21 #include "cesmrcaldbmgr.h" |
21 #include "cesmrcaldbmgr.h" |
22 #include "cesmrcaldbnormal.h" |
22 #include "cesmrcaldbnormal.h" |
23 #include "cesmrentrycmditeratorao.h" |
23 #include "cesmrentrycmditeratorao.h" |
24 #include "esmrhelper.h" |
24 #include "esmrhelper.h" |
25 #include "esmrentryhelper.h" |
25 #include "esmrentryhelper.h" |
26 //<cmail> |
26 #include "mesmrcalentry.h" |
27 #include "mesmrutilstombsext.h" |
27 #include "mesmrutilstombsext.h" |
28 //</cmail> |
28 #include "mruidomaincrkeys.h" |
29 |
29 |
30 // From System |
30 // From System |
31 #include <ct/rcpointerarray.h> |
31 #include <ct/rcpointerarray.h> |
32 #include <calsession.h> |
32 #include <calsession.h> |
33 #include <calentryview.h> |
33 #include <calentryview.h> |
34 #include <calinstance.h> |
34 #include <calinstance.h> |
35 #include <calinstanceview.h> |
35 #include <calinstanceview.h> |
36 #include <calentry.h> |
36 #include <calentry.h> |
37 #include <calcommon.h> |
37 #include <calcommon.h> |
38 #include <caluser.h> |
38 #include <caluser.h> |
39 #include <CalenInterimUtils2.h> |
39 #include <caleninterimutils2.h> |
|
40 #include <sysutil.h> |
|
41 #include <errorui.h> |
|
42 #include <coemain.h> |
|
43 #include <calcalendarinfo.h> |
|
44 #include <centralrepository.h> |
40 |
45 |
41 // CONSTANTS |
46 // CONSTANTS |
42 |
47 |
43 // Unnamed namespace for local definitions |
48 // Unnamed namespace for local definitions |
44 namespace { |
49 namespace { |
45 |
50 |
46 const TInt KDbInitReady = 100; |
51 const TInt KDbInitReady( 100 ); |
47 |
52 |
48 #ifdef _DEBUG |
53 /** |
|
54 * Reads last used database index from central repository |
|
55 * |
|
56 * @param aIndex on return contains the last used database index |
|
57 */ |
|
58 void ReadDatabaseIndexL( TInt& aIndex ) |
|
59 { |
|
60 FUNC_LOG; |
|
61 |
|
62 CRepository* repository = CRepository::NewLC( KCRUidESMRUIFeatures ); |
|
63 User::LeaveIfError( repository->Get( KMRUIDefaultCalDbIndex, aIndex ) ); |
|
64 CleanupStack::PopAndDestroy( repository ); |
|
65 } |
|
66 |
|
67 /** |
|
68 * Writes used database index into central repository |
|
69 * |
|
70 * @param database index |
|
71 */ |
|
72 void WriteDatabaseIndexL( TInt aIndex ) |
|
73 { |
|
74 FUNC_LOG; |
|
75 |
|
76 CRepository* repository = CRepository::NewLC( KCRUidESMRUIFeatures ); |
|
77 User::LeaveIfError( repository->Set( KMRUIDefaultCalDbIndex, aIndex ) ); |
|
78 CleanupStack::PopAndDestroy( repository ); |
|
79 } |
|
80 |
49 |
81 |
50 // Panic code definitions |
82 // Panic code definitions |
51 enum TPanicCode |
83 enum TPanicCode |
52 { |
84 { |
53 EPanicIllegalFetchParams = 1, |
85 EPanicIllegalFetchParams = 1, |
54 EPanicAccessedWhenUnavailable, |
86 EPanicAccessedWhenUnavailable, |
55 EPanicAsyncOpAlreadyExists, |
87 EPanicAsyncOpAlreadyExists, |
56 EPanicIllegalEntryStatus, |
88 EPanicIllegalEntryStatus, |
57 EPanicIllegalResurrect, |
89 EPanicIllegalResurrect, |
58 EPanicUnexpectedUidValue |
90 EPanicUnexpectedUidValue, |
|
91 EPanicLoadMultiDbInfoFail, |
|
92 EPanicInvalidDbIndex |
59 }; |
93 }; |
60 |
94 |
61 // Panic string definition |
95 // Panic string definition |
62 _LIT( KPanicMsg, "CESMRCalDbMgr" ); |
96 _LIT( KPanicMsg, "CESMRCalDbMgr" ); |
63 |
97 |
317 RPointerArray<CCalEntry> calEntryTmpArray( 1 ); // entry not own |
370 RPointerArray<CCalEntry> calEntryTmpArray( 1 ); // entry not own |
318 CleanupClosePushL( calEntryTmpArray ); |
371 CleanupClosePushL( calEntryTmpArray ); |
319 calEntryTmpArray.AppendL( &aCalEntry ); |
372 calEntryTmpArray.AppendL( &aCalEntry ); |
320 TInt numSuccessfulEntry( 0 ); |
373 TInt numSuccessfulEntry( 0 ); |
321 // entry view surely exists when status is 'available': |
374 // entry view surely exists when status is 'available': |
322 iNormalDb->EntryView()->UpdateL( calEntryTmpArray, numSuccessfulEntry ); |
375 EntryViewL( aCalEntry )->UpdateL( calEntryTmpArray, numSuccessfulEntry ); |
323 TInt retVal( numSuccessfulEntry == 1 ? KErrNone : KErrGeneral ); |
376 TInt retVal( numSuccessfulEntry == 1 ? KErrNone : KErrGeneral ); |
324 CleanupStack::PopAndDestroy(); // calEntryTmpArray, only close array |
377 CleanupStack::Pop(); // calEntryTmpArray, only close array |
325 |
|
326 |
378 |
327 return retVal; |
379 return retVal; |
328 } |
380 } |
329 |
381 |
330 // ---------------------------------------------------------------------------- |
382 // ---------------------------------------------------------------------------- |
331 // CESMRCalDbMgr::DeleteEntryL |
383 // CESMRCalDbMgr::DeleteEntryL |
332 // ---------------------------------------------------------------------------- |
384 // ---------------------------------------------------------------------------- |
333 // |
385 // |
334 TInt CESMRCalDbMgr::DeleteEntryL( const TDesC8& aUid ) |
386 TInt CESMRCalDbMgr::DeleteEntryL( const TDesC8& aUid, TInt aCalenIndex ) |
335 { |
387 { |
336 FUNC_LOG; |
388 FUNC_LOG; |
337 |
389 |
338 CDesC8ArrayFlat* uidArray = new( ELeave ) CDesC8ArrayFlat( 1 ); |
390 CDesC8ArrayFlat* uidArray = new( ELeave ) CDesC8ArrayFlat( 1 ); |
339 CleanupStack::PushL( uidArray ); |
391 CleanupStack::PushL( uidArray ); |
340 uidArray->AppendL( aUid ); |
392 uidArray->AppendL( aUid ); |
341 // entry view surely exists when status is 'available': |
393 // entry view surely exists when status is 'available': |
342 iNormalDb->EntryView()->DeleteL( *uidArray ); |
394 iCalEntryViewArray[aCalenIndex]->DeleteL( *uidArray ); |
343 CleanupStack::PopAndDestroy( uidArray ); |
395 CleanupStack::PopAndDestroy( uidArray ); |
344 |
396 |
345 |
|
346 return KErrNone; |
397 return KErrNone; |
347 } |
398 } |
348 |
399 |
349 // ---------------------------------------------------------------------------- |
400 // ---------------------------------------------------------------------------- |
350 // CESMRCalDbMgr::DeleteEntryL |
401 // CESMRCalDbMgr::DeleteEntryL |
351 // ---------------------------------------------------------------------------- |
402 // ---------------------------------------------------------------------------- |
352 // |
403 // |
353 TInt CESMRCalDbMgr::DeleteEntryL( const TCalLocalUid& aLocalUid ) |
404 TInt CESMRCalDbMgr::DeleteEntryL( const TCalLocalUid& aLocalUid, TInt aCalenIndex ) |
354 { |
405 { |
355 FUNC_LOG; |
406 FUNC_LOG; |
356 |
407 |
357 RArray<TCalLocalUid> localUidArray( 1 ); |
408 RArray<TCalLocalUid> localUidArray( 1 ); |
358 CleanupClosePushL( localUidArray ); |
409 CleanupClosePushL( localUidArray ); |
359 localUidArray.AppendL( aLocalUid ); |
410 localUidArray.AppendL( aLocalUid ); |
360 TInt numSuccessfulEntry( 0 ); |
411 TInt numSuccessfulEntry( 0 ); |
361 iNormalDb->EntryView()->DeleteL( localUidArray, numSuccessfulEntry ); |
412 iCalEntryViewArray[aCalenIndex]->DeleteL( localUidArray, numSuccessfulEntry ); |
362 TInt retVal( numSuccessfulEntry == 1 ? KErrNone : KErrGeneral ); |
413 TInt retVal( numSuccessfulEntry == 1 ? KErrNone : KErrGeneral ); |
363 CleanupStack::PopAndDestroy(); // localUidArray |
414 CleanupStack::PopAndDestroy(); // localUidArray |
364 |
415 |
365 |
416 |
366 return retVal; |
417 return retVal; |
376 CCalEntry& aCalEntry, |
427 CCalEntry& aCalEntry, |
377 TBool aResurrect, |
428 TBool aResurrect, |
378 TBool aCheckOnly ) |
429 TBool aCheckOnly ) |
379 { |
430 { |
380 FUNC_LOG; |
431 FUNC_LOG; |
|
432 MESMRUtilsTombsExt::TESMRUtilsDbResult entryStatus( |
|
433 MESMRUtilsTombsExt::EUndefined ); |
|
434 |
|
435 if ( CheckSpaceBelowCriticalLevelL() ) |
|
436 { |
|
437 entryStatus = MESMRUtilsTombsExt::EErrorCancelled; |
|
438 } |
|
439 else |
|
440 { |
|
441 RCPointerArray<CCalEntry> tmpFetchArray; |
|
442 CleanupClosePushL( tmpFetchArray ); |
|
443 |
|
444 TInt index( -1 ); |
|
445 |
|
446 // 1. Normal db part, if entry is found in there then tombstones aren't |
|
447 // checked at all: |
|
448 |
|
449 if ( EntryExistsInDbL( aCalEntry, *iNormalDb, tmpFetchArray, index ) ) |
|
450 { // Entry exists in normal db |
|
451 entryStatus = EvaluateExistingEntryL( aCalEntry, |
|
452 *( tmpFetchArray[index] ) ); |
|
453 if ( entryStatus == MESMRUtilsTombsExt::ECheckedValidUpdate && |
|
454 !aCheckOnly ) |
|
455 { |
|
456 StoreEntryL( aCalEntry ); |
|
457 entryStatus = MESMRUtilsTombsExt::EStoredUpdate; |
|
458 } |
|
459 else if ( entryStatus == MESMRUtilsTombsExt::EErrorCancelled && |
|
460 aResurrect ) |
|
461 { |
|
462 __ASSERT_DEBUG( !aCheckOnly, Panic( EPanicIllegalResurrect ) ); |
|
463 StoreEntryL( aCalEntry ); |
|
464 entryStatus = MESMRUtilsTombsExt::EResurrectedCancelled; |
|
465 } |
|
466 // entry can't be new if it exists in the db already: |
|
467 __ASSERT_DEBUG( entryStatus != MESMRUtilsTombsExt::ECheckedValidNew, |
|
468 Panic( EPanicIllegalEntryStatus) ); |
|
469 } |
|
470 |
|
471 // 2. New entry in this phone: |
|
472 |
|
473 else |
|
474 { // Completely new entry (or tombstone has disappeared) |
|
475 entryStatus = EvaluateNewEntryL( aCalEntry ); |
|
476 if ( entryStatus == MESMRUtilsTombsExt::ECheckedValidNew && !aCheckOnly ) |
|
477 { |
|
478 StoreEntryL( aCalEntry ); |
|
479 entryStatus = MESMRUtilsTombsExt::EStoredNew; |
|
480 } |
|
481 |
|
482 // entry can't be update if doesn't exist in the db already: |
|
483 __ASSERT_DEBUG( entryStatus != MESMRUtilsTombsExt::ECheckedValidUpdate, |
|
484 Panic( EPanicIllegalEntryStatus) ); |
|
485 } |
|
486 |
|
487 CleanupStack::PopAndDestroy(); // tmpFetchArray |
|
488 } |
|
489 |
|
490 return entryStatus; |
|
491 } |
|
492 |
|
493 // ---------------------------------------------------------------------------- |
|
494 // CESMRCalDbMgr::DeleteEntryCondL |
|
495 // ---------------------------------------------------------------------------- |
|
496 // |
|
497 void CESMRCalDbMgr::DeleteEntryCondL( const TDesC8& aUid ) |
|
498 { |
|
499 FUNC_LOG; |
381 |
500 |
382 RCPointerArray<CCalEntry> tmpFetchArray; |
501 RCPointerArray<CCalEntry> tmpFetchArray; |
383 CleanupClosePushL( tmpFetchArray ); |
502 CleanupClosePushL( tmpFetchArray ); |
384 |
503 |
385 MESMRUtilsTombsExt::TESMRUtilsDbResult entryStatus( |
504 // 1. Delete all found entries from normal db: |
386 MESMRUtilsTombsExt::EUndefined ); |
505 TInt count = iCalEntryViewArray.Count(); |
387 TInt index( -1 ); |
506 for( TInt i(0); i < count; i++ ) |
388 |
507 { |
389 // 1. Normal db part, if entry is found in there then tombstones aren't |
508 iCalEntryViewArray[i]->FetchL( aUid, tmpFetchArray ); |
390 // checked at all: |
509 if( tmpFetchArray.Count() > 0 ) |
391 |
510 { |
392 if ( EntryExistsInDbL( aCalEntry, *iNormalDb, tmpFetchArray, index ) ) |
511 DeleteEntryL( aUid, i ); |
393 { // Entry exists in normal db |
512 tmpFetchArray.ResetAndDestroy(); |
394 entryStatus = EvaluateExistingEntryL( aCalEntry, |
513 } |
395 *( tmpFetchArray[index] ) ); |
|
396 if ( entryStatus == MESMRUtilsTombsExt::ECheckedValidUpdate && |
|
397 !aCheckOnly ) |
|
398 { |
|
399 StoreEntryL( aCalEntry ); |
|
400 entryStatus = MESMRUtilsTombsExt::EStoredUpdate; |
|
401 } |
|
402 else if ( entryStatus == MESMRUtilsTombsExt::EErrorCancelled && |
|
403 aResurrect ) |
|
404 { |
|
405 __ASSERT_DEBUG( !aCheckOnly, Panic( EPanicIllegalResurrect ) ); |
|
406 StoreEntryL( aCalEntry ); |
|
407 entryStatus = MESMRUtilsTombsExt::EResurrectedCancelled; |
|
408 } |
|
409 // entry can't be new if it exists in the db already: |
|
410 __ASSERT_DEBUG( entryStatus != MESMRUtilsTombsExt::ECheckedValidNew, |
|
411 Panic( EPanicIllegalEntryStatus) ); |
|
412 } |
|
413 |
|
414 // 2. New entry in this phone: |
|
415 |
|
416 else |
|
417 { // Completely new entry (or tombstone has disappeared) |
|
418 entryStatus = EvaluateNewEntryL( aCalEntry ); |
|
419 if ( entryStatus == MESMRUtilsTombsExt::ECheckedValidNew && !aCheckOnly ) |
|
420 { |
|
421 StoreEntryL( aCalEntry ); |
|
422 entryStatus = MESMRUtilsTombsExt::EStoredNew; |
|
423 } |
|
424 |
|
425 // entry can't be update if doesn't exist in the db already: |
|
426 __ASSERT_DEBUG( entryStatus != MESMRUtilsTombsExt::ECheckedValidUpdate, |
|
427 Panic( EPanicIllegalEntryStatus) ); |
|
428 } |
514 } |
429 |
515 |
430 CleanupStack::PopAndDestroy(); // tmpFetchArray |
516 CleanupStack::PopAndDestroy(); // tmpFetchArray |
431 |
|
432 |
|
433 return entryStatus; |
|
434 } |
517 } |
435 |
518 |
436 // ---------------------------------------------------------------------------- |
519 // ---------------------------------------------------------------------------- |
437 // CESMRCalDbMgr::DeleteEntryCondL |
520 // CESMRCalDbMgr::DeleteEntryCondL |
438 // ---------------------------------------------------------------------------- |
521 // ---------------------------------------------------------------------------- |
439 // |
522 // |
440 void CESMRCalDbMgr::DeleteEntryCondL( const TDesC8& aUid ) |
|
441 { |
|
442 FUNC_LOG; |
|
443 |
|
444 RCPointerArray<CCalEntry> tmpFetchArray; |
|
445 CleanupClosePushL( tmpFetchArray ); |
|
446 |
|
447 // 1. Delete all found entries from normal db: |
|
448 |
|
449 iNormalDb->EntryView()->FetchL( aUid, tmpFetchArray ); |
|
450 DeleteEntryL( aUid ); |
|
451 |
|
452 CleanupStack::PopAndDestroy(); // tmpFetchArray |
|
453 |
|
454 } |
|
455 |
|
456 // ---------------------------------------------------------------------------- |
|
457 // CESMRCalDbMgr::DeleteEntryCondL |
|
458 // ---------------------------------------------------------------------------- |
|
459 // |
|
460 void CESMRCalDbMgr::DeleteEntryCondL( const TCalLocalUid& aLocalUid ) |
523 void CESMRCalDbMgr::DeleteEntryCondL( const TCalLocalUid& aLocalUid ) |
461 { |
524 { |
462 FUNC_LOG; |
525 FUNC_LOG; |
463 |
526 |
464 CCalEntry* entry = iNormalDb->EntryView()->FetchL( aLocalUid ); |
527 TInt count = iCalEntryViewArray.Count(); |
465 if ( entry ) |
528 for( TInt i(0); i < count; i++ ) |
466 { |
529 { |
467 CleanupStack::PushL( entry ); |
530 CCalEntry* entry = iCalEntryViewArray[i]->FetchL( aLocalUid ); |
468 DeleteEntryCondL( *entry ); |
531 if ( entry ) |
469 CleanupStack::PopAndDestroy( entry ); |
532 { |
470 } |
533 CleanupStack::PushL( entry ); |
471 |
534 DeleteEntryCondL( *entry ); |
|
535 CleanupStack::PopAndDestroy( entry ); |
|
536 } |
|
537 } |
472 } |
538 } |
473 |
539 |
474 // ---------------------------------------------------------------------------- |
540 // ---------------------------------------------------------------------------- |
475 // CESMRCalDbMgr::DeleteEntryCondL |
541 // CESMRCalDbMgr::DeleteEntryCondL |
476 // ---------------------------------------------------------------------------- |
542 // ---------------------------------------------------------------------------- |
525 FUNC_LOG; |
606 FUNC_LOG; |
526 return iCalSession; |
607 return iCalSession; |
527 } |
608 } |
528 |
609 |
529 // ---------------------------------------------------------------------------- |
610 // ---------------------------------------------------------------------------- |
|
611 // CESMRCalDbMgr::FindInstanceL |
|
612 // ---------------------------------------------------------------------------- |
|
613 // |
|
614 CCalInstance* CESMRCalDbMgr::FindInstanceL( |
|
615 const CCalEntry& aEntry ) |
|
616 { |
|
617 FUNC_LOG; |
|
618 |
|
619 CCalInstance* instance = NULL; |
|
620 RCPointerArray<CCalInstance> calInstances; |
|
621 CleanupClosePushL( calInstances ); |
|
622 |
|
623 CalCommon::TCalViewFilter instanceFilter = |
|
624 CalCommon::EIncludeAppts | |
|
625 CalCommon::EIncludeEvents | |
|
626 CalCommon::EIncludeReminder | |
|
627 CalCommon::EIncludeAnnivs | |
|
628 CalCommon::EIncludeCompletedTodos | |
|
629 CalCommon::EIncludeIncompletedTodos; |
|
630 |
|
631 // Removing one seconds from start time and adding one second to stop |
|
632 // time. Otherwise wanted entry is not included into results. |
|
633 TCalTime startTime; |
|
634 startTime.SetTimeLocalL( |
|
635 aEntry.StartTimeL().TimeLocalL() - TTimeIntervalSeconds( 1 ) ); |
|
636 TCalTime endTime; |
|
637 endTime.SetTimeLocalL( |
|
638 aEntry.EndTimeL().TimeLocalL() + TTimeIntervalSeconds( 1 ) ); |
|
639 |
|
640 TDateTime start = startTime.TimeLocalL().DateTime(); |
|
641 TDateTime end = endTime.TimeLocalL().DateTime(); |
|
642 |
|
643 CalCommon::TCalTimeRange timeRange( |
|
644 startTime, |
|
645 endTime ); |
|
646 |
|
647 |
|
648 TInt count = iCalInstanceViewArray.Count(); |
|
649 for( TInt i = 0; i < count && !instance; i++ ) |
|
650 { |
|
651 iCalInstanceViewArray[i]->FindInstanceL( |
|
652 calInstances, |
|
653 instanceFilter, |
|
654 timeRange); |
|
655 if( calInstances.Count() > 0 ) |
|
656 { |
|
657 TInt instanceCount( calInstances.Count() ); |
|
658 for (TInt i = 0; (i < instanceCount && !instance); ++i) |
|
659 { |
|
660 CCalEntry& entry = calInstances[i]->Entry(); |
|
661 |
|
662 // Finding the entry we are intrested for |
|
663 if ( !entry.UidL().Compare( aEntry.UidL() ) ) |
|
664 { |
|
665 instance = calInstances[i]; |
|
666 calInstances.Remove( i ); |
|
667 } |
|
668 } |
|
669 } |
|
670 } |
|
671 |
|
672 CleanupStack::PopAndDestroy(); // arrayCleanup |
|
673 return instance; |
|
674 } |
|
675 |
|
676 // ---------------------------------------------------------------------------- |
|
677 // CESMRCalDbMgr::GetCalendarColorByEntryL |
|
678 // ---------------------------------------------------------------------------- |
|
679 // |
|
680 TRgb CESMRCalDbMgr::GetCalendarColorByEntryL(MESMRCalEntry& aEntry) |
|
681 { |
|
682 FUNC_LOG; |
|
683 TInt count = iCalSessionArray.Count(); |
|
684 TRgb color(0); |
|
685 if( count < 1 ) |
|
686 return color; |
|
687 |
|
688 if( !aEntry.IsStoredL() ) |
|
689 { |
|
690 color = iCalendarInfoArray[0]->Color(); |
|
691 } |
|
692 else |
|
693 { |
|
694 CCalInstance* instance = aEntry.InstanceL(); |
|
695 CleanupStack::PushL( instance ); |
|
696 TInt collectionId = instance->InstanceIdL().iCollectionId; |
|
697 |
|
698 for( TInt i = 0; i < count; i++ ) |
|
699 { |
|
700 if( collectionId == iCalSessionArray[i]->CollectionIdL() ) |
|
701 { |
|
702 color = iCalendarInfoArray[i]->Color(); |
|
703 break; |
|
704 } |
|
705 } |
|
706 |
|
707 CleanupStack::PopAndDestroy( instance ); |
|
708 } |
|
709 |
|
710 return color; |
|
711 } |
|
712 // ---------------------------------------------------------------------------- |
|
713 // CESMRCalDbMgr::GetMultiCalendarNameListL |
|
714 // ---------------------------------------------------------------------------- |
|
715 // |
|
716 void CESMRCalDbMgr::GetMultiCalendarNameListL(RArray<TPtrC>& aCalendarNameList) |
|
717 { |
|
718 FUNC_LOG; |
|
719 TInt count = iCalendarInfoArray.Count(); |
|
720 aCalendarNameList.ReserveL( count ); |
|
721 |
|
722 for( TInt i = 0; i < count; i++ ) |
|
723 { |
|
724 const TDesC& calenName = iCalendarInfoArray[i]->NameL(); |
|
725 aCalendarNameList.AppendL( TPtrC( calenName ) ); |
|
726 } |
|
727 } |
|
728 |
|
729 // ---------------------------------------------------------------------------- |
|
730 // CESMRCalDbMgr::GetCalendarNameByEntryL |
|
731 // ---------------------------------------------------------------------------- |
|
732 // |
|
733 TPtrC CESMRCalDbMgr::GetCalendarNameByEntryL(MESMRCalEntry& aEntry) |
|
734 { |
|
735 FUNC_LOG; |
|
736 |
|
737 TInt count = iCalSessionArray.Count(); |
|
738 |
|
739 TRgb color(0); |
|
740 TPtrC calenName; |
|
741 |
|
742 if( !aEntry.IsStoredL() ) |
|
743 { |
|
744 //while create new entry, use current calendar db |
|
745 if( count > 0 ) |
|
746 { |
|
747 calenName.Set(iCalendarInfoArray[iCurCalenIndex]->NameL()); |
|
748 } |
|
749 } |
|
750 else |
|
751 { |
|
752 CCalInstance* instance = NULL; |
|
753 TRAPD( err, instance = aEntry.InstanceL() ); |
|
754 CleanupStack::PushL( instance ); |
|
755 if( err == KErrNotFound || instance == NULL ) |
|
756 calenName.Set(iCalendarInfoArray[iCurCalenIndex]->NameL()); |
|
757 else |
|
758 { |
|
759 TInt collectionId = instance->InstanceIdL().iCollectionId; |
|
760 TBuf<16> val; |
|
761 |
|
762 for( TInt i = 0; i < count; i++ ) |
|
763 { |
|
764 if( collectionId == iCalSessionArray[i]->CollectionIdL() ) |
|
765 { |
|
766 calenName.Set(iCalendarInfoArray[i]->NameL()); |
|
767 break; |
|
768 } |
|
769 } |
|
770 } |
|
771 CleanupStack::PopAndDestroy( instance ); |
|
772 } |
|
773 |
|
774 return calenName; |
|
775 } |
|
776 |
|
777 // ---------------------------------------------------------------------------- |
|
778 // CESMRCalDbMgr::GetCalendarColorByNameL |
|
779 // ---------------------------------------------------------------------------- |
|
780 // |
|
781 TRgb CESMRCalDbMgr::GetCalendarColorByNameL(TDesC& aCalendarName) |
|
782 { |
|
783 FUNC_LOG; |
|
784 TInt count = iCalendarInfoArray.Count(); |
|
785 TRgb color(0); |
|
786 |
|
787 for ( TInt i = 0; i < count; i++) |
|
788 { |
|
789 if( aCalendarName.Compare( iCalendarInfoArray[i]->NameL() ) == 0 ) |
|
790 { |
|
791 color = iCalendarInfoArray[i]->Color(); |
|
792 } |
|
793 } |
|
794 |
|
795 return color; |
|
796 } |
|
797 |
|
798 // ---------------------------------------------------------------------------- |
|
799 // CESMRCalDbMgr::SetCurCalendarByNameL |
|
800 // ---------------------------------------------------------------------------- |
|
801 // |
|
802 void CESMRCalDbMgr::SetCurCalendarByNameL( TDesC& aCalendarName ) |
|
803 { |
|
804 FUNC_LOG; |
|
805 TInt count = iCalendarInfoArray.Count(); |
|
806 |
|
807 for( TInt i(0); i < count; i++ ) |
|
808 { |
|
809 if( aCalendarName.Compare( iCalendarInfoArray[i]->NameL() ) == 0 ) |
|
810 { |
|
811 SetCurCalendarByIndex( i ); |
|
812 break; |
|
813 } |
|
814 } |
|
815 } |
|
816 |
|
817 // ---------------------------------------------------------------------------- |
|
818 // CESMRCalDbMgr::SetCurCalendarByColIdL |
|
819 // ---------------------------------------------------------------------------- |
|
820 // |
|
821 void CESMRCalDbMgr::SetCurCalendarByColIdL( TInt aColId ) |
|
822 { |
|
823 FUNC_LOG; |
|
824 TInt count = iCalSessionArray.Count(); |
|
825 |
|
826 for( TInt i = 0; i < count; i++ ) |
|
827 { |
|
828 if( aColId == iCalSessionArray[i]->CollectionIdL() ) |
|
829 { |
|
830 SetCurCalendarByIndex( i ); |
|
831 break; |
|
832 } |
|
833 } |
|
834 } |
|
835 |
|
836 // ---------------------------------------------------------------------------- |
|
837 // CESMRCalDbMgr::SetCurCalendarByEntry |
|
838 // ---------------------------------------------------------------------------- |
|
839 // |
|
840 void CESMRCalDbMgr::SetCurCalendarByEntryL( MESMRCalEntry& aEntry ) |
|
841 { |
|
842 TPtrC calenName = GetCalendarNameByEntryL( aEntry ); |
|
843 SetCurCalendarByNameL( calenName ); |
|
844 } |
|
845 |
|
846 // ---------------------------------------------------------------------------- |
|
847 // CESMRCalDbMgr::SetCurCalendarByIndex |
|
848 // ---------------------------------------------------------------------------- |
|
849 // |
|
850 void CESMRCalDbMgr::SetCurCalendarByIndex( TInt aIndex ) |
|
851 { |
|
852 FUNC_LOG; |
|
853 iCurCalenIndex = aIndex; |
|
854 } |
|
855 |
|
856 // ---------------------------------------------------------------------------- |
|
857 // CESMRCalDbMgr::GetCurCalendarColor |
|
858 // ---------------------------------------------------------------------------- |
|
859 // |
|
860 TRgb CESMRCalDbMgr::GetCurCalendarColor() |
|
861 { |
|
862 FUNC_LOG; |
|
863 __ASSERT_ALWAYS( |
|
864 iCurCalenIndex < iCalendarInfoArray.Count(), |
|
865 Panic( EPanicInvalidDbIndex ) ); |
|
866 return iCalendarInfoArray[iCurCalenIndex]->Color(); |
|
867 } |
|
868 |
|
869 // ---------------------------------------------------------------------------- |
|
870 // CESMRCalDbMgr::GetCurCalendarColIdL |
|
871 // ---------------------------------------------------------------------------- |
|
872 // |
|
873 TInt CESMRCalDbMgr::GetCurCalendarColIdL() |
|
874 { |
|
875 FUNC_LOG; |
|
876 __ASSERT_ALWAYS( |
|
877 iCurCalenIndex < iCalSessionArray.Count(), |
|
878 Panic( EPanicInvalidDbIndex ) ); |
|
879 |
|
880 return iCalSessionArray[iCurCalenIndex]->CollectionIdL(); |
|
881 } |
|
882 |
|
883 // ---------------------------------------------------------------------------- |
|
884 // CESMRCalDbMgr::GetCurCalendarIndex |
|
885 // ---------------------------------------------------------------------------- |
|
886 // |
|
887 TInt CESMRCalDbMgr::GetCurCalendarIndex() |
|
888 { |
|
889 return iCurCalenIndex; |
|
890 } |
|
891 |
|
892 // ---------------------------------------------------------------------------- |
|
893 // CESMRCalDbMgr::EntryViewL |
|
894 // ---------------------------------------------------------------------------- |
|
895 // |
|
896 CCalEntryView* CESMRCalDbMgr::EntryViewL(const CCalEntry& aCalEntry ) |
|
897 { |
|
898 FUNC_LOG; |
|
899 CCalInstance* instance = FindInstanceL( aCalEntry ); |
|
900 if( !instance ) |
|
901 { |
|
902 return NULL; |
|
903 } |
|
904 |
|
905 CleanupStack::PushL( instance ); |
|
906 CCalEntryView* entryView = NULL; |
|
907 |
|
908 TInt colId = instance->InstanceIdL().iCollectionId; |
|
909 TInt count = iCalSessionArray.Count(); |
|
910 |
|
911 for( TInt i = 0; i < count; i++ ) |
|
912 { |
|
913 if( colId == iCalSessionArray[i]->CollectionIdL() ) |
|
914 { |
|
915 entryView = iCalEntryViewArray[i]; |
|
916 break; |
|
917 } |
|
918 } |
|
919 |
|
920 if ( !entryView ) |
|
921 { |
|
922 User::Leave( KErrNotFound ); |
|
923 } |
|
924 |
|
925 CleanupStack::PopAndDestroy( instance ); |
|
926 return entryView; |
|
927 } |
|
928 |
|
929 // ---------------------------------------------------------------------------- |
|
930 // CESMRCalDbMgr::InstanceViewL |
|
931 // ---------------------------------------------------------------------------- |
|
932 // |
|
933 CCalInstanceView* CESMRCalDbMgr::InstanceViewL(const CCalEntry& aCalEntry ) |
|
934 { |
|
935 FUNC_LOG; |
|
936 CCalInstance* instance = FindInstanceL( aCalEntry ); |
|
937 if( !instance ) |
|
938 { |
|
939 return NULL; |
|
940 } |
|
941 |
|
942 CleanupStack::PushL( instance ); |
|
943 CCalInstanceView* instanceView = NULL; |
|
944 |
|
945 TInt colId = instance->InstanceIdL().iCollectionId; |
|
946 TInt count = iCalSessionArray.Count(); |
|
947 |
|
948 for( TInt i = 0; i < count; i++ ) |
|
949 { |
|
950 if( colId == iCalSessionArray[i]->CollectionIdL() ) |
|
951 { |
|
952 instanceView = iCalInstanceViewArray[i]; |
|
953 break; |
|
954 } |
|
955 } |
|
956 |
|
957 if ( !instanceView ) |
|
958 { |
|
959 User::Leave( KErrNotFound ); |
|
960 } |
|
961 |
|
962 CleanupStack::PopAndDestroy( instance ); |
|
963 return instanceView; |
|
964 } |
|
965 |
|
966 // ---------------------------------------------------------------------------- |
|
967 // CESMRCalDbMgr::EntryView |
|
968 // ---------------------------------------------------------------------------- |
|
969 // |
|
970 CCalEntryView* CESMRCalDbMgr::EntryView() |
|
971 { |
|
972 FUNC_LOG; |
|
973 __ASSERT_ALWAYS( |
|
974 iCurCalenIndex < iCalEntryViewArray.Count(), |
|
975 Panic( EPanicInvalidDbIndex ) ); |
|
976 return iCalEntryViewArray[iCurCalenIndex]; |
|
977 } |
|
978 |
|
979 |
|
980 |
|
981 // ---------------------------------------------------------------------------- |
530 // CESMRCalDbMgr::EntryExistsInDbL |
982 // CESMRCalDbMgr::EntryExistsInDbL |
531 // ---------------------------------------------------------------------------- |
983 // ---------------------------------------------------------------------------- |
532 // |
984 // |
533 TBool CESMRCalDbMgr::EntryExistsInDbL( |
985 TBool CESMRCalDbMgr::EntryExistsInDbL( |
534 const TDesC8& aUid, |
986 const TDesC8& aUid, |
535 const TCalTime& aRecurrenceId, |
987 const TCalTime& aRecurrenceId, |
536 const CESMRCalDbBase& aDb, |
988 const CESMRCalDbBase& /*aDb*/, |
537 RPointerArray<CCalEntry>& aCalEntryArray, |
989 RPointerArray<CCalEntry>& aCalEntryArray, |
538 TInt& aIndex ) const |
990 TInt& aIndex ) const |
539 { |
991 { |
540 FUNC_LOG; |
992 FUNC_LOG; |
541 |
993 |
542 TBool retVal( EFalse ); |
994 TBool retVal( EFalse ); |
543 aIndex = KErrNotFound; |
995 aIndex = KErrNotFound; |
544 |
996 |
545 aDb.EntryView()->FetchL( aUid, aCalEntryArray ); |
997 TInt sessionCount = iCalSessionArray.Count(); |
|
998 for( TInt i = 0; i < sessionCount; i++ ) |
|
999 { |
|
1000 iCalEntryViewArray[i]->FetchL( aUid, aCalEntryArray ); |
|
1001 if( aCalEntryArray.Count() > 0) |
|
1002 { |
|
1003 break; |
|
1004 } |
|
1005 } |
|
1006 |
546 TInt count( aCalEntryArray.Count() ); |
1007 TInt count( aCalEntryArray.Count() ); |
547 for ( TInt i( 0 ); i < count; ++i ) |
1008 for ( TInt i( 0 ); i < count; ++i ) |
548 { |
1009 { |
549 const CCalEntry& dbEntry( *( aCalEntryArray[i] ) ); |
1010 const CCalEntry& dbEntry( *( aCalEntryArray[i] ) ); |
550 if ( aRecurrenceId.TimeUtcL() == dbEntry.RecurrenceIdL().TimeUtcL() ) |
1011 if ( aRecurrenceId.TimeUtcL() == dbEntry.RecurrenceIdL().TimeUtcL() ) |
700 { |
1174 { |
701 delete dbEntry; |
1175 delete dbEntry; |
702 retVal = ETrue; |
1176 retVal = ETrue; |
703 } |
1177 } |
704 |
1178 |
705 |
|
706 return retVal; |
1179 return retVal; |
707 } |
1180 } |
708 |
1181 |
|
1182 // --------------------------------------------------------------------------- |
|
1183 // CESMRCalDbMgr::CheckSpaceBelowCriticalLevelL |
|
1184 // --------------------------------------------------------------------------- |
|
1185 // |
|
1186 TBool CESMRCalDbMgr::CheckSpaceBelowCriticalLevelL() |
|
1187 { |
|
1188 FUNC_LOG; |
|
1189 |
|
1190 TBool retcode(EFalse); |
|
1191 |
|
1192 CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
1193 |
|
1194 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &( coeEnv->FsSession() ) ) ) |
|
1195 { |
|
1196 CErrorUI* errorUi = CErrorUI::NewLC(); |
|
1197 errorUi->ShowGlobalErrorNoteL( KErrDiskFull ); |
|
1198 CleanupStack::PopAndDestroy(); // errorUi |
|
1199 retcode = ETrue; |
|
1200 } |
|
1201 |
|
1202 return retcode; |
|
1203 } |
|
1204 |
|
1205 // --------------------------------------------------------------------------- |
|
1206 // CESMRCalDbMgr::LoadMultiCalenInfo |
|
1207 // --------------------------------------------------------------------------- |
|
1208 // |
|
1209 void CESMRCalDbMgr::LoadMultiCalenInfoL() |
|
1210 { |
|
1211 FUNC_LOG; |
|
1212 |
|
1213 CDesCArray* fileArray = iCalSession.ListCalFilesL(); |
|
1214 CleanupStack::PushL( fileArray ); |
|
1215 |
|
1216 TInt count = fileArray->Count(); |
|
1217 |
|
1218 iCalSessionArray.ReserveL( count ); |
|
1219 iCalEntryViewArray.ReserveL( count ); |
|
1220 iCalInstanceViewArray.ReserveL( count ); |
|
1221 iCalendarInfoArray.ReserveL( count ); |
|
1222 |
|
1223 for( TInt i = 0; i < count; i++ ) |
|
1224 { |
|
1225 CCalSession* file = CCalSession::NewL(); |
|
1226 CleanupStack::PushL( file ); |
|
1227 |
|
1228 const TDesC& fileName = (*fileArray)[i]; |
|
1229 file->OpenL( fileName ); |
|
1230 CCalCalendarInfo* calendarInfo = file->CalendarInfoL(); |
|
1231 |
|
1232 if( calendarInfo->IsValid() |
|
1233 && calendarInfo->Enabled() ) |
|
1234 { |
|
1235 // Push info into CleanupStack because NewL may leave |
|
1236 CleanupStack::PushL( calendarInfo ); |
|
1237 |
|
1238 CCalEntryView* entryView = CCalEntryView::NewL( *file ); |
|
1239 // Push entryView into CleanupStack because NewL may leave |
|
1240 CleanupStack::PushL( entryView ); |
|
1241 |
|
1242 CCalInstanceView* instanceView = CCalInstanceView::NewL( *file ); |
|
1243 |
|
1244 // Space has been reserved so AppendL won't leave |
|
1245 iCalInstanceViewArray.AppendL( instanceView ); |
|
1246 |
|
1247 iCalEntryViewArray.AppendL( entryView ); |
|
1248 CleanupStack::Pop( entryView ); |
|
1249 |
|
1250 iCalendarInfoArray.AppendL( calendarInfo ); |
|
1251 CleanupStack::Pop( calendarInfo ); |
|
1252 |
|
1253 iCalSessionArray.AppendL( file ); |
|
1254 CleanupStack::Pop( file ); |
|
1255 } |
|
1256 else |
|
1257 { |
|
1258 delete calendarInfo; |
|
1259 CleanupStack::PopAndDestroy( file ); |
|
1260 } |
|
1261 } |
|
1262 |
|
1263 CleanupStack::PopAndDestroy( fileArray ); |
|
1264 |
|
1265 // Restore default database index from repository |
|
1266 ReadDatabaseIndexL( iCurCalenIndex ); |
|
1267 } |
|
1268 |
|
1269 |
709 // End of file |
1270 // End of file |
710 |
1271 |
|
1272 |