newwizardwidget.cpp 25 KB
Newer Older
Andreas Traczyk's avatar
Andreas Traczyk committed
1
2
3
/**************************************************************************
* Copyright (C) 2015-2018 by Savoir-faire Linux                           *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
4
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>          *
Andreas Traczyk's avatar
Andreas Traczyk committed
5
* Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>          *
Andreas Traczyk's avatar
Andreas Traczyk committed
6
7
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>          *
* Author: Mingrui Zhang   <mingrui.zhang@savoirfairelinux.com>            *
Andreas Traczyk's avatar
Andreas Traczyk committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
*                                                                         *
* This program is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU General Public License as published by    *
* the Free Software Foundation; either version 3 of the License, or       *
* (at your option) any later version.                                     *
*                                                                         *
* This program is distributed in the hope that it will be useful,         *
* but WITHOUT ANY WARRANTY; without even the implied warranty of          *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
* GNU General Public License for more details.                            *
*                                                                         *
* You should have received a copy of the GNU General Public License       *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
**************************************************************************/

#include "newwizardwidget.h"
#include "ui_newwizardwidget.h"

#include <QMovie>
#include <QMessageBox>
#include <QFileDialog>
#include <QBitmap>
Andreas Traczyk's avatar
Andreas Traczyk committed
30
#include <QtConcurrent/QtConcurrent>
Andreas Traczyk's avatar
Andreas Traczyk committed
31
32
33
34
35
36

#include "namedirectory.h"

#include "utils.h"
#include "ringthemeutils.h"

37
38
39
#undef REGISTERED
#include "../daemon/src/dring/account_const.h"

40
NewWizardWidget::NewWizardWidget(QWidget* parent) :
Andreas Traczyk's avatar
Andreas Traczyk committed
41
42
    NavWidget(parent),
    ui(new Ui::NewWizardWidget),
43
    wizardMode_(WizardMode::CREATE),
