diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 22c1e4c..7880461 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -1,315 +1,301 @@ /******************************************************************** KSld - the KDE Screenlocker Daemon This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin Copyright (C) 2019 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "kcm.h" #include "kscreensaversettings.h" #include "ui_kcm.h" #include "screenlocker_interface.h" #include "../greeter/wallpaper_integration.h" #include "../greeter/lnf_integration.h" #include #include #include #include #include #include #include #include #include #include #include #include static const QString s_defaultWallpaperPackage = QStringLiteral("org.kde.image"); class ScreenLockerKcmForm : public QWidget, public Ui::ScreenLockerKcmForm { Q_OBJECT public: explicit ScreenLockerKcmForm(QWidget *parent); }; ScreenLockerKcmForm::ScreenLockerKcmForm(QWidget *parent) : QWidget(parent) { setupUi(this); layout()->setContentsMargins(0, 0, 0, 0); kcfg_Timeout->setSuffix(ki18ncp("Spinbox suffix"," minute"," minutes")); kcfg_LockGrace->setSuffix(ki18ncp("Spinbox suffix"," second"," seconds")); } ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args) : KCModule(parent, args) , m_settings(new KScreenSaverSettings(this)) , m_ui(new ScreenLockerKcmForm(this)) { QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(m_ui); addConfig(m_settings, m_ui); loadWallpapers(); connect(m_ui->wallpaperCombo, static_cast(&QComboBox::currentIndexChanged), this, &ScreenLockerKcm::loadWallpaperConfig); m_ui->wallpaperCombo->installEventFilter(this); auto proxy = new ScreenLockerProxy(this); m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("configDialog"), proxy); m_ui->lnfConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); m_ui->lnfConfigWidget->rootContext()->setContextProperty(QStringLiteral("configDialog"), proxy); connect(this, &ScreenLockerKcm::wallpaperConfigurationChanged, proxy, &ScreenLockerProxy::wallpaperConfigurationChanged); connect(this, &ScreenLockerKcm::currentWallpaperChanged, proxy, &ScreenLockerProxy::currentWallpaperChanged); m_ui->wallpaperConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/wallpaperconfig.qml"))); connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState())); m_ui->lnfConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/lnfconfig.qml"))); connect(m_ui->lnfConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState())); m_ui->installEventFilter(this); } void ScreenLockerKcm::load() { KCModule::load(); // Because the wallpaper plugin is currently handled wrongly m_settings->load(); m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); if (!packageName.isEmpty()) { m_package.setPath(packageName); } m_lnfIntegration = new ScreenLocker::LnFIntegration(this); m_lnfIntegration->setPackage(m_package); m_lnfIntegration->setConfig(m_settings->sharedConfig()); m_lnfIntegration->init(); m_lnfSettings = m_lnfIntegration->configScheme(); selectWallpaper(m_settings->wallpaperPlugin()); loadWallpaperConfig(); loadLnfConfig(); if (m_lnfSettings) { m_lnfSettings->load(); emit m_lnfSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate } if (m_wallpaperSettings) { m_wallpaperSettings->load(); emit m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate } updateState(); } -void ScreenLockerKcm::test(const QString &plugin) -{ - if (plugin.isEmpty() || plugin == QLatin1String("none")) { - return; - } - - QProcess proc; - QStringList arguments; - arguments << plugin << QStringLiteral("--testing"); - if (proc.execute(QString::fromLatin1(KSCREENLOCKER_GREET_BIN), arguments)) { - QMessageBox::critical(this, i18n("Error"), i18n("Failed to successfully test the screen locker.")); - } -} - void ScreenLockerKcm::save() { KCModule::save(); if (m_lnfSettings) { m_lnfSettings->save(); } if (m_wallpaperSettings) { m_wallpaperSettings->save(); } // reconfigure through DBus OrgKdeScreensaverInterface interface(QStringLiteral("org.kde.screensaver"), QStringLiteral("/ScreenSaver"), QDBusConnection::sessionBus()); if (interface.isValid()) { interface.configure(); } updateState(); } void ScreenLockerKcm::defaults() { KCModule::defaults(); selectWallpaper(s_defaultWallpaperPackage); if (m_lnfSettings) { m_lnfSettings->setDefaults(); emit m_lnfSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate } if (m_wallpaperSettings) { m_wallpaperSettings->setDefaults(); emit m_wallpaperSettings->configChanged(); // To force the ConfigPropertyMap to reevaluate } updateState(); } void ScreenLockerKcm::updateState() { bool isDefaults = m_settings->isDefaults(); bool isSaveNeeded = m_settings->isSaveNeeded(); if (m_lnfSettings) { isDefaults &= m_lnfSettings->isDefaults(); isSaveNeeded |= m_lnfSettings->isSaveNeeded(); } if (m_wallpaperSettings) { isDefaults &= m_wallpaperSettings->isDefaults(); isSaveNeeded |= m_wallpaperSettings->isSaveNeeded(); } emit changed(isSaveNeeded); emit defaulted(isDefaults); } void ScreenLockerKcm::loadWallpapers() { const auto wallpaperPackages = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/Wallpaper")); for (auto &package : wallpaperPackages) { m_ui->wallpaperCombo->addItem(package.name(), package.pluginId()); } } void ScreenLockerKcm::selectWallpaper(const QString &pluginId) { const auto index = m_ui->wallpaperCombo->findData(pluginId); if (index != -1) { m_ui->wallpaperCombo->setCurrentIndex(index); } else if (pluginId != s_defaultWallpaperPackage) { // fall back to default plugin selectWallpaper(s_defaultWallpaperPackage); } } void ScreenLockerKcm::loadWallpaperConfig() { // set the wallpaper config m_settings->setWallpaperPlugin(m_ui->wallpaperCombo->currentData().toString()); updateState(); if (m_wallpaperIntegration) { if (m_wallpaperIntegration->pluginName() == m_ui->wallpaperCombo->currentData().toString()) { // nothing changed return; } delete m_wallpaperIntegration; } emit currentWallpaperChanged(); m_wallpaperIntegration = new ScreenLocker::WallpaperIntegration(this); m_wallpaperIntegration->setConfig(m_settings->sharedConfig()); m_wallpaperIntegration->setPluginName(m_ui->wallpaperCombo->currentData().toString()); m_wallpaperIntegration->init(); m_wallpaperSettings = m_wallpaperIntegration->configScheme(); m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("wallpaper"), m_wallpaperIntegration); emit wallpaperConfigurationChanged(); m_ui->wallpaperConfigWidget->rootObject()->setProperty("sourceFile", m_wallpaperIntegration->package().filePath(QByteArrayLiteral("ui"), QStringLiteral("config.qml"))); } void ScreenLockerKcm::loadLnfConfig() { auto sourceFile = m_package.fileUrl(QByteArrayLiteral("lockscreen"), QStringLiteral("config.qml")); if (sourceFile.isEmpty()) { m_ui->lnfConfigWidget->hide(); return; } m_ui->lnfConfigWidget->rootObject()->setProperty("sourceFile", sourceFile); } KDeclarative::ConfigPropertyMap * ScreenLockerKcm::wallpaperConfiguration() const { if (!m_wallpaperIntegration) { return nullptr; } return m_wallpaperIntegration->configuration(); } KDeclarative::ConfigPropertyMap * ScreenLockerKcm::lnfConfiguration() const { if (!m_lnfIntegration) { return nullptr; } return m_lnfIntegration->configuration(); } QString ScreenLockerKcm::currentWallpaper() const { return m_ui->wallpaperCombo->currentData().toString(); } bool ScreenLockerKcm::eventFilter(QObject *watched, QEvent *event) { if (watched == m_ui) { if (event->type() == QEvent::PaletteChange) { m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); } return false; } if (watched != m_ui->wallpaperCombo) { return false; } if (event->type() == QEvent::Move) { if (auto object = m_ui->wallpaperConfigWidget->rootObject()) { // QtQuick Layouts have a hardcoded 5 px spacing by default object->setProperty("formAlignment", m_ui->wallpaperCombo->x() + 5); } if (auto object = m_ui->lnfConfigWidget->rootObject()) { // QtQuick Layouts have a hardcoded 5 px spacing by default object->setProperty("formAlignment", m_ui->wallpaperCombo->x() + 5); } } return false; } K_PLUGIN_FACTORY_WITH_JSON(ScreenLockerKcmFactory, "screenlocker.json", registerPlugin();) #include "kcm.moc" diff --git a/kcm/kcm.h b/kcm/kcm.h index 0b46680..f237d45 100644 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -1,117 +1,116 @@ /******************************************************************** KSld - the KDE Screenlocker Daemon This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin Copyright (C) 2014 Marco Martin Copyright (C) 2019 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include #include class KScreenSaverSettings; class ScreenLockerKcmForm; namespace ScreenLocker { class WallpaperIntegration; class LnFIntegration; } namespace KDeclarative { class ConfigPropertyMap; } class ScreenLockerKcm : public KCModule { Q_OBJECT public: enum Roles { PluginNameRole = Qt::UserRole +1, ScreenhotRole }; explicit ScreenLockerKcm(QWidget *parent = nullptr, const QVariantList& args = QVariantList()); KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const; KDeclarative::ConfigPropertyMap *lnfConfiguration() const; QString currentWallpaper() const; bool eventFilter(QObject *watched, QEvent *event) override; public Q_SLOTS: void load() override; void save() override; void defaults() override; - void test(const QString &plugin); Q_SIGNALS: void wallpaperConfigurationChanged(); void currentWallpaperChanged(); private Q_SLOTS: void updateState(); private: void loadWallpapers(); void selectWallpaper(const QString &pluginId); void loadWallpaperConfig(); void loadLnfConfig(); KPackage::Package m_package; KScreenSaverSettings *m_settings; ScreenLockerKcmForm *m_ui; ScreenLocker::WallpaperIntegration *m_wallpaperIntegration = nullptr; KCoreConfigSkeleton *m_wallpaperSettings = nullptr; ScreenLocker::LnFIntegration* m_lnfIntegration = nullptr; KCoreConfigSkeleton *m_lnfSettings = nullptr; }; //see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property class ScreenLockerProxy : public QObject { Q_OBJECT Q_PROPERTY(KDeclarative::ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration NOTIFY wallpaperConfigurationChanged) Q_PROPERTY(KDeclarative::ConfigPropertyMap *lnfConfiguration READ lnfConfiguration CONSTANT) Q_PROPERTY(QString currentWallpaper READ currentWallpaper NOTIFY currentWallpaperChanged) public: ScreenLockerProxy(ScreenLockerKcm *parent) : QObject(parent), q(parent) { } KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const { return q->wallpaperConfiguration(); } KDeclarative::ConfigPropertyMap *lnfConfiguration() const { return q->lnfConfiguration(); } QString currentWallpaper() const { return q->currentWallpaper(); } Q_SIGNALS: void wallpaperConfigurationChanged(); void currentWallpaperChanged(); private: ScreenLockerKcm* q; };