mirror of
https://github.com/FAUSheppy/speech-server-client-qt
synced 2025-12-06 00:41:35 +01:00
implement configuration window
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "mainwindow.h"
|
||||
#include "notificationwidget.h"
|
||||
#include "settings.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QFileDialog>
|
||||
@@ -11,26 +12,33 @@
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QAction>
|
||||
#include <QProgressBar>
|
||||
#include <QProcess>
|
||||
#include <QSettings>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <settingkeys.h>
|
||||
|
||||
#define FILENAME_COL 0
|
||||
#define TRACKING_ID_COL 1
|
||||
#define PG_BAR_COL 2
|
||||
#define OPEN_DIR_COL 3
|
||||
#define TRANSCRIPT_STATUS_COL 4
|
||||
#define NUM_OF_COLS 5
|
||||
|
||||
#define STATUS_REQUEST_URL "http://localhost:5000/dumpstate"
|
||||
#define SUBMIT_URL "http://localhost:5000/submit-async"
|
||||
#define REQUEST_TRANSCRIPT_URL "http://localhost:5000/transcript"
|
||||
#define TRANSCRIPT_TARGET_DIR "."
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::MainWindow){
|
||||
|
||||
/* setup ui */
|
||||
ui->setupUi(this);
|
||||
|
||||
/* ensure all initial settings are set */
|
||||
handleInitialSettings();
|
||||
|
||||
setAuthHeader("user", "pass");
|
||||
networkManager = new QNetworkAccessManager(this);
|
||||
@@ -47,7 +55,7 @@ MainWindow::MainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::MainWind
|
||||
tw->horizontalHeader()->setVisible(false);
|
||||
tw->setRowCount(0);
|
||||
/* FILE | trackingId | STATUS | open dir | download completed? true/false | */
|
||||
tw->setColumnCount(5);
|
||||
tw->setColumnCount(NUM_OF_COLS);
|
||||
tw->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
tw->setColumnHidden(TRANSCRIPT_STATUS_COL, true);
|
||||
|
||||
@@ -63,6 +71,46 @@ MainWindow::MainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::MainWind
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(queryStatusAll()));
|
||||
timer->start(1000);
|
||||
|
||||
/* add handler for menu configuration */
|
||||
ui->menuKonfiguration->addAction("Standards", this, SLOT(openConfigurationWindow()) );
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::openConfigurationWindow(){
|
||||
Settings *settingsWindow = new Settings();
|
||||
settingsWindow->show();
|
||||
}
|
||||
|
||||
void MainWindow::handleInitialSettings(){
|
||||
QSettings mySettings;
|
||||
if(!mySettings.contains(SETTING_HOST)){
|
||||
mySettings.setValue(SETTING_HOST, "localhost");
|
||||
}
|
||||
if(!mySettings.contains(SETTING_PORT)){
|
||||
mySettings.setValue(SETTING_PORT, "5000");
|
||||
}
|
||||
if(!mySettings.contains(SETTING_PROTO)){
|
||||
mySettings.setValue(SETTING_PROTO, "https://");
|
||||
}
|
||||
if(!mySettings.contains(SETTING_LOC_STATE)){
|
||||
mySettings.setValue(SETTING_LOC_STATE, "/dumpstate");
|
||||
}
|
||||
if(!mySettings.contains(SETTING_LOC_SUBMIT)){
|
||||
mySettings.setValue(SETTING_LOC_SUBMIT, "/submit-async");
|
||||
}
|
||||
if(!mySettings.contains(SETTING_LOC_TRANSCRIPT)){
|
||||
mySettings.setValue(SETTING_LOC_TRANSCRIPT, "/transcript");
|
||||
}
|
||||
if(!mySettings.contains(SETTING_SAVE_DIR)){
|
||||
mySettings.setValue(SETTING_SAVE_DIR, ".");
|
||||
}
|
||||
if(!mySettings.contains(SETTING_USER)){
|
||||
mySettings.setValue(SETTING_USER, "");
|
||||
}
|
||||
if(!mySettings.contains(SETTING_PASS)){
|
||||
mySettings.setValue(SETTING_PASS, "");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::importFile(){
|
||||
|
||||
@@ -23,10 +23,12 @@ private slots:
|
||||
void requestFinished(QNetworkReply*);
|
||||
void queryStatusAll();
|
||||
void openContainingDir();
|
||||
void openConfigurationWindow();
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QTableWidget *tw;
|
||||
QPushButton *button;
|
||||
QAction *standardsMenu;
|
||||
QByteArray authHeaderData;
|
||||
QNetworkAccessManager *networkManager;
|
||||
void submitFile(QString filename);
|
||||
@@ -36,6 +38,7 @@ private:
|
||||
void showNotification(QString str);
|
||||
void queryTransscript(QString trackingId);
|
||||
void saveTranscript(QNetworkReply *reply);
|
||||
void handleInitialSettings();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@@ -40,8 +40,6 @@
|
||||
<property name="title">
|
||||
<string>&Konfiguration</string>
|
||||
</property>
|
||||
<addaction name="actionServer"/>
|
||||
<addaction name="actionStandards"/>
|
||||
</widget>
|
||||
<addaction name="menuKonfiguration"/>
|
||||
</widget>
|
||||
@@ -55,12 +53,12 @@
|
||||
</widget>
|
||||
<action name="actionServer">
|
||||
<property name="text">
|
||||
<string>Server</string>
|
||||
<string>&Server</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionStandards">
|
||||
<property name="text">
|
||||
<string>Standards</string>
|
||||
<string>Sta&ndards</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
||||
14
settingkeys.h
Normal file
14
settingkeys.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef SETTINGKEYS_H
|
||||
#define SETTINGKEYS_H
|
||||
|
||||
#define SETTING_HOST "host"
|
||||
#define SETTING_PORT "port"
|
||||
#define SETTING_PROTO "proto"
|
||||
#define SETTING_LOC_STATE "loc-state"
|
||||
#define SETTING_LOC_SUBMIT "loc-submit"
|
||||
#define SETTING_LOC_TRANSCRIPT "loc-transcript"
|
||||
#define SETTING_SAVE_DIR "save-dir"
|
||||
#define SETTING_USER "user"
|
||||
#define SETTING_PASS "pass"
|
||||
|
||||
#endif // SETTINGKEYS_H
|
||||
92
settings.cpp
Normal file
92
settings.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "settings.h"
|
||||
#include "ui_settings.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <settingkeys.h>
|
||||
|
||||
Settings::Settings(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::settings)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
configLineEditMap = new QHash<QString, QLineEdit*>();
|
||||
QSettings mySettings;
|
||||
|
||||
/* config options */
|
||||
QStringList *configOptions = new QStringList();
|
||||
configOptions->append("Host");
|
||||
configOptions->append("Port");
|
||||
configOptions->append("Protokoll");
|
||||
configOptions->append("Transcript Ordner");
|
||||
configOptions->append("Username");
|
||||
configOptions->append("Passwort");
|
||||
|
||||
/* config option keys */
|
||||
QStringList *configOptionsKeys = new QStringList();
|
||||
configOptionsKeys->append(SETTING_HOST);
|
||||
configOptionsKeys->append(SETTING_PORT);
|
||||
configOptionsKeys->append(SETTING_PROTO);
|
||||
configOptionsKeys->append(SETTING_SAVE_DIR);
|
||||
configOptionsKeys->append(SETTING_USER);
|
||||
configOptionsKeys->append(SETTING_PASS);
|
||||
|
||||
/* config options layout */
|
||||
auto cw = this->findChild<QWidget*>("centralwidget");
|
||||
QGridLayout *layout = static_cast<QGridLayout*>(cw->layout());
|
||||
|
||||
for(int i = 0; i < configOptions->length(); i++){
|
||||
|
||||
/* create widgets */
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setText(configOptions->at(i));
|
||||
QLineEdit *edit = new QLineEdit();
|
||||
edit->setText(mySettings.value(configOptionsKeys->at(i)).toString());
|
||||
|
||||
/* add widgets to layout */
|
||||
layout->addWidget(label, i, 0);
|
||||
layout->addWidget(edit, i, 1);
|
||||
|
||||
/* set stretch factors */
|
||||
layout->setColumnStretch(0, 1);
|
||||
layout->setColumnStretch(1, 1);
|
||||
|
||||
/* remeber options for laters save */
|
||||
configLineEditMap->insert(configOptionsKeys->at(i), edit);
|
||||
}
|
||||
|
||||
/* buttons */
|
||||
auto ok = new QPushButton("Ok");
|
||||
auto cancle = new QPushButton("Cancle");
|
||||
|
||||
layout->addWidget(ok, configOptions->length(), 0);
|
||||
layout->addWidget(cancle, configOptions->length(), 1);
|
||||
|
||||
connect(ok, SIGNAL(released()), this, SLOT(okClose()));
|
||||
connect(cancle, SIGNAL(released()), this, SLOT(cancleClose()));
|
||||
}
|
||||
|
||||
void Settings::cancleClose(){
|
||||
if(false){
|
||||
// TODO warning
|
||||
}
|
||||
this->close();
|
||||
}
|
||||
|
||||
void Settings::okClose(){
|
||||
QSettings mySettings;
|
||||
for(auto key : configLineEditMap->keys()){
|
||||
QString input = configLineEditMap->take(key)->text();
|
||||
if(input.compare("") != 0){
|
||||
mySettings.setValue(key, input);
|
||||
}
|
||||
}
|
||||
this->close();
|
||||
}
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
27
settings.h
Normal file
27
settings.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QLineEdit>
|
||||
|
||||
namespace Ui {
|
||||
class settings;
|
||||
}
|
||||
|
||||
class Settings : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Settings(QWidget *parent = nullptr);
|
||||
~Settings();
|
||||
|
||||
private slots:
|
||||
void okClose();
|
||||
void cancleClose();
|
||||
private:
|
||||
Ui::settings *ui;
|
||||
QHash<QString, QLineEdit*> *configLineEditMap;
|
||||
};
|
||||
|
||||
#endif // SETTINGS_H
|
||||
23
settings.ui
Normal file
23
settings.ui
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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>
|
||||
10
untitled.pro
10
untitled.pro
@@ -27,14 +27,18 @@ CONFIG += c++11
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
notificationwidget.cpp
|
||||
notificationwidget.cpp \
|
||||
settings.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
notificationwidget.h
|
||||
notificationwidget.h \
|
||||
settings.h \
|
||||
settingkeys.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
mainwindow.ui \
|
||||
settings.ui
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.8.2, 2020-07-16T16:18:43. -->
|
||||
<!-- Written by QtCreator 4.8.2, 2020-08-12T17:50:54. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
@@ -54,7 +54,10 @@
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||
<valuemap type="QVariantMap"/>
|
||||
<valuemap type="QVariantMap">
|
||||
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey"/>
|
||||
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||
@@ -290,19 +293,20 @@
|
||||
</valuelist>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Executable</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">untitled</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/ik15ydit/qt-projects/untitled/untitled.pro</value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">untitled.pro</value>
|
||||
<value type="QString" key="RunConfiguration.Arguments"></value>
|
||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/ik15ydit/qt-projects/build-untitled-Desktop-Debug</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
</valuemap>
|
||||
|
||||
Reference in New Issue
Block a user