calendarui/controller/src/calennotifier.cpp
branchRCL_3
changeset 30 bd7edf625bdd
parent 29 12af337248b1
child 31 97232defd20e
equal deleted inserted replaced
29:12af337248b1 30:bd7edf625bdd
    14 * Description:  Calendar notifier
    14 * Description:  Calendar notifier
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 //system includes
    19 
       
    20 #include <aknappui.h>                 // iavkonappui macro
       
    21 #include <bacntf.h>                   // cenvironmentchangenotifier
       
    22 #include <coemain.h>                  // eactiveprioritylogona
       
    23 #include <centralrepository.h>        // crepository
       
    24 #include <ErrorUI.h>                  // cerrorui
       
    25 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS // new 
       
    26 #include <asshdalarm.h>
       
    27 #else // new
       
    28 #include <asshdalarm.h>
       
    29 #include <ASShdAlarmCal.h>
       
    30 #endif // new
    20 #include <e32property.h>
    31 #include <e32property.h>
    21 #include <bacntf.h>                   // CEnvironmentChangeNotifier
    32 #include <calfilechangenotification.h>
    22 #include <coemain.h>                  // EActivePriorityLogonA
    33 #include <calenecomwatcher.h>
    23 
    34 #include <calenglobaldata.h>
    24 //user includes
    35 #include <calenconstants.h>
       
    36 #include <calencontext.h>
       
    37 #include <calsession.h>
       
    38 #include <calcalendarinfo.h>
       
    39 #include <calenmulticaluids.hrh>
       
    40 
    25 #include "calendarui_debug.h"
    41 #include "calendarui_debug.h"
    26 #include "calennotifier.h"            // CalenNotifier
    42 #include "calennotifier.h"            // CCalenNotifier
       
    43 #include "CalendarPrivateCRKeys.h"    // Central Repository keys
       
    44 #include "calensetting.h"
    27 #include "calenstatemachine.h"
    45 #include "calenstatemachine.h"
    28 #include "OstTraceDefinitions.h"
    46 #include "calencontroller.h"
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "calennotifierTraces.h"
       
    31 #endif
       
    32 
    47 
    33 const TInt KHashLength = 64;
    48 const TInt KHashLength = 64;
    34 
    49 const TInt KBuffLength = 24;
    35 // ----------------------------------------------------------------------------
    50 
    36 // CalenNotifier::CalenNotifier
    51 // ----------------------------------------------------------------------------
       
    52 // CCalenNotifier::CCalenNotifier
    37 // C++ default constructor.
    53 // C++ default constructor.
    38 // (other items were commented in a header).
    54 // (other items were commented in a header).
    39 // ----------------------------------------------------------------------------
    55 // ----------------------------------------------------------------------------
    40 //
    56 //
    41 CalenNotifier::CalenNotifier( CCalenStateMachine& aStateMachine )
    57 CCalenNotifier::CCalenNotifier( CCalenController& aController )
    42     : iStateMachine( aStateMachine )
    58     : iController( aController )
    43     {
    59     {
    44     OstTraceFunctionEntry0( CALENNOTIFIER_CALENNOTIFIER_ENTRY );
    60     TRACE_ENTRY_POINT;
    45     
    61     TRACE_EXIT_POINT;
    46     OstTraceFunctionExit0( CALENNOTIFIER_CALENNOTIFIER_EXIT );
    62     }
    47     }
    63 
    48 
    64 // ----------------------------------------------------------------------------
    49 // ----------------------------------------------------------------------------
    65 // CCalenNotifier::~CCalenNotifier
    50 // CalenNotifier::~CalenNotifier
       
    51 // Destructor.
    66 // Destructor.
    52 // (other items were commented in a header).
    67 // (other items were commented in a header).
    53 // ----------------------------------------------------------------------------
    68 // ----------------------------------------------------------------------------
    54 //
    69 //
    55 CalenNotifier::~CalenNotifier()
    70 CCalenNotifier::~CCalenNotifier()
    56     {
    71     {
    57     OstTraceFunctionEntry0( DUP1_CALENNOTIFIER_CALENNOTIFIER_ENTRY );
    72     TRACE_ENTRY_POINT;
    58     
    73 
    59     // Reset the handler array.
    74     // Reset the handler array.
    60     // Before we reset , close hashset for each handler
    75     // Before we reset , close hashset for each handler
    61     for(TInt i = 0 ; i < iHandlers.Count() ; i++)
    76     for(TInt i = 0 ; i < iHandlers.Count() ; i++)
    62         {
    77         {
    63         iHandlers[i].iHashSet.Close();
    78         iHandlers[i].iHashSet.Close();
    64         }
    79         }
    65     
    80     
    66     iHandlers.Reset();
    81     iHandlers.Close();
    67     iBroadcastQueue.Reset();
    82     
       
    83     iBroadcastQueue.Close();
       
    84     
       
    85     
       
    86     if( iFilnameDeleted )
       
    87         {
       
    88         delete iFilnameDeleted;
       
    89         iFilnameDeleted = NULL;
       
    90         }
       
    91     
       
    92     // Stop ECom change notifications
       
    93     if( iEComWatcher )
       
    94         {
       
    95         delete iEComWatcher;
       
    96         iEComWatcher = NULL;
       
    97         }
       
    98 
       
    99     // Stop settings change notifications
       
   100     if( iCenRepChangeNotifier )
       
   101         {
       
   102         delete iCenRepChangeNotifier;
       
   103         iCenRepChangeNotifier = NULL;
       
   104         }
       
   105     
       
   106     if( iRepository )
       
   107         {
       
   108         delete iRepository;
       
   109         iRepository = NULL;
       
   110         }
    68     
   111     
    69     // Stop environment change notifications
   112     // Stop environment change notifications
    70     if( iEnvChangeNotifier )
   113     if( iEnvChangeNotifier )
    71         {
   114         {
    72         iEnvChangeNotifier->Cancel();
   115         iEnvChangeNotifier->Cancel();
    73         delete iEnvChangeNotifier;
   116         delete iEnvChangeNotifier;
    74         }
   117         }
    75 
   118     
    76     OstTraceFunctionExit0( DUP1_CALENNOTIFIER_CALENNOTIFIER_EXIT );
   119     if( iSetting )
    77     }
   120         {
    78 
   121         iSetting->Release();
    79 // ----------------------------------------------------------------------------
   122         }
    80 // CalenNotifier::ConstructL
   123     
       
   124     // Release the global data
       
   125     if( iGlobalData )
       
   126         {
       
   127         // stop listening for calendar file change notifications
       
   128         TRAP_IGNORE(iGlobalData->CalSessionL().StopFileChangeNotification());
       
   129         iGlobalData->Release();
       
   130         }
       
   131 	TRACE_EXIT_POINT;
       
   132 	}
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CCalenNotifier::ConstructL
    81 // Symbian 2nd phase of construction.
   136 // Symbian 2nd phase of construction.
    82 // (other items were commented in a header).
   137 // (other items were commented in a header).
    83 // ----------------------------------------------------------------------------
   138 // ----------------------------------------------------------------------------
    84 //
   139 //
    85 void CalenNotifier::ConstructL()
   140 void CCalenNotifier::ConstructL()
    86     {
   141     {
    87     OstTraceFunctionEntry0( CALENNOTIFIER_CONSTRUCTL_ENTRY );
   142     TRACE_ENTRY_POINT;
       
   143     
       
   144     // Get the global data
       
   145     iGlobalData = CCalenGlobalData::InstanceL();
       
   146     
       
   147     // Get the setting singleton. We update it when settings change.
       
   148     iSetting = CCalenSetting::InstanceL();
    88     
   149     
    89     // Register for system environment changes
   150     // Register for system environment changes
    90     TCallBack envCallback( EnvChangeCallbackL, this );
   151     TCallBack envCallback( EnvChangeCallbackL, this );
    91     iEnvChangeNotifier =
   152     iEnvChangeNotifier =
    92         CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, envCallback );
   153         CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, envCallback );
    93     iEnvChangeNotifier->Start();
   154     iEnvChangeNotifier->Start();
    94 
   155     
    95     iIgnoreFirstLocaleChange = ETrue;
   156     // Register for changes to Calendar settings from the Central Repository
    96  
   157     iRepository = CRepository::NewL( KCRUidCalendar );
    97     OstTraceFunctionExit0( CALENNOTIFIER_CONSTRUCTL_EXIT );
   158     iCenRepChangeNotifier = CCenRepNotifyHandler::NewL( *this, *iRepository );
    98     }
   159     iCenRepChangeNotifier->StartListeningL();
    99 
   160     
   100 // ----------------------------------------------------------------------------
   161     // Register for changes to the ECom registry
   101 // CalenNotifier::RegisterForNotificationsL
   162     iEComWatcher = CCalenEComWatcher::NewL( *this );
       
   163      
       
   164 	iIgnoreFirstLocaleChange = ETrue;
       
   165 
       
   166 	// start listening for calendar file change notifications
       
   167 	iGlobalData->CalSessionL().StartFileChangeNotificationL(*this);
       
   168 	
       
   169 	
       
   170 	iFilnameDeleted = NULL;
       
   171 
       
   172 	TRACE_EXIT_POINT;
       
   173 	}
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CCalenNotifier::RegisterForNotificationsL
   102 // Adds the passed handler to the handler array.
   177 // Adds the passed handler to the handler array.
   103 // (other items were commented in a header).
   178 // (other items were commented in a header).
   104 // ----------------------------------------------------------------------------
   179 // ----------------------------------------------------------------------------
   105 //
   180 //
   106 void CalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, 
   181 void CCalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, 
   107                                                 TCalenNotification aNotification)
   182                                                 TCalenNotification aNotification)
   108     {
   183     {
   109     OstTraceFunctionEntry0( CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_ENTRY );
   184     TRACE_ENTRY_POINT;
   110     
   185 
   111     TNotificationHandler handler;
   186     TNotificationHandler handler;
   112     handler.iHandler = aHandler;
   187     handler.iHandler = aHandler;
   113     
   188     
   114     //Prepare hash
   189     //Prepare hash
   115     handler.iHashSet.ReserveL(KHashLength);
   190     handler.iHashSet.ReserveL(KHashLength);
   132         handler.iHashSet.InsertL(aNotification);
   207         handler.iHashSet.InsertL(aNotification);
   133         }
   208         }
   134     
   209     
   135     iHandlers.Append( handler );
   210     iHandlers.Append( handler );
   136     
   211     
   137     OstTraceFunctionExit0( CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_EXIT );
   212     TRACE_EXIT_POINT;
   138     }
   213     }
   139 
   214 
   140 // ----------------------------------------------------------------------------
   215 // ----------------------------------------------------------------------------
   141 // CalenNotifier::RegisterForNotificationsL
   216 // CCalenNotifier::RegisterForNotificationsL
   142 // Adds the passed handler to the handler array.
   217 // Adds the passed handler to the handler array.
   143 // (other items were commented in a header).
   218 // (other items were commented in a header).
   144 // ----------------------------------------------------------------------------
   219 // ----------------------------------------------------------------------------
   145 //
   220 //
   146 void CalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, 
   221 void CCalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, 
   147                                                            RArray<TCalenNotification>& aNotifications  )
   222                                                            RArray<TCalenNotification>& aNotifications  )
   148     {
   223     {
   149     OstTraceFunctionEntry0( DUP1_CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_ENTRY );
   224     TRACE_ENTRY_POINT;
   150 
   225 
   151     TNotificationHandler handler;
   226     TNotificationHandler handler;
   152     handler.iHandler = aHandler;
   227     handler.iHandler = aHandler;
   153     
   228     
   154     //Prepare hash
   229     //Prepare hash
   175             }
   250             }
   176         }
   251         }
   177     
   252     
   178     iHandlers.Append( handler );
   253     iHandlers.Append( handler );
   179 
   254 
   180     OstTraceFunctionExit0( DUP1_CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_EXIT );
   255     TRACE_EXIT_POINT;
   181     }
   256     }
   182 
   257 
   183 // ----------------------------------------------------------------------------
   258 // ----------------------------------------------------------------------------
   184 // CalenNotifier::CancelNotifications
   259 // CCalenNotifier::CancelNotifications
   185 // Removes the passed handler from the handler array.
   260 // Removes the passed handler from the handler array.
   186 // (other items were commented in a header).
   261 // (other items were commented in a header).
   187 // ----------------------------------------------------------------------------
   262 // ----------------------------------------------------------------------------
   188 //
   263 //
   189 void CalenNotifier::CancelNotifications( MCalenNotificationHandler* aHandler )
   264 void CCalenNotifier::CancelNotifications( MCalenNotificationHandler* aHandler )
   190     {
   265     {
   191     OstTraceFunctionEntry0( CALENNOTIFIER_CANCELNOTIFICATIONS_ENTRY );
   266     TRACE_ENTRY_POINT;
   192     
   267 
   193     for( TInt x = 0; x < iHandlers.Count(); ++x )
   268     for( TInt x = 0; x < iHandlers.Count(); ++x )
   194         {
   269         {
   195         if( iHandlers[x].iHandler == aHandler )
   270         if( iHandlers[x].iHandler == aHandler )
   196             {
   271             {
   197             // Mark the notification for deletion by
   272             // Mark the notification for deletion by
   198             // settings the handler to NULL. Actual deletion
   273             // settings the handler to NULL. Actual deletion
   199             // will take place in DoBroadcast
   274             // will take place in DoBroadcast
   200             iHandlers[x].iHashSet.Close();
   275             iHandlers[x].iHashSet.Close();
   201             iHandlers[x].iHandler = NULL;
   276             iHandlers[x].iHandler = NULL;
   202             TRACE_EXIT_POINT;
   277             TRACE_EXIT_POINT;
   203             OstTraceFunctionExit0( CALENNOTIFIER_CANCELNOTIFICATIONS_EXIT );
       
   204             return;
   278             return;
   205             }
   279             }
   206         }
   280         }
   207 
   281 
   208     OstTraceFunctionExit0( DUP1_CALENNOTIFIER_CANCELNOTIFICATIONS_EXIT );
   282     TRACE_EXIT_POINT;
   209     }
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // CalenNotifier::ContextChanged
       
   213 // From MCalenContextChangeObserver. Called when the context changes.
       
   214 // (other items were commented in a header).
       
   215 // ----------------------------------------------------------------------------
       
   216 //
       
   217 void CalenNotifier::ContextChanged()
       
   218     {
       
   219     OstTraceFunctionEntry0( CALENNOTIFIER_CONTEXTCHANGED_ENTRY );
       
   220     
       
   221     BroadcastNotification( ECalenNotifyContextChanged );
       
   222 
       
   223     OstTraceFunctionExit0( CALENNOTIFIER_CONTEXTCHANGED_EXIT );
       
   224     }
   283     }
   225 
   284 
   226 // ----------------------------------------------------------------------------
   285 // ----------------------------------------------------------------------------
   227 //  CCalenNotifier::EnvChangeCallbackL
   286 //  CCalenNotifier::EnvChangeCallbackL
   228 //  CEnvironmentChangeNotifier callback.  Calendar is only interested in:
   287 //  CEnvironmentChangeNotifier callback.  Calendar is only interested in:
   230 //  EChangesMidnightCrossover   - System time passed midnight
   289 //  EChangesMidnightCrossover   - System time passed midnight
   231 //  EChangesSystemTime          - System time changed
   290 //  EChangesSystemTime          - System time changed
   232 // (other items were commented in a header).
   291 // (other items were commented in a header).
   233 // ----------------------------------------------------------------------------
   292 // ----------------------------------------------------------------------------
   234 //
   293 //
   235 TInt CalenNotifier::EnvChangeCallbackL( TAny* aThisPtr )
   294 TInt CCalenNotifier::EnvChangeCallbackL( TAny* aThisPtr )
   236     {
   295     {
   237     OstTraceFunctionEntry0( CALENNOTIFIER_ENVCHANGECALLBACKL_ENTRY );
   296     TRACE_ENTRY_POINT;
   238     
   297 
   239     OstTraceFunctionExit0( CALENNOTIFIER_ENVCHANGECALLBACKL_EXIT );
   298   /*  CCalenNotifier* thisPtr = static_cast<CCalenNotifier*>( aThisPtr );
   240     
   299 
       
   300     if( thisPtr->iEnvChangeNotifier->Change() & EChangesMidnightCrossover )
       
   301         {
       
   302         thisPtr->BroadcastNotification( ECalenNotifySystemTimeChanged );
       
   303         }
       
   304 
       
   305     if( thisPtr->iEnvChangeNotifier->Change() & EChangesLocale )
       
   306         {
       
   307         thisPtr->BroadcastNotification( ECalenNotifySystemLocaleChanged );
       
   308         }
       
   309 
       
   310     if( thisPtr->iEnvChangeNotifier->Change() & EChangesSystemTime ) 
       
   311         {
       
   312         thisPtr->BroadcastNotification( ECalenNotifySystemTimeChanged );
       
   313         }*/
       
   314         
       
   315     TRACE_EXIT_POINT;
   241     // Return value for functions used as TCallBack objects should be EFalse
   316     // Return value for functions used as TCallBack objects should be EFalse
   242     // unless the function is intended to be called again from a timer.
   317     // unless the function is intended to be called again from a timer.
   243    // return EFalse;
   318    // return EFalse;
   244     return static_cast<CalenNotifier*>(aThisPtr)->DoEnvChange();
   319     return static_cast<CCalenNotifier*>(aThisPtr)->DoEnvChange();
   245     }
   320     }
   246 
   321 
   247 // ----------------------------------------------------------------------------
   322 // ----------------------------------------------------------------------------
   248 //  CCalenNotifier::DoEnvChange
   323 //  CCalenNotifier::DoEnvChange
   249 //  EnvChangeCallbackL calls this function
   324 //  EnvChangeCallbackL calls this function
   250 // ----------------------------------------------------------------------------
   325 // ----------------------------------------------------------------------------
   251 //
   326 //
   252 TInt CalenNotifier::DoEnvChange()
   327 TInt CCalenNotifier::DoEnvChange()
   253     {
   328 	{
   254     OstTraceFunctionEntry0( CALENNOTIFIER_DOENVCHANGE_ENTRY );
   329 	TRACE_ENTRY_POINT;
   255     
   330 	
   256     if( ((iEnvChangeNotifier->Change() & EChangesMidnightCrossover)
   331 	if( ((iEnvChangeNotifier->Change() & EChangesMidnightCrossover)
   257         || (iEnvChangeNotifier->Change() & EChangesSystemTime))
   332 		|| (iEnvChangeNotifier->Change() & EChangesSystemTime))
   258         && !iIgnoreFirstLocaleChange )
   333 		&& !iIgnoreFirstLocaleChange )
   259         {
   334         {
   260         BroadcastNotification( ECalenNotifySystemTimeChanged );
   335         BroadcastNotification( ECalenNotifySystemTimeChanged );
   261         }
   336         }
   262     else if( (iEnvChangeNotifier->Change() & EChangesLocale)
   337 	else if( (iEnvChangeNotifier->Change() & EChangesLocale)
   263             && !iIgnoreFirstLocaleChange )  
   338 			&& !iIgnoreFirstLocaleChange )	
   264         {
   339         {
   265         BroadcastNotification( ECalenNotifySystemLocaleChanged );
   340         BroadcastNotification( ECalenNotifySystemLocaleChanged );
   266         }
   341         }
   267      else
   342      else
   268         {
   343      	{
   269         iIgnoreFirstLocaleChange = EFalse;
   344      	iIgnoreFirstLocaleChange = EFalse;
   270         }   
   345      	}   
   271 
   346 
   272     OstTraceFunctionExit0( CALENNOTIFIER_DOENVCHANGE_EXIT );
   347     TRACE_EXIT_POINT; 
   273     return EFalse ;
   348     return EFalse ;
   274     }
   349 	}
   275 
   350 // ----------------------------------------------------------------------------
   276 // ----------------------------------------------------------------------------
   351 // CCalenNotifier::HandleNotifyGeneric
   277 // CalenNotifier::BroadcastNotification
   352 // From MCenRepNotifyHandlerCallback
       
   353 // Generic notification that one of our central repository keys has changed
       
   354 // If any keys change we broadcast a settings changed notification
       
   355 // (other items were commented in a header).
       
   356 // ----------------------------------------------------------------------------
       
   357 //
       
   358 void CCalenNotifier::HandleNotifyGeneric( TUint32 /*aId*/ )
       
   359     {
       
   360     TRACE_ENTRY_POINT;
       
   361 
       
   362     PIM_TRAPD_HANDLE( iSetting->LoadL() );
       
   363     BroadcastNotification( ECalenNotifySettingsChanged );
       
   364 
       
   365     // Use another trap to make sure we start listening again, regardless
       
   366     // of whether the previous function left or not.
       
   367     PIM_TRAPD_HANDLE( iCenRepChangeNotifier->StartListeningL() );
       
   368 
       
   369     TRACE_EXIT_POINT;
       
   370     }
       
   371 
       
   372 // ----------------------------------------------------------------------------
       
   373 // CCalenNotifier::HandleNotifyError
       
   374 // Cenrep watcher error callback
       
   375 // (other items were commented in a header).
       
   376 // ----------------------------------------------------------------------------
       
   377 //
       
   378 void CCalenNotifier::HandleNotifyError( TUint32 /*aId*/,
       
   379                                                     TInt /*aError*/,
       
   380                                                     CCenRepNotifyHandler* /*aHandler*/ )
       
   381     {
       
   382     TRACE_ENTRY_POINT;
       
   383 
       
   384     PIM_TRAPD_HANDLE( iCenRepChangeNotifier->StartListeningL() );
       
   385 
       
   386     TRACE_EXIT_POINT;
       
   387     }
       
   388 
       
   389 // ----------------------------------------------------------------------------
       
   390 // CCalenNotifier::HandleDBChangeL
       
   391 // From MCalenDBChangeObserver
       
   392 // Notification that an external CCalSession has modified the database we are
       
   393 // using in some way.  This notification is limited to a maximum of one per
       
   394 // second.  This is to avoid multiple notifications when performing large sync
       
   395 // operations
       
   396 // (other items were commented in a header).
       
   397 // ----------------------------------------------------------------------------
       
   398 //
       
   399 void CCalenNotifier::HandleDBChangeL()
       
   400     {
       
   401     TRACE_ENTRY_POINT;
       
   402 
       
   403     BroadcastNotification( ECalenNotifyExternalDatabaseChanged );
       
   404 
       
   405     TRACE_EXIT_POINT;
       
   406     }
       
   407 
       
   408 // ----------------------------------------------------------------------------
       
   409 // CCalenNotifier::ContextChanged
       
   410 // From MCalenContextChangeObserver. Called when the context changes.
       
   411 // (other items were commented in a header).
       
   412 // ----------------------------------------------------------------------------
       
   413 //
       
   414 void CCalenNotifier::ContextChanged()
       
   415     {
       
   416     TRACE_ENTRY_POINT;
       
   417 
       
   418     BroadcastNotification( ECalenNotifyContextChanged );
       
   419 
       
   420     TRACE_EXIT_POINT;
       
   421     }
       
   422 
       
   423 // ----------------------------------------------------------------------------
       
   424 // CCalenNotifier::EComChanged
       
   425 // From MCalenEComChangeObserver. Called when the ECom registry changes 
       
   426 // (install/uninstall).
       
   427 // ----------------------------------------------------------------------------
       
   428 //
       
   429 void CCalenNotifier::EComChanged()
       
   430     {
       
   431     TRACE_ENTRY_POINT;
       
   432     
       
   433     if(!iController.IsFasterAppFlagEnabled())
       
   434         {
       
   435         BroadcastNotification( ECalenNotifyEComRegistryChanged );
       
   436         }
       
   437     
       
   438     TRACE_EXIT_POINT;
       
   439     }
       
   440 
       
   441 // ----------------------------------------------------------------------------
       
   442 // CCalenNotifier::DeferSettingsNotifications
       
   443 // After calling this function, any settings changed notifications
       
   444 // will not be broadcast until after ResumeSettingsNotifications
       
   445 // has been called.
       
   446 // (other items were commented in a header).
       
   447 // ----------------------------------------------------------------------------
       
   448 //
       
   449 void CCalenNotifier::DeferSettingsNotifications()
       
   450     {
       
   451     TRACE_ENTRY_POINT;
       
   452 
       
   453     iIsSettingsBroadcastDeferred = ETrue;
       
   454 
       
   455     TRACE_EXIT_POINT;
       
   456     }
       
   457 
       
   458 // ----------------------------------------------------------------------------
       
   459 // CCalenNotifier::ResumeSettingsNotifications
       
   460 // Resumes settings notifications after they have been paused
       
   461 // with DeferSettingsNotifications.
       
   462 // (other items were commented in a header).
       
   463 // ----------------------------------------------------------------------------
       
   464 //
       
   465 void CCalenNotifier::ResumeSettingsNotifications()
       
   466     {
       
   467     TRACE_ENTRY_POINT;
       
   468 
       
   469     iIsSettingsBroadcastDeferred = EFalse;
       
   470 
       
   471     if( iSettingsNeedsBroadcast )
       
   472         {
       
   473         iSettingsNeedsBroadcast = EFalse;
       
   474         BroadcastNotification( ECalenNotifySettingsChanged );
       
   475         }
       
   476 
       
   477     if( iLocaleNeedsBroadcast )
       
   478         {
       
   479         iLocaleNeedsBroadcast = EFalse;
       
   480         BroadcastNotification( ECalenNotifySystemLocaleChanged );
       
   481         }
       
   482 
       
   483     TRACE_EXIT_POINT;
       
   484     }
       
   485 
       
   486 // ----------------------------------------------------------------------------
       
   487 // CCalenNotifier::BroadcastNotification
   278 // Issues a notification to all registered handlers
   488 // Issues a notification to all registered handlers
   279 // (other items were commented in a header).
   489 // (other items were commented in a header).
   280 // ----------------------------------------------------------------------------
   490 // ----------------------------------------------------------------------------
   281 //
   491 //
   282 void CalenNotifier::BroadcastNotification( TCalenNotification aNotification )
   492 void CCalenNotifier::BroadcastNotification( TCalenNotification aNotification )
   283     {
   493     {
   284     OstTraceFunctionEntry0( CALENNOTIFIER_BROADCASTNOTIFICATION_ENTRY );
   494     TRACE_ENTRY_POINT;
   285     
   495 
   286     // Someone has told us to broadcast, or one of our notifiers completed.
   496     // Someone has told us to broadcast, or one of our notifiers completed.
   287     // We run it past the state machine and that may or may not call the
   497     // We run it past the state machine and that may or may not call the
   288     // function to really do the broadcast.
   498     // function to really do the broadcast.
   289     iStateMachine.HandleNotification( aNotification );
   499     iController.StateMachine().HandleNotification( aNotification );
   290     
   500     
   291     OstTraceFunctionExit0( CALENNOTIFIER_BROADCASTNOTIFICATION_EXIT );
   501     TRACE_EXIT_POINT;
   292     }
   502     }
   293     
   503     
   294 // ----------------------------------------------------------------------------
   504 // ----------------------------------------------------------------------------
   295 // CalenNotifier::BroadcastApprovedNotification
   505 // CCalenNotifier::BroadcastApprovedNotification
   296 // Issues a notification to all registered handlers
   506 // Issues a notification to all registered handlers
   297 // (other items were commented in a header).
   507 // (other items were commented in a header).
   298 // ----------------------------------------------------------------------------
   508 // ----------------------------------------------------------------------------
   299 //
   509 //
   300 void CalenNotifier::BroadcastApprovedNotification( TCalenNotification aNotification )
   510 void CCalenNotifier::BroadcastApprovedNotification( TCalenNotification aNotification )
   301     {
   511     {
   302     OstTraceFunctionEntry0( CALENNOTIFIER_BROADCASTAPPROVEDNOTIFICATION_ENTRY );
   512     TRACE_ENTRY_POINT;
   303     
   513     /*if ( aNotification == ECalenNotifySettingsChanged
   304     iBroadcastQueue.Append( aNotification );
   514             &&  iIsSettingsBroadcastDeferred )
   305 
   515         {
   306     if( !iBroadcastActive )
   516         iSettingsNeedsBroadcast = ETrue;
   307         {
   517         }
   308         iBroadcastActive = ETrue;
   518     else if ( aNotification == ECalenNotifySystemLocaleChanged 
   309         while( iBroadcastQueue.Count() )
   519                 && iIsSettingsBroadcastDeferred)
       
   520         {
       
   521         iLocaleNeedsBroadcast = ETrue;
       
   522         }
       
   523     else*/
       
   524         {
       
   525         iBroadcastQueue.Append( aNotification );
       
   526 
       
   527         if( !iBroadcastActive )
   310             {
   528             {
   311             TCalenNotification notification = iBroadcastQueue[0];
   529             iBroadcastActive = ETrue;
   312             DoBroadcast( notification );
   530             while( iBroadcastQueue.Count() )
   313             iBroadcastQueue.Remove( 0 );
   531                 {
       
   532                 TCalenNotification notification = iBroadcastQueue[0];
       
   533                 DoBroadcast( notification );
       
   534                 iBroadcastQueue.Remove( 0 );
       
   535                 }
       
   536             iBroadcastActive = EFalse;
   314             }
   537             }
   315         iBroadcastActive = EFalse;
   538         }
   316         }
   539 
   317     
   540     TRACE_EXIT_POINT;
   318     OstTraceFunctionExit0( CALENNOTIFIER_BROADCASTAPPROVEDNOTIFICATION_EXIT );
   541     }
   319     }
   542 
   320 
   543 // ----------------------------------------------------------------------------
   321 // ----------------------------------------------------------------------------
   544 // CCalenNotifier::DoBroadcast
   322 // CalenNotifier::DoBroadcast
       
   323 // Issues a notification to all registered handlers
   545 // Issues a notification to all registered handlers
   324 // (other items were commented in a header).
   546 // (other items were commented in a header).
   325 // ----------------------------------------------------------------------------
   547 // ----------------------------------------------------------------------------
   326 //
   548 //
   327 void CalenNotifier::DoBroadcast( TCalenNotification aNotification )
   549 void CCalenNotifier::DoBroadcast( TCalenNotification aNotification )
   328     {
   550     {
   329     OstTraceFunctionEntry0( CALENNOTIFIER_DOBROADCAST_ENTRY );
   551     TRACE_ENTRY_POINT;
   330     
   552 
   331     for( TInt x = 0; x < iHandlers.Count(); ++x )
   553     for( TInt x = 0; x < iHandlers.Count(); ++x )
   332         {
   554         {
   333         TNotificationHandler handler = iHandlers[x];
   555         TNotificationHandler handler = iHandlers[x];
   334         if( handler.iHandler )
   556         if( handler.iHandler )
   335             {
   557             {
   344             iHandlers.Remove( x ); // remove the entry
   566             iHandlers.Remove( x ); // remove the entry
   345             --x; // decrement the index.
   567             --x; // decrement the index.
   346             }
   568             }
   347         }
   569         }
   348 
   570 
   349     OstTraceFunctionExit0( CALENNOTIFIER_DOBROADCAST_EXIT );
   571     TRACE_EXIT_POINT;
   350     }
   572     }
   351 
   573 
   352 // ----------------------------------------------------------------------------
   574 // ----------------------------------------------------------------------------
   353 // CalenNotifier::TNotificationHandler()
   575 // CCalenNotifier::Progress
       
   576 // From MCalProgressCallback. Intentionally empty.
       
   577 // (other items were commented in a header).
       
   578 // ----------------------------------------------------------------------------
       
   579 //
       
   580 void CCalenNotifier::Progress( TInt /*aPercentageCompleted*/ )
       
   581     {
       
   582     TRACE_ENTRY_POINT;
       
   583     TRACE_EXIT_POINT;
       
   584     }
       
   585 
       
   586 // ----------------------------------------------------------------------------
       
   587 // CCalenNotifier::NotifyProgress
       
   588 // From MCalProgressCallback. Don't notify us about progress updates.
       
   589 // (other items were commented in a header).
       
   590 // ----------------------------------------------------------------------------
       
   591 //
       
   592 TBool CCalenNotifier::NotifyProgress()
       
   593     {
       
   594     TRACE_ENTRY_POINT;
       
   595 	// No one interested in this notification.Removing to avoid notification clutter.
       
   596     // BroadcastNotification( ECalenNotifyViewCreationStarted );
       
   597 
       
   598     TRACE_EXIT_POINT;
       
   599     return EFalse;
       
   600     }
       
   601 
       
   602 // ----------------------------------------------------------------------------
       
   603 // CCalenNotifier::Completed
       
   604 // From MCalProgressCallback.
       
   605 // Notifies observer of completion
       
   606 // (other items were commented in a header).
       
   607 // ----------------------------------------------------------------------------
       
   608 //
       
   609 void CCalenNotifier::Completed( TInt aStatus )
       
   610     {
       
   611     TRACE_ENTRY_POINT;
       
   612 
       
   613     if( aStatus == KErrNone )
       
   614         {
       
   615         BroadcastNotification( ECalenNotifyEntryInstanceViewCreated );
       
   616         }
       
   617     else
       
   618         {
       
   619         BroadcastNotification( ECalenNotifyEntryInstanceViewCreationFailed );
       
   620         // The view creation has failed, hence the calendar
       
   621         // application needs to close gracefully
       
   622         // 1) Display error note.
       
   623         
       
   624         CErrorUI* errorUi;
       
   625         TRAPD(error,errorUi = CErrorUI::NewLC();
       
   626        if(error!=KErrNone)
       
   627        		{
       
   628     		// do avoid warning
       
   629     		}        
       
   630         errorUi->ShowGlobalErrorNoteL( aStatus );        
       
   631         CleanupStack::PopAndDestroy( errorUi );
       
   632         );
       
   633 
       
   634 		// If Instance view creation is cancelled, no need to
       
   635 		// exit application.All other errors exit application.
       
   636 		if(aStatus != KErrCancel)
       
   637 			{
       
   638 	        // Exit application
       
   639 	        if (iAvkonAppUi)
       
   640 	            {
       
   641 	            iAvkonAppUi->Exit();
       
   642 	            }
       
   643 			}
       
   644         }
       
   645 
       
   646     TRACE_EXIT_POINT;
       
   647     }
       
   648 
       
   649 // ----------------------------------------------------------------------------
       
   650 // CCalenNotifier::SystemTimeChangedL
       
   651 // Check if the system time changed since Calendar was last launched
       
   652 // If the system time did change, we need to notify the user that alarms may
       
   653 // have been missed.
       
   654 // (other items were commented in a header).
       
   655 // ----------------------------------------------------------------------------
       
   656 //
       
   657 TInt CCalenNotifier::SystemTimeChangedL()
       
   658     {
       
   659     TRACE_ENTRY_POINT;
       
   660     
       
   661     TBool timeZoneChanged(EFalse);
       
   662 
       
   663     TPckgBuf<TMissedAlarmPubSubData> alarmPkgVarBuf;
       
   664     TInt errorVal = RProperty::Get( KAlarmServerPubSubCategory, 
       
   665                             KMissingAlarmPubSubKey, alarmPkgVarBuf);
       
   666 
       
   667     if(errorVal != KErrNone)
       
   668         {
       
   669         // Error in accessing the P&S key.
       
   670         // Alarm server defines this key when first time SystemTime Changes after bootup.
       
   671         // But Calendar may try to access this before it is defined by Alarm server.
       
   672         // So better not leaving based on errorVal
       
   673         return timeZoneChanged;
       
   674         }
       
   675     
       
   676     // read the latest timechange from agenda Server Time Stamp
       
   677     TTime timeOfChangeUtc = alarmPkgVarBuf().iTimeOfChangeUtc;
       
   678     //timeOfChangeUtc.RoundUpToNextMinute();
       
   679     iTimeOfChangeUtcReal = I64REAL(timeOfChangeUtc.Int64());
       
   680 
       
   681     // read the persistent time stamp from CalendarInternalCRKeys
       
   682     TReal previousTimeOfChange = 1.0;
       
   683     CRepository* repository = CRepository::NewL( KCRUidCalendar );
       
   684     CleanupStack::PushL( repository );
       
   685     errorVal = repository->Get( KCalendarPersistentTime, previousTimeOfChange );
       
   686     User::LeaveIfError( errorVal );    
       
   687     
       
   688     TInt tzChangedOrAlarmsMissed(0);
       
   689     // compare the times. If the time set in the PubSub key by the Alarm Server is 
       
   690     // greater than the last time we looked at it, we will show 1 of the 2 info notes 
       
   691     // to the user.
       
   692     if (iTimeOfChangeUtcReal != previousTimeOfChange)
       
   693         {
       
   694         // Agenda Server set this value to tell what has happened since
       
   695         // the time change
       
   696         tzChangedOrAlarmsMissed = alarmPkgVarBuf().iValue;
       
   697         }
       
   698     CleanupStack::PopAndDestroy( repository );
       
   699        
       
   700     TRACE_EXIT_POINT;
       
   701     return tzChangedOrAlarmsMissed;    
       
   702     }
       
   703 
       
   704 // ----------------------------------------------------------------------------
       
   705 // CCalenNotifier::UpdateSytemTimeChangeInfoL
       
   706 // Update cenrep with latest system time change info
       
   707 // (other items were commented in a header).
       
   708 // ----------------------------------------------------------------------------
       
   709 //
       
   710 void CCalenNotifier::UpdateSytemTimeChangeInfoL()
       
   711     {
       
   712     TRACE_ENTRY_POINT;
       
   713     
       
   714     CRepository* repository = CRepository::NewL( KCRUidCalendar );
       
   715     CleanupStack::PushL( repository );
       
   716         
       
   717     // Update the persistent time stamp to the time stamp 
       
   718     // indicated by the agenda server
       
   719     TInt errorVal = repository->Set( KCalendarPersistentTime, iTimeOfChangeUtcReal);
       
   720     User::LeaveIfError( errorVal );
       
   721     CleanupStack::PopAndDestroy( repository );
       
   722     
       
   723     TRACE_EXIT_POINT;
       
   724     }
       
   725 
       
   726 // ----------------------------------------------------------------------------
       
   727 // CCalenNotifier::TNotificationHandler()
   354 // TNotificationHandler contructor
   728 // TNotificationHandler contructor
   355 // ----------------------------------------------------------------------------
   729 // ----------------------------------------------------------------------------
   356 CalenNotifier::TNotificationHandler::TNotificationHandler() : 
   730 CCalenNotifier::TNotificationHandler::TNotificationHandler() : 
   357                 iHashSet(&::HashCalenNotificationFunction,&::HashCalenNotificationIdentityRelation)
   731                 iHashSet(&::HashCalenNotificationFunction,&::HashCalenNotificationIdentityRelation)
   358     {
   732     {
   359     OstTraceFunctionEntry0( TNOTIFICATIONHANDLER_TNOTIFICATIONHANDLER_ENTRY );
   733     TRACE_ENTRY_POINT;
   360     
   734     TRACE_EXIT_POINT;
   361     OstTraceFunctionExit0( TNOTIFICATIONHANDLER_TNOTIFICATIONHANDLER_EXIT );
   735     }
   362     }
   736 
       
   737 // ----------------------------------------------------------------------------
       
   738 // CCalenNotifier::CalendarInfoChangeNotificationL()
       
   739 // Handle calendar file change notifications
       
   740 // ----------------------------------------------------------------------------
       
   741 void CCalenNotifier::CalendarInfoChangeNotificationL( 
       
   742         RPointerArray<CCalFileChangeInfo>& aCalendarInfoChangeEntries)
       
   743 	{
       
   744 	TRACE_ENTRY_POINT;
       
   745 
       
   746 	// get the file change count
       
   747 	TInt calenInfoChangeCount = aCalendarInfoChangeEntries.Count();
       
   748 
       
   749 	for(TInt index = 0;index < calenInfoChangeCount;index++)
       
   750 		{
       
   751 		//get the context and set the calendar filename which triggered the
       
   752 		// notification
       
   753 		MCalenContext &context = iController.Services().Context();
       
   754 		context.SetCalendarFileNameL(
       
   755 				aCalendarInfoChangeEntries[index]->FileNameL());
       
   756 		
       
   757 		MCalFileChangeObserver::TChangeType changeType = 
       
   758 					aCalendarInfoChangeEntries[index]->ChangeType();
       
   759 		switch(changeType)
       
   760 			{
       
   761 			case MCalFileChangeObserver::ECalendarFileCreated:
       
   762 			    {
       
   763 			   TFileName lastCreatedFileName = aCalendarInfoChangeEntries[index]->FileNameL();
       
   764                CRepository* cenRep = CRepository::NewLC(KCRUidCalendar); 
       
   765                User::LeaveIfError( cenRep->Set( KCalendarLastUsedCalendar, lastCreatedFileName ) );
       
   766                CleanupStack::PopAndDestroy( cenRep );
       
   767 			    }
       
   768 			case MCalFileChangeObserver::ECalendarInfoCreated:
       
   769 				{
       
   770 				BroadcastNotification(ECalenNotifyDeleteInstanceView);
       
   771 				BroadcastNotification(ECalenNotifyCalendarInfoCreated);
       
   772 				}
       
   773 				break;
       
   774 			case MCalFileChangeObserver::ECalendarFileDeleted:
       
   775 				{
       
   776 				BroadcastNotification(ECalenNotifyCalendarFileDeleted);
       
   777 				}
       
   778 				break;
       
   779 			case MCalFileChangeObserver::ECalendarInfoUpdated:
       
   780 			case MCalFileChangeObserver::ECalendarInfoDeleted:
       
   781 				{
       
   782 				TFileName calFileName = aCalendarInfoChangeEntries[index]->FileNameL();
       
   783                 CCalSession* session = NULL;
       
   784                 TRAPD(err, session = &iGlobalData->CalSessionL( calFileName ));
       
   785                 if(KErrNotFound == err && ECalendarInfoUpdated == changeType)
       
   786                     {
       
   787                     BroadcastNotification(ECalenNotifyDeleteInstanceView);
       
   788                     BroadcastNotification(ECalenNotifyCalendarInfoCreated);
       
   789                     break;
       
   790                     }
       
   791 				
       
   792 				CCalCalendarInfo* calendarInfo = session->CalendarInfoL();
       
   793                 CleanupStack::PushL(calendarInfo);
       
   794 
       
   795                 TBuf8<KBuffLength> keyBuff;
       
   796                 keyBuff.AppendNum(EMarkAsDelete);
       
   797 
       
   798                 TBool markAsdelete;
       
   799                 TPckgC<TBool> pkgMarkAsDelete(markAsdelete);
       
   800                 TRAP(err,pkgMarkAsDelete.Set(calendarInfo->PropertyValueL(keyBuff)));
       
   801                 markAsdelete = pkgMarkAsDelete();
       
   802 
       
   803                 CleanupStack::PopAndDestroy(calendarInfo);
       
   804 
       
   805                 //remove calendar except default calendar
       
   806                 if (err == KErrNone && markAsdelete
       
   807                         && aCalendarInfoChangeEntries[index]->FileNameL().CompareF(
       
   808                                 iGlobalData->CalSessionL().DefaultFileNameL()))
       
   809                     {
       
   810                     iFilnameDeleted = aCalendarInfoChangeEntries[index]->FileNameL().AllocL();
       
   811                     BroadcastNotification(ECalenNotifyDeleteInstanceView);
       
   812                     iGlobalData->RemoveCalendarL(iFilnameDeleted->Des());
       
   813                     BroadcastNotification(ECalenNotifyCalendarFileDeleted);
       
   814                                        
       
   815                     delete iFilnameDeleted;
       
   816                     iFilnameDeleted = NULL;
       
   817                     }
       
   818                 else
       
   819                     {
       
   820                     BroadcastNotification(ECalenNotifyCalendarInfoUpdated);
       
   821                     }
       
   822                 }
       
   823 				break;
       
   824 			default:
       
   825 				break;
       
   826 			}
       
   827 		context.ResetCalendarFileName();
       
   828 		}
       
   829 
       
   830 	TRACE_EXIT_POINT;
       
   831 	}
       
   832 
   363 
   833 
   364 // End of file
   834 // End of file