#include "Configurator.h" #include #include #include Configurator::Configurator(int &argc, char **&argv):QApplication(argc, argv),_nam(this) { setQuitOnLastWindowClosed(false); _loginDialog = new FederatedLogin(0); _loginDialog->setModal(true); connect(_loginDialog, &QDialog::accepted, this, &Configurator::loginRequested); connect(_loginDialog, &QDialog::rejected, this, &QApplication::quit); _loginDialog->show(); } void Configurator::loginRequested() { QNetworkRequest *req=new QNetworkRequest("https://dashboard." + _loginDialog->domain() + "/apps"); connect(&_nam, &QNetworkAccessManager::finished, this, &Configurator::appListReceived); QNetworkReply *r=_nam.get(*req); } void Configurator::appListReceived(QNetworkReply *reply) { disconnect(&_nam, &QNetworkAccessManager::finished, this, &Configurator::appListReceived); if(reply->error() != QNetworkReply::NoError) { _loginDialog->setMessage(tr("Failed to retrieve app list. Is the domain name correct?")); _loginDialog->show(); return; } _services=QJsonDocument::fromJson(reply->readAll()); if(!_services.isArray()) { _loginDialog->setMessage(tr("App list did not return an array. Is the domain name correct?")); _loginDialog->show(); return; } QJsonArray a=_services.array(); for(auto i : a) { if(!i.isObject()) { 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; } }