libkcal Library API Documentation

todo.cpp

00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include <kglobal.h>
00023 #include <klocale.h>
00024 #include <kdebug.h>
00025 
00026 #include "todo.h"
00027 
00028 using namespace KCal;
00029 
00030 Todo::Todo()
00031 {
00032   mHasDueDate = false;
00033   mHasStartDate = false;
00034 
00035   mHasCompletedDate = false;
00036   mPercentComplete = 0;
00037 }
00038 
00039 Todo::Todo(const Todo &t) : Incidence(t)
00040 {
00041   mDtDue = t.mDtDue;
00042   mHasDueDate = t.mHasDueDate;
00043   mHasStartDate = t.mHasStartDate;
00044   mCompleted = t.mCompleted;
00045   mHasCompletedDate = t.mHasCompletedDate;
00046   mPercentComplete = t.mPercentComplete;
00047   mDtRecurrence = t.mDtRecurrence;
00048 }
00049 
00050 Todo::~Todo()
00051 {
00052 }
00053 
00054 Todo *Todo::clone()
00055 {
00056   return new Todo( *this );
00057 }
00058 
00059 
00060 bool Todo::operator==( const Todo& t2 ) const
00061 {
00062     return
00063         static_cast<const Incidence&>(*this) == static_cast<const Incidence&>(t2) &&
00064         dtDue() == t2.dtDue() &&
00065         hasDueDate() == t2.hasDueDate() &&
00066         hasStartDate() == t2.hasStartDate() &&
00067         completed() == t2.completed() &&
00068         hasCompletedDate() == t2.hasCompletedDate() &&
00069         percentComplete() == t2.percentComplete();
00070 }
00071 
00072 void Todo::setDtDue(const QDateTime &dtDue, bool first )
00073 {
00074   //int diffsecs = mDtDue.secsTo(dtDue);
00075 
00076   /*if (mReadOnly) return;
00077   const Alarm::List& alarms = alarms();
00078   for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
00079     if (alarm->enabled()) {
00080       alarm->setTime(alarm->time().addSecs(diffsecs));
00081     }
00082   }*/
00083   if( doesRecur() && !first ) {
00084     mDtRecurrence = dtDue;
00085   } else {
00086     mDtDue = dtDue;
00087     recurrence()->setRecurStart( dtDue );
00088   }
00089 
00090   if ( doesRecur() && dtDue < recurrence()->recurStart() )
00091     setDtStart( dtDue );
00092 
00093   //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
00094 
00095   /*const Alarm::List& alarms = alarms();
00096   for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
00097     alarm->setAlarmStart(mDtDue);*/
00098 
00099   updated();
00100 }
00101 
00102 QDateTime Todo::dtDue( bool first ) const
00103 {
00104   if ( doesRecur() && !first && mDtRecurrence.isValid() )
00105     return mDtRecurrence;
00106 
00107   return mDtDue;
00108 }
00109 
00110 QString Todo::dtDueTimeStr() const
00111 {
00112   return KGlobal::locale()->formatTime( dtDue(!doesRecur()).time() );
00113 }
00114 
00115 QString Todo::dtDueDateStr(bool shortfmt) const
00116 {
00117   return KGlobal::locale()->formatDate(dtDue( !doesRecur() ).date(),shortfmt);
00118 }
00119 
00120 QString Todo::dtDueStr() const
00121 {
00122   return KGlobal::locale()->formatDateTime( dtDue( !doesRecur() ) );
00123 }
00124 
00125 bool Todo::hasDueDate() const
00126 {
00127   return mHasDueDate;
00128 }
00129 
00130 void Todo::setHasDueDate(bool f)
00131 {
00132   if (mReadOnly) return;
00133   mHasDueDate = f;
00134   updated();
00135 }
00136 
00137 
00138 bool Todo::hasStartDate() const
00139 {
00140   return mHasStartDate;
00141 }
00142 
00143 void Todo::setHasStartDate(bool f)
00144 {
00145   if (mReadOnly) return;
00146 
00147   if ( doesRecur() && !f ) {
00148     if ( !comments().grep("NoStartDate").count() )
00149       addComment("NoStartDate");
00150   } else {
00151     QString s("NoStartDate");
00152     removeComment(s);
00153   }
00154   mHasStartDate = f;
00155   updated();
00156 }
00157 
00158 QDateTime Todo::dtStart( bool first ) const
00159 {
00160   if ( doesRecur() && !first )
00161     return mDtRecurrence.addDays( dtDue( true ).daysTo( IncidenceBase::dtStart() ) );
00162   else
00163     return IncidenceBase::dtStart();
00164 }
00165 
00166 void Todo::setDtStart( const QDateTime &dtStart )
00167 {
00168   if ( doesRecur() )
00169     recurrence()->setRecurStart( mDtDue );
00170   IncidenceBase::setDtStart( dtStart );
00171 }
00172 
00173 QString Todo::dtStartTimeStr( bool first ) const
00174 {
00175   return KGlobal::locale()->formatTime(dtStart(first).time());
00176 }
00177 
00178 QString Todo::dtStartDateStr(bool shortfmt, bool first) const
00179 {
00180   return KGlobal::locale()->formatDate(dtStart(first).date(),shortfmt);
00181 }
00182 
00183 QString Todo::dtStartStr(bool first) const
00184 {
00185   return KGlobal::locale()->formatDateTime(dtStart(first));
00186 }
00187 
00188 bool Todo::isCompleted() const
00189 {
00190   if (mPercentComplete == 100) return true;
00191   else return false;
00192 }
00193 
00194 void Todo::setCompleted(bool completed)
00195 {
00196   if (completed) mPercentComplete = 100;
00197   else mPercentComplete = 0;
00198   updated();
00199 }
00200 
00201 QDateTime Todo::completed() const
00202 {
00203   return mCompleted;
00204 }
00205 
00206 QString Todo::completedStr() const
00207 {
00208   return KGlobal::locale()->formatDateTime(mCompleted);
00209 }
00210 
00211 void Todo::setCompleted(const QDateTime &completed)
00212 {
00213   mHasCompletedDate = true;
00214   mPercentComplete = 100;
00215   mCompleted = completed;
00216   updated();
00217 }
00218 
00219 bool Todo::hasCompletedDate() const
00220 {
00221   return mHasCompletedDate;
00222 }
00223 
00224 int Todo::percentComplete() const
00225 {
00226   return mPercentComplete;
00227 }
00228 
00229 void Todo::setPercentComplete(int v)
00230 {
00231   mPercentComplete = v;
00232   updated();
00233 }
00234 
00235 void Todo::setDtRecurrence( const QDateTime &dt )
00236 {
00237   mDtRecurrence = dt;
00238 }
00239 
00240 QDateTime Todo::dtRecurrence() const
00241 {
00242   if ( !mDtRecurrence.isValid() )
00243     return mDtDue;
00244 
00245   return mDtRecurrence;
00246 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 4 14:39:39 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003