calendarui/controller/src/calennotifier.cpp
branchRCL_3
changeset 30 bd7edf625bdd
parent 29 12af337248b1
child 31 97232defd20e
--- a/calendarui/controller/src/calennotifier.cpp	Tue Aug 31 15:13:43 2010 +0300
+++ b/calendarui/controller/src/calennotifier.cpp	Wed Sep 01 12:32:31 2010 +0100
@@ -16,46 +16,61 @@
 */
 
 
-//system includes
+
+#include <aknappui.h>                 // iavkonappui macro
+#include <bacntf.h>                   // cenvironmentchangenotifier
+#include <coemain.h>                  // eactiveprioritylogona
+#include <centralrepository.h>        // crepository
+#include <ErrorUI.h>                  // cerrorui
+#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS // new 
+#include <asshdalarm.h>
+#else // new
+#include <asshdalarm.h>
+#include <ASShdAlarmCal.h>
+#endif // new
 #include <e32property.h>
-#include <bacntf.h>                   // CEnvironmentChangeNotifier
-#include <coemain.h>                  // EActivePriorityLogonA
+#include <calfilechangenotification.h>
+#include <calenecomwatcher.h>
+#include <calenglobaldata.h>
+#include <calenconstants.h>
+#include <calencontext.h>
+#include <calsession.h>
+#include <calcalendarinfo.h>
+#include <calenmulticaluids.hrh>
 
-//user includes
 #include "calendarui_debug.h"
-#include "calennotifier.h"            // CalenNotifier
+#include "calennotifier.h"            // CCalenNotifier
+#include "CalendarPrivateCRKeys.h"    // Central Repository keys
+#include "calensetting.h"
 #include "calenstatemachine.h"
-#include "OstTraceDefinitions.h"
-#ifdef OST_TRACE_COMPILER_IN_USE
-#include "calennotifierTraces.h"
-#endif
+#include "calencontroller.h"
 
 const TInt KHashLength = 64;
+const TInt KBuffLength = 24;
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::CalenNotifier
+// CCalenNotifier::CCalenNotifier
 // C++ default constructor.
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-CalenNotifier::CalenNotifier( CCalenStateMachine& aStateMachine )
-    : iStateMachine( aStateMachine )
+CCalenNotifier::CCalenNotifier( CCalenController& aController )
+    : iController( aController )
     {
-    OstTraceFunctionEntry0( CALENNOTIFIER_CALENNOTIFIER_ENTRY );
-    
-    OstTraceFunctionExit0( CALENNOTIFIER_CALENNOTIFIER_EXIT );
+    TRACE_ENTRY_POINT;
+    TRACE_EXIT_POINT;
     }
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::~CalenNotifier
+// CCalenNotifier::~CCalenNotifier
 // Destructor.
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-CalenNotifier::~CalenNotifier()
+CCalenNotifier::~CCalenNotifier()
     {
-    OstTraceFunctionEntry0( DUP1_CALENNOTIFIER_CALENNOTIFIER_ENTRY );
-    
+    TRACE_ENTRY_POINT;
+
     // Reset the handler array.
     // Before we reset , close hashset for each handler
     for(TInt i = 0 ; i < iHandlers.Count() ; i++)
@@ -63,8 +78,36 @@
         iHandlers[i].iHashSet.Close();
         }
     
-    iHandlers.Reset();
-    iBroadcastQueue.Reset();
+    iHandlers.Close();
+    
+    iBroadcastQueue.Close();
+    
+    
+    if( iFilnameDeleted )
+        {
+        delete iFilnameDeleted;
+        iFilnameDeleted = NULL;
+        }
+    
+    // Stop ECom change notifications
+    if( iEComWatcher )
+        {
+        delete iEComWatcher;
+        iEComWatcher = NULL;
+        }
+
+    // Stop settings change notifications
+    if( iCenRepChangeNotifier )
+        {
+        delete iCenRepChangeNotifier;
+        iCenRepChangeNotifier = NULL;
+        }
+    
+    if( iRepository )
+        {
+        delete iRepository;
+        iRepository = NULL;
+        }
     
     // Stop environment change notifications
     if( iEnvChangeNotifier )
@@ -72,42 +115,74 @@
         iEnvChangeNotifier->Cancel();
         delete iEnvChangeNotifier;
         }
