author | alwin <alwin> | 2004-02-26 15:33:31 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-02-26 15:33:31 (UTC) |
commit | 42eb413737eb6e911867e1b9c0f5b6cf81c677fd (patch) (unidiff) | |
tree | b32284f8cec0f584151f0826fd121c153fc07601 /noncore/applets/zkbapplet | |
parent | d26a7814b7b454583a136a78aeb7016467ec9ff8 (diff) | |
download | opie-42eb413737eb6e911867e1b9c0f5b6cf81c677fd.zip opie-42eb413737eb6e911867e1b9c0f5b6cf81c677fd.tar.gz opie-42eb413737eb6e911867e1b9c0f5b6cf81c677fd.tar.bz2 |
Yeah - zkb fixed and working within OPIE.
-rw-r--r-- | noncore/applets/zkbapplet/config.in | 4 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/zkbapplet.control | 9 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/zkbapplet.cpp | 49 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/zkbapplet.h | 23 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/zkbapplet.pro | 22 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/zkbwidget.cpp | 150 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/zkbwidget.h | 38 |
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 @@ | |||
1 | Package: zkbapplet | ||
2 | Files: plugins/applets/libzkbapplet.so* pics/zkb-disabled.png share/zkb/*.xml | ||
3 | Priority: optional | ||
4 | Section: opie/applets | ||
5 | Maintainer: Rajko Albrecht <alwin@handhelds.org> | ||
6 | Architecture: arm | ||
7 | Depends: task-opie-minimal, key-cfg | ||
8 | Description: ZKB Applet | ||
9 | 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 @@ | |||
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 | |||
9 | ZkbApplet::ZkbApplet() : app(0){ | ||
10 | } | ||
11 | |||
12 | ZkbApplet::~ZkbApplet() | ||
13 | { | ||
14 | if (app) delete app; | ||
15 | } | ||
16 | |||
17 | QWidget* ZkbApplet::applet(QWidget* parent) { | ||
18 | if (app == 0) { | ||
19 | app = new ZkbWidget(parent); | ||
20 | } | ||
21 | |||
22 | return app; | ||
23 | } | ||
24 | |||
25 | int ZkbApplet::position() const { | ||
26 | return 8; | ||
27 | } | ||
28 | |||
29 | QRESULT 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 | |||
47 | Q_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 | |||
6 | class ZkbWidget; | ||
7 | |||
8 | class ZkbApplet : public TaskbarAppletInterface { | ||
9 | public: | ||
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 | |||
19 | protected: | ||
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 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += qt plugin warn_on release | ||
3 | HEADERS = 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 | ||
9 | SOURCES = 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 | ||
15 | TARGET = zkbapplet | ||
16 | DESTDIR = $(OPIEDIR)/plugins/applets | ||
17 | INCLUDEPATH += $(OPIEDIR)/include ../../apps/keyz-cfg | ||
18 | DEPENDPATH += ../$(OPIEDIR)/include | ||
19 | VERSION = 0.6.0 | ||
20 | LIBS += -lqpe | ||
21 | |||
22 | 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 @@ | |||
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 | |||
10 | ZkbWidget::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 | |||
26 | ZkbWidget::~ZkbWidget() { | ||
27 | } | ||
28 | |||
29 | bool 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 | |||
85 | QSize ZkbWidget::sizeHint() const { | ||
86 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); | ||
87 | } | ||
88 | |||
89 | void ZkbWidget::stateChanged(const QString& s) { | ||
90 | //qDebug("stateChanged: %s\n", (const char*) s.utf8()); | ||
91 | setText(s); | ||
92 | } | ||
93 | |||
94 | void 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 | |||
114 | void 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 | |||
120 | void 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 | |||
147 | void 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 | |||
12 | class ZkbWidget : public QLabel { | ||
13 | Q_OBJECT | ||
14 | |||
15 | public: | ||
16 | ZkbWidget(QWidget* parent); | ||
17 | ~ZkbWidget(); | ||
18 | |||
19 | QSize sizeHint() const; | ||
20 | |||
21 | protected: | ||
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 | |||
32 | protected 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 | ||