summaryrefslogtreecommitdiff
path: root/inputmethods/multikey/configdlg.cpp
Unidiff
Diffstat (limited to 'inputmethods/multikey/configdlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/configdlg.cpp56
1 files changed, 45 insertions, 11 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index 10bc611..c5ebe3c 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -1,24 +1,22 @@
1/* 1/*
2 * TODO 2 * TODO
3 * make a font selection thing (size too) 3 * make a font selection thing (size too)
4 * make a cursor thing 4 * make a cursor thing
5 * add meta key support for german, etc 5 * add meta key support for german, etc
6 * 6 *
7 * 7 *
8 * 8 *
9 */ 9 */
10 10
11#include <iostream.h>
12
13#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
14#include <qpe/config.h> 12#include <qpe/config.h>
15 13
16#include <qwidget.h> 14#include <qwidget.h>
17#include <qdialog.h> 15#include <qdialog.h>
18#include <qtabwidget.h> 16#include <qtabwidget.h>
19#include <qvbox.h> 17#include <qvbox.h>
20#include <qgrid.h> 18#include <qgrid.h>
21#include <qgroupbox.h> 19#include <qgroupbox.h>
22#include <qlabel.h> 20#include <qlabel.h>
23#include <qcheckbox.h> 21#include <qcheckbox.h>
24#include <qsizepolicy.h> 22#include <qsizepolicy.h>
@@ -51,50 +49,88 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
51 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); 49 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box);
52 50
53 keymaps = new QListBox (map_group); 51 keymaps = new QListBox (map_group);
54 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 52 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
55 53
56 QString cur(tr("Current Language")); 54 QString cur(tr("Current Language"));
57 keymaps->insertItem(cur); 55 keymaps->insertItem(cur);
58 keymaps->setSelected(0, true); 56 keymaps->setSelected(0, true);
59 57
60 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); 58 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap");
61 default_maps = map_dir.entryList(); // so i can access it in other places 59 default_maps = map_dir.entryList(); // so i can access it in other places
62 60
63 for (uint i = 0; i <map_dir.count(); i++) { 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()) {
64 70
65 keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]); 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 }
66 if (map_dir.absPath() + "/" + map_dir[i] == current_map) { 83 if (map_dir.absPath() + "/" + map_dir[i] == current_map) {
67 84
68 keymaps->setSelected(i + 1, true); 85 keymaps->setSelected(i + 1, true);
69 } 86 }
70 87
71 } 88 }
72 89
73 custom_maps = config.readListEntry("maps", QChar('|')); 90 custom_maps = config.readListEntry("maps", QChar('|'));
74 91
75 for (uint i = 0; i < custom_maps.count(); i++) { 92 for (uint i = 0; i < custom_maps.count(); i++) {
76 93
77 if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) 94 if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false)
78 || !QFile::exists(custom_maps[i])) { 95 || !QFile::exists(custom_maps[i])) {
79 96
80 custom_maps.remove(custom_maps.at(i)); 97 custom_maps.remove(custom_maps.at(i));
81 98
82 // remove it from the list too 99 // remove it from the list too
83 config.writeEntry("maps", custom_maps.join("|")); 100 config.writeEntry("maps", custom_maps.join("|"));
84 101
85 102
86 } else { 103 } else {
87 104
88 keymaps->insertItem(custom_maps[i]); 105 QFile map (custom_maps[i]);
106 if (map.open(IO_ReadOnly)) {
107
108 QString line; bool found = 0;
109
110 map.readLine(line, 1024);
111 while (!map.atEnd()) {
112
113 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
114
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 }
89 if (custom_maps[i] == current_map) { 125 if (custom_maps[i] == current_map) {
90 126
91 keymaps->setSelected(map_dir.count() + i + 1, true); 127 keymaps->setSelected(map_dir.count() + i + 1, true);
92 } 128 }
93 } 129 }
94 } 130 }
95 131
96 // have to "+1" because the "current language" listItem... remember? 132 // have to "+1" because the "current language" listItem... remember?
97 133
98 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); 134 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int)));
99 135
100 136
@@ -223,65 +259,63 @@ void ConfigDlg::repeatTog() {
223 */ 259 */
224 260
225void ConfigDlg::setMap(int index) { 261void ConfigDlg::setMap(int index) {
226 262
227 if (index == 0) { 263 if (index == 0) {
228 264
229 remove_button->setDisabled(true); 265 remove_button->setDisabled(true);
230 emit setMapToDefault(); 266 emit setMapToDefault();
231 } 267 }
232 else if ((uint)index <= default_maps.count()) { 268 else if ((uint)index <= default_maps.count()) {
233 269
234 remove_button->setDisabled(true); 270 remove_button->setDisabled(true);
235 emit setMapToFile(keymaps->text(index)); 271 emit setMapToFile(QPEApplication::qpeDir() + "/share/multikey/" + default_maps[index - 1]);
236 272
237 } else { 273 } else {
238 274
239 remove_button->setEnabled(true); 275 remove_button->setEnabled(true);
240 emit setMapToFile(keymaps->text(index)); 276 emit setMapToFile(custom_maps[index - default_maps.count() - 1]);
241 } 277 }
242} 278}
243 279
244// ConfigDlg::addMap() {{{1 280// ConfigDlg::addMap() {{{1
245void ConfigDlg::addMap() { 281void ConfigDlg::addMap() {
246 282
247 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); 283 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath());
248 284
249 if (map.isNull()) return; 285 if (map.isNull()) return;
250 286
251 Config config ("multikey"); 287 Config config ("multikey");
252 config.setGroup("keymaps"); 288 config.setGroup("keymaps");
253 QStringList maps = config.readListEntry("maps", QChar('|')); 289 QStringList maps = config.readListEntry("maps", QChar('|'));
254 maps.append(map); 290 maps.append(map);
291 custom_maps.append(map);
255 keymaps->insertItem(map); 292 keymaps->insertItem(map);
256 keymaps->setSelected(keymaps->count() - 1, true); 293 keymaps->setSelected(keymaps->count() - 1, true);
257 294
258 295
259 config.writeEntry("maps", maps, QChar('|')); 296 config.writeEntry("maps", maps, QChar('|'));
260 config.writeEntry("current", map); 297 config.writeEntry("current", map);
261 298
262} 299}
263 300
264// ConfigDlg::removeMap() {{{1 301// ConfigDlg::removeMap() {{{1
265void ConfigDlg::removeMap() { 302void ConfigDlg::removeMap() {
266 303
267 cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n";
268 cout << "currentItem : " << keymaps->currentItem() << "\n";
269
270 // move selection up one 304 // move selection up one
271 keymaps->setSelected(keymaps->currentItem() - 1, true); 305 keymaps->setSelected(keymaps->currentItem() - 1, true);
272 // delete the next selected item cus you just moved it up 306 // delete the next selected item cus you just moved it up
273 keymaps->removeItem(keymaps->currentItem() + 1); 307 keymaps->removeItem(keymaps->currentItem() + 1);
274 308
275 custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]); 309 custom_maps.remove(custom_maps.at(keymaps->currentItem() - default_maps.count()));
276 310
277 // write the changes 311 // write the changes
278 Config config ("multikey"); 312 Config config ("multikey");
279 config.setGroup("keymaps"); 313 config.setGroup("keymaps");
280 config.writeEntry("maps", custom_maps, QChar('|')); 314 config.writeEntry("maps", custom_maps, QChar('|'));
281} 315}
282 316
283/* ConfigDlg::slots for the color buttons {{{1 317/* ConfigDlg::slots for the color buttons {{{1
284 * 318 *
285 * these four slots are almost the same, except for the names. i was thinking 319 * these four slots are almost the same, except for the names. i was thinking
286 * of making a map with pointers to the buttons and names of the configEntry 320 * of making a map with pointers to the buttons and names of the configEntry
287 * so it could be one slot, but then there would be no way of telling which 321 * so it could be one slot, but then there would be no way of telling which