karm Library API Documentation

desktoptracker.cpp

00001 #include <algorithm> // std::find 00002 00003 #include <qtimer.h> 00004 #include <kdebug.h> 00005 00006 #include "desktoptracker.h" 00007 00008 // TODO: Put in config dialog 00009 const int minimumInterval = 5; // seconds 00010 00011 DesktopTracker::DesktopTracker () 00012 { 00013 // Setup desktop change handling 00014 connect( &kWinModule, SIGNAL( currentDesktopChanged(int) ), 00015 this, SLOT( handleDesktopChange(int) )); 00016 00017 _desktopCount = kWinModule.numberOfDesktops(); 00018 _previousDesktop = kWinModule.currentDesktop()-1; 00019 // TODO: removed? fixed by Lubos? 00020 // currentDesktop will return 0 if no window manager is started 00021 if( _previousDesktop < 0 ) _previousDesktop = 0; 00022 00023 _timer = new QTimer(this); 00024 connect( _timer, SIGNAL( timeout() ), this, SLOT( changeTimers() ) ); 00025 } 00026 00027 void DesktopTracker::handleDesktopChange( int desktop ) 00028 { 00029 _desktop = desktop; 00030 00031 // If user changes back and forth between desktops rapidly and frequently, 00032 // the data file can get huge fast if logging is turned on. Then saving 00033 // get's slower, etc. There's no benefit in saving a lot of start/stop 00034 // events that are very small. Wait a bit to make sure the user is settled. 00035 if ( !_timer->start( minimumInterval * 1000, TRUE ) ) changeTimers(); 00036 } 00037 00038 void DesktopTracker::changeTimers() 00039 { 00040 _desktop--; // desktopTracker starts with 0 for desktop 1 00041 // notify start all tasks setup for running on desktop 00042 TaskVector::iterator it; 00043 00044 // stop trackers for _previousDesktop 00045 TaskVector tv = desktopTracker[_previousDesktop]; 00046 for (it = tv.begin(); it != tv.end(); it++) { 00047 emit leftActiveDesktop(*it); 00048 } 00049 00050 // start trackers for desktop 00051 tv = desktopTracker[_desktop]; 00052 for (it = tv.begin(); it != tv.end(); it++) { 00053 emit reachedtActiveDesktop(*it); 00054 } 00055 _previousDesktop = _desktop; 00056 00057 // emit updateButtons(); 00058 } 00059 00060 void DesktopTracker::startTracking() 00061 { 00062 int currentDesktop = kWinModule.currentDesktop() -1; 00063 // TODO: removed? fixed by Lubos? 00064 // currentDesktop will return 0 if no window manager is started 00065 if ( currentDesktop < 0 ) currentDesktop = 0; 00066 00067 TaskVector &tv = desktopTracker[ currentDesktop ]; 00068 TaskVector::iterator tit = tv.begin(); 00069 while(tit!=tv.end()) { 00070 emit reachedtActiveDesktop(*tit); 00071 tit++; 00072 } 00073 } 00074 00075 void DesktopTracker::registerForDesktops( Task* task, DesktopList desktopList) 00076 { 00077 // if no desktop is marked, disable auto tracking for this task 00078 if (desktopList.size()==0) { 00079 for (int i=0; i<maxDesktops; i++) { 00080 TaskVector *v = &(desktopTracker[i]); 00081 TaskVector::iterator tit = std::find(v->begin(), v->end(), task); 00082 if (tit != v->end()) 00083 desktopTracker[i].erase(tit); 00084 // if the task was priviously tracking this desktop then 00085 // emit a signal that is not tracking it any more 00086 if( i == kWinModule.currentDesktop() -1) 00087 emit leftActiveDesktop(task); 00088 } 00089 00090 return; 00091 } 00092 00093 // If desktop contains entries then configure desktopTracker 00094 // If a desktop was disabled, it will not be stopped automatically. 00095 // If enabled: Start it now. 00096 if (desktopList.size()>0) { 00097 for (int i=0; i<maxDesktops; i++) { 00098 TaskVector& v = desktopTracker[i]; 00099 TaskVector::iterator tit = std::find(v.begin(), v.end(), task); 00100 // Is desktop i in the desktop list? 00101 if ( std::find( desktopList.begin(), desktopList.end(), i) 00102 != desktopList.end()) { 00103 if (tit == v.end()) // not yet in start vector 00104 v.push_back(task); // track in desk i 00105 } 00106 else { // delete it 00107 if (tit != v.end()) // not in start vector any more 00108 { 00109 v.erase(tit); // so we delete it from desktopTracker 00110 // if the task was priviously tracking this desktop then 00111 // emit a signal that is not tracking it any more 00112 if( i == kWinModule.currentDesktop() -1) 00113 emit leftActiveDesktop(task); 00114 } 00115 } 00116 } 00117 startTracking(); 00118 } 00119 } 00120 00121 void DesktopTracker::printTrackers() { 00122 TaskVector::iterator it; 00123 for (int i=0; i<maxDesktops; i++) { 00124 TaskVector& start = desktopTracker[i]; 00125 it = start.begin(); 00126 while (it != start.end()) { 00127 it++; 00128 } 00129 } 00130 } 00131 #include "desktoptracker.moc"
KDE Logo
This file is part of the documentation for karm Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:56 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003