Warning, /plasma/plasma-sdk/plasmoidviewer/qmlpackages/shell/contents/configuration/ConfigurationContainmentAppearance.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.0
0008 import org.kde.plasma.configuration 2.0
0009 import QtQuick.Controls 2.3 as QtControls
0010 import QtQuick.Layouts 1.1
0011 import QtQml 2.15
0012 
0013 import org.kde.newstuff 1.62 as NewStuff
0014 import org.kde.kirigami 2.20 as Kirigami
0015 import org.kde.plasma.plasmoid 2.0
0016 import org.kde.kcmutils
0017 
0018 AbstractKCM {
0019     id: root
0020     signal settingValueChanged
0021 
0022     property int formAlignment: wallpaperComboBox.Kirigami.ScenePosition.x - root.Kirigami.ScenePosition.x + Kirigami.Units.largeSpacing
0023     property string currentWallpaper: ""
0024     property string containmentPlugin: ""
0025 
0026     title: i18n("Appearance")
0027 
0028     function saveConfig() {
0029         if (main.currentItem.saveConfig) {
0030             main.currentItem.saveConfig()
0031         }
0032         for (var key in configDialog.wallpaperConfiguration) {
0033             if (main.currentItem["cfg_"+key] !== undefined) {
0034                 configDialog.wallpaperConfiguration[key] = main.currentItem["cfg_"+key]
0035             }
0036         }
0037         configDialog.currentWallpaper = root.currentWallpaper;
0038         configDialog.applyWallpaper()
0039         configDialog.containmentPlugin = root.containmentPlugin
0040     }
0041 
0042     ColumnLayout {
0043         anchors.fill: parent
0044         spacing: 0 // unless it's 0 there will be an additional gap between two FormLayouts
0045 
0046         Component.onCompleted: {
0047             for (var i = 0; i < configDialog.containmentPluginsConfigModel.count; ++i) {
0048                 var data = configDialog.containmentPluginsConfigModel.get(i);
0049                 if (configDialog.containmentPlugin === data.pluginName) {
0050                     pluginComboBox.currentIndex = i
0051                     pluginComboBox.activated(i);
0052                     break;
0053                 }
0054             }
0055 
0056             for (var i = 0; i < configDialog.wallpaperConfigModel.count; ++i) {
0057                 var data = configDialog.wallpaperConfigModel.get(i);
0058                 if (configDialog.currentWallpaper === data.pluginName) {
0059                     wallpaperComboBox.currentIndex = i
0060                     wallpaperComboBox.activated(i);
0061                     break;
0062                 }
0063             }
0064         }
0065 
0066         Kirigami.InlineMessage {
0067             visible: Plasmoid.immutable || animating
0068             text: i18nd("plasma_shell_org.kde.plasma.desktop", "Layout changes have been restricted by the system administrator")
0069             showCloseButton: true
0070             Layout.fillWidth: true
0071             Layout.leftMargin: Kirigami.Units.smallSpacing
0072             Layout.rightMargin: Kirigami.Units.smallSpacing
0073             Layout.bottomMargin: Kirigami.Units.smallSpacing * 2 // we need this because ColumnLayout's spacing is 0
0074         }
0075 
0076         Kirigami.FormLayout {
0077             id: parentLayout // needed for twinFormLayouts to work in wallpaper plugins
0078             twinFormLayouts: main.currentItem.formLayout
0079             Layout.fillWidth: true
0080             QtControls.ComboBox {
0081                 id: pluginComboBox
0082                 Layout.preferredWidth: Math.max(implicitWidth, wallpaperComboBox.implicitWidth)
0083                 Kirigami.FormData.label: i18nd("plasma_shell_org.kde.plasma.desktop", "Layout:")
0084                 enabled: !Plasmoid.immutable
0085                 model: configDialog.containmentPluginsConfigModel
0086                 implicitWidth: Kirigami.Units.gridUnit * 24
0087                 textRole: "name"
0088                 onActivated: {
0089                     var model = configDialog.containmentPluginsConfigModel.get(currentIndex)
0090                     root.containmentPlugin = model.pluginName
0091                     root.settingValueChanged()
0092                 }
0093             }
0094 
0095             RowLayout {
0096                 Layout.fillWidth: true
0097                 visible: !switchContainmentWarning.visible
0098                 Kirigami.FormData.label: i18nd("plasma_shell_org.kde.plasma.desktop", "Wallpaper Type:")
0099                 QtControls.ComboBox {
0100                     id: wallpaperComboBox
0101                     Layout.preferredWidth: Math.max(implicitWidth, pluginComboBox.implicitWidth)
0102                     model: configDialog.wallpaperConfigModel
0103                     implicitWidth: Kirigami.Units.gridUnit * 24
0104                     textRole: "name"
0105                     onActivated: {
0106                         var model = configDialog.wallpaperConfigModel.get(currentIndex)
0107                         root.currentWallpaper = model.pluginName
0108                         configDialog.currentWallpaper = model.pluginName
0109                         main.sourceFile = model.source
0110                         root.settingValueChanged()
0111                     }
0112                 }
0113                 NewStuff.Button {
0114                     configFile: "wallpaperplugin.knsrc"
0115                     text: i18nd("plasma_shell_org.kde.plasma.desktop", "Get New Plugins...")
0116                     Layout.preferredHeight: wallpaperComboBox.height
0117                 }
0118             }
0119         }
0120 
0121         ColumnLayout {
0122             id: switchContainmentWarning
0123             Layout.fillWidth: true
0124             visible: configDialog.containmentPlugin !== root.containmentPlugin
0125             QtControls.Label {
0126                 Layout.fillWidth: true
0127                 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Layout changes must be applied before other changes can be made")
0128                 wrapMode: Text.Wrap
0129                 horizontalAlignment: Text.AlignHCenter
0130             }
0131             QtControls.Button {
0132                 Layout.alignment: Qt.AlignHCenter
0133                 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Apply now")
0134                 onClicked: saveConfig()
0135             }
0136 
0137             Binding {
0138                 target: categoriesScroll //from parent scope AppletConfiguration
0139                 property: "enabled"
0140                 value: !switchContainmentWarning.visible
0141                 restoreMode: Binding.RestoreBinding
0142             }
0143         }
0144 
0145         Item {
0146             Layout.fillHeight: true
0147             visible: switchContainmentWarning.visible
0148         }
0149 
0150         Item {
0151             id: emptyConfig
0152         }
0153 
0154         QtControls.StackView {
0155             id: main
0156 
0157             Layout.fillHeight: true;
0158             Layout.fillWidth: true;
0159 
0160             visible: !switchContainmentWarning.visible
0161 
0162             // Bug 360862: if wallpaper has no config, sourceFile will be ""
0163             // so we wouldn't load emptyConfig and break all over the place
0164             // hence set it to some random value initially
0165             property string sourceFile: "tbd"
0166             onSourceFileChanged: {
0167                 if (sourceFile) {
0168                     var props = {}
0169 
0170                     var wallpaperConfig = configDialog.wallpaperConfiguration
0171                     for (var key in wallpaperConfig) {
0172                         props["cfg_" + key] = wallpaperConfig[key]
0173                     }
0174 
0175                     var newItem = replace(Qt.resolvedUrl(sourceFile), props)
0176 
0177                     for (var key in wallpaperConfig) {
0178                         var changedSignal = newItem["cfg_" + key + "Changed"]
0179                         if (changedSignal) {
0180                             changedSignal.connect(root.settingValueChanged)
0181                         }
0182                     }
0183                 } else {
0184                     replace(emptyConfig)
0185                 }
0186             }
0187         }
0188     }
0189 }