#include "locker.h"

#include <QTimer>
#include "appvals/AppGlobalValues.h"
#include "event/EventCenter.h"
#include "json/jsonobject.h"
Locker* Locker::locker = Q_NULLPTR;

Locker* Locker::Instance()
{
	if (locker == Q_NULLPTR)
	{
		locker = new Locker();
	}
	return locker;
}
Locker::Locker()
{
	counter = JsonObject::Instance()->lockerCount();
	screenTimer = new QTimer(this);
	connect(screenTimer, SIGNAL(timeout()), this, SLOT(coverScreen()));
}
Locker::~Locker() {}

void Locker::start()
{
	screenTimer->start(counter);
}
void Locker::coverScreen()
{

	if (AppGlobalValues::InProcessing().toBool()) {
		refreshTimer();
	}
	else
	{
		screenTimer->stop();
		EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr);
	}
}
void Locker::setTimer(int interval)
{
	this->counter = interval;
	screenTimer->stop();
	screenTimer->start(this->counter);

}
void Locker::refreshTimer()
{
	screenTimer->stop();
	screenTimer->start(counter);
}
