From f33552320f6f36f5fe4f0def84435eadb8424b4f Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 6 Mar 2014 16:12:36 +0100 Subject: [PATCH] [AutoSaver] Rework AutoSaver so each object can use own instance Instead of saving everything in MainApp::saveStateSlot, save each object separately. As a result, this will save a lot of writes to disk. Other changes includes: Saving bookmarks also in private mode. Closes #1208 Cleanup of code --- src/lib/app/autosaver.cpp | 31 ++- src/lib/app/autosaver.h | 12 +- src/lib/app/mainapplication.cpp | 49 ++--- src/lib/app/mainapplication.h | 6 +- src/lib/bookmarks/bookmarks.cpp | 47 +++-- src/lib/bookmarks/bookmarks.h | 16 +- src/lib/bookmarks/bookmarksmanager.cpp | 2 +- src/lib/cookies/cookiejar.cpp | 250 ++++++++++++------------ src/lib/cookies/cookiejar.h | 37 ++-- src/lib/cookies/cookiemanager.cpp | 4 +- src/lib/network/networkmanagerproxy.cpp | 9 +- src/lib/network/networkmanagerproxy.h | 1 - src/lib/other/useragentmanager.cpp | 6 +- src/lib/other/useragentmanager.h | 8 +- src/lib/webview/tabwidget.cpp | 15 +- src/lib/webview/tabwidget.h | 3 + 16 files changed, 271 insertions(+), 225 deletions(-) diff --git a/src/lib/app/autosaver.cpp b/src/lib/app/autosaver.cpp index 2d9d47723..ed5c50f2f 100644 --- a/src/lib/app/autosaver.cpp +++ b/src/lib/app/autosaver.cpp @@ -16,20 +16,37 @@ * along with this program. If not, see . * ============================================================ */ #include "autosaver.h" -#include "mainapplication.h" + +#include + +#define SAVE_DELAY 1000 * 10 // 10 seconds AutoSaver::AutoSaver(QObject* parent) : QObject(parent) { - m_timer.start(1000 * 5, this); +} + +void AutoSaver::changeOcurred() +{ + if (!m_timer.isActive()) { + m_timer.start(SAVE_DELAY, this); + } +} + +void AutoSaver::saveIfNecessary() +{ + if (m_timer.isActive()) { + m_timer.stop(); + emit save(); + } } void AutoSaver::timerEvent(QTimerEvent* event) { - if (event->timerId() == m_timer.timerId() && mApp->isStateChanged()) { - emit saveApp(); - } - else { - QObject::timerEvent(event); + if (event->timerId() == m_timer.timerId()) { + m_timer.stop(); + emit save(); } + + QObject::timerEvent(event); } diff --git a/src/lib/app/autosaver.h b/src/lib/app/autosaver.h index 2cf0561c8..1c7f80210 100644 --- a/src/lib/app/autosaver.h +++ b/src/lib/app/autosaver.h @@ -26,18 +26,22 @@ class QUPZILLA_EXPORT AutoSaver : public QObject { Q_OBJECT + public: explicit AutoSaver(QObject* parent = 0); -signals: - void saveApp(); + // Tells AutoSaver that change occurred. Signal save() will be emitted after a delay + void changeOcurred(); + // Emits save() if timer is running. Call this from destructor. + void saveIfNecessary(); -public slots: +signals: + void save(); private: void timerEvent(QTimerEvent* event); - QBasicTimer m_timer; + QBasicTimer m_timer; }; #endif // AUTOSAVER_H diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 5b1b5b784..fcc0e57ba 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -81,9 +81,10 @@ MainApplication::MainApplication(int &argc, char** argv) : QtSingleApplication(argc, argv) + , m_autoSaver(0) , m_cookiemanager(0) , m_browsingLibrary(0) - , m_historymodel(0) + , m_history(0) , m_websettings(0) , m_networkmanager(0) , m_cookiejar(0) @@ -102,11 +103,10 @@ MainApplication::MainApplication(int &argc, char** argv) , m_speller(0) #endif , m_dbWriter(new DatabaseWriter(this)) - , m_uaManager(new UserAgentManager) + , m_uaManager(new UserAgentManager(this)) , m_isPrivateSession(false) , m_isPortable(false) , m_isClosing(false) - , m_isStateChanged(false) , m_isRestoring(false) , m_startingAfterCrash(false) , m_databaseConnected(false) @@ -301,6 +301,9 @@ MainApplication::MainApplication(int &argc, char** argv) Settings::createSettings(m_activeProfil + "settings.ini"); + m_autoSaver = new AutoSaver(this); + connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveStateSlot())); + translateApp(); BrowserWindow* qupzilla = new BrowserWindow(Qz::BW_FirstAppWindow, startUrl); @@ -361,9 +364,6 @@ void MainApplication::postLaunch() getWindow()->toggleFullScreen(); } - AutoSaver* saver = new AutoSaver(); - connect(saver, SIGNAL(saveApp()), this, SLOT(saveStateSlot())); - QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, m_activeProfil); QWebHistoryInterface::setDefaultInterface(new WebHistoryInterface(this)); @@ -500,19 +500,10 @@ BrowserWindow* MainApplication::getWindow() void MainApplication::setStateChanged() { - m_isStateChanged = true; + m_autoSaver->changeOcurred(); sendMessages(Qz::AM_HistoryStateChanged, true); } -bool MainApplication::isStateChanged() -{ - if (m_isStateChanged) { - m_isStateChanged = false; - return true; - } - return false; -} - QList MainApplication::mainWindows() { QList list; @@ -870,13 +861,13 @@ void MainApplication::quitApplication() return; } + if (m_mainWindows.count() > 0) { + m_autoSaver->saveIfNecessary(); + } + m_isClosing = true; m_networkmanager->disconnectObjects(); - if (m_mainWindows.count() > 0) { - saveStateSlot(); - } - // Saving settings in saveSettings() slot called from quit() so // everything gets saved also when quitting application in other // way than clicking Quit action in File menu or closing last window @@ -910,7 +901,7 @@ void MainApplication::saveSettings() settings.endGroup(); if (deleteHistory) { - m_historymodel->clearHistory(); + m_history->clearHistory(); } if (deleteHtml5Storage) { ClearPrivateData::clearLocalStorage(); @@ -946,10 +937,10 @@ CookieManager* MainApplication::cookieManager() History* MainApplication::history() { - if (!m_historymodel) { - m_historymodel = new History(this); + if (!m_history) { + m_history = new History(this); } - return m_historymodel; + return m_history; } QWebSettings* MainApplication::webSettings() @@ -971,8 +962,7 @@ NetworkManager* MainApplication::networkManager() CookieJar* MainApplication::cookieJar() { if (!m_cookiejar) { - m_cookiejar = new CookieJar(getWindow()); - m_cookiejar->restoreCookies(); + m_cookiejar = new CookieJar(m_isPrivateSession ? QString() : m_activeProfil, this); } return m_cookiejar; } @@ -993,7 +983,7 @@ PluginProxy* MainApplication::plugins() Bookmarks* MainApplication::bookmarks() { if (!m_bookmarks) { - m_bookmarks = new Bookmarks(this); + m_bookmarks = new Bookmarks(m_activeProfil, this); } return m_bookmarks; } @@ -1225,10 +1215,6 @@ bool MainApplication::saveStateSlot() qupzilla_->tabWidget()->savePinnedTabs(); } - // Save cookies & bookmarks - m_cookiejar->saveCookies(); - m_bookmarks->saveSettings(); - return true; } @@ -1384,7 +1370,6 @@ QString MainApplication::tempPath() const MainApplication::~MainApplication() { - delete m_uaManager; #ifdef Q_OS_MAC delete m_macDockMenu; #endif diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index d5c009bfe..6233474de 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -52,6 +52,7 @@ class UserAgentManager; class ProxyStyle; class RegisterQAppAssociation; class HTML5PermissionsManager; +class AutoSaver; class Speller; #ifdef Q_OS_MAC @@ -76,7 +77,6 @@ public: bool restoreStateSlot(BrowserWindow* window, RestoreData recoveryData); BrowserWindow* makeNewWindow(Qz::BrowserWindowType type, const QUrl &startUrl = QUrl()); void aboutToCloseWindow(BrowserWindow* window); - bool isStateChanged(); QList mainWindows(); @@ -169,9 +169,10 @@ private: QUrl userStyleSheet(const QString &filePath) const; + AutoSaver* m_autoSaver; CookieManager* m_cookiemanager; BrowsingLibrary* m_browsingLibrary; - History* m_historymodel; + History* m_history; QWebSettings* m_websettings; NetworkManager* m_networkmanager; CookieJar* m_cookiejar; @@ -200,7 +201,6 @@ private: bool m_isPrivateSession; bool m_isPortable; bool m_isClosing; - bool m_isStateChanged; bool m_isRestoring; bool m_startingAfterCrash; diff --git a/src/lib/bookmarks/bookmarks.cpp b/src/lib/bookmarks/bookmarks.cpp index 1a5170e57..19d41bbf9 100644 --- a/src/lib/bookmarks/bookmarks.cpp +++ b/src/lib/bookmarks/bookmarks.cpp @@ -19,24 +19,29 @@ #include "bookmarkitem.h" #include "bookmarksmodel.h" #include "bookmarkstools.h" -#include "mainapplication.h" -#include "qztools.h" -#include "webview.h" +#include "autosaver.h" #include "settings.h" +#include "qztools.h" #include "json.h" #include #include -Bookmarks::Bookmarks(QObject* parent) +Bookmarks::Bookmarks(const QString &profilePath, QObject* parent) : QObject(parent) + , m_autoSaver(0) + , m_profilePath(profilePath) { init(); loadSettings(); + + m_autoSaver = new AutoSaver(this); + connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveSettings())); } Bookmarks::~Bookmarks() { + m_autoSaver->saveIfNecessary(); delete m_root; } @@ -48,16 +53,6 @@ void Bookmarks::loadSettings() settings.endGroup(); } -void Bookmarks::saveSettings() -{ - Settings settings; - settings.beginGroup("Bookmarks"); - settings.setValue("showOnlyIconsInToolbar", m_showOnlyIconsInToolbar); - settings.endGroup(); - - saveBookmarks(); -} - bool Bookmarks::showOnlyIconsInToolbar() const { return m_showOnlyIconsInToolbar; @@ -129,6 +124,8 @@ void Bookmarks::addBookmark(BookmarkItem* parent, BookmarkItem* item) Q_ASSERT(item); insertBookmark(parent, 0, item); + + m_autoSaver->changeOcurred(); } void Bookmarks::insertBookmark(BookmarkItem* parent, int row, BookmarkItem* item) @@ -140,6 +137,8 @@ void Bookmarks::insertBookmark(BookmarkItem* parent, int row, BookmarkItem* item m_lastFolder = parent; m_model->addBookmark(parent, row, item); emit bookmarkAdded(item); + + m_autoSaver->changeOcurred(); } bool Bookmarks::removeBookmark(BookmarkItem* item) @@ -150,13 +149,17 @@ bool Bookmarks::removeBookmark(BookmarkItem* item) m_model->removeBookmark(item); emit bookmarkRemoved(item); + + m_autoSaver->changeOcurred(); return true; } -void Bookmarks::notifyBookmarkChanged(BookmarkItem* item) +void Bookmarks::changeBookmark(BookmarkItem* item) { Q_ASSERT(item); emit bookmarkChanged(item); + + m_autoSaver->changeOcurred(); } void Bookmarks::setShowOnlyIconsInToolbar(bool state) @@ -165,6 +168,16 @@ void Bookmarks::setShowOnlyIconsInToolbar(bool state) emit showOnlyIconsInToolbarChanged(state); } +void Bookmarks::saveSettings() +{ + Settings settings; + settings.beginGroup("Bookmarks"); + settings.setValue("showOnlyIconsInToolbar", m_showOnlyIconsInToolbar); + settings.endGroup(); + + saveBookmarks(); +} + void Bookmarks::init() { m_root = new BookmarkItem(BookmarkItem::Root); @@ -196,7 +209,7 @@ void Bookmarks::init() void Bookmarks::loadBookmarks() { - const QString bookmarksFile = mApp->currentProfilePath() + QLatin1String("/bookmarks.json"); + const QString bookmarksFile = m_profilePath + QLatin1String("/bookmarks.json"); const QString backupFile = bookmarksFile + QLatin1String(".old"); QFile file(bookmarksFile); @@ -259,7 +272,7 @@ void Bookmarks::saveBookmarks() return; } - QFile file(mApp->currentProfilePath() + QLatin1String("/bookmarks.json")); + QFile file(m_profilePath + QLatin1String("/bookmarks.json")); if (!file.open(QFile::WriteOnly)) { qWarning() << "Bookmarks::saveBookmarks() Error opening bookmarks file for writing!"; diff --git a/src/lib/bookmarks/bookmarks.h b/src/lib/bookmarks/bookmarks.h index 3e9c6401c..b52393f5e 100644 --- a/src/lib/bookmarks/bookmarks.h +++ b/src/lib/bookmarks/bookmarks.h @@ -27,16 +27,16 @@ class QUrl; class BookmarkItem; class BookmarksModel; +class AutoSaver; class QUPZILLA_EXPORT Bookmarks : public QObject { Q_OBJECT public: - explicit Bookmarks(QObject* parent = 0); + explicit Bookmarks(const QString &profilePath, QObject* parent = 0); ~Bookmarks(); void loadSettings(); - void saveSettings(); bool showOnlyIconsInToolbar() const; @@ -59,8 +59,7 @@ public: void addBookmark(BookmarkItem* parent, BookmarkItem* item); void insertBookmark(BookmarkItem* parent, int row, BookmarkItem* item); bool removeBookmark(BookmarkItem* item); - - void notifyBookmarkChanged(BookmarkItem* item); + void changeBookmark(BookmarkItem* item); public slots: void setShowOnlyIconsInToolbar(bool state); @@ -75,6 +74,9 @@ signals: void showOnlyIconsInToolbarChanged(bool show); +private slots: + void saveSettings(); + private: void init(); void loadBookmarks(); @@ -91,10 +93,12 @@ private: BookmarkItem* m_folderToolbar; BookmarkItem* m_folderMenu; BookmarkItem* m_folderUnsorted; - BookmarkItem* m_lastFolder; - BookmarksModel* m_model; + BookmarksModel* m_model; + AutoSaver* m_autoSaver; + + QString m_profilePath; bool m_showOnlyIconsInToolbar; }; diff --git a/src/lib/bookmarks/bookmarksmanager.cpp b/src/lib/bookmarks/bookmarksmanager.cpp index d181cb2ed..96768b8bd 100644 --- a/src/lib/bookmarks/bookmarksmanager.cpp +++ b/src/lib/bookmarks/bookmarksmanager.cpp @@ -206,7 +206,7 @@ void BookmarksManager::bookmarkEdited() item->setKeyword(ui->keyword->text()); item->setDescription(ui->description->toPlainText()); - m_bookmarks->notifyBookmarkChanged(item); + m_bookmarks->changeBookmark(item); } void BookmarksManager::descriptionEdited() diff --git a/src/lib/cookies/cookiejar.cpp b/src/lib/cookies/cookiejar.cpp index 640b04fb3..913aeba81 100644 --- a/src/lib/cookies/cookiejar.cpp +++ b/src/lib/cookies/cookiejar.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . * ============================================================ */ #include "cookiejar.h" -#include "browserwindow.h" +#include "autosaver.h" #include "mainapplication.h" #include "settings.h" #include "qztools.h" @@ -25,16 +25,24 @@ #include #include #include -#include // QTWEBKIT_VERSION_CHECK macro //#define COOKIE_DEBUG -CookieJar::CookieJar(BrowserWindow* window, QObject* parent) +CookieJar::CookieJar(const QString &profilePath, QObject* parent) : QNetworkCookieJar(parent) - , m_window(window) + , m_autoSaver(0) + , m_profilePath(profilePath) { - m_activeProfil = mApp->currentProfilePath(); loadSettings(); + restoreCookies(); + + m_autoSaver = new AutoSaver(this); + connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveCookies())); +} + +CookieJar::~CookieJar() +{ + m_autoSaver->saveIfNecessary(); } void CookieJar::loadSettings() @@ -50,7 +58,7 @@ void CookieJar::loadSettings() settings.endGroup(); #if QTWEBKIT_FROM_2_3 - mApp->webSettings()->setThirdPartyCookiePolicy(m_blockThirdParty ? + QWebSettings::globalSettings()->setThirdPartyCookiePolicy(m_blockThirdParty ? QWebSettings::AlwaysBlockThirdPartyCookies : QWebSettings::AlwaysAllowThirdPartyCookies); #endif @@ -61,6 +69,120 @@ void CookieJar::setAllowCookies(bool allow) m_allowCookies = allow; } +bool CookieJar::setCookiesFromUrl(const QList &cookieList, const QUrl &url) +{ + QList newList; + + foreach (QNetworkCookie cookie, cookieList) { + // If cookie domain is empty, set it to url.host() + if (cookie.domain().isEmpty()) { + cookie.setDomain(url.host()); + } + + if (!rejectCookie(url.host(), cookie)) { + newList.append(cookie); + } + } + + bool added = QNetworkCookieJar::setCookiesFromUrl(newList, url); + + if (added) { + m_autoSaver->changeOcurred(); + } + + return added; +} + +QList CookieJar::allCookies() const +{ + return QNetworkCookieJar::allCookies(); +} + +void CookieJar::setAllCookies(const QList &cookieList) +{ + m_autoSaver->changeOcurred(); + QNetworkCookieJar::setAllCookies(cookieList); +} + +void CookieJar::clearCookies() +{ + setAllCookies(QList()); +} + +void CookieJar::restoreCookies() +{ + if (m_profilePath.isEmpty()) { + return; + } + + const QString cookiesFile = m_profilePath + QLatin1String("cookies.dat"); + QDateTime now = QDateTime::currentDateTime(); + + QList restoredCookies; + QFile file(cookiesFile); + file.open(QIODevice::ReadOnly); + QDataStream stream(&file); + int count; + + stream >> count; + for (int i = 0; i < count; i++) { + QByteArray rawForm; + stream >> rawForm; + const QList &cookieList = QNetworkCookie::parseCookies(rawForm); + if (cookieList.isEmpty()) { + continue; + } + + const QNetworkCookie cookie = cookieList.at(0); + + if (cookie.expirationDate() < now) { + continue; + } + restoredCookies.append(cookie); + } + + file.close(); + QNetworkCookieJar::setAllCookies(restoredCookies); +} + +void CookieJar::saveCookies() +{ + if (m_profilePath.isEmpty()) { + return; + } + + QList cookies = allCookies(); + + if (m_deleteOnClose) { + // If we are deleting cookies on close, save only whitelisted cookies + cookies.clear(); + QList aCookies = allCookies(); + + foreach (const QNetworkCookie &cookie, aCookies) { + if (listMatchesDomain(m_whitelist, cookie.domain())) { + cookies.append(cookie); + } + } + } + + QFile file(m_profilePath + QLatin1String("cookies.dat")); + file.open(QIODevice::WriteOnly); + QDataStream stream(&file); + int count = cookies.count(); + + stream << count; + for (int i = 0; i < count; i++) { + const QNetworkCookie cookie = cookies.at(i); + + if (cookie.isSessionCookie()) { + continue; + } + stream << cookie.toRawForm(); + } + + file.close(); +} + bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie) const { Q_UNUSED(domain) @@ -110,119 +232,7 @@ bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie return false; } -bool CookieJar::setCookiesFromUrl(const QList &cookieList, const QUrl &url) -{ - QList newList; - - foreach (QNetworkCookie cookie, cookieList) { - // If cookie domain is empty, set it to url.host() - if (cookie.domain().isEmpty()) { - cookie.setDomain(url.host()); - } - - if (!rejectCookie(url.host(), cookie)) { - newList.append(cookie); - } - } - - return QNetworkCookieJar::setCookiesFromUrl(newList, url); -} - -void CookieJar::saveCookies() -{ - if (mApp->isPrivateSession()) { - return; - } - - QList allCookies; - - if (!m_deleteOnClose) { - // If we are deleting cookies on close, let's just save empty cookie list - allCookies = getAllCookies(); - } - else { - // Do not delete whitelisted cookies - QList cookies = getAllCookies(); - int count = cookies.count(); - - for (int i = 0; i < count; i++) { - const QNetworkCookie cookie = cookies.at(i); - - if (listMatchesDomain(m_whitelist, cookie.domain())) { - allCookies.append(cookie); - } - } - } - - QFile file(m_activeProfil + "cookies.dat"); - file.open(QIODevice::WriteOnly); - QDataStream stream(&file); - int count = allCookies.count(); - - stream << count; - for (int i = 0; i < count; i++) { - const QNetworkCookie cookie = allCookies.at(i); - - if (cookie.isSessionCookie()) { - continue; - } - stream << cookie.toRawForm(); - } - - file.close(); -} - -void CookieJar::restoreCookies() -{ - if (!QFile::exists(m_activeProfil + "cookies.dat") || mApp->isPrivateSession()) { - return; - } - - QDateTime now = QDateTime::currentDateTime(); - - QList restoredCookies; - QFile file(m_activeProfil + "cookies.dat"); - file.open(QIODevice::ReadOnly); - QDataStream stream(&file); - int count; - - stream >> count; - for (int i = 0; i < count; i++) { - QByteArray rawForm; - stream >> rawForm; - const QList &cookieList = QNetworkCookie::parseCookies(rawForm); - if (cookieList.isEmpty()) { - continue; - } - - const QNetworkCookie cookie = cookieList.at(0); - - if (cookie.expirationDate() < now) { - continue; - } - restoredCookies.append(cookie); - } - - file.close(); - setAllCookies(restoredCookies); -} - -void CookieJar::clearCookies() -{ - setAllCookies(QList()); -} - -QList CookieJar::getAllCookies() -{ - return QNetworkCookieJar::allCookies(); -} - -void CookieJar::setAllCookies(const QList &cookieList) -{ - QNetworkCookieJar::setAllCookies(cookieList); -} - -bool CookieJar::matchDomain(QString cookieDomain, QString siteDomain) +bool CookieJar::matchDomain(QString cookieDomain, QString siteDomain) const { // According to RFC 6265 @@ -238,7 +248,7 @@ bool CookieJar::matchDomain(QString cookieDomain, QString siteDomain) return QzTools::matchDomain(cookieDomain, siteDomain); } -bool CookieJar::listMatchesDomain(const QStringList &list, const QString &cookieDomain) +bool CookieJar::listMatchesDomain(const QStringList &list, const QString &cookieDomain) const { foreach (const QString &d, list) { if (matchDomain(d, cookieDomain)) { diff --git a/src/lib/cookies/cookiejar.h b/src/lib/cookies/cookiejar.h index 40d87ee73..d860214ca 100644 --- a/src/lib/cookies/cookiejar.h +++ b/src/lib/cookies/cookiejar.h @@ -18,37 +18,41 @@ #ifndef COOKIEJAR_H #define COOKIEJAR_H -#include "qzcommon.h" - #include #include #include -class BrowserWindow; +#include "qzcommon.h" + +class AutoSaver; class QUPZILLA_EXPORT CookieJar : public QNetworkCookieJar { + Q_OBJECT + public: - explicit CookieJar(BrowserWindow* window, QObject* parent = 0); + // Passing empty profilePath will create empty CookieJar (for Private Session) + explicit CookieJar(const QString &profilePath, QObject* parent = 0); + ~CookieJar(); void loadSettings(); - bool setCookiesFromUrl(const QList &cookieList, const QUrl &url); - QList getAllCookies(); - void setAllCookies(const QList &cookieList); - - void saveCookies(); - void restoreCookies(); - void clearCookies(); void setAllowCookies(bool allow); + bool setCookiesFromUrl(const QList &cookieList, const QUrl &url); - static bool matchDomain(QString cookieDomain, QString siteDomain); - static bool listMatchesDomain(const QStringList &list, const QString &cookieDomain); + QList allCookies() const; + void setAllCookies(const QList &cookieList); + + void clearCookies(); + void restoreCookies(); + +private slots: + void saveCookies(); private: bool rejectCookie(const QString &domain, const QNetworkCookie &cookie) const; - - BrowserWindow* m_window; + bool matchDomain(QString cookieDomain, QString siteDomain) const; + bool listMatchesDomain(const QStringList &list, const QString &cookieDomain) const; bool m_allowCookies; bool m_filterTrackingCookie; @@ -58,7 +62,8 @@ private: QStringList m_whitelist; QStringList m_blacklist; - QString m_activeProfil; + AutoSaver* m_autoSaver; + QString m_profilePath; }; #endif // COOKIEJAR_H diff --git a/src/lib/cookies/cookiemanager.cpp b/src/lib/cookies/cookiemanager.cpp index 18ee2c67e..359847d31 100644 --- a/src/lib/cookies/cookiemanager.cpp +++ b/src/lib/cookies/cookiemanager.cpp @@ -108,7 +108,7 @@ void CookieManager::removeCookie() return; } - QList allCookies = mApp->cookieJar()->getAllCookies(); + QList allCookies = mApp->cookieJar()->allCookies(); if (current->text(1).isEmpty()) { //Remove whole cookie group const QString domain = current->data(0, Qt::UserRole + 10).toString(); @@ -178,7 +178,7 @@ void CookieManager::refreshTable() void CookieManager::slotRefreshTable() { - const QList &allCookies = mApp->cookieJar()->getAllCookies(); + const QList &allCookies = mApp->cookieJar()->allCookies(); QApplication::setOverrideCursor(Qt::WaitCursor); ui->cookieTree->clear(); diff --git a/src/lib/network/networkmanagerproxy.cpp b/src/lib/network/networkmanagerproxy.cpp index 2399075f3..883454ace 100644 --- a/src/lib/network/networkmanagerproxy.cpp +++ b/src/lib/network/networkmanagerproxy.cpp @@ -29,6 +29,9 @@ NetworkManagerProxy::NetworkManagerProxy(QObject* parent) , m_manager(0) { setCookieJar(mApp->cookieJar()); + + // CookieJar is shared between NetworkManagers + mApp->cookieJar()->setParent(0); } void NetworkManagerProxy::setPrimaryNetworkAccessManager(NetworkManager* manager) @@ -61,9 +64,3 @@ void NetworkManagerProxy::disconnectObjects() disconnect(m_manager); } - -NetworkManagerProxy::~NetworkManagerProxy() -{ - // Prevent deleting of cookie jar - cookieJar()->setParent(m_manager); -} diff --git a/src/lib/network/networkmanagerproxy.h b/src/lib/network/networkmanagerproxy.h index 57e7ca222..8a075445e 100644 --- a/src/lib/network/networkmanagerproxy.h +++ b/src/lib/network/networkmanagerproxy.h @@ -29,7 +29,6 @@ class QUPZILLA_EXPORT NetworkManagerProxy : public QNetworkAccessManager { public: explicit NetworkManagerProxy(QObject* parent = 0); - ~NetworkManagerProxy(); void setPage(WebPage* page) { m_page = page; } void setPrimaryNetworkAccessManager(NetworkManager* manager); diff --git a/src/lib/other/useragentmanager.cpp b/src/lib/other/useragentmanager.cpp index 33519e184..97b243f81 100644 --- a/src/lib/other/useragentmanager.cpp +++ b/src/lib/other/useragentmanager.cpp @@ -22,8 +22,9 @@ #include // QTWEBKIT_VERSION_CHECK macro -UserAgentManager::UserAgentManager() - : m_usePerDomainUserAgent(false) +UserAgentManager::UserAgentManager(QObject* parent) + : QObject(parent) + , m_usePerDomainUserAgent(false) { m_fakeUserAgent = QString("Mozilla/5.0 (%1) AppleWebKit/%2 (KHTML, like Gecko) Chrome/10.0 Safari/%2").arg(QzTools::operatingSystem(), BrowserWindow::WEBKITVERSION); } @@ -77,7 +78,6 @@ QString UserAgentManager::userAgentForUrl(const QUrl &url) const } #endif - return m_globalUserAgent; } diff --git a/src/lib/other/useragentmanager.h b/src/lib/other/useragentmanager.h index 4242a4429..68bd8f96c 100644 --- a/src/lib/other/useragentmanager.h +++ b/src/lib/other/useragentmanager.h @@ -18,17 +18,19 @@ #ifndef USERAGENTMANAGER_H #define USERAGENTMANAGER_H +#include #include -#include #include "qzcommon.h" class QUrl; -class QUPZILLA_EXPORT UserAgentManager +class QUPZILLA_EXPORT UserAgentManager : QObject { + Q_OBJECT + public: - explicit UserAgentManager(); + explicit UserAgentManager(QObject* parent = 0); void loadSettings(); diff --git a/src/lib/webview/tabwidget.cpp b/src/lib/webview/tabwidget.cpp index d80b1c5b0..f7373b746 100644 --- a/src/lib/webview/tabwidget.cpp +++ b/src/lib/webview/tabwidget.cpp @@ -127,6 +127,7 @@ TabWidget::TabWidget(BrowserWindow* window, QWidget* parent) setTabBar(m_tabBar); connect(this, SIGNAL(currentChanged(int)), m_window, SLOT(refreshHistory())); + connect(this, SIGNAL(changed()), mApp, SLOT(setStateChanged())); connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int))); @@ -378,7 +379,7 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT } connect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); - connect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged())); + connect(webView, SIGNAL(changed()), this, SIGNAL(changed())); connect(webView, SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString))); if (url.isValid()) { @@ -407,6 +408,8 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT setUpdatesEnabled(true); + emit changed(); + #ifdef Q_OS_WIN QTimer::singleShot(0, m_window, SLOT(applyBlurToMainWindow())); #endif @@ -429,7 +432,7 @@ int TabWidget::addView(WebTab* tab) } connect(tab->view(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); - connect(tab->view(), SIGNAL(changed()), mApp, SLOT(setStateChanged())); + connect(tab->view(), SIGNAL(changed()), this, SIGNAL(changed())); connect(tab->view(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString))); return index; @@ -486,7 +489,7 @@ void TabWidget::closeTab(int index, bool force) m_locationBars->removeWidget(webView->webTab()->locationBar()); disconnect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); - disconnect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged())); + disconnect(webView, SIGNAL(changed()), this, SIGNAL(changed())); disconnect(webView, SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString))); if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) { @@ -505,6 +508,8 @@ void TabWidget::closeTab(int index, bool force) QAction* labelAction = m_menuTabs->actions().last(); labelAction->setText(tr("Currently you have %n opened tab(s)", "", count() - 1)); } + + emit changed(); } void TabWidget::currentTabChanged(int index) @@ -526,6 +531,8 @@ void TabWidget::currentTabChanged(int index) webTab->setCurrentTab(); m_window->currentTabChanged(); + + emit changed(); } void TabWidget::tabMoved(int before, int after) @@ -707,7 +714,7 @@ void TabWidget::detachTab(int index) m_locationBars->removeWidget(tab->locationBar()); disconnect(tab->view(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); - disconnect(tab->view(), SIGNAL(changed()), mApp, SLOT(setStateChanged())); + disconnect(tab->view(), SIGNAL(changed()), this, SIGNAL(changed())); disconnect(tab->view(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString))); BrowserWindow* window = mApp->makeNewWindow(Qz::BW_NewWindow); diff --git a/src/lib/webview/tabwidget.h b/src/lib/webview/tabwidget.h index 372e4d938..7547a3a80 100644 --- a/src/lib/webview/tabwidget.h +++ b/src/lib/webview/tabwidget.h @@ -135,6 +135,9 @@ public slots: void tabBarOverFlowChanged(bool overFlowed); +signals: + void changed(); + private slots: void aboutToShowTabsMenu(); void actionChangeIndex();