Skip to content

armgit / Spun

Public Imported from GitHub
0

A CD-shaped music player for Linux, with local playback and Cider integration.

Add remote feature regression coverage

yappologistica5c7f279ea94
diff --git a/.gitignore b/.gitignore
index 167e46c..57e72aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -60,3 +60,4 @@ listening.json
/tests/*
!/tests/youtube_fixture.py
!/tests/test_youtube.py
+!/tests/REGRESSION.md
diff --git a/CMakeLists.txt b/CMakeLists.txt
index feafe5c..a1462fc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -148,3 +148,15 @@ if(BUILD_TESTING)
add_test(NAME spun-subsonic-protocol COMMAND spun-subsonic-protocol-test)
set_tests_properties(spun-subsonic-protocol PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen;QT_QPA_PLATFORMTHEME=")
endif()
+
+if(BUILD_TESTING)
+ qt_add_executable(spun-remote-library-test src/remotelibrarytest.cpp)
+ target_link_libraries(spun-remote-library-test PRIVATE spun_core Qt6::Test)
+ add_test(NAME spun-remote-library COMMAND spun-remote-library-test)
+ set_tests_properties(spun-remote-library PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen;QT_QPA_PLATFORMTHEME=")
+ add_test(NAME spun-immersive-media-ui COMMAND spun --test-media-ui)
+ set_tests_properties(spun-remote-library PROPERTIES TIMEOUT 120 LABELS "remote;regression")
+ set_tests_properties(spun-immersive-media-ui PROPERTIES
+ ENVIRONMENT "QT_QPA_PLATFORM=offscreen;QT_QUICK_BACKEND=software;QSG_RENDER_LOOP=basic;QT_QPA_PLATFORMTHEME="
+ TIMEOUT 180 LABELS "ui;regression")
+endif()
diff --git a/README.md b/README.md
index 3750b3b..b07837c 100644
--- a/README.md
+++ b/README.md
@@ -244,6 +244,8 @@ For the intended appearance, we recommend [Google Sans Flex](https://github.com/
<details>
<summary><strong>Keyboard shortcuts</strong></summary>
+Immersive mode hides controls after inactivity; move the pointer or use the keyboard to reveal them. Press Y for lyrics or Escape to leave.
+
| Action | Shortcut |
| --- | --- |
| Play / pause | Space |
@@ -258,6 +260,7 @@ For the intended appearance, we recommend [Google Sans Flex](https://github.com/
| Toggle focused browser track | Space (track list focused) |
| Select tracks / range | Ctrl-click / Shift-click |
| Mini mode | Ctrl + M |
+| Immersive mode | Ctrl + I |
| Flip medium / switch lyrics | F / Y |
| Mute | M |
| Keyboard help | F1 |
diff --git a/qml/IconButton.qml b/qml/IconButton.qml
index fb87ab5..9abbdf1 100644
--- a/qml/IconButton.qml
+++ b/qml/IconButton.qml
@@ -5,7 +5,7 @@ AbstractButton {
id: control
property string glyphName: "play"
property string tip: ""
- property bool showTip: true
+ property bool showTip: !Window.window || Window.window["chromeHidden"] !== true
property color ink: "#eee8de"
property color fill: "transparent"
property color hoverFill: "#30ffffff"
diff --git a/qml/Main.qml b/qml/Main.qml
index 922fbec..db85329 100644
--- a/qml/Main.qml
+++ b/qml/Main.qml
@@ -7,6 +7,42 @@ ApplicationWindow {
id: root
objectName: "spunWindow"
title: "Spun"
+ property bool immersive: false
+ property bool chromeIdle: false
+ property bool immersionQueue: false
+ property bool immersionLibrary: false
+ readonly property bool chromeHidden: immersive && chromeIdle && !menuOpen && !sideOpen && !deckPlayer.error.length && !(useServer && serverLibrary.buffering)
+ function revealChrome() { chromeIdle = false; if (immersive) immersionIdle.restart() }
+ function toggleImmersion() { immersive = !immersive }
+ onImmersiveChanged: {
+ if (immersive) {
+ immersionQueue = queueOpen; immersionLibrary = libraryOpen;
+ queueOpen = false; libraryOpen = false; player.miniMode = false;
+ } else { queueOpen = immersionQueue; libraryOpen = immersionLibrary }
+ revealChrome(); Qt.callLater(updateMask);
+ }
+ onActiveFocusItemChanged: revealChrome()
+ Timer {
+ id: immersionIdle; objectName: "immersionIdle"
+ interval: 3000
+ onTriggered: {
+ const focused = root.activeFocusItem && root.activeFocusItem.visualFocus;
+ if (root.immersive && !root.menuOpen && !root.editingText && !focused && !root.threeDGesture && !root.threeDHardwarePressed)
+ root.chromeIdle = true;
+ else if (root.immersive) restart();
+ }
+ }
+ HoverHandler {
+ parent: root.contentItem
+ property point previousPosition: Qt.point(-1, -1)
+ onPointChanged: {
+ const position = point.position;
+ if (position.x !== previousPosition.x || position.y !== previousPosition.y) {
+ previousPosition = position;
+ root.revealChrome();
+ }
+ }
+ }
visible: true
readonly property bool wideMixer: tx6Visible && threeDRequested
readonly property real playerWidth: miniMode ? 300 : wideMixer ? 740 : 530
@@ -127,6 +163,7 @@ ApplicationWindow {
running: root.useCider && root.visible && root.visibility !== Window.Minimized && (songMenu.visible || crossfadeMenu.visible || qualityPopup.visible)
onTriggered: root.refreshOpenCiderDetails()
}
+ readonly property bool playbackFailed: useServer && deckPlayer.error.length > 0
property var deckPlayer: useCider ? root.ciderService : useServer ? serverLibrary.transport : useYoutube ? youtube.transport : player
onDeckPlayerChanged: tx6.setPlayer(useServer ? serverLibrary.transport : useYoutube ? youtube.transport : player)
readonly property string cassetteTrackIdentity: (useCider ? "cider:" : useServer ? (useSubsonic ? "subsonic:" : "jellyfin:") : useYoutube ? "youtube:" : "local:") + (deckPlayer.trackKey || "")
@@ -254,7 +291,7 @@ ApplicationWindow {
property bool miniMode: player.miniMode
onMiniModeChanged: Qt.callLater(function() {
cancelSeekPreview(); scrubber.cancelScrub(); stopSwap()
- if (miniMode) { artworkPopup.close(); savedQueuePicker.close(); qualityPopup.close(); if(libraryDragging)endLibraryDrag(false); preferences.close(); crossfadeMenu.close(); songMenu.close(); musicBrowser.closeActions(); libraryOpen = false; queueOpen = false; helpOpen = false; menu.close(); miniReveal.restart() }
+ if (miniMode) { immersive = false; artworkPopup.close(); savedQueuePicker.close(); qualityPopup.close(); if(libraryDragging)endLibraryDrag(false); preferences.close(); crossfadeMenu.close(); songMenu.close(); musicBrowser.closeActions(); libraryOpen = false; queueOpen = false; helpOpen = false; menu.close(); miniReveal.restart() }
updateMask(); platformNative.effects(root, backgroundBlur)
})
property bool editingText: activeFocusItem instanceof TextInput || activeFocusItem instanceof TextEdit
@@ -539,28 +576,29 @@ ApplicationWindow {
MouseArea { anchors.fill: parent; onPressed: root.startSystemMove() }
}
- Shortcut { sequence: "Alt+G"; enabled: actionNotice.shown && actionNotice.canUndo && !root.menuOpen; onActivated: noticeUndo.forceActiveFocus(Qt.ShortcutFocusReason) }
- Shortcut { sequence: "Ctrl+K"; enabled: !root.menuOpen || quickJump.visible; onActivated: quickJump.visible ? quickJump.close() : root.openQuickJump() }
- Shortcut { sequence: "Space"; enabled: !(root.activeFocusItem instanceof AbstractButton) && !(root.useCider && root.queueOpen && trackList.activeFocus) && !(root.libraryOpen && musicBrowser.item && musicBrowser.item.trackListFocused) && !root.editingText && !root.menuOpen; onActivated: root.deckPlayer.count ? root.deckPlayer.toggle() : (root.useYoutube || root.useServer) ? root.openLibrary() : root.useCider ? root.ciderService.toggle() : files.open() }
- Shortcut { sequence: "Ctrl+V"; enabled: !root.editingText && !root.menuOpen; onActivated: root.openMusicLink("", true) }
- Shortcut { sequence: "Ctrl+O"; enabled: !root.menuOpen; onActivated: files.open() }
- Shortcut { sequence: "Ctrl+Shift+O"; enabled: !root.menuOpen; onActivated: folder.open() }
- Shortcut { sequence: "Ctrl+Q"; onActivated: Qt.quit() }
- Shortcut { sequence: "Ctrl+F"; enabled: !root.menuOpen; onActivated: root.libraryOpen ? (root.useServer ? serverBrowser.item.focusSearch() : root.useYoutube ? youtubeBrowser.item.focusSearch() : musicBrowser.focusSearch()) : root.openQueueSearch() }
- Shortcut { sequence: "Ctrl+B"; enabled: (root.useCider || root.useYoutube || root.useServer) && !root.menuOpen; onActivated: root.openLibrary() }
- Shortcut { sequence: "Ctrl+L"; enabled: !root.menuOpen; onActivated: root.toggleQueue() }
- Shortcut { sequence: "Ctrl+M"; enabled: !root.menuOpen; onActivated: player.miniMode = !player.miniMode }
- Shortcut { sequence: "Right"; enabled: !(root.activeFocusItem instanceof Slider) && !root.editingText && !root.menuOpen; onActivated: root.deckPlayer.seek(root.deckPlayer.position + 5000) }
- Shortcut { sequence: "Left"; enabled: !(root.activeFocusItem instanceof Slider) && !root.editingText && !root.menuOpen; onActivated: root.deckPlayer.seek(root.deckPlayer.position - 5000) }
- Shortcut { sequence: "Ctrl+Right"; enabled: !root.editingText && !root.menuOpen; onActivated: root.deckPlayer.next() }
- Shortcut { sequence: "Ctrl+Left"; enabled: !root.editingText && !root.menuOpen; onActivated: root.deckPlayer.previous() }
- Shortcut { sequence: "Up"; enabled: !(root.activeFocusItem instanceof Slider) && !root.libraryOpen && !trackList.activeFocus && !root.menuOpen && !root.editingText && !(root.discFlipped && (albumList.activeFocus || lyricList.activeFocus)); onActivated: root.deckPlayer.volume = Math.min(1, root.deckPlayer.volume + .05) }
- Shortcut { sequence: "Down"; enabled: !(root.activeFocusItem instanceof Slider) && !root.libraryOpen && !trackList.activeFocus && !root.menuOpen && !root.editingText && !(root.discFlipped && (albumList.activeFocus || lyricList.activeFocus)); onActivated: root.deckPlayer.volume = Math.max(0, root.deckPlayer.volume - .05) }
- Shortcut { sequence: "M"; enabled: !root.editingText && !root.menuOpen; onActivated: root.toggleMute() }
- Shortcut { sequence: "Escape"; onActivated: { if(root.threeDPointer || root.threeDHardwarePressed) { root.cancel3DPointer();return }; if(artworkPopup.visible) { artworkPopup.close();return }; if(root.activeSeekControl) { root.cancelSeekPreview();return }; if(scrubber.scrubbing) { scrubber.cancelScrub();return }; if(root.libraryDragging) { root.endLibraryDrag(false);return }; if(quickJump.visible) { quickJump.close();return }; if(savedQueuePicker.visible) { savedQueuePicker.close();return }; if(cleanupPopup.visible) { cleanupPopup.close();return }; if(qualityPopup.visible) { qualityPopup.close();return }; if (saveQueuePopup.visible) { saveQueuePopup.close(); return }; if (deleteQueuePopup.visible) { deleteQueuePopup.close(); return }; if (savedQueueMenu.visible) { savedQueueMenu.close(); return }; if (fontPicker.shown || fontPicker.opening) { fontPicker.close(); return }; if (preferences.visible) { preferences.close(); return }; if (crossfadeMenu.visible) { crossfadeMenu.close(); return }; if (queueMenu.visible) { queueMenu.close(); return }; if (songMenu.visible) { songMenu.close(); return }; if (serverBrowser.item && serverBrowser.item.actionsOpen) { serverBrowser.item.closeActions(); return }; if (youtubeBrowser.item && youtubeBrowser.item.actionsOpen) { youtubeBrowser.item.closeActions(); return }; if (musicBrowser.actionsOpen) { musicBrowser.closeActions(); return }; if (menu.visible) { menu.close(); return }; if (root.queueSelectionCount > 0) { root.clearQueueSelection(); return }; if (root.queueSearchOpen) { root.closeQueueSearch(); return }; if (root.libraryOpen) { if(root.useYoutube || root.useServer){root.libraryOpen=false;return}; if (musicBrowser.item && musicBrowser.item.selectionCount > 0) musicBrowser.item.clearSelection(); else if (musicBrowser.detail && musicBrowser.browser.collectionQuery.length) musicBrowser.browser.collectionQuery = ""; else if (musicBrowser.detail) musicBrowser.browser.back(); else root.libraryOpen = false; return }; if (root.discFlipped) { root.discFlipped = false; return }; root.queueOpen = false; root.helpOpen = false; menu.close(); if (root.miniMode) player.miniMode = false } }
- Shortcut { sequence: "Y"; enabled: !root.editingText && !root.menuOpen; onActivated: { if (root.deckPlayer.count) { root.discFlipped = true; root.lyricsView = !root.lyricsView } } }
- Shortcut { sequence: "F"; enabled: !root.editingText && !root.menuOpen; onActivated: root.flipDisc() }
- Shortcut { sequence: "F1"; enabled: !root.menuOpen; onActivated: root.helpOpen = !root.helpOpen }
+ Shortcut { sequence: "Alt+G"; enabled: actionNotice.shown && actionNotice.canUndo && !root.menuOpen; onActivated: { root.revealChrome(); noticeUndo.forceActiveFocus(Qt.ShortcutFocusReason) } }
+ Shortcut { sequence: "Ctrl+K"; enabled: !root.menuOpen || quickJump.visible; onActivated: { root.revealChrome(); quickJump.visible ? quickJump.close() : root.openQuickJump() } }
+ Shortcut { sequence: "Space"; enabled: !(root.activeFocusItem instanceof AbstractButton) && !(root.useCider && root.queueOpen && trackList.activeFocus) && !(root.libraryOpen && musicBrowser.item && musicBrowser.item.trackListFocused) && !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); root.deckPlayer.count ? root.deckPlayer.toggle() : (root.useYoutube || root.useServer) ? root.openLibrary() : root.useCider ? root.ciderService.toggle() : files.open() } }
+ Shortcut { sequence: "Ctrl+V"; enabled: !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); root.openMusicLink("", true) } }
+ Shortcut { sequence: "Ctrl+O"; enabled: !root.menuOpen; onActivated: { root.revealChrome(); files.open() } }
+ Shortcut { sequence: "Ctrl+Shift+O"; enabled: !root.menuOpen; onActivated: { root.revealChrome(); folder.open() } }
+ Shortcut { sequence: "Ctrl+Q"; onActivated: { root.revealChrome(); Qt.quit() } }
+ Shortcut { sequence: "Ctrl+F"; enabled: !root.menuOpen; onActivated: { root.revealChrome(); root.libraryOpen ? (root.useServer ? serverBrowser.item.focusSearch() : root.useYoutube ? youtubeBrowser.item.focusSearch() : musicBrowser.focusSearch()) : root.openQueueSearch() } }
+ Shortcut { sequence: "Ctrl+B"; enabled: (root.useCider || root.useYoutube || root.useServer) && !root.menuOpen; onActivated: { root.revealChrome(); root.openLibrary() } }
+ Shortcut { sequence: "Ctrl+L"; enabled: !root.menuOpen; onActivated: { root.revealChrome(); root.toggleQueue() } }
+ Shortcut { sequence: "Ctrl+I"; enabled: !root.menuOpen; onActivated: { root.revealChrome(); root.toggleImmersion() } }
+ Shortcut { sequence: "Ctrl+M"; enabled: !root.menuOpen; onActivated: { root.revealChrome(); player.miniMode = !player.miniMode } }
+ Shortcut { sequence: "Right"; enabled: !(root.activeFocusItem instanceof Slider) && !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); root.deckPlayer.seek(root.deckPlayer.position + 5000) } }
+ Shortcut { sequence: "Left"; enabled: !(root.activeFocusItem instanceof Slider) && !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); root.deckPlayer.seek(root.deckPlayer.position - 5000) } }
+ Shortcut { sequence: "Ctrl+Right"; enabled: !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); root.deckPlayer.next() } }
+ Shortcut { sequence: "Ctrl+Left"; enabled: !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); root.deckPlayer.previous() } }
+ Shortcut { sequence: "Up"; enabled: !(root.activeFocusItem instanceof Slider) && !root.libraryOpen && !trackList.activeFocus && !root.menuOpen && !root.editingText && !(root.discFlipped && (albumList.activeFocus || lyricList.activeFocus)); onActivated: { root.revealChrome(); root.deckPlayer.volume = Math.min(1, root.deckPlayer.volume + .05) } }
+ Shortcut { sequence: "Down"; enabled: !(root.activeFocusItem instanceof Slider) && !root.libraryOpen && !trackList.activeFocus && !root.menuOpen && !root.editingText && !(root.discFlipped && (albumList.activeFocus || lyricList.activeFocus)); onActivated: { root.revealChrome(); root.deckPlayer.volume = Math.max(0, root.deckPlayer.volume - .05) } }
+ Shortcut { sequence: "M"; enabled: !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); root.toggleMute() } }
+ Shortcut { sequence: "Escape"; onActivated: { root.revealChrome(); if(root.threeDPointer || root.threeDHardwarePressed) { root.cancel3DPointer();return }; if(artworkPopup.visible) { artworkPopup.close();return }; if(root.activeSeekControl) { root.cancelSeekPreview();return }; if(scrubber.scrubbing) { scrubber.cancelScrub();return }; if(root.libraryDragging) { root.endLibraryDrag(false);return }; if(quickJump.visible) { quickJump.close();return }; if(savedQueuePicker.visible) { savedQueuePicker.close();return }; if(cleanupPopup.visible) { cleanupPopup.close();return }; if(qualityPopup.visible) { qualityPopup.close();return }; if (saveQueuePopup.visible) { saveQueuePopup.close(); return }; if (deleteQueuePopup.visible) { deleteQueuePopup.close(); return }; if (savedQueueMenu.visible) { savedQueueMenu.close(); return }; if (fontPicker.shown || fontPicker.opening) { fontPicker.close(); return }; if (preferences.visible) { preferences.close(); return }; if (crossfadeMenu.visible) { crossfadeMenu.close(); return }; if (queueMenu.visible) { queueMenu.close(); return }; if (songMenu.visible) { songMenu.close(); return }; if (serverBrowser.item && serverBrowser.item.actionsOpen) { serverBrowser.item.closeActions(); return }; if (youtubeBrowser.item && youtubeBrowser.item.actionsOpen) { youtubeBrowser.item.closeActions(); return }; if (musicBrowser.actionsOpen) { musicBrowser.closeActions(); return }; if (menu.visible) { menu.close(); return }; if (root.queueSelectionCount > 0) { root.clearQueueSelection(); return }; if (root.queueSearchOpen) { root.closeQueueSearch(); return }; if (root.libraryOpen) { if(root.useYoutube || root.useServer){root.libraryOpen=false;return}; if (musicBrowser.item && musicBrowser.item.selectionCount > 0) musicBrowser.item.clearSelection(); else if (musicBrowser.detail && musicBrowser.browser.collectionQuery.length) musicBrowser.browser.collectionQuery = ""; else if (musicBrowser.detail) musicBrowser.browser.back(); else root.libraryOpen = false; return }; if (root.immersive) { root.immersive = false; return }; if (root.discFlipped) { root.discFlipped = false; return }; root.queueOpen = false; root.helpOpen = false; menu.close(); if (root.miniMode) player.miniMode = false } }
+ Shortcut { sequence: "Y"; enabled: !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); if (root.deckPlayer.count) { root.discFlipped = true; root.lyricsView = !root.lyricsView } } }
+ Shortcut { sequence: "F"; enabled: !root.editingText && !root.menuOpen; onActivated: { root.revealChrome(); root.flipDisc() } }
+ Shortcut { sequence: "F1"; enabled: !root.menuOpen; onActivated: { root.revealChrome(); root.helpOpen = !root.helpOpen } }
FileDialog {
id: files
@@ -612,6 +650,8 @@ ApplicationWindow {
Rectangle {
id: badge
objectName: "sourceBar"
+ opacity: root.chromeHidden ? 0 : 1
+ Behavior on opacity { NumberAnimation { duration: SpunStyle.feedback; easing.type: Easing.BezierSpline; easing.bezierCurve: SpunStyle.effectsCurve } }
visible: !root.miniMode
x: (root.playerWidth - width) / 2; y: 13; width: platformNative.hyprland ? 504 : 512; height: 48; radius: 24
readonly property real tabWidth: platformNative.hyprland ? 80 : 64
@@ -1008,7 +1048,7 @@ ApplicationWindow {
width: lyricList.width-10; x: 5
text: modelData.text; textFormat: Text.PlainText
wrapMode: Text.WordWrap; horizontalAlignment: Text.AlignHCenter
- font.pixelSize: root.miniMode ? 19 : 15
+ font.pixelSize: root.immersive ? 22 : root.miniMode ? 19 : 15
color: (seekable && lyricList.hoveredLine === lyricLine) || (root.lyricService.timed && index === root.lyricService.currentIndex) ? root.accent : root.ink
opacity: root.lyricService.timed && index !== root.lyricService.currentIndex && !(seekable && lyricList.hoveredLine === lyricLine) ? .62 : 1
Behavior on color { ColorAnimation { duration: SpunStyle.feedback; easing.type: Easing.BezierSpline; easing.bezierCurve: SpunStyle.effectsCurve } }
@@ -1327,6 +1367,8 @@ ApplicationWindow {
Button {
id: mixerToggle
objectName: "tx6Toggle"
+ opacity: root.chromeHidden ? 0 : 1
+ Behavior on opacity { NumberAnimation { duration: SpunStyle.feedback; easing.type: Easing.BezierSpline; easing.bezierCurve: SpunStyle.effectsCurve } }
// The visible pill keeps its position; the surrounding target is 48 px.
x: root.playerWidth - 102; y: 73; width: 74; height: 48
hoverEnabled: true; focusPolicy: Qt.StrongFocus
@@ -1342,7 +1384,7 @@ ApplicationWindow {
border.color: mixerToggle.visualFocus ? root.accent : Qt.alpha(root.mutedInk,.25)
SpunStateLayer { anchors.fill: parent; radius: parent.radius; color: root.ink; hovered: mixerToggle.hovered; pressed: mixerToggle.down; focused: mixerToggle.visualFocus }
}
- SpunToolTip { visible: mixerToggle.hovered; text: mixerToggle.checked ? "Hide TX-6 mixer" : "Show TX-6 mixer" }
+ SpunToolTip { visible: mixerToggle.hovered && !root.chromeHidden; text: mixerToggle.checked ? "Hide TX-6 mixer" : "Show TX-6 mixer" }
contentItem: SpunText { text: parent.text; color: parent.checked?root.accent:root.mutedInk; font.pixelSize:12; horizontalAlignment:Text.AlignHCenter; verticalAlignment:Text.AlignVCenter }
}
DropArea {
@@ -1392,6 +1434,8 @@ ApplicationWindow {
Rectangle {
id: deck
objectName: "playerDeck"
+ opacity: root.chromeHidden ? 0 : 1
+ Behavior on opacity { NumberAnimation { duration: SpunStyle.feedback; easing.type: Easing.BezierSpline; easing.bezierCurve: SpunStyle.effectsCurve } }
visible: !root.miniMode
x: (root.playerWidth - width) / 2; y: 533 + root.mixerHeightExtra; width: 406; height: 144 + (root.showHorizontalSeek ? 28 : 0); radius: SpunStyle.panelRadius
color: root.surface; border.width: 0
@@ -1412,12 +1456,13 @@ ApplicationWindow {
AbstractButton {
id: playerArtist
objectName: "playerArtistLink"
- x: 24; y: 44; width: 284; height: 28
- enabled: (root.useCider || root.useYoutube || root.useServer) && root.deckPlayer.artist.length > 0; hoverEnabled: true
+ x: 24; y: 44; width: root.playbackFailed ? 268 : 284; height: 28
+ enabled: !root.playbackFailed && (root.useCider || root.useYoutube || root.useServer) && root.deckPlayer.artist.length > 0; hoverEnabled: true
Accessible.name: "View artist " + root.deckPlayer.artist
background: null
onClicked: root.openArtistName(root.deckPlayer.artist)
- contentItem: SpunText { text: root.deckPlayer.artist; color: playerArtist.hovered || playerArtist.visualFocus ? root.accent : root.mutedInk; elide: Text.ElideRight; font.pixelSize: SpunStyle.body; verticalAlignment: Text.AlignVCenter; font.underline: playerArtist.hovered || playerArtist.visualFocus }
+ Accessible.description: root.playbackFailed ? root.deckPlayer.error : ""
+ contentItem: SpunText { text: root.playbackFailed ? root.deckPlayer.error : root.deckPlayer.artist; color: root.playbackFailed ? theme.colors.error : playerArtist.hovered || playerArtist.visualFocus ? root.accent : root.mutedInk; elide: Text.ElideRight; font.pixelSize: SpunStyle.body; verticalAlignment: Text.AlignVCenter; font.underline: playerArtist.hovered || playerArtist.visualFocus }
}
SpunText {
objectName: "elapsedTime"
@@ -1427,6 +1472,20 @@ ApplicationWindow {
text: root.time(root.deckPlayer.position); color: root.mutedInk
font.pixelSize: 13
}
+ SpunButton {
+ objectName: "remotePlaybackRetry"
+ x: 306; y: 36; width: 84; height: 48
+ text: "Retry"; visible: root.playbackFailed
+ Accessible.description: root.deckPlayer.error
+ enabled: !root.serverLibrary.buffering
+ onClicked: root.serverLibrary.retry()
+ }
+ SpunLoading {
+ objectName: "remotePlaybackLoading"
+ x: 24; y: 70; width: 358; height: 8
+ visible: root.useServer && root.serverLibrary.buffering
+ label: "Loading song"
+ }
SeekSlider {
app: root; objectName: "horizontalSeek"
visible: root.showHorizontalSeek; x: 24; y: 72; width: 358; height: 32
@@ -2141,6 +2200,7 @@ ApplicationWindow {
SettingsGap {}
SettingsAction { objectName: "quickJumpAction"; text: "Quick jump"; hint: "Ctrl+K"; glyphName: "search"; onTriggered: root.openQuickJump() }
SettingsAction { objectName: "flipDiscAction"; text: root.discFlipped ? "Show artwork" : "Flip disc"; glyphName: "flip"; hint: "F"; enabled: root.deckPlayer.count > 0; onTriggered: root.flipDisc() }
+ SettingsAction { objectName: "immersionToggle"; text: "Immersive mode"; hint: "Ctrl+I"; glyphName: "artwork"; height: 48; checkable: true; checked: root.immersive; onTriggered: root.toggleImmersion() }
SettingsAction { objectName: "miniToggle"; text: "Mini mode"; glyphName: "mini"; checkable: true; checked: player.miniMode; onTriggered: player.miniMode = !player.miniMode }
SettingsAction { objectName: "preferencesAction"; text: "Preferences"; glyphName: "settings"; onTriggered: Qt.callLater(function() { preferences.open() }) }
SettingsAction { text: "Play demo"; glyphName: "play"; onTriggered: { root.useLocal(); player.demo() } }
@@ -2433,7 +2493,7 @@ ApplicationWindow {
}
Rectangle {
- visible: root.deckPlayer.error.length > 0
+ visible: !root.useServer && root.deckPlayer.error.length > 0
x: 73; y: 419; width: 384; height: Math.max(78, errorText.implicitHeight+28); radius: 14
color: root.surface; border.color: theme.colors.error
SpunText { id: errorText; x: 14; y: 14; width: 310; text: root.deckPlayer.error; color: root.ink; font.pixelSize: SpunStyle.caption; wrapMode: Text.WordWrap }
@@ -2481,7 +2541,7 @@ ApplicationWindow {
["Ctrl + M", "Mini / full player"], ["Ctrl + B", "Browse Cider music"],
["Ctrl + V", "Open music link"], ["F", "Flip disc"], ["Y", "Lyrics / album tracks"],
["Ctrl / Shift + click", "Select tracks"], ["Ctrl + A / Space", "Select all / toggle*"],
- ["Alt + G", "Focus Undo notice"], ["Esc", "Back / close"], ["F1", "Keyboard shortcuts"]
+ ["Ctrl + I", "Immersive mode"], ["Alt + G", "Focus Undo notice"], ["Esc", "Back / close"], ["F1", "Keyboard shortcuts"]
]
Item {
required property var modelData
diff --git a/qml/RemoteLibraryPanel.qml b/qml/RemoteLibraryPanel.qml
index 3c17dbb..b1e3893 100644
--- a/qml/RemoteLibraryPanel.qml
+++ b/qml/RemoteLibraryPanel.qml
@@ -25,7 +25,24 @@ Rectangle {
}
color: app.surface
radius: SpunStyle.panelRadius
- onProviderChanged: { closeActions(); search.text = ""; selected = ({}); selectedIndex = -1; searchFilter = "albums" }
+ property bool restoringView: false
+ onProviderChanged: { closeActions(); selected = ({}); selectedIndex = -1; Qt.callLater(restoreView) }
+ Component.onCompleted: restoreView()
+ function saveView() {
+ if (!provider || restoringView) return;
+ provider.viewState = { query: search.text, filter: searchFilter, y: list.contentY, index: list.currentIndex };
+ }
+ function restoreView() {
+ if (!provider) return;
+ restoringView = true;
+ const state = provider.viewState;
+ search.text = state.query || "";
+ const filter = state.filter || selectedPage;
+ searchFilter = ["albums", "artists", "songs", "playlists"].includes(filter) ? filter : ["albums", "artists", "songs", "playlists"].includes(selectedPage) ? selectedPage : "songs";
+ list.currentIndex = state.index === undefined ? -1 : Math.min(state.index, list.count - 1);
+ list.contentY = Math.max(list.originY, Math.min(state.y || 0, Math.max(list.originY, list.contentHeight - list.height)));
+ restoringView = false;
+ }
function closeActions() {
actions.close();
pageActions.close();
@@ -78,6 +95,7 @@ Rectangle {
}
Connections {
target: provider
+ function onViewRestored() { Qt.callLater(panel.restoreView) }
function onChanged() {
panel.revision++;
}
@@ -151,8 +169,7 @@ Rectangle {
Keys.onReturnPressed: clicked()
Keys.onEnterPressed: clicked()
onClicked: {
- panel.searchFilter = modelData;
- search.text = "";
+ panel.saveView();
provider.show(modelData);
}
}
@@ -177,7 +194,8 @@ Rectangle {
height: 44
maximumLength: 512
placeholderText: "Search " + panel.searchFilter
- onAccepted: provider.search(text, panel.searchFilter)
+ onTextEdited: panel.saveView()
+ onAccepted: { panel.saveView(); provider.search(text, panel.searchFilter) }
Keys.onDownPressed: {
list.forceActiveFocus();
if (list.count)
@@ -192,7 +210,7 @@ Rectangle {
tip: "Back"
ink: panel.app.ink
enabled: provider.canBack
- onClicked: provider.back()
+ onClicked: { panel.saveView(); provider.back() }
}
SpunText {
visible: server.connected
@@ -246,7 +264,8 @@ Rectangle {
SpunLoading {
objectName: panel.prefix + "Loading"
x: 24
- y: 160
+ y: 152
+ height: 8
width: parent.width - 48
visible: server.connected && provider.busy
label: "Loading music"
@@ -258,16 +277,18 @@ Rectangle {
y: 164
width: parent.width - 16
height: parent.height - y - 56
- visible: server.connected && !provider.error.length
+ visible: server.connected && provider.items.length > 0
model: provider.items
clip: true
spacing: 2
boundsBehavior: Flickable.StopAtBounds
ScrollBar.vertical: ScrollBar {}
- Keys.onReturnPressed: if (currentIndex >= 0)
- provider.open(provider.items[currentIndex])
- Keys.onEnterPressed: if (currentIndex >= 0)
- provider.open(provider.items[currentIndex])
+ onMovementEnded: panel.saveView()
+ function openCurrent() { if (currentIndex >= 0) { panel.saveView(); provider.open(provider.items[currentIndex]) } }
+ Keys.onReturnPressed: openCurrent()
+ Keys.onEnterPressed: openCurrent()
+ Keys.onUpPressed: { decrementCurrentIndex(); panel.saveView() }
+ Keys.onDownPressed: { incrementCurrentIndex(); panel.saveView() }
delegate: ItemDelegate {
id: row
required property var modelData
@@ -294,6 +315,7 @@ Rectangle {
}
onClicked: {
list.currentIndex = index;
+ panel.saveView();
provider.open(modelData);
}
Image {
@@ -353,12 +375,13 @@ Rectangle {
}
Column {
x: 24
- y: 210
+ y: provider.items.length ? parent.height - 56 : 210
width: parent.width - 48
spacing: 12
visible: server.connected && !provider.busy && (!!provider.error.length || !provider.items.length)
SpunText {
width: parent.width
+ visible: !provider.items.length
text: provider.error || "No results"
wrapMode: Text.WordWrap
color: provider.error.length ? theme.colors.error : panel.app.mutedInk
@@ -366,13 +389,14 @@ Rectangle {
}
SpunButton {
text: "Retry"
+ Accessible.description: provider.error
visible: !!provider.error.length
onClicked: provider.reload()
}
}
SpunButton {
objectName: panel.prefix + "More"
- visible: server.connected && provider.more
+ visible: server.connected && provider.more && !provider.error.length
enabled: !provider.busy
anchors.horizontalCenter: parent.horizontalCenter
y: parent.height - 48
@@ -381,7 +405,7 @@ Rectangle {
}
component Action: MenuItem {
id: action
- implicitHeight: 40
+ implicitHeight: 48
font.family: SpunStyle.family
contentItem: SpunText {
text: action.text
@@ -453,7 +477,7 @@ Rectangle {
Action {
text: "Rename playlist…"
visible: panel.playlistPage && !!provider.collection.editable
- height: visible ? 40 : 0
+ height: visible ? 48 : 0
enabled: !provider.actionBusy
onTriggered: {
panel.renameId = provider.collection.remoteId;
@@ -462,9 +486,10 @@ Rectangle {
}
}
Action {
+ objectName: panel.prefix + "DeletePlaylist"
text: "Delete playlist…"
visible: panel.playlistPage && !!provider.collection.deletable
- height: visible ? 40 : 0
+ height: visible ? 48 : 0
enabled: !provider.actionBusy
onTriggered: deleteDialog.open()
}
@@ -485,6 +510,12 @@ Rectangle {
text: panel.selected.kind === "song" ? "Play" : "Open"
onTriggered: provider.open(panel.selected)
}
+ Action {
+ objectName: panel.prefix + "PlayNext"
+ text: "Play next"
+ enabled: panel.selected.kind === "song"
+ onTriggered: provider.playNext(panel.selected)
+ }
Action {
text: "Add to queue"
enabled: panel.selected.kind === "song"
@@ -507,7 +538,7 @@ Rectangle {
text: "Open album"
enabled: !!panel.selected.albumId
onTriggered: provider.open({
- source: "provider",
+ source: provider.server.scheme,
server: panel.selected.server,
kind: "album",
remoteId: panel.selected.albumId,
@@ -518,7 +549,7 @@ Rectangle {
text: "Open artist"
enabled: !!panel.selected.artistId
onTriggered: provider.open({
- source: "provider",
+ source: provider.server.scheme,
server: panel.selected.server,
kind: "artist",
remoteId: panel.selected.artistId,
@@ -528,21 +559,21 @@ Rectangle {
Action {
text: "Remove from playlist"
visible: panel.playlistPage && !!provider.collection.editable
- height: visible ? 40 : 0
+ height: visible ? 48 : 0
enabled: !provider.actionBusy
onTriggered: provider.removeFromPlaylist(panel.selected)
}
Action {
text: "Move up"
visible: panel.playlistPage && !!provider.collection.editable
- height: visible ? 40 : 0
+ height: visible ? 48 : 0
enabled: !provider.actionBusy && panel.selectedIndex > 0
onTriggered: provider.movePlaylistItem(panel.selectedIndex, panel.selectedIndex - 1)
}
Action {
text: "Move down"
visible: panel.playlistPage && !!provider.collection.editable
- height: visible ? 40 : 0
+ height: visible ? 48 : 0
enabled: !provider.actionBusy && panel.selectedIndex >= 0 && panel.selectedIndex < provider.items.length - 1
onTriggered: provider.movePlaylistItem(panel.selectedIndex, panel.selectedIndex + 1)
}
@@ -860,6 +891,7 @@ Rectangle {
}
LibraryDialog {
id: deleteDialog
+ objectName: panel.prefix + "DeleteDialog"
title: "Delete playlist?"
standardButtons: Dialog.Ok | Dialog.Cancel
onAboutToShow: standardButton(Dialog.Ok).text = "Delete"
diff --git a/src/jellyfinapi.cpp b/src/jellyfinapi.cpp
index d2e47fb..861c340 100644
--- a/src/jellyfinapi.cpp
+++ b/src/jellyfinapi.cpp
@@ -933,6 +933,7 @@ void JellyfinApi::file(const QUrl &u, const QString &path, qint64 limit,
}
f->setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner);
auto req = request(u);
+ if (channel == "prefetch") req.setPriority(QNetworkRequest::LowPriority);
req.setTransferTimeout(30000);
auto *r = m_network.get(req);
m_channels[channel] = r;
diff --git a/src/jellyfintest.cpp b/src/jellyfintest.cpp
index 998c74d..a5e5db0 100644
--- a/src/jellyfintest.cpp
+++ b/src/jellyfintest.cpp
@@ -175,6 +175,24 @@ int exerciseJellyfin(Player &local, Jellyfin &jf, QQuickWindow *window,
check(until([&] { return !jf.busy(); }) && jf.items().size() == 105 &&
!jf.more(),
"search pagination returns all 105 songs");
+ QTest::qWait(100);
+ auto *results = find(window->contentItem(), "jellyfinResults");
+ if (!check(results != nullptr,
+ "Jellyfin results are available for scroll restoration"))
+ return 1;
+ results->setProperty("contentY", 700);
+ QMetaObject::invokeMethod(find(window->contentItem(), "jellyfinPanel"),
+ "saveView");
+ click("localSourceButton");
+ click("jellyfinSourceButton");
+ check(until([&] {
+ auto *view = find(window->contentItem(), "jellyfinResults");
+ return view && qAbs(view->property("contentY").toReal() - 700) < 2;
+ }),
+ "source switch restores library scroll position");
+ auto *searchField = find(window->contentItem(), "jellyfinSearch");
+ check(searchField && searchField->property("text").toString() == "Fixture",
+ "source switch restores search query");
QSet<QString> ids;
for (const auto &v : jf.items())
ids.insert(v.toMap().value("id").toString());
@@ -360,7 +378,50 @@ int exerciseJellyfin(Player &local, Jellyfin &jf, QQuickWindow *window,
"source switch preserves local queue and pauses Jellyfin");
click("jellyfinSourceButton");
check(player->count() == 2, "Jellyfin queue survives source switching");
+ const auto beforeNextKey = player->trackKey();
+ auto *panel = find(window->contentItem(), "jellyfinPanel");
+ if (!check(panel != nullptr, "Jellyfin panel is available for menu checks"))
+ return 1;
+ QMetaObject::invokeMethod(panel, "menuFor", Q_ARG(QVariant, QVariant(first)),
+ Q_ARG(QVariant, QVariant(-1)),
+ Q_ARG(QVariant, QVariant()));
+ check(until([&] {
+ auto *action = find(window->contentItem(), "jellyfinPlayNext");
+ return action && action->isVisible();
+ }),
+ "Play next is available in remote song menu");
+ capture("jellyfin-play-next-menu");
+ click("jellyfinPlayNext");
+ check(player->count() == 3 && player->trackKey() == beforeNextKey &&
+ player->queue()[player->currentIndex() + 1].toMap().value(
+ "title") == first.value("title"),
+ "Play next inserts without restarting current song");
+ player->remove(player->currentIndex() + 1);
+ player->failExternal(player->trackKey(),
+ "Connection interrupted. Retry this song.");
+ check(until([&] {
+ auto *retry = find(window->contentItem(), "remotePlaybackRetry");
+ return retry && retry->isVisible();
+ }),
+ "failed remote playback exposes inline Retry");
+ capture("jellyfin-retry");
+ click("remotePlaybackRetry");
+ check(player->trackKey() == beforeNextKey && player->count() == 2 &&
+ until([&] {
+ return player->position() > 200 && player->error().isEmpty();
+ }),
+ "Retry reloads same song and preserves queue");
+ player->pause();
window->setProperty("libraryOpen", false);
+ window->setProperty("immersive", true);
+ window->setProperty("discFlipped", true);
+ window->setProperty("lyricsView", true);
+ check(until([&] { return !jf.loading() && jf.lines().size() == 3; }),
+ "immersive lyrics use the current server timeline");
+ QTest::qWait(200);
+ capture("jellyfin-immersive-lyrics");
+ window->setProperty("discFlipped", false);
+ window->setProperty("immersive", false);
local.setShowPlayerBody(true);
for (const auto &medium : QStringList{"cd", "vinyl", "cassette", "tp7"}) {
local.setMedium(medium);
diff --git a/src/main.cpp b/src/main.cpp
index 29814d0..268633f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -851,7 +851,8 @@ static int exercise(Player &player, Theme &theme, Lyrics &lyrics, QQuickWindow *
for(auto *child:item->childItems())collectHelp(child);
};
collectHelp(window->contentItem());
- bool aligned=helpKeys.size()==21&&helpActions.size()==21;
+ bool aligned=!helpKeys.isEmpty()&&helpKeys.size()==helpActions.size();
+ check(std::any_of(helpActions.cbegin(), helpActions.cend(), [](QQuickItem *item) { return item->property("text").toString() == "Immersive mode"; }), "shortcut help includes immersive mode");
for(int i=0;i<helpKeys.size()&&i<helpActions.size();++i)
aligned &= helpKeys[i]->x()==helpKeys[0]->x()&&helpActions[i]->x()==helpActions[0]->x()
&&helpKeys[i]->width()+12<=helpActions[i]->x()+.01;
diff --git a/src/mediauitest.cpp b/src/mediauitest.cpp
index d7451e1..85ea39a 100644
--- a/src/mediauitest.cpp
+++ b/src/mediauitest.cpp
@@ -52,6 +52,62 @@ int exerciseMediaUi(Player &player, QQuickWindow *window, const QString &temp, c
files.append(QUrl::fromLocalFile(path));
}
player.addUrls(files,false);check(wait([&]{return !player.busy();})&&player.count()==3,"album fixture imports three tracks");
+ // Immersion reuses the physical player and never changes playback state.
+ window->setProperty("queueOpen", true);
+ window->contentItem()->forceActiveFocus(Qt::MouseFocusReason);
+ QTest::mouseMove(window, item("playButton")->mapToScene(QPointF(28,24)).toPoint());
+ QTest::keyClick(window, Qt::Key_I, Qt::ControlModifier);
+ check(wait([&]{return window->property("immersive").toBool();}), "Ctrl+I enters immersive mode");
+ check(!window->property("sideOpen").toBool(), "immersion closes secondary panels");
+ check(wait([&]{return window->property("chromeHidden").toBool();}), "idle immersion hides chrome");
+ check(item("sourceBar")->opacity()==0 && item("playerDeck")->opacity()==0, "reduced motion hides chrome without animation");
+ QTest::qWait(1300);
+ check(window->property("chromeHidden").toBool(), "stationary synthetic hover does not reveal idle controls");
+ const auto *idleTip = item("playButton")->findChild<QObject *>("spunToolTip");
+ check(idleTip && !idleTip->property("visible").toBool(), "hidden immersive controls also dismiss their tooltips");
+ capture("immersive-idle");
+ QTest::keyClick(window, Qt::Key_Space);
+ check(!window->property("chromeHidden").toBool(), "keyboard playback shortcut reveals immersive controls");
+ player.pause();
+ window->setProperty("chromeIdle", true);
+ QTest::mouseMove(window, QPoint(270, 560));
+ check(wait([&]{return !window->property("chromeHidden").toBool();}), "pointer movement restores immersive controls");
+ QTest::keyClick(window, Qt::Key_Tab);
+ QTest::qWait(3100);
+ check(!window->property("chromeHidden").toBool(), "keyboard focus keeps immersive controls visible");
+ capture("immersive-controls");
+ QTest::keyClick(window, Qt::Key_Escape);
+ check(!window->property("immersive").toBool() && window->property("queueOpen").toBool(), "Escape exits immersion and restores previous queue panel");
+ window->setProperty("queueOpen", false);
+ // Repeated entry must refresh the saved panels and preserve transport.
+ const auto immersionTrack = player.trackKey();
+ const int immersionCount = player.count();
+ player.setMiniMode(true);
+ QTest::qWait(100);
+ window->contentItem()->forceActiveFocus(Qt::MouseFocusReason);
+ QTest::keyClick(window, Qt::Key_I, Qt::ControlModifier);
+ check(window->property("immersive").toBool() && !player.miniMode(), "immersion exits mini mode");
+ QTest::keyClick(window, Qt::Key_I, Qt::ControlModifier);
+ check(!window->property("immersive").toBool() && !window->property("sideOpen").toBool(), "leaving immersion from mini keeps panels closed");
+ window->setProperty("libraryOpen", true);
+ QTest::keyClick(window, Qt::Key_I, Qt::ControlModifier);
+ check(window->property("immersive").toBool() && !window->property("sideOpen").toBool(), "immersion closes the previously open library");
+ QTest::keyClick(window, Qt::Key_F1);
+ check(window->property("helpOpen").toBool(), "keyboard help opens during immersion");
+ window->setProperty("chromeIdle", true);
+ check(!window->property("chromeHidden").toBool(), "open help keeps immersive controls visible");
+ QTest::keyClick(window, Qt::Key_I, Qt::ControlModifier);
+ check(window->property("immersive").toBool(), "immersion shortcut is suppressed while help is open");
+ window->setProperty("helpOpen", false);
+ QTest::keyClick(window, Qt::Key_I, Qt::ControlModifier);
+ check(!window->property("immersive").toBool() && window->property("libraryOpen").toBool() && !window->property("queueOpen").toBool(), "second immersion restores library instead of stale queue state");
+ window->setProperty("libraryOpen", false);
+ for (int cycle = 0; cycle < 3; ++cycle) {
+ QTest::keyClick(window, Qt::Key_I, Qt::ControlModifier);
+ QTest::keyClick(window, Qt::Key_I, Qt::ControlModifier);
+ }
+ check(!window->property("immersive").toBool() && !window->property("sideOpen").toBool(), "repeated immersion toggles leave panels closed");
+ check(player.trackKey() == immersionTrack && player.count() == immersionCount && !player.playing(), "immersion toggles preserve the paused song and queue");
// Check actual reverse pixels: valid theme properties alone missed a
// hardcoded silver backing behind light ink in the CD/cassette booklets.
{
diff --git a/src/player.cpp b/src/player.cpp
index cdb7097..65fb34d 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -25,7 +25,7 @@ static QString text(const TagLib::String &s) { return QString::fromStdString(s.t
Player::Player(const QString &settingsPath, QObject *parent, bool external)
: QObject(parent), m_external(external), m_settings(settingsPath, QSettings::IniFormat) {
- connect(this, &Player::queueChanged, this, [this] { m_tracksDirty = true; });
+ connect(this, &Player::queueChanged, this, [this] { m_tracksDirty = true; m_plannedNext.clear(); });
connect(this, &Player::trackChanged, this, &Player::discDetailsChanged);
connect(this, &Player::queueChanged, this, &Player::discDetailsChanged);
connect(&m_audioPreparation, &QFutureWatcherBase::finished, this, [this] {
@@ -280,6 +280,8 @@ void Player::select(int index, bool autoplay) {
m_restorePosition = -1;
dismissError();
m_index = index;
+ m_plannedNext.clear();
+ m_priorityNext.clear();
m_shuffleVisited.insert(m_tracks[index].path);
if (m_media) m_media->setSource(mediaUrl());
loadArt();
@@ -384,6 +386,7 @@ bool Player::playAlbumPosition(const QString &path, qint64 position) {
void Player::next(bool automatic, bool autoplay) {
if (!count()) return;
if (automatic && m_repeat == 2) { seek(0); play(); return; }
+ if (m_index + 1 < count() && !m_priorityNext.isEmpty() && m_tracks[m_index + 1].path == m_priorityNext) { select(m_index + 1, autoplay); return; }
if (m_vinylAlbumMode && vinyl()) {
const auto rows = discDetails().value("tracks").toList();
const bool mapped = rows.size()>=2 && rows.size()<=500 && std::all_of(rows.cbegin(),rows.cend(),[](const QVariant &row){return row.toMap().value("duration").toLongLong()>0;});
@@ -403,7 +406,10 @@ void Player::next(bool automatic, bool autoplay) {
m_shuffleVisited.insert(m_tracks[m_index].path);
for (int i = 0; i < count(); ++i) if (i != m_index) candidates.append(i);
}
- select(candidates[QRandomGenerator::global()->bounded(candidates.size())], autoplay);
+ int selected = -1;
+ for (int i : candidates) if (m_tracks[i].path == m_plannedNext) selected = i;
+ if (selected < 0) selected = candidates[QRandomGenerator::global()->bounded(candidates.size())];
+ select(selected, autoplay);
return;
}
if (m_index + 1 < count()) select(m_index + 1, autoplay);
@@ -468,6 +474,7 @@ void Player::setVolume(double value) {
else emit volumeChanged();
}
void Player::setShuffle(bool value) {
+ m_plannedNext.clear();
m_shuffle = value; m_shuffleVisited.clear();
if (m_index >= 0) m_shuffleVisited.insert(m_tracks[m_index].path);
emit settingsChanged(); save();
@@ -607,6 +614,46 @@ void Player::appendExternalTracks(const QList<Track> &tracks) {
const bool empty = m_tracks.isEmpty(); m_tracks.append(tracks); emit queueChanged();
if (empty) select(0, false);
}
+void Player::insertExternalNext(const QList<Track> &tracks) {
+ if (!m_external || tracks.isEmpty()) return;
+ if (m_index < 0) { appendExternalTracks(tracks); return; }
+ int at = m_index + 1;
+ for (const auto &track : tracks) m_tracks.insert(at++, track);
+ m_priorityNext = tracks.first().path;
+ emit queueChanged();
+}
+int Player::nextTrackIndex(bool automatic) const {
+ if (m_index < 0 || !count() || (automatic && m_repeat == 2)) return -1;
+ if (m_index + 1 < count() && !m_priorityNext.isEmpty() && m_tracks[m_index + 1].path == m_priorityNext) return m_index + 1;
+ if (m_vinylAlbumMode && vinyl()) {
+ const auto rows = discDetails().value("tracks").toList();
+ const bool mapped = rows.size() >= 2 && rows.size() <= 500 && std::all_of(rows.cbegin(), rows.cend(), [](const QVariant &row) { return row.toMap().value("duration").toLongLong() > 0; });
+ for (int i = 0; mapped && i < rows.size(); ++i) if (rows[i].toMap().value("current").toBool())
+ return i + 1 < rows.size() ? rows[i + 1].toMap().value("index").toInt() : (!automatic || m_repeat == 1) ? rows.first().toMap().value("index").toInt() : -1;
+ }
+ if (m_shuffle && count() > 1) {
+ QList<int> candidates;
+ for (int i = 0; i < count(); ++i) if (!m_shuffleVisited.contains(m_tracks[i].path)) candidates.append(i);
+ if (candidates.isEmpty()) {
+ if (automatic && m_repeat == 0) return -1;
+ for (int i = 0; i < count(); ++i) if (i != m_index) candidates.append(i);
+ }
+ for (int i : candidates) if (m_tracks[i].path == m_plannedNext) return i;
+ const int i = candidates[QRandomGenerator::global()->bounded(candidates.size())];
+ m_plannedNext = m_tracks[i].path;
+ return i;
+ }
+ return m_index + 1 < count() ? m_index + 1 : (!automatic || m_repeat == 1) ? 0 : -1;
+}
+void Player::retryExternal() {
+ if (!m_external || m_index < 0) return;
+ // Re-resolve the same queue entry, including decoder failures of a cached file.
+ pause();
+ if (m_media) m_media->setSource({});
+ m_externalSource = QUrl();
+ m_restorePosition = -1;
+ play();
+}
void Player::resolveExternal(const QString &key, const QUrl &source) {
if (!m_external || key != trackKey() || !source.isLocalFile() || !QFileInfo::exists(source.toLocalFile())) return;
const bool autoplay = std::exchange(m_externalWantPlay, false);
diff --git a/src/player.h b/src/player.h
index ecfe937..d229b06 100644
--- a/src/player.h
+++ b/src/player.h
@@ -71,6 +71,10 @@ public:
bool external() const { return m_external; }
void setExternalTracks(const QList<Track> &tracks, int index = 0, bool autoplay = true);
void appendExternalTracks(const QList<Track> &tracks);
+ void insertExternalNext(const QList<Track> &tracks);
+ int nextTrackIndex(bool automatic = true) const;
+ QString queuedTrackKey(int index) const { return index >= 0 && index < count() ? m_tracks[index].path : QString(); }
+ Q_INVOKABLE void retryExternal();
void resolveExternal(const QString &key, const QUrl &source);
void setExternalArtwork(const QString &key, const QImage &image);
void failExternal(const QString &key, const QString &message);
@@ -212,6 +216,8 @@ private:
quint64 m_artGeneration = 0;
bool m_artLoading = false, m_artJobActive = false;
QSet<QString> m_shuffleVisited;
+ mutable QString m_plannedNext;
+ QString m_priorityNext;
QString m_artFile, m_error;
bool m_ciderAutoStart = false;
bool m_threeD=false;
diff --git a/src/remotelibrary.cpp b/src/remotelibrary.cpp
index 1659537..f5d6ce7 100644
--- a/src/remotelibrary.cpp
+++ b/src/remotelibrary.cpp
@@ -17,6 +17,9 @@ RemoteLibrary::RemoteLibrary(const QString &directory, bool restore,
m_api(*m_apiOwner), m_player(directory + "/player.ini", this, true),
m_directory(directory) {
m_player.setExternalName(m_api.serviceName());
+ m_prefetchTimer.setSingleShot(true);
+ m_prefetchTimer.setInterval(300);
+ connect(&m_prefetchTimer, &QTimer::timeout, this, &RemoteLibrary::prefetch);
m_save.setSingleShot(true);
m_save.setInterval(200);
connect(&m_save, &QTimer::timeout, this, &RemoteLibrary::persist);
@@ -26,6 +29,11 @@ RemoteLibrary::RemoteLibrary(const QString &directory, bool restore,
connect(&m_api, &RemoteMusicApi::accountChanged, this, [this] {
persist();
++m_generation;
+ cancelPrefetch();
+ m_pages.clear();
+ m_pageOrder.clear();
+ m_viewState.clear();
+ emit viewRestored();
m_player.stop();
m_player.setExternalTracks({}, 0, false);
m_audio.reset();
@@ -50,6 +58,22 @@ RemoteLibrary::RemoteLibrary(const QString &directory, bool restore,
});
connect(&m_api, &RemoteMusicApi::changed, this, [this] {
m_player.setExternalName(m_api.serviceName());
+ if (m_pageFolder != m_api.folder()) {
+ m_pageFolder = m_api.folder();
+ m_pages.clear();
+ m_pageOrder.clear();
+ ++m_generation;
+ m_api.cancel("catalog");
+ m_busy = false;
+ m_items.clear();
+ m_back.clear();
+ m_viewState.clear();
+ emit viewRestored();
+ }
+ if (m_prefetchBitrate != m_api.bitrate()) {
+ cancelPrefetch();
+ m_prefetchTimer.start();
+ }
if (m_api.connected() && m_identity != m_api.identity()) {
m_identity = m_api.identity();
restoreQueue();
@@ -60,19 +84,42 @@ RemoteLibrary::RemoteLibrary(const QString &directory, bool restore,
});
connect(&m_player, &Player::externalRequested, this,
&RemoteLibrary::loadCurrent);
- connect(&m_player, &Player::externalCancelled, this,
- [this] { m_api.cancel("audio"); });
+ connect(&m_player, &Player::externalCancelled, this, [this] {
+ ++m_audioGeneration;
+ m_api.cancel("audio");
+ m_buffering = false;
+ emit changed();
+ });
connect(&m_player, &Player::trackChanged, this, [this] {
+ if (m_observedKey == m_player.trackKey()) {
+ if (m_player.artwork().isNull())
+ loadArt();
+ m_prefetchTimer.start();
+ emit changed();
+ return;
+ }
+ m_observedKey = m_player.trackKey();
report(true);
- m_audio.reset();
+ // Queue reordering can emit trackChanged without replacing the playing
+ // song.
+ if (m_audioKey != m_player.trackKey())
+ m_audio.reset();
+ ++m_audioGeneration;
m_api.cancel("audio");
+ m_buffering = false;
loadArt();
refresh();
m_save.start();
emit changed();
});
- connect(&m_player, &Player::queueChanged, this, [this] { m_save.start(); });
+ connect(&m_player, &Player::queueChanged, this, [this] {
+ m_save.start();
+ m_prefetchTimer.start();
+ });
+ connect(&m_player, &Player::settingsChanged, this,
+ [this] { m_prefetchTimer.start(); });
connect(&m_player, &Player::playingChanged, this, [this] {
+ m_prefetchTimer.start();
report(m_player.playbackState() == QMediaPlayer::StoppedState &&
!m_player.busy());
});
@@ -87,7 +134,8 @@ RemoteLibrary::RemoteLibrary(const QString &directory, bool restore,
connect(&m_player, &Player::errorChanged, this, [this] {
if (!m_player.error().isEmpty()) {
report(true);
- emit feedback(m_player.error(), true);
+ cancelPrefetch();
+ emit changed();
}
});
m_reportTimer.setInterval(10000);
@@ -95,6 +143,7 @@ RemoteLibrary::RemoteLibrary(const QString &directory, bool restore,
m_reportTimer.start();
}
RemoteLibrary::~RemoteLibrary() {
+ cancelPrefetch();
persist();
report(true);
m_player.stop();
@@ -104,6 +153,8 @@ void RemoteLibrary::setEnabled(bool value) {
return;
m_enabled = value;
if (!value) {
+ cancelPrefetch();
+ ++m_generation;
m_player.pause();
report(true);
m_api.cancel("catalog");
@@ -125,11 +176,13 @@ QVariantMap RemoteLibrary::current() const {
return m_catalog.value(m_player.currentUrl().path().mid(1));
}
void RemoteLibrary::show(const QString &mode) {
+ savePage();
m_back.clear();
m_collection.clear();
browse({{"mode", mode}});
}
void RemoteLibrary::search(const QString &query, const QString &filter) {
+ savePage();
m_back.clear();
m_collection.clear();
browse({{"mode", "search"},
@@ -143,6 +196,7 @@ void RemoteLibrary::open(const QVariantMap &row) {
playItem(row);
return;
}
+ savePage();
m_back.append(
QVariantMap{{"request", m_request}, {"collection", m_collection}});
if (m_back.size() > 30)
@@ -153,16 +207,38 @@ void RemoteLibrary::open(const QVariantMap &row) {
void RemoteLibrary::back() {
if (m_back.isEmpty())
return;
+ savePage();
auto state = m_back.takeLast().toMap();
m_collection = state.value("collection").toMap();
browse(state.value("request").toMap());
}
-void RemoteLibrary::reload() { browse(m_request); }
+void RemoteLibrary::reload() { browse(m_request, false, true); }
void RemoteLibrary::loadMore() {
if (m_more && !m_busy)
browse(m_request, true);
}
-void RemoteLibrary::browse(const QVariantMap &request, bool append) {
+void RemoteLibrary::savePage() {
+ if (m_busy || !m_error.isEmpty() || m_items.isEmpty())
+ return;
+ const auto key = QString::fromUtf8(
+ QJsonDocument::fromVariant(m_request).toJson(QJsonDocument::Compact));
+ m_pages[key] = {{"items", m_items},
+ {"collection", m_collection},
+ {"heading", m_heading},
+ {"more", m_more},
+ {"view", m_viewState}};
+ m_pageOrder.removeAll(key);
+ m_pageOrder.append(key);
+ qsizetype total = 0;
+ for (const auto &page : m_pages)
+ total += page.value("items").toList().size();
+ while (!m_pageOrder.isEmpty() && (m_pages.size() > 6 || total > 20000)) {
+ auto old = m_pageOrder.takeFirst();
+ total -= m_pages.take(old).value("items").toList().size();
+ }
+}
+void RemoteLibrary::browse(const QVariantMap &request, bool append,
+ bool refresh) {
if (!m_api.connected())
return;
++m_generation;
@@ -171,10 +247,33 @@ void RemoteLibrary::browse(const QVariantMap &request, bool append) {
m_thumbBusy = false;
m_thumbPending.clear();
m_thumbActive.clear();
+ m_api.cancel("catalog");
+ const bool same = request == m_request;
m_request = request;
+ const auto key = QString::fromUtf8(
+ QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact));
+ if (!append && !refresh && m_pages.contains(key)) {
+ const auto state = m_pages.value(key);
+ m_items = state.value("items").toList();
+ m_collection = state.value("collection").toMap();
+ m_heading = state.value("heading").toString();
+ m_more = state.value("more").toBool();
+ m_viewState = state.value("view").toMap();
+ m_error.clear();
+ m_busy = false;
+ for (const auto &row : m_items)
+ m_catalog[row.toMap().value("id").toString()] = row.toMap();
+ emit changed();
+ emit viewRestored();
+ loadThumbs();
+ return;
+ }
+ if (!append && !refresh)
+ m_viewState = {{"query", request.value("query")},
+ {"filter", request.value("filter", request.value("mode"))}};
m_busy = true;
m_error.clear();
- if (!append)
+ if (!append && !(refresh && same))
m_items.clear();
auto req = request;
req["offset"] = append ? m_items.size() : 0;
@@ -184,6 +283,7 @@ void RemoteLibrary::browse(const QVariantMap &request, bool append) {
m_heading = mode == "search" ? request.value("query").toString()
: mode.left(1).toUpper() + mode.mid(1);
emit changed();
+ emit viewRestored();
m_api.browse(req, [this, generation, append](const QVariantMap &data,
const QString &error) {
if (generation != m_generation)
@@ -204,6 +304,8 @@ void RemoteLibrary::browse(const QVariantMap &request, bool append) {
m_more = data.value("more").toBool();
if (data.contains("editable"))
m_collection["editable"] = data.value("editable");
+ if (data.contains("deletable"))
+ m_collection["deletable"] = data.value("deletable");
if (data.contains("title"))
m_heading = data.value("title").toString();
// Retain only displayed rows and queued tracks, not every visited page.
@@ -220,6 +322,7 @@ void RemoteLibrary::browse(const QVariantMap &request, bool append) {
loadThumbs();
}
emit changed();
+ emit viewRestored();
});
}
QList<Track> RemoteLibrary::tracks(const QVariantList &rows) {
@@ -260,6 +363,58 @@ void RemoteLibrary::enqueue(const QVariantMap &row) {
emit feedback("Added to queue", false);
}
}
+void RemoteLibrary::playNext(const QVariantMap &row) {
+ const auto queue = tracks({row});
+ if (queue.isEmpty())
+ return;
+ m_player.insertExternalNext(queue);
+ emit feedback("Playing next", false);
+}
+void RemoteLibrary::retry() {
+ cancelPrefetch();
+ m_audio.reset();
+ m_player.retryExternal();
+}
+void RemoteLibrary::cancelPrefetch() {
+ m_prefetchTimer.stop();
+ ++m_prefetchGeneration;
+ m_api.cancel("prefetch");
+ m_prefetched.reset();
+ m_prefetchKey.clear();
+ m_prefetchReady = false;
+ m_prefetchBitrate = m_api.bitrate();
+}
+void RemoteLibrary::prefetch() {
+ const auto key = m_player.queuedTrackKey(m_player.nextTrackIndex());
+ if (!m_enabled || !m_api.connected() || key.isEmpty()) {
+ cancelPrefetch();
+ return;
+ }
+ if (key == m_prefetchKey && m_prefetchBitrate == m_api.bitrate())
+ return;
+ cancelPrefetch();
+ if (!m_audio || !m_player.playing() || m_buffering)
+ return;
+ const auto row = m_catalog.value(QUrl(key).path().mid(1));
+ if (key.isEmpty() || !m_api.owns(row))
+ return;
+ m_prefetchKey = key;
+ const auto generation = m_prefetchGeneration;
+ auto buffer = std::make_shared<QTemporaryDir>();
+ m_prefetched = buffer;
+ m_api.download(
+ row, buffer->filePath("audio"),
+ [this, buffer, key, generation](const QVariantMap &,
+ const QString &error) {
+ if (generation != m_prefetchGeneration || key != m_prefetchKey)
+ return;
+ m_prefetchReady =
+ error.isEmpty() && QFileInfo::exists(buffer->filePath("audio"));
+ if (!m_prefetchReady)
+ m_prefetched.reset();
+ },
+ "prefetch");
+}
void RemoteLibrary::loadCurrent() {
const auto row = current();
const auto key = m_player.trackKey();
@@ -267,21 +422,39 @@ void RemoteLibrary::loadCurrent() {
m_player.failExternal(key, "Connect to this song's music server first.");
return;
}
+ const auto generation = ++m_audioGeneration;
+ if (key == m_prefetchKey && m_prefetchReady &&
+ m_prefetchBitrate == m_api.bitrate()) {
+ m_audio = m_prefetched;
+ m_audioKey = key;
+ cancelPrefetch();
+ m_player.resolveExternal(key,
+ QUrl::fromLocalFile(m_audio->filePath("audio")));
+ m_prefetchTimer.start();
+ return;
+ }
+ cancelPrefetch();
auto buffer = std::make_shared<QTemporaryDir>();
- const auto path = buffer->filePath("audio");
- m_api.download(
- row, path,
- [this, buffer, key](const QVariantMap &, const QString &error) {
- if (key != m_player.trackKey())
- return;
- if (!error.isEmpty()) {
- m_player.failExternal(key, error);
- return;
- }
- m_audio = buffer;
- m_player.resolveExternal(
- key, QUrl::fromLocalFile(buffer->filePath("audio")));
- });
+ m_buffering = true;
+ emit changed();
+ m_api.download(row, buffer->filePath("audio"),
+ [this, buffer, key, generation](const QVariantMap &,
+ const QString &error) {
+ if (generation != m_audioGeneration ||
+ key != m_player.trackKey())
+ return;
+ m_buffering = false;
+ emit changed();
+ if (!error.isEmpty()) {
+ m_player.failExternal(key, error);
+ return;
+ }
+ m_audio = buffer;
+ m_audioKey = key;
+ m_player.resolveExternal(
+ key, QUrl::fromLocalFile(buffer->filePath("audio")));
+ m_prefetchTimer.start();
+ });
}
void RemoteLibrary::loadArt() {
m_api.cancel("cover");
@@ -349,6 +522,8 @@ void RemoteLibrary::loadThumbs() {
}
}
void RemoteLibrary::finishAction(const QString &error, bool refreshPage) {
+ m_pages.clear();
+ m_pageOrder.clear();
m_actionBusy = false;
if (!error.isEmpty())
emit feedback(error, true);
diff --git a/src/remotelibrary.h b/src/remotelibrary.h
index 3012a16..591f0f6 100644
--- a/src/remotelibrary.h
+++ b/src/remotelibrary.h
@@ -11,6 +11,9 @@ class RemoteLibrary : public QObject {
Q_PROPERTY(Player *transport READ transport CONSTANT)
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY changed)
Q_PROPERTY(bool busy READ busy NOTIFY changed)
+ Q_PROPERTY(bool buffering READ buffering NOTIFY changed)
+ Q_PROPERTY(QVariantMap viewState READ viewState WRITE setViewState NOTIFY
+ viewRestored)
Q_PROPERTY(bool more READ more NOTIFY changed)
Q_PROPERTY(bool actionBusy READ actionBusy NOTIFY changed)
Q_PROPERTY(QString error READ error NOTIFY changed)
@@ -36,6 +39,9 @@ public:
bool enabled() const { return m_enabled; }
void setEnabled(bool);
bool busy() const { return m_busy; }
+ bool buffering() const { return m_buffering; }
+ QVariantMap viewState() const { return m_viewState; }
+ void setViewState(const QVariantMap &state) { m_viewState = state; }
bool more() const { return m_more; }
bool actionBusy() const { return m_actionBusy; }
QString error() const { return m_error; }
@@ -56,6 +62,8 @@ public:
Q_INVOKABLE void playItems(const QVariantList &, int index = 0);
Q_INVOKABLE void playItem(const QVariantMap &);
Q_INVOKABLE void enqueue(const QVariantMap &);
+ Q_INVOKABLE void playNext(const QVariantMap &);
+ Q_INVOKABLE void retry();
Q_INVOKABLE bool favorite(const QString &id) const {
return m_api.isStarred(id);
}
@@ -81,9 +89,13 @@ signals:
void currentIndexChanged();
void feedback(const QString &message, bool error);
void artworkChanged();
+ void viewRestored();
private:
- void browse(const QVariantMap &, bool append = false);
+ void browse(const QVariantMap &, bool append = false, bool refresh = false);
+ void savePage();
+ void cancelPrefetch();
+ void prefetch();
void loadCurrent();
void loadArt();
void loadThumbs();
@@ -113,6 +125,14 @@ private:
QString m_thumbActive;
std::shared_ptr<QTemporaryDir> m_audio, m_art;
QTemporaryDir m_thumbnailDirectory;
- QTimer m_save, m_reportTimer;
+ QTimer m_save, m_reportTimer, m_prefetchTimer;
+ bool m_buffering = false, m_prefetchReady = false;
+ quint64 m_audioGeneration = 0, m_prefetchGeneration = 0;
+ int m_prefetchBitrate = -1;
+ QString m_prefetchKey, m_audioKey, m_observedKey, m_pageFolder;
+ std::shared_ptr<QTemporaryDir> m_prefetched;
+ QVariantMap m_viewState;
+ QHash<QString, QVariantMap> m_pages;
+ QStringList m_pageOrder;
LyricTimeline m_timeline;
};
diff --git a/src/remotelibrarytest.cpp b/src/remotelibrarytest.cpp
new file mode 100644
index 0000000..0eec3e7
--- /dev/null
+++ b/src/remotelibrarytest.cpp
@@ -0,0 +1,605 @@
+#include "remotelibrary.h"
+#include <QFile>
+#include <QSignalSpy>
+#include <QTemporaryDir>
+#include <QtTest>
+
+// Controllable replies deliberately permit late completion after cancellation.
+// This exercises controller guards independently of a protocol adapter's
+// guards.
+class FixtureMusicApi final : public RemoteMusicApi {
+public:
+ explicit FixtureMusicApi(const QString &source = "jellyfin")
+ : protocol(source) {}
+ QString protocol, selectedFolder;
+ struct Download {
+ QString key, path, channel;
+ Reply reply;
+ };
+ QList<Download> downloads;
+ QList<QPair<QVariantMap, Reply>> pages;
+ QStringList cancelled;
+ QString account = "fixture";
+ int quality = 0;
+ bool online = true;
+ QString serviceName() const override { return "Fixture"; }
+ QString scheme() const override { return protocol; }
+ bool connected() const override { return online; }
+ bool connecting() const override { return false; }
+ QString address() const override { return {}; }
+ QString username() const override { return "listener"; }
+ QString identity() const override { return account; }
+ QString error() const override { return {}; }
+ QVariantList playlists() const override { return {}; }
+ QVariantList folders() const override { return {}; }
+ QString folder() const override { return selectedFolder; }
+ bool scrobbling() const override { return false; }
+ int bitrate() const override { return quality; }
+ bool keyringAvailable() const override { return false; }
+ void setFolder(const QString &value) override {
+ selectedFolder = value;
+ emit changed();
+ }
+ void setScrobbling(bool) override {}
+ void setBitrate(int n) override {
+ quality = n;
+ emit changed();
+ }
+ void connectServer(const QString &, const QString &, const QString &,
+ bool) override {}
+ void disconnectServer() override {
+ online = false;
+ account = "other";
+ emit accountChanged();
+ emit changed();
+ }
+ void reloadPlaylists() override {}
+ void createPlaylist(const QString &, Reply reply) override {
+ if (reply)
+ reply({}, {});
+ }
+ void cancel(const QString &channel) override { cancelled.append(channel); }
+ void browse(const QVariantMap &request, Reply reply,
+ const QString &) override {
+ pages.append({request, reply});
+ }
+ void cover(const QVariantMap &, const QString &path, Reply reply,
+ const QString &) override {
+ QImage image(12, 12, QImage::Format_RGB32);
+ image.fill(QColor("#88ccee"));
+ image.save(path, "PNG");
+ reply({{"file", path}}, {});
+ }
+ void lyrics(const QVariantMap &, Reply reply) override { reply({}, {}); }
+ void download(const QVariantMap &row, const QString &path, Reply reply,
+ const QString &channel) override {
+ downloads.append({row.value("id").toString(), path, channel, reply});
+ }
+ void star(const QVariantMap &, bool, Reply reply) override { reply({}, {}); }
+ void editPlaylist(const QString &, const Params &, Reply reply) override {
+ reply({}, {});
+ }
+ void movePlaylistItem(const QString &, const QString &, int,
+ Reply reply) override {
+ reply({}, {});
+ }
+ void removePlaylist(const QString &, Reply reply) override { reply({}, {}); }
+ bool owns(const QVariantMap &row) const override {
+ return online && row.value("server") == account &&
+ row.value("source") == scheme();
+ }
+ bool isStarred(const QString &) const override { return false; }
+ QVariantMap item(const QVariantMap &raw, const QString &) const override {
+ return raw;
+ }
+ QUrl artworkUrl(const QUrl &) const override { return {}; }
+ QNetworkRequest artworkRequest(const QUrl &) const override { return {}; }
+ QUrl shareUrl(const QVariantMap &) const override { return {}; }
+ void reportPlayback(const QVariantMap &, qint64, bool, bool) override {}
+ QVariantMap row(const QString &id, const QString &kind = "song") const {
+ return {{"id", id}, {"remoteId", id}, {"source", scheme()},
+ {"server", account}, {"kind", kind}, {"title", id},
+ {"seconds", 180}, {"artist", "Fixture"}};
+ }
+ void finishPage(int i, const QVariantList &rows, bool more = false,
+ const QString &error = {}) {
+ pages[i].second({{"items", rows}, {"more", more}}, error);
+ }
+ void finishDownload(int i, const QString &error = {}) {
+ const auto request = downloads[i];
+ if (error.isEmpty()) {
+ QFile::remove(request.path);
+ QVERIFY(QFile::copy(QStringLiteral(SPUN_DEMO_FILE), request.path));
+ }
+ request.reply({}, error);
+ }
+};
+
+class RemoteLibraryTest : public QObject {
+ Q_OBJECT
+ static void providerRows() {
+ QTest::addColumn<QString>("source");
+ QTest::newRow("jellyfin") << QString("jellyfin");
+ QTest::newRow("subsonic-navidrome") << QString("subsonic");
+ }
+private slots:
+ void navigationAndRefresh() {
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi;
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ QCOMPARE(api->pages.size(), 1);
+ const auto album = api->row("album", "album");
+ api->finishPage(0, {album});
+ library.setViewState(
+ {{"query", "draft"}, {"filter", "albums"}, {"y", 220}, {"index", 3}});
+ library.open(album);
+ api->finishPage(1, {api->row("a"), api->row("b")});
+ library.back();
+ QCOMPARE(api->pages.size(), 2);
+ QCOMPARE(library.items(), QVariantList{album});
+ QCOMPARE(library.viewState().value("query").toString(), QString("draft"));
+ QCOMPARE(library.viewState().value("y").toInt(), 220);
+ library.reload();
+ QVERIFY(library.busy());
+ QCOMPARE(library.items(), QVariantList{album});
+ api->finishPage(2, {}, false, "Offline");
+ QCOMPARE(library.items(), QVariantList{album});
+ QCOMPARE(library.error(), QString("Offline"));
+ library.reload();
+ api->finishPage(3, {album, api->row("second", "album")}, true);
+ QCOMPARE(library.items().size(), 2);
+ library.loadMore();
+ QCOMPARE(api->pages.last().first.value("offset").toInt(), 2);
+ api->finishPage(4, {api->row("third", "album")});
+ QCOMPARE(library.items().size(), 3);
+ library.setEnabled(false);
+ library.setEnabled(true);
+ QCOMPARE(api->pages.size(), 5);
+ QCOMPARE(library.viewState().value("y").toInt(), 220);
+ }
+ void stalePagesAndAccount() {
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi;
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ library.search("wanted", "songs");
+ api->finishPage(1, {api->row("new")});
+ api->finishPage(0, {api->row("old")});
+ QCOMPARE(library.items().first().toMap().value("id").toString(),
+ QString("new"));
+ library.show("artists");
+ library.setEnabled(false);
+ api->finishPage(2, {api->row("late")});
+ QVERIFY(library.items().isEmpty());
+ api->disconnectServer();
+ QVERIFY(library.items().isEmpty());
+ QVERIFY(library.viewState().isEmpty());
+ QVERIFY(!library.canBack());
+ }
+ void boundedPageHistory() {
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi;
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ api->finishPage(0, {api->row("first", "album")});
+ for (int i = 0; i < 8; ++i) {
+ library.search(QString::number(i), "songs");
+ api->finishPage(i + 1, {api->row(QString::number(i))});
+ }
+ library.search("6", "songs");
+ QCOMPARE(api->pages.size(), 9); // Recent query is restored immediately.
+ library.show("albums");
+ QCOMPARE(api->pages.size(), 10); // Oldest page was evicted.
+ }
+ void nextPreservesTransportAndOverridesShuffle() {
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi;
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b"), api->row("c")});
+ QCOMPARE(api->downloads.size(), 1);
+ const auto key = player->trackKey();
+ player->setShuffle(true);
+ library.playNext(api->row("next"));
+ QCOMPARE(player->trackKey(), key);
+ QCOMPARE(api->downloads.size(), 1);
+ QCOMPARE(player->count(), 4);
+ QCOMPARE(player->queue()[1].toMap().value("title").toString(),
+ QString("next"));
+ player->next(false, false);
+ QVERIFY(player->trackKey().endsWith("/next"));
+ QVERIFY(!player->playing());
+ library.enqueue(api->row("last"));
+ QCOMPARE(player->queue().last().toMap().value("title").toString(),
+ QString("last"));
+ }
+ void selectingSameTrackKeepsArtwork() {
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi;
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ library.playItem(api->row("a"));
+ auto *player = library.transport();
+ QVERIFY(!player->artwork().isNull());
+ player->select(0, false);
+ QVERIFY(!player->artwork().isNull());
+ }
+ void retryAndSameTrackLateReply() {
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi;
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b")});
+ QVERIFY(library.buffering());
+ api->finishDownload(0, "Temporary failure");
+ QVERIFY(!library.buffering());
+ QCOMPARE(player->error(), QString("Temporary failure"));
+ library.retry();
+ QCOMPARE(api->downloads.size(), 2);
+ QCOMPARE(player->currentIndex(), 0);
+ QCOMPARE(player->count(), 2);
+ QVERIFY(player->error().isEmpty());
+ api->finishDownload(0, "Stale failure");
+ QVERIFY(player->error().isEmpty());
+ QVERIFY(library.buffering());
+ player->pause();
+ api->finishDownload(1, "Cancelled failure");
+ QVERIFY(!library.buffering());
+ QVERIFY(player->error().isEmpty());
+ }
+ void prefetchConsumesOnlyOneAndInvalidates() {
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi;
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b"), api->row("c")});
+ api->finishDownload(0);
+ QTRY_COMPARE_WITH_TIMEOUT(api->downloads.size(), 2, 5000);
+ QCOMPARE(api->downloads[1].channel, QString("prefetch"));
+ QCOMPARE(api->downloads[1].key, QString("b"));
+ api->finishDownload(1);
+ QTest::qWait(400);
+ QCOMPARE(api->downloads.size(), 2);
+ player->next();
+ QVERIFY(player->trackKey().endsWith("/b"));
+ QVERIFY(!library.buffering());
+ QCOMPARE(api->downloads.size(),
+ 2); // Consumed cache, no foreground download.
+ QTRY_COMPARE_WITH_TIMEOUT(api->downloads.size(), 3, 5000);
+ QCOMPARE(api->downloads[2].key, QString("c"));
+ library.playNext(api->row("priority"));
+ QTRY_COMPARE_WITH_TIMEOUT(api->downloads.size(), 4, 5000);
+ QCOMPARE(api->downloads[3].key, QString("priority"));
+ api->finishDownload(2); // Completion of superseded c must not become ready.
+ api->finishDownload(3);
+ api->setBitrate(128);
+ QTRY_COMPARE_WITH_TIMEOUT(api->downloads.size(), 5, 5000);
+ api->finishDownload(4);
+ const auto prefetchedPath = api->downloads[4].path;
+ library.setEnabled(false);
+ // Fixture retains callbacks, so release their captured buffers too.
+ api->downloads.clear();
+ QVERIFY(!QFile::exists(prefetchedPath));
+ QVERIFY(!player->playing());
+ }
+ void reorderingKeepsBufferedAudio() {
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi;
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b")});
+ api->finishDownload(0);
+ QTRY_VERIFY_WITH_TIMEOUT(player->position() > 100, 5000);
+ const auto key = player->trackKey();
+ const auto file = api->downloads[0].path;
+ player->move(0, 1);
+ QCOMPARE(player->trackKey(), key);
+ QCOMPARE(api->downloads.size(), 1);
+ QVERIFY(QFile::exists(file));
+ QVERIFY(player->playing());
+ QTRY_VERIFY_WITH_TIMEOUT(player->position() > 200, 5000);
+ }
+ void shufflePlanMatchesPlayback() {
+ QTemporaryDir dir;
+ Player player(dir.filePath("player.ini"), nullptr, true);
+ QList<Track> tracks;
+ for (int i = 0; i < 5; ++i) {
+ Track t;
+ t.path = "jellyfin://fixture/" + QString::number(i);
+ tracks.append(t);
+ }
+ player.setExternalTracks(tracks, 0, false);
+ QCOMPARE(player.queuedTrackKey(-1), QString());
+ QCOMPARE(player.queuedTrackKey(5), QString());
+ QCOMPARE(player.queuedTrackKey(3), tracks[3].path);
+ player.setShuffle(true);
+ QSet<int> visited{0};
+ for (int i = 0; i < 4; ++i) {
+ const auto next = player.nextTrackIndex();
+ QVERIFY(next >= 0);
+ QVERIFY(!visited.contains(next));
+ QCOMPARE(player.nextTrackIndex(), next);
+ player.next(true, false);
+ QCOMPARE(player.currentIndex(), next);
+ visited.insert(next);
+ }
+ QCOMPARE(player.nextTrackIndex(), -1);
+ player.setRepeatMode(1);
+ const auto next = player.nextTrackIndex();
+ player.next(true, false);
+ QCOMPARE(player.currentIndex(), next);
+ player.setRepeatMode(2);
+ QCOMPARE(player.nextTrackIndex(), -1);
+ }
+ void failedPrefetchFallsBack_data() { providerRows(); }
+ void failedPrefetchFallsBack() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b")});
+ api->finishDownload(0);
+ QTRY_COMPARE_WITH_TIMEOUT(api->downloads.size(), 2, 5000);
+ QCOMPARE(api->downloads[1].channel, QString("prefetch"));
+ api->finishDownload(1, "Preload disconnected");
+ QVERIFY(player->error().isEmpty());
+ QVERIFY(player->playing());
+ QVERIFY(!library.buffering());
+ QTRY_VERIFY_WITH_TIMEOUT(player->position() > 100, 5000);
+ player->next();
+ QCOMPARE(api->downloads.size(), 3);
+ QCOMPARE(api->downloads[2].channel, QString("audio"));
+ QCOMPARE(api->downloads[2].key, QString("b"));
+ QVERIFY(library.buffering());
+ api->finishDownload(2);
+ QTRY_VERIFY_WITH_TIMEOUT(player->position() > 100, 5000);
+ QVERIFY(!library.buffering());
+ QVERIFY(player->error().isEmpty());
+ }
+ void removingUpcomingTrackDiscardsItsBuffer_data() { providerRows(); }
+ void removingUpcomingTrackDiscardsItsBuffer() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b"), api->row("c")});
+ api->finishDownload(0);
+ QTRY_COMPARE_WITH_TIMEOUT(api->downloads.size(), 2, 5000);
+ api->finishDownload(1);
+ const auto discarded = api->downloads[1].path;
+ api->downloads[1].reply = {};
+ player->remove(1);
+ QTRY_COMPARE_WITH_TIMEOUT(api->downloads.size(), 3, 5000);
+ QCOMPARE(api->downloads[2].key, QString("c"));
+ QVERIFY(!QFile::exists(discarded));
+ QVERIFY(player->trackKey().endsWith("/a"));
+ QVERIFY(player->playing());
+ player->clear();
+ api->finishDownload(
+ 2); // A successful late reply cannot repopulate a cleared queue.
+ const auto latePath = api->downloads[2].path;
+ api->downloads.clear();
+ QTest::qWait(400);
+ QCOMPARE(player->count(), 0);
+ QVERIFY(!player->playing());
+ QVERIFY(!library.buffering());
+ QVERIFY(!QFile::exists(latePath));
+ }
+ void disconnectRejectsLateAudio_data() { providerRows(); }
+ void disconnectRejectsLateAudio() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b")});
+ QVERIFY(library.buffering());
+ api->disconnectServer();
+ api->finishDownload(0);
+ const auto discarded = api->downloads[0].path;
+ api->downloads.clear();
+ QTest::qWait(400);
+ QCOMPARE(player->count(), 0);
+ QVERIFY(!player->playing());
+ QVERIFY(!library.buffering());
+ QVERIFY(player->error().isEmpty());
+ QVERIFY(player->artwork().isNull());
+ QVERIFY(!QFile::exists(discarded));
+ api->online = true;
+ emit api->changed();
+ library.playItem(
+ api->row("a")); // Same id in a different account is a new song.
+ QCOMPARE(api->downloads.size(), 1);
+ QVERIFY(player->trackKey().contains("://other/"));
+ api->finishDownload(0);
+ QTRY_VERIFY_WITH_TIMEOUT(player->position() > 100, 5000);
+ }
+ void retryRejectsLateSuccess_data() { providerRows(); }
+ void retryRejectsLateSuccess() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b")});
+ library.retry();
+ library.retry();
+ QCOMPARE(api->downloads.size(), 3);
+ api->finishDownload(0);
+ api->finishDownload(1);
+ QVERIFY(library.buffering());
+ QCOMPARE(player->position(), 0);
+ QCOMPARE(player->count(), 2);
+ QCOMPARE(player->currentIndex(), 0);
+ api->finishDownload(2);
+ QTRY_VERIFY_WITH_TIMEOUT(player->position() > 100, 5000);
+ QVERIFY(!library.buffering());
+ api->finishDownload(0, "Stale failure after recovery");
+ QVERIFY(player->error().isEmpty());
+ QVERIFY(player->playing());
+ }
+ void reorderWhileDownloading_data() { providerRows(); }
+ void reorderWhileDownloading() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playItems({api->row("a"), api->row("b"), api->row("c")});
+ const auto key = player->trackKey();
+ player->move(0, 2);
+ QCOMPARE(player->trackKey(), key);
+ QCOMPARE(player->currentIndex(), 2);
+ QCOMPARE(api->downloads.size(), 1);
+ QVERIFY(library.buffering());
+ api->finishDownload(0);
+ QTRY_VERIFY_WITH_TIMEOUT(player->position() > 100, 5000);
+ QVERIFY(!library.buffering());
+ player->remove(0);
+ QCOMPARE(player->trackKey(), key);
+ QCOMPARE(player->currentIndex(), 1);
+ QCOMPARE(api->downloads.size(), 1);
+ QVERIFY(player->playing());
+ }
+ void pageCacheRowBudget_data() { providerRows(); }
+ void pageCacheRowBudget() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ QVariantList rows;
+ for (int i = 0; i < 11000; ++i)
+ rows.append(api->row(QString::number(i)));
+ api->finishPage(0, rows);
+ library.search("second", "songs");
+ api->finishPage(1, rows);
+ library.search("third", "songs");
+ api->finishPage(2, {api->row("third")});
+ library.search("second", "songs");
+ QCOMPARE(api->pages.size(), 3); // Recent large page is still cached.
+ QCOMPARE(library.items().size(), 11000);
+ library.show("albums");
+ QCOMPARE(api->pages.size(),
+ 4); // Row budget evicts before the six-page limit.
+ QVERIFY(library.items().isEmpty());
+ }
+ void folderChangeInvalidatesHistory_data() { providerRows(); }
+ void folderChangeInvalidatesHistory() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ const auto album = api->row("album", "album");
+ api->finishPage(0, {album});
+ library.setViewState({{"query", "private"}, {"y", 600}});
+ library.open(album);
+ api->setFolder("new-folder");
+ api->finishPage(1, {api->row("late-old-folder")});
+ QVERIFY(library.items().isEmpty());
+ QVERIFY(library.viewState().isEmpty());
+ QVERIFY(!library.canBack());
+ QVERIFY(!library.busy());
+ library.show("albums");
+ QCOMPARE(api->pages.size(), 3);
+ api->finishPage(2, {api->row("new-folder-album", "album")});
+ QCOMPARE(library.items().first().toMap().value("id").toString(),
+ QString("new-folder-album"));
+ }
+ void playlistPermissionsRefresh_data() { providerRows(); }
+ void playlistPermissionsRefresh() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ emit api->changed();
+ library.setEnabled(true);
+ const auto playlist = api->row("list", "playlist");
+ api->finishPage(0, {playlist});
+ library.open(playlist);
+ api->pages[1].second({{"items", QVariantList{api->row("a")}},
+ {"editable", true},
+ {"deletable", true}},
+ {});
+ QVERIFY(library.collection().value("editable").toBool());
+ QVERIFY(library.collection().value("deletable").toBool());
+ library.back();
+ library.open(playlist);
+ QCOMPARE(api->pages.size(), 2);
+ QVERIFY(library.collection().value("deletable").toBool());
+ library.reload();
+ api->pages[2].second({{"items", QVariantList{api->row("a")}},
+ {"editable", false},
+ {"deletable", false}},
+ {});
+ QVERIFY(!library.collection().value("editable").toBool());
+ QVERIFY(!library.collection().value("deletable").toBool());
+ library.back();
+ library.open(playlist);
+ QCOMPARE(api->pages.size(), 3);
+ QVERIFY(!library.collection().value("deletable").toBool());
+ }
+ void playNextRejectsForeignRowsAndHonorsManualSkip_data() { providerRows(); }
+ void playNextRejectsForeignRowsAndHonorsManualSkip() {
+ QFETCH(QString, source);
+ QTemporaryDir dir;
+ auto *api = new FixtureMusicApi(source);
+ RemoteLibrary library(dir.path(), false, nullptr, api);
+ auto *player = library.transport();
+ player->setVolume(0);
+ library.playNext(api->row("a"));
+ QCOMPARE(player->count(), 1);
+ QVERIFY(!player->playing());
+ QVERIFY(api->downloads.isEmpty());
+ auto foreign = api->row("foreign");
+ foreign["server"] = "another-account";
+ library.playNext(foreign);
+ library.playNext(api->row("album", "album"));
+ QCOMPARE(player->count(), 1);
+ library.enqueue(api->row("tail"));
+ library.playNext(api->row("first"));
+ library.playNext(api->row("second"));
+ QCOMPARE(player->queue()[1].toMap().value("title").toString(),
+ QString("second"));
+ QCOMPARE(player->queue()[2].toMap().value("title").toString(),
+ QString("first"));
+ player->setShuffle(true);
+ player->setRepeatMode(2);
+ QCOMPARE(player->nextTrackIndex(),
+ -1); // Automatic repeat keeps the current song.
+ QCOMPARE(player->nextTrackIndex(false), 1);
+ player->next(false, false);
+ QVERIFY(player->trackKey().endsWith("/second"));
+ QVERIFY(!player->playing());
+ QVERIFY(api->downloads.isEmpty());
+ }
+};
+QTEST_MAIN(RemoteLibraryTest)
+#include "remotelibrarytest.moc"
diff --git a/src/subsonicapi.cpp b/src/subsonicapi.cpp
index 5190f0d..72729ee 100644
--- a/src/subsonicapi.cpp
+++ b/src/subsonicapi.cpp
@@ -425,8 +425,10 @@ QVariantMap SubsonicApi::item(const QVariantMap &raw,
cover.setPath("/" + m_identity + "/" + raw.value("coverArt").toString());
out["art"] = cover.toString();
}
- if (kind == "playlist")
+ if (kind == "playlist") {
out["editable"] = raw.value("owner").toString() == m_username;
+ out["deletable"] = out["editable"];
+ }
return out;
}
QVariantList SubsonicApi::items(const QVariant &rows,
@@ -726,9 +728,10 @@ void SubsonicApi::browse(const QVariantMap &req, Reply callback,
result["artist"] = container.value("artist");
result["year"] = container.value("year");
}
- if (mode == "playlist")
- result["editable"] =
- container.value("owner").toString() == m_username;
+ if (mode == "playlist") {
+ result["editable"] = container.value("owner").toString() == m_username;
+ result["deletable"] = result["editable"];
+ }
callback(result, {});
},
channel);
@@ -814,6 +817,7 @@ void SubsonicApi::download(const QVariantMap &track, const QString &path,
if (bitrate())
p.append(QPair<QString, QString>{"maxBitRate", QString::number(bitrate())});
QNetworkRequest request(url("stream", p));
+ if (channel == "prefetch") request.setPriority(QNetworkRequest::LowPriority);
request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
request.setTransferTimeout(30000);
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute,
diff --git a/src/subsonicprotocoltest.cpp b/src/subsonicprotocoltest.cpp
index 4bd7a8f..cabfd9f 100644
--- a/src/subsonicprotocoltest.cpp
+++ b/src/subsonicprotocoltest.cpp
@@ -366,6 +366,8 @@ else:
};
client.browse({{"mode", "playlist"}, {"remoteId", "p"}}, callback);
QTRY_VERIFY(done);
+ QVERIFY(result.value("editable").toBool());
+ QVERIFY(result.value("deletable").toBool());
auto rows = result.value("items").toList();
QCOMPARE(rows.size(), 3);
auto first = rows[0].toMap().value("entryId").toString(),
@@ -396,6 +398,11 @@ else:
QCOMPARE(mutations, count);
owner = "someone-else";
done = false;
+ client.browse({{"mode", "playlist"}, {"remoteId", "p"}}, callback);
+ QTRY_VERIFY(done);
+ QVERIFY(!result.value("editable").toBool());
+ QVERIFY(!result.value("deletable").toBool());
+ done = false;
client.removePlaylist("p", callback);
QTRY_VERIFY(done);
QVERIFY(error.contains("owner"));
diff --git a/src/subsonictest.cpp b/src/subsonictest.cpp
index 6e2b057..a2bf249 100644
--- a/src/subsonictest.cpp
+++ b/src/subsonictest.cpp
@@ -19,8 +19,10 @@ namespace {
bool until(const std::function<bool()> &fn, int timeout = 15000) {
QElapsedTimer t;
t.start();
- while (!fn() && t.elapsed() < timeout)
+ do {
+ if (fn()) return true;
QTest::qWait(20);
+ } while (t.elapsed() < timeout);
return fn();
}
QQuickItem *find(QQuickItem *item, const QString &name) {
@@ -188,6 +190,15 @@ int exerciseSubsonic(Player &local, RemoteLibrary &jf, QQuickWindow *window,
check(until([&] { return !jf.busy(); }) && jf.items().size() == 105 &&
!jf.more(),
"search pagination returns all 105 songs");
+ QTest::qWait(100);
+ auto *results = find(window->contentItem(), "subsonicResults");
+ results->setProperty("contentY", 700);
+ QMetaObject::invokeMethod(find(window->contentItem(), "subsonicPanel"), "saveView");
+ click("localSourceButton");
+ click("subsonicSourceButton");
+ check(until([&] { auto *view = find(window->contentItem(), "subsonicResults"); return view && qAbs(view->property("contentY").toReal()-700) < 2; }), "source switch restores library scroll position");
+ auto *searchField = find(window->contentItem(), "subsonicSearch");
+ check(searchField && searchField->property("text").toString() == "Fixture", "source switch restores search query");
QSet<QString> ids;
for (const auto &v : jf.items())
ids.insert(v.toMap().value("id").toString());
@@ -303,6 +314,13 @@ int exerciseSubsonic(Player &local, RemoteLibrary &jf, QQuickWindow *window,
check(until([&] { return !jf.actionBusy() && !jf.busy(); }) &&
jf.heading() == "Renamed fixture",
"playlist renamed on server");
+ check(jf.collection().value("deletable").toBool(), "owner can delete playlist from shared controller");
+ click("subsonicPageActions");
+ auto *deleteAction = find(window->contentItem(), "subsonicDeletePlaylist");
+ check(deleteAction && deleteAction->isVisible() && deleteAction->height() >= 48,
+ "owner delete action visible with Material touch target");
+ capture("subsonic-playlist-menu");
+ QMetaObject::invokeMethod(find(window->contentItem(), "subsonicPanel"), "closeActions");
capture("subsonic-playlist");
for (const auto &song : QVariantList{first, second, third}) {
jf.playItem(song.toMap());
@@ -379,7 +397,29 @@ int exerciseSubsonic(Player &local, RemoteLibrary &jf, QQuickWindow *window,
"Jellyfin and Subsonic remain separate sources");
click("subsonicSourceButton");
check(player->count() == 2, "Subsonic queue survives source switching");
+ const auto beforeNextKey = player->trackKey();
+ auto *panel = find(window->contentItem(), "subsonicPanel");
+ QMetaObject::invokeMethod(panel, "menuFor", Q_ARG(QVariant, QVariant(first)), Q_ARG(QVariant, QVariant(-1)), Q_ARG(QVariant, QVariant()));
+ check(until([&] { auto *action = find(window->contentItem(), "subsonicPlayNext"); return action && action->isVisible(); }), "Play next is available in remote song menu");
+ capture("subsonic-play-next-menu");
+ click("subsonicPlayNext");
+ check(player->count() == 3 && player->trackKey() == beforeNextKey && player->queue()[player->currentIndex()+1].toMap().value("title") == first.value("title"), "Play next inserts without restarting current song");
+ player->remove(player->currentIndex()+1);
+ player->failExternal(player->trackKey(), "Connection interrupted. Retry this song.");
+ check(until([&] { auto *retry = find(window->contentItem(), "remotePlaybackRetry"); return retry && retry->isVisible(); }), "failed remote playback exposes inline Retry");
+ capture("subsonic-retry");
+ click("remotePlaybackRetry");
+ check(player->trackKey() == beforeNextKey && player->count() == 2 && until([&] { return player->position() > 200 && player->error().isEmpty(); }), "Retry reloads same song and preserves queue");
+ player->pause();
window->setProperty("libraryOpen", false);
+ window->setProperty("immersive", true);
+ window->setProperty("discFlipped", true);
+ window->setProperty("lyricsView", true);
+ check(until([&] { return !jf.loading() && jf.lines().size() == 3; }), "immersive lyrics use the current server timeline");
+ QTest::qWait(200);
+ capture("subsonic-immersive-lyrics");
+ window->setProperty("discFlipped", false);
+ window->setProperty("immersive", false);
local.setShowPlayerBody(true);
for (const auto &medium : QStringList{"cd", "vinyl", "cassette", "tp7"}) {
local.setMedium(medium);
@@ -394,6 +434,12 @@ int exerciseSubsonic(Player &local, RemoteLibrary &jf, QQuickWindow *window,
"3D medium activates");
QTest::qWait(500);
capture("subsonic-" + medium + "-3d");
+ window->setProperty("immersive", true);
+ window->setProperty("chromeIdle", true);
+ QTest::qWait(300);
+ check(window->property("chromeHidden").toBool() && window->property("threeDActive").toBool(), "immersive mode retains active 3D medium");
+ capture("subsonic-immersive-" + medium + "-3d");
+ window->setProperty("immersive", false);
player->seek(2000);
click("playButton");
check(until([&] { return player->position() > 2200; }) &&
@@ -434,6 +480,12 @@ int exerciseSubsonic(Player &local, RemoteLibrary &jf, QQuickWindow *window,
!jf.collection().value("editable").toBool() &&
jf.items().size() == 1,
"read-only playlist displays tracks without edit permission");
+ check(!jf.collection().value("deletable").toBool(), "reader has no playlist delete permission");
+ window->setProperty("libraryOpen", true);
+ click("subsonicPageActions");
+ auto *removeAction = find(window->contentItem(), "subsonicDeletePlaylist");
+ check(!removeAction || !removeAction->isVisible(), "read-only playlist hides Delete action");
+ QMetaObject::invokeMethod(find(window->contentItem(), "subsonicPanel"), "closeActions");
jf.removeFromPlaylist(jf.items().value(0).toMap());
check(!jf.actionBusy() && jf.items().size() == 1,
"read-only playlist removal blocked locally");
@@ -450,7 +502,13 @@ int exerciseSubsonic(Player &local, RemoteLibrary &jf, QQuickWindow *window,
api->connectServer(base, user, password, false);
check(until([&] { return api->connected() && !api->playlists().isEmpty(); }),
"owner account reconnects after permission checks");
- jf.deletePlaylist(playlistId);
+ jf.open(api->playlists().first().toMap());
+ check(until([&] { return !jf.busy(); }), "owner playlist opens for deletion");
+ window->setProperty("libraryOpen", true);
+ click("subsonicPageActions");
+ click("subsonicDeletePlaylist");
+ capture("subsonic-delete-confirmation");
+ click("subsonicDeleteDialogAccept");
check(until([&] { return !jf.actionBusy() && api->playlists().isEmpty(); }),
"playlist deleted on server");
api->setBitrate(128);
diff --git a/src/testcapture.h b/src/testcapture.h
index dc39692..9b2437c 100644
--- a/src/testcapture.h
+++ b/src/testcapture.h
@@ -16,7 +16,11 @@ inline QImage captureTestWindow(QQuickWindow *window) {
|| qEnvironmentVariable("QT_QUICK_BACKEND") == "software")
return window->grabWindow();
- const auto result = window->contentItem()->grabToImage();
+ // Explicit pixel dimensions avoid an old offscreen drawable size surviving
+ // a resize while a transient notice is leaving the scene.
+ const QSize pixels(qRound(window->width() * window->devicePixelRatio()),
+ qRound(window->height() * window->devicePixelRatio()));
+ const auto result = window->contentItem()->grabToImage(pixels);
if (!result) return {};
QElapsedTimer timer;
timer.start();
diff --git a/tests/REGRESSION.md b/tests/REGRESSION.md
new file mode 100644
index 0000000..8b166bf
--- /dev/null
+++ b/tests/REGRESSION.md
@@ -0,0 +1,32 @@
+# Recent-feature regression coverage
+
+Build and run from the repository root:
+
+```sh
+cmake -S . -B build -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release
+cmake --build build --parallel 4
+ctest --test-dir build --output-on-failure -j1
+```
+
+The recent improvement batch contains six features. The focused tests cover their behavior and failure paths:
+
+| Feature | Automated coverage |
+| --- | --- |
+| Upcoming-song preload | One-song limit, ready-buffer consumption, failure fallback, queue removal, shuffle plan, bitrate invalidation, source cancellation and buffer cleanup. |
+| Immersion | Ctrl+I, idle chrome, pointer and keyboard reveal, hidden tooltips, focus, help, Mini transitions, repeated toggles and queue/library restoration. |
+| Browsing continuity | Navigation, search and scroll restoration, failed refresh, pagination, stale replies, six-page and 20,000-row limits, account/folder isolation. |
+| Play next | Insert position, paused/current transport preservation, shuffle priority, manual skip under repeat-one, append distinction and rejection of foreign-account/non-song rows. |
+| Retry | Repeated retry, late success/failure rejection, same queue entry, resumed audio, and the rendered Retry action. |
+| Playlist actions | Cached and refreshed ownership permissions, owner deletion and read-only rejection through the server integrations. |
+
+`spun-remote-library` runs nine additional controller scenarios for each of the Jellyfin and Subsonic/Navidrome source identities. Its controllable adapter intentionally completes cancelled requests to expose stale-result bugs. These cases complement the existing protocol tests; they do not replace real-server validation.
+
+`spun-immersive-media-ui` runs automatically in CTest. To run the two focused suites:
+
+```sh
+ctest --test-dir build -L regression --output-on-failure -j1
+```
+
+All CTest UI runs use Qt's offscreen software renderer. Audio fixtures are muted. For app-only screenshots, run `spun --test-media-ui --capture-dir /tmp/spun-ui-captures` with `QT_QPA_PLATFORM=offscreen QT_QUICK_BACKEND=software QT_QPA_PLATFORMTHEME=`.
+
+The complete suite also checks local import, desktop media controls, frame timing, YouTube, playback, geometry, and Jellyfin/Subsonic protocols. Optional real-server runners are `scripts/test-jellyfin-server.py` and `scripts/test-subsonic-server.py`. Supply a server executable, `--test-binary build/spun`, and a new `--output` directory outside the repository. They create private loopback servers with generated music and temporary accounts, then stop the servers. Software rendering is the default; `--renderer 3d` uses offscreen Mesa rendering. These fixtures require Qt audio-service and local-socket access.