Commit 33857261 authored by Kevin Ottens's avatar Kevin Ottens
Browse files

Integrate the lnf and wallpaper settings with the KCM logic

Summary:
This was currently very much disconnected and broken in quite a few
cases. The main changes here are:
 * disabling ConfigPropertyMap autosave behavior
 * having the QML integration write directly in the settings objects
 * use the settings objects to update the state of the KCM propertly

Further improvement is needed to simplify the handling of the wallpaper
plugin combo, it's still a bit over the place and fragile.

Reviewers: #plasma, mart, davidedmundson, bport, crossi

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25287
parent f368ffa0
......@@ -48,6 +48,7 @@ void LnFIntegration::init()
}
if (auto config = configScheme()) {
m_configuration = new KDeclarative::ConfigPropertyMap(config, this);
m_configuration->setAutosave(false);
}
}
......
......@@ -65,12 +65,13 @@ public:
return m_configuration;
}
KConfigLoader *configScheme();
Q_SIGNALS:
void packageChanged();
void configurationChanged();
private:
KConfigLoader *configScheme();
KPackage::Package m_package;
KSharedConfig::Ptr m_config;
KConfigLoader *m_configLoader = nullptr;
......
......@@ -49,6 +49,7 @@ void WallpaperIntegration::init()
}
if (auto config = configScheme()) {
m_configuration = new KDeclarative::ConfigPropertyMap(config, this);
m_configuration->setAutosave(false);
}
}
......
......@@ -65,12 +65,13 @@ public:
return m_configuration;
}
KConfigLoader *configScheme();
Q_SIGNALS:
void packageChanged();
void configurationChanged();
private:
KConfigLoader *configScheme();
QString m_pluginName;
KPackage::Package m_package;
KSharedConfig::Ptr m_config;
......
......@@ -3,6 +3,7 @@
This file is part of the KDE project.
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2019 Kevin Ottens <kevin.ottens@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 published by
......@@ -25,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../greeter/lnf_integration.h"
#include <config-kscreenlocker.h>
#include <KConfigLoader>
#include <KConfigDialogManager>
#include <KGlobalAccel>
#include <KCModule>
......@@ -70,9 +72,8 @@ ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args)
addConfig(m_settings, m_ui);
loadWallpapers();
auto wallpaperChangedSignal = static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
connect(m_ui->wallpaperCombo, wallpaperChangedSignal, this, static_cast<void (KCModule::*)()>(&ScreenLockerKcm::changed));
connect(m_ui->wallpaperCombo, wallpaperChangedSignal, this, &ScreenLockerKcm::loadWallpaperConfig);
connect(m_ui->wallpaperCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &ScreenLockerKcm::loadWallpaperConfig);
m_ui->wallpaperCombo->installEventFilter(this);
......@@ -89,10 +90,10 @@ ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args)
connect(this, &ScreenLockerKcm::currentWallpaperChanged, proxy, &ScreenLockerProxy::currentWallpaperChanged);
m_ui->wallpaperConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/wallpaperconfig.qml")));
connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(changed()));
connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState()));
m_ui->lnfConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/lnfconfig.qml")));
connect(m_ui->lnfConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(changed()));
connect(m_ui->lnfConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState()));
m_ui->installEventFilter(this);
}
......@@ -100,6 +101,8 @@ ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args)
void ScreenLockerKcm::load()
{
KCModule::load();
// Because the wallpaper plugin is currently handled wrongly
m_settings->load();
m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE");
......@@ -112,11 +115,23 @@ void ScreenLockerKcm::load()
m_lnfIntegration->setPackage(m_package);
m_lnfIntegration->setConfig(m_settings->sharedConfig());
m_lnfIntegration->init();
m_lnfSettings = m_lnfIntegration->configScheme();
selectWallpaper(m_settings->wallpaperPlugin());
loadWallpaperConfig();
loadLnfConfig();
if (m_lnfSettings) {
m_lnfSettings->load();
emit m_lnfSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
}
if (m_wallpaperSettings) {
m_wallpaperSettings->load();
emit m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
}
updateState();
}
void ScreenLockerKcm::test(const QString &plugin)
......@@ -136,13 +151,13 @@ void ScreenLockerKcm::test(const QString &plugin)
void ScreenLockerKcm::save()
{
KCModule::save();
QMetaObject::invokeMethod(m_ui->wallpaperConfigWidget->rootObject(), "saveConfig");
QMetaObject::invokeMethod(m_ui->lnfConfigWidget->rootObject(), "saveConfig");
// set the wallpaper config
m_settings->setWallpaperPlugin(m_ui->wallpaperCombo->currentData().toString());
if (m_lnfSettings) {
m_lnfSettings->save();
}
m_settings->save();
if (m_wallpaperSettings) {
m_wallpaperSettings->save();
}
// reconfigure through DBus
OrgKdeScreensaverInterface interface(QStringLiteral("org.kde.screensaver"),
......@@ -151,12 +166,45 @@ void ScreenLockerKcm::save()
if (interface.isValid()) {
interface.configure();
}
updateState();
}
void ScreenLockerKcm::defaults()
{
KCModule::defaults();
selectWallpaper(s_defaultWallpaperPackage);
if (m_lnfSettings) {
m_lnfSettings->setDefaults();
emit m_lnfSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
}
if (m_wallpaperSettings) {
m_wallpaperSettings->setDefaults();
emit m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
}
updateState();
}
void ScreenLockerKcm::updateState()
{
bool isDefaults = m_settings->isDefaults();
bool isSaveNeeded = m_settings->isSaveNeeded();
if (m_lnfSettings) {
isDefaults &= m_lnfSettings->isDefaults();
isSaveNeeded |= m_lnfSettings->isSaveNeeded();
}
if (m_wallpaperSettings) {
isDefaults &= m_wallpaperSettings->isDefaults();
isSaveNeeded |= m_wallpaperSettings->isSaveNeeded();
}
emit changed(isSaveNeeded);
emit defaulted(isDefaults);
}
void ScreenLockerKcm::loadWallpapers()
......@@ -180,6 +228,10 @@ void ScreenLockerKcm::selectWallpaper(const QString &pluginId)
void ScreenLockerKcm::loadWallpaperConfig()
{
// set the wallpaper config
m_settings->setWallpaperPlugin(m_ui->wallpaperCombo->currentData().toString());
updateState();
if (m_wallpaperIntegration) {
if (m_wallpaperIntegration->pluginName() == m_ui->wallpaperCombo->currentData().toString()) {
// nothing changed
......@@ -193,6 +245,7 @@ void ScreenLockerKcm::loadWallpaperConfig()
m_wallpaperIntegration->setConfig(m_settings->sharedConfig());
m_wallpaperIntegration->setPluginName(m_ui->wallpaperCombo->currentData().toString());
m_wallpaperIntegration->init();
m_wallpaperSettings = m_wallpaperIntegration->configScheme();
m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("wallpaper"), m_wallpaperIntegration);
emit wallpaperConfigurationChanged();
m_ui->wallpaperConfigWidget->rootObject()->setProperty("sourceFile", m_wallpaperIntegration->package().filePath(QByteArrayLiteral("ui"), QStringLiteral("config.qml")));
......
......@@ -4,6 +4,7 @@
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2014 Marco Martin <mart@kde.org>
Copyright (C) 2019 Kevin Ottens <kevin.ottens@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 published by
......@@ -64,6 +65,9 @@ Q_SIGNALS:
void wallpaperConfigurationChanged();
void currentWallpaperChanged();
private Q_SLOTS:
void updateState();
private:
void loadWallpapers();
void selectWallpaper(const QString &pluginId);
......@@ -73,7 +77,9 @@ private:
KScreenSaverSettings *m_settings;
ScreenLockerKcmForm *m_ui;
ScreenLocker::WallpaperIntegration *m_wallpaperIntegration = nullptr;
KCoreConfigSkeleton *m_wallpaperSettings = nullptr;
ScreenLocker::LnFIntegration* m_lnfIntegration = nullptr;
KCoreConfigSkeleton *m_lnfSettings = nullptr;
};
//see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property
......
......@@ -3,6 +3,7 @@
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2019 Kevin Ottens <kevin.ottens@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
......@@ -30,19 +31,6 @@ ColumnLayout {
property alias sourceFile: main.sourceFile
signal configurationChanged
//BEGIN functions
function saveConfig() {
if (main.currentItem.saveConfig) {
main.currentItem.saveConfig()
}
for (var key in configDialog.lnfConfiguration) {
if (main.currentItem["cfg_"+key] !== undefined) {
configDialog.lnfConfiguration[key] = main.currentItem["cfg_"+key]
}
}
}
//END functions
Item {
id: emptyConfig
}
......@@ -72,10 +60,23 @@ ColumnLayout {
properties: props
})
lnfConfiguration.valueChanged.connect(function(key, value) {
if (newItem["cfg_" + key] !== undefined) {
newItem["cfg_" + key] = value
}
})
var createSignalHandler = function(key) {
return function() {
configDialog.lnfConfiguration[key] = newItem["cfg_" + key]
root.configurationChanged()
}
}
for (var key in lnfConfiguration) {
var changedSignal = newItem["cfg_" + key + "Changed"]
if (changedSignal) {
changedSignal.connect(root.configurationChanged)
changedSignal.connect(createSignalHandler(key))
}
}
} else {
......
......@@ -3,6 +3,7 @@
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2019 Kevin Ottens <kevin.ottens@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
......@@ -30,19 +31,6 @@ ColumnLayout {
property alias sourceFile: main.sourceFile
signal configurationChanged
//BEGIN functions
function saveConfig() {
if (main.currentItem.saveConfig) {
main.currentItem.saveConfig()
}
for (var key in configDialog.wallpaperConfiguration) {
if (main.currentItem["cfg_"+key] !== undefined) {
configDialog.wallpaperConfiguration[key] = main.currentItem["cfg_"+key]
}
}
}
//END functions
Item {
id: emptyConfig
}
......@@ -71,10 +59,23 @@ ColumnLayout {
properties: props
})
wallpaperConfig.valueChanged.connect(function(key, value) {
if (newItem["cfg_" + key] !== undefined) {
newItem["cfg_" + key] = value
}
})
var createSignalHandler = function(key) {
return function() {
configDialog.wallpaperConfiguration[key] = newItem["cfg_" + key]
root.configurationChanged()
}
}
for (var key in wallpaperConfig) {
var changedSignal = newItem["cfg_" + key + "Changed"]
if (changedSignal) {
changedSignal.connect(root.configurationChanged)
changedSignal.connect(createSignalHandler(key))
}
}
} else {
......
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