Files
qbz/crates/qbz-ui/ui/discover/DiscoverConfigModal.slint
T
vicrodh be487dca4c feat(slint): work grouping, ru/ja locales, About + What's New + Discover reco modal
- Album view: classical "work" section grouping (PR #536 port) — new
  Track.work model field + run-length per-work headers in AlbumView.
- i18n: add Russian + Japanese locales (1365 msgids each); extend plural.rs
  (ru 3-form one/few/many, ja single-form) + tests; fix the language-selector
  reseed (main.rs set_languages + ui_prefs index maps). Seven languages total.
- About modal: native port of the Tauri About (version, links, build info,
  one-paragraph acknowledgments, inline contributors with GitHub avatars,
  signature). Contributors credit hoyon (PR #536) and mxnix (PR #517, ru).
- What's New modal: renders the GitHub release-tag description (markdown
  sections + TOC); release fetch + build.rs emits build date/commit.
- Discover Recommendations: move Cache window + Refresh now into the Customize
  modal, gated to the reco tab; hide the section-config UI there; add an
  explainer paragraph. New strings translated to all six non-English locales.
- About modal width +120px; splash screen gains the legal disclaimer footer.

cc
2026-06-29 22:55:17 -06:00

371 lines
16 KiB
Plaintext

// Discover section configurator (Slice 5) — the per-tab "Customize" modal:
// reorder + show/hide the active tab's Discover sections, with a perf-warning
// banner, an enabled/total count, and a Reset-to-defaults footer. No Save
// button — every toggle / move / reset persists live (the controller re-pushes
// config-rows immediately, so the list stays authoritative).
//
// Reuses the codebase modal idiom (self-contained Rectangle, full-window scrim +
// centered panel; mounted LAST in AppShell so declaration order = top z-stack,
// satisfying ADR-009 >= 3000 structurally). There is NO shared Modal component.
//
// Labels are resolved in Rust (DiscoverState.config-rows[].label) — Slint @tr
// needs a literal key and the gettext pipeline is unwired, so section labels are
// English strings (consistent with every other Slint section title). The modal's
// own chrome strings use @tr literals (passthrough today).
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { DiscoverState, DiscoverActions, ConfigRow, ExternalRecoState, ExternalRecoActions } from "../state.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { QbzCheckbox } from "../primitives/QbzCheckbox.slint";
import { QbzSelect } from "../primitives/QbzSelect.slint";
// A 28x28 ghost reorder button (chevron up / down). Dims + drops the pointer
// cursor at the list boundary.
component ReorderButton inherits Rectangle {
in property <image> glyph;
in property <bool> button-enabled: true;
callback clicked();
width: 28px;
height: 28px;
border-radius: Radius.sm;
opacity: root.button-enabled ? 1.0 : 0.3;
background: (root.button-enabled && ta.has-hover) ? Theme.surface-hover : transparent;
QbzIcon {
source: root.glyph;
width: 16px;
height: 16px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: Theme.text-secondary;
}
ta := TouchArea {
mouse-cursor: root.button-enabled ? pointer : default;
enabled: root.button-enabled;
clicked => {
root.clicked();
}
}
}
// One configurator row: [checkbox] [label (stretch)] [up] [down].
component ConfigRowView inherits Rectangle {
in property <ConfigRow> entry; // NOT `row`: `row` is a reserved Slint grid attached-property
in property <int> index;
in property <int> last-index;
in property <string> tab;
height: 40px;
border-radius: Radius.sm;
background: row-ta.has-hover ? Theme.surface-hover : transparent;
// Whole-row tap toggles (primary affordance). The checkbox below also
// toggles; the Rust re-push of config-rows re-asserts truth either way.
row-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
DiscoverActions.toggle-section(root.tab, root.entry.id);
}
}
HorizontalLayout {
padding-left: 10px;
padding-right: 6px;
spacing: 12px;
VerticalLayout {
alignment: center;
QbzCheckbox {
checked: root.entry.enabled;
toggled => {
DiscoverActions.toggle-section(root.tab, root.entry.id);
}
}
}
Text {
text: root.entry.label;
color: root.entry.enabled ? Theme.text-primary : Theme.text-muted;
font-size: Typography.body;
font-weight: Typography.medium;
vertical-alignment: center;
horizontal-stretch: 1;
}
VerticalLayout {
alignment: center;
ReorderButton {
glyph: @image-url("../assets/icons/chevron-up.svg");
button-enabled: root.index > 0;
clicked => {
DiscoverActions.move-section(root.tab, root.entry.id, -1);
}
}
}
VerticalLayout {
alignment: center;
ReorderButton {
glyph: @image-url("../assets/icons/chevron-down.svg");
button-enabled: root.index < root.last-index;
clicked => {
DiscoverActions.move-section(root.tab, root.entry.id, 1);
}
}
}
}
}
export component DiscoverConfigModal inherits Rectangle {
visible: DiscoverState.configurator-open;
if DiscoverState.configurator-open: Rectangle {
// Scrim — closes on outside click.
background: #000000bf;
TouchArea {
mouse-cursor: default;
clicked => {
DiscoverActions.close-configurator();
}
}
// Panel.
Rectangle {
width: Math.min(root.width - 80px, 520px);
height: Math.min(panel.preferred-height, root.height * 0.78);
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
border-radius: Radius.md;
background: Theme.surface-card;
border-width: 1px;
border-color: Theme.border-subtle;
drop-shadow-blur: 32px;
drop-shadow-color: #00000080;
clip: true;
// Swallow clicks so they do not fall through to the scrim.
TouchArea { }
panel := VerticalLayout {
padding: 20px;
spacing: 14px;
// Title row + close.
HorizontalLayout {
Text {
text: @tr("Customize");
color: Theme.text-primary;
font-size: Typography.heading;
font-weight: Typography.semibold;
horizontal-stretch: 1;
vertical-alignment: center;
}
close-x := TouchArea {
width: 28px;
height: 28px;
mouse-cursor: pointer;
clicked => {
DiscoverActions.close-configurator();
}
QbzIcon {
source: @image-url("../assets/icons/x.svg");
width: 17px;
height: 17px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: close-x.has-hover ? Theme.text-primary : Theme.text-muted;
}
}
}
// Perf-warning banner — section-config only; the Recommendations
// tab has no configurable sections, so it (and the count, list,
// and reset footer below) are hidden there in favor of the
// Recommendations explainer + cache-window controls.
if DiscoverState.active-tab != "recommendations": Rectangle {
border-radius: Radius.sm;
background: Theme.surface-elevated;
banner := HorizontalLayout {
padding: 10px;
spacing: 10px;
VerticalLayout {
alignment: start;
QbzIcon {
source: @image-url("../assets/icons/triangle-alert.svg");
width: 16px;
height: 16px;
tint: Theme.warning;
}
}
Text {
text: @tr("Enabling more sections increases load time.");
color: Theme.text-secondary;
font-size: Typography.legal;
wrap: word-wrap;
horizontal-stretch: 1;
}
}
}
// Count line — section-config only.
if DiscoverState.active-tab != "recommendations": Text {
text: @tr("{} of {} enabled", DiscoverState.enabled-count, DiscoverState.total-count);
color: Theme.text-muted;
font-size: Typography.legal;
font-weight: Typography.medium;
}
// Section list — section-config only (hidden on Recommendations).
if DiscoverState.active-tab != "recommendations": Rectangle {
// Explicit, content-derived height — NOT vertical-stretch: a
// stretch child inside a panel sized to `preferred-height`
// collapses (a Flickable's intrinsic preferred-height is ~0,
// the documented Slint trap). Cap = window minus the modal
// chrome so the whole panel stays within root.height * 0.78;
// the Flickable scrolls when the rows exceed this.
height: Math.min(list-col.preferred-height, root.height * 0.78 - 260px);
clip: true;
list-flick := Flickable {
width: 100%;
height: 100%;
viewport-width: self.width;
viewport-height: list-col.preferred-height;
list-col := VerticalLayout {
spacing: 2px;
alignment: start;
for row[idx] in DiscoverState.config-rows: ConfigRowView {
entry: row;
index: idx;
last-index: DiscoverState.config-rows.length - 1;
tab: DiscoverState.active-tab;
}
}
}
}
// Recommendations explainer — what this section is + how the
// cache window below works (Last.fm / ListenBrainz enrichment).
if DiscoverState.active-tab == "recommendations": Text {
text: @tr("QBZ uses your Last.fm and ListenBrainz account data when they're connected (if they aren't, we recommend connecting them to enrich this section). Here you set how often that data is fetched — it defaults to 48 hours, or you can request an update right now.");
color: Theme.text-secondary;
font-size: Typography.body;
wrap: word-wrap;
}
// Cache window + Refresh now — Recommendations tab only. Moved
// here from the old floating ExternalRecoView block; reuses the
// SAME ExternalRecoState.cache-ttl-index binding and the SAME
// ExternalRecoActions callbacks (set-cache-ttl / refresh-now).
if DiscoverState.active-tab == "recommendations": HorizontalLayout {
spacing: 8px;
VerticalLayout {
alignment: center;
Text {
text: @tr("Cache window");
color: Theme.text-muted;
font-size: Typography.body;
vertical-alignment: center;
}
}
VerticalLayout {
alignment: center;
QbzSelect {
sm: true;
menu-width: 140px;
options: [@tr("24 hours"), @tr("36 hours"), @tr("48 hours"), @tr("72 hours")];
current-index: ExternalRecoState.cache-ttl-index;
selected(i) => {
ExternalRecoActions.set-cache-ttl(i);
}
}
}
// Spacer pushes Refresh now to the right edge.
Rectangle {
horizontal-stretch: 1;
}
refresh-btn := Rectangle {
width: refresh-row.preferred-width + 24px;
height: 34px;
border-radius: Radius.sm;
border-width: 1px;
border-color: Theme.border-subtle;
background: refresh-ta.has-hover ? Theme.surface-hover : Theme.surface-elevated;
refresh-row := HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
spacing: 8px;
alignment: center;
VerticalLayout {
alignment: center;
QbzIcon {
source: @image-url("../assets/icons/refresh-cw.svg");
width: 15px;
height: 15px;
tint: Theme.text-secondary;
}
}
Text {
text: @tr("Refresh now");
color: Theme.text-primary;
font-size: Typography.body;
vertical-alignment: center;
}
}
refresh-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
ExternalRecoActions.refresh-now();
}
}
}
}
// Footer — Reset to defaults, pinned left (section-config only).
if DiscoverState.active-tab != "recommendations": HorizontalLayout {
reset-btn := Rectangle {
width: reset-row.preferred-width + 24px;
height: 34px;
border-radius: Radius.sm;
border-width: 1px;
border-color: Theme.border-subtle;
background: reset-ta.has-hover ? Theme.surface-hover : Theme.surface-elevated;
reset-row := HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
spacing: 8px;
alignment: center;
VerticalLayout {
alignment: center;
QbzIcon {
source: @image-url("../assets/icons/rotate-ccw.svg");
width: 15px;
height: 15px;
tint: Theme.text-secondary;
}
}
Text {
text: @tr("Reset to defaults");
color: Theme.text-primary;
font-size: Typography.body;
vertical-alignment: center;
}
}
reset-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
DiscoverActions.reset-tab(DiscoverState.active-tab);
}
}
}
// Spacer pushes the reset button to the left edge.
Rectangle {
horizontal-stretch: 1;
}
}
}
}
}
}