diff --git a/CMakeLists.txt b/CMakeLists.txt index ff32a1f..6fb4c05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ SET(LIB_METHOD STATIC) #SHARED / STATIC option(BUILD_DOC "Build documentation" ON) # additional dependency for Doxygen option(PACKAGING "Allow Packaging to , or " ON) # additional dependencies for RPMbuild,dpkg or NSIS option(TESTS "Build Tests" ON) # additional dependencies for GTEST - to build tests -option(GUI "Build GUI elements" ON) # additional dependencies to QT libraries needed +option(GUI "Build GUI elements" OFF) # additional dependencies to QT libraries needed set(WinBuild false) # helper variables @@ -199,7 +199,7 @@ if (${GUI}) src/gui/MainWindow.h ${UI_GENERATED_HEADERS}) # LINK generated LIBS # - target_link_libraries(iprefresher-gui dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES} ${QT5_LIBRARIES}) + target_link_libraries(iprefresher-gui -lpthread dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES} ${QT5_LIBRARIES}) endif () # setting install targets diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 6c1afca..7294823 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1,20 +1,28 @@ -// -// Created by lukas on 09.05.20. -// - -#include +#include +#include #include "MainWindow.h" #include "ui_mainwindow.h" -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), ui(new Ui::MainWindow) { +#include "inc/Config.h" +#include "inc/Logger.h" +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); - ui->textLog-> -// ui->labelCurrentIP->setText("currently is nothing to do"); -// ui->labelConfig->setText("blabliblub"); -// ui->textfieldname->setText("hangover"); + // needs to be defined out of scope -- would be termintated after this constructor. +// myThread = std::thread([this](){ +// IPAPI ipapi; +// std::string ip = ipapi.getGlobalIp(); +// Logger::message("Current global IP: " + ip); +// std::string msg = "Your current global IP: "+ip; +// ui->labelCurrentIP->setText(msg.c_str()); +// }); + + + if (Config::validateConfig()) + ui->labelConfig->setText("Config is: OK"); + else + ui->labelConfig->setText("Config is: NOT OK"); connect(ui->buttonCheckConfig, SIGNAL(clicked()), this, SLOT(checkConfigBtn())); connect(ui->buttonRefreshIP, SIGNAL(clicked()), this, SLOT(refreshIPBtn())); @@ -28,11 +36,48 @@ MainWindow::~MainWindow() { } void MainWindow::checkConfigBtn() { - std::cout << "btn clicked!" << std::endl; + Logger::message("checking config!"); + appendLogField("checking config!"); - appendLogField("btn clicked! \n"); + if (Config::validateConfig()) { + Logger::message("Config file is OK"); + appendLogField("Config file is OK"); + ui->labelConfig->setText("Config is: OK"); + } else { + Logger::error("There are errors in config file!"); + appendLogField("There are errors in config file!"); + } + appendLogField(""); } void MainWindow::refreshIPBtn() { + Logger::message("start refreshing Dynu IP."); + appendLogField(""); + appendLogField("start refreshing Dynu IP."); +new std::thread([this](){ + IPRefresher ipr; + if (Config::readConfig()) { + ipr.checkIPAdress(false); + } else { + std::cout << "incorrect credentials!" << std::endl; + } + + Logger::message("Finished refreshing Dynu IP."); + appendLogField("Finished refreshing Dynu IP."); + delete this; +}); +// myThread = std::thread([this](){ +// IPRefresher ipr; +// if (Config::readConfig()) { +// ipr.checkIPAdress(false); +// } else { +// std::cout << "incorrect credentials!" << std::endl; +// } +// +// Logger::message("Finished refreshing Dynu IP."); +// appendLogField("Finished refreshing Dynu IP."); +// ui->textLog->appendPlainText("Finished refreshing Dynu IP."); +// }); + } \ No newline at end of file diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index c954b49..dbdc2b8 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -4,7 +4,7 @@ #pragma once - +#include #include namespace Ui { @@ -15,11 +15,12 @@ class MainWindow : public QMainWindow{ Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; + std::thread myThread; private slots: // void startdownloadBtn(); void checkConfigBtn(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 2857309..bd9e356 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -32,7 +32,7 @@ 40 60 - 161 + 301 17 @@ -42,7 +42,7 @@ - true + false