Commit 5df37be9 authored by David Edmundson's avatar David Edmundson

[applets/lock_logout] Port away from DataEngine

DataEngines are set to be deprecated in Plasma 6 and SessionManagement
has all the same ready.
parent c02b4329
......@@ -21,6 +21,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.5 as QtControls
import org.kde.kirigami 2.5 as Kirigami
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.private.sessions 2.0
Kirigami.FormLayout {
id: iconsPage
......@@ -35,14 +36,8 @@ Kirigami.FormLayout {
property alias cfg_show_suspendToDisk: hibernate.checked
property alias cfg_show_suspendToRam: sleep.checked
readonly property bool canLockScreen: dataEngine.data["Sleep States"].LockScreen
readonly property bool canSuspend: dataEngine.data["Sleep States"].Suspend
readonly property bool canHibernate: dataEngine.data["Sleep States"].Hibernate
PlasmaCore.DataSource {
id: dataEngine
engine: "powermanagement"
connectedSources: ["Sleep States"]
SessionManagement {
id: session
}
QtControls.CheckBox {
......@@ -55,7 +50,7 @@ Kirigami.FormLayout {
QtControls.CheckBox {
id: lock
text: i18n("Lock")
enabled: iconsPage.canLockScreen && (checkedOptions > 1 || !checked)
enabled: session.canLock && (checkedOptions > 1 || !checked)
}
QtControls.CheckBox {
id: switchUser
......@@ -65,11 +60,11 @@ Kirigami.FormLayout {
QtControls.CheckBox {
id: hibernate
text: i18n("Hibernate")
enabled: iconsPage.canHibernate && (checkedOptions > 1 || !checked)
enabled: session.canHibernate && (checkedOptions > 1 || !checked)
}
QtControls.CheckBox {
id: sleep
text: i18nc("Suspend to RAM", "Sleep")
enabled: iconsPage.canSuspend && (checkedOptions > 1 || !checked)
enabled: session.canSuspend && (checkedOptions > 1 || !checked)
}
}
var data = [{
icon: "system-lock-screen",
operation: "lockScreen",
operation: "lock",
tooltip_mainText: i18n("Lock"),
tooltip_subText: i18n("Lock the screen"),
requires: "LockScreen"
requires: "Lock"
}, {
icon: "system-switch-user",
operation: "switchUser",
......@@ -11,18 +11,19 @@ var data = [{
tooltip_subText: i18n("Start a parallel session as a different user")
}, {
icon: "system-shutdown",
operation: "requestShutDown",
operation: "requestShutdown",
tooltip_mainText: i18n("Leave..."),
tooltip_subText: i18n("Log out, turn off or restart the computer")
tooltip_subText: i18n("Log out, turn off or restart the computer"),
requires: "Shutdown"
}, {
icon: "system-suspend",
operation: "suspendToRam",
operation: "suspend",
tooltip_mainText: i18nc("Suspend to RAM", "Sleep"),
tooltip_subText: i18n("Sleep (suspend to RAM)"),
requires: "Suspend"
}, {
icon: "system-suspend-hibernate",
operation: "suspendToDisk",
operation: "hibernate",
tooltip_mainText: i18n("Hibernate"),
tooltip_subText: i18n("Hibernate (suspend to disk)"),
requires: "Hibernate"
......
......@@ -24,6 +24,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents // For QueryDialog
import org.kde.kquickcontrolsaddons 2.0
import "data.js" as Data
import org.kde.plasma.private.sessions 2.0
Flow {
id: lockout
......@@ -72,10 +73,8 @@ Flow {
}
}
PlasmaCore.DataSource {
id: dataEngine
engine: "powermanagement"
connectedSources: ["PowerDevil", "Sleep States"]
SessionManagement {
id: session
}
Repeater {
......@@ -88,7 +87,7 @@ Flow {
delegate: Item {
id: iconDelegate
visible: plasmoid.configuration["show_" + modelData.operation] && (!modelData.hasOwnProperty("requires") || dataEngine.data["Sleep States"][modelData.requires])
visible: plasmoid.configuration["show_" + modelData.operation] && (!modelData.hasOwnProperty("requires") || session["can" + modelData.requires])
width: items.itemWidth
height: items.itemHeight
......@@ -128,7 +127,7 @@ Flow {
acceptButtonText: i18n("Yes")
rejectButtonText: i18n("No")
onAccepted: performOperation("suspendToDisk")
onAccepted: performOperation("hibernate")
}
}
property PlasmaComponents.QueryDialog hibernateDialog
......@@ -144,20 +143,20 @@ Flow {
acceptButtonText: i18n("Yes")
rejectButtonText: i18n("No")
onAccepted: performOperation("suspendToRam")
onAccepted: performOperation("suspend")
}
}
property PlasmaComponents.QueryDialog sleepDialog
function clickHandler(what, button) {
if (what === "suspendToDisk") {
if (what === "suspend") {
if (!hibernateDialog) {
hibernateDialog = hibernateDialogComponent.createObject(lockout);
}
hibernateDialog.visualParent = button
hibernateDialog.open();
} else if (what === "suspendToRam") {
} else if (what === "hibernate") {
if (!sleepDialog) {
sleepDialog = sleepDialogComponent.createObject(lockout);
}
......@@ -169,10 +168,8 @@ Flow {
}
}
function performOperation(what) {
var service = dataEngine.serviceForSource("PowerDevil");
var operation = service.operationDescription(what);
service.startOperationCall(operation);
function performOperation(operation) {
session[operation]()
}
}
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