-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverconfig.cpp
238 lines (192 loc) · 8.19 KB
/
serverconfig.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#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()
{
}