Commit 6648a1a4 authored by Kevin Ottens's avatar Kevin Ottens
Browse files

Switch from naked KConfig to KConfigXT

Summary:
It provides some improvements at least: first in code reuse, but also it
cleans up the config file behind itself when we get back to the default
value.

Reviewers: #plasma, mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24393
parent 4c694f97
......@@ -5,6 +5,8 @@ set(kcm_desktoptheme_SRCS
kcm.cpp
)
kconfig_add_kcfg_files(kcm_desktoptheme_SRCS desktopthemesettings.kcfgc GENERATE_MOC)
add_library(kcm_desktoptheme MODULE ${kcm_desktoptheme_SRCS})
target_link_libraries(kcm_desktoptheme
......
<?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" >
<kcfgfile name="plasmarc" />
<group name="Theme">
<entry name="name" type="String">
<label>Name of the current Plasma Style</label>
<default>default</default>
</entry>
</group>
</kcfg>
File=desktopthemesettings.kcfg
ClassName=DesktopThemeSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
......@@ -24,7 +24,6 @@
#include <KPluginFactory>
#include <KAboutData>
#include <KSharedConfig>
#include <KLocalizedString>
#include <KDesktopFile>
......@@ -44,14 +43,19 @@
#include <KNewStuff3/KNS3/DownloadDialog>
#include "desktopthemesettings.h"
Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme")
K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();)
KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
, m_settings(new DesktopThemeSettings)
, m_haveThemeExplorerInstalled(false)
{
// Unfortunately doesn't generate a ctor taking the parent as parameter
m_settings->setParent(this);
qmlRegisterType<QStandardItemModel>();
KAboutData* about = new KAboutData(QStringLiteral("kcm_desktoptheme"), i18n("Plasma Style"),
......@@ -280,8 +284,7 @@ void KCMDesktopTheme::load()
m_model->setSortRole(ThemeNameRole); // FIXME the model should really be just using Qt::DisplayRole
m_model->sort(0 /*column*/);
KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme");
setSelectedPlugin(cg.readEntry("name", QStringLiteral("default")));
setSelectedPlugin(m_settings->name());
emit selectedPluginIndexChanged();
......@@ -290,12 +293,10 @@ void KCMDesktopTheme::load()
void KCMDesktopTheme::save()
{
KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme");
const auto currentTheme = cg.readEntry("name", QStringLiteral("default"));
if (currentTheme != m_selectedPlugin) {
cg.writeEntry("name", m_selectedPlugin);
cg.sync();
Plasma::Theme().setThemeName(m_selectedPlugin);
if (m_settings->name() != m_selectedPlugin) {
m_settings->setName(m_selectedPlugin);
m_settings->save();
Plasma::Theme().setThemeName(m_settings->name());
}
processPendingDeletions();
......@@ -304,7 +305,7 @@ void KCMDesktopTheme::save()
void KCMDesktopTheme::defaults()
{
setSelectedPlugin(QStringLiteral("default"));
setSelectedPlugin(m_settings->defaultNameValue());
// can this be done more elegantly?
const auto pendingDeletions = m_model->match(m_model->index(0, 0), PendingDeletionRole, true);
......@@ -325,10 +326,8 @@ void KCMDesktopTheme::editTheme(const QString &theme)
void KCMDesktopTheme::updateNeedsSave()
{
KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme");
const auto currentTheme = cg.readEntry("name", QStringLiteral("default"));
setNeedsSave(!m_model->match(m_model->index(0, 0), PendingDeletionRole, true).isEmpty()
|| m_selectedPlugin != currentTheme);
|| m_selectedPlugin != m_settings->name());
}
void KCMDesktopTheme::processPendingDeletions()
......
......@@ -40,6 +40,7 @@ class FileCopyJob;
class QQuickItem;
class QStandardItemModel;
class DesktopThemeSettings;
class KCMDesktopTheme : public KQuickAddons::ConfigModule
{
......@@ -102,6 +103,8 @@ private:
void installTheme(const QString &path);
DesktopThemeSettings *m_settings;
QStandardItemModel *m_model;
QString m_selectedPlugin;
QStringList m_pendingRemoval;
......
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