File indexing completed on 2024-04-21 05:27:34
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2019 Kevin Ottens <kevin.ottens@enioka.com> 0004 SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 #include "kcm.h" 0009 #include "appearancesettings.h" 0010 #include "kscreenlockerdata.h" 0011 #include "lnf_integration.h" 0012 #include "screenlocker_interface.h" 0013 0014 #include <KConfigLoader> 0015 #include <KConfigPropertyMap> 0016 #include <KGlobalAccel> 0017 #include <KLocalizedString> 0018 #include <KPluginFactory> 0019 0020 #include <QList> 0021 0022 K_PLUGIN_FACTORY_WITH_JSON(ScreenLockerKcmFactory, "kcm_screenlocker.json", registerPlugin<ScreenLockerKcm>(); registerPlugin<KScreenLockerData>();) 0023 0024 ScreenLockerKcm::ScreenLockerKcm(QObject *parent, const KPluginMetaData &data) 0025 : KQuickManagedConfigModule(parent, data) 0026 , m_appearanceSettings(new AppearanceSettings(this)) 0027 { 0028 registerSettings(&KScreenSaverSettings::getInstance()); 0029 0030 constexpr const char *url = "org.kde.private.kcms.screenlocker"; 0031 qRegisterMetaType<QList<WallpaperInfo>>("QList<WallpaperInfo>"); 0032 qmlRegisterAnonymousType<KScreenSaverSettings>(url, 1); 0033 qmlRegisterAnonymousType<WallpaperInfo>(url, 1); 0034 qmlRegisterAnonymousType<ScreenLocker::WallpaperIntegration>(url, 1); 0035 qmlRegisterAnonymousType<KConfigPropertyMap>(url, 1); 0036 qmlProtectModule(url, 1); 0037 0038 // Our modules will be checking the Plasmoid attached object when running from Plasma, let it load the module 0039 constexpr const char *uri = "org.kde.plasma.plasmoid"; 0040 qmlRegisterUncreatableType<QObject>(uri, 2, 0, "PlasmoidPlaceholder", QStringLiteral("Do not create objects of type Plasmoid")); 0041 0042 connect(&KScreenSaverSettings::getInstance(), 0043 &KScreenSaverSettings::wallpaperPluginIdChanged, 0044 m_appearanceSettings, 0045 &AppearanceSettings::loadWallpaperConfig); 0046 connect(m_appearanceSettings, &AppearanceSettings::currentWallpaperChanged, this, &ScreenLockerKcm::currentWallpaperChanged); 0047 } 0048 0049 void ScreenLockerKcm::load() 0050 { 0051 KQuickManagedConfigModule::load(); 0052 m_appearanceSettings->load(); 0053 0054 updateState(); 0055 } 0056 0057 void ScreenLockerKcm::save() 0058 { 0059 KQuickManagedConfigModule::save(); 0060 m_appearanceSettings->save(); 0061 0062 // reconfigure through DBus 0063 OrgKdeScreensaverInterface interface(QStringLiteral("org.kde.screensaver"), QStringLiteral("/ScreenSaver"), QDBusConnection::sessionBus()); 0064 if (interface.isValid()) { 0065 interface.configure(); 0066 } 0067 updateState(); 0068 } 0069 0070 void ScreenLockerKcm::defaults() 0071 { 0072 KQuickManagedConfigModule::defaults(); 0073 m_appearanceSettings->defaults(); 0074 0075 updateState(); 0076 } 0077 0078 void ScreenLockerKcm::updateState() 0079 { 0080 m_forceUpdateState = false; 0081 settingsChanged(); 0082 Q_EMIT isDefaultsAppearanceChanged(); 0083 } 0084 0085 void ScreenLockerKcm::forceUpdateState() 0086 { 0087 m_forceUpdateState = true; 0088 settingsChanged(); 0089 Q_EMIT isDefaultsAppearanceChanged(); 0090 } 0091 0092 bool ScreenLockerKcm::isSaveNeeded() const 0093 { 0094 return m_forceUpdateState || m_appearanceSettings->isSaveNeeded(); 0095 } 0096 0097 bool ScreenLockerKcm::isDefaults() const 0098 { 0099 return m_appearanceSettings->isDefaults(); 0100 } 0101 0102 KConfigPropertyMap *ScreenLockerKcm::wallpaperConfiguration() const 0103 { 0104 return m_appearanceSettings->wallpaperConfiguration(); 0105 } 0106 0107 KConfigPropertyMap *ScreenLockerKcm::lnfConfiguration() const 0108 { 0109 return m_appearanceSettings->lnfConfiguration(); 0110 } 0111 0112 KScreenSaverSettings *ScreenLockerKcm::settings() const 0113 { 0114 return &KScreenSaverSettings::getInstance(); 0115 } 0116 0117 QString ScreenLockerKcm::currentWallpaper() const 0118 { 0119 return KScreenSaverSettings::getInstance().wallpaperPluginId(); 0120 } 0121 0122 bool ScreenLockerKcm::isDefaultsAppearance() const 0123 { 0124 return m_appearanceSettings->isDefaults(); 0125 } 0126 0127 QUrl ScreenLockerKcm::lnfConfigFile() const 0128 { 0129 return m_appearanceSettings->lnfConfigFile(); 0130 } 0131 0132 QUrl ScreenLockerKcm::wallpaperConfigFile() const 0133 { 0134 return m_appearanceSettings->wallpaperConfigFile(); 0135 } 0136 0137 ScreenLocker::WallpaperIntegration *ScreenLockerKcm::wallpaperIntegration() const 0138 { 0139 return m_appearanceSettings->wallpaperIntegration(); 0140 } 0141 0142 #include "kcm.moc" 0143 0144 #include "moc_kcm.cpp"