voiceui/voiceuivoicerecognition/src/vuiccontactresultsstate.cpp
branchRCL_3
changeset 19 e36f3802f733
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     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 <CPbkViewState.h>
       
    21 #include <PbkUID.h>
       
    22 #include <StringLoader.h>
       
    23 
       
    24 #include <vasmbasepbkhandler.h>
       
    25 
       
    26 #include <vuivoicerecognition.rsg>
       
    27 
       
    28 #include "vuivoicerecognition.hrh"
       
    29 
       
    30 #include "vuicstate.h"
       
    31 #include "vuiccontactresultsstate.h"
       
    32 #include "vuicplaystate.h"
       
    33 #include "vuicabortstate.h"
       
    34 #include "vuicerrorstate.h"
       
    35 #include "vuicexitstate.h"
       
    36 
       
    37 #include "vuicdatastorage.h"
       
    38 
       
    39 #include "vuicvoicerecogdialogimpl.h"
       
    40 #include "vuicnbestlistdialog.h"
       
    41 #include "vuicttsplayer.h"
       
    42 #include "vuivoiceicondefs.h"
       
    43 
       
    44 #include "rubydebug.h"
       
    45 
       
    46 // Constants
       
    47 _LIT( KTab, "\t" );
       
    48 _LIT( KStringPosition, "%U" );
       
    49     
       
    50 // -----------------------------------------------------------------------------
       
    51 // CContactResultsState::NewL
       
    52 // Two-phased constructor.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CContactResultsState* CContactResultsState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
    56     {
       
    57     CContactResultsState* self = new (ELeave) CContactResultsState( aDataStorage, aUiModel );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }       
       
    63     
       
    64 // Destructor       
       
    65 CContactResultsState::~CContactResultsState()
       
    66     {
       
    67     RUBY_DEBUG0( "CContactResultsState::~CContactResultsState START" );
       
    68     
       
    69     DataStorage().TtsPlayer()->Stop();
       
    70     
       
    71     delete iNBestListDialog;
       
    72     
       
    73     delete iTagList; // Only copies of pointers, do not reset and destroy
       
    74     
       
    75     DataStorage().SetAdditionalTagList( NULL ); // Reset for next time
       
    76     
       
    77     delete iNssVasDbManager;
       
    78     iNssTagManager = NULL;
       
    79     
       
    80     RUBY_DEBUG0( "CContactResultsState::~CContactResultsState EXIT" );
       
    81     }
       
    82     
       
    83 // ---------------------------------------------------------
       
    84 // CContactResultsState::HandleEventL
       
    85 // ---------------------------------------------------------
       
    86 //       
       
    87 void CContactResultsState::HandleEventL( TInt aEvent )
       
    88     {
       
    89     RUBY_DEBUG_BLOCK( "CContactResultsState::HandleEventL" );
       
    90 
       
    91     CState* nextState = NULL;
       
    92 
       
    93     switch( aEvent )
       
    94         {
       
    95         case KErrNone:
       
    96         
       
    97             if ( iInternalState == ENotStarted )
       
    98                 {
       
    99                 nextState = this;
       
   100                 }
       
   101             else if ( iInternalState == EStarted )
       
   102                 {
       
   103                 iInternalState = EInitialized;
       
   104                 nextState = this;
       
   105                 }
       
   106             else if ( iInternalState == EInitialized )
       
   107                 {
       
   108                 iInternalState = ECompleted;
       
   109                 nextState = this;
       
   110                 }
       
   111             break;
       
   112             
       
   113         case EVoiceTagSoftKeySelect:
       
   114         
       
   115             nextState = CPlayState::NewL( DataStorage(), UiModel() );
       
   116             break;
       
   117             
       
   118         case EAknSoftkeyQuit:
       
   119         case EAknSoftkeyNo:
       
   120         case EVoiceTagSoftKeyQuit:
       
   121         case EEndCallKeypress:
       
   122         case ELongKeypress:
       
   123         
       
   124             nextState = CAbortState::NewL( DataStorage(), UiModel() );
       
   125             break;
       
   126         
       
   127         case EShortKeypress:
       
   128         case EUpKeypress:
       
   129         case EDownKeypress:
       
   130         case ESelectKeypress:
       
   131         case EDirectSelectKeypress:
       
   132         case EDragKeypress:
       
   133         case EScrollKeypress:
       
   134         
       
   135             iKeypress = aEvent;
       
   136             nextState = this;
       
   137             break;
       
   138             
       
   139         default:
       
   140             
       
   141             nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent );
       
   142             break;
       
   143         }
       
   144 
       
   145     DataStorage().VoiceRecognitionImpl()->ChangeState( nextState );
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------
       
   149 // CContactResultsState::ExecuteL
       
   150 // ---------------------------------------------------------
       
   151 //       
       
   152 void CContactResultsState::ExecuteL()
       
   153     {
       
   154     RUBY_DEBUG_BLOCK( "CContactResultsState::ExecuteL" );
       
   155 
       
   156     if ( HandleKeypressL() )
       
   157         {
       
   158         iKeypress = ENoKeypress;
       
   159         }
       
   160     else if ( iInternalState == EInitialized )
       
   161         {
       
   162         // If automatic confirmation or device lock is on then start the timer
       
   163         if ( DataStorage().VerificationMode() == EAutomatic ||
       
   164              DataStorage().DeviceLockMode() )
       
   165             {
       
   166             TInt timeoutValue = DataStorage().PlayDuration().Int64();
       
   167             if ( timeoutValue < KTimeoutMicroseconds )
       
   168                 {
       
   169                 timeoutValue = KTimeoutMicroseconds;
       
   170                 }
       
   171         
       
   172             StartTimerL( *this, timeoutValue, timeoutValue );
       
   173             }
       
   174         }
       
   175     else if ( iInternalState == ECompleted )
       
   176         {
       
   177         DataStorage().TtsPlayer()->Stop();
       
   178         }
       
   179     else
       
   180         {
       
   181         if ( !DataStorage().AdditionalTagList() )
       
   182             {
       
   183             if ( iNssTagManager->GetTagList( DataStorage().VoiceRecognitionImpl(),
       
   184                                              DataStorage().Tag()->Context(),
       
   185                                              DataStorage().Tag()->RRD()->IntArray()->At( KVasContactIdRrdLocation ),
       
   186                                              KVasContactIdRrdLocation ) != KErrNone )
       
   187                 {
       
   188                 HandleEventL( KErrGeneral );
       
   189                 }
       
   190             }
       
   191         else
       
   192             {
       
   193             iInternalState = EStarted;
       
   194             
       
   195             TInt returnValue = KErrNoResults;
       
   196 
       
   197             // Get the name for the n-best list title
       
   198             HBufC* name = DataStorage().Tag()->SpeechItem()->PartialTextL( KNameTrainingIndex );
       
   199             CleanupStack::PushL( name );
       
   200             
       
   201             CreateContactInfoArrayL();
       
   202             
       
   203             if ( iTagList->Count() != KErrNone )
       
   204                 {
       
   205                 iNBestListDialog = CNBestListDialog::NewL();
       
   206                 iNBestListDialog->CreateNBestListPopupLC( CreateItemsArrayL(), *name );
       
   207     
       
   208                 PlaySelectedNameL();
       
   209                 BringToForeground();
       
   210     
       
   211                 iNBestListDialog->RegisterForKeyCallback( DataStorage().VoiceRecognitionImpl() );            
       
   212                 returnValue = iNBestListDialog->ShowNBestListPopupL(); // Pops things pushed in CreateNBestListPopupLC
       
   213                 }
       
   214             CleanupStack::PopAndDestroy( name );
       
   215             
       
   216             if ( returnValue != KErrNone )
       
   217                 {
       
   218                 iInternalState = ECompleted;
       
   219                 
       
   220                 SelectTag();
       
   221                 
       
   222                 HandleEventL( returnValue );
       
   223                 }
       
   224             }
       
   225         }
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------
       
   229 // CContactResultsState::CContactResultsState
       
   230 // ---------------------------------------------------------
       
   231 //              
       
   232 CContactResultsState::CContactResultsState( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
   233  : CState( aDataStorage, aUiModel ), iKeypress( ENoKeypress ),
       
   234    iInternalState( ENotStarted )
       
   235     {
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------
       
   239 // CContactResultsState::ConstructL
       
   240 // ---------------------------------------------------------
       
   241 //           
       
   242 void CContactResultsState::ConstructL()
       
   243     {
       
   244     RUBY_DEBUG_BLOCK( "CContactResultsState::ConstructL" );
       
   245     
       
   246     CState::ConstructL();
       
   247     
       
   248     iNssVasDbManager = CNssVASDBMgr::NewL();
       
   249     iNssVasDbManager->InitializeL();
       
   250     iNssTagManager = iNssVasDbManager->GetTagMgr();
       
   251    
       
   252     DataStorage().SetVerificationMode();
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------
       
   256 // CContactResultsState::DoTimedEventL
       
   257 // ---------------------------------------------------------
       
   258 //
       
   259 void CContactResultsState::DoTimedEventL()
       
   260    {   
       
   261    SelectTag();
       
   262    
       
   263    HandleEventL( EVoiceTagSoftKeySelect );
       
   264    }
       
   265 
       
   266 // ---------------------------------------------------------
       
   267 // CContactResultsState::HandleKeypressL
       
   268 // ---------------------------------------------------------
       
   269 //           
       
   270 TBool CContactResultsState::HandleKeypressL()
       
   271     {
       
   272     RUBY_DEBUG_BLOCK( "CContactResultsState::HandleKeypressL" );
       
   273     
       
   274     TBool handled = ETrue;
       
   275     
       
   276     if ( iKeypress == EShortKeypress )
       
   277         {       
       
   278         if ( iNBestListDialog->HandleShortKeypressL( NULL ) )
       
   279             {
       
   280             iInternalState = EStarted;
       
   281             
       
   282             PlaySelectedNameL();
       
   283             }
       
   284         else
       
   285             {
       
   286             HandleEventL( KErrNoResults );
       
   287             }
       
   288         }
       
   289     else if ( iKeypress == EUpKeypress || iKeypress == EDownKeypress ||
       
   290               iKeypress == EDragKeypress )
       
   291         {
       
   292         iInternalState = EStarted;
       
   293         
       
   294         PlaySelectedNameL();
       
   295         }
       
   296     else if ( iKeypress == EScrollKeypress )
       
   297         {
       
   298         StopTimer();
       
   299         }
       
   300     else if ( iKeypress == ESelectKeypress || iKeypress == EDirectSelectKeypress )
       
   301         {        
       
   302         if ( !DataStorage().Tag() )
       
   303             {
       
   304             SelectTag();
       
   305     
       
   306             HandleEventL( EVoiceTagSoftKeySelect );
       
   307             }
       
   308         }
       
   309     else
       
   310         {
       
   311         handled = EFalse;
       
   312         }
       
   313     
       
   314     return handled;
       
   315     }
       
   316     
       
   317 // ---------------------------------------------------------------------------
       
   318 // CContactResultsState::PlaySelectedNameL
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 void CContactResultsState::PlaySelectedNameL()
       
   322     {
       
   323     RUBY_DEBUG_BLOCK( "CContactResultsState::PlaySelectedNameL" );
       
   324 
       
   325     // if TTS is used
       
   326     if ( ( DataStorage().SynthesizerMode() != KErrNone ||
       
   327          DataStorage().DeviceLockMode() ) &&
       
   328          iTagList->Count() > 0 )
       
   329         {
       
   330         TInt index = iNBestListDialog->SelectedIndex();        
       
   331         MNssTag* tag = iTagList->At( index );
       
   332             
       
   333         if ( tag->Context()->ContextName() == KVoiceDialContext &&
       
   334              tag->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial )
       
   335             {
       
   336             HBufC* ttsText = StringLoader::LoadLC( R_QAN_VC_TTS_DIALLING );
       
   337             
       
   338             TInt position = ttsText->FindC( KStringPosition );
       
   339             User::LeaveIfError( position );            
       
   340             
       
   341             CleanupStack::PopAndDestroy( ttsText );
       
   342             
       
   343             ttsText = StringLoader::LoadLC( R_QAN_VC_TTS_DIALLING,
       
   344                                             tag->SpeechItem()->Text() );
       
   345                                                    
       
   346             HBufC* text = tag->SpeechItem()->PartialTextL( KNameTrainingIndex );        
       
   347             CleanupStack::PushL( text ); 
       
   348             
       
   349             DataStorage().TtsPlayer()->PlayL( *ttsText, position,
       
   350                                               tag->SpeechItem()->Text().Length() , *text );
       
   351             
       
   352             CleanupStack::PopAndDestroy( text );
       
   353             CleanupStack::PopAndDestroy( ttsText );
       
   354             }
       
   355         else if ( tag->Context()->ContextName() == KVoiceDialContext )
       
   356             {           
       
   357             HBufC* text = tag->SpeechItem()->PartialTextL( KNameTrainingIndex );        
       
   358             CleanupStack::PushL( text ); 
       
   359         
       
   360             DataStorage().TtsPlayer()->PlayL( tag->SpeechItem()->Text(), 0,
       
   361                                               tag->SpeechItem()->Text().Length(), *text );
       
   362 
       
   363             CleanupStack::PopAndDestroy( text );
       
   364             }
       
   365         }
       
   366     else
       
   367         {
       
   368         DataStorage().SetPlayDuration( KTimeoutMicroseconds );
       
   369         HandleEventL( KErrNone );
       
   370         }
       
   371     }
       
   372     
       
   373 // ---------------------------------------------------------------------------
       
   374 // CContactResultsState::CreateContactInfoArrayL
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CContactResultsState::CreateContactInfoArrayL()
       
   378     {
       
   379     RUBY_DEBUG_BLOCK( "CContactResultsState::CreateContactInfoArrayL" );
       
   380     
       
   381     CArrayPtrFlat<MNssTag>* completeTagList = DataStorage().CompleteTagList();
       
   382     CArrayPtrFlat<MNssTag>* additionalTags = DataStorage().AdditionalTagList();
       
   383     
       
   384     iTagList = new ( ELeave ) CArrayPtrFlat<MNssTag>( KSindMaxResults );
       
   385     
       
   386     iTagList->AppendL( DataStorage().Tag() );
       
   387     
       
   388     // Add all commands from selected contact to taglist
       
   389     for ( TInt i = 0; i < completeTagList->Count(); ++i )
       
   390         {
       
   391         MNssTag* tag = completeTagList->At( i );
       
   392         
       
   393         if ( tag->Context()->ContextName() == KVoiceDialContext &&
       
   394              ( !DataStorage().DeviceLockMode() || tag->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial ) &&
       
   395              tag->RRD()->IntArray()->At( KVasContactIdRrdLocation ) ==
       
   396              DataStorage().Tag()->RRD()->IntArray()->At( KVasContactIdRrdLocation ) &&
       
   397              CompareContactNamesL( tag ) )
       
   398             {
       
   399             // Add tag to list
       
   400             iTagList->AppendL( tag );
       
   401             }
       
   402         }
       
   403     
       
   404     // Add all additional commands from selected contact to taglist if not added already    
       
   405     for ( TInt i = 0; i < additionalTags->Count(); ++i )
       
   406         {
       
   407         MNssTag* tag = additionalTags->At( i );
       
   408         
       
   409         if ( !CheckIfAlreadyAdded( tag ) && CompareContactNamesL( tag ) &&
       
   410              ( !DataStorage().DeviceLockMode() || tag->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial ) )
       
   411             {
       
   412             // Add tag to list
       
   413             iTagList->AppendL( tag );
       
   414             }
       
   415         }
       
   416         
       
   417     // Add selected tag back to tag list
       
   418     completeTagList->AppendL( DataStorage().Tag() );
       
   419     
       
   420     // Clear selected tag    
       
   421     DataStorage().SetTag( NULL, EFalse );
       
   422     }
       
   423 
       
   424 // ---------------------------------------------------------
       
   425 // CContactResultsState::CompareContactNamesL
       
   426 // ---------------------------------------------------------
       
   427 //     
       
   428 TBool CContactResultsState::CompareContactNamesL( MNssTag* aTag )
       
   429     {
       
   430     RUBY_DEBUG_BLOCK( "CContactResultsState::CompareContactNamesL" );
       
   431     
       
   432     TBool returnValue = EFalse;
       
   433     
       
   434     HBufC* firstName = DataStorage().Tag()->SpeechItem()->PartialTextL( KNameTrainingIndex );
       
   435     CleanupStack::PushL( firstName );
       
   436     
       
   437     HBufC* secondName = aTag->SpeechItem()->PartialTextL( KNameTrainingIndex );
       
   438     CleanupStack::PushL( secondName );
       
   439     
       
   440     returnValue = ( *firstName == *secondName );
       
   441         
       
   442     CleanupStack::PopAndDestroy( secondName );
       
   443     CleanupStack::PopAndDestroy( firstName );
       
   444     
       
   445     return returnValue;
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------
       
   449 // CContactResultsState::CheckIfAlreadyAdded
       
   450 // ---------------------------------------------------------
       
   451 //    
       
   452 TBool CContactResultsState::CheckIfAlreadyAdded( MNssTag* aTag )
       
   453     {
       
   454     RUBY_DEBUG0( "CContactResultsState::CheckIfAlreadyAdded START" );
       
   455     
       
   456     TBool returnValue = EFalse;
       
   457 
       
   458     for ( TInt i = 0; i < iTagList->Count(); ++i )
       
   459         {
       
   460         if ( aTag->SpeechItem()->RawText() ==
       
   461              iTagList->At( i )->SpeechItem()->RawText() ||
       
   462              aTag->SpeechItem()->RawText() ==
       
   463              DataStorage().Tag()->SpeechItem()->RawText() )
       
   464             {
       
   465             returnValue = ETrue;
       
   466             
       
   467             break;
       
   468             }
       
   469         }
       
   470     
       
   471     RUBY_DEBUG0( "CContactResultsState::CheckIfAlreadyAdded EXIT" );
       
   472     
       
   473     return returnValue;
       
   474     }
       
   475     
       
   476 // ---------------------------------------------------------------------------
       
   477 // CContactResultsState::CreateItemsArrayLC
       
   478 // ---------------------------------------------------------------------------
       
   479 //    
       
   480 CDesC16ArrayFlat* CContactResultsState::CreateItemsArrayL()
       
   481     {
       
   482     RUBY_DEBUG_BLOCK( "CContactResultsState::CreateItemsArrayL" );
       
   483         
       
   484     TInt count = iTagList->Count();
       
   485            
       
   486     CDesC16ArrayFlat* items = new ( ELeave ) CDesC16ArrayFlat( KSindMaxResults );
       
   487     CleanupStack::PushL( items );
       
   488 
       
   489     TFullName buffer;
       
   490     
       
   491     for ( TInt i = 0; i < count; ++i )
       
   492         {
       
   493         MNssTag* tag = iTagList->At( i );        
       
   494         
       
   495         FillDialContextBufferL( tag, buffer );
       
   496             
       
   497         items->AppendL( buffer );
       
   498         }
       
   499         
       
   500     CleanupStack::Pop( items );
       
   501     
       
   502     return items;
       
   503     }
       
   504 
       
   505 // ---------------------------------------------------------
       
   506 // CContactResultsState::FillDialContextBufferL
       
   507 // ---------------------------------------------------------
       
   508 //
       
   509 void CContactResultsState::FillDialContextBufferL( MNssTag* aTag, TDes& aBuffer )
       
   510     {
       
   511     RUBY_DEBUG_BLOCK( "CContactResultsState::FillDialContextBufferL" );
       
   512     
       
   513     TPtrC type = KNullDesC();
       
   514     
       
   515     DataStorage().PbkHandler()->FindContactFieldL( aTag );
       
   516                            
       
   517     TBufC<KMaxFieldLength> phoneNumber = DataStorage().PbkHandler()->TextL();
       
   518     type.Set( GetContactIconType( DataStorage().PbkHandler()->FieldTypeL() ) );
       
   519 
       
   520     aBuffer.Zero();
       
   521     aBuffer.Append( type );
       
   522     aBuffer.Append( KTab );
       
   523     
       
   524     HBufC* label = NULL;
       
   525         
       
   526     TRAPD( error, label = aTag->SpeechItem()->PartialTextL( KExtensionTrainingIndex ) );
       
   527     if ( error == KErrNone || error == KErrNotFound )
       
   528         {
       
   529         // If there is no extension then the phonebook label is shown
       
   530         if ( label )
       
   531             {
       
   532             CleanupStack::PushL( label );
       
   533     
       
   534             aBuffer.Append( *label );
       
   535     
       
   536             CleanupStack::PopAndDestroy( label );
       
   537             }
       
   538         else
       
   539             {
       
   540             aBuffer.Append( DataStorage().PbkHandler()->LabelL() );
       
   541             }
       
   542         }
       
   543     else
       
   544         {
       
   545         User::Leave( error );
       
   546         }
       
   547         
       
   548     aBuffer.Append( KTab );
       
   549     aBuffer.Append( phoneNumber );
       
   550     }
       
   551     
       
   552 // ---------------------------------------------------------
       
   553 // CContactResultsState::GetContactIconType
       
   554 // ---------------------------------------------------------
       
   555 //
       
   556 TPtrC CContactResultsState::GetContactIconType( TFieldType aFieldType )
       
   557     {
       
   558     RUBY_DEBUG0( "CContactResultsState::GetContactIconType START" );
       
   559     
       
   560     TPtrC type;
       
   561     // select a phone type
       
   562     if ( aFieldType == KUidContactFieldVCardMapVOICE )
       
   563         {
       
   564         type.Set( KIconPhone );
       
   565         }
       
   566     else if ( aFieldType == KUidContactFieldVCardMapCELL )
       
   567         {
       
   568         type.Set( KIconMobile );
       
   569         }
       
   570     else if ( aFieldType == KUidContactFieldVCardMapFAX )
       
   571         {
       
   572         type.Set( KIconFax );
       
   573         }
       
   574     else if ( aFieldType == KUidContactFieldVCardMapEMAILINTERNET )
       
   575         {
       
   576         type.Set( KIconEmail );
       
   577         }
       
   578     else if ( aFieldType == KUidContactFieldVCardMapVIDEO )
       
   579         {
       
   580         type.Set( KIconVideo );
       
   581         }
       
   582     else if ( aFieldType == KUidContactFieldVCardMapVOIP )
       
   583         {
       
   584         type.Set( KIconVoip );
       
   585         }
       
   586     else
       
   587         {
       
   588         type.Set( KIconBlank );
       
   589         }
       
   590 
       
   591     RUBY_DEBUG0( "CContactResultsState::GetContactIconType EXIT" );
       
   592     
       
   593     return type;
       
   594     }
       
   595     
       
   596 // ---------------------------------------------------------
       
   597 // CContactResultsState::SelectTag
       
   598 // ---------------------------------------------------------
       
   599 //   
       
   600 void CContactResultsState::SelectTag()
       
   601     {
       
   602     RUBY_DEBUG0( "CContactResultsState::SelectTag START" );
       
   603     
       
   604     if ( iTagList->Count() > 0 )
       
   605         {
       
   606         DataStorage().SetTag( iTagList->At( iNBestListDialog->SelectedIndex() ), ETrue );
       
   607             
       
   608         // Remove selected item from the complete taglist
       
   609         for ( TInt i = 0; i < DataStorage().CompleteTagList()->Count(); ++i )
       
   610             {
       
   611             if ( DataStorage().CompleteTagList()->At( i ) ==
       
   612                  DataStorage().Tag() )
       
   613                 {
       
   614                 DataStorage().CompleteTagList()->Delete( i );
       
   615                 break;
       
   616                 }
       
   617             }
       
   618             
       
   619         // Remove selected item from the additional taglist
       
   620         for ( TInt i = 0; i < DataStorage().AdditionalTagList()->Count(); ++i )
       
   621             {
       
   622             if ( DataStorage().AdditionalTagList()->At( i ) ==
       
   623                  DataStorage().Tag() )
       
   624                 {
       
   625                 // Disable adaptation since tag is not from recognition results
       
   626                 DataStorage().SetAdaptationEnabled( EFalse );
       
   627                 
       
   628                 DataStorage().AdditionalTagList()->Delete( i );
       
   629                 break;
       
   630                 }
       
   631             }
       
   632         }
       
   633         
       
   634     RUBY_DEBUG0( "CContactResultsState::SelectTag EXIT" );
       
   635     }
       
   636 
       
   637 // End of File
       
   638