Skip to content
Snippets Groups Projects
Commit 281d13a1 authored by Isa's avatar Isa Committed by Andreas Traczyk
Browse files

fix: add timeout to network link device slot


Change-Id: I2bb7b2e19c393a0c9523a3719f2c11b3bf94dbde
Reviewed-by: default avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 41a4304f
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "linkdevwidget.h" #include "linkdevwidget.h"
#include <QMovie> #include <QMovie>
#include <QTimer>
LinkDevWidget::LinkDevWidget(QWidget* parent) LinkDevWidget::LinkDevWidget(QWidget* parent)
: QWidget(parent), : QWidget(parent),
...@@ -32,7 +33,8 @@ LinkDevWidget::LinkDevWidget(QWidget* parent) ...@@ -32,7 +33,8 @@ LinkDevWidget::LinkDevWidget(QWidget* parent)
setGeneratingPage(); setGeneratingPage();
} }
connect(ui->enterBtn, &QPushButton::clicked, this, &LinkDevWidget::setGeneratingPage); connect(ui->enterBtn, &QPushButton::clicked,
this, &LinkDevWidget::setGeneratingPage);
connect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::exportOnRingEnded, connect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::exportOnRingEnded,
this, &LinkDevWidget::setExportPage); this, &LinkDevWidget::setExportPage);
} }
...@@ -52,6 +54,17 @@ LinkDevWidget::setGeneratingPage() ...@@ -52,6 +54,17 @@ LinkDevWidget::setGeneratingPage()
ui->spinningLabel->show(); ui->spinningLabel->show();
movie->start(); 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()); LRCInstance::accountModel().exportOnRing(LRCInstance::getCurrAccId(), ui->passwordLineEdit->text().toStdString());
} }
...@@ -59,6 +72,8 @@ void ...@@ -59,6 +72,8 @@ void
LinkDevWidget::setExportPage(const std::string& accountId, lrc::api::account::ExportOnRingStatus status, const std::string& pin) LinkDevWidget::setExportPage(const std::string& accountId, lrc::api::account::ExportOnRingStatus status, const std::string& pin)
{ {
Q_UNUSED(accountId); Q_UNUSED(accountId);
timeout_->stop();
ui->stackedWidget->setCurrentWidget(ui->end); ui->stackedWidget->setCurrentWidget(ui->end);
switch (status) { switch (status) {
...@@ -73,6 +88,7 @@ LinkDevWidget::setExportPage(const std::string& accountId, lrc::api::account::Ex ...@@ -73,6 +88,7 @@ LinkDevWidget::setExportPage(const std::string& accountId, lrc::api::account::Ex
break; break;
default: default:
disconnect();
ui->label_4->setText(tr("Something went wrong.\nPlease try again later.")); ui->label_4->setText(tr("Something went wrong.\nPlease try again later."));
ui->label_5->hide(); ui->label_5->hide();
ui->label_6->hide(); ui->label_6->hide();
......
...@@ -42,8 +42,13 @@ public: ...@@ -42,8 +42,13 @@ public:
private: private:
Ui::LinkDevWidget* ui; Ui::LinkDevWidget* ui;
const int exportTimeout_ = 10000;
QTimer* timeout_;
private slots: private slots:
void setGeneratingPage(); 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);
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment