68 EKey5, |
68 EKey5, |
69 EKey6, |
69 EKey6, |
70 EKey7, |
70 EKey7, |
71 EKey8, |
71 EKey8, |
72 EKey9, |
72 EKey9, |
73 EKey0 |
73 EKey0, |
|
74 EKeyStar, |
|
75 EKeyHash, |
|
76 ELastKey = EKeyHash |
74 }; |
77 }; |
|
78 |
|
79 const QChar KStar = '*'; |
|
80 const QChar KPlus = '+'; |
|
81 const QChar KHash = '#'; |
75 #endif // #if defined(USE_ORBIT_KEYMAP) |
82 #endif // #if defined(USE_ORBIT_KEYMAP) |
76 |
83 |
|
84 // * key is mapped to this |
|
85 const TChar KMappedCharForStar = 'a'; |
|
86 // # key is mapped to this |
|
87 const TChar KMappedCharForHash = 'b'; |
|
88 // Unmapped (unknown) characters are replaced with this |
|
89 const TChar KPadChar = 'f'; |
|
90 |
|
91 |
77 // ============================== MEMBER FUNCTIONS ============================ |
92 // ============================== MEMBER FUNCTIONS ============================ |
78 |
93 |
79 // ---------------------------------------------------------------------------- |
94 // ---------------------------------------------------------------------------- |
80 // CPcsKeyMap::NewL |
95 // CPcsKeyMap::NewL |
81 // ---------------------------------------------------------------------------- |
96 // ---------------------------------------------------------------------------- |
82 CPcsKeyMap* CPcsKeyMap::NewL() |
97 CPcsKeyMap* CPcsKeyMap::NewL() |
83 { |
98 { |
84 PRINT( _L("Enter CPcsKeyMap::NewL") ); |
99 PRINT(_L("Enter CPcsKeyMap::NewL")); |
85 |
100 |
86 CPcsKeyMap* self = new ( ELeave ) CPcsKeyMap(); |
101 CPcsKeyMap* self = new (ELeave) CPcsKeyMap(); |
87 CleanupStack::PushL( self ); |
102 CleanupStack::PushL(self); |
88 self->ConstructL(); |
103 self->ConstructL(); |
89 CleanupStack::Pop( self ); |
104 CleanupStack::Pop(self); |
90 |
105 |
91 PRINT( _L("End CPcsKeyMap::NewL") ); |
106 PRINT(_L("End CPcsKeyMap::NewL")); |
92 return self; |
107 return self; |
93 } |
108 } |
94 |
109 |
95 // ---------------------------------------------------------------------------- |
110 // ---------------------------------------------------------------------------- |
96 // CPcsKeyMap::~CPcsKeyMap |
111 // CPcsKeyMap::~CPcsKeyMap |
97 // ---------------------------------------------------------------------------- |
112 // ---------------------------------------------------------------------------- |
98 CPcsKeyMap::~CPcsKeyMap() |
113 CPcsKeyMap::~CPcsKeyMap() |
99 { |
114 { |
100 PRINT( _L("Enter CPcsKeyMap::~CPcsKeyMap") ); |
115 PRINT(_L("Enter CPcsKeyMap::~CPcsKeyMap")); |
101 PRINT( _L("End CPcsKeyMap::~CPcsKeyMap") ); |
116 PRINT(_L("End CPcsKeyMap::~CPcsKeyMap")); |
102 } |
117 } |
103 |
118 |
104 // ---------------------------------------------------------------------------- |
119 // ---------------------------------------------------------------------------- |
105 // CPcsKeyMap::GetNumericKeyStringL |
120 // CPcsKeyMap::GetNumericKeyStringL |
106 // If aPlainConversion is EFalse, supports sub-string searches and space is |
121 // If aPlainConversion is EFalse, supports sub-string searches and space is |
107 // converted to a separator character (not zero). |
122 // converted to a separator character (not zero). |
108 // ---------------------------------------------------------------------------- |
123 // ---------------------------------------------------------------------------- |
109 HBufC* CPcsKeyMap::GetNumericKeyStringL(const TDesC& aSource, |
124 HBufC* CPcsKeyMap::GetNumericKeyStringL(const TDesC& aSource, |
110 TBool aPlainConversion) const |
125 TBool aPlainConversion) const |
111 { |
126 { |
112 PRINT1( _L("Enter CPcsKeyMap::GetNumericKeyStringL input '%S'"), &aSource ); |
127 PRINT1(_L("Enter CPcsKeyMap::GetNumericKeyStringL input '%S'"), &aSource); |
113 |
128 |
114 TInt length = aSource.Length(); |
129 TInt length = aSource.Length(); |
115 HBufC* destination = HBufC::NewL(length); |
130 HBufC* destination = HBufC::NewL(length); |
116 TPtr ptr = destination->Des(); |
131 TPtr ptr = destination->Des(); |
117 |
132 |
151 // Fill QList with empty strings |
166 // Fill QList with empty strings |
152 // ---------------------------------------------------------------------------- |
167 // ---------------------------------------------------------------------------- |
153 CPcsKeyMap::CPcsKeyMap() : |
168 CPcsKeyMap::CPcsKeyMap() : |
154 iKeyMapping() |
169 iKeyMapping() |
155 { |
170 { |
156 for (TInt i = 0; i < KAmountOfKeys; ++i) |
|
157 { |
|
158 iKeyMapping << QString(""); |
|
159 } |
|
160 } |
171 } |
161 |
172 |
162 // ---------------------------------------------------------------------------- |
173 // ---------------------------------------------------------------------------- |
163 // CPcsKeyMap::ConstructL |
174 // CPcsKeyMap::ConstructL |
164 // ---------------------------------------------------------------------------- |
175 // ---------------------------------------------------------------------------- |
165 void CPcsKeyMap::ConstructL() |
176 void CPcsKeyMap::ConstructL() |
166 { |
177 { |
167 TBool ok(EFalse); |
|
168 TInt err(KErrNone); |
178 TInt err(KErrNone); |
169 QT_TRYCATCH_ERROR(err, ok = ContructKeyboardMappings()); |
179 QT_TRYCATCH_ERROR(err, ContructKeyboardMappings()); |
170 if (err != KErrNone) |
180 if (err != KErrNone) |
171 { |
181 { |
172 PRINT1(_L("ContructKeyboardMappings threw exception, err=%d"), err); |
182 PRINT1(_L("ContructKeyboardMappings threw exception, err=%d"), err); |
173 User::Leave(err); |
183 User::Leave(err); |
174 } |
184 } |
175 if (!ok) |
|
176 { |
|
177 PRINT(_L("ContructKeyboardMappings returns error")); |
|
178 User::Leave(KErrGeneral); |
|
179 } |
|
180 } |
185 } |
181 |
186 |
182 // ---------------------------------------------------------------------------- |
187 // ---------------------------------------------------------------------------- |
183 // CPcsKeyMap::ContructKeyboardMappings |
188 // CPcsKeyMap::ContructKeyboardMappings |
184 // Fetch keymap for every language/country pair present. |
189 // Fetch keymap for every language/country pair present. |
185 // 10.1 only has virtual 12 key ITU-T keyboard |
190 // Even though most languages map *, + and # to 1-key, they are here mapped to |
186 // ---------------------------------------------------------------------------- |
191 // the distinct *-key or #-key of the 12-key ITU-T keypad. |
187 TBool CPcsKeyMap::ContructKeyboardMappings() |
192 // ---------------------------------------------------------------------------- |
188 { |
193 void CPcsKeyMap::ContructKeyboardMappings() |
189 PRINT( _L("Enter CPcsKeyMap::ContructKeyboardMappings") ); |
194 { |
|
195 PRINT(_L("Enter CPcsKeyMap::ContructKeyboardMappings")); |
|
196 |
|
197 for (TInt i = 0; i < KAmountOfKeys; ++i) |
|
198 { |
|
199 iKeyMapping << QString(""); |
|
200 } |
|
201 |
|
202 iKeyMapping[EKeyStar].append(KStar); |
|
203 iKeyMapping[EKeyStar].append(KPlus); |
|
204 iKeyMapping[EKeyHash].append(KHash); |
|
205 iHardcodedChars.append(KStar); |
|
206 iHardcodedChars.append(KPlus); |
|
207 iHardcodedChars.append(KHash); |
190 |
208 |
191 #if defined(_DEBUG) |
209 #if defined(_DEBUG) |
192 TInt count(0); |
210 TInt count(0); |
193 #endif |
211 #endif |
194 |
|
195 TInt err(KErrNone); |
|
196 QList<HbInputLanguage> languages; |
212 QList<HbInputLanguage> languages; |
197 #if defined(USE_ONLY_DEFAULT_LANG_KEYMAP) |
213 #if defined(USE_ONLY_DEFAULT_LANG_KEYMAP) |
198 HbInputLanguage inputLanguage(QLocale::system().language()); |
214 HbInputLanguage inputLanguage(QLocale::system().language()); |
199 languages << inputLanguage; |
215 languages << inputLanguage; |
200 #else |
216 #else |
201 languages = AvailableLanguages(); |
217 languages = AvailableLanguages(); |
202 #endif |
218 #endif |
203 // Calling HbKeymapFactory::keymap() causes "no memory" exception after |
219 TInt languageCount = languages.size(); |
204 // ~20 different language/variant combinations in emulator. |
220 for (TInt lang = 0; lang < languageCount; ++lang) |
205 // In text shell all languages can be handled successfully. |
|
206 // In device, already the first call to HbKeymapFactory::keymap() |
|
207 // crashes. |
|
208 const TInt KMaxLanguages = 30; |
|
209 TInt handleMaxLanguages = languages.size(); |
|
210 if (handleMaxLanguages > KMaxLanguages) |
|
211 { |
|
212 handleMaxLanguages = KMaxLanguages; |
|
213 } |
|
214 PRINT1( _L("handle %d languages"), handleMaxLanguages ); // test |
|
215 |
|
216 for (TInt lang = 0; lang < handleMaxLanguages; ++lang) |
|
217 { |
221 { |
218 // PRINT1( _L("handle language %d"), languages[lang].language() ); // test |
222 PRINT2(_L("(%d) handle language %d"), lang, languages[lang].language()); |
219 if (IsLanguageSupported(languages[lang].language())) |
223 if (IsLanguageSupported(languages[lang].language())) |
220 { |
224 { |
221 PRINT2(_L("Constructing keymap for lang=%d,var=%d"), |
225 /* PRINT2(_L("Constructing keymap for lang=%d,var=%d"), |
222 languages[lang].language(), |
226 languages[lang].language(), |
223 languages[lang].variant()); |
227 languages[lang].variant()); */ |
224 const HbKeymap* keymap = |
228 const HbKeymap* keymap = |
225 HbKeymapFactory::instance()->keymap(languages[lang].language(), |
229 HbKeymapFactory::instance()->keymap(languages[lang].language(), |
226 languages[lang].variant()); |
230 languages[lang].variant()); |
227 if (keymap) |
231 if (keymap) |
228 { |
232 { |
229 for (TInt key = EKey1; key <= EKey0; ++key) |
233 for (TInt key = EKey1; key <= ELastKey; ++key) |
230 { |
234 { |
231 PRINT1( _L("handle key(enum value %d)"), key ); // test |
235 // PRINT1(_L("handle key(enum value %d)"), key); // test |
232 const HbMappedKey* mappedKey = keymap->keyForIndex(HbKeyboardVirtual12Key, key); |
236 const HbMappedKey* mappedKey = keymap->keyForIndex(HbKeyboardVirtual12Key, key); |
233 if (!mappedKey) |
237 // mappedKey can be NULL, as most languages don't have mapping for EKeyStar, EKeyHash |
|
238 if (mappedKey) |
234 { |
239 { |
235 PRINT1(_L("Mapped key not found, key(%d)"), KeyIdToNumber(key)); |
240 const QString lowerCase = mappedKey->characters(HbModifierNone); // "abc2.." |
236 return EFalse; |
241 const QString upperCase = mappedKey->characters(HbModifierShiftPressed); // "ABC2.." |
237 } |
242 const QString charsForKey = lowerCase + upperCase; |
238 // Get both upper and lowercase letters |
243 |
239 const QString lowerCase = mappedKey->characters(HbModifierNone); // e.g. "abc2.." |
244 // Filter out duplicate characters |
240 const QString upperCase = mappedKey->characters(HbModifierShiftPressed); // e.g. "ABC2.." |
245 for (TInt i = charsForKey.length() - 1; i >= 0 ; --i) |
241 const QString charsForKey = lowerCase + upperCase; |
246 { |
242 |
247 QChar ch = charsForKey[i]; |
243 // Filter out duplicate characters |
248 if (!iKeyMapping[key].contains(ch) && |
244 for (TInt i = charsForKey.length() - 1; i >= 0 ; --i) |
249 !iHardcodedChars.contains(ch)) |
245 { |
250 { |
246 QChar ch = charsForKey[i]; |
251 /* PRINT3(_L("CPcsKeyMap: map key(%d) <-> char='%c'(0x%x)"), |
247 // Key '1' is at index 0 in iKeyMapping, key '2' at index 1 etc. |
252 KeyIdToNumber(key), |
248 // and key '0' at the last index. |
253 ch.toAscii(), |
249 TInt index = key - EKey1; |
254 ch.toAscii()); */ |
250 if (!iKeyMapping[index].contains(ch)) |
|
251 { |
|
252 /* |
|
253 PRINT3(_L("CPcsKeyMap: map key(%d) <-> char='%c'(0x%x)"), |
|
254 KeyIdToNumber(key), |
|
255 ch.toAscii(), |
|
256 ch.toAscii()); */ |
|
257 #if defined(_DEBUG) |
255 #if defined(_DEBUG) |
258 ++count; |
256 ++count; |
259 #endif |
257 #endif |
260 iKeyMapping[index] += ch; |
258 iKeyMapping[key] += ch; |
261 } |
259 } |
262 } |
260 } |
|
261 } |
263 } |
262 } |
264 } |
263 } |
265 else |
264 else |
266 { |
265 { |
267 PRINT(_L("CPcsKeyMap::ContructKeyboardMapping keymap not found")); |
266 PRINT(_L("CPcsKeyMap::ContructKeyboardMapping keymap not found")); |
268 } |
267 } |
269 } |
268 } |
270 } |
269 } |
271 |
270 |
272 #if defined(_DEBUG) |
271 #if defined(_DEBUG) |
273 PRINT1( _L("End CPcsKeyMap::ContructKeyboardMappings keymap has %d chars"), count ); |
272 PRINT1(_L("End CPcsKeyMap::ContructKeyboardMappings keymap has %d chars"), count); |
274 #endif |
273 #endif |
275 return ETrue; |
|
276 } |
274 } |
277 |
275 |
278 // ---------------------------------------------------------------------------- |
276 // ---------------------------------------------------------------------------- |
279 // CPcsKeyMap::AvailableLanguages |
277 // CPcsKeyMap::AvailableLanguages |
280 // Put default language at the beginning of the language list, so that |
278 // Put default language at the beginning of the language list, so that |
281 // ContructKeyboardMappingsL handles it first. |
279 // ContructKeyboardMappingsL handles it first. |
282 // ---------------------------------------------------------------------------- |
280 // ---------------------------------------------------------------------------- |
283 QList<HbInputLanguage> CPcsKeyMap::AvailableLanguages() const |
281 QList<HbInputLanguage> CPcsKeyMap::AvailableLanguages() const |
284 { |
282 { |
285 PRINT( _L("Enter CPcsKeyMap::AvailableLanguages") ); |
283 PRINT(_L("Enter CPcsKeyMap::AvailableLanguages")); |
286 |
284 |
287 QList<HbInputLanguage> languages = HbKeymapFactory::availableLanguages(); |
285 QList<HbInputLanguage> languages = HbKeymapFactory::availableLanguages(); |
288 |
286 |
289 #if 0 // This code would make sure the default language is at the beginning of |
287 #if 1 // This code would make sure the default language is at the beginning of |
290 // list of available languages. But since there is resource leak, the code |
288 // list of available languages. But since there is resource leak, the code |
291 // is currently commented out until the leak is fixed. |
289 // is currently commented out until the leak is fixed. |
292 QLocale::Language currentLanguage = QLocale::system().language(); |
290 QLocale::Language currentLanguage = QLocale::system().language(); |
293 if (!IsLanguageSupported(currentLanguage)) |
291 if (!IsLanguageSupported(currentLanguage)) |
294 { |
292 { |
295 PRINT( _L("current lang not supported, use english") ); //test |
293 PRINT(_L("current lang not supported, use english")); //test |
296 currentLanguage = QLocale::English; |
294 currentLanguage = QLocale::English; |
297 } |
295 } |
298 HbInputLanguage defaultLanguage(currentLanguage); |
296 HbInputLanguage defaultLanguage(currentLanguage); |
299 if (languages.contains(defaultLanguage)) |
297 if (languages.contains(defaultLanguage)) |
300 { |
298 { |
301 PRINT( _L("remove default lang") ); //test |
299 PRINT(_L("remove default lang")); //test |
302 languages.removeOne(defaultLanguage); |
300 languages.removeOne(defaultLanguage); |
303 } |
301 } |
304 PRINT( _L("insert default lang as first lang") ); //test |
302 PRINT(_L("insert default lang as first lang")); //test |
305 languages.prepend(defaultLanguage); // THIS LEAKS RESOURCES! |
303 languages.prepend(defaultLanguage); // THIS LEAKS RESOURCES! |
306 #endif |
304 #endif |
307 |
305 |
308 PRINT1( _L("End CPcsKeyMap::AvailableLanguages found %d languages"), |
306 PRINT1(_L("End CPcsKeyMap::AvailableLanguages found %d languages"), |
309 languages.count() ); |
307 languages.count()); |
310 return languages; |
308 return languages; |
311 } |
309 } |
312 |
310 |
313 // ---------------------------------------------------------------------------- |
311 // ---------------------------------------------------------------------------- |
314 // CPcsKeyMap::IsLanguageSupported |
312 // CPcsKeyMap::IsLanguageSupported |