aboutsummaryrefslogtreecommitdiff
path: root/src/webengine
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-04-13 15:44:09 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-04-13 15:44:09 +0300
commit396bc0c1721af8d3ee970228e7df457f6b2c73d5 (patch)
tree5aee4f0faec3fdfe616e1684dcb1736be9126bc1 /src/webengine
parentAdd singleapplication.wrap (diff)
downloadsmolbote-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/webengine')
-rw-r--r--src/webengine/webview.cpp47
-rw-r--r--src/webengine/webview.h10
2 files changed, 50 insertions, 7 deletions
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index d42bad5..c64333e 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -13,15 +13,12 @@
#include "webprofilemanager.h"
#include "webviewcontextmenu.h"
#include <QContextMenuEvent>
+#include <QJsonObject>
#include <QWebEngineHistoryItem>
-WebView::WebView(WebProfile *profile, QWidget *parent)
+WebView::WebView(QWidget *parent)
: QWebEngineView(parent)
{
- Q_CHECK_PTR(profile);
- m_profile = profile;
- setPage(new WebPage(profile, this));
-
m_parentWindow = qobject_cast<SubWindow *>(parent);
// load status and progress
@@ -40,6 +37,34 @@ WebView::WebView(WebProfile *profile, QWidget *parent)
});
}
+WebView::WebView(WebProfile *profile, QWidget *parent)
+ : WebView(parent)
+{
+ Q_CHECK_PTR(profile);
+ m_profile = profile;
+ setPage(new WebPage(profile, this));
+}
+
+WebView::WebView(const Session::WebView &data, QWidget *parent)
+ : WebView(parent)
+{
+ const auto *profileManager = WebProfileManager::instance();
+ Q_CHECK_PTR(profileManager);
+
+ auto *profile = profileManager->profile(data.profile);
+ if(profile != nullptr) {
+ setProfile(profile);
+ }
+
+ if(!data.url.isEmpty())
+ load(QUrl::fromUserInput(data.url));
+ else {
+ QByteArray copy(data.history);
+ QDataStream historyStream(&copy, QIODevice::ReadOnly);
+ historyStream >> *history();
+ }
+}
+
void WebView::setProfile(WebProfile *profile)
{
m_profile = profile;
@@ -48,6 +73,18 @@ void WebView::setProfile(WebProfile *profile)
this->load(url);
}
+Session::WebView WebView::serialize() const
+{
+ const auto *profileManager = WebProfileManager::instance();
+ Q_CHECK_PTR(profileManager);
+
+ QByteArray historyData;
+ QDataStream historyStream(&historyData, QIODevice::WriteOnly);
+ historyStream << *history();
+
+ return { profileManager->id(profile()), QString(), historyData };
+}
+
bool WebView::isLoaded() const
{
return m_loaded;
diff --git a/src/webengine/webview.h b/src/webengine/webview.h
index 0223b78..5748691 100644
--- a/src/webengine/webview.h
+++ b/src/webengine/webview.h
@@ -11,26 +11,32 @@
#include "webpage.h"
#include <QWebEngineView>
+#include <session.hpp>
class WebProfile;
class SubWindow;
class WebViewContextMenu;
-class WebView : public QWebEngineView
+class WebView final : public QWebEngineView
{
friend class WebViewContextMenu;
Q_OBJECT
+ explicit WebView(QWidget *parent = nullptr);
+
public:
explicit WebView(WebProfile *profile = nullptr, QWidget *parent = nullptr);
+ explicit WebView(const Session::WebView &data, QWidget *parent = nullptr);
~WebView() = default;
- WebProfile *profile() const
+ [[nodiscard]] WebProfile *profile() const
{
return m_profile;
}
void setProfile(WebProfile *profile);
+ [[nodiscard]] Session::WebView serialize() const;
+
bool isLoaded() const;
public slots: