Warning, /plasma/plasma-mobile/shell/contents/configuration/AppletConfiguration.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
0002 // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 import QtQuick 2.15
0006 import QtQuick.Controls 2.15 as QQC2
0007 import QtQuick.Layouts 1.15
0008 import QtQuick.Window 2.15
0009 
0010 import org.kde.kirigami 2.19 as Kirigami
0011 import org.kde.plasma.configuration 2.0
0012 import org.kde.kitemmodels 1.0 as KItemModels
0013 
0014 Rectangle {
0015     id: root
0016     LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
0017     LayoutMirroring.childrenInherit: true
0018 
0019     color: "transparent"
0020 
0021 //BEGIN properties
0022     
0023     property bool isContainment: false
0024     property alias app: appLoader.item
0025     property bool loadApp: true
0026     
0027     signal appLoaded()
0028     
0029 //END properties
0030 
0031 //BEGIN model
0032 
0033     property ConfigModel globalConfigModel: globalAppletConfigModel
0034 
0035     ConfigModel {
0036         id: globalAppletConfigModel
0037     }
0038 
0039     KItemModels.KSortFilterProxyModel {
0040         id: configDialogFilterModel
0041         sourceModel: configDialog.configModel
0042         filterRowCallback: (row, parent) => {
0043             return sourceModel.data(sourceModel.index(row, 0), ConfigModel.VisibleRole);
0044         }
0045     }
0046     
0047 //END model
0048 
0049 //BEGIN functions
0050 
0051     function saveConfig() {
0052         if (app.pageStack.currentItem.saveConfig) {
0053             app.pageStack.currentItem.saveConfig()
0054         }
0055         for (var key in plasmoid.configuration) {
0056             if (app.pageStack.currentItem["cfg_"+key] !== undefined) {
0057                 plasmoid.configuration[key] = app.pageStack.currentItem["cfg_"+key]
0058             }
0059         }
0060     }
0061 
0062     function configurationHasChanged() {
0063         for (var key in plasmoid.configuration) {
0064             if (app.pageStack.currentItem["cfg_"+key] !== undefined) {
0065                 //for objects == doesn't work
0066                 if (typeof plasmoid.configuration[key] == 'object') {
0067                     for (var i in plasmoid.configuration[key]) {
0068                         if (plasmoid.configuration[key][i] != app.pageStack.currentItem["cfg_"+key][i]) {
0069                             return true;
0070                         }
0071                     }
0072                     return false;
0073                 } else if (app.pageStack.currentItem["cfg_"+key] != plasmoid.configuration[key]) {
0074                     return true;
0075                 }
0076             }
0077         }
0078         return false;
0079     }
0080 
0081 
0082     function settingValueChanged() {
0083         if (app.pageStack.currentItem.saveConfig !== undefined) {
0084             app.pageStack.currentItem.saveConfig();
0085         } else {
0086             root.saveConfig();
0087         }
0088     }
0089     
0090     function pushReplace(item, config) {
0091         let page;
0092         if (app.pageStack.depth === 0) {
0093             page = app.pageStack.push(item, config);
0094         } else {
0095             page = app.pageStack.replace(item, config);
0096         }
0097         app.currentConfigPage = page;
0098     }
0099     
0100     function open(item) {
0101         app.isAboutPage = false;
0102         if (item.source) {
0103             app.isAboutPage = item.source === "AboutPlugin.qml";
0104             pushReplace(Qt.resolvedUrl("ConfigurationAppletPage.qml"), {configItem: item, title: item.name});
0105         } else if (item.kcm) {
0106             pushReplace(configurationKcmPageComponent, {kcm: item.kcm, internalPage: item.kcm.mainUi});
0107         } else {
0108             app.pageStack.pop();
0109         }
0110     }
0111     
0112 //END functions
0113 
0114 
0115 //BEGIN connections
0116 
0117     Connections {
0118         target: root.Window.window
0119         function onVisibleChanged() {
0120             if (root.Window.window.visible) {
0121                 root.Window.window.showMaximized();
0122             }
0123         }
0124     }
0125     
0126 //END connections
0127 
0128 //BEGIN UI components
0129 
0130     Component {
0131         id: configurationKcmPageComponent
0132         ConfigurationKcmPage {}
0133     }
0134     
0135     Loader {
0136         id: appLoader
0137         anchors.fill: parent
0138         asynchronous: true
0139         active: root.loadApp
0140         onLoaded: {
0141             // if we are a containment then the first item will be ConfigurationContainmentAppearance
0142             // if the applet does not have own configs then the first item will be Shortcuts
0143             if (isContainment || !configDialog.configModel || configDialog.configModel.count === 0) {
0144                 root.open(root.globalConfigModel.get(0))
0145             } else {
0146                 root.open(configDialog.configModel.get(0))
0147             }
0148             
0149             root.appLoaded();
0150         }
0151         
0152         sourceComponent: Kirigami.ApplicationItem {
0153             id: app
0154             anchors.fill: parent
0155             
0156             // animation on show
0157             opacity: 0
0158             NumberAnimation on opacity {
0159                 to: 1
0160                 running: true
0161                 duration: Kirigami.Units.longDuration
0162                 easing.type: Easing.InOutQuad
0163             }
0164             
0165             pageStack.globalToolBar.canContainHandles: true
0166             pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar
0167             pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.ShowBackButton;
0168             
0169             property var currentConfigPage: null
0170             property bool isAboutPage: false
0171             
0172             // pop pages when not in use
0173             Connections {
0174                 target: app.pageStack
0175                 function onCurrentIndexChanged() {
0176                     // wait for animation to finish before popping pages
0177                     timer.restart();
0178                 }
0179             }
0180             
0181             Timer {
0182                 id: timer
0183                 interval: 300
0184                 onTriggered: {
0185                     let currentIndex = app.pageStack.currentIndex;
0186                     while (app.pageStack.depth > (currentIndex + 1) && currentIndex >= 0) {
0187                         app.pageStack.pop();
0188                     }
0189                 }
0190             }
0191 
0192             footer: Kirigami.NavigationTabBar {
0193                 id: footerBar
0194                 visible: count > 1
0195                 height: visible ? implicitHeight : 0
0196                 Repeater {
0197                     model: root.isContainment ? globalConfigModel : undefined
0198                     delegate: configCategoryDelegate
0199                 }
0200                 Repeater {
0201                     model: configDialogFilterModel
0202                     delegate: configCategoryDelegate
0203                 }
0204                 Repeater {
0205                     model: !root.isContainment ? globalConfigModel : undefined
0206                     delegate: configCategoryDelegate
0207                 }
0208             }
0209             
0210             Component {
0211                 id: configCategoryDelegate
0212                 Kirigami.NavigationTabButton {
0213                     icon.name: model.icon
0214                     text: model.name
0215                     width: footerBar.buttonWidth
0216                     recolorIcon: false
0217                     QQC2.ButtonGroup.group: footerBar.tabGroup
0218                     
0219                     onClicked: {
0220                         if (checked) {
0221                             root.open(model);
0222                         }
0223                     }
0224                     
0225                     checked: {
0226                         if (app.pageStack.currentItem) {
0227                             if (model.kcm && app.pageStack.currentItem.kcm) {
0228                                 return model.kcm == app.pageStack.currentItem.kcm;
0229                             } else if (app.pageStack.currentItem.configItem) {
0230                                 return model.source == app.pageStack.currentItem.configItem.source;
0231                             } else {
0232                                 return app.pageStack.currentItem.source == Qt.resolvedUrl(model.source);
0233                             }
0234                         }
0235                         return false;
0236                     }
0237                 }
0238             }
0239         }
0240     }
0241 //END UI components
0242 }
0243