Files
qbz/crates/qbz-ui/ui/primitives/PlaylistImportModal.slint
T
vicrodh c8ef2a1b1d refactor(slint): split qbz-slint into qbz-ui lib + qbz bin; reclaim qbz binary
Slint cannot split the .slint compilation across crates, but a Slint LIBRARY
crate exposes its generated Rust types to dependent crates (verified with a
minimal proof). So:

- NEW crate `qbz-ui` (lib): owns the whole .slint tree + build.rs + bundled
  translations; `slint::include_modules!()` + the generated types (AppWindow,
  MiniPlayerWindow, all globals/structs) are re-exported. Translation domain is
  now `qbz-ui` (the .po files renamed accordingly).
- `qbz-slint` (bin) -> renamed to `qbz` (package + `[[bin]] name = "qbz"`),
  reclaiming the binary name from the retired Tauri app. It depends on `qbz-ui`
  and does `pub use qbz_ui::*;` so existing `crate::AppWindow` / `crate::*State`
  references resolve unchanged.

This splits the single ~20 GB rustc into two crates (UI/codegen vs the 75k LOC
of logic) — the foundation for lower build peak, incremental caching, and the
upcoming per-feature crate extraction.

Also fixed for the move: qbz-i18n bundled-.po include paths, the font/WGSL
`include_bytes!`/`include_str!` paths (-> ../../qbz-ui/ui/), workspace members,
dev scripts (`-p qbz`), and the CI workflows. `cargo check -p qbz` is green.

cc
2026-06-25 17:51:09 -06:00

563 lines
31 KiB
Plaintext

