Commit 59601361 authored by Cyril Rossi's avatar Cyril Rossi

KCM KScreenLocker highlight non default settings

Make KScreensaverSettings Singleton as it inherits a singleton to avoid multiple parents singleton instanciation
parent 8882e7d5
......@@ -56,6 +56,7 @@ add_feature_info("sys/event.h"
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Crash
Declarative
KCMUtils
GlobalAccel
I18n
IdleTime
......
......@@ -3,6 +3,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"screenlocker_kcm\")
set(screenlocker_kcm_SRCS
kcm.cpp
kscreenlockerdata.cpp
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../)
......@@ -15,6 +16,7 @@ target_link_libraries(kcm_screenlocker
settings
Qt5::DBus
KF5::Declarative
KF5::KCMUtils
KF5::I18n
KF5::GlobalAccel
KF5::Package
......
......@@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "screenlocker_interface.h"
#include "wallpaper_integration.h"
#include "lnf_integration.h"
#include "kscreenlockerdata.h"
#include "appearancesettings.h"
#include <KAboutData>
#include <KConfigLoader>
......@@ -35,10 +37,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QVector>
K_PLUGIN_FACTORY_WITH_JSON(ScreenLockerKcmFactory, "screenlocker.json", registerPlugin<ScreenLockerKcm>(); registerPlugin<KScreenLockerData>();)
ScreenLockerKcm::ScreenLockerKcm(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_settings(new KScreenSaverSettings(this))
, m_appearanceSettings(new AppearanceSettings(this))
{
registerSettings(&KScreenSaverSettings::getInstance());
constexpr const char* url = "org.kde.private.kcms.screenlocker";
qRegisterMetaType<QVector<WallpaperInfo>>("QVector<WallpaperInfo>");
qmlRegisterAnonymousType<KScreenSaverSettings>(url, 1);
......@@ -51,25 +57,14 @@ ScreenLockerKcm::ScreenLockerKcm(QObject *parent, const QVariantList &args)
about->addAuthor(i18n("Martin Gräßlin"), QString(), QStringLiteral("mgraesslin@kde.org"));
about->addAuthor(i18n("Kevin Ottens"), QString(), QStringLiteral("kevin.ottens@enioka.com"));
setAboutData(about);
connect(m_settings, &KScreenSaverSettings::wallpaperPluginIdChanged, this, &ScreenLockerKcm::loadWallpaperConfig);
connect(&KScreenSaverSettings::getInstance(), &KScreenSaverSettings::wallpaperPluginIdChanged, m_appearanceSettings, &AppearanceSettings::loadWallpaperConfig);
connect(m_appearanceSettings, &AppearanceSettings::currentWallpaperChanged, this, &ScreenLockerKcm::currentWallpaperChanged);
}
void ScreenLockerKcm::load()
{
ManagedConfigModule::load();
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
}
m_appearanceSettings->load();
updateState();
}
......@@ -77,13 +72,7 @@ void ScreenLockerKcm::load()
void ScreenLockerKcm::save()
{
ManagedConfigModule::save();
if (m_lnfSettings) {
m_lnfSettings->save();
}
if (m_wallpaperSettings) {
m_wallpaperSettings->save();
}
m_appearanceSettings->save();
// reconfigure through DBus
OrgKdeScreensaverInterface interface(QStringLiteral("org.kde.screensaver"),
......@@ -92,113 +81,71 @@ void ScreenLockerKcm::save()
if (interface.isValid()) {
interface.configure();
}
updateState();
}
void ScreenLockerKcm::defaults()
{
ManagedConfigModule::defaults();
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
}
m_appearanceSettings->defaults();
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();
}
setNeedsSave(isSaveNeeded);
setRepresentsDefaults(isDefaults);
settingsChanged();
emit isDefaultsAppearanceChanged();
}
void ScreenLockerKcm::loadWallpaperConfig()
bool ScreenLockerKcm::isSaveNeeded() const
{
if (m_wallpaperIntegration) {
if (m_wallpaperIntegration->pluginName() == m_settings->wallpaperPluginId()) {
//nothing changed
return;
}
delete m_wallpaperIntegration;
}
m_wallpaperIntegration = new ScreenLocker::WallpaperIntegration(this);
m_wallpaperIntegration->setConfig(m_settings->sharedConfig());
m_wallpaperIntegration->setPluginName(m_settings->wallpaperPluginId());
m_wallpaperIntegration->init();
m_wallpaperSettings = m_wallpaperIntegration->configScheme();
m_wallpaperConfigFile = m_wallpaperIntegration->package().fileUrl(QByteArrayLiteral("ui"), QStringLiteral("config.qml"));
emit currentWallpaperChanged();
return m_appearanceSettings->isSaveNeeded();
}
void ScreenLockerKcm::loadLnfConfig()
bool ScreenLockerKcm::isDefaults() const
{
if (m_package.isValid() && m_lnfIntegration) {
return;
}
Q_ASSERT(!m_package.isValid() && !m_lnfIntegration);
m_package = KPackage::PackageLoader::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);
}
m_lnfIntegration = new ScreenLocker::LnFIntegration(this);
m_lnfIntegration->setPackage(m_package);
m_lnfIntegration->setConfig(m_settings->sharedConfig());
m_lnfIntegration->init();
m_lnfSettings = m_lnfIntegration->configScheme();
auto sourceFile = m_package.fileUrl(QByteArrayLiteral("lockscreen"), QStringLiteral("config.qml"));
m_lnfConfigFile = sourceFile;
return m_appearanceSettings->isDefaults();
}
KDeclarative::ConfigPropertyMap * ScreenLockerKcm::wallpaperConfiguration() const
{
if (!m_wallpaperIntegration) {
return nullptr;
}
return m_wallpaperIntegration->configuration();
return m_appearanceSettings->wallpaperConfiguration();
}
KDeclarative::ConfigPropertyMap * ScreenLockerKcm::lnfConfiguration() const
{
if (!m_lnfIntegration) {
return nullptr;
}
return m_lnfIntegration->configuration();
return m_appearanceSettings->lnfConfiguration();
}
KScreenSaverSettings *ScreenLockerKcm::settings() const
{
return &KScreenSaverSettings::getInstance();
}
QString ScreenLockerKcm::currentWallpaper() const
{
return m_settings->wallpaperPluginId();
return KScreenSaverSettings::getInstance().wallpaperPluginId();
}
bool ScreenLockerKcm::isDefaultsAppearance() const
{
return m_appearanceSettings->isDefaults();
}
QUrl ScreenLockerKcm::lnfConfigFile() const
{
return m_appearanceSettings->lnfConfigFile();
}
QUrl ScreenLockerKcm::wallpaperConfigFile() const
{
return m_appearanceSettings->wallpaperConfigFile();
}
K_PLUGIN_CLASS_WITH_JSON(ScreenLockerKcm, "screenlocker.json")
ScreenLocker::WallpaperIntegration *ScreenLockerKcm::wallpaperIntegration() const
{
return m_appearanceSettings->wallpaperIntegration();
}
#include "kcm.moc"
......@@ -26,8 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KQuickAddons/ManagedConfigModule>
#include "kscreensaversettings.h"
class ScreenLockerKcmForm;
class ScreenLockerKcmForm;
class AppearanceSettings;
namespace ScreenLocker
{
class WallpaperIntegration;
......@@ -46,19 +47,25 @@ class ScreenLockerKcm : public KQuickAddons::ManagedConfigModule
public:
explicit ScreenLockerKcm(QObject *parent = nullptr, const QVariantList& args = QVariantList());
Q_PROPERTY(KScreenSaverSettings *settings MEMBER m_settings CONSTANT)
Q_PROPERTY(KDeclarative::ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration NOTIFY currentWallpaperChanged)
Q_PROPERTY(KScreenSaverSettings *settings READ settings CONSTANT)
Q_PROPERTY(KDeclarative::ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration NOTIFY currentWallpaperChanged)
Q_PROPERTY(KDeclarative::ConfigPropertyMap *lnfConfiguration READ lnfConfiguration CONSTANT)
Q_PROPERTY(QUrl lnfConfigFile MEMBER m_lnfConfigFile CONSTANT)
Q_PROPERTY(QUrl wallpaperConfigFile MEMBER m_wallpaperConfigFile NOTIFY currentWallpaperChanged)
Q_PROPERTY(ScreenLocker::WallpaperIntegration *wallpaperIntegration MEMBER m_wallpaperIntegration NOTIFY currentWallpaperChanged)
Q_PROPERTY(QUrl lnfConfigFile READ lnfConfigFile CONSTANT)
Q_PROPERTY(QUrl wallpaperConfigFile READ wallpaperConfigFile NOTIFY currentWallpaperChanged)
Q_PROPERTY(ScreenLocker::WallpaperIntegration *wallpaperIntegration READ wallpaperIntegration NOTIFY currentWallpaperChanged)
Q_PROPERTY(QString currentWallpaper READ currentWallpaper NOTIFY currentWallpaperChanged)
Q_PROPERTY(bool isDefaultsAppearance READ isDefaultsAppearance NOTIFY isDefaultsAppearanceChanged)
Q_INVOKABLE QVector<WallpaperInfo> availableWallpaperPlugins() {
return m_settings->availableWallpaperPlugins();
return KScreenSaverSettings::getInstance().availableWallpaperPlugins();
}
QString currentWallpaper() const;
KScreenSaverSettings *settings() const;
QUrl lnfConfigFile() const;
QUrl wallpaperConfigFile() const;
ScreenLocker::WallpaperIntegration *wallpaperIntegration() const;
QString currentWallpaper() const;
bool isDefaultsAppearance() const;
public Q_SLOTS:
void load() override;
......@@ -68,22 +75,17 @@ public Q_SLOTS:
Q_SIGNALS:
void currentWallpaperChanged();
void isDefaultsAppearanceChanged();
private:
void loadWallpaperConfig();
void loadLnfConfig();
bool isSaveNeeded() const override;
bool isDefaults() const override;
KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const;
KDeclarative::ConfigPropertyMap *lnfConfiguration() const;
KPackage::Package m_package;
KScreenSaverSettings *m_settings;
ScreenLocker::WallpaperIntegration *m_wallpaperIntegration = nullptr;
KCoreConfigSkeleton *m_wallpaperSettings = nullptr;
QUrl m_wallpaperConfigFile;
ScreenLocker::LnFIntegration* m_lnfIntegration = nullptr;
KCoreConfigSkeleton *m_lnfSettings = nullptr;
QUrl m_lnfConfigFile;
AppearanceSettings *m_appearanceSettings;
QString m_currentWallpaper;
};
#endif
/********************************************************************
This file is part of the KDE project.
Copyright (C) 2020 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 published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kscreenlockerdata.h"
#include "kscreensaversettings.h"
#include "appearancesettings.h"
KScreenLockerData::KScreenLockerData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_appearanceSettings(new AppearanceSettings(this))
{
m_appearanceSettings->load();
}
bool KScreenLockerData::isDefaults() const
{
return KScreenSaverSettings::getInstance().isDefaults() && m_appearanceSettings->isDefaults();
}
#include "kscreenlockerdata.moc"
/********************************************************************
This file is part of the KDE project.
Copyright (C) 2020 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 published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KSCREENLOCKERDATA_H
#define KSCREENLOCKERDATA_H
#include <QObject>
#include "kcmoduledata.h"
class AppearanceSettings;
class KScreenLockerData : public KCModuleData
{
Q_OBJECT
public:
explicit KScreenLockerData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
bool isDefaults() const override;
private:
AppearanceSettings *m_appearanceSettings = nullptr;
};
#endif
......@@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import QtQuick 2.14
import QtQuick.Controls 2.14 as QQC2
import QtQuick.Layouts 1.14
import org.kde.kcm 1.1 as KCM
import org.kde.kcm 1.5 as KCM
import org.kde.kirigami 2.12 as Kirigami
Kirigami.Page {
......@@ -49,6 +49,10 @@ Kirigami.Page {
onActivated: {
kcm.settings.wallpaperPluginId = model[index]["id"]
}
KCM.SettingStateBinding {
configObject: kcm.settings
settingName: "wallpaperPluginId"
}
}
}
WallpaperConfig {
......
......@@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import QtQuick 2.14
import QtQuick.Controls 2.14 as QQC2
import QtQuick.Layouts 1.14
import org.kde.kcm 1.1 as KCM
import org.kde.kcm 1.5 as KCM
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kquickcontrols 2.0 as KQuickControls
......@@ -41,6 +41,11 @@ KCM.SimpleKCM {
text: i18nc("First part of sentence \"Automatically after X minutes\"","After")
checked: kcm.settings.autolock
onToggled: kcm.settings.autolock = checked
KCM.SettingStateBinding {
configObject: kcm.settings
settingName: "Autolock"
}
}
QQC2.SpinBox {
from: 1
......@@ -53,12 +58,22 @@ KCM.SimpleKCM {
}
value: kcm.settings.timeout
onValueModified: kcm.settings.timeout = value
KCM.SettingStateBinding {
configObject: kcm.settings
settingName: "Timeout"
}
}
}
QQC2.CheckBox {
text: i18nc("@option:check","After waking from sleep")
checked: kcm.settings.lockOnResume
onToggled: kcm.settings.lockOnResume = checked
KCM.SettingStateBinding {
configObject: kcm.settings
settingName: "LockOnResume"
}
}
Item {
......@@ -78,6 +93,11 @@ KCM.SimpleKCM {
}
value: kcm.settings.lockGrace
onValueModified: kcm.settings.lockGrace = value
KCM.SettingStateBinding {
configObject: kcm.settings
settingName: "LockGrace"
}
}
Kirigami.Separator {
......@@ -88,6 +108,11 @@ KCM.SimpleKCM {
Kirigami.FormData.label: i18n("Keyboard shortcut:")
keySequence: kcm.settings.shortcut
onKeySequenceChanged: kcm.settings.shortcut = keySequence
KCM.SettingStateBinding {
configObject: kcm.settings
settingName: "shortcut"
}
}
Item {
......@@ -99,6 +124,10 @@ KCM.SimpleKCM {
text: i18nc("@action:button", "Configure...")
icon.name: "preferences-desktop-theme"
onClicked: kcm.push("Appearance.qml")
KCM.SettingHighlighter {
highlight: !kcm.isDefaultsAppearance
}
}
}
}
......
......@@ -2,6 +2,7 @@ add_library(settings STATIC
kscreensaversettings.cpp
lnf_integration.cpp
wallpaper_integration.cpp
appearancesettings.cpp
)
kconfig_add_kcfg_files(settings GENERATE_MOC kscreensaversettingsbase.kcfgc)
target_link_libraries(settings
......
/********************************************************************
This file is part of the KDE project.
Copyright 2020 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 published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "appearancesettings.h"
#include <KConfigLoader>
#include <KPackage/PackageLoader>
#include "kscreensaversettings.h"
#include "wallpaper_integration.h"
#include "lnf_integration.h"
AppearanceSettings::AppearanceSettings(QObject *parent) : QObject(parent)
{
}
QUrl AppearanceSettings::lnfConfigFile() const
{
return m_lnfConfigFile;
}
QUrl AppearanceSettings::wallpaperConfigFile() const
{
return m_wallpaperConfigFile;
}
KDeclarative::ConfigPropertyMap *AppearanceSettings::wallpaperConfiguration() const
{
if (!m_wallpaperIntegration) {
return nullptr;
}
return m_wallpaperIntegration->configuration();
}
KDeclarative::ConfigPropertyMap *AppearanceSettings::lnfConfiguration() const
{
if (!m_lnfIntegration) {
return nullptr;
}
return m_lnfIntegration->configuration();
}
ScreenLocker::WallpaperIntegration *AppearanceSettings::wallpaperIntegration() const
{
return m_wallpaperIntegration;
}
void AppearanceSettings::load()
{
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
}
}
void AppearanceSettings::save()
{
if (m_lnfSettings) {
m_lnfSettings->save();
}
if (m_wallpaperSettings) {
m_wallpaperSettings->save();
}
}
void AppearanceSettings::defaults()
{
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
}
}
bool AppearanceSettings::isDefaults() const
{
bool defaults = true;
if (m_lnfSettings) {
defaults &= m_lnfSettings->isDefaults();
}
if (m_wallpaperSettings) {
defaults &= m_wallpaperSettings->isDefaults();
}
return defaults;
}
bool AppearanceSettings::isSaveNeeded() const
{
bool saveNeeded = false;
if (m_lnfSettings) {
saveNeeded |= m_lnfSettings->isSaveNeeded();
}
if (m_wallpaperSettings) {
saveNeeded |= m_wallpaperSettings->isSaveNeeded();
}
return saveNeeded;
}
void AppearanceSettings::loadWallpaperConfig()
{