1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-22 02:02:10 +02:00

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.
This commit is contained in:
David Rosca 2015-09-27 18:46:16 +02:00
parent 94bac52e1f
commit 6d37ab5ce4
5 changed files with 41 additions and 21 deletions

View File

@ -196,8 +196,7 @@ void BrowserWindow::postLaunch()
addTab = !mApp->restoreSession(this, mApp->restoreManager()->restoreData()); addTab = !mApp->restoreSession(this, mApp->restoreManager()->restoreData());
} }
else { else {
// Pinned tabs are restored in MainApplication::restoreStateSlot // Restore pinned tabs also when not restoring session
// Make sure they will be restored also when not restoring session
m_tabWidget->restorePinnedTabs(); m_tabWidget->restorePinnedTabs();
} }
break; break;

View File

@ -714,10 +714,19 @@ void MainApplication::saveSession()
} }
} }
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(); BrowserWindow* qupzilla_ = getWindow();
if (qupzilla_ && m_windows.count() == 1) { if (qupzilla_ && m_windows.count() == 1) {
qupzilla_->tabWidget()->savePinnedTabs(); qupzilla_->tabWidget()->savePinnedTabs();
} }
}
QFile file(DataPaths::currentProfilePath() + QLatin1String("/session.dat")); QFile file(DataPaths::currentProfilePath() + QLatin1String("/session.dat"));
file.open(QIODevice::WriteOnly); file.open(QIODevice::WriteOnly);

View File

@ -814,9 +814,8 @@ QByteArray TabWidget::saveState()
for (int i = 0; i < count(); ++i) { for (int i = 0; i < count(); ++i) {
WebTab* webTab = weTab(i); WebTab* webTab = weTab(i);
if (!webTab || webTab->isPinned()) { if (!webTab)
continue; continue;
}
WebTab::SavedTab tab(webTab); WebTab::SavedTab tab(webTab);
tabList.append(tab); tabList.append(tab);
@ -838,17 +837,14 @@ QByteArray TabWidget::saveState()
bool TabWidget::restoreState(const QVector<WebTab::SavedTab> &tabs, int currentTab) bool TabWidget::restoreState(const QVector<WebTab::SavedTab> &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) { for (int i = 0; i < tabs.size(); ++i) {
WebTab::SavedTab tab = tabs.at(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); weTab(index)->restoreTab(tab);
if (tab.isPinned)
m_tabBar->updatePinnedTabCloseButton(index);
} }
setCurrentIndex(currentTab); setCurrentIndex(currentTab);

View File

@ -34,7 +34,12 @@
#include <QTimer> #include <QTimer>
#include <QSplitter> #include <QSplitter>
static const int savedTabVersion = 1; static const int savedTabVersion = 2;
WebTab::SavedTab::SavedTab()
: isPinned(false)
{
}
WebTab::SavedTab::SavedTab(WebTab* webTab) WebTab::SavedTab::SavedTab(WebTab* webTab)
{ {
@ -42,11 +47,12 @@ WebTab::SavedTab::SavedTab(WebTab* webTab)
url = webTab->url(); url = webTab->url();
icon = webTab->icon(); icon = webTab->icon();
history = webTab->historyData(); 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() void WebTab::SavedTab::clear()
@ -55,6 +61,7 @@ void WebTab::SavedTab::clear()
url.clear(); url.clear();
icon = QIcon(); icon = QIcon();
history.clear(); history.clear();
isPinned = false;
} }
QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab) 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.url;
stream << tab.icon.pixmap(16); stream << tab.icon.pixmap(16);
stream << tab.history; stream << tab.history;
stream << tab.isPinned;
return stream; return stream;
} }
@ -73,12 +81,18 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
int version; int version;
stream >> version; stream >> version;
if (version < 1)
return stream;
QPixmap pixmap; QPixmap pixmap;
stream >> tab.title; stream >> tab.title;
stream >> tab.url; stream >> tab.url;
stream >> pixmap; stream >> pixmap;
stream >> tab.history; stream >> tab.history;
if (version >= 2)
stream >> tab.isPinned;
tab.icon = QIcon(pixmap); tab.icon = QIcon(pixmap);
return stream; return stream;
@ -255,14 +269,14 @@ TabIcon* WebTab::tabIcon() const
bool WebTab::isRestored() const bool WebTab::isRestored() const
{ {
return m_savedTab.isEmpty(); return !m_savedTab.isValid();
} }
void WebTab::restoreTab(const WebTab::SavedTab &tab) void WebTab::restoreTab(const WebTab::SavedTab &tab)
{ {
Q_ASSERT(m_tabBar); Q_ASSERT(m_tabBar);
if (qzSettings->loadTabsOnActivation) { if (!tab.isPinned && qzSettings->loadTabsOnActivation) {
m_savedTab = tab; m_savedTab = tab;
int index = tabIndex(); 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) void WebTab::p_restoreTab(const WebTab::SavedTab &tab)
{ {
p_restoreTab(tab.url, tab.history); p_restoreTab(tab.url, tab.history);
m_isPinned = tab.isPinned;
} }
QPixmap WebTab::renderTabPreview() QPixmap WebTab::renderTabPreview()

View File

@ -44,11 +44,12 @@ public:
QUrl url; QUrl url;
QIcon icon; QIcon icon;
QByteArray history; QByteArray history;
bool isPinned;
SavedTab() { } SavedTab();
SavedTab(WebTab* webTab); SavedTab(WebTab* webTab);
bool isEmpty() const; bool isValid() const;
void clear(); void clear();
friend QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const SavedTab &tab); friend QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const SavedTab &tab);