Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> | |
3 | * Released under the terms of the GNU GPL v2.0. | |
4 | */ | |
5 | ||
133c5f7c AS |
6 | #include <qglobal.h> |
7 | ||
b1f8a45b | 8 | #include <QMainWindow> |
041fbdc2 | 9 | #include <QList> |
924bbb53 | 10 | #include <qtextbrowser.h> |
85eaf28a | 11 | #include <QAction> |
bea00771 | 12 | #include <QFileDialog> |
76bede87 | 13 | #include <QMenu> |
133c5f7c AS |
14 | |
15 | #include <qapplication.h> | |
8d90c97e | 16 | #include <qdesktopwidget.h> |
1da177e4 | 17 | #include <qtoolbar.h> |
43bf612a | 18 | #include <qlayout.h> |
1da177e4 | 19 | #include <qsplitter.h> |
1da177e4 | 20 | #include <qlineedit.h> |
43bf612a RZ |
21 | #include <qlabel.h> |
22 | #include <qpushbutton.h> | |
1da177e4 LT |
23 | #include <qmenubar.h> |
24 | #include <qmessagebox.h> | |
1da177e4 | 25 | #include <qregexp.h> |
133c5f7c | 26 | #include <qevent.h> |
1da177e4 LT |
27 | |
28 | #include <stdlib.h> | |
29 | ||
30 | #include "lkc.h" | |
31 | #include "qconf.h" | |
32 | ||
33 | #include "qconf.moc" | |
34 | #include "images.c" | |
35 | ||
3b9fa093 ACM |
36 | #ifdef _ |
37 | # undef _ | |
38 | # define _ qgettext | |
39 | #endif | |
40 | ||
1da177e4 | 41 | static QApplication *configApp; |
7fc925fd | 42 | static ConfigSettings *configSettings; |
1da177e4 | 43 | |
85eaf28a | 44 | QAction *ConfigMainWindow::saveAction; |
3b354c55 | 45 | |
3b9fa093 ACM |
46 | static inline QString qgettext(const char* str) |
47 | { | |
43bf612a | 48 | return QString::fromLocal8Bit(gettext(str)); |
3b9fa093 ACM |
49 | } |
50 | ||
51 | static inline QString qgettext(const QString& str) | |
52 | { | |
68ccb7ef | 53 | return QString::fromLocal8Bit(gettext(str.toLatin1())); |
3b9fa093 ACM |
54 | } |
55 | ||
00d4f8fc BH |
56 | ConfigSettings::ConfigSettings() |
57 | : QSettings("kernel.org", "qconf") | |
58 | { | |
59 | } | |
60 | ||
1da177e4 LT |
61 | /** |
62 | * Reads a list of integer values from the application settings. | |
63 | */ | |
041fbdc2 | 64 | QList<int> ConfigSettings::readSizes(const QString& key, bool *ok) |
1da177e4 | 65 | { |
041fbdc2 | 66 | QList<int> result; |
68ccb7ef | 67 | QStringList entryList = value(key).toStringList(); |
c1f96f09 LZ |
68 | QStringList::Iterator it; |
69 | ||
70 | for (it = entryList.begin(); it != entryList.end(); ++it) | |
71 | result.push_back((*it).toInt()); | |
1da177e4 LT |
72 | |
73 | return result; | |
74 | } | |
75 | ||
76 | /** | |
77 | * Writes a list of integer values to the application settings. | |
78 | */ | |
041fbdc2 | 79 | bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value) |
1da177e4 LT |
80 | { |
81 | QStringList stringList; | |
041fbdc2 | 82 | QList<int>::ConstIterator it; |
1da177e4 LT |
83 | |
84 | for (it = value.begin(); it != value.end(); ++it) | |
85 | stringList.push_back(QString::number(*it)); | |
68ccb7ef BB |
86 | setValue(key, stringList); |
87 | return true; | |
1da177e4 | 88 | } |
1da177e4 | 89 | |
1019f1a5 BB |
90 | /* |
91 | * construct a menu entry | |
92 | */ | |
93 | void ConfigItem::init(void) | |
94 | { | |
95 | } | |
96 | ||
97 | /* | |
98 | * destruct a menu entry | |
99 | */ | |
100 | ConfigItem::~ConfigItem(void) | |
101 | { | |
102 | } | |
103 | ||
43bf612a RZ |
104 | ConfigLineEdit::ConfigLineEdit(ConfigView* parent) |
105 | : Parent(parent) | |
106 | { | |
92119937 | 107 | connect(this, SIGNAL(editingFinished()), SLOT(hide())); |
43bf612a RZ |
108 | } |
109 | ||
1019f1a5 | 110 | void ConfigLineEdit::show(ConfigItem* i) |
1da177e4 LT |
111 | { |
112 | item = i; | |
1da177e4 LT |
113 | Parent::show(); |
114 | setFocus(); | |
115 | } | |
116 | ||
117 | void ConfigLineEdit::keyPressEvent(QKeyEvent* e) | |
118 | { | |
119 | switch (e->key()) { | |
fbb86374 | 120 | case Qt::Key_Escape: |
1da177e4 | 121 | break; |
fbb86374 MH |
122 | case Qt::Key_Return: |
123 | case Qt::Key_Enter: | |
1da177e4 LT |
124 | parent()->updateList(item); |
125 | break; | |
126 | default: | |
127 | Parent::keyPressEvent(e); | |
128 | return; | |
129 | } | |
130 | e->accept(); | |
131 | parent()->list->setFocus(); | |
132 | hide(); | |
133 | } | |
134 | ||
1019f1a5 BB |
135 | ConfigList::ConfigList(ConfigView* p, const char *name) |
136 | : Parent(p) | |
137 | { | |
138 | } | |
39a4897c LZ |
139 | ConfigView*ConfigView::viewList; |
140 | QAction *ConfigView::showNormalAction; | |
141 | QAction *ConfigView::showAllAction; | |
142 | QAction *ConfigView::showPromptAction; | |
1da177e4 | 143 | |
7fc925fd | 144 | ConfigView::ConfigView(QWidget* parent, const char *name) |
68ccb7ef | 145 | : Parent(parent) |
1da177e4 | 146 | { |
29a70168 | 147 | QVBoxLayout *verticalLayout = new QVBoxLayout(this); |
92298b49 | 148 | verticalLayout->setContentsMargins(0, 0, 0, 0); |
29a70168 | 149 | |
1019f1a5 | 150 | list = new ConfigList(this); |
29a70168 | 151 | verticalLayout->addWidget(list); |
1da177e4 LT |
152 | lineEdit = new ConfigLineEdit(this); |
153 | lineEdit->hide(); | |
29a70168 | 154 | verticalLayout->addWidget(lineEdit); |
1da177e4 LT |
155 | |
156 | this->nextView = viewList; | |
157 | viewList = this; | |
158 | } | |
159 | ||
160 | ConfigView::~ConfigView(void) | |
161 | { | |
162 | ConfigView** vp; | |
163 | ||
164 | for (vp = &viewList; *vp; vp = &(*vp)->nextView) { | |
165 | if (*vp == this) { | |
166 | *vp = nextView; | |
167 | break; | |
168 | } | |
169 | } | |
170 | } | |
171 | ||
39a4897c | 172 | void ConfigView::setOptionMode(QAction *act) |
7fc925fd | 173 | { |
7fc925fd RZ |
174 | } |
175 | ||
176 | void ConfigView::setShowName(bool b) | |
177 | { | |
7fc925fd RZ |
178 | } |
179 | ||
180 | void ConfigView::setShowRange(bool b) | |
181 | { | |
7fc925fd RZ |
182 | } |
183 | ||
184 | void ConfigView::setShowData(bool b) | |
185 | { | |
7fc925fd RZ |
186 | } |
187 | ||
1019f1a5 | 188 | void ConfigView::updateList(ConfigItem* item) |
1da177e4 | 189 | { |
1da177e4 LT |
190 | } |
191 | ||
192 | void ConfigView::updateListAll(void) | |
193 | { | |
1da177e4 LT |
194 | } |
195 | ||
43bf612a | 196 | ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name) |
68ccb7ef | 197 | : Parent(parent), sym(0), _menu(0) |
43bf612a | 198 | { |
7fc925fd RZ |
199 | if (name) { |
200 | configSettings->beginGroup(name); | |
68ccb7ef | 201 | _showDebug = configSettings->value("/showDebug", false).toBool(); |
7fc925fd RZ |
202 | configSettings->endGroup(); |
203 | connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); | |
204 | } | |
205 | } | |
206 | ||
207 | void ConfigInfoView::saveSettings(void) | |
208 | { | |
68ccb7ef | 209 | /*if (name()) { |
7fc925fd | 210 | configSettings->beginGroup(name()); |
68ccb7ef | 211 | configSettings->setValue("/showDebug", showDebug()); |
7fc925fd | 212 | configSettings->endGroup(); |
68ccb7ef | 213 | }*/ |
43bf612a RZ |
214 | } |
215 | ||
216 | void ConfigInfoView::setShowDebug(bool b) | |
217 | { | |
218 | if (_showDebug != b) { | |
219 | _showDebug = b; | |
133c5f7c | 220 | if (_menu) |
43bf612a | 221 | menuInfo(); |
ab45d190 RZ |
222 | else if (sym) |
223 | symbolInfo(); | |
43bf612a RZ |
224 | emit showDebugChanged(b); |
225 | } | |
226 | } | |
227 | ||
228 | void ConfigInfoView::setInfo(struct menu *m) | |
229 | { | |
133c5f7c | 230 | if (_menu == m) |
b65a47e1 | 231 | return; |
133c5f7c | 232 | _menu = m; |
6fa1da8e | 233 | sym = NULL; |
133c5f7c | 234 | if (!_menu) |
43bf612a | 235 | clear(); |
6fa1da8e | 236 | else |
43bf612a RZ |
237 | menuInfo(); |
238 | } | |
239 | ||
ab45d190 RZ |
240 | void ConfigInfoView::symbolInfo(void) |
241 | { | |
242 | QString str; | |
243 | ||
244 | str += "<big>Symbol: <b>"; | |
245 | str += print_filter(sym->name); | |
246 | str += "</b></big><br><br>value: "; | |
247 | str += print_filter(sym_get_string_value(sym)); | |
248 | str += "<br>visibility: "; | |
249 | str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n"; | |
250 | str += "<br>"; | |
251 | str += debug_info(sym); | |
252 | ||
253 | setText(str); | |
254 | } | |
255 | ||
43bf612a RZ |
256 | void ConfigInfoView::menuInfo(void) |
257 | { | |
258 | struct symbol* sym; | |
259 | QString head, debug, help; | |
260 | ||
133c5f7c | 261 | sym = _menu->sym; |
43bf612a | 262 | if (sym) { |
133c5f7c | 263 | if (_menu->prompt) { |
43bf612a | 264 | head += "<big><b>"; |
133c5f7c | 265 | head += print_filter(_(_menu->prompt->text)); |
43bf612a RZ |
266 | head += "</b></big>"; |
267 | if (sym->name) { | |
268 | head += " ("; | |
ab45d190 RZ |
269 | if (showDebug()) |
270 | head += QString().sprintf("<a href=\"s%p\">", sym); | |
43bf612a | 271 | head += print_filter(sym->name); |
ab45d190 RZ |
272 | if (showDebug()) |
273 | head += "</a>"; | |
43bf612a RZ |
274 | head += ")"; |
275 | } | |
276 | } else if (sym->name) { | |
277 | head += "<big><b>"; | |
ab45d190 RZ |
278 | if (showDebug()) |
279 | head += QString().sprintf("<a href=\"s%p\">", sym); | |
43bf612a | 280 | head += print_filter(sym->name); |
ab45d190 RZ |
281 | if (showDebug()) |
282 | head += "</a>"; | |
43bf612a RZ |
283 | head += "</b></big>"; |
284 | } | |
285 | head += "<br><br>"; | |
286 | ||
287 | if (showDebug()) | |
288 | debug = debug_info(sym); | |
289 | ||
d74c15f3 | 290 | struct gstr help_gstr = str_new(); |
133c5f7c | 291 | menu_get_ext_help(_menu, &help_gstr); |
d74c15f3 CR |
292 | help = print_filter(str_get(&help_gstr)); |
293 | str_free(&help_gstr); | |
133c5f7c | 294 | } else if (_menu->prompt) { |
43bf612a | 295 | head += "<big><b>"; |
133c5f7c | 296 | head += print_filter(_(_menu->prompt->text)); |
43bf612a RZ |
297 | head += "</b></big><br><br>"; |
298 | if (showDebug()) { | |
133c5f7c | 299 | if (_menu->prompt->visible.expr) { |
43bf612a | 300 | debug += " dep: "; |
133c5f7c | 301 | expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE); |
43bf612a RZ |
302 | debug += "<br><br>"; |
303 | } | |
304 | } | |
305 | } | |
306 | if (showDebug()) | |
133c5f7c | 307 | debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno); |
43bf612a RZ |
308 | |
309 | setText(head + debug + help); | |
310 | } | |
311 | ||
312 | QString ConfigInfoView::debug_info(struct symbol *sym) | |
313 | { | |
314 | QString debug; | |
315 | ||
316 | debug += "type: "; | |
317 | debug += print_filter(sym_type_name(sym->type)); | |
318 | if (sym_is_choice(sym)) | |
319 | debug += " (choice)"; | |
320 | debug += "<br>"; | |
321 | if (sym->rev_dep.expr) { | |
322 | debug += "reverse dep: "; | |
323 | expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE); | |
324 | debug += "<br>"; | |
325 | } | |
326 | for (struct property *prop = sym->prop; prop; prop = prop->next) { | |
327 | switch (prop->type) { | |
328 | case P_PROMPT: | |
329 | case P_MENU: | |
ab45d190 | 330 | debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu); |
43bf612a | 331 | debug += print_filter(_(prop->text)); |
ab45d190 | 332 | debug += "</a><br>"; |
43bf612a RZ |
333 | break; |
334 | case P_DEFAULT: | |
93449082 RZ |
335 | case P_SELECT: |
336 | case P_RANGE: | |
337 | case P_ENV: | |
338 | debug += prop_get_type_name(prop->type); | |
339 | debug += ": "; | |
43bf612a RZ |
340 | expr_print(prop->expr, expr_print_help, &debug, E_NONE); |
341 | debug += "<br>"; | |
342 | break; | |
343 | case P_CHOICE: | |
344 | if (sym_is_choice(sym)) { | |
345 | debug += "choice: "; | |
346 | expr_print(prop->expr, expr_print_help, &debug, E_NONE); | |
347 | debug += "<br>"; | |
348 | } | |
349 | break; | |
43bf612a RZ |
350 | default: |
351 | debug += "unknown property: "; | |
352 | debug += prop_get_type_name(prop->type); | |
353 | debug += "<br>"; | |
354 | } | |
355 | if (prop->visible.expr) { | |
356 | debug += " dep: "; | |
357 | expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE); | |
358 | debug += "<br>"; | |
359 | } | |
360 | } | |
361 | debug += "<br>"; | |
362 | ||
363 | return debug; | |
364 | } | |
365 | ||
366 | QString ConfigInfoView::print_filter(const QString &str) | |
367 | { | |
368 | QRegExp re("[<>&\"\\n]"); | |
369 | QString res = str; | |
68ccb7ef BB |
370 | for (int i = 0; (i = res.indexOf(re, i)) >= 0;) { |
371 | switch (res[i].toLatin1()) { | |
43bf612a RZ |
372 | case '<': |
373 | res.replace(i, 1, "<"); | |
374 | i += 4; | |
375 | break; | |
376 | case '>': | |
377 | res.replace(i, 1, ">"); | |
378 | i += 4; | |
379 | break; | |
380 | case '&': | |
381 | res.replace(i, 1, "&"); | |
382 | i += 5; | |
383 | break; | |
384 | case '"': | |
385 | res.replace(i, 1, """); | |
386 | i += 6; | |
387 | break; | |
388 | case '\n': | |
389 | res.replace(i, 1, "<br>"); | |
390 | i += 4; | |
391 | break; | |
392 | } | |
393 | } | |
394 | return res; | |
395 | } | |
396 | ||
ab45d190 | 397 | void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str) |
43bf612a | 398 | { |
ab45d190 RZ |
399 | QString* text = reinterpret_cast<QString*>(data); |
400 | QString str2 = print_filter(str); | |
401 | ||
402 | if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) { | |
403 | *text += QString().sprintf("<a href=\"s%p\">", sym); | |
404 | *text += str2; | |
405 | *text += "</a>"; | |
406 | } else | |
407 | *text += str2; | |
43bf612a RZ |
408 | } |
409 | ||
924bbb53 | 410 | QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos) |
7fc925fd | 411 | { |
924bbb53 | 412 | QMenu* popup = Parent::createStandardContextMenu(pos); |
85eaf28a | 413 | QAction* action = new QAction(_("Show Debug Info"), popup); |
68ccb7ef | 414 | action->setCheckable(true); |
7fc925fd RZ |
415 | connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool))); |
416 | connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool))); | |
9c86235a | 417 | action->setChecked(showDebug()); |
924bbb53 | 418 | popup->addSeparator(); |
68ccb7ef | 419 | popup->addAction(action); |
7fc925fd RZ |
420 | return popup; |
421 | } | |
422 | ||
924bbb53 | 423 | void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e) |
7fc925fd | 424 | { |
924bbb53 | 425 | Parent::contextMenuEvent(e); |
7fc925fd RZ |
426 | } |
427 | ||
63431e75 | 428 | ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name) |
68ccb7ef | 429 | : Parent(parent), result(NULL) |
43bf612a | 430 | { |
68ccb7ef | 431 | setWindowTitle("Search Config"); |
43bf612a | 432 | |
68ccb7ef BB |
433 | QVBoxLayout* layout1 = new QVBoxLayout(this); |
434 | layout1->setContentsMargins(11, 11, 11, 11); | |
435 | layout1->setSpacing(6); | |
436 | QHBoxLayout* layout2 = new QHBoxLayout(0); | |
437 | layout2->setContentsMargins(0, 0, 0, 0); | |
438 | layout2->setSpacing(6); | |
c21a2d95 | 439 | layout2->addWidget(new QLabel(_("Find:"), this)); |
43bf612a RZ |
440 | editField = new QLineEdit(this); |
441 | connect(editField, SIGNAL(returnPressed()), SLOT(search())); | |
442 | layout2->addWidget(editField); | |
c21a2d95 | 443 | searchButton = new QPushButton(_("Search"), this); |
68ccb7ef | 444 | searchButton->setAutoDefault(false); |
43bf612a RZ |
445 | connect(searchButton, SIGNAL(clicked()), SLOT(search())); |
446 | layout2->addWidget(searchButton); | |
447 | layout1->addLayout(layout2); | |
448 | ||
7fc925fd | 449 | split = new QSplitter(this); |
7298b936 | 450 | split->setOrientation(Qt::Vertical); |
7fc925fd | 451 | list = new ConfigView(split, name); |
7fc925fd | 452 | info = new ConfigInfoView(split, name); |
43bf612a RZ |
453 | connect(list->list, SIGNAL(menuChanged(struct menu *)), |
454 | info, SLOT(setInfo(struct menu *))); | |
63431e75 MC |
455 | connect(list->list, SIGNAL(menuChanged(struct menu *)), |
456 | parent, SLOT(setMenuLink(struct menu *))); | |
457 | ||
43bf612a | 458 | layout1->addWidget(split); |
7fc925fd RZ |
459 | |
460 | if (name) { | |
68ccb7ef BB |
461 | QVariant x, y; |
462 | int width, height; | |
7fc925fd RZ |
463 | bool ok; |
464 | ||
465 | configSettings->beginGroup(name); | |
68ccb7ef BB |
466 | width = configSettings->value("/window width", parent->width() / 2).toInt(); |
467 | height = configSettings->value("/window height", parent->height() / 2).toInt(); | |
7fc925fd | 468 | resize(width, height); |
68ccb7ef BB |
469 | x = configSettings->value("/window x"); |
470 | y = configSettings->value("/window y"); | |
471 | if ((x.isValid())&&(y.isValid())) | |
472 | move(x.toInt(), y.toInt()); | |
041fbdc2 | 473 | QList<int> sizes = configSettings->readSizes("/split", &ok); |
7fc925fd RZ |
474 | if (ok) |
475 | split->setSizes(sizes); | |
476 | configSettings->endGroup(); | |
477 | connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); | |
478 | } | |
479 | } | |
480 | ||
481 | void ConfigSearchWindow::saveSettings(void) | |
482 | { | |
68ccb7ef | 483 | /*if (name()) { |
7fc925fd | 484 | configSettings->beginGroup(name()); |
68ccb7ef BB |
485 | configSettings->setValue("/window x", pos().x()); |
486 | configSettings->setValue("/window y", pos().y()); | |
487 | configSettings->setValue("/window width", size().width()); | |
488 | configSettings->setValue("/window height", size().height()); | |
7fc925fd RZ |
489 | configSettings->writeSizes("/split", split->sizes()); |
490 | configSettings->endGroup(); | |
68ccb7ef | 491 | }*/ |
43bf612a RZ |
492 | } |
493 | ||
494 | void ConfigSearchWindow::search(void) | |
495 | { | |
43bf612a RZ |
496 | } |
497 | ||
1da177e4 LT |
498 | /* |
499 | * Construct the complete config widget | |
500 | */ | |
501 | ConfigMainWindow::ConfigMainWindow(void) | |
f12aa704 | 502 | : searchWindow(0) |
1da177e4 LT |
503 | { |
504 | QMenuBar* menu; | |
92119937 | 505 | bool ok = true; |
68ccb7ef BB |
506 | QVariant x, y; |
507 | int width, height; | |
a54bb701 | 508 | char title[256]; |
1da177e4 | 509 | |
8d90c97e | 510 | QDesktopWidget *d = configApp->desktop(); |
0954828f AL |
511 | snprintf(title, sizeof(title), "%s%s", |
512 | rootmenu.prompt->text, | |
76a136c4 | 513 | "" |
76a136c4 | 514 | ); |
68ccb7ef | 515 | setWindowTitle(title); |
1da177e4 | 516 | |
68ccb7ef BB |
517 | width = configSettings->value("/window width", d->width() - 64).toInt(); |
518 | height = configSettings->value("/window height", d->height() - 64).toInt(); | |
1da177e4 | 519 | resize(width, height); |
68ccb7ef BB |
520 | x = configSettings->value("/window x"); |
521 | y = configSettings->value("/window y"); | |
522 | if ((x.isValid())&&(y.isValid())) | |
523 | move(x.toInt(), y.toInt()); | |
1da177e4 LT |
524 | |
525 | split1 = new QSplitter(this); | |
7298b936 | 526 | split1->setOrientation(Qt::Horizontal); |
1da177e4 LT |
527 | setCentralWidget(split1); |
528 | ||
7fc925fd | 529 | menuView = new ConfigView(split1, "menu"); |
1da177e4 LT |
530 | menuList = menuView->list; |
531 | ||
532 | split2 = new QSplitter(split1); | |
7298b936 | 533 | split2->setOrientation(Qt::Vertical); |
1da177e4 LT |
534 | |
535 | // create config tree | |
7fc925fd | 536 | configView = new ConfigView(split2, "config"); |
1da177e4 LT |
537 | configList = configView->list; |
538 | ||
7fc925fd | 539 | helpText = new ConfigInfoView(split2, "help"); |
68ccb7ef | 540 | //helpText->setTextFormat(Qt::RichText); |
1da177e4 LT |
541 | |
542 | setTabOrder(configList, helpText); | |
543 | configList->setFocus(); | |
544 | ||
545 | menu = menuBar(); | |
b1f8a45b | 546 | toolBar = new QToolBar("Tools", this); |
29a70168 | 547 | addToolBar(toolBar); |
1da177e4 | 548 | |
85eaf28a | 549 | backAction = new QAction(QPixmap(xpm_back), _("Back"), this); |
92119937 | 550 | connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack())); |
68ccb7ef | 551 | backAction->setEnabled(false); |
85eaf28a BB |
552 | QAction *quitAction = new QAction(_("&Quit"), this); |
553 | quitAction->setShortcut(Qt::CTRL + Qt::Key_Q); | |
92119937 | 554 | connect(quitAction, SIGNAL(triggered(bool)), SLOT(close())); |
85eaf28a BB |
555 | QAction *loadAction = new QAction(QPixmap(xpm_load), _("&Load"), this); |
556 | loadAction->setShortcut(Qt::CTRL + Qt::Key_L); | |
92119937 | 557 | connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig())); |
85eaf28a BB |
558 | saveAction = new QAction(QPixmap(xpm_save), _("&Save"), this); |
559 | saveAction->setShortcut(Qt::CTRL + Qt::Key_S); | |
92119937 | 560 | connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig())); |
3b354c55 KW |
561 | conf_set_changed_callback(conf_changed); |
562 | // Set saveAction's initial state | |
563 | conf_changed(); | |
85eaf28a | 564 | QAction *saveAsAction = new QAction(_("Save &As..."), this); |
92119937 | 565 | connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs())); |
85eaf28a BB |
566 | QAction *searchAction = new QAction(_("&Find"), this); |
567 | searchAction->setShortcut(Qt::CTRL + Qt::Key_F); | |
92119937 | 568 | connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig())); |
780505e3 | 569 | singleViewAction = new QAction(QPixmap(xpm_single_view), _("Single View"), this); |
68ccb7ef | 570 | singleViewAction->setCheckable(true); |
92119937 | 571 | connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView())); |
780505e3 | 572 | splitViewAction = new QAction(QPixmap(xpm_split_view), _("Split View"), this); |
68ccb7ef | 573 | splitViewAction->setCheckable(true); |
92119937 | 574 | connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView())); |
780505e3 | 575 | fullViewAction = new QAction(QPixmap(xpm_tree_view), _("Full View"), this); |
68ccb7ef | 576 | fullViewAction->setCheckable(true); |
92119937 | 577 | connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView())); |
1da177e4 | 578 | |
85eaf28a | 579 | QAction *showNameAction = new QAction(_("Show Name"), this); |
68ccb7ef | 580 | showNameAction->setCheckable(true); |
7fc925fd | 581 | connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool))); |
9c86235a | 582 | showNameAction->setChecked(configView->showName()); |
85eaf28a | 583 | QAction *showRangeAction = new QAction(_("Show Range"), this); |
68ccb7ef | 584 | showRangeAction->setCheckable(true); |
7fc925fd | 585 | connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool))); |
85eaf28a | 586 | QAction *showDataAction = new QAction(_("Show Data"), this); |
68ccb7ef | 587 | showDataAction->setCheckable(true); |
7fc925fd | 588 | connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool))); |
39a4897c LZ |
589 | |
590 | QActionGroup *optGroup = new QActionGroup(this); | |
68ccb7ef | 591 | optGroup->setExclusive(true); |
92119937 | 592 | connect(optGroup, SIGNAL(triggered(QAction*)), configView, |
39a4897c | 593 | SLOT(setOptionMode(QAction *))); |
92119937 | 594 | connect(optGroup, SIGNAL(triggered(QAction *)), menuView, |
39a4897c LZ |
595 | SLOT(setOptionMode(QAction *))); |
596 | ||
133c5f7c AS |
597 | configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup); |
598 | configView->showAllAction = new QAction(_("Show All Options"), optGroup); | |
599 | configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup); | |
68ccb7ef BB |
600 | configView->showNormalAction->setCheckable(true); |
601 | configView->showAllAction->setCheckable(true); | |
602 | configView->showPromptAction->setCheckable(true); | |
39a4897c | 603 | |
85eaf28a | 604 | QAction *showDebugAction = new QAction( _("Show Debug Info"), this); |
68ccb7ef | 605 | showDebugAction->setCheckable(true); |
43bf612a | 606 | connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool))); |
9c86235a | 607 | showDebugAction->setChecked(helpText->showDebug()); |
1da177e4 | 608 | |
85eaf28a | 609 | QAction *showIntroAction = new QAction( _("Introduction"), this); |
92119937 | 610 | connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro())); |
85eaf28a | 611 | QAction *showAboutAction = new QAction( _("About"), this); |
92119937 | 612 | connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout())); |
1da177e4 LT |
613 | |
614 | // init tool bar | |
68ccb7ef | 615 | toolBar->addAction(backAction); |
1da177e4 | 616 | toolBar->addSeparator(); |
68ccb7ef BB |
617 | toolBar->addAction(loadAction); |
618 | toolBar->addAction(saveAction); | |
1da177e4 | 619 | toolBar->addSeparator(); |
68ccb7ef BB |
620 | toolBar->addAction(singleViewAction); |
621 | toolBar->addAction(splitViewAction); | |
622 | toolBar->addAction(fullViewAction); | |
1da177e4 LT |
623 | |
624 | // create config menu | |
68ccb7ef BB |
625 | QMenu* config = menu->addMenu(_("&File")); |
626 | config->addAction(loadAction); | |
627 | config->addAction(saveAction); | |
628 | config->addAction(saveAsAction); | |
76bede87 | 629 | config->addSeparator(); |
68ccb7ef | 630 | config->addAction(quitAction); |
1da177e4 | 631 | |
66e7c723 | 632 | // create edit menu |
68ccb7ef BB |
633 | QMenu* editMenu = menu->addMenu(_("&Edit")); |
634 | editMenu->addAction(searchAction); | |
66e7c723 | 635 | |
1da177e4 | 636 | // create options menu |
68ccb7ef BB |
637 | QMenu* optionMenu = menu->addMenu(_("&Option")); |
638 | optionMenu->addAction(showNameAction); | |
639 | optionMenu->addAction(showRangeAction); | |
640 | optionMenu->addAction(showDataAction); | |
76bede87 | 641 | optionMenu->addSeparator(); |
68ccb7ef | 642 | optionMenu->addActions(optGroup->actions()); |
76bede87 | 643 | optionMenu->addSeparator(); |
1da177e4 LT |
644 | |
645 | // create help menu | |
76bede87 | 646 | menu->addSeparator(); |
68ccb7ef BB |
647 | QMenu* helpMenu = menu->addMenu(_("&Help")); |
648 | helpMenu->addAction(showIntroAction); | |
649 | helpMenu->addAction(showAboutAction); | |
1da177e4 | 650 | |
b65a47e1 RZ |
651 | connect(helpText, SIGNAL(menuSelected(struct menu *)), |
652 | SLOT(setMenuLink(struct menu *))); | |
1da177e4 | 653 | |
68ccb7ef | 654 | QString listMode = configSettings->value("/listMode", "symbol").toString(); |
1da177e4 LT |
655 | if (listMode == "single") |
656 | showSingleView(); | |
657 | else if (listMode == "full") | |
658 | showFullView(); | |
659 | else /*if (listMode == "split")*/ | |
660 | showSplitView(); | |
661 | ||
662 | // UI setup done, restore splitter positions | |
041fbdc2 | 663 | QList<int> sizes = configSettings->readSizes("/split1", &ok); |
1da177e4 LT |
664 | if (ok) |
665 | split1->setSizes(sizes); | |
666 | ||
7fc925fd | 667 | sizes = configSettings->readSizes("/split2", &ok); |
1da177e4 LT |
668 | if (ok) |
669 | split2->setSizes(sizes); | |
1da177e4 LT |
670 | } |
671 | ||
1da177e4 LT |
672 | void ConfigMainWindow::loadConfig(void) |
673 | { | |
68ccb7ef | 674 | QString s = QFileDialog::getOpenFileName(this, "", conf_get_configname()); |
1da177e4 LT |
675 | if (s.isNull()) |
676 | return; | |
3b9fa093 | 677 | if (conf_read(QFile::encodeName(s))) |
c21a2d95 | 678 | QMessageBox::information(this, "qconf", _("Unable to load configuration!")); |
1da177e4 LT |
679 | ConfigView::updateListAll(); |
680 | } | |
681 | ||
bac6aa86 | 682 | bool ConfigMainWindow::saveConfig(void) |
1da177e4 | 683 | { |
bac6aa86 | 684 | if (conf_write(NULL)) { |
c21a2d95 | 685 | QMessageBox::information(this, "qconf", _("Unable to save configuration!")); |
bac6aa86 MM |
686 | return false; |
687 | } | |
688 | return true; | |
1da177e4 LT |
689 | } |
690 | ||
691 | void ConfigMainWindow::saveConfigAs(void) | |
692 | { | |
68ccb7ef | 693 | QString s = QFileDialog::getSaveFileName(this, "", conf_get_configname()); |
1da177e4 LT |
694 | if (s.isNull()) |
695 | return; | |
d49e4687 | 696 | saveConfig(); |
1da177e4 LT |
697 | } |
698 | ||
43bf612a RZ |
699 | void ConfigMainWindow::searchConfig(void) |
700 | { | |
701 | if (!searchWindow) | |
7fc925fd | 702 | searchWindow = new ConfigSearchWindow(this, "search"); |
43bf612a RZ |
703 | searchWindow->show(); |
704 | } | |
705 | ||
1da177e4 LT |
706 | void ConfigMainWindow::changeMenu(struct menu *menu) |
707 | { | |
76538660 | 708 | |
1da177e4 LT |
709 | } |
710 | ||
b65a47e1 | 711 | void ConfigMainWindow::setMenuLink(struct menu *menu) |
1da177e4 | 712 | { |
1da177e4 LT |
713 | } |
714 | ||
b65a47e1 RZ |
715 | void ConfigMainWindow::listFocusChanged(void) |
716 | { | |
b65a47e1 RZ |
717 | } |
718 | ||
1da177e4 LT |
719 | void ConfigMainWindow::goBack(void) |
720 | { | |
1da177e4 LT |
721 | } |
722 | ||
723 | void ConfigMainWindow::showSingleView(void) | |
724 | { | |
780505e3 BB |
725 | singleViewAction->setEnabled(false); |
726 | singleViewAction->setChecked(true); | |
727 | splitViewAction->setEnabled(true); | |
728 | splitViewAction->setChecked(false); | |
729 | fullViewAction->setEnabled(true); | |
730 | fullViewAction->setChecked(false); | |
731 | ||
1da177e4 | 732 | menuView->hide(); |
1da177e4 LT |
733 | configList->setFocus(); |
734 | } | |
735 | ||
736 | void ConfigMainWindow::showSplitView(void) | |
737 | { | |
780505e3 BB |
738 | singleViewAction->setEnabled(true); |
739 | singleViewAction->setChecked(false); | |
740 | splitViewAction->setEnabled(false); | |
741 | splitViewAction->setChecked(true); | |
742 | fullViewAction->setEnabled(true); | |
743 | fullViewAction->setChecked(false); | |
744 | ||
1da177e4 LT |
745 | menuView->show(); |
746 | menuList->setFocus(); | |
747 | } | |
748 | ||
749 | void ConfigMainWindow::showFullView(void) | |
750 | { | |
780505e3 BB |
751 | singleViewAction->setEnabled(true); |
752 | singleViewAction->setChecked(false); | |
753 | splitViewAction->setEnabled(true); | |
754 | splitViewAction->setChecked(false); | |
755 | fullViewAction->setEnabled(false); | |
756 | fullViewAction->setChecked(true); | |
757 | ||
1da177e4 | 758 | menuView->hide(); |
1da177e4 LT |
759 | configList->setFocus(); |
760 | } | |
761 | ||
1da177e4 LT |
762 | /* |
763 | * ask for saving configuration before quitting | |
764 | * TODO ask only when something changed | |
765 | */ | |
766 | void ConfigMainWindow::closeEvent(QCloseEvent* e) | |
767 | { | |
b3214293 | 768 | if (!conf_get_changed()) { |
1da177e4 LT |
769 | e->accept(); |
770 | return; | |
771 | } | |
c21a2d95 | 772 | QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning, |
1da177e4 | 773 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); |
c21a2d95 EG |
774 | mb.setButtonText(QMessageBox::Yes, _("&Save Changes")); |
775 | mb.setButtonText(QMessageBox::No, _("&Discard Changes")); | |
776 | mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit")); | |
1da177e4 LT |
777 | switch (mb.exec()) { |
778 | case QMessageBox::Yes: | |
bac6aa86 MM |
779 | if (saveConfig()) |
780 | e->accept(); | |
781 | else | |
782 | e->ignore(); | |
783 | break; | |
1da177e4 LT |
784 | case QMessageBox::No: |
785 | e->accept(); | |
786 | break; | |
787 | case QMessageBox::Cancel: | |
788 | e->ignore(); | |
789 | break; | |
790 | } | |
791 | } | |
792 | ||
793 | void ConfigMainWindow::showIntro(void) | |
794 | { | |
652cf982 | 795 | static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n" |
1da177e4 LT |
796 | "For each option, a blank box indicates the feature is disabled, a check\n" |
797 | "indicates it is enabled, and a dot indicates that it is to be compiled\n" | |
798 | "as a module. Clicking on the box will cycle through the three states.\n\n" | |
799 | "If you do not see an option (e.g., a device driver) that you believe\n" | |
800 | "should be present, try turning on Show All Options under the Options menu.\n" | |
801 | "Although there is no cross reference yet to help you figure out what other\n" | |
802 | "options must be enabled to support the option you are interested in, you can\n" | |
803 | "still view the help of a grayed-out option.\n\n" | |
804 | "Toggling Show Debug Info under the Options menu will show the dependencies,\n" | |
c21a2d95 | 805 | "which you can then match by examining other options.\n\n"); |
1da177e4 LT |
806 | |
807 | QMessageBox::information(this, "qconf", str); | |
808 | } | |
809 | ||
810 | void ConfigMainWindow::showAbout(void) | |
811 | { | |
c21a2d95 EG |
812 | static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n" |
813 | "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n"); | |
1da177e4 LT |
814 | |
815 | QMessageBox::information(this, "qconf", str); | |
816 | } | |
817 | ||
818 | void ConfigMainWindow::saveSettings(void) | |
819 | { | |
68ccb7ef BB |
820 | configSettings->setValue("/window x", pos().x()); |
821 | configSettings->setValue("/window y", pos().y()); | |
822 | configSettings->setValue("/window width", size().width()); | |
823 | configSettings->setValue("/window height", size().height()); | |
1da177e4 LT |
824 | |
825 | QString entry; | |
98403a91 | 826 | |
68ccb7ef | 827 | configSettings->setValue("/listMode", entry); |
1da177e4 | 828 | |
7fc925fd RZ |
829 | configSettings->writeSizes("/split1", split1->sizes()); |
830 | configSettings->writeSizes("/split2", split2->sizes()); | |
1da177e4 LT |
831 | } |
832 | ||
3b354c55 KW |
833 | void ConfigMainWindow::conf_changed(void) |
834 | { | |
835 | if (saveAction) | |
836 | saveAction->setEnabled(conf_get_changed()); | |
837 | } | |
838 | ||
1da177e4 LT |
839 | void fixup_rootmenu(struct menu *menu) |
840 | { | |
841 | struct menu *child; | |
842 | static int menu_cnt = 0; | |
843 | ||
844 | menu->flags |= MENU_ROOT; | |
845 | for (child = menu->list; child; child = child->next) { | |
846 | if (child->prompt && child->prompt->type == P_MENU) { | |
847 | menu_cnt++; | |
848 | fixup_rootmenu(child); | |
849 | menu_cnt--; | |
850 | } else if (!menu_cnt) | |
851 | fixup_rootmenu(child); | |
852 | } | |
853 | } | |
854 | ||
855 | static const char *progname; | |
856 | ||
857 | static void usage(void) | |
858 | { | |
68ccb7ef | 859 | printf(_("%s [-s] <config>\n").toLatin1().constData(), progname); |
1da177e4 LT |
860 | exit(0); |
861 | } | |
862 | ||
863 | int main(int ac, char** av) | |
864 | { | |
865 | ConfigMainWindow* v; | |
866 | const char *name; | |
867 | ||
3b9fa093 ACM |
868 | bindtextdomain(PACKAGE, LOCALEDIR); |
869 | textdomain(PACKAGE); | |
870 | ||
1da177e4 LT |
871 | progname = av[0]; |
872 | configApp = new QApplication(ac, av); | |
873 | if (ac > 1 && av[1][0] == '-') { | |
874 | switch (av[1][1]) { | |
0a1f00a1 MM |
875 | case 's': |
876 | conf_set_message_callback(NULL); | |
877 | break; | |
1da177e4 LT |
878 | case 'h': |
879 | case '?': | |
880 | usage(); | |
881 | } | |
882 | name = av[2]; | |
883 | } else | |
884 | name = av[1]; | |
885 | if (!name) | |
886 | usage(); | |
887 | ||
888 | conf_parse(name); | |
889 | fixup_rootmenu(&rootmenu); | |
890 | conf_read(NULL); | |
891 | //zconfdump(stdout); | |
892 | ||
7fc925fd RZ |
893 | configSettings = new ConfigSettings(); |
894 | configSettings->beginGroup("/kconfig/qconf"); | |
1da177e4 LT |
895 | v = new ConfigMainWindow(); |
896 | ||
897 | //zconfdump(stdout); | |
1da177e4 LT |
898 | configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit())); |
899 | configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings())); | |
43bf612a | 900 | v->show(); |
1da177e4 LT |
901 | configApp->exec(); |
902 | ||
7fc925fd RZ |
903 | configSettings->endGroup(); |
904 | delete configSettings; | |
905 | ||
1da177e4 LT |
906 | return 0; |
907 | } |