Adding vCard programmatically

Login to reply to this topic.
Fri, 2004-10-08 11:39
Joined: 2004-09-06
Forum posts: 349
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

Fri, 2004-10-08 17:51
Joined: 2004-07-10
Forum posts: 364
Re: Adding vCard programmatically
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.
Mon, 2004-10-11 20:31
Joined: 2004-09-06
Forum posts: 349
Error using ImportContactsL()
I have tried the following:
Code:
TBool importSuccessful;
RDesReadStream iDesRead(aDes);
CArrayPtr<CContactItem>* contact = contactsDb->ImportContactsL(KVersitEntityUidVCard, iDesRead, importSuccessful, CContactDatabase.EIncludeX);
But get the following compilation error:

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.
Tue, 2004-10-12 03:09
Joined: 2004-07-10
Forum posts: 364
Re: Error using ImportContactsL()
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.
Tue, 2004-10-12 05:14
Joined: 2004-09-06
Forum posts: 349
Adding vCard programmatically
Thanks mungbeans,

What is a KVersitEntityUidVCard? I can't find the meaning of it in the docs.

Rgds,
Joachim
Tue, 2004-10-12 07:41
Joined: 2003-09-29
Forum posts: 32
Adding vCard programmatically
Hi,

you could also use BCardEng to import your vCards to contacts database. Following code should give you a clue how to do that.
Code:
RFs fs;
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

Tue, 2004-10-12 09:04
Joined: 2004-09-06
Forum posts: 349
Adding vCard programmatically
Deleted
Tue, 2004-10-12 17:35
Joined: 2004-07-10
Forum posts: 364
Adding vCard programmatically
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.
Tue, 2004-10-12 18:35
Joined: 2004-09-06
Forum posts: 349
Adding vCard programmatically
Thanks again all for your replies and time! /Joachim
Fri, 2004-10-22 09:23
Joined: 2004-09-06
Forum posts: 349
How to use CPbkContact...
Quote from: Jari
Hi,

you could also use BCardEng to import your vCards to contacts database. Following code should give you a clue how to do that.
Code:
RFs fs;
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?
Code:
RDesReadStream iDesRead(aDes); //I know aDes contains the contact info

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;
}
Joachim
Sat, 2004-10-23 08:19
Joined: 2004-09-06
Forum posts: 349
Re: Error using ImportContactsL()
Quote from: mungbeans
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

TUid uid = KVersitEntityUidVCard;
TUid* uid = TUid::NewL(KVersitEntityUidVCard);

and similar doesn't work I guess.
Sun, 2004-10-24 19:29
Anonymous (not verified)
Forum posts: 2018
Re: Error using ImportContactsL()
Pass it in like this
TUid::Uid(KVersitEntityUidVCard)
  • Login to reply to this topic.