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