blob: 4a616128a15484c6f9359cdd9ba35901dfebb41a [file] [log] [blame]
Masahiro Yamada0c874102018-12-18 21:13:35 +09001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07004 * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Boris Barbulovski85eaf282015-09-22 11:36:03 -07007#include <QAction>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +02008#include <QApplication>
9#include <QCloseEvent>
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +020010#include <QDebug>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020011#include <QDesktopWidget>
Boris Barbulovskibea00772015-09-22 11:36:04 -070012#include <QFileDialog>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020013#include <QLabel>
14#include <QLayout>
15#include <QList>
Boris Barbulovski76bede82015-09-22 11:36:07 -070016#include <QMenu>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020017#include <QMenuBar>
18#include <QMessageBox>
19#include <QToolBar>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <stdlib.h>
22
23#include "lkc.h"
24#include "qconf.h"
25
26#include "qconf.moc"
Masahiro Yamada3b541978562018-12-21 17:33:07 +090027#include "images.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070031static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Boris Barbulovski85eaf282015-09-22 11:36:03 -070033QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080034
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070035static inline QString qgettext(const char* str)
36{
Sam Ravnborg694c49a2018-05-22 21:36:12 +020037 return QString::fromLocal8Bit(str);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070038}
39
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010040ConfigSettings::ConfigSettings()
41 : QSettings("kernel.org", "qconf")
42{
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/**
46 * Reads a list of integer values from the application settings.
47 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070048QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070050 QList<int> result;
Li Zefanc1f96f02010-05-07 13:58:04 +080051
Boris Barbulovski83c3a1b2016-11-30 14:57:55 -080052 if (contains(key))
53 {
54 QStringList entryList = value(key).toStringList();
55 QStringList::Iterator it;
56
57 for (it = entryList.begin(); it != entryList.end(); ++it)
58 result.push_back((*it).toInt());
59
60 *ok = true;
61 }
62 else
63 *ok = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 return result;
66}
67
68/**
69 * Writes a list of integer values to the application settings.
70 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070071bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070074 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 for (it = value.begin(); it != value.end(); ++it)
77 stringList.push_back(QString::number(*it));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070078 setValue(key, stringList);
Boris Barbulovski59e56442015-09-22 11:36:18 -070079
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070080 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Boris Barbulovski59e56442015-09-22 11:36:18 -070083
84/*
85 * set the new data
86 * TODO check the value
87 */
88void ConfigItem::okRename(int col)
89{
90}
91
92/*
93 * update the displayed of a menu entry
94 */
95void ConfigItem::updateMenu(void)
96{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070097 ConfigList* list;
98 struct symbol* sym;
99 struct property *prop;
100 QString prompt;
101 int type;
102 tristate expr;
103
104 list = listView();
105 if (goParent) {
106 setPixmap(promptColIdx, list->menuBackPix);
107 prompt = "..";
108 goto set_prompt;
109 }
110
111 sym = menu->sym;
112 prop = menu->prompt;
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200113 prompt = qgettext(menu_get_prompt(menu));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700114
115 if (prop) switch (prop->type) {
116 case P_MENU:
117 if (list->mode == singleMode || list->mode == symbolMode) {
118 /* a menuconfig entry is displayed differently
119 * depending whether it's at the view root or a child.
120 */
121 if (sym && list->rootEntry == menu)
122 break;
123 setPixmap(promptColIdx, list->menuPix);
124 } else {
125 if (sym)
126 break;
127 setPixmap(promptColIdx, QIcon());
128 }
129 goto set_prompt;
130 case P_COMMENT:
131 setPixmap(promptColIdx, QIcon());
132 goto set_prompt;
133 default:
134 ;
135 }
136 if (!sym)
137 goto set_prompt;
138
139 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
140
141 type = sym_get_type(sym);
142 switch (type) {
143 case S_BOOLEAN:
144 case S_TRISTATE:
145 char ch;
146
Marco Ammonbaa23ec2019-07-04 12:50:41 +0200147 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700148 setPixmap(promptColIdx, QIcon());
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200149 setText(noColIdx, QString());
150 setText(modColIdx, QString());
151 setText(yesColIdx, QString());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700152 break;
153 }
154 expr = sym_get_tristate_value(sym);
155 switch (expr) {
156 case yes:
157 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
158 setPixmap(promptColIdx, list->choiceYesPix);
159 else
160 setPixmap(promptColIdx, list->symbolYesPix);
161 setText(yesColIdx, "Y");
162 ch = 'Y';
163 break;
164 case mod:
165 setPixmap(promptColIdx, list->symbolModPix);
166 setText(modColIdx, "M");
167 ch = 'M';
168 break;
169 default:
170 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
171 setPixmap(promptColIdx, list->choiceNoPix);
172 else
173 setPixmap(promptColIdx, list->symbolNoPix);
174 setText(noColIdx, "N");
175 ch = 'N';
176 break;
177 }
178 if (expr != no)
179 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
180 if (expr != mod)
181 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
182 if (expr != yes)
183 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
184
185 setText(dataColIdx, QChar(ch));
186 break;
187 case S_INT:
188 case S_HEX:
189 case S_STRING:
190 const char* data;
191
192 data = sym_get_string_value(sym);
193
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700194 setText(dataColIdx, data);
195 if (type == S_STRING)
196 prompt = QString("%1: %2").arg(prompt).arg(data);
197 else
198 prompt = QString("(%2) %1").arg(prompt).arg(data);
199 break;
200 }
201 if (!sym_has_value(sym) && visible)
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200202 prompt += " (NEW)";
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700203set_prompt:
204 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700205}
206
207void ConfigItem::testUpdateMenu(bool v)
208{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700209 ConfigItem* i;
210
211 visible = v;
212 if (!menu)
213 return;
214
215 sym_calc_value(menu->sym);
216 if (menu->flags & MENU_CHANGED) {
217 /* the menu entry changed, so update all list items */
218 menu->flags &= ~MENU_CHANGED;
219 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
220 i->updateMenu();
221 } else if (listView()->updateAll)
222 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700223}
224
225
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700226/*
227 * construct a menu entry
228 */
229void ConfigItem::init(void)
230{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700231 if (menu) {
232 ConfigList* list = listView();
233 nextItem = (ConfigItem*)menu->data;
234 menu->data = this;
235
236 if (list->mode != fullMode)
237 setExpanded(true);
238 sym_calc_value(menu->sym);
239 }
240 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700241}
242
243/*
244 * destruct a menu entry
245 */
246ConfigItem::~ConfigItem(void)
247{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700248 if (menu) {
249 ConfigItem** ip = (ConfigItem**)&menu->data;
250 for (; *ip; ip = &(*ip)->nextItem) {
251 if (*ip == this) {
252 *ip = nextItem;
253 break;
254 }
255 }
256 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700257}
258
Roman Zippel43bf6122006-06-08 22:12:45 -0700259ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
260 : Parent(parent)
261{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700262 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700263}
264
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700265void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700268 if (sym_get_string_value(item->menu->sym))
269 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
270 else
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200271 setText(QString());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 Parent::show();
273 setFocus();
274}
275
276void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
277{
278 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200279 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200281 case Qt::Key_Return:
282 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700283 sym_set_string_value(item->menu->sym, text().toLatin1());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 parent()->updateList(item);
285 break;
286 default:
287 Parent::keyPressEvent(e);
288 return;
289 }
290 e->accept();
291 parent()->list->setFocus();
292 hide();
293}
294
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700295ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700296 : Parent(p),
297 updateAll(false),
298 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
299 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
300 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700301 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700302 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700303{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700304 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700305 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700306 setRootIsDecorated(true);
307
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700308 setVerticalScrollMode(ScrollPerPixel);
309 setHorizontalScrollMode(ScrollPerPixel);
310
Mauro Carvalho Chehab5752ff02020-04-02 11:27:59 +0200311 if (mode == symbolMode)
312 setHeaderLabels(QStringList() << "Item" << "Name" << "N" << "M" << "Y" << "Value");
313 else
314 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700315
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700316 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700317 SLOT(updateSelection(void)));
318
319 if (name) {
320 configSettings->beginGroup(name);
321 showName = configSettings->value("/showName", false).toBool();
322 showRange = configSettings->value("/showRange", false).toBool();
323 showData = configSettings->value("/showData", false).toBool();
324 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
325 configSettings->endGroup();
326 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
327 }
328
329 addColumn(promptColIdx);
330
331 reinit();
332}
333
334bool ConfigList::menuSkip(struct menu *menu)
335{
336 if (optMode == normalOpt && menu_is_visible(menu))
337 return false;
338 if (optMode == promptOpt && menu_has_prompt(menu))
339 return false;
340 if (optMode == allOpt)
341 return false;
342 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700343}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700344
345void ConfigList::reinit(void)
346{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700347 removeColumn(dataColIdx);
348 removeColumn(yesColIdx);
349 removeColumn(modColIdx);
350 removeColumn(noColIdx);
351 removeColumn(nameColIdx);
352
353 if (showName)
354 addColumn(nameColIdx);
355 if (showRange) {
356 addColumn(noColIdx);
357 addColumn(modColIdx);
358 addColumn(yesColIdx);
359 }
360 if (showData)
361 addColumn(dataColIdx);
362
363 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700364}
365
366void ConfigList::saveSettings(void)
367{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700368 if (!objectName().isEmpty()) {
369 configSettings->beginGroup(objectName());
370 configSettings->setValue("/showName", showName);
371 configSettings->setValue("/showRange", showRange);
372 configSettings->setValue("/showData", showData);
373 configSettings->setValue("/optionMode", (int)optMode);
374 configSettings->endGroup();
375 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700376}
377
378ConfigItem* ConfigList::findConfigItem(struct menu *menu)
379{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700380 ConfigItem* item = (ConfigItem*)menu->data;
381
382 for (; item; item = item->nextItem) {
383 if (this == item->listView())
384 break;
385 }
386
387 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700388}
389
390void ConfigList::updateSelection(void)
391{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700392 struct menu *menu;
393 enum prop_type type;
394
Mauro Carvalho Chehab5752ff02020-04-02 11:27:59 +0200395 if (mode == symbolMode)
396 setHeaderLabels(QStringList() << "Item" << "Name" << "N" << "M" << "Y" << "Value");
397 else
398 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
399
Boris Barbulovskibe596aa2015-09-22 11:36:28 -0700400 if (selectedItems().count() == 0)
401 return;
402
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700403 ConfigItem* item = (ConfigItem*)selectedItems().first();
404 if (!item)
405 return;
406
407 menu = item->menu;
408 emit menuChanged(menu);
409 if (!menu)
410 return;
411 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
412 if (mode == menuMode && type == P_MENU)
413 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700414}
415
416void ConfigList::updateList(ConfigItem* item)
417{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700418 ConfigItem* last = 0;
419
420 if (!rootEntry) {
421 if (mode != listMode)
422 goto update;
423 QTreeWidgetItemIterator it(this);
424 ConfigItem* item;
425
426 while (*it) {
427 item = (ConfigItem*)(*it);
428 if (!item->menu)
429 continue;
430 item->testUpdateMenu(menu_is_visible(item->menu));
431
432 ++it;
433 }
434 return;
435 }
436
437 if (rootEntry != &rootmenu && (mode == singleMode ||
438 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
Boris Barbulovskiee7298f2015-09-22 11:36:37 -0700439 item = (ConfigItem *)topLevelItem(0);
Mauro Carvalho Chehabcc1c08e2020-06-30 08:26:40 +0200440 if (!item && mode != symbolMode) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700441 item = new ConfigItem(this, 0, true);
Mauro Carvalho Chehabcc1c08e2020-06-30 08:26:40 +0200442 last = item;
443 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700444 }
445 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
446 rootEntry->sym && rootEntry->prompt) {
447 item = last ? last->nextSibling() : firstChild();
448 if (!item)
449 item = new ConfigItem(this, last, rootEntry, true);
450 else
451 item->testUpdateMenu(true);
452
453 updateMenuList(item, rootEntry);
454 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700455 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700456 return;
457 }
458update:
459 updateMenuList(this, rootEntry);
460 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700461 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700462}
463
464void ConfigList::setValue(ConfigItem* item, tristate val)
465{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700466 struct symbol* sym;
467 int type;
468 tristate oldval;
469
470 sym = item->menu ? item->menu->sym : 0;
471 if (!sym)
472 return;
473
474 type = sym_get_type(sym);
475 switch (type) {
476 case S_BOOLEAN:
477 case S_TRISTATE:
478 oldval = sym_get_tristate_value(sym);
479
480 if (!sym_set_tristate_value(sym, val))
481 return;
482 if (oldval == no && item->menu->list)
483 item->setExpanded(true);
484 parent()->updateList(item);
485 break;
486 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700487}
488
489void ConfigList::changeValue(ConfigItem* item)
490{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700491 struct symbol* sym;
492 struct menu* menu;
493 int type, oldexpr, newexpr;
494
495 menu = item->menu;
496 if (!menu)
497 return;
498 sym = menu->sym;
499 if (!sym) {
500 if (item->menu->list)
501 item->setExpanded(!item->isExpanded());
502 return;
503 }
504
505 type = sym_get_type(sym);
506 switch (type) {
507 case S_BOOLEAN:
508 case S_TRISTATE:
509 oldexpr = sym_get_tristate_value(sym);
510 newexpr = sym_toggle_tristate_value(sym);
511 if (item->menu->list) {
512 if (oldexpr == newexpr)
513 item->setExpanded(!item->isExpanded());
514 else if (oldexpr == no)
515 item->setExpanded(true);
516 }
517 if (oldexpr != newexpr)
518 parent()->updateList(item);
519 break;
520 case S_INT:
521 case S_HEX:
522 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700523 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700524 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()) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200541 setSelected(currentItem(), hasFocus());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700542 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 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200629hide:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700630 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 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200694hide:
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700695 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) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200738 if (mode == menuMode)
739 emit menuSelected(menu);
740 else
741 emit itemSelected(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700742 break;
743 }
744 case Qt::Key_Space:
745 changeValue(item);
746 break;
747 case Qt::Key_N:
748 setValue(item, no);
749 break;
750 case Qt::Key_M:
751 setValue(item, mod);
752 break;
753 case Qt::Key_Y:
754 setValue(item, yes);
755 break;
756 default:
757 Parent::keyPressEvent(ev);
758 return;
759 }
760 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700761}
762
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700763void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700764{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700765 //QPoint p(contentsToViewport(e->pos()));
766 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
767 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700768}
769
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700770void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700771{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700772 QPoint p = e->pos();
773 ConfigItem* item = (ConfigItem*)itemAt(p);
774 struct menu *menu;
775 enum prop_type ptype;
776 QIcon icon;
777 int idx, x;
778
779 if (!item)
780 goto skip;
781
782 menu = item->menu;
783 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700784 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700785 switch (idx) {
786 case promptColIdx:
787 icon = item->pixmap(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700788 if (!icon.isNull()) {
789 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
790 if (x >= off && x < off + icon.availableSizes().first().width()) {
791 if (item->goParent) {
792 emit parentSelected();
793 break;
794 } else if (!menu)
795 break;
796 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
797 if (ptype == P_MENU && rootEntry != menu &&
798 mode != fullMode && mode != menuMode)
799 emit menuSelected(menu);
800 else
801 changeValue(item);
802 }
803 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700804 break;
805 case noColIdx:
806 setValue(item, no);
807 break;
808 case modColIdx:
809 setValue(item, mod);
810 break;
811 case yesColIdx:
812 setValue(item, yes);
813 break;
814 case dataColIdx:
815 changeValue(item);
816 break;
817 }
818
819skip:
820 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
821 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700822}
823
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700824void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700825{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700826 //QPoint p(contentsToViewport(e->pos()));
827 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
828 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700829}
830
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700831void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700832{
Mauro Carvalho Chehabe1f77692020-04-02 11:28:02 +0200833 QPoint p = e->pos();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700834 ConfigItem* item = (ConfigItem*)itemAt(p);
835 struct menu *menu;
836 enum prop_type ptype;
837
838 if (!item)
839 goto skip;
840 if (item->goParent) {
841 emit parentSelected();
842 goto skip;
843 }
844 menu = item->menu;
845 if (!menu)
846 goto skip;
847 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200848 if (ptype == P_MENU) {
849 if (mode == singleMode)
850 emit itemSelected(menu);
851 else if (mode == symbolMode)
852 emit menuSelected(menu);
853 } else if (menu->sym)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700854 changeValue(item);
855
856skip:
857 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
858 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700859}
860
861void ConfigList::focusInEvent(QFocusEvent *e)
862{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700863 struct menu *menu = NULL;
864
865 Parent::focusInEvent(e);
866
867 ConfigItem* item = (ConfigItem *)currentItem();
868 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200869 setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700870 menu = item->menu;
871 }
872 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700873}
874
875void ConfigList::contextMenuEvent(QContextMenuEvent *e)
876{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700877 if (e->y() <= header()->geometry().bottom()) {
878 if (!headerPopup) {
879 QAction *action;
880
881 headerPopup = new QMenu(this);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200882 action = new QAction("Show Name", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700883 action->setCheckable(true);
884 connect(action, SIGNAL(toggled(bool)),
885 parent(), SLOT(setShowName(bool)));
886 connect(parent(), SIGNAL(showNameChanged(bool)),
887 action, SLOT(setOn(bool)));
888 action->setChecked(showName);
889 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200890 action = new QAction("Show Range", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700891 action->setCheckable(true);
892 connect(action, SIGNAL(toggled(bool)),
893 parent(), SLOT(setShowRange(bool)));
894 connect(parent(), SIGNAL(showRangeChanged(bool)),
895 action, SLOT(setOn(bool)));
896 action->setChecked(showRange);
897 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200898 action = new QAction("Show Data", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700899 action->setCheckable(true);
900 connect(action, SIGNAL(toggled(bool)),
901 parent(), SLOT(setShowData(bool)));
902 connect(parent(), SIGNAL(showDataChanged(bool)),
903 action, SLOT(setOn(bool)));
904 action->setChecked(showData);
905 headerPopup->addAction(action);
906 }
907 headerPopup->exec(e->globalPos());
908 e->accept();
909 } else
910 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700911}
912
Li Zefan39a48972010-05-10 16:33:41 +0800913ConfigView*ConfigView::viewList;
914QAction *ConfigView::showNormalAction;
915QAction *ConfigView::showAllAction;
916QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Roman Zippel7fc925f2006-06-08 22:12:46 -0700918ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700919 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700921 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700922 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700923 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700924
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700925 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700926 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 lineEdit = new ConfigLineEdit(this);
928 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700929 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 this->nextView = viewList;
932 viewList = this;
933}
934
935ConfigView::~ConfigView(void)
936{
937 ConfigView** vp;
938
939 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
940 if (*vp == this) {
941 *vp = nextView;
942 break;
943 }
944 }
945}
946
Li Zefan39a48972010-05-10 16:33:41 +0800947void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700948{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700949 if (act == showNormalAction)
950 list->optMode = normalOpt;
951 else if (act == showAllAction)
952 list->optMode = allOpt;
953 else
954 list->optMode = promptOpt;
955
956 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700957}
958
959void ConfigView::setShowName(bool b)
960{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700961 if (list->showName != b) {
962 list->showName = b;
963 list->reinit();
964 emit showNameChanged(b);
965 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700966}
967
968void ConfigView::setShowRange(bool b)
969{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700970 if (list->showRange != b) {
971 list->showRange = b;
972 list->reinit();
973 emit showRangeChanged(b);
974 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700975}
976
977void ConfigView::setShowData(bool b)
978{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700979 if (list->showData != b) {
980 list->showData = b;
981 list->reinit();
982 emit showDataChanged(b);
983 }
984}
985
986void ConfigList::setAllOpen(bool open)
987{
988 QTreeWidgetItemIterator it(this);
989
990 while (*it) {
991 (*it)->setExpanded(open);
992
993 ++it;
994 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700995}
996
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700997void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700998{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700999 ConfigView* v;
1000
1001 for (v = viewList; v; v = v->nextView)
1002 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003}
1004
1005void ConfigView::updateListAll(void)
1006{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001007 ConfigView* v;
1008
1009 for (v = viewList; v; v = v->nextView)
1010 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Roman Zippel43bf6122006-06-08 22:12:45 -07001013ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001014 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -07001015{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001016 setObjectName(name);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001017 setOpenLinks(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001018
1019 if (!objectName().isEmpty()) {
1020 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001021 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001022 configSettings->endGroup();
1023 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1024 }
1025}
1026
1027void ConfigInfoView::saveSettings(void)
1028{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001029 if (!objectName().isEmpty()) {
1030 configSettings->beginGroup(objectName());
1031 configSettings->setValue("/showDebug", showDebug());
1032 configSettings->endGroup();
1033 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001034}
1035
1036void ConfigInfoView::setShowDebug(bool b)
1037{
1038 if (_showDebug != b) {
1039 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001040 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001041 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001042 else if (sym)
1043 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001044 emit showDebugChanged(b);
1045 }
1046}
1047
1048void ConfigInfoView::setInfo(struct menu *m)
1049{
Alexander Stein133c5f72010-08-31 17:34:37 +02001050 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001051 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001052 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001053 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001054 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001055 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001056 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001057 menuInfo();
1058}
1059
Roman Zippelab45d192006-06-08 22:12:47 -07001060void ConfigInfoView::symbolInfo(void)
1061{
1062 QString str;
1063
1064 str += "<big>Symbol: <b>";
1065 str += print_filter(sym->name);
1066 str += "</b></big><br><br>value: ";
1067 str += print_filter(sym_get_string_value(sym));
1068 str += "<br>visibility: ";
1069 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1070 str += "<br>";
1071 str += debug_info(sym);
1072
1073 setText(str);
1074}
1075
Roman Zippel43bf6122006-06-08 22:12:45 -07001076void ConfigInfoView::menuInfo(void)
1077{
1078 struct symbol* sym;
1079 QString head, debug, help;
1080
Alexander Stein133c5f72010-08-31 17:34:37 +02001081 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001082 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001083 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001084 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001085 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001086 head += "</b></big>";
1087 if (sym->name) {
1088 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001089 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001090 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001091 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001092 if (showDebug())
1093 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001094 head += ")";
1095 }
1096 } else if (sym->name) {
1097 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001098 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001099 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001100 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001101 if (showDebug())
1102 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001103 head += "</b></big>";
1104 }
1105 head += "<br><br>";
1106
1107 if (showDebug())
1108 debug = debug_info(sym);
1109
Cheng Renquand74c15f2009-07-12 16:11:47 +08001110 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001111 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001112 help = print_filter(str_get(&help_gstr));
1113 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001114 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001115 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001116 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001117 head += "</b></big><br><br>";
1118 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001119 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001120 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001121 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001122 debug += "<br><br>";
1123 }
1124 }
1125 }
1126 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001127 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001128
1129 setText(head + debug + help);
1130}
1131
1132QString ConfigInfoView::debug_info(struct symbol *sym)
1133{
1134 QString debug;
1135
1136 debug += "type: ";
1137 debug += print_filter(sym_type_name(sym->type));
1138 if (sym_is_choice(sym))
1139 debug += " (choice)";
1140 debug += "<br>";
1141 if (sym->rev_dep.expr) {
1142 debug += "reverse dep: ";
1143 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1144 debug += "<br>";
1145 }
1146 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1147 switch (prop->type) {
1148 case P_PROMPT:
1149 case P_MENU:
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001150 debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001151 debug += print_filter(prop->text);
Roman Zippelab45d192006-06-08 22:12:47 -07001152 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001153 break;
1154 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001155 case P_SELECT:
1156 case P_RANGE:
Mauro Carvalho Chehab8f8499a2020-06-30 08:48:53 +02001157 case P_COMMENT:
1158 case P_IMPLY:
1159 case P_SYMBOL:
Roman Zippel93449082008-01-14 04:50:54 +01001160 debug += prop_get_type_name(prop->type);
1161 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001162 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1163 debug += "<br>";
1164 break;
1165 case P_CHOICE:
1166 if (sym_is_choice(sym)) {
1167 debug += "choice: ";
1168 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1169 debug += "<br>";
1170 }
1171 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001172 default:
1173 debug += "unknown property: ";
1174 debug += prop_get_type_name(prop->type);
1175 debug += "<br>";
1176 }
1177 if (prop->visible.expr) {
1178 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1179 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1180 debug += "<br>";
1181 }
1182 }
1183 debug += "<br>";
1184
1185 return debug;
1186}
1187
1188QString ConfigInfoView::print_filter(const QString &str)
1189{
1190 QRegExp re("[<>&\"\\n]");
1191 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001192 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1193 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001194 case '<':
1195 res.replace(i, 1, "&lt;");
1196 i += 4;
1197 break;
1198 case '>':
1199 res.replace(i, 1, "&gt;");
1200 i += 4;
1201 break;
1202 case '&':
1203 res.replace(i, 1, "&amp;");
1204 i += 5;
1205 break;
1206 case '"':
1207 res.replace(i, 1, "&quot;");
1208 i += 6;
1209 break;
1210 case '\n':
1211 res.replace(i, 1, "<br>");
1212 i += 4;
1213 break;
1214 }
1215 }
1216 return res;
1217}
1218
Roman Zippelab45d192006-06-08 22:12:47 -07001219void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001220{
Roman Zippelab45d192006-06-08 22:12:47 -07001221 QString* text = reinterpret_cast<QString*>(data);
1222 QString str2 = print_filter(str);
1223
1224 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001225 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001226 *text += str2;
1227 *text += "</a>";
1228 } else
1229 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001230}
1231
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001232void ConfigInfoView::clicked(const QUrl &url)
1233{
1234 QByteArray str = url.toEncoded();
1235 const std::size_t count = str.size();
1236 char *data = new char[count + 1];
1237 struct symbol **result;
1238 struct menu *m = NULL;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001239
1240 if (count < 1) {
1241 qInfo() << "Clicked link is empty";
1242 delete data;
1243 return;
1244 }
1245
1246 memcpy(data, str.constData(), count);
1247 data[count] = '\0';
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001248
1249 /* Seek for exact match */
1250 data[0] = '^';
1251 strcat(data, "$");
1252 result = sym_re_search(data);
1253 if (!result) {
1254 qInfo() << "Clicked symbol is invalid:" << data;
1255 delete data;
1256 return;
1257 }
1258
1259 sym = *result;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001260
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001261 /* Seek for the menu which holds the symbol */
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001262 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1263 if (prop->type != P_PROMPT && prop->type != P_MENU)
1264 continue;
1265 m = prop->menu;
1266 break;
1267 }
1268
1269 if (!m) {
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001270 /* Symbol is not visible as a menu */
1271 symbolInfo();
1272 emit showDebugChanged(true);
1273 } else {
1274 emit menuSelected(m);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001275 }
1276
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001277 free(result);
1278 delete data;
1279}
1280
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001281QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001282{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001283 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001284 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001285
1286 action->setCheckable(true);
1287 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1288 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1289 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001290 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001291 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001292 return popup;
1293}
1294
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001295void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001296{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001297 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001298}
1299
Marco Costalba63431e72006-10-05 19:12:59 +02001300ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001301 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001302{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001303 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001304 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001305
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001306 QVBoxLayout* layout1 = new QVBoxLayout(this);
1307 layout1->setContentsMargins(11, 11, 11, 11);
1308 layout1->setSpacing(6);
1309 QHBoxLayout* layout2 = new QHBoxLayout(0);
1310 layout2->setContentsMargins(0, 0, 0, 0);
1311 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001312 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001313 editField = new QLineEdit(this);
1314 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1315 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001316 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001317 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001318 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1319 layout2->addWidget(searchButton);
1320 layout1->addLayout(layout2);
1321
Roman Zippel7fc925f2006-06-08 22:12:46 -07001322 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001323 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001324 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001325 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001326 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001327 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1328 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001329 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1330 parent, SLOT(setMenuLink(struct menu *)));
1331
Roman Zippel43bf6122006-06-08 22:12:45 -07001332 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001333
1334 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001335 QVariant x, y;
1336 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001337 bool ok;
1338
1339 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001340 width = configSettings->value("/window width", parent->width() / 2).toInt();
1341 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001342 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001343 x = configSettings->value("/window x");
1344 y = configSettings->value("/window y");
1345 if ((x.isValid())&&(y.isValid()))
1346 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001347 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001348 if (ok)
1349 split->setSizes(sizes);
1350 configSettings->endGroup();
1351 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1352 }
1353}
1354
1355void ConfigSearchWindow::saveSettings(void)
1356{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001357 if (!objectName().isEmpty()) {
1358 configSettings->beginGroup(objectName());
1359 configSettings->setValue("/window x", pos().x());
1360 configSettings->setValue("/window y", pos().y());
1361 configSettings->setValue("/window width", size().width());
1362 configSettings->setValue("/window height", size().height());
1363 configSettings->writeSizes("/split", split->sizes());
1364 configSettings->endGroup();
1365 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001366}
1367
1368void ConfigSearchWindow::search(void)
1369{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001370 struct symbol **p;
1371 struct property *prop;
1372 ConfigItem *lastItem = NULL;
1373
1374 free(result);
1375 list->list->clear();
1376 info->clear();
1377
1378 result = sym_re_search(editField->text().toLatin1());
1379 if (!result)
1380 return;
1381 for (p = result; *p; p++) {
1382 for_all_prompts((*p), prop)
1383 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1384 menu_is_visible(prop->menu));
1385 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001386}
1387
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388/*
1389 * Construct the complete config widget
1390 */
1391ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001392 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
1394 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001395 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001396 QVariant x, y;
1397 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001398 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001400 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001401 snprintf(title, sizeof(title), "%s%s",
1402 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001403 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001404 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001405 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001407 width = configSettings->value("/window width", d->width() - 64).toInt();
1408 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001410 x = configSettings->value("/window x");
1411 y = configSettings->value("/window y");
1412 if ((x.isValid())&&(y.isValid()))
1413 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001415 QWidget *widget = new QWidget(this);
1416 QVBoxLayout *layout = new QVBoxLayout(widget);
1417 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001419 split1 = new QSplitter(widget);
1420 split1->setOrientation(Qt::Horizontal);
1421 split1->setChildrenCollapsible(false);
1422
1423 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 menuList = menuView->list;
1425
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001426 split2 = new QSplitter(widget);
1427 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001428 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001431 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 configList = configView->list;
1433
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001434 helpText = new ConfigInfoView(widget, "help");
1435
1436 layout->addWidget(split2);
1437 split2->addWidget(split1);
1438 split1->addWidget(configView);
1439 split1->addWidget(menuView);
1440 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
1442 setTabOrder(configList, helpText);
1443 configList->setFocus();
1444
1445 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001446 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001447 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001449 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001450 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1451
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001452 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001453 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001454 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1455
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001456 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001457 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001458 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1459
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001460 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001461 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001462 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1463
Karsten Wiese3b354c52006-12-13 00:34:08 -08001464 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001465
Karsten Wiese3b354c52006-12-13 00:34:08 -08001466 // Set saveAction's initial state
1467 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001468 configname = xstrdup(conf_get_configname());
1469
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001470 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001471 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001472 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001473 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001474 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001475 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001476 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001477 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001478 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001479 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001480 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001481 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001482 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001483 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001485 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001486 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001487 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001488 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001489 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001490 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001491 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001492 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001493 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001494 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001495
1496 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001497 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001498 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001499 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001500 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001501 SLOT(setOptionMode(QAction *)));
1502
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001503 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1504 configView->showAllAction = new QAction("Show All Options", optGroup);
1505 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001506 configView->showNormalAction->setCheckable(true);
1507 configView->showAllAction->setCheckable(true);
1508 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001509
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001510 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001511 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001512 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001513 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001515 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001516 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001517 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001518 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001521 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001523 toolBar->addAction(loadAction);
1524 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001526 toolBar->addAction(singleViewAction);
1527 toolBar->addAction(splitViewAction);
1528 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001531 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001532 config->addAction(loadAction);
1533 config->addAction(saveAction);
1534 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001535 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001536 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Shlomi Fish66e7c722007-02-14 00:32:58 -08001538 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001539 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001540 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001541
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001543 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001544 optionMenu->addAction(showNameAction);
1545 optionMenu->addAction(showRangeAction);
1546 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001547 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001548 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001549 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001550 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001553 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001554 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001555 helpMenu->addAction(showIntroAction);
1556 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001558 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1559 helpText, SLOT (clicked (const QUrl &)) );
1560
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001561 connect(configList, SIGNAL(menuChanged(struct menu *)),
1562 helpText, SLOT(setInfo(struct menu *)));
1563 connect(configList, SIGNAL(menuSelected(struct menu *)),
1564 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001565 connect(configList, SIGNAL(itemSelected(struct menu *)),
1566 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001567 connect(configList, SIGNAL(parentSelected()),
1568 SLOT(goBack()));
1569 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1570 helpText, SLOT(setInfo(struct menu *)));
1571 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1572 SLOT(changeMenu(struct menu *)));
1573
1574 connect(configList, SIGNAL(gotFocus(struct menu *)),
1575 helpText, SLOT(setInfo(struct menu *)));
1576 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1577 helpText, SLOT(setInfo(struct menu *)));
1578 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1579 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001580 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1581 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001583 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 if (listMode == "single")
1585 showSingleView();
1586 else if (listMode == "full")
1587 showFullView();
1588 else /*if (listMode == "split")*/
1589 showSplitView();
1590
1591 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001592 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 if (ok)
1594 split1->setSizes(sizes);
1595
Roman Zippel7fc925f2006-06-08 22:12:46 -07001596 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 if (ok)
1598 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599}
1600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601void ConfigMainWindow::loadConfig(void)
1602{
Masahiro Yamada87419082019-03-11 01:13:15 +09001603 QString str;
1604 QByteArray ba;
1605 const char *name;
1606
1607 str = QFileDialog::getOpenFileName(this, "", configname);
1608 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001610
1611 ba = str.toLocal8Bit();
1612 name = ba.data();
1613
1614 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001615 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001616
1617 free(configname);
1618 configname = xstrdup(name);
1619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 ConfigView::updateListAll();
1621}
1622
Michal Marekbac6aa82011-05-25 15:10:25 +02001623bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Masahiro Yamada87419082019-03-11 01:13:15 +09001625 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001626 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001627 return false;
1628 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001629 conf_write_autoconf(0);
1630
Michal Marekbac6aa82011-05-25 15:10:25 +02001631 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
1634void ConfigMainWindow::saveConfigAs(void)
1635{
Masahiro Yamada87419082019-03-11 01:13:15 +09001636 QString str;
1637 QByteArray ba;
1638 const char *name;
1639
1640 str = QFileDialog::getSaveFileName(this, "", configname);
1641 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001643
1644 ba = str.toLocal8Bit();
1645 name = ba.data();
1646
1647 if (conf_write(name)) {
1648 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1649 }
1650 conf_write_autoconf(0);
1651
1652 free(configname);
1653 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654}
1655
Roman Zippel43bf6122006-06-08 22:12:45 -07001656void ConfigMainWindow::searchConfig(void)
1657{
1658 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001659 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001660 searchWindow->show();
1661}
1662
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001663void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001665 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001668void ConfigMainWindow::changeMenu(struct menu *menu)
1669{
1670 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001671}
1672
Roman Zippelb65a47e2006-06-08 22:12:47 -07001673void ConfigMainWindow::setMenuLink(struct menu *menu)
1674{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001675 struct menu *parent;
1676 ConfigList* list = NULL;
1677 ConfigItem* item;
1678
1679 if (configList->menuSkip(menu))
1680 return;
1681
1682 switch (configList->mode) {
1683 case singleMode:
1684 list = configList;
1685 parent = menu_get_parent_menu(menu);
1686 if (!parent)
1687 return;
1688 list->setRootMenu(parent);
1689 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001690 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001691 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001692 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001693 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001694 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001695 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001696 parent = menu_get_parent_menu(menu->parent);
1697 if (!parent)
1698 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001699
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001700 /* Select the config view */
1701 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001702 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001703 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001704 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001705 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001706
1707 menuList->setRootMenu(parent);
1708 menuList->clearSelection();
1709 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001710 }
1711 break;
1712 case fullMode:
1713 list = configList;
1714 break;
1715 default:
1716 break;
1717 }
1718
1719 if (list) {
1720 item = list->findConfigItem(menu);
1721 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001722 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001723 list->scrollToItem(item);
1724 list->setFocus();
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001725 helpText->setInfo(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001726 }
1727 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001728}
1729
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730void ConfigMainWindow::listFocusChanged(void)
1731{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001732 if (menuList->mode == menuMode)
1733 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
1735
1736void ConfigMainWindow::goBack(void)
1737{
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001738qInfo() << __FUNCTION__;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001739 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001740 return;
1741
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001742 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
1744
1745void ConfigMainWindow::showSingleView(void)
1746{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001747 singleViewAction->setEnabled(false);
1748 singleViewAction->setChecked(true);
1749 splitViewAction->setEnabled(true);
1750 splitViewAction->setChecked(false);
1751 fullViewAction->setEnabled(true);
1752 fullViewAction->setChecked(false);
1753
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001754 backAction->setEnabled(true);
1755
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001757 menuList->setRootMenu(0);
1758 configList->mode = singleMode;
1759 if (configList->rootEntry == &rootmenu)
1760 configList->updateListAll();
1761 else
1762 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 configList->setFocus();
1764}
1765
1766void ConfigMainWindow::showSplitView(void)
1767{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001768 singleViewAction->setEnabled(true);
1769 singleViewAction->setChecked(false);
1770 splitViewAction->setEnabled(false);
1771 splitViewAction->setChecked(true);
1772 fullViewAction->setEnabled(true);
1773 fullViewAction->setChecked(false);
1774
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001775 backAction->setEnabled(false);
1776
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001777 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001778 if (configList->rootEntry == &rootmenu)
1779 configList->updateListAll();
1780 else
1781 configList->setRootMenu(&rootmenu);
1782 configList->setAllOpen(true);
1783 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001784 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001785 menuList->setRootMenu(&rootmenu);
1786 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 menuView->show();
1788 menuList->setFocus();
1789}
1790
1791void ConfigMainWindow::showFullView(void)
1792{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001793 singleViewAction->setEnabled(true);
1794 singleViewAction->setChecked(false);
1795 splitViewAction->setEnabled(true);
1796 splitViewAction->setChecked(false);
1797 fullViewAction->setEnabled(false);
1798 fullViewAction->setChecked(true);
1799
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001800 backAction->setEnabled(false);
1801
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001803 menuList->setRootMenu(0);
1804 configList->mode = fullMode;
1805 if (configList->rootEntry == &rootmenu)
1806 configList->updateListAll();
1807 else
1808 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 configList->setFocus();
1810}
1811
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812/*
1813 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 */
1815void ConfigMainWindow::closeEvent(QCloseEvent* e)
1816{
Karsten Wieseb3214292006-12-13 00:34:06 -08001817 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 e->accept();
1819 return;
1820 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001821 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001823 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1824 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1825 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 switch (mb.exec()) {
1827 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001828 if (saveConfig())
1829 e->accept();
1830 else
1831 e->ignore();
1832 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 case QMessageBox::No:
1834 e->accept();
1835 break;
1836 case QMessageBox::Cancel:
1837 e->ignore();
1838 break;
1839 }
1840}
1841
1842void ConfigMainWindow::showIntro(void)
1843{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001844 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 "For each option, a blank box indicates the feature is disabled, a check\n"
1846 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1847 "as a module. Clicking on the box will cycle through the three states.\n\n"
1848 "If you do not see an option (e.g., a device driver) that you believe\n"
1849 "should be present, try turning on Show All Options under the Options menu.\n"
1850 "Although there is no cross reference yet to help you figure out what other\n"
1851 "options must be enabled to support the option you are interested in, you can\n"
1852 "still view the help of a grayed-out option.\n\n"
1853 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001854 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
1856 QMessageBox::information(this, "qconf", str);
1857}
1858
1859void ConfigMainWindow::showAbout(void)
1860{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001861 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001862 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001863 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 QMessageBox::information(this, "qconf", str);
1866}
1867
1868void ConfigMainWindow::saveSettings(void)
1869{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001870 configSettings->setValue("/window x", pos().x());
1871 configSettings->setValue("/window y", pos().y());
1872 configSettings->setValue("/window width", size().width());
1873 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
1875 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001876 switch(configList->mode) {
1877 case singleMode :
1878 entry = "single";
1879 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001881 case symbolMode :
1882 entry = "split";
1883 break;
1884
1885 case fullMode :
1886 entry = "full";
1887 break;
1888
1889 default:
1890 break;
1891 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001892 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Roman Zippel7fc925f2006-06-08 22:12:46 -07001894 configSettings->writeSizes("/split1", split1->sizes());
1895 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896}
1897
Karsten Wiese3b354c52006-12-13 00:34:08 -08001898void ConfigMainWindow::conf_changed(void)
1899{
1900 if (saveAction)
1901 saveAction->setEnabled(conf_get_changed());
1902}
1903
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904void fixup_rootmenu(struct menu *menu)
1905{
1906 struct menu *child;
1907 static int menu_cnt = 0;
1908
1909 menu->flags |= MENU_ROOT;
1910 for (child = menu->list; child; child = child->next) {
1911 if (child->prompt && child->prompt->type == P_MENU) {
1912 menu_cnt++;
1913 fixup_rootmenu(child);
1914 menu_cnt--;
1915 } else if (!menu_cnt)
1916 fixup_rootmenu(child);
1917 }
1918}
1919
1920static const char *progname;
1921
1922static void usage(void)
1923{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001924 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 exit(0);
1926}
1927
1928int main(int ac, char** av)
1929{
1930 ConfigMainWindow* v;
1931 const char *name;
1932
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 progname = av[0];
1934 configApp = new QApplication(ac, av);
1935 if (ac > 1 && av[1][0] == '-') {
1936 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001937 case 's':
1938 conf_set_message_callback(NULL);
1939 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 case 'h':
1941 case '?':
1942 usage();
1943 }
1944 name = av[2];
1945 } else
1946 name = av[1];
1947 if (!name)
1948 usage();
1949
1950 conf_parse(name);
1951 fixup_rootmenu(&rootmenu);
1952 conf_read(NULL);
1953 //zconfdump(stdout);
1954
Roman Zippel7fc925f2006-06-08 22:12:46 -07001955 configSettings = new ConfigSettings();
1956 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 v = new ConfigMainWindow();
1958
1959 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1961 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001962 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 configApp->exec();
1964
Roman Zippel7fc925f2006-06-08 22:12:46 -07001965 configSettings->endGroup();
1966 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001967 delete v;
1968 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001969
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 return 0;
1971}