summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-02-09 12:33:43 +0100
committerAndrea Diamantini <adjam7@gmail.com>2012-02-09 12:33:43 +0100
commitcb21e318076c30c906582ad3ce6e138ed5f6ce65 (patch)
treece524f1e1d445c92e78b9fdb036141377745faa8
parentGet SURE window exists (diff)
downloadrekonq-cb21e318076c30c906582ad3ce6e138ed5f6ce65.tar.xz
Clean up sessionmanager mess :)
Create a local function to get rid of code repetition. I know this is a bit hackish (at least the way I did it) but it works well in my tests against the three situations: - restore crashed sessions - restore saved sessions - restore from private sessions - restore user sessions (restarting KDE)
-rw-r--r--src/newtabpage.cpp2
-rw-r--r--src/sessionmanager.cpp124
2 files changed, 42 insertions, 84 deletions
diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp
index 7392c920..f22f0d50 100644
--- a/src/newtabpage.cpp
+++ b/src/newtabpage.cpp
@@ -537,8 +537,6 @@ void NewTabPage::tabsPage()
for (int i = 0; i < tabCount; ++i)
{
KUrl url = w->mainView()->webTab(i)->url();
- if (url.protocol() == QL1S("about"))
- continue;
if (!WebSnap::existsImage(url))
{
diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp
index 0557fcb4..b0ef1fce 100644
--- a/src/sessionmanager.cpp
+++ b/src/sessionmanager.cpp
@@ -43,6 +43,7 @@
// Qt Includes
#include <QtCore/QFile>
+
// Only used internally
bool readSessionDocument(QDomDocument & document, const QString & sessionFilePath)
{
@@ -66,6 +67,41 @@ bool readSessionDocument(QDomDocument & document, const QString & sessionFilePat
return true;
}
+
+int loadViewTabs(MainView *mv, QDomElement & window, bool checkViewExists)
+{
+ 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;
+
+ WebView * view = 0;
+ if (tabNo == 0 && checkViewExists)
+ view = mv->webTab(0)->view();
+ else
+ view = mv->newWebTab()->view();
+
+ QDomCDATASection historySection = tab.firstChild().toCDATASection();
+ QByteArray history = QByteArray::fromBase64(historySection.data().toAscii());
+
+ QDataStream readingStream(&history, QIODevice::ReadOnly);
+ readingStream >> *(view->history());
+
+ // Get sure about urls and/or pdf are loaded
+ KUrl u = KUrl(tab.attribute("url"));
+ view->load(u);
+ }
+
+ return currentTab;
+}
+
+
+// ---------------------------------------------------------------------
+
+
SessionManager::SessionManager(QObject *parent)
: QObject(parent)
, m_safe(true)
@@ -105,10 +141,7 @@ void SessionManager::saveSession()
for (signed int tabNo = 0; tabNo < mv->count(); tabNo++)
{
- // IGNORE about urls
KUrl u = mv->webTab(tabNo)->url();
- if (u.protocol() == QL1S("about"))
- continue;
tabInserted++;
QDomElement tab = document.createElement("tab");
@@ -150,32 +183,10 @@ bool SessionManager::restoreSessionFromScratch()
for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++)
{
QDomElement window = document.elementsByTagName("window").at(winNo).toElement();
- int currentTab = 0;
MainView *mv = rApp->newMainWindow(false)->mainView();
- 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;
-
- WebView *view = mv->newWebTab()->view();
-
- QDomCDATASection historySection = tab.firstChild().toCDATASection();
- QByteArray history = QByteArray::fromBase64(historySection.data().toAscii());
-
- QDataStream readingStream(&history, QIODevice::ReadOnly);
- readingStream >> *(view->history());
-
- // IGNORE "eventual" about urls
- KUrl u = KUrl(tab.attribute("url"));
- if (u.protocol() == QL1S("about"))
- continue;
-
- // This is needed for particular URLs, eg pdfs
- view->load(u);
- }
+ int currentTab = loadViewTabs(mv, window, false);
mv->tabBar()->setCurrentIndex(currentTab);
}
@@ -194,28 +205,11 @@ void SessionManager::restoreCrashedSession()
for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++)
{
QDomElement window = document.elementsByTagName("window").at(winNo).toElement();
- int currentTab = 0;
MainView *mv = (winNo == 0) ? rApp->mainWindow()->mainView() : rApp->newMainWindow()->mainView();
- 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;
-
- WebView *view = (tabNo == 0) ? mv->webTab(0)->view() : mv->newWebTab()->view();
-
- QDomCDATASection historySection = tab.firstChild().toCDATASection();
- QByteArray history = QByteArray::fromBase64(historySection.data().toAscii());
+ int currentTab = loadViewTabs(mv, window, true);
- QDataStream readingStream(&history, QIODevice::ReadOnly);
- readingStream >> *(view->history());
-
- // Get sure about urls and/or pdf are loaded
- KUrl u = KUrl(tab.attribute("url"));
- view->load(u);
- }
mv->tabBar()->setCurrentIndex(currentTab);
}
@@ -235,34 +229,18 @@ int SessionManager::restoreSavedSession()
for (winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++)
{
QDomElement window = document.elementsByTagName("window").at(winNo).toElement();
- int currentTab = 0;
MainView *mv = rApp->newMainWindow()->mainView();
- 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;
-
- WebView *view = (tabNo == 0) ? mv->webTab(0)->view() : mv->newWebTab()->view();
-
- QDomCDATASection historySection = tab.firstChild().toCDATASection();
- QByteArray history = QByteArray::fromBase64(historySection.data().toAscii());
+ int currentTab = loadViewTabs(mv, window, true);
- QDataStream readingStream(&history, QIODevice::ReadOnly);
- readingStream >> *(view->history());
-
- // Get sure about urls and/or pdfs are loaded
- KUrl u = KUrl(tab.attribute("url"));
- view->load(u);
- }
mv->tabBar()->setCurrentIndex(currentTab);
}
return winNo;
}
+
bool SessionManager::restoreMainWindow(MainWindow* window)
{
QDomDocument document("session");
@@ -275,32 +253,13 @@ bool SessionManager::restoreMainWindow(MainWindow* window)
for (winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++)
{
QDomElement savedWindowElement = document.elementsByTagName("window").at(winNo).toElement();
- int currentTab = 0;
if (window->objectName() != savedWindowElement.attribute("name", ""))
continue;
MainView *mv = window->mainView();
- for (unsigned int tabNo = 0; tabNo < savedWindowElement.elementsByTagName("tab").length(); tabNo++)
- {
- QDomElement tab = savedWindowElement.elementsByTagName("tab").at(tabNo).toElement();
- if (tab.hasAttribute("currentTab"))
- currentTab = tabNo;
-
- WebView *view = mv->newWebTab()->view();
-
- QDomCDATASection historySection = tab.firstChild().toCDATASection();
- QByteArray history = QByteArray::fromBase64(historySection.data().toAscii());
-
- QDataStream readingStream(&history, QIODevice::ReadOnly);
- readingStream >> *(view->history());
-
- // Get sure about urls are loaded
- KUrl u = KUrl(tab.attribute("url"));
- if (u.protocol() == QL1S("about"))
- view->load(u);
- }
+ int currentTab = loadViewTabs(mv, savedWindowElement, false);
mv->tabBar()->setCurrentIndex(currentTab);
@@ -310,6 +269,7 @@ bool SessionManager::restoreMainWindow(MainWindow* window)
return false;
}
+
QList<TabHistory> SessionManager::closedSites()
{
QList<TabHistory> list;