Commit 77b27da4 authored by Cyril Rossi's avatar Cyril Rossi
Browse files

Port KCMSplashScreen to KConfigXT

Reviewers: #plasma, ervin, mart, bport

Reviewed By: bport

Subscribers: plasma-devel, apol

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24730
parent c402ff93
......@@ -5,6 +5,8 @@ set(kcm_splashscreen_SRCS
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 @@ target_link_libraries(kcm_splashscreen
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)
/* This file is part of the KDE Project
Copyright (c) 2014 Marco Martin <mart@kde.org>
Copyright (c) 2014 Vishesh Handa <me@vhanda.in>
Copyright (c) 2019 Cyril Rossi <cyril.rossi@enioka.com>
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 <KPluginFactory>
#include <KPluginLoader>
#include <KAboutData>
#include <KSharedConfig>
#include <KLocalizedString>
#include <QStandardPaths>
#include <QProcess>
#include <QQuickView>
#include <QVBoxLayout>
#include <QPushButton>
#include <QStandardItemModel>
#include <QQmlContext>
#include <QDir>
#include <KLocalizedString>
#include <Plasma/PluginLoader>
#include <KNewStuff3/KNS3/DownloadDialog>
#include "splashscreensettings.h"
K_PLUGIN_FACTORY_WITH_JSON(KCMSplashScreenFactory, "kcm_splashscreen.json", registerPlugin<KCMSplashScreen>();)
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<SplashScreenSettings>();
qmlRegisterType<QStandardItemModel>();
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<int, QByteArray> roles = m_model->roleNames();
roles[PluginNameRole] = "pluginName";
roles[ScreenshotRole] = "screenshot";
......@@ -84,28 +86,14 @@ QList<Plasma::Package> KCMSplashScreen::availablePackages(const QString &compone
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 @@ void KCMSplashScreen::loadModel()
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;
}
......
/*
Copyright (c) 2014 Marco Martin <mart@kde.org>
Copyright (c) 2014 Vishesh Handa <me@vhanda.in>
Copyright (c) 2019 Cyril Rossi <cyril.rossi@enioka.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -20,20 +21,17 @@
#ifndef _KCM_SEARCH_H
#define _KCM_SEARCH_H
#include <KConfig>
#include <KConfigGroup>
#include <Plasma/Package>
#include <KQuickAddons/ConfigModule>
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:
......@@ -42,20 +40,14 @@ public:
ScreenshotRole,
DescriptionRole
};
KCMSplashScreen(QObject* parent, const QVariantList& args);
QList<Plasma::Package> 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 @@ public Q_SLOTS:
void test(const QString &plugin);
Q_SIGNALS:
void selectedPluginChanged();
void selectedPluginIndexChanged();
void testingChanged();
void testingFailed();
private:
void loadModel();
QList<Plasma::Package> 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
......@@ -31,7 +31,7 @@ KCM.GridViewKCM {
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 @@ KCM.GridViewKCM {
}
]
onClicked: {
kcm.selectedPlugin = model.pluginName;
kcm.splashScreenSettings.theme = model.pluginName;
view.forceActiveFocus();
}
}
......
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<include>KSharedConfig</include>
<include>KConfig</include>
<include>KConfigGroup</include>
<kcfgfile name="ksplashrc" />
<group name="KSplash">
<entry name="engine" key="Engine" type="String">
<label>For futur use</label>
<default code="true">theme() == QStringLiteral("None") ? QStringLiteral("none") : QStringLiteral("KSplashQML")</default>
</entry>
<entry name="theme" key="Theme" type="String">
<label>Name of the current splash theme</label>
<code>KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE");
QString defaultTheme = cg.readEntry("LookAndFeelPackage", QStringLiteral("org.kde.breeze.desktop"));
</code>
<default code="true">defaultTheme</default>
</entry>
</group>
</kcfg>
File=splashscreensettings.kcfg
ClassName=SplashScreenSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
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