Fix more behaviors view
This commit is contained in:
1 parent
f6462f05b8
commit
acb58142d9
4 files changed
+87
-20
No files matched your search
@@ -38,6 +38,7 @@ There is no build system or test suite.
|
||||
|
||||
- Target is QtQuick 2.5 (Qt 5.5 era): **ES5 JavaScript only** (`var`, `function`; no `let`/`const`/arrow functions) and no QtQuick.Controls.
|
||||
- Input is a TV remote: navigation uses `KeyNavigation` + explicit focus. On a `ListView`, set `KeyNavigation.priority: KeyNavigation.AfterItem` so the list handles arrows itself and only hands off at its ends.
|
||||
- The box's virtual keyboard lacks `:` (and likely `/`): never require typing a URL scheme or `host:port`. Server entry takes host + optional numeric port; `Session.serverCandidates()` derives the URLs to probe (https, http:8096, https:8920, http).
|
||||
- In bindings, guard `page.session`/`page.navigator` against null: they are injected after bindings are first evaluated.
|
||||
- **HTTP loading rules** (the box fetches files over HTTP, so directories can't be listed):
|
||||
- every imported directory needs a `qmldir` listing all its types (`Core/`, `Components/`, `Shared/`); a missing one gives "X is not a type" only on the box;
|
||||
|
||||
@@ -10,6 +10,10 @@ FocusScope {
|
||||
property alias text: input.text
|
||||
property alias placeholder: placeholderText.text
|
||||
property bool password: false
|
||||
// Ex. Qt.ImhDigitsOnly pour demander un clavier numérique (si le système le gère).
|
||||
property alias inputMethodHints: input.inputMethodHints
|
||||
property alias validator: input.validator
|
||||
property alias maximumLength: input.maximumLength
|
||||
signal accepted()
|
||||
|
||||
implicitWidth: 400
|
||||
|
||||
+60
-15
@@ -20,15 +20,24 @@ QtObject {
|
||||
currentServer = { name: server.name, address: server.address };
|
||||
}
|
||||
|
||||
// Ajoute (ou retrouve) un serveur à partir de l'adresse saisie.
|
||||
// TODO API : valider via GET <adresse>/System/Info/Public et utiliser ServerName.
|
||||
function connectToServer(rawAddress, callback) {
|
||||
var address = normalizeAddress(rawAddress);
|
||||
if (address === "") {
|
||||
// Ajoute (ou retrouve) un serveur à partir de l'hôte saisi et d'un port facultatif.
|
||||
// Le clavier de la box n'a ni « : » ni « / » : le protocole et le port sont
|
||||
// détectés en essayant chaque adresse de serverCandidates() dans l'ordre.
|
||||
function connectToServer(host, port, callback) {
|
||||
if ((host || "").trim() === "") {
|
||||
callback("Veuillez saisir l'adresse du serveur.");
|
||||
return;
|
||||
}
|
||||
_simulate(function () {
|
||||
var portText = (port || "").trim();
|
||||
if (portText !== "" && !isValidPort(portText)) {
|
||||
callback("Le port doit être un nombre entre 1 et 65535.");
|
||||
return;
|
||||
}
|
||||
_probeCandidates(serverCandidates(host, portText), 0, function (err, address) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
var index = _indexOfServer(address);
|
||||
if (index < 0) {
|
||||
servers.insert(0, { name: _hostOf(address), address: address, discovered: false });
|
||||
@@ -39,6 +48,51 @@ QtObject {
|
||||
});
|
||||
}
|
||||
|
||||
// Adresses à essayer, de la plus probable à la moins probable
|
||||
// (même logique que les clients Jellyfin officiels).
|
||||
function serverCandidates(host, port) {
|
||||
var text = (host || "").trim().replace(/\/+$/, "");
|
||||
if (text === "")
|
||||
return [];
|
||||
// Adresse complète (saisie depuis un clavier qui a « : ») : utilisée telle quelle.
|
||||
if (/^https?:\/\//i.test(text)) {
|
||||
if (port && !/:\d+$/.test(text.replace(/^https?:\/\//i, "")))
|
||||
text += ":" + port;
|
||||
return [text];
|
||||
}
|
||||
if (port)
|
||||
return ["https://" + text + ":" + port, "http://" + text + ":" + port];
|
||||
// Port déjà inclus dans l'hôte (ex. 192.168.1.20:8096).
|
||||
if (/:\d+$/.test(text))
|
||||
return ["https://" + text, "http://" + text];
|
||||
return [
|
||||
"https://" + text,
|
||||
"http://" + text + ":8096",
|
||||
"https://" + text + ":8920",
|
||||
"http://" + text
|
||||
];
|
||||
}
|
||||
|
||||
// Essaie les adresses une par une ; renvoie la première qui répond.
|
||||
// TODO API : GET <adresse>/System/Info/Public, accepter si la réponse contient un Id,
|
||||
// et utiliser ServerName comme nom. Simulation : la première adresse « répond ».
|
||||
function _probeCandidates(candidates, index, callback) {
|
||||
if (index >= candidates.length) {
|
||||
callback("Aucun serveur Jellyfin trouvé à cette adresse.");
|
||||
return;
|
||||
}
|
||||
_simulate(function () {
|
||||
callback(null, candidates[index]);
|
||||
});
|
||||
}
|
||||
|
||||
function isValidPort(text) {
|
||||
if (!/^\d+$/.test(text))
|
||||
return false;
|
||||
var value = parseInt(text, 10);
|
||||
return value >= 1 && value <= 65535;
|
||||
}
|
||||
|
||||
// TODO API : GET /Users/Public
|
||||
function publicUsers() {
|
||||
return [
|
||||
@@ -78,15 +132,6 @@ QtObject {
|
||||
_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];
|
||||
}
|
||||
|
||||
+22
-5
@@ -3,6 +3,8 @@ import "../Components"
|
||||
import "../Shared"
|
||||
|
||||
// Écran 2 : saisie manuelle de l'adresse d'un serveur.
|
||||
// Le clavier virtuel de la box n'a ni « : » ni « / » : on saisit l'hôte seul, le port
|
||||
// à part (facultatif), et Session détecte le protocole (https/http) et le port.
|
||||
Page {
|
||||
id: page
|
||||
|
||||
@@ -10,7 +12,7 @@ Page {
|
||||
property string error: ""
|
||||
|
||||
title: "Ajouter un serveur"
|
||||
subtitle: "Saisissez l'adresse de votre serveur Jellyfin, par exemple 192.168.1.20:8096."
|
||||
subtitle: "Saisissez l'adresse IP ou le nom de domaine de votre serveur Jellyfin. Le protocole et le port sont détectés automatiquement."
|
||||
initialFocus: addressField
|
||||
|
||||
function connect() {
|
||||
@@ -18,11 +20,12 @@ Page {
|
||||
return;
|
||||
error = "";
|
||||
busy = true;
|
||||
page.session.connectToServer(addressField.text, function (err) {
|
||||
page.session.connectToServer(addressField.text, portField.text, function (err) {
|
||||
page.busy = false;
|
||||
if (err) {
|
||||
page.error = err;
|
||||
addressField.forceActiveFocus();
|
||||
var port = portField.text.trim();
|
||||
(port !== "" && !page.session.isValidPort(port) ? portField : addressField).forceActiveFocus();
|
||||
return;
|
||||
}
|
||||
// Remplace cet écran : Retour depuis la liste des utilisateurs ramène aux serveurs.
|
||||
@@ -40,7 +43,21 @@ Page {
|
||||
id: addressField
|
||||
width: parent.width
|
||||
label: "Adresse du serveur"
|
||||
placeholder: "http://192.168.1.20:8096"
|
||||
placeholder: "192.168.1.20 ou jellyfin.example.com"
|
||||
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
|
||||
KeyNavigation.down: portField
|
||||
onAccepted: portField.forceActiveFocus()
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: portField
|
||||
width: 200
|
||||
label: "Port (facultatif)"
|
||||
placeholder: "Auto"
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
validator: RegExpValidator { regExp: /\d{0,5}/ }
|
||||
maximumLength: 5
|
||||
KeyNavigation.up: addressField
|
||||
KeyNavigation.down: connectButton
|
||||
onAccepted: page.connect()
|
||||
}
|
||||
@@ -58,7 +75,7 @@ Page {
|
||||
id: connectButton
|
||||
primary: true
|
||||
text: page.busy ? "Connexion…" : "Se connecter"
|
||||
KeyNavigation.up: addressField
|
||||
KeyNavigation.up: portField
|
||||
onClicked: page.connect()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user