File indexing completed on 2024-04-21 05:27:34

0001 /*
0002 SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
0003 SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "appearancesettings.h"
0007 
0008 #include <KConfigLoader>
0009 #include <KPackage/PackageLoader>
0010 
0011 #include "kscreensaversettings.h"
0012 #include "lnf_integration.h"
0013 #include "wallpaper_integration.h"
0014 
0015 AppearanceSettings::AppearanceSettings(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 QUrl AppearanceSettings::lnfConfigFile() const
0021 {
0022     return m_lnfConfigFile;
0023 }
0024 
0025 QUrl AppearanceSettings::wallpaperConfigFile() const
0026 {
0027     return m_wallpaperConfigFile;
0028 }
0029 
0030 KConfigPropertyMap *AppearanceSettings::wallpaperConfiguration() const
0031 {
0032     if (!m_wallpaperIntegration) {
0033         return nullptr;
0034     }
0035     return m_wallpaperIntegration->configuration();
0036 }
0037 
0038 KConfigPropertyMap *AppearanceSettings::lnfConfiguration() const
0039 {
0040     if (!m_lnfIntegration) {
0041         return nullptr;
0042     }
0043     return m_lnfIntegration->configuration();
0044 }
0045 
0046 ScreenLocker::WallpaperIntegration *AppearanceSettings::wallpaperIntegration() const
0047 {
0048     return m_wallpaperIntegration;
0049 }
0050 
0051 void AppearanceSettings::load()
0052 {
0053     loadWallpaperConfig();
0054     loadLnfConfig();
0055 
0056     if (m_lnfSettings) {
0057         m_lnfSettings->load();
0058         Q_EMIT m_lnfSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
0059     }
0060 
0061     if (m_wallpaperSettings) {
0062         m_wallpaperSettings->load();
0063         Q_EMIT m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
0064     }
0065 }
0066 
0067 void AppearanceSettings::save()
0068 {
0069     if (m_lnfSettings) {
0070         m_lnfSettings->save();
0071     }
0072 
0073     if (m_wallpaperSettings) {
0074         m_wallpaperSettings->save();
0075     }
0076 }
0077 
0078 void AppearanceSettings::defaults()
0079 {
0080     if (m_lnfSettings) {
0081         m_lnfSettings->setDefaults();
0082         Q_EMIT m_lnfSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
0083     }
0084 
0085     if (m_wallpaperSettings) {
0086         m_wallpaperSettings->setDefaults();
0087         Q_EMIT m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
0088     }
0089 }
0090 
0091 bool AppearanceSettings::isDefaults() const
0092 {
0093     bool defaults = true;
0094 
0095     if (m_lnfSettings) {
0096         defaults &= m_lnfSettings->isDefaults();
0097     }
0098 
0099     if (m_wallpaperSettings) {
0100         defaults &= m_wallpaperSettings->isDefaults();
0101     }
0102     return defaults;
0103 }
0104 
0105 bool AppearanceSettings::isSaveNeeded() const
0106 {
0107     bool saveNeeded = false;
0108 
0109     if (m_lnfSettings) {
0110         saveNeeded |= m_lnfSettings->isSaveNeeded();
0111     }
0112 
0113     if (m_wallpaperSettings) {
0114         saveNeeded |= m_wallpaperSettings->isSaveNeeded();
0115     }
0116 
0117     return saveNeeded;
0118 }
0119 
0120 void AppearanceSettings::loadWallpaperConfig()
0121 {
0122     if (m_wallpaperIntegration) {
0123         if (m_wallpaperIntegration->pluginName() == KScreenSaverSettings::getInstance().wallpaperPluginId()) {
0124             // nothing changed
0125             return;
0126         }
0127         delete m_wallpaperIntegration;
0128     }
0129 
0130     m_wallpaperIntegration = new ScreenLocker::WallpaperIntegration();
0131     m_wallpaperIntegration->setConfig(KScreenSaverSettings::getInstance().sharedConfig());
0132     m_wallpaperIntegration->setPluginName(KScreenSaverSettings::getInstance().wallpaperPluginId());
0133     m_wallpaperIntegration->init();
0134     m_wallpaperSettings = m_wallpaperIntegration->configScheme();
0135     m_wallpaperConfigFile = m_wallpaperIntegration->package().fileUrl(QByteArrayLiteral("ui"), QStringLiteral("config.qml"));
0136     Q_EMIT currentWallpaperChanged();
0137 }
0138 
0139 void AppearanceSettings::loadLnfConfig()
0140 {
0141     if (m_package.isValid() && m_lnfIntegration) {
0142         return;
0143     }
0144 
0145     Q_ASSERT(!m_package.isValid() && !m_lnfIntegration);
0146 
0147     m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
0148     KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE");
0149     const QString packageName = cg.readEntry("LookAndFeelPackage", QString());
0150     if (!packageName.isEmpty()) {
0151         m_package.setPath(packageName);
0152     }
0153 
0154     m_lnfIntegration = new ScreenLocker::LnFIntegration(this);
0155     m_lnfIntegration->setPackage(m_package);
0156     m_lnfIntegration->setConfig(KScreenSaverSettings::getInstance().sharedConfig());
0157     m_lnfIntegration->init();
0158     m_lnfSettings = m_lnfIntegration->configScheme();
0159 
0160     auto sourceFile = m_package.fileUrl(QByteArrayLiteral("lockscreen"), QStringLiteral("config.qml"));
0161     m_lnfConfigFile = sourceFile;
0162 }
0163 
0164 #include "moc_appearancesettings.cpp"