mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Add support to switch gateway
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include "gpgateway.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
|
||||
GPGateway::GPGateway()
|
||||
{
|
||||
}
|
||||
@@ -36,3 +40,58 @@ int GPGateway::priorityOf(QString ruleName) const
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QJsonObject GPGateway::toJsonObject() const
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert("name", name());
|
||||
obj.insert("address", address());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
QString GPGateway::toString() const
|
||||
{
|
||||
QJsonDocument jsonDoc{ toJsonObject() };
|
||||
return QString::fromUtf8(jsonDoc.toJson());
|
||||
}
|
||||
|
||||
QString GPGateway::serialize(QList<GPGateway> &gateways)
|
||||
{
|
||||
QJsonArray arr;
|
||||
|
||||
for (auto g : gateways) {
|
||||
arr.append(g.toJsonObject());
|
||||
}
|
||||
|
||||
QJsonDocument jsonDoc{ arr };
|
||||
return QString::fromUtf8(jsonDoc.toJson());
|
||||
}
|
||||
|
||||
QList<GPGateway> GPGateway::fromJson(const QString &jsonString)
|
||||
{
|
||||
QList<GPGateway> gateways;
|
||||
|
||||
if (jsonString.isEmpty()) {
|
||||
return gateways;
|
||||
}
|
||||
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
|
||||
for (auto item : jsonDoc.array()) {
|
||||
GPGateway g = GPGateway::fromJsonObject(item.toObject());
|
||||
gateways.append(g);
|
||||
}
|
||||
|
||||
return gateways;
|
||||
}
|
||||
|
||||
GPGateway GPGateway::fromJsonObject(const QJsonObject &jsonObj)
|
||||
{
|
||||
GPGateway g;
|
||||
|
||||
g.setName(jsonObj.value("name").toString());
|
||||
g.setAddress(jsonObj.value("address").toString());
|
||||
|
||||
return g;
|
||||
}
|
||||
|
Reference in New Issue
Block a user