/*
* polldrop.cpp -- Implementation of class KPollableDrop.
* Author:	Sirtaj Singh Kang
* Version:	$Id: polldrop.cpp,v 1.1 1999/07/22 18:17:05 tibirna Exp $
* Generated:	Sun Nov 30 22:41:49 EST 1997
*/

#include<qevent.h>

#include<kconfigbase.h>

#include"polldrop.h"
#include"pollcfg.h"
#include"dropdlg.h"

KPollableDrop::KPollableDrop()
	: KMailDrop()
{
	_timerId = 0;
	_timerRunning = false;
	_freq = 300;
}


bool KPollableDrop::startMonitor()
{
	if( !running() ) {
		recheck();

		_timerId = startTimer( _freq * 1000 );
		_timerRunning = true;

		return true;
	}

	return false;
}

bool KPollableDrop::stopMonitor()
{
	if( running() ) {
		killTimer( _timerId );
		_timerId = 0;
		_timerRunning = false;

		return true;
	}

	return false;
}


void KPollableDrop::timerEvent( QTimerEvent *ev )
{
	if( _timerRunning && (ev->timerId() == _timerId) ) {
		// this event is ours.
		recheck(); // should be reimplemented by children.
	}
	else {
		QObject::timerEvent( ev );
	}
}

bool KPollableDrop::readConfigGroup( const KConfigBase& cfg )
{
	KMailDrop::readConfigGroup( cfg );

	setFreq( cfg.readNumEntry( PollConfigKey, DefaultPoll ) );

	return true;
}

bool KPollableDrop::writeConfigGroup( KConfigBase& cfg ) const
{
	KMailDrop::writeConfigGroup( cfg );

	cfg.writeEntry( PollConfigKey, freq() );

	return true;
}

void KPollableDrop::addConfigPage( KDropCfgDialog *dlg )
{
	dlg->addConfigPage( new KPollCfg( this ) );

	KMailDrop::addConfigPage( dlg );
}

const char *KPollableDrop::PollConfigKey = "poll";
const int KPollableDrop::DefaultPoll = 300; // 5 minutes

