summaryrefslogtreecommitdiff
path: root/inputmethods
authormickeyl <mickeyl>2004-01-03 16:57:51 (UTC)
committer mickeyl <mickeyl>2004-01-03 16:57:51 (UTC)
commitbdabd0e055d494c7546de08348e32cf5622c9074 (patch) (unidiff)
tree97346f3ef40158d31c2e649390a941135890a39b /inputmethods
parent4f7bf49ba4c0466aa9cea618c9317ac965a1118f (diff)
downloadopie-bdabd0e055d494c7546de08348e32cf5622c9074.zip
opie-bdabd0e055d494c7546de08348e32cf5622c9074.tar.gz
opie-bdabd0e055d494c7546de08348e32cf5622c9074.tar.bz2
add multikey patches courtesy Anton Kachalov <mouse@altlinux.ru>
Diffstat (limited to 'inputmethods') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/configdlg.cpp238
-rw-r--r--inputmethods/multikey/configdlg.h8
-rw-r--r--inputmethods/multikey/keyboard.cpp42
-rw-r--r--inputmethods/multikey/keyboard.h2
4 files changed, 209 insertions, 81 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index a8206b7..f127d0e 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -12,2 +12,3 @@
12#include <qpe/config.h> 12#include <qpe/config.h>
13#include <qpe/resource.h>
13 14
@@ -25,2 +26,3 @@
25#include <qstringlist.h> 26#include <qstringlist.h>
27#include <qtoolbutton.h>
26#include <opie/ofiledialog.h> 28#include <opie/ofiledialog.h>
@@ -50,4 +52,20 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
50 52
51 keymaps = new QListBox (map_group); 53 QHBox *hbox1 = new QHBox(map_group);
54 keymaps = new QListBox(hbox1);
52 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 55 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
56 QVBox *vbox1 = new QVBox(hbox1);
57
58 QToolButton *tb1 = new QToolButton(vbox1, tr("Move Up"));
59 tb1->setPixmap(Resource::loadPixmap("up"));
60 tb1->setAutoRaise(TRUE);
61 tb1->setFocusPolicy(QWidget::NoFocus);
62 tb1->setToggleButton(FALSE);
63 connect(tb1, SIGNAL(clicked()), this, SLOT(moveSelectedUp()));
64
65 QToolButton *tb2 = new QToolButton(vbox1, tr("Move Down"));
66 tb2->setPixmap(Resource::loadPixmap("down"));
67 tb2->setAutoRaise(TRUE);
68 tb2->setFocusPolicy(QWidget::NoFocus);
69 tb2->setToggleButton(FALSE);
70 connect(tb2, SIGNAL(clicked()), this, SLOT(moveSelectedDown()));
53 71
@@ -59,72 +77,53 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
59 default_maps = map_dir.entryList(); // so i can access it in other places 77 default_maps = map_dir.entryList(); // so i can access it in other places
60
61 for (uint i = 0; i < map_dir.count(); i++) {
62
63 QFile map (map_dir.absPath() + "/" + map_dir[i]);
64 if (map.open(IO_ReadOnly)) {
65
66 QString line; bool found = 0;
67
68 map.readLine(line, 1024);
69 while (!map.atEnd()) {
70
71 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
72
73 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
74 found = 1;
75 break;
76 }
77 map.readLine(line, 1024);
78 }
79 if (!found) keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]);
80
81 map.close();
82 }
83 if (map_dir.absPath() + "/" + map_dir[i] == current_map) {
84
85 keymaps->setSelected(i + 1, true);
86 }
87
88 }
89
90 custom_maps = config.readListEntry("maps", QChar('|')); 78 custom_maps = config.readListEntry("maps", QChar('|'));
79 sw_maps = ConfigDlg::loadSw();
91 80
92 for (uint i = 0; i < custom_maps.count(); i++) { 81 QStringList sw_copy(sw_maps);
82 for (uint i = 0; i < sw_copy.count(); i++) {
93 83
94 if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) 84 QString keymap_map;
95 || !QFile::exists(custom_maps[i])) { 85 if (sw_copy[i][0] != '/') { /* share/multikey */
96 86
97 custom_maps.remove(custom_maps.at(i)); 87 keymap_map = map_dir.absPath() + "/" + sw_copy[i];
88 } else {
98 89
99 // remove it from the list too 90 if (map_dir.exists(QFileInfo(sw_copy[i]).fileName(), false)
100 config.writeEntry("maps", custom_maps.join("|")); 91 || !QFile::exists(sw_copy[i])) {
101 92
93 custom_maps.remove(sw_copy[i]);
94 sw_maps.remove(sw_copy[i]);
102 95
103 } else { 96 // remove it from the list too
97 config.writeEntry("maps", custom_maps.join("|"));
104 98
105 QFile map (custom_maps[i]); 99 continue;
106 if (map.open(IO_ReadOnly)) { 100 }
101 keymap_map = sw_copy[i];
102 }
107 103
108 QString line; bool found = 0; 104 QFile map(keymap_map);
105 if (map.open(IO_ReadOnly)) {
109 106
110 map.readLine(line, 1024); 107 QString line; bool found = 0;
111 while (!map.atEnd()) {
112 108
113 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { 109 map.readLine(line, 1024);
114 110 while (!map.atEnd()) {
115 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
116 found = 1;
117 break;
118 }
119 map.readLine(line, 1024);
120 }
121 if (!found) keymaps->insertItem(custom_maps[i]);
122
123 map.close();
124 }
125 if (custom_maps[i] == current_map) {
126 111
127 keymaps->setSelected(map_dir.count() + i + 1, true); 112 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
128 } 113
129 } 114 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
115 found = 1;
116 break;
117 }
118 map.readLine(line, 1024);
119 }
120 if (!found)
121 keymaps->insertItem(keymap_map);
122
123 map.close();
124 }
125
126 if (keymap_map == current_map) {
127 keymaps->setSelected(i + 1, true);
128 }
130 } 129 }
@@ -135,3 +134,2 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
135 134
136
137 QGrid *add_remove_grid = new QGrid(2, map_group); 135 QGrid *add_remove_grid = new QGrid(2, map_group);
@@ -141,3 +139,3 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
141 add_button = new QPushButton(tr("Add"), add_remove_grid); 139 add_button = new QPushButton(tr("Add"), add_remove_grid);
142 add_button->setFlat((bool)1); 140 add_button->setFlat(TRUE);
143 connect(add_button, SIGNAL(clicked()), SLOT(addMap())); 141 connect(add_button, SIGNAL(clicked()), SLOT(addMap()));
@@ -145,5 +143,5 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
145 remove_button = new QPushButton(tr("Remove"), add_remove_grid); 143 remove_button = new QPushButton(tr("Remove"), add_remove_grid);
146 remove_button->setFlat((bool)1); 144 remove_button->setFlat(TRUE);
147 if ((int)map_dir.count() >= keymaps->currentItem()) 145 if (default_maps.find(QFileInfo(current_map).fileName()) != default_maps.end())
148 remove_button->setDisabled(true); 146 remove_button->setDisabled(true);
149 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); 147 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap()));
@@ -155,3 +153,3 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
155 config.setGroup ("general"); 153 config.setGroup ("general");
156 bool pick_open = config.readBoolEntry ("usePickboard", (bool)0); // default closed 154 bool pick_open = config.readBoolEntry ("usePickboard", FALSE); // default closed
157 if (pick_open) { 155 if (pick_open) {
@@ -165,3 +163,3 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
165 repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); 163 repeat_button = new QCheckBox(tr("Key Repeat"), other_grid);
166 bool repeat_on = config.readBoolEntry ("useRepeat", (bool)1); 164 bool repeat_on = config.readBoolEntry ("useRepeat", TRUE);
167 165
@@ -173,3 +171,2 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
173 171
174
175 /* 172 /*
@@ -191,3 +188,3 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
191 connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); 188 connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked()));
192 keycolor_button->setFlat((bool)1); 189 keycolor_button->setFlat(TRUE);
193 color = config.readListEntry("keycolor", QChar(',')); 190 color = config.readListEntry("keycolor", QChar(','));
@@ -208,3 +205,3 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
208 connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); 205 connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked()));
209 keycolor_pressed_button->setFlat((bool)1); 206 keycolor_pressed_button->setFlat(TRUE);
210 color = config.readListEntry("keycolor_pressed", QChar(',')); 207 color = config.readListEntry("keycolor_pressed", QChar(','));
@@ -215,3 +212,3 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
215 connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); 212 connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked()));
216 keycolor_lines_button->setFlat((bool)1); 213 keycolor_lines_button->setFlat(TRUE);
217 color = config.readListEntry("keycolor_lines", QChar(',')); 214 color = config.readListEntry("keycolor_lines", QChar(','));
@@ -223,3 +220,3 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
223 connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); 220 connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked()));
224 textcolor_button->setFlat((bool)1); 221 textcolor_button->setFlat(TRUE);
225 color = config.readListEntry("textcolor", QChar(',')); 222 color = config.readListEntry("textcolor", QChar(','));
@@ -227,6 +224,90 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
227 224
228
229 label = new QLabel("", color_box); // a spacer so the above buttons dont expand 225 label = new QLabel("", color_box); // a spacer so the above buttons dont expand
230 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 226 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
227}
228
229ConfigDlg::~ConfigDlg()
230{
231 emit reloadSw();
232}
233
234QStringList ConfigDlg::loadSw()
235{
236 Config *config = new Config("multikey");
237 config->setGroup("keymaps");
238 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap");
239 QStringList d_maps = map_dir.entryList(); // so i can access it in other places
240 QStringList c_maps = config->readListEntry("maps", QChar('|'));
241 QStringList s_maps = config->readListEntry("sw", QChar('|'));
242 delete config;
243
244 if (!s_maps.count())
245 {
246 s_maps = d_maps+c_maps;
247 }
248 else
249 {
250 /* Clear non existents entries */
251 QStringList s_copy = s_maps;
252 for (uint i = 0; i < s_copy.count(); ++i) {
253 if (d_maps.find(s_copy[i]) == d_maps.end()
254 && c_maps.find(s_copy[i]) == c_maps.end()) {
255 s_maps.remove(s_copy[i]);
256 }
257 }
258 /* Update sw_maps from default_maps */
259 for (uint i = 0; i < d_maps.count(); ++i) {
260 if (s_maps.find(d_maps[i]) == s_maps.end()) {
261 s_maps.append(d_maps[i]);
262 }
263 }
264 /* Update sw_maps from custom_maps */
265 for (uint i = 0; i < c_maps.count(); ++i) {
266 if (s_maps.find(c_maps[i]) == s_maps.end()) {
267 s_maps.append(c_maps[i]);
268 }
269 }
270 }
271
272 return s_maps;
273}
274
275void ConfigDlg::moveSelectedUp()
276{
277 int i = keymaps->currentItem();
278 /* Ignore Current Language */
279 if (i > 1) {
280 QString t = sw_maps[i-1];
281 sw_maps[i-1] = sw_maps[i-2];
282 sw_maps[i-2] = t;
283
284 QString item = keymaps->currentText();
285 keymaps->removeItem(i);
286 keymaps->insertItem(item, i-1);
287 keymaps->setCurrentItem(i-1);
288
289 Config config("multikey");
290 config.setGroup("keymaps");
291 config.writeEntry("sw", sw_maps, QChar('|'));
292 }
293}
231 294
295void ConfigDlg::moveSelectedDown()
296{
297 int i = keymaps->currentItem();
298 /* Ignore Current Language */
299 if (i > 0 && i < (int)keymaps->count() - 1) {
300 QString t = sw_maps[i-1];
301 sw_maps[i-1] = sw_maps[i];
302 sw_maps[i] = t;
303
304 QString item = keymaps->currentText();
305 keymaps->removeItem(i);
306 keymaps->insertItem(item, i+1);
307 keymaps->setCurrentItem(i+1);
308
309 Config config("multikey");
310 config.setGroup("keymaps");
311 config.writeEntry("sw", sw_maps, QChar('|'));
312 }
232} 313}
@@ -273,6 +354,6 @@ void ConfigDlg::setMap(int index) {
273 } 354 }
274 else if ((uint)index <= default_maps.count()) { 355 else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) {
275 356
276 remove_button->setDisabled(true); 357 remove_button->setDisabled(true);
277 emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + default_maps[index - 1]); 358 emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + sw_maps[index - 1]);
278 359
@@ -281,3 +362,3 @@ void ConfigDlg::setMap(int index) {
281 remove_button->setEnabled(true); 362 remove_button->setEnabled(true);
282 emit setMapToFile(custom_maps[index - default_maps.count() - 1]); 363 emit setMapToFile(sw_maps[index - 1]);
283 } 364 }
@@ -297,2 +378,4 @@ void ConfigDlg::addMap() {
297 custom_maps.append(map); 378 custom_maps.append(map);
379 if (sw_maps.find(map) == sw_maps.end())
380 sw_maps.append(map);
298 381
@@ -323,2 +406,3 @@ void ConfigDlg::addMap() {
323 config.writeEntry("maps", maps, QChar('|')); 406 config.writeEntry("maps", maps, QChar('|'));
407 config.writeEntry("sw", sw_maps, QChar('|'));
324 config.writeEntry("current", map); 408 config.writeEntry("current", map);
@@ -335,3 +419,4 @@ void ConfigDlg::removeMap() {
335 419
336 custom_maps.remove(custom_maps.at(keymaps->currentItem() - default_maps.count())); 420 custom_maps.remove(sw_maps[keymaps->currentItem()]);
421 sw_maps.remove(sw_maps.at(keymaps->currentItem()));
337 422
@@ -341,2 +426,3 @@ void ConfigDlg::removeMap() {
341 config.writeEntry("maps", custom_maps, QChar('|')); 426 config.writeEntry("maps", custom_maps, QChar('|'));
427 config.writeEntry("sw", sw_maps, QChar('|'));
342} 428}
diff --git a/inputmethods/multikey/configdlg.h b/inputmethods/multikey/configdlg.h
index 336932b..ea157c5 100644
--- a/inputmethods/multikey/configdlg.h
+++ b/inputmethods/multikey/configdlg.h
@@ -15,2 +15,4 @@ public:
15 ConfigDlg (); 15 ConfigDlg ();
16 ~ConfigDlg ();
17 static QStringList ConfigDlg::loadSw();
16 18
@@ -23,2 +25,7 @@ signals:
23 void configDlgClosed(); 25 void configDlgClosed();
26 void reloadSw();
27
28protected slots:
29 void moveSelectedUp();
30 void moveSelectedDown();
24 31
@@ -49,2 +56,3 @@ private:
49 QStringList custom_maps; // maps you added with the 'add' button 56 QStringList custom_maps; // maps you added with the 'add' button
57 QStringList sw_maps; // maps, which used in keyboard switch rotation ring
50 58
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 2ce6dd3..aec0ad3 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -33,3 +33,3 @@
33#include <ctype.h> 33#include <ctype.h>
34#include <qfile.h> 34#include <qdir.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
@@ -96,2 +96,5 @@ Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
96 96
97 QCopChannel* kbdChannel = new QCopChannel("MultiKey/Keyboard", this);
98 connect(kbdChannel, SIGNAL(received(const QCString &, const QByteArray &)),
99 this, SLOT(receive(const QCString &, const QByteArray &)));
97} 100}
@@ -101,3 +104,3 @@ Keyboard::~Keyboard() {
101 if ( configdlg ) { 104 if ( configdlg ) {
102 delete (ConfigDlg *) configdlg; 105 delete configdlg;
103 configdlg = 0; 106 configdlg = 0;
@@ -419,3 +422,3 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
419 422
420 delete (ConfigDlg *) configdlg; 423 delete configdlg;
421 configdlg = 0; 424 configdlg = 0;
@@ -436,2 +439,4 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
436 this, SLOT(cleanupConfigDlg())); 439 this, SLOT(cleanupConfigDlg()));
440 connect(configdlg, SIGNAL(reloadSw()),
441 this, SLOT(reloadSw()));
437 configdlg->showMaximized(); 442 configdlg->showMaximized();
@@ -762,2 +767,13 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
762 767
768void Keyboard::receive(const QCString &msg, const QByteArray &data)
769{
770 if (msg == "setmultikey(QString)") {
771 QDataStream stream(data, IO_ReadOnly);
772 QString map;
773 stream >> map;
774 setMapToFile(map);
775 } else if (msg == "getmultikey()") {
776 reloadSw();
777 }
778}
763 779
@@ -913,3 +929,3 @@ void Keyboard::cleanupConfigDlg() {
913 if ( configdlg ) { 929 if ( configdlg ) {
914 delete (ConfigDlg *) configdlg; 930 delete configdlg;
915 configdlg = 0; 931 configdlg = 0;
@@ -918,2 +934,13 @@ void Keyboard::cleanupConfigDlg() {
918 934
935void Keyboard::reloadSw() {
936 QCopEnvelope e("MultiKey/Switcher", "setsw(QString,QString)");
937
938 Config* config = new Config("multikey");
939 config->setGroup("keymaps");
940 QString current_map = config->readEntry("current", "en.keymap");
941 delete config;
942
943 e << ConfigDlg::loadSw().join("|") << current_map;
944}
945
919/* Keyboard::setMapTo ... {{{1 */ 946/* Keyboard::setMapTo ... {{{1 */
@@ -928,2 +955,7 @@ void Keyboard::setMapToDefault() {
928 955
956 /* if Language represents as en_US, ru_RU, etc... */
957 int d = l.find('_');
958 if (d != -1) {
959 l.remove(d, l.length()-d);
960 }
929 QString key_map = QPEApplication::qpeDir() + "share/multikey/" 961 QString key_map = QPEApplication::qpeDir() + "share/multikey/"
@@ -1508,3 +1540,3 @@ void Keys::setKeysFromFile(const char * filename) {
1508 1540
1509 // other variables like lang & title 1541 // other variables like lang & title & sw
1510 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { 1542 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h
index 20c5cee..0b56988 100644
--- a/inputmethods/multikey/keyboard.h
+++ b/inputmethods/multikey/keyboard.h
@@ -132,2 +132,3 @@ private slots:
132 void cleanupConfigDlg(); 132 void cleanupConfigDlg();
133 void reloadSw();
133 134
@@ -135,2 +136,3 @@ private slots:
135 void reloadKeyboard(); 136 void reloadKeyboard();
137 void receive( const QCString &msg, const QByteArray &data );
136 138