blob: fd721c6c4c9485f0c7701c8c2b882604c9a3d0ae [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:
Roman Zippel93449082008-01-14 04:50:54 +01001157 debug += prop_get_type_name(prop->type);
1158 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001159 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1160 debug += "<br>";
1161 break;
1162 case P_CHOICE:
1163 if (sym_is_choice(sym)) {
1164 debug += "choice: ";
1165 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1166 debug += "<br>";
1167 }
1168 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001169 default:
1170 debug += "unknown property: ";
1171 debug += prop_get_type_name(prop->type);
1172 debug += "<br>";
1173 }
1174 if (prop->visible.expr) {
1175 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1176 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1177 debug += "<br>";
1178 }
1179 }
1180 debug += "<br>";
1181
1182 return debug;
1183}
1184
1185QString ConfigInfoView::print_filter(const QString &str)
1186{
1187 QRegExp re("[<>&\"\\n]");
1188 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001189 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1190 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001191 case '<':
1192 res.replace(i, 1, "&lt;");
1193 i += 4;
1194 break;
1195 case '>':
1196 res.replace(i, 1, "&gt;");
1197 i += 4;
1198 break;
1199 case '&':
1200 res.replace(i, 1, "&amp;");
1201 i += 5;
1202 break;
1203 case '"':
1204 res.replace(i, 1, "&quot;");
1205 i += 6;
1206 break;
1207 case '\n':
1208 res.replace(i, 1, "<br>");
1209 i += 4;
1210 break;
1211 }
1212 }
1213 return res;
1214}
1215
Roman Zippelab45d192006-06-08 22:12:47 -07001216void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001217{
Roman Zippelab45d192006-06-08 22:12:47 -07001218 QString* text = reinterpret_cast<QString*>(data);
1219 QString str2 = print_filter(str);
1220
1221 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001222 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001223 *text += str2;
1224 *text += "</a>";
1225 } else
1226 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001227}
1228
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001229void ConfigInfoView::clicked(const QUrl &url)
1230{
1231 QByteArray str = url.toEncoded();
1232 const std::size_t count = str.size();
1233 char *data = new char[count + 1];
1234 struct symbol **result;
1235 struct menu *m = NULL;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001236
1237 if (count < 1) {
1238 qInfo() << "Clicked link is empty";
1239 delete data;
1240 return;
1241 }
1242
1243 memcpy(data, str.constData(), count);
1244 data[count] = '\0';
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001245
1246 /* Seek for exact match */
1247 data[0] = '^';
1248 strcat(data, "$");
1249 result = sym_re_search(data);
1250 if (!result) {
1251 qInfo() << "Clicked symbol is invalid:" << data;
1252 delete data;
1253 return;
1254 }
1255
1256 sym = *result;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001257
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001258 /* Seek for the menu which holds the symbol */
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001259 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1260 if (prop->type != P_PROMPT && prop->type != P_MENU)
1261 continue;
1262 m = prop->menu;
1263 break;
1264 }
1265
1266 if (!m) {
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001267 /* Symbol is not visible as a menu */
1268 symbolInfo();
1269 emit showDebugChanged(true);
1270 } else {
1271 emit menuSelected(m);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001272 }
1273
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001274 free(result);
1275 delete data;
1276}
1277
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001278QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001279{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001280 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001281 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001282
1283 action->setCheckable(true);
1284 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1285 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1286 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001287 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001288 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001289 return popup;
1290}
1291
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001292void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001293{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001294 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001295}
1296
Marco Costalba63431e72006-10-05 19:12:59 +02001297ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001298 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001299{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001300 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001301 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001302
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001303 QVBoxLayout* layout1 = new QVBoxLayout(this);
1304 layout1->setContentsMargins(11, 11, 11, 11);
1305 layout1->setSpacing(6);
1306 QHBoxLayout* layout2 = new QHBoxLayout(0);
1307 layout2->setContentsMargins(0, 0, 0, 0);
1308 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001309 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001310 editField = new QLineEdit(this);
1311 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1312 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001313 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001314 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001315 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1316 layout2->addWidget(searchButton);
1317 layout1->addLayout(layout2);
1318
Roman Zippel7fc925f2006-06-08 22:12:46 -07001319 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001320 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001321 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001322 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001323 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001324 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1325 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001326 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1327 parent, SLOT(setMenuLink(struct menu *)));
1328
Roman Zippel43bf6122006-06-08 22:12:45 -07001329 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001330
1331 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001332 QVariant x, y;
1333 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001334 bool ok;
1335
1336 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001337 width = configSettings->value("/window width", parent->width() / 2).toInt();
1338 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001339 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001340 x = configSettings->value("/window x");
1341 y = configSettings->value("/window y");
1342 if ((x.isValid())&&(y.isValid()))
1343 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001344 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001345 if (ok)
1346 split->setSizes(sizes);
1347 configSettings->endGroup();
1348 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1349 }
1350}
1351
1352void ConfigSearchWindow::saveSettings(void)
1353{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001354 if (!objectName().isEmpty()) {
1355 configSettings->beginGroup(objectName());
1356 configSettings->setValue("/window x", pos().x());
1357 configSettings->setValue("/window y", pos().y());
1358 configSettings->setValue("/window width", size().width());
1359 configSettings->setValue("/window height", size().height());
1360 configSettings->writeSizes("/split", split->sizes());
1361 configSettings->endGroup();
1362 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001363}
1364
1365void ConfigSearchWindow::search(void)
1366{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001367 struct symbol **p;
1368 struct property *prop;
1369 ConfigItem *lastItem = NULL;
1370
1371 free(result);
1372 list->list->clear();
1373 info->clear();
1374
1375 result = sym_re_search(editField->text().toLatin1());
1376 if (!result)
1377 return;
1378 for (p = result; *p; p++) {
1379 for_all_prompts((*p), prop)
1380 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1381 menu_is_visible(prop->menu));
1382 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001383}
1384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385/*
1386 * Construct the complete config widget
1387 */
1388ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001389 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
1391 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001392 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001393 QVariant x, y;
1394 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001395 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001397 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001398 snprintf(title, sizeof(title), "%s%s",
1399 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001400 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001401 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001402 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001404 width = configSettings->value("/window width", d->width() - 64).toInt();
1405 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001407 x = configSettings->value("/window x");
1408 y = configSettings->value("/window y");
1409 if ((x.isValid())&&(y.isValid()))
1410 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001412 QWidget *widget = new QWidget(this);
1413 QVBoxLayout *layout = new QVBoxLayout(widget);
1414 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001416 split1 = new QSplitter(widget);
1417 split1->setOrientation(Qt::Horizontal);
1418 split1->setChildrenCollapsible(false);
1419
1420 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 menuList = menuView->list;
1422
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001423 split2 = new QSplitter(widget);
1424 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001425 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001428 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 configList = configView->list;
1430
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001431 helpText = new ConfigInfoView(widget, "help");
1432
1433 layout->addWidget(split2);
1434 split2->addWidget(split1);
1435 split1->addWidget(configView);
1436 split1->addWidget(menuView);
1437 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
1439 setTabOrder(configList, helpText);
1440 configList->setFocus();
1441
1442 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001443 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001444 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001446 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001447 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1448
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001449 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001450 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001451 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1452
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001453 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001454 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001455 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1456
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001457 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001458 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001459 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1460
Karsten Wiese3b354c52006-12-13 00:34:08 -08001461 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001462
Karsten Wiese3b354c52006-12-13 00:34:08 -08001463 // Set saveAction's initial state
1464 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001465 configname = xstrdup(conf_get_configname());
1466
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001467 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001468 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001469 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001470 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001471 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001472 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001473 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001474 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001475 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001476 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001477 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001478 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001479 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001480 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001482 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001483 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001484 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001485 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001486 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001487 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001488 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001489 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001490 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001491 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001492
1493 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001494 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001495 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001496 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001497 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001498 SLOT(setOptionMode(QAction *)));
1499
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001500 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1501 configView->showAllAction = new QAction("Show All Options", optGroup);
1502 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001503 configView->showNormalAction->setCheckable(true);
1504 configView->showAllAction->setCheckable(true);
1505 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001506
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001507 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001508 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001509 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001510 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001512 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001513 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001514 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001515 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
1517 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001518 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001520 toolBar->addAction(loadAction);
1521 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001523 toolBar->addAction(singleViewAction);
1524 toolBar->addAction(splitViewAction);
1525 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001528 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001529 config->addAction(loadAction);
1530 config->addAction(saveAction);
1531 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001532 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001533 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Shlomi Fish66e7c722007-02-14 00:32:58 -08001535 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001536 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001537 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001538
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001540 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001541 optionMenu->addAction(showNameAction);
1542 optionMenu->addAction(showRangeAction);
1543 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001544 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001545 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001546 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001547 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001550 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001551 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001552 helpMenu->addAction(showIntroAction);
1553 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001555 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1556 helpText, SLOT (clicked (const QUrl &)) );
1557
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001558 connect(configList, SIGNAL(menuChanged(struct menu *)),
1559 helpText, SLOT(setInfo(struct menu *)));
1560 connect(configList, SIGNAL(menuSelected(struct menu *)),
1561 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001562 connect(configList, SIGNAL(itemSelected(struct menu *)),
1563 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001564 connect(configList, SIGNAL(parentSelected()),
1565 SLOT(goBack()));
1566 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1567 helpText, SLOT(setInfo(struct menu *)));
1568 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1569 SLOT(changeMenu(struct menu *)));
1570
1571 connect(configList, SIGNAL(gotFocus(struct menu *)),
1572 helpText, SLOT(setInfo(struct menu *)));
1573 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1574 helpText, SLOT(setInfo(struct menu *)));
1575 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1576 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001577 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1578 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001580 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 if (listMode == "single")
1582 showSingleView();
1583 else if (listMode == "full")
1584 showFullView();
1585 else /*if (listMode == "split")*/
1586 showSplitView();
1587
1588 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001589 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 if (ok)
1591 split1->setSizes(sizes);
1592
Roman Zippel7fc925f2006-06-08 22:12:46 -07001593 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 if (ok)
1595 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598void ConfigMainWindow::loadConfig(void)
1599{
Masahiro Yamada87419082019-03-11 01:13:15 +09001600 QString str;
1601 QByteArray ba;
1602 const char *name;
1603
1604 str = QFileDialog::getOpenFileName(this, "", configname);
1605 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001607
1608 ba = str.toLocal8Bit();
1609 name = ba.data();
1610
1611 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001612 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001613
1614 free(configname);
1615 configname = xstrdup(name);
1616
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 ConfigView::updateListAll();
1618}
1619
Michal Marekbac6aa82011-05-25 15:10:25 +02001620bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
Masahiro Yamada87419082019-03-11 01:13:15 +09001622 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001623 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001624 return false;
1625 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001626 conf_write_autoconf(0);
1627
Michal Marekbac6aa82011-05-25 15:10:25 +02001628 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629}
1630
1631void ConfigMainWindow::saveConfigAs(void)
1632{
Masahiro Yamada87419082019-03-11 01:13:15 +09001633 QString str;
1634 QByteArray ba;
1635 const char *name;
1636
1637 str = QFileDialog::getSaveFileName(this, "", configname);
1638 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001640
1641 ba = str.toLocal8Bit();
1642 name = ba.data();
1643
1644 if (conf_write(name)) {
1645 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1646 }
1647 conf_write_autoconf(0);
1648
1649 free(configname);
1650 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
Roman Zippel43bf6122006-06-08 22:12:45 -07001653void ConfigMainWindow::searchConfig(void)
1654{
1655 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001656 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001657 searchWindow->show();
1658}
1659
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001660void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001662 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001665void ConfigMainWindow::changeMenu(struct menu *menu)
1666{
1667 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001668}
1669
Roman Zippelb65a47e2006-06-08 22:12:47 -07001670void ConfigMainWindow::setMenuLink(struct menu *menu)
1671{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001672 struct menu *parent;
1673 ConfigList* list = NULL;
1674 ConfigItem* item;
1675
1676 if (configList->menuSkip(menu))
1677 return;
1678
1679 switch (configList->mode) {
1680 case singleMode:
1681 list = configList;
1682 parent = menu_get_parent_menu(menu);
1683 if (!parent)
1684 return;
1685 list->setRootMenu(parent);
1686 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001687 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001688 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001689 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001690 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001691 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001692 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001693 parent = menu_get_parent_menu(menu->parent);
1694 if (!parent)
1695 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001696
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001697 /* Select the config view */
1698 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001699 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001700 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001701 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001702 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001703
1704 menuList->setRootMenu(parent);
1705 menuList->clearSelection();
1706 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001707 }
1708 break;
1709 case fullMode:
1710 list = configList;
1711 break;
1712 default:
1713 break;
1714 }
1715
1716 if (list) {
1717 item = list->findConfigItem(menu);
1718 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001719 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001720 list->scrollToItem(item);
1721 list->setFocus();
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001722 helpText->setInfo(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001723 }
1724 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001725}
1726
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727void ConfigMainWindow::listFocusChanged(void)
1728{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001729 if (menuList->mode == menuMode)
1730 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731}
1732
1733void ConfigMainWindow::goBack(void)
1734{
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001735qInfo() << __FUNCTION__;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001736 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001737 return;
1738
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001739 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740}
1741
1742void ConfigMainWindow::showSingleView(void)
1743{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001744 singleViewAction->setEnabled(false);
1745 singleViewAction->setChecked(true);
1746 splitViewAction->setEnabled(true);
1747 splitViewAction->setChecked(false);
1748 fullViewAction->setEnabled(true);
1749 fullViewAction->setChecked(false);
1750
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001751 backAction->setEnabled(true);
1752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001754 menuList->setRootMenu(0);
1755 configList->mode = singleMode;
1756 if (configList->rootEntry == &rootmenu)
1757 configList->updateListAll();
1758 else
1759 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 configList->setFocus();
1761}
1762
1763void ConfigMainWindow::showSplitView(void)
1764{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001765 singleViewAction->setEnabled(true);
1766 singleViewAction->setChecked(false);
1767 splitViewAction->setEnabled(false);
1768 splitViewAction->setChecked(true);
1769 fullViewAction->setEnabled(true);
1770 fullViewAction->setChecked(false);
1771
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001772 backAction->setEnabled(false);
1773
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001774 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001775 if (configList->rootEntry == &rootmenu)
1776 configList->updateListAll();
1777 else
1778 configList->setRootMenu(&rootmenu);
1779 configList->setAllOpen(true);
1780 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001781 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001782 menuList->setRootMenu(&rootmenu);
1783 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 menuView->show();
1785 menuList->setFocus();
1786}
1787
1788void ConfigMainWindow::showFullView(void)
1789{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001790 singleViewAction->setEnabled(true);
1791 singleViewAction->setChecked(false);
1792 splitViewAction->setEnabled(true);
1793 splitViewAction->setChecked(false);
1794 fullViewAction->setEnabled(false);
1795 fullViewAction->setChecked(true);
1796
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001797 backAction->setEnabled(false);
1798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001800 menuList->setRootMenu(0);
1801 configList->mode = fullMode;
1802 if (configList->rootEntry == &rootmenu)
1803 configList->updateListAll();
1804 else
1805 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 configList->setFocus();
1807}
1808
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809/*
1810 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 */
1812void ConfigMainWindow::closeEvent(QCloseEvent* e)
1813{
Karsten Wieseb3214292006-12-13 00:34:06 -08001814 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 e->accept();
1816 return;
1817 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001818 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001820 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1821 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1822 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 switch (mb.exec()) {
1824 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001825 if (saveConfig())
1826 e->accept();
1827 else
1828 e->ignore();
1829 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 case QMessageBox::No:
1831 e->accept();
1832 break;
1833 case QMessageBox::Cancel:
1834 e->ignore();
1835 break;
1836 }
1837}
1838
1839void ConfigMainWindow::showIntro(void)
1840{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001841 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 "For each option, a blank box indicates the feature is disabled, a check\n"
1843 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1844 "as a module. Clicking on the box will cycle through the three states.\n\n"
1845 "If you do not see an option (e.g., a device driver) that you believe\n"
1846 "should be present, try turning on Show All Options under the Options menu.\n"
1847 "Although there is no cross reference yet to help you figure out what other\n"
1848 "options must be enabled to support the option you are interested in, you can\n"
1849 "still view the help of a grayed-out option.\n\n"
1850 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001851 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
1853 QMessageBox::information(this, "qconf", str);
1854}
1855
1856void ConfigMainWindow::showAbout(void)
1857{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001858 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001859 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001860 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
1862 QMessageBox::information(this, "qconf", str);
1863}
1864
1865void ConfigMainWindow::saveSettings(void)
1866{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001867 configSettings->setValue("/window x", pos().x());
1868 configSettings->setValue("/window y", pos().y());
1869 configSettings->setValue("/window width", size().width());
1870 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
1872 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001873 switch(configList->mode) {
1874 case singleMode :
1875 entry = "single";
1876 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001878 case symbolMode :
1879 entry = "split";
1880 break;
1881
1882 case fullMode :
1883 entry = "full";
1884 break;
1885
1886 default:
1887 break;
1888 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001889 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
Roman Zippel7fc925f2006-06-08 22:12:46 -07001891 configSettings->writeSizes("/split1", split1->sizes());
1892 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893}
1894
Karsten Wiese3b354c52006-12-13 00:34:08 -08001895void ConfigMainWindow::conf_changed(void)
1896{
1897 if (saveAction)
1898 saveAction->setEnabled(conf_get_changed());
1899}
1900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901void fixup_rootmenu(struct menu *menu)
1902{
1903 struct menu *child;
1904 static int menu_cnt = 0;
1905
1906 menu->flags |= MENU_ROOT;
1907 for (child = menu->list; child; child = child->next) {
1908 if (child->prompt && child->prompt->type == P_MENU) {
1909 menu_cnt++;
1910 fixup_rootmenu(child);
1911 menu_cnt--;
1912 } else if (!menu_cnt)
1913 fixup_rootmenu(child);
1914 }
1915}
1916
1917static const char *progname;
1918
1919static void usage(void)
1920{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001921 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 exit(0);
1923}
1924
1925int main(int ac, char** av)
1926{
1927 ConfigMainWindow* v;
1928 const char *name;
1929
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 progname = av[0];
1931 configApp = new QApplication(ac, av);
1932 if (ac > 1 && av[1][0] == '-') {
1933 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001934 case 's':
1935 conf_set_message_callback(NULL);
1936 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 case 'h':
1938 case '?':
1939 usage();
1940 }
1941 name = av[2];
1942 } else
1943 name = av[1];
1944 if (!name)
1945 usage();
1946
1947 conf_parse(name);
1948 fixup_rootmenu(&rootmenu);
1949 conf_read(NULL);
1950 //zconfdump(stdout);
1951
Roman Zippel7fc925f2006-06-08 22:12:46 -07001952 configSettings = new ConfigSettings();
1953 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 v = new ConfigMainWindow();
1955
1956 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1958 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001959 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 configApp->exec();
1961
Roman Zippel7fc925f2006-06-08 22:12:46 -07001962 configSettings->endGroup();
1963 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001964 delete v;
1965 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 return 0;
1968}