voiceui/voiceuivoicerecognition/src/vuicresultsstate.cpp
changeset 0 bf1d17376201
child 15 6347473a7bb2
equal deleted inserted replaced
-1:000000000000 0:bf1d17376201
       
     1 /*
       
     2 * Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <ccafactory.h>
       
    21 #include <mccaparameter.h>
       
    22 #include <mccaconnection.h>
       
    23 
       
    24 #include <vasmbasepbkhandler.h>
       
    25 
       
    26 #include <vuivoicerecognition.rsg>
       
    27 
       
    28 #include "vuivoicerecognition.hrh"
       
    29 
       
    30 #include "vuicstate.h"
       
    31 #include "vuicresultsstate.h"
       
    32 #include "vuicplaystate.h"
       
    33 #include "vuiccontactresultsstate.h"
       
    34 #include "vuicabortstate.h"
       
    35 #include "vuicerrorstate.h"
       
    36 #include "vuicexitstate.h"
       
    37 
       
    38 #include "vuicdatastorage.h"
       
    39 
       
    40 #include "vuicvoicerecogdialogimpl.h"
       
    41 #include "vuicnbestlistdialog.h"
       
    42 #include "vuicttsplayer.h"
       
    43 #include "vuivoiceicondefs.h"
       
    44 
       
    45 #include "rubydebug.h"
       
    46 
       
    47 _LIT( KTab, "\t" );
       
    48     
       
    49 // -----------------------------------------------------------------------------
       
    50 // CResultsState::NewL
       
    51 // Two-phased constructor.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CResultsState* CResultsState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
    55     {
       
    56     CResultsState* self = new (ELeave) CResultsState( aDataStorage, aUiModel );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }       
       
    62     
       
    63 // Destructor       
       
    64 CResultsState::~CResultsState()
       
    65     {
       
    66     RUBY_DEBUG0( "CResultsState::~CResultsState START" );
       
    67     
       
    68     DataStorage().TtsPlayer()->Stop();
       
    69     
       
    70     delete iNBestListDialog;
       
    71     
       
    72     delete iTagList; // Only copies of pointers, do not reset and destroy
       
    73     
       
    74     if ( iConnection )
       
    75         {
       
    76         iConnection->Close();
       
    77         }
       
    78     
       
    79     RUBY_DEBUG0( "CResultsState::~CResultsState EXIT" );
       
    80     }
       
    81     
       
    82 // ---------------------------------------------------------
       
    83 // CResultsState::HandleEventL
       
    84 // ---------------------------------------------------------
       
    85 //       
       
    86 void CResultsState::HandleEventL( TInt aEvent )
       
    87     {
       
    88     RUBY_DEBUG_BLOCK( "CResultsState::HandleEventL" );
       
    89 
       
    90     CState* nextState = NULL;
       
    91 
       
    92     switch( aEvent )
       
    93         {
       
    94         case KErrNone:
       
    95         
       
    96             if ( iInternalState == EStarted )
       
    97                 {
       
    98                 iInternalState = EInitialized;
       
    99                 }
       
   100             else if ( iInternalState == EInitialized )
       
   101                 {
       
   102                 iInternalState = ECompleted;
       
   103                 nextState = this;
       
   104                 }                
       
   105             break;
       
   106                     
       
   107         case EVoiceTagSoftKeySelect:
       
   108             
       
   109             if ( DataStorage().Tag()->Context()->ContextName() == KVoiceDialContext )
       
   110                 {
       
   111                 nextState = CContactResultsState::NewL( DataStorage(), UiModel() );
       
   112                 }
       
   113             else
       
   114                 {
       
   115                 nextState = CPlayState::NewL( DataStorage(), UiModel() );
       
   116                 }
       
   117             break;
       
   118             
       
   119         case EVoiceTagSoftKeyDirectSelect:
       
   120 
       
   121             nextState = CPlayState::NewL( DataStorage(), UiModel() );
       
   122             break;
       
   123         
       
   124         case EAknSoftkeyQuit:
       
   125         case EAknSoftkeyNo:
       
   126         case EVoiceTagSoftKeyQuit:
       
   127         case EEndCallKeypress:
       
   128         case ELongKeypress:
       
   129 
       
   130             nextState = CAbortState::NewL( DataStorage(), UiModel() );
       
   131             break;
       
   132         
       
   133         case EShortKeypress:
       
   134         case EUpKeypress:
       
   135         case EDownKeypress:
       
   136         case ESelectKeypress:
       
   137         case EDirectSelectKeypress:
       
   138         case EOptionsKeypress:
       
   139         case EOpenKeypress:
       
   140         case EDragKeypress:
       
   141         case EScrollKeypress:
       
   142         
       
   143             iKeypress = aEvent;
       
   144             nextState = this;
       
   145             break;
       
   146         
       
   147         case EAknSoftkeyOpen:
       
   148         
       
   149             nextState = CExitState::NewL( DataStorage(), UiModel() );
       
   150             break;
       
   151             
       
   152         default:
       
   153             
       
   154             nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent );
       
   155             break;
       
   156         }
       
   157 
       
   158     DataStorage().VoiceRecognitionImpl()->ChangeState( nextState );
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CResultsState::ExecuteL
       
   163 // ---------------------------------------------------------
       
   164 //       
       
   165 void CResultsState::ExecuteL()
       
   166     {
       
   167     RUBY_DEBUG_BLOCK( "CResultsState::ExecuteL" );
       
   168 
       
   169     if ( HandleKeypressL() )
       
   170         {
       
   171         iKeypress = ENoKeypress;
       
   172         }
       
   173     else if ( iInternalState == ECompleted )
       
   174         {
       
   175         DataStorage().TtsPlayer()->Stop();
       
   176         }
       
   177     else
       
   178         {
       
   179         TInt returnValue = KErrNoResults;
       
   180         
       
   181         if ( DataStorage().CompleteTagList()->Count() != KErrNone )
       
   182             {
       
   183             iInternalState = EStarted;
       
   184             
       
   185             CreateContactArrayL();
       
   186             
       
   187             if ( iTagList->Count() != KErrNone )
       
   188                 {
       
   189                 iNBestListDialog = CNBestListDialog::NewL();
       
   190                 
       
   191                 CDesC16ArrayFlat* items = NULL;
       
   192                 TRAPD( error, items = CreateItemsArrayL() );
       
   193                 
       
   194                 if ( !error )
       
   195                     {
       
   196                     iNBestListDialog->CreateNBestListPopupLC( items );
       
   197                     iNBestListDialog->SetSoftkeysL( R_SOFTKEYS_OPTIONS_QUIT__SELECT );
       
   198                 
       
   199                     CheckOptionsCommands();
       
   200                     PlaySelectedNameL();
       
   201                     BringToForeground();
       
   202                     
       
   203                     // If automatic confirmation or device lock is on then start the timer
       
   204                     if ( DataStorage().VerificationMode() == EAutomatic ||
       
   205                          DataStorage().DeviceLockMode() )
       
   206                         {
       
   207                         StartTimerL( *this, KTimeoutMicroseconds, KTimeoutMicroseconds );
       
   208                         }
       
   209     
       
   210                     iNBestListDialog->RegisterForKeyCallback( DataStorage().VoiceRecognitionImpl() );        
       
   211                     returnValue = iNBestListDialog->ShowNBestListPopupL(); // Pops things pushed in CreateNBestListPopupLC
       
   212                     RUBY_DEBUG1( "CResultsState::ExecuteL - N-Best list returns [%d]", returnValue );
       
   213                     }
       
   214                 else if ( error != KErrNotFound )
       
   215                     {
       
   216                     User::Leave( error );
       
   217                     }
       
   218                 }
       
   219             }
       
   220         
       
   221         if ( returnValue != KErrNone )
       
   222             {
       
   223             iInternalState = ECompleted;
       
   224             
       
   225             SelectTag();
       
   226             
       
   227             HandleEventL( returnValue );
       
   228             }
       
   229         }
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CResultsState::CResultsState
       
   234 // ---------------------------------------------------------
       
   235 //     
       
   236 void CResultsState::CCASimpleNotifyL( TNotifyType /*aType*/, TInt /*aReason*/ )
       
   237     {
       
   238     RUBY_DEBUG_BLOCK( "CResultsState::CCASimpleNotifyL" );
       
   239         
       
   240     HandleEventL( EAknSoftkeyOpen );
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------
       
   244 // CResultsState::CResultsState
       
   245 // ---------------------------------------------------------
       
   246 //              
       
   247 CResultsState::CResultsState( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
   248  : CState( aDataStorage, aUiModel ), iKeypress( ENoKeypress ),
       
   249    iInternalState( ENotStarted )
       
   250     {
       
   251     }
       
   252 
       
   253 // ---------------------------------------------------------
       
   254 // CResultsState::ConstructL
       
   255 // ---------------------------------------------------------
       
   256 //           
       
   257 void CResultsState::ConstructL()
       
   258     {
       
   259     RUBY_DEBUG_BLOCK( "CResultsState::ConstructL" );
       
   260     
       
   261     CState::ConstructL();
       
   262     
       
   263     DataStorage().SetAdaptationEnabled( ETrue );
       
   264     }
       
   265     
       
   266 // ---------------------------------------------------------
       
   267 // CResultsState::DoTimedEventL
       
   268 // ---------------------------------------------------------
       
   269 //
       
   270 void CResultsState::DoTimedEventL()
       
   271    {
       
   272    RUBY_DEBUG_BLOCK( "CResultsState::DoTimedEventL" );
       
   273    
       
   274    SelectTag();
       
   275    
       
   276    HandleEventL( EVoiceTagSoftKeySelect );
       
   277    }
       
   278     
       
   279 // ---------------------------------------------------------
       
   280 // CResultsState::HandleKeypressL
       
   281 // ---------------------------------------------------------
       
   282 //           
       
   283 TBool CResultsState::HandleKeypressL()
       
   284     {
       
   285     RUBY_DEBUG_BLOCK( "CResultsState::HandleKeypressL" );
       
   286     
       
   287     TBool handled = ETrue;
       
   288     
       
   289     if ( iKeypress == EShortKeypress )
       
   290         {
       
   291         CDesC16ArrayFlat* items = NULL;
       
   292         
       
   293         if ( UpdateContactArray() )
       
   294             {
       
   295             items = CreateItemsArrayL();
       
   296             }
       
   297         
       
   298         if ( iNBestListDialog->HandleShortKeypressL( items ) )
       
   299             {
       
   300             iInternalState = EStarted;
       
   301         
       
   302             CheckOptionsCommands();
       
   303             PlaySelectedNameL();
       
   304             
       
   305             // If automatic confirmation or device lock is on then start the timer
       
   306             if ( DataStorage().VerificationMode() == EAutomatic ||
       
   307                  DataStorage().DeviceLockMode() )
       
   308                 {
       
   309                 StartTimerL( *this, KTimeoutMicroseconds, KTimeoutMicroseconds );
       
   310                 }
       
   311             }
       
   312         else
       
   313             {
       
   314             HandleEventL( KErrNoResults );
       
   315             }
       
   316         }
       
   317     else if ( iKeypress == EUpKeypress || iKeypress == EDownKeypress ||
       
   318               iKeypress == EDragKeypress )
       
   319         {
       
   320         iInternalState = EStarted;
       
   321         
       
   322         CheckOptionsCommands();
       
   323         PlaySelectedNameL();
       
   324         
       
   325         // If automatic confirmation or device lock is on then start the timer
       
   326         if ( DataStorage().VerificationMode() == EAutomatic ||
       
   327                 DataStorage().DeviceLockMode() )
       
   328             {
       
   329             StartTimerL( *this, KTimeoutMicroseconds, KTimeoutMicroseconds );
       
   330             }
       
   331         }
       
   332     else if ( iKeypress == EScrollKeypress )
       
   333         {
       
   334         StopTimer();
       
   335         }
       
   336     else if ( iKeypress == ESelectKeypress )
       
   337         {        
       
   338         if ( !DataStorage().Tag() )
       
   339             {
       
   340             SelectTag();
       
   341     
       
   342             HandleEventL( EVoiceTagSoftKeySelect );
       
   343             }
       
   344         }
       
   345     else if ( iKeypress == EDirectSelectKeypress )
       
   346         {        
       
   347         if ( !DataStorage().Tag() )
       
   348             {
       
   349             SelectTag();
       
   350     
       
   351             HandleEventL( EVoiceTagSoftKeyDirectSelect );
       
   352             }
       
   353         }
       
   354     else if ( iKeypress == EOptionsKeypress )
       
   355         {        
       
   356         StopTimer();
       
   357         DataStorage().SetVerificationMode( EManual );
       
   358         }
       
   359     else if ( iKeypress == EOpenKeypress )
       
   360         {       
       
   361         OpenPhonebookContactL();
       
   362         }
       
   363     else
       
   364         {
       
   365         handled = EFalse;
       
   366         }
       
   367     
       
   368     return handled;
       
   369     }
       
   370     
       
   371 // ---------------------------------------------------------------------------
       
   372 // CResultsState::PlaySelectedNameL
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CResultsState::PlaySelectedNameL()
       
   376     {
       
   377     RUBY_DEBUG_BLOCK( "CResultsState::PlaySelectedNameL" );
       
   378 
       
   379     // if TTS is used
       
   380     if ( ( DataStorage().SynthesizerMode() != KErrNone ||
       
   381          DataStorage().DeviceLockMode() ) &&
       
   382          iTagList->Count() > 0 )
       
   383         {
       
   384         TInt index = iNBestListDialog->SelectedIndex();
       
   385         HBufC* text = NULL;
       
   386                     
       
   387         if ( iTagList->At( index )->Context()->ContextName() == KVoiceDialContext )
       
   388             {
       
   389             text = iTagList->At( index )->SpeechItem()->PartialTextL( KNameTrainingIndex );
       
   390             }
       
   391         else
       
   392             {
       
   393             text = HBufC::NewL( 0 );
       
   394             }
       
   395 
       
   396         CleanupStack::PushL( text );        
       
   397                 
       
   398         DataStorage().TtsPlayer()->PlayL( iTagList->At( index )->SpeechItem()->Text(), 0,
       
   399                                           iTagList->At( index )->SpeechItem()->Text().Length(),
       
   400                                           *text );
       
   401 
       
   402         CleanupStack::PopAndDestroy( text );
       
   403         }
       
   404     }
       
   405     
       
   406 // ---------------------------------------------------------------------------
       
   407 // CResultsState::CheckOptionsCommands
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 void CResultsState::CheckOptionsCommands()
       
   411     {
       
   412     RUBY_DEBUG0( "CResultsState::CheckOptionsCommands START" );
       
   413 
       
   414     if ( iTagList->Count() > 0 )
       
   415         {
       
   416         TBool hidden = ETrue;
       
   417         
       
   418         TInt index = iNBestListDialog->SelectedIndex();
       
   419         if ( iTagList->At( index )->Context()->ContextName() == KVoiceDialContext )
       
   420             {
       
   421             hidden = EFalse;
       
   422             }
       
   423         iNBestListDialog->SetCommandsHidden( hidden );
       
   424         }
       
   425     RUBY_DEBUG0( "CResultsState::CheckOptionsCommands EXIT" );
       
   426     }
       
   427     
       
   428 // ---------------------------------------------------------------------------
       
   429 // CResultsState::CreateContactArrayL
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 void CResultsState::CreateContactArrayL()
       
   433     {
       
   434     RUBY_DEBUG_BLOCK( "CResultsState::CreateContactArrayL" );
       
   435     
       
   436     CArrayPtrFlat<MNssTag>* completeTagList = DataStorage().CompleteTagList();
       
   437     
       
   438     iTagList = new ( ELeave ) CArrayPtrFlat<MNssTag>( KSindMaxResults );
       
   439     
       
   440     // Add commands to taglist
       
   441     for ( TInt i = 0; i < completeTagList->Count() && iTagList->Count() < KSindMaxResults; ++i )
       
   442         {
       
   443         MNssTag* tag = completeTagList->At( i );
       
   444         
       
   445         if ( tag->Context()->ContextName() == KVoiceDialContext &&
       
   446              ( !DataStorage().DeviceLockMode() || tag->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial ) )
       
   447             {   
       
   448             if ( !CheckIfAlreadyAdded( tag ) )
       
   449                 {
       
   450                 iTagList->AppendL( tag );            
       
   451                 }
       
   452             }
       
   453         else if ( !DataStorage().DeviceLockMode() )
       
   454             {
       
   455             iTagList->AppendL( tag );
       
   456             }
       
   457         }
       
   458     }
       
   459     
       
   460 // ---------------------------------------------------------------------------
       
   461 // CResultsState::UpdateContactArray
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 TBool CResultsState::UpdateContactArray()
       
   465     {
       
   466     RUBY_DEBUG0( "CResultsState::UpdateContactArray START" );
       
   467     
       
   468     MNssTag* tag = iTagList->At( iNBestListDialog->SelectedIndex() );
       
   469         
       
   470     TBool currentTagFound = EFalse;
       
   471     TBool updated = EFalse;
       
   472                         
       
   473     if ( tag->Context()->ContextName() == KVoiceDialContext )
       
   474         {  
       
   475         for ( TInt i = 0; i < DataStorage().CompleteTagList()->Count(); ++i )
       
   476             {
       
   477             MNssTag* newTag = DataStorage().CompleteTagList()->At( i );
       
   478             
       
   479             if ( newTag->Context()->ContextName() == KVoiceDialContext &&
       
   480                  ( !DataStorage().DeviceLockMode() || newTag->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial ) &&
       
   481                  tag->RRD()->IntArray()->At( KVasContactIdRrdLocation ) ==
       
   482                  newTag->RRD()->IntArray()->At( KVasContactIdRrdLocation ) )
       
   483                 {
       
   484                 if ( currentTagFound )
       
   485                     {
       
   486                     iTagList->At( iNBestListDialog->SelectedIndex() ) = newTag;
       
   487                     updated = ETrue;
       
   488                     break;
       
   489                     }   
       
   490                 else if ( tag->SpeechItem()->RawText() == newTag->SpeechItem()->RawText() )
       
   491                     {
       
   492                     currentTagFound = ETrue;
       
   493                     }
       
   494                 }
       
   495             }
       
   496         }
       
   497         
       
   498     RUBY_DEBUG0( "CResultsState::UpdateContactArray EXIT" );
       
   499         
       
   500     return updated;
       
   501     }
       
   502     
       
   503 // ---------------------------------------------------------
       
   504 // CResultsState::CheckIfAlreadyAdded
       
   505 // ---------------------------------------------------------
       
   506 //    
       
   507 TBool CResultsState::CheckIfAlreadyAdded( MNssTag* aTag )
       
   508     {
       
   509     RUBY_DEBUG0( "CResultsState::CheckIfAlreadyAdded START" );
       
   510     
       
   511     TBool returnValue = EFalse;
       
   512 
       
   513     for ( TInt i = 0; i < iTagList->Count(); ++i )
       
   514         {
       
   515         if ( aTag->RRD()->IntArray()->At( KVasContactIdRrdLocation ) ==
       
   516              iTagList->At( i )->RRD()->IntArray()->At( KVasContactIdRrdLocation ) )
       
   517             {
       
   518             returnValue = ETrue;
       
   519             
       
   520             break;
       
   521             }
       
   522         }
       
   523     
       
   524     RUBY_DEBUG0( "CResultsState::CheckIfAlreadyAdded EXIT" );
       
   525     
       
   526     return returnValue;
       
   527     }
       
   528     
       
   529 // ---------------------------------------------------------------------------
       
   530 // CResultsState::CreateItemsArrayLC
       
   531 // ---------------------------------------------------------------------------
       
   532 //    
       
   533 CDesC16ArrayFlat* CResultsState::CreateItemsArrayL()
       
   534     {
       
   535     RUBY_DEBUG_BLOCK( "CResultsState::CreateItemsArrayL" );
       
   536     
       
   537     TInt count = iTagList->Count();
       
   538             
       
   539     CDesC16ArrayFlat* items = new ( ELeave ) CDesC16ArrayFlat( KSindMaxResults );
       
   540     CleanupStack::PushL( items );
       
   541 
       
   542     TName buffer;
       
   543     
       
   544     for ( TInt i = 0; i < count; ++i )
       
   545         {
       
   546         MNssTag* tag = iTagList->At( i );
       
   547         
       
   548         if ( tag->Context()->ContextName() == KVoiceDialContext )
       
   549             {            
       
   550             FillDialContextBufferL( tag, buffer );
       
   551             
       
   552             items->AppendL( buffer );
       
   553             }
       
   554         else
       
   555             {                      
       
   556             FillCommandContextBuffer( tag, buffer );
       
   557             
       
   558             items->AppendL( buffer );
       
   559             }
       
   560         }
       
   561         
       
   562     CleanupStack::Pop( items );
       
   563     
       
   564     return items;
       
   565     }
       
   566 
       
   567 // ---------------------------------------------------------
       
   568 // CResultsState::FillDialContextBufferL
       
   569 // ---------------------------------------------------------
       
   570 //
       
   571 void CResultsState::FillDialContextBufferL( MNssTag* aTag, TDes& aBuffer )
       
   572     {
       
   573     RUBY_DEBUG_BLOCK( "CResultsState::FillDialContextBufferL" );
       
   574     
       
   575     TPtrC type = KNullDesC();
       
   576     
       
   577     DataStorage().PbkHandler()->FindContactFieldL( aTag );
       
   578         
       
   579     type.Set( GetContactIconType( DataStorage().PbkHandler()->FieldTypeL() ) );
       
   580 
       
   581     // Get the actual name only        
       
   582     HBufC* name = aTag->SpeechItem()->PartialTextL( KNameTrainingIndex );
       
   583     CleanupStack::PushL( name );
       
   584 
       
   585     aBuffer.Zero();
       
   586     aBuffer.Append( type );
       
   587     aBuffer.Append( KTab );
       
   588     aBuffer.Append( *name );
       
   589     aBuffer.Append( KTab );
       
   590     
       
   591     HBufC* label = NULL;
       
   592         
       
   593     TRAPD( error, label = aTag->SpeechItem()->PartialTextL( KExtensionTrainingIndex ) );
       
   594     if ( error == KErrNone || error == KErrNotFound )
       
   595         {
       
   596         // If there is no extension then the phonebook label is shown
       
   597         if ( label )
       
   598             {
       
   599             CleanupStack::PushL( label );
       
   600     
       
   601             aBuffer.Append( *label );
       
   602     
       
   603             CleanupStack::PopAndDestroy( label );
       
   604             }
       
   605         else
       
   606             {
       
   607             aBuffer.Append( DataStorage().PbkHandler()->LabelL() );
       
   608             }
       
   609         }
       
   610     else
       
   611         {
       
   612         User::Leave( error );
       
   613         }
       
   614 
       
   615     CleanupStack::PopAndDestroy( name );
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------
       
   619 // CResultsState::FillCommandContextBuffer
       
   620 // ---------------------------------------------------------
       
   621 //    
       
   622 void CResultsState::FillCommandContextBuffer( MNssTag* aTag, TDes& aBuffer )
       
   623     {
       
   624     RUBY_DEBUG0( "CResultsState::FillCommandContextBuffer START" );
       
   625     
       
   626     aBuffer.Zero();
       
   627     
       
   628     if ( aTag->RRD()->IntArray()->At( KVasContactIdRrdLocation ) >= KProfileValue )
       
   629         {
       
   630         aBuffer.Append( KIconProfile );
       
   631         }
       
   632     else
       
   633         {
       
   634         aBuffer.Append( KIconApplication );
       
   635         }
       
   636             
       
   637     aBuffer.Append( KTab );
       
   638     aBuffer.Append( aTag->SpeechItem()->Text() );
       
   639     
       
   640     RUBY_DEBUG0( "CResultsState::FillCommandContextBuffer EXIT" );
       
   641     }
       
   642         
       
   643 // ---------------------------------------------------------
       
   644 // CResultsState::GetContactIconType
       
   645 // ---------------------------------------------------------
       
   646 //
       
   647 TPtrC CResultsState::GetContactIconType( TFieldType aFieldType )
       
   648     {
       
   649     RUBY_DEBUG0( "CResultsState::GetContactIconType START" );
       
   650     
       
   651     TPtrC type;
       
   652     // select a phone type
       
   653     if ( aFieldType == KUidContactFieldVCardMapVOICE )
       
   654         {
       
   655         type.Set( KIconPhone );
       
   656         }
       
   657     else if ( aFieldType == KUidContactFieldVCardMapCELL )
       
   658         {
       
   659         type.Set( KIconMobile );
       
   660         }
       
   661     else if ( aFieldType == KUidContactFieldVCardMapFAX )
       
   662         {
       
   663         type.Set( KIconFax );
       
   664         }
       
   665     else if ( aFieldType == KUidContactFieldVCardMapEMAILINTERNET )
       
   666         {
       
   667         type.Set( KIconEmail );
       
   668         }
       
   669     else if ( aFieldType == KUidContactFieldVCardMapVIDEO )
       
   670         {
       
   671         type.Set( KIconVideo );
       
   672         }
       
   673     else if ( aFieldType == KUidContactFieldVCardMapVOIP )
       
   674         {
       
   675         type.Set( KIconVoip );
       
   676         }
       
   677     else
       
   678         {
       
   679         type.Set( KIconBlank );
       
   680         }
       
   681 
       
   682     RUBY_DEBUG0( "CResultsState::GetContactIconType EXIT" );
       
   683     
       
   684     return type;
       
   685     }
       
   686     
       
   687 // ---------------------------------------------------------
       
   688 // CResultsState::SelectTag
       
   689 // ---------------------------------------------------------
       
   690 //   
       
   691 void CResultsState::SelectTag()
       
   692     {
       
   693     RUBY_DEBUG0( "CResultsState::SelectTag START" );
       
   694     
       
   695     if ( iTagList && iTagList->Count() > 0 )
       
   696         {
       
   697         DataStorage().SetTag( iTagList->At( iNBestListDialog->SelectedIndex() ), ETrue );
       
   698        
       
   699         // Remove selected item from the complete taglist
       
   700         for ( TInt i = 0; i < DataStorage().CompleteTagList()->Count(); ++i )
       
   701             {
       
   702             if ( DataStorage().CompleteTagList()->At( i ) ==
       
   703                  DataStorage().Tag() )
       
   704                 {
       
   705                 DataStorage().CompleteTagList()->Delete( i );
       
   706                 break;
       
   707                 }
       
   708             }
       
   709         }
       
   710         
       
   711     RUBY_DEBUG0( "CResultsState::SelectTag EXIT" );
       
   712     }
       
   713 
       
   714 // ---------------------------------------------------------
       
   715 // CResultsState::OpenPhonebookContactL
       
   716 // ---------------------------------------------------------
       
   717 //      
       
   718 void CResultsState::OpenPhonebookContactL()
       
   719     {
       
   720     RUBY_DEBUG_BLOCK( "CResultsState::OpenPhonebookContactL" );
       
   721     
       
   722     SelectTag();
       
   723     
       
   724     if ( iConnection )
       
   725         {
       
   726         iConnection->Close();
       
   727         }
       
   728     iConnection = TCCAFactory::NewConnectionL();
       
   729 
       
   730     MCCAParameter* parameter = TCCAFactory::NewParameterL();
       
   731     CleanupClosePushL( *parameter );
       
   732 
       
   733     parameter->SetConnectionFlag( MCCAParameter::ENormal );
       
   734     parameter->SetContactDataFlag( MCCAParameter::EContactId );
       
   735 
       
   736     TBuf<10> idString;
       
   737     idString.Num( DataStorage().Tag()->RRD()->IntArray()->At( KVasContactIdRrdLocation ) );
       
   738 
       
   739     parameter->SetContactDataL( idString );
       
   740 
       
   741     iConnection->LaunchAppL( *parameter, this );
       
   742     
       
   743     CleanupStack::Pop(); // parameter
       
   744     }
       
   745     
       
   746 // End of File
       
   747