diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-13 15:44:09 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-13 15:44:09 +0300 |
commit | 396bc0c1721af8d3ee970228e7df457f6b2c73d5 (patch) | |
tree | 5aee4f0faec3fdfe616e1684dcb1736be9126bc1 /src/subwindow | |
parent | Add singleapplication.wrap (diff) | |
download | smolbote-396bc0c1721af8d3ee970228e7df457f6b2c73d5.tar.xz |
Rewrite Session backend
Add session.hpp, containing structs that describe session data
MainWindow, SubWindow and WebView can be created from
Session::structs
Opening new window will automatically open a default subwindow and tab
if none were specified
Add lib/session_formats
Add JsonSession, to serialize/deserialize Session structs into JSON
- add some tests
clang-tidy:
- fix various warnings
- disable modernize-use-trailing-return-type check
Diffstat (limited to 'src/subwindow')
-rw-r--r-- | src/subwindow/subwindow.cpp | 37 | ||||
-rw-r--r-- | src/subwindow/subwindow.h | 4 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp index 58acee6..8c2e3e7 100644 --- a/src/subwindow/subwindow.cpp +++ b/src/subwindow/subwindow.cpp @@ -10,10 +10,12 @@ #include "browser.h" #include "configuration.h" #include "webengine/webprofile.h" +#include "webengine/webprofilemanager.h" #include "webengine/webview.h" #include <QAction> #include <QCloseEvent> #include <QHideEvent> +#include <QJsonArray> #include <QMenu> #include <QShortcut> #include <QShowEvent> @@ -76,6 +78,35 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags flags) }); } +SubWindow::SubWindow(const Session::SubWindow &data, QWidget *parent, Qt::WindowFlags flags) + : SubWindow(parent, flags) +{ + const auto *profileManager = WebProfileManager::instance(); + Q_CHECK_PTR(profileManager); + + auto *profile = profileManager->profile(data.profile); + if(profile != nullptr) { + setProfile(profile); + } + + for(const auto &data : data.tabs) { + addTab(data); + } +} + +Session::SubWindow SubWindow::serialize() const +{ + const auto *profileManager = WebProfileManager::instance(); + Q_CHECK_PTR(profileManager); + + QVector<Session::WebView> tabs(tabCount()); + for(int i = 0; i < tabCount(); ++i) { + tabs[i] = view(i)->serialize(); + } + + return { profileManager->id(profile()), tabs }; +} + void SubWindow::setProfile(WebProfile *profile) { if(profile == nullptr) { @@ -115,6 +146,12 @@ int SubWindow::addTab(const QUrl &url, WebProfile *profile) return tabWidget->addTab(view); } +int SubWindow::addTab(const Session::WebView &data) +{ + auto *view = new WebView(data, this); + return tabWidget->addTab(view); +} + void SubWindow::moveTab(int from, int to) { tabWidget->tabBar()->moveTab(from, to); diff --git a/src/subwindow/subwindow.h b/src/subwindow/subwindow.h index 8343a9b..02f50d0 100644 --- a/src/subwindow/subwindow.h +++ b/src/subwindow/subwindow.h @@ -9,6 +9,7 @@ #ifndef SMOLBOTE_SUBWINDOW_H #define SMOLBOTE_SUBWINDOW_H +#include "session.hpp" #include "tabwidget.h" #include "webengine/webview.h" #include <QMenu> @@ -27,7 +28,9 @@ public: }; explicit SubWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); + explicit SubWindow(const Session::SubWindow &data, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); ~SubWindow() = default; + [[nodiscard]] Session::SubWindow serialize() const; [[nodiscard]] int currentTabIndex() const { @@ -66,6 +69,7 @@ signals: public slots: int addTab(const QUrl &url = QUrl(), WebProfile *profile = nullptr); + int addTab(const Session::WebView &data); void closeTab(int index) { tabWidget->removeTab(index); |