mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2024-11-15 22:15:18 +00:00
Chris Josten
a35d8026be
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. :(
242 lines
9 KiB
QML
242 lines
9 KiB
QML
/*
|
|
Sailfin: a Jellyfin client written using Qt
|
|
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
|
|
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
|
|
import Nemo.Configuration 1.0
|
|
|
|
import nl.netsoj.chris.Jellyfin 1.0 as J
|
|
|
|
import "../components"
|
|
import ".."
|
|
|
|
Page {
|
|
id: settingsPage
|
|
allowedOrientations: Orientation.All
|
|
|
|
property alias loggedInUser: userLoader.data
|
|
|
|
SilicaFlickable {
|
|
anchors.fill: parent
|
|
contentHeight: content.height
|
|
|
|
Column {
|
|
id: content
|
|
width: parent.width
|
|
|
|
RemorsePopup {
|
|
id: remorse
|
|
}
|
|
|
|
PageHeader {
|
|
//: Header of Settings page
|
|
title: qsTr("Settings")
|
|
}
|
|
|
|
|
|
SectionHeader {
|
|
text: qsTr("Session")
|
|
}
|
|
|
|
Item {
|
|
anchors {
|
|
left: parent.left
|
|
leftMargin: Theme.horizontalPageMargin
|
|
right: parent.right
|
|
rightMargin: Theme.horizontalPageMargin
|
|
}
|
|
height: user.implicitHeight + server.implicitHeight + Theme.paddingMedium
|
|
J.UserLoader{
|
|
id: userLoader
|
|
apiClient: appWindow.apiClient
|
|
userId: appWindow.apiClient.userId
|
|
}
|
|
RemoteImage {
|
|
id: userIcon
|
|
width: height
|
|
anchors {
|
|
left: parent.left
|
|
top: parent.top
|
|
bottom: parent.bottom
|
|
}
|
|
source: apiClient.baseUrl + "/Users/" + apiClient.userId + "/Images/Primary?tag=" + loggedInUser.primaryImageTag
|
|
}
|
|
|
|
Label {
|
|
id: user
|
|
anchors {
|
|
left: userIcon.right
|
|
leftMargin: Theme.paddingLarge
|
|
bottom: parent.verticalCenter
|
|
right: parent.right
|
|
}
|
|
text: userLoader.status === J.UserLoader.Ready ? loggedInUser.name : apiClient.userId
|
|
color: Theme.highlightColor
|
|
}
|
|
|
|
Label {
|
|
id: server
|
|
anchors {
|
|
left: userIcon.right
|
|
leftMargin: Theme.paddingLarge
|
|
top: parent.verticalCenter
|
|
right: parent.right
|
|
}
|
|
text: apiClient.baseUrl
|
|
color: Theme.secondaryHighlightColor
|
|
}
|
|
|
|
|
|
}
|
|
|
|
Item { width: 1; height: Theme.paddingLarge; }
|
|
|
|
ButtonLayout {
|
|
Button {
|
|
//: This is a name used by Jellyfin and seems to be untranslated in other languages
|
|
text: qsTr("Quick Connect")
|
|
onClicked: pageStack.push(Qt.resolvedUrl("QuickConnectDialog.qml"))
|
|
}
|
|
Button {
|
|
text: qsTr("Log out")
|
|
onClicked: remorse.execute(qsTr("Logging out"), apiClient.deleteSession)
|
|
}
|
|
}
|
|
|
|
SectionHeader {
|
|
//: Other settings menu item
|
|
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")
|
|
iconSource: "image://theme/icon-m-cloud-download"
|
|
onClicked: pageStack.push(Qt.resolvedUrl("settings/StreamingPage.qml"))
|
|
}
|
|
|
|
IconListItem {
|
|
//: Debug information settings menu itemy
|
|
text: qsTr("Debug information")
|
|
iconSource: "image://theme/icon-s-developer"
|
|
onClicked: pageStack.push(Qt.resolvedUrl("settings/DebugPage.qml"))
|
|
}
|
|
|
|
//: About Sailfin settings menu itemy
|
|
IconListItem {
|
|
text: qsTr("About Sailfin")
|
|
iconSource: "image://theme/icon-m-about"
|
|
onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
|
|
}
|
|
}
|
|
}
|
|
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
|
|
)
|
|
}
|
|
}
|
|
|
|
}
|