phonebookui/Phonebook2/ccapplication/ccamycardplugin/src/ccappmycardimageloader.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2009-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of MyCard image loader
       
    15 *
       
    16 */
       
    17 
       
    18 #include "ccappmycardimageloader.h"
       
    19 #include "ccappmycardcommon.h"
       
    20 
       
    21 // phonebook
       
    22 #include <CVPbkContactManager.h>
       
    23 #include <MVPbkStoreContact.h>
       
    24 #include <MVPbkFieldType.h>
       
    25 
       
    26 #include <CPbk2ImageManager.h>
       
    27 #include <TPbk2ImageManagerParams.h>
       
    28 #include <VPbkEng.rsg>
       
    29 
       
    30 // System
       
    31 #include <fbs.h>
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CCCAppMyCardImageLoader::NewL
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CCCAppMyCardImageLoader* CCCAppMyCardImageLoader::NewL(
       
    39     CVPbkContactManager& aContactManager,
       
    40     MMyCardImageLoaderObserver& aObserver )
       
    41     {
       
    42     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardImageLoader::NewL()"));
       
    43     
       
    44     CCCAppMyCardImageLoader* self = 
       
    45         new ( ELeave ) CCCAppMyCardImageLoader( aContactManager, aObserver );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     
       
    50     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardImageLoader::NewL()"));
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()
       
    59     {
       
    60     CCA_DP(KMyCardLogFile, 
       
    61         CCA_L("->CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()"));
       
    62     
       
    63     delete iImageManager;
       
    64     delete iOperation;
       
    65 
       
    66     CCA_DP(KMyCardLogFile, 
       
    67         CCA_L("<-CCCAppMyCardImageLoader::~CCCAppMyCardImageLoader()"));
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CCCAppMyCardImageLoader::CCCAppMyCardImageLoader
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 inline CCCAppMyCardImageLoader::CCCAppMyCardImageLoader(
       
    75     CVPbkContactManager& aContactManager,
       
    76     MMyCardImageLoaderObserver& aObserver ) :
       
    77         iContactManager( aContactManager ),
       
    78         iObserver( aObserver )
       
    79     {
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CCCAppMyCardImageLoader::ConstructL
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 inline void CCCAppMyCardImageLoader::ConstructL()
       
    87     {
       
    88     iImageManager = CPbk2ImageManager::NewL( iContactManager );
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CCCAppMyCardImageLoader::LoadContactImageL
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CCCAppMyCardImageLoader::LoadContactImageL( 
       
    96     MVPbkStoreContact& aContact )
       
    97     {
       
    98     CCA_DP(KMyCardLogFile, 
       
    99         CCA_L("->CCCAppMyCardImageLoader::LoadContactImageL()"));
       
   100     
       
   101     // cancel previous operations
       
   102     delete iOperation;
       
   103     iOperation = NULL;
       
   104     
       
   105     const MVPbkFieldType* thumbType = iContactManager.FieldTypes().Find(
       
   106         R_VPBK_FIELD_TYPE_THUMBNAILPIC );
       
   107   
       
   108     if( thumbType )
       
   109         {
       
   110         if( iImageManager->HasImage( aContact, *thumbType ) )
       
   111             {
       
   112             // contact has image. load it.
       
   113             iOperation = iImageManager->GetImageAsyncL( 
       
   114                 NULL, aContact, *thumbType, *this );
       
   115             }
       
   116         }
       
   117     
       
   118     if( !iOperation )
       
   119         {
       
   120         // no operation means the contact does not have image
       
   121         iObserver.ThumbnailLoadError( KErrNotFound );
       
   122         }
       
   123     
       
   124     CCA_DP(KMyCardLogFile, 
       
   125         CCA_L("<-CCCAppMyCardImageLoader::LoadContactImageL()"));
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CCCAppMyCardImageLoader::Pbk2ImageGetComplete
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CCCAppMyCardImageLoader::Pbk2ImageGetComplete(
       
   133     MPbk2ImageOperation& /*aOperation*/,
       
   134     CFbsBitmap* aBitmap )
       
   135     {
       
   136     CCA_DP(KMyCardLogFile, 
       
   137         CCA_L("->CCCAppMyCardImageLoader::Pbk2ImageGetComplete()"));
       
   138     
       
   139     delete iOperation;
       
   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     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CCCAppMyCardImageLoader::Pbk2ImageGetFailed
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CCCAppMyCardImageLoader::Pbk2ImageGetFailed( 
       
   155     MPbk2ImageOperation& /*aOperation*/,
       
   156     TInt aError )
       
   157     {
       
   158     CCA_DP(KMyCardLogFile, 
       
   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     }
       
   171 
       
   172 // End of File