voiceui/voiceuivoicerecognition/src/vuicrecordstate.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19: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 <featmgr.h>
       
    21 
       
    22 #include <avkon.rsg>
       
    23 #include <AknIconUtils.h>
       
    24 #include <StringLoader.h>
       
    25 
       
    26 #include <vuivoicerecognition.rsg>
       
    27 
       
    28 #include "vuicstate.h"
       
    29 #include "vuicrecordstate.h"
       
    30 #include "vuictutorialstate.h"
       
    31 #include "vuicabortstate.h"
       
    32 #include "vuicerrorstate.h"
       
    33 
       
    34 #include "vuicdatastorage.h"
       
    35 #include "vuicuimodel.h"
       
    36 
       
    37 #include "vuicvoicerecogdialogimpl.h"
       
    38 #include "vuicglobalprogressdialog.h"
       
    39 
       
    40 #include "vuivoiceicondefs.h"
       
    41 
       
    42 #include "rubydebug.h"
       
    43     
       
    44 // -----------------------------------------------------------------------------
       
    45 // CRecordState::NewL
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CRecordState* CRecordState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
    50     {
       
    51     CRecordState* self = new (ELeave) CRecordState( aDataStorage, aUiModel );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }       
       
    57     
       
    58 // Destructor       
       
    59 CRecordState::~CRecordState()
       
    60     {
       
    61     RUBY_DEBUG0( "CRecordState::~CRecordState START" );
       
    62     
       
    63     // If recording has not ended we should cancel recording
       
    64     if ( iInternalState != EFinished )
       
    65         {
       
    66         DataStorage().RecognitionHandler()->Cancel();
       
    67         }        
       
    68 
       
    69     delete iProgressDialog;
       
    70     
       
    71     RUBY_DEBUG0( "CRecordState::~CRecordState EXIT" );
       
    72     }
       
    73     
       
    74 // ---------------------------------------------------------
       
    75 // CRecordState::HandleEventL
       
    76 // ---------------------------------------------------------
       
    77 //       
       
    78 void CRecordState::HandleEventL( TInt aEvent )
       
    79     {
       
    80     RUBY_DEBUG_BLOCK( "CRecordState::HandleEventL" );
       
    81 
       
    82     CState* nextState = NULL;
       
    83 
       
    84     switch( aEvent )
       
    85         {
       
    86         case KErrNone:
       
    87         
       
    88             if ( iInternalState == EStarted )
       
    89                 {
       
    90                 iInternalState = ERecording;
       
    91                 nextState = this;
       
    92                 }
       
    93             else if ( iInternalState == ERecording )
       
    94                 {
       
    95                 iInternalState = EStopped;
       
    96                 }
       
    97             else if ( iInternalState == EStopped )
       
    98                 {
       
    99                 iInternalState = EFinished;
       
   100                 nextState = CTutorialState::NewL( DataStorage(), UiModel() );
       
   101                 }
       
   102             break;
       
   103             
       
   104         case KErrNoMatch:
       
   105         case KErrRecogFailed:
       
   106         case KErrNoSpeech:
       
   107         case KErrTooEarly:
       
   108         case KErrTooLong:
       
   109         case KErrTooShort:
       
   110         case KErrGeneral:
       
   111         
       
   112             nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent );
       
   113             break;
       
   114             
       
   115         case EEndCallKeypress:
       
   116         
       
   117             // Do nothing
       
   118             break;
       
   119             
       
   120         default:
       
   121         
       
   122             nextState = CAbortState::NewL( DataStorage(), UiModel() );
       
   123             break;
       
   124         }
       
   125 
       
   126     DataStorage().VoiceRecognitionImpl()->ChangeState( nextState );
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------
       
   130 // CRecordState::ExecuteL
       
   131 // ---------------------------------------------------------
       
   132 //       
       
   133 void CRecordState::ExecuteL()
       
   134     {
       
   135     RUBY_DEBUG_BLOCK( "CRecordState::ExecuteL" );
       
   136     
       
   137     if ( iInternalState == ENotStarted )
       
   138         {
       
   139         // Show the "Speak now" prompt and start the voice recording
       
   140         MNssRecognitionHandler* handler = DataStorage().RecognitionHandler();
       
   141         User::LeaveIfError( handler->Recognize( DataStorage().VoiceRecognitionImpl() ) );
       
   142     
       
   143         iProgressDialog = CGlobalProgressDialog::NewL();
       
   144    
       
   145         iProgressDialog->SetImageL( AknIconUtils::AvkonIconFileName(),
       
   146                                     EMbmAvkonQgn_note_voice,
       
   147                                     EMbmAvkonQgn_note_voice_mask );
       
   148                                     
       
   149         iProgressDialog->SetSkinIds( KAknsIIDQgnNoteVoice, EMbmAvkonQgn_note_voice,
       
   150                                      EMbmAvkonQgn_note_voice_mask, KAknsIIDQgnStatBtBlank );
       
   151 
       
   152         iProgressDialog->RegisterForKeyCallback( DataStorage().VoiceRecognitionImpl() );     
       
   153         
       
   154         iProgressDialog->SetSecondaryDisplayDataL( SecondaryDisplay::KCatVoiceUi,
       
   155                                                    SecondaryDisplay::ECmdShowVoiceSpeakNowNote,
       
   156                                                    NULL );
       
   157                                                    
       
   158         BringToForeground();
       
   159 
       
   160         HBufC* speakMsg = StringLoader::LoadLC( R_TEXT_VOICE_SPEAK_NOW );
       
   161         iProgressDialog->ShowProgressDialogL( *speakMsg, KNullDesC, R_AVKON_SOFTKEYS_QUIT );
       
   162         CleanupStack::PopAndDestroy( speakMsg );
       
   163         
       
   164         iInternalState = EStarted;
       
   165         }
       
   166     else if ( iInternalState == ERecording )
       
   167         {
       
   168         StartTimerL( *this, KRecogDelay, KKRecogInterval * iTModel.iHundreths );
       
   169         }
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------
       
   173 // CRecordState::CRecordState
       
   174 // ---------------------------------------------------------
       
   175 //              
       
   176 CRecordState::CRecordState( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
   177  : CState( aDataStorage, aUiModel ), iInternalState( ENotStarted ),
       
   178    iTickCount( 0 )
       
   179     {    
       
   180     iTModel.iFinalValue = KRecogFinal;
       
   181     iTModel.iHundreths = KRecogInterval;
       
   182     iTModel.iIncrement = KRecogIncrement;
       
   183     iTModel.iRunning = EFalse;
       
   184     }
       
   185     
       
   186 // ---------------------------------------------------------
       
   187 // CRecordState::DoTimedEventL
       
   188 // ---------------------------------------------------------
       
   189 //
       
   190 void CRecordState::DoTimedEventL()
       
   191    {
       
   192    if ( ( ++iTickCount != iTModel.iFinalValue + 1 ) && iProgressDialog )
       
   193       {
       
   194       iProgressDialog->UpdateProgressDialogL( iTickCount, iTModel.iFinalValue ); 
       
   195       }
       
   196    else
       
   197       {
       
   198       StopTimer();
       
   199       }
       
   200    }
       
   201     
       
   202 // End of File
       
   203