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) ));
60 connect(
this, TQ_SIGNAL( deletingTask(
Task* ) ),
61 listView(), TQ_SLOT( deletingTask(
Task* ) ));
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);
83 connect(_timer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(updateActiveIcon()));
84 setPixmap(1, UserIcon(TQString::fromLatin1(
"empty-watch.xpm")));
86 _percentcomplete = percent_complete;
89 changeParentTotalTimes( _sessionTime, _time);
93 emit deletingTask(
this);
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;
163 if (isRunning() && _percentcomplete==100) taskView()->stopTimerFor(
this);
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");
198 while (
Task* child = firstChild() )
199 child->removeFromView();
203 void Task::setDesktopList ( DesktopList desktopList )
205 _desktops = desktopList;
210 changeTimes( minutes, minutes, storage);
215 if( minutesSession != 0 || minutes != 0)
217 _sessionTime += minutesSession;
219 if ( storage ) storage->
changeTime(
this, minutes * gSecondsPerMinute);
220 changeTotalTimes( minutesSession, minutes );
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 );
255 parent()->changeTotalTimes( minutesSession, minutes );
260 kdDebug(5970) <<
"Task::remove: " << _name << endl;
266 if( isRunning() ) setRunning(
false, storage );
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;
void addComment(TQString comment, KarmStorage *storage)
Add a comment to this task.
void startTimer(const Task *task)
Log the event that a timer has started for a task.
void stopTimer(const Task *task, TQDateTime when=TQDateTime::currentDateTime())
Log the event that the timer has stopped for this task.
void changeTime(long minutes, KarmStorage *storage)
Change task time.
void setPercentComplete(const int percent, KarmStorage *storage)
Update percent complete for this task.
void updateActiveIcon()
animate the active icon
void update()
Update the display of the task (all columns) in the UI.
bool removeTask(Task *task)
Remove this task from iCalendar file.
void changeTotalTimes(long minutesSession, long minutes)
adds minutes to total and session time
bool isComplete()
Return true if task is complete (percent complete equals 100).
bool isRunning() const
return the state of a task - if it's running or not
void resetTimes()
Reset all times to 0.
KCal::Todo * asTodo(KCal::Todo *calendar) const
Load the todo passed in with this tasks info.
void changeTime(const Task *task, const long deltaSeconds)
Log the change in a task's time.
Singleton to store/retrieve KArm data to/from persistent storage.
void setUid(const TQString uid)
Set unique id for the task.
TQString comment() const
Retrieve the entire comment for the task.
void removeFromView()
Remove current task and all it's children from the view.
int compare(TQListViewItem *i, int col, bool ascending) const
Sort times numerically, not alphabetically.
void setName(const TQString &name, KarmStorage *storage)
sets the name of the task
void cut()
cut Task out of parent Task or the TaskView
void paste(Task *destination)
insert Task into the destination Task
void setName(const Task *task, const TQString &oldname)
Log a change to a task name.
void move(Task *destination)
cut Task out of parent Task or the TaskView and into the destination Task
TQString fullName() const
Returns that task name, prefixed by parent tree up to root.
void addComment(const Task *task, const TQString &comment)
Log a new comment for this task.
void setPixmapProgress()
Sets an appropriate icon for this task based on its level of completion.
Container and interface for the tasks.
A class representing a task.
void changeTimes(long minutesSession, long minutes, KarmStorage *storage=0)
Add minutes to time and session time, and write to storage.
void setRunning(bool on, KarmStorage *storage, TQDateTime whenStarted=TQDateTime::currentDateTime(), TQDateTime whenStopped=TQDateTime::currentDateTime())
starts or stops a task
bool remove(TQPtrList< Task > &activeTasks, KarmStorage *storage)
remove Task with all it's children