Warning, /plasma/plasma-workspace/kcms/wallpaper/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de> 0004 SPDX-FileCopyrightText: 2019 David Redondo <kde@david-redondo.de> 0005 SPDX-FileCopyrightText: 2023 Méven Car <meven@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 import QtQuick 0011 import QtQuick.Controls as QQC2 0012 import QtQuick.Layouts 0013 import QtQml 0014 0015 import org.kde.newstuff as NewStuff 0016 import org.kde.kirigami as Kirigami 0017 0018 import org.kde.kcmutils as KCM 0019 0020 import org.kde.plasma.kcm.wallpaper 0021 import org.kde.plasma.configuration 2.0 0022 0023 KCM.SimpleKCM { 0024 id: appearanceRoot 0025 0026 signal configurationChanged 0027 0028 property alias parentLayout: parentLayout 0029 0030 implicitWidth: Kirigami.Units.gridUnit * 15 0031 implicitHeight: Kirigami.Units.gridUnit * 30 0032 0033 actions: [ 0034 Kirigami.Action { 0035 id: allScreensAction 0036 text: i18nc("@option:check Set the wallpaper for all screens","Set for all screens") 0037 visible: kcm.screens.length > 1 0038 checkable: true 0039 checked: kcm.allScreens 0040 onTriggered: kcm.allScreens = checked 0041 displayComponent: QQC2.Switch { 0042 text: allScreensAction.text 0043 checked: allScreensAction.checked 0044 visible: allScreensAction.visible 0045 onToggled: allScreensAction.trigger() 0046 } 0047 } 0048 ] 0049 0050 function onConfigurationChanged() { 0051 for (var key in kcm.configuration) { 0052 const cfgKey = "cfg_" + key; 0053 if (main.currentItem[cfgKey] !== undefined) { 0054 kcm.configuration[key] = main.currentItem[cfgKey] 0055 } 0056 } 0057 } 0058 0059 ColumnLayout { 0060 anchors.fill: parent 0061 0062 ScreenView { 0063 visible: !kcm.allScreens && kcm.screens.length > 1 0064 0065 Layout.fillWidth: true; 0066 implicitHeight: Kirigami.Units.gridUnit * 10 0067 0068 outputs: kcm.screens 0069 selectedScreen: kcm.selectedScreen 0070 0071 onScreenSelected: (screenName) => { kcm.setSelectedScreen(screenName) } 0072 } 0073 0074 Kirigami.FormLayout { 0075 id: parentLayout // needed for twinFormLayouts to work in wallpaper plugins 0076 Layout.fillWidth: true 0077 0078 RowLayout { 0079 Layout.fillWidth: true 0080 Kirigami.FormData.label: i18nd("plasma_shell_org.kde.plasma.desktop", "Wallpaper type:") 0081 0082 QQC2.ComboBox { 0083 id: wallpaperComboBox 0084 model: kcm.wallpaperConfigModel 0085 textRole: "name" 0086 onActivated: { 0087 var pluginName = kcm.wallpaperConfigModel.data(kcm.wallpaperConfigModel.index(currentIndex, 0), ConfigModel.PluginNameRole) 0088 if (appearanceRoot.currentWallpaper === pluginName) { 0089 return; 0090 } 0091 kcm.currentWallpaper = pluginName 0092 } 0093 0094 KCM.SettingHighlighter { 0095 highlight: kcm.currentWallpaper !== "org.kde.image" 0096 } 0097 } 0098 NewStuff.Button { 0099 configFile: "wallpaperplugin.knsrc" 0100 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Get New Plugins…") 0101 visibleWhenDisabled: true // don't hide on disabled 0102 Layout.preferredHeight: wallpaperComboBox.height 0103 } 0104 } 0105 } 0106 0107 Item { 0108 id: emptyConfig 0109 } 0110 0111 QQC2.StackView { 0112 id: main 0113 0114 Layout.fillHeight: true; 0115 Layout.fillWidth: true; 0116 0117 Connections { 0118 target: kcm 0119 function onCurrentWallpaperChanged () { main.loadSourceFile() } 0120 function onSelectedScreenChanged () { main.onScreenChanged() } 0121 0122 function onConfigurationChanged() { main.onWallpaperConfigurationChanged() } 0123 0124 function onSettingsSaved() { main.currentItem.saveConfig(); } 0125 } 0126 0127 function onWallpaperConfigurationChanged() { 0128 let wallpaperConfig = kcm.configuration 0129 wallpaperConfig.keys().forEach(key => { 0130 const cfgKey = "cfg_" + key; 0131 if (cfgKey in main.currentItem) { 0132 0133 var changedSignal = main.currentItem[cfgKey + "Changed"] 0134 if (changedSignal) { 0135 changedSignal.disconnect(appearanceRoot.onConfigurationChanged); 0136 } 0137 main.currentItem[cfgKey] = wallpaperConfig[key]; 0138 0139 changedSignal = main.currentItem[cfgKey + "Changed"] 0140 if (changedSignal) { 0141 changedSignal.connect(appearanceRoot.onConfigurationChanged) 0142 } 0143 } 0144 }) 0145 } 0146 0147 function onScreenChanged() { 0148 if (!main.currentItem) { 0149 main.loadSourceFile(); 0150 return ; 0151 } 0152 main.currentItem.screen = kcm.selectedScreen; 0153 } 0154 0155 function loadSourceFile() { 0156 for (var i = 0; i < kcm.wallpaperConfigModel.count; ++i) { 0157 var pluginName = kcm.wallpaperConfigModel.data(kcm.wallpaperConfigModel.index(i, 0), ConfigModel.PluginNameRole) 0158 if (kcm.currentWallpaper === pluginName) { 0159 wallpaperComboBox.currentIndex = i; 0160 break; 0161 } 0162 } 0163 0164 const wallpaperConfig = kcm.configuration; 0165 const wallpaperPluginSource = kcm.wallpaperPluginSource 0166 // BUG 407619: wallpaperConfig can be null before calling `ContainmentItem::loadWallpaper()` 0167 if (wallpaperConfig && wallpaperPluginSource) { 0168 var props = { 0169 "configDialog": kcm, 0170 "screen": kcm.selectedScreen, 0171 "wallpaperConfiguration": wallpaperConfig 0172 }; 0173 0174 wallpaperConfig.keys().forEach(key => { 0175 // Preview is not part of the config, only of the WallpaperObject 0176 if (!key.startsWith("Preview")) { 0177 props["cfg_" + key] = wallpaperConfig[key]; 0178 } 0179 }); 0180 0181 var newItem = replace(Qt.resolvedUrl(wallpaperPluginSource), props) 0182 0183 wallpaperConfig.keys().forEach(key => { 0184 const cfgKey = "cfg_" + key; 0185 if (cfgKey in main.currentItem) { 0186 var changedSignal = main.currentItem[cfgKey + "Changed"] 0187 if (changedSignal) { 0188 changedSignal.connect(appearanceRoot.onConfigurationChanged) 0189 } 0190 } 0191 }); 0192 0193 const configurationChangedSignal = newItem.configurationChanged 0194 if (configurationChangedSignal) { 0195 configurationChangedSignal.connect(appearanceRoot.onConfigurationChanged) 0196 } 0197 } else { 0198 replace(emptyConfig) 0199 } 0200 } 0201 } 0202 } 0203 0204 }