author | hash <hash> | 2002-08-19 05:35:38 (UTC) |
---|---|---|
committer | hash <hash> | 2002-08-19 05:35:38 (UTC) |
commit | 64a00421be85d223072e087d4d3c9ecdad464095 (patch) (unidiff) | |
tree | 66cf285aa1a8d17126c5b59125c7d91fc2c08c45 /inputmethods/multikey/configdlg.cpp | |
parent | d92fbca743e676182a8f33ae4c28044031143fb0 (diff) | |
download | opie-64a00421be85d223072e087d4d3c9ecdad464095.zip opie-64a00421be85d223072e087d4d3c9ecdad464095.tar.gz opie-64a00421be85d223072e087d4d3c9ecdad464095.tar.bz2 |
now reads maps in default dir, and also lets you add/remove your own maps
Diffstat (limited to 'inputmethods/multikey/configdlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/multikey/configdlg.cpp | 93 |
1 files changed, 75 insertions, 18 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 | |||
@@ -1,89 +1,123 @@ | |||
1 | /* | 1 | /* |
2 | * TODO | 2 | * TODO |
3 | * make a font selection thing (size too) | 3 | * make a font selection thing (size too) |
4 | * | 4 | * |
5 | * | 5 | * |
6 | * | 6 | * |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <iostream.h> | ||
10 | |||
9 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
10 | #include <qpe/config.h> | 12 | #include <qpe/config.h> |
11 | 13 | ||
12 | #include <qwidget.h> | 14 | #include <qwidget.h> |
13 | #include <qdialog.h> | 15 | #include <qdialog.h> |
14 | #include <qtabwidget.h> | 16 | #include <qtabwidget.h> |
15 | #include <qvbox.h> | 17 | #include <qvbox.h> |
16 | #include <qgrid.h> | 18 | #include <qgrid.h> |
17 | #include <qgroupbox.h> | 19 | #include <qgroupbox.h> |
18 | #include <qlabel.h> | 20 | #include <qlabel.h> |
19 | #include <qcheckbox.h> | 21 | #include <qcheckbox.h> |
20 | #include <qsizepolicy.h> | 22 | #include <qsizepolicy.h> |
21 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
22 | #include <qlistbox.h> | 24 | #include <qlistbox.h> |
23 | #include <qstringlist.h> | 25 | #include <qstringlist.h> |
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" |
27 | #include "keyboard.h" | 30 | #include "keyboard.h" |
28 | 31 | ||
29 | ConfigDlg::ConfigDlg () : QTabWidget () | 32 | ConfigDlg::ConfigDlg () : QTabWidget () |
30 | { | 33 | { |
31 | setCaption( tr("Multikey Configuration") ); | 34 | setCaption( tr("Multikey Configuration") ); |
32 | Config config ("multikey"); | 35 | Config config ("multikey"); |
36 | config.setGroup("keymaps"); | ||
37 | QString current_map = config.readEntry("current", 0); | ||
33 | 38 | ||
34 | /* | 39 | /* |
35 | * 'general config' tab | 40 | * 'general config' tab |
36 | */ | 41 | */ |
37 | 42 | ||
38 | QVBox *gen_box = new QVBox (this); | 43 | QVBox *gen_box = new QVBox (this); |
39 | gen_box->setMargin(3); | 44 | gen_box->setMargin(3); |
40 | addTab(gen_box, tr("General Settings")); | 45 | addTab(gen_box, tr("General Settings")); |
41 | 46 | ||
42 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); | 47 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); |
43 | 48 | ||
44 | keymaps = new QListBox (map_group); | 49 | keymaps = new QListBox (map_group); |
45 | keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 50 | keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
46 | 51 | ||
47 | QString cur(tr("Current Language")); | 52 | QString cur(tr("Current Language")); |
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 | } |
57 | 91 | ||
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 | ||
61 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); | 94 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); |
62 | 95 | ||
63 | 96 | ||
64 | QGrid *add_remove_grid = new QGrid(2, map_group); | 97 | QGrid *add_remove_grid = new QGrid(2, map_group); |
65 | add_remove_grid->setMargin(3); | 98 | add_remove_grid->setMargin(3); |
66 | add_remove_grid->setSpacing(3); | 99 | add_remove_grid->setSpacing(3); |
67 | 100 | ||
68 | add_button = new QPushButton(tr("Add"), add_remove_grid); | 101 | add_button = new QPushButton(tr("Add"), add_remove_grid); |
69 | add_button->setFlat((bool)1); | 102 | add_button->setFlat((bool)1); |
70 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); | 103 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); |
71 | 104 | ||
72 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); | 105 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); |
73 | remove_button->setFlat((bool)1); | 106 | remove_button->setFlat((bool)1); |
107 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); | ||
74 | 108 | ||
75 | pick_button = new QCheckBox(tr("Pickboard"), gen_box); | 109 | pick_button = new QCheckBox(tr("Pickboard"), gen_box); |
76 | 110 | ||
77 | config.setGroup ("pickboard"); | 111 | config.setGroup ("pickboard"); |
78 | bool pick_open = config.readBoolEntry ("open", "0"); // default closed | 112 | bool pick_open = config.readBoolEntry ("open", "0"); // default closed |
79 | if (pick_open) { | 113 | if (pick_open) { |
80 | 114 | ||
81 | pick_button->setChecked(true); | 115 | pick_button->setChecked(true); |
82 | } | 116 | } |
83 | 117 | ||
84 | // by connecting it after checking it, the signal isn't emmited | 118 | // by connecting it after checking it, the signal isn't emmited |
85 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); | 119 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); |
86 | 120 | ||
87 | /* | 121 | /* |
88 | * 'color' tab | 122 | * 'color' tab |
89 | */ | 123 | */ |
@@ -113,50 +147,73 @@ ConfigDlg::ConfigDlg () : QTabWidget () | |||
113 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 147 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
114 | 148 | ||
115 | } | 149 | } |
116 | 150 | ||
117 | void ConfigDlg::pickTog() { | 151 | void ConfigDlg::pickTog() { |
118 | 152 | ||
119 | Config config ("multikey"); | 153 | Config config ("multikey"); |
120 | config.setGroup ("pickboard"); | 154 | config.setGroup ("pickboard"); |
121 | config.writeEntry ("open", pick_button->isChecked()); // default closed | 155 | config.writeEntry ("open", pick_button->isChecked()); // default closed |
122 | 156 | ||
123 | emit pickboardToggled(pick_button->isChecked()); | 157 | emit pickboardToggled(pick_button->isChecked()); |
124 | } | 158 | } |
125 | 159 | ||
126 | /* | 160 | /* |
127 | * the index is kinda screwy, because in the config file, index 0 is just the | 161 | * the index is kinda screwy, because in the config file, index 0 is just the |
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 | */ |
134 | 166 | ||
135 | void ConfigDlg::setMap(int index) { | 167 | void ConfigDlg::setMap(int index) { |
136 | 168 | ||
137 | if (index == 0) { | 169 | if (index == 0) { |
138 | 170 | ||
139 | if (remove_button->isEnabled()) | 171 | remove_button->setDisabled(true); |
140 | remove_button->setDisabled(true); | ||
141 | 172 | ||
142 | emit setMapToDefault(); | 173 | emit setMapToDefault(); |
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 | } |
151 | } | 185 | } |
152 | 186 | ||
153 | void ConfigDlg::addMap() { | 187 | 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 | ||
158 | } | 201 | } |
159 | 202 | ||
160 | void ConfigDlg::removeMap(int index) { | 203 | void 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 | } |