From a35d8026bea2d8b471b2da31e3866b6d5a89170b Mon Sep 17 00:00:00 2001 From: Chris Josten Date: Tue, 2 Jan 2024 21:43:45 +0100 Subject: [PATCH] sailfish: allow configuring the startup page A setting has been added to allow users to select which page should be opened first. This allows for using Sailfin as a music player exclusively, as proposed in #34 Special care has been taken to avoid the user being locked out from the app, for when the library selected as home has been deleted on the server side. It is real tricky to guide the user to delete dconf keys. Therefore, a pulley menu with access to settings has been added to all collection pages and to the unknown page. Additionally, when the setting is changed, it throws away the entire pagestack and replaces it with the new home page + the settings page, so the user can always navigate back. The navigation history of the user will get lost, but otherwise the implementation gets to complex for a feature that is expected to be used not that often. This uses more timers than I hoped for, because otherwise things are undefined for some reason which I do not know and using timers solves it. :( --- sailfish/qml/Utils.js | 1 - sailfish/qml/harbour-sailfin.qml | 17 +++- sailfish/qml/pages/SettingsPage.qml | 95 ++++++++++++++++++- .../qml/pages/itemdetails/CollectionPage.qml | 14 ++- .../pages/itemdetails/MusicLibraryPage.qml | 32 +++++++ .../qml/pages/itemdetails/UnsupportedPage.qml | 16 +++- 6 files changed, 167 insertions(+), 8 deletions(-) diff --git a/sailfish/qml/Utils.js b/sailfish/qml/Utils.js index 96e464e..5716697 100644 --- a/sailfish/qml/Utils.js +++ b/sailfish/qml/Utils.js @@ -89,7 +89,6 @@ function itemModelImageUrl(baseUrl, itemId, tag, type, options) { } function usePortraitCover(itemType) { - console.log("ItemType: " + itemType) return ["Series", "Movie", "tvshows", "movies"].indexOf(itemType) >= 0 } diff --git a/sailfish/qml/harbour-sailfin.qml b/sailfish/qml/harbour-sailfin.qml index 624c163..565230a 100644 --- a/sailfish/qml/harbour-sailfin.qml +++ b/sailfish/qml/harbour-sailfin.qml @@ -1,6 +1,6 @@ /* Sailfin: a Jellyfin client written using Qt -Copyright (C) 2020-2022 Chris Josten +Copyright (C) 2020-2024 Chris Josten This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -151,6 +151,8 @@ ApplicationWindow { id: config path: "/nl/netsoj/chris/Sailfin" property bool showDebugInfo: false + property string startupItemId + property string startupItemType } function navigateToItem(jellyfinId, mediaType, type, isFolder) { @@ -182,8 +184,17 @@ ApplicationWindow { onAuthenticatedChanged: { if (authenticated && !isInSetup()) { console.log("Authenticated)") - //loginAnimation.start() - pageStack.replace(Qt.resolvedUrl("pages/MainPage.qml")) + console.log("Startup id: %1, item type: %2".arg(config.startupItemId).arg(config.startupItemType)) + + if (config.startupItemId) { + pageStack.replace( + Utils.getPageUrl(config.startupItemType, "collectionfolder", true), + { "itemId": config.startupItemId } + ) + } else { + pageStack.replace(Qt.resolvedUrl("pages/MainPage.qml")) + } + pageStack.replace(pages) } } } diff --git a/sailfish/qml/pages/SettingsPage.qml b/sailfish/qml/pages/SettingsPage.qml index 2596bac..69e3701 100644 --- a/sailfish/qml/pages/SettingsPage.qml +++ b/sailfish/qml/pages/SettingsPage.qml @@ -1,6 +1,6 @@ /* Sailfin: a Jellyfin client written using Qt -Copyright (C) 2020 Chris Josten +Copyright (C) 2020-2024 Chris Josten This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ import QtQuick 2.6 import Sailfish.Silica 1.0 +import Nemo.Configuration 1.0 import nl.netsoj.chris.Jellyfin 1.0 as J @@ -122,6 +123,63 @@ Page { text: qsTr("Other") } + ConfigurationGroup { + id: config + path: "/nl/netsoj/chris/Sailfin" + property string startupItemId + property string startupItemType + } + + ComboBox { + id: startupLibrarySelector + //: Combo box label for selecting where the application should start + label: qsTr("Start page") + //: Combo box description for selecting where the application should start + description: qsTr("Which page should be shown when the application starts?") + menu: ContextMenu { + MenuItem { + readonly property string jellyfinId: "" + readonly property string mediaType: "" + text: qsTr("All libraries (default)") + onClicked:saveStartupLibrary("", "") + } + + Timer { + id: libraryRepeaterDelay + // Ugh, there must be a small delay before setting the currentIndex or else it won't work + interval: 100 + onTriggered: { + console.log("Libraries ready") + for (var i = 0; i < libraryRepeater.count; i++) { + console.log("%1: %2 (%3)".arg(i).arg(libraryRepeater.itemAt(i).jellyfinId).arg(config.startupItemId)) + if (libraryRepeater.itemAt(i).jellyfinId == config.startupItemId) { + startupLibrarySelector.currentIndex = i + 1 + console.log("%1: %2".arg(i + 1).arg(startupLibrarySelector.currentIndex)) + } + } + } + } + + Repeater { + id: libraryRepeater + model: J.ItemModel { + loader: J.UserItemsLoader { + apiClient: appWindow.apiClient + includeItemTypes: "CollectionFolder" + onReady: libraryRepeaterDelay.start() + } + } + + MenuItem { + readonly property string jellyfinId: model.jellyfinId + readonly property string type: model.collectionType + onClicked: saveStartupLibrary(jellyfinId, model.collectionType) + text: model.name + } + } + } + } + IconListItem { //: Settings list item for settings related to streaming text: qsTr("Streaming settings") @@ -144,5 +202,40 @@ Page { } } } + function saveStartupLibrary(itemId, mediaType) { + config.startupItemId = itemId + config.startupItemType = mediaType + config.sync() + console.log("Saved pref: %1 (%2)".arg(config.startupItemId).arg(config.startupMediaType)) + // We do a little trick: after clicking an item, we wait for + // the animation to finish and then replace the entire page stack with the new start page + // and the settings page. This is not ideal in the case that the page stack does not equal that + // but the tradeoff is that users should not get stuck in the app when the library that they selected + // as their start library has been deleted on the server. Otherwise, they need to restart the app. + startupPageReplacer.start() + } + + Timer { + id: startupPageReplacer + interval: 500 + onTriggered: { + var firstPage = Qt.resolvedUrl("MainPage.qml") + if (config.startupItemId) { + firstPage = { + "page": Utils.getPageUrl(config.startupItemType, "collectionfolder", true), + "properties": { "itemId": config.startupItemId } + } + } + pageStack.replaceAbove( + null, + [ + firstPage, + Qt.resolvedUrl("SettingsPage.qml") + ], + {}, + PageStackAction.Immediate + ) + } + } } diff --git a/sailfish/qml/pages/itemdetails/CollectionPage.qml b/sailfish/qml/pages/itemdetails/CollectionPage.qml index 8723095..ce2c436 100644 --- a/sailfish/qml/pages/itemdetails/CollectionPage.qml +++ b/sailfish/qml/pages/itemdetails/CollectionPage.qml @@ -1,6 +1,6 @@ /* Sailfin: a Jellyfin client written using Qt -Copyright (C) 2020 Chris Josten +Copyright (C) 2020-2024 Chris Josten This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -66,7 +66,7 @@ BaseDetailPage { cellWidth: Constants.libraryDelegateWidth cellHeight: Utils.usePortraitCover(itemData.collectionType) ? Constants.libraryDelegatePosterHeight : Constants.libraryDelegateHeight - visible: itemData.status !== J.ItemLoader.Error + visible: itemData.status !== J.LoaderBase.Error header: PageHeader { title: pageTitle || qsTr("Loading") @@ -74,6 +74,16 @@ BaseDetailPage { PullDownMenu { id: downMenu visible: pageRoot.allowSort + MenuItem { + //: Pulley menu item: navigate to application settings page + text: qsTr("Settings") + onClicked: pageStack.push(Qt.resolvedUrl("../SettingsPage.qml")) + } + MenuItem { + //: Pulley menu item: shows controllable device page + text: qsTr("Remote control") + onClicked: pageStack.push(Qt.resolvedUrl("../ControllableDevicesPage.qml")) + } MenuItem { id: sortMenuItem //: Menu item for selecting the sort order of a collection diff --git a/sailfish/qml/pages/itemdetails/MusicLibraryPage.qml b/sailfish/qml/pages/itemdetails/MusicLibraryPage.qml index 2d14c30..965f488 100644 --- a/sailfish/qml/pages/itemdetails/MusicLibraryPage.qml +++ b/sailfish/qml/pages/itemdetails/MusicLibraryPage.qml @@ -1,3 +1,21 @@ +/* +Sailfin: a Jellyfin client written using Qt +Copyright (C) 2022-2024 Chris Josten + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ import QtQuick 2.6 import Sailfish.Silica 1.0 @@ -19,6 +37,20 @@ BaseDetailPage { SilicaFlickable { anchors.fill: parent contentHeight: content.height + + PullDownMenu { + MenuItem { + //: Pulley menu item: navigate to application settings page + text: qsTr("Settings") + onClicked: pageStack.push(Qt.resolvedUrl("../SettingsPage.qml")) + } + MenuItem { + //: Pulley menu item: shows controllable device page + text: qsTr("Remote control") + onClicked: pageStack.push(Qt.resolvedUrl("../ControllableDevicesPage.qml")) + } + } + Component { id: latestMediaLoaderComponent J.LatestMediaLoader { diff --git a/sailfish/qml/pages/itemdetails/UnsupportedPage.qml b/sailfish/qml/pages/itemdetails/UnsupportedPage.qml index 67f5cfe..0683792 100644 --- a/sailfish/qml/pages/itemdetails/UnsupportedPage.qml +++ b/sailfish/qml/pages/itemdetails/UnsupportedPage.qml @@ -1,6 +1,6 @@ /* Sailfin: a Jellyfin client written using Qt -Copyright (C) 2020 Chris Josten +Copyright (C) 2020-2024 Chris Josten This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -27,6 +27,20 @@ BaseDetailPage { PageHeader { title: itemData.name } + PullDownMenu { + // If for some reason the initial library item is not accessible, we must be able + // to access the settings. + MenuItem { + //: Pulley menu item: navigate to application settings page + text: qsTr("Settings") + onClicked: pageStack.push(Qt.resolvedUrl("../SettingsPage.qml")) + } + MenuItem { + //: Pulley menu item: shows controllable device page + text: qsTr("Remote control") + onClicked: pageStack.push(Qt.resolvedUrl("../ControllableDevicesPage.qml")) + } + } ViewPlaceholder { enabled: true