-
-    OstTraceFunctionExit0( DUP1_CALENNOTIFIER_CALENNOTIFIER_EXIT );
-    }
+    
+    if( iSetting )
+        {
+        iSetting->Release();
+        }
+    
+    // Release the global data
+    if( iGlobalData )
+        {
+        // stop listening for calendar file change notifications
+        TRAP_IGNORE(iGlobalData->CalSessionL().StopFileChangeNotification());
+        iGlobalData->Release();
+        }
+	TRACE_EXIT_POINT;
+	}
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::ConstructL
+// CCalenNotifier::ConstructL
 // Symbian 2nd phase of construction.
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-void CalenNotifier::ConstructL()
+void CCalenNotifier::ConstructL()
     {
-    OstTraceFunctionEntry0( CALENNOTIFIER_CONSTRUCTL_ENTRY );
+    TRACE_ENTRY_POINT;
+    
+    // Get the global data
+    iGlobalData = CCalenGlobalData::InstanceL();
+    
+    // Get the setting singleton. We update it when settings change.
+    iSetting = CCalenSetting::InstanceL();
     
     // Register for system environment changes
     TCallBack envCallback( EnvChangeCallbackL, this );
     iEnvChangeNotifier =
         CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, envCallback );
     iEnvChangeNotifier->Start();
+    
+    // Register for changes to Calendar settings from the Central Repository
+    iRepository = CRepository::NewL( KCRUidCalendar );
+    iCenRepChangeNotifier = CCenRepNotifyHandler::NewL( *this, *iRepository );
+    iCenRepChangeNotifier->StartListeningL();
+    
+    // Register for changes to the ECom registry
+    iEComWatcher = CCalenEComWatcher::NewL( *this );
+     
+	iIgnoreFirstLocaleChange = ETrue;
 
-    iIgnoreFirstLocaleChange = ETrue;
- 
-    OstTraceFunctionExit0( CALENNOTIFIER_CONSTRUCTL_EXIT );
-    }
+	// start listening for calendar file change notifications
+	iGlobalData->CalSessionL().StartFileChangeNotificationL(*this);
+	
+	
+	iFilnameDeleted = NULL;
+
+	TRACE_EXIT_POINT;
+	}
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::RegisterForNotificationsL
+// CCalenNotifier::RegisterForNotificationsL
 // Adds the passed handler to the handler array.
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-void CalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, 
+void CCalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, 
                                                 TCalenNotification aNotification)
     {
-    OstTraceFunctionEntry0( CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_ENTRY );
-    
+    TRACE_ENTRY_POINT;
+
     TNotificationHandler handler;
     handler.iHandler = aHandler;
     
@@ -134,19 +209,19 @@
     
     iHandlers.Append( handler );
     
-    OstTraceFunctionExit0( CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_EXIT );
+    TRACE_EXIT_POINT;
     }
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::RegisterForNotificationsL
+// CCalenNotifier::RegisterForNotificationsL
 // Adds the passed handler to the handler array.
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-void CalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, 
+void CCalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, 
                                                            RArray<TCalenNotification>& aNotifications  )
     {
-    OstTraceFunctionEntry0( DUP1_CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_ENTRY );
+    TRACE_ENTRY_POINT;
 
     TNotificationHandler handler;
     handler.iHandler = aHandler;
@@ -177,19 +252,19 @@
     
     iHandlers.Append( handler );
 
-    OstTraceFunctionExit0( DUP1_CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_EXIT );
+    TRACE_EXIT_POINT;
     }
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::CancelNotifications
+// CCalenNotifier::CancelNotifications
 // Removes the passed handler from the handler array.
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-void CalenNotifier::CancelNotifications( MCalenNotificationHandler* aHandler )
+void CCalenNotifier::CancelNotifications( MCalenNotificationHandler* aHandler )
     {
-    OstTraceFunctionEntry0( CALENNOTIFIER_CANCELNOTIFICATIONS_ENTRY );
-    
+    TRACE_ENTRY_POINT;
+
     for( TInt x = 0; x < iHandlers.Count(); ++x )
         {
         if( iHandlers[x].iHandler == aHandler )
@@ -200,27 +275,11 @@
             iHandlers[x].iHashSet.Close();
             iHandlers[x].iHandler = NULL;
             TRACE_EXIT_POINT;
-            OstTraceFunctionExit0( CALENNOTIFIER_CANCELNOTIFICATIONS_EXIT );
             return;
             }
         }
 
