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