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.6
|
|
|
|
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
|
|
|
|
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
|
|
|
import "../../components"
|
2021-08-11 21:35:33 +00:00
|
|
|
import "../../"
|
2020-09-15 14:53:13 +00:00
|
|
|
|
2020-09-25 13:21:08 +00:00
|
|
|
/**
|
|
|
|
* This page displays details about a film, show, season, episode, and so on.
|
|
|
|
*
|
|
|
|
* It contains the common functionality for all items. Additional components are
|
|
|
|
* loaded in for every specific type of items, from ../components/itemdetails.
|
|
|
|
*/
|
2020-09-15 14:53:13 +00:00
|
|
|
Page {
|
|
|
|
id: pageRoot
|
2021-07-31 13:06:17 +00:00
|
|
|
property string itemId: ""
|
|
|
|
property alias itemData: jItemLoader.data
|
|
|
|
property bool _loading: jItemLoader.status === J.ItemLoader.Loading
|
|
|
|
readonly property bool hasLogo: (typeof itemData.imageTags !== "undefined") && (typeof itemData.imageTags["Logo"] !== "undefined")
|
2021-02-12 02:10:54 +00:00
|
|
|
property string _chosenBackdropImage: ""
|
2021-07-31 13:06:17 +00:00
|
|
|
readonly property string parentId: itemData.parentId || ""
|
2020-09-15 14:53:13 +00:00
|
|
|
|
|
|
|
function updateBackdrop() {
|
2021-02-12 02:32:28 +00:00
|
|
|
var rand = 0;
|
2021-02-12 02:10:54 +00:00
|
|
|
if (itemData.backdropImageTags.length > 0) {
|
2021-02-12 02:32:28 +00:00
|
|
|
rand = Math.floor(Math.random() * (itemData.backdropImageTags.length - 0.001))
|
2020-09-15 14:53:13 +00:00
|
|
|
console.log("Random: ", rand)
|
2021-08-11 21:35:33 +00:00
|
|
|
_chosenBackdropImage = apiClient.baseUrl + "/Items/" + itemId + "/Images/Backdrop/" + rand + "?tag=" +itemData.backdropImageTags[rand] + "&maxHeight" + height
|
2021-02-12 02:10:54 +00:00
|
|
|
} else if (itemData.parentBackdropImageTags.length > 0) {
|
2021-02-12 02:32:28 +00:00
|
|
|
rand = Math.floor(Math.random() * (itemData.parentBackdropImageTags.length - 0.001))
|
2021-08-11 21:35:33 +00:00
|
|
|
_chosenBackdropImage = apiClient.baseUrl + "/Items/" + itemData.parentBackdropItemId + "/Images/Backdrop/" + rand + "?tag=" + itemData.parentBackdropImageTags[0]
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
allowedOrientations: Orientation.All
|
2021-02-12 02:10:54 +00:00
|
|
|
|
2020-09-15 14:53:13 +00:00
|
|
|
PageBusyIndicator {
|
|
|
|
running: pageRoot._loading
|
|
|
|
}
|
|
|
|
|
2020-10-10 13:56:04 +00:00
|
|
|
SilicaFlickable {
|
|
|
|
anchors.fill: parent
|
|
|
|
contentHeight: errorContent.height
|
2021-07-31 13:06:17 +00:00
|
|
|
visible: jItemLoader.status === J.ItemLoader.Error
|
2020-10-10 13:56:04 +00:00
|
|
|
|
|
|
|
PullDownMenu {
|
2021-07-31 13:06:17 +00:00
|
|
|
busy: jItemLoader.status === J.ItemLoader.Loading
|
2020-10-10 13:56:04 +00:00
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Retry")
|
2021-07-31 13:06:17 +00:00
|
|
|
onClicked: jItemLoader.reload()
|
2020-10-10 13:56:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Column {
|
|
|
|
id: errorContent
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
ViewPlaceholder {
|
|
|
|
enabled: true
|
|
|
|
text: qsTr("An error has occured")
|
2021-07-31 13:06:17 +00:00
|
|
|
hintText: jItemLoader.errorString
|
2020-10-10 13:56:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
J.ItemLoader {
|
|
|
|
id: jItemLoader
|
2021-08-11 21:35:33 +00:00
|
|
|
apiClient: appWindow.apiClient
|
2021-07-31 13:06:17 +00:00
|
|
|
itemId: pageRoot.itemId
|
2021-08-11 21:35:33 +00:00
|
|
|
autoReload: false
|
2020-10-04 21:03:58 +00:00
|
|
|
onStatusChanged: {
|
2021-07-31 13:06:17 +00:00
|
|
|
console.log("Status changed: " + newStatus, JSON.stringify(jItemLoader.data))
|
|
|
|
if (status === J.ItemLoader.Ready) {
|
2021-02-12 02:32:28 +00:00
|
|
|
updateBackdrop()
|
|
|
|
}
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onStatusChanged: {
|
2021-08-11 21:35:33 +00:00
|
|
|
if (status === PageStatus.Deactivating) {
|
2020-09-26 00:51:37 +00:00
|
|
|
//appWindow.itemData = ({})
|
|
|
|
}
|
2021-08-11 21:35:33 +00:00
|
|
|
if (status === PageStatus.Active) {
|
|
|
|
console.log("Page ready, ItemID: ", itemId, ", UserID: ", apiClient.userId)
|
|
|
|
jItemLoader.autoReload = true
|
2021-07-31 13:06:17 +00:00
|
|
|
//appWindow.itemData = jItemLoader.data
|
2020-09-15 14:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|