emailcontacts/remotecontactlookup/engine/src/cpbkxrclserviceuicontextimpl.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 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:  Implementation of the class CPbkxRclServiceUiContextImpl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <pbkxrclengine.rsg>
       
    21 #include <cntfldst.h>
       
    22 #include <StringLoader.h>
       
    23 #include <CPbkContactEngine.h>
       
    24 #include <bautils.h>
       
    25 #include <textresolver.h>
       
    26 //<cmail>
       
    27 #include "fsccontactactionservicedefines.h"
       
    28 //</cmail>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 #include <AknsUtils.h>
       
    31 #include <hlplch.h>
       
    32 
       
    33 #include "cpbkxrclserviceuicontextimpl.h"
       
    34 #include "pbkxremotecontactlookuppanic.h"
       
    35 #include "cpbkxremotecontactlookupprotocolsession.h"
       
    36 #include "cpbkxrclprotocolenvimpl.h"
       
    37 #include "cpbkxremotecontactlookupprotocoladapter.h"
       
    38 #include "cpbkxremotecontactlookupprotocolaccount.h"
       
    39 
       
    40 #include "cpbkxrclsearchresultdlg.h"
       
    41 #include "cpbkxrclresultinfodlg.h"
       
    42 #include "cpbkxrclqueryeditor.h"
       
    43 #include "cpbkxrclactionservicewrapper.h"
       
    44 
       
    45 #include "pbkxrclutils.h"
       
    46 #include "pbkxrclengineconstants.h"
       
    47 
       
    48 #include "engine.hrh"
       
    49 #include <aknnotewrappers.h>
       
    50 
       
    51 // own macro to handle errors in traps
       
    52 // <cmail> Do not use, produces Codescanner warnings
       
    53 //#define EXIT_IF_ERROR( xxx ) { TRAPD( err, xxx ); if ( err != KErrNone ) HandleError( err ); }
       
    54 // </cmail>
       
    55 
       
    56 /// Unnamed namespace for local definitions
       
    57 namespace {
       
    58 const TInt KTwoMinutesTimerInterval(120000000);
       
    59 } /// namespace
       
    60 
       
    61 // ======== MEMBER FUNCTIONS ========
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CPbkxRclServiceUiContextImpl::NewL
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CPbkxRclServiceUiContextImpl* CPbkxRclServiceUiContextImpl::NewL(
       
    68     TPbkxRemoteContactLookupProtocolAccountId aId,
       
    69     TMode aMode )
       
    70     {
       
    71     FUNC_LOG;
       
    72     CPbkxRclServiceUiContextImpl* context = 
       
    73         CPbkxRclServiceUiContextImpl::NewLC( aId, aMode );
       
    74     CleanupStack::Pop( context );
       
    75     return context;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CPbkxRclServiceUiContextImpl::NewLC
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CPbkxRclServiceUiContextImpl* CPbkxRclServiceUiContextImpl::NewLC(
       
    83     TPbkxRemoteContactLookupProtocolAccountId aId,
       
    84     TMode aMode )
       
    85     {
       
    86     FUNC_LOG;
       
    87     CPbkxRclServiceUiContextImpl* context = 
       
    88         new ( ELeave ) CPbkxRclServiceUiContextImpl( aId, aMode );
       
    89     CleanupStack::PushL( context );
       
    90     context->ConstructL();
       
    91     return context;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CPbkxRclServiceUiContextImpl::CPbkxRclServiceUiContextImpl
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CPbkxRclServiceUiContextImpl::CPbkxRclServiceUiContextImpl(
       
    99     TPbkxRemoteContactLookupProtocolAccountId aId,
       
   100     TMode aMode ) : 
       
   101     iAccountId( aId ), iMode( aMode ), iSelectedIndex( KErrNotFound )
       
   102     {
       
   103     FUNC_LOG;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CPbkxRclServiceUiContextImpl::~CPbkxRclServiceUiContextImpl
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 CPbkxRclServiceUiContextImpl::~CPbkxRclServiceUiContextImpl()
       
   111     {
       
   112     FUNC_LOG;
       
   113 
       
   114     if( iTimer )
       
   115         {
       
   116         iTimer->Cancel();
       
   117         }
       
   118     delete iTimer;
       
   119 
       
   120     iQueryText.Close();
       
   121     iQueryCriteria.Close();
       
   122 
       
   123     CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset );
       
   124 
       
   125     iContactCards.Reset();
       
   126     iSearchResults.ResetAndDestroy();
       
   127     iWaitObjects.ResetAndDestroy();
       
   128     delete iContactEngine;
       
   129 
       
   130     delete iActionServiceWrapper;
       
   131 
       
   132     delete iAccount;
       
   133     delete iSession;
       
   134     delete iAdapter;
       
   135     delete iEnvImpl;
       
   136 
       
   137     delete iEventScheduler;
       
   138     
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CPbkxRclServiceUiContextImpl::ConstructL
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CPbkxRclServiceUiContextImpl::ConstructL()
       
   146     {
       
   147     FUNC_LOG;
       
   148 
       
   149     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   150 
       
   151     TFileName dllFileName;
       
   152     Dll::FileName( dllFileName );
       
   153       
       
   154     TParse parse;
       
   155     parse.Set( KResourceFile, &KDC_APP_RESOURCE_DIR, &dllFileName );
       
   156     TFileName resourceFile = parse.FullName();
       
   157     BaflUtils::NearestLanguageFile( coeEnv->FsSession(), resourceFile );
       
   158 
       
   159     TRAPD( status,
       
   160            iResourceFileOffset = coeEnv->AddResourceFileL( resourceFile ) );
       
   161     
       
   162     if( status != KErrNone )
       
   163         {
       
   164     	PbkxRclPanic( EPbkxRclPanicGeneral );		
       
   165         }
       
   166 	else 
       
   167         {
       
   168         }
       
   169 
       
   170     // create default contact engine to use to create CPbkContactItems
       
   171     iContactEngine = CPbkContactEngine::NewL();
       
   172 
       
   173     // create actions service wrapper used by UI views
       
   174     iActionServiceWrapper = CPbkxRclActionServiceWrapper::NewL( *iContactEngine );
       
   175 
       
   176     iActionServiceWrapper->SetContactSelectorMode( 
       
   177         iMode == EModeContactSelector );
       
   178 
       
   179     // Create objects needed for executing the search
       
   180     iEnvImpl = CPbkxRclProtocolEnvImpl::NewL();
       
   181     
       
   182     iAdapter = CPbkxRemoteContactLookupProtocolAdapter::NewL( 
       
   183         iAccountId.iProtocolUid, 
       
   184         *iEnvImpl );
       
   185 
       
   186     iAccount = iAdapter->NewProtocolAccountL( iAccountId );
       
   187 
       
   188     if ( iAccount == NULL )
       
   189         {
       
   190         User::Leave( KErrNotFound );
       
   191         }
       
   192     
       
   193     iSession = iAdapter->NewSessionL();
       
   194     iSession->InitializeL( *this, iAccountId );
       
   195 
       
   196     iEventScheduler = CPbkxRclEventScheduler::NewL( *this );
       
   197     
       
   198     iTimer = CPeriodic::NewL( CActive::EPriorityIdle );
       
   199 
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CPbkxRclServiceUiContextImpl::GetSelectedContactL
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 CContactItem* CPbkxRclServiceUiContextImpl::GetSelectedContactL()
       
   207     {
       
   208     FUNC_LOG;
       
   209     __ASSERT_ALWAYS( iSelectedIndex >= 0 && iSelectedIndex < iContactCards.Count(),
       
   210                      PbkxRclPanic( EPbkxRclPanicGeneral ) );
       
   211     CContactCard* selected = iContactCards[iSelectedIndex];
       
   212     CContactCard* copy = CContactCard::NewL( selected );
       
   213     return copy;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CPbkxRclServiceUiContextImpl::GetResultByIndex
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 CPbkxRemoteContactLookupProtocolResult* 
       
   221 CPbkxRclServiceUiContextImpl::GetResultByIndex( TInt aIndex )
       
   222     {
       
   223     __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iContactCards.Count(), 
       
   224                      PbkxRclPanic( EPbkxRclPanicGeneral ) );
       
   225   
       
   226     CContactCard* card = iContactCards[aIndex];
       
   227     CPbkxRemoteContactLookupProtocolResult* result = NULL;
       
   228     for ( TInt i = 0; i < iSearchResults.Count(); i++ )
       
   229         {
       
   230         if ( card == &( iSearchResults[i]->ContactItem() ) )
       
   231             {
       
   232             result = iSearchResults[i];
       
   233             break;
       
   234             }
       
   235         }
       
   236 
       
   237     __ASSERT_ALWAYS( result != NULL, PbkxRclPanic( EPbkxRclPanicGeneral ) );
       
   238 
       
   239     return result;
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // CPbkxRclServiceUiContextImpl::ExecuteL
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 void CPbkxRclServiceUiContextImpl::ExecuteL( const TDesC& aQueryText, TResult& aResult )
       
   247     {
       
   248     FUNC_LOG;
       
   249 
       
   250     // set state as initial
       
   251     ResetState();
       
   252     SetState( EInitial );
       
   253     iExitCode = KErrNone;
       
   254 
       
   255     iSearchResults.ResetAndDestroy();
       
   256 
       
   257     iQueryCriteria.Close();
       
   258     iQueryCriteria.CreateL( KRclQueryTextMaxLength );
       
   259     iQueryCriteria = aQueryText.Left( KRclQueryTextMaxLength );
       
   260 
       
   261     iResult = &aResult;
       
   262 
       
   263     TOperation op = ( iMode != EModeExistingCriteria ) ? 
       
   264         EOpenSearchQueryDefault : EExecuteSearchWithNoQuery;
       
   265     
       
   266     AddOperation( op );
       
   267         
       
   268     StartActiveWaitL( EMainWait );
       
   269 
       
   270     
       
   271     HandleContextExitL();
       
   272 
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // CPbkxRclServiceUiContextImpl::LooseSearchCompleted
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 void CPbkxRclServiceUiContextImpl::LooseSearchCompleted(
       
   280     TInt aStatus,
       
   281     RPointerArray<CPbkxRemoteContactLookupProtocolResult>& aResults )
       
   282     {
       
   283     FUNC_LOG;
       
   284 
       
   285     // <cmail>
       
   286     TRAPD( err, DoLooseSearchCompletedL( aStatus, aResults ) );
       
   287     if ( err != KErrNone )
       
   288         {
       
   289         HandleError( err );
       
   290         }
       
   291     // </cmail>
       
   292     
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // CPbkxRclServiceUiContextImpl::ContactFieldsRetrievalCompleted
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void CPbkxRclServiceUiContextImpl::ContactFieldsRetrievalCompleted( TInt aStatus )
       
   300     {
       
   301     FUNC_LOG;
       
   302 
       
   303     // <cmail>
       
   304     TRAPD( err, DoContactFieldsRetrievalCompletedL( aStatus ) );
       
   305     if ( err != KErrNone )
       
   306         {
       
   307         HandleError( err );
       
   308         }
       
   309     // </cmail>
       
   310 
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // CPbkxRclServiceUiContextImpl::RetrieveDetailsL
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 CContactCard* CPbkxRclServiceUiContextImpl::RetrieveDetailsL( 
       
   318     TInt aContactIndex,
       
   319     const TDesC& aWaitNoteText )
       
   320     {
       
   321     FUNC_LOG;
       
   322 
       
   323     CPbkxRemoteContactLookupProtocolResult* result = GetResultByIndex( aContactIndex );
       
   324 
       
   325     CContactCard* card = static_cast<CContactCard*>( &result->ContactItem() );
       
   326 
       
   327     if ( !result->IsComplete() )
       
   328         {
       
   329         
       
   330         RPointerArray<CPbkxRemoteContactLookupProtocolResult> array;
       
   331         CleanupClosePushL( array );
       
   332         array.AppendL( result );
       
   333 
       
   334         iSession->RetrieveContactFieldsL( array );
       
   335 
       
   336         // Start time for time out event
       
   337         iTimer->Start(
       
   338         		KTwoMinutesTimerInterval, KTwoMinutesTimerInterval, 
       
   339             TCallBack(TimerCallBack, this));
       
   340         
       
   341         DisplayWaitDialogL( R_RCL_SEARCH_WAIT_DIALOG_CANCEL, aWaitNoteText );
       
   342 
       
   343         // Start active wait. When contact retrieval is completed, 
       
   344         // ContactFieldsRetrievalCompleted is called. If user cancels
       
   345         // retrieval, DialogDismissedL is called. TimeOut is called when time is out.
       
   346         StartActiveWaitL( EContactRetrievalWait );
       
   347         
       
   348         CleanupStack::PopAndDestroy( &array );
       
   349         
       
   350 
       
   351         // if contact retrieval was canceledor retrieval failed, 
       
   352         // result is not yet complete
       
   353         if ( !result->IsComplete() )
       
   354             {
       
   355             card = NULL;
       
   356             }
       
   357         
       
   358         }
       
   359 
       
   360     return card;
       
   361     }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // CPbkxRclServiceUiContextImpl::ContactCount
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 TInt CPbkxRclServiceUiContextImpl::ContactCount() const
       
   368     {
       
   369     FUNC_LOG;
       
   370     return iContactCards.Count();
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // CPbkxRclServiceUiContextImpl::SetSelectedContact
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CPbkxRclServiceUiContextImpl::SetSelectedContactL( TInt aIndex )
       
   378     {
       
   379     FUNC_LOG;
       
   380     iSearchResultDialog->SetCurrentItemIndexL( aIndex );
       
   381     }
       
   382 
       
   383 // ---------------------------------------------------------------------------
       
   384 // CPbkxRclServiceUiContextImpl::EventTriggered
       
   385 // ---------------------------------------------------------------------------
       
   386 //
       
   387 void CPbkxRclServiceUiContextImpl::EventTriggered()
       
   388     {
       
   389     FUNC_LOG;
       
   390 
       
   391     // <cmail>
       
   392     TRAPD( err, DoHandleOperationL() );
       
   393     if ( err != KErrNone )
       
   394         {
       
   395         HandleError( err );
       
   396         }
       
   397     // </cmail>
       
   398 
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CPbkxRclServiceUiContextImpl::ProcessCommandL
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CPbkxRclServiceUiContextImpl::ProcessCommandL( TInt aCommandId )
       
   406     {
       
   407     FUNC_LOG;
       
   408    
       
   409     // some commands are handled the same way no matter which dialog is on top
       
   410     TBool handled = ETrue;
       
   411 
       
   412     switch ( aCommandId )
       
   413         {
       
   414         case ERclCmdVoiceCall:
       
   415             iActionServiceWrapper->ExecuteActionL( 
       
   416                 KFscAtComCallGSM );
       
   417             break;
       
   418         case ERclCmdVideoCall:
       
   419             iActionServiceWrapper->ExecuteActionL( 
       
   420                 KFscAtComCallVideo );
       
   421             break;
       
   422         case ERclCmdVoip:
       
   423             iActionServiceWrapper->ExecuteActionL(
       
   424                 KFscAtComCallVoip );
       
   425             break;
       
   426         case ERclCmdSendMsg:
       
   427             iActionServiceWrapper->ExecuteActionL( 
       
   428                 KFscAtComSendMsg );
       
   429             break;
       
   430           
       
   431         case ERclCmdSendEmail:
       
   432             iActionServiceWrapper->ExecuteActionL( 
       
   433                 KFscAtComSendEmail );
       
   434             break;
       
   435             
       
   436         case ERclCmdSendMeetingReq:
       
   437             iActionServiceWrapper->ExecuteActionL( 
       
   438                 KFscAtComSendCalReq );
       
   439             break;
       
   440         case ERclCmdSendAudioMsg:
       
   441             iActionServiceWrapper->ExecuteActionL( 
       
   442                 KFscAtComSendAudio );
       
   443             break;
       
   444         case ERclCmdToContact:
       
   445             iActionServiceWrapper->ExecuteActionL(
       
   446                 KFscAtComCallPoc );
       
   447             break;
       
   448         case ERclCmdHelp:
       
   449             {
       
   450             CCoeAppUi* appUi = CCoeEnv::Static()->AppUi();
       
   451             CArrayFix<TCoeHelpContext>* contexts = appUi->AppHelpContextL();
       
   452             HlpLauncher::LaunchHelpApplicationL( 
       
   453                 CCoeEnv::Static()->WsSession(), 
       
   454                 contexts );
       
   455             }
       
   456             break;
       
   457         default:
       
   458             handled = EFalse;
       
   459             break;
       
   460         }
       
   461     
       
   462     if ( !handled )
       
   463         {
       
   464         if ( IsStateSet( EResultDlgOnTop ) )
       
   465             {
       
   466             switch ( aCommandId )
       
   467                 {
       
   468                 case ERclCmdAddAsRecipient:
       
   469                     // close the dialog, selected contact is stored in iSelectedContact
       
   470                     AddOperation( ECloseSearchResultDlg );
       
   471                     SetState( EReturnToCaller );
       
   472                     SetState( EResultSelected );
       
   473                     break;
       
   474                 case ERclCmdViewDetails:
       
   475                     AddOperation( EOpenResultInfoDlg );
       
   476                     break;
       
   477                 case ERclCmdNewSearch:
       
   478                     // open empty search query
       
   479                     AddOperation( EOpenSearchQueryEmpty );
       
   480                     break;
       
   481                 case ERclCmdSendBusinessCard:
       
   482                     {
       
   483                     // first fetch details if they are not already
       
   484                     // fetched
       
   485                     HBufC* waitNoteText = StringLoader::LoadLC(
       
   486                         R_QTN_RCL_RETRIEVAL_WAIT_NOTE );
       
   487                     if ( RetrieveDetailsL(
       
   488                              iSearchResultDialog->CurrentItemIndex(),
       
   489                              *waitNoteText ) != NULL )
       
   490                         {
       
   491                         iSearchResultDialog->SendBusinessCardL();
       
   492                         }
       
   493                     CleanupStack::PopAndDestroy( waitNoteText );
       
   494                     }
       
   495                     break;
       
   496                 case ERclCmdSaveToContacts:
       
   497                     {
       
   498                     // first retrieve all the details
       
   499                     HBufC* waitNoteText = StringLoader::LoadLC(
       
   500                         R_QTN_RCL_SAVING_WAIT_NOTE );
       
   501                     if ( RetrieveDetailsL( 
       
   502                              iSearchResultDialog->CurrentItemIndex(),
       
   503                              *waitNoteText ) != NULL )
       
   504                         {
       
   505                         
       
   506                         iActionServiceWrapper->ExecuteActionL( 
       
   507                             KFscAtManSaveAs );
       
   508                         
       
   509                         // in contact selector mode, return to the calling 
       
   510                         // application
       
   511                         if ( iMode == EModeContactSelector )
       
   512                             {
       
   513                             AddOperation( ECloseSearchResultDlg );
       
   514                             SetState( EReturnToCaller );
       
   515                             SetState( EResultSelected );
       
   516                             }
       
   517                         }
       
   518                     CleanupStack::PopAndDestroy( waitNoteText );
       
   519                     }
       
   520                     break;
       
   521                 case EAknCmdExit:
       
   522                     iResult->iExitReason = TResult::EExitApplication;
       
   523                     AddOperation( ECloseSearchResultDlg );
       
   524                     SetState( EReturnToCaller );
       
   525                     break;
       
   526                 default:
       
   527                     break;
       
   528                 }
       
   529             }
       
   530         else if ( IsStateSet( EInfoDlgOnTop ) )
       
   531             {
       
   532             switch ( aCommandId )
       
   533                 {
       
   534                 case ERclCmdAddAsRecipient:
       
   535                     // close both dialogs, selected contact is in iSelectedContact
       
   536                     AddOperation( ECloseResultInfoDlg );
       
   537                     AddOperation( ECloseSearchResultDlg );
       
   538                     SetState( EResultSelected );
       
   539                     SetState( EReturnToCaller );
       
   540                     break;
       
   541                 case ERclCmdSendCallbackReq:
       
   542                     iResultInfoDialog->SendCallbackRequestL();
       
   543                     break;
       
   544                 case ERclCmdCreateNew:
       
   545                     iActionServiceWrapper->ExecuteActionL(
       
   546                         KFscAtManSaveAs );
       
   547                     // in contact selector mode, return to the calling
       
   548                     // application
       
   549                     if ( iMode == EModeContactSelector )
       
   550                         {
       
   551                         AddOperation( ECloseResultInfoDlg );
       
   552                         AddOperation( ECloseSearchResultDlg );
       
   553                         SetState( EReturnToCaller );
       
   554                         SetState( EResultSelected );
       
   555                         }
       
   556                     break;
       
   557                 case ERclCmdUpdateExisting:
       
   558                     {
       
   559                     HBufC* resultText = 
       
   560                         iResultInfoDialog->UpdateExistingContactL();
       
   561                     if ( resultText != NULL )
       
   562                         {
       
   563                         CleanupStack::PushL( resultText );
       
   564                         DisplayNoteDialogL(
       
   565                             R_RCL_CONFIRMATION_NOTE,
       
   566                             *resultText,
       
   567                             ETrue );
       
   568                         CleanupStack::PopAndDestroy( resultText );
       
   569                         }
       
   570                     }
       
   571                     break;
       
   572                 case ERclCmdSendBusinessCard:
       
   573                     iResultInfoDialog->SendBusinessCardL();
       
   574                     break;
       
   575                 case EAknCmdExit:
       
   576                     // again close both dialogs
       
   577                     AddOperation( ECloseResultInfoDlg );
       
   578                     AddOperation( ECloseSearchResultDlg );
       
   579                     SetState( EReturnToCaller );
       
   580                     iResult->iExitReason = TResult::EExitApplication;
       
   581                     break;
       
   582                 default:
       
   583                     break;
       
   584                 }
       
   585             }
       
   586         }
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------------------------
       
   590 // CPbkxRclServiceUiContextImpl::DialogDismissedL
       
   591 // ---------------------------------------------------------------------------
       
   592 //
       
   593 void CPbkxRclServiceUiContextImpl::DialogDismissedL( TInt aButtonId )
       
   594     {
       
   595     FUNC_LOG;
       
   596 
       
   597     if ( aButtonId == EAknSoftkeyCancel )
       
   598         {
       
   599         
       
   600         // Action was canceled. Don't need to inform about errors
       
   601         iExitCode = KErrNone;
       
   602     	// cancel search or detail retrieval
       
   603     	if (iSession)
       
   604     		{
       
   605     		iSession->Cancel();
       
   606     		}
       
   607     	
       
   608     	// cancel time out timer
       
   609         if (iTimer)
       
   610     		{
       
   611     		iTimer->Cancel();
       
   612     		}
       
   613         
       
   614         // do actions based on state
       
   615         if ( IsStateSet( EInitial ) )
       
   616             {
       
   617             if ( iMode != EModeExistingCriteria )
       
   618                 {
       
   619                 // show new search query dialog
       
   620                 AddOperation( EOpenSearchQueryDefault );
       
   621                 }
       
   622             else
       
   623                 {
       
   624                 // with existing criteria, exit
       
   625                 AddOperation( EExit );
       
   626                 }
       
   627             }
       
   628         else if ( IsStateSet( EResultDlgOnTop ) )
       
   629             {
       
   630             if ( iWaitObjects.Count() == EContactRetrievalWait + 1 )
       
   631                 {
       
   632                 // contact retrieval was in progress
       
   633                 StopActiveWait( EContactRetrievalWait );
       
   634                 } // else new search was in progress, no actions needed
       
   635             }
       
   636         else if ( IsStateSet( EInfoDlgOnTop ) )
       
   637             {
       
   638             // details retrieval was in progress, stop active wait 
       
   639             StopActiveWait( EContactRetrievalWait );
       
   640             }
       
   641         
       
   642         }
       
   643     else
       
   644         {
       
   645         // wait dialog closed by itself. exit now if exiting
       
   646         if ( IsStateSet( EReturnToCaller ) &&
       
   647                 ( IsStateSet( EResultSelected ) || IsStateSet( EInitial ) ) )
       
   648             {
       
   649             AddOperation( EExit );
       
   650             }
       
   651         
       
   652         }
       
   653     }
       
   654 
       
   655 // ---------------------------------------------------------------------------
       
   656 // CPbkxRclServiceUiContextImpl::ExecuteSearchL
       
   657 // ---------------------------------------------------------------------------
       
   658 //
       
   659 void CPbkxRclServiceUiContextImpl::ExecuteSearchL( 
       
   660     TBool aShowQueryDialog,
       
   661     const TDesC& aQueryText )
       
   662     {
       
   663     FUNC_LOG;
       
   664 
       
   665 
       
   666     iQueryText.Close();
       
   667     iQueryText.CreateMaxL( KRclQueryTextMaxLength );
       
   668     iQueryText = aQueryText;
       
   669 
       
   670     TBool result = EFalse;
       
   671     if ( aShowQueryDialog )
       
   672         {
       
   673         CPbkxRclQueryEditor* queryEditor = CPbkxRclQueryEditor::NewL( 
       
   674             iAccount->Name(), 
       
   675             iQueryText );
       
   676         result = queryEditor->ExecuteDialogLD();
       
   677         
       
   678         // save initial query text given by user
       
   679         if ( !IsStateSet( EResultDlgOnTop ) )
       
   680             {
       
   681             iQueryCriteria = iQueryText;
       
   682             }
       
   683         }
       
   684     else
       
   685         {
       
   686         result = ETrue;
       
   687         }
       
   688 
       
   689     if ( result )
       
   690         {
       
   691         
       
   692         // Start time for time out event
       
   693         iTimer->Start(
       
   694             KTwoMinutesTimerInterval, KTwoMinutesTimerInterval, 
       
   695             TCallBack(TimerCallBack, this));
       
   696         
       
   697         // execute search based on query text
       
   698         // use KMaxMatches + 1 to be able to catch "too many results error"
       
   699         iSession->LooseSearchL( iQueryText, KMaxMatches + 1 );
       
   700         HBufC* text = StringLoader::LoadLC( R_QTN_RCL_SEARCH_WAIT_NOTE, iQueryText );
       
   701         DisplayWaitDialogL( R_RCL_SEARCH_WAIT_DIALOG_CANCEL, *text );
       
   702         CleanupStack::PopAndDestroy( text );
       
   703         }
       
   704     else
       
   705         {
       
   706         if ( !IsStateSet( EResultDlgOnTop ) )
       
   707             {
       
   708             AddOperation( EExit );
       
   709             } // otherwise just return to search result dlg
       
   710         }
       
   711     }
       
   712 
       
   713 // ---------------------------------------------------------------------------
       
   714 // CPbkxRclServiceUiContextImpl::DisplayWaitDialogL
       
   715 // ---------------------------------------------------------------------------
       
   716 //
       
   717 void CPbkxRclServiceUiContextImpl::DisplayWaitDialogL(
       
   718     TInt aDialogResourceId,
       
   719     const TDesC& aText )
       
   720     {
       
   721     FUNC_LOG;
       
   722 
       
   723     iWaitDialog = new ( ELeave ) CAknWaitDialog( NULL, ETrue );
       
   724     iWaitDialog->SetTextL( aText );
       
   725     iWaitDialog->SetCallback( this );
       
   726     iWaitDialog->ExecuteLD( aDialogResourceId );
       
   727 
       
   728     }
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // CPbkxRclServiceUiContextImpl::DisplayNoteDialogL
       
   732 // ---------------------------------------------------------------------------
       
   733 //
       
   734 TBool CPbkxRclServiceUiContextImpl::DisplayNoteDialogL(
       
   735     TInt aDialogResourceId, 
       
   736     const TDesC& aText,
       
   737     TBool aTimeout )
       
   738     {
       
   739     FUNC_LOG;
       
   740     CAknNoteDialog* dialog = NULL;
       
   741     
       
   742     if ( aTimeout )
       
   743         {
       
   744         dialog = new ( ELeave ) CAknNoteDialog( 
       
   745             CAknNoteDialog::ENoTone, 
       
   746             CAknNoteDialog::ELongTimeout );
       
   747         }
       
   748     else
       
   749         {
       
   750         dialog = new ( ELeave ) CAknNoteDialog();
       
   751         }
       
   752 
       
   753     dialog->PrepareLC( aDialogResourceId );
       
   754     dialog->SetTextL( aText );
       
   755         
       
   756     TBool ret = ( TBool )dialog->RunLD();
       
   757     
       
   758 
       
   759     return ret;
       
   760     }
       
   761 
       
   762 // ---------------------------------------------------------------------------
       
   763 // CPbkxRclServiceUiContextImpl::DisplayQueryDialogL
       
   764 // ---------------------------------------------------------------------------
       
   765 //
       
   766 //Fix for: EASV-7KFGG3
       
   767 TBool CPbkxRclServiceUiContextImpl::DisplayQueryDialogL(
       
   768     TInt aDialogResourceId, 
       
   769     const TDesC& aText )
       
   770     {
       
   771     FUNC_LOG;
       
   772     CAknQueryDialog* dialog = NULL;
       
   773     
       
   774     dialog = new ( ELeave ) CAknQueryDialog();
       
   775     dialog->PrepareLC( aDialogResourceId );
       
   776     dialog->SetPromptL( aText );
       
   777         
       
   778     TBool ret = ( TBool )dialog->RunLD();
       
   779     
       
   780 
       
   781     return ret;
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------------------------
       
   785 // CPbkxRclServiceUiContextImpl::CloseWaitDialogL
       
   786 // ---------------------------------------------------------------------------
       
   787 //
       
   788 void CPbkxRclServiceUiContextImpl::CloseWaitDialogL()
       
   789     {
       
   790     FUNC_LOG;
       
   791     iWaitDialog->ProcessFinishedL();
       
   792     iWaitDialog = NULL;
       
   793     }
       
   794 
       
   795 // ---------------------------------------------------------------------------
       
   796 // CPbkxRclServiceUiContextImpl::DisplaySearchResultDialogL
       
   797 // ---------------------------------------------------------------------------
       
   798 //
       
   799 void CPbkxRclServiceUiContextImpl::DisplaySearchResultDialogL()
       
   800     {
       
   801     FUNC_LOG;
       
   802 
       
   803     if ( iSearchResultDialog == NULL )
       
   804         {
       
   805         // no search result dialog on screen, show new one
       
   806 
       
   807         // result array holds list box items and it is filled inside search
       
   808         // result dialog
       
   809         CDesCArrayFlat* resultArray = 
       
   810             new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   811         CleanupStack::PushL( resultArray );
       
   812         
       
   813         TBool contactSelectorEnabled = iMode == EModeContactSelector;
       
   814         
       
   815         iSearchResultDialog = CPbkxRclSearchResultDlg::NewL(
       
   816             iSelectedIndex,
       
   817             resultArray,
       
   818             this,
       
   819             iContactCards,
       
   820             *iContactEngine,
       
   821             *iActionServiceWrapper,
       
   822             contactSelectorEnabled );
       
   823         
       
   824         UnsetState( EInitial );
       
   825         SetState( EResultDlgOnTop );
       
   826     
       
   827         // set action service mode
       
   828         iActionServiceWrapper->SetActionMenuMode( ETrue );
       
   829     
       
   830         iSearchResultDialog->ExecuteLD();
       
   831         
       
   832         iActionServiceWrapper->SetActionMenuMode( EFalse );
       
   833 
       
   834 
       
   835         iSearchResultDialog = NULL;
       
   836         
       
   837         CleanupStack::PopAndDestroy( resultArray );
       
   838 
       
   839         HandleSearchResultDialogExitL();
       
   840 
       
   841         UnsetState( EResultDlgOnTop );
       
   842         SetState( EInitial );
       
   843         }
       
   844     else
       
   845         { // iSearchResultDialog != NULL
       
   846         
       
   847         
       
   848         iSearchResultDialog->UpdateDialogL();
       
   849         }
       
   850     }
       
   851 // ---------------------------------------------------------------------------
       
   852 // CPbkxRclServiceUiContextImpl::DisplayResultInfoDialogL
       
   853 // ---------------------------------------------------------------------------
       
   854 //
       
   855 void CPbkxRclServiceUiContextImpl::DisplayResultInfoDialogL()
       
   856     {
       
   857     FUNC_LOG;
       
   858     
       
   859     // items array holds the list box items in result info dialog and it is filled
       
   860     // result info dialog
       
   861     CDesCArrayFlat* items = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   862     CleanupStack::PushL( items );
       
   863     
       
   864     TInt index = 0;
       
   865     
       
   866     TBool contactSelectorEnabled = iMode == EModeContactSelector;
       
   867 
       
   868     TInt itemIndex = iSearchResultDialog->CurrentItemIndex();
       
   869 
       
   870     // creation fails if item details cannot be retrieved or user cancels
       
   871     // retrieval
       
   872     iResultInfoDialog = CPbkxRclResultInfoDlg::NewL(
       
   873         index,
       
   874         items,
       
   875         this,
       
   876         this,
       
   877         *iContactEngine,
       
   878         *iActionServiceWrapper,
       
   879         contactSelectorEnabled,
       
   880         itemIndex );
       
   881     
       
   882     UnsetState( EResultDlgOnTop );
       
   883     SetState( EInfoDlgOnTop );
       
   884     
       
   885      // set action service mode
       
   886     iActionServiceWrapper->SetActionMenuMode( EFalse );
       
   887     
       
   888     //Fix for: PKAO-7NNCJ2
       
   889     if ( iSearchResultDialog )
       
   890         {
       
   891         iSearchResultDialog->InfoDlgVisible( ETrue );
       
   892         }
       
   893     
       
   894     iResultInfoDialog->ExecuteLD();
       
   895     
       
   896     // update action service since now search result dialog is on top
       
   897     iActionServiceWrapper->SetActionMenuMode( ETrue );
       
   898 
       
   899     if ( !IsStateSet( EReturnToCaller ) && iResult->iExitReason != TResult::EExitApplication )
       
   900     	{
       
   901     	iSearchResultDialog->SetCurrentContactToActionServiceL();
       
   902     	}
       
   903     
       
   904     //Fix for: PKAO-7NNCJ2
       
   905     if ( iSearchResultDialog )
       
   906         {
       
   907         iSearchResultDialog->InfoDlgVisible( EFalse );
       
   908         }
       
   909     
       
   910     iResultInfoDialog = NULL;
       
   911     
       
   912     UnsetState( EInfoDlgOnTop );
       
   913     SetState( EResultDlgOnTop );
       
   914         
       
   915     CleanupStack::PopAndDestroy( items );
       
   916     
       
   917     }
       
   918 
       
   919 // ---------------------------------------------------------------------------
       
   920 // CPbkxRclServiceUiContextImpl::CreateContactCardArray
       
   921 // ---------------------------------------------------------------------------
       
   922 //
       
   923 void CPbkxRclServiceUiContextImpl::CreateContactCardArray()
       
   924     {
       
   925     FUNC_LOG;
       
   926 
       
   927     // remove possible old contact cards
       
   928     iContactCards.Reset();
       
   929     
       
   930 
       
   931     for ( TInt i = 0; i < iSearchResults.Count(); i++ )
       
   932         {
       
   933         CContactItem& item = iSearchResults[i]->ContactItem();
       
   934         CContactCard* card = dynamic_cast<CContactCard*>( &item );
       
   935         if ( card != NULL )
       
   936             {
       
   937             iContactCards.Append( card );
       
   938             }
       
   939         }
       
   940 
       
   941 
       
   942     }
       
   943 
       
   944 // ---------------------------------------------------------------------------
       
   945 // CPbkxRclServiceUiContextImpl::DoLooseSearchCompletedL
       
   946 // ---------------------------------------------------------------------------
       
   947 //
       
   948 void CPbkxRclServiceUiContextImpl::DoLooseSearchCompletedL( 
       
   949     TInt aStatus,
       
   950     RPointerArray<CPbkxRemoteContactLookupProtocolResult>& aResults )
       
   951     {
       
   952     FUNC_LOG;
       
   953 	
       
   954     // cancel time out timer
       
   955     if (iTimer)
       
   956 		{
       
   957 		iTimer->Cancel();
       
   958 		}
       
   959     
       
   960     CloseWaitDialogL();
       
   961 
       
   962     if ( aStatus == KErrNone )
       
   963         {
       
   964         if ( aResults.Count() > KMaxMatches )
       
   965             {
       
   966             
       
   967             HBufC* text = StringLoader::LoadLC( 
       
   968                 R_QTN_RCL_TOO_MANY_RESULTS_NOTE, 
       
   969                 KMaxMatches );
       
   970 
       
   971             TBool ret = DisplayQueryDialogL(
       
   972                 R_RCL_CONFIRMATION_NOTE_OK_REFINE,
       
   973                 *text );
       
   974             
       
   975             CleanupStack::PopAndDestroy( text );
       
   976             
       
   977             if ( !ret )
       
   978                 {
       
   979                 // user wants new search
       
   980                 AddOperation( EOpenSearchQueryDefault );
       
   981 
       
   982                 // reset the old results
       
   983                 aResults.ResetAndDestroy();
       
   984                 return;
       
   985                 }
       
   986             }
       
   987         
       
   988         // delete old results
       
   989         iSearchResults.ResetAndDestroy();
       
   990         TInt count = aResults.Count() <= KMaxMatches ? aResults.Count() : KMaxMatches;
       
   991         for ( TInt i = 0; i < count; i++ )
       
   992             {
       
   993             iSearchResults.AppendL( aResults[i] );
       
   994             }
       
   995 
       
   996         // delete the extra results
       
   997         for ( TInt j = aResults.Count() - 1; j >= KMaxMatches; j-- )
       
   998             {
       
   999             delete aResults[j];
       
  1000             aResults.Remove( j );
       
  1001             }
       
  1002         
       
  1003         CreateContactCardArray();
       
  1004         TLinearOrder<CContactCard> sort( CPbkxRclServiceUiContextImpl::Sort );
       
  1005         iContactCards.Sort( sort );
       
  1006         
       
  1007         AddOperation( EOpenSearchResultDlg );
       
  1008         }
       
  1009     else
       
  1010         {
       
  1011 
       
  1012         // reset the array just in case
       
  1013         aResults.ResetAndDestroy();
       
  1014 
       
  1015         // remote contact lookup failed, exit
       
  1016         HandleError( aStatus );
       
  1017         
       
  1018         }
       
  1019     }
       
  1020 
       
  1021 // ---------------------------------------------------------------------------
       
  1022 // CPbkxRclServiceUiContextImpl::DoContactFieldsRetrievalCompletedL
       
  1023 // ---------------------------------------------------------------------------
       
  1024 //
       
  1025 void CPbkxRclServiceUiContextImpl::DoContactFieldsRetrievalCompletedL( TInt aStatus )
       
  1026     {
       
  1027     FUNC_LOG;
       
  1028 
       
  1029 	// cancel time out timer
       
  1030     if (iTimer)
       
  1031 		{
       
  1032 		iTimer->Cancel();
       
  1033 		}
       
  1034     
       
  1035     StopActiveWait( EContactRetrievalWait );
       
  1036 
       
  1037     CloseWaitDialogL();
       
  1038 
       
  1039     if ( aStatus != KErrNone )
       
  1040         {
       
  1041         // error occurred, so contact is not complete. this is checked
       
  1042         // in RetrieveContactDetailsL method and it returns NULL
       
  1043         // to the caller
       
  1044 
       
  1045         // exit application
       
  1046         HandleError( aStatus );
       
  1047         }
       
  1048     
       
  1049     }
       
  1050 
       
  1051 // ---------------------------------------------------------------------------
       
  1052 // CPbkxRclServiceUiContextImpl::DoHandleOperationL
       
  1053 // ---------------------------------------------------------------------------
       
  1054 //
       
  1055 void CPbkxRclServiceUiContextImpl::DoHandleOperationL()
       
  1056     {
       
  1057     FUNC_LOG;
       
  1058 
       
  1059     if ( iOperations.Count() > 0 )
       
  1060         {
       
  1061         TOperation operation = iOperations.Pop();
       
  1062         
       
  1063         
       
  1064         switch ( operation )
       
  1065             {
       
  1066             case EOpenSearchResultDlg:
       
  1067                 DisplaySearchResultDialogL();
       
  1068                 break;
       
  1069             case EOpenResultInfoDlg:
       
  1070                 DisplayResultInfoDialogL();
       
  1071                 break;
       
  1072             case ECloseSearchResultDlg:
       
  1073                 if ( iSearchResultDialog != NULL )
       
  1074                     {
       
  1075                     iSearchResultDialog->Close();
       
  1076                     }
       
  1077                 break;
       
  1078             case ECloseResultInfoDlg:
       
  1079                 if ( iResultInfoDialog != NULL )
       
  1080                     {
       
  1081                     iResultInfoDialog->Close();
       
  1082                     }
       
  1083                 break;
       
  1084             case EOpenSearchQueryDefault:
       
  1085                 ExecuteSearchL( ETrue, iQueryCriteria );
       
  1086                 break;
       
  1087             case EOpenSearchQueryEmpty:
       
  1088                 ExecuteSearchL( ETrue, KNullDesC );
       
  1089                 break;
       
  1090             case EExecuteSearchWithNoQuery:
       
  1091                 ExecuteSearchL( EFalse, iQueryCriteria );
       
  1092                 break;
       
  1093             case EExit:
       
  1094                 StopActiveWait( EMainWait );
       
  1095                 break;
       
  1096             default:
       
  1097                 PbkxRclPanic( EPbkxRclPanicGeneral );
       
  1098                 break;
       
  1099             }
       
  1100         
       
  1101         if ( iOperations.Count() > 0 )
       
  1102             {
       
  1103             iEventScheduler->TriggerEvent();
       
  1104             }
       
  1105         }
       
  1106     }
       
  1107 
       
  1108 // ---------------------------------------------------------------------------
       
  1109 // CPbkxRclServiceUiContextImpl::HandleSearchResultDialogExitL
       
  1110 // ---------------------------------------------------------------------------
       
  1111 //
       
  1112 void CPbkxRclServiceUiContextImpl::HandleSearchResultDialogExitL()
       
  1113     {
       
  1114     FUNC_LOG;
       
  1115 
       
  1116     // this flag is set if wait dialog on the screen and we cannot exit before
       
  1117     // wait dialog is closed itself
       
  1118     TBool waitDlgOnScreen = EFalse;
       
  1119     
       
  1120     if ( IsStateSet( EResultSelected ) )
       
  1121         {
       
  1122         // if contact details are not retrieved, we must do that before exiting
       
  1123         CPbkxRemoteContactLookupProtocolResult* result = GetResultByIndex( iSelectedIndex );
       
  1124         if ( !result->IsComplete() )
       
  1125             {
       
  1126             HBufC* text = StringLoader::LoadLC( R_QTN_RCL_RETRIEVAL_WAIT_NOTE );
       
  1127             RetrieveDetailsL( iSelectedIndex, *text );
       
  1128             CleanupStack::PopAndDestroy( text );
       
  1129             
       
  1130             // if wait dialog is NULL, it is closed by CloseWaitDialogL method
       
  1131             // and not by user. so it is still on the screen
       
  1132             waitDlgOnScreen = iWaitDialog == NULL;
       
  1133             
       
  1134             // make sure we succeeded in detail retrieving. if not, return nothing.
       
  1135             if ( result->IsComplete() )
       
  1136                 {
       
  1137                 iResult->iSelectedContactItem = GetSelectedContactL();
       
  1138                 }
       
  1139             }
       
  1140         else
       
  1141             {
       
  1142             iResult->iSelectedContactItem = GetSelectedContactL();
       
  1143             }
       
  1144         }
       
  1145     
       
  1146     if ( !waitDlgOnScreen )
       
  1147         {
       
  1148         // exit
       
  1149 
       
  1150         AddOperation( EExit );
       
  1151         }
       
  1152 
       
  1153     }
       
  1154 
       
  1155 // ---------------------------------------------------------------------------
       
  1156 // CPbkxRclServiceUiContextImpl::HandleContextExitL
       
  1157 // ---------------------------------------------------------------------------
       
  1158 //
       
  1159 void CPbkxRclServiceUiContextImpl::HandleContextExitL()
       
  1160     {
       
  1161     FUNC_LOG;
       
  1162 
       
  1163     // set exit reason
       
  1164     if ( iResult->iExitReason == TResult::EExitUndefined )
       
  1165         {
       
  1166         if ( iExitCode != KErrNone )
       
  1167             {
       
  1168             iResult->iExitReason = TResult::EExitError;
       
  1169             }
       
  1170         else if ( iResult->iSelectedContactItem != NULL )
       
  1171             {
       
  1172             iResult->iExitReason = TResult::EExitContactSelected;
       
  1173             }
       
  1174         else
       
  1175             {
       
  1176             iResult->iExitReason = TResult::EExitUserClosed;
       
  1177             }
       
  1178         }
       
  1179 
       
  1180     if ( iExitCode != KErrNone )
       
  1181         {
       
  1182         // show error note
       
  1183         CTextResolver* resolver = CTextResolver::NewLC( *( CCoeEnv::Static() ) );
       
  1184     
       
  1185         // on return, contains information about the loaded error text
       
  1186         TUint textFlags;
       
  1187         TInt textId;
       
  1188 
       
  1189         const TDesC& errorText = resolver->ResolveErrorString( 
       
  1190             iExitCode,
       
  1191             textId,
       
  1192             textFlags,
       
  1193             CTextResolver::ECtxNoCtxNoSeparator );
       
  1194         
       
  1195         if ( textFlags & EErrorResBlankErrorFlag ||
       
  1196              textFlags & ETextResolverUnknownErrorFlag )
       
  1197             {
       
  1198             // show general error message, because there was no good error 
       
  1199             // message available
       
  1200             HBufC* text = StringLoader::LoadLC( R_QTN_RCL_ERROR_NOTE );
       
  1201             DisplayNoteDialogL( R_RCL_WARNING_NOTE, *text, ETrue );
       
  1202             CleanupStack::PopAndDestroy( text );
       
  1203             }
       
  1204         else
       
  1205             {
       
  1206             DisplayNoteDialogL( R_RCL_WARNING_NOTE, errorText, ETrue );
       
  1207             }
       
  1208         CleanupStack::PopAndDestroy( resolver );
       
  1209         }
       
  1210     }
       
  1211 
       
  1212 // ---------------------------------------------------------------------------
       
  1213 // CPbkxRclServiceUiContextImpl::StartActiveWaitL
       
  1214 // ---------------------------------------------------------------------------
       
  1215 //
       
  1216 void CPbkxRclServiceUiContextImpl::StartActiveWaitL( TWaitObjectIndex aIndex )
       
  1217     {
       
  1218     FUNC_LOG;
       
  1219 
       
  1220     if ( aIndex != iWaitObjects.Count() )
       
  1221         {
       
  1222         // wait object index invalid, panic
       
  1223         PbkxRclPanic( EPbkxRclPanicGeneral );
       
  1224         }
       
  1225     
       
  1226     // starts new active wait and appends it in the list of wait objects
       
  1227     CActiveSchedulerWait* wait = new ( ELeave ) CActiveSchedulerWait();
       
  1228     CleanupStack::PushL( wait );
       
  1229     iWaitObjects.AppendL( wait );
       
  1230     CleanupStack::Pop( wait );
       
  1231     wait->Start();
       
  1232     }
       
  1233 
       
  1234 // ---------------------------------------------------------------------------
       
  1235 // CPbkxRclServiceUiContextImpl::StopActiveWait
       
  1236 // ---------------------------------------------------------------------------
       
  1237 //
       
  1238 void CPbkxRclServiceUiContextImpl::StopActiveWait( TWaitObjectIndex aIndex )
       
  1239     {
       
  1240     FUNC_LOG;
       
  1241     if ( iWaitObjects.Count() != aIndex + 1 )
       
  1242         {
       
  1243         // invalid wait object count, panic
       
  1244         PbkxRclPanic( EPbkxRclPanicGeneral );
       
  1245         }
       
  1246     
       
  1247     // stops active wait of the most recently started wait
       
  1248     CActiveSchedulerWait* wait = iWaitObjects[aIndex];
       
  1249     iWaitObjects.Remove( aIndex );
       
  1250     wait->AsyncStop();
       
  1251     delete wait;
       
  1252     }
       
  1253 
       
  1254 // ---------------------------------------------------------------------------
       
  1255 // CPbkxRclServiceUiContextImpl::SetState
       
  1256 // ---------------------------------------------------------------------------
       
  1257 //
       
  1258 void CPbkxRclServiceUiContextImpl::SetState( TState aState )
       
  1259     {
       
  1260     FUNC_LOG;
       
  1261     iState |= aState;
       
  1262     }
       
  1263 
       
  1264 // ---------------------------------------------------------------------------
       
  1265 // CPbkxRclServiceUiContextImpl::UnsetState
       
  1266 // ---------------------------------------------------------------------------
       
  1267 //
       
  1268 void CPbkxRclServiceUiContextImpl::UnsetState( TState aState )
       
  1269     {
       
  1270     FUNC_LOG;
       
  1271     iState &= ~aState;
       
  1272     }
       
  1273 
       
  1274 // ---------------------------------------------------------------------------
       
  1275 // CPbkxRclServiceUiContextImpl::IsStateSet
       
  1276 // ---------------------------------------------------------------------------
       
  1277 //
       
  1278 TBool CPbkxRclServiceUiContextImpl::IsStateSet( TState aState )
       
  1279     {
       
  1280     FUNC_LOG;
       
  1281     return ( iState & aState ) != 0;
       
  1282     }
       
  1283 
       
  1284 // ---------------------------------------------------------------------------
       
  1285 // CPbkxRclServiceUiContextImpl::ResetState
       
  1286 // ---------------------------------------------------------------------------
       
  1287 //
       
  1288 void CPbkxRclServiceUiContextImpl::ResetState()
       
  1289     {
       
  1290     FUNC_LOG;
       
  1291     iState = 0;
       
  1292     }
       
  1293 
       
  1294 // ---------------------------------------------------------------------------
       
  1295 // CPbkxRclServiceUiContextImpl::AddOperation
       
  1296 // ---------------------------------------------------------------------------
       
  1297 //
       
  1298 void CPbkxRclServiceUiContextImpl::AddOperation( TOperation aOperation )
       
  1299     {
       
  1300     FUNC_LOG;
       
  1301     iOperations.Add( aOperation );
       
  1302     iEventScheduler->TriggerEvent();
       
  1303     }
       
  1304 
       
  1305 // ---------------------------------------------------------------------------
       
  1306 // CPbkxRclServiceUiContextImpl::HandleError
       
  1307 // ---------------------------------------------------------------------------
       
  1308 //
       
  1309 void CPbkxRclServiceUiContextImpl::HandleError( TInt aError )
       
  1310     {
       
  1311     FUNC_LOG;
       
  1312     iExitCode = aError;
       
  1313     SetState( EReturnToCaller );
       
  1314     if ( IsStateSet( EInfoDlgOnTop ) )
       
  1315         {
       
  1316         AddOperation( ECloseResultInfoDlg );
       
  1317         AddOperation( ECloseSearchResultDlg );
       
  1318         }
       
  1319     else if ( IsStateSet( EResultDlgOnTop ) )
       
  1320         {
       
  1321         AddOperation( ECloseSearchResultDlg );
       
  1322         }
       
  1323     
       
  1324 	// If dialog is NULL and state is EInitial & EReturnToCaller
       
  1325 	// EExit operation is added in DialogDismissedL callback
       
  1326 	if ( !iWaitDialog && IsStateSet( EInitial ) && IsStateSet( EReturnToCaller ) )
       
  1327         { 
       
  1328         return;
       
  1329         }
       
  1330 	else 
       
  1331 	    {
       
  1332 	    AddOperation( EExit );
       
  1333 	    }
       
  1334     }
       
  1335 
       
  1336 // ---------------------------------------------------------------------------
       
  1337 // CPbkxRclServiceUiContextImpl::Sort
       
  1338 // ---------------------------------------------------------------------------
       
  1339 //
       
  1340 TInt CPbkxRclServiceUiContextImpl::Sort( 
       
  1341     const CContactCard& aFirst, 
       
  1342     const CContactCard& aSecond )
       
  1343     {
       
  1344     FUNC_LOG;
       
  1345     
       
  1346     TPtrC lastName1 = PbkxRclUtils::FieldText( &aFirst, KUidContactFieldFamilyName );
       
  1347     TPtrC lastName2 = PbkxRclUtils::FieldText( &aSecond, KUidContactFieldFamilyName );
       
  1348 
       
  1349     TInt ret = 0;
       
  1350     if ( lastName1 < lastName2 )
       
  1351         {
       
  1352         ret = -1;
       
  1353         }
       
  1354     else if ( lastName1 > lastName2 )
       
  1355         {
       
  1356         ret = 1;
       
  1357         }
       
  1358     return ret;
       
  1359     }
       
  1360 
       
  1361 // ----------------------------------------------------------------------------
       
  1362 // CPbkxRclServiceUiContextImpl::TimerCallBack
       
  1363 // ----------------------------------------------------------------------------
       
  1364 //
       
  1365 TInt CPbkxRclServiceUiContextImpl::TimerCallBack(TAny* aAny)
       
  1366 	{
       
  1367     FUNC_LOG;
       
  1368 	CPbkxRclServiceUiContextImpl* self = static_cast<CPbkxRclServiceUiContextImpl*>( aAny );
       
  1369 	self->TimeOut();
       
  1370 	return KErrNone;
       
  1371 	}
       
  1372 
       
  1373 // ----------------------------------------------------------------------------
       
  1374 // CPbkxRclServiceUiContextImpl::TimeOut
       
  1375 // ----------------------------------------------------------------------------
       
  1376 //
       
  1377 void CPbkxRclServiceUiContextImpl::TimeOut()
       
  1378 	{
       
  1379     FUNC_LOG;
       
  1380 	iTimer->Cancel();
       
  1381 	
       
  1382 	if (iSession)
       
  1383 		{
       
  1384 		iSession->Cancel();
       
  1385 		}
       
  1386 	
       
  1387 	if (IsStateSet( EInfoDlgOnTop ) || IsStateSet( EResultDlgOnTop ))
       
  1388 		{
       
  1389 		StopActiveWait( EContactRetrievalWait );
       
  1390 		}
       
  1391 	
       
  1392 	TRAP_IGNORE( CloseWaitDialogL() );	
       
  1393 	HandleError( KErrTimedOut );
       
  1394 	}
       
  1395 
       
  1396 //////////////////////////////////////////////////////////////////////////////
       
  1397 // TOperationQueue class definition
       
  1398 //////////////////////////////////////////////////////////////////////////////
       
  1399 
       
  1400 // ---------------------------------------------------------------------------
       
  1401 // CPbkxRclServiceUiContextImpl::TOperationQueue::TOperationQueue
       
  1402 // ---------------------------------------------------------------------------
       
  1403 //
       
  1404 CPbkxRclServiceUiContextImpl::TOperationQueue::TOperationQueue() : 
       
  1405     iCurrent( 0 ), iCount( 0 )
       
  1406     {
       
  1407     FUNC_LOG;
       
  1408     }
       
  1409 
       
  1410 // ---------------------------------------------------------------------------
       
  1411 // CPbkxRclServiceUiContextImpl::TOperationQueue::Add
       
  1412 // ---------------------------------------------------------------------------
       
  1413 //
       
  1414 void CPbkxRclServiceUiContextImpl::TOperationQueue::Add( TOperation aOperation )
       
  1415     {
       
  1416     FUNC_LOG;
       
  1417     if ( iCount == KMaxOperations )
       
  1418         {
       
  1419         PbkxRclPanic( EPbkxRclPanicGeneral );
       
  1420         }
       
  1421     
       
  1422     TBool exists = EFalse;
       
  1423     for ( TInt i = iCurrent, count = 0; 
       
  1424           count < iCount; 
       
  1425           ( ++i ) % KMaxOperations, count++ )
       
  1426         {
       
  1427         if ( iOperations[i] == aOperation )
       
  1428             {
       
  1429             exists = ETrue;
       
  1430             break;
       
  1431             }
       
  1432         }
       
  1433 
       
  1434     if ( !exists )
       
  1435         {
       
  1436         TInt newIndex = ( iCurrent + iCount ) % KMaxOperations;
       
  1437         iOperations[newIndex] = aOperation;
       
  1438         iCount++;
       
  1439         }
       
  1440     
       
  1441     }
       
  1442 
       
  1443 // ---------------------------------------------------------------------------
       
  1444 // CPbkxRclServiceUiContextImpl::TOperationQueue::Pop
       
  1445 // ---------------------------------------------------------------------------
       
  1446 //
       
  1447 CPbkxRclServiceUiContextImpl::TOperation 
       
  1448 CPbkxRclServiceUiContextImpl::TOperationQueue::Pop()
       
  1449     {
       
  1450     if ( iCount > 0 )
       
  1451         {
       
  1452         TOperation op = iOperations[iCurrent];
       
  1453         iOperations[iCurrent] = ENoOperation;
       
  1454         iCount--;
       
  1455         
       
  1456         if ( iCount > 0 )
       
  1457             {
       
  1458             iCurrent = ( ++iCurrent ) % KMaxOperations;
       
  1459             }
       
  1460         else
       
  1461             {
       
  1462             iCurrent = 0;
       
  1463             }
       
  1464         return op;
       
  1465         }
       
  1466     else
       
  1467         {
       
  1468         return ENoOperation;
       
  1469         }
       
  1470     }
       
  1471 
       
  1472 TInt CPbkxRclServiceUiContextImpl::TOperationQueue::Count() const
       
  1473     {
       
  1474     FUNC_LOG;
       
  1475     return iCount;
       
  1476     }
       
  1477 
       
  1478