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 "about.h"
#include "serverconnection.h"
#include "ui_about.h" #include "ui_about.h"
#include <QGridLayout> #include <QGridLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QJsonDocument>
#include <QLabel> #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) {
/* config options layout */ mySettings = settings;
QGridLayout *layoutLegal = new QGridLayout(); mainLayout = new QGridLayout();
QGridLayout *layoutSoftwareinfo = new QGridLayout();
/* create legal box */ /* create legal box */
QGridLayout *layoutLegal = new QGridLayout();
QGroupBox *legalGroup = new QGroupBox(); 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 */ /* create software infor group */
QGroupBox *softwareInfoGroup = new QGroupBox(); layoutSoftwareinfo = new QGridLayout();
softwareInfoGroup = new QGroupBox();
QString *version = getCurrentVersion(); QString *version = getCurrentVersion();
QLabel *richText = new QLabel(); QLabel *versionLabelIdent = new QLabel("Version:");
richText->setText(*version); QLabel *versionLabel = new QLabel();
softwareInfoGroup->setTitle("Software Information"); 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); softwareInfoGroup->setLayout(layoutSoftwareinfo);
/* add groups to main layout */ /* add groups to main layout */
mainLayout->addWidget(softwareInfoGroup); mainLayout->addWidget(softwareInfoGroup);
mainLayout->addWidget(legalGroup);
/* setup main window */ /* setup main window */
QWidget *mainWidget = new QWidget(this); QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(mainLayout); mainWidget->setLayout(mainLayout);
this->setCentralWidget(mainWidget); 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() About::~About()
{ {
} }
QString* About::getCurrentVersion(){ void About::handleServerVersion(QNetworkReply* reply){
return new QString("<p>LOLOLOL</p>"); 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(){ QString* About::getCurrentVersion(){
return new QString("<p>LOLOLOL</p>"); return new QString(GIT_VERSION);
} }

14
about.h
View File

@@ -1,17 +1,29 @@
#ifndef ABOUT_H #ifndef ABOUT_H
#define ABOUT_H #define ABOUT_H
#include <QBoxLayout>
#include <QGroupBox>
#include <QLabel>
#include <QMainWindow> #include <QMainWindow>
#include <QNetworkReply>
#include <QSettings>
class About : public QMainWindow class About : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit About(QWidget *parent = nullptr); explicit About(QWidget *parent = nullptr, QSettings *settings = nullptr);
~About(); ~About();
private slots:
void handleServerVersion(QNetworkReply*);
private: private:
QGridLayout* mainLayout;
QGridLayout* layoutSoftwareinfo;
QLabel* serverInfo;
QGroupBox* softwareInfoGroup;
QSettings* mySettings;
QString* getCurrentVersion(); QString* getCurrentVersion();
QString* getServerVersion(); QString* getServerVersion();
}; };

View File

@@ -96,7 +96,7 @@ void MainWindow::openConfigurationWindow(){
} }
void MainWindow::openAboutWindow(){ void MainWindow::openAboutWindow(){
About *aboutWindow = new About(); About *aboutWindow = new About(this, mySettings);
aboutWindow->setAttribute(Qt::WA_DeleteOnClose); aboutWindow->setAttribute(Qt::WA_DeleteOnClose);
aboutWindow->show(); aboutWindow->show();
} }

View File

