1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*
* Plasma XR Applet
* Copyright 2018 Collabora Ltd.
* Author: Christoph Haag <christoph.haag@collabora.com>
* Author: Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
* Author: Fabian Kranewitter <fabiankranewitter@gmail.com>
* SPDX-License-Identifier: MIT
*/
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 2.0 as PlasmaComponents
import QtQuick.Dialogs 1.1
Item {
id:applet
Plasmoid.icon: plasmoid.file("images", "../images/vr-symbolic.svg")
Plasmoid.status:PlasmaCore.Types.PassiveStatus
Layout.minimumWidth: units.gridUnit * 8
Layout.minimumHeight: units.gridUnit * 3
MessageDialog {
id: messageDialog
title: "Error calling XR desktop dbus interface"
// default text that should be replaced before showing the dialog
text: "An error occured"
onAccepted: {
enableButton.skip_processing = true
enableButton.togglestatus = false
//console.log("And of course you could only agree.")
}
Component.onCompleted: visible = false
}
Item {
id: statusView
visible: true
anchors.fill: parent
PlasmaComponents.BusyIndicator {
id: busyindicator
visible: !enableButton.visible
Timer {
property bool queryfinish:false
id: busyindicatortimer;
interval: 1000;
onTriggered: {
if(queryfinish){
enableButton.visible = true
busyindicator.visible = false
}
queryfinish = false
}
}
anchors {
horizontalCenter: parent.horizontalCenter
verticalCenter: parent.verticalCenter
}
PlasmaExtras.Heading {
id: xrdesktopstatusheading
level: 3
visible: applet.height > (units.gridUnit * 6)
opacity: 0.6
text: enableButton.togglestatus ? i18n("Starting...") : i18n("Stopping...")
anchors {
horizontalCenter: parent.horizontalCenter
bottom: busyindicator.top
bottomMargin: units.smallSpacing
}
}
}
PlasmaComponents.Button {
id: enableButton
text: togglestatus ? i18n("Disable xrdesktop") : i18n("Enable xrdesktop")
checked:togglestatus
iconSource: Qt.resolvedUrl("../images/vr-symbolic.svg")
// after an error, when setting the button to off, don't trigger the error message again
property bool skip_processing: false
property bool togglestatus: false
onClicked: {
togglestatus = !togglestatus
toggleAction(togglestatus)
}
anchors {
horizontalCenter: parent.horizontalCenter
verticalCenter: parent.verticalCenter
}
}
}
PlasmaExtras.Heading {
id: headingStatus
width: parent.width
opacity: 0.6
level:3
visible: true
}
function toggleAction(checked) {
console.info("xrdesktop enabled: " + checked)
enableButton.visible = false;
//reset timer
busyindicatortimer.running = false;
busyindicatortimer.running = true;
busyindicator.visible = true;
execToggle.connectSource('qdbus org.kde.KWin /XR org.kde.kwin.XR.active ' + checked)
}
PlasmaCore.DataSource {
id: execToggle
engine: "executable"
connectedSources: []
onNewData: {
headingStatus.text = ""
//console.info("Toggle reply: " + data.stdout + "; " + data.stderr)
if (data.stderr !== "") {
// the button is being set to false as a result of an error, don't do anything'
if (enableButton.skip_processing) {
enableButton.skip_processing = false;
disconnectSource(sourceName)
return
}
}
if (data.stdout !== "") {
// TODO: handle error
}
disconnectSource(sourceName)
}
}
PlasmaCore.DataSource {
id: execQuery
engine: "executable"
connectedSources: []
onNewData: {
headingStatus.text = ""
//console.info("Timer query reply: " + data.stdout + "; " + data.stderr)
if (data.stderr == "") {
enableButton.togglestatus = data.stdout.toString().match("^true")
if(busyindicatortimer.running) {
busyindicatortimer.queryfinish = true;
}else {
enableButton.visible = true;
busyindicator.visible = false;
}
} else {
// console.info("xrdesktop plugin error: " + data.stderr + "\n")
headingStatus.text = applet.height > (units.gridUnit * 6) ? i18n("The xrdesktop plugin is not enabled in KWin or not working.") : i18n("The plugin is not enabled.")
headingStatus.text += "\n" + data.stderr + "\n"
if (data.stderr.toString().match("^Cannot find")) {
headingStatus.text += "Usually this means the xrdesktop plugin is not enabled in KWin or not working."
}
enableButton.visible = false;
busyindicator.visible = false;
}
disconnectSource(sourceName)
}
}
Timer {
id: timer;
interval: 2000;
onTriggered: {
execQuery.connectSource('qdbus org.kde.KWin /XR org.kde.kwin.XR.active');
}
repeat: true;
triggeredOnStart:true;
running: true;
}
}
|