1 /********************************************************************
2 KSld - the KDE Screenlocker Daemon
3 This file is part of the KDE project.
4
5 Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
6 Copyright (C) 2019 Kevin Ottens <kevin.ottens@enioka.com>
7 Copyright (C) 2020 David Redondo <kde@david-redondo.de>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************/
22 #include "kcm.h"
23 #include "appearancesettings.h"
24 #include "kscreenlockerdata.h"
25 #include "lnf_integration.h"
26 #include "screenlocker_interface.h"
27 #include "wallpaper_integration.h"
28
29 #include <KAboutData>
30 #include <KConfigLoader>
31 #include <KDeclarative/ConfigPropertyMap>
32 #include <KGlobalAccel>
33 #include <KLocalizedString>
34 #include <KPluginFactory>
35
36 #include <KPackage/PackageLoader>
37
38 #include <QVector>
39
40 K_PLUGIN_FACTORY_WITH_JSON(ScreenLockerKcmFactory, "screenlocker.json", registerPlugin<ScreenLockerKcm>(); registerPlugin<KScreenLockerData>();)
41
ScreenLockerKcm(QObject * parent,const QVariantList & args)42 ScreenLockerKcm::ScreenLockerKcm(QObject *parent, const QVariantList &args)
43 : KQuickAddons::ManagedConfigModule(parent, args)
44 , m_appearanceSettings(new AppearanceSettings(this))
45 {
46 registerSettings(&KScreenSaverSettings::getInstance());
47
48 constexpr const char *url = "org.kde.private.kcms.screenlocker";
49 qRegisterMetaType<QVector<WallpaperInfo>>("QVector<WallpaperInfo>");
50 qmlRegisterAnonymousType<KScreenSaverSettings>(url, 1);
51 qmlRegisterAnonymousType<WallpaperInfo>(url, 1);
52 qmlRegisterAnonymousType<ScreenLocker::WallpaperIntegration>(url, 1);
53 qmlRegisterAnonymousType<KDeclarative::ConfigPropertyMap>(url, 1);
54 qmlProtectModule(url, 1);
55 KAboutData *about = new KAboutData(QStringLiteral("kcm_screenlocker"), i18n("Screen Locking"), QStringLiteral("1.0"), QString(), KAboutLicense::GPL);
56 about->addAuthor(i18n("Martin Gräßlin"), QString(), QStringLiteral("mgraesslin@kde.org"));
57 about->addAuthor(i18n("Kevin Ottens"), QString(), QStringLiteral("kevin.ottens@enioka.com"));
58 setAboutData(about);
59 connect(&KScreenSaverSettings::getInstance(),
60 &KScreenSaverSettings::wallpaperPluginIdChanged,
61 m_appearanceSettings,
62 &AppearanceSettings::loadWallpaperConfig);
63 connect(m_appearanceSettings, &AppearanceSettings::currentWallpaperChanged, this, &ScreenLockerKcm::currentWallpaperChanged);
64 }
65
load()66 void ScreenLockerKcm::load()
67 {
68 ManagedConfigModule::load();
69 m_appearanceSettings->load();
70
71 updateState();
72 }
73
save()74 void ScreenLockerKcm::save()
75 {
76 ManagedConfigModule::save();
77 m_appearanceSettings->save();
78
79 // reconfigure through DBus
80 OrgKdeScreensaverInterface interface(QStringLiteral("org.kde.screensaver"), QStringLiteral("/ScreenSaver"), QDBusConnection::sessionBus());
81 if (interface.isValid()) {
82 interface.configure();
83 }
84 updateState();
85 }
86
defaults()87 void ScreenLockerKcm::defaults()
88 {
89 ManagedConfigModule::defaults();
90 m_appearanceSettings->defaults();
91
92 updateState();
93 }
94
updateState()95 void ScreenLockerKcm::updateState()
96 {
97 settingsChanged();
98 Q_EMIT isDefaultsAppearanceChanged();
99 }
100
isSaveNeeded() const101 bool ScreenLockerKcm::isSaveNeeded() const
102 {
103 return m_appearanceSettings->isSaveNeeded();
104 }
105
isDefaults() const106 bool ScreenLockerKcm::isDefaults() const
107 {
108 return m_appearanceSettings->isDefaults();
109 }
110
wallpaperConfiguration() const111 KDeclarative::ConfigPropertyMap *ScreenLockerKcm::wallpaperConfiguration() const
112 {
113 return m_appearanceSettings->wallpaperConfiguration();
114 }
115
lnfConfiguration() const116 KDeclarative::ConfigPropertyMap *ScreenLockerKcm::lnfConfiguration() const
117 {
118 return m_appearanceSettings->lnfConfiguration();
119 }
120
settings() const121 KScreenSaverSettings *ScreenLockerKcm::settings() const
122 {
123 return &KScreenSaverSettings::getInstance();
124 }
125
currentWallpaper() const126 QString ScreenLockerKcm::currentWallpaper() const
127 {
128 return KScreenSaverSettings::getInstance().wallpaperPluginId();
129 }
130
isDefaultsAppearance() const131 bool ScreenLockerKcm::isDefaultsAppearance() const
132 {
133 return m_appearanceSettings->isDefaults();
134 }
135
lnfConfigFile() const136 QUrl ScreenLockerKcm::lnfConfigFile() const
137 {
138 return m_appearanceSettings->lnfConfigFile();
139 }
140
wallpaperConfigFile() const141 QUrl ScreenLockerKcm::wallpaperConfigFile() const
142 {
143 return m_appearanceSettings->wallpaperConfigFile();
144 }
145
wallpaperIntegration() const146 ScreenLocker::WallpaperIntegration *ScreenLockerKcm::wallpaperIntegration() const
147 {
148 return m_appearanceSettings->wallpaperIntegration();
149 }
150
151 #include "kcm.moc"
152