summaryrefslogtreecommitdiff
authorerik <erik>2007-01-12 19:12:57 (UTC)
committer erik <erik>2007-01-12 19:12:57 (UTC)
commite9768d9a498037195b8ca3bb5155db7419f30e1a (patch) (unidiff)
tree55effb9a63d0533292d6c8989691c6050c23e032
parent37d5f4aeb353f4a3e48f5c739b7797e788687b77 (diff)
downloadopie-e9768d9a498037195b8ca3bb5155db7419f30e1a.zip
opie-e9768d9a498037195b8ca3bb5155db7419f30e1a.tar.gz
opie-e9768d9a498037195b8ca3bb5155db7419f30e1a.tar.bz2
Various comment changes to make them grammatically correct. Also changed the
behavior of the remove button. Only when a custom keymap is selected is the remove button ever shown. Added 'keymap...' to the add button to make it more clear that one is add a keymap and that a dialog to add it will come next. This should follow the Opie UI convention.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/configdlg.cpp18
-rw-r--r--inputmethods/multikey/configdlg.h2
2 files changed, 13 insertions, 7 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index 52c498b..24fdb7f 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -1,511 +1,517 @@
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 keymap editor 4 * make a keymap editor
5 * make keys translucent 5 * make keys translucent
6 * make vertical keys possible 6 * make vertical keys possible
7 * 7 *
8 * 8 *
9 */ 9 */
10 10
11#include <opie2/ofiledialog.h> 11#include <opie2/ofiledialog.h>
12#include <opie2/qcolordialog.h> 12#include <opie2/qcolordialog.h>
13#include <opie2/oresource.h> 13#include <opie2/oresource.h>
14 14
15#include <qpe/qpeapplication.h> 15#include <qpe/qpeapplication.h>
16#include <qpe/config.h> 16#include <qpe/config.h>
17 17
18#include <qlayout.h> 18#include <qlayout.h>
19#include <qwidget.h> 19#include <qwidget.h>
20#include <qdialog.h> 20#include <qdialog.h>
21#include <qtabwidget.h> 21#include <qtabwidget.h>
22#include <qvbox.h> 22#include <qvbox.h>
23#include <qgrid.h> 23#include <qgrid.h>
24#include <qgroupbox.h> 24#include <qgroupbox.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qcheckbox.h> 26#include <qcheckbox.h>
27#include <qsizepolicy.h> 27#include <qsizepolicy.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qlistbox.h> 29#include <qlistbox.h>
30#include <qstringlist.h> 30#include <qstringlist.h>
31#include <qtoolbutton.h> 31#include <qtoolbutton.h>
32#include <qdir.h> 32#include <qdir.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include "configdlg.h" 34#include "configdlg.h"
35#include "keyboard.h" 35#include "keyboard.h"
36 36
37using namespace Opie; 37using namespace Opie;
38using namespace Opie::Ui; 38using namespace Opie::Ui;
39// ConfigDlg::ConfigDlg() {{{1 39// ConfigDlg::ConfigDlg() {{{1
40ConfigDlg::ConfigDlg () : QDialog () 40ConfigDlg::ConfigDlg () : QDialog ()
41{ 41{
42 setCaption( tr("Multikey Configuration") ); 42 setCaption( tr("Multikey Configuration") );
43 Config config ("multikey"); 43 Config config ("multikey");
44 config.setGroup("keymaps"); 44 config.setGroup("keymaps");
45 QString current_map = config.readEntry("current", 0); 45 QString current_map = config.readEntry("current", 0);
46 46
47 /* 47 /*
48 * 'general config' tab 48 * 'general config' tab
49 */ 49 */
50 50
51 QVBoxLayout *base_lay = new QVBoxLayout(this); 51 QVBoxLayout *base_lay = new QVBoxLayout(this);
52 52
53 QTabWidget *tabs = new QTabWidget(this, "tabs"); 53 QTabWidget *tabs = new QTabWidget(this, "tabs");
54 54
55 QWidget *gen_box = new QWidget(tabs, "gen_tab"); 55 QWidget *gen_box = new QWidget(tabs, "gen_tab");
56 QVBoxLayout *gen_lay = new QVBoxLayout(gen_box); 56 QVBoxLayout *gen_lay = new QVBoxLayout(gen_box);
57 gen_lay->setMargin(3); 57 gen_lay->setMargin(3);
58 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); 58 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box);
59 59
60 QHBox *hbox1 = new QHBox(map_group); 60 QHBox *hbox1 = new QHBox(map_group);
61 keymaps = new QListBox(hbox1); 61 keymaps = new QListBox(hbox1);
62 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 62 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
63 QVBox *vbox1 = new QVBox(hbox1); 63 QVBox *vbox1 = new QVBox(hbox1);
64 64
65 QToolButton *tb1 = new QToolButton(vbox1, tr("Move Up")); 65 QToolButton *tb1 = new QToolButton(vbox1, tr("Move Up"));
66 tb1->setUsesBigPixmap( qApp->desktop()->size().width() > 330 ); 66 tb1->setUsesBigPixmap( qApp->desktop()->size().width() > 330 );
67 tb1->setPixmap(Opie::Core::OResource::loadPixmap("up", Opie::Core::OResource::SmallIcon)); 67 tb1->setPixmap(Opie::Core::OResource::loadPixmap("up", Opie::Core::OResource::SmallIcon));
68 tb1->setAutoRaise(TRUE); 68 tb1->setAutoRaise(TRUE);
69 tb1->setFocusPolicy(QWidget::NoFocus); 69 tb1->setFocusPolicy(QWidget::NoFocus);
70 tb1->setToggleButton(FALSE); 70 tb1->setToggleButton(FALSE);
71 connect(tb1, SIGNAL(clicked()), this, SLOT(moveSelectedUp())); 71 connect(tb1, SIGNAL(clicked()), this, SLOT(moveSelectedUp()));
72 72
73 QToolButton *tb2 = new QToolButton(vbox1, tr("Move Down")); 73 QToolButton *tb2 = new QToolButton(vbox1, tr("Move Down"));
74 tb2->setUsesBigPixmap( qApp->desktop()->size().width() > 330 ); 74 tb2->setUsesBigPixmap( qApp->desktop()->size().width() > 330 );
75 tb2->setPixmap(Opie::Core::OResource::loadPixmap("down", Opie::Core::OResource::SmallIcon)); 75 tb2->setPixmap(Opie::Core::OResource::loadPixmap("down", Opie::Core::OResource::SmallIcon));
76 tb2->setAutoRaise(TRUE); 76 tb2->setAutoRaise(TRUE);
77 tb2->setFocusPolicy(QWidget::NoFocus); 77 tb2->setFocusPolicy(QWidget::NoFocus);
78 tb2->setToggleButton(FALSE); 78 tb2->setToggleButton(FALSE);
79 connect(tb2, SIGNAL(clicked()), this, SLOT(moveSelectedDown())); 79 connect(tb2, SIGNAL(clicked()), this, SLOT(moveSelectedDown()));
80 80
81 QString cur(tr("Current Language")); 81 QString cur(tr("Current Language"));
82 keymaps->insertItem(cur); 82 keymaps->insertItem(cur);
83 keymaps->setSelected(0, true); 83 keymaps->setSelected(0, true);
84 84
85 QDir map_dir(QPEApplication::qpeDir() + "share/multikey", "*.keymap"); 85 QDir map_dir(QPEApplication::qpeDir() + "share/multikey", "*.keymap");
86 default_maps = map_dir.entryList(); // so i can access it in other places 86 default_maps = map_dir.entryList(); // so the object can access keymaps in other places
87 custom_maps = config.readListEntry("maps", QChar('|')); 87 custom_maps = config.readListEntry("maps", QChar('|'));
88 sw_maps = ConfigDlg::loadSw(); 88 sw_maps = ConfigDlg::loadSw();
89 89
90 QStringList sw_copy(sw_maps); 90 QStringList sw_copy(sw_maps);
91 for (uint i = 0; i < sw_copy.count(); i++) { 91 for (uint i = 0; i < sw_copy.count(); i++) {
92 92
93 QString keymap_map; 93 QString keymap_map;
94 if (sw_copy[i][0] != '/') { /* share/multikey */ 94 if (sw_copy[i][0] != '/') { /* share/multikey */
95 95
96 keymap_map = map_dir.absPath() + "/" + sw_copy[i]; 96 keymap_map = map_dir.absPath() + "/" + sw_copy[i];
97 } else { 97 } else {
98 98
99 if (map_dir.exists(QFileInfo(sw_copy[i]).fileName(), false) 99 if (map_dir.exists(QFileInfo(sw_copy[i]).fileName(), false)
100 || !QFile::exists(sw_copy[i])) { 100 || !QFile::exists(sw_copy[i])) {
101 101
102 custom_maps.remove(sw_copy[i]); 102 custom_maps.remove(sw_copy[i]);
103 sw_maps.remove(sw_copy[i]); 103 sw_maps.remove(sw_copy[i]);
104 104
105 // remove it from the list too 105 // remove it from the list too
106 config.writeEntry("maps", custom_maps.join("|")); 106 config.writeEntry("maps", custom_maps.join("|"));
107 107
108 continue; 108 continue;
109 } 109 }
110 keymap_map = sw_copy[i]; 110 keymap_map = sw_copy[i];
111 } 111 }
112 112
113 QFile map(keymap_map); 113 QFile map(keymap_map);
114 if (map.open(IO_ReadOnly)) { 114 if (map.open(IO_ReadOnly)) {
115 115
116 QString line; bool found = 0; 116 QString line; bool found = 0;
117 117
118 map.readLine(line, 1024); 118 map.readLine(line, 1024);
119 while (!map.atEnd()) { 119 while (!map.atEnd()) {
120 120
121 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { 121 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
122 122
123 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 123 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
124 found = 1; 124 found = 1;
125 break; 125 break;
126 } 126 }
127 map.readLine(line, 1024); 127 map.readLine(line, 1024);
128 } 128 }
129 if (!found) 129 if (!found)
130 keymaps->insertItem(keymap_map); 130 keymaps->insertItem(keymap_map);
131 131
132 map.close(); 132 map.close();
133 } 133 }
134 134
135 if (keymap_map == current_map) { 135 if (keymap_map == current_map) {
136 keymaps->setSelected(i + 1, true); 136 keymaps->setSelected(i + 1, true);
137 } 137 }
138 } 138 }
139 139
140 // have to "+1" because the "current language" listItem... remember? 140 // have to "+1" because the "current language" listItem... remember?
141 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); 141 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int)));
142 142
143 QGrid *add_remove_grid = new QGrid(2, map_group); 143 QGrid *add_remove_grid = new QGrid(2, map_group);
144 add_remove_grid->setMargin(3); 144 add_remove_grid->setMargin(3);
145 add_remove_grid->setSpacing(3); 145 add_remove_grid->setSpacing(3);
146 146
147 add_button = new QPushButton(tr("Add"), add_remove_grid); 147 add_button = new QPushButton(tr("Add keymap..."), add_remove_grid);
148 add_button->setFlat(TRUE); 148 add_button->setFlat(TRUE);
149 connect(add_button, SIGNAL(clicked()), SLOT(addMap())); 149 connect(add_button, SIGNAL(clicked()), SLOT(addMap()));
150 150
151 remove_button = new QPushButton(tr("Remove"), add_remove_grid); 151 remove_button = new QPushButton(tr("Remove keymap"), add_remove_grid);
152 remove_button->setFlat(TRUE); 152 remove_button->setFlat(TRUE);
153 if (keymaps->currentItem() == 0 || default_maps.find(QFileInfo(current_map).fileName()) != default_maps.end()) 153 if (keymaps->currentItem() == 0 || default_maps.find(QFileInfo(current_map).fileName()) != default_maps.end()) {
154 remove_button->setDisabled(true); 154 remove_button->setDisabled(true);
155 remove_button->hide();
156 }
155 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); 157 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap()));
156 158
157 gen_lay->addWidget(map_group); 159 gen_lay->addWidget(map_group);
158 160
159 // make a box that will contain the buttons on the bottom 161 // make a box that will contain the buttons on the bottom
160 QGrid *other_grid = new QGrid(2, gen_box); 162 QGrid *other_grid = new QGrid(2, gen_box);
161 pick_button = new QCheckBox(tr("Pickboard"), other_grid); 163 pick_button = new QCheckBox(tr("Pickboard"), other_grid);
162 164
163 config.setGroup ("general"); 165 config.setGroup ("general");
164 bool pick_open = config.readBoolEntry ("usePickboard", FALSE); // default closed 166 bool pick_open = config.readBoolEntry ("usePickboard", FALSE); // default closed
165 if (pick_open) { 167 if (pick_open) {
166 168
167 pick_button->setChecked(true); 169 pick_button->setChecked(true);
168 } 170 }
169 171
170 repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); 172 repeat_button = new QCheckBox(tr("Key Repeat"), other_grid);
171 bool repeat_on = config.readBoolEntry ("useRepeat", TRUE); 173 bool repeat_on = config.readBoolEntry ("useRepeat", TRUE);
172 174
173 if (repeat_on) { 175 if (repeat_on) {
174 176
175 repeat_button->setChecked(true); 177 repeat_button->setChecked(true);
176 } 178 }
177 179
178 gen_lay->addWidget(other_grid); 180 gen_lay->addWidget(other_grid);
179 tabs->addTab(gen_box, tr("General Settings")); 181 tabs->addTab(gen_box, tr("General Settings"));
180 182
181 /* 183 /*
182 * 'color' tab 184 * 'color' tab
183 */ 185 */
184 186
185 QWidget *color_box = new QWidget(tabs, "color_tab"); 187 QWidget *color_box = new QWidget(tabs, "color_tab");
186 188
187 QGridLayout *color_lay = new QGridLayout(color_box); 189 QGridLayout *color_lay = new QGridLayout(color_box);
188 QGrid *color_grid = new QGrid(2, color_box); 190 QGrid *color_grid = new QGrid(2, color_box);
189 color_lay->setAlignment(Qt::AlignTop); 191 color_lay->setAlignment(Qt::AlignTop);
190 color_grid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); 192 color_grid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
191 color_grid->layout()->setAlignment(Qt::AlignTop); 193 color_grid->layout()->setAlignment(Qt::AlignTop);
192 color_grid->setMargin(3); 194 color_grid->setMargin(3);
193 color_grid->setSpacing(3); 195 color_grid->setSpacing(3);
194 196
195 QLabel *label; 197 QLabel *label;
196 QStringList color; 198 QStringList color;
197 config.setGroup("colors"); 199 config.setGroup("colors");
198 200
199 label = new QLabel(tr("Key Color"), color_grid); 201 label = new QLabel(tr("Key Color"), color_grid);
200 keycolor_button = new QPushButton(color_grid); 202 keycolor_button = new QPushButton(color_grid);
201 connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); 203 connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked()));
202 keycolor_button->setFlat(TRUE); 204 keycolor_button->setFlat(TRUE);
203 color = config.readListEntry("keycolor", QChar(',')); 205 color = config.readListEntry("keycolor", QChar(','));
204 /* 206 /*
205 * hopefully not required 207 * hopefully not required
206 208
207 if (color.isEmpty()) { 209 if (color.isEmpty()) {
208 color = QStringList::split(",", "240,240,240"); 210 color = QStringList::split(",", "240,240,240");
209 config.writeEntry("keycolor", color.join(",")); 211 config.writeEntry("keycolor", color.join(","));
210 212
211 } 213 }
212 */ 214 */
213 keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))); 215 keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())));
214 216
215 217
216 label = new QLabel(tr("Key Pressed Color"), color_grid); 218 label = new QLabel(tr("Key Pressed Color"), color_grid);
217 keycolor_pressed_button = new QPushButton(color_grid); 219 keycolor_pressed_button = new QPushButton(color_grid);
218 connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); 220 connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked()));
219 keycolor_pressed_button->setFlat(TRUE); 221 keycolor_pressed_button->setFlat(TRUE);
220 color = config.readListEntry("keycolor_pressed", QChar(',')); 222 color = config.readListEntry("keycolor_pressed", QChar(','));
221 keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 223 keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
222 224
223 label = new QLabel(tr("Line Color"), color_grid); 225 label = new QLabel(tr("Line Color"), color_grid);
224 keycolor_lines_button = new QPushButton(color_grid); 226 keycolor_lines_button = new QPushButton(color_grid);
225 connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); 227 connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked()));
226 keycolor_lines_button->setFlat(TRUE); 228 keycolor_lines_button->setFlat(TRUE);
227 color = config.readListEntry("keycolor_lines", QChar(',')); 229 color = config.readListEntry("keycolor_lines", QChar(','));
228 keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 230 keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
229 231
230 232
231 label = new QLabel(tr("Text Color"), color_grid); 233 label = new QLabel(tr("Text Color"), color_grid);
232 textcolor_button = new QPushButton(color_grid); 234 textcolor_button = new QPushButton(color_grid);
233 connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); 235 connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked()));
234 textcolor_button->setFlat(TRUE); 236 textcolor_button->setFlat(TRUE);
235 color = config.readListEntry("textcolor", QChar(',')); 237 color = config.readListEntry("textcolor", QChar(','));
236 textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 238 textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
237 239
238 label = new QLabel("", color_grid); // a spacer so the above buttons dont expand 240 label = new QLabel("", color_grid); // a spacer so the above buttons dont expand
239 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 241 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
240 /* FIXME: hacked spacer height */ 242 /* FIXME: hacked spacer height */
241 QSpacerItem *spacer = new QSpacerItem(0, 300, QSizePolicy::Expanding, QSizePolicy::Maximum); 243 QSpacerItem *spacer = new QSpacerItem(0, 300, QSizePolicy::Expanding, QSizePolicy::Maximum);
242 244
243 color_lay->addWidget(color_grid, 0, 0); 245 color_lay->addWidget(color_grid, 0, 0);
244 color_lay->addItem(spacer); 246 color_lay->addItem(spacer);
245 247
246 tabs->addTab(color_box, tr("Colors")); 248 tabs->addTab(color_box, tr("Colors"));
247 base_lay->addWidget(tabs); 249 base_lay->addWidget(tabs);
248} 250}
249 251
250QStringList ConfigDlg::loadSw() 252QStringList ConfigDlg::loadSw()
251{ 253{
252 Config *config = new Config("multikey"); 254 Config *config = new Config("multikey");
253 config->setGroup("keymaps"); 255 config->setGroup("keymaps");
254 QDir map_dir(QPEApplication::qpeDir() + "share/multikey", "*.keymap"); 256 QDir map_dir(QPEApplication::qpeDir() + "share/multikey", "*.keymap");
255 QStringList d_maps = map_dir.entryList(); // so i can access it in other places 257 QStringList d_maps = map_dir.entryList(); // so i can access it in other places
256 QStringList c_maps = config->readListEntry("maps", QChar('|')); 258 QStringList c_maps = config->readListEntry("maps", QChar('|'));
257 QStringList s_maps = config->readListEntry("sw", QChar('|')); 259 QStringList s_maps = config->readListEntry("sw", QChar('|'));
258 delete config; 260 delete config;
259 261
260 if (!s_maps.count()) 262 if (!s_maps.count())
261 { 263 {
262 s_maps = d_maps+c_maps; 264 s_maps = d_maps+c_maps;
263 } 265 }
264 else 266 else
265 { 267 {
266 /* Clear non existents entries */ 268 /* Clear non existents entries */
267 QStringList s_copy(s_maps); 269 QStringList s_copy(s_maps);
268 for (uint i = 0; i < s_copy.count(); ++i) { 270 for (uint i = 0; i < s_copy.count(); ++i) {
269 if (d_maps.find(s_copy[i]) == d_maps.end() 271 if (d_maps.find(s_copy[i]) == d_maps.end()
270 && c_maps.find(s_copy[i]) == c_maps.end()) { 272 && c_maps.find(s_copy[i]) == c_maps.end()) {
271 s_maps.remove(s_copy[i]); 273 s_maps.remove(s_copy[i]);
272 } 274 }
273 } 275 }
274 /* Update sw_maps from default_maps */ 276 /* Update sw_maps from default_maps */
275 for (uint i = 0; i < d_maps.count(); ++i) { 277 for (uint i = 0; i < d_maps.count(); ++i) {
276 if (s_maps.find(d_maps[i]) == s_maps.end()) { 278 if (s_maps.find(d_maps[i]) == s_maps.end()) {
277 s_maps.append(d_maps[i]); 279 s_maps.append(d_maps[i]);
278 } 280 }
279 } 281 }
280 /* Update sw_maps from custom_maps */ 282 /* Update sw_maps from custom_maps */
281 for (uint i = 0; i < c_maps.count(); ++i) { 283 for (uint i = 0; i < c_maps.count(); ++i) {
282 if (s_maps.find(c_maps[i]) == s_maps.end()) { 284 if (s_maps.find(c_maps[i]) == s_maps.end()) {
283 s_maps.append(c_maps[i]); 285 s_maps.append(c_maps[i]);
284 } 286 }
285 } 287 }
286 } 288 }
287 289
288 return s_maps; 290 return s_maps;
289} 291}
290 292
291void ConfigDlg::accept() 293void ConfigDlg::accept()
292{ 294{
293 /* Writing all stuffs to config */ 295 /* Writing all stuffs to config */
294 Config *config = new Config("multikey"); 296 Config *config = new Config("multikey");
295 config->setGroup("general"); 297 config->setGroup("general");
296 config->writeEntry("usePickboard", pick_button->isChecked()); // default closed 298 config->writeEntry("usePickboard", pick_button->isChecked()); // default closed
297 config->writeEntry("useRepeat", repeat_button->isChecked()); // default closed 299 config->writeEntry("useRepeat", repeat_button->isChecked()); // default closed
298 300
299 config->setGroup("keymaps"); 301 config->setGroup("keymaps");
300 config->writeEntry("sw", sw_maps, QChar('|')); 302 config->writeEntry("sw", sw_maps, QChar('|'));
301 config->writeEntry("maps", custom_maps, QChar('|')); 303 config->writeEntry("maps", custom_maps, QChar('|'));
302 delete config; 304 delete config;
303 305
304 int index = keymaps->currentItem(); 306 int index = keymaps->currentItem();
305 if (index == 0) { 307 if (index == 0) {
306 308
307 remove_button->setDisabled(true); 309 remove_button->setDisabled(true);
310 remove_button->hide();
308 emit setMapToDefault(); 311 emit setMapToDefault();
309 } 312 }
310 else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) { 313 else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) {
311 314
312 remove_button->setDisabled(true); 315 remove_button->setDisabled(true);
316 remove_button->hide();
313 emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + sw_maps[index - 1]); 317 emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + sw_maps[index - 1]);
314 318
315 } else { 319 } else {
316 320 remove_button->show();
317 remove_button->setEnabled(true); 321 remove_button->setEnabled(true);
318 emit setMapToFile(sw_maps[index - 1]); 322 emit setMapToFile(sw_maps[index - 1]);
319 } 323 }
320 324
321 emit pickboardToggled(pick_button->isChecked()); 325 emit pickboardToggled(pick_button->isChecked());
322 emit repeatToggled(repeat_button->isChecked()); 326 emit repeatToggled(repeat_button->isChecked());
323 emit reloadSw(); 327 emit reloadSw();
324 328
325 QDialog::accept(); 329 QDialog::accept();
326 emit configDlgClosed(); 330 emit configDlgClosed();
327} 331}
328 332
329void ConfigDlg::moveSelectedUp() 333void ConfigDlg::moveSelectedUp()
330{ 334{
331 int i = keymaps->currentItem(); 335 int i = keymaps->currentItem();
332 /* Ignore Current Language */ 336 /* Ignore Current Language */
333 if (i > 1) { 337 if (i > 1) {
334 QString t = sw_maps[i-1]; 338 QString t = sw_maps[i-1];
335 sw_maps[i-1] = sw_maps[i-2]; 339 sw_maps[i-1] = sw_maps[i-2];
336 sw_maps[i-2] = t; 340 sw_maps[i-2] = t;
337 341
338 QString item = keymaps->currentText(); 342 QString item = keymaps->currentText();
339 keymaps->removeItem(i); 343 keymaps->removeItem(i);
340 keymaps->insertItem(item, i-1); 344 keymaps->insertItem(item, i-1);
341 keymaps->setCurrentItem(i-1); 345 keymaps->setCurrentItem(i-1);
342 } 346 }
343} 347}
344 348
345void ConfigDlg::moveSelectedDown() 349void ConfigDlg::moveSelectedDown()
346{ 350{
347 int i = keymaps->currentItem(); 351 int i = keymaps->currentItem();
348 /* Ignore Current Language */ 352 /* Ignore Current Language */
349 if (i > 0 && i < (int)keymaps->count() - 1) { 353 if (i > 0 && i < (int)keymaps->count() - 1) {
350 QString t = sw_maps[i-1]; 354 QString t = sw_maps[i-1];
351 sw_maps[i-1] = sw_maps[i]; 355 sw_maps[i-1] = sw_maps[i];
352 sw_maps[i] = t; 356 sw_maps[i] = t;
353 357
354 QString item = keymaps->currentText(); 358 QString item = keymaps->currentText();
355 keymaps->removeItem(i); 359 keymaps->removeItem(i);
356 keymaps->insertItem(item, i+1); 360 keymaps->insertItem(item, i+1);
357 keymaps->setCurrentItem(i+1); 361 keymaps->setCurrentItem(i+1);
358 } 362 }
359} 363}
360 364
361void ConfigDlg::closeEvent(QCloseEvent *) { 365void ConfigDlg::closeEvent(QCloseEvent *) {
362 366
363 // tell the parent it was closed, so delete me 367 // tell the parent it was closed, so delete me
364 emit configDlgClosed(); 368 emit configDlgClosed();
365} 369}
366 370
367void ConfigDlg::setMap(int index) { 371void ConfigDlg::setMap(int index) {
368 372
369 if (index == 0 || default_maps.find(sw_maps[index-1]) != default_maps.end()) { 373 if (index == 0 || default_maps.find(sw_maps[index-1]) != default_maps.end()) {
370 remove_button->setDisabled(true); 374 remove_button->setDisabled(true);
375 remove_button->hide();
371 } else { 376 } else {
377 remove_button->show();
372 remove_button->setEnabled(true); 378 remove_button->setEnabled(true);
373 } 379 }
374} 380}
375 381
376// ConfigDlg::addMap() {{{1 382// ConfigDlg::addMap() {{{1
377void ConfigDlg::addMap() { 383void ConfigDlg::addMap() {
378 384
379 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); 385 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath());
380 386
381 if (map.isNull()) return; 387 if (map.isNull()) return;
382 388
383 Config config ("multikey"); 389 Config config ("multikey");
384 config.setGroup("keymaps"); 390 config.setGroup("keymaps");
385 QStringList maps = config.readListEntry("maps", QChar('|')); 391 QStringList maps = config.readListEntry("maps", QChar('|'));
386 maps.append(map); 392 maps.append(map);
387 custom_maps.append(map); 393 custom_maps.append(map);
388 if (sw_maps.find(map) == sw_maps.end()) 394 if (sw_maps.find(map) == sw_maps.end())
389 sw_maps.append(map); 395 sw_maps.append(map);
390 396
391 QFile map_file (map); 397 QFile map_file (map);
392 if (map_file.open(IO_ReadOnly)) { 398 if (map_file.open(IO_ReadOnly)) {
393 399
394 QString line; bool found = 0; 400 QString line; bool found = 0;
395 401
396 map_file.readLine(line, 1024); 402 map_file.readLine(line, 1024);
397 while (!map_file.atEnd()) { 403 while (!map_file.atEnd()) {
398 404
399 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { 405 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
400 406
401 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 407 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
402 found = 1; 408 found = 1;
403 break; 409 break;
404 } 410 }
405 map_file.readLine(line, 1024); 411 map_file.readLine(line, 1024);
406 } 412 }
407 if (!found) keymaps->insertItem(map); 413 if (!found) keymaps->insertItem(map);
408 414
409 map_file.close(); 415 map_file.close();
410 } 416 }
411 417
412 keymaps->setSelected(keymaps->count() - 1, true); 418 keymaps->setSelected(keymaps->count() - 1, true);
413} 419}
414 420
415// ConfigDlg::removeMap() {{{1 421// ConfigDlg::removeMap() {{{1
416void ConfigDlg::removeMap() { 422void ConfigDlg::removeMap() {
417 423
418 // move selection up one 424 // move selection up one
419 keymaps->setSelected(keymaps->currentItem() - 1, true); 425 keymaps->setSelected(keymaps->currentItem() - 1, true);
420 // delete the next selected item cus you just moved it up 426 // delete the next selected item cus you just moved it up
421 keymaps->removeItem(keymaps->currentItem() + 1); 427 keymaps->removeItem(keymaps->currentItem() + 1);
422 428
423 custom_maps.remove(sw_maps[keymaps->currentItem()]); 429 custom_maps.remove(sw_maps[keymaps->currentItem()]);
424 sw_maps.remove(sw_maps.at(keymaps->currentItem())); 430 sw_maps.remove(sw_maps.at(keymaps->currentItem()));
425} 431}
426 432
427/* ConfigDlg::slots for the color buttons {{{1 433/* ConfigDlg::slots for the color buttons {{{1
428 * 434 *
429 * these four slots are almost the same, except for the names. i was thinking 435 * these four slots are almost the same, except for the names. i was thinking
430 * of making a map with pointers to the buttons and names of the configEntry 436 * of making a map with pointers to the buttons and names of the configEntry
431 * so it could be one slot, but then there would be no way of telling which 437 * so it could be one slot, but then there would be no way of telling which
432 * of the buttons was clicked if they all connect to the same slot. 438 * of the buttons was clicked if they all connect to the same slot.
433 * 439 *
434 */ 440 */
435 441
436void ConfigDlg::keyColorClicked() { 442void ConfigDlg::keyColorClicked() {
437 443
438 Config config ("multikey"); 444 Config config ("multikey");
439 config.setGroup ("colors"); 445 config.setGroup ("colors");
440 446
441 QStringList color = config.readListEntry("keycolor", QChar(',')); 447 QStringList color = config.readListEntry("keycolor", QChar(','));
442 448
443 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 449 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
444 450
445 color[0].setNum(newcolor.red()); 451 color[0].setNum(newcolor.red());
446 color[1].setNum(newcolor.green()); 452 color[1].setNum(newcolor.green());
447 color[2].setNum(newcolor.blue()); 453 color[2].setNum(newcolor.blue());
448 454
449 config.writeEntry("keycolor", color, QChar(',')); 455 config.writeEntry("keycolor", color, QChar(','));
450 config.write(); 456 config.write();
451 457
452 keycolor_button->setPalette(QPalette(newcolor)); 458 keycolor_button->setPalette(QPalette(newcolor));
453 emit reloadKeyboard(); 459 emit reloadKeyboard();
454} 460}
455void ConfigDlg::keyColorPressedClicked() { 461void ConfigDlg::keyColorPressedClicked() {
456 462
457 Config config ("multikey"); 463 Config config ("multikey");
458 config.setGroup ("colors"); 464 config.setGroup ("colors");
459 465
460 QStringList color = config.readListEntry("keycolor_pressed", QChar(',')); 466 QStringList color = config.readListEntry("keycolor_pressed", QChar(','));
461 467
462 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 468 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
463 469
464 color[0].setNum(newcolor.red()); 470 color[0].setNum(newcolor.red());
465 color[1].setNum(newcolor.green()); 471 color[1].setNum(newcolor.green());
466 color[2].setNum(newcolor.blue()); 472 color[2].setNum(newcolor.blue());
467 473
468 config.writeEntry("keycolor_pressed", color, QChar(',')); 474 config.writeEntry("keycolor_pressed", color, QChar(','));
469 config.write(); 475 config.write();
470 476
471 keycolor_pressed_button->setPalette(QPalette(newcolor)); 477 keycolor_pressed_button->setPalette(QPalette(newcolor));
472 emit reloadKeyboard(); 478 emit reloadKeyboard();
473} 479}
474void ConfigDlg::keyColorLinesClicked() { 480void ConfigDlg::keyColorLinesClicked() {
475 481
476 Config config ("multikey"); 482 Config config ("multikey");
477 config.setGroup ("colors"); 483 config.setGroup ("colors");
478 484
479 QStringList color = config.readListEntry("keycolor_lines", QChar(',')); 485 QStringList color = config.readListEntry("keycolor_lines", QChar(','));
480 486
481 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 487 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
482 488
483 color[0].setNum(newcolor.red()); 489 color[0].setNum(newcolor.red());
484 color[1].setNum(newcolor.green()); 490 color[1].setNum(newcolor.green());
485 color[2].setNum(newcolor.blue()); 491 color[2].setNum(newcolor.blue());
486 492
487 config.writeEntry("keycolor_lines", color, QChar(',')); 493 config.writeEntry("keycolor_lines", color, QChar(','));
488 config.write(); 494 config.write();
489 495
490 keycolor_lines_button->setPalette(QPalette(newcolor)); 496 keycolor_lines_button->setPalette(QPalette(newcolor));
491 emit reloadKeyboard(); 497 emit reloadKeyboard();
492} 498}
493void ConfigDlg::textColorClicked() { 499void ConfigDlg::textColorClicked() {
494 500
495 Config config ("multikey"); 501 Config config ("multikey");
496 config.setGroup ("colors"); 502 config.setGroup ("colors");
497 503
498 QStringList color = config.readListEntry("textcolor", QChar(',')); 504 QStringList color = config.readListEntry("textcolor", QChar(','));
499 505
500 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 506 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
501 507
502 color[0].setNum(newcolor.red()); 508 color[0].setNum(newcolor.red());
503 color[1].setNum(newcolor.green()); 509 color[1].setNum(newcolor.green());
504 color[2].setNum(newcolor.blue()); 510 color[2].setNum(newcolor.blue());
505 511
506 config.writeEntry("textcolor", color, QChar(',')); 512 config.writeEntry("textcolor", color, QChar(','));
507 config.write(); 513 config.write();
508 514
509 textcolor_button->setPalette(QPalette(newcolor)); 515 textcolor_button->setPalette(QPalette(newcolor));
510 emit reloadKeyboard(); 516 emit reloadKeyboard();
511} 517}
diff --git a/inputmethods/multikey/configdlg.h b/inputmethods/multikey/configdlg.h
index 8e96e9b..f900a14 100644
--- a/inputmethods/multikey/configdlg.h
+++ b/inputmethods/multikey/configdlg.h
@@ -1,65 +1,65 @@
1#include <qpe/qpeapplication.h> 1#include <qpe/qpeapplication.h>
2#include <qdialog.h> 2#include <qdialog.h>
3#include <qcheckbox.h> 3#include <qcheckbox.h>
4#include <qlistbox.h> 4#include <qlistbox.h>
5#include <qpushbutton.h> 5#include <qpushbutton.h>
6 6
7#ifndef CONFIGDLG_H 7#ifndef CONFIGDLG_H
8#define CONFIGDLG_H 8#define CONFIGDLG_H
9 9
10class ConfigDlg : public QDialog 10class ConfigDlg : public QDialog
11{ 11{
12 Q_OBJECT 12 Q_OBJECT
13 13
14public: 14public:
15 ConfigDlg (); 15 ConfigDlg ();
16 static QStringList loadSw(); 16 static QStringList loadSw();
17 17
18signals: 18signals:
19 void pickboardToggled(bool on_off); 19 void pickboardToggled(bool on_off);
20 void repeatToggled(bool on_off); 20 void repeatToggled(bool on_off);
21 void setMapToDefault(); 21 void setMapToDefault();
22 void setMapToFile(QString map); 22 void setMapToFile(QString map);
23 void reloadKeyboard(); 23 void reloadKeyboard();
24 void configDlgClosed(); 24 void configDlgClosed();
25 void reloadSw(); 25 void reloadSw();
26 26
27protected: 27protected:
28 virtual void accept(); 28 virtual void accept();
29 29
30protected slots: 30protected slots:
31 void moveSelectedUp(); 31 void moveSelectedUp();
32 void moveSelectedDown(); 32 void moveSelectedDown();
33 33
34private slots: 34private slots:
35 void setMap(int index); 35 void setMap(int index);
36 void addMap(); 36 void addMap();
37 void removeMap(); 37 void removeMap();
38 virtual void closeEvent ( QCloseEvent * ); 38 virtual void closeEvent ( QCloseEvent * );
39 39
40 // all those required slots for the color push buttons 40 // all those required slots for the color push buttons
41 void keyColorClicked(); 41 void keyColorClicked();
42 void keyColorPressedClicked(); 42 void keyColorPressedClicked();
43 void keyColorLinesClicked(); 43 void keyColorLinesClicked();
44 void textColorClicked(); 44 void textColorClicked();
45 45
46private: 46private:
47 QCheckBox *pick_button; 47 QCheckBox *pick_button;
48 QCheckBox *repeat_button; 48 QCheckBox *repeat_button;
49 QListBox *keymaps; 49 QListBox *keymaps;
50 QPushButton *add_button; 50 QPushButton *add_button;
51 QPushButton *remove_button; 51 QPushButton *remove_button;
52 52
53 QStringList default_maps; // the maps in your share/multikey/ dir 53 QStringList default_maps; // the maps in your share/multikey/ dir
54 QStringList custom_maps; // maps you added with the 'add' button 54 QStringList custom_maps; // maps you added with the 'add' button
55 QStringList sw_maps; // maps, which used in keyboard switch rotation ring 55 QStringList sw_maps; // maps used in keyboard switch rotation ring
56 56
57 /* color buttons */ 57 /* color buttons */
58 QPushButton *keycolor_button; 58 QPushButton *keycolor_button;
59 QPushButton *keycolor_pressed_button; 59 QPushButton *keycolor_pressed_button;
60 QPushButton *keycolor_lines_button; 60 QPushButton *keycolor_lines_button;
61 QPushButton *textcolor_button; 61 QPushButton *textcolor_button;
62 62
63}; 63};
64 64
65#endif 65#endif