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
|
||||
@@ -7,11 +7,14 @@
|
||||
#include <QWidget>
|
||||
#include <QtUiTools>
|
||||
|
||||
#include "multivalueinputdialog.h"
|
||||
#include "urls.h"
|
||||
|
||||
ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(parent) {
|
||||
|
||||
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);
|
||||
sc->getUnifiedServerConfig();
|
||||
|
||||
@@ -62,6 +65,9 @@ ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(p
|
||||
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();
|
||||
@@ -72,6 +78,44 @@ ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(p
|
||||
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()
|
||||
{
|
||||
QUiLoader loader;
|
||||
@@ -91,6 +135,14 @@ void ServerConfig::finishedRequest(QNetworkReply *reply){
|
||||
return;
|
||||
}
|
||||
|
||||
QString addPP = sc->buildURLFromLocation(PP_EDIT);
|
||||
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();
|
||||
|
||||
@@ -98,6 +150,9 @@ void ServerConfig::finishedRequest(QNetworkReply *reply){
|
||||
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);
|
||||
@@ -112,8 +167,25 @@ void ServerConfig::finishedRequest(QNetworkReply *reply){
|
||||
|
||||
contextTable->setCellWidget(i, 1, deleteCell);
|
||||
}
|
||||
this->repaint();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
ServerConfig::~ServerConfig()
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef SERVERCONFIG_H
|
||||
#define SERVERCONFIG_H
|
||||
|
||||
#include "serverconnection.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QMainWindow>
|
||||
#include <QNetworkReply>
|
||||
@@ -19,12 +21,15 @@ public:
|
||||
virtual ~ServerConfig();
|
||||
private slots:
|
||||
void finishedRequest(QNetworkReply*);
|
||||
void addNewPP();
|
||||
void addNewContext();
|
||||
private:
|
||||
QGridLayout* mainLayout;
|
||||
QSettings* mySettings;
|
||||
QWidget *loatListItemUiForm();
|
||||
QTableWidget* ppTable;
|
||||
QTableWidget* contextTable;
|
||||
ServerConnection* sc;
|
||||
};
|
||||
|
||||
#endif // SERVERCONFIG_H
|
||||
|
||||
@@ -22,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();
|
||||
@@ -90,18 +94,39 @@ QNetworkAccessManager *ServerConnection::getNetworkManager(){
|
||||
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)));
|
||||
QNetworkRequest request(serviceUrl);
|
||||
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)));
|
||||
QNetworkRequest request(serviceUrl);
|
||||
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(){
|
||||
|
||||
@@ -17,10 +17,11 @@ public:
|
||||
QNetworkAccessManager *getNetworkManager();
|
||||
void queryServerVersion();
|
||||
void getPostProcessorMap();
|
||||
void submitPostProcessorChange(QJsonDocument jsonDocument);
|
||||
void submitSpeechContextPhraseChange(QJsonDocument jsonDocument);
|
||||
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);
|
||||
public slots:
|
||||
void queryStatusAll();
|
||||
private slots:
|
||||
|
||||
@@ -38,7 +38,8 @@ SOURCES += \
|
||||
settings.cpp \
|
||||
about.cpp \
|
||||
serverconnection.cpp \
|
||||
serverconfig.cpp
|
||||
serverconfig.cpp \
|
||||
multivalueinputdialog.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
@@ -48,7 +49,8 @@ HEADERS += \
|
||||
about.h \
|
||||
serverconnection.h \
|
||||
serverconfig.h \
|
||||
urls.h
|
||||
urls.h \
|
||||
multivalueinputdialog.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui \
|
||||
|
||||
Reference in New Issue
Block a user