aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/browser.h2
-rw-r--r--src/main.cpp2
-rw-r--r--src/mainwindow/mainwindow.cpp22
-rw-r--r--src/meson.build20
-rw-r--r--src/session/session.cpp (renamed from src/session.cpp)34
-rw-r--r--src/session/session.h (renamed from src/session.h)5
-rw-r--r--src/webengine/webview.h2
7 files changed, 73 insertions, 14 deletions
diff --git a/src/browser.h b/src/browser.h
index 2148484..1989631 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -9,7 +9,7 @@
#ifndef SMOLBOTE_BROWSER_H
#define SMOLBOTE_BROWSER_H
-#include "session.h"
+#include "session/session.h"
#include <QJsonObject>
#include <QVector>
#include <browserinterface.h>
diff --git a/src/main.cpp b/src/main.cpp
index 3eb6dac..a80784b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -8,7 +8,7 @@
#include "browser.h"
#include "configuration.h"
-#include "session.h"
+#include "session/session.h"
#include "util.h"
#include <QFile>
#include <QLibraryInfo>
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 80e4faa..a01cb94 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -12,7 +12,7 @@
#include "config.h"
#include "configuration.h"
#include "profilemanager.h"
-#include "session.h"
+#include "session/session.h"
#include "session/sessiondialog.h"
#include "subwindow/subwindow.h"
#include "ui_mainwindow.h"
@@ -119,13 +119,33 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa
// connect session menu
{
connect(ui->actionSaveSession, &QAction::triggered, this, [this]() {
+#ifndef QT_DEBUG
const QString filename = QFileDialog::getSaveFileName(this, tr("Save Session"), QDir::homePath(), tr("JSON (*.json)"));
QFile output(filename);
if(output.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
output.write(QJsonDocument(Session::window(this)).toJson());
output.close();
}
+#else
+ auto data = Session::view(currentView);
+ QJsonDocument doc(data);
+ qDebug(qUtf8Printable(doc.toJson()));
+#endif
+ });
+
+#ifdef QT_DEBUG
+ auto *openViewAction = ui->menuSession->addAction("Open View");
+ connect(openViewAction, &QAction::triggered, this, [this]() {
+ const QString filename = QFileDialog::getOpenFileName(this, tr("Open View"), QDir::homePath(), tr("JSON (*json)"));
+ QFile output(filename);
+ if(output.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ QJsonDocument doc = QJsonDocument::fromJson(output.readAll());
+ Session::restoreView(currentView, doc.object());
+ output.close();
+ }
});
+#endif
+
connect(ui->actionLoadSession, &QAction::triggered, this, [this]() {
auto *sessionDialog = new SessionDialog(this);
sessionDialog->exec();
diff --git a/src/meson.build b/src/meson.build
index 5df5a36..209fb5c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -27,24 +27,24 @@ poi = executable(get_option('poiName'), install: true,
include_directories: [include],
sources: ['main.cpp', poi_moc,
'browser.cpp',
- 'session.cpp',
'util.cpp', 'util.h',
- 'mainwindow/mainwindow.cpp',
- 'mainwindow/widgets/dockwidget.cpp',
- 'mainwindow/widgets/navigationbar.cpp',
+ 'mainwindow/mainwindow.cpp',
+ 'mainwindow/widgets/dockwidget.cpp',
+ 'mainwindow/widgets/navigationbar.cpp',
'mainwindow/widgets/searchform.cpp',
+ 'session/session.cpp',
'session/sessiondialog.cpp',
'session/sessionform.cpp',
- 'subwindow/subwindow.cpp',
- 'subwindow/tabwidget.cpp',
+ 'subwindow/subwindow.cpp',
+ 'subwindow/tabwidget.cpp',
- 'webengine/filter.cpp',
- 'webengine/urlinterceptor.cpp',
- 'webengine/webpage.cpp',
- 'webengine/webview.cpp',
+ 'webengine/filter.cpp',
+ 'webengine/urlinterceptor.cpp',
+ 'webengine/webpage.cpp',
+ 'webengine/webview.cpp',
'wallet/wallet.cpp', 'wallet/wallet.h']
)
diff --git a/src/session.cpp b/src/session/session.cpp
index 4e1c6d6..d728d55 100644
--- a/src/session.cpp
+++ b/src/session/session.cpp
@@ -14,6 +14,8 @@
#include "webengine/webview.h"
#include "profilemanager.h"
#include "browser.h"
+#include "../webengine/webview.h"
+#include <QWebEngineHistory>
QJsonObject Session::session(QVector<MainWindow *> windows)
{
@@ -78,3 +80,35 @@ QJsonObject Session::window(const QString &profile, const QStringList &urls)
return session;
}
+
+QJsonObject Session::view(const WebView *view)
+{
+ auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
+ Q_CHECK_PTR(profileManager);
+
+ QByteArray historyData;
+ QDataStream historyStream(&historyData, QIODevice::WriteOnly);
+ historyStream << *view->history();
+
+ QJsonObject viewData;
+ viewData.insert("url", view->url().toString());
+ viewData.insert("profile", profileManager->id(view->profile()));
+ //viewData.insert("history", QString(qCompress(historyData).toBase64()));
+ viewData.insert("history", QString(historyData.toBase64()));
+
+ return viewData;
+}
+
+void Session::restoreView(WebView *view, const QJsonObject &data)
+{
+ auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
+ Q_CHECK_PTR(profileManager);
+
+ auto *profile = profileManager->profile(data["profile"].toString());
+ if(profile)
+ view->setProfile(profile);
+
+ QByteArray historyData = QByteArray::fromBase64(data["history"].toString().toLatin1());
+ QDataStream historyStream(&historyData, QIODevice::ReadOnly);
+ historyStream >> *view->history();
+}
diff --git a/src/session.h b/src/session/session.h
index 8c0300c..222c7ef 100644
--- a/src/session.h
+++ b/src/session/session.h
@@ -12,10 +12,15 @@
#include <QJsonDocument>
class MainWindow;
+class WebView;
+
namespace Session {
QJsonObject session(QVector<MainWindow *> windows);
QJsonObject window(const MainWindow *window);
QJsonObject window(const QString &profile, const QStringList &urls);
+
+QJsonObject view(const WebView *view);
+void restoreView(WebView *view, const QJsonObject &data);
}
#endif // SMOLBOTE_SESSION_H
diff --git a/src/webengine/webview.h b/src/webengine/webview.h
index be4dfa4..8d320b9 100644
--- a/src/webengine/webview.h
+++ b/src/webengine/webview.h
@@ -26,7 +26,7 @@ public:
explicit WebView(WebProfile *profile = nullptr, QWidget *parent = nullptr);
~WebView() = default;
- WebProfile *profile()
+ WebProfile *profile() const
{
return m_profile;
}