|
| 1 | +import QtCore |
| 2 | +import QtQuick |
| 3 | +import QtQuick.Layouts |
| 4 | +import org.kde.kirigami as Kirigami |
| 5 | +import org.kde.plasma.components as PlasmaComponents |
| 6 | +import org.kde.plasma.extras as PlasmaExtras |
| 7 | +import org.kde.plasma.plasmoid |
| 8 | +import "../" |
| 9 | + |
| 10 | +ColumnLayout { |
| 11 | + id: popup |
| 12 | + property var main |
| 13 | + Layout.minimumWidth: Kirigami.Units.gridUnit * 25 |
| 14 | + Layout.minimumHeight: Kirigami.Units.gridUnit * 25 |
| 15 | + Layout.maximumWidth: Kirigami.Units.gridUnit * 25 |
| 16 | + Layout.maximumHeight: Kirigami.Units.gridUnit * 25 |
| 17 | + |
| 18 | + property string presetsDir: StandardPaths.writableLocation(StandardPaths.HomeLocation).toString().substring(7) + "/.config/panel-colorizer/presets" |
| 19 | + property string cratePresetsDirCmd: "mkdir -p " + presetsDir |
| 20 | + property string presetsBuiltinDir: Qt.resolvedUrl("../presets").toString().substring(7) + "/" |
| 21 | + property string toolsDir: Qt.resolvedUrl("../tools").toString().substring(7) + "/" |
| 22 | + property string listUserPresetsCmd: "'" + toolsDir + "list_presets.sh' '" + presetsDir + "'" |
| 23 | + property string listBuiltinPresetsCmd: "'" + toolsDir + "list_presets.sh' '" + presetsBuiltinDir + "' b" |
| 24 | + property string listPresetsCmd: listBuiltinPresetsCmd + ";" + listUserPresetsCmd |
| 25 | + |
| 26 | + ListModel { |
| 27 | + id: presetsModel |
| 28 | + } |
| 29 | + |
| 30 | + RunCommand { |
| 31 | + id: listPresets |
| 32 | + } |
| 33 | + |
| 34 | + Component.onCompleted: { |
| 35 | + listPresets.run(listPresetsCmd); |
| 36 | + } |
| 37 | + |
| 38 | + Connections { |
| 39 | + target: listPresets |
| 40 | + function onExited(cmd, exitCode, exitStatus, stdout, stderr) { |
| 41 | + if (exitCode !== 0) { |
| 42 | + console.error(cmd, exitCode, exitStatus, stdout, stderr); |
| 43 | + return; |
| 44 | + } |
| 45 | + if (cmd === popup.listPresetsCmd) { |
| 46 | + if (stdout.length === 0) |
| 47 | + return; |
| 48 | + const out = stdout.trim().split("\n"); |
| 49 | + for (const line of out) { |
| 50 | + let builtin = false; |
| 51 | + const parts = line.split(":"); |
| 52 | + const path = parts[parts.length - 1]; |
| 53 | + let name = path.split("/"); |
| 54 | + name = name[name.length - 1]; |
| 55 | + const dir = parts[1]; |
| 56 | + if (line.startsWith("b:")) { |
| 57 | + builtin = true; |
| 58 | + } |
| 59 | + presetsModel.append({ |
| 60 | + "name": name, |
| 61 | + "value": dir |
| 62 | + }); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + ColumnLayout { |
| 68 | + visible: popup.main.runningLatest |
| 69 | + PlasmaComponents.Label { |
| 70 | + text: i18n("Select a preset") |
| 71 | + Layout.fillWidth: true |
| 72 | + font.weight: Font.DemiBold |
| 73 | + Layout.leftMargin: Kirigami.Units.smallSpacing |
| 74 | + } |
| 75 | + |
| 76 | + ListView { |
| 77 | + id: listView |
| 78 | + clip: true |
| 79 | + // Layout.preferredWidth: Kirigami.Units.gridUnit * 10 |
| 80 | + // Layout.preferredHeight: Kirigami.Units.gridUnit * 12 |
| 81 | + Layout.fillWidth: true |
| 82 | + Layout.fillHeight: true |
| 83 | + model: presetsModel |
| 84 | + delegate: PlasmaComponents.ItemDelegate { |
| 85 | + id: presetDelegate |
| 86 | + width: ListView.view.width |
| 87 | + required property string name |
| 88 | + required property string value |
| 89 | + contentItem: RowLayout { |
| 90 | + spacing: Kirigami.Units.smallSpacing |
| 91 | + PlasmaComponents.Label { |
| 92 | + Layout.fillWidth: true |
| 93 | + text: presetDelegate.name |
| 94 | + textFormat: Text.PlainText |
| 95 | + elide: Text.ElideRight |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + onClicked: { |
| 100 | + popup.main.applyPreset(value); |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + ColumnLayout { |
| 107 | + visible: !popup.main.runningLatest |
| 108 | + PlasmaExtras.PlaceholderMessage { |
| 109 | + Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter |
| 110 | + Layout.margins: Kirigami.Units.gridUnit |
| 111 | + iconName: "dialog-warning" |
| 112 | + text: i18n("Running outdated version of %1", Plasmoid.metaData.name) |
| 113 | + } |
| 114 | + |
| 115 | + PlasmaComponents.Label { |
| 116 | + Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter |
| 117 | + Layout.margins: Kirigami.Units.gridUnit |
| 118 | + text: i18n("Running version of the widget (%1) is different to the one on disk (%2), please log out and back in (or restart plasmashell user unit) to ensure things work correctly!", Plasmoid.metaData.version, popup.main.localVersion.version) |
| 119 | + Layout.fillWidth: true |
| 120 | + wrapMode: Text.Wrap |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments