diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -167,10 +167,11 @@
waylandserver.cpp
powermanagement.cpp
powermanagement_inhibition.cpp
+ kscreensaversettings.cpp
)
qt5_add_dbus_adaptor(ksld_SRCS ${screensaver_dbusXML} interface.h ScreenLocker::Interface)
qt5_add_dbus_adaptor(ksld_SRCS ${kscreensaver_dbusXML} interface.h ScreenLocker::Interface kscreensaveradaptor KScreenSaverAdaptor)
-kconfig_add_kcfg_files(ksld_SRCS kcfg/kscreensaversettings.kcfgc)
+kconfig_add_kcfg_files(ksld_SRCS kcfg/kscreensaversettingsbase.kcfgc)
qt5_add_dbus_interface(ksld_SRCS ${powerdevilpolicyagent_xml} powerdevilpolicyagent)
ecm_add_wayland_server_protocol(ksld_SRCS
@@ -193,6 +194,7 @@
KF5::CoreAddons
KF5::ConfigGui
KF5::WindowSystem
+ KF5::XmlGui
${X11_LIBRARIES}
XCB::XCB
XCB::KEYSYMS
diff --git a/greeter/CMakeLists.txt b/greeter/CMakeLists.txt
--- a/greeter/CMakeLists.txt
+++ b/greeter/CMakeLists.txt
@@ -22,7 +22,7 @@
endif()
qt5_add_resources(kscreenlocker_greet_SRCS fallbacktheme.qrc)
-kconfig_add_kcfg_files(kscreenlocker_greet_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../kcfg/kscreensaversettings.kcfgc)
+kconfig_add_kcfg_files(kscreenlocker_greet_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../kcfg/kscreensaversettingsbase.kcfgc)
ecm_add_wayland_client_protocol(kscreenlocker_greet_SRCS
PROTOCOL ../protocols/ksld.xml
diff --git a/greeter/greeterapp.cpp b/greeter/greeterapp.cpp
--- a/greeter/greeterapp.cpp
+++ b/greeter/greeterapp.cpp
@@ -19,7 +19,7 @@
along with this program. If not, see .
*********************************************************************/
#include "greeterapp.h"
-#include "kscreensaversettings.h"
+#include "kscreensaversettingsbase.h"
#include "authenticator.h"
#include "noaccessnetworkaccessmanagerfactory.h"
#include "wallpaper_integration.h"
@@ -181,25 +181,25 @@
m_resetRequestIgnoreTimer->setInterval(2000);
connect(m_resetRequestIgnoreTimer, &QTimer::timeout, this, &UnlockApp::resetRequestIgnore);
- KScreenSaverSettings::self()->load();
+ KScreenSaverSettingsBase::self()->load();
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE");
m_packageName = cg.readEntry("LookAndFeelPackage", QString());
if (!m_packageName.isEmpty()) {
package.setPath(m_packageName);
}
- if (!KScreenSaverSettings::theme().isEmpty()) {
- package.setPath(KScreenSaverSettings::theme());
+ if (!KScreenSaverSettingsBase::theme().isEmpty()) {
+ package.setPath(KScreenSaverSettingsBase::theme());
}
m_mainQmlPath = package.fileUrl("lockscreenmainscript");
- m_wallpaperIntegration->setConfig(KScreenSaverSettings::self()->sharedConfig());
- m_wallpaperIntegration->setPluginName(KScreenSaverSettings::self()->wallpaperPlugin());
+ m_wallpaperIntegration->setConfig(KScreenSaverSettingsBase::self()->sharedConfig());
+ m_wallpaperIntegration->setPluginName(KScreenSaverSettingsBase::self()->wallpaperPlugin());
m_wallpaperIntegration->init();
m_lnfIntegration->setPackage(package);
- m_lnfIntegration->setConfig(KScreenSaverSettings::self()->sharedConfig());
+ m_lnfIntegration->setConfig(KScreenSaverSettingsBase::self()->sharedConfig());
m_lnfIntegration->init();
diff --git a/kcfg/kscreensaversettings.kcfgc b/kcfg/kscreensaversettingsbase.kcfgc
rename from kcfg/kscreensaversettings.kcfgc
rename to kcfg/kscreensaversettingsbase.kcfgc
--- a/kcfg/kscreensaversettings.kcfgc
+++ b/kcfg/kscreensaversettingsbase.kcfgc
@@ -1,4 +1,4 @@
File=kscreenlockersettings.kcfg
-ClassName=KScreenSaverSettings
+ClassName=KScreenSaverSettingsBase
Singleton=true
Mutators=true
diff --git a/kcm/CMakeLists.txt b/kcm/CMakeLists.txt
--- a/kcm/CMakeLists.txt
+++ b/kcm/CMakeLists.txt
@@ -3,13 +3,15 @@
set(screenlocker_kcm_SRCS
kcm.cpp
+ ../kscreensaversettings.cpp
../greeter/wallpaper_integration.cpp
../greeter/lnf_integration.cpp
)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../)
ki18n_wrap_ui(screenlocker_kcm_SRCS kcm.ui)
-kconfig_add_kcfg_files(screenlocker_kcm_SRCS ../kcfg/kscreensaversettings.kcfgc)
+kconfig_add_kcfg_files(screenlocker_kcm_SRCS ../kcfg/kscreensaversettingsbase.kcfgc)
qt5_add_dbus_interface(screenlocker_kcm_SRCS ../dbus/org.kde.screensaver.xml screenlocker_interface)
qt5_add_resources( screenlocker_kcm_SRCS resources.qrc )
diff --git a/kcm/kcm.h b/kcm/kcm.h
--- a/kcm/kcm.h
+++ b/kcm/kcm.h
@@ -22,7 +22,7 @@
#include
#include
-class KActionCollection;
+class KScreenSaverSettings;
class ScreenLockerKcmForm;
namespace ScreenLocker
@@ -65,14 +65,12 @@
void currentWallpaperChanged();
private:
- void shortcutChanged(const QKeySequence &key);
- bool shouldSaveShortcut();
void loadWallpapers();
void selectWallpaper(const QString &pluginId);
void loadWallpaperConfig();
void loadLnfConfig();
KPackage::Package m_package;
- KActionCollection *m_actionCollection;
+ KScreenSaverSettings *m_settings;
ScreenLockerKcmForm *m_ui;
ScreenLocker::WallpaperIntegration *m_wallpaperIntegration = nullptr;
ScreenLocker::LnFIntegration* m_lnfIntegration = nullptr;
diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp
--- a/kcm/kcm.cpp
+++ b/kcm/kcm.cpp
@@ -25,7 +25,7 @@
#include "../greeter/lnf_integration.h"
#include
-#include
+#include
#include
#include
#include
@@ -38,7 +38,6 @@
#include
#include
-static const QString s_lockActionName = QStringLiteral("Lock Session");
static const QString s_defaultWallpaperPackage = QStringLiteral("org.kde.image");
class ScreenLockerKcmForm : public QWidget, public Ui::ScreenLockerKcmForm
@@ -62,21 +61,13 @@
ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
- , m_actionCollection(new KActionCollection(this, QStringLiteral("ksmserver")))
+ , m_settings(new KScreenSaverSettings(this))
, m_ui(new ScreenLockerKcmForm(this))
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_ui);
- addConfig(KScreenSaverSettings::self(), m_ui);
-
- m_actionCollection->setConfigGlobal(true);
- QAction *a = m_actionCollection->addAction(s_lockActionName);
- a->setProperty("isConfigurationAction", true);
- m_ui->lockscreenShortcut->setCheckForConflictsAgainst(KKeySequenceWidget::None);
- a->setText(i18n("Lock Session"));
- KGlobalAccel::self()->setShortcut(a, QList{Qt::ALT+Qt::CTRL+Qt::Key_L, Qt::Key_ScreenSaver});
- connect(m_ui->lockscreenShortcut, &KKeySequenceWidget::keySequenceChanged, this, &ScreenLockerKcm::shortcutChanged);
+ addConfig(m_settings, m_ui);
loadWallpapers();
auto wallpaperChangedSignal = static_cast(&QComboBox::currentIndexChanged);
@@ -106,15 +97,6 @@
m_ui->installEventFilter(this);
}
-void ScreenLockerKcm::shortcutChanged(const QKeySequence &key)
-{
- if (QAction *a = m_actionCollection->action(s_lockActionName)) {
- auto shortcuts = KGlobalAccel::self()->shortcut(a);
- m_ui->lockscreenShortcut->setProperty("changed", !shortcuts.contains(key));
- }
- changed();
-}
-
void ScreenLockerKcm::load()
{
KCModule::load();
@@ -126,19 +108,13 @@
m_package.setPath(packageName);
}
- if (QAction *a = m_actionCollection->action(s_lockActionName)) {
- auto shortcuts = KGlobalAccel::self()->shortcut(a);
- if (!shortcuts.isEmpty()) {
- m_ui->lockscreenShortcut->setKeySequence(shortcuts.first());
- }
- }
m_lnfIntegration = new ScreenLocker::LnFIntegration(this);
m_lnfIntegration->setPackage(m_package);
- m_lnfIntegration->setConfig(KScreenSaverSettings::self()->sharedConfig());
+ m_lnfIntegration->setConfig(m_settings->sharedConfig());
m_lnfIntegration->init();
- selectWallpaper(KScreenSaverSettings::self()->wallpaperPlugin());
+ selectWallpaper(m_settings->wallpaperPlugin());
loadWallpaperConfig();
loadLnfConfig();
}
@@ -159,25 +135,15 @@
void ScreenLockerKcm::save()
{
- if (!shouldSaveShortcut()) {
- QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection);
- return;
- }
KCModule::save();
QMetaObject::invokeMethod(m_ui->wallpaperConfigWidget->rootObject(), "saveConfig");
QMetaObject::invokeMethod(m_ui->lnfConfigWidget->rootObject(), "saveConfig");
// set the wallpaper config
- KScreenSaverSettings::self()->setWallpaperPlugin(m_ui->wallpaperCombo->currentData().toString());
+ m_settings->setWallpaperPlugin(m_ui->wallpaperCombo->currentData().toString());
+
+ m_settings->save();
- KScreenSaverSettings::self()->save();
- if (m_ui->lockscreenShortcut->property("changed").toBool()) {
- if (QAction *a = m_actionCollection->action(s_lockActionName)) {
- KGlobalAccel::self()->setShortcut(a, QList{m_ui->lockscreenShortcut->keySequence()}, KGlobalAccel::NoAutoloading);
- m_actionCollection->writeSettings();
- }
- m_ui->lockscreenShortcut->setProperty("changed", false);
- }
// reconfigure through DBus
OrgKdeScreensaverInterface interface(QStringLiteral("org.kde.screensaver"),
QStringLiteral("/ScreenSaver"),
@@ -187,28 +153,9 @@
}
}
-bool ScreenLockerKcm::shouldSaveShortcut()
-{
- if (m_ui->lockscreenShortcut->property("changed").toBool()) {
- const QKeySequence &sequence = m_ui->lockscreenShortcut->keySequence();
- auto conflicting = KGlobalAccel::getGlobalShortcutsByKey(sequence);
- if (!conflicting.isEmpty()) {
- // Inform and ask the user about the conflict and reassigning
- // the keys sequence
- if (!KGlobalAccel::promptStealShortcutSystemwide(this, conflicting, sequence)) {
- return false;
- }
- KGlobalAccel::stealShortcutSystemwide(sequence);
- }
- }
- return true;
-}
-
void ScreenLockerKcm::defaults()
{
KCModule::defaults();
- m_ui->lockscreenShortcut->setKeySequence(Qt::ALT+Qt::CTRL+Qt::Key_L);
-
selectWallpaper(s_defaultWallpaperPackage);
}
@@ -243,7 +190,7 @@
emit currentWallpaperChanged();
m_wallpaperIntegration = new ScreenLocker::WallpaperIntegration(this);
- m_wallpaperIntegration->setConfig(KScreenSaverSettings::self()->sharedConfig());
+ m_wallpaperIntegration->setConfig(m_settings->sharedConfig());
m_wallpaperIntegration->setPluginName(m_ui->wallpaperCombo->currentData().toString());
m_wallpaperIntegration->init();
m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("wallpaper"), m_wallpaperIntegration);
diff --git a/kcm/kcm.ui b/kcm/kcm.ui
--- a/kcm/kcm.ui
+++ b/kcm/kcm.ui
@@ -97,7 +97,7 @@
-
-
+
diff --git a/kscreensaversettings.h b/kscreensaversettings.h
new file mode 100644
--- /dev/null
+++ b/kscreensaversettings.h
@@ -0,0 +1,45 @@
+/********************************************************************
+ This file is part of the KDE project.
+
+ Copyright 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 .
+*********************************************************************/
+#ifndef KSCREENSAVERSETTINGS_H
+#define KSCREENSAVERSETTINGS_H
+
+#include "kscreensaversettingsbase.h"
+
+class QAction;
+class KActionCollection;
+
+class KScreenSaverSettings : public KScreenSaverSettingsBase
+{
+ Q_OBJECT
+ Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
+public:
+ static QList defaultShortcuts();
+
+ KScreenSaverSettings(QObject *parent = nullptr);
+ ~KScreenSaverSettings() override;
+
+ QKeySequence shortcut() const;
+ void setShortcut(const QKeySequence &sequence);
+
+private:
+ KActionCollection *m_actionCollection;
+ QAction *m_lockAction;
+};
+
+#endif // KSCREENSAVERSETTINGS_H
diff --git a/kscreensaversettings.cpp b/kscreensaversettings.cpp
new file mode 100644
--- /dev/null
+++ b/kscreensaversettings.cpp
@@ -0,0 +1,69 @@
+/********************************************************************
+ This file is part of the KDE project.
+
+ Copyright 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 "kscreensaversettings.h"
+
+#include
+#include
+#include
+
+QList KScreenSaverSettings::defaultShortcuts()
+{
+ return {
+ Qt::META + Qt::Key_L,
+ Qt::ALT + Qt::CTRL + Qt::Key_L,
+ Qt::Key_ScreenSaver
+ };
+}
+
+KScreenSaverSettings::KScreenSaverSettings(QObject *parent)
+ : KScreenSaverSettingsBase()
+ , m_actionCollection(new KActionCollection(this, QStringLiteral("ksmserver")))
+ , m_lockAction(nullptr)
+{
+ setParent(parent);
+
+ m_actionCollection->setConfigGlobal(true);
+ m_lockAction = m_actionCollection->addAction(QStringLiteral("Lock Session"));
+ m_lockAction->setProperty("isConfigurationAction", true);
+ m_lockAction->setText(i18n("Lock Session"));
+ KGlobalAccel::self()->setShortcut(m_lockAction, defaultShortcuts());
+
+ addItem(new KPropertySkeletonItem(this, "shortcut", defaultShortcuts().first()), QStringLiteral("lockscreenShortcut"));
+}
+
+KScreenSaverSettings::~KScreenSaverSettings()
+{
+}
+
+QKeySequence KScreenSaverSettings::shortcut() const
+{
+ return KGlobalAccel::self()->shortcut(m_lockAction).first();
+}
+
+void KScreenSaverSettings::setShortcut(const QKeySequence &sequence)
+{
+ auto shortcuts = KGlobalAccel::self()->shortcut(m_lockAction);
+ if (shortcuts.isEmpty()) {
+ shortcuts << QKeySequence();
+ }
+
+ shortcuts[0] = sequence;
+ KGlobalAccel::self()->setShortcut(m_lockAction, shortcuts, KGlobalAccel::NoAutoloading);
+}
diff --git a/ksldapp.cpp b/ksldapp.cpp
--- a/ksldapp.cpp
+++ b/ksldapp.cpp
@@ -173,7 +173,7 @@
a->setObjectName(QStringLiteral("Lock Session"));
a->setProperty("componentName", QStringLiteral("ksmserver"));
a->setText(i18n("Lock Session"));
- KGlobalAccel::self()->setGlobalShortcut(a, QList() << Qt::META+Qt::Key_L << Qt::ALT+Qt::CTRL+Qt::Key_L << Qt::Key_ScreenSaver );
+ KGlobalAccel::self()->setGlobalShortcut(a, KScreenSaverSettings::defaultShortcuts());
connect(a, &QAction::triggered, this,
[this]() {
lock(EstablishLock::Immediate);