From acb401d7b24bfc670b534d68edc15e0847e73313 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 28 Sep 2018 17:28:43 +0200 Subject: Turn Session class into namespace --- src/browser.h | 2 +- src/main.cpp | 2 +- src/mainwindow/mainwindow.cpp | 2 +- src/session.cpp | 18 +++++++----------- src/session.h | 20 +++----------------- 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/browser.h b/src/browser.h index 694a3a7..0547168 100644 --- a/src/browser.h +++ b/src/browser.h @@ -50,7 +50,7 @@ public: void setup(const QString &defaultProfile); QJsonObject session() const { - return JsonSession::session(m_windows); + return Session::session(m_windows); } public slots: diff --git a/src/main.cpp b/src/main.cpp index e7fdcee..41091a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -194,7 +194,7 @@ int main(int argc, char **argv) sessionJson.close(); } } else { - sessionData = Session::toJsonObject(profile.value(), urls); + sessionData = Session::window(profile.value(), urls); } if(app.isPrimary() || isStandalone) { diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index cc67b3d..e3c64f5 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -130,7 +130,7 @@ MainWindow::MainWindow(const std::unique_ptr &config, QWidget *pa const QString filename = QFileDialog::getSaveFileName(this, tr("Save Session"), QDir::homePath(), tr("JSON (*.json)")); QFile output(filename); if(output.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { - output.write(QJsonDocument(Session::toJsonObject(this)).toJson()); + output.write(QJsonDocument(Session::window(this)).toJson()); output.close(); } }); diff --git a/src/session.cpp b/src/session.cpp index 9c69088..70e1deb 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -15,26 +15,22 @@ #include -QJsonObject JsonSession::session(QVector windows) +QJsonObject Session::session(QVector windows) { QJsonObject obj; QJsonArray windowsArray; for(const MainWindow *window : windows) { - windowsArray.append(Session::toJsonObject(window)); + windowsArray.append(Session::window(window)); } obj.insert("windows", windowsArray); return obj; } -Session::Session(QObject *parent) : QObject(parent) +QJsonObject Session::window(const MainWindow *window) { -} - -QJsonObject Session::toJsonObject(const MainWindow *window) -{ - QJsonObject session; + QJsonObject obj; QJsonArray subwindows; for(const SubWindow *subwindow : window->subWindows()) { @@ -52,12 +48,12 @@ QJsonObject Session::toJsonObject(const MainWindow *window) subwindows.append(window); } - session.insert("subwindows", subwindows); + obj.insert("subwindows", subwindows); - return session; + return obj; } -QJsonObject Session::toJsonObject(const QString &profile, const QStringList &urls) +QJsonObject Session::window(const QString &profile, const QStringList &urls) { QJsonObject session; diff --git a/src/session.h b/src/session.h index c81b2bf..759687c 100644 --- a/src/session.h +++ b/src/session.h @@ -9,27 +9,13 @@ #ifndef SMOLBOTE_SESSION_H #define SMOLBOTE_SESSION_H -#include #include class MainWindow; - -namespace JsonSession { +namespace Session { QJsonObject session(QVector windows); +QJsonObject window(const MainWindow *window); +QJsonObject window(const QString &profile, const QStringList &urls); } -class Session : public QObject -{ - Q_OBJECT -public: - explicit Session(QObject *parent = nullptr); - - static QJsonObject toJsonObject(const MainWindow *window); - static QJsonObject toJsonObject(const QString &profile, const QStringList &urls); - -signals: - -public slots: -}; - #endif // SMOLBOTE_SESSION_H -- cgit v1.2.1