karm
idletimedetector.cpp00001 #include "idletimedetector.h"
00002
00003 #include <tqdatetime.h>
00004 #include <tqmessagebox.h>
00005 #include <tqtimer.h>
00006
00007 #include <tdeglobal.h>
00008 #include <tdelocale.h>
00009
00010 IdleTimeDetector::IdleTimeDetector(int maxIdle)
00011
00012 {
00013 kdDebug(5970) << "Entering IdleTimeDetector::IdleTimeDetector" << endl;
00014 _maxIdle = maxIdle;
00015
00016 #ifdef HAVE_LIBXSS
00017 kdDebug(5970) << "IdleTimeDetector: LIBXSS detected @ compile time" << endl;
00018 int event_base, error_base;
00019 if(XScreenSaverQueryExtension(tqt_xdisplay(), &event_base, &error_base))
00020 {
00021 _idleDetectionPossible = true;
00022 _mit_info = XScreenSaverAllocInfo ();
00023 }
00024 else
00025 {
00026 _idleDetectionPossible = false;
00027 }
00028
00029 _timer = new TQTimer(this);
00030 connect(_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(check()));
00031 #else
00032 _idleDetectionPossible = false;
00033 #endif // HAVE_LIBXSS
00034
00035 }
00036
00037 bool IdleTimeDetector::isIdleDetectionPossible()
00038 {
00039 return _idleDetectionPossible;
00040 }
00041
00042 void IdleTimeDetector::check()
00043 {
00044 kdDebug(5970) << "Entering IdleTimeDetector::check" << endl;
00045 #ifdef HAVE_LIBXSS
00046 if (_idleDetectionPossible)
00047 {
00048 XScreenSaverQueryInfo(tqt_xdisplay(), tqt_xrootwin(), _mit_info);
00049 int idleSeconds = (_mit_info->idle/1000);
00050 if (idleSeconds >= _maxIdle)
00051 informOverrun(idleSeconds);
00052 }
00053 #endif // HAVE_LIBXSS
00054 }
00055
00056 void IdleTimeDetector::setMaxIdle(int maxIdle)
00057 {
00058 _maxIdle = maxIdle;
00059 }
00060
00061 #ifdef HAVE_LIBXSS
00062 void IdleTimeDetector::informOverrun(int idleSeconds)
00063 {
00064 kdDebug(5970) << "Entering IdleTimeDetector::informOverrun" << endl;
00065 if (!_overAllIdleDetect)
00066 return;
00067
00068 _timer->stop();
00069
00070 TQDateTime idleStart = TQDateTime::currentDateTime().addSecs(-idleSeconds);
00071 TQString idleStartTQString = TDEGlobal::locale()->formatTime(idleStart.time());
00072
00073 int id = TQMessageBox::warning( 0, i18n("Idle Detection"),
00074 i18n("Desktop has been idle since %1."
00075 " What should we do?").arg(idleStartTQString),
00076 i18n("Revert && Stop"),
00077 i18n("Revert && Continue"),
00078 i18n("Continue Timing"),0,2);
00079 TQDateTime end = TQDateTime::currentDateTime();
00080 int diff = idleStart.secsTo(end)/secsPerMinute;
00081
00082 if (id == 0)
00083 {
00084
00085 kdDebug(5970) << "Now it is " << TQDateTime::currentDateTime() << endl;
00086 kdDebug(5970) << "Reverting timer to " << TDEGlobal::locale()->formatTime(idleStart.time()).ascii() << endl;
00087 emit(extractTime(idleSeconds/60+diff));
00088 emit(stopAllTimersAt(idleStart));
00089 }
00090 else if (id == 1)
00091 {
00092
00093 emit(extractTime(idleSeconds/60+diff));
00094 _timer->start(testInterval);
00095 }
00096 else
00097 {
00098
00099 _timer->start(testInterval);
00100 }
00101 }
00102 #endif // HAVE_LIBXSS
00103
00104 void IdleTimeDetector::startIdleDetection()
00105 {
00106 kdDebug(5970) << "Entering IdleTimeDetector::startIdleDetection" << endl;
00107 #ifdef HAVE_LIBXSS
00108 kdDebug(5970) << "Starting Timer" << endl;
00109 if (!_timer->isActive())
00110 _timer->start(testInterval);
00111 #endif //HAVE_LIBXSS
00112 }
00113
00114 void IdleTimeDetector::stopIdleDetection()
00115 {
00116 #ifdef HAVE_LIBXSS
00117 if (_timer->isActive())
00118 _timer->stop();
00119 #endif // HAVE_LIBXSS
00120 }
00121 void IdleTimeDetector::toggleOverAllIdleDetection(bool on)
00122 {
00123 _overAllIdleDetect = on;
00124 }
00125
00126 #include "idletimedetector.moc"
|