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