summaryrefslogtreecommitdiffstats
path: root/karm/idletimedetector.h
blob: b5645431ec392573fa1e967de6f9fa806b649fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef KARM_IDLE_TIME_DETECTOR_H
#define KARM_IDLE_TIME_DETECTOR_H

#include <tqobject.h>
#include "config.h"     // HAVE_LIBXSS
#include <tqdatetime.h>
#include <kdebug.h>

class TQTimer;

#ifdef HAVE_LIBXSS
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/extensions/scrnsaver.h>
 #include <fixx11h.h>
#endif // HAVE_LIBXSS

// Seconds per minutes - useful for speeding debugging up!
const int secsPerMinute = 60;

// Minutes between each idle overrun test.
const int testInterval= secsPerMinute * 1000;

/**
 * Keep track of how long the computer has been idle.
 */

class IdleTimeDetector :public TQObject
{
TQ_OBJECT
  

public:
  /**
     Initializes and idle test timer
     @param maxIdle minutes before the idle timer will go off.
  **/
  IdleTimeDetector(int maxIdle);

  /**
     Returns true if it is possible to do idle detection.
     Idle detection relys on a feature in the X server, which might not
     always be present.
  **/
  bool isIdleDetectionPossible();

signals:
  /**
     Tells the listener to extract time from current timing.
     The time to extract is due to the idle time since the dialog wass
     shown, and until the user answers the dialog.
     @param minutes Minutes to extract.
  **/
  void extractTime(int minutes);

  /** Tells the listener to stop timing **/
  void stopAllTimers();

  /** Tells the listener to stop timing for TQDateTime **/
  void stopAllTimersAt(TQDateTime qdt);

public slots:
  /**
     Sets the maximum allowed idle.
     @param maxIdle Maximum allowed idle time in minutes
  **/
  void setMaxIdle(int maxIdle);

  /**
     Starts detecting idle time
  **/
  void startIdleDetection();

  /**
      Stops detecting idle time.
  **/
  void stopIdleDetection();

  /**
     Sets whether idle detection should be done at all
     @param on If true idle detection is done based on
     startIdleDetection and @ref stopIdleDetection
  **/
  void toggleOverAllIdleDetection(bool on);


protected:
#ifdef HAVE_LIBXSS
  void informOverrun(int idle);
#endif // HAVE_LIBXSS

protected slots:
  void check();

private:
#ifdef HAVE_LIBXSS
  XScreenSaverInfo *_mit_info;
#endif
  bool _idleDetectionPossible;
  bool _overAllIdleDetect; // Based on preferences.
  int _maxIdle;
  TQTimer *_timer;
};

#endif // KARM_IDLE_TIME_DETECTOR_H