summaryrefslogtreecommitdiff
authormouse <mouse>2004-01-09 14:18:03 (UTC)
committer mouse <mouse>2004-01-09 14:18:03 (UTC)
commit6875988077013544246ae0df7cc2e5d538a7f152 (patch) (unidiff)
treef24c11b218457095d303be1a366423648dc15331
parent8dd8648b0e82b16bcb0c976d330eaf670081a748 (diff)
downloadopie-6875988077013544246ae0df7cc2e5d538a7f152.zip
opie-6875988077013544246ae0df7cc2e5d538a7f152.tar.gz
opie-6875988077013544246ae0df7cc2e5d538a7f152.tar.bz2
bug fix: range checking in sw_maps
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/multikeyapplet/multikey.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/core/applets/multikeyapplet/multikey.cpp b/core/applets/multikeyapplet/multikey.cpp
index 9ef162f..d304f54 100644
--- a/core/applets/multikeyapplet/multikey.cpp
+++ b/core/applets/multikeyapplet/multikey.cpp
@@ -1,130 +1,136 @@
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#include <qpe/global.h> 17#include <qpe/global.h>
18#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21 21
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qdir.h> 23#include <qdir.h>
24#include <qfileinfo.h> 24#include <qfileinfo.h>
25#include <qcopchannel_qws.h> 25#include <qcopchannel_qws.h>
26 26
27Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN") 27Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN")
28{ 28{
29 QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); 29 QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this);
30 connect( swChannel, SIGNAL(received(const QCString &, const QByteArray &)), 30 connect( swChannel, SIGNAL(received(const QCString &, const QByteArray &)),
31 this, SLOT(message(const QCString &, const QByteArray &))); 31 this, SLOT(message(const QCString &, const QByteArray &)));
32 32
33 setFont( QFont( "Helvetica", 10, QFont::Normal ) ); 33 setFont( QFont( "Helvetica", 10, QFont::Normal ) );
34 QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold); 34 QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold);
35 lang = 0; 35 lang = 0;
36 QCopEnvelope e("MultiKey/Keyboard", "getmultikey()"); 36 QCopEnvelope e("MultiKey/Keyboard", "getmultikey()");
37 setText("EN"); 37 setText("EN");
38 popupMenu.insertItem("EN", -1); 38 popupMenu.insertItem("EN", 0);
39 show(); 39 show();
40} 40}
41 41
42void Multikey::mousePressEvent(QMouseEvent *ev) 42void Multikey::mousePressEvent(QMouseEvent *ev)
43{ 43{
44 if (!sw_maps.count())
45 return;
46
44 if (ev->button() == RightButton) { 47 if (ev->button() == RightButton) {
45 48
46 QPoint p = mapToGlobal(QPoint(0, 0)); 49 QPoint p = mapToGlobal(QPoint(0, 0));
47 QSize s = popupMenu.sizeHint(); 50 QSize s = popupMenu.sizeHint();
48 int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), 51 int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2),
49 p.y() - s.height()), 0); 52 p.y() - s.height()), 0);
50 53
51 if (opt == -1) 54 if (opt == -1)
52 return; 55 return;
53 lang = opt; 56 lang = opt;
54 57
55 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); 58 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)");
56 e << sw_maps[lang]; 59 e << sw_maps[lang];
57 setText(labels[lang]); 60 setText(labels[lang]);
58 } 61 }
59 QWidget::mousePressEvent(ev); 62 QWidget::mousePressEvent(ev);
60} 63}
61 64
62void Multikey::mouseReleaseEvent(QMouseEvent *ev) 65void Multikey::mouseReleaseEvent(QMouseEvent *ev)
63{ 66{
67 if (!sw_maps.count())
68 return;
69
64 lang = lang < sw_maps.count()-1 ? lang+1 : 0; 70 lang = lang < sw_maps.count()-1 ? lang+1 : 0;
65 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); 71 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)");
66 //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii()); 72 //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii());
67 e << sw_maps[lang]; 73 e << sw_maps[lang];
68 setText(labels[lang]); 74 setText(labels[lang]);
69} 75}
70 76
71void Multikey::message(const QCString &message, const QByteArray &data) 77void Multikey::message(const QCString &message, const QByteArray &data)
72{ 78{
73 if ( message == "setsw(QString,QString)" ) { 79 if ( message == "setsw(QString,QString)" ) {
74 80
75 QDataStream stream(data, IO_ReadOnly); 81 QDataStream stream(data, IO_ReadOnly);
76 QString maps, current_map; 82 QString maps, current_map;
77 stream >> maps >> current_map; 83 stream >> maps >> current_map;
78 QStringList sw = QStringList::split(QChar('|'), maps); 84 QStringList sw = QStringList::split(QChar('|'), maps);
79 sw.append(current_map); 85 sw.append(current_map);
80 86
81 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap"); 87 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap");
82 lang = 0; 88 lang = 0;
83 labels.clear(); 89 labels.clear();
84 sw_maps.clear(); 90 sw_maps.clear();
85 popupMenu.clear(); 91 popupMenu.clear();
86 92
87 for (uint i = 0; i < sw.count(); ++i) { 93 for (uint i = 0; i < sw.count(); ++i) {
88 QString keymap_map; 94 QString keymap_map;
89 if (sw[i][0] != '/') { 95 if (sw[i][0] != '/') {
90 96
91 keymap_map = map_dir.absPath() + "/" + sw[i]; 97 keymap_map = map_dir.absPath() + "/" + sw[i];
92 } else { 98 } else {
93 99
94 if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) 100 if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false)
95 && i != sw.count()-1) || !QFile::exists(sw[i])) { 101 && i != sw.count()-1) || !QFile::exists(sw[i])) {
96 continue; 102 continue;
97 } 103 }
98 keymap_map = sw[i]; 104 keymap_map = sw[i];
99 } 105 }
100 106
101 QFile map(keymap_map); 107 QFile map(keymap_map);
102 if (map.open(IO_ReadOnly)) { 108 if (map.open(IO_ReadOnly)) {
103 QString line; 109 QString line;
104 110
105 map.readLine(line, 1024); 111 map.readLine(line, 1024);
106 while (!map.atEnd()) { 112 while (!map.atEnd()) {
107 113
108 if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { 114 if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) {
109 115
110 if (i != sw.count()-1) { 116 if (i != sw.count()-1) {
111 if (keymap_map == current_map) { 117 if (keymap_map == current_map) {
112 lang = i; 118 lang = i;
113 } 119 }
114 sw_maps.append(keymap_map); 120 sw_maps.append(keymap_map);
115 labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 121 labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
116 popupMenu.insertItem(labels[labels.count()-1], labels.count()-1); 122 popupMenu.insertItem(labels[labels.count()-1], labels.count()-1);
117 } else { 123 } else {
118 current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); 124 current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace();
119 } 125 }
120 break; 126 break;
121 } 127 }
122 map.readLine(line, 1024); 128 map.readLine(line, 1024);
123 } 129 }
124 map.close(); 130 map.close();
125 } 131 }
126 } 132 }
127 133
128 setText(current); 134 setText(current);
129 } 135 }
130} 136}