From 575b15db6c28100df4f8b2ab7cfe133c65c26202 Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 3 Nov 2011 18:51:46 +0100 Subject: [PATCH] Fixed restoring of multiple windows Restoring of multiple windows now won't add additional tab in second and next windows --- src/app/mainapplication.cpp | 12 +++++++++--- src/app/qupzilla.cpp | 26 +++++++++++++++++++++----- src/app/qupzilla.h | 5 +++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/app/mainapplication.cpp b/src/app/mainapplication.cpp index cd3460a30..d7f4c882d 100644 --- a/src/app/mainapplication.cpp +++ b/src/app/mainapplication.cpp @@ -154,7 +154,7 @@ MainApplication::MainApplication(const QList &cm translateApp(); QWebHistoryInterface::setDefaultInterface(new WebHistoryInterface(this)); - QupZilla* qupzilla = new QupZilla(true, startUrl); + QupZilla* qupzilla = new QupZilla(QupZilla::FirstAppWindow, startUrl); m_mainWindows.append(qupzilla); connect(qupzilla, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(sendMessages(MainApplication::MessageType,bool))); qupzilla->show(); @@ -350,7 +350,13 @@ void MainApplication::addNewTab(const QUrl &url) void MainApplication::makeNewWindow(bool tryRestore, const QUrl &startUrl) { - QupZilla* newWindow = new QupZilla(tryRestore, startUrl); + QupZilla::StartBehaviour behaviour; + if (tryRestore) + behaviour = QupZilla::OtherRestoredWindow; + else + behaviour = QupZilla::NewWindow; + + QupZilla* newWindow = new QupZilla(behaviour, startUrl); connect(newWindow, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(sendMessages(MainApplication::MessageType,bool))); m_mainWindows.append(newWindow); newWindow->show(); @@ -623,7 +629,7 @@ bool MainApplication::restoreStateSlot(QupZilla* window) stream >> tabState; stream >> qMainWindowState; - QupZilla* window = new QupZilla(false); + QupZilla* window = new QupZilla(QupZilla::OtherRestoredWindow); m_mainWindows.append(window); connect(window, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(sendMessages(MainApplication::MessageType,bool))); QEventLoop eLoop; diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index 3321545a0..77c652669 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -81,13 +81,13 @@ const QIcon QupZilla::qupzillaIcon() return i; } -QupZilla::QupZilla(bool tryRestore, QUrl startUrl) +QupZilla::QupZilla(StartBehaviour behaviour, QUrl startUrl) : QMainWindow(0) - , m_tryRestore(tryRestore) , m_historyMenuChanged(true) , m_bookmarksMenuChanged(true) , m_isClosing(false) , m_startingUrl(startUrl) + , m_startBehaviour(behaviour) , m_actionPrivateBrowsing(0) , m_webInspectorDock(0) , m_sideBar(0) @@ -136,7 +136,8 @@ void QupZilla::postLaunch() settings.endGroup(); QUrl startUrl; - if (m_tryRestore) { + switch (m_startBehaviour) { + case FirstAppWindow: if (afterLaunch == 0) startUrl = QUrl(""); else if (afterLaunch == 1) @@ -146,8 +147,23 @@ void QupZilla::postLaunch() if ( startingAfterCrash || (addTab && afterLaunch == 2) ) addTab = !mApp->restoreStateSlot(this); - } else - startUrl = m_homepage; + break; + + case NewWindow: + if (afterLaunch == 0) + startUrl = QUrl(""); + else if (afterLaunch == 1) + startUrl = m_homepage; + else + startUrl = m_homepage; + + addTab = true; + break; + + case OtherRestoredWindow: + addTab = false; + break; + } if (!m_startingUrl.isEmpty()) { startUrl = WebView::guessUrlFromString(m_startingUrl.toString()); diff --git a/src/app/qupzilla.h b/src/app/qupzilla.h index 1cb4de1bd..abbd09f73 100644 --- a/src/app/qupzilla.h +++ b/src/app/qupzilla.h @@ -79,7 +79,8 @@ public: static const QIcon qupzillaIcon(); - explicit QupZilla(bool m_tryRestore=true, QUrl startUrl=QUrl()); + enum StartBehaviour { FirstAppWindow, OtherRestoredWindow, NewWindow }; + explicit QupZilla(StartBehaviour behaviour = FirstAppWindow, QUrl startUrl = QUrl()); ~QupZilla(); void refreshAddressBar(); @@ -195,13 +196,13 @@ private: void addSideBar(); - bool m_tryRestore; bool m_historyMenuChanged; bool m_bookmarksMenuChanged; bool m_isClosing; QUrl m_startingUrl; QUrl m_newtab; QUrl m_homepage; + StartBehaviour m_startBehaviour; QVBoxLayout* m_mainLayout; QSplitter* m_mainSplitter;