To add and delete the listening Symbian Address Book, I found the following code about the address book listening:
This is a simplified example of the code lines needed for the contacts observer. (from Nokia Technical Library)
// Application UI owns contact observer
Class ceventsappui: Public ceikappui
{
Public:
Void constructl ();
~ Ceventsappui ();
Public:
Void handlecommandl (tint acommand );
PRIVATE:
Ceventsappview * iappview; // owns
Ceventscontacts * icontactobserver; // data observer
};
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;
Case econtactdbobservereventcontactadded
// Handle contact added event
Break;
...
Default:
Break;
}
}
Integrate the code into my program and add library cntmodel. Lib // For contact to the matrix containing the header file # include <cntdbobs. h>
# Include <cntdb. h> # include <cntdef. h> where cntdbobs. h defines tcontactdbobserverevent
The following error occurs:
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdbobs. h: 96: Undefined identifier 'tcontactitemid'
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdbobs. h: 96: (encoded ded from:
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdbobs. h: 96: C:/Symbian/carbide/workspace/helloworld/INC/eventscontacts. h: 17
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdbobs. h: 96: C:/Symbian/carbide/workspace/helloworld/INC/helloworldappui. h: 15
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdbobs. h: 96: C:/Symbian/carbide/workspace/helloworld/src/helloworlddocument. cpp: 11)
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: identifier 'tcontactitemid' redeclared
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: was declared as: 'int'
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: Now declared as: 'Long'
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: (encoded ded from:
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdb. h: 13
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: C:/Symbian/carbide/workspace/helloworld/INC/eventscontacts. h: 18
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: C:/Symbian/carbide/workspace/helloworld/INC/helloworldappui. h: 15
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: C:/Symbian/carbide/workspace/helloworld/src/helloworlddocument. cpp: 11)
../Src/helloworldappui. cpp: 299: Warning: Preprocessor # warning Directive
../Src/helloworldappui. cpp: 299: Warning: # warning "Please see comment about help and uid3 ..."
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdbobs. h: 96: Undefined identifier 'tcontactitemid'
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: identifier 'tcontactitemid' redeclared
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: was declared as: 'int'
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: Now declared as: 'Long'
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: (encoded ded from:
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdb. h: 13
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: C:/Symbian/carbide/workspace/helloworld/INC/eventscontacts. h: 18
C:/Symbian/9.1/s60_3rd_mr/epoc32/include/cntdef. h: 71: C:/Symbian/carbide/workspace/helloworld/src/eventscontacts. cpp: 11)
../Src/eventscontacts. cpp: 56: Undefined identifier 'icontactid'
This is obviously a redefinition, but I don't know which file has defined my own things for a long time and it hasn't solved the problem.
I don't know which header file is redundant.
The header file # include <cntdbobs. h> remove the content defined in the two header files to avoid conflict. Because today there is no time to write the response code. I don't know which header file should be removed, but I find that the header file is not all required, even if you find which one it's not always useful.
Lessons learned