本文整理汇总了C++中CContactDatabase::AddNewContactL方法的典型用法代码示例。如果您正苦于以下问题:C++ CContactDatabase::AddNewContactL方法的具体用法?C++ CContactDatabase::AddNewContactL怎么用?C++ CContactDatabase::AddNewContactL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CContactDatabase
的用法示例。
在下文中一共展示了CContactDatabase::AddNewContactL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateTestContactsL
void CTestResources::CreateTestContactsL()
{
// Create a few test contacts in the db
// - Creating 'prefix' results for 'an'
CContactCard* card;
CContactItemField* field;
card = CContactCard::NewLC();
field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
field->TextStorage()->SetTextL(_L("Annie"));
card->AddFieldL(*field);
CleanupStack::Pop(field);
iDb->AddNewContactL(*card);
CleanupStack::PopAndDestroy(card);
card = CContactCard::NewLC();
field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
field->TextStorage()->SetTextL(_L("Anne"));
card->AddFieldL(*field);
CleanupStack::Pop(field);
iDb->AddNewContactL(*card);
CleanupStack::PopAndDestroy(card);
card = CContactCard::NewLC();
field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
field->TextStorage()->SetTextL(_L("Andrew"));
card->AddFieldL(*field);
CleanupStack::Pop(field);
iDb->AddNewContactL(*card);
CleanupStack::PopAndDestroy(card);
// - Creating 'fullsearch' results for 'an'
card = CContactCard::NewLC();
field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
field->TextStorage()->SetTextL(_L("Christan"));
card->AddFieldL(*field);
CleanupStack::Pop(field);
iDb->AddNewContactL(*card);
CleanupStack::PopAndDestroy(card);
card = CContactCard::NewLC();
field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
field->TextStorage()->SetTextL(_L("Adan"));
card->AddFieldL(*field);
CleanupStack::Pop(field);
iDb->AddNewContactL(*card);
CleanupStack::PopAndDestroy(card);
}
示例2: TestResultL
void CAsyncTest::TestResultL()
{
CContactDatabase* db = iOpenOp->TakeDatabase();
if(db == NULL)
User::Leave(KErrNotFound);
// Test adding a contact
CContactItemViewDef* matchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
matchAll->AddL(KUidContactFieldMatchAll);
CContactItem* cntTemplate = db->ReadContactL(0, *matchAll);
CleanupStack::PopAndDestroy(matchAll);
CleanupStack::PushL(cntTemplate);
CCntItemBuilder* cntItemBldr = CCntItemBuilder::NewLC(static_cast<CContactTemplate&>(*cntTemplate));
CContactItem* tempCntItem = cntItemBldr->GetCntItemLC();
db->AddNewContactL(*tempCntItem);
CleanupStack::PopAndDestroy(tempCntItem);
CleanupStack::PopAndDestroy(cntItemBldr);
CleanupStack::PopAndDestroy(cntTemplate);
delete iOpenOp;
delete db;
iOpenOp = NULL;
db = NULL;
iTest->Next(_L("Read data from Database\n"));
}
示例3: AddEntryL
TContactItemId CPbTester::AddEntryL()
{
_LIT(KForename,"John");
_LIT(KSurname,"Smith");
_LIT(KPhoneNumber,"+441617779700");
// Create a contact card to contain the data
CContactCard* newCard = CContactCard::NewLC();
// Create the firstName field and add the data to it
CContactItemField* firstName = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
firstName->TextStorage()->SetTextL(KForename);
newCard->AddFieldL(*firstName);
CleanupStack::Pop(firstName);
// Create the lastName field and add the data to it
CContactItemField* lastName= CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
lastName ->TextStorage()->SetTextL(KSurname);
newCard->AddFieldL(*lastName);
CleanupStack::Pop(lastName);
// Create the phoneNo field and add the data to it
CContactItemField* phoneNumber = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber);
phoneNumber->SetMapping(KUidContactFieldVCardMapTEL);
phoneNumber ->TextStorage()->SetTextL(KPhoneNumber);
newCard->AddFieldL(*phoneNumber);
CleanupStack::Pop(phoneNumber);
// Add newCard to the database
const TContactItemId contactId = ipbDb->AddNewContactL(*newCard);
CleanupStack::PopAndDestroy(newCard);
return contactId;
}
示例4: doAddIccEntryL
/**
* Create an entry based on the template for this specific phonebook, and add
* the entry to the contact database
* @param aDb Contact database
* @param aPhonebookUid The phonebook uid
* @return TContactItemId Id of the newly created icc entry
*/
TContactItemId doAddIccEntryL(CContactDatabase& aDb,TUid aPhonebookUid)
{
syncChecker->ResetMethodCallCountsL();
TContactItemId templateId = aDb.ICCTemplateIdL(aPhonebookUid);
test(syncChecker->ValidateMethodCallCountL() == 1);
CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
CContactICCEntry* entry = CContactICCEntry::NewL(*iccTemplate);
CleanupStack::PopAndDestroy(iccTemplate);
CleanupStack::PushL(entry);
// Add to the database
CheckPhonebookField(*entry,aPhonebookUid, EFalse);
syncChecker->ResetMethodCallCountsL();
TContactItemId id = aDb.AddNewContactL(*entry);
test(syncChecker->ValidateMethodCallCountL() == 3);
CleanupStack::PopAndDestroy(entry);
test(id!=KNullContactId);
// Check group membership
syncChecker->ResetMethodCallCountsL();
CContactICCEntry* fetchedItem = static_cast<CContactICCEntry*>(aDb.ReadContactL(id));
test(syncChecker->ValidateMethodCallCountL() == 1);
CleanupStack::PushL(fetchedItem);
const CContactIdArray* owned = fetchedItem->GroupsJoined();
test(owned!=NULL && owned->Count() == 1);
test((*owned)[0]==syncChecker->GroupIdL(aPhonebookUid));
test(fetchedItem->Type() == KUidContactICCEntry);
// Verify that the phonebook field has been set
CheckPhonebookField(*fetchedItem,aPhonebookUid, ETrue);
CleanupStack::PopAndDestroy(fetchedItem);
return id;
}
示例5:
TContactItemId CTestResources::CreateTestContactL
(const TDesC& aFamilyName, TBool aWithPhoneNumber)
{
// Create a contact card
CContactCard* card = CContactCard::NewLC();
// Create a name field
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
field->TextStorage()->SetTextL(aFamilyName);
card->AddFieldL(*field);
CleanupStack::Pop(field);
// Create a phone number field
if (aWithPhoneNumber)
{
// Create a phone number field
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber);
field->TextStorage()->SetTextL(_L("555"));
card->AddFieldL(*field);
CleanupStack::Pop(field);
}
// Add the contact to the DB
const TContactItemId contactId = iDb->AddNewContactL(*card);
CleanupStack::PopAndDestroy(card);
// Eat away contact db events
TContactDbObserverEvent event;
while
(iDbEventQueue->ListenForEvent(10,event) &&
(event.iType != EContactDbObserverEventContactAdded ||
event.iContactId != contactId))
{
}
iTestContactId = contactId;
return contactId;
}
示例6: TestAddingWithoutGroupL
/**
* Test addition to database without adding to a group
* @param aDb Contact database
*/
void TestAddingWithoutGroupL(CContactDatabase& aDb)
{
TContactItemId templateId = aDb.ICCTemplateIdL(KUidIccGlobalAdnPhonebook);
CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
CContactICCEntry* entry = CContactICCEntry::NewL(*iccTemplate);
CleanupStack::PopAndDestroy(iccTemplate);
CleanupStack::PushL(entry);
SetNameL(*entry,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,KGivenName,EFalse);
SetNameL(*entry,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,KTelephoneNum,EFalse);
syncChecker->ResetMethodCallCountsL();
syncChecker->SetValidateWriteResponseL(KErrNone);
TInt oldGroupId = syncChecker->GroupIdL(KUidIccGlobalAdnPhonebook);
test(KErrNone == syncChecker->UpdatePhonebookGroupIdL(KUidIccGlobalAdnPhonebook, KNullContactId));
TContactItemId id = aDb.AddNewContactL(*entry);
test(syncChecker->ValidateMethodCallCountL() == 3);
CleanupStack::PopAndDestroy(entry);
CContactICCEntry* fetchedItem = static_cast<CContactICCEntry*>(aDb.ReadContactL(id));
CleanupStack::PushL(fetchedItem);
//Check group membership
const CContactIdArray* owned = fetchedItem->GroupsJoined();
test(owned==NULL || owned->Count() == 0);
CleanupStack::PopAndDestroy(fetchedItem);
test(KErrNone == syncChecker->UpdatePhonebookGroupIdL(KUidIccGlobalAdnPhonebook, oldGroupId));
}
示例7: CreateContactL
//Creates a contact item. Then adds it to the default contacts database.
LOCAL_D TLogContactItemId CreateContactL(const TDesC& aGivenName,
const TDesC& aFamilyName,
const TDesC& aPhoneNumber)
{
CContactItem* item=CContactCard::NewLC();
if (aFamilyName.Length())
SetNameL(*item, KUidContactFieldFamilyName, aFamilyName, ETrue);
if (aGivenName.Length())
SetNameL(*item, KUidContactFieldGivenName, aGivenName, ETrue);
if (aPhoneNumber.Length())
SetNameL(*item, KUidContactFieldPhoneNumber, aPhoneNumber, ETrue);
CContactItemFieldSet& fieldSet= item->CardFields();
TLogContactItemId id = KLogNullContactId;
if (fieldSet.Count())
{
// Open the DB for writing
CContactDatabase* TheContacts = CContactDatabase::OpenL();
CleanupStack::PushL(TheContacts);
id = TheContacts->AddNewContactL(*item);
CleanupStack::PopAndDestroy(); // TheContacts,
}
else
User::Leave(KErrNotSupported);
CleanupStack::PopAndDestroy(item);
return id;
}
示例8: AddContactsL
void CContactsRamTest::AddContactsL(const TInt aNumber)
/**
Add number of contacts to db, using the system template.
@return None
@param aNumber number of contacts to be added
@pre None
@post database now contains aNumber of empty contacts
*/
{
//viewdef that loads all fields
CContactItemViewDef *viewAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
viewAll->AddL(KUidContactFieldMatchAll);
CContactTemplate *ttemplate = static_cast< CContactTemplate* >(
iContactsDatabase->ReadContactLC( iContactsDatabase->TemplateId(), *viewAll ) );
CContactCard* contact = CContactCard::NewLC(ttemplate);
SetManyFieldsL(KFieldValue, KManyFields, contact->CardFields());
for(TInt k = 0; k<aNumber; k++)
{
iContactsDatabase->AddNewContactL(*contact);
}
CleanupStack::PopAndDestroy(contact);
CleanupStack::PopAndDestroy(ttemplate);
CleanupStack::PopAndDestroy(viewAll);
}
示例9: TestAddingContactCardL
/**
* Verify that adding contact cards doesn't call the synchroniser interface
* @param aDb Contact database
*/
void TestAddingContactCardL(CContactDatabase& aDb)
{
CContactCard* card = CContactCard::NewLC();
syncChecker->ResetMethodCallCountsL();
aDb.AddNewContactL(*card);
test(syncChecker->ValidateMethodCallCountL() == 0);
CleanupStack::PopAndDestroy(card);
}
示例10: TestSuccessfulAddL
/**
* Test successful addition to database.
* @param aDb Contact database
*/
void TestSuccessfulAddL(CContactDatabase& aDb)
{
//Create group
TContactItemId groupId = CreatePhonebookGroupL(aDb);
test(KErrNone == syncChecker->UpdatePhonebookGroupIdL(KUidIccGlobalAdnPhonebook, groupId));
//Create item and add fields
TContactItemId templateId = aDb.ICCTemplateIdL(KUidIccGlobalAdnPhonebook);
CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
CContactICCEntry* entry = CContactICCEntry::NewL(*iccTemplate);
CleanupStack::PopAndDestroy(iccTemplate);
CleanupStack::PushL(entry);
SetNameL(*entry,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,KGivenName,EFalse);
SetNameL(*entry,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,KTelephoneNum,EFalse);
//Add to database
syncChecker->ResetMethodCallCountsL();
syncChecker->SetValidateWriteResponseL(KErrNone);
syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
test(syncChecker->ValidateMethodCallCountL() == 0);
TContactItemId id = aDb.AddNewContactL(*entry);
CleanupStack::PopAndDestroy(entry);
test(syncChecker->ValidateMethodCallCountL() == 3);
test(id!=KNullContactId);
CContactICCEntry* fetchedItem = static_cast<CContactICCEntry*>(aDb.ReadContactL(id));
CleanupStack::PushL(fetchedItem);
//Check group membership
const CContactIdArray* owned = fetchedItem->GroupsJoined();
test(owned!=NULL && owned->Count() == 1);
test((*owned)[0]==groupId);
//Check number of fields and content
CContactItemFieldSet& fieldset = fetchedItem->CardFields();
TInt pos = fieldset.Find(KUidContactFieldTemplateLabel);
test(pos==KErrNotFound);
// test(fieldset.Count() == 3);
/* for (TInt i=0; i<fieldset.Count(); i++)
{
CContactItemField& field = fieldset[i];
TInt count = field.ContentType().FieldTypeCount();
for (TInt j=0; j<count; j++)
{
TFieldType ft= field.ContentType().FieldType(j);
}
TUid mapping = field.ContentType().Mapping();
}
*/
CheckFieldContentL(fieldset,KUidContactFieldFamilyName,KGivenName);
// CheckFieldContentL(fieldset,KUidContactFieldPhoneNumber,KTelephoneNum);
CleanupStack::PopAndDestroy(fetchedItem);
}
示例11: LongNumSpeedDialTestsL
LOCAL_C void LongNumSpeedDialTestsL()
{
_LIT(KLongNumSpeedDialTest, "Long Phone Number Speed Dial Test");
g_test.Start(KLongNumSpeedDialTest);
// create default, empty database
CContactDatabase* db = CContactDatabase::ReplaceL(KLongNumSpeedDialDbName);
CleanupStack::PushL(db);
// create a contact and add it to the db
CContactItem* contact = CContactCard::NewLC();
CContactItemField* fname = CContactItemField::NewLC(KStorageTypeText,
KUidContactFieldGivenName);
_LIT(KFname, "James");
fname->TextStorage()->SetTextL(KFname() );
contact->AddFieldL(*fname);
CleanupStack::Pop(fname);
CContactItemField* phone = CContactItemField::NewLC(KStorageTypeText,
KUidContactFieldPhoneNumber);
_LIT(KPhoneNum, "01234567890123456789012345678901234567890123456789012345678901234567890123456789"); // 80 chars
phone->TextStorage()->SetTextL(KPhoneNum() );
contact->AddFieldL(*phone);
CleanupStack::Pop(phone);
const TContactItemId KContactId = db->AddNewContactL(*contact);
CleanupStack::PopAndDestroy(contact);
contact = NULL;
// retrieve contact and assign its number to speed dial #1
contact = db->OpenContactL(KContactId);
CleanupStack::PushL(contact);
const TInt KSpeedDial1(1);
const TInt KPhoneNumIndex = contact->CardFields().Find(KUidContactFieldPhoneNumber);
db->SetFieldAsSpeedDialL(*contact, KPhoneNumIndex, KSpeedDial1);
TBuf<100> speedDialNumberText;
TContactItemId speedDialId = db->GetSpeedDialFieldL(KSpeedDial1, speedDialNumberText);
_LIT(KOutputFormat, "retrieved speed dial id: %d;\nretrieved speed dial phone number: ...\n%S\n");
g_test.Printf(KOutputFormat, speedDialId, &speedDialNumberText);
db->CloseContactL(KContactId);
// cleanup
CleanupStack::PopAndDestroy(2, db); // and contact
CContactDatabase::DeleteDatabaseL(KLongNumSpeedDialDbName);
// Since PDEF121954, long phone numbers set as speed dial are truncated to
// the length of KSpeedDialPhoneLength. So, we need to get the truncated
// version of the phone number for comparison with the speed dial value.
TPtrC phoneNum(KPhoneNum().Mid(0, KSpeedDialPhoneLength));
g_test(speedDialId == KContactId && speedDialNumberText.CompareC(phoneNum) == 0);
g_test.End();
g_test.Close();
}
示例12: AddFieldToContactL
LOCAL_C TContactItemId CreateTestContactL
(CContactDatabase& aDb,
const TDesC& aFamilyName,
const TDesC& aGivenName,
const TDesC& aCompanyName)
{
CContactCard* card = CContactCard::NewLC();
AddFieldToContactL(*card, KUidContactFieldFamilyName, aFamilyName);
AddFieldToContactL(*card, KUidContactFieldGivenName, aGivenName);
AddFieldToContactL(*card, KUidContactFieldCompanyName, aCompanyName);
const TContactItemId id = aDb.AddNewContactL(*card);
CleanupStack::PopAndDestroy(card);
return id;
}
示例13: AddContactCardL
/**
* Verify that adding contact cards doesn't call the synchroniser interface
* @param aDb Contact database
*/
TContactItemId AddContactCardL(CContactDatabase& aDb)
{
_LIT(KTemplateName,"contact card template");
RArray<TFieldEntry> entries=fieldSetForPhonebook(KUidIccGlobalAdnPhonebook);
TContactItemId templateId=CreatePhonebookTemplateL(aDb,KTemplateName,entries);
entries.Close();
CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
CContactCard* card = CContactCard::NewLC(iccTemplate);
syncChecker->ResetMethodCallCountsL();
TContactItemId id=aDb.AddNewContactL(*card);
test(syncChecker->ValidateMethodCallCountL() == 0);
CleanupStack::PopAndDestroy(2,iccTemplate);
return id;
}
示例14: PopulateDatabaseL
void DbCreator::PopulateDatabaseL(CContactDatabase& aDb, TInt aNumContacts)
{
for(TInt i = 0; i < aNumContacts; ++i)
{
CContactCard* contact = CContactCard::NewLC();
// first name
HBufC* fnameBuf = RandomNameL();
CleanupStack::PushL(fnameBuf);
CContactItemField* fname = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
TPtr fnamePtr = fnameBuf->Des();
fname->TextStorage()->SetTextL(fnamePtr);
contact->AddFieldL(*fname);
CleanupStack::Pop(fname);
CleanupStack::PopAndDestroy(fnameBuf);
// last name
HBufC* lnameBuf = RandomNameL();
CleanupStack::PushL(lnameBuf);
CContactItemField* lname = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
TPtr lnamePtr = lnameBuf->Des();
lname->TextStorage()->SetTextL(lnamePtr);
contact->AddFieldL(*lname);
CleanupStack::Pop(lname);
CleanupStack::PopAndDestroy(lnameBuf);
// company name
HBufC* cnameBuf = RandomNameL();
CleanupStack::PushL(cnameBuf);
CContactItemField* cname = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCompanyName);
TPtr cnamePtr = cnameBuf->Des();
cname->TextStorage()->SetTextL(cnamePtr);
contact->AddFieldL(*cname);
CleanupStack::Pop(cname);
CleanupStack::PopAndDestroy(cnameBuf);
// phone number
HBufC* numBuf = RandomPhoneNumL();
CleanupStack::PushL(numBuf);
CContactItemField* num = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber);
TPtr numPtr = numBuf->Des();
num->TextStorage()->SetTextL(numPtr);
contact->AddFieldL(*num);
CleanupStack::Pop(num);
CleanupStack::PopAndDestroy(numBuf);
aDb.AddNewContactL(*contact);
CleanupStack::PopAndDestroy(contact);
}
}
示例15: CreateContactL
EXPORT_C TContactItemId CTestUtils::CreateContactL(const TDesC& aGivenName, const TDesC& aFamilyName, const TDesC& aPhoneNumber, const TDesC& aEmailAddress, TBool aReplaceContactsDb)
{
CContactDatabase* db = NULL;
if (aReplaceContactsDb)
{
db = CContactDatabase::ReplaceL();
}
else
{
TRAPD(err, db = CContactDatabase::OpenL());
if (err == KErrNotFound)
{
TRAP(err, db = CContactDatabase::CreateL());
}
User::LeaveIfError(err);
}
CleanupStack::PushL(db);
CContactItem* item=CContactCard::NewLC();
if (aFamilyName.Length())
SetNameL(*item, KUidContactFieldFamilyName, aFamilyName, ETrue);
if (aGivenName.Length())
SetNameL(*item, KUidContactFieldGivenName, aGivenName, ETrue);
if (aPhoneNumber.Length())
SetNameL(*item, KUidContactFieldPhoneNumber, aPhoneNumber, ETrue);
if (aEmailAddress.Length())
SetNameL(*item, KUidContactFieldEMail, aEmailAddress, ETrue);
CContactItemFieldSet& fieldSet= item->CardFields();
TContactItemId id = KNullContactId;
if (fieldSet.Count())
id = db->AddNewContactL(*item);
else
User::Leave(KErrNotSupported);
CleanupStack::PopAndDestroy(2); // item, db
return id;
}