19 files changed, 2903 insertions, 22 deletions
diff --git a/noncore/applets/zkbapplet/applet/applet.pro b/noncore/applets/zkbapplet/applet/applet.pro new file mode 100644 index 0000000..20a4c89 --- a/dev/null +++ b/noncore/applets/zkbapplet/applet/applet.pro | |||
@@ -0,0 +1,20 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += qt plugin warn_on | ||
3 | HEADERS = zkbwidget.h \ | ||
4 | ../keyz-cfg/zkbcfg.h \ | ||
5 | ../keyz-cfg/zkbnames.h \ | ||
6 | ../keyz-cfg/zkbxml.h \ | ||
7 | ../keyz-cfg/zkb.h | ||
8 | SOURCES = zkbwidget.cpp \ | ||
9 | ../keyz-cfg/zkbcfg.cpp \ | ||
10 | ../keyz-cfg/zkbnames.cpp \ | ||
11 | ../keyz-cfg/zkbxml.cpp \ | ||
12 | ../keyz-cfg/zkb.cpp | ||
13 | TARGET = zkbapplet | ||
14 | DESTDIR = $(OPIEDIR)/plugins/applets | ||
15 | INCLUDEPATH += $(OPIEDIR)/include ../keyz-cfg | ||
16 | DEPENDPATH += | ||
17 | VERSION = 0.7.0 | ||
18 | LIBS += -lqpe -lopiecore2 | ||
19 | |||
20 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/noncore/applets/zkbapplet/zkbwidget.cpp b/noncore/applets/zkbapplet/applet/zkbwidget.cpp index 8499500..8499500 100644 --- a/noncore/applets/zkbapplet/zkbwidget.cpp +++ b/noncore/applets/zkbapplet/applet/zkbwidget.cpp | |||
diff --git a/noncore/applets/zkbapplet/zkbwidget.h b/noncore/applets/zkbapplet/applet/zkbwidget.h index 9bce85a..9bce85a 100644 --- a/noncore/applets/zkbapplet/zkbwidget.h +++ b/noncore/applets/zkbapplet/applet/zkbwidget.h | |||
diff --git a/noncore/applets/zkbapplet/config.in b/noncore/applets/zkbapplet/config.in index 3e02fdd..b3d3fc5 100644 --- a/noncore/applets/zkbapplet/config.in +++ b/noncore/applets/zkbapplet/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config ZKBAPPLET | 1 | config ZKBAPPLET |
2 | boolean "zkbapplet (Switch hardware keyboard layout on the fly)" | 2 | boolean "zkbapplet (Switch hardware keyboard layout on the fly)" |
3 | default "n" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) && KEYZCFG | 4 | depends ( LIBQPE || LIBQPE-X11 ) |
diff --git a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp new file mode 100644 index 0000000..8d868d4 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | |||
2 | #include <qdir.h> | ||
3 | #include <qpe/qpeapplication.h> | ||
4 | #include <qpe/qcopenvelope_qws.h> | ||
5 | #include <unistd.h> | ||
6 | #include "cfgdlg.h" | ||
7 | |||
8 | CfgDlg::CfgDlg(QWidget* parent, CfgFile* cf, QApplication* app, bool mod): | ||
9 | QDialog(parent, "CfgDlg", mod), cfile(cf), application(app) { | ||
10 | |||
11 | setCaption(tr("keyz configurator")); | ||
12 | |||
13 | QGridLayout* gl = new QGridLayout(this, 7, 5, 5, 5); | ||
14 | |||
15 | QLabel* flabel = new QLabel("Available Keymaps", this); | ||
16 | files = new QListBox(this); | ||
17 | QPushButton* addButton = new QPushButton(">>", this); //add->setText("Add"); | ||
18 | connect(addButton, SIGNAL(clicked()), this, SLOT(add())); | ||
19 | QLabel* klabel = new QLabel("Selected Keymaps", this); | ||
20 | keymaps = new QListBox(this); | ||
21 | connect(keymaps, SIGNAL(highlighted(const QString&)), this, SLOT(keymapHighlighted(const QString&))); | ||
22 | QPushButton* delButton = new QPushButton("<<", this); //del->setText("Delete"); | ||
23 | connect(delButton, SIGNAL(clicked()), this, SLOT(del())); | ||
24 | QPushButton* slabelButton = new QPushButton("Set Label", this); //apply->setText("Apply"); | ||
25 | connect(slabelButton, SIGNAL(clicked()), this, SLOT(setLabel())); | ||
26 | QLabel* l = new QLabel("Label", this); | ||
27 | label = new QLineEdit(this); | ||
28 | QLabel* adlabel = new QLabel("Auto Repeat Delay (ms)", this); | ||
29 | QLabel* aplabel = new QLabel("Auto Repeat Period (ms)", this); | ||
30 | ad = new QSpinBox(50, 5000, 5, this); | ||
31 | ap = new QSpinBox(0, 5000, 5, this); | ||
32 | |||
33 | //QLabel* adms = new QLabel("ms", this); | ||
34 | //QLabel* apms = new QLabel("ms", this); | ||
35 | |||
36 | //QCheckBox* enable = new QCheckBox("Enable", t); | ||
37 | |||
38 | gl->setColStretch(0, 1); | ||
39 | gl->setColStretch(1, 1); | ||
40 | gl->setColStretch(3, 1); | ||
41 | gl->setColStretch(4, 1); | ||
42 | gl->setRowStretch(3, 1); | ||
43 | gl->addMultiCellWidget(flabel, 0, 0, 0, 1); | ||
44 | gl->addMultiCellWidget(klabel, 0, 0, 3, 4); | ||
45 | gl->addMultiCellWidget(files, 1, 3, 0, 1); | ||
46 | gl->addMultiCellWidget(keymaps, 1, 3, 3, 4); | ||
47 | gl->addWidget(addButton, 1, 2); | ||
48 | gl->addWidget(delButton, 2, 2); | ||
49 | |||
50 | gl->addWidget(l, 4, 0); | ||
51 | gl->addWidget(label, 4, 1); | ||
52 | gl->addMultiCellWidget(slabelButton, 4, 4, 3, 4); | ||
53 | |||
54 | gl->addMultiCellWidget(adlabel, 5, 5, 0, 2); | ||
55 | gl->addMultiCellWidget(ad, 5, 5, 3, 4); | ||
56 | //gl->addWidget(adms, 5, 3); | ||
57 | |||
58 | gl->addMultiCellWidget(aplabel, 6, 6, 0, 2); | ||
59 | gl->addMultiCellWidget(ap, 6, 6, 3, 4); | ||
60 | |||
61 | //gl->addWidget(apms, 6, 3); | ||
62 | |||
63 | QList<CfgEntry>& e = cfile->getEntries(); | ||
64 | |||
65 | for(uint i = 0; i < e.count(); i++) { | ||
66 | CfgEntry* entry = e.at(i); | ||
67 | keymaps->insertItem(entry->getFile()); | ||
68 | m.insert(entry->getFile(), entry->getLabel()); | ||
69 | } | ||
70 | |||
71 | QDir dir(QPEApplication::qpeDir()+"/share/zkb", "*.xml"); | ||
72 | QStringList flist = dir.entryList(); | ||
73 | QStringList::Iterator sit; | ||
74 | for(sit = flist.begin(); sit != flist.end(); ++sit) { | ||
75 | if (*sit != "common.xml" && *sit != "zkb.xml" && m.find(*sit) == m.end()) { | ||
76 | files->insertItem(*sit); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | ad->setValue(cfile->getAutorepeatDelay()); | ||
81 | ap->setValue(cfile->getAutorepeatPeriod()); | ||
82 | |||
83 | //gl->addMultiCellWidget(enable, 7, 7, 0, 4); | ||
84 | } | ||
85 | |||
86 | CfgDlg::~CfgDlg() { | ||
87 | } | ||
88 | |||
89 | void CfgDlg::add() { | ||
90 | if (!files->currentText().isEmpty()) { | ||
91 | QString t = files->currentText(); | ||
92 | files->removeItem(files->currentItem()); | ||
93 | keymaps->insertItem(t); | ||
94 | cfile->replaceEntry(t, ""); | ||
95 | m.replace(t, ""); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void CfgDlg::del() { | ||
100 | if (!keymaps->currentText().isEmpty()) { | ||
101 | QString t = keymaps->currentText(); | ||
102 | keymaps->removeItem(keymaps->currentItem()); | ||
103 | cfile->deleteEntry(t); | ||
104 | files->insertItem(t); | ||
105 | m.remove(files->currentText()); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | void CfgDlg::setLabel() { | ||
110 | if (!keymaps->currentText().isEmpty()) { | ||
111 | cfile->replaceEntry(keymaps->currentText(), | ||
112 | label->text()); | ||
113 | m.replace(keymaps->currentText(), label->text()); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | void CfgDlg::keymapHighlighted(const QString&text) { | ||
118 | label->setText(*m.find(text)); | ||
119 | } | ||
120 | |||
121 | |||
122 | void CfgDlg::accept() { | ||
123 | cfile->setAutorepeatDelay(ad->value()); | ||
124 | cfile->setAutorepeatPeriod(ap->value()); | ||
125 | |||
126 | CfgParser p; | ||
127 | p.save(QPEApplication::qpeDir()+"/share/zkb/zkb.xml", *cfile); | ||
128 | QCopEnvelope("QPE/zkb", "reload()"); | ||
129 | |||
130 | QDialog::accept(); | ||
131 | } | ||
132 | |||
diff --git a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.h b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.h new file mode 100644 index 0000000..cbefdf1 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.h | |||
@@ -0,0 +1,39 @@ | |||
1 | #include <qlabel.h> | ||
2 | #include <qlistbox.h> | ||
3 | #include <qpushbutton.h> | ||
4 | #include <qlineedit.h> | ||
5 | #include <qlayout.h> | ||
6 | #include <qcheckbox.h> | ||
7 | #include <qspinbox.h> | ||
8 | #include <qdialog.h> | ||
9 | #include <qapplication.h> | ||
10 | |||
11 | #include "cfgfile.h" | ||
12 | |||
13 | class CfgDlg : public QDialog { | ||
14 | Q_OBJECT | ||
15 | |||
16 | public: | ||
17 | CfgDlg(QWidget* parent, CfgFile* cfile, QApplication *, bool b = false); | ||
18 | virtual ~CfgDlg(); | ||
19 | |||
20 | protected: | ||
21 | CfgFile* cfile; | ||
22 | QApplication* application; | ||
23 | |||
24 | QMap<QString, QString> m; | ||
25 | |||
26 | QListBox* files; | ||
27 | QListBox* keymaps; | ||
28 | QLineEdit* label; | ||
29 | QSpinBox* ap; | ||
30 | QSpinBox* ad; | ||
31 | |||
32 | virtual void accept(); | ||
33 | |||
34 | protected slots: | ||
35 | void add(); | ||
36 | void del(); | ||
37 | void setLabel(); | ||
38 | void keymapHighlighted(const QString&); | ||
39 | }; | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/cfgfile.cpp b/noncore/applets/zkbapplet/keyzcfg/cfgfile.cpp new file mode 100644 index 0000000..be7150e --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/cfgfile.cpp | |||
@@ -0,0 +1,349 @@ | |||
1 | #include "cfgfile.h" | ||
2 | |||
3 | /* OPIE */ | ||
4 | #include <opie2/odebug.h> | ||
5 | using namespace Opie::Core; | ||
6 | |||
7 | /* QT */ | ||
8 | #include <qmessagebox.h> | ||
9 | |||
10 | // CfgEntry implementation | ||
11 | CfgEntry::CfgEntry() { | ||
12 | } | ||
13 | |||
14 | CfgEntry::CfgEntry(const QString& f, const QString& l): | ||
15 | file(f), label(l) { | ||
16 | } | ||
17 | |||
18 | const QString& CfgEntry::getFile() const { | ||
19 | return file; | ||
20 | } | ||
21 | |||
22 | void CfgEntry::setFile(const QString& f) { | ||
23 | file = f; | ||
24 | } | ||
25 | |||
26 | const QString& CfgEntry::getLabel() const { | ||
27 | return label; | ||
28 | } | ||
29 | |||
30 | void CfgEntry::setLabel(const QString& f) { | ||
31 | label = f; | ||
32 | } | ||
33 | |||
34 | // CfgFile implementation | ||
35 | CfgFile::CfgFile():ardelay(400), arperiod(80) { | ||
36 | } | ||
37 | |||
38 | CfgFile::~CfgFile() { | ||
39 | } | ||
40 | |||
41 | QList<CfgEntry>& CfgFile::getEntries() { | ||
42 | return entries; | ||
43 | } | ||
44 | |||
45 | bool CfgFile::replaceEntry(const QString& file, const QString& label, int index) { | ||
46 | deleteEntry(file); | ||
47 | |||
48 | CfgEntry* entry = new CfgEntry(file, label); | ||
49 | if (index >= 0) { | ||
50 | entries.insert(index, entry); | ||
51 | } else { | ||
52 | entries.append(entry); | ||
53 | } | ||
54 | |||
55 | return true; | ||
56 | } | ||
57 | |||
58 | bool CfgFile::deleteEntry(const QString& file) { | ||
59 | for(int i = 0; i < (int) entries.count(); i++) { | ||
60 | CfgEntry* entry = entries.at(i); | ||
61 | if (entry->getFile() == file) { | ||
62 | entries.remove(i); | ||
63 | return true; | ||
64 | } | ||
65 | } | ||
66 | return false; | ||
67 | } | ||
68 | |||
69 | int CfgFile::getAutorepeatDelay() const { | ||
70 | return ardelay; | ||
71 | } | ||
72 | |||
73 | void CfgFile::setAutorepeatDelay(int n) { | ||
74 | ardelay = n; | ||
75 | } | ||
76 | |||
77 | int CfgFile::getAutorepeatPeriod() const { | ||
78 | return arperiod; | ||
79 | } | ||
80 | |||
81 | void CfgFile::setAutorepeatPeriod(int n) { | ||
82 | arperiod = n; | ||
83 | } | ||
84 | |||
85 | // CfgParser implementation | ||
86 | CfgParser::CfgParser() { | ||
87 | } | ||
88 | |||
89 | bool CfgParser::load(QString file, CfgFile& cfg) { | ||
90 | QFile f(file); | ||
91 | QXmlInputSource is(f); | ||
92 | QXmlSimpleReader reader; | ||
93 | CfgHandler p(*this); | ||
94 | |||
95 | reader.setErrorHandler(this); | ||
96 | reader.setContentHandler(&p); | ||
97 | |||
98 | err = ""; | ||
99 | ardelay = -1; | ||
100 | arperiod = -1; | ||
101 | reader.parse(is); | ||
102 | |||
103 | if (!err.isEmpty()) { | ||
104 | odebug << err << oendl; | ||
105 | return false; | ||
106 | } | ||
107 | |||
108 | QMap<QString, QString>::Iterator fit, lit; | ||
109 | for(uint i = 0; i < includeList.count(); i++) { | ||
110 | QString file = *includeList.at(i); | ||
111 | fit = includes.find(file); | ||
112 | QString prefix = fit.data(); | ||
113 | QString label = ""; | ||
114 | |||
115 | odebug << "include: file=" + fit.key() + ", prefix=" + fit.data() << oendl; | ||
116 | lit = labels.find(prefix+":*"); | ||
117 | if (lit != labels.end()) { | ||
118 | label = lit.data(); | ||
119 | } | ||
120 | |||
121 | cfg.replaceEntry(file, label); | ||
122 | } | ||
123 | |||
124 | if (ardelay != -1) { | ||
125 | cfg.setAutorepeatDelay(ardelay); | ||
126 | } | ||
127 | |||
128 | if (arperiod != -1) { | ||
129 | cfg.setAutorepeatPeriod(arperiod); | ||
130 | } | ||
131 | |||
132 | return true; | ||
133 | } | ||
134 | |||
135 | bool CfgParser::save(QString file, CfgFile& cfg) { | ||
136 | FILE* f = fopen((const char*) file.local8Bit(), "w"); | ||
137 | if (!f) { | ||
138 | oerr << "Could not write config file!" << oendl; | ||
139 | return false; | ||
140 | } | ||
141 | |||
142 | fprintf(f, "<keymap autorepeat-delay=\"%d\" autorepeat-period=\"%d\" " | ||
143 | "author=\"keyzcfg\">\n", cfg.getAutorepeatDelay(), | ||
144 | cfg.getAutorepeatPeriod()); | ||
145 | |||
146 | QList<CfgEntry>& entries = cfg.getEntries(); | ||
147 | int n; | ||
148 | |||
149 | for(n=0; n < (int) entries.count(); n++) { | ||
150 | CfgEntry* entry = entries.at(n); | ||
151 | QString l = entry->getLabel(); | ||
152 | if (l.isEmpty()) { | ||
153 | l = entry->getFile(); | ||
154 | } | ||
155 | fprintf(f, "\t<label name=\"%s\" state=\"km%d:*\"/>\n", | ||
156 | (const char*) l.utf8(), n); | ||
157 | } | ||
158 | |||
159 | for(n=0; n < (int) entries.count(); n++) { | ||
160 | CfgEntry* entry = entries.at(n); | ||
161 | fprintf(f, "\t<include file=\"%s\" prefix=\"km%d\"/>\n", | ||
162 | (const char*) entry->getFile().utf8(), n); | ||
163 | } | ||
164 | |||
165 | int k = n-1; | ||
166 | char* states[] = { "LShift", "LShift-Caps", "LShift-Num", | ||
167 | "LShift-Num-Caps", 0}; | ||
168 | |||
169 | for(n=0; n < (int) entries.count(); n++) { | ||
170 | QString nstate = "km" + QString::number(n+1); | ||
171 | if (n == k) { | ||
172 | nstate = "km" + QString::number(0); | ||
173 | } | ||
174 | |||
175 | for(int i = 0; states[i] != 0; i++) { | ||
176 | fprintf(f, "\t<state name=\"km%d:%s\">\n", | ||
177 | n, states[i]); | ||
178 | fprintf(f, "\t\t<map keycode=\"Middle\" pressed=\"true\">\n"); | ||
179 | fprintf(f, "\t\t\t<next-state name=\"%s:%s\"/>\n", | ||
180 | (const char*) nstate.utf8(), states[i]); | ||
181 | fprintf(f, "\t\t</map>\n\t</state>\n\n"); | ||
182 | } | ||
183 | } | ||
184 | |||
185 | fprintf(f, "\t<state name=\"km0:Normal\" default=\"true\"/>\n"); | ||
186 | |||
187 | fprintf(f, "</keymap>"); | ||
188 | fclose(f); | ||
189 | return true; | ||
190 | } | ||
191 | |||
192 | CfgParser::~CfgParser() { | ||
193 | } | ||
194 | |||
195 | int CfgParser::getAutorepeatDelay() const { | ||
196 | return ardelay; | ||
197 | } | ||
198 | |||
199 | void CfgParser::setAutorepeatDelay(int n) { | ||
200 | ardelay = n; | ||
201 | } | ||
202 | |||
203 | int CfgParser::getAutorepeatPeriod() const { | ||
204 | return arperiod; | ||
205 | } | ||
206 | |||
207 | void CfgParser::setAutorepeatPeriod(int n) { | ||
208 | arperiod = n; | ||
209 | } | ||
210 | |||
211 | void CfgParser::addLabel(const QString& name, const QString& state) { | ||
212 | labels.insert(state, name); | ||
213 | labelList.append(&labels.find(state).data()); | ||
214 | } | ||
215 | |||
216 | void CfgParser::addFile(const QString& file, const QString& prefix) { | ||
217 | includes.insert(file, prefix); | ||
218 | includeList.append(&includes.find(file).key()); | ||
219 | } | ||
220 | |||
221 | QString CfgParser::errorString() { | ||
222 | return err; | ||
223 | } | ||
224 | |||
225 | bool CfgParser::warning(const QXmlParseException& e) { | ||
226 | QString tmp; | ||
227 | |||
228 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), | ||
229 | (const char*) e.message().utf8()); | ||
230 | |||
231 | err += tmp; | ||
232 | |||
233 | return true; | ||
234 | } | ||
235 | |||
236 | bool CfgParser::error(const QXmlParseException& e) { | ||
237 | QString tmp; | ||
238 | |||
239 | tmp.sprintf("%d: error: %s\n", e.lineNumber(), | ||
240 | (const char*) e.message().utf8()); | ||
241 | |||
242 | err += tmp; | ||
243 | |||
244 | return true; | ||
245 | } | ||
246 | |||
247 | bool CfgParser::fatalError(const QXmlParseException& e) { | ||
248 | QString tmp; | ||
249 | |||
250 | tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), | ||
251 | (const char*) e.message().utf8()); | ||
252 | |||
253 | err += tmp; | ||
254 | |||
255 | return false; | ||
256 | } | ||
257 | |||
258 | // CfgHandler implementation | ||
259 | CfgHandler::CfgHandler(CfgParser& c):cfg(c) { | ||
260 | } | ||
261 | |||
262 | CfgHandler::~CfgHandler() { | ||
263 | } | ||
264 | |||
265 | bool CfgHandler::startKeymapElement(int ard, int arp, const QString& author) { | ||
266 | if (author != "keyzcfg") { | ||
267 | bool ret; | ||
268 | ret = QMessageBox::warning(0, "keyz configurator", | ||
269 | "Your zkb.xml doesn't seem created by keyz configurator.\n" | ||
270 | "By using keyz configurator you may loose your current " | ||
271 | "configuration\n Do you want to continue\n\n", | ||
272 | "Yes", "No", 0, 0, 1); | ||
273 | |||
274 | if (ret != 0) { | ||
275 | err = "cancelled by user"; | ||
276 | return false; | ||
277 | } | ||
278 | } | ||
279 | |||
280 | if (ard != -1) { | ||
281 | cfg.setAutorepeatDelay(ard); | ||
282 | } | ||
283 | |||
284 | if (arp != -1) { | ||
285 | cfg.setAutorepeatPeriod(arp); | ||
286 | } | ||
287 | |||
288 | return true; | ||
289 | } | ||
290 | |||
291 | bool CfgHandler::startIncludeElement(const QString& file, | ||
292 | const QString& pref) { | ||
293 | |||
294 | cfg.addFile(file, pref); | ||
295 | return true; | ||
296 | } | ||
297 | |||
298 | bool CfgHandler::startLabelElement(const QString& label, | ||
299 | const QString& state) { | ||
300 | |||
301 | cfg.addLabel(label, state); | ||
302 | return true; | ||
303 | } | ||
304 | |||
305 | bool CfgHandler::startStateElement(const QString&, const QString&, bool) { | ||
306 | |||
307 | return true; | ||
308 | } | ||
309 | |||
310 | bool CfgHandler::startMapElement(int, bool) { | ||
311 | return true; | ||
312 | } | ||
313 | |||
314 | bool CfgHandler::startEventElement(int, int, int, bool, bool) { | ||
315 | return true; | ||
316 | } | ||
317 | |||
318 | bool CfgHandler::startNextStateElement(const QString&) { | ||
319 | return true; | ||
320 | } | ||
321 | |||
322 | |||
323 | bool CfgHandler::endKeymapElement() { | ||
324 | return true; | ||
325 | } | ||
326 | |||
327 | bool CfgHandler::endIncludeElement() { | ||
328 | return true; | ||
329 | } | ||
330 | |||
331 | bool CfgHandler::endLabelElement() { | ||
332 | return true; | ||
333 | } | ||
334 | |||
335 | bool CfgHandler::endStateElement() { | ||
336 | return true; | ||
337 | } | ||
338 | |||
339 | bool CfgHandler::endMapElement() { | ||
340 | return true; | ||
341 | } | ||
342 | |||
343 | bool CfgHandler::endEventElement() { | ||
344 | return true; | ||
345 | } | ||
346 | |||
347 | bool CfgHandler::endNextStateElement() { | ||
348 | return true; | ||
349 | } | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/cfgfile.h b/noncore/applets/zkbapplet/keyzcfg/cfgfile.h new file mode 100644 index 0000000..9759900 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/cfgfile.h | |||
@@ -0,0 +1,106 @@ | |||
1 | #ifndef CFGFILE_H | ||
2 | #define CFGFILE_H | ||
3 | |||
4 | #include <qlist.h> | ||
5 | #include "zkbxml.h" | ||
6 | |||
7 | class CfgEntry { | ||
8 | public: | ||
9 | CfgEntry(); | ||
10 | CfgEntry(const QString& file, const QString& label); | ||
11 | |||
12 | const QString& getFile() const; | ||
13 | void setFile(const QString& f); | ||
14 | const QString& getLabel() const; | ||
15 | void setLabel(const QString& l); | ||
16 | |||
17 | protected: | ||
18 | QString file; | ||
19 | QString label; | ||
20 | }; | ||
21 | |||
22 | class CfgFile { | ||
23 | public: | ||
24 | CfgFile(); | ||
25 | ~CfgFile(); | ||
26 | |||
27 | QList<CfgEntry>& getEntries(); | ||
28 | bool replaceEntry(const QString& file, const QString& label, | ||
29 | int index = -1); | ||
30 | bool deleteEntry(const QString& file); | ||
31 | |||
32 | int getAutorepeatDelay() const; | ||
33 | void setAutorepeatDelay(int); | ||
34 | int getAutorepeatPeriod() const; | ||
35 | void setAutorepeatPeriod(int); | ||
36 | |||
37 | protected: | ||
38 | QList<CfgEntry> entries; | ||
39 | int ardelay; | ||
40 | int arperiod; | ||
41 | }; | ||
42 | |||
43 | class CfgParser : public QXmlErrorHandler { | ||
44 | public: | ||
45 | CfgParser(); | ||
46 | virtual ~CfgParser(); | ||
47 | |||
48 | bool load(QString file, CfgFile& cfg); | ||
49 | bool save(QString file, CfgFile& cfg); | ||
50 | |||
51 | void addLabel(const QString& name, const QString& state); | ||
52 | void addFile(const QString& file, const QString& prefix); | ||
53 | |||
54 | int getAutorepeatDelay() const; | ||
55 | void setAutorepeatDelay(int); | ||
56 | int getAutorepeatPeriod() const; | ||
57 | void setAutorepeatPeriod(int); | ||
58 | |||
59 | virtual bool warning(const QXmlParseException& e); | ||
60 | virtual bool error(const QXmlParseException& e); | ||
61 | virtual bool fatalError(const QXmlParseException& e); | ||
62 | virtual QString errorString(); | ||
63 | |||
64 | QString getError(); | ||
65 | |||
66 | protected: | ||
67 | QString err; | ||
68 | QMap<QString, QString> labels; | ||
69 | QMap<QString, QString> includes; | ||
70 | QList<QString> labelList; | ||
71 | QList<QString> includeList; | ||
72 | int ardelay; | ||
73 | int arperiod; | ||
74 | }; | ||
75 | |||
76 | class CfgHandler : public ZkbXmlHandler { | ||
77 | public: | ||
78 | CfgHandler(CfgParser &); | ||
79 | virtual ~CfgHandler(); | ||
80 | |||
81 | protected: | ||
82 | CfgParser& cfg; | ||
83 | |||
84 | virtual bool startKeymapElement(int ardelay, int arperiod, | ||
85 | const QString& author); | ||
86 | virtual bool startIncludeElement(const QString& file, | ||
87 | const QString& prfix); | ||
88 | virtual bool startLabelElement(const QString& label, | ||
89 | const QString& state); | ||
90 | virtual bool startStateElement(const QString& name, | ||
91 | const QString& parent, bool dflt); | ||
92 | virtual bool startMapElement(int key, bool pressed); | ||
93 | virtual bool startEventElement(int keycode, int unicode, int modifiers, | ||
94 | bool pressed, bool autorepeat); | ||
95 | virtual bool startNextStateElement(const QString& state); | ||
96 | |||
97 | virtual bool endKeymapElement(); | ||
98 | virtual bool endIncludeElement(); | ||
99 | virtual bool endLabelElement(); | ||
100 | virtual bool endStateElement(); | ||
101 | virtual bool endMapElement(); | ||
102 | virtual bool endEventElement(); | ||
103 | virtual bool endNextStateElement(); | ||
104 | }; | ||
105 | |||
106 | #endif | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/keyzcfg.pro b/noncore/applets/zkbapplet/keyzcfg/keyzcfg.pro new file mode 100644 index 0000000..7ac604b --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/keyzcfg.pro | |||
@@ -0,0 +1,24 @@ | |||
1 | TEMPLATE = app | ||
2 | DESTDIR = $(OPIEDIR)/bin | ||
3 | CONFIG = qt warn_on | ||
4 | HEADERS = zkb.h \ | ||
5 | zkbcfg.h \ | ||
6 | zkbnames.h \ | ||
7 | zkbxml.h \ | ||
8 | cfgdlg.h \ | ||
9 | cfgfile.h | ||
10 | |||
11 | SOURCES = main.cpp \ | ||
12 | cfgdlg.cpp \ | ||
13 | cfgfile.cpp \ | ||
14 | zkb.cpp \ | ||
15 | zkbcfg.cpp \ | ||
16 | zkbnames.cpp \ | ||
17 | zkbxml.cpp | ||
18 | |||
19 | INCLUDEPATH += $(OPIEDIR)/include | ||
20 | DEPENDPATH += $(OPIEDIR)/include | ||
21 | LIBS += -lqpe -lopiecore2 | ||
22 | TARGET = keyz-cfg | ||
23 | |||
24 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/main.cpp b/noncore/applets/zkbapplet/keyzcfg/main.cpp new file mode 100644 index 0000000..4615562 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/main.cpp | |||
@@ -0,0 +1,22 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <qpe/qpeapplication.h> | ||
3 | #include <qlayout.h> | ||
4 | #include <qmainwindow.h> | ||
5 | |||
6 | #include "cfgdlg.h" | ||
7 | |||
8 | int main( int argc, char **argv ) { | ||
9 | QPEApplication app(argc, argv); | ||
10 | CfgFile cfile; | ||
11 | CfgParser cp; | ||
12 | cp.load(QPEApplication::qpeDir()+"/share/zkb/zkb.xml", cfile); | ||
13 | |||
14 | |||
15 | CfgDlg c(0, &cfile, &app, true); | ||
16 | |||
17 | |||
18 | app.showMainWidget(&c); | ||
19 | int ret = QPEApplication::execDialog(&c); | ||
20 | |||
21 | return ret; | ||
22 | } | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkb.cpp b/noncore/applets/zkbapplet/keyzcfg/zkb.cpp new file mode 100644 index 0000000..a357b88 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkb.cpp | |||
@@ -0,0 +1,592 @@ | |||
1 | #include "zkb.h" | ||
2 | |||
3 | /* OPIE */ | ||
4 | #include <opie2/odebug.h> | ||
5 | #include <opie2/okeyfilter.h> | ||
6 | |||
7 | #include <stdio.h> | ||
8 | |||
9 | // Implementation of Action class | ||
10 | Action::Action():state(0), keycode(0), unicode(0), flags(0) { | ||
11 | } | ||
12 | |||
13 | Action::Action(State* s, ushort kc, ushort uni, int f): | ||
14 | state(s), keycode(kc), unicode(uni), flags(f) { | ||
15 | } | ||
16 | |||
17 | Action::~Action() { | ||
18 | } | ||
19 | |||
20 | State* Action::getState() const { | ||
21 | return state; | ||
22 | } | ||
23 | |||
24 | void Action::setState(State* s) { | ||
25 | state = s; | ||
26 | setDefined(true); | ||
27 | } | ||
28 | |||
29 | bool Action::hasEvent() const { | ||
30 | return flags & Event; | ||
31 | } | ||
32 | |||
33 | void Action::setEvent(bool e) { | ||
34 | flags = (flags & ~Event) | ((e) ? Event : 0); | ||
35 | |||
36 | if (e) { | ||
37 | setDefined(true); | ||
38 | } else { | ||
39 | if (state == 0) { | ||
40 | setDefined(false); | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
45 | bool Action::isDefined() const { | ||
46 | return flags & Defined; | ||
47 | } | ||
48 | |||
49 | void Action::setDefined(bool d) { | ||
50 | flags = (flags & ~Defined) | ((d) ? Defined : 0); | ||
51 | } | ||
52 | |||
53 | int Action::getKeycode() const { | ||
54 | return keycode; | ||
55 | } | ||
56 | |||
57 | void Action::setKeycode(int c) { | ||
58 | keycode = (ushort) c; | ||
59 | setEvent(true); | ||
60 | } | ||
61 | |||
62 | int Action::getUnicode() const { | ||
63 | return unicode; | ||
64 | } | ||
65 | |||
66 | void Action::setUnicode(int u) { | ||
67 | unicode = (ushort) u; | ||
68 | setEvent(true); | ||
69 | } | ||
70 | |||
71 | int Action::getModifiers() const { | ||
72 | int ret = 0; | ||
73 | if (flags & Shift_Mod) { | ||
74 | ret |= Qt::ShiftButton; | ||
75 | } | ||
76 | |||
77 | if (flags & Ctrl_Mod) { | ||
78 | ret |= Qt::ControlButton; | ||
79 | } | ||
80 | |||
81 | if (flags & Alt_Mod) { | ||
82 | ret |= Qt::AltButton; | ||
83 | } | ||
84 | |||
85 | if (flags & Keypad_Mod) { | ||
86 | ret |= Qt::Keypad; | ||
87 | } | ||
88 | |||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | void Action::setModifiers(int m) { | ||
93 | int n = 0; | ||
94 | |||
95 | if (m & Qt::ShiftButton) { | ||
96 | n |= Shift_Mod; | ||
97 | } | ||
98 | |||
99 | if (m & Qt::ControlButton) { | ||
100 | n |= Ctrl_Mod; | ||
101 | } | ||
102 | |||
103 | if (m & Qt::AltButton) { | ||
104 | n |= Alt_Mod; | ||
105 | } | ||
106 | |||
107 | if (m & Qt::Keypad) { | ||
108 | n |= Keypad_Mod; | ||
109 | } | ||
110 | |||
111 | flags = flags & ~Mod_Bits | n; | ||
112 | setEvent(true); | ||
113 | } | ||
114 | |||
115 | bool Action::isPressed() const { | ||
116 | return (flags & Press) != 0; | ||
117 | } | ||
118 | |||
119 | void Action::setPressed(bool p) { | ||
120 | flags = (flags & ~Press) | ((p) ? Press : 0); | ||
121 | setEvent(true); | ||
122 | } | ||
123 | |||
124 | bool Action::isAutorepeat() const { | ||
125 | return (flags & Autorepeat) != 0; | ||
126 | } | ||
127 | |||
128 | void Action::setAutorepeat(bool p) { | ||
129 | flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); | ||
130 | setEvent(true); | ||
131 | } | ||
132 | |||
133 | // Implementation of State class | ||
134 | const short State::x1[] = { /* from 0x20 to 0x5f */ | ||
135 | 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ | ||
136 | 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ | ||
137 | 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ | ||
138 | 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ | ||
139 | 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ | ||
140 | 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ | ||
141 | 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ | ||
142 | 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ | ||
143 | 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ | ||
144 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ | ||
145 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ | ||
146 | -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ | ||
147 | }; | ||
148 | |||
149 | const short State::x2[] = { /* from 0x1000 to 0x1057*/ | ||
150 | 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ | ||
151 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ | ||
152 | -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ | ||
153 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ | ||
154 | 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ | ||
155 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ | ||
156 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ | ||
157 | 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ | ||
158 | -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ | ||
159 | -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ | ||
160 | 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ | ||
161 | }; | ||
162 | |||
163 | State::State(State* p):parent(p), keys(0) { | ||
164 | keys = new Action[Key_Max * 2 + 1]; | ||
165 | } | ||
166 | |||
167 | State::State(const State& s) { | ||
168 | parent = s.parent; | ||
169 | keys = new Action[Key_Max * 2 + 1]; | ||
170 | memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); | ||
171 | } | ||
172 | |||
173 | State::~State() { | ||
174 | if (keys!=0) { | ||
175 | delete [] keys; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | Action* State::get(int keycode, bool pressed, bool follow) const { | ||
180 | Action* ret = 0; | ||
181 | int n = translateKeycode(keycode); | ||
182 | |||
183 | if (n != -1 && keys != 0) { | ||
184 | if (pressed) { | ||
185 | n += Key_Max; | ||
186 | } | ||
187 | ret = &keys[n]; | ||
188 | } | ||
189 | |||
190 | if (ret==0 || !ret->isDefined()) { | ||
191 | if (follow && parent!=0) { | ||
192 | ret = parent->get(keycode, pressed, follow); | ||
193 | } | ||
194 | } | ||
195 | |||
196 | return ret; | ||
197 | } | ||
198 | |||
199 | bool State::set(int keycode, bool pressed, Action& action) { | ||
200 | int n = translateKeycode(keycode); | ||
201 | |||
202 | if (n==-1 || keys==0) { | ||
203 | return false; | ||
204 | } | ||
205 | |||
206 | if (pressed) { | ||
207 | n += Key_Max + 1; | ||
208 | } | ||
209 | |||
210 | keys[n] = action; | ||
211 | return true; | ||
212 | } | ||
213 | |||
214 | State* State::getParent() const { | ||
215 | return parent; | ||
216 | } | ||
217 | |||
218 | void State::setParent(State* s) { | ||
219 | parent = s; | ||
220 | } | ||
221 | |||
222 | int State::translateKeycode(int keycode) const { | ||
223 | if (keycode < 0x20) { | ||
224 | return -1; | ||
225 | } | ||
226 | |||
227 | if (keycode < 0x80) { | ||
228 | return x1[keycode - 0x20]; | ||
229 | } | ||
230 | |||
231 | if (keycode < 0x1000) { | ||
232 | return -1; | ||
233 | } | ||
234 | |||
235 | if (keycode < 0x1057) { | ||
236 | return x2[keycode - 0x1000]; | ||
237 | } | ||
238 | |||
239 | return -1; | ||
240 | } | ||
241 | |||
242 | // Implementation of Keymap class | ||
243 | Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { | ||
244 | repeatDelay=400; | ||
245 | repeatPeriod=80; | ||
246 | connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); | ||
247 | } | ||
248 | |||
249 | Keymap::~Keymap() { | ||
250 | odebug << "removing keyboard filter for zkb"<<oendl; | ||
251 | Opie::Core::OKeyFilter::inst()->remHandler(this); | ||
252 | QMap<QString, State*>::Iterator it; | ||
253 | for(it = states.begin(); it != states.end(); ++it) { | ||
254 | delete it.data(); | ||
255 | } | ||
256 | states.clear(); | ||
257 | } | ||
258 | |||
259 | bool Keymap::filter(int unicode, int keycode, int modifiers, | ||
260 | bool isPress, bool autoRepeat) { | ||
261 | |||
262 | odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode | ||
263 | << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl; | ||
264 | |||
265 | if (!enabled) { | ||
266 | return false; | ||
267 | } | ||
268 | |||
269 | // the second check is workaround to make suspend work if | ||
270 | // the user pressed it right after he did resume. for some | ||
271 | // reason the event sent by qt has autoRepeat true in this | ||
272 | // case | ||
273 | if (autoRepeat && keycode != 4177) { | ||
274 | return true; | ||
275 | } | ||
276 | |||
277 | (void) unicode; (void) modifiers; | ||
278 | |||
279 | Action* action = currentState->get(keycode, isPress, true); | ||
280 | if (action==0 || !action->isDefined()) { | ||
281 | return true; | ||
282 | } | ||
283 | |||
284 | if (action->hasEvent()) { | ||
285 | odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode() | ||
286 | << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl; | ||
287 | |||
288 | QWSServer::sendKeyEvent(action->getUnicode(), | ||
289 | action->getKeycode(), action->getModifiers(), | ||
290 | action->isPressed(), false); | ||
291 | } | ||
292 | |||
293 | if (action->isAutorepeat()) { | ||
294 | autoRepeatAction = action; | ||
295 | repeater.start(repeatDelay, TRUE); | ||
296 | } else { | ||
297 | autoRepeatAction = 0; | ||
298 | } | ||
299 | |||
300 | State* nstate = action->getState(); | ||
301 | if (nstate != 0) { | ||
302 | setCurrentState(nstate); | ||
303 | QString lbl = getCurrentLabel(); | ||
304 | if (!lbl.isEmpty()) { | ||
305 | emit stateChanged(lbl); | ||
306 | } | ||
307 | } | ||
308 | |||
309 | |||
310 | return true; | ||
311 | } | ||
312 | |||
313 | void Keymap::enable() { | ||
314 | enabled = true; | ||
315 | } | ||
316 | |||
317 | void Keymap::disable() { | ||
318 | enabled = false; | ||
319 | } | ||
320 | |||
321 | QStringList Keymap::listStates() { | ||
322 | QStringList ret; | ||
323 | |||
324 | QMap<QString, State*>::Iterator it; | ||
325 | for(it = states.begin(); it != states.end(); ++it) { | ||
326 | ret.append(it.key()); | ||
327 | } | ||
328 | |||
329 | return ret; | ||
330 | } | ||
331 | |||
332 | State* Keymap::getStateByName(const QString& name) { | ||
333 | QMap<QString, State*>::Iterator it = states.find(name); | ||
334 | |||
335 | if (it == states.end()) { | ||
336 | return 0; | ||
337 | } | ||
338 | |||
339 | return it.data(); | ||
340 | } | ||
341 | |||
342 | QStringList Keymap::listLabels() { | ||
343 | QStringList ret; | ||
344 | |||
345 | for(uint i = 0; i < labelList.count(); i++) { | ||
346 | ret.append(*labelList.at(i)); | ||
347 | } | ||
348 | |||
349 | return ret; | ||
350 | } | ||
351 | |||
352 | State* Keymap::getStateByLabel(const QString& label) { | ||
353 | QMap<QString, QString>::Iterator lit = labels.find(label); | ||
354 | State* state = 0; | ||
355 | |||
356 | if (lit == labels.end()) { | ||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | QString name = lit.data(); | ||
361 | |||
362 | int n = name.find(":*"); | ||
363 | if (n>=0 && n==(int)(name.length()-2)) { | ||
364 | name=name.left(name.length() - 1); | ||
365 | |||
366 | n = currentStateName.findRev(":"); | ||
367 | if (n >= 0) { | ||
368 | name += currentStateName.mid(n+1); | ||
369 | } | ||
370 | } | ||
371 | |||
372 | // odebug << "look for: " << name.utf8() << "\n" << oendl; | ||
373 | QMap<QString, State*>::Iterator sit = states.find(name); | ||
374 | if (sit != states.end()) { | ||
375 | state = sit.data(); | ||
376 | } | ||
377 | |||
378 | return state; | ||
379 | } | ||
380 | |||
381 | bool Keymap::addState(const QString& name, State* state) { | ||
382 | if (states.find(name) != states.end()) { | ||
383 | return false; | ||
384 | } | ||
385 | |||
386 | states.insert(name, state); | ||
387 | lsmapInSync = false; | ||
388 | |||
389 | if (currentState == 0) { | ||
390 | setCurrentState(state); | ||
391 | } | ||
392 | |||
393 | return true; | ||
394 | } | ||
395 | |||
396 | State* Keymap::getCurrentState() const { | ||
397 | return currentState; | ||
398 | } | ||
399 | |||
400 | QString Keymap::getCurrentLabel() { | ||
401 | return currentLabel; | ||
402 | } | ||
403 | |||
404 | bool Keymap::setCurrentState(State* state) { | ||
405 | QMap<QString, State*>::Iterator it; | ||
406 | for(it = states.begin(); it != states.end(); ++it) { | ||
407 | State* s = it.data(); | ||
408 | if (s == state) { | ||
409 | currentState = s; | ||
410 | currentStateName = it.key(); | ||
411 | |||
412 | odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl; | ||
413 | |||
414 | if (!lsmapInSync) { | ||
415 | generateLabelStateMaps(); | ||
416 | } | ||
417 | |||
418 | QMap<State*, QString>::Iterator tit; | ||
419 | tit = stateLabelMap.find(state); | ||
420 | if (tit != stateLabelMap.end()) { | ||
421 | currentLabel = tit.data(); | ||
422 | } else { | ||
423 | // odebug << "no label for: " + currentStateName + "\n" << oendl; | ||
424 | currentLabel = ""; | ||
425 | } | ||
426 | |||
427 | return true; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | return false; | ||
432 | } | ||
433 | |||
434 | bool Keymap::removeState(const QString& name, bool force) { | ||
435 | QMap<QString, State*>::Iterator it = states.find(name); | ||
436 | |||
437 | if (it == states.end()) { | ||
438 | return false; | ||
439 | } | ||
440 | |||
441 | State* state = it.data(); | ||
442 | QList<Action> acts = findStateUsage(state); | ||
443 | |||
444 | if (!acts.isEmpty()) { | ||
445 | if (!force) { | ||
446 | return false; | ||
447 | } else { | ||
448 | for(Action* a = acts.first(); a != 0; a = acts.next()) { | ||
449 | a->setState(0); | ||
450 | } | ||
451 | } | ||
452 | } | ||
453 | |||
454 | if (state == currentState) { | ||
455 | if (states.begin() != states.end()) { | ||
456 | setCurrentState(states.begin().data()); | ||
457 | } | ||
458 | } | ||
459 | |||
460 | states.remove(it); | ||
461 | delete state; | ||
462 | |||
463 | lsmapInSync = false; | ||
464 | |||
465 | return true; | ||
466 | } | ||
467 | |||
468 | void Keymap::autoRepeat() { | ||
469 | if (autoRepeatAction != 0) { | ||
470 | odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode() | ||
471 | << ", keycode=" << autoRepeatAction->getKeycode() | ||
472 | << ", modifiers=" << autoRepeatAction->getModifiers() | ||
473 | << "ispressed=" << autoRepeatAction->isPressed() << oendl; | ||
474 | |||
475 | QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), | ||
476 | autoRepeatAction->getKeycode(), | ||
477 | autoRepeatAction->getModifiers(), | ||
478 | autoRepeatAction->isPressed(), true); | ||
479 | } | ||
480 | |||
481 | repeater.start(repeatPeriod, TRUE); | ||
482 | } | ||
483 | |||
484 | bool Keymap::addLabel(const QString& label, const QString& state, int index) { | ||
485 | if (labels.find(label) != labels.end()) { | ||
486 | return false; | ||
487 | } | ||
488 | |||
489 | labels.insert(label, state); | ||
490 | const QString& l = labels.find(label).key(); | ||
491 | if (index == -1) { | ||
492 | labelList.append(l); | ||
493 | } else { | ||
494 | labelList.insert(labelList.at(index), l); | ||
495 | } | ||
496 | |||
497 | lsmapInSync = false; | ||
498 | |||
499 | return true; | ||
500 | } | ||
501 | |||
502 | bool Keymap::removeLabel(const QString& label) { | ||
503 | |||
504 | if (labels.find(label) == labels.end()) { | ||
505 | return false; | ||
506 | } | ||
507 | |||
508 | labels.remove(label); | ||
509 | labelList.remove(label); | ||
510 | lsmapInSync = false; | ||
511 | |||
512 | if (label == currentLabel) { | ||
513 | currentLabel = ""; | ||
514 | } | ||
515 | |||
516 | return true; | ||
517 | } | ||
518 | |||
519 | int Keymap::getAutorepeatDelay() const { | ||
520 | return repeatDelay; | ||
521 | } | ||
522 | |||
523 | void Keymap::setAutorepeatDelay(int n) { | ||
524 | repeatDelay = n; | ||
525 | } | ||
526 | |||
527 | int Keymap::getAutorepeatPeriod() const { | ||
528 | return repeatPeriod; | ||
529 | } | ||
530 | |||
531 | void Keymap::setAutorepeatPeriod(int n) { | ||
532 | repeatPeriod = n; | ||
533 | } | ||
534 | |||
535 | QList<Action> Keymap::findStateUsage(State* s) { | ||
536 | QList<Action> ret; | ||
537 | |||
538 | QMap<QString, State*>::Iterator it; | ||
539 | for(it = states.begin(); it != states.end(); ++it) { | ||
540 | State* state = it.data(); | ||
541 | |||
542 | for(int i = 0; i < 0x1100; i++) { | ||
543 | Action* action = state->get(i, false); | ||
544 | if (action!=0 && action->getState()==s) { | ||
545 | ret.append(action); | ||
546 | } | ||
547 | |||
548 | action = state->get(i, true); | ||
549 | if (action!=0 && action->getState()==s) { | ||
550 | ret.append(action); | ||
551 | } | ||
552 | } | ||
553 | } | ||
554 | |||
555 | return ret; | ||
556 | } | ||
557 | |||
558 | void Keymap::generateLabelStateMaps() { | ||
559 | stateLabelMap.clear(); | ||
560 | |||
561 | QMap<QString, QString>::Iterator lit; | ||
562 | for(lit = labels.begin(); lit != labels.end(); ++lit) { | ||
563 | QString label = lit.key(); | ||
564 | QString name = lit.data(); | ||
565 | |||
566 | bool wc = false; | ||
567 | int n = name.find("*"); | ||
568 | if (n>=0 && n==(int)(name.length()-1)) { | ||
569 | name=name.left(name.length() - 1); | ||
570 | wc = true; | ||
571 | } | ||
572 | |||
573 | QMap<QString, State*>::Iterator sit; | ||
574 | for(sit = states.begin(); sit != states.end(); ++sit) { | ||
575 | QString sname = sit.key(); | ||
576 | State* state = sit.data(); | ||
577 | |||
578 | if (sname.length() < name.length()) { | ||
579 | continue; | ||
580 | } | ||
581 | |||
582 | if (sname.left(name.length()) == name) { | ||
583 | if (wc || sname.length()==name.length()) { | ||
584 | stateLabelMap.insert(state, label); | ||
585 | } | ||
586 | |||
587 | } | ||
588 | } | ||
589 | } | ||
590 | |||
591 | lsmapInSync = true; | ||
592 | } | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkb.h b/noncore/applets/zkbapplet/keyzcfg/zkb.h new file mode 100644 index 0000000..deff869 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkb.h | |||
@@ -0,0 +1,205 @@ | |||
1 | #ifndef ZKB_H | ||
2 | #define ZKB_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qmap.h> | ||
7 | #include <qwindowsystem_qws.h> | ||
8 | #include <qkeyboard_qws.h> | ||
9 | #include <qtimer.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | class State; | ||
13 | |||
14 | class Action { | ||
15 | protected: | ||
16 | State* state; | ||
17 | ushort keycode; | ||
18 | ushort unicode; | ||
19 | int flags; | ||
20 | |||
21 | enum { | ||
22 | Shift_Mod = 1, | ||
23 | Ctrl_Mod = 2, | ||
24 | Alt_Mod = 4, | ||
25 | Keypad_Mod = 8, | ||
26 | Mod_Bits = 15, | ||
27 | Press = 16, | ||
28 | Autorepeat = 32, | ||
29 | Event = 64, | ||
30 | Defined = 128, | ||
31 | }; | ||
32 | |||
33 | void setDefined(bool); | ||
34 | |||
35 | public: | ||
36 | Action(); | ||
37 | Action(State*, ushort, ushort, int); | ||
38 | ~Action(); | ||
39 | |||
40 | State* getState() const; | ||
41 | void setState(State*); | ||
42 | |||
43 | bool hasEvent() const; | ||
44 | void setEvent(bool); | ||
45 | |||
46 | bool isDefined() const; | ||
47 | |||
48 | int getKeycode() const; | ||
49 | void setKeycode(int); | ||
50 | |||
51 | int getUnicode() const; | ||
52 | void setUnicode(int); | ||
53 | |||
54 | int getModifiers() const; | ||
55 | void setModifiers(int m); | ||
56 | |||
57 | bool isPressed() const; | ||
58 | void setPressed(bool); | ||
59 | |||
60 | bool isAutorepeat() const; | ||
61 | void setAutorepeat(bool); | ||
62 | }; | ||
63 | |||
64 | class State { | ||
65 | protected: | ||
66 | State* parent; | ||
67 | Action* keys; | ||
68 | |||
69 | enum { | ||
70 | Key_a=0, | ||
71 | Key_b=1, | ||
72 | Key_c=2, | ||
73 | Key_d=3, | ||
74 | Key_e=4, | ||
75 | Key_f=5, | ||
76 | Key_g=6, | ||
77 | Key_h=7, | ||
78 | Key_i=8, | ||
79 | Key_j=9, | ||
80 | Key_k=10, | ||
81 | Key_l=11, | ||
82 | Key_m=12, | ||
83 | Key_n=13, | ||
84 | Key_o=14, | ||
85 | Key_p=15, | ||
86 | Key_q=16, | ||
87 | Key_r=17, | ||
88 | Key_s=18, | ||
89 | Key_t=19, | ||
90 | Key_u=20, | ||
91 | Key_v=21, | ||
92 | Key_w=22, | ||
93 | Key_x=23, | ||
94 | Key_y=24, | ||
95 | Key_z=25, | ||
96 | Key_Comma=26, | ||
97 | Key_Slash=27, | ||
98 | Key_Quote=28, | ||
99 | Key_Dot=29, | ||
100 | Key_Backspace=30, | ||
101 | Key_Space=31, | ||
102 | Key_Enter=32, | ||
103 | Key_LeftShift=33, | ||
104 | Key_RightShift=34, | ||
105 | Key_Fn=35, | ||
106 | Key_Tab=36, | ||
107 | Key_Calendar=37, | ||
108 | Key_Addressbook=38, | ||
109 | Key_Home=39, | ||
110 | Key_Menu=40, | ||
111 | Key_Mail=41, | ||
112 | Key_Cancel=42, | ||
113 | Key_OK=43, | ||
114 | Key_Left=44, | ||
115 | Key_Up=45, | ||
116 | Key_Right=46, | ||
117 | Key_Down=47, | ||
118 | Key_Middle=48, | ||
119 | Key_Off=49, | ||
120 | Key_Light=50, | ||
121 | |||
122 | Key_Max=51 | ||
123 | }; | ||
124 | |||
125 | static const short x1[]; | ||
126 | static const short x2[]; | ||
127 | |||
128 | int translateKeycode(int keycode) const; | ||
129 | |||
130 | public: | ||
131 | State(State* parent=0); | ||
132 | State(const State&); | ||
133 | ~State(); | ||
134 | |||
135 | Action* get(int keycode, bool pressed, bool follow = false) const; | ||
136 | bool set(int keycode, bool pressed, Action& action); | ||
137 | |||
138 | State* getParent() const; | ||
139 | void setParent(State*); | ||
140 | }; | ||
141 | |||
142 | class Keymap : public QObject, public QWSServer::KeyboardFilter { | ||
143 | Q_OBJECT | ||
144 | |||
145 | public: | ||
146 | Keymap(); | ||
147 | virtual ~Keymap(); | ||
148 | |||
149 | virtual bool filter(int unicode, int keycode, int modifiers, | ||
150 | bool isPress, bool autoRepeat); | ||
151 | |||
152 | void enable(); | ||
153 | void disable(); | ||
154 | |||
155 | QStringList listStates(); | ||
156 | State* getStateByName(const QString& name); | ||
157 | |||
158 | QStringList listLabels(); | ||
159 | State* getStateByLabel(const QString& label); | ||
160 | |||
161 | bool addState(const QString& name, State* state); | ||
162 | bool removeState(const QString& name, bool force = false); | ||
163 | bool setCurrentState(State*); | ||
164 | State* getCurrentState() const; | ||
165 | QString getCurrentLabel(); | ||
166 | |||
167 | bool addLabel(const QString& label, const QString& state, | ||
168 | int index=-1); | ||
169 | bool removeLabel(const QString& label); | ||
170 | |||
171 | int getAutorepeatDelay() const; | ||
172 | void setAutorepeatDelay(int); | ||
173 | |||
174 | int getAutorepeatPeriod() const; | ||
175 | void setAutorepeatPeriod(int); | ||
176 | |||
177 | signals: | ||
178 | void stateChanged(const QString& name); | ||
179 | |||
180 | protected slots: | ||
181 | void autoRepeat(); | ||
182 | |||
183 | protected: | ||
184 | QMap<QString, State*> states; | ||
185 | QMap<QString, QString> labels; | ||
186 | QStringList labelList; | ||
187 | |||
188 | QMap<State*,QString> stateLabelMap; | ||
189 | bool lsmapInSync; | ||
190 | |||
191 | bool enabled; | ||
192 | State* currentState; | ||
193 | QString currentStateName; | ||
194 | QString currentLabel; | ||
195 | Action* autoRepeatAction; | ||
196 | |||
197 | int repeatDelay; | ||
198 | int repeatPeriod; | ||
199 | QTimer repeater; | ||
200 | |||
201 | QList<Action> findStateUsage(State* s); | ||
202 | void generateLabelStateMaps(); | ||
203 | }; | ||
204 | |||
205 | #endif | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp b/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp new file mode 100644 index 0000000..24bd897 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp | |||
@@ -0,0 +1,231 @@ | |||
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 | } | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbcfg.h b/noncore/applets/zkbapplet/keyzcfg/zkbcfg.h new file mode 100644 index 0000000..dc1ac07 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkbcfg.h | |||
@@ -0,0 +1,69 @@ | |||
1 | #ifndef ZKBCFG_H | ||
2 | #define ZKBCFG_H | ||
3 | |||
4 | #include <qxml.h> | ||
5 | #include "zkb.h" | ||
6 | #include "zkbxml.h" | ||
7 | |||
8 | class ZkbConfig : public QXmlErrorHandler { | ||
9 | public: | ||
10 | ZkbConfig(const QString& dir); | ||
11 | virtual ~ZkbConfig(); | ||
12 | |||
13 | bool load(const QString& file, Keymap& keymap, const QString& prefix); | ||
14 | |||
15 | virtual bool warning(const QXmlParseException& e); | ||
16 | virtual bool error(const QXmlParseException& e); | ||
17 | virtual bool fatalError(const QXmlParseException& e); | ||
18 | virtual QString errorString(); | ||
19 | |||
20 | protected: | ||
21 | QString path; | ||
22 | QMap<QString, int> includedFiles; | ||
23 | QString err; | ||
24 | }; | ||
25 | |||
26 | class ZkbHandler : public ZkbXmlHandler { | ||
27 | public: | ||
28 | ZkbHandler(ZkbConfig& zkc, Keymap& keymap, const QString& prefix); | ||
29 | virtual ~ZkbHandler(); | ||
30 | |||
31 | protected: | ||
32 | ZkbConfig& zkc; | ||
33 | Keymap& keymap; | ||
34 | QString prefix; | ||
35 | |||
36 | // stuff for keymap tag | ||
37 | int ardelay; | ||
38 | int arperiod; | ||
39 | |||
40 | // stuff for state tag | ||
41 | QString currentStateName; | ||
42 | State* currentState; | ||
43 | |||
44 | // stuff for map tag | ||
45 | Action* currentAction; | ||
46 | |||
47 | virtual bool startKeymapElement(int ardelay, int arperiod, | ||
48 | const QString& author); | ||
49 | virtual bool startIncludeElement(const QString& file, | ||
50 | const QString& prfix); | ||
51 | virtual bool startLabelElement(const QString& label, | ||
52 | const QString& state); | ||
53 | virtual bool startStateElement(const QString& name, | ||
54 | const QString& parent, bool dflt); | ||
55 | virtual bool startMapElement(int key, bool pressed); | ||
56 | virtual bool startEventElement(int keycode, int unicode, int modifiers, | ||
57 | bool pressed, bool autorepeat); | ||
58 | virtual bool startNextStateElement(const QString& state); | ||
59 | |||
60 | virtual bool endKeymapElement(); | ||
61 | virtual bool endIncludeElement(); | ||
62 | virtual bool endLabelElement(); | ||
63 | virtual bool endStateElement(); | ||
64 | virtual bool endMapElement(); | ||
65 | virtual bool endEventElement(); | ||
66 | virtual bool endNextStateElement(); | ||
67 | }; | ||
68 | |||
69 | #endif | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp b/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp new file mode 100644 index 0000000..b2180ba --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp | |||
@@ -0,0 +1,446 @@ | |||
1 | #include <qmap.h> | ||
2 | |||
3 | #include "zkbnames.h" | ||
4 | |||
5 | QString Null_String((const char*) 0); | ||
6 | |||
7 | // Implementation of KeyNames | ||
8 | static struct { | ||
9 | int key; | ||
10 | char *name; | ||
11 | } Key_Names[] = { | ||
12 | { 32, "Space" }, | ||
13 | { 39, "Apostrophe" }, | ||
14 | { 44, "Comma" }, | ||
15 | { 46, "Period" }, | ||
16 | { 47, "Slash" }, | ||
17 | { 65, "A" }, | ||
18 | { 66, "B" }, | ||
19 | { 67, "C" }, | ||
20 | { 68, "D" }, | ||
21 | { 69, "E" }, | ||
22 | { 70, "F" }, | ||
23 | { 71, "G" }, | ||
24 | { 72, "H" }, | ||
25 | { 73, "I" }, | ||
26 | { 74, "J" }, | ||
27 | { 75, "K" }, | ||
28 | { 76, "L" }, | ||
29 | { 77, "M" }, | ||
30 | { 78, "N" }, | ||
31 | { 79, "O" }, | ||
32 | { 80, "P" }, | ||
33 | { 81, "Q" }, | ||
34 | { 82, "R" }, | ||
35 | { 83, "S" }, | ||
36 | { 84, "T" }, | ||
37 | { 85, "U" }, | ||
38 | { 86, "V" }, | ||
39 | { 87, "W" }, | ||
40 | { 88, "X" }, | ||
41 | { 89, "Y" }, | ||
42 | { 90, "Z" }, | ||
43 | { 4096, "Cancel" }, | ||
44 | { 4097, "Tab" }, | ||
45 | { 4099, "Backspace" }, | ||
46 | { 4100, "Enter" }, | ||
47 | { 4114, "Left" }, | ||
48 | { 4115, "Up" }, | ||
49 | { 4116, "Right" }, | ||
50 | { 4117, "Down" }, | ||
51 | { 4128, "Left Shift" }, | ||
52 | { 4130, "Right Shift" }, | ||
53 | { 4152, "Calendar" }, | ||
54 | { 4153, "Addressbook" }, | ||
55 | { 4154, "Menu" }, | ||
56 | { 4155, "Home" }, | ||
57 | { 4156, "Mail" }, | ||
58 | { 4165, "Fn" }, | ||
59 | { 4173, "Middle" }, | ||
60 | { 4176, "OK" }, | ||
61 | { 4177, "Off" }, | ||
62 | { 4178, "Light" }, | ||
63 | { 0, 0 } | ||
64 | }; | ||
65 | |||
66 | static QMap<QString, int> kn_map; | ||
67 | static QMap<int, QString> kn_rmap; | ||
68 | |||
69 | void init_kn_maps() { | ||
70 | int i = 0; | ||
71 | while (Key_Names[i].name != 0) { | ||
72 | int key = Key_Names[i].key; | ||
73 | QString name(Key_Names[i].name); | ||
74 | |||
75 | kn_map.insert(name, key); | ||
76 | kn_rmap.insert(key, name); | ||
77 | i++; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | int KeyNames::find(const QString& key) { | ||
82 | if (kn_map.isEmpty()) { | ||
83 | init_kn_maps(); | ||
84 | } | ||
85 | |||
86 | QMap<QString, int>::Iterator it = kn_map.find(key); | ||
87 | if (it == kn_map.end()) { | ||
88 | return -1; | ||
89 | } else { | ||
90 | return it.data(); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | const QString& KeyNames::find(int k) { | ||
95 | if (kn_map.isEmpty()) { | ||
96 | init_kn_maps(); | ||
97 | } | ||
98 | |||
99 | QMap<int, QString>::Iterator it = kn_rmap.find(k); | ||
100 | if (it == kn_rmap.end()) { | ||
101 | return Null_String; | ||
102 | } else { | ||
103 | return it.data(); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | // Implementation of ModifierNames | ||
108 | struct { | ||
109 | int value; | ||
110 | char* name; | ||
111 | } Modifier_Names[] = { | ||
112 | { 8, "Shift" }, | ||
113 | { 16, "Control" }, | ||
114 | { 32, "Alt" }, | ||
115 | { 0x4000, "Keypad" }, | ||
116 | { 0, 0 } | ||
117 | }; | ||
118 | |||
119 | static QMap<QString, int> mn_map; | ||
120 | static QMap<int, QString> mn_rmap; | ||
121 | |||
122 | void init_mn_maps() { | ||
123 | int i = 0; | ||
124 | while (Modifier_Names[i].name != 0) { | ||
125 | int value = Modifier_Names[i].value; | ||
126 | QString name(Modifier_Names[i].name); | ||
127 | |||
128 | mn_map.insert(name, value); | ||
129 | mn_rmap.insert(value, name); | ||
130 | i++; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | int ModifierNames::find(const QString& key) { | ||
135 | if (mn_map.isEmpty()) { | ||
136 | init_mn_maps(); | ||
137 | } | ||
138 | |||
139 | QMap<QString, int>::Iterator it = mn_map.find(key); | ||
140 | if (it == mn_map.end()) { | ||
141 | return -1; | ||
142 | } else { | ||
143 | return it.data(); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | const QString& ModifierNames::find(int k) { | ||
148 | if (mn_map.isEmpty()) { | ||
149 | init_mn_maps(); | ||
150 | } | ||
151 | |||
152 | QMap<int, QString>::Iterator it = mn_rmap.find(k); | ||
153 | if (it == mn_rmap.end()) { | ||
154 | return Null_String; | ||
155 | } else { | ||
156 | return it.data(); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | // Implementation of KeycodeNames | ||
161 | |||
162 | struct { | ||
163 | char* name; | ||
164 | int keycode; | ||
165 | } Keycode_Names[] = { | ||
166 | { "Escape", 0x1000 }, | ||
167 | { "Tab", 0x1001 }, | ||
168 | { "Backtab", 0x1002 }, | ||
169 | { "Backspace", 0x1003 }, | ||
170 | { "BackSpace", 0x1003 }, | ||
171 | { "Return", 0x1004 }, | ||
172 | { "Enter", 0x1005 }, | ||
173 | { "Insert", 0x1006 }, | ||
174 | { "Delete", 0x1007 }, | ||
175 | { "Pause", 0x1008 }, | ||
176 | { "Print", 0x1009 }, | ||
177 | { "SysReq", 0x100a }, | ||
178 | { "Home", 0x1010 }, | ||
179 | { "End", 0x1011 }, | ||
180 | { "Left", 0x1012 }, | ||
181 | { "Up", 0x1013 }, | ||
182 | { "Right", 0x1014 }, | ||
183 | { "Down", 0x1015 }, | ||
184 | { "Prior", 0x1016 }, | ||
185 | { "PageUp", 0x1016 }, | ||
186 | { "Next", 0x1017 }, | ||
187 | { "PageDown", 0x1017 }, | ||
188 | { "Shift", 0x1020 }, | ||
189 | { "Control", 0x1021 }, | ||
190 | { "Meta", 0x1022 }, | ||
191 | { "Alt", 0x1023 }, | ||
192 | { "CapsLock", 0x1024 }, | ||
193 | { "NumLock", 0x1025 }, | ||
194 | { "ScrollLock", 0x1026 }, | ||
195 | { "F1", 0x1030 }, | ||
196 | { "F2", 0x1031 }, | ||
197 | { "F3", 0x1032 }, | ||
198 | { "F4", 0x1033 }, | ||
199 | { "F5", 0x1034 }, | ||
200 | { "F6", 0x1035 }, | ||
201 | { "F7", 0x1036 }, | ||
202 | { "F8", 0x1037 }, | ||
203 | { "F9", 0x1038 }, | ||
204 | { "F10", 0x1039 }, | ||
205 | { "F11", 0x103a }, | ||
206 | { "F12", 0x103b }, | ||
207 | { "F13", 0x103c }, | ||
208 | { "F14", 0x103d }, | ||
209 | { "F15", 0x103e }, | ||
210 | { "F16", 0x103f }, | ||
211 | { "F17", 0x1040 }, | ||
212 | { "F18", 0x1041 }, | ||
213 | { "F19", 0x1042 }, | ||
214 | { "F20", 0x1043 }, | ||
215 | { "F21", 0x1044 }, | ||
216 | { "F22", 0x1045 }, | ||
217 | { "F23", 0x1046 }, | ||
218 | { "F24", 0x1047 }, | ||
219 | { "F25", 0x1048 }, | ||
220 | { "F26", 0x1049 }, | ||
221 | { "F27", 0x104a }, | ||
222 | { "F28", 0x104b }, | ||
223 | { "F29", 0x104c }, | ||
224 | { "F30", 0x104d }, | ||
225 | { "F31", 0x104e }, | ||
226 | { "F32", 0x104f }, | ||
227 | { "F33", 0x1050 }, | ||
228 | { "F34", 0x1051 }, | ||
229 | { "F35", 0x1052 }, | ||
230 | { "Super_L", 0x1053 }, | ||
231 | { "Super_R", 0x1054 }, | ||
232 | { "Menu", 0x1055 }, | ||
233 | { "Hyper_L", 0x1056 }, | ||
234 | { "Hyper_R", 0x1057 }, | ||
235 | { "Help", 0x1058 }, | ||
236 | { "Space", 0x20 }, | ||
237 | { "Any", 0x20 }, | ||
238 | { "Exclam", 0x21 }, | ||
239 | { "QuoteDbl", 0x22 }, | ||
240 | { "NumberSign", 0x23 }, | ||
241 | { "Dollar", 0x24 }, | ||
242 | { "Percent", 0x25 }, | ||
243 | { "Ampersand", 0x26 }, | ||
244 | { "Apostrophe", 0x27 }, | ||
245 | { "ParenLeft", 0x28 }, | ||
246 | { "ParenRight", 0x29 }, | ||
247 | { "Asterisk", 0x2a }, | ||
248 | { "Plus", 0x2b }, | ||
249 | { "Comma", 0x2c }, | ||
250 | { "Minus", 0x2d }, | ||
251 | { "Period", 0x2e }, | ||
252 | { "Slash", 0x2f }, | ||
253 | { "0", 0x30 }, | ||
254 | { "1", 0x31 }, | ||
255 | { "2", 0x32 }, | ||
256 | { "3", 0x33 }, | ||
257 | { "4", 0x34 }, | ||
258 | { "5", 0x35 }, | ||
259 | { "6", 0x36 }, | ||
260 | { "7", 0x37 }, | ||
261 | { "8", 0x38 }, | ||
262 | { "9", 0x39 }, | ||
263 | { "Colon", 0x3a }, | ||
264 | { "Semicolon", 0x3b }, | ||
265 | { "Less", 0x3c }, | ||
266 | { "Equal", 0x3d }, | ||
267 | { "Greater", 0x3e }, | ||
268 | { "Question", 0x3f }, | ||
269 | { "At", 0x40 }, | ||
270 | { "A", 0x41 }, | ||
271 | { "B", 0x42 }, | ||
272 | { "C", 0x43 }, | ||
273 | { "D", 0x44 }, | ||
274 | { "E", 0x45 }, | ||
275 | { "F", 0x46 }, | ||
276 | { "G", 0x47 }, | ||
277 | { "H", 0x48 }, | ||
278 | { "I", 0x49 }, | ||
279 | { "J", 0x4a }, | ||
280 | { "K", 0x4b }, | ||
281 | { "L", 0x4c }, | ||
282 | { "M", 0x4d }, | ||
283 | { "N", 0x4e }, | ||
284 | { "O", 0x4f }, | ||
285 | { "P", 0x50 }, | ||
286 | { "Q", 0x51 }, | ||
287 | { "R", 0x52 }, | ||
288 | { "S", 0x53 }, | ||
289 | { "T", 0x54 }, | ||
290 | { "U", 0x55 }, | ||
291 | { "V", 0x56 }, | ||
292 | { "W", 0x57 }, | ||
293 | { "X", 0x58 }, | ||
294 | { "Y", 0x59 }, | ||
295 | { "Z", 0x5a }, | ||
296 | { "BracketLeft", 0x5b }, | ||
297 | { "Backslash", 0x5c }, | ||
298 | { "BracketRight", 0x5d }, | ||
299 | { "AsciiCircum", 0x5e }, | ||
300 | { "Underscore", 0x5f }, | ||
301 | { "QuoteLeft", 0x60 }, | ||
302 | { "BraceLeft", 0x7b }, | ||
303 | { "Bar", 0x7c }, | ||
304 | { "BraceRight", 0x7d }, | ||
305 | { "AsciiTilde", 0x7e }, | ||
306 | { "nobreakspace", 0x0a0 }, | ||
307 | { "exclamdown", 0x0a1 }, | ||
308 | { "cent", 0x0a2 }, | ||
309 | { "sterling", 0x0a3 }, | ||
310 | { "currency", 0x0a4 }, | ||
311 | { "yen", 0x0a5 }, | ||
312 | { "brokenbar", 0x0a6 }, | ||
313 | { "section", 0x0a7 }, | ||
314 | { "diaeresis", 0x0a8 }, | ||
315 | { "copyright", 0x0a9 }, | ||
316 | { "ordfeminine", 0x0aa }, | ||
317 | { "guillemotleft", 0x0ab }, | ||
318 | { "notsign", 0x0ac }, | ||
319 | { "hyphen", 0x0ad }, | ||
320 | { "registered", 0x0ae }, | ||
321 | { "macron", 0x0af }, | ||
322 | { "degree", 0x0b0 }, | ||
323 | { "plusminus", 0x0b1 }, | ||
324 | { "twosuperior", 0x0b2 }, | ||
325 | { "threesuperior", 0x0b3 }, | ||
326 | { "acute", 0x0b4 }, | ||
327 | { "mu", 0x0b5 }, | ||
328 | { "paragraph", 0x0b6 }, | ||
329 | { "periodcentered", 0x0b7 }, | ||
330 | { "cedilla", 0x0b8 }, | ||
331 | { "onesuperior", 0x0b9 }, | ||
332 | { "masculine", 0x0ba }, | ||
333 | { "guillemotright", 0x0bb }, | ||
334 | { "onequarter", 0x0bc }, | ||
335 | { "onehalf", 0x0bd }, | ||
336 | { "threequarters", 0x0be }, | ||
337 | { "questiondown", 0x0bf }, | ||
338 | { "Agrave", 0x0c0 }, | ||
339 | { "Aacute", 0x0c1 }, | ||
340 | { "Acircumflex", 0x0c2 }, | ||
341 | { "Atilde", 0x0c3 }, | ||
342 | { "Adiaeresis", 0x0c4 }, | ||
343 | { "Aring", 0x0c5 }, | ||
344 | { "AE", 0x0c6 }, | ||
345 | { "Ccedilla", 0x0c7 }, | ||
346 | { "Egrave", 0x0c8 }, | ||
347 | { "Eacute", 0x0c9 }, | ||
348 | { "Ecircumflex", 0x0ca }, | ||
349 | { "Ediaeresis", 0x0cb }, | ||
350 | { "Igrave", 0x0cc }, | ||
351 | { "Iacute", 0x0cd }, | ||
352 | { "Icircumflex", 0x0ce }, | ||
353 | { "Idiaeresis", 0x0cf }, | ||
354 | { "ETH", 0x0d0 }, | ||
355 | { "Ntilde", 0x0d1 }, | ||
356 | { "Ograve", 0x0d2 }, | ||
357 | { "Oacute", 0x0d3 }, | ||
358 | { "Ocircumflex", 0x0d4 }, | ||
359 | { "Otilde", 0x0d5 }, | ||
360 | { "Odiaeresis", 0x0d6 }, | ||
361 | { "multiply", 0x0d7 }, | ||
362 | { "Ooblique", 0x0d8 }, | ||
363 | { "Ugrave", 0x0d9 }, | ||
364 | { "Uacute", 0x0da }, | ||
365 | { "Ucircumflex", 0x0db }, | ||
366 | { "Udiaeresis", 0x0dc }, | ||
367 | { "Yacute", 0x0dd }, | ||
368 | { "THORN", 0x0de }, | ||
369 | { "ssharp", 0x0df }, | ||
370 | { "agrave", 0x0e0 }, | ||
371 | { "aacute", 0x0e1 }, | ||
372 | { "acircumflex", 0x0e2 }, | ||
373 | { "atilde", 0x0e3 }, | ||
374 | { "adiaeresis", 0x0e4 }, | ||
375 | { "aring", 0x0e5 }, | ||
376 | { "ae", 0x0e6 }, | ||
377 | { "ccedilla", 0x0e7 }, | ||
378 | { "egrave", 0x0e8 }, | ||
379 | { "eacute", 0x0e9 }, | ||
380 | { "ecircumflex", 0x0ea }, | ||
381 | { "ediaeresis", 0x0eb }, | ||
382 | { "igrave", 0x0ec }, | ||
383 | { "iacute", 0x0ed }, | ||
384 | { "icircumflex", 0x0ee }, | ||
385 | { "idiaeresis", 0x0ef }, | ||
386 | { "eth", 0x0f0 }, | ||
387 | { "ntilde", 0x0f1 }, | ||
388 | { "ograve", 0x0f2 }, | ||
389 | { "oacute", 0x0f3 }, | ||
390 | { "ocircumflex", 0x0f4 }, | ||
391 | { "otilde", 0x0f5 }, | ||
392 | { "odiaeresis", 0x0f6 }, | ||
393 | { "division", 0x0f7 }, | ||
394 | { "oslash", 0x0f8 }, | ||
395 | { "ugrave", 0x0f9 }, | ||
396 | { "uacute", 0x0fa }, | ||
397 | { "ucircumflex", 0x0fb }, | ||
398 | { "udiaeresis", 0x0fc }, | ||
399 | { "yacute", 0x0fd }, | ||
400 | { "thorn", 0x0fe }, | ||
401 | { "ydiaeresis", 0x0ff }, | ||
402 | { "unknown", 0xffff }, | ||
403 | { 0, 0} | ||
404 | }; | ||
405 | |||
406 | static QMap<QString, int> kcn_map; | ||
407 | static QMap<int, QString> kcn_rmap; | ||
408 | |||
409 | void init_kcn_maps() { | ||
410 | int i = 0; | ||
411 | while (Keycode_Names[i].name != 0) { | ||
412 | int keycode = Keycode_Names[i].keycode; | ||
413 | QString name(Keycode_Names[i].name); | ||
414 | |||
415 | kcn_map.insert(name, keycode); | ||
416 | kcn_rmap.insert(keycode, name); | ||
417 | i++; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | int KeycodeNames::find(const QString& key) { | ||
422 | if (kcn_map.isEmpty()) { | ||
423 | init_kcn_maps(); | ||
424 | } | ||
425 | |||
426 | QMap<QString, int>::Iterator it = kcn_map.find(key); | ||
427 | if (it == kcn_map.end()) { | ||
428 | return -1; | ||
429 | } else { | ||
430 | return it.data(); | ||
431 | } | ||
432 | } | ||
433 | |||
434 | const QString& KeycodeNames::find(int k) { | ||
435 | if (kcn_map.isEmpty()) { | ||
436 | init_kcn_maps(); | ||
437 | } | ||
438 | |||
439 | QMap<int, QString>::Iterator it = kcn_rmap.find(k); | ||
440 | if (it == kcn_rmap.end()) { | ||
441 | return Null_String; | ||
442 | } else { | ||
443 | return it.data(); | ||
444 | } | ||
445 | } | ||
446 | |||
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbnames.h b/noncore/applets/zkbapplet/keyzcfg/zkbnames.h new file mode 100644 index 0000000..0d1e7f5 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkbnames.h | |||
@@ -0,0 +1,23 @@ | |||
1 | #ifndef ZKBNAMES_H | ||
2 | #define ZKBNAMES_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | |||
6 | class KeyNames { | ||
7 | public: | ||
8 | static int find(const QString& key); | ||
9 | static const QString& find(int); | ||
10 | }; | ||
11 | |||
12 | class KeycodeNames { | ||
13 | public: | ||
14 | static int find(const QString& key); | ||
15 | static const QString& find(int); | ||
16 | }; | ||
17 | |||
18 | class ModifierNames { | ||
19 | public: | ||
20 | static int find(const QString& key); | ||
21 | static const QString& find(int); | ||
22 | }; | ||
23 | #endif | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbxml.cpp b/noncore/applets/zkbapplet/keyzcfg/zkbxml.cpp new file mode 100644 index 0000000..5b0084c --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkbxml.cpp | |||
@@ -0,0 +1,573 @@ | |||
1 | #include "zkbxml.h" | ||
2 | #include "zkbnames.h" | ||
3 | |||
4 | static QString Keymap_Tag("keymap"); | ||
5 | static QString Include_Tag("include"); | ||
6 | static QString Label_Tag("label"); | ||
7 | static QString State_Tag("state"); | ||
8 | static QString Map_Tag("map"); | ||
9 | static QString Event_Tag("event"); | ||
10 | static QString NextState_Tag("next-state"); | ||
11 | |||
12 | ZkbXmlHandler::ZkbXmlHandler() { | ||
13 | } | ||
14 | |||
15 | ZkbXmlHandler::~ZkbXmlHandler() { | ||
16 | } | ||
17 | |||
18 | bool ZkbXmlHandler::startElement(const QString&, const QString&, | ||
19 | const QString& name, const QXmlAttributes& attr) { | ||
20 | |||
21 | bool ret = false; | ||
22 | |||
23 | if (name == Keymap_Tag) { | ||
24 | ret = start_keymap(attr); | ||
25 | } else if (name == Include_Tag) { | ||
26 | ret = start_include(attr); | ||
27 | } else if (name == Label_Tag) { | ||
28 | ret = start_label(attr); | ||
29 | } else if (name == State_Tag) { | ||
30 | ret = start_state(attr); | ||
31 | } else if (name == Map_Tag) { | ||
32 | ret = start_map(attr); | ||
33 | } else if (name == Event_Tag) { | ||
34 | ret = start_event(attr); | ||
35 | } else if (name == NextState_Tag) { | ||
36 | ret = start_next_state(attr); | ||
37 | } | ||
38 | |||
39 | elements.prepend(name); | ||
40 | |||
41 | return ret; | ||
42 | } | ||
43 | |||
44 | bool ZkbXmlHandler::endElement(const QString&, const QString&, | ||
45 | const QString& name) { | ||
46 | |||
47 | bool ret = false; | ||
48 | |||
49 | elements.remove(elements.begin()); | ||
50 | |||
51 | if (name == Keymap_Tag) { | ||
52 | ret = end_keymap(); | ||
53 | } else if (name == Include_Tag) { | ||
54 | ret = end_include(); | ||
55 | } else if (name == Label_Tag) { | ||
56 | ret = end_label(); | ||
57 | } else if (name == State_Tag) { | ||
58 | ret = end_state(); | ||
59 | } else if (name == Map_Tag) { | ||
60 | ret = end_map(); | ||
61 | } else if (name == Event_Tag) { | ||
62 | ret = end_event(); | ||
63 | } else if (name == NextState_Tag) { | ||
64 | ret = end_next_state(); | ||
65 | } | ||
66 | |||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | QString ZkbXmlHandler::errorString() { | ||
71 | return err; | ||
72 | } | ||
73 | |||
74 | bool ZkbXmlHandler::startKeymapElement(int ardelay, int arperiod, const QString& author) { | ||
75 | return false; | ||
76 | } | ||
77 | |||
78 | bool ZkbXmlHandler::startIncludeElement(const QString& file, | ||
79 | const QString& prefix) { | ||
80 | |||
81 | return false; | ||
82 | } | ||
83 | |||
84 | bool ZkbXmlHandler::startLabelElement(const QString& label, | ||
85 | const QString& state) { | ||
86 | |||
87 | return false; | ||
88 | } | ||
89 | |||
90 | bool ZkbXmlHandler::startStateElement(const QString& name, | ||
91 | const QString& parent, bool dflt) { | ||
92 | |||
93 | return false; | ||
94 | } | ||
95 | |||
96 | bool ZkbXmlHandler::startMapElement(int keycode, bool pressed) { | ||
97 | return false; | ||
98 | } | ||
99 | |||
100 | bool ZkbXmlHandler::startEventElement(int keycode, int unicode, int modifiers, | ||
101 | bool pressed, bool autorepeat) { | ||
102 | |||
103 | return false; | ||
104 | } | ||
105 | |||
106 | bool ZkbXmlHandler::startNextStateElement(const QString& state) { | ||
107 | return false; | ||
108 | } | ||
109 | |||
110 | |||
111 | bool ZkbXmlHandler::endKeymapElement() { | ||
112 | return false; | ||
113 | } | ||
114 | |||
115 | bool ZkbXmlHandler::endIncludeElement() { | ||
116 | return false; | ||
117 | } | ||
118 | |||
119 | bool ZkbXmlHandler::endLabelElement() { | ||
120 | return false; | ||
121 | } | ||
122 | |||
123 | bool ZkbXmlHandler::endStateElement() { | ||
124 | return false; | ||
125 | } | ||
126 | |||
127 | bool ZkbXmlHandler::endMapElement() { | ||
128 | return false; | ||
129 | } | ||
130 | |||
131 | bool ZkbXmlHandler::endEventElement() { | ||
132 | return false; | ||
133 | } | ||
134 | |||
135 | bool ZkbXmlHandler::endNextStateElement() { | ||
136 | return false; | ||
137 | } | ||
138 | |||
139 | |||
140 | bool ZkbXmlHandler::start_keymap(const QXmlAttributes& attr) { | ||
141 | int nattr = 0; | ||
142 | int didx = attr.index("autorepeat-delay"); | ||
143 | int pidx = attr.index("autorepeat-period"); | ||
144 | int aidx = attr.index("author"); | ||
145 | int ard = -1; | ||
146 | int arp = -1; | ||
147 | QString author; | ||
148 | |||
149 | if (!elements.isEmpty()) { | ||
150 | setError("keymap element should be top-level element"); | ||
151 | return false; | ||
152 | } | ||
153 | |||
154 | if (didx >= 0) { | ||
155 | QString s = attr.value(didx); | ||
156 | bool ok; | ||
157 | |||
158 | ard = s.toInt(&ok); | ||
159 | if (!ok) { | ||
160 | setError("Invalid autorepeat-delay value: " + s); | ||
161 | return false; | ||
162 | } | ||
163 | |||
164 | nattr++; | ||
165 | } | ||
166 | |||
167 | if (pidx >= 0) { | ||
168 | QString s = attr.value(pidx); | ||
169 | bool ok; | ||
170 | |||
171 | arp = s.toInt(&ok); | ||
172 | if (!ok) { | ||
173 | setError("Invalid autorepeat-period value: " + s); | ||
174 | return false; | ||
175 | } | ||
176 | |||
177 | nattr++; | ||
178 | } | ||
179 | |||
180 | if (aidx >= 0) { | ||
181 | author = attr.value(aidx); | ||
182 | nattr++; | ||
183 | } | ||
184 | |||
185 | if (attr.length() > nattr) { | ||
186 | setError("Unsupported attributes"); | ||
187 | return false; | ||
188 | } | ||
189 | |||
190 | return startKeymapElement(ard, arp, author); | ||
191 | } | ||
192 | |||
193 | bool ZkbXmlHandler::start_include(const QXmlAttributes& attr) { | ||
194 | int nattr = 0; | ||
195 | int fidx = attr.index("file"); | ||
196 | int pidx = attr.index("prefix"); | ||
197 | QString file; | ||
198 | QString prefix((const char*) 0); | ||
199 | |||
200 | if (elements.first() != Keymap_Tag) { | ||
201 | setError("include element should be used only " | ||
202 | "within keymap element"); | ||
203 | return false; | ||
204 | } | ||
205 | |||
206 | if (fidx >= 0) { | ||
207 | file = attr.value(fidx); | ||
208 | nattr++; | ||
209 | } else { | ||
210 | setError("Missing file attribute"); | ||
211 | return false; | ||
212 | } | ||
213 | |||
214 | if (pidx >= 0) { | ||
215 | prefix = attr.value(pidx); | ||
216 | nattr++; | ||
217 | } | ||
218 | |||
219 | if (attr.length() > nattr) { | ||
220 | setError("Unsupported attributes"); | ||
221 | return false; | ||
222 | } | ||
223 | |||
224 | return startIncludeElement(file, prefix); | ||
225 | } | ||
226 | |||
227 | bool ZkbXmlHandler::start_label(const QXmlAttributes& attr) { | ||
228 | int nattr = 0; | ||
229 | int nidx = attr.index("name"); | ||
230 | int sidx = attr.index("state"); | ||
231 | QString name; | ||
232 | QString state; | ||
233 | |||
234 | if (elements.first() != Keymap_Tag) { | ||
235 | setError("label element should be used only " | ||
236 | "within keymap element"); | ||
237 | return false; | ||
238 | } | ||
239 | |||
240 | if (nidx >= 0) { | ||
241 | name = attr.value(nidx); | ||
242 | nattr++; | ||
243 | } else { | ||
244 | setError("Missing name attribute"); | ||
245 | return false; | ||
246 | } | ||
247 | |||
248 | if (sidx >= 0) { | ||
249 | state = attr.value(sidx); | ||
250 | nattr++; | ||
251 | } else { | ||
252 | setError("Missing name attribute"); | ||
253 | return false; | ||
254 | } | ||
255 | |||
256 | if (attr.length() > nattr) { | ||
257 | setError("Unsupported attributes"); | ||
258 | return false; | ||
259 | } | ||
260 | |||
261 | return startLabelElement(name, state); | ||
262 | } | ||
263 | |||
264 | bool ZkbXmlHandler::start_state(const QXmlAttributes& attr) { | ||
265 | int nattr = 0; | ||
266 | int nidx = attr.index("name"); | ||
267 | int pidx = attr.index("parent"); | ||
268 | int didx = attr.index("default"); | ||
269 | QString name; | ||
270 | QString parent((const char*) 0); | ||
271 | bool dflt = false; | ||
272 | |||
273 | if (elements.first() != Keymap_Tag) { | ||
274 | setError("state element should be used only " | ||
275 | "within keymap element"); | ||
276 | return false; | ||
277 | } | ||
278 | |||
279 | if (nidx >= 0) { | ||
280 | name = attr.value(nidx); | ||
281 | nattr++; | ||
282 | } else { | ||
283 | setError("Missing name attribute"); | ||
284 | return false; | ||
285 | } | ||
286 | |||
287 | if (pidx >= 0) { | ||
288 | parent = attr.value(pidx); | ||
289 | nattr++; | ||
290 | } | ||
291 | |||
292 | if (didx >= 0) { | ||
293 | dflt = str2bool(attr.value(didx)); | ||
294 | if (!err.isEmpty()) { | ||
295 | return false; | ||
296 | } | ||
297 | |||
298 | nattr++; | ||
299 | } | ||
300 | |||
301 | if (attr.length() > nattr) { | ||
302 | setError("Unsupported attributes"); | ||
303 | return false; | ||
304 | } | ||
305 | |||
306 | return startStateElement(name, parent, dflt); | ||
307 | } | ||
308 | |||
309 | bool ZkbXmlHandler::start_map(const QXmlAttributes& attr) { | ||
310 | int nattr = 0; | ||
311 | int kidx = attr.index("keycode"); | ||
312 | int pidx = attr.index("pressed"); | ||
313 | int key; | ||
314 | bool pressed; | ||
315 | |||
316 | if (elements.first() != State_Tag) { | ||
317 | setError("map element should be used only " | ||
318 | "within state element"); | ||
319 | return false; | ||
320 | } | ||
321 | |||
322 | if (kidx >= 0) { | ||
323 | key = str2key(attr.value(kidx)); | ||
324 | if (!err.isEmpty()) { | ||
325 | return false; | ||
326 | } | ||
327 | nattr++; | ||
328 | } else { | ||
329 | setError("Missing keycode attribute"); | ||
330 | return false; | ||
331 | } | ||
332 | |||
333 | if (pidx >= 0) { | ||
334 | pressed = str2bool(attr.value(pidx)); | ||
335 | if (!err.isEmpty()) { | ||
336 | return false; | ||
337 | } | ||
338 | nattr++; | ||
339 | } else { | ||
340 | setError("Missing pressed attribute"); | ||
341 | return false; | ||
342 | } | ||
343 | |||
344 | if (attr.length() > nattr) { | ||
345 | setError("Unsupported attributes"); | ||
346 | return false; | ||
347 | } | ||
348 | |||
349 | return startMapElement(key, pressed); | ||
350 | } | ||
351 | |||
352 | bool ZkbXmlHandler::start_event(const QXmlAttributes& attr) { | ||
353 | int nattr = 0; | ||
354 | int kidx = attr.index("keycode"); | ||
355 | int pidx = attr.index("pressed"); | ||
356 | int uidx = attr.index("unicode"); | ||
357 | int midx = attr.index("modifiers"); | ||
358 | int aidx = attr.index("autorepeat"); | ||
359 | |||
360 | int keycode; | ||
361 | int unicode; | ||
362 | int modifiers = 0; | ||
363 | bool pressed; | ||
364 | bool autorepeat = false; | ||
365 | |||
366 | if (elements.first() != Map_Tag) { | ||
367 | setError("event element should be used only " | ||
368 | "within map element"); | ||
369 | return false; | ||
370 | } | ||
371 | |||
372 | if (kidx >= 0) { | ||
373 | keycode = str2keycode(attr.value(kidx)); | ||
374 | if (!err.isEmpty()) { | ||
375 | return false; | ||
376 | } | ||
377 | nattr++; | ||
378 | } else { | ||
379 | setError("Missing keycode attribute"); | ||
380 | return false; | ||
381 | } | ||
382 | |||
383 | if (uidx >= 0) { | ||
384 | unicode = str2unicode(attr.value(uidx)); | ||
385 | if (!err.isEmpty()) { | ||
386 | return false; | ||
387 | } | ||
388 | nattr++; | ||
389 | } else { | ||
390 | setError("Missing unicode attribute"); | ||
391 | return false; | ||
392 | } | ||
393 | |||
394 | if (midx >= 0) { | ||
395 | modifiers = str2modifier(attr.value(midx)); | ||
396 | if (!err.isEmpty()) { | ||
397 | return false; | ||
398 | } | ||
399 | nattr++; | ||
400 | } | ||
401 | |||
402 | if (pidx >= 0) { | ||
403 | pressed = str2bool(attr.value(pidx)); | ||
404 | if (!err.isEmpty()) { | ||
405 | return false; | ||
406 | } | ||
407 | nattr++; | ||
408 | } else { | ||
409 | setError("Missing pressed attribute"); | ||
410 | return false; | ||
411 | } | ||
412 | |||
413 | if (aidx >= 0) { | ||
414 | autorepeat = str2bool(attr.value(aidx)); | ||
415 | if (!err.isEmpty()) { | ||
416 | return false; | ||
417 | } | ||
418 | nattr++; | ||
419 | } | ||
420 | |||
421 | if (attr.length() > nattr) { | ||
422 | setError("Unsupported attributes"); | ||
423 | return false; | ||
424 | } | ||
425 | |||
426 | return startEventElement(keycode, unicode, modifiers, pressed, | ||
427 | autorepeat); | ||
428 | } | ||
429 | |||
430 | bool ZkbXmlHandler::start_next_state(const QXmlAttributes& attr) { | ||
431 | int nattr = 0; | ||
432 | int nidx = attr.index("name"); | ||
433 | QString name; | ||
434 | |||
435 | if (elements.first() != Map_Tag) { | ||
436 | setError("next-state element should be used only " | ||
437 | "within map element"); | ||
438 | return false; | ||
439 | } | ||
440 | |||
441 | if (nidx >= 0) { | ||
442 | name = attr.value(nidx); | ||
443 | nattr++; | ||
444 | } else { | ||
445 | setError("Missing name attribute"); | ||
446 | return false; | ||
447 | } | ||
448 | |||
449 | if (attr.length() > nattr) { | ||
450 | setError("Unsupported attributes"); | ||
451 | return false; | ||
452 | } | ||
453 | |||
454 | return startNextStateElement(name); | ||
455 | } | ||
456 | |||
457 | bool ZkbXmlHandler::end_keymap() { | ||
458 | return endKeymapElement(); | ||
459 | } | ||
460 | |||
461 | bool ZkbXmlHandler::end_include() { | ||
462 | return endIncludeElement(); | ||
463 | } | ||
464 | |||
465 | bool ZkbXmlHandler::end_label() { | ||
466 | return endLabelElement(); | ||
467 | } | ||
468 | |||
469 | bool ZkbXmlHandler::end_state() { | ||
470 | return endStateElement(); | ||
471 | } | ||
472 | |||
473 | bool ZkbXmlHandler::end_map() { | ||
474 | return endMapElement(); | ||
475 | } | ||
476 | |||
477 | bool ZkbXmlHandler::end_event() { | ||
478 | return endEventElement(); | ||
479 | } | ||
480 | |||
481 | bool ZkbXmlHandler::end_next_state() { | ||
482 | return endNextStateElement(); | ||
483 | } | ||
484 | |||
485 | void ZkbXmlHandler::setError(const QString& e) { | ||
486 | err = e; | ||
487 | } | ||
488 | |||
489 | int ZkbXmlHandler::str2key(const QString& s) { | ||
490 | int ret; | ||
491 | |||
492 | ret = KeyNames::find(s); | ||
493 | if (ret == -1) { | ||
494 | setError("Invalid value: " + s); | ||
495 | } | ||
496 | |||
497 | return ret; | ||
498 | } | ||
499 | |||
500 | int ZkbXmlHandler::str2modifier(const QString& val) { | ||
501 | int ret; | ||
502 | |||
503 | int n, i; | ||
504 | ret = 0; | ||
505 | n = 0; | ||
506 | do { | ||
507 | i = val.find('|', n); | ||
508 | if (i < 0) { | ||
509 | i = val.length(); | ||
510 | } | ||
511 | |||
512 | QString s = val.mid(n, i - n); | ||
513 | int v = ModifierNames::find(s.stripWhiteSpace()); | ||
514 | |||
515 | if (v == -1) { | ||
516 | setError("Invalid value: " + val); | ||
517 | return -1; | ||
518 | } | ||
519 | |||
520 | ret |= v; | ||
521 | n = i + 1; | ||
522 | } while (n < val.length()); | ||
523 | |||
524 | return ret; | ||
525 | } | ||
526 | |||
527 | bool ZkbXmlHandler::str2bool(const QString& s) { | ||
528 | if (s == "true") { | ||
529 | return true; | ||
530 | } else { | ||
531 | return false; | ||
532 | } | ||
533 | } | ||
534 | |||
535 | int ZkbXmlHandler::str2unicode(const QString& s) { | ||
536 | return str2uint(s); | ||
537 | } | ||
538 | |||
539 | int ZkbXmlHandler::str2keycode(const QString& s) { | ||
540 | int ret; | ||
541 | |||
542 | ret = KeycodeNames::find(s); | ||
543 | if (ret == -1) { | ||
544 | setError("Invalid value: " + s); | ||
545 | } | ||
546 | |||
547 | return ret; | ||
548 | } | ||
549 | |||
550 | int ZkbXmlHandler::str2uint(const QString& s) { | ||
551 | int ret; | ||
552 | bool ok; | ||
553 | QString val = s; | ||
554 | int r; | ||
555 | |||
556 | if (val.left(2) == "0x") { | ||
557 | val = s.mid(2); | ||
558 | r = 16; | ||
559 | } else if (val.left(1) == "0") { | ||
560 | val = s.mid(1); | ||
561 | r = 8; | ||
562 | } else { | ||
563 | r = 10; | ||
564 | } | ||
565 | |||
566 | ret = val.toInt(&ok, r); | ||
567 | if (!ok) { | ||
568 | setError("Invalid value: " + s); | ||
569 | ret = -1; | ||
570 | } | ||
571 | |||
572 | return ret; | ||
573 | } | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbxml.h b/noncore/applets/zkbapplet/keyzcfg/zkbxml.h new file mode 100644 index 0000000..2b15cbb --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkbxml.h | |||
@@ -0,0 +1,68 @@ | |||
1 | #ifndef ZKBXML_H | ||
2 | #define ZKBXML_H | ||
3 | |||
4 | #include <qxml.h> | ||
5 | |||
6 | class ZkbXmlHandler : public QXmlDefaultHandler { | ||
7 | public: | ||
8 | ZkbXmlHandler(); | ||
9 | virtual ~ZkbXmlHandler(); | ||
10 | |||
11 | virtual bool startElement(const QString&, const QString&, | ||
12 | const QString& name, const QXmlAttributes& attr); | ||
13 | |||
14 | virtual bool endElement(const QString&, const QString&, | ||
15 | const QString& name); | ||
16 | |||
17 | virtual QString errorString(); | ||
18 | |||
19 | protected: | ||
20 | QString err; | ||
21 | QStringList elements; | ||
22 | |||
23 | virtual bool startKeymapElement(int ardelay, int arperiod, | ||
24 | const QString& author); | ||
25 | virtual bool startIncludeElement(const QString& file, | ||
26 | const QString& prfix); | ||
27 | virtual bool startLabelElement(const QString& label, | ||
28 | const QString& state); | ||
29 | virtual bool startStateElement(const QString& name, | ||
30 | const QString& parent, bool dflt); | ||
31 | virtual bool startMapElement(int key, bool pressed); | ||
32 | virtual bool startEventElement(int keycode, int unicode, int modifiers, | ||
33 | bool pressed, bool autorepeat); | ||
34 | virtual bool startNextStateElement(const QString& state); | ||
35 | |||
36 | virtual bool endKeymapElement(); | ||
37 | virtual bool endIncludeElement(); | ||
38 | virtual bool endLabelElement(); | ||
39 | virtual bool endStateElement(); | ||
40 | virtual bool endMapElement(); | ||
41 | virtual bool endEventElement(); | ||
42 | virtual bool endNextStateElement(); | ||
43 | |||
44 | bool start_keymap(const QXmlAttributes&); | ||
45 | bool start_include(const QXmlAttributes&); | ||
46 | bool start_label(const QXmlAttributes&); | ||
47 | bool start_state(const QXmlAttributes&); | ||
48 | bool start_map(const QXmlAttributes&); | ||
49 | bool start_event(const QXmlAttributes&); | ||
50 | bool start_next_state(const QXmlAttributes&); | ||
51 | bool end_keymap(); | ||
52 | bool end_include(); | ||
53 | bool end_label(); | ||
54 | bool end_state(); | ||
55 | bool end_map(); | ||
56 | bool end_event(); | ||
57 | bool end_next_state(); | ||
58 | |||
59 | void setError(const QString&); | ||
60 | int str2key(const QString&); | ||
61 | int str2modifier(const QString&); | ||
62 | bool str2bool(const QString&); | ||
63 | int str2unicode(const QString&); | ||
64 | int str2keycode(const QString&); | ||
65 | int str2uint(const QString&); | ||
66 | }; | ||
67 | |||
68 | #endif | ||
diff --git a/noncore/applets/zkbapplet/zkbapplet.pro b/noncore/applets/zkbapplet/zkbapplet.pro index d270c28..cf60af2 100644 --- a/noncore/applets/zkbapplet/zkbapplet.pro +++ b/noncore/applets/zkbapplet/zkbapplet.pro | |||
@@ -1,20 +1,2 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = subdirs |
2 | CONFIG += qt plugin warn_on | 2 | SUBDIRS = keyz-cfg zkbapplet |
3 | HEADERS = zkbwidget.h \ | ||
4 | ../../apps/keyz-cfg/zkbcfg.h \ | ||
5 | ../../apps/keyz-cfg/zkbnames.h \ | ||
6 | ../../apps/keyz-cfg/zkbxml.h \ | ||
7 | ../../apps/keyz-cfg/zkb.h | ||
8 | SOURCES = zkbwidget.cpp \ | ||
9 | ../../apps/keyz-cfg/zkbcfg.cpp \ | ||
10 | ../../apps/keyz-cfg/zkbnames.cpp \ | ||
11 | ../../apps/keyz-cfg/zkbxml.cpp \ | ||
12 | ../../apps/keyz-cfg/zkb.cpp | ||
13 | TARGET = zkbapplet | ||
14 | DESTDIR = $(OPIEDIR)/plugins/applets | ||
15 | INCLUDEPATH += $(OPIEDIR)/include ../../apps/keyz-cfg | ||
16 | DEPENDPATH += | ||
17 | VERSION = 0.6.0 | ||
18 | LIBS += -lqpe | ||
19 | |||
20 | include ( $(OPIEDIR)/include.pro ) | ||