From 43b0121f717dda8a1f179fb585a3c78e3552430c Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 8 Oct 2012 19:41:55 +0200 Subject: Restoring pinned tabs, yeah!!!! :D --- src/sessionmanager.cpp | 83 +++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 38 deletions(-) (limited to 'src/sessionmanager.cpp') diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp index 5c93e2d0..7e13388e 100644 --- a/src/sessionmanager.cpp +++ b/src/sessionmanager.cpp @@ -74,36 +74,43 @@ bool readSessionDocument(QDomDocument & document, const QString & sessionFilePat } -int loadTabs(TabWindow *tw, QDomElement & window, bool useFirstTab) +int loadTabs(TabWindow *tw, QDomElement & window, bool useFirstTab, bool justThePinnedOnes = false) { int currentTab = 0; for (unsigned int tabNo = 0; tabNo < window.elementsByTagName("tab").length(); tabNo++) { QDomElement tab = window.elementsByTagName("tab").at(tabNo).toElement(); - if (tab.hasAttribute("currentTab")) - currentTab = tabNo; + bool tabIsPinned = tab.hasAttribute("pinned"); + kDebug() << "Tab # " << tabNo << " is pinned? " << tabIsPinned; - KUrl u = KUrl(tab.attribute("url")); + if (!justThePinnedOnes || tabIsPinned) + { + if (tab.hasAttribute("currentTab")) + currentTab = tabNo; - TabHistory tabHistory; - tabHistory.title = tab.attribute("title"); - tabHistory.url = tab.attribute("url"); - QDomCDATASection historySection = tab.firstChild().toCDATASection(); - tabHistory.history = QByteArray::fromBase64(historySection.data().toAscii()); + KUrl u = KUrl(tab.attribute("url")); - if (tabNo == 0 && useFirstTab) - { - tw->loadUrl(u, Rekonq::CurrentTab, &tabHistory); - } - else - { - tw->loadUrl(u, Rekonq::NewTab, &tabHistory); - } + TabHistory tabHistory; + tabHistory.title = tab.attribute("title"); + tabHistory.url = tab.attribute("url"); + QDomCDATASection historySection = tab.firstChild().toCDATASection(); + tabHistory.history = QByteArray::fromBase64(historySection.data().toAscii()); - if (tab.hasAttribute("pinned")) - { - tw->tabBar()->setTabData(tabNo, true); + if (tabNo == 0 && useFirstTab) + { + tw->loadUrl(u, Rekonq::CurrentTab, &tabHistory); + } + else + { + tw->loadUrl(u, Rekonq::NewTab, &tabHistory); + } + + if (tabIsPinned) + { + tw->tabBar()->setTabData(tabNo, true); + tw->tabBar()->tabButton(tabNo, QTabBar::RightSide)->hide(); // NOTE: this is not good here: where is its proper place? + } } } @@ -230,7 +237,7 @@ bool SessionManager::restoreSessionFromScratch() TabWindow *tw = rApp->newTabWindow(); - int currentTab = loadTabs(tw, window, false); + int currentTab = loadTabs(tw, window, true, false); tw->setCurrentIndex(currentTab); } @@ -239,53 +246,53 @@ bool SessionManager::restoreSessionFromScratch() } -void SessionManager::restoreCrashedSession() +bool SessionManager::restoreJustThePinnedTabs() { QDomDocument document("session"); if (!readSessionDocument(document, m_sessionFilePath)) - return; + return false; + bool done = false; for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++) { + done = true; QDomElement window = document.elementsByTagName("window").at(winNo).toElement(); - TabWindow *tw = (winNo == 0) - ? rApp->tabWindow() - : rApp->newTabWindow(); + TabWindow *tw = rApp->newTabWindow(); - KUrl u = tw->currentWebWindow()->url(); - bool useCurrentTab = (u.isEmpty() || u.protocol() == QL1S("about")); - int currentTab = loadTabs(tw, window, useCurrentTab); + int currentTab = loadTabs(tw, window, true, true); tw->setCurrentIndex(currentTab); } - setSessionManagementEnabled(true); + return done; } -int SessionManager::restoreSavedSession() +void SessionManager::restoreCrashedSession() { QDomDocument document("session"); if (!readSessionDocument(document, m_sessionFilePath)) - return 0; - - unsigned int winNo; + return; - for (winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++) + for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++) { QDomElement window = document.elementsByTagName("window").at(winNo).toElement(); - TabWindow *tw = rApp->newTabWindow(); + TabWindow *tw = (winNo == 0) + ? rApp->tabWindow() + : rApp->newTabWindow(); - int currentTab = loadTabs(tw, window, true); + KUrl u = tw->currentWebWindow()->url(); + bool useCurrentTab = (u.isEmpty() || u.protocol() == QL1S("about")); + int currentTab = loadTabs(tw, window, useCurrentTab); tw->setCurrentIndex(currentTab); } - return winNo; + setSessionManagementEnabled(true); } -- cgit v1.2.1