From dc3c565ec0ddbc8aa535f78be88e5c762b27aa8b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 7 May 2020 19:54:36 -0700 Subject: [PATCH] Move serialization and deserialization into NvApp class --- app/app.pro | 2 ++ app/backend/nvapp.cpp | 22 ++++++++++++++++++++++ app/backend/nvapp.h | 30 ++++++++++++++++++++++++++++++ app/backend/nvcomputer.cpp | 20 +++----------------- app/backend/nvhttp.h | 22 +--------------------- 5 files changed, 58 insertions(+), 38 deletions(-) create mode 100644 app/backend/nvapp.cpp create mode 100644 app/backend/nvapp.h diff --git a/app/app.pro b/app/app.pro index ff8e1868..d47ca829 100644 --- a/app/app.pro +++ b/app/app.pro @@ -133,6 +133,7 @@ macx { } SOURCES += \ + backend/nvapp.cpp \ main.cpp \ backend/computerseeker.cpp \ backend/identitymanager.cpp \ @@ -167,6 +168,7 @@ SOURCES += \ wm.cpp HEADERS += \ + backend/nvapp.h \ utils.h \ backend/computerseeker.h \ backend/identitymanager.h \ diff --git a/app/backend/nvapp.cpp b/app/backend/nvapp.cpp new file mode 100644 index 00000000..f06fca13 --- /dev/null +++ b/app/backend/nvapp.cpp @@ -0,0 +1,22 @@ +#include "nvapp.h" + +#define SER_APPNAME "name" +#define SER_APPID "id" +#define SER_APPHDR "hdr" +#define SER_APPCOLLECTOR "appcollector" + +NvApp::NvApp(QSettings& settings) +{ + name = settings.value(SER_APPNAME).toString(); + id = settings.value(SER_APPID).toInt(); + hdrSupported = settings.value(SER_APPHDR).toBool(); + isAppCollectorGame = settings.value(SER_APPCOLLECTOR).toBool(); +} + +void NvApp::serialize(QSettings& settings) const +{ + settings.setValue(SER_APPNAME, name); + settings.setValue(SER_APPID, id); + settings.setValue(SER_APPHDR, hdrSupported); + settings.setValue(SER_APPCOLLECTOR, isAppCollectorGame); +} diff --git a/app/backend/nvapp.h b/app/backend/nvapp.h new file mode 100644 index 00000000..bc70f37a --- /dev/null +++ b/app/backend/nvapp.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +class NvApp +{ +public: + NvApp() {} + explicit NvApp(QSettings& settings); + + bool operator==(const NvApp& other) const + { + return id == other.id; + } + + bool isInitialized() + { + return id != 0 && !name.isEmpty(); + } + + void + serialize(QSettings& settings) const; + + int id = 0; + QString name; + bool hdrSupported = false; + bool isAppCollectorGame = false; +}; + +Q_DECLARE_METATYPE(NvApp) diff --git a/app/backend/nvcomputer.cpp b/app/backend/nvcomputer.cpp index a7ce3874..8783eee6 100644 --- a/app/backend/nvcomputer.cpp +++ b/app/backend/nvcomputer.cpp @@ -1,4 +1,5 @@ #include "nvcomputer.h" +#include "nvapp.h" #include #include @@ -16,11 +17,6 @@ #define SER_SRVCERT "srvcert" #define SER_CUSTOMNAME "customname" -#define SER_APPNAME "name" -#define SER_APPID "id" -#define SER_APPHDR "hdr" -#define SER_APPCOLLECTOR "appcollector" - NvComputer::NvComputer(QSettings& settings) { this->name = settings.value(SER_NAME).toString(); @@ -35,15 +31,9 @@ NvComputer::NvComputer(QSettings& settings) int appCount = settings.beginReadArray(SER_APPLIST); for (int i = 0; i < appCount; i++) { - NvApp app; - settings.setArrayIndex(i); - app.name = settings.value(SER_APPNAME).toString(); - app.id = settings.value(SER_APPID).toInt(); - app.hdrSupported = settings.value(SER_APPHDR).toBool(); - app.isAppCollectorGame = settings.value(SER_APPCOLLECTOR).toBool(); - + NvApp app(settings); this->appList.append(app); } settings.endArray(); @@ -81,11 +71,7 @@ void NvComputer::serialize(QSettings& settings) const settings.beginWriteArray(SER_APPLIST); for (int i = 0; i < appList.count(); i++) { settings.setArrayIndex(i); - - settings.setValue(SER_APPNAME, appList[i].name); - settings.setValue(SER_APPID, appList[i].id); - settings.setValue(SER_APPHDR, appList[i].hdrSupported); - settings.setValue(SER_APPCOLLECTOR, appList[i].isAppCollectorGame); + appList[i].serialize(settings); } settings.endArray(); } diff --git a/app/backend/nvhttp.h b/app/backend/nvhttp.h index f0c606a6..69041497 100644 --- a/app/backend/nvhttp.h +++ b/app/backend/nvhttp.h @@ -1,6 +1,7 @@ #pragma once #include "identitymanager.h" +#include "nvapp.h" #include @@ -8,27 +9,6 @@ #include #include -class NvApp -{ -public: - bool operator==(const NvApp& other) const - { - return id == other.id; - } - - bool isInitialized() - { - return id != 0 && !name.isEmpty(); - } - - int id; - QString name; - bool hdrSupported; - bool isAppCollectorGame; -}; - -Q_DECLARE_METATYPE(NvApp) - class NvDisplayMode { public: