diff options
Diffstat (limited to 'SwifTools/Idle/ActualIdleDetector.cpp')
-rw-r--r-- | SwifTools/Idle/ActualIdleDetector.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/SwifTools/Idle/ActualIdleDetector.cpp b/SwifTools/Idle/ActualIdleDetector.cpp new file mode 100644 index 0000000..2e3f307 --- /dev/null +++ b/SwifTools/Idle/ActualIdleDetector.cpp @@ -0,0 +1,29 @@ +#include "SwifTools/Idle/ActualIdleDetector.h" + +#include <boost/bind.hpp> + +#include "SwifTools/Idle/IdleQuerier.h" +#include "Swiften/Network/Timer.h" +#include "Swiften/Network/TimerFactory.h" + +namespace Swift { + +ActualIdleDetector::ActualIdleDetector(IdleQuerier* querier, TimerFactory* timerFactory, int refreshRateSeconds) : querier(querier), isIdle(false) { + timer = timerFactory->createTimer(refreshRateSeconds*1000); + timer->onTick.connect(boost::bind(&ActualIdleDetector::handleTimerTick, this)); + timer->start(); +} + +ActualIdleDetector::~ActualIdleDetector() { + timer->stop(); +} + +void ActualIdleDetector::handleTimerTick() { + bool idle = (querier->getIdleTimeSeconds() >= getIdleTimeSeconds()); + if (idle != isIdle) { + isIdle = idle; + onIdleChanged(isIdle); + } +} + +} |