1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-24 18:15:16 +00:00

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. :(
This commit is contained in:
Chris Josten 2024-01-02 21:43:45 +01:00
parent 3c02985990
commit a35d8026be
6 changed files with 167 additions and 8 deletions

View file

@ -89,7 +89,6 @@ function itemModelImageUrl(baseUrl, itemId, tag, type, options) {
} }
function usePortraitCover(itemType) { function usePortraitCover(itemType) {
console.log("ItemType: " + itemType)
return ["Series", "Movie", "tvshows", "movies"].indexOf(itemType) >= 0 return ["Series", "Movie", "tvshows", "movies"].indexOf(itemType) >= 0
} }

View file

@ -1,6 +1,6 @@
/* /*
Sailfin: a Jellyfin client written using Qt 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 This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -151,6 +151,8 @@ ApplicationWindow {
id: config id: config
path: "/nl/netsoj/chris/Sailfin" path: "/nl/netsoj/chris/Sailfin"
property bool showDebugInfo: false property bool showDebugInfo: false
property string startupItemId
property string startupItemType
} }
function navigateToItem(jellyfinId, mediaType, type, isFolder) { function navigateToItem(jellyfinId, mediaType, type, isFolder) {
@ -182,8 +184,17 @@ ApplicationWindow {
onAuthenticatedChanged: { onAuthenticatedChanged: {
if (authenticated && !isInSetup()) { if (authenticated && !isInSetup()) {
console.log("Authenticated)") console.log("Authenticated)")
//loginAnimation.start() console.log("Startup id: %1, item type: %2".arg(config.startupItemId).arg(config.startupItemType))
pageStack.replace(Qt.resolvedUrl("pages/MainPage.qml"))
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)
} }
} }
} }

View file

@ -1,6 +1,6 @@
/* /*
Sailfin: a Jellyfin client written using Qt 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 This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public 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 QtQuick 2.6
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import Nemo.Configuration 1.0
import nl.netsoj.chris.Jellyfin 1.0 as J import nl.netsoj.chris.Jellyfin 1.0 as J
@ -122,6 +123,63 @@ Page {
text: qsTr("Other") 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 { IconListItem {
//: Settings list item for settings related to streaming //: Settings list item for settings related to streaming
text: qsTr("Streaming settings") 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
)
}
}
} }

View file

@ -1,6 +1,6 @@
/* /*
Sailfin: a Jellyfin client written using Qt 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 This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -66,7 +66,7 @@ BaseDetailPage {
cellWidth: Constants.libraryDelegateWidth cellWidth: Constants.libraryDelegateWidth
cellHeight: Utils.usePortraitCover(itemData.collectionType) ? Constants.libraryDelegatePosterHeight cellHeight: Utils.usePortraitCover(itemData.collectionType) ? Constants.libraryDelegatePosterHeight
: Constants.libraryDelegateHeight : Constants.libraryDelegateHeight
visible: itemData.status !== J.ItemLoader.Error visible: itemData.status !== J.LoaderBase.Error
header: PageHeader { header: PageHeader {
title: pageTitle || qsTr("Loading") title: pageTitle || qsTr("Loading")
@ -74,6 +74,16 @@ BaseDetailPage {
PullDownMenu { PullDownMenu {
id: downMenu id: downMenu
visible: pageRoot.allowSort 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 { MenuItem {
id: sortMenuItem id: sortMenuItem
//: Menu item for selecting the sort order of a collection //: Menu item for selecting the sort order of a collection

View file

@ -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 QtQuick 2.6
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
@ -19,6 +37,20 @@ BaseDetailPage {
SilicaFlickable { SilicaFlickable {
anchors.fill: parent anchors.fill: parent
contentHeight: content.height 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 { Component {
id: latestMediaLoaderComponent id: latestMediaLoaderComponent
J.LatestMediaLoader { J.LatestMediaLoader {

View file

@ -1,6 +1,6 @@
/* /*
Sailfin: a Jellyfin client written using Qt 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 This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -27,6 +27,20 @@ BaseDetailPage {
PageHeader { PageHeader {
title: itemData.name 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 { ViewPlaceholder {
enabled: true enabled: true