1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the demonstration applications of the Qt Toolkit.
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
45 #include <QtNetwork/QNetworkCookieJar>
47 #include <QtCore/QAbstractItemModel>
48 #include <QtCore/QStringList>
50 #include <QtGui/QDialog>
51 #include <QtGui/QTableView>
54 class QSortFilterProxyModel;
60 class CookieJar : public QNetworkCookieJar
62 friend class CookieModel;
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)
73 void cookiesChanged();
79 AcceptOnlyFromSitesNavigatedTo
88 CookieJar(QObject *parent = 0);
91 QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const;
92 bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
94 AcceptPolicy acceptPolicy() const;
95 void setAcceptPolicy(AcceptPolicy policy);
97 KeepPolicy keepPolicy() const;
98 void setKeepPolicy(KeepPolicy policy);
100 QStringList blockedCookies() const;
101 QStringList allowedCookies() const;
102 QStringList allowForSessionCookies() const;
104 void setBlockedCookies(const QStringList &list);
105 void setAllowedCookies(const QStringList &list);
106 void setAllowForSessionCookies(const QStringList &list);
116 void purgeOldCookies();
119 AutoSaver *m_saveTimer;
121 AcceptPolicy m_acceptCookies;
122 KeepPolicy m_keepCookies;
124 QStringList m_exceptions_block;
125 QStringList m_exceptions_allow;
126 QStringList m_exceptions_allowForSession;
129 class CookieModel : public QAbstractTableModel
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());
142 void cookiesChanged();
145 CookieJar *m_cookieJar;
148 #include "ui_cookies.h"
149 #include "ui_cookiesexceptions.h"
151 class CookiesDialog : public QDialog, public Ui_CookiesDialog
156 CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0);
159 QSortFilterProxyModel *m_proxyModel;
162 class CookieExceptionsModel : public QAbstractTableModel
165 friend class CookiesExceptionsDialog;
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());
176 CookieJar *m_cookieJar;
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;
184 class CookiesExceptionsDialog : public QDialog, public Ui_CookiesExceptionsDialog
189 CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent = 0);
194 void allowForSession();
195 void textChanged(const QString &text);
198 CookieExceptionsModel *m_exceptionsModel;
199 QSortFilterProxyModel *m_proxyModel;
200 CookieJar *m_cookieJar;
203 #endif // COOKIEJAR_H