Warning, /plasma/flatpak-kcm/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /**
0002  * SPDX-FileCopyrightText: 2022 Suhaas Joshi <joshiesuhaas0@gmail.com>
0003  * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Layouts 1.15
0009 import QtQuick.Controls 2.15 as QQC2
0010 import org.kde.kirigami 2.20 as Kirigami
0011 import org.kde.kcm 1.6 as KCM
0012 import org.kde.plasma.kcm.flatpakpermissions 1.0
0013 
0014 KCM.ScrollViewKCM {
0015     id: root
0016     title: i18n("Flatpak Applications")
0017     Kirigami.ColumnView.fillWidth: false
0018     implicitWidth: Kirigami.Units.gridUnit * 40
0019     implicitHeight: Kirigami.Units.gridUnit * 20
0020     framedView: false
0021 
0022     function changeApp() {
0023         let ref = null;
0024         const row = appsListView.currentIndex;
0025         if (row !== -1) {
0026             const m = kcm.refsModel;
0027             const index = m.index(row, 0);
0028             ref = m.data(m.index(row, 0), FlatpakReferencesModel.Ref);
0029         }
0030         kcm.pop()
0031         kcm.setIndex(row)
0032         kcm.push("permissions.qml", { ref })
0033     }
0034 
0035     Component.onCompleted: {
0036         kcm.columnWidth = Kirigami.Units.gridUnit * 15
0037         kcm.push("permissions.qml")
0038     }
0039 
0040     KCM.ConfigModule.buttons: KCM.ConfigModule.Apply | KCM.ConfigModule.Default
0041 
0042     Component {
0043         id: applyOrDiscardDialogComponent
0044 
0045         Kirigami.PromptDialog {
0046             id: dialog
0047 
0048             required property string applicationName
0049             required property url applicationIcon
0050 
0051             readonly property bool narrow: (parent.width - leftMargin - rightMargin) < Kirigami.Units.gridUnit * 20
0052 
0053             parent: root.Kirigami.ColumnView.view
0054             title: i18n("Apply Permissions")
0055             subtitle: i18n("The permissions of this application have been changed. Do you want to apply these changes or discard them?")
0056             standardButtons: QQC2.Dialog.Apply | QQC2.Dialog.Discard
0057 
0058             GridLayout {
0059                 columns: dialog.narrow ? 1 : 2
0060                 columnSpacing: Kirigami.Units.largeSpacing
0061                 rowSpacing: Kirigami.Units.largeSpacing
0062 
0063                 Kirigami.Icon {
0064                     source: dialog.applicationIcon
0065 
0066                     Layout.alignment: Qt.AlignCenter
0067                     Layout.preferredWidth: Kirigami.Units.iconSizes.large
0068                     Layout.preferredHeight: Kirigami.Units.iconSizes.large
0069                 }
0070                 Kirigami.SelectableLabel {
0071                     text: dialog.subtitle
0072                     wrapMode: QQC2.Label.Wrap
0073 
0074                     Layout.fillWidth: true
0075                     Layout.fillHeight: true
0076                 }
0077             }
0078 
0079             QQC2.Overlay.modal: KcmPopupModal {}
0080 
0081             onApplied: {
0082                 kcm.save()
0083                 root.changeApp()
0084                 dialog.close()
0085             }
0086 
0087             onDiscarded: {
0088                 kcm.load()
0089                 root.changeApp()
0090                 dialog.close()
0091             }
0092 
0093             onRejected: {
0094                 appsListView.currentIndex = kcm.currentIndex()
0095             }
0096 
0097             onClosed: destroy()
0098         }
0099     }
0100 
0101     view: ListView {
0102         id: appsListView
0103 
0104         model: kcm.refsModel
0105         currentIndex: -1
0106         delegate: Kirigami.BasicListItem {
0107 
0108             text: model.name
0109             icon: model.icon
0110 
0111             function shouldChange() {
0112                 if (index === kcm.currentIndex()) {
0113                     // Don't reload if it's current anyway.
0114                     return;
0115                 }
0116                 if (kcm.isSaveNeeded()) {
0117                     const m = kcm.refsModel;
0118                     const index = m.index(kcm.currentIndex(), 0);
0119                     const applicationName = m.data(index, FlatpakReferencesModel.Name);
0120                     const applicationIcon = m.data(index, FlatpakReferencesModel.Icon);
0121                     const dialog = applyOrDiscardDialogComponent.createObject(root, {
0122                         applicationName,
0123                         applicationIcon,
0124                     });
0125                     dialog.open();
0126                 } else {
0127                     root.changeApp()
0128                 }
0129             }
0130 
0131             onClicked: shouldChange()
0132         }
0133     }
0134 }
0135