@@ -8,7 +8,6 @@
ServerConnection::ServerConnection(QObject *parent, QSettings *settings) ServerConnection::ServerConnection(QObject *parent, QSettings *settings)
{ {
setAuthHeader(settings->value(SETTING_USER).toString(), settings->value(SETTING_PASS).toString()); setAuthHeader(settings->value(SETTING_USER).toString(), settings->value(SETTING_PASS).toString());
networkManager = new QNetworkAccessManager(parent); networkManager = new QNetworkAccessManager(parent);
mySettings = settings; mySettings = settings;
@@ -76,6 +75,13 @@ void ServerConnection::submitFile(QJsonDocument jsonDocument){
qDebug("Request submitted"); qDebug("Request submitted");
} }
void ServerConnection::queryServerVersion(){
QUrl serviceUrl = QUrl(buildURLFromLocation(QString("/server-info")));
QNetworkRequest request(serviceUrl);
request.setRawHeader("Authorization", authHeaderData);
networkManager->get(request);
}
QNetworkAccessManager *ServerConnection::getNetworkManager(){ QNetworkAccessManager *ServerConnection::getNetworkManager(){
return networkManager; return networkManager;
} }

View File

@@ -15,6 +15,7 @@ public:
QString buildURLFromLocation(QVariant location); QString buildURLFromLocation(QVariant location);
QString buildURLFromLocation(QString location); QString buildURLFromLocation(QString location);
QNetworkAccessManager *getNetworkManager(); QNetworkAccessManager *getNetworkManager();
void queryServerVersion();
public slots: public slots:
void queryStatusAll(); void queryStatusAll();
private slots: private slots:

View File

@@ -1,13 +1,22 @@
#include "serverconnection.h"
#include "settings.h" #include "settings.h"
#include "ui_settings.h" #include "ui_settings.h"
#include <QDialog>
#include <QFile>
#include <QFileInfo>
#include <QFileInfo>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QMessageBox>
#include <QNetworkReply>
#include <QNetworkReply>
#include <QPushButton> #include <QPushButton>
#include <QSettings> #include <QSettings>
#include <settingkeys.h> #include <settingkeys.h>
#define SETTINGS_WINDOW_TITLE "Konfiguration" #define SETTINGS_WINDOW_TITLE "Konfiguration"
#define BUTTON_TEXT_CHECK "Konfiguration Testen"
#define BUTTON_TEXT_ABORT "Abbrechen" #define BUTTON_TEXT_ABORT "Abbrechen"
#define BUTTON_TEXT_OK "OK" #define BUTTON_TEXT_OK "OK"
@@ -74,16 +83,60 @@ void Settings::selectSettings(QSettings *selectedSettings){
} }
/* buttons */ /* buttons */
auto check = new QPushButton(BUTTON_TEXT_CHECK);
auto ok = new QPushButton(BUTTON_TEXT_OK); auto ok = new QPushButton(BUTTON_TEXT_OK);
auto cancle = new QPushButton(BUTTON_TEXT_ABORT); auto cancle = new QPushButton(BUTTON_TEXT_ABORT);
layout->addWidget(ok, configOptions->length(), 0); layout->addWidget(check, configOptions->length(), 0);
layout->addWidget(cancle, configOptions->length(), 1); layout->addWidget(ok, configOptions->length()+1, 0);
layout->addWidget(cancle, configOptions->length()+1, 1);
connect(check, SIGNAL(released()), this, SLOT(checkConfig()));
connect(ok, SIGNAL(released()), this, SLOT(okClose())); connect(ok, SIGNAL(released()), this, SLOT(okClose()));
connect(cancle, SIGNAL(released()), this, SLOT(cancleClose())); connect(cancle, SIGNAL(released()), this, SLOT(cancleClose()));
} }
void Settings::checkConfig(){
ServerConnection *sc = new ServerConnection(this, mySettings);
connect(sc->getNetworkManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(handleTestConnectionResult(QNetworkReply*)));
sc->queryServerVersion();
}
void Settings::handleTestConnectionResult(QNetworkReply* reply){
QString *dialogText;
bool error = false;
if(reply->error() != QNetworkReply::NoError){
dialogText = new QString(reply->errorString());
error = true;
}else {
dialogText = new QString("Verbinndung Ok");
}
#ifdef Q_OS_LINUX
auto *fi = new QFileInfo(mySettings->value(SETTING_LINUX_EXPLORER).toString());
if(!fi->isExecutable()){
dialogText->append("\nExplorer nicht ausführbar!");
error = true;
}
#endif
QLabel *testResult = new QLabel("Ok!");
testResult->setStyleSheet("QLabel { color : green; }");
if(error){
QMessageBox *info = new QMessageBox();
info->setAttribute(Qt::WA_DeleteOnClose);
info->setWindowTitle("Konfiguration - Fehler!");
info->setText(*dialogText);
info->show();
testResult = new QLabel("Konfigurationsfehler.");
testResult->setStyleSheet("QLabel { color : red; }");
}
auto cw = this->findChild<QWidget*>("centralwidget");
QGridLayout *layout = static_cast<QGridLayout*>(cw->layout());
layout->addWidget(testResult, configOptions->length(), 1);
}
void Settings::cancleClose(){ void Settings::cancleClose(){
if(false){ if(false){
// TODO warning // TODO warning

View File

@@ -4,6 +4,7 @@
#include <QMainWindow> #include <QMainWindow>
#include <QLineEdit> #include <QLineEdit>
#include <QSettings> #include <QSettings>
#include <QNetworkReply>
namespace Ui { namespace Ui {
class settings; class settings;
@@ -21,6 +22,8 @@ public:
private slots: private slots:
void okClose(); void okClose();
void cancleClose(); void cancleClose();
void checkConfig();
void handleTestConnectionResult(QNetworkReply *reply);
private: private:
Ui::settings *ui; Ui::settings *ui;
QSettings *mySettings; QSettings *mySettings;

View File

@@ -4,6 +4,8 @@
# #
#------------------------------------------------- #-------------------------------------------------
GIT_STR_VERSION = $$system(git describe)
QT += core gui network QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@@ -16,6 +18,7 @@ TEMPLATE = app
# depend on your compiler). Please consult the documentation of the # depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it. # deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += "GIT_VERSION=\"\\\"$$GIT_STR_VERSION\\\"\""
# You can also make your code fail to compile if you use deprecated APIs. # You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line. # In order to do so, uncomment the following line.