voiceui/voiceuivoicerecognition/src/vuicplaystate.cpp
branchRCL_3
changeset 23 e36f3802f733
equal deleted inserted replaced
22:cad71a31b7fc 23:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknappui.h>
       
    21 #include <AknUtils.h> 
       
    22 #include <AknIconUtils.h> 
       
    23 #include <cntdef.h>
       
    24 #include <AknsConstants.h>
       
    25 #include <StringLoader.h>
       
    26 #include <AudioPreference.h>
       
    27 
       
    28 #include <vasmbasepbkhandler.h>
       
    29 
       
    30 #include <secondarydisplay/vuisecondarydisplayapi.h>
       
    31 
       
    32 #include <vuivoicerecognition.rsg>
       
    33 
       
    34 #include "vuivoicerecognition.hrh"
       
    35 
       
    36 #include "vuicstate.h"
       
    37 #include "vuicplaystate.h"
       
    38 #include "vuictutorialstate.h"
       
    39 #include "vuicresultsstate.h"
       
    40 #include "vuicverificationinitstate.h"
       
    41 #include "vuicabortstate.h"
       
    42 
       
    43 #include "vuicdatastorage.h"
       
    44 
       
    45 #include "vuicvoicerecogdialogimpl.h"
       
    46 #include "vuicpropertyhandler.h"
       
    47 #include "vuictoneplayer.h"
       
    48 #include "vuicttsplayer.h"
       
    49 #include "vuicglobalprogressdialog.h"
       
    50 #include "vuivoiceicondefs.h"
       
    51 
       
    52 #include "rubydebug.h"
       
    53 
       
    54 // Constants
       
    55 _LIT( KStringPosition, "%U" );
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CPlayState::NewL
       
    59 // Two-phased constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CPlayState* CPlayState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
    63     {
       
    64     CPlayState* self = new (ELeave) CPlayState( aDataStorage, aUiModel );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }       
       
    70     
       
    71 // Destructor       
       
    72 CPlayState::~CPlayState()
       
    73     {
       
    74     RUBY_DEBUG0( "CPlayState::~CPlayState START" );
       
    75     
       
    76     DataStorage().TtsPlayer()->Stop();
       
    77     
       
    78     delete iProgressDialog;
       
    79     
       
    80     RUBY_DEBUG0( "CPlayState::~CPlayState EXIT" );
       
    81     }
       
    82     
       
    83 // ---------------------------------------------------------
       
    84 // CPlayState::HandleEventL
       
    85 // ---------------------------------------------------------
       
    86 //       
       
    87 void CPlayState::HandleEventL( TInt aEvent )
       
    88     {
       
    89     RUBY_DEBUG_BLOCK( "CPlayState::HandleEventL" );
       
    90 
       
    91     CState* nextState = NULL;
       
    92 
       
    93     switch( aEvent )
       
    94         {
       
    95         case KErrNone:
       
    96         
       
    97             if ( iInternalState == EStarted )
       
    98                 {
       
    99                 iInternalState = EInitialized;
       
   100                 nextState = this;
       
   101                 }
       
   102             else if ( iInternalState == EInitialized )
       
   103                 {
       
   104                 iInternalState = ECompleted;
       
   105                 nextState = this;
       
   106                 }
       
   107             break;
       
   108         
       
   109         case KErrPathNotFound:
       
   110         
       
   111             // Ignore mysterious path not found error when loading confirmation tone
       
   112             if ( iInternalState == EStarted )
       
   113                 {
       
   114                 nextState = CTutorialState::NewL( DataStorage(), UiModel() );
       
   115                 }
       
   116             break;
       
   117         
       
   118         case EVoiceTagSoftKeySelect:
       
   119         
       
   120             nextState = CTutorialState::NewL( DataStorage(), UiModel() );
       
   121             break;
       
   122             
       
   123         case EShortKeypress:
       
   124         case EVoiceTagSoftKeyOther:
       
   125         case EAknSoftkeyOther:
       
   126         case EAknSoftkeyDone:
       
   127         case EStdKeyDevice2:
       
   128         
       
   129             if ( iInternalState != EStarted )
       
   130                 {
       
   131                 if ( DataStorage().VerificationMode() != EVoice )
       
   132                     {
       
   133                     nextState = CResultsState::NewL( DataStorage(), UiModel() );
       
   134                     }
       
   135                 else
       
   136                     {
       
   137                     if ( DataStorage().Tag()->Context()->ContextName() == KVoiceDialContext &&
       
   138                          DataStorage().Tag()->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial )
       
   139                         {
       
   140                         nextState = CVerificationInitState::NewL( DataStorage(), UiModel() );
       
   141                         }
       
   142                     }
       
   143                 }
       
   144             break;
       
   145             
       
   146         case EEndCallKeypress:
       
   147         
       
   148             // Do nothing
       
   149             break;
       
   150             
       
   151         default:
       
   152         
       
   153             nextState = CAbortState::NewL( DataStorage(), UiModel() );
       
   154             break;
       
   155         }
       
   156 
       
   157     DataStorage().VoiceRecognitionImpl()->ChangeState( nextState );
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // CPlayState::ExecuteL
       
   162 // ---------------------------------------------------------
       
   163 //       
       
   164 void CPlayState::ExecuteL()
       
   165     {
       
   166     RUBY_DEBUG_BLOCK( "CPlayState::ExecuteL" );
       
   167 
       
   168     if ( iInternalState == ENotStarted )
       
   169         {
       
   170         TBuf<KMaxFieldLength> phoneNumber;        
       
   171         TFieldType fieldType;        
       
   172         TName name;
       
   173         
       
   174         iInternalState = EStarted;
       
   175 
       
   176         if ( DataStorage().Tag()->Context()->ContextName() == KVoiceDialContext )
       
   177             {
       
   178             if ( DataStorage().VerificationMode() == EVoice &&
       
   179                  DataStorage().Tag()->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial )
       
   180                 {
       
   181                 FormatDataL( name, phoneNumber, fieldType );
       
   182 
       
   183                 ShowPlaydialogL( name, phoneNumber, fieldType );
       
   184                 }
       
   185             else
       
   186                 {
       
   187                 TRAP_IGNORE( HandleEventL( EVoiceTagSoftKeySelect ) );
       
   188                 }
       
   189             }
       
   190         else
       
   191             {
       
   192             DataStorage().TonePlayer()->InitToneL( EAvkonSIDConfirmationTone );
       
   193             }                
       
   194         }
       
   195     else if ( iInternalState == EInitialized )
       
   196         {
       
   197         if ( DataStorage().Tag()->Context()->ContextName() == KVoiceDialContext &&
       
   198              DataStorage().Tag()->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial )
       
   199             {
       
   200             iTModel.iFinalValue = DataStorage().PlayDuration().Int64() / KKRecogInterval + 4 * KRecogDelay;
       
   201             StartTimerL( *this, KRecogDelay, KKRecogInterval * iTModel.iHundreths );
       
   202             }
       
   203         else
       
   204             {
       
   205             DataStorage().TonePlayer()->PlayTone( EAvkonSIDConfirmationTone );
       
   206             }
       
   207         }
       
   208     else  if ( iInternalState == ECompleted )
       
   209         {
       
   210         if ( DataStorage().Tag()->Context()->ContextName() != KVoiceDialContext ||
       
   211              DataStorage().Tag()->RRD()->IntArray()->At( KVasExtensionRrdLocation ) != EDial )
       
   212             {
       
   213             TRAP_IGNORE( HandleEventL( EVoiceTagSoftKeySelect ) );
       
   214             }
       
   215         }
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------
       
   219 // CPlayState::CPlayState
       
   220 // ---------------------------------------------------------
       
   221 //              
       
   222 CPlayState::CPlayState( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
   223  : CState( aDataStorage, aUiModel ), iInternalState( ENotStarted ),
       
   224    iTickCount( 0 ), iPlaybackDelay( KPlaybackTimeout )
       
   225     {
       
   226     iTModel.iFinalValue = KRecogFinal;
       
   227     iTModel.iHundreths = KRecogInterval;
       
   228     iTModel.iIncrement = KRecogIncrement;
       
   229     iTModel.iRunning = EFalse;
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CPlayState::ConstructL
       
   234 // ---------------------------------------------------------
       
   235 //           
       
   236 void CPlayState::ConstructL()
       
   237     {
       
   238     RUBY_DEBUG_BLOCK( "CPlayState::ConstructL" );
       
   239     
       
   240     CState::ConstructL();
       
   241     }
       
   242     
       
   243 // ---------------------------------------------------------
       
   244 // CPlayState::DoTimedEventL
       
   245 // ---------------------------------------------------------
       
   246 //
       
   247 void CPlayState::DoTimedEventL()
       
   248     {
       
   249     if ( ( ++iTickCount < iTModel.iFinalValue + iPlaybackDelay ) && iProgressDialog )
       
   250         {
       
   251         iProgressDialog->UpdateProgressDialogL( iTickCount, iTModel.iFinalValue ); 
       
   252         }
       
   253     else 
       
   254         {
       
   255         HandleEventL( EVoiceTagSoftKeySelect );
       
   256         } 
       
   257     }
       
   258     
       
   259 // ---------------------------------------------------------
       
   260 // CPlayState::FormatName
       
   261 // ---------------------------------------------------------
       
   262 //           
       
   263 void CPlayState::FormatName( TDes& aName )
       
   264     {
       
   265     RUBY_DEBUG0( "CPlayState::FormatName START" );
       
   266     
       
   267     const CFont* font = CEikonEnv::Static()->NormalFont();
       
   268     if ( AknLayoutUtils::Variant() == EApacVariant )
       
   269         {
       
   270         font = ApacPlain16();
       
   271         }
       
   272 
       
   273     TRect rect = iAvkonAppUi->ClientRect();
       
   274     TAknLayoutText layoutText;
       
   275     layoutText.LayoutText( rect, AKN_LAYOUT_TEXT_Wait_or_progress_note_pop_up_window_texts_Line_1(0,0,0) );
       
   276     TInt maxWidth = layoutText.TextRect().Width();
       
   277 
       
   278     AknTextUtils::ClipToFit( aName, *font, maxWidth, AknTextUtils::EClipFromEnd );
       
   279     
       
   280     RUBY_DEBUG0( "CPlayState::FormatName EXIT" );
       
   281     }     
       
   282     
       
   283 // ---------------------------------------------------------------------------
       
   284 // CPlayState::PlayVoiceTagL
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CPlayState::PlayVoiceTagL()
       
   288     {
       
   289     RUBY_DEBUG_BLOCK( "CPlayState::PlayVoiceTagL" );
       
   290     
       
   291     // if TTS is used
       
   292     if ( DataStorage().SynthesizerMode() != KErrNone ||
       
   293          DataStorage().DeviceLockMode() )
       
   294         {            
       
   295         // Add text "dialling" in front of the name if using voice dialing
       
   296         if ( DataStorage().Tag()->Context()->ContextName() == KVoiceDialContext &&
       
   297              DataStorage().Tag()->RRD()->IntArray()->At( KVasExtensionRrdLocation ) == EDial )
       
   298             {
       
   299             HBufC* ttsText = StringLoader::LoadLC( R_QAN_VC_TTS_DIALLING );
       
   300             
       
   301             TInt position = ttsText->FindC( KStringPosition );
       
   302             User::LeaveIfError( position );            
       
   303             
       
   304             CleanupStack::PopAndDestroy( ttsText );
       
   305                                                    
       
   306             ttsText = StringLoader::LoadLC( R_QAN_VC_TTS_DIALLING,
       
   307                                             DataStorage().Tag()->SpeechItem()->Text() );
       
   308                                                    
       
   309             HBufC* text = DataStorage().Tag()->SpeechItem()->PartialTextL( KNameTrainingIndex );        
       
   310             CleanupStack::PushL( text ); 
       
   311             
       
   312             DataStorage().TtsPlayer()->PlayL( *ttsText, position,
       
   313                                               DataStorage().Tag()->SpeechItem()->Text().Length(),
       
   314                                               *text );
       
   315             
       
   316             CleanupStack::PopAndDestroy( text );
       
   317             CleanupStack::PopAndDestroy( ttsText );
       
   318             }
       
   319         else if ( DataStorage().Tag()->Context()->ContextName() == KVoiceDialContext )
       
   320             {           
       
   321             HBufC* text = DataStorage().Tag()->SpeechItem()->PartialTextL( KNameTrainingIndex );        
       
   322             CleanupStack::PushL( text ); 
       
   323         
       
   324             DataStorage().TtsPlayer()->PlayL( DataStorage().Tag()->SpeechItem()->Text(), 0,
       
   325                                               DataStorage().Tag()->SpeechItem()->Text().Length(),
       
   326                                               *text );
       
   327 
       
   328             CleanupStack::PopAndDestroy( text );
       
   329             }
       
   330         else
       
   331             {            
       
   332             DataStorage().TtsPlayer()->PlayL( DataStorage().Tag()->SpeechItem()->Text() );
       
   333             }
       
   334         }
       
   335     else
       
   336         {
       
   337         // Set playback delay so that dialog will be dismissed immediately when
       
   338         // progess bar reaches final value
       
   339         iPlaybackDelay = 1;
       
   340                 
       
   341         // Show playback dialog without TTS.
       
   342         DataStorage().SetPlayDuration( KTimeoutMicroseconds );
       
   343         HandleEventL( KErrNone );
       
   344         }
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // CPlayState::FormatDataL
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void CPlayState::FormatDataL( TDes& aName, TDes& aPhoneNumber, TFieldType& aFieldType )
       
   352     {
       
   353     RUBY_DEBUG_BLOCK( "CPlayState::FormatDataL" );
       
   354     
       
   355     TPtrC phoneNumber( KNullDesC );
       
   356     aPhoneNumber = (TDes&) phoneNumber;
       
   357         
       
   358     aFieldType = KNullUid;
       
   359     
       
   360     aName.Zero();
       
   361         
       
   362     if ( DataStorage().Tag()->Context()->ContextName() == KVoiceDialContext )
       
   363         {
       
   364         HBufC* name = DataStorage().Tag()->SpeechItem()->PartialTextL( KNameTrainingIndex );
       
   365         CleanupStack::PushL( name );
       
   366         
       
   367         aName.Copy( *name );
       
   368             
       
   369         CleanupStack::PopAndDestroy( name );
       
   370         
       
   371         // Format name so that it fits on one line
       
   372         FormatName( aName );
       
   373  
       
   374         DataStorage().PbkHandler()->FindContactFieldL( DataStorage().Tag() );
       
   375 
       
   376         // Format phone number
       
   377         phoneNumber.Set( DataStorage().PbkHandler()->TextL() );
       
   378         aPhoneNumber = (TDes&) phoneNumber;
       
   379         AknTextUtils::LanguageSpecificNumberConversion( aPhoneNumber );
       
   380  
       
   381         aFieldType = DataStorage().PbkHandler()->FieldTypeL();      
       
   382         }
       
   383     else
       
   384         {
       
   385         aName.Copy( DataStorage().Tag()->SpeechItem()->Text() );
       
   386         }
       
   387     }  
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CPlayState::ShowPlaydialogL
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void CPlayState::ShowPlaydialogL( const TDesC& aName, const TDesC& aPhoneNumber,
       
   394                                   const TFieldType aFieldType )
       
   395     {
       
   396     RUBY_DEBUG_BLOCK( "CPlayState::ShowPlaydialogL" );
       
   397     
       
   398     // Get icon information
       
   399     TInt iconId;
       
   400     TInt iconMaskId;
       
   401     TAknsItemID iconSkinId;
       
   402     GetDialogIcon( aFieldType, iconId, iconMaskId, iconSkinId );
       
   403 
       
   404     iProgressDialog = CGlobalProgressDialog::NewL();
       
   405 
       
   406     // Set icon, image and skin for the playback dialog
       
   407     iProgressDialog->SetIconL( AknIconUtils::AvkonIconFileName(),
       
   408                                iconId, iconMaskId );
       
   409     
       
   410     iProgressDialog->SetImageL( AknIconUtils::AvkonIconFileName(),
       
   411                                 EMbmAvkonQgn_note_voice_found,
       
   412                                 EMbmAvkonQgn_note_voice_found_mask );
       
   413 
       
   414     iProgressDialog->SetSkinIds( KAknsIIDQgnNoteVoiceFound, EMbmAvkonQgn_note_voice_found,
       
   415                                  EMbmAvkonQgn_note_voice_found_mask, iconSkinId );
       
   416    
       
   417     iProgressDialog->RegisterForKeyCallback( DataStorage().VoiceRecognitionImpl() );
       
   418         
       
   419     // Package dialog data for coverui
       
   420     SecondaryDisplay::TMatchData matchData;
       
   421     matchData.iType = aFieldType;
       
   422     matchData.iName.Append( aName );
       
   423     matchData.iNumber.Append( aPhoneNumber );
       
   424 
       
   425     // Publish the data for the secondary display
       
   426     iProgressDialog->SetSecondaryDisplayDataL( SecondaryDisplay::KCatVoiceUi,
       
   427                                                SecondaryDisplay::ECmdShowMatchedItemNote,
       
   428                                                &matchData );
       
   429                                                
       
   430     BringToForeground();
       
   431 
       
   432     iProgressDialog->ShowProgressDialogL( aName, aPhoneNumber, R_AVKON_SOFTKEYS_OTHER_QUIT );
       
   433            
       
   434     // Play selected name using TTS
       
   435     PlayVoiceTagL();
       
   436     }    
       
   437     
       
   438 // ---------------------------------------------------------
       
   439 // CPlayState::GetDialogIcon
       
   440 // Chooses appropriate dialog icon
       
   441 // ---------------------------------------------------------
       
   442 //
       
   443 void CPlayState::GetDialogIcon( const TFieldType& aType, TInt& aIcon,
       
   444                                 TInt& aIconMask, TAknsItemID& aIconId )
       
   445    {   
       
   446    // select a phone type bitmap
       
   447    if ( aType == KUidContactFieldVCardMapVOICE )
       
   448       {
       
   449       aIcon = KBitmapId[ EIconPhone ];
       
   450       aIconMask = KMaskId[ EIconPhone ];
       
   451       aIconId = *KIconId[ EIconPhone ];
       
   452       }
       
   453    else if ( aType == KUidContactFieldVCardMapCELL )
       
   454       {
       
   455       aIcon = KBitmapId[ EIconMobile ];
       
   456       aIconMask = KMaskId[ EIconMobile ];
       
   457       aIconId = *KIconId[ EIconMobile ];
       
   458       }
       
   459    else if ( aType == KUidContactFieldVCardMapFAX )
       
   460       {
       
   461       aIcon = KBitmapId[ EIconFax ];
       
   462       aIconMask = KMaskId[ EIconFax ];
       
   463       aIconId = *KIconId[ EIconFax ];
       
   464       }
       
   465    else if ( aType == KUidContactFieldVCardMapEMAILINTERNET )
       
   466       {
       
   467       aIcon = KBitmapId[ EIconEmail ];
       
   468       aIconMask = KMaskId[ EIconEmail ];
       
   469       aIconId = *KIconId[ EIconEmail ];
       
   470       }
       
   471    else if ( aType == KUidContactFieldVCardMapVIDEO )
       
   472       {
       
   473       aIcon = KBitmapId[ EIconVideo ];
       
   474       aIconMask = KMaskId[ EIconVideo ];
       
   475       aIconId = *KIconId[ EIconVideo ];
       
   476       }
       
   477    else if ( aType == KUidContactFieldVCardMapVOIP )
       
   478       {
       
   479       aIcon = KBitmapId[ EIconVoip ];
       
   480       aIconMask = KMaskId[ EIconVoip ];
       
   481       aIconId = *KIconId[ EIconVoip ];
       
   482       }   
       
   483    else
       
   484       {
       
   485       aIcon = KBitmapId[ EIconBlank ];
       
   486       aIconMask = KMaskId[ EIconBlank ];
       
   487       aIconId = *KIconId[ EIconBlank ];
       
   488       }
       
   489    }
       
   490 
       
   491 // End of File
       
   492