-rw-r--r-- | noncore/applets/zkbapplet/zkbwidget.cpp | 21 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/zkbwidget.h | 0 | ||||
-rw-r--r-- | noncore/apps/keyz-cfg/zkb.cpp | 3 |
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 @@ #include <opie2/otaskbarapplet.h> +#include <opie2/okeyfilter.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/applnk.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <stdio.h> #include <unistd.h> #include "zkbwidget.h" #include "zkbcfg.h" using namespace Opie::Ui; -ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), - disabled(Resource::loadPixmap("zkb-disabled")) { + +ZkbWidget::ZkbWidget(QWidget* parent) + :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) { labels = new QPopupMenu(); connect(labels, SIGNAL(activated(int)), this, SLOT(labelChanged(int))); loadKeymap(); channel = new QCopChannel("QPE/zkb", this); connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(signalReceived(const QCString&,const QByteArray&))); setFixedWidth ( AppLnk::smallIconSize() ); setFixedHeight ( AppLnk::smallIconSize() ); } -ZkbWidget::~ZkbWidget() { +ZkbWidget::~ZkbWidget() +{ + if (keymap != 0) { + delete keymap; + keymap = 0; + } } int ZkbWidget::position() { return 8; } bool ZkbWidget::loadKeymap() { ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); QFontMetrics fm(font()); if (keymap != 0) { delete keymap; keymap = 0; } Keymap* km = new Keymap(); if (!c.load("zkb.xml", *km, "")) { delete km; setPixmap(disabled); return false; } connect(km, SIGNAL(stateChanged(const QString&)), this, SLOT(stateChanged(const QString&))); - qwsServer->setKeyboardFilter(km); + Opie::Core::OKeyFilter::inst()->addHandler(km); Keymap* oldkm = keymap; keymap = km; if (oldkm != 0) { delete oldkm; } - setText(keymap->getCurrentLabel()); + QString ltext = keymap->getCurrentLabel(); + if (ltext.length()==0) ltext = "??"; + setText(ltext); labels->clear(); QStringList l = keymap->listLabels(); labels->insertItem(disabled, 0, 0); int n = 1; w = 0; for(QStringList::Iterator it = l.begin(); it != l.end(); ++it, n++) { // printf("label: %s\n", (const char*) (*it).utf8()); labels->insertItem(*it, n, n); int lw = fm.width(*it); if (lw > w) { w = lw; } } if (w == 0) { hide(); } else { show(); } return true; @@ -136,26 +145,24 @@ void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { QTimer::singleShot(0, this, SLOT(reload())); } else if (msg == "switch(QString)") { QString lbl; stream >> lbl; if (keymap != 0) { State* state = keymap->getStateByLabel(lbl); if (state != 0) { keymap->setCurrentState(state); setText(lbl); } } } else if (msg == "debug(QString)") { QString flag; stream >> flag; } } void ZkbWidget::reload() { loadKeymap(); QCopEnvelope("QPE/System", "notBusy()"); } EXPORT_OPIE_APPLET_v1( ZkbWidget ) - - 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 @@ #include "zkb.h" /* OPIE */ #include <opie2/odebug.h> +#include <opie2/okeyfilter.h> #include <stdio.h> // Implementation of Action class Action::Action():state(0), keycode(0), unicode(0), flags(0) { } Action::Action(State* s, ushort kc, ushort uni, int f): state(s), keycode(kc), unicode(uni), flags(f) { } Action::~Action() { } State* Action::getState() const { return state; } void Action::setState(State* s) { state = s; setDefined(true); } bool Action::hasEvent() const { @@ -225,48 +226,50 @@ int State::translateKeycode(int keycode) const { if (keycode < 0x80) { return x1[keycode - 0x20]; } if (keycode < 0x1000) { return -1; } if (keycode < 0x1057) { return x2[keycode - 0x1000]; } return -1; } // Implementation of Keymap class Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { repeatDelay=400; repeatPeriod=80; connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); } Keymap::~Keymap() { + odebug << "removing keyboard filter for zkb"<<oendl; + Opie::Core::OKeyFilter::inst()->remHandler(this); QMap<QString, State*>::Iterator it; for(it = states.begin(); it != states.end(); ++it) { delete it.data(); } states.clear(); } bool Keymap::filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat) { odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl; if (!enabled) { return false; } // the second check is workaround to make suspend work if // the user pressed it right after he did resume. for some // reason the event sent by qt has autoRepeat true in this // case if (autoRepeat && keycode != 4177) { return true; } |