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

ktimetracker

  • sources
  • kde-4.12
  • kdepim
  • ktimetracker
desktoptracker.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003 by Tomas Pospisek <tpo@sourcepole.ch>
3  * 2007 the ktimetracker developers
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the
17  * Free Software Foundation, Inc.
18  * 51 Franklin Street, Fifth Floor
19  * Boston, MA 02110-1301 USA.
20  *
21  */
22 
23 #include "desktoptracker.h"
24 #include <KDebug>
25 #include "ktimetracker.h"
26 #include "ktimetrackerutility.h"
27 #include <KWindowSystem>
28 #include <QTimer>
29 
30 DesktopTracker::DesktopTracker ()
31 {
32  // Setup desktop change handling
33 #ifdef Q_WS_X11
34  connect( KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)),
35  this, SLOT(handleDesktopChange(int)) );
36  mDesktopCount = desktopCount();
37  mPreviousDesktop = KWindowSystem::self()->currentDesktop()-1;
38 #else
39 #ifdef __GNUC__
40 #warning non-X11 support missing
41 #endif
42 #endif
43  // currentDesktop will return 0 if no window manager is started
44  if( mPreviousDesktop < 0 ) mPreviousDesktop = 0;
45  mTimer = new QTimer( this );
46  mTimer->setSingleShot( true );
47  connect( mTimer, SIGNAL(timeout()), this, SLOT(changeTimers()) );
48 }
49 
50 void DesktopTracker::handleDesktopChange( int desktop )
51 {
52  mDesktop = desktop;
53 
54  // If user changes back and forth between desktops rapidly and frequently,
55  // the data file can get huge fast if logging is turned on. Then saving
56  // gets slower, etc. There's no benefit in saving a lot of start/stop
57  // events that are very small. Wait a bit to make sure the user is settled.
58  mTimer->start( KTimeTrackerSettings::minActiveTime() * 1000 );
59 }
60 
61 void DesktopTracker::changeTimers()
62 {
63  --mDesktop; // desktopTracker starts with 0 for desktop 1
64  // notify start all tasks setup for running on desktop
65 
66  // stop trackers for mPreviousDesktop
67  foreach ( Task *task, mDesktopTracker[mPreviousDesktop] )
68  {
69  emit leftActiveDesktop( task );
70  }
71 
72  // start trackers for desktop
73  foreach ( Task *task, mDesktopTracker[mDesktop] )
74  {
75  emit reachedActiveDesktop( task );
76  }
77  mPreviousDesktop = mDesktop;
78 }
79 
80 QString DesktopTracker::startTracking()
81 {
82  QString err;
83 #ifdef Q_WS_X11
84  int currentDesktop = KWindowSystem::self()->currentDesktop() -1;
85 #else
86  int currentDesktop = 0;
87 #endif
88  if ( currentDesktop < 0 ) currentDesktop = 0;
89  if ( currentDesktop >= maxDesktops ) err="desktop number too high, desktop tracking will not work";
90  else
91  foreach ( Task *task, mDesktopTracker[ currentDesktop ] )
92  {
93  emit reachedActiveDesktop( task );
94  }
95  return err;
96 }
97 
98 void DesktopTracker::registerForDesktops( Task* task, DesktopList desktopList )
99 {
100  kDebug(5970) << "Entering function";
101  // if no desktop is marked, disable auto tracking for this task
102  if ( desktopList.size() == 0 )
103  {
104  for ( int i = 0; i < maxDesktops; ++i )
105  {
106  TaskVector *v = &( mDesktopTracker[i] );
107  TaskVector::iterator tit = qFind( v->begin(), v->end(), task );
108  if ( tit != v->end() )
109  mDesktopTracker[i].erase( tit );
110  // if the task was priviously tracking this desktop then
111  // emit a signal that is not tracking it any more
112 #ifdef Q_WS_X11
113  if ( i == KWindowSystem::self()->currentDesktop() - 1 )
114  emit leftActiveDesktop( task );
115 #endif
116  }
117  kDebug(5970) << "Leaving function, desktopList.size=0";
118  return;
119  }
120 
121  // If desktop contains entries then configure desktopTracker
122  // If a desktop was disabled, it will not be stopped automatically.
123  // If enabled: Start it now.
124  if ( desktopList.size() > 0 )
125  {
126  for ( int i = 0; i < maxDesktops; ++i )
127  {
128  TaskVector& v = mDesktopTracker[i];
129  TaskVector::iterator tit = qFind( v.begin(), v.end(), task );
130  // Is desktop i in the desktop list?
131  if ( qFind( desktopList.begin(), desktopList.end(), i )
132  != desktopList.end() )
133  {
134  if ( tit == v.end() ) // not yet in start vector
135  v.push_back( task ); // track in desk i
136  }
137  else
138  { // delete it
139  if ( tit != v.end() ) // not in start vector any more
140  {
141  v.erase( tit ); // so we delete it from desktopTracker
142  // if the task was priviously tracking this desktop then
143  // emit a signal that is not tracking it any more
144 #ifdef Q_WS_X11
145  if( i == KWindowSystem::self()->currentDesktop() -1)
146  emit leftActiveDesktop( task );
147 #endif
148  }
149  }
150  }
151  startTracking();
152  }
153  kDebug(5970) << "Leaving function";
154 }
155 
156 #include "desktoptracker.moc"
desktoptracker.h
DesktopTracker::leftActiveDesktop
void leftActiveDesktop(Task *task)
TaskVector
QVector< Task * > TaskVector
Definition: desktoptracker.h:32
KTimeTrackerSettings::minActiveTime
static uint minActiveTime()
Get minActiveTime.
Definition: ktimetracker.h:107
DesktopTracker::DesktopTracker
DesktopTracker()
Definition: desktoptracker.cpp:30
DesktopTracker::desktopCount
int desktopCount() const
Definition: desktoptracker.h:56
DesktopTracker::handleDesktopChange
void handleDesktopChange(int desktop)
Definition: desktoptracker.cpp:50
ktimetracker.h
maxDesktops
const int maxDesktops
Definition: desktoptracker.h:35
DesktopList
QVector< int > DesktopList
Definition: desktoplist.h:28
DesktopTracker::startTracking
QString startTracking()
Start time tracking of tasks by virtual desktop.
Definition: desktoptracker.cpp:80
DesktopTracker::registerForDesktops
void registerForDesktops(Task *task, DesktopList dl)
Definition: desktoptracker.cpp:98
ktimetrackerutility.h
Task
A class representing a task.
Definition: task.h:54
DesktopTracker::reachedActiveDesktop
void reachedActiveDesktop(Task *task)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktimetracker

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal