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 | |
4 | #ifndef QABSTRACTNETWORKCACHE_H |
5 | #define QABSTRACTNETWORKCACHE_H |
6 | |
7 | #include <QtNetwork/qtnetworkglobal.h> |
8 | #include <QtCore/qobject.h> |
9 | #include <QtCore/qshareddata.h> |
10 | #include <QtCore/qpair.h> |
11 | #include <QtNetwork/qnetworkrequest.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | |
16 | class QIODevice; |
17 | class QDateTime; |
18 | class QUrl; |
19 | |
20 | class QNetworkCacheMetaDataPrivate; |
21 | class Q_NETWORK_EXPORT QNetworkCacheMetaData |
22 | { |
23 | |
24 | public: |
25 | typedef QPair<QByteArray, QByteArray> RawHeader; |
26 | typedef QList<RawHeader> RawHeaderList; |
27 | typedef QHash<QNetworkRequest::Attribute, QVariant> AttributesMap; |
28 | |
29 | QNetworkCacheMetaData(); |
30 | QNetworkCacheMetaData(const QNetworkCacheMetaData &other); |
31 | ~QNetworkCacheMetaData(); |
32 | |
33 | QNetworkCacheMetaData &operator=(QNetworkCacheMetaData &&other) noexcept { swap(other); return *this; } |
34 | QNetworkCacheMetaData &operator=(const QNetworkCacheMetaData &other); |
35 | |
36 | void swap(QNetworkCacheMetaData &other) noexcept |
37 | { d.swap(other&: other.d); } |
38 | |
39 | bool operator==(const QNetworkCacheMetaData &other) const; |
40 | inline bool operator!=(const QNetworkCacheMetaData &other) const |
41 | { return !(*this == other); } |
42 | |
43 | bool isValid() const; |
44 | |
45 | QUrl url() const; |
46 | void setUrl(const QUrl &url); |
47 | |
48 | RawHeaderList rawHeaders() const; |
49 | void setRawHeaders(const RawHeaderList &headers); |
50 | |
51 | QDateTime lastModified() const; |
52 | void setLastModified(const QDateTime &dateTime); |
53 | |
54 | QDateTime expirationDate() const; |
55 | void setExpirationDate(const QDateTime &dateTime); |
56 | |
57 | bool saveToDisk() const; |
58 | void setSaveToDisk(bool allow); |
59 | |
60 | AttributesMap attributes() const; |
61 | void setAttributes(const AttributesMap &attributes); |
62 | |
63 | private: |
64 | friend class QNetworkCacheMetaDataPrivate; |
65 | QSharedDataPointer<QNetworkCacheMetaDataPrivate> d; |
66 | }; |
67 | |
68 | Q_DECLARE_SHARED(QNetworkCacheMetaData) |
69 | |
70 | Q_NETWORK_EXPORT QDataStream &operator<<(QDataStream &, const QNetworkCacheMetaData &); |
71 | Q_NETWORK_EXPORT QDataStream &operator>>(QDataStream &, QNetworkCacheMetaData &); |
72 | |
73 | |
74 | class QAbstractNetworkCachePrivate; |
75 | class Q_NETWORK_EXPORT QAbstractNetworkCache : public QObject |
76 | { |
77 | Q_OBJECT |
78 | |
79 | public: |
80 | virtual ~QAbstractNetworkCache(); |
81 | |
82 | virtual QNetworkCacheMetaData metaData(const QUrl &url) = 0; |
83 | virtual void updateMetaData(const QNetworkCacheMetaData &metaData) = 0; |
84 | virtual QIODevice *data(const QUrl &url) = 0; |
85 | virtual bool remove(const QUrl &url) = 0; |
86 | virtual qint64 cacheSize() const = 0; |
87 | |
88 | virtual QIODevice *prepare(const QNetworkCacheMetaData &metaData) = 0; |
89 | virtual void insert(QIODevice *device) = 0; |
90 | |
91 | public Q_SLOTS: |
92 | virtual void clear() = 0; |
93 | |
94 | protected: |
95 | explicit QAbstractNetworkCache(QObject *parent = nullptr); |
96 | QAbstractNetworkCache(QAbstractNetworkCachePrivate &dd, QObject *parent); |
97 | |
98 | private: |
99 | Q_DECLARE_PRIVATE(QAbstractNetworkCache) |
100 | Q_DISABLE_COPY(QAbstractNetworkCache) |
101 | }; |
102 | |
103 | QT_END_NAMESPACE |
104 | |
105 | #endif |
106 |