phoneapp/phoneuiview/src/cphonequerycontroller.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of CPhoneQueryController class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <AknGlobalConfirmationQuery.h>
       
    21 #include <eikenv.h>
       
    22 #include <StringLoader.h>
       
    23 #include <ccauireconnectquery.h>
       
    24 #include <mcauireconnectqueryobserver.h>
       
    25 #include <AknGlobalMsgQuery.h>
       
    26 #include <AknGlobalNote.h> // for CAknGlobalNote
       
    27 
       
    28 #include "phoneui.hrh"
       
    29 #include "cphonequerycontroller.h"
       
    30 #include "tphonecommandparam.h"
       
    31 #include "tphonecmdparamreconnectquery.h"
       
    32 #include "tphonecmdparamstring.h"
       
    33 #include "phonelogger.h"
       
    34 #include "cphonequerydialog.h"
       
    35 #include "tphonecmdparamboolean.h"
       
    36 #include "cphonedtmfnumberlistquery.h"
       
    37 #include "cphonelistquerydialog.h"
       
    38 #include "cphonetimer.h"
       
    39 
       
    40 // ================= MEMBER FUNCTIONS =======================
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 //
       
    44 CPhoneQueryController::CPhoneQueryController( CEikonEnv& aEikEnv )
       
    45     : CActive ( EPriorityUserInput ),
       
    46     iQueryDeleted( ETrue ),
       
    47     iEikEnv( aEikEnv )
       
    48     {
       
    49     CActiveScheduler::Add( this );
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CPhoneQueryController::NewL()
       
    54 // Two-phased constructor
       
    55 // (other items were commented in a header).
       
    56 // ---------------------------------------------------------
       
    57 CPhoneQueryController* CPhoneQueryController::NewL( CEikonEnv& aEikEnv )
       
    58     {
       
    59     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::NewL( ) ");
       
    60     CPhoneQueryController* self =
       
    61         new( ELeave ) CPhoneQueryController( aEikEnv );
       
    62 
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // Destructor
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 CPhoneQueryController::~CPhoneQueryController()
       
    71     {
       
    72     DestroyQuery();
       
    73     ClearTimer();
       
    74     DestroyGlobalQuery();
       
    75     DestroyGlobalMsgQuery();
       
    76 
       
    77     if( iCommandAsync )
       
    78         {
       
    79         delete iCommandAsync;
       
    80         iCommandAsync = NULL;
       
    81         }
       
    82     iQueryPreviousText.Close();
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------
       
    86 // CPhoneQueryController::CreateNoteL
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 void CPhoneQueryController::CreateQueryL(
       
    90     TPhoneCommandParam* aCommandParam )
       
    91     {
       
    92     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneQueryController::CreateQueryL()" );
       
    93 
       
    94     // Cancel previous note. This prevents scheduler crashes.
       
    95     // Canceling must be done here since iActiveAvkonQuery may be overwritten.
       
    96     Cancel();
       
    97 
       
    98     TPhoneCmdParamQuery& params = *static_cast<TPhoneCmdParamQuery*>( aCommandParam );
       
    99     iCommandId = NULL;
       
   100     iNoConnectedCalls = EFalse;
       
   101     switch( params.ParamId() )
       
   102 	    {
       
   103         case TPhoneCommandParam::EPhoneParamIdQuery:
       
   104 	    case TPhoneCommandParam::EPhoneParamIdVideoCallSetupFailedCreateVoiceCallToTheSameContactQuery:
       
   105         case TPhoneCommandParam::EPhoneParamIdUnattendedTransferAcceptanceQuery:
       
   106         case TPhoneCommandParam::EPhoneParamIdGlobalWaitNote:
       
   107 	    	CreateDefaultQueryL( params );
       
   108 	    	break;
       
   109 
       
   110 	    case TPhoneCommandParam::EPhoneParamIdReconnectQuery:
       
   111 	    	CreateReconnectQueryL( aCommandParam );
       
   112 	    	break;
       
   113 
       
   114 	    case TPhoneCommandParam::EPhoneParamRebootQuery:
       
   115 	        {
       
   116 	        TRequestStatus status = KRequestPending;
       
   117 	        CAknGlobalConfirmationQuery* query = CAknGlobalConfirmationQuery::NewLC();
       
   118 	        query->ShowConfirmationQueryL(
       
   119 	            status, params.QueryPrompt(), params.DefaultCba(), R_QGN_NOTE_INFO_ANIM );
       
   120 	        User::WaitForRequest( status );
       
   121 	        CleanupStack::PopAndDestroy( query );
       
   122 	        }
       
   123 	        break;
       
   124 
       
   125 	    default:
       
   126 	    	break;
       
   127 	    }
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------
       
   131 // CPhoneQueryController::DestroyQuery
       
   132 // ---------------------------------------------------------
       
   133 //
       
   134 void CPhoneQueryController::DestroyQuery()
       
   135     {
       
   136     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::DestroyQuery( ) ");
       
   137 
       
   138     // Delete the query if it exists
       
   139     if ( iQuery )
       
   140         {
       
   141         delete iQuery;
       
   142         iQuery = NULL;
       
   143         }
       
   144 
       
   145     iQueryNoteText.Close();
       
   146     iQueryPrompt.Close();
       
   147 
       
   148     if( iCallUiReconnectQuery )
       
   149 	    {
       
   150         delete iCallUiReconnectQuery;
       
   151         iCallUiReconnectQuery = NULL;
       
   152 	    }
       
   153 
       
   154     if ( iDtmfNumberListQuery && !iQueryDeleted )
       
   155         {
       
   156         delete iDtmfNumberListQuery;
       
   157         iDtmfNumberListQuery = NULL;
       
   158         }
       
   159 
       
   160   	if ( iTextQuery )
       
   161   	    {
       
   162   	    delete iTextQuery;
       
   163   	    iTextQuery = NULL;
       
   164   	    }
       
   165 
       
   166     if ( iListQuery && !iQueryDeleted )
       
   167         {
       
   168         delete iListQuery;
       
   169         iListQuery = NULL;
       
   170         }
       
   171 
       
   172     if( iTextQueryDisplayer )
       
   173         {
       
   174         delete iTextQueryDisplayer;
       
   175         iTextQueryDisplayer = NULL;
       
   176         }
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CPhoneQueryController::DestroyGlobalQuery
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 void CPhoneQueryController::DestroyGlobalQuery()
       
   184     {
       
   185     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::DestroyGlobalQuery( ) ");
       
   186 
       
   187     if ( iGlobalConfirmationQuery )
       
   188         {
       
   189         iGlobalConfirmationQuery->CancelConfirmationQuery();
       
   190 
       
   191         delete iGlobalConfirmationQuery;
       
   192         iGlobalConfirmationQuery = NULL;
       
   193         }
       
   194     DestroyGlobalWaitNote();
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // CPhoneQueryController::CreateQueryDialogL
       
   199 // ---------------------------------------------------------
       
   200 //
       
   201 void CPhoneQueryController::CreateQueryDialogL(
       
   202     const TPhoneCmdParamQuery& aParams )
       
   203     {
       
   204     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::CreateQueryDialogL( ) ");
       
   205 
       
   206     // Delete the existing query
       
   207     DestroyQuery();
       
   208 
       
   209     iQueryParam = aParams;
       
   210 
       
   211     // Create the query
       
   212 	iQuery = CPhoneQueryDialog::NewL();
       
   213 
       
   214     if ( iQuery )
       
   215         {
       
   216         // Set the prompt if specified
       
   217         if ( aParams.QueryPrompt().Length() )
       
   218             {
       
   219             iQueryPrompt.Close();
       
   220             iQueryPrompt.Create( aParams.QueryPrompt() );
       
   221             iQuery->SetPromptL( iQueryPrompt );
       
   222             }
       
   223 
       
   224         // Display the query
       
   225 		TInt buttonId = iQuery->ExecuteLD( aParams.QueryResourceId() );
       
   226         iQuery = NULL;
       
   227 
       
   228 		if( buttonId != EPhoneCmdDoNothing )
       
   229 			{
       
   230             if ( iQueryParam.QueryCommandObserver() )
       
   231                 {
       
   232                 // Let observer handle command.
       
   233                 iQueryParam.QueryCommandObserver()->ProcessCommandL(
       
   234                         iStatus.Int() );
       
   235                 return;
       
   236                 }
       
   237             else
       
   238                 {
       
   239                 // Forward pressed CBA to the framework so that we can handle it
       
   240                 // in our active state
       
   241                 static_cast<MEikCommandObserver*>( iEikEnv.EikAppUi() )
       
   242                     ->ProcessCommandL( buttonId );
       
   243                 }
       
   244 			}
       
   245         }
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------
       
   249 // CPhoneQueryController::CreateTextQueryDialogL
       
   250 // ---------------------------------------------------------
       
   251 //
       
   252 void CPhoneQueryController::CreateTextQueryDialogL(
       
   253         const TPhoneCmdParamQuery& aParams,
       
   254         TInt aEikBidOkCmd )
       
   255     {
       
   256     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::CreateTextQueryDialogL( ) ");
       
   257 
       
   258     // Delete the existing query
       
   259     DestroyQuery();
       
   260 
       
   261     iQueryNoteText.Create( *aParams.DataText() );
       
   262 
       
   263     iTextQuery = new( ELeave ) CPhoneTextQuery(
       
   264         *this,
       
   265         iQueryNoteText,
       
   266         aParams.DefaultCba(),
       
   267         aParams.ContentCba(),
       
   268         aParams.SendKeyEnabled(),
       
   269         aEikBidOkCmd );
       
   270 
       
   271     // Set the prompt if specified
       
   272     if ( aParams.QueryPrompt().Length() )
       
   273         {
       
   274         iQueryPrompt.Create( aParams.QueryPrompt() );
       
   275         iTextQuery->SetPromptL( iQueryPrompt );
       
   276         }
       
   277 
       
   278     // Cut the call stack so that Phone UI is responsive
       
   279     iTextQueryDisplayer = CIdle::NewL( EPriorityNormal );
       
   280     iTextQueryDisplayer->Start( TCallBack( DisplayTextQueryCallBack, this ) );
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------
       
   284 // CPhoneQueryController::SetNoConnectedCalls
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 void CPhoneQueryController::SetNoConnectedCalls( TPhoneCommandParam* aCommandParam )
       
   288     {
       
   289     TPhoneCmdParamBoolean* booleanParam =
       
   290             static_cast<TPhoneCmdParamBoolean*>( aCommandParam );
       
   291     iNoConnectedCalls = booleanParam->Boolean();
       
   292     __PHONELOG1( EBasic, EPhoneUIView,
       
   293            "CPhoneQueryController::SetNoConnectedCalls(%d)",
       
   294            iNoConnectedCalls );
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------
       
   298 // CPhoneQueryController::DisplayTextQueryCallBackL
       
   299 // ---------------------------------------------------------
       
   300 //
       
   301 TInt CPhoneQueryController::DisplayTextQueryCallBack( TAny* aCPhoneQueryController )
       
   302     {
       
   303     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::DisplayTextQueryCallBack( ) ");
       
   304 
       
   305     // Display the query
       
   306     CPhoneQueryController* queryController =
       
   307         static_cast<CPhoneQueryController*>( aCPhoneQueryController );
       
   308 
       
   309     TInt leaveError = KErrNone;
       
   310     TInt retVal = KErrNone;
       
   311 
       
   312     TRAP( leaveError, (
       
   313          retVal = queryController->iTextQuery->ExecuteLD( queryController->iQueryParam.QueryResourceId() ) ) );
       
   314 
       
   315     queryController->iTextQuery = NULL;
       
   316 
       
   317     // If iCommandId is EPhoneCmdEnd(User has pressed end dismiss DTMF query&dialog) or if iNoConnectedCalls
       
   318     // is TRUE it is an indication that remote party has terminated call and there is no connected call in device
       
   319     // therefore we dont need to reopen EPhoneInCallCmdDtmfListQuery.
       
   320     if ( retVal == KErrNone &&
       
   321          leaveError == KErrNone &&
       
   322          queryController->iQueryParam.QueryType() == EPhoneDtmfTextQuery &&
       
   323          queryController->iCommandId != EPhoneCmdEnd &&
       
   324          !queryController->iNoConnectedCalls )
       
   325         {
       
   326         //User has exited DMTF query with cancel, rule says that
       
   327         //we need to activate DTMF list query dialog.
       
   328 
       
   329         // Forward pressed CBA to the framework so that we can handle it
       
   330         // in our active state
       
   331         TRAP_IGNORE( static_cast<MEikCommandObserver*>( queryController->iEikEnv.EikAppUi() )
       
   332             ->ProcessCommandL( EPhoneInCallCmdDtmfListQuery ) );
       
   333         }
       
   334 
       
   335     queryController->iNoConnectedCalls = EFalse;
       
   336     return KErrNone;
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------
       
   340 // CPhoneQueryController::CreateListQueryL
       
   341 // ---------------------------------------------------------
       
   342 //
       
   343 void CPhoneQueryController::CreateListQueryL( TInt aDialogResourceId,
       
   344                                               const RArray<TInt>& aCommands )
       
   345     {
       
   346     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::CreateListQueryL( ) ");
       
   347     DestroyQuery();
       
   348 
       
   349     if ( !iListQuery )
       
   350        {
       
   351        iListQuery = new (ELeave)
       
   352                 CPhoneListQueryDialog(
       
   353                 static_cast<MEikCommandObserver&>( *iEikEnv.EikAppUi() ),
       
   354                 *this, aCommands );
       
   355        }
       
   356     iQueryDeleted = EFalse;
       
   357     iCommandHandled = EFalse;
       
   358     iListQuery->ExecuteLD( aDialogResourceId );
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------
       
   362 // CPhoneQueryController::CreateCustomListQueryL
       
   363 // ---------------------------------------------------------
       
   364 //
       
   365 void CPhoneQueryController::CreateCustomListQueryL(
       
   366         const TPhoneCmdParamQuery& aParams )
       
   367     {
       
   368     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::CreateCustomListQueryL( ) ");
       
   369     DestroyQuery();
       
   370     RArray<TInt> commands;
       
   371     CleanupClosePushL( commands );
       
   372     const_cast<TPhoneCmdParamQuery&>(aParams).ItemTextArrayForListQuery();
       
   373 
       
   374     MDesCArray* itemArray = aParams.ItemTextArrayForListQuery();
       
   375 
       
   376     if ( NULL == itemArray )
       
   377         {
       
   378         User::Leave( KErrArgument );
       
   379         }
       
   380 
       
   381     for ( TInt i = 0; i < itemArray->MdcaCount(); i++ )
       
   382         {
       
   383         commands.Append( i );
       
   384         }
       
   385 
       
   386     if ( !iListQuery )
       
   387        {
       
   388        iListQuery = new (ELeave)
       
   389                 CPhoneListQueryDialog(
       
   390                 static_cast<MEikCommandObserver&>( *iEikEnv.EikAppUi() ),
       
   391                 *this, commands );
       
   392        }
       
   393 
       
   394     iListQuery->PrepareLC( aParams.QueryResourceId() );
       
   395 
       
   396 
       
   397     iListQuery->SetItemTextArray( itemArray );
       
   398     iListQuery->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   399     iListQuery->SetTone( aParams.Tone() );
       
   400 
       
   401     iQueryDeleted = EFalse;
       
   402     iCommandHandled = EFalse;
       
   403 
       
   404     iListQuery->RunLD();
       
   405 
       
   406     CleanupStack::PopAndDestroy( &commands );
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------
       
   410 // CPhoneQueryController::CreateDtmfListQueryL
       
   411 // ---------------------------------------------------------
       
   412 //
       
   413 void CPhoneQueryController::CreateDtmfListQueryL( TInt aDialogResourceId )
       
   414     {
       
   415     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::CreateDtmfListQueryL( ) ");
       
   416     DestroyQuery();
       
   417 
       
   418     if ( !iDtmfNumberListQuery )
       
   419         {
       
   420         iDtmfNumberListQuery = CPhoneDtmfNumberListQuery::NewL(
       
   421             static_cast<MEikCommandObserver&>( *iEikEnv.EikAppUi() ),
       
   422                                                *this,
       
   423                                                iResultBuffer );
       
   424         }
       
   425     iQueryDeleted = EFalse;
       
   426     iDtmfNumberListQuery->ExecuteLD( aDialogResourceId );
       
   427     }
       
   428 
       
   429 // ---------------------------------------------------------
       
   430 // CPhoneQueryController::GetTextQueryContentL
       
   431 // ---------------------------------------------------------
       
   432 //
       
   433 void CPhoneQueryController::GetTextQueryContentL(
       
   434     TPhoneCommandParam* aCommandParam )
       
   435     {
       
   436     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::GetTextQueryContentL( ) ");
       
   437 
       
   438     TPhoneCmdParamString* stringParam =
       
   439         static_cast<TPhoneCmdParamString*>( aCommandParam );
       
   440 
       
   441     if ( iQueryPreviousText.Length() )
       
   442         {
       
   443         *stringParam->String() = iQueryPreviousText;
       
   444         iQueryPreviousText.Close();
       
   445         }
       
   446     else if ( iTextQuery  )
       
   447         {
       
   448         iTextQuery->GetContent( *stringParam->String() );
       
   449         }
       
   450     else if ( iResultBuffer )
       
   451         {
       
   452         stringParam->String()->Append( iResultBuffer->Des() );
       
   453         delete iResultBuffer;
       
   454         iResultBuffer = NULL;
       
   455         }
       
   456 
       
   457     __PHONELOG1( EBasic, EPhoneUIView,
       
   458         "CPhoneQueryController::GetTextQueryContentL(%S)",
       
   459         stringParam->String() );
       
   460 
       
   461     AknTextUtils::ConvertDigitsTo( *stringParam->String(), EDigitTypeWestern );
       
   462 
       
   463     __PHONELOG1( EBasic, EPhoneUIView,
       
   464         "CPhoneQueryController::GetTextQueryContentL(%S)",
       
   465         stringParam->String() );
       
   466     }
       
   467 
       
   468 // ---------------------------------------------------------
       
   469 // CPhoneQueryController::SetQueryDeletedFlag
       
   470 // ---------------------------------------------------------
       
   471 //
       
   472 void CPhoneQueryController::SetQueryDeletedFlag( TBool aQueryDeleted )
       
   473     {
       
   474     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::SetQueryDeletedFlag( ) ");
       
   475     switch( iActiveAvkonQuery )
       
   476         {
       
   477         case EPhoneContactsListQuery:
       
   478         case EPhoneCustomListQueryDialog:
       
   479              {
       
   480              iListQuery = NULL;
       
   481 
       
   482              if ( iQueryParam.QueryCommandObserver() &&
       
   483                   !iCommandHandled )
       
   484                  {
       
   485                  ReportQueryCompleteAsync( EAknSoftkeyCancel );
       
   486                  }
       
   487              }
       
   488              break;
       
   489         case EPhoneDtmfListQueryDialog:
       
   490              {
       
   491              iDtmfNumberListQuery = NULL;
       
   492              }
       
   493              break;
       
   494         default:
       
   495              break;
       
   496         }
       
   497     iQueryDeleted = aQueryDeleted;
       
   498     }
       
   499 
       
   500 
       
   501 // ---------------------------------------------------------
       
   502 // CPhoneQueryController::CreateDefaultQueryL
       
   503 // ---------------------------------------------------------
       
   504 //
       
   505 void CPhoneQueryController::CreateDefaultQueryL( const TPhoneCmdParamQuery& aParams )
       
   506 	{
       
   507     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::CreateDefaultQueryL( ) ");
       
   508 
       
   509     iQueryParam = aParams;
       
   510     iActiveAvkonQuery = aParams.QueryType();
       
   511 
       
   512     switch( iActiveAvkonQuery )
       
   513         {
       
   514         case EPhoneQueryDialog:
       
   515             CreateQueryDialogL( aParams );
       
   516             break;
       
   517 
       
   518         case EPhoneTextQueryDialog:
       
   519             CreateTextQueryDialogL( aParams );
       
   520             break;
       
   521 
       
   522        case EPhoneDtmfTextQuery:
       
   523        case EPhoneGenericTextQuery:
       
   524             CreateTextQueryDialogL( aParams,
       
   525                                     EPhoneCmdDtmfOk );
       
   526             break;
       
   527 
       
   528         case EPhoneGlobalQueryDialog:
       
   529             {
       
   530             if ( aParams.ParamId() ==
       
   531                 TPhoneCommandParam::EPhoneParamIdVideoCallSetupFailedCreateVoiceCallToTheSameContactQuery )
       
   532                 {
       
   533                 iVideoCallSetupFailedQuery = ETrue;
       
   534                 }
       
   535             else
       
   536                 {
       
   537                 iVideoCallSetupFailedQuery = EFalse;
       
   538                 }
       
   539             // Use timeout if defined
       
   540             TTimeIntervalMicroSeconds32 timeout = aParams.TimeOut() * 1000000;
       
   541             if ( timeout.Int() > 0 && !iTimer )
       
   542                 {
       
   543                 iTimer = CPhoneTimer::NewL();
       
   544                 // Start timer.
       
   545                 iTimer->After( timeout, this );
       
   546                 }
       
   547             // Create query
       
   548             CreateGlobalQueryDialogL( aParams );
       
   549             break;
       
   550             }
       
   551         case EPhoneCustomListQueryDialog:
       
   552               {
       
   553               CreateCustomListQueryL( aParams );
       
   554               }
       
   555             break;
       
   556         case EPhoneDtmfListQueryDialog:
       
   557               CreateDtmfListQueryL(
       
   558                 aParams.QueryResourceId() );
       
   559              break;
       
   560 
       
   561         case EPhoneContactsListQuery:
       
   562               {
       
   563               RArray<TInt> commands;
       
   564               CleanupClosePushL( commands );
       
   565               commands.Append( EPhoneNumberAcqCmdSave );
       
   566               commands.Append( EPhoneNumberAcqCmdAddToName );
       
   567               CreateListQueryL( aParams.QueryResourceId(), commands );
       
   568               CleanupStack::PopAndDestroy(); // CleanupClosePushL
       
   569               }
       
   570             break;
       
   571         case EPhoneGlobalMsgQuery:
       
   572             {
       
   573             iTransferAcceptanceQuery = ( aParams.ParamId() ==
       
   574                 TPhoneCommandParam::EPhoneParamIdUnattendedTransferAcceptanceQuery );
       
   575 
       
   576             CreateGlobalMsgQueryL( aParams );
       
   577             break;
       
   578             }
       
   579         case EPhoneGlobalWaitNote:
       
   580             {
       
   581             CreateGlobalWaitNoteL( aParams );
       
   582             break;
       
   583             }
       
   584 
       
   585         default:
       
   586             return;
       
   587         }
       
   588 	}
       
   589 
       
   590 // ---------------------------------------------------------
       
   591 // CPhoneQueryController::CreateReconnectQueryL
       
   592 // ---------------------------------------------------------
       
   593 //
       
   594 void CPhoneQueryController::CreateReconnectQueryL( TPhoneCommandParam* aCommandParam )
       
   595 	{
       
   596     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::CreateReconnectQueryL( ) ");
       
   597 
       
   598     TPhoneCmdParamReconnectQuery* queryParam =
       
   599         static_cast<TPhoneCmdParamReconnectQuery*>( aCommandParam );
       
   600 
       
   601 	if( !iCallUiReconnectQuery )
       
   602 		{
       
   603 		iCallUiReconnectQuery =
       
   604 		    CCaUiReconnectQuery::NewL(
       
   605 		        queryParam->ReconnectQueryObserver());
       
   606 		}
       
   607 
       
   608    	iCallUiReconnectQuery->ShowL( queryParam->PhoneNumber(),
       
   609    	     queryParam->IncludeVideoCallOption() );
       
   610 	}
       
   611 
       
   612 // ---------------------------------------------------------
       
   613 // CPhoneQueryController::CreateGlobalQueryDialogL
       
   614 // ---------------------------------------------------------
       
   615 //
       
   616 void CPhoneQueryController::CreateGlobalQueryDialogL( const TPhoneCmdParamQuery& aParams )
       
   617     {
       
   618     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::CreateGlobalQueryDialogL( ) ");
       
   619 
       
   620     // Delete the existing global query
       
   621     DestroyGlobalQuery();
       
   622 
       
   623     iGlobalConfirmationQuery = CAknGlobalConfirmationQuery::NewL();
       
   624     iGlobalConfirmationQuery->ShowConfirmationQueryL(
       
   625         iStatus,
       
   626         aParams.QueryPrompt(),
       
   627         aParams.DefaultCba(),
       
   628         R_QGN_NOTE_QUERY_ANIM,
       
   629         KNullDesC,
       
   630         0,
       
   631         0,
       
   632         CAknQueryDialog::TTone(aParams.Tone() ) );
       
   633 
       
   634     SetActive();
       
   635     }
       
   636 
       
   637 
       
   638 // ---------------------------------------------------------------------------
       
   639 // CPhoneQueryController::ReportQueryCompleteAsync
       
   640 // ---------------------------------------------------------------------------
       
   641 //
       
   642 void CPhoneQueryController::ReportQueryCompleteAsync( TInt aCommand )
       
   643     {
       
   644     iCommandHandled = ETrue;
       
   645     Cancel();
       
   646     TRequestStatus* status = &iStatus;
       
   647     User::RequestComplete( status, aCommand );
       
   648     SetActive();
       
   649     }
       
   650 
       
   651 // ---------------------------------------------------------
       
   652 // CPhoneQueryController::RunL
       
   653 // EAknSoftkeyYes and EAknSoftkeyNo need to be used with
       
   654 // CAknGlobalConfirmationQuery. Others does not work
       
   655 // ---------------------------------------------------------
       
   656 //
       
   657 void CPhoneQueryController::RunL()
       
   658     {
       
   659     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::RunL( ) ");
       
   660     TInt buttonId( KErrNone );
       
   661 
       
   662     if ( iQueryParam.QueryCommandObserver() )
       
   663         {
       
   664         // Let observer handle command.
       
   665         iQueryParam.QueryCommandObserver()->ProcessCommandL(
       
   666                 iStatus.Int() );
       
   667         return;
       
   668         }
       
   669 
       
   670     if ( iActiveAvkonQuery == EPhoneContactsListQuery ||
       
   671          iActiveAvkonQuery == EPhoneDtmfListQueryDialog )
       
   672         {
       
   673         buttonId = iStatus.Int();
       
   674         }
       
   675     else if ( iActiveAvkonQuery == EPhoneGlobalQueryDialog )
       
   676         {
       
   677         if ( iStatus.Int() == EAknSoftkeyYes )
       
   678             {
       
   679             if ( iVideoCallSetupFailedQuery )
       
   680                 {
       
   681                 buttonId = EPhoneCmdYesVideoFailedNoMemorySwitchToVoice;
       
   682                 }
       
   683             else
       
   684                 {
       
   685                 buttonId = EPhoneCmdYesBtDisconnectQuery;
       
   686                 }
       
   687             }
       
   688         else if ( iStatus.Int() == EAknSoftkeyNo  )
       
   689             {
       
   690             if ( iVideoCallSetupFailedQuery )
       
   691                 {
       
   692                 buttonId = EPhoneCmdNoVideoFailedNoMemorySwitchToVoice;
       
   693                 }
       
   694             else
       
   695                 {
       
   696                 buttonId = EPhoneCmdNoBtDisconnectQuery;
       
   697                 }
       
   698              }
       
   699         ClearTimer();
       
   700         iVideoCallSetupFailedQuery = EFalse;
       
   701         DestroyGlobalQuery();
       
   702         }
       
   703     else if ( iActiveAvkonQuery == EPhoneGlobalMsgQuery )
       
   704         {
       
   705         buttonId = iQueryParam.CbaCommandMapping( iStatus.Int() );
       
   706         if ( iTransferAcceptanceQuery )
       
   707             {
       
   708             iTransferAcceptanceQuery = EFalse;
       
   709             }
       
   710 
       
   711         ClearTimer();
       
   712         DestroyGlobalMsgQuery();
       
   713         }
       
   714     else if ( iActiveAvkonQuery == EPhoneGlobalWaitNote )
       
   715         {
       
   716         // If note is destroyed through DestroyGlobalQuery() then KErrCancel
       
   717         // is not mapped to any command.
       
   718         if ( iStatus.Int() == KErrCancel &&
       
   719              !iGlobalWaitNote )
       
   720             {
       
   721             ClearTimer();
       
   722             return;
       
   723             }
       
   724         else
       
   725             {
       
   726             buttonId = iQueryParam.CbaCommandMapping( iStatus.Int() );
       
   727             }
       
   728 
       
   729         ClearTimer();
       
   730         DestroyGlobalWaitNote();
       
   731         }
       
   732     // Forward pressed CBA to the framework so that we can handle it
       
   733     // in our active state
       
   734     static_cast<MEikCommandObserver*>( iEikEnv.EikAppUi() )
       
   735 	    ->ProcessCommandL( buttonId );
       
   736     }
       
   737 
       
   738 // ---------------------------------------------------------
       
   739 // CPhoneQueryController::RunError
       
   740 // ---------------------------------------------------------
       
   741 //
       
   742 TInt CPhoneQueryController::RunError( TInt aError )
       
   743     {
       
   744     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::RunError( ) ");
       
   745 
       
   746     if ( aError )
       
   747         {
       
   748         __PHONELOG1( EBasic, EPhoneUIView,
       
   749         "CPhoneQueryController::RunError: error: %d",
       
   750         aError );
       
   751         }
       
   752     return aError;
       
   753     }
       
   754 
       
   755 // ---------------------------------------------------------
       
   756 // CPhoneQueryController::DoCancel
       
   757 // ---------------------------------------------------------
       
   758 //
       
   759 void CPhoneQueryController::DoCancel()
       
   760     {
       
   761     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::DoCancel( ) ");
       
   762 
       
   763     if ( iActiveAvkonQuery == EPhoneGlobalQueryDialog )
       
   764         {
       
   765         ClearTimer();
       
   766         DestroyGlobalQuery();
       
   767         if ( iVideoCallSetupFailedQuery )
       
   768             {
       
   769             iVideoCallSetupFailedQuery = EFalse;
       
   770             TRAP_IGNORE(
       
   771                 static_cast<MEikCommandObserver*>( iEikEnv.EikAppUi() )
       
   772 	                ->ProcessCommandL(
       
   773 	                        EPhoneCmdNoVideoFailedNoMemorySwitchToVoice ) )
       
   774             }
       
   775         else if ( iQueryParam.QueryCommandObserver() )
       
   776             {
       
   777             // Let observer handle command.
       
   778             TRAP_IGNORE( iQueryParam.QueryCommandObserver()->ProcessCommandL(
       
   779                     EAknSoftkeyCancel ) );
       
   780             }
       
   781         }
       
   782     if ( EPhoneGlobalMsgQuery == iActiveAvkonQuery )
       
   783         {
       
   784         ClearTimer();
       
   785         DestroyGlobalMsgQuery();
       
   786 
       
   787         TInt buttonId = 0;
       
   788         TInt result = iQueryParam.GetCustomCommandForTimeOut( buttonId );
       
   789         if ( KErrNone == result && iTransferAcceptanceQuery )
       
   790             {
       
   791             // timeout equals reject of unattended transfer request
       
   792             iTransferAcceptanceQuery = EFalse;
       
   793             TRAP_IGNORE(
       
   794                 static_cast<MEikCommandObserver*>( iEikEnv.EikAppUi() )
       
   795                     ->ProcessCommandL( buttonId ) )
       
   796             }
       
   797         }
       
   798 
       
   799     if ( EPhoneGlobalWaitNote == iActiveAvkonQuery )
       
   800         {
       
   801         ClearTimer();
       
   802         TInt buttonId = 0;
       
   803         TInt result = iQueryParam.GetCustomCommandForTimeOut( buttonId );
       
   804         if ( KErrNone == result && iGlobalWaitNote )
       
   805             {
       
   806             DestroyGlobalWaitNote();
       
   807 
       
   808             TRAP_IGNORE(
       
   809                 static_cast<MEikCommandObserver*>( iEikEnv.EikAppUi() )
       
   810                     ->ProcessCommandL( buttonId ) )
       
   811             }
       
   812         }
       
   813     }
       
   814 
       
   815 // ---------------------------------------------------------
       
   816 // CPhoneQueryController::IsQueryActive
       
   817 // ---------------------------------------------------------
       
   818 //
       
   819 void CPhoneQueryController::IsQueryActive( TPhoneCommandParam* aCommandParam )
       
   820     {
       
   821     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::IsQueryActive() ");
       
   822     TPhoneCmdParamBoolean* booleanParam =
       
   823         booleanParam = static_cast<TPhoneCmdParamBoolean*>( aCommandParam );
       
   824 
       
   825     if ( iQuery ||
       
   826          iTextQuery ||
       
   827          iGlobalConfirmationQuery ||
       
   828          !iQueryDeleted )
       
   829         {
       
   830         booleanParam->SetBoolean( ETrue );
       
   831         }
       
   832     else
       
   833         {
       
   834         booleanParam->SetBoolean( EFalse );
       
   835         }
       
   836     }
       
   837 
       
   838 // ---------------------------------------------------------
       
   839 // CPhoneQueryController::IsDTMFQueryVisible
       
   840 // ---------------------------------------------------------
       
   841 //
       
   842 TBool CPhoneQueryController::IsDTMFQueryVisible()
       
   843     {
       
   844     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::IsDTMFQueryVisible() ");
       
   845     TBool dtmfVisible(EFalse);
       
   846     if( ( iTextQuery && iQueryParam.QueryType() == EPhoneDtmfTextQuery ) ||
       
   847         ( iDtmfNumberListQuery && iQueryParam.QueryType() == EPhoneDtmfListQueryDialog ) )
       
   848         {
       
   849         dtmfVisible = ETrue;
       
   850         }
       
   851     __PHONELOG1( EBasic, EPhoneUIView,
       
   852             "CPhoneQueryController::IsDTMFQueryVisible :%d",
       
   853             dtmfVisible );
       
   854     return dtmfVisible;
       
   855     }
       
   856 
       
   857 // ---------------------------------------------------------
       
   858 // CPhoneQueryController::SetListQueryStringL
       
   859 // ---------------------------------------------------------
       
   860 //
       
   861 void CPhoneQueryController::SetListQueryStringL( TPhoneCommandParam* aCommandParam )
       
   862     {
       
   863     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::SetListQueryStringL() ");
       
   864     //Create new object if needed
       
   865     if ( !iDtmfNumberListQuery )
       
   866         {
       
   867         iDtmfNumberListQuery = CPhoneDtmfNumberListQuery::NewL(
       
   868         static_cast<MEikCommandObserver&>( *iEikEnv.EikAppUi() ),
       
   869                                            *this,
       
   870                                            iResultBuffer );
       
   871         }
       
   872     TPhoneCmdParamString* stringParam =
       
   873         static_cast<TPhoneCmdParamString*>( aCommandParam );
       
   874     iDtmfNumberListQuery->AppendStringToArrayL( *stringParam->String() );
       
   875     }
       
   876 
       
   877 // -----------------------------------------------------------------------------
       
   878 // CPhoneQueryController::HandleTimeOutL
       
   879 // -----------------------------------------------------------------------------
       
   880 //
       
   881 void CPhoneQueryController::HandleTimeOutL()
       
   882     {
       
   883     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::HandleTimeOutL()");
       
   884     Cancel();
       
   885     }
       
   886 
       
   887 // -----------------------------------------------------------------------------
       
   888 // CPhoneQueryController::ClearTimer
       
   889 // -----------------------------------------------------------------------------
       
   890 //
       
   891 void CPhoneQueryController::ClearTimer()
       
   892     {
       
   893     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::ClearTimer()");
       
   894     if ( iTimer )
       
   895         {
       
   896         if ( iTimer->IsActive() )
       
   897             {
       
   898             iTimer->Cancel();
       
   899             }
       
   900         delete iTimer;
       
   901         iTimer = NULL;
       
   902         }
       
   903     }
       
   904 
       
   905 // ---------------------------------------------------------
       
   906 // CPhoneQueryController::CreateGlobalMsgQueryL
       
   907 // ---------------------------------------------------------
       
   908 //
       
   909 void CPhoneQueryController::CreateGlobalMsgQueryL(
       
   910         const TPhoneCmdParamQuery& aParams )
       
   911     {
       
   912     iQueryNoteText.Close();
       
   913     iQueryNoteText.Create( *aParams.DataText() );
       
   914     iQueryPrompt.Close();
       
   915     iQueryPrompt.Create( aParams.QueryPrompt() );
       
   916 
       
   917     // use timeout if defined
       
   918     const TInt KSecToUsFactor = 1000000;
       
   919     TTimeIntervalMicroSeconds32 timeout = aParams.TimeOut() * KSecToUsFactor;
       
   920     if ( 0 < timeout.Int() && !iTimer )
       
   921         {
       
   922         iTimer = CPhoneTimer::NewL();
       
   923         iTimer->After( timeout, this );
       
   924         }
       
   925 
       
   926     DestroyGlobalMsgQuery();
       
   927     iGlobalMsgQuery = CAknGlobalMsgQuery::NewL();
       
   928 
       
   929     const TInt KNoImage     = 0;
       
   930     const TInt KNoImageMask = -1;
       
   931 
       
   932     iGlobalMsgQuery->ShowMsgQueryL( iStatus, iQueryNoteText, aParams.DefaultCba(),
       
   933             iQueryPrompt, KNullDesC(), KNoImage, KNoImageMask,
       
   934         static_cast<CAknQueryDialog::TTone>( aParams.Tone() ) );
       
   935     SetActive();
       
   936     }
       
   937 
       
   938 // ---------------------------------------------------------
       
   939 // CPhoneQueryController::DestroyGlobalMsgQuery
       
   940 // ---------------------------------------------------------
       
   941 //
       
   942 void CPhoneQueryController::DestroyGlobalMsgQuery()
       
   943     {
       
   944     if ( iGlobalMsgQuery )
       
   945         {
       
   946         iGlobalMsgQuery->CancelMsgQuery();
       
   947 
       
   948         delete iGlobalMsgQuery;
       
   949         iGlobalMsgQuery = NULL;
       
   950         }
       
   951     }
       
   952 
       
   953 // ---------------------------------------------------------
       
   954 // CPhoneQueryController::CreateGlobalWaitNote
       
   955 // ---------------------------------------------------------
       
   956 //
       
   957 void CPhoneQueryController::CreateGlobalWaitNoteL(
       
   958         const TPhoneCmdParamQuery& aParams )
       
   959     {
       
   960     __LOGMETHODSTARTEND(EPhoneUIView,
       
   961         "CPhoneQueryController::CreateGlobalWaitNote()");
       
   962     if ( aParams.DataText()->Length() > 0 )
       
   963         {
       
   964         iWaitNoteText.Close();
       
   965         iWaitNoteText.Create( *aParams.DataText() );
       
   966         // use timeout if defined
       
   967         const TInt KSecToUsFactor = 1000000;
       
   968         TTimeIntervalMicroSeconds32 timeout = aParams.TimeOut() * KSecToUsFactor;
       
   969         if ( 0 < timeout.Int() && !iTimer )
       
   970             {
       
   971             iTimer = CPhoneTimer::NewL();
       
   972             iTimer->After( timeout, this );
       
   973             }
       
   974 
       
   975         DestroyGlobalWaitNote();
       
   976         iGlobalWaitNote = CAknGlobalNote::NewL();
       
   977         iGlobalWaitNote->SetSoftkeys( aParams.DefaultCba() );
       
   978         // Show the global note
       
   979         iGlobalWaitNote->ShowNoteL( iStatus, EAknGlobalWaitNote, *aParams.DataText()  );
       
   980 
       
   981         SetActive();
       
   982         }
       
   983     }
       
   984 
       
   985 // ---------------------------------------------------------
       
   986 // CPhoneQueryController::DestroyGlobalWaitNote
       
   987 // ---------------------------------------------------------
       
   988 //
       
   989 void CPhoneQueryController::DestroyGlobalWaitNote()
       
   990     {
       
   991     __LOGMETHODSTARTEND(EPhoneUIView,
       
   992           "CPhoneQueryController::DestroyGlobalWaitNote()");
       
   993     if ( iGlobalWaitNote )
       
   994         {
       
   995         ClearTimer();
       
   996         TRAP_IGNORE( iGlobalWaitNote->CancelNoteL( KErrCancel ) );
       
   997 
       
   998         delete iGlobalWaitNote;
       
   999         iGlobalWaitNote = NULL;
       
  1000         }
       
  1001     iWaitNoteText.Close();
       
  1002     }
       
  1003 
       
  1004 // ---------------------------------------------------------
       
  1005 // CPhoneQueryController::ProcessCommand
       
  1006 // ---------------------------------------------------------
       
  1007 
       
  1008 void CPhoneQueryController::ProcessCommandL( TInt aCommandId )
       
  1009     {
       
  1010 	__LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::ProcessCommandL()");
       
  1011 
       
  1012 	iCommandId = aCommandId;
       
  1013 
       
  1014     if ( iTextQuery )
       
  1015         { // Store text for next content getting
       
  1016         iQueryPreviousText.Close();
       
  1017         iQueryPreviousText.Create( KPhoneMaxCharsInNote );
       
  1018         iTextQuery->GetContent( iQueryPreviousText );
       
  1019         }
       
  1020 
       
  1021     iCommandAsync = CIdle::NewL( EPriorityNormal );
       
  1022     iCommandAsync->Start( TCallBack( ProcessCommandCallBack, this ) );
       
  1023     }
       
  1024 
       
  1025 // ---------------------------------------------------------
       
  1026 // CPhoneQueryController::ProcessCommandCallBack
       
  1027 // ---------------------------------------------------------
       
  1028 //
       
  1029 TInt CPhoneQueryController::ProcessCommandCallBack( TAny* aCPhoneQueryController )
       
  1030     {
       
  1031     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneQueryController::ProcessCommandCallBack() ");
       
  1032 
       
  1033     CPhoneQueryController* queryController =
       
  1034         static_cast<CPhoneQueryController*>( aCPhoneQueryController );
       
  1035 
       
  1036     delete queryController->iCommandAsync;
       
  1037     queryController->iCommandAsync = NULL;
       
  1038 
       
  1039     TRAP_IGNORE( static_cast<MEikCommandObserver*>( queryController->iEikEnv.EikAppUi() )
       
  1040         ->ProcessCommandL( queryController->iCommandId ) );
       
  1041 
       
  1042     return KErrNone;
       
  1043     }
       
  1044 
       
  1045 
       
  1046 // end of file
       
  1047