Commit e36101cd authored by David Edmundson's avatar David Edmundson

Load config specified by the LnF theme

Summary:
This is loaded in a QQuickView like the wallpaper, rest of the code is
mostly based on something quite similar.

Only differences is that wallpapers packages can change during the
config, whereas the base package cannot; which simplifies some code.

BUG: 384264

Test Plan:
Started playing some tunes
Locked screen, still had my controls
Changed setting
Locked screen, didn't have my controls
Changed wallpaper to confirm I hadn't broken anything

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9684
parent d0db1577
......@@ -12,6 +12,7 @@ set(kscreenlocker_greet_SRCS
greeterapp.cpp
main.cpp
noaccessnetworkaccessmanagerfactory.cpp
lnf_integration.cpp
wallpaper_integration.cpp
kwinglplatform.cpp
)
......
......@@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "authenticator.h"
#include "noaccessnetworkaccessmanagerfactory.h"
#include "wallpaper_integration.h"
#include "lnf_integration.h"
#include <config-kscreenlocker.h>
// KDE
......@@ -31,6 +33,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kdeclarative/kdeclarative.h>
#include <KDeclarative/KQuickAddons/QuickViewSharedEngine>
#include <KDeclarative/QmlObjectSharedEngine>
#include <KDeclarative/ConfigPropertyMap>
#include <KUser>
//Plasma
#include <KPackage/Package>
......@@ -108,6 +112,7 @@ UnlockApp::UnlockApp(int &argc, char **argv)
, m_noLock(false)
, m_defaultToSwitchUser(false)
, m_wallpaperIntegration(new WallpaperIntegration(this))
, m_lnfIntegration(new LnFIntegration(this))
{
m_authenticator = createAuthenticator();
connect(m_authenticator, &Authenticator::succeeded, this, &QCoreApplication::quit);
......@@ -186,6 +191,11 @@ void UnlockApp::initialize()
m_wallpaperIntegration->setPluginName(KScreenSaverSettings::self()->wallpaperPlugin());
m_wallpaperIntegration->init();
m_lnfIntegration->setPackage(package);
m_lnfIntegration->setConfig(KScreenSaverSettings::self()->sharedConfig());
m_lnfIntegration->init();
installEventFilter(this);
}
......@@ -295,7 +305,7 @@ void UnlockApp::desktopResized()
context->setContextProperty(QStringLiteral("org_kde_plasma_screenlocker_greeter_interfaceVersion"), 2);
context->setContextProperty(QStringLiteral("org_kde_plasma_screenlocker_greeter_view"), view);
context->setContextProperty(QStringLiteral("defaultToSwitchUser"), m_defaultToSwitchUser);
context->setContextProperty(QStringLiteral("config"), m_lnfIntegration->configuration());
view->setSource(m_mainQmlPath);
// on error, load the fallback lockscreen to not lock the user out of the system
......
......@@ -45,6 +45,7 @@ namespace ScreenLocker
{
class Unlocker;
class WallpaperIntegration;
class LnFIntegration;
class UnlockApp : public QGuiApplication
{
......@@ -117,6 +118,8 @@ private:
KWayland::Client::PlasmaShell *m_plasmaShell = nullptr;
WallpaperIntegration *m_wallpaperIntegration;
LnFIntegration *m_lnfIntegration;
bool m_supportsSeccomp = false;
};
} // namespace
......
/********************************************************************
KSld - the KDE Screenlocker Daemon
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2017 David Edmundson <davidedmundson@kde.org>
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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
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 "lnf_integration.h"
#include <KConfig>
#include <KConfigGroup>
#include <KConfigLoader>
#include <KPackage/PackageLoader>
#include <KDeclarative/ConfigPropertyMap>
#include <QFile>
#include <QDebug>
namespace ScreenLocker
{
LnFIntegration::LnFIntegration(QObject *parent)
: QObject(parent)
{
qRegisterMetaType<KDeclarative::ConfigPropertyMap*>();
}
LnFIntegration::~LnFIntegration() = default;
void LnFIntegration::init()
{
if (!m_package.isValid()) {
return;
}
if (auto config = configScheme()) {
m_configuration = new KDeclarative::ConfigPropertyMap(config, this);
}
}
KConfigLoader *LnFIntegration::configScheme()
{
if (!m_configLoader) {
const QString xmlPath = m_package.filePath(QByteArrayLiteral("lockscreen"), QStringLiteral("config.xml"));
const KConfigGroup cfg = m_config->group("Greeter").group("LnF");
if (xmlPath.isEmpty()) {
m_configLoader = new KConfigLoader(cfg, 0, this);
} else {
QFile file(xmlPath);
m_configLoader = new KConfigLoader(cfg, &file, this);
}
}
return m_configLoader;
}
}
/********************************************************************
KSld - the KDE Screenlocker Daemon
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2017 David Edmundson <davidedmundson@kde.org>
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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
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 KSCREENLOCKER_LNF_INTEGRATION_H
#define KSCREENLOCKER_LNF_INTEGRATION_H
#include <KPackage/Package>
#include <KSharedConfig>
class KConfigLoader;
namespace KDeclarative
{
class ConfigPropertyMap;
class QmlObject;
}
namespace ScreenLocker
{
class LnFIntegration : public QObject
{
Q_OBJECT
Q_PROPERTY(KDeclarative::ConfigPropertyMap *configuration READ configuration NOTIFY configurationChanged)
public:
LnFIntegration(QObject *parent);
virtual ~LnFIntegration();
void init();
void setConfig(const KSharedConfig::Ptr &config) {
m_config = config;
}
void setPackage(const KPackage::Package &package) {
m_package = package;
}
KPackage::Package package() const {
return m_package;
}
KDeclarative::ConfigPropertyMap *configuration() const {
return m_configuration;
}
Q_SIGNALS:
void packageChanged();
void configurationChanged();
private:
KConfigLoader *configScheme();
KPackage::Package m_package;
KSharedConfig::Ptr m_config;
KConfigLoader *m_configLoader = nullptr;
KDeclarative::ConfigPropertyMap *m_configuration = nullptr;
};
}
#endif
......@@ -4,6 +4,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"screenlocker_kcm\")
set(screenlocker_kcm_SRCS
kcm.cpp
../greeter/wallpaper_integration.cpp
../greeter/lnf_integration.cpp
)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../)
......
......@@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ui_kcm.h"
#include "screenlocker_interface.h"
#include "../greeter/wallpaper_integration.h"
#include "../greeter/lnf_integration.h"
#include <config-kscreenlocker.h>
#include <KActionCollection>
#include <KGlobalAccel>
......@@ -84,16 +86,24 @@ ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args)
m_ui->wallpaperCombo->installEventFilter(this);
m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window));
auto proxy = new ScreenLockerProxy(this);
m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window));
m_ui->wallpaperConfigWidget->rootContext()->setContextProperty("configDialog", proxy);
m_ui->lnfConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window));
m_ui->lnfConfigWidget->rootContext()->setContextProperty("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/config.qml")));
m_ui->wallpaperConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/wallpaperconfig.qml")));
connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(changed()));
m_ui->lnfConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/lnfconfig.qml")));
connect(m_ui->lnfConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(changed()));
m_ui->installEventFilter(this);
}
......@@ -123,9 +133,15 @@ void ScreenLockerKcm::load()
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->init();
selectWallpaper(KScreenSaverSettings::self()->wallpaperPlugin());
loadWallpaperConfig();
loadLnfConfig();
}
void ScreenLockerKcm::test(const QString &plugin)
......@@ -150,6 +166,7 @@ void ScreenLockerKcm::save()
}
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());
......@@ -235,6 +252,16 @@ void ScreenLockerKcm::loadWallpaperConfig()
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) {
......@@ -243,6 +270,15 @@ KDeclarative::ConfigPropertyMap * ScreenLockerKcm::wallpaperConfiguration() cons
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();
......@@ -264,6 +300,11 @@ bool ScreenLockerKcm::eventFilter(QObject *watched, QEvent *event)
// 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;
}
......
......@@ -30,6 +30,7 @@ class ScreenLockerKcmForm;
namespace ScreenLocker
{
class WallpaperIntegration;
class LnFIntegration;
}
namespace KDeclarative
......@@ -49,6 +50,8 @@ public:
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;
......@@ -69,10 +72,12 @@ private:
void loadWallpapers();
void selectWallpaper(const QString &pluginId);
void loadWallpaperConfig();
void loadLnfConfig();
KPackage::Package m_package;
KActionCollection *m_actionCollection;
ScreenLockerKcmForm *m_ui;
ScreenLocker::WallpaperIntegration *m_wallpaperIntegration = nullptr;
ScreenLocker::LnFIntegration* m_lnfIntegration = nullptr;
};
//see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property
......@@ -80,6 +85,8 @@ 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) :
......@@ -91,6 +98,9 @@ public:
KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const {
return q->wallpaperConfiguration();
}
KDeclarative::ConfigPropertyMap *lnfConfiguration() const {
return q->lnfConfiguration();
}
QString currentWallpaper() const {
return q->currentWallpaper();
......
......@@ -120,7 +120,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="KKeySequenceWidget" name="lockscreenShortcut" native="true"/>
<widget class="KKeySequenceWidget" name="lockscreenShortcut"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
......@@ -138,9 +138,28 @@
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Wallpaper</string>
<string>Appearance</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QQuickWidget" name="lnfConfigWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<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::SizeRootObjectToView</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
......@@ -151,7 +170,7 @@
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Wallpaper &amp;Type:</string>
......@@ -161,7 +180,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QComboBox" name="wallpaperCombo"/>
</item>
</layout>
......@@ -188,11 +207,6 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QQuickWidget</class>
<extends>QWidget</extends>
<header>QtQuickWidgets/QQuickWidget</header>
</customwidget>
<customwidget>
<class>KKeySequenceWidget</class>
<extends>QWidget</extends>
......@@ -203,6 +217,11 @@
<extends>QSpinBox</extends>
<header>kpluralhandlingspinbox.h</header>
</customwidget>
<customwidget>
<class>QQuickWidget</class>
<extends>QWidget</extends>
<header>QtQuickWidgets/QQuickWidget</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
/********************************************************************
KSld - the KDE Screenlocker Daemon
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
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/>.
*********************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.0 as QtControls
import QtQuick.Layouts 1.1
ColumnLayout {
id: root
property int formAlignment: 0
property alias sourceFile: main.sourceFile
signal configurationChanged
//BEGIN functions
function saveConfig() {
if (main.currentItem.saveConfig) {
main.currentItem.saveConfig()
}
for (var key in configDialog.lnfConfiguration) {
if (main.currentItem["cfg_"+key] !== undefined) {
configDialog.lnfConfiguration[key] = main.currentItem["cfg_"+key]
}
}
}
//END functions
Item {
id: emptyConfig
}
QtControls.StackView {
id: main
Layout.fillHeight: true
anchors {
left: parent.left;
right: parent.right;
}
property string sourceFile
onSourceFileChanged: {
if (sourceFile) {
var props = {}
var lnfConfiguration = configDialog.lnfConfiguration
for (var key in lnfConfiguration) {
props["cfg_" + key] = lnfConfiguration[key]
}
var newItem = push({
item: sourceFile,
replace: true,
properties: props
})
for (var key in lnfConfiguration) {
var changedSignal = newItem["cfg_" + key + "Changed"]
if (changedSignal) {
changedSignal.connect(root.configurationChanged)
}
}
} else {
replace(emptyConfig)
}
}
}
}
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/kscreenlocker-kcm-resources">
<file>config.qml</file>
<file>wallpaperconfig.qml</file>
<file>lnfconfig.qml</file>
</qresource>
</RCC>
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