summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Thiago Macieira <thiago@macieira.org>2013-11-14 16:52:08 -0800
committerGravatar Thiago Macieira <thiago@macieira.org>2013-12-03 13:53:00 -0800
commitab1b314a84347b648fa0df6a9719f67a9fb54d54 (patch)
tree4bd019243a617070026c51783911518851cd28ad
parentfa07f554e2894c7720a41c1fbb379743dd6c7285 (diff)
downloadsubsurface-ab1b314a84347b648fa0df6a9719f67a9fb54d54.tar.gz
Set the download reply pointer to NULL after dismissing it
QNetworkReply might emit signals after it's been told to go away. We don't want to change the status after that. Signed-off-by: Thiago Macieira <thiago@macieira.org>
-rw-r--r--qt-ui/subsurfacewebservices.cpp42
-rw-r--r--qt-ui/subsurfacewebservices.h4
2 files changed, 42 insertions, 4 deletions
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index 1f47d965b..2607dbb2e 100644
--- a/qt-ui/subsurfacewebservices.cpp
+++ b/qt-ui/subsurfacewebservices.cpp
@@ -115,6 +115,37 @@ QNetworkAccessManager *WebServices::manager()
return manager;
}
+void WebServices::updateProgress(qint64 current, qint64 total)
+{
+ if (!reply)
+ return;
+
+ if (total >= INT_MAX / 2) {
+ // over a gigabyte!
+ if (total >= Q_INT64_C(1) << 47) {
+ total >>= 16;
+ current >>= 16;
+ }
+ total >>= 16;
+ current >>= 16;
+ }
+ ui.progressBar->setRange(0, total);
+ ui.progressBar->setValue(current);
+ ui.status->setText(tr("Downloading..."));
+
+ // reset the timer: 30 seconds after we last got any data
+ timeout.start();
+}
+
+void WebServices::connectSignalsForDownload(QNetworkReply *reply)
+{
+ connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
+ connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
+ this, SLOT(downloadError(QNetworkReply::NetworkError)));
+ connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this,
+ SLOT(updateProgress(qint64,qint64)));
+}
+
void WebServices::resetState()
{
ui.download->setEnabled(true);
@@ -170,6 +201,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
case QDialogButtonBox::RejectRole:
// we may want to clean up after ourselves
// reply->deleteLater();
+ reply = NULL;
resetState();
break;
case QDialogButtonBox::HelpRole:
@@ -193,14 +225,14 @@ void SubsurfaceWebServices::startDownload()
ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin'
ui.download->setEnabled(false);
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
-
- connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
- connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
- this, SLOT(downloadError(QNetworkReply::NetworkError)));
+ connectSignalsForDownload(reply);
}
void SubsurfaceWebServices::downloadFinished()
{
+ if (!reply)
+ return;
+
ui.progressBar->setRange(0,1);
downloadedData = reply->readAll();
@@ -213,6 +245,7 @@ void SubsurfaceWebServices::downloadFinished()
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
}
reply->deleteLater();
+ reply = NULL;
}
void SubsurfaceWebServices::downloadError(QNetworkReply::NetworkError)
@@ -220,6 +253,7 @@ void SubsurfaceWebServices::downloadError(QNetworkReply::NetworkError)
resetState();
ui.status->setText(tr("Download error: %1").arg(reply->errorString()));
reply->deleteLater();
+ reply = NULL;
}
void SubsurfaceWebServices::setStatusText(int status)
diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h
index 0cd083001..05735f859 100644
--- a/qt-ui/subsurfacewebservices.h
+++ b/qt-ui/subsurfacewebservices.h
@@ -24,8 +24,12 @@ private slots:
virtual void startUpload() = 0;
virtual void buttonClicked(QAbstractButton* button) = 0;
+protected slots:
+ void updateProgress(qint64 current, qint64 total);
+
protected:
void resetState();
+ void connectSignalsForDownload(QNetworkReply *reply);
Ui::WebServices ui;
QNetworkReply *reply;