Commit f55252fb authored by Méven Car's avatar Méven Car Committed by Méven Car

KCM/Component Refactor UI to a single list of combobox

Summary:
Refactor UI to a single list of Combobox:
 * Simplify code

Test Plan:
Before:
{F7894383}

After:

{F7930030}

In systemsettings :
{F7930035}

Reviewers: #plasma, #vdg, ngraham, ervin

Reviewed By: #vdg, ngraham, ervin

Subscribers: filipf, broulik, plasma-devel

Tags: #plasma

Maniphest Tasks: T12551

Differential Revision: https://phabricator.kde.org/D26797
parent 8eb9e9b7
......@@ -19,12 +19,7 @@ kconfig_add_kcfg_files(kcm_componentchooser_SRCS browser_settings.kcfgc GENERATE
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})
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BrowserConfig_UI</class>
<widget class="QWidget" name="BrowserConfig_UI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>218</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="browserCombo"/>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
This diff is collapsed.
/***************************************************************************
componentchooser.h - description
-------------------
copyright : (C) 2002 by Joseph Wenninger
email : jowenn@kde.org
copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
copyright : (C) 2020 by Méven Car <meven.car@enioka.com>
***************************************************************************/
/***************************************************************************
* *
* 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 *
* *
***************************************************************************/
......@@ -17,50 +17,49 @@
#define _COMPONENTCHOOSER_H_
#include "ui_componentchooser_ui.h"
#include "ui_componentconfig_ui.h"
#include <QHash>
#include <QVBoxLayout>
#include <QComboBox>
#include <kservice.h>
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<QString, QString> 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 @@ public:
void restoreDefault();
private:
QString latestEditedService;
bool somethingChanged;
QWidget *configWidget;
QVBoxLayout *myLayout;
QMap<QString, QWidget*> configWidgetMap;
QMap<QString, CfgPlugin*> 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);
};
......
......@@ -10,59 +10,71 @@
<height>192</height>
</rect>
</property>
<layout class="QGridLayout">
<property name="margin">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<item row="2" column="1">
<widget class="QGroupBox" name="headerGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>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.</string>
</property>
<property name="title">
<string>Default Component</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QStackedWidget" name="configContainer"/>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" rowspan="3">
<widget class="QListWidget" name="ServiceChooser">
<property name="whatsThis">
<string>&lt;qt&gt;
&lt;p&gt;This list shows the configurable component types. Click the component you want to configure.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;/qt&gt;</string>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="ComponentDescription">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
......
......@@ -9,7 +9,7 @@
* *
* 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 *
* *
***************************************************************************/
......@@ -17,7 +17,6 @@
#include <kopenwithdialog.h>
#include "browser_settings.h"
#include <KBuildSycocaProgressDialog>
#include <KLocalizedString>
#include <KServiceTypeTrader>
#include <KMimeTypeTrader>
......@@ -27,11 +26,9 @@
#include <QDBusMessage>
CfgBrowser::CfgBrowser(QWidget *parent)
: QWidget(parent), Ui::BrowserConfig_UI(),CfgPlugin()
: CfgPlugin(parent)
{
setupUi(this);
connect(browserCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), this, &CfgBrowser::selectBrowser);
connect(this, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), this, &CfgBrowser::selectBrowser);
}
CfgBrowser::~CfgBrowser() {
......@@ -39,27 +36,27 @@ CfgBrowser::~CfgBrowser() {
void CfgBrowser::selectBrowser(int index)
{
if (index == browserCombo->count() -1) {
if (index == count() -1) {
QList<QUrl> 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::selectBrowser(int index)
}
}
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 @@ void CfgBrowser::save(KConfig *)
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);
}
......
......@@ -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 <QComboBox>
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 */
......
......@@ -23,7 +23,6 @@
#include <KSharedConfig>
#include <KService>
#include <KServiceTypeTrader>
#include <KBuildSycocaProgressDialog>
#include <KMimeTypeTrader>
#include <KShell>
......@@ -39,37 +38,17 @@ namespace {
}
CfgEmailClient::CfgEmailClient(QWidget *parent)
: QWidget(parent), Ui::EmailClientConfig_UI(), CfgPlugin()
: CfgPlugin(parent)
{
setupUi( this );
pSettings = new KEMailSettings();
connect(emailClientsCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), this, &CfgEmailClient::selectEmailClient);
connect(this, static_cast<void(QComboBox::*)(int)>(&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);
......@@ -77,21 +56,21 @@ void CfgEmailClient::load(KConfig *)
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,24 +92,24 @@ void CfgEmailClient::load(KConfig *)
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);
......@@ -138,16 +117,16 @@ void CfgEmailClient::selectEmailClient(int index)
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"));