Until S60 3rd Edition, Feature Pack 1 devices, only a thumbnail image could be assigned to a contact.
From S60 3rd Edition, Feature Pack 2 onwards, a contact also has an Image name field and an option to view the full-size image, via Image > View in contact details. When dialing a contact, a full-size image will be displayed on S60 3rd Edition, FP2 devices.
Therefore, to assign an image to a contact on S60 3rd Edition, FP2 devices, additional settings are required to update also the path to the full-size image.
/**
* void AssignPicture( HBufC8* aData, TContactItemId aId )
*
* Updates a specified contact item (aId) with thumbnail image data (aData)
*
*/
void CContactContainer::AssignPicture (HBufC8* aData, TContactItemId aId)
{
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL( contactsDb );
CContactItem* contactItem = contactsDb->OpenContactL( aId );
CleanupStack::PushL( contactItem );
TInt index = contactItem->CardFields().Find( KUidContactFieldPicture );
if ( index != KErrNotFound )
{
contactItem->RemoveField( index );
}
CContactItemField* field;
field = CContactItemField::NewLC( KStorageTypeStore,
KUidContactFieldPicture );
field->SetMapping( KUidContactFieldVCardMapPHOTO );
field->AddFieldTypeL( KUidContactFieldVCardMapBMP );
field->ResetStore();
// aData contains the thumbnails image data.
field->StoreStorage()->SetThingL( *aData );
contactItem->AddFieldL( *field );
CleanupStack::Pop( field );
// Save and close the contacts database
contactsDb->CommitContactL( *contactItem );
contactsDb->CloseContactL( aId );
CleanupStack::PopAndDestroy(2); // contactItem, contactsDb
}
/**
* void AssignPicturePath( const TDesC& aImagePath, TContactItemId aId )
*
* Updates a specified contact item (aId) with a full-size image path
* (aImagePath)
*
*/
void CContactContainer::AssignPicturePath( const TDesC& aImagePath,
TContactItemId aId )
{
// create pbkengine.
CPbkContactEngine* pbkContactEng =
CPbkContactEngine::NewL( &iCoeEnv->FsSession());
CleanupStack::PushL( pbkContactEng );
// Get image field info if there is no image assigned initially
const CPbkFieldsInfo& fieldsInfo = pbkContactEng->FieldsInfo();
CpbkFieldInfo* pbkFieldInfo = fieldsInfo.Find( EPbkFieldIdCodImageID );
// Open the contact item specified by aId
CPbkContactItem* aContactItem = pbkContactEng->OpenContactL( aId );
CleanupStack::PushL( aContactItem );
// Get the image field info
TPbkContactItemField* info = aContactItem->FindField( EPbkFieldIdCodImageID );
if ( !info )
{
// Add the image field if it was not found
TPbkContactItemField info = aContactItem->AddFieldL( *pbkFieldInfo );
if( KStorageTypeText == info.StorageType() )
{
// set path for the new image
CContactTextField* textstore = info.TextStorage();
textstore->SetTextL( aImagePath );
}
}
else
{
if( KStorageTypeText == info->StorageType() )
{
// Update with the new image path
CContactTextField* textstore = info->TextStorage();
textstore->SetTextL( aImagePath );
}
}
// Save and close the contacts database
pbkContactEng->CommitContactL( *aContactItem, EFalse );
pbkContactEng->CloseContactL( aId );
CleanupStack::PopAndDestroy( 2 ); // aContactItem, pbkContactEng
}
http://wiki.forum.nokia.com/index.php/TSS001074_-_Updating_contact's_images_in_S60_3rd_Ed,_FP2_devices
Two functions are defined below. AssignPicture updates the thumbnail image for a particular contact. AssignPicturePath (needed from S60 3rd Edition, FP2 onwards) updates the path of the full-size image.