Files
qbz/crates/qbz-slint/ui/playlist/PlaylistView.slint
T
vicrodh 5ac5c60c57 feat(slint): playlist collage + custom artwork + edit description
Wires qbz-library into the Slint app (new library_db module) so the
local, Tauri-shared organization data is read/written from the same
per-user library.db (<data_dir>/qbz/users/<id>/library.db). The DB is
opened per-operation on a blocking thread (rusqlite Connection is
!Send).

  - Header collage: the playlist cover is now a 4-up collage of the
    first tracks' covers (Tauri parity); falls back to the server
    image, then the first track, then a placeholder.
  - Custom artwork: owner-only buttons on the cover set/clear a custom
    image. Set copies the picked file into <cache_dir>/qbz/artwork and
    stores the path in playlist_settings.custom_artwork_path (shared
    with Tauri); it's loaded directly from disk and overrides the
    collage.
  - Edit description: the edit modal gains a description field
    (prefilled), saved through update_playlist alongside the name.

cc
2026-05-22 08:30:16 -06:00

443 lines
19 KiB
Plaintext

// Playlist detail view. Same anatomy as AlbumView / MixView: a header
// (cover + "Playlist" label + name + description + "owner • N tracks •
// duration" info line + circular actions) over a column-headed track
// list of shared TrackRows (show-artwork + show-album).
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { PlaylistState } from "../state.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { TrackRow } from "../primitives/TrackRow.slint";
import { LoadingSpinner } from "../primitives/LoadingSpinner.slint";
import { NavButtons } from "../shell/NavButtons.slint";
component CircleAction inherits Rectangle {
in property <image> icon;
in property <bool> primary: false;
in property <bool> active: false;
in property <length> diameter: 38px;
in property <bool> enabled: true;
callback clicked();
width: root.diameter;
height: root.diameter;
border-radius: root.diameter / 2;
opacity: root.enabled ? 1.0 : 0.4;
background: root.primary
? (ta.has-hover ? #ffffffd6 : Theme.accent)
: (ta.has-hover ? Theme.surface-hover : Theme.surface-elevated);
QbzIcon {
source: root.icon;
width: root.primary ? 18px : 16px;
height: root.primary ? 18px : 16px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
tint: root.primary
? #ffffff
: (root.active ? Theme.accent : Theme.text-secondary);
}
ta := TouchArea {
mouse-cursor: root.enabled ? pointer : default;
clicked => {
if (root.enabled) {
root.clicked();
}
}
}
}
export component PlaylistView inherits Rectangle {
callback play-track(string);
callback play-all();
callback shuffle();
callback toggle-favorite();
callback edit();
callback media-action(string, string, string);
background: Theme.surface-main;
Flickable {
viewport-width: self.width;
viewport-height: page.preferred-height;
page := VerticalLayout {
width: parent.width;
padding-left: 32px;
padding-right: 32px;
padding-top: 11px;
padding-bottom: 100px;
spacing: 0px;
alignment: start;
HorizontalLayout {
alignment: start;
NavButtons { }
}
Rectangle { height: 22px; }
// --- Header ------------------------------------------------
HorizontalLayout {
spacing: 32px;
alignment: start;
// Cover — custom artwork if set, else a 4-up collage of
// the first tracks' covers (Tauri parity), else the
// server playlist image, else the first track, else a
// placeholder.
cover-box := Rectangle {
width: 224px;
height: 224px;
border-radius: Radius.md;
background: Theme.surface-elevated;
clip: true;
// Custom artwork / single server image.
property <bool> show-single:
PlaylistState.has-custom
|| (PlaylistState.track-count < 4 && PlaylistState.cover-url != "");
property <bool> show-collage:
!PlaylistState.has-custom && PlaylistState.track-count >= 4;
if cover-box.show-single: Image {
width: 100%;
height: 100%;
source: PlaylistState.cover;
image-fit: cover;
}
// 2x2 collage from the first four track covers.
if cover-box.show-collage: VerticalLayout {
spacing: 2px;
HorizontalLayout {
spacing: 2px;
Image {
width: 111px; height: 111px;
source: PlaylistState.tracks[0].artwork;
image-fit: cover;
}
Image {
width: 111px; height: 111px;
source: PlaylistState.tracks[1].artwork;
image-fit: cover;
}
}
HorizontalLayout {
spacing: 2px;
Image {
width: 111px; height: 111px;
source: PlaylistState.tracks[2].artwork;
image-fit: cover;
}
Image {
width: 111px; height: 111px;
source: PlaylistState.tracks[3].artwork;
image-fit: cover;
}
}
}
// Single first-track cover when 1-3 tracks and no
// server image.
if !cover-box.show-single && !cover-box.show-collage
&& PlaylistState.track-count >= 1: Image {
width: 100%;
height: 100%;
source: PlaylistState.tracks[0].artwork;
image-fit: cover;
}
// Empty placeholder.
if PlaylistState.track-count == 0 && PlaylistState.cover-url == ""
&& !PlaylistState.has-custom: QbzIcon {
source: @image-url("../assets/icons/list-music.svg");
width: 56px;
height: 56px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
tint: Theme.text-muted;
}
// Set custom artwork (owner only) — bottom-right.
if PlaylistState.is-owner: Rectangle {
width: 32px;
height: 32px;
border-radius: 16px;
x: parent.width - self.width - 8px;
y: parent.height - self.height - 8px;
background: set-ta.has-hover ? Theme.accent : #000000aa;
QbzIcon {
source: @image-url("../assets/icons/image-plus.svg");
width: 16px;
height: 16px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
tint: #ffffff;
}
set-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.media-action("playlist", "", "set-artwork");
}
}
}
// Clear custom artwork — top-right, only when set.
if PlaylistState.is-owner && PlaylistState.has-custom: Rectangle {
width: 28px;
height: 28px;
border-radius: 14px;
x: parent.width - self.width - 8px;
y: 8px;
background: clr-ta.has-hover ? #ef4444 : #000000aa;
QbzIcon {
source: @image-url("../assets/icons/x.svg");
width: 14px;
height: 14px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
tint: #ffffff;
}
clr-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.media-action("playlist", "", "clear-artwork");
}
}
}
}
// Metadata.
VerticalLayout {
alignment: start;
padding-top: 4px;
horizontal-stretch: 1;
Text {
text: @tr("Playlist");
color: Theme.text-muted;
font-size: 11px;
font-weight: Typography.semibold;
letter-spacing: 1.5px;
}
Rectangle { height: 6px; }
Text {
text: PlaylistState.name;
color: Theme.text-primary;
font-size: Typography.title;
font-weight: Typography.bold;
wrap: word-wrap;
}
if PlaylistState.description != "": Rectangle { height: 8px; }
if PlaylistState.description != "": Text {
width: root.width - 320px;
text: PlaylistState.description;
color: Theme.text-secondary;
font-size: Typography.body;
wrap: word-wrap;
overflow: elide;
}
Rectangle { height: 10px; }
Text {
text: PlaylistState.owner
+ " • " + PlaylistState.track-count + " " + @tr("tracks")
+ " • " + PlaylistState.total-duration;
color: Theme.text-secondary;
font-size: Typography.legal;
}
Rectangle { height: 20px; }
// Actions.
HorizontalLayout {
alignment: start;
spacing: 12px;
CircleAction {
icon: @image-url("../assets/icons/play-fill.svg");
primary: true;
diameter: 44px;
enabled: PlaylistState.tracks.length > 0;
clicked => {
root.play-all();
}
}
VerticalLayout {
alignment: center;
CircleAction {
icon: @image-url("../assets/icons/shuffle.svg");
enabled: PlaylistState.tracks.length > 0;
clicked => {
root.shuffle();
}
}
}
VerticalLayout {
alignment: center;
CircleAction {
icon: @image-url("../assets/icons/heart.svg");
active: PlaylistState.is-favorite;
clicked => {
root.toggle-favorite();
}
}
}
// Edit (rename / delete) — only the user's own.
if PlaylistState.is-owner: VerticalLayout {
alignment: center;
CircleAction {
icon: @image-url("../assets/icons/pen-line.svg");
clicked => {
root.edit();
}
}
}
// Select tracks (multi-select edit mode).
if PlaylistState.is-owner && PlaylistState.tracks.length > 0: VerticalLayout {
alignment: center;
CircleAction {
icon: @image-url("../assets/icons/square-check-big.svg");
active: PlaylistState.multi-select-mode;
clicked => {
root.media-action("playlist", "", "select-toggle");
}
}
}
}
}
}
Rectangle { height: 28px; }
if PlaylistState.loading: HorizontalLayout {
alignment: center;
LoadingSpinner { size: 36px; }
}
if !PlaylistState.loading && PlaylistState.tracks.length == 0: Text {
text: @tr("This playlist is empty.");
color: Theme.text-muted;
font-size: Typography.body;
}
// --- Track list column header ------------------------------
if PlaylistState.tracks.length > 0: HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
spacing: 14px;
Text {
text: "#";
width: 20px;
color: Theme.text-muted;
font-size: Typography.legal;
horizontal-alignment: center;
}
Rectangle { width: 40px; }
Text {
text: @tr("Title");
color: Theme.text-muted;
font-size: Typography.legal;
horizontal-stretch: 1;
}
Text {
text: @tr("Album");
width: 220px;
color: Theme.text-muted;
font-size: Typography.legal;
}
Text {
text: @tr("Duration");
width: 70px;
color: Theme.text-muted;
font-size: Typography.legal;
horizontal-alignment: center;
}
Text {
text: @tr("Quality");
width: 70px;
color: Theme.text-muted;
font-size: Typography.legal;
horizontal-alignment: center;
}
Rectangle { width: 28px; }
Rectangle { width: 32px; }
}
if PlaylistState.tracks.length > 0: Rectangle {
height: 1px;
background: Theme.border-subtle;
}
Rectangle { height: 6px; }
// Bulk action bar — visible in edit mode.
if PlaylistState.multi-select-mode: Rectangle {
height: 44px;
border-radius: 8px;
background: Theme.surface-elevated;
HorizontalLayout {
padding-left: 14px;
padding-right: 10px;
spacing: 12px;
Text {
text: PlaylistState.selected-count + " " + @tr("selected");
color: Theme.text-secondary;
font-size: Typography.body;
vertical-alignment: center;
horizontal-stretch: 1;
}
pill-all := Rectangle {
width: all-label.preferred-width + 24px;
height: 30px;
border-radius: Radius.sm;
background: all-ta.has-hover ? Theme.surface-hover : transparent;
all-label := Text {
text: @tr("Select all");
color: Theme.text-secondary;
font-size: Typography.legal;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
}
all-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.media-action("playlist", "", "select-all");
}
}
}
pill-remove := Rectangle {
width: rm-label.preferred-width + 24px;
height: 30px;
border-radius: Radius.sm;
opacity: PlaylistState.selected-count > 0 ? 1.0 : 0.5;
background: rm-ta.has-hover ? #ef444433 : transparent;
border-width: 1px;
border-color: #ef4444;
rm-label := Text {
text: @tr("Remove");
color: #ef4444;
font-size: Typography.legal;
font-weight: Typography.medium;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
}
rm-ta := TouchArea {
mouse-cursor: PlaylistState.selected-count > 0 ? pointer : default;
clicked => {
if (PlaylistState.selected-count > 0) {
root.media-action("playlist", "", "remove-selected");
}
}
}
}
}
}
if PlaylistState.multi-select-mode: Rectangle { height: 8px; }
for track[i] in PlaylistState.tracks: TrackRow {
track: track;
index: i;
show-artwork: true;
show-album: true;
show-favorite: true;
multi-select-mode: PlaylistState.multi-select-mode;
media-action(kind, id, action) => {
if (action == "play") {
root.play-track(id);
} else {
root.media-action(kind, id, action);
}
}
}
}
}
}