1 /******************************************************************** 2 This file is part of the KDE project. 3 4 Copyright 2020 Cyril Rossi <cyril.rossi@enioka.com> 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 *********************************************************************/ 19 20 #include "appearancesettings.h" 21 22 #include <KConfigLoader> 23 #include <KPackage/PackageLoader> 24 25 #include "kscreensaversettings.h" 26 #include "lnf_integration.h" 27 #include "wallpaper_integration.h" 28 AppearanceSettings(QObject * parent)29AppearanceSettings::AppearanceSettings(QObject *parent) 30 : QObject(parent) 31 { 32 } 33 lnfConfigFile() const34QUrl AppearanceSettings::lnfConfigFile() const 35 { 36 return m_lnfConfigFile; 37 } 38 wallpaperConfigFile() const39QUrl AppearanceSettings::wallpaperConfigFile() const 40 { 41 return m_wallpaperConfigFile; 42 } 43 wallpaperConfiguration() const44KDeclarative::ConfigPropertyMap *AppearanceSettings::wallpaperConfiguration() const 45 { 46 if (!m_wallpaperIntegration) { 47 return nullptr; 48 } 49 return m_wallpaperIntegration->configuration(); 50 } 51 lnfConfiguration() const52KDeclarative::ConfigPropertyMap *AppearanceSettings::lnfConfiguration() const 53 { 54 if (!m_lnfIntegration) { 55 return nullptr; 56 } 57 return m_lnfIntegration->configuration(); 58 } 59 wallpaperIntegration() const60ScreenLocker::WallpaperIntegration *AppearanceSettings::wallpaperIntegration() const 61 { 62 return m_wallpaperIntegration; 63 } 64 load()65void AppearanceSettings::load() 66 { 67 loadWallpaperConfig(); 68 loadLnfConfig(); 69 70 if (m_lnfSettings) { 71 m_lnfSettings->load(); 72 Q_EMIT m_lnfSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate 73 } 74 75 if (m_wallpaperSettings) { 76 m_wallpaperSettings->load(); 77 Q_EMIT m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate 78 } 79 } 80 save()81void AppearanceSettings::save() 82 { 83 if (m_lnfSettings) { 84 m_lnfSettings->save(); 85 } 86 87 if (m_wallpaperSettings) { 88 m_wallpaperSettings->save(); 89 } 90 } 91 defaults()92void AppearanceSettings::defaults() 93 { 94 if (m_lnfSettings) { 95 m_lnfSettings->setDefaults(); 96 Q_EMIT m_lnfSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate 97 } 98 99 if (m_wallpaperSettings) { 100 m_wallpaperSettings->setDefaults(); 101 Q_EMIT m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate 102 } 103 } 104 isDefaults() const105bool AppearanceSettings::isDefaults() const 106 { 107 bool defaults = true; 108 109 if (m_lnfSettings) { 110 defaults &= m_lnfSettings->isDefaults(); 111 } 112 113 if (m_wallpaperSettings) { 114 defaults &= m_wallpaperSettings->isDefaults(); 115 } 116 return defaults; 117 } 118 isSaveNeeded() const119bool AppearanceSettings::isSaveNeeded() const 120 { 121 bool saveNeeded = false; 122 123 if (m_lnfSettings) { 124 saveNeeded |= m_lnfSettings->isSaveNeeded(); 125 } 126 127 if (m_wallpaperSettings) { 128 saveNeeded |= m_wallpaperSettings->isSaveNeeded(); 129 } 130 131 return saveNeeded; 132 } 133 loadWallpaperConfig()134void AppearanceSettings::loadWallpaperConfig() 135 { 136 if (m_wallpaperIntegration) { 137 if (m_wallpaperIntegration->pluginName() == KScreenSaverSettings::getInstance().wallpaperPluginId()) { 138 // nothing changed 139 return; 140 } 141 delete m_wallpaperIntegration; 142 } 143 144 m_wallpaperIntegration = new ScreenLocker::WallpaperIntegration(this); 145 m_wallpaperIntegration->setConfig(KScreenSaverSettings::getInstance().sharedConfig()); 146 m_wallpaperIntegration->setPluginName(KScreenSaverSettings::getInstance().wallpaperPluginId()); 147 m_wallpaperIntegration->init(); 148 m_wallpaperSettings = m_wallpaperIntegration->configScheme(); 149 m_wallpaperConfigFile = m_wallpaperIntegration->package().fileUrl(QByteArrayLiteral("ui"), QStringLiteral("config.qml")); 150 Q_EMIT currentWallpaperChanged(); 151 } 152 loadLnfConfig()153void AppearanceSettings::loadLnfConfig() 154 { 155 if (m_package.isValid() && m_lnfIntegration) { 156 return; 157 } 158 159 Q_ASSERT(!m_package.isValid() && !m_lnfIntegration); 160 161 m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); 162 KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); 163 const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); 164 if (!packageName.isEmpty()) { 165 m_package.setPath(packageName); 166 } 167 168 m_lnfIntegration = new ScreenLocker::LnFIntegration(this); 169 m_lnfIntegration->setPackage(m_package); 170 m_lnfIntegration->setConfig(KScreenSaverSettings::getInstance().sharedConfig()); 171 m_lnfIntegration->init(); 172 m_lnfSettings = m_lnfIntegration->configScheme(); 173 174 auto sourceFile = m_package.fileUrl(QByteArrayLiteral("lockscreen"), QStringLiteral("config.qml")); 175 m_lnfConfigFile = sourceFile; 176 } 177