Add a shutdown button in the top drawer

it uses the PowerDevil data engine to request a
shutdown from ksmserver. Since ksmserver is not yet
running on the images this also prints a debug message.
Tested to work on desktop neon.
This commit is contained in:
Simon Schmeisser 2019-02-06 18:01:12 +01:00
parent 7310f8282a
commit 3194b36952
2 changed files with 24 additions and 0 deletions

View file

@ -9,6 +9,10 @@
<entry name="AppletOrder" type="String">
<label>encoded order of items</label>
</entry>
<entry name="ShowPowerButton" type="Bool">
<default>true</default>
<label>optional power button</label>
</entry>
</group>
</kcfg>

View file

@ -33,6 +33,14 @@ Item {
plasmoid.nativeInterface.toggleTorch()
}
function requestShutdown() {
print("Shutdown requested, depends on ksmserver running");
var service = pmSource.serviceForSource("PowerDevil");
//note the strange camelCasing is intentional
var operation = service.operationDescription("requestShutDown");
return service.startOperationCall(operation);
}
function addPlasmoid(applet) {
settingsModel.append({"icon": applet.icon,
"text": applet.title,
@ -107,6 +115,18 @@ Item {
"settingsCommand": "",
"applet": null
});
if (plasmoid.configuration.ShowPowerButton) {
settingsModel.append({
"text": i18n("Shutdown"),
"icon": "system-shutdown-symbolic",
"enabled": false,
"settingsCommand": "",
"toggleFunction": "requestShutdown",
"plasmoidId": -1,
"applet": null
});
}
brightnessSlider.valueChanged.connect(function() {
root.screenBrightness = brightnessSlider.value;
});