// "Import Playlist" modal — 1:1 port of Tauri's PlaylistImportModal.svelte.
// Two-step flow: URL entry → provider auto-detect (Rust-side; Slint 1.16
// has no string `.contains`) → fetch preview → rename + optional folder →
// import with a live progress bar, status line and append-only log, then
// an in-panel Summary block. All interpolated strings arrive pre-formatted
// from the Rust controller; the modal renders them verbatim.
//
// Documented visual deviation (port spec §1.5): Slint/femtovg has no
// grayscale/drop-shadow image filters, so the provider logos homologate to
// opacity 0.45 idle / 1.0 active (no glow/translate/scale), and Tidal's
// black SVG renders through QbzIcon tinted white so it reads on dark
// surfaces in both states.
//
// Close semantics (port spec §1.8): footer Close disables while loading
// (Tauri-verbatim); the header X and the scrim stay clickable mid-import —
// closing only hides the UI, the import task runs to completion.
//
// CJK/femtovg: playlist names, the current-track line and log lines can
// hold Korean/CJK, which femtovg measures at ~0 in both axes — every such
// Text gets BOTH width and height assigned from layout (stretch + fixed
// row heights, overflow: elide), never intrinsic sizing.
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { PlaylistImportState, PlaylistImportActions, OfflineState, UiFocusState } from "../state.slint";
import { QbzIcon } from "QbzIcon.slint";
import { QbzSelect } from "QbzSelect.slint";
import { LoadingSpinner } from "LoadingSpinner.slint";
import { QbzPrimaryButton } from "QbzPrimaryButton.slint";
import { SecondaryButton } from "SecondaryButton.slint";
export component PlaylistImportModal inherits Rectangle {
visible: PlaylistImportState.open;
if PlaylistImportState.open: Rectangle {
background: #000000bf;
// Scrim — click outside dismisses, even mid-import (§1.8: closing
// only hides the UI, the tokio task keeps running).
TouchArea {
mouse-cursor: default;
clicked => {
PlaylistImportActions.close();
}
}
card := Rectangle {
// Tauri: 560px max, min-height 420px, max-height 90vh.
width: Math.min(root.width - 80px, 560px);
// 140px = header 68 + 2 hairlines + footer 70 (16/34/20); the
// body scrolls inside a Flickable past the 90% clamp.
height: Math.min(Math.max(420px, body.preferred-height + 140px), root.height * 0.9);
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
border-radius: Radius.lg;
background: Theme.surface-card;
border-width: 1px;
border-color: Theme.border-subtle;
drop-shadow-blur: 32px;
drop-shadow-color: #00000080;
// Swallow clicks so they never reach the scrim.
TouchArea { }
panel := VerticalLayout {
padding: 0px;
spacing: 0px;
// Header: Qobuz logo + title + close-x.
header := HorizontalLayout {
padding-left: 24px;
padding-right: 24px;
padding-top: 20px;
padding-bottom: 20px;
spacing: 10px;
VerticalLayout {
alignment: center;
QbzIcon {
source: @image-url("../assets/icons/qobuz-logo.svg");
width: 26px;
height: 26px;
tint: #ffffff;
opacity: 0.9;
}
}
Text {
text: @tr("Import Playlist");
color: Theme.text-primary;
font-size: Typography.section;
font-weight: Typography.semibold;
horizontal-stretch: 1;
vertical-alignment: center;
}
// X close — allowed mid-import (§1.8).
close-x := TouchArea {
width: 28px;
height: 28px;
mouse-cursor: pointer;
clicked => {
PlaylistImportActions.close();
}
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;
}
}
}
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
// Body — scrolls when the progress panel outgrows the card.
body-flick := Flickable {
vertical-stretch: 1;
viewport-width: self.width;
viewport-height: body.preferred-height;
body := VerticalLayout {
padding: 24px;
spacing: 16px;
alignment: start;
// Offline banner — fetch is gated (can-fetch goes
// false), the URL input stays enabled.
if OfflineState.offline: Rectangle {
height: offline-row.preferred-height;
border-radius: 8px;
background: #eab3081a;
border-width: 1px;
border-color: #eab3084d;
offline-row := HorizontalLayout {
padding: 12px;
spacing: 10px;
VerticalLayout {
alignment: center;
QbzIcon {
source: @image-url("../assets/icons/cloud-off.svg");
width: 16px;
height: 16px;
tint: #eab308;
}
}
Text {
text: @tr("This feature requires internet connection");
color: #eab308;
font-size: Typography.legal;
vertical-alignment: center;
horizontal-stretch: 1;
}
}
}
// Error banner (preview or execute failure).
if PlaylistImportState.error != "": Rectangle {
height: error-row.preferred-height;
border-radius: 8px;
background: #ef44441a;
border-width: 1px;
border-color: #ef44444d;
error-row := HorizontalLayout {
padding: 12px;
Text {
text: PlaylistImportState.error;
color: #ef4444;
font-size: Typography.legal;
wrap: word-wrap;
min-height: 20px;
horizontal-stretch: 1;
}
}
}
// URL input — every keystroke routes the detection
// through Rust (url-edited); Enter fetches (step A).
VerticalLayout {
spacing: 8px;
Text {
text: @tr("Playlist URL");
color: Theme.text-secondary;
font-size: Typography.legal;
font-weight: Typography.medium;
}
// The standard 43px input box (PlaylistPicker
// recipe).
url-box := Rectangle {
height: 43px;
border-radius: Radius.sm;
background: Theme.surface-card;
border-width: 1px;
border-color: url-input.has-focus ? Theme.accent : Theme.border-subtle;
opacity: PlaylistImportState.loading ? 0.5 : 1.0;
HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
Rectangle {
horizontal-stretch: 1;
clip: true;
url-input := TextInput {
width: 100%;
height: 100%;
color: Theme.text-primary;
font-size: Typography.link;
vertical-alignment: center;
single-line: true;
enabled: !PlaylistImportState.loading;
text <=> PlaylistImportState.url;
changed has-focus => { UiFocusState.text-input-focused = self.has-focus; }
edited => {
PlaylistImportActions.url-edited(self.text);
}
accepted => {
if (!PlaylistImportState.show-preview
&& PlaylistImportState.can-fetch
&& !PlaylistImportState.loading) {
PlaylistImportActions.fetch();
}
}
}
Text {
// Placeholder — Slint TextInput has
// no placeholder property; a sibling
// Text gated on empty text. Plain
// string: not localized in Tauri
// either.
visible: url-input.text == "";
width: 100%;
height: 100%;
text: "https://open.spotify.com/playlist/...";
color: Theme.text-muted;
font-size: Typography.link;
vertical-alignment: center;
overflow: elide;
}
}
}
}
}
// Allowed sources — the detected provider's logo at
// full opacity, the rest dimmed (§1.5 homologation).
VerticalLayout {
spacing: 8px;
Text {
text: @tr("ALLOWED SOURCES");
color: Theme.text-muted;
font-size: Typography.legal;
font-weight: Typography.semibold;
letter-spacing: 0.5px;
}
HorizontalLayout {
spacing: 10px;
alignment: start;
Image {
source: @image-url("../assets/icons/spotify-logo.svg");
width: 70px;
height: 24px;
image-fit: contain;
opacity: PlaylistImportState.active-provider == "spotify" ? 1.0 : 0.45;
}
Image {
source: @image-url("../assets/icons/apple-music-logo.svg");
width: 70px;
height: 24px;
image-fit: contain;
opacity: PlaylistImportState.active-provider == "apple" ? 1.0 : 0.45;
}
// Tidal's SVG is black — tint white so it
// reads on dark surfaces in both states.
QbzIcon {
source: @image-url("../assets/icons/tidal-tidal.svg");
width: 70px;
height: 24px;
tint: #ffffff;
opacity: PlaylistImportState.active-provider == "tidal" ? 1.0 : 0.45;
}
Image {
source: @image-url("../assets/icons/deezer-logo.svg");
width: 70px;
height: 24px;
image-fit: contain;
opacity: PlaylistImportState.active-provider == "deezer" ? 1.0 : 0.45;
}
}
}
// Customization panel (step B): rename + optional
// folder. Editing the URL reverts to step A
// (show-preview recomputes Rust-side).
if PlaylistImportState.show-preview: Rectangle {
height: custom-col.preferred-height;
border-radius: Radius.md;
background: Theme.surface-elevated;
border-width: 1px;
border-color: Theme.border-subtle;
custom-col := VerticalLayout {
padding: 16px;
spacing: 12px;
VerticalLayout {
spacing: 8px;
Text {
text: @tr("Playlist name");
color: Theme.text-secondary;
font-size: Typography.legal;
font-weight: Typography.medium;
}
name-box := Rectangle {
height: 43px;
border-radius: Radius.sm;
background: Theme.surface-card;
border-width: 1px;
border-color: name-input.has-focus ? Theme.accent : Theme.border-subtle;
opacity: name-input.enabled ? 1.0 : 0.5;
HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
Rectangle {
horizontal-stretch: 1;
clip: true;
name-input := TextInput {
width: 100%;
height: 100%;
color: Theme.text-primary;
font-size: Typography.link;
vertical-alignment: center;
single-line: true;
enabled: !PlaylistImportState.loading
&& !PlaylistImportState.import-completed;
text <=> PlaylistImportState.custom-name;
changed has-focus => { UiFocusState.text-input-focused = self.has-focus; }
edited => {
PlaylistImportActions.name-edited(self.text);
}
accepted => {
// Enter here executes (step B).
if (!PlaylistImportState.loading
&& !PlaylistImportState.import-completed) {
PlaylistImportActions.execute();
}
}
}
}
}
}
}
// Folder dropdown — only when the user has
// folders (mirrors Tauri; index 0 = "No
// folder").
if PlaylistImportState.folder-options.length > 1: VerticalLayout {
spacing: 8px;
Text {
text: @tr("Folder");
color: Theme.text-secondary;
font-size: Typography.legal;
font-weight: Typography.medium;
}
QbzSelect {
options: PlaylistImportState.folder-options;
current-index: PlaylistImportState.folder-index;
menu-width: 380px;
selected(i) => {
PlaylistImportState.folder-index = i;
}
}
}
}
}
// Progress panel: spinner header, determinate bar,
// status + current-track lines, the log, and the
// Summary block on completion.
if PlaylistImportState.progress-visible: Rectangle {
height: progress-col.preferred-height;
border-radius: Radius.md;
background: Theme.surface-elevated;
border-width: 1px;
border-color: Theme.border-subtle;
progress-col := VerticalLayout {
padding: 16px;
spacing: 10px;
HorizontalLayout {
spacing: 8px;
Text {
text: @tr("Conversion progress");
color: Theme.text-primary;
font-size: Typography.body;
font-weight: Typography.medium;
vertical-alignment: center;
horizontal-stretch: 1;
}
// Tauri: 14px accent ring while loading.
if PlaylistImportState.loading: VerticalLayout {
alignment: center;
LoadingSpinner {
size: 14px;
}
}
}
if PlaylistImportState.has-progress: VerticalLayout {
spacing: 6px;
// Determinate 6px bar (LocalLibrarySettings
// recipe); track in the 8%-alpha tone — the
// panel bg already uses surface-elevated.
Rectangle {
height: 6px;
border-radius: 3px;
background: Theme.border-subtle;
clip: true;
Rectangle {
x: 0;
width: parent.width * Math.min(1.0, PlaylistImportState.progress);
height: parent.height;
border-radius: 3px;
background: Theme.accent;
}
}
// Status line — 12px Tauri metric; fixed
// height (CJK floor) + elide.
Text {
text: PlaylistImportState.status-line;
color: Theme.text-secondary;
font-size: 12px;
height: 18px;
vertical-alignment: center;
overflow: elide;
}
// Current-track line — "Artist - Title"
// while matching, "Part i/n" while adding.
if PlaylistImportState.current-track != "": Text {
text: PlaylistImportState.current-track;
color: Theme.text-muted;
font-size: 11px;
height: 16px;
vertical-alignment: center;
overflow: elide;
}
}
// Append-only log. Height capped via static
// arithmetic over the MODEL LENGTH — never row
// geometry (Recursion-detected footgun). No
// autoscroll (Tauri parity). Render-only rows:
// no TouchAreas here.
if PlaylistImportState.log.length > 0: Flickable {
height: Math.min(PlaylistImportState.log.length * 20px, 160px);
viewport-width: self.width;
viewport-height: PlaylistImportState.log.length * 20px;
VerticalLayout {
spacing: 0px;
for entry in PlaylistImportState.log: Rectangle {
height: 20px;
Text {
width: 100%;
height: 100%;
text: entry.message;
// Hex literals kept — Tauri
// hardcodes them.
color: entry.status == "success" ? #34d399
: (entry.status == "error" ? #f87171 : Theme.text-muted);
font-size: Typography.legal;
vertical-alignment: center;
overflow: elide;
}
}
}
}
// Summary block — pre-formatted lines, hairline
// separated, "" = hidden.
if PlaylistImportState.summary-playlist != "": VerticalLayout {
spacing: 6px;
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
Text {
text: @tr("Summary");
color: Theme.text-primary;
font-size: Typography.body;
font-weight: Typography.semibold;
}
Text {
text: PlaylistImportState.summary-playlist;
color: Theme.text-secondary;
font-size: Typography.legal;
height: 18px;
vertical-alignment: center;
overflow: elide;
}
Text {
text: PlaylistImportState.summary-matched;
color: Theme.text-secondary;
font-size: Typography.legal;
height: 18px;
vertical-alignment: center;
overflow: elide;
}
Text {
text: PlaylistImportState.summary-skipped;
color: Theme.text-secondary;
font-size: Typography.legal;
height: 18px;
vertical-alignment: center;
overflow: elide;
}
if PlaylistImportState.summary-parts != "": Text {
text: PlaylistImportState.summary-parts;
color: Theme.text-secondary;
font-size: Typography.legal;
height: 18px;
vertical-alignment: center;
overflow: elide;
}
}
}
}
}
}
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
footer := HorizontalLayout {
padding-left: 24px;
padding-right: 24px;
padding-top: 16px;
padding-bottom: 20px;
alignment: end;
spacing: 12px;
SecondaryButton {
label: @tr("Close");
enabled: !PlaylistImportState.loading;
clicked => {
PlaylistImportActions.close();
}
}
// The single accent confirm (ADR-008). Step A fetches,
// step B imports; stays visible-but-disabled after
// completion (Tauri parity).
QbzPrimaryButton {
height: 34px;
label: PlaylistImportState.show-preview
? (PlaylistImportState.loading ? @tr("Importing...") : @tr("Import"))
: (PlaylistImportState.loading ? @tr("Fetching...") : @tr("Fetch playlist"));
enabled: PlaylistImportState.show-preview
? (!PlaylistImportState.loading && !PlaylistImportState.import-completed)
: (PlaylistImportState.can-fetch && !PlaylistImportState.loading);
clicked => {
if (PlaylistImportState.show-preview) {
PlaylistImportActions.execute();
} else {
PlaylistImportActions.fetch();
}
}
}
}
}
}
}
}