blob: c1caca169ce69473455aec6bf26ca57a1356cc57 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
2 * Copyright (C) 2020 by Savoir-faire Linux
3 * Author: Yang Wang <yang.wang@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.15
20import QtQuick.Controls 2.14
21import QtQuick.Layouts 1.14
22import QtQuick.Controls.Styles 1.4
23import net.jami.Models 1.0
24
25import "../../commoncomponents"
26
27Dialog {
28 id: linkDeviceDialog
29
30 function openLinkDeviceDialog(){
31 infoLabel.text = qsTr("This pin and the account password should be entered in your device within 10 minutes.")
32 passwordEdit.clear()
33 linkDeviceDialog.open()
34 if(ClientWrapper.accountAdaptor.hasPassword()){
35 stackedWidget.currentIndex = 0
36 } else {
37 setGeneratingPage()
38 }
39 }
40
41 function setGeneratingPage(){
42 if(passwordEdit.length === 0 && ClientWrapper.accountAdaptor.hasPassword()){
43 setExportPage(NameDirectory.ExportOnRingStatus.WRONG_PASSWORD, "")
44 return
45 }
46
47 stackedWidget.currentIndex = 1
48 spinnerMovie.playing = true
49
50 timerForExport.restart()
51 }
52
53 function slotExportOnRing(){
54 ClientWrapper.accountModel.exportOnRing(ClientWrapper.utilsAdaptor.getCurrAccId(),passwordEdit.text)
55 }
56
57 Timer{
58 id: timerForExport
59
60 repeat: false
61 interval: 200
62
63 onTriggered: {
64 timeOut.restart()
65 slotExportOnRing()
66 }
67 }
68
69 Timer{
70 id: timeOut
71
72 repeat: false
73 interval: exportTimeout
74
75 onTriggered: {
76 setExportPage(NameDirectory.ExportOnRingStatus.NETWORK_ERROR, "")
77 }
78 }
79
80 function setExportPage(status, pin){
81 timeOut.stop()
82
83 if(status === NameDirectory.ExportOnRingStatus.SUCCESS){
84 infoLabel.isSucessState = true
85 yourPinLabel.visible = true
86 exportedPIN.visible = true
87 infoLabel.text = qsTr("This pin and the account password should be entered in your device within 10 minutes.")
88 exportedPIN.text = pin
89 } else {
90 infoLabel.isSucessState = false
91 yourPinLabel.visible = false
92 exportedPIN.visible = false
93
94 switch(status){
95 case NameDirectory.ExportOnRingStatus.WRONG_PASSWORD:
96 infoLabel.text = qsTr("Incorrect password")
97
98 break
99 case NameDirectory.ExportOnRingStatus.NETWORK_ERROR:
100 infoLabel.text = qsTr("Error connecting to the network.\nPlease try again later.")
101
102 break
103 case NameDirectory.ExportOnRingStatus.INVALID:
104 infoLabel.text = qsTr("Something went wrong.\n")
105
106 break
107 }
108 }
109 stackedWidget.currentIndex = 2
110 }
111
112 property int exportTimeout : 20000
113
114 Connections{
115 target: ClientWrapper.nameDirectory
116
117 function onExportOnRingEnded(status, pin){
118 setExportPage(status, pin)
119 }
120 }
121
122 visible: false
123
124 anchors.centerIn: parent.Center
125 x: (parent.width - width) / 2
126 y: (parent.height - height) / 2
127
128 title: qsTr("Link another device")
129
130 onClosed: {
131 if(infoLabel.isSucessState){
132 accept()
133 } else {
134 reject()
135 }
136 }
137
138 contentItem: Rectangle{
139 implicitWidth: 365
140 implicitHeight: 208
141
142 StackLayout{
143 id: stackedWidget
144 anchors.fill: parent
145
146 currentIndex: 2
147
148 Rectangle{
149 id: passwordConfirmPage
150
151 Layout.fillWidth: true
152 Layout.fillHeight: true
153
154 Layout.leftMargin: 11
155 Layout.rightMargin: 11
156 Layout.topMargin: 11
157 Layout.bottomMargin: 11
158
159 ColumnLayout{
160 anchors.fill: parent
161 spacing: 7
162
163 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
164
165 Item{
166 Layout.alignment: Qt.AlignHCenter
167
168 Layout.fillHeight: true
169 Layout.maximumHeight: 20
170 Layout.preferredHeight: 20
171 Layout.minimumHeight: 20
172 }
173
174 Label{
175 Layout.preferredWidth: 219
176 Layout.alignment: Qt.AlignHCenter
177 wrapMode: Text.Wrap
178 text: qsTr("Enter your account password")
179 font.pointSize: 8
180 font.kerning: true
181 horizontalAlignment: Text.AlignHCenter
182 verticalAlignment: Text.AlignVCenter
183 }
184
185 Item{
186 Layout.alignment: Qt.AlignHCenter
187
188 Layout.fillHeight: true
189
190 Layout.maximumHeight: 20
191 Layout.preferredHeight: 20
192 Layout.minimumHeight: 20
193 }
194
195 InfoLineEdit{
196 id: passwordEdit
197
198 Layout.alignment: Qt.AlignHCenter
199
200 Layout.minimumWidth: 294
201 Layout.preferredWidth: 294
202
203 Layout.preferredHeight: 30
204 Layout.minimumHeight: 30
205
206 echoMode: TextInput.Password
207
208 placeholderText: qsTr("Password")
209 }
210
211 Item{
212 Layout.alignment: Qt.AlignHCenter
213
214 Layout.fillHeight: true
215
216 Layout.maximumHeight: 20
217 Layout.preferredHeight: 20
218 Layout.minimumHeight: 20
219 }
220
221 RowLayout{
222 spacing: 7
223
224 Layout.alignment: Qt.AlignHCenter
225 Layout.fillWidth: true
226
227 Item{
228 Layout.fillWidth: true
229
230 Layout.maximumHeight: 20
231 Layout.preferredHeight: 20
232 Layout.minimumHeight: 20
233 }
234
235 HoverableRadiusButton{
236 id: btnPasswordOk
237
238 Layout.maximumWidth: 130
239 Layout.preferredWidth: 130
240 Layout.minimumWidth: 130
241
242 Layout.maximumHeight: 30
243 Layout.preferredHeight: 30
244 Layout.minimumHeight: 30
245
246 radius: height /2
247
248 text: qsTr("Register")
249 font.pointSize: 10
250 font.kerning: true
251
252 onClicked: {
253 setGeneratingPage()
254 }
255 }
256
257 Item{
258 Layout.fillWidth: true
259 Layout.minimumWidth: 40
260
261 Layout.maximumHeight: 20
262 Layout.preferredHeight: 20
263 Layout.minimumHeight: 20
264 }
265
266 HoverableButtonTextItem {
267 id: btnCancel
268
269 Layout.maximumWidth: 130
270 Layout.preferredWidth: 130
271 Layout.minimumWidth: 130
272
273 Layout.maximumHeight: 30
274 Layout.preferredHeight: 30
275 Layout.minimumHeight: 30
276
277 backgroundColor: "red"
278 onEnterColor: Qt.rgba(150 / 256, 0, 0, 0.7)
279 onDisabledBackgroundColor: Qt.rgba(
280 255 / 256,
281 0, 0, 0.8)
282 onPressColor: backgroundColor
283 textColor: "white"
284
285 radius: height /2
286
287 text: qsTr("Cancel")
288 font.pointSize: 10
289 font.kerning: true
290
291 onClicked: {
292 reject()
293 }
294 }
295
296 Item{
297 Layout.fillWidth: true
298 Layout.minimumWidth: 40
299
300 Layout.maximumHeight: 20
301 Layout.preferredHeight: 20
302 Layout.minimumHeight: 20
303 }
304 }
305
306 Item{
307 Layout.alignment: Qt.AlignHCenter
308
309 Layout.fillHeight: true
310
311 Layout.maximumHeight: 20
312 Layout.preferredHeight: 20
313 Layout.minimumHeight: 20
314 }
315 }
316 }
317
318 Rectangle{
319 id: exportingPage
320
321 Layout.fillWidth: true
322 Layout.fillHeight: true
323
324 Layout.leftMargin: 11
325 Layout.rightMargin: 11
326 Layout.topMargin: 11
327 Layout.bottomMargin: 11
328
329 ColumnLayout{
330 anchors.fill: parent
331 spacing: 7
332
333 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
334
335 Item{
336 Layout.alignment: Qt.AlignHCenter
337
338 Layout.fillHeight: true
339 Layout.minimumHeight: 40
340
341 Layout.maximumWidth: 20
342 Layout.preferredWidth: 20
343 Layout.minimumWidth: 20
344 }
345
346 RowLayout{
347 Layout.fillWidth: true
348 spacing: 0
349
350 Layout.maximumHeight: 30
351
352 Item{
353 Layout.fillWidth: true
354
355 Layout.maximumHeight: 20
356 Layout.preferredHeight: 20
357 Layout.minimumHeight: 20
358 }
359
360 Label{
361 Layout.alignment: Qt.AlignHCenter
362
363 Layout.maximumWidth: 0
364 Layout.preferredWidth: 341
365
366 Layout.minimumHeight: 0
367 Layout.preferredHeight: 30
368 Layout.maximumHeight: 30
369
370 wrapMode: Text.Wrap
371 text: qsTr("Exporting Account")
372 font.pointSize: 8
373 font.kerning: true
374 horizontalAlignment: Text.AlignHCenter
375 verticalAlignment: Text.AlignVCenter
376 }
377
378 Item{
379 Layout.fillWidth: true
380
381 Layout.maximumHeight: 20
382 Layout.preferredHeight: 20
383 Layout.minimumHeight: 20
384 }
385 }
386
387 Item{
388 Layout.alignment: Qt.AlignHCenter
389
390 Layout.fillHeight: true
391
392 Layout.maximumWidth: 20
393 Layout.preferredWidth: 20
394 Layout.minimumWidth: 20
395 }
396
397 RowLayout{
398 spacing: 7
399
400 Item{
401 Layout.fillWidth: true
402
403 Layout.maximumHeight: 20
404 Layout.preferredHeight: 20
405 Layout.minimumHeight: 20
406 }
407
408 Label{
409 id: exportingSpinner
410
411 Layout.alignment: Qt.AlignHCenter
412
413 Layout.maximumWidth: 96
414 Layout.preferredWidth: 96
415 Layout.minimumWidth: 96
416
417 Layout.maximumHeight: 96
418 Layout.preferredHeight: 96
419 Layout.minimumHeight: 96
420
421 background: Rectangle {
422 anchors.fill: parent
423 AnimatedImage {
424 id: spinnerMovie
425
426 anchors.fill: parent
427
428 source: "qrc:/images/jami_eclipse_spinner.gif"
429
430 playing: exportingSpinner.visible
431 paused: false
432 fillMode: Image.PreserveAspectFit
433 mipmap: true
434 }
435 }
436 }
437
438 Item{
439 Layout.fillWidth: true
440
441 Layout.maximumHeight: 20
442 Layout.preferredHeight: 20
443 Layout.minimumHeight: 20
444 }
445
446 }
447
448 Item{
449 Layout.alignment: Qt.AlignHCenter
450
451 Layout.fillHeight: true
452 Layout.minimumHeight: 40
453
454 Layout.maximumWidth: 20
455 Layout.preferredWidth: 20
456 Layout.minimumWidth: 20
457 }
458 }
459 }
460
461 Rectangle{
462 id: exportedPage
463
464 Layout.fillWidth: true
465 Layout.fillHeight: true
466
467 Layout.leftMargin: 11
468 Layout.rightMargin: 11
469 Layout.topMargin: 11
470 Layout.bottomMargin: 11
471
472 ColumnLayout{
473 anchors.fill: parent
474 spacing: 7
475
476 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
477
478 Item{
479 Layout.fillHeight: true
480
481 Layout.maximumWidth: 20
482 Layout.preferredWidth: 20
483 Layout.minimumWidth: 20
484 }
485
486 RowLayout{
487 spacing: 7
488
489 Layout.alignment: Qt.AlignHCenter
490 Layout.fillWidth: true
491
492 Item{
493 Layout.fillWidth: true
494
495 Layout.maximumHeight: 20
496 Layout.preferredHeight: 20
497 Layout.minimumHeight: 20
498 }
499
500 Label{
501 id: yourPinLabel
502
503 Layout.alignment: Qt.AlignHCenter
504
505 Layout.preferredHeight: 25
506
507 wrapMode: Text.Wrap
508 text: "Your PIN is:"
509 font.pointSize: 8
510 font.kerning: true
511 horizontalAlignment: Text.AlignHCenter
512 verticalAlignment: Text.AlignVCenter
513 }
514
515 Item{
516 Layout.alignment: Qt.AlignHCenter
517
518 Layout.maximumWidth: 20
519 Layout.preferredWidth: 20
520 Layout.minimumWidth: 20
521
522 Layout.maximumHeight: 20
523 Layout.preferredHeight: 20
524 Layout.minimumHeight: 20
525 }
526
527 Label{
528 id: exportedPIN
529
530 Layout.alignment: Qt.AlignHCenter
531
532 Layout.preferredHeight: 25
533
534 wrapMode: Text.Wrap
535 text: "PIN"
536 font.pointSize: 12
537 font.kerning: true
538 horizontalAlignment: Text.AlignHCenter
539 verticalAlignment: Text.AlignVCenter
540 }
541
542 Item{
543 Layout.fillWidth: true
544
545 Layout.maximumHeight: 20
546 Layout.preferredHeight: 20
547 Layout.minimumHeight: 20
548 }
549 }
550
551 RowLayout{
552 spacing: 7
553
554 Layout.alignment: Qt.AlignHCenter
555 Layout.fillWidth: true
556
557 Item{
558 Layout.fillWidth: true
559
560 Layout.maximumHeight: 20
561 Layout.preferredHeight: 20
562 Layout.minimumHeight: 20
563 }
564
565 Label{
566 id: infoLabel
567
568 property bool isSucessState: false
569 property int borderWidth : isSucessState? 1 : 0
570 property int borderRadius : isSucessState? 15 : 0
571 property string backgroundColor : isSucessState? "whitesmoke" : "transparent"
572 property string borderColor : isSucessState? "lightgray" : "transparent"
573 color: isSucessState ? "#2b5084" : "black"
574 padding: isSucessState ? 8 : 0
575
576 Layout.alignment: Qt.AlignHCenter
577 Layout.preferredWidth: 320
578 Layout.preferredHeight: 50
579
580 wrapMode: Text.Wrap
581 text: qsTr("This pin and the account password should be entered in your device within 10 minutes.")
582 font.pointSize: 8
583 font.kerning: true
584
585 horizontalAlignment: Text.AlignHCenter
586 verticalAlignment: Text.AlignVCenter
587
588 background: Rectangle{
589 id: infoLabelBackground
590
591 anchors.fill: parent
592 border.width: infoLabel.borderWidth
593 border.color: infoLabel.borderColor
594 radius: infoLabel.borderRadius
595 color: infoLabel.backgroundColor
596 }
597 }
598
599 Item{
600 Layout.fillWidth: true
601
602 Layout.maximumHeight: 20
603 Layout.preferredHeight: 20
604 Layout.minimumHeight: 20
605 }
606 }
607
608 Item{
609 Layout.fillHeight: true
610
611 Layout.maximumWidth: 20
612 Layout.preferredWidth: 20
613 Layout.minimumWidth: 20
614 }
615
616 RowLayout{
617 spacing: 7
618
619 Layout.alignment: Qt.AlignHCenter
620 Layout.fillWidth: true
621
622 Item{
623 Layout.fillWidth: true
624
625 Layout.maximumHeight: 20
626 Layout.preferredHeight: 20
627 Layout.minimumHeight: 20
628 }
629
630 HoverableRadiusButton{
631 id: btnCloseExportDialog
632
633 Layout.alignment: Qt.AlignHCenter
634
635 Layout.maximumWidth: 130
636 Layout.preferredWidth: 130
637 Layout.minimumWidth: 130
638
639 Layout.maximumHeight: 30
640 Layout.preferredHeight: 30
641 Layout.minimumHeight: 30
642
643 radius: height /2
644
645 text: qsTr("Close")
646 font.pointSize: 10
647 font.kerning: true
648
649 onClicked: {
650 if(infoLabel.isSucessState){
651 accept()
652 } else {
653 reject()
654 }
655 }
656 }
657
658 Item{
659 Layout.fillWidth: true
660
661 Layout.maximumHeight: 20
662 Layout.preferredHeight: 20
663 Layout.minimumHeight: 20
664 }
665 }
666
667 Item{
668 Layout.fillHeight: true
669
670 Layout.maximumWidth: 20
671 Layout.preferredWidth: 20
672 Layout.minimumWidth: 20
673 }
674 }
675 }
676 }
677 }
678}