blob: 199934c5cdbf3037146b062132f88e94470d306b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
Alexander Stein133c5f72010-08-31 17:34:37 +02006#include <qglobal.h>
7
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07008#include <QMainWindow>
Alexander Stein133c5f72010-08-31 17:34:37 +02009#include <q3vbox.h>
10#include <q3valuelist.h>
11#include <q3textbrowser.h>
12#include <q3action.h>
13#include <q3header.h>
14#include <q3filedialog.h>
15#include <q3dragobject.h>
16#include <q3popupmenu.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020017
18#include <qapplication.h>
Markus Heidelberg8d90c972009-05-18 01:36:52 +020019#include <qdesktopwidget.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <qtoolbar.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070021#include <qlayout.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <qsplitter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <qlineedit.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070024#include <qlabel.h>
25#include <qpushbutton.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <qmenubar.h>
27#include <qmessagebox.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <qregexp.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020029#include <qevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <stdlib.h>
32
33#include "lkc.h"
34#include "qconf.h"
35
36#include "qconf.moc"
37#include "images.c"
38
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070039#ifdef _
40# undef _
41# define _ qgettext
42#endif
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070045static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Alexander Stein133c5f72010-08-31 17:34:37 +020047Q3Action *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080048
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070049static inline QString qgettext(const char* str)
50{
Roman Zippel43bf6122006-06-08 22:12:45 -070051 return QString::fromLocal8Bit(gettext(str));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070052}
53
54static inline QString qgettext(const QString& str)
55{
Roman Zippel43bf6122006-06-08 22:12:45 -070056 return QString::fromLocal8Bit(gettext(str.latin1()));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070057}
58
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010059ConfigSettings::ConfigSettings()
60 : QSettings("kernel.org", "qconf")
61{
62}
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064/**
65 * Reads a list of integer values from the application settings.
66 */
Alexander Stein133c5f72010-08-31 17:34:37 +020067Q3ValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Alexander Stein133c5f72010-08-31 17:34:37 +020069 Q3ValueList<int> result;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 QStringList entryList = readListEntry(key, ok);
Li Zefanc1f96f02010-05-07 13:58:04 +080071 QStringList::Iterator it;
72
73 for (it = entryList.begin(); it != entryList.end(); ++it)
74 result.push_back((*it).toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 return result;
77}
78
79/**
80 * Writes a list of integer values to the application settings.
81 */
Alexander Stein133c5f72010-08-31 17:34:37 +020082bool ConfigSettings::writeSizes(const QString& key, const Q3ValueList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 QStringList stringList;
Alexander Stein133c5f72010-08-31 17:34:37 +020085 Q3ValueList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 for (it = value.begin(); it != value.end(); ++it)
88 stringList.push_back(QString::number(*it));
89 return writeEntry(key, stringList);
90}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093/*
94 * set the new data
95 * TODO check the value
96 */
97void ConfigItem::okRename(int col)
98{
99 Parent::okRename(col);
100 sym_set_string_value(menu->sym, text(dataColIdx).latin1());
Karsten Wiese49e56462007-02-14 00:32:57 -0800101 listView()->updateList(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104/*
105 * update the displayed of a menu entry
106 */
107void ConfigItem::updateMenu(void)
108{
109 ConfigList* list;
110 struct symbol* sym;
111 struct property *prop;
112 QString prompt;
113 int type;
114 tristate expr;
115
116 list = listView();
117 if (goParent) {
118 setPixmap(promptColIdx, list->menuBackPix);
119 prompt = "..";
120 goto set_prompt;
121 }
122
123 sym = menu->sym;
124 prop = menu->prompt;
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100125 prompt = _(menu_get_prompt(menu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 if (prop) switch (prop->type) {
128 case P_MENU:
129 if (list->mode == singleMode || list->mode == symbolMode) {
130 /* a menuconfig entry is displayed differently
131 * depending whether it's at the view root or a child.
132 */
133 if (sym && list->rootEntry == menu)
134 break;
135 setPixmap(promptColIdx, list->menuPix);
136 } else {
137 if (sym)
138 break;
139 setPixmap(promptColIdx, 0);
140 }
141 goto set_prompt;
142 case P_COMMENT:
143 setPixmap(promptColIdx, 0);
144 goto set_prompt;
145 default:
146 ;
147 }
148 if (!sym)
149 goto set_prompt;
150
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700151 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 type = sym_get_type(sym);
154 switch (type) {
155 case S_BOOLEAN:
156 case S_TRISTATE:
157 char ch;
158
Li Zefan39a48972010-05-10 16:33:41 +0800159 if (!sym_is_changable(sym) && list->optMode == normalOpt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 setPixmap(promptColIdx, 0);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700161 setText(noColIdx, QString::null);
162 setText(modColIdx, QString::null);
163 setText(yesColIdx, QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 break;
165 }
166 expr = sym_get_tristate_value(sym);
167 switch (expr) {
168 case yes:
169 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
170 setPixmap(promptColIdx, list->choiceYesPix);
171 else
172 setPixmap(promptColIdx, list->symbolYesPix);
173 setText(yesColIdx, "Y");
174 ch = 'Y';
175 break;
176 case mod:
177 setPixmap(promptColIdx, list->symbolModPix);
178 setText(modColIdx, "M");
179 ch = 'M';
180 break;
181 default:
182 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
183 setPixmap(promptColIdx, list->choiceNoPix);
184 else
185 setPixmap(promptColIdx, list->symbolNoPix);
186 setText(noColIdx, "N");
187 ch = 'N';
188 break;
189 }
190 if (expr != no)
191 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
192 if (expr != mod)
193 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
194 if (expr != yes)
195 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
196
197 setText(dataColIdx, QChar(ch));
198 break;
199 case S_INT:
200 case S_HEX:
201 case S_STRING:
202 const char* data;
203
204 data = sym_get_string_value(sym);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 int i = list->mapIdx(dataColIdx);
207 if (i >= 0)
208 setRenameEnabled(i, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 setText(dataColIdx, data);
210 if (type == S_STRING)
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700211 prompt = QString("%1: %2").arg(prompt).arg(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 else
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700213 prompt = QString("(%2) %1").arg(prompt).arg(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 break;
215 }
216 if (!sym_has_value(sym) && visible)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100217 prompt += _(" (NEW)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218set_prompt:
219 setText(promptColIdx, prompt);
220}
221
222void ConfigItem::testUpdateMenu(bool v)
223{
224 ConfigItem* i;
225
226 visible = v;
227 if (!menu)
228 return;
229
230 sym_calc_value(menu->sym);
231 if (menu->flags & MENU_CHANGED) {
232 /* the menu entry changed, so update all list items */
233 menu->flags &= ~MENU_CHANGED;
234 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
235 i->updateMenu();
236 } else if (listView()->updateAll)
237 updateMenu();
238}
239
240void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
241{
242 ConfigList* list = listView();
243
244 if (visible) {
245 if (isSelected() && !list->hasFocus() && list->mode == menuMode)
246 Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
247 else
248 Parent::paintCell(p, cg, column, width, align);
249 } else
250 Parent::paintCell(p, list->disabledColorGroup, column, width, align);
251}
252
253/*
254 * construct a menu entry
255 */
256void ConfigItem::init(void)
257{
258 if (menu) {
259 ConfigList* list = listView();
260 nextItem = (ConfigItem*)menu->data;
261 menu->data = this;
262
263 if (list->mode != fullMode)
264 setOpen(TRUE);
265 sym_calc_value(menu->sym);
266 }
267 updateMenu();
268}
269
270/*
271 * destruct a menu entry
272 */
273ConfigItem::~ConfigItem(void)
274{
275 if (menu) {
276 ConfigItem** ip = (ConfigItem**)&menu->data;
277 for (; *ip; ip = &(*ip)->nextItem) {
278 if (*ip == this) {
279 *ip = nextItem;
280 break;
281 }
282 }
283 }
284}
285
Roman Zippel43bf6122006-06-08 22:12:45 -0700286ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
287 : Parent(parent)
288{
289 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
290}
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292void ConfigLineEdit::show(ConfigItem* i)
293{
294 item = i;
295 if (sym_get_string_value(item->menu->sym))
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700296 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 else
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700298 setText(QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 Parent::show();
300 setFocus();
301}
302
303void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
304{
305 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200306 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200308 case Qt::Key_Return:
309 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 sym_set_string_value(item->menu->sym, text().latin1());
311 parent()->updateList(item);
312 break;
313 default:
314 Parent::keyPressEvent(e);
315 return;
316 }
317 e->accept();
318 parent()->list->setFocus();
319 hide();
320}
321
Roman Zippel7fc925f2006-06-08 22:12:46 -0700322ConfigList::ConfigList(ConfigView* p, const char *name)
323 : Parent(p, name),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 updateAll(false),
325 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
326 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
327 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Li Zefan39a48972010-05-10 16:33:41 +0800328 showName(false), showRange(false), showData(false), optMode(normalOpt),
Roman Zippel7fc925f2006-06-08 22:12:46 -0700329 rootEntry(0), headerPopup(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
331 int i;
332
333 setSorting(-1);
334 setRootIsDecorated(TRUE);
335 disabledColorGroup = palette().active();
336 disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
337 inactivedColorGroup = palette().active();
338 inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
339
340 connect(this, SIGNAL(selectionChanged(void)),
341 SLOT(updateSelection(void)));
342
Roman Zippel7fc925f2006-06-08 22:12:46 -0700343 if (name) {
344 configSettings->beginGroup(name);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700345 showName = configSettings->readBoolEntry("/showName", false);
346 showRange = configSettings->readBoolEntry("/showRange", false);
347 showData = configSettings->readBoolEntry("/showData", false);
Li Zefan39a48972010-05-10 16:33:41 +0800348 optMode = (enum optionMode)configSettings->readNumEntry("/optionMode", false);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700349 configSettings->endGroup();
350 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352
353 for (i = 0; i < colNr; i++)
354 colMap[i] = colRevMap[i] = -1;
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100355 addColumn(promptColIdx, _("Option"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 reinit();
358}
359
Li Zefan39a48972010-05-10 16:33:41 +0800360bool ConfigList::menuSkip(struct menu *menu)
361{
362 if (optMode == normalOpt && menu_is_visible(menu))
363 return false;
364 if (optMode == promptOpt && menu_has_prompt(menu))
365 return false;
366 if (optMode == allOpt)
367 return false;
368 return true;
369}
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371void ConfigList::reinit(void)
372{
373 removeColumn(dataColIdx);
374 removeColumn(yesColIdx);
375 removeColumn(modColIdx);
376 removeColumn(noColIdx);
377 removeColumn(nameColIdx);
378
379 if (showName)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100380 addColumn(nameColIdx, _("Name"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (showRange) {
382 addColumn(noColIdx, "N");
383 addColumn(modColIdx, "M");
384 addColumn(yesColIdx, "Y");
385 }
386 if (showData)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100387 addColumn(dataColIdx, _("Value"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 updateListAll();
390}
391
Roman Zippel7fc925f2006-06-08 22:12:46 -0700392void ConfigList::saveSettings(void)
393{
394 if (name()) {
395 configSettings->beginGroup(name());
396 configSettings->writeEntry("/showName", showName);
397 configSettings->writeEntry("/showRange", showRange);
398 configSettings->writeEntry("/showData", showData);
Li Zefan39a48972010-05-10 16:33:41 +0800399 configSettings->writeEntry("/optionMode", (int)optMode);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700400 configSettings->endGroup();
401 }
402}
403
Roman Zippelb65a47e2006-06-08 22:12:47 -0700404ConfigItem* ConfigList::findConfigItem(struct menu *menu)
405{
406 ConfigItem* item = (ConfigItem*)menu->data;
407
408 for (; item; item = item->nextItem) {
409 if (this == item->listView())
410 break;
411 }
412
413 return item;
414}
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416void ConfigList::updateSelection(void)
417{
418 struct menu *menu;
419 enum prop_type type;
420
421 ConfigItem* item = (ConfigItem*)selectedItem();
422 if (!item)
423 return;
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 menu = item->menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700426 emit menuChanged(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 if (!menu)
428 return;
429 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
430 if (mode == menuMode && type == P_MENU)
431 emit menuSelected(menu);
432}
433
434void ConfigList::updateList(ConfigItem* item)
435{
436 ConfigItem* last = 0;
437
Roman Zippel43bf6122006-06-08 22:12:45 -0700438 if (!rootEntry) {
439 if (mode != listMode)
440 goto update;
Alexander Stein133c5f72010-08-31 17:34:37 +0200441 Q3ListViewItemIterator it(this);
Roman Zippel43bf6122006-06-08 22:12:45 -0700442 ConfigItem* item;
443
444 for (; it.current(); ++it) {
445 item = (ConfigItem*)it.current();
446 if (!item->menu)
447 continue;
448 item->testUpdateMenu(menu_is_visible(item->menu));
449 }
450 return;
451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 if (rootEntry != &rootmenu && (mode == singleMode ||
454 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
455 item = firstChild();
456 if (!item)
457 item = new ConfigItem(this, 0, true);
458 last = item;
459 }
460 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
461 rootEntry->sym && rootEntry->prompt) {
462 item = last ? last->nextSibling() : firstChild();
463 if (!item)
464 item = new ConfigItem(this, last, rootEntry, true);
465 else
466 item->testUpdateMenu(true);
467
468 updateMenuList(item, rootEntry);
469 triggerUpdate();
470 return;
471 }
472update:
473 updateMenuList(this, rootEntry);
474 triggerUpdate();
475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477void ConfigList::setValue(ConfigItem* item, tristate val)
478{
479 struct symbol* sym;
480 int type;
481 tristate oldval;
482
483 sym = item->menu ? item->menu->sym : 0;
484 if (!sym)
485 return;
486
487 type = sym_get_type(sym);
488 switch (type) {
489 case S_BOOLEAN:
490 case S_TRISTATE:
491 oldval = sym_get_tristate_value(sym);
492
493 if (!sym_set_tristate_value(sym, val))
494 return;
495 if (oldval == no && item->menu->list)
496 item->setOpen(TRUE);
497 parent()->updateList(item);
498 break;
499 }
500}
501
502void ConfigList::changeValue(ConfigItem* item)
503{
504 struct symbol* sym;
505 struct menu* menu;
506 int type, oldexpr, newexpr;
507
508 menu = item->menu;
509 if (!menu)
510 return;
511 sym = menu->sym;
512 if (!sym) {
513 if (item->menu->list)
514 item->setOpen(!item->isOpen());
515 return;
516 }
517
518 type = sym_get_type(sym);
519 switch (type) {
520 case S_BOOLEAN:
521 case S_TRISTATE:
522 oldexpr = sym_get_tristate_value(sym);
523 newexpr = sym_toggle_tristate_value(sym);
524 if (item->menu->list) {
525 if (oldexpr == newexpr)
526 item->setOpen(!item->isOpen());
527 else if (oldexpr == no)
528 item->setOpen(TRUE);
529 }
530 if (oldexpr != newexpr)
531 parent()->updateList(item);
532 break;
533 case S_INT:
534 case S_HEX:
535 case S_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (colMap[dataColIdx] >= 0)
537 item->startRename(colMap[dataColIdx]);
538 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 parent()->lineEdit->show(item);
540 break;
541 }
542}
543
544void ConfigList::setRootMenu(struct menu *menu)
545{
546 enum prop_type type;
547
548 if (rootEntry == menu)
549 return;
550 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
551 if (type != P_MENU)
552 return;
553 updateMenuList(this, 0);
554 rootEntry = menu;
555 updateListAll();
556 setSelected(currentItem(), hasFocus());
Roman Zippelb65a47e2006-06-08 22:12:47 -0700557 ensureItemVisible(currentItem());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
560void ConfigList::setParentMenu(void)
561{
562 ConfigItem* item;
563 struct menu *oldroot;
564
565 oldroot = rootEntry;
566 if (rootEntry == &rootmenu)
567 return;
568 setRootMenu(menu_get_parent_menu(rootEntry->parent));
569
Alexander Stein133c5f72010-08-31 17:34:37 +0200570 Q3ListViewItemIterator it(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 for (; (item = (ConfigItem*)it.current()); it++) {
572 if (item->menu == oldroot) {
573 setCurrentItem(item);
574 ensureItemVisible(item);
575 break;
576 }
577 }
578}
579
Roman Zippel7fc925f2006-06-08 22:12:46 -0700580/*
581 * update all the children of a menu entry
582 * removes/adds the entries from the parent widget as necessary
583 *
584 * parent: either the menu list widget or a menu entry widget
585 * menu: entry to be updated
586 */
587template <class P>
588void ConfigList::updateMenuList(P* parent, struct menu* menu)
589{
590 struct menu* child;
591 ConfigItem* item;
592 ConfigItem* last;
593 bool visible;
594 enum prop_type type;
595
596 if (!menu) {
597 while ((item = parent->firstChild()))
598 delete item;
599 return;
600 }
601
602 last = parent->firstChild();
603 if (last && !last->goParent)
604 last = 0;
605 for (child = menu->list; child; child = child->next) {
606 item = last ? last->nextSibling() : parent->firstChild();
607 type = child->prompt ? child->prompt->type : P_UNKNOWN;
608
609 switch (mode) {
610 case menuMode:
611 if (!(child->flags & MENU_ROOT))
612 goto hide;
613 break;
614 case symbolMode:
615 if (child->flags & MENU_ROOT)
616 goto hide;
617 break;
618 default:
619 break;
620 }
621
622 visible = menu_is_visible(child);
Li Zefan39a48972010-05-10 16:33:41 +0800623 if (!menuSkip(child)) {
Cyrill V. Gorcunoved8b4d42007-02-14 00:33:03 -0800624 if (!child->sym && !child->list && !child->prompt)
625 continue;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700626 if (!item || item->menu != child)
627 item = new ConfigItem(parent, last, child, visible);
628 else
629 item->testUpdateMenu(visible);
630
631 if (mode == fullMode || mode == menuMode || type != P_MENU)
632 updateMenuList(item, child);
633 else
634 updateMenuList(item, 0);
635 last = item;
636 continue;
637 }
638 hide:
639 if (item && item->menu == child) {
640 last = parent->firstChild();
641 if (last == item)
642 last = 0;
643 else while (last->nextSibling() != item)
644 last = last->nextSibling();
645 delete item;
646 }
647 }
648}
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650void ConfigList::keyPressEvent(QKeyEvent* ev)
651{
Alexander Stein133c5f72010-08-31 17:34:37 +0200652 Q3ListViewItem* i = currentItem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 ConfigItem* item;
654 struct menu *menu;
655 enum prop_type type;
656
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200657 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 emit parentSelected();
659 ev->accept();
660 return;
661 }
662
663 if (!i) {
664 Parent::keyPressEvent(ev);
665 return;
666 }
667 item = (ConfigItem*)i;
668
669 switch (ev->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200670 case Qt::Key_Return:
671 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 if (item->goParent) {
673 emit parentSelected();
674 break;
675 }
676 menu = item->menu;
677 if (!menu)
678 break;
679 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
680 if (type == P_MENU && rootEntry != menu &&
681 mode != fullMode && mode != menuMode) {
682 emit menuSelected(menu);
683 break;
684 }
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200685 case Qt::Key_Space:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 changeValue(item);
687 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200688 case Qt::Key_N:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 setValue(item, no);
690 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200691 case Qt::Key_M:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 setValue(item, mod);
693 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200694 case Qt::Key_Y:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 setValue(item, yes);
696 break;
697 default:
698 Parent::keyPressEvent(ev);
699 return;
700 }
701 ev->accept();
702}
703
704void ConfigList::contentsMousePressEvent(QMouseEvent* e)
705{
706 //QPoint p(contentsToViewport(e->pos()));
707 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
708 Parent::contentsMousePressEvent(e);
709}
710
711void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
712{
713 QPoint p(contentsToViewport(e->pos()));
714 ConfigItem* item = (ConfigItem*)itemAt(p);
715 struct menu *menu;
716 enum prop_type ptype;
717 const QPixmap* pm;
718 int idx, x;
719
720 if (!item)
721 goto skip;
722
723 menu = item->menu;
724 x = header()->offset() + p.x();
725 idx = colRevMap[header()->sectionAt(x)];
726 switch (idx) {
727 case promptColIdx:
728 pm = item->pixmap(promptColIdx);
729 if (pm) {
730 int off = header()->sectionPos(0) + itemMargin() +
731 treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
732 if (x >= off && x < off + pm->width()) {
733 if (item->goParent) {
734 emit parentSelected();
735 break;
736 } else if (!menu)
737 break;
738 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
739 if (ptype == P_MENU && rootEntry != menu &&
740 mode != fullMode && mode != menuMode)
741 emit menuSelected(menu);
742 else
743 changeValue(item);
744 }
745 }
746 break;
747 case noColIdx:
748 setValue(item, no);
749 break;
750 case modColIdx:
751 setValue(item, mod);
752 break;
753 case yesColIdx:
754 setValue(item, yes);
755 break;
756 case dataColIdx:
757 changeValue(item);
758 break;
759 }
760
761skip:
762 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
763 Parent::contentsMouseReleaseEvent(e);
764}
765
766void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
767{
768 //QPoint p(contentsToViewport(e->pos()));
769 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
770 Parent::contentsMouseMoveEvent(e);
771}
772
773void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
774{
775 QPoint p(contentsToViewport(e->pos()));
776 ConfigItem* item = (ConfigItem*)itemAt(p);
777 struct menu *menu;
778 enum prop_type ptype;
779
780 if (!item)
781 goto skip;
782 if (item->goParent) {
783 emit parentSelected();
784 goto skip;
785 }
786 menu = item->menu;
787 if (!menu)
788 goto skip;
789 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
790 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
791 emit menuSelected(menu);
792 else if (menu->sym)
793 changeValue(item);
794
795skip:
796 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
797 Parent::contentsMouseDoubleClickEvent(e);
798}
799
800void ConfigList::focusInEvent(QFocusEvent *e)
801{
Roman Zippelb65a47e2006-06-08 22:12:47 -0700802 struct menu *menu = NULL;
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 Parent::focusInEvent(e);
805
Roman Zippelb65a47e2006-06-08 22:12:47 -0700806 ConfigItem* item = (ConfigItem *)currentItem();
807 if (item) {
808 setSelected(item, TRUE);
809 menu = item->menu;
810 }
811 emit gotFocus(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
813
Roman Zippel7fc925f2006-06-08 22:12:46 -0700814void ConfigList::contextMenuEvent(QContextMenuEvent *e)
815{
816 if (e->y() <= header()->geometry().bottom()) {
817 if (!headerPopup) {
Alexander Stein133c5f72010-08-31 17:34:37 +0200818 Q3Action *action;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700819
Alexander Stein133c5f72010-08-31 17:34:37 +0200820 headerPopup = new Q3PopupMenu(this);
821 action = new Q3Action(NULL, _("Show Name"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700822 action->setToggleAction(TRUE);
823 connect(action, SIGNAL(toggled(bool)),
824 parent(), SLOT(setShowName(bool)));
825 connect(parent(), SIGNAL(showNameChanged(bool)),
826 action, SLOT(setOn(bool)));
827 action->setOn(showName);
828 action->addTo(headerPopup);
Alexander Stein133c5f72010-08-31 17:34:37 +0200829 action = new Q3Action(NULL, _("Show Range"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700830 action->setToggleAction(TRUE);
831 connect(action, SIGNAL(toggled(bool)),
832 parent(), SLOT(setShowRange(bool)));
833 connect(parent(), SIGNAL(showRangeChanged(bool)),
834 action, SLOT(setOn(bool)));
835 action->setOn(showRange);
836 action->addTo(headerPopup);
Alexander Stein133c5f72010-08-31 17:34:37 +0200837 action = new Q3Action(NULL, _("Show Data"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700838 action->setToggleAction(TRUE);
839 connect(action, SIGNAL(toggled(bool)),
840 parent(), SLOT(setShowData(bool)));
841 connect(parent(), SIGNAL(showDataChanged(bool)),
842 action, SLOT(setOn(bool)));
843 action->setOn(showData);
844 action->addTo(headerPopup);
845 }
846 headerPopup->exec(e->globalPos());
847 e->accept();
848 } else
849 e->ignore();
850}
851
Li Zefan39a48972010-05-10 16:33:41 +0800852ConfigView*ConfigView::viewList;
853QAction *ConfigView::showNormalAction;
854QAction *ConfigView::showAllAction;
855QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Roman Zippel7fc925f2006-06-08 22:12:46 -0700857ConfigView::ConfigView(QWidget* parent, const char *name)
858 : Parent(parent, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700860 list = new ConfigList(this, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 lineEdit = new ConfigLineEdit(this);
862 lineEdit->hide();
863
864 this->nextView = viewList;
865 viewList = this;
866}
867
868ConfigView::~ConfigView(void)
869{
870 ConfigView** vp;
871
872 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
873 if (*vp == this) {
874 *vp = nextView;
875 break;
876 }
877 }
878}
879
Li Zefan39a48972010-05-10 16:33:41 +0800880void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700881{
Li Zefan39a48972010-05-10 16:33:41 +0800882 if (act == showNormalAction)
883 list->optMode = normalOpt;
884 else if (act == showAllAction)
885 list->optMode = allOpt;
886 else
887 list->optMode = promptOpt;
888
889 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700890}
891
892void ConfigView::setShowName(bool b)
893{
894 if (list->showName != b) {
895 list->showName = b;
896 list->reinit();
897 emit showNameChanged(b);
898 }
899}
900
901void ConfigView::setShowRange(bool b)
902{
903 if (list->showRange != b) {
904 list->showRange = b;
905 list->reinit();
906 emit showRangeChanged(b);
907 }
908}
909
910void ConfigView::setShowData(bool b)
911{
912 if (list->showData != b) {
913 list->showData = b;
914 list->reinit();
915 emit showDataChanged(b);
916 }
917}
918
919void ConfigList::setAllOpen(bool open)
920{
Alexander Stein133c5f72010-08-31 17:34:37 +0200921 Q3ListViewItemIterator it(this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700922
923 for (; it.current(); it++)
924 it.current()->setOpen(open);
925}
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927void ConfigView::updateList(ConfigItem* item)
928{
929 ConfigView* v;
930
931 for (v = viewList; v; v = v->nextView)
932 v->list->updateList(item);
933}
934
935void ConfigView::updateListAll(void)
936{
937 ConfigView* v;
938
939 for (v = viewList; v; v = v->nextView)
940 v->list->updateListAll();
941}
942
Roman Zippel43bf6122006-06-08 22:12:45 -0700943ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Alexander Stein133c5f72010-08-31 17:34:37 +0200944 : Parent(parent, name), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700945{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700946 if (name) {
947 configSettings->beginGroup(name);
948 _showDebug = configSettings->readBoolEntry("/showDebug", false);
949 configSettings->endGroup();
950 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
951 }
952}
953
954void ConfigInfoView::saveSettings(void)
955{
956 if (name()) {
957 configSettings->beginGroup(name());
958 configSettings->writeEntry("/showDebug", showDebug());
959 configSettings->endGroup();
960 }
Roman Zippel43bf6122006-06-08 22:12:45 -0700961}
962
963void ConfigInfoView::setShowDebug(bool b)
964{
965 if (_showDebug != b) {
966 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +0200967 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700968 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -0700969 else if (sym)
970 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -0700971 emit showDebugChanged(b);
972 }
973}
974
975void ConfigInfoView::setInfo(struct menu *m)
976{
Alexander Stein133c5f72010-08-31 17:34:37 +0200977 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -0700978 return;
Alexander Stein133c5f72010-08-31 17:34:37 +0200979 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -0800980 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +0200981 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700982 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -0800983 else
Roman Zippel43bf6122006-06-08 22:12:45 -0700984 menuInfo();
985}
986
Roman Zippelab45d192006-06-08 22:12:47 -0700987void ConfigInfoView::symbolInfo(void)
988{
989 QString str;
990
991 str += "<big>Symbol: <b>";
992 str += print_filter(sym->name);
993 str += "</b></big><br><br>value: ";
994 str += print_filter(sym_get_string_value(sym));
995 str += "<br>visibility: ";
996 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
997 str += "<br>";
998 str += debug_info(sym);
999
1000 setText(str);
1001}
1002
Roman Zippel43bf6122006-06-08 22:12:45 -07001003void ConfigInfoView::menuInfo(void)
1004{
1005 struct symbol* sym;
1006 QString head, debug, help;
1007
Alexander Stein133c5f72010-08-31 17:34:37 +02001008 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001009 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001010 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001011 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001012 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001013 head += "</b></big>";
1014 if (sym->name) {
1015 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001016 if (showDebug())
1017 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001018 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001019 if (showDebug())
1020 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001021 head += ")";
1022 }
1023 } else if (sym->name) {
1024 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001025 if (showDebug())
1026 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001027 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001028 if (showDebug())
1029 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001030 head += "</b></big>";
1031 }
1032 head += "<br><br>";
1033
1034 if (showDebug())
1035 debug = debug_info(sym);
1036
Cheng Renquand74c15f2009-07-12 16:11:47 +08001037 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001038 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001039 help = print_filter(str_get(&help_gstr));
1040 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001041 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001042 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001043 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001044 head += "</b></big><br><br>";
1045 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001046 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001047 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001048 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001049 debug += "<br><br>";
1050 }
1051 }
1052 }
1053 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001054 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001055
1056 setText(head + debug + help);
1057}
1058
1059QString ConfigInfoView::debug_info(struct symbol *sym)
1060{
1061 QString debug;
1062
1063 debug += "type: ";
1064 debug += print_filter(sym_type_name(sym->type));
1065 if (sym_is_choice(sym))
1066 debug += " (choice)";
1067 debug += "<br>";
1068 if (sym->rev_dep.expr) {
1069 debug += "reverse dep: ";
1070 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1071 debug += "<br>";
1072 }
1073 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1074 switch (prop->type) {
1075 case P_PROMPT:
1076 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -07001077 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Roman Zippel43bf6122006-06-08 22:12:45 -07001078 debug += print_filter(_(prop->text));
Roman Zippelab45d192006-06-08 22:12:47 -07001079 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001080 break;
1081 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001082 case P_SELECT:
1083 case P_RANGE:
1084 case P_ENV:
1085 debug += prop_get_type_name(prop->type);
1086 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001087 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1088 debug += "<br>";
1089 break;
1090 case P_CHOICE:
1091 if (sym_is_choice(sym)) {
1092 debug += "choice: ";
1093 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1094 debug += "<br>";
1095 }
1096 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001097 default:
1098 debug += "unknown property: ";
1099 debug += prop_get_type_name(prop->type);
1100 debug += "<br>";
1101 }
1102 if (prop->visible.expr) {
1103 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1104 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1105 debug += "<br>";
1106 }
1107 }
1108 debug += "<br>";
1109
1110 return debug;
1111}
1112
1113QString ConfigInfoView::print_filter(const QString &str)
1114{
1115 QRegExp re("[<>&\"\\n]");
1116 QString res = str;
1117 for (int i = 0; (i = res.find(re, i)) >= 0;) {
1118 switch (res[i].latin1()) {
1119 case '<':
1120 res.replace(i, 1, "&lt;");
1121 i += 4;
1122 break;
1123 case '>':
1124 res.replace(i, 1, "&gt;");
1125 i += 4;
1126 break;
1127 case '&':
1128 res.replace(i, 1, "&amp;");
1129 i += 5;
1130 break;
1131 case '"':
1132 res.replace(i, 1, "&quot;");
1133 i += 6;
1134 break;
1135 case '\n':
1136 res.replace(i, 1, "<br>");
1137 i += 4;
1138 break;
1139 }
1140 }
1141 return res;
1142}
1143
Roman Zippelab45d192006-06-08 22:12:47 -07001144void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001145{
Roman Zippelab45d192006-06-08 22:12:47 -07001146 QString* text = reinterpret_cast<QString*>(data);
1147 QString str2 = print_filter(str);
1148
1149 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1150 *text += QString().sprintf("<a href=\"s%p\">", sym);
1151 *text += str2;
1152 *text += "</a>";
1153 } else
1154 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001155}
1156
Alexander Stein133c5f72010-08-31 17:34:37 +02001157Q3PopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001158{
Alexander Stein133c5f72010-08-31 17:34:37 +02001159 Q3PopupMenu* popup = Parent::createPopupMenu(pos);
1160 Q3Action* action = new Q3Action(NULL, _("Show Debug Info"), 0, popup);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001161 action->setToggleAction(TRUE);
1162 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1163 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1164 action->setOn(showDebug());
1165 popup->insertSeparator();
1166 action->addTo(popup);
1167 return popup;
1168}
1169
1170void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
1171{
1172 Parent::contentsContextMenuEvent(e);
1173}
1174
Marco Costalba63431e72006-10-05 19:12:59 +02001175ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001176 : Parent(parent, name), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001177{
1178 setCaption("Search Config");
1179
1180 QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
1181 QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001182 layout2->addWidget(new QLabel(_("Find:"), this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001183 editField = new QLineEdit(this);
1184 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1185 layout2->addWidget(editField);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001186 searchButton = new QPushButton(_("Search"), this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001187 searchButton->setAutoDefault(FALSE);
1188 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1189 layout2->addWidget(searchButton);
1190 layout1->addLayout(layout2);
1191
Roman Zippel7fc925f2006-06-08 22:12:46 -07001192 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001193 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001194 list = new ConfigView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001195 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001196 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001197 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1198 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001199 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1200 parent, SLOT(setMenuLink(struct menu *)));
1201
Roman Zippel43bf6122006-06-08 22:12:45 -07001202 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001203
1204 if (name) {
1205 int x, y, width, height;
1206 bool ok;
1207
1208 configSettings->beginGroup(name);
1209 width = configSettings->readNumEntry("/window width", parent->width() / 2);
1210 height = configSettings->readNumEntry("/window height", parent->height() / 2);
1211 resize(width, height);
1212 x = configSettings->readNumEntry("/window x", 0, &ok);
1213 if (ok)
1214 y = configSettings->readNumEntry("/window y", 0, &ok);
1215 if (ok)
1216 move(x, y);
Alexander Stein133c5f72010-08-31 17:34:37 +02001217 Q3ValueList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001218 if (ok)
1219 split->setSizes(sizes);
1220 configSettings->endGroup();
1221 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1222 }
1223}
1224
1225void ConfigSearchWindow::saveSettings(void)
1226{
1227 if (name()) {
1228 configSettings->beginGroup(name());
1229 configSettings->writeEntry("/window x", pos().x());
1230 configSettings->writeEntry("/window y", pos().y());
1231 configSettings->writeEntry("/window width", size().width());
1232 configSettings->writeEntry("/window height", size().height());
1233 configSettings->writeSizes("/split", split->sizes());
1234 configSettings->endGroup();
1235 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001236}
1237
1238void ConfigSearchWindow::search(void)
1239{
1240 struct symbol **p;
1241 struct property *prop;
1242 ConfigItem *lastItem = NULL;
1243
1244 free(result);
1245 list->list->clear();
Cyrill V. Gorcunov786fb182007-02-14 00:32:59 -08001246 info->clear();
Roman Zippel43bf6122006-06-08 22:12:45 -07001247
1248 result = sym_re_search(editField->text().latin1());
1249 if (!result)
1250 return;
1251 for (p = result; *p; p++) {
1252 for_all_prompts((*p), prop)
1253 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1254 menu_is_visible(prop->menu));
1255 }
1256}
1257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258/*
1259 * Construct the complete config widget
1260 */
1261ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001262 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
1264 QMenuBar* menu;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001265 bool ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 int x, y, width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001267 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001269 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001270 snprintf(title, sizeof(title), "%s%s",
1271 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001272 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001273 );
Randy Dunlapa54bb702007-10-20 11:18:47 -07001274 setCaption(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Roman Zippel7fc925f2006-06-08 22:12:46 -07001276 width = configSettings->readNumEntry("/window width", d->width() - 64);
1277 height = configSettings->readNumEntry("/window height", d->height() - 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 resize(width, height);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001279 x = configSettings->readNumEntry("/window x", 0, &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 if (ok)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001281 y = configSettings->readNumEntry("/window y", 0, &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 if (ok)
1283 move(x, y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001286 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 setCentralWidget(split1);
1288
Roman Zippel7fc925f2006-06-08 22:12:46 -07001289 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 menuList = menuView->list;
1291
1292 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001293 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
1295 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -07001296 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 configList = configView->list;
1298
Roman Zippel7fc925f2006-06-08 22:12:46 -07001299 helpText = new ConfigInfoView(split2, "help");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 helpText->setTextFormat(Qt::RichText);
1301
1302 setTabOrder(configList, helpText);
1303 configList->setFocus();
1304
1305 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001306 toolBar = new QToolBar("Tools", this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Alexander Stein133c5f72010-08-31 17:34:37 +02001308 backAction = new Q3Action("Back", QPixmap(xpm_back), _("Back"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 connect(backAction, SIGNAL(activated()), SLOT(goBack()));
1310 backAction->setEnabled(FALSE);
Alexander Stein133c5f72010-08-31 17:34:37 +02001311 Q3Action *quitAction = new Q3Action("Quit", _("&Quit"), Qt::CTRL + Qt::Key_Q, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 connect(quitAction, SIGNAL(activated()), SLOT(close()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001313 Q3Action *loadAction = new Q3Action("Load", QPixmap(xpm_load), _("&Load"), Qt::CTRL + Qt::Key_L, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001315 saveAction = new Q3Action("Save", QPixmap(xpm_save), _("&Save"), Qt::CTRL + Qt::Key_S, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001317 conf_set_changed_callback(conf_changed);
1318 // Set saveAction's initial state
1319 conf_changed();
Alexander Stein133c5f72010-08-31 17:34:37 +02001320 Q3Action *saveAsAction = new Q3Action("Save As...", _("Save &As..."), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001322 Q3Action *searchAction = new Q3Action("Find", _("&Find"), Qt::CTRL + Qt::Key_F, this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001323 connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001324 Q3Action *singleViewAction = new Q3Action("Single View", QPixmap(xpm_single_view), _("Single View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001326 Q3Action *splitViewAction = new Q3Action("Split View", QPixmap(xpm_split_view), _("Split View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001328 Q3Action *fullViewAction = new Q3Action("Full View", QPixmap(xpm_tree_view), _("Full View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
1330
Alexander Stein133c5f72010-08-31 17:34:37 +02001331 Q3Action *showNameAction = new Q3Action(NULL, _("Show Name"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 showNameAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001333 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
1334 connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
1335 showNameAction->setOn(configView->showName());
Alexander Stein133c5f72010-08-31 17:34:37 +02001336 Q3Action *showRangeAction = new Q3Action(NULL, _("Show Range"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 showRangeAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001338 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
1339 connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 showRangeAction->setOn(configList->showRange);
Alexander Stein133c5f72010-08-31 17:34:37 +02001341 Q3Action *showDataAction = new Q3Action(NULL, _("Show Data"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 showDataAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001343 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
1344 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 showDataAction->setOn(configList->showData);
Li Zefan39a48972010-05-10 16:33:41 +08001346
1347 QActionGroup *optGroup = new QActionGroup(this);
1348 optGroup->setExclusive(TRUE);
1349 connect(optGroup, SIGNAL(selected(QAction *)), configView,
1350 SLOT(setOptionMode(QAction *)));
1351 connect(optGroup, SIGNAL(selected(QAction *)), menuView,
1352 SLOT(setOptionMode(QAction *)));
1353
Alexander Stein133c5f72010-08-31 17:34:37 +02001354 configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
1355 configView->showAllAction = new QAction(_("Show All Options"), optGroup);
1356 configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
Li Zefan39a48972010-05-10 16:33:41 +08001357 configView->showNormalAction->setToggleAction(TRUE);
1358 configView->showNormalAction->setOn(configList->optMode == normalOpt);
1359 configView->showAllAction->setToggleAction(TRUE);
1360 configView->showAllAction->setOn(configList->optMode == allOpt);
1361 configView->showPromptAction->setToggleAction(TRUE);
1362 configView->showPromptAction->setOn(configList->optMode == promptOpt);
1363
Alexander Stein133c5f72010-08-31 17:34:37 +02001364 Q3Action *showDebugAction = new Q3Action(NULL, _("Show Debug Info"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 showDebugAction->setToggleAction(TRUE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001366 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
1367 connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
Roman Zippel7fc925f2006-06-08 22:12:46 -07001368 showDebugAction->setOn(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Alexander Stein133c5f72010-08-31 17:34:37 +02001370 Q3Action *showIntroAction = new Q3Action(NULL, _("Introduction"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001372 Q3Action *showAboutAction = new Q3Action(NULL, _("About"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
1374
1375 // init tool bar
1376 backAction->addTo(toolBar);
1377 toolBar->addSeparator();
1378 loadAction->addTo(toolBar);
1379 saveAction->addTo(toolBar);
1380 toolBar->addSeparator();
1381 singleViewAction->addTo(toolBar);
1382 splitViewAction->addTo(toolBar);
1383 fullViewAction->addTo(toolBar);
1384
1385 // create config menu
Alexander Stein133c5f72010-08-31 17:34:37 +02001386 Q3PopupMenu* config = new Q3PopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001387 menu->insertItem(_("&File"), config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 loadAction->addTo(config);
1389 saveAction->addTo(config);
1390 saveAsAction->addTo(config);
1391 config->insertSeparator();
1392 quitAction->addTo(config);
1393
Shlomi Fish66e7c722007-02-14 00:32:58 -08001394 // create edit menu
Alexander Stein133c5f72010-08-31 17:34:37 +02001395 Q3PopupMenu* editMenu = new Q3PopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001396 menu->insertItem(_("&Edit"), editMenu);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001397 searchAction->addTo(editMenu);
1398
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 // create options menu
Alexander Stein133c5f72010-08-31 17:34:37 +02001400 Q3PopupMenu* optionMenu = new Q3PopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001401 menu->insertItem(_("&Option"), optionMenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 showNameAction->addTo(optionMenu);
1403 showRangeAction->addTo(optionMenu);
1404 showDataAction->addTo(optionMenu);
1405 optionMenu->insertSeparator();
Li Zefan39a48972010-05-10 16:33:41 +08001406 optGroup->addTo(optionMenu);
1407 optionMenu->insertSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
1409 // create help menu
Alexander Stein133c5f72010-08-31 17:34:37 +02001410 Q3PopupMenu* helpMenu = new Q3PopupMenu(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 menu->insertSeparator();
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001412 menu->insertItem(_("&Help"), helpMenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 showIntroAction->addTo(helpMenu);
1414 showAboutAction->addTo(helpMenu);
1415
Roman Zippel43bf6122006-06-08 22:12:45 -07001416 connect(configList, SIGNAL(menuChanged(struct menu *)),
1417 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 connect(configList, SIGNAL(menuSelected(struct menu *)),
1419 SLOT(changeMenu(struct menu *)));
1420 connect(configList, SIGNAL(parentSelected()),
1421 SLOT(goBack()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001422 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1423 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1425 SLOT(changeMenu(struct menu *)));
1426
Roman Zippelb65a47e2006-06-08 22:12:47 -07001427 connect(configList, SIGNAL(gotFocus(struct menu *)),
1428 helpText, SLOT(setInfo(struct menu *)));
1429 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1430 helpText, SLOT(setInfo(struct menu *)));
1431 connect(menuList, SIGNAL(gotFocus(struct menu *)),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001433 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1434 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Roman Zippel7fc925f2006-06-08 22:12:46 -07001436 QString listMode = configSettings->readEntry("/listMode", "symbol");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 if (listMode == "single")
1438 showSingleView();
1439 else if (listMode == "full")
1440 showFullView();
1441 else /*if (listMode == "split")*/
1442 showSplitView();
1443
1444 // UI setup done, restore splitter positions
Alexander Stein133c5f72010-08-31 17:34:37 +02001445 Q3ValueList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 if (ok)
1447 split1->setSizes(sizes);
1448
Roman Zippel7fc925f2006-06-08 22:12:46 -07001449 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 if (ok)
1451 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452}
1453
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454void ConfigMainWindow::loadConfig(void)
1455{
Alexander Stein133c5f72010-08-31 17:34:37 +02001456 QString s = Q3FileDialog::getOpenFileName(conf_get_configname(), NULL, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 if (s.isNull())
1458 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001459 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001460 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 ConfigView::updateListAll();
1462}
1463
Michal Marekbac6aa82011-05-25 15:10:25 +02001464bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Michal Marekbac6aa82011-05-25 15:10:25 +02001466 if (conf_write(NULL)) {
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001467 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Michal Marekbac6aa82011-05-25 15:10:25 +02001468 return false;
1469 }
1470 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
1473void ConfigMainWindow::saveConfigAs(void)
1474{
Alexander Stein133c5f72010-08-31 17:34:37 +02001475 QString s = Q3FileDialog::getSaveFileName(conf_get_configname(), NULL, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 if (s.isNull())
1477 return;
Arnaud Lacombed49e4682011-05-24 14:16:18 -04001478 saveConfig();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Roman Zippel43bf6122006-06-08 22:12:45 -07001481void ConfigMainWindow::searchConfig(void)
1482{
1483 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001484 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001485 searchWindow->show();
1486}
1487
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488void ConfigMainWindow::changeMenu(struct menu *menu)
1489{
1490 configList->setRootMenu(menu);
Cyrill V. Gorcunovf253f002007-02-14 00:33:00 -08001491 if (configList->rootEntry->parent == &rootmenu)
1492 backAction->setEnabled(FALSE);
1493 else
1494 backAction->setEnabled(TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495}
1496
Roman Zippelb65a47e2006-06-08 22:12:47 -07001497void ConfigMainWindow::setMenuLink(struct menu *menu)
1498{
1499 struct menu *parent;
1500 ConfigList* list = NULL;
1501 ConfigItem* item;
1502
Li Zefan39a48972010-05-10 16:33:41 +08001503 if (configList->menuSkip(menu))
Roman Zippelb65a47e2006-06-08 22:12:47 -07001504 return;
1505
1506 switch (configList->mode) {
1507 case singleMode:
1508 list = configList;
1509 parent = menu_get_parent_menu(menu);
1510 if (!parent)
1511 return;
1512 list->setRootMenu(parent);
1513 break;
1514 case symbolMode:
1515 if (menu->flags & MENU_ROOT) {
1516 configList->setRootMenu(menu);
1517 configList->clearSelection();
1518 list = menuList;
1519 } else {
1520 list = configList;
1521 parent = menu_get_parent_menu(menu->parent);
1522 if (!parent)
1523 return;
1524 item = menuList->findConfigItem(parent);
1525 if (item) {
1526 menuList->setSelected(item, TRUE);
1527 menuList->ensureItemVisible(item);
1528 }
1529 list->setRootMenu(parent);
1530 }
1531 break;
1532 case fullMode:
1533 list = configList;
1534 break;
Markus Heidelberg98403a92009-05-18 01:36:49 +02001535 default:
1536 break;
Roman Zippelb65a47e2006-06-08 22:12:47 -07001537 }
1538
1539 if (list) {
1540 item = list->findConfigItem(menu);
1541 if (item) {
1542 list->setSelected(item, TRUE);
1543 list->ensureItemVisible(item);
1544 list->setFocus();
1545 }
1546 }
1547}
1548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549void ConfigMainWindow::listFocusChanged(void)
1550{
Roman Zippelb65a47e2006-06-08 22:12:47 -07001551 if (menuList->mode == menuMode)
1552 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
1555void ConfigMainWindow::goBack(void)
1556{
1557 ConfigItem* item;
1558
1559 configList->setParentMenu();
1560 if (configList->rootEntry == &rootmenu)
1561 backAction->setEnabled(FALSE);
1562 item = (ConfigItem*)menuList->selectedItem();
1563 while (item) {
1564 if (item->menu == configList->rootEntry) {
1565 menuList->setSelected(item, TRUE);
1566 break;
1567 }
1568 item = (ConfigItem*)item->parent();
1569 }
1570}
1571
1572void ConfigMainWindow::showSingleView(void)
1573{
1574 menuView->hide();
1575 menuList->setRootMenu(0);
1576 configList->mode = singleMode;
1577 if (configList->rootEntry == &rootmenu)
1578 configList->updateListAll();
1579 else
1580 configList->setRootMenu(&rootmenu);
1581 configList->setAllOpen(TRUE);
1582 configList->setFocus();
1583}
1584
1585void ConfigMainWindow::showSplitView(void)
1586{
1587 configList->mode = symbolMode;
1588 if (configList->rootEntry == &rootmenu)
1589 configList->updateListAll();
1590 else
1591 configList->setRootMenu(&rootmenu);
1592 configList->setAllOpen(TRUE);
1593 configApp->processEvents();
1594 menuList->mode = menuMode;
1595 menuList->setRootMenu(&rootmenu);
1596 menuList->setAllOpen(TRUE);
1597 menuView->show();
1598 menuList->setFocus();
1599}
1600
1601void ConfigMainWindow::showFullView(void)
1602{
1603 menuView->hide();
1604 menuList->setRootMenu(0);
1605 configList->mode = fullMode;
1606 if (configList->rootEntry == &rootmenu)
1607 configList->updateListAll();
1608 else
1609 configList->setRootMenu(&rootmenu);
1610 configList->setAllOpen(FALSE);
1611 configList->setFocus();
1612}
1613
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614/*
1615 * ask for saving configuration before quitting
1616 * TODO ask only when something changed
1617 */
1618void ConfigMainWindow::closeEvent(QCloseEvent* e)
1619{
Karsten Wieseb3214292006-12-13 00:34:06 -08001620 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 e->accept();
1622 return;
1623 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001624 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001626 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1627 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1628 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 switch (mb.exec()) {
1630 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001631 if (saveConfig())
1632 e->accept();
1633 else
1634 e->ignore();
1635 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 case QMessageBox::No:
1637 e->accept();
1638 break;
1639 case QMessageBox::Cancel:
1640 e->ignore();
1641 break;
1642 }
1643}
1644
1645void ConfigMainWindow::showIntro(void)
1646{
Arnaud Lacombe652cf982010-08-14 23:51:40 -04001647 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 "For each option, a blank box indicates the feature is disabled, a check\n"
1649 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1650 "as a module. Clicking on the box will cycle through the three states.\n\n"
1651 "If you do not see an option (e.g., a device driver) that you believe\n"
1652 "should be present, try turning on Show All Options under the Options menu.\n"
1653 "Although there is no cross reference yet to help you figure out what other\n"
1654 "options must be enabled to support the option you are interested in, you can\n"
1655 "still view the help of a grayed-out option.\n\n"
1656 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001657 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 QMessageBox::information(this, "qconf", str);
1660}
1661
1662void ConfigMainWindow::showAbout(void)
1663{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001664 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1665 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 QMessageBox::information(this, "qconf", str);
1668}
1669
1670void ConfigMainWindow::saveSettings(void)
1671{
Roman Zippel7fc925f2006-06-08 22:12:46 -07001672 configSettings->writeEntry("/window x", pos().x());
1673 configSettings->writeEntry("/window y", pos().y());
1674 configSettings->writeEntry("/window width", size().width());
1675 configSettings->writeEntry("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
1677 QString entry;
1678 switch(configList->mode) {
1679 case singleMode :
1680 entry = "single";
1681 break;
1682
1683 case symbolMode :
1684 entry = "split";
1685 break;
1686
1687 case fullMode :
1688 entry = "full";
1689 break;
Markus Heidelberg98403a92009-05-18 01:36:49 +02001690
1691 default:
1692 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 }
Roman Zippel7fc925f2006-06-08 22:12:46 -07001694 configSettings->writeEntry("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Roman Zippel7fc925f2006-06-08 22:12:46 -07001696 configSettings->writeSizes("/split1", split1->sizes());
1697 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698}
1699
Karsten Wiese3b354c52006-12-13 00:34:08 -08001700void ConfigMainWindow::conf_changed(void)
1701{
1702 if (saveAction)
1703 saveAction->setEnabled(conf_get_changed());
1704}
1705
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706void fixup_rootmenu(struct menu *menu)
1707{
1708 struct menu *child;
1709 static int menu_cnt = 0;
1710
1711 menu->flags |= MENU_ROOT;
1712 for (child = menu->list; child; child = child->next) {
1713 if (child->prompt && child->prompt->type == P_MENU) {
1714 menu_cnt++;
1715 fixup_rootmenu(child);
1716 menu_cnt--;
1717 } else if (!menu_cnt)
1718 fixup_rootmenu(child);
1719 }
1720}
1721
1722static const char *progname;
1723
1724static void usage(void)
1725{
Michal Marek0a1f00a2015-04-08 13:30:42 +02001726 printf(_("%s [-s] <config>\n"), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 exit(0);
1728}
1729
1730int main(int ac, char** av)
1731{
1732 ConfigMainWindow* v;
1733 const char *name;
1734
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001735 bindtextdomain(PACKAGE, LOCALEDIR);
1736 textdomain(PACKAGE);
1737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 progname = av[0];
1739 configApp = new QApplication(ac, av);
1740 if (ac > 1 && av[1][0] == '-') {
1741 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001742 case 's':
1743 conf_set_message_callback(NULL);
1744 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 case 'h':
1746 case '?':
1747 usage();
1748 }
1749 name = av[2];
1750 } else
1751 name = av[1];
1752 if (!name)
1753 usage();
1754
1755 conf_parse(name);
1756 fixup_rootmenu(&rootmenu);
1757 conf_read(NULL);
1758 //zconfdump(stdout);
1759
Roman Zippel7fc925f2006-06-08 22:12:46 -07001760 configSettings = new ConfigSettings();
1761 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 v = new ConfigMainWindow();
1763
1764 //zconfdump(stdout);
Roman Zippel43bf6122006-06-08 22:12:45 -07001765 configApp->setMainWidget(v);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1767 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001768 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 configApp->exec();
1770
Roman Zippel7fc925f2006-06-08 22:12:46 -07001771 configSettings->endGroup();
1772 delete configSettings;
1773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 return 0;
1775}