summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Unidiff
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidence.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 9c35b1d..762103f 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -156,390 +156,416 @@ void Incidence::setHasStartDate(bool f)
156 156
157// A string comparison that considers that null and empty are the same 157// A string comparison that considers that null and empty are the same
158static bool stringCompare( const QString& s1, const QString& s2 ) 158static bool stringCompare( const QString& s1, const QString& s2 )
159{ 159{
160 if ( s1.isEmpty() && s2.isEmpty() ) 160 if ( s1.isEmpty() && s2.isEmpty() )
161 return true; 161 return true;
162 return s1 == s2; 162 return s1 == s2;
163} 163}
164 164
165bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 165bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
166{ 166{
167 167
168 if( i1.alarms().count() != i2.alarms().count() ) { 168 if( i1.alarms().count() != i2.alarms().count() ) {
169 return false; // no need to check further 169 return false; // no need to check further
170 } 170 }
171 if ( i1.alarms().count() > 0 ) { 171 if ( i1.alarms().count() > 0 ) {
172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
173 { 173 {
174 qDebug("alarm not equal "); 174 qDebug("alarm not equal ");
175 return false; 175 return false;
176 } 176 }
177 } 177 }
178#if 0 178#if 0
179 QPtrListIterator<Alarm> a1( i1.alarms() ); 179 QPtrListIterator<Alarm> a1( i1.alarms() );
180 QPtrListIterator<Alarm> a2( i2.alarms() ); 180 QPtrListIterator<Alarm> a2( i2.alarms() );
181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
182 if( *a1.current() == *a2.current() ) { 182 if( *a1.current() == *a2.current() ) {
183 continue; 183 continue;
184 } 184 }
185 else { 185 else {
186 return false; 186 return false;
187 } 187 }
188 } 188 }
189#endif 189#endif
190 190
191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
192 if ( i1.hasRecurrenceID() ) { 192 if ( i1.hasRecurrenceID() ) {
193 if ( i1.recurrenceID() != i2.recurrenceID() ) 193 if ( i1.recurrenceID() != i2.recurrenceID() )
194 return false; 194 return false;
195 } 195 }
196 196
197 } else { 197 } else {
198 return false; 198 return false;
199 } 199 }
200 200
201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
202 return false; 202 return false;
203 if ( i1.hasStartDate() == i2.hasStartDate() ) { 203 if ( i1.hasStartDate() == i2.hasStartDate() ) {
204 if ( i1.hasStartDate() ) { 204 if ( i1.hasStartDate() ) {
205 if ( i1.dtStart() != i2.dtStart() ) 205 if ( i1.dtStart() != i2.dtStart() )
206 return false; 206 return false;
207 } 207 }
208 } else { 208 } else {
209 return false; 209 return false;
210 } 210 }
211 if (!( *i1.recurrence() == *i2.recurrence()) ) { 211 if (!( *i1.recurrence() == *i2.recurrence()) ) {
212 qDebug("recurrence is NOT equal "); 212 qDebug("recurrence is NOT equal ");
213 return false; 213 return false;
214 } 214 }
215 return 215 return
216 // i1.created() == i2.created() && 216 // i1.created() == i2.created() &&
217 stringCompare( i1.description(), i2.description() ) && 217 stringCompare( i1.description(), i2.description() ) &&
218 stringCompare( i1.summary(), i2.summary() ) && 218 stringCompare( i1.summary(), i2.summary() ) &&
219 i1.categories() == i2.categories() && 219 i1.categories() == i2.categories() &&
220 // no need to compare mRelatedTo 220 // no need to compare mRelatedTo
221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
222 // i1.relations() == i2.relations() && 222 // i1.relations() == i2.relations() &&
223 i1.exDates() == i2.exDates() && 223 i1.exDates() == i2.exDates() &&
224 i1.attachments() == i2.attachments() && 224 i1.attachments() == i2.attachments() &&
225 i1.resources() == i2.resources() && 225 i1.resources() == i2.resources() &&
226 i1.secrecy() == i2.secrecy() && 226 i1.secrecy() == i2.secrecy() &&
227 i1.priority() == i2.priority() && 227 i1.priority() == i2.priority() &&
228 i1.cancelled() == i2.cancelled() && 228 i1.cancelled() == i2.cancelled() &&
229 stringCompare( i1.location(), i2.location() ); 229 stringCompare( i1.location(), i2.location() );
230} 230}
231 231
232Incidence* Incidence::recreateCloneException( QDate d ) 232Incidence* Incidence::recreateCloneException( QDate d )
233{ 233{
234 Incidence* newInc = clone(); 234 Incidence* newInc = clone();
235 newInc->recreate(); 235 newInc->recreate();
236 if ( doesRecur() ) { 236 if ( doesRecur() ) {
237 addExDate( d ); 237 addExDate( d );
238 newInc->recurrence()->unsetRecurs(); 238 newInc->recurrence()->unsetRecurs();
239 if ( type() == "Event") { 239 if ( type() == "Event") {
240 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 240 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
241 QTime tim = dtStart().time(); 241 QTime tim = dtStart().time();
242 newInc->setDtStart( QDateTime(d, tim) ); 242 newInc->setDtStart( QDateTime(d, tim) );
243 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 243 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
244 } else { 244 } else {
245 int len = dtStart().secsTo( ((Todo*)this)->dtDue()); 245 int len = dtStart().secsTo( ((Todo*)this)->dtDue());
246 QTime tim = ((Todo*)this)->dtDue().time(); 246 QTime tim = ((Todo*)this)->dtDue().time();
247 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); 247 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) );
248 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); 248 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) );
249 ((Todo*)this)->setRecurDates(); 249 ((Todo*)this)->setRecurDates();
250 } 250 }
251 newInc->setExDates( DateList () ); 251 newInc->setExDates( DateList () );
252 } 252 }
253 return newInc; 253 return newInc;
254} 254}
255 255
256void Incidence::recreate() 256void Incidence::recreate()
257{ 257{
258 setCreated(QDateTime::currentDateTime()); 258 setCreated(QDateTime::currentDateTime());
259 259
260 setUid(CalFormat::createUniqueId()); 260 setUid(CalFormat::createUniqueId());
261 261
262 setRevision(0); 262 setRevision(0);
263 setIDStr( ":" ); 263 setIDStr( ":" );
264 setLastModified(QDateTime::currentDateTime()); 264 setLastModified(QDateTime::currentDateTime());
265} 265}
266void Incidence::cloneRelations( Incidence * newInc ) 266void Incidence::cloneRelations( Incidence * newInc )
267{ 267{
268 // newInc is already a clone of this incidence 268 // newInc is already a clone of this incidence
269 Incidence * inc; 269 Incidence * inc;
270 Incidence * cloneInc; 270 Incidence * cloneInc;
271 QPtrList<Incidence> Relations = relations(); 271 QPtrList<Incidence> Relations = relations();
272 for (inc=Relations.first();inc;inc=Relations.next()) { 272 for (inc=Relations.first();inc;inc=Relations.next()) {
273 cloneInc = inc->clone(); 273 cloneInc = inc->clone();
274 cloneInc->recreate(); 274 cloneInc->recreate();
275 cloneInc->setRelatedTo( newInc ); 275 cloneInc->setRelatedTo( newInc );
276 inc->cloneRelations( cloneInc ); 276 inc->cloneRelations( cloneInc );
277 } 277 }
278} 278}
279void Incidence::setReadOnly( bool readOnly ) 279void Incidence::setReadOnly( bool readOnly )
280{ 280{
281 IncidenceBase::setReadOnly( readOnly ); 281 IncidenceBase::setReadOnly( readOnly );
282 recurrence()->setRecurReadOnly( readOnly); 282 recurrence()->setRecurReadOnly( readOnly);
283} 283}
284 284
285void Incidence::setCreated(QDateTime created) 285void Incidence::setCreated(QDateTime created)
286{ 286{
287 if (mReadOnly) return; 287 if (mReadOnly) return;
288 mCreated = getEvenTime(created); 288 mCreated = getEvenTime(created);
289} 289}
290 290
291QDateTime Incidence::created() const 291QDateTime Incidence::created() const
292{ 292{
293 return mCreated; 293 return mCreated;
294} 294}
295 295
296void Incidence::setRevision(int rev) 296void Incidence::setRevision(int rev)
297{ 297{
298 if (mReadOnly) return; 298 if (mReadOnly) return;
299 mRevision = rev; 299 mRevision = rev;
300 300
301 updated(); 301 updated();
302} 302}
303 303
304int Incidence::revision() const 304int Incidence::revision() const
305{ 305{
306 return mRevision; 306 return mRevision;
307} 307}
308 308
309void Incidence::setDtStart(const QDateTime &dtStart) 309void Incidence::setDtStart(const QDateTime &dtStart)
310{ 310{
311 311
312 QDateTime dt = getEvenTime(dtStart); 312 QDateTime dt = getEvenTime(dtStart);
313 recurrence()->setRecurStart( dt); 313 recurrence()->setRecurStart( dt);
314 IncidenceBase::setDtStart( dt ); 314 IncidenceBase::setDtStart( dt );
315} 315}
316 316
317void Incidence::setDescription(const QString &description) 317void Incidence::setDescription(const QString &description)
318{ 318{
319 if (mReadOnly) return; 319 if (mReadOnly) return;
320 mDescription = description; 320 mDescription = description;
321 updated(); 321 updated();
322} 322}
323 323
324QString Incidence::description() const 324QString Incidence::description() const
325{ 325{
326 return mDescription; 326 return mDescription;
327} 327}
328 328
329 329
330void Incidence::setSummary(const QString &summary) 330void Incidence::setSummary(const QString &summary)
331{ 331{
332 if (mReadOnly) return; 332 if (mReadOnly) return;
333 mSummary = summary; 333 mSummary = summary;
334 updated(); 334 updated();
335} 335}
336 336
337QString Incidence::summary() const 337QString Incidence::summary() const
338{ 338{
339 return mSummary; 339 return mSummary;
340} 340}
341void Incidence::checkCategories() 341void Incidence::checkCategories()
342{ 342{
343 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 343 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
344 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 344 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
345 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 345 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
346} 346}
347 347
348void Incidence::setCategories(const QStringList &categories) 348void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false
349{
350 if (mReadOnly) return;
351 int i;
352 for( i = 0; i < categories.count(); ++i ) {
353 if ( !mCategories.contains (categories[i]))
354 mCategories.append( categories[i] );
355 }
356 checkCategories();
357 updated();
358 if ( addToRelations ) {
359 Incidence * inc;
360 QPtrList<Incidence> Relations = relations();
361 for (inc=Relations.first();inc;inc=Relations.next()) {
362 inc->addCategories( categories, true );
363 }
364 }
365}
366
367void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false
349{ 368{
350 if (mReadOnly) return; 369 if (mReadOnly) return;
351 mCategories = categories; 370 mCategories = categories;
352 checkCategories(); 371 checkCategories();
353 updated(); 372 updated();
373 if ( setForRelations ) {
374 Incidence * inc;
375 QPtrList<Incidence> Relations = relations();
376 for (inc=Relations.first();inc;inc=Relations.next()) {
377 inc->setCategories( categories, true );
378 }
379 }
354} 380}
355 381
356// TODO: remove setCategories(QString) function 382// TODO: remove setCategories(QString) function
357void Incidence::setCategories(const QString &catStr) 383void Incidence::setCategories(const QString &catStr)
358{ 384{
359 if (mReadOnly) return; 385 if (mReadOnly) return;
360 mCategories.clear(); 386 mCategories.clear();
361 387
362 if (catStr.isEmpty()) return; 388 if (catStr.isEmpty()) return;
363 389
364 mCategories = QStringList::split(",",catStr); 390 mCategories = QStringList::split(",",catStr);
365 391
366 QStringList::Iterator it; 392 QStringList::Iterator it;
367 for(it = mCategories.begin();it != mCategories.end(); ++it) { 393 for(it = mCategories.begin();it != mCategories.end(); ++it) {
368 *it = (*it).stripWhiteSpace(); 394 *it = (*it).stripWhiteSpace();
369 } 395 }
370 checkCategories(); 396 checkCategories();
371 updated(); 397 updated();
372} 398}
373 399
374QStringList Incidence::categories() const 400QStringList Incidence::categories() const
375{ 401{
376 return mCategories; 402 return mCategories;
377} 403}
378 404
379QString Incidence::categoriesStr() 405QString Incidence::categoriesStr()
380{ 406{
381 return mCategories.join(","); 407 return mCategories.join(",");
382} 408}
383QString Incidence::categoriesStrWithSpace() 409QString Incidence::categoriesStrWithSpace()
384{ 410{
385 return mCategories.join(", "); 411 return mCategories.join(", ");
386} 412}
387 413
388void Incidence::setRelatedToUid(const QString &relatedToUid) 414void Incidence::setRelatedToUid(const QString &relatedToUid)
389{ 415{
390 if (mReadOnly) return; 416 if (mReadOnly) return;
391 mRelatedToUid = relatedToUid; 417 mRelatedToUid = relatedToUid;
392} 418}
393 419
394QString Incidence::relatedToUid() const 420QString Incidence::relatedToUid() const
395{ 421{
396 return mRelatedToUid; 422 return mRelatedToUid;
397} 423}
398 424
399void Incidence::setRelatedTo(Incidence *relatedTo) 425void Incidence::setRelatedTo(Incidence *relatedTo)
400{ 426{
401 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 427 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
402 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 428 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
403 if (mReadOnly || mRelatedTo == relatedTo) return; 429 if (mReadOnly || mRelatedTo == relatedTo) return;
404 if(mRelatedTo) { 430 if(mRelatedTo) {
405 // updated(); 431 // updated();
406 mRelatedTo->removeRelation(this); 432 mRelatedTo->removeRelation(this);
407 } 433 }
408 mRelatedTo = relatedTo; 434 mRelatedTo = relatedTo;
409 if (mRelatedTo) { 435 if (mRelatedTo) {
410 mRelatedTo->addRelation(this); 436 mRelatedTo->addRelation(this);
411 mRelatedToUid = mRelatedTo->uid(); 437 mRelatedToUid = mRelatedTo->uid();
412 } else { 438 } else {
413 mRelatedToUid = ""; 439 mRelatedToUid = "";
414 } 440 }
415} 441}
416 442
417Incidence *Incidence::relatedTo() const 443Incidence *Incidence::relatedTo() const
418{ 444{
419 return mRelatedTo; 445 return mRelatedTo;
420} 446}
421 447
422QPtrList<Incidence> Incidence::relations() const 448QPtrList<Incidence> Incidence::relations() const
423{ 449{
424 return mRelations; 450 return mRelations;
425} 451}
426 452
427void Incidence::addRelation(Incidence *event) 453void Incidence::addRelation(Incidence *event)
428{ 454{
429 if( mRelations.findRef( event ) == -1 ) { 455 if( mRelations.findRef( event ) == -1 ) {
430 mRelations.append(event); 456 mRelations.append(event);
431 //updated(); 457 //updated();
432 } 458 }
433} 459}
434 460
435void Incidence::removeRelation(Incidence *event) 461void Incidence::removeRelation(Incidence *event)
436{ 462{
437 463
438 mRelations.removeRef(event); 464 mRelations.removeRef(event);
439 465
440// if (event->getRelatedTo() == this) event->setRelatedTo(0); 466// if (event->getRelatedTo() == this) event->setRelatedTo(0);
441} 467}
442 468
443bool Incidence::recursOn(const QDate &qd) const 469bool Incidence::recursOn(const QDate &qd) const
444{ 470{
445 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 471 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
446 else return false; 472 else return false;
447} 473}
448 474
449void Incidence::setExDates(const DateList &exDates) 475void Incidence::setExDates(const DateList &exDates)
450{ 476{
451 if (mReadOnly) return; 477 if (mReadOnly) return;
452 mExDates = exDates; 478 mExDates = exDates;
453 479
454 recurrence()->setRecurExDatesCount(mExDates.count()); 480 recurrence()->setRecurExDatesCount(mExDates.count());
455 481
456 updated(); 482 updated();
457} 483}
458 484
459void Incidence::addExDate(const QDate &date) 485void Incidence::addExDate(const QDate &date)
460{ 486{
461 if (mReadOnly) return; 487 if (mReadOnly) return;
462 mExDates.append(date); 488 mExDates.append(date);
463 489
464 recurrence()->setRecurExDatesCount(mExDates.count()); 490 recurrence()->setRecurExDatesCount(mExDates.count());
465 491
466 updated(); 492 updated();
467} 493}
468 494
469DateList Incidence::exDates() const 495DateList Incidence::exDates() const
470{ 496{
471 return mExDates; 497 return mExDates;
472} 498}
473 499
474bool Incidence::isException(const QDate &date) const 500bool Incidence::isException(const QDate &date) const
475{ 501{
476 DateList::ConstIterator it; 502 DateList::ConstIterator it;
477 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 503 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
478 if ( (*it) == date ) { 504 if ( (*it) == date ) {
479 return true; 505 return true;
480 } 506 }
481 } 507 }
482 508
483 return false; 509 return false;
484} 510}
485 511
486void Incidence::addAttachment(Attachment *attachment) 512void Incidence::addAttachment(Attachment *attachment)
487{ 513{
488 if (mReadOnly || !attachment) return; 514 if (mReadOnly || !attachment) return;
489 mAttachments.append(attachment); 515 mAttachments.append(attachment);
490 updated(); 516 updated();
491} 517}
492 518
493void Incidence::deleteAttachment(Attachment *attachment) 519void Incidence::deleteAttachment(Attachment *attachment)
494{ 520{
495 mAttachments.removeRef(attachment); 521 mAttachments.removeRef(attachment);
496} 522}
497 523
498void Incidence::deleteAttachments(const QString& mime) 524void Incidence::deleteAttachments(const QString& mime)
499{ 525{
500 Attachment *at = mAttachments.first(); 526 Attachment *at = mAttachments.first();
501 while (at) { 527 while (at) {
502 if (at->mimeType() == mime) 528 if (at->mimeType() == mime)
503 mAttachments.remove(); 529 mAttachments.remove();
504 else 530 else
505 at = mAttachments.next(); 531 at = mAttachments.next();
506 } 532 }
507} 533}
508 534
509QPtrList<Attachment> Incidence::attachments() const 535QPtrList<Attachment> Incidence::attachments() const
510{ 536{
511 return mAttachments; 537 return mAttachments;
512} 538}
513 539
514QPtrList<Attachment> Incidence::attachments(const QString& mime) const 540QPtrList<Attachment> Incidence::attachments(const QString& mime) const
515{ 541{
516 QPtrList<Attachment> attachments; 542 QPtrList<Attachment> attachments;
517 QPtrListIterator<Attachment> it( mAttachments ); 543 QPtrListIterator<Attachment> it( mAttachments );
518 Attachment *at; 544 Attachment *at;
519 while ( (at = it.current()) ) { 545 while ( (at = it.current()) ) {
520 if (at->mimeType() == mime) 546 if (at->mimeType() == mime)
521 attachments.append(at); 547 attachments.append(at);
522 ++it; 548 ++it;
523 } 549 }
524 550
525 return attachments; 551 return attachments;
526} 552}
527 553
528void Incidence::setResources(const QStringList &resources) 554void Incidence::setResources(const QStringList &resources)
529{ 555{
530 if (mReadOnly) return; 556 if (mReadOnly) return;
531 mResources = resources; 557 mResources = resources;
532 updated(); 558 updated();
533} 559}
534 560
535QStringList Incidence::resources() const 561QStringList Incidence::resources() const
536{ 562{
537 return mResources; 563 return mResources;
538} 564}
539 565
540 566
541void Incidence::setPriority(int priority) 567void Incidence::setPriority(int priority)
542{ 568{
543 if (mReadOnly) return; 569 if (mReadOnly) return;
544 mPriority = priority; 570 mPriority = priority;
545 updated(); 571 updated();