TBool CPackagerCntComparator::DoCompareCContactItemFieldSet(const CContactItemFieldSet& anItemFieldSet1, const CContactItemFieldSet& anItemFieldSet2) const /** Compares two CContactItemFieldSet items. @param anItemFieldSet1 The first CContactItemFieldSet to be compared. @param anItemFieldSet2 The second CContactItemFieldSet to be compared. @return ETrue if the two items are equal, EFalse otherwise. */ {// Need to check for NULL arrays first. if((!&anItemFieldSet1[0]) && (!&anItemFieldSet2[0])) { return ETrue; } if((!&anItemFieldSet1[0]) || (!&anItemFieldSet2[0])) { return EFalse; } // Check if arrays are same length to begin with. TInt maxCount = anItemFieldSet1.Count(); if(!DoCompareTInt(maxCount, anItemFieldSet2.Count())) { return EFalse; } for(TInt i=0; i<maxCount; ++i) { if(!(DoCompareCContactItemField(anItemFieldSet1[i],anItemFieldSet2[i]))) { return EFalse; } } return ETrue; }
/** Utility method used to read text blob fields from contacts database. Provides a mechanism to fill a contact item with informations stored in text blobs within contact database. A reference to the contact item to be fill has to be provided. A template has to be provided if the contact item is based on a template. Template can be NULL. Also a view definition can be provided to filter which fields are read from blob fields. @param aTextHeader reference to a read stream from which header values will be read @param aTextValues reference to a descriptor from which text values will be read @param aItem Contact item to be filled with information from text blob field. @param aView View definition specifying what item fields should be read from text blob field @param aTemplate Contact item representing a template based on which aItem should be read. Can be NULL @leave KErrNotFound if the specified contact item does not exist any more in contact database */ void TCntPersistenceUtility::ReadTextBlobL(CEmbeddedStore& aTextHeaderStore, TPtrC& aTextValues, CContactItem& aItem, const CContactItemViewDef& aView, const CContactItem* aTemplate) { HBufC* textFieldsBuf = aTextValues.AllocLC(); if (aTemplate) { // If a system template is provided, we create a new CContactItemFieldSet object // and restore it based on provided template (CContactItemField objects composing // template). CContactItem object will be set with the newly created CContactItemFieldSet. CContactItemFieldSet* original = CContactItemFieldSet::NewLC(); RestoreTextL(*original, aTextHeaderStore, aTextHeaderStore.Root(), textFieldsBuf, aView, aTemplate); for(TInt loop = 0;loop < original->Count();loop++) { CContactItemField* additionalField = CContactItemField::NewLC((*original)[loop]); aItem.CardFields().AddL(*additionalField); CleanupStack::Pop(additionalField); } CleanupStack::PopAndDestroy(original); } else { // If there is no template provided, we will fill the CContactItemField set provided // in the curent CContactItem object RestoreTextL(aItem.CardFields(), aTextHeaderStore, aTextHeaderStore.Root(), textFieldsBuf, aView, NULL); } CleanupStack::PopAndDestroy(textFieldsBuf); }
void CReadContactsAO::GetTextFieldFromFieldSet(CContactItemFieldSet& aFieldSet, const TUid aField,TDesC& name) { TInt index = aFieldSet.Find(aField); if ((index >= 0) && (index < aFieldSet.Count())) { CContactItemField& textfield = aFieldSet[index]; CContactTextField* textValue = textfield.TextStorage(); ((TDes&)name).Copy(textValue->Text()); } }
TBool CAgentAddressbook::ContainsEmptyField(const CContactItemFieldSet& fields) { for (TInt i = 0; i < fields.Count(); i++) { const CContactItemField& itemField = fields[i]; if (itemField.StorageType() == KStorageTypeText || itemField.StorageType() == KStorageTypeDateTime) { if (!itemField.Storage()->IsFull()) return ETrue; } } return EFalse; }
/** sets aMany fields of a currently read / open item to aText */ void CContactsRamTest::SetManyFieldsL(const TDesC& aText, const TInt aMany, CContactItemFieldSet &fields) { TInt count = fields.Count(); if( count > aMany ) { count = aMany; } TInt i = 0; for(; i < count; ++i) { SetFieldL(fields[i],aText); } }
/** this function encompasses two tests Test1(!aNewFields) opens contact item, and adds a custom uid to each field, changes lable to custom label then checks if uid and label were stored correctly Test2(aNewFields) opens contact item and adds ten new fields, and adds a custom uid to each field(new and old), changes lable to custom label then checks if uid and label were stored correctly. also checks both uids of new fields */ void CCustomLabelUid::TestCustomUidLabelsL( const TContactItemId aCid, const TBool aNewFields ) { CContactItem *contactItem = NULL; //open contact contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); CleanupStack::PushL(contactItem); CContactItemFieldSet *ContactFields = &(contactItem->CardFields()); if(aNewFields) { TInt length = 10;//add 10 new custom fields for(TInt i = 0, uids = TestConstants::KAltUID; i < length; i++, uids++) { AddNewFieldL( *ContactFields, TestConstants::KShortString, TFieldType::Uid(uids) ); } } //set custom labels for contact fields SetContactLabelsL(*contactItem); //set custom uids for contact fields AddUIDsL(*ContactFields,TestConstants::KInitialUID); //populate contact fields and update SetContactFieldsL(*contactItem); iContactsDatabase->CommitContactL(*contactItem); CleanupStack::PopAndDestroy(contactItem); CleanupStack::Pop();//lock //read contact contactItem = NULL; contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); ContactFields = &(contactItem->CardFields()); //check uids were update correctly SINGLECOMPARE( CheckUIDsL(*ContactFields,TestConstants::KInitialUID),0,0 ); //check labels were update correctly SINGLECOMPARE( CheckContactLabelsL(*contactItem),0,0 ); //check fields were populated correctly SINGLECOMPARE( CheckContactFieldsL(*contactItem),0,0 ); if(aNewFields) { //check that new fields contain the correct uids(2), initial and updated custom values TInt length = ContactFields->Count(); TInt i = ContactFields->Find( TFieldType::Uid(TestConstants::KAltUID) ); for(TInt uids = TestConstants::KAltUID; i < length; i++, uids++) { SINGLECOMPARE( CheckNewFieldL( *ContactFields, i, TFieldType::Uid(uids) ), i, 0); } } CleanupStack::PopAndDestroy(contactItem); }
/**Utility function for finding number of agents in a contact item*/ TInt CAgentTest::GetAgentCountL(TContactItemId aContactId) { CContactItem* mainItem = NULL; mainItem = iDb->ReadContactL(aContactId); CleanupStack::PushL(mainItem); CContactItemFieldSet* fields = &mainItem->CardFields(); TInt count = fields->Count(); TInt agentCount = 0; TInt i = 0; for(; i < count; ++i) { if( (*fields)[i].StorageType() == KStorageTypeContactItemId ) { ++agentCount; } } CleanupStack::PopAndDestroy(); return agentCount; }
void PrintFieldsTableL(RFile& outFile, const CContactItemFieldSet& fldSet, TBuf8<255>& buf) { SDescArr sTStorageType[] = { _S("KStorageTypeText"), _S("KStorageTypeStore"), _S("KStorageTypeContactIt"), _S("KStorageTypeDateTime") }; SFlagsDict sFieldFlag[]= { FF(EHidden), FF(EReadOnly), FF(ESynchronize), FF(EDisabled), FF(EUserMask), FF(EOverRidesLabel), FF(EUsesTemplateData), FF(EUserAddedField), FF(ETemplate), FF(ELabelUnspecified), FF(EDeleted), FF(NbTestLast) }; outFile.Write(_L8("<html><body><table width=100% cellpadding=1 cellspacing=1 border=1>")); outFile.Write(_L8("<tr><td>Fld</td><td>Label</td><td>Field types:</td><td>Storg type</td>" \ "<td>Field</td><td>Attr</td><td>Ext.Att</td><td>Templ</td></tr>\r\n")); const TInt numOfFields = fldSet.Count(); for (TInt i=0; i < numOfFields; ++i) { const CContactItemField& field = fldSet[i]; const CMyField& myField = reinterpret_cast<const CMyField&>(field); const CContentType& conType = *myField.iContentType; buf.Format(_L8("<tr><td>%d</td>"), myField.iId); outFile.Write(buf); outFile.Write(_L8("<td>")); if (myField.iLabel) { buf.Copy(*myField.iLabel); outFile.Write(buf); } outFile.Write(_L8("</td>\r\n")); //test.Printf(_L("Field types are:")); outFile.Write(_L8("<td>")); for(TInt j=0; j < conType.FieldTypeCount(); ++j) { const TFieldType& fldType = conType.FieldType(j); //test.Printf(_L(" %s"), VCardMaping(fldType)); const TPtrC str = VCardMaping(fldType); buf.Copy(str); outFile.Write(buf); outFile.Write(_L8(",<br>")); } //Print Mapping of the field outFile.Write(_L8("MP>: ")); const TPtrC mapp = VCardMaping(conType.Mapping()); buf.Copy(mapp); outFile.Write(buf); outFile.Write(_L8("</td>\r\n<td>")); //test.Printf(_L("Storg type: %s"), sTStorageType[myField.iStorageType]); const TPtrC str (sTStorageType[myField.iStorageType]); buf.Copy(str); outFile.Write(buf); outFile.Write(_L8("</td>\r\n<td>")); switch(myField.iStorageType) { case KStorageTypeText: { const TPtrC& textFld = static_cast<CContactTextField*>(field.Storage())->Text(); //test.Printf(_L("Text : %S"), textFld); buf.Copy(textFld); outFile.Write(buf); } break; default: break; } outFile.Write(_L8("</td>\r\n")); //test.Printf(_L("Attributes: 0x%08x"), myField.iAttributes); buf.Format(_L8("<td>0x%08x"), myField.iAttributes); outFile.Write(buf); for (TInt i = 0;; ++i) { const SFlagsDict& aFlag = sFieldFlag[i]; if (aFlag.iFlag & myField.iAttributes) { TPtrC str(aFlag.iDescript); buf.Copy(str); outFile.Write(_L8(",<br>")); outFile.Write(buf); } if (aFlag.iFlag == NbTestLast) { break; } } outFile.Write(_L8("</td>\r\n")); //test.Printf(_L("Ext Attrib: 0x%08x"), myField.iExtendedAttributes); buf.Format(_L8("<td>0x%08x</td>\r\n"), myField.iExtendedAttributes); outFile.Write(buf); //test.Printf(_L("Temp fldId: 0x%08x"), myField.iTemplateFieldId); buf.Format(_L8("<td>%d</td>\r\n"), myField.iTemplateFieldId); outFile.Write(buf); outFile.Write(_L8("</tr>\r\n\r\n")); } outFile.Write(_L8("</table></body></html>\r\n")); }
/** Test: opens contact item, add two identical uids to each field, alternating between custom and existing uids, then checks if uids were stored correctly */ void CCustomLabelUid::DuplicateUidsTestL( const TContactItemId aCid ) { //open contact CContactItem *contactItem = NULL; contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); CleanupStack::PushL(contactItem); CContactItemFieldSet *contactFields = &(contactItem->CardFields()); //add two identical uids to each field, alternating between custom and existing uids const TInt KFieldsCount = contactFields->Count(); TInt error = KErrNone; //add duplicate custom uids CContactItemField *contactField1 = CContactItemField::NewL(KStorageTypeText); CleanupStack::PushL(contactField1); contactField1->SetTemplateField(EFalse); TRAP( error, contactField1->AddFieldTypeL( TFieldType::Uid(TestConstants::KInitialUID) )); INTCOMPARE( KErrNone, ==, error, 0, 0 ); TRAP( error, contactField1->AddFieldTypeL( TFieldType::Uid(TestConstants::KInitialUID) )); INTCOMPARE( KErrNone, ==, error, 0, 0 ); contactItem->AddFieldL(*contactField1); CleanupStack::Pop(contactField1); //add duplicate existing uids CContactItemField *contactField2 = CContactItemField::NewL(KStorageTypeText); CleanupStack::PushL(contactField2); contactField2->SetTemplateField(EFalse); TRAP( error, contactField2->AddFieldTypeL(KUidContactFieldAdditionalName)); INTCOMPARE( KErrNone, ==, error, 1, 0 ); TRAP( error, contactField2->AddFieldTypeL(KUidContactFieldAdditionalName)); INTCOMPARE( KErrNone, ==, error, 1, 0 ); contactItem->AddFieldL(*contactField2); CleanupStack::Pop(contactField2); //populate contact fields SetContactFieldsL(*contactItem); //update contact iContactsDatabase->CommitContactL(*contactItem); CleanupStack::PopAndDestroy(contactItem); CleanupStack::Pop();//lock contactItem = NULL; //read contact item contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); contactFields = &(contactItem->CardFields()); //check that contact field uids updated correctly const TInt KReadFieldsCount = contactFields->Count(); const CContentType *KContentType = NULL; INTCOMPARE( KReadFieldsCount, >, 0, 0, 0 ); KContentType = &(*contactFields)[KFieldsCount].ContentType(); SINGLECOMPARE( KContentType->ContainsFieldType( TFieldType::Uid(TestConstants::KInitialUID) ), KFieldsCount,0 ); KContentType = &(*contactFields)[KFieldsCount+1].ContentType(); SINGLECOMPARE( KContentType->ContainsFieldType(KUidContactFieldAdditionalName), KFieldsCount+1,0 ); //check that contact fields updated correctly SINGLECOMPARE( CheckContactFieldsL(*contactItem), 0, 0 ); CleanupStack::PopAndDestroy(contactItem); }