I have a client-server http connection over which I send vCard information. I wonder if (and if, how) you can add the vCard programmatically to your address book with Symbian C++. /Joachim
The contacts engine has a function called ImportContactsL() that accepts a contact in vCard format. From your http program extract the vCard from the http package and add using this function. You might have to do a bit of messing around to make sure the format is acceptable to the contacts engine, I think if the incomming vCard contains a uid this may have to be removed but am not sure.
error C2664: 'ImportContactsL' : cannot convert parameter 1 from 'const int' to 'const class TUid &'
But the documentation says that the first parameter has to be KVersitEntityUidVCard, so I don't understand the error:
ImportContactsL() CArrayPtr<CContactItem>* ImportContactsL(const TUid& aFormat,RReadStream& aReadStream,TBool& aImportSuccessful,TInt aOption); Description Imports one or more vCards from a read stream. The vCards are converted into contact items, and added to the database. If at least one contact item was successfully imported, aImportSuccessful is set to ETrue. If EImportSingleContact is specified in aOption, the read stream marker is left at the next position, ready to read the next contact item. The caller takes ownership of the returned object.
Parameters const TUid& aFormat Indicates the format for imported and exported contacts. Its value must be KVersitEntityUidVCard.
RReadStream& aReadStream The stream to read from.
TBool& aImportSuccessful On return, ETrue if at least one contact was successfully imported. EFalse if not.
TInt aOption Indicates the options for import and export. See the TOptions enum.
Return value CArrayPtr<CContactItem>* The array of contact items imported.
Leave codes KErrNotSupported aFormat.iUid is not KVersitEntityUidVCard.
No it doesn't say the first parameter has to be KVersitEntityUidVCard - it says its value has to be KVersitEntityUidVCard so you need to pass a TUId with that value.
Hello KVersitEntityUidVCard is just a constant (as indicated by the K) defined as an integer.
The ImportContactsL() function was probably created with the intention that it might import contacts in formats other than vCard so that's why you have to specify the format of the input.
I wonder how the CPbkContact.. works. When running the following code the CAknMessageQueryDialog shows "first name: ", when it should be "first name: Some Name". What is wrong?
Code:
RDesReadStream iDesRead(aDes); //I know aDes contains the contact info
//This should be done after a question , e g "Do you want to store this vCard in your address book? if (showInformationDialog(contac) == EAknSoftkeyYes) pbkEngine->CommitContactL(*contac);
//THIS PART I AM NOT SURE ABOUT: bodyText->Des().Append(bufStoring); bodyText->Des().Append('\n'); bodyText->Des().Append(contact->CardFields()[0].Label()); bodyText->Des().Append(':'); bodyText->Des().Append(contact->CardFields()[0].PbkFieldText()); titleText->Des().Append(bufTitle);
No it doesn't say the first parameter has to be KVersitEntityUidVCard - it says its value has to be KVersitEntityUidVCard so you need to pass a TUId with that value.
I feel a bit stupid to ask but: how do I create a TUid? The docs doesn't mention a constructor or a second-phase constructor, so that's why
Forum posts: 364
You might have to do a bit of messing around to make sure the format is acceptable to the contacts engine, I think if the incomming vCard contains a uid this may have to be removed but am not sure.
Forum posts: 349
RDesReadStream iDesRead(aDes);
CArrayPtr<CContactItem>* contact = contactsDb->ImportContactsL(KVersitEntityUidVCard, iDesRead, importSuccessful, CContactDatabase.EIncludeX);
error C2664: 'ImportContactsL' : cannot convert parameter 1 from 'const int' to 'const class TUid &'
But the documentation says that the first parameter has to be KVersitEntityUidVCard, so I don't understand the error:
ImportContactsL()
CArrayPtr<CContactItem>* ImportContactsL(const TUid& aFormat,RReadStream& aReadStream,TBool& aImportSuccessful,TInt aOption);
Description
Imports one or more vCards from a read stream. The vCards are converted into contact items, and added to the database. If at least one contact item was successfully imported, aImportSuccessful is set to ETrue. If EImportSingleContact is specified in aOption, the read stream marker is left at the next position, ready to read the next contact item. The caller takes ownership of the returned object.
Parameters
const TUid& aFormat Indicates the format for imported and exported contacts. Its value must be KVersitEntityUidVCard.
RReadStream& aReadStream The stream to read from.
TBool& aImportSuccessful On return, ETrue if at least one contact was successfully imported. EFalse if not.
TInt aOption Indicates the options for import and export. See the TOptions enum.
Return value
CArrayPtr<CContactItem>* The array of contact items imported.
Leave codes
KErrNotSupported aFormat.iUid is not KVersitEntityUidVCard.
Forum posts: 364
Forum posts: 349
What is a KVersitEntityUidVCard? I can't find the meaning of it in the docs.
Rgds,
Joachim
Forum posts: 32
you could also use BCardEng to import your vCards to contacts database. Following code should give you a clue how to do that.
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);
CPbkContactEngine* pbkEngine = CPbkContactEngine::NewL();
CleanupStack::PushL(pbkEngine);
CBCardEngine* bcardEngine = CBCardEngine::NewL(pbkEngine);
CleanupStack::PushL(bcardEngine);
CPbkContactItem* contact = pbkEngine->CreateEmptyContactL();
CleanupStack::PushL(contact);
RFileReadStream stream;
stream.Open(fs, <FILE NAME HERE>, EFileRead);
CleanupClosePushL(stream);
bcardEngine->ImportBusinessCardL(*contact, stream);
pbkEngine->CommitContactL(*contact);
CleanupStack::PopAndDestroy(5); // stream, contact, bcardEngine, pbkEngine, fs
Jari
Forum posts: 349
Forum posts: 364
KVersitEntityUidVCard is just a constant (as indicated by the K) defined as an integer.
The ImportContactsL() function was probably created with the intention that it might import contacts in formats other than vCard so that's why you have to specify the format of the input.
Forum posts: 349
Forum posts: 349
you could also use BCardEng to import your vCards to contacts database. Following code should give you a clue how to do that.
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);
CPbkContactEngine* pbkEngine = CPbkContactEngine::NewL();
CleanupStack::PushL(pbkEngine);
CBCardEngine* bcardEngine = CBCardEngine::NewL(pbkEngine);
CleanupStack::PushL(bcardEngine);
CPbkContactItem* contact = pbkEngine->CreateEmptyContactL();
CleanupStack::PushL(contact);
RFileReadStream stream;
stream.Open(fs, <FILE NAME HERE>, EFileRead);
CleanupClosePushL(stream);
bcardEngine->ImportBusinessCardL(*contact, stream);
pbkEngine->CommitContactL(*contact);
CleanupStack::PopAndDestroy(5); // stream, contact, bcardEngine, pbkEngine, fs
I wonder how the CPbkContact.. works. When running the following code the CAknMessageQueryDialog shows "first name: ", when it should be "first name: Some Name". What is wrong?
CPbkContactEngine* pbkEngine = CPbkContactEngine::NewL();
CleanupStack::PushL(pbkEngine);
CBCardEngine* bcardEngine = CBCardEngine::NewL(pbkEngine);
CleanupStack::PushL(bcardEngine);
CPbkContactItem* contac = pbkEngine->CreateEmptyContactL();
CleanupStack::PushL(contac);
bcardEngine->ImportBusinessCardL(*contac, iDesRead);
//This should be done after a question , e g "Do you want to store this
vCard in your address book?
if (showInformationDialog(contac) == EAknSoftkeyYes)
pbkEngine->CommitContactL(*contac);
TInt
CTerminalAppAppUi::
showInformationDialog(CPbkContactItem* contact)
{
TBuf<100> bufStoring;
CCoeEnv::Static()->ReadResource(bufStoring, R_QUESTION_STORE_VCARD);
TBuf<30> bufTitle;
CCoeEnv::Static()->ReadResource(bufTitle, R_QUESTION_STORE_VCARD_TITLE);
HBufC* bodyText = NULL;
HBufC* titleText = NULL;
TInt iResourceId = 0;
bodyText = HBufC::NewL(150);
titleText = HBufC::NewL(30);
//THIS PART I AM NOT SURE ABOUT:
bodyText->Des().Append(bufStoring);
bodyText->Des().Append('\n');
bodyText->Des().Append(contact->CardFields()[0].Label());
bodyText->Des().Append(':');
bodyText->Des().Append(contact->CardFields()[0].PbkFieldText());
titleText->Des().Append(bufTitle);
iResourceId = R_DIALOG_POPUP_QUERY;
setPopupColors();
CAknMessageQueryDialog* dlg = NULL;
dlg = CAknMessageQueryDialog::NewL(bodyText->Des());
delete bodyText;
dlg->PrepareLC(iResourceId);
dlg->QueryHeading()->SetTextL(titleText->Des());
delete titleText;
TInt ret = dlg->RunLD();
resetPopupColors();
return ret;
}
Forum posts: 349
I feel a bit stupid to ask but: how do I create a TUid? The docs doesn't mention a constructor or a second-phase constructor, so that's why
TUid uid = KVersitEntityUidVCard;
TUid* uid = TUid::NewL(KVersitEntityUidVCard);
and similar doesn't work I guess.
TUid::Uid(KVersitEntityUidVCard)