/* 
 * File:   NetworkThread.cpp
 * Author: matthieu
 * 
 * Created on 6 février 2015, 11:40
 */

#include "NetworkThread.h"
#include "RecalboxSystem.h"
#include "guis/GuiMsgBox.h"


NetworkThread::NetworkThread(Window* window) : mWindow(window){
    
    // creer le thread
    mFirstRun = true;
    mRunning = true;
    mThreadHandle = new boost::thread(boost::bind(&NetworkThread::run, this));

}

NetworkThread::~NetworkThread() {
    	mThreadHandle->join();
}

void NetworkThread::run(){
    while(mRunning){
        if(mFirstRun){
            boost::this_thread::sleep(boost::posix_time::seconds(15));
            mFirstRun = false;
        }else {
            boost::this_thread::sleep(boost::posix_time::hours(1));
        }

        if(RecalboxSystem::getInstance()->canUpdate()){
            if(RecalboxSystem::getInstance()->canUpdate()){
                mWindow->displayMessage("AN UPDATE IS AVAILABLE FOR YOUR RECALBOX");
                mRunning = false;
            }
        }
    }
}


/* 
 * File:   NetworkThread.cpp
 * Author: matthieu
 * 
 * Created on 6 février 2015, 11:40
 */

#include "NetworkThread.h"
#include "RecalboxSystem.h"
#include "guis/GuiMsgBox.h"


NetworkThread::NetworkThread(Window* window) : mWindow(window){
    
    // creer le thread
    mFirstRun = true;
    mRunning = true;
    mThreadHandle = new boost::thread(boost::bind(&NetworkThread::run, this));

}

NetworkThread::~NetworkThread() {
    	mThreadHandle->join();
}

void NetworkThread::run(){
    while(mRunning){
        if(mFirstRun){
            boost::this_thread::sleep(boost::posix_time::seconds(15));
            mFirstRun = false;
        }else {
            boost::this_thread::sleep(boost::posix_time::hours(1));
        }

	if(RecalboxConf::getInstance()->get("updates.enabled") == "1") {
	  if(RecalboxSystem::getInstance()->canUpdate()){
	    mWindow->displayMessage("AN UPDATE IS AVAILABLE FOR YOUR RECALBOX");
	    mRunning = false;
	  }
	}
    }
}


Update : make the updates.enabled switch usefull
Update : make the updates.enabled switch usefull

Signed-off-by: Nicolas Adenis-Lamarre <dc6fdc1a9744a7ef1c7adc041d3cf105890663bc@gmail.com>
