From d0ecd4c042b81f0eb732a6702f9d1a83d6f4144e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 19 May 2009 12:29:32 +0200 Subject: Cookie System Refactoring. Step 1.. --- src/cookiejar.cpp | 271 ------------------------------------------------------ 1 file changed, 271 deletions(-) (limited to 'src/cookiejar.cpp') 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 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 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; -} -- cgit v1.2.1