diff --git a/serverconfig.cpp b/serverconfig.cpp index bd16f08..8ca5346 100644 --- a/serverconfig.cpp +++ b/serverconfig.cpp @@ -99,6 +99,16 @@ void ServerConfig::addNewPP(){ } } +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(); @@ -112,6 +122,7 @@ void ServerConfig::addNewContext() auto lineEdit = static_cast(wl->at(0)); if(!lineEdit->text().isEmpty()){ sc->submitSpeechContextPhraseChange(lineEdit->text()); + askFlushServerCache(); } } } @@ -137,10 +148,26 @@ void ServerConfig::finishedRequest(QNetworkReply *reply){ 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){ + qDebug("WTF"); + 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 += "
"; + } + msgBox.setInformativeText(display); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); }else{ /* this is the unified server config query */ /* get filename and tracking id from replay */ diff --git a/serverconfig.h b/serverconfig.h index c35e0d9..6c291f5 100644 --- a/serverconfig.h +++ b/serverconfig.h @@ -30,6 +30,7 @@ private: QTableWidget* ppTable; QTableWidget* contextTable; ServerConnection* sc; + void askFlushServerCache(); }; #endif // SERVERCONFIG_H diff --git a/serverconnection.cpp b/serverconnection.cpp index ac020f7..3d83717 100644 --- a/serverconnection.cpp +++ b/serverconnection.cpp @@ -149,3 +149,10 @@ void ServerConnection::getUnifiedServerConfig(){ 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); +} diff --git a/serverconnection.h b/serverconnection.h index 63ecbdc..9ceb521 100644 --- a/serverconnection.h +++ b/serverconnection.h @@ -22,6 +22,7 @@ public: void getSpeechContextPhrases(); void getUnifiedServerConfig(); QString buildURLFromLocation(const char *location); + void flushCache(); public slots: void queryStatusAll(); private slots: diff --git a/urls.h b/urls.h index cff1ca2..055efa1 100644 --- a/urls.h +++ b/urls.h @@ -10,4 +10,6 @@ #define UNIFIED_GET "/unified-server-settings" #define SERVER_INFO "/server-info" +#define FLUSH_SERVER_CACHE "/flush-cache" + #endif // URLS_H