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