mirror of
https://github.com/FAUSheppy/speech-server-client-qt
synced 2025-12-06 00:41:35 +01:00
implement adding new serverconfig
This commit is contained in:
24
multivalueinputdialog.cpp
Normal file
24
multivalueinputdialog.cpp
Normal 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
13
multivalueinputdialog.h
Normal 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
|
||||||
110
serverconfig.cpp
110
serverconfig.cpp
@@ -7,11 +7,14 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QtUiTools>
|
#include <QtUiTools>
|
||||||
|
|
||||||
|
#include "multivalueinputdialog.h"
|
||||||
|
#include "urls.h"
|
||||||
|
|
||||||
ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(parent) {
|
ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(parent) {
|
||||||
|
|
||||||
mySettings = settings;
|
mySettings = settings;
|
||||||
|
|
||||||
ServerConnection *sc = new ServerConnection(this, mySettings);
|
sc = new ServerConnection(this, mySettings);
|
||||||
connect(sc->getNetworkManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedRequest(QNetworkReply*)), Qt::UniqueConnection);
|
connect(sc->getNetworkManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedRequest(QNetworkReply*)), Qt::UniqueConnection);
|
||||||
sc->getUnifiedServerConfig();
|
sc->getUnifiedServerConfig();
|
||||||
|
|
||||||
@@ -62,6 +65,9 @@ ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(p
|
|||||||
innerLayoutContext->addWidget(addNewContext);
|
innerLayoutContext->addWidget(addNewContext);
|
||||||
context->setLayout(innerLayoutContext);
|
context->setLayout(innerLayoutContext);
|
||||||
|
|
||||||
|
/* connect buttons */
|
||||||
|
connect(addNew, SIGNAL (released()), this, SLOT (addNewPP()));
|
||||||
|
connect(addNewContext, SIGNAL (released()), this, SLOT (addNewContext()));
|
||||||
|
|
||||||
/* setup main window */
|
/* setup main window */
|
||||||
mainLayout = new QGridLayout();
|
mainLayout = new QGridLayout();
|
||||||
@@ -72,6 +78,44 @@ ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(p
|
|||||||
this->setCentralWidget(mainWidget);
|
this->setCentralWidget(mainWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(0));
|
||||||
|
|
||||||
|
if(!keyword->text().isEmpty() && !replace->text().isEmpty()){
|
||||||
|
sc->submitPostProcessorChange(keyword->text(), replace->text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QWidget* ServerConfig::loatListItemUiForm()
|
QWidget* ServerConfig::loatListItemUiForm()
|
||||||
{
|
{
|
||||||
QUiLoader loader;
|
QUiLoader loader;
|
||||||
@@ -91,29 +135,57 @@ void ServerConfig::finishedRequest(QNetworkReply *reply){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get filename and tracking id from replay */
|
QString addPP = sc->buildURLFromLocation(PP_EDIT);
|
||||||
QJsonObject json = QJsonDocument::fromJson(reply->readAll()).object();
|
QString addContext = sc->buildURLFromLocation(CONTEXT_EDIT);
|
||||||
|
if(QString::compare(reply->url().toString(), addPP) == 0){
|
||||||
|
sc->getUnifiedServerConfig();
|
||||||
|
}else if(QString::compare(reply->url().toString(), addContext) == 0){
|
||||||
|
sc->getUnifiedServerConfig();
|
||||||
|
}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 keywordMap = json["keyword-map"].toObject();
|
||||||
auto phrases = json["phrases"].toArray();
|
auto phrases = json["phrases"].toArray();
|
||||||
|
|
||||||
contextTable->clear();
|
contextTable->clear();
|
||||||
|
contextTable->setRowCount(0);
|
||||||
|
ppTable->clear();
|
||||||
|
ppTable->setRowCount(0);
|
||||||
|
|
||||||
for(int i = 0; i < phrases.size(); i++){
|
for(int i = 0; i < phrases.size(); i++){
|
||||||
contextTable->insertRow(i);
|
contextTable->insertRow(i);
|
||||||
contextTable->setItem(i, 0, new QTableWidgetItem(phrases.at(i).toString()));
|
contextTable->setItem(i, 0, new QTableWidgetItem(phrases.at(i).toString()));
|
||||||
auto *deleteButtonLayout = new QGridLayout();
|
auto *deleteButtonLayout = new QGridLayout();
|
||||||
auto *deleteCell = new QWidget();
|
auto *deleteCell = new QWidget();
|
||||||
auto *deleteButton = new QPushButton("Entfernen");
|
auto *deleteButton = new QPushButton("Entfernen");
|
||||||
deleteButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
deleteButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
deleteButtonLayout->addWidget(deleteButton);
|
deleteButtonLayout->addWidget(deleteButton);
|
||||||
deleteButtonLayout->setContentsMargins(0,0,0,0);
|
deleteButtonLayout->setContentsMargins(0,0,0,0);
|
||||||
deleteCell->setLayout(deleteButtonLayout);
|
deleteCell->setLayout(deleteButtonLayout);
|
||||||
|
|
||||||
contextTable->setCellWidget(i, 1, deleteCell);
|
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 QPushButton("Entfernen");
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
this->repaint();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerConfig::~ServerConfig()
|
ServerConfig::~ServerConfig()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef SERVERCONFIG_H
|
#ifndef SERVERCONFIG_H
|
||||||
#define SERVERCONFIG_H
|
#define SERVERCONFIG_H
|
||||||
|
|
||||||
|
#include "serverconnection.h"
|
||||||
|
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
@@ -19,12 +21,15 @@ public:
|
|||||||
virtual ~ServerConfig();
|
virtual ~ServerConfig();
|
||||||
private slots:
|
private slots:
|
||||||
void finishedRequest(QNetworkReply*);
|
void finishedRequest(QNetworkReply*);
|
||||||
|
void addNewPP();
|
||||||
|
void addNewContext();
|
||||||
private:
|
private:
|
||||||
QGridLayout* mainLayout;
|
QGridLayout* mainLayout;
|
||||||
QSettings* mySettings;
|
QSettings* mySettings;
|
||||||
QWidget *loatListItemUiForm();
|
QWidget *loatListItemUiForm();
|
||||||
QTableWidget* ppTable;
|
QTableWidget* ppTable;
|
||||||
QTableWidget* contextTable;
|
QTableWidget* contextTable;
|
||||||
|
ServerConnection* sc;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVERCONFIG_H
|
#endif // SERVERCONFIG_H
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ QString ServerConnection::buildURLFromLocation(QVariant location){
|
|||||||
return buildURLFromLocation(location.toString());
|
return buildURLFromLocation(location.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ServerConnection::buildURLFromLocation(const char *location){
|
||||||
|
return buildURLFromLocation(QString(location));
|
||||||
|
}
|
||||||
|
|
||||||
QString ServerConnection::buildURLFromLocation(QString location){
|
QString ServerConnection::buildURLFromLocation(QString location){
|
||||||
QString proto = mySettings->value(SETTING_PROTO).toString();
|
QString proto = mySettings->value(SETTING_PROTO).toString();
|
||||||
QString host = mySettings->value(SETTING_HOST).toString();
|
QString host = mySettings->value(SETTING_HOST).toString();
|
||||||
@@ -90,18 +94,39 @@ QNetworkAccessManager *ServerConnection::getNetworkManager(){
|
|||||||
return networkManager;
|
return networkManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConnection::submitPostProcessorChange(QJsonDocument jsonDocument){
|
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)));
|
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(PP_EDIT)));
|
||||||
QNetworkRequest request(serviceUrl);
|
QNetworkRequest request(serviceUrl);
|
||||||
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
|
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
|
||||||
networkManager->post(request, jsonDocument.toJson());
|
request.setHeader(QNetworkRequest::ContentTypeHeader, MIME_JSON);
|
||||||
|
networkManager->post(request, QJsonDocument(json).toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConnection::submitSpeechContextPhraseChange(QJsonDocument jsonDocument){
|
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)));
|
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(CONTEXT_EDIT)));
|
||||||
QNetworkRequest request(serviceUrl);
|
QNetworkRequest request(serviceUrl);
|
||||||
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
|
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
|
||||||
networkManager->post(request, jsonDocument.toJson());
|
request.setHeader(QNetworkRequest::ContentTypeHeader, MIME_JSON);
|
||||||
|
networkManager->post(request, QJsonDocument(json).toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConnection::getSpeechContextPhrases(){
|
void ServerConnection::getSpeechContextPhrases(){
|
||||||
|
|||||||
@@ -17,10 +17,11 @@ public:
|
|||||||
QNetworkAccessManager *getNetworkManager();
|
QNetworkAccessManager *getNetworkManager();
|
||||||
void queryServerVersion();
|
void queryServerVersion();
|
||||||
void getPostProcessorMap();
|
void getPostProcessorMap();
|
||||||
void submitPostProcessorChange(QJsonDocument jsonDocument);
|
void submitPostProcessorChange(QString keyword, QString repl, bool remove = false);
|
||||||
void submitSpeechContextPhraseChange(QJsonDocument jsonDocument);
|
void submitSpeechContextPhraseChange(QString phrase, bool remove = false);
|
||||||
void getSpeechContextPhrases();
|
void getSpeechContextPhrases();
|
||||||
void getUnifiedServerConfig();
|
void getUnifiedServerConfig();
|
||||||
|
QString buildURLFromLocation(const char *location);
|
||||||
public slots:
|
public slots:
|
||||||
void queryStatusAll();
|
void queryStatusAll();
|
||||||
private slots:
|
private slots:
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ SOURCES += \
|
|||||||
settings.cpp \
|
settings.cpp \
|
||||||
about.cpp \
|
about.cpp \
|
||||||
serverconnection.cpp \
|
serverconnection.cpp \
|
||||||
serverconfig.cpp
|
serverconfig.cpp \
|
||||||
|
multivalueinputdialog.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
@@ -48,7 +49,8 @@ HEADERS += \
|
|||||||
about.h \
|
about.h \
|
||||||
serverconnection.h \
|
serverconnection.h \
|
||||||
serverconfig.h \
|
serverconfig.h \
|
||||||
urls.h
|
urls.h \
|
||||||
|
multivalueinputdialog.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
mainwindow.ui \
|
mainwindow.ui \
|
||||||
|
|||||||
Reference in New Issue
Block a user