mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-04 00:36:36 +00:00
Implement app list parsing
This commit is contained in:
parent
16d7dca784
commit
76d39c08da
@ -4,19 +4,6 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
|
|
||||||
class NvApp
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool operator==(const NvApp& other) const
|
|
||||||
{
|
|
||||||
return id == other.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id;
|
|
||||||
QString name;
|
|
||||||
bool hdrSupported;
|
|
||||||
};
|
|
||||||
|
|
||||||
class NvComputer
|
class NvComputer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -101,8 +88,29 @@ private:
|
|||||||
|
|
||||||
bool updateAppList(bool& changed)
|
bool updateAppList(bool& changed)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(m_Computer->activeAddress != nullptr);
|
||||||
|
|
||||||
|
NvHTTP http(m_Computer->activeAddress);
|
||||||
|
|
||||||
|
QVector<NvApp> appList;
|
||||||
|
|
||||||
|
try {
|
||||||
|
appList = http.getAppList();
|
||||||
|
if (appList.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWriteLocker lock(&m_Computer->lock);
|
||||||
|
if (m_Computer->appList != appList) {
|
||||||
|
m_Computer->appList = appList;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
|
@ -181,6 +181,44 @@ NvHTTP::quitApp()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<NvApp>
|
||||||
|
NvHTTP::getAppList()
|
||||||
|
{
|
||||||
|
QString appxml = openConnectionToString(m_BaseUrlHttps,
|
||||||
|
"applist",
|
||||||
|
nullptr,
|
||||||
|
true);
|
||||||
|
verifyResponseStatus(appxml);
|
||||||
|
|
||||||
|
QXmlStreamReader xmlReader(appxml);
|
||||||
|
QVector<NvApp> apps;
|
||||||
|
while (!xmlReader.atEnd()) {
|
||||||
|
while (xmlReader.readNextStartElement()) {
|
||||||
|
QStringRef name = xmlReader.name();
|
||||||
|
if (xmlReader.name() == "App") {
|
||||||
|
// We must have a valid app before advancing to the next one
|
||||||
|
if (!apps.isEmpty() && !apps.last().isInitialized()) {
|
||||||
|
qWarning() << "Invalid applist XML";
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return QVector<NvApp>();
|
||||||
|
}
|
||||||
|
apps.append(NvApp());
|
||||||
|
}
|
||||||
|
else if (xmlReader.name() == "AppTitle") {
|
||||||
|
apps.last().name = xmlReader.readElementText();
|
||||||
|
}
|
||||||
|
else if (xmlReader.name() == "ID") {
|
||||||
|
apps.last().id = xmlReader.readElementText().toInt();
|
||||||
|
}
|
||||||
|
else if (xmlReader.name() == "IsHdrSupported") {
|
||||||
|
apps.last().hdrSupported = xmlReader.readElementText() == "1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return apps;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NvHTTP::verifyResponseStatus(QString xml)
|
NvHTTP::verifyResponseStatus(QString xml)
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,24 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QtNetwork/QNetworkAccessManager>
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
|
|
||||||
|
class NvApp
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool operator==(const NvApp& other) const
|
||||||
|
{
|
||||||
|
return id == other.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isInitialized()
|
||||||
|
{
|
||||||
|
return id != 0 && !name.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
int id;
|
||||||
|
QString name;
|
||||||
|
bool hdrSupported;
|
||||||
|
};
|
||||||
|
|
||||||
class GfeHttpResponseException : public std::exception
|
class GfeHttpResponseException : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -86,6 +104,9 @@ public:
|
|||||||
bool localAudio,
|
bool localAudio,
|
||||||
int gamepadMask);
|
int gamepadMask);
|
||||||
|
|
||||||
|
QVector<NvApp>
|
||||||
|
getAppList();
|
||||||
|
|
||||||
QUrl m_BaseUrlHttp;
|
QUrl m_BaseUrlHttp;
|
||||||
QUrl m_BaseUrlHttps;
|
QUrl m_BaseUrlHttps;
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user