2 #include <tqdatetime.h>
6 #include <kiconloader.h>
8 #include "tdeapplication.h"
13 #include "karmutility.h"
16 #include "preferences.h"
19 const int gSecondsPerMinute = 60;
22 TQPtrVector<TQPixmap> *Task::icons = 0;
24 Task::Task(
const TQString& taskName,
long minutes,
long sessionTime,
25 DesktopList desktops,
TaskView *parent)
26 : TQObject(), TQListViewItem(parent)
28 init(taskName, minutes, sessionTime, desktops, 0);
31 Task::Task(
const TQString& taskName,
long minutes,
long sessionTime,
32 DesktopList desktops,
Task *parent)
33 : TQObject(), TQListViewItem(parent)
35 init(taskName, minutes, sessionTime, desktops, 0);
38 Task::Task( KCal::Todo* todo,
TaskView* parent )
39 : TQObject(), TQListViewItem( parent )
44 int percent_complete = 0;
47 parseIncidence(todo, minutes, sessionTime, name, desktops, percent_complete);
48 init(name, minutes, sessionTime, desktops, percent_complete);
51 void Task::init(
const TQString& taskName,
long minutes,
long sessionTime,
52 DesktopList desktops,
int percent_complete)
57 connect(
this, TQ_SIGNAL( totalTimesChanged (
long,
long ) ),
58 listView(), TQ_SLOT( taskTotalTimesChanged(
long,
long) ));
64 icons =
new TQPtrVector<TQPixmap>(8);
65 TDEIconLoader kil(
"karm");
66 for (
int i=0; i<8; i++)
68 TQPixmap *icon =
new TQPixmap();
70 name.sprintf(
"watch-%d.xpm",i);
71 *icon = kil.loadIcon(
name, TDEIcon::User );
72 icons->insert(i,icon);
77 _name = taskName.stripWhiteSpace();
78 _lastStart = TQDateTime::currentDateTime();
79 _totalTime = _time = minutes;
80 _totalSessionTime = _sessionTime = sessionTime;
81 _timer =
new TQTimer(
this);
84 setPixmap(1, UserIcon(TQString::fromLatin1(
"empty-watch.xpm")));
86 _percentcomplete = percent_complete;
89 changeParentTotalTimes( _sessionTime, _time);
102 kdDebug(5970) <<
"Entering Task::setRunning " <<
"on=" << on <<
"whenStarted=" << whenStarted <<
" whenStopped=" << whenStopped << endl;
105 if (!_timer->isActive())
110 _lastStart = whenStarted;
116 if (_timer->isActive())
122 setPixmap(1, UserIcon(TQString::fromLatin1(
"empty-watch.xpm")));
134 return _timer->isActive();
139 kdDebug(5970) <<
"Task:setName: " <<
name << endl;
141 TQString oldname = _name;
142 if ( oldname !=
name ) {
144 storage->
setName(
this, oldname);
151 kdDebug(5970) <<
"Task::setPercentComplete(" << percent <<
", storage): "
155 _percentcomplete = 0;
156 else if (percent > 100)
157 _percentcomplete = 100;
158 else if (percent < 0)
159 _percentcomplete = 0;
161 _percentcomplete = percent;
177 if (_percentcomplete == 100)
179 for (
Task* child= this->
firstChild(); child; child = child->nextSibling())
180 child->setPercentComplete(_percentcomplete, storage);
187 if (_percentcomplete >= 100)
188 icon = UserIcon(
"task-complete.xpm");
190 icon = UserIcon(
"task-incomplete.xpm");
199 child->removeFromView();
203 void Task::setDesktopList ( DesktopList desktopList )
205 _desktops = desktopList;
215 if( minutesSession != 0 || minutes != 0)
217 _sessionTime += minutesSession;
219 if ( storage ) storage->
changeTime(
this, minutes * gSecondsPerMinute);
227 <<
"Task::changeTotalTimes(" << minutesSession <<
", "
228 << minutes <<
") for " <<
name() << endl;
230 _totalSessionTime += minutesSession;
231 _totalTime += minutes;
233 changeParentTotalTimes( minutesSession, minutes );
238 _totalSessionTime -= _sessionTime;
240 changeParentTotalTimes( -_sessionTime, -_time);
246 void Task::changeParentTotalTimes(
long minutesSession,
long minutes )
253 emit totalTimesChanged( minutesSession, minutes );
260 kdDebug(5970) <<
"Task::remove: " << _name << endl;
268 for (
Task* child = this->
firstChild(); child; child = child->nextSibling())
270 if (child->isRunning())
271 child->setRunning(
false, storage);
272 child->remove(activeTasks, storage);
275 changeParentTotalTimes( -_sessionTime, -_time);
284 _currentPic = (_currentPic+1) % 8;
285 setPixmap(1, *(*icons)[_currentPic]);
293 return parent()->
fullName() + TQString::fromLatin1(
"/") +
name();
299 Q_ASSERT( todo != NULL );
301 kdDebug(5970) <<
"Task::asTodo: name() = '" <<
name() <<
"'" << endl;
302 todo->setSummary(
name() );
309 todo->setCustomProperty( kapp->instanceName(),
310 TQCString(
"totalTaskTime" ), TQString::number( _time ) );
311 todo->setCustomProperty( kapp->instanceName(),
312 TQCString(
"totalSessionTime" ), TQString::number( _sessionTime) );
314 if (getDesktopStr().isEmpty())
315 todo->removeCustomProperty(kapp->instanceName(), TQCString(
"desktopList"));
317 todo->setCustomProperty( kapp->instanceName(),
318 TQCString(
"desktopList" ), getDesktopStr() );
320 todo->setOrganizer( Preferences::instance()->userRealName() );
322 todo->setPercentComplete(_percentcomplete);
327 bool Task::parseIncidence( KCal::Incidence* incident,
long& minutes,
328 long& sessionMinutes, TQString& name, DesktopList& desktops,
329 int& percent_complete )
333 name = incident->summary();
334 _uid = incident->uid();
336 _comment = incident->description();
339 minutes = incident->customProperty( kapp->instanceName(),
340 TQCString(
"totalTaskTime" )).toInt( &ok );
345 sessionMinutes = incident->customProperty( kapp->instanceName(),
346 TQCString(
"totalSessionTime" )).toInt( &ok );
350 TQString desktopList = incident->customProperty( kapp->instanceName(),
351 TQCString(
"desktopList" ) );
352 TQStringList desktopStrList = TQStringList::split( TQString::fromLatin1(
","),
356 for ( TQStringList::iterator iter = desktopStrList.begin();
357 iter != desktopStrList.end();
359 int desktopInt = (*iter).toInt( &ok );
361 desktops.push_back( desktopInt );
365 percent_complete =
static_cast<KCal::Todo*
>(incident)->percentComplete();
374 TQString Task::getDesktopStr()
const
376 if ( _desktops.empty() )
380 for ( DesktopList::const_iterator iter = _desktops.begin();
381 iter != _desktops.end();
383 desktopstr += TQString::number( *iter ) + TQString::fromLatin1(
"," );
385 desktopstr.remove( desktopstr.length() - 1, 1 );
392 changeParentTotalTimes( -_totalSessionTime, -_totalTime);
394 listView()->takeItem(
this);
396 parent()->takeItem(
this);
407 destination->insertItem(
this);
408 changeParentTotalTimes( _totalSessionTime, _totalTime);
414 setText(1, formatTime(_sessionTime));
415 setText(2, formatTime(_time));
416 setText(3, formatTime(_totalSessionTime));
417 setText(4, formatTime(_totalTime));
422 _comment = _comment + TQString::fromLatin1(
"\n") +
comment;
440 thistime = _sessionTime;
441 thattime = task->sessionTime();
445 thattime = task->time();
448 thistime = _totalSessionTime;
449 thattime = task->totalSessionTime();
452 thistime = _totalTime;
453 thattime = task->totalTime();
456 return key(col, ascending).localeAwareCompare( i->key(col, ascending) );
459 if ( thistime < thattime )
return -1;
460 if ( thistime > thattime )
return 1;