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