2024-08-27 22:13:54 +00:00
|
|
|
#include "Configurator.h"
|
2024-09-03 13:40:08 +00:00
|
|
|
#include <dialogs/ServicesDialog.h>
|
2024-08-27 22:13:54 +00:00
|
|
|
#include <iostream>
|
2024-08-29 11:21:00 +00:00
|
|
|
#include <QJsonDocument>
|
2024-08-27 22:13:54 +00:00
|
|
|
#include <QJsonObject>
|
|
|
|
|
2024-09-03 19:52:55 +00:00
|
|
|
Configurator::Configurator(int &argc, char **&argv):QApplication(argc, argv),_nam(this),_settings("federated.computer", "configurator", this) {
|
2024-08-27 22:13:54 +00:00
|
|
|
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() {
|
2024-09-03 13:40:08 +00:00
|
|
|
QByteArray servicesJson = download("https://dashboard." + _loginDialog->domain() + "/apps");
|
|
|
|
if(servicesJson.isEmpty()) {
|
2024-08-27 22:13:54 +00:00
|
|
|
_loginDialog->setMessage(tr("Failed to retrieve app list. Is the domain name correct?"));
|
|
|
|
_loginDialog->show();
|
|
|
|
return;
|
|
|
|
}
|
2024-09-03 13:40:08 +00:00
|
|
|
QJsonDocument services = QJsonDocument::fromJson(servicesJson);
|
2024-08-29 11:21:00 +00:00
|
|
|
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();
|
2024-09-03 13:40:08 +00:00
|
|
|
|
|
|
|
ServicesDialog *d = new ServicesDialog(0);
|
|
|
|
d->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Configurator::download(QUrl const &url) {
|
|
|
|
QNetworkRequest req(url);
|
|
|
|
QNetworkReply *r = _nam.get(req);
|
|
|
|
waitForDownload(r);
|
|
|
|
QByteArray d = r->readAll();
|
|
|
|
delete r;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Configurator::waitForDownload(QNetworkReply *r) const {
|
|
|
|
if(!r->isFinished()) {
|
|
|
|
QEventLoop loop;
|
|
|
|
connect(r, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
|
|
|
loop.exec();
|
|
|
|
}
|
2024-08-27 22:13:54 +00:00
|
|
|
}
|