Read-only archive of the All About Symbian forum (2001–2013) · About this archive

CPbkContact

1 replies · 1,687 views · Started 22 October 2004

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?

RDesReadStream iDesRead(aDes);

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

I don't think there is anything wrong with your code. It is possible that there is something wrong with the vCard you are importing. Apparently, if the vCard parser can't read the card it returns an empty contact with no fields filled in. That may be why you are seeing nothing when you try to show the fields.
I had a similar problem and found that when I added \r\n (instead of just \n, i.e., CR-LF pairs instead of just LF) to the end of the vCard lines it fixed the problem. My code, similar to yours, could show the contact contents.
I recommend using the Phone Book application as a model. You can inspect the contact file it imports to see if your vCard format matches.

Jon Webb