diff options
-rw-r--r-- | src/sessionmanager.cpp | 93 | ||||
-rw-r--r-- | src/sessionmanager.h | 6 | ||||
-rw-r--r-- | src/webwindow/rekonqui.rc | 7 | ||||
-rw-r--r-- | src/webwindow/webwindow.cpp | 10 |
4 files changed, 113 insertions, 3 deletions
diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp index 8c781720..9aa02560 100644 --- a/src/sessionmanager.cpp +++ b/src/sessionmanager.cpp @@ -369,3 +369,96 @@ QList<TabHistory> SessionManager::closedSitesForWindow(const QString &windowName return list; } + + +// ------------------------------------------------------------------------------------------------------- + + +bool SessionManager::saveYourSession() +{ + kDebug() << "SAVING YOUR OWN SESSION..."; + + const QString & sessionName = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/")); + + QFile sessionFile(sessionName + QL1S("prova")); // FIXME + if (!sessionFile.open(QFile::WriteOnly | QFile::Truncate)) + { + kDebug() << "Unable to open session file" << sessionFile.fileName(); + return true; + } + RekonqWindowList wl = rApp->rekonqWindowList(); + QDomDocument document("session"); + QDomElement session = document.createElement("session"); + document.appendChild(session); + + Q_FOREACH(const QWeakPointer<RekonqWindow> &w, wl) + { + if (w.data()->isPrivateBrowsingMode()) + continue; + + QDomElement window = document.createElement("window"); + int tabInserted = 0; + + window.setAttribute("name", w.data()->objectName()); + + TabWidget *tw = w.data()->tabWidget(); + for (signed int tabNo = 0; tabNo < tw->count(); tabNo++) + { + KUrl u = tw->webWindow(tabNo)->url(); + + tabInserted++; + QDomElement tab = document.createElement("tab"); + tab.setAttribute("title", tw->webWindow(tabNo)->title()); // redundant, but needed for closedSites() + // as there's not way to read out the historyData + tab.setAttribute("url", u.url()); + if (tw->currentIndex() == tabNo) + { + tab.setAttribute("currentTab", 1); + } + if (tw->tabBar()->tabData(tabNo).toBool()) // pinned tab info + { + tab.setAttribute("pinned", 1); + } + QByteArray history; + QDataStream historyStream(&history, QIODevice::ReadWrite); + historyStream << *(tw->webWindow(tabNo)->page()->history()); + QDomCDATASection historySection = document.createCDATASection(history.toBase64()); + + tab.appendChild(historySection); + window.appendChild(tab); + } + + if (tabInserted > 0) + session.appendChild(window); + } + + QTextStream TextStream(&sessionFile); + document.save(TextStream, 2); + sessionFile.close(); + + return true; + +} + + +bool SessionManager::restoreYourSession() +{ + const QString & sessionName = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/")); + QDomDocument document("session"); + + if (!readSessionDocument(document,sessionName + QL1S("prova"))) // FIXME + return false; + + for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++) + { + QDomElement window = document.elementsByTagName("window").at(winNo).toElement(); + + RekonqWindow *tw = rApp->newWindow(); + + int currentTab = loadTabs(tw, window, true, false); + + tw->tabWidget()->setCurrentIndex(currentTab); + } + + return true; +} diff --git a/src/sessionmanager.h b/src/sessionmanager.h index 6d6bef26..22665dc4 100644 --- a/src/sessionmanager.h +++ b/src/sessionmanager.h @@ -77,11 +77,9 @@ public Q_SLOTS: // This method restores session // on restart when restore at startup is chosen bool restoreSessionFromScratch(); - // 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: @@ -89,9 +87,11 @@ private Q_SLOTS: // after a crash void restoreCrashedSession(); + bool saveYourSession(); + bool restoreYourSession(); + private: QString m_sessionFilePath; - bool m_safe; bool m_isSessionEnabled; diff --git a/src/webwindow/rekonqui.rc b/src/webwindow/rekonqui.rc index 90c5c192..72ae6672 100644 --- a/src/webwindow/rekonqui.rc +++ b/src/webwindow/rekonqui.rc @@ -30,6 +30,13 @@ <text>&Tools</text> <Action name="clear_private_data" /> <Separator/> + + <Menu name="sessionMenu" noMerge="1"> + <text>&Sessions</text> + <Action name="session_save" /> + <Action name="session_manage" /> + </Menu> + <Action name="webapp_shortcut" /> <Action name="web_inspector" /> <Action name="page_source" /> diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index 1225fb07..da7a1bc5 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -40,6 +40,7 @@ #include "iconmanager.h" #include "syncmanager.h" #include "useragentmanager.h" +#include "sessionmanager.h" #include "webpage.h" #include "webtab.h" @@ -279,6 +280,15 @@ void WebWindow::setupActions() actionCollection()->addAction(QL1S("open_location"), a); connect(a, SIGNAL(triggered(bool)) , this, SLOT(openLocation())); + // User sessions management + a = new KAction(KIcon("document-save"), i18n("&Save Session"), this); + actionCollection()->addAction(QL1S("session_save"), a); + connect(a, SIGNAL(triggered(bool)), SessionManager::self(), SLOT(saveYourSession())); + + a = new KAction(KIcon("view-choose"), i18n("&Manage Session"), this); + actionCollection()->addAction(QL1S("session_manage"), a); + connect(a, SIGNAL(triggered(bool)), SessionManager::self(), SLOT(restoreYourSession())); + // ===== Tools Actions ================================= a = new KAction(i18n("View Page S&ource"), this); a->setIcon(KIcon("application-xhtml+xml")); |