Warning, /network/kdeconnect-kde/plugins/runcommand/kdeconnect_runcommand_config.qml is written in an unsupported language. File is not indexed.

0001 /**
0002  * SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Controls 2.15 as QQC2
0009 import org.kde.kirigami 2.20 as Kirigami
0010 import org.kde.kdeconnect 1.0
0011 
0012 ListView {
0013     id: view
0014     Component.onCompleted: {
0015         root.leftPadding = 0
0016         root.rightPadding = 0
0017         root.topPadding = 0
0018         root.bottomPadding = 0
0019     }
0020 
0021     property string device
0022 
0023     property var action: Kirigami.Action {
0024         icon.name: "list-add"
0025         text: i18n("Add command")
0026         onTriggered: addDialog.open()
0027     }
0028 
0029     model: CommandsModel {
0030         id: commandModel
0031         deviceId: device
0032     }
0033 
0034     delegate: Kirigami.SwipeListItem {
0035         width: parent.width
0036         enabled: true
0037 
0038         contentItem: QQC2.Label {
0039             text: i18n("%1 <br> <i>%2</i>", name, command)
0040         }
0041 
0042         actions: Kirigami.Action {
0043             text: i18n("Delete")
0044             icon.name: "delete"
0045             onTriggered: commandModel.removeCommand(index)
0046         }
0047     }
0048 
0049     Kirigami.PlaceholderMessage {
0050         icon.name: 'utilities-terminal'
0051         anchors.centerIn: parent
0052         visible: view.count === 0
0053         width: parent.width - Kirigami.Units.gridUnit * 4
0054         text: i18n("No Commands")
0055         explanation: i18n("Add commands to run them remotely from other devices")
0056         helpfulAction: view.action
0057     }
0058 
0059     QQC2.Dialog {
0060         id: addDialog
0061         title: "Add command"
0062 
0063         standardButtons: QQC2.Dialog.Save | QQC2.Dialog.Cancel
0064 
0065         Kirigami.FormLayout {
0066             QQC2.TextField {
0067                 id: nameField
0068                 Kirigami.FormData.label: i18n("Name:")
0069             }
0070             QQC2.TextField {
0071                 id: commandField
0072                 Kirigami.FormData.label: i18n("Command:")
0073             }
0074 
0075             QQC2.ComboBox {
0076                 Kirigami.FormData.label: i18n("Sample commands:")
0077                 textRole: "name"
0078                 model: ListModel {
0079                     id: sampleCommands
0080                     ListElement {
0081                         name: "Sample command"
0082                         command: ""
0083                     }
0084                     ListElement {
0085                         name: "Suspend"
0086                         command: "systemctl suspend"
0087                     }
0088                     ListElement {
0089                         name: "Maximum Brightness"
0090                         command: "qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.setBrightness `qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.brightnessMax`"
0091                     }
0092                     ListElement {
0093                         name: "Lock Screen"
0094                         command: "loginctl lock-session"
0095                     }
0096                     ListElement {
0097                         name: "Unlock Screen"
0098                         command: "loginctl unlock-session"
0099                     }
0100                     ListElement {
0101                         name: "Close All Vaults"
0102                         command: "qdbus org.kde.kded5 /modules/plasmavault closeAllVaults"
0103                     }
0104                     ListElement {
0105                         name: "Forcefully Close All Vaults"
0106                         command: "qdbus org.kde.kded5 /modules/plasmavault forceCloseAllVaults"
0107                     }
0108                 }
0109                 onActivated: {
0110                     if (index > 0) {
0111                         nameField.text = sampleCommands.get(index).name
0112                         commandField.text = sampleCommands.get(index).command
0113                     }
0114                 }
0115             }
0116         }
0117 
0118         onAccepted: commandModel.addCommand(nameField.text, commandField.text)
0119     }
0120 }