From 6d37ab5ce4f646d4eaba700f1c918c23bec1787a Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sun, 27 Sep 2015 18:46:16 +0200 Subject: [PATCH] Save pinned tabs per window if restoring session on start No more pinned tabs restoring on wrong window. Also it is now possible to have different pinned tabs on each window. --- src/lib/app/browserwindow.cpp | 3 +-- src/lib/app/mainapplication.cpp | 15 ++++++++++++--- src/lib/tabwidget/tabwidget.cpp | 14 +++++--------- src/lib/webtab/webtab.cpp | 25 ++++++++++++++++++++----- src/lib/webtab/webtab.h | 5 +++-- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index c5608dd9e..84bc65587 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -196,8 +196,7 @@ void BrowserWindow::postLaunch() addTab = !mApp->restoreSession(this, mApp->restoreManager()->restoreData()); } else { - // Pinned tabs are restored in MainApplication::restoreStateSlot - // Make sure they will be restored also when not restoring session + // Restore pinned tabs also when not restoring session m_tabWidget->restorePinnedTabs(); } break; diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index e4c7d8acf..421e3e7fe 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -714,9 +714,18 @@ void MainApplication::saveSession() } } - BrowserWindow* qupzilla_ = getWindow(); - if (qupzilla_ && m_windows.count() == 1) { - qupzilla_->tabWidget()->savePinnedTabs(); + int afterLaunch = Settings().value("Web-URL-Settings/afterLaunch", 3).toInt(); + + if (afterLaunch == 3) { + // Pinned tabs are saved into session.dat, so remove the old saved pinned tabs + QFile::remove(DataPaths::currentProfilePath() + QL1S("/pinnedtabs.dat")); + } + else { + // Pinned tabs are saved only for last window into pinnedtabs.dat + BrowserWindow* qupzilla_ = getWindow(); + if (qupzilla_ && m_windows.count() == 1) { + qupzilla_->tabWidget()->savePinnedTabs(); + } } QFile file(DataPaths::currentProfilePath() + QLatin1String("/session.dat")); diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index 8887e02c4..f8f595e76 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -814,9 +814,8 @@ QByteArray TabWidget::saveState() for (int i = 0; i < count(); ++i) { WebTab* webTab = weTab(i); - if (!webTab || webTab->isPinned()) { + if (!webTab) continue; - } WebTab::SavedTab tab(webTab); tabList.append(tab); @@ -838,17 +837,14 @@ QByteArray TabWidget::saveState() bool TabWidget::restoreState(const QVector &tabs, int currentTab) { - Qz::BrowserWindowType type = m_window->windowType(); - - if (type == Qz::BW_FirstAppWindow || type == Qz::BW_MacFirstWindow) { - restorePinnedTabs(); - } - for (int i = 0; i < tabs.size(); ++i) { WebTab::SavedTab tab = tabs.at(i); - int index = addView(QUrl(), Qz::NT_CleanSelectedTab); + int index = addView(QUrl(), Qz::NT_CleanSelectedTab, false, tab.isPinned); weTab(index)->restoreTab(tab); + + if (tab.isPinned) + m_tabBar->updatePinnedTabCloseButton(index); } setCurrentIndex(currentTab); diff --git a/src/lib/webtab/webtab.cpp b/src/lib/webtab/webtab.cpp index fba1b86a2..83a92806c 100644 --- a/src/lib/webtab/webtab.cpp +++ b/src/lib/webtab/webtab.cpp @@ -34,7 +34,12 @@ #include #include -static const int savedTabVersion = 1; +static const int savedTabVersion = 2; + +WebTab::SavedTab::SavedTab() + : isPinned(false) +{ +} WebTab::SavedTab::SavedTab(WebTab* webTab) { @@ -42,11 +47,12 @@ WebTab::SavedTab::SavedTab(WebTab* webTab) url = webTab->url(); icon = webTab->icon(); history = webTab->historyData(); + isPinned = webTab->isPinned(); } -bool WebTab::SavedTab::isEmpty() const +bool WebTab::SavedTab::isValid() const { - return url.isEmpty(); + return !url.isEmpty(); } void WebTab::SavedTab::clear() @@ -55,6 +61,7 @@ void WebTab::SavedTab::clear() url.clear(); icon = QIcon(); history.clear(); + isPinned = false; } QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab) @@ -64,6 +71,7 @@ QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab) stream << tab.url; stream << tab.icon.pixmap(16); stream << tab.history; + stream << tab.isPinned; return stream; } @@ -73,12 +81,18 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab) int version; stream >> version; + if (version < 1) + return stream; + QPixmap pixmap; stream >> tab.title; stream >> tab.url; stream >> pixmap; stream >> tab.history; + if (version >= 2) + stream >> tab.isPinned; + tab.icon = QIcon(pixmap); return stream; @@ -255,14 +269,14 @@ TabIcon* WebTab::tabIcon() const bool WebTab::isRestored() const { - return m_savedTab.isEmpty(); + return !m_savedTab.isValid(); } void WebTab::restoreTab(const WebTab::SavedTab &tab) { Q_ASSERT(m_tabBar); - if (qzSettings->loadTabsOnActivation) { + if (!tab.isPinned && qzSettings->loadTabsOnActivation) { m_savedTab = tab; int index = tabIndex(); @@ -297,6 +311,7 @@ void WebTab::p_restoreTab(const QUrl &url, const QByteArray &history) void WebTab::p_restoreTab(const WebTab::SavedTab &tab) { p_restoreTab(tab.url, tab.history); + m_isPinned = tab.isPinned; } QPixmap WebTab::renderTabPreview() diff --git a/src/lib/webtab/webtab.h b/src/lib/webtab/webtab.h index 4802f8e99..842453b13 100644 --- a/src/lib/webtab/webtab.h +++ b/src/lib/webtab/webtab.h @@ -44,11 +44,12 @@ public: QUrl url; QIcon icon; QByteArray history; + bool isPinned; - SavedTab() { } + SavedTab(); SavedTab(WebTab* webTab); - bool isEmpty() const; + bool isValid() const; void clear(); friend QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const SavedTab &tab);