×
Namespaces

Variants
Actions

Observing changes in the Contacts database using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

How to observer changes in the Contacts database.

Article Metadata
Compatibility
Platform(s): S60 1st Edition
S60 2nd Edition
S60 2nd Edition (initial release)
S60 1st Edition
Article
Created: User:Technical writer 2 (14 May 2003)
Last edited: hamishwillee (03 Dec 2012)


Description

This is a simplified example of the code lines needed for the Contacts observer.

// Application UI owns contact observer
class CEventsAppUi : public CEikAppUi
{
public:
void ConstructL();
~CEventsAppUi();
public:
void HandleCommandL(TInt aCommand);
private:
CEventsAppView* iAppView; // owns
CEventsContacts* iContactObserver;
};
void CEventsAppUi::ConstructL()
{
BaseConstructL(); // Call base constructor
iAppView = CEventsAppView::NewL(ClientRect());
AddToStackL(iAppView);
// Create an observer
iContactObserver = new(ELeave) CEventsContacts(iAppView);
iContactObserver->ConstructL();
}
// CEventsContacts implements MContactDbObserver interface
class CEventsContacts : public CBase, public MContactDbObserver
{
public:
CEventsContacts(CEventsAppView* aAppView);
void ConstructL();
~CEventsContacts();
// Override the virtual function of MContactDbObserver
void HandleDatabaseEventL(TContactDbObserverEvent aEvent);
private:
CContactDatabase* iContactDb;
CContactChangeNotifier* iNotifier;
CEventsAppView* iAppView;
};
CEventsContacts::CEventsContacts(CEventsAppView* aAppView)
:iAppView(aAppView)
{
}
void CEventsContacts::ConstructL()
{
// Open the database
iContactDb = CContactDatabase::OpenL();
// Register the observer
iNotifier = CContactChangeNotifier::NewL(*iContactDb, this);
}
CEventsContacts::~CEventsContacts()
{
delete iNotifier;
delete iContactDb;
}
void CEventsContacts::HandleDatabaseEventL(TContactDbObserverEvent
aEvent)
{
// The changed item
TContactItemId contactItem = aEvent.iContactId;
switch (aEvent.iType)
{
case EContactDbObserverEventContactChanged:
// Handle contact changed event
break;
case EContactDbObserverEventContactDeleted:
// Handle contact deleted event
break;
...
default:
break;
}
}
This page was last modified on 3 December 2012, at 10:05.
55 page views in the last 30 days.