| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2021 George Florea Bănuș <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
import QtQuick |
| 8 |
import QtQuick.Layouts |
| 9 |
import QtQuick.Controls |
| 10 |
|
| 11 |
import org.kde.kirigami as Kirigami |
| 12 |
import org.kde.haruna |
| 13 |
|
| 14 |
SettingsBasePage { |
| 15 |
id: root |
| 16 |
|
| 17 |
required property CustomCommandsModel m_customCommandsModel |
| 18 |
|
| 19 |
property string settingsPath: "qrc:/qt/qml/org/kde/haruna/qml/Settings" |
| 20 |
property string command: "" |
| 21 |
property string osdMessage: "" |
| 22 |
property string type: "shortcut" |
| 23 |
property string commandId: "" |
| 24 |
property int index: -1 |
| 25 |
property int mode: EditCustomCommand.Mode.Create |
| 26 |
|
| 27 |
enum Mode { |
| 28 |
Create = 0, |
| 29 |
Edit |
| 30 |
} |
| 31 |
|
| 32 |
Action { |
| 33 |
shortcut: "esc" |
| 34 |
onTriggered: applicationWindow().pageStack.replace(`${root.settingsPath}/CustomCommandsSettings.qml`, |
| 35 |
{m_customCommandsModel: root.m_customCommandsModel}) |
| 36 |
} |
| 37 |
|
| 38 |
GridLayout { |
| 39 |
columns: 2 |
| 40 |
|
| 41 |
Label { |
| 42 |
text: i18nc("@label:textbox", "Command") |
| 43 |
Layout.alignment: Qt.AlignRight |
| 44 |
} |
| 45 |
|
| 46 |
RowLayout { |
| 47 |
TextField { |
| 48 |
id: commandTextField |
| 49 |
|
| 50 |
text: root.command |
| 51 |
placeholderText: "add volume +10" |
| 52 |
Layout.fillWidth: true |
| 53 |
Component.onCompleted: forceActiveFocus() |
| 54 |
} |
| 55 |
|
| 56 |
ToolTipButton { |
| 57 |
toolTipText: i18nc("@info:tooltip", |
| 58 |
"What mpv command to run, " + |
| 59 |
"see <a href=\"https://mpv.io/manual/stable/#list-of-input-commands\">MPV Commands</a> " + |
| 60 |
"for a list of available commands.<br>" + |
| 61 |
"Not all commands will work as some are specific for mpv.<br>" + |
| 62 |
"Most useful are the commands to manipulate properties, " + |
| 63 |
"like <strong>set</strong>, <strong>add</strong>, <strong>cycle</strong>.<br>" + |
| 64 |
"<strong>set</strong>: sets the value of a property <strong>set volume-max 150</strong>.<br>" + |
| 65 |
"<strong>add</strong>: increases/decreases the value of a property <strong>add volume 15</strong>, " + |
| 66 |
"increases volume by 15. To decrease the value use <strong>add volume -15</strong>.<br>" + |
| 67 |
"<strong>cycle</strong>: cycle through the values of a property <strong>cycle aid up</strong>.") |
| 68 |
toolTipWidth: 450 |
| 69 |
|
| 70 |
Layout.preferredHeight: Kirigami.Units.iconSizes.medium |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
Label { |
| 75 |
text: i18nc("@label:textbox", "OSD Message") |
| 76 |
Layout.alignment: Qt.AlignRight |
| 77 |
} |
| 78 |
|
| 79 |
RowLayout { |
| 80 |
TextField { |
| 81 |
id: osdMessageTextField |
| 82 |
|
| 83 |
text: root.osdMessage |
| 84 |
enabled: typeGroup.checkedButton.optionName === "shortcut" |
| 85 |
placeholderText: i18nc("placeholder text; %1 is an example of how to display an mpv property", "Filename: %1", "${filename}") |
| 86 |
Layout.fillWidth: true |
| 87 |
} |
| 88 |
|
| 89 |
ToolTipButton { |
| 90 |
toolTipText: i18nc("@info:tooltip", |
| 91 |
"An OSD message to display when triggering an action type custom command.<br>" + |
| 92 |
"Use ${property_name} to display the value of a property <strong>Volume: ${volume}</strong>") |
| 93 |
toolTipWidth: 450 |
| 94 |
|
| 95 |
Layout.preferredHeight: Kirigami.Units.iconSizes.medium |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
Label { |
| 100 |
text: i18nc("@label", "Type") |
| 101 |
visible: root.mode === EditCustomCommand.Mode.Create |
| 102 |
Layout.alignment: Qt.AlignRight | Qt.AlignTop |
| 103 |
} |
| 104 |
|
| 105 |
ButtonGroup { |
| 106 |
id: typeGroup |
| 107 |
|
| 108 |
buttons: typeGroupItems.children |
| 109 |
} |
| 110 |
|
| 111 |
Column { |
| 112 |
id: typeGroupItems |
| 113 |
|
| 114 |
spacing: Kirigami.Units.largeSpacing |
| 115 |
visible: root.mode === EditCustomCommand.Mode.Create |
| 116 |
|
| 117 |
RadioButton { |
| 118 |
property string optionName: "shortcut" |
| 119 |
|
| 120 |
checked: optionName === root.type |
| 121 |
text: i18nc("@option:radio", "Keyboard shortcut") |
| 122 |
ToolTip.text: i18nc("@info:tooltip", "The command will be triggered with a shortcut. The shortcut can be set after saving.") |
| 123 |
ToolTip.visible: hovered |
| 124 |
ToolTip.delay: 700 |
| 125 |
} |
| 126 |
|
| 127 |
RadioButton { |
| 128 |
property string optionName: "startup" |
| 129 |
|
| 130 |
checked: optionName === root.type |
| 131 |
text: i18nc("@option:radio", "Run at startup") |
| 132 |
ToolTip.text: i18nc("@info:tooltip", "The command will be run at application startup.") |
| 133 |
ToolTip.visible: hovered |
| 134 |
ToolTip.delay: 700 |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
footer: ToolBar { |
| 140 |
RowLayout { |
| 141 |
anchors.fill: parent |
| 142 |
|
| 143 |
ToolButton { |
| 144 |
text: i18nc("@action:intoolbar", "Delete") |
| 145 |
icon.name: "delete" |
| 146 |
visible: root.mode === EditCustomCommand.Mode.Edit |
| 147 |
onClicked: { |
| 148 |
root.m_customCommandsModel.deleteCustomCommand(root.commandId, root.index) |
| 149 |
applicationWindow().pageStack.replace(`${root.settingsPath}/CustomCommandsSettings.qml`, |
| 150 |
{m_customCommandsModel: root.m_customCommandsModel}) |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
Item { |
| 155 |
|
| 156 |
Layout.fillWidth: true |
| 157 |
} |
| 158 |
|
| 159 |
ToolButton { |
| 160 |
text: i18nc("@action:intoolbar", "Cancel") |
| 161 |
icon.name: "dialog-cancel" |
| 162 |
onClicked: applicationWindow().pageStack.replace(`${root.settingsPath}/CustomCommandsSettings.qml`, |
| 163 |
{m_customCommandsModel: root.m_customCommandsModel}) |
| 164 |
Layout.alignment: Qt.AlignRight |
| 165 |
} |
| 166 |
|
| 167 |
ToolButton { |
| 168 |
text: i18nc("@action:intoolbar", "&Save") |
| 169 |
icon.name: "document-save" |
| 170 |
enabled: commandTextField.text !== "" |
| 171 |
onClicked: saveCustomCommand() |
| 172 |
|
| 173 |
Layout.alignment: Qt.AlignRight |
| 174 |
|
| 175 |
function saveCustomCommand() : void { |
| 176 |
if (commandTextField.text === "") { |
| 177 |
return |
| 178 |
} |
| 179 |
if (typeGroup.checkedButton.optionName === "startup") { |
| 180 |
// execute the user command |
| 181 |
mpv.userCommand(commandTextField.text) |
| 182 |
} |
| 183 |
switch (root.mode) { |
| 184 |
case EditCustomCommand.Mode.Create: |
| 185 |
// save new command to config file |
| 186 |
root.m_customCommandsModel.saveCustomCommand(commandTextField.text, |
| 187 |
osdMessageTextField.text, |
| 188 |
typeGroup.checkedButton.optionName) |
| 189 |
break |
| 190 |
case EditCustomCommand.Mode.Edit: |
| 191 |
// update existing command |
| 192 |
root.m_customCommandsModel.editCustomCommand(root.index, |
| 193 |
commandTextField.text, |
| 194 |
osdMessageTextField.text, |
| 195 |
typeGroup.checkedButton.optionName) |
| 196 |
break |
| 197 |
} |
| 198 |
applicationWindow().pageStack.replace(`${root.settingsPath}/CustomCommandsSettings.qml`, |
| 199 |
{m_customCommandsModel: root.m_customCommandsModel}) |
| 200 |
} |
| 201 |
|
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
} |