newwizardwidget.cpp 19.4 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
NewWizardWidget::NewWizardWidget(QWidget* parent) :
Andreas Traczyk's avatar
Andreas Traczyk committed
38 39
    NavWidget(parent),
    ui(new Ui::NewWizardWidget),
40
    wizardMode_(WizardMode::CREATE),
Andreas Traczyk's avatar
Andreas Traczyk committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    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
57 58
    ui->lookupStatusLabel->setMovie(lookupSpinnerMovie_);
    ui->lookupStatusLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
59 60 61 62 63 64 65

    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_);

66 67
    ui->infoWidget->hide();
    setNavBarVisibility(false, true);
Andreas Traczyk's avatar
Andreas Traczyk committed
68 69 70

    lookupTimer_.setSingleShot(true);

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    connect(ui->fileImportBtn, &QPushButton::clicked,
        [this] {
            QString filePath;
            filePath = QFileDialog::getOpenFileName(this,
                tr("Open File"),
                QString(),
                tr("Jami archive files (*.gz); All files (*)"));
            fileToImport_ = QDir::toNativeSeparators(filePath);
            if (!fileToImport_.isEmpty()) {
                QFileInfo fi(filePath);
                ui->fileImportBtn->setText(fi.fileName());
            } else {
                ui->fileImportBtn->setText(tr("(None)"));
            }
            validateWizardProgression();
        });

Andreas Traczyk's avatar
Andreas Traczyk committed
88 89 90 91 92 93 94 95 96 97 98 99 100
    connect(&lookupTimer_, &QTimer::timeout,
            this, &NewWizardWidget::timeoutNameLookupTimer);

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

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

101 102 103 104 105
    connect(ui->pinEdit, &QLineEdit::textChanged,
        [this] {
            validateWizardProgression();
        });

Andreas Traczyk's avatar
Andreas Traczyk committed
106 107 108 109 110 111 112 113
    ui->containerWidget->setVisible(false);
}

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

114 115 116
void
NewWizardWidget::setToMigrate(AccountInfo* toBeMigrated)
{
117
    wizardMode_ = WizardMode::MIGRATE;
118 119 120 121 122 123 124 125
    changePage(ui->createRingAccountPage);
    ui->usernameEdit->setEnabled(false);
    ui->usernameEdit->setText(QString::fromStdString(toBeMigrated->profileInfo.alias));
    ui->previousButton->hide();
    ui->infoWidget->show();
    ui->infoLabel->setText(tr("Your account needs to be migrated. Enter your password."));
}

