|
1 /* |
|
2 * Copyright (c) 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: Implement of class CTruiPtiEngine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <bautils.h> |
|
21 |
|
22 #include "PtiTruiEngine.h" |
|
23 #include "PtiSymbolList.h" |
|
24 |
|
25 |
|
26 // ===================== Constant Definition ======================= |
|
27 _LIT( KSymbolPath, "c:\\PredicH\\TrainUISymbol.dat" ); |
|
28 _LIT( KShortCutPath, "c:\\PredicH\\TrainUiShortcut.dat" ); |
|
29 _LIT( KPresetPath, "c:\\PredicH\\TrainUiPreset.dat"); |
|
30 _LIT( KPresetRomPath, "z:\\resource\\TrainUiPreset.dat" ); |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 CTruiPtiEngine::CTruiPtiEngine() |
|
35 { |
|
36 iScript = EPtiHwrScriptAny; |
|
37 iHl = 0; |
|
38 iBl = 0; |
|
39 } |
|
40 |
|
41 void CTruiPtiEngine::ConstructL( CHwrRecognizer* aHwrEngine ) |
|
42 { |
|
43 // Load the file |
|
44 iSymboList.Reset(); |
|
45 iHwrEngine = aHwrEngine; |
|
46 User::LeaveIfError( iFsSession.Connect() ); |
|
47 } |
|
48 |
|
49 |
|
50 CTruiPtiEngine* CTruiPtiEngine::NewL( CHwrRecognizer* aHwrEngine ) |
|
51 { |
|
52 CTruiPtiEngine* self = CTruiPtiEngine::NewLC( aHwrEngine ); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 CTruiPtiEngine* CTruiPtiEngine::NewLC( CHwrRecognizer* aHwrEngine ) |
|
58 { |
|
59 CTruiPtiEngine* self = new( ELeave ) CTruiPtiEngine; |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL( aHwrEngine ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 CTruiPtiEngine::~CTruiPtiEngine() |
|
66 { |
|
67 iSymboList.DeleteAll(); |
|
68 delete iPreSetList; |
|
69 iPreSetList = NULL; |
|
70 iFsSession.Close(); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // From class MTruiEngine. |
|
75 // Set current trained character's Language Script. |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CTruiPtiEngine::SetLanguageScriptL( TInt aLanguageScript ) |
|
79 { |
|
80 iScript = aLanguageScript; |
|
81 |
|
82 LoadUdmL( EUdmSymbol ); |
|
83 LoadUdmL( EUdmShortcut ); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // From class MTruiEngine. |
|
88 // Check if character has model. |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 TBool CTruiPtiEngine::CharacterModelExist( const TDesC& aChar ) |
|
92 { |
|
93 TRAPD( err, LoadUdmL( EUdmSymbol ) ); |
|
94 if ( err != KErrNone ) |
|
95 { |
|
96 return err; |
|
97 } |
|
98 |
|
99 THwrUdmRange range = { iScript, EPtiHwrRangeAny }; |
|
100 return iSymboList[EUdmSymbol]->CheckSymbolModel( aChar, range ); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // From class MTruiEngine. |
|
105 // Get character model. |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CTruiPtiEngine::GetCharacterModelL( const TDesC& aChar, RArray<TPoint>& aModel ) |
|
109 { |
|
110 LoadUdmL( EUdmSymbol ); |
|
111 THwrUdmRange range = { iScript, EPtiHwrRangeAny }; |
|
112 TUint presetCode = 0; |
|
113 iSymboList[EUdmSymbol]->GetSymbolModelL( aChar, aModel, presetCode,range ); |
|
114 } |
|
115 |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // From class MTruiEngine. |
|
119 // Set character model. |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CTruiPtiEngine::SetCharacterModelL( const TDesC& aChar, RArray<TPoint>& aModel, TInt aSubRange, TDes& aSimilarChar ) |
|
123 { |
|
124 THwrUdmRange script = { iScript, aSubRange }; |
|
125 User::LeaveIfError( iHwrEngine->SymbolModelValid( aChar, aModel, script, aSimilarChar ) ); |
|
126 |
|
127 LoadUdmL( EUdmSymbol ); |
|
128 THwrUdmRange range = { iScript, aSubRange }; |
|
129 iSymboList[EUdmSymbol]->SetSymbolModelL( aChar, aModel, iHl,iBl,range ); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // From class MTruiEngine. |
|
134 // Delete character model. |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CTruiPtiEngine::DeleteCharacterModel( const TDesC& aChar ) |
|
138 { |
|
139 TRAPD( errUdm, LoadUdmL( EUdmSymbol ) ); |
|
140 if ( errUdm != KErrNone ) |
|
141 { |
|
142 return errUdm; |
|
143 } |
|
144 |
|
145 THwrUdmRange range = { iScript, EPtiHwrRangeAny }; |
|
146 TRAPD( err,iSymboList[EUdmSymbol]->DeleteSymbolModelL( aChar, range ) ); |
|
147 return err; |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // From class MTruiEngine. |
|
152 // Get text list of all the shortcuts. |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void CTruiPtiEngine::GetShortcutTextListL( RPointerArray<HBufC>& aShortcutTextList ) |
|
156 { |
|
157 LoadUdmL( EUdmShortcut ); |
|
158 THwrUdmRange range = { EPtiHwrScriptAny, EPtiHwrRangeAny }; |
|
159 iSymboList[EUdmShortcut]->GetModelTextListL( aShortcutTextList, range ); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // From class MTruiEngine. |
|
164 // Check if shortcut has model. |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 TBool CTruiPtiEngine::CheckShortcutModel( const TDesC& aText ) |
|
168 { |
|
169 TRAPD( err, LoadUdmL( EUdmShortcut ) ); |
|
170 if ( err != KErrNone ) |
|
171 return EFalse; |
|
172 |
|
173 THwrUdmRange range = { EPtiHwrScriptAny, EPtiHwrRangeAny }; |
|
174 return iSymboList[EUdmShortcut]->CheckSymbolModel( aText, range ); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // From class MTruiEngine. |
|
179 // Get Shortcut model. |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 void CTruiPtiEngine::GetShortcutModelL( const TDesC& aText, RArray<TPoint>& aModel,TUint& aUnicode ) |
|
183 { |
|
184 LoadUdmL( EUdmShortcut ); |
|
185 THwrUdmRange range = { EPtiHwrScriptAny, EPtiHwrRangeAny }; |
|
186 iSymboList[EUdmShortcut]->GetSymbolModelL( aText, aModel, aUnicode, range ); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // From class MTruiEngine. |
|
191 // Set Shortcut model. |
|
192 // --------------------------------------------------------------------------- |
|
193 void CTruiPtiEngine::SetShortcutModelL( const TDesC& aText, RArray<TPoint>& aModel, TDes& aSimilarText ) |
|
194 { |
|
195 THwrUdmRange script = { iScript, EPtiHwrRangeAny }; |
|
196 User::LeaveIfError( iHwrEngine->SymbolModelValid( aText, aModel, script, aSimilarText ) ); |
|
197 |
|
198 LoadUdmL( EUdmShortcut ); |
|
199 THwrUdmRange range = { EPtiHwrScriptAny, EPtiHwrRangeAny }; |
|
200 return iSymboList[EUdmShortcut]->SetSymbolModelL( aText, aModel, iHl, iBl, range ); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // From class MTruiEngine. |
|
205 // Delete Shortcut model. |
|
206 // --------------------------------------------------------------------------- |
|
207 TInt CTruiPtiEngine::DeleteShortcutModel( const TDesC& aText ) |
|
208 { |
|
209 TRAPD( errUdm, LoadUdmL( EUdmShortcut ) ); |
|
210 if ( errUdm != KErrNone ) |
|
211 { |
|
212 return errUdm; |
|
213 } |
|
214 |
|
215 THwrUdmRange range = { EPtiHwrScriptAny, EPtiHwrRangeAny }; |
|
216 TRAPD( err,iSymboList[EUdmShortcut]->DeleteSymbolModelL( aText, range ) ); |
|
217 return err; |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // From class MTruiEngine. |
|
222 // hange the text of an existing shortcut. |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void CTruiPtiEngine::ChangeShortcutTextL( const TDesC& aOldText, |
|
226 const TDesC& aNewText ) |
|
227 { |
|
228 LoadUdmL( EUdmShortcut ); |
|
229 |
|
230 THwrUdmRange range = { EPtiHwrScriptAny, EPtiHwrRangeAny }; |
|
231 TRAP_IGNORE( iSymboList[EUdmShortcut]->ChangeSymbolTextL( aOldText, aNewText, range ) ); |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // Get guiding line pos |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 TInt CTruiPtiEngine::GetGuidingLinePos( const TSize& aSize, TInt& aTop , TInt& aBottom) |
|
239 { |
|
240 iHl = aTop = aSize.iHeight * 65 / 135; |
|
241 iBl = aBottom = aSize.iHeight * 88 / 135; |
|
242 return KErrNone; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // Get the number of the maximum of shortcuts |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 TInt CTruiPtiEngine::MaxShortCutLength() |
|
250 { |
|
251 return 10; |
|
252 } |
|
253 |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 void CTruiPtiEngine::SavePresetShortcutL( TUint aUnicode, const TDesC& aShortcut ) |
|
259 { |
|
260 LoadUdmL( EUdmShortcut ); |
|
261 iSymboList[EUdmShortcut]->SavePresetShortcutL( aUnicode, aShortcut ) ; |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void CTruiPtiEngine::GetAllPresetSymbolsL( RArray<TUint>& aPresets ) |
|
268 { |
|
269 LoadUdmL( EUdmShortcut ); |
|
270 iSymboList[EUdmShortcut]->GetAllPresetSymbolsL( aPresets ) ; |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 void CTruiPtiEngine::GetPresetSymbolByUnicodeL( TUint aUnicode, RArray<TPoint>& aModel, TDes& aShortcut ) |
|
277 { |
|
278 LoadUdmL( EUdmShortcut ); |
|
279 iSymboList[EUdmShortcut]->GetPresetSymbolByUnicodeL( aUnicode, aModel, aShortcut ) ; |
|
280 } |
|
281 |
|
282 void CTruiPtiEngine::LoadUdmL( TUdmType aType ) |
|
283 { |
|
284 if ( iSymboList[aType] ) |
|
285 { |
|
286 return; |
|
287 } |
|
288 |
|
289 iSymboList[EUdmSymbol] = CSymbolList::NewL( KSymbolPath(), NULL ); |
|
290 iSymboList[EUdmSymbol]->ExternalizeL(); |
|
291 |
|
292 // well , EUdmPreset belong to shourtcut |
|
293 if ( !iPreSetList ) |
|
294 { |
|
295 // copy the data from rom if not exist on KPresetPath |
|
296 TInt retCode = BaflUtils::CopyFile( iFsSession, KPresetRomPath(), KPresetPath(), 0 ); |
|
297 TUint attPresetDataFile = 0; |
|
298 iFsSession.Att( KPresetPath, attPresetDataFile ); |
|
299 if ( attPresetDataFile & KEntryAttReadOnly ) |
|
300 { |
|
301 attPresetDataFile &= ~KEntryAttReadOnly; |
|
302 iFsSession.SetAtt( KPresetPath(), attPresetDataFile, KEntryAttReadOnly ); |
|
303 } |
|
304 if ( KErrNone == retCode || KErrAlreadyExists == retCode ) |
|
305 { |
|
306 iPreSetList = CSymbolList::NewL( KPresetPath(), NULL ); |
|
307 } |
|
308 } |
|
309 iSymboList[EUdmShortcut] = CSymbolList::NewL( KShortCutPath(), iPreSetList ); |
|
310 } |
|
311 |
|
312 void CTruiPtiEngine::UnLoadUdm( TUdmType aType ) |
|
313 { |
|
314 if ( iSymboList[aType] ) |
|
315 { |
|
316 delete iSymboList[aType]; |
|
317 iSymboList[aType] = NULL; |
|
318 } |
|
319 } |
|
320 |
|
321 void CTruiPtiEngine::GetModelIndexListL( TUdmType aType, RArray<TInt>& aList, const THwrUdmRange& aRange) |
|
322 { |
|
323 CSymbolList* temp = iSymboList[aType]; |
|
324 TBool tempB = !iSymboList[aType]; |
|
325 LoadUdmL( aType ); |
|
326 |
|
327 THwrUdmRange range = aRange; |
|
328 ConvertUdmRange( range ); |
|
329 iSymboList[aType]->GetModelIndexListL( aList, range ); |
|
330 } |
|
331 |
|
332 |
|
333 |
|
334 void CTruiPtiEngine::GetSymbolModelL( TUdmType aType,TInt aIndex, TPtrC& aSymbolName,RArray<TPoint>& aModel, TInt& aHelpLine, TInt& aBaseLine ) |
|
335 { |
|
336 LoadUdmL( aType ); |
|
337 |
|
338 iSymboList[aType]->GetSymbolDataRef( aIndex, aSymbolName, aModel, aHelpLine, aBaseLine); |
|
339 } |
|
340 |
|
341 void CTruiPtiEngine::ConvertUdmRange( THwrUdmRange& aRange ) |
|
342 { |
|
343 switch ( aRange.iScript ) |
|
344 { |
|
345 case ELangEnglish: |
|
346 case ELangAustralian: |
|
347 case ELangNewZealand: |
|
348 case ELangInternationalEnglish: |
|
349 case ELangSouthAfricanEnglish: |
|
350 case ELangCanadianEnglish: |
|
351 case ELangAmerican: |
|
352 case ELangSwissFrench: |
|
353 case ELangBelgianFrench: |
|
354 case ELangInternationalFrench: |
|
355 case ELangFrench: |
|
356 case ELangCanadianFrench: |
|
357 case ELangGerman: |
|
358 case ELangSwissGerman: |
|
359 case ELangSpanish: |
|
360 case ELangLatinAmericanSpanish: |
|
361 case ELangSwissItalian: |
|
362 case ELangItalian: |
|
363 case ELangFinlandSwedish: |
|
364 case ELangSwedish: |
|
365 case ELangFinnish: |
|
366 // case ELangAlbanian: |
|
367 case ELangDanish: |
|
368 case ELangDutch: |
|
369 case ELangIcelandic: |
|
370 case ELangNorwegian: |
|
371 case ELangPortuguese: |
|
372 case ELangIndonesian: |
|
373 case ELangMalay: |
|
374 case ELangTagalog: |
|
375 case ELangCroatian: |
|
376 case ELangCzech: |
|
377 case ELangHungarian: |
|
378 case ELangPolish: |
|
379 case ELangRomanian: |
|
380 case ELangSlovak: |
|
381 case ELangSlovenian: |
|
382 // case ELangSerbian: |
|
383 case ELangEstonian: |
|
384 case ELangLatvian: |
|
385 case ELangLithuanian: |
|
386 case ELangTurkish: |
|
387 aRange.iScript = EPtiHwrScriptLatin; |
|
388 break; |
|
389 case ELangGreek: |
|
390 case ELangCyprusGreek: |
|
391 aRange.iScript = EPtiHwrScriptGreek; |
|
392 break; |
|
393 case ELangBelarussian: |
|
394 case ELangRussian: |
|
395 case ELangUkrainian: |
|
396 case ELangBulgarian: |
|
397 aRange.iScript = EPtiHwrScriptCyrillic; |
|
398 break; |
|
399 case ELangHebrew: |
|
400 aRange.iScript = EPtiHwrScriptHebrew; |
|
401 break; |
|
402 case ELangArabic: |
|
403 aRange.iScript = EPtiHwrScriptArabic; |
|
404 break; |
|
405 default: |
|
406 break; |
|
407 } |
|
408 } |
|
409 |
|
410 // end of line |