From 727eacdc226873f61a5a546ab81ff11181fe9bb5 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 24 Aug 2010 13:10:23 +0200 Subject: QNAM: New QNetworkReply::setFinished() protected function This function custom allows subclasses of QNetworkReply to also use the behaviour that is enabled by having isFinished(). Task-Number: QTBUG-11737 Reviewed-by: Peter Hartmann --- src/network/access/qfilenetworkreply.cpp | 7 +------ src/network/access/qfilenetworkreply_p.h | 2 -- src/network/access/qnetworkaccessbackend.cpp | 2 +- src/network/access/qnetworkreply.cpp | 18 +++++++++++++++++- src/network/access/qnetworkreply.h | 1 + src/network/access/qnetworkreply_p.h | 3 +-- src/network/access/qnetworkreplyimpl.cpp | 11 ++++------- src/network/access/qnetworkreplyimpl_p.h | 2 -- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/network/access/qfilenetworkreply.cpp b/src/network/access/qfilenetworkreply.cpp index 4ac9a8c..c6715e6 100644 --- a/src/network/access/qfilenetworkreply.cpp +++ b/src/network/access/qfilenetworkreply.cpp @@ -68,6 +68,7 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req setRequest(req); setUrl(req.url()); setOperation(op); + setFinished(true); QNetworkReply::open(QIODevice::ReadOnly); qRegisterMetaType("QNetworkReply::NetworkError"); @@ -141,12 +142,6 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); } - -bool QFileNetworkReplyPrivate::isFinished() const -{ - return true; -} - void QFileNetworkReply::close() { Q_D(QFileNetworkReply); diff --git a/src/network/access/qfilenetworkreply_p.h b/src/network/access/qfilenetworkreply_p.h index 710ec9f..227c775 100644 --- a/src/network/access/qfilenetworkreply_p.h +++ b/src/network/access/qfilenetworkreply_p.h @@ -92,8 +92,6 @@ public: qint64 fileSize; qint64 filePos; - virtual bool isFinished() const; - Q_DECLARE_PUBLIC(QFileNetworkReply) }; diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 45495f7..c3d765b 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -146,7 +146,7 @@ QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice() // and the special backends need to access this. void QNetworkAccessBackend::emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal) { - if (reply->isFinished()) + if (reply->isFinished) return; reply->emitUploadProgress(bytesSent, bytesTotal); } diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index c8b8c1f..b40ee3c 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -49,6 +49,7 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() : readBufferMaxSize(0), operation(QNetworkAccessManager::UnknownOperation), errorCode(QNetworkReply::NoError) + , isFinished(false) { // set the default attribute values attributes.insert(QNetworkRequest::ConnectionEncryptedAttribute, false); @@ -468,7 +469,7 @@ QNetworkReply::NetworkError QNetworkReply::error() const */ bool QNetworkReply::isFinished() const { - return d_func()->isFinished(); + return d_func()->isFinished; } /*! @@ -724,6 +725,21 @@ void QNetworkReply::setError(NetworkError errorCode, const QString &errorString) } /*! + \since 4.8 + Sets the reply as \a finished. + + After having this set the replies data must not change. + + \sa isFinished() +*/ +void QNetworkReply::setFinished(bool finished) +{ + Q_D(QNetworkReply); + d->isFinished = finished; +} + + +/*! Sets the URL being processed to be \a url. Normally, the URL matches that of the request that was posted, but for a variety of reasons it can be different (for example, a file path being made diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index acb7379..b39fd32 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -163,6 +163,7 @@ protected: void setOperation(QNetworkAccessManager::Operation operation); void setRequest(const QNetworkRequest &request); void setError(NetworkError errorCode, const QString &errorString); + void setFinished(bool); void setUrl(const QUrl &url); void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); void setRawHeader(const QByteArray &headerName, const QByteArray &value); diff --git a/src/network/access/qnetworkreply_p.h b/src/network/access/qnetworkreply_p.h index d7b8ab0..2e2e0bc 100644 --- a/src/network/access/qnetworkreply_p.h +++ b/src/network/access/qnetworkreply_p.h @@ -71,12 +71,11 @@ public: qint64 readBufferMaxSize; QNetworkAccessManager::Operation operation; QNetworkReply::NetworkError errorCode; + bool isFinished; static inline void setManager(QNetworkReply *reply, QNetworkAccessManager *manager) { reply->d_func()->manager = manager; } - virtual bool isFinished() const { return false; } - Q_DECLARE_PUBLIC(QNetworkReply) }; diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 5345d63..70418e9 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -689,6 +689,8 @@ void QNetworkReplyImplPrivate::finished() resumeNotificationHandling(); state = Finished; + q->setFinished(true); + pendingNotifications.clear(); pauseNotificationHandling(); @@ -759,11 +761,6 @@ void QNetworkReplyImplPrivate::sslErrors(const QList &errors) #endif } -bool QNetworkReplyImplPrivate::isFinished() const -{ - return (state == Finished || state == Aborted); -} - QNetworkReplyImpl::QNetworkReplyImpl(QObject *parent) : QNetworkReply(*new QNetworkReplyImplPrivate, parent) { @@ -798,7 +795,7 @@ void QNetworkReplyImpl::abort() QNetworkReply::close(); if (d->state != QNetworkReplyImplPrivate::Finished) { - // emit signals + // call finished which will emit signals d->error(OperationCanceledError, tr("Operation canceled")); d->finished(); } @@ -826,7 +823,7 @@ void QNetworkReplyImpl::close() QNetworkReply::close(); - // emit signals + // call finished which will emit signals d->error(OperationCanceledError, tr("Operation canceled")); d->finished(); } diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index ab11ebe..2cb3082 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -173,8 +173,6 @@ public: void redirectionRequested(const QUrl &target); void sslErrors(const QList &errors); - bool isFinished() const; - QNetworkAccessBackend *backend; QIODevice *outgoingData; QRingBuffer *outgoingDataBuffer; -- cgit v0.12