summaryrefslogtreecommitdiffstats
path: root/karm/desktoptracker.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /karm/desktoptracker.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'karm/desktoptracker.cpp')
-rw-r--r--karm/desktoptracker.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/karm/desktoptracker.cpp b/karm/desktoptracker.cpp
new file mode 100644
index 000000000..52eb67210
--- /dev/null
+++ b/karm/desktoptracker.cpp
@@ -0,0 +1,137 @@
+#include <algorithm> // std::find
+
+#include <qtimer.h>
+#include <kdebug.h>
+
+#include "desktoptracker.h"
+
+// TODO: Put in config dialog
+const int minimumInterval = 5; // seconds
+
+DesktopTracker::DesktopTracker ()
+{
+ // Setup desktop change handling
+ connect( &kWinModule, SIGNAL( currentDesktopChanged(int) ),
+ this, SLOT( handleDesktopChange(int) ));
+
+ _desktopCount = kWinModule.numberOfDesktops();
+ _previousDesktop = kWinModule.currentDesktop()-1;
+ // TODO: removed? fixed by Lubos?
+ // currentDesktop will return 0 if no window manager is started
+ if( _previousDesktop < 0 ) _previousDesktop = 0;
+
+ _timer = new QTimer(this);
+ connect( _timer, SIGNAL( timeout() ), this, SLOT( changeTimers() ) );
+}
+
+void DesktopTracker::handleDesktopChange( int desktop )
+{
+ _desktop = desktop;
+
+ // If user changes back and forth between desktops rapidly and frequently,
+ // the data file can get huge fast if logging is turned on. Then saving
+ // get's slower, etc. There's no benefit in saving a lot of start/stop
+ // events that are very small. Wait a bit to make sure the user is settled.
+ if ( !_timer->start( minimumInterval * 1000, true ) ) changeTimers();
+}
+
+void DesktopTracker::changeTimers()
+{
+ _desktop--; // desktopTracker starts with 0 for desktop 1
+ // notify start all tasks setup for running on desktop
+ TaskVector::iterator it;
+
+ // stop trackers for _previousDesktop
+ TaskVector tv = desktopTracker[_previousDesktop];
+ for (it = tv.begin(); it != tv.end(); ++it) {
+ emit leftActiveDesktop(*it);
+ }
+
+ // start trackers for desktop
+ tv = desktopTracker[_desktop];
+ for (it = tv.begin(); it != tv.end(); ++it) {
+ emit reachedtActiveDesktop(*it);
+ }
+ _previousDesktop = _desktop;
+
+ // emit updateButtons();
+}
+
+QString DesktopTracker::startTracking()
+{
+ QString err;
+ int currentDesktop = kWinModule.currentDesktop() -1;
+ // TODO: removed? fixed by Lubos?
+ // currentDesktop will return 0 if no window manager is started
+ if ( currentDesktop < 0 ) currentDesktop = 0;
+ if ( currentDesktop < maxDesktops )
+ {
+ TaskVector &tv = desktopTracker[ currentDesktop ];
+ TaskVector::iterator tit = tv.begin();
+ while(tit!=tv.end())
+ {
+ emit reachedtActiveDesktop(*tit);
+ tit++;
+ }
+ }
+ else err="ETooHighDeskTopNumber";
+ return err;
+}
+
+void DesktopTracker::registerForDesktops( Task* task, DesktopList desktopList)
+{
+ // if no desktop is marked, disable auto tracking for this task
+ if (desktopList.size()==0) {
+ for (int i=0; i<maxDesktops; i++) {
+ TaskVector *v = &(desktopTracker[i]);
+ TaskVector::iterator tit = std::find(v->begin(), v->end(), task);
+ if (tit != v->end())
+ desktopTracker[i].erase(tit);
+ // if the task was priviously tracking this desktop then
+ // emit a signal that is not tracking it any more
+ if( i == kWinModule.currentDesktop() -1)
+ emit leftActiveDesktop(task);
+ }
+
+ return;
+ }
+
+ // If desktop contains entries then configure desktopTracker
+ // If a desktop was disabled, it will not be stopped automatically.
+ // If enabled: Start it now.
+ if (desktopList.size()>0) {
+ for (int i=0; i<maxDesktops; i++) {
+ TaskVector& v = desktopTracker[i];
+ TaskVector::iterator tit = std::find(v.begin(), v.end(), task);
+ // Is desktop i in the desktop list?
+ if ( std::find( desktopList.begin(), desktopList.end(), i)
+ != desktopList.end()) {
+ if (tit == v.end()) // not yet in start vector
+ v.push_back(task); // track in desk i
+ }
+ else { // delete it
+ if (tit != v.end()) // not in start vector any more
+ {
+ v.erase(tit); // so we delete it from desktopTracker
+ // if the task was priviously tracking this desktop then
+ // emit a signal that is not tracking it any more
+ if( i == kWinModule.currentDesktop() -1)
+ emit leftActiveDesktop(task);
+ }
+ }
+ }
+ startTracking();
+ }
+}
+
+void DesktopTracker::printTrackers() {
+ TaskVector::iterator it;
+ for (int i=0; i<maxDesktops; i++) {
+ TaskVector& start = desktopTracker[i];
+ it = start.begin();
+ while (it != start.end()) {
+ it++;
+ }
+ }
+}
+#include "desktoptracker.moc"