diff options
Diffstat (limited to 'src/mainwindow/subwindow.cpp')
-rw-r--r-- | src/mainwindow/subwindow.cpp | 45 |
1 files changed, 11 insertions, 34 deletions
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 <QStyle> #include <QToolButton> #include <webprofile.h> +#include "profilemanager.h" SubWindow::SubWindow(const QHash<QString, QString> &config, QWidget *parent, Qt::WindowFlags flags) : QMdiSubWindow(parent, flags) @@ -44,12 +45,15 @@ SubWindow::SubWindow(const QHash<QString, QString> &config, QWidget *parent, Qt: Browser *browser = qobject_cast<Browser *>(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<WebView *>(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<Browser *>(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); - } -} |