Commit 199bbe20 authored by Cyril Rossi's avatar Cyril Rossi
Browse files

KCM Colors : port color scheme state management to KConfigXT

Reviewers: #plasma, ervin, mart, bport

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25198
parent 659a46aa
......@@ -11,6 +11,8 @@ set(kcm_colors_SRCS
# needed for krdb
qt5_add_dbus_interface(kcm_colors_SRCS ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml klauncher_iface)
kconfig_add_kcfg_files(kcm_colors_SRCS colorssettings.kcfgc GENERATE_MOC)
add_library(kcm_colors MODULE ${kcm_colors_SRCS})
target_link_libraries(kcm_colors
Qt5::DBus
......@@ -32,6 +34,7 @@ endif()
kcoreaddons_desktop_to_json(kcm_colors "kcm_colors.desktop")
install(FILES colorssettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES kcm_colors.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS kcm_colors DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
install(FILES colorschemes.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR})
......
......@@ -3,6 +3,7 @@
* Copyright (C) 2007 Jeremy Whiting <jpwhiting@kde.org>
* Copyright (C) 2016 Olivier Churlaud <olivier@churlaud.com>
* Copyright (C) 2019 Kai Uwe Broulik <kde@privat.broulik.de>
* Copyright (c) 2019 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
......@@ -52,15 +53,15 @@
#include "colorsmodel.h"
#include "filterproxymodel.h"
static const QString s_defaultColorSchemeName = QStringLiteral("Breeze");
#include "colorssettings.h"
K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_colors.json", registerPlugin<KCMColors>();)
KCMColors::KCMColors(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_model(new ColorsModel(this))
, m_filteredModel(new FilterProxyModel(this))
, m_settings(new ColorsSettings(this))
, m_config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")))
{
qmlRegisterUncreatableType<KCMColors>("org.kde.private.kcms.colors", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM"));
......@@ -72,14 +73,19 @@ KCMColors::KCMColors(QObject *parent, const QVariantList &args)
about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@privat.broulik.de"));
setAboutData(about);
connect(m_model, &ColorsModel::selectedSchemeChanged, this, [this] {
m_selectedSchemeDirty = true;
setNeedsSave(true);
});
connect(m_model, &ColorsModel::pendingDeletionsChanged, this, [this] {
setNeedsSave(true);
});
connect(m_model, &ColorsModel::selectedSchemeChanged, this, [this](const QString &scheme) {
m_selectedSchemeDirty = true;
m_settings->setColorScheme(scheme);
});
connect(m_settings, &ColorsSettings::colorSchemeChanged, this, [this] {
m_model->setSelectedScheme(m_settings->colorScheme());
});
connect(m_model, &ColorsModel::selectedSchemeChanged, m_filteredModel, &FilterProxyModel::setSelectedScheme);
m_filteredModel->setSourceModel(m_model);
}
......@@ -293,20 +299,20 @@ void KCMColors::editScheme(const QString &schemeName, QQuickItem *ctx)
void KCMColors::load()
{
ManagedConfigModule::load();
m_model->load();
m_config->markAsClean();
m_config->reparseConfiguration();
KConfigGroup group(m_config, "General");
const QString schemeName = group.readEntry("ColorScheme", s_defaultColorSchemeName);
const QString schemeName = m_settings->colorScheme();
// If the scheme named in kdeglobals doesn't exist, show a warning and use default scheme
if (m_model->indexOfScheme(schemeName) == -1) {
m_model->setSelectedScheme(s_defaultColorSchemeName);
m_model->setSelectedScheme(m_settings->defaultColorSchemeValue());
// These are normally synced but initially the model doesn't emit a change to avoid the
// Apply button from being enabled without any user interaction. Sync manually here.
m_filteredModel->setSelectedScheme(s_defaultColorSchemeName);
m_filteredModel->setSelectedScheme(m_settings->defaultColorSchemeValue());
emit showSchemeNotInstalledWarning(schemeName);
} else {
m_model->setSelectedScheme(schemeName);
......@@ -315,6 +321,7 @@ void KCMColors::load()
{
KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals);
KConfigGroup group(m_config, "General");
group = KConfigGroup(&cfg, "X11");
m_applyToAlien = group.readEntry("exportKDEColors", true);
}
......@@ -322,20 +329,16 @@ void KCMColors::load()
void KCMColors::save()
{
ManagedConfigModule::save();
if (m_selectedSchemeDirty) {
saveColors();
}
processPendingDeletions();
setNeedsSave(false);
}
void KCMColors::saveColors()
{
KConfigGroup grp(m_config, "General");
grp.writeEntry("ColorScheme", m_model->selectedScheme());
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral("color-schemes/%1.colors").arg(m_model->selectedScheme()));
......@@ -464,11 +467,4 @@ void KCMColors::processPendingDeletions()
m_model->removeItemsPendingDeletion();
}
void KCMColors::defaults()
{
m_model->setSelectedScheme(s_defaultColorSchemeName);
setNeedsSave(true);
}
#include "colors.moc"
/*
* Copyright (c) 2019 Kai Uwe Broulik <kde@privat.broulik.de>
* Copyright (c) 2019 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
......@@ -27,7 +28,7 @@
#include <KNewStuff3/KNS3/DownloadDialog>
#include <KQuickAddons/ConfigModule>
#include <KQuickAddons/ManagedConfigModule>
class QProcess;
class QTemporaryFile;
......@@ -39,8 +40,9 @@ class FileCopyJob;
class ColorsModel;
class FilterProxyModel;
class ColorsSettings;
class KCMColors : public KQuickAddons::ConfigModule
class KCMColors : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
......@@ -79,11 +81,8 @@ public:
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
Q_SIGNALS:
void selectedSchemeChanged();
void selectedSchemeIndexChanged();
void downloadingFileChanged();
void showSuccessMessage(const QString &message);
......@@ -99,6 +98,7 @@ private:
ColorsModel *m_model;
FilterProxyModel *m_filteredModel;
ColorsSettings *m_settings;
bool m_selectedSchemeDirty = false;
......
<?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="kdeglobals"/>
<group name="General">
<entry name="colorScheme" key="ColorScheme" type="String">
<label>Color scheme name</label>
<default>Breeze</default>
</entry>
</group>
</kcfg>
File=colorssettings.kcfg
ClassName=ColorsSettings
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