diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-14 14:25:04 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-14 14:45:13 +0100 |
commit | f15af11e4b6ad5dfa1be5107c2db0ddad6480f5b (patch) | |
tree | fb32290b6a8b2f1b86dca1b483b994a30de9206b | |
parent | Profile picker menu: use QActionGroup instead of QRadioButton (diff) | |
download | smolbote-f15af11e4b6ad5dfa1be5107c2db0ddad6480f5b.tar.xz |
Add SaveSessionDialog
-rw-r--r-- | lib/configuration/configuration.cpp | 3 | ||||
-rw-r--r-- | src/mainwindow/menubar.cpp | 18 | ||||
-rw-r--r-- | src/meson.build | 5 | ||||
-rw-r--r-- | src/session/savesessiondialog.cpp | 78 | ||||
-rw-r--r-- | src/session/savesessiondialog.h | 34 | ||||
-rw-r--r-- | src/session/savesessiondialog.ui | 87 |
6 files changed, 213 insertions, 12 deletions
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp index 9b84166..d4f1eae 100644 --- a/lib/configuration/configuration.cpp +++ b/lib/configuration/configuration.cpp @@ -56,6 +56,9 @@ Configuration::Configuration(int argc, char **argv, const std::string &path, QOb ("mainwindow.title", po::value<std::string>()->default_value(CONFIG_POI_NAME)) // main window shortcuts + ("mainwindow.shortcuts.saveSession", po::value<std::string>()->default_value("Ctrl+S,S")) + ("mainwindow.shortcuts.openSession", po::value<std::string>()->default_value("Ctrl+S,O")) + ("mainwindow.shortcuts.newGroup", po::value<std::string>()->default_value(CONFIG_SHORTCUT_WINDOW_NEWGROUP)) ("mainwindow.shortcuts.newWindow", po::value<std::string>()->default_value(CONFIG_SHORTCUT_WINDOW_NEWWINDOW)) diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp index 0429ffd..84ce24f 100644 --- a/src/mainwindow/menubar.cpp +++ b/src/mainwindow/menubar.cpp @@ -13,6 +13,7 @@ #include "downloadswidget.h" #include "mainwindow.h" #include "profilemanager.h" +#include "session/savesessiondialog.h" #include "session/sessiondialog.h" #include "subwindow/subwindow.h" #include "webengine/webview.h" @@ -69,21 +70,18 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent) smolbote->addSeparator(); const QString sessionPath = config->value<QString>("browser.session.path").value(); - smolbote->addAction(tr("Save Session"), parent, [parent, sessionPath]() { - const QString filename = QFileDialog::getSaveFileName(parent, tr("Save Session"), sessionPath, tr("JSON (*.json)")); - QFile output(filename); - if(output.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { - auto *browser = qobject_cast<Browser *>(qApp); - auto data = Session::_session(browser->windows()); - output.write(QJsonDocument(data).toJson()); - output.close(); - } + auto *actionSaveSession = smolbote->addAction(tr("Save Session"), parent, [sessionPath]() { + auto *sessionDialog = new SaveSessionDialog(nullptr); + if(sessionDialog->exec()) + sessionDialog->save(sessionPath); }); + config->setShortcut(actionSaveSession, "mainwindow.shortcuts.saveSession"); - smolbote->addAction(tr("Open Session"), parent, [parent]() { + auto *actionOpenSession = smolbote->addAction(tr("Open Session"), parent, [parent]() { auto *sessionDialog = new SessionDialog(parent); sessionDialog->exec(); }); + config->setShortcut(actionOpenSession, "mainwindow.shortcuts.openSession"); smolbote->addSeparator(); auto *actionBookmarks = smolbote->addAction(tr("Bookmarks"), browser, [browser, parent]() { diff --git a/src/meson.build b/src/meson.build index 7dfba88..1fb4a98 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,10 +2,10 @@ poi_moc = qt5.preprocess( moc_headers: ['browser.h', 'mainwindow/mainwindow.h', 'mainwindow/menubar.h', 'mainwindow/widgets/dockwidget.h', 'mainwindow/widgets/menusearch.h', 'mainwindow/widgets/navigationbar.h', 'mainwindow/widgets/searchform.h', - 'session/sessiondialog.h', 'session/sessionform.h', + 'session/savesessiondialog.h', 'session/sessiondialog.h', 'session/sessionform.h', 'subwindow/subwindow.h', 'subwindow/tabwidget.h', 'webengine/filter.h', 'webengine/urlinterceptor.h', 'webengine/webpage.h', 'webengine/webview.h'], - ui_files: ['mainwindow/widgets/searchform.ui', 'session/sessiondialog.ui', 'session/sessionform.ui'], + ui_files: ['mainwindow/widgets/searchform.ui', 'session/savesessiondialog.ui', 'session/sessiondialog.ui', 'session/sessionform.ui'], qresources: '../data/resources.qrc', rcc_extra_arguments: ['--format-version=1'], dependencies: dep_qt5 @@ -37,6 +37,7 @@ poi = executable(get_option('poiName'), install: true, 'mainwindow/widgets/searchform.cpp', 'session/session.cpp', + 'session/savesessiondialog.cpp', 'session/sessiondialog.cpp', 'session/sessionform.cpp', 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> |