aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/webview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/webview.cpp')
-rw-r--r--src/webengine/webview.cpp47
1 files changed, 42 insertions, 5 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;