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"
|
2021-01-17 16:08:07 +00:00
|
|
|
import "../components/search"
|
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
|
|
|
|
|
|
|
|
SilicaFlickable {
|
2021-01-17 16:08:07 +00:00
|
|
|
id: mainView
|
2020-09-15 14:53:13 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
|
|
|
|
PullDownMenu {
|
|
|
|
MenuItem {
|
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 {
|
|
|
|
text: qsTr("Refresh")
|
|
|
|
onClicked: loadModels(true)
|
|
|
|
}
|
2020-09-26 21:29:45 +00:00
|
|
|
busy: mediaLibraryModel.status == ApiModel.Loading
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tell SilicaFlickable the height of its content.
|
2020-10-10 13:56:04 +00:00
|
|
|
contentHeight: column.visible ? column.height : errorColumn.height
|
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
|
2020-10-10 13:56:04 +00:00
|
|
|
visible: mediaLibraryModel.status != ApiModel.Error
|
2020-09-15 14:53:13 +00:00
|
|
|
|
|
|
|
width: page.width
|
|
|
|
//spacing: Theme.paddingLarge
|
|
|
|
UserViewModel {
|
|
|
|
id: mediaLibraryModel2
|
|
|
|
apiClient: ApiClient
|
|
|
|
}
|
2021-01-17 16:08:07 +00:00
|
|
|
Item {
|
|
|
|
id: searchBoxPlaceholder
|
|
|
|
width: parent.width
|
|
|
|
height: searchBox.height
|
2020-09-15 14:53:13 +00:00
|
|
|
|
2021-01-17 16:08:07 +00:00
|
|
|
SearchField {
|
|
|
|
id: searchBox
|
2020-09-27 14:54:45 +00:00
|
|
|
width: parent.width
|
2021-01-17 16:08:07 +00:00
|
|
|
placeholderText: qsTr("Search")
|
2020-09-27 14:54:45 +00:00
|
|
|
}
|
2020-09-27 01:14:05 +00:00
|
|
|
}
|
2020-10-10 14:26:08 +00:00
|
|
|
|
2021-01-17 16:08:07 +00:00
|
|
|
Label {
|
|
|
|
text: "%1 results".arg(searchView.count)
|
2020-09-27 01:14:05 +00:00
|
|
|
}
|
2020-09-15 14:53:13 +00:00
|
|
|
|
2021-01-17 16:08:07 +00:00
|
|
|
Column {
|
|
|
|
id: homeView
|
|
|
|
width: parent.width
|
|
|
|
MoreSection {
|
|
|
|
text: qsTr("Resume watching")
|
|
|
|
clickable: false
|
|
|
|
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-15 14:53:13 +00:00
|
|
|
MoreSection {
|
2021-01-17 16:08:07 +00:00
|
|
|
text: qsTr("Next up")
|
|
|
|
clickable: false
|
|
|
|
busy: showNextUpModel.status == ApiModel.Loading
|
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
|
2021-01-17 16:08:07 +00:00
|
|
|
property alias itemModel: showNextUpModel
|
|
|
|
property string collectionType: "series"
|
2020-09-27 14:54:45 +00:00
|
|
|
|
2021-01-17 16:08:07 +00:00
|
|
|
ShowNextUpModel {
|
|
|
|
id: showNextUpModel
|
2020-09-15 14:53:13 +00:00
|
|
|
apiClient: ApiClient
|
|
|
|
limit: 12
|
|
|
|
}
|
2021-01-17 16:08:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UserViewModel {
|
|
|
|
id: mediaLibraryModel
|
|
|
|
apiClient: ApiClient
|
|
|
|
}
|
|
|
|
Repeater {
|
|
|
|
model: mediaLibraryModel
|
|
|
|
MoreSection {
|
|
|
|
text: model.name
|
|
|
|
busy: userItemModel.status != ApiModel.Ready
|
|
|
|
|
|
|
|
onHeaderClicked: pageStack.push(Qt.resolvedUrl("itemdetails/CollectionPage.qml"), {"itemId": model.id})
|
|
|
|
Loader {
|
|
|
|
width: parent.width
|
|
|
|
sourceComponent: carrouselView
|
|
|
|
property alias itemModel: userItemModel
|
|
|
|
property string collectionType: model.collectionType || ""
|
|
|
|
|
|
|
|
UserItemLatestModel {
|
|
|
|
id: userItemModel
|
|
|
|
apiClient: ApiClient
|
|
|
|
parentId: model.id
|
|
|
|
limit: 12
|
|
|
|
}
|
|
|
|
Connections {
|
|
|
|
target: mediaLibraryModel
|
|
|
|
onStatusChanged: {
|
|
|
|
console.log("MediaLibraryModel status " + status)
|
|
|
|
if (status == ApiModel.Ready) {
|
|
|
|
userItemModel.reload()
|
|
|
|
}
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-10 13:56:04 +00:00
|
|
|
}
|
2020-09-26 21:29:45 +00:00
|
|
|
|
2020-10-10 13:56:04 +00:00
|
|
|
Column {
|
|
|
|
id: errorColumn
|
|
|
|
width: parent.width
|
|
|
|
visible: mediaLibraryModel.status == ApiModel.Error
|
|
|
|
PageHeader {
|
|
|
|
title: qsTr("Network error")
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
width: 1
|
|
|
|
height: page.height / 3
|
|
|
|
}
|
|
|
|
|
|
|
|
PlainLabel {
|
|
|
|
text: qsTr("An error has occurred. Please try again.")
|
|
|
|
}
|
|
|
|
Item { width: 1; height: Theme.paddingLarge }
|
|
|
|
Button {
|
|
|
|
text: qsTr("Retry")
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
onClicked: loadModels(true)
|
2020-09-26 21:29:45 +00:00
|
|
|
}
|
2020-10-10 13:56:04 +00:00
|
|
|
Item { width: 1; height: Theme.paddingLarge }
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-25 13:21:08 +00:00
|
|
|
|
2021-01-17 16:08:07 +00:00
|
|
|
SearchResults {
|
|
|
|
id: searchView
|
|
|
|
anchors.fill: parent
|
|
|
|
header: Item {
|
|
|
|
width: parent.width
|
|
|
|
height: searchBox.height
|
|
|
|
}
|
|
|
|
query: searchBox.text
|
|
|
|
visible: false
|
|
|
|
opacity: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "search"
|
|
|
|
when: searchBox.text.length
|
|
|
|
PropertyChanges {
|
|
|
|
target: searchView
|
|
|
|
visible: true
|
|
|
|
opacity: 1
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: mainView
|
|
|
|
opacity: 0
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
ParentChange {
|
|
|
|
target: searchBox
|
|
|
|
parent: searchView.headerItem
|
|
|
|
}
|
|
|
|
StateChangeScript {
|
|
|
|
script: searchBox.forceActiveFocus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2021-01-17 16:08:07 +00:00
|
|
|
* Loads models if not loaded. Set force to true to reload models
|
2020-09-26 21:29:45 +00:00
|
|
|
* 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 {
|
|
|
|
NumberAnimation { duration: 300 }
|
|
|
|
}
|
|
|
|
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: {
|
2020-10-01 09:56:02 +00:00
|
|
|
pageStack.push(Utils.getPageUrl(model.mediaType, model.type), {"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
|
|
|
}
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|