diff options
Diffstat (limited to 'src/mainwindow')
| -rw-r--r-- | src/mainwindow/mainwindow.cpp | 4 | ||||
| -rw-r--r-- | src/mainwindow/subwindow.cpp | 45 | ||||
| -rw-r--r-- | src/mainwindow/subwindow.h | 1 | 
3 files changed, 13 insertions, 37 deletions
| 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 <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); -    } -} 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); | 
