Debian Codegraph @

resources/qml/pages/LoginPage.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import QtQuick 2.15
6 import QtQuick.Controls 2.15
7 import QtQuick.Layouts 1.2
8 import QtQuick.Window 2.15
9 import im.nheko 1.0
10 import "../components/"
11 import "../ui/"
12 import "../"
13
14 Item {
15 id: loginPage
16 property int maxExpansion: 400
17
18 property string error: login.error
19
20 Login {
21 id: login
22 }
23
24 ScrollView {
25 id: scroll
26
27 clip: false
28 ScrollBar.horizontal.visible: false
29 anchors.left: parent.left
30 anchors.right: parent.right
31 anchors.verticalCenter: parent.verticalCenter
32 height: Math.min(loginPage.height, col.implicitHeight)
33 anchors.margins: Nheko.paddingLarge
34
35 contentWidth: availableWidth
36
37 ColumnLayout {
38 id: col
39
40 spacing: Nheko.paddingMedium
41
42 anchors.horizontalCenter: parent.horizontalCenter
43 width: Math.min(loginPage.maxExpansion, scroll.width- Nheko.paddingLarge*2)
44
45 Image {
46 Layout.alignment: Qt.AlignHCenter
47 source: "qrc:/logos/login.png"
48 Layout.preferredHeight: 128
49 Layout.preferredWidth: 128
50 }
51
52 RowLayout {
53 spacing: Nheko.paddingLarge
54
55 Layout.fillWidth: true
56 MatrixTextField {
57 id: matrixIdLabel
58 label: qsTr("Matrix ID")
59 placeholderText: qsTr("e.g @user:yourserver.example.com")
60 onEditingFinished: login.mxid = text
61
62 ToolTip.text: qsTr("Your login name. A mxid should start with @ followed by the user ID. After the user ID you need to include your server name after a :.\nYou can also put your homeserver address there if your server doesn't support .well-known lookup.\nExample: @user:yourserver.example.com\nIf Nheko fails to discover your homeserver, it will show you a field to enter the server manually.")
63 Keys.forwardTo: [pwBtn, ssoRepeater]
64 }
65
66
67 Spinner {
68 Layout.preferredHeight: matrixIdLabel.height/2
69 Layout.alignment: Qt.AlignBottom
70
71 visible: running
72 running: login.lookingUpHs
73 foreground: palette.mid
74 }
75 }
76
77 MatrixText {
78 Layout.fillWidth: true
79 textFormat: Text.PlainText
80 color: Nheko.theme.error
81 text: login.mxidError
82 visible: text
83 wrapMode: TextEdit.Wrap
84 }
85 RowLayout {
86
87 MatrixTextField {
88 id: passwordLabel
89 Layout.fillWidth: true
90 label: qsTr("Password")
91 echoMode: TextInput.Password
92 ToolTip.text: qsTr("Your password.")
93 visible: login.passwordSupported
94 Keys.forwardTo: [pwBtn, ssoRepeater]
95 }
96
97 ImageButton {
98 id: showPwButton
99 Layout.preferredWidth: 30
100 Layout.preferredHeight: 30
101 visible: login.passwordSupported
102 Layout.alignment: Qt.AlignBottom
103 image: passwordLabel.echoMode === TextInput.Password ? ":/icons/icons/ui/eye-show.svg" : ":/icons/icons/ui/eye-hide.svg"
104 ToolTip.visible: hovered
105 ToolTip.text: qsTr("Show/Hide Password")
106 onClicked: {
107 if (passwordLabel.echoMode === TextInput.Normal) {
108 passwordLabel.echoMode = TextInput.Password
109 }
110 else {
111 passwordLabel.echoMode = TextInput.Normal
112 }
113 }
114 }
115 }
116
117 MatrixTextField {
118 id: deviceNameLabel
119 Layout.fillWidth: true
120 label: qsTr("Device name")
121 placeholderText: login.initialDeviceName()
122 ToolTip.text: qsTr("A name for this device which will be shown to others when verifying your devices. If nothing is provided, a default is used.")
123 Keys.forwardTo: [pwBtn, ssoRepeater]
124 }
125
126 MatrixTextField {
127 id: hsLabel
128 enabled: visible
129 visible: login.homeserverNeeded
130
131 Layout.fillWidth: true
132 label: qsTr("Homeserver address")
133 placeholderText: qsTr("yourserver.example.com:8787")
134 text: login.homeserver
135 onEditingFinished: login.homeserver = text
136 ToolTip.text: qsTr("The address that can be used to contact your homeserver's client API.\nExample: https://yourserver.example.com:8787")
137 Keys.forwardTo: [pwBtn, ssoRepeater]
138 }
139
140 Item {
141 Layout.preferredHeight: Nheko.avatarSize
142 Layout.fillWidth: true
143
144 Spinner {
145 height: parent.height
146 anchors.centerIn: parent
147
148 visible: running
149 running: login.loggingIn
150 foreground: palette.mid
151 }
152 }
153
154 MatrixText {
155 Layout.fillWidth: true
156 textFormat: Text.PlainText
157 color: Nheko.theme.error
158 text: loginPage.error
159 visible: text
160 wrapMode: TextEdit.Wrap
161 }
162
163 FlatButton {
164 id: pwBtn
165 visible: login.passwordSupported
166 enabled: login.homeserverValid && matrixIdLabel.text == login.mxid && login.homeserver == hsLabel.text
167 Layout.alignment: Qt.AlignHCenter
168 text: qsTr("LOGIN")
169 function pwLogin() {
170 login.onLoginButtonClicked(Login.Password, matrixIdLabel.text, passwordLabel.text, deviceNameLabel.text)
171 }
172 onClicked: pwBtn.pwLogin()
173 Keys.onEnterPressed: pwBtn.pwLogin()
174 Keys.onReturnPressed: pwBtn.pwLogin()
175 Keys.enabled: pwBtn.enabled && login.passwordSupported
176 }
177
178 Repeater {
179 id: ssoRepeater
180
181 model: login.identityProviders
182
183 delegate: FlatButton {
184 id: ssoBtn
185 visible: login.ssoSupported
186 enabled: login.homeserverValid && matrixIdLabel.text == login.mxid && login.homeserver == hsLabel.text
187 Layout.alignment: Qt.AlignHCenter
188 text: modelData.name
189 iconImage: modelData.avatarUrl.replace("mxc://", "image://MxcImage/")
190 function ssoLogin() {
191 login.onLoginButtonClicked(Login.SSO, matrixIdLabel.text, modelData.id, deviceNameLabel.text)
192 }
193 onClicked: ssoBtn.ssoLogin()
194 Keys.onEnterPressed: ssoBtn.ssoLogin()
195 Keys.onReturnPressed: ssoBtn.ssoLogin()
196 Keys.enabled: ssoBtn.enabled && !login.passwordSupported
197 }
198 }
199 }
200 }
201
202 ImageButton {
203 anchors.top: parent.top
204 anchors.left: parent.left
205 anchors.margins: Nheko.paddingMedium
206 width: Nheko.avatarSize
207 height: Nheko.avatarSize
208 image: ":/icons/icons/ui/angle-arrow-left.svg"
209 ToolTip.visible: hovered
210 ToolTip.text: qsTr("Back")
211 onClicked: mainWindow.pop()
212 }
213 }