Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 <https://www.gnu.org/licenses/>. * |
| 17 | **************************************************************************/ |
| 18 | |
| 19 | #include "linkdevwidget.h" |
| 20 | |
| 21 | #include <QMovie> |
Isa Nanic | 281d13a | 2018-12-11 18:55:02 -0500 | [diff] [blame] | 22 | #include <QTimer> |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 23 | |
| 24 | LinkDevWidget::LinkDevWidget(QWidget* parent) |
| 25 | : QWidget(parent), |
| 26 | ui(new Ui::LinkDevWidget) |
| 27 | { |
| 28 | ui->setupUi(this); |
| 29 | |
| 30 | if (LRCInstance::getCurrAccConfig().archiveHasPassword) { |
| 31 | ui->stackedWidget->setCurrentWidget(ui->start); |
| 32 | } else { |
| 33 | setGeneratingPage(); |
| 34 | } |
| 35 | |
Isa Nanic | 281d13a | 2018-12-11 18:55:02 -0500 | [diff] [blame] | 36 | connect(ui->enterBtn, &QPushButton::clicked, |
| 37 | this, &LinkDevWidget::setGeneratingPage); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 38 | connect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::exportOnRingEnded, |
Isa Nanic | 281d13a | 2018-12-11 18:55:02 -0500 | [diff] [blame] | 39 | this, &LinkDevWidget::setExportPage); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | LinkDevWidget::~LinkDevWidget() |
| 43 | { |
| 44 | delete ui; |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | LinkDevWidget::setGeneratingPage() |
| 49 | { |
| 50 | ui->stackedWidget->setCurrentWidget(ui->middle); |
| 51 | |
| 52 | QMovie* movie = new QMovie(":/images/ajax-loader.gif"); |
| 53 | ui->spinningLabel->setMovie(movie); |
| 54 | ui->spinningLabel->show(); |
| 55 | movie->start(); |
| 56 | |
Isa Nanic | 281d13a | 2018-12-11 18:55:02 -0500 | [diff] [blame] | 57 | timeout_ = new QTimer(this); |
| 58 | timeout_->setInterval(exportTimeout_); |
| 59 | timeout_->setSingleShot(true); |
| 60 | connect(timeout_, &QTimer::timeout, this, |
| 61 | [&]() { |
| 62 | setExportPage(std::string(), |
| 63 | lrc::api::account::ExportOnRingStatus::NETWORK_ERROR, |
| 64 | std::string()); |
| 65 | }); |
| 66 | timeout_->start(); |
| 67 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 68 | LRCInstance::accountModel().exportOnRing(LRCInstance::getCurrAccId(), ui->passwordLineEdit->text().toStdString()); |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | LinkDevWidget::setExportPage(const std::string& accountId, lrc::api::account::ExportOnRingStatus status, const std::string& pin) |
| 73 | { |
| 74 | Q_UNUSED(accountId); |
Isa Nanic | 281d13a | 2018-12-11 18:55:02 -0500 | [diff] [blame] | 75 | timeout_->stop(); |
| 76 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 77 | ui->stackedWidget->setCurrentWidget(ui->end); |
| 78 | |
| 79 | switch (status) { |
| 80 | case lrc::api::account::ExportOnRingStatus::WRONG_PASSWORD: |
| 81 | ui->label_4->setText(tr("Your account password was incorrect")); |
| 82 | ui->label_5->hide(); |
| 83 | ui->label_6->hide(); |
| 84 | break; |
| 85 | |
| 86 | case lrc::api::account::ExportOnRingStatus::SUCCESS: |
| 87 | ui->label_5->setText(QString::fromStdString(pin)); |
| 88 | break; |
| 89 | |
| 90 | default: |
Isa Nanic | 281d13a | 2018-12-11 18:55:02 -0500 | [diff] [blame] | 91 | disconnect(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 92 | ui->label_4->setText(tr("Something went wrong.\nPlease try again later.")); |
| 93 | ui->label_5->hide(); |
| 94 | ui->label_6->hide(); |
| 95 | } |
| 96 | } |