diff --git a/package/contents/config/main.xml b/package/contents/config/main.xml index fe8aad7..c485ae5 100644 --- a/package/contents/config/main.xml +++ b/package/contents/config/main.xml @@ -29,6 +29,14 @@ BreezeDark + + + breeze-light + + + + breeze-dark + diff --git a/package/contents/ui/components/ColorSchemeSwitcher.qml b/package/contents/ui/components/ColorSchemeSwitcher.qml index c2ea935..12376d6 100644 --- a/package/contents/ui/components/ColorSchemeSwitcher.qml +++ b/package/contents/ui/components/ColorSchemeSwitcher.qml @@ -39,9 +39,12 @@ Lib.CardButton { function swapColorScheme() { var usingDark = isDarkTheme(); var colorSchemeName = usingDark ? Plasmoid.configuration.lightTheme : Plasmoid.configuration.darkTheme; + var plasmaThemeName = usingDark ? Plasmoid.configuration.lightPlasmaTheme : Plasmoid.configuration.darkPlasmaTheme; + Plasmoid.configuration.isDarkTheme = !usingDark ? 1 : 0; - exec("plasma-apply-colorscheme " + colorSchemeName) + exec("plasma-apply-colorscheme " + colorSchemeName + + ";plasma-apply-desktoptheme " + plasmaThemeName); } } diff --git a/package/contents/ui/components/ConfigAppearanceComboBox.qml b/package/contents/ui/components/ConfigAppearanceComboBox.qml new file mode 100644 index 0000000..aad0290 --- /dev/null +++ b/package/contents/ui/components/ConfigAppearanceComboBox.qml @@ -0,0 +1,29 @@ +import QtQml +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + + +ComboBox { + property bool isChangeAvailable: false + property string lastText: "" + + Layout.column: 1 + Layout.minimumWidth: 300 + + onCurrentTextChanged: { + if (!isChangeAvailable) + return; + + lastText = currentText; + } + + // Functions // + + function configure(model) { + this.model = model + + this.currentIndex = this.find(lastText); + this.isChangeAvailable = true + } +} \ No newline at end of file diff --git a/package/contents/ui/components/ConfigAppearanceDataSource.qml b/package/contents/ui/components/ConfigAppearanceDataSource.qml new file mode 100644 index 0000000..fd2070c --- /dev/null +++ b/package/contents/ui/components/ConfigAppearanceDataSource.qml @@ -0,0 +1,79 @@ +import QtQuick +import org.kde.plasma.plasma5support as PlasmaCore + + +PlasmaCore.DataSource { + engine: "executable" + connectedSources: [] + + enum ItemType { + Unknown, + ColourThemes, + PlasmaThemes + } + + property int lastItemType: ConfigAppearanceDataSource.ItemType.Unknown + property var typesToFetch: [] + + signal itemsReady(var items, var itemType) + + onNewData: (sourceName, data) => { + disconnectSource(sourceName); // cmd finished + + if (lastItemType == ConfigAppearanceDataSource.ItemType.Unknown) + return; + + itemsReady(parseCommandOutput(data), lastItemType); + processNextFetchRequest(); + } + + // Functions // + + function getItems() { + // TODO: Find a better way of doing this + typesToFetch = [ + ConfigAppearanceDataSource.ItemType.ColourThemes, + ConfigAppearanceDataSource.ItemType.PlasmaThemes + ]; + + processNextFetchRequest(); + } + + function getItemsForType(itemType) { + if (itemType == ConfigAppearanceDataSource.ItemType.Unknown) { + processNextFetchRequest(); + return; + } + + this.lastItemType = itemType; + + switch (itemType) { + case ConfigAppearanceDataSource.ItemType.ColourThemes: + connectSource("plasma-apply-colorscheme --list-schemes | tail --lines=+2"); + break; + + case ConfigAppearanceDataSource.ItemType.PlasmaThemes: + connectSource("plasma-apply-desktoptheme --list-themes | tail --lines=+2"); + break; + } + } + + function processNextFetchRequest() { + if (typesToFetch.length < 1) + return; + + getItemsForType(typesToFetch.pop()); + } + + function parseCommandOutput(data) { + var items = data["stdout"].split("\n"); + + for (var i = 0; i < items.length; i++) { + items[i] = items[i] + .substring(3) + .split(" ")[0]; + } + + return items; + } +} \ No newline at end of file diff --git a/package/contents/ui/config/configColorscheme.qml b/package/contents/ui/config/configColorscheme.qml index 757e52e..4940f12 100644 --- a/package/contents/ui/config/configColorscheme.qml +++ b/package/contents/ui/config/configColorscheme.qml @@ -2,118 +2,113 @@ import QtQml import QtQuick import QtQuick.Controls import QtQuick.Layouts -import org.kde.plasma.plasma5support as PlasmaCore -import org.kde.plasma.extras as PlasmaExtras import org.kde.kcmutils as KCM -KCM.SimpleKCM { - property alias cfg_lightTheme: labelA.text // labels to store previous choices (ComboBox doesn't like to do it by itself) - property alias cfg_darkTheme: labelB.text // labels to store previous choices (ComboBox doesn't like to do it by itself) - - PlasmaCore.DataSource { - id: executable - engine: "executable" - connectedSources: [] +import "../components" +import "../js/funcs.js" as Funcs - signal colorsListReady(var colors) - function exec(cmd) { - connectSource(cmd) - } +KCM.SimpleKCM { + property alias cfg_lightTheme: cboxLightColour.lastText + property alias cfg_darkTheme: cboxDarkColour.lastText + property alias cfg_lightPlasmaTheme: cboxLightPlasma.lastText + property alias cfg_darkPlasmaTheme: cboxDarkPlasma.lastText - onNewData: { - var colors = data["stdout"].split("\n") - console.log(colors) - for (var i = 0; i < colors.length; i++) // parse command output - colors[i] = colors[i].substring(3).split(" ")[0] - colorsListReady(colors) - disconnectSource(sourceName) // cmd finished - } + ColumnLayout { + GridLayout { + columns: 2 - } + Label { + text: i18n("Colour Theme") + font.bold: true + Layout.row: 0 + } - // Copies of the last saved ComboBox entries. - Label { - id: labelA - visible: false - } - Label { - id: labelB - visible: false - } + // Light Colour Selection + Label { + text: i18n("Light") - function setText(comboBox, text) { // comboboxes don't really allow to set current entry by text => manually search for them - var found = false - for (var colorIndex = 0; colorIndex < comboBox.count; colorIndex++) { - if (comboBox.currentText === text) { - found = true - break + Layout.row: 1 + Layout.column: 0 } - comboBox.incrementCurrentIndex() - } - if (!found) - console.log("Color not found (perhaps it has been removed?).") - } - Connections { - target: executable - onColorsListReady: { - cBoxA.model = colors - cBoxB.model = colors - // look for color in list - setText(cBoxA, labelA.text) - setText(cBoxB, labelB.text) - // enable changes user just after everything is set up - cBoxA.isChangeAvailable = true - cBoxB.isChangeAvailable = true - } - } + ConfigAppearanceComboBox { + id: cboxLightColour + Layout.row: 1 + } - ColumnLayout { - GridLayout { - columns: 2 + // Dark Colour selection Label { - Layout.row :0 + text: i18n("Dark") + + Layout.row: 2 Layout.column: 0 - text: i18n("Light color") } - ComboBox { - id: cBoxA - property bool isChangeAvailable: false + ConfigAppearanceComboBox { + id: cboxDarkColour + Layout.row: 2 + } - Layout.row: 0 - Layout.column: 1 - Layout.minimumWidth: 300 - onCurrentTextChanged: { - if (isChangeAvailable) - labelA.text = currentText - } + Label { + text: i18n("Plasma Theme") + font.bold: true + Layout.row: 3 } + // Light plasma theme selection Label { - Layout.row :1 + text: i18n("Light") + + Layout.row: 4 Layout.column: 0 - text: i18n("Dark color") } - ComboBox { - id: cBoxB - property bool isChangeAvailable: false + ConfigAppearanceComboBox { + id: cboxLightPlasma + Layout.row: 4 + } - Layout.row: 1 - Layout.column: 1 - Layout.minimumWidth: 300 + // Dark plasma theme selection + Label { + text: i18n("Dark") - onCurrentTextChanged: { - if (isChangeAvailable) - labelB.text = currentText - } + Layout.row: 5 + Layout.column: 0 + } + + ConfigAppearanceComboBox { + id: cboxDarkPlasma + Layout.row: 5 } } } Component.onCompleted: { - executable.exec("plasma-apply-colorscheme --list-schemes | tail --lines=+2") + dataSource.getItems(); + } + + // Components // + + ConfigAppearanceDataSource { + id: dataSource + } + + Connections { + target: dataSource + + onItemsReady: (items, itemType) => { + switch (itemType) { + case ConfigAppearanceDataSource.ItemType.ColourThemes: + cboxLightColour.configure(items); + cboxDarkColour.configure(items); + break; + + case ConfigAppearanceDataSource.ItemType.PlasmaThemes: + cboxLightPlasma.configure(items); + cboxDarkPlasma.configure(items); + break; + } + } } }