summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-05-19 12:29:32 +0200
committerAndrea Diamantini <adjam7@gmail.com>2009-06-03 00:04:20 +0200
commitd0ecd4c042b81f0eb732a6702f9d1a83d6f4144e (patch)
tree78ff281bcfd44d72e651ebd3dc6ded39193ca2ec /src
parentremoved unuseful comments (diff)
downloadrekonq-d0ecd4c042b81f0eb732a6702f9d1a83d6f4144e.tar.xz
Cookie System Refactoring. Step 1..
Diffstat (limited to 'src')
-rw-r--r--src/cookiedialog.cpp218
-rw-r--r--src/cookiedialog.h (renamed from src/cookiedialogs.h)41
-rw-r--r--src/cookieexcaptiondialog.cpp (renamed from src/cookiedialogs.cpp)180
-rw-r--r--src/cookieexcaptiondialog.h89
-rw-r--r--src/cookiejar.cpp271
-rw-r--r--src/cookiejar.h61
6 files changed, 455 insertions, 405 deletions
diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp
new file mode 100644
index 00000000..1628a0c6
--- /dev/null
+++ b/src/cookiedialog.cpp
@@ -0,0 +1,218 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot 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.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "cookiedialog.h"
+#include "cookiedialog.moc"
+
+// Local Includes
+#include "cookiejar.h"
+
+
+CookieModel::CookieModel(CookieJar *cookieJar, QObject *parent)
+ : QAbstractTableModel(parent)
+ , m_cookieJar(cookieJar)
+{
+ connect(m_cookieJar, SIGNAL(cookiesChanged()), this, SLOT(cookiesChanged()));
+ m_cookieJar->load();
+}
+
+
+QVariant CookieModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::SizeHintRole)
+ {
+ QFont font;
+ font.setPointSize(10);
+ QFontMetrics fm(font);
+ int height = fm.height() + fm.height() / 3;
+ int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString());
+ return QSize(width, height);
+ }
+
+ if (orientation == Qt::Horizontal)
+ {
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ switch (section)
+ {
+ case 0:
+ return i18n("Website");
+ case 1:
+ return i18n("Name");
+ case 2:
+ return i18n("Path");
+ case 3:
+ return i18n("Secure");
+ case 4:
+ return i18n("Expires");
+ case 5:
+ return i18n("Contents");
+ default:
+ return QVariant();
+ }
+ }
+ return QAbstractTableModel::headerData(section, orientation, role);
+}
+
+
+QVariant CookieModel::data(const QModelIndex &index, int role) const
+{
+ QList<QNetworkCookie> lst;
+ if (m_cookieJar)
+ lst = m_cookieJar->allCookies();
+ if (index.row() < 0 || index.row() >= lst.size())
+ return QVariant();
+
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ case Qt::EditRole:
+ {
+ QNetworkCookie cookie = lst.at(index.row());
+ switch (index.column())
+ {
+ case 0:
+ return cookie.domain();
+ case 1:
+ return cookie.name();
+ case 2:
+ return cookie.path();
+ case 3:
+ return cookie.isSecure();
+ case 4:
+ return cookie.expirationDate();
+ case 5:
+ return cookie.value();
+ }
+ }
+ case Qt::FontRole:
+ {
+ QFont font;
+ font.setPointSize(10);
+ return font;
+ }
+ }
+
+ return QVariant();
+}
+
+
+int CookieModel::columnCount(const QModelIndex &parent) const
+{
+ return (parent.isValid()) ? 0 : 6;
+}
+
+
+int CookieModel::rowCount(const QModelIndex &parent) const
+{
+ return (parent.isValid() || !m_cookieJar) ? 0 : m_cookieJar->allCookies().count();
+}
+
+
+bool CookieModel::removeRows(int row, int count, const QModelIndex &parent)
+{
+ if (parent.isValid() || !m_cookieJar)
+ return false;
+ int lastRow = row + count - 1;
+ beginRemoveRows(parent, row, lastRow);
+ QList<QNetworkCookie> lst = m_cookieJar->allCookies();
+ for (int i = lastRow; i >= row; --i)
+ {
+ lst.removeAt(i);
+ }
+ m_cookieJar->setAllCookies(lst);
+ endRemoveRows();
+ return true;
+}
+
+
+void CookieModel::cookiesChanged()
+{
+ reset();
+}
+
+
+// ---------------------------------------------------------------------------------------
+
+
+// Ui Includes
+#include "ui_cookies.h"
+
+
+CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent)
+ : KDialog(parent)
+{
+ setWindowFlags(Qt::Sheet);
+ setCaption("Cookies");
+ setButtons( KDialog::Ok );
+
+ Ui::CookiesWidget *cookieWidget = new Ui::CookiesWidget;
+ QWidget *widget = new QWidget(this);
+ cookieWidget->setupUi(widget);
+ setMainWidget(widget);
+
+ CookieModel *model = new CookieModel(cookieJar, this);
+ m_proxyModel = new QSortFilterProxyModel(this);
+
+ // connecting signals and slots
+ connect(cookieWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString)));
+ connect(cookieWidget->removeButton, SIGNAL(clicked()), cookieWidget->cookiesTable, SLOT(removeOne()));
+ connect(cookieWidget->removeAllButton, SIGNAL(clicked()), cookieWidget->cookiesTable, SLOT(removeAll()));
+
+ m_proxyModel->setSourceModel(model);
+
+ cookieWidget->cookiesTable->verticalHeader()->hide();
+ cookieWidget->cookiesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+ cookieWidget->cookiesTable->setModel(m_proxyModel);
+ cookieWidget->cookiesTable->setAlternatingRowColors(true);
+ cookieWidget->cookiesTable->setTextElideMode(Qt::ElideMiddle);
+ cookieWidget->cookiesTable->setShowGrid(false);
+ cookieWidget->cookiesTable->setSortingEnabled(true);
+
+ QFont f = font();
+ f.setPointSize(10);
+ QFontMetrics fm(f);
+ int height = fm.height() + fm.height() / 3;
+ cookieWidget->cookiesTable->verticalHeader()->setDefaultSectionSize(height);
+ cookieWidget->cookiesTable->verticalHeader()->setMinimumSectionSize(-1);
+
+ for (int i = 0; i < model->columnCount(); ++i)
+ {
+ int header = cookieWidget->cookiesTable->horizontalHeader()->sectionSizeHint(i);
+ switch (i)
+ {
+ case 0:
+ header = fm.width(QLatin1String("averagehost.domain.com"));
+ break;
+ case 1:
+ header = fm.width(QLatin1String("_session_id"));
+ break;
+ case 4:
+ header = fm.width(QDateTime::currentDateTime().toString(Qt::LocalDate));
+ break;
+ }
+ int buffer = fm.width(QLatin1String("xx"));
+ header += buffer;
+ cookieWidget->cookiesTable->horizontalHeader()->resizeSection(i, header);
+ }
+ cookieWidget->cookiesTable->horizontalHeader()->setStretchLastSection(true);
+}
diff --git a/src/cookiedialogs.h b/src/cookiedialog.h
index 4331ae83..be8b9236 100644
--- a/src/cookiedialogs.h
+++ b/src/cookiedialog.h
@@ -19,13 +19,14 @@
-#ifndef COOKIEDIALOGS_H
-#define COOKIEDIALOGS_H
+#ifndef COOKIEDIALOG_H
+#define COOKIEDIALOG_H
// KDE Includes
#include <KDialog>
+
// Qt Includes
#include <QtCore/QStringList>
#include <QtCore/QAbstractItemModel>
@@ -35,50 +36,46 @@
#include <QtNetwork/QNetworkCookieJar>
+
// Forward Declarations
class CookieJar;
class CookieExceptionsModel;
-class CookiesDialog : public KDialog
+class CookieModel : public QAbstractTableModel
{
Q_OBJECT
public:
- explicit CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0);
+ explicit 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:
- QSortFilterProxyModel *m_proxyModel;
+ CookieJar *m_cookieJar;
};
-// -----------------------------------------------------------------------------------------------------------------
-
-// Ui Includes
-#include "ui_cookiesexceptions.h"
+// -----------------------------------------------------------------------------------------------------------------
-class CookiesExceptionsDialog : public KDialog
+class CookiesDialog : public KDialog
{
Q_OBJECT
public:
- explicit CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent = 0);
-
-private slots:
- void block();
- void allow();
- void allowForSession();
- void textChanged(const QString &text);
+ explicit CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0);
private:
- CookieExceptionsModel *m_exceptionsModel;
QSortFilterProxyModel *m_proxyModel;
- CookieJar *m_cookieJar;
-
- Ui::CookiesExceptionsWidget *m_exceptionsWidget;
};
-
#endif
diff --git a/src/cookiedialogs.cpp b/src/cookieexcaptiondialog.cpp
index 1d120666..c349c885 100644
--- a/src/cookiedialogs.cpp
+++ b/src/cookieexcaptiondialog.cpp
@@ -19,77 +19,154 @@
// Self Includes
-#include "cookiedialogs.h"
-#include "cookiedialogs.moc"
-
-// Ui Includes
-#include "ui_cookies.h"
+#include "cookieexceptiondialog.h"
+#include "cookieexceptiondialog.moc"
// Local Includes
-#include "cookiejar.h"
-CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent)
- : KDialog(parent)
+
+CookieExceptionsModel::CookieExceptionsModel(CookieJar *cookiejar, QObject *parent)
+ : QAbstractTableModel(parent)
+ , m_cookieJar(cookiejar)
{
- setCaption("Cookies");
- setButtons( KDialog::Ok );
+ m_allowedCookies = m_cookieJar->allowedCookies();
+ m_blockedCookies = m_cookieJar->blockedCookies();
+ m_sessionCookies = m_cookieJar->allowForSessionCookies();
+}
- Ui::CookiesWidget *cookieWidget = new Ui::CookiesWidget;
- QWidget *widget = new QWidget(this);
- cookieWidget->setupUi(widget);
- setMainWidget(widget);
- setWindowFlags(Qt::Sheet);
+QVariant CookieExceptionsModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::SizeHintRole)
+ {
+ QFont font;
+ font.setPointSize(10);
+ QFontMetrics fm(font);
+ int height = fm.height() + fm.height() / 3;
+ int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString());
+ return QSize(width, height);
+ }
- CookieModel *model = new CookieModel(cookieJar, this);
- m_proxyModel = new QSortFilterProxyModel(this);
+ if (orientation == Qt::Horizontal
+ && role == Qt::DisplayRole)
+ {
+ switch (section)
+ {
+ case 0:
+ return i18n("Website");
+ case 1:
+ return i18n("Status");
+ }
+ }
+ return QAbstractTableModel::headerData(section, orientation, role);
+}
+
+
+QVariant CookieExceptionsModel::data(const QModelIndex &index, int role) const
+{
+ if (index.row() < 0 || index.row() >= rowCount())
+ return QVariant();
+
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ case Qt::EditRole:
+ {
+ int row = index.row();
+ if (row < m_allowedCookies.count())
+ {
+ switch (index.column())
+ {
+ case 0:
+ return m_allowedCookies.at(row);
+ case 1:
+ return i18n("Allow");
+ }
+ }
+ row = row - m_allowedCookies.count();
+ if (row < m_blockedCookies.count())
+ {
+ switch (index.column())
+ {
+ case 0:
+ return m_blockedCookies.at(row);
+ case 1:
+ return i18n("Block");
+ }
+ }
+ row = row - m_blockedCookies.count();
+ if (row < m_sessionCookies.count())
+ {
+ switch (index.column())
+ {
+ case 0:
+ return m_sessionCookies.at(row);
+ case 1:
+ return i18n("Allow For Session");
+ }
+ }
+ }
+ case Qt::FontRole:
+ {
+ QFont font;
+ font.setPointSize(10);
+ return font;
+ }
+ }
+ return QVariant();
+}
- // connecting signals and slots
- connect(cookieWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString)));
- connect(cookieWidget->removeButton, SIGNAL(clicked()), cookieWidget->cookiesTable, SLOT(removeOne()));
- connect(cookieWidget->removeAllButton, SIGNAL(clicked()), cookieWidget->cookiesTable, SLOT(removeAll()));
- m_proxyModel->setSourceModel(model);
+int CookieExceptionsModel::columnCount(const QModelIndex &parent) const
+{
+ return (parent.isValid()) ? 0 : 2;
+}
- cookieWidget->cookiesTable->verticalHeader()->hide();
- cookieWidget->cookiesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
- cookieWidget->cookiesTable->setModel(m_proxyModel);
- cookieWidget->cookiesTable->setAlternatingRowColors(true);
- cookieWidget->cookiesTable->setTextElideMode(Qt::ElideMiddle);
- cookieWidget->cookiesTable->setShowGrid(false);
- cookieWidget->cookiesTable->setSortingEnabled(true);
- QFont f = font();
- f.setPointSize(10);
- QFontMetrics fm(f);
- int height = fm.height() + fm.height() / 3;
- cookieWidget->cookiesTable->verticalHeader()->setDefaultSectionSize(height);
- cookieWidget->cookiesTable->verticalHeader()->setMinimumSectionSize(-1);
+int CookieExceptionsModel::rowCount(const QModelIndex &parent) const
+{
+ return (parent.isValid() || !m_cookieJar) ? 0 : m_allowedCookies.count() + m_blockedCookies.count() + m_sessionCookies.count();
+}
+
+
+bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &parent)
+{
+ if (parent.isValid() || !m_cookieJar)
+ return false;
- for (int i = 0; i < model->columnCount(); ++i)
+ int lastRow = row + count - 1;
+ beginRemoveRows(parent, row, lastRow);
+ for (int i = lastRow; i >= row; --i)
{
- int header = cookieWidget->cookiesTable->horizontalHeader()->sectionSizeHint(i);
- switch (i)
+ if (i < m_allowedCookies.count())
{
- case 0:
- header = fm.width(QLatin1String("averagehost.domain.com"));
- break;
- case 1:
- header = fm.width(QLatin1String("_session_id"));
- break;
- case 4:
- header = fm.width(QDateTime::currentDateTime().toString(Qt::LocalDate));
- break;
+ m_allowedCookies.removeAt(row);
+ continue;
+ }
+ i = i - m_allowedCookies.count();
+ if (i < m_blockedCookies.count())
+ {
+ m_blockedCookies.removeAt(row);
+ continue;
+ }
+ i = i - m_blockedCookies.count();
+ if (i < m_sessionCookies.count())
+ {
+ m_sessionCookies.removeAt(row);
+ continue;
}
- int buffer = fm.width(QLatin1String("xx"));
- header += buffer;
- cookieWidget->cookiesTable->horizontalHeader()->resizeSection(i, header);
}
- cookieWidget->cookiesTable->horizontalHeader()->setStretchLastSection(true);
+ m_cookieJar->setAllowedCookies(m_allowedCookies);
+ m_cookieJar->setBlockedCookies(m_blockedCookies);
+ m_cookieJar->setAllowForSessionCookies(m_sessionCookies);
+ endRemoveRows();
+ return true;
}
+
+
// ----------------------------------------------------------------------------------------------------------------
@@ -191,3 +268,4 @@ void CookiesExceptionsDialog::allowForSession()
m_cookieJar->setAllowForSessionCookies(m_exceptionsModel->m_sessionCookies);
m_exceptionsModel->reset();
}
+
diff --git a/src/cookieexcaptiondialog.h b/src/cookieexcaptiondialog.h
new file mode 100644
index 00000000..f68c119e
--- /dev/null
+++ b/src/cookieexcaptiondialog.h
@@ -0,0 +1,89 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot 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 COOKIEEXCEPTIONDIALOG_H
+#define COOKIEEXCEPTIONDIALOG_H
+
+// Qt Includes
+#include <QtGui/QAbstractTableModel>
+
+// Forward Declarations
+class CookieJar;
+class QString;
+class QStringList;
+class QModelIndex;
+class QVariant;
+
+class CookieExceptionsModel : public QAbstractTableModel
+{
+ Q_OBJECT
+ friend class CookiesExceptionsDialog;
+
+public:
+ explicit 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;
+};
+
+
+// -----------------------------------------------------------------------------------------------
+
+
+// Ui Includes
+#include "ui_cookiesexceptions.h"
+
+//Forward Declarations
+class QSortFilterProxyModel;
+
+
+class CookiesExceptionsDialog : public KDialog
+{
+ Q_OBJECT
+
+public:
+ explicit 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;
+
+ Ui::CookiesExceptionsWidget *m_exceptionsWidget;
+};
+
+#endif
diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp
index 99399471..1b0c0051 100644
--- a/src/cookiejar.cpp
+++ b/src/cookiejar.cpp
@@ -425,274 +425,3 @@ void CookieJar::setAllowForSessionCookies(const QStringList &list)
qSort(m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end());
m_saveTimer->changeOccurred();
}
-
-
-// -------------------------------------------------------------------------------------------
-
-
-CookieModel::CookieModel(CookieJar *cookieJar, QObject *parent)
- : QAbstractTableModel(parent)
- , m_cookieJar(cookieJar)
-{
- connect(m_cookieJar, SIGNAL(cookiesChanged()), this, SLOT(cookiesChanged()));
- m_cookieJar->load();
-}
-
-
-QVariant CookieModel::headerData(int section, Qt::Orientation orientation, int role) const
-{
- if (role == Qt::SizeHintRole)
- {
- QFont font;
- font.setPointSize(10);
- QFontMetrics fm(font);
- int height = fm.height() + fm.height() / 3;
- int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString());
- return QSize(width, height);
- }
-
- if (orientation == Qt::Horizontal)
- {
- if (role != Qt::DisplayRole)
- return QVariant();
-
- switch (section)
- {
- case 0:
- return i18n("Website");
- case 1:
- return i18n("Name");
- case 2:
- return i18n("Path");
- case 3:
- return i18n("Secure");
- case 4:
- return i18n("Expires");
- case 5:
- return i18n("Contents");
- default:
- return QVariant();
- }
- }
- return QAbstractTableModel::headerData(section, orientation, role);
-}
-
-
-QVariant CookieModel::data(const QModelIndex &index, int role) const
-{
- QList<QNetworkCookie> lst;
- if (m_cookieJar)
- lst = m_cookieJar->allCookies();
- if (index.row() < 0 || index.row() >= lst.size())
- return QVariant();
-
- switch (role)
- {
- case Qt::DisplayRole:
- case Qt::EditRole:
- {
- QNetworkCookie cookie = lst.at(index.row());
- switch (index.column())
- {
- case 0:
- return cookie.domain();
- case 1:
- return cookie.name();
- case 2:
- return cookie.path();
- case 3:
- return cookie.isSecure();
- case 4:
- return cookie.expirationDate();
- case 5:
- return cookie.value();
- }
- }
- case Qt::FontRole:
- {
- QFont font;
- font.setPointSize(10);
- return font;
- }
- }
-
- return QVariant();
-}
-
-
-int CookieModel::columnCount(const QModelIndex &parent) const
-{
- return (parent.isValid()) ? 0 : 6;
-}
-
-
-int CookieModel::rowCount(const QModelIndex &parent) const
-{
- return (parent.isValid() || !m_cookieJar) ? 0 : m_cookieJar->allCookies().count();
-}
-
-
-bool CookieModel::removeRows(int row, int count, const QModelIndex &parent)
-{
- if (parent.isValid() || !m_cookieJar)
- return false;
- int lastRow = row + count - 1;
- beginRemoveRows(parent, row, lastRow);
- QList<QNetworkCookie> lst = m_cookieJar->allCookies();
- for (int i = lastRow; i >= row; --i)
- {
- lst.removeAt(i);
- }
- m_cookieJar->setAllCookies(lst);
- endRemoveRows();
- return true;
-}
-
-
-void CookieModel::cookiesChanged()
-{
- reset();
-}
-
-
-
-// ------------------------------------------------------------------------------------------------
-
-
-CookieExceptionsModel::CookieExceptionsModel(CookieJar *cookiejar, QObject *parent)
- : QAbstractTableModel(parent)
- , m_cookieJar(cookiejar)
-{
- m_allowedCookies = m_cookieJar->allowedCookies();
- m_blockedCookies = m_cookieJar->blockedCookies();
- m_sessionCookies = m_cookieJar->allowForSessionCookies();
-}
-
-
-QVariant CookieExceptionsModel::headerData(int section, Qt::Orientation orientation, int role) const
-{
- if (role == Qt::SizeHintRole)
- {
- QFont font;
- font.setPointSize(10);
- QFontMetrics fm(font);
- int height = fm.height() + fm.height() / 3;
- int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString());
- return QSize(width, height);
- }
-
- if (orientation == Qt::Horizontal
- && role == Qt::DisplayRole)
- {
- switch (section)
- {
- case 0:
- return i18n("Website");
- case 1:
- return i18n("Status");
- }
- }
- return QAbstractTableModel::headerData(section, orientation, role);
-}
-
-
-QVariant CookieExceptionsModel::data(const QModelIndex &index, int role) const
-{
- if (index.row() < 0 || index.row() >= rowCount())
- return QVariant();
-
- switch (role)
- {
- case Qt::DisplayRole:
- case Qt::EditRole:
- {
- int row = index.row();
- if (row < m_allowedCookies.count())
- {
- switch (index.column())
- {
- case 0:
- return m_allowedCookies.at(row);
- case 1:
- return i18n("Allow");
- }
- }
- row = row - m_allowedCookies.count();
- if (row < m_blockedCookies.count())
- {
- switch (index.column())
- {
- case 0:
- return m_blockedCookies.at(row);
- case 1:
- return i18n("Block");
- }
- }
- row = row - m_blockedCookies.count();
- if (row < m_sessionCookies.count())
- {
- switch (index.column())
- {
- case 0:
- return m_sessionCookies.at(row);
- case 1:
- return i18n("Allow For Session");
- }
- }
- }
- case Qt::FontRole:
- {
- QFont font;
- font.setPointSize(10);
- return font;
- }
- }
- return QVariant();
-}
-
-
-int CookieExceptionsModel::columnCount(const QModelIndex &parent) const
-{
- return (parent.isValid()) ? 0 : 2;
-}
-
-
-int CookieExceptionsModel::rowCount(const QModelIndex &parent) const
-{
- return (parent.isValid() || !m_cookieJar) ? 0 : m_allowedCookies.count() + m_blockedCookies.count() + m_sessionCookies.count();
-}
-
-
-bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &parent)
-{
- if (parent.isValid() || !m_cookieJar)
- return false;
-
- int lastRow = row + count - 1;
- beginRemoveRows(parent, row, lastRow);
- for (int i = lastRow; i >= row; --i)
- {
- if (i < m_allowedCookies.count())
- {
- m_allowedCookies.removeAt(row);
- continue;
- }
- i = i - m_allowedCookies.count();
- if (i < m_blockedCookies.count())
- {
- m_blockedCookies.removeAt(row);
- continue;
- }
- i = i - m_blockedCookies.count();
- if (i < m_sessionCookies.count())
- {
- m_sessionCookies.removeAt(row);
- continue;
- }
- }
- m_cookieJar->setAllowedCookies(m_allowedCookies);
- m_cookieJar->setBlockedCookies(m_blockedCookies);
- m_cookieJar->setAllowForSessionCookies(m_sessionCookies);
- endRemoveRows();
- return true;
-}
diff --git a/src/cookiejar.h b/src/cookiejar.h
index 81d3ce64..4d60d658 100644
--- a/src/cookiejar.h
+++ b/src/cookiejar.h
@@ -24,20 +24,11 @@
#define COOKIEJAR_H
-// Local Includes
-#include "cookiedialogs.h"
-
// Qt Includes
#include <QtCore/QStringList>
-#include <QtCore/QAbstractItemModel>
-#include <QtGui/QTableView>
#include <QtNetwork/QNetworkCookieJar>
-
-
// Forward Declarations
-class QSortFilterProxyModel;
-class QKeyEvent;
class AutoSaver;
class QUrl;
@@ -113,56 +104,4 @@ private:
QStringList m_exceptions_allowForSession;
};
-
-// -------------------------------------------------------------------------------------------------------------
-
-
-class CookieModel : public QAbstractTableModel
-{
- Q_OBJECT
-
-public:
- explicit 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;
-};
-
-
-// ----------------------------------------------------------------------------------------------------------------------
-
-
-class CookieExceptionsModel : public QAbstractTableModel
-{
- Q_OBJECT
- friend class CookiesExceptionsDialog;
-
-public:
- explicit 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;
-};
-
-
#endif // COOKIEJAR_H