diff --git a/kcms/lookandfeel/CMakeLists.txt b/kcms/lookandfeel/CMakeLists.txt --- a/kcms/lookandfeel/CMakeLists.txt +++ b/kcms/lookandfeel/CMakeLists.txt @@ -15,6 +15,8 @@ set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml) qt5_add_dbus_interface(kcm_lookandfeel_SRCS ${klauncher_xml} klauncher_iface) +kconfig_add_kcfg_files(kcm_lookandfeel_SRCS lookandfeelsettings.kcfgc GENERATE_MOC) + add_library(kcm_lookandfeel MODULE ${kcm_lookandfeel_SRCS}) target_link_libraries(kcm_lookandfeel @@ -48,6 +50,7 @@ kcoreaddons_desktop_to_json(kcm_lookandfeel "kcm_lookandfeel.desktop" SERVICE_TYPES kcmodule.desktop) #this desktop file is installed only for retrocompatibility with sycoca +install(FILES lookandfeelsettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) install(FILES kcm_lookandfeel.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) install(TARGETS kcm_lookandfeel DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms) install(FILES lookandfeel.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR}) @@ -72,6 +75,8 @@ qt5_add_dbus_interface(lookandfeeltool_SRCS ${klauncher_xml} klauncher_iface) +kconfig_add_kcfg_files(lookandfeeltool_SRCS lookandfeelsettings.kcfgc GENERATE_MOC) + add_executable(lookandfeeltool ${lookandfeeltool_SRCS}) target_link_libraries(lookandfeeltool diff --git a/kcms/lookandfeel/autotests/CMakeLists.txt b/kcms/lookandfeel/autotests/CMakeLists.txt --- a/kcms/lookandfeel/autotests/CMakeLists.txt +++ b/kcms/lookandfeel/autotests/CMakeLists.txt @@ -13,6 +13,8 @@ set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml) qt5_add_dbus_interface(kcmTest_SRCS ${klauncher_xml} klauncher_iface) +kconfig_add_kcfg_files(kcmTest_SRCS ../lookandfeelsettings.kcfgc GENERATE_MOC) + add_executable(kcmTest ${kcmTest_SRCS}) add_dependencies(kcmTest kcm_lookandfeel) diff --git a/kcms/lookandfeel/kcm.h b/kcms/lookandfeel/kcm.h --- a/kcms/lookandfeel/kcm.h +++ b/kcms/lookandfeel/kcm.h @@ -1,6 +1,7 @@ /* Copyright (c) 2014 Marco Martin Copyright (c) 2014 Vishesh Handa + Copyright (c) 2019 Cyril Rossi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -25,17 +26,17 @@ #include #include -#include +#include class QQuickItem; class QStandardItemModel; +class LookAndFeelSettings; -class KCMLookandFeel : public KQuickAddons::ConfigModule +class KCMLookandFeel : public KQuickAddons::ManagedConfigModule { Q_OBJECT + Q_PROPERTY(LookAndFeelSettings *lookAndFeelSettings READ lookAndFeelSettings CONSTANT) Q_PROPERTY(QStandardItemModel *lookAndFeelModel READ lookAndFeelModel CONSTANT) - Q_PROPERTY(QString selectedPlugin READ selectedPlugin WRITE setSelectedPlugin NOTIFY selectedPluginChanged) - Q_PROPERTY(int selectedPluginIndex READ selectedPluginIndex NOTIFY selectedPluginIndexChanged) Q_PROPERTY(bool resetDefaultLayout READ resetDefaultLayout WRITE setResetDefaultLayout NOTIFY resetDefaultLayoutChanged) public: @@ -60,15 +61,10 @@ KCMLookandFeel(QObject* parent, const QVariantList& args); ~KCMLookandFeel() override; - //List only packages which provide at least one of the components - QList availablePackages(const QStringList &components); - + LookAndFeelSettings *lookAndFeelSettings() const; QStandardItemModel *lookAndFeelModel() const; - QString selectedPlugin() const; - void setSelectedPlugin(const QString &plugin); - - int selectedPluginIndex() const; + Q_INVOKABLE int pluginIndex(const QString &pluginName) const; bool resetDefaultLayout() const; void setResetDefaultLayout(bool reset); @@ -90,20 +86,20 @@ public Q_SLOTS: void load() override; void save() override; - void defaults() override; Q_SIGNALS: - void selectedPluginChanged(); - void selectedPluginIndexChanged(); void resetDefaultLayoutChanged(); private: + //List only packages which provide at least one of the components + QList availablePackages(const QStringList &components); void loadModel(); QDir cursorThemeDir(const QString &theme, const int depth); const QStringList cursorSearchPaths(); + + LookAndFeelSettings *m_settings; QStandardItemModel *m_model; KPackage::Package m_package; - QString m_selectedPlugin; QStringList m_cursorSearchPaths; KConfig m_config; diff --git a/kcms/lookandfeel/kcm.cpp b/kcms/lookandfeel/kcm.cpp --- a/kcms/lookandfeel/kcm.cpp +++ b/kcms/lookandfeel/kcm.cpp @@ -1,6 +1,7 @@ /* This file is part of the KDE Project Copyright (c) 2014 Marco Martin Copyright (c) 2014 Vishesh Handa + Copyright (c) 2019 Cyril Rossi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -46,12 +47,15 @@ #include #include +#include "lookandfeelsettings.h" + #ifdef HAVE_XFIXES # include #endif -KCMLookandFeel::KCMLookandFeel(QObject* parent, const QVariantList& args) - : KQuickAddons::ConfigModule(parent, args) +KCMLookandFeel::KCMLookandFeel(QObject *parent, const QVariantList &args) + : KQuickAddons::ManagedConfigModule(parent, args) + , m_settings(new LookAndFeelSettings(this)) , m_config(QStringLiteral("kdeglobals")) , m_configGroup(m_config.group("KDE")) , m_applyColors(true) @@ -64,9 +68,11 @@ , m_resetDefaultLayout(false) , m_applyWindowDecoration(true) { + qmlRegisterType(); qmlRegisterType(); qmlRegisterType(); - KAboutData* about = new KAboutData(QStringLiteral("kcm_lookandfeel"), i18n("Global Theme"), + + KAboutData *about = new KAboutData(QStringLiteral("kcm_lookandfeel"), i18n("Global Theme"), QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); about->addAuthor(i18n("Marco Martin"), QString(), QStringLiteral("mart@kde.org")); setAboutData(about); @@ -108,34 +114,13 @@ return m_model; } -QString KCMLookandFeel::selectedPlugin() const -{ - return m_selectedPlugin; -} - -void KCMLookandFeel::setSelectedPlugin(const QString &plugin) +int KCMLookandFeel::pluginIndex(const QString &pluginName) const { - if (m_selectedPlugin == plugin) { - return; - } - - const bool firstTime = m_selectedPlugin.isNull(); - m_selectedPlugin = plugin; - emit selectedPluginChanged(); - emit selectedPluginIndexChanged(); - - if (!firstTime) { - setNeedsSave(true); + const auto results = m_model->match(m_model->index(0, 0), PluginNameRole, pluginName); + if (results.count() == 1) { + return results.first().row(); } -} -int KCMLookandFeel::selectedPluginIndex() const -{ - for (int i = 0; i < m_model->rowCount(); ++i) { - if (m_model->data(m_model->index(i, 0), PluginNameRole).toString() == m_selectedPlugin) { - return i; - } - } return -1; } @@ -170,6 +155,11 @@ return packages; } +LookAndFeelSettings *KCMLookandFeel::lookAndFeelSettings() const +{ + return m_settings; +} + void KCMLookandFeel::loadModel() { m_model->clear(); @@ -179,7 +169,7 @@ if (!pkg.metadata().isValid()) { continue; } - QStandardItem* row = new QStandardItem(pkg.metadata().name()); + QStandardItem *row = new QStandardItem(pkg.metadata().name()); row->setData(pkg.metadata().pluginId(), PluginNameRole); row->setData(pkg.metadata().description(), DescriptionRole); row->setData(pkg.filePath("preview"), ScreenshotRole); @@ -226,45 +216,36 @@ m_model->appendRow(row); } m_model->sort(0 /*column*/); - emit selectedPluginIndexChanged(); + + //Model has been cleared so pretend the selected look and fell changed to force view update + emit m_settings->lookAndFeelPackageChanged(); } void KCMLookandFeel::load() { - m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); - KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); - const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); - if (!packageName.isEmpty()) { - m_package.setPath(packageName); - } - - if (!m_package.metadata().isValid()) { - return; - } - - setSelectedPlugin(m_package.metadata().pluginId()); + ManagedConfigModule::load(); - setNeedsSave(false); + m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); + m_package.setPath(m_settings->lookAndFeelPackage()); } - void KCMLookandFeel::save() { KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); - package.setPath(m_selectedPlugin); + package.setPath(m_settings->lookAndFeelPackage()); if (!package.isValid()) { return; } - m_configGroup.writeEntry("LookAndFeelPackage", m_selectedPlugin); + ManagedConfigModule::save(); if (m_resetDefaultLayout) { QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), QStringLiteral("/PlasmaShell"), QStringLiteral("org.kde.PlasmaShell"), QStringLiteral("loadLookAndFeelDefaultLayout")); QList args; - args << m_selectedPlugin; + args << m_settings->lookAndFeelPackage(); message.setArguments(args); QDBusConnection::sessionBus().call(message, QDBus::NoBlock); @@ -407,23 +388,14 @@ } //TODO: option to enable/disable apply? they don't seem required by UI design - setSplashScreen(m_selectedPlugin); - setLockScreen(m_selectedPlugin); + setSplashScreen(m_settings->lookAndFeelPackage()); + setLockScreen(m_settings->lookAndFeelPackage()); m_configGroup.sync(); - m_package.setPath(m_selectedPlugin); + m_package.setPath(m_settings->lookAndFeelPackage()); runRdb(KRdbExportQtColors | KRdbExportGtkTheme | KRdbExportColors | KRdbExportQtSettings | KRdbExportXftSettings); } -void KCMLookandFeel::defaults() -{ - if (!m_package.metadata().isValid()) { - return; - } - - setSelectedPlugin(m_package.metadata().pluginId()); -} - void KCMLookandFeel::setWidgetStyle(const QString &style) { if (style.isEmpty()) { diff --git a/kcms/lookandfeel/lnftool.cpp b/kcms/lookandfeel/lnftool.cpp --- a/kcms/lookandfeel/lnftool.cpp +++ b/kcms/lookandfeel/lnftool.cpp @@ -32,6 +32,8 @@ #include #include +#include "lookandfeelsettings.h" + int main(int argc, char **argv) { QApplication app(argc, argv); @@ -88,7 +90,7 @@ KCMLookandFeel *kcm = new KCMLookandFeel(nullptr, QVariantList()); kcm->load(); kcm->setResetDefaultLayout(parser.isSet(_resetLayout)); - kcm->setSelectedPlugin(parser.value(_apply)); + kcm->lookAndFeelSettings()->setLookAndFeelPackage(parser.value(_apply)); kcm->save(); delete kcm; } diff --git a/kcms/lookandfeel/lookandfeelsettings.kcfg b/kcms/lookandfeel/lookandfeelsettings.kcfg new file mode 100644 --- /dev/null +++ b/kcms/lookandfeel/lookandfeelsettings.kcfg @@ -0,0 +1,13 @@ + + + + + + + org.kde.breeze.desktop + + + diff --git a/kcms/lookandfeel/lookandfeelsettings.kcfgc b/kcms/lookandfeel/lookandfeelsettings.kcfgc new file mode 100644 --- /dev/null +++ b/kcms/lookandfeel/lookandfeelsettings.kcfgc @@ -0,0 +1,6 @@ +File=lookandfeelsettings.kcfg +ClassName=LookAndFeelSettings +Mutators=true +DefaultValueGetters=true +GenerateProperties=true +ParentInConstructor=true diff --git a/kcms/lookandfeel/package/contents/ui/main.qml b/kcms/lookandfeel/package/contents/ui/main.qml --- a/kcms/lookandfeel/package/contents/ui/main.qml +++ b/kcms/lookandfeel/package/contents/ui/main.qml @@ -29,7 +29,7 @@ KCM.ConfigModule.quickHelp: i18n("This module lets you choose the global look and feel.") view.model: kcm.lookAndFeelModel - view.currentIndex: kcm.selectedPluginIndex + view.currentIndex: kcm.pluginIndex(kcm.lookAndFeelSettings.lookAndFeelPackage) view.delegate: KCM.GridDelegate { id: delegate @@ -55,7 +55,7 @@ } ] onClicked: { - kcm.selectedPlugin = model.pluginName; + kcm.lookAndFeelSettings.lookAndFeelPackage = model.pluginName; view.forceActiveFocus(); resetCheckbox.checked = false; }