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); }
/**Utility function for Adding any number of contact items with name and telephone fields. */ void CAgentTest::AddContactItemsL(TInt aCount) { iIdArray->Reset(); CContactItem* templateCard = NULL; CContactCard* card = NULL; CContactItemFieldSet* fieldSet = NULL; for(TInt loop = 0; loop < aCount; ++loop) { TInt pos = KErrNotFound; TBuf<16> name; name.Format(_L("NAME%d"),loop); TBuf<16> tel; tel.Format(_L("123456%d"),loop); templateCard = iDb->ReadContactLC(iDb->TemplateId()); card = CContactCard::NewLC(templateCard); fieldSet = &card->CardFields(); pos = fieldSet->Find(KUidContactFieldFamilyName); if (pos != KErrNotFound) { (*fieldSet)[pos].TextStorage()->SetTextL(name); } pos = fieldSet->Find(KUidContactFieldPhoneNumber); if (pos != KErrNotFound) { (*fieldSet)[pos].TextStorage()->SetTextL(tel); } TContactItemId contactId = iDb->AddNewContactL(*card); iIdArray->AddL(contactId); CleanupStack::PopAndDestroy(2); } }
void CTestImpExvCardSuiteStepBase::ExportItemL(TBuf<80> aPath, TBool aAddBDay) { OpenDBL(); TContactItemId itemId; RFs fsSession; RFileWriteStream fileStream; CContactIdArray* idArray = NULL; CContactCard* contactAdded = NULL; TTime now; User::LeaveIfError(fsSession.Connect()); CleanupClosePushL(fsSession); idArray = CContactIdArray::NewL(); CleanupStack::PushL(idArray); // idArray fsSession.MkDirAll(aPath); User::LeaveIfError(fileStream.Replace(fsSession, aPath, EFileWrite)); contactAdded = CContactCard::NewL(); CleanupStack::PushL(contactAdded); // contactAdded contactAdded->IncAccessCount(); // ADD BDAY if (aAddBDay) { CContactItemFieldSet& fieldSet=contactAdded->CardFields(); const TInt pos=fieldSet.Find(KUidContactFieldBirthday); if (pos!=KErrNotFound) { fieldSet[pos].DateTimeStorage()->SetTime(iBDayLocal); } else { CContactItemField* field=CContactItemField::NewLC(KStorageTypeDateTime,KUidContactFieldBirthday); field->SetMapping(KUidContactFieldVCardMapBDAY); field->DateTimeStorage()->SetTime(iBDayLocal); contactAdded->AddFieldL(*field); CleanupStack::Pop(); // field } } SetNameL(*contactAdded, KUidContactFieldGivenName, _L("toby"), ETrue); SetNameL(*contactAdded, KUidContactFieldPhoneNumber, _L("6041233214"), ETrue); User::After(3000000); // There is no need to call SetLastModifed because // That function will be call by ExportSelectedContactsL below now.UniversalTime(); iRecordedTime = now; INFO_PRINTF1(_L("Adding contact to Database.....")); itemId = iDb->AddNewContactL(*contactAdded); INFO_PRINTF1(_L("Contact Added to Database")); CleanupStack::PopAndDestroy(contactAdded); // contactAdded contactAdded = NULL; idArray->InsertL(0, itemId); INFO_PRINTF1(_L("Exporting Contact.....")); iDb->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl), *idArray, fileStream, CContactVCardConverter::EDefault, ETrue); INFO_PRINTF1(_L("Exported Contact")); fileStream.CommitL(); fileStream.Close(); CleanupStack::PopAndDestroy(idArray); // idArray fsSession.Close(); CleanupStack::PopAndDestroy(); // fsSession CloseDB(); }