Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Identifying and retrieving the fields in a vCard using Symbian C++

From Wiki
Jump to: navigation, search


Article Metadata
Tested with
Devices(s): Nokia 5630
Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP2
S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
Article
Keywords: CParserVCard, CParserProperty, CParserPropertyValueHBufC, CParserPropertyValueCDesCArray
Created: User:Kbwiki (22 Sep 2010)
Last edited: hamishwillee (01 Aug 2012)

Contents

Description

The different fields in a vCard (such as name, telephone number, address) associated with a contact can be identified and retrieved using the CParserVCard API. A typical vCard will have the following fields:

BEGIN:VCARD
VERSION:2.1
N:Contact;Test
FN:Test Contact
ORG:Test_org
TITLE:Test_title
NOTE;ENCODING=QUOTED-PRINTABLE:Location :Test_location;Tower:Test_tower;Wing:No Wing;Floor:Test_floor;
TEL;WORK;VOICE:<xxxxx>
TEL;HOME;VOICE:<xxxxx>
TEL;CELL;VOICE:<xxxxx>
TEL;HOME:<xxxxx>
ADR;WORK:;;;<org>;<city>;<pin>;
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:<org>, <city>, <PIN>
EMAIL;PREF;INTERNET:<e-mail>
REV:20100701T044256Z
END:VCARD


MMP File

CAPABILITY ReadUserData WriteUserData
LIBRARY vcard.lib 
LIBRARY versit.lib 

Header Files

#include <vcard.h>
#include <VPROP.H>

Source File

The following code snippet can be used for parsing the vCard to get the required fields. CParserVCard is the class for parsing the contents of a vCard and the CParserProperty class is used for identifying the various properties like N, FN, TEL, and so on.

 RFs fileSession;
RFile file;
User::LeaveIfError(fileSession.Connect());
CleanupClosePushL(fileSession);
//save the vcard in some temporary location
_LIT(KFileName, "c:\\data\\testcontact.vcf");
if (file.Open(fileSession, KFileName, EFileRead) != KErrNone)
{
//failed to open the file
CleanupStack::PopAndDestroy(); //fileSession
}
CleanupClosePushL(file);
//open a read stream to the file
RFileReadStream inputFileStream(file);
CleanupClosePushL(inputFileStream);
//parser for parsing the contents of vcard
CParserVCard* vCardParser = CParserVCard::NewL();
CleanupStack::PushL(vCardParser);
//Internalize the vCard entity
vCardParser->InternalizeL(inputFileStream);
CArrayPtr<CParserProperty>* properties = vCardParser->ArrayOfProperties(EFalse);
CleanupStack::PushL(properties);
//Access the fields of vCard using the CParserProperty class
for(TInt i=0;i<properties->Count();i++)
{
//Retrieve the property name
TPtrC8 name = properties->operator[](i)->Name();
//match for the specific property
if(name.Match(_L8("TEL"))==KErrNone)
{
//Retrieve the corresponding value
CParserPropertyValueHBufC* value = static_cast<CParserPropertyValueHBufC*>(properties->operator[](i)->Value());
CleanupStack::PushL(value);
TPtrC val_ptr = value->Value();
buf.Copy(val_ptr);
CleanupStack::Pop(value);
}
if(name.Match(_L8("N"))==KErrNone)
{
//if multiple entries in a single field exist then use CParserPropertyValueCDesCArray
CParserPropertyValueCDesCArray* value = static_cast<CParserPropertyValueCDesCArray*>(properties->operator[](i)->Value());
CleanupStack::PushL(value);
CDesCArray* aArr = value->Value();
for(TInt k=0;k<aArr->Count();k++)
{
TPtrC val = aArr->operator [](k);//k=0 gives last name;k=1 gives first name
}
CleanupStack::Pop(value);
}
}
CleanupStack::Pop(properties);
file.Close();
CleanupStack::PopAndDestroy(vCardParser);
CleanupStack::PopAndDestroy(3);//inputFileStream, file, fileSession

The other fields corresponding to Full Name(FN), EMAIL, ORG, ADR can also be retrieved in a similar fashion.

This page was last modified on 1 August 2012, at 04:40.
31 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×