author | ar <ar> | 2004-05-27 22:04:46 (UTC) |
---|---|---|
committer | ar <ar> | 2004-05-27 22:04:46 (UTC) |
commit | 4f7c3c4d0d634706d13950b3827714b168e279e3 (patch) (unidiff) | |
tree | 2df448e7a4dcd538c26365873e194be2b55e83b7 /noncore/apps/keyz-cfg | |
parent | 46f81a089ba8febdb79e0d150b69f74bb1ea7d18 (diff) | |
download | opie-4f7c3c4d0d634706d13950b3827714b168e279e3.zip opie-4f7c3c4d0d634706d13950b3827714b168e279e3.tar.gz opie-4f7c3c4d0d634706d13950b3827714b168e279e3.tar.bz2 |
- convert qDebug to odebug
-rw-r--r-- | noncore/apps/keyz-cfg/zkb.cpp | 716 |
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,589 +1,589 @@ | |||
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> |
3 | 7 | ||
4 | // Implementation of Action class | 8 | // Implementation of Action class |
5 | Action::Action():state(0), keycode(0), unicode(0), flags(0) { | 9 | Action::Action():state(0), keycode(0), unicode(0), flags(0) { |
6 | } | 10 | } |
7 | 11 | ||
8 | Action::Action(State* s, ushort kc, ushort uni, int f): | 12 | Action::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 | } |
11 | 15 | ||
12 | Action::~Action() { | 16 | Action::~Action() { |
13 | } | 17 | } |
14 | 18 | ||
15 | State* Action::getState() const { | 19 | State* Action::getState() const { |
16 | return state; | 20 | return state; |
17 | } | 21 | } |
18 | 22 | ||
19 | void Action::setState(State* s) { | 23 | void Action::setState(State* s) { |
20 | state = s; | 24 | state = s; |
21 | setDefined(true); | 25 | setDefined(true); |
22 | } | 26 | } |
23 | 27 | ||
24 | bool Action::hasEvent() const { | 28 | bool Action::hasEvent() const { |
25 | return flags & Event; | 29 | return flags & Event; |
26 | } | 30 | } |
27 | 31 | ||
28 | void Action::setEvent(bool e) { | 32 | void 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 | } |
39 | 43 | ||
40 | bool Action::isDefined() const { | 44 | bool Action::isDefined() const { |
41 | return flags & Defined; | 45 | return flags & Defined; |
42 | } | 46 | } |
43 | 47 | ||
44 | void Action::setDefined(bool d) { | 48 | void Action::setDefined(bool d) { |
45 | flags = (flags & ~Defined) | ((d) ? Defined : 0); | 49 | flags = (flags & ~Defined) | ((d) ? Defined : 0); |
46 | } | 50 | } |
47 | 51 | ||
48 | int Action::getKeycode() const { | 52 | int Action::getKeycode() const { |
49 | return keycode; | 53 | return keycode; |
50 | } | 54 | } |
51 | 55 | ||
52 | void Action::setKeycode(int c) { | 56 | void Action::setKeycode(int c) { |
53 | keycode = (ushort) c; | 57 | keycode = (ushort) c; |
54 | setEvent(true); | 58 | setEvent(true); |
55 | } | 59 | } |
56 | 60 | ||
57 | int Action::getUnicode() const { | 61 | int Action::getUnicode() const { |
58 | return unicode; | 62 | return unicode; |
59 | } | 63 | } |
60 | 64 | ||
61 | void Action::setUnicode(int u) { | 65 | void Action::setUnicode(int u) { |
62 | unicode = (ushort) u; | 66 | unicode = (ushort) u; |
63 | setEvent(true); | 67 | setEvent(true); |
64 | } | 68 | } |
65 | 69 | ||
66 | int Action::getModifiers() const { | 70 | int 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 | } |
86 | 90 | ||
87 | void Action::setModifiers(int m) { | 91 | void 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 | } |
109 | 113 | ||
110 | bool Action::isPressed() const { | 114 | bool Action::isPressed() const { |
111 | return (flags & Press) != 0; | 115 | return (flags & Press) != 0; |
112 | } | 116 | } |
113 | 117 | ||
114 | void Action::setPressed(bool p) { | 118 | void 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 | } |
118 | 122 | ||
119 | bool Action::isAutorepeat() const { | 123 | bool Action::isAutorepeat() const { |
120 | return (flags & Autorepeat) != 0; | 124 | return (flags & Autorepeat) != 0; |
121 | } | 125 | } |
122 | 126 | ||
123 | void Action::setAutorepeat(bool p) { | 127 | void 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 | } |
127 | 131 | ||
128 | // Implementation of State class | 132 | // Implementation of State class |
129 | const short State::x1[] = { /* from 0x20 to 0x5f */ | 133 | const 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 | }; |
143 | 147 | ||
144 | const short State::x2[] = { /* from 0x1000 to 0x1057*/ | 148 | const 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 | ||
158 | State::State(State* p):parent(p), keys(0) { | 162 | State::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 | } |
161 | 165 | ||
162 | State::State(const State& s) { | 166 | State::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 | } |
167 | 171 | ||
168 | State::~State() { | 172 | State::~State() { |
169 | if (keys!=0) { | 173 | if (keys!=0) { |
170 | delete [] keys; | 174 | delete [] keys; |
171 | } | 175 | } |
172 | } | 176 | } |
173 | 177 | ||
174 | Action* State::get(int keycode, bool pressed, bool follow) const { | 178 | Action* 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 | } |
193 | 197 | ||
194 | bool State::set(int keycode, bool pressed, Action& action) { | 198 | bool 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 | } |
208 | 212 | ||
209 | State* State::getParent() const { | 213 | State* State::getParent() const { |
210 | return parent; | 214 | return parent; |
211 | } | 215 | } |
212 | 216 | ||
213 | void State::setParent(State* s) { | 217 | void State::setParent(State* s) { |
214 | parent = s; | 218 | parent = s; |
215 | } | 219 | } |
216 | 220 | ||
217 | int State::translateKeycode(int keycode) const { | 221 | int 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 | } |
236 | 240 | ||
237 | // Implementation of Keymap class | 241 | // Implementation of Keymap class |
238 | Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { | 242 | Keymap::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 | } |
243 | 247 | ||
244 | Keymap::~Keymap() { | 248 | Keymap::~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 | } |
251 | 255 | ||
252 | bool Keymap::filter(int unicode, int keycode, int modifiers, | 256 | bool 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 | } |
307 | 309 | ||
308 | void Keymap::enable() { | 310 | void Keymap::enable() { |
309 | enabled = true; | 311 | enabled = true; |
310 | } | 312 | } |
311 | 313 | ||
312 | void Keymap::disable() { | 314 | void Keymap::disable() { |
313 | enabled = false; | 315 | enabled = false; |
314 | } | 316 | } |
315 | 317 | ||
316 | QStringList Keymap::listStates() { | 318 | QStringList 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 | } |
326 | 328 | ||
327 | State* Keymap::getStateByName(const QString& name) { | 329 | State* 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 | } |
336 | 338 | ||
337 | QStringList Keymap::listLabels() { | 339 | QStringList 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 | } |
346 | 348 | ||
347 | State* Keymap::getStateByLabel(const QString& label) { | 349 | State* 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 | } |
375 | 377 | ||
376 | bool Keymap::addState(const QString& name, State* state) { | 378 | bool 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 | } |
390 | 392 | ||
391 | State* Keymap::getCurrentState() const { | 393 | State* Keymap::getCurrentState() const { |
392 | return currentState; | 394 | return currentState; |
393 | } | 395 | } |
394 | 396 | ||
395 | QString Keymap::getCurrentLabel() { | 397 | QString Keymap::getCurrentLabel() { |
396 | return currentLabel; | 398 | return currentLabel; |
397 | } | 399 | } |
398 | 400 | ||
399 | bool Keymap::setCurrentState(State* state) { | 401 | bool 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 | } |
429 | 430 | ||
430 | bool Keymap::removeState(const QString& name, bool force) { | 431 | bool 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 | } |
463 | 464 | ||
464 | void Keymap::autoRepeat() { | 465 | void 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 | } |
480 | 480 | ||
481 | bool Keymap::addLabel(const QString& label, const QString& state, int index) { | 481 | bool 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 | } |
498 | 498 | ||
499 | bool Keymap::removeLabel(const QString& label) { | 499 | 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 | } |
515 | 515 | ||
516 | int Keymap::getAutorepeatDelay() const { | 516 | int Keymap::getAutorepeatDelay() const { |
517 | return repeatDelay; | 517 | return repeatDelay; |
518 | } | 518 | } |
519 | 519 | ||
520 | void Keymap::setAutorepeatDelay(int n) { | 520 | void Keymap::setAutorepeatDelay(int n) { |
521 | repeatDelay = n; | 521 | repeatDelay = n; |
522 | } | 522 | } |
523 | 523 | ||
524 | int Keymap::getAutorepeatPeriod() const { | 524 | int Keymap::getAutorepeatPeriod() const { |
525 | return repeatPeriod; | 525 | return repeatPeriod; |
526 | } | 526 | } |
527 | 527 | ||
528 | void Keymap::setAutorepeatPeriod(int n) { | 528 | void Keymap::setAutorepeatPeriod(int n) { |
529 | repeatPeriod = n; | 529 | repeatPeriod = n; |
530 | } | 530 | } |
531 | 531 | ||
532 | QList<Action> Keymap::findStateUsage(State* s) { | 532 | QList<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 | } |
554 | 554 | ||
555 | void Keymap::generateLabelStateMaps() { | 555 | void 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 | } |