2 * Copyright (C) 2003 by Mark Bucciarelli <mark@hubcapconsutling.com>
3 * 2007 the ktimetracker developers
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.
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.
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.
35 #include <kcal/event.h>
37 #include "karmstorage.h"
38 #include "ktimetrackerutility.h" // formatTime()
42 const int taskWidth
= 40;
43 const int timeWidth
= 6;
44 const int totalTimeWidth
= 7;
45 const int reportWidth
= taskWidth
+ timeWidth
;
47 const QString cr
= QString::fromLatin1("\n");
49 QString
TimeKard::totalsAsText(TaskView
* taskview
, ReportCriteria rc
)
51 kDebug(5970) << "Entering function";
56 bool justThisTask
=!rc
.allTasks
;
58 line
.fill('-', reportWidth
);
62 retval
+= i18n("Task Totals") + cr
;
63 retval
+= KGlobal::locale()->formatDateTime(QDateTime::currentDateTime());
65 retval
+= QString(QString::fromLatin1("%1 %2"))
66 .arg(i18n("Time"), timeWidth
)
72 if (taskview
->currentItem())
76 if (!rc
.sessionTimes
) sum
= taskview
->currentItem()->totalTime();
77 else sum
= taskview
->currentItem()->totalSessionTime();
78 printTask(taskview
->currentItem(), retval
, 0, rc
);
80 else // print all tasks
83 for ( int i
= 0; i
< taskview
->topLevelItemCount(); ++i
) {
84 Task
*task
= static_cast< Task
* >( taskview
->topLevelItem( i
) );
85 if (!rc
.sessionTimes
) sum
+= task
->totalTime();
86 else sum
+= task
->totalSessionTime();
87 if ( (task
->totalTime() && (!rc
.sessionTimes
)) || (task
->totalSessionTime() && rc
.sessionTimes
) )
88 printTask(task
, retval
, 0, rc
);
93 buf
.fill('-', reportWidth
);
94 retval
+= QString(QString::fromLatin1("%1")).arg(buf
, timeWidth
) + cr
;
95 retval
+= QString(QString::fromLatin1("%1 %2"))
96 .arg(formatTime(sum
),timeWidth
)
97 .arg(i18nc( "total time of all tasks", "Total" ));
100 retval
+= i18n("No tasks.");
105 // Print out "<indent for level> <task total> <task>", for task and subtasks. Used by totalsAsText.
106 void TimeKard::printTask(Task
*task
, QString
&s
, int level
, const ReportCriteria
&rc
)
108 kDebug(5970) << "Entering function";
111 s
+= buf
.fill(' ', level
);
112 if (!rc
.sessionTimes
)
114 s
+= QString(QString::fromLatin1("%1 %2"))
115 .arg(formatTime(task
->totalTime()), timeWidth
)
118 else // print session times
120 s
+= QString(QString::fromLatin1("%1 %2"))
121 .arg(formatTime(task
->totalSessionTime()), timeWidth
)
126 for ( int i
= 0; i
< task
->childCount(); ++i
) {
127 Task
*subTask
= static_cast< Task
* >( task
->child( i
) );
128 if ( !rc
.sessionTimes
)
130 if ( subTask
->totalTime() ) // to avoid 00:00 entries
131 printTask(subTask
, s
, level
+1, rc
);
135 if ( subTask
->totalSessionTime() ) // to avoid 00:00 entries
136 printTask(subTask
, s
, level
+1, rc
);
143 Week::Week( const QDate
&from
)
148 QDate
Week::start() const
153 QDate
Week::end() const
155 return _start
.addDays(6);
158 QString
Week::name() const
160 return i18n("Week of %1", KGlobal::locale()->formatDate(start()));
163 QList
<Week
> Week::weeksFromDateRange(const QDate
& from
, const QDate
& to
)
168 // The QDate weekNumber() method always puts monday as the first day of the
171 // Not that it matters here, but week 1 always includes the first Thursday
172 // of the year. For example, January 1, 2000 was a Saturday, so
173 // QDate(2000,1,1).weekNumber() returns 52.
175 // Since report always shows a full week, we generate a full week of dates,
176 // even if from and to are the same date. The week starts on the day
177 // that is set in the locale settings.
178 start
= from
.addDays(
179 -((7 - KGlobal::locale()->weekStartDay() + from
.dayOfWeek()) % 7));
181 for (QDate d
= start
; d
<= to
; d
= d
.addDays(7))
182 weeks
.append(Week(d
));