summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/applets/zkbapplet/zkbwidget.cpp21
-rw-r--r--noncore/applets/zkbapplet/zkbwidget.h0
-rw-r--r--noncore/apps/keyz-cfg/zkb.cpp3
3 files changed, 17 insertions, 7 deletions
diff --git a/noncore/applets/zkbapplet/zkbwidget.cpp b/noncore/applets/zkbapplet/zkbwidget.cpp
index 38bfba9..8499500 100644
--- a/noncore/applets/zkbapplet/zkbwidget.cpp
+++ b/noncore/applets/zkbapplet/zkbwidget.cpp
@@ -1,89 +1,98 @@
1#include <opie2/otaskbarapplet.h> 1#include <opie2/otaskbarapplet.h>
2#include <opie2/okeyfilter.h>
2#include <qpe/qcopenvelope_qws.h> 3#include <qpe/qcopenvelope_qws.h>
3#include <qpe/applnk.h> 4#include <qpe/applnk.h>
4#include <qpe/qpeapplication.h> 5#include <qpe/qpeapplication.h>
5#include <qpe/resource.h> 6#include <qpe/resource.h>
6#include <stdio.h> 7#include <stdio.h>
7#include <unistd.h> 8#include <unistd.h>
8#include "zkbwidget.h" 9#include "zkbwidget.h"
9#include "zkbcfg.h" 10#include "zkbcfg.h"
10 11
11using namespace Opie::Ui; 12using namespace Opie::Ui;
12ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), 13
13 disabled(Resource::loadPixmap("zkb-disabled")) { 14ZkbWidget::ZkbWidget(QWidget* parent)
15 :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) {
14 16
15 labels = new QPopupMenu(); 17 labels = new QPopupMenu();
16 connect(labels, SIGNAL(activated(int)), this, 18 connect(labels, SIGNAL(activated(int)), this,
17 SLOT(labelChanged(int))); 19 SLOT(labelChanged(int)));
18 20
19 loadKeymap(); 21 loadKeymap();
20 22
21 channel = new QCopChannel("QPE/zkb", this); 23 channel = new QCopChannel("QPE/zkb", this);
22 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), 24 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)),
23 this, SLOT(signalReceived(const QCString&,const QByteArray&))); 25 this, SLOT(signalReceived(const QCString&,const QByteArray&)));
24 setFixedWidth ( AppLnk::smallIconSize() ); 26 setFixedWidth ( AppLnk::smallIconSize() );
25 setFixedHeight ( AppLnk::smallIconSize() ); 27 setFixedHeight ( AppLnk::smallIconSize() );
26} 28}
27 29
28ZkbWidget::~ZkbWidget() { 30ZkbWidget::~ZkbWidget()
31{
32 if (keymap != 0) {
33 delete keymap;
34 keymap = 0;
35 }
29} 36}
30 37
31int ZkbWidget::position() 38int ZkbWidget::position()
32{ 39{
33 return 8; 40 return 8;
34} 41}
35 42
36bool ZkbWidget::loadKeymap() { 43bool ZkbWidget::loadKeymap() {
37 ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); 44 ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb");
38 QFontMetrics fm(font()); 45 QFontMetrics fm(font());
39 46
40 if (keymap != 0) { 47 if (keymap != 0) {
41 delete keymap; 48 delete keymap;
42 keymap = 0; 49 keymap = 0;
43 } 50 }
44 51
45 Keymap* km = new Keymap(); 52 Keymap* km = new Keymap();
46 53
47 if (!c.load("zkb.xml", *km, "")) { 54 if (!c.load("zkb.xml", *km, "")) {
48 delete km; 55 delete km;
49 setPixmap(disabled); 56 setPixmap(disabled);
50 return false; 57 return false;
51 } 58 }
52 59
53 connect(km, SIGNAL(stateChanged(const QString&)), 60 connect(km, SIGNAL(stateChanged(const QString&)),
54 this, SLOT(stateChanged(const QString&))); 61 this, SLOT(stateChanged(const QString&)));
55 62
56 qwsServer->setKeyboardFilter(km); 63 Opie::Core::OKeyFilter::inst()->addHandler(km);
57 64
58 Keymap* oldkm = keymap; 65 Keymap* oldkm = keymap;
59 keymap = km; 66 keymap = km;
60 67
61 if (oldkm != 0) { 68 if (oldkm != 0) {
62 delete oldkm; 69 delete oldkm;
63 } 70 }
64 71
65 setText(keymap->getCurrentLabel()); 72 QString ltext = keymap->getCurrentLabel();
73 if (ltext.length()==0) ltext = "??";
74 setText(ltext);
66 75
67 labels->clear(); 76 labels->clear();
68 QStringList l = keymap->listLabels(); 77 QStringList l = keymap->listLabels();
69 labels->insertItem(disabled, 0, 0); 78 labels->insertItem(disabled, 0, 0);
70 int n = 1; 79 int n = 1;
71 w = 0; 80 w = 0;
72 for(QStringList::Iterator it = l.begin(); it != l.end(); 81 for(QStringList::Iterator it = l.begin(); it != l.end();
73 ++it, n++) { 82 ++it, n++) {
74 83
75 // printf("label: %s\n", (const char*) (*it).utf8()); 84 // printf("label: %s\n", (const char*) (*it).utf8());
76 85
77 labels->insertItem(*it, n, n); 86 labels->insertItem(*it, n, n);
78 int lw = fm.width(*it); 87 int lw = fm.width(*it);
79 if (lw > w) { 88 if (lw > w) {
80 w = lw; 89 w = lw;
81 } 90 }
82 } 91 }
83 92
84 if (w == 0) { 93 if (w == 0) {
85 hide(); 94 hide();
86 } else { 95 } else {
87 show(); 96 show();
88 } 97 }
89 return true; 98 return true;
@@ -136,26 +145,24 @@ void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) {
136 QTimer::singleShot(0, this, SLOT(reload())); 145 QTimer::singleShot(0, this, SLOT(reload()));
137 } else if (msg == "switch(QString)") { 146 } else if (msg == "switch(QString)") {
138 QString lbl; 147 QString lbl;
139 stream >> lbl; 148 stream >> lbl;
140 149
141 if (keymap != 0) { 150 if (keymap != 0) {
142 State* state = keymap->getStateByLabel(lbl); 151 State* state = keymap->getStateByLabel(lbl);
143 if (state != 0) { 152 if (state != 0) {
144 keymap->setCurrentState(state); 153 keymap->setCurrentState(state);
145 setText(lbl); 154 setText(lbl);
146 } 155 }
147 } 156 }
148 } else if (msg == "debug(QString)") { 157 } else if (msg == "debug(QString)") {
149 QString flag; 158 QString flag;
150 stream >> flag; 159 stream >> flag;
151 } 160 }
152} 161}
153 162
154void ZkbWidget::reload() { 163void ZkbWidget::reload() {
155 loadKeymap(); 164 loadKeymap();
156 QCopEnvelope("QPE/System", "notBusy()"); 165 QCopEnvelope("QPE/System", "notBusy()");
157} 166}
158 167
159EXPORT_OPIE_APPLET_v1( ZkbWidget ) 168EXPORT_OPIE_APPLET_v1( ZkbWidget )
160
161
diff --git a/noncore/applets/zkbapplet/zkbwidget.h b/noncore/applets/zkbapplet/zkbwidget.h
index 7c67794..9bce85a 100644
--- a/noncore/applets/zkbapplet/zkbwidget.h
+++ b/noncore/applets/zkbapplet/zkbwidget.h
diff --git a/noncore/apps/keyz-cfg/zkb.cpp b/noncore/apps/keyz-cfg/zkb.cpp
index c9e1dc5..a357b88 100644
--- a/noncore/apps/keyz-cfg/zkb.cpp
+++ b/noncore/apps/keyz-cfg/zkb.cpp
@@ -1,28 +1,29 @@
1#include "zkb.h" 1#include "zkb.h"
2 2
3/* OPIE */ 3/* OPIE */
4#include <opie2/odebug.h> 4#include <opie2/odebug.h>
5#include <opie2/okeyfilter.h>
5 6
6#include <stdio.h> 7#include <stdio.h>
7 8
8// Implementation of Action class 9// Implementation of Action class
9Action::Action():state(0), keycode(0), unicode(0), flags(0) { 10Action::Action():state(0), keycode(0), unicode(0), flags(0) {
10} 11}
11 12
12Action::Action(State* s, ushort kc, ushort uni, int f): 13Action::Action(State* s, ushort kc, ushort uni, int f):
13 state(s), keycode(kc), unicode(uni), flags(f) { 14 state(s), keycode(kc), unicode(uni), flags(f) {
14} 15}
15 16
16Action::~Action() { 17Action::~Action() {
17} 18}
18 19
19State* Action::getState() const { 20State* Action::getState() const {
20 return state; 21 return state;
21} 22}
22 23
23void Action::setState(State* s) { 24void Action::setState(State* s) {
24 state = s; 25 state = s;
25 setDefined(true); 26 setDefined(true);
26} 27}
27 28
28bool Action::hasEvent() const { 29bool Action::hasEvent() const {
@@ -225,48 +226,50 @@ int State::translateKeycode(int keycode) const {
225 226
226 if (keycode < 0x80) { 227 if (keycode < 0x80) {
227 return x1[keycode - 0x20]; 228 return x1[keycode - 0x20];
228 } 229 }
229 230
230 if (keycode < 0x1000) { 231 if (keycode < 0x1000) {
231 return -1; 232 return -1;
232 } 233 }
233 234
234 if (keycode < 0x1057) { 235 if (keycode < 0x1057) {
235 return x2[keycode - 0x1000]; 236 return x2[keycode - 0x1000];
236 } 237 }
237 238
238 return -1; 239 return -1;
239} 240}
240 241
241// Implementation of Keymap class 242// Implementation of Keymap class
242Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { 243Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
243 repeatDelay=400; 244 repeatDelay=400;
244 repeatPeriod=80; 245 repeatPeriod=80;
245 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); 246 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
246} 247}
247 248
248Keymap::~Keymap() { 249Keymap::~Keymap() {
250 odebug << "removing keyboard filter for zkb"<<oendl;
251 Opie::Core::OKeyFilter::inst()->remHandler(this);
249 QMap<QString, State*>::Iterator it; 252 QMap<QString, State*>::Iterator it;
250 for(it = states.begin(); it != states.end(); ++it) { 253 for(it = states.begin(); it != states.end(); ++it) {
251 delete it.data(); 254 delete it.data();
252 } 255 }
253 states.clear(); 256 states.clear();
254} 257}
255 258
256bool Keymap::filter(int unicode, int keycode, int modifiers, 259bool Keymap::filter(int unicode, int keycode, int modifiers,
257 bool isPress, bool autoRepeat) { 260 bool isPress, bool autoRepeat) {
258 261
259 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode 262 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
260 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl; 263 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
261 264
262 if (!enabled) { 265 if (!enabled) {
263 return false; 266 return false;
264 } 267 }
265 268
266 // the second check is workaround to make suspend work if 269 // the second check is workaround to make suspend work if
267 // the user pressed it right after he did resume. for some 270 // the user pressed it right after he did resume. for some
268 // reason the event sent by qt has autoRepeat true in this 271 // reason the event sent by qt has autoRepeat true in this
269 // case 272 // case
270 if (autoRepeat && keycode != 4177) { 273 if (autoRepeat && keycode != 4177) {
271 return true; 274 return true;
272 } 275 }