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 <avkon.hrh> |
|
21 |
|
22 #include <vasmbasepbkhandler.h> |
|
23 |
|
24 #include "vuicstate.h" |
|
25 #include "vuicinitstate.h" |
|
26 #include "vuicrecordstate.h" |
|
27 #include "vuicabortstate.h" |
|
28 #include "vuicerrorstate.h" |
|
29 |
|
30 #include "vuicdatastorage.h" |
|
31 |
|
32 #include "vuicvoicerecogdialogimpl.h" |
|
33 #include "vuictoneplayer.h" |
|
34 #include "vuicpropertyhandler.h" |
|
35 |
|
36 #include "rubydebug.h" |
|
37 |
|
38 // CONSTANTS |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CInitState::NewL |
|
43 // Two-phased constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CInitState* CInitState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel ) |
|
47 { |
|
48 CInitState* self = new (ELeave) CInitState( aDataStorage, aUiModel ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // Destructor |
|
56 CInitState::~CInitState() |
|
57 { |
|
58 RUBY_DEBUG0( "CInitState::~CInitState START" ); |
|
59 |
|
60 if ( iInternalState != EReady ) |
|
61 { |
|
62 DataStorage().RecognitionHandler()->Cancel(); |
|
63 } |
|
64 |
|
65 RUBY_DEBUG0( "CInitState::~CInitState EXIT" ); |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CInitState::HandleEventL |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 void CInitState::HandleEventL( TInt aEvent ) |
|
73 { |
|
74 RUBY_DEBUG_BLOCK( "CInitState::HandleEventL" ); |
|
75 |
|
76 CState* nextState = NULL; |
|
77 |
|
78 switch( aEvent ) |
|
79 { |
|
80 case KErrNone: |
|
81 |
|
82 if ( iInternalState == EStarted ) |
|
83 { |
|
84 #ifndef __WINS__ |
|
85 #ifdef __FULLDUPLEX_CHANGE |
|
86 iInternalState = ESamplingStarted; |
|
87 nextState = this; |
|
88 } |
|
89 else if ( iInternalState == ESamplingStarted ) |
|
90 { |
|
91 #endif // __FULLDUPLEX_CHANGE |
|
92 #endif // __WINS__ |
|
93 iInternalState = EInitialized; |
|
94 } |
|
95 else if ( iInternalState == EInitialized ) |
|
96 { |
|
97 iInternalState = EReady; |
|
98 nextState = this; |
|
99 } |
|
100 else |
|
101 { |
|
102 nextState = CRecordState::NewL( DataStorage(), UiModel() ); |
|
103 } |
|
104 break; |
|
105 |
|
106 case KErrInit: |
|
107 case KErrNoContacts: |
|
108 |
|
109 nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent ); |
|
110 break; |
|
111 |
|
112 case KErrNoMemory: |
|
113 nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent ); |
|
114 break; |
|
115 |
|
116 case ELongKeypress: |
|
117 case EEndCallKeypress: |
|
118 |
|
119 // Do nothing |
|
120 break; |
|
121 |
|
122 default: |
|
123 |
|
124 nextState = CAbortState::NewL( DataStorage(), UiModel() ); |
|
125 break; |
|
126 } |
|
127 |
|
128 DataStorage().VoiceRecognitionImpl()->ChangeState( nextState ); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // CInitState::ExecuteL |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 void CInitState::ExecuteL() |
|
136 { |
|
137 RUBY_DEBUG_BLOCK( "CInitState::ExecuteL" ); |
|
138 |
|
139 if ( iInternalState == ENotStarted ) |
|
140 { |
|
141 // Initialize recognition system |
|
142 InitializeL(); |
|
143 iInternalState = EStarted; |
|
144 |
|
145 #ifndef __WINS__ |
|
146 #ifdef __FULLDUPLEX_CHANGE |
|
147 // Initialize sampling |
|
148 StartSamplingL(); |
|
149 } |
|
150 else if ( iInternalState == ESamplingStarted ) |
|
151 { |
|
152 #endif // __FULLDUPLEX_CHANGE |
|
153 #endif // __WINS__ |
|
154 // Initialize phonebook handler |
|
155 TRAPD( error, DataStorage().PbkHandler()->InitializeL() ); |
|
156 if ( error == KErrNoMemory ) |
|
157 { |
|
158 HandleEventL ( KErrNoMemory ); |
|
159 } |
|
160 else |
|
161 { |
|
162 if ( error != KErrAlreadyExists ) |
|
163 { |
|
164 User::LeaveIfError( error ); |
|
165 } |
|
166 |
|
167 // Initialize start tone |
|
168 DataStorage().TonePlayer()->InitToneL( EAvkonSIDNameDiallerStartTone ); |
|
169 |
|
170 // Initialize recognition |
|
171 RecognizeInitL(); |
|
172 } |
|
173 } |
|
174 else |
|
175 { |
|
176 // Play the starting tone |
|
177 DataStorage().TonePlayer()->PlayTone( EAvkonSIDNameDiallerStartTone ); |
|
178 } |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------- |
|
182 // CInitState::CInitState |
|
183 // --------------------------------------------------------- |
|
184 // |
|
185 CInitState::CInitState( CDataStorage& aDataStorage, CUiModel& aUiModel ) |
|
186 : CState( aDataStorage, aUiModel ), iInternalState( ENotStarted ) |
|
187 { |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------- |
|
191 // CInitState::InitializeL |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 void CInitState::InitializeL() |
|
195 { |
|
196 RUBY_DEBUG_BLOCK( "CInitState::InitializeL" ); |
|
197 |
|
198 DataStorage().AccessoryButtonMonitor()->Register( DataStorage().VoiceRecognitionImpl() ); |
|
199 |
|
200 CNssRecognitionHandlerBuilder* builder = CNssRecognitionHandlerBuilder::NewL(); |
|
201 DataStorage().SetRecognitionHandlerBuilder( builder ); |
|
202 builder->InitializeL(); |
|
203 |
|
204 DataStorage().SetRecognitionHandler( builder->GetRecognitionHandler() ); |
|
205 } |
|
206 |
|
207 #ifndef __WINS__ |
|
208 #ifdef __FULLDUPLEX_CHANGE |
|
209 // --------------------------------------------------------- |
|
210 // CInitState::StartSamplingL |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 void CInitState::StartSamplingL() |
|
214 { |
|
215 RUBY_DEBUG_BLOCK( "CInitState::StartSamplingL" ); |
|
216 |
|
217 MNssRecognitionHandler* handler = DataStorage().RecognitionHandler(); |
|
218 User::LeaveIfError( |
|
219 handler->PreStartSampling( DataStorage().VoiceRecognitionImpl() ) ); |
|
220 } |
|
221 #endif // __FULLDUPLEX_CHANGE |
|
222 #endif // __WINS__ |
|
223 |
|
224 // --------------------------------------------------------- |
|
225 // CInitState::RecognizeInitL |
|
226 // --------------------------------------------------------- |
|
227 // |
|
228 void CInitState::RecognizeInitL() |
|
229 { |
|
230 RUBY_DEBUG_BLOCK( "CInitState::RecognizeInitL" ); |
|
231 |
|
232 TInt numResults = KSindMaxResults * 3; |
|
233 |
|
234 if ( DataStorage().VerificationMode() == EVoice ) |
|
235 { |
|
236 numResults = KVerificationResults; |
|
237 } |
|
238 |
|
239 MNssRecognitionHandler* handler = DataStorage().RecognitionHandler(); |
|
240 User::LeaveIfError( |
|
241 handler->RecognizeInitL( DataStorage().VoiceRecognitionImpl(), numResults ) ); |
|
242 } |
|
243 |
|
244 // End of File |
|
245 |
|