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
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
import nl.netsoj.chris.Jellyfin 1.0 as J
|
2020-09-15 14:53:13 +00:00
|
|
|
|
|
|
|
import "../components"
|
2020-09-26 00:51:37 +00:00
|
|
|
import "../"
|
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
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
id: mainPage
|
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)
|
|
|
|
}
|
2021-08-11 21:35:33 +00:00
|
|
|
busy: mediaLibraryLoader.status === J.UsersViewsLoader.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
|
2021-07-31 13:06:17 +00:00
|
|
|
width: mainPage.width
|
2021-02-16 16:25:11 +00:00
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
J.ItemModel {
|
|
|
|
id: mediaLibraryModel
|
|
|
|
loader: J.UsersViewsLoader {
|
|
|
|
id: mediaLibraryLoader
|
2021-08-11 21:35:33 +00:00
|
|
|
apiClient: appWindow.apiClient
|
2021-07-31 13:06:17 +00:00
|
|
|
}
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
|
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
|
2021-08-21 22:29:44 +00:00
|
|
|
busy: userResumeLoader.status === J.UsersViewsLoader.Loading
|
2020-09-27 14:54:45 +00:00
|
|
|
Loader {
|
|
|
|
width: parent.width
|
|
|
|
sourceComponent: carrouselView
|
|
|
|
property alias itemModel: userResumeModel
|
|
|
|
property string collectionType: "series"
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
J.ItemModel {
|
2020-09-27 14:54:45 +00:00
|
|
|
id: userResumeModel
|
2021-08-11 21:35:33 +00:00
|
|
|
loader: J.ResumeItemsLoader {
|
|
|
|
id: userResumeLoader
|
|
|
|
apiClient: appWindow.apiClient
|
|
|
|
limit: 12
|
|
|
|
//recursive: true*/
|
|
|
|
}
|
2020-09-27 14:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
2021-07-31 13:06:17 +00:00
|
|
|
//busy: showNextUpModel.status === .Loading
|
2020-10-10 14:26:08 +00:00
|
|
|
|
|
|
|
Loader {
|
|
|
|
width: parent.width
|
|
|
|
sourceComponent: carrouselView
|
|
|
|
property alias itemModel: showNextUpModel
|
|
|
|
property string collectionType: "series"
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
J.ItemModel {
|
2020-10-10 14:26:08 +00:00
|
|
|
id: showNextUpModel
|
2021-08-11 21:35:33 +00:00
|
|
|
/*apiClient: appWindow.apiClient
|
2021-07-31 13:06:17 +00:00
|
|
|
limit: 12*/
|
2020-10-10 14:26:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-27 01:14:05 +00:00
|
|
|
}
|
2020-09-15 14:53:13 +00:00
|
|
|
Repeater {
|
|
|
|
model: mediaLibraryModel
|
|
|
|
MoreSection {
|
|
|
|
text: model.name
|
2021-07-31 13:06:17 +00:00
|
|
|
busy: userItemModel.status !== J.UsersViewsLoader.Ready
|
2020-09-27 14:54:45 +00:00
|
|
|
|
2021-02-20 22:20:39 +00:00
|
|
|
onHeaderClicked: pageStack.push(Qt.resolvedUrl("itemdetails/CollectionPage.qml"), {"itemId": model.jellyfinId})
|
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 || ""
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
J.ItemModel {
|
2020-09-15 14:53:13 +00:00
|
|
|
id: userItemModel
|
2021-07-31 13:06:17 +00:00
|
|
|
loader: J.LatestMediaLoader {
|
2021-08-11 21:35:33 +00:00
|
|
|
apiClient: appWindow.apiClient
|
2021-07-31 13:06:17 +00:00
|
|
|
parentId: jellyfinId
|
|
|
|
}
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
Connections {
|
|
|
|
target: mediaLibraryModel
|
2021-02-20 22:20:39 +00:00
|
|
|
onReady: userItemModel.reload()
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
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 {
|
2021-08-11 21:35:33 +00:00
|
|
|
target: appWindow.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) {
|
2021-08-11 21:35:33 +00:00
|
|
|
if (force || (appWindow.apiClient.authenticated && !_modelsLoaded)) {
|
2020-09-26 21:29:45 +00:00
|
|
|
_modelsLoaded = true;
|
|
|
|
mediaLibraryModel.reload()
|
2021-08-17 22:04:27 +00:00
|
|
|
userResumeModel.reload()
|
|
|
|
showNextUpModel.reload()
|
2020-09-27 14:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: carrouselView
|
|
|
|
SilicaListView {
|
2021-08-11 21:35:33 +00:00
|
|
|
property bool isPortrait: Utils.usePortraitCover(collectionType)
|
2020-09-27 14:54:45 +00:00
|
|
|
id: list
|
|
|
|
clip: true
|
|
|
|
height: {
|
|
|
|
if (count > 0) {
|
2021-08-11 21:35:33 +00:00
|
|
|
if (isPortrait) {
|
2020-09-27 14:54:45 +00:00
|
|
|
Constants.libraryDelegatePosterHeight
|
2021-08-11 21:35:33 +00:00
|
|
|
} else {
|
|
|
|
Constants.libraryDelegateHeight
|
2020-09-27 14:54:45 +00:00
|
|
|
}
|
|
|
|
} 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 {
|
2021-02-20 22:20:39 +00:00
|
|
|
property string id: model.jellyfinId
|
2020-09-27 14:54:45 +00:00
|
|
|
title: model.name
|
2021-08-11 21:35:33 +00:00
|
|
|
poster: Utils.itemModelImageUrl(appWindow.apiClient.baseUrl, model.jellyfinId, model.imageTags["Primary"], "Primary", {"maxHeight": height})
|
2021-02-20 22:20:39 +00:00
|
|
|
Binding on blurhash {
|
|
|
|
when: poster !== ""
|
|
|
|
value: model.imageBlurHashes["Primary"][model.imageTags["Primary"]]
|
|
|
|
}
|
2021-08-11 21:35:33 +00:00
|
|
|
landscape: !isPortrait
|
2021-08-17 22:04:27 +00:00
|
|
|
progress: (typeof model.userDataPlayedProgress !== 0.0) ? model.userDataPlayedPercentage / 100 : 0.0
|
2020-09-27 14:54:45 +00:00
|
|
|
|
|
|
|
onClicked: {
|
2021-02-20 22:20:39 +00:00
|
|
|
pageStack.push(Utils.getPageUrl(model.mediaType, model.type, model.isFolder), {"itemId": model.jellyfinId, "itemData": model.qtObject})
|
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"
|
2021-07-31 13:06:17 +00:00
|
|
|
when: mediaLibraryLoader.status !== J.UsersViewsLoader.Error
|
2021-02-16 16:25:11 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "error"
|
2021-07-31 13:06:17 +00:00
|
|
|
when: mediaLibraryLoader.status === J.UsersViewsLoader.Error
|
2021-02-16 16:25:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|