Merge branch 'mart/screenlockerConfig'

wilder-5.14
Marco Martin 12 years ago
commit 9f1271fa00
  1. 12
      ksmserver/screenlocker/kcm/CMakeLists.txt
  2. 92
      ksmserver/screenlocker/kcm/kcm.cpp
  3. 60
      ksmserver/screenlocker/kcm/kcm.h
  4. 17
      ksmserver/screenlocker/kcm/kcm.ui
  5. 145
      ksmserver/screenlocker/kcm/package/contents/ui/main.qml
  6. 19
      ksmserver/screenlocker/kcm/package/metadata.desktop
  7. BIN
      lookandfeel/contents/lockscreen/screenshot.png

@ -1,7 +1,12 @@
# KI18N Translation Domain for this library
add_definitions(-DTRANSLATION_DOMAIN=\"screenlocker_kcm\")
set(screenlocker_kcm_SRCS kcm.cpp)
set(screenlocker_kcm_SRCS
kcm.cpp
../../../lookandfeelaccess/lookandfeelaccess.cpp
)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../)
ki18n_wrap_ui(screenlocker_kcm_SRCS kcm.ui)
kconfig_add_kcfg_files(screenlocker_kcm_SRCS ../kcfg/kscreensaversettings.kcfgc)
qt5_add_dbus_interface(screenlocker_kcm_SRCS ../dbus/org.kde.screensaver.xml screenlocker_interface)
@ -13,6 +18,9 @@ target_link_libraries(screenlocker_kcm
KF5::ConfigWidgets
KF5::I18n
KF5::Service
KF5::Plasma
KF5::PlasmaQuick
Qt5::QuickWidgets
)
kservice_desktop_to_json(screenlocker_kcm screenlocker.desktop)
@ -30,3 +38,5 @@ install(
DESTINATION
${SERVICES_INSTALL_DIR}
)
plasma_install_package(package screenlocker_kcm kcms screenlocker_kcm)

