You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
1.8 KiB
94 lines
1.8 KiB
|
|
/*
|
|
* File name: kactivitytracker.cpp
|
|
* Summary: Utility object to track user activity
|
|
* License: LGPL - See file COPYING.LIB for details.
|
|
* Author: Stefan Hundhammer <sh@suse.de>
|
|
*
|
|
* Updated: 2003-01-07
|
|
*/
|
|
|
|
|
|
#include <kapp.h>
|
|
#include <kdebug.h>
|
|
#include <tdeconfig.h>
|
|
#include "kactivitytracker.h"
|
|
|
|
|
|
KActivityTracker::KActivityTracker( TQObject * parent,
|
|
const TQString & id,
|
|
long initialThreshold )
|
|
: TQObject( parent )
|
|
{
|
|
_id = id;
|
|
|
|
TDEConfig * config = kapp->config();
|
|
config->setGroup( _id );
|
|
_sum = config->readNumEntry( "activityPoints", 0 );
|
|
_lastSignal = config->readNumEntry( "lastSignal" , 0 );
|
|
_threshold = config->readNumEntry( "threshold", initialThreshold );
|
|
}
|
|
|
|
|
|
KActivityTracker::~KActivityTracker()
|
|
{
|
|
// NOP
|
|
}
|
|
|
|
|
|
void
|
|
KActivityTracker::setThreshold( long threshold )
|
|
{
|
|
_threshold = threshold;
|
|
|
|
TDEConfig * config = kapp->config();
|
|
config->setGroup( _id );
|
|
config->writeEntry( "threshold", _threshold );
|
|
|
|
checkThreshold();
|
|
}
|
|
|
|
|
|
void
|
|
KActivityTracker::trackActivity( int points )
|
|
{
|
|
_sum += points;
|
|
|
|
if ( _sum < 0 ) // handle long int overflow
|
|
_sum = 0;
|
|
|
|
#if 0
|
|
kdDebug() << "Adding " << points << " activity points."
|
|
<< " Total: " << _sum << " threshold: " << _threshold
|
|
<< endl;
|
|
#endif
|
|
|
|
TDEConfig * config = kapp->config();
|
|
config->setGroup( _id );
|
|
config->writeEntry( "activityPoints", _sum );
|
|
|
|
checkThreshold();
|
|
}
|
|
|
|
|
|
void
|
|
KActivityTracker::checkThreshold()
|
|
{
|
|
if ( _sum > _threshold && _lastSignal < _threshold )
|
|
{
|
|
// kdDebug() << "Activity threshold reached for " << _id << endl;
|
|
|
|
_lastSignal = _sum;
|
|
TDEConfig * config = kapp->config();
|
|
config->setGroup( _id );
|
|
config->writeEntry( "lastSignal", _lastSignal );
|
|
|
|
emit thresholdReached();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// EOF
|