2024-08-27 22:13:54 +00:00
|
|
|
#include "Configurator.h"
|
|
|
|
#include <iostream>
|
2024-08-29 11:21:00 +00:00
|
|
|
#include <QJsonDocument>
|
2024-08-27 22:13:54 +00:00
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-08-29 11:21:00 +00:00
|
|
|
QJsonDocument services = QJsonDocument::fromJson(reply->readAll());
|
|
|
|
if(!services.isArray()) {
|
2024-08-27 22:13:54 +00:00
|
|
|
_loginDialog->setMessage(tr("App list did not return an array. Is the domain name correct?"));
|
|
|
|
_loginDialog->show();
|
|
|
|
return;
|
|
|
|
}
|
2024-08-29 11:21:00 +00:00
|
|
|
_services = services.array();
|
|
|
|
for(auto i : _services)
|
|
|
|
std::cerr << qPrintable(i.title) << std::endl;
|
2024-08-27 22:13:54 +00:00
|
|
|
}
|