diff --git a/kompareurldialog.cpp b/kompareurldialog.cpp index 2b03c98..ea22dc7 100644 --- a/kompareurldialog.cpp +++ b/kompareurldialog.cpp @@ -1,191 +1,192 @@ /*************************************************************************** kompareurldialog.cpp -------------------- begin : Sun Mar 4 2001 Copyright 2001-2005,2009 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. ** ***************************************************************************/ #include "kompareurldialog.h" #include #include #include #include #include #include #include #include #include #include "diffpage.h" #include "filespage.h" #include "filessettings.h" #include "viewpage.h" #include "viewsettings.h" KompareURLDialog::KompareURLDialog(QWidget* parent) : KPageDialog(parent) { setFaceType(List); KSharedConfig::Ptr cfg = KSharedConfig::openConfig(); m_filesPage = new FilesPage(); KPageWidgetItem* filesItem = addPage(m_filesPage, i18n("Files")); filesItem->setIcon(QIcon::fromTheme(QStringLiteral("text-plain"))); filesItem->setHeader(i18n("Here you can enter the files you want to compare.")); m_filesSettings = new FilesSettings(this); m_filesSettings->loadSettings(cfg.data()); m_filesPage->setSettings(m_filesSettings); m_diffPage = new DiffPage(); KPageWidgetItem* diffItem = addPage(m_diffPage, i18n("Diff")); diffItem->setIcon(QIcon::fromTheme(QStringLiteral("text-x-patch"))); diffItem->setHeader(i18n("Here you can change the options for comparing the files.")); m_diffSettings = new DiffSettings(this); m_diffSettings->loadSettings(cfg.data()); m_diffPage->setSettings(m_diffSettings); m_viewPage = new ViewPage(); KPageWidgetItem* viewItem = addPage(m_viewPage, i18n("Appearance")); viewItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-theme"))); viewItem->setHeader(i18n("Here you can change the options for the view.")); m_viewSettings = new ViewSettings(this); m_viewSettings->loadSettings(cfg.data()); m_viewPage->setSettings(m_viewSettings); adjustSize(); connect(m_filesPage->firstURLRequester(), &KUrlRequester::textChanged, this, &KompareURLDialog::slotEnableOk); connect(m_filesPage->secondURLRequester(), &KUrlRequester::textChanged, this, &KompareURLDialog::slotEnableOk); - + connect(m_filesPage, &FilesPage::urlChanged, + this, &KompareURLDialog::slotEnableOk); } KompareURLDialog::~KompareURLDialog() { } void KompareURLDialog::showEvent(QShowEvent* event) { if (!event->spontaneous()) { slotEnableOk(); } } void KompareURLDialog::reject() { m_filesPage->restore(); m_diffPage->restore(); m_viewPage->restore(); QDialog::reject(); } void KompareURLDialog::accept() { // 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()) { qCDebug(KOMPARESHELL) << "Ok the checkbox is active..." ; if (QFileInfo(m_diffPage->m_excludeFileURLComboBox->currentText()).isDir()) { qCDebug(KOMPARESHELL) << "Don't enter directory names where filenames are expected..." ; KMessageBox::sorry(this, i18n("File used for excluding files cannot be found, please specify another file.")); reject(); return; } } // Room for more checks for invalid input m_filesPage->setURLsInComboBoxes(); KSharedConfig::Ptr cfg = KSharedConfig::openConfig(); m_filesPage->apply(); m_diffPage->apply(); m_viewPage->apply(); m_filesSettings->saveSettings(cfg.data()); m_diffSettings->saveSettings(cfg.data()); m_viewSettings->saveSettings(cfg.data()); cfg->sync(); QDialog::accept(); } void KompareURLDialog::slotEnableOk() { button(QDialogButtonBox::Ok)->setEnabled(!m_filesPage->firstURLRequester()->url().isEmpty() && !m_filesPage->secondURLRequester()->url().isEmpty()); } /** * Returns the first URL, which was entered. * @return first URL */ QUrl KompareURLDialog::getFirstURL() const { return m_filesPage->firstURLRequester()->url(); } /** * Returns the second URL, which was entered. * @return second URL */ QUrl KompareURLDialog::getSecondURL() const { return m_filesPage->secondURLRequester()->url(); } /** * Returns the encoding. * @return encoding */ QString KompareURLDialog::encoding() const { return m_filesPage->encoding(); } void KompareURLDialog::setFirstGroupBoxTitle(const QString& title) { m_filesPage->setFirstGroupBoxTitle(title); } void KompareURLDialog::setSecondGroupBoxTitle(const QString& title) { m_filesPage->setSecondGroupBoxTitle(title); } void KompareURLDialog::setGroup(const QString& groupName) { m_filesSettings->setGroup(groupName); m_filesSettings->loadSettings(KSharedConfig::openConfig().data()); m_filesPage->setSettings(m_filesSettings); } void KompareURLDialog::setFirstURLRequesterMode(unsigned int mode) { m_filesPage->setFirstURLRequesterMode(mode); } void KompareURLDialog::setSecondURLRequesterMode(unsigned int mode) { m_filesPage->setSecondURLRequesterMode(mode); } diff --git a/libdialogpages/filespage.cpp b/libdialogpages/filespage.cpp index 86e27ae..88f742a 100644 --- a/libdialogpages/filespage.cpp +++ b/libdialogpages/filespage.cpp @@ -1,240 +1,241 @@ /*************************************************************************** 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" FilesPage::FilesPage() : QFrame() { QVBoxLayout* layout = new QVBoxLayout(this); m_firstGB = new QGroupBox(QStringLiteral("You have to set this moron :)"), this); // whut? 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(QStringLiteral("SourceURLComboBox")); m_firstURLRequester = new KUrlRequester(m_firstURLComboBox, nullptr); gb1Layout->addWidget(m_firstURLComboBox); m_firstURLComboBox->setFocus(); QPushButton* button = new QPushButton(this); button->setIcon(QIcon::fromTheme(QStringLiteral("document-open"))); button->setToolTip(i18n("Select File")); button->setProperty("combobox", QStringLiteral("SourceURLComboBox")); button->setProperty("folder", false); connect(button, &QPushButton::clicked, this, &FilesPage::open); gb1Layout->addWidget(button); button = new QPushButton(this); button->setIcon(QIcon::fromTheme(QStringLiteral("folder-open"))); QSizePolicy sp = button->sizePolicy(); sp.setRetainSizeWhenHidden(true); button->setSizePolicy(sp); button->setObjectName(QStringLiteral("firstURLOpenFolder")); button->setToolTip(i18n("Select Folder")); button->setProperty("combobox", QStringLiteral("SourceURLComboBox")); button->setProperty("folder", true); connect(button, &QPushButton::clicked, this, &FilesPage::open); gb1Layout->addWidget(button); m_secondGB = new QGroupBox(QStringLiteral("This too moron !"), this); // whut again? 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(QStringLiteral("DestURLComboBox")); m_secondURLRequester = new KUrlRequester(m_secondURLComboBox, nullptr); gb2Layout->addWidget(m_secondURLComboBox); button = new QPushButton(this); button->setIcon(QIcon::fromTheme(QStringLiteral("document-open"))); button->setToolTip(i18n("Select File")); button->setProperty("combobox", QStringLiteral("DestURLComboBox")); button->setProperty("folder", false); connect(button, &QPushButton::clicked, this, &FilesPage::open); gb2Layout->addWidget(button); button = new QPushButton(this); button->setIcon(QIcon::fromTheme(QStringLiteral("folder-open"))); button->setObjectName(QStringLiteral("secondURLOpenFolder")); sp = button->sizePolicy(); sp.setRetainSizeWhenHidden(true); button->setSizePolicy(sp); button->setToolTip(i18n("Select Folder")); button->setProperty("combobox", QStringLiteral("DestURLComboBox")); button->setProperty("folder", true); connect(button, &QPushButton::clicked, this, &FilesPage::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(QStringLiteral("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 = nullptr; delete m_secondURLRequester; m_secondURLRequester = nullptr; m_settings = nullptr; } void FilesPage::open() { QPushButton* button = (QPushButton*) sender(); bool selectFolders = button->property("folder").toBool(); KUrlComboBox* urlComboBox = findChild(button->property("combobox").toString()); doOpen(urlComboBox, selectFolders); } void FilesPage::doOpen(KUrlComboBox* urlComboBox, bool selectFolders) { QUrl currentUrl = QUrl::fromUserInput(urlComboBox->currentText()); QUrl newUrl = selectFolders ? QFileDialog::getExistingDirectoryUrl(this, i18n("Select Folder"), currentUrl, 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); + emit urlChanged(); } } 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(QUrl::fromUserInput(m_firstURLComboBox->currentText(), QDir::currentPath(), QUrl::AssumeLocalFile)); m_secondURLComboBox->setUrl(QUrl::fromUserInput(m_secondURLComboBox->currentText(), QDir::currentPath(), QUrl::AssumeLocalFile)); } void FilesPage::setFirstURLRequesterMode(unsigned int mode) { m_firstURLRequester->setMode((KFile::Mode) mode); if ((mode & KFile::Directory) == 0) { QPushButton* button = findChild(QStringLiteral("firstURLOpenFolder")); button->setVisible(false); } } void FilesPage::setSecondURLRequesterMode(unsigned int mode) { m_secondURLRequester->setMode((KFile::Mode) mode); if ((mode & KFile::Directory) == 0) { QPushButton* button = findChild(QStringLiteral("secondURLOpenFolder")); button->setVisible(false); } } void FilesPage::setSettings(FilesSettings* settings) { m_settings = settings; m_firstURLComboBox->setUrls(m_settings->m_recentSources); m_firstURLComboBox->setUrl(QUrl::fromUserInput(m_settings->m_lastChosenSourceURL, QDir::currentPath(), QUrl::AssumeLocalFile)); m_secondURLComboBox->setUrls(m_settings->m_recentDestinations); m_secondURLComboBox->setUrl(QUrl::fromUserInput(m_settings->m_lastChosenDestinationURL, QDir::currentPath(), QUrl::AssumeLocalFile)); 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 27971e0..bff3065 100644 --- a/libdialogpages/filespage.h +++ b/libdialogpages/filespage.h @@ -1,83 +1,90 @@ /*************************************************************************** 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(); ~FilesPage() override; 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(); +Q_SIGNALS: + // Signal when we set a url from browse buttons. + // Since KUrlComboBox::setUrl doesn't emit textChanged we need to notify + // the main dialog that we set a url programatically so it can enable OK + // if there's a path in both boxes... + void urlChanged(); + private Q_SLOTS: void open(); private: void doOpen(KUrlComboBox* urlComboBox, bool selectFolders); 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; }; #endif