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