1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-01 07:35:17 +00:00
harbour-sailfin/sailfish/qml/pages/itemdetails/CollectionPage.qml
Chris Josten a35d8026be 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. :(
2024-01-02 22:28:34 +01:00

208 lines
7.4 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 nl.netsoj.chris.Jellyfin 1.0 as J
import "../.."
import "../../components"
BaseDetailPage {
id: pageRoot
property bool _collectionModelLoaded: false
property bool allowSort: true
property var modelStatus: collectionModel.loader.modelStatus
property string pageTitle: itemData.name
property alias loader: collectionModel.loader
J.ItemModel {
id: collectionModel
loader: J.UserItemsLoader {
id: collectionLoader
apiClient: appWindow.apiClient
parentId: itemData.jellyfinId
sortBy: "SortName"
autoReload: itemData.jellyfinId.length > 0 && (pageRoot.status == PageStatus.Active || _collectionModelLoaded)
}
}
Binding {
target: collectionModel.loader
property: "autoReload"
value: (pageRoot.status == PageStatus.Active || pageRoot._collectionModelLoaded)
}
Connections {
target: collectionModel.loader
onStatusChanged: {
if (status === J.ModelStatus.Ready) {
_collectionModelLoaded = true
}
}
}
SilicaGridView {
id: gridView
anchors.fill: parent
model: collectionModel
cellWidth: Constants.libraryDelegateWidth
cellHeight: Utils.usePortraitCover(itemData.collectionType) ? Constants.libraryDelegatePosterHeight
: Constants.libraryDelegateHeight
visible: itemData.status !== J.LoaderBase.Error
header: PageHeader {
title: pageTitle || qsTr("Loading")
}
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
text: qsTr("Sort by")
onClicked: pageStack.push(sortPageComponent)
}
busy: modelStatus === J.ModelStatus.Loading
}
add: Transition {
id: trans
SequentialAnimation {
PropertyAction {
property: "opacity"; value: 0 }
PauseAnimation { duration: trans.ViewTransition.index * 3;}
NumberAnimation { properties: "opacity"; from: 0; to: 1.0; }
} // properties: "opacity"; from: 0; to: 1.0; }
}
delegate: GridItem {
RemoteImage {
id: itemImage
anchors.fill: parent
source: Utils.itemModelImageUrl(apiClient.baseUrl, model.jellyfinId, model.imageTags.Primary, "Primary", {"maxWidth": width})
blurhash: model.imageBlurHashes.Primary[model.imageTags.Primary]
fallbackColor: Utils.colorFromString(model.name)
fillMode: Image.PreserveAspectCrop
clip: true
}
Shim {
anchors {
left: parent.left
bottom: parent.bottom
right: parent.right
}
height: itemName.height + Theme.paddingMedium * 2
visible: itemImage.status !== Image.Null
}
Label {
id: itemName
anchors {
left: parent.left
leftMargin: Theme.paddingMedium
right: parent.right
rightMargin: Theme.paddingMedium
bottom: parent.bottom
bottomMargin: Theme.paddingSmall
}
text: model.name
truncationMode: TruncationMode.Fade
horizontalAlignment: Text.AlignLeft
font.pixelSize: Theme.fontSizeSmall
}
onClicked: appWindow.navigateToItem(model.jellyfinId, model.mediaType, model.type, model.isFolder);
}
ViewPlaceholder {
enabled: gridView.count == 0 && !pageRoot._loading && collectionModel.status === J.ModelStatus.Ready
text: qsTr("Empty collection")
hintText: qsTr("Add some items to this collection!")
}
VerticalScrollDecorator {}
}
// The page for selecting a sort order
Component {
id: sortPageComponent
Page {
id: sortPage
ListModel {
id: sortOptions
ListElement { name: qsTr("Name"); value: "SortName"; }
ListElement { name: qsTr("Play count"); value: "PlayCount"; }
ListElement { name: qsTr("Date added"); value: "DateCreated"; }
}
SilicaListView {
anchors.fill: parent
model: sortOptions
header: PageHeader {
title: qsTr("Sort by")
}
delegate: ListItem {
Label {
anchors {
left: parent.left
leftMargin: Theme.horizontalPageMargin
right: parent.right
rightMargin: Theme.horizontalPageMargin
verticalCenter: parent.verticalCenter
}
text: model.name
}
menu: ContextMenu {
MenuItem {
//: Sort order
text: qsTr("Ascending")
onClicked: apply(model.value, "Ascending")
}
MenuItem {
//: Sort order
text: qsTr("Descending")
onClicked: apply(model.value, "Descending")
}
}
onClicked: openMenu()
function apply(field, order) {
collectionModel.loader.sortBy = field;
collectionModel.loader.sortOrder = order;
collectionModel.loader.reload()
pageStack.pop()
}
}
}
}
}
}