/*SPDX-FileCopyrightText: 2026 Ramil Nurmanov <ramil2004nur@gmail.com>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport QtQuick.Controls as QQC2import QtQuick.Layoutsimport org.kde.kirigami as Kirigamiimport org.kde.kcmutils as KCMimport org.kde.plasma.plasmoidKCM.AbstractKCM {id: layoutRootsignal configurationChangedleftPadding: 0rightPadding: 0topPadding: 0bottomPadding: 0readonly property string desktopPlugin: "org.kde.desktopcontainment"readonly property string folderPlugin: "org.kde.plasma.folder"readonly property bool onlyDefaultPlugins: {const model = configDialog.containmentPluginsConfigModelif (model.count !== 2) {return false}const plugins = [model.get(0).pluginName, model.get(1).pluginName]return plugins.includes(desktopPlugin) && plugins.includes(folderPlugin)}property string selectedPlugin: configDialog.containmentPluginreadonly property bool pluginChanged: selectedPlugin !== configDialog.containmentPluginreadonly property string containmentPageSource: configDialog.configModel?.layoutConfigSource ?? ""readonly property bool containmentPageShown: onlyDefaultPlugins|| (!pluginChanged && configDialog.containmentPlugin !== desktopPlugin)property bool containmentPageChanged: falseproperty bool unsavedChanges: falsefunction saveConfig() {const page = containmentPage.itemif (page) {if (page.saveConfig) {page.saveConfig()}const config = Plasmoid.configurationconfig.keys().forEach(key => {const cfgKey = "cfg_" + keyif (cfgKey in page) {config[key] = page[cfgKey]}})config.writeConfig()}layoutRoot.containmentPageChanged = falseconfigDialog.containmentPlugin = layoutRoot.selectedPluginlayoutRoot.checkUnsavedChanges()}function checkUnsavedChanges() {const page = containmentPage.itemconst config = Plasmoid.configurationconst pageChanged = page !== null && (layoutRoot.containmentPageChanged || (page.unsavedChanges ?? false) || config.keys().some(key => {const cfgKey = "cfg_" + keyif (!(cfgKey in page)) {return false}return page[cfgKey] != config[key] &&page[cfgKey].toString() != config[key].toString()}))layoutRoot.unsavedChanges = layoutRoot.pluginChanged || pageChanged}onPluginChangedChanged: checkUnsavedChanges()ColumnLayout {anchors.fill: parentspacing: 0Kirigami.InlineMessage {visible: Plasmoid.immutable || animatingtext: i18ndc("plasma_shell_org.kde.plasma.desktop", "@info:status inlinemessage", "Layout changes have been restricted by the system administrator")showCloseButton: trueLayout.fillWidth: trueLayout.margins: Kirigami.Units.smallSpacing}Kirigami.FormAlignmentGroup {id: formAlignmentGroup}Kirigami.Form {Kirigami.FormAlignmentGroup.group: formAlignmentGroupLayout.fillWidth: trueLayout.margins: Kirigami.Units.largeSpacingKirigami.FormGroup {Kirigami.FormEntry {visible: layoutRoot.onlyDefaultPluginstitle: i18ndc("plasma_shell_org.kde.plasma.desktop", "@label", "Desktop:")subtitle: i18ndc("plasma_shell_org.kde.plasma.desktop", "@info", "Icons for items in the selected location appear on the desktop")contentItem: QQC2.CheckBox {enabled: !Plasmoid.immutabletext: i18ndc("plasma_shell_org.kde.plasma.desktop", "@option:check", "Show files and folders")checked: layoutRoot.selectedPlugin === layoutRoot.folderPluginonToggled: layoutRoot.selectedPlugin = checked ? layoutRoot.folderPlugin : layoutRoot.desktopPlugin}}Kirigami.FormEntry {visible: !layoutRoot.onlyDefaultPluginstitle: i18ndc("plasma_shell_org.kde.plasma.desktop", "@label:listbox", "Layout:")contentItem: QQC2.ComboBox {enabled: !Plasmoid.immutablemodel: configDialog.containmentPluginsConfigModeltextRole: "name"valueRole: "pluginName"onActivated: layoutRoot.selectedPlugin = currentValueComponent.onCompleted: currentIndex = indexOfValue(configDialog.containmentPlugin)}}}}Loader {id: containmentPageLayout.fillWidth: trueLayout.fillHeight: truevisible: item !== null && layoutRoot.containmentPageShownComponent.onCompleted: {if (layoutRoot.containmentPageSource === "") {return}const config = Plasmoid.configurationconst props = {}const temp = Qt.createComponent(layoutRoot.containmentPageSource).createObject(layoutRoot)config.keys().forEach(key => {const cfgKey = "cfg_" + keyif (cfgKey in temp) {props[cfgKey] = config[key]}})if ("formAlignmentGroup" in temp) {props.formAlignmentGroup = formAlignmentGroup}temp.destroy()setSource(layoutRoot.containmentPageSource, props)}onLoaded: {const content = item.flickable?.contentItem ?? itemcontent.enabled = Qt.binding(() => !Plasmoid.immutable && layoutRoot.selectedPlugin !== layoutRoot.desktopPlugin)Plasmoid.configuration.keys().forEach(key => {const changedSignal = item["cfg_" + key + "Changed"]if (changedSignal) {changedSignal.connect(layoutRoot.checkUnsavedChanges)}})if (item.configurationChanged) {item.configurationChanged.connect(() => {layoutRoot.containmentPageChanged = truelayoutRoot.checkUnsavedChanges()layoutRoot.configurationChanged()})}if (item.unsavedChangesChanged) {item.unsavedChangesChanged.connect(layoutRoot.checkUnsavedChanges)}layoutRoot.checkUnsavedChanges()}}Item {id: switchContainmentWarningLayout.fillWidth: trueLayout.fillHeight: truevisible: !layoutRoot.onlyDefaultPlugins && layoutRoot.pluginChangedKirigami.PlaceholderMessage {width: parent.width - Kirigami.Units.largeSpacing * 8anchors.centerIn: parenticon.name: "documentinfo"text: i18ndc("plasma_shell_org.kde.plasma.desktop", "@info", "Layout changes must be applied before other changes can be made")helpfulAction: QQC2.Action {icon.name: "dialog-ok-apply"text: i18ndc("plasma_shell_org.kde.plasma.desktop", "@action:button", "Apply Now")onTriggered: layoutRoot.saveConfig()}}}Item {visible: !containmentPage.visible && !switchContainmentWarning.visibleLayout.fillHeight: true}}}