libkcal Library API Documentation

todo.cpp

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