From 1581e94b9ac98f5d385a71a5bfbde81da22da2b2 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 24 Jun 2018 18:42:40 +0200 Subject: Add ProfileManager --- src/mainwindow/subwindow.cpp | 45 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) (limited to 'src/mainwindow/subwindow.cpp') diff --git a/src/mainwindow/subwindow.cpp b/src/mainwindow/subwindow.cpp index cbfe46a..354e07e 100644 --- a/src/mainwindow/subwindow.cpp +++ b/src/mainwindow/subwindow.cpp @@ -19,6 +19,7 @@ #include #include #include +#include "profilemanager.h" SubWindow::SubWindow(const QHash &config, QWidget *parent, Qt::WindowFlags flags) : QMdiSubWindow(parent, flags) @@ -44,12 +45,15 @@ SubWindow::SubWindow(const QHash &config, QWidget *parent, Qt: Browser *browser = qobject_cast(qApp); Q_CHECK_PTR(browser); - for(const QString &name : browser->profiles()) { - auto *loadAction = loadProfile_menu->addAction(name); - connect(loadAction, &QAction::triggered, this, [name, browser, profileName_action, this]() { - auto *profile = browser->profile(name); + ProfileIterator it(ProfileManager::profileList()); + while(it.hasNext()) { + it.next(); + auto *profile =it.value(); + auto *loadAction = loadProfile_menu->addAction(profile->name()); + + connect(loadAction, &QAction::triggered, this, [=]() { this->setProfile(profile); - profileName_action->setText(tr("Profile: %1").arg(name)); + profileName_action->setText(tr("Profile: %1").arg(profile->name())); }); } } @@ -149,14 +153,14 @@ void SubWindow::setCurrentTab(int index) QJsonObject SubWindow::session() const { QJsonObject obj; - obj.insert("profile", profile->id()); + obj.insert("profile", ProfileManager::id(profile)); QJsonArray tabs; for(int i = 0; i < tabWidget->count(); ++i) { auto *view = qobject_cast(tabWidget->widget(i)); if(view) { QJsonObject tab; - tab.insert(view->url().toString(), view->profile()->id()); + tab.insert(view->url().toString(), ProfileManager::id(view->profile())); tabs.append(tab); } } @@ -164,30 +168,3 @@ QJsonObject SubWindow::session() const return obj; } - -void SubWindow::restoreSession(const QJsonObject &sessionData) -{ - auto *browser = qobject_cast(qApp); - Q_CHECK_PTR(browser); - - Q_ASSERT_X(sessionData.value("profile") != QJsonValue::Undefined, "Window::restoreSession", "no profile in json"); - if(browser->profiles().contains(sessionData.value("profile").toString())) - profile = browser->profile(sessionData.value("profile").toString()); - - Q_ASSERT_X(sessionData.value("tabs") != QJsonValue::Undefined, "Window::restoreSession", "no tabs in json"); - const QJsonArray tabs = sessionData.value("tabs").toArray(); - - if(tabs.count() == 0) { - // open a newtab - auto *view = new WebView(profile, this); - view->load(profile->newtab()); - tabWidget->addTab(view); - return; - } - - for(const auto &tab : tabs) { - auto *view = new WebView(profile, this); - view->load(QUrl::fromUserInput(tab.toString())); - tabWidget->addTab(view); - } -} -- cgit v1.2.1