Warning, /multimedia/plasmatube/src/ui/LoginPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Window
0007 
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.kirigamiaddons.formcard as FormCard
0010 
0011 import org.kde.plasmatube
0012 import org.kde.plasmatube.private
0013 
0014 FormCard.FormCardPage {
0015     id: root
0016 
0017     required property var source
0018 
0019     readonly property bool isValid: usernameField.text.length !== 0 && passwordField.text.length !== 0
0020 
0021     title: i18n("Sign in")
0022 
0023     data: [
0024         LogInController {
0025             id: logInController
0026 
0027             source: root.source
0028 
0029             onLoggedIn: {
0030                 applicationWindow().showPassiveNotification(i18n("Successfully logged in!"))
0031                 root.Window.window.pageStack.layers.pop()
0032             }
0033 
0034             onErrorOccurred: (errorText) => {
0035                 applicationWindow().showPassiveNotification(errorText)
0036             }
0037         },
0038         QQC2.BusyIndicator {
0039             parent: root
0040             anchors.centerIn: parent
0041             visible: logInController.isLoading
0042         }
0043     ]
0044 
0045     Component.onCompleted: usernameField.clicked()
0046 
0047     FormCard.FormHeader {
0048         title: i18n("Log in")
0049         visible: !logInController.isLoading
0050     }
0051 
0052     FormCard.FormCard {
0053         visible: !logInController.isLoading
0054 
0055         FormCard.FormTextFieldDelegate {
0056             id: usernameField
0057             label: i18n("Username")
0058             inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoPredictiveText
0059             status: Kirigami.MessageType.Error
0060 
0061             onAccepted: passwordField.clicked()
0062         }
0063 
0064         FormCard.FormDelegateSeparator {
0065             above: usernameField
0066             below: passwordField
0067         }
0068 
0069         FormCard.FormTextFieldDelegate {
0070             id: passwordField
0071             label: i18n("Password")
0072             inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoPredictiveText
0073             echoMode: TextInput.Password
0074             status: Kirigami.MessageType.Error
0075 
0076             onAccepted: logInButton.clicked()
0077         }
0078 
0079         FormCard.FormDelegateSeparator {
0080             above: passwordField
0081             below: logInButton
0082         }
0083 
0084         FormCard.FormButtonDelegate {
0085             id: logInButton
0086             text: i18n("Log in")
0087             enabled: root.isValid
0088             onClicked: {
0089                 usernameField.statusMessage = ""
0090                 passwordField.statusMessage = ""
0091 
0092                 if (!usernameField.text) {
0093                     usernameField.statusMessage = i18n("Username must not be empty!")
0094                     return;
0095                 }
0096 
0097                 if (!passwordField.text) {
0098                     passwordField.statusMessage = i18n("Password must not be empty!")
0099                     return;
0100                 }
0101 
0102                 logInController.logIn(usernameField.text, passwordField.text)
0103             }
0104         }
0105     }
0106 }