92 lines
2.8 KiB
QML
92 lines
2.8 KiB
QML
import QtQuick 2.5
|
|
import "../Components"
|
|
import "../Shared"
|
|
import "../Shared/Remote.js" as Remote
|
|
import "../Shared/Format.js" as Format
|
|
|
|
// Contenu d'une bibliothèque en grille d'affiches, chargé par pages à mesure qu'on descend.
|
|
Page {
|
|
id: page
|
|
|
|
property var library: null // { id, name, collectionType }
|
|
property int total: 0
|
|
property bool loading: false
|
|
property string error: ""
|
|
|
|
readonly property int pageSize: 60
|
|
|
|
fullscreen: true
|
|
title: library ? library.name : ""
|
|
subtitle: total > 0 ? total + " élément" + (total > 1 ? "s" : "") : ""
|
|
initialFocus: grid
|
|
|
|
function loadMore() {
|
|
if (loading || (total > 0 && itemsModel.count >= total))
|
|
return;
|
|
loading = true;
|
|
page.session.loadLibraryItems(library, itemsModel.count, pageSize, function (err, items, count) {
|
|
page.loading = false;
|
|
if (err) {
|
|
page.error = err;
|
|
return;
|
|
}
|
|
page.total = count;
|
|
for (var i = 0; i < items.length; i++)
|
|
itemsModel.append(items[i]);
|
|
});
|
|
}
|
|
|
|
Component.onCompleted: loadMore()
|
|
Component.onDestruction: if (page.session) page.session.cancel()
|
|
|
|
ListModel {
|
|
id: itemsModel
|
|
}
|
|
|
|
GridView {
|
|
id: grid
|
|
anchors.fill: parent
|
|
clip: true
|
|
focus: true
|
|
// Marges pour la carte agrandie (scale).
|
|
leftMargin: 8
|
|
topMargin: 8
|
|
cellWidth: Theme.posterWidth + Theme.spacingL
|
|
cellHeight: Theme.posterHeight + Theme.cardTextHeight + Theme.spacingL
|
|
model: itemsModel
|
|
|
|
delegate: MediaCard {
|
|
width: Theme.posterWidth
|
|
title: model.name
|
|
subtitle: Format.cardSubtitle(model)
|
|
imageSource: page.session ? page.session.posterUrl(model) : ""
|
|
progress: Format.progress(model)
|
|
played: model.played
|
|
highlighted: GridView.isCurrentItem && grid.activeFocus
|
|
onClicked: {
|
|
grid.currentIndex = index;
|
|
page.navigator.openItem(itemsModel.get(index));
|
|
}
|
|
}
|
|
|
|
// Page suivante quand on approche de la fin.
|
|
onCurrentIndexChanged: if (currentIndex >= count - 14) page.loadMore()
|
|
|
|
Keys.onPressed: {
|
|
if (Remote.isAccept(event.key) && currentIndex >= 0) {
|
|
event.accepted = true;
|
|
page.navigator.openItem(itemsModel.get(currentIndex));
|
|
}
|
|
}
|
|
}
|
|
|
|
Text {
|
|
anchors.centerIn: parent
|
|
visible: text !== ""
|
|
text: page.error !== "" ? page.error
|
|
: itemsModel.count === 0 ? (page.loading ? "Chargement…" : "Cette bibliothèque est vide.") : ""
|
|
color: page.error !== "" ? Theme.error : Theme.textMuted
|
|
font.pixelSize: Theme.fontBody
|
|
}
|
|
}
|