31 #include <KIconLoader>
32 #include <KComponentData>
34 #include <KCalCore/Event>
40 QVector<QPixmap*> *Task::icons = 0;
42 Task::Task(
const QString& taskName,
const QString& taskDescription,
long minutes,
long sessionTime,
46 init( taskName, taskDescription, minutes, sessionTime, 0, desktops, 0, 0, konsolemode );
49 Task::Task(
const QString& taskName,
const QString& taskDescription,
long minutes,
long sessionTime,
53 init( taskName, taskDescription, minutes, sessionTime, 0, desktops, 0, 0 );
64 int percent_complete = 0;
68 parseIncidence( todo, minutes, sessionTime, sessionStartTiMe, name, description, desktops, percent_complete,
70 init( name, description, minutes, sessionTime, sessionStartTiMe, desktops, percent_complete, priority, konsolemode );
77 kDebug(5970) <<
"Entering function";
80 while ( ( t = t->
parent() ) ) res++;
81 kDebug(5970) <<
"Leaving function. depth is:" << res;
85 void Task::init(
const QString& taskName,
const QString& taskDescription,
long minutes,
long sessionTime, QString sessionStartTiMe,
86 DesktopList desktops,
int percent_complete,
int priority,
bool konsolemode )
93 taskView, SLOT(taskTotalTimesChanged(
long,
long)));
100 icons =
new QVector<QPixmap*>(8);
103 KIconLoader kil(
"ktimetracker");
104 for (
int i=0; i<8; ++i)
106 QPixmap *icon =
new QPixmap();
108 name.sprintf(
"watch-%d.xpm",i);
109 *icon = kil.loadIcon( name, KIconLoader::User );
110 icons->insert(i,icon);
116 mName = taskName.trimmed();
117 mDescription = taskDescription.trimmed();
118 mLastStart = QDateTime::currentDateTime();
119 mTotalTime = mTime = minutes;
121 mTimer =
new QTimer(
this);
124 if ( !konsolemode ) setIcon(1, UserIcon(QString::fromLatin1(
"empty-watch.xpm")));
126 mPercentComplete = percent_complete;
128 mSessionStartTiMe=KDateTime::fromString(sessionStartTiMe);
134 for (
int i = 1; i < columnCount(); ++i)
136 setTextAlignment( i, Qt::AlignRight );
140 setTextAlignment( 5, Qt::AlignCenter );
151 while ( this->child(0) )
162 kDebug(5970) <<
"Entering function";
165 if (!mTimer->isActive())
171 kDebug(5970) <<
"task has been started for " << when;
177 if (mTimer->isActive())
183 setIcon(1, UserIcon(QString::fromLatin1(
"empty-watch.xpm")));
194 kDebug(5970) <<
"Entering function";
195 if (!mTimer->isActive())
210 return mTimer->isActive();
215 kDebug(5970) <<
"Entering function, name=" <<
name;
217 QString oldname = mName;
218 if ( oldname != name )
221 storage->
setName(
this, oldname);
228 kDebug(5970) <<
"Entering function, description=" <<
description;
230 QString olddescription = mDescription;
231 if ( olddescription != description )
240 kDebug(5970) <<
"Entering function(" << percent <<
", storage):" << mUid;
243 mPercentComplete = 0;
244 else if (percent > 100)
245 mPercentComplete = 100;
246 else if (percent < 0)
247 mPercentComplete = 0;
249 mPercentComplete = percent;
257 if (mPercentComplete == 100)
259 for (
int i = 0; i < childCount(); ++i )
261 Task *task =
static_cast< Task*
>( child( i ) );
275 else if ( priority > 9 )
286 kDebug(5970) <<
"Entering function";
288 KIconLoader* kil =
new KIconLoader();
289 if (mPercentComplete >= 100)
291 const QString iconcomplete=QString(
"task-complete.xpm");
292 icon = kil->loadIcon( iconcomplete, KIconLoader::User );
296 const QString iconincomplete=QString(
"task-incomplete.xpm");
297 icon = kil->loadIcon( iconincomplete, KIconLoader::User );
301 kDebug(5970) <<
"Leaving function";
308 mDesktops = desktopList;
313 kDebug(5970) <<
"Entering function";
317 kDebug(5970) <<
"Leaving function";
323 kDebug(5970) <<
"Entering function";
327 kDebug(5970) <<
"Leaving function";
333 kDebug(5970) <<
"Entering function";
335 mSessionTime+=minutes;
337 kDebug(5970) <<
"Leaving function";
343 kDebug(5970) <<
"Entering function";
345 mTotalSessionTime+=minutes;
347 kDebug(5970) <<
"Leaving function";
353 kDebug(5970) <<
"Entering function";
357 kDebug(5970) <<
"Leaving function";
366 for (
int i=0; i<this->childCount(); ++i)
367 child=(
Task*)this->child(i);
377 for (
int i=0; i<this->childCount(); ++i)
378 child=(
Task*)this->child(i);
385 kDebug(5970) <<
"Entering function";
387 mSessionTime=minutes;
388 mTotalSessionTime+=minutes;
389 kDebug(5970) <<
"Leaving function";
395 kDebug(5970) <<
"Entering function";
396 kDebug() <<
"Task's sessionStartTiMe is " << mSessionStartTiMe;
397 if( minutesSession != 0 || minutes != 0)
399 mSessionTime += minutesSession;
404 kDebug(5970) <<
"Leaving function";
415 <<
"Task::changeTotalTimes(" << minutesSession <<
","
416 << minutes <<
") for" <<
name();
417 mTotalSessionTime += minutesSession;
418 mTotalTime += minutes;
421 kDebug(5970) <<
"Leaving function";
426 kDebug(5970) <<
"Entering function";
427 mTotalSessionTime -= mSessionTime;
433 kDebug(5970) <<
"Leaving function";
446 kDebug(5970) <<
"entering function" << mName;
453 for (
int i = 0; i < childCount(); ++i )
455 Task *task =
static_cast< Task*
>( child( i ) );
468 mCurrentPic = (mCurrentPic+1) % 8;
469 setIcon(1, *(*icons)[mCurrentPic]);
480 KCalCore::Todo::Ptr
Task::asTodo(
const KCalCore::Todo::Ptr &todo)
const
482 Q_ASSERT( todo != NULL );
484 kDebug(5970) <<
"Task::asTodo: name() = '" <<
name() <<
"'";
485 todo->setSummary(
name() );
493 todo->setCustomProperty( KGlobal::mainComponent().componentName().toUtf8(),
494 QByteArray(
"totalTaskTime" ), QString::number( mTime ) );
495 todo->setCustomProperty( KGlobal::mainComponent().componentName().toUtf8(),
496 QByteArray(
"totalSessionTime" ), QString::number( mSessionTime) );
497 todo->setCustomProperty( KGlobal::mainComponent().componentName().toUtf8(),
498 QByteArray(
"sessionStartTiMe" ), mSessionStartTiMe.toString() );
499 kDebug() <<
"mSessionStartTiMe=" << mSessionStartTiMe.toString() ;
502 todo->removeCustomProperty(KGlobal::mainComponent().componentName().toUtf8(), QByteArray(
"desktopList"));
504 todo->setCustomProperty( KGlobal::mainComponent().componentName().toUtf8(),
508 todo->setPercentComplete(mPercentComplete);
509 todo->setPriority( mPriority );
514 long& sessionMinutes, QString& sessionStartTiMe, QString& name, QString& description,
DesktopList& desktops,
515 int& percent_complete,
int& priority )
517 kDebug(5970) <<
"Entering function";
519 name = incident->summary();
520 description = incident->description();
521 mUid = incident->uid();
522 mComment = incident->description();
527 incident->customProperty( KGlobal::mainComponent().componentName().toUtf8(),
528 QByteArray(
"totalTaskTime" )) == QString::null && incident->customProperty(
"karm",
529 QByteArray(
"totalTaskTime" )) != QString::null )
530 incident->setCustomProperty(
531 KGlobal::mainComponent().componentName().toUtf8(),
532 QByteArray(
"totalTaskTime" ), incident->customProperty(
"karm",
533 QByteArray(
"totalTaskTime" )));
534 minutes = incident->customProperty( KGlobal::mainComponent().componentName().toUtf8(),
535 QByteArray(
"totalTaskTime" )).toInt( &ok );
542 incident->customProperty( KGlobal::mainComponent().componentName().toUtf8(),
543 QByteArray(
"totalSessionTime" )) == QString::null && incident->customProperty(
"karm",
544 QByteArray(
"totalSessionTime" )) != QString::null )
545 incident->setCustomProperty(
546 KGlobal::mainComponent().componentName().toUtf8(),
547 QByteArray(
"totalSessionTime" ), incident->customProperty(
"karm",
548 QByteArray(
"totalSessionTime" )));
549 sessionMinutes = incident->customProperty( KGlobal::mainComponent().componentName().toUtf8(),
550 QByteArray(
"totalSessionTime" )).toInt( &ok );
553 sessionStartTiMe=incident->customProperty( KGlobal::mainComponent().componentName().toUtf8(), QByteArray(
"sessionStartTiMe" ));
557 incident->customProperty( KGlobal::mainComponent().componentName().toUtf8(),
558 QByteArray(
"desktopList" )) == QString::null && incident->customProperty(
"karm",
559 QByteArray(
"desktopList" )) != QString::null )
560 incident->setCustomProperty(
561 KGlobal::mainComponent().componentName().toUtf8(),
562 QByteArray(
"desktopList" ), incident->customProperty(
"karm",
563 QByteArray(
"desktopList" )));
565 QString desktopList = incident->customProperty( KGlobal::mainComponent().componentName().toUtf8(),
566 QByteArray(
"desktopList" ) );
567 QStringList desktopStrList = desktopList.split( QString::fromLatin1(
","),
568 QString::SkipEmptyParts );
571 for ( QStringList::iterator iter = desktopStrList.begin();
572 iter != desktopStrList.end();
575 int desktopInt = (*iter).toInt( &ok );
578 desktops.push_back( desktopInt );
581 percent_complete = incident.staticCast<KCalCore::Todo>()->
percentComplete();
582 priority = incident->priority();
588 if ( mDesktops.empty() )
592 for ( DesktopList::const_iterator iter = mDesktops.begin();
593 iter != mDesktops.end();
596 desktopstr += QString::number( *iter ) + QString::fromLatin1(
"," );
598 desktopstr.remove( desktopstr.length() - 1, 1 );
605 kDebug(5970) <<
"Entering function";
608 treeWidget()->takeTopLevelItem(treeWidget()->indexOfTopLevelItem(
this));
610 parent()->takeChild(indexOfChild(
this));
611 kDebug(5970) <<
"Leaving function";
617 kDebug(5970) <<
"Entering function";
618 destination->QTreeWidgetItem::insertChild(0,
this);
620 kDebug(5970) <<
"Leaving function";
626 kDebug(5970) <<
"Entering function";
629 kDebug(5970) <<
"Leaving function";
635 kDebug( 5970 ) <<
"Entering function";
640 setText( 3,
formatTime( mTotalSessionTime, b ) );
642 setText( 5, mPriority > 0 ? QString::number( mPriority ) :
"--" );
643 setText( 6, QString::number( mPercentComplete ) );
644 kDebug( 5970 ) <<
"Leaving function";
649 mComment = mComment + QString::fromLatin1(
"\n") +
comment;
656 mSessionStartTiMe=KDateTime::currentLocalDateTime();
672 return mPercentComplete;
697 return mSessionStartTiMe;
void setPercentComplete(const int percent, timetrackerstorage *storage)
Update percent complete for this task.
Task(const QString &taskname, const QString &taskdescription, long minutes, long sessionTime, DesktopList desktops, TaskView *parent=0, bool konsolemode=false)
TaskView * taskView() const
Return task view for this task.
void startTimer(const Task *task, const KDateTime &when=KDateTime::currentLocalDateTime())
Log the event that a timer has started for a task.
void setName(const Task *task, const QString &oldname)
Log a change to a task name.
bool parseIncidence(const KCalCore::Incidence::Ptr &, long &minutes, long &sessionMinutes, QString &sessionStartTiMe, QString &name, QString &description, DesktopList &desktops, int &percent_complete, int &priority)
Parses an incidence.
QString name() const
returns the name of this task.
static bool decimalFormat()
Get decimalFormat.
void addComment(const Task *task, const QString &comment)
Log a new comment for this task.
void startNewSession()
sets session time to zero.
static QString userRealName()
Get userRealName.
KDateTime sessionStartTiMe() const
void updateActiveIcon()
animate the active icon
bool isRoot() const
tells you whether this task is the root of the task tree
void setRunning(bool on, timetrackerstorage *storage, const QDateTime &when=QDateTime::currentDateTime())
starts or stops a task
void update()
Update the display of the task (all columns) in the UI.
void changeParentTotalTimes(long minutesSession, long minutes)
QString formatTime(double minutes, bool decimal)
Format time for output.
void setTotalTime(long minutes)
Sets the total time, does not change the parent's total time.
void changeTotalTimes(long minutesSession, long minutes)
adds minutes to total and session time by adding an event
bool remove(timetrackerstorage *storage)
remove Task with all it's children
bool isComplete()
Return true if task is complete (percent complete equals 100).
QString setSessionTime(long minutes)
Sets the session time.
void totalTimesChanged(long minutesSession, long minutes)
void setName(const QString &name, timetrackerstorage *storage)
sets the name of the task
void resetTimes()
Reset all times to 0 and adjust parent task's totalTiMes.
QString setTime(long minutes)
Sets the time (not session time).
QString comment() const
Retrieve the entire comment for the task.
void changeTimes(long minutesSession, long minutes, timetrackerstorage *storage=0)
Add minutes to time and session time by adding an event, and write to storage.
void setTotalSessionTime(long minutes)
Sets the total session time, does not change the parent's total session time.
QString addTotalSessionTime(long minutes)
Adds minutes to the task's and its supertasks' total session time.
bool removeTask(Task *task)
Remove this task from iCalendar file.
QString uid() const
Return unique iCalendar Todo ID for this task.
void resumeRunning()
Resume the running state of a task.
bool isRunning() const
return the state of a task - if it's running or not
void stopTimerFor(Task *task)
void changeTime(const Task *task, const long deltaSeconds)
Log the change in a task's time.
QString addTime(long minutes)
Adds minutes to the time of the task and the total time of its supertasks.
QString addSessionTime(long minutes)
Adds minutes to the task's session time and its supertasks' total session time.
QString getDesktopStr() const
QString description() const
returns the description of this task.
void setDesktopList(DesktopList dl)
void addComment(const QString &comment, timetrackerstorage *storage)
Add a comment to this task.
void changeTime(long minutes, timetrackerstorage *storage)
Change task time.
QVector< int > DesktopList
int percentComplete() const
void setUid(const QString &uid)
Set unique id for the task.
QString addTotalTime(long minutes)
Adds minutes to the total time of the task and its supertasks.
void stopTimer(const Task *task, const QDateTime &when=QDateTime::currentDateTime())
Log the event that the timer has stopped for this task.
void cut()
cut Task out of parent Task or the TaskView
Task * parent() const
return parent Task or null in case of TaskView.
DesktopList desktops() const
QString recalculatetotalsessiontime()
A recursive function to calculate the total session time of a task.
void paste(Task *destination)
insert Task into the destination Task
void move(Task *destination)
cut Task out of parent Task or the TaskView and into the destination Task
void setPriority(int priority)
Update priority for this task.
QString fullName() const
Returns that task name, prefixed by parent tree up to root.
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.
KCalCore::Todo::Ptr asTodo(const KCalCore::Todo::Ptr &calendar) const
Load the todo passed in with this tasks info.
QString recalculatetotaltime()
A recursive function to calculate the total time of a task.
QDateTime startTime() const
Return time the task was started.
void deletingTask(Task *thisTask)
signal that we're about to delete a task
Class to store/retrieve KTimeTracker data to/from persistent storage.
void setDescription(const QString &description)
sets the description of the task