Move serialization and deserialization into NvApp class

This commit is contained in:
Cameron Gutman 2020-05-07 19:54:36 -07:00
parent 350c7d7081
commit dc3c565ec0
5 changed files with 58 additions and 38 deletions

View file

@ -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 \

22
app/backend/nvapp.cpp Normal file
View file

@ -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);
}

30
app/backend/nvapp.h Normal file
View file

@ -0,0 +1,30 @@
#pragma once
#include <QSettings>
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)

View file

@ -1,4 +1,5 @@
#include "nvcomputer.h"
#include "nvapp.h"
#include <QUdpSocket>
#include <QHostInfo>
@ -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();
}

View file

@ -1,6 +1,7 @@
#pragma once
#include "identitymanager.h"
#include "nvapp.h"
#include <Limelight.h>
@ -8,27 +9,6 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
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: