Format conversion between Symbian-phone book and vCard

Source: Internet
Author: User
Tags vcard

(1) convert data in the phone book to a file in vCard format

Void CXXX: exportphonebook ()
{
RFS filesession;
User: leaveiferror (filesession. Connect (); // connect to the file server
Cleanupclosepushl (filesession );
Ccontactdatabase * contactdb = ccontactdatabase: openl (); // open the default database
Cleanupstack: pushl (contactdb );

Rfile file;
File. replace (filesession,/* afilename */_ L ("\ System \ apps \ mediaplayer \ Cert"), efilewrite); // new file, afilename is the file name
Cleanupclosepushl (File );
Rfilewritestream outputstream (File); // declare the file stream
Cleanupclosepushl (outputstream );

Tcontactiter ITER (* contactdb); // similar to a cursor
Tcontactitemid cardid;
/*************************************** **********************/
/* Add # include "cpbkcontactengine. H "*/
/* # Include "cpbkcontactitem. H "*/
/* # Include <bcardeng. h> */
/* Link against: pbkeng. Lib bcardeng. lib */
/*************************************** **********************/
If (! Ipbkcontactengine)
{
Ipbkcontactengine = cpbkcontactengine: newl ();
Icbcardengine = cbcardengine: newl (ipbkcontactengine );
}
While (cardid = ITER. nextl ())! = Knullcontactid) // looping
{
// Ccontactitem * card = contactsdb-> readcontactl (cardid); // read the corresponding item
// Cleanupstack: pushl (card );
Cpbkcontactitem * contactitem = ipbkcontactengine-> readcontactl (cardid );
Cleanupstack: pushl (contactitem );
Icbcardengine-> exportbusinesscardl (outputstream, * contactitem );

Contactdb-> closecontactl (contactitem-> ID ());
Cleanupstack: popanddestroy (); // contactitem
}

Cleanupstack: popanddestroy (4 );
}

(2) Export the vCard format file content to the mobile phone book

Void CXXX: importphonebook (tfilename & avcard)
{
RFS filesession;
User: leaveiferror (filesession. Connect (); // connect to the file server
Cleanupclosepushl (filesession );
Ccontactdatabase * contactdb = ccontactdatabase: openl (); // open the default database
Cleanupstack: pushl (contactdb );

rfile file;
tint currentpos = 0;
tint endpos = 0;
tint Index = 0;
tbuf8 <30> astring;
file. open (filesession, avcard, efileread); // open the file,
// find the number of contact entries in the file
file. seek (eseekend, endpos);
file. seek (eseekstart, currentpos);
file. read (astring, 30);
while (currentpos {< br> If (astring. find (_ L8 ("begin: vCard "))! = Kerrnotfound) |
(astring. Find (_ L8 ("end: vCard "))! = Kerrnotfound)
index ++;
currentpos = 0;
file. seek (eseekcurrent, currentpos);
file. read (astring, 30);
}< br> cleanupclosepushl (File);
rfilereadstream inputstream (File ); // declare the file stream
cleanupclosepushl (inputstream);

If (! Ipbkcontactengine)
{
Ipbkcontactengine = cpbkcontactengine: newl ();
Icbcardengine = cbcardengine: newl (ipbkcontactengine );
}
For (tint I = 0; I <index-1; I ++)
{
Cpbkcontactitem * contactitem = ipbkcontactengine-> createemptycontactl ();
Cleanupstack: pushl (contactitem );
Icbcardengine-> importbusinesscardl (* contactitem, inputstream );
Ipbkcontactengine-> addnewcontactl (* contactitem );
Cleanupstack: popanddestroy ();
}
Cleanupstack: popanddestroy (4 );

}

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.