aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-11-28 12:39:14 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-11-28 12:39:14 +0100
commit0b9cf8c968a89784b5c2b8afe1a819b33749165e (patch)
tree7153fc8fe5447ee710ce689352db6e0e3b8849cc /src/mainwindow
parentAdd Session::view and Session::restoreView (diff)
downloadsmolbote-0b9cf8c968a89784b5c2b8afe1a819b33749165e.tar.xz
Rewrite Session saving and loading
Diffstat (limited to 'src/mainwindow')
-rw-r--r--src/mainwindow/mainwindow.cpp32
-rw-r--r--src/mainwindow/mainwindow.h2
2 files changed, 9 insertions, 25 deletions
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index a01cb94..9e6f187 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -95,7 +95,7 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa
{
connect(ui->actionNewSubwindow, &QAction::triggered, this, [this, &config]() {
auto *profile = WebProfile::defaultProfile();
- auto *window = createSubWindow(config, profile);
+ auto *window = createSubWindow(config.get(), profile);
window->addTab(profile->newtab(), profile);
});
config->setShortcut(ui->actionNewSubwindow, "mainwindow.shortcuts.newGroup");
@@ -118,34 +118,18 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa
// connect session menu
{
- connect(ui->actionSaveSession, &QAction::triggered, this, [this]() {
-#ifndef QT_DEBUG
- const QString filename = QFileDialog::getSaveFileName(this, tr("Save Session"), QDir::homePath(), tr("JSON (*.json)"));
+ const QString sessionPath = config->value<QString>("browser.session.path").value();
+ connect(ui->actionSaveSession, &QAction::triggered, this, [this, 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)) {
- output.write(QJsonDocument(Session::window(this)).toJson());
+ auto *browser = qobject_cast<Browser *>(qApp);
+ auto data = Session::_session(browser->windows());
+ output.write(QJsonDocument(data).toJson());
output.close();
}
-#else
- auto data = Session::view(currentView);
- QJsonDocument doc(data);
- qDebug(qUtf8Printable(doc.toJson()));
-#endif
});
-#ifdef QT_DEBUG
- auto *openViewAction = ui->menuSession->addAction("Open View");
- connect(openViewAction, &QAction::triggered, this, [this]() {
- const QString filename = QFileDialog::getOpenFileName(this, tr("Open View"), QDir::homePath(), tr("JSON (*json)"));
- QFile output(filename);
- if(output.open(QIODevice::ReadOnly | QIODevice::Text)) {
- QJsonDocument doc = QJsonDocument::fromJson(output.readAll());
- Session::restoreView(currentView, doc.object());
- output.close();
- }
- });
-#endif
-
connect(ui->actionLoadSession, &QAction::triggered, this, [this]() {
auto *sessionDialog = new SessionDialog(this);
sessionDialog->exec();
@@ -356,7 +340,7 @@ SubWindow *MainWindow::currentSubWindow() const
return qobject_cast<SubWindow *>(mdiArea->currentSubWindow());
}
-SubWindow *MainWindow::createSubWindow(const std::unique_ptr<Configuration> &config, WebProfile *profile)
+SubWindow *MainWindow::createSubWindow(const Configuration *config, WebProfile *profile)
{
bool shouldMaximize = true;
// if there is a current window, use its maximize state
diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h
index 296a73e..de77540 100644
--- a/src/mainwindow/mainwindow.h
+++ b/src/mainwindow/mainwindow.h
@@ -54,7 +54,7 @@ signals:
public slots:
void createTab(const QUrl &url);
- SubWindow *createSubWindow(const std::unique_ptr<Configuration> &config, WebProfile *profile);
+ SubWindow *createSubWindow(const Configuration *config, WebProfile *profile);
private slots:
void setView(WebView *view);