Andreas Traczyk's avatar
Andreas Traczyk committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    lookupTimer_(this)
{
    ui->setupUi(this);

    QPixmap logo(":/images/logo-jami-standard-coul.png");

    ui->welcomeLogo->setPixmap(logo.scaledToHeight(100, Qt::SmoothTransformation));
    ui->welcomeLogo->setAlignment(Qt::AlignHCenter);

    creationSpinnerMovie_ = new QMovie(":/images/jami_eclipse_spinner.gif");
    ui->spinnerLabel->setMovie(creationSpinnerMovie_);
    creationSpinnerMovie_->start();

    lookupSpinnerMovie_ = new QMovie(":/images/jami_rolling_spinner.gif");
    lookupSpinnerMovie_->setScaledSize(QSize(30, 30));

Andreas Traczyk's avatar
Andreas Traczyk committed
60
61
    ui->lookupStatusLabel->setMovie(lookupSpinnerMovie_);
    ui->lookupStatusLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
62
63
64
65
66
67
68

    registrationStateOk_ = false;

    statusSuccessPixmap_ = Utils::generateTintedPixmap(":/images/icons/baseline-done-24px.svg", RingTheme::presenceGreen_);
    statusInvalidPixmap_ = Utils::generateTintedPixmap(":/images/icons/baseline-error_outline-24px.svg", RingTheme::urgentOrange_);
    statusErrorPixmap_ = Utils::generateTintedPixmap(":/images/icons/baseline-close-24px.svg", RingTheme::red_);

69
    setNavBarVisibility(false, true);
Andreas Traczyk's avatar
Andreas Traczyk committed
70
71
72

    lookupTimer_.setSingleShot(true);

73
74
75
76
77
    collapsiblePasswordWidget_ = new CollapsiblePasswordWidget(this);
    collapsiblePasswordWidget_->setParent(ui->expandablePasswordWidget);
    ui->expandablePasswordWidget->setLabelText("Choose a password for enchanced security");
    ui->expandablePasswordWidget->addExpandWidget(collapsiblePasswordWidget_);

78
79
80
81
82
83
    connect(ui->fileImportBtn, &QPushButton::clicked,
        [this] {
            QString filePath;
            filePath = QFileDialog::getOpenFileName(this,
                tr("Open File"),
                QString(),
84
                tr("Jami archive files") + " (*.gz);" + tr("All files") + " (*)");
85
86
87
88
89
            fileToImport_ = QDir::toNativeSeparators(filePath);
            if (!fileToImport_.isEmpty()) {
                QFileInfo fi(filePath);
                ui->fileImportBtn->setText(fi.fileName());
            } else {
90
                ui->fileImportBtn->setText(tr("Archive (None)"));
91
92
93
94
            }
            validateWizardProgression();
        });

Andreas Traczyk's avatar
Andreas Traczyk committed
95
96
97
98
99
100
101
102
    connect(&lookupTimer_, &QTimer::timeout,
            this, &NewWizardWidget::timeoutNameLookupTimer);

    connect(ui->backButton, &QPushButton::clicked,
        [this] {
            emit NavigationRequested(ScreenEnum::CallScreen);
        });

103
104
105
106
107
    connect(collapsiblePasswordWidget_->getPasswordEdit(), &QLineEdit::textChanged,
        [this] {
            validateWizardProgression();
        });

108
    connect(collapsiblePasswordWidget_->getConfirmPasswordEdit(), &QLineEdit::textChanged,
Andreas Traczyk's avatar
Andreas Traczyk committed
109
110
111
112
        [this] {
            validateWizardProgression();
        });

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    connect(ui->pinFromDevice, &QLineEdit::textChanged,
        [this] {
            validateWizardProgression();
        });

    connect(ui->usernameManagerEdit, &QLineEdit::textChanged,
        [this] {
            validateWizardProgression();
        });

    connect(ui->accountManagerEdit, &QLineEdit::textChanged,
        [this] {
            validateWizardProgression();
        });

    connect(ui->passwordManagerEdit, &QLineEdit::textChanged,
129
130
131
132
        [this] {
            validateWizardProgression();
        });

Andreas Traczyk's avatar
Andreas Traczyk committed
133
134
135
136
137
138
139
140
141
142
143
144
145
    ui->containerWidget->setVisible(false);
}

NewWizardWidget::~NewWizardWidget()
{
    delete ui;
}

