blob: 10fe15d9aca6b78f3403befa931b0c29ef63d89f [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>
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07009#include <QList>
Boris Barbulovski924bbb52015-09-22 11:36:06 -070010#include <qtextbrowser.h>
Boris Barbulovski85eaf282015-09-22 11:36:03 -070011#include <QAction>
Boris Barbulovskibea00772015-09-22 11:36:04 -070012#include <QFileDialog>
Boris Barbulovski76bede82015-09-22 11:36:07 -070013#include <QMenu>
Alexander Stein133c5f72010-08-31 17:34:37 +020014
15#include <qapplication.h>
Markus Heidelberg8d90c972009-05-18 01:36:52 +020016#include <qdesktopwidget.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <qtoolbar.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070018#include <qlayout.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <qsplitter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <qlineedit.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070021#include <qlabel.h>
22#include <qpushbutton.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <qmenubar.h>
24#include <qmessagebox.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <qregexp.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020026#include <qevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <stdlib.h>
29
30#include "lkc.h"
31#include "qconf.h"
32
33#include "qconf.moc"
34#include "images.c"
35
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070036#ifdef _
37# undef _
38# define _ qgettext
39#endif
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070042static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Boris Barbulovski85eaf282015-09-22 11:36:03 -070044QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080045
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070046static inline QString qgettext(const char* str)
47{
Roman Zippel43bf6122006-06-08 22:12:45 -070048 return QString::fromLocal8Bit(gettext(str));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070049}
50
51static inline QString qgettext(const QString& str)
52{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070053 return QString::fromLocal8Bit(gettext(str.toLatin1()));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070054}
55
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010056ConfigSettings::ConfigSettings()
57 : QSettings("kernel.org", "qconf")
58{
59}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/**
62 * Reads a list of integer values from the application settings.
63 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070064QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070066 QList<int> result;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070067 QStringList entryList = value(key).toStringList();
Li Zefanc1f96f02010-05-07 13:58:04 +080068 QStringList::Iterator it;
69
70 for (it = entryList.begin(); it != entryList.end(); ++it)
71 result.push_back((*it).toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 return result;
74}
75
76/**
77 * Writes a list of integer values to the application settings.
78 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070079bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070082 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 for (it = value.begin(); it != value.end(); ++it)
85 stringList.push_back(QString::number(*it));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070086 setValue(key, stringList);
Boris Barbulovski59e56442015-09-22 11:36:18 -070087
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070088 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Boris Barbulovski59e56442015-09-22 11:36:18 -070091
92/*
93 * set the new data
94 * TODO check the value
95 */
96void ConfigItem::okRename(int col)
97{
98}
99
100/*
101 * update the displayed of a menu entry
102 */
103void ConfigItem::updateMenu(void)
104{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700105 ConfigList* list;
106 struct symbol* sym;
107 struct property *prop;
108 QString prompt;
109 int type;
110 tristate expr;
111
112 list = listView();
113 if (goParent) {
114 setPixmap(promptColIdx, list->menuBackPix);
115 prompt = "..";
116 goto set_prompt;
117 }
118
119 sym = menu->sym;
120 prop = menu->prompt;
121 prompt = _(menu_get_prompt(menu));
122
123 if (prop) switch (prop->type) {
124 case P_MENU:
125 if (list->mode == singleMode || list->mode == symbolMode) {
126 /* a menuconfig entry is displayed differently
127 * depending whether it's at the view root or a child.
128 */
129 if (sym && list->rootEntry == menu)
130 break;
131 setPixmap(promptColIdx, list->menuPix);
132 } else {
133 if (sym)
134 break;
135 setPixmap(promptColIdx, QIcon());
136 }
137 goto set_prompt;
138 case P_COMMENT:
139 setPixmap(promptColIdx, QIcon());
140 goto set_prompt;
141 default:
142 ;
143 }
144 if (!sym)
145 goto set_prompt;
146
147 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
148
149 type = sym_get_type(sym);
150 switch (type) {
151 case S_BOOLEAN:
152 case S_TRISTATE:
153 char ch;
154
155 if (!sym_is_changable(sym) && list->optMode == normalOpt) {
156 setPixmap(promptColIdx, QIcon());
157 setText(noColIdx, QString::null);
158 setText(modColIdx, QString::null);
159 setText(yesColIdx, QString::null);
160 break;
161 }
162 expr = sym_get_tristate_value(sym);
163 switch (expr) {
164 case yes:
165 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
166 setPixmap(promptColIdx, list->choiceYesPix);
167 else
168 setPixmap(promptColIdx, list->symbolYesPix);
169 setText(yesColIdx, "Y");
170 ch = 'Y';
171 break;
172 case mod:
173 setPixmap(promptColIdx, list->symbolModPix);
174 setText(modColIdx, "M");
175 ch = 'M';
176 break;
177 default:
178 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
179 setPixmap(promptColIdx, list->choiceNoPix);
180 else
181 setPixmap(promptColIdx, list->symbolNoPix);
182 setText(noColIdx, "N");
183 ch = 'N';
184 break;
185 }
186 if (expr != no)
187 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
188 if (expr != mod)
189 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
190 if (expr != yes)
191 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
192
193 setText(dataColIdx, QChar(ch));
194 break;
195 case S_INT:
196 case S_HEX:
197 case S_STRING:
198 const char* data;
199
200 data = sym_get_string_value(sym);
201
202 //int i = list->mapIdx(dataColIdx);
203 //if (i >= 0)
204 // setRenameEnabled(i, true);
205 setText(dataColIdx, data);
206 if (type == S_STRING)
207 prompt = QString("%1: %2").arg(prompt).arg(data);
208 else
209 prompt = QString("(%2) %1").arg(prompt).arg(data);
210 break;
211 }
212 if (!sym_has_value(sym) && visible)
213 prompt += _(" (NEW)");
214set_prompt:
215 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700216}
217
218void ConfigItem::testUpdateMenu(bool v)
219{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700220 ConfigItem* i;
221
222 visible = v;
223 if (!menu)
224 return;
225
226 sym_calc_value(menu->sym);
227 if (menu->flags & MENU_CHANGED) {
228 /* the menu entry changed, so update all list items */
229 menu->flags &= ~MENU_CHANGED;
230 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
231 i->updateMenu();
232 } else if (listView()->updateAll)
233 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700234}
235
236
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700237/*
238 * construct a menu entry
239 */
240void ConfigItem::init(void)
241{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700242 if (menu) {
243 ConfigList* list = listView();
244 nextItem = (ConfigItem*)menu->data;
245 menu->data = this;
246
247 if (list->mode != fullMode)
248 setExpanded(true);
249 sym_calc_value(menu->sym);
250 }
251 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700252}
253
254/*
255 * destruct a menu entry
256 */
257ConfigItem::~ConfigItem(void)
258{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700259 if (menu) {
260 ConfigItem** ip = (ConfigItem**)&menu->data;
261 for (; *ip; ip = &(*ip)->nextItem) {
262 if (*ip == this) {
263 *ip = nextItem;
264 break;
265 }
266 }
267 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700268}
269
Roman Zippel43bf6122006-06-08 22:12:45 -0700270ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
271 : Parent(parent)
272{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700273 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700274}
275
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700276void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700279 if (sym_get_string_value(item->menu->sym))
280 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
281 else
282 setText(QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 Parent::show();
284 setFocus();
285}
286
287void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
288{
289 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200290 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200292 case Qt::Key_Return:
293 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700294 sym_set_string_value(item->menu->sym, text().toLatin1());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 parent()->updateList(item);
296 break;
297 default:
298 Parent::keyPressEvent(e);
299 return;
300 }
301 e->accept();
302 parent()->list->setFocus();
303 hide();
304}
305
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700306ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700307 : Parent(p),
308 updateAll(false),
309 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
310 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
311 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700312 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700313 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700314{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700315 int i;
316
317 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700318 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700319 setRootIsDecorated(true);
320
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700321 setVerticalScrollMode(ScrollPerPixel);
322 setHorizontalScrollMode(ScrollPerPixel);
323
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700324 setHeaderLabels(QStringList() << _("Option") << _("Name") << "N" << "M" << "Y" << _("Value"));
325
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700326 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700327 SLOT(updateSelection(void)));
328
329 if (name) {
330 configSettings->beginGroup(name);
331 showName = configSettings->value("/showName", false).toBool();
332 showRange = configSettings->value("/showRange", false).toBool();
333 showData = configSettings->value("/showData", false).toBool();
334 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
335 configSettings->endGroup();
336 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
337 }
338
339 addColumn(promptColIdx);
340
341 reinit();
342}
343
344bool ConfigList::menuSkip(struct menu *menu)
345{
346 if (optMode == normalOpt && menu_is_visible(menu))
347 return false;
348 if (optMode == promptOpt && menu_has_prompt(menu))
349 return false;
350 if (optMode == allOpt)
351 return false;
352 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700353}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700354
355void ConfigList::reinit(void)
356{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700357 removeColumn(dataColIdx);
358 removeColumn(yesColIdx);
359 removeColumn(modColIdx);
360 removeColumn(noColIdx);
361 removeColumn(nameColIdx);
362
363 if (showName)
364 addColumn(nameColIdx);
365 if (showRange) {
366 addColumn(noColIdx);
367 addColumn(modColIdx);
368 addColumn(yesColIdx);
369 }
370 if (showData)
371 addColumn(dataColIdx);
372
373 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700374}
375
376void ConfigList::saveSettings(void)
377{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700378 if (!objectName().isEmpty()) {
379 configSettings->beginGroup(objectName());
380 configSettings->setValue("/showName", showName);
381 configSettings->setValue("/showRange", showRange);
382 configSettings->setValue("/showData", showData);
383 configSettings->setValue("/optionMode", (int)optMode);
384 configSettings->endGroup();
385 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700386}
387
388ConfigItem* ConfigList::findConfigItem(struct menu *menu)
389{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700390 ConfigItem* item = (ConfigItem*)menu->data;
391
392 for (; item; item = item->nextItem) {
393 if (this == item->listView())
394 break;
395 }
396
397 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700398}
399
400void ConfigList::updateSelection(void)
401{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700402 struct menu *menu;
403 enum prop_type type;
404
405 ConfigItem* item = (ConfigItem*)selectedItems().first();
406 if (!item)
407 return;
408
409 menu = item->menu;
410 emit menuChanged(menu);
411 if (!menu)
412 return;
413 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
414 if (mode == menuMode && type == P_MENU)
415 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700416}
417
418void ConfigList::updateList(ConfigItem* item)
419{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700420 ConfigItem* last = 0;
421
422 if (!rootEntry) {
423 if (mode != listMode)
424 goto update;
425 QTreeWidgetItemIterator it(this);
426 ConfigItem* item;
427
428 while (*it) {
429 item = (ConfigItem*)(*it);
430 if (!item->menu)
431 continue;
432 item->testUpdateMenu(menu_is_visible(item->menu));
433
434 ++it;
435 }
436 return;
437 }
438
439 if (rootEntry != &rootmenu && (mode == singleMode ||
440 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
441 item = firstChild();
442 if (!item)
443 item = new ConfigItem(this, 0, true);
444 last = item;
445 }
446 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
447 rootEntry->sym && rootEntry->prompt) {
448 item = last ? last->nextSibling() : firstChild();
449 if (!item)
450 item = new ConfigItem(this, last, rootEntry, true);
451 else
452 item->testUpdateMenu(true);
453
454 updateMenuList(item, rootEntry);
455 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700456 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700457 return;
458 }
459update:
460 updateMenuList(this, rootEntry);
461 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700462 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700463}
464
465void ConfigList::setValue(ConfigItem* item, tristate val)
466{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700467 struct symbol* sym;
468 int type;
469 tristate oldval;
470
471 sym = item->menu ? item->menu->sym : 0;
472 if (!sym)
473 return;
474
475 type = sym_get_type(sym);
476 switch (type) {
477 case S_BOOLEAN:
478 case S_TRISTATE:
479 oldval = sym_get_tristate_value(sym);
480
481 if (!sym_set_tristate_value(sym, val))
482 return;
483 if (oldval == no && item->menu->list)
484 item->setExpanded(true);
485 parent()->updateList(item);
486 break;
487 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700488}
489
490void ConfigList::changeValue(ConfigItem* item)
491{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700492 struct symbol* sym;
493 struct menu* menu;
494 int type, oldexpr, newexpr;
495
496 menu = item->menu;
497 if (!menu)
498 return;
499 sym = menu->sym;
500 if (!sym) {
501 if (item->menu->list)
502 item->setExpanded(!item->isExpanded());
503 return;
504 }
505
506 type = sym_get_type(sym);
507 switch (type) {
508 case S_BOOLEAN:
509 case S_TRISTATE:
510 oldexpr = sym_get_tristate_value(sym);
511 newexpr = sym_toggle_tristate_value(sym);
512 if (item->menu->list) {
513 if (oldexpr == newexpr)
514 item->setExpanded(!item->isExpanded());
515 else if (oldexpr == no)
516 item->setExpanded(true);
517 }
518 if (oldexpr != newexpr)
519 parent()->updateList(item);
520 break;
521 case S_INT:
522 case S_HEX:
523 case S_STRING:
524 break;
525 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700526}
527
528void ConfigList::setRootMenu(struct menu *menu)
529{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700530 enum prop_type type;
531
532 if (rootEntry == menu)
533 return;
534 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
535 if (type != P_MENU)
536 return;
537 updateMenuList(this, 0);
538 rootEntry = menu;
539 updateListAll();
540 if (currentItem()) {
541 currentItem()->setSelected(hasFocus());
542 scrollToItem(currentItem());
543 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700544}
545
546void ConfigList::setParentMenu(void)
547{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700548 ConfigItem* item;
549 struct menu *oldroot;
550
551 oldroot = rootEntry;
552 if (rootEntry == &rootmenu)
553 return;
554 setRootMenu(menu_get_parent_menu(rootEntry->parent));
555
556 QTreeWidgetItemIterator it(this);
557 while (*it) {
558 item = (ConfigItem *)(*it);
559 if (item->menu == oldroot) {
560 setCurrentItem(item);
561 scrollToItem(item);
562 break;
563 }
564
565 ++it;
566 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700567}
568
569/*
570 * update all the children of a menu entry
571 * removes/adds the entries from the parent widget as necessary
572 *
573 * parent: either the menu list widget or a menu entry widget
574 * menu: entry to be updated
575 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700576void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700577{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700578 struct menu* child;
579 ConfigItem* item;
580 ConfigItem* last;
581 bool visible;
582 enum prop_type type;
583
584 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700585 while (parent->childCount() > 0)
586 {
587 delete parent->takeChild(0);
588 }
589
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700590 return;
591 }
592
593 last = parent->firstChild();
594 if (last && !last->goParent)
595 last = 0;
596 for (child = menu->list; child; child = child->next) {
597 item = last ? last->nextSibling() : parent->firstChild();
598 type = child->prompt ? child->prompt->type : P_UNKNOWN;
599
600 switch (mode) {
601 case menuMode:
602 if (!(child->flags & MENU_ROOT))
603 goto hide;
604 break;
605 case symbolMode:
606 if (child->flags & MENU_ROOT)
607 goto hide;
608 break;
609 default:
610 break;
611 }
612
613 visible = menu_is_visible(child);
614 if (!menuSkip(child)) {
615 if (!child->sym && !child->list && !child->prompt)
616 continue;
617 if (!item || item->menu != child)
618 item = new ConfigItem(parent, last, child, visible);
619 else
620 item->testUpdateMenu(visible);
621
622 if (mode == fullMode || mode == menuMode || type != P_MENU)
623 updateMenuList(item, child);
624 else
625 updateMenuList(item, 0);
626 last = item;
627 continue;
628 }
629 hide:
630 if (item && item->menu == child) {
631 last = parent->firstChild();
632 if (last == item)
633 last = 0;
634 else while (last->nextSibling() != item)
635 last = last->nextSibling();
636 delete item;
637 }
638 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700639}
640
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700641void ConfigList::updateMenuList(ConfigList *parent, struct menu* menu)
642{
643 struct menu* child;
644 ConfigItem* item;
645 ConfigItem* last;
646 bool visible;
647 enum prop_type type;
648
649 if (!menu) {
650 while (parent->topLevelItemCount() > 0)
651 {
652 delete parent->takeTopLevelItem(0);
653 }
654
655 return;
656 }
657
658 last = (ConfigItem*)parent->topLevelItem(0);
659 if (last && !last->goParent)
660 last = 0;
661 for (child = menu->list; child; child = child->next) {
662 item = last ? last->nextSibling() : (ConfigItem*)parent->topLevelItem(0);
663 type = child->prompt ? child->prompt->type : P_UNKNOWN;
664
665 switch (mode) {
666 case menuMode:
667 if (!(child->flags & MENU_ROOT))
668 goto hide;
669 break;
670 case symbolMode:
671 if (child->flags & MENU_ROOT)
672 goto hide;
673 break;
674 default:
675 break;
676 }
677
678 visible = menu_is_visible(child);
679 if (!menuSkip(child)) {
680 if (!child->sym && !child->list && !child->prompt)
681 continue;
682 if (!item || item->menu != child)
683 item = new ConfigItem(parent, last, child, visible);
684 else
685 item->testUpdateMenu(visible);
686
687 if (mode == fullMode || mode == menuMode || type != P_MENU)
688 updateMenuList(item, child);
689 else
690 updateMenuList(item, 0);
691 last = item;
692 continue;
693 }
694 hide:
695 if (item && item->menu == child) {
696 last = (ConfigItem*)parent->topLevelItem(0);
697 if (last == item)
698 last = 0;
699 else while (last->nextSibling() != item)
700 last = last->nextSibling();
701 delete item;
702 }
703 }
704}
705
Boris Barbulovski59e56442015-09-22 11:36:18 -0700706void ConfigList::keyPressEvent(QKeyEvent* ev)
707{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700708 QTreeWidgetItem* i = currentItem();
709 ConfigItem* item;
710 struct menu *menu;
711 enum prop_type type;
712
713 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
714 emit parentSelected();
715 ev->accept();
716 return;
717 }
718
719 if (!i) {
720 Parent::keyPressEvent(ev);
721 return;
722 }
723 item = (ConfigItem*)i;
724
725 switch (ev->key()) {
726 case Qt::Key_Return:
727 case Qt::Key_Enter:
728 if (item->goParent) {
729 emit parentSelected();
730 break;
731 }
732 menu = item->menu;
733 if (!menu)
734 break;
735 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
736 if (type == P_MENU && rootEntry != menu &&
737 mode != fullMode && mode != menuMode) {
738 emit menuSelected(menu);
739 break;
740 }
741 case Qt::Key_Space:
742 changeValue(item);
743 break;
744 case Qt::Key_N:
745 setValue(item, no);
746 break;
747 case Qt::Key_M:
748 setValue(item, mod);
749 break;
750 case Qt::Key_Y:
751 setValue(item, yes);
752 break;
753 default:
754 Parent::keyPressEvent(ev);
755 return;
756 }
757 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700758}
759
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700760void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700761{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700762 //QPoint p(contentsToViewport(e->pos()));
763 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
764 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700765}
766
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700767void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700768{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700769 QPoint p = e->pos();
770 ConfigItem* item = (ConfigItem*)itemAt(p);
771 struct menu *menu;
772 enum prop_type ptype;
773 QIcon icon;
774 int idx, x;
775
776 if (!item)
777 goto skip;
778
779 menu = item->menu;
780 x = header()->offset() + p.x();
781 idx = header()->sectionPosition(x);
782 switch (idx) {
783 case promptColIdx:
784 icon = item->pixmap(promptColIdx);
785 break;
786 case noColIdx:
787 setValue(item, no);
788 break;
789 case modColIdx:
790 setValue(item, mod);
791 break;
792 case yesColIdx:
793 setValue(item, yes);
794 break;
795 case dataColIdx:
796 changeValue(item);
797 break;
798 }
799
800skip:
801 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
802 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700803}
804
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700805void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700806{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700807 //QPoint p(contentsToViewport(e->pos()));
808 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
809 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700810}
811
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700812void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700813{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700814 QPoint p = e->pos(); // TODO: Check if this works(was contentsToViewport).
815 ConfigItem* item = (ConfigItem*)itemAt(p);
816 struct menu *menu;
817 enum prop_type ptype;
818
819 if (!item)
820 goto skip;
821 if (item->goParent) {
822 emit parentSelected();
823 goto skip;
824 }
825 menu = item->menu;
826 if (!menu)
827 goto skip;
828 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
829 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
830 emit menuSelected(menu);
831 else if (menu->sym)
832 changeValue(item);
833
834skip:
835 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
836 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700837}
838
839void ConfigList::focusInEvent(QFocusEvent *e)
840{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700841 struct menu *menu = NULL;
842
843 Parent::focusInEvent(e);
844
845 ConfigItem* item = (ConfigItem *)currentItem();
846 if (item) {
847 item->setSelected(true);
848 menu = item->menu;
849 }
850 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700851}
852
853void ConfigList::contextMenuEvent(QContextMenuEvent *e)
854{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700855 if (e->y() <= header()->geometry().bottom()) {
856 if (!headerPopup) {
857 QAction *action;
858
859 headerPopup = new QMenu(this);
860 action = new QAction(_("Show Name"), this);
861 action->setCheckable(true);
862 connect(action, SIGNAL(toggled(bool)),
863 parent(), SLOT(setShowName(bool)));
864 connect(parent(), SIGNAL(showNameChanged(bool)),
865 action, SLOT(setOn(bool)));
866 action->setChecked(showName);
867 headerPopup->addAction(action);
868 action = new QAction(_("Show Range"), this);
869 action->setCheckable(true);
870 connect(action, SIGNAL(toggled(bool)),
871 parent(), SLOT(setShowRange(bool)));
872 connect(parent(), SIGNAL(showRangeChanged(bool)),
873 action, SLOT(setOn(bool)));
874 action->setChecked(showRange);
875 headerPopup->addAction(action);
876 action = new QAction(_("Show Data"), this);
877 action->setCheckable(true);
878 connect(action, SIGNAL(toggled(bool)),
879 parent(), SLOT(setShowData(bool)));
880 connect(parent(), SIGNAL(showDataChanged(bool)),
881 action, SLOT(setOn(bool)));
882 action->setChecked(showData);
883 headerPopup->addAction(action);
884 }
885 headerPopup->exec(e->globalPos());
886 e->accept();
887 } else
888 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700889}
890
Li Zefan39a48972010-05-10 16:33:41 +0800891ConfigView*ConfigView::viewList;
892QAction *ConfigView::showNormalAction;
893QAction *ConfigView::showAllAction;
894QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Roman Zippel7fc925f2006-06-08 22:12:46 -0700896ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700897 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700899 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700900 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700901 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700902
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700903 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700904 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 lineEdit = new ConfigLineEdit(this);
906 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700907 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 this->nextView = viewList;
910 viewList = this;
911}
912
913ConfigView::~ConfigView(void)
914{
915 ConfigView** vp;
916
917 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
918 if (*vp == this) {
919 *vp = nextView;
920 break;
921 }
922 }
923}
924
Li Zefan39a48972010-05-10 16:33:41 +0800925void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700926{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700927 if (act == showNormalAction)
928 list->optMode = normalOpt;
929 else if (act == showAllAction)
930 list->optMode = allOpt;
931 else
932 list->optMode = promptOpt;
933
934 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700935}
936
937void ConfigView::setShowName(bool b)
938{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700939 if (list->showName != b) {
940 list->showName = b;
941 list->reinit();
942 emit showNameChanged(b);
943 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700944}
945
946void ConfigView::setShowRange(bool b)
947{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700948 if (list->showRange != b) {
949 list->showRange = b;
950 list->reinit();
951 emit showRangeChanged(b);
952 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700953}
954
955void ConfigView::setShowData(bool b)
956{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700957 if (list->showData != b) {
958 list->showData = b;
959 list->reinit();
960 emit showDataChanged(b);
961 }
962}
963
964void ConfigList::setAllOpen(bool open)
965{
966 QTreeWidgetItemIterator it(this);
967
968 while (*it) {
969 (*it)->setExpanded(open);
970
971 ++it;
972 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700973}
974
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700975void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700976{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700977 ConfigView* v;
978
979 for (v = viewList; v; v = v->nextView)
980 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981}
982
983void ConfigView::updateListAll(void)
984{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700985 ConfigView* v;
986
987 for (v = viewList; v; v = v->nextView)
988 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
Roman Zippel43bf6122006-06-08 22:12:45 -0700991ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700992 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700993{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700994 setObjectName(name);
995
996
997 if (!objectName().isEmpty()) {
998 configSettings->beginGroup(objectName());
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700999 _showDebug = configSettings->value("/showDebug", false).toBool();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001000 configSettings->endGroup();
1001 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1002 }
1003}
1004
1005void ConfigInfoView::saveSettings(void)
1006{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001007 if (!objectName().isEmpty()) {
1008 configSettings->beginGroup(objectName());
1009 configSettings->setValue("/showDebug", showDebug());
1010 configSettings->endGroup();
1011 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001012}
1013
1014void ConfigInfoView::setShowDebug(bool b)
1015{
1016 if (_showDebug != b) {
1017 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001018 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001019 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001020 else if (sym)
1021 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001022 emit showDebugChanged(b);
1023 }
1024}
1025
1026void ConfigInfoView::setInfo(struct menu *m)
1027{
Alexander Stein133c5f72010-08-31 17:34:37 +02001028 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001029 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001030 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001031 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001032 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001033 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001034 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001035 menuInfo();
1036}
1037
Roman Zippelab45d192006-06-08 22:12:47 -07001038void ConfigInfoView::symbolInfo(void)
1039{
1040 QString str;
1041
1042 str += "<big>Symbol: <b>";
1043 str += print_filter(sym->name);
1044 str += "</b></big><br><br>value: ";
1045 str += print_filter(sym_get_string_value(sym));
1046 str += "<br>visibility: ";
1047 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1048 str += "<br>";
1049 str += debug_info(sym);
1050
1051 setText(str);
1052}
1053
Roman Zippel43bf6122006-06-08 22:12:45 -07001054void ConfigInfoView::menuInfo(void)
1055{
1056 struct symbol* sym;
1057 QString head, debug, help;
1058
Alexander Stein133c5f72010-08-31 17:34:37 +02001059 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001060 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001061 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001062 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001063 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001064 head += "</b></big>";
1065 if (sym->name) {
1066 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001067 if (showDebug())
1068 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001069 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001070 if (showDebug())
1071 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001072 head += ")";
1073 }
1074 } else if (sym->name) {
1075 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001076 if (showDebug())
1077 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001078 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001079 if (showDebug())
1080 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001081 head += "</b></big>";
1082 }
1083 head += "<br><br>";
1084
1085 if (showDebug())
1086 debug = debug_info(sym);
1087
Cheng Renquand74c15f2009-07-12 16:11:47 +08001088 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001089 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001090 help = print_filter(str_get(&help_gstr));
1091 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001092 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001093 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001094 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001095 head += "</b></big><br><br>";
1096 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001097 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001098 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001099 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001100 debug += "<br><br>";
1101 }
1102 }
1103 }
1104 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001105 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001106
1107 setText(head + debug + help);
1108}
1109
1110QString ConfigInfoView::debug_info(struct symbol *sym)
1111{
1112 QString debug;
1113
1114 debug += "type: ";
1115 debug += print_filter(sym_type_name(sym->type));
1116 if (sym_is_choice(sym))
1117 debug += " (choice)";
1118 debug += "<br>";
1119 if (sym->rev_dep.expr) {
1120 debug += "reverse dep: ";
1121 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1122 debug += "<br>";
1123 }
1124 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1125 switch (prop->type) {
1126 case P_PROMPT:
1127 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -07001128 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Roman Zippel43bf6122006-06-08 22:12:45 -07001129 debug += print_filter(_(prop->text));
Roman Zippelab45d192006-06-08 22:12:47 -07001130 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001131 break;
1132 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001133 case P_SELECT:
1134 case P_RANGE:
1135 case P_ENV:
1136 debug += prop_get_type_name(prop->type);
1137 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001138 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1139 debug += "<br>";
1140 break;
1141 case P_CHOICE:
1142 if (sym_is_choice(sym)) {
1143 debug += "choice: ";
1144 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1145 debug += "<br>";
1146 }
1147 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001148 default:
1149 debug += "unknown property: ";
1150 debug += prop_get_type_name(prop->type);
1151 debug += "<br>";
1152 }
1153 if (prop->visible.expr) {
1154 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1155 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1156 debug += "<br>";
1157 }
1158 }
1159 debug += "<br>";
1160
1161 return debug;
1162}
1163
1164QString ConfigInfoView::print_filter(const QString &str)
1165{
1166 QRegExp re("[<>&\"\\n]");
1167 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001168 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1169 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001170 case '<':
1171 res.replace(i, 1, "&lt;");
1172 i += 4;
1173 break;
1174 case '>':
1175 res.replace(i, 1, "&gt;");
1176 i += 4;
1177 break;
1178 case '&':
1179 res.replace(i, 1, "&amp;");
1180 i += 5;
1181 break;
1182 case '"':
1183 res.replace(i, 1, "&quot;");
1184 i += 6;
1185 break;
1186 case '\n':
1187 res.replace(i, 1, "<br>");
1188 i += 4;
1189 break;
1190 }
1191 }
1192 return res;
1193}
1194
Roman Zippelab45d192006-06-08 22:12:47 -07001195void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001196{
Roman Zippelab45d192006-06-08 22:12:47 -07001197 QString* text = reinterpret_cast<QString*>(data);
1198 QString str2 = print_filter(str);
1199
1200 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1201 *text += QString().sprintf("<a href=\"s%p\">", sym);
1202 *text += str2;
1203 *text += "</a>";
1204 } else
1205 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001206}
1207
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001208QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001209{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001210 QMenu* popup = Parent::createStandardContextMenu(pos);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001211 QAction* action = new QAction(_("Show Debug Info"), popup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001212 action->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001213 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1214 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001215 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001216 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001217 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001218 return popup;
1219}
1220
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001221void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001222{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001223 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001224}
1225
Marco Costalba63431e72006-10-05 19:12:59 +02001226ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001227 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001228{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001229 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001230 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001231
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001232 QVBoxLayout* layout1 = new QVBoxLayout(this);
1233 layout1->setContentsMargins(11, 11, 11, 11);
1234 layout1->setSpacing(6);
1235 QHBoxLayout* layout2 = new QHBoxLayout(0);
1236 layout2->setContentsMargins(0, 0, 0, 0);
1237 layout2->setSpacing(6);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001238 layout2->addWidget(new QLabel(_("Find:"), this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001239 editField = new QLineEdit(this);
1240 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1241 layout2->addWidget(editField);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001242 searchButton = new QPushButton(_("Search"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001243 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001244 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1245 layout2->addWidget(searchButton);
1246 layout1->addLayout(layout2);
1247
Roman Zippel7fc925f2006-06-08 22:12:46 -07001248 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001249 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001250 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001251 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001252 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001253 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1254 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001255 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1256 parent, SLOT(setMenuLink(struct menu *)));
1257
Roman Zippel43bf6122006-06-08 22:12:45 -07001258 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001259
1260 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001261 QVariant x, y;
1262 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001263 bool ok;
1264
1265 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001266 width = configSettings->value("/window width", parent->width() / 2).toInt();
1267 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001268 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001269 x = configSettings->value("/window x");
1270 y = configSettings->value("/window y");
1271 if ((x.isValid())&&(y.isValid()))
1272 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001273 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001274 if (ok)
1275 split->setSizes(sizes);
1276 configSettings->endGroup();
1277 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1278 }
1279}
1280
1281void ConfigSearchWindow::saveSettings(void)
1282{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001283 if (!objectName().isEmpty()) {
1284 configSettings->beginGroup(objectName());
1285 configSettings->setValue("/window x", pos().x());
1286 configSettings->setValue("/window y", pos().y());
1287 configSettings->setValue("/window width", size().width());
1288 configSettings->setValue("/window height", size().height());
1289 configSettings->writeSizes("/split", split->sizes());
1290 configSettings->endGroup();
1291 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001292}
1293
1294void ConfigSearchWindow::search(void)
1295{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001296 struct symbol **p;
1297 struct property *prop;
1298 ConfigItem *lastItem = NULL;
1299
1300 free(result);
1301 list->list->clear();
1302 info->clear();
1303
1304 result = sym_re_search(editField->text().toLatin1());
1305 if (!result)
1306 return;
1307 for (p = result; *p; p++) {
1308 for_all_prompts((*p), prop)
1309 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1310 menu_is_visible(prop->menu));
1311 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001312}
1313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314/*
1315 * Construct the complete config widget
1316 */
1317ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001318 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
1320 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001321 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001322 QVariant x, y;
1323 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001324 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001326 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001327 snprintf(title, sizeof(title), "%s%s",
1328 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001329 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001330 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001331 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001333 width = configSettings->value("/window width", d->width() - 64).toInt();
1334 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001336 x = configSettings->value("/window x");
1337 y = configSettings->value("/window y");
1338 if ((x.isValid())&&(y.isValid()))
1339 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
1341 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001342 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 setCentralWidget(split1);
1344
Roman Zippel7fc925f2006-06-08 22:12:46 -07001345 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 menuList = menuView->list;
1347
1348 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001349 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
1351 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -07001352 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 configList = configView->list;
1354
Roman Zippel7fc925f2006-06-08 22:12:46 -07001355 helpText = new ConfigInfoView(split2, "help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001356 //helpText->setTextFormat(Qt::RichText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358 setTabOrder(configList, helpText);
1359 configList->setFocus();
1360
1361 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001362 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001363 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001365 backAction = new QAction(QPixmap(xpm_back), _("Back"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001366 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001367 backAction->setEnabled(false);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001368 QAction *quitAction = new QAction(_("&Quit"), this);
1369 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Boris Barbulovski92119932015-09-22 11:36:16 -07001370 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001371 QAction *loadAction = new QAction(QPixmap(xpm_load), _("&Load"), this);
1372 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Boris Barbulovski92119932015-09-22 11:36:16 -07001373 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001374 saveAction = new QAction(QPixmap(xpm_save), _("&Save"), this);
1375 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Boris Barbulovski92119932015-09-22 11:36:16 -07001376 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001377 conf_set_changed_callback(conf_changed);
1378 // Set saveAction's initial state
1379 conf_changed();
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001380 QAction *saveAsAction = new QAction(_("Save &As..."), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001381 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001382 QAction *searchAction = new QAction(_("&Find"), this);
1383 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001384 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001385 singleViewAction = new QAction(QPixmap(xpm_single_view), _("Single View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001386 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001387 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001388 splitViewAction = new QAction(QPixmap(xpm_split_view), _("Split View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001389 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001390 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001391 fullViewAction = new QAction(QPixmap(xpm_tree_view), _("Full View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001392 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001393 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001395 QAction *showNameAction = new QAction(_("Show Name"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001396 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001397 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001398 showNameAction->setChecked(configView->showName());
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001399 QAction *showRangeAction = new QAction(_("Show Range"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001400 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001401 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001402 QAction *showDataAction = new QAction(_("Show Data"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001403 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001404 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001405
1406 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001407 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001408 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001409 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001410 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001411 SLOT(setOptionMode(QAction *)));
1412
Alexander Stein133c5f72010-08-31 17:34:37 +02001413 configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
1414 configView->showAllAction = new QAction(_("Show All Options"), optGroup);
1415 configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001416 configView->showNormalAction->setCheckable(true);
1417 configView->showAllAction->setCheckable(true);
1418 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001419
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001420 QAction *showDebugAction = new QAction( _("Show Debug Info"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001421 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001422 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001423 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001425 QAction *showIntroAction = new QAction( _("Introduction"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001426 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001427 QAction *showAboutAction = new QAction( _("About"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001428 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001431 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001433 toolBar->addAction(loadAction);
1434 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001436 toolBar->addAction(singleViewAction);
1437 toolBar->addAction(splitViewAction);
1438 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
1440 // create config menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001441 QMenu* config = menu->addMenu(_("&File"));
1442 config->addAction(loadAction);
1443 config->addAction(saveAction);
1444 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001445 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001446 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Shlomi Fish66e7c722007-02-14 00:32:58 -08001448 // create edit menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001449 QMenu* editMenu = menu->addMenu(_("&Edit"));
1450 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 // create options menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001453 QMenu* optionMenu = menu->addMenu(_("&Option"));
1454 optionMenu->addAction(showNameAction);
1455 optionMenu->addAction(showRangeAction);
1456 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001457 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001458 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001459 optionMenu->addSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001462 menu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001463 QMenu* helpMenu = menu->addMenu(_("&Help"));
1464 helpMenu->addAction(showIntroAction);
1465 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001467 connect(configList, SIGNAL(menuChanged(struct menu *)),
1468 helpText, SLOT(setInfo(struct menu *)));
1469 connect(configList, SIGNAL(menuSelected(struct menu *)),
1470 SLOT(changeMenu(struct menu *)));
1471 connect(configList, SIGNAL(parentSelected()),
1472 SLOT(goBack()));
1473 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1474 helpText, SLOT(setInfo(struct menu *)));
1475 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1476 SLOT(changeMenu(struct menu *)));
1477
1478 connect(configList, SIGNAL(gotFocus(struct menu *)),
1479 helpText, SLOT(setInfo(struct menu *)));
1480 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1481 helpText, SLOT(setInfo(struct menu *)));
1482 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1483 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001484 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1485 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001487 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 if (listMode == "single")
1489 showSingleView();
1490 else if (listMode == "full")
1491 showFullView();
1492 else /*if (listMode == "split")*/
1493 showSplitView();
1494
1495 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001496 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 if (ok)
1498 split1->setSizes(sizes);
1499
Roman Zippel7fc925f2006-06-08 22:12:46 -07001500 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 if (ok)
1502 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505void ConfigMainWindow::loadConfig(void)
1506{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001507 QString s = QFileDialog::getOpenFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 if (s.isNull())
1509 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001510 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001511 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 ConfigView::updateListAll();
1513}
1514
Michal Marekbac6aa82011-05-25 15:10:25 +02001515bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516{
Michal Marekbac6aa82011-05-25 15:10:25 +02001517 if (conf_write(NULL)) {
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001518 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Michal Marekbac6aa82011-05-25 15:10:25 +02001519 return false;
1520 }
1521 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522}
1523
1524void ConfigMainWindow::saveConfigAs(void)
1525{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001526 QString s = QFileDialog::getSaveFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 if (s.isNull())
1528 return;
Arnaud Lacombed49e4682011-05-24 14:16:18 -04001529 saveConfig();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Roman Zippel43bf6122006-06-08 22:12:45 -07001532void ConfigMainWindow::searchConfig(void)
1533{
1534 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001535 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001536 searchWindow->show();
1537}
1538
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539void ConfigMainWindow::changeMenu(struct menu *menu)
1540{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001541 configList->setRootMenu(menu);
1542 if (configList->rootEntry->parent == &rootmenu)
1543 backAction->setEnabled(false);
1544 else
1545 backAction->setEnabled(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Roman Zippelb65a47e2006-06-08 22:12:47 -07001548void ConfigMainWindow::setMenuLink(struct menu *menu)
1549{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001550 struct menu *parent;
1551 ConfigList* list = NULL;
1552 ConfigItem* item;
1553
1554 if (configList->menuSkip(menu))
1555 return;
1556
1557 switch (configList->mode) {
1558 case singleMode:
1559 list = configList;
1560 parent = menu_get_parent_menu(menu);
1561 if (!parent)
1562 return;
1563 list->setRootMenu(parent);
1564 break;
1565 case symbolMode:
1566 if (menu->flags & MENU_ROOT) {
1567 configList->setRootMenu(menu);
1568 configList->clearSelection();
1569 list = menuList;
1570 } else {
1571 list = configList;
1572 parent = menu_get_parent_menu(menu->parent);
1573 if (!parent)
1574 return;
1575 item = menuList->findConfigItem(parent);
1576 if (item) {
1577 item->setSelected(true);
1578 menuList->scrollToItem(item);
1579 }
1580 list->setRootMenu(parent);
1581 }
1582 break;
1583 case fullMode:
1584 list = configList;
1585 break;
1586 default:
1587 break;
1588 }
1589
1590 if (list) {
1591 item = list->findConfigItem(menu);
1592 if (item) {
1593 item->setSelected(true);
1594 list->scrollToItem(item);
1595 list->setFocus();
1596 }
1597 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001598}
1599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600void ConfigMainWindow::listFocusChanged(void)
1601{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001602 if (menuList->mode == menuMode)
1603 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604}
1605
1606void ConfigMainWindow::goBack(void)
1607{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001608 ConfigItem* item;
1609
1610 configList->setParentMenu();
1611 if (configList->rootEntry == &rootmenu)
1612 backAction->setEnabled(false);
1613 item = (ConfigItem*)menuList->selectedItems().first();
1614 while (item) {
1615 if (item->menu == configList->rootEntry) {
1616 item->setSelected(true);
1617 break;
1618 }
1619 item = (ConfigItem*)item->parent();
1620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
1623void ConfigMainWindow::showSingleView(void)
1624{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001625 singleViewAction->setEnabled(false);
1626 singleViewAction->setChecked(true);
1627 splitViewAction->setEnabled(true);
1628 splitViewAction->setChecked(false);
1629 fullViewAction->setEnabled(true);
1630 fullViewAction->setChecked(false);
1631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001633 menuList->setRootMenu(0);
1634 configList->mode = singleMode;
1635 if (configList->rootEntry == &rootmenu)
1636 configList->updateListAll();
1637 else
1638 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 configList->setFocus();
1640}
1641
1642void ConfigMainWindow::showSplitView(void)
1643{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001644 singleViewAction->setEnabled(true);
1645 singleViewAction->setChecked(false);
1646 splitViewAction->setEnabled(false);
1647 splitViewAction->setChecked(true);
1648 fullViewAction->setEnabled(true);
1649 fullViewAction->setChecked(false);
1650
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001651 configList->mode = symbolMode;
1652 if (configList->rootEntry == &rootmenu)
1653 configList->updateListAll();
1654 else
1655 configList->setRootMenu(&rootmenu);
1656 configList->setAllOpen(true);
1657 configApp->processEvents();
1658 menuList->mode = menuMode;
1659 menuList->setRootMenu(&rootmenu);
1660 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 menuView->show();
1662 menuList->setFocus();
1663}
1664
1665void ConfigMainWindow::showFullView(void)
1666{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001667 singleViewAction->setEnabled(true);
1668 singleViewAction->setChecked(false);
1669 splitViewAction->setEnabled(true);
1670 splitViewAction->setChecked(false);
1671 fullViewAction->setEnabled(false);
1672 fullViewAction->setChecked(true);
1673
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001675 menuList->setRootMenu(0);
1676 configList->mode = fullMode;
1677 if (configList->rootEntry == &rootmenu)
1678 configList->updateListAll();
1679 else
1680 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 configList->setFocus();
1682}
1683
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684/*
1685 * ask for saving configuration before quitting
1686 * TODO ask only when something changed
1687 */
1688void ConfigMainWindow::closeEvent(QCloseEvent* e)
1689{
Karsten Wieseb3214292006-12-13 00:34:06 -08001690 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 e->accept();
1692 return;
1693 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001694 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001696 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1697 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1698 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 switch (mb.exec()) {
1700 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001701 if (saveConfig())
1702 e->accept();
1703 else
1704 e->ignore();
1705 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 case QMessageBox::No:
1707 e->accept();
1708 break;
1709 case QMessageBox::Cancel:
1710 e->ignore();
1711 break;
1712 }
1713}
1714
1715void ConfigMainWindow::showIntro(void)
1716{
Arnaud Lacombe652cf982010-08-14 23:51:40 -04001717 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 "For each option, a blank box indicates the feature is disabled, a check\n"
1719 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1720 "as a module. Clicking on the box will cycle through the three states.\n\n"
1721 "If you do not see an option (e.g., a device driver) that you believe\n"
1722 "should be present, try turning on Show All Options under the Options menu.\n"
1723 "Although there is no cross reference yet to help you figure out what other\n"
1724 "options must be enabled to support the option you are interested in, you can\n"
1725 "still view the help of a grayed-out option.\n\n"
1726 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001727 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
1729 QMessageBox::information(this, "qconf", str);
1730}
1731
1732void ConfigMainWindow::showAbout(void)
1733{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001734 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1735 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 QMessageBox::information(this, "qconf", str);
1738}
1739
1740void ConfigMainWindow::saveSettings(void)
1741{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001742 configSettings->setValue("/window x", pos().x());
1743 configSettings->setValue("/window y", pos().y());
1744 configSettings->setValue("/window width", size().width());
1745 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
1747 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001748 switch(configList->mode) {
1749 case singleMode :
1750 entry = "single";
1751 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001753 case symbolMode :
1754 entry = "split";
1755 break;
1756
1757 case fullMode :
1758 entry = "full";
1759 break;
1760
1761 default:
1762 break;
1763 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001764 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
Roman Zippel7fc925f2006-06-08 22:12:46 -07001766 configSettings->writeSizes("/split1", split1->sizes());
1767 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
Karsten Wiese3b354c52006-12-13 00:34:08 -08001770void ConfigMainWindow::conf_changed(void)
1771{
1772 if (saveAction)
1773 saveAction->setEnabled(conf_get_changed());
1774}
1775
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776void fixup_rootmenu(struct menu *menu)
1777{
1778 struct menu *child;
1779 static int menu_cnt = 0;
1780
1781 menu->flags |= MENU_ROOT;
1782 for (child = menu->list; child; child = child->next) {
1783 if (child->prompt && child->prompt->type == P_MENU) {
1784 menu_cnt++;
1785 fixup_rootmenu(child);
1786 menu_cnt--;
1787 } else if (!menu_cnt)
1788 fixup_rootmenu(child);
1789 }
1790}
1791
1792static const char *progname;
1793
1794static void usage(void)
1795{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001796 printf(_("%s [-s] <config>\n").toLatin1().constData(), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 exit(0);
1798}
1799
1800int main(int ac, char** av)
1801{
1802 ConfigMainWindow* v;
1803 const char *name;
1804
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001805 bindtextdomain(PACKAGE, LOCALEDIR);
1806 textdomain(PACKAGE);
1807
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 progname = av[0];
1809 configApp = new QApplication(ac, av);
1810 if (ac > 1 && av[1][0] == '-') {
1811 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001812 case 's':
1813 conf_set_message_callback(NULL);
1814 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 case 'h':
1816 case '?':
1817 usage();
1818 }
1819 name = av[2];
1820 } else
1821 name = av[1];
1822 if (!name)
1823 usage();
1824
1825 conf_parse(name);
1826 fixup_rootmenu(&rootmenu);
1827 conf_read(NULL);
1828 //zconfdump(stdout);
1829
Roman Zippel7fc925f2006-06-08 22:12:46 -07001830 configSettings = new ConfigSettings();
1831 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 v = new ConfigMainWindow();
1833
1834 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1836 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001837 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 configApp->exec();
1839
Roman Zippel7fc925f2006-06-08 22:12:46 -07001840 configSettings->endGroup();
1841 delete configSettings;
1842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 return 0;
1844}