本文整理汇总了C++中CContactItem::AddFieldL方法的典型用法代码示例。如果您正苦于以下问题:C++ CContactItem::AddFieldL方法的具体用法?C++ CContactItem::AddFieldL怎么用?C++ CContactItem::AddFieldL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CContactItem
的用法示例。
在下文中一共展示了CContactItem::AddFieldL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: AddNamesL
/** Add first and last name fields to the contact in the format "Given Name #n" and "Family Name #n",
where n is the supplied index.
@param aItem The contact database
@param aIndex The number attached to the first and last names
*/
LOCAL_C void AddNamesL(CContactItem& aItem, TInt aIndex)
{
CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldFamilyName);
TBuf<32> text;
text.Format(KCardFamilyName,aIndex);
field->TextStorage()->SetTextL(text);
aItem.AddFieldL(*field);
CleanupStack::Pop(field);
field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldGivenName);
text.Format(KCardGivenName,aIndex);
field->TextStorage()->SetTextL(text);
aItem.AddFieldL(*field);
CleanupStack::Pop(field);
}
示例3: CreatePhonebookTemplateL
/**
* Create a new template and add it to the database
* @param aDb Contact database
* @param aTemplateName Name for the template
* @param aFieldSet Array of fields which should are added to the template
* @return TContactItemId Id of the newly created template
*/
TContactItemId CreatePhonebookTemplateL(CContactDatabase& aDb, const TDesC& aTemplateName, RArray<TFieldEntry>& aFieldSet)
{
CContactItem* temp = aDb.CreateContactCardTemplateLC(aTemplateName);
TContactItemId templateId = temp->Id();
CleanupStack::PopAndDestroy(temp);
temp=NULL;
//Remove all the unnecessary fields
temp = aDb.OpenContactLX(templateId);
CleanupStack::PushL(temp);
const TInt fieldCount = temp->CardFields().Count();
for(TInt i=fieldCount-1;i>=0;i--)
temp->RemoveField(i);
// Add each of the required fields to the template
for (TInt j=0; j<aFieldSet.Count(); ++j)
{
TFieldEntry fieldEntry=aFieldSet[j];
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,fieldEntry.iField);
if (fieldEntry.iFieldType!=KNullUid)
field->AddFieldTypeL(fieldEntry.iFieldType);
temp->AddFieldL(*field);
CleanupStack::Pop(field);
}
aDb.CommitContactL(*temp);
CleanupStack::PopAndDestroy(2); // temp, close template
return templateId;
}
示例4: ReadMailAddressesL
TBool CPredictiveSearchSynchronizer::ReadMailAddressesL(CContactItem& aContact)
{
PRINT(_L("CPredictiveSearchSynchronizer::ReadMailAddressesL"));
// SELECT value FROM comm_addr
// WHERE contact_id = [contact id value] AND type = [type value];
_LIT(KSelectMailAddrFormat, "SELECT %S FROM %S WHERE %S = %d AND %S = %d;");
const TInt KContactIdLength = 10;
const TInt KCommAddrTypeLength = 2; // CPplCommAddrTable::EEmailAddress is enum
TInt bufSize = KSelectMailAddrFormat().Length() +
KCommAddrValue().Length() +
KSqlContactCommAddrTableName().Length() +
KCommAddrContactId().Length() +
KContactIdLength +
KCommAddrType().Length() +
KCommAddrTypeLength;
HBufC* sqlStatement = HBufC::NewLC(bufSize);
sqlStatement->Des().AppendFormat(KSelectMailAddrFormat,
&KCommAddrValue,
&KSqlContactCommAddrTableName,
&KCommAddrContactId,
aContact.Id(),
&KCommAddrType,
CPplCommAddrTable::EEmailAddress);
RSqlStatement stmnt;
CleanupClosePushL(stmnt);
PRINT1(_L("prepare SQL statement:%S"), sqlStatement);
stmnt.PrepareL(iDatabase, *sqlStatement);
const TInt KValueIndex = 0;
TBool foundMailAddress(EFalse);
TInt err(KErrNone);
while ((err = stmnt.Next()) == KSqlAtRow)
{
TPtrC value;
if (stmnt.ColumnText(KValueIndex, value) == KErrNone)
{
PRINT2(_L(" id=%d, found mail address=%S"), aContact.Id(), &value);
CContactItemField* field =
CContactItemField::NewLC(KStorageTypeText, KUidContactFieldEMail);
CContactTextField* textfield = field->TextStorage();
textfield->SetTextL(value);
aContact.AddFieldL(*field); // Takes ownership
CleanupStack::Pop(field);
foundMailAddress = ETrue;
}
}
if (err != KSqlAtEnd)
{
PRINT1(_L("CPredictiveSearchSynchronizer::ReadMailAddressesL SQL err=%d"), err);
User::Leave(err);
}
CleanupStack::PopAndDestroy(&stmnt);
CleanupStack::PopAndDestroy(sqlStatement);
PRINT1(_L("CPredictiveSearchSynchronizer::ReadMailAddressesL return %d"), foundMailAddress);
return foundMailAddress;
}
示例5: AddFieldsL
/** Create Contact Item and add field to it and
* verify the field is being added
* aValue - field value
* @param aStorageType - Storage type of each field
* @param aContFieldUid - Uid of Contact field
* @param avCardMapUid - Uid of vCard
* @return - void
*/
void CTestAddFieldsStep::AddFieldsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)
{
TPtrC value;
TInt year, month, day;
// Create contact Item and add field to it
CContactItem* item = CContactCard::NewLC();
CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid);
CleanupStack::PushL(field);
field->SetMapping(avCardMap);
if(aStorageType==KStorageTypeDateTime)
{
GetIntFromConfig(ConfigSection(), KIniYear, year);
GetIntFromConfig(ConfigSection(), KIniMonth, month);
GetIntFromConfig(ConfigSection(), KIniDay, day);
TDateTime date(year,(TMonth)month,day,0,0,0,0);
field->DateTimeStorage()->SetTime(date);
}
else
{
field->TextStorage()->SetTextL(aValue);
}
item->AddFieldL(*field);
// verify the field is being added
CContactItemFieldSet& ContactFieldSet = item->CardFields();
TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);
if(pos != KErrNotFound)
{
if(aStorageType==KStorageTypeDateTime)
{
TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
//compair the results
if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day))
{
SetTestStepResult(EPass);
}
else
{
SetTestStepResult(EFail);
}
}
else
{
value.Set(ContactFieldSet[pos].TextStorage()->Text());
//compair the results
if(aValue.Compare(value)==0 )
{
SetTestStepResult(EPass);
}
else
{
SetTestStepResult(EFail);
}
}
}
CleanupStack::Pop(field);
CleanupStack::PopAndDestroy(item);
}
示例6:
LOCAL_C void AddFieldToContactL
(CContactItem& aContact, TFieldType aFieldType, const TDesC& aText)
{
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, aFieldType);
field->TextStorage()->SetTextL(aText);
aContact.AddFieldL(*field);
CleanupStack::Pop(field);
}
示例7: TestUpdateContactL
LOCAL_C void TestUpdateContactL()
{
test.Next(_L("TestUpdateContactL"));
SETUP;
CContactItem* contact = CContactItem::NewLC(KUidContactCard);
TContactItemId id = cntClient.CreateContactL(*contact);
CleanupStack::PopAndDestroy(contact);
// View definition to read image field
CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
imageViewDef->AddL(KUidContactFieldMatchAll);
contact = cntClient.OpenContactLX(imageViewDef ,id);
CleanupStack::PushL(contact);
CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
newField->SetMapping(KUidContactFieldVCardMapUnknown);
newField->TextStorage()->SetTextL(KSrcImage());
contact->AddFieldL(*newField); // Takes ownership
CleanupStack::Pop(newField);
cntClient.CommitContactL(*contact, EFalse);
CleanupStack::PopAndDestroy(2); // contact, imageViewDef
// View definition to read image field
imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
imageViewDef->AddL(KUidContactFieldCodImage);
contact = cntClient.ReadContactL(imageViewDef ,id);
TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);
// Test image field found
test(index != KErrNotFound);
CContactItemField& field = contact->CardFields()[index];
TPtrC imagePtr = field.TextStorage()->Text();
// Image should exist
test(BaflUtils::FileExists(fs, imagePtr));
// Test for GUID
TPtrC guid = contact->Guid();
test(imagePtr.Find(guid));
cntClient.CloseContact(id);
CleanupStack::PopAndDestroy(2); // contact, imageViewDef
TEAR_DOWN;
}
示例8: CreateICCTemplateL
/**
* Create template card for ICC contact items
* @param aDb Contact database
*/
TContactItemId CreateICCTemplateL(CContactDatabase& aDb)
{
CContactItem* temp = aDb.CreateContactCardTemplateLC(KTemplateName);
TContactItemId templateId = temp->Id();
CleanupStack::PopAndDestroy(temp);
temp=NULL;
//Remove all the unnecessary fields
temp = aDb.OpenContactLX(templateId);
CleanupStack::PushL(temp);
const TInt fieldCount = temp->CardFields().Count();
for(TInt i=fieldCount-1;i>=0;i--)
temp->RemoveField(i);
CContactItemField* name = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldFamilyName);
name->SetMapping(KUidContactFieldVCardMapUnusedN);
temp->AddFieldL(*name);
CleanupStack::Pop(name);
CContactItemField* number = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
number->SetMapping(KUidContactFieldVCardMapTEL);
temp->AddFieldL(*number);
CleanupStack::Pop(number);
CContactItemField* slotnum = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldICCSlot);
temp->AddFieldL(*slotnum);
CleanupStack::Pop(slotnum);
CContactItemField* phonebook = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldICCPhonebook);
temp->AddFieldL(*phonebook);
CleanupStack::Pop(phonebook);
aDb.CommitContactL(*temp);
CleanupStack::PopAndDestroy(2); // temp, close template
return templateId;
}
示例9: SetNameL
//
// Set the contents of a text field, creating the field if required
//
LOCAL_D void SetNameL(CContactItem& aItem,const TUid& aType,const TDesC& aName, TBool aAddField)
{
CContactItemFieldSet& fieldSet=aItem.CardFields();
const TInt pos=fieldSet.Find(aType);
if (!aAddField && pos!=KErrNotFound)
fieldSet[pos].TextStorage()->SetTextL(aName);
else
{
CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,aType);
field->SetMapping(KUidContactFieldVCardMapUnusedN);
field->TextStorage()->SetTextL(aName);
aItem.AddFieldL(*field);
CleanupStack::Pop(); // field
}
}
示例10: MakeAgentL
/**Utility function for adding agent to a contact item*/
void CAgentTest::MakeAgentL(TContactItemId aMainContactId, TContactItemId aAgentId)
{
CContactItem* mainItem = NULL;
CContactItemField* field = NULL;
mainItem = iDb->OpenContactL(aMainContactId);
CleanupStack::PushL(mainItem);
field = CContactItemField::NewLC(KStorageTypeContactItemId, KUidContactFieldVCardMapAGENT );
field->SetMapping(KUidContactFieldVCardMapAGENT);
field->AgentStorage()->SetAgentId(aAgentId);
mainItem->AddFieldL(*field);
CleanupStack::Pop();
iDb->CommitContactL(*mainItem);
CleanupStack::PopAndDestroy();
}
示例11: SetNameL
LOCAL_C void SetNameL(CContactItem& aItem,TUid aVcardType,const TDesC& aName)
//
// Set the contents of a text field, creating the field if required
//
{
CContactItemFieldSet& fieldSet=aItem.CardFields();
const TInt pos=fieldSet.Find(KUidContactFieldFamilyName);
if (pos!=KErrNotFound)
fieldSet[pos].TextStorage()->SetTextL(aName);
else
{
CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldFamilyName);
field->SetMapping(aVcardType);
field->TextStorage()->SetTextL(aName);
aItem.AddFieldL(*field);
CleanupStack::Pop(); // item
}
}
示例12: SetNameL
EXPORT_C void CTestUtils::SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName, TBool aAddField)
//
// Set the contents of a text field, creating the field if required
//
{
CContactItemFieldSet& fieldSet=aItem.CardFields();
const TInt pos=fieldSet.Find(aType);
if (!aAddField && pos!=KErrNotFound)
fieldSet[pos].TextStorage()->SetTextL(aName);
else
{
CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,aType);
field->SetMapping(KUidContactFieldVCardMapUnusedN);
field->TextStorage()->SetTextL(aName);
aItem.AddFieldL(*field);
CleanupStack::Pop(); // field
}
}
示例13: TestDeleteContactL
LOCAL_C void TestDeleteContactL()
{
test.Next(_L("TestDeleteContactL"));
SETUP;
CContactItem* contact = CContactItem::NewLC(KUidContactCard);
CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
newField->SetMapping(KUidContactFieldVCardMapUnknown);
newField->TextStorage()->SetTextL(KSrcImage());
contact->AddFieldL(*newField); // Takes ownership
CleanupStack::Pop(newField);
TContactItemId id = cntClient.CreateContactL(*contact);
CleanupStack::PopAndDestroy(contact);
// View definition to read image field
CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
imageViewDef->AddL(KUidContactFieldCodImage);
contact = cntClient.ReadContactL(imageViewDef ,id);
CleanupStack::PopAndDestroy(imageViewDef); // imageViewDef
TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);
// Test image field found
test(index != KErrNotFound);
CContactItemField& field = contact->CardFields()[index];
TPtrC imagePtr = field.TextStorage()->Text();
test(BaflUtils::FileExists(fs, imagePtr));
cntClient.DeleteContactL(id, EDeferEvent, ETrue);
test(!BaflUtils::FileExists(fs, imagePtr));
cntClient.CloseContact(id);
delete contact;
TEAR_DOWN;
}
示例14: AddContactFieldL
/**
* Add fields that meet some desired sort order
* @param aContact - Contact to be updated woth desired fields
* @param aSortOrder - specifies information about the desired fields
*/
void CTestContactViewCRUDOperationsStep::AddContactFieldL(CContactItem& aContact,
const RContactViewSortOrder& aSortOrder)
{
const TInt KMaxSortOrderCount = 3;
for(TInt i = 0; i < KMaxSortOrderCount; ++i)
{
TFieldType fieldType = aSortOrder[i];
TStorageType storageType = GetStorageType(fieldType);
CContentType* contentType = CContentType::NewL();
CleanupStack::PushL(contentType);
contentType->AddFieldTypeL(fieldType);
CContactItemField* field = CContactItemField::NewL(storageType, *contentType);
CleanupStack::PushL(field);
SetDataL(fieldType, *field);
aContact.AddFieldL(*field);
CleanupStack::Pop(field);
CleanupStack::PopAndDestroy(contentType);
}
}
示例15: AddContactToDatabaseL
void CLowDiskSpaceTest::AddContactToDatabaseL()
{
_LIT(KXChar, "x");
CContactItem* item = CContactCard::NewLC();
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCompanyName);
field->SetMapping(KUidContactFieldVCardMapORG);
field->TextStorage()->SetTextL(KXChar() );
item->AddFieldL(*field);
CleanupStack::Pop(); // field
field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
field->SetMapping(KUidContactFieldVCardMapTEL);
field->TextStorage()->SetTextL(KXChar() );
item->AddFieldL(*field);
CleanupStack::Pop(); // field
field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
field->SetMapping(KUidContactFieldVCardMapTEL);
field->TextStorage()->SetTextL(KXChar() );
item->AddFieldL(*field);
CleanupStack::Pop(); // field
field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
field->SetMapping(KUidContactFieldVCardMapTEL);
field->TextStorage()->SetTextL(KXChar() );
item->AddFieldL(*field);
CleanupStack::Pop(); // field
field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
field->SetMapping(KUidContactFieldVCardMapTEL);
field->SetHidden(ETrue);
field->TextStorage()->SetTextL(KXChar() );
item->AddFieldL(*field);
CleanupStack::Pop(); // field
field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldSuffixName);
field->SetMapping(KUidContactFieldVCardMapUnusedN);
field->TextStorage()->SetTextL(KXChar() );
item->AddFieldL(*field);
CleanupStack::Pop(); // field
field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPrefixName);
field->SetMapping(KUidContactFieldVCardMapUnusedN);
field->TextStorage()->SetTextL(KXChar() );
item->AddFieldL(*field);
CleanupStack::Pop(); // field
iContactDatabase->AddNewContactL(*item);
CleanupStack::PopAndDestroy(); // item
}