aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/browser.cpp4
-rw-r--r--src/mainwindow/mainwindow.cpp37
-rw-r--r--src/mainwindow/mainwindow.h1
-rw-r--r--src/mainwindow/subwindow.cpp19
-rw-r--r--src/session.cpp30
-rw-r--r--src/session.h29
7 files changed, 95 insertions, 27 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5f4aed1..796f8e6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,6 +13,8 @@ add_executable(poi
singleapplication.h
browser.cpp
browser.h
+ session.cpp
+ session.h
../data/resources.qrc
# main window
diff --git a/src/browser.cpp b/src/browser.cpp
index e266024..d5a3d3e 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -94,7 +94,7 @@ void Browser::setup(const QString &defaultProfile)
for(const QFileInfo &f : entries) {
auto name = f.baseName();
- auto *profile = loadProfile(name, defaults, f.absoluteFilePath(), this);
+ auto *profile = WebProfile::loadProfile(name, defaults, f.absoluteFilePath(), this);
m_profiles.insert(name, profile);
connect(profile, &WebProfile::destroyed, this, [=]() {
m_profiles.remove(name);
@@ -106,7 +106,7 @@ void Browser::setup(const QString &defaultProfile)
// set default profile
if(!m_profiles.contains(defaultProfile)) {
// if this profile has not been added, it doesn't have a path
- auto *profile = loadProfile(defaultProfile, defaults, QString(), this);
+ auto *profile = WebProfile::loadProfile(defaultProfile, defaults, QString(), this);
m_profiles.insert(defaultProfile, profile);
connect(profile, &WebProfile::destroyed, this, [=]() {
m_profiles.remove(defaultProfile);
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 27279c1..0932aee 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -29,6 +29,10 @@
#include <QUrl>
#include <configuration/configuration.h>
+#ifdef QT_DEBUG
+#include "session.h"
+#endif
+
#ifdef PLASMA_BLUR
#include <KWindowEffects>
#endif
@@ -183,6 +187,16 @@ void MainWindow::createMenuBar()
// tools menu
toolsMenu = menuBar()->addMenu(tr("Tools"));
+
+ // debug menu
+#ifdef QT_DEBUG
+ auto *debugMenu = menuBar()->addMenu(tr("Debug"));
+
+ debugMenu->addAction(tr("Print window session"), [this]() {
+ auto json = Session::toJson(this);
+ qDebug("session data >>>\n%s\n<<<", qUtf8Printable(json.toJson()));
+ });
+#endif
}
void MainWindow::addAction(ActionLocation where, QAction *action)
@@ -236,6 +250,18 @@ void MainWindow::createTab(const QUrl &url)
}
}
+const QVector<SubWindow *> MainWindow::subWindows() const
+{
+ QVector<SubWindow *> list;
+ for(auto *w : mdiArea->subWindowList()) {
+ auto *subwindow = qobject_cast<SubWindow *>(w);
+ if(subwindow != nullptr)
+ list.append(subwindow);
+ }
+
+ return list;
+}
+
SubWindow *MainWindow::currentSubWindow() const
{
return qobject_cast<SubWindow *>(mdiArea->currentSubWindow());
@@ -247,16 +273,7 @@ SubWindow *MainWindow::createSubWindow(const QString &url)
mdiArea->addSubWindow(w);
w->showMaximized();
w->setFocus();
-
- QJsonObject session;
- session.insert("profile", "");
- QJsonArray urls;
- if(!url.isEmpty())
- urls.append(url);
- session.insert("tabs", urls);
-
- w->restoreSession(session);
-
+ w->addTab(url);
return w;
}
diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h
index 7974806..9cb65d6 100644
--- a/src/mainwindow/mainwindow.h
+++ b/src/mainwindow/mainwindow.h
@@ -42,6 +42,7 @@ public:
void addDockWidget(Qt::DockWidgetArea area, QWidget *widget);
void removeDockWidget(QWidget *widget);
+ const QVector<SubWindow *> subWindows() const;
SubWindow *currentSubWindow() const;
public slots:
diff --git a/src/mainwindow/subwindow.cpp b/src/mainwindow/subwindow.cpp
index 2b9cd48..cbfe46a 100644
--- a/src/mainwindow/subwindow.cpp
+++ b/src/mainwindow/subwindow.cpp
@@ -52,19 +52,6 @@ SubWindow::SubWindow(const QHash<QString, QString> &config, QWidget *parent, Qt:
profileName_action->setText(tr("Profile: %1").arg(name));
});
}
-
-#ifdef QT_DEBUG
- menu->addSeparator();
- menu->addAction(tr("Debug menu"))->setEnabled(false);
- 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
@@ -162,13 +149,15 @@ void SubWindow::setCurrentTab(int index)
QJsonObject SubWindow::session() const
{
QJsonObject obj;
- obj.insert("profile", QJsonValue(""));
+ obj.insert("profile", profile->id());
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());
+ QJsonObject tab;
+ tab.insert(view->url().toString(), view->profile()->id());
+ tabs.append(tab);
}
}
obj.insert("tabs", tabs);
diff --git a/src/session.cpp b/src/session.cpp
new file mode 100644
index 0000000..8e4f9a8
--- /dev/null
+++ b/src/session.cpp
@@ -0,0 +1,30 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "session.h"
+#include "mainwindow/mainwindow.h"
+#include "mainwindow/subwindow.h"
+#include <QJsonObject>
+#include <QJsonArray>
+
+Session::Session(QObject *parent) : QObject(parent)
+{
+}
+
+QJsonDocument Session::toJson(MainWindow *window)
+{
+ QJsonObject session;
+
+ QJsonArray subwindows;
+ for(const SubWindow *subwindow : window->subWindows()) {
+ subwindows.append(subwindow->session());
+ }
+ session.insert("subwindows", subwindows);
+
+ return QJsonDocument(session);
+}
diff --git a/src/session.h b/src/session.h
new file mode 100644
index 0000000..bb4f842
--- /dev/null
+++ b/src/session.h
@@ -0,0 +1,29 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_SESSION_H
+#define SMOLBOTE_SESSION_H
+
+#include <QObject>
+#include <QJsonDocument>
+
+class MainWindow;
+class Session : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Session(QObject *parent = nullptr);
+
+ static QJsonDocument toJson(MainWindow *window);
+
+signals:
+
+public slots:
+};
+
+#endif // SMOLBOTE_SESSION_H