From e81526f15e8c1e9c82b27009dbe512f78cf1dc0f Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 24 Jun 2018 17:27:44 +0200 Subject: Add Session class --- src/mainwindow/mainwindow.cpp | 37 +++++++++++++++++++++++++++---------- src/mainwindow/mainwindow.h | 1 + src/mainwindow/subwindow.cpp | 19 ++++--------------- 3 files changed, 32 insertions(+), 25 deletions(-) (limited to 'src/mainwindow') diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 27279c1..0932aee 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -29,6 +29,10 @@ #include #include +#ifdef QT_DEBUG +#include "session.h" +#endif + #ifdef PLASMA_BLUR #include #endif @@ -183,6 +187,16 @@ void MainWindow::createMenuBar() // tools menu toolsMenu = menuBar()->addMenu(tr("Tools")); + + // debug menu +#ifdef QT_DEBUG + auto *debugMenu = menuBar()->addMenu(tr("Debug")); + + debugMenu->addAction(tr("Print window session"), [this]() { + auto json = Session::toJson(this); + qDebug("session data >>>\n%s\n<<<", qUtf8Printable(json.toJson())); + }); +#endif } void MainWindow::addAction(ActionLocation where, QAction *action) @@ -236,6 +250,18 @@ void MainWindow::createTab(const QUrl &url) } } +const QVector MainWindow::subWindows() const +{ + QVector list; + for(auto *w : mdiArea->subWindowList()) { + auto *subwindow = qobject_cast(w); + if(subwindow != nullptr) + list.append(subwindow); + } + + return list; +} + SubWindow *MainWindow::currentSubWindow() const { return qobject_cast(mdiArea->currentSubWindow()); @@ -247,16 +273,7 @@ SubWindow *MainWindow::createSubWindow(const QString &url) mdiArea->addSubWindow(w); w->showMaximized(); w->setFocus(); - - QJsonObject session; - session.insert("profile", ""); - QJsonArray urls; - if(!url.isEmpty()) - urls.append(url); - session.insert("tabs", urls); - - w->restoreSession(session); - + w->addTab(url); return w; } diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 7974806..9cb65d6 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -42,6 +42,7 @@ public: void addDockWidget(Qt::DockWidgetArea area, QWidget *widget); void removeDockWidget(QWidget *widget); + const QVector subWindows() const; SubWindow *currentSubWindow() const; public slots: diff --git a/src/mainwindow/subwindow.cpp b/src/mainwindow/subwindow.cpp index 2b9cd48..cbfe46a 100644 --- a/src/mainwindow/subwindow.cpp +++ b/src/mainwindow/subwindow.cpp @@ -52,19 +52,6 @@ SubWindow::SubWindow(const QHash &config, QWidget *parent, Qt: profileName_action->setText(tr("Profile: %1").arg(name)); }); } - -#ifdef QT_DEBUG - menu->addSeparator(); - menu->addAction(tr("Debug menu"))->setEnabled(false); - auto *saveSession_action = menu->addAction(tr("Save session")); - menu->addAction(tr("Load session"))->setEnabled(false); - setSystemMenu(menu); - - connect(saveSession_action, &QAction::triggered, [this]() { - QJsonDocument doc(session()); - qDebug("%s", qUtf8Printable(doc.toJson())); - }); -#endif } // new tab button @@ -162,13 +149,15 @@ void SubWindow::setCurrentTab(int index) QJsonObject SubWindow::session() const { QJsonObject obj; - obj.insert("profile", QJsonValue("")); + obj.insert("profile", profile->id()); QJsonArray tabs; for(int i = 0; i < tabWidget->count(); ++i) { auto *view = qobject_cast(tabWidget->widget(i)); if(view) { - tabs.append(view->url().toString()); + QJsonObject tab; + tab.insert(view->url().toString(), view->profile()->id()); + tabs.append(tab); } } obj.insert("tabs", tabs); -- cgit v1.2.1