-    OstTraceFunctionExit0( DUP1_CALENNOTIFIER_CANCELNOTIFICATIONS_EXIT );
-    }
-
-// ----------------------------------------------------------------------------
-// CalenNotifier::ContextChanged
-// From MCalenContextChangeObserver. Called when the context changes.
-// (other items were commented in a header).
-// ----------------------------------------------------------------------------
-//
-void CalenNotifier::ContextChanged()
-    {
-    OstTraceFunctionEntry0( CALENNOTIFIER_CONTEXTCHANGED_ENTRY );
-    
-    BroadcastNotification( ECalenNotifyContextChanged );
-
-    OstTraceFunctionExit0( CALENNOTIFIER_CONTEXTCHANGED_EXIT );
+    TRACE_EXIT_POINT;
     }
 
 // ----------------------------------------------------------------------------
@@ -232,16 +291,32 @@
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-TInt CalenNotifier::EnvChangeCallbackL( TAny* aThisPtr )
+TInt CCalenNotifier::EnvChangeCallbackL( TAny* aThisPtr )
     {
-    OstTraceFunctionEntry0( CALENNOTIFIER_ENVCHANGECALLBACKL_ENTRY );
-    
-    OstTraceFunctionExit0( CALENNOTIFIER_ENVCHANGECALLBACKL_EXIT );
-    
+    TRACE_ENTRY_POINT;
+
+  /*  CCalenNotifier* thisPtr = static_cast<CCalenNotifier*>( aThisPtr );
+
+    if( thisPtr->iEnvChangeNotifier->Change() & EChangesMidnightCrossover )
+        {
+        thisPtr->BroadcastNotification( ECalenNotifySystemTimeChanged );
+        }
+
+    if( thisPtr->iEnvChangeNotifier->Change() & EChangesLocale )
+        {
+        thisPtr->BroadcastNotification( ECalenNotifySystemLocaleChanged );
+        }
+
+    if( thisPtr->iEnvChangeNotifier->Change() & EChangesSystemTime ) 
+        {
+        thisPtr->BroadcastNotification( ECalenNotifySystemTimeChanged );
+        }*/
+        
+    TRACE_EXIT_POINT;
     // Return value for functions used as TCallBack objects should be EFalse
     // unless the function is intended to be called again from a timer.
    // return EFalse;
-    return static_cast<CalenNotifier*>(aThisPtr)->DoEnvChange();
+    return static_cast<CCalenNotifier*>(aThisPtr)->DoEnvChange();
     }
 
 // ----------------------------------------------------------------------------
@@ -249,85 +324,232 @@
 //  EnvChangeCallbackL calls this function
 // ----------------------------------------------------------------------------
 //
