meetingrequest/mrdb/src/cesmrcaldbmgr.cpp
branchRCL_3
changeset 33 da5135c61bad
parent 0 8466d47a6819
child 19 b13141f05c3d
equal deleted inserted replaced
32:a3a1ae9acec6 33:da5135c61bad
     1 /*
     1 /*
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    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 
    67  */
   101  */
    68 void Panic( TPanicCode aReason )
   102 void Panic( TPanicCode aReason )
    69     {
   103     {
    70     User::Panic( KPanicMsg, aReason );
   104     User::Panic( KPanicMsg, aReason );
    71     }
   105     }
    72 
       
    73 #endif // _DEBUG
       
    74 
   106 
    75 }  // namespace
   107 }  // namespace
    76 
   108 
    77 
   109 
    78 // ======== MEMBER FUNCTIONS ========
   110 // ======== MEMBER FUNCTIONS ========
    92                 aObserver );
   124                 aObserver );
    93     CleanupStack::PushL( self );
   125     CleanupStack::PushL( self );
    94     self->ConstructL();
   126     self->ConstructL();
    95     CleanupStack::Pop();
   127     CleanupStack::Pop();
    96 
   128 
    97 
       
    98     return self;
   129     return self;
    99     }
   130     }
   100 
   131 
   101 // ----------------------------------------------------------------------------
   132 // ----------------------------------------------------------------------------
   102 // CESMRCalDbMgr::CESMRCalDbMgr
   133 // CESMRCalDbMgr::CESMRCalDbMgr
   121 // ----------------------------------------------------------------------------
   152 // ----------------------------------------------------------------------------
   122 //
   153 //
   123 CESMRCalDbMgr::~CESMRCalDbMgr()
   154 CESMRCalDbMgr::~CESMRCalDbMgr()
   124     {
   155     {
   125     FUNC_LOG;
   156     FUNC_LOG;
       
   157 
       
   158     iCalInstanceViewArray.ResetAndDestroy();
       
   159     iCalEntryViewArray.ResetAndDestroy();
       
   160     iCalendarInfoArray.ResetAndDestroy();
       
   161     iCalSessionArray.ResetAndDestroy();
       
   162 
   126     delete iCmdIterator;
   163     delete iCmdIterator;
   127     delete iNormalDb;
   164     delete iNormalDb;
   128     }
   165     }
   129 
   166 
   130 // ----------------------------------------------------------------------------
   167 // ----------------------------------------------------------------------------
   136     FUNC_LOG;
   173     FUNC_LOG;
   137 
   174 
   138     iNormalDb    = CESMRCalDbNormal::NewL( iCalSession, *this, *this );
   175     iNormalDb    = CESMRCalDbNormal::NewL( iCalSession, *this, *this );
   139     iCmdIterator = CESMREntryCmdIteratorAO::NewL( *this );
   176     iCmdIterator = CESMREntryCmdIteratorAO::NewL( *this );
   140 
   177 
       
   178     TRAPD( err, LoadMultiCalenInfoL() );
       
   179     __ASSERT_ALWAYS( err == KErrNone, Panic( EPanicLoadMultiDbInfoFail ) );
       
   180     User::LeaveIfError( err );
   141     }
   181     }
   142 
   182 
   143 // ----------------------------------------------------------------------------
   183 // ----------------------------------------------------------------------------
   144 // CESMRCalDbMgr::HandleCalDbStatus
   184 // CESMRCalDbMgr::HandleCalDbStatus
   145 // ----------------------------------------------------------------------------
   185 // ----------------------------------------------------------------------------
   166     else if ( iNormalDb->DbStatus() == MESMRCalDbObserver::EFinishedError )
   206     else if ( iNormalDb->DbStatus() == MESMRCalDbObserver::EFinishedError )
   167         {
   207         {
   168         iObserver.HandleCalEngStatus( MMRUtilsObserver::ENotAvailable );
   208         iObserver.HandleCalEngStatus( MMRUtilsObserver::ENotAvailable );
   169         }
   209         }
   170 
   210 
   171 
       
   172     // In other cases either db is not yet finished
   211     // In other cases either db is not yet finished
   173     }
   212     }
   174 
   213 
   175 // ----------------------------------------------------------------------------
   214 // ----------------------------------------------------------------------------
   176 // CESMRCalDbMgr::Progress
   215 // CESMRCalDbMgr::Progress
   201     {
   240     {
   202     FUNC_LOG;
   241     FUNC_LOG;
   203 
   242 
   204     iObserver.HandleOperation( iCurrentAsyncOp, KDbInitReady, aError );
   243     iObserver.HandleOperation( iCurrentAsyncOp, KDbInitReady, aError );
   205     iCurrentAsyncOp = CMRUtils::ENoOperation;
   244     iCurrentAsyncOp = CMRUtils::ENoOperation;
   206 
       
   207     }
   245     }
   208 
   246 
   209 // ----------------------------------------------------------------------------
   247 // ----------------------------------------------------------------------------
   210 // CESMRCalDbMgr::NormalDbEntryView
   248 // CESMRCalDbMgr::NormalDbEntryView
   211 // ----------------------------------------------------------------------------
   249 // ----------------------------------------------------------------------------
   222 //
   260 //
   223 CCalInstanceView* CESMRCalDbMgr::NormalDbInstanceView()
   261 CCalInstanceView* CESMRCalDbMgr::NormalDbInstanceView()
   224     {
   262     {
   225     FUNC_LOG;
   263     FUNC_LOG;
   226     return iNormalDb->InstanceView();
   264     return iNormalDb->InstanceView();
       
   265     }
       
   266 
       
   267 // ----------------------------------------------------------------------------
       
   268 // CESMRCalDbMgr::NormalDbAllCalenInstanceView
       
   269 // ----------------------------------------------------------------------------
       
   270 //
       
   271 RPointerArray<CCalInstanceView> CESMRCalDbMgr::NormalDbAllCalenInstanceView()
       
   272     {
       
   273     FUNC_LOG;
       
   274     return iCalInstanceViewArray;
   227     }
   275     }
   228 
   276 
   229 // ----------------------------------------------------------------------------
   277 // ----------------------------------------------------------------------------
   230 // CESMRCalDbMgr::FetchEntriesL
   278 // CESMRCalDbMgr::FetchEntriesL
   231 // ----------------------------------------------------------------------------
   279 // ----------------------------------------------------------------------------
   275         tmpFetchArray.Remove( index ); // ownership transferred to retVal
   323         tmpFetchArray.Remove( index ); // ownership transferred to retVal
   276         }
   324         }
   277 
   325 
   278     CleanupStack::PopAndDestroy(); // tmpFetchArray
   326     CleanupStack::PopAndDestroy(); // tmpFetchArray
   279 
   327 
   280 
       
   281     return retVal;
   328     return retVal;
   282     }
   329     }
   283 
   330 
   284 // ----------------------------------------------------------------------------
   331 // ----------------------------------------------------------------------------
   285 // CESMRCalDbMgr::StoreEntryL
   332 // CESMRCalDbMgr::StoreEntryL
   291     {
   338     {
   292     FUNC_LOG;
   339     FUNC_LOG;
   293 
   340 
   294     TInt retVal( KErrNone );
   341     TInt retVal( KErrNone );
   295 
   342 
   296     if(aToNormalDb)
   343     if ( CheckSpaceBelowCriticalLevelL() )
   297         {
   344         {
   298         CCalenInterimUtils2::StoreL( *( iNormalDb->EntryView() ),
   345         retVal = KErrNoMemory;
   299                                  aCalEntry,
   346         }
   300                                  ETrue );
   347 
   301 
   348     else
   302         }
   349         {
   303 
   350         if( aToNormalDb )
   304 
   351             {
       
   352             CCalenInterimUtils2::StoreL( *(iCalEntryViewArray[iCurCalenIndex]),
       
   353                                      aCalEntry,
       
   354                                      ETrue );
       
   355             WriteDatabaseIndexL( iCurCalenIndex );
       
   356             }
       
   357         }
   305 
   358 
   306     return retVal;
   359     return retVal;
   307     }
   360     }
   308 
   361 
   309 // ----------------------------------------------------------------------------
   362 // ----------------------------------------------------------------------------
   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 // ----------------------------------------------------------------------------
   481 
   547 
   482     if ( ESMREntryHelper::IsModifyingEntryL( aCalEntry ) )
   548     if ( ESMREntryHelper::IsModifyingEntryL( aCalEntry ) )
   483         {
   549         {
   484         // Modifying entry
   550         // Modifying entry
   485         // 1. Delete entry from normal db:
   551         // 1. Delete entry from normal db:
   486         iNormalDb->EntryView()->DeleteL( aCalEntry );
   552 
       
   553         CCalInstance* instance = FindInstanceL( (CCalEntry&)aCalEntry );
       
   554         CleanupStack::PushL( instance );
       
   555         TInt colId = instance->InstanceIdL().iCollectionId;
       
   556 
       
   557         TInt index = 0;
       
   558         TInt count = iCalSessionArray.Count();
       
   559         for( TInt i = 0; i < count; i++ )
       
   560             {
       
   561             if( colId == iCalSessionArray[i]->CollectionIdL() )
       
   562                 {
       
   563                 index = i;
       
   564                 break;
       
   565                 }
       
   566             }
       
   567         iCalEntryViewArray[index]->DeleteL( aCalEntry );
       
   568         CleanupStack::PopAndDestroy( instance );
   487         }
   569         }
   488 
   570 
   489     else
   571     else
   490         { // Originating entry, this is the same case as deleting with GUID:
   572         { // Originating entry, this is the same case as deleting with GUID:
   491         DeleteEntryCondL( aCalEntry.UidL() );
   573         DeleteEntryCondL( aCalEntry.UidL() );
   492         }
   574         }
   493 
       
   494     }
   575     }
   495 
   576 
   496 // ----------------------------------------------------------------------------
   577 // ----------------------------------------------------------------------------
   497 // CESMRCalDbMgr::DeleteEntryCondL
   578 // CESMRCalDbMgr::DeleteEntryCondL
   498 // ----------------------------------------------------------------------------
   579 // ----------------------------------------------------------------------------
   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() )
   553             retVal = ETrue;
  1014             retVal = ETrue;
   554             aIndex = i;
  1015             aIndex = i;
   555             }
  1016             }
   556         }
  1017         }
   557 
  1018 
   558 
       
   559     return retVal;
  1019     return retVal;
   560     }
  1020     }
   561 
  1021 
   562 // ----------------------------------------------------------------------------
  1022 // ----------------------------------------------------------------------------
   563 // CESMRCalDbMgr::EntryExistsInDbL
  1023 // CESMRCalDbMgr::EntryExistsInDbL
   585     const CCalEntry& aEntry,
  1045     const CCalEntry& aEntry,
   586     const CCalEntry& aDbEntry ) const
  1046     const CCalEntry& aDbEntry ) const
   587     {
  1047     {
   588     FUNC_LOG;
  1048     FUNC_LOG;
   589 
  1049 
   590     __ASSERT_DEBUG( aEntry.UidL() == aEntry.UidL(),
  1050     __ASSERT_DEBUG( aEntry.UidL() == aDbEntry.UidL(),
   591                     Panic( EPanicUnexpectedUidValue ) );
  1051                     Panic( EPanicUnexpectedUidValue ) );
   592     MESMRUtilsTombsExt::TESMRUtilsDbResult retVal( MESMRUtilsTombsExt::EUndefined );
  1052 
       
  1053     MESMRUtilsTombsExt::TESMRUtilsDbResult retVal(
       
  1054             MESMRUtilsTombsExt::EUndefined );
   593 
  1055 
   594     TInt seq( aEntry.SequenceNumberL() );
  1056     TInt seq( aEntry.SequenceNumberL() );
   595     TInt dbSeq( aDbEntry.SequenceNumberL() );
  1057     TInt dbSeq( aDbEntry.SequenceNumberL() );
   596     TTime stamp = aEntry.DTStampL().TimeUtcL();
  1058     TTime stamp = aEntry.DTStampL().TimeUtcL();
   597     TTime dbStamp = aDbEntry.DTStampL().TimeUtcL();
  1059     TTime dbStamp = aDbEntry.DTStampL().TimeUtcL();
   615     else
  1077     else
   616         {
  1078         {
   617         retVal = MESMRUtilsTombsExt::EErrorObsolete;
  1079         retVal = MESMRUtilsTombsExt::EErrorObsolete;
   618         }
  1080         }
   619 
  1081 
   620 
       
   621     return retVal;
  1082     return retVal;
   622     }
  1083     }
   623 
  1084 
   624 // ----------------------------------------------------------------------------
  1085 // ----------------------------------------------------------------------------
   625 // CESMRCalDbMgr::EvaluateNewEntryL
  1086 // CESMRCalDbMgr::EvaluateNewEntryL
   640         }
  1101         }
   641     else
  1102     else
   642         {
  1103         {
   643         retVal = MESMRUtilsTombsExt::ECheckedValidNew;
  1104         retVal = MESMRUtilsTombsExt::ECheckedValidNew;
   644         }
  1105         }
   645 
       
   646 
  1106 
   647     return retVal;
  1107     return retVal;
   648     }
  1108     }
   649 
  1109 
   650 // ----------------------------------------------------------------------------
  1110 // ----------------------------------------------------------------------------
   664 
  1124 
   665     iNormalDb->InstanceView()->FindInstanceL( instances,
  1125     iNormalDb->InstanceView()->FindInstanceL( instances,
   666                                               CalCommon::EIncludeAppts,
  1126                                               CalCommon::EIncludeAppts,
   667                                               range );
  1127                                               range );
   668     TInt count( instances.Count() );
  1128     TInt count( instances.Count() );
       
  1129 
       
  1130     // The entry can also be in other calendar than the default one,
       
  1131     // so the instance view array should be checked in this case.
       
  1132     if( count == 0 )
       
  1133     	{
       
  1134 		TInt instanceViewCount = iCalInstanceViewArray.Count();
       
  1135 		for( TInt i(0); i < instanceViewCount; i++ )
       
  1136 			{
       
  1137 			iCalInstanceViewArray[i]->FindInstanceL( instances,
       
  1138 					                                 CalCommon::EIncludeAppts,
       
  1139                                                      range );
       
  1140 			}
       
  1141 		count = instances.Count();
       
  1142     	}
       
  1143 
   669     for ( TInt i( 0 ); i < count; ++i )
  1144     for ( TInt i( 0 ); i < count; ++i )
   670         {
  1145         {
   671         // When creating a new modifying entry, recurrence id must match
  1146         // When creating a new modifying entry, recurrence id must match
   672         // to an existing instance start time (later on start time may get
  1147         // to an existing instance start time (later on start time may get
   673         // modified whereas recurrence id remains unchanged).
  1148         // modified whereas recurrence id remains unchanged).
   678             break; // match found, ready to return
  1153             break; // match found, ready to return
   679             }
  1154             }
   680         }
  1155         }
   681     CleanupStack::PopAndDestroy(); // instances, delete array items
  1156     CleanupStack::PopAndDestroy(); // instances, delete array items
   682 
  1157 
   683 
       
   684     return retVal;
  1158     return retVal;
   685     }
  1159     }
   686 
  1160 
   687 // ----------------------------------------------------------------------------
  1161 // ----------------------------------------------------------------------------
   688 // CESMRCalDbMgr::OriginatingExistInDbL
  1162 // CESMRCalDbMgr::OriginatingExistInDbL
   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