From 0b9cf8c968a89784b5c2b8afe1a819b33749165e Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 28 Nov 2018 12:39:14 +0100 Subject: Rewrite Session saving and loading --- src/mainwindow/mainwindow.cpp | 32 ++++++++------------------------ src/mainwindow/mainwindow.h | 2 +- 2 files changed, 9 insertions(+), 25 deletions(-) (limited to 'src/mainwindow') 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 &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 &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("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(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(mdiArea->currentSubWindow()); } -SubWindow *MainWindow::createSubWindow(const std::unique_ptr &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 &config, WebProfile *profile); + SubWindow *createSubWindow(const Configuration *config, WebProfile *profile); private slots: void setView(WebView *view); -- cgit v1.2.1