calendarui/globaldata/src/calendbchangenotifier.cpp
branchRCL_3
changeset 30 d68a4b5d5885
parent 20 21239b3bcd78
child 59 aba12c885d83
equal deleted inserted replaced
27:55d60436f00b 30:d68a4b5d5885
    19 
    19 
    20 //debug
    20 //debug
    21 #include "calendarui_debug.h"
    21 #include "calendarui_debug.h"
    22 
    22 
    23 // INCLUDE FILES
    23 // INCLUDE FILES
       
    24 #include "CleanupResetAndDestroy.h"
    24 #include "calendbchangenotifier.h"    // CCalenDbChangeNotifier
    25 #include "calendbchangenotifier.h"    // CCalenDbChangeNotifier
    25 #include "calenglobaldata.h"            // Calendar global data
    26 #include "calenglobaldata.h"            // Calendar global data
    26 #include <calsession.h>                 // CalSession
    27 #include <calsession.h>                 // CalSession
       
    28 #include <missedalarm.h>
       
    29 #include <missedalarmstore.h>
       
    30 #include <missedalarmstorecrkeys.h>
       
    31 #include <calcalendarinfo.h>
    27 
    32 
    28 // -----------------------------------------------------------------------------
    33 // -----------------------------------------------------------------------------
    29 // KTimerResolution limits the number of notifications sent to registered
    34 // KTimerResolution limits the number of notifications sent to registered
    30 // MCalenDBChangeObserver instances.  Notifications may come from 
    35 // MCalenDBChangeObserver instances.  Notifications may come from 
    31 // MCalChangeCallBack2 at a very high rate which could impact performance, 
    36 // MCalChangeCallBack2 at a very high rate which could impact performance, 
   146 // CCalenDbChangeNotifier::CalChangeNotification
   151 // CCalenDbChangeNotifier::CalChangeNotification
   147 // Called when a change to the agenda database occurs from a different session
   152 // Called when a change to the agenda database occurs from a different session
   148 // to the one we are currently using.
   153 // to the one we are currently using.
   149 // (other items were commented in a header).
   154 // (other items were commented in a header).
   150 // -----------------------------------------------------------------------------
   155 // -----------------------------------------------------------------------------
   151 void CCalenDbChangeNotifier::CalChangeNotification( RArray<TCalChangeEntry>& /*aChangeItems*/ )
   156 void CCalenDbChangeNotifier::CalChangeNotification( RArray<TCalChangeEntry>& aChangeItems )
   152     {
   157     {
   153     TRACE_ENTRY_POINT;
   158     TRACE_ENTRY_POINT;
   154 
   159 
       
   160     TRAP_IGNORE(HandleMissedAlarmsL(aChangeItems));
   155     // Always update the last notification time, even if we don't notify 
   161     // Always update the last notification time, even if we don't notify 
   156     // our observers
   162     // our observers
   157     iLastDbChangeNotification.UniversalTime();
   163     iLastDbChangeNotification.UniversalTime();
   158     if( !IsActive() )
   164     if( !IsActive() )
   159         {
   165         {
   165         iRestartTimer = ETrue;
   171         iRestartTimer = ETrue;
   166         iNotificationTimer.Cancel();
   172         iNotificationTimer.Cancel();
   167         }
   173         }
   168 
   174 
   169     TRACE_EXIT_POINT;
   175     TRACE_EXIT_POINT;
       
   176     }
       
   177 void CCalenDbChangeNotifier::HandleMissedAlarmsL(const RArray<TCalChangeEntry>& aChangeItems)
       
   178     {
       
   179     TRACE_ENTRY_POINT
       
   180     CRepository* missedAlarmStoreRepository = CRepository::NewL(
       
   181             KCRUidMissedAlarmStore);
       
   182     // Create missed alarm store
       
   183     CMissedAlarmStore* missedAlarmStore = CMissedAlarmStore::NewL(
       
   184             *missedAlarmStoreRepository);
       
   185     CleanupStack::PushL(missedAlarmStore);
       
   186     RPointerArray<CMissedAlarm> missedAlarmStorelist;
       
   187     CleanupResetAndDestroyPushL(missedAlarmStorelist);
       
   188     missedAlarmStore->GetL(missedAlarmStorelist);
       
   189     CCalCalendarInfo* calendarInfo = iSession.CalendarInfoL();
       
   190     CleanupStack::PushL(calendarInfo);
       
   191     CCalenDbChangeNotifier::TCalLuidFilename calLuidFilename;
       
   192     calLuidFilename.iFilename = calendarInfo->FileNameL();
       
   193     if (missedAlarmStorelist.Count())
       
   194         {
       
   195         for (TInt idx = 0; idx < aChangeItems.Count(); idx++)
       
   196             {
       
   197             if (aChangeItems[idx].iChangeType == EChangeDelete)
       
   198                 {
       
   199                 calLuidFilename.iLuid = aChangeItems[idx].iEntryId;
       
   200                 TInt index = missedAlarmStorelist.Find(
       
   201                         calLuidFilename,CCalenDbChangeNotifier::DoFindEntryByLuid);
       
   202                 if(index != KErrNotFound)
       
   203                     {
       
   204                     CMissedAlarm* missedAlarm = missedAlarmStorelist[index];
       
   205                     missedAlarmStore->RemoveL(*missedAlarm);
       
   206                     }
       
   207                 }
       
   208             }
       
   209         }
       
   210     CleanupStack::PopAndDestroy(calendarInfo);
       
   211     CleanupStack::PopAndDestroy(&missedAlarmStorelist);
       
   212     CleanupStack::PopAndDestroy(missedAlarmStore);
       
   213     TRACE_EXIT_POINT    
       
   214     }
       
   215 TBool CCalenDbChangeNotifier::DoFindEntryByLuid(
       
   216                 const TCalLuidFilename* aLuidFilename,const CMissedAlarm& aMissedAlarm)
       
   217     {
       
   218     TRACE_ENTRY_POINT
       
   219     TRACE_EXIT_POINT
       
   220     return (aLuidFilename->iLuid == aMissedAlarm.iLuid 
       
   221             && !aLuidFilename->iFilename.CompareF(aMissedAlarm.iCalFileName));
   170     }
   222     }
   171 
   223 
   172 // -----------------------------------------------------------------------------
   224 // -----------------------------------------------------------------------------
   173 // CCalenDbChangeNotifier::RegisterObserverL
   225 // CCalenDbChangeNotifier::RegisterObserverL
   174 // Adds the passed observer to the observer array.  All observers in the array 
   226 // Adds the passed observer to the observer array.  All observers in the array