×
Namespaces

Variants
Actions

如何监测名片夹数据库的变化

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
User:Jiangbaolan 在 02 Apr 2009 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

下面提供一段代码示例如何监测名片夹的变化

Code: // 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 15 December 2011, at 09:35.
27 page views in the last 30 days.