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 @@ -17,50 +17,30 @@ #define _COMPONENTCHOOSER_H_ #include "ui_componentchooser_ui.h" -#include "ui_componentconfig_ui.h" #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 { public: - CfgPlugin(){} + CfgPlugin(){} virtual ~CfgPlugin(){} virtual void load(KConfig *cfg)=0; virtual void save(KConfig *cfg)=0; - virtual void defaults()=0; - virtual bool isDefaults() const=0; -}; - -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; - -protected: - QHash m_lookupDict,m_revLookupDict; + virtual void defaults()=0; + virtual bool isDefaults() const=0; + virtual bool hasChanged() const=0; -protected Q_SLOTS: - void slotComponentChanged(const QString&); -Q_SIGNALS: - void changed(bool); - void defaulted(bool); }; class ComponentChooser : public QWidget, public Ui::ComponentChooser_UI @@ -76,22 +56,16 @@ void restoreDefault(); private: - QString latestEditedService; - bool somethingChanged; - QWidget *configWidget; - QVBoxLayout *myLayout; QMap configWidgetMap; - void loadConfigWidget(const QString &, const QString &, const QString &); + QWidget *loadConfigWidget(const QString &cfgType); protected Q_SLOTS: void emitChanged(bool); - void slotServiceSelected(QListWidgetItem *); 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 @@ -34,98 +34,15 @@ #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() -{ -} - -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) { - - ComponentSelector->clear(); - m_lookupDict.clear(); - m_revLookupDict.clear(); - - const KConfigGroup mainGroup = cfg->group(QByteArray()); - const QString serviceTypeToConfigure = mainGroup.readEntry("ServiceTypeToConfigure"); - - const KService::List offers = KServiceTypeTrader::self()->query(serviceTypeToConfigure); - - for (const auto &service: offers) { - ComponentSelector->addItem(service->name()); - m_lookupDict.insert(service->name(), service->desktopEntryName()); - m_revLookupDict.insert(service->desktopEntryName(), service->name()); - } - - 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()); - - 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); -} - -void CfgComponent::defaults() -{ - //todo -} - -bool CfgComponent::isDefaults() const -{ - return false; -} - -//END General kpart based Component selection - - - - +#include ComponentChooser::ComponentChooser(QWidget *parent): - QWidget(parent), Ui::ComponentChooser_UI(), somethingChanged(false), configWidget(nullptr) + QWidget(parent), Ui::ComponentChooser_UI() { setupUi(this); - static_cast(layout())->setRowStretch(1, 1); const QStringList directories = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kcm_componentchooser"), QStandardPaths::LocateDirectory); QStringList services; @@ -139,136 +56,109 @@ 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); + KConfigGroup cg = cfg.group(QByteArray()); + + // fill the form layout + const auto name = cg.readEntry("Name",i18n("Unknown")); + const auto loadedConfigWidget = loadConfigWidget(cfg.group(QByteArray()).readEntry("configurationType")); + + QLabel *label = new QLabel(i18nc("The label for the combobox : browser, terminal emulator...)", "%1:", name), this); + label->setToolTip(cfg.group(QByteArray()).readEntry("Comment", QString())); + + formLayout->addRow(label, loadedConfigWidget); + + connect(loadedConfigWidget, SIGNAL(changed(bool)), this, SLOT(emitChanged(bool))); + + configWidgetMap.insert(service, loadedConfigWidget); + } } -void ComponentChooser::loadConfigWidget(const QString &service, const QString &cfgType, const QString &name) +QWidget *ComponentChooser::loadConfigWidget(const QString &cfgType) { - 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); + QComboBox *loadedConfigWidget = nullptr; + + 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); - } + else if (cfgType==QLatin1String("internal_filemanager")) { + loadedConfigWidget = new CfgFileManager(this); + } else if (cfgType==QLatin1String("internal_browser")) { + loadedConfigWidget = new CfgBrowser(this); + } + loadedConfigWidget->setSizeAdjustPolicy(QComboBox::AdjustToContents); - if (loadedConfigWidget) { - configWidgetMap.insert(service, loadedConfigWidget); - configContainer->addWidget(loadedConfigWidget); - connect(loadedConfigWidget, SIGNAL(changed(bool)), this, SLOT(emitChanged(bool))); - } + return loadedConfigWidget; } -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()); - } - - emitChanged(false); - latestEditedService = service; -} +void ComponentChooser::emitChanged(bool val) { + bool somethingChanged = val; + if (!somethingChanged) { + // check if another plugin has changed + for (auto it= configWidgetMap.constKeyValueBegin(); it != configWidgetMap.constKeyValueEnd(); ++it) { + CfgPlugin *plugin = dynamic_cast( (*it).second ); + somethingChanged |= plugin->hasChanged(); + } + } + emit changed(somethingChanged); -void ComponentChooser::emitChanged(bool val) { - somethingChanged=val; - emit changed(val); + bool isDefault = true; + for (auto it= configWidgetMap.constKeyValueBegin(); it != configWidgetMap.constKeyValueEnd(); ++it) { + CfgPlugin *plugin = dynamic_cast( (*it).second ); + isDefault &= plugin->isDefaults(); + } - CfgPlugin *plugin = dynamic_cast( configWidget ); - emit defaulted(plugin->isDefaults()); + emit defaulted(isDefault); } - ComponentChooser::~ComponentChooser() { - for (QWidget *configWidget : configWidgetMap) { - delete configWidget; + for (QWidget *configWidget : 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.constKeyValueBegin(); it != configWidgetMap.constKeyValueEnd(); ++it) { + + const auto service = (*it).first; + const auto widget = (*it).second; + + 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.constKeyValueBegin(); it != configWidgetMap.constKeyValueEnd(); ++it){ + + const auto service = (*it).first; + const auto widget = (*it).second; + + 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) - { + for (const auto &configWidget : configWidgetMap) { dynamic_cast(configWidget)->defaults(); emitChanged(true); } - -/* - 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 @@ -16,10 +16,10 @@ #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 QComboBox, public CfgPlugin { Q_OBJECT public: @@ -29,12 +29,13 @@ void save(KConfig *cfg) override; void defaults() override; bool isDefaults() const override; + bool hasChanged() const override; protected Q_SLOTS: void selectBrowser(int index); Q_SIGNALS: - void changed(bool); + void changed(bool); private: int m_currentIndex = -1; int m_falkonIndex = -1; diff --git a/kcms/componentchooser/componentchooserbrowser.cpp b/kcms/componentchooser/componentchooserbrowser.cpp --- a/kcms/componentchooser/componentchooserbrowser.cpp +++ b/kcms/componentchooser/componentchooserbrowser.cpp @@ -17,7 +17,6 @@ #include #include "browser_settings.h" -#include #include #include #include @@ -27,39 +26,37 @@ #include CfgBrowser::CfgBrowser(QWidget *parent) - : QWidget(parent), Ui::BrowserConfig_UI(),CfgPlugin() + : QComboBox(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); } @@ -72,54 +69,59 @@ void CfgBrowser::defaults() { if (m_falkonIndex != -1) { - browserCombo->setCurrentIndex(m_falkonIndex); + setCurrentIndex(m_falkonIndex); } } bool CfgBrowser::isDefaults() const { - return m_falkonIndex == -1 || m_falkonIndex == browserCombo->currentIndex(); + return m_falkonIndex == -1 || m_falkonIndex == currentIndex(); +} + +bool CfgBrowser::hasChanged() const +{ + return m_currentIndex != -1 && m_currentIndex != currentIndex(); } void CfgBrowser::load(KConfig *) { const auto browser = KMimeTypeTrader::self()->preferredService("x-scheme-handler/http"); - browserCombo->clear(); + clear(); m_currentIndex = -1; m_falkonIndex = -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_falkonIndex = 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..."), QStringLiteral()); 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 +135,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 @@ -16,12 +16,12 @@ #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 QComboBox, public CfgPlugin { Q_OBJECT public: @@ -31,6 +31,7 @@ void save(KConfig *cfg) override; void defaults() override; bool isDefaults() const override; + bool hasChanged() const override; private: KEMailSettings *pSettings; 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,13 +38,11 @@ } CfgEmailClient::CfgEmailClient(QWidget *parent) - : QWidget(parent), Ui::EmailClientConfig_UI(), CfgPlugin() + : QComboBox(parent), CfgPlugin() { - 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() { @@ -56,42 +53,47 @@ { // select kmail if installed if (m_kmailIndex != -1) { - emailClientsCombo->setCurrentIndex(m_kmailIndex); + setCurrentIndex(m_kmailIndex); } } bool CfgEmailClient::isDefaults() const { // if kmail is installed and is selected if (m_kmailIndex != -1) { - return emailClientsCombo->currentIndex() == m_kmailIndex; + return currentIndex() == m_kmailIndex; } return true; } +bool CfgEmailClient::hasChanged() const +{ + return m_currentIndex != -1 && m_currentIndex != currentIndex(); +} + 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(); + clear(); m_kmailIndex = -1; m_currentIndex = -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_kmailIndex = count() - 1; } } @@ -113,41 +115,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 +161,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_kmailIndex != -1 && currentIndex() == m_kmailIndex; if (kmailSelected) { pSettings->setSetting(KEMailSettings::ClientProgram, QString()); pSettings->setSetting(KEMailSettings::ClientTerminal, QStringLiteral("false")); @@ -189,10 +191,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,10 +21,10 @@ #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 QComboBox, public CfgPlugin { Q_OBJECT public: @@ -34,6 +34,7 @@ void save(KConfig *cfg) override; void defaults() override; bool isDefaults() const override; + bool hasChanged() const override; protected Q_SLOTS: void selectFileManager(int index); 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,54 @@ #include CfgFileManager::CfgFileManager(QWidget *parent) - : QWidget(parent), Ui::FileManagerConfig_UI(),CfgPlugin() + : QComboBox(parent),CfgPlugin() { - 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); + setCurrentIndex(m_dolphinIndex); } } bool CfgFileManager::isDefaults() const { - return m_dolphinIndex == -1 || m_dolphinIndex == combofileManager->currentIndex(); + return m_dolphinIndex == -1 || m_dolphinIndex == currentIndex(); +} + +bool CfgFileManager::hasChanged() const +{ + return m_currentIndex != -1 && m_currentIndex != 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 +89,37 @@ void CfgFileManager::load(KConfig *) { - combofileManager->clear(); + clear(); m_currentIndex = -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_dolphinIndex = 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 +129,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 +149,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 @@ -16,12 +16,13 @@ #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 QComboBox, public CfgPlugin { Q_OBJECT public: @@ -31,6 +32,7 @@ void save(KConfig *cfg) override; void defaults() override; bool isDefaults() const override; + bool hasChanged() const override; protected Q_SLOTS: void selectTerminalApp(); diff --git a/kcms/componentchooser/componentchooserterminal.cpp b/kcms/componentchooser/componentchooserterminal.cpp --- a/kcms/componentchooser/componentchooserterminal.cpp +++ b/kcms/componentchooser/componentchooserterminal.cpp @@ -34,18 +34,17 @@ #include CfgTerminalEmulator::CfgTerminalEmulator(QWidget *parent) - : QWidget(parent), Ui::TerminalEmulatorConfig_UI(), CfgPlugin() + : QComboBox(parent), CfgPlugin() { - 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); @@ -55,59 +54,65 @@ void CfgTerminalEmulator::defaults() { if (m_konsoleIndex != -1) { - terminalCombo->setCurrentIndex(m_konsoleIndex); + setCurrentIndex(m_konsoleIndex); } } bool CfgTerminalEmulator::isDefaults() const { - return m_konsoleIndex == -1 || m_konsoleIndex == terminalCombo->currentIndex(); + return m_konsoleIndex == -1 || m_konsoleIndex == currentIndex(); } +bool CfgTerminalEmulator::hasChanged() const +{ + return m_currentIndex != -1 && m_currentIndex != currentIndex(); +} void CfgTerminalEmulator::load(KConfig *) { TerminalSettings settings; const QString terminal = settings.terminalApplication(); m_currentIndex = -1; - terminalCombo->clear(); + clear(); 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_konsoleIndex = 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 +129,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,12 +39,12 @@ 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"), + KAboutData *about = new KAboutData( QStringLiteral("kcmcomponentchooser"), i18n("Component Chooser"), QStringLiteral("1.0"), QString(), KAboutLicense::GPL, - i18n("(c), 2002 Joseph Wenninger")); + i18n("(c), 2002 Joseph Wenninger")); about->addAuthor(i18n("Joseph Wenninger"), QString() , QStringLiteral("jowenn@kde.org")); + about->addAuthor(i18n("Méven Car"), QString() , QStringLiteral("meven.car@kdemail.net")); setAboutData( about ); } 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 - - - - - - - - -