#define QT_CLEAN_NAMESPACE // no qt 1.x compatability, INT32 conflicts with X
#include "screensaver-xss.h"

#include "util.h"

#include "mythcontext.h"

ScreenSaverXSSTimer::ScreenSaverXSSTimer() 
{
    resetTimer = new QTimer();
    connect(resetTimer, SIGNAL(timeout()), this, SLOT(resetSlot()));
}

ScreenSaverXSSTimer::~ScreenSaverXSSTimer() 
{
    if (resetTimer)
    {
        delete resetTimer;
    }
}

void ScreenSaverXSSTimer::resetXSS() 
{
    myth_system(QString("xscreensaver-command -deactivate >&- 2>&- &")); 
}

void ScreenSaverXSSTimer::resetSlot() 
{
    resetXSS();
}

ScreenSaverXSS::ScreenSaverXSS() 
{
    d = new ScreenSaverXSSTimer();
    d->timeoutInterval = 60000;
}

ScreenSaverXSS::~ScreenSaverXSS() 
{
    if (d)
    {
        delete d;
    }
}


void ScreenSaverXSS::Disable(void) 
{
    if (d->resetTimer->isActive())
    {
        d->resetTimer->stop();
    }
    d->resetTimer->start(d->timeoutInterval, FALSE);
}

void ScreenSaverXSS::Restore(void) 
{
    if (d->resetTimer->isActive())
    {
        d->resetTimer->stop();
    }
}

void ScreenSaverXSS::Reset(void) 
{
    d->resetXSS();
}
