-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.qml
243 lines (204 loc) · 6.74 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
import QtQuick 1.0
import "dialog"
import "message"
import "control"
import "auth"
import Kutegram 1.0
Item {
//TODO: remove dynamically unused pages / components from memory
//TODO: keypad navigation
id: root
width: 320
height: 240
property color globalAccent: platformUtils.isWindows() ? platformUtils.windowsRealColorizationColor() : "#54759E"
state: "AUTH"
states: [
State {
name: "AUTH"
PropertyChanges {
target: mainScreen
anchors.leftMargin: -root.width
opacity: 0
}
PropertyChanges {
target: authScreen
anchors.leftMargin: 0
}
},
State {
name: "MAIN"
PropertyChanges {
target: mainScreen
anchors.leftMargin: 0
opacity: 1
}
PropertyChanges {
target: authScreen
anchors.leftMargin: -root.width
}
}
]
transitions: [
Transition {
NumberAnimation {
properties: "anchors.leftMargin,opacity"
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);
authScreen.currentIndex = 1;
helpGetCountriesList();
}
onDisconnected: {
setAuthProgress(false);
if (!hasUserId) {
root.state = "AUTH";
authScreen.currentIndex = 0;
} else {
// TODO: show reconnecting
// TODO: timer!
telegramClient.start();
}
}
onAuthSentCodeResponse: {
setAuthProgress(false);
authScreen.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;
}
authScreen.currentIndex = 2;
}
onAuthAuthorizationResponse: {
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.";
}
onHelpCountriesListResponse: {
//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
}
AuthScreen {
id: authScreen
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width
}
MainScreen {
id: mainScreen
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width
}
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();
}
}
}