Skip to content

Commit

Permalink
Port lock desktop config in plasma to plasma 6
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbruno committed Mar 17, 2024
1 parent 4372aa3 commit f705acb
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,95 +1,90 @@
/*
* SPDX-FileCopyleftText: 2022 Bruno Gonçalves <[email protected]> and Rafael Ruscher <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

import QtQuick 2.1
import QtQuick.Layouts 1.0
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponent

Item {
* SPDX-FileCopyrightText: 2022 Bruno Gonçalves <[email protected]> and Rafael Ruscher <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick
import org.kde.plasma.plasmoid
import org.kde.plasma.core as PlasmaCore
import org.kde.kirigami as Kirigami
import org.kde.plasma.plasma5support as Plasma5Support

PlasmoidItem {
id: root
property string outputText

PlasmaCore.DataSource {
id: executable
engine: "executable"
connectedSources: []
onNewData: {
var exitCode = data["exit code"]
var exitStatus = data["exit status"]
var stdout = data["stdout"]
var stderr = data["stderr"]
exited(sourceName, exitCode, exitStatus, stdout, stderr)
disconnectSource(sourceName) // cmd finished
}
function exec(cmd) {
if (cmd) {
connectSource(cmd)
}
}
signal exited(string cmd, int exitCode, int exitStatus, string stdout, string stderr)
}

property string outputText: 'true'
Connections {
target: executable
onExited: {
outputText = stdout
timer.restart()
}
}

function runCommand() {
// Change to run your command
//
executable.exec('cat $HOME/.config/lockplasma')
//executable.exec('qdbus org.kde.plasmashell /PlasmaShell org.freedesktop.DBus.Properties.Get "" editMode')

}

Timer {
id: timer

// Wait in ms
interval: 7000
onTriggered: runCommand()
Component.onCompleted: {
triggered()
}
}
function runCommand() {
// Change to run your command
executable.exec('cat $HOME/.config/lockplasma');
}

Plasmoid.icon: outputText ? 'biglinux-lock' : 'biglinux-unlock'
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
function toggle() {
executable.exec('/usr/share/bigbashview/bcc/apps/biglinux-themes-gui/lock-desktop.run');
timer.interval = 500;
}

preferredRepresentation: fullRepresentation
// Active = in systray and Passive in notification area
Plasmoid.status: {
//return PlasmaCore.Types.ActiveStatus;
return PlasmaCore.Types.PassiveStatus;
}
}

function toggle() {
Plasma5Support.DataSource {
id: "executable"
signal exited(string sourceName, int exitCode, int exitStatus, string stdout, string stderr)
function exec(cmd) {
connectSource(cmd);
}

executable.exec('/usr/share/bigbashview/bcc/apps/biglinux-themes-gui/lock-desktop.run')
timer.interval = 500
engine: "executable"
connectedSources: []
onNewData: function(sourceName, data) {
var exitCode = data["exit code"];
var exitStatus = data["exit status"];
var stdout = data["stdout"];
var stderr = data["stderr"];
exited(sourceName, exitCode, exitStatus, stdout, stderr);
disconnectSource(sourceName);
}
}

Connections {
function onExited(sourceName, exitCode, exitStatus, stdout, stderr) {
Qt.callLater(function() {
root.outputText = stdout;
});
timer.restart();
}

target: executable
}

Timer {
id: timer

// Wait in ms
interval: 7000
onTriggered: runCommand()
Component.onCompleted: {
triggered();
}
}

fullRepresentation: PlasmoidItem {
Kirigami.Icon {
id: icon
source: outputText ? 'biglinux-lock' : 'biglinux-unlock'
height: Math.min(parent.height, parent.width)
width: Math.min(parent.height, parent.width)
anchors.fill: parent
}

Plasmoid.compactRepresentation: PlasmaCore.IconItem {
active: compactMouseArea.containsMouse
source: plasmoid.icon

MouseArea {
id: compactMouseArea
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onClicked: toggle()
}
}

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"KPackageStructure": "Plasma/Applet",
"KPlugin": {
"Authors": [
{
Expand All @@ -14,6 +15,9 @@
"Description": "Prevents the desktop from being accidentally misconfigured.",
"Description[pt_BR]": "Evita que o desktop seja desconfigurado acidentalmente",
"EnabledByDefault": true,
"FormFactors": [
"desktop"
],
"Icon": "biglinux-lock",
"Id": "org.biglinux.lock_edit_plasma",
"License": "GPL-2.0+",
Expand Down Expand Up @@ -53,8 +57,11 @@
"Version": "1.0",
"Website": "https://kde.org/plasma-desktop"
},
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-MainScript": "ui/main.qml",
"X-Plasma-API-Minimum-Version": "6.0",
"X-Plasma-NotificationArea": "true",
"X-Plasma-NotificationAreaCategory": "SystemServices"
"X-Plasma-NotificationAreaCategory": "System",
"X-Plasma-Provides": [
"org.biglinux.lock_edit_plasma"
],
"X-Plasma-OptionalExtensions": "LaunchApp"
}

0 comments on commit f705acb

Please sign in to comment.