|
1 /* |
|
2 * Copyright (c) 2008 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: DB Engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 //system include files |
|
30 #include <aknfep.rsg> |
|
31 #include <PtiUserDicEntry.h> |
|
32 #include <PtiEngine.h> |
|
33 #include <StringLoader.h> |
|
34 |
|
35 //user inlucde files |
|
36 #include "dbmanagement.h" |
|
37 #include "AknFepGlobalEnums.h" |
|
38 #include "AknFepManager.h" |
|
39 #include "AknFepSharedDataInterface.h" |
|
40 |
|
41 // CONSTANTS |
|
42 const TInt KInputPhraseMaxLength = 7; |
|
43 const TInt KInvalidPhrase = -103; |
|
44 const TInt KPhraseExisted = -104; |
|
45 const TInt KPhraseNotExisted = -105; |
|
46 const TInt KInputPhraseOutRange = -106; |
|
47 const TInt KDBHasNoSpace = -150; |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // Symbian constructor |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 CDBManagement* CDBManagement::NewL( CAknFepManager* aFepManager ) |
|
54 { |
|
55 CDBManagement* self = new( ELeave ) CDBManagement(); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(aFepManager); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // C++ constructor |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 CDBManagement::CDBManagement() |
|
67 { |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------- |
|
71 // Second phase constructor |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 void CDBManagement::ConstructL( CAknFepManager* aFepManager ) |
|
75 { |
|
76 iAknFepSharedDataInterface = CAknFepSharedDataInterface::NewL( aFepManager ); |
|
77 iFepManager = aFepManager; |
|
78 iPtiEngineOfFep = iFepManager->PtiEngine(); |
|
79 iPtiEngine = CPtiEngine::NewL(ETrue); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------- |
|
83 // destructor |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 CDBManagement::~CDBManagement() |
|
87 { |
|
88 delete iAknFepSharedDataInterface; |
|
89 delete iPtiEngine; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------- |
|
93 // Add phrase to DB. |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 TBool CDBManagement::AddPhraseToDB( const TDesC& aPhraseAdd ) |
|
97 { |
|
98 TInt retCode; |
|
99 TPtiUserDictionaryEntry addUdbEntry(aPhraseAdd); |
|
100 TRAP_IGNORE( ActivateLanguageOfFepL() ); |
|
101 //Add the phrase to the DB by PTI Engine |
|
102 iPtiEngineOfFep->AddUserDictionaryEntry( addUdbEntry ); |
|
103 retCode = iPtiEngine->AddUserDictionaryEntry( addUdbEntry ); |
|
104 if ( KErrNone != retCode ) |
|
105 { |
|
106 GetDBErrMsg( retCode ); |
|
107 return EFalse; |
|
108 } |
|
109 return ETrue; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // Edit phrase from DB |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 TBool CDBManagement::EditPhraseFromDB( const TDesC& aPhraseOld, |
|
117 const TDesC& aPhraseNew ) |
|
118 { |
|
119 TBool retCode; |
|
120 //Add the new phrase to the DB by PTI Engine |
|
121 retCode = AddPhraseToDB( aPhraseNew ); |
|
122 if ( !retCode ) |
|
123 { |
|
124 GetDBErrMsg( retCode ); |
|
125 return EFalse; |
|
126 } |
|
127 retCode = RemovePhraseFromDB( aPhraseOld ); |
|
128 if ( !retCode ) |
|
129 { |
|
130 GetDBErrMsg( retCode ); |
|
131 return EFalse; |
|
132 } |
|
133 return ETrue; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------- |
|
137 // Remove phrase from DB |
|
138 // --------------------------------------------------------- |
|
139 // |
|
140 TBool CDBManagement::RemovePhraseFromDB(const TDesC& aPhraseRemove ) |
|
141 { |
|
142 TInt retCode; |
|
143 TPtiUserDictionaryEntry removeUdbEntry( aPhraseRemove ); |
|
144 //Remove the phrase from the DB by PTI Engine |
|
145 TRAP_IGNORE( ActivateLanguageOfFepL() ); |
|
146 iPtiEngineOfFep->RemoveEntryFromUserDictionary( removeUdbEntry ); |
|
147 retCode = iPtiEngine->RemoveEntryFromUserDictionary( removeUdbEntry ); |
|
148 if( KErrNone != retCode ) |
|
149 { |
|
150 GetDBErrMsg( retCode ); |
|
151 return EFalse; |
|
152 } |
|
153 return ETrue; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------- |
|
157 // Get phrases from DB |
|
158 // --------------------------------------------------------- |
|
159 // |
|
160 TBool CDBManagement::GetPhraseFromDBL( CDesCArray& aPhraseGet ) |
|
161 { |
|
162 TPtiUserDictionaryEntry getUdbEntry; |
|
163 TInt retCode; |
|
164 TInt i = 0; |
|
165 ActivateLanguage(); |
|
166 |
|
167 retCode = iPtiEngine->GetUserDictionaryEntry(i, getUdbEntry); |
|
168 |
|
169 while (retCode == KErrNone) |
|
170 { |
|
171 aPhraseGet.AppendL(getUdbEntry.Word()); |
|
172 i++; |
|
173 retCode = iPtiEngine->GetUserDictionaryEntry(i, getUdbEntry); |
|
174 } |
|
175 |
|
176 return ETrue; |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------- |
|
180 // Get Error Message |
|
181 // --------------------------------------------------------- |
|
182 // |
|
183 void CDBManagement::GetErrMsg( TDes& aErrMsg ) |
|
184 { |
|
185 aErrMsg.Copy(iErrMsg); |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // Check the input phrase |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 TBool CDBManagement::InputPhraseCheck( TDes& aPhraseInput ) |
|
193 { |
|
194 const TUint16 KChineseUnicodeMin = 0x4E00; |
|
195 const TUint16 KChineseUnicodeMax = 0x9FA5; |
|
196 const TUint16 KSpaceUnicode = 0x0020; |
|
197 const TUint16 KKeytroke2Unicode = 0x4E28; |
|
198 const TUint16 KKeytroke3Unicode = 0x4E3F; |
|
199 const TUint16 KKeytroke4Unicode = 0x4E36; |
|
200 const TUint16 KKeytroke5Unicode = 0x4E5B; |
|
201 TBuf<KInputPhraseMaxLength> inputText; |
|
202 aPhraseInput.TrimAll(); |
|
203 TBool inValidFlg = EFalse; |
|
204 //the input phrase length more than the max length |
|
205 if ( aPhraseInput.Length() > KInputPhraseMaxLength ) |
|
206 { |
|
207 return EFalse; |
|
208 } |
|
209 //check every character of input phrase |
|
210 for ( TInt i = 0; i < aPhraseInput.Length(); ++i ) |
|
211 { |
|
212 if ( ( (TInt)aPhraseInput[i] >= KChineseUnicodeMin ) && |
|
213 ( (TInt)aPhraseInput[i] <= KChineseUnicodeMax ) ) |
|
214 { |
|
215 if ( ( KKeytroke2Unicode == (TInt)aPhraseInput[i] ) || |
|
216 ( KKeytroke3Unicode == (TInt)aPhraseInput[i] ) || |
|
217 ( KKeytroke4Unicode == (TInt)aPhraseInput[i] ) || |
|
218 ( KKeytroke5Unicode == (TInt)aPhraseInput[i] ) ) |
|
219 { |
|
220 inValidFlg = ETrue; |
|
221 } |
|
222 else |
|
223 { |
|
224 inputText.Append( aPhraseInput[i] ); |
|
225 } |
|
226 } |
|
227 else |
|
228 { |
|
229 if ( KSpaceUnicode != (TInt)aPhraseInput[i] ) |
|
230 { |
|
231 inValidFlg = ETrue; |
|
232 } |
|
233 } |
|
234 } |
|
235 |
|
236 //out the chinese phrase. |
|
237 aPhraseInput = inputText; |
|
238 |
|
239 if ( inValidFlg ) |
|
240 { |
|
241 StringLoader::Load( iErrMsg, R_AKNFEP_CHINESE_USER_DB_NOTE_ONLY_CHINESE_TEXT ); |
|
242 return EFalse; |
|
243 } |
|
244 |
|
245 if ( aPhraseInput.Length() < 2 ) |
|
246 { |
|
247 StringLoader::Load( iErrMsg, R_AKNFEP_CHINESE_USER_DB_NOTE_TOO_SHORT_TEXT ); |
|
248 return EFalse; |
|
249 } |
|
250 |
|
251 return ETrue; |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------- |
|
255 // Set language |
|
256 // --------------------------------------------------------- |
|
257 // |
|
258 void CDBManagement::ActivateLanguageL() |
|
259 { |
|
260 TInt epocLanguageID = iAknFepSharedDataInterface->InputTextLanguage(); |
|
261 iPtiEngine->ActivateLanguageL((TLanguage)epocLanguageID); |
|
262 switch(epocLanguageID) |
|
263 { |
|
264 case ELangHongKongChinese: |
|
265 iPtiEngine->SetInputMode( EPtiEngineStrokeByPhrase ); |
|
266 break; |
|
267 case ELangTaiwanChinese: |
|
268 iPtiEngine->SetInputMode( EPtiEngineZhuyinByPhrase ); |
|
269 break; |
|
270 case ELangPrcChinese: |
|
271 iPtiEngine->SetInputMode( EPtiEnginePinyinByPhrase ); |
|
272 break; |
|
273 } |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------- |
|
277 // Set language |
|
278 // --------------------------------------------------------- |
|
279 // |
|
280 void CDBManagement::ActivateLanguageOfFepL() |
|
281 { |
|
282 TInt epocLanguageID = iAknFepSharedDataInterface->InputTextLanguage(); |
|
283 iPtiEngineOfFep->ActivateLanguageL((TLanguage)epocLanguageID); |
|
284 switch(epocLanguageID) |
|
285 { |
|
286 case ELangHongKongChinese: |
|
287 iPtiEngineOfFep->SetInputMode( EPtiEngineStroke ); |
|
288 break; |
|
289 case ELangTaiwanChinese: |
|
290 iPtiEngineOfFep->SetInputMode( EPtiEngineZhuyinByPhrase ); |
|
291 break; |
|
292 case ELangPrcChinese: |
|
293 iPtiEngineOfFep->SetInputMode( EPtiEnginePinyin ); |
|
294 break; |
|
295 } |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------- |
|
299 // Set language |
|
300 // --------------------------------------------------------- |
|
301 // |
|
302 void CDBManagement::ActivateLanguage() |
|
303 { |
|
304 TRAP_IGNORE( ActivateLanguageL() ); |
|
305 } |
|
306 |
|
307 // --------------------------------------------------------- |
|
308 // Get the ptiengine's error |
|
309 // --------------------------------------------------------- |
|
310 // |
|
311 void CDBManagement::GetDBErrMsg( TInt aErrCode ) |
|
312 { |
|
313 switch( aErrCode ) |
|
314 { |
|
315 case KInvalidPhrase: |
|
316 StringLoader::Load( iErrMsg, R_AKNFEP_CHINESE_USER_DB_NOTE_INVALID_PHRASE_TEXT ); |
|
317 break; |
|
318 case KPhraseExisted: |
|
319 StringLoader::Load( iErrMsg, R_AKNFEP_CHINESE_USER_DB_NOTE_PHRASE_EXISTED_TEXT ); |
|
320 break; |
|
321 case KPhraseNotExisted: |
|
322 StringLoader::Load( iErrMsg, R_AKNFEP_CHINESE_USER_DB_NOTE_NOT_EXISTED_TEXT ); |
|
323 break; |
|
324 case KInputPhraseOutRange: |
|
325 StringLoader::Load( iErrMsg, R_AKNFEP_CHINESE_USER_DB_PHRASE_TOO_LONG_TEXT ); |
|
326 break; |
|
327 case KDBHasNoSpace: |
|
328 StringLoader::Load( iErrMsg, R_AKNFEP_CHINESE_USER_DB_NOTE_DB_HAVE_NO_SPACE_TEXT ); |
|
329 break; |
|
330 default: |
|
331 break; |
|
332 } |
|
333 } |
|
334 |
|
335 //End of File |