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