void
NewWizardWidget::updateNameRegistrationUi(NameRegistrationUIState state)
{
    switch (state) {
    case NameRegistrationUIState::BLANK:
Andreas Traczyk's avatar
Andreas Traczyk committed
146
        ui->lookupStatusLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
147
148
        break;
    case NameRegistrationUIState::INVALID:
Andreas Traczyk's avatar
Andreas Traczyk committed
149
        ui->lookupStatusLabel->setPixmap(statusInvalidPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
150
151
        break;
    case NameRegistrationUIState::TAKEN:
Andreas Traczyk's avatar
Andreas Traczyk committed
152
        ui->lookupStatusLabel->setPixmap(statusErrorPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
153
154
        break;
    case NameRegistrationUIState::FREE:
Andreas Traczyk's avatar
Andreas Traczyk committed
155
        ui->lookupStatusLabel->setPixmap(statusSuccessPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
156
157
        break;
    case NameRegistrationUIState::SEARCHING:
Andreas Traczyk's avatar
Andreas Traczyk committed
158
        ui->lookupStatusLabel->setMovie(lookupSpinnerMovie_);
Andreas Traczyk's avatar
Andreas Traczyk committed
159
160
        lookupSpinnerMovie_->stop();
        lookupSpinnerMovie_->start();
Andreas Traczyk's avatar
Andreas Traczyk committed
161
        ui->lookupStatusLabel->show();
Andreas Traczyk's avatar
Andreas Traczyk committed
162
163
164
165
166
167
168
169
170
171
172
173
        break;
    }
}

void
NewWizardWidget::navigated(bool to)
{
    ui->containerWidget->setVisible(to);
    changePage(ui->welcomePage);
    Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
}

174
void
175
NewWizardWidget::slotAccountListChanged()
176
177
{}

Andreas Traczyk's avatar
Andreas Traczyk committed
178
void
179
NewWizardWidget::on_fromDeviceButton_clicked()
Andreas Traczyk's avatar
Andreas Traczyk committed
180
{
181
    changePage(ui->importFromDevicePage);
Andreas Traczyk's avatar
Andreas Traczyk committed
182
183
184
185
186
}

void
NewWizardWidget::on_newAccountButton_clicked()
{
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
    changePage(ui->createAccountPage);
}

void
NewWizardWidget::on_showAdvancedButton_clicked()
{
    ui->newSIPAccountButton->setVisible(!ui->newSIPAccountButton->isVisible());
    ui->connectAccountManagerButton->setVisible(!ui->connectAccountManagerButton->isVisible());
}

void
NewWizardWidget::on_connectAccountManagerButton_clicked()
{
    changePage(ui->connectToAccountManagerPage);
}

void
NewWizardWidget::on_fromBackupButton_clicked()
{
    changePage(ui->importFromBackupPage);
Andreas Traczyk's avatar
Andreas Traczyk committed
207
208
}

209
210
211
void
NewWizardWidget::on_newSIPAccountButton_clicked()
{
212
    changePage(ui->createSIPAccountPage);
213
214
}

Andreas Traczyk's avatar
Andreas Traczyk committed
215
216
217
218
219
220
221
void NewWizardWidget::changePage(QWidget* toPage)
{
    if (toPage == ui->spinnerPage) {
        setNavBarVisibility(false);
    }
    Utils::setStackWidget(ui->stackedWidget, toPage);
    if (toPage == ui->welcomePage) {
222
        fileToImport_ = QString("");
Andreas Traczyk's avatar
Andreas Traczyk committed
223
        setNavBarVisibility(false, true);
Andreas Traczyk's avatar
Andreas Traczyk committed
224
        ui->lookupStatusLabel->hide();
225
        collapsiblePasswordWidget_->getPasswordStatusLabel()->hide();
226
227
228
        ui->newSIPAccountButton->hide();
        ui->connectAccountManagerButton->hide();
    } else if (toPage == ui->createAccountPage) {
Andreas Traczyk's avatar
Andreas Traczyk committed
229
        ui->usernameEdit->clear();
230
231
        collapsiblePasswordWidget_->getPasswordEdit()->clear();
        collapsiblePasswordWidget_->getConfirmPasswordEdit()->clear();
Andreas Traczyk's avatar
Andreas Traczyk committed
232
233
        ui->signUpCheckbox->setChecked(true);
        ui->usernameEdit->setEnabled(true);
234
        ui->fullNameEdit->setText(QString());
Andreas Traczyk's avatar
Andreas Traczyk committed
235
236
237
238
239
240
241
        setNavBarVisibility(true);
        updateCustomUI();
        registeredNameFoundConnection_ = connect(
            &LRCInstance::accountModel(), &lrc::api::NewAccountModel::registeredNameFound,
            this, &NewWizardWidget::slotRegisteredNameFound);
        validateWizardProgression();
        ui->setAvatarWidget->startBooth();
242
    } else if (toPage == ui->createSIPAccountPage) {
243
244
245
246
247
248
249
250
251
        ui->SIPusernameEdit->clear();
        ui->SIPpasswordEdit->clear();
        ui->SIPservernameEdit->clear();
        ui->SIPproxyEdit->clear();
        ui->SIPfullNameEdit->setText(QString());
        ui->SIPusernameEdit->setEnabled(true);
        setNavBarVisibility(true);
        ui->nextButton->setEnabled(true);
        ui->setSIPAvatarWidget->startBooth();
252
253
254
    } else if (toPage == ui->importFromDevicePage) {
        ui->pinFromDevice->clear();
        ui->passwordFromDevice->clear();
Andreas Traczyk's avatar
Andreas Traczyk committed
255
        setNavBarVisibility(true);
256
        ui->pinInfoLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
257
    } else if (toPage == ui->spinnerPage) {
Andreas Traczyk's avatar
Andreas Traczyk committed
258
        ui->lookupStatusLabel->hide();
259
        collapsiblePasswordWidget_->getPasswordStatusLabel()->hide();
260
261
262
263
264
265
266
267
268
269
270
271
272
    } else if (toPage == ui->connectToAccountManagerPage) {
        setNavBarVisibility(true);
        ui->usernameManagerEdit->clear();
        ui->passwordManagerEdit->clear();
        ui->accountManagerEdit->clear();
        ui->nextButton->setEnabled(false);
    } else if (toPage == ui->importFromBackupPage) {
        setNavBarVisibility(true);
        ui->passwordFromBackupEdit->clear();
        fileToImport_ = QString("");
        ui->fileImportBtn->setText(tr("Archive (None)"));
        ui->nextButton->setEnabled(false);
        ui->backupInfoLabel->hide();
Sébastien Blin's avatar
Sébastien Blin committed
273
274
    } else if (toPage == ui->backupKeysPage) {
        setNavBarVisibility(false);
Andreas Traczyk's avatar
Andreas Traczyk committed
275
276
277
278
279
280
281
282
283
284
285
    }
}

void
NewWizardWidget::updateCustomUI()
{
}

void
NewWizardWidget::setNavBarVisibility(bool nav, bool back)
{
286
287
288
    ui->navBarWidget->setVisible(nav || back);
    ui->nextButton->setVisible(nav);
    ui->previousButton->setVisible(nav);
Andreas Traczyk's avatar
Andreas Traczyk committed
289
290
291
292
293
294
295
    ui->backButton->setVisible(back && LRCInstance::accountModel().getAccountList().size());
}

void
NewWizardWidget::on_nextButton_clicked()
{
    const QWidget* curWidget = ui->stackedWidget->currentWidget();
296
297
    ui->setAvatarWidget->stopBooth();
    disconnect(registeredNameFoundConnection_);
298
    if (curWidget == ui->createAccountPage) {
299
300
        wizardMode_ = WizardMode::CREATE;
        processWizardInformations();
301
    } else if (curWidget == ui->importFromDevicePage) {
302
        wizardMode_ = WizardMode::IMPORT;
Andreas Traczyk's avatar
Andreas Traczyk committed
303
        processWizardInformations();
304
    } else if (curWidget == ui->createSIPAccountPage) {
305
306
        wizardMode_ = WizardMode::CREATESIP;
        processWizardInformations();
307
308
309
310
311
312
    } else if (curWidget == ui->connectToAccountManagerPage) {
        wizardMode_ = WizardMode::CONNECTMANAGER;
        processWizardInformations();
    } else if (curWidget == ui->importFromBackupPage) {
        wizardMode_ = WizardMode::IMPORT;
        processWizardInformations();
Andreas Traczyk's avatar
Andreas Traczyk committed
313
314
315
316
317
318
319
    }
}

void
NewWizardWidget::on_previousButton_clicked()
{
    const QWidget* curWidget = ui->stackedWidget->currentWidget();
320
321
    if (curWidget == ui->createAccountPage) { ui->setAvatarWidget->stopBooth(); }
    if (curWidget == ui->createSIPAccountPage) { ui->setSIPAvatarWidget->stopBooth(); }
322
    disconnect(registeredNameFoundConnection_);
Andreas Traczyk's avatar
Andreas Traczyk committed
323
    ui->lookupStatusLabel->hide();
324
    collapsiblePasswordWidget_->getPasswordStatusLabel()->hide();
325
326
327
328
329
    if (curWidget == ui->createAccountPage ||
        curWidget == ui->importFromDevicePage ||
        curWidget == ui->createSIPAccountPage ||
        curWidget == ui->connectToAccountManagerPage ||
        curWidget == ui->importFromBackupPage) {
Andreas Traczyk's avatar
Andreas Traczyk committed
330
331
332
333
        changePage(ui->welcomePage);
    }
}

334
335
336
337
338
339
340
341
342
343
344
345
void
NewWizardWidget::on_pinInfoBtn_clicked()
{
    ui->pinInfoLabel->setVisible(!ui->pinInfoLabel->isVisible());
}

void
NewWizardWidget::on_backupInfoBtn_clicked()
{
    ui->backupInfoLabel->setVisible(!ui->backupInfoLabel->isVisible());
}

Sébastien Blin's avatar
Sébastien Blin committed
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
void
NewWizardWidget::on_neverShowAgainBox_clicked()
{
    QSettings settings("jami.net", "Jami");
    settings.setValue(SettingsKey::neverShowMeAgain, ui->neverShowAgainBox->isChecked());
}

void
NewWizardWidget::on_skipBtn_clicked()
{
    emit NavigationRequested(ScreenEnum::CallScreen);
    emit LRCInstance::instance().accountListChanged();
}

void
NewWizardWidget::on_exportBtn_clicked()
{
363
364
365
    if (Utils::exportAccount(this)) {
        emit NavigationRequested(ScreenEnum::CallScreen);
        emit LRCInstance::instance().accountListChanged();
Sébastien Blin's avatar
Sébastien Blin committed
366
367
368
    }
}

Andreas Traczyk's avatar
Andreas Traczyk committed
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
void
NewWizardWidget::on_usernameEdit_textChanged(const QString &arg1)
{
    registrationStateOk_ = false;
    if (ui->signUpCheckbox->isChecked() && !arg1.isEmpty()) {
        registeredName_ = ui->usernameEdit->text().simplified();
        lookupTimer_.start(200);
    } else {
        updateNameRegistrationUi(NameRegistrationUIState::BLANK);
        lookupTimer_.stop();
        if (!arg1.isEmpty()) {
            lookupTimer_.start(200);
        }
    }
    validateWizardProgression();
}

void
NewWizardWidget::timeoutNameLookupTimer()
{
    if (ui->signUpCheckbox->isChecked() && !ui->usernameEdit->text().isEmpty()) {
        updateNameRegistrationUi(NameRegistrationUIState::SEARCHING);
391
        NameDirectory::instance().lookupName(QString(), registeredName_);
Andreas Traczyk's avatar
Andreas Traczyk committed
392
393
394
395
    }
}

void
396
NewWizardWidget::slotRegisteredNameFound(const QString& accountId,
Andreas Traczyk's avatar
Andreas Traczyk committed
397
                                         LookupStatus status,
398
399
                                         const QString& address,
                                         const QString& name)
Andreas Traczyk's avatar
Andreas Traczyk committed
400
{
401
402
403
    Q_UNUSED(accountId);
    Q_UNUSED(address);

Andreas Traczyk's avatar
Andreas Traczyk committed
404
405
406
407
    using namespace lrc::api::account;
    if (name.length() < 3) {
        registrationStateOk_ = false;
        updateNameRegistrationUi(NameRegistrationUIState::INVALID);
408
    } else if (registeredName_ == name) {
Andreas Traczyk's avatar
Andreas Traczyk committed
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
        switch (status) {
        case LookupStatus::NOT_FOUND:
        case LookupStatus::ERROR:
            registrationStateOk_ = true;
            updateNameRegistrationUi(NameRegistrationUIState::FREE);
            break;
        case LookupStatus::INVALID_NAME:
        case LookupStatus::INVALID:
            registrationStateOk_ = false;
            updateNameRegistrationUi(NameRegistrationUIState::INVALID);
            break;
        case LookupStatus::SUCCESS:
            registrationStateOk_ = false;
            updateNameRegistrationUi(NameRegistrationUIState::TAKEN);
            break;
        }
    }
    validateWizardProgression();
}

void
NewWizardWidget::handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name)
{
    Q_UNUSED(name);
    Q_UNUSED(status);
}

void
NewWizardWidget::on_signUpCheckbox_toggled(bool checked)
{
    if (checked) {
        ui->usernameEdit->setEnabled(true);
    } else {
        ui->usernameEdit->setEnabled(false);
        ui->usernameEdit->clear();
    }
    validateWizardProgression();
}

void
NewWizardWidget::validateWizardProgression()
{
451
452
453
454
455
456
457
458
459
460
461
    if (ui->stackedWidget->currentWidget() == ui->importFromDevicePage) {
        bool validPin = !ui->pinFromDevice->text().isEmpty();
        ui->nextButton->setEnabled(validPin);
        return;
    } else if (ui->stackedWidget->currentWidget() == ui->connectToAccountManagerPage) {
        bool validUsername = !ui->usernameManagerEdit->text().isEmpty();
        bool validPassword = !ui->passwordManagerEdit->text().isEmpty();
        bool validManager = !ui->accountManagerEdit->text().isEmpty();
        ui->nextButton->setEnabled(validUsername && validPassword && validManager);
        return;
    } else if (ui->stackedWidget->currentWidget() == ui->importFromBackupPage) {
462
        bool validImport = !fileToImport_.isEmpty();
463
        ui->nextButton->setEnabled(validImport);
464
465
        return;
    }
Andreas Traczyk's avatar
Andreas Traczyk committed
466
467
468
469
470
471
    bool usernameOk =
        !ui->signUpCheckbox->isChecked() ||
        (ui->signUpCheckbox->isChecked() &&
         !registeredName_.isEmpty() &&
         (registeredName_ == ui->usernameEdit->text()) &&
         registrationStateOk_ == true);
472
473
474
475
476
    bool passwordOk = collapsiblePasswordWidget_->getPasswordEdit()->text()
                      == collapsiblePasswordWidget_->getConfirmPasswordEdit()->text();
    if (passwordOk && !collapsiblePasswordWidget_->getPasswordEdit()->text().isEmpty()) {
        collapsiblePasswordWidget_->getPasswordStatusLabel()->show();
        collapsiblePasswordWidget_->getPasswordStatusLabel()->setPixmap(statusSuccessPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
477
    } else if (!passwordOk) {
478
479
        collapsiblePasswordWidget_->getPasswordStatusLabel()->show();
        collapsiblePasswordWidget_->getPasswordStatusLabel()->setPixmap(statusErrorPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
480
    } else {
481
        collapsiblePasswordWidget_->getPasswordStatusLabel()->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
482
483
484
485
    }
    ui->nextButton->setEnabled(usernameOk && passwordOk);
}

486
487
488
void
NewWizardWidget::processWizardInformations()
{
489
    inputPara_.clear();
490
491
492
    switch (wizardMode_) {
    case WizardMode::CREATE:
        ui->progressLabel->setText(tr("Generating your Jami account..."));
493
        inputPara_["alias"] = ui->fullNameEdit->text();
494
        inputPara_["password"] = collapsiblePasswordWidget_->getPasswordEdit()->text();
495
        ui->fullNameEdit->clear();
496
497
        collapsiblePasswordWidget_->getPasswordEdit()->clear();
        collapsiblePasswordWidget_->getConfirmPasswordEdit()->clear();
498
499
500
        break;
    case WizardMode::IMPORT:
        ui->progressLabel->setText(tr("Importing account archive..."));
501
502
503
504
505
506
507
        if (ui->stackedWidget->currentWidget() == ui->importFromBackupPage) {
            inputPara_["password"] = ui->passwordFromBackupEdit->text();
            ui->passwordFromBackupEdit->clear();
        } else if (ui->stackedWidget->currentWidget() == ui->importFromDevicePage) {
            inputPara_["archivePin"] = ui->pinFromDevice->text();
            inputPara_["password"] = ui->passwordFromDevice->text();
        }
508
509
510
511
        break;
    case WizardMode::MIGRATE:
        ui->progressLabel->setText(tr("Migrating your Jami account..."));
        break;
512
513
514
515
516
517
518
519
520
    case WizardMode::CREATESIP:
        ui->progressLabel->setText(tr("Generating your SIP account..."));
        if (ui->SIPfullNameEdit->text().isEmpty()) { inputPara_["alias"] = "SIP"; }
        else { inputPara_["alias"] = ui->SIPfullNameEdit->text(); }
        inputPara_["hostname"] = ui->SIPservernameEdit->text();
        inputPara_["username"] = ui->SIPusernameEdit->text();
        inputPara_["password"] = ui->SIPpasswordEdit->text();
        inputPara_["proxy"] = ui->SIPproxyEdit->text();
        break;
521
522
523
524
525
526
    case WizardMode::CONNECTMANAGER:
        ui->progressLabel->setText(tr("Connecting to account manager..."));
        inputPara_["username"] = ui->usernameManagerEdit->text();
        inputPara_["password"] = ui->passwordManagerEdit->text();
        inputPara_["manager"] = ui->accountManagerEdit->text();
        break;
527
528
    }

529
    inputPara_["archivePath"] = fileToImport_;
Andreas Traczyk's avatar
Andreas Traczyk committed
530
531
532
    if (inputPara_.find("archivePin") == inputPara_.end()) {
        inputPara_["archivePin"] = "";
    }
533

534
    changePage(ui->spinnerPage);
535
    createAccount();
536

537
    Utils::CreateStartupLink(L"Jami");
538
539
}

Andreas Traczyk's avatar
Andreas Traczyk committed
540
void
541
NewWizardWidget::createAccount()
Andreas Traczyk's avatar
Andreas Traczyk committed
542
{
543
    bool isConnectingToManager = wizardMode_ == WizardMode::CONNECTMANAGER;
544
    bool isRing = wizardMode_ == WizardMode::CREATE || wizardMode_ == WizardMode::IMPORT;
Sébastien Blin's avatar
Sébastien Blin committed
545
    bool isCreating = wizardMode_ == WizardMode::CREATE;
546
547
    if (isConnectingToManager) {
        Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::accountAdded,
548
            [this](const QString& accountId) {
549
                Q_UNUSED(accountId)
550
551
                if (!LRCInstance::accountModel().getAccountList().size())
                    return;
552
553
554
555
556
                emit NavigationRequested(ScreenEnum::CallScreen);
                emit LRCInstance::instance().accountListChanged();
        });
    } else {
        Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::accountAdded,
557
            [this, isRing, isCreating](const QString& accountId) {
558
559
560
                auto confProps = LRCInstance::accountModel().getAccountConfig(accountId);
                if (!isRing) {
                    // set SIP details
561
562
563
564
                    confProps.hostname = inputPara_["hostname"];
                    confProps.username = inputPara_["username"];
                    confProps.password = inputPara_["password"];
                    confProps.proxyServer = inputPara_["proxy"];
565
                }
566
567
                LRCInstance::accountModel().setAccountConfig(accountId, confProps);
                if (isRing) {
Sébastien Blin's avatar
Sébastien Blin committed
568
569
570
571
572
573
                    QSettings settings("jami.net", "Jami");
                    if (not settings.contains(SettingsKey::neverShowMeAgain)) {
                        settings.setValue(SettingsKey::neverShowMeAgain, false);
                    }
                    auto showBackup = isCreating && !settings.value(SettingsKey::neverShowMeAgain).toBool();

574
                    if (!confProps.username.isEmpty()) {
Sébastien Blin's avatar
Sébastien Blin committed
575
                        Utils::oneShotConnect(&LRCInstance::accountModel(),
576
                            &lrc::api::NewAccountModel::nameRegistrationEnded,
Sébastien Blin's avatar
Sébastien Blin committed
577
                            [this, showBackup] {
578
579
                                lrc::api::account::ConfProperties_t accountProperties = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
                                LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), accountProperties);
Sébastien Blin's avatar
Sébastien Blin committed
580
581
582
583
584
585
586
                                QSettings settings("jami.net", "Jami");
                                if (showBackup) {
                                    changePage(ui->backupKeysPage);
                                } else {
                                    emit NavigationRequested(ScreenEnum::CallScreen);
                                    emit LRCInstance::instance().accountListChanged();
                                }
587
588
589
                            });
                        LRCInstance::accountModel().registerName(
                            LRCInstance::getCurrAccId(),
590
                            inputPara_["password"],
591
                            registeredName_
592
593
                        );
                    } else {
Sébastien Blin's avatar
Sébastien Blin committed
594
595
596
597
598
599
                        if (showBackup) {
                            changePage(ui->backupKeysPage);
                        } else {
                            emit NavigationRequested(ScreenEnum::CallScreen);
                            emit LRCInstance::instance().accountListChanged();
                        }
600
601
602
603
                    }
                    LRCInstance::setCurrAccAvatar(ui->setAvatarWidget->getAvatarPixmap());
                } else {
                    LRCInstance::setCurrAccAvatar(ui->setSIPAvatarWidget->getAvatarPixmap());
604

605
606
607
                }
        });
    }
608
    Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::accountRemoved,
609
        [this](const QString& accountId) {
610
611
612
613
614
            Q_UNUSED(accountId);
            qWarning() << Q_FUNC_INFO << ": " << "accountRemoved";
            reportFailure();
        });
    Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::invalidAccountDetected,
