phonebookui/Phonebook2/ccapplication/ccamycardplugin/src/ccappmycardimageloader.cpp
branchRCL_3
changeset 3 04ab22b956c2
parent 0 e686773b3f54
child 15 e8e3147d53eb
equal deleted inserted replaced
0:e686773b3f54 3:04ab22b956c2
    24 #include <MVPbkFieldType.h>
    24 #include <MVPbkFieldType.h>
    25 
    25 
    26 #include <CPbk2ImageManager.h>
    26 #include <CPbk2ImageManager.h>
    27 #include <TPbk2ImageManagerParams.h>
    27 #include <TPbk2ImageManagerParams.h>
    28 #include <VPbkEng.rsg>
    28 #include <VPbkEng.rsg>
       
    29 #include <MVPbkContactFieldBinaryData.h>
       
    30 #include <MVPbkContactFieldTextData.h>
    29 
    31 
    30 // System
    32 // System
    31 #include <fbs.h>
    33 #include <fbs.h>
       
    34 #include <eikenv.h>
    32 
    35 
    33 
    36 
    34 // ---------------------------------------------------------------------------
    37 // ---------------------------------------------------------------------------
    35 // CCCAppMyCardImageLoader::NewL
    38 // CCCAppMyCardImageLoader::NewL
    36 // ---------------------------------------------------------------------------
    39 // ---------------------------------------------------------------------------
    37 //
    40 //
    38 CCCAppMyCardImageLoader* CCCAppMyCardImageLoader::NewL(
    41 CCCAppMyCardImageLoader* CCCAppMyCardImageLoader::NewL(
    39     CVPbkContactManager& aContactManager,
       
    40     MMyCardImageLoaderObserver& aObserver )
    42     MMyCardImageLoaderObserver& aObserver )
    41     {
    43     {
    42     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardImageLoader::NewL()"));
    44     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardImageLoader::NewL()"));
    43     
    45     
    44     CCCAppMyCardImageLoader* self = 
    46     CCCAppMyCardImageLoader* self = 
    45         new ( ELeave ) CCCAppMyCardImageLoader( aContactManager, aObserver );
    47         new ( ELeave ) CCCAppMyCardImageLoader( aObserver );
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     
    48     
    50     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardImageLoader::NewL()"));
    49     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardImageLoader::NewL()"));
    51     return self;
    50     return self;
    52     }
    51     }
    53 
    52 
    57 //
    56 //
    58 CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()
    57 CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()
    59     {
    58     {
    60     CCA_DP(KMyCardLogFile, 
    59     CCA_DP(KMyCardLogFile, 
    61         CCA_L("->CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()"));
    60         CCA_L("->CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()"));
    62     
    61 
    63     delete iImageManager;
    62     delete iImageDecoding;
    64     delete iOperation;
    63     delete iImageBuffer;
       
    64     delete iImageFileName;
    65 
    65 
    66     CCA_DP(KMyCardLogFile, 
    66     CCA_DP(KMyCardLogFile, 
    67         CCA_L("<-CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()"));
    67         CCA_L("<-CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()"));
    68     }
    68     }
    69 
    69 
    70 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    71 // CCCAppMyCardImageLoader::CCCAppMyCardImageLoader
    71 // CCCAppMyCardImageLoader::CCCAppMyCardImageLoader
    72 // ---------------------------------------------------------------------------
    72 // ---------------------------------------------------------------------------
    73 //
    73 //
    74 inline CCCAppMyCardImageLoader::CCCAppMyCardImageLoader(
    74 inline CCCAppMyCardImageLoader::CCCAppMyCardImageLoader(
    75     CVPbkContactManager& aContactManager,
       
    76     MMyCardImageLoaderObserver& aObserver ) :
    75     MMyCardImageLoaderObserver& aObserver ) :
    77         iContactManager( aContactManager ),
       
    78         iObserver( aObserver )
    76         iObserver( aObserver )
    79     {
    77     {
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CCCAppMyCardImageLoader::ConstructL
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 inline void CCCAppMyCardImageLoader::ConstructL()
       
    87     {
       
    88     iImageManager = CPbk2ImageManager::NewL( iContactManager );
       
    89     }
    78     }
    90 
    79 
    91 // ---------------------------------------------------------------------------
    80 // ---------------------------------------------------------------------------
    92 // CCCAppMyCardImageLoader::LoadContactImageL
    81 // CCCAppMyCardImageLoader::LoadContactImageL
    93 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
    94 //
    83 //
    95 void CCCAppMyCardImageLoader::LoadContactImageL( 
    84 void CCCAppMyCardImageLoader::LoadContactImageL( 
    96     MVPbkStoreContact& aContact )
    85     MVPbkStoreContact& aContact,
       
    86     const TSize& aThumbnailSize )
    97     {
    87     {
    98     CCA_DP(KMyCardLogFile, 
    88     CCA_DP(KMyCardLogFile, 
    99         CCA_L("->CCCAppMyCardImageLoader::LoadContactImageL()"));
    89         CCA_L("->CCCAppMyCardImageLoader::LoadContactImageL()"));
       
    90 
       
    91     MVPbkStoreContactFieldCollection& fields = aContact.Fields();
   100     
    92     
   101     // cancel previous operations
    93     delete iImageBuffer;
   102     delete iOperation;
    94     iImageBuffer = NULL;
   103     iOperation = NULL;
    95     delete iImageFileName;
       
    96     iImageFileName = NULL;
   104     
    97     
   105     const MVPbkFieldType* thumbType = iContactManager.FieldTypes().Find(
    98     const TInt fieldCount = fields.FieldCount();                           
   106         R_VPBK_FIELD_TYPE_THUMBNAILPIC );
    99     
   107   
   100     // Check all the fields and store first and last name
   108     if( thumbType )
   101     for ( TInt i = 0; i < fieldCount;  ++i )
   109         {
   102         {
   110         if( iImageManager->HasImage( aContact, *thumbType ) )
   103         MVPbkStoreContactField& field = fields.FieldAt( i );    
       
   104         const MVPbkFieldType* fieldType = field.BestMatchingFieldType();
       
   105         
       
   106         if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_THUMBNAILPIC )
   111             {
   107             {
   112             // contact has image. load it.
   108             MVPbkContactFieldData& contactField = field.FieldData(); 
   113             iOperation = iImageManager->GetImageAsyncL( 
   109             iImageBuffer = 
   114                 NULL, aContact, *thumbType, *this );
   110                 MVPbkContactFieldBinaryData::Cast(contactField).BinaryData().AllocL();
       
   111             }
       
   112         
       
   113         if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_CALLEROBJIMG )
       
   114             {
       
   115             MVPbkContactFieldData& contactField = field.FieldData();                        
       
   116             iImageFileName = MVPbkContactFieldTextData::Cast(contactField).Text().AllocL();
   115             }
   117             }
   116         }
   118         }
   117     
   119         
   118     if( !iOperation )
   120     if( iImageBuffer )
   119         {
   121         {
   120         // no operation means the contact does not have image
   122         delete iImageDecoding;
       
   123         iImageDecoding = NULL;
       
   124         
       
   125         RFs& fs = CEikonEnv::Static()->FsSession();
       
   126         iImageDecoding = CCCAppImageDecoding::NewL(
       
   127                 *this, 
       
   128                 fs, 
       
   129                 iImageBuffer, 
       
   130                 iImageFileName );
       
   131         iImageFileName = NULL;  // ownership is moved to CCCAppImageDecoding
       
   132         iImageBuffer = NULL;  // ownership is moved to CCCAppImageDecoding   
       
   133         iImageDecoding->StartL( aThumbnailSize );      
       
   134         }
       
   135     else
       
   136         {
   121         iObserver.ThumbnailLoadError( KErrNotFound );
   137         iObserver.ThumbnailLoadError( KErrNotFound );
   122         }
   138         }        
   123     
   139     
   124     CCA_DP(KMyCardLogFile, 
   140     CCA_DP(KMyCardLogFile, 
   125         CCA_L("<-CCCAppMyCardImageLoader::LoadContactImageL()"));
   141         CCA_L("<-CCCAppMyCardImageLoader::LoadContactImageL()"));
   126     }
   142     }
   127 
   143 
   128 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
   129 // CCCAppMyCardImageLoader::Pbk2ImageGetComplete
   145 // CCCAppMyCardImageLoader::ResizeImageL
   130 // ---------------------------------------------------------------------------
   146 // ---------------------------------------------------------------------------
   131 //
   147 //
   132 void CCCAppMyCardImageLoader::Pbk2ImageGetComplete(
   148 void CCCAppMyCardImageLoader::ResizeImageL( const TSize& aThumbnailSize )
   133     MPbk2ImageOperation& /*aOperation*/,
       
   134     CFbsBitmap* aBitmap )
       
   135     {
   149     {
   136     CCA_DP(KMyCardLogFile, 
   150     if( iImageDecoding  )
   137         CCA_L("->CCCAppMyCardImageLoader::Pbk2ImageGetComplete()"));
   151         {
   138     
   152         iImageDecoding->StartL( aThumbnailSize );      
   139     delete iOperation;
   153         }
   140     iOperation = NULL;
       
   141     
       
   142     // keep this last, so that observer can delete the image loader when it has
       
   143     // received the notification.
       
   144     iObserver.ThumbnailReady( aBitmap );
       
   145     
       
   146     CCA_DP(KMyCardLogFile, 
       
   147         CCA_L("<-CCCAppMyCardImageLoader::Pbk2ImageGetComplete()"));    
       
   148     }
   154     }
   149 
   155 
   150 // ---------------------------------------------------------------------------
   156 // ---------------------------------------------------------------------------
   151 // CCCAppMyCardImageLoader::Pbk2ImageGetFailed
   157 // CCCAppMyCardImageLoader::BitmapReadyL
   152 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   153 //
   159 //
   154 void CCCAppMyCardImageLoader::Pbk2ImageGetFailed( 
   160 void CCCAppMyCardImageLoader::BitmapReadyL( CFbsBitmap* aBitmap )
   155     MPbk2ImageOperation& /*aOperation*/,
       
   156     TInt aError )
       
   157     {
   161     {
   158     CCA_DP(KMyCardLogFile, 
   162     iObserver.ThumbnailReady( aBitmap );
   159         CCA_L("->CCCAppMyCardImageLoader::Pbk2ImageGetFailed() %d"), aError );    
       
   160     
       
   161     delete iOperation;
       
   162     iOperation = NULL;
       
   163 
       
   164     // keep this last, so that observer can delete the image loader when it has
       
   165     // received the notification.
       
   166     iObserver.ThumbnailLoadError( aError );
       
   167 
       
   168     CCA_DP(KMyCardLogFile, 
       
   169         CCA_L("<-CCCAppMyCardImageLoader::Pbk2ImageGetFailed()"));    
       
   170     }
   163     }
   171 
   164 
       
   165 
   172 // End of File
   166 // End of File