/** * Add one contact to the database. */ void CMainThread::TestAddContactL() { // Add a contact _LIT(KForename,"Jo"); _LIT(KSurname,"Stichbury"); // 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); // Add newCard to the database iContactId = database->AddNewContactL(*newCard); CleanupStack::PopAndDestroy(newCard); iTest->Printf( _L("Thread1: Added 1 contact to the database.")); }
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; }
/** Utility method used to write text and binary blob fields into write streams. The write streams will be used to persist the blob informations in contact database. Provides a mechanism to get information from a contact item and store them in the right blob fields within contact database. Template can be NULL. @param aTextHeader reference to a write stream in which text header will be written @param aTextValues reference to a write stream in which text values will be written. From the caller point of view this reference should be a reference to a RSqlParamWriteStream instance @param aBinaryHeader reference to a write stream in which binary header will be written @param aBinaryValues reference to a write stream in which binary values will be written. @param aItem Contact item to be filled with information from text blob field. @param aSysTemplate System template item. */ void TCntPersistenceUtility::WriteBlobL(CEmbeddedStore& aTextEmbeddedStore, RWriteStream& aTextValues, CEmbeddedStore& aBinaryEmbeddedStore, CEmbeddedStore& aBinaryEmbeddedBlobStore, const CContactItem& aItem, const CContactTemplate* aSysTemplate) { CContactItemFieldSet& fieldSet = aItem.CardFields(); CContactItemFieldSet* textFieldSet = CContactItemFieldSet::NewLC(); CContactItemFieldSet* binaryFieldSet = CContactItemFieldSet::NewLC(); for(TInt i = 0; i < fieldSet.Count(); ++i) { CContactItemField* item = CContactItemField::NewL((aItem.CardFields())[i]); CleanupStack::PushL(item); if(item->StorageType() == KStorageTypeText) { textFieldSet->AddL(*item); } else { binaryFieldSet->AddL(*item); } CleanupStack::Pop(item); } TStreamId rootId = textFieldSet->StoreL(aTextEmbeddedStore, aSysTemplate, aTextValues, aBinaryEmbeddedBlobStore, NULL);// *textEmbeddedBlobStore); aTextEmbeddedStore.SetRootL(rootId); aTextEmbeddedStore.CommitL(); rootId = binaryFieldSet->StoreL(aBinaryEmbeddedStore, aSysTemplate, aTextValues, aBinaryEmbeddedBlobStore, NULL); aBinaryEmbeddedStore.SetRootL(rootId); aBinaryEmbeddedStore.CommitL(); aBinaryEmbeddedBlobStore.CommitL(); CleanupStack::PopAndDestroy(2, textFieldSet); //binaryFieldSet, textFieldSet }
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; }
/** * 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; }
CContactItemField* CFilteredViewTester::CreateFieldLC(const TUid aMappingUId, TFieldType aFieldType, const TDesC &aText) { CContactItemField * field =CContactItemField::NewLC(KStorageTypeText, aFieldType); field->SetMapping(aMappingUId); field->TextStorage()->SetTextL(aText); return field; }
QList<CContactItemField *> CntTransformUrl::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactUrl::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to url const QContactUrl &url(static_cast<const QContactUrl&>(detail)); //create new field TPtrC fieldText(reinterpret_cast<const TUint16*>(url.url().utf16())); if(fieldText.Length()) { CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldUrl); newField->TextStorage()->SetTextL(fieldText); newField->SetMapping(KUidContactFieldVCardMapURL); QString subType = url.subType(); const QString& subTypeHomePage(QContactUrl::SubTypeHomePage); if (subType.length() != 0 && subType.compare(subTypeHomePage) != 0) { User::LeaveIfError(KErrNotSupported); } //contexts setContextsL(url, *newField); fieldList.append(newField); CleanupStack::Pop(newField); } return fieldList; }
/** 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); }
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; }
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); }
void CAccessCountTests::AddAgentFieldL(const TContactItemId aCid) { _LIT(KAgentName, "ImAnAgent"); CContactItemField * field = CContactItemField::NewLC(KStorageTypeContactItemId, KUidContactFieldVCardMapAGENT ); field->SetMapping(KUidContactFieldVCardMapAGENT); field->SetLabelL(KAgentName); field->AgentStorage()->SetAgentId(aCid); iFields->AddL(*field); CleanupStack::Pop(field); field = NULL; }
EXPORT_C void TCnt::TGetSet::operator+= (const TDesC& aStr) { //Create the field if it is not found CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, *iContType); iCnt->AddFieldL(*field); //Takes ownership field->TextStorage()->SetTextL(aStr); CleanupStack::Pop(field); CleanupStack::PopAndDestroy(iContType); }
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; }
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(); }
//------------------------------------------------------------------------------------------------------------ void CPerfTestContact::InsertTextFieldL(TFieldType aID, const TDesC& aStringOfStuff ) { CContactItemField* itemFieldPtr = NULL; CContactTextField* textStoragePtr = NULL; itemFieldPtr = CContactItemField::NewLC( KStorageTypeText, aID ); textStoragePtr = itemFieldPtr->TextStorage(); // we don't have ownership here, hence no stack. textStoragePtr->SetTextL( aStringOfStuff ); textStoragePtr = NULL; // we've finished with this ptr now. iContactItem->AddFieldL( *itemFieldPtr ); // hand ownership over here CleanupStack::Pop( itemFieldPtr ); // and pop, }
//------------------------------------------------------------------------------------------------------------ void CPerfTestContact::InsertBinaryFieldL(TUid aID, const TDesC8& aBufOfStuff ) { CContactItemField* itemFieldPtr = NULL; CContactStoreField* binStoragePtr = NULL; itemFieldPtr = CContactItemField::NewLC( KStorageTypeStore, aID ); binStoragePtr = itemFieldPtr->StoreStorage(); // we don't have ownership here, hence no stack. binStoragePtr->SetThingL(aBufOfStuff); binStoragePtr = NULL; // we've finished with this ptr now. iContactItem->AddFieldL( *itemFieldPtr ); // hand ownership over here CleanupStack::Pop( itemFieldPtr ); // and pop, }
LOCAL_C void CreateTestContactsL(CTestResources& aRes, TInt aCount) { for (TInt i=1; i <= aCount; ++i) { CContactCard* card = CContactCard::NewLC(); CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName); TBuf<30> name; name.Format(_L("Contact%02d"), i); field->TextStorage()->SetTextL(name); card->AddFieldL(*field); CleanupStack::Pop(field); aRes.iDb->AddNewContactL(*card); CleanupStack::PopAndDestroy(card); } }
QList<CContactItemField *> CntTransformThumbnail::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactThumbnail::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to thumbnail const QContactThumbnail &thumbnail(static_cast<const QContactThumbnail&>(detail)); //if thumbnail was not changed, use existing jpg image bool checksumExists; qint64 checksum = thumbnail.variantValue(KThumbnailChecksum).toLongLong(&checksumExists); if (!thumbnail.thumbnail().isNull() && checksumExists && thumbnail.thumbnail().cacheKey() == checksum) { initializeThumbnailFieldL(); CContactItemField *thumbnailField = CContactItemField::NewLC(*m_thumbnailFieldFromTemplate); QByteArray jpgData = thumbnail.variantValue(KThumbnailJpgImage).toByteArray(); TPtrC8 ptr((TUint8*)jpgData.data(), jpgData.size()); thumbnailField->StoreStorage()->SetThingL(ptr); fieldList.append(thumbnailField); CleanupStack::Pop(thumbnailField); } else if (!thumbnail.thumbnail().isNull()) { QByteArray jpgImage; QImage scaledImage; if (thumbnail.thumbnail().size().width() <= KMaxThumbnailSize.iWidth && thumbnail.thumbnail().size().height() <= KMaxThumbnailSize.iHeight) { scaledImage = thumbnail.thumbnail(); } else { scaledImage = thumbnail.thumbnail().scaled( KMaxThumbnailSize.iWidth, KMaxThumbnailSize.iHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); } if (!scaledImage.isNull()) { QBuffer buffer(&jpgImage); buffer.open(QIODevice::WriteOnly); scaledImage.save(&buffer, "JPG"); buffer.close(); initializeThumbnailFieldL(); CContactItemField *thumbnailField = CContactItemField::NewLC(*m_thumbnailFieldFromTemplate); TPtrC8 ptr((TUint8*)jpgImage.data(), jpgImage.size()); thumbnailField->StoreStorage()->SetThingL(ptr); fieldList.append(thumbnailField); CleanupStack::Pop(thumbnailField); } } return fieldList; }
/** * Create a test contact with a Euro character name field. * This bug can be reproduced with most of the cyrillic characters also. */ void CTestResources::CreateTestContactsL() { const TInt KContacts = 1; TInt i; for (i=1; i <= KContacts; ++i) { CContactCard* card = CContactCard::NewLC(); CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName); _LIT(KName, "\x20a0"); //Euro character field->TextStorage()->SetTextL(KName); card->AddFieldL(*field); CleanupStack::Pop(field); iAddedContact = iDb->AddNewContactL(*card); CleanupStack::PopAndDestroy(card); } }
/**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(); }
void CntThumbnailCreator::CreateContactFieldL() { __ASSERT_DEBUG(m_imageData, User::Panic(KPanicCategory, KPanicUnitialized)); initializeThumbnailFieldL(); CContactItemField *thumbnailField = CContactItemField::NewLC(*m_thumbnailFieldFromTemplate); thumbnailField->StoreStorage()->SetThingL(*m_imageData); QT_TRYCATCH_LEAVING(m_fieldList->append(thumbnailField)); CleanupStack::Pop(thumbnailField); // Complete request to proceed to the final state TRequestStatus *status = &iStatus; User::RequestComplete(status, KErrNone); SetActive(); }
void CPbTester::EditEntryL(TContactItemId itemId) { _LIT(KEmailAddress,"*****@*****.**"); CContactItem *item = ipbDb->OpenContactL(itemId); CContactCard* card = NULL; CleanupStack::PushL(item); card = (CContactCard*)item; // Create the emailAddress field and add the data to it CContactItemField* emailAddr = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldEMail); emailAddr->SetMapping(KUidContactFieldVCardMapEMAILINTERNET); emailAddr ->TextStorage()->SetTextL(KEmailAddress); card->AddFieldL(*emailAddr); CleanupStack::Pop(emailAddr); ipbDb->CommitContactL(*item); CleanupStack::PopAndDestroy(item); }
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; }
/** Utility method used to read text fields from blob and fill item field set,Provides a mechanism to restore a contact item field set from text blob field within contact database. Blob informations are stored based on contact item field. At restore, a reference to a contact item field set is provided. For every contact item field in the item field set, a text restore is made. @param aFieldSet Reference to CContactItemFieldSet. Item field set that has to be filled with informations from blob @param aHeaderStore Stream store containing the header informations @param aId Root id for the header stream store @param aValuesStore Read stream used to read text fields from text blob @param aViewDef View definition indicating which fields have to be read from blob @param aTemplate Template indicating if current field set should be filled based on a template */ void TCntPersistenceUtility::RestoreTextL(CContactItemFieldSet& aFieldSet, CStreamStore& aHeaderStore, TStreamId aId, HBufC* textStream, const CContactItemViewDef& aViewDef, const CContactItem* aTemplate) { const TBool KIncludeFields = ( aViewDef.Use() == CContactItemViewDef::EIncludeFields ); if (KIncludeFields && aViewDef.Count() == 0) { // If view definition does not contain any field we don't do anything (don't read from // blob). We simply return from method without doing anything. // This is not an error condition return; } RStoreReadStream stream; stream.OpenLC(aHeaderStore,aId); TCardinality fieldCount; stream>>fieldCount; TInt textFieldIndex=0; for (TInt ii = 0; ii < fieldCount; ++ii) { // Restore text for every CContactItemField in provided CContactItemFieldSet. CContactItemField* field = CContactItemField::NewLC(); if(aTemplate) { field->RestoreFieldTypesL(stream, &(aTemplate->CardFields())); } else { field->RestoreFieldTypesL(stream, NULL); } ASSERT(field->StorageType() == KStorageTypeText); TBool fieldDefined = ETrue; if(!aViewDef.MatchesAll()) { fieldDefined = (aViewDef.Find(field->ContentType()) != KErrNotFound); } if ((!((fieldDefined && KIncludeFields) || (!fieldDefined && !KIncludeFields))) || (field->IsHidden() && aViewDef.Mode() == CContactItemViewDef::EMaskHiddenFields)) { CleanupStack::PopAndDestroy(field); } else { field->RestoreTextL(textStream, textFieldIndex); aFieldSet.AddL(*field); CleanupStack::Pop(field); } ++textFieldIndex; } CleanupStack::PopAndDestroy(&stream); }
QList<CContactItemField *> CntTransformBirthday::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactBirthday::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to birthday const QContactBirthday &birthday(static_cast<const QContactUrl&>(detail)); //create new field TDateTime dateTime(birthday.date().year(), TMonth(birthday.date().month() - 1), birthday.date().day() - 1, 0, 0, 0, 0); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeDateTime, KUidContactFieldBirthday); newField->DateTimeStorage()->SetTime(dateTime); newField->SetMapping(KUidContactFieldVCardMapBDAY); fieldList.append(newField); CleanupStack::Pop(newField); return fieldList; }
QList<CContactItemField *> CntTransformAvatar::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactAvatar::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to avatar const QContactAvatar &avatar(static_cast<const QContactAvatar&>(detail)); //create new field QString urlString = avatar.imageUrl().toString(); TPtrC fieldText(reinterpret_cast<const TUint16*>(urlString.utf16())); //copy filename and replace slash with a backslash TFileName filename; for(TInt i(0); i < fieldText.Length(); ++i) { if(i >= filename.MaxLength()) User::Leave(KErrTooBig); if(fieldText[i] == '/') { filename.Append('\\'); } else { filename.Append(fieldText[i]); } } if(filename.Length()) { TUid uid(KUidContactFieldCodImage); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, uid); newField->SetMapping(KUidContactFieldVCardMapUnknown); newField->TextStorage()->SetTextL(filename); fieldList.append(newField); CleanupStack::Pop(newField); } return fieldList; }
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); } }
void CTestResources::CreateTestContactsL() { const TInt KContacts = 4; TInt i; iContacts = CContactIdArray::NewL(); // Create contacts for (i=1; i <= KContacts; ++i) { CContactCard* card = CContactCard::NewLC(); CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName); TBuf<30> name; name.Format(_L("Contact%02d"), i); field->TextStorage()->SetTextL(name); card->AddFieldL(*field); CleanupStack::Pop(field); const TContactItemId contactId = iDb->AddNewContactL(*card); iContacts->AddL(contactId); CleanupStack::PopAndDestroy(card); // Eat away contact db events TContactDbObserverEvent event; test(iDbEventQueue->ListenForEvent(10,event)); } // Create a group CContactItem* group = iDb->CreateContactGroupLC(_L("TestGroup")); iGroupId = group->Id(); CleanupStack::PopAndDestroy(group); // Connect half of the contacts to the group for (i=0; i < iContacts->Count(); ++i) { if (i%2 == 0) { iDb->AddContactToGroupL((*iContacts)[i], iGroupId); } } }
QList<CContactItemField *> CntTransformAnniversarySimple::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactAnniversary::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to anniversary const QContactAnniversary &anniversary(static_cast<const QContactAnniversary&>(detail)); //create new field TDateTime dateTime(anniversary.originalDate().year(), TMonth(anniversary.originalDate().month() - 1), anniversary.originalDate().day() - 1, 0, 0, 0, 0); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeDateTime, KUidContactFieldAnniversary); newField->DateTimeStorage()->SetTime(dateTime); newField->SetMapping(KUidContactFieldVCardMapAnniversary); fieldList.append(newField); CleanupStack::Pop(newField); return fieldList; }
/** * 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; }