diff -r 96907930389d -r 12af337248b1 calendarui/globaldata/src/calenglobaldata.cpp --- a/calendarui/globaldata/src/calenglobaldata.cpp Thu Aug 19 09:53:43 2010 +0300 +++ b/calendarui/globaldata/src/calenglobaldata.cpp Tue Aug 31 15:13:43 2010 +0300 @@ -11,59 +11,27 @@ * * Contributors: * -* Description: Global Data for Calendar application +* Description: Global Data for Calendar application * */ - //debug #include "calendarui_debug.h" // INCLUDE FILES -#include "calenglobaldata.h" // CCalenGlobalData -#include "RImplInfoPtrArrayOwn.inl" // Wrapper class with array deletion on close -#include "calensend.h" // CCalenSend -#include "CalenInterimUtils2.h" // CalenInterimUtils +#include "calenglobaldata.h" // CalenGlobalData +#include "calencontext.h" // Calendar context #include "calencontextimpl.h" // Calendar context implementation -#include "calenfilemapping.h" -#include "missedalarmstore.h" -#include "CleanupResetAndDestroy.h" -#include "calendar.hrh" - -#include // Calendar resources -#include // CMRMailboxUtils -#include // CnvUtfConverter -#include // Loads strings from resource files -#include // Feature discovery API -#include // Calendar database session +#include "hb_calencommands.hrh" +#include // Calendar database session #include // Calendar Instance view #include // Calendar Entry view -#include // CMRMailboxUtils -#include // Calendar commands -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // Default Calendar database path -_LIT( KCalendarDatabaseFilePath, "c:calendar" ); -_LIT( KPhoneCalendar,"Personal" ); -_LIT( KExtCalendar,"Ext calendar" ); -const TInt KBuffLength = 24; +_LIT( KCalendarDatabaseFilePath, "c:Calendar" ); -_LIT(KPersonal,"Personal"); - -_LIT( KMissedAlarmResourceFile, "z:\\resource\\CalenSvrMissedAlarmManagerResource.rsc"); // changes done - // ============================ MEMBER FUNCTIONS =============================== // ----------------------------------------------------------------------------- @@ -72,16 +40,14 @@ // (other items were commented in a header). // ----------------------------------------------------------------------------- // + CCalenGlobalData::CCalenGlobalData( MCalProgressCallBack& aCalCallBack ) : iCalCallBack( aCalCallBack ) { TRACE_ENTRY_POINT; iGlobalDataOwnsCalSession = EFalse; - iGlobalDataOwnsEntryView = EFalse; - - iCalendarForcedExit = EFalse; - + TRACE_EXIT_POINT; } @@ -95,11 +61,9 @@ // ---------------------------------------------------------------------------- // EXPORT_C CCalenGlobalData* CCalenGlobalData::NewL( MCalProgressCallBack& aCalCallBack, - MCalenContextChangeObserver* aNotifier, - MCalenDBChangeObserver* aDBNotifier) + MCalenContextChangeObserver* aNotifier ) { TRACE_ENTRY_POINT; - CCalenGlobalData* self = NULL; TAny* tlsPtr = Dll::Tls(); @@ -115,7 +79,7 @@ // calls CCalenGlobalData::InstanceL in ConstructL and then ConstructL // leaves, we will double delete the global data. ++self->iRefCount; - self->ConstructL( aNotifier, aDBNotifier ); + self->ConstructL( aNotifier ); CleanupStack::Pop( self ); } else @@ -135,7 +99,7 @@ // (other items were commented in a header). // ----------------------------------------------------------------------------- EXPORT_C CCalenGlobalData* CCalenGlobalData::InstanceL() - { + { TRACE_ENTRY_POINT; CCalenGlobalData* self = NULL; @@ -146,13 +110,7 @@ { // The global data has not yet been constructed. // FIXME - Revise comment - //TLS is NULL, so no CCalenGlobalData has been created yet. - /* self = new( ELeave ) CCalenGlobalData; - CleanupStack::PushL( self ); - self->ConstructL(); - //Store a self pointer in TLS - User::LeaveIfError( Dll::SetTls(static_cast(self))); - CleanupStack::Pop(self);*/ + //TLS is NULL, so no CCalenGlobalData has been created yet. User::Leave( KErrNotReady ); } else @@ -197,7 +155,6 @@ EXPORT_C CCalenGlobalData* CCalenGlobalData::Instance() { TRACE_ENTRY_POINT; - TAny* tlsPtr = Dll::Tls(); CCalenGlobalData* self = static_cast( tlsPtr ); @@ -215,17 +172,12 @@ // Symbian 2nd phase constructor can leave. // (other items were commented in a header). // ----------------------------------------------------------------------------- -void CCalenGlobalData::ConstructL( MCalenContextChangeObserver* aNotifier, - MCalenDBChangeObserver* aDBNotifier) +void CCalenGlobalData::ConstructL( MCalenContextChangeObserver* aNotifier) { TRACE_ENTRY_POINT; - iContext = new (ELeave ) CCalenContextImpl( aNotifier ); - - iNewInstanceViewCreation = NULL; - - iDBChangeNotifier = aDBNotifier; - + iContext = new (ELeave ) CalenContextImpl( aNotifier ); + TRACE_EXIT_POINT; } @@ -280,109 +232,33 @@ CCalenGlobalData::~CCalenGlobalData() { TRACE_ENTRY_POINT; - - delete iSend; - delete iInterimUtils; - delete iUtilsAs; - delete iMailboxUtils; - delete iMRUtils; - - if (iInstanceView) - { - delete iInstanceView; - iInstanceView = NULL; - } - - if (iInstanceViewCreation) - { - delete iInstanceViewCreation; - iInstanceViewCreation = NULL; - } + + delete iInterimUtils; + delete iEntryView; + delete iInstanceView; + delete iEntryViewCreation; + delete iInstanceViewCreation; + delete iContext; - if (iEntryViewCreation) - { - delete iEntryViewCreation; - iEntryViewCreation = NULL; - } - - if (iNewInstanceView) - { - delete iNewInstanceView; - iNewInstanceView = NULL; - iNewInstanceViewCreation = NULL; - } - - if (iNewInstanceViewCreation) - { - delete iNewInstanceViewCreation; - iNewInstanceViewCreation = NULL; - } - - delete iContext; - - if(iGlobalDataOwnsEntryView) - { - if(iEntryView) - { - delete iEntryView; - iEntryView = NULL; - } - } - - if (iGlobalDataOwnsCalSession) + if (iGlobalDataOwnsCalSession) { delete iCalSession; } - if (iCalendarInfoList.Count()) - { - iCalendarInfoList.ResetAndDestroy(); - } - - if( iFileMappingArray.Count() ) + --iRefCount; + + // The controller owns its own instance of the services, therefore the + // reference count will be one, immediatley before deletion. + if (iRefCount == 1) { - iFileMappingArray.ResetAndDestroy(); + delete this; } - - iKeyQueue.Reset(); - - iHashDbidIndexMap.Close(); Dll::SetTls(NULL); - if (iCalendarsSession) - { - delete iCalendarsSession; - iCalendarsSession = NULL; - } - TRACE_EXIT_POINT; } -// ----------------------------------------------------------------------------- -// CCalenGlobalData::MailboxUtilsL -// Create MailBoxUtils if necessary and returns a reference -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C CMRMailboxUtils& CCalenGlobalData::MRMailboxUtilsL() - { - TRACE_ENTRY_POINT; - - if (!iMailboxUtils) - { - if (InterimUtilsL().MRViewersEnabledL()) - { - iMailboxUtils = CMRMailboxUtils::NewL(); - } - else - { - User::Leave(KErrNotSupported); - } - } - - TRACE_EXIT_POINT; - return *iMailboxUtils; - } // ----------------------------------------------------------------------------- // CCalenGlobalData::CalSessionL @@ -392,41 +268,23 @@ EXPORT_C CCalSession& CCalenGlobalData::CalSessionL() { TRACE_ENTRY_POINT; - + if (!iCalSession) { iGlobalDataOwnsCalSession = ETrue; iCalSession = CCalSession::NewL(); TRAPD( err, iCalSession->OpenL(KCalendarDatabaseFilePath)); - if (err == KErrNotFound) - { - CCalCalendarInfo* calendarInfo = GetDefaultCalendarInfoL(); - CleanupStack::PushL(calendarInfo); - iCalSession->CreateCalFileL( KCalendarDatabaseFilePath, - *calendarInfo); - iCalSession->OpenL(KCalendarDatabaseFilePath); - CleanupStack::PopAndDestroy(calendarInfo); - } - else if(err == KErrNone) + if ( err == KErrNotFound ) { - // temp solution...need to handle this case - CCalCalendarInfo* calendarInfo = iCalSession->CalendarInfoL(); - CleanupStack::PushL(calendarInfo); - if( !calendarInfo->NameL().Compare(KNullDesC) && - !calendarInfo->Enabled() ) - { - calendarInfo->SetNameL(KExtCalendar); - calendarInfo->SetColor(KRgbBlack.Value()); - iCalSession->SetCalendarInfoL(*calendarInfo); - } - CleanupStack::PopAndDestroy(calendarInfo); - + iCalSession->CreateCalFileL(KCalendarDatabaseFilePath); + iCalSession->OpenL(KCalendarDatabaseFilePath); // not trapped anymore } else { User::LeaveIfError( err ); } + } TRACE_EXIT_POINT; @@ -434,32 +292,6 @@ } // ----------------------------------------------------------------------------- -// CCalenGlobalData::CalSessionL -// Based on the calendar name return already cached session from iFileMappingArray -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C CCalSession& CCalenGlobalData::CalSessionL(const TDesC& aCalendar) - { - TRACE_ENTRY_POINT; - CCalSession* session = NULL; - HBufC* calendarFileName = aCalendar.AllocLC(); - TInt index = iFileMappingArray.Find( - *calendarFileName,CCalenGlobalData::CalenInfoIdentifierL); - CleanupStack::PopAndDestroy(calendarFileName); - if(KErrNotFound != index) - { - session = iFileMappingArray[index]->GetSessionPtr(); - } - else - { - User::LeaveIfError(KErrNotFound); - } - - TRACE_EXIT_POINT; - return *session; - } - -// ----------------------------------------------------------------------------- // CCalenGlobalData::InstanceViewL // Create an instance view if necessary and returns a reference. Creating an // instance view is an asynchronous operation, but this call returns @@ -472,11 +304,16 @@ EXPORT_C CCalInstanceView* CCalenGlobalData::InstanceViewL() { TRACE_ENTRY_POINT; - + if (!iInstanceView && !iInstanceViewCreation) { if ( iEntryViewCreation ) { + /* We need queueing to avoid two immediate instance and entry view creation requests to symbian. + * Though symbian handle two immediate requests ,this we require because we have only one observer + * for callback and we would not be able to differentiate whether instance view got created or entry view got created. + * If we dont queue the second request, we may end up giving incomplete object to the caller function. + */ iQueued = &CreateInstanceViewL; } else @@ -484,36 +321,12 @@ CreateInstanceViewL(); } } - + TRACE_EXIT_POINT; return iInstanceView; } // ----------------------------------------------------------------------------- -// CCalenGlobalData::InstanceViewL -// Based on collection id array Create an instance view if necessary and returns a reference. -// Creating an instance view is an asynchronous operation, but this call returns -// synchronously. When the view is created, Completed() is called, which stops -// iAs allowing this function to complete. -// Leaves with KErrInUse if this class is in the process of creating the -// instance view -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C CCalInstanceView* CCalenGlobalData::InstanceViewL( - const RArray& aCollectionIds) - { - TRACE_ENTRY_POINT; - - if(!iNewInstanceView && !iNewInstanceViewCreation) - { - CreateInstanceViewL(aCollectionIds); - } - - TRACE_EXIT_POINT; - return iNewInstanceView; - } - -// ----------------------------------------------------------------------------- // CCalenGlobalData::EntryViewL // Create an entry view if necessary and returns a reference. Creating an // entry view is an asynchronous operation, but this call returns @@ -526,11 +339,16 @@ EXPORT_C CCalEntryView* CCalenGlobalData::EntryViewL() { TRACE_ENTRY_POINT; - - if (!iEntryView && !iEntryViewCreation) + + if (!iEntryView && !iEntryViewCreation) { if ( iInstanceViewCreation ) { + /* We need queueing to avoid two immediate instance and entry view creation requests to symbian. + * Though symbian handle two immediate requests ,this we require because we have only one observer + * for callback and we would not be able to differentiate whether instance view got created or entry view got created. + * If we dont queue the second request, we may end up giving incomplete object to the caller function. + */ iQueued = &CreateEntryViewL; } else @@ -538,636 +356,21 @@ CreateEntryViewL(); } } - - TRACE_EXIT_POINT; + TRACE_EXIT_POINT; return iEntryView; } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::EntryViewL -// Based on collection id array Create an entry view if necessary and returns a reference. -// Creating an entry view is an asynchronous operation, but this call returns -// synchronously. When the view is created, Completed() is called, which stops -// iAs allowing this function to complete. -// Leaves with KErrInUse if this class is in the process of creating the -// entry view -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C CCalEntryView* CCalenGlobalData::EntryViewL( - const TCalCollectionId aCollectionId) - { - TRACE_ENTRY_POINT; - __ASSERT_ALWAYS(aCollectionId > 0 ,User::Panic(_L("CCalenGlobalData"),-1)); - - CCalEntryView* entryView = NULL; - - TInt index = iHashDbidIndexMap.FindL(aCollectionId); - if(index != KErrNotFound) - { - entryView = iFileMappingArray[index]->GetEntryView(); - } - - if(!entryView) - { - User::LeaveIfNull(entryView); - } - - TRACE_EXIT_POINT; - return entryView; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::RegisterEntryViewObserver -// Add observer into view observers entry observer list. -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C TBool CCalenGlobalData::EntryViewExists() - { - TRACE_ENTRY_POINT; - TRACE_EXIT_POINT; - return ( iEntryView != NULL ); - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::MeetingRequestUtilsL -// Create MR Utils if necessary and returns a reference -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C CMRUtils& CCalenGlobalData::MeetingRequestUtilsL() - { - TRACE_ENTRY_POINT; - - iCreateError = KErrNone; - if (!iUtilsAs) - { - iUtilsAs = new (ELeave) CActiveSchedulerWait; - } - if (!iMRUtils) - { - if (InterimUtilsL().MRViewersEnabledL()) - { - if (iUtilsAs->IsStarted()) - { - User::Leave(KErrInUse); - } - else - { - //Get the currently selected mailbox - CMRMailboxUtils::TMailboxInfo defaultMailbox; - MRMailboxUtilsL().GetDefaultMRMailBoxL(defaultMailbox); - //CMRUtils resolves meeting request utilities based on mtm uid - TBuf8 mrMtm; - CnvUtfConverter::ConvertFromUnicodeToUtf8(mrMtm, defaultMailbox.iMtmUid.Name()); - iMRUtils = CMRUtils::NewL(mrMtm, *this, CalSessionL(), NULL); - iUtilsAs->Start(); - User::LeaveIfError(iCreateError); - } - } - else - { - User::Leave(KErrNotSupported); - } - } - - TRACE_EXIT_POINT; - return *iMRUtils; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::InterimUtilsL -// Create a CCalenInterimUtils object if neccessary and return a reference -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C CCalenInterimUtils2& CCalenGlobalData::InterimUtilsL() +void CCalenGlobalData::CreateEntryViewL() { TRACE_ENTRY_POINT; - - if(!iInterimUtils) - { - iInterimUtils = CCalenInterimUtils2::NewL(); - } - - TRACE_EXIT_POINT; - return *iInterimUtils; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CalenSendL -// Create a CCalenSend object if neccessary and return a reference -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C CCalenSend& CCalenGlobalData::CalenSendL() - { - TRACE_ENTRY_POINT; - - if( !iSend ) - { - iSend = CCalenSend::NewL( ECalenSend, CalSessionL() ); - } - - TRACE_EXIT_POINT; - return *iSend; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::Context -// Return a reference to the CCalenContext object -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C MCalenContext& CCalenGlobalData::Context() - { - TRACE_ENTRY_POINT; - TRACE_EXIT_POINT; - return *iContext; - } - -// ----------------------------------------------------------------------------- -// CCalenEditUi::AttemptToRetrieveDefaultMailboxL -// Check to see if we have any mailboxes defined, and if we have a default -// mailbox. If we don't, inform the user and return EFalse. This function -// returns ETrue if aDefaultMailbox was initialised, and it is OK to create -// a new MR. -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C TBool CCalenGlobalData::AttemptToRetrieveDefaultMailboxL( CMRMailboxUtils::TMailboxInfo& aDefaultMailbox) - { - TRACE_ENTRY_POINT; - - CMRMailboxUtils& mbUtils = MRMailboxUtilsL(); - // Get the currently defined mailboxes. - RArray mailboxes; - CleanupClosePushL(mailboxes); - mbUtils.ListMailBoxesL(mailboxes); - - TBool canCreateMeetingRequest=EFalse; - TInt mbCount = mailboxes.Count(); - - // The following 'if-else' block should always initialise - // defaultMailBox if canCreateMeetingRequest comes out as ETrue. - if(mbCount > 0) - { - TInt res = KErrNone; - TRAPD(err, res = mbUtils.GetDefaultMRMailBoxL(aDefaultMailbox)); - if( res == KErrNone && err == KErrNone) - { - canCreateMeetingRequest = ETrue; - } - else - { - // We have one or more mailboxes defined, but failed to get a default. - // Ask user to answer "Select default mailbox" query. The available mailboxes must - // first be reduced to only show mailboxes with an associated meetnig request solution - RImplInfoPtrArrayOwn implArray; - CleanupClosePushL( implArray ); - //Get all MRViewers Implementation - const TUid mrViewersIface = {KMRViewersInterfaceUID}; - REComSession::ListImplementationsL(mrViewersIface, implArray ); - - for (TInt i = mailboxes.Count() - 1; i >= 0; --i) - { - //See if any meeting request implementation matches this mailbox - for (TInt j=0; j mbName; - CnvUtfConverter::ConvertToUnicodeFromUtf8( mbName, implArray[j]->DataType() ); - if(mailboxes[i].iMtmUid.Name().CompareF(mbName) == 0) - { - //Found a match - break; - } - //Mailbox has no matching meeting request solution - //remove from list - mailboxes.Remove(i); - } - } - CleanupStack::PopAndDestroy(); //implArray - - TInt selected = PromptToSelectDefaultMailboxL(mailboxes); - - if(selected >= KErrNone) - { - mbUtils.SetDefaultMRMailBoxL( mailboxes[selected].iEntryId ); - canCreateMeetingRequest = ETrue; - __ASSERT_ALWAYS((mbUtils.GetDefaultMRMailBoxL( aDefaultMailbox ) == KErrNone), User::Invariant()); // so we don't return ref to local variable. - } - } - } - else - { - // Force the check of MR Impl existing - InterimUtilsL().MRViewersEnabledL(ETrue); //ignore result - } - - CleanupStack::PopAndDestroy(); // mailboxes - - TRACE_EXIT_POINT; - return canCreateMeetingRequest; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::ResetKeyEventQueue -// Reset Keyevents queue -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C void CCalenGlobalData::ResetKeyEventQueue() - { - TRACE_ENTRY_POINT; - iKeyQueue.Reset(); + iEntryViewCreation = CCalEntryView::NewL( CalSessionL(), iCalCallBack ); TRACE_EXIT_POINT; } -// ----------------------------------------------------------------------------- -// CCalenGlobalData::QueueKeyEvent -// Queue key press event in a queue -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C TBool CCalenGlobalData::QueueKeyEvent(const TKeyEvent& aEvent, - TEventCode aType) - { - TRACE_ENTRY_POINT; - TBool result(EFalse); - TQueuedKeyEvent item; - item.iType = aType; - item.iEvent = aEvent; - if( iKeyQueue.Insert(item, iKeyQueue.Count()) == KErrNone) // add to last - { - result = ETrue; - } - TRACE_EXIT_POINT; - return result; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::GetQueueKeyEvent -// Get 1 queued event from the queue -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -EXPORT_C TBool CCalenGlobalData::GetQueuedKeyEvent(TKeyEvent& aEvent, TEventCode& aType) - { - TRACE_ENTRY_POINT; - TBool result(EFalse); - if(iKeyQueue.Count() > 0) - { - TQueuedKeyEvent item; - item = iKeyQueue[0];// get first - aEvent = item.iEvent; - aType = item.iType; - iKeyQueue.Remove(0); // remove first - result = ETrue; - iKeyQueue.Compress(); - } - TRACE_EXIT_POINT; - return result; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::ConstructFileMappingL -// Constructs mapping between symbian calendar file and metabd info -// ----------------------------------------------------------------------------- -EXPORT_C TBool CCalenGlobalData::ConstructFileMappingL() - { - TRACE_ENTRY_POINT; - iCalendarsSession = CCalSession::NewL(); - - ConstructCalendarsListL(); - - iFileMappingArray.Reset(); - - for(TInt index = 0; index < iCalendarInfoList.Count(); index++) - { - TPtrC calendarFileName = iCalendarInfoList[index]->FileNameL(); - CCalenFileMapping* filemap = CCalenFileMapping::NewL(); - CleanupStack::PushL(filemap); - filemap->SetCalendarFileNameL(calendarFileName); - - iNewEntryView = NULL; - iNewEntryViewCreation = NULL; - CCalenDbChangeNotifier* dbChangeNotifier = NULL; - if(iCalSession) - { - iNewCalSession = NULL; - CCalCalendarInfo* calendarInfo = iCalendarInfoList[index]; - - CCalSession& tempSession = CreateNewSessionL( calendarFileName, - *calendarInfo ); - filemap->SetSessionPtr(&tempSession); - filemap->SetCollectionId(tempSession.CollectionIdL()); - CreateEntryViewL(tempSession); - filemap->SetEntryView( iNewEntryView ); - dbChangeNotifier = CCalenDbChangeNotifier::NewL( tempSession ); - dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier); - filemap->SetDBChangeNotifier(dbChangeNotifier); - } - else - { - CCalSession& tempSession = CalSessionL(); - filemap->SetSessionPtr(&tempSession); - filemap->SetCollectionId(tempSession.CollectionIdL()); - CreateEntryViewL(tempSession); - filemap->SetEntryView( iNewEntryView ); - iGlobalDataOwnsEntryView = EFalse; - iGlobalDataOwnsCalSession = EFalse; - dbChangeNotifier = CCalenDbChangeNotifier::NewL( tempSession ); - dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier); - filemap->SetDBChangeNotifier(dbChangeNotifier); - } - iFileMappingArray.Append(filemap); - CleanupStack::Pop(filemap); - } - - for(TInt index = 0; index < iFileMappingArray.Count(); index++) - { - iHashDbidIndexMap.InsertL( iFileMappingArray[index]->GetCollectionId(), - index); - } - - TRACE_EXIT_POINT - return ETrue; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::InitializeGlobalDataL -// Initializes multiple db related objects -// ----------------------------------------------------------------------------- -EXPORT_C void CCalenGlobalData::InitializeGlobalDataL() - { - TRACE_ENTRY_POINT - - ConstructFileMappingL(); - - TRACE_EXIT_POINT - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::PromptToSelectDefaultMailboxL -// Prompts the user to select the default mailbox. If the user cancels, the -// function returns KErrCancel, otherwise it returns the index of the selected -// mailbox. This function does not set the default mailbox, but rather returns -// the index of the given array to which the default should be set. -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -TInt CCalenGlobalData::PromptToSelectDefaultMailboxL( RArray& aMailboxes ) - { - TRACE_ENTRY_POINT; - - TInt mbCount = aMailboxes.Count(); - - TInt selected; - if (mbCount > 0) - { - CAknSinglePopupMenuStyleListBox* list = - new (ELeave) CAknSinglePopupMenuStyleListBox; - CleanupStack::PushL(list); - - CAknPopupList* popupList = CAknPopupList::NewL(list, R_AVKON_SOFTKEYS_OK_CANCEL); - CleanupStack::PushL(popupList); - - list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect); - list->CreateScrollBarFrameL(ETrue); - list->ScrollBarFrame()->SetScrollBarVisibilityL( - CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); - - CEikonEnv* eikEnv = CEikonEnv::Static(); - - CDesCArrayFlat* items = new (ELeave)CDesCArrayFlat(mbCount); - CleanupStack::PushL(items); - for(TInt i=0; iAppendL( aMailboxes[i].iName ); - } - CleanupStack::Pop(items); - CTextListBoxModel* model = list->Model(); - - //Pass ownersip of items to model - model->SetItemTextArray(items); - - HBufC* title = StringLoader::LoadLC(R_CALEN_SELECT_MAILBOX, eikEnv); - popupList->SetTitleL(*title); - CleanupStack::PopAndDestroy(title); - - TBool accepted = popupList->ExecuteLD(); - CleanupStack::Pop(); // popupList - - if(accepted) - { - selected = list->CurrentItemIndex(); - } - else - { - selected = KErrCancel; - } - - CleanupStack::PopAndDestroy(); // list - } - else - { - //No mailboxes defined. Could prompt user to define one here? - selected = KErrCancel; - } - - TRACE_EXIT_POINT; - return selected; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::HandleCalEngStatus -// Called when Meeting Request utils are creation is complete. -// Stops the CActiveSchedulerWait, allowing MeetingRequestUtilsL() to complete -// (other items were commented in a header). -// ----------------------------------------------------------------------------- -void CCalenGlobalData::HandleCalEngStatus( TMRUtilsCalEngStatus aStatus ) - { - TRACE_ENTRY_POINT; - - ASSERT(iUtilsAs); - - switch (aStatus) - { - case ENotReady: - { - //Keep waiting - } - break; - case EAvailableWithoutTombs: - case EAvailable: - { - //Ready for use. Stop the CActiveSchedulerWait and return - iUtilsAs->AsyncStop(); - iCreateError = KErrNone; - } - break; - case ENotAvailable: - { - //Somethings gone wrong. Stop the CActiveSchedulerWait but force - //MeetingRequestUtilsL to leave. - //We'll use KErrNotFound for now but we don't know what the problem is. - iUtilsAs->AsyncStop(); - iCreateError = KErrNotFound; - } - break; - default: - { - //Shouldn't ever get called. - iUtilsAs->AsyncStop(); - iCreateError = KErrArgument; - } - break; - } - - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::HandleNotification -// Handle any notification if registered for -// ----------------------------------------------------------------------------- -void CCalenGlobalData::HandleNotification(const TCalenNotification aNotification ) - { - TRACE_ENTRY_POINT; - - switch(aNotification) - { - case ECalenNotifyEntryInstanceViewCreated: - { - ViewCreationCompleted( ETrue ); - } - break; - case ECalenNotifyEntryInstanceViewCreationFailed: - { - ViewCreationCompleted( EFalse ); - } - break; - case ECalenNotifyDeleteInstanceView: - { - //InstanceView has to be deleted since deleting any session(Calendar) - //entryView and instanceView has to be deleted before deleting session. - if(iNewInstanceView) - { - delete iNewInstanceView; - iNewInstanceViewCreation = iNewInstanceView = NULL; - } - - //If InstanceView is called by any component single instanceView - // without the knowledge of multi session (calendar). - //This instance also should be deleted for deleting the session. - if(iInstanceView) - { - delete iInstanceView; - iInstanceView = iInstanceViewCreation = NULL; - } - } - break; - case ECalenNotifyRealExit: - { - iCalendarForcedExit = ETrue; - } - break; - case ECalenNotifyCalendarInfoCreated: - { - TRAP_IGNORE(HandleCalendarInfoCreatedL()); - } - break; - case ECalenNotifyCalendarInfoUpdated: - { - TRAP_IGNORE(HandleCalendarInfoUpdatedL()); - } - break; - case ECalenNotifyCalendarFileDeleted: - { - TRAP_IGNORE(HandleCalendarFileDeletedL()); - } - break; - default: - break; - } - - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CreateEntryViewL -// ----------------------------------------------------------------------------- -void CCalenGlobalData::CreateEntryViewL() - { - TRACE_ENTRY_POINT; - - HBufC* calendarFileName = KCalendarDatabaseFilePath().AllocLC(); - TInt index = iFileMappingArray.Find( - *calendarFileName, CCalenGlobalData::CalenInfoIdentifierL); - CleanupStack::PopAndDestroy(calendarFileName); - if(index != KErrNotFound) - { - iEntryView = iFileMappingArray[index]->GetEntryView(); - } - - if(!iEntryView) - { - User::LeaveIfNull(iEntryView); - } - - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CreateEntryViewL -// ----------------------------------------------------------------------------- -void CCalenGlobalData::CreateEntryViewL(CCalSession& session) - { - TRACE_ENTRY_POINT; - iNewEntryViewCreation = CCalEntryView::NewL( session, iCalCallBack ); - - if(iNewEntryViewCreation) - { - iNewEntryView = iNewEntryViewCreation; - } - - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CreateInstanceViewL -// ----------------------------------------------------------------------------- void CCalenGlobalData::CreateInstanceViewL() { TRACE_ENTRY_POINT; iInstanceViewCreation = CCalInstanceView::NewL( CalSessionL(), iCalCallBack ); - if(iInstanceViewCreation) - { - iInstanceView = iInstanceViewCreation; - } - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CreateEntryViewL -// ----------------------------------------------------------------------------- -void CCalenGlobalData::CreateInstanceViewL(const RArray& aCollectionIds) - { - TRACE_ENTRY_POINT; - - RPointerArray sessionArray; - - for(TInt i = 0; i < aCollectionIds.Count() ; i++) - { - TInt index = iHashDbidIndexMap.FindL(aCollectionIds[i]); - if(index != KErrNotFound) - { - CCalSession* sessionPtr = iFileMappingArray[index]->GetSessionPtr(); - sessionArray.AppendL(sessionPtr); - } - } - - if(sessionArray.Count()) - { - iNewInstanceViewCreation = CCalInstanceView::NewL( sessionArray, iCalCallBack ); - if(iNewInstanceViewCreation) - { - iNewInstanceView = iNewInstanceViewCreation; - } - } - - sessionArray.Reset(); TRACE_EXIT_POINT; } @@ -1184,39 +387,8 @@ if ( !aSuccess ) { // Something has gone wrong - if (iEntryViewCreation) - { - delete iEntryViewCreation; - iEntryViewCreation = NULL; - } - if (iInstanceViewCreation) - { - delete iInstanceViewCreation; - iInstanceViewCreation = NULL; - } - - if (iNewEntryViewCreation) - { - delete iNewEntryViewCreation; - iNewEntryViewCreation = NULL; - - HBufC* fileName = iContext->GetCalendarFileNameL().AllocLC(); - TInt index = iFileMappingArray.Find(*fileName, - CCalenGlobalData::CalenInfoIdentifierL); - CleanupStack::PopAndDestroy(fileName); - - if (index != KErrNotFound) - { - iFileMappingArray[index]->SetEntryView(NULL); - } - } - - if (iNewInstanceViewCreation) - { - delete iNewInstanceViewCreation; - iNewInstanceViewCreation = NULL; - } - + delete iEntryViewCreation; + delete iInstanceViewCreation; } else { @@ -1228,22 +400,11 @@ { iInstanceView = iInstanceViewCreation; } - - if ( iNewEntryViewCreation ) - { - iNewEntryView = iNewEntryViewCreation; - } - else if ( iNewInstanceViewCreation ) - { - iNewInstanceView = iNewInstanceViewCreation; - } } iEntryViewCreation = NULL; iInstanceViewCreation = NULL; - iNewEntryViewCreation = NULL; - iNewInstanceViewCreation = NULL; - + if ( iQueued ) { (this->*iQueued)(); @@ -1254,617 +415,44 @@ } // ----------------------------------------------------------------------------- -// CCalenGlobalData::CreateNewSessionL -// Create a Calendar session if necessary and return a reference +// CCalenGlobalData::RegisterEntryViewObserver +// Add observer into view observers entry observer list. // (other items were commented in a header). // ----------------------------------------------------------------------------- -CCalSession& CCalenGlobalData::CreateNewSessionL( const TDesC& aCalendar ) +EXPORT_C TBool CCalenGlobalData::EntryViewExists() + { + TRACE_ENTRY_POINT; + TRACE_EXIT_POINT; + return ( iEntryView != NULL ); + } + + +// ----------------------------------------------------------------------------- +// CCalenGlobalData::Context +// Return a reference to the CCalenContext object +// (other items were commented in a header). +// ----------------------------------------------------------------------------- +EXPORT_C MCalenContext& CCalenGlobalData::Context() + { + TRACE_ENTRY_POINT; + TRACE_EXIT_POINT; + return *iContext; + } + +void CCalenGlobalData::HandleNotification(const TCalenNotification aNotification ) { TRACE_ENTRY_POINT; - if(!iNewCalSession) + if ( aNotification == ECalenNotifyEntryInstanceViewCreated ) { - iNewCalSession = CCalSession::NewL(*iCalSession); - - TRAPD( err, iNewCalSession->OpenL(aCalendar)); - if ( err == KErrNotFound ) - { - iNewCalSession->CreateCalFileL(aCalendar); - iNewCalSession->OpenL(aCalendar); // not trapped anymore - } - else - { - User::LeaveIfError( err ); - } + ViewCreationCompleted( ETrue ); } - TRACE_EXIT_POINT; - return *iNewCalSession; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CalenInfoIdentifierL -// ----------------------------------------------------------------------------- -// -TBool CCalenGlobalData::CalenInfoIdentifierL( const HBufC* aName, - const CCalenFileMapping& aFileMapping) - { - TRACE_ENTRY_POINT; - TPtrC calendarFileName = aFileMapping.GetCalendarFileName(); - TRACE_EXIT_POINT; - return (!calendarFileName.CompareF(*aName)); - } + else if (aNotification == ECalenNotifyEntryInstanceViewCreationFailed ) + { + ViewCreationCompleted( EFalse ); + } -// ----------------------------------------------------------------------------- -// CCalenGlobalData::AddCalendarL -// adds new calendar file and sets calendar info to it -// ----------------------------------------------------------------------------- -// -EXPORT_C void CCalenGlobalData::AddCalendarL(CCalCalendarInfo* aCalendarInfo) - { - TRACE_ENTRY_POINT; - CleanupStack::PushL(aCalendarInfo); - - CCalenFileMapping* fileMapping = CCalenFileMapping::NewL(); - CleanupStack::PushL(fileMapping); - - HBufC* calendarFileName = CCalenMultiCalUtil::GetNextAvailableCalFileL(); - CleanupStack::PushL(calendarFileName); - fileMapping->SetCalendarFileNameL(calendarFileName->Des()); - CleanupStack::PopAndDestroy(calendarFileName); - if(iCalSession) - { - iNewCalSession = NULL; - iNewEntryView = NULL; - iNewEntryViewCreation = NULL; - TPtrC calFileName = fileMapping->GetCalendarFileName(); - CCalSession& tempSession = CreateNewSessionL( calFileName, - *aCalendarInfo ); - fileMapping->SetSessionPtr(&tempSession); - fileMapping->SetCollectionId(tempSession.CollectionIdL()); - - if(!iCalendarForcedExit) - { - CreateEntryViewL(tempSession); - } - fileMapping->SetEntryView( iNewEntryView ); - CCalenDbChangeNotifier* dbChangeNotifier = CCalenDbChangeNotifier::NewL( tempSession ); - dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier); - fileMapping->SetDBChangeNotifier(dbChangeNotifier); - iCalendarInfoList.Append(tempSession.CalendarInfoL()); - } - - CleanupStack::Pop(fileMapping); - iFileMappingArray.Append(fileMapping); - - iHashDbidIndexMap.Close(); - for(TInt index = 0; index < iFileMappingArray.Count(); index++) - { - iHashDbidIndexMap.InsertL( iFileMappingArray[index]->GetCollectionId(), - index); - } - - CleanupStack::PopAndDestroy(aCalendarInfo); - aCalendarInfo = NULL; - - TRACE_EXIT_POINT - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::RemoveDeadCalendarsL -// removes dead calendar files from the file system -// ----------------------------------------------------------------------------- -// -EXPORT_C void CCalenGlobalData::RemoveDeadCalendarsL() - { - TRACE_ENTRY_POINT; - CCalCalendarIterator* calendarIterator = - CCalCalendarIterator::NewL(*iCalendarsSession); - CleanupStack::PushL(calendarIterator); - - for( CCalCalendarInfo* calendarInfo = calendarIterator->FirstL(); - calendarInfo!=NULL;calendarInfo = calendarIterator->NextL()) - { - CleanupStack::PushL(calendarInfo); - HBufC* filename = calendarInfo->FileNameL().AllocLC(); - TInt index = iFileMappingArray.Find( *filename, - CCalenGlobalData::CalenInfoIdentifierL); - if(KErrNotFound == index) - { - CCalSession* session = CCalSession::NewL(*iCalSession); - CleanupStack::PushL(session); - TRAP_IGNORE(session->DeleteCalFileL( *filename )); - CleanupStack::PopAndDestroy(session); - } - CleanupStack::PopAndDestroy(filename); - CleanupStack::PopAndDestroy(calendarInfo); - } - CleanupStack::PopAndDestroy(calendarIterator); TRACE_EXIT_POINT; } -// ----------------------------------------------------------------------------- -// CCalenGlobalData::RemoveCalendarL -// removes calendar file from the file system -// ----------------------------------------------------------------------------- -// -EXPORT_C void CCalenGlobalData::RemoveCalendarL(const TDesC& aCalendarFileName) - { - TRACE_ENTRY_POINT; - - HBufC* calendarFilename = aCalendarFileName.AllocLC(); - TInt index = iFileMappingArray.Find( *calendarFilename, - CCalenGlobalData::CalenInfoIdentifierL); - - if( KErrNotFound == index ) - { - CleanupStack::PopAndDestroy(calendarFilename); - // reconstruct the calendar list using the iterator - ConstructCalendarsListL(); - - TRACE_EXIT_POINT; - return; - } - - if( index >= 0 ) - { - CCalenFileMapping* filemap = iFileMappingArray.operator [](index); - CCalSession* session = filemap->GetSessionPtr(); - if(session) - { - TRAPD(err, session->DeleteCalFileL(aCalendarFileName)); - if( err == KErrInUse ) - { - //Calendar file is opened by other application. - //Mark the file as deleted. Try delete the file at later time. - // Get the CalFile - CCalCalendarInfo* caleninfo = session->CalendarInfoL(); - CleanupStack::PushL(caleninfo); - - // Mark the CalFile as Hidden - caleninfo->SetEnabled( EFalse ); - - - TBuf8 keyBuff; - - // Set the modification time as home time. - keyBuff.Zero(); - keyBuff.AppendNum(EModificationTime); - TTime modificationTime; - modificationTime.HomeTime(); - TPckgC pkgModificationTime(modificationTime); - caleninfo->SetPropertyL(keyBuff, pkgModificationTime); - - // Set the SyncStatus to False - keyBuff.Zero(); - keyBuff.AppendNum( ESyncStatus ); - TBool syncstatus( EFalse ); - TPckgC pckgSyncStatusValue( syncstatus ); - caleninfo->SetPropertyL( keyBuff, pckgSyncStatusValue ); - - // Mark the meta property as SoftDeleted - keyBuff.Zero(); - keyBuff.AppendNum(EMarkAsDelete); - TPckgC pkgSoftDelete( ETrue ); - caleninfo->SetPropertyL(keyBuff, pkgSoftDelete); - - session->SetCalendarInfoL( *caleninfo ); - CleanupStack::PopAndDestroy(caleninfo); - } - - TRAP_IGNORE(DeleteCalendarMissedAlarmsL(aCalendarFileName)); - - TInt infoListIndex = iCalendarInfoList.Find(*calendarFilename, - CCalenGlobalData::CalenCalendarInfoIdentiferL); - - CCalCalendarInfo* calendarInfo = iCalendarInfoList[infoListIndex]; - iCalendarInfoList.Remove(infoListIndex); - delete calendarInfo; - calendarInfo = NULL; - - iHashDbidIndexMap.Close(); - - iFileMappingArray.Remove(index); - delete filemap; - for(TInt index = 0; index < iFileMappingArray.Count(); index++) - { - iHashDbidIndexMap.InsertL(iFileMappingArray[index]->GetCollectionId(), index); - } - } - } - - - CleanupStack::PopAndDestroy(calendarFilename); - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::UpdateCalendarL -// updates calendar info for the calendar file -// ----------------------------------------------------------------------------- -// -EXPORT_C void CCalenGlobalData::UpdateCalendarL(CCalCalendarInfo* aCalendarInfo) - { - TRACE_ENTRY_POINT; - - HBufC* calendar = aCalendarInfo->FileNameL().AllocLC(); - TInt index = iFileMappingArray.Find( *calendar, - CCalenGlobalData::CalenInfoIdentifierL); - - if(index != KErrNotFound) - { - CCalSession* session = iFileMappingArray[index]->GetSessionPtr(); - if(session) - { - session->SetCalendarInfoL(*aCalendarInfo); - } - } - CleanupStack::PopAndDestroy(calendar); - - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::GetCalFileNameForCollectionId -// Get Calendar file name for the given collectionid -// ----------------------------------------------------------------------------- -// -EXPORT_C const TDesC& CCalenGlobalData::GetCalFileNameForCollectionId( - const TCalCollectionId aColId) - { - TRACE_ENTRY_POINT; - - TInt index = iFileMappingArray.Find( aColId, - CCalenGlobalData::CalenFileMapIdentifierForColId ); - - if(index != KErrNotFound) - { - TRACE_EXIT_POINT; - return iFileMappingArray[index]->GetCalendarFileName(); - } - else - { - TRACE_EXIT_POINT; - return KNullDesC; - } - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::GetAllCalendarInfoL -// Get all available calendar info -// ----------------------------------------------------------------------------- -// -EXPORT_C void CCalenGlobalData::GetAllCalendarInfoL( - RPointerArray& aCalendarInfoList ) - { - TRACE_ENTRY_POINT; - CleanupClosePushL(aCalendarInfoList); - RFs fsSession; - CleanupClosePushL( fsSession ); - RResourceFile resourceFile; - CleanupClosePushL( resourceFile ); - User::LeaveIfError( fsSession.Connect() ); - TFileName resourceFileName( KMissedAlarmResourceFile ); - - BaflUtils::NearestLanguageFile( fsSession, resourceFileName ); - resourceFile.OpenL(fsSession, resourceFileName ); - resourceFile.ConfirmSignatureL( 0 ); - for(TInt index=0;index < iCalendarInfoList.Count();index++) - { - - TPtrC calendarNamePtr = iCalendarInfoList[index]->NameL(); - if(calendarNamePtr.Compare(KPersonal) == 0) - { - HBufC8* personalBuffer = resourceFile.AllocReadLC( R_CALE_DB_PERSONAL ); - const TPtrC16 ptrPBuffer(( TText16*) personalBuffer->Ptr(), - ( personalBuffer->Length()+1 )>>1 ); - HBufC *personalCalendar = ptrPBuffer.AllocL(); - CleanupStack::PushL(personalCalendar); - iCalendarInfoList[index]->SetNameL(*personalCalendar); - CleanupStack::PopAndDestroy( 2,personalBuffer ); - } - - - aCalendarInfoList.AppendL(iCalendarInfoList[index]); - - } - CleanupStack::PopAndDestroy(2); - CleanupStack::Pop(&aCalendarInfoList); - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CreateNewSessionL -// Create new session with metadata -// ----------------------------------------------------------------------------- -// -CCalSession& CCalenGlobalData::CreateNewSessionL( const TDesC& aCalendar, - const CCalCalendarInfo& aCalendarInfo ) - { - TRACE_ENTRY_POINT; - - if(!iNewCalSession) - { - iNewCalSession = CCalSession::NewL(*iCalSession); - - TRAPD( err, iNewCalSession->OpenL(aCalendar)); - if ( err == KErrNotFound ) - { - iNewCalSession->CreateCalFileL( aCalendar, aCalendarInfo ); - iNewCalSession->OpenL(aCalendar); // not trapped anymore - } - else - { - User::LeaveIfError( err ); - } - } - TRACE_EXIT_POINT; - return *iNewCalSession; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CalenFileMapIdentifierForColId -// Search for filemap index based on collection id -// ----------------------------------------------------------------------------- -// -TBool CCalenGlobalData::CalenFileMapIdentifierForColId(const TCalCollectionId* aId, - const CCalenFileMapping& aFileMapping ) - { - TRACE_ENTRY_POINT; - TRACE_EXIT_POINT; - return (*aId == (aFileMapping.GetCollectionId())); - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::CalenCalendarInfoIdentiferL -// Construct calendar list from the calendar iterator -// ----------------------------------------------------------------------------- -// -TBool CCalenGlobalData::CalenCalendarInfoIdentiferL(const HBufC* aFileName, - const CCalCalendarInfo& aCalendarInfo) - { - TRACE_ENTRY_POINT - TPtrC calendarFileName = aCalendarInfo.FileNameL(); - TRACE_EXIT_POINT - return (!calendarFileName.CompareF(*aFileName) ); - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::ConstructCalendarsListL -// Construct calendar list from the calendar iterator -// ----------------------------------------------------------------------------- -// -void CCalenGlobalData::ConstructCalendarsListL() - { - TRACE_ENTRY_POINT; - - iCalendarInfoList.ResetAndDestroy(); - CCalCalendarIterator* calendarIterator = - CCalCalendarIterator::NewL(*iCalendarsSession); - CleanupStack::PushL(calendarIterator); - - for( CCalCalendarInfo* calendarInfo = calendarIterator->FirstL(); - calendarInfo!=NULL;calendarInfo = calendarIterator->NextL()) - { - TBuf8 keyBuff; - // Mark the meta property as SoftDeleted - keyBuff.Zero(); - keyBuff.AppendNum(EMarkAsDelete); - TBool softDelete = EFalse; - TPckgC pkgSoftDelete( softDelete ); - TRAPD(err,pkgSoftDelete.Set(calendarInfo->PropertyValueL(keyBuff))); - if( KErrNone == err ) - { - softDelete = pkgSoftDelete(); - } - if( softDelete && - calendarInfo->FileNameL().CompareF(CalSessionL().DefaultFileNameL()) ) - { - // delete caleninfo except for default calendar. - delete calendarInfo; - } - else - { - iCalendarInfoList.Append(calendarInfo); - } - } - CleanupStack::PopAndDestroy(calendarIterator); - - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::UpdateCalendarListL -// Update calendar list whenever CalendarInfoUpdated notification is received. -// ----------------------------------------------------------------------------- -// -void CCalenGlobalData::UpdateCalendarListL() - { - //Getting calendar name updated from calennotifier infochangednotification - HBufC* calendarNameUpdated = iContext->GetCalendarFileNameL().AllocLC(); - TInt index = iFileMappingArray.Find( *calendarNameUpdated, - CCalenGlobalData::CalenInfoIdentifierL); - - if(index != KErrNotFound) - { - CCalSession* session = iFileMappingArray[index]->GetSessionPtr(); - for(TInt i=0; iFileNameL().CompareF(calendarNameUpdated->Des())) - { - iCalendarInfoList[i] = session->CalendarInfoL(); - } - } - } - CleanupStack::PopAndDestroy(calendarNameUpdated); - } -// ----------------------------------------------------------------------------- -// CCalenGlobalData::GetDefaultCalendarInfoL -// Get default calendar info -// ----------------------------------------------------------------------------- -// -CCalCalendarInfo* CCalenGlobalData::GetDefaultCalendarInfoL() - { - TRACE_ENTRY_POINT; - - CCalCalendarInfo* defaultCalendarInfo = CCalCalendarInfo::NewL(); - CleanupStack::PushL(defaultCalendarInfo); - defaultCalendarInfo->SetColor(KCalenBlue.Value()); - defaultCalendarInfo->SetEnabled(ETrue); - defaultCalendarInfo->SetNameL(KPhoneCalendar); - CleanupStack::Pop(defaultCalendarInfo); - - TRACE_EXIT_POINT; - return defaultCalendarInfo; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::HandleCalendarInfoCreatedL -// Handles the notification ECalenNotifyCalendarInfoCreated -// ----------------------------------------------------------------------------- -// -void CCalenGlobalData::HandleCalendarInfoCreatedL() - { - TRACE_ENTRY_POINT; - // get the filename from the context - TDesC& fileName = iContext->GetCalendarFileNameL(); - - // check for the calendar file already exists in filemap list - HBufC* calendar = fileName.AllocLC(); - TInt index = iFileMappingArray.Find(*calendar, - CCalenGlobalData::CalenInfoIdentifierL); - CleanupStack::PopAndDestroy(calendar); - - // if not exists,add to filemapper list - if (KErrNotFound == index) - { - CCalenFileMapping* fileMapper = CCalenFileMapping::NewL(); - CleanupStack::PushL(fileMapper); - fileMapper->SetCalendarFileNameL(fileName); - - iNewEntryView = NULL; - iNewEntryViewCreation = NULL; - CCalSession* newSession = NULL; - if(iCalSession) - { - // create the new session using default session - newSession = CCalSession::NewL(*iCalSession); - CleanupStack::PushL(newSession); - TRAPD(err,newSession->OpenL(fileName)); - User::LeaveIfError( err ); - CleanupStack::Pop(newSession); - // set filemapper data - fileMapper->SetSessionPtr(newSession); - fileMapper->SetCollectionId(newSession->CollectionIdL()); - - if(!iCalendarForcedExit) - { - CreateEntryViewL(*newSession); - } - fileMapper->SetEntryView( iNewEntryView ); - - iCalendarInfoList.AppendL(newSession->CalendarInfoL()); - CCalenDbChangeNotifier* dbChangeNotifier = CCalenDbChangeNotifier::NewL( *newSession ); - dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier); - fileMapper->SetDBChangeNotifier(dbChangeNotifier); - } - else - { - // create the first session - iCalSession = CCalSession::NewL(); - TRAPD(err,iCalSession->OpenL(fileName)); - User::LeaveIfError(err); - - // set filemapper data - fileMapper->SetSessionPtr(iCalSession); - fileMapper->SetCollectionId(iCalSession->CollectionIdL()); - - if(!iCalendarForcedExit) - { - CreateEntryViewL(*iCalSession); - } - - fileMapper->SetEntryView(iNewEntryView); - CCalenDbChangeNotifier* dbChangeNotifier = CCalenDbChangeNotifier::NewL( *iCalSession ); - fileMapper->SetDBChangeNotifier(dbChangeNotifier); - dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier); - iGlobalDataOwnsEntryView = EFalse; - iGlobalDataOwnsCalSession = EFalse; - iCalendarInfoList.AppendL(iCalSession->CalendarInfoL()); - } - // append to filemapper list - iFileMappingArray.Append(fileMapper); - CleanupStack::Pop(fileMapper); - - iHashDbidIndexMap.Close(); - for(TInt index = 0; index < iFileMappingArray.Count(); index++) - { - iHashDbidIndexMap.InsertL( - iFileMappingArray[index]->GetCollectionId(), index); - } - } - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::HandleCalendarInfoUpdatedL -// Handles the notification ECalenNotifyCalendarInfoUpdated -// ----------------------------------------------------------------------------- -// -void CCalenGlobalData::HandleCalendarInfoUpdatedL() - { - TRACE_ENTRY_POINT; - - //Update Calendar list. - UpdateCalendarListL(); - - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::HandleCalendarFileDeletedL -// Handles the notification ECalenNotifyCalendarFileDeleted -// ----------------------------------------------------------------------------- -// -void CCalenGlobalData::HandleCalendarFileDeletedL() - { - TRACE_ENTRY_POINT; - - // get the filename from the context - TDesC& fileName = iContext->GetCalendarFileNameL(); - - // delete the calendar file - RemoveCalendarL(fileName); - - TRACE_EXIT_POINT; - } - -// ----------------------------------------------------------------------------- -// CCalenGlobalData::DeleteCalendarMissedAlarmsL -// Delete all missed alarms for deleted calendar -// ----------------------------------------------------------------------------- -// -void CCalenGlobalData::DeleteCalendarMissedAlarmsL(const TDesC& aCalendarFilename) - { - TRACE_ENTRY_POINT - //Clear all missed alarms related to this calendar - CMissedAlarmStore* missedAlarmStore = CMissedAlarmStore::NewLC(); - RPointerArray missedAlarms; - CleanupResetAndDestroyPushL(missedAlarms); - - missedAlarmStore->GetL(missedAlarms); - - for (TInt idx = 0; idx < missedAlarms.Count(); idx++) - { - CMissedAlarm* missedAlarm = missedAlarms[idx]; - if (!missedAlarm->iCalFileName.CompareF(aCalendarFilename)) - { - missedAlarmStore->RemoveL(*missedAlarm); - } - } - - CleanupStack::PopAndDestroy(&missedAlarms); - CleanupStack::PopAndDestroy(missedAlarmStore); - TRACE_EXIT_POINT - } - -// End of file +// Enf of file