diff --git a/Components/FocusButton.qml b/Components/FocusButton.qml new file mode 100644 index 0000000..d1f6b02 --- /dev/null +++ b/Components/FocusButton.qml @@ -0,0 +1,46 @@ +import QtQuick 2.5 +import "." + +// Bouton navigable à la télécommande : surbrillance blanche quand il a le focus. +Rectangle { + id: root + + property alias text: label.text + property bool primary: false + signal clicked() + + implicitWidth: Math.max(160, label.implicitWidth + Theme.spacingL * 2) + implicitHeight: Theme.controlHeight + radius: Theme.radius + opacity: enabled ? 1 : 0.5 + color: activeFocus ? Theme.focusBackground : (primary ? Theme.accent : Theme.surface) + scale: activeFocus ? 1.05 : 1 + + Behavior on scale { NumberAnimation { duration: Theme.animFast } } + Behavior on color { ColorAnimation { duration: Theme.animFast } } + + Text { + id: label + anchors.centerIn: parent + color: root.activeFocus ? Theme.textOnFocus : Theme.text + font.pixelSize: Theme.fontBody + font.bold: root.activeFocus + } + + Keys.onPressed: { + if (Remote.isAccept(event.key)) { + event.accepted = true; + root.clicked(); + } + } + + // Souris : pratique pour tester hors de la box. + MouseArea { + anchors.fill: parent + enabled: root.enabled + onClicked: { + root.forceActiveFocus(); + root.clicked(); + } + } +} diff --git a/Views/Logo.qml b/Components/Logo.qml similarity index 50% rename from Views/Logo.qml rename to Components/Logo.qml index d21787a..c60c7c2 100644 --- a/Views/Logo.qml +++ b/Components/Logo.qml @@ -1,11 +1,9 @@ import QtQuick 2.5 +import "." -// Display the logo +// Panneau de gauche avec le logo, affiché sur tous les écrans de connexion. Rectangle { - width: parent.width - height: parent.height - - color: "#000B25" + color: Theme.panel Image { anchors.centerIn: parent diff --git a/Components/Page.qml b/Components/Page.qml new file mode 100644 index 0000000..b937b1b --- /dev/null +++ b/Components/Page.qml @@ -0,0 +1,60 @@ +import QtQuick 2.5 +import "." + +// Base de chaque écran : en-tête (titre + sous-titre) et zone de contenu. +// `navigator` et `session` sont injectés par le Navigator au chargement. +FocusScope { + id: page + + property var navigator: null + property var session: null + // Élément qui reçoit le focus quand l'écran s'affiche. + property Item initialFocus: null + + property alias title: titleText.text + property alias subtitle: subtitleText.text + default property alias content: body.data + + Column { + id: header + anchors { + top: parent.top + left: parent.left + right: parent.right + margins: Theme.pageMargin + } + spacing: Theme.spacingS + + Text { + id: titleText + width: parent.width + color: Theme.text + font.pixelSize: Theme.fontTitle + font.bold: true + elide: Text.ElideRight + } + + Text { + id: subtitleText + width: parent.width + visible: text !== "" + color: Theme.textMuted + font.pixelSize: Theme.fontBody + wrapMode: Text.WordWrap + } + } + + Item { + id: body + anchors { + top: header.bottom + topMargin: Theme.spacingXL + left: parent.left + right: parent.right + bottom: parent.bottom + leftMargin: Theme.pageMargin + rightMargin: Theme.pageMargin + bottomMargin: Theme.pageMargin + } + } +} diff --git a/Components/Remote.qml b/Components/Remote.qml new file mode 100644 index 0000000..ead9949 --- /dev/null +++ b/Components/Remote.qml @@ -0,0 +1,14 @@ +pragma Singleton +import QtQuick 2.5 + +// Correspondance des touches de la télécommande Freebox. +// Plusieurs codes sont acceptés tant que le mapping exact sur la box n'est pas vérifié. +QtObject { + function isAccept(key) { + return key === Qt.Key_Return || key === Qt.Key_Enter || key === Qt.Key_Select; + } + + function isBack(key) { + return key === Qt.Key_Back || key === Qt.Key_Escape; + } +} diff --git a/Components/ServerItem.qml b/Components/ServerItem.qml new file mode 100644 index 0000000..f3c0f3e --- /dev/null +++ b/Components/ServerItem.qml @@ -0,0 +1,94 @@ +import QtQuick 2.5 +import "." + +// Ligne de la liste des serveurs. +Rectangle { + id: root + + property string name: "" + property string address: "" + property bool discovered: false + property bool highlighted: false + signal clicked() + + height: 72 + radius: Theme.radius + color: highlighted ? Theme.focusBackground : Theme.surface + + Behavior on color { ColorAnimation { duration: Theme.animFast } } + + Rectangle { + id: icon + anchors { + left: parent.left + leftMargin: Theme.spacingM + verticalCenter: parent.verticalCenter + } + width: 40 + height: 40 + radius: width / 2 + color: Theme.avatarColor(root.name) + + Text { + anchors.centerIn: parent + text: root.name.charAt(0).toUpperCase() + color: Theme.text + font.pixelSize: Theme.fontBody + font.bold: true + } + } + + Column { + anchors { + left: icon.right + leftMargin: Theme.spacingM + right: root.discovered ? tag.left : parent.right + rightMargin: Theme.spacingM + verticalCenter: parent.verticalCenter + } + + Text { + width: parent.width + text: root.name + color: root.highlighted ? Theme.textOnFocus : Theme.text + font.pixelSize: Theme.fontBody + font.bold: true + elide: Text.ElideRight + } + + Text { + width: parent.width + text: root.address + color: root.highlighted ? Theme.textOnFocusMuted : Theme.textMuted + font.pixelSize: Theme.fontSmall + elide: Text.ElideRight + } + } + + Rectangle { + id: tag + visible: root.discovered + anchors { + right: parent.right + rightMargin: Theme.spacingM + verticalCenter: parent.verticalCenter + } + width: tagText.implicitWidth + Theme.spacingM + height: tagText.implicitHeight + Theme.spacingS + radius: height / 2 + color: Theme.accentAlt + + Text { + id: tagText + anchors.centerIn: parent + text: "Réseau local" + color: Theme.text + font.pixelSize: Theme.fontSmall + } + } + + MouseArea { + anchors.fill: parent + onClicked: root.clicked() + } +} diff --git a/Components/TextField.qml b/Components/TextField.qml new file mode 100644 index 0000000..7de07c8 --- /dev/null +++ b/Components/TextField.qml @@ -0,0 +1,71 @@ +import QtQuick 2.5 +import "." + +// Champ de saisie avec libellé. Haut/Bas ne sont pas consommés par le TextInput +// et remontent donc jusqu'au KeyNavigation posé sur ce composant. +FocusScope { + id: root + + property alias label: labelText.text + property alias text: input.text + property alias placeholder: placeholderText.text + property bool password: false + signal accepted() + + implicitWidth: 400 + implicitHeight: column.implicitHeight + + MouseArea { + anchors.fill: parent + onClicked: input.forceActiveFocus() + } + + Column { + id: column + width: parent.width + spacing: Theme.spacingS + + Text { + id: labelText + visible: text !== "" + color: root.activeFocus ? Theme.text : Theme.textMuted + font.pixelSize: Theme.fontSmall + } + + Rectangle { + width: parent.width + height: Theme.controlHeight + radius: Theme.radius + color: Theme.surface + border.width: 2 + border.color: root.activeFocus ? Theme.accent : Theme.border + + TextInput { + id: input + anchors { + fill: parent + leftMargin: Theme.spacingM + rightMargin: Theme.spacingM + } + focus: true + clip: true + verticalAlignment: TextInput.AlignVCenter + color: Theme.text + selectionColor: Theme.accent + font.pixelSize: Theme.fontBody + echoMode: root.password ? TextInput.Password : TextInput.Normal + onAccepted: root.accepted() + } + + Text { + id: placeholderText + anchors.fill: input + visible: input.text === "" + verticalAlignment: Text.AlignVCenter + color: Theme.textMuted + font: input.font + elide: Text.ElideRight + } + } + } +} diff --git a/Components/Theme.qml b/Components/Theme.qml new file mode 100644 index 0000000..604ef6a --- /dev/null +++ b/Components/Theme.qml @@ -0,0 +1,46 @@ +pragma Singleton +import QtQuick 2.5 + +// Couleurs, tailles et animations partagées par toute l'application. +QtObject { + // Couleurs (inspirées de la palette Jellyfin) + readonly property color background: "#101010" + readonly property color panel: "#000B25" + readonly property color surface: "#202020" + readonly property color border: "#3A3A3A" + readonly property color focusBackground: "#FFFFFF" + readonly property color text: "#FFFFFF" + readonly property color textMuted: "#A0A0A0" + readonly property color textOnFocus: "#101010" + readonly property color textOnFocusMuted: "#505050" + readonly property color accent: "#00A4DC" + readonly property color accentAlt: "#AA5CC3" + readonly property color error: "#FF5252" + readonly property var avatarColors: ["#AA5CC3", "#00A4DC", "#E67E22", "#27AE60", "#C0392B", "#2C3E50"] + + // Espacements + readonly property int pageMargin: 48 + readonly property int spacingS: 8 + readonly property int spacingM: 16 + readonly property int spacingL: 24 + readonly property int spacingXL: 40 + + // Typographie + readonly property int fontSmall: 14 + readonly property int fontBody: 18 + readonly property int fontTitle: 32 + readonly property int fontCode: 56 + + // Contrôles + readonly property int controlHeight: 48 + readonly property int radius: 6 + readonly property int animFast: 120 + + // Couleur stable dérivée d'un nom (avatars, icônes de serveur). + function avatarColor(name) { + var hash = 0; + for (var i = 0; i < name.length; i++) + hash = (hash * 31 + name.charCodeAt(i)) % 100000; + return avatarColors[hash % avatarColors.length]; + } +} diff --git a/Components/UserCard.qml b/Components/UserCard.qml new file mode 100644 index 0000000..1afc727 --- /dev/null +++ b/Components/UserCard.qml @@ -0,0 +1,58 @@ +import QtQuick 2.5 +import "." + +// Carte utilisateur (avatar rond + nom). `addCard` affiche la carte « Ajouter un compte ». +Item { + id: root + + property string name: "" + property bool addCard: false + property bool highlighted: false + signal clicked() + + width: 140 + height: 200 + + Rectangle { + id: avatar + anchors.horizontalCenter: parent.horizontalCenter + y: Theme.spacingS + width: 120 + height: 120 + radius: width / 2 + color: root.addCard ? Theme.surface : Theme.avatarColor(root.name) + border.width: root.highlighted ? 4 : 0 + border.color: Theme.focusBackground + scale: root.highlighted ? 1.1 : 1 + + Behavior on scale { NumberAnimation { duration: Theme.animFast } } + + Text { + anchors.centerIn: parent + text: root.addCard ? "+" : root.name.charAt(0).toUpperCase() + color: Theme.text + font.pixelSize: 48 + font.bold: true + } + } + + Text { + anchors { + top: avatar.bottom + topMargin: Theme.spacingL + left: parent.left + right: parent.right + } + text: root.name + horizontalAlignment: Text.AlignHCenter + elide: Text.ElideRight + color: root.highlighted ? Theme.text : Theme.textMuted + font.pixelSize: Theme.fontBody + font.bold: root.highlighted + } + + MouseArea { + anchors.fill: parent + onClicked: root.clicked() + } +} diff --git a/Components/qmldir b/Components/qmldir new file mode 100644 index 0000000..c346c9d --- /dev/null +++ b/Components/qmldir @@ -0,0 +1,8 @@ +singleton Theme 1.0 Theme.qml +singleton Remote 1.0 Remote.qml +Page 1.0 Page.qml +FocusButton 1.0 FocusButton.qml +TextField 1.0 TextField.qml +ServerItem 1.0 ServerItem.qml +UserCard 1.0 UserCard.qml +Logo 1.0 Logo.qml diff --git a/Core/Navigator.qml b/Core/Navigator.qml new file mode 100644 index 0000000..7b5ad69 --- /dev/null +++ b/Core/Navigator.qml @@ -0,0 +1,73 @@ +import QtQuick 2.5 +import "../Components" + +// Pile de navigation entre les écrans de Views/. +// push("ServerAdd") charge Views/ServerAddView.qml ; la touche Retour dépile. +// Chaque écran reçoit `navigator` et `session`, plus les propriétés passées à push(). +FocusScope { + id: root + + property var session: null + property int depth: 0 + property var _stack: [] + + function push(name, props) { + _stack.push({ name: name, props: props || {} }); + _load(); + } + + function replace(name, props) { + if (_stack.length > 0) + _stack.pop(); + push(name, props); + } + + function pop() { + if (_stack.length <= 1) + return false; + _stack.pop(); + _load(); + return true; + } + + function reset(name, props) { + _stack = []; + push(name, props); + } + + function _load() { + var entry = _stack[_stack.length - 1]; + var props = { navigator: root, session: root.session }; + for (var key in entry.props) + props[key] = entry.props[key]; + depth = _stack.length; + loader.setSource(Qt.resolvedUrl("../Views/" + entry.name + "View.qml"), props); + } + + Loader { + id: loader + anchors.fill: parent + focus: true + + onLoaded: { + fadeIn.restart(); + var target = item.initialFocus ? item.initialFocus : item; + target.forceActiveFocus(); + } + } + + NumberAnimation { + id: fadeIn + target: loader.item + property: "opacity" + from: 0 + to: 1 + duration: 180 + } + + // Retour : on dépile ; à la racine, la touche remonte (fermeture de l'app). + Keys.onPressed: { + if (Remote.isBack(event.key) && pop()) + event.accepted = true; + } +} diff --git a/Core/Session.qml b/Core/Session.qml new file mode 100644 index 0000000..3b28e39 --- /dev/null +++ b/Core/Session.qml @@ -0,0 +1,118 @@ +import QtQuick 2.5 + +// État de connexion : serveurs connus, serveur et utilisateur courants. +// Les appels réseau sont SIMULÉS (_simulate) : à remplacer par l'API Jellyfin +// en gardant la forme des callbacks `callback(erreur, résultat)`. +QtObject { + id: session + + property ListModel servers: ListModel { + // Données fictives + ListElement { name: "Maison"; address: "http://192.168.1.20:8096"; discovered: false } + ListElement { name: "jellyfin-nas"; address: "http://192.168.1.42:8096"; discovered: true } + } + + property var currentServer: null // { name, address } + property var currentUser: null // { name } + + function selectServer(index) { + var server = servers.get(index); + currentServer = { name: server.name, address: server.address }; + } + + // Ajoute (ou retrouve) un serveur à partir de l'adresse saisie. + // TODO API : valider via GET /System/Info/Public et utiliser ServerName. + function connectToServer(rawAddress, callback) { + var address = normalizeAddress(rawAddress); + if (address === "") { + callback("Veuillez saisir l'adresse du serveur."); + return; + } + _simulate(function () { + var index = _indexOfServer(address); + if (index < 0) { + servers.insert(0, { name: _hostOf(address), address: address, discovered: false }); + index = 0; + } + selectServer(index); + callback(null, currentServer); + }); + } + + // TODO API : GET /Users/Public + function publicUsers() { + return [ + { name: "Alice", hasPassword: true }, + { name: "Bob", hasPassword: false }, + { name: "Enfants", hasPassword: false } + ]; + } + + // TODO API : POST /Users/AuthenticateByName + function authenticate(username, password, callback) { + var name = (username || "").trim(); + if (name === "") { + callback("Veuillez saisir votre nom d'utilisateur."); + return; + } + _simulate(function () { + currentUser = { name: name }; + callback(null, currentUser); + }); + } + + // TODO API : POST /QuickConnect/Initiate puis interroger /QuickConnect/Connect + function startQuickConnect() { + var code = ""; + for (var i = 0; i < 6; i++) + code += Math.floor(Math.random() * 10); + return code; + } + + function logout() { + currentUser = null; + } + + function cancel() { + _pending = null; + _latency.stop(); + } + + function normalizeAddress(text) { + var address = (text || "").trim(); + if (address === "") + return ""; + if (!/^https?:\/\//i.test(address)) + address = "http://" + address; + return address.replace(/\/+$/, ""); + } + + function _hostOf(address) { + return address.replace(/^https?:\/\//i, "").split(/[:\/]/)[0]; + } + + function _indexOfServer(address) { + for (var i = 0; i < servers.count; i++) { + if (servers.get(i).address === address) + return i; + } + return -1; + } + + // Simulation de latence réseau. + property var _pending: null + property Timer _latency: Timer { + interval: 700 + onTriggered: { + var callback = session._pending; + session._pending = null; + if (callback) + callback(); + } + } + + function _simulate(callback) { + _pending = callback; + _latency.restart(); + } +} diff --git a/Jellyfin.qml b/Jellyfin.qml index 8102cbc..71a85ec 100644 --- a/Jellyfin.qml +++ b/Jellyfin.qml @@ -1,32 +1,35 @@ import QtQuick 2.5 import fbx.application 1.0 -import "Views" as View +import "Components" +import "Core" Application { + Rectangle { + anchors.fill: parent + color: Theme.background + } + + Session { + id: appSession + } + Row { anchors.fill: parent - spacing: 10 - Rectangle { - width: parent.width / 3 - 5 + Logo { + id: logo + width: parent.width / 3 height: parent.height - - View.Logo {} } - Rectangle { - width: parent.width / 3 * 2 - 5 + + Navigator { + id: navigator + width: parent.width - logo.width height: parent.height - - color: "#000B25" - + session: appSession focus: true - - View.Login {} - } - - Component.onCompleted: { - // Setup the login view to be focus on start - columnLogin.updateSelection(); } } + + Component.onCompleted: navigator.push("ServerSelect") } diff --git a/Views/HomeView.qml b/Views/HomeView.qml new file mode 100644 index 0000000..0400c37 --- /dev/null +++ b/Views/HomeView.qml @@ -0,0 +1,24 @@ +import QtQuick 2.5 +import "../Components" + +// Écran d'accueil provisoire : confirme la connexion en attendant la vraie bibliothèque. +Page { + id: page + + title: page.session && page.session.currentUser + ? "Bonjour " + page.session.currentUser.name + : "Accueil" + subtitle: page.session && page.session.currentServer + ? "Connecté à " + page.session.currentServer.name + "." + : "" + initialFocus: logoutButton + + FocusButton { + id: logoutButton + text: "Se déconnecter" + onClicked: { + page.session.logout(); + page.navigator.reset("UserSelect"); + } + } +} diff --git a/Views/Login.qml b/Views/Login.qml deleted file mode 100644 index b3e14b1..0000000 --- a/Views/Login.qml +++ /dev/null @@ -1,75 +0,0 @@ -import QtQuick 2.5 - -Column { - // Liste des labels et types - property var fields: [ - {label: "Server", type: "text"}, - {label: "User", type: "text"}, - {label: "Password", type: "password"} - ] - - property int currentIndex: 0 - - id: columnLogin - - //anchors.centerIn: parent - anchors.verticalCenter: parent.verticalCenter - anchors.margins: 20 - spacing: 15 - width: parent.width * 0.8 - - function updateSelection() { - for (let i = 0; i < repeater.count; i++) { - repeater.itemAt(i).color = i === columnLogin.currentIndex ? "lightblue" : "transparent"; - } - } - - // Repeater pour générer les champs basés sur la liste des labels et types - Repeater { - model: fields - - Row { - spacing: 10 - - Text { - width: parent.width / 2 - 5 - text: modelData.label + ":" - color: "white" - font.pixelSize: 16 - } - - // TextInput pour les champs Server et User, et mode Password pour Password - Rectangle { - width: 200 - height: 20 - color: "white" - //border.color: "black" - //border.width: 3 - //radius: 5 - - TextInput { - font.pixelSize: 16 - color: "black" - text: modelData.label - - // Détermine le mode de saisie en fonction du type - echoMode: modelData.type === "password" ? TextInput.Password : TextInput.Normal - } - } - } - - Keys.onPressed: { - if (event.key === Qt.Key_Up) { - if (currentIndex > 0) { - currentIndex--; - updateSelection(); - } - } else if (event.key == Qt.Key_Down) { - if (currentIndex < repeater.children.length - 1) { - currentIndex++; - updateSelection() - } - } - } - } -} diff --git a/Views/LoginView.qml b/Views/LoginView.qml new file mode 100644 index 0000000..5cd635a --- /dev/null +++ b/Views/LoginView.qml @@ -0,0 +1,140 @@ +import QtQuick 2.5 +import "../Components" + +// Écran 4 : connexion par mot de passe ou par Quick Connect. +Page { + id: page + + property string username: "" + property bool quickConnect: false + property string quickConnectCode: "" + property bool busy: false + property string error: "" + + title: quickConnect ? "Quick Connect" : "Se connecter" + subtitle: page.session && page.session.currentServer + ? "Serveur : " + page.session.currentServer.name + : "" + initialFocus: username !== "" ? passwordField : usernameField + + function signIn() { + if (busy) + return; + error = ""; + busy = true; + page.session.authenticate(usernameField.text, passwordField.text, function (err) { + page.busy = false; + if (err) { + page.error = err; + (usernameField.text.trim() === "" ? usernameField : passwordField).forceActiveFocus(); + return; + } + // Réinitialise la pile : Retour ne doit pas revenir à l'écran de connexion. + page.navigator.reset("Home"); + }); + } + + function setQuickConnect(enabled) { + error = ""; + quickConnect = enabled; + if (enabled) { + quickConnectCode = page.session.startQuickConnect(); + passwordModeButton.forceActiveFocus(); + } else { + page.initialFocus.forceActiveFocus(); + } + } + + Component.onDestruction: if (page.session) page.session.cancel() + + Column { + id: passwordForm + visible: !page.quickConnect + width: Math.min(parent.width, 560) + spacing: Theme.spacingL + + TextField { + id: usernameField + width: parent.width + label: "Nom d'utilisateur" + text: page.username + KeyNavigation.down: passwordField + onAccepted: passwordField.forceActiveFocus() + } + + TextField { + id: passwordField + width: parent.width + label: "Mot de passe" + password: true + KeyNavigation.up: usernameField + KeyNavigation.down: signInButton + onAccepted: page.signIn() + } + + Text { + width: parent.width + visible: text !== "" + text: page.error + color: Theme.error + font.pixelSize: Theme.fontBody + wrapMode: Text.WordWrap + } + + Row { + spacing: Theme.spacingM + + FocusButton { + id: signInButton + primary: true + text: page.busy ? "Connexion…" : "Se connecter" + KeyNavigation.up: passwordField + KeyNavigation.right: quickConnectButton + onClicked: page.signIn() + } + + FocusButton { + id: quickConnectButton + text: "Utiliser Quick Connect" + KeyNavigation.up: passwordField + KeyNavigation.left: signInButton + onClicked: page.setQuickConnect(true) + } + } + } + + Column { + id: quickConnectPanel + visible: page.quickConnect + width: Math.min(parent.width, 560) + spacing: Theme.spacingL + + Text { + width: parent.width + text: "Depuis un appareil déjà connecté, ouvrez Quick Connect dans les paramètres de votre compte Jellyfin et saisissez ce code :" + color: Theme.textMuted + font.pixelSize: Theme.fontBody + wrapMode: Text.WordWrap + } + + Text { + text: page.quickConnectCode + color: Theme.accent + font.pixelSize: Theme.fontCode + font.bold: true + font.letterSpacing: 8 + } + + Text { + text: "En attente d'autorisation…" + color: Theme.textMuted + font.pixelSize: Theme.fontSmall + } + + FocusButton { + id: passwordModeButton + text: "Utiliser un mot de passe" + onClicked: page.setQuickConnect(false) + } + } +} diff --git a/Views/ServerAddView.qml b/Views/ServerAddView.qml new file mode 100644 index 0000000..82bf8fa --- /dev/null +++ b/Views/ServerAddView.qml @@ -0,0 +1,64 @@ +import QtQuick 2.5 +import "../Components" + +// Écran 2 : saisie manuelle de l'adresse d'un serveur. +Page { + id: page + + property bool busy: false + property string error: "" + + title: "Ajouter un serveur" + subtitle: "Saisissez l'adresse de votre serveur Jellyfin, par exemple 192.168.1.20:8096." + initialFocus: addressField + + function connect() { + if (busy) + return; + error = ""; + busy = true; + page.session.connectToServer(addressField.text, function (err) { + page.busy = false; + if (err) { + page.error = err; + addressField.forceActiveFocus(); + return; + } + // Remplace cet écran : Retour depuis la liste des utilisateurs ramène aux serveurs. + page.navigator.replace("UserSelect"); + }); + } + + Component.onDestruction: if (page.session) page.session.cancel() + + Column { + width: Math.min(parent.width, 560) + spacing: Theme.spacingL + + TextField { + id: addressField + width: parent.width + label: "Adresse du serveur" + placeholder: "http://192.168.1.20:8096" + KeyNavigation.down: connectButton + onAccepted: page.connect() + } + + Text { + width: parent.width + visible: text !== "" + text: page.error + color: Theme.error + font.pixelSize: Theme.fontBody + wrapMode: Text.WordWrap + } + + FocusButton { + id: connectButton + primary: true + text: page.busy ? "Connexion…" : "Se connecter" + KeyNavigation.up: addressField + onClicked: page.connect() + } + } +} diff --git a/Views/ServerSelectView.qml b/Views/ServerSelectView.qml new file mode 100644 index 0000000..f0a79a8 --- /dev/null +++ b/Views/ServerSelectView.qml @@ -0,0 +1,65 @@ +import QtQuick 2.5 +import "../Components" + +// Écran 1 : choix d'un serveur enregistré ou découvert sur le réseau local. +Page { + id: page + + title: "Sélectionner un serveur" + subtitle: serverList.count > 0 + ? "Choisissez le serveur Jellyfin auquel vous connecter." + : "Aucun serveur enregistré. Ajoutez l'adresse de votre serveur Jellyfin." + initialFocus: serverList.count > 0 ? serverList : addButton + + function openServer(index) { + page.session.selectServer(index); + page.navigator.push("UserSelect"); + } + + ListView { + id: serverList + anchors { + top: parent.top + left: parent.left + right: parent.right + bottom: addButton.top + bottomMargin: Theme.spacingL + } + clip: true + spacing: Theme.spacingS + model: page.session ? page.session.servers : null + + delegate: ServerItem { + width: serverList.width + name: model.name + address: model.address + discovered: model.discovered + highlighted: ListView.isCurrentItem && serverList.activeFocus + onClicked: { + serverList.currentIndex = index; + page.openServer(index); + } + } + + Keys.onPressed: { + if (Remote.isAccept(event.key) && currentIndex >= 0) { + event.accepted = true; + page.openServer(currentIndex); + } + } + // Laisse la ListView gérer Haut/Bas ; on ne sort qu'en bout de liste. + KeyNavigation.priority: KeyNavigation.AfterItem + KeyNavigation.down: addButton + } + + FocusButton { + id: addButton + anchors { + left: parent.left + bottom: parent.bottom + } + text: "Ajouter un serveur" + KeyNavigation.up: serverList.count > 0 ? serverList : null + onClicked: page.navigator.push("ServerAdd") + } +} diff --git a/Views/UserSelectView.qml b/Views/UserSelectView.qml new file mode 100644 index 0000000..b5edd29 --- /dev/null +++ b/Views/UserSelectView.qml @@ -0,0 +1,102 @@ +import QtQuick 2.5 +import "../Components" + +// Écran 3 : choix de l'utilisateur parmi les comptes publics du serveur. +Page { + id: page + + property var users: page.session ? page.session.publicUsers() : [] + property bool busy: false + property string error: "" + + title: "Qui regarde ?" + subtitle: page.session && page.session.currentServer + ? page.session.currentServer.name + " · " + page.session.currentServer.address + : "" + initialFocus: userList + + function openUser(index) { + if (busy) + return; + // Dernière carte : « Ajouter un compte » → identifiant libre. + if (index >= users.length) { + page.navigator.push("Login"); + return; + } + var user = users[index]; + if (user.hasPassword) { + page.navigator.push("Login", { username: user.name }); + return; + } + // Compte sans mot de passe : connexion directe, comme sur Android TV. + error = ""; + busy = true; + page.session.authenticate(user.name, "", function (err) { + page.busy = false; + if (err) { + page.error = err; + return; + } + page.navigator.reset("Home"); + }); + } + + Component.onDestruction: if (page.session) page.session.cancel() + + ListView { + id: userList + anchors { + top: parent.top + left: parent.left + right: parent.right + } + height: 220 + orientation: ListView.Horizontal + spacing: Theme.spacingL + model: page.users.concat([{ name: "Ajouter un compte", add: true }]) + + delegate: UserCard { + name: modelData.name + addCard: modelData.add === true + highlighted: ListView.isCurrentItem && userList.activeFocus + onClicked: { + userList.currentIndex = index; + page.openUser(index); + } + } + + Keys.onPressed: { + if (Remote.isAccept(event.key) && currentIndex >= 0) { + event.accepted = true; + page.openUser(currentIndex); + } + } + KeyNavigation.priority: KeyNavigation.AfterItem + KeyNavigation.down: changeServerButton + } + + Text { + id: statusText + anchors { + top: userList.bottom + left: parent.left + right: parent.right + } + visible: text !== "" + text: page.busy ? "Connexion…" : page.error + color: page.busy ? Theme.textMuted : Theme.error + font.pixelSize: Theme.fontBody + wrapMode: Text.WordWrap + } + + FocusButton { + id: changeServerButton + anchors { + left: parent.left + bottom: parent.bottom + } + text: "Changer de serveur" + KeyNavigation.up: userList + onClicked: page.navigator.pop() + } +}