The versit API provides support for exporting contact and calendar data
to a stream. For example, suppose you want to make changes to an existing
contact or calendar entry, and export the same to an external file store. To do
so, again create the appropriate parser objects. That is,
CParserVCard
and CParserVCal
objects
to export vCards and/or vCalendars. For more information on importing vCard and
vCalendar, refer to
How to Import Contact and Calendar Data.
Let us assume that, you want to add a new property to the vCard called
EMAIL with the parameters ENCODING and
CHARSET, and the property value of [email protected]. To do
so, you need to create objects of CParserProperty
, an
array of CParserParam
to hold parameter information, and
CParserPropertyValue
to hold the property values.
// String literals representing the property and its value.
_LIT(KPName,"EMAIL");
_LIT(KEmail,"[email protected]");
// String literals representing the property parameters and their values.
_LIT(KParam1,"ENCODING");
_LIT(KValue1,"QUOTED-PRINTABLE");
_LIT(KParam2,"CHARSET");
_LIT(KValue2,"US-ASCII");
CParserPropertyValue* value=CParserPropertyValueHBufC::NewL(KEmail); // The property value.
// Array to hold parameters of EMAIL property.
CArrayPtr<CParserParam>* arrayOfParams = new(ELeave)CArrayPtrFlat<CParserParam>(2);
// Parameters with their corresponding values are added to the array.
CParserParam* parserParam1=CParserParam::NewL(KParam1,KValue1);
arrayOfParams->AppendL(parserParam1);
CParserParam* parserParam2=CParserParam::NewL(KParam2,KValue2);
arrayOfParams->AppendL(parserParam2);
// Associate the property params and property value with the EMAIL property
CParserProperty* property=CParserProperty::NewL(*value,KPName,arrayOfParams);
// Finally add the EMAIL property to the vCard using the parser object.
vCardParser->AddPropertyL(property);
// Set the character set as ASCII (7-bit) for transformation.
vCardParser->SetDefaultCharSet(Versit::EUSAsciiCharSet);
Note that you should include proper error checks in the above given code before using it for production.
Once you have added the EMAIL property, you can externalize (export) the vCard. This time you have to open the file in write mode to externalize the vCard data.
TInt err = file.Replace(iFsSession, KVCardFileJIS, EFileWrite) // Replace the file with modified information.
// Check if there is any error reported before exporting the vCard.
if(err == KErrNone)
vCardParser->ExternalizeL(file);
Same procedure could be followed if you want to modify a vCalendar using
the CParserVCal
object.