summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-10-08 19:41:55 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:05 +0100
commit43b0121f717dda8a1f179fb585a3c78e3552430c (patch)
tree60b7132e4440685d7e905fae8afc7df447993748
parentSaving the "pinned" state in the sessionmanager (diff)
downloadrekonq-43b0121f717dda8a1f179fb585a3c78e3552430c.tar.xz
Restoring pinned tabs, yeah!!!! :D
-rw-r--r--src/application.cpp27
-rw-r--r--src/sessionmanager.cpp83
-rw-r--r--src/sessionmanager.h11
-rw-r--r--src/tabwindow/tabbar.cpp8
-rw-r--r--src/tabwindow/tabwindow.cpp9
5 files changed, 86 insertions, 52 deletions
diff --git a/src/application.cpp b/src/application.cpp
index 831df323..4f6f9651 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -135,9 +135,19 @@ int Application::newInstance()
}
}
- if (isFirstLoad && (ReKonfig::startupBehaviour() == 2) && SessionManager::self()->restoreSessionFromScratch())
+ if (isFirstLoad)
{
- isFirstLoad = false;
+ bool restoreOk = false;
+ if (ReKonfig::startupBehaviour() == 2)
+ {
+ restoreOk = SessionManager::self()->restoreSessionFromScratch();
+ }
+ else
+ {
+ restoreOk = SessionManager::self()->restoreJustThePinnedTabs();
+ }
+
+ isFirstLoad = restoreOk;
}
// first argument: 99% of the time we have just that...
@@ -183,13 +193,22 @@ int Application::newInstance()
// if NOT is Session restored...
if (!isSessionRestored())
{
+ bool restoreOk = false;
switch (ReKonfig::startupBehaviour())
{
case 0: // open home page
- loadUrl(KUrl(ReKonfig::homePage()) , Rekonq::NewWindow);
+ restoreOk = SessionManager::self()->restoreJustThePinnedTabs();
+ if (restoreOk)
+ loadUrl(KUrl(ReKonfig::homePage()) , Rekonq::NewTab);
+ else
+ loadUrl(KUrl(ReKonfig::homePage()) , Rekonq::NewWindow);
break;
case 1: // open new tab page
- loadUrl(KUrl("about:home"), Rekonq::NewWindow);
+ restoreOk = SessionManager::self()->restoreJustThePinnedTabs();
+ if (restoreOk)
+ loadUrl(KUrl("about:home"), Rekonq::NewTab);
+ else
+ loadUrl(KUrl("about:home"), Rekonq::NewWindow);
break;
case 2: // restore session
if (SessionManager::self()->restoreSessionFromScratch())
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);
}
diff --git a/src/sessionmanager.h b/src/sessionmanager.h
index dbff7e69..da60d889 100644
--- a/src/sessionmanager.h
+++ b/src/sessionmanager.h
@@ -67,10 +67,6 @@ public:
QList<TabHistory> closedSites();
- // This method restores session
- // while turning back from Private mode
- int restoreSavedSession();
-
// This method restores a single TabWindow
bool restoreTabWindow(TabWindow * window);
@@ -82,8 +78,13 @@ public Q_SLOTS:
// on restart when restore at startup is chosen
bool restoreSessionFromScratch();
-private Q_SLOTS:
+ // This method restores (eventually) the tabs present
+ // if there are NO pinned tabs to restore, it returns FALSE...
+ bool restoreJustThePinnedTabs();
+
void saveSession();
+
+private Q_SLOTS:
void save();
// This method restores session
diff --git a/src/tabwindow/tabbar.cpp b/src/tabwindow/tabbar.cpp
index 7e493fec..feb3fd8d 100644
--- a/src/tabwindow/tabbar.cpp
+++ b/src/tabwindow/tabbar.cpp
@@ -34,6 +34,7 @@
#include "webwindow.h"
#include "iconmanager.h"
+#include "sessionmanager.h"
#include <KAcceleratorManager>
#include <KAction>
@@ -511,7 +512,7 @@ void TabBar::pinTab()
tabButton(index, QTabBar::RightSide)->hide();
setTabText(index, QString());
- // workaround: "fix" the icon
+ // workaround: "fix" the icon (or at least, try to...)
QLabel *label = qobject_cast<QLabel* >(tabButton(index, QTabBar::LeftSide));
if (!label)
label = new QLabel(this);
@@ -522,6 +523,7 @@ void TabBar::pinTab()
KIcon ic = IconManager::self()->iconForUrl(w->webWindow(index)->url());
label->setPixmap(ic.pixmap(16, 16));
+ SessionManager::self()->saveSession();
}
@@ -554,7 +556,7 @@ void TabBar::unpinTab()
tabButton(index, QTabBar::RightSide)->show();
setTabText(index, w->webWindow(index)->title());
- // workaround: "fix" the icon
+ // workaround: "fix" the icon (or at least, try to...)
QLabel *label = qobject_cast<QLabel* >(tabButton(index, QTabBar::LeftSide));
if (!label)
label = new QLabel(this);
@@ -564,4 +566,6 @@ void TabBar::unpinTab()
KIcon ic = IconManager::self()->iconForUrl(w->webWindow(index)->url());
label->setPixmap(ic.pixmap(16, 16));
+
+ SessionManager::self()->saveSession();
}
diff --git a/src/tabwindow/tabwindow.cpp b/src/tabwindow/tabwindow.cpp
index 55d680b5..203da30a 100644
--- a/src/tabwindow/tabwindow.cpp
+++ b/src/tabwindow/tabwindow.cpp
@@ -331,9 +331,12 @@ void TabWindow::tabLoadFinished(bool ok)
QLabel *label = qobject_cast<QLabel* >(tabBar()->tabButton(index, QTabBar::LeftSide));
QMovie *movie = label->movie();
- movie->stop();
- delete movie;
-
+ if (movie)
+ {
+ movie->stop();
+ delete movie;
+ }
+
label->setMovie(0);
KIcon ic = IconManager::self()->iconForUrl(tab->url());