summaryrefslogtreecommitdiff
path: root/noncore/applets
Unidiff
Diffstat (limited to 'noncore/applets') (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 @@
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