25 #include <tqdatetime.h>
26 #include <tqpaintdevicemetrics.h>
27 #include <tqpainter.h>
30 #include <tdeglobal.h>
32 #include <tdelocale.h>
35 #include "karmutility.h"
41 const int taskWidth = 40;
42 const int timeWidth = 6;
43 const int totalTimeWidth = 7;
44 const int reportWidth = taskWidth + timeWidth;
46 const TQString cr = TQString::fromLatin1(
"\n");
51 kdDebug(5970) <<
"Entering TimeKard::totalsAsText" << endl;
57 line.fill(
'-', reportWidth);
61 retval += i18n(
"Task Totals") + cr;
62 retval += TDEGlobal::locale()->formatDateTime(TQDateTime::currentDateTime());
64 retval += TQString(TQString::fromLatin1(
"%1 %2"))
65 .arg(i18n(
"Time"), timeWidth)
83 task= task->nextSibling())
85 kdDebug(5970) <<
"Copying task " << task->name() << endl;
86 int time = which == TotalTime ? task->totalTime() : task->totalSessionTime();
88 if ( time || task->firstChild() )
89 printTask(task, retval, 0, which);
94 buf.fill(
'-', reportWidth);
95 retval += TQString(TQString::fromLatin1(
"%1")).arg(buf, timeWidth) + cr;
96 retval += TQString(TQString::fromLatin1(
"%1 %2"))
97 .arg(formatTime(sum),timeWidth)
101 retval += i18n(
"No tasks.");
107 void TimeKard::printTask(
Task *task, TQString &s,
int level, WhichTime which)
111 s += buf.fill(
' ', level);
112 s += TQString(TQString::fromLatin1(
"%1 %2"))
113 .arg(formatTime(which == TotalTime?task->totalTime():task->totalSessionTime()), timeWidth)
119 subTask = subTask->nextSibling())
121 int time = which == TotalTime ? subTask->totalTime() : subTask->totalSessionTime();
123 printTask(subTask, s, level+1, which);
127 void TimeKard::printTaskHistory(
const Task *task,
128 const TQMap<TQString,long>& taskdaytotals,
129 TQMap<TQString,long>& daytotals,
132 const int level, TQString& s,
bool totalsOnly)
135 for ( TQDate day = from; day <= to; day = day.addDays(1) )
137 TQString daykey = day.toString(TQString::fromLatin1(
"yyyyMMdd"));
138 TQString daytaskkey = TQString::fromLatin1(
"%1_%2")
142 if (taskdaytotals.contains(daytaskkey))
146 s += TQString::fromLatin1(
"%1")
147 .arg(formatTime(taskdaytotals[daytaskkey]/60), timeWidth);
149 sectionsum += taskdaytotals[daytaskkey];
151 if (daytotals.contains(daykey))
152 daytotals.replace(daykey, daytotals[daykey] + taskdaytotals[daytaskkey]);
154 daytotals.insert(daykey, taskdaytotals[daytaskkey]);
156 else if ( !totalsOnly )
159 buf.fill(
' ', timeWidth);
165 s += TQString::fromLatin1(
"%1").arg(formatTime(sectionsum/60), totalTimeWidth);
169 s += buf.fill(
' ', level + 1);
170 s += TQString::fromLatin1(
"%1").arg(task->
name());
175 subTask = subTask->nextSibling())
178 printTaskHistory(subTask, taskdaytotals, daytotals, from, to, level+1, s, totalsOnly);
182 TQString TimeKard::sectionHistoryAsText(
184 const TQDate& sectionFrom,
const TQDate& sectionTo,
185 const TQDate& from,
const TQDate& to,
186 const TQString& name,
187 bool justThisTask,
bool totalsOnly)
190 const int sectionReportWidth = taskWidth + ( totalsOnly ? 0 : sectionFrom.daysTo(sectionTo) * timeWidth ) + totalTimeWidth;
191 assert( sectionReportWidth > 0 );
193 line.fill(
'-', sectionReportWidth);
196 TQValueList<HistoryEvent> events;
197 if ( sectionFrom < from && sectionTo > to)
201 else if ( sectionFrom < from )
203 events = taskview->
getHistory(from, sectionTo);
205 else if ( sectionTo > to)
207 events = taskview->
getHistory(sectionFrom, to);
211 events = taskview->
getHistory(sectionFrom, sectionTo);
214 TQMap<TQString, long> taskdaytotals;
215 TQMap<TQString, long> daytotals;
222 for (TQValueList<HistoryEvent>::iterator event = events.begin(); event != events.end(); ++event)
224 TQString daykey = (*event).start().date().toString(TQString::fromLatin1(
"yyyyMMdd"));
225 TQString daytaskkey = TQString::fromLatin1(
"%1_%2")
227 .arg((*event).todoUid());
229 if (taskdaytotals.contains(daytaskkey))
230 taskdaytotals.replace(daytaskkey,
231 taskdaytotals[daytaskkey] + (*event).duration());
233 taskdaytotals.insert(daytaskkey, (*event).duration());
240 if ( name.length() < (
unsigned int)sectionReportWidth )
241 buf.fill(
' ',
int((sectionReportWidth - name.length()) / 2));
242 retval += buf + name + cr;
247 for (TQDate day = sectionFrom; day <= sectionTo; day = day.addDays(1))
249 retval += TQString::fromLatin1(
"%1").arg(day.day(), timeWidth);
259 retval += i18n(
"No hours logged.");
265 printTaskHistory(taskview->
current_item(), taskdaytotals, daytotals,
266 sectionFrom, sectionTo, 0, retval, totalsOnly);
271 task= task->nextSibling())
273 printTaskHistory(task, taskdaytotals, daytotals,
274 sectionFrom, sectionTo, 0, retval, totalsOnly);
281 for (TQDate day = sectionFrom; day <= sectionTo; day = day.addDays(1))
283 TQString daykey = day.toString(TQString::fromLatin1(
"yyyyMMdd"));
285 if (daytotals.contains(daykey))
289 retval += TQString::fromLatin1(
"%1")
290 .arg(formatTime(daytotals[daykey]/60), timeWidth);
292 sum += daytotals[daykey];
294 else if ( !totalsOnly )
296 buf.fill(
' ', timeWidth);
301 retval += TQString::fromLatin1(
"%1 %2")
302 .arg(formatTime(sum/60), totalTimeWidth)
309 const TQDate& to,
bool justThisTask,
bool perWeek,
bool totalsOnly)
313 retval += totalsOnly ? i18n(
"Task Totals") : i18n(
"Task History");
315 retval += i18n(
"From %1 to %2")
316 .arg(TDEGlobal::locale()->formatDate(from))
317 .arg(TDEGlobal::locale()->formatDate(to));
319 retval += i18n(
"Printed on: %1")
320 .arg(TDEGlobal::locale()->formatDateTime(TQDateTime::currentDateTime()));
326 for (TQValueList<Week>::iterator week = weeks.begin(); week != weeks.end(); ++week)
328 retval += sectionHistoryAsText( taskview, (*week).start(), (*week).end(), from, to, (*week).name(), justThisTask, totalsOnly );
332 retval += sectionHistoryAsText( taskview, from, to, from, to,
"", justThisTask, totalsOnly );
344 TQDate Week::start()
const
349 TQDate Week::end()
const
351 return _start.addDays(6);
356 return i18n(
"Week of %1").arg(TDEGlobal::locale()->formatDate(start()));
362 TQValueList<Week> weeks;
374 start = from.addDays(
375 -((7 - TDEGlobal::locale()->weekStartDay() + from.dayOfWeek()) % 7));
377 for (TQDate d = start; d <= to; d = d.addDays(7))
378 weeks.append(
Week(d));
Container and interface for the tasks.
Task * current_item() const
Return the current item in the view, cast to a Task pointer.
Task * item_at_index(int i)
Return the i'th item (zero-based), cast to a Task pointer.
TQValueList< HistoryEvent > getHistory(const TQDate &from, const TQDate &to) const
Return list of start/stop events for given date range.
A class representing a task.
TQString name() const
returns the name of this task.
Task * firstChild() const
return parent Task or null in case of TaskView.
TQString uid() const
Return unique iCalendar Todo ID for this task.
TQString totalsAsText(TaskView *taskview, bool justThisTask, WhichTime which)
Generates ascii text of task totals, for current task on down.
TQString historyAsText(TaskView *taskview, const TQDate &from, const TQDate &to, bool justThisTask, bool perWeek, bool totalsOnly)
Generates ascii text of weekly task history, for current task on down.
TQString name() const
Return the name of the week.
Week()
Need an empty constructor to use in a TQValueList.
static TQValueList< Week > weeksFromDateRange(const TQDate &from, const TQDate &to)
Returns a list of weeks for the given date range.