From f15af11e4b6ad5dfa1be5107c2db0ddad6480f5b Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 14 Dec 2018 14:25:04 +0100 Subject: Add SaveSessionDialog --- src/session/savesessiondialog.cpp | 78 +++++++++++++++++++++++++++++++++++ src/session/savesessiondialog.h | 34 +++++++++++++++ src/session/savesessiondialog.ui | 87 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 src/session/savesessiondialog.cpp create mode 100644 src/session/savesessiondialog.h create mode 100644 src/session/savesessiondialog.ui (limited to 'src/session') 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 +#include +#include + +SaveSessionDialog::SaveSessionDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::SaveSessionDialog) +{ + ui->setupUi(this); + + auto *browser = qobject_cast(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(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 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(item->data(0, Qt::UserRole).value()); + 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 + +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 @@ + + + SaveSessionDialog + + + + 0 + 0 + 1000 + 600 + + + + Save Session + + + + + + QAbstractItemView::NoEditTriggers + + + 300 + + + 300 + + + + Name + + + + + Profile + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + + + + + + + buttonBox + accepted() + SaveSessionDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SaveSessionDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- cgit v1.2.1