Initial import

Not much there yet, just a login dialog and an app list
JSON parser
This commit is contained in:
Bernhard Rosenkränzer 2024-08-28 00:13:54 +02:00
commit 7f0cd77b4e
9 changed files with 177 additions and 0 deletions

15
CMakeLists.txt Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.20)
project(configurator)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 23)
set(QT_VERSION 6 CACHE STRING "Major version of Qt to use (6 will work, anything else may or may not work)")
find_package(Qt${QT_VERSION} COMPONENTS Core Gui Widgets WebEngineWidgets REQUIRED)
add_subdirectory(dialogs)
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)
install(TARGETS configurator DESTINATION bin)

51
Configurator.cpp Normal file
View File

@ -0,0 +1,51 @@
#include "Configurator.h"
#include <iostream>
#include <QJsonArray>
#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;
}
_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;
}
}

20
Configurator.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include <QApplication>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonDocument>
#include <dialogs/FederatedLogin.h>
class Configurator:public QApplication {
Q_OBJECT
public:
Configurator(int &argc, char **&argv);
protected Q_SLOTS:
void loginRequested();
void appListReceived(QNetworkReply *reply);
private:
QNetworkAccessManager _nam;
FederatedLogin * _loginDialog;
QJsonDocument _services;
};

2
dialogs/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
add_library(dialogs STATIC FederatedLogin.cpp)
target_link_libraries(dialogs Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets)

View File

@ -0,0 +1,35 @@
#include "FederatedLogin.h"
FederatedLogin::FederatedLogin(QWidget *parent):QDialog(parent),_layout(this) {
int y = 0;
_message = new QLabel(this);
setMessage("");
_layout.addWidget(_message, y, 0, 1, 2);
_domainLbl = new QLabel(tr("&Domain:"), this);
_layout.addWidget(_domainLbl, ++y, 0);
_domain = new QLineEdit("f11890a1.fedcom.net", this);
_domainLbl->setBuddy(_domain);
_layout.addWidget(_domain, y, 1);
_userLbl = new QLabel(tr("&User/Email:"), this);
_layout.addWidget(_userLbl, ++y, 0);
_user = new QLineEdit(this);
_userLbl->setBuddy(_user);
_layout.addWidget(_user, y, 1);
_passwordLbl = new QLabel(tr("&Password:"), this);
_layout.addWidget(_passwordLbl, ++y, 0);
_password = new QLineEdit(this);
_password->setEchoMode(QLineEdit::Password);
_passwordLbl->setBuddy(_password);
_layout.addWidget(_password, y, 1);
_ok = new QPushButton(tr("&OK"), this);
_layout.addWidget(_ok, ++y, 0);
_cancel = new QPushButton(tr("&Cancel"), this);
_layout.addWidget(_cancel, y, 1);
connect(_ok, &QPushButton::clicked, this, &QDialog::accept);
connect(_cancel, &QPushButton::clicked, this, &QDialog::reject);
}
void FederatedLogin::setMessage(QString const &m) {
_message->setText(m);
_message->setHidden(m.isEmpty());
}

28
dialogs/FederatedLogin.h Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include <QDialog>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
class FederatedLogin:public QDialog {
Q_OBJECT
public:
FederatedLogin(QWidget *parent=0);
QString domain() const { return _domain->text(); }
QString user() const { return _user->text(); }
QString password() const { return _password->text(); }
void setMessage(QString const &m);
protected:
QGridLayout _layout;
QLabel * _message;
QLabel * _domainLbl;
QLineEdit * _domain;
QLabel * _userLbl;
QLineEdit * _user;
QLabel * _passwordLbl;
QLineEdit * _password;
QPushButton * _ok;
QPushButton * _cancel;
};

10
lib/DnfPackageInstaller.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include "PackageInstaller.h"
class DnfPackageInstaller:public PackageInstaller {
public:
bool installPackages(QString const &packages) const;
bool installPackage(QString const &package) const;
bool installed(QString const &package) const;
};

10
lib/PackageInstaller.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include <QString>
class PackageInstaller {
public:
virtual bool installPackages(QStringList const &packages) const;
virtual bool installPackage(QString const &package) const = 0;
virtual bool installed(QString const &package) const = 0;
};

6
main.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "Configurator.h"
int main(int argc, char **argv) {
Configurator app(argc, argv);
app.exec();
}