Contact View that would let user select from a list of numbers
| Tue, 2005-06-07 09:06 | |
|
Hello Experts!
I would like to ask help.. I have here a code that would display the list of contacts from the phone memory.. however, i want to further enhance it.. the problem with this code is that even though if a contact has many mobile numbers it would return immidiately the first which is +639201234567 (based from the example below). ex: Name: John Smith Mobile Number: +639201234567 Mobile Number: +639179876543 i want it to display and enumerate the numbers of the contact, then let the user choose one.. Here's the code: void CQuickSMSContainer::PromptForContactL() { TInt aOk=0; _LIT (KStringHeader, "\t%S\t\t"); TBuf <60> aString; TBuf <50> txtname; TBuf <220> dummytxt; TBuf <50> dummyphone; // open the contact database CContactDatabase* contactDatabase = NULL; contactDatabase = CContactDatabase::OpenL(); // create an array to store the contact names CDesCArrayFlat* itemArray = new (ELeave) CDesCArrayFlat(10); // set the contact db view to look only at contacts (not groups) contactDatabase->SetDbViewContactType(KUidContactCard); // sort the contacts by last name and first name CArrayFixFlat<CContactDatabase::TSortPref>* aSortOrder = new CArrayFixFlat<CContactDatabase::TSortPref>(2); //CleanupStack::PushL(aSortOrder); aSortOrder->SetReserveL(2); TFieldType fieldType = KUidContactFieldFamilyName; CContactDatabase::TSortPref::TOrder order=CContactDatabase::TSortPref::EAsc; CContactDatabase::TSortPref sortPref1(fieldType,order); aSortOrder->AppendL(sortPref1); fieldType = KUidContactFieldGivenName; CContactDatabase::TSortPref sortPref2(fieldType,order); aSortOrder->AppendL(sortPref2); contactDatabase->SortByTypeL(aSortOrder); const CContactIdArray* iContactIdArray = contactDatabase->SortedItemsL(); iPbkContactEngine = CPbkContactEngine::NewL(); CPbkContactItem* contact; if (iContactIdArray->Count() > 0) { for (TInt i = 0; i < iContactIdArray->Count();++i) { TContactItemId Id = (*iContactIdArray)[i]; contact = iPbkContactEngine->ReadContactLC(Id); HBufC* name=contact->GetContactTitleL(); dummytxt.Copy(name->Des()); if (dummytxt.Length()>50) { txtname.Copy(dummytxt.Ptr(),50); } else { txtname.Copy(dummytxt); } aString.Format(KStringHeader(),&txtname); CleanupStack::PopAndDestroy(contact); delete name; itemArray->AppendL(aString); } } if (itemArray->Count() > 0) { CAknSelectionListDialog* dlg; TInt index = 0; dlg = CAknSelectionListDialog::NewL(index, itemArray,R_LISTDLG_MENU_BAR); dlg->SetupFind(CAknSelectionListDialog::EPopupFind); if (dlg->ExecuteLD(R_CONTACT_SELECTION_LIST_DIALOG)) { if ((index>=0)&&(index<itemArray->Count())) { const TContactItemId& choseContactId =(*iContactIdArray)[index]; contact = iPbkContactEngine->ReadContactLC(choseContactId); HBufC* name = contact->GetContactTitleL(); dummytxt.Copy(name->Des()); if (dummytxt.Length()>50) { nName.Copy(dummytxt.Ptr(),50); } else { nName.Copy(dummytxt); } TPbkContactItemField* phoneNumber=NULL; phoneNumber = contact->FindField(EPbkFieldIdPhoneNumberMobile); if (phoneNumber==NULL) { phoneNumber = contact->FindField(EPbkFieldIdPhoneNumberGeneral); phoneNumber->GetTextL(dummyphone); } else { phoneNumber->GetTextL(dummyphone); } if (dummyphone.Length()>20) { nPhone.Copy(dummyphone.Ptr(),20); } else { nPhone.Copy(dummyphone); } phoneNumber=NULL; delete name; name=NULL; CleanupStack::PopAndDestroy(contact); aOk=1; } else { aOk=0; } } else { aOk=0; } } delete itemArray; aSortOrder->Reset(); delete contactDatabase; contactDatabase=NULL; delete iPbkContactEngine; iPbkContactEngine=NULL; if (aOk==1) { nName.TrimRight(); nPhone.TrimRight(); //Name has been selected. Name and Number will be saved in nName and nPhone. } else { //contact selection canclelled } } -------------------- nName and nPhone are stored globally.. nName contains the name of the contact selected.. nPhone contains the number of the contact selected.. what should i add and where? Tnx!! |
|






Forum posts: 6
Hello
I have seen your excellent code for showing the contacts list, and let the user choose one from.
But i need the resource structures of
R_CONTACT_SELECTION_LIST_DIALOG
R_LISTDLG_MENU_BAR
u used in ur example,
and if u can send me the working example, i will much thankful..
Hope you send it to me if u don't mind, and i am sure u don't.
Thanx very much dear.
Khalid