23 // If this macro is defined, Orbit code is used to build the keymap. |
23 // If this macro is defined, Orbit code is used to build the keymap. |
24 // But this might crash at startup for unknown reason. |
24 // But this might crash at startup for unknown reason. |
25 // |
25 // |
26 // If macro is not defined, a hardcoded keymap is used. That code does not |
26 // If macro is not defined, a hardcoded keymap is used. That code does not |
27 // crash, but it supports just a limited range of characters. |
27 // crash, but it supports just a limited range of characters. |
28 //#define USE_ORBIT_KEYMAP |
28 #define USE_ORBIT_KEYMAP |
|
29 |
|
30 // If this macro is defined, the hardcoded keymap contains also Thai characters |
|
31 #define THAI_KEYMAP |
29 |
32 |
30 |
33 |
31 // INCLUDES |
34 // INCLUDES |
32 #if defined(USE_ORBIT_KEYMAP) |
35 #if defined(USE_ORBIT_KEYMAP) |
33 #include <QList> |
36 #include <QList> |
34 #include <QLocale> |
37 #include <QLocale> |
|
38 #include <hbinputdef.h> // HbKeyboardType |
|
39 #include <hbinputlanguage.h> |
35 #endif |
40 #endif |
36 |
|
37 #include <e32base.h> |
41 #include <e32base.h> |
38 |
42 |
39 // FORWARD DECLARATIONS |
43 // FORWARD DECLARATIONS |
40 #if defined(USE_ORBIT_KEYMAP) |
|
41 class QString; |
44 class QString; |
42 class HbInputLanguage; |
45 class QChar; |
43 class HbKeymap; |
46 |
44 #endif |
|
45 |
47 |
46 // CLASS DECLARATION |
48 // CLASS DECLARATION |
47 NONSHARABLE_CLASS(CPcsKeyMap) : public CBase |
49 NONSHARABLE_CLASS(CPcsKeyMap) : public CBase |
48 { |
50 { |
49 public: |
51 public: |
50 /** |
|
51 * Two phase construction |
|
52 */ |
|
53 static CPcsKeyMap* NewL(); |
|
54 |
|
55 /** |
52 /** |
56 * Destructor |
53 * Destructor |
57 */ |
54 */ |
58 virtual ~CPcsKeyMap(); |
55 virtual ~CPcsKeyMap(); |
59 |
56 |
|
57 public: // New functions |
60 /** |
58 /** |
61 * Converts a string to a numeric string. |
59 * Maps the given string using the key map. |
62 * aSource String to be converted |
60 * aSource String to be converted |
63 * aPlainConversion ETrue Perform a simple conversion, without special |
|
64 * handling for sepator characters |
|
65 * EFalse Convert spaces to separator characters |
|
66 * returns Conversion result, ownership is transferred |
61 * returns Conversion result, ownership is transferred |
67 */ |
62 */ |
68 HBufC* GetNumericKeyStringL(const TDesC& aSource, |
63 HBufC* GetMappedStringL(const TDesC& aSource) const; |
69 TBool aPlainConversion) const; |
64 |
|
65 /** |
|
66 * Maps the given string using the key map. |
|
67 * aSource String to be converted |
|
68 * returns Conversion result |
|
69 * |
|
70 * Overloaded version using QString. |
|
71 */ |
|
72 QString GetMappedString(QString aSource) const; |
|
73 |
|
74 /** |
|
75 * Computes the upper and lower limits, that can be put into SQL SELECT |
|
76 * statement, from the string. |
|
77 * aString Only contains valid characters (for 12-key keymap this means |
|
78 * 0..9, 'a', 'b', 'f'). This is fulfilled if aString is output from |
|
79 * GetMappedStringL or GetMappedString, or a sub-string of the output. |
|
80 * aLowerLimit Lower limit |
|
81 * aUpperLimit Upper limit |
|
82 * returns KErrNone if successful |
|
83 */ |
|
84 TInt GetNumericLimits(QString aString, |
|
85 QString& aLowerLimit, |
|
86 QString& aUpperLimit) const; |
70 |
87 |
71 #if defined(USE_ORBIT_KEYMAP) |
88 #if defined(USE_ORBIT_KEYMAP) |
72 /* |
89 /* |
73 * Return the separator character. |
90 * Return the separator character. |
74 */ |
91 */ |
75 QChar Separator() const; |
92 QChar Separator() const; |
76 #endif |
93 #endif |
77 |
94 |
78 private: |
95 public: // Pure virtual functions |
79 /** |
96 virtual const QChar ArrayIndexToMappedChar(TInt aArrayIndex) const = 0; |
|
97 #if !defined(USE_ORBIT_KEYMAP) |
|
98 virtual const QChar UseHardcodedKeyMap(const QChar input) const = 0; |
|
99 #endif |
|
100 |
|
101 private: // Pure virtual functions |
|
102 virtual TInt ComputeValue(QString aString, |
|
103 TBool aUpperLimit, |
|
104 QString& aValue) const = 0; |
|
105 |
|
106 #if defined(USE_ORBIT_KEYMAP) |
|
107 protected: // Virtual functions |
|
108 virtual QList<HbInputLanguage> SelectLanguages(); |
|
109 |
|
110 private: // Virtual functions |
|
111 virtual void SetHardcodedCharacters(); |
|
112 #endif |
|
113 |
|
114 private: // Virtual functions |
|
115 /** |
|
116 * Returns ETrue if characters that are mapped to certain specific keys, |
|
117 * should be skipped. |
|
118 */ |
|
119 virtual TBool DetermineSpecialCharBehaviour(QString aSource) const; |
|
120 |
|
121 virtual TBool ShouldSkipChar(QChar aChar, TBool aSkipHashStar) const; |
|
122 |
|
123 protected: // Constructors |
|
124 /** |
80 * Constructor |
125 * Constructor |
81 */ |
126 */ |
82 CPcsKeyMap(); |
127 CPcsKeyMap(TInt aAmountOfKeys, QChar aPadChar, TInt aMaxKeysStoredInDb); |
83 |
128 |
84 /** |
129 /** |
85 * Second phase constructor |
130 * Second phase constructor |
86 */ |
131 */ |
|
132 #if defined(USE_ORBIT_KEYMAP) |
|
133 void ConstructL(HbKeyboardType aKeyboardType); |
|
134 #else |
87 void ConstructL(); |
135 void ConstructL(); |
|
136 #endif |
88 |
137 |
|
138 private: // New functions |
89 #if defined(USE_ORBIT_KEYMAP) |
139 #if defined(USE_ORBIT_KEYMAP) |
90 /** |
140 void InitKeyMappings(); |
91 * Construct mappings between keys and characters. |
|
92 */ |
|
93 void ContructKeyboardMappings(); |
|
94 |
141 |
95 /** |
142 /** |
96 * Returns a list of languages installed on the phone. |
143 * Construct mappings between keys and characters for all languages. |
97 */ |
144 */ |
98 QList<HbInputLanguage> AvailableLanguages() const; |
145 void ConstructLanguageMappings(HbKeyboardType aKeyboardType); |
99 |
146 |
100 /** |
147 /** |
101 * Returns ETrue if this language is supported |
148 * Returns ETrue if this language is supported |
102 */ |
149 */ |
103 TBool IsLanguageSupported(QLocale::Language aLanguage) const; |
150 TBool IsLanguageSupported(QLocale::Language aLanguage) const; |
104 |
151 |
105 /** |
152 /** |
106 * Returns the numeric key id corresponding to a specific character |
153 * Returns the key into which the given character is mapped. |
107 * Considers possible multiple matches for some phone variants |
|
108 */ |
154 */ |
109 TChar KeyForCharacter(const TChar& aChar) const; |
155 const QChar MappedKeyForChar(const QChar aChar) const; |
110 |
|
111 #if defined(_DEBUG) |
|
112 TInt KeyIdToNumber(TInt aKeyId) const; |
|
113 #endif // #if defined(_DEBUG) |
|
114 |
|
115 TChar ArrayIndexToNumberChar(TInt aArrayIndex) const; |
|
116 #else // #if defined(USE_ORBIT_KEYMAP) |
|
117 TChar GetNumericValueForChar(TChar input) const; |
|
118 #endif // #if defined(USE_ORBIT_KEYMAP) |
156 #endif // #if defined(USE_ORBIT_KEYMAP) |
119 |
157 |
120 private: // Data |
|
121 |
|
122 #if defined(USE_ORBIT_KEYMAP) |
158 #if defined(USE_ORBIT_KEYMAP) |
123 // One QString for each key of the keyboard (1-9,0,*,#). |
159 protected: |
|
160 // One QString for each key of the keyboard. |
124 // Each contains all the characters that can originate from that key, |
161 // Each contains all the characters that can originate from that key, |
125 // considering the languages available on the device. |
162 // considering the languages available on the device. |
126 // |
163 // |
127 // iKeyMapping[0] has mappings for 1-key, iKeyMapping[1] for 2-key, ... |
164 // 12-key keymap has keys 1-9,0,*,#. |
128 // iKeyMapping[8] for 9-key, iKeyMapping[9] for 0-key, |
165 // iKeyMapping[0] has mappings for 1-key, iKeyMapping[1] for 2-key, ... |
129 // iKeyMapping[10] for *-key, iKeyMapping[11] for #-key. |
166 // iKeyMapping[8] for 9-key, iKeyMapping[9] for 0-key, |
|
167 // iKeyMapping[10] for *-key, iKeyMapping[11] for #-key. |
|
168 // |
|
169 // Qwerty keymap has keys q, w, e, r, ... |
|
170 // iKeyMapping[0] has mappings for q-key, iKeyMapping[1] for w-key, ... |
130 QList<QString> iKeyMapping; |
171 QList<QString> iKeyMapping; |
131 |
172 |
132 // Characters that have been hardcoded to certain keys, regardless of |
173 // Characters that have been hardcoded to certain keys, regardless of |
133 // actual keymap. |
174 // the actual keymaps. |
134 QString iHardcodedChars; |
175 QString iHardcodedChars; |
|
176 |
|
177 private: // Data |
|
178 // How many keys (not characters) the keymap has |
|
179 const TInt iAmountOfKeys; |
|
180 |
|
181 // Unmapped (unknown) characters are mapped to this |
|
182 const QChar iPadChar; |
135 #endif // #if defined(USE_ORBIT_KEYMAP) |
183 #endif // #if defined(USE_ORBIT_KEYMAP) |
|
184 |
|
185 // Largest amount of keypresses that can be stored in predictive search |
|
186 // table, using this keyboard. |
|
187 const TInt iMaxKeysStoredInDb; |
136 |
188 |
137 // For unit testing |
189 // For unit testing |
138 friend class UT_CPcsKeyMap; |
190 friend class UT_CPcsKeyMap; |
139 }; |
191 }; |
140 |
192 |