KDirStat – a graphical disk usage utility
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.

kactivitytracker.cpp 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * File name: kactivitytracker.cpp
  3. * Summary: Utility object to track user activity
  4. * License: LGPL - See file COPYING.LIB for details.
  5. * Author: Stefan Hundhammer <sh@suse.de>
  6. *
  7. * Updated: 2003-01-07
  8. */
  9. #include <kapp.h>
  10. #include <kdebug.h>
  11. #include <tdeconfig.h>
  12. #include "kactivitytracker.h"
  13. KActivityTracker::KActivityTracker( TQObject * parent,
  14. const TQString & id,
  15. long initialThreshold )
  16. : TQObject( parent )
  17. {
  18. _id = id;
  19. TDEConfig * config = kapp->config();
  20. config->setGroup( _id );
  21. _sum = config->readNumEntry( "activityPoints", 0 );
  22. _lastSignal = config->readNumEntry( "lastSignal" , 0 );
  23. _threshold = config->readNumEntry( "threshold", initialThreshold );
  24. }
  25. KActivityTracker::~KActivityTracker()
  26. {
  27. // NOP
  28. }
  29. void
  30. KActivityTracker::setThreshold( long threshold )
  31. {
  32. _threshold = threshold;
  33. TDEConfig * config = kapp->config();
  34. config->setGroup( _id );
  35. config->writeEntry( "threshold", _threshold );
  36. checkThreshold();
  37. }
  38. void
  39. KActivityTracker::trackActivity( int points )
  40. {
  41. _sum += points;
  42. if ( _sum < 0 ) // handle long int overflow
  43. _sum = 0;
  44. #if 0
  45. kdDebug() << "Adding " << points << " activity points."
  46. << " Total: " << _sum << " threshold: " << _threshold
  47. << endl;
  48. #endif
  49. TDEConfig * config = kapp->config();
  50. config->setGroup( _id );
  51. config->writeEntry( "activityPoints", _sum );
  52. checkThreshold();
  53. }
  54. void
  55. KActivityTracker::checkThreshold()
  56. {
  57. if ( _sum > _threshold && _lastSignal < _threshold )
  58. {
  59. // kdDebug() << "Activity threshold reached for " << _id << endl;
  60. _lastSignal = _sum;
  61. TDEConfig * config = kapp->config();
  62. config->setGroup( _id );
  63. config->writeEntry( "lastSignal", _lastSignal );
  64. emit thresholdReached();
  65. }
  66. }
  67. #include "kactivitytracker.moc"
  68. // EOF