Warning, /plasma/plasma-workspace/kcms/autostart/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtCore
0008 import QtQuick
0009 import QtQuick.Controls
0010 import QtQuick.Layouts
0011 import QtQuick.Dialogs
0012 
0013 import org.kde.kcmutils as KCM
0014 import org.kde.kirigami as Kirigami
0015 import org.kde.plasma.kcm.autostart
0016 
0017 KCM.ScrollViewKCM {
0018     id: root
0019 
0020     implicitHeight: Kirigami.Units.gridUnit * 28
0021     implicitWidth: Kirigami.Units.gridUnit * 28
0022 
0023     header: Kirigami.InlineMessage {
0024         id: errorMessage
0025 
0026         showCloseButton: true
0027 
0028         Connections {
0029             target: kcm.model
0030             
0031             property var fixItAction: Kirigami.Action {
0032                 property string fileName
0033                 text: i18n("Make Executable")
0034                 icon.name: "dialog-ok"
0035                 onTriggered: {
0036                     kcm.model.makeFileExecutable(fileName);
0037                     errorMessage.visible = false;
0038                 }
0039             }
0040             
0041             function onError(message) {
0042                 errorMessage.type = Kirigami.MessageType.Error;
0043                 errorMessage.visible = true;
0044                 errorMessage.text = message;
0045             }
0046 
0047             function onNonExecutableScript(fileName, kind) {
0048                 fixItAction.fileName = fileName;
0049                 errorMessage.type = Kirigami.MessageType.Warning;
0050                 errorMessage.visible = true;
0051                 errorMessage.actions = [fixItAction];
0052                 if (kind === AutostartModel.PlasmaShutdown) {
0053                     errorMessage.text = i18nd("kcm_autostart", "The file '%1' must be executable to run at logout.", fileName);
0054                 } else {
0055                     errorMessage.text = i18nd("kcm_autostart", "The file '%1' must be executable to run at login.", fileName);
0056                 }
0057             }
0058 
0059         }
0060 
0061     }
0062 
0063     actions: [
0064         Kirigami.Action {
0065             icon.name: "list-add-symbolic"
0066             text: i18nc("@action:button", "Add…")
0067 
0068             Kirigami.Action {
0069                 text: i18nc("@action:button", "Add Application…")
0070                 icon.name: "list-add-symbolic"
0071                 onTriggered: kcm.model.showApplicationDialog(root)
0072             }
0073             Kirigami.Action {
0074                 text: i18nc("@action:button", "Add Login Script…")
0075                 icon.name: "list-add-symbolic"
0076                 onTriggered: loginFileDialogLoader.active = true
0077             }
0078             Kirigami.Action {
0079                 text: i18nc("@action:button", "Add Logout Script…")
0080                 icon.name: "list-add-symbolic"
0081                 onTriggered: logoutFileDialogLoader.active = true
0082             }
0083         }
0084     ]
0085 
0086     view: ListView {
0087         id: listView
0088 
0089         clip: true
0090         model: kcm.model
0091 
0092         delegate: ItemDelegate {
0093             id: delegate
0094 
0095             property Unit unit: model.systemdUnit
0096             property bool noUnit: (unit && !kcm.model.usingSystemdBoot) || (model.source === AutostartModel.PlasmaShutdown || model.source === AutostartModel.PlasmaEnvScripts)
0097 
0098             text: model.name
0099             width: ListView.view.width
0100 
0101             onClicked: {
0102                 if (noUnit) {
0103                     return;
0104                 }
0105 
0106                 if (!model.systemdUnit.invalid) {
0107                     kcm.pop();
0108                     kcm.push("entry.qml", {
0109                         "unit": unit
0110                     });
0111                 } else {
0112                     errorMessage.type = Kirigami.MessageType.Warning;
0113                     errorMessage.visible = true;
0114                     errorMessage.text = i18nd("kcm_autostart", "%1 has not been autostarted yet. Details will be available after the system is restarted.", model.name);
0115                 }
0116             }
0117 
0118             contentItem: RowLayout {
0119                 spacing: Kirigami.Units.smallSpacing
0120 
0121                 Kirigami.IconTitleSubtitle {
0122                     Layout.fillWidth: true
0123                     icon.name: model.iconName
0124 
0125                     reserveSpaceForSubtitle: true
0126 
0127                     title: delegate.text
0128                     subtitle: model.source === AutostartModel.PlasmaShutdown || model.source === AutostartModel.XdgScripts ? model.targetFileDirPath : ""
0129                 }
0130 
0131                 Label {
0132                     Layout.rightMargin: Kirigami.Units.smallSpacing
0133                     text: {
0134                         if (noUnit || !model.systemdUnit) {
0135                             return "";
0136                         } else if (model.systemdUnit.invalid) {
0137                             return i18nc("@label Entry hasn't been autostarted because system hasn't been restarted", "Not autostarted yet");
0138                         } else {
0139                             return model.systemdUnit.activeStateValue;
0140                         }
0141                     }
0142                     color: model.systemdUnit.activeState === "failed" ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.disabledTextColor
0143                 }
0144 
0145                 ToolButton {
0146                     text: i18nc("@action:button", "See properties")
0147                     icon.name: "document-properties"
0148                     display: Button.IconOnly
0149                     onClicked: kcm.model.editApplication(model.index, root)
0150                     visible: model.source === AutostartModel.XdgAutoStart || model.source === AutostartModel.XdgScripts
0151                 }
0152 
0153                 ToolButton {
0154                     text: i18nc("@action:button", "Remove entry")
0155                     icon.name: "edit-delete-remove"
0156                     display: Button.IconOnly
0157                     onClicked: kcm.model.removeEntry(model.index)
0158                 }
0159             }
0160         }
0161 
0162         section.property: "source"
0163         section.delegate: Kirigami.ListSectionHeader {
0164             width: listView.width
0165             text: {
0166                 if (section == AutostartModel.XdgAutoStart){
0167                     return i18n("Applications");
0168                 }
0169                 if (section == AutostartModel.XdgScripts){
0170                     return i18n("Login Scripts");
0171                 }
0172                 if (section == AutostartModel.PlasmaEnvScripts){
0173                     return i18n("Pre-startup Scripts");
0174                 }
0175                 if (section == AutostartModel.PlasmaShutdown){
0176                     return i18n("Logout Scripts");
0177                 }
0178             }
0179         }
0180         Kirigami.PlaceholderMessage {
0181             anchors.centerIn: parent
0182             width: parent.width - (Kirigami.Units.largeSpacing * 4)
0183             visible: parent.count === 0
0184             text: i18n("No user-specified autostart items")
0185             explanation: xi18nc("@info 'some' refers to autostart items", "Click the <interface>Add…</interface> button to add some")
0186         }
0187     }
0188 
0189     footer: Row {
0190         spacing: Kirigami.Units.largeSpacing
0191 
0192         Loader {
0193             id: loginFileDialogLoader
0194 
0195             active: false
0196 
0197             sourceComponent: FileDialog {
0198                 id: loginFileDialog
0199 
0200                 title: i18n("Choose Login Script")
0201                 currentFolder: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0]
0202                 onAccepted: {
0203                     kcm.model.addScript(loginFileDialog.selectedFile, AutostartModel.XdgScripts);
0204                     loginFileDialogLoader.active = false;
0205                 }
0206                 onRejected: loginFileDialogLoader.active = false
0207                 Component.onCompleted: open()
0208             }
0209 
0210         }
0211 
0212         Loader {
0213             id: logoutFileDialogLoader
0214 
0215             active: false
0216 
0217             sourceComponent: FileDialog {
0218                 id: logoutFileDialog
0219 
0220                 title: i18n("Choose Logout Script")
0221                 currentFolder: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0]
0222                 onAccepted: {
0223                     kcm.model.addScript(logoutFileDialog.selectedFile, AutostartModel.PlasmaShutdown);
0224                     logoutFileDialogLoader.active = false;
0225                 }
0226                 onRejected: logoutFileDialogLoader.active = false
0227                 Component.onCompleted: open()
0228             }
0229         }
0230     }
0231 }