diff options
-rw-r--r-- | src/application.cpp | 15 | ||||
-rw-r--r-- | src/sessionmanager.cpp | 61 | ||||
-rw-r--r-- | src/sessionmanager.h | 7 | ||||
-rw-r--r-- | src/webtab.cpp | 2 |
4 files changed, 75 insertions, 10 deletions
diff --git a/src/application.cpp b/src/application.cpp index 627536da..985de818 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -223,7 +223,7 @@ int Application::newInstance() loadUrl(KUrl("about:home"), Rekonq::NewWindow); break; case 2: // restore session - if (sessionManager()->restoreSession()) + if (sessionManager()->restoreSessionFromScratch()) { break; } @@ -251,6 +251,11 @@ int Application::newInstance() } } + if (!isRekonqCrashed) + { + sessionManager()->setSessionManagementEnabled(true); + } + if (isFirstLoad) { // give me some time to do the other things.. @@ -275,7 +280,6 @@ void Application::postLaunch() setWindowIcon(KIcon("rekonq")); historyManager(); - sessionManager()->setSessionManagementEnabled(true); // bookmarks loading connect(bookmarkProvider(), SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType&)), @@ -668,7 +672,9 @@ void Application::setPrivateBrowsingMode(bool b) QString text = i18n("<b>%1</b>" "<p>rekonq will save your current tabs for when you'll stop private browsing the net.</p>", caption); - int button = KMessageBox::warningContinueCancel(mainWindow(), text, caption, KStandardGuiItem::cont(), KStandardGuiItem::cancel(), i18n("don't ask again")); + int button = KMessageBox::warningContinueCancel(mainWindow(), + text, caption, KStandardGuiItem::cont(), KStandardGuiItem::cancel(), + i18n("don't ask again")); if (button != KMessageBox::Continue) return; @@ -691,8 +697,7 @@ void Application::setPrivateBrowsingMode(bool b) settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, false); _privateBrowsingAction->setChecked(false); - loadUrl(KUrl("about:blank"), Rekonq::NewWindow); - if (!sessionManager()->restoreSession()) + if (!sessionManager()->restoreSessionFromScratch()) loadUrl(KUrl("about:home"), Rekonq::NewWindow); } } 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<TabHistory> SessionManager::closedSites() { QList<TabHistory> list; diff --git a/src/sessionmanager.h b/src/sessionmanager.h index fa23623e..ae6caaa2 100644 --- a/src/sessionmanager.h +++ b/src/sessionmanager.h @@ -57,11 +57,12 @@ public: QList<TabHistory> closedSites(); -public slots: - bool restoreSession(); +public Q_SLOTS: + bool restoreSessionFromScratch(); -private slots: +private Q_SLOTS: void saveSession(); + void restoreCrashedSession(); private: QString m_sessionFilePath; diff --git a/src/webtab.cpp b/src/webtab.cpp index 9b1a31f9..61c9077f 100644 --- a/src/webtab.cpp +++ b/src/webtab.cpp @@ -310,5 +310,5 @@ void WebTab::showMessageBar() qobject_cast<QVBoxLayout *>(layout())->insertWidget(0, msgBar); msgBar->animatedShow(); - connect(msgBar, SIGNAL(accepted()), rApp->sessionManager(), SLOT(restoreSession())); + connect(msgBar, SIGNAL(accepted()), rApp->sessionManager(), SLOT(restoreCrashedSession())); } |