calendarui/globaldata/src/calenglobaldata.cpp
changeset 18 c198609911f9
parent 0 f979ecb2b13e
child 89 b57382753122
equal deleted inserted replaced
0:f979ecb2b13e 18:c198609911f9
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:   Global Data for Calendar application
    14 * Description:  Global Data for Calendar application
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
       
    20 //debug
    19 //debug
    21 #include "calendarui_debug.h"
    20 #include "calendarui_debug.h"
    22 
    21 
    23 // INCLUDE FILES
    22 // INCLUDE FILES
    24 #include "calenglobaldata.h"        // CCalenGlobalData
    23 #include "calenglobaldata.h"        // CalenGlobalData
    25 #include "RImplInfoPtrArrayOwn.inl" // Wrapper class with array deletion on close
    24 #include "calencontext.h"           // Calendar context
    26 #include "calensend.h"              // CCalenSend
       
    27 #include "CalenInterimUtils2.h"     // CalenInterimUtils
       
    28 #include "calencontextimpl.h"       // Calendar context implementation
    25 #include "calencontextimpl.h"       // Calendar context implementation
    29 #include "calenfilemapping.h"
    26 #include "hb_calencommands.hrh"
    30 
    27 #include <CalSession.h>             // Calendar database session
    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
    28 #include <calinstanceview.h>        // Calendar Instance view
    38 #include <calentryview.h>           // Calendar Entry view
    29 #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 
    30 
    51 // Default Calendar database path
    31 // Default Calendar database path
    52 _LIT( KCalendarDatabaseFilePath, "c:calendar" );
    32 _LIT( KCalendarDatabaseFilePath, "c:Calendar" );
    53 _LIT( KPhoneCalendar,"Personal" );
    33 
    54 _LIT( KExtCalendar,"Ext calendar" );
       
    55 const TInt KBuffLength = 24;
       
    56 
    34 
    57 // ============================ MEMBER FUNCTIONS ===============================
    35 // ============================ MEMBER FUNCTIONS ===============================
    58 
    36 
    59 // -----------------------------------------------------------------------------
    37 // -----------------------------------------------------------------------------
    60 // CCalenGlobalData::CCalenGlobalData
    38 // CCalenGlobalData::CCalenGlobalData
    61 // C++ default constructor can NOT contain any code, that might leave.
    39 // C++ default constructor can NOT contain any code, that might leave.
    62 // (other items were commented in a header).
    40 // (other items were commented in a header).
    63 // -----------------------------------------------------------------------------
    41 // -----------------------------------------------------------------------------
    64 //
    42 //
       
    43 
    65 CCalenGlobalData::CCalenGlobalData( MCalProgressCallBack& aCalCallBack )
    44 CCalenGlobalData::CCalenGlobalData( MCalProgressCallBack& aCalCallBack )
    66     : iCalCallBack( aCalCallBack )
    45     : iCalCallBack( aCalCallBack )
    67     {
    46     {
    68     TRACE_ENTRY_POINT;
    47     TRACE_ENTRY_POINT;
    69 
    48 
    70     iGlobalDataOwnsCalSession = EFalse;
    49     iGlobalDataOwnsCalSession = EFalse;
    71     iGlobalDataOwnsEntryView = EFalse;
    50 
    72     
       
    73     iCalendarForcedExit = EFalse;
       
    74     
       
    75     TRACE_EXIT_POINT;
    51     TRACE_EXIT_POINT;
    76     }
    52     }
    77 
    53 
    78 // ----------------------------------------------------------------------------
    54 // ----------------------------------------------------------------------------
    79 // CCalenGlobalData::NewL
    55 // CCalenGlobalData::NewL
    86 //
    62 //
    87 EXPORT_C CCalenGlobalData* CCalenGlobalData::NewL( MCalProgressCallBack& aCalCallBack,
    63 EXPORT_C CCalenGlobalData* CCalenGlobalData::NewL( MCalProgressCallBack& aCalCallBack,
    88                                                    MCalenContextChangeObserver* aNotifier )
    64                                                    MCalenContextChangeObserver* aNotifier )
    89     {
    65     {
    90     TRACE_ENTRY_POINT;
    66     TRACE_ENTRY_POINT;
    91 
       
    92     CCalenGlobalData* self = NULL;
    67     CCalenGlobalData* self = NULL;
    93     TAny* tlsPtr = Dll::Tls();
    68     TAny* tlsPtr = Dll::Tls();
    94 
    69 
    95     // Check Thread local storage
    70     // Check Thread local storage
    96     if (!tlsPtr)
    71     if (!tlsPtr)
   122 // CCalenGlobalData::InstanceL
    97 // CCalenGlobalData::InstanceL
   123 // Two-phased constructor.
    98 // Two-phased constructor.
   124 // (other items were commented in a header).
    99 // (other items were commented in a header).
   125 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   126 EXPORT_C CCalenGlobalData* CCalenGlobalData::InstanceL()
   101 EXPORT_C CCalenGlobalData* CCalenGlobalData::InstanceL()
   127     {
   102     {    	
   128     TRACE_ENTRY_POINT;
   103     TRACE_ENTRY_POINT;
   129 
   104 
   130     CCalenGlobalData* self = NULL;
   105     CCalenGlobalData* self = NULL;
   131     TAny* tlsPtr = Dll::Tls();
   106     TAny* tlsPtr = Dll::Tls();
   132 
   107 
   133     // Check Thread local storage
   108     // Check Thread local storage
   134     if (!tlsPtr)
   109     if (!tlsPtr)
   135         {
   110         {
   136         // The global data has not yet been constructed.
   111         // The global data has not yet been constructed.
   137         // FIXME - Revise comment
   112         // FIXME - Revise comment
   138         //TLS is NULL, so no CCalenGlobalData has been created yet.
   113         //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 );
   114         User::Leave( KErrNotReady );
   146         }
   115         }
   147     else
   116     else
   148         {
   117         {
   149         self = static_cast<CCalenGlobalData*>( tlsPtr );
   118         self = static_cast<CCalenGlobalData*>( tlsPtr );
   184 // (other items were commented in a header).
   153 // (other items were commented in a header).
   185 // -----------------------------------------------------------------------------
   154 // -----------------------------------------------------------------------------
   186 EXPORT_C CCalenGlobalData* CCalenGlobalData::Instance()
   155 EXPORT_C CCalenGlobalData* CCalenGlobalData::Instance()
   187     {
   156     {
   188     TRACE_ENTRY_POINT;
   157     TRACE_ENTRY_POINT;
   189 
       
   190     TAny* tlsPtr = Dll::Tls();
   158     TAny* tlsPtr = Dll::Tls();
   191     CCalenGlobalData* self = static_cast<CCalenGlobalData*>( tlsPtr );
   159     CCalenGlobalData* self = static_cast<CCalenGlobalData*>( tlsPtr );
   192 
   160 
   193     if ( self )
   161     if ( self )
   194         {
   162         {
   202 // -----------------------------------------------------------------------------
   170 // -----------------------------------------------------------------------------
   203 // CCalenGlobalData::ConstructL
   171 // CCalenGlobalData::ConstructL
   204 // Symbian 2nd phase constructor can leave.
   172 // Symbian 2nd phase constructor can leave.
   205 // (other items were commented in a header).
   173 // (other items were commented in a header).
   206 // -----------------------------------------------------------------------------
   174 // -----------------------------------------------------------------------------
   207 void CCalenGlobalData::ConstructL( MCalenContextChangeObserver* aNotifier )
   175 void CCalenGlobalData::ConstructL( MCalenContextChangeObserver* aNotifier)
   208     {
   176     {
   209     TRACE_ENTRY_POINT;
   177     TRACE_ENTRY_POINT;
   210 
   178 
   211     iContext = new (ELeave ) CCalenContextImpl( aNotifier );  
   179     iContext = new (ELeave ) CalenContextImpl( aNotifier );
   212     
   180 
   213     iNewInstanceViewCreation = NULL;
       
   214     
       
   215     TRACE_EXIT_POINT;
   181     TRACE_EXIT_POINT;
   216     }
   182     }
   217 
   183 
   218 // -----------------------------------------------------------------------------
   184 // -----------------------------------------------------------------------------
   219 // CCalenGlobalData::SetSessionL
   185 // CCalenGlobalData::SetSessionL
   264 // (other items were commented in a header).
   230 // (other items were commented in a header).
   265 // -----------------------------------------------------------------------------
   231 // -----------------------------------------------------------------------------
   266 CCalenGlobalData::~CCalenGlobalData()
   232 CCalenGlobalData::~CCalenGlobalData()
   267     {
   233     {
   268     TRACE_ENTRY_POINT;
   234     TRACE_ENTRY_POINT;
   269 
   235     
   270     delete iSend;
   236     delete iInterimUtils;    
   271     delete iInterimUtils;
   237     delete iEntryView;
   272     delete iUtilsAs;
   238     delete iInstanceView;
   273     delete iMailboxUtils;
   239     delete iEntryViewCreation;
   274     delete iMRUtils;
   240     delete iInstanceViewCreation;
   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;
   241     delete iContext;
       
   242 
       
   243     if (iGlobalDataOwnsCalSession)
       
   244         {
       
   245         delete iCalSession;
       
   246         }
   307     
   247     
   308     if(iGlobalDataOwnsEntryView)
   248     --iRefCount;
   309         {
       
   310         if(iEntryView)
       
   311             {
       
   312             delete iEntryView;
       
   313             iEntryView = NULL;           
       
   314             }
       
   315         }
       
   316 
       
   317    if (iGlobalDataOwnsCalSession)
       
   318         {
       
   319         delete iCalSession;
       
   320         }
       
   321     
   249     
   322     if( iFileMappingArray.Count() )
   250     // The controller owns its own instance of the services, therefore the
   323         {
   251     // reference count will be one, immediatley before deletion.
   324         iFileMappingArray.ResetAndDestroy();
   252     if (iRefCount == 1)
   325         }
   253         {
   326     
   254         delete this;
   327     iKeyQueue.Reset();
   255         }
   328     
       
   329     iHashDbidIndexMap.Close();
       
   330 
   256 
   331     Dll::SetTls(NULL);
   257     Dll::SetTls(NULL);
   332 
   258 
   333     if (iCalendarInfoList.Count())
   259     TRACE_EXIT_POINT;
   334         {
   260     }
   335         iCalendarInfoList.ResetAndDestroy();
   261 
   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 
   262 
   372 // -----------------------------------------------------------------------------
   263 // -----------------------------------------------------------------------------
   373 // CCalenGlobalData::CalSessionL
   264 // CCalenGlobalData::CalSessionL
   374 // Create a Calendar session if necessary and return a reference
   265 // Create a Calendar session if necessary and return a reference
   375 // (other items were commented in a header).
   266 // (other items were commented in a header).
   376 // -----------------------------------------------------------------------------
   267 // -----------------------------------------------------------------------------
   377 EXPORT_C CCalSession& CCalenGlobalData::CalSessionL()
   268 EXPORT_C CCalSession& CCalenGlobalData::CalSessionL()
   378     {
   269     {
   379     TRACE_ENTRY_POINT;
   270     TRACE_ENTRY_POINT;
   380     
   271 
   381     if (!iCalSession)
   272     if (!iCalSession)
   382         {
   273         {
   383         iGlobalDataOwnsCalSession = ETrue;
   274         iGlobalDataOwnsCalSession = ETrue;
   384         iCalSession = CCalSession::NewL();
   275         iCalSession = CCalSession::NewL();
   385 
   276 
   386         TRAPD( err, iCalSession->OpenL(KCalendarDatabaseFilePath));
   277         TRAPD( err, iCalSession->OpenL(KCalendarDatabaseFilePath));
   387         if (err == KErrNotFound)
   278         if ( err == KErrNotFound )
   388             {
   279             {
   389             CCalCalendarInfo* calendarInfo = GetDefaultCalendarInfoL();
   280             iCalSession->CreateCalFileL(KCalendarDatabaseFilePath);
   390             CleanupStack::PushL(calendarInfo);
   281             iCalSession->OpenL(KCalendarDatabaseFilePath); // not trapped anymore
   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             }
   282             }
   411         else
   283         else
   412             {
   284             {
   413             User::LeaveIfError( err );
   285             User::LeaveIfError( err );
   414             }
   286             }
       
   287 
   415         }
   288         }
   416 
   289 
   417     TRACE_EXIT_POINT;
   290     TRACE_EXIT_POINT;
   418     return *iCalSession;
   291     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     }
   292     }
   446 
   293 
   447 // -----------------------------------------------------------------------------
   294 // -----------------------------------------------------------------------------
   448 // CCalenGlobalData::InstanceViewL
   295 // CCalenGlobalData::InstanceViewL
   449 // Create an instance view if necessary and returns a reference.  Creating an
   296 // Create an instance view if necessary and returns a reference.  Creating an
   455 // (other items were commented in a header).
   302 // (other items were commented in a header).
   456 // -----------------------------------------------------------------------------
   303 // -----------------------------------------------------------------------------
   457 EXPORT_C CCalInstanceView* CCalenGlobalData::InstanceViewL()
   304 EXPORT_C CCalInstanceView* CCalenGlobalData::InstanceViewL()
   458     {
   305     {
   459     TRACE_ENTRY_POINT;
   306     TRACE_ENTRY_POINT;
   460     
   307 
   461     if (!iInstanceView && !iInstanceViewCreation)
   308     if (!iInstanceView && !iInstanceViewCreation)
   462         {
   309         {
   463         if ( iEntryViewCreation )
   310         if ( iEntryViewCreation )
   464             {
   311             {
       
   312             /* We need queueing to avoid two immediate instance and entry view creation requests to symbian.
       
   313              * Though symbian handle two immediate requests ,this we require because we have only one observer
       
   314              * for callback and we would not be able to differentiate whether instance view got created or entry view got created.
       
   315              * If we dont queue the second request, we may end up giving incomplete object to the caller function.
       
   316              */
   465             iQueued = &CreateInstanceViewL;
   317             iQueued = &CreateInstanceViewL;
   466             }
   318             }
   467         else
   319         else
   468             {
   320             {
   469             CreateInstanceViewL();
   321             CreateInstanceViewL();
   470             }
   322             }
   471         }
   323         }
   472     
   324 
   473     TRACE_EXIT_POINT;
   325     TRACE_EXIT_POINT;
   474     return iInstanceView;
   326     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     }
   327     }
   500 
   328 
   501 // -----------------------------------------------------------------------------
   329 // -----------------------------------------------------------------------------
   502 // CCalenGlobalData::EntryViewL
   330 // CCalenGlobalData::EntryViewL
   503 // Create an entry view if necessary and returns a reference.  Creating an
   331 // Create an entry view if necessary and returns a reference.  Creating an
   509 // (other items were commented in a header).
   337 // (other items were commented in a header).
   510 // -----------------------------------------------------------------------------
   338 // -----------------------------------------------------------------------------
   511 EXPORT_C CCalEntryView* CCalenGlobalData::EntryViewL()
   339 EXPORT_C CCalEntryView* CCalenGlobalData::EntryViewL()
   512     {
   340     {
   513     TRACE_ENTRY_POINT;
   341     TRACE_ENTRY_POINT;
   514     
   342 
   515      if (!iEntryView && !iEntryViewCreation)
   343     if (!iEntryView && !iEntryViewCreation)
   516         {
   344         {
   517         if ( iInstanceViewCreation )
   345         if ( iInstanceViewCreation )
   518             {
   346             {
       
   347             /* We need queueing to avoid two immediate instance and entry view creation requests to symbian.
       
   348              * Though symbian handle two immediate requests ,this we require because we have only one observer
       
   349              * for callback and we would not be able to differentiate whether instance view got created or entry view got created.
       
   350              * If we dont queue the second request, we may end up giving incomplete object to the caller function.
       
   351              */
   519             iQueued = &CreateEntryViewL;
   352             iQueued = &CreateEntryViewL;
   520             }
   353             }
   521         else
   354         else
   522             {
   355             {
   523             CreateEntryViewL();
   356             CreateEntryViewL();
   524             }
   357             }
   525         }
   358         }
   526     
   359     TRACE_EXIT_POINT;
   527      TRACE_EXIT_POINT;
       
   528     return iEntryView;
   360     return iEntryView;
   529     }
   361     }
   530 
   362 
   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()
   363 void CCalenGlobalData::CreateEntryViewL()
  1070     {
   364     {
  1071     TRACE_ENTRY_POINT;
   365     TRACE_ENTRY_POINT;
  1072 
   366     iEntryViewCreation = CCalEntryView::NewL( CalSessionL(), iCalCallBack );
  1073     HBufC* calendarFileName = KCalendarDatabaseFilePath().AllocLC();
   367     TRACE_EXIT_POINT;
  1074     TInt index  = iFileMappingArray.Find(   
   368     }
  1075             *calendarFileName, CCalenGlobalData::CalenInfoIdentifierL);
   369 
  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()
   370 void CCalenGlobalData::CreateInstanceViewL()
  1110     {
   371     {
  1111     TRACE_ENTRY_POINT;
   372     TRACE_ENTRY_POINT;
  1112     iInstanceViewCreation = CCalInstanceView::NewL( CalSessionL(), iCalCallBack );
   373     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;
   374     TRACE_EXIT_POINT;
  1150     }
   375     }
  1151 
   376 
  1152 // -----------------------------------------------------------------------------
   377 // -----------------------------------------------------------------------------
  1153 // CEntryViewObserver::ViewCreationCompleted
   378 // CEntryViewObserver::ViewCreationCompleted
  1162     if ( !aSuccess )
   387     if ( !aSuccess )
  1163         {
   388         {
  1164         // Something has gone wrong
   389         // Something has gone wrong
  1165         delete iEntryViewCreation;
   390         delete iEntryViewCreation;
  1166         delete iInstanceViewCreation;
   391         delete iInstanceViewCreation;
  1167         delete iNewEntryViewCreation;
       
  1168         delete iNewInstanceViewCreation;
       
  1169         }
   392         }
  1170     else
   393     else
  1171         {
   394         {
  1172         if ( iEntryViewCreation )
   395         if ( iEntryViewCreation )
  1173             {
   396             {
  1174             iEntryView = iEntryViewCreation;
   397             iEntryView = iEntryViewCreation;
  1175             }
   398             }
  1176         else if ( iInstanceViewCreation )
   399         else if ( iInstanceViewCreation )
  1177             {
   400             {
  1178             iInstanceView = iInstanceViewCreation;
   401             iInstanceView = iInstanceViewCreation;
  1179             }
       
  1180         
       
  1181         if ( iNewEntryViewCreation )
       
  1182             {
       
  1183             iNewEntryView = iEntryViewCreation;
       
  1184             }
       
  1185         else if ( iNewInstanceViewCreation )
       
  1186             {
       
  1187             iNewInstanceView = iNewInstanceViewCreation;
       
  1188             }
   402             }
  1189         }
   403         }
  1190 
   404 
  1191     iEntryViewCreation = NULL;
   405     iEntryViewCreation = NULL;
  1192     iInstanceViewCreation = NULL;
   406     iInstanceViewCreation = NULL;
  1193     iNewEntryViewCreation = NULL;
   407 
  1194     iNewInstanceViewCreation = NULL;
       
  1195     
       
  1196     if ( iQueued )
   408     if ( iQueued )
  1197         {
   409         {
  1198         (this->*iQueued)();
   410         (this->*iQueued)();
  1199         iQueued = NULL;
   411         iQueued = NULL;
  1200         }
   412         }
  1201 
   413 
  1202     TRACE_EXIT_POINT;
   414     TRACE_EXIT_POINT;
  1203     }
   415     }
  1204 
   416 
  1205 // -----------------------------------------------------------------------------
   417 // -----------------------------------------------------------------------------
  1206 // CCalenGlobalData::CreateNewSessionL
   418 // CCalenGlobalData::RegisterEntryViewObserver
  1207 // Create a Calendar session if necessary and return a reference
   419 // Add observer into view observers entry observer list.
  1208 // (other items were commented in a header).
   420 // (other items were commented in a header).
  1209 // -----------------------------------------------------------------------------
   421 // -----------------------------------------------------------------------------
  1210 CCalSession& CCalenGlobalData::CreateNewSessionL( const TDesC& aCalendar )
   422 EXPORT_C TBool CCalenGlobalData::EntryViewExists()
  1211     {
   423     {
  1212     TRACE_ENTRY_POINT;
   424     TRACE_ENTRY_POINT;
  1213 
   425     TRACE_EXIT_POINT;
  1214     if(!iNewCalSession)
   426     return ( iEntryView != NULL );
  1215         {
   427     }
  1216         iNewCalSession = CCalSession::NewL(*iCalSession);
   428 
  1217         
   429 
  1218         TRAPD( err, iNewCalSession->OpenL(aCalendar));
   430 // -----------------------------------------------------------------------------
  1219         if ( err == KErrNotFound )
   431 // CCalenGlobalData::Context
  1220            {
   432 // Return a reference to the CCalenContext object
  1221            iNewCalSession->CreateCalFileL(aCalendar);
   433 // (other items were commented in a header).
  1222            iNewCalSession->OpenL(aCalendar); // not trapped anymore
   434 // -----------------------------------------------------------------------------
  1223            }
   435 EXPORT_C MCalenContext& CCalenGlobalData::Context()
  1224         else
   436     {
  1225            {
   437     TRACE_ENTRY_POINT;
  1226            User::LeaveIfError( err );
   438     TRACE_EXIT_POINT;
  1227            }
   439     return *iContext;
  1228         }
   440     }
  1229     TRACE_EXIT_POINT;
   441 
  1230     return *iNewCalSession;
   442 void CCalenGlobalData::HandleNotification(const TCalenNotification aNotification )
  1231     }
   443     {
  1232 
   444     TRACE_ENTRY_POINT;
  1233 // -----------------------------------------------------------------------------
   445 
  1234 // CCalenGlobalData::CalenInfoIdentifierL
   446     if ( aNotification == ECalenNotifyEntryInstanceViewCreated )
  1235 // -----------------------------------------------------------------------------
   447         {
  1236 //
   448         ViewCreationCompleted( ETrue );
  1237 TBool CCalenGlobalData::CalenInfoIdentifierL( const HBufC* aName,
   449         }
  1238                                         const CCalenFileMapping& aFileMapping)
   450     else if (aNotification == ECalenNotifyEntryInstanceViewCreationFailed )
  1239     {
   451         {
  1240     TRACE_ENTRY_POINT;
   452         ViewCreationCompleted( EFalse );
  1241     TPtrC calendarFileName = aFileMapping.GetCalendarFileName();
   453         }
  1242     TRACE_EXIT_POINT;
   454 
  1243     return (!calendarFileName.CompareF(*aName));
   455     TRACE_EXIT_POINT;
  1244     }
   456     }
  1245 
   457 
  1246 // -----------------------------------------------------------------------------
   458 // Enf of file
  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