2020-09-27 18:38:33 +00:00
|
|
|
/*
|
|
|
|
Sailfin: a Jellyfin client written using Qt
|
2024-01-17 14:28:57 +00:00
|
|
|
Copyright (C) 2020-2024 Chris Josten
|
2020-09-27 18:38:33 +00:00
|
|
|
|
|
|
|
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-25 15:14:44 +00:00
|
|
|
.pragma library
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts miliseconds to a h:mm:ss format
|
|
|
|
*/
|
2020-10-26 21:29:07 +00:00
|
|
|
function timeToText(time, showHours) {
|
|
|
|
var mShowHours = showHours === undefined ? true : showHours
|
2020-09-25 15:14:44 +00:00
|
|
|
if (time < 0) return "??:??:??"
|
|
|
|
var hours = Math.floor(time / (60 * 60 * 1000))
|
|
|
|
var left = time % (60 * 60 * 1000)
|
|
|
|
var minutes = Math.floor(left / (60 * 1000))
|
|
|
|
left = time % (60 * 1000)
|
|
|
|
var seconds = Math.floor(left / 1000)
|
2020-10-26 21:29:07 +00:00
|
|
|
return (hours > 0 ? hours + ":" : "")
|
|
|
|
+ (minutes < 10 ? "0" : "")
|
|
|
|
+ minutes + ":" + (seconds < 10 ? "0" : "")+ seconds
|
2020-09-25 15:14:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-01 19:45:34 +00:00
|
|
|
function msToTicks(ms) {
|
|
|
|
return ms * 10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ticksToMs(ticks) {
|
|
|
|
return ticks / 10000;
|
|
|
|
}
|
|
|
|
|
2020-10-26 21:29:07 +00:00
|
|
|
function ticksToText(ticks, showHours) {
|
|
|
|
return timeToText(ticks / 10000, showHours);
|
2020-09-25 15:14:44 +00:00
|
|
|
}
|
2020-09-26 00:51:37 +00:00
|
|
|
|
2022-07-28 17:55:33 +00:00
|
|
|
function propsToQuery(options) {
|
|
|
|
var query = "";
|
2020-09-26 00:51:37 +00:00
|
|
|
for (var prop in options) {
|
|
|
|
if (options.hasOwnProperty(prop)) {
|
2020-10-27 01:35:50 +00:00
|
|
|
var value = options[prop];
|
2024-01-17 14:28:57 +00:00
|
|
|
if (prop === "maxWidth" || prop === "maxHeight" || prop === "width" || prop === "height") {
|
2020-10-27 01:35:50 +00:00
|
|
|
value = Math.floor(options[prop]);
|
|
|
|
}
|
2022-07-28 17:55:33 +00:00
|
|
|
query += "&" + prop + "=" + value;
|
2020-09-26 00:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-28 17:55:33 +00:00
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
function randomBackdrop(baseUrl, item) {
|
|
|
|
var count = item.backdropImageTags.length;
|
|
|
|
if (count === 0) return -1
|
|
|
|
return Math.floor(Math.random() * count);
|
|
|
|
}
|
|
|
|
|
|
|
|
function itemBackdropUrl(baseUrl, item, idx, options) {
|
|
|
|
var extraQuery = propsToQuery(options)
|
2023-01-11 22:11:02 +00:00
|
|
|
if (item.backdropImageTags[idx]) {
|
|
|
|
return baseUrl + "/Items/" + item.jellyfinId + "/Images/Backdrop/" + idx + "?tag=" + item.backdropImageTags[idx] + extraQuery;
|
|
|
|
} else {
|
|
|
|
return baseUrl + "/Items/" + item.parentBackdropItemId + "/Images/Backdrop/" + idx + "?tag=" + item.parentBackdropImageTags[idx] + extraQuery;
|
|
|
|
}
|
2022-07-28 17:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function itemImageUrl(baseUrl, item, type, options) {
|
|
|
|
if (item === null || !item.imageTags[type]) { return "" }
|
|
|
|
return itemModelImageUrl(baseUrl, item.jellyfinId, item.imageTags[type], type, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
function itemModelImageUrl(baseUrl, itemId, tag, type, options) {
|
|
|
|
if (tag === undefined) return ""
|
|
|
|
var extraQuery = propsToQuery(options)
|
2020-09-26 00:51:37 +00:00
|
|
|
return baseUrl + "/Items/" + itemId + "/Images/" + type + "?tag=" + tag + extraQuery
|
2020-09-26 22:42:20 +00:00
|
|
|
}
|
2020-09-26 00:51:37 +00:00
|
|
|
|
2020-09-26 22:42:20 +00:00
|
|
|
function usePortraitCover(itemType) {
|
2020-09-27 14:54:45 +00:00
|
|
|
return ["Series", "Movie", "tvshows", "movies"].indexOf(itemType) >= 0
|
2020-09-26 00:51:37 +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
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the page url for a certain item type.
|
|
|
|
*/
|
2021-02-12 02:32:28 +00:00
|
|
|
function getPageUrl(mediaType, itemType, isFolder) {
|
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
|
|
|
switch (itemType.toLowerCase()) {
|
|
|
|
case "series":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/SeriesPage.qml")
|
|
|
|
case "movie":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/FilmPage.qml")
|
|
|
|
case "collection":
|
2021-02-12 02:32:28 +00:00
|
|
|
case "photoalbum":
|
2020-10-01 09:56:02 +00:00
|
|
|
return Qt.resolvedUrl("pages/itemdetails/CollectionPage.qml")
|
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
|
|
|
case "season":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/SeasonPage.qml")
|
|
|
|
case "episode":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/EpisodePage.qml")
|
2022-07-28 17:55:33 +00:00
|
|
|
case "musicartist":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/MusicArtistPage.qml")
|
2020-10-26 21:29:07 +00:00
|
|
|
case "musicalbum":
|
2022-07-22 23:52:26 +00:00
|
|
|
case "playlist":
|
2020-10-26 21:29:07 +00:00
|
|
|
return Qt.resolvedUrl("pages/itemdetails/MusicAlbumPage.qml")
|
2021-02-12 02:32:28 +00:00
|
|
|
case "photo":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/PhotoPage.qml")
|
2022-07-29 12:26:25 +00:00
|
|
|
case "collectionfolder":
|
|
|
|
// TODO: support for other collection folders
|
|
|
|
switch(mediaType.toLowerCase()) {
|
|
|
|
case "music":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/MusicLibraryPage.qml")
|
|
|
|
}
|
|
|
|
// FALLTRHOUGH
|
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
|
|
|
default:
|
2021-02-12 02:32:28 +00:00
|
|
|
switch (mediaType ? mediaType.toLowerCase() : isFolder ? "folder" : "") {
|
2020-10-01 09:56:02 +00:00
|
|
|
case "folder":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/CollectionPage.qml")
|
|
|
|
case "video":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/VideoPage.qml")
|
2020-10-10 15:28:13 +00:00
|
|
|
case "photo":
|
|
|
|
return Qt.resolvedUrl("pages/itemdetails/PhotoPage.qml")
|
2020-10-01 09:56:02 +00:00
|
|
|
default:
|
2021-02-12 02:32:28 +00:00
|
|
|
if (isFolder) return Qt.resolvedUrl("pages/itemdetails/CollectionPage.qml")
|
2020-10-01 09:56:02 +00:00
|
|
|
return Qt.resolvedUrl("pages/itemdetails/UnsupportedPage.qml")
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2020-10-01 10:55:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a "nice" color based on a string by "hashing" it.
|
|
|
|
*/
|
|
|
|
function colorFromString(string) {
|
|
|
|
var hash = 0;
|
|
|
|
for (var i = 0; i < string.length; i++) {
|
|
|
|
hash += string.charCodeAt(i);
|
|
|
|
}
|
|
|
|
hash = (hash % 16) / 16;
|
|
|
|
return Qt.hsva(hash, 1.0, 1.0, 1.0);
|
|
|
|
}
|