added return codes for IPrefresher refresh method.
error messages in gui.
This commit is contained in:
parent
0eea7095e0
commit
3b32f60190
@ -20,7 +20,7 @@ option(BUILD_DOC "Build documentation" ON) # additional dependency for Doxygen
|
|||||||
option(PACKAGING "Allow Packaging to <exe>, <deb> or <rpm>" ON) # additional dependencies for RPMbuild,dpkg or NSIS
|
option(PACKAGING "Allow Packaging to <exe>, <deb> or <rpm>" ON) # additional dependencies for RPMbuild,dpkg or NSIS
|
||||||
option(TESTS "Build Tests" ON) # additional dependencies for GTEST - to build tests
|
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" ON) # additional dependencies to QT libraries needed
|
||||||
set(WinBuild true)
|
set(WinBuild false)
|
||||||
|
|
||||||
# helper variables
|
# helper variables
|
||||||
SET(CMAKE_CXX_STANDARD 17)
|
SET(CMAKE_CXX_STANDARD 17)
|
||||||
|
@ -9,12 +9,19 @@
|
|||||||
|
|
||||||
#pragma once
|
#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 {
|
class IPRefresher {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* refresh ip address on Dynu server
|
* refresh ip address on Dynu server
|
||||||
*/
|
*/
|
||||||
void checkIPAdress(bool force);
|
bool checkIPAdress(bool force);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor
|
* default constructor
|
||||||
|
@ -11,23 +11,26 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <Logger.h>
|
#include <Logger.h>
|
||||||
|
|
||||||
void IPRefresher::checkIPAdress(bool force) {
|
bool IPRefresher::checkIPAdress(bool force) {
|
||||||
FileLogger logger;
|
FileLogger logger;
|
||||||
|
testspace::testi5();
|
||||||
IPAPI ipapi;
|
IPAPI ipapi;
|
||||||
std::string ip = ipapi.getGlobalIp();
|
std::string ip = ipapi.getGlobalIp();
|
||||||
|
|
||||||
if (ip.empty()) {
|
if (ip.empty()) {
|
||||||
//no internet connection (or other error)
|
//no internet connection (or other error)
|
||||||
Logger::warning("no internet connection");
|
Logger::warning("no internet connection");
|
||||||
|
return IPRefresher_Status_Code::ERROR_NO_INTERNET;
|
||||||
} else if (!IpHelper::isIpValid(ip)) {
|
} else if (!IpHelper::isIpValid(ip)) {
|
||||||
// error when ip doesn't contain a :
|
// error when ip doesn't contain a :
|
||||||
Logger::warning("an error occured when getting the global ip");
|
Logger::warning("an error occured when getting the global ip");
|
||||||
|
return IPRefresher_Status_Code::ERROR;
|
||||||
} else {
|
} else {
|
||||||
std::string oldip = logger.readip();
|
std::string oldip = logger.readip();
|
||||||
|
|
||||||
if (oldip == ip && !force) {
|
if (oldip == ip && !force) {
|
||||||
Logger::message("no change -- ip: " + ip);
|
Logger::message("no change -- ip: " + ip);
|
||||||
|
return IPRefresher_Status_Code::NOREFRESH;
|
||||||
} else {
|
} else {
|
||||||
Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
|
Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
|
||||||
|
|
||||||
@ -43,9 +46,11 @@ void IPRefresher::checkIPAdress(bool force) {
|
|||||||
} else if (!result) {
|
} else if (!result) {
|
||||||
//error
|
//error
|
||||||
Logger::error("failed to write ip to dynu api!");
|
Logger::error("failed to write ip to dynu api!");
|
||||||
|
return IPRefresher_Status_Code::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.safeip(ip);
|
logger.safeip(ip);
|
||||||
|
return result ? IPRefresher_Status_Code::SUCCESS : IPRefresher_Status_Code::ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,23 @@ void MainWindow::refreshIPBtn() {
|
|||||||
new std::thread([this]() {
|
new std::thread([this]() {
|
||||||
IPRefresher ipr;
|
IPRefresher ipr;
|
||||||
if (Config::readConfig()) {
|
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 {
|
} else {
|
||||||
std::cout << "incorrect credentials!" << std::endl;
|
std::cout << "incorrect credentials!" << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <iostream>
|
|
||||||
#include "gui/MainWindow.h"
|
#include "gui/MainWindow.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
std::cout << "gui here!" << std::endl;
|
|
||||||
QCoreApplication::addLibraryPath(".");
|
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
|
Loading…
Reference in New Issue
Block a user