Commit 65f1447b authored by David Redondo's avatar David Redondo 🏎
Browse files

This is a straightforward port of the kcm to qml. Additonally the appearance...

This is a straightforward port of the kcm to qml. Additonally the appearance tabs is now a page instead.
parent 09d8a423
......@@ -55,10 +55,8 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
GlobalAccel
I18n
IdleTime
KCMUtils
Notifications
Solid
TextWidgets
WindowSystem
XmlGui
)
......@@ -185,7 +183,7 @@ ecm_qt_declare_logging_category(ksld_SRCS
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/kscreensaversettingsbase.kcfgc)
kconfig_add_kcfg_files(ksld_SRCS GENERATE_MOC kcfg/kscreensaversettingsbase.kcfgc)
qt5_add_dbus_interface(ksld_SRCS ${powerdevilpolicyagent_xml} powerdevilpolicyagent)
ecm_add_wayland_server_protocol(ksld_SRCS
......
......@@ -2,3 +2,5 @@ File=kscreenlockersettings.kcfg
ClassName=KScreenSaverSettingsBase
Singleton=true
Mutators=true
GenerateProperties=true
ParentInConstructor=true
......@@ -10,34 +10,32 @@ set(screenlocker_kcm_SRCS
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/kscreensaversettingsbase.kcfgc)
qt5_add_dbus_interface(screenlocker_kcm_SRCS ../dbus/org.kde.screensaver.xml screenlocker_interface)
qt5_add_resources( screenlocker_kcm_SRCS resources.qrc )
add_library(screenlocker_kcm MODULE ${screenlocker_kcm_SRCS})
add_library(kcm_screenlocker MODULE ${screenlocker_kcm_SRCS})
target_link_libraries(screenlocker_kcm
target_link_libraries(kcm_screenlocker
Qt5::DBus
Qt5::QuickWidgets
KF5::ConfigWidgets
KF5::Declarative
KF5::I18n
KF5::TextWidgets
KF5::GlobalAccel
KF5::Package
KF5::QuickAddons
KF5::XmlGui
KF5::Declarative
)
kcoreaddons_desktop_to_json(screenlocker_kcm screenlocker.desktop SERVICE_TYPES kcmodule.desktop)
kcoreaddons_desktop_to_json(kcm_screenlocker screenlocker.desktop SERVICE_TYPES kcmodule.desktop)
install(
TARGETS
screenlocker_kcm
kcm_screenlocker
DESTINATION
${KDE_INSTALL_PLUGINDIR}
${KDE_INSTALL_PLUGINDIR}/kcms
)
kpackage_install_package(package kcm_screenlocker kcms)
install(
FILES
screenlocker.desktop
......
#!bin/sh
$EXTRACTRC *.ui >> rc.cpp
$XGETTEXT `find . -name "*.cpp" -o -name "*.qml"` -o $podir/screenlocker_kcm.pot
rm -f rc.cpp
......@@ -4,6 +4,7 @@
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2019 Kevin Ottens <kevin.ottens@enioka.com>
Copyright (C) 2020 David Redondo <kde@david-redondo.de>
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
......@@ -20,79 +21,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#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 <config-kscreenlocker.h>
#include <KAboutData>
#include <KConfigLoader>
#include <KConfigDialogManager>
#include <KDeclarative/ConfigPropertyMap>
#include <KGlobalAccel>
#include <KCModule>
#include <KLocalizedString>
#include <KPluginFactory>
#include <QVBoxLayout>
#include <QMessageBox>
#include <KPackage/Package>
#include <KPackage/PackageLoader>
#include <QQmlContext>
#include <QQuickItem>
#include <QVector>
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)
ScreenLockerKcm::ScreenLockerKcm(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_settings(new KScreenSaverSettings(this))
, m_ui(new ScreenLockerKcmForm(this))
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_ui);
for (const auto &pluginInfo : m_settings->availableWallpaperPlugins()) {
m_ui->kcfg_wallpaperPluginIndex->addItem(pluginInfo.name, pluginInfo.id);
}
connect(m_ui->kcfg_wallpaperPluginIndex, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &ScreenLockerKcm::loadWallpaperConfig);
m_ui->kcfg_wallpaperPluginIndex->installEventFilter(this);
m_ui->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->wallpaperConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/wallpaperconfig.qml")));
connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState()));
m_ui->lnfConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window));
m_ui->lnfConfigWidget->rootContext()->setContextProperty(QStringLiteral("configDialog"), proxy);
m_ui->lnfConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/lnfconfig.qml")));
connect(m_ui->lnfConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState()));
addConfig(m_settings, m_ui);
constexpr const char* url = "org.kde.private.kcms.screenlocker";
qRegisterMetaType<QVector<WallpaperInfo>>("QVector<WallpaperInfo>");
qmlRegisterAnonymousType<KScreenSaverSettings>(url, 1);
qmlRegisterAnonymousType<WallpaperInfo>(url, 1);
qmlRegisterAnonymousType<ScreenLocker::WallpaperIntegration>(url, 1);
qmlRegisterAnonymousType<KDeclarative::ConfigPropertyMap>(url, 1);
qmlProtectModule(url, 1);
KAboutData *about = new KAboutData(QStringLiteral("kcm_screenlocker"), i18n("Screen Locking"),
QStringLiteral("1.0"), QString(), KAboutLicense::GPL);
about->addAuthor(i18n("Martin Gräßlin"), QString(), QStringLiteral("mgraesslin@kde.org"));
about->addAuthor(i18n("Kevin Ottens"), QString(), QStringLiteral("kevin.ottens@enioka.com"));
setAboutData(about);
connect(m_settings, &KScreenSaverSettings::wallpaperPluginIdChanged, this, &ScreenLockerKcm::loadWallpaperConfig);
}
void ScreenLockerKcm::load()
{
KCModule::load();
ManagedConfigModule::load();
loadWallpaperConfig();
loadLnfConfig();
......@@ -111,7 +78,7 @@ void ScreenLockerKcm::load()
void ScreenLockerKcm::save()
{
KCModule::save();
ManagedConfigModule::save();
if (m_lnfSettings) {
m_lnfSettings->save();
}
......@@ -133,7 +100,7 @@ void ScreenLockerKcm::save()
void ScreenLockerKcm::defaults()
{
KCModule::defaults();
ManagedConfigModule::defaults();
if (m_lnfSettings) {
m_lnfSettings->setDefaults();
......@@ -162,30 +129,27 @@ void ScreenLockerKcm::updateState()
isDefaults &= m_wallpaperSettings->isDefaults();
isSaveNeeded |= m_wallpaperSettings->isSaveNeeded();
}
emit changed(isSaveNeeded);
emit defaulted(isDefaults);
setNeedsSave(isSaveNeeded);
setRepresentsDefaults(isDefaults);
}
void ScreenLockerKcm::loadWallpaperConfig()
{
if (m_wallpaperIntegration) {
if (m_wallpaperIntegration->pluginName() == m_ui->kcfg_wallpaperPluginIndex->currentData().toString()) {
// nothing changed
if (m_wallpaperIntegration->pluginName() == m_settings->wallpaperPluginId()) {
//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->kcfg_wallpaperPluginIndex->currentData().toString());
m_wallpaperIntegration->setPluginName(m_settings->wallpaperPluginId());
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")));
m_wallpaperConfigFile = m_wallpaperIntegration->package().fileUrl(QByteArrayLiteral("ui"), QStringLiteral("config.qml"));
emit currentWallpaperChanged();
}
void ScreenLockerKcm::loadLnfConfig()
......@@ -210,11 +174,7 @@ void ScreenLockerKcm::loadLnfConfig()
m_lnfSettings = m_lnfIntegration->configScheme();
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);
m_lnfConfigFile = sourceFile;
}
KDeclarative::ConfigPropertyMap * ScreenLockerKcm::wallpaperConfiguration() const
......@@ -236,33 +196,10 @@ KDeclarative::ConfigPropertyMap * ScreenLockerKcm::lnfConfiguration() const
QString ScreenLockerKcm::currentWallpaper() const
{
return m_ui->kcfg_wallpaperPluginIndex->currentData().toString();
return m_settings->wallpaperPluginId();
}
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->kcfg_wallpaperPluginIndex) {
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->kcfg_wallpaperPluginIndex->x() + 5);
}
if (auto object = m_ui->lnfConfigWidget->rootObject()) {
// QtQuick Layouts have a hardcoded 5 px spacing by default
object->setProperty("formAlignment", m_ui->kcfg_wallpaperPluginIndex->x() + 5);
}
}
return false;
}
K_PLUGIN_CLASS_WITH_JSON(ScreenLockerKcm, "screenlocker.json")
......
/********************************************************************
KSld - the KDE Screenlocker Daemon
This file is part of the KDE project.
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2014 Marco Martin <mart@kde.org>
Copyright (C) 2019 Kevin Ottens <kevin.ottens@enioka.com>
Copyright (C) 2020 David Redondo <kde@david-redondo.de>
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
......@@ -19,11 +19,13 @@ 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 KCM_H
#define KCM_H
#include <KCModule>
#include <KPackage/Package>
#include <KQuickAddons/ManagedConfigModule>
class KScreenSaverSettings;
#include "kscreensaversettings.h"
class ScreenLockerKcmForm;
namespace ScreenLocker
......@@ -38,80 +40,50 @@ class ConfigPropertyMap;
}
class ScreenLockerKcm : public KCModule
class ScreenLockerKcm : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
public:
enum Roles {
PluginNameRole = Qt::UserRole +1,
ScreenhotRole
};
explicit ScreenLockerKcm(QWidget *parent = nullptr, const QVariantList& args = QVariantList());
explicit ScreenLockerKcm(QObject *parent = nullptr, const QVariantList& args = QVariantList());
KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const;
KDeclarative::ConfigPropertyMap *lnfConfiguration() const;
Q_PROPERTY(KScreenSaverSettings *settings MEMBER m_settings CONSTANT)
Q_PROPERTY(KDeclarative::ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration NOTIFY currentWallpaperChanged)
Q_PROPERTY(KDeclarative::ConfigPropertyMap *lnfConfiguration READ lnfConfiguration CONSTANT)
Q_PROPERTY(QUrl lnfConfigFile MEMBER m_lnfConfigFile CONSTANT)
Q_PROPERTY(QUrl wallpaperConfigFile MEMBER m_wallpaperConfigFile NOTIFY currentWallpaperChanged)
Q_PROPERTY(ScreenLocker::WallpaperIntegration *wallpaperIntegration MEMBER m_wallpaperIntegration NOTIFY currentWallpaperChanged)
Q_PROPERTY(QString currentWallpaper READ currentWallpaper NOTIFY currentWallpaperChanged)
QString currentWallpaper() const;
Q_INVOKABLE QVector<WallpaperInfo> availableWallpaperPlugins() {
return m_settings->availableWallpaperPlugins();
}
bool eventFilter(QObject *watched, QEvent *event) override;
QString currentWallpaper() const;
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
void updateState();
Q_SIGNALS:
void wallpaperConfigurationChanged();
void currentWallpaperChanged();
private Q_SLOTS:
void updateState();
private:
void selectWallpaper(const QString &pluginId);
void loadWallpaperConfig();
void loadLnfConfig();
KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const;
KDeclarative::ConfigPropertyMap *lnfConfiguration() const;
KPackage::Package m_package;
KScreenSaverSettings *m_settings;
ScreenLockerKcmForm *m_ui;
ScreenLocker::WallpaperIntegration *m_wallpaperIntegration = nullptr;
KCoreConfigSkeleton *m_wallpaperSettings = nullptr;
QUrl m_wallpaperConfigFile;
ScreenLocker::LnFIntegration* m_lnfIntegration = nullptr;
KCoreConfigSkeleton *m_lnfSettings = nullptr;
QUrl m_lnfConfigFile;
};
//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)
{
connect(q, &ScreenLockerKcm::wallpaperConfigurationChanged, this, &ScreenLockerProxy::wallpaperConfigurationChanged);
connect(q, &ScreenLockerKcm::currentWallpaperChanged, this, &ScreenLockerProxy::currentWallpaperChanged);
}
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;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScreenLockerKcmForm</class>
<widget class="QWidget" name="ScreenLockerKcmForm">
<property name="geometry">
<rect>
<width>500</width>
<height>525</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_1">
<attribute name="title">
<string>Activation</string>
</attribute>
<layout class="QFormLayout" name="formLayout_1">
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_1">
<property name="text">
<string>Lock screen:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_1">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="kcfg_Autolock">
<property name="text">
<string>Automatically after:</string>
</property>
</widget>
</item>
<item>
<widget class="KPluralHandlingSpinBox" name="kcfg_Timeout">
<property name="enabled">
<bool>false</bool>
</property>
<property name="specialValueText">
<string notr="true"/>
</property>
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="kcfg_LockOnResume">
<property name="toolTip">
<string>Lock screen when waking up from suspension</string>
</property>
<property name="text">
<string>After waking from sleep</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Allow unlocking without password for:</string>
</property>
<property name="buddy">
<cstring>kcfg_LockGrace</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KPluralHandlingSpinBox" name="kcfg_LockGrace">
<property name="specialValueText">
<string>Immediately</string>
</property>
<property name="maximum">
<number>300</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string>The global keyboard shortcut to lock the screen.</string>
</property>
<property name="text">
<string>Keyboard shortcut:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KKeySequenceWidget" name="kcfg_lockscreenShortcut"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Appearance</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QQuickWidget" name="lnfConfigWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="resizeMode">
<enum>QQuickWidget::SizeViewToRootObject</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property>
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Wallpaper &amp;type:</string>
</property>
<property name="buddy">
<cstring>kcfg_wallpaperPluginIndex</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="kcfg_wallpaperPluginIndex"/>
</item>
</layout>
</item>
<item>
<widget class="QQuickWidget" name="wallpaperConfigWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="resizeMode">
<enum>QQuickWidget::SizeRootObjectToView</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QQuickWidget</class>
<extends>QWidget</extends>
<header location="global">QtQuickWidgets/QQuickWidget</header>
</customwidget>
<customwidget>
<class>KKeySequenceWidget</class>
<extends>QWidget</extends>
<header>kkeysequencewidget.h</header>
</customwidget>
<customwidget>
<class>KPluralHandlingSpinBox</class>
<extends>QSpinBox</extends>
<header>kpluralhandlingspinbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>kcfg_Autolock</sender>
<signal>toggled(bool)</signal>
<receiver>kcfg_Timeout</receiver>
<slot>setEnabled(bool)</slot>
</connection>
</connections>
</ui>
/********************************************************************
KSld - the KDE Screenlocker Daemon
This file is part of the KDE project.
Copyright (C) 2020 David Redondo <kde@david-redondo.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as