summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/configdlg.cpp93
-rw-r--r--inputmethods/multikey/configdlg.h8
-rw-r--r--inputmethods/multikey/keyboard.cpp37
-rw-r--r--inputmethods/multikey/keyboard.h2
4 files changed, 95 insertions, 45 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index 157714c..a6e4dad 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -8,2 +8,4 @@
8 8
9#include <iostream.h>
10
9#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
@@ -24,3 +26,4 @@
24#include <opie/ofiledialog.h> 26#include <opie/ofiledialog.h>
25#include <iostream.h> 27#include <qdir.h>
28#include <qfileinfo.h>
26#include "configdlg.h" 29#include "configdlg.h"
@@ -32,2 +35,4 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
32 Config config ("multikey"); 35 Config config ("multikey");
36 config.setGroup("keymaps");
37 QString current_map = config.readEntry("current", 0);
33 38
@@ -48,9 +53,38 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
48 keymaps->insertItem(cur); 53 keymaps->insertItem(cur);
54 keymaps->setSelected(0, true);
55
56 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap");
57 default_maps = map_dir.entryList(); // so i can access it in other places
49 58
50 config.setGroup ("keymaps"); 59 for (uint i = 0; i <map_dir.count(); i++) {
51 QStringList maps = config.readListEntry("maps", QChar('|')); 60
61 keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]);
62 if (map_dir.absPath() + "/" + map_dir[i] == current_map) {
63
64 keymaps->setSelected(i + 1, true);
65 }
66
67 }
68
69 custom_maps = config.readListEntry("maps", QChar('|'));
70
71 for (uint i = 0; i < custom_maps.count(); i++) {
72
73 if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false)
74 || !QFile::exists(custom_maps[i])) {
75
76 custom_maps.remove(custom_maps.at(i));
77
78 // remove it from the list too
79 config.writeEntry("maps", custom_maps.join("|"));
52 80
53 for (unsigned int i = 0; i < maps.count(); i++) {
54 81
55 keymaps->insertItem(maps[i]); 82 } else {
83
84 keymaps->insertItem(custom_maps[i]);
85 if (custom_maps[i] == current_map) {
86
87 keymaps->setSelected(map_dir.count() + i + 1, true);
88 }
89 }
56 } 90 }
@@ -58,3 +92,2 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
58 // have to "+1" because the "current language" listItem... remember? 92 // have to "+1" because the "current language" listItem... remember?
59 keymaps->setSelected(config.readNumEntry("current", 0) + 1, true);
60 93
@@ -73,2 +106,3 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
73 remove_button->setFlat((bool)1); 106 remove_button->setFlat((bool)1);
107 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap()));
74 108
@@ -128,6 +162,4 @@ void ConfigDlg::pickTog() {
128 * first element in the QStringList, but here it's the "Current Language" 162 * first element in the QStringList, but here it's the "Current Language"
129 * listItem. therefor you have to minus one to the index before you access 163 * listItem. therefor you have to minus one to the index before you access it.
130 * it from the config file.
131 * 164 *
132 * and later on, the "current language" setting should be -1 in the config file
133 */ 165 */
@@ -138,4 +170,3 @@ void ConfigDlg::setMap(int index) {
138 170
139 if (remove_button->isEnabled()) 171 remove_button->setDisabled(true);
140 remove_button->setDisabled(true);
141 172
@@ -143,8 +174,11 @@ void ConfigDlg::setMap(int index) {
143 } 174 }
144 else { 175 else if ((uint)index <= default_maps.count()) {
176
177 remove_button->setDisabled(true);
145 178
146 if (!remove_button->isEnabled()) 179 } else {
147 remove_button->setEnabled(true);
148 180
149 emit setMapToFile(index - 1); 181 remove_button->setEnabled(true);
182
183 emit setMapToFile(keymaps->text(index));
150 } 184 }
@@ -154,4 +188,13 @@ void ConfigDlg::addMap() {
154 188
155 QString map = OFileDialog::getOpenFileName(2, QPEApplication::qpeDir() + "/share/multikey"); 189 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath());
156 cout << "added file " << map << "!\n"; 190 Config config ("multikey");
191 config.setGroup("keymaps");
192 QStringList maps = config.readListEntry("maps", QChar('|'));
193 maps.append(map);
194 keymaps->insertItem(map);
195 keymaps->setSelected(keymaps->count() - 1, true);
196
197
198 config.writeEntry("maps", maps.join("|"));
199 config.writeEntry("current", map);
157 200
@@ -159,4 +202,18 @@ void ConfigDlg::addMap() {
159 202
160void ConfigDlg::removeMap(int index) { 203void ConfigDlg::removeMap() {
204
205 cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n";
206 cout << "currentItem : " << keymaps->currentItem() << "\n";
161 207
208 // move selection up one
209 keymaps->setSelected(keymaps->currentItem() - 1, true);
210 // delete the next selected item cus you just moved it up
211 keymaps->removeItem(keymaps->currentItem() + 1);
212
213 custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]);
214
215 // write the changes
216 Config config ("multikey");
217 config.setGroup("keymaps");
218 config.writeEntry("maps", custom_maps.join("|"));
162} 219}
diff --git a/inputmethods/multikey/configdlg.h b/inputmethods/multikey/configdlg.h
index 03a3547..07d109c 100644
--- a/inputmethods/multikey/configdlg.h
+++ b/inputmethods/multikey/configdlg.h
@@ -19,3 +19,3 @@ signals:
19 void setMapToDefault(); 19 void setMapToDefault();
20 void setMapToFile(int index); 20 void setMapToFile(QString map);
21 21
@@ -25,3 +25,3 @@ private slots:
25 void addMap(); 25 void addMap();
26 void removeMap(int index); 26 void removeMap();
27 27
@@ -33,2 +33,6 @@ private:
33 33
34
35 QStringList default_maps; // the maps in your share/multikey/ dir
36 QStringList custom_maps; // maps you added with the 'add' button
37
34}; 38};
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index c53ae6c..ac3d9be 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -292,4 +292,4 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
292 this, SLOT(setMapToDefault())); 292 this, SLOT(setMapToDefault()));
293 connect(configdlg, SIGNAL(setMapToFile(int)), 293 connect(configdlg, SIGNAL(setMapToFile(QString)),
294 this, SLOT(setMapToFile(int))); 294 this, SLOT(setMapToFile(QString)));
295 configdlg->showMaximized(); 295 configdlg->showMaximized();
@@ -521,3 +521,3 @@ void Keyboard::setMapToDefault() {
521 config->setGroup ("keymaps"); 521 config->setGroup ("keymaps");
522 config->writeEntry ("current", -1); // default closed 522 config->writeEntry ("current", key_map); // default closed
523 delete config; 523 delete config;
@@ -531,3 +531,3 @@ void Keyboard::setMapToDefault() {
531 531
532void Keyboard::setMapToFile(int index) { 532void Keyboard::setMapToFile(QString map) {
533 533
@@ -536,7 +536,4 @@ void Keyboard::setMapToFile(int index) {
536 config->setGroup ("keymaps"); 536 config->setGroup ("keymaps");
537 config->writeEntry ("current", index); // default closed 537 config->writeEntry ("current", map); // default closed
538 538
539
540 /* now you have to retrieve the map */
541 QStringList maps = config->readListEntry("maps", QChar('|'));
542 delete config; 539 delete config;
@@ -544,6 +541,6 @@ void Keyboard::setMapToFile(int index) {
544 delete keys; 541 delete keys;
545 if (index < 0 || (int)maps.count() <= index) 542 if (QFile(map).exists())
546 keys = new Keys(); 543 keys = new Keys(map);
547 else 544 else
548 keys = new Keys(maps[index]); 545 keys = new Keys();
549 546
@@ -861,10 +858,6 @@ Keys::Keys() {
861 config->setGroup( "keymaps" ); 858 config->setGroup( "keymaps" );
862 QStringList maps = config->readListEntry ("maps", QChar('|')); 859 QString map = config->readEntry( "current" );
863
864 int index = config->readNumEntry( "current", -1 );
865 delete config; 860 delete config;
866 861
867 QString key_map; 862 if (map.isNull() || !(QFile(map).exists())) {
868
869 if (index < 0 || (int)maps.count() <= index) {
870 863
@@ -875,12 +868,8 @@ Keys::Keys() {
875 868
876 key_map = QPEApplication::qpeDir() + "/share/multikey/" 869 map = QPEApplication::qpeDir() + "/share/multikey/"
877 + l + ".keymap"; 870 + l + ".keymap";
878 871
879 } else { 872 }
880
881 key_map = maps[index];
882 }
883
884 873
885 setKeysFromFile(key_map); 874 setKeysFromFile(map);
886} 875}
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h
index 7a8d4b4..805f0ed 100644
--- a/inputmethods/multikey/keyboard.h
+++ b/inputmethods/multikey/keyboard.h
@@ -115,3 +115,3 @@ private slots:
115 void setMapToDefault(); 115 void setMapToDefault();
116 void setMapToFile(int index); 116 void setMapToFile(QString map);
117 117