Debian Codegraph @

resources/qml/pages/RegisterPage.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: registrationPage
16 property int maxExpansion: 400
17
18 property string error: regis.error
19
20 Registration {
21 id: regis
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(registrationPage.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(registrationPage.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: hsLabel
58 label: qsTr("Homeserver")
59 placeholderText: qsTr("your.server")
60 onEditingFinished: regis.setServer(text)
61
62 ToolTip.text: qsTr("A server that allows registration. Since matrix is decentralized, you need to first find a server you can register on or host your own.")
63 }
64
65
66 Spinner {
67 Layout.preferredHeight: hsLabel.height/2
68 Layout.alignment: Qt.AlignBottom
69
70 visible: running
71 running: regis.lookingUpHs
72 foreground: palette.mid
73 }
74 }
75
76 MatrixText {
77 Layout.fillWidth: true
78 textFormat: Text.PlainText
79 color: Nheko.theme.error
80 text: regis.hsError
81 visible: text
82 wrapMode: TextEdit.Wrap
83 }
84
85 RowLayout {
86 spacing: Nheko.paddingLarge
87
88 visible: regis.supported
89
90 Layout.fillWidth: true
91 MatrixTextField {
92 id: usernameLabel
93 Layout.fillWidth: true
94 label: qsTr("Username")
95 ToolTip.text: qsTr("The username must not be empty, and must contain only the characters a-z, 0-9, ., _, =, -, and /.")
96 onEditingFinished: regis.checkUsername(text)
97 }
98 Spinner {
99 Layout.preferredHeight: usernameLabel.height/2
100 Layout.alignment: Qt.AlignBottom
101
102 visible: running
103 running: regis.lookingUpUsername
104 foreground: palette.mid
105 }
106
107 Image {
108 Layout.preferredHeight: usernameLabel.height/2
109 Layout.preferredWidth: usernameLabel.height/2
110 Layout.alignment: Qt.AlignBottom
111 source: regis.usernameAvailable ? ("image://colorimage/:/icons/icons/ui/checkmark.svg?green") : ("image://colorimage/:/icons/icons/ui/dismiss.svg?"+Nheko.theme.error)
112 visible: regis.usernameAvailable || regis.usernameUnavailable
113 ToolTip.visible: ma.hovered
114 ToolTip.text: qsTr("Back")
115 sourceSize.height: height
116 sourceSize.width: width
117 HoverHandler {
118 id: ma
119 }
120 }
121 }
122
123 MatrixText {
124 Layout.fillWidth: true
125 textFormat: Text.PlainText
126 color: Nheko.theme.error
127 text: regis.usernameError
128 visible: text && regis.supported
129 wrapMode: TextEdit.Wrap
130 }
131
132
133 MatrixTextField {
134 visible: regis.supported
135 id: passwordLabel
136 Layout.fillWidth: true
137 label: qsTr("Password")
138 echoMode: TextInput.Password
139 ToolTip.text: qsTr("Please choose a secure password. The exact requirements for password strength may depend on your server.")
140 }
141
142 MatrixTextField {
143 visible: regis.supported
144 id: passwordConfirmationLabel
145 Layout.fillWidth: true
146 label: qsTr("Password confirmation")
147 echoMode: TextInput.Password
148 }
149
150 MatrixText {
151 Layout.fillWidth: true
152 visible: regis.supported
153 textFormat: Text.PlainText
154 color: Nheko.theme.error
155 text: passwordLabel.text != passwordConfirmationLabel.text ? qsTr("Your passwords do not match!") : ""
156 wrapMode: TextEdit.Wrap
157 }
158
159 MatrixTextField {
160 visible: regis.supported
161 id: deviceNameLabel
162 Layout.fillWidth: true
163 label: qsTr("Device name")
164 placeholderText: regis.initialDeviceName()
165 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.")
166 }
167
168 Item {
169 Layout.preferredHeight: Nheko.avatarSize
170 Layout.fillWidth: true
171
172 Spinner {
173 height: parent.height
174 anchors.centerIn: parent
175
176 visible: running
177 running: regis.registering
178 foreground: palette.mid
179 }
180 }
181
182 MatrixText {
183 Layout.fillWidth: true
184 textFormat: Text.PlainText
185 color: Nheko.theme.error
186 text: registrationPage.error
187 visible: text
188 wrapMode: TextEdit.Wrap
189 }
190
191 FlatButton {
192 id: regisBtn
193 visible: regis.supported
194 enabled: usernameLabel.text && passwordLabel.text && passwordLabel.text == passwordConfirmationLabel.text
195 Layout.alignment: Qt.AlignHCenter
196 text: qsTr("REGISTER")
197 function register() {
198 regis.startRegistration(usernameLabel.text, passwordLabel.text, deviceNameLabel.text)
199 }
200 onClicked: regisBtn.register()
201 Keys.onEnterPressed: regisBtn.register()
202 Keys.onReturnPressed: regisBtn.register()
203 Keys.enabled: regisBtn.enabled && regis.supported
204 }
205 }
206 }
207
208 ImageButton {
209 anchors.top: parent.top
210 anchors.left: parent.left
211 anchors.margins: Nheko.paddingMedium
212 width: Nheko.avatarSize
213 height: Nheko.avatarSize
214 image: ":/icons/icons/ui/angle-arrow-left.svg"
215 ToolTip.visible: hovered
216 ToolTip.text: qsTr("Back")
217 onClicked: mainWindow.pop()
218 }
219 }
220