18 Commits

Author SHA1 Message Date
Yannik Schmidt
c05a38c45d remember most recently selected path/file 2020-09-17 20:26:15 +02:00
Yannik Schmidt
76b077a661 fix win explorer call 2020-09-17 20:17:21 +02:00
Yannik Schmidt
360e8a03d3 implement samedir transcript saving 2020-09-17 19:42:33 +02:00
Yannik Schmidt
31aec36202 initialize checkConfig with nullptr 2020-09-17 18:53:07 +02:00
Yannik Schmidt
529ff87c44 fix windows crash 2020-09-17 17:59:24 +02:00
Yannik Schmidt
7793499acc fix pp input 2020-09-07 20:12:13 +02:00
Yannik Schmidt
1839b4b28e implement server config remove button 2020-09-07 19:25:01 +02:00
Yannik Schmidt
29be79f278 remove forgotten debug msg 2020-09-07 18:32:22 +02:00
Yannik Schmidt
e21b1ac3ca implement clear cache option after context change 2020-09-07 16:00:58 +02:00
Yannik Schmidt
3f6862e26b Save settings before running check
https://github.com/FAUSheppy/speech-server-client-qt/issues/1
2020-09-05 22:07:48 +02:00
Yannik Schmidt
4bee34fbd6 implement adding new serverconfig 2020-09-05 21:34:23 +02:00
Yannik Schmidt
5a4620191c fix list display 2020-09-04 23:54:34 +02:00
Yannik Schmidt
b7023d348b implement server settings window (readonly) 2020-09-04 23:33:24 +02:00
Yannik Schmidt
30291ef72d change option labels 2020-09-04 14:07:55 +02:00
Yannik Schmidt
758babcaf8 correctly name project 2020-09-04 13:21:40 +02:00
Yannik Schmidt
205f591dad add README.md 2020-09-04 13:16:11 +02:00
Yannik Schmidt
916005ddea add more information to about 2020-09-04 12:59:33 +02:00
Yannik Schmidt
41c29d43ce implement about window 2020-09-03 23:56:33 +02:00
24 changed files with 757 additions and 62 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
*.user
*.stash
Makefile

29
README.md Normal file
View File

@@ -0,0 +1,29 @@
# Intro
This is the GUI Interface to a proprietary server that interfaces with speech recognition backends.
![GUI Main-Window](https://media.atlantishq.de/qt_client.png)
# Build on Linux
This is a qt-creator project and can be imported as such. To build for Windows (on Linux) you need [MXE](https://github.com/mxe/mxe.git).
To download and compile MXE and dependencies:
git clone https://github.com/mxe/mxe.git
cd mxe && make qtbase
make -j 4 qt qt5 MXE_TARGETS='x86_64-w64-mingw32.shared i686-w64-mingw32.shared x86_64-w64-mingw32.static i686-w64-mingw32.static'
make qtbase
Setup the actual compilation enviroment:
MXE_ROOT=/path/to/mxe/root/
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$MXE_ROOT/usr/bin
$MXE_ROOT/usr/bin/i686-w64-mingw32.static-qmake-qt5
make
Also check the ``cross_compile.sh`` file in this project.
# Build on Windows
If you want to build this project on windows, you need change the way this project determines some of it's defines in the project file.
# Build for Mac
This project does not currently support Mac.

View File

@@ -1,49 +1,89 @@
#include "about.h"
#include "ui_about.h"
#include "serverconnection.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
#define Y_POS_BUILD_DATE 2
#define Y_POS_BUILD_HOST 3
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("GUI Version:");
QLabel *versionLabel = new QLabel();
serverInfo = new QLabel("Wird ermittelt..");
versionLabel->setText(*version);
layoutSoftwareinfo->addWidget(richText);
QLabel *buildDateLabelIdent = new QLabel("Version gebaut:");
QLabel *buildDateLabel = new QLabel(BUILD_DATE);
layoutSoftwareinfo->addWidget(buildDateLabelIdent, Y_POS_BUILD_DATE, 0);
layoutSoftwareinfo->addWidget(buildDateLabel, Y_POS_BUILD_DATE, 1);
QLabel *buildHostLabelIdent = new QLabel("Kompilations Host:");
QLabel *buildHostLabel = new QLabel(BUILD_HOST);
layoutSoftwareinfo->addWidget(buildHostLabelIdent, Y_POS_BUILD_HOST, 0);
layoutSoftwareinfo->addWidget(buildHostLabel, Y_POS_BUILD_HOST, 1);
softwareInfoGroup->setTitle("Software Information");
layoutSoftwareinfo->addWidget(versionLabelIdent, Y_POS_VERSION, 0);
layoutSoftwareinfo->addWidget(versionLabel, Y_POS_VERSION, 1);
layoutSoftwareinfo->addWidget(new QLabel("Server Version:"), 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 + " (kompatibel)");
}
}
QString* About::getServerVersion(){
return new QString("<p>LOLOLOL</p>");
QString* About::getCurrentVersion(){
QString *string = new QString(GIT_VERSION);
return string;
}

16
about.h
View File

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

37
listItemServeConfig.ui Normal file
View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -7,5 +7,9 @@ int main(int argc, char *argv[])
MainWindow w;
w.show();
a.setApplicationName("Speech-To-Text");
a.setOrganizationName("Lantia IT");
a.setOrganizationDomain("lantia-it.de");
return a.exec();
}

