diff --git a/greeter/lnf_integration.h b/greeter/lnf_integration.h --- a/greeter/lnf_integration.h +++ b/greeter/lnf_integration.h @@ -65,12 +65,13 @@ 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; diff --git a/greeter/lnf_integration.cpp b/greeter/lnf_integration.cpp --- a/greeter/lnf_integration.cpp +++ b/greeter/lnf_integration.cpp @@ -48,6 +48,7 @@ } if (auto config = configScheme()) { m_configuration = new KDeclarative::ConfigPropertyMap(config, this); + m_configuration->setAutosave(false); } } diff --git a/greeter/wallpaper_integration.h b/greeter/wallpaper_integration.h --- a/greeter/wallpaper_integration.h +++ b/greeter/wallpaper_integration.h @@ -65,12 +65,13 @@ 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; diff --git a/greeter/wallpaper_integration.cpp b/greeter/wallpaper_integration.cpp --- a/greeter/wallpaper_integration.cpp +++ b/greeter/wallpaper_integration.cpp @@ -49,6 +49,7 @@ } if (auto config = configScheme()) { m_configuration = new KDeclarative::ConfigPropertyMap(config, this); + m_configuration->setAutosave(false); } } diff --git a/kcm/kcm.h b/kcm/kcm.h --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -64,6 +64,9 @@ void wallpaperConfigurationChanged(); void currentWallpaperChanged(); +private Q_SLOTS: + void updateState(); + private: void loadWallpapers(); void selectWallpaper(const QString &pluginId); @@ -73,7 +76,9 @@ 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 diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -25,6 +25,7 @@ #include "../greeter/lnf_integration.h" #include +#include #include #include #include @@ -70,9 +71,8 @@ addConfig(m_settings, m_ui); loadWallpapers(); - auto wallpaperChangedSignal = static_cast(&QComboBox::currentIndexChanged); - connect(m_ui->wallpaperCombo, wallpaperChangedSignal, this, static_cast(&ScreenLockerKcm::changed)); - connect(m_ui->wallpaperCombo, wallpaperChangedSignal, this, &ScreenLockerKcm::loadWallpaperConfig); + connect(m_ui->wallpaperCombo, static_cast(&QComboBox::currentIndexChanged), + this, &ScreenLockerKcm::loadWallpaperConfig); m_ui->wallpaperCombo->installEventFilter(this); @@ -89,17 +89,19 @@ 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); } 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 +114,23 @@ 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 ConfigProperyMap to reevaluate + } + + if (m_wallpaperSettings) { + m_wallpaperSettings->load(); + emit m_wallpaperSettings->configChanged(); // To force the ConfigProperyMap to reevaluate + } + + updateState(); } void ScreenLockerKcm::test(const QString &plugin) @@ -136,27 +150,60 @@ 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"), QStringLiteral("/ScreenSaver"), QDBusConnection::sessionBus()); 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 ConfigProperyMap to reevaluate + } + + if (m_wallpaperSettings) { + m_wallpaperSettings->setDefaults(); + emit m_wallpaperSettings->configChanged(); // To force the ConfigProperyMap 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 +227,10 @@ 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 +244,7 @@ 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"))); diff --git a/kcm/lnfconfig.qml b/kcm/lnfconfig.qml --- a/kcm/lnfconfig.qml +++ b/kcm/lnfconfig.qml @@ -30,19 +30,6 @@ 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 +59,23 @@ 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 { diff --git a/kcm/wallpaperconfig.qml b/kcm/wallpaperconfig.qml --- a/kcm/wallpaperconfig.qml +++ b/kcm/wallpaperconfig.qml @@ -30,19 +30,6 @@ 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 +58,23 @@ 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 {