-rw-r--r-- | libkcal/incidence.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index d9bda64..56c9801 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -281,314 +281,319 @@ QStringList Incidence::categories() const | |||
281 | QString Incidence::categoriesStr() | 281 | QString Incidence::categoriesStr() |
282 | { | 282 | { |
283 | return mCategories.join(","); | 283 | return mCategories.join(","); |
284 | } | 284 | } |
285 | 285 | ||
286 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 286 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
287 | { | 287 | { |
288 | if (mReadOnly) return; | 288 | if (mReadOnly) return; |
289 | mRelatedToUid = relatedToUid; | 289 | mRelatedToUid = relatedToUid; |
290 | } | 290 | } |
291 | 291 | ||
292 | QString Incidence::relatedToUid() const | 292 | QString Incidence::relatedToUid() const |
293 | { | 293 | { |
294 | return mRelatedToUid; | 294 | return mRelatedToUid; |
295 | } | 295 | } |
296 | 296 | ||
297 | void Incidence::setRelatedTo(Incidence *relatedTo) | 297 | void Incidence::setRelatedTo(Incidence *relatedTo) |
298 | { | 298 | { |
299 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 299 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
300 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 300 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
301 | if (mReadOnly || mRelatedTo == relatedTo) return; | 301 | if (mReadOnly || mRelatedTo == relatedTo) return; |
302 | if(mRelatedTo) { | 302 | if(mRelatedTo) { |
303 | // updated(); | 303 | // updated(); |
304 | mRelatedTo->removeRelation(this); | 304 | mRelatedTo->removeRelation(this); |
305 | } | 305 | } |
306 | mRelatedTo = relatedTo; | 306 | mRelatedTo = relatedTo; |
307 | if (mRelatedTo) mRelatedTo->addRelation(this); | 307 | if (mRelatedTo) mRelatedTo->addRelation(this); |
308 | } | 308 | } |
309 | 309 | ||
310 | Incidence *Incidence::relatedTo() const | 310 | Incidence *Incidence::relatedTo() const |
311 | { | 311 | { |
312 | return mRelatedTo; | 312 | return mRelatedTo; |
313 | } | 313 | } |
314 | 314 | ||
315 | QPtrList<Incidence> Incidence::relations() const | 315 | QPtrList<Incidence> Incidence::relations() const |
316 | { | 316 | { |
317 | return mRelations; | 317 | return mRelations; |
318 | } | 318 | } |
319 | 319 | ||
320 | void Incidence::addRelation(Incidence *event) | 320 | void Incidence::addRelation(Incidence *event) |
321 | { | 321 | { |
322 | if( mRelations.findRef( event ) == -1 ) { | 322 | if( mRelations.findRef( event ) == -1 ) { |
323 | mRelations.append(event); | 323 | mRelations.append(event); |
324 | //updated(); | 324 | //updated(); |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | void Incidence::removeRelation(Incidence *event) | 328 | void Incidence::removeRelation(Incidence *event) |
329 | { | 329 | { |
330 | 330 | ||
331 | mRelations.removeRef(event); | 331 | mRelations.removeRef(event); |
332 | 332 | ||
333 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 333 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
334 | } | 334 | } |
335 | 335 | ||
336 | bool Incidence::recursOn(const QDate &qd) const | 336 | bool Incidence::recursOn(const QDate &qd) const |
337 | { | 337 | { |
338 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 338 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
339 | else return false; | 339 | else return false; |
340 | } | 340 | } |
341 | 341 | ||
342 | void Incidence::setExDates(const DateList &exDates) | 342 | void Incidence::setExDates(const DateList &exDates) |
343 | { | 343 | { |
344 | if (mReadOnly) return; | 344 | if (mReadOnly) return; |
345 | mExDates = exDates; | 345 | mExDates = exDates; |
346 | 346 | ||
347 | recurrence()->setRecurExDatesCount(mExDates.count()); | 347 | recurrence()->setRecurExDatesCount(mExDates.count()); |
348 | 348 | ||
349 | updated(); | 349 | updated(); |
350 | } | 350 | } |
351 | 351 | ||
352 | void Incidence::addExDate(const QDate &date) | 352 | void Incidence::addExDate(const QDate &date) |
353 | { | 353 | { |
354 | if (mReadOnly) return; | 354 | if (mReadOnly) return; |
355 | mExDates.append(date); | 355 | mExDates.append(date); |
356 | 356 | ||
357 | recurrence()->setRecurExDatesCount(mExDates.count()); | 357 | recurrence()->setRecurExDatesCount(mExDates.count()); |
358 | 358 | ||
359 | updated(); | 359 | updated(); |
360 | } | 360 | } |
361 | 361 | ||
362 | DateList Incidence::exDates() const | 362 | DateList Incidence::exDates() const |
363 | { | 363 | { |
364 | return mExDates; | 364 | return mExDates; |
365 | } | 365 | } |
366 | 366 | ||
367 | bool Incidence::isException(const QDate &date) const | 367 | bool Incidence::isException(const QDate &date) const |
368 | { | 368 | { |
369 | DateList::ConstIterator it; | 369 | DateList::ConstIterator it; |
370 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 370 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
371 | if ( (*it) == date ) { | 371 | if ( (*it) == date ) { |
372 | return true; | 372 | return true; |
373 | } | 373 | } |
374 | } | 374 | } |
375 | 375 | ||
376 | return false; | 376 | return false; |
377 | } | 377 | } |
378 | 378 | ||
379 | void Incidence::addAttachment(Attachment *attachment) | 379 | void Incidence::addAttachment(Attachment *attachment) |
380 | { | 380 | { |
381 | if (mReadOnly || !attachment) return; | 381 | if (mReadOnly || !attachment) return; |
382 | mAttachments.append(attachment); | 382 | mAttachments.append(attachment); |
383 | updated(); | 383 | updated(); |
384 | } | 384 | } |
385 | 385 | ||
386 | void Incidence::deleteAttachment(Attachment *attachment) | 386 | void Incidence::deleteAttachment(Attachment *attachment) |
387 | { | 387 | { |
388 | mAttachments.removeRef(attachment); | 388 | mAttachments.removeRef(attachment); |
389 | } | 389 | } |
390 | 390 | ||
391 | void Incidence::deleteAttachments(const QString& mime) | 391 | void Incidence::deleteAttachments(const QString& mime) |
392 | { | 392 | { |
393 | Attachment *at = mAttachments.first(); | 393 | Attachment *at = mAttachments.first(); |
394 | while (at) { | 394 | while (at) { |
395 | if (at->mimeType() == mime) | 395 | if (at->mimeType() == mime) |
396 | mAttachments.remove(); | 396 | mAttachments.remove(); |
397 | else | 397 | else |
398 | at = mAttachments.next(); | 398 | at = mAttachments.next(); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | 401 | ||
402 | QPtrList<Attachment> Incidence::attachments() const | 402 | QPtrList<Attachment> Incidence::attachments() const |
403 | { | 403 | { |
404 | return mAttachments; | 404 | return mAttachments; |
405 | } | 405 | } |
406 | 406 | ||
407 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 407 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
408 | { | 408 | { |
409 | QPtrList<Attachment> attachments; | 409 | QPtrList<Attachment> attachments; |
410 | QPtrListIterator<Attachment> it( mAttachments ); | 410 | QPtrListIterator<Attachment> it( mAttachments ); |
411 | Attachment *at; | 411 | Attachment *at; |
412 | while ( (at = it.current()) ) { | 412 | while ( (at = it.current()) ) { |
413 | if (at->mimeType() == mime) | 413 | if (at->mimeType() == mime) |
414 | attachments.append(at); | 414 | attachments.append(at); |
415 | ++it; | 415 | ++it; |
416 | } | 416 | } |
417 | 417 | ||
418 | return attachments; | 418 | return attachments; |
419 | } | 419 | } |
420 | 420 | ||
421 | void Incidence::setResources(const QStringList &resources) | 421 | void Incidence::setResources(const QStringList &resources) |
422 | { | 422 | { |
423 | if (mReadOnly) return; | 423 | if (mReadOnly) return; |
424 | mResources = resources; | 424 | mResources = resources; |
425 | updated(); | 425 | updated(); |
426 | } | 426 | } |
427 | 427 | ||
428 | QStringList Incidence::resources() const | 428 | QStringList Incidence::resources() const |
429 | { | 429 | { |
430 | return mResources; | 430 | return mResources; |
431 | } | 431 | } |
432 | 432 | ||
433 | 433 | ||
434 | void Incidence::setPriority(int priority) | 434 | void Incidence::setPriority(int priority) |
435 | { | 435 | { |
436 | if (mReadOnly) return; | 436 | if (mReadOnly) return; |
437 | mPriority = priority; | 437 | mPriority = priority; |
438 | updated(); | 438 | updated(); |
439 | } | 439 | } |
440 | 440 | ||
441 | int Incidence::priority() const | 441 | int Incidence::priority() const |
442 | { | 442 | { |
443 | return mPriority; | 443 | return mPriority; |
444 | } | 444 | } |
445 | 445 | ||
446 | void Incidence::setSecrecy(int sec) | 446 | void Incidence::setSecrecy(int sec) |
447 | { | 447 | { |
448 | if (mReadOnly) return; | 448 | if (mReadOnly) return; |
449 | mSecrecy = sec; | 449 | mSecrecy = sec; |
450 | updated(); | 450 | updated(); |
451 | } | 451 | } |
452 | 452 | ||
453 | int Incidence::secrecy() const | 453 | int Incidence::secrecy() const |
454 | { | 454 | { |
455 | return mSecrecy; | 455 | return mSecrecy; |
456 | } | 456 | } |
457 | 457 | ||
458 | QString Incidence::secrecyStr() const | 458 | QString Incidence::secrecyStr() const |
459 | { | 459 | { |
460 | return secrecyName(mSecrecy); | 460 | return secrecyName(mSecrecy); |
461 | } | 461 | } |
462 | 462 | ||
463 | QString Incidence::secrecyName(int secrecy) | 463 | QString Incidence::secrecyName(int secrecy) |
464 | { | 464 | { |
465 | switch (secrecy) { | 465 | switch (secrecy) { |
466 | case SecrecyPublic: | 466 | case SecrecyPublic: |
467 | return i18n("Public"); | 467 | return i18n("Public"); |
468 | break; | 468 | break; |
469 | case SecrecyPrivate: | 469 | case SecrecyPrivate: |
470 | return i18n("Private"); | 470 | return i18n("Private"); |
471 | break; | 471 | break; |
472 | case SecrecyConfidential: | 472 | case SecrecyConfidential: |
473 | return i18n("Confidential"); | 473 | return i18n("Confidential"); |
474 | break; | 474 | break; |
475 | default: | 475 | default: |
476 | return i18n("Undefined"); | 476 | return i18n("Undefined"); |
477 | break; | 477 | break; |
478 | } | 478 | } |
479 | } | 479 | } |
480 | 480 | ||
481 | QStringList Incidence::secrecyList() | 481 | QStringList Incidence::secrecyList() |
482 | { | 482 | { |
483 | QStringList list; | 483 | QStringList list; |
484 | list << secrecyName(SecrecyPublic); | 484 | list << secrecyName(SecrecyPublic); |
485 | list << secrecyName(SecrecyPrivate); | 485 | list << secrecyName(SecrecyPrivate); |
486 | list << secrecyName(SecrecyConfidential); | 486 | list << secrecyName(SecrecyConfidential); |
487 | 487 | ||
488 | return list; | 488 | return list; |
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | ||
492 | QPtrList<Alarm> Incidence::alarms() const | 492 | QPtrList<Alarm> Incidence::alarms() const |
493 | { | 493 | { |
494 | return mAlarms; | 494 | return mAlarms; |
495 | } | 495 | } |
496 | 496 | ||
497 | Alarm* Incidence::newAlarm() | 497 | Alarm* Incidence::newAlarm() |
498 | { | 498 | { |
499 | Alarm* alarm = new Alarm(this); | 499 | Alarm* alarm = new Alarm(this); |
500 | mAlarms.append(alarm); | 500 | mAlarms.append(alarm); |
501 | // updated(); | 501 | // updated(); |
502 | return alarm; | 502 | return alarm; |
503 | } | 503 | } |
504 | 504 | ||
505 | void Incidence::addAlarm(Alarm *alarm) | 505 | void Incidence::addAlarm(Alarm *alarm) |
506 | { | 506 | { |
507 | mAlarms.append(alarm); | 507 | mAlarms.append(alarm); |
508 | updated(); | 508 | updated(); |
509 | } | 509 | } |
510 | 510 | ||
511 | void Incidence::removeAlarm(Alarm *alarm) | 511 | void Incidence::removeAlarm(Alarm *alarm) |
512 | { | 512 | { |
513 | mAlarms.removeRef(alarm); | 513 | mAlarms.removeRef(alarm); |
514 | updated(); | 514 | updated(); |
515 | } | 515 | } |
516 | 516 | ||
517 | void Incidence::clearAlarms() | 517 | void Incidence::clearAlarms() |
518 | { | 518 | { |
519 | mAlarms.clear(); | 519 | mAlarms.clear(); |
520 | updated(); | 520 | updated(); |
521 | } | 521 | } |
522 | 522 | ||
523 | bool Incidence::isAlarmEnabled() const | 523 | bool Incidence::isAlarmEnabled() const |
524 | { | 524 | { |
525 | Alarm* alarm; | 525 | Alarm* alarm; |
526 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 526 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
527 | if (alarm->enabled()) | 527 | if (alarm->enabled()) |
528 | return true; | 528 | return true; |
529 | } | 529 | } |
530 | return false; | 530 | return false; |
531 | } | 531 | } |
532 | 532 | ||
533 | Recurrence *Incidence::recurrence() const | 533 | Recurrence *Incidence::recurrence() const |
534 | { | 534 | { |
535 | return mRecurrence; | 535 | return mRecurrence; |
536 | } | 536 | } |
537 | void Incidence::setRecurrence( Recurrence * r) | ||
538 | { | ||
539 | delete mRecurrence; | ||
540 | mRecurrence = r; | ||
541 | } | ||
537 | 542 | ||
538 | void Incidence::setLocation(const QString &location) | 543 | void Incidence::setLocation(const QString &location) |
539 | { | 544 | { |
540 | if (mReadOnly) return; | 545 | if (mReadOnly) return; |
541 | mLocation = location; | 546 | mLocation = location; |
542 | updated(); | 547 | updated(); |
543 | } | 548 | } |
544 | 549 | ||
545 | QString Incidence::location() const | 550 | QString Incidence::location() const |
546 | { | 551 | { |
547 | return mLocation; | 552 | return mLocation; |
548 | } | 553 | } |
549 | 554 | ||
550 | ushort Incidence::doesRecur() const | 555 | ushort Incidence::doesRecur() const |
551 | { | 556 | { |
552 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 557 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
553 | else return Recurrence::rNone; | 558 | else return Recurrence::rNone; |
554 | } | 559 | } |
555 | 560 | ||
556 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 561 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
557 | { | 562 | { |
558 | QDateTime incidenceStart = dt; | 563 | QDateTime incidenceStart = dt; |
559 | *ok = false; | 564 | *ok = false; |
560 | if ( doesRecur() ) { | 565 | if ( doesRecur() ) { |
561 | bool last; | 566 | bool last; |
562 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 567 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
563 | int count = 0; | 568 | int count = 0; |
564 | if ( !last ) { | 569 | if ( !last ) { |
565 | while ( !last ) { | 570 | while ( !last ) { |
566 | ++count; | 571 | ++count; |
567 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 572 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
568 | if ( recursOn( incidenceStart.date() ) ) { | 573 | if ( recursOn( incidenceStart.date() ) ) { |
569 | last = true; // exit while llop | 574 | last = true; // exit while llop |
570 | } else { | 575 | } else { |
571 | if ( last ) { // no alarm on last recurrence | 576 | if ( last ) { // no alarm on last recurrence |
572 | return QDateTime (); | 577 | return QDateTime (); |
573 | } | 578 | } |
574 | int year = incidenceStart.date().year(); | 579 | int year = incidenceStart.date().year(); |
575 | // workaround for bug in recurrence | 580 | // workaround for bug in recurrence |
576 | if ( count == 100 || year < 1980 || year > 5000 ) { | 581 | if ( count == 100 || year < 1980 || year > 5000 ) { |
577 | return QDateTime (); | 582 | return QDateTime (); |
578 | } | 583 | } |
579 | incidenceStart = incidenceStart.addSecs( 1 ); | 584 | incidenceStart = incidenceStart.addSecs( 1 ); |
580 | } | 585 | } |
581 | } | 586 | } |
582 | } else { | 587 | } else { |
583 | return QDateTime (); | 588 | return QDateTime (); |
584 | } | 589 | } |
585 | } else { | 590 | } else { |
586 | if ( hasStartDate () ) { | 591 | if ( hasStartDate () ) { |
587 | incidenceStart = dtStart(); | 592 | incidenceStart = dtStart(); |
588 | 593 | ||
589 | } | 594 | } |
590 | } | 595 | } |
591 | if ( incidenceStart > dt ) | 596 | if ( incidenceStart > dt ) |
592 | *ok = true; | 597 | *ok = true; |
593 | return incidenceStart; | 598 | return incidenceStart; |
594 | } | 599 | } |