145 lines
4.5 KiB
QML
145 lines
4.5 KiB
QML
import QtQuick 2.5
|
|
import "../Components"
|
|
import "../Shared"
|
|
import "../Shared/Remote.js" as Remote
|
|
|
|
// Accueil : rangées « Reprendre », « Mes médias » et derniers ajouts de chaque bibliothèque.
|
|
// Toutes les rangées sont chargées avant affichage, pour ne pas déplacer le focus en cours de route.
|
|
Page {
|
|
id: page
|
|
|
|
property var rows: []
|
|
property bool loading: true
|
|
property string error: ""
|
|
|
|
fullscreen: true
|
|
title: page.session && page.session.currentUser ? "Bonjour " + page.session.currentUser.name : "Accueil"
|
|
subtitle: page.session && page.session.currentServer ? page.session.currentServer.name : ""
|
|
initialFocus: switchUserButton
|
|
|
|
// La pile a été réinitialisée à la connexion : on reconstruit Serveurs > Utilisateurs.
|
|
function goBack() {
|
|
page.navigator.reset("ServerSelect");
|
|
page.navigator.push("UserSelect");
|
|
}
|
|
|
|
function load() {
|
|
page.session.loadLibraries(function (err, libraries) {
|
|
if (err) {
|
|
page.error = err;
|
|
page.loading = false;
|
|
return;
|
|
}
|
|
var resume = [];
|
|
var latest = [];
|
|
var pending = 1 + libraries.length;
|
|
function done() {
|
|
if (--pending === 0)
|
|
page.build(libraries, resume, latest);
|
|
}
|
|
page.session.loadResume(function (e, items) {
|
|
resume = items;
|
|
done();
|
|
});
|
|
for (var i = 0; i < libraries.length; i++) {
|
|
(function (index) {
|
|
page.session.loadLatest(libraries[index].id, function (e, items) {
|
|
latest[index] = items;
|
|
done();
|
|
});
|
|
})(i);
|
|
}
|
|
});
|
|
}
|
|
|
|
function build(libraries, resume, latest) {
|
|
var list = [];
|
|
if (resume.length > 0)
|
|
list.push({ title: "Reprendre", items: resume, landscape: true });
|
|
if (libraries.length > 0)
|
|
list.push({ title: "Mes médias", items: libraries, landscape: true });
|
|
for (var i = 0; i < libraries.length; i++) {
|
|
if (latest[i] && latest[i].length > 0)
|
|
list.push({ title: "Ajouts récents · " + libraries[i].name, items: latest[i], landscape: false });
|
|
}
|
|
rows = list;
|
|
loading = false;
|
|
if (list.length > 0)
|
|
rowsList.forceActiveFocus();
|
|
}
|
|
|
|
Component.onCompleted: load()
|
|
Component.onDestruction: if (page.session) page.session.cancel()
|
|
|
|
// Retour : choix de l'utilisateur (sinon, à la racine de la pile, l'app se fermerait).
|
|
Keys.onPressed: {
|
|
if (Remote.isBack(event.key)) {
|
|
event.accepted = true;
|
|
page.goBack();
|
|
}
|
|
}
|
|
|
|
Row {
|
|
id: actions
|
|
spacing: Theme.spacingM
|
|
|
|
FocusButton {
|
|
id: switchUserButton
|
|
text: "Changer d'utilisateur"
|
|
KeyNavigation.right: logoutButton
|
|
KeyNavigation.down: rowsList
|
|
onClicked: page.goBack()
|
|
}
|
|
|
|
FocusButton {
|
|
id: logoutButton
|
|
text: "Se déconnecter"
|
|
KeyNavigation.left: switchUserButton
|
|
KeyNavigation.down: rowsList
|
|
onClicked: {
|
|
page.session.logout();
|
|
page.goBack();
|
|
}
|
|
}
|
|
}
|
|
|
|
ListView {
|
|
id: rowsList
|
|
anchors {
|
|
top: actions.bottom
|
|
topMargin: Theme.spacingL
|
|
left: parent.left
|
|
right: parent.right
|
|
bottom: parent.bottom
|
|
}
|
|
clip: true
|
|
spacing: Theme.spacingS
|
|
model: page.rows
|
|
|
|
delegate: MediaRow {
|
|
width: rowsList.width
|
|
title: modelData.title
|
|
items: modelData.items
|
|
landscape: modelData.landscape
|
|
session: page.session
|
|
onActivated: page.navigator.openItem(item)
|
|
}
|
|
|
|
// La rangée courante reste en haut de la zone visible.
|
|
onCurrentIndexChanged: positionViewAtIndex(currentIndex, ListView.Beginning)
|
|
|
|
KeyNavigation.priority: KeyNavigation.AfterItem
|
|
KeyNavigation.up: switchUserButton
|
|
}
|
|
|
|
Text {
|
|
anchors.centerIn: rowsList
|
|
visible: text !== ""
|
|
text: page.loading ? "Chargement…"
|
|
: page.error !== "" ? page.error
|
|
: page.rows.length === 0 ? "Aucun média disponible pour ce compte." : ""
|
|
color: page.error !== "" ? Theme.error : Theme.textMuted
|
|
font.pixelSize: Theme.fontBody
|
|
}
|
|
}
|