blob: ac1939237adadfa7433543e8f23288bd91f76c87 [file] [log] [blame]
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001/**************************************************************************
2* Copyright (C) 2018 by Savoir-faire Linux *
3* Author: Isa Nanic <isa.nanic@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 <http://www.gnu.org/licenses/>. *
17**************************************************************************/
18
19#include "regnamedialog.h"
20#include "ui_regnamedialog.h"
21
Isa Nanic26c86612018-12-14 12:21:56 -050022#include <QTimer>
23
Isa Nanic6e4a39a2018-12-04 14:26:02 -050024RegNameDialog::RegNameDialog(const QString& newRegName, QWidget* parent)
Isa Nanic26c86612018-12-14 12:21:56 -050025 :QDialog(parent),
26 ui(new Ui::RegNameDialog),
27 registeredName_(newRegName),
28 gif(new QMovie(":/images/ajax-loader.gif"))
Isa Nanic6e4a39a2018-12-04 14:26:02 -050029{
30 ui->setupUi(this);
Isa Nanic26c86612018-12-14 12:21:56 -050031
32 ui->stackedWidget->setCurrentWidget(ui->startPage);
Isa Nanic6e4a39a2018-12-04 14:26:02 -050033 ui->registeredName->setText(newRegName);
34
Isa Nanic26c86612018-12-14 12:21:56 -050035 connect(ui->startPageConfirmBtn, &QPushButton::clicked, this, &RegNameDialog::startNameRegistration);
Isa Nanic6e4a39a2018-12-04 14:26:02 -050036
Isa Nanic26c86612018-12-14 12:21:56 -050037 connect(ui->startPageCancelBtn, &QPushButton::clicked, [this]() {
Isa Nanic6e4a39a2018-12-04 14:26:02 -050038 reject();
39 }
40 );
Isa Nanic26c86612018-12-14 12:21:56 -050041
42 // get name registration result
43 connect(LRCInstance::editableAccountModel(), &lrc::api::NewAccountModel::nameRegistrationEnded,
44 this, &RegNameDialog::nameRegistrationResultSlot);
Isa Nanic6e4a39a2018-12-04 14:26:02 -050045}
46
47RegNameDialog::~RegNameDialog()
48{
49 disconnect(this);
50 delete ui;
51}
52
Isa Nanic26c86612018-12-14 12:21:56 -050053void
54RegNameDialog::startNameRegistration()
55{
56 LRCInstance::editableAccountModel()->registerName(LRCInstance::getCurrAccId(),
57 "", registeredName_.toStdString());
58 startSpinner();
59}
60
61void
62RegNameDialog::nameRegistrationResultSlot(const std::string& accountId,
63 lrc::api::account::RegisterNameStatus status, const std::string& registerdName)
64{
65 gif->stop();
66
67 if(status == lrc::api::account::RegisterNameStatus::SUCCESS) {
68 ui->stackedWidget->setCurrentWidget(ui->nameRegisteredPage);
69 QTimer::singleShot(1000, this, &RegNameDialog::accept);
70 } else {
71 ui->stackedWidget->setCurrentWidget(ui->nameNotRegisteredPage);
72 QTimer::singleShot(1000, this, &RegNameDialog::reject);
73 }
74}
75
76void
77RegNameDialog::startSpinner()
78{
79 ui->stackedWidget->setCurrentWidget(ui->loadingPage);
80
81 ui->spinnerLabel->setMovie(gif);
82 gif->start();
83}