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