aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow/window.cpp')
-rw-r--r--src/mainwindow/window.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/mainwindow/window.cpp b/src/mainwindow/window.cpp
index 735df4a..fb4eb07 100644
--- a/src/mainwindow/window.cpp
+++ b/src/mainwindow/window.cpp
@@ -14,6 +14,10 @@
#include <QToolButton>
#include <QStyle>
#include <QAction>
+#include <QMenu>
+#include <QJsonObject>
+#include <QJsonArray>
+#include <QJsonDocument>
Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::WindowFlags flags)
: QMdiSubWindow(parent, flags)
@@ -25,6 +29,21 @@ Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::Windo
resize(800, 600);
setWidget(tabWidget);
+#ifdef QT_DEBUG
+ {
+ auto *menu = systemMenu();
+ menu->addSeparator();
+ auto *saveSession_action = menu->addAction(tr("Save session"));
+ menu->addAction(tr("Load session"))->setEnabled(false);
+ setSystemMenu(menu);
+
+ connect(saveSession_action, &QAction::triggered, [this]() {
+ QJsonDocument doc(session());
+ qDebug("%s", qUtf8Printable(doc.toJson()));
+ });
+ }
+#endif
+
// new tab button
auto *newTab_button = new QToolButton(this);
newTab_button->setIcon(style()->standardIcon(QStyle::SP_FileIcon));
@@ -108,3 +127,35 @@ void Window::swapToTab(int index)
{
tabWidget->setCurrentIndex(index);
}
+
+QJsonObject Window::session() const
+{
+ QJsonObject obj;
+ obj.insert("profile", QJsonValue(""));
+
+ QJsonArray tabs;
+ for(int i = 0; i < tabWidget->count(); ++i) {
+ auto *view = qobject_cast<WebView *>(tabWidget->widget(i));
+ if(view) {
+ tabs.append(view->url().toString());
+ }
+ }
+ obj.insert("tabs", tabs);
+
+ return obj;
+}
+
+void Window::restoreSession(const QJsonObject &sessionData)
+{
+ Q_ASSERT_X(sessionData.value("profile") != QJsonValue::Undefined, "Window::restoreSession", "no profile in json");
+ auto *profile = WebProfile::defaultProfile();
+
+ Q_ASSERT_X(sessionData.value("tabs") != QJsonValue::Undefined, "Window::restoreSession", "no tabs in json");
+ const QJsonArray tabs = sessionData.value("tabs").toArray();
+ for(const auto tab : tabs) {
+ auto *view = new WebView(profile, this);
+ view->load(QUrl::fromUserInput(tab.toString()));
+ tabWidget->addTab(view);
+ }
+
+}