1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*
SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "appearancesettings.h"
#include <KConfigLoader>
#include <KPackage/PackageLoader>
#include "kscreensaversettings.h"
#include "shell_integration.h"
#include "wallpaper_integration.h"
AppearanceSettings::AppearanceSettings(QObject *parent)
: QObject(parent)
{
}
QUrl AppearanceSettings::shellConfigFile() const
{
return m_shellConfigFile;
}
QUrl AppearanceSettings::wallpaperConfigFile() const
{
return m_wallpaperConfigFile;
}
KConfigPropertyMap *AppearanceSettings::wallpaperConfiguration() const
{
if (!m_wallpaperIntegration) {
return nullptr;
}
return m_wallpaperIntegration->configuration();
}
KConfigPropertyMap *AppearanceSettings::shellConfiguration() const
{
if (!m_shellIntegration) {
return nullptr;
}
return m_shellIntegration->configuration();
}
ScreenLocker::WallpaperIntegration *AppearanceSettings::wallpaperIntegration() const
{
return m_wallpaperIntegration;
}
void AppearanceSettings::load()
{
loadWallpaperConfig();
loadShellConfig();
if (m_shellSettings) {
m_shellSettings->load();
Q_EMIT m_shellSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
}
if (m_wallpaperSettings) {
m_wallpaperSettings->load();
Q_EMIT m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
}
}
void AppearanceSettings::save()
{
if (m_shellSettings) {
m_shellSettings->save();
}
if (m_wallpaperSettings) {
m_wallpaperSettings->save();
}
}
void AppearanceSettings::defaults()
{
if (m_shellSettings) {
m_shellSettings->setDefaults();
Q_EMIT m_shellSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
}
if (m_wallpaperSettings) {
m_wallpaperSettings->setDefaults();
Q_EMIT m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate
}
}
bool AppearanceSettings::isDefaults() const
{
bool defaults = true;
if (m_shellSettings) {
defaults &= m_shellSettings->isDefaults();
}
if (m_wallpaperSettings) {
defaults &= m_wallpaperSettings->isDefaults();
}
return defaults;
}
bool AppearanceSettings::isSaveNeeded() const
{
bool saveNeeded = false;
if (m_shellSettings) {
saveNeeded |= m_shellSettings->isSaveNeeded();
}
if (m_wallpaperSettings) {
saveNeeded |= m_wallpaperSettings->isSaveNeeded();
}
return saveNeeded;
}
void AppearanceSettings::loadWallpaperConfig()
{
if (m_wallpaperIntegration) {
if (m_wallpaperIntegration->pluginName() == KScreenSaverSettings::getInstance().wallpaperPluginId()) {
// nothing changed
return;
}
delete m_wallpaperIntegration;
}
m_wallpaperIntegration = new ScreenLocker::WallpaperIntegration();
m_wallpaperIntegration->setConfig(KScreenSaverSettings::getInstance().sharedConfig());
m_wallpaperIntegration->setPluginName(KScreenSaverSettings::getInstance().wallpaperPluginId());
m_wallpaperIntegration->init();
m_wallpaperSettings = m_wallpaperIntegration->configScheme();
m_wallpaperConfigFile = m_wallpaperIntegration->package().fileUrl(QByteArrayLiteral("ui"), QStringLiteral("config.qml"));
Q_EMIT currentWallpaperChanged();
}
void AppearanceSettings::loadShellConfig()
{
if (m_package.isValid() && m_shellIntegration) {
return;
}
Q_ASSERT(!m_package.isValid() && !m_shellIntegration);
m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Shell"));
m_shellIntegration = new ScreenLocker::ShellIntegration(this);
m_package.setPath(m_shellIntegration->defaultShell());
m_shellIntegration->setPackage(m_package);
m_shellIntegration->setConfig(KScreenSaverSettings::getInstance().sharedConfig());
m_shellIntegration->init();
m_shellSettings = m_shellIntegration->configScheme();
auto sourceFile = m_package.fileUrl(QByteArrayLiteral("lockscreen"), QStringLiteral("config.qml"));
m_shellConfigFile = sourceFile;
}
#include "moc_appearancesettings.cpp"
|