diff --git a/kcms/componentchooser/CMakeLists.txt b/kcms/componentchooser/CMakeLists.txt --- a/kcms/componentchooser/CMakeLists.txt +++ b/kcms/componentchooser/CMakeLists.txt @@ -19,12 +19,7 @@ kconfig_add_kcfg_files(kcm_componentchooser_SRCS terminal_settings.kcfgc GENERATE_MOC) ki18n_wrap_ui(kcm_componentchooser_SRCS - browserconfig_ui.ui - filemanagerconfig_ui.ui - emailclientconfig_ui.ui componentchooser_ui.ui - componentconfig_ui.ui - terminalemulatorconfig_ui.ui ) add_library(kcm_componentchooser MODULE ${kcm_componentchooser_SRCS}) diff --git a/kcms/componentchooser/browserconfig_ui.ui b/kcms/componentchooser/browserconfig_ui.ui deleted file mode 100644 --- a/kcms/componentchooser/browserconfig_ui.ui +++ /dev/null @@ -1,49 +0,0 @@ - - - BrowserConfig_UI - - - - 0 - 0 - 432 - 218 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 0 - 20 - - - - - - - - - diff --git a/kcms/componentchooser/componentchooser.h b/kcms/componentchooser/componentchooser.h --- a/kcms/componentchooser/componentchooser.h +++ b/kcms/componentchooser/componentchooser.h @@ -1,66 +1,65 @@ /*************************************************************************** componentchooser.h - description ------------------- - copyright : (C) 2002 by Joseph Wenninger - email : jowenn@kde.org + copyright : (C) 2002 by Joseph Wenninger + copyright : (C) 2020 by Méven Car ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundationi * + * published by the Free Software Foundation * * * ***************************************************************************/ #ifndef _COMPONENTCHOOSER_H_ #define _COMPONENTCHOOSER_H_ #include "ui_componentchooser_ui.h" -#include "ui_componentconfig_ui.h" #include - -#include +#include #include -class QListWidgetItem; +class QWidget; class KConfig; -/* The CfgPlugin class is an exception. It is LGPL. It will be parted of the plugin interface - which I plan for KDE 3.2. -*/ -class CfgPlugin +class CfgPlugin : public QComboBox { + Q_OBJECT + public: - CfgPlugin(){} + CfgPlugin(QWidget *parent): QComboBox(parent) {} virtual ~CfgPlugin(){} virtual void load(KConfig *cfg)=0; - virtual void save(KConfig *cfg)=0; - virtual void defaults()=0; - virtual bool isDefaults() const=0; -}; + virtual void save(KConfig *cfg)=0; + bool hasChanged() const + { + return m_currentIndex != -1 && m_currentIndex != currentIndex(); + } + + void defaults() + { + if (m_defaultIndex != -1) { + setCurrentIndex(m_defaultIndex); + } + } + + bool isDefaults() const + { + return m_defaultIndex == -1 || m_defaultIndex == currentIndex(); + } -class CfgComponent: public QWidget, public Ui::ComponentConfig_UI, public CfgPlugin -{ -Q_OBJECT -public: - CfgComponent(QWidget *parent); - ~CfgComponent() override; - void load(KConfig *cfg) override; - void save(KConfig *cfg) override; - void defaults() override; - bool isDefaults() const override; +Q_SIGNALS: + void changed(bool); protected: - QHash m_lookupDict,m_revLookupDict; - -protected Q_SLOTS: - void slotComponentChanged(const QString&); -Q_SIGNALS: - void changed(bool); - void defaulted(bool); + // the currently saved selected option + int m_currentIndex = -1; + // the index default of the default option + int m_defaultIndex = -1; }; class ComponentChooser : public QWidget, public Ui::ComponentChooser_UI @@ -76,22 +75,16 @@ void restoreDefault(); private: - QString latestEditedService; - bool somethingChanged; - QWidget *configWidget; - QVBoxLayout *myLayout; - QMap configWidgetMap; + QMap configWidgetMap; - void loadConfigWidget(const QString &, const QString &, const QString &); + CfgPlugin *loadConfigWidget(const QString &cfgType); protected Q_SLOTS: - void emitChanged(bool); - void slotServiceSelected(QListWidgetItem *); + void emitChanged(); Q_SIGNALS: void changed(bool); void defaulted(bool); - }; diff --git a/kcms/componentchooser/componentchooser.cpp b/kcms/componentchooser/componentchooser.cpp --- a/kcms/componentchooser/componentchooser.cpp +++ b/kcms/componentchooser/componentchooser.cpp @@ -1,8 +1,8 @@ /*************************************************************************** componentchooser.cpp - description ------------------- - copyright : (C) 2002 by Joseph Wenninger - email : jowenn@kde.org + copyright : (C) 2002 by Joseph Wenninger + copyright : (C) 2020 by Méven Car ***************************************************************************/ /*************************************************************************** @@ -34,241 +34,126 @@ #include #include #include +#include #include +#include -//BEGIN General kpart based Component selection - -CfgComponent::CfgComponent(QWidget *parent) - : QWidget(parent), Ui::ComponentConfig_UI(), CfgPlugin() -{ - setupUi( this ); - connect(ComponentSelector,SIGNAL(activated(const QString&)),this,SLOT(slotComponentChanged(const QString&))); -} - -CfgComponent::~CfgComponent() +ComponentChooser::ComponentChooser(QWidget *parent): + QWidget(parent), Ui::ComponentChooser_UI() { -} - -void CfgComponent::slotComponentChanged(const QString&) { - emit changed(true); -} - -void CfgComponent::save(KConfig *cfg) { - // yes, this can happen if there are NO KTrader offers for this component - if (!m_lookupDict.contains(ComponentSelector->currentText())) - return; - - KConfigGroup mainGroup = cfg->group(QByteArray()); - QString serviceTypeToConfigure=mainGroup.readEntry("ServiceTypeToConfigure"); - KConfig store(mainGroup.readPathEntry("storeInFile", QStringLiteral("null"))); - KConfigGroup cg(&store, mainGroup.readEntry("valueSection")); - cg.writePathEntry(mainGroup.readEntry("valueName", "kcm_componenchooser_null"), - m_lookupDict.value(ComponentSelector->currentText())); - store.sync(); - emit changed(false); -} - -void CfgComponent::load(KConfig *cfg) { + setupUi(this); - ComponentSelector->clear(); - m_lookupDict.clear(); - m_revLookupDict.clear(); + const QString directory = QStandardPaths::locate( + QStandardPaths::GenericDataLocation, QStringLiteral("kcm_componentchooser"), QStandardPaths::LocateDirectory); + QStringList services; + const QDir dir(directory); + for (const auto &f: dir.entryList(QStringList("*.desktop"))) { + services += dir.absoluteFilePath(f); + } - const KConfigGroup mainGroup = cfg->group(QByteArray()); - const QString serviceTypeToConfigure = mainGroup.readEntry("ServiceTypeToConfigure"); + for (const QString &service : qAsConst(services)) + { + KConfig cfg(service, KConfig::SimpleConfig); + KConfigGroup cg = cfg.group(QByteArray()); - const KService::List offers = KServiceTypeTrader::self()->query(serviceTypeToConfigure); + // fill the form layout + const auto name = cg.readEntry("Name", i18n("Unknown")); + CfgPlugin *loadedConfigWidget = loadConfigWidget(cfg.group(QByteArray()).readEntry("configurationType")); - for (const auto &service: offers) { - ComponentSelector->addItem(service->name()); - m_lookupDict.insert(service->name(), service->desktopEntryName()); - m_revLookupDict.insert(service->desktopEntryName(), service->name()); - } + QLabel *label = new QLabel(i18nc("The label for the combobox: browser, terminal emulator...)", "%1:", name), this); + label->setToolTip(cfg.group(QByteArray()).readEntry("Comment", QString())); - KConfig store(mainGroup.readPathEntry("storeInFile",QStringLiteral("null"))); - const KConfigGroup group(&store, mainGroup.readEntry("valueSection")); - QString setting = group.readEntry(mainGroup.readEntry("valueName","kcm_componenchooser_null"), QString()); + formLayout->addRow(label, loadedConfigWidget); - if (setting.isEmpty()) - setting = mainGroup.readEntry("defaultImplementation", QString()); - QString tmp = m_revLookupDict.value(setting); - if (!tmp.isEmpty()) { - for (int i=0;icount();i++) - if (tmp==ComponentSelector->itemText(i)) - { - ComponentSelector->setCurrentIndex(i); - break; - } - } - emit changed(false); -} + connect(loadedConfigWidget, &CfgPlugin::changed, this, &ComponentChooser::emitChanged); -void CfgComponent::defaults() -{ - //todo -} - -bool CfgComponent::isDefaults() const -{ - return false; + configWidgetMap.insert(service, loadedConfigWidget); + } } -//END General kpart based Component selection - - - - - - -ComponentChooser::ComponentChooser(QWidget *parent): - QWidget(parent), Ui::ComponentChooser_UI(), somethingChanged(false), configWidget(nullptr) +CfgPlugin *ComponentChooser::loadConfigWidget(const QString &cfgType) { - setupUi(this); - static_cast(layout())->setRowStretch(1, 1); - - const QStringList directories = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kcm_componentchooser"), QStandardPaths::LocateDirectory); - QStringList services; - for(const QString &directory : directories) { - const QDir dir(directory); - for(const QString &f: dir.entryList(QStringList("*.desktop"))) { - services += dir.absoluteFilePath(f); - } - } - - for (const QString &service : qAsConst(services)) - { - KConfig cfg(service, KConfig::SimpleConfig); - KConfigGroup cg = cfg.group(QByteArray()); - QListWidgetItem *item = new QListWidgetItem( - QIcon::fromTheme(cg.readEntry("Icon",QStringLiteral("preferences-desktop-default-applications"))), - cg.readEntry("Name",i18n("Unknown"))); - item->setData(Qt::UserRole, service); - ServiceChooser->addItem(item); - loadConfigWidget(service, cfg.group(QByteArray()).readEntry("configurationType"), item->text()); - } - ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20); - ServiceChooser->sortItems(); - connect(ServiceChooser,&QListWidget::currentItemChanged,this,&ComponentChooser::slotServiceSelected); - ServiceChooser->setCurrentRow(0); -} + CfgPlugin *loadedConfigWidget = nullptr; -void ComponentChooser::loadConfigWidget(const QString &service, const QString &cfgType, const QString &name) -{ - QWidget *loadedConfigWidget = nullptr; - if (cfgType.isEmpty() || (cfgType == QLatin1String("component"))) - { - loadedConfigWidget = new CfgComponent(configContainer); - static_cast(loadedConfigWidget)->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", name)); - } - else if (cfgType==QLatin1String("internal_email")) - { - loadedConfigWidget = new CfgEmailClient(configContainer); + if (cfgType == QLatin1String("internal_email")) { + loadedConfigWidget = new CfgEmailClient(this); } #ifdef Q_OS_UNIX - else if (cfgType==QLatin1String("internal_terminal")) - { - loadedConfigWidget = new CfgTerminalEmulator(configContainer); + else if (cfgType == QLatin1String("internal_terminal")) { + loadedConfigWidget = new CfgTerminalEmulator(this); } #endif - else if (cfgType==QLatin1String("internal_filemanager")) - { - loadedConfigWidget = new CfgFileManager(configContainer); - } - else if (cfgType==QLatin1String("internal_browser")) - { - loadedConfigWidget = new CfgBrowser(configContainer); - } - - if (loadedConfigWidget) { - configWidgetMap.insert(service, loadedConfigWidget); - configContainer->addWidget(loadedConfigWidget); - connect(loadedConfigWidget, SIGNAL(changed(bool)), this, SLOT(emitChanged(bool))); - } -} - -void ComponentChooser::slotServiceSelected(QListWidgetItem* it) { - if (!it) return; - - if (somethingChanged) { - if (KMessageBox::questionYesNo(this,i18n("You changed the default component of your choice, do want to save that change now ?"),QString(),KStandardGuiItem::save(),KStandardGuiItem::discard())==KMessageBox::Yes) save(); - } - const QString &service = it->data(Qt::UserRole).toString(); - KConfig cfg(service, KConfig::SimpleConfig); - - ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available"))); - ComponentDescription->setMinimumSize(ComponentDescription->sizeHint()); - - configWidget = configWidgetMap.value(service); - if (configWidget) { - configContainer->setCurrentWidget(configWidget); - const auto plugin = dynamic_cast(configWidget); - headerGroupBox->setTitle(it->text()); - plugin->load(&cfg); - emit defaulted(plugin->isDefaults()); - } + else if (cfgType == QLatin1String("internal_filemanager")) { + loadedConfigWidget = new CfgFileManager(this); + } else if (cfgType == QLatin1String("internal_browser")) { + loadedConfigWidget = new CfgBrowser(this); + } else { + Q_ASSERT_X(false, "loadConfigWidget", "cfgType no supported"); + } + loadedConfigWidget->setSizeAdjustPolicy(QComboBox::AdjustToContents); + loadedConfigWidget->setMinimumContentsLength(18); - emitChanged(false); - latestEditedService = service; + return loadedConfigWidget; } +void ComponentChooser::emitChanged() +{ + bool somethingChanged = false; + bool isDefaults = true; + // check if another plugin has changed and default status + for (CfgPlugin *plugin: qAsConst(configWidgetMap)) { + somethingChanged |= plugin->hasChanged(); + isDefaults &= plugin->isDefaults(); + } -void ComponentChooser::emitChanged(bool val) { - somethingChanged=val; - emit changed(val); - - CfgPlugin *plugin = dynamic_cast( configWidget ); - emit defaulted(plugin->isDefaults()); + emit changed(somethingChanged); + emit defaulted(isDefaults); } - ComponentChooser::~ComponentChooser() { - for (QWidget *configWidget : configWidgetMap) { - delete configWidget; + for (QWidget *configWidget : qAsConst(configWidgetMap)) { + delete configWidget; } } void ComponentChooser::load() { - if( configWidget ) - { - CfgPlugin * plugin = dynamic_cast( configWidget ); - if( plugin ) - { - KConfig cfg(latestEditedService, KConfig::SimpleConfig); - plugin->load( &cfg ); - } + for (auto it = configWidgetMap.constBegin(); it != configWidgetMap.constEnd(); ++it) { + + const auto service = it.key(); + const auto widget = it.value(); + + CfgPlugin *plugin = dynamic_cast(widget); + if (plugin) { + KConfig cfg(service, KConfig::SimpleConfig); + plugin->load( &cfg ); + } } } void ComponentChooser::save() { - if( configWidget ) - { - CfgPlugin* plugin = dynamic_cast( configWidget ); - if( plugin ) - { - KConfig cfg(latestEditedService, KConfig::SimpleConfig); + for (auto it = configWidgetMap.constBegin(); it != configWidgetMap.constEnd(); ++it) { + + const auto service = it.key(); + const auto widget = it.value(); + + CfgPlugin *plugin = dynamic_cast(widget); + if (plugin) { + KConfig cfg(service, KConfig::SimpleConfig); plugin->save( &cfg ); } } + + // refresh System configuration cache + KBuildSycocaProgressDialog::rebuildKSycoca(this); } void ComponentChooser::restoreDefault() { - if (configWidget) - { - dynamic_cast(configWidget)->defaults(); - emitChanged(true); + for (CfgPlugin *plugin : qAsConst(configWidgetMap)) { + plugin->defaults(); + emitChanged(); } - -/* - txtEMailClient->setText("kmail"); - chkRunTerminal->setChecked(false); - - // Check if -e is needed, I do not think so - terminalLE->setText("xterm"); //No need for i18n - terminalCB->setChecked(true); - emitChanged(false); -*/ } // vim: sw=4 ts=4 noet diff --git a/kcms/componentchooser/componentchooser_ui.ui b/kcms/componentchooser/componentchooser_ui.ui --- a/kcms/componentchooser/componentchooser_ui.ui +++ b/kcms/componentchooser/componentchooser_ui.ui @@ -10,59 +10,71 @@ 192 - - + + 0 - - - - - 0 - 0 - - - - Here you can change the component program. Components are programs that handle basic tasks, like the terminal emulator, the text editor and the email client. Different KDE applications sometimes need to invoke a console emulator, send a mail or display some text. To do so consistently, these applications always call the same components. You can choose here which programs these components are. - - - Default Component - - - - - - - - - - - - <qt> -<p>This list shows the configurable component types. Click the component you want to configure.</p> -<p>In this dialog you can change KDE default components. Components are programs that handle basic tasks, like the terminal emulator, the text editor and the email client. Different KDE applications sometimes need to invoke a console emulator, send a mail or display some text. To do so consistently, these applications always call the same components. Here you can select which programs these components are.</p> -</qt> - - - true - - - - - - - - 0 - 0 - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - + + 0 + + + 0 + + + 0 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 0 + 0 + + + + + diff --git a/kcms/componentchooser/componentchooserbrowser.h b/kcms/componentchooser/componentchooserbrowser.h --- a/kcms/componentchooser/componentchooserbrowser.h +++ b/kcms/componentchooser/componentchooserbrowser.h @@ -9,35 +9,27 @@ * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundationi * + * published by the Free Software Foundation * * * ***************************************************************************/ #ifndef COMPONENTCHOOSERBROWSER_H #define COMPONENTCHOOSERBROWSER_H -#include "ui_browserconfig_ui.h" #include "componentchooser.h" +#include -class CfgBrowser: public QWidget, public Ui::BrowserConfig_UI, public CfgPlugin +class CfgBrowser: public CfgPlugin { Q_OBJECT public: - CfgBrowser(QWidget *parent); - ~CfgBrowser() override; - void load(KConfig *cfg) override; - void save(KConfig *cfg) override; - void defaults() override; - bool isDefaults() const override; + CfgBrowser(QWidget *parent); + ~CfgBrowser() override; + void load(KConfig *cfg) override; + void save(KConfig *cfg) override; protected Q_SLOTS: void selectBrowser(int index); - -Q_SIGNALS: - void changed(bool); -private: - int m_currentIndex = -1; - int m_falkonIndex = -1; }; #endif /* COMPONENTCHOOSERBROWSER_H */ diff --git a/kcms/componentchooser/componentchooserbrowser.cpp b/kcms/componentchooser/componentchooserbrowser.cpp --- a/kcms/componentchooser/componentchooserbrowser.cpp +++ b/kcms/componentchooser/componentchooserbrowser.cpp @@ -9,15 +9,14 @@ * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundationi * + * published by the Free Software Foundation * * * ***************************************************************************/ #include "componentchooserbrowser.h" #include #include "browser_settings.h" -#include #include #include #include @@ -27,39 +26,37 @@ #include CfgBrowser::CfgBrowser(QWidget *parent) - : QWidget(parent), Ui::BrowserConfig_UI(),CfgPlugin() + : CfgPlugin(parent) { - setupUi(this); - connect(browserCombo, static_cast(&QComboBox::activated), this, &CfgBrowser::selectBrowser); - + connect(this, static_cast(&QComboBox::activated), this, &CfgBrowser::selectBrowser); } CfgBrowser::~CfgBrowser() { } void CfgBrowser::selectBrowser(int index) { - if (index == browserCombo->count() -1) { + if (index == count() -1) { QList urlList; KOpenWithDialog dlg(QStringLiteral("x-scheme-handler/http"), QString(), this); dlg.setSaveNewApplications(true); if (dlg.exec() != QDialog::Accepted) { - browserCombo->setCurrentIndex(m_currentIndex); + setCurrentIndex(m_currentIndex); return; } const auto service = dlg.service(); // check if the selected service is already in the list - const auto matching = browserCombo->model()->match(browserCombo->model()->index(0,0), Qt::UserRole, service->storageId()); + const auto matching = model()->match(model()->index(0,0), Qt::UserRole, service->storageId()); if (!matching.isEmpty()) { const int index = matching.at(0).row(); - browserCombo->setCurrentIndex(index); + setCurrentIndex(index); emit changed(index != m_currentIndex); } else { const QString icon = !service->icon().isEmpty() ? service->icon() : QStringLiteral("application-x-shellscript"); - browserCombo->insertItem(browserCombo->count() -1, QIcon::fromTheme(icon), service->name(), service->storageId()); - browserCombo->setCurrentIndex(browserCombo->count() - 2); + insertItem(count() -1, QIcon::fromTheme(icon), service->name(), service->storageId()); + setCurrentIndex(count() - 2); emit changed(true); } @@ -69,57 +66,45 @@ } } -void CfgBrowser::defaults() -{ - if (m_falkonIndex != -1) { - browserCombo->setCurrentIndex(m_falkonIndex); - } -} - -bool CfgBrowser::isDefaults() const -{ - return m_falkonIndex == -1 || m_falkonIndex == browserCombo->currentIndex(); -} - -void CfgBrowser::load(KConfig *) +void CfgBrowser::load(KConfig *) { const auto browser = KMimeTypeTrader::self()->preferredService("x-scheme-handler/http"); - browserCombo->clear(); + clear(); m_currentIndex = -1; - m_falkonIndex = -1; + m_defaultIndex = -1; const auto constraint = QStringLiteral("'WebBrowser' in Categories and" " ('x-scheme-handler/http' in ServiceTypes or 'x-scheme-handler/https' in ServiceTypes)"); const auto browsers = KServiceTypeTrader::self()->query(QStringLiteral("Application"), constraint); for (const auto &service : browsers) { - browserCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); + addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); if (browser->storageId() == service->storageId()) { - browserCombo->setCurrentIndex(browserCombo->count() - 1); - m_currentIndex = browserCombo->count() - 1; + setCurrentIndex(count() - 1); + m_currentIndex = count() - 1; } if (service->storageId() == QStringLiteral("org.kde.falkon.desktop")) { - m_falkonIndex = browserCombo->count() - 1; + m_defaultIndex = count() - 1; } } if (browser && m_currentIndex == -1) { // we have a browser specified by the user - browserCombo->addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), browser->name(), browser->storageId()); - browserCombo->setCurrentIndex(browserCombo->count() - 1); - m_currentIndex = browserCombo->count() - 1; + addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), browser->name(), browser->storageId()); + setCurrentIndex(count() - 1); + m_currentIndex = count() - 1; } // add a other option to add a new browser - browserCombo->addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other..."), QStringLiteral()); + addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other...")); emit changed(false); } void CfgBrowser::save(KConfig *) { - const QString browserStorageId = browserCombo->currentData().toString(); + const QString browserStorageId = currentData().toString(); BrowserSettings settings; settings.setBrowserApplication(browserStorageId); @@ -133,15 +118,13 @@ defaultApp.writeXdgListEntry(QStringLiteral("x-scheme-handler/https"), QStringList(browserStorageId)); mimeAppList->sync(); - KBuildSycocaProgressDialog::rebuildKSycoca(this); - QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QStringLiteral("org.kde.KLauncher"), QStringLiteral("reparseConfiguration")); QDBusConnection::sessionBus().send(message); - m_currentIndex = browserCombo->currentIndex(); + m_currentIndex = currentIndex(); emit changed(false); } diff --git a/kcms/componentchooser/componentchooseremail.h b/kcms/componentchooser/componentchooseremail.h --- a/kcms/componentchooser/componentchooseremail.h +++ b/kcms/componentchooser/componentchooseremail.h @@ -9,38 +9,32 @@ * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundationi * + * published by the Free Software Foundation * * * ***************************************************************************/ #ifndef COMPONENTCHOOSEREMAIL_H #define COMPONENTCHOOSEREMAIL_H -class KEMailSettings; - -#include "ui_emailclientconfig_ui.h" #include "componentchooser.h" +#include + +class KEMailSettings; -class CfgEmailClient: public QWidget, public Ui::EmailClientConfig_UI, public CfgPlugin +class CfgEmailClient: public CfgPlugin { Q_OBJECT public: CfgEmailClient(QWidget *parent); ~CfgEmailClient() override; void load(KConfig *cfg) override; void save(KConfig *cfg) override; - void defaults() override; - bool isDefaults() const override; private: KEMailSettings *pSettings; - int m_currentIndex = -1; - int m_kmailIndex = -1; protected Q_SLOTS: void selectEmailClient(int index); -Q_SIGNALS: - void changed(bool); }; #endif diff --git a/kcms/componentchooser/componentchooseremail.cpp b/kcms/componentchooser/componentchooseremail.cpp --- a/kcms/componentchooser/componentchooseremail.cpp +++ b/kcms/componentchooser/componentchooseremail.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -39,59 +38,39 @@ } CfgEmailClient::CfgEmailClient(QWidget *parent) - : QWidget(parent), Ui::EmailClientConfig_UI(), CfgPlugin() + : CfgPlugin(parent) { - setupUi( this ); - pSettings = new KEMailSettings(); - connect(emailClientsCombo, static_cast(&QComboBox::activated), this, &CfgEmailClient::selectEmailClient); + connect(this, static_cast(&QComboBox::activated), this, &CfgEmailClient::selectEmailClient); } CfgEmailClient::~CfgEmailClient() { delete pSettings; } -void CfgEmailClient::defaults() -{ - // select kmail if installed - if (m_kmailIndex != -1) { - emailClientsCombo->setCurrentIndex(m_kmailIndex); - } -} - -bool CfgEmailClient::isDefaults() const -{ - // if kmail is installed and is selected - if (m_kmailIndex != -1) { - return emailClientsCombo->currentIndex() == m_kmailIndex; - } - - return true; -} - void CfgEmailClient::load(KConfig *) { const KService::Ptr emailClientService = KMimeTypeTrader::self()->preferredService(s_mimetype); const auto emailClients = KServiceTypeTrader::self()->query(QStringLiteral("Application"), QStringLiteral("'Email' in Categories and 'x-scheme-handler/mailto' in ServiceTypes")); - emailClientsCombo->clear(); - m_kmailIndex = -1; + clear(); m_currentIndex = -1; + m_defaultIndex = -1; for (const auto &service : emailClients) { - emailClientsCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); + addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); if (emailClientService && emailClientService->storageId() == service->storageId()) { - emailClientsCombo->setCurrentIndex(emailClientsCombo->count() - 1); - m_currentIndex = emailClientsCombo->count() - 1; + setCurrentIndex(count() - 1); + m_currentIndex = count() - 1; } if (service->storageId() == QStringLiteral("org.kde.kmail2.desktop") || service->storageId() == QStringLiteral("org.kde.kmail.desktop")) { - m_kmailIndex = emailClientsCombo->count() - 1; + m_defaultIndex = count() - 1; } } @@ -113,41 +92,41 @@ const bool isServiceAlreadyInserted = std::none_of(emailClients.constBegin(), emailClients.constEnd(), [service] (const KService::Ptr &serv) { return service->storageId() == serv->storageId(); }); if (isServiceAlreadyInserted) { const auto icon = QIcon::fromTheme(!service->icon().isEmpty() ? service->icon() : QStringLiteral("application-x-shellscript")); - emailClientsCombo->addItem(icon, service->name() + " (" + KShell::tildeCollapse(service->entryPath()) + ")", service->storageId()); + addItem(icon, service->name() + " (" + KShell::tildeCollapse(service->entryPath()) + ")", service->storageId()); if (emailClientService && emailClientService->storageId() == service->storageId()) { - emailClientsCombo->setCurrentIndex(emailClientsCombo->count() - 1); - m_currentIndex = emailClientsCombo->count() - 1; + setCurrentIndex(count() - 1); + m_currentIndex = count() - 1; } } } // add a other option to add a new email client with KOpenWithDialog - emailClientsCombo->addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other..."), QStringLiteral()); + addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other..."), QStringLiteral()); emit changed(false); } void CfgEmailClient::selectEmailClient(int index) { - if (index == emailClientsCombo->count() -1) { + if (index == count() -1) { // Other option KOpenWithDialog dlg(s_mimetype, QString(), this); dlg.setSaveNewApplications(true); if (dlg.exec() != QDialog::Accepted) { // restore previous setting - emailClientsCombo->setCurrentIndex(m_currentIndex); + setCurrentIndex(m_currentIndex); emit changed(false); } else { const auto service = dlg.service(); const auto icon = QIcon::fromTheme(!service->icon().isEmpty() ? service->icon() : QStringLiteral("application-x-shellscript")); - emailClientsCombo->insertItem(emailClientsCombo->count() - 1, icon, service->name() + " (" + KShell::tildeCollapse(service->entryPath()) + ")", service->storageId()); + insertItem(count() - 1, icon, service->name() + " (" + KShell::tildeCollapse(service->entryPath()) + ")", service->storageId()); // select newly inserted email client - emailClientsCombo->setCurrentIndex(emailClientsCombo->count() - 2); + setCurrentIndex(count() - 2); emit changed(true); return; @@ -159,10 +138,10 @@ void CfgEmailClient::save(KConfig *) { - const QString &storageId = emailClientsCombo->currentData().toString(); + const QString &storageId = currentData().toString(); const KService::Ptr emailClientService = KService::serviceByStorageId(storageId); - const bool kmailSelected = m_kmailIndex != -1 && emailClientsCombo->currentIndex() == m_kmailIndex; + const bool kmailSelected = m_defaultIndex != -1 && currentIndex() == m_defaultIndex; if (kmailSelected) { pSettings->setSetting(KEMailSettings::ClientProgram, QString()); pSettings->setSetting(KEMailSettings::ClientTerminal, QStringLiteral("false")); @@ -189,10 +168,7 @@ profile->sync(); - m_currentIndex = emailClientsCombo->currentIndex(); - - // refresh cache - KBuildSycocaProgressDialog::rebuildKSycoca(this); + m_currentIndex = currentIndex(); emit changed(false); } diff --git a/kcms/componentchooser/componentchooserfilemanager.h b/kcms/componentchooser/componentchooserfilemanager.h --- a/kcms/componentchooser/componentchooserfilemanager.h +++ b/kcms/componentchooser/componentchooserfilemanager.h @@ -21,29 +21,20 @@ #ifndef COMPONENTCHOOSERFILEMANAGER_H #define COMPONENTCHOOSERFILEMANAGER_H -#include "ui_filemanagerconfig_ui.h" #include "componentchooser.h" +#include -class CfgFileManager: public QWidget, public Ui::FileManagerConfig_UI, public CfgPlugin +class CfgFileManager: public CfgPlugin { Q_OBJECT public: CfgFileManager(QWidget *parent); ~CfgFileManager() override; void load(KConfig *cfg) override; void save(KConfig *cfg) override; - void defaults() override; - bool isDefaults() const override; protected Q_SLOTS: void selectFileManager(int index); - -Q_SIGNALS: - void changed(bool); - -private: - int m_currentIndex = -1; - int m_dolphinIndex = -1; }; #endif diff --git a/kcms/componentchooser/componentchooserfilemanager.cpp b/kcms/componentchooser/componentchooserfilemanager.cpp --- a/kcms/componentchooser/componentchooserfilemanager.cpp +++ b/kcms/componentchooser/componentchooserfilemanager.cpp @@ -20,7 +20,6 @@ */ #include "componentchooserfilemanager.h" -#include #include #include #include @@ -30,50 +29,37 @@ #include CfgFileManager::CfgFileManager(QWidget *parent) - : QWidget(parent), Ui::FileManagerConfig_UI(),CfgPlugin() + : CfgPlugin(parent) { - setupUi(this); - connect(combofileManager, static_cast(&QComboBox::activated), this, &CfgFileManager::selectFileManager); + connect(this, static_cast(&QComboBox::activated), this, &CfgFileManager::selectFileManager); } CfgFileManager::~CfgFileManager() { } -void CfgFileManager::defaults() -{ - if (m_dolphinIndex != -1) { - combofileManager->setCurrentIndex(m_dolphinIndex); - } -} - -bool CfgFileManager::isDefaults() const -{ - return m_dolphinIndex == -1 || m_dolphinIndex == combofileManager->currentIndex(); -} - void CfgFileManager::selectFileManager(int index) { - if (index == combofileManager->count() -1) { + if (index == count() -1) { KOpenWithDialog dlg({}, i18n("Select preferred file manager:"), QString(), this); dlg.setSaveNewApplications(true); if (dlg.exec() != QDialog::Accepted) { - combofileManager->setCurrentIndex(m_currentIndex); + setCurrentIndex(m_currentIndex); return; } const auto service = dlg.service(); // if the selected service is already in the list - const auto matching = combofileManager->model()->match(combofileManager->model()->index(0,0), Qt::UserRole, service->storageId()); + const auto matching = model()->match(model()->index(0,0), Qt::UserRole, service->storageId()); if (!matching.isEmpty()) { const int index = matching.at(0).row(); - combofileManager->setCurrentIndex(index); + setCurrentIndex(index); changed(index != m_currentIndex); } else { const QString icon = !service->icon().isEmpty() ? service->icon() : QStringLiteral("application-x-shellscript"); - combofileManager->insertItem(combofileManager->count() -1, QIcon::fromTheme(icon), service->name(), service->storageId()); - combofileManager->setCurrentIndex(combofileManager->count() - 2); + insertItem(count() -1, QIcon::fromTheme(icon), service->name(), service->storageId()); + setCurrentIndex(count() - 2); changed(true); } @@ -86,37 +72,38 @@ void CfgFileManager::load(KConfig *) { - combofileManager->clear(); + clear(); m_currentIndex = -1; + m_defaultIndex = -1; const KService::Ptr fileManager = KMimeTypeTrader::self()->preferredService(mime); const auto constraint = QStringLiteral("'FileManager' in Categories and 'inode/directory' in ServiceTypes"); const KService::List fileManagers = KServiceTypeTrader::self()->query(QStringLiteral("Application"), constraint); for (const KService::Ptr &service : fileManagers) { - combofileManager->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); + addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); if (fileManager->storageId() == service->storageId()) { - combofileManager->setCurrentIndex(combofileManager->count() -1); - m_currentIndex = combofileManager->count() -1; + setCurrentIndex(count() -1); + m_currentIndex = count() -1; } if (service->storageId() == QStringLiteral("org.kde.dolphin.desktop")) { - m_dolphinIndex = combofileManager->count() -1; + m_defaultIndex = count() -1; } } // in case of a service not associated with FileManager Category if (m_currentIndex == -1 && !fileManager->storageId().isEmpty()) { const KService::Ptr service = KService::serviceByStorageId(fileManager->storageId()); const QString icon = !service->icon().isEmpty() ? service->icon() : QStringLiteral("application-x-shellscript"); - combofileManager->addItem(QIcon::fromTheme(icon), service->name(), service->storageId()); - combofileManager->setCurrentIndex(combofileManager->count() -1); - m_currentIndex = combofileManager->count() -1; + addItem(QIcon::fromTheme(icon), service->name(), service->storageId()); + setCurrentIndex(count() -1); + m_currentIndex = count() -1; } // add a other option to add a new file manager with KOpenWithDialog - combofileManager->addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other..."), QStringLiteral()); + addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other..."), QStringLiteral()); emit changed(false); } @@ -126,10 +113,9 @@ void CfgFileManager::save(KConfig *) { - const QString storageId = combofileManager->currentData().toString(); + const QString storageId = currentData().toString(); if (!storageId.isEmpty()) { - - m_currentIndex = combofileManager->currentIndex(); + m_currentIndex = currentIndex(); // This is taken from filetypes/mimetypedata.cpp KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); @@ -147,7 +133,6 @@ profile->sync(); - KBuildSycocaProgressDialog::rebuildKSycoca(this); emit changed(false); } } diff --git a/kcms/componentchooser/componentchooserterminal.h b/kcms/componentchooser/componentchooserterminal.h --- a/kcms/componentchooser/componentchooserterminal.h +++ b/kcms/componentchooser/componentchooserterminal.h @@ -9,39 +9,30 @@ * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundationi * + * published by the Free Software Foundation * * * ***************************************************************************/ #ifndef _COMPONENTCHOOSERTERMINAL_H_ #define _COMPONENTCHOOSERTERMINAL_H_ -#include "ui_terminalemulatorconfig_ui.h" #include "componentchooser.h" +#include + class KConfig; class CfgPlugin; -class CfgTerminalEmulator: public QWidget, public Ui::TerminalEmulatorConfig_UI, public CfgPlugin +class CfgTerminalEmulator: public CfgPlugin { Q_OBJECT public: - CfgTerminalEmulator(QWidget *parent); - ~CfgTerminalEmulator() override; - void load(KConfig *cfg) override; - void save(KConfig *cfg) override; - void defaults() override; - bool isDefaults() const override; - + CfgTerminalEmulator(QWidget *parent); + ~CfgTerminalEmulator() override; + void load(KConfig *cfg) override; + void save(KConfig *cfg) override; protected Q_SLOTS: void selectTerminalApp(); void selectTerminalEmulator(int index); - -Q_SIGNALS: - void changed(bool); - -private: - int m_currentIndex = -1; - int m_konsoleIndex = -1; }; #endif diff --git a/kcms/componentchooser/componentchooserterminal.cpp b/kcms/componentchooser/componentchooserterminal.cpp --- a/kcms/componentchooser/componentchooserterminal.cpp +++ b/kcms/componentchooser/componentchooserterminal.cpp @@ -34,80 +34,70 @@ #include CfgTerminalEmulator::CfgTerminalEmulator(QWidget *parent) - : QWidget(parent), Ui::TerminalEmulatorConfig_UI(), CfgPlugin() + : CfgPlugin(parent) { - setupUi(this); - connect(terminalCombo, static_cast(&QComboBox::activated), this, &CfgTerminalEmulator::selectTerminalEmulator); + connect(this, static_cast(&QComboBox::activated), this, &CfgTerminalEmulator::selectTerminalEmulator); } CfgTerminalEmulator::~CfgTerminalEmulator() { } void CfgTerminalEmulator::selectTerminalEmulator(int index) { - if (index == terminalCombo->count() - 1) { + if (index == count() - 1) { selectTerminalApp(); } else { emit changed(m_currentIndex != index); } } -void CfgTerminalEmulator::defaults() -{ - if (m_konsoleIndex != -1) { - terminalCombo->setCurrentIndex(m_konsoleIndex); - } -} - -bool CfgTerminalEmulator::isDefaults() const -{ - return m_konsoleIndex == -1 || m_konsoleIndex == terminalCombo->currentIndex(); -} - void CfgTerminalEmulator::load(KConfig *) { TerminalSettings settings; const QString terminal = settings.terminalApplication(); + clear(); m_currentIndex = -1; - terminalCombo->clear(); + m_defaultIndex = -1; const auto constraint = QStringLiteral("'TerminalEmulator' in Categories AND (not exist NoDisplay OR NoDisplay == false)"); const auto terminalEmulators = KServiceTypeTrader::self()->query(QStringLiteral("Application"), constraint); for (const auto &service : terminalEmulators) { - terminalCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->exec()); + addItem(QIcon::fromTheme(service->icon()), service->name(), service->exec()); if (!terminal.isEmpty() && service->exec() == terminal) { - terminalCombo->setCurrentIndex(terminalCombo->count() - 1); - m_currentIndex = terminalCombo->count() - 1; + setCurrentIndex(count() - 1); + m_currentIndex = count() - 1; } if (service->exec() == QStringLiteral("konsole")) { - m_konsoleIndex = terminalCombo->count() - 1; + m_defaultIndex = count() - 1; } } if (!terminal.isEmpty() && m_currentIndex == -1) { // we have a terminal specified by the user - terminalCombo->addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), terminal, terminal); - terminalCombo->setCurrentIndex(terminalCombo->count() - 1); - m_currentIndex = terminalCombo->count() - 1; + addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), terminal, terminal); + setCurrentIndex(count() - 1); + m_currentIndex = count() - 1; } // add a other option to add a new terminal emulator with KOpenWithDialog - terminalCombo->addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other..."), QStringLiteral()); + addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other..."), QStringLiteral()); emit changed(false); } void CfgTerminalEmulator::save(KConfig *) { - const QString terminal = terminalCombo->currentData().toString(); - m_currentIndex = terminalCombo->currentIndex(); + const QString terminal = currentData().toString(); + m_currentIndex = currentIndex(); TerminalSettings settings; settings.setTerminalApplication(terminal); settings.save(); + m_currentIndex = currentIndex(); + QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QStringLiteral("org.kde.KLauncher"), @@ -124,21 +114,21 @@ dlg.hideRunInTerminal(); dlg.setSaveNewApplications(true); if (dlg.exec() != QDialog::Accepted) { - terminalCombo->setCurrentIndex(m_currentIndex); + setCurrentIndex(m_currentIndex); return; } const auto service = dlg.service(); // if the selected service is already in the list - const auto matching = terminalCombo->model()->match(terminalCombo->model()->index(0,0), Qt::DisplayRole, service->exec()); + const auto matching = model()->match(model()->index(0,0), Qt::DisplayRole, service->exec()); if (!matching.isEmpty()) { const int index = matching.at(0).row(); - terminalCombo->setCurrentIndex(index); + setCurrentIndex(index); changed(index != m_currentIndex); } else { const QString icon = !service->icon().isEmpty() ? service->icon() : QStringLiteral("application-x-shellscript"); - terminalCombo->insertItem(terminalCombo->count() -1, QIcon::fromTheme(icon), service->name(), service->exec()); - terminalCombo->setCurrentIndex(terminalCombo->count() - 2); + insertItem(count() -1, QIcon::fromTheme(icon), service->name(), service->exec()); + setCurrentIndex(count() - 2); changed(true); } diff --git a/kcms/componentchooser/componentconfig_ui.ui b/kcms/componentchooser/componentconfig_ui.ui deleted file mode 100644 --- a/kcms/componentchooser/componentconfig_ui.ui +++ /dev/null @@ -1,49 +0,0 @@ - - - ComponentConfig_UI - - - - 0 - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 0 - 20 - - - - - - - - - KComboBox - QComboBox -
KComboBox
-
-
- - -
diff --git a/kcms/componentchooser/emailclientconfig_ui.ui b/kcms/componentchooser/emailclientconfig_ui.ui deleted file mode 100644 --- a/kcms/componentchooser/emailclientconfig_ui.ui +++ /dev/null @@ -1,69 +0,0 @@ - - - EmailClientConfig_UI - - - - 0 - 0 - 240 - 148 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 0 - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 0 - 20 - - - - - - - - - diff --git a/kcms/componentchooser/filemanagerconfig_ui.ui b/kcms/componentchooser/filemanagerconfig_ui.ui deleted file mode 100644 --- a/kcms/componentchooser/filemanagerconfig_ui.ui +++ /dev/null @@ -1,46 +0,0 @@ - - - FileManagerConfig_UI - - - - 0 - 0 - 339 - 94 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - Qt::Vertical - - - - 0 - 20 - - - - - - - - - diff --git a/kcms/componentchooser/kcm_componentchooser.h b/kcms/componentchooser/kcm_componentchooser.h --- a/kcms/componentchooser/kcm_componentchooser.h +++ b/kcms/componentchooser/kcm_componentchooser.h @@ -21,7 +21,7 @@ #include "componentchooser.h" -class KCMComponentChooser : public KCModule +class KCMComponentChooser: public KCModule { Q_OBJECT public: diff --git a/kcms/componentchooser/kcm_componentchooser.cpp b/kcms/componentchooser/kcm_componentchooser.cpp --- a/kcms/componentchooser/kcm_componentchooser.cpp +++ b/kcms/componentchooser/kcm_componentchooser.cpp @@ -39,13 +39,13 @@ connect(m_chooser,SIGNAL(changed(bool)),this,SIGNAL(changed(bool))); connect(m_chooser, &ComponentChooser::defaulted, this, &KCModule::defaulted); - KAboutData *about = - new KAboutData( QStringLiteral("kcmcomponentchooser"), i18n("Component Chooser"), QStringLiteral("1.0"), - QString(), KAboutLicense::GPL, - i18n("(c), 2002 Joseph Wenninger")); + KAboutData *about = new KAboutData( QStringLiteral("kcmcomponentchooser"), i18n("Component Chooser"), QStringLiteral("1.0"), + QString(), KAboutLicense::GPL, + i18n("(c), 2002 Joseph Wenninger")); - about->addAuthor(i18n("Joseph Wenninger"), QString() , QStringLiteral("jowenn@kde.org")); - setAboutData( about ); + about->addAuthor(i18n("Joseph Wenninger"), QString() , QStringLiteral("jowenn@kde.org")); + about->addAuthor(i18n("Méven Car"), QString() , QStringLiteral("meven.car@kdemail.net")); + setAboutData( about ); } void KCMComponentChooser::load(){ diff --git a/kcms/componentchooser/terminalemulatorconfig_ui.ui b/kcms/componentchooser/terminalemulatorconfig_ui.ui deleted file mode 100644 --- a/kcms/componentchooser/terminalemulatorconfig_ui.ui +++ /dev/null @@ -1,49 +0,0 @@ - - - TerminalEmulatorConfig_UI - - - - 0 - 0 - 246 - 118 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 0 - 20 - - - - - - - - -