2021-02-27 19:04:47 +00:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
|
|
|
|
2022-12-13 20:45:50 +00:00
|
|
|
import QtQuick 2.15
|
2024-08-08 12:37:32 +01:00
|
|
|
import QtQuick.Layouts
|
2022-12-13 20:45:50 +00:00
|
|
|
import QtQuick.Controls 2.15 as QQC2
|
|
|
|
import org.kde.kirigami 2.20 as Kirigami
|
2019-10-27 17:08:51 +00:00
|
|
|
import org.kde.kdeconnect 1.0
|
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
Kirigami.ScrollablePage {
|
|
|
|
id: root
|
2019-10-27 17:08:51 +00:00
|
|
|
|
|
|
|
property string device
|
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
actions: Kirigami.Action {
|
|
|
|
id: addCommandDialogAction
|
2019-10-27 17:08:51 +00:00
|
|
|
icon.name: "list-add"
|
2024-08-01 23:24:13 +01:00
|
|
|
text: i18n("Add Command…")
|
2019-10-27 17:08:51 +00:00
|
|
|
onTriggered: addDialog.open()
|
|
|
|
}
|
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
ListView {
|
|
|
|
id: view
|
|
|
|
|
|
|
|
model: CommandsModel {
|
|
|
|
id: commandModel
|
|
|
|
deviceId: device
|
|
|
|
}
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
delegate: Kirigami.SwipeListItem {
|
|
|
|
width: parent.width
|
|
|
|
enabled: true
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
contentItem: ColumnLayout {
|
|
|
|
QQC2.Label {
|
|
|
|
text: name
|
|
|
|
Layout.fillWidth: true
|
|
|
|
elide: Text.ElideRight
|
|
|
|
}
|
|
|
|
QQC2.Label {
|
|
|
|
text: command
|
|
|
|
font.italic: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
elide: Text.ElideRight
|
|
|
|
}
|
2024-08-08 12:37:32 +01:00
|
|
|
}
|
2024-10-05 21:53:32 +01:00
|
|
|
|
|
|
|
actions: Kirigami.Action {
|
|
|
|
text: i18n("Delete")
|
|
|
|
icon.name: "delete"
|
|
|
|
onTriggered: commandModel.removeCommand(index)
|
2024-08-08 12:37:32 +01:00
|
|
|
}
|
2022-12-13 20:45:50 +00:00
|
|
|
}
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
Kirigami.PlaceholderMessage {
|
|
|
|
icon.name: 'utilities-terminal'
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: view.count === 0
|
|
|
|
width: parent.width - Kirigami.Units.gridUnit * 4
|
|
|
|
text: i18nc("@info", "No commands configured")
|
2024-10-05 19:24:35 +01:00
|
|
|
explanation: i18nc("@info", "Add commands to run them remotely from other devices")
|
2024-10-05 21:53:32 +01:00
|
|
|
helpfulAction: addCommandDialogAction
|
2019-10-27 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
Kirigami.Dialog {
|
|
|
|
id: addDialog
|
|
|
|
title: i18nc("@title:window", "Add Command")
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
padding: Kirigami.Units.largeSpacing
|
|
|
|
preferredWidth: Kirigami.Units.gridUnit * 20
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
property Kirigami.Action addCommandAction: Kirigami.Action {
|
|
|
|
text: i18nc("@action:button", "Add")
|
|
|
|
icon.name: "list-add"
|
|
|
|
enabled: commandField.length > 0
|
|
|
|
onTriggered: {
|
|
|
|
commandModel.addCommand(nameField.text, commandField.text)
|
|
|
|
addDialog.close();
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
// TODO: can be set directly once Qt 6.8 is required
|
|
|
|
Accessible.Name = i18nc("@action:button accessible", "Add command")
|
|
|
|
}
|
2024-08-01 23:24:13 +01:00
|
|
|
}
|
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
standardButtons: Kirigami.Dialog.Cancel
|
|
|
|
customFooterActions: [addCommandAction]
|
2024-08-01 23:24:13 +01:00
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
Kirigami.FormLayout {
|
|
|
|
QQC2.TextField {
|
|
|
|
id: nameField
|
|
|
|
Kirigami.FormData.label: i18n("Name:")
|
|
|
|
}
|
|
|
|
QQC2.TextField {
|
|
|
|
id: commandField
|
|
|
|
Kirigami.FormData.label: i18n("Command:")
|
|
|
|
}
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2024-10-05 21:53:32 +01:00
|
|
|
QQC2.ComboBox {
|
|
|
|
Kirigami.FormData.label: i18n("Sample commands:")
|
|
|
|
textRole: "name"
|
|
|
|
model: ListModel {
|
|
|
|
id: sampleCommands
|
|
|
|
ListElement {
|
|
|
|
name: "Sample command"
|
|
|
|
command: ""
|
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
name: "Suspend"
|
|
|
|
command: "systemctl suspend"
|
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
name: "Maximum Brightness"
|
|
|
|
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`"
|
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
name: "Lock Screen"
|
|
|
|
command: "loginctl lock-session"
|
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
name: "Unlock Screen"
|
|
|
|
command: "loginctl unlock-session"
|
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
name: "Close All Vaults"
|
|
|
|
command: "qdbus org.kde.kded5 /modules/plasmavault closeAllVaults"
|
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
name: "Forcefully Close All Vaults"
|
|
|
|
command: "qdbus org.kde.kded5 /modules/plasmavault forceCloseAllVaults"
|
|
|
|
}
|
2019-10-27 17:08:51 +00:00
|
|
|
}
|
2024-10-05 21:53:32 +01:00
|
|
|
onActivated: {
|
|
|
|
if (index > 0) {
|
|
|
|
nameField.text = sampleCommands.get(index).name
|
|
|
|
commandField.text = sampleCommands.get(index).command
|
|
|
|
}
|
2019-10-27 17:08:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|