aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-04-30 15:21:22 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-04-30 15:21:22 +0200
commit5f0a8b4d3a5ac5dd01d8fb2f9d58e6b6ac35d576 (patch)
tree57b88aeac842a4b04d0d11f93e166750c88696b7 /src
parentFix poi-config crashing (diff)
downloadsmolbote-5f0a8b4d3a5ac5dd01d8fb2f9d58e6b6ac35d576.tar.xz
Window::session
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow/mainwindow.cpp11
-rw-r--r--src/mainwindow/window.cpp51
-rw-r--r--src/mainwindow/window.h2
3 files changed, 63 insertions, 1 deletions
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 6e4189e..be5e6e4 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -26,6 +26,8 @@
#include <QUrl>
#include <about/aboutdialog.h>
#include <configuration/configuration.h>
+#include <QJsonObject>
+#include <QJsonArray>
MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent)
: QMainWindow(parent)
@@ -178,7 +180,14 @@ Window *MainWindow::createSubWindow(const QUrl &url)
w->showMaximized();
w->setFocus();
- w->addTab(url);
+ QJsonObject session;
+ session.insert("profile", "");
+ QJsonArray urls;
+ urls.append(url.toString());
+ session.insert("tabs", urls);
+
+ //w->addTab(url);
+ //w->restoreSession(session);
return w;
}
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);
+ }
+
+}
diff --git a/src/mainwindow/window.h b/src/mainwindow/window.h
index cdc504c..22955b8 100644
--- a/src/mainwindow/window.h
+++ b/src/mainwindow/window.h
@@ -23,6 +23,8 @@ public:
~Window() override;
WebView *currentView();
+ QJsonObject session() const;
+ void restoreSession(const QJsonObject &sessionData);
signals:
void currentViewChanged(WebView *view);