1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Qt Software Information (qt-info@nokia.com)
6 ** This file is part of the demonstration applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
10 ** This file contains pre-release code and may not be distributed.
11 ** You may use this file in accordance with the terms and conditions
12 ** contained in the either Technology Preview License Agreement or the
13 ** Beta Release License Agreement.
15 ** GNU Lesser General Public License Usage
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** General Public License version 2.1 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** packaging of this file. Please review the following information to
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 ** In addition, as a special exception, Nokia gives you certain
24 ** additional rights. These rights are described in the Nokia Qt LGPL
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ** If you are unsure which license is appropriate for your use, please
37 ** contact the sales department at qt-sales@nokia.com.
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