diff --git a/qml/Main.qml b/qml/Main.qml index 03ee073..d3e993c 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -31,17 +31,41 @@ MainView { } } + property real musicVolume: 0.5 + property real crackVolume: 1.0 + + // Funktionen zum Setzen der Lautstärke + function setMusicVolume(volume) { + root.musicVolume = volume; + py.call("fortunecookie.set_music_volume", [volume]); + } + + function setCrackVolume(volume) { + root.crackVolume = volume; + py.call("fortunecookie.set_crack_volume", [volume]); + } + + function reloadFortune() { + currentFortune = py.call_sync("fortunecookie.get_current_fortune", []); + currentFortuneLabel.text = currentFortune; + if (fortuneOpened) { + currentFortuneLabel.visible = true; + } + } + MediaPlayer { id: mediaPlayer + objectName: "mediaPlayer" source: Qt.resolvedUrl("../assets/chinese_music.mp3") loops: MediaPlayer.Infinite - volume: 0.5 + volume: root.musicVolume } MediaPlayer { id: crackMediaPlayer + objectName: "crackMediaPlayer" source: Qt.resolvedUrl("../assets/cookie_crack.mp3") - volume: 1.0 + volume: root.crackVolume } // ==================================================================== @@ -95,11 +119,11 @@ MainView { mediaPlayer.play(); } - // Volumes laden und setzen + // Volumes laden und Properties setzen var musicVol = py.call_sync("fortunecookie.get_music_volume", []); var crackVol = py.call_sync("fortunecookie.get_crack_volume", []); - mediaPlayer.volume = musicVol; - crackMediaPlayer.volume = crackVol; + root.musicVolume = musicVol; + root.crackVolume = crackVol; appInitialized = true; @@ -201,8 +225,8 @@ MainView { bottom: parent.bottom margins: units.gu(2) } - width: units.gu(10) - height: units.gu(10) + width: units.gu(14) + height: units.gu(14) text: musicPlaying ? "\uD83D\uDD0A" : "\uD83D\uDD07" fontSize: "xx-large" horizontalAlignment: Text.AlignHCenter diff --git a/qml/Settings.qml b/qml/Settings.qml index 7efce8e..b89fd7e 100644 --- a/qml/Settings.qml +++ b/qml/Settings.qml @@ -36,13 +36,15 @@ Page { musicVolumeSlider.value = musicVolume; crackVolumeSlider.value = crackVolume; - // Spruchlisten ComboBox füllen - var lists = py.call_sync("fortunecookie.get_fortune_lists", []); + // Spruchlisten ComboBox füllen (mit Beschreibungen und Anzahl) + var lists = py.call_sync("fortunecookie.get_fortune_lists_with_description", []); fortuneListCombo.model = lists; - // Aktuelle Liste auswählen + // Aktuelle Liste auswählen (vergleiche nur den Listennamen, nicht die Beschreibung) for (var i = 0; i < fortuneListCombo.count; i++) { - if (fortuneListCombo.textAt(i) === currentFortuneList) { + var text = fortuneListCombo.textAt(i); + var listName = text.split(" - ")[0]; + if (listName === currentFortuneList) { fortuneListCombo.currentIndex = i; break; } @@ -56,15 +58,38 @@ Page { } } + // SPRUCHLISTEN-AUSWAHL + // ============================================================ + + Label { + text: "Spruchliste:" + Layout.fillWidth: true + fontSize: "large" + } +======= ColumnLayout { anchors.fill: parent anchors.margins: units.gu(2) spacing: units.gu(2) + // Spacer für Header + Item { + Layout.fillWidth: true + Layout.preferredHeight: units.gu(2) + } + // ============================================================ // SPRUCHLISTEN-AUSWAHL // ============================================================ + Label { + text: "Spruchliste:" + Layout.fillWidth: true + fontSize: "large" + }============================================================ + // SPRUCHLISTEN-AUSWAHL + // ============================================================ + Label { text: "Spruchliste:" Layout.fillWidth: true @@ -77,9 +102,12 @@ Page { Layout.preferredHeight: units.gu(8) onActivated: { - var newList = fortuneListCombo.currentText; + var newListFull = fortuneListCombo.currentText; + // Extrahiere den Listennamen (Teil vor " - ") + var newList = newListFull.split(" - ")[0]; py.call("fortunecookie.set_fortune_list", [newList], function() { - console.log("Spruchliste gewaehlt: " + newList); + console.log("Spruchliste gewählt: " + newList); + root.reloadFortune(); }); } } @@ -108,7 +136,7 @@ Page { onValueChanged: { var volume = musicVolumeSlider.value; - py.call("fortunecookie.set_music_volume", [volume]); + root.setMusicVolume(volume); musicVolumeLabel.text = Math.round(volume * 100) + "%"; } } @@ -146,7 +174,7 @@ Page { onValueChanged: { var volume = crackVolumeSlider.value; - py.call("fortunecookie.set_crack_volume", [volume]); + root.setCrackVolume(volume); crackVolumeLabel.text = Math.round(volume * 100) + "%"; } } diff --git a/src/fortunecookie.py b/src/fortunecookie.py index 244317f..c05e0d1 100644 --- a/src/fortunecookie.py +++ b/src/fortunecookie.py @@ -260,6 +260,22 @@ def get_fortune_lists(): return AVAILABLE_FORTUNE_LISTS +def get_fortune_lists_with_description(): + """Gibt die Liste mit Beschreibungen und Anzahl zurück.""" + _init() + result = [] + descriptions = { + "fortune": "Glückskeks-Sprüche", + "farmer wisdom": "Bauernweisheiten", + "UNfortune": "Darkside-Sprüche" + } + for list_name in AVAILABLE_FORTUNE_LISTS: + count = len(_fortunes.get(list_name, [])) + desc = descriptions.get(list_name, list_name) + result.append(f"{list_name} - {desc} ({count})") + return result + + def get_current_fortune_list(): """Gibt den Namen der aktuellen Spruchliste zurück.""" _init()