-TInt CalenNotifier::DoEnvChange()
-    {
-    OstTraceFunctionEntry0( CALENNOTIFIER_DOENVCHANGE_ENTRY );
-    
-    if( ((iEnvChangeNotifier->Change() & EChangesMidnightCrossover)
-        || (iEnvChangeNotifier->Change() & EChangesSystemTime))
-        && !iIgnoreFirstLocaleChange )
+TInt CCalenNotifier::DoEnvChange()
+	{
+	TRACE_ENTRY_POINT;
+	
+	if( ((iEnvChangeNotifier->Change() & EChangesMidnightCrossover)
+		|| (iEnvChangeNotifier->Change() & EChangesSystemTime))
+		&& !iIgnoreFirstLocaleChange )
         {
         BroadcastNotification( ECalenNotifySystemTimeChanged );
         }
-    else if( (iEnvChangeNotifier->Change() & EChangesLocale)
-            && !iIgnoreFirstLocaleChange )  
+	else if( (iEnvChangeNotifier->Change() & EChangesLocale)
+			&& !iIgnoreFirstLocaleChange )	
         {
         BroadcastNotification( ECalenNotifySystemLocaleChanged );
         }
      else
-        {
-        iIgnoreFirstLocaleChange = EFalse;
-        }   
+     	{
+     	iIgnoreFirstLocaleChange = EFalse;
+     	}   
+
+    TRACE_EXIT_POINT; 
+    return EFalse ;
+	}
+// ----------------------------------------------------------------------------
+// CCalenNotifier::HandleNotifyGeneric
+// From MCenRepNotifyHandlerCallback
+// Generic notification that one of our central repository keys has changed
+// If any keys change we broadcast a settings changed notification
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::HandleNotifyGeneric( TUint32 /*aId*/ )
+    {
+    TRACE_ENTRY_POINT;
+
+    PIM_TRAPD_HANDLE( iSetting->LoadL() );
+    BroadcastNotification( ECalenNotifySettingsChanged );
+
+    // Use another trap to make sure we start listening again, regardless
+    // of whether the previous function left or not.
+    PIM_TRAPD_HANDLE( iCenRepChangeNotifier->StartListeningL() );
+
+    TRACE_EXIT_POINT;
+    }
 
-    OstTraceFunctionExit0( CALENNOTIFIER_DOENVCHANGE_EXIT );
-    return EFalse ;
+// ----------------------------------------------------------------------------
+// CCalenNotifier::HandleNotifyError
+// Cenrep watcher error callback
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::HandleNotifyError( TUint32 /*aId*/,
+                                                    TInt /*aError*/,
+                                                    CCenRepNotifyHandler* /*aHandler*/ )
+    {
+    TRACE_ENTRY_POINT;
+
+    PIM_TRAPD_HANDLE( iCenRepChangeNotifier->StartListeningL() );
+
+    TRACE_EXIT_POINT;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::HandleDBChangeL
+// From MCalenDBChangeObserver
+// Notification that an external CCalSession has modified the database we are
+// using in some way.  This notification is limited to a maximum of one per
+// second.  This is to avoid multiple notifications when performing large sync
+// operations
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::HandleDBChangeL()
+    {
+    TRACE_ENTRY_POINT;
+
+    BroadcastNotification( ECalenNotifyExternalDatabaseChanged );
+
+    TRACE_EXIT_POINT;
     }
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::BroadcastNotification
+// CCalenNotifier::ContextChanged
+// From MCalenContextChangeObserver. Called when the context changes.
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::ContextChanged()
+    {
+    TRACE_ENTRY_POINT;
+
+    BroadcastNotification( ECalenNotifyContextChanged );
+
+    TRACE_EXIT_POINT;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::EComChanged
+// From MCalenEComChangeObserver. Called when the ECom registry changes 
+// (install/uninstall).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::EComChanged()
+    {
+    TRACE_ENTRY_POINT;
+    
+    if(!iController.IsFasterAppFlagEnabled())
+        {
+        BroadcastNotification( ECalenNotifyEComRegistryChanged );
+        }
+    
+    TRACE_EXIT_POINT;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::DeferSettingsNotifications
+// After calling this function, any settings changed notifications
+// will not be broadcast until after ResumeSettingsNotifications
+// has been called.
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::DeferSettingsNotifications()
+    {
+    TRACE_ENTRY_POINT;
+
+    iIsSettingsBroadcastDeferred = ETrue;
+
+    TRACE_EXIT_POINT;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::ResumeSettingsNotifications
+// Resumes settings notifications after they have been paused
+// with DeferSettingsNotifications.
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::ResumeSettingsNotifications()
+    {
+    TRACE_ENTRY_POINT;
+
+    iIsSettingsBroadcastDeferred = EFalse;
+
+    if( iSettingsNeedsBroadcast )
+        {
+        iSettingsNeedsBroadcast = EFalse;
+        BroadcastNotification( ECalenNotifySettingsChanged );
+        }
+
+    if( iLocaleNeedsBroadcast )
+        {
+        iLocaleNeedsBroadcast = EFalse;
+        BroadcastNotification( ECalenNotifySystemLocaleChanged );
+        }
+
+    TRACE_EXIT_POINT;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::BroadcastNotification
 // Issues a notification to all registered handlers
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-void CalenNotifier::BroadcastNotification( TCalenNotification aNotification )
+void CCalenNotifier::BroadcastNotification( TCalenNotification aNotification )
     {
-    OstTraceFunctionEntry0( CALENNOTIFIER_BROADCASTNOTIFICATION_ENTRY );
-    
+    TRACE_ENTRY_POINT;
+
     // Someone has told us to broadcast, or one of our notifiers completed.
     // We run it past the state machine and that may or may not call the
     // function to really do the broadcast.
-    iStateMachine.HandleNotification( aNotification );
+    iController.StateMachine().HandleNotification( aNotification );
     
-    OstTraceFunctionExit0( CALENNOTIFIER_BROADCASTNOTIFICATION_EXIT );
+    TRACE_EXIT_POINT;
     }
     
 // ----------------------------------------------------------------------------
-// CalenNotifier::BroadcastApprovedNotification
+// CCalenNotifier::BroadcastApprovedNotification
 // Issues a notification to all registered handlers
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-void CalenNotifier::BroadcastApprovedNotification( TCalenNotification aNotification )
+void CCalenNotifier::BroadcastApprovedNotification( TCalenNotification aNotification )
     {
-    OstTraceFunctionEntry0( CALENNOTIFIER_BROADCASTAPPROVEDNOTIFICATION_ENTRY );
-    
-    iBroadcastQueue.Append( aNotification );
-
-    if( !iBroadcastActive )
+    TRACE_ENTRY_POINT;
+    /*if ( aNotification == ECalenNotifySettingsChanged
+            &&  iIsSettingsBroadcastDeferred )
+        {
+        iSettingsNeedsBroadcast = ETrue;
+        }
+    else if ( aNotification == ECalenNotifySystemLocaleChanged 
+                && iIsSettingsBroadcastDeferred)
+        {
+        iLocaleNeedsBroadcast = ETrue;
+        }
+    else*/
         {
-        iBroadcastActive = ETrue;
-        while( iBroadcastQueue.Count() )
+        iBroadcastQueue.Append( aNotification );
+
+        if( !iBroadcastActive )
             {
-            TCalenNotification notification = iBroadcastQueue[0];
-            DoBroadcast( notification );
-            iBroadcastQueue.Remove( 0 );
+            iBroadcastActive = ETrue;
+            while( iBroadcastQueue.Count() )
+                {
+                TCalenNotification notification = iBroadcastQueue[0];
+                DoBroadcast( notification );
+                iBroadcastQueue.Remove( 0 );
+                }
+            iBroadcastActive = EFalse;
             }
-        iBroadcastActive = EFalse;
         }
-    
-    OstTraceFunctionExit0( CALENNOTIFIER_BROADCASTAPPROVEDNOTIFICATION_EXIT );
+
+    TRACE_EXIT_POINT;
     }
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::DoBroadcast
+// CCalenNotifier::DoBroadcast
 // Issues a notification to all registered handlers
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-void CalenNotifier::DoBroadcast( TCalenNotification aNotification )
+void CCalenNotifier::DoBroadcast( TCalenNotification aNotification )
     {
-    OstTraceFunctionEntry0( CALENNOTIFIER_DOBROADCAST_ENTRY );
-    
+    TRACE_ENTRY_POINT;
+
     for( TInt x = 0; x < iHandlers.Count(); ++x )
         {
         TNotificationHandler handler = iHandlers[x];
@@ -346,19 +568,267 @@
             }
         }
 
-    OstTraceFunctionExit0( CALENNOTIFIER_DOBROADCAST_EXIT );
+    TRACE_EXIT_POINT;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::Progress
+// From MCalProgressCallback. Intentionally empty.
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::Progress( TInt /*aPercentageCompleted*/ )
+    {
+    TRACE_ENTRY_POINT;
+    TRACE_EXIT_POINT;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::NotifyProgress
+// From MCalProgressCallback. Don't notify us about progress updates.
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+TBool CCalenNotifier::NotifyProgress()
+    {
+    TRACE_ENTRY_POINT;
+	// No one interested in this notification.Removing to avoid notification clutter.
+    // BroadcastNotification( ECalenNotifyViewCreationStarted );
+
+    TRACE_EXIT_POINT;
+    return EFalse;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::Completed
+// From MCalProgressCallback.
+// Notifies observer of completion
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::Completed( TInt aStatus )
+    {
+    TRACE_ENTRY_POINT;
+
+    if( aStatus == KErrNone )
+        {
+        BroadcastNotification( ECalenNotifyEntryInstanceViewCreated );
+        }
+    else
+        {
+        BroadcastNotification( ECalenNotifyEntryInstanceViewCreationFailed );
+        // The view creation has failed, hence the calendar
+        // application needs to close gracefully
+        // 1) Display error note.
+        
+        CErrorUI* errorUi;
+        TRAPD(error,errorUi = CErrorUI::NewLC();
+       if(error!=KErrNone)
+       		{
+    		// do avoid warning
+    		}        
+        errorUi->ShowGlobalErrorNoteL( aStatus );        
+        CleanupStack::PopAndDestroy( errorUi );
+        );
+
+		// If Instance view creation is cancelled, no need to
+		// exit application.All other errors exit application.
+		if(aStatus != KErrCancel)
+			{
+	        // Exit application
+	        if (iAvkonAppUi)
+	            {
+	            iAvkonAppUi->Exit();
+	            }
+			}
+        }
+
+    TRACE_EXIT_POINT;
     }
 
 // ----------------------------------------------------------------------------
-// CalenNotifier::TNotificationHandler()
+// CCalenNotifier::SystemTimeChangedL
+// Check if the system time changed since Calendar was last launched
+// If the system time did change, we need to notify the user that alarms may
+// have been missed.
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+TInt CCalenNotifier::SystemTimeChangedL()
+    {
+    TRACE_ENTRY_POINT;
+    
+    TBool timeZoneChanged(EFalse);
+
+    TPckgBuf<TMissedAlarmPubSubData> alarmPkgVarBuf;
+    TInt errorVal = RProperty::Get( KAlarmServerPubSubCategory, 
+                            KMissingAlarmPubSubKey, alarmPkgVarBuf);
+
+    if(errorVal != KErrNone)
+        {
+        // Error in accessing the P&S key.
+        // Alarm server defines this key when first time SystemTime Changes after bootup.
+        // But Calendar may try to access this before it is defined by Alarm server.
+        // So better not leaving based on errorVal
+        return timeZoneChanged;
+        }
+    
+    // read the latest timechange from agenda Server Time Stamp
+    TTime timeOfChangeUtc = alarmPkgVarBuf().iTimeOfChangeUtc;
+    //timeOfChangeUtc.RoundUpToNextMinute();
+    iTimeOfChangeUtcReal = I64REAL(timeOfChangeUtc.Int64());
+
+    // read the persistent time stamp from CalendarInternalCRKeys
+    TReal previousTimeOfChange = 1.0;
+    CRepository* repository = CRepository::NewL( KCRUidCalendar );
+    CleanupStack::PushL( repository );
+    errorVal = repository->Get( KCalendarPersistentTime, previousTimeOfChange );
+    User::LeaveIfError( errorVal );    
+    
+    TInt tzChangedOrAlarmsMissed(0);
+    // compare the times. If the time set in the PubSub key by the Alarm Server is 
+    // greater than the last time we looked at it, we will show 1 of the 2 info notes 
+    // to the user.
+    if (iTimeOfChangeUtcReal != previousTimeOfChange)
+        {
+        // Agenda Server set this value to tell what has happened since
+        // the time change
+        tzChangedOrAlarmsMissed = alarmPkgVarBuf().iValue;
+        }
+    CleanupStack::PopAndDestroy( repository );
+       
+    TRACE_EXIT_POINT;
+    return tzChangedOrAlarmsMissed;    
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::UpdateSytemTimeChangeInfoL
+// Update cenrep with latest system time change info
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenNotifier::UpdateSytemTimeChangeInfoL()
+    {
+    TRACE_ENTRY_POINT;
+    
+    CRepository* repository = CRepository::NewL( KCRUidCalendar );
+    CleanupStack::PushL( repository );
+        
+    // Update the persistent time stamp to the time stamp 
+    // indicated by the agenda server
+    TInt errorVal = repository->Set( KCalendarPersistentTime, iTimeOfChangeUtcReal);
+    User::LeaveIfError( errorVal );
+    CleanupStack::PopAndDestroy( repository );
+    
+    TRACE_EXIT_POINT;
+    }
+
+// ----------------------------------------------------------------------------
+// CCalenNotifier::TNotificationHandler()
 // TNotificationHandler contructor
 // ----------------------------------------------------------------------------
-CalenNotifier::TNotificationHandler::TNotificationHandler() : 
+CCalenNotifier::TNotificationHandler::TNotificationHandler() : 
                 iHashSet(&::HashCalenNotificationFunction,&::HashCalenNotificationIdentityRelation)
     {
-    OstTraceFunctionEntry0( TNOTIFICATIONHANDLER_TNOTIFICATIONHANDLER_ENTRY );
-    
-    OstTraceFunctionExit0( TNOTIFICATIONHANDLER_TNOTIFICATIONHANDLER_EXIT );
+    TRACE_ENTRY_POINT;
+    TRACE_EXIT_POINT;
     }
 
+// ----------------------------------------------------------------------------
+// CCalenNotifier::CalendarInfoChangeNotificationL()
+// Handle calendar file change notifications
+// ----------------------------------------------------------------------------
+void CCalenNotifier::CalendarInfoChangeNotificationL( 
+        RPointerArray<CCalFileChangeInfo>& aCalendarInfoChangeEntries)
+	{
+	TRACE_ENTRY_POINT;
+
+	// get the file change count
+	TInt calenInfoChangeCount = aCalendarInfoChangeEntries.Count();
+
+	for(TInt index = 0;index < calenInfoChangeCount;index++)
+		{
+		//get the context and set the calendar filename which triggered the
+		// notification
+		MCalenContext &context = iController.Services().Context();
+		context.SetCalendarFileNameL(
+				aCalendarInfoChangeEntries[index]->FileNameL());
+		
+		MCalFileChangeObserver::TChangeType changeType = 
+					aCalendarInfoChangeEntries[index]->ChangeType();
+		switch(changeType)
+			{
+			case MCalFileChangeObserver::ECalendarFileCreated:
+			    {
+			   TFileName lastCreatedFileName = aCalendarInfoChangeEntries[index]->FileNameL();
+               CRepository* cenRep = CRepository::NewLC(KCRUidCalendar); 
+               User::LeaveIfError( cenRep->Set( KCalendarLastUsedCalendar, lastCreatedFileName ) );
+               CleanupStack::PopAndDestroy( cenRep );
+			    }
+			case MCalFileChangeObserver::ECalendarInfoCreated:
+				{
+				BroadcastNotification(ECalenNotifyDeleteInstanceView);
+				BroadcastNotification(ECalenNotifyCalendarInfoCreated);
+				}
+				break;
+			case MCalFileChangeObserver::ECalendarFileDeleted:
+				{
+				BroadcastNotification(ECalenNotifyCalendarFileDeleted);
+				}
+				break;
+			case MCalFileChangeObserver::ECalendarInfoUpdated:
+			case MCalFileChangeObserver::ECalendarInfoDeleted:
+				{
+				TFileName calFileName = aCalendarInfoChangeEntries[index]->FileNameL();
+                CCalSession* session = NULL;
+                TRAPD(err, session = &iGlobalData->CalSessionL( calFileName ));
+                if(KErrNotFound == err && ECalendarInfoUpdated == changeType)
+                    {
+                    BroadcastNotification(ECalenNotifyDeleteInstanceView);
+                    BroadcastNotification(ECalenNotifyCalendarInfoCreated);
+                    break;
+                    }
+				
+				CCalCalendarInfo* calendarInfo = session->CalendarInfoL();
+                CleanupStack::PushL(calendarInfo);
+
+                TBuf8<KBuffLength> keyBuff;
+                keyBuff.AppendNum(EMarkAsDelete);
+
+                TBool markAsdelete;
+                TPckgC<TBool> pkgMarkAsDelete(markAsdelete);
+                TRAP(err,pkgMarkAsDelete.Set(calendarInfo->PropertyValueL(keyBuff)));
+                markAsdelete = pkgMarkAsDelete();
+
+                CleanupStack::PopAndDestroy(calendarInfo);
+
+                //remove calendar except default calendar
+                if (err == KErrNone && markAsdelete
+                        && aCalendarInfoChangeEntries[index]->FileNameL().CompareF(
+                                iGlobalData->CalSessionL().DefaultFileNameL()))
+                    {
+                    iFilnameDeleted = aCalendarInfoChangeEntries[index]->FileNameL().AllocL();
+                    BroadcastNotification(ECalenNotifyDeleteInstanceView);
+                    iGlobalData->RemoveCalendarL(iFilnameDeleted->Des());
+                    BroadcastNotification(ECalenNotifyCalendarFileDeleted);
+                                       
+                    delete iFilnameDeleted;
+                    iFilnameDeleted = NULL;
+                    }
+                else
+                    {
+                    BroadcastNotification(ECalenNotifyCalendarInfoUpdated);
+                    }
+                }
+				break;
+			default:
+				break;
+			}
+		context.ResetCalendarFileName();
+		}
+
+	TRACE_EXIT_POINT;
+	}
+
+
 // End of file