1 /* |
|
2 * Copyright (c) 2009 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 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 #include <PtiEngine.h> |
|
29 #include <AknAppUi.h> //For CAknAppUi |
|
30 #include <akntitle.h> //CAknTitlePane |
|
31 #include <aknfep.rsg> //For R_SECONDARY_WRITING_LANG_NONE |
|
32 #include <StringLoader.h> |
|
33 #include <AknFepInternalCRKeys.h> |
|
34 #include <aknnotedialog.h> |
|
35 #include <avkon.rsg> |
|
36 #include <featmgr.h> |
|
37 #include <e32property.h> |
|
38 #include <AvkonInternalCRKeys.h> |
|
39 #include <aknenv.h> |
|
40 #include <AknSettingCache.h> |
|
41 #include "AknFepUIAvkonCtrlDualLanguageSettingModel.h" |
|
42 |
|
43 const TInt KAkFepDualLanguageMask = 0x03FF; |
|
44 const TInt KAkFepDualLanguageBufSize128 = 128; |
|
45 |
|
46 CAknFepDualLanguageSettingModel* CAknFepDualLanguageSettingModel::NewL() |
|
47 { |
|
48 CAknFepDualLanguageSettingModel* self = new( ELeave ) CAknFepDualLanguageSettingModel(); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 void CAknFepDualLanguageSettingModel::ConstructL() |
|
56 { |
|
57 iAknFepRepository = CRepository::NewL( KCRUidAknFep ); |
|
58 } |
|
59 |
|
60 CAknFepDualLanguageSettingModel::~CAknFepDualLanguageSettingModel() |
|
61 { |
|
62 if(iAknFepRepository) |
|
63 delete iAknFepRepository; |
|
64 } |
|
65 void CAknFepDualLanguageSettingModel::GetSecondaryInputLanguagesL( |
|
66 CArrayFix<TInt>* aSeedLanguages, |
|
67 CDesCArray* aLanguageNames, |
|
68 CCoeEnv* aCoeEnv) |
|
69 { |
|
70 CPtiEngine* ptiEngine = CPtiEngine::NewL(); |
|
71 CleanupStack::PushL( ptiEngine ); |
|
72 |
|
73 CArrayFix<TInt>* languageCodeArray = aSeedLanguages; |
|
74 ptiEngine->GetAvailableLanguagesL( languageCodeArray ); |
|
75 languageCodeArray->InsertL(0,0); // No secondary input language as the first item |
|
76 |
|
77 TInt count = languageCodeArray->Count(); |
|
78 for ( TInt index = 0; index < count; ++index ) |
|
79 { |
|
80 const TInt langCode = languageCodeArray->At(index); |
|
81 if(langCode == ELangTaiwanChinese || |
|
82 langCode == ELangHongKongChinese || |
|
83 langCode == ELangPrcChinese || |
|
84 langCode == ELangJapanese || |
|
85 langCode == ELangKorean ) |
|
86 { |
|
87 languageCodeArray->Delete(index); |
|
88 count--; |
|
89 index--; |
|
90 } |
|
91 } |
|
92 |
|
93 HBufC* noneString = StringLoader::LoadLC( R_SECONDARY_WRITING_LANG_NONE, aCoeEnv); |
|
94 TPtr nonePtr( noneString->Des() ); |
|
95 aLanguageNames->AppendL(nonePtr); |
|
96 CleanupStack::PopAndDestroy( noneString ); |
|
97 |
|
98 HBufC* buffer = HBufC::NewLC( KAkFepDualLanguageBufSize128 ); |
|
99 for ( TInt index = 1; index < count; ++index ) |
|
100 { |
|
101 const TInt langId = languageCodeArray->At( index ); |
|
102 |
|
103 TPtr ptrToBuffer( buffer->Des() ); |
|
104 ptiEngine->GetLocalizedLanguageName( langId & KAkFepDualLanguageMask, |
|
105 ptrToBuffer ); |
|
106 |
|
107 aLanguageNames->AppendL( ptrToBuffer ); |
|
108 |
|
109 ptrToBuffer.Zero(); |
|
110 } |
|
111 |
|
112 CleanupStack::PopAndDestroy( buffer ); |
|
113 CleanupStack::PopAndDestroy( ptiEngine ); |
|
114 } |
|
115 void CAknFepDualLanguageSettingModel::ShowDualInputLanguageSettingListL(CCoeEnv* aCoeEnv) |
|
116 { |
|
117 CAknAppUi* appUi = static_cast<CAknAppUi*>(aCoeEnv->AppUi()); |
|
118 |
|
119 CAknTitlePane* titlePane = static_cast<CAknTitlePane*>( appUi->StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
120 |
|
121 const TDesC* appTitle = titlePane->Text(); |
|
122 HBufC* oldTitle = appTitle->AllocL(); |
|
123 CleanupStack::PushL(oldTitle); |
|
124 HBufC* title = StringLoader::LoadLC( R_INPUT_LANGUAGE_SETTINGS_TITLE, aCoeEnv); |
|
125 titlePane->SetTextL( *title ); |
|
126 CleanupStack::PopAndDestroy(title); |
|
127 |
|
128 //Launch dialog |
|
129 |
|
130 titlePane->SetTextL( *oldTitle ); |
|
131 CleanupStack::PopAndDestroy(oldTitle); |
|
132 } |
|
133 |
|
134 |
|
135 // ================= DATA ACCESS FUNCTIONS ================== |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // CAknFepDualLanguageSettingModel::GetLanguagesFromPtiL |
|
139 // |
|
140 // Utility routine to get available languages with Symbian OS codes |
|
141 // ---------------------------------------------------------------------------- |
|
142 // |
|
143 void CAknFepDualLanguageSettingModel::GetLanguagesFromPtiL( |
|
144 CArrayFix<TInt>* aInstalledLangCodes, |
|
145 CArrayFix<TInt>* aSeedLanguages, |
|
146 CDesCArray* aLanguageNames ) |
|
147 { |
|
148 CPtiEngine* ptiEngine = CPtiEngine::NewL(); |
|
149 CleanupStack::PushL( ptiEngine ); |
|
150 |
|
151 CArrayFix<TInt>* languageCodeArray = aSeedLanguages; |
|
152 if ( aInstalledLangCodes ) |
|
153 { |
|
154 languageCodeArray = aInstalledLangCodes; |
|
155 } |
|
156 else |
|
157 { |
|
158 ptiEngine->GetAvailableLanguagesL( languageCodeArray ); |
|
159 } |
|
160 |
|
161 HBufC* buffer = HBufC::NewLC( KAkFepDualLanguageBufSize128 ); |
|
162 const TInt count = languageCodeArray->Count(); |
|
163 for ( TInt index = 0; index < count; ++index ) |
|
164 { |
|
165 const TInt langId = languageCodeArray->At( index ); |
|
166 |
|
167 TPtr ptrToBuffer( buffer->Des() ); |
|
168 ptiEngine->GetLocalizedLanguageName( langId & KAkFepDualLanguageMask, |
|
169 ptrToBuffer ); |
|
170 |
|
171 if ( aInstalledLangCodes ) |
|
172 { |
|
173 aSeedLanguages->AppendL( langId ); |
|
174 } |
|
175 aLanguageNames->AppendL( ptrToBuffer ); |
|
176 |
|
177 ptrToBuffer.Zero(); |
|
178 } |
|
179 |
|
180 CleanupStack::PopAndDestroy( buffer ); |
|
181 CleanupStack::PopAndDestroy( ptiEngine ); |
|
182 } |
|
183 |
|
184 TInt CAknFepDualLanguageSettingModel::LanguageL( TLanguageType aType ) |
|
185 { |
|
186 TInt Language = KErrNone; |
|
187 switch ( aType ) |
|
188 { |
|
189 case EAknFepDualLanguageSettingInputLanguage: |
|
190 { |
|
191 User::LeaveIfError( |
|
192 iAknFepRepository->Get( KAknFepInputTxtLang, Language ) ); |
|
193 } |
|
194 break; |
|
195 case EAknFepDualLanguageSettingInputLanguageSecondary: |
|
196 { |
|
197 User::LeaveIfError( |
|
198 iAknFepRepository->Get( KAknFepInputTxtLangSecondary, Language ) ); |
|
199 } |
|
200 break; |
|
201 default: |
|
202 break; |
|
203 } |
|
204 return Language; |
|
205 |
|
206 } |
|
207 |
|
208 |
|
209 TBool CAknFepDualLanguageSettingModel::SetLanguageL( TLanguageType aType, TInt aLanguage ) |
|
210 { |
|
211 TBool ret = ETrue; |
|
212 |
|
213 switch( aType ) |
|
214 { |
|
215 case EAknFepDualLanguageSettingInputLanguage: |
|
216 { |
|
217 if( iAknFepRepository->Set( KAknFepInputTxtLang, |
|
218 aLanguage ) != KErrNone ) |
|
219 { |
|
220 ret = EFalse; |
|
221 } |
|
222 |
|
223 if(ret) |
|
224 { |
|
225 // now inform all open apps of the switch |
|
226 TWsEvent event; |
|
227 event.SetType(KEikInputLanguageChange); |
|
228 CEikonEnv::Static()->WsSession().SendEventToAllWindowGroups(event); |
|
229 CAknEnv::Static()->SettingCache().Update(KEikInputLanguageChange); |
|
230 } |
|
231 |
|
232 // See if it cannot do predictive text entry |
|
233 if( !CheckDictionaryFromPtiL( aLanguage ) ) |
|
234 { |
|
235 CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog( ); |
|
236 dlg->ExecuteDlgLD( |
|
237 CAknNoteDialog::EShortTimeout, |
|
238 CAknNoteDialog::ENoTone, |
|
239 R_AVKON_T9_NOTE_NO_AVAILABLE ); |
|
240 |
|
241 } |
|
242 } |
|
243 break; |
|
244 case EAknFepDualLanguageSettingInputLanguageSecondary: |
|
245 { |
|
246 if( iAknFepRepository->Set( KAknFepInputTxtLangSecondary, |
|
247 aLanguage ) != KErrNone ) |
|
248 { |
|
249 ret = EFalse; |
|
250 } |
|
251 if(ret) |
|
252 { |
|
253 // now inform all open apps of the switch |
|
254 // same event as primary input language change |
|
255 TWsEvent event; |
|
256 event.SetType(KEikInputLanguageChange); |
|
257 CEikonEnv::Static()->WsSession().SendEventToAllWindowGroups(event); |
|
258 CAknEnv::Static()->SettingCache().Update(KEikInputLanguageChange); |
|
259 } |
|
260 // Secondary input language does not need prediction |
|
261 // so we don't check for it |
|
262 } |
|
263 break; |
|
264 default: |
|
265 break; |
|
266 |
|
267 } |
|
268 return ret; |
|
269 } |
|
270 |
|
271 // ---------------------------------------------------------------------------- |
|
272 // CGSLangModel::CheckDictionaryFromPtiL |
|
273 // |
|
274 // Checks if the selected language supports predictive text input. |
|
275 // In case this returns EFalse, the UI display's "Not available" |
|
276 // for Predictive text input. |
|
277 // ---------------------------------------------------------------------------- |
|
278 // |
|
279 TBool CAknFepDualLanguageSettingModel::CheckDictionaryFromPtiL( TInt aLangCode ) |
|
280 { |
|
281 TBool langSupport = EFalse; |
|
282 |
|
283 if ( FeatureManager::FeatureSupported( KFeatureIdChinese ) || |
|
284 FeatureManager::FeatureSupported( KFeatureIdJapanese ) ) |
|
285 { |
|
286 langSupport = ETrue; |
|
287 } |
|
288 else |
|
289 { |
|
290 CPtiEngine* ptiEngine = CPtiEngine::NewL(); |
|
291 CleanupStack::PushL( ptiEngine ); |
|
292 |
|
293 MPtiLanguage* ptiLang = ptiEngine->GetLanguage( aLangCode ); |
|
294 if ( ptiLang ) |
|
295 { |
|
296 // the check here should be based on the keyboard |
|
297 TInt keyboardLayout = 0; |
|
298 RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout); |
|
299 TPtiKeyboardType layout = (TPtiKeyboardType)keyboardLayout; |
|
300 switch(layout) |
|
301 { |
|
302 case EPtiKeyboardHalfQwerty: |
|
303 langSupport = ptiLang->HasInputMode( (TPtiEngineInputMode)EPtiEngineHalfQwertyPredictive); |
|
304 break; |
|
305 case EPtiKeyboardQwerty4x12: |
|
306 case EPtiKeyboardQwerty4x10: |
|
307 case EPtiKeyboardQwerty3x11: |
|
308 case EPtiKeyboardCustomQwerty: |
|
309 langSupport = ptiLang->HasInputMode( (TPtiEngineInputMode)EPtiEngineQwertyPredictive); |
|
310 break; |
|
311 case EPtiKeyboardNone: |
|
312 case EPtiKeyboard12Key: |
|
313 langSupport = ptiLang->HasInputMode( (TPtiEngineInputMode)EPtiEnginePredictive); |
|
314 break; |
|
315 default: |
|
316 langSupport = ptiLang->HasInputMode( (TPtiEngineInputMode)EPtiEnginePredictive); |
|
317 break; |
|
318 } |
|
319 |
|
320 } |
|
321 CleanupStack::PopAndDestroy( ptiEngine ); |
|
322 ptiLang = NULL; |
|
323 } |
|
324 |
|
325 return langSupport; |
|
326 } |
|