Commit 281d13a1 authored by Isa's avatar Isa Committed by Andreas Traczyk

fix: add timeout to network link device slot

Change-Id: I2bb7b2e19c393a0c9523a3719f2c11b3bf94dbde
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 41a4304f
......@@ -19,6 +19,7 @@
#include "linkdevwidget.h"
#include <QMovie>
#include <QTimer>
LinkDevWidget::LinkDevWidget(QWidget* parent)
: QWidget(parent),
......@@ -32,9 +33,10 @@ LinkDevWidget::LinkDevWidget(QWidget* parent)
setGeneratingPage();
}
connect(ui->enterBtn, &QPushButton::clicked, this, &LinkDevWidget::setGeneratingPage);
connect(ui->enterBtn, &QPushButton::clicked,
this, &LinkDevWidget::setGeneratingPage);
connect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::exportOnRingEnded,
this, &LinkDevWidget::setExportPage);
this, &LinkDevWidget::setExportPage);
}
LinkDevWidget::~LinkDevWidget()
......@@ -52,6 +54,17 @@ LinkDevWidget::setGeneratingPage()
ui->spinningLabel->show();
movie->start();
timeout_ = new QTimer(this);
timeout_->setInterval(exportTimeout_);
timeout_->setSingleShot(true);
connect(timeout_, &QTimer::timeout, this,
[&]() {
setExportPage(std::string(),
lrc::api::account::ExportOnRingStatus::NETWORK_ERROR,
std::string());
});
timeout_->start();
LRCInstance::accountModel().exportOnRing(LRCInstance::getCurrAccId(), ui->passwordLineEdit->text().toStdString());
}
......@@ -59,6 +72,8 @@ void
LinkDevWidget::setExportPage(const std::string& accountId, lrc::api::account::ExportOnRingStatus status, const std::string& pin)
{
Q_UNUSED(accountId);
timeout_->stop();
ui->stackedWidget->setCurrentWidget(ui->end);
switch (status) {
......@@ -73,6 +88,7 @@ LinkDevWidget::setExportPage(const std::string& accountId, lrc::api::account::Ex
break;
default:
disconnect();
ui->label_4->setText(tr("Something went wrong.\nPlease try again later."));
ui->label_5->hide();
ui->label_6->hide();
......
......@@ -42,8 +42,13 @@ public:
private:
Ui::LinkDevWidget* ui;
const int exportTimeout_ = 10000;
QTimer* timeout_;
private slots:
void setGeneratingPage();
void setExportPage(const std::string& accountId, lrc::api::account::ExportOnRingStatus status, const std::string& pin);
void setExportPage(const std::string& accountId,
lrc::api::account::ExportOnRingStatus status,
const std::string& pin);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment