mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-05 18:22:46 +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
158
sailfish/qml/pages/itemdetails/CollectionPage.qml
Normal file
158
sailfish/qml/pages/itemdetails/CollectionPage.qml
Normal file
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
import QtQuick 2.6
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
import nl.netsoj.chris.Jellyfin 1.0
|
||||
|
||||
import "../.."
|
||||
import "../../components"
|
||||
|
||||
BaseDetailPage {
|
||||
id: pageRoot
|
||||
|
||||
UserItemModel {
|
||||
id: collectionModel
|
||||
apiClient: ApiClient
|
||||
parentId: itemData.jellyfinId
|
||||
sortBy: ["SortName"]
|
||||
onParentIdChanged: reload()
|
||||
}
|
||||
|
||||
SilicaGridView {
|
||||
id: gridView
|
||||
anchors.fill: parent
|
||||
model: collectionModel
|
||||
cellWidth: Constants.libraryDelegateWidth
|
||||
cellHeight: Utils.usePortraitCover(itemData.CollectionType) ? Constants.libraryDelegatePosterHeight
|
||||
: Constants.libraryDelegateHeight
|
||||
header: PageHeader {
|
||||
title: itemData.Name || qsTr("Loading")
|
||||
}
|
||||
PullDownMenu {
|
||||
id: downMenu
|
||||
MenuItem {
|
||||
//: Menu item for selecting the sort order of a collection
|
||||
text: qsTr("Sort by")
|
||||
onClicked: pageStack.push(sortPageComponent)
|
||||
}
|
||||
busy: collectionModel.status == ApiModel.Loading
|
||||
}
|
||||
delegate: GridItem {
|
||||
RemoteImage {
|
||||
id: itemImage
|
||||
anchors.fill: parent
|
||||
source: Utils.itemModelImageUrl(ApiClient.baseUrl, model.id, model.imageTags["Primary"], "Primary", {"maxWidth": width})
|
||||
fallbackColor: Utils.colorFromString(model.name)
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
clip: true
|
||||
}
|
||||
Shim {
|
||||
anchors {
|
||||
left: parent.left
|
||||
bottom: parent.bottom
|
||||
right: parent.right
|
||||
}
|
||||
height: itemName.height + Theme.paddingMedium * 2
|
||||
visible: itemImage.status !== Image.Null
|
||||
}
|
||||
Label {
|
||||
id: itemName
|
||||
anchors {
|
||||
left: parent.left
|
||||
leftMargin: Theme.paddingMedium
|
||||
right: parent.right
|
||||
rightMargin: Theme.paddingMedium
|
||||
bottom: parent.bottom
|
||||
bottomMargin: Theme.paddingSmall
|
||||
}
|
||||
text: model.name
|
||||
truncationMode: TruncationMode.Fade
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
}
|
||||
onClicked: pageStack.push(Utils.getPageUrl(model.mediaType, model.type), {"itemId": model.id})
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
enabled: gridView.count == 0 && !pageRoot._loading
|
||||
text: qsTr("Empty collection")
|
||||
hintText: qsTr("Add some items to this collection!")
|
||||
}
|
||||
|
||||
VerticalScrollDecorator {}
|
||||
}
|
||||
|
||||
// The page for selecting a sort order
|
||||
|
||||
Component {
|
||||
id: sortPageComponent
|
||||
Page {
|
||||
id: sortPage
|
||||
|
||||
ListModel {
|
||||
id: sortOptions
|
||||
ListElement { name: qsTr("Name"); value: "SortName"; }
|
||||
ListElement { name: qsTr("Play count"); value: "PlayCount"; }
|
||||
ListElement { name: qsTr("Date added"); value: "DateCreated"; }
|
||||
}
|
||||
|
||||
SilicaListView {
|
||||
anchors.fill: parent
|
||||
model: sortOptions
|
||||
header: PageHeader {
|
||||
title: qsTr("Sort by")
|
||||
}
|
||||
delegate: ListItem {
|
||||
Label {
|
||||
anchors {
|
||||
left: parent.left
|
||||
leftMargin: Theme.horizontalPageMargin
|
||||
right: parent.right
|
||||
rightMargin: Theme.horizontalPageMargin
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
text: model.name
|
||||
}
|
||||
menu: ContextMenu {
|
||||
MenuItem {
|
||||
//: Sort order
|
||||
text: qsTr("Ascending")
|
||||
onClicked: apply(model.value, ApiModel.Ascending)
|
||||
}
|
||||
MenuItem {
|
||||
//: Sort order
|
||||
text: qsTr("Descending")
|
||||
onClicked: apply(model.value, ApiModel.Descending)
|
||||
}
|
||||
}
|
||||
onClicked: openMenu()
|
||||
|
||||
function apply(field, order) {
|
||||
collectionModel.sortBy = [field];
|
||||
collectionModel.sortOrder = order;
|
||||
collectionModel.reload()
|
||||
pageStack.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue