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.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * File name: kactivitytracker.h
  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. #ifndef KActivityTracker_h
  10. #define KActivityTracker_h
  11. #ifdef HAVE_CONFIG_H
  12. #include <config.h>
  13. #endif
  14. #include <tqobject.h>
  15. /**
  16. * Helper class to track user activity of any kind: When the user uses an
  17. * application's actions (menu items etc.), those actions notify this object of
  18. * that fact. Each action has an amount of "activity points" assigned
  19. * (i.e. what this action is "worth"). Those points are summed up here, and
  20. * when a certain number of points is reached, a signal is triggered. This
  21. * signal can be used for example to ask the user if he wouldn't like to rate
  22. * this program - or register it if this is a shareware program.
  23. *
  24. * @short User activity tracker
  25. **/
  26. class KActivityTracker: public TQObject
  27. {
  28. Q_OBJECT
  29. public:
  30. /**
  31. * Constructor. The ID is a name for the TDEConfig object to look in for
  32. * accumulated activity points so far. 'initialThreshold' is only used if
  33. * the application's @ref TDEConfig object doesn't contain a corresponding
  34. * entry yet.
  35. **/
  36. KActivityTracker( TQObject * parent,
  37. const TQString & id,
  38. long initialThreshold );
  39. /**
  40. * Destructor.
  41. **/
  42. virtual ~KActivityTracker();
  43. /**
  44. * Returns the number of activity points accumulated so far.
  45. **/
  46. long sum() const { return _sum; }
  47. /**
  48. * Sets the activity threshold, i.e. when a signal will be sent.
  49. **/
  50. void setThreshold( long threshold );
  51. /**
  52. * Returns the current threshold.
  53. **/
  54. long threshold() const { return _threshold; }
  55. /**
  56. * Check the sum of activity points accumulated so far against the current
  57. * threshold and emit a signal if appropriate.
  58. **/
  59. void checkThreshold();
  60. public slots:
  61. /**
  62. * Track an activity, i.e. add the specified amount of activity points to
  63. * the accumulated sum.
  64. **/
  65. void trackActivity( int points );
  66. /**
  67. * Set the threshold to its double value.
  68. **/
  69. void doubleThreshold() { setThreshold( 2 * threshold() ); }
  70. signals:
  71. /**
  72. * Emitted when the activity threshold is reached.
  73. *
  74. * You might want to set the threshold to a new value when this signal is
  75. * emitted. You can simply connect it to @ref doubleThreshold().
  76. **/
  77. void thresholdReached( void );
  78. protected:
  79. long _sum;
  80. long _threshold;
  81. long _lastSignal;
  82. TQString _id;
  83. };
  84. #endif // KActivityTracker_h
  85. // EOF