diff options
author | Shane Kearns <ext-shane.2.kearns@nokia.com> | 2012-05-24 16:14:28 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-14 05:26:35 +0200 |
commit | d6d9c8bf3245ec3d1ff05ae45d54baac64d76cec (patch) | |
tree | a06dd484063c9ad94ad21b98241b0d1afe4d0961 /src/network/access/qnetworkreplyhttpimpl.cpp | |
parent | 5a7937bb042a006482ed50f7b7de437e15e593ce (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 <faure@kde.org>
Reviewed-by: Markus Goetz <markus@woboq.com>
Reviewed-by: Martin Petersson <Martin.Petersson@nokia.com>
Diffstat (limited to 'src/network/access/qnetworkreplyhttpimpl.cpp')
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 5be59e20ce..cf92f55cdf 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -888,6 +888,10 @@ void QNetworkReplyHttpImplPrivate::postRequest() delegate->moveToThread(thread); // This call automatically moves the uploadDevice too for the asynchronous case. + // Start timer for progress notifications + downloadProgressSignalChoke.start(); + + // Send an signal to the delegate so it starts working in the other thread if (synchronous) { emit q->startHttpRequestSynchronously(); // This one is BlockingQueuedConnection, so it will return when all work is done @@ -1022,8 +1026,11 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d) 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()); + } } @@ -1181,7 +1188,10 @@ void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceive // 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 QNetworkReplyHttpImplPrivate::httpAuthenticationRequired(const QHttpNetworkRequest &request, @@ -1623,8 +1633,11 @@ void QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead() // This readyRead() goes to the user. The user then may or may not read() anything. 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()); + } // If there are still bytes available in the cacheLoadDevice then the user did not read // in response to the readyRead() signal. This means we have to load from the cacheLoadDevice @@ -1863,6 +1876,8 @@ void QNetworkReplyHttpImplPrivate::finished() if (totalSize.isNull() || totalSize == -1) { emit q->downloadProgress(bytesDownloaded, bytesDownloaded); + } else { + emit q->downloadProgress(bytesDownloaded, totalSize.toLongLong()); } if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer)) |