diff --git a/kcms/ksplash/CMakeLists.txt b/kcms/ksplash/CMakeLists.txt --- a/kcms/ksplash/CMakeLists.txt +++ b/kcms/ksplash/CMakeLists.txt @@ -5,6 +5,8 @@ kcm.cpp ) +kconfig_add_kcfg_files(kcm_splashscreen_SRCS splashscreensettings.kcfgc GENERATE_MOC) + add_library(kcm_splashscreen MODULE ${kcm_splashscreen_SRCS}) target_link_libraries(kcm_splashscreen @@ -24,8 +26,9 @@ kcoreaddons_desktop_to_json(kcm_splashscreen "kcm_splashscreen.desktop" SERVICE_TYPES kcmodule.desktop) #this desktop file is installed only for retrocompatibility with sycoca +install(FILES splashscreensettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) install(FILES kcm_splashscreen.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) -install(TARGETS kcm_splashscreen DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms) install( FILES ksplash.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR} ) +install(TARGETS kcm_splashscreen DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms) kpackage_install_package(package kcm_splashscreen kcms) diff --git a/kcms/ksplash/kcm.h b/kcms/ksplash/kcm.h --- a/kcms/ksplash/kcm.h +++ b/kcms/ksplash/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 @@ -20,42 +21,33 @@ #ifndef _KCM_SEARCH_H #define _KCM_SEARCH_H -#include -#include - #include #include class QStandardItemModel; +class SplashScreenSettings; class KCMSplashScreen : public KQuickAddons::ConfigModule { Q_OBJECT + Q_PROPERTY(SplashScreenSettings *splashScreenSettings READ splashScreenSettings CONSTANT) Q_PROPERTY(QStandardItemModel *splashModel READ splashModel CONSTANT) - Q_PROPERTY(QString selectedPlugin READ selectedPlugin WRITE setSelectedPlugin NOTIFY selectedPluginChanged) - Q_PROPERTY(int selectedPluginIndex READ selectedPluginIndex NOTIFY selectedPluginIndexChanged) Q_PROPERTY(bool testing READ testing NOTIFY testingChanged) public: enum Roles { PluginNameRole = Qt::UserRole +1, ScreenshotRole, DescriptionRole }; - KCMSplashScreen(QObject* parent, const QVariantList& args); - QList availablePackages(const QString &component); + KCMSplashScreen(QObject* parent, const QVariantList& args); + SplashScreenSettings *splashScreenSettings() const; QStandardItemModel *splashModel() const; - - QString selectedPlugin() const; - void setSelectedPlugin(const QString &plugin); - - int selectedPluginIndex() const; - bool testing() const; - void loadModel(); + Q_INVOKABLE int pluginIndex(const QString &pluginName) const; public Q_SLOTS: void getNewClicked(); @@ -65,21 +57,17 @@ void test(const QString &plugin); Q_SIGNALS: - void selectedPluginChanged(); - void selectedPluginIndexChanged(); - void testingChanged(); void testingFailed(); private: + void loadModel(); + QList availablePackages(const QString &component); + + SplashScreenSettings *m_settings; QStandardItemModel *m_model; - Plasma::Package m_package; - QString m_selectedPlugin; QProcess *m_testProcess = nullptr; - - KConfig m_config; - KConfigGroup m_configGroup; }; #endif diff --git a/kcms/ksplash/kcm.cpp b/kcms/ksplash/kcm.cpp --- a/kcms/ksplash/kcm.cpp +++ b/kcms/ksplash/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 @@ -22,37 +23,38 @@ #include #include #include -#include +#include + #include #include -#include - -#include -#include #include -#include #include -#include #include #include +#include "splashscreensettings.h" + K_PLUGIN_FACTORY_WITH_JSON(KCMSplashScreenFactory, "kcm_splashscreen.json", registerPlugin();) KCMSplashScreen::KCMSplashScreen(QObject* parent, const QVariantList& args) : KQuickAddons::ConfigModule(parent, args) - , m_config(QStringLiteral("ksplashrc")) - , m_configGroup(m_config.group("KSplash")) + , m_settings(new SplashScreenSettings(this)) + , m_model(new QStandardItemModel(this)) { + connect(m_settings, &SplashScreenSettings::engineChanged, this, [this]{ setNeedsSave(true); }); + connect(m_settings, &SplashScreenSettings::themeChanged, this, [this]{ setNeedsSave(true); }); + + qmlRegisterType(); qmlRegisterType(); + KAboutData* about = new KAboutData(QStringLiteral("kcm_splashscreen"), i18n("Splash Screen"), QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); about->addAuthor(i18n("Marco Martin"), QString(), QStringLiteral("mart@kde.org")); setAboutData(about); setButtons(Help | Apply | Default); - m_model = new QStandardItemModel(this); QHash roles = m_model->roleNames(); roles[PluginNameRole] = "pluginName"; roles[ScreenshotRole] = "screenshot"; @@ -84,28 +86,14 @@ return packages; } -QStandardItemModel *KCMSplashScreen::splashModel() const -{ - return m_model; -} - -QString KCMSplashScreen::selectedPlugin() const +SplashScreenSettings *KCMSplashScreen::splashScreenSettings() const { - return m_selectedPlugin; + return m_settings; } -void KCMSplashScreen::setSelectedPlugin(const QString &plugin) +QStandardItemModel *KCMSplashScreen::splashModel() const { - if (m_selectedPlugin == plugin) { - return; - } - - if (!m_selectedPlugin.isEmpty()) { - setNeedsSave(true); - } - m_selectedPlugin = plugin; - emit selectedPluginChanged(); - emit selectedPluginIndexChanged(); + return m_model; } void KCMSplashScreen::getNewClicked() @@ -138,59 +126,38 @@ row->setData(i18n("No splash screen will be shown"), DescriptionRole); m_model->insertRow(0, row); - emit selectedPluginIndexChanged(); + if (-1 == pluginIndex(m_settings->theme())) { + defaults(); + } + + emit m_settings->themeChanged(); } void KCMSplashScreen::load() { - m_package = Plasma::PluginLoader::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); - } - - QString currentPlugin = m_configGroup.readEntry("Theme", QString()); - if (currentPlugin.isEmpty()) { - currentPlugin = m_package.metadata().pluginName(); - } - setSelectedPlugin(currentPlugin); - + m_settings->load(); setNeedsSave(false); } - void KCMSplashScreen::save() { - if (m_selectedPlugin.isEmpty()) { - return; - } else if (m_selectedPlugin == QLatin1String("None")) { - m_configGroup.writeEntry("Theme", m_selectedPlugin); - m_configGroup.writeEntry("Engine", "none"); - } else { - m_configGroup.writeEntry("Theme", m_selectedPlugin); - m_configGroup.writeEntry("Engine", "KSplashQML"); - } - - m_configGroup.sync(); - setNeedsSave(false); + m_settings->setEngine(m_settings->theme() == QStringLiteral("None") ? QStringLiteral("none") : QStringLiteral("KSplashQML")); + m_settings->save(); } void KCMSplashScreen::defaults() { - if (!m_package.metadata().isValid()) { - return; - } - setSelectedPlugin(m_package.metadata().pluginName()); + m_settings->setDefaults(); + setNeedsSave(m_settings->isSaveNeeded()); } -int KCMSplashScreen::selectedPluginIndex() const +int KCMSplashScreen::pluginIndex(const QString &pluginName) 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; - } + const auto results = m_model->match(m_model->index(0, 0), PluginNameRole, pluginName); + if (results.count() == 1) { + return results.first().row(); } + return -1; } diff --git a/kcms/ksplash/package/contents/ui/main.qml b/kcms/ksplash/package/contents/ui/main.qml --- a/kcms/ksplash/package/contents/ui/main.qml +++ b/kcms/ksplash/package/contents/ui/main.qml @@ -31,7 +31,7 @@ view.model: kcm.splashModel //NOTE: pay attention to never break this binding - view.currentIndex: kcm.selectedPluginIndex + view.currentIndex: kcm.pluginIndex(kcm.splashScreenSettings.theme) // putting the InlineMessage as header item causes it to show up initially despite visible false header: ColumnLayout { @@ -71,7 +71,7 @@ } ] onClicked: { - kcm.selectedPlugin = model.pluginName; + kcm.splashScreenSettings.theme = model.pluginName; view.forceActiveFocus(); } } diff --git a/kcms/ksplash/splashscreensettings.kcfg b/kcms/ksplash/splashscreensettings.kcfg new file mode 100644 --- /dev/null +++ b/kcms/ksplash/splashscreensettings.kcfg @@ -0,0 +1,23 @@ + + + KSharedConfig + KConfig + KConfigGroup + + + + + theme() == QStringLiteral("None") ? QStringLiteral("none") : QStringLiteral("KSplashQML") + + + + KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); + QString defaultTheme = cg.readEntry("LookAndFeelPackage", QStringLiteral("org.kde.breeze.desktop")); + + defaultTheme + + + diff --git a/kcms/ksplash/splashscreensettings.kcfgc b/kcms/ksplash/splashscreensettings.kcfgc new file mode 100644 --- /dev/null +++ b/kcms/ksplash/splashscreensettings.kcfgc @@ -0,0 +1,6 @@ +File=splashscreensettings.kcfg +ClassName=SplashScreenSettings +Mutators=true +DefaultValueGetters=true +GenerateProperties=true +ParentInConstructor=true