implement about window

This commit is contained in:
Yannik Schmidt
2020-09-03 23:56:33 +02:00
parent 782d34fa35
commit 41c29d43ce
8 changed files with 126 additions and 22 deletions

View File

@@ -1,49 +1,75 @@
#include "about.h"
#include "serverconnection.h"
#include "ui_about.h"
#include <QGridLayout>
#include <QGroupBox>
#include <QJsonDocument>
#include <QLabel>
About::About(QWidget *parent) : QMainWindow(parent) {
#define Y_POS_VERSION 0
#define Y_POS_SERVER_INFO 1
QGridLayout *mainLayout = new QGridLayout();
About::About(QWidget *parent, QSettings *settings) : QMainWindow(parent) {
mySettings = settings;
mainLayout = new QGridLayout();
/* config options layout */
QGridLayout *layoutLegal = new QGridLayout();
QGridLayout *layoutSoftwareinfo = new QGridLayout();
/* create legal box */
QGridLayout *layoutLegal = new QGridLayout();
QGroupBox *legalGroup = new QGroupBox();
legalGroup->setTitle("Rechtliches");
QLabel *licenseLabel = new QLabel("Diese Software wird unter der<a href=\"https://www.gnu.org/licenses/gpl-3.0-standalone.html\">GPLv3</a>verbreitet.<br>Code und Kompelierungsinstruktionen sind konform zur Lizenz<a href=\"https://github.com/FAUSheppy/speech-server-client-qt\">hier</a> zugänglich.");
licenseLabel->setOpenExternalLinks(true);
layoutLegal->addWidget(licenseLabel, 0, 0);
layoutLegal->addWidget(new QLabel("Author: Yannik Schmidt"), 1, 0);
legalGroup->setLayout(layoutLegal);
/* create software infor group */
QGroupBox *softwareInfoGroup = new QGroupBox();
layoutSoftwareinfo = new QGridLayout();
softwareInfoGroup = new QGroupBox();
QString *version = getCurrentVersion();
QLabel *richText = new QLabel();
richText->setText(*version);
softwareInfoGroup->setTitle("Software Information");
QLabel *versionLabelIdent = new QLabel("Version:");
QLabel *versionLabel = new QLabel();
serverInfo = new QLabel("Wird ermittelt..");
versionLabel->setText(*version);
layoutSoftwareinfo->addWidget(richText);
softwareInfoGroup->setTitle("Software Information");
layoutSoftwareinfo->addWidget(versionLabelIdent, Y_POS_VERSION, 0);
layoutSoftwareinfo->addWidget(versionLabel, Y_POS_VERSION, 1);
layoutSoftwareinfo->addWidget(new QLabel("Server:"), Y_POS_SERVER_INFO, 0);
layoutSoftwareinfo->addWidget(serverInfo, Y_POS_SERVER_INFO, 1);
softwareInfoGroup->setLayout(layoutSoftwareinfo);
/* add groups to main layout */
mainLayout->addWidget(softwareInfoGroup);
mainLayout->addWidget(legalGroup);
/* setup main window */
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(mainLayout);
this->setCentralWidget(mainWidget);
/* get server info and set as soon as possible*/
ServerConnection *sc = new ServerConnection(this, mySettings);
connect(sc->getNetworkManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(handleServerVersion(QNetworkReply*)));
sc->queryServerVersion();
}
About::~About()
{
}
QString* About::getCurrentVersion(){
return new QString("<p>LOLOLOL</p>");
void About::handleServerVersion(QNetworkReply* reply){
if(reply->error() != QNetworkReply::NoError){
serverInfo->setText(reply->errorString());
}else {
QJsonDocument json = QJsonDocument::fromJson(reply->readAll());
auto serverInfoValue = json["server-version"].toString();
serverInfo->setText(serverInfoValue);
}
}
QString* About::getServerVersion(){
return new QString("<p>LOLOLOL</p>");
QString* About::getCurrentVersion(){
return new QString(GIT_VERSION);
}