From 72219b94111542eb45cf8b93ad12c47f1d33aaa8 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 27 Sep 2011 13:00:01 +0200 Subject: Fix session manager restore I think we need to consider the two cases (normal restore vs restore from crash) in different ways. --- src/sessionmanager.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'src/sessionmanager.cpp') diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp index c4697f4b..0548db3d 100644 --- a/src/sessionmanager.cpp +++ b/src/sessionmanager.cpp @@ -103,7 +103,7 @@ void SessionManager::saveSession() } -bool SessionManager::restoreSession() +bool SessionManager::restoreSessionFromScratch() { QFile sessionFile(m_sessionFilePath); if (!sessionFile.exists()) @@ -166,6 +166,65 @@ bool SessionManager::restoreSession() } +void SessionManager::restoreCrashedSession() +{ + setSessionManagementEnabled(true); + + QFile sessionFile(m_sessionFilePath); + if (!sessionFile.exists()) + { + kDebug() << "Unable to find session file" << sessionFile.fileName(); + return; + } + + if (!sessionFile.open(QFile::ReadOnly)) + { + kDebug() << "Unable to open session file" << sessionFile.fileName(); + return; + } + + QDomDocument document("session"); + if (!document.setContent(&sessionFile, false)) + { + kDebug() << "Unable to parse session file" << sessionFile.fileName(); + return; + } + + setSessionManagementEnabled(false); + + 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()); + + 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); + } + mv->tabBar()->setCurrentIndex(currentTab); + } + + setSessionManagementEnabled(true); +} + + QList SessionManager::closedSites() { QList list; -- cgit v1.2.1