diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2009-06-03 00:40:28 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2009-06-03 00:40:28 +0200 |
commit | 7ea16e97740ee21660d7130c83ff6af5fb3b1563 (patch) | |
tree | b1606230a21adf04f49de208fa71cc21d9d0af7d | |
parent | Fixing CMakelists and close buttons (diff) | |
download | rekonq-7ea16e97740ee21660d7130c83ff6af5fb3b1563.tar.xz |
new cookie management system. That (hopefully) works well..;)
-rw-r--r-- | src/cookiedialog.cpp | 1 | ||||
-rw-r--r-- | src/cookieexceptiondialog.cpp | 1 | ||||
-rw-r--r-- | src/cookiejar.cpp | 148 | ||||
-rw-r--r-- | src/cookiejar.h | 5 | ||||
-rw-r--r-- | src/settings.cpp | 1 |
5 files changed, 36 insertions, 120 deletions
diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp index 36379e58..e48d9c02 100644 --- a/src/cookiedialog.cpp +++ b/src/cookiedialog.cpp @@ -34,7 +34,6 @@ CookieModel::CookieModel(CookieJar *cookieJar, QObject *parent) , m_cookieJar(cookieJar) { connect(m_cookieJar, SIGNAL(cookiesChanged()), this, SLOT(cookiesChanged())); - m_cookieJar->load(); } diff --git a/src/cookieexceptiondialog.cpp b/src/cookieexceptiondialog.cpp index 0a88b378..b4ad555f 100644 --- a/src/cookieexceptiondialog.cpp +++ b/src/cookieexceptiondialog.cpp @@ -268,4 +268,3 @@ QSize CookiesExceptionsDialog::sizeHint() const QSize size = desktopRect.size() * 0.6; return size; } - diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp index 1e9ce3f2..4e4ef2c2 100644 --- a/src/cookiejar.cpp +++ b/src/cookiejar.cpp @@ -49,87 +49,18 @@ static const unsigned int JAR_VERSION = 23; -static const char cookieFileName[] = "cookies.ini.NEW"; - -// QDataStream &operator<<(QDataStream &stream, const QList<QNetworkCookie> &list) -// { -// stream << JAR_VERSION; -// stream << quint32(list.size()); -// for (int i = 0; i < list.size(); ++i) -// stream << list.at(i).toRawForm(); -// return stream; -// } -// -// -// QDataStream &operator>>(QDataStream &stream, QList<QNetworkCookie> &list) -// { -// list.clear(); -// -// quint32 version; -// stream >> version; -// -// if (version != JAR_VERSION) -// return stream; -// -// quint32 count; -// stream >> count; -// for (quint32 i = 0; i < count; ++i) -// { -// QByteArray value; -// stream >> value; -// QList<QNetworkCookie> newCookies = QNetworkCookie::parseCookies(value); -// if (newCookies.count() == 0 && value.length() != 0) -// { -// kDebug() << "CookieJar: Unable to parse saved cookie:" << value; -// } -// for (int j = 0; j < newCookies.count(); ++j) -// list.append(newCookies.at(j)); -// if (stream.atEnd()) -// break; -// } -// return stream; -// } +static const char cookieFileName[] = "cookies"; CookieJar::CookieJar(QObject *parent) : QNetworkCookieJar(parent) - , m_loaded(false) - , m_saveTimer(new AutoSaver(this)) , m_acceptCookies(AcceptOnlyFromSitesNavigatedTo) { - load(); -} - - -CookieJar::~CookieJar() -{ - if (m_keepCookies == KeepUntilExit) - clear(); - m_saveTimer->saveIfNeccessary(); -} - - -void CookieJar::clear() -{ - setAllCookies(QList<QNetworkCookie>()); - m_saveTimer->changeOccurred(); - emit cookiesChanged(); -} - - -void CookieJar::load() -{ - if (m_loaded) - return; - // load cookies and exceptions QString filepath = KStandardDirs::locateLocal("appdata", cookieFileName); KConfig iniconfig(filepath); -// commented out to try managing cookies my way.. -// qRegisterMetaTypeStreamOperators<QList<QNetworkCookie> >("QList<QNetworkCookie>"); - - KConfigGroup inigroup1 = iniconfig.group("general"); + KConfigGroup inigroup1 = iniconfig.group("cookielist"); QStringList cookieStringList = inigroup1.readEntry( QString("cookies"), QStringList() ); QList<QNetworkCookie> cookieNetworkList; @@ -149,11 +80,28 @@ void CookieJar::load() qSort( m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end() ); loadSettings(); +} + + +CookieJar::~CookieJar() +{ + if (m_keepCookies == KeepUntilExit) + clear(); save(); } +void CookieJar::clear() +{ + setAllCookies(QList<QNetworkCookie>()); + + save(); + + emit cookiesChanged(); +} + + void CookieJar::loadSettings() { int canAcceptCookies = ReKonfig::acceptCookies(); @@ -189,21 +137,18 @@ void CookieJar::loadSettings() break; } - m_loaded = true; emit cookiesChanged(); } void CookieJar::save() { - if (!m_loaded) - return; purgeOldCookies(); QString filepath = KStandardDirs::locateLocal("appdata", cookieFileName); KConfig iniconfig( filepath ); - KConfigGroup inigroup1 = iniconfig.group("general"); + KConfigGroup inigroup1 = iniconfig.group("cookielist"); QList<QNetworkCookie> cookies = allCookies(); for (int i = cookies.count() - 1; i >= 0; --i) { @@ -212,9 +157,9 @@ void CookieJar::save() } QStringList cookieStringList; - foreach( QNetworkCookie cook, cookies ) + foreach( QNetworkCookie cookie, cookies ) { - cookieStringList << QString( cook.toRawForm() ); + cookieStringList << QString( cookie.toRawForm() ); } inigroup1.writeEntry( QString("cookies"), cookieStringList ); @@ -273,16 +218,13 @@ void CookieJar::purgeOldCookies() if (oldCount == cookies.count()) return; setAllCookies(cookies); + emit cookiesChanged(); } QList<QNetworkCookie> CookieJar::cookiesForUrl(const QUrl &url) const { - CookieJar *that = const_cast<CookieJar*>(this); - if (!m_loaded) - that->load(); - QWebSettings *globalSettings = QWebSettings::globalSettings(); if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) { @@ -296,9 +238,6 @@ QList<QNetworkCookie> CookieJar::cookiesForUrl(const QUrl &url) const bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url) { - if (!m_loaded) - load(); - QWebSettings *globalSettings = QWebSettings::globalSettings(); if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) return false; @@ -340,17 +279,13 @@ bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const setAllCookies(cookies); addedCookies = true; } -#if 0 - else - kWarning() << "setCookiesFromUrl failed" << url << cookieList.value(0).toRawForm(); -#endif } } } if (addedCookies) { - m_saveTimer->changeOccurred(); + save(); emit cookiesChanged(); } return addedCookies; @@ -359,91 +294,76 @@ bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const CookieJar::AcceptPolicy CookieJar::acceptPolicy() const { - if (!m_loaded) - (const_cast<CookieJar*>(this))->load(); return m_acceptCookies; } void CookieJar::setAcceptPolicy(AcceptPolicy policy) { - if (!m_loaded) - load(); if (policy == m_acceptCookies) return; m_acceptCookies = policy; - m_saveTimer->changeOccurred(); + + save(); } CookieJar::KeepPolicy CookieJar::keepPolicy() const { - if (!m_loaded) - (const_cast<CookieJar*>(this))->load(); return m_keepCookies; } void CookieJar::setKeepPolicy(KeepPolicy policy) { - if (!m_loaded) - load(); if (policy == m_keepCookies) return; m_keepCookies = policy; - m_saveTimer->changeOccurred(); + + save(); } QStringList CookieJar::blockedCookies() const { - if (!m_loaded) - (const_cast<CookieJar*>(this))->load(); return m_exceptions_block; } QStringList CookieJar::allowedCookies() const { - if (!m_loaded) - (const_cast<CookieJar*>(this))->load(); return m_exceptions_allow; } QStringList CookieJar::allowForSessionCookies() const { - if (!m_loaded) - (const_cast<CookieJar*>(this))->load(); return m_exceptions_allowForSession; } void CookieJar::setBlockedCookies(const QStringList &list) { - if (!m_loaded) - load(); m_exceptions_block = list; qSort(m_exceptions_block.begin(), m_exceptions_block.end()); - m_saveTimer->changeOccurred(); + + save(); } void CookieJar::setAllowedCookies(const QStringList &list) { - if (!m_loaded) - load(); m_exceptions_allow = list; qSort(m_exceptions_allow.begin(), m_exceptions_allow.end()); - m_saveTimer->changeOccurred(); + + save(); } void CookieJar::setAllowForSessionCookies(const QStringList &list) { - if (!m_loaded) - load(); m_exceptions_allowForSession = list; qSort(m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end()); - m_saveTimer->changeOccurred(); + + save(); } diff --git a/src/cookiejar.h b/src/cookiejar.h index 4d60d658..08c65218 100644 --- a/src/cookiejar.h +++ b/src/cookiejar.h @@ -37,11 +37,13 @@ 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) @@ -92,9 +94,6 @@ private slots: private: void purgeOldCookies(); - void load(); - bool m_loaded; - AutoSaver *m_saveTimer; AcceptPolicy m_acceptCookies; KeepPolicy m_keepCookies; diff --git a/src/settings.cpp b/src/settings.cpp index d8de1441..f6e73412 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -215,4 +215,3 @@ void SettingsDialog::setHomeToCurrentPage() d->generalUi.kcfg_homePage->setText(webView->url().prettyUrl()); } } - |