phonebookui/Phonebook2/ServerApplication/src/CPbk2ItemFetcher.cpp
branchRCL_3
changeset 20 f4a778e096c2
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 application server item fetcher.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2ItemFetcher.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "MPbk2UiServiceObserver.h"
       
    23 #include "TPbk2ServerMessageDataRetriever.h"
       
    24 #include "CPbk2ServerAppAppUi.h"
       
    25 #include "TPbk2TitlePaneOperator.h"
       
    26 #include "CPbk2ServerAppStoreManager.h"
       
    27 #include "CPbk2ContactFetchPhase.h"
       
    28 #include "CPbk2AddressSelectPhase.h"
       
    29 #include <CPbk2StoreManager.h>
       
    30 #include <Pbk2UIControls.rsg>
       
    31 #include <TPbk2AddressSelectParams.h>
       
    32 #include <Pbk2IPCPackage.h>
       
    33 #include <MPbk2ApplicationServices.h>
       
    34 #include "CPbk2CommAddressSelectPhase.h"
       
    35 
       
    36 // Virtual Phonebook
       
    37 #include <CVPbkContactManager.h>
       
    38 #include <CVPbkContactStoreUriArray.h>
       
    39 #include <MVPbkContactLink.h>
       
    40 #include <MVPbkStoreContact.h>
       
    41 #include <CVPbkFieldTypeSelector.h>
       
    42 #include <MVPbkContactStore.h>
       
    43 #include <MVPbkStoreContact.h>
       
    44 #include <TVPbkContactStoreUriPtr.h>
       
    45 
       
    46 // System includes
       
    47 #include <avkon.rsg>
       
    48 #include <spsettings.h>
       
    49 #include <spproperty.h>
       
    50 
       
    51 // Debug
       
    52 #include <Pbk2Debug.h>
       
    53 
       
    54 /// Unnamed namespace for local definitions
       
    55 namespace {
       
    56 
       
    57 /**
       
    58  * Sets title pane.
       
    59  *
       
    60  * @param aDataRetriever    Server message data retriever.
       
    61  * @param aFlags            Fetch flags.
       
    62  * @param aMessage          Server message.
       
    63  */
       
    64 void SetTitlePaneL
       
    65         ( TPbk2ServerMessageDataRetriever& aDataRetriever, TUint aFlags,
       
    66           const RMessage2& aMessage )
       
    67     {
       
    68     HBufC* titlePaneText = NULL;
       
    69     if ( !( aFlags & ::EUseProviderTitle ) )
       
    70         {
       
    71         titlePaneText = aDataRetriever.GetTitlePaneTextL( aMessage );
       
    72         }
       
    73     TPbk2TitlePaneOperator titlePaneOperator;
       
    74     titlePaneOperator.SetTitlePaneL( titlePaneText ); // takes ownership
       
    75     }
       
    76 
       
    77 
       
    78 /**
       
    79  * Change the StatusPane layout to use the mentioned StatusPane ID.
       
    80  *
       
    81  * @param aStatusPaneId     StatusPane ID
       
    82  */
       
    83 void SetStatusPaneL( TInt aStatusPaneId )
       
    84     {
       
    85     CEikStatusPane* statusPane =
       
    86             CEikonEnv::Static()->AppUiFactory()->StatusPane();
       
    87     
       
    88     if ( statusPane && 0 != aStatusPaneId )
       
    89         {
       
    90         statusPane->SwitchLayoutL( aStatusPaneId );        
       
    91         }                    
       
    92     }
       
    93 
       
    94 struct TMap
       
    95     {
       
    96     TAiwCommAddressSelectType aiwType;
       
    97     VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector selectorType;
       
    98     };
       
    99 
       
   100 const TMap KAiwMapTable[] = {
       
   101     { EAiwCommEmpty,            VPbkFieldTypeSelectorFactory::EEmptySelector },
       
   102     { EAiwCommVoiceCall,        VPbkFieldTypeSelectorFactory::EVoiceCallSelector },
       
   103     { EAiwCommUniEditor,        VPbkFieldTypeSelectorFactory::EUniEditorSelector },
       
   104     { EAiwCommEmailEditor,      VPbkFieldTypeSelectorFactory::EEmailEditorSelector },
       
   105     { EAiwCommInstantMessaging, VPbkFieldTypeSelectorFactory::EInstantMessagingSelector },
       
   106     { EAiwCommVOIPCall,         VPbkFieldTypeSelectorFactory::EVOIPCallSelector },
       
   107     { EAiwCommURL,              VPbkFieldTypeSelectorFactory::EURLSelector },
       
   108     { EAiwCommVideoCall,        VPbkFieldTypeSelectorFactory::EVideoCallSelector }
       
   109 };
       
   110 const TInt KAiwMapTableLength = sizeof( KAiwMapTable ) / sizeof( TMap ); 
       
   111 
       
   112 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector
       
   113     MapToCommSelectorType( TAiwCommAddressSelectType aAiwType )
       
   114     {
       
   115     VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector selector =
       
   116         VPbkFieldTypeSelectorFactory::EEmptySelector;
       
   117     for( TInt i = 0; i < KAiwMapTableLength; i++ )
       
   118         {
       
   119         if( aAiwType == KAiwMapTable[i].aiwType)
       
   120             {
       
   121             selector = KAiwMapTable[i].selectorType;
       
   122             break;
       
   123             }
       
   124         }
       
   125     
       
   126     return selector;
       
   127     }
       
   128 
       
   129 /**
       
   130  * Builds contact view filter based on selected address select type.
       
   131  *
       
   132  * @param aType                 Address select type.
       
   133  * @param aFieldTypeList        Master field type list.
       
   134  * @param aShowEmailInSendMsg   Indicates whether email fields are valid
       
   135  *                              for message sending purposes (UniEditor).
       
   136  * @return  Contact view filter.
       
   137  */
       
   138 CVPbkFieldTypeSelector* BuildViewFilterL(
       
   139         TAiwAddressSelectType aType,
       
   140         const MVPbkFieldTypeList& aFieldTypeList,
       
   141         TBool aShowEmailInSendMsg )
       
   142     {
       
   143     CVPbkFieldTypeSelector* selector = NULL;
       
   144     
       
   145     switch( aType )
       
   146         {
       
   147         case EAiwMMSSelect:
       
   148             {
       
   149             // Do not use VPbkFieldTypeSelectorFactory's EUniEditorSelector
       
   150             // filter here, as it's performance is not good.
       
   151             // For view filtering needs, we need to use a fast filter.
       
   152             if ( aShowEmailInSendMsg )
       
   153                 {
       
   154                 selector = VPbkFieldTypeSelectorFactory::BuildFieldTypeSelectorL
       
   155                     ( VPbkFieldTypeSelectorFactory::EMmsAddressSelector,
       
   156                     aFieldTypeList );
       
   157                 }
       
   158             else
       
   159                 {
       
   160                 selector = VPbkFieldTypeSelectorFactory::BuildFieldTypeSelectorL
       
   161                     ( VPbkFieldTypeSelectorFactory::EPhoneNumberSelector,
       
   162                     aFieldTypeList );
       
   163                 }
       
   164             break;
       
   165             }
       
   166         case EAiwEMailSelect:
       
   167             {
       
   168             selector = VPbkFieldTypeSelectorFactory::
       
   169                 BuildContactActionTypeSelectorL(
       
   170                     VPbkFieldTypeSelectorFactory::EEmailEditorSelector,
       
   171                     aFieldTypeList );
       
   172             break;
       
   173             }        
       
   174         case EAiwVideoNumberSelect:
       
   175             {
       
   176             selector = VPbkFieldTypeSelectorFactory::
       
   177                 BuildContactActionTypeSelectorL(
       
   178                     VPbkFieldTypeSelectorFactory::EVideoCallSelector,
       
   179                     aFieldTypeList );
       
   180             break;
       
   181             }
       
   182         case EAiwVOIPSelect:
       
   183             {
       
   184             selector = VPbkFieldTypeSelectorFactory::
       
   185                 BuildContactActionTypeSelectorL(
       
   186                     VPbkFieldTypeSelectorFactory::EVOIPCallSelector,
       
   187                     aFieldTypeList );
       
   188             break;
       
   189             }
       
   190         default:
       
   191             {
       
   192             break;
       
   193             }
       
   194         }
       
   195     
       
   196     return selector;
       
   197     }
       
   198 
       
   199 #ifdef _DEBUG
       
   200 
       
   201 enum TPanicCode
       
   202     {
       
   203     EPanicLogicPhaseCompletion = 1
       
   204     };
       
   205 
       
   206 void Panic( TPanicCode aReason )
       
   207     {
       
   208     _LIT( KPanicText, "CPbk2ItemFetcher" );
       
   209     User::Panic( KPanicText, aReason );
       
   210     }
       
   211 
       
   212 #endif // _DEBUG
       
   213 
       
   214 } /// namespace
       
   215 
       
   216 
       
   217 // --------------------------------------------------------------------------
       
   218 // CPbk2ItemFetcher::CPbk2ItemFetcher
       
   219 // --------------------------------------------------------------------------
       
   220 //
       
   221 CPbk2ItemFetcher::CPbk2ItemFetcher
       
   222         ( MPbk2UiServiceObserver& aObserver,
       
   223           TPbk2FetchType aFetchType ) :
       
   224             iObserver( aObserver ),
       
   225             iFetchType( aFetchType ),
       
   226             iStatusPaneId( 0 )
       
   227     {
       
   228     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   229         ("CPbk2ItemFetcher::CPbk2ItemFetcher()") );
       
   230     }
       
   231 
       
   232 // --------------------------------------------------------------------------
       
   233 // CPbk2ItemFetcher::~CPbk2ItemFetcher
       
   234 // --------------------------------------------------------------------------
       
   235 //
       
   236 CPbk2ItemFetcher::~CPbk2ItemFetcher()
       
   237     {
       
   238     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   239         ("CPbk2ItemFetcher::~CPbk2ItemFetcher()") );
       
   240 
       
   241     delete iStoreUris;
       
   242     delete iContactFetchStoreUris;
       
   243     delete iPreselectedContacts;
       
   244     delete iContactViewFilter;
       
   245     iDefaultPriorities.Close();
       
   246     delete iStoreManager;
       
   247     delete iFetchPhase;
       
   248     delete iAddressSelectPhase;
       
   249     delete iCommAddressSelectPhase;
       
   250     }
       
   251 
       
   252 // --------------------------------------------------------------------------
       
   253 // CPbk2ItemFetcher::NewL
       
   254 // --------------------------------------------------------------------------
       
   255 //
       
   256 CPbk2ItemFetcher* CPbk2ItemFetcher::NewL
       
   257         ( const RMessage2& aFetchCompleteMessage,
       
   258           MPbk2UiServiceObserver& aObserver,
       
   259           TPbk2FetchType aFetchType )
       
   260     {
       
   261     CPbk2ItemFetcher* self =
       
   262         new ( ELeave ) CPbk2ItemFetcher( aObserver, aFetchType );
       
   263     CleanupStack::PushL( self );
       
   264     self->ConstructL( aFetchCompleteMessage );
       
   265     CleanupStack::Pop( self );
       
   266     return self;
       
   267     }
       
   268 
       
   269 // --------------------------------------------------------------------------
       
   270 // CPbk2ItemFetcher::ConstructL
       
   271 // --------------------------------------------------------------------------
       
   272 //
       
   273 inline void CPbk2ItemFetcher::ConstructL( const RMessage2& aMessage )
       
   274     {
       
   275     // Retrieve data from the client-server message
       
   276     CPbk2ServerAppAppUi& appUi =
       
   277         static_cast<CPbk2ServerAppAppUi&>(*CEikonEnv::Static()->EikAppUi());
       
   278 
       
   279     TPbk2ServerMessageDataRetriever dataRetriever;
       
   280     TUint flags = dataRetriever.FetchFlagsL( aMessage );
       
   281 
       
   282     // Set title pane
       
   283     SetTitlePaneL( dataRetriever, flags, aMessage );
       
   284     
       
   285     iStatusPaneId = dataRetriever.GetStatusPaneIdL( aMessage );
       
   286 
       
   287     iPreselectedContacts = dataRetriever.GetPreselectedContactLinksL
       
   288         ( aMessage, appUi.ApplicationServices().ContactManager() );
       
   289     iStoreUris = dataRetriever.GetContactStoreUriArrayL
       
   290         ( aMessage, appUi.ApplicationServices().StoreConfiguration(),
       
   291           iPreselectedContacts, iUseDeviceConfig );
       
   292     
       
   293     // Contact fetch store uris, not including xSP stores
       
   294     iContactFetchStoreUris = CVPbkContactStoreUriArray::NewL();
       
   295     iContactFetchStoreUris->AppendAllL(*iStoreUris); 
       
   296     
       
   297     TAiwCommAddressSelectType selectorType = 
       
   298         dataRetriever.GetCommAddressSelectTypeL( aMessage );
       
   299     iCommAddressSelectType = MapToCommSelectorType( selectorType );
       
   300     
       
   301     iAddressSelectType = dataRetriever.GetAddressSelectTypeL( aMessage );
       
   302     
       
   303     // Create contact filters
       
   304     if ( iCommAddressSelectType != VPbkFieldTypeSelectorFactory::EEmptySelector )
       
   305         {
       
   306         iContactViewFilter = VPbkFieldTypeSelectorFactory::
       
   307         	BuildContactActionTypeSelectorL( iCommAddressSelectType,
       
   308                 appUi.ApplicationServices().ContactManager().FieldTypes() );
       
   309         }
       
   310     // Phonebook specific filters take prefference over the
       
   311     // filter specified by client
       
   312     else
       
   313         {
       
   314         iContactViewFilter = BuildViewFilterL( iAddressSelectType,
       
   315                 appUi.ApplicationServices().ContactManager().FieldTypes(),
       
   316                 appUi.ApplicationServices().LocallyVariatedFeatureEnabled
       
   317                 ( EVPbkLVShowEmailInSendMsg ) );
       
   318         
       
   319         // Filter specified by client
       
   320         if ( iContactViewFilter == NULL )
       
   321             {
       
   322             iContactViewFilter = dataRetriever.GetContactViewFilterL
       
   323                 ( aMessage, appUi.ApplicationServices().ContactManager().
       
   324                   FieldTypes() );
       
   325             }
       
   326         }
       
   327 
       
   328     iFetchResId = dataRetriever.GetFetchDialogResourceL( aMessage );
       
   329 
       
   330     iStoreManager = CPbk2ServerAppStoreManager::NewL
       
   331         ( appUi.StoreManager(),
       
   332           appUi.ApplicationServices().ContactManager() );
       
   333 
       
   334     if ( iCommAddressSelectType != VPbkFieldTypeSelectorFactory::EEmptySelector )
       
   335         {
       
   336         GetDefaultPriorities( flags );
       
   337         }
       
   338     else
       
   339         {
       
   340         iDefaultPriorities = dataRetriever.FetchDefaultPrioritiesL( aMessage );
       
   341         }
       
   342     
       
   343     if ( iCommAddressSelectType != VPbkFieldTypeSelectorFactory::EEmptySelector )
       
   344         {
       
   345         // add also xSP stores to the store list
       
   346         AddXSPStoresL();
       
   347         }
       
   348     }
       
   349 
       
   350 // --------------------------------------------------------------------------
       
   351 // CPbk2ItemFetcher::LaunchServiceL
       
   352 // --------------------------------------------------------------------------
       
   353 //
       
   354 void CPbk2ItemFetcher::LaunchServiceL()
       
   355     {
       
   356     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   357         ("CPbk2ItemFetcher::LaunchServiceL()") );
       
   358 
       
   359     iStoreManager->LoadAndOpenContactStoresL( *iStoreUris, *this, EFalse );
       
   360     }
       
   361 
       
   362 // --------------------------------------------------------------------------
       
   363 // CPbk2ItemFetcher::CancelService
       
   364 // --------------------------------------------------------------------------
       
   365 //
       
   366 void CPbk2ItemFetcher::CancelService()
       
   367     {
       
   368     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   369         ("CPbk2ItemFetcher::CancelService()") );
       
   370 
       
   371     if ( iFetchPhase )
       
   372         {
       
   373         iFetchPhase->CancelServicePhase();
       
   374         }
       
   375 
       
   376     if ( iAddressSelectPhase )
       
   377         {
       
   378         iAddressSelectPhase->CancelServicePhase();
       
   379         }
       
   380 
       
   381    if ( iCommAddressSelectPhase )
       
   382         {
       
   383         iCommAddressSelectPhase->CancelServicePhase();
       
   384         }
       
   385     }
       
   386 
       
   387 // --------------------------------------------------------------------------
       
   388 // CPbk2ItemFetcher::AcceptDelayedContactsL
       
   389 // --------------------------------------------------------------------------
       
   390 //
       
   391 void CPbk2ItemFetcher::AcceptDelayedContactsL
       
   392         ( const TDesC8& aContactLinkBuffer )
       
   393     {
       
   394     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   395         ("CPbk2ItemFetcher::AcceptDelayedContactsL()") );
       
   396 
       
   397     if ( iAddressSelectPhase )
       
   398         {
       
   399         iAddressSelectPhase->AcceptDelayedL( aContactLinkBuffer );
       
   400         }
       
   401 
       
   402     if ( iCommAddressSelectPhase )
       
   403         {
       
   404         iCommAddressSelectPhase->AcceptDelayedL( aContactLinkBuffer );
       
   405         }
       
   406 
       
   407     if ( iFetchPhase )
       
   408         {
       
   409         iFetchPhase->AcceptDelayedL( aContactLinkBuffer );
       
   410         }
       
   411     }
       
   412 // --------------------------------------------------------------------------
       
   413 // CPbk2ItemFetcher::DenyDelayedContactsL
       
   414 // --------------------------------------------------------------------------
       
   415 //
       
   416 void CPbk2ItemFetcher::DenyDelayedContactsL
       
   417         ( const TDesC8& aContactLinkBuffer )
       
   418     {
       
   419     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   420         ("CPbk2ItemFetcher::DenyDelayedContactsL()") );
       
   421 
       
   422     if ( iAddressSelectPhase )
       
   423         {
       
   424         iAddressSelectPhase->DenyDelayedL( aContactLinkBuffer );
       
   425         }
       
   426 
       
   427     if ( iCommAddressSelectPhase )
       
   428         {
       
   429         iCommAddressSelectPhase->DenyDelayedL( aContactLinkBuffer );
       
   430         }
       
   431 
       
   432     if ( iFetchPhase )
       
   433         {
       
   434         iFetchPhase->DenyDelayedL( aContactLinkBuffer );
       
   435         }
       
   436     }
       
   437 
       
   438 // --------------------------------------------------------------------------
       
   439 // CPbk2ItemFetcher::ExitServiceL
       
   440 // --------------------------------------------------------------------------
       
   441 //
       
   442 void CPbk2ItemFetcher::ExitServiceL( TInt aExitCommandId )
       
   443     {
       
   444     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   445         ("CPbk2ItemFetcher::ExitServiceL(%d)"), aExitCommandId );
       
   446 
       
   447     if ( iAddressSelectPhase )
       
   448         {
       
   449         iAddressSelectPhase->RequestCancelL( aExitCommandId );
       
   450 
       
   451         // Report fetch aborting and close application
       
   452         iObserver.ServiceAborted();
       
   453         }
       
   454 
       
   455     if ( iCommAddressSelectPhase )
       
   456         {
       
   457         iCommAddressSelectPhase->RequestCancelL( aExitCommandId );
       
   458 
       
   459         // Report fetch aborting and close application
       
   460         iObserver.ServiceAborted();
       
   461         }
       
   462 
       
   463     if ( iFetchPhase )
       
   464         {
       
   465         iFetchPhase->RequestCancelL( aExitCommandId );
       
   466         }
       
   467     }
       
   468 
       
   469 // --------------------------------------------------------------------------
       
   470 // CPbk2ItemFetcher::ServiceResults
       
   471 // --------------------------------------------------------------------------
       
   472 //
       
   473 void CPbk2ItemFetcher::ServiceResults(TServiceResults* aResults) const
       
   474     {
       
   475     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   476         ("CPbk2ItemFetcher::ServiceResults()") );
       
   477 
       
   478     if ( iAddressSelectPhase )
       
   479         {
       
   480         aResults->iLinkArray = iAddressSelectPhase->Results();
       
   481         aResults->iExtraData = iAddressSelectPhase->ExtraResultData();
       
   482         aResults->iFieldContent = NULL;
       
   483         }
       
   484         
       
   485     if ( iCommAddressSelectPhase )
       
   486         {
       
   487         aResults->iLinkArray = iCommAddressSelectPhase->Results();
       
   488         aResults->iExtraData = iCommAddressSelectPhase->ExtraResultData();
       
   489         aResults->iFieldContent = iCommAddressSelectPhase->FieldContent();
       
   490         }
       
   491     }
       
   492 
       
   493 // --------------------------------------------------------------------------
       
   494 // CPbk2ItemFetcher::NextPhase
       
   495 // --------------------------------------------------------------------------
       
   496 //
       
   497 void CPbk2ItemFetcher::NextPhase( MPbk2ServicePhase& aPhase )
       
   498     {
       
   499     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   500         ("CPbk2ItemFetcher::NextPhase()") );
       
   501 
       
   502     if ( &aPhase == iFetchPhase )
       
   503         {
       
   504         MVPbkContactLinkArray* fetchResult = iFetchPhase->Results();
       
   505         __ASSERT_DEBUG( fetchResult && fetchResult->Count() > 0,
       
   506             Panic( EPanicLogicPhaseCompletion ) );
       
   507 
       
   508         TRAPD( err, LaunchAddressSelectPhaseL( *fetchResult ) );
       
   509         if ( err != KErrNone )
       
   510             {
       
   511             iObserver.ServiceError( err );
       
   512             }
       
   513         }
       
   514     else if ( &aPhase == iAddressSelectPhase || 
       
   515               &aPhase == iCommAddressSelectPhase )
       
   516         {
       
   517         // Address select was the last phase
       
   518         iObserver.ServiceComplete();
       
   519         }
       
   520     else
       
   521         {
       
   522         __ASSERT_DEBUG( EFalse, Panic( EPanicLogicPhaseCompletion ) );
       
   523         }
       
   524     }
       
   525 
       
   526 // --------------------------------------------------------------------------
       
   527 // CPbk2ItemFetcher::PreviousPhase
       
   528 // --------------------------------------------------------------------------
       
   529 //
       
   530 void CPbk2ItemFetcher::PreviousPhase( MPbk2ServicePhase& /*aPhase*/ )
       
   531     {
       
   532     // Do nothing
       
   533     }
       
   534 
       
   535 // --------------------------------------------------------------------------
       
   536 // CPbk2ItemFetcher::PhaseCanceled
       
   537 // --------------------------------------------------------------------------
       
   538 //
       
   539 void CPbk2ItemFetcher::PhaseCanceled( MPbk2ServicePhase& aPhase )
       
   540     {
       
   541     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   542         ("CPbk2ItemFetcher::PhaseCanceled()") );
       
   543 
       
   544     // We cannot cancel the phase completely if the cancellation
       
   545     // was done from address phase and fetch phase dialog still exists and
       
   546     // we are dealing with singleitemfetch
       
   547     if ( ( ( &aPhase != iAddressSelectPhase ) && 
       
   548          ( &aPhase != iCommAddressSelectPhase ) ) || 
       
   549          !iFetchPhase ||
       
   550          iFetchType == EMultipleItemFetch )
       
   551         {
       
   552         iObserver.ServiceCanceled();
       
   553         }
       
   554     }
       
   555 
       
   556 // --------------------------------------------------------------------------
       
   557 // CPbk2ItemFetcher::PhaseAborted
       
   558 // --------------------------------------------------------------------------
       
   559 //
       
   560 void CPbk2ItemFetcher::PhaseAborted( MPbk2ServicePhase& /*aPhase*/ )
       
   561     {
       
   562     iObserver.ServiceAborted();
       
   563     }
       
   564 
       
   565 // --------------------------------------------------------------------------
       
   566 // CPbk2ItemFetcher::PhaseError
       
   567 // --------------------------------------------------------------------------
       
   568 //
       
   569 void CPbk2ItemFetcher::PhaseError
       
   570         ( MPbk2ServicePhase& /*aPhase*/, TInt aErrorCode )
       
   571     {
       
   572     iObserver.ServiceError( aErrorCode );
       
   573     }
       
   574 
       
   575 // --------------------------------------------------------------------------
       
   576 // CPbk2ItemFetcher::PhaseOkToExit
       
   577 // --------------------------------------------------------------------------
       
   578 //
       
   579 TBool CPbk2ItemFetcher::PhaseOkToExit
       
   580         ( MPbk2ServicePhase& /*aPhase*/, TInt aCommandId )
       
   581     {
       
   582     // Deny exit and pass an asynchronous query to the consumer,
       
   583     // which may later approve exit
       
   584     iObserver.CompleteExitMessage( aCommandId );
       
   585     return EFalse;
       
   586     }
       
   587 
       
   588 // --------------------------------------------------------------------------
       
   589 // CPbk2ItemFetcher::PhaseAccept
       
   590 // --------------------------------------------------------------------------
       
   591 //
       
   592 void CPbk2ItemFetcher::PhaseAccept
       
   593         ( MPbk2ServicePhase& /*aPhase*/, const TDesC8& aMarkedEntries,
       
   594           const TDesC8& aLinkData )
       
   595     {
       
   596     iObserver.CompleteAcceptMsg( aMarkedEntries, aLinkData );
       
   597     }
       
   598 
       
   599 // --------------------------------------------------------------------------
       
   600 // CPbk2ItemFetcher::ContactUiReadyL
       
   601 // --------------------------------------------------------------------------
       
   602 //
       
   603 void CPbk2ItemFetcher::ContactUiReadyL
       
   604         ( MPbk2StartupMonitor& aStartupMonitor )
       
   605     {
       
   606     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   607         ("CPbk2ItemFetcher::ContactUiReadyL()") );
       
   608 
       
   609     aStartupMonitor.DeregisterEvents( *this );
       
   610 
       
   611     if ( !iPreselectedContacts || iPreselectedContacts->Count() == 0 )
       
   612         {
       
   613         LaunchFetchPhaseL();
       
   614         }
       
   615     else
       
   616         {
       
   617         if ( iStoreManager->ContactsAvailableL( *iPreselectedContacts ) )
       
   618             {
       
   619             LaunchAddressSelectPhaseL( *iPreselectedContacts );
       
   620             }
       
   621         else
       
   622             {
       
   623             iObserver.ServiceError( KErrNotSupported );
       
   624             }
       
   625         }
       
   626     }
       
   627 
       
   628 // --------------------------------------------------------------------------
       
   629 // CPbk2ItemFetcher::StartupCanceled
       
   630 // --------------------------------------------------------------------------
       
   631 //
       
   632 void CPbk2ItemFetcher::StartupCanceled( TInt aErrorCode )
       
   633     {
       
   634     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   635         ("CPbk2ItemFetcher::StartupCanceled()"), aErrorCode );
       
   636 
       
   637     if ( aErrorCode == KErrCancel )
       
   638         {
       
   639         iObserver.ServiceCanceled();
       
   640         }
       
   641     else
       
   642         {
       
   643         iObserver.ServiceError( aErrorCode );
       
   644         }
       
   645     }
       
   646 
       
   647 // --------------------------------------------------------------------------
       
   648 // CPbk2ItemFetcher::LaunchFetchPhaseL
       
   649 // --------------------------------------------------------------------------
       
   650 //
       
   651 void CPbk2ItemFetcher::LaunchFetchPhaseL()
       
   652     {
       
   653     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   654         ("CPbk2ItemFetcher::LaunchFetchPhaseL()") );
       
   655 
       
   656     // By default fetch cannot exit
       
   657     TBool fetchOkToExit = EFalse;
       
   658 
       
   659     CPbk2FetchDlg::TParams params;
       
   660     params.iResId = R_PBK2_SINGLE_ENTRY_FETCH_DLG;
       
   661     params.iFlags = CPbk2FetchDlg::EFetchSingle;
       
   662 
       
   663     if ( iFetchType == ECallItemFetch )
       
   664         {
       
   665         params.iResId = R_PBK2_CALL_ITEM_FETCH_DLG;
       
   666         params.iFlags = CPbk2FetchDlg::EFetchCallItem;
       
   667         }
       
   668     else if ( iFetchType == EMultipleItemFetch )
       
   669         {
       
   670         params.iResId = R_PBK2_MULTIPLE_ENTRY_FETCH_DLG;
       
   671         params.iFlags = CPbk2FetchDlg::EFetchMultiple;
       
   672 
       
   673         // In multiple entry fetch, fetch can exit
       
   674         fetchOkToExit = ETrue;
       
   675         }
       
   676 
       
   677     delete iFetchPhase;
       
   678     iFetchPhase = NULL;
       
   679     iFetchPhase = CPbk2ContactFetchPhase::NewL
       
   680         ( *this, *iStoreManager, params, fetchOkToExit,
       
   681           MPbk2FetchDlgObserver::EFetchDelayed, iContactViewFilter,
       
   682           iUseDeviceConfig, iContactFetchStoreUris );
       
   683 
       
   684     CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&>
       
   685         ( *CEikonEnv::Static()->EikAppUi() );
       
   686 
       
   687     // Change layout to fetch's layout
       
   688     appUi.ChangeStatuspaneLayoutL(
       
   689         CPbk2ServerAppAppUi::EStatusPaneLayoutUsual );
       
   690 
       
   691     iFetchPhase->LaunchServicePhaseL();
       
   692     }
       
   693 
       
   694 // --------------------------------------------------------------------------
       
   695 // CPbk2ItemFetcher::LaunchAddressSelectPhaseL
       
   696 // --------------------------------------------------------------------------
       
   697 //
       
   698 void CPbk2ItemFetcher::LaunchAddressSelectPhaseL
       
   699         ( MVPbkContactLinkArray& aContactLinks )
       
   700     {
       
   701     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   702         ("CPbk2ItemFetcher::LaunchAddressSelectPhaseL()") );
       
   703 
       
   704     // By default RSK is 'Back'
       
   705     TBool rskBack = ETrue;
       
   706 
       
   707     // RSK is cancel in case of multiple item fetch
       
   708     // or if there are preselected contacts
       
   709     if ( iFetchType == EMultipleItemFetch )
       
   710         {
       
   711         rskBack = EFalse;
       
   712         }
       
   713     else if ( iPreselectedContacts && iPreselectedContacts->Count() != 0 )
       
   714         {
       
   715         rskBack = EFalse;
       
   716         }
       
   717 
       
   718     delete iAddressSelectPhase;
       
   719     iAddressSelectPhase = NULL;
       
   720     delete iCommAddressSelectPhase;
       
   721     iCommAddressSelectPhase = NULL;
       
   722     
       
   723     //Restore the appropriate StatusPane
       
   724     SetStatusPaneL( iStatusPaneId );
       
   725     
       
   726     if ( iCommAddressSelectType != VPbkFieldTypeSelectorFactory::EEmptySelector )
       
   727         {
       
   728         iCommAddressSelectPhase = CPbk2CommAddressSelectPhase::NewL
       
   729             ( *this, aContactLinks.At( 0 ), iDefaultPriorities,
       
   730               *iContactViewFilter, iCommAddressSelectType, rskBack );
       
   731 
       
   732         iCommAddressSelectPhase->LaunchServicePhaseL();
       
   733         }
       
   734     else
       
   735         {
       
   736         iAddressSelectPhase = CPbk2AddressSelectPhase::NewL
       
   737             ( *this, aContactLinks, iDefaultPriorities,
       
   738             iAddressSelectType, rskBack );
       
   739 
       
   740         iAddressSelectPhase->LaunchServicePhaseL();
       
   741         }
       
   742     }
       
   743 
       
   744 // --------------------------------------------------------------------------
       
   745 // CPbk2ItemFetcher::AddXSPStoresL
       
   746 // --------------------------------------------------------------------------
       
   747 //
       
   748 void CPbk2ItemFetcher::AddXSPStoresL()
       
   749     {
       
   750     RIdArray ids;
       
   751     CleanupClosePushL( ids );
       
   752     CSPSettings* settings = CSPSettings::NewL();
       
   753     CleanupStack::PushL( settings ); 
       
   754     TInt error = settings->FindServiceIdsL( ids );  
       
   755     const TInt count = ids.Count();
       
   756 
       
   757     for( TInt i = 0; i < count; i++ )
       
   758         {
       
   759         CSPProperty* property = CSPProperty::NewLC();
       
   760         error = settings->FindPropertyL( ids[i], EPropertyContactStoreId,
       
   761             *property );
       
   762         if( KErrNone == error )
       
   763             {
       
   764             RBuf uri;
       
   765             uri.Create( KSPMaxDesLength );
       
   766             CleanupClosePushL( uri );  
       
   767             property->GetValue( uri );
       
   768             TVPbkContactStoreUriPtr uriPtr( uri );
       
   769             iStoreUris->AppendL( uriPtr );
       
   770             CleanupStack::PopAndDestroy();  //uri
       
   771             }
       
   772         CleanupStack::PopAndDestroy();  //property
       
   773         }
       
   774     CleanupStack::PopAndDestroy( 2 );  //settings, ids
       
   775     }
       
   776 
       
   777 // --------------------------------------------------------------------------
       
   778 // CPbk2ItemFetcher::GetDefaultPriorities
       
   779 // --------------------------------------------------------------------------
       
   780 //
       
   781 void CPbk2ItemFetcher::GetDefaultPriorities( TUint aFlags )
       
   782     {
       
   783     if ( !( aFlags & ::EDoNotUseDefaultField ) )
       
   784         {
       
   785         switch ( iCommAddressSelectType )
       
   786             {
       
   787             // Errors during Append() operation are ignored, in this case 
       
   788             // address select dialog will be shown instead of immediate return
       
   789             // of the default field.
       
   790             case VPbkFieldTypeSelectorFactory::EVoiceCallSelector:
       
   791                 {
       
   792                 iDefaultPriorities.Append( EVPbkDefaultTypePhoneNumber );
       
   793                 break;
       
   794                 }
       
   795             case VPbkFieldTypeSelectorFactory::EUniEditorSelector:
       
   796                 {
       
   797                 iDefaultPriorities.Append( EVPbkDefaultTypeSms );
       
   798                 iDefaultPriorities.Append( EVPbkDefaultTypeMms );
       
   799                 break;
       
   800                 }
       
   801             case VPbkFieldTypeSelectorFactory::EVideoCallSelector:
       
   802                 {
       
   803                 iDefaultPriorities.Append( EVPbkDefaultTypeVideoNumber );
       
   804                 break;
       
   805                 }
       
   806             case VPbkFieldTypeSelectorFactory::EEmailEditorSelector:
       
   807                 {
       
   808                 iDefaultPriorities.Append( EVPbkDefaultTypeEmail );
       
   809                 break;    
       
   810                 }
       
   811             case VPbkFieldTypeSelectorFactory::EVOIPCallSelector:
       
   812                 {
       
   813                 iDefaultPriorities.Append( EVPbkDefaultTypeVoIP );
       
   814                 break;
       
   815                 }
       
   816             case VPbkFieldTypeSelectorFactory::EPocSelector:
       
   817                 {
       
   818                 iDefaultPriorities.Append( EVPbkDefaultTypePOC );
       
   819                 break;
       
   820                 }
       
   821             case VPbkFieldTypeSelectorFactory::EURLSelector :
       
   822                 {
       
   823                 iDefaultPriorities.Append( EVPbkDefaultTypeOpenLink );
       
   824                 break;
       
   825                 }
       
   826             case VPbkFieldTypeSelectorFactory::EInstantMessagingSelector :
       
   827                 {
       
   828                 iDefaultPriorities.Append( EVPbkDefaultTypeChat );
       
   829                 break;
       
   830                 }
       
   831             default:
       
   832                 {
       
   833                 break;
       
   834                 }
       
   835             }
       
   836         }
       
   837     }
       
   838 // End of File