From 919c7045b76f61a67cd00189127cd7d3488065b0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 14 Nov 2013 17:47:35 -0800 Subject: Add support for timing the download out The time out is 30 seconds from the start of the request or from the last time we got any data from the server. Signed-off-by: Thiago Macieira --- qt-ui/subsurfacewebservices.cpp | 15 +++++++++++++++ qt-ui/subsurfacewebservices.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 2607dbb2e..5756e806d 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -95,7 +95,9 @@ WebServices::WebServices(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f) ui.setupUi(this); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); connect(ui.download, SIGNAL(clicked(bool)), this, SLOT(startDownload())); + connect(&timeout, SIGNAL(timeout()), this, SLOT(downloadTimedOut())); ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); + timeout.setSingleShot(true); } void WebServices::hidePassword() @@ -115,6 +117,17 @@ QNetworkAccessManager *WebServices::manager() return manager; } +void WebServices::downloadTimedOut() +{ + if (!reply) + return; + + reply->deleteLater(); + reply = NULL; + resetState(); + ui.status->setText(tr("Download timed out")); +} + void WebServices::updateProgress(qint64 current, qint64 total) { if (!reply) @@ -144,6 +157,8 @@ void WebServices::connectSignalsForDownload(QNetworkReply *reply) this, SLOT(downloadError(QNetworkReply::NetworkError))); connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64))); + + timeout.start(30000); // 30s } void WebServices::resetState() diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h index 05735f859..89c41e4dd 100644 --- a/qt-ui/subsurfacewebservices.h +++ b/qt-ui/subsurfacewebservices.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "ui_webservices.h" @@ -23,6 +24,7 @@ private slots: virtual void startDownload() = 0; virtual void startUpload() = 0; virtual void buttonClicked(QAbstractButton* button) = 0; + virtual void downloadTimedOut(); protected slots: void updateProgress(qint64 current, qint64 total); @@ -33,6 +35,7 @@ protected: Ui::WebServices ui; QNetworkReply *reply; + QTimer timeout; QByteArray downloadedData; }; -- cgit v1.2.3-70-g09d2