Diffstat (limited to 'noncore/apps/keyz-cfg/zkbcfg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/keyz-cfg/zkbcfg.cpp | 231 |
1 files changed, 0 insertions, 231 deletions
diff --git a/noncore/apps/keyz-cfg/zkbcfg.cpp b/noncore/apps/keyz-cfg/zkbcfg.cpp deleted file mode 100644 index 24bd897..0000000 --- a/noncore/apps/keyz-cfg/zkbcfg.cpp +++ b/dev/null | |||
@@ -1,231 +0,0 @@ | |||
1 | #include "zkbcfg.h" | ||
2 | |||
3 | /* OPIE */ | ||
4 | #include <opie2/odebug.h> | ||
5 | using namespace Opie::Core; | ||
6 | |||
7 | /* QT */ | ||
8 | #include <qfileinfo.h> | ||
9 | |||
10 | // Implementation of XkbConfig class | ||
11 | ZkbConfig::ZkbConfig(const QString& dir):path(dir) { | ||
12 | } | ||
13 | |||
14 | ZkbConfig::~ZkbConfig() { | ||
15 | } | ||
16 | |||
17 | bool ZkbConfig::load(const QString& file, Keymap& keymap, const QString& prefix) { | ||
18 | bool ret; | ||
19 | QFile f(path+"/"+file); | ||
20 | QFileInfo fi(f); | ||
21 | |||
22 | odebug << "start loading file=" << file.utf8() << "\n" << oendl; | ||
23 | if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) { | ||
24 | return false; | ||
25 | } | ||
26 | |||
27 | includedFiles.insert(fi.absFilePath(), 1); | ||
28 | QXmlInputSource is(f); | ||
29 | QXmlSimpleReader reader; | ||
30 | ZkbHandler h(*this, keymap, prefix); | ||
31 | |||
32 | reader.setContentHandler(&h); | ||
33 | reader.setErrorHandler(this); | ||
34 | ret = reader.parse(is); | ||
35 | includedFiles.remove(fi.absFilePath()); | ||
36 | |||
37 | odebug << "end loading file=" << file.utf8() << ": status=" << err.utf8() << oendl; | ||
38 | return ret; | ||
39 | } | ||
40 | |||
41 | bool ZkbConfig::warning(const QXmlParseException& e) { | ||
42 | QString tmp; | ||
43 | |||
44 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), | ||
45 | (const char*) e.message().utf8()); | ||
46 | |||
47 | err += tmp; | ||
48 | |||
49 | return true; | ||
50 | } | ||
51 | |||
52 | bool ZkbConfig::error(const QXmlParseException& e) { | ||
53 | QString tmp; | ||
54 | |||
55 | tmp.sprintf("%d: error: %s\n", e.lineNumber(), | ||
56 | (const char*) e.message().utf8()); | ||
57 | |||
58 | err += tmp; | ||
59 | |||
60 | return true; | ||
61 | } | ||
62 | |||
63 | bool ZkbConfig::fatalError(const QXmlParseException& e) { | ||
64 | QString tmp; | ||
65 | |||
66 | tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), | ||
67 | (const char*) e.message().utf8()); | ||
68 | |||
69 | err += tmp; | ||
70 | |||
71 | return false; | ||
72 | } | ||
73 | |||
74 | QString ZkbConfig::errorString() { | ||
75 | return err; | ||
76 | } | ||
77 | |||
78 | // Implementation of ZkbHandler | ||
79 | ZkbHandler::ZkbHandler(ZkbConfig& z, Keymap& k, const QString& p):zkc(z), keymap(k), | ||
80 | prefix(p), ardelay(-1), arperiod(-1), currentState(0), currentAction(0) { | ||
81 | } | ||
82 | |||
83 | ZkbHandler::~ZkbHandler() { | ||
84 | } | ||
85 | |||
86 | bool ZkbHandler::startKeymapElement(int ard, int arp, const QString&) { | ||
87 | ardelay = ard; | ||
88 | arperiod = arp; | ||
89 | |||
90 | return true; | ||
91 | } | ||
92 | |||
93 | bool ZkbHandler::startIncludeElement(const QString& file, | ||
94 | const QString& pref) { | ||
95 | |||
96 | QString p = prefix; | ||
97 | |||
98 | if (!pref.isNull()) { | ||
99 | p += pref + ":"; | ||
100 | } | ||
101 | |||
102 | |||
103 | bool ret = zkc.load(file, keymap, p); | ||
104 | if (!ret) { | ||
105 | setError("Error including file: " + file); | ||
106 | } | ||
107 | |||
108 | return ret; | ||
109 | } | ||
110 | |||
111 | bool ZkbHandler::startLabelElement(const QString& label, | ||
112 | const QString& state) { | ||
113 | |||
114 | if (!keymap.addLabel(label, prefix + state)) { | ||
115 | err = "label " + label + " already defined"; | ||
116 | return false; | ||
117 | } | ||
118 | |||
119 | return true; | ||
120 | } | ||
121 | |||
122 | bool ZkbHandler::startStateElement(const QString& name, | ||
123 | const QString& parentName, bool dflt) { | ||
124 | |||
125 | currentStateName = prefix + name; | ||
126 | currentState = keymap.getStateByName(currentStateName); | ||
127 | |||
128 | //odebug << "state name=" << currentStateName.utf8() << "\n" << oendl; | ||
129 | |||
130 | State* parent = 0; | ||
131 | if (!parentName.isEmpty()) { | ||
132 | QString pn = prefix + parentName; | ||
133 | parent = keymap.getStateByName(pn); | ||
134 | if (parent == 0) { | ||
135 | err = currentStateName + | ||
136 | ": undefined parent state: " + pn; | ||
137 | return false; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | if (currentState == 0) { | ||
142 | currentState = new State(parent); | ||
143 | keymap.addState(currentStateName, currentState); | ||
144 | } else { | ||
145 | if (parent!=0) { | ||
146 | currentState->setParent(parent); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | if (dflt) { | ||
151 | keymap.setCurrentState(currentState); | ||
152 | } | ||
153 | |||
154 | return true; | ||
155 | } | ||
156 | |||
157 | bool ZkbHandler::startMapElement(int keycode, bool pressed) { | ||
158 | currentAction = currentState->get(keycode, pressed); | ||
159 | if (currentAction == 0) { | ||
160 | setError("keycode " + QString::number(keycode) + " not supported"); | ||
161 | return false; | ||
162 | } | ||
163 | |||
164 | currentAction->setEvent(false); | ||
165 | currentAction->setState(0); | ||
166 | |||
167 | return true; | ||
168 | } | ||
169 | |||
170 | bool ZkbHandler::startEventElement(int keycode, int unicode, int modifiers, | ||
171 | bool pressed, bool autorepeat) { | ||
172 | |||
173 | currentAction->setEvent(true); | ||
174 | currentAction->setKeycode(keycode); | ||
175 | currentAction->setUnicode(unicode); | ||
176 | currentAction->setModifiers(modifiers); | ||
177 | currentAction->setPressed(pressed); | ||
178 | currentAction->setAutorepeat(autorepeat); | ||
179 | |||
180 | return true; | ||
181 | } | ||
182 | |||
183 | bool ZkbHandler::startNextStateElement(const QString& state) { | ||
184 | State* s = keymap.getStateByName(prefix + state); | ||
185 | if (s == 0) { | ||
186 | setError("undefine state: " + prefix + state); | ||
187 | return false; | ||
188 | } | ||
189 | |||
190 | currentAction->setState(s); | ||
191 | return true; | ||
192 | } | ||
193 | |||
194 | |||
195 | bool ZkbHandler::endKeymapElement() { | ||
196 | if (ardelay > 0) { | ||
197 | keymap.setAutorepeatDelay(ardelay); | ||
198 | } | ||
199 | |||
200 | if (arperiod > 0) { | ||
201 | keymap.setAutorepeatPeriod(arperiod); | ||
202 | } | ||
203 | |||
204 | return true; | ||
205 | } | ||
206 | |||
207 | bool ZkbHandler::endIncludeElement() { | ||
208 | return true; | ||
209 | } | ||
210 | |||
211 | bool ZkbHandler::endLabelElement() { | ||
212 | return true; | ||
213 | } | ||
214 | |||
215 | bool ZkbHandler::endStateElement() { | ||
216 | currentState = 0; | ||
217 | return true; | ||
218 | } | ||
219 | |||
220 | bool ZkbHandler::endMapElement() { | ||
221 | currentAction = 0; | ||
222 | return true; | ||
223 | } | ||
224 | |||
225 | bool ZkbHandler::endEventElement() { | ||
226 | return true; | ||
227 | } | ||
228 | |||
229 | bool ZkbHandler::endNextStateElement() { | ||
230 | return true; | ||
231 | } | ||