diff --git a/CMakeLists.txt b/CMakeLists.txt index 733e054..dfe8361 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ 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 -set(WinBuild true) +set(WinBuild false) # helper variables SET(CMAKE_CXX_STANDARD 17) diff --git a/inc/IPRefresher.h b/inc/IPRefresher.h index 6bc713d..70d8e0e 100644 --- a/inc/IPRefresher.h +++ b/inc/IPRefresher.h @@ -9,12 +9,19 @@ #pragma once +namespace IPRefresher_Status_Code { + const int SUCCESS = 1; + const int ERROR = -1; + const int ERROR_NO_INTERNET = -2; + const int NOREFRESH = 0; +} + class IPRefresher { public: /** * refresh ip address on Dynu server */ - void checkIPAdress(bool force); + bool checkIPAdress(bool force); /** * default constructor @@ -27,4 +34,4 @@ public: * @param loop true->loopmode on */ explicit IPRefresher(bool loop); -}; +}; \ No newline at end of file diff --git a/src/IPRefresher.cpp b/src/IPRefresher.cpp index 3dbcf0f..7238a02 100644 --- a/src/IPRefresher.cpp +++ b/src/IPRefresher.cpp @@ -11,23 +11,26 @@ #include #include -void IPRefresher::checkIPAdress(bool force) { +bool IPRefresher::checkIPAdress(bool force) { FileLogger logger; - + testspace::testi5(); IPAPI ipapi; std::string ip = ipapi.getGlobalIp(); if (ip.empty()) { //no internet connection (or other error) Logger::warning("no internet connection"); + return IPRefresher_Status_Code::ERROR_NO_INTERNET; } else if (!IpHelper::isIpValid(ip)) { // error when ip doesn't contain a : Logger::warning("an error occured when getting the global ip"); + return IPRefresher_Status_Code::ERROR; } else { std::string oldip = logger.readip(); if (oldip == ip && !force) { Logger::message("no change -- ip: " + ip); + return IPRefresher_Status_Code::NOREFRESH; } else { Logger::message("ip changed! -- from :" + oldip + "to: " + ip); @@ -43,9 +46,11 @@ void IPRefresher::checkIPAdress(bool force) { } else if (!result) { //error Logger::error("failed to write ip to dynu api!"); + return IPRefresher_Status_Code::ERROR; } logger.safeip(ip); + return result ? IPRefresher_Status_Code::SUCCESS : IPRefresher_Status_Code::ERROR; } } } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 2c758d9..3471287 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -58,7 +58,23 @@ void MainWindow::refreshIPBtn() { new std::thread([this]() { IPRefresher ipr; if (Config::readConfig()) { - ipr.checkIPAdress(false); + int code = ipr.checkIPAdress(false); + switch (code) { + case IPRefresher_Status_Code::SUCCESS: + appendLogField("successfully refreshed IP!"); + break; + case IPRefresher_Status_Code::NOREFRESH: + appendLogField("IP is already correct."); + break; + case IPRefresher_Status_Code::ERROR_NO_INTERNET: + appendLogField("Error: No Internet connection"); + break; + case IPRefresher_Status_Code::ERROR: + appendLogField("An error occured while refreshing."); + break; + default: + appendLogField("An unknown error code occured"); + } } else { std::cout << "incorrect credentials!" << std::endl; } diff --git a/src/maingui.cpp b/src/maingui.cpp index ec9a7a0..c144b60 100644 --- a/src/maingui.cpp +++ b/src/maingui.cpp @@ -3,13 +3,9 @@ // #include -#include #include "gui/MainWindow.h" int main(int argc, char *argv[]) { - std::cout << "gui here!" << std::endl; - QCoreApplication::addLibraryPath("."); - QApplication a(argc, argv); MainWindow w; w.show();