Diffstat (limited to 'core/applets/multikeyapplet/multikey.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/multikeyapplet/multikey.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/core/applets/multikeyapplet/multikey.cpp b/core/applets/multikeyapplet/multikey.cpp index b17498d..fc5f093 100644 --- a/core/applets/multikeyapplet/multikey.cpp +++ b/core/applets/multikeyapplet/multikey.cpp | |||
@@ -1,143 +1,143 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru | 2 | ** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru |
3 | ** All rights reserved. | 3 | ** All rights reserved. |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | **********************************************************************/ | 13 | **********************************************************************/ |
14 | 14 | ||
15 | #include "multikey.h" | 15 | #include "multikey.h" |
16 | 16 | ||
17 | /* OPIE */ | 17 | /* OPIE */ |
18 | #include <opie2/otaskbarapplet.h> | 18 | #include <opie2/otaskbarapplet.h> |
19 | #include <qpe/qcopenvelope_qws.h> | 19 | #include <qpe/qcopenvelope_qws.h> |
20 | 20 | ||
21 | /* QT */ | 21 | /* QT */ |
22 | #include <qdir.h> | 22 | #include <qdir.h> |
23 | 23 | ||
24 | Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN") | 24 | Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN") |
25 | { | 25 | { |
26 | QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); | 26 | QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); |
27 | connect( swChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 27 | connect( swChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
28 | this, SLOT(message(const QCString &, const QByteArray &))); | 28 | this, SLOT(message(const QCString&,const QByteArray&))); |
29 | 29 | ||
30 | setFont( QFont( "Helvetica", 10, QFont::Normal ) ); | 30 | setFont( QFont( "Helvetica", 10, QFont::Normal ) ); |
31 | QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold); | 31 | QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold); |
32 | lang = 0; | 32 | lang = 0; |
33 | QCopEnvelope e("MultiKey/Keyboard", "getmultikey()"); | 33 | QCopEnvelope e("MultiKey/Keyboard", "getmultikey()"); |
34 | setText("EN"); | 34 | setText("EN"); |
35 | popupMenu.insertItem("EN", 0); | 35 | popupMenu.insertItem("EN", 0); |
36 | show(); | 36 | show(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void Multikey::mousePressEvent(QMouseEvent *ev) | 39 | void Multikey::mousePressEvent(QMouseEvent *ev) |
40 | { | 40 | { |
41 | if (!sw_maps.count()) | 41 | if (!sw_maps.count()) |
42 | return; | 42 | return; |
43 | 43 | ||
44 | if (ev->button() == RightButton) { | 44 | if (ev->button() == RightButton) { |
45 | 45 | ||
46 | QPoint p = mapToGlobal(QPoint(0, 0)); | 46 | QPoint p = mapToGlobal(QPoint(0, 0)); |
47 | QSize s = popupMenu.sizeHint(); | 47 | QSize s = popupMenu.sizeHint(); |
48 | int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), | 48 | int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), |
49 | p.y() - s.height()), 0); | 49 | p.y() - s.height()), 0); |
50 | 50 | ||
51 | if (opt == -1) | 51 | if (opt == -1) |
52 | return; | 52 | return; |
53 | lang = opt; | 53 | lang = opt; |
54 | 54 | ||
55 | QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); | 55 | QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); |
56 | e << sw_maps[lang]; | 56 | e << sw_maps[lang]; |
57 | setText(labels[lang]); | 57 | setText(labels[lang]); |
58 | } | 58 | } |
59 | QWidget::mousePressEvent(ev); | 59 | QWidget::mousePressEvent(ev); |
60 | } | 60 | } |
61 | 61 | ||
62 | void Multikey::mouseReleaseEvent(QMouseEvent *ev) | 62 | void Multikey::mouseReleaseEvent(QMouseEvent *ev) |
63 | { | 63 | { |
64 | if (!sw_maps.count()) | 64 | if (!sw_maps.count()) |
65 | return; | 65 | return; |
66 | 66 | ||
67 | lang = lang < sw_maps.count()-1 ? lang+1 : 0; | 67 | lang = lang < sw_maps.count()-1 ? lang+1 : 0; |
68 | QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); | 68 | QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); |
69 | //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii()); | 69 | //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii()); |
70 | e << sw_maps[lang]; | 70 | e << sw_maps[lang]; |
71 | setText(labels[lang]); | 71 | setText(labels[lang]); |
72 | } | 72 | } |
73 | 73 | ||
74 | void Multikey::message(const QCString &message, const QByteArray &data) | 74 | void Multikey::message(const QCString &message, const QByteArray &data) |
75 | { | 75 | { |
76 | if ( message == "setsw(QString,QString)" ) { | 76 | if ( message == "setsw(QString,QString)" ) { |
77 | 77 | ||
78 | QDataStream stream(data, IO_ReadOnly); | 78 | QDataStream stream(data, IO_ReadOnly); |
79 | QString maps, current_map; | 79 | QString maps, current_map; |
80 | stream >> maps >> current_map; | 80 | stream >> maps >> current_map; |
81 | QStringList sw = QStringList::split(QChar('|'), maps); | 81 | QStringList sw = QStringList::split(QChar('|'), maps); |
82 | sw.append(current_map); | 82 | sw.append(current_map); |
83 | 83 | ||
84 | QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap"); | 84 | QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap"); |
85 | lang = 0; | 85 | lang = 0; |
86 | labels.clear(); | 86 | labels.clear(); |
87 | sw_maps.clear(); | 87 | sw_maps.clear(); |
88 | popupMenu.clear(); | 88 | popupMenu.clear(); |
89 | 89 | ||
90 | for (uint i = 0; i < sw.count(); ++i) { | 90 | for (uint i = 0; i < sw.count(); ++i) { |
91 | QString keymap_map; | 91 | QString keymap_map; |
92 | if (sw[i][0] != '/') { | 92 | if (sw[i][0] != '/') { |
93 | 93 | ||
94 | keymap_map = map_dir.absPath() + "/" + sw[i]; | 94 | keymap_map = map_dir.absPath() + "/" + sw[i]; |
95 | } else { | 95 | } else { |
96 | 96 | ||
97 | if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) | 97 | if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) |
98 | && i != sw.count()-1) || !QFile::exists(sw[i])) { | 98 | && i != sw.count()-1) || !QFile::exists(sw[i])) { |
99 | continue; | 99 | continue; |
100 | } | 100 | } |
101 | keymap_map = sw[i]; | 101 | keymap_map = sw[i]; |
102 | } | 102 | } |
103 | 103 | ||
104 | QFile map(keymap_map); | 104 | QFile map(keymap_map); |
105 | if (map.open(IO_ReadOnly)) { | 105 | if (map.open(IO_ReadOnly)) { |
106 | QString line; | 106 | QString line; |
107 | 107 | ||
108 | map.readLine(line, 1024); | 108 | map.readLine(line, 1024); |
109 | while (!map.atEnd()) { | 109 | while (!map.atEnd()) { |
110 | 110 | ||
111 | if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { | 111 | if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { |
112 | 112 | ||
113 | if (i != sw.count()-1) { | 113 | if (i != sw.count()-1) { |
114 | if (keymap_map == current_map) { | 114 | if (keymap_map == current_map) { |
115 | lang = i; | 115 | lang = i; |
116 | } | 116 | } |
117 | sw_maps.append(keymap_map); | 117 | sw_maps.append(keymap_map); |
118 | labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); | 118 | labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); |
119 | popupMenu.insertItem(labels[labels.count()-1], labels.count()-1); | 119 | popupMenu.insertItem(labels[labels.count()-1], labels.count()-1); |
120 | } else { | 120 | } else { |
121 | current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); | 121 | current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); |
122 | } | 122 | } |
123 | break; | 123 | break; |
124 | } | 124 | } |
125 | map.readLine(line, 1024); | 125 | map.readLine(line, 1024); |
126 | } | 126 | } |
127 | map.close(); | 127 | map.close(); |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | setText(current); | 131 | setText(current); |
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | int Multikey::position() | 135 | int Multikey::position() |
136 | { | 136 | { |
137 | return 10; | 137 | return 10; |
138 | } | 138 | } |
139 | 139 | ||
140 | Q_EXPORT_INTERFACE() | 140 | Q_EXPORT_INTERFACE() |
141 | { | 141 | { |
142 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<Multikey> ); | 142 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<Multikey> ); |
143 | } | 143 | } |