diff options
author | adjam <adjam@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-05-03 23:51:22 +0000 |
---|---|---|
committer | adjam <adjam@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-05-03 23:51:22 +0000 |
commit | c0190e41f7f2e5fe30fa8556fa35f43950afbfdb (patch) | |
tree | 086794c886f413b3e4dbcfad9d3697a55f8dd64b /src/cookiejar.h | |
parent | Initial rekcommit.. (diff) | |
download | rekonq-c0190e41f7f2e5fe30fa8556fa35f43950afbfdb.tar.xz |
Importing recode (rekonq code).
I'm sorry I coudn't perform this with gitsvn or tailor..
but I cannot lose all the evening just for this.
And I need to sleep now..
git-svn-id: svn+ssh://svn.kde.org/home/kde/trunk/playground/network/rekonq@963146 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/cookiejar.h')
-rw-r--r-- | src/cookiejar.h | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/src/cookiejar.h b/src/cookiejar.h new file mode 100644 index 00000000..27071b6d --- /dev/null +++ b/src/cookiejar.h @@ -0,0 +1,200 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + + +#ifndef COOKIEJAR_H +#define COOKIEJAR_H + + +// KDE Includes +#include <QDialog> + +// Qt Includes +#include <QNetworkCookieJar> +#include <QAbstractItemModel> +#include <QStringList> +#include <QTableView> + +// Forward Declarations +class QSortFilterProxyModel; +class QKeyEvent; +class AutoSaver; + + +class CookieJar : public QNetworkCookieJar +{ + friend class CookieModel; + Q_OBJECT + Q_PROPERTY(AcceptPolicy acceptPolicy READ acceptPolicy WRITE setAcceptPolicy) + Q_PROPERTY(KeepPolicy keepPolicy READ keepPolicy WRITE setKeepPolicy) + Q_PROPERTY(QStringList blockedCookies READ blockedCookies WRITE setBlockedCookies) + Q_PROPERTY(QStringList allowedCookies READ allowedCookies WRITE setAllowedCookies) + Q_PROPERTY(QStringList allowForSessionCookies READ allowForSessionCookies WRITE setAllowForSessionCookies) + Q_ENUMS(KeepPolicy) + Q_ENUMS(AcceptPolicy) + +signals: + void cookiesChanged(); + +public: + enum AcceptPolicy + { + AcceptAlways, + AcceptNever, + AcceptOnlyFromSitesNavigatedTo + }; + + enum KeepPolicy + { + KeepUntilExpire, + KeepUntilExit, + KeepUntilTimeLimit + }; + + CookieJar(QObject *parent = 0); + ~CookieJar(); + + QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const; + bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url); + + AcceptPolicy acceptPolicy() const; + void setAcceptPolicy(AcceptPolicy policy); + + KeepPolicy keepPolicy() const; + void setKeepPolicy(KeepPolicy policy); + + QStringList blockedCookies() const; + QStringList allowedCookies() const; + QStringList allowForSessionCookies() const; + + void setBlockedCookies(const QStringList &list); + void setAllowedCookies(const QStringList &list); + void setAllowForSessionCookies(const QStringList &list); + +public slots: + void clear(); + void loadSettings(); + +private slots: + void save(); + +private: + void purgeOldCookies(); + void load(); + bool m_loaded; + AutoSaver *m_saveTimer; + + AcceptPolicy m_acceptCookies; + KeepPolicy m_keepCookies; + + QStringList m_exceptions_block; + QStringList m_exceptions_allow; + QStringList m_exceptions_allowForSession; +}; + + +// ------------------------------------------------------------------------------------------------------------- + + +class CookieModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + CookieModel(CookieJar *jar, QObject *parent = 0); + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); + +private slots: + void cookiesChanged(); + +private: + CookieJar *m_cookieJar; +}; + + +// ---------------------------------------------------------------------------------------------------------------------- + + +#include "ui_cookies.h" + +class CookiesDialog : public QDialog, public Ui_CookiesDialog +{ + Q_OBJECT + +public: + CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0); + +private: + QSortFilterProxyModel *m_proxyModel; +}; + +class CookieExceptionsModel : public QAbstractTableModel +{ + Q_OBJECT + friend class CookiesExceptionsDialog; + +public: + CookieExceptionsModel(CookieJar *cookieJar, QObject *parent = 0); + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); + +private: + CookieJar *m_cookieJar; + + // Domains we allow, Domains we block, Domains we allow for this session + QStringList m_allowedCookies; + QStringList m_blockedCookies; + QStringList m_sessionCookies; +}; + + +// ----------------------------------------------------------------------------------------------------------------- + + +#include "ui_cookiesexceptions.h" + +class CookiesExceptionsDialog : public QDialog, public Ui_CookiesExceptionsDialog +{ + Q_OBJECT + +public: + CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent = 0); + +private slots: + void block(); + void allow(); + void allowForSession(); + void textChanged(const QString &text); + +private: + CookieExceptionsModel *m_exceptionsModel; + QSortFilterProxyModel *m_proxyModel; + CookieJar *m_cookieJar; +}; + +#endif // COOKIEJAR_H |