added return codes for IPrefresher refresh method.
error messages in gui.
This commit is contained in:
		@@ -11,23 +11,26 @@
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <Logger.h>
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,13 +3,9 @@
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#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();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user