1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[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
This commit is contained in:
nowrep 2014-03-06 16:12:36 +01:00
parent c0311d7ee8
commit f33552320f
16 changed files with 271 additions and 225 deletions

View File

@ -16,20 +16,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "autosaver.h"
#include "mainapplication.h"
#include <QTimerEvent>
#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();
if (event->timerId() == m_timer.timerId()) {
m_timer.stop();
emit save();
}
else {
QObject::timerEvent(event);
}
}

View File

@ -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

View File

@ -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<BrowserWindow*> MainApplication::mainWindows()
{
QList<BrowserWindow*> 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

View File

@ -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<BrowserWindow*> 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;

View File

@ -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 <QDebug>
#include <QFile>
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!";

View File

@ -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;
};

View File

@ -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()

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "cookiejar.h"
#include "browserwindow.h"
#include "autosaver.h"
#include "mainapplication.h"
#include "settings.h"
#include "qztools.h"
@ -25,16 +25,24 @@
#include <QWebSettings>
#include <QDateTime>
#include <QDebug>
#include <QWebPage> // 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<QNetworkCookie> &cookieList, const QUrl &url)
{
QList<QNetworkCookie> 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<QNetworkCookie> CookieJar::allCookies() const
{
return QNetworkCookieJar::allCookies();
}
void CookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList)
{
m_autoSaver->changeOcurred();
QNetworkCookieJar::setAllCookies(cookieList);
}
void CookieJar::clearCookies()
{
setAllCookies(QList<QNetworkCookie>());
}
void CookieJar::restoreCookies()
{
if (m_profilePath.isEmpty()) {
return;
}
const QString cookiesFile = m_profilePath + QLatin1String("cookies.dat");
QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> 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<QNetworkCookie> &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<QNetworkCookie> cookies = allCookies();
if (m_deleteOnClose) {
// If we are deleting cookies on close, save only whitelisted cookies
cookies.clear();
QList<QNetworkCookie> 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<QNetworkCookie> &cookieList, const QUrl &url)
{
QList<QNetworkCookie> 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<QNetworkCookie> 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<QNetworkCookie> 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<QNetworkCookie> 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<QNetworkCookie> &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<QNetworkCookie>());
}
QList<QNetworkCookie> CookieJar::getAllCookies()
{
return QNetworkCookieJar::allCookies();
}
void CookieJar::setAllCookies(const QList<QNetworkCookie> &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)) {

View File

@ -18,37 +18,41 @@
#ifndef COOKIEJAR_H
#define COOKIEJAR_H
#include "qzcommon.h"
#include <QFile>
#include <QStringList>
#include <QNetworkCookieJar>
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<QNetworkCookie> &cookieList, const QUrl &url);
QList<QNetworkCookie> getAllCookies();
void setAllCookies(const QList<QNetworkCookie> &cookieList);
void saveCookies();
void restoreCookies();
void clearCookies();
void setAllowCookies(bool allow);
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
static bool matchDomain(QString cookieDomain, QString siteDomain);
static bool listMatchesDomain(const QStringList &list, const QString &cookieDomain);
QList<QNetworkCookie> allCookies() const;
void setAllCookies(const QList<QNetworkCookie> &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

View File

@ -108,7 +108,7 @@ void CookieManager::removeCookie()
return;
}
QList<QNetworkCookie> allCookies = mApp->cookieJar()->getAllCookies();
QList<QNetworkCookie> 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<QNetworkCookie> &allCookies = mApp->cookieJar()->getAllCookies();
const QList<QNetworkCookie> &allCookies = mApp->cookieJar()->allCookies();
QApplication::setOverrideCursor(Qt::WaitCursor);
ui->cookieTree->clear();

View File

@ -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);
}

View File

@ -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);

View File

@ -22,8 +22,9 @@
#include <QWebPage> // 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;
}

View File

@ -18,17 +18,19 @@
#ifndef USERAGENTMANAGER_H
#define USERAGENTMANAGER_H
#include <QObject>
#include <QHash>
#include <QString>
#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();

View File

@ -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);

View File

@ -135,6 +135,9 @@ public slots:
void tabBarOverFlowChanged(bool overFlowed);
signals:
void changed();
private slots:
void aboutToShowTabsMenu();
void actionChangeIndex();