diff --git a/kompareurldialog.h b/kompareurldialog.h --- a/kompareurldialog.h +++ b/kompareurldialog.h @@ -52,8 +52,9 @@ void setFirstURLRequesterMode ( unsigned int mode ); void setSecondURLRequesterMode( unsigned int mode ); -protected slots: - virtual void slotButtonClicked( int button ); +public slots: + virtual void accept(); + virtual void reject(); private slots: void slotEnableOk(); diff --git a/kompareurldialog.cpp b/kompareurldialog.cpp --- a/kompareurldialog.cpp +++ b/kompareurldialog.cpp @@ -87,13 +87,17 @@ } } -void KompareURLDialog::slotButtonClicked( int button ) +void KompareURLDialog::reject() +{ + m_filesPage->restore(); + m_diffPage->restore(); + m_viewPage->restore(); + + QDialog::reject(); +} + +void KompareURLDialog::accept() { - if ( button == QDialogButtonBox::Cancel ) - { - reject(); - return; - } // BUG: 124121 File with filenames to be excluded does not exist so diff complains and no diffs are generated qCDebug(KOMPARESHELL) << "Test to see if the file is an actual file that is given in the file with filenames to exclude field" ; if ( m_diffPage->m_excludeFileNameGroupBox->isChecked() ) @@ -123,7 +127,7 @@ cfg->sync(); - accept(); + QDialog::accept(); } void KompareURLDialog::slotEnableOk() diff --git a/libdialogpages/filespage.h b/libdialogpages/filespage.h --- a/libdialogpages/filespage.h +++ b/libdialogpages/filespage.h @@ -58,6 +58,9 @@ virtual void apply(); virtual void setDefaults(); +private slots: + void open(); + private: QGroupBox* m_firstGB; QGroupBox* m_secondGB; @@ -72,6 +75,9 @@ KComboBox* m_encodingComboBox; FilesSettings* m_settings; + +private: + void open(KUrlComboBox* urlComboBox, bool selectFolders); }; #endif diff --git a/libdialogpages/filespage.cpp b/libdialogpages/filespage.cpp --- a/libdialogpages/filespage.cpp +++ b/libdialogpages/filespage.cpp @@ -40,18 +40,61 @@ layout->addWidget( m_firstGB ); QHBoxLayout* gb1Layout = new QHBoxLayout( m_firstGB ); m_firstURLComboBox = new KUrlComboBox( KUrlComboBox::Both, true, m_firstGB ); + m_firstURLComboBox->setMaxItems( 20 ); 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( 20 ); 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 ); @@ -71,9 +114,41 @@ 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; @@ -111,11 +186,21 @@ 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 ) @@ -136,6 +221,10 @@ 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(); diff --git a/main.cpp b/main.cpp --- a/main.cpp +++ b/main.cpp @@ -229,8 +229,8 @@ 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 ) {