ccservices/cmsservices/cmsengine/Server/src/cmsphonebookproxy.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005 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: 
       
    15 *       
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <spsettings.h>
       
    22 #include <spproperty.h>
       
    23 #include <MVPbkContactStore.h>
       
    24 #include <CVPbkContactManager.h>
       
    25 #include <VPbkContactStoreUris.h>
       
    26 #include <CVPbkContactLinkArray.h>
       
    27 #include <MVPbkContactStoreList.h>
       
    28 #include <CVPbkFieldTypeRefsList.h>
       
    29 #include <CVPbkContactIdConverter.h>
       
    30 #include <CPbk2StoreConfiguration.h>
       
    31 #include <MVPbkContactOperationBase.h>
       
    32 #include <MVPbkContactStoreProperties.h>
       
    33 #include <TVPbkWordParserCallbackParam.h>
       
    34 #include <CVPbkContactStoreUriArray.h>
       
    35 #include "cmsphonebookproxy.h"
       
    36 #include "cmsservercontact.h"
       
    37 #include "cmsdefines.h"
       
    38 #include "cmsserver.h"
       
    39 #include "cmsdebug.h"
       
    40 #include "cmssetvoicecalldefault.h"
       
    41 
       
    42 #include "cmsfindlinkedcontact.h"
       
    43 #include <MVPbkContactLink.h>
       
    44 #include <MVPbkStoreContact.h>
       
    45 
       
    46 // CONSTANTS
       
    47 const TInt KArrayGranularity = 2;
       
    48 
       
    49 // ----------------------------------------------------------
       
    50 // CCmsPhonebookProxy::CCmsPhonebookProxy
       
    51 //
       
    52 // ----------------------------------------------------------
       
    53 //
       
    54 CCmsPhonebookProxy::CCmsPhonebookProxy( MCmsPhonebookOperationsObserver& aCmsStoreOpencompleteObserver,
       
    55                                         RFs& aFileSessionHandle ) :
       
    56                                            iAtLeastOneStoreReady( EFalse ),
       
    57                                            iOpenComplete( EFalse ),
       
    58                                            iXspStoresInstalled( EFalse ),
       
    59                                            iCmsPhonebookOperationsObserver( aCmsStoreOpencompleteObserver ),
       
    60                                            iFileSessionHandle( aFileSessionHandle ),
       
    61                                            ixSPStoresArray( KArrayGranularity )
       
    62     {
       
    63     }
       
    64 
       
    65 // ----------------------------------------------------------
       
    66 // CCmsPhonebookProxy::NewL
       
    67 //
       
    68 // ----------------------------------------------------------
       
    69 //
       
    70 CCmsPhonebookProxy* CCmsPhonebookProxy::NewL(
       
    71     MCmsPhonebookOperationsObserver& aCmsStoreOpencompleteObserver,
       
    72     RFs& aFileSessionHandle )
       
    73     {
       
    74     CCmsPhonebookProxy* self = new ( ELeave ) CCmsPhonebookProxy(
       
    75         aCmsStoreOpencompleteObserver, aFileSessionHandle );
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     CleanupStack::Pop();
       
    79     return self;
       
    80     }
       
    81 
       
    82 // ----------------------------------------------------------
       
    83 // CCmsPhonebookProxy::ConstructL
       
    84 //
       
    85 // ----------------------------------------------------------
       
    86 //
       
    87 void CCmsPhonebookProxy::ConstructL()
       
    88     {
       
    89     PRINT ( _L("Start CCmsPhonebookProxy::ConstructL()") );
       
    90     iStoreConfiguration = CPbk2StoreConfiguration::NewL();
       
    91     iStoreConfiguration->AddObserverL( *this );
       
    92     CreateConfigurationL();
       
    93     iSetDefault = CmsSetVoiceCallDefault::NewL();
       
    94     PRINT ( _L("End CCmsPhonebookProxy::ConstructL()") );
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------
       
    98 // CCmsPhonebookProxy::~CCmsPhonebookProxy
       
    99 //
       
   100 // ----------------------------------------------------------
       
   101 //
       
   102 CCmsPhonebookProxy::~CCmsPhonebookProxy()
       
   103     {
       
   104     delete iOperation;
       
   105     delete iUriList;
       
   106     delete iFieldTypeRefList;
       
   107     delete iContactManager;
       
   108     if( iStoreConfiguration )
       
   109         {
       
   110         iStoreConfiguration->RemoveObserver( *this );
       
   111         delete iStoreConfiguration;
       
   112         iStoreConfiguration = NULL;
       
   113         }
       
   114     iObserverArray.Close();
       
   115     ixSPStoresArray.Reset();           
       
   116     iReadyStores.ResetAndDestroy();
       
   117     delete iSetDefault;
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------------
       
   121 // CCmsPhonebookProxy::StoreOpenStatus
       
   122 //
       
   123 // ----------------------------------------------------------
       
   124 //
       
   125 TBool CCmsPhonebookProxy::StoreOpenStatus()
       
   126     {
       
   127     if( iAtLeastOneStoreReady && iOpenComplete )
       
   128         {
       
   129         return ETrue;
       
   130         }
       
   131 
       
   132     return EFalse;
       
   133     }
       
   134 
       
   135 // ----------------------------------------------------------
       
   136 // CCmsPhonebookProxy::InitStoresL
       
   137 //
       
   138 // ----------------------------------------------------------
       
   139 //
       
   140 void CCmsPhonebookProxy::InitStoresL()
       
   141     {
       
   142     PRINT ( _L("Start CCmsPhonebookProxy::InitStoresL()") );
       
   143     
       
   144     if( !iOpenComplete )
       
   145         {                               
       
   146         iStoreList->OpenAllL( *this );
       
   147         }
       
   148     PRINT ( _L("End CCmsPhonebookProxy::InitStoresL()") );
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------------
       
   152 // CCmsPhonebookProxy::FetchContactL
       
   153 //
       
   154 // ----------------------------------------------------------
       
   155 //
       
   156 TInt CCmsPhonebookProxy::FetchContactL( TInt32 aContactId, MCmsContactInterface* aContactInterface )
       
   157     {
       
   158     PRINT ( _L("Start CCmsPhonebookProxy::FetchContactL()") );
       
   159     PRINT1 ( _L("CCmsPhonebookProxy::FetchContactL() - Contact ID: %d"), aContactId  );
       
   160 
       
   161     if( iContactStore == NULL )  //Cannot do anything if phonebook store is not available
       
   162         {
       
   163         return KErrNotReady;
       
   164         }
       
   165 
       
   166     TInt error = KErrNotFound;
       
   167     iContactInterface = aContactInterface;
       
   168     CVPbkContactIdConverter* converter = CVPbkContactIdConverter::NewL( *iContactStore );
       
   169     CleanupStack::PushL( converter );
       
   170     MVPbkContactLink* link = converter->IdentifierToLinkLC( aContactId );
       
   171     if( link )
       
   172         {
       
   173         if( iOperation )
       
   174             {
       
   175             delete iOperation;
       
   176             iOperation = NULL;
       
   177             }
       
   178         iOperation = iContactManager->RetrieveContactL( *link, *this );
       
   179         error = KErrNone;
       
   180         }
       
   181     CleanupStack::PopAndDestroy( 2 );  //link, converter
       
   182     PRINT ( _L("End CCmsPhonebookProxy::FetchContactL()") );
       
   183     return error;
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------------
       
   187 // CCmsPhonebookProxy::FetchContactL
       
   188 //
       
   189 // ----------------------------------------------------------
       
   190 //
       
   191 TInt CCmsPhonebookProxy::FetchContactL( const TDesC8& aPackedLink, MCmsContactInterface* aContactInterface )
       
   192     {
       
   193     //Whenever we get contact link, there can be the following possibilities
       
   194     //Contact could belong to any of the foll stores - Sim Store, PBK2Store, XSP Store    
       
   195     
       
   196     //If contact is from Sim Store, PBK2Store no extra effort is needed
       
   197     //just use the passed link and retreive the contact info
       
   198     
       
   199     //XSPContact
       
   200     //**********
       
   201     //If contacts is from XSP Store - then the challenge is to find whether this xspid 
       
   202     //is linked to the contact in DefaultCntDbUri or not    
       
   203     //How?
       
   204     //We need to search the entire DefaultCntDbUri() for any contact which is linked to this xspcontact
       
   205     //if more than 1 contact is linked to the same xspid, smartly choose anyone link(first link)
       
   206     //Once having found this linked contact in the DefaultCntDbUri(), use this found
       
   207     //contact to retreive the info
       
   208     
       
   209     PRINT ( _L("Start CCmsPhonebookProxy::FetchContactL()") );
       
   210     TInt error = KErrNotFound;
       
   211     iContactInterface = aContactInterface;
       
   212     CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC( aPackedLink, *iStoreList );
       
   213     if( linkArray->Count() > 0 )
       
   214         {    
       
   215         MVPbkContactLink* contactLinkToFetch = NULL;
       
   216         const MVPbkContactLink& contactLink = linkArray->At( 0 );
       
   217         
       
   218         CCmsFindLinkedContact* findLinkedContact = NULL;
       
   219         
       
   220         //Check whether the contact belongs to xsp store or not
       
   221         if ( IsXspContact( contactLink ) )
       
   222             {
       
   223             findLinkedContact = CCmsFindLinkedContact::NewL(
       
   224                                                 *iContactManager );
       
   225             CleanupStack::PushL( findLinkedContact );  
       
   226             //Its been proved that the contact passed is an XSP Contact
       
   227             //Now fetch the contact in DefaultCntDbUri which is linked to
       
   228             //the passed XSP contact
       
   229             contactLinkToFetch = 
       
   230                         (findLinkedContact->FetchLinkedContactL( contactLink )).CloneLC();            
       
   231             
       
   232             }
       
   233         else
       
   234             {
       
   235             contactLinkToFetch = contactLink.CloneLC();
       
   236             }
       
   237         // Send the latest contact link to cmsservercontact
       
   238         // to fetch contact.
       
   239         iContactInterface->FetchContactL( contactLinkToFetch );
       
   240         CleanupStack::PopAndDestroy();  //contactLinkToFetch
       
   241         
       
   242         if ( findLinkedContact )
       
   243             {
       
   244             CleanupStack::PopAndDestroy();  //findLinkedContact
       
   245             }
       
   246         
       
   247         error = KErrNone;
       
   248         }
       
   249 
       
   250     CleanupStack::PopAndDestroy();  //linkArray
       
   251     PRINT ( _L("End CCmsPhonebookProxy::FetchContactL()") );
       
   252     return error;
       
   253     }
       
   254 
       
   255 // ----------------------------------------------------------
       
   256 // CCmsPhonebookProxy::FetchContactL
       
   257 //
       
   258 // ----------------------------------------------------------
       
   259 //
       
   260 TInt CCmsPhonebookProxy::FetchContactL( const TDesC& aPhoneNbr, MCmsContactInterface* aContactInterface )
       
   261     {
       
   262     PRINT ( _L("Start CCmsPhonebookProxy::FetchContactL()") );
       
   263 
       
   264     // Write the aPhoneNbr to log file
       
   265     PRINT1 ( _L("CCmsPhonebookProxy::FetchContactL() - Phone number: %S"), &aPhoneNbr);
       
   266     iContactInterface = aContactInterface;
       
   267     
       
   268     if( iOperation )
       
   269         {
       
   270         delete iOperation;
       
   271         iOperation = NULL;
       
   272         }
       
   273     iOperation = iContactManager->MatchPhoneNumberL( aPhoneNbr, aPhoneNbr.Length(), *this );
       
   274     PRINT ( _L("End CCmsPhonebookProxy::FetchContactL()") );
       
   275     return KErrNone;
       
   276     }
       
   277 
       
   278 // ----------------------------------------------------------
       
   279 // CCmsPhonebookProxy::AddObserverL
       
   280 //
       
   281 // ----------------------------------------------------------
       
   282 //
       
   283 void CCmsPhonebookProxy::AddObserverL( MCmsContactInterface* aObserver )
       
   284     {
       
   285     PRINT ( _L("Start CCmsPhonebookProxy::AddObserverL()") );
       
   286 
       
   287     PRINT1 ( _L( "CCmsPhonebookProxy::AddObserverL(): 0x%x" ), &aObserver );
       
   288     User::LeaveIfError( iObserverArray.Append( aObserver ) );
       
   289 
       
   290     PRINT ( _L("End CCmsPhonebookProxy::AddObserverL()") );
       
   291     }
       
   292 
       
   293 // ----------------------------------------------------------
       
   294 // CCmsPhonebookProxy::RemoveObserver
       
   295 //
       
   296 // ----------------------------------------------------------
       
   297 //
       
   298 void CCmsPhonebookProxy::RemoveObserver( MCmsContactInterface* aObserver )
       
   299     {
       
   300     TInt index( iObserverArray.Find( aObserver ) );
       
   301     if( 0 <= index )
       
   302         {
       
   303         PRINT1( _L( "CCmsPhonebookProxy::RemoveObserver(): 0x%x" ), &aObserver );
       
   304         iObserverArray.Remove( index );
       
   305         }
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------------
       
   309 // CCmsPhonebookProxy::FindXSPContactL
       
   310 //
       
   311 // ----------------------------------------------------------
       
   312 //
       
   313 MVPbkContactOperationBase* CCmsPhonebookProxy::FindXSPContactL( const TDesC& aXspId, /*const TDesC& aExcludedStoreUri,*/
       
   314                                           MVPbkContactFindFromStoresObserver& aContacthandler )
       
   315     {
       
   316     if( iFieldTypeRefList )
       
   317         {
       
   318         iFieldTypeRefList->Reset();
       
   319         delete iFieldTypeRefList;
       
   320         iFieldTypeRefList = NULL;
       
   321         }
       
   322     iFieldTypeRefList = CVPbkFieldTypeRefsList::NewL();
       
   323     TCallBack parser( CCmsPhonebookProxy::WordParser, this );
       
   324     iFieldTypeRefList->AppendL( *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_IMPP ) );
       
   325     CDesCArrayFlat* searchString = new( ELeave) CDesCArrayFlat( 1 );
       
   326     CleanupStack::PushL( searchString );
       
   327     searchString->AppendL( aXspId );
       
   328 
       
   329     MVPbkContactOperationBase* XSPFindOperation = iContactManager->FindL(
       
   330         *searchString, *iFieldTypeRefList, aContacthandler, parser, ixSPStoresArray );
       
   331     CleanupStack::PopAndDestroy( searchString );
       
   332 
       
   333     return XSPFindOperation;
       
   334     }
       
   335 
       
   336 // ----------------------------------------------------------
       
   337 // CCmsPhonebookProxy::NumberOfStoresInFind
       
   338 //
       
   339 // ----------------------------------------------------------
       
   340 //
       
   341 TInt CCmsPhonebookProxy::NumberOfStoresInFind( const TDesC& aExcludedStoreUri )
       
   342     {
       
   343     TVPbkContactStoreUriPtr excludedUri( aExcludedStoreUri );
       
   344     if ( iUriList->IsIncluded( excludedUri ) )
       
   345         {
       
   346         return iUriList->Count() - 1;
       
   347         }
       
   348     else
       
   349         {
       
   350         return iUriList->Count();
       
   351         }
       
   352     }
       
   353 
       
   354 // ----------------------------------------------------------
       
   355 // CCmsPhonebookProxy::UpdateXSPStoresListL
       
   356 //
       
   357 // ----------------------------------------------------------
       
   358 //
       
   359 void CCmsPhonebookProxy::UpdateXSPStoresListL()
       
   360     {
       
   361     CDesCArrayFlat* xSPStoresArray = new (ELeave)
       
   362         CDesCArrayFlat( KArrayGranularity );
       
   363     CleanupStack::PushL( xSPStoresArray );
       
   364     FindXSPStoresL( *xSPStoresArray );
       
   365 
       
   366     TBool configurationChanged = EFalse;
       
   367     TInt oldStoresCount = ixSPStoresArray.Count();
       
   368     TInt newStoresCount = xSPStoresArray->Count();
       
   369 
       
   370     if ( oldStoresCount != newStoresCount )
       
   371         {
       
   372         configurationChanged = ETrue;
       
   373         }
       
   374 
       
   375     for ( TInt i = 0; i < oldStoresCount && !configurationChanged; i++ )
       
   376         {
       
   377         if ( ixSPStoresArray.operator[](i).Compare(
       
   378             xSPStoresArray->operator[](i) ) != 0 )
       
   379             {
       
   380             configurationChanged = ETrue;
       
   381             }
       
   382         }
       
   383 
       
   384     if ( configurationChanged )
       
   385         {
       
   386         CreateConfigurationL();
       
   387         InitStoresL();
       
   388         }
       
   389 
       
   390     CleanupStack::PopAndDestroy( xSPStoresArray );
       
   391     }
       
   392 
       
   393 // ----------------------------------------------------------
       
   394 // CCmsPhonebookProxy::WordParser
       
   395 //
       
   396 // ----------------------------------------------------------
       
   397 //
       
   398 TInt CCmsPhonebookProxy::WordParser( TAny* aWordParserParam )
       
   399     {
       
   400     TVPbkWordParserCallbackParam* param = static_cast<TVPbkWordParserCallbackParam*>( aWordParserParam );
       
   401     TPtrC data( param->iStringToParse->Ptr() );
       
   402 
       
   403     PRINT1( _L( "CCmsPhonebookProxy::WordParser(): %S" ), &data );
       
   404 
       
   405     param->iWordArray->AppendL( data );
       
   406     return 0;
       
   407     }
       
   408 
       
   409 // ----------------------------------------------------------
       
   410 // CCmsPhonebookProxy::SetVoiceCallDefaultL
       
   411 //
       
   412 // ----------------------------------------------------------
       
   413 //
       
   414 void CCmsPhonebookProxy::SetVoiceCallDefaultL( MVPbkStoreContact* aContact )
       
   415 	{
       
   416 	iSetDefault->SetVoiceCallDefaultL( aContact, iContactManager );
       
   417 	}
       
   418 
       
   419 // ----------------------------------------------------------
       
   420 // CCmsPhonebookProxy::SetContact
       
   421 //
       
   422 // ----------------------------------------------------------
       
   423 //
       
   424 void CCmsPhonebookProxy::SetContact( MVPbkStoreContact* aContact )
       
   425     {
       
   426     iContact = aContact;
       
   427     iCurrentContactStoreReady = EFalse;
       
   428         
       
   429     if( iContact )
       
   430         {
       
   431         for( TInt x=0; x<iReadyStores.Count(); x++ )
       
   432             {
       
   433             if( iReadyStores[x]->Des().CompareC(  
       
   434                     iContact->ContactStore().StoreProperties().Uri().UriDes() ) == 0 )
       
   435                 {                            
       
   436                 iCurrentContactStoreReady = ETrue;
       
   437                 break;
       
   438                 }                                        
       
   439             }
       
   440         }            
       
   441     }
       
   442 
       
   443 // ----------------------------------------------------------
       
   444 // CCmsPhonebookProxy::ExternalStoresIntalled
       
   445 //
       
   446 // ----------------------------------------------------------
       
   447 //
       
   448 TBool CCmsPhonebookProxy::ExternalStoresIntalled() const
       
   449     {
       
   450     return iXspStoresInstalled;
       
   451     }
       
   452 
       
   453 // ----------------------------------------------------------
       
   454 // CCmsPhonebookProxy::ContactManager
       
   455 //
       
   456 // ----------------------------------------------------------
       
   457 //
       
   458 CVPbkContactManager* CCmsPhonebookProxy::ContactManager() const
       
   459     {
       
   460     return iContactManager;
       
   461     }
       
   462 
       
   463 // ----------------------------------------------------------
       
   464 // CCmsPhonebookProxy::OpenComplete
       
   465 //
       
   466 // ----------------------------------------------------------
       
   467 //
       
   468 void CCmsPhonebookProxy::OpenComplete()
       
   469     {
       
   470     PRINT( _L("Start CCmsPhonebookProxy::OpenComplete()" ) );
       
   471     iOpenComplete = ETrue;
       
   472     if ( iAtLeastOneStoreReady )
       
   473         {        
       
   474         iCmsPhonebookOperationsObserver.StoreOpenComplete();
       
   475         iCurrentContactStoreReady = ETrue;				      
       
   476         }
       
   477     PRINT( _L("End CCmsPhonebookProxy::OpenComplete()" ) );
       
   478     }
       
   479 
       
   480 // ----------------------------------------------------------
       
   481 // CCmsPhonebookProxy::FindCompleteL
       
   482 //
       
   483 // ----------------------------------------------------------
       
   484 //
       
   485 void CCmsPhonebookProxy::FindCompleteL( MVPbkContactLinkArray* aResults )
       
   486     {
       
   487     PRINT1( _L( "CCmsPhonebookProxy::FindCompleteL() - Count: %d" ), aResults->Count() );
       
   488     ResetData();
       
   489     TInt count( aResults->Count() );
       
   490     if( count > 0 )
       
   491         {
       
   492         if( iOperation )
       
   493             {
       
   494             delete iOperation;
       
   495             iOperation = NULL;
       
   496             }
       
   497         iOperation = iContactManager->RetrieveContactL( aResults->At( 0 ), *this );
       
   498         }
       
   499     else
       
   500         {
       
   501         PRINT( _L( " CCmsPhonebookProxy::FindCompleteL() : No results -> complete with KErrNotFound" ) );
       
   502         CompleteContactRequestL( KErrNotFound, NULL );
       
   503         iCmsPhonebookOperationsObserver.CmsSingleContactOperationComplete( KErrNotFound );
       
   504         }
       
   505     delete aResults;
       
   506     aResults = NULL;
       
   507     PRINT( _L( "End CCmsPhonebookProxy::FindCompleteL()" ) );
       
   508     }
       
   509 
       
   510 // ----------------------------------------------------------
       
   511 // CCmsPhonebookProxy::FindFailed
       
   512 //
       
   513 // ----------------------------------------------------------
       
   514 //
       
   515 void CCmsPhonebookProxy::FindFailed( TInt aError )
       
   516     {
       
   517     PRINT1( _L( "CCmsPhonebookProxy::FindFailed() - Error: %d" ), aError );
       
   518     ResetData();
       
   519     CompleteContactRequestL( aError, NULL );
       
   520     iCmsPhonebookOperationsObserver.CmsSingleContactOperationComplete( aError );
       
   521     }
       
   522 
       
   523 // ----------------------------------------------------------
       
   524 // CCmsPhonebookProxy::FindFailed
       
   525 //
       
   526 // ----------------------------------------------------------
       
   527 //
       
   528 void CCmsPhonebookProxy::CompleteContactRequestL( TInt aError, MVPbkStoreContact* aContact )
       
   529     {
       
   530     PRINT1( _L( "CCmsPhonebookProxy::CompleteContactRequestL() - Error: %d" ), aError );
       
   531     if( iContactInterface )
       
   532         {
       
   533         iContactInterface->ContactReadyL( aError, aContact );
       
   534         }
       
   535     else
       
   536         {
       
   537         PRINT( _L( " CCmsPhonebookProxy::CompleteContactRequestL(): No contact interface => Panic with ENullInterfaceHandle" ) );
       
   538         CCmsServer::PanicServer( ENullInterfaceHandle );
       
   539         }
       
   540     }
       
   541 
       
   542 // ----------------------------------------------------------
       
   543 // CCmsPhonebookProxy::StoreReady
       
   544 //
       
   545 // ----------------------------------------------------------
       
   546 //
       
   547 void CCmsPhonebookProxy::StoreReady( MVPbkContactStore& aContactStore )
       
   548     {
       
   549     
       
   550     PRINT1( _L( "CCmsPhonebookProxy::StoreReady(): Store: %S" ), (&aContactStore.StoreProperties().Uri().UriDes()) );
       
   551     //Set iAtLeastOneStoreReady to ETrue to indicate that
       
   552     //at least one store is available
       
   553     iAtLeastOneStoreReady = ETrue;
       
   554     using namespace VPbkContactStoreUris;
       
   555     if( aContactStore.StoreProperties().Uri().UriDes().Compare( DefaultCntDbUri() ) == 0 )
       
   556         {
       
   557         iContactStore = &aContactStore;
       
   558         }
       
   559         
       
   560     TRAP_IGNORE(
       
   561         {
       
   562         HBufC* buf = aContactStore.StoreProperties().Uri().UriDes().AllocLC();        
       
   563         iReadyStores.AppendL( buf );
       
   564         CleanupStack::Pop( buf );
       
   565         } );
       
   566     
       
   567     if( iContact && iContact->ContactStore().StoreProperties().Uri().UriDes().Compare(
       
   568     aContactStore.StoreProperties().Uri().UriDes() ) == 0 && !iCurrentContactStoreReady )
       
   569         {
       
   570         iCurrentContactStoreReady = ETrue;
       
   571         iCmsPhonebookOperationsObserver.StoreOpenComplete();
       
   572         }
       
   573     }
       
   574 
       
   575 // ----------------------------------------------------------
       
   576 // CCmsPhonebookProxy::StoreUnavailable
       
   577 //
       
   578 // ----------------------------------------------------------
       
   579 //
       
   580 void CCmsPhonebookProxy::StoreUnavailable( MVPbkContactStore& aContactStore, TInt /*aReason*/ )
       
   581     {
       
   582     PRINT1( _L( "CCmsPhonebookProxy::StoreUnavailable(): Store: %S" ),
       
   583         &aContactStore.StoreProperties().Uri().UriDes() );
       
   584     }
       
   585 
       
   586 // ----------------------------------------------------------
       
   587 // CCmsPhonebookProxy::HandleStoreEventL
       
   588 //
       
   589 // ----------------------------------------------------------
       
   590 //
       
   591 void CCmsPhonebookProxy::HandleStoreEventL( MVPbkContactStore& /*aContactStore*/,
       
   592                                             TVPbkContactStoreEvent aStoreEvent )
       
   593     {
       
   594     PRINT( _L("Start CCmsPhonebookProxy::HandleStoreEventL()" ) );
       
   595     
       
   596     const TInt count = iObserverArray.Count();
       
   597     // send store event to all observers
       
   598     for( TInt i = 0; i < count ; i++ )
       
   599         {
       
   600         MCmsContactInterface* observer( iObserverArray[i] );
       
   601         if( observer )
       
   602             {
       
   603             TCmsPhonebookEvent event = SelectEventType( aStoreEvent.iEventType );
       
   604             observer->OfferContactEventL( event, aStoreEvent.iContactLink );
       
   605             }
       
   606         }
       
   607     PRINT( _L("End CCmsPhonebookProxy::HandleStoreEventL()" ) );
       
   608     }
       
   609 
       
   610 // ----------------------------------------------------------
       
   611 // CCmsPhonebookProxy::ConfigurationChanged
       
   612 //
       
   613 // ----------------------------------------------------------
       
   614 //
       
   615 void CCmsPhonebookProxy::ConfigurationChanged()
       
   616     {
       
   617     PRINT( _L( "CCmsPhonebookProxy::ConfigurationChanged()" ) );
       
   618     if( iContactInterface && iContact )
       
   619         {
       
   620         iContactInterface->ContactReadyL( KErrNone, NULL );        
       
   621         }
       
   622     }
       
   623 
       
   624 // ----------------------------------------------------------
       
   625 // CCmsPhonebookProxy::ConfigurationChangedComplete
       
   626 //
       
   627 // ----------------------------------------------------------
       
   628 //
       
   629 void CCmsPhonebookProxy::ConfigurationChangedComplete()
       
   630     {
       
   631     PRINT( _L( "Start CCmsPhonebookProxy::ConfigurationChangedComplete()" ) );
       
   632     CreateConfigurationL();
       
   633     InitStoresL();
       
   634     PRINT( _L( "End CCmsPhonebookProxy::ConfigurationChangedComplete()" ) );
       
   635     }
       
   636 
       
   637 // ----------------------------------------------------------
       
   638 // CCmsPhonebookProxy::CreateConfigurationL
       
   639 //
       
   640 // ----------------------------------------------------------
       
   641 //
       
   642 void CCmsPhonebookProxy::CreateConfigurationL()
       
   643     {
       
   644     PRINT( _L( "Start CCmsPhonebookProxy::CreateConfigurationL()" ) );
       
   645 
       
   646     iAtLeastOneStoreReady = EFalse;
       
   647     iCurrentContactStoreReady = EFalse;    
       
   648     iOpenComplete = EFalse;
       
   649     delete iUriList;
       
   650     iUriList = NULL;
       
   651     iContactStore = NULL;
       
   652     iReadyStores.ResetAndDestroy();
       
   653 
       
   654     // Support all contact stores, not only those defined by phonebook2 setting
       
   655     iUriList = iStoreConfiguration->SupportedStoreConfigurationL();
       
   656     
       
   657     ixSPStoresArray.Reset();
       
   658     FindXSPStoresL( ixSPStoresArray );
       
   659 
       
   660 #ifdef _DEBUG
       
   661     PRINT( _L( " CCmsPhonebookProxy::CreateConfigurationL(): Current store configuration:" ) );
       
   662     for( TInt i = 0; i < iUriList->Count(); i++ )
       
   663         {
       
   664         PRINT2( _L( "  [%d] = %S" ), i, &iUriList->operator[](i).UriDes() );
       
   665         }
       
   666 #endif
       
   667 
       
   668     delete iContactManager;
       
   669     iContactManager = NULL;
       
   670     iContactManager = CVPbkContactManager::NewL( *iUriList, &iFileSessionHandle );
       
   671     iStoreList = &iContactManager->ContactStoresL();
       
   672 
       
   673     PRINT( _L( "End CCmsPhonebookProxy::CreateConfigurationL()" ) );
       
   674     }
       
   675 
       
   676 // ----------------------------------------------------
       
   677 // CCmsServerAsyncContact::FindXSPStoresL
       
   678 //
       
   679 // ----------------------------------------------------
       
   680 //
       
   681 void CCmsPhonebookProxy::FindXSPStoresL( CDesCArrayFlat& aArray )
       
   682     {
       
   683     PRINT( _L( "Start CCmsPhonebookProxy::OpenXSPStoresL()" ) );
       
   684 
       
   685     RIdArray ids;
       
   686     CleanupClosePushL( ids );
       
   687     iXspStoresInstalled = EFalse;
       
   688     CSPSettings* settings = CSPSettings::NewL();
       
   689     CleanupStack::PushL( settings );
       
   690     TInt error = settings->FindServiceIdsL( ids );
       
   691     const TInt count = ids.Count();
       
   692     PRINT2( _L( "CCmsPhonebookProxy::OpenXSPStoresL : Error: %d Count: %d" ), error, count );
       
   693 
       
   694     for( TInt i = 0; i < count; i++)
       
   695         {
       
   696         CSPProperty* property = CSPProperty::NewLC();
       
   697         error = settings->FindPropertyL( ids[i], EPropertyContactStoreId, *property );
       
   698         if( KErrNone == error )
       
   699             {
       
   700             RBuf uri;
       
   701             uri.Create( KSPMaxDesLength );
       
   702             CleanupClosePushL( uri );
       
   703             property->GetValue( uri );
       
   704             // Don't add native contact DB's into the find array. Some service 
       
   705             // providers might add e.g. default contacts db as contact store.
       
   706             // Unnecessary lookup from default contacts store is very slow
       
   707             // if there are thousands of contacts, and it will delay the launch
       
   708             // of CCA UI with tens of seconds. 
       
   709             if( IsXspStoreUri( uri ) )
       
   710                 {
       
   711                 TVPbkContactStoreUriPtr uriPtr( uri );
       
   712                 if( !iUriList->IsIncluded( uriPtr ) ) 
       
   713                     {
       
   714                     iUriList->AppendL( uriPtr );            
       
   715                     }
       
   716                 aArray.AppendL( uri );
       
   717                 iXspStoresInstalled = ETrue;
       
   718                 }
       
   719             CleanupStack::PopAndDestroy();  //uri
       
   720             }
       
   721         CleanupStack::PopAndDestroy();  //property
       
   722         }
       
   723     CleanupStack::PopAndDestroy( 2 );  //settings, ids
       
   724     aArray.Sort();
       
   725 
       
   726     PRINT( _L( "End CCmsPhonebookProxy::OpenXSPStoresL()" ) );
       
   727     }
       
   728 
       
   729 // ----------------------------------------------------------
       
   730 // CCmsPhonebookProxy::SelectEventType
       
   731 //
       
   732 // ----------------------------------------------------------
       
   733 //
       
   734 TCmsPhonebookEvent CCmsPhonebookProxy::SelectEventType( TVPbkContactStoreEvent::TVPbkContactStoreEventType aPhonebookEvent )
       
   735     {
       
   736     TCmsPhonebookEvent event = ( TCmsPhonebookEvent )-1;
       
   737     switch( aPhonebookEvent )
       
   738         {
       
   739         case TVPbkContactStoreEvent::EContactDeleted:
       
   740             {
       
   741             event = ECmsContactDeleted;
       
   742             break;
       
   743             }
       
   744         case TVPbkContactStoreEvent::EContactChanged:
       
   745             {
       
   746             event = ECmsContactModified;
       
   747             break;
       
   748             }
       
   749         default:
       
   750             {
       
   751             event = ECmsContactModified;
       
   752             break;
       
   753             }
       
   754         }
       
   755     return event;
       
   756     }
       
   757 
       
   758 
       
   759 // ----------------------------------------------------------
       
   760 // CCmsPhonebookProxy::ResetData
       
   761 //
       
   762 // ----------------------------------------------------------
       
   763 //
       
   764 void CCmsPhonebookProxy::ResetData()
       
   765     {
       
   766     PRINT( _L( "Start CCmsPhonebookProxy::ResetData()" ) );
       
   767     if( iOperation )
       
   768         {
       
   769         delete iOperation;
       
   770         iOperation = NULL;
       
   771         }
       
   772     PRINT( _L( "End CCmsPhonebookProxy::ResetData()" ) );
       
   773     }
       
   774 
       
   775 // ----------------------------------------------------------
       
   776 // CCmsPhonebookProxy::VPbkSingleContactOperationComplete
       
   777 //
       
   778 // ----------------------------------------------------------
       
   779 //
       
   780 void CCmsPhonebookProxy::VPbkSingleContactOperationComplete(
       
   781         MVPbkContactOperationBase& /*aOperation*/,
       
   782         MVPbkStoreContact* aContact )
       
   783     {
       
   784     PRINT( _L( "Start CCmsPhonebookProxy::VPbkSingleContactOperationComplete()" ) );
       
   785 
       
   786     ResetData();
       
   787     CompleteContactRequestL( KErrNone, aContact );
       
   788     iCmsPhonebookOperationsObserver.CmsSingleContactOperationComplete( KErrNone );
       
   789 
       
   790     PRINT( _L( "End CCmsPhonebookProxy::VPbkSingleContactOperationComplete()" ) );
       
   791     }
       
   792 
       
   793 // ----------------------------------------------------------
       
   794 // CCmsPhonebookProxy::~CCmsPhonebookProxy
       
   795 //
       
   796 // ----------------------------------------------------------
       
   797 //
       
   798 void CCmsPhonebookProxy::VPbkSingleContactOperationFailed(
       
   799         MVPbkContactOperationBase& /*aOperation*/,
       
   800         TInt aError )
       
   801     {
       
   802     PRINT1( _L( "CCmsPhonebookProxy::VPbkSingleContactOperationFailed(): Error: %d" ), aError );
       
   803 
       
   804     ResetData();
       
   805     CompleteContactRequestL( aError, NULL );
       
   806     iCmsPhonebookOperationsObserver.CmsSingleContactOperationComplete( aError );    
       
   807     }
       
   808 
       
   809 
       
   810 // ----------------------------------------------------------
       
   811 // CCmsPhonebookProxy::IsXspContact
       
   812 //
       
   813 // ----------------------------------------------------------
       
   814 //
       
   815 TBool CCmsPhonebookProxy::IsXspContact( const MVPbkContactLink& aContactLink ) const
       
   816     {
       
   817     //find whether the contact belongs to XSP Store using the StoreProperties
       
   818     return IsXspStoreUri( 
       
   819         aContactLink.ContactStore().StoreProperties().Uri().UriDes() );
       
   820     }
       
   821 
       
   822 // ----------------------------------------------------------
       
   823 // CCmsPhonebookProxy::IsXspStoreUri
       
   824 // ----------------------------------------------------------
       
   825 //
       
   826 TBool CCmsPhonebookProxy::IsXspStoreUri( const TDesC& aStoreUri ) const
       
   827     {
       
   828     if( aStoreUri.CompareF( VPbkContactStoreUris::DefaultCntDbUri() ) == 0 ||
       
   829         aStoreUri.CompareF( VPbkContactStoreUris::SimGlobalAdnUri() ) == 0 ||
       
   830         aStoreUri.CompareF( VPbkContactStoreUris::SimGlobalFdnUri() ) == 0 ||
       
   831         aStoreUri.CompareF( VPbkContactStoreUris::SimGlobalSdnUri() ) == 0 )
       
   832         {
       
   833         return EFalse;
       
   834         }
       
   835     return ETrue;
       
   836     }
       
   837 
       
   838 // End of File