12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 #include <QObject> |
|
18 #include <QLocale> |
17 #include <QLocale> |
19 #include <QHash> |
|
20 #include <hbinputkeymap.h> |
18 #include <hbinputkeymap.h> |
21 #include <hbinputsettingproxy.h> |
19 #include <hbinputsettingproxy.h> |
22 #include <QTextCodec> |
20 #include <QTextCodec> |
23 |
21 |
24 #include "logspredictivelatin12keytranslator.h" |
22 #include "logspredictivelatin12keytranslator.h" |
25 #include "logslogger.h" |
23 #include "logslogger.h" |
26 |
24 |
|
25 |
27 //mapping char,key(name) |
26 //mapping char,key(name) |
28 const QChar SpecialMapping[] = {'+', '*', '*', '*','#','#','%','1'}; |
27 const QChar SpecialMapping[] = {'+', StarKey, '*', StarKey, '#',HashKey }; |
29 const int SpecialsCount = 4; |
28 const int SpecialsCount = 3; |
30 const QChar SpaceSepar(' '); |
29 const QChar SpaceSepar(' '); |
|
30 const QChar ZeroSepar('0'); |
|
31 const int NotAssigned = -1; |
31 |
32 |
32 |
33 |
33 // ----------------------------------------------------------------------------- |
34 // ----------------------------------------------------------------------------- |
34 // LogsPredictiveLatin12KeyTranslator::LogsPredictiveLatin12KeyTranslator() |
35 // LogsPredictiveLatin12KeyTranslator::LogsPredictiveLatin12KeyTranslator() |
35 // ----------------------------------------------------------------------------- |
36 // ----------------------------------------------------------------------------- |
92 ~LogsPredictiveLatin12KeyTranslator()" ) |
93 ~LogsPredictiveLatin12KeyTranslator()" ) |
93 |
94 |
94 } |
95 } |
95 |
96 |
96 // ----------------------------------------------------------------------------- |
97 // ----------------------------------------------------------------------------- |
|
98 // LogsPredictiveLatin12KeyTranslator::patternTokens() |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 QStringList LogsPredictiveLatin12KeyTranslator::patternTokens( const QString& pattern ) const |
|
102 { |
|
103 |
|
104 LOGS_QDEBUG( "logs [FINDER] -> LogsPredictiveLatin12KeyTranslator::\ |
|
105 patternTokens()" ) |
|
106 LOGS_QDEBUG_2( "logs [FINDER] pattern ", pattern ); |
|
107 QString car; |
|
108 QString cdr; |
|
109 |
|
110 QStringList target; |
|
111 splitPattern( pattern, car, cdr ); |
|
112 if ( car.length() ) { |
|
113 target.append( car ); |
|
114 if ( cdr.length() ) { |
|
115 target.append( cdr ); |
|
116 } |
|
117 } |
|
118 LOGS_QDEBUG( "logs [FINDER] <- LogsPredictiveLatin12KeyTranslator::\ |
|
119 patternTokens()" ) |
|
120 return target; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // LogsPredictiveLatin12KeyTranslator::splitPattern() |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void LogsPredictiveLatin12KeyTranslator::splitPattern( const QString& pattern, |
|
128 QString& car, QString& cdr ) const |
|
129 { |
|
130 car = ""; |
|
131 cdr = ""; |
|
132 |
|
133 QChar current; |
|
134 QChar previous; |
|
135 int splitStart = NotAssigned; |
|
136 int splitEnd = NotAssigned; |
|
137 int index = 0; |
|
138 while( splitEnd == NotAssigned && index < pattern.length() ) { |
|
139 current = pattern[index]; |
|
140 splitStart = splitStart == NotAssigned && |
|
141 ( previous != ZeroSepar && previous != QChar() ) && |
|
142 current == ZeroSepar ? |
|
143 index : splitStart; |
|
144 splitEnd = splitStart != NotAssigned && |
|
145 previous == ZeroSepar && |
|
146 current != ZeroSepar ? |
|
147 index : splitEnd; |
|
148 previous = current; |
|
149 index++; |
|
150 } |
|
151 |
|
152 if ( splitStart != NotAssigned && splitEnd != NotAssigned ) { |
|
153 car = pattern.left( splitStart ); |
|
154 cdr = pattern.right( pattern.length() - splitEnd ); |
|
155 } else { |
|
156 car = pattern; |
|
157 } |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // LogsPredictiveLatin12KeyTranslator::trimPattern() |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 QString& LogsPredictiveLatin12KeyTranslator::trimPattern( QString& pattern, |
|
165 bool tailOnly ) const |
|
166 { |
|
167 QRegExp lead("^0*");//remove leading zeros |
|
168 QRegExp trail("0*$");//remove trailing zeros |
|
169 |
|
170 if ( pattern.length() ) { |
|
171 if ( !tailOnly ) { |
|
172 pattern.remove( lead ); |
|
173 } |
|
174 |
|
175 pattern.remove( trail ); |
|
176 |
|
177 if( !pattern.length() ) { |
|
178 pattern += ZeroSepar; |
|
179 } |
|
180 } |
|
181 return pattern; |
|
182 } |
|
183 |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // LogsPredictiveLatin12KeyTranslator::hasPatternSeparators() |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 int LogsPredictiveLatin12KeyTranslator::hasPatternSeparators( |
|
190 const QString& pattern ) const |
|
191 { |
|
192 return pattern.count( ZeroSepar ); |
|
193 |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
97 // LogsPredictiveLatin12KeyTranslator::translateChar() |
197 // LogsPredictiveLatin12KeyTranslator::translateChar() |
98 // ----------------------------------------------------------------------------- |
198 // ----------------------------------------------------------------------------- |
99 // |
199 // |
100 const QChar LogsPredictiveLatin12KeyTranslator::translateChar( |
200 const QString LogsPredictiveLatin12KeyTranslator::translateChar( |
101 const QChar character, |
201 const QChar character, |
102 bool& ok ) const |
202 bool& ok ) const |
103 { |
203 { |
104 ok = true; |
204 ok = true; |
105 QChar keycode = mSpecialKeyMap[ character ]; |
205 QChar sch = mSpecialKeyMap[ character ]; |
106 if ( keycode.isNull() ) { |
206 QString keycode( sch ); |
|
207 if ( sch.isNull() ) { |
107 keycode = LogsPredictive12KeyTranslator::translateChar( character ); |
208 keycode = LogsPredictive12KeyTranslator::translateChar( character ); |
108 if ( keycode.isNull() ) { |
209 if ( keycode.isEmpty() ) { |
109 QString decomposed = character.decomposition(); |
210 QString decomposed = character.decomposition(); |
110 if (decomposed.isEmpty()) { |
211 if (decomposed.isEmpty()) { |
111 ok = false; |
212 ok = false; |
112 return keycode; |
213 return keycode; |
113 } |
214 } |