Qt 4.8
qnetworkreplydataimpl.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
43 #include "private/qdataurl_p.h"
44 #include <QtCore/QCoreApplication>
45 #include <QtCore/QMetaObject>
46 
48 
51 {
52 }
53 
55 {
56 }
57 
59 {
60 }
61 
64 {
66  setRequest(req);
67  setUrl(req.url());
68  setOperation(op);
69  setFinished(true);
71 
72  QUrl url = req.url();
73 
74  // FIXME qDecodeDataUrl should instead be rewritten to have the QByteArray
75  // and the mime type as an output parameter and return a bool instead
76  d->decodeDataUrlResult = qDecodeDataUrl(url);
77 
78  if (! d->decodeDataUrlResult.first.isNull()) {
79  QString &mimeType = d->decodeDataUrlResult.first;
80  qint64 size = d->decodeDataUrlResult.second.size();
83  QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);
84 
85  d->decodedData.setBuffer(&d->decodeDataUrlResult.second);
86  d->decodedData.open(QIODevice::ReadOnly);
87 
88  QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,
89  Q_ARG(qint64,size), Q_ARG(qint64, size));
92  } else {
93  // something wrong with this URI
94  const QString msg = QCoreApplication::translate("QNetworkAccessDataBackend",
95  "Invalid URI: %1").arg(QString::fromLatin1(url.toEncoded()));
100  }
101 }
102 
104 {
106 }
107 
109 {
111 }
112 
114 {
115  Q_D(const QNetworkReplyDataImpl);
116  return QNetworkReply::bytesAvailable() + d->decodedData.bytesAvailable();
117 }
118 
120 {
121  return true;
122 }
123 
125 {
126  Q_D(const QNetworkReplyDataImpl);
127  return d->decodedData.size();
128 }
129 
134 {
136 
137  // TODO idea:
138  // Instead of decoding the whole data into new memory, we could decode on demand.
139  // Note that this might be tricky to do.
140 
141  return d->decodedData.read(data, maxlen);
142 }
143 
144 
146 
147 #include "moc_qnetworkreplydataimpl_p.cpp"
148 
double d
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setUrl(const QUrl &url)
Sets the URL being processed to be url.
void setError(NetworkError errorCode, const QString &errorString)
Sets the error condition to be errorCode.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
qint64 size() const
For open random-access devices, this function returns the size of the device.
Operation
Indicates the operation this reply is processing.
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
QUrl url() const
Returns the URL this network request is referring to.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
void setOperation(QNetworkAccessManager::Operation operation)
Sets the associated operation for this object to be operation.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void close()
Closes this device for reading.
static const char * data(const QByteArray &arr)
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
Sets the known header header to be of value value.
virtual void close()
Closes this device for reading.
__int64 qint64
Definition: qglobal.h:942
void setRequest(const QNetworkRequest &request)
Sets the associated request for this object to be request.
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
virtual bool isSequential() const
QNetworkReplyDataImpl(QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
virtual void abort()
Aborts the operation immediately and close down any network connections still open.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void setFinished(bool)
Sets the reply as finished.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QObject * parent
Definition: qobject.h:92
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
virtual qint64 readData(char *data, qint64 maxlen)
QUrl url() const
Returns the URL of the content downloaded or uploaded.
Q_CORE_EXPORT QPair< QString, QByteArray > qDecodeDataUrl(const QUrl &uri)
Decode a data: URL into its mimetype and payload.
Definition: qdataurl.cpp:57