@ -17,12 +17,23 @@ 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 "kcm.h"
#include "kscreensaversettings.h"
#include "ui_kcm.h"
#include "screenlocker_interface.h"
#include <config-ksmserver.h>
#include <KCModule>
#include <KPluginFactory>
#include <QVBoxLayout>
#include <QQuickWidget>
#include <QtQml>
#include <QQmlEngine>
#include <QQmlContext>
#include <QMessageBox>
#include <QStandardItemModel>
#include <Plasma/Package>
#include <Plasma/PluginLoader>
class ScreenLockerKcmForm : public QWidget, public Ui::ScreenLockerKcmForm
{
@ -38,31 +49,94 @@ ScreenLockerKcmForm::ScreenLockerKcmForm(QWidget *parent)
}
class ScreenLockerKcm : public KCModule
{
Q_OBJECT
public:
explicit ScreenLockerKcm(QWidget *parent = nullptr, const QVariantList& args = QVariantList());
public Q_SLOTS:
void save() override;
};
ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
{
qmlRegisterType<QStandardItemModel>();
ScreenLockerKcmForm *ui = new ScreenLockerKcmForm(this);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(ui);
addConfig(KScreenSaverSettings::self(), ui);
m_model = new QStandardItemModel(this);
QHash<int, QByteArray> roles = m_model->roleNames();
roles[PluginNameRole] = "pluginName";
roles[ScreenhotRole] = "screenshot";
m_model->setItemRoleNames(roles);
m_quickWidget = new QQuickWidget(this);
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
Plasma::Package package = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
package.setDefaultPackageRoot("plasma/kcms");
package.setPath("screenlocker_kcm");
m_quickWidget->rootContext()->setContextProperty("kcm", this);
m_quickWidget->setSource(QUrl::fromLocalFile(package.filePath("mainscript")));
setMinimumHeight(m_quickWidget->initialSize().height());
layout->addWidget(m_quickWidget);
}
void ScreenLockerKcm::load()
{
QString currentPlugin = KScreenSaverSettings::theme();
if (currentPlugin.isEmpty()) {
currentPlugin = m_access.metadata().pluginName();
}
setSelectedPlugin(currentPlugin);
const QList<Plasma::Package> pkgs = LookAndFeelAccess::availablePackages("lockscreenmainscript");
for (const Plasma::Package &pkg : pkgs) {
QStandardItem* row = new QStandardItem(pkg.metadata().name());
row->setData(pkg.metadata().pluginName(), PluginNameRole);
row->setData(pkg.filePath("lockscreen", "screenshot.png"), ScreenhotRole);
m_model->appendRow(row);
}
}
QStandardItemModel *ScreenLockerKcm::lockerModel()
{
return m_model;
}
QString ScreenLockerKcm::selectedPlugin() const
{
return m_selectedPlugin;
}
void ScreenLockerKcm::setSelectedPlugin(const QString &plugin)
{
if (m_selectedPlugin == plugin) {
return;
}
m_selectedPlugin = plugin;
emit selectedPluginChanged();
changed();
}
void ScreenLockerKcm::test(const QString &plugin)
{
if (plugin.isEmpty() || plugin == "none") {
return;
}
QProcess proc;
QStringList arguments;
arguments << plugin << "--testing";
if (proc.execute(KSCREENLOCKER_GREET_BIN, arguments)) {
QMessageBox::critical(this, i18n("Error"), i18n("Failed to successfully test the screen locker."));
}
}
void ScreenLockerKcm::save()
{
KCModule::save();
KScreenSaverSettings::setTheme(m_selectedPlugin);
// reconfigure through DBus
OrgKdeScreensaverInterface interface(QStringLiteral("org.kde.screensaver"),
QStringLiteral("/ScreenSaver"),

@ -0,0 +1,60 @@
/********************************************************************
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>
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 <KCModule>
#include "../../../lookandfeelaccess/lookandfeelaccess.h"
class QQuickWidget;
class QStandardItemModel;
class ScreenLockerKcm : public KCModule
{
Q_OBJECT
Q_PROPERTY(QStandardItemModel *lockerModel READ lockerModel CONSTANT)
Q_PROPERTY(QString selectedPlugin READ selectedPlugin WRITE setSelectedPlugin NOTIFY selectedPluginChanged)
public:
enum Roles {
PluginNameRole = Qt::UserRole +1,
ScreenhotRole
};
explicit ScreenLockerKcm(QWidget *parent = nullptr, const QVariantList& args = QVariantList());
QStandardItemModel *lockerModel();
QString selectedPlugin() const;
void setSelectedPlugin(const QString &plugin);
public Q_SLOTS:
void load();
void save() override;
void test(const QString &plugin);
Q_SIGNALS:
void selectedPluginChanged();
private:
QStandardItemModel *m_model;
QString m_selectedPlugin;
QQuickWidget *m_quickWidget;
LookAndFeelAccess m_access;
};

@ -6,21 +6,30 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>65</height>
<width>524</width>
<height>193</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Lock screen after:</string>
<string>&amp;Lock screen after:</string>
</property>
<property name="buddy">
<cstring>kcfg_Timeout</cstring>
@ -46,7 +55,7 @@
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Require password after locking:</string>
<string>Re&amp;quire password after locking:</string>
</property>
<property name="buddy">
<cstring>kcfg_LockGrace</cstring>

@ -0,0 +1,145 @@
/*
Copyright (c) 2014 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
import QtQuick 2.1
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.0 as QtControls
import org.kde.kquickcontrolsaddons 2.0
import QtQuick.Controls.Private 1.0
//We need units from it
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
Rectangle {
width: units.gridUnit * 20
height: units.gridUnit * 20
color: syspal.window
SystemPalette {id: syspal}
QtControls.ScrollView {
anchors.fill: parent
GridView {
id: grid
model: kcm.lockerModel
cellWidth: Math.floor(grid.width / Math.max(Math.floor(grid.width / (units.gridUnit*12)), 3))
cellHeight: cellWidth / 1.6
delegate: Rectangle {
width: grid.cellWidth
height: grid.cellHeight
Connections {
target: kcm
onSelectedPluginChanged: {
if (kcm.selectedPlugin == model.pluginName) {
makeCurrentTimer.pendingIndex = index
}
}
}
Component.onCompleted: {
if (kcm.selectedPlugin == model.pluginName) {
makeCurrentTimer.pendingIndex = index
}
}
QIconItem {
id: icon
anchors.centerIn: parent
width: units.iconSizes.large
height: width
icon: "view-preview"
}
QtControls.Label {
anchors {
horizontalCenter: parent.horizontalCenter
top: icon.bottom
topMargin: units.gridUnit
}
color: "gray"
text: model.display
}
Image {
anchors.fill: parent
source: model.screenshot
}
Rectangle {
opacity: grid.currentIndex == index ? 1.0 : 0
anchors.fill: parent
border.width: units.smallSpacing * 2
border.color: syspal.highlight
color: "transparent"
Behavior on opacity {
PropertyAnimation {
duration: units.longDuration
easing.type: Easing.OutQuad
}
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onClicked: {
grid.currentIndex = index
kcm.selectedPlugin = model.pluginName
}
Timer {
interval: 1000 // FIXME TODO: Use platform value for tooltip activation delay.
running: parent.containsMouse && !parent.pressedButtons
onTriggered: {
Tooltip.showText(parent, Qt.point(parent.mouseX, parent.mouseY), model.display);
}
}
PlasmaComponents.ToolButton {
anchors {
top: parent.top
right: parent.right
margins: units.smallSpacing
}
visible: model.pluginName != "none"
iconSource: "media-playback-start"
tooltip: i18n("Test Screen Locker")
flat: false
onClicked: kcm.test(model.pluginName)
opacity: parent.containsMouse ? 1 : 0
Behavior on opacity {
PropertyAnimation {
duration: units.longDuration
easing.type: Easing.OutQuad
}
}
}
}
}
/*list.setCurrentIndex doesn't work while the model is getting loaded,
* so list.currentIndex = index in a component.onCompleted of the delegate,
* doesn't work, restarting a timer when a delegate gets created,
* seems the only place where we can approximate "set the property when
* the view really is done loading"*/
Timer {
id: makeCurrentTimer
interval: 0
repeat: false
property int pendingIndex
onPendingIndexChanged: makeCurrentTimer.restart()
onTriggered: {
grid.currentIndex = pendingIndex
}
}
}
}
}

@ -0,0 +1,19 @@
[Desktop Entry]
Name=Screen Locking
Comment=Screen Locking Themes
Icon=preferences-system
Encoding=UTF-8
Keywords=
Type=Service
X-KDE-ParentApp=
X-KDE-PluginInfo-Author=Marco Martin
X-KDE-PluginInfo-Email=mart@kde.org
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-Name=screenlocker_kcm
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-KDE-ServiceTypes=Plasma/Generic
X-Plasma-API=declarativeappletscript
X-Plasma-MainScript=ui/main.qml
X-Plasma-RemoteLocation=

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Loading…
Cancel
Save