aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-24 17:27:44 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-24 17:27:44 +0200
commite81526f15e8c1e9c82b27009dbe512f78cf1dc0f (patch)
treeea9a140347b6077d0521f85da4f9d881185fbb90 /src/mainwindow
parentSplit shortcuts into new tab (diff)
downloadsmolbote-e81526f15e8c1e9c82b27009dbe512f78cf1dc0f.tar.xz
Add Session class
Diffstat (limited to 'src/mainwindow')
-rw-r--r--src/mainwindow/mainwindow.cpp37
-rw-r--r--src/mainwindow/mainwindow.h1
-rw-r--r--src/mainwindow/subwindow.cpp19
3 files changed, 32 insertions, 25 deletions
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);