View File

@@ -1,6 +1,7 @@
#include "about.h"
#include "mainwindow.h"
#include "notificationwidget.h"
#include "serverconfig.h"
#include "settings.h"
#include "ui_mainwindow.h"
#include <QCoreApplication>
@@ -80,13 +81,20 @@ MainWindow::MainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::MainWind
timer->start(1000);
/* add handler for menu configuration */
ui->menuKonfiguration->addAction("Standards", this, SLOT(openConfigurationWindow()) );
ui->menuKonfiguration->addAction("Spracherkennung", this, SLOT(openSpeechConfigWindow()) );
ui->menuKonfiguration->addAction("Konfiguration", this, SLOT(openConfigurationWindow()) );
ui->menuKonfiguration->addAction("Über diese Software", this, SLOT(openAboutWindow()) );
/* set window options */
this->setWindowTitle(WINDOW_TITLE);
}
void MainWindow::openSpeechConfigWindow(){
ServerConfig *serverConfig = new ServerConfig(this, mySettings);
serverConfig->setAttribute(Qt::WA_DeleteOnClose);
serverConfig->show();
}
void MainWindow::openConfigurationWindow(){
Settings *settingsWindow = new Settings();
settingsWindow->selectSettings(this->mySettings);
@@ -96,7 +104,7 @@ void MainWindow::openConfigurationWindow(){
}
void MainWindow::openAboutWindow(){
About *aboutWindow = new About();
About *aboutWindow = new About(this, mySettings);
aboutWindow->setAttribute(Qt::WA_DeleteOnClose);
aboutWindow->show();
}
@@ -140,12 +148,24 @@ void MainWindow::handleInitialSettings(){
}
void MainWindow::importFile(){
QString startDir = QDir::currentPath();
if(mySettings->contains(SETTING_MOST_RECENT_PATH)){
startDir = mySettings->value(SETTING_MOST_RECENT_PATH).toString();
}
QString filename = QFileDialog::getOpenFileName(
this,
"Open Document",
QDir::currentPath(),
startDir,
"All files (*.*) ;; Document files (*.doc *.rtf);; PNG files (*.png)");
/* set most recent path */
QFileInfo* fi = new QFileInfo(filename);
QDir dirInfo = fi->absoluteDir();
QString dirPath = dirInfo.absolutePath();
mySettings->setValue(SETTING_MOST_RECENT_PATH, dirPath);
if(filename.isNull()){
return;
}else{
@@ -167,7 +187,17 @@ void MainWindow::showNotification(QString str){
void MainWindow::openContainingDir(){
QString filePath = mySettings->value(SETTING_SAVE_DIR).toString();
QString settingPath = mySettings->value(SETTING_SAVE_DIR).toString();
QString filePath;
if(QString::compare(settingPath, ".") == 0){
QPushButton* senderButton = static_cast<QPushButton*>(sender());
filePath = senderButton->toolTip();
QFileInfo* fi = new QFileInfo(filePath);
QDir dirInfo = fi->absoluteDir();
filePath = dirInfo.absolutePath();
}else{
filePath = settingPath;
}
QStringList args;
/* OS specific explorer call */
@@ -176,7 +206,7 @@ void MainWindow::openContainingDir(){
QProcess::startDetached(mySettings->value(SETTING_LINUX_EXPLORER).toString(), args);
#endif
#ifdef Q_OS_WIN
args << "/select," << QDir::toNativeSeparators(filePath);
args << QDir::toNativeSeparators(filePath);
QProcess::startDetached("explorer", args);
#endif
}
@@ -251,6 +281,13 @@ void MainWindow::saveTranscript(QNetworkReply* reply){
/* save return data */
QString fullpath = QDir(mySettings->value(SETTING_SAVE_DIR).toString()).filePath(targetName);
QString settingPath = mySettings->value(SETTING_SAVE_DIR).toString();
if(QString::compare(settingPath, ".") == 0){
fullpath = tw->item(rowId, FILENAME_COL)->text() + ".txt";
}else{
/* do nothing */
}
QFile file(fullpath);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
@@ -308,6 +345,7 @@ void MainWindow::addTrackingToList(QNetworkReply* reply){
auto *openDirCellContent = new QWidget();
openDirLayout->addWidget(dirButton);
dirButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
dirButton->setToolTip(filename);
openDirLayout->setContentsMargins(0,0,0,0);
openDirCellContent->setLayout(openDirLayout);

View File

@@ -29,6 +29,7 @@ private slots:
void openConfigurationWindow();
void appyConfigChanges();
void openAboutWindow();
void openSpeechConfigWindow();
private:
Ui::MainWindow *ui;
QTableWidget *tw;

View File

@@ -38,7 +38,7 @@
</property>
<widget class="QMenu" name="menuKonfiguration">
<property name="title">
<string>&amp;Konfiguration</string>
<string>&amp;Weitere Optionen</string>
</property>
</widget>
<addaction name="menuKonfiguration"/>

24
multivalueinputdialog.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include "multivalueinputdialog.h"
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QLabel>
MultiValueInputDialog::MultiValueInputDialog(QStringList *inputValueLabels, QWidgetList *inputWidgets){
QFormLayout *form = new QFormLayout();
for(int i = 0; i<inputValueLabels->size(); i++){
form->addRow(new QLabel(inputValueLabels->at(i)));
form->addRow(inputWidgets->at(i));
}
// Add some text above the fields
// Add some standard buttons (Cancel/Ok) at the bottom of the dialog
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
form->addRow(buttonBox);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
this->setLayout(form);
}

13
multivalueinputdialog.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef MULTIVALUEINPUTDIALOG_H
#define MULTIVALUEINPUTDIALOG_H
#include <QDialog>
#include <QMainWindow>
class MultiValueInputDialog : public QDialog
{
public:
MultiValueInputDialog(QStringList *inputValueLabels, QWidgetList *inputWidgets);
};
#endif // MULTIVALUEINPUTDIALOG_H

View File

@@ -0,0 +1 @@
#include "pushbuttonwithposition.h"

17
pushbuttonwithposition.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef PUSHBUTTONWITHPOSITION_H
#define PUSHBUTTONWITHPOSITION_H
#include <QPushButton>
class PushButtonWithPosition : public QPushButton
{
public:
PushButtonWithPosition(int row, QString text) : QPushButton(text){
this->row = row;
}
int row;
};
#endif // PUSHBUTTONWITHPOSITION_H

238
serverconfig.cpp Normal file
View File

@@ -0,0 +1,238 @@
#include "serverconfig.h"
#include "serverconnection.h"
#include <QGridLayout>
#include <QGroupBox>
#include <QListWidget>
#include <QWidget>
#include <QtUiTools>
#include "multivalueinputdialog.h"
#include "urls.h"
#include "pushbuttonwithposition.h"
ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(parent) {
mySettings = settings;
sc = new ServerConnection(this, mySettings);
connect(sc->getNetworkManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedRequest(QNetworkReply*)), Qt::UniqueConnection);
sc->getUnifiedServerConfig();
/* post processing group */
QGroupBox *pp = new QGroupBox();
pp->setTitle("Post Processing");
ppTable = new QTableWidget();
/* table ui */
ppTable->verticalHeader()->setVisible(false);
ppTable->horizontalHeader()->setVisible(false);
ppTable->setRowCount(0);
QStringList *headerList = new QStringList();
headerList->append("Suchwort");
headerList->append("Ersetzen durch");
headerList->append("Entfernen");
ppTable->setColumnCount(headerList->length());
ppTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
QGridLayout *innerLayoutPP = new QGridLayout();
QPushButton *addNew = new QPushButton("Neue Regel");
innerLayoutPP->addWidget(ppTable);
innerLayoutPP->addWidget(addNew);
pp->setLayout(innerLayoutPP);
/* context phrases group */
QGridLayout *innerLayoutContext = new QGridLayout();
QGroupBox *context = new QGroupBox();
context->setTitle("Spracherkennungs Wörter");
contextTable = new QTableWidget();
/* table ui */
contextTable->verticalHeader()->setVisible(false);
contextTable->horizontalHeader()->setVisible(false);
contextTable->setRowCount(0);
QStringList *headerListContext = new QStringList();
headerListContext->append("Ausdruck/Wort");
headerListContext->append("Entfernen");
contextTable->setColumnCount(headerListContext->length());
contextTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
QPushButton *addNewContext = new QPushButton("Neuer Ausdruck");
innerLayoutContext->addWidget(contextTable);
innerLayoutContext->addWidget(addNewContext);
context->setLayout(innerLayoutContext);
/* connect buttons */
connect(addNew, SIGNAL (released()), this, SLOT (addNewPP()));
connect(addNewContext, SIGNAL (released()), this, SLOT (addNewContext()));
/* setup main window */
mainLayout = new QGridLayout();
mainLayout->addWidget(pp);
mainLayout->addWidget(context);
QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(mainLayout);
this->setCentralWidget(mainWidget);
}
void ServerConfig::removePP(){
PushButtonWithPosition* pButton = static_cast<PushButtonWithPosition*>(sender());
auto key = ppTable->item(pButton->row, 0);
auto repl = ppTable->item(pButton->row, 1);
sc->submitPostProcessorChange(key->text(), repl->text(), true);
}
void ServerConfig::removeContext(){
PushButtonWithPosition* pButton = static_cast<PushButtonWithPosition*>(sender());
auto label = contextTable->item(pButton->row, 0);
sc->submitSpeechContextPhraseChange(label->text(), true);
}
void ServerConfig::addNewPP(){
QStringList *sl = new QStringList();
sl->append("Schlüsselword");
sl->append("Ersetzung");
QWidgetList *wl = new QWidgetList();
wl->append(new QLineEdit());
wl->append(new QLineEdit());
MultiValueInputDialog *dialog = new MultiValueInputDialog(sl, wl);
if (dialog->exec() == QDialog::Accepted) {
auto keyword = static_cast<QLineEdit*>(wl->at(0));
auto replace = static_cast<QLineEdit*>(wl->at(1));
if(!keyword->text().isEmpty() && !replace->text().isEmpty()){
sc->submitPostProcessorChange(keyword->text(), replace->text());
}
}
}
void ServerConfig::askFlushServerCache(){
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Server Cache",
"Sollen alte Transcripte auf dem Server, die ohne diese Konfiguration erstellt wurden gelöscht werden?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
sc->flushCache();
}
}
void ServerConfig::addNewContext()
{
QStringList *sl = new QStringList();
sl->append("Ausdruck");
QWidgetList *wl = new QWidgetList();
wl->append(new QLineEdit());
MultiValueInputDialog *dialog = new MultiValueInputDialog(sl, wl);
if (dialog->exec() == QDialog::Accepted) {
auto lineEdit = static_cast<QLineEdit*>(wl->at(0));
if(!lineEdit->text().isEmpty()){
sc->submitSpeechContextPhraseChange(lineEdit->text());
askFlushServerCache();
}
}
}
QWidget* ServerConfig::loatListItemUiForm()
{
QUiLoader loader;
QFile file(":/forms/serverconfigitem.ui");
file.open(QFile::ReadOnly);
QWidget *formWidget = loader.load(&file, this);
file.close();
return formWidget;
}
void ServerConfig::finishedRequest(QNetworkReply *reply){
if(reply->error() != QNetworkReply::NoError){
qDebug("unified sc fail..");
return;
}
QString addPP = sc->buildURLFromLocation(PP_EDIT);
QString addContext = sc->buildURLFromLocation(CONTEXT_EDIT);
QString flushCache = sc->buildURLFromLocation(FLUSH_SERVER_CACHE);
if(QString::compare(reply->url().toString(), addPP) == 0){
sc->getUnifiedServerConfig();
}else if(QString::compare(reply->url().toString(), addContext) == 0){
sc->getUnifiedServerConfig();
}else if(QString::compare(reply->url().toString(), flushCache) == 0){
QMessageBox msgBox;
msgBox.setText("Server Cache Gelöscht");
QJsonObject jsonFlushCache = QJsonDocument::fromJson(reply->readAll()).object();
QJsonArray removals = jsonFlushCache["removals"].toArray();
QString display = "";
for(int i = 0; i < removals.size(); i++){
display += removals[i].toString();
display += "<br>";
}
msgBox.setInformativeText(display);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}else{
/* this is the unified server config query */
/* get filename and tracking id from replay */
QJsonObject json = QJsonDocument::fromJson(reply->readAll()).object();
auto keywordMap = json["keyword-map"].toObject();
auto phrases = json["phrases"].toArray();
contextTable->clear();
contextTable->setRowCount(0);
ppTable->clear();
ppTable->setRowCount(0);
for(int i = 0; i < phrases.size(); i++){
contextTable->insertRow(i);
contextTable->setItem(i, 0, new QTableWidgetItem(phrases.at(i).toString()));
auto *deleteButtonLayout = new QGridLayout();
auto *deleteCell = new QWidget();
auto *deleteButton = new PushButtonWithPosition(i, "Entfernen");
connect(deleteButton, SIGNAL (released()), this, SLOT (removeContext()));
deleteButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
deleteButtonLayout->addWidget(deleteButton);
deleteButtonLayout->setContentsMargins(0,0,0,0);
deleteCell->setLayout(deleteButtonLayout);
contextTable->setCellWidget(i, 1, deleteCell);
}
for(int i = 0; i < keywordMap.keys().size(); i++){
auto key = keywordMap.keys().at(i);
ppTable->insertRow(i);
ppTable->setItem(i, 0, new QTableWidgetItem(key));
ppTable->setItem(i, 1, new QTableWidgetItem(keywordMap[key].toString()));
auto *deleteButtonLayout = new QGridLayout();
auto *deleteCell = new QWidget();
auto *deleteButton = new PushButtonWithPosition(i, "Entfernen");
connect(deleteButton, SIGNAL (released()), this, SLOT (removePP()));
deleteButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
deleteButtonLayout->addWidget(deleteButton);
deleteButtonLayout->setContentsMargins(0,0,0,0);
deleteCell->setLayout(deleteButtonLayout);
ppTable->setCellWidget(i, 2, deleteCell);
}
this->repaint();
}
}
ServerConfig::~ServerConfig()
{
}

38
serverconfig.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef SERVERCONFIG_H
#define SERVERCONFIG_H
#include "serverconnection.h"
#include <QGridLayout>
#include <QMainWindow>
#include <QNetworkReply>
#include <QSettings>
#include <QTableWidget>
#include <QWidget>
class ServerConfig : public QMainWindow
{
Q_OBJECT
public:
explicit ServerConfig(QWidget *parent = nullptr, QSettings *settings = nullptr);
virtual ~ServerConfig();
private slots:
void finishedRequest(QNetworkReply*);
void addNewPP();
void addNewContext();
void removePP();
void removeContext();
private:
QGridLayout* mainLayout;
QSettings* mySettings;
QWidget *loatListItemUiForm();
QTableWidget* ppTable;
QTableWidget* contextTable;
ServerConnection* sc;
void askFlushServerCache();
};
#endif // SERVERCONFIG_H

34
serverconfigitem.ui Normal file
View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineEdit_2"/>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="buttonDelete">
<property name="text">
<string>Löschen</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -5,10 +5,13 @@
#include <QJsonObject>
#include <QNetworkAccessManager>
#include <QSettings>
#include <urls.h>
#define AUTH_HEADER_NAME "Authorization"
#define MIME_JSON "application/json"
ServerConnection::ServerConnection(QObject *parent, QSettings *settings)
{
setAuthHeader(settings->value(SETTING_USER).toString(), settings->value(SETTING_PASS).toString());
networkManager = new QNetworkAccessManager(parent);
mySettings = settings;
@@ -19,6 +22,10 @@ QString ServerConnection::buildURLFromLocation(QVariant location){
return buildURLFromLocation(location.toString());
}
QString ServerConnection::buildURLFromLocation(const char *location){
return buildURLFromLocation(QString(location));
}
QString ServerConnection::buildURLFromLocation(QString location){
QString proto = mySettings->value(SETTING_PROTO).toString();
QString host = mySettings->value(SETTING_HOST).toString();
@@ -48,7 +55,7 @@ void ServerConnection::queryStatusAll(){
QString statusRequestUrl = buildURLFromLocation(mySettings->value(SETTING_LOC_STATE));
QUrl trackingUrl = QUrl(statusRequestUrl);
QNetworkRequest request(trackingUrl);
request.setRawHeader("Authorization", authHeaderData);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
//qDebug("Status query sent");
}
@@ -58,7 +65,7 @@ void ServerConnection::queryTransscript(QString trackingId){
QString paramUrl = QString("%1?id=%2").arg(url, trackingId);
QUrl transcriptUrl = QUrl(paramUrl);
QNetworkRequest request(transcriptUrl);
request.setRawHeader("Authorization", authHeaderData);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
}
@@ -67,8 +74,8 @@ void ServerConnection::submitFile(QJsonDocument jsonDocument){
/* prepare request */
QUrl serviceUrl = QUrl(buildURLFromLocation(mySettings->value(SETTING_LOC_SUBMIT)));
QNetworkRequest request(serviceUrl);
request.setRawHeader("Authorization", authHeaderData);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
request.setHeader(QNetworkRequest::ContentTypeHeader, MIME_JSON);
/* make request */
networkManager->post(request, jsonDocument.toJson());
@@ -76,6 +83,76 @@ void ServerConnection::submitFile(QJsonDocument jsonDocument){
qDebug("Request submitted");
}
void ServerConnection::queryServerVersion(){
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(SERVER_INFO)));
QNetworkRequest request(serviceUrl);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
}
QNetworkAccessManager *ServerConnection::getNetworkManager(){
return networkManager;
}
void ServerConnection::submitPostProcessorChange(QString keyword, QString repl, bool remove){
QJsonObject json = QJsonObject();
json["keyword-regex"] = keyword;
json["replacement"] = repl;
if(remove){
json["action"] = "delete";
}else{
json["action"] = "add";
}
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(PP_EDIT)));
QNetworkRequest request(serviceUrl);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
request.setHeader(QNetworkRequest::ContentTypeHeader, MIME_JSON);
networkManager->post(request, QJsonDocument(json).toJson());
}
void ServerConnection::submitSpeechContextPhraseChange(QString phrase, bool remove){
QJsonObject json = QJsonObject();
json["phrase"] = phrase;
if(remove){
json["action"] = "delete";
}else{
json["action"] = "add";
}
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(CONTEXT_EDIT)));
QNetworkRequest request(serviceUrl);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
request.setHeader(QNetworkRequest::ContentTypeHeader, MIME_JSON);
networkManager->post(request, QJsonDocument(json).toJson());
}
void ServerConnection::getSpeechContextPhrases(){
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(CONTEXT_GET)));
QNetworkRequest request(serviceUrl);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
}
void ServerConnection::getPostProcessorMap(){
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(PP_GET)));
QNetworkRequest request(serviceUrl);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
}
void ServerConnection::getUnifiedServerConfig(){
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(UNIFIED_GET)));
QNetworkRequest request(serviceUrl);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
}
void ServerConnection::flushCache(){
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(FLUSH_SERVER_CACHE)));
QNetworkRequest request(serviceUrl);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
}

