diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-11-24 20:03:09 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-11-24 20:03:09 (GMT) |
commit | 48fc9e9fb0abd42d47a95042837a026730f20f34 (patch) | |
tree | 3390dbf200fcde18c2b1c6877c29a143e80671fd /SwifTools/Idle | |
parent | 3b7e581ad1d57170d9809e27437ee3c468c5702f (diff) | |
download | swift-48fc9e9fb0abd42d47a95042837a026730f20f34.zip swift-48fc9e9fb0abd42d47a95042837a026730f20f34.tar.bz2 |
Integrated new IdleDetector.
Diffstat (limited to 'SwifTools/Idle')
-rw-r--r-- | SwifTools/Idle/ActualIdleDetector.cpp | 11 | ||||
-rw-r--r-- | SwifTools/Idle/ActualIdleDetector.h | 3 | ||||
-rw-r--r-- | SwifTools/Idle/IdleDetector.h | 14 |
3 files changed, 19 insertions, 9 deletions
diff --git a/SwifTools/Idle/ActualIdleDetector.cpp b/SwifTools/Idle/ActualIdleDetector.cpp index 2e3f307..ef73a4c 100644 --- a/SwifTools/Idle/ActualIdleDetector.cpp +++ b/SwifTools/Idle/ActualIdleDetector.cpp @@ -1,6 +1,7 @@ #include "SwifTools/Idle/ActualIdleDetector.h" #include <boost/bind.hpp> +#include <iostream> #include "SwifTools/Idle/IdleQuerier.h" #include "Swiften/Network/Timer.h" @@ -8,8 +9,8 @@ namespace Swift { -ActualIdleDetector::ActualIdleDetector(IdleQuerier* querier, TimerFactory* timerFactory, int refreshRateSeconds) : querier(querier), isIdle(false) { - timer = timerFactory->createTimer(refreshRateSeconds*1000); +ActualIdleDetector::ActualIdleDetector(IdleQuerier* querier, TimerFactory* timerFactory, int refreshRateMilliseconds) : querier(querier) { + timer = timerFactory->createTimer(refreshRateMilliseconds); timer->onTick.connect(boost::bind(&ActualIdleDetector::handleTimerTick, this)); timer->start(); } @@ -19,11 +20,7 @@ ActualIdleDetector::~ActualIdleDetector() { } void ActualIdleDetector::handleTimerTick() { - bool idle = (querier->getIdleTimeSeconds() >= getIdleTimeSeconds()); - if (idle != isIdle) { - isIdle = idle; - onIdleChanged(isIdle); - } + setIdle(querier->getIdleTimeSeconds() >= getIdleTimeSeconds()); } } diff --git a/SwifTools/Idle/ActualIdleDetector.h b/SwifTools/Idle/ActualIdleDetector.h index 48428bb..7bc36e2 100644 --- a/SwifTools/Idle/ActualIdleDetector.h +++ b/SwifTools/Idle/ActualIdleDetector.h @@ -11,7 +11,7 @@ namespace Swift { class ActualIdleDetector : public IdleDetector, public boost::bsignals::trackable { public: - ActualIdleDetector(IdleQuerier*, TimerFactory*, int refreshRateSeconds); + ActualIdleDetector(IdleQuerier*, TimerFactory*, int refreshRateMilliseconds); ~ActualIdleDetector(); private: @@ -19,7 +19,6 @@ namespace Swift { private: IdleQuerier* querier; - bool isIdle; boost::shared_ptr<Timer> timer; }; } diff --git a/SwifTools/Idle/IdleDetector.h b/SwifTools/Idle/IdleDetector.h index 1fb3d69..bd7175d 100644 --- a/SwifTools/Idle/IdleDetector.h +++ b/SwifTools/Idle/IdleDetector.h @@ -6,6 +6,7 @@ namespace Swift { class IdleDetector { public: + IdleDetector() : idle(false) {} virtual ~IdleDetector(); void setIdleTimeSeconds(int time) { @@ -16,9 +17,22 @@ namespace Swift { return idleTimeSeconds; } + virtual bool isIdle() const { + return idle; + } + boost::signal<void (bool /* isIdle */)> onIdleChanged; + protected: + void setIdle(bool b) { + if (b != idle) { + idle = b; + onIdleChanged(b); + } + } + private: int idleTimeSeconds; + bool idle; }; } |