1/****************************************************************************
2**
3** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/
5**
6** This file is part of the QtNetwork module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** GNU Lesser General Public License Usage
10** This file may be used under the terms of the GNU Lesser General Public
11** License version 2.1 as published by the Free Software Foundation and
12** appearing in the file LICENSE.LGPL included in the packaging of this
13** file. Please review the following information to ensure the GNU Lesser
14** General Public License version 2.1 requirements will be met:
15** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16**
17** In addition, as a special exception, Nokia gives you certain additional
18** rights. These rights are described in the Nokia Qt LGPL Exception
19** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20**
21** GNU General Public License Usage
22** Alternatively, this file may be used under the terms of the GNU General
23** Public License version 3.0 as published by the Free Software Foundation
24** and appearing in the file LICENSE.GPL included in the packaging of this
25** file. Please review the following information to ensure the GNU General
26** Public License version 3.0 requirements will be met:
27** http://www.gnu.org/copyleft/gpl.html.
28**
29** Other Usage
30** Alternatively, this file may be used in accordance with the terms and
31** conditions contained in a signed written agreement between you and Nokia.
32**
33**
34**
35**
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QABSTRACTNETWORKCACHE_H
43#define QABSTRACTNETWORKCACHE_H
44
45#include <QtCore/qobject.h>
46#include <QtCore/qshareddata.h>
47#include <QtCore/qpair.h>
48#include <QtNetwork/qnetworkrequest.h>
49
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(Network)
55
56class QIODevice;
57class QDateTime;
58class QUrl;
59template<class T> class QList;
60
61class QNetworkCacheMetaDataPrivate;
62class Q_NETWORK_EXPORT QNetworkCacheMetaData
63{
64
65public:
66 typedef QPair<QByteArray, QByteArray> RawHeader;
67 typedef QList<RawHeader> RawHeaderList;
68 typedef QHash<QNetworkRequest::Attribute, QVariant> AttributesMap;
69
70 QNetworkCacheMetaData();
71 QNetworkCacheMetaData(const QNetworkCacheMetaData &other);
72 ~QNetworkCacheMetaData();
73
74 QNetworkCacheMetaData &operator=(const QNetworkCacheMetaData &other);
75 bool operator==(const QNetworkCacheMetaData &other) const;
76 inline bool operator!=(const QNetworkCacheMetaData &other) const
77 { return !(*this == other); }
78
79 bool isValid() const;
80
81 QUrl url() const;
82 void setUrl(const QUrl &url);
83
84 RawHeaderList rawHeaders() const;
85 void setRawHeaders(const RawHeaderList &headers);
86
87 QDateTime lastModified() const;
88 void setLastModified(const QDateTime &dateTime);
89
90 QDateTime expirationDate() const;
91 void setExpirationDate(const QDateTime &dateTime);
92
93 bool saveToDisk() const;
94 void setSaveToDisk(bool allow);
95
96 AttributesMap attributes() const;
97 void setAttributes(const AttributesMap &attributes);
98
99private:
100 friend class QNetworkCacheMetaDataPrivate;
101 QSharedDataPointer<QNetworkCacheMetaDataPrivate> d;
102};
103
104Q_NETWORK_EXPORT QDataStream &operator<<(QDataStream &, const QNetworkCacheMetaData &);
105Q_NETWORK_EXPORT QDataStream &operator>>(QDataStream &, QNetworkCacheMetaData &);
106
107
108class QAbstractNetworkCachePrivate;
109class Q_NETWORK_EXPORT QAbstractNetworkCache : public QObject
110{
111 Q_OBJECT
112
113public:
114 virtual ~QAbstractNetworkCache();
115
116 virtual QNetworkCacheMetaData metaData(const QUrl &url) = 0;
117 virtual void updateMetaData(const QNetworkCacheMetaData &metaData) = 0;
118 virtual QIODevice *data(const QUrl &url) = 0;
119 virtual bool remove(const QUrl &url) = 0;
120 virtual qint64 cacheSize() const = 0;
121
122 virtual QIODevice *prepare(const QNetworkCacheMetaData &metaData) = 0;
123 virtual void insert(QIODevice *device) = 0;
124
125public Q_SLOTS:
126 virtual void clear() = 0;
127
128protected:
129 explicit QAbstractNetworkCache(QObject *parent = 0);
130 QAbstractNetworkCache(QAbstractNetworkCachePrivate &dd, QObject *parent);
131
132private:
133 Q_DECLARE_PRIVATE(QAbstractNetworkCache)
134 Q_DISABLE_COPY(QAbstractNetworkCache)
135};
136
137QT_END_NAMESPACE
138
139QT_END_HEADER
140
141#endif
142