Andreas Traczyk's avatar
Andreas Traczyk committed
126 127 128 129 130
void
NewWizardWidget::updateNameRegistrationUi(NameRegistrationUIState state)
{
    switch (state) {
    case NameRegistrationUIState::BLANK:
Andreas Traczyk's avatar
Andreas Traczyk committed
131
        ui->lookupStatusLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
132 133
        break;
    case NameRegistrationUIState::INVALID:
Andreas Traczyk's avatar
Andreas Traczyk committed
134
        ui->lookupStatusLabel->setPixmap(statusInvalidPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
135 136
        break;
    case NameRegistrationUIState::TAKEN:
Andreas Traczyk's avatar
Andreas Traczyk committed
137
        ui->lookupStatusLabel->setPixmap(statusErrorPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
138 139
        break;
    case NameRegistrationUIState::FREE:
Andreas Traczyk's avatar
Andreas Traczyk committed
140
        ui->lookupStatusLabel->setPixmap(statusSuccessPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
141 142
        break;
    case NameRegistrationUIState::SEARCHING:
Andreas Traczyk's avatar
Andreas Traczyk committed
143
        ui->lookupStatusLabel->setMovie(lookupSpinnerMovie_);
Andreas Traczyk's avatar
Andreas Traczyk committed
144 145
        lookupSpinnerMovie_->stop();
        lookupSpinnerMovie_->start();
Andreas Traczyk's avatar
Andreas Traczyk committed
146
        ui->lookupStatusLabel->show();
Andreas Traczyk's avatar
Andreas Traczyk committed
147 148 149 150 151 152 153 154 155 156 157 158
        break;
    }
}

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

159 160 161 162
void
NewWizardWidget::slotAccountOnBoarded()
{}

Andreas Traczyk's avatar
Andreas Traczyk committed
163 164 165 166 167 168 169 170 171 172 173 174
void
NewWizardWidget::on_existingPushButton_clicked()
{
    changePage(ui->linkRingAccountPage);
}

void
NewWizardWidget::on_newAccountButton_clicked()
{
    changePage(ui->createRingAccountPage);
}

175 176 177 178 179 180
void
NewWizardWidget::on_newSIPAccountButton_clicked()
{
    changePage(ui->createRingSIPAccountPage);
}

Andreas Traczyk's avatar
Andreas Traczyk committed
181 182 183 184 185 186 187
void NewWizardWidget::changePage(QWidget* toPage)
{
    if (toPage == ui->spinnerPage) {
        setNavBarVisibility(false);
    }
    Utils::setStackWidget(ui->stackedWidget, toPage);
    if (toPage == ui->welcomePage) {
188
        fileToImport_ = QString("");
Andreas Traczyk's avatar
Andreas Traczyk committed
189
        setNavBarVisibility(false, true);
Andreas Traczyk's avatar
Andreas Traczyk committed
190 191
        ui->lookupStatusLabel->hide();
        ui->passwordStatusLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
192 193 194 195 196 197
    } else if (toPage == ui->createRingAccountPage) {
        ui->usernameEdit->clear();
        ui->passwordEdit->clear();
        ui->confirmPasswordEdit->clear();
        ui->signUpCheckbox->setChecked(true);
        ui->usernameEdit->setEnabled(true);
198
        ui->fullNameEdit->setText(QString());
Andreas Traczyk's avatar
Andreas Traczyk committed
199 200 201 202 203 204 205
        setNavBarVisibility(true);
        updateCustomUI();
        registeredNameFoundConnection_ = connect(
            &LRCInstance::accountModel(), &lrc::api::NewAccountModel::registeredNameFound,
            this, &NewWizardWidget::slotRegisteredNameFound);
        validateWizardProgression();
        ui->setAvatarWidget->startBooth();
206 207 208 209 210 211 212 213 214 215
    } else if (toPage == ui->createRingSIPAccountPage) {
        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();
Andreas Traczyk's avatar
Andreas Traczyk committed
216
    } else if (toPage == ui->linkRingAccountPage) {
217 218 219 220 221 222
        fileToImport_ = QString("");
        ui->fileImportBtn->setText(tr("(None)"));
        ui->pinEdit->clear();
        ui->importPasswordEdit->clear();
        ui->pinEdit->setEnabled(true);
        ui->fileImportBtn->setEnabled(true);
Andreas Traczyk's avatar
Andreas Traczyk committed
223
        setNavBarVisibility(true);
Andreas Traczyk's avatar
Andreas Traczyk committed
224 225
        ui->lookupStatusLabel->hide();
        ui->passwordStatusLabel->hide();
226
        validateWizardProgression();
Andreas Traczyk's avatar
Andreas Traczyk committed
227
    } else if (toPage == ui->spinnerPage) {
Andreas Traczyk's avatar
Andreas Traczyk committed
228 229
        ui->lookupStatusLabel->hide();
        ui->passwordStatusLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
230 231 232 233 234 235 236 237 238 239 240
    }
}

void
NewWizardWidget::updateCustomUI()
{
}

void
NewWizardWidget::setNavBarVisibility(bool nav, bool back)
{
241 242 243
    ui->navBarWidget->setVisible(nav || back);
    ui->nextButton->setVisible(nav);
    ui->previousButton->setVisible(nav);
Andreas Traczyk's avatar
Andreas Traczyk committed
244 245 246 247 248 249 250
    ui->backButton->setVisible(back && LRCInstance::accountModel().getAccountList().size());
}

void
NewWizardWidget::on_nextButton_clicked()
{
    const QWidget* curWidget = ui->stackedWidget->currentWidget();
251 252
    ui->setAvatarWidget->stopBooth();
    disconnect(registeredNameFoundConnection_);
253 254 255
    if (curWidget == ui->createRingAccountPage) {
        wizardMode_ = WizardMode::CREATE;
        processWizardInformations();
256
    } else if (curWidget == ui->linkRingAccountPage) {
257
        wizardMode_ = WizardMode::IMPORT;
Andreas Traczyk's avatar
Andreas Traczyk committed
258
        processWizardInformations();
259 260 261
    } else if (curWidget == ui->createRingSIPAccountPage) {
        wizardMode_ = WizardMode::CREATESIP;
        processWizardInformations();
Andreas Traczyk's avatar
Andreas Traczyk committed
262 263 264 265 266 267 268
    }
}

void
NewWizardWidget::on_previousButton_clicked()
{
    const QWidget* curWidget = ui->stackedWidget->currentWidget();
269 270
    if (curWidget == ui->createRingAccountPage) { ui->setAvatarWidget->stopBooth(); }
    if (curWidget == ui->createRingSIPAccountPage) { ui->setSIPAvatarWidget->stopBooth(); }
271
    disconnect(registeredNameFoundConnection_);
Andreas Traczyk's avatar
Andreas Traczyk committed
272 273
    ui->lookupStatusLabel->hide();
    ui->passwordStatusLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
274
    if (curWidget == ui->createRingAccountPage ||
275
        curWidget == ui->linkRingAccountPage || curWidget == ui->createRingSIPAccountPage) {
Andreas Traczyk's avatar
Andreas Traczyk committed
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
        changePage(ui->welcomePage);
    }
}

void
NewWizardWidget::on_passwordEdit_textChanged(const QString& arg1)
{
    Q_UNUSED(arg1);
    validateWizardProgression();
}

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);
        NameDirectory::instance().lookupName(nullptr, QString(), registeredName_);
    }
}

