1 #include "idletimedetector.h"
3 #include <tqdatetime.h>
4 #include <tqmessagebox.h>
13 kdDebug(5970) << "Entering IdleTimeDetector::IdleTimeDetector" << endl;
17 kdDebug(5970) << "IdleTimeDetector: LIBXSS detected @ compile time" << endl;
18 int event_base, error_base;
19 if(XScreenSaverQueryExtension(tqt_xdisplay(), &event_base, &error_base))
21 _idleDetectionPossible = true;
22 _mit_info = XScreenSaverAllocInfo ();
26 _idleDetectionPossible = false;
29 _timer = new TQTimer( this);
30 connect(_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(check()));
32 _idleDetectionPossible = false;
39 return _idleDetectionPossible;
42 void IdleTimeDetector::check()
44 kdDebug(5970) << "Entering IdleTimeDetector::check" << endl;
46 if (_idleDetectionPossible)
48 XScreenSaverQueryInfo(tqt_xdisplay(), tqt_xrootwin(), _mit_info);
49 int idleSeconds = (_mit_info->idle/1000);
50 if (idleSeconds >= _maxIdle)
51 informOverrun(idleSeconds);
62 void IdleTimeDetector::informOverrun( int idleSeconds)
64 kdDebug(5970) << "Entering IdleTimeDetector::informOverrun" << endl;
65 if (!_overAllIdleDetect)
70 TQDateTime idleStart = TQDateTime::currentDateTime().addSecs(-idleSeconds);
71 TQString idleStartTQString = TDEGlobal::locale()->formatTime(idleStart.time());
73 int id = TQMessageBox::warning( 0, i18n( "Idle Detection"),
74 i18n( "Desktop has been idle since %1."
75 " What should we do?").arg(idleStartTQString),
76 i18n( "Revert && Stop"),
77 i18n( "Revert && Continue"),
78 i18n( "Continue Timing"),0,2);
79 TQDateTime end = TQDateTime::currentDateTime();
80 int diff = idleStart.secsTo(end)/secsPerMinute;
85 kdDebug(5970) << "Now it is " << TQDateTime::currentDateTime() << endl;
86 kdDebug(5970) << "Reverting timer to " << TDEGlobal::locale()->formatTime(idleStart.time()).ascii() << endl;
94 _timer->start(testInterval);
99 _timer->start(testInterval);
102 #endif // HAVE_LIBXSS
106 kdDebug(5970) << "Entering IdleTimeDetector::startIdleDetection" << endl;
108 kdDebug(5970) << "Starting Timer" << endl;
109 if (!_timer->isActive())
110 _timer->start(testInterval);
117 if (_timer->isActive())
119 #endif // HAVE_LIBXSS
123 _overAllIdleDetect = on;
126 #include "idletimedetector.moc"
|