Symbian Address Book)

Source: Internet
Author: User

Symbian OS Address Book Model
the address book of Symbian OS is stored as a file. In Symbian, the address book database is used. Each Symbian OS mobile phone has a default Address Book database, which has different locations in the 2nd and 3rd mobile phones. The former is c: \ System \ data \ contacts. CDB, Which is c: \ private \ 100012a5 \ dbs_100065ff_contacts.cdb.
the mobile phone Address Book of Symbian OS is developed based on the contacts model. The address book model consists of the address book database, address book entries (items), and address book domain. The relationship between them is that a mobile phone can contain multiple address book databases in addition to the default Address Book database provided by the system; an Address Book database consists of multiple address book entries, each of which is a single contact. The specific quantity limit varies with mobile phones. A address book entry consists of Multiple Address Book fields, such as name, work phone number, and home phone number. each item is a domain.
in order to unify the address book format, Symbian defines the domain by using the plaintext defined in the mime specification (RFC 1521) in vCard format.

Symbian OS address book operation API class
with the concept of contacts model, Symbian OS encapsulates many system API operations into several categories: ccontactdatabase (Database Class): In addition to basic database operations such as creation, opening, and closing, it is also responsible for database updates (the creation, modification, and deletion of address book entries can only be achieved through ccontactdatabase class operations), sorting and searching, and some other operations such as setting up a speed dial are also implemented through it.
ccontactitem (address book entry class): it is identified by a unique tcontactitemid (A tint32 macro definition) and is responsible for creating and modifying a specific address book entry, it directly manages each address book domain ccontactitemfield (domain class): each domain is a real and single data. The data type is determined by both the storage type (tstoragetype) and the domain type (tfieldtype, for the definition of the four Storage types and multiple domain types, see the system header file cntdef. h.
Of course, there are many other classes, such as ccontactitemfieldset, ccontactfieldstorage, and ccontacttextfields) mcontactdbobserver (Communication database observation class) and so on. It involves too much scope and cannot be clearly stated out of thin air. You can see the code in Code .

Symbian OS address book operation instance
Example 1 open and close a database
Ccontactdatabase: The openl () function has two overload functions. If this function does not provide a parameter, open the default Address Book database. You can also pass a database path and file name to open a specified address book database.
Ccontactdatabase * contactsdb = ccontactdatabase: openl ();
Cleanupstack: pushl (contactsdb );
Tint numberofcontacts = contactsdb-> countl ();
Cleanupstack: popanddestroy (contactsdb );

Example 2 create a database
Ccontactdatabase: createl (), ccontactdatabase: replacel (). Ccontactdatabase: createl () and

The only difference between ccontactdatabase: replacel () functions is that if the database already exists, the former exits with kerralreadyexists. As mentioned above, if no parameters are defined, these functions will create a default database.

Tfilename contactdbfilepath (_ L ("C: \ System \ data \ contacts. CDB "));
Ccontactdatabase * newdefacontcontactdb;
If (ccontactdatabase: findcontactfile (contactdbfilepath ))
Newdefacontcontactdb = ccontactdatabase: replacel ();
Else
Newdefacontcontactdb = ccontactdatabase: createl ();
Cleanupstack: pushl (newdefaultcontactdb );
Cleanupstack: popanddestroy (newdefacontcontactdb );

Example 3 read (traverse) address book entries

You can use the tcontactiter class (this class acts as a cursor in database operations) to traverse a communication record database. This class provides a complete set of functions for traversing all communication records. All functions are operated by tcontactitemid, which is used to access a specific communication record.

Ccontactdatabase * contactsdb = ccontactdatabase: openl ();
Cleanupstack: pushl (contactsdb );
Tcontactiter ITER (* contactsdb );
Tcontactitemid cardid;
While (cardid = ITER. nextl ())! = Knullcontactid)
{
Ccontactitem * card = contactsdb-> readcontactl (cardid );
Cleanupstack: pushl (card );
// Add your own function code
Contactsdb-> closecontactl (card-> ID ());
Cleanupstack: popanddestroy (); // card
}
Cleanupstack: popanddestroy (); // contactsdb

