diff --git a/libdialogpages/filespage.cpp b/libdialogpages/filespage.cpp index 07072fb..8272f94 100644 --- a/libdialogpages/filespage.cpp +++ b/libdialogpages/filespage.cpp @@ -1,159 +1,242 @@ /*************************************************************************** filespage.cpp ------------- begin : Sun Apr 18 2004 Copyright 2004 Otto Bruggeman Copyright 2007-2011 Kevin Kofler ****************************************************************************/ /*************************************************************************** ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ***************************************************************************/ #include "filespage.h" #include #include #include #include #include #include #include #include #include #include "filessettings.h" QUrl urlFromArg(const QString &arg); FilesPage::FilesPage() : QFrame() { QVBoxLayout* layout = new QVBoxLayout( this ); m_firstGB = new QGroupBox( "You have to set this moron :)", this ); layout->addWidget( m_firstGB ); QHBoxLayout* gb1Layout = new QHBoxLayout( m_firstGB ); m_firstURLComboBox = new KUrlComboBox( KUrlComboBox::Both, true, m_firstGB ); m_firstURLComboBox->setMaxItems( 10 ); m_firstURLComboBox->setObjectName( "SourceURLComboBox" ); - m_firstURLRequester = new KUrlRequester( m_firstURLComboBox, m_firstGB ); - gb1Layout->addWidget( m_firstURLRequester ); - m_firstURLRequester->setFocus(); + m_firstURLRequester = new KUrlRequester( m_firstURLComboBox, 0 ); + gb1Layout->addWidget( m_firstURLComboBox ); + m_firstURLComboBox->setFocus(); + + QPushButton* button = new QPushButton( "", this ); + button->setIcon( QIcon::fromTheme("document-open") ); + button->setToolTip( i18n( "Select File" ) ); + button->setProperty( "combobox", "SourceURLComboBox" ); + button->setProperty( "folder", false ); + connect( button, SIGNAL(clicked()), this, SLOT(open()) ); + gb1Layout->addWidget( button ); + + button = new QPushButton( "", this ); + button->setIcon( QIcon::fromTheme("folder-open") ); + QSizePolicy sp = button->sizePolicy(); + sp.setRetainSizeWhenHidden( true ); + button->setSizePolicy( sp ); + button->setObjectName( "firstURLOpenFolder" ); + button->setToolTip( i18n( "Select Folder" ) ); + button->setProperty( "combobox", "SourceURLComboBox" ); + button->setProperty( "folder", true ); + connect( button, SIGNAL(clicked()), this, SLOT(open()) ); + gb1Layout->addWidget( button ); m_secondGB = new QGroupBox( "This too moron !", this ); layout->addWidget( m_secondGB ); QHBoxLayout* gb2Layout = new QHBoxLayout( m_secondGB ); m_secondURLComboBox = new KUrlComboBox( KUrlComboBox::Both, true, m_secondGB ); m_secondURLComboBox->setMaxItems( 10 ); m_secondURLComboBox->setObjectName( "DestURLComboBox" ); - m_secondURLRequester = new KUrlRequester( m_secondURLComboBox, m_secondGB ); - gb2Layout->addWidget( m_secondURLRequester ); + m_secondURLRequester = new KUrlRequester( m_secondURLComboBox, 0 ); + gb2Layout->addWidget( m_secondURLComboBox ); + + button = new QPushButton( "", this ); + button->setIcon( QIcon::fromTheme("document-open") ); + button->setToolTip( i18n( "Select File" ) ); + button->setProperty( "combobox", "DestURLComboBox" ); + button->setProperty( "folder", false ); + connect( button, SIGNAL(clicked()), this, SLOT(open()) ); + gb2Layout->addWidget( button ); + + button = new QPushButton( "", this ); + button->setIcon( QIcon::fromTheme("folder-open") ); + button->setObjectName( "secondURLOpenFolder" ); + sp = button->sizePolicy(); + sp.setRetainSizeWhenHidden( true ); + button->setSizePolicy( sp ); + button->setToolTip( i18n( "Select Folder" ) ); + button->setProperty( "combobox", "DestURLComboBox" ); + button->setProperty( "folder", true ); + connect( button, SIGNAL(clicked()), this, SLOT(open()) ); + gb2Layout->addWidget( button ); + m_thirdGB = new QGroupBox( i18n( "Encoding" ), this ); layout->addWidget( m_thirdGB ); QHBoxLayout* gb3Layout = new QHBoxLayout( m_thirdGB ); m_encodingComboBox = new KComboBox( false, m_thirdGB ); m_encodingComboBox->setObjectName( "encoding_combobox" ); m_encodingComboBox->insertItem( 0, i18n( "Default" ) ); m_encodingComboBox->insertItems( 1, KCharsets::charsets()->availableEncodingNames() ); gb3Layout->addWidget( m_encodingComboBox ); layout->addWidget( m_firstGB ); layout->addWidget( m_secondGB ); layout->addWidget( m_thirdGB ); layout->addStretch( 1 ); } FilesPage::~FilesPage() { + delete m_firstURLRequester; + m_firstURLRequester = 0; + delete m_secondURLRequester; + m_secondURLRequester = 0; m_settings = 0; } +void FilesPage::open() +{ + QPushButton* button = ( QPushButton* ) sender(); + bool selectFolders = button->property( "folder" ).toBool(); + KUrlComboBox* urlComboBox = findChild( button->property( "combobox" ).toString() ); + + open( urlComboBox, selectFolders ); +} + +void FilesPage::open( KUrlComboBox *urlComboBox, bool selectFolders ) +{ + QUrl currentUrl = QUrl::fromUserInput( urlComboBox->currentText() ); + + QUrl newUrl = selectFolders ? QFileDialog::getExistingDirectoryUrl( this, + i18n( "Select Folder" ), + currentUrl, + QFileDialog::ShowDirsOnly & QFileDialog::ReadOnly ) + : QFileDialog::getOpenFileUrl( this, + i18n( "Select File" ), + currentUrl ); + if ( !newUrl.isEmpty() ) + { + // remove newUrl if already exists and add it as the first item + urlComboBox->setUrl( newUrl ); + } + +} + KUrlRequester* FilesPage::firstURLRequester() const { return m_firstURLRequester; } KUrlRequester* FilesPage::secondURLRequester() const { return m_secondURLRequester; } QString FilesPage::encoding() const { return m_encodingComboBox->currentText(); } void FilesPage::setFirstGroupBoxTitle( const QString& title ) { m_firstGB->setTitle( title ); } void FilesPage::setSecondGroupBoxTitle( const QString& title ) { m_secondGB->setTitle( title ); } void FilesPage::setURLsInComboBoxes() { // qDebug() << "first : " << m_firstURLComboBox->currentText() ; // qDebug() << "second: " << m_secondURLComboBox->currentText() ; m_firstURLComboBox->setUrl( urlFromArg( m_firstURLComboBox->currentText() ) ); m_secondURLComboBox->setUrl( urlFromArg( m_secondURLComboBox->currentText() ) ); } void FilesPage::setFirstURLRequesterMode( unsigned int mode ) { m_firstURLRequester->setMode( (KFile::Mode) mode ); + if ( mode == (KFile::File | KFile::ExistingOnly) ) + { + QPushButton *button = findChild( "firstURLOpenFolder" ); + button->setVisible( false ); + } } void FilesPage::setSecondURLRequesterMode( unsigned int mode ) { m_secondURLRequester->setMode( (KFile::Mode) mode ); + if ( mode == (KFile::File | KFile::ExistingOnly) ) + { + QPushButton *button = findChild( "secondURLOpenFolder" ); + button->setVisible( false ); + } } void FilesPage::setSettings( FilesSettings* settings ) { m_settings = settings; m_firstURLComboBox->setUrls( m_settings->m_recentSources ); m_firstURLComboBox->setUrl( urlFromArg( m_settings->m_lastChosenSourceURL ) ); m_secondURLComboBox->setUrls( m_settings->m_recentDestinations ); m_secondURLComboBox->setUrl( urlFromArg( m_settings->m_lastChosenDestinationURL ) ); m_encodingComboBox->setCurrentIndex( m_encodingComboBox->findText( m_settings->m_encoding, Qt::MatchFixedString ) ); } void FilesPage::restore() { // this shouldn't do a thing... } void FilesPage::apply() { // set the current items as the first ones m_firstURLComboBox->insertUrl( 0, QUrl( m_firstURLComboBox->currentText() ) ); m_secondURLComboBox->insertUrl( 0, QUrl( m_secondURLComboBox->currentText() ) ); m_settings->m_recentSources = m_firstURLComboBox->urls(); m_settings->m_lastChosenSourceURL = m_firstURLComboBox->currentText(); m_settings->m_recentDestinations = m_secondURLComboBox->urls(); m_settings->m_lastChosenDestinationURL = m_secondURLComboBox->currentText(); m_settings->m_encoding = m_encodingComboBox->currentText(); } void FilesPage::setDefaults() { m_firstURLComboBox->setUrls( QStringList() ); m_firstURLComboBox->setUrl( QUrl() ); m_secondURLComboBox->setUrls( QStringList() ); m_secondURLComboBox->setUrl( QUrl() ); m_encodingComboBox->setCurrentIndex( 0 ); // "Default" } diff --git a/libdialogpages/filespage.h b/libdialogpages/filespage.h index 305b4b9..af56bd4 100644 --- a/libdialogpages/filespage.h +++ b/libdialogpages/filespage.h @@ -1,77 +1,83 @@ /*************************************************************************** kcompareurldialog.h ------------------- begin : Sun Mar 4 2001 Copyright 2001-2004 Otto Bruggeman Copyright 2001-2003 John Firebaugh Copyright 2007 Kevin Kofler ****************************************************************************/ /*************************************************************************** ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ***************************************************************************/ #ifndef FILESPAGE_H #define FILESPAGE_H #include #include "dialogpages_export.h" class QGroupBox; class KComboBox; class KUrlComboBox; class KUrlRequester; class FilesSettings; class DIALOGPAGES_EXPORT FilesPage : public QFrame { Q_OBJECT public: FilesPage(); virtual ~FilesPage(); public: KUrlRequester* firstURLRequester() const; KUrlRequester* secondURLRequester() const; QString encoding() const; void setFirstGroupBoxTitle ( const QString& title ); void setSecondGroupBoxTitle( const QString& title ); void setURLsInComboBoxes(); void setFirstURLRequesterMode( unsigned int mode ); void setSecondURLRequesterMode( unsigned int mode ); public: virtual void setSettings( FilesSettings* settings ); virtual void restore(); virtual void apply(); virtual void setDefaults(); +private slots: + void open(); + private: QGroupBox* m_firstGB; QGroupBox* m_secondGB; QGroupBox* m_thirdGB; KUrlComboBox* m_firstURLComboBox; KUrlComboBox* m_secondURLComboBox; KUrlRequester* m_firstURLRequester; KUrlRequester* m_secondURLRequester; // Use this bool to lock the connection between both KUrlRequesters. // This prevents annoying behaviour bool m_URLChanged; KComboBox* m_encodingComboBox; FilesSettings* m_settings; + +private: + void open(KUrlComboBox* urlComboBox, bool selectFolders); }; #endif diff --git a/main.cpp b/main.cpp index 3558a85..37277f9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,254 +1,254 @@ /*************************************************************************** main.cpp -------- begin : Sun Mar 4 2001 Copyright 2001-2005,2009 Otto Bruggeman Copyright 2001-2003 John Firebaugh Copyright 2007-2012 Kevin Kofler ****************************************************************************/ /*************************************************************************** ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ***************************************************************************/ /** * @file main.cpp * This is the main entry point for Kompare. * The command line arguments are handled and the application is started. * @author Otto Bruggeman * @author John Firebaugh * @author Kevin Kofler */ #include #include #include #include #include #include #include #include #include "kompare_part.h" #include "kompare_shell.h" #include "kompareurldialog.h" /** * Program description. */ static const char description[] = I18N_NOOP("A program to view the differences between files and optionally generate a diff" ); /** * Version number. */ static const char version[] = "4.1.3"; QUrl urlFromArg(const QString& arg) { #if QT_VERSION >= 0x050400 return QUrl::fromUserInput(arg, QDir::currentPath(), QUrl::AssumeLocalFile); #else // Logic from QUrl::fromUserInput(QString, QString, UserInputResolutionOptions) return (QUrl(arg, QUrl::TolerantMode).isRelative() && !QDir::isAbsolutePath(arg)) ? QUrl::fromLocalFile(QDir::current().absoluteFilePath(arg)) : QUrl::fromUserInput(arg); #endif } /** * Setting up the KAboutData structure. * Parsing and handling of the given command line arguments. * @param argc the number of arguments * @param argv the array of arguments * @return exit status */ int main(int argc, char *argv[]) { KLocalizedString::setApplicationDomain("kompare"); KAboutData aboutData( "kompare", i18n("Kompare"), version, i18n(description), KAboutLicense::GPL, i18n("(c) 2001-2004 John Firebaugh, (c) 2001-2005,2009 Otto Bruggeman, (c) 2004-2005 Jeff Snyder, (c) 2007-2012 Kevin Kofler") ); aboutData.addAuthor( i18n("John Firebaugh"), i18n("Author"), "jfirebaugh@kde.org" ); aboutData.addAuthor( i18n("Otto Bruggeman"), i18n("Author"), "bruggie@gmail.com" ); aboutData.addAuthor( i18n("Jeff Snyder"), i18n("Developer"), "jeff@caffeinated.me.uk" ); aboutData.addCredit( i18n("Kevin Kofler"), i18n("Maintainer"), "kevin.kofler@chello.at" ); aboutData.addCredit( i18n("Chris Luetchford"), i18n("Kompare icon artist"), "chris@os11.com" ); aboutData.addCredit( i18n("Malte Starostik"), i18n("A lot of good advice"), "malte@kde.org" ); aboutData.addCredit( i18n("Bernd Gehrmann"), i18n("Cervisia diff viewer"), "bernd@physik.hu-berlin.de" ); QApplication app(argc, argv); app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kompare"))); QCommandLineParser parser; KAboutData::setApplicationData(aboutData); parser.addVersionOption(); parser.addHelpOption(); aboutData.setupCommandLine(&parser); parser.addOption(QCommandLineOption("c", i18n("This will compare URL1 with URL2"))); parser.addOption(QCommandLineOption("o", i18n( "This will open URL1 and expect it to be diff output. URL1 can also be a '-' and then it will read from standard input. Can be used for instance for cvs diff | kompare -o -. Kompare will do a check to see if it can find the original file(s) and then blend the original file(s) into the diffoutput and show that in the viewer. -n disables the check." ))); parser.addOption(QCommandLineOption("b", i18n( "This will blend URL2 into URL1, URL2 is expected to be diff output and URL1 the file or folder that the diffoutput needs to be blended into. " ))); parser.addOption(QCommandLineOption("n", i18n( "Disables the check for automatically finding the original file(s) when using '-' as URL with the -o option." ))); parser.addOption(QCommandLineOption("e ", i18n( "Use this to specify the encoding when calling it from the command line. It will default to the local encoding if not specified." ))); parser.process(app); aboutData.processCommandLine(&parser); bool difault = false; KompareShell* ks; QStringList args = parser.positionalArguments(); // see if we are starting with session management if (app.isSessionRestored()) { RESTORE(KompareShell) } else { ks = new KompareShell(); ks->setObjectName( "FirstKompareShell" ); qCDebug(KOMPARESHELL) << "Arg Count = " << args.count() ; for ( int i=0; i < args.count(); i++ ) { qCDebug(KOMPARESHELL) << "Argument " << (i+1) << ": " << args.at( i ) ; } if ( parser.isSet( "e " ) ) { // Encoding given... // FIXME: Need to implement this... } if ( parser.isSet( "o" ) ) { qCDebug(KOMPARESHELL) << "Option -o is set" ; if ( args.count() != 1 ) { difault = true; } else { ks->show(); qCDebug(KOMPARESHELL) << "OpenDiff..." ; if ( args.at(0) == QLatin1String("-") ) ks->openStdin(); else ks->openDiff( urlFromArg( args.at( 0 ) ) ); difault = false; } } else if ( parser.isSet( "c" ) ) { qCDebug(KOMPARESHELL) << "Option -c is set" ; if ( args.count() != 2 ) { parser.showHelp(); difault = true; } else { ks->show(); QUrl url0 = urlFromArg(args.at( 0 )); qCDebug(KOMPARESHELL) << "URL0 = " << url0.url() ; QUrl url1 = urlFromArg(args.at( 1 )); qCDebug(KOMPARESHELL) << "URL1 = " << url1.url() ; ks->compare( url0, url1 ); difault = false; } } else if ( parser.isSet( "b" ) ) { qCDebug(KOMPARESHELL) << "Option -b is set" ; if ( args.count() != 2 ) { parser.showHelp(); difault = true; } else { ks->show(); qCDebug(KOMPARESHELL) << "blend..." ; QUrl url0 = urlFromArg(args.at( 0 )); qCDebug(KOMPARESHELL) << "URL0 = " << url0.url() ; QUrl url1 = urlFromArg(args.at( 1 )); qCDebug(KOMPARESHELL) << "URL1 = " << url1.url() ; ks->blend( url0, url1 ); difault = false; } } else if ( args.count() == 1 ) { ks->show(); qCDebug(KOMPARESHELL) << "Single file. so openDiff/openStdin is only possible..." ; if ( args.at(0) == QLatin1String("-") ) ks->openStdin(); else ks->openDiff( urlFromArg(args.at( 0 ) ) ); difault = false; } else if ( args.count() == 2 ) { // In this case we are assuming you want to compare files/dirs // and not blending because that is almost impossible to detect ks->show(); qCDebug(KOMPARESHELL) << "Dunno, we'll have to figure it out later, trying compare for now..." ; QUrl url0 = urlFromArg(args.at( 0 )); qCDebug(KOMPARESHELL) << "URL0 = " << url0.url() ; QUrl url1 = urlFromArg(args.at( 1 )); qCDebug(KOMPARESHELL) << "URL1 = " << url1.url() ; ks->compare( url0, url1 ); difault = false; } else if ( args.count() == 0 ) // no options and no args { difault = true; } if ( difault ) { KompareURLDialog dialog( 0 ); dialog.setWindowTitle( i18n("Compare Files or Folders") ); dialog.setFirstGroupBoxTitle( i18n( "Source" ) ); dialog.setSecondGroupBoxTitle( i18n( "Destination" ) ); QPushButton *okButton = dialog.button( QDialogButtonBox::Ok ); okButton->setText( i18n( "Compare" )); okButton->setToolTip( i18n( "Compare these files or folders" )); okButton->setWhatsThis( i18n( "If you have entered 2 filenames or 2 folders in the fields in this dialog then this button will be enabled and pressing it will start a comparison of the entered files or folders. " )); dialog.setGroup( "Recent Compare Files" ); - dialog.setFirstURLRequesterMode( KFile::File|KFile::ExistingOnly ); - dialog.setSecondURLRequesterMode( KFile::File|KFile::ExistingOnly ); + dialog.setFirstURLRequesterMode( KFile::File|KFile::Directory|KFile::ExistingOnly ); + dialog.setSecondURLRequesterMode( KFile::File|KFile::Directory|KFile::ExistingOnly ); if( dialog.exec() == QDialog::Accepted ) { ks->show(); ks->viewPart()->setEncoding( dialog.encoding() ); ks->compare( dialog.getFirstURL(), dialog.getSecondURL() ); } else { return -1; } } } return app.exec(); } /* vim: set ts=4 sw=4 noet: */