-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.qml
383 lines (328 loc) · 10.3 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
import QtQuick 1.0
import "dialog"
import "message"
import "control"
import "auth"
import Kutegram 1.0
Rectangle {
//TODO: UI scaling - 1.5x for Nokia N8
//TODO: remove dynamically unused pages / components from memory
//TODO: keypad navigation
id: root
width: 320
height: 240
state: "AUTH"
states: [
State {
name: "AUTH"
PropertyChanges {
target: mainRect
anchors.leftMargin: root.width
opacity: 0
}
},
State {
name: "MAIN"
PropertyChanges {
target: mainRect
anchors.leftMargin: 0
opacity: 1
}
}
]
onStateChanged: {
if (state == "MAIN") {
mainRect.forceActiveFocus();
} else {
authRect.forceActiveFocus();
}
}
transitions: [
Transition {
NumberAnimation {
properties: "opacity,anchors.leftMargin"
easing.type: Easing.InOutQuad
duration: 200
}
}
]
property int currentFolderIndex: 0
property bool authProgress: false
function setAuthProgress(visible) {
authProgress = visible;
}
Component.onCompleted: {
if (telegramClient.hasSession()) {
setAuthProgress(true);
telegramClient.start();
}
}
TgClient {
id: telegramClient
onInitialized: {
if (hasUserId) {
return;
}
setAuthProgress(false);
authStack.currentIndex = 1;
helpGetCountriesList();
}
onDisconnected: {
setAuthProgress(false);
if (!hasUserId) {
root.state = "AUTH";
authStack.currentIndex = 0;
} else {
// TODO: show reconnecting
telegramClient.start();
}
}
onAuthSendCodeResponse: {
setAuthProgress(false);
phonePage.phoneCodeHash = data["phone_code_hash"];
switch (data["type"]["_"]) {
//TODO messages
// case TLType::AuthSentCodeTypeApp:
// codeNumberDescriptionLabel->setText("A code was sent via Telegram to your other\ndevices, if you have any connected.");
// break;
// case TLType::AuthSentCodeTypeSms:
// codeNumberDescriptionLabel->setText("We've sent an activation code to your phone.\nPlease enter it below.");
// break;
// case TLType::AuthSentCodeTypeCall:
// break;
// case TLType::AuthSentCodeTypeFlashCall:
// break;
// case TLType::AuthSentCodeTypeMissedCall:
// break;
// case TLType::AuthSentCodeTypeEmailCode:
// break;
// case TLType::AuthSentCodeTypeSetUpEmailRequired:
// //TODO: show error or implement it lol
// break;
// case TLType::AuthSentCodeTypeFragmentSms:
// break;
// case TLType::AuthSentCodeTypeFirebaseSms:
// break;
}
authStack.currentIndex = 2;
}
onAuthSignInResponse: {
setAuthProgress(false);
if (data["_"] == 0x44747e9a) {
//TODO sign up / registration support
snackBar.text = "Sign up isn't supported now. Please, use official app for signing up.";
}
}
onAuthorized: {
setAuthProgress(false);
//TODO hide reconnecting
root.state = "MAIN";
}
onRpcError: {
setAuthProgress(false);
//TODO think how to improve it
if (errorMessage == "PHONE_NUMBER_INVALID") {
snackBar.text = "Invalid phone number. Please try again.";
}
else if (errorMessage == "PHONE_NUMBER_FLOOD") {
snackBar.text = "Phone is used too many times recently.";
}
else if (errorMessage == "PHONE_CODE_INVALID") {
snackBar.text = "You have entered an invalid code.";
}
else {
snackBar.text = "RPC error occured: " + errorMessage + " (" + errorCode + ")"
}
}
onSocketError: {
if (state == "AUTH") {
setAuthProgress(false);
snackBar.text = "Socket error occured: " + errorMessage + " (" + errorCode + ")"
} else {
snackBar.text = "Reconnecting...";
}
}
onTfaRequired: {
setAuthProgress(false);
//TODO 2fa support
snackBar.text = "2FA isn't supported now. You can disable 2FA, log in and enable it afterwards.";
}
onHelpGetCountriesListResponse: {
//TODO country selector
}
//Debug only
// onFileDownloadCanceled: {
// console.log("[INFO] File " + fileId + " download canceled");
// }
// onFileDownloaded: {
// console.log("[INFO] File " + fileId + " have been downloaded");
// }
// onFileDownloading: {
// console.log("[INFO] File " + fileId + " download progress: " + processedLength + " / " + totalLength + " " + progressPercentage + " %");
// }
// onFileUploadCanceled: {
// console.log("[INFO] File " + fileId + " upload canceled");
// }
// onFileUploaded: {
// console.log("[INFO] File " + fileId + " have been uploaded");
// }
// onFileUploading: {
// console.log("[INFO] File " + fileId + " upload progress: " + processedLength + " / " + totalLength + " " + progressPercentage + " %");
// }
}
AvatarDownloader {
id: globalAvatarDownloader
client: telegramClient
}
//TODO: remove stack and rewrite with states
Rectangle {
id: authRect
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width
focus: true
Stack {
flickableDirection: Flickable.VerticalFlick
id: authStack
anchors.fill: parent
IntroPage {
width: authStack.width
height: authStack.height
}
PhonePage {
id: phonePage
width: authStack.width
height: authStack.height
}
CodePage {
id: codePage
width: authStack.width
height: authStack.height
}
}
Item {
anchors.top: parent.top
anchors.left: parent.left
height: 40
width: 40
state: authStack.currentIndex == 0 ? "NO_BACK" : "BACK"
id: authBackRect
states: [
State {
name: "NO_BACK"
PropertyChanges {
target: authBackImage
opacity: 0
rotation: 180
}
},
State {
name: "BACK"
PropertyChanges {
target: authBackImage
opacity: 1
rotation: 0
}
}
]
transitions: [
Transition {
NumberAnimation {
properties: "opacity,rotation"
easing.type: Easing.InOutQuad
duration: 200
}
}
]
Image {
id: authBackImage
anchors.centerIn: parent
source: "../img/arrow-left_black.png"
width: 20
height: 20
smooth: true
asynchronous: true
}
MouseArea {
anchors.fill: parent
onClicked: {
setAuthProgress(false);
authStack.currentIndex = Math.max(0, authStack.currentIndex - 1)
}
}
}
Item {
anchors.top: parent.top
anchors.right: parent.right
width: settingsText.width + 20
height: 40
visible: false
Text {
id: settingsText
anchors.centerIn: parent
font.bold: true
text: "SETTINGS"
}
}
Spinner {
id: authSpinner
visible: root.authProgress
anchors.top: parent.top
anchors.right: parent.right
}
}
Rectangle {
id: mainRect
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width
focus: true
Stack {
id: stack
anchors.top: topBar.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
onCurrentItemChanged: {
topBar.currentState = currentIndex == 1 ? "CHAT" : "MENU";
messagePage.globalState = "NO_SELECT";
}
DialogPage {
id: dialogPage
width: stack.width
height: stack.height
}
MessagePage {
id: messagePage
width: stack.width
height: stack.height
}
}
Drawer {
id: drawer
anchors.top: topBar.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
}
TopBar {
id: topBar
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
}
}
SnackBar {
id: snackBar
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
}
Keys.onPressed: {
if (event.key == Qt.Key_Context1 || event.key == Qt.Key_Escape) {
topBar.menuButtonClicked();
}
}
}