Example 4 Create an address book entry

_ Encrypt (kforenamelabel, "forename ");
_ Partition (ksurnamelabel, "surname ");
_ Queue (kworkphonelabel, "Work phone ");
_ Encrypt (kforename, "Steve ");
_ Partition (ksurname, "Wilkinson ");
_ Worker (kworkphone, "+ 441617779700 ");

Ccontactdatabase * contactdb = ccontactdatabase: openl ();
Cleanupstack: pushl (contactdb );

Ccontactitem * Contact = ccontactcard: newlc ();

Ccontactitemfield * field = ccontactitemfield: newlc (
Kstoragetypetext, kuidcontactfieldfamilyname );
Field-> setmapping (kuidcontactfieldvcardmapunusedn );
Field-> setlabell (ksurnamelabel );
Field-> textstorage ()-> settextl (ksurname );
Contact-> addfieldl (* field );
Cleanupstack: Pop ();

Field = ccontactitemfield: newlc (kstoragetypetext,
Kuidcontactfieldgivenname );
Field-> setmapping (kuidcontactfieldvcardmapunusedn );
Field-> setlabell (kforenamelabel );
Field-> textstorage ()-> settextl (kforename );
Contact-> addfieldl (* field );
Cleanupstack: Pop ();

Field = ccontactitemfield: newlc (kstoragetypetext,
Kuidcontactfieldphonenumber );
Field-> setmapping (kuidcontactfieldvcardmaptel );
Field-> setlabell (kworkphonelabel );
Field-> textstorage ()-> settextl (kworkphone );
Contact-> addfieldl (* field );
Cleanupstack: Pop ();

Contactdb-> addnewcontactl (* contact );
Contactdb-> setowncardl (* contact );
Cleanupstack: popanddestroy (2 );

Example 5 search for and update address book entries

This example is complex and involves the findasyncl lookup function. Such function instances include:
Ccontactidarray * ccontactdatabase: findlc (const tdesc & atext, const ccontactitemfielddef * afielddef );
Cidlefinder * ccontactdatabase: findasyncl (const tdesc & atext, const ccontactitemfielddef * afielddef, midlefindobserver * aobserver );
There are two groups of findintextdeflc () and findintextdefasyncl (). For details, see SDK.

Ccontactdatabase * icontactsdb = ccontactdatabase: openl ();
Cleanupstack: pushl (icontactsdb );
Ccontactitemfielddef * ifielddef =
New (eleave) ccontactitemfielddef ();
Cleanupstack: pushl (ifielddef );
Ifielddef-> appendl (kuidcontactfieldgivenname );
Ifielddef-> appendl (kuidcontactfieldfamilyname );
_ Token (kfindtoken, "Bond ");
_ Resolve (kotherforename, "Wilkinson ");
Cidlefinder * ifinder = icontactsdb-> findasyncl (kfindtoken,
Ifielddef, this );
Cleanupstack: pushl (ifinder );
If (ifinder-> iscomplete ())
{
If (ifinder-> error () = kerrnone)
{
Ccontactidarray * result = ifinder-> takecontactids ();
Cleanupstack: pushl (result );
For (tint I = 0; I <result-> count (); I ++)
{
Tcontactitemid cardid = (* result) [I];
Ccontactitem * owncard = icontactsdb-> opencontactl (cardid );
Cleanupstack: pushl (owncard );
Tint Index = owncard-> cardfields (). Find (kuidcontactfieldgivenname );
Owncard-> cardfields () [Index]. textstorage ()-> settextl (kotherforename );
Icontactsdb-> commitcontactl (* owncard );
Cleanupstack: popanddestroy (); // owncard
}
Cleanupstack: popanddestroy (); // result;
}
}
Cleanupstack: popanddestroy (3); // icontactsdb, ifielddef, ifinder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.