mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-06 02:32:44 +00:00
Deserialized a list! Restructured project!
I finally got deserializing lists working. Exposing them to QML was not a trivial task either. Note that I didn't do it the clean way. Nested lists are not supported. But it works! Because I got so frustarted at one point trying to implement things the right way, I restructured the project to seperate the Sailfish code from the Qt code and created a new, empty desktop project. The Qt code has been transformed into a happy little library, to which the Sailfish OS application links. Note that QMake doesn't seem to strip the library for some reason.
This commit is contained in:
parent
4e3395c4e5
commit
1e80ceb697
77 changed files with 507 additions and 213 deletions
105
sailfish/qml/Utils.js
Normal file
105
sailfish/qml/Utils.js
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
.pragma library
|
||||
|
||||
/**
|
||||
* Converts miliseconds to a h:mm:ss format
|
||||
*/
|
||||
function timeToText(time) {
|
||||
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)
|
||||
|
||||
return hours + ":" + (minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "")+ seconds
|
||||
}
|
||||
|
||||
function msToTicks(ms) {
|
||||
return ms * 10000;
|
||||
}
|
||||
|
||||
function ticksToMs(ticks) {
|
||||
return ticks / 10000;
|
||||
}
|
||||
|
||||
function ticksToText(ticks) {
|
||||
return timeToText(ticks / 10000);
|
||||
}
|
||||
|
||||
function itemImageUrl(baseUrl, item, type, options) {
|
||||
if (!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 = "";
|
||||
for (var prop in options) {
|
||||
if (options.hasOwnProperty(prop)) {
|
||||
extraQuery += "&" + prop + "=" + options[prop];
|
||||
}
|
||||
}
|
||||
return baseUrl + "/Items/" + itemId + "/Images/" + type + "?tag=" + tag + extraQuery
|
||||
}
|
||||
|
||||
function usePortraitCover(itemType) {
|
||||
return ["Series", "Movie", "tvshows", "movies"].indexOf(itemType) >= 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page url for a certain item type.
|
||||
*/
|
||||
function getPageUrl(mediaType, itemType) {
|
||||
switch (itemType.toLowerCase()) {
|
||||
case "series":
|
||||
return Qt.resolvedUrl("pages/itemdetails/SeriesPage.qml")
|
||||
case "movie":
|
||||
return Qt.resolvedUrl("pages/itemdetails/FilmPage.qml")
|
||||
case "collection":
|
||||
return Qt.resolvedUrl("pages/itemdetails/CollectionPage.qml")
|
||||
case "season":
|
||||
return Qt.resolvedUrl("pages/itemdetails/SeasonPage.qml")
|
||||
case "episode":
|
||||
return Qt.resolvedUrl("pages/itemdetails/EpisodePage.qml")
|
||||
default:
|
||||
switch (mediaType ? mediaType.toLowerCase() : "folder") {
|
||||
case "folder":
|
||||
return Qt.resolvedUrl("pages/itemdetails/CollectionPage.qml")
|
||||
case "video":
|
||||
return Qt.resolvedUrl("pages/itemdetails/VideoPage.qml")
|
||||
default:
|
||||
return Qt.resolvedUrl("pages/itemdetails/UnsupportedPage.qml")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue