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/mainwindow.cpp | 4 ++-- src/mainwindow/subwindow.cpp | 45 +++++++++++-------------------------------- src/mainwindow/subwindow.h | 1 - 3 files changed, 13 insertions(+), 37 deletions(-) (limited to 'src/mainwindow') diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 0932aee..07ac8f0 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -193,8 +193,8 @@ void MainWindow::createMenuBar() auto *debugMenu = menuBar()->addMenu(tr("Debug")); debugMenu->addAction(tr("Print window session"), [this]() { - auto json = Session::toJson(this); - qDebug("session data >>>\n%s\n<<<", qUtf8Printable(json.toJson())); + auto json = Session::toJsonObject(this); + qDebug("session data >>>\n%s\n<<<", qUtf8Printable(QJsonDocument(json).toJson())); }); #endif } 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); - } -} diff --git a/src/mainwindow/subwindow.h b/src/mainwindow/subwindow.h index ac1610a..d5f4f4c 100644 --- a/src/mainwindow/subwindow.h +++ b/src/mainwindow/subwindow.h @@ -30,7 +30,6 @@ public: void setProfile(WebProfile *profile); QJsonObject session() const; - void restoreSession(const QJsonObject &sessionData); signals: void currentViewChanged(WebView *view); -- cgit v1.2.1