View File

@@ -15,6 +15,14 @@ public:
QString buildURLFromLocation(QVariant location);
QString buildURLFromLocation(QString location);
QNetworkAccessManager *getNetworkManager();
void queryServerVersion();
void getPostProcessorMap();
void submitPostProcessorChange(QString keyword, QString repl, bool remove = false);
void submitSpeechContextPhraseChange(QString phrase, bool remove = false);
void getSpeechContextPhrases();
void getUnifiedServerConfig();
QString buildURLFromLocation(const char *location);
void flushCache();
public slots:
void queryStatusAll();
private slots:

View File

@@ -11,5 +11,6 @@
#define SETTING_USER "user"
#define SETTING_PASS "pass"
#define SETTING_LINUX_EXPLORER "linux-explorer"
#define SETTING_MOST_RECENT_PATH "most-recent-path"
#endif // SETTINGKEYS_H

View File

@@ -1,13 +1,22 @@
#include "serverconnection.h"
#include "settings.h"
#include "ui_settings.h"
#include <QDialog>
#include <QFile>
#include <QFileInfo>
#include <QFileInfo>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QNetworkReply>
#include <QNetworkReply>
#include <QPushButton>
#include <QSettings>
#include <settingkeys.h>
#define SETTINGS_WINDOW_TITLE "Konfiguration"
#define BUTTON_TEXT_CHECK "Konfiguration Testen"
#define BUTTON_TEXT_ABORT "Abbrechen"
#define BUTTON_TEXT_OK "OK"
@@ -44,10 +53,15 @@ Settings::Settings(QWidget *parent) :
#endif
this->setWindowTitle(SETTINGS_WINDOW_TITLE);
currentConfigCheckDisplay = nullptr;
}
void Settings::selectSettings(QSettings *selectedSettings){
this->mySettings = selectedSettings;
sc = new ServerConnection(this, mySettings);
connect(sc->getNetworkManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(handleTestConnectionResult(QNetworkReply*)));
/* config options layout */
auto cw = this->findChild<QWidget*>("centralwidget");
@@ -74,16 +88,63 @@ void Settings::selectSettings(QSettings *selectedSettings){
}
/* buttons */
auto check = new QPushButton(BUTTON_TEXT_CHECK);
auto ok = new QPushButton(BUTTON_TEXT_OK);
auto cancle = new QPushButton(BUTTON_TEXT_ABORT);
layout->addWidget(ok, configOptions->length(), 0);
layout->addWidget(cancle, configOptions->length(), 1);
layout->addWidget(check, configOptions->length(), 0);
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(cancle, SIGNAL(released()), this, SLOT(cancleClose()));
}
void Settings::checkConfig(){
saveSetting();
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());
if(currentConfigCheckDisplay != nullptr){
delete currentConfigCheckDisplay; //this removes it from the layout
}
currentConfigCheckDisplay = testResult;
layout->addWidget(testResult, configOptions->length(), 1);
}
void Settings::cancleClose(){
if(false){
// TODO warning
@@ -91,14 +152,18 @@ void Settings::cancleClose(){
this->close();
}
void Settings::okClose(){
void Settings::saveSetting(){
QSettings mySettings;
for(auto key : configLineEditMap->keys()){
QString input = configLineEditMap->take(key)->text();
QString input = configLineEditMap->value(key)->text();
if(input.compare("") != 0){
this->mySettings->setValue(key, input);
}
}
}
void Settings::okClose(){
saveSetting();
this->close();
}

View File

@@ -1,9 +1,13 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#include "serverconnection.h"
#include <QMainWindow>
#include <QLineEdit>
#include <QSettings>
#include <QNetworkReply>
#include <QLabel>
namespace Ui {
class settings;
@@ -21,12 +25,17 @@ public:
private slots:
void okClose();
void cancleClose();
void checkConfig();
void handleTestConnectionResult(QNetworkReply *reply);
private:
ServerConnection *sc;
Ui::settings *ui;
QSettings *mySettings;
QHash<QString, QLineEdit*> *configLineEditMap;
QStringList *configOptionsKeys;
QStringList *configOptions;
void saveSetting();
QLabel *currentConfigCheckDisplay;
};
#endif // SETTINGS_H

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>settings</class>
<widget class="QMainWindow" name="settings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>281</width>
<height>245</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -4,11 +4,15 @@
#
#-------------------------------------------------
QT += core gui network
GIT_STR_VERSION = $$system(git describe)
DATE_STR = $$system(date)
HOSTNAME_STR = $$system(hostname)
QT += core gui network uitools
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TARGET = speech-server-client-qt
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
@@ -16,6 +20,9 @@ TEMPLATE = app
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += "GIT_VERSION=\"\\\"$$GIT_STR_VERSION\\\"\""
DEFINES += "BUILD_DATE=\"\\\"$$DATE_STR\\\"\""
DEFINES += "BUILD_HOST=\"\\\"$$HOSTNAME_STR\\\"\""
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
@@ -30,7 +37,10 @@ SOURCES += \
notificationwidget.cpp \
settings.cpp \
about.cpp \
serverconnection.cpp
serverconnection.cpp \
serverconfig.cpp \
multivalueinputdialog.cpp \
pushbuttonwithposition.cpp
HEADERS += \
mainwindow.h \
@@ -38,11 +48,16 @@ HEADERS += \
settings.h \
settingkeys.h \
about.h \
serverconnection.h
serverconnection.h \
serverconfig.h \
urls.h \
multivalueinputdialog.h \
pushbuttonwithposition.h
FORMS += \
mainwindow.ui \
settings.ui
listItemServeConfig.ui \
serverconfigitem.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin

15
urls.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef URLS_H
#define URLS_H
#define PP_GET "/keyword-map"
#define PP_EDIT "/add-pp-keyword"
#define CONTEXT_GET "/context-phrases"
#define CONTEXT_EDIT "/add-context-phrase"
#define UNIFIED_GET "/unified-server-settings"
#define SERVER_INFO "/server-info"
#define FLUSH_SERVER_CACHE "/flush-cache"
#endif // URLS_H