phoneengine/PhoneCntFinder/ContactService/src/cphcntstoreloaderimpl.cpp
changeset 0 5f000ab63145
child 31 ba54057fe027
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2008 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 CPhCntStoreLoaderImpl class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <CVPbkContactLinkArray.h>
       
    20 #include <TVPbkContactStoreUriPtr.h>
       
    21 #include <MVPbkContactStoreList.h>
       
    22 #include "cphcntstoreloaderimpl.h"
       
    23 #include "MPhCntContactManager.h"
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // CPhCntStoreLoaderImpl::CPhCntStoreLoaderImpl
       
    29 // C++ default constructor can NOT contain any code, that might leave.
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CPhCntStoreLoaderImpl::CPhCntStoreLoaderImpl( MPhCntContactManager& aManager )
       
    33         :
       
    34         iContactManager( aManager )
       
    35     {
       
    36 
       
    37     }
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Two-phased constructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CPhCntStoreLoaderImpl* CPhCntStoreLoaderImpl::NewL( 
       
    45         MPhCntContactManager& aManager )
       
    46     {
       
    47     CPhCntStoreLoaderImpl* self = CPhCntStoreLoaderImpl::NewLC( aManager );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Two-phased constructor.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CPhCntStoreLoaderImpl* CPhCntStoreLoaderImpl::NewLC( 
       
    58         MPhCntContactManager& aManager )
       
    59     {
       
    60     CPhCntStoreLoaderImpl* self 
       
    61         = new( ELeave ) CPhCntStoreLoaderImpl( aManager );
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     return self;
       
    65     }
       
    66 
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // ?description_if_needed
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CPhCntStoreLoaderImpl::~CPhCntStoreLoaderImpl()
       
    73     {
       
    74     iObserver = NULL;
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // Secondphase constructor.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CPhCntStoreLoaderImpl::ConstructL()
       
    82     {
       
    83     BaseConstructL();
       
    84     }
       
    85 // ---------------------------------------------------------------------------
       
    86 // From class MPhCntStoreLoader.
       
    87 // Checks is the specified contact store loaded.
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 TBool CPhCntStoreLoaderImpl::IsContactStoreLoaded( 
       
    91         const TDesC8& aContactLink ) const
       
    92     {
       
    93     TBool isStoreLoaded( EFalse );
       
    94     TRAP_IGNORE( isStoreLoaded = IsContactStoreLoadedL( aContactLink ) );
       
    95     
       
    96     return isStoreLoaded;
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // From class MPhCntStoreLoader.
       
   102 // Starts asynchronous loading process for the store specified by the given
       
   103 // contact link.
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CPhCntStoreLoaderImpl::LoadContactStoreL( const TDesC8& aContactLink,
       
   107         MPhCntStoreLoaderObserver& aObserver )
       
   108     {
       
   109     __ASSERT_ALWAYS( NULL == iObserver, User::Leave( KErrInUse ) );
       
   110     
       
   111     iObserver = &aObserver;
       
   112     iContactManager.LoadContactStoreL( aContactLink, *this );
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // From class MPhCntStoreLoaderObserver.
       
   118 // Called when contact store loading process is completed. 
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CPhCntStoreLoaderImpl::ContactStoreLoadingCompleted( 
       
   122         MVPbkContactStore* aStore, TInt aErrorCode )
       
   123     {
       
   124     // Loading with contact store uri was completed  
       
   125     if ( iStoreUri )
       
   126         {
       
   127         ResponseReceived( aErrorCode );
       
   128         iStoreUri = NULL;
       
   129         }
       
   130     // Loading with contact link was completed   
       
   131     else if ( iObserver )
       
   132         {
       
   133         iObserver->ContactStoreLoadingCompleted( aStore, aErrorCode );
       
   134         iObserver = NULL;
       
   135         }
       
   136     else
       
   137         {
       
   138         ASSERT( NULL != iObserver );
       
   139         }
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CPhCntStoreLoaderImpl::LoadContactStoreWithUri.
       
   144 // Loads contact store (specified by the given URI) synchronously.
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 TInt CPhCntStoreLoaderImpl::LoadContactStoreWithUri( const TDesC& aStoreUri )
       
   148     {      
       
   149     TInt err = KErrNone;
       
   150     TBool storeLoaded = EFalse;
       
   151     TRAP_IGNORE( storeLoaded = IsContactStoreLoadedL( aStoreUri ) );
       
   152     if ( !storeLoaded )
       
   153         {
       
   154         iStoreUri = &aStoreUri;
       
   155         // convert Asynch store loading to synch 
       
   156         err = MakeAsyncRequest();
       
   157         }
       
   158     return err;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // From class CPhCntAsyncToSync
       
   163 // Issues asynchronous request for contact store loading.
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CPhCntStoreLoaderImpl::DoMakeAsyncRequestL()
       
   167     {
       
   168     __ASSERT_ALWAYS( NULL != iStoreUri, User::Leave( KErrArgument ) );
       
   169     iContactManager.LoadContactStoreWithUriL( *iStoreUri, *this );
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CPhCntStoreLoaderImpl::IsContactStoreLoadedL.
       
   174 // Checks is the contact store (specified by the given contact link) loaded.
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 TBool CPhCntStoreLoaderImpl::IsContactStoreLoadedL( 
       
   178         const TDesC8& aContactLink ) const
       
   179     {
       
   180     CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC( 
       
   181         aContactLink, iContactManager.ContactStoresL() );
       
   182     
       
   183     TBool storeLoaded( linkArray->Count() != 0 );
       
   184     CleanupStack::PopAndDestroy( linkArray );
       
   185     
       
   186     return storeLoaded;
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CPhCntStoreLoaderImpl::IsContactStoreLoadedL.
       
   191 // Checks is the contact store (specified by the given URI) loaded.
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 TBool CPhCntStoreLoaderImpl::IsContactStoreLoadedL( 
       
   195         const TDesC16& aContactStoreUri ) const
       
   196     {
       
   197     MVPbkContactStoreList& storeList = iContactManager.ContactStoresL();
       
   198     TVPbkContactStoreUriPtr uriPtr( aContactStoreUri );
       
   199     MVPbkContactStore* store = storeList.Find( uriPtr );
       
   200     return ( NULL != store );
       
   201     }
       
   202