calendarui/globaldata/src/calenglobaldata.cpp
changeset 0 f979ecb2b13e
child 13 0f07cd1b5772
child 17 b5a86db05ae8
child 18 c198609911f9
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Global Data for Calendar application
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //debug
       
    21 #include "calendarui_debug.h"
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include "calenglobaldata.h"        // CCalenGlobalData
       
    25 #include "RImplInfoPtrArrayOwn.inl" // Wrapper class with array deletion on close
       
    26 #include "calensend.h"              // CCalenSend
       
    27 #include "CalenInterimUtils2.h"     // CalenInterimUtils
       
    28 #include "calencontextimpl.h"       // Calendar context implementation
       
    29 #include "calenfilemapping.h"
       
    30 
       
    31 #include <Calendar.rsg>             // Calendar resources
       
    32 #include <cmrmailboxutils.h>        // CMRMailboxUtils
       
    33 #include <utf.h>                    // CnvUtfConverter
       
    34 #include <StringLoader.h>           // Loads strings from resource files
       
    35 #include <featmgr.h>                // Feature discovery API
       
    36 #include <calsession.h>             // Calendar database session
       
    37 #include <calinstanceview.h>        // Calendar Instance view
       
    38 #include <calentryview.h>           // Calendar Entry view
       
    39 #include <cmrmailboxutils.h>        // CMRMailboxUtils
       
    40 #include <calencommands.hrh>            // Calendar commands
       
    41 #include <aknlists.h>
       
    42 #include <aknPopup.h>
       
    43 #include <AknUtils.h>
       
    44 #include <AknQueryDialog.h>
       
    45 #include <calencontext.h>
       
    46 #include <calcalendarinfo.h>
       
    47 #include <calcalendariterator.h>
       
    48 #include <CalendarInternalCRKeys.h>
       
    49 #include <calenmulticalutil.h>
       
    50 
       
    51 // Default Calendar database path
       
    52 _LIT( KCalendarDatabaseFilePath, "c:calendar" );
       
    53 _LIT( KPhoneCalendar,"Personal" );
       
    54 _LIT( KExtCalendar,"Ext calendar" );
       
    55 const TInt KBuffLength = 24;
       
    56 
       
    57 // ============================ MEMBER FUNCTIONS ===============================
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CCalenGlobalData::CCalenGlobalData
       
    61 // C++ default constructor can NOT contain any code, that might leave.
       
    62 // (other items were commented in a header).
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CCalenGlobalData::CCalenGlobalData( MCalProgressCallBack& aCalCallBack )
       
    66     : iCalCallBack( aCalCallBack )
       
    67     {
       
    68     TRACE_ENTRY_POINT;
       
    69 
       
    70     iGlobalDataOwnsCalSession = EFalse;
       
    71     iGlobalDataOwnsEntryView = EFalse;
       
    72     
       
    73     iCalendarForcedExit = EFalse;
       
    74     
       
    75     TRACE_EXIT_POINT;
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // CCalenGlobalData::NewL
       
    80 // Two phased construction. This will leave if an instance of global data
       
    81 // already exists.  All access to an instance of the global data should be
       
    82 // through the InstanceL function, except for the initial construction
       
    83 // which should be handled by the controller.
       
    84 // (other items were commented in a header).
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C CCalenGlobalData* CCalenGlobalData::NewL( MCalProgressCallBack& aCalCallBack,
       
    88                                                    MCalenContextChangeObserver* aNotifier )
       
    89     {
       
    90     TRACE_ENTRY_POINT;
       
    91 
       
    92     CCalenGlobalData* self = NULL;
       
    93     TAny* tlsPtr = Dll::Tls();
       
    94 
       
    95     // Check Thread local storage
       
    96     if (!tlsPtr)
       
    97         {
       
    98         // TLS is NULL, so no CCalenGlobalData has been created yet.
       
    99         self = new( ELeave ) CCalenGlobalData( aCalCallBack );
       
   100         CleanupStack::PushL( self );
       
   101         // Store a self pointer in TLS
       
   102         User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( self ) ) );
       
   103         // Increment ref count right away. If we don't do it here, and someone
       
   104         // calls CCalenGlobalData::InstanceL in ConstructL and then ConstructL
       
   105         // leaves, we will double delete the global data.
       
   106         ++self->iRefCount;
       
   107         self->ConstructL( aNotifier );
       
   108         CleanupStack::Pop( self );
       
   109         }
       
   110     else
       
   111         {
       
   112         // An instance of the global data exists already.
       
   113         // This function should only have been called once, by CCalenAppUi
       
   114         User::Leave( KErrAlreadyExists );
       
   115         }
       
   116 
       
   117     TRACE_EXIT_POINT;
       
   118     return self;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CCalenGlobalData::InstanceL
       
   123 // Two-phased constructor.
       
   124 // (other items were commented in a header).
       
   125 // -----------------------------------------------------------------------------
       
   126 EXPORT_C CCalenGlobalData* CCalenGlobalData::InstanceL()
       
   127     {
       
   128     TRACE_ENTRY_POINT;
       
   129 
       
   130     CCalenGlobalData* self = NULL;
       
   131     TAny* tlsPtr = Dll::Tls();
       
   132 
       
   133     // Check Thread local storage
       
   134     if (!tlsPtr)
       
   135         {
       
   136         // The global data has not yet been constructed.
       
   137         // FIXME - Revise comment
       
   138         //TLS is NULL, so no CCalenGlobalData has been created yet.
       
   139       /*  self = new( ELeave ) CCalenGlobalData;
       
   140         CleanupStack::PushL( self );
       
   141         self->ConstructL();
       
   142         //Store a self pointer in TLS
       
   143         User::LeaveIfError( Dll::SetTls(static_cast<TAny*>(self)));
       
   144         CleanupStack::Pop(self);*/
       
   145         User::Leave( KErrNotReady );
       
   146         }
       
   147     else
       
   148         {
       
   149         self = static_cast<CCalenGlobalData*>( tlsPtr );
       
   150         }
       
   151 
       
   152     ++self->iRefCount;
       
   153 
       
   154     TRACE_EXIT_POINT;
       
   155     return self;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CCalenGlobalData::InstanceL
       
   160 // Two-phased constructor.  Creates the CCalenGlobalData with an existing
       
   161 // CCalSession.  CCalenGlobalData does NOT take ownership of the passed session
       
   162 // The caller is responsible for ensuring that the session exists until all
       
   163 // open references to the CCalenGlobalData are released.
       
   164 // Calls User::Invariant() if CCalenGlobalData already has a valid session.
       
   165 // (other items were commented in a header).
       
   166 // -----------------------------------------------------------------------------
       
   167 EXPORT_C CCalenGlobalData* CCalenGlobalData::InstanceL(CCalSession& aSession)
       
   168     {
       
   169     TRACE_ENTRY_POINT;
       
   170 
       
   171     CCalenGlobalData* self = CCalenGlobalData::InstanceL();
       
   172     CleanupStack::PushL(self);
       
   173     self->SetSessionL(&aSession);
       
   174     CleanupStack::Pop(self);
       
   175 
       
   176     TRACE_EXIT_POINT;
       
   177     return self;
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CCalenGlobalData::InstanceL
       
   182 // Non-leaving version of constructor. Returns an instance of
       
   183 // CCalenGlobalData if one exists or NULL otherwise
       
   184 // (other items were commented in a header).
       
   185 // -----------------------------------------------------------------------------
       
   186 EXPORT_C CCalenGlobalData* CCalenGlobalData::Instance()
       
   187     {
       
   188     TRACE_ENTRY_POINT;
       
   189 
       
   190     TAny* tlsPtr = Dll::Tls();
       
   191     CCalenGlobalData* self = static_cast<CCalenGlobalData*>( tlsPtr );
       
   192 
       
   193     if ( self )
       
   194         {
       
   195         ++self->iRefCount;
       
   196         }
       
   197 
       
   198     TRACE_EXIT_POINT;
       
   199     return self;
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CCalenGlobalData::ConstructL
       
   204 // Symbian 2nd phase constructor can leave.
       
   205 // (other items were commented in a header).
       
   206 // -----------------------------------------------------------------------------
       
   207 void CCalenGlobalData::ConstructL( MCalenContextChangeObserver* aNotifier )
       
   208     {
       
   209     TRACE_ENTRY_POINT;
       
   210 
       
   211     iContext = new (ELeave ) CCalenContextImpl( aNotifier );  
       
   212     
       
   213     iNewInstanceViewCreation = NULL;
       
   214     
       
   215     TRACE_EXIT_POINT;
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CCalenGlobalData::SetSessionL
       
   220 // Sets the CCalenGlobalData to use an externally created CCalSession.
       
   221 // Leaves with KErrAlreadyExists if a session has already been created by the
       
   222 // CCalenGlobalData
       
   223 // (other items were commented in a header).
       
   224 // -----------------------------------------------------------------------------
       
   225 void CCalenGlobalData::SetSessionL(CCalSession* aSession)
       
   226     {
       
   227     TRACE_ENTRY_POINT;
       
   228 
       
   229     if (iCalSession)
       
   230         {
       
   231         __ASSERT_ALWAYS(iCalSession == aSession, User::Leave(KErrAlreadyExists));
       
   232         }
       
   233     else
       
   234         {
       
   235         iGlobalDataOwnsCalSession = EFalse;
       
   236         iCalSession = aSession;
       
   237         }
       
   238 
       
   239     TRACE_EXIT_POINT;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CCalenGlobalData::Release
       
   244 // Release handle to CCalenGlobalData.  If no other objects are referencing
       
   245 // this class it will be deleted
       
   246 // (other items were commented in a header).
       
   247 // -----------------------------------------------------------------------------
       
   248 EXPORT_C void CCalenGlobalData::Release()
       
   249     {
       
   250     TRACE_ENTRY_POINT;
       
   251 
       
   252     --iRefCount;
       
   253     if (iRefCount == 0)
       
   254         {
       
   255         delete this;
       
   256         }
       
   257 
       
   258     TRACE_EXIT_POINT;
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // Destructor
       
   263 // This is private and should only be called from the Release() function above
       
   264 // (other items were commented in a header).
       
   265 // -----------------------------------------------------------------------------
       
   266 CCalenGlobalData::~CCalenGlobalData()
       
   267     {
       
   268     TRACE_ENTRY_POINT;
       
   269 
       
   270     delete iSend;
       
   271     delete iInterimUtils;
       
   272     delete iUtilsAs;
       
   273     delete iMailboxUtils;
       
   274     delete iMRUtils;
       
   275 
       
   276     if (iInstanceView)
       
   277         {
       
   278         delete iInstanceView;
       
   279         iInstanceView = NULL;
       
   280         }
       
   281 
       
   282     if (iInstanceViewCreation)
       
   283         {
       
   284         delete iInstanceViewCreation;
       
   285         iInstanceViewCreation = NULL;
       
   286         }
       
   287 
       
   288     if (iEntryViewCreation)
       
   289         {
       
   290         delete iEntryViewCreation;
       
   291         iEntryViewCreation = NULL;
       
   292         }
       
   293 
       
   294     if (iNewInstanceViewCreation)
       
   295         {
       
   296         delete iNewInstanceViewCreation;
       
   297         iNewInstanceViewCreation = NULL;
       
   298         }
       
   299 
       
   300     if (iNewInstanceView)
       
   301         {
       
   302         delete iNewInstanceView;
       
   303         iNewInstanceView = NULL;
       
   304         }
       
   305 
       
   306     delete iContext;
       
   307     
       
   308     if(iGlobalDataOwnsEntryView)
       
   309         {
       
   310         if(iEntryView)
       
   311             {
       
   312             delete iEntryView;
       
   313             iEntryView = NULL;           
       
   314             }
       
   315         }
       
   316 
       
   317    if (iGlobalDataOwnsCalSession)
       
   318         {
       
   319         delete iCalSession;
       
   320         }
       
   321     
       
   322     if( iFileMappingArray.Count() )
       
   323         {
       
   324         iFileMappingArray.ResetAndDestroy();
       
   325         }
       
   326     
       
   327     iKeyQueue.Reset();
       
   328     
       
   329     iHashDbidIndexMap.Close();
       
   330 
       
   331     Dll::SetTls(NULL);
       
   332 
       
   333     if (iCalendarInfoList.Count())
       
   334         {
       
   335         iCalendarInfoList.ResetAndDestroy();
       
   336         }
       
   337 
       
   338     if (iCalendarsSession)
       
   339         {
       
   340         delete iCalendarsSession;
       
   341         iCalendarsSession = NULL;
       
   342         }
       
   343 
       
   344     TRACE_EXIT_POINT;
       
   345     }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CCalenGlobalData::MailboxUtilsL
       
   349 // Create MailBoxUtils if necessary and returns a reference
       
   350 // (other items were commented in a header).
       
   351 // -----------------------------------------------------------------------------
       
   352 EXPORT_C CMRMailboxUtils& CCalenGlobalData::MRMailboxUtilsL()
       
   353     {
       
   354     TRACE_ENTRY_POINT;
       
   355 
       
   356     if (!iMailboxUtils)
       
   357         {
       
   358         if (InterimUtilsL().MRViewersEnabledL())
       
   359             {
       
   360             iMailboxUtils = CMRMailboxUtils::NewL();
       
   361             }
       
   362         else
       
   363             {
       
   364             User::Leave(KErrNotSupported);
       
   365             }
       
   366         }
       
   367 
       
   368     TRACE_EXIT_POINT;
       
   369     return *iMailboxUtils;
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CCalenGlobalData::CalSessionL
       
   374 // Create a Calendar session if necessary and return a reference
       
   375 // (other items were commented in a header).
       
   376 // -----------------------------------------------------------------------------
       
   377 EXPORT_C CCalSession& CCalenGlobalData::CalSessionL()
       
   378     {
       
   379     TRACE_ENTRY_POINT;
       
   380     
       
   381     if (!iCalSession)
       
   382         {
       
   383         iGlobalDataOwnsCalSession = ETrue;
       
   384         iCalSession = CCalSession::NewL();
       
   385 
       
   386         TRAPD( err, iCalSession->OpenL(KCalendarDatabaseFilePath));
       
   387         if (err == KErrNotFound)
       
   388             {
       
   389             CCalCalendarInfo* calendarInfo = GetDefaultCalendarInfoL();
       
   390             CleanupStack::PushL(calendarInfo);
       
   391             iCalSession->CreateCalFileL( KCalendarDatabaseFilePath,
       
   392                                         *calendarInfo);
       
   393             iCalSession->OpenL(KCalendarDatabaseFilePath);
       
   394             CleanupStack::PopAndDestroy(calendarInfo);
       
   395             }
       
   396         else if(err == KErrNone)
       
   397             {
       
   398             // temp solution...need to handle this case
       
   399             CCalCalendarInfo* calendarInfo = iCalSession->CalendarInfoL();
       
   400             CleanupStack::PushL(calendarInfo);
       
   401             if( !calendarInfo->NameL().Compare(KNullDesC) && 
       
   402                  !calendarInfo->Enabled() )
       
   403                 {
       
   404                 calendarInfo->SetNameL(KExtCalendar);
       
   405                 calendarInfo->SetColor(KRgbBlack.Value());
       
   406                 iCalSession->SetCalendarInfoL(*calendarInfo);
       
   407                 }
       
   408             CleanupStack::PopAndDestroy(calendarInfo);
       
   409             
       
   410             }
       
   411         else
       
   412             {
       
   413             User::LeaveIfError( err );
       
   414             }
       
   415         }
       
   416 
       
   417     TRACE_EXIT_POINT;
       
   418     return *iCalSession;
       
   419     }
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CCalenGlobalData::CalSessionL
       
   423 // Based on the calendar name return already cached session from iFileMappingArray
       
   424 // (other items were commented in a header).
       
   425 // -----------------------------------------------------------------------------
       
   426 EXPORT_C CCalSession& CCalenGlobalData::CalSessionL(const TDesC& aCalendar)
       
   427     {
       
   428     TRACE_ENTRY_POINT;
       
   429     CCalSession* session = NULL;
       
   430     HBufC* calendarFileName = aCalendar.AllocLC();
       
   431     TInt index = iFileMappingArray.Find(
       
   432             *calendarFileName,CCalenGlobalData::CalenInfoIdentifierL);
       
   433     CleanupStack::PopAndDestroy(calendarFileName);
       
   434     if(KErrNotFound != index)
       
   435         {
       
   436         session = iFileMappingArray[index]->GetSessionPtr();
       
   437         }
       
   438     else
       
   439         {
       
   440         User::LeaveIfError(KErrNotFound);
       
   441         }
       
   442     
       
   443     TRACE_EXIT_POINT;
       
   444     return *session;
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CCalenGlobalData::InstanceViewL
       
   449 // Create an instance view if necessary and returns a reference.  Creating an
       
   450 // instance view is an asynchronous operation, but this call returns
       
   451 // synchronously.  When the view is created, Completed() is called, which stops
       
   452 // iAs allowing this function to complete.
       
   453 // Leaves with KErrInUse if this class is in the process of creating the
       
   454 // instance view
       
   455 // (other items were commented in a header).
       
   456 // -----------------------------------------------------------------------------
       
   457 EXPORT_C CCalInstanceView* CCalenGlobalData::InstanceViewL()
       
   458     {
       
   459     TRACE_ENTRY_POINT;
       
   460     
       
   461     if (!iInstanceView && !iInstanceViewCreation)
       
   462         {
       
   463         if ( iEntryViewCreation )
       
   464             {
       
   465             iQueued = &CreateInstanceViewL;
       
   466             }
       
   467         else
       
   468             {
       
   469             CreateInstanceViewL();
       
   470             }
       
   471         }
       
   472     
       
   473     TRACE_EXIT_POINT;
       
   474     return iInstanceView;
       
   475     }
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CCalenGlobalData::InstanceViewL
       
   479 // Based on collection id array Create an instance view if necessary and returns a reference.
       
   480 // Creating an instance view is an asynchronous operation, but this call returns
       
   481 // synchronously.  When the view is created, Completed() is called, which stops
       
   482 // iAs allowing this function to complete.
       
   483 // Leaves with KErrInUse if this class is in the process of creating the
       
   484 // instance view
       
   485 // (other items were commented in a header).
       
   486 // -----------------------------------------------------------------------------
       
   487 EXPORT_C CCalInstanceView* CCalenGlobalData::InstanceViewL(
       
   488                                         const RArray<TInt>& aCollectionIds)
       
   489     {
       
   490     TRACE_ENTRY_POINT;
       
   491     
       
   492     if(!iNewInstanceView && !iNewInstanceViewCreation)
       
   493         {
       
   494         CreateInstanceViewL(aCollectionIds);
       
   495         }
       
   496     
       
   497     TRACE_EXIT_POINT;
       
   498     return iNewInstanceView;
       
   499     }
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CCalenGlobalData::EntryViewL
       
   503 // Create an entry view if necessary and returns a reference.  Creating an
       
   504 // entry view is an asynchronous operation, but this call returns
       
   505 // synchronously.  When the view is created, Completed() is called, which stops
       
   506 // iAs allowing this function to complete.
       
   507 // Leaves with KErrInUse if this class is in the process of creating the
       
   508 // entry view
       
   509 // (other items were commented in a header).
       
   510 // -----------------------------------------------------------------------------
       
   511 EXPORT_C CCalEntryView* CCalenGlobalData::EntryViewL()
       
   512     {
       
   513     TRACE_ENTRY_POINT;
       
   514     
       
   515      if (!iEntryView && !iEntryViewCreation)
       
   516         {
       
   517         if ( iInstanceViewCreation )
       
   518             {
       
   519             iQueued = &CreateEntryViewL;
       
   520             }
       
   521         else
       
   522             {
       
   523             CreateEntryViewL();
       
   524             }
       
   525         }
       
   526     
       
   527      TRACE_EXIT_POINT;
       
   528     return iEntryView;
       
   529     }
       
   530 
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CCalenGlobalData::EntryViewL
       
   534 // Based on collection id array Create an entry view if necessary and returns a reference.  
       
   535 // Creating an entry view is an asynchronous operation, but this call returns
       
   536 // synchronously.  When the view is created, Completed() is called, which stops
       
   537 // iAs allowing this function to complete.
       
   538 // Leaves with KErrInUse if this class is in the process of creating the
       
   539 // entry view
       
   540 // (other items were commented in a header).
       
   541 // -----------------------------------------------------------------------------
       
   542 EXPORT_C CCalEntryView* CCalenGlobalData::EntryViewL(
       
   543                                                 const TCalCollectionId aCollectionId)
       
   544     {
       
   545     TRACE_ENTRY_POINT;
       
   546     __ASSERT_ALWAYS(aCollectionId > 0 ,User::Panic(_L("CCalenGlobalData"),-1));
       
   547     
       
   548     CCalEntryView* entryView = NULL;
       
   549     
       
   550     TInt index = iHashDbidIndexMap.FindL(aCollectionId);
       
   551     if(index != KErrNotFound)
       
   552         {
       
   553         entryView = iFileMappingArray[index]->GetEntryView();
       
   554         }    
       
   555     
       
   556     if(!entryView)
       
   557         {
       
   558         User::LeaveIfNull(entryView);
       
   559         }
       
   560     
       
   561     TRACE_EXIT_POINT;
       
   562     return entryView;
       
   563     }
       
   564 
       
   565 // -----------------------------------------------------------------------------
       
   566 // CCalenGlobalData::RegisterEntryViewObserver
       
   567 // Add observer into view observers entry observer list.
       
   568 // (other items were commented in a header).
       
   569 // -----------------------------------------------------------------------------
       
   570 EXPORT_C TBool CCalenGlobalData::EntryViewExists()
       
   571     {
       
   572     TRACE_ENTRY_POINT;
       
   573     TRACE_EXIT_POINT;
       
   574     return ( iEntryView != NULL );
       
   575     }
       
   576 
       
   577 // -----------------------------------------------------------------------------
       
   578 // CCalenGlobalData::MeetingRequestUtilsL
       
   579 // Create MR Utils if necessary and returns a reference
       
   580 // (other items were commented in a header).
       
   581 // -----------------------------------------------------------------------------
       
   582 EXPORT_C CMRUtils& CCalenGlobalData::MeetingRequestUtilsL()
       
   583     {
       
   584     TRACE_ENTRY_POINT;
       
   585 
       
   586     iCreateError = KErrNone;
       
   587     if (!iUtilsAs)
       
   588         {
       
   589         iUtilsAs = new (ELeave) CActiveSchedulerWait;
       
   590         }
       
   591     if (!iMRUtils)
       
   592         {
       
   593         if (InterimUtilsL().MRViewersEnabledL())
       
   594             {
       
   595             if (iUtilsAs->IsStarted())
       
   596                 {
       
   597                 User::Leave(KErrInUse);
       
   598                 }
       
   599             else
       
   600                 {
       
   601                 //Get the currently selected mailbox
       
   602                 CMRMailboxUtils::TMailboxInfo defaultMailbox;
       
   603                 MRMailboxUtilsL().GetDefaultMRMailBoxL(defaultMailbox);
       
   604                 //CMRUtils resolves meeting request utilities based on mtm uid
       
   605                 TBuf8<KMaxUidName> mrMtm;
       
   606                 CnvUtfConverter::ConvertFromUnicodeToUtf8(mrMtm, defaultMailbox.iMtmUid.Name());
       
   607                 iMRUtils = CMRUtils::NewL(mrMtm, *this, CalSessionL(), NULL);
       
   608                 iUtilsAs->Start();
       
   609                 User::LeaveIfError(iCreateError);
       
   610                 }
       
   611             }
       
   612         else
       
   613             {
       
   614             User::Leave(KErrNotSupported);
       
   615             }
       
   616         }
       
   617 
       
   618     TRACE_EXIT_POINT;
       
   619     return *iMRUtils;
       
   620     }
       
   621 
       
   622 // -----------------------------------------------------------------------------
       
   623 // CCalenGlobalData::InterimUtilsL
       
   624 // Create a CCalenInterimUtils object if neccessary and return a reference
       
   625 // (other items were commented in a header).
       
   626 // -----------------------------------------------------------------------------
       
   627 EXPORT_C CCalenInterimUtils2& CCalenGlobalData::InterimUtilsL()
       
   628     {
       
   629     TRACE_ENTRY_POINT;
       
   630 
       
   631     if(!iInterimUtils)
       
   632         {
       
   633         iInterimUtils = CCalenInterimUtils2::NewL();
       
   634         }
       
   635 
       
   636     TRACE_EXIT_POINT;
       
   637     return *iInterimUtils;
       
   638     }
       
   639 
       
   640 // -----------------------------------------------------------------------------
       
   641 // CCalenGlobalData::CalenSendL
       
   642 // Create a CCalenSend object if neccessary and return a reference
       
   643 // (other items were commented in a header).
       
   644 // -----------------------------------------------------------------------------
       
   645 EXPORT_C CCalenSend& CCalenGlobalData::CalenSendL()
       
   646     {
       
   647     TRACE_ENTRY_POINT;
       
   648 
       
   649     if( !iSend )
       
   650         {
       
   651         iSend = CCalenSend::NewL( ECalenSend, CalSessionL() );
       
   652         }
       
   653 
       
   654     TRACE_EXIT_POINT;
       
   655     return *iSend;
       
   656     }
       
   657 
       
   658 // -----------------------------------------------------------------------------
       
   659 // CCalenGlobalData::Context
       
   660 // Return a reference to the CCalenContext object
       
   661 // (other items were commented in a header).
       
   662 // -----------------------------------------------------------------------------
       
   663 EXPORT_C MCalenContext& CCalenGlobalData::Context()
       
   664     {
       
   665     TRACE_ENTRY_POINT;
       
   666     TRACE_EXIT_POINT;
       
   667     return *iContext;
       
   668     }
       
   669 
       
   670 // -----------------------------------------------------------------------------
       
   671 // CCalenEditUi::AttemptToRetrieveDefaultMailboxL
       
   672 // Check to see if we have any mailboxes defined, and if we have a default
       
   673 // mailbox. If we don't, inform the user and return EFalse. This function
       
   674 // returns ETrue if aDefaultMailbox was initialised, and it is OK to create
       
   675 // a new MR.
       
   676 // (other items were commented in a header).
       
   677 // -----------------------------------------------------------------------------
       
   678 EXPORT_C TBool CCalenGlobalData::AttemptToRetrieveDefaultMailboxL( CMRMailboxUtils::TMailboxInfo& aDefaultMailbox)
       
   679     {
       
   680     TRACE_ENTRY_POINT;
       
   681 
       
   682     CMRMailboxUtils& mbUtils = MRMailboxUtilsL();
       
   683     // Get the currently defined mailboxes.
       
   684     RArray<CMRMailboxUtils::TMailboxInfo> mailboxes;
       
   685     CleanupClosePushL(mailboxes);
       
   686     mbUtils.ListMailBoxesL(mailboxes);
       
   687 
       
   688     TBool canCreateMeetingRequest=EFalse;
       
   689     TInt mbCount = mailboxes.Count();
       
   690 
       
   691     // The following 'if-else' block should always initialise
       
   692     // defaultMailBox if canCreateMeetingRequest comes out as ETrue.
       
   693     if(mbCount > 0)
       
   694         {
       
   695         TInt res = KErrNone;
       
   696         TRAPD(err, res = mbUtils.GetDefaultMRMailBoxL(aDefaultMailbox));
       
   697         if( res == KErrNone && err == KErrNone)
       
   698             {
       
   699             canCreateMeetingRequest = ETrue;
       
   700             }
       
   701         else
       
   702             {
       
   703             // We have one or more mailboxes defined, but failed to get a default.
       
   704             // Ask user to answer "Select default mailbox" query.  The available mailboxes must
       
   705             // first be reduced to only show mailboxes with an associated meetnig request solution
       
   706             RImplInfoPtrArrayOwn implArray;
       
   707              CleanupClosePushL( implArray );
       
   708             //Get all MRViewers Implementation
       
   709              const TUid mrViewersIface = {KMRViewersInterfaceUID};
       
   710              REComSession::ListImplementationsL(mrViewersIface, implArray );
       
   711 
       
   712             for (TInt i = mailboxes.Count() - 1; i >= 0; --i)
       
   713                 {
       
   714                 //See if any meeting request implementation matches this mailbox
       
   715                 for (TInt j=0; j<implArray.Count(); ++j)
       
   716                      {
       
   717                      TBuf16<KMaxUidName> mbName;
       
   718                      CnvUtfConverter::ConvertToUnicodeFromUtf8( mbName, implArray[j]->DataType() );
       
   719                      if(mailboxes[i].iMtmUid.Name().CompareF(mbName) == 0)
       
   720                          {
       
   721                          //Found a match
       
   722                         break;
       
   723                         }
       
   724                     //Mailbox has no matching meeting request solution
       
   725                     //remove from list
       
   726                     mailboxes.Remove(i);
       
   727                     }
       
   728                 }
       
   729             CleanupStack::PopAndDestroy();    //implArray
       
   730             
       
   731             TInt selected = PromptToSelectDefaultMailboxL(mailboxes);
       
   732 
       
   733             if(selected >= KErrNone)
       
   734                 {
       
   735                 mbUtils.SetDefaultMRMailBoxL( mailboxes[selected].iEntryId );
       
   736                 canCreateMeetingRequest = ETrue;
       
   737                 __ASSERT_ALWAYS((mbUtils.GetDefaultMRMailBoxL( aDefaultMailbox ) == KErrNone), User::Invariant()); // so we don't return ref to local variable.
       
   738                 }
       
   739             }
       
   740         }
       
   741     else
       
   742         {
       
   743         // Force the check of MR Impl existing
       
   744         InterimUtilsL().MRViewersEnabledL(ETrue); //ignore result
       
   745         }
       
   746    
       
   747     CleanupStack::PopAndDestroy(); // mailboxes
       
   748 
       
   749     TRACE_EXIT_POINT;
       
   750     return canCreateMeetingRequest;
       
   751     }
       
   752 
       
   753 // -----------------------------------------------------------------------------
       
   754 // CCalenGlobalData::ResetKeyEventQueue
       
   755 // Reset Keyevents queue
       
   756 // (other items were commented in a header).
       
   757 // -----------------------------------------------------------------------------
       
   758 EXPORT_C void CCalenGlobalData::ResetKeyEventQueue()
       
   759     {
       
   760     TRACE_ENTRY_POINT;
       
   761     iKeyQueue.Reset();
       
   762     TRACE_EXIT_POINT;
       
   763     }
       
   764 
       
   765 // -----------------------------------------------------------------------------
       
   766 // CCalenGlobalData::QueueKeyEvent
       
   767 // Queue key press event in a queue
       
   768 // (other items were commented in a header).
       
   769 // -----------------------------------------------------------------------------
       
   770 EXPORT_C TBool CCalenGlobalData::QueueKeyEvent(const TKeyEvent& aEvent,
       
   771                                                TEventCode aType)
       
   772     {
       
   773     TRACE_ENTRY_POINT;
       
   774     TBool result(EFalse);
       
   775     TQueuedKeyEvent item;
       
   776     item.iType = aType;
       
   777     item.iEvent = aEvent;
       
   778     if( iKeyQueue.Insert(item, iKeyQueue.Count()) == KErrNone) // add to last
       
   779         {
       
   780         result = ETrue;
       
   781         }
       
   782     TRACE_EXIT_POINT;
       
   783     return result;
       
   784     }
       
   785 
       
   786 // -----------------------------------------------------------------------------
       
   787 // CCalenGlobalData::GetQueueKeyEvent
       
   788 // Get 1 queued event from the queue
       
   789 // (other items were commented in a header).
       
   790 // -----------------------------------------------------------------------------
       
   791 EXPORT_C TBool CCalenGlobalData::GetQueuedKeyEvent(TKeyEvent& aEvent, TEventCode& aType)
       
   792     {
       
   793     TRACE_ENTRY_POINT;
       
   794     TBool result(EFalse);
       
   795     if(iKeyQueue.Count() > 0)
       
   796         {
       
   797         TQueuedKeyEvent item;
       
   798         item = iKeyQueue[0];// get first
       
   799         aEvent = item.iEvent;
       
   800         aType = item.iType;
       
   801         iKeyQueue.Remove(0); // remove first
       
   802         result = ETrue;
       
   803         iKeyQueue.Compress();
       
   804         }
       
   805     TRACE_EXIT_POINT;
       
   806     return result;
       
   807     }
       
   808 
       
   809 // -----------------------------------------------------------------------------
       
   810 // CCalenGlobalData::ConstructFileMappingL
       
   811 // Constructs mapping between symbian calendar file and metabd info
       
   812 // -----------------------------------------------------------------------------
       
   813 EXPORT_C TBool CCalenGlobalData::ConstructFileMappingL()
       
   814     {
       
   815     TRACE_ENTRY_POINT;
       
   816     iCalendarsSession = CCalSession::NewL();
       
   817     
       
   818     ConstructCalendarsListL();
       
   819     
       
   820     iFileMappingArray.Reset();
       
   821         
       
   822     for(TInt index = 0; index < iCalendarInfoList.Count(); index++)
       
   823         {
       
   824         TPtrC calendarFileName = iCalendarInfoList[index]->FileNameL();
       
   825         CCalenFileMapping* filemap = CCalenFileMapping::NewL(); 
       
   826         CleanupStack::PushL(filemap);
       
   827         filemap->SetCalendarFileNameL(calendarFileName);
       
   828         
       
   829         iNewEntryView  = NULL;
       
   830         iNewEntryViewCreation  = NULL;  
       
   831         if(iCalSession)
       
   832             {
       
   833             iNewCalSession = NULL;
       
   834             CCalCalendarInfo* calendarInfo = iCalendarInfoList[index];
       
   835             
       
   836             CCalSession& tempSession = CreateNewSessionL( calendarFileName,
       
   837                                     *calendarInfo );
       
   838             filemap->SetSessionPtr(&tempSession);
       
   839             filemap->SetCollectionId(tempSession.CollectionIdL());
       
   840             CreateEntryViewL(tempSession);
       
   841             filemap->SetEntryView( iNewEntryView );
       
   842             }            
       
   843          else
       
   844             {
       
   845             CCalSession& tempSession = CalSessionL();
       
   846             filemap->SetSessionPtr(&tempSession);
       
   847             filemap->SetCollectionId(tempSession.CollectionIdL());
       
   848             CreateEntryViewL(tempSession);
       
   849             filemap->SetEntryView( iNewEntryView );
       
   850             iGlobalDataOwnsEntryView = EFalse;
       
   851             iGlobalDataOwnsCalSession = EFalse;
       
   852             }
       
   853         iFileMappingArray.Append(filemap);        
       
   854         CleanupStack::Pop(filemap);
       
   855         }   
       
   856     
       
   857     for(TInt index = 0; index < iFileMappingArray.Count(); index++)
       
   858         {
       
   859         iHashDbidIndexMap.InsertL( iFileMappingArray[index]->GetCollectionId(),
       
   860                                     index);
       
   861         }
       
   862     
       
   863     TRACE_EXIT_POINT
       
   864     return ETrue;
       
   865     }
       
   866 
       
   867 // -----------------------------------------------------------------------------
       
   868 // CCalenGlobalData::InitializeGlobalDataL
       
   869 // Initializes multiple db related objects
       
   870 // -----------------------------------------------------------------------------
       
   871 EXPORT_C void CCalenGlobalData::InitializeGlobalDataL()
       
   872     {
       
   873     TRACE_ENTRY_POINT
       
   874     
       
   875     ConstructFileMappingL();
       
   876     
       
   877     TRACE_EXIT_POINT
       
   878     }
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // CCalenGlobalData::PromptToSelectDefaultMailboxL
       
   882 // Prompts the user to select the default mailbox. If the user cancels, the
       
   883 // function returns KErrCancel, otherwise it returns the index of the selected
       
   884 // mailbox. This function does not set the default mailbox, but rather returns
       
   885 // the index of the given array to which the default should be set.
       
   886 // (other items were commented in a header).
       
   887 // -----------------------------------------------------------------------------
       
   888 TInt CCalenGlobalData::PromptToSelectDefaultMailboxL( RArray<CMRMailboxUtils::TMailboxInfo>& aMailboxes )
       
   889     {
       
   890     TRACE_ENTRY_POINT;
       
   891 
       
   892     TInt mbCount = aMailboxes.Count();
       
   893 
       
   894     TInt selected;
       
   895     if (mbCount > 0)
       
   896         {
       
   897         CAknSinglePopupMenuStyleListBox* list =
       
   898             new (ELeave) CAknSinglePopupMenuStyleListBox;
       
   899         CleanupStack::PushL(list);
       
   900 
       
   901         CAknPopupList* popupList = CAknPopupList::NewL(list, R_AVKON_SOFTKEYS_OK_CANCEL);
       
   902         CleanupStack::PushL(popupList);
       
   903 
       
   904         list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
       
   905         list->CreateScrollBarFrameL(ETrue);
       
   906         list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   907             CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   908 
       
   909         CEikonEnv* eikEnv = CEikonEnv::Static();
       
   910 
       
   911         CDesCArrayFlat* items = new (ELeave)CDesCArrayFlat(mbCount);
       
   912         CleanupStack::PushL(items);
       
   913         for(TInt i=0; i<mbCount; ++i)
       
   914             {
       
   915             items->AppendL( aMailboxes[i].iName );
       
   916             }
       
   917         CleanupStack::Pop(items);
       
   918         CTextListBoxModel* model = list->Model();
       
   919 
       
   920         //Pass ownersip of items to model
       
   921         model->SetItemTextArray(items);
       
   922 
       
   923         HBufC* title = StringLoader::LoadLC(R_CALEN_SELECT_MAILBOX, eikEnv);
       
   924         popupList->SetTitleL(*title);
       
   925         CleanupStack::PopAndDestroy(title);
       
   926 
       
   927         TBool accepted = popupList->ExecuteLD();
       
   928         CleanupStack::Pop(); // popupList
       
   929 
       
   930         if(accepted)
       
   931             {
       
   932             selected = list->CurrentItemIndex();
       
   933             }
       
   934         else
       
   935             {
       
   936             selected = KErrCancel;
       
   937             }
       
   938 
       
   939         CleanupStack::PopAndDestroy();  // list
       
   940         }
       
   941     else
       
   942         {
       
   943         //No mailboxes defined.  Could prompt user to define one here?
       
   944         selected = KErrCancel;
       
   945         }
       
   946 
       
   947     TRACE_EXIT_POINT;
       
   948     return selected;
       
   949     }
       
   950 
       
   951 // -----------------------------------------------------------------------------
       
   952 // CCalenGlobalData::HandleCalEngStatus
       
   953 // Called when Meeting Request utils are creation is complete.
       
   954 // Stops the CActiveSchedulerWait, allowing MeetingRequestUtilsL() to complete
       
   955 // (other items were commented in a header).
       
   956 // -----------------------------------------------------------------------------
       
   957 void CCalenGlobalData::HandleCalEngStatus( TMRUtilsCalEngStatus aStatus )
       
   958     {
       
   959     TRACE_ENTRY_POINT;
       
   960 
       
   961     ASSERT(iUtilsAs);
       
   962 
       
   963     switch (aStatus)
       
   964         {
       
   965         case ENotReady:
       
   966             {
       
   967             //Keep waiting
       
   968             }
       
   969         break;
       
   970         case EAvailableWithoutTombs:
       
   971         case EAvailable:
       
   972             {
       
   973             //Ready for use.  Stop the CActiveSchedulerWait and return
       
   974             iUtilsAs->AsyncStop();
       
   975             iCreateError = KErrNone;
       
   976             }
       
   977         break;
       
   978         case ENotAvailable:
       
   979             {
       
   980             //Somethings gone wrong.  Stop the CActiveSchedulerWait but force
       
   981             //MeetingRequestUtilsL to leave.
       
   982             //We'll use KErrNotFound for now but we don't know what the problem is.
       
   983             iUtilsAs->AsyncStop();
       
   984             iCreateError = KErrNotFound;
       
   985             }
       
   986         break;
       
   987         default:
       
   988             {
       
   989             //Shouldn't ever get called.
       
   990             iUtilsAs->AsyncStop();
       
   991             iCreateError = KErrArgument;
       
   992             }
       
   993         break;
       
   994         }
       
   995 
       
   996     TRACE_EXIT_POINT;
       
   997     }
       
   998 
       
   999 // -----------------------------------------------------------------------------
       
  1000 // CCalenGlobalData::HandleNotification
       
  1001 // Handle any notification if registered for
       
  1002 // -----------------------------------------------------------------------------
       
  1003 void CCalenGlobalData::HandleNotification(const TCalenNotification aNotification )
       
  1004 	{
       
  1005 	TRACE_ENTRY_POINT;
       
  1006 
       
  1007 	switch(aNotification)
       
  1008 		{
       
  1009 		case ECalenNotifyEntryInstanceViewCreated:
       
  1010 			{
       
  1011 			ViewCreationCompleted( ETrue );
       
  1012 			}
       
  1013 			break;
       
  1014 		case ECalenNotifyEntryInstanceViewCreationFailed:
       
  1015 			{
       
  1016 			ViewCreationCompleted( EFalse );
       
  1017 			}
       
  1018 			break;
       
  1019 		case ECalenNotifyDeleteInstanceView:
       
  1020 			{
       
  1021 			//InstanceView has to be deleted since deleting any session(Calendar) 
       
  1022 			//entryView and instanceView has to be deleted before deleting session.
       
  1023 			if(iNewInstanceView)
       
  1024 				{
       
  1025 				delete iNewInstanceView;
       
  1026 				iNewInstanceViewCreation = iNewInstanceView =  NULL;
       
  1027 				}
       
  1028 			
       
  1029 			//If InstanceView is called by any component single instanceView 
       
  1030 			// without the knowledge of multi session (calendar).
       
  1031 			//This instance also should be deleted for deleting the session.  
       
  1032 			if(iInstanceView)
       
  1033 				{
       
  1034 				delete iInstanceView;
       
  1035 				iInstanceView = iInstanceViewCreation = NULL;
       
  1036 				}
       
  1037 			}
       
  1038 			break;
       
  1039 		case ECalenNotifyRealExit:
       
  1040 			{
       
  1041 			iCalendarForcedExit = ETrue;
       
  1042 			}
       
  1043 			break;
       
  1044 		case ECalenNotifyCalendarInfoCreated:
       
  1045 			{
       
  1046 			HandleCalendarInfoCreatedL();
       
  1047 			}
       
  1048 			break;
       
  1049 		case ECalenNotifyCalendarInfoUpdated:
       
  1050 			{
       
  1051 			HandleCalendarInfoUpdatedL();
       
  1052 			}
       
  1053 			break;
       
  1054 		case ECalenNotifyCalendarFileDeleted:
       
  1055 			{
       
  1056 			HandleCalendarFileDeletedL();
       
  1057 			}
       
  1058 			break;
       
  1059 		default:
       
  1060 			break;
       
  1061 		}
       
  1062 
       
  1063     TRACE_EXIT_POINT;
       
  1064     }
       
  1065 
       
  1066 // -----------------------------------------------------------------------------
       
  1067 // CCalenGlobalData::CreateEntryViewL
       
  1068 // -----------------------------------------------------------------------------
       
  1069 void CCalenGlobalData::CreateEntryViewL()
       
  1070     {
       
  1071     TRACE_ENTRY_POINT;
       
  1072 
       
  1073     HBufC* calendarFileName = KCalendarDatabaseFilePath().AllocLC();
       
  1074     TInt index  = iFileMappingArray.Find(   
       
  1075             *calendarFileName, CCalenGlobalData::CalenInfoIdentifierL);
       
  1076     CleanupStack::PopAndDestroy(calendarFileName);
       
  1077     if(index != KErrNotFound)
       
  1078         {
       
  1079         iEntryView = iFileMappingArray[index]->GetEntryView();
       
  1080         }
       
  1081     
       
  1082     if(!iEntryView)
       
  1083         {
       
  1084         User::LeaveIfNull(iEntryView);
       
  1085         }
       
  1086     
       
  1087     TRACE_EXIT_POINT;
       
  1088     }
       
  1089 
       
  1090 // -----------------------------------------------------------------------------
       
  1091 // CCalenGlobalData::CreateEntryViewL
       
  1092 // -----------------------------------------------------------------------------
       
  1093 void  CCalenGlobalData::CreateEntryViewL(CCalSession& session)
       
  1094     {
       
  1095     TRACE_ENTRY_POINT;
       
  1096     iNewEntryViewCreation = CCalEntryView::NewL( session, iCalCallBack );
       
  1097     
       
  1098     if(iNewEntryViewCreation)
       
  1099         {
       
  1100         iNewEntryView = iNewEntryViewCreation;
       
  1101         }
       
  1102     
       
  1103     TRACE_EXIT_POINT;
       
  1104     }
       
  1105 
       
  1106 // -----------------------------------------------------------------------------
       
  1107 // CCalenGlobalData::CreateInstanceViewL
       
  1108 // -----------------------------------------------------------------------------
       
  1109 void CCalenGlobalData::CreateInstanceViewL()
       
  1110     {
       
  1111     TRACE_ENTRY_POINT;
       
  1112     iInstanceViewCreation = CCalInstanceView::NewL( CalSessionL(), iCalCallBack );
       
  1113      if(iInstanceViewCreation)
       
  1114         {
       
  1115         iInstanceView = iInstanceViewCreation;
       
  1116         }
       
  1117     TRACE_EXIT_POINT;
       
  1118     }
       
  1119 
       
  1120 // -----------------------------------------------------------------------------
       
  1121 // CCalenGlobalData::CreateEntryViewL
       
  1122 // -----------------------------------------------------------------------------
       
  1123 void CCalenGlobalData::CreateInstanceViewL(const RArray<TInt>& aCollectionIds)
       
  1124     {
       
  1125     TRACE_ENTRY_POINT;
       
  1126     
       
  1127     RPointerArray<CCalSession> sessionArray;
       
  1128     
       
  1129     for(TInt i = 0; i < aCollectionIds.Count() ; i++)
       
  1130         {
       
  1131         TInt index = iHashDbidIndexMap.FindL(aCollectionIds[i]);
       
  1132         if(index != KErrNotFound)
       
  1133            {
       
  1134            CCalSession* sessionPtr = iFileMappingArray[index]->GetSessionPtr();
       
  1135            sessionArray.AppendL(sessionPtr);
       
  1136            }
       
  1137         }
       
  1138     
       
  1139     if(sessionArray.Count())
       
  1140         {
       
  1141         iNewInstanceViewCreation = CCalInstanceView::NewL( sessionArray, iCalCallBack );
       
  1142         if(iNewInstanceViewCreation)
       
  1143            {
       
  1144            iNewInstanceView = iNewInstanceViewCreation;        
       
  1145            }
       
  1146         }
       
  1147     
       
  1148     sessionArray.Reset();
       
  1149     TRACE_EXIT_POINT;
       
  1150     }
       
  1151 
       
  1152 // -----------------------------------------------------------------------------
       
  1153 // CEntryViewObserver::ViewCreationCompleted
       
  1154 // FIXME -- Update description
       
  1155 // Get call after entryview / instance view being created
       
  1156 // (other items were commented in a header).
       
  1157 // -----------------------------------------------------------------------------
       
  1158 void CCalenGlobalData::ViewCreationCompleted( TBool aSuccess )
       
  1159     {
       
  1160     TRACE_ENTRY_POINT;
       
  1161 
       
  1162     if ( !aSuccess )
       
  1163         {
       
  1164         // Something has gone wrong
       
  1165         delete iEntryViewCreation;
       
  1166         delete iInstanceViewCreation;
       
  1167         delete iNewEntryViewCreation;
       
  1168         delete iNewInstanceViewCreation;
       
  1169         }
       
  1170     else
       
  1171         {
       
  1172         if ( iEntryViewCreation )
       
  1173             {
       
  1174             iEntryView = iEntryViewCreation;
       
  1175             }
       
  1176         else if ( iInstanceViewCreation )
       
  1177             {
       
  1178             iInstanceView = iInstanceViewCreation;
       
  1179             }
       
  1180         
       
  1181         if ( iNewEntryViewCreation )
       
  1182             {
       
  1183             iNewEntryView = iEntryViewCreation;
       
  1184             }
       
  1185         else if ( iNewInstanceViewCreation )
       
  1186             {
       
  1187             iNewInstanceView = iNewInstanceViewCreation;
       
  1188             }
       
  1189         }
       
  1190 
       
  1191     iEntryViewCreation = NULL;
       
  1192     iInstanceViewCreation = NULL;
       
  1193     iNewEntryViewCreation = NULL;
       
  1194     iNewInstanceViewCreation = NULL;
       
  1195     
       
  1196     if ( iQueued )
       
  1197         {
       
  1198         (this->*iQueued)();
       
  1199         iQueued = NULL;
       
  1200         }
       
  1201 
       
  1202     TRACE_EXIT_POINT;
       
  1203     }
       
  1204 
       
  1205 // -----------------------------------------------------------------------------
       
  1206 // CCalenGlobalData::CreateNewSessionL
       
  1207 // Create a Calendar session if necessary and return a reference
       
  1208 // (other items were commented in a header).
       
  1209 // -----------------------------------------------------------------------------
       
  1210 CCalSession& CCalenGlobalData::CreateNewSessionL( const TDesC& aCalendar )
       
  1211     {
       
  1212     TRACE_ENTRY_POINT;
       
  1213 
       
  1214     if(!iNewCalSession)
       
  1215         {
       
  1216         iNewCalSession = CCalSession::NewL(*iCalSession);
       
  1217         
       
  1218         TRAPD( err, iNewCalSession->OpenL(aCalendar));
       
  1219         if ( err == KErrNotFound )
       
  1220            {
       
  1221            iNewCalSession->CreateCalFileL(aCalendar);
       
  1222            iNewCalSession->OpenL(aCalendar); // not trapped anymore
       
  1223            }
       
  1224         else
       
  1225            {
       
  1226            User::LeaveIfError( err );
       
  1227            }
       
  1228         }
       
  1229     TRACE_EXIT_POINT;
       
  1230     return *iNewCalSession;
       
  1231     }
       
  1232 
       
  1233 // -----------------------------------------------------------------------------
       
  1234 // CCalenGlobalData::CalenInfoIdentifierL
       
  1235 // -----------------------------------------------------------------------------
       
  1236 //
       
  1237 TBool CCalenGlobalData::CalenInfoIdentifierL( const HBufC* aName,
       
  1238                                         const CCalenFileMapping& aFileMapping)
       
  1239     {
       
  1240     TRACE_ENTRY_POINT;
       
  1241     TPtrC calendarFileName = aFileMapping.GetCalendarFileName();
       
  1242     TRACE_EXIT_POINT;
       
  1243     return (!calendarFileName.CompareF(*aName));
       
  1244     }
       
  1245 
       
  1246 // -----------------------------------------------------------------------------
       
  1247 // CCalenGlobalData::AddCalendarL
       
  1248 // adds new calendar file and sets calendar info to it 
       
  1249 // -----------------------------------------------------------------------------
       
  1250 //
       
  1251 EXPORT_C void CCalenGlobalData::AddCalendarL(CCalCalendarInfo* aCalendarInfo)
       
  1252 	{	
       
  1253 	TRACE_ENTRY_POINT;
       
  1254 
       
  1255 	CCalenFileMapping* fileMapping = CCalenFileMapping::NewL();
       
  1256 	CleanupStack::PushL(fileMapping);
       
  1257 	
       
  1258 	HBufC* calendarFileName = CCalenMultiCalUtil::GetNextAvailableCalFileL();
       
  1259 	CleanupStack::PushL(calendarFileName);
       
  1260 	fileMapping->SetCalendarFileNameL(calendarFileName->Des());
       
  1261 	CleanupStack::PopAndDestroy(calendarFileName);
       
  1262 	if(iCalSession)
       
  1263 		{
       
  1264 		iNewCalSession = NULL;
       
  1265 		iNewEntryView  = NULL;
       
  1266 		iNewEntryViewCreation  = NULL;
       
  1267 		TPtrC calFileName = fileMapping->GetCalendarFileName();
       
  1268 		CleanupStack::PushL(aCalendarInfo);
       
  1269 		CCalSession& tempSession = CreateNewSessionL( calFileName,
       
  1270 													*aCalendarInfo );
       
  1271 		fileMapping->SetSessionPtr(&tempSession);
       
  1272 		fileMapping->SetCollectionId(tempSession.CollectionIdL());
       
  1273 		
       
  1274 		if(!iCalendarForcedExit)
       
  1275 			{
       
  1276 			CreateEntryViewL(tempSession);
       
  1277 			}
       
  1278 		fileMapping->SetEntryView( iNewEntryView );
       
  1279 		CleanupStack::PopAndDestroy(aCalendarInfo);
       
  1280 		iCalendarInfoList.Append(tempSession.CalendarInfoL());
       
  1281 		}
       
  1282 
       
  1283 	CleanupStack::Pop(fileMapping);
       
  1284 	iFileMappingArray.Append(fileMapping);
       
  1285 	
       
  1286 	iHashDbidIndexMap.Close();   
       
  1287 	for(TInt index = 0; index < iFileMappingArray.Count(); index++)
       
  1288 	    {
       
  1289 	    iHashDbidIndexMap.InsertL( iFileMappingArray[index]->GetCollectionId(),
       
  1290                                    index);
       
  1291 	    }
       
  1292 	
       
  1293 	TRACE_EXIT_POINT
       
  1294 	}
       
  1295 
       
  1296 // -----------------------------------------------------------------------------
       
  1297 // CCalenGlobalData::RemoveDeadCalendarsL
       
  1298 // removes dead calendar files from the file system
       
  1299 // -----------------------------------------------------------------------------
       
  1300 //
       
  1301 EXPORT_C void CCalenGlobalData::RemoveDeadCalendarsL()
       
  1302     {
       
  1303     TRACE_ENTRY_POINT;
       
  1304     CCalCalendarIterator* calendarIterator = 
       
  1305                       CCalCalendarIterator::NewL(*iCalendarsSession);
       
  1306     CleanupStack::PushL(calendarIterator);
       
  1307     
       
  1308     for( CCalCalendarInfo* calendarInfo = calendarIterator->FirstL();
       
  1309          calendarInfo!=NULL;calendarInfo = calendarIterator->NextL())
       
  1310         {
       
  1311         CleanupStack::PushL(calendarInfo);
       
  1312         HBufC* filename = calendarInfo->FileNameL().AllocLC();
       
  1313         TInt index = iFileMappingArray.Find( *filename, 
       
  1314                                  CCalenGlobalData::CalenInfoIdentifierL);
       
  1315         if(KErrNotFound == index)
       
  1316             {
       
  1317             CCalSession* session = CCalSession::NewL(*iCalSession);
       
  1318             CleanupStack::PushL(session);
       
  1319             TRAP_IGNORE(session->DeleteCalFileL( *filename ));
       
  1320             CleanupStack::PopAndDestroy(session);
       
  1321             }
       
  1322         CleanupStack::PopAndDestroy(filename);
       
  1323         CleanupStack::PopAndDestroy(calendarInfo);
       
  1324         }
       
  1325     CleanupStack::PopAndDestroy(calendarIterator);
       
  1326     TRACE_EXIT_POINT;
       
  1327     }
       
  1328 
       
  1329 // -----------------------------------------------------------------------------
       
  1330 // CCalenGlobalData::RemoveCalendarL
       
  1331 // removes calendar file from the file system
       
  1332 // -----------------------------------------------------------------------------
       
  1333 //
       
  1334 EXPORT_C void CCalenGlobalData::RemoveCalendarL(const TDesC& aCalendarFileName)
       
  1335 	{
       
  1336 	TRACE_ENTRY_POINT;
       
  1337 
       
  1338 	HBufC* calendarFilename = aCalendarFileName.AllocLC();
       
  1339 	TInt index = iFileMappingArray.Find( *calendarFilename, 
       
  1340 				CCalenGlobalData::CalenInfoIdentifierL);
       
  1341 	
       
  1342     if( KErrNotFound == index )
       
  1343         {
       
  1344         CleanupStack::PopAndDestroy(calendarFilename);
       
  1345         // reconstruct the calendar list using the iterator
       
  1346         ConstructCalendarsListL();
       
  1347         
       
  1348         TRACE_EXIT_POINT;
       
  1349         return;
       
  1350         }
       
  1351 
       
  1352 	if( index >= 0 )
       
  1353 		{
       
  1354         CCalenFileMapping* filemap = iFileMappingArray.operator [](index);
       
  1355         CCalSession* session = filemap->GetSessionPtr();
       
  1356 		if(session)
       
  1357 			{
       
  1358             TRAPD(err, session->DeleteCalFileL(aCalendarFileName));
       
  1359             if( err == KErrInUse )
       
  1360                 {
       
  1361                 //Calendar file is opened by other application.
       
  1362                 //Mark the file as deleted. Try delete the file at later time.
       
  1363                 // Get the CalFile
       
  1364                 CCalCalendarInfo* caleninfo = session->CalendarInfoL();
       
  1365                 CleanupStack::PushL(caleninfo);
       
  1366                 
       
  1367                 // Mark the CalFile as Hidden
       
  1368                 caleninfo->SetEnabled( EFalse );
       
  1369                             
       
  1370                 // Set the SyncStatus to False
       
  1371                 TBuf8<KBuffLength> keyBuff;
       
  1372                 keyBuff.Zero();
       
  1373                 keyBuff.AppendNum( ESyncStatus );
       
  1374                 TBool syncstatus( EFalse );
       
  1375                 TPckgC<TBool> pckgSyncStatusValue( syncstatus );
       
  1376                 caleninfo->SetPropertyL( keyBuff, pckgSyncStatusValue );
       
  1377                 
       
  1378                 // Mark the meta property as SoftDeleted
       
  1379                 keyBuff.Zero();
       
  1380                 keyBuff.AppendNum(EMarkAsDelete);
       
  1381                 TPckgC<TBool> pkgSoftDelete( ETrue );
       
  1382                 caleninfo->SetPropertyL(keyBuff, pkgSoftDelete);
       
  1383                 
       
  1384                 session->SetCalendarInfoL( *caleninfo );
       
  1385                 CleanupStack::PopAndDestroy(caleninfo);            
       
  1386                 }
       
  1387             TInt infoListIndex = iCalendarInfoList.Find(*calendarFilename,
       
  1388                         CCalenGlobalData::CalenCalendarInfoIdentiferL);
       
  1389             
       
  1390             CCalCalendarInfo* calendarInfo = iCalendarInfoList[infoListIndex];
       
  1391             iCalendarInfoList.Remove(infoListIndex);
       
  1392             delete calendarInfo;
       
  1393             calendarInfo = NULL;
       
  1394 
       
  1395             iHashDbidIndexMap.Close();
       
  1396 
       
  1397             iFileMappingArray.Remove(index);
       
  1398             delete filemap;
       
  1399             for(TInt index = 0; index < iFileMappingArray.Count(); index++)
       
  1400                 {
       
  1401                 iHashDbidIndexMap.InsertL(iFileMappingArray[index]->GetCollectionId(), index);
       
  1402                 }
       
  1403 			}
       
  1404 		}
       
  1405 
       
  1406 	
       
  1407 	CleanupStack::PopAndDestroy(calendarFilename);        
       
  1408 	TRACE_EXIT_POINT;
       
  1409 	}
       
  1410 
       
  1411 // -----------------------------------------------------------------------------
       
  1412 // CCalenGlobalData::UpdateCalendarL
       
  1413 // updates calendar info for the calendar file
       
  1414 // -----------------------------------------------------------------------------
       
  1415 //
       
  1416 EXPORT_C void CCalenGlobalData::UpdateCalendarL(CCalCalendarInfo* aCalendarInfo)
       
  1417 	{
       
  1418 	TRACE_ENTRY_POINT;
       
  1419 
       
  1420 	HBufC* calendar = aCalendarInfo->FileNameL().AllocLC();
       
  1421 	TInt index = iFileMappingArray.Find( *calendar, 
       
  1422 				CCalenGlobalData::CalenInfoIdentifierL);
       
  1423 
       
  1424 	if(index != KErrNotFound)
       
  1425 		{
       
  1426 		CCalSession* session = iFileMappingArray[index]->GetSessionPtr();
       
  1427 		if(session)
       
  1428 			{
       
  1429 			session->SetCalendarInfoL(*aCalendarInfo);
       
  1430 			}
       
  1431 		}
       
  1432 	CleanupStack::PopAndDestroy(calendar);
       
  1433 
       
  1434 	TRACE_EXIT_POINT;
       
  1435 	}
       
  1436 
       
  1437 // -----------------------------------------------------------------------------
       
  1438 // CCalenGlobalData::GetCalFileNameForCollectionId
       
  1439 // Get Calendar file name for the given collectionid
       
  1440 // -----------------------------------------------------------------------------
       
  1441 //
       
  1442 EXPORT_C const TDesC& CCalenGlobalData::GetCalFileNameForCollectionId( 
       
  1443      const TCalCollectionId aColId)
       
  1444 	{
       
  1445 	TRACE_ENTRY_POINT;
       
  1446 
       
  1447 	TInt index = iFileMappingArray.Find( aColId,
       
  1448 			CCalenGlobalData::CalenFileMapIdentifierForColId );
       
  1449 	
       
  1450 	if(index != KErrNotFound)
       
  1451 		{
       
  1452 		TRACE_EXIT_POINT;
       
  1453 		return iFileMappingArray[index]->GetCalendarFileName();
       
  1454 		}
       
  1455 	else
       
  1456 	    {
       
  1457 	    TRACE_EXIT_POINT;
       
  1458 	    return KNullDesC;
       
  1459 	    }
       
  1460 	}
       
  1461 
       
  1462 // -----------------------------------------------------------------------------
       
  1463 // CCalenGlobalData::GetAllCalendarInfoL
       
  1464 // Get all available calendar info
       
  1465 // -----------------------------------------------------------------------------
       
  1466 //
       
  1467 EXPORT_C void CCalenGlobalData::GetAllCalendarInfoL( 
       
  1468                     RPointerArray<CCalCalendarInfo>& aCalendarInfoList )
       
  1469 	{
       
  1470 	TRACE_ENTRY_POINT;
       
  1471 		
       
  1472 	for(TInt index=0;index<iCalendarInfoList.Count();index++)
       
  1473 	    {
       
  1474 	    aCalendarInfoList.AppendL(iCalendarInfoList[index]);
       
  1475 	    }
       
  1476 	
       
  1477 	TRACE_EXIT_POINT;
       
  1478 	}
       
  1479 
       
  1480 // -----------------------------------------------------------------------------
       
  1481 // CCalenGlobalData::CreateNewSessionL
       
  1482 // Create new session with metadata
       
  1483 // -----------------------------------------------------------------------------
       
  1484 //
       
  1485 CCalSession& CCalenGlobalData::CreateNewSessionL( const TDesC& aCalendar,
       
  1486                      const CCalCalendarInfo& aCalendarInfo )
       
  1487 	{
       
  1488 	TRACE_ENTRY_POINT;
       
  1489 
       
  1490 	if(!iNewCalSession)
       
  1491 		{
       
  1492 		iNewCalSession = CCalSession::NewL(*iCalSession);
       
  1493 		
       
  1494 		TRAPD( err, iNewCalSession->OpenL(aCalendar));
       
  1495 		if ( err == KErrNotFound )
       
  1496 		   {
       
  1497 		   iNewCalSession->CreateCalFileL( aCalendar, aCalendarInfo );
       
  1498 		   iNewCalSession->OpenL(aCalendar); // not trapped anymore
       
  1499 		   }
       
  1500 		else
       
  1501 		   {
       
  1502 		   User::LeaveIfError( err );
       
  1503 		   }
       
  1504 		}
       
  1505 	TRACE_EXIT_POINT;
       
  1506 	return *iNewCalSession;
       
  1507 	}
       
  1508 
       
  1509 // -----------------------------------------------------------------------------
       
  1510 // CCalenGlobalData::CalenFileMapIdentifierForColId
       
  1511 // Search for filemap index based on collection id
       
  1512 // -----------------------------------------------------------------------------
       
  1513 //
       
  1514 TBool CCalenGlobalData::CalenFileMapIdentifierForColId(const TCalCollectionId* aId,
       
  1515                                        const CCalenFileMapping& aFileMapping )
       
  1516 	{
       
  1517 	TRACE_ENTRY_POINT;
       
  1518 	TRACE_EXIT_POINT;
       
  1519 	return (*aId == (aFileMapping.GetCollectionId()));
       
  1520 	}
       
  1521 
       
  1522 // -----------------------------------------------------------------------------
       
  1523 // CCalenGlobalData::CalenCalendarInfoIdentiferL
       
  1524 // Construct calendar list from the calendar iterator
       
  1525 // -----------------------------------------------------------------------------
       
  1526 //
       
  1527 TBool CCalenGlobalData::CalenCalendarInfoIdentiferL(const HBufC* aFileName,
       
  1528                                                         const CCalCalendarInfo& aCalendarInfo)
       
  1529     {
       
  1530     TRACE_ENTRY_POINT
       
  1531     TPtrC calendarFileName = aCalendarInfo.FileNameL();
       
  1532     TRACE_EXIT_POINT
       
  1533     return (!calendarFileName.CompareF(*aFileName) );
       
  1534     }
       
  1535 
       
  1536 // -----------------------------------------------------------------------------
       
  1537 // CCalenGlobalData::ConstructCalendarsListL
       
  1538 // Construct calendar list from the calendar iterator
       
  1539 // -----------------------------------------------------------------------------
       
  1540 //
       
  1541 void CCalenGlobalData::ConstructCalendarsListL()
       
  1542     {
       
  1543     TRACE_ENTRY_POINT;
       
  1544     
       
  1545     iCalendarInfoList.ResetAndDestroy();
       
  1546     CCalCalendarIterator* calendarIterator = 
       
  1547         CCalCalendarIterator::NewL(*iCalendarsSession);
       
  1548     CleanupStack::PushL(calendarIterator);
       
  1549     
       
  1550     for( CCalCalendarInfo* calendarInfo = calendarIterator->FirstL();
       
  1551          calendarInfo!=NULL;calendarInfo = calendarIterator->NextL())
       
  1552         {
       
  1553         TBuf8<KBuffLength> keyBuff;
       
  1554         // Mark the meta property as SoftDeleted
       
  1555         keyBuff.Zero();
       
  1556         keyBuff.AppendNum(EMarkAsDelete);
       
  1557         TBool softDelete = EFalse;
       
  1558         TPckgC<TBool> pkgSoftDelete( softDelete );
       
  1559         TRAPD(err,pkgSoftDelete.Set(calendarInfo->PropertyValueL(keyBuff)));
       
  1560         if( KErrNone == err )
       
  1561             {
       
  1562             softDelete = pkgSoftDelete();
       
  1563             }
       
  1564         if(!softDelete)
       
  1565             {
       
  1566             iCalendarInfoList.Append(calendarInfo);
       
  1567             }
       
  1568         else
       
  1569             {
       
  1570             delete calendarInfo;
       
  1571             }
       
  1572         }
       
  1573     CleanupStack::PopAndDestroy(calendarIterator);
       
  1574     
       
  1575     TRACE_EXIT_POINT;
       
  1576     }
       
  1577 
       
  1578 // -----------------------------------------------------------------------------
       
  1579 // CCalenGlobalData::GetDefaultCalendarInfoL
       
  1580 // Get default calendar info
       
  1581 // -----------------------------------------------------------------------------
       
  1582 //
       
  1583 CCalCalendarInfo* CCalenGlobalData::GetDefaultCalendarInfoL()
       
  1584 	{
       
  1585 	TRACE_ENTRY_POINT;
       
  1586 
       
  1587 	CCalCalendarInfo* defaultCalendarInfo = CCalCalendarInfo::NewL();
       
  1588 	CleanupStack::PushL(defaultCalendarInfo);
       
  1589 	defaultCalendarInfo->SetColor(KRgbRed.Value());
       
  1590 	defaultCalendarInfo->SetEnabled(ETrue);
       
  1591 	defaultCalendarInfo->SetNameL(KPhoneCalendar);
       
  1592 	CleanupStack::Pop(defaultCalendarInfo);
       
  1593 
       
  1594 	TRACE_EXIT_POINT;
       
  1595 	return defaultCalendarInfo;
       
  1596 	}
       
  1597 
       
  1598 // -----------------------------------------------------------------------------
       
  1599 // CCalenGlobalData::HandleCalendarInfoCreatedL
       
  1600 // Handles the notification ECalenNotifyCalendarInfoCreated
       
  1601 // -----------------------------------------------------------------------------
       
  1602 //
       
  1603 void CCalenGlobalData::HandleCalendarInfoCreatedL()
       
  1604 	{
       
  1605 	TRACE_ENTRY_POINT;
       
  1606 	// get the filename from the context
       
  1607 	TDesC& fileName = iContext->GetCalendarFileNameL();
       
  1608 
       
  1609 	// check for the calendar file already exists in filemap list
       
  1610 	HBufC* calendar = fileName.AllocLC();
       
  1611 	TInt index = iFileMappingArray.Find(*calendar,
       
  1612 			CCalenGlobalData::CalenInfoIdentifierL);
       
  1613 	CleanupStack::PopAndDestroy(calendar);
       
  1614 	
       
  1615 	// if not exists,add to filemapper list
       
  1616 	if (KErrNotFound == index)
       
  1617 		{
       
  1618 		CCalenFileMapping* fileMapper = CCalenFileMapping::NewL();
       
  1619 		CleanupStack::PushL(fileMapper);
       
  1620 		fileMapper->SetCalendarFileNameL(fileName);
       
  1621 
       
  1622 		iNewEntryView  = NULL;
       
  1623 		iNewEntryViewCreation  = NULL;
       
  1624 		CCalSession* newSession = NULL;
       
  1625 		if(iCalSession)
       
  1626 			{
       
  1627 			// create the new session using default session
       
  1628 			newSession = CCalSession::NewL(*iCalSession);
       
  1629 			CleanupStack::PushL(newSession);
       
  1630 			TRAPD(err,newSession->OpenL(fileName));
       
  1631 			User::LeaveIfError( err );
       
  1632 			CleanupStack::Pop(newSession);
       
  1633 			// set filemapper data 
       
  1634 			fileMapper->SetSessionPtr(newSession);
       
  1635 			fileMapper->SetCollectionId(newSession->CollectionIdL());
       
  1636 			 
       
  1637 			if(!iCalendarForcedExit)
       
  1638 				{
       
  1639 				CreateEntryViewL(*newSession);
       
  1640 				}
       
  1641 			fileMapper->SetEntryView( iNewEntryView );
       
  1642 			
       
  1643 			iCalendarInfoList.AppendL(newSession->CalendarInfoL());
       
  1644 			}
       
  1645 		else
       
  1646 			{
       
  1647 			// create the first session
       
  1648 			iCalSession = CCalSession::NewL();
       
  1649 			TRAPD(err,iCalSession->OpenL(fileName));
       
  1650 			User::LeaveIfError(err);
       
  1651 			
       
  1652 			// set filemapper data 
       
  1653 			fileMapper->SetSessionPtr(iCalSession);
       
  1654 			fileMapper->SetCollectionId(iCalSession->CollectionIdL());
       
  1655 			
       
  1656 			if(!iCalendarForcedExit)
       
  1657 				{
       
  1658 				CreateEntryViewL(*iCalSession);
       
  1659 				}
       
  1660 			
       
  1661 			fileMapper->SetEntryView(iNewEntryView);
       
  1662 			iGlobalDataOwnsEntryView = EFalse;
       
  1663 			iGlobalDataOwnsCalSession = EFalse;
       
  1664 			iCalendarInfoList.AppendL(iCalSession->CalendarInfoL());
       
  1665 			}
       
  1666 		// append to filemapper list
       
  1667 		iFileMappingArray.Append(fileMapper);
       
  1668 		CleanupStack::Pop(fileMapper);
       
  1669 
       
  1670 		iHashDbidIndexMap.Close();
       
  1671 		for(TInt index = 0; index < iFileMappingArray.Count(); index++)
       
  1672 			{
       
  1673 			iHashDbidIndexMap.InsertL(
       
  1674 				iFileMappingArray[index]->GetCollectionId(), index);
       
  1675 			}
       
  1676 		}
       
  1677 	TRACE_EXIT_POINT;
       
  1678 	}
       
  1679 
       
  1680 // -----------------------------------------------------------------------------
       
  1681 // CCalenGlobalData::HandleCalendarInfoUpdatedL
       
  1682 // Handles the notification ECalenNotifyCalendarInfoUpdated
       
  1683 // -----------------------------------------------------------------------------
       
  1684 //
       
  1685 void CCalenGlobalData::HandleCalendarInfoUpdatedL()
       
  1686 	{
       
  1687 	TRACE_ENTRY_POINT;
       
  1688 	
       
  1689 	// reconstruct the calendar list using the iterator
       
  1690 	ConstructCalendarsListL();
       
  1691 
       
  1692 	TRACE_EXIT_POINT;
       
  1693 	}
       
  1694 
       
  1695 // -----------------------------------------------------------------------------
       
  1696 // CCalenGlobalData::HandleCalendarFileDeletedL
       
  1697 // Handles the notification ECalenNotifyCalendarFileDeleted
       
  1698 // -----------------------------------------------------------------------------
       
  1699 //
       
  1700 void CCalenGlobalData::HandleCalendarFileDeletedL()
       
  1701 	{
       
  1702 	TRACE_ENTRY_POINT;
       
  1703 
       
  1704 	// get the filename from the context
       
  1705 	TDesC& fileName = iContext->GetCalendarFileNameL();
       
  1706 
       
  1707 	// delete the calendar file
       
  1708 	RemoveCalendarL(fileName);
       
  1709 	
       
  1710 	TRACE_EXIT_POINT;
       
  1711 	}
       
  1712 
       
  1713 // End of file