Contacts database events

A client application of the Contacts Server can be set to observe changes in the contacts database. When a change in the database occurs, the application gets an event. The event carries information about the type of the event, the contact ID, and the connection ID.

      
       
      
      struct TContactDbObserverEvent
    {
    TContactDbObserverEventType iType;
    TContactItemId iContactId;
    TUint iConnectionId;
    };
     

The following event types are defined in the cntdbobs.h :

      
       
      
      enum TContactDbObserverEventType
    {
    EContactDbObserverEventNull,
    EContactDbObserverEventUnused,
    EContactDbObserverEventContactChanged,
    EContactDbObserverEventContactDeleted,
    EContactDbObserverEventContactAdded,
    EContactDbObserverEventUnknownChanges,
    EContactDbObserverEventRecover,
    EContactDbObserverEventRollback,
    EContactDbObserverEventTablesClosed,
    EContactDbObserverEventTablesOpened,
    EContactDbObserverEventTemplateChanged,
    EContactDbObserverEventTemplateDeleted,
    EContactDbObserverEventTemplateAdded,
    EContactDbObserverEventCurrentItemDeleted,
    EContactDbObserverEventCurrentItemChanged,
    EContactDbObserverEventOwnCardChanged,
    EContactDbObserverEventPreferredTemplateChanged,
    EContactDbObserverEventOwnCardDeleted,
    EContactDbObserverEventGroupAdded,
    EContactDbObserverEventGroupChanged,
    EContactDbObserverEventGroupDeleted,
    EContactDbObserverEventCurrentDatabaseChanged,
    EContactDbObserverEventSpeedDialsChanged
    EContactDbObserverEventSortOrderChanged,
    EContactDbObserverEventBackupBeginning,
    EContactDbObserverEventRestoreBeginning,
    EContactDbObserverEventBackupRestoreCompleted,
    EContactDbObserverEventRestoreBadDatabase,
    };
     

To receive events on contact database changes, the application must derive MContactDbObserver base class and implement MContactDbObserver::HandleDatabaseEventL() virtual function. The function is called by the system when a contact database event occurs.

      
       
      
      class CMyContactObserver : public CBase, public MContactDbObserver
    {
     public:
         // any public data and functions
         CMyContactObserver ();
         // override the virtual function from the base class
         virtual void HandleDatabaseEventL( TContactDbObserverEvent aEvent );
         };
     // handling contact database events
     void CMyContactObserver::HandleDatabaseEventL( TContactDbObserverEvent aEvent )
         {
         // Event handling code
         }
     

In addition, the application must create the CContactChangeNotifier object to register itself to receive events.

      
       
      
      CContactDatabase* contactDb = CContactDatabase::OpenL();
//iContactDbObserver is a CMyContactObserver pointer
CContactChangeNotifier* notifier = CContactChangeNotifier::NewL( *contactDb, iContactDbObserver );