Commit 68bdeb8c authored by Kevin Ottens's avatar Kevin Ottens
Browse files

Move the shortcut management in the settings object

Summary:
This uses the new KPropertySkeletonItem facility to allow proper
integration with KGlobalAccel while keeping all the nice semantic coming
from KConfigXT.

This required turning the kconfig_compiler code into a base class and
inheriting from it to introduce the property managed via
KPropertySkeletonItem.

Reviewers: #plasma, davidedmundson, bport, crossi

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25212
parent e9981695
......@@ -167,10 +167,11 @@ set(ksld_SRCS
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 @@ PRIVATE
KF5::CoreAddons
KF5::ConfigGui
KF5::WindowSystem
KF5::XmlGui
${X11_LIBRARIES}
XCB::XCB
XCB::KEYSYMS
......
......@@ -22,7 +22,7 @@ if(HAVE_SECCOMP)
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
......
......@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "greeterapp.h"
#include "kscreensaversettings.h"
#include "kscreensaversettingsbase.h"
#include "authenticator.h"
#include "noaccessnetworkaccessmanagerfactory.h"
#include "wallpaper_integration.h"
......@@ -181,25 +181,25 @@ void UnlockApp::initialize()
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();
......
File=kscreenlockersettings.kcfg
ClassName=KScreenSaverSettings
ClassName=KScreenSaverSettingsBase
Singleton=true
Mutators=true
......@@ -3,13 +3,15 @@ add_definitions(-DTRANSLATION_DOMAIN=\"screenlocker_kcm\")
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 )
......
......@@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../greeter/lnf_integration.h"
#include <config-kscreenlocker.h>
#include <KActionCollection>
#include <KConfigDialogManager>
#include <KGlobalAccel>
#include <KCModule>
#include <KPluginFactory>
......@@ -38,7 +38,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QQmlContext>
#include <QQuickItem>
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 @@ ScreenLockerKcmForm::ScreenLockerKcmForm(QWidget *parent)
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<QKeySequence>{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<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
......@@ -106,15 +97,6 @@ ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args)
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 @@ void ScreenLockerKcm::load()
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::test(const QString &plugin)
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<QKeySequence>{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 @@ void ScreenLockerKcm::save()
}
}
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 @@ void ScreenLockerKcm::loadWallpaperConfig()
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);
......
......@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KCModule>
#include <KPackage/Package>
class KActionCollection;
class KScreenSaverSettings;
class ScreenLockerKcmForm;
namespace ScreenLocker
......@@ -65,14 +65,12 @@ Q_SIGNALS:
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;
......
......@@ -97,7 +97,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="KKeySequenceWidget" name="lockscreenShortcut" native="true"/>
<widget class="KKeySequenceWidget" name="kcfg_lockscreenShortcut"/>
</item>
</layout>
</widget>
......
/********************************************************************
This file is part of the KDE project.
Copyright 2019 Kevin Ottens <kevin.ottens@enioka.com>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kscreensaversettings.h"
#include <KActionCollection>
#include <KGlobalAccel>
#include <KLocalizedString>
QList<QKeySequence> 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);
}
/********************************************************************
This file is part of the KDE project.
Copyright 2019 Kevin Ottens <kevin.ottens@enioka.com>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#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<QKeySequence> 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
......@@ -173,7 +173,7 @@ void KSldApp::initialize()
a->setObjectName(QStringLiteral("Lock Session"));
a->setProperty("componentName", QStringLiteral("ksmserver"));
a->setText(i18n("Lock Session"));
KGlobalAccel::self()->setGlobalShortcut(a, QList<QKeySequence>() << 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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment