Warning, /multimedia/haruna/src/qml/Settings/EditCustomCommand.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2021 George Florea Bănuș <georgefb899@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Layouts 0009 import QtQuick.Controls 0010 0011 import org.kde.kirigami as Kirigami 0012 import org.kde.haruna 0013 0014 SettingsBasePage { 0015 id: root 0016 0017 property string settingsPath: "qrc:/qt/qml/org/kde/haruna/qml/Settings" 0018 property string command: "" 0019 property string osdMessage: "" 0020 property string type: "shortcut" 0021 property string commandId: "" 0022 property int index: -1 0023 property int mode: EditCustomCommand.Mode.Create 0024 0025 enum Mode { 0026 Create = 0, 0027 Edit 0028 } 0029 0030 hasHelp: true 0031 helpFile: ":/CustomCommandsSettings.html" 0032 0033 Action { 0034 shortcut: "esc" 0035 onTriggered: applicationWindow().pageStack.replace(`${root.settingsPath}/CustomCommandsSettings.qml`) 0036 } 0037 0038 GridLayout { 0039 columns: 2 0040 0041 Label { 0042 text: i18nc("@label:textbox", "Command") 0043 Layout.alignment: Qt.AlignRight 0044 } 0045 0046 TextField { 0047 id: commandTextField 0048 0049 text: root.command 0050 placeholderText: i18nc("placeholder text", "add volume +10") 0051 Layout.fillWidth: true 0052 Component.onCompleted: forceActiveFocus() 0053 } 0054 0055 Label { 0056 text: i18nc("@label:textbox", "OSD Message") 0057 Layout.alignment: Qt.AlignRight 0058 } 0059 0060 TextField { 0061 id: osdMessageTextField 0062 0063 text: root.osdMessage 0064 enabled: typeGroup.checkedButton.optionName === "shortcut" 0065 placeholderText: i18nc("placeholder text", "Filename: ${filename}") 0066 Layout.fillWidth: true 0067 } 0068 0069 Label { 0070 text: i18nc("@label", "Type") 0071 visible: root.mode === EditCustomCommand.Mode.Create 0072 Layout.alignment: Qt.AlignRight | Qt.AlignTop 0073 } 0074 0075 ButtonGroup { 0076 id: typeGroup 0077 0078 buttons: typeGroupItems.children 0079 } 0080 0081 Column { 0082 id: typeGroupItems 0083 0084 spacing: Kirigami.Units.largeSpacing 0085 visible: root.mode === EditCustomCommand.Mode.Create 0086 0087 RadioButton { 0088 property string optionName: "shortcut" 0089 0090 checked: optionName === root.type 0091 text: i18nc("@option:radio", "Keyboard shortcut") 0092 } 0093 0094 RadioButton { 0095 property string optionName: "startup" 0096 0097 checked: optionName === root.type 0098 text: i18nc("@option:radio", "Run at startup") 0099 } 0100 } 0101 } 0102 0103 footer: ToolBar { 0104 RowLayout { 0105 anchors.fill: parent 0106 0107 ToolButton { 0108 text: i18nc("@action:intoolbar", "Delete") 0109 icon.name: "delete" 0110 visible: root.mode === EditCustomCommand.Mode.Edit 0111 onClicked: { 0112 customCommandsModel.deleteCustomCommand(root.commandId, root.index) 0113 applicationWindow().pageStack.replace(`${root.settingsPath}/CustomCommandsSettings.qml`) 0114 } 0115 } 0116 0117 Item { 0118 0119 Layout.fillWidth: true 0120 } 0121 0122 ToolButton { 0123 text: i18nc("@action:intoolbar", "Cancel") 0124 icon.name: "dialog-cancel" 0125 onClicked: applicationWindow().pageStack.replace(`${root.settingsPath}/CustomCommandsSettings.qml`) 0126 Layout.alignment: Qt.AlignRight 0127 } 0128 0129 ToolButton { 0130 text: i18nc("@action:intoolbar", "&Save") 0131 icon.name: "document-save" 0132 enabled: commandTextField.text !== "" 0133 onClicked: saveCustomCommand() 0134 0135 Layout.alignment: Qt.AlignRight 0136 0137 function saveCustomCommand() { 0138 if (commandTextField.text === "") { 0139 return 0140 } 0141 if (typeGroup.checkedButton.optionName === "startup") { 0142 // execute the user command 0143 mpv.userCommand(commandTextField.text) 0144 } 0145 switch (root.mode) { 0146 case EditCustomCommand.Mode.Create: 0147 // save new command to config file 0148 customCommandsModel.saveCustomCommand(commandTextField.text, 0149 osdMessageTextField.text, 0150 typeGroup.checkedButton.optionName) 0151 break 0152 case EditCustomCommand.Mode.Edit: 0153 // update existing command 0154 customCommandsModel.editCustomCommand(root.index, 0155 commandTextField.text, 0156 osdMessageTextField.text, 0157 typeGroup.checkedButton.optionName) 0158 break 0159 } 0160 applicationWindow().pageStack.replace(`${root.settingsPath}/CustomCommandsSettings.qml`) 0161 } 0162 0163 } 0164 } 0165 } 0166 }