diff --git a/mainwindow.cpp b/mainwindow.cpp index 1a3298b..af99520 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" #include "notificationwidget.h" +#include "settings.h" #include "ui_mainwindow.h" #include #include @@ -11,26 +12,33 @@ #include #include #include +#include #include #include +#include #include +#include -#define FILENAME_COL 0 -#define TRACKING_ID_COL 1 -#define PG_BAR_COL 2 -#define OPEN_DIR_COL 3 +#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 "." -#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,14 +71,54 @@ 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(){ QString filename = QFileDialog::getOpenFileName( - this, - "Open Document", - QDir::currentPath(), - "All files (*.*) ;; Document files (*.doc *.rtf);; PNG files (*.png)"); + this, + "Open Document", + QDir::currentPath(), + "All files (*.*) ;; Document files (*.doc *.rtf);; PNG files (*.png)"); if(filename.isNull()){ return; @@ -80,9 +128,9 @@ void MainWindow::importFile(){ } void MainWindow::showNotification(QString str){ - #ifdef Q_OS_LINUX +#ifdef Q_OS_LINUX return; - #endif +#endif auto popUp = new NotificationWidget(this); popUp->setPopupText(str); popUp->setGeometry(0, 0, popUp->width(), popUp->height()); @@ -127,7 +175,7 @@ void MainWindow::submitFile(QString filename){ /* make request */ connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, - SLOT(requestFinished(QNetworkReply*)), Qt::UniqueConnection); + SLOT(requestFinished(QNetworkReply*)), Qt::UniqueConnection); networkManager->post(request, QJsonDocument(json).toJson()); qDebug("Request submitted"); @@ -145,15 +193,15 @@ void MainWindow::openContainingDir(){ qDebug("Called"); auto filePath = TRANSCRIPT_TARGET_DIR; QStringList args; - #ifdef Q_OS_LINUX +#ifdef Q_OS_LINUX args << QDir::toNativeSeparators(filePath); QProcess::startDetached("/usr/bin/thunar", args); - #endif - #ifdef Q_OS_WIN +#endif +#ifdef Q_OS_WIN QStringList args; args << "/select," << QDir::toNativeSeparators(filePath); QProcess::startDetached("explorer", args); - #endif +#endif } void MainWindow::updateList(QNetworkReply* reply){ diff --git a/mainwindow.h b/mainwindow.h index 2820f97..83f31e6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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 diff --git a/mainwindow.ui b/mainwindow.ui index cc90630..3fe6b9a 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -40,8 +40,6 @@ &Konfiguration - - @@ -55,12 +53,12 @@ - Server + &Server - Standards + Sta&ndards diff --git a/settingkeys.h b/settingkeys.h new file mode 100644 index 0000000..cedb2cd --- /dev/null +++ b/settingkeys.h @@ -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 diff --git a/settings.cpp b/settings.cpp new file mode 100644 index 0000000..b4a4ccb --- /dev/null +++ b/settings.cpp @@ -0,0 +1,92 @@ +#include "settings.h" +#include "ui_settings.h" + +#include +#include +#include +#include +#include + +Settings::Settings(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::settings) +{ + ui->setupUi(this); + configLineEditMap = new QHash(); + 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("centralwidget"); + QGridLayout *layout = static_cast(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; +} diff --git a/settings.h b/settings.h new file mode 100644 index 0000000..5da0f93 --- /dev/null +++ b/settings.h @@ -0,0 +1,27 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include + +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 *configLineEditMap; +}; + +#endif // SETTINGS_H diff --git a/settings.ui b/settings.ui new file mode 100644 index 0000000..d37edf0 --- /dev/null +++ b/settings.ui @@ -0,0 +1,23 @@ + + + settings + + + + 0 + 0 + 281 + 245 + + + + MainWindow + + + + + + + + + diff --git a/untitled.pro b/untitled.pro index 9e65277..5b9cc8b 100644 --- a/untitled.pro +++ b/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 diff --git a/untitled.pro.user b/untitled.pro.user index 1c73466..410714b 100644 --- a/untitled.pro.user +++ b/untitled.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -54,7 +54,10 @@ ProjectExplorer.Project.PluginSettings - + + + true + ProjectExplorer.Project.Target.0 @@ -290,19 +293,20 @@ 2 - - Custom Executable + untitled - ProjectExplorer.CustomExecutableRunConfiguration + Qt4ProjectManager.Qt4RunConfiguration:/home/ik15ydit/qt-projects/untitled/untitled.pro + untitled.pro 3768 false true + true false false true - + /home/ik15ydit/qt-projects/build-untitled-Desktop-Debug 1