phoneengine/PhoneCntFinder/ContactService/src/cphcntvpbkthumbnailloader.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Thumbnail loader for loading thumbnails from VirtualPhonebook
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <CPbk2ImageManager.h>
       
    20 
       
    21 #include "cphcntvpbkthumbnailloader.h"
       
    22 #include "MPhCntContactStores.h"
       
    23 #include "cphcntvpbkcontactid.h"
       
    24 #include "CPhCntContact.h"
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // Constructor
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CPhCntVPbkThumbnailLoader::CPhCntVPbkThumbnailLoader(
       
    33     MPhCntContactStores& aContactStores ) : 
       
    34     iContactStores( &aContactStores )
       
    35     {
       
    36     }
       
    37 
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // ConstructL
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CPhCntVPbkThumbnailLoader::ConstructL()
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // static constructor
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CPhCntVPbkThumbnailLoader* CPhCntVPbkThumbnailLoader::NewL(
       
    53     MPhCntContactStores& aContactStores )
       
    54     {
       
    55     CPhCntVPbkThumbnailLoader* self = 
       
    56         CPhCntVPbkThumbnailLoader::NewLC( aContactStores );
       
    57     CleanupStack::Pop( self );
       
    58     return self;
       
    59     }
       
    60 
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // static constructor
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CPhCntVPbkThumbnailLoader* CPhCntVPbkThumbnailLoader::NewLC(
       
    67     MPhCntContactStores& aContactStores )
       
    68     {
       
    69     CPhCntVPbkThumbnailLoader* self = 
       
    70         new( ELeave ) CPhCntVPbkThumbnailLoader( aContactStores );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     return self;
       
    74     }
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // destructor.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 CPhCntVPbkThumbnailLoader::~CPhCntVPbkThumbnailLoader()
       
    82     {
       
    83     delete iContactStores;
       
    84     delete iOperation;
       
    85     delete iReceivedContact;
       
    86     }
       
    87     
       
    88     
       
    89 // ---------------------------------------------------------------------------
       
    90 // From class MPhCntThumbnailLoader
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CPhCntVPbkThumbnailLoader::Cancel()
       
    94     {
       
    95     delete iReceivedContact;
       
    96     iReceivedContact = NULL;
       
    97     delete iOperation;
       
    98     iOperation = NULL;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // From class MPhCntThumbnailLoader
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CPhCntVPbkThumbnailLoader::Release()
       
   106     {
       
   107     // Nothing to do.
       
   108     }
       
   109 
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // From class CPhCntThumbnailLoaderBase
       
   113 // Starts the loading of thumbnail
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void CPhCntVPbkThumbnailLoader::DoLoadL( const CPhCntContactId& aContactId ) 
       
   117     {
       
   118     // Cast is safe because compile time variation makes sure that 
       
   119     // CPhCntContactId is only subclassed by CPhCntVPbkContactId.
       
   120     const CPhCntVPbkContactId& contactId = 
       
   121         reinterpret_cast<const CPhCntVPbkContactId&>( aContactId );
       
   122         
       
   123     // Fetch the contact.
       
   124     iContactStores->FetchContactL( contactId.ContactLink(), *this );
       
   125     }
       
   126  
       
   127 // ---------------------------------------------------------------------------
       
   128 // From class MPhCntContactFetchObserver
       
   129 // Indication that contact has been fetched from contact stores.
       
   130 // Starts loading the thumbnail from contact.
       
   131 // ---------------------------------------------------------------------------
       
   132 //   
       
   133 void CPhCntVPbkThumbnailLoader::ContactReceived( 
       
   134     CPhCntContact* aContact, 
       
   135     TInt aError )
       
   136     {
       
   137     if( aError == KErrNone )
       
   138         {
       
   139         iReceivedContact = aContact;
       
   140         TRAPD( err, iOperation = iReceivedContact->LoadThumbnailL( *this ) );
       
   141         if( err != KErrNone ) 
       
   142             {
       
   143             NotifyObserver( NULL, err );
       
   144             delete iReceivedContact;
       
   145             iReceivedContact = NULL;
       
   146             }
       
   147         }
       
   148     else 
       
   149         {
       
   150         NotifyObserver( NULL, aError );
       
   151         }
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // From class MPbk2ImageGetObserver
       
   156 // ---------------------------------------------------------------------------
       
   157 //  
       
   158 void CPhCntVPbkThumbnailLoader::Pbk2ImageGetComplete( 
       
   159     MPbk2ImageOperation& /*aOperation*/, 
       
   160     CFbsBitmap* aBitmap )
       
   161     {
       
   162     delete iOperation;
       
   163     iOperation = NULL;
       
   164     
       
   165     delete iReceivedContact;
       
   166     iReceivedContact = NULL;
       
   167     
       
   168     NotifyObserver( aBitmap, KErrNone );
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // From class MPbk2ImageGetObserver
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CPhCntVPbkThumbnailLoader::Pbk2ImageGetFailed( 
       
   176     MPbk2ImageOperation& /*aOperation*/, 
       
   177     TInt aError )
       
   178     {
       
   179     delete iOperation;
       
   180     iOperation = NULL;
       
   181     
       
   182     delete iReceivedContact;
       
   183     iReceivedContact = NULL;
       
   184     
       
   185     NotifyObserver( NULL, aError );
       
   186     }
       
   187