615
        [this](const QString& accountId) {
616
617
618
619
            Q_UNUSED(accountId);
            qWarning() << Q_FUNC_INFO << ": " << "invalidAccountDetected";
            reportFailure();
        });
620
    QtConcurrent::run(
621
        [this, isRing, isConnectingToManager] {
622
623
624
            QMap<QString, QString> additionalAccountConfig;
            additionalAccountConfig.insert(DRing::Account::ConfProperties::Ringtone::PATH, Utils::GetRingtonePath());

625
626
            if (isConnectingToManager) {
                LRCInstance::accountModel().connectToAccountManager(
627
628
                    inputPara_["username"],
                    inputPara_["password"],
629
630
                    inputPara_["manager"],
                    additionalAccountConfig
631
                );
Sébastien Blin's avatar
Sébastien Blin committed
632
            } else if (isRing) {
633
634
                LRCInstance::accountModel().createNewAccount(
                    lrc::api::profile::Type::RING,
635
636
637
                    inputPara_["alias"],
                    inputPara_["archivePath"],
                    inputPara_["password"],
638
639
640
                    inputPara_["archivePin"],
                    "",
                    additionalAccountConfig
641
642
643
644
                );
            } else {
                LRCInstance::accountModel().createNewAccount(
                    lrc::api::profile::Type::SIP,
645
646
                    inputPara_["alias"],
                    inputPara_["archivePath"],
647
648
                    "",
                    "",
649
650
                    inputPara_["username"],
                    additionalAccountConfig
651
652
653
                );
                QThread::sleep(2);
                emit NavigationRequested(ScreenEnum::CallScreen);
654
                emit LRCInstance::instance().accountListChanged();
655
656
            }
    });
Andreas Traczyk's avatar
Andreas Traczyk committed
657
658
    changePage(ui->spinnerPage);
    repaint();
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
}

void
NewWizardWidget::reportFailure()
{
    auto spinnerGeometry = ui->spinnerLabel->frameGeometry();
    auto pixmap = Utils::generateTintedPixmap(":/images/icons/baseline-error_outline-24px.svg", RingTheme::urgentOrange_)
        .scaled(spinnerGeometry.width(), spinnerGeometry.height());
    ui->spinnerLabel->setPixmap(pixmap);
    ui->progressLabel->setStyleSheet("color:red;");
    ui->progressLabel->setText(tr("Error creating account"));
    QTimer::singleShot(1000, this,
        [this] {
            changePage(ui->welcomePage);
            ui->progressLabel->setStyleSheet("");
            ui->spinnerLabel->setMovie(creationSpinnerMovie_);
        });
676
}