summaryrefslogtreecommitdiff
path: root/noncore/apps/keyz-cfg/zkb.cpp
Unidiff
Diffstat (limited to 'noncore/apps/keyz-cfg/zkb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/keyz-cfg/zkb.cpp716
1 files changed, 358 insertions, 358 deletions
diff --git a/noncore/apps/keyz-cfg/zkb.cpp b/noncore/apps/keyz-cfg/zkb.cpp
index 58bde2a..c9e1dc5 100644
--- a/noncore/apps/keyz-cfg/zkb.cpp
+++ b/noncore/apps/keyz-cfg/zkb.cpp
@@ -1,2 +1,6 @@
1#include "zkb.h" 1#include "zkb.h"
2
3/* OPIE */
4#include <opie2/odebug.h>
5
2#include <stdio.h> 6#include <stdio.h>
@@ -8,3 +12,3 @@ Action::Action():state(0), keycode(0), unicode(0), flags(0) {
8Action::Action(State* s, ushort kc, ushort uni, int f): 12Action::Action(State* s, ushort kc, ushort uni, int f):
9 state(s), keycode(kc), unicode(uni), flags(f) { 13 state(s), keycode(kc), unicode(uni), flags(f) {
10} 14}
@@ -15,3 +19,3 @@ Action::~Action() {
15State* Action::getState() const { 19State* Action::getState() const {
16 return state; 20 return state;
17} 21}
@@ -19,4 +23,4 @@ State* Action::getState() const {
19void Action::setState(State* s) { 23void Action::setState(State* s) {
20 state = s; 24 state = s;
21 setDefined(true); 25 setDefined(true);
22} 26}
@@ -24,3 +28,3 @@ void Action::setState(State* s) {
24bool Action::hasEvent() const { 28bool Action::hasEvent() const {
25 return flags & Event; 29 return flags & Event;
26} 30}
@@ -28,11 +32,11 @@ bool Action::hasEvent() const {
28void Action::setEvent(bool e) { 32void Action::setEvent(bool e) {
29 flags = (flags & ~Event) | ((e) ? Event : 0); 33 flags = (flags & ~Event) | ((e) ? Event : 0);
30 34
31 if (e) { 35 if (e) {
32 setDefined(true); 36 setDefined(true);
33 } else { 37 } else {
34 if (state == 0) { 38 if (state == 0) {
35 setDefined(false); 39 setDefined(false);
36 } 40 }
37 } 41 }
38} 42}
@@ -40,3 +44,3 @@ void Action::setEvent(bool e) {
40bool Action::isDefined() const { 44bool Action::isDefined() const {
41 return flags & Defined; 45 return flags & Defined;
42} 46}
@@ -44,3 +48,3 @@ bool Action::isDefined() const {
44void Action::setDefined(bool d) { 48void Action::setDefined(bool d) {
45 flags = (flags & ~Defined) | ((d) ? Defined : 0); 49 flags = (flags & ~Defined) | ((d) ? Defined : 0);
46} 50}
@@ -48,3 +52,3 @@ void Action::setDefined(bool d) {
48int Action::getKeycode() const { 52int Action::getKeycode() const {
49 return keycode; 53 return keycode;
50} 54}
@@ -52,4 +56,4 @@ int Action::getKeycode() const {
52void Action::setKeycode(int c) { 56void Action::setKeycode(int c) {
53 keycode = (ushort) c; 57 keycode = (ushort) c;
54 setEvent(true); 58 setEvent(true);
55} 59}
@@ -57,3 +61,3 @@ void Action::setKeycode(int c) {
57int Action::getUnicode() const { 61int Action::getUnicode() const {
58 return unicode; 62 return unicode;
59} 63}
@@ -61,4 +65,4 @@ int Action::getUnicode() const {
61void Action::setUnicode(int u) { 65void Action::setUnicode(int u) {
62 unicode = (ushort) u; 66 unicode = (ushort) u;
63 setEvent(true); 67 setEvent(true);
64} 68}
@@ -66,20 +70,20 @@ void Action::setUnicode(int u) {
66int Action::getModifiers() const { 70int Action::getModifiers() const {
67 int ret = 0; 71 int ret = 0;
68 if (flags & Shift_Mod) { 72 if (flags & Shift_Mod) {
69 ret |= Qt::ShiftButton; 73 ret |= Qt::ShiftButton;
70 } 74 }
71 75
72 if (flags & Ctrl_Mod) { 76 if (flags & Ctrl_Mod) {
73 ret |= Qt::ControlButton; 77 ret |= Qt::ControlButton;
74 } 78 }
75 79
76 if (flags & Alt_Mod) { 80 if (flags & Alt_Mod) {
77 ret |= Qt::AltButton; 81 ret |= Qt::AltButton;
78 } 82 }
79 83
80 if (flags & Keypad_Mod) { 84 if (flags & Keypad_Mod) {
81 ret |= Qt::Keypad; 85 ret |= Qt::Keypad;
82 } 86 }
83 87
84 return ret; 88 return ret;
85} 89}
@@ -87,22 +91,22 @@ int Action::getModifiers() const {
87void Action::setModifiers(int m) { 91void Action::setModifiers(int m) {
88 int n = 0; 92 int n = 0;
89 93
90 if (m & Qt::ShiftButton) { 94 if (m & Qt::ShiftButton) {
91 n |= Shift_Mod; 95 n |= Shift_Mod;
92 } 96 }
93 97
94 if (m & Qt::ControlButton) { 98 if (m & Qt::ControlButton) {
95 n |= Ctrl_Mod; 99 n |= Ctrl_Mod;
96 } 100 }
97 101
98 if (m & Qt::AltButton) { 102 if (m & Qt::AltButton) {
99 n |= Alt_Mod; 103 n |= Alt_Mod;
100 } 104 }
101 105
102 if (m & Qt::Keypad) { 106 if (m & Qt::Keypad) {
103 n |= Keypad_Mod; 107 n |= Keypad_Mod;
104 } 108 }
105 109
106 flags = flags & ~Mod_Bits | n; 110 flags = flags & ~Mod_Bits | n;
107 setEvent(true); 111 setEvent(true);
108} 112}
@@ -110,3 +114,3 @@ void Action::setModifiers(int m) {
110bool Action::isPressed() const { 114bool Action::isPressed() const {
111 return (flags & Press) != 0; 115 return (flags & Press) != 0;
112} 116}
@@ -114,4 +118,4 @@ bool Action::isPressed() const {
114void Action::setPressed(bool p) { 118void Action::setPressed(bool p) {
115 flags = (flags & ~Press) | ((p) ? Press : 0); 119 flags = (flags & ~Press) | ((p) ? Press : 0);
116 setEvent(true); 120 setEvent(true);
117} 121}
@@ -119,3 +123,3 @@ void Action::setPressed(bool p) {
119bool Action::isAutorepeat() const { 123bool Action::isAutorepeat() const {
120 return (flags & Autorepeat) != 0; 124 return (flags & Autorepeat) != 0;
121} 125}
@@ -123,4 +127,4 @@ bool Action::isAutorepeat() const {
123void Action::setAutorepeat(bool p) { 127void Action::setAutorepeat(bool p) {
124 flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); 128 flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0);
125 setEvent(true); 129 setEvent(true);
126} 130}
@@ -129,14 +133,14 @@ void Action::setAutorepeat(bool p) {
129const short State::x1[] = { /* from 0x20 to 0x5f */ 133const short State::x1[] = { /* from 0x20 to 0x5f */
130 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ 134 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */
131 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ 135 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */
132 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ 136 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */
133 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ 137 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */
134 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ 138 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */
135 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ 139 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */
136 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ 140 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */
137 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ 141 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */
138 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ 142 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */
139 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ 143 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */
140 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ 144 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */
141 -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ 145 -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */
142}; 146};
@@ -144,17 +148,17 @@ const short State::x1[] = { /* from 0x20 to 0x5f */
144const short State::x2[] = { /* from 0x1000 to 0x1057*/ 148const short State::x2[] = { /* from 0x1000 to 0x1057*/
145 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ 149 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */
146 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ 150 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */
147 -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ 151 -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */
148 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ 152 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */
149 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ 153 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */
150 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ 154 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */
151 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ 155 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */
152 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ 156 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */
153 -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ 157 -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */
154 -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ 158 -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */
155 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ 159 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */
156}; 160};
157 161
158State::State(State* p):parent(p), keys(0) { 162State::State(State* p):parent(p), keys(0) {
159 keys = new Action[Key_Max * 2 + 1]; 163 keys = new Action[Key_Max * 2 + 1];
160} 164}
@@ -162,5 +166,5 @@ State::State(State* p):parent(p), keys(0) {
162State::State(const State& s) { 166State::State(const State& s) {
163 parent = s.parent; 167 parent = s.parent;
164 keys = new Action[Key_Max * 2 + 1]; 168 keys = new Action[Key_Max * 2 + 1];
165 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); 169 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1));
166} 170}
@@ -168,5 +172,5 @@ State::State(const State& s) {
168State::~State() { 172State::~State() {
169 if (keys!=0) { 173 if (keys!=0) {
170 delete [] keys; 174 delete [] keys;
171 } 175 }
172} 176}
@@ -174,19 +178,19 @@ State::~State() {
174Action* State::get(int keycode, bool pressed, bool follow) const { 178Action* State::get(int keycode, bool pressed, bool follow) const {
175 Action* ret = 0; 179 Action* ret = 0;
176 int n = translateKeycode(keycode); 180 int n = translateKeycode(keycode);
177 181
178 if (n != -1 && keys != 0) { 182 if (n != -1 && keys != 0) {
179 if (pressed) { 183 if (pressed) {
180 n += Key_Max; 184 n += Key_Max;
181 } 185 }
182 ret = &keys[n]; 186 ret = &keys[n];
183 } 187 }
184 188
185 if (ret==0 || !ret->isDefined()) { 189 if (ret==0 || !ret->isDefined()) {
186 if (follow && parent!=0) { 190 if (follow && parent!=0) {
187 ret = parent->get(keycode, pressed, follow); 191 ret = parent->get(keycode, pressed, follow);
188 } 192 }
189 } 193 }
190 194
191 return ret; 195 return ret;
192} 196}
@@ -194,14 +198,14 @@ Action* State::get(int keycode, bool pressed, bool follow) const {
194bool State::set(int keycode, bool pressed, Action& action) { 198bool State::set(int keycode, bool pressed, Action& action) {
195 int n = translateKeycode(keycode); 199 int n = translateKeycode(keycode);
196 200
197 if (n==-1 || keys==0) { 201 if (n==-1 || keys==0) {
198 return false; 202 return false;
199 } 203 }
200 204
201 if (pressed) { 205 if (pressed) {
202 n += Key_Max + 1; 206 n += Key_Max + 1;
203 } 207 }
204 208
205 keys[n] = action; 209 keys[n] = action;
206 return true; 210 return true;
207} 211}
@@ -209,3 +213,3 @@ bool State::set(int keycode, bool pressed, Action& action) {
209State* State::getParent() const { 213State* State::getParent() const {
210 return parent; 214 return parent;
211} 215}
@@ -213,3 +217,3 @@ State* State::getParent() const {
213void State::setParent(State* s) { 217void State::setParent(State* s) {
214 parent = s; 218 parent = s;
215} 219}
@@ -217,19 +221,19 @@ void State::setParent(State* s) {
217int State::translateKeycode(int keycode) const { 221int State::translateKeycode(int keycode) const {
218 if (keycode < 0x20) { 222 if (keycode < 0x20) {
219 return -1; 223 return -1;
220 } 224 }
221 225
222 if (keycode < 0x80) { 226 if (keycode < 0x80) {
223 return x1[keycode - 0x20]; 227 return x1[keycode - 0x20];
224 } 228 }
225 229
226 if (keycode < 0x1000) { 230 if (keycode < 0x1000) {
227 return -1; 231 return -1;
228 } 232 }
229 233
230 if (keycode < 0x1057) { 234 if (keycode < 0x1057) {
231 return x2[keycode - 0x1000]; 235 return x2[keycode - 0x1000];
232 } 236 }
233 237
234 return -1; 238 return -1;
235} 239}
@@ -238,5 +242,5 @@ int State::translateKeycode(int keycode) const {
238Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { 242Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
239 repeatDelay=400; 243 repeatDelay=400;
240 repeatPeriod=80; 244 repeatPeriod=80;
241 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); 245 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
242} 246}
@@ -244,7 +248,7 @@ Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(t
244Keymap::~Keymap() { 248Keymap::~Keymap() {
245 QMap<QString, State*>::Iterator it; 249 QMap<QString, State*>::Iterator it;
246 for(it = states.begin(); it != states.end(); ++it) { 250 for(it = states.begin(); it != states.end(); ++it) {
247 delete it.data(); 251 delete it.data();
248 } 252 }
249 states.clear(); 253 states.clear();
250} 254}
@@ -252,55 +256,53 @@ Keymap::~Keymap() {
252bool Keymap::filter(int unicode, int keycode, int modifiers, 256bool Keymap::filter(int unicode, int keycode, int modifiers,
253 bool isPress, bool autoRepeat) { 257 bool isPress, bool autoRepeat) {
254 258
255 qDebug("filter: >>> unicode=%x, keycode=%x, modifiers=%x, " 259 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
256 "ispressed=%x\n", unicode, keycode, modifiers, isPress); 260 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
257 261
258 if (!enabled) { 262 if (!enabled) {
259 return false; 263 return false;
260 } 264 }
261 265
262 // the second check is workaround to make suspend work if 266 // the second check is workaround to make suspend work if
263 // the user pressed it right after he did resume. for some 267 // the user pressed it right after he did resume. for some
264 // reason the event sent by qt has autoRepeat true in this 268 // reason the event sent by qt has autoRepeat true in this
265 // case 269 // case
266 if (autoRepeat && keycode != 4177) { 270 if (autoRepeat && keycode != 4177) {
267 return true; 271 return true;
268 } 272 }
269 273
270 (void) unicode; (void) modifiers; 274 (void) unicode; (void) modifiers;
271 275
272 Action* action = currentState->get(keycode, isPress, true); 276 Action* action = currentState->get(keycode, isPress, true);
273 if (action==0 || !action->isDefined()) { 277 if (action==0 || !action->isDefined()) {
274 return true; 278 return true;
275 } 279 }
276 280
277 if (action->hasEvent()) { 281 if (action->hasEvent()) {
278 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " 282 odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode()
279 "ispressed=%x\n", action->getUnicode(), 283 << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl;
280 action->getKeycode(), action->getModifiers(),
281 action->isPressed());
282 284
283 QWSServer::sendKeyEvent(action->getUnicode(), 285 QWSServer::sendKeyEvent(action->getUnicode(),
284 action->getKeycode(), action->getModifiers(), 286 action->getKeycode(), action->getModifiers(),
285 action->isPressed(), false); 287 action->isPressed(), false);
286 } 288 }
287 289
288 if (action->isAutorepeat()) { 290 if (action->isAutorepeat()) {
289 autoRepeatAction = action; 291 autoRepeatAction = action;
290 repeater.start(repeatDelay, TRUE); 292 repeater.start(repeatDelay, TRUE);
291 } else { 293 } else {
292 autoRepeatAction = 0; 294 autoRepeatAction = 0;
293 } 295 }
294 296
295 State* nstate = action->getState(); 297 State* nstate = action->getState();
296 if (nstate != 0) { 298 if (nstate != 0) {
297 setCurrentState(nstate); 299 setCurrentState(nstate);
298 QString lbl = getCurrentLabel(); 300 QString lbl = getCurrentLabel();
299 if (!lbl.isEmpty()) { 301 if (!lbl.isEmpty()) {
300 emit stateChanged(lbl); 302 emit stateChanged(lbl);
301 } 303 }
302 } 304 }
303 305
304 306
305 return true; 307 return true;
306} 308}
@@ -308,3 +310,3 @@ bool Keymap::filter(int unicode, int keycode, int modifiers,
308void Keymap::enable() { 310void Keymap::enable() {
309 enabled = true; 311 enabled = true;
310} 312}
@@ -312,3 +314,3 @@ void Keymap::enable() {
312void Keymap::disable() { 314void Keymap::disable() {
313 enabled = false; 315 enabled = false;
314} 316}
@@ -316,10 +318,10 @@ void Keymap::disable() {
316QStringList Keymap::listStates() { 318QStringList Keymap::listStates() {
317 QStringList ret; 319 QStringList ret;
318 320
319 QMap<QString, State*>::Iterator it; 321 QMap<QString, State*>::Iterator it;
320 for(it = states.begin(); it != states.end(); ++it) { 322 for(it = states.begin(); it != states.end(); ++it) {
321 ret.append(it.key()); 323 ret.append(it.key());
322 } 324 }
323 325
324 return ret; 326 return ret;
325} 327}
@@ -327,9 +329,9 @@ QStringList Keymap::listStates() {
327State* Keymap::getStateByName(const QString& name) { 329State* Keymap::getStateByName(const QString& name) {
328 QMap<QString, State*>::Iterator it = states.find(name); 330 QMap<QString, State*>::Iterator it = states.find(name);
329 331
330 if (it == states.end()) { 332 if (it == states.end()) {
331 return 0; 333 return 0;
332 } 334 }
333 335
334 return it.data(); 336 return it.data();
335} 337}
@@ -337,9 +339,9 @@ State* Keymap::getStateByName(const QString& name) {
337QStringList Keymap::listLabels() { 339QStringList Keymap::listLabels() {
338 QStringList ret; 340 QStringList ret;
339 341
340 for(uint i = 0; i < labelList.count(); i++) { 342 for(uint i = 0; i < labelList.count(); i++) {
341 ret.append(*labelList.at(i)); 343 ret.append(*labelList.at(i));
342 } 344 }
343 345
344 return ret; 346 return ret;
345} 347}
@@ -347,28 +349,28 @@ QStringList Keymap::listLabels() {
347State* Keymap::getStateByLabel(const QString& label) { 349State* Keymap::getStateByLabel(const QString& label) {
348 QMap<QString, QString>::Iterator lit = labels.find(label); 350 QMap<QString, QString>::Iterator lit = labels.find(label);
349 State* state = 0; 351 State* state = 0;
350 352
351 if (lit == labels.end()) { 353 if (lit == labels.end()) {
352 return 0; 354 return 0;
353 } 355 }
354 356
355 QString name = lit.data(); 357 QString name = lit.data();
356 358
357 int n = name.find(":*"); 359 int n = name.find(":*");
358 if (n>=0 && n==(int)(name.length()-2)) { 360 if (n>=0 && n==(int)(name.length()-2)) {
359 name=name.left(name.length() - 1); 361 name=name.left(name.length() - 1);
360 362
361 n = currentStateName.findRev(":"); 363 n = currentStateName.findRev(":");
362 if (n >= 0) { 364 if (n >= 0) {
363 name += currentStateName.mid(n+1); 365 name += currentStateName.mid(n+1);
364 } 366 }
365 } 367 }
366 368
367 //odebug << "look for: " << name.utf8() << "\n" << oendl; 369// odebug << "look for: " << name.utf8() << "\n" << oendl;
368 QMap<QString, State*>::Iterator sit = states.find(name); 370 QMap<QString, State*>::Iterator sit = states.find(name);
369 if (sit != states.end()) { 371 if (sit != states.end()) {
370 state = sit.data(); 372 state = sit.data();
371 } 373 }
372 374
373 return state; 375 return state;
374} 376}
@@ -376,14 +378,14 @@ State* Keymap::getStateByLabel(const QString& label) {
376bool Keymap::addState(const QString& name, State* state) { 378bool Keymap::addState(const QString& name, State* state) {
377 if (states.find(name) != states.end()) { 379 if (states.find(name) != states.end()) {
378 return false; 380 return false;
379 } 381 }
380 382
381 states.insert(name, state); 383 states.insert(name, state);
382 lsmapInSync = false; 384 lsmapInSync = false;
383 385
384 if (currentState == 0) { 386 if (currentState == 0) {
385 setCurrentState(state); 387 setCurrentState(state);
386 } 388 }
387 389
388 return true; 390 return true;
389} 391}
@@ -391,3 +393,3 @@ bool Keymap::addState(const QString& name, State* state) {
391State* Keymap::getCurrentState() const { 393State* Keymap::getCurrentState() const {
392 return currentState; 394 return currentState;
393} 395}
@@ -395,3 +397,3 @@ State* Keymap::getCurrentState() const {
395QString Keymap::getCurrentLabel() { 397QString Keymap::getCurrentLabel() {
396 return currentLabel; 398 return currentLabel;
397} 399}
@@ -399,30 +401,29 @@ QString Keymap::getCurrentLabel() {
399bool Keymap::setCurrentState(State* state) { 401bool Keymap::setCurrentState(State* state) {
400 QMap<QString, State*>::Iterator it; 402 QMap<QString, State*>::Iterator it;
401 for(it = states.begin(); it != states.end(); ++it) { 403 for(it = states.begin(); it != states.end(); ++it) {
402 State* s = it.data(); 404 State* s = it.data();
403 if (s == state) { 405 if (s == state) {
404 currentState = s; 406 currentState = s;
405 currentStateName = it.key(); 407 currentStateName = it.key();
406 408
407 qDebug("state changed: %s\n", (const char*) 409 odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl;
408 currentStateName.utf8());
409 410
410 if (!lsmapInSync) { 411 if (!lsmapInSync) {
411 generateLabelStateMaps(); 412 generateLabelStateMaps();
412 } 413 }
413 414
414 QMap<State*, QString>::Iterator tit; 415 QMap<State*, QString>::Iterator tit;
415 tit = stateLabelMap.find(state); 416 tit = stateLabelMap.find(state);
416 if (tit != stateLabelMap.end()) { 417 if (tit != stateLabelMap.end()) {
417 currentLabel = tit.data(); 418 currentLabel = tit.data();
418 } else { 419 } else {
419 // odebug << "no label for: " + currentStateName + "\n" << oendl; 420// odebug << "no label for: " + currentStateName + "\n" << oendl;
420 currentLabel = ""; 421 currentLabel = "";
421 } 422 }
422 423
423 return true; 424 return true;
424 } 425 }
425 } 426 }
426 427
427 return false; 428 return false;
428} 429}
@@ -430,33 +431,33 @@ bool Keymap::setCurrentState(State* state) {
430bool Keymap::removeState(const QString& name, bool force) { 431bool Keymap::removeState(const QString& name, bool force) {
431 QMap<QString, State*>::Iterator it = states.find(name); 432 QMap<QString, State*>::Iterator it = states.find(name);
432 433
433 if (it == states.end()) { 434 if (it == states.end()) {
434 return false; 435 return false;
435 } 436 }
436 437
437 State* state = it.data(); 438 State* state = it.data();
438 QList<Action> acts = findStateUsage(state); 439 QList<Action> acts = findStateUsage(state);
439 440
440 if (!acts.isEmpty()) { 441 if (!acts.isEmpty()) {
441 if (!force) { 442 if (!force) {
442 return false; 443 return false;
443 } else { 444 } else {
444 for(Action* a = acts.first(); a != 0; a = acts.next()) { 445 for(Action* a = acts.first(); a != 0; a = acts.next()) {
445 a->setState(0); 446 a->setState(0);
446 } 447 }
447 } 448 }
448 } 449 }
449 450
450 if (state == currentState) { 451 if (state == currentState) {
451 if (states.begin() != states.end()) { 452 if (states.begin() != states.end()) {
452 setCurrentState(states.begin().data()); 453 setCurrentState(states.begin().data());
453 } 454 }
454 } 455 }
455 456
456 states.remove(it); 457 states.remove(it);
457 delete state; 458 delete state;
458 459
459 lsmapInSync = false; 460 lsmapInSync = false;
460 461
461 return true; 462 return true;
462} 463}
@@ -464,16 +465,15 @@ bool Keymap::removeState(const QString& name, bool force) {
464void Keymap::autoRepeat() { 465void Keymap::autoRepeat() {
465 if (autoRepeatAction != 0) { 466 if (autoRepeatAction != 0) {
466 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " 467 odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode()
467 "ispressed=%x\n", autoRepeatAction->getUnicode(), 468 << ", keycode=" << autoRepeatAction->getKeycode()
468 autoRepeatAction->getKeycode(), 469 << ", modifiers=" << autoRepeatAction->getModifiers()
469 autoRepeatAction->getModifiers(), 470 << "ispressed=" << autoRepeatAction->isPressed() << oendl;
470 autoRepeatAction->isPressed());
471 471
472 QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), 472 QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(),
473 autoRepeatAction->getKeycode(), 473 autoRepeatAction->getKeycode(),
474 autoRepeatAction->getModifiers(), 474 autoRepeatAction->getModifiers(),
475 autoRepeatAction->isPressed(), true); 475 autoRepeatAction->isPressed(), true);
476 } 476 }
477 477
478 repeater.start(repeatPeriod, TRUE); 478 repeater.start(repeatPeriod, TRUE);
479} 479}
@@ -481,17 +481,17 @@ void Keymap::autoRepeat() {
481bool Keymap::addLabel(const QString& label, const QString& state, int index) { 481bool Keymap::addLabel(const QString& label, const QString& state, int index) {
482 if (labels.find(label) != labels.end()) { 482 if (labels.find(label) != labels.end()) {
483 return false; 483 return false;
484 } 484 }
485 485
486 labels.insert(label, state); 486 labels.insert(label, state);
487 const QString& l = labels.find(label).key(); 487 const QString& l = labels.find(label).key();
488 if (index == -1) { 488 if (index == -1) {
489 labelList.append(l); 489 labelList.append(l);
490 } else { 490 } else {
491 labelList.insert(labelList.at(index), l); 491 labelList.insert(labelList.at(index), l);
492 } 492 }
493 493
494 lsmapInSync = false; 494 lsmapInSync = false;
495 495
496 return true; 496 return true;
497} 497}
@@ -500,15 +500,15 @@ bool Keymap::removeLabel(const QString& label) {
500 500
501 if (labels.find(label) == labels.end()) { 501 if (labels.find(label) == labels.end()) {
502 return false; 502 return false;
503 } 503 }
504 504
505 labels.remove(label); 505 labels.remove(label);
506 labelList.remove(label); 506 labelList.remove(label);
507 lsmapInSync = false; 507 lsmapInSync = false;
508 508
509 if (label == currentLabel) { 509 if (label == currentLabel) {
510 currentLabel = ""; 510 currentLabel = "";
511 } 511 }
512 512
513 return true; 513 return true;
514} 514}
@@ -516,3 +516,3 @@ bool Keymap::removeLabel(const QString& label) {
516int Keymap::getAutorepeatDelay() const { 516int Keymap::getAutorepeatDelay() const {
517 return repeatDelay; 517 return repeatDelay;
518} 518}
@@ -520,3 +520,3 @@ int Keymap::getAutorepeatDelay() const {
520void Keymap::setAutorepeatDelay(int n) { 520void Keymap::setAutorepeatDelay(int n) {
521 repeatDelay = n; 521 repeatDelay = n;
522} 522}
@@ -524,3 +524,3 @@ void Keymap::setAutorepeatDelay(int n) {
524int Keymap::getAutorepeatPeriod() const { 524int Keymap::getAutorepeatPeriod() const {
525 return repeatPeriod; 525 return repeatPeriod;
526} 526}
@@ -528,3 +528,3 @@ int Keymap::getAutorepeatPeriod() const {
528void Keymap::setAutorepeatPeriod(int n) { 528void Keymap::setAutorepeatPeriod(int n) {
529 repeatPeriod = n; 529 repeatPeriod = n;
530} 530}
@@ -532,22 +532,22 @@ void Keymap::setAutorepeatPeriod(int n) {
532QList<Action> Keymap::findStateUsage(State* s) { 532QList<Action> Keymap::findStateUsage(State* s) {
533 QList<Action> ret; 533 QList<Action> ret;
534 534
535 QMap<QString, State*>::Iterator it; 535 QMap<QString, State*>::Iterator it;
536 for(it = states.begin(); it != states.end(); ++it) { 536 for(it = states.begin(); it != states.end(); ++it) {
537 State* state = it.data(); 537 State* state = it.data();
538 538
539 for(int i = 0; i < 0x1100; i++) { 539 for(int i = 0; i < 0x1100; i++) {
540 Action* action = state->get(i, false); 540 Action* action = state->get(i, false);
541 if (action!=0 && action->getState()==s) { 541 if (action!=0 && action->getState()==s) {
542 ret.append(action); 542 ret.append(action);
543 } 543 }
544 544
545 action = state->get(i, true); 545 action = state->get(i, true);
546 if (action!=0 && action->getState()==s) { 546 if (action!=0 && action->getState()==s) {
547 ret.append(action); 547 ret.append(action);
548 } 548 }
549 } 549 }
550 } 550 }
551 551
552 return ret; 552 return ret;
553} 553}
@@ -555,35 +555,35 @@ QList<Action> Keymap::findStateUsage(State* s) {
555void Keymap::generateLabelStateMaps() { 555void Keymap::generateLabelStateMaps() {
556 stateLabelMap.clear(); 556 stateLabelMap.clear();
557 557
558 QMap<QString, QString>::Iterator lit; 558 QMap<QString, QString>::Iterator lit;
559 for(lit = labels.begin(); lit != labels.end(); ++lit) { 559 for(lit = labels.begin(); lit != labels.end(); ++lit) {
560 QString label = lit.key(); 560 QString label = lit.key();
561 QString name = lit.data(); 561 QString name = lit.data();
562 562
563 bool wc = false; 563 bool wc = false;
564 int n = name.find("*"); 564 int n = name.find("*");
565 if (n>=0 && n==(int)(name.length()-1)) { 565 if (n>=0 && n==(int)(name.length()-1)) {
566 name=name.left(name.length() - 1); 566 name=name.left(name.length() - 1);
567 wc = true; 567 wc = true;
568 } 568 }
569 569
570 QMap<QString, State*>::Iterator sit; 570 QMap<QString, State*>::Iterator sit;
571 for(sit = states.begin(); sit != states.end(); ++sit) { 571 for(sit = states.begin(); sit != states.end(); ++sit) {
572 QString sname = sit.key(); 572 QString sname = sit.key();
573 State* state = sit.data(); 573 State* state = sit.data();
574 574
575 if (sname.length() < name.length()) { 575 if (sname.length() < name.length()) {
576 continue; 576 continue;
577 } 577 }
578 578
579 if (sname.left(name.length()) == name) { 579 if (sname.left(name.length()) == name) {
580 if (wc || sname.length()==name.length()) { 580 if (wc || sname.length()==name.length()) {
581 stateLabelMap.insert(state, label); 581 stateLabelMap.insert(state, label);
582 } 582 }
583 583
584 } 584 }
585 } 585 }
586 } 586 }
587 587
588 lsmapInSync = true; 588 lsmapInSync = true;
589} 589}