Getting Contact Database Change Event using Symbian C++
This article shows how to register for notification of Symbian contact database change events. To receive events we inherit from MContactDbObserver and implement the virtual function HandleDatabaseEventL() (this function is called when a contact database event occurs).
Article Metadata
If you are not familiar with Observer Pattern, see Observer
Header required:
#include <CNTDBOBS.H> //MContactDbObserver
#include <cntdb.h> // CContactDatabase, CContactChangeNotifier
Library needed:
LIBRARY cntmodel.lib // CContactDatabase, CContactChangeNotifier
Source code:
class CContactDatabaseObserver : public CBase, MContactDbObserver
{
public:
CContactDatabaseObserver();
// we need to override the virtual function from the base class //
virtual void HandleDatabaseEventL( TContactDbObserverEvent aEvent );
};
// Handle contact database events //
void CContactDatabaseObserver::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
{
switch(aEvent.iType)
{
//if any contact deleted in phonebook
case EContactDbObserverEventContactDeleted:
break;
//event if any contact changed
case EContactDbObserverEventContactChanged:
{}
break;
//event if any new contact added to phonebook
case EContactDbObserverEventContactAdded:
{}
break;
//check TContactDbObserverEventType for more events.
}
}
//We must also create the CContactChangeNotifier object to register itself to receive events.
CContactDatabase* ContactDatabase = CContactDatabase::OpenL();
// Here iContactDatabaseObserver is a CContactDatabaseObserver pointer //
CContactChangeNotifier* DatabaseNotifier =
CContactChangeNotifier::NewL(*ContactDatabase , this);// Changes by aamitgupta on date 5/06/2008


(no comments yet)