From f0a7c1760a0186ebfb7d80da34d6675b6d987303 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 28 Nov 2018 16:31:48 +0100 Subject: Remove old session code --- src/session/session.cpp | 78 ++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 46 deletions(-) (limited to 'src/session/session.cpp') diff --git a/src/session/session.cpp b/src/session/session.cpp index 0853c70..10aca4e 100644 --- a/src/session/session.cpp +++ b/src/session/session.cpp @@ -19,46 +19,7 @@ #include #include "configuration.h" -QJsonObject Session::session(QVector windows) -{ - QJsonObject obj; - - QJsonArray windowsArray; - for(const MainWindow *window : windows) { - windowsArray.append(Session::window(window)); - } - obj.insert("windows", windowsArray); - - return obj; -} - -QJsonObject Session::window(const MainWindow *window) -{ - QJsonObject obj; - auto *profileManager = dynamic_cast(qApp)->getProfileManager(); - - QJsonArray subwindows; - for(const SubWindow *subwindow : window->subWindows()) { - QJsonObject window; - window.insert("profile", profileManager->id(subwindow->profile())); - - QJsonArray tabs; - for(int i = 0; i < subwindow->tabCount(); ++i) { - QJsonObject tab; - tab.insert("url", subwindow->view(i)->url().toString()); - tab.insert("profile", profileManager->id(subwindow->view(i)->profile())); - tabs.append(tab); - } - window.insert("tabs", tabs); - - subwindows.append(window); - } - obj.insert("subwindows", subwindows); - - return obj; -} - -QJsonObject Session::window(const QString &profile, const QStringList &urls) +QJsonObject Session::fromCommandLine(const QString &profile, const QStringList &urls) { QJsonObject session; @@ -162,10 +123,15 @@ void Session::restoreView(WebView *view, const QJsonObject &data) if(profile) view->setProfile(profile); - // restore history: toLatin1 (turn into bytearray), fromBase64, uncompress - QByteArray historyData = qUncompress(QByteArray::fromBase64(data["history"].toString().toLatin1())); - QDataStream historyStream(&historyData, QIODevice::ReadOnly); - historyStream >> *view->history(); + auto url = data.value("url"); + if(url.isString()) + view->load(QUrl::fromUserInput(url.toString())); + else { + // restore history: toLatin1 (turn into bytearray), fromBase64, uncompress + QByteArray historyData = qUncompress(QByteArray::fromBase64(data["history"].toString().toLatin1())); + QDataStream historyStream(&historyData, QIODevice::ReadOnly); + historyStream >> *view->history(); + } } void Session::restoreSession(const QJsonObject &sessionData) @@ -175,12 +141,32 @@ void Session::restoreSession(const QJsonObject &sessionData) auto *profileManager = browser->getProfileManager(); Q_CHECK_PTR(profileManager); + for(const auto subwindowData : sessionData["subwindows"].toArray()) { + MainWindow *window = nullptr; + SubWindow *subwindow = nullptr; + + if(!browser->windows().isEmpty()) { + window = browser->windows().last(); + subwindow = window->currentSubWindow(); + } else { + window = browser->createWindow(); + subwindow = window->createSubWindow(browser->getConfiguration(), profileManager->profile(subwindowData.toObject()["profile"].toString())); + } + + Q_CHECK_PTR(window); + Q_CHECK_PTR(subwindow); + + for(const auto tabData : subwindowData.toObject()["tabs"].toArray()) { + auto *view = subwindow->view(subwindow->addTab()); + Session::restoreView(view, tabData.toObject()); + } + } + for(const auto windowData : sessionData["windows"].toArray()) { auto *window = browser->createWindow(); for(const auto subwindowData : windowData.toObject()["subwindows"].toArray()) { - auto *subwindow = window->createSubWindow(browser->getConfiguration(), WebProfile::defaultProfile()); - subwindow->setProfile(profileManager->profile(subwindowData.toObject()["profile"].toString())); + auto *subwindow = window->createSubWindow(browser->getConfiguration(), profileManager->profile(subwindowData.toObject()["profile"].toString())); for(const auto tabData : subwindowData.toObject()["tabs"].toArray()) { auto *view = subwindow->view(subwindow->addTab()); -- cgit v1.2.1