incidence.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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), mRecurrence(0)
00034 {
00035 recreate();
00036
00037 mAlarms.setAutoDelete(true);
00038 mAttachments.setAutoDelete(true);
00039 }
00040
00041 Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
00042 {
00043
00044 mRevision = i.mRevision;
00045 mCreated = i.mCreated;
00046 mDescription = i.mDescription;
00047 mSummary = i.mSummary;
00048 mCategories = i.mCategories;
00049
00050 mRelatedTo = 0;
00051 mRelatedToUid = i.mRelatedToUid;
00052
00053 mExDates = i.mExDates;
00054 mExDateTimes = i.mExDateTimes;
00055 mAttachments = i.mAttachments;
00056 mResources = i.mResources;
00057 mSecrecy = i.mSecrecy;
00058 mPriority = i.mPriority;
00059 mLocation = i.mLocation;
00060
00061 Alarm::List::ConstIterator it;
00062 for( it = i.mAlarms.begin(); it != i.mAlarms.end(); ++it ) {
00063 Alarm *b = new Alarm( **it );
00064 b->setParent( this );
00065 mAlarms.append( b );
00066 }
00067 mAlarms.setAutoDelete(true);
00068
00069 if (i.mRecurrence)
00070 mRecurrence = new Recurrence( *(i.mRecurrence), this );
00071 else
00072 mRecurrence = 0;
00073 }
00074
00075 Incidence::~Incidence()
00076 {
00077 List::ConstIterator it;
00078 for ( it = mRelations.begin(); it != mRelations.end(); ++it ) {
00079 if ( (*it)->relatedTo() == this ) (*it)->setRelatedTo( 0 );
00080 }
00081 if ( relatedTo() ) relatedTo()->removeRelation( this );
00082
00083 delete mRecurrence;
00084 }
00085
00086
00087 static bool stringCompare( const QString& s1, const QString& s2 )
00088 {
00089 if ( s1.isEmpty() && s2.isEmpty() )
00090 return true;
00091 return s1 == s2;
00092 }
00093
00094 bool Incidence::operator==( const Incidence& i2 ) const
00095 {
00096 if( alarms().count() != i2.alarms().count() ) {
00097 return false;
00098 }
00099
00100 Alarm::List::ConstIterator a1 = alarms().begin();
00101 Alarm::List::ConstIterator a2 = i2.alarms().begin();
00102 for( ; a1 != alarms().end() && a2 != i2.alarms().end(); ++a1, ++a2 )
00103 if( **a1 == **a2 )
00104 continue;
00105 else {
00106 return false;
00107 }
00108
00109 if ( !IncidenceBase::operator==(i2) )
00110 return false;
00111
00112 bool recurrenceEqual = ( mRecurrence == 0 && i2.mRecurrence == 0 );
00113 if ( !recurrenceEqual )
00114 {
00115 recurrenceEqual = mRecurrence != 0 &&
00116 i2.mRecurrence != 0 &&
00117 *mRecurrence == *i2.mRecurrence;
00118 }
00119
00120 return
00121 recurrenceEqual &&
00122 created() == i2.created() &&
00123 stringCompare( description(), i2.description() ) &&
00124 stringCompare( summary(), i2.summary() ) &&
00125 categories() == i2.categories() &&
00126
00127 stringCompare( relatedToUid(), i2.relatedToUid() ) &&
00128 relations() == i2.relations() &&
00129 exDates() == i2.exDates() &&
00130 exDateTimes() == i2.exDateTimes() &&
00131 attachments() == i2.attachments() &&
00132 resources() == i2.resources() &&
00133 secrecy() == i2.secrecy() &&
00134 priority() == i2.priority() &&
00135 stringCompare( location(), i2.location() );
00136 }
00137
00138
00139 void Incidence::recreate()
00140 {
00141 setCreated(QDateTime::currentDateTime());
00142
00143 setUid(CalFormat::createUniqueId());
00144
00145 setRevision(0);
00146
00147 setLastModified(QDateTime::currentDateTime());
00148 }
00149
00150 void Incidence::setReadOnly( bool readOnly )
00151 {
00152 IncidenceBase::setReadOnly( readOnly );
00153 if (mRecurrence)
00154 mRecurrence->setRecurReadOnly(readOnly);
00155 }
00156
00157 void Incidence::setCreated( const QDateTime &created )
00158 {
00159 if (mReadOnly) return;
00160 mCreated = created;
00161 }
00162
00163 QDateTime Incidence::created() const
00164 {
00165 return mCreated;
00166 }
00167
00168 void Incidence::setRevision( int rev )
00169 {
00170 if (mReadOnly) return;
00171 mRevision = rev;
00172
00173 updated();
00174 }
00175
00176 int Incidence::revision() const
00177 {
00178 return mRevision;
00179 }
00180
00181 void Incidence::setDtStart(const QDateTime &dtStart)
00182 {
00183 if (mRecurrence)
00184 mRecurrence->setRecurStart( dtStart);
00185 IncidenceBase::setDtStart( dtStart );
00186 }
00187
00188 void Incidence::setDescription(const QString &description)
00189 {
00190 if (mReadOnly) return;
00191 mDescription = description;
00192 updated();
00193 }
00194
00195 QString Incidence::description() const
00196 {
00197 return mDescription;
00198 }
00199
00200
00201 void Incidence::setSummary(const QString &summary)
00202 {
00203 if (mReadOnly) return;
00204 mSummary = summary;
00205 updated();
00206 }
00207
00208 QString Incidence::summary() const
00209 {
00210 return mSummary;
00211 }
00212
00213 void Incidence::setCategories(const QStringList &categories)
00214 {
00215 if (mReadOnly) return;
00216 mCategories = categories;
00217 updated();
00218 }
00219
00220
00221 void Incidence::setCategories(const QString &catStr)
00222 {
00223 if (mReadOnly) return;
00224 mCategories.clear();
00225
00226 if (catStr.isEmpty()) return;
00227
00228 mCategories = QStringList::split(",",catStr);
00229
00230 QStringList::Iterator it;
00231 for(it = mCategories.begin();it != mCategories.end(); ++it) {
00232 *it = (*it).stripWhiteSpace();
00233 }
00234
00235 updated();
00236 }
00237
00238 QStringList Incidence::categories() const
00239 {
00240 return mCategories;
00241 }
00242
00243 QString Incidence::categoriesStr()
00244 {
00245 return mCategories.join(",");
00246 }
00247
00248 void Incidence::setRelatedToUid(const QString &relatedToUid)
00249 {
00250 if (mReadOnly) return;
00251 mRelatedToUid = relatedToUid;
00252 }
00253
00254 QString Incidence::relatedToUid() const
00255 {
00256 return mRelatedToUid;
00257 }
00258
00259 void Incidence::setRelatedTo(Incidence *relatedTo)
00260 {
00261 if (mReadOnly || mRelatedTo == relatedTo) return;
00262 if(mRelatedTo)
00263 mRelatedTo->removeRelation(this);
00264 mRelatedTo = relatedTo;
00265 if (mRelatedTo) mRelatedTo->addRelation(this);
00266 }
00267
00268 Incidence *Incidence::relatedTo() const
00269 {
00270 return mRelatedTo;
00271 }
00272
00273 Incidence::List Incidence::relations() const
00274 {
00275 return mRelations;
00276 }
00277
00278 void Incidence::addRelation( Incidence *event )
00279 {
00280 if ( mRelations.find( event ) == mRelations.end() ) {
00281 mRelations.append( event );
00282 updated();
00283 }
00284 }
00285
00286 void Incidence::removeRelation(Incidence *event)
00287 {
00288 mRelations.removeRef(event);
00289
00290 }
00291
00292 bool Incidence::recursOn(const QDate &qd) const
00293 {
00294 return (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd));
00295 }
00296
00297 bool Incidence::recursAt(const QDateTime &qdt) const
00298 {
00299 return (mRecurrence && mRecurrence->recursAtPure(qdt) && !isException(qdt.date()) && !isException(qdt));
00300 }
00301
00302 void Incidence::setExDates(const DateList &exDates)
00303 {
00304 if (mReadOnly) return;
00305 mExDates = exDates;
00306 updated();
00307 }
00308
00309 void Incidence::setExDateTimes(const DateTimeList &exDateTimes)
00310 {
00311 if (mReadOnly) return;
00312 mExDateTimes = exDateTimes;
00313 updated();
00314 }
00315
00316 void Incidence::addExDate(const QDate &date)
00317 {
00318 if (mReadOnly) return;
00319 mExDates.append(date);
00320 updated();
00321 }
00322
00323 void Incidence::addExDateTime(const QDateTime &dateTime)
00324 {
00325 if (mReadOnly) return;
00326 mExDateTimes.append(dateTime);
00327 updated();
00328 }
00329
00330 DateList Incidence::exDates() const
00331 {
00332 return mExDates;
00333 }
00334
00335 DateTimeList Incidence::exDateTimes() const
00336 {
00337 return mExDateTimes;
00338 }
00339
00340 bool Incidence::isException(const QDate &date) const
00341 {
00342 DateList::ConstIterator it;
00343 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
00344 if ( (*it) == date ) {
00345 return true;
00346 }
00347 }
00348
00349 return false;
00350 }
00351
00352 bool Incidence::isException(const QDateTime &dateTime) const
00353 {
00354 DateTimeList::ConstIterator it;
00355 for( it = mExDateTimes.begin(); it != mExDateTimes.end(); ++it ) {
00356 if ( (*it) == dateTime ) {
00357 return true;
00358 }
00359 }
00360
00361 return false;
00362 }
00363
00364 void Incidence::addAttachment(Attachment *attachment)
00365 {
00366 if (mReadOnly || !attachment) return;
00367 mAttachments.append(attachment);
00368 updated();
00369 }
00370
00371 void Incidence::deleteAttachment(Attachment *attachment)
00372 {
00373 mAttachments.removeRef(attachment);
00374 }
00375
00376 void Incidence::deleteAttachments( const QString &mime )
00377 {
00378 Attachment::List::Iterator it = mAttachments.begin();
00379 while( it != mAttachments.end() ) {
00380 if ( (*it)->mimeType() == mime ) mAttachments.remove( it );
00381 else ++it;
00382 }
00383 }
00384
00385 Attachment::List Incidence::attachments() const
00386 {
00387 return mAttachments;
00388 }
00389
00390 Attachment::List Incidence::attachments(const QString& mime) const
00391 {
00392 Attachment::List attachments;
00393 Attachment::List::ConstIterator it;
00394 for( it = mAttachments.begin(); it != mAttachments.end(); ++it ) {
00395 if ( (*it)->mimeType() == mime ) attachments.append( *it );
00396 }
00397
00398 return attachments;
00399 }
00400
00401 void Incidence::clearAttachments()
00402 {
00403 mAttachments.clear();
00404 }
00405
00406 void Incidence::setResources(const QStringList &resources)
00407 {
00408 if (mReadOnly) return;
00409 mResources = resources;
00410 updated();
00411 }
00412
00413 QStringList Incidence::resources() const
00414 {
00415 return mResources;
00416 }
00417
00418
00419 void Incidence::setPriority(int priority)
00420 {
00421 if (mReadOnly) return;
00422 mPriority = priority;
00423 updated();
00424 }
00425
00426 int Incidence::priority() const
00427 {
00428 return mPriority;
00429 }
00430
00431 void Incidence::setSecrecy(int sec)
00432 {
00433 if (mReadOnly) return;
00434 mSecrecy = sec;
00435 updated();
00436 }
00437
00438 int Incidence::secrecy() const
00439 {
00440 return mSecrecy;
00441 }
00442
00443 QString Incidence::secrecyStr() const
00444 {
00445 return secrecyName(mSecrecy);
00446 }
00447
00448 QString Incidence::secrecyName(int secrecy)
00449 {
00450 switch (secrecy) {
00451 case SecrecyPublic:
00452 return i18n("Public");
00453 break;
00454 case SecrecyPrivate:
00455 return i18n("Private");
00456 break;
00457 case SecrecyConfidential:
00458 return i18n("Confidential");
00459 break;
00460 default:
00461 return i18n("Undefined");
00462 break;
00463 }
00464 }
00465
00466 QStringList Incidence::secrecyList()
00467 {
00468 QStringList list;
00469 list << secrecyName(SecrecyPublic);
00470 list << secrecyName(SecrecyPrivate);
00471 list << secrecyName(SecrecyConfidential);
00472
00473 return list;
00474 }
00475
00476
00477 const Alarm::List &Incidence::alarms() const
00478 {
00479 return mAlarms;
00480 }
00481
00482 Alarm* Incidence::newAlarm()
00483 {
00484 Alarm* alarm = new Alarm(this);
00485 mAlarms.append(alarm);
00486
00487 return alarm;
00488 }
00489
00490 void Incidence::addAlarm(Alarm *alarm)
00491 {
00492 mAlarms.append(alarm);
00493 updated();
00494 }
00495
00496 void Incidence::removeAlarm(Alarm *alarm)
00497 {
00498 mAlarms.removeRef(alarm);
00499 updated();
00500 }
00501
00502 void Incidence::clearAlarms()
00503 {
00504 mAlarms.clear();
00505 updated();
00506 }
00507
00508 bool Incidence::isAlarmEnabled() const
00509 {
00510 Alarm::List::ConstIterator it;
00511 for( it = mAlarms.begin(); it != mAlarms.end(); ++it ) {
00512 if ( (*it)->enabled() ) return true;
00513 }
00514 return false;
00515 }
00516
00517 Recurrence *Incidence::recurrence() const
00518 {
00519 if (!mRecurrence)
00520 {
00521 const_cast<KCal::Incidence*>(this)->mRecurrence = new Recurrence(const_cast<KCal::Incidence*>(this));
00522 mRecurrence->setRecurReadOnly(mReadOnly);
00523 mRecurrence->setRecurStart(dtStart());
00524 }
00525
00526 return mRecurrence;
00527 }
00528
00529 void Incidence::setLocation(const QString &location)
00530 {
00531 if (mReadOnly) return;
00532 mLocation = location;
00533 updated();
00534 }
00535
00536 QString Incidence::location() const
00537 {
00538 return mLocation;
00539 }
00540
00541 ushort Incidence::doesRecur() const
00542 {
00543 if ( mRecurrence ) return mRecurrence->doesRecur();
00544 else return Recurrence::rNone;
00545 }
This file is part of the documentation for libkcal Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Mar 6 17:18:03 2004 by
doxygen 1.3.6-20040222 written by
Dimitri van Heesch, © 1997-2003