Symbian OS通讯录模型
2010-08-11 12:18:00 来源:WEB开发网_LIT(KForename,"Steve");
_LIT(KSurname,"Wilkinson");
_LIT(KWorkPhone,"+441617779700");
CContactDatabase* contactDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactDb);
CContactItem* contact = CContactCard::NewLC();
CContactItemField* field = CContactItemField::NewLC(
KStorageTypeText, KUidContactFieldFamilyName);
field->SetMapping(KUidContactFieldVCardMapUnusedN);
field->SetLabelL(KSurnameLabel);
field->TextStorage()->SetTextL(KSurname);
contact->AddFieldL(*field);
CleanupStack::Pop();
field = CContactItemField::NewLC(KStorageTypeText,
KUidContactFieldGivenName);
field->SetMapping(KUidContactFieldVCardMapUnusedN);
field->SetLabelL(KForenameLabel);
field->TextStorage()->SetTextL(KForename);
contact->AddFieldL(*field);
CleanupStack::Pop();
field = CContactItemField::NewLC(KStorageTypeText,
KUidContactFieldPhoneNumber);
field->SetMapping(KUidContactFieldVCardMapTEL);
field->SetLabelL(KWorkPhoneLabel);
field->TextStorage()->SetTextL(KWorkPhone);
contact->AddFieldL(*field);
CleanupStack::Pop();
contactDb->AddNewContactL(*contact);
contactDb->SetOwnCardL(*contact);
CleanupStack::PopAndDestroy(2);
例5 查找并更新通讯录条目
这个例子比较复杂,涉及的查找函数为FindAsyncL,该类函数实例有:
CContactIdArray * CContactDatabase::FindLC(const TDesC &aText, const CContactItemFieldDef *aFieldDef);
CIdleFinder * CContactDatabase::FindAsyncL(const TDesC &aText, const CContactItemFieldDef *aFieldDef, MIdleFindObserver *aObserver);
还有对应的FindInTextDefLC()和FindInTextDefAsyncL()各两组,具体参见sdk。
CContactDatabase* iContactsDb = CContactDatabase::OpenL();
更多精彩
赞助商链接