libkcal Library API Documentation

incidence.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 "calformat.h"
00026 
00027 #include "incidence.h"
00028 
00029 using namespace KCal;
00030 
00031 Incidence::Incidence() :
00032   IncidenceBase(),
00033   mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
00034 {
00035   mRecurrence = new Recurrence(this);
00036 
00037   recreate();
00038 
00039   mAlarms.setAutoDelete(true);
00040 }
00041 
00042 Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
00043 {
00044 // TODO: reenable attributes currently commented out.
00045   mRevision = i.mRevision;
00046   mCreated = i.mCreated;
00047   mDescription = i.mDescription;
00048   mSummary = i.mSummary;
00049   mCategories = i.mCategories;
00050 //  Incidence *mRelatedTo;          Incidence *mRelatedTo;
00051   mRelatedTo = 0;
00052   mRelatedToUid = i.mRelatedToUid;
00053 //  QPtrList<Incidence> mRelations;    QPtrList<Incidence> mRelations;
00054   mExDates = i.mExDates;
00055   mAttachments = i.mAttachments;
00056   mResources = i.mResources;
00057   mSecrecy = i.mSecrecy;
00058   mPriority = i.mPriority;
00059   mLocation = i.mLocation;
00060 
00061   QPtrListIterator<Alarm> it( i.mAlarms );
00062   const Alarm *a;
00063   while( (a = it.current()) ) {
00064     Alarm *b = new Alarm( *a );
00065     b->setParent( this );
00066     mAlarms.append( b );
00067 
00068     ++it;
00069   }
00070   mAlarms.setAutoDelete(true);
00071 
00072   mRecurrence = new Recurrence( *(i.mRecurrence), this );
00073 }
00074 
00075 Incidence::~Incidence()
00076 {
00077   Incidence *ev;
00078   for (ev=mRelations.first();ev;ev=mRelations.next()) {
00079     if (ev->relatedTo() == this) ev->setRelatedTo(0);
00080   }
00081   if (relatedTo()) relatedTo()->removeRelation(this);
00082 
00083   delete mRecurrence;
00084 }
00085 
00086 void Incidence::recreate()
00087 {
00088   setCreated(QDateTime::currentDateTime());
00089 
00090   setUid(CalFormat::createUniqueId());
00091 
00092   setRevision(0);
00093 
00094   setLastModified(QDateTime::currentDateTime());
00095 }
00096 
00097 void Incidence::setReadOnly( bool readOnly )
00098 {
00099   IncidenceBase::setReadOnly( readOnly );
00100   recurrence()->setRecurReadOnly( readOnly);
00101 }
00102 
00103 void Incidence::setCreated(QDateTime created)
00104 {
00105   if (mReadOnly) return;
00106   mCreated = created;
00107 }
00108 
00109 QDateTime Incidence::created() const
00110 {
00111   return mCreated;
00112 }
00113 
00114 void Incidence::setRevision(int rev)
00115 {
00116   if (mReadOnly) return;
00117   mRevision = rev;
00118   
00119   updated();
00120 }
00121 
00122 int Incidence::revision() const
00123 {
00124   return mRevision;
00125 }
00126 
00127 void Incidence::setDtStart(const QDateTime &dtStart)
00128 {
00129   recurrence()->setRecurStart( dtStart);
00130   IncidenceBase::setDtStart( dtStart );
00131 }
00132 
00133 void Incidence::setDescription(const QString &description)
00134 {
00135   if (mReadOnly) return;
00136   mDescription = description;
00137   updated();
00138 }
00139 
00140 QString Incidence::description() const
00141 {
00142   return mDescription;
00143 }
00144 
00145 
00146 void Incidence::setSummary(const QString &summary)
00147 {
00148   if (mReadOnly) return;
00149   mSummary = summary;
00150   updated();
00151 }
00152 
00153 QString Incidence::summary() const
00154 {
00155   return mSummary;
00156 }
00157 
00158 void Incidence::setCategories(const QStringList &categories)
00159 {
00160   if (mReadOnly) return;
00161   mCategories = categories;
00162   updated();
00163 }
00164 
00165 // TODO: remove setCategories(QString) function
00166 void Incidence::setCategories(const QString &catStr)
00167 {
00168   if (mReadOnly) return;
00169   mCategories.clear();
00170 
00171   if (catStr.isEmpty()) return;
00172 
00173   mCategories = QStringList::split(",",catStr);
00174 
00175   QStringList::Iterator it;
00176   for(it = mCategories.begin();it != mCategories.end(); ++it) {
00177     *it = (*it).stripWhiteSpace();
00178   }
00179 
00180   updated();
00181 }
00182 
00183 QStringList Incidence::categories() const
00184 {
00185   return mCategories;
00186 }
00187 
00188 QString Incidence::categoriesStr()
00189 {
00190   return mCategories.join(",");
00191 }
00192 
00193 void Incidence::setRelatedToUid(const QString &relatedToUid)
00194 {
00195   if (mReadOnly) return;
00196   mRelatedToUid = relatedToUid;
00197 }
00198 
00199 QString Incidence::relatedToUid() const
00200 {
00201   return mRelatedToUid;
00202 }
00203 
00204 void Incidence::setRelatedTo(Incidence *relatedTo)
00205 {
00206   if (mReadOnly) return;
00207   Incidence *oldRelatedTo = mRelatedTo;
00208   if(oldRelatedTo) {
00209     oldRelatedTo->removeRelation(this);
00210   }
00211   mRelatedTo = relatedTo;
00212   if (mRelatedTo) mRelatedTo->addRelation(this);
00213 }
00214 
00215 Incidence *Incidence::relatedTo() const
00216 {
00217   return mRelatedTo;
00218 }
00219 
00220 QPtrList<Incidence> Incidence::relations() const
00221 {
00222   return mRelations;
00223 }
00224 
00225 void Incidence::addRelation(Incidence *event)
00226 {
00227   mRelations.append(event);
00228   updated();
00229 }
00230 
00231 void Incidence::removeRelation(Incidence *event)
00232 {
00233   mRelations.removeRef(event);
00234 //  if (event->getRelatedTo() == this) event->setRelatedTo(0);
00235 }
00236 
00237 bool Incidence::recursOn(const QDate &qd) const
00238 {
00239   if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
00240   else return false;
00241 }
00242 
00243 void Incidence::setExDates(const DateList &exDates)
00244 {
00245   if (mReadOnly) return;
00246   mExDates = exDates;
00247 
00248   recurrence()->setRecurExDatesCount(mExDates.count());
00249 
00250   updated();
00251 }
00252 
00253 void Incidence::addExDate(const QDate &date)
00254 {
00255   if (mReadOnly) return;
00256   mExDates.append(date);
00257 
00258   recurrence()->setRecurExDatesCount(mExDates.count());
00259 
00260   updated();
00261 }
00262 
00263 DateList Incidence::exDates() const
00264 {
00265   return mExDates;
00266 }
00267 
00268 bool Incidence::isException(const QDate &date) const
00269 {
00270   DateList::ConstIterator it;
00271   for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
00272     if ( (*it) == date ) {
00273       return true;
00274     }
00275   }
00276 
00277   return false;
00278 }
00279 
00280 void Incidence::setAttachments(const QStringList &attachments)
00281 {
00282   if (mReadOnly) return;
00283   mAttachments = attachments;
00284   updated();
00285 }
00286 
00287 QStringList Incidence::attachments() const
00288 {
00289   return mAttachments;
00290 }
00291 
00292 void Incidence::setResources(const QStringList &resources)
00293 {
00294   if (mReadOnly) return;
00295   mResources = resources;
00296   updated();
00297 }
00298 
00299 QStringList Incidence::resources() const
00300 {
00301   return mResources;
00302 }
00303 
00304 
00305 void Incidence::setPriority(int priority)
00306 {
00307   if (mReadOnly) return;
00308   mPriority = priority;
00309   updated();
00310 }
00311 
00312 int Incidence::priority() const
00313 {
00314   return mPriority;
00315 }
00316 
00317 void Incidence::setSecrecy(int sec)
00318 {
00319   if (mReadOnly) return;
00320   mSecrecy = sec;
00321   updated();
00322 }
00323 
00324 int Incidence::secrecy() const
00325 {
00326   return mSecrecy;
00327 }
00328 
00329 QString Incidence::secrecyStr() const
00330 {
00331   return secrecyName(mSecrecy);
00332 }
00333 
00334 QString Incidence::secrecyName(int secrecy)
00335 {
00336   switch (secrecy) {
00337     case SecrecyPublic:
00338       return i18n("Public");
00339       break;
00340     case SecrecyPrivate:
00341       return i18n("Private");
00342       break;
00343     case SecrecyConfidential:
00344       return i18n("Confidential");
00345       break;
00346     default:
00347       return i18n("Undefined");
00348       break;
00349   }
00350 }
00351 
00352 QStringList Incidence::secrecyList()
00353 {
00354   QStringList list;
00355   list << secrecyName(SecrecyPublic);
00356   list << secrecyName(SecrecyPrivate);
00357   list << secrecyName(SecrecyConfidential);
00358 
00359   return list;
00360 }
00361 
00362 
00363 QPtrList<Alarm> Incidence::alarms() const
00364 {
00365   return mAlarms;
00366 }
00367 
00368 Alarm* Incidence::newAlarm()
00369 {
00370   Alarm* alarm = new Alarm(this);
00371   mAlarms.append(alarm);
00372 //  updated();
00373   return alarm;
00374 }
00375 
00376 void Incidence::addAlarm(Alarm *alarm)
00377 {
00378   mAlarms.append(alarm);
00379   updated();
00380 }
00381 
00382 void Incidence::removeAlarm(Alarm *alarm)
00383 {
00384   mAlarms.removeRef(alarm);
00385   updated();
00386 }
00387 
00388 void Incidence::clearAlarms()
00389 {
00390   mAlarms.clear();
00391   updated();
00392 }
00393 
00394 bool Incidence::isAlarmEnabled() const
00395 {
00396   Alarm* alarm;
00397   for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
00398     if (alarm->enabled())
00399       return true;
00400   }
00401   return false;
00402 }
00403 
00404 Recurrence *Incidence::recurrence() const
00405 {
00406   return mRecurrence;
00407 }
00408 
00409 void Incidence::setLocation(const QString &location)
00410 {
00411   if (mReadOnly) return;
00412   mLocation = location;
00413   updated();
00414 }
00415 
00416 QString Incidence::location() const
00417 {
00418   return mLocation;
00419 }
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