void AssignSpeedDialL( TInt aContact, TInt aSpeedDialID, CContactDatabase& database ) { CContactItem* item = NULL; item = database.OpenContactL( aContact ); CleanupStack::PushL( item ); if ( ContactIsASpeedDial( *item ) ) { g_test.Printf( _L("Contact is a speed dial !!! \n") ); } else { g_test.Printf( _L("Contact is NOT A SPEED DIAL \n") ); } CContactItemFieldSet &fieldSet = item->CardFields(); for(TInt index = fieldSet.Count() - 1; index > 0; --index) { if(fieldSet[index].StorageType() == KStorageTypeText) { //set the last text field from the fieldset as speeddial field. database.SetFieldAsSpeedDialL(*item, index, aSpeedDialID ); break; } } g_test.Next( _L("Contact changed to speed dial") ); g_test(ContactIsASpeedDial( *item )); CleanupStack::PopAndDestroy( item ); }
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 UpdateSpeedDialL(TInt aContact, TInt aSpeedDialID, CContactDatabase& database ) { CContactItem* item = NULL; item = database.OpenContactL( aContact ); CleanupStack::PushL( item ); if ( ContactIsASpeedDial( *item ) ) { g_test.Printf( _L("Contact is a speed dial !!! \n") ); database.SetFieldAsSpeedDialL(*item, item->Id(), aSpeedDialID ); } else { g_test.Printf( _L("Contact is NOT A SPEED DIAL \n") ); } CleanupStack::PopAndDestroy( item ); }