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