summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkreplyimpl.cpp
diff options
context:
space:
mode:
authorShane Kearns <[email protected]>2012-05-24 16:14:28 +0100
committerQt by Nokia <[email protected]>2012-06-14 05:26:35 +0200
commitd6d9c8bf3245ec3d1ff05ae45d54baac64d76cec (patch)
treea06dd484063c9ad94ad21b98241b0d1afe4d0961 /src/network/access/qnetworkreplyimpl.cpp
parent5a7937bb042a006482ed50f7b7de437e15e593ce (diff)
choke downloadProgress signals
The QNetworkReply::downloadProgress signal is intended for updating user interface components (e.g. a progress bar). Limit signal emissions to 10 times per second, with an additional signal just before the finished() signal to provide the 100% progress. For the size of download where a progress bar is necessary, this update frequency seems sufficient. The implementation is done by dropping signals which would be emitted less than 100ms after the previous signal emission. Task-number: QTBUG-20449 Change-Id: I9c2dbe16c70f3270cbf98f3c74cf9d9a3f0ab900 Reviewed-by: David Faure <[email protected]> Reviewed-by: Markus Goetz <[email protected]> Reviewed-by: Martin Petersson <[email protected]>
Diffstat (limited to 'src/network/access/qnetworkreplyimpl.cpp')
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 7cbbe389da6..9f8a6cfb5ce 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -144,6 +144,9 @@ void QNetworkReplyImplPrivate::_q_startOperation()
}
#endif
+ // Start timer for progress notifications
+ downloadProgressSignalChoke.start();
+
if (backend && backend->isSynchronous()) {
state = Finished;
q_func()->setFinished(true);
@@ -210,8 +213,11 @@ void QNetworkReplyImplPrivate::_q_copyReadyRead()
// emit readyRead before downloadProgress incase this will cause events to be
// processed and we get into a recursive call (as in QProgressDialog).
emit q->readyRead();
- emit q->downloadProgress(bytesDownloaded,
+ if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
+ downloadProgressSignalChoke.restart();
+ emit q->downloadProgress(bytesDownloaded,
totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
+ }
resumeNotificationHandling();
}
@@ -640,8 +646,11 @@ void QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions()
emit q->readyRead();
// emit readyRead before downloadProgress incase this will cause events to be
// processed and we get into a recursive call (as in QProgressDialog).
- emit q->downloadProgress(bytesDownloaded,
+ if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
+ downloadProgressSignalChoke.restart();
+ emit q->downloadProgress(bytesDownloaded,
totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
+ }
resumeNotificationHandling();
// do we still have room in the buffer?
@@ -747,7 +756,10 @@ void QNetworkReplyImplPrivate::appendDownstreamDataDownloadBuffer(qint64 bytesRe
// processed and we get into a recursive call (as in QProgressDialog).
if (bytesDownloaded > 0)
emit q->readyRead();
- emit q->downloadProgress(bytesDownloaded, bytesTotal);
+ if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
+ downloadProgressSignalChoke.restart();
+ emit q->downloadProgress(bytesDownloaded, bytesTotal);
+ }
}
void QNetworkReplyImplPrivate::finished()
@@ -795,6 +807,8 @@ void QNetworkReplyImplPrivate::finished()
pauseNotificationHandling();
if (totalSize.isNull() || totalSize == -1) {
emit q->downloadProgress(bytesDownloaded, bytesDownloaded);
+ } else {
+ emit q->downloadProgress(bytesDownloaded, totalSize.toLongLong());
}
if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer))