summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-02-01 13:04:26 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-02-01 13:04:26 (GMT)
commit11d2c8f96697adc93ccd82e3db1de6ecde025eff (patch)
tree9ed5acfa397b093fd726742ae3c478c2f21223bc /src/network/access
parent1b4bb02fcb3da77ddfa6281365ba3210aab9daad (diff)
parentf3da2f414f9fce9aa014da79be9f50c075c60936 (diff)
downloadQt-11d2c8f96697adc93ccd82e3db1de6ecde025eff.zip
Qt-11d2c8f96697adc93ccd82e3db1de6ecde025eff.tar.gz
Qt-11d2c8f96697adc93ccd82e3db1de6ecde025eff.tar.bz2
Merge remote branch 'qt/4.6' into qt-master-from-4.6
Conflicts: src/gui/kernel/qeventdispatcher_mac.mm src/gui/kernel/qt_cocoa_helpers_mac.mm src/gui/widgets/qmenu_mac.mm tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp tools/assistant/tools/assistant/centralwidget.cpp tools/linguist/lupdate/main.cpp
Diffstat (limited to 'src/network/access')
-rw-r--r--src/network/access/qfilenetworkreply.cpp50
-rw-r--r--src/network/access/qfilenetworkreply_p.h7
-rw-r--r--src/network/access/qhttpnetworkheader.cpp2
-rw-r--r--src/network/access/qnetworkaccesshttpbackend.cpp2
-rw-r--r--src/network/access/qnetworkrequest.cpp2
5 files changed, 41 insertions, 22 deletions
diff --git a/src/network/access/qfilenetworkreply.cpp b/src/network/access/qfilenetworkreply.cpp
index 8c5065c..4ac9a8c 100644
--- a/src/network/access/qfilenetworkreply.cpp
+++ b/src/network/access/qfilenetworkreply.cpp
@@ -49,10 +49,15 @@
QT_BEGIN_NAMESPACE
QFileNetworkReplyPrivate::QFileNetworkReplyPrivate()
- : QNetworkReplyPrivate(), realFileSize(0)
+ : QNetworkReplyPrivate(), fileEngine(0), fileSize(0), filePos(0)
{
}
+QFileNetworkReplyPrivate::~QFileNetworkReplyPrivate()
+{
+ delete fileEngine;
+}
+
QFileNetworkReply::~QFileNetworkReply()
{
}
@@ -94,9 +99,8 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
if (fileName.isEmpty()) {
fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
}
- d->realFile.setFileName(fileName);
- QFileInfo fi(d->realFile);
+ QFileInfo fi(fileName);
if (fi.isDir()) {
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString());
setError(QNetworkReply::ContentOperationNotPermittedError, msg);
@@ -106,14 +110,15 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
return;
}
- bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered);
+ d->fileEngine = QAbstractFileEngine::create(fileName);
+ bool opened = d->fileEngine->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
// could we open the file?
if (!opened) {
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2")
- .arg(d->realFile.fileName(), d->realFile.errorString());
+ .arg(fileName, d->fileEngine->errorString());
- if (d->realFile.exists()) {
+ if (fi.exists()) {
setError(QNetworkReply::ContentAccessDenied, msg);
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentAccessDenied));
@@ -126,13 +131,13 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
return;
}
- d->realFileSize = fi.size();
+ d->fileSize = fi.size();
setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified());
- setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize);
+ setHeader(QNetworkRequest::ContentLengthHeader, d->fileSize);
QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,
- Q_ARG(qint64, d->realFileSize), Q_ARG(qint64, d->realFileSize));
+ Q_ARG(qint64, d->fileSize), Q_ARG(qint64, d->fileSize));
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
}
@@ -146,20 +151,25 @@ void QFileNetworkReply::close()
{
Q_D(QFileNetworkReply);
QNetworkReply::close();
- d->realFile.close();
+ if (d->fileEngine)
+ d->fileEngine->close();
}
void QFileNetworkReply::abort()
{
Q_D(QFileNetworkReply);
QNetworkReply::close();
- d->realFile.close();
+ if (d->fileEngine)
+ d->fileEngine->close();
}
qint64 QFileNetworkReply::bytesAvailable() const
{
Q_D(const QFileNetworkReply);
- return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();
+ if (!d->fileEngine)
+ return 0;
+
+ return QNetworkReply::bytesAvailable() + d->fileSize - d->filePos;
}
bool QFileNetworkReply::isSequential () const
@@ -170,7 +180,7 @@ bool QFileNetworkReply::isSequential () const
qint64 QFileNetworkReply::size() const
{
Q_D(const QFileNetworkReply);
- return d->realFileSize;
+ return d->fileSize;
}
/*!
@@ -179,11 +189,17 @@ qint64 QFileNetworkReply::size() const
qint64 QFileNetworkReply::readData(char *data, qint64 maxlen)
{
Q_D(QFileNetworkReply);
- qint64 ret = d->realFile.read(data, maxlen);
- if (ret == 0 && bytesAvailable() == 0)
+ if (!d->fileEngine)
+ return -1;
+
+ qint64 ret = d->fileEngine->read(data, maxlen);
+ if (ret == 0 && bytesAvailable() == 0) {
return -1; // everything had been read
- else
- return ret;
+ } else if (ret > 0) {
+ d->filePos += ret;
+ }
+
+ return ret;
}
diff --git a/src/network/access/qfilenetworkreply_p.h b/src/network/access/qfilenetworkreply_p.h
index 125fa2e..710ec9f 100644
--- a/src/network/access/qfilenetworkreply_p.h
+++ b/src/network/access/qfilenetworkreply_p.h
@@ -57,6 +57,7 @@
#include "qnetworkreply_p.h"
#include "qnetworkaccessmanager.h"
#include <QFile>
+#include <QAbstractFileEngine>
QT_BEGIN_NAMESPACE
@@ -85,9 +86,11 @@ class QFileNetworkReplyPrivate: public QNetworkReplyPrivate
{
public:
QFileNetworkReplyPrivate();
+ ~QFileNetworkReplyPrivate();
- QFile realFile;
- qint64 realFileSize;
+ QAbstractFileEngine *fileEngine;
+ qint64 fileSize;
+ qint64 filePos;
virtual bool isFinished() const;
diff --git a/src/network/access/qhttpnetworkheader.cpp b/src/network/access/qhttpnetworkheader.cpp
index c2cc69c..669f9cf 100644
--- a/src/network/access/qhttpnetworkheader.cpp
+++ b/src/network/access/qhttpnetworkheader.cpp
@@ -80,7 +80,7 @@ QByteArray QHttpNetworkHeaderPrivate::headerField(const QByteArray &name, const
QByteArray result;
bool first = true;
- foreach (QByteArray value, allValues) {
+ foreach (const QByteArray &value, allValues) {
if (!first)
result += ", ";
first = false;
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp
index 519bc95..8e02723 100644
--- a/src/network/access/qnetworkaccesshttpbackend.cpp
+++ b/src/network/access/qnetworkaccesshttpbackend.cpp
@@ -767,7 +767,7 @@ void QNetworkAccessHttpBackend::replyHeaderChanged()
QByteArray value = rawHeader(it->first);
if (!value.isEmpty()) {
if (qstricmp(it->first.constData(), "set-cookie") == 0)
- value += "\n";
+ value += '\n';
else
value += ", ";
}
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 07ff7b4..52b88a3 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -681,7 +681,7 @@ static QVariant parseCookieHeader(const QByteArray &raw)
{
QList<QNetworkCookie> result;
QList<QByteArray> cookieList = raw.split(';');
- foreach (QByteArray cookie, cookieList) {
+ foreach (const QByteArray &cookie, cookieList) {
QList<QNetworkCookie> parsed = QNetworkCookie::parseCookies(cookie.trimmed());
if (parsed.count() != 1)
return QVariant(); // invalid Cookie: header