summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-07-14 11:05:11 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-07-14 11:33:49 (GMT)
commitec11bd70c78cbdb07b399b058fabdb16d66072b0 (patch)
treea29b7061a0624df7539750dc2e9183c5068912f1
parenta2bad25383e565233a0c2527e04cef9f6b577f14 (diff)
downloadQt-ec11bd70c78cbdb07b399b058fabdb16d66072b0.zip
Qt-ec11bd70c78cbdb07b399b058fabdb16d66072b0.tar.gz
Qt-ec11bd70c78cbdb07b399b058fabdb16d66072b0.tar.bz2
QNetworkReply: Add isFinished() method
The isFinished() method will return true if the reply has successfully finished or has been aborted. Task-number: 257349 Reviewed-by: Thiago Macieira
-rw-r--r--src/network/access/qnetworkreply.cpp21
-rw-r--r--src/network/access/qnetworkreply.h2
-rw-r--r--src/network/access/qnetworkreply_p.h2
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp5
-rw-r--r--src/network/access/qnetworkreplyimpl_p.h2
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp10
6 files changed, 42 insertions, 0 deletions
diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp
index 1b0d9f5..e55c202 100644
--- a/src/network/access/qnetworkreply.cpp
+++ b/src/network/access/qnetworkreply.cpp
@@ -442,6 +442,27 @@ QNetworkReply::NetworkError QNetworkReply::error() const
}
/*!
+ Returns true when the reply has finished or was aborted.
+
+ \sa isRunning()
+*/
+bool QNetworkReply::isFinished() const
+{
+ return d_func()->isFinished();
+}
+
+/*!
+ Returns true when the request is still processing and the
+ reply has not finished or was aborted yet.
+
+ \sa isFinished()
+*/
+bool QNetworkReply::isRunning() const
+{
+ return !isFinished();
+}
+
+/*!
Returns the URL of the content downloaded or uploaded. Note that
the URL may be different from that of the original request.
diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h
index 7cb082f..30e89f1 100644
--- a/src/network/access/qnetworkreply.h
+++ b/src/network/access/qnetworkreply.h
@@ -116,6 +116,8 @@ public:
QNetworkAccessManager::Operation operation() const;
QNetworkRequest request() const;
NetworkError error() const;
+ bool isFinished() const;
+ bool isRunning() const;
QUrl url() const;
// "cooked" headers
diff --git a/src/network/access/qnetworkreply_p.h b/src/network/access/qnetworkreply_p.h
index c8543f0..b51e3fb 100644
--- a/src/network/access/qnetworkreply_p.h
+++ b/src/network/access/qnetworkreply_p.h
@@ -75,6 +75,8 @@ public:
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 b11d986..55b8b7f 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -532,6 +532,11 @@ void QNetworkReplyImplPrivate::sslErrors(const QList<QSslError> &errors)
#endif
}
+bool QNetworkReplyImplPrivate::isFinished() const
+{
+ return (state == Finished || state == Aborted);
+}
+
QNetworkReplyImpl::QNetworkReplyImpl(QObject *parent)
: QNetworkReply(*new QNetworkReplyImplPrivate, parent)
{
diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h
index 3e89a00..454185a 100644
--- a/src/network/access/qnetworkreplyimpl_p.h
+++ b/src/network/access/qnetworkreplyimpl_p.h
@@ -152,6 +152,8 @@ public:
void redirectionRequested(const QUrl &target);
void sslErrors(const QList<QSslError> &errors);
+ bool isFinished() const;
+
QNetworkAccessBackend *backend;
QIODevice *outgoingData;
QRingBuffer *outgoingDataBuffer;
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index cb1cb9b..f2bfb1f 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -1003,6 +1003,7 @@ void tst_QNetworkReply::stateChecking()
QCOMPARE(reply->request(), req);
QCOMPARE(int(reply->operation()), int(QNetworkAccessManager::GetOperation));
QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QCOMPARE(reply->isFinished(), false);
QCOMPARE(reply->url(), url);
reply->abort();
@@ -1324,6 +1325,9 @@ void tst_QNetworkReply::getErrors()
QTEST(reply->readAll().isEmpty(), "dataIsEmpty");
+ QVERIFY(reply->isFinished());
+ QVERIFY(!reply->isRunning());
+
QFETCH(int, httpStatusCode);
if (httpStatusCode != 0) {
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), httpStatusCode);
@@ -3237,6 +3241,8 @@ void tst_QNetworkReply::downloadProgress()
connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
&QTestEventLoop::instance(), SLOT(exitLoop()));
QVERIFY(spy.isValid());
+ QVERIFY(!reply->isFinished());
+ QVERIFY(reply->isRunning());
QCoreApplication::instance()->processEvents();
if (!server.hasPendingConnections())
@@ -3257,6 +3263,8 @@ void tst_QNetworkReply::downloadProgress()
QTestEventLoop::instance().enterLoop(2);
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(spy.count() > 0);
+ QVERIFY(!reply->isFinished());
+ QVERIFY(reply->isRunning());
QList<QVariant> args = spy.last();
QCOMPARE(args.at(0).toInt(), i*data.size());
@@ -3270,6 +3278,8 @@ void tst_QNetworkReply::downloadProgress()
QTestEventLoop::instance().enterLoop(2);
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(spy.count() > 0);
+ QVERIFY(!reply->isRunning());
+ QVERIFY(reply->isFinished());
QList<QVariant> args = spy.last();
QCOMPARE(args.at(0).toInt(), loopCount * data.size());