void
NewWizardWidget::slotRegisteredNameFound(const std::string& accountId,
                                         LookupStatus status,
                                         const std::string& address,
                                         const std::string& name)
{
319 320 321
    Q_UNUSED(accountId);
    Q_UNUSED(address);

Andreas Traczyk's avatar
Andreas Traczyk committed
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
    using namespace lrc::api::account;
    if (name.length() < 3) {
        registrationStateOk_ = false;
        updateNameRegistrationUi(NameRegistrationUIState::INVALID);
    } else if (registeredName_.toStdString() == name) {
        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()
{
369 370 371 372 373 374 375 376 377 378
    if (ui->stackedWidget->currentWidget() == ui->linkRingAccountPage) {
        bool validPin = !ui->pinEdit->text().isEmpty();
        ui->fileImportBtn->setEnabled(!validPin);
        ui->fileImportLabel->setEnabled(!validPin);
        bool validImport = !fileToImport_.isEmpty();
        ui->pinEdit->setEnabled(!validImport);
        ui->pinEditLabel->setEnabled(!validImport);
        ui->nextButton->setEnabled(validPin || validImport);
        return;
    }
Andreas Traczyk's avatar
Andreas Traczyk committed
379 380 381 382 383 384 385 386
    bool usernameOk =
        !ui->signUpCheckbox->isChecked() ||
        (ui->signUpCheckbox->isChecked() &&
         !registeredName_.isEmpty() &&
         (registeredName_ == ui->usernameEdit->text()) &&
         registrationStateOk_ == true);
    bool passwordOk = ui->passwordEdit->text() == ui->confirmPasswordEdit->text();
    if (passwordOk && !ui->passwordEdit->text().isEmpty()) {
Andreas Traczyk's avatar
Andreas Traczyk committed
387 388
        ui->passwordStatusLabel->show();
        ui->passwordStatusLabel->setPixmap(statusSuccessPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
389
    } else if (!passwordOk) {
Andreas Traczyk's avatar
Andreas Traczyk committed
390 391
        ui->passwordStatusLabel->show();
        ui->passwordStatusLabel->setPixmap(statusErrorPixmap_);
Andreas Traczyk's avatar
Andreas Traczyk committed
392
    } else {
Andreas Traczyk's avatar
Andreas Traczyk committed
393
        ui->passwordStatusLabel->hide();
Andreas Traczyk's avatar
Andreas Traczyk committed
394 395 396 397
    }
    ui->nextButton->setEnabled(usernameOk && passwordOk);
}

398 399 400
void
NewWizardWidget::processWizardInformations()
{
401
    inputPara_.clear();
402 403 404
    switch (wizardMode_) {
    case WizardMode::CREATE:
        ui->progressLabel->setText(tr("Generating your Jami account..."));
405 406
        inputPara_["alias"] = ui->fullNameEdit->text();
        inputPara_["password"] = ui->passwordEdit->text();
407 408 409 410 411 412
        ui->fullNameEdit->clear();
        ui->passwordEdit->clear();
        ui->confirmPasswordEdit->clear();
        break;
    case WizardMode::IMPORT:
        ui->progressLabel->setText(tr("Importing account archive..."));
413 414
        inputPara_["password"] = ui->importPasswordEdit->text();
        inputPara_["archivePin"] = ui->pinEdit->text();
415 416 417 418 419 420
        ui->pinEdit->clear();
        ui->importPasswordEdit->clear();
        break;
    case WizardMode::MIGRATE:
        ui->progressLabel->setText(tr("Migrating your Jami account..."));
        break;
421 422 423 424 425 426 427 428 429
    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;
430 431
    }

432
    inputPara_["archivePath"] = fileToImport_;
Andreas Traczyk's avatar
Andreas Traczyk committed
433 434 435
    if (inputPara_.find("archivePin") == inputPara_.end()) {
        inputPara_["archivePin"] = "";
    }
436

437
    changePage(ui->spinnerPage);
438
    createAccount();
439 440 441 442

    Utils::CreateStartupLink();
}

Andreas Traczyk's avatar
Andreas Traczyk committed
443
void
444
NewWizardWidget::createAccount()
Andreas Traczyk's avatar
Andreas Traczyk committed
445
{
446
    bool isRing = wizardMode_ == WizardMode::CREATE || wizardMode_ == WizardMode::IMPORT;
Andreas Traczyk's avatar
Andreas Traczyk committed
447
    Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::accountAdded,
448
        [this, isRing](const std::string& accountId) {
Andreas Traczyk's avatar
Andreas Traczyk committed
449 450 451
            //set default ringtone
            auto confProps = LRCInstance::accountModel().getAccountConfig(accountId);
            confProps.Ringtone.ringtonePath = Utils::GetRingtonePath().toStdString();
452 453 454 455 456 457 458
            if (!isRing) {
                // set SIP details
                confProps.hostname = inputPara_["hostname"].toStdString();
                confProps.username = inputPara_["username"].toStdString();
                confProps.password = inputPara_["password"].toStdString();
                confProps.proxyServer = inputPara_["proxy"].toStdString();
            }
Andreas Traczyk's avatar
Andreas Traczyk committed
459
            LRCInstance::accountModel().setAccountConfig(accountId, confProps);
460
            if (isRing) {
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
                if (!confProps.username.empty()) {
                    connect(LRCInstance::editableAccountModel(),
                        &lrc::api::NewAccountModel::nameRegistrationEnded,
                        [this] {
                            lrc::api::account::ConfProperties_t accountProperties = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
                            LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), accountProperties);
                            emit NavigationRequested(ScreenEnum::CallScreen);
                            emit LRCInstance::instance().accountOnBoarded();
                        });
                    LRCInstance::editableAccountModel()->registerName(
                        LRCInstance::getCurrAccId(),
                        "",
                        registeredName_.toStdString()
                    );
                } else {
Andreas Traczyk's avatar
Andreas Traczyk committed
476
                    emit NavigationRequested(ScreenEnum::CallScreen);
477
                    emit LRCInstance::instance().accountOnBoarded();
478
                }
479
                LRCInstance::setCurrAccAvatar(ui->setAvatarWidget->getAvatarPixmap());
480 481 482
            } else {
                LRCInstance::setCurrAccAvatar(ui->setSIPAvatarWidget->getAvatarPixmap());

483
            }
484
    });
485 486 487 488 489 490 491 492 493 494 495 496
    Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::accountRemoved,
        [this](const std::string& accountId) {
            Q_UNUSED(accountId);
            qWarning() << Q_FUNC_INFO << ": " << "accountRemoved";
            reportFailure();
        });
    Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::invalidAccountDetected,
        [this](const std::string& accountId) {
            Q_UNUSED(accountId);
            qWarning() << Q_FUNC_INFO << ": " << "invalidAccountDetected";
            reportFailure();
        });
497
    QtConcurrent::run(
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
        [this, isRing] {
            if (isRing) {
                LRCInstance::accountModel().createNewAccount(
                    lrc::api::profile::Type::RING,
                    inputPara_["alias"].toStdString(),
                    inputPara_["archivePath"].toStdString(),
                    inputPara_["password"].toStdString(),
                    inputPara_["archivePin"].toStdString()
                );
            } else {
                LRCInstance::accountModel().createNewAccount(
                    lrc::api::profile::Type::SIP,
                    inputPara_["alias"].toStdString(),
                    inputPara_["archivePath"].toStdString(),
                    "",
                    "",
                    inputPara_["username"].toStdString()
                );
                QThread::sleep(2);
                emit NavigationRequested(ScreenEnum::CallScreen);
518
                emit LRCInstance::instance().accountOnBoarded();
519 520
            }
    });
Andreas Traczyk's avatar
Andreas Traczyk committed
521 522
    changePage(ui->spinnerPage);
    repaint();
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
}

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_);
        });
540
}