Updating contact’s images in S60 3rd Ed, FP2

來源:互聯網
上載者:User

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.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.