• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

ktimetracker

timekard.cpp

Go to the documentation of this file.
00001 /*
00002  *     Copyright (C) 2003 by Mark Bucciarelli <mark@hubcapconsutling.com>
00003  *                   2007 the ktimetracker developers
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License along
00016  *   with this program; if not, write to the
00017  *      Free Software Foundation, Inc.
00018  *      51 Franklin Street, Fifth Floor
00019  *      Boston, MA  02110-1301  USA.
00020  *
00021  */
00022 
00023 #include "timekard.h"
00024 
00025 #include <cassert>
00026 
00027 #include <QDateTime>
00028 #include <QList>
00029 #include <QMap>
00030 
00031 #include <KDebug>
00032 #include <KGlobal>
00033 #include <KLocale>
00034 
00035 #include <kcal/event.h>
00036 
00037 #include "karmstorage.h"
00038 #include "ktimetrackerutility.h"        // formatTime()
00039 #include "task.h"
00040 #include "taskview.h"
00041 
00042 const int taskWidth = 40;
00043 const int timeWidth = 6;
00044 const int totalTimeWidth = 7;
00045 const int reportWidth = taskWidth + timeWidth;
00046 
00047 const QString cr = QString::fromLatin1("\n");
00048 
00049 QString TimeKard::totalsAsText(TaskView* taskview, ReportCriteria rc)
00050 {
00051   kDebug(5970) << "Entering function";
00052   QString retval;
00053   QString line;
00054   QString buf;
00055   long sum;
00056   bool justThisTask=!rc.allTasks;
00057 
00058   line.fill('-', reportWidth);
00059   line += cr;
00060 
00061   // header
00062   retval += i18n("Task Totals") + cr;
00063   retval += KGlobal::locale()->formatDateTime(QDateTime::currentDateTime());
00064   retval += cr + cr;
00065   retval += QString(QString::fromLatin1("%1    %2"))
00066     .arg(i18n("Time"), timeWidth)
00067     .arg(i18n("Task"));
00068   retval += cr;
00069   retval += line;
00070 
00071   // tasks
00072   if (taskview->currentItem())
00073   {
00074     if (justThisTask)
00075     {
00076       if (!rc.sessionTimes) sum = taskview->currentItem()->totalTime();
00077       else sum = taskview->currentItem()->totalSessionTime();
00078       printTask(taskview->currentItem(), retval, 0, rc);
00079     }
00080     else // print all tasks
00081     {
00082       sum = 0;
00083       for ( int i = 0; i < taskview->topLevelItemCount(); ++i ) {
00084         Task *task = static_cast< Task* >( taskview->topLevelItem( i ) );
00085         if (!rc.sessionTimes) sum += task->totalTime();
00086         else sum += task->totalSessionTime();
00087         if ( (task->totalTime() && (!rc.sessionTimes)) || (task->totalSessionTime() && rc.sessionTimes) )
00088           printTask(task, retval, 0, rc);
00089       }
00090     }
00091 
00092     // total
00093     buf.fill('-', reportWidth);
00094     retval += QString(QString::fromLatin1("%1")).arg(buf, timeWidth) + cr;
00095     retval += QString(QString::fromLatin1("%1 %2"))
00096       .arg(formatTime(sum),timeWidth)
00097       .arg(i18nc( "total time of all tasks", "Total" ));
00098   }
00099   else
00100     retval += i18n("No tasks.");
00101 
00102   return retval;
00103 }
00104 
00105 // Print out "<indent for level> <task total> <task>", for task and subtasks. Used by totalsAsText.
00106 void TimeKard::printTask(Task *task, QString &s, int level, const ReportCriteria &rc)
00107 {
00108   kDebug(5970) << "Entering function";
00109   QString buf;
00110 
00111   s += buf.fill(' ', level);
00112   if (!rc.sessionTimes)
00113   {
00114     s += QString(QString::fromLatin1("%1    %2"))
00115       .arg(formatTime(task->totalTime()), timeWidth)
00116       .arg(task->name());
00117   }
00118   else // print session times
00119   {
00120     s += QString(QString::fromLatin1("%1    %2"))
00121       .arg(formatTime(task->totalSessionTime()), timeWidth)
00122       .arg(task->name());
00123   }
00124   s += cr;
00125 
00126   for ( int i = 0; i < task->childCount(); ++i ) {
00127     Task *subTask = static_cast< Task* >( task->child( i ) );
00128     if ( !rc.sessionTimes )
00129     {
00130       if ( subTask->totalTime() ) // to avoid 00:00 entries
00131         printTask(subTask, s, level+1, rc);
00132     }
00133     else
00134     {
00135       if ( subTask->totalSessionTime() ) // to avoid 00:00 entries
00136         printTask(subTask, s, level+1, rc);
00137     }
00138   }
00139 }
00140 
00141 Week::Week() {}
00142 
00143 Week::Week( const QDate &from )
00144 {
00145   _start = from;
00146 }
00147 
00148 QDate Week::start() const
00149 {
00150   return _start;
00151 }
00152 
00153 QDate Week::end() const
00154 {
00155   return _start.addDays(6);
00156 }
00157 
00158 QString Week::name() const
00159 {
00160   return i18n("Week of %1", KGlobal::locale()->formatDate(start()));
00161 }
00162 
00163 QList<Week> Week::weeksFromDateRange(const QDate& from, const QDate& to)
00164 {
00165   QDate start;
00166   QList<Week> weeks;
00167 
00168   // The QDate weekNumber() method always puts monday as the first day of the
00169   // week.
00170   //
00171   // Not that it matters here, but week 1 always includes the first Thursday
00172   // of the year.  For example, January 1, 2000 was a Saturday, so
00173   // QDate(2000,1,1).weekNumber() returns 52.
00174 
00175   // Since report always shows a full week, we generate a full week of dates,
00176   // even if from and to are the same date.  The week starts on the day
00177   // that is set in the locale settings.
00178   start = from.addDays(
00179       -((7 - KGlobal::locale()->weekStartDay() + from.dayOfWeek()) % 7));
00180 
00181   for (QDate d = start; d <= to; d = d.addDays(7))
00182     weeks.append(Week(d));
00183 
00184   return weeks;
00185 }
00186 

ktimetracker

Skip menu "ktimetracker"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal