Transform JSON objects into native objects
This commit is contained in:
parent
7f0cd77b4e
commit
892de92aa2
@ -9,7 +9,8 @@ set(QT_VERSION 6 CACHE STRING "Major version of Qt to use (6 will work, anything
|
|||||||
|
|
||||||
find_package(Qt${QT_VERSION} COMPONENTS Core Gui Widgets WebEngineWidgets REQUIRED)
|
find_package(Qt${QT_VERSION} COMPONENTS Core Gui Widgets WebEngineWidgets REQUIRED)
|
||||||
add_subdirectory(dialogs)
|
add_subdirectory(dialogs)
|
||||||
|
add_subdirectory(lib)
|
||||||
add_executable(configurator main.cpp Configurator.cpp)
|
add_executable(configurator main.cpp Configurator.cpp)
|
||||||
target_link_libraries(configurator Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::WebEngineWidgets Qt${QT_VERSION}::Network dialogs)
|
target_link_libraries(configurator Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::WebEngineWidgets Qt${QT_VERSION}::Network dialogs fed)
|
||||||
|
|
||||||
install(TARGETS configurator DESTINATION bin)
|
install(TARGETS configurator DESTINATION bin)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "Configurator.h"
|
#include "Configurator.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QJsonArray>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
Configurator::Configurator(int &argc, char **&argv):QApplication(argc, argv),_nam(this) {
|
Configurator::Configurator(int &argc, char **&argv):QApplication(argc, argv),_nam(this) {
|
||||||
@ -25,27 +25,13 @@ void Configurator::appListReceived(QNetworkReply *reply) {
|
|||||||
_loginDialog->show();
|
_loginDialog->show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_services=QJsonDocument::fromJson(reply->readAll());
|
QJsonDocument services = QJsonDocument::fromJson(reply->readAll());
|
||||||
if(!_services.isArray()) {
|
if(!services.isArray()) {
|
||||||
_loginDialog->setMessage(tr("App list did not return an array. Is the domain name correct?"));
|
_loginDialog->setMessage(tr("App list did not return an array. Is the domain name correct?"));
|
||||||
_loginDialog->show();
|
_loginDialog->show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QJsonArray a=_services.array();
|
_services = services.array();
|
||||||
for(auto i : a) {
|
for(auto i : _services)
|
||||||
if(!i.isObject()) {
|
std::cerr << qPrintable(i.title) << std::endl;
|
||||||
std::cerr << "Non-object in JSON array" << std::endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QJsonObject o = i.toObject();
|
|
||||||
// We can assume the object has:
|
|
||||||
// o["Title"].toString()
|
|
||||||
// o["Url"].toString()
|
|
||||||
// o["DocumentationUrl"].toString()
|
|
||||||
// o["Image"].toString()
|
|
||||||
// o["Description"].toString()
|
|
||||||
// o["SpecialNote"].toString()
|
|
||||||
// o["LDAP"].toBool()
|
|
||||||
std::cerr << qPrintable(o["Title"].toString()) << " " << o["LDAP"].toBool() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <dialogs/FederatedLogin.h>
|
#include <dialogs/FederatedLogin.h>
|
||||||
|
#include <lib/Service.h>
|
||||||
|
|
||||||
class Configurator:public QApplication {
|
class Configurator:public QApplication {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -16,5 +17,5 @@ protected Q_SLOTS:
|
|||||||
private:
|
private:
|
||||||
QNetworkAccessManager _nam;
|
QNetworkAccessManager _nam;
|
||||||
FederatedLogin * _loginDialog;
|
FederatedLogin * _loginDialog;
|
||||||
QJsonDocument _services;
|
Services _services;
|
||||||
};
|
};
|
||||||
|
2
lib/CMakeLists.txt
Normal file
2
lib/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
add_library(fed STATIC Service.cpp)
|
||||||
|
target_link_libraries(fed Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets)
|
22
lib/Service.cpp
Normal file
22
lib/Service.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "Service.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
Service::Service(QJsonObject const &o) {
|
||||||
|
title = o["Title"].toString();
|
||||||
|
url = o["Url"].toString();
|
||||||
|
documentationUrl = o["DocumentationUrl"].toString();
|
||||||
|
image = o["Image"].toString();
|
||||||
|
description = o["Description"].toString();
|
||||||
|
specialNote = o["SpecialNote"].toString();
|
||||||
|
LDAP = o["LDAP"].toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
Services::Services(QJsonArray const &a):QList<Service>() {
|
||||||
|
for(auto i : a) {
|
||||||
|
if(!i.isObject()) {
|
||||||
|
std::cerr << "Non-object in JSON array, ignoring" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
append(Service{i.toObject()});
|
||||||
|
}
|
||||||
|
}
|
24
lib/Service.h
Normal file
24
lib/Service.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
struct Service {
|
||||||
|
Service(QJsonObject const &o);
|
||||||
|
|
||||||
|
QString title;
|
||||||
|
QUrl url;
|
||||||
|
QUrl documentationUrl;
|
||||||
|
QUrl image;
|
||||||
|
QString description;
|
||||||
|
QString specialNote;
|
||||||
|
bool LDAP;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Services:public QList<Service> {
|
||||||
|
public:
|
||||||
|
Services():QList<Service>() {}
|
||||||
|
Services(QJsonArray const &a);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user