summaryrefslogtreecommitdiff
path: root/noncore/applets/zkbapplet
authoralwin <alwin>2004-02-26 15:33:31 (UTC)
committer alwin <alwin>2004-02-26 15:33:31 (UTC)
commit42eb413737eb6e911867e1b9c0f5b6cf81c677fd (patch) (side-by-side diff)
treeb32284f8cec0f584151f0826fd121c153fc07601 /noncore/applets/zkbapplet
parentd26a7814b7b454583a136a78aeb7016467ec9ff8 (diff)
downloadopie-42eb413737eb6e911867e1b9c0f5b6cf81c677fd.zip
opie-42eb413737eb6e911867e1b9c0f5b6cf81c677fd.tar.gz
opie-42eb413737eb6e911867e1b9c0f5b6cf81c677fd.tar.bz2
Yeah - zkb fixed and working within OPIE.
Diffstat (limited to 'noncore/applets/zkbapplet') (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
7 files changed, 295 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 @@
+ config ZKBAPPLET
+ boolean "zkbapplet (switch keyboard layout on the fly)"
+ default "n"
+ 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 @@
+Package: zkbapplet
+Files: plugins/applets/libzkbapplet.so* pics/zkb-disabled.png share/zkb/*.xml
+Priority: optional
+Section: opie/applets
+Maintainer: Rajko Albrecht <alwin@handhelds.org>
+Architecture: arm
+Depends: task-opie-minimal, key-cfg
+Description: ZKB Applet
+Version: 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 @@
+#include <stdio.h>
+#include <qlabel.h>
+#include <qbutton.h>
+#include <qwindowsystem_qws.h>
+#include "zkbapplet.h"
+#include "zkbwidget.h"
+
+
+ZkbApplet::ZkbApplet() : app(0){
+}
+
+ZkbApplet::~ZkbApplet()
+{
+ if (app) delete app;
+}
+
+QWidget* ZkbApplet::applet(QWidget* parent) {
+ if (app == 0) {
+ app = new ZkbWidget(parent);
+ }
+
+ return app;
+}
+
+int ZkbApplet::position() const {
+ return 8;
+}
+
+QRESULT ZkbApplet::queryInterface(const QUuid& uuid, QUnknownInterface** iface) {
+
+ *iface = 0;
+ if (uuid == IID_QUnknown) {
+ *iface = this;
+ } else if (uuid == IID_TaskbarApplet) {
+ *iface = this;
+ } else {
+ return QS_FALSE;
+ }
+
+ if (*iface) {
+ (*iface)->addRef();
+ }
+
+ return QS_OK;
+}
+
+Q_EXPORT_INTERFACE() {
+ Q_CREATE_INSTANCE(ZkbApplet)
+}
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 @@
+#include "qpe/taskbarappletinterface.h"
+
+#ifndef ZKBAPPLET_H
+#define ZKBAPPLET_H
+
+class ZkbWidget;
+
+class ZkbApplet : public TaskbarAppletInterface {
+public:
+ ZkbApplet();
+ virtual ~ZkbApplet();
+
+ QRESULT queryInterface(const QUuid&, QUnknownInterface**);
+ Q_REFCOUNT
+
+ virtual QWidget* applet(QWidget*);
+ virtual int position() const;
+
+protected:
+ ZkbWidget* app;
+};
+
+#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 @@
+TEMPLATE = lib
+CONFIG += qt plugin warn_on release
+HEADERS = zkbapplet.h\
+ zkbwidget.h \
+ ../../apps/keyz-cfg/zkbcfg.h \
+ ../../apps/keyz-cfg/zkbnames.h \
+ ../../apps/keyz-cfg/zkbxml.h \
+ ../../apps/keyz-cfg/zkb.h
+SOURCES = zkbapplet.cpp \
+ zkbwidget.cpp \
+ ../../apps/keyz-cfg/zkbcfg.cpp \
+ ../../apps/keyz-cfg/zkbnames.cpp \
+ ../../apps/keyz-cfg/zkbxml.cpp \
+ ../../apps/keyz-cfg/zkb.cpp
+TARGET = zkbapplet
+DESTDIR = $(OPIEDIR)/plugins/applets
+INCLUDEPATH += $(OPIEDIR)/include ../../apps/keyz-cfg
+DEPENDPATH += ../$(OPIEDIR)/include
+VERSION = 0.6.0
+LIBS += -lqpe
+
+include ( $(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 @@
+#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"
+
+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() {
+}
+
+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);
+
+ Keymap* oldkm = keymap;
+ keymap = km;
+
+ if (oldkm != 0) {
+ delete oldkm;
+ }
+
+ setText(keymap->getCurrentLabel());
+
+ 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;
+}
+
+QSize ZkbWidget::sizeHint() const {
+ return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize());
+}
+
+void ZkbWidget::stateChanged(const QString& s) {
+// qDebug("stateChanged: %s\n", (const char*) s.utf8());
+ setText(s);
+}
+
+void ZkbWidget::labelChanged(int id) {
+ if (id == 0) {
+ keymap->disable();
+ setPixmap(disabled);
+ return;
+ }
+
+ keymap->enable();
+
+ QStringList l = keymap->listLabels();
+ QString lbl = l[id-1];
+
+// printf("labelChanged: %s\n", (const char*) lbl.utf8());
+ State* state = keymap->getStateByLabel(lbl);
+ if (state != 0) {
+ keymap->setCurrentState(state);
+ setText(lbl);
+ }
+}
+
+void ZkbWidget::mouseReleaseEvent(QMouseEvent*) {
+ QSize sh = labels->sizeHint();
+ QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height()));
+ labels->exec(p);
+}
+
+void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) {
+ QDataStream stream(data, IO_ReadOnly);
+
+ if (msg == "enable()") {
+ keymap->enable();
+ } else if (msg == "disable()") {
+ keymap->disable();
+ } else if (msg == "reload()") {
+ QCopEnvelope("QPE/System", "busy()");
+ 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()");
+}
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 @@
+#ifndef ZKBWIDGET_H
+#define ZKBWIDGET_H
+
+#include <qwidget.h>
+#include <qlabel.h>
+#include <qpopupmenu.h>
+#include <qpixmap.h>
+#include <qcopchannel_qws.h>
+
+#include "zkb.h"
+
+class ZkbWidget : public QLabel {
+Q_OBJECT
+
+public:
+ ZkbWidget(QWidget* parent);
+ ~ZkbWidget();
+
+ QSize sizeHint() const;
+
+protected:
+ QLabel* label;
+ Keymap* keymap;
+ QPopupMenu* labels;
+ QCopChannel* channel;
+ int w, h;
+ QPixmap disabled;
+
+ bool loadKeymap();
+ void mouseReleaseEvent(QMouseEvent*);
+
+protected slots:
+ void stateChanged(const QString&);
+ void labelChanged(int id);
+ void signalReceived(const QCString& msg, const QByteArray& data);
+ void reload();
+};
+#endif