voiceui/voiceuivoicerecognition/src/vuiccontextcheckstate.cpp
branchRCL_3
changeset 23 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
22:cad71a31b7fc 23:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2006 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 <centralrepository.h>
       
    21 
       
    22 #include <srsfdomaincrkeys.h>
       
    23 
       
    24 #include "vuicstate.h"
       
    25 #include "vuiccontextcheckstate.h"
       
    26 #include "vuicverificationtrainingstate.h"
       
    27 #include "vuictutorialstate.h"
       
    28 #include "vuicexitstate.h"
       
    29 #include "vuicerrorstate.h"
       
    30 
       
    31 #include "vuicdatastorage.h"
       
    32 
       
    33 #include "vuicvoicerecogdialogimpl.h"
       
    34 
       
    35 #include "rubydebug.h"
       
    36 
       
    37 static const TInt KUndefinedLanguage = -1;
       
    38     
       
    39 // -----------------------------------------------------------------------------
       
    40 // CContextCheckState::NewL
       
    41 // Two-phased constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CContextCheckState* CContextCheckState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
    45     {
       
    46     CContextCheckState* self = new (ELeave) CContextCheckState( aDataStorage, aUiModel );
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }       
       
    52     
       
    53 // Destructor       
       
    54 CContextCheckState::~CContextCheckState()
       
    55     {
       
    56     RUBY_DEBUG0( "CContextCheckState::~CContextCheckState START" );
       
    57     
       
    58     delete iVasDbManager;
       
    59     iContextManager = NULL;
       
    60     iTagManager = NULL;
       
    61     
       
    62     RUBY_DEBUG0( "CContextCheckState::~CContextCheckState EXIT" );
       
    63     }
       
    64     
       
    65 // ---------------------------------------------------------
       
    66 // CContextCheckState::HandleEventL
       
    67 // ---------------------------------------------------------
       
    68 //       
       
    69 void CContextCheckState::HandleEventL( TInt aEvent )
       
    70     {
       
    71     RUBY_DEBUG_BLOCK( "CContextCheckState::HandleEventL" );
       
    72 
       
    73     CState* nextState = NULL;
       
    74     
       
    75     switch( aEvent )
       
    76         {
       
    77         case KErrNone:
       
    78         
       
    79             if ( iInternalState == EStarted )
       
    80                 {
       
    81                 iInternalState = ECommandsReady;
       
    82                 nextState = this;
       
    83                 }
       
    84             else if ( iInternalState == ECommandsReady )
       
    85                 {
       
    86                 iInternalState = EDialReady;
       
    87                 nextState = this;
       
    88                 }
       
    89             else if ( iInternalState == EDialReady )
       
    90                 {
       
    91                 iInternalState = EVerificationReady;
       
    92                 nextState = this;
       
    93                 }
       
    94             else
       
    95                 {
       
    96                 nextState = CTutorialState::NewL( DataStorage(), UiModel() );
       
    97                 }
       
    98             break;
       
    99             
       
   100         case KErrNoVerificationTrained:
       
   101         
       
   102             nextState = CVerificationTrainingState::NewL( DataStorage(), UiModel() );
       
   103             break;
       
   104             
       
   105         case KErrNotReady:
       
   106         
       
   107             nextState = CExitState::NewL( DataStorage(), UiModel() );
       
   108             break;
       
   109             
       
   110         default:
       
   111             
       
   112             nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent );
       
   113             break;
       
   114         }
       
   115 
       
   116     DataStorage().VoiceRecognitionImpl()->ChangeState( nextState );
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CContextCheckState::ExecuteL
       
   121 // ---------------------------------------------------------
       
   122 //       
       
   123 void CContextCheckState::ExecuteL()
       
   124     {
       
   125     RUBY_DEBUG_BLOCK( "CContextCheckState::ExecuteL" );
       
   126 
       
   127     if ( iInternalState == ENotStarted )
       
   128         {
       
   129         iInternalState = EStarted;
       
   130         
       
   131         // Get voice command context
       
   132         if ( iContextManager->GetContext( DataStorage().VoiceRecognitionImpl(),
       
   133                                           KVoiceCommandContext ) != KErrNone )
       
   134             {
       
   135             HandleEventL( KErrNotReady );
       
   136             }
       
   137         }
       
   138     else if ( iInternalState == ECommandsReady )
       
   139         {
       
   140         // Get voice command context tag count
       
   141         iTagCount += iTagManager->TagCount( DataStorage().Context() );
       
   142         
       
   143         // Get voice dial context
       
   144         if ( iContextManager->GetContext( DataStorage().VoiceRecognitionImpl(),
       
   145                                           KVoiceDialContext ) != KErrNone )
       
   146             {
       
   147             HandleEventL( KErrNotReady );
       
   148             }
       
   149         }
       
   150     else if ( iInternalState == EDialReady )
       
   151         {
       
   152         // Get voice dial context tag count
       
   153         iTagCount += iTagManager->TagCount( DataStorage().Context() );
       
   154         
       
   155         // Check if any tags were found
       
   156         if ( !iTagCount )
       
   157             {
       
   158             HandleEventL( KErrNoContacts );
       
   159             }
       
   160             
       
   161         // Get voice verification context
       
   162         if ( iContextManager->GetContext( DataStorage().VoiceRecognitionImpl(),
       
   163                                           KVoiceVerificationContext ) != KErrNone )
       
   164             {
       
   165             HandleEventL( KErrNoVerificationTrained );
       
   166             }
       
   167         }
       
   168     else if ( iInternalState == EVerificationReady )
       
   169         {
       
   170         // Get voice verification context tag count
       
   171         iTagCount = iTagManager->TagCount( DataStorage().Context() );
       
   172         
       
   173         // Check if any tags were found or has UI language changed
       
   174         if ( !iTagCount || LanguageChangedL() )
       
   175             {
       
   176             HandleEventL( KErrNoVerificationTrained );
       
   177             }
       
   178         else
       
   179             {
       
   180             HandleEventL( KErrNone );
       
   181             }
       
   182         }
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // CContextCheckState::CContextCheckState
       
   187 // ---------------------------------------------------------
       
   188 //              
       
   189 CContextCheckState::CContextCheckState( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
   190  : CState( aDataStorage, aUiModel ), iInternalState( ENotStarted ),
       
   191    iTagCount( 0 )
       
   192     {
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------
       
   196 // CContextCheckState::ConstructL
       
   197 // ---------------------------------------------------------
       
   198 //           
       
   199 void CContextCheckState::ConstructL()
       
   200     {
       
   201     RUBY_DEBUG_BLOCK( "CContextCheckState::ConstructL" );
       
   202     
       
   203     CState::ConstructL();
       
   204     
       
   205     iVasDbManager = CNssVASDBMgr::NewL();
       
   206     iVasDbManager->InitializeL();
       
   207     iTagManager = iVasDbManager->GetTagMgr();
       
   208     iContextManager = iVasDbManager->GetContextMgr();   
       
   209     }
       
   210     
       
   211 // ---------------------------------------------------------
       
   212 // CContextCheckState::LanguageChangedL
       
   213 // ---------------------------------------------------------
       
   214 //           
       
   215 TBool CContextCheckState::LanguageChangedL()
       
   216     {
       
   217     RUBY_DEBUG_BLOCK( "CContextCheckState::LanguageChangedL" );
       
   218     
       
   219     TBool changed = EFalse;
       
   220     TInt language = KUndefinedLanguage;
       
   221     
       
   222     CRepository* client = CRepository::NewLC( KCRUidSRSFSettings );
       
   223     client->Get( KSRSFVoiceUiLanguage, language );
       
   224     
       
   225     if ( language != User::Language() )
       
   226         {
       
   227         client->Set( KSRSFVoiceUiLanguage, KUndefinedLanguage );
       
   228         changed = ETrue;
       
   229         }
       
   230         
       
   231     CleanupStack::PopAndDestroy( client );
       
   232     
       
   233     return changed;
       
   234     }
       
   235     
       
   236 // End of File
       
   237