Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qabstractnetworkcache.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <qdatastream.h>
8#include <qdatetime.h>
9#include <qurl.h>
10#include <qhash.h>
11
12#include <qdebug.h>
13
15
17{
18
19public:
21 : QSharedData()
22 , saveToDisk(true)
23 {}
24
26 {
27 return
28 url == other.url
29 && lastModified == other.lastModified
30 && expirationDate == other.expirationDate
31 && headers == other.headers
32 && saveToDisk == other.saveToDisk;
33 }
34
41
42 static void save(QDataStream &out, const QNetworkCacheMetaData &metaData);
43 static void load(QDataStream &in, QNetworkCacheMetaData &metaData);
44};
45Q_GLOBAL_STATIC(QNetworkCacheMetaDataPrivate, metadata_shared_invalid)
46
47
87{
88}
89
94{
95 // QSharedDataPointer takes care of freeing d
96}
97
102 : d(other.d)
103{
104}
105
110{
111 d = other.d;
112 return *this;
113}
114
129{
130 if (d == other.d)
131 return true;
132 if (d && other.d)
133 return *d == *other.d;
134 return false;
135}
136
149{
150 return !(*d == *metadata_shared_invalid());
151}
152
166{
167 return d->saveToDisk;
168}
169
177{
178 d->saveToDisk = allow;
179}
180
187{
188 return d->url;
189}
190
199{
200 auto *p = d.data();
201 p->url = url;
202 p->url.setPassword(QString());
203 p->url.setFragment(QString());
204}
205
213{
214 return d->headers;
215}
216
223{
224 d->headers = list;
225}
226
231{
232 return d->lastModified;
233}
234
239{
241}
242
247{
248 return d->expirationDate;
249}
250
255{
257}
258
267{
268 return d->attributes;
269}
270
279{
281}
282
292{
294 return out;
295}
296
298{
299 out << quint32(hash.size());
302 while (it != end) {
303 out << int(it.key()) << it.value();
304 ++it;
305 }
306 return out;
307}
308
310{
311 // note: if you change the contents of the meta data here
312 // remember to bump the cache version in qnetworkdiskcache.cpp CurrentCacheVersion
313 out << metaData.url();
314 out << metaData.expirationDate();
315 out << metaData.lastModified();
316 out << metaData.saveToDisk();
317 out << metaData.attributes();
318 out << metaData.rawHeaders();
319}
320
330{
332 return in;
333}
334
336{
337 hash.clear();
338 QDataStream::Status oldStatus = in.status();
339 in.resetStatus();
340 hash.clear();
341
342 quint32 n;
343 in >> n;
344
345 for (quint32 i = 0; i < n; ++i) {
346 if (in.status() != QDataStream::Ok)
347 break;
348
349 int k;
350 QVariant t;
351 in >> k >> t;
353 }
354
355 if (in.status() != QDataStream::Ok)
356 hash.clear();
357 if (oldStatus != QDataStream::Ok)
358 in.setStatus(oldStatus);
359 return in;
360}
361
363{
364 auto *p = metaData.d.data();
365 in >> p->url;
366 in >> p->expirationDate;
367 in >> p->lastModified;
368 in >> p->saveToDisk;
369 in >> p->attributes;
370 in >> p->headers;
371}
372
392{
393}
394
399 : QObject(dd, parent)
400{
401}
402
411{
412}
413
512
513#include "moc_qabstractnetworkcache.cpp"
virtual ~QAbstractNetworkCache()
Destroys the cache.
QAbstractNetworkCache(QObject *parent=nullptr)
Constructs an abstract network cache with the given parent.
\inmodule QtCore\reentrant
Definition qdatastream.h:30
Status
This enum describes the current status of the data stream.
Definition qdatastream.h:84
\inmodule QtCore\reentrant
Definition qdatetime.h:257
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition qhash.h:1256
static void save(QDataStream &out, const QNetworkCacheMetaData &metaData)
QNetworkCacheMetaData::RawHeaderList headers
bool operator==(const QNetworkCacheMetaDataPrivate &other) const
QNetworkCacheMetaData::AttributesMap attributes
static void load(QDataStream &in, QNetworkCacheMetaData &metaData)
The QNetworkCacheMetaData class provides cache information.
bool saveToDisk() const
Returns is this cache should be allowed to be stored on disk.
QDataStream & operator>>(QDataStream &in, QNetworkCacheMetaData &metaData)
void setUrl(const QUrl &url)
Sets the URL this network cache meta data to be url.
void setSaveToDisk(bool allow)
Sets whether this network cache meta data and associated content should be allowed to be stored on di...
void setRawHeaders(const RawHeaderList &headers)
Sets the raw headers to list.
void setExpirationDate(const QDateTime &dateTime)
Sets the date and time when the meta data expires to dateTime.
bool isValid() const
Returns true if this network cache meta data has attributes that have been set otherwise false.
bool operator==(const QNetworkCacheMetaData &other) const
Returns true if this meta data is equal to the other meta data; otherwise returns false.
QUrl url() const
Returns the URL this network cache meta data is referring to.
AttributesMap attributes() const
RawHeaderList rawHeaders() const
Returns a list of all raw headers that are set in this meta data.
void setLastModified(const QDateTime &dateTime)
Sets the date and time when the meta data was last modified to dateTime.
QDateTime lastModified() const
Returns the date and time when the meta data was last modified.
QNetworkCacheMetaData & operator=(QNetworkCacheMetaData &&other) noexcept
QNetworkCacheMetaData()
Constructs an invalid network cache meta data.
QDataStream & operator<<(QDataStream &out, const QNetworkCacheMetaData &metaData)
QDateTime expirationDate() const
Returns the date and time when the meta data expires.
~QNetworkCacheMetaData()
Destroys the network cache meta data.
void setAttributes(const AttributesMap &attributes)
\inmodule QtCore
Definition qobject.h:90
T * data()
Returns a pointer to the shared data object.
Definition qshareddata.h:47
\inmodule QtCore
Definition qshareddata.h:19
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qurl.h:94
QString url(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2814
\inmodule QtCore
Definition qvariant.h:64
QHash< int, QWidget * > hash
[35multi]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static QDataStream & operator<<(QDataStream &out, const QNetworkCacheMetaData::AttributesMap &hash)
static QDataStream & operator>>(QDataStream &in, QNetworkCacheMetaData::AttributesMap &hash)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLuint GLuint end
GLfloat n
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint in
GLfloat GLfloat p
[1]
unsigned int quint32
Definition qtypes.h:45
QList< int > list
[14]
QTextStream out(stdout)
[7]
QUrl url("example.com")
[constructor-url-reference]
QDateTime dateTime
[12]
QSharedPointer< T > other(t)
[5]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent