• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

ktimetracker

desktoptracker.cpp

Go to the documentation of this file.
00001 /*
00002  *     Copyright (C) 2003 by Tomas Pospisek <tpo@sourcepole.ch>
00003  *                   2007 the ktimetracker developers
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License along
00016  *   with this program; if not, write to the
00017  *      Free Software Foundation, Inc.
00018  *      51 Franklin Street, Fifth Floor
00019  *      Boston, MA  02110-1301  USA.
00020  *
00021  */
00022 #include "desktoptracker.h"
00023 
00024 #include <QTimer>
00025 
00026 #include <KDebug>
00027 #include <KWindowSystem>
00028 
00029 #include "ktimetracker.h"
00030 
00031 DesktopTracker::DesktopTracker ()
00032 {
00033   // Setup desktop change handling
00034 #ifdef Q_WS_X11
00035   connect( KWindowSystem::self(), SIGNAL( currentDesktopChanged( int ) ),
00036            this, SLOT( handleDesktopChange( int ) ) );
00037 
00038   mDesktopCount = KWindowSystem::self()->numberOfDesktops();
00039   mPreviousDesktop = KWindowSystem::self()->currentDesktop()-1;
00040 #else
00041 #ifdef __GNUC__
00042 #warning non-X11 support missing
00043 #endif
00044 #endif
00045   // TODO: removed? fixed by Lubos?
00046   // currentDesktop will return 0 if no window manager is started
00047   if( mPreviousDesktop < 0 ) mPreviousDesktop = 0;
00048 
00049   mTimer = new QTimer( this );
00050   mTimer->setSingleShot( true );
00051   connect( mTimer, SIGNAL( timeout() ), this, SLOT( changeTimers() ) );
00052 }
00053 
00054 void DesktopTracker::handleDesktopChange( int desktop )
00055 {
00056   mDesktop = desktop;
00057 
00058   // If user changes back and forth between desktops rapidly and frequently,
00059   // the data file can get huge fast if logging is turned on.  Then saving
00060   // get's slower, etc.  There's no benefit in saving a lot of start/stop 
00061   // events that are very small.  Wait a bit to make sure the user is settled.
00062   mTimer->start( KTimeTrackerSettings::minActiveTime() * 1000 );
00063 }
00064 
00065 void DesktopTracker::changeTimers()
00066 {
00067   --mDesktop; // desktopTracker starts with 0 for desktop 1
00068   // notify start all tasks setup for running on desktop
00069 
00070   // stop trackers for mPreviousDesktop
00071   foreach ( Task *task, mDesktopTracker[mPreviousDesktop] ) {
00072     emit leftActiveDesktop( task );
00073   }
00074 
00075   // start trackers for desktop
00076   foreach ( Task *task, mDesktopTracker[mDesktop] ) {
00077     emit reachedActiveDesktop( task );
00078   }
00079 
00080   mPreviousDesktop = mDesktop;
00081 }
00082 
00083 QString DesktopTracker::startTracking()
00084 {
00085   QString err;
00086 #ifdef Q_WS_X11
00087   int currentDesktop = KWindowSystem::self()->currentDesktop() -1;
00088 #else
00089 #ifdef __GNUC__
00090 #warning non-X11 support missing
00091 #endif
00092   int currentDesktop = 0;
00093 #endif
00094   // TODO: removed? fixed by Lubos?
00095   // currentDesktop will return 0 if no window manager is started
00096   if ( currentDesktop < 0 ) currentDesktop = 0;
00097   if ( currentDesktop >= maxDesktops ) err="desktop number too high, desktop tracking will not work";
00098   else 
00099     foreach ( Task *task, mDesktopTracker[ currentDesktop ] ) 
00100     {
00101       emit reachedActiveDesktop( task );
00102     }
00103   return err;
00104 }
00105 
00106 void DesktopTracker::registerForDesktops( Task* task, DesktopList desktopList )
00107 {
00108   kDebug(5970) << "Entering function";
00109   // if no desktop is marked, disable auto tracking for this task
00110   if ( desktopList.size() == 0 ) 
00111   {
00112     for ( int i = 0; i < maxDesktops; ++i ) 
00113     {
00114       TaskVector *v = &( mDesktopTracker[i] );
00115       TaskVector::iterator tit = qFind( v->begin(), v->end(), task );
00116       if ( tit != v->end() )
00117         mDesktopTracker[i].erase( tit );
00118       // if the task was priviously tracking this desktop then
00119       // emit a signal that is not tracking it any more
00120 #ifdef Q_WS_X11
00121       if ( i == KWindowSystem::self()->currentDesktop() - 1 )
00122         emit leftActiveDesktop( task );
00123 #else
00124 #ifdef __GNUC__
00125 #warning non-X11 support missing
00126 #endif
00127 #endif
00128     }
00129     kDebug(5970) << "Leaving function, desktopList.size=0";
00130     return;
00131   }
00132 
00133   // If desktop contains entries then configure desktopTracker
00134   // If a desktop was disabled, it will not be stopped automatically.
00135   // If enabled: Start it now.
00136   if ( desktopList.size() > 0 ) 
00137   {
00138     for ( int i = 0; i < maxDesktops; ++i ) 
00139     {
00140       TaskVector& v = mDesktopTracker[i];
00141       TaskVector::iterator tit = qFind( v.begin(), v.end(), task );
00142       // Is desktop i in the desktop list?
00143       if ( qFind( desktopList.begin(), desktopList.end(), i )
00144            != desktopList.end() ) 
00145       {
00146         if ( tit == v.end() )  // not yet in start vector
00147           v.push_back( task ); // track in desk i
00148       } 
00149       else 
00150       { // delete it
00151         if ( tit != v.end() ) // not in start vector any more
00152         {
00153           v.erase( tit ); // so we delete it from desktopTracker
00154           // if the task was priviously tracking this desktop then
00155           // emit a signal that is not tracking it any more
00156 #ifdef Q_WS_X11
00157           if( i == KWindowSystem::self()->currentDesktop() -1)
00158             emit leftActiveDesktop( task );
00159 #else
00160 #ifdef __GNUC__
00161 #warning non-X11 support missing
00162 #endif
00163 #endif
00164         }
00165       }
00166     }
00167     startTracking();
00168   }
00169   kDebug(5970) << "Leaving function";
00170 }
00171 
00172 #include "desktoptracker.moc"

ktimetracker

Skip menu "ktimetracker"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal