Commit 84a298e3 authored by Cyril Rossi's avatar Cyril Rossi

KCM Componentchooser highlight non default settings

parent b07cc50e
......@@ -8,6 +8,7 @@ set(componentchooser_SRCS
componentchooseremail.cpp
componentchooserterminal.cpp
componentchooserfilemanager.cpp
componentchooserdata.cpp
)
kconfig_add_kcfg_files(componentchooser_SRCS browser_settings.kcfgc GENERATE_MOC)
......@@ -23,6 +24,7 @@ target_link_libraries(kcm_componentchooser
KF5::Service
KF5::KIOWidgets
KF5::ConfigGui
KF5::KCMUtils
)
kcoreaddons_desktop_to_json(kcm_componentchooser "package/metadata.desktop")
......
......@@ -94,6 +94,7 @@ void ComponentChooser::load()
m_previousApplication = m_applications[m_index].toMap()["storageId"].toString();
Q_EMIT applicationsChanged();
Q_EMIT indexChanged();
Q_EMIT isDefaultsChanged();
}
void ComponentChooser::select(int index)
......@@ -108,6 +109,7 @@ void ComponentChooser::select(int index)
connect(dialog, &KOpenWithDialog::finished, this, [this, dialog] (int result) {
if (result == QDialog::Rejected) {
Q_EMIT indexChanged();
Q_EMIT isDefaultsChanged();
return;
}
......@@ -117,6 +119,7 @@ void ComponentChooser::select(int index)
if (m_applications[i].toMap()["storageId"] == service->storageId()) {
m_index = i;
Q_EMIT indexChanged();
Q_EMIT isDefaultsChanged();
return;
}
}
......@@ -130,12 +133,14 @@ void ComponentChooser::select(int index)
m_index = m_applications.length() - 2;
Q_EMIT applicationsChanged();
Q_EMIT indexChanged();
Q_EMIT isDefaultsChanged();
});
dialog->open();
} else {
m_index = index;
}
Q_EMIT indexChanged();
Q_EMIT isDefaultsChanged();
}
void ComponentChooser::saveMimeTypeAssociation(const QString &mime, const QString &storageId)
......
......@@ -32,6 +32,7 @@ class ComponentChooser : public QObject
Q_OBJECT
Q_PROPERTY(QVariantList applications MEMBER m_applications NOTIFY applicationsChanged)
Q_PROPERTY(int index MEMBER m_index NOTIFY indexChanged)
Q_PROPERTY(bool isDefaults READ isDefaults NOTIFY isDefaultsChanged)
public:
......@@ -48,10 +49,12 @@ public:
virtual void save() = 0;
void saveMimeTypeAssociation(const QString &mime, const QString &storageId);
bool isDefault() const;
Q_SIGNALS:
void applicationsChanged();
void indexChanged();
void isDefaultsChanged();
protected:
QVariantList m_applications;
......
/***************************************************************************
* Copyright (C) 2020 Cyril Rossi <cyril.rossi@enioka.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
***************************************************************************/
#include "componentchooserdata.h"
#include "componentchooserbrowser.h"
#include "componentchooserfilemanager.h"
#include "componentchooserterminal.h"
#include "componentchooseremail.h"
ComponentChooserData::ComponentChooserData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_browsers(new ComponentChooserBrowser(this))
, m_fileManagers(new ComponentChooserFileManager(this))
, m_terminalEmulators(new ComponentChooserTerminal(this))
, m_emailClients(new ComponentChooserEmail(this))
{
load();
}
void ComponentChooserData::load()
{
m_browsers->load();
m_fileManagers->load();
m_terminalEmulators->load();
m_emailClients->load();
}
void ComponentChooserData::save()
{
m_browsers->save();
m_fileManagers->save();
m_terminalEmulators->save();
m_emailClients->save();
}
void ComponentChooserData::defaults()
{
m_browsers->defaults();
m_fileManagers->defaults();
m_terminalEmulators->defaults();
m_emailClients->defaults();
}
bool ComponentChooserData::isDefaults() const
{
return m_browsers->isDefaults() && m_fileManagers->isDefaults() && m_terminalEmulators->isDefaults() && m_emailClients->isDefaults();
}
bool ComponentChooserData::isSaveNeeded() const
{
return m_browsers->isSaveNeeded() || m_fileManagers->isSaveNeeded() || m_terminalEmulators->isSaveNeeded() || m_emailClients->isSaveNeeded();
}
ComponentChooser *ComponentChooserData::browsers() const
{
return m_browsers;
}
ComponentChooser *ComponentChooserData::fileManagers() const
{
return m_fileManagers;
}
ComponentChooser *ComponentChooserData::terminalEmulators() const
{
return m_terminalEmulators;
}
ComponentChooser *ComponentChooserData::emailClients() const
{
return m_emailClients;
}
/***************************************************************************
* Copyright (C) 2020 Cyril Rossi <cyril.rossi@enioka.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
***************************************************************************/
#ifndef COMPONENTCHOOSERDATA_H
#define COMPONENTCHOOSERDATA_H
#include <QObject>
#include <KCModuleData>
class ComponentChooser;
class ComponentChooserData : public KCModuleData
{
public:
ComponentChooserData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
void load();
void save();
void defaults();
bool isDefaults() const override;
bool isSaveNeeded() const;
ComponentChooser *browsers() const;
ComponentChooser *fileManagers() const;
ComponentChooser *terminalEmulators() const;
ComponentChooser *emailClients() const;
private:
ComponentChooser *m_browsers;
ComponentChooser *m_fileManagers;
ComponentChooser *m_terminalEmulators;
ComponentChooser *m_emailClients;
};
#endif // COMPONENTCHOOSERDATA_H
......@@ -41,7 +41,6 @@ void ComponentChooserTerminal::load()
bool preferredServiceAdded = false;
TerminalSettings settings;
QString preferredService = settings.terminalApplication();
KApplicationTrader::query([&preferredServiceAdded, preferredService, this](const KService::Ptr &service) {
......@@ -93,6 +92,7 @@ void ComponentChooserTerminal::load()
m_previousApplication = m_applications[m_index].toMap()["storageId"].toString();
Q_EMIT applicationsChanged();
Q_EMIT indexChanged();
Q_EMIT isDefaultsChanged();
}
void ComponentChooserTerminal::save()
......
......@@ -28,11 +28,13 @@
#include "componentchooserfilemanager.h"
#include "componentchooserterminal.h"
#include "componentchooseremail.h"
#include "componentchooserdata.h"
K_PLUGIN_CLASS_WITH_JSON(KcmComponentChooser, "metadata.json")
K_PLUGIN_FACTORY_WITH_JSON(KcmComponentChooserFactory, "metadata.json", registerPlugin<KcmComponentChooser>(); registerPlugin<ComponentChooserData>();)
KcmComponentChooser::KcmComponentChooser(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_data(new ComponentChooserData(this))
{
KAboutData *aboutData = new KAboutData("kcm_componentchooser", i18nc("@title", "Default Applications"), "1.0", QString(), KAboutLicense::LicenseKey::GPL_V2);
......@@ -43,50 +45,56 @@ KcmComponentChooser::KcmComponentChooser(QObject *parent, const QVariantList &ar
setAboutData(aboutData);
setButtons(Help | Default | Apply);
m_browsers = new ComponentChooserBrowser(this);
m_fileManagers = new ComponentChooserFileManager(this);
m_terminalEmulators = new ComponentChooserTerminal(this);
m_emailClients = new ComponentChooserEmail(this);
connect(browsers(), &ComponentChooser::indexChanged, this, &KcmComponentChooser::settingsChanged);
connect(fileManagers(), &ComponentChooser::indexChanged, this, &KcmComponentChooser::settingsChanged);
connect(terminalEmulators(), &ComponentChooser::indexChanged, this, &KcmComponentChooser::settingsChanged);
connect(emailClients(), &ComponentChooser::indexChanged, this, &KcmComponentChooser::settingsChanged);
}
connect(m_browsers, &ComponentChooser::indexChanged, this, &KcmComponentChooser::settingsChanged);
connect(m_fileManagers, &ComponentChooser::indexChanged, this, &KcmComponentChooser::settingsChanged);
connect(m_terminalEmulators, &ComponentChooser::indexChanged, this, &KcmComponentChooser::settingsChanged);
connect(m_emailClients, &ComponentChooser::indexChanged, this, &KcmComponentChooser::settingsChanged);
ComponentChooser *KcmComponentChooser::browsers() const
{
return m_data->browsers();
}
ComponentChooser *KcmComponentChooser::emailClients() const
{
return m_data->emailClients();
}
ComponentChooser *KcmComponentChooser::terminalEmulators() const
{
return m_data->terminalEmulators();
}
ComponentChooser *KcmComponentChooser::fileManagers() const
{
return m_data->fileManagers();
}
void KcmComponentChooser::defaults()
{
m_browsers->defaults();
m_fileManagers->defaults();
m_terminalEmulators->defaults();
m_emailClients->defaults();
m_data->defaults();
}
void KcmComponentChooser::load()
{
m_browsers->load();
m_fileManagers->load();
m_terminalEmulators->load();
m_emailClients->load();
m_data->load();
}
void KcmComponentChooser::save()
{
m_browsers->save();
m_fileManagers->save();
m_terminalEmulators->save();
m_emailClients->save();
m_data->save();
KBuildSycocaProgressDialog::rebuildKSycoca(nullptr);
}
bool KcmComponentChooser::isDefaults() const
{
return m_browsers->isDefaults() && m_fileManagers->isDefaults() && m_terminalEmulators->isDefaults() && m_emailClients->isDefaults();
return m_data->isDefaults();
}
bool KcmComponentChooser::isSaveNeeded() const
{
return m_browsers->isSaveNeeded() || m_fileManagers->isSaveNeeded() || m_terminalEmulators->isSaveNeeded() || m_emailClients->isSaveNeeded();
return m_data->isSaveNeeded();
}
......
......@@ -24,17 +24,24 @@
#include "componentchooser.h"
class ComponentChooserData;
class KcmComponentChooser : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(ComponentChooser *browsers MEMBER m_browsers CONSTANT)
Q_PROPERTY(ComponentChooser *emailClients MEMBER m_emailClients CONSTANT)
Q_PROPERTY(ComponentChooser *terminalEmulators MEMBER m_terminalEmulators CONSTANT)
Q_PROPERTY(ComponentChooser *fileManagers MEMBER m_fileManagers CONSTANT)
Q_PROPERTY(ComponentChooser *browsers READ browsers CONSTANT)
Q_PROPERTY(ComponentChooser *emailClients READ emailClients CONSTANT)
Q_PROPERTY(ComponentChooser *terminalEmulators READ terminalEmulators CONSTANT)
Q_PROPERTY(ComponentChooser *fileManagers READ fileManagers CONSTANT)
public:
KcmComponentChooser(QObject *parent, const QVariantList &args);
ComponentChooser *browsers() const;
ComponentChooser *emailClients() const;
ComponentChooser *terminalEmulators() const;
ComponentChooser *fileManagers() const;
void defaults() override;
void load() override;
void save() override;
......@@ -42,10 +49,7 @@ public:
bool isSaveNeeded() const override;
private:
ComponentChooser *m_browsers;
ComponentChooser *m_emailClients;
ComponentChooser *m_terminalEmulators;
ComponentChooser *m_fileManagers;
ComponentChooserData *m_data;
};
#endif
......@@ -20,25 +20,41 @@
import QtQuick 2.12
import org.kde.kirigami 2.7 as Kirigami
import org.kde.kcm 1.2
import org.kde.kcm 1.5 as KCM
SimpleKCM {
KCM.SimpleKCM {
Kirigami.FormLayout {
ComponentComboBox {
component: kcm.browsers
label: i18n("Web browser:")
KCM.SettingHighlighter {
highlight: !kcm.browsers.isDefaults
}
}
ComponentComboBox {
component: kcm.fileManagers
label: i18n("File manager:")
KCM.SettingHighlighter {
highlight: !kcm.fileManagers.isDefaults
}
}
ComponentComboBox {
component: kcm.emailClients
label: i18n("Email client:")
KCM.SettingHighlighter {
highlight: !kcm.emailClients.isDefaults
}
}
ComponentComboBox {
component: kcm.terminalEmulators
label: i18n("Terminal emulator:")
KCM.SettingHighlighter {
highlight: !kcm.terminalEmulators.isDefaults
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment