2020-09-27 18:38:33 +00:00
|
|
|
/*
|
|
|
|
Sailfin: a Jellyfin client written using Qt
|
|
|
|
Copyright (C) 2020 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
|
|
|
|
*/
|
2020-09-15 14:53:13 +00:00
|
|
|
import QtQuick 2.0
|
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
|
|
|
|
import nl.netsoj.chris.Jellyfin 1.0
|
|
|
|
|
|
|
|
import "../components"
|
2020-09-26 00:51:37 +00:00
|
|
|
import "../"
|
|
|
|
import "../Utils.js" as Utils
|
2020-09-15 14:53:13 +00:00
|
|
|
|
2020-09-25 13:21:08 +00:00
|
|
|
/**
|
|
|
|
* Main page, which simply shows some content of every library, as well as next items.
|
|
|
|
*/
|
2020-09-15 14:53:13 +00:00
|
|
|
Page {
|
2021-01-14 19:35:24 +00:00
|
|
|
/// True if the models on this page already have been loaded and don't necessarily need a refresh
|
2020-09-25 13:21:08 +00:00
|
|
|
property bool _modelsLoaded: false
|
2020-09-15 14:53:13 +00:00
|
|
|
|
2020-09-25 13:21:08 +00:00
|
|
|
id: page
|
2020-09-15 14:53:13 +00:00
|
|
|
allowedOrientations: Orientation.All
|
|
|
|
|
2021-02-16 16:25:11 +00:00
|
|
|
// This component is reused both in the normal state and error state
|
|
|
|
Component {
|
|
|
|
id: commonPullDownMenu
|
2020-09-15 14:53:13 +00:00
|
|
|
PullDownMenu {
|
|
|
|
MenuItem {
|
2021-02-16 16:25:11 +00:00
|
|
|
//: Pulley menu item: navigate to application settings page
|
2020-09-26 21:29:45 +00:00
|
|
|
text: qsTr("Settings")
|
|
|
|
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
2020-10-01 22:13:05 +00:00
|
|
|
MenuItem {
|
2021-02-16 16:25:11 +00:00
|
|
|
//: Pulley menu item: reload items on page
|
|
|
|
text: qsTr("Reload")
|
2020-10-01 22:13:05 +00:00
|
|
|
onClicked: loadModels(true)
|
|
|
|
}
|
2020-09-26 21:29:45 +00:00
|
|
|
busy: mediaLibraryModel.status == ApiModel.Loading
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
2021-02-16 16:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SilicaFlickable {
|
|
|
|
id: flickable
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
|
|
|
|
Loader { sourceComponent: commonPullDownMenu; }
|
2020-09-15 14:53:13 +00:00
|
|
|
|
|
|
|
// Tell SilicaFlickable the height of its content.
|
2021-02-16 16:25:11 +00:00
|
|
|
contentHeight: column.height + Theme.paddingMedium
|
2020-09-15 14:53:13 +00:00
|
|
|
|
|
|
|
// Place our content in a Column. The PageHeader is always placed at the top
|
|
|
|
// of the page, followed by our content.
|
|
|
|
Column {
|
|
|
|
id: column
|
|
|
|
width: page.width
|
2021-02-16 16:25:11 +00:00
|
|
|
|
2020-09-15 14:53:13 +00:00
|
|
|
UserViewModel {
|
|
|
|
id: mediaLibraryModel2
|
|
|
|
apiClient: ApiClient
|
|
|
|
}
|
|
|
|
|
2020-09-27 01:14:05 +00:00
|
|
|
MoreSection {
|
2021-02-16 16:25:11 +00:00
|
|
|
//- Section header for films and TV shows that an user hasn't completed yet.
|
2020-09-26 00:51:37 +00:00
|
|
|
text: qsTr("Resume watching")
|
|
|
|
clickable: false
|
2020-09-27 14:54:45 +00:00
|
|
|
busy: userResumeModel.status == ApiModel.Loading
|
|
|
|
Loader {
|
|
|
|
width: parent.width
|
|
|
|
sourceComponent: carrouselView
|
|
|
|
property alias itemModel: userResumeModel
|
|
|
|
property string collectionType: "series"
|
|
|
|
|
|
|
|
UserItemResumeModel {
|
|
|
|
id: userResumeModel
|
|
|
|
apiClient: ApiClient
|
|
|
|
limit: 12
|
|
|
|
recursive: true
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 01:14:05 +00:00
|
|
|
}
|
|
|
|
MoreSection {
|
2021-02-16 16:25:11 +00:00
|
|
|
//- Section header for next episodes in a TV show that an user was watching.
|
2020-09-26 00:51:37 +00:00
|
|
|
text: qsTr("Next up")
|
|
|
|
clickable: false
|
2020-10-10 14:26:08 +00:00
|
|
|
busy: showNextUpModel.status == ApiModel.Loading
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
width: parent.width
|
|
|
|
sourceComponent: carrouselView
|
|
|
|
property alias itemModel: showNextUpModel
|
|
|
|
property string collectionType: "series"
|
|
|
|
|
|
|
|
ShowNextUpModel {
|
|
|
|
id: showNextUpModel
|
|
|
|
apiClient: ApiClient
|
|
|
|
limit: 12
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 01:14:05 +00:00
|
|
|
}
|
2020-09-15 14:53:13 +00:00
|
|
|
|
|
|
|
UserViewModel {
|
|
|
|
id: mediaLibraryModel
|
|
|
|
apiClient: ApiClient
|
|
|
|
}
|
|
|
|
Repeater {
|
|
|
|
model: mediaLibraryModel
|
|
|
|
MoreSection {
|
|
|
|
text: model.name
|
|
|
|
busy: userItemModel.status != ApiModel.Ready
|
2020-09-27 14:54:45 +00:00
|
|
|
|
Restructured the way item "details" are loaded
Previously, Items were displayed in one page, named DetailPage.qml.
This page then would load a qml component, based on the page type. It
also contained some components common for each detail page, like
displaying the name of the item. This construction had as downside that
modifying the page properties, adding a pulley menu or basing the page
around a SilicaListview was not possible. So I already had created some
other pages.
The new construction uses a base page, named BaseDetailPage which does
set some common properties and handle the loading of the items, so that
that part does not have to be duplicated. Displaying the name of an item
was a very trivial thing to do, so duplicating that part across files
was not a problem. Anyway, the rest of the pages are now seperate, but
all have BaseDetailsPage as the root, so they can use the common
functionality by that page. Those subpages now can be based around
GridViews, Carrousels, have pully menus and so on. To determine to which
page to go to, based on the content type, a function named getPageUrl
has been added to Utils.js, which takes a content type as argument and
gives the page url back.
2020-09-29 00:15:50 +00:00
|
|
|
onHeaderClicked: pageStack.push(Qt.resolvedUrl("itemdetails/CollectionPage.qml"), {"itemId": model.id})
|
2020-09-27 14:54:45 +00:00
|
|
|
Loader {
|
2020-09-15 14:53:13 +00:00
|
|
|
width: parent.width
|
2020-09-27 14:54:45 +00:00
|
|
|
sourceComponent: carrouselView
|
|
|
|
property alias itemModel: userItemModel
|
|
|
|
property string collectionType: model.collectionType || ""
|
|
|
|
|
2020-09-25 15:14:44 +00:00
|
|
|
UserItemLatestModel {
|
2020-09-15 14:53:13 +00:00
|
|
|
id: userItemModel
|
|
|
|
apiClient: ApiClient
|
|
|
|
parentId: model.id
|
2021-01-17 16:34:17 +00:00
|
|
|
limit: 16
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
Connections {
|
|
|
|
target: mediaLibraryModel
|
|
|
|
onStatusChanged: {
|
|
|
|
if (status == ApiModel.Ready) {
|
|
|
|
userItemModel.reload()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-10 13:56:04 +00:00
|
|
|
}
|
2021-02-16 16:25:11 +00:00
|
|
|
}
|
|
|
|
SilicaFlickable {
|
|
|
|
id: errorFlickable
|
|
|
|
anchors.fill: parent
|
|
|
|
visible: false
|
|
|
|
opacity: 0
|
|
|
|
contentHeight: errorColumn.height
|
2020-09-26 21:29:45 +00:00
|
|
|
|
2021-02-16 16:25:11 +00:00
|
|
|
Loader { sourceComponent: commonPullDownMenu; }
|
2020-10-10 13:56:04 +00:00
|
|
|
|
2021-02-16 16:25:11 +00:00
|
|
|
ViewPlaceholder {
|
|
|
|
enabled: true
|
|
|
|
//- ViewPlaceholder text for when a network error has occurred and no contents could be loaded
|
|
|
|
text: qsTr("Network error")
|
|
|
|
//- ViewPlaceholder hint text for when a network error has occurred and no contents could be loaded.
|
|
|
|
//- The user can reload the page by using the pulley, which this text should hint at.
|
|
|
|
hintText: qsTr("Pull down to retry again")
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-25 13:21:08 +00:00
|
|
|
|
2020-09-26 00:51:37 +00:00
|
|
|
onStatusChanged: {
|
|
|
|
if (status == PageStatus.Active) {
|
|
|
|
appWindow.itemData = null
|
2020-09-26 21:29:45 +00:00
|
|
|
loadModels(false)
|
2020-09-26 00:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 13:21:08 +00:00
|
|
|
Connections {
|
|
|
|
target: ApiClient
|
2020-09-26 21:29:45 +00:00
|
|
|
onAuthenticatedChanged: loadModels(false)
|
2020-09-25 13:21:08 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 21:29:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads models if not laoded. Set force to true to reload models
|
|
|
|
* even if loaded.
|
|
|
|
*/
|
|
|
|
function loadModels(force) {
|
|
|
|
if (force || (ApiClient.authenticated && !_modelsLoaded)) {
|
|
|
|
_modelsLoaded = true;
|
|
|
|
mediaLibraryModel.reload()
|
2020-09-27 14:54:45 +00:00
|
|
|
userResumeModel.reload()
|
2020-10-10 14:26:08 +00:00
|
|
|
showNextUpModel.reload()
|
2020-09-27 14:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: carrouselView
|
|
|
|
SilicaListView {
|
|
|
|
id: list
|
|
|
|
clip: true
|
|
|
|
height: {
|
|
|
|
if (count > 0) {
|
|
|
|
if (["tvshows", "movies"].indexOf(collectionType) == -1) {
|
|
|
|
Constants.libraryDelegateHeight
|
|
|
|
} else {
|
|
|
|
Constants.libraryDelegatePosterHeight
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Behavior on height {
|
2021-02-16 16:25:11 +00:00
|
|
|
NumberAnimation { easing.type: Easing.OutQuad; duration: 300 }
|
2020-09-27 14:54:45 +00:00
|
|
|
}
|
|
|
|
model: itemModel
|
|
|
|
width: parent.width
|
|
|
|
orientation: ListView.Horizontal
|
|
|
|
leftMargin: Theme.horizontalPageMargin
|
|
|
|
rightMargin: Theme.horizontalPageMargin
|
|
|
|
spacing: Theme.paddingLarge
|
|
|
|
delegate: LibraryItemDelegate {
|
|
|
|
property string id: model.id
|
|
|
|
title: model.name
|
2020-10-09 00:33:08 +00:00
|
|
|
poster: Utils.itemModelImageUrl(ApiClient.baseUrl, model.id, model.imageTags["primary"], "Primary", {"maxHeight": height})
|
2021-01-14 19:35:24 +00:00
|
|
|
blurhash: model.imageBlurHashes["primary"][model.imageTags["primary"]]
|
2020-10-01 22:13:05 +00:00
|
|
|
landscape: !Utils.usePortraitCover(collectionType)
|
2020-10-09 00:33:08 +00:00
|
|
|
progress: (typeof model.userData !== "undefined") ? model.userData.playedPercentage / 100 : 0.0
|
2020-09-27 14:54:45 +00:00
|
|
|
|
|
|
|
onClicked: {
|
2021-02-12 02:32:28 +00:00
|
|
|
pageStack.push(Utils.getPageUrl(model.mediaType, model.type, model.isFolder), {"itemId": model.id})
|
2020-09-27 14:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-25 13:21:08 +00:00
|
|
|
}
|
2020-09-27 01:14:05 +00:00
|
|
|
}
|
2021-02-16 16:25:11 +00:00
|
|
|
|
|
|
|
state: "default"
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "default"
|
|
|
|
when: mediaLibraryModel2.status !== ApiModel.Error
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "error"
|
|
|
|
when: mediaLibraryModel2.status === ApiModel.Error
|
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: errorFlickable
|
|
|
|
visible: true
|
|
|
|
opacity: 1
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: flickable
|
|
|
|
opacity: 0
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
transitions: [
|
|
|
|
Transition {
|
|
|
|
from: "default"
|
|
|
|
to: "error"
|
|
|
|
SequentialAnimation {
|
|
|
|
PropertyAction { target: errorFlickable; property: "visible"; value: true }
|
|
|
|
FadeAnimation {}
|
|
|
|
PropertyAction { target: flickable; property: "visible"; value: false }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Transition {
|
|
|
|
from: "error"
|
|
|
|
to: "default"
|
|
|
|
SequentialAnimation {
|
|
|
|
PropertyAction { target: flickable; property: "visible"; value: true }
|
|
|
|
FadeAnimation {}
|
|
|
|
PropertyAction { target: errorFlickable; property: "visible"; value: false }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|