Files
Jellyfin-Freebox/Views/LoginView.qml
T

167 lines
5.0 KiB
QML

import QtQuick 2.5
import "../Components"
import "../Shared"
// Écran 4 : connexion par mot de passe ou par Quick Connect.
Page {
id: page
property string username: ""
property bool quickConnect: false
property bool quickConnectAvailable: 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 = "";
passwordModeButton.forceActiveFocus();
page.session.startQuickConnect(function (err, code) {
if (err) {
page.error = err;
return;
}
page.quickConnectCode = code;
}, function (err) {
if (err) {
page.error = err;
return;
}
page.navigator.reset("Home");
});
} else {
page.session.stopQuickConnect();
page.initialFocus.forceActiveFocus();
}
}
// Le bouton Quick Connect n'est proposé que si le serveur l'autorise.
Component.onCompleted: {
page.session.isQuickConnectEnabled(function (err, enabled) {
page.quickConnectAvailable = enabled;
});
}
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: page.quickConnectAvailable ? quickConnectButton : null
onClicked: page.signIn()
}
FocusButton {
id: quickConnectButton
visible: page.quickConnectAvailable
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 !== "" ? page.quickConnectCode : "…"
color: Theme.accent
font.pixelSize: Theme.fontCode
font.bold: true
font.letterSpacing: 8
}
Text {
width: parent.width
text: page.error !== "" ? page.error : "En attente d'autorisation…"
color: page.error !== "" ? Theme.error : Theme.textMuted
wrapMode: Text.WordWrap
font.pixelSize: Theme.fontSmall
}
FocusButton {
id: passwordModeButton
text: "Utiliser un mot de passe"
onClicked: page.setQuickConnect(false)
}
}
}