From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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 --- karm/desktoptracker.cpp | 137 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 karm/desktoptracker.cpp (limited to 'karm/desktoptracker.cpp') 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 // std::find + +#include +#include + +#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; ibegin(), 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