426 } |
411 } |
427 |
412 |
428 // Repeat rule has to be modified in both cases |
413 // Repeat rule has to be modified in both cases |
429 if ( isNew || IsStartDateTimeEdited() || IsRepeatRuleEdited() ) |
414 if ( isNew || IsStartDateTimeEdited() || IsRepeatRuleEdited() ) |
430 { |
415 { |
431 if ( FeatureManager::FeatureSupported( KFeatureIdKorean ) && |
416 |
432 Edited().EntryType() == CCalEntry::EAnniv && |
417 if ( aRepeatTarget == CalCommon::EThisOnly) |
433 ( Edited().CalendarType() == ELunar || Edited().CalendarType() == ELunarLeap) ) |
418 { |
434 { /* Lunar entries need special repeating dates */ |
|
435 CKoreanLunarDateUtil* dateUtil = CKoreanLunarDateUtil::NewLC(&iServices); |
|
436 RArray<TCalTime> repeatDateList; |
|
437 CleanupClosePushL( repeatDateList ); |
|
438 |
|
439 /* Clear previous repeat rules */ |
|
440 iEntry.ClearRepeatingPropertiesL(); |
419 iEntry.ClearRepeatingPropertiesL(); |
441 TRAPD( err, dateUtil->GetLunarYearlyRepeatsL( repeatDateList, Edited().StartDateTime().DateTime(), UseFloatingTimeL() ) ); |
420 } |
442 |
421 else if ( Edited().IsRepeating() ) |
443 if( err == KErrNone ) |
422 { |
444 { |
423 // If we're an RDate (with repeat type ERepeatOther), don't try to set an RRule, |
445 iEntry.SetRDatesL( repeatDateList ); |
424 // but don't clear the repeat properties either. |
446 } |
425 if( Edited().RepeatType() != ERepeatOther ) |
447 |
426 { |
448 /* Pop and destroy repeatDateList and dateUtil */ |
427 TCalRRule rrule; |
449 CleanupStack::PopAndDestroy(2); |
428 |
450 } |
429 CalculateRepeatRuleL( Edited().StartDateTime(), |
451 else |
430 Edited().RepeatType(), |
452 { |
431 Edited().RepeatUntilDateTime(), |
453 if ( aRepeatTarget == CalCommon::EThisOnly) |
432 rrule ); |
454 { |
433 |
455 iEntry.ClearRepeatingPropertiesL(); |
434 iEntry.SetRRuleL( rrule ); |
456 } |
435 |
457 else if ( Edited().IsRepeating() ) |
436 // As there should not be any rdates, remove any that are |
458 { |
437 // still present |
459 // If we're an RDate (with repeat type ERepeatOther), don't try to set an RRule, |
438 RArray<TCalTime> emptyList; |
460 // but don't clear the repeat properties either. |
439 CleanupClosePushL( emptyList ); |
461 if( Edited().RepeatType() != ERepeatOther ) |
440 iEntry.SetRDatesL( emptyList ); |
|
441 CleanupStack::PopAndDestroy(); // emptyList |
|
442 } |
|
443 else |
|
444 { |
|
445 // The repeat type is ERepeatOther, therefore as |
|
446 // it is impossible to create an entry of type |
|
447 // ERepeat other using the editor either the repeat until |
|
448 // date or the start date must have been changed |
|
449 |
|
450 // The start date/time has changed, in order for the |
|
451 // series to maintain its pattern, any rDates and if |
|
452 // present rRule are moved by the same offset |
|
453 // The repeat type is ERepeatOther, so check if we have any rdates |
|
454 RArray<TCalTime> rDateList; |
|
455 CleanupClosePushL( rDateList ); |
|
456 iEntry.GetRDatesL( rDateList ); |
|
457 TInt count = rDateList.Count(); |
|
458 |
|
459 if ( count == 0 ) |
462 { |
460 { |
|
461 // There are no rdates so the new until and start date can be applied |
|
462 // directly. |
463 TCalRRule rrule; |
463 TCalRRule rrule; |
464 |
464 |
465 CalculateRepeatRuleL( Edited().StartDateTime(), |
465 CalculateRepeatRuleL( Edited().StartDateTime(), |
466 Edited().RepeatType(), |
466 Edited().RepeatType(), |
467 Edited().RepeatUntilDateTime(), |
467 Edited().RepeatUntilDateTime(), |
468 rrule ); |
468 rrule ); |
469 |
469 |
470 iEntry.SetRRuleL( rrule ); |
470 iEntry.SetRRuleL( rrule ); |
471 |
|
472 // As there should not be any rdates, remove any that are |
|
473 // still present |
|
474 RArray<TCalTime> emptyList; |
|
475 CleanupClosePushL( emptyList ); |
|
476 iEntry.SetRDatesL( emptyList ); |
|
477 CleanupStack::PopAndDestroy(); // emptyList |
|
478 } |
471 } |
479 else |
472 else |
480 { |
473 { |
481 // The repeat type is ERepeatOther, therefore as |
474 // There are rDates which need to be checked. |
482 // it is impossible to create an entry of type |
475 if ( IsStartDateTimeEdited() ) |
483 // ERepeat other using the editor either the repeat until |
476 { |
484 // date or the start date must have been changed |
477 // Need to shift any rdates |
|
478 TTime editedStart = iEdited->StartDateTime(); |
|
479 TTime origStart = iOriginal->StartDateTime(); |
|
480 TTimeIntervalMicroSeconds offSet = editedStart.MicroSecondsFrom( origStart ); |
|
481 for ( TInt index = 0; index < count; index++ ) |
|
482 { |
|
483 TCalTime& rDateTime = rDateList[ index ]; |
|
484 TTime shiftedTime = rDateTime.TimeUtcL(); |
|
485 TDateTime before = shiftedTime.DateTime(); |
|
486 shiftedTime += offSet; |
|
487 TDateTime after = shiftedTime.DateTime(); |
|
488 rDateTime.SetTimeUtcL( shiftedTime ); |
|
489 } |
|
490 } |
|
491 |
|
492 // Check and fix the rDates and rRules match the |
|
493 // repeat until date and time. |
|
494 TTime untilTime = Edited().RepeatUntilDateTime(); |
485 |
495 |
486 // The start date/time has changed, in order for the |
496 // Remove any rdates that are after the the repeat until date |
487 // series to maintain its pattern, any rDates and if |
|
488 // present rRule are moved by the same offset |
|
489 // The repeat type is ERepeatOther, so check if we have any rdates |
|
490 RArray<TCalTime> rDateList; |
|
491 CleanupClosePushL( rDateList ); |
|
492 iEntry.GetRDatesL( rDateList ); |
|
493 TInt count = rDateList.Count(); |
497 TInt count = rDateList.Count(); |
|
498 if ( count > 0 ) |
|
499 { |
|
500 TInt index = count - 1; |
|
501 do |
|
502 { |
|
503 TTime lastRDate = CalenDateUtils::BeginningOfDay( rDateList[ index ].TimeLocalL() ); |
|
504 TDateTime before = lastRDate.DateTime(); |
|
505 if ( lastRDate > untilTime ) |
|
506 { |
|
507 rDateList.Remove( index-- ); |
|
508 } |
|
509 else |
|
510 { |
|
511 index = KErrNotFound; |
|
512 } |
|
513 } while ( index != KErrNotFound ); |
|
514 } |
494 |
515 |
495 if ( count == 0 ) |
516 // Need to check if the end date of the |
|
517 // rrule needs adjusting if it exists. |
|
518 TCalRRule rRule; |
|
519 if ( iEntry.GetRRuleL( rRule ) ) |
496 { |
520 { |
497 // There are no rdates so the new until and start date can be applied |
521 count = rDateList.Count(); |
498 // directly. |
|
499 TCalRRule rrule; |
|
500 |
|
501 CalculateRepeatRuleL( Edited().StartDateTime(), |
|
502 Edited().RepeatType(), |
|
503 Edited().RepeatUntilDateTime(), |
|
504 rrule ); |
|
505 |
|
506 iEntry.SetRRuleL( rrule ); |
|
507 } |
|
508 else |
|
509 { |
|
510 // There are rDates which need to be checked. |
|
511 if ( IsStartDateTimeEdited() ) |
|
512 { |
|
513 // Need to shift any rdates |
|
514 TTime editedStart = iEdited->StartDateTime(); |
|
515 TTime origStart = iOriginal->StartDateTime(); |
|
516 TTimeIntervalMicroSeconds offSet = editedStart.MicroSecondsFrom( origStart ); |
|
517 for ( TInt index = 0; index < count; index++ ) |
|
518 { |
|
519 TCalTime& rDateTime = rDateList[ index ]; |
|
520 TTime shiftedTime = rDateTime.TimeUtcL(); |
|
521 TDateTime before = shiftedTime.DateTime(); |
|
522 shiftedTime += offSet; |
|
523 TDateTime after = shiftedTime.DateTime(); |
|
524 rDateTime.SetTimeUtcL( shiftedTime ); |
|
525 } |
|
526 } |
|
527 |
|
528 // Check and fix the rDates and rRules match the |
|
529 // repeat until date and time. |
|
530 TTime untilTime = Edited().RepeatUntilDateTime(); |
|
531 |
|
532 // Remove any rdates that are after the the repeat until date |
|
533 TInt count = rDateList.Count(); |
|
534 if ( count > 0 ) |
522 if ( count > 0 ) |
535 { |
523 { |
536 TInt index = count - 1; |
524 // There still exists some rdates, so only need to trim |
537 do |
525 // the rrule if it exists |
538 { |
526 TTime lastRDate = CalenDateUtils::BeginningOfDay( rDateList[ count - 1 ].TimeLocalL() ); |
539 TTime lastRDate = CalenDateUtils::BeginningOfDay( rDateList[ index ].TimeLocalL() ); |
527 const TTime& origUntilDate = Original().RepeatUntilDateTime(); |
540 TDateTime before = lastRDate.DateTime(); |
528 TTime startDT = rRule.DtStart().TimeLocalL(); |
541 if ( lastRDate > untilTime ) |
529 |
|
530 if ( lastRDate <= origUntilDate && startDT > lastRDate ) |
|
531 { |
|
532 if ( startDT < untilTime) |
542 { |
533 { |
543 rDateList.Remove( index-- ); |
534 if( origUntilDate != untilTime) |
|
535 { |
|
536 ApplyUntilDateToRRuleL( rRule, untilTime); |
|
537 iEntry.SetRRuleL( rRule ); |
|
538 } |
544 } |
539 } |
545 else |
540 else |
546 { |
541 { |
547 index = KErrNotFound; |
542 // The repeat start is after the until date |
548 } |
543 // so remove any repeat information. |
549 } while ( index != KErrNotFound ); |
544 iEntry.ClearRepeatingPropertiesL(); |
550 } |
545 |
551 |
546 // If the entry date has been moved past the until |
552 // Need to check if the end date of the |
547 // date, need to swap the an rDate for the entry. |
553 // rrule needs adjusting if it exists. |
548 TTime startTime = iEntry.StartTimeL().TimeLocalL(); |
554 TCalRRule rRule; |
549 |
555 if ( iEntry.GetRRuleL( rRule ) ) |
550 if ( startTime > untilTime ) |
556 { |
|
557 count = rDateList.Count(); |
|
558 if ( count > 0 ) |
|
559 { |
|
560 // There still exists some rdates, so only need to trim |
|
561 // the rrule if it exists |
|
562 TTime lastRDate = CalenDateUtils::BeginningOfDay( rDateList[ count - 1 ].TimeLocalL() ); |
|
563 const TTime& origUntilDate = Original().RepeatUntilDateTime(); |
|
564 TTime startDT = rRule.DtStart().TimeLocalL(); |
|
565 |
|
566 if ( lastRDate <= origUntilDate && startDT > lastRDate ) |
|
567 { |
|
568 if ( startDT < untilTime) |
|
569 { |
551 { |
570 if( origUntilDate != untilTime) |
552 // Find the duration of the entry |
|
553 TTime endTime = iEntry.EndTimeL().TimeLocalL(); |
|
554 TTimeIntervalMinutes duration; |
|
555 //startTime.MinutesFrom( endTime, duration );// for bug: CMCA-745CZ4 |
|
556 endTime.MinutesFrom( startTime, duration ); |
|
557 |
|
558 // Choose the first rDate as the new start time |
|
559 TCalTime newStartTime = rDateList[ 0 ]; |
|
560 endTime = newStartTime.TimeLocalL() + duration; |
|
561 |
|
562 // FIXME. |
|
563 // If there is only one rDate left, the agenda model |
|
564 // will crash if it is deleted. |
|
565 if ( count != 0 ) |
571 { |
566 { |
572 ApplyUntilDateToRRuleL( rRule, untilTime); |
567 rDateList.Remove( 0 ); |
573 iEntry.SetRRuleL( rRule ); |
|
574 } |
568 } |
575 } |
569 |
576 else |
570 TCalTime newEndTime; |
577 { |
571 if ( UseFloatingTimeL() ) |
578 // The repeat start is after the until date |
|
579 // so remove any repeat information. |
|
580 iEntry.ClearRepeatingPropertiesL(); |
|
581 |
|
582 // If the entry date has been moved past the until |
|
583 // date, need to swap the an rDate for the entry. |
|
584 TTime startTime = iEntry.StartTimeL().TimeLocalL(); |
|
585 |
|
586 if ( startTime > untilTime ) |
|
587 { |
572 { |
588 // Find the duration of the entry |
573 newEndTime.SetTimeLocalFloatingL( endTime ); |
589 TTime endTime = iEntry.EndTimeL().TimeLocalL(); |
574 } |
590 TTimeIntervalMinutes duration; |
575 else |
591 //startTime.MinutesFrom( endTime, duration );// for bug: CMCA-745CZ4 |
576 { |
592 endTime.MinutesFrom( startTime, duration ); |
577 newEndTime.SetTimeLocalL( endTime ); |
593 |
578 } |
594 // Choose the first rDate as the new start time |
579 |
595 TCalTime newStartTime = rDateList[ 0 ]; |
580 iEntry.SetStartAndEndTimeL( newStartTime, newEndTime ); |
596 endTime = newStartTime.TimeLocalL() + duration; |
581 } |
597 |
|
598 // FIXME. |
|
599 // If there is only one rDate left, the agenda model |
|
600 // will crash if it is deleted. |
|
601 if ( count != 0 ) |
|
602 { |
|
603 rDateList.Remove( 0 ); |
|
604 } |
|
605 |
|
606 TCalTime newEndTime; |
|
607 if ( UseFloatingTimeL() ) |
|
608 { |
|
609 newEndTime.SetTimeLocalFloatingL( endTime ); |
|
610 } |
|
611 else |
|
612 { |
|
613 newEndTime.SetTimeLocalL( endTime ); |
|
614 } |
|
615 |
|
616 iEntry.SetStartAndEndTimeL( newStartTime, newEndTime ); |
|
617 } |
|
618 } |
|
619 } |
582 } |
620 } |
583 } |
621 } |
584 } |
622 |
|
623 iEntry.SetRDatesL( rDateList ); |
|
624 } |
585 } |
625 |
586 |
626 CleanupStack::PopAndDestroy(); // rDateList |
587 iEntry.SetRDatesL( rDateList ); |
627 } |
588 } |
628 } |
589 |
629 else |
590 CleanupStack::PopAndDestroy(); // rDateList |
630 { |
591 } |
631 iEntry.ClearRepeatingPropertiesL(); |
592 } |
632 |
593 else |
633 // FIXME As the entry is supposedly not repeating |
594 { |
634 // any rDates should be removed. Unforunately this |
595 iEntry.ClearRepeatingPropertiesL(); |
635 // is not possible at the moment because removing the |
596 |
636 // rdates will cause the agenda model to panic |
597 // FIXME As the entry is supposedly not repeating |
637 // |
598 // any rDates should be removed. Unforunately this |
638 // RArray<TCalTime> emptyList; |
599 // is not possible at the moment because removing the |
639 // CleanupClosePushL( emptyList ); |
600 // rdates will cause the agenda model to panic |
640 // iEntry.SetRDatesL( emptyList ); |
601 // |
641 // CleanupStack::PopAndDestroy(); // emptyList |
602 // RArray<TCalTime> emptyList; |
642 } |
603 // CleanupClosePushL( emptyList ); |
|
604 // iEntry.SetRDatesL( emptyList ); |
|
605 // CleanupStack::PopAndDestroy(); // emptyList |
643 } |
606 } |
644 } |
607 } |
645 |
608 |
646 if ( isNew || IsAlarmEditedL() && ( iEntry.StatusL() != CCalEntry::ETodoCompleted ) ) |
609 if ( isNew || IsAlarmEditedL() && ( iEntry.StatusL() != CCalEntry::ETodoCompleted ) ) |
647 { |
610 { |