diff options
| -rw-r--r-- | desktop/modules/companion/ArtistsModule.qml | 67 | ||||
| -rw-r--r-- | desktop/modules/companion/PhrasesPage.qml | 19 | ||||
| -rw-r--r-- | desktop/shell.qml | 1 |
3 files changed, 81 insertions, 6 deletions
diff --git a/desktop/modules/companion/ArtistsModule.qml b/desktop/modules/companion/ArtistsModule.qml new file mode 100644 index 0000000..5bd53eb --- /dev/null +++ b/desktop/modules/companion/ArtistsModule.qml @@ -0,0 +1,67 @@ +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +import QtQuick +import "../.." +import "../../companion/Lines.js" as Lines + +// The lines the companion says when a track by an artist she knows starts, +// matched as a case-insensitive substring of the player's artist. Same +// draft, Save and Reset as PhrasesModule, on Prefs.companionArtists and +// Lines.artists; the page's cls field holds the artist. +Module { + id: am + name: "artists" + label: "Companion artists" + // nf-fa-music, present in Inconsolata Nerd Font. + icon: "" + settings: true + group: "Companion" + keywords: ["companion", "artist", "music", "song", "track", "line", "say", "2b"] + searchItems: am.shown.map((a, i) => ({ text: a.cls + ": " + a.lines.join(" / "), key: "app:" + i })) + + property var draft: null + property bool resetting: false + readonly property var shown: am.draft ?? Lines.appList(Prefs.companionArtists, Lines.artists) + readonly property bool valid: am.shown.every(a => String(a.cls).trim() !== "" + && (a.lines || []).some(l => String(l).trim() !== "")) + dirty: am.draft !== null + + function edit(list) { am.draft = list; am.resetting = false; } + function reset() { am.draft = Lines.appList(null, Lines.artists); am.resetting = true; } + function save() { + if (am.resetting) Prefs.resetCompanionArtists(); + else Prefs.setCompanionArtists(Lines.toMap(am.draft)); + am.discard(); + } + function discard() { am.draft = null; am.resetting = false; } + + page: Component { + Page { + title: "Companion artists" + actions: Component { + SaveBar { dirty: am.dirty; valid: am.valid; note: "every artist needs a name and a phrase" + onSave: am.save(); onDiscard: am.discard() } + } + PhrasesPage { + width: parent.width + owner: am + intro: "When a track by an artist she knows starts or changes, she says one of their lines at " + + "random, under her 30 s line cooldown. The name matches any part of the player's artist, " + + "ignoring case, so \"daft punk\" also catches \"Daft Punk, Pharrell Williams\". " + + "Save applies at once." + keyHint: "artist, e.g. linkin park" + addText: "Add artist" + saved: Prefs.companionArtists + } + } + } +} diff --git a/desktop/modules/companion/PhrasesPage.qml b/desktop/modules/companion/PhrasesPage.qml index 67c1e03..1971171 100644 --- a/desktop/modules/companion/PhrasesPage.qml +++ b/desktop/modules/companion/PhrasesPage.qml @@ -23,6 +23,15 @@ Column { // The module, holding the draft. Not named pm, its id (it would bind to // itself, AGENTS.md). required property QtObject owner + // What the cards are keyed by; the defaults are the app set's, so + // PhrasesModule passes nothing. + property string intro: "When focus moves to a program she recognizes, she says one of its lines at random, a third " + + "of the time and under her 30 s line cooldown. The class is Hyprland's window class, " + + "lowercased (hyprctl activewindow shows it). Save applies at once." + property string keyHint: "window class, e.g. firefox" + property string addText: "Add app" + // The saved set, for Reset's enabled state; null means the defaults. + property var saved: Prefs.companionApps readonly property var list: owner.shown // The app card awaiting a second click on Remove. property int confirming: -1 @@ -98,9 +107,7 @@ Column { Small { width: page.width wrapMode: Text.Wrap - text: "When focus moves to a program she recognizes, she says one of its lines at random, a third " - + "of the time and under her 30 s line cooldown. The class is Hyprland's window class, " - + "lowercased (hyprctl activewindow shows it). Save applies at once." + text: page.intro } Repeater { @@ -129,7 +136,7 @@ Column { Field { anchors { left: parent.left; right: del.left; rightMargin: 8; top: parent.top; bottom: parent.bottom } value: card.modelData.cls - placeholder: "window class, e.g. firefox" + placeholder: page.keyHint onEdited: t => page.setCls(card.index, t) } Button { @@ -177,11 +184,11 @@ Column { Row { spacing: 8 - Button { text: "Add app"; onClicked: page.addApp() } + Button { text: page.addText; onClicked: page.addApp() } Button { text: "Reset to defaults" danger: true - enabled: !page.owner.resetting && (Prefs.companionApps !== null || page.owner.dirty) + enabled: !page.owner.resetting && (page.saved !== null || page.owner.dirty) onClicked: page.owner.reset() } } diff --git a/desktop/shell.qml b/desktop/shell.qml index 1331673..35dbe3f 100644 --- a/desktop/shell.qml +++ b/desktop/shell.qml @@ -89,6 +89,7 @@ ShellRoot { IdleModule {}, CompanionModule {}, PhrasesModule {}, + ArtistsModule {}, NotificationsModule {}, AutostartModule {}, ObsScenesModule {}, |
