aboutsummaryrefslogtreecommitdiff
path: root/src/session
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-12-14 14:25:04 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-12-14 14:45:13 +0100
commitf15af11e4b6ad5dfa1be5107c2db0ddad6480f5b (patch)
treefb32290b6a8b2f1b86dca1b483b994a30de9206b /src/session
parentProfile picker menu: use QActionGroup instead of QRadioButton (diff)
downloadsmolbote-f15af11e4b6ad5dfa1be5107c2db0ddad6480f5b.tar.xz
Add SaveSessionDialog
Diffstat (limited to 'src/session')
-rw-r--r--src/session/savesessiondialog.cpp78
-rw-r--r--src/session/savesessiondialog.h34
-rw-r--r--src/session/savesessiondialog.ui87
3 files changed, 199 insertions, 0 deletions
diff --git a/src/session/savesessiondialog.cpp b/src/session/savesessiondialog.cpp
new file mode 100644
index 0000000..808ba45
--- /dev/null
+++ b/src/session/savesessiondialog.cpp
@@ -0,0 +1,78 @@
+/*
+ * 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/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "savesessiondialog.h"
+#include "browser.h"
+#include "mainwindow/mainwindow.h"
+#include "profilemanager.h"
+#include "subwindow/subwindow.h"
+#include "ui_savesessiondialog.h"
+#include "webengine/webview.h"
+#include <QFileDialog>
+#include <QPointer>
+#include <QTreeWidgetItem>
+
+SaveSessionDialog::SaveSessionDialog(QWidget *parent)
+ : QDialog(parent)
+ , ui(new Ui::SaveSessionDialog)
+{
+ ui->setupUi(this);
+
+ auto *browser = qobject_cast<Browser *>(qApp);
+ Q_CHECK_PTR(browser);
+
+ for(MainWindow *window : browser->windows()) {
+ auto *windowItem = new QTreeWidgetItem(ui->treeWidget);
+ windowItem->setText(0, tr("Main Window"));
+ windowItem->setData(0, Qt::UserRole, QVariant::fromValue(static_cast<void *>(window)));
+ windowItem->setCheckState(0, Qt::Checked);
+ ui->treeWidget->expandItem(windowItem);
+
+ for(const SubWindow *subwindow : window->subWindows()) {
+ auto *subwindowItem = new QTreeWidgetItem(windowItem);
+ subwindowItem->setText(0, tr("Subwindow"));
+ subwindowItem->setText(1, browser->getProfileManager()->id(subwindow->profile()));
+
+ ui->treeWidget->expandItem(subwindowItem);
+
+ for(int i = 0; i < subwindow->tabCount(); ++i) {
+ auto *tabItem = new QTreeWidgetItem(subwindowItem);
+ auto *view = subwindow->view(i);
+ tabItem->setText(0, view->title());
+ tabItem->setText(1, browser->getProfileManager()->id(view->profile()));
+ }
+ }
+ }
+}
+
+SaveSessionDialog::~SaveSessionDialog()
+{
+ delete ui;
+}
+
+void SaveSessionDialog::save(const QString &sessionPath)
+{
+ const QString filename = QFileDialog::getSaveFileName(this, tr("Save Session"), sessionPath, tr("JSON (*.json)"));
+ QFile output(filename);
+
+ if(output.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
+ QVector<MainWindow *> windows;
+ for(int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
+ if(item->checkState(0) == Qt::Checked) {
+ auto *window = static_cast<MainWindow *>(item->data(0, Qt::UserRole).value<void *>());
+ Q_CHECK_PTR(window);
+ windows.append(window);
+ }
+ }
+
+ auto data = Session::_session(windows);
+ output.write(QJsonDocument(data).toJson());
+ output.close();
+ }
+}
diff --git a/src/session/savesessiondialog.h b/src/session/savesessiondialog.h
new file mode 100644
index 0000000..ade1d23
--- /dev/null
+++ b/src/session/savesessiondialog.h
@@ -0,0 +1,34 @@
+/*
+ * 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/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_SAVESESSIONDIALOG_H
+#define SMOLBOTE_SAVESESSIONDIALOG_H
+
+#include <QDialog>
+
+namespace Ui
+{
+class SaveSessionDialog;
+}
+
+class SaveSessionDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit SaveSessionDialog(QWidget *parent = nullptr);
+ ~SaveSessionDialog();
+
+public slots:
+ void save(const QString &sessionPath);
+
+private:
+ Ui::SaveSessionDialog *ui;
+};
+
+#endif // SMOLBOTE_SAVESESSIONDIALOG_H
diff --git a/src/session/savesessiondialog.ui b/src/session/savesessiondialog.ui
new file mode 100644
index 0000000..120858f
--- /dev/null
+++ b/src/session/savesessiondialog.ui
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SaveSessionDialog</class>
+ <widget class="QDialog" name="SaveSessionDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>1000</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Save Session</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTreeWidget" name="treeWidget">
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <attribute name="headerDefaultSectionSize">
+ <number>300</number>
+ </attribute>
+ <attribute name="headerMinimumSectionSize">
+ <number>300</number>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Profile</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>SaveSessionDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>SaveSessionDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>