From 5825451aef1a762bfaeff2d37c09b3790deee7b1 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 26 Jun 2018 19:51:52 +0200 Subject: Socket messages are json formatted --- src/browser.cpp | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'src/browser.cpp') diff --git a/src/browser.cpp b/src/browser.cpp index 73b466f..fe103a8 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -24,6 +24,7 @@ #include #include #include "profilemanager.h" +#include Browser::Browser(int &argc, char *argv[]) : SingleApplication(argc, argv) @@ -128,27 +129,39 @@ void Browser::setup(const QString &defaultProfile) connect(WebProfile::defaultProfile(), &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); } -void Browser::createSession(const QString &profileName, bool newWindow, const QStringList &urls) +void Browser::createSession(const QJsonObject &object) { - if(m_windows.isEmpty()) { - createWindow(); - } - - auto *mainwindow = m_windows.last(); - if(newWindow) { - QString firstUrl; // = WebProfile::defaultProfile()->homepage(); - if(!urls.isEmpty()) - firstUrl = urls.at(0); - auto *w = mainwindow->createSubWindow(firstUrl); - for(int i = 1; i < urls.count() - 1; i++) { - w->addTab(QUrl::fromUserInput(urls.at(i))); + MainWindow *mainwindow = nullptr; + if(m_windows.isEmpty()) + mainwindow = createWindow(); + else + mainwindow = m_windows.last(); + + const QJsonArray subwindows = object.value("subwindows").toArray(); + + for(const QJsonValue &s : subwindows) { + const QJsonObject subwindow = s.toObject(); + const QString profileId = subwindow.value("profile").toString(); + WebProfile *profile = ProfileManager::profile(profileId); + Q_CHECK_PTR(profile); + + SubWindow *window = nullptr; + for(SubWindow *w : mainwindow->subWindows()) { + if(w->profile() == profile) { + window = w; + break; + } } - } else { - if(urls.isEmpty()) - mainwindow->createTab(WebProfile::defaultProfile()->homepage()); + if(window == nullptr) + window = mainwindow->createSubWindow(profile); + + const QJsonArray tabs = subwindow.value("tabs").toArray(); + if(tabs.isEmpty()) + window->addTab(profile->newtab()); else { - for(const QString &url : urls) { - mainwindow->createTab(QUrl::fromUserInput(url)); + for(const QJsonValue &t : subwindow.value("tabs").toArray()) { + const QJsonObject tab = t.toObject(); + window->addTab(QUrl::fromUserInput(tab.value("url").toString())); } } } -- cgit v1.2.1