Skip to content

Commit

Permalink
feat: added more options for customising the user's light/dark appear…
Browse files Browse the repository at this point in the history
…ance preferences
  • Loading branch information
SadColourfulHues committed Mar 12, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent fc061a7 commit 23907e7
Showing 5 changed files with 199 additions and 85 deletions.
8 changes: 8 additions & 0 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
@@ -29,6 +29,14 @@
<label>Dark Theme</label>
<default>BreezeDark</default>
</entry>
<entry name="lightPlasmaTheme" type="String">
<label>Plasma Theme (Light)</label>
<default>breeze-light</default>
</entry>
<entry name="darkPlasmaTheme" type="String">
<label>Plasma Theme (Dark)</label>
<default>breeze-dark</default>
</entry>

<!-- BEHAVIOUR -->
<entry name="playVolumeFeedback" type="Bool">
5 changes: 4 additions & 1 deletion package/contents/ui/components/ColorSchemeSwitcher.qml
Original file line number Diff line number Diff line change
@@ -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);
}
}

29 changes: 29 additions & 0 deletions package/contents/ui/components/ConfigAppearanceComboBox.qml
Original file line number Diff line number Diff line change
@@ -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
}
}
79 changes: 79 additions & 0 deletions package/contents/ui/components/ConfigAppearanceDataSource.qml
Original file line number Diff line number Diff line change
@@ -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;
}
}
163 changes: 79 additions & 84 deletions package/contents/ui/config/configColorscheme.qml
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}

0 comments on commit 23907e7

Please sign in to comment.