author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the demonstration applications of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef COOKIEJAR_H |
|
43 |
#define COOKIEJAR_H |
|
44 |
||
45 |
#include <QtNetwork/QNetworkCookieJar> |
|
46 |
||
47 |
#include <QtCore/QAbstractItemModel> |
|
48 |
#include <QtCore/QStringList> |
|
49 |
||
50 |
#include <QtGui/QDialog> |
|
51 |
#include <QtGui/QTableView> |
|
52 |
||
53 |
QT_BEGIN_NAMESPACE |
|
54 |
class QSortFilterProxyModel; |
|
55 |
class QKeyEvent; |
|
56 |
QT_END_NAMESPACE |
|
57 |
||
58 |
class AutoSaver; |
|
59 |
||
60 |
class CookieJar : public QNetworkCookieJar |
|
61 |
{ |
|
62 |
friend class CookieModel; |
|
63 |
Q_OBJECT |
|
64 |
Q_PROPERTY(AcceptPolicy acceptPolicy READ acceptPolicy WRITE setAcceptPolicy) |
|
65 |
Q_PROPERTY(KeepPolicy keepPolicy READ keepPolicy WRITE setKeepPolicy) |
|
66 |
Q_PROPERTY(QStringList blockedCookies READ blockedCookies WRITE setBlockedCookies) |
|
67 |
Q_PROPERTY(QStringList allowedCookies READ allowedCookies WRITE setAllowedCookies) |
|
68 |
Q_PROPERTY(QStringList allowForSessionCookies READ allowForSessionCookies WRITE setAllowForSessionCookies) |
|
69 |
Q_ENUMS(KeepPolicy) |
|
70 |
Q_ENUMS(AcceptPolicy) |
|
71 |
||
72 |
signals: |
|
73 |
void cookiesChanged(); |
|
74 |
||
75 |
public: |
|
76 |
enum AcceptPolicy { |
|
77 |
AcceptAlways, |
|
78 |
AcceptNever, |
|
79 |
AcceptOnlyFromSitesNavigatedTo |
|
80 |
}; |
|
81 |
||
82 |
enum KeepPolicy { |
|
83 |
KeepUntilExpire, |
|
84 |
KeepUntilExit, |
|
85 |
KeepUntilTimeLimit |
|
86 |
}; |
|
87 |
||
88 |
CookieJar(QObject *parent = 0); |
|
89 |
~CookieJar(); |
|
90 |
||
91 |
QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const; |
|
92 |
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url); |
|
93 |
||
94 |
AcceptPolicy acceptPolicy() const; |
|
95 |
void setAcceptPolicy(AcceptPolicy policy); |
|
96 |
||
97 |
KeepPolicy keepPolicy() const; |
|
98 |
void setKeepPolicy(KeepPolicy policy); |
|
99 |
||
100 |
QStringList blockedCookies() const; |
|
101 |
QStringList allowedCookies() const; |
|
102 |
QStringList allowForSessionCookies() const; |
|
103 |
||
104 |
void setBlockedCookies(const QStringList &list); |
|
105 |
void setAllowedCookies(const QStringList &list); |
|
106 |
void setAllowForSessionCookies(const QStringList &list); |
|
107 |
||
108 |
public slots: |
|
109 |
void clear(); |
|
110 |
void loadSettings(); |
|
111 |
||
112 |
private slots: |
|
113 |
void save(); |
|
114 |
||
115 |
private: |
|
116 |
void purgeOldCookies(); |
|
117 |
void load(); |
|
118 |
bool m_loaded; |
|
119 |
AutoSaver *m_saveTimer; |
|
120 |
||
121 |
AcceptPolicy m_acceptCookies; |
|
122 |
KeepPolicy m_keepCookies; |
|
123 |
||
124 |
QStringList m_exceptions_block; |
|
125 |
QStringList m_exceptions_allow; |
|
126 |
QStringList m_exceptions_allowForSession; |
|
127 |
}; |
|
128 |
||
129 |
class CookieModel : public QAbstractTableModel |
|
130 |
{ |
|
131 |
Q_OBJECT |
|
132 |
||
133 |
public: |
|
134 |
CookieModel(CookieJar *jar, QObject *parent = 0); |
|
135 |
QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
|
136 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
137 |
int columnCount(const QModelIndex &parent = QModelIndex()) const; |
|
138 |
int rowCount(const QModelIndex &parent = QModelIndex()) const; |
|
139 |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
140 |
||
141 |
private slots: |
|
142 |
void cookiesChanged(); |
|
143 |
||
144 |
private: |
|
145 |
CookieJar *m_cookieJar; |
|
146 |
}; |
|
147 |
||
148 |
#include "ui_cookies.h" |
|
149 |
#include "ui_cookiesexceptions.h" |
|
150 |
||
151 |
class CookiesDialog : public QDialog, public Ui_CookiesDialog |
|
152 |
{ |
|
153 |
Q_OBJECT |
|
154 |
||
155 |
public: |
|
156 |
CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0); |
|
157 |
||
158 |
private: |
|
159 |
QSortFilterProxyModel *m_proxyModel; |
|
160 |
}; |
|
161 |
||
162 |
class CookieExceptionsModel : public QAbstractTableModel |
|
163 |
{ |
|
164 |
Q_OBJECT |
|
165 |
friend class CookiesExceptionsDialog; |
|
166 |
||
167 |
public: |
|
168 |
CookieExceptionsModel(CookieJar *cookieJar, QObject *parent = 0); |
|
169 |
QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
|
170 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
171 |
int columnCount(const QModelIndex &parent = QModelIndex()) const; |
|
172 |
int rowCount(const QModelIndex &parent = QModelIndex()) const; |
|
173 |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
174 |
||
175 |
private: |
|
176 |
CookieJar *m_cookieJar; |
|
177 |
||
178 |
// Domains we allow, Domains we block, Domains we allow for this session |
|
179 |
QStringList m_allowedCookies; |
|
180 |
QStringList m_blockedCookies; |
|
181 |
QStringList m_sessionCookies; |
|
182 |
}; |
|
183 |
||
184 |
class CookiesExceptionsDialog : public QDialog, public Ui_CookiesExceptionsDialog |
|
185 |
{ |
|
186 |
Q_OBJECT |
|
187 |
||
188 |
public: |
|
189 |
CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent = 0); |
|
190 |
||
191 |
private slots: |
|
192 |
void block(); |
|
193 |
void allow(); |
|
194 |
void allowForSession(); |
|
195 |
void textChanged(const QString &text); |
|
196 |
||
197 |
private: |
|
198 |
CookieExceptionsModel *m_exceptionsModel; |
|
199 |
QSortFilterProxyModel *m_proxyModel; |
|
200 |
CookieJar *m_cookieJar; |
|
201 |
}; |
|
202 |
||
203 |
#endif // COOKIEJAR_H |
|
204 |