blob: 3a11940ff5dc0b84f9b6b66d67ef6d757aae5396 [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
Masahiro Yamada3b541978562018-12-21 17:33:07 +090026#include "images.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070030static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Boris Barbulovski85eaf282015-09-22 11:36:03 -070032QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080033
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070034static inline QString qgettext(const char* str)
35{
Sam Ravnborg694c49a2018-05-22 21:36:12 +020036 return QString::fromLocal8Bit(str);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070037}
38
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010039ConfigSettings::ConfigSettings()
40 : QSettings("kernel.org", "qconf")
41{
42}
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/**
45 * Reads a list of integer values from the application settings.
46 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070047QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070049 QList<int> result;
Li Zefanc1f96f02010-05-07 13:58:04 +080050
Boris Barbulovski83c3a1b2016-11-30 14:57:55 -080051 if (contains(key))
52 {
53 QStringList entryList = value(key).toStringList();
54 QStringList::Iterator it;
55
56 for (it = entryList.begin(); it != entryList.end(); ++it)
57 result.push_back((*it).toInt());
58
59 *ok = true;
60 }
61 else
62 *ok = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 return result;
65}
66
67/**
68 * Writes a list of integer values to the application settings.
69 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070070bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
72 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070073 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 for (it = value.begin(); it != value.end(); ++it)
76 stringList.push_back(QString::number(*it));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070077 setValue(key, stringList);
Boris Barbulovski59e56442015-09-22 11:36:18 -070078
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070079 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Boris Barbulovski59e56442015-09-22 11:36:18 -070082
83/*
84 * set the new data
85 * TODO check the value
86 */
87void ConfigItem::okRename(int col)
88{
89}
90
91/*
92 * update the displayed of a menu entry
93 */
94void ConfigItem::updateMenu(void)
95{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070096 ConfigList* list;
97 struct symbol* sym;
98 struct property *prop;
99 QString prompt;
100 int type;
101 tristate expr;
102
103 list = listView();
104 if (goParent) {
105 setPixmap(promptColIdx, list->menuBackPix);
106 prompt = "..";
107 goto set_prompt;
108 }
109
110 sym = menu->sym;
111 prop = menu->prompt;
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200112 prompt = qgettext(menu_get_prompt(menu));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700113
114 if (prop) switch (prop->type) {
115 case P_MENU:
116 if (list->mode == singleMode || list->mode == symbolMode) {
117 /* a menuconfig entry is displayed differently
118 * depending whether it's at the view root or a child.
119 */
120 if (sym && list->rootEntry == menu)
121 break;
122 setPixmap(promptColIdx, list->menuPix);
123 } else {
124 if (sym)
125 break;
126 setPixmap(promptColIdx, QIcon());
127 }
128 goto set_prompt;
129 case P_COMMENT:
130 setPixmap(promptColIdx, QIcon());
131 goto set_prompt;
132 default:
133 ;
134 }
135 if (!sym)
136 goto set_prompt;
137
138 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
139
140 type = sym_get_type(sym);
141 switch (type) {
142 case S_BOOLEAN:
143 case S_TRISTATE:
144 char ch;
145
Marco Ammonbaa23ec2019-07-04 12:50:41 +0200146 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700147 setPixmap(promptColIdx, QIcon());
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200148 setText(noColIdx, QString());
149 setText(modColIdx, QString());
150 setText(yesColIdx, QString());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700151 break;
152 }
153 expr = sym_get_tristate_value(sym);
154 switch (expr) {
155 case yes:
156 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
157 setPixmap(promptColIdx, list->choiceYesPix);
158 else
159 setPixmap(promptColIdx, list->symbolYesPix);
160 setText(yesColIdx, "Y");
161 ch = 'Y';
162 break;
163 case mod:
164 setPixmap(promptColIdx, list->symbolModPix);
165 setText(modColIdx, "M");
166 ch = 'M';
167 break;
168 default:
169 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
170 setPixmap(promptColIdx, list->choiceNoPix);
171 else
172 setPixmap(promptColIdx, list->symbolNoPix);
173 setText(noColIdx, "N");
174 ch = 'N';
175 break;
176 }
177 if (expr != no)
178 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
179 if (expr != mod)
180 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
181 if (expr != yes)
182 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
183
184 setText(dataColIdx, QChar(ch));
185 break;
186 case S_INT:
187 case S_HEX:
188 case S_STRING:
189 const char* data;
190
191 data = sym_get_string_value(sym);
192
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700193 setText(dataColIdx, data);
194 if (type == S_STRING)
195 prompt = QString("%1: %2").arg(prompt).arg(data);
196 else
197 prompt = QString("(%2) %1").arg(prompt).arg(data);
198 break;
199 }
200 if (!sym_has_value(sym) && visible)
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200201 prompt += " (NEW)";
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700202set_prompt:
203 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700204}
205
206void ConfigItem::testUpdateMenu(bool v)
207{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700208 ConfigItem* i;
209
210 visible = v;
211 if (!menu)
212 return;
213
214 sym_calc_value(menu->sym);
215 if (menu->flags & MENU_CHANGED) {
216 /* the menu entry changed, so update all list items */
217 menu->flags &= ~MENU_CHANGED;
218 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
219 i->updateMenu();
220 } else if (listView()->updateAll)
221 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700222}
223
224
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700225/*
226 * construct a menu entry
227 */
228void ConfigItem::init(void)
229{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700230 if (menu) {
231 ConfigList* list = listView();
232 nextItem = (ConfigItem*)menu->data;
233 menu->data = this;
234
235 if (list->mode != fullMode)
236 setExpanded(true);
237 sym_calc_value(menu->sym);
238 }
239 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700240}
241
242/*
243 * destruct a menu entry
244 */
245ConfigItem::~ConfigItem(void)
246{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700247 if (menu) {
248 ConfigItem** ip = (ConfigItem**)&menu->data;
249 for (; *ip; ip = &(*ip)->nextItem) {
250 if (*ip == this) {
251 *ip = nextItem;
252 break;
253 }
254 }
255 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700256}
257
Roman Zippel43bf6122006-06-08 22:12:45 -0700258ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
259 : Parent(parent)
260{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700261 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700262}
263
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700264void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700267 if (sym_get_string_value(item->menu->sym))
268 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
269 else
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200270 setText(QString());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 Parent::show();
272 setFocus();
273}
274
275void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
276{
277 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200278 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200280 case Qt::Key_Return:
281 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700282 sym_set_string_value(item->menu->sym, text().toLatin1());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 parent()->updateList(item);
284 break;
285 default:
286 Parent::keyPressEvent(e);
287 return;
288 }
289 e->accept();
290 parent()->list->setFocus();
291 hide();
292}
293
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700294ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700295 : Parent(p),
296 updateAll(false),
297 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
298 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
299 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700300 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700301 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700302{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700303 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700304 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700305 setRootIsDecorated(true);
306
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700307 setVerticalScrollMode(ScrollPerPixel);
308 setHorizontalScrollMode(ScrollPerPixel);
309
Mauro Carvalho Chehab5752ff02020-04-02 11:27:59 +0200310 if (mode == symbolMode)
311 setHeaderLabels(QStringList() << "Item" << "Name" << "N" << "M" << "Y" << "Value");
312 else
313 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700314
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700315 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700316 SLOT(updateSelection(void)));
317
318 if (name) {
319 configSettings->beginGroup(name);
320 showName = configSettings->value("/showName", false).toBool();
321 showRange = configSettings->value("/showRange", false).toBool();
322 showData = configSettings->value("/showData", false).toBool();
323 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
324 configSettings->endGroup();
325 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
326 }
327
328 addColumn(promptColIdx);
329
330 reinit();
331}
332
333bool ConfigList::menuSkip(struct menu *menu)
334{
335 if (optMode == normalOpt && menu_is_visible(menu))
336 return false;
337 if (optMode == promptOpt && menu_has_prompt(menu))
338 return false;
339 if (optMode == allOpt)
340 return false;
341 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700342}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700343
344void ConfigList::reinit(void)
345{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700346 removeColumn(dataColIdx);
347 removeColumn(yesColIdx);
348 removeColumn(modColIdx);
349 removeColumn(noColIdx);
350 removeColumn(nameColIdx);
351
352 if (showName)
353 addColumn(nameColIdx);
354 if (showRange) {
355 addColumn(noColIdx);
356 addColumn(modColIdx);
357 addColumn(yesColIdx);
358 }
359 if (showData)
360 addColumn(dataColIdx);
361
362 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700363}
364
365void ConfigList::saveSettings(void)
366{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700367 if (!objectName().isEmpty()) {
368 configSettings->beginGroup(objectName());
369 configSettings->setValue("/showName", showName);
370 configSettings->setValue("/showRange", showRange);
371 configSettings->setValue("/showData", showData);
372 configSettings->setValue("/optionMode", (int)optMode);
373 configSettings->endGroup();
374 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700375}
376
377ConfigItem* ConfigList::findConfigItem(struct menu *menu)
378{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700379 ConfigItem* item = (ConfigItem*)menu->data;
380
381 for (; item; item = item->nextItem) {
382 if (this == item->listView())
383 break;
384 }
385
386 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700387}
388
389void ConfigList::updateSelection(void)
390{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700391 struct menu *menu;
392 enum prop_type type;
393
Mauro Carvalho Chehab5752ff02020-04-02 11:27:59 +0200394 if (mode == symbolMode)
395 setHeaderLabels(QStringList() << "Item" << "Name" << "N" << "M" << "Y" << "Value");
396 else
397 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
398
Boris Barbulovskibe596aa2015-09-22 11:36:28 -0700399 if (selectedItems().count() == 0)
400 return;
401
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700402 ConfigItem* item = (ConfigItem*)selectedItems().first();
403 if (!item)
404 return;
405
406 menu = item->menu;
407 emit menuChanged(menu);
408 if (!menu)
409 return;
410 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
411 if (mode == menuMode && type == P_MENU)
412 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700413}
414
415void ConfigList::updateList(ConfigItem* item)
416{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700417 ConfigItem* last = 0;
418
419 if (!rootEntry) {
420 if (mode != listMode)
421 goto update;
422 QTreeWidgetItemIterator it(this);
423 ConfigItem* item;
424
425 while (*it) {
426 item = (ConfigItem*)(*it);
427 if (!item->menu)
428 continue;
429 item->testUpdateMenu(menu_is_visible(item->menu));
430
431 ++it;
432 }
433 return;
434 }
435
436 if (rootEntry != &rootmenu && (mode == singleMode ||
437 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
Boris Barbulovskiee7298f2015-09-22 11:36:37 -0700438 item = (ConfigItem *)topLevelItem(0);
Mauro Carvalho Chehabcc1c08e2020-06-30 08:26:40 +0200439 if (!item && mode != symbolMode) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700440 item = new ConfigItem(this, 0, true);
Mauro Carvalho Chehabcc1c08e2020-06-30 08:26:40 +0200441 last = item;
442 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700443 }
444 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
445 rootEntry->sym && rootEntry->prompt) {
446 item = last ? last->nextSibling() : firstChild();
447 if (!item)
448 item = new ConfigItem(this, last, rootEntry, true);
449 else
450 item->testUpdateMenu(true);
451
452 updateMenuList(item, rootEntry);
453 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700454 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700455 return;
456 }
457update:
458 updateMenuList(this, rootEntry);
459 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700460 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700461}
462
463void ConfigList::setValue(ConfigItem* item, tristate val)
464{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700465 struct symbol* sym;
466 int type;
467 tristate oldval;
468
469 sym = item->menu ? item->menu->sym : 0;
470 if (!sym)
471 return;
472
473 type = sym_get_type(sym);
474 switch (type) {
475 case S_BOOLEAN:
476 case S_TRISTATE:
477 oldval = sym_get_tristate_value(sym);
478
479 if (!sym_set_tristate_value(sym, val))
480 return;
481 if (oldval == no && item->menu->list)
482 item->setExpanded(true);
483 parent()->updateList(item);
484 break;
485 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700486}
487
488void ConfigList::changeValue(ConfigItem* item)
489{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700490 struct symbol* sym;
491 struct menu* menu;
492 int type, oldexpr, newexpr;
493
494 menu = item->menu;
495 if (!menu)
496 return;
497 sym = menu->sym;
498 if (!sym) {
499 if (item->menu->list)
500 item->setExpanded(!item->isExpanded());
501 return;
502 }
503
504 type = sym_get_type(sym);
505 switch (type) {
506 case S_BOOLEAN:
507 case S_TRISTATE:
508 oldexpr = sym_get_tristate_value(sym);
509 newexpr = sym_toggle_tristate_value(sym);
510 if (item->menu->list) {
511 if (oldexpr == newexpr)
512 item->setExpanded(!item->isExpanded());
513 else if (oldexpr == no)
514 item->setExpanded(true);
515 }
516 if (oldexpr != newexpr)
517 parent()->updateList(item);
518 break;
519 case S_INT:
520 case S_HEX:
521 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700522 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700523 break;
524 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700525}
526
527void ConfigList::setRootMenu(struct menu *menu)
528{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700529 enum prop_type type;
530
531 if (rootEntry == menu)
532 return;
533 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
534 if (type != P_MENU)
535 return;
536 updateMenuList(this, 0);
537 rootEntry = menu;
538 updateListAll();
539 if (currentItem()) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200540 setSelected(currentItem(), hasFocus());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700541 scrollToItem(currentItem());
542 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700543}
544
545void ConfigList::setParentMenu(void)
546{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700547 ConfigItem* item;
548 struct menu *oldroot;
549
550 oldroot = rootEntry;
551 if (rootEntry == &rootmenu)
552 return;
553 setRootMenu(menu_get_parent_menu(rootEntry->parent));
554
555 QTreeWidgetItemIterator it(this);
556 while (*it) {
557 item = (ConfigItem *)(*it);
558 if (item->menu == oldroot) {
559 setCurrentItem(item);
560 scrollToItem(item);
561 break;
562 }
563
564 ++it;
565 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700566}
567
568/*
569 * update all the children of a menu entry
570 * removes/adds the entries from the parent widget as necessary
571 *
572 * parent: either the menu list widget or a menu entry widget
573 * menu: entry to be updated
574 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700575void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700576{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700577 struct menu* child;
578 ConfigItem* item;
579 ConfigItem* last;
580 bool visible;
581 enum prop_type type;
582
583 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700584 while (parent->childCount() > 0)
585 {
586 delete parent->takeChild(0);
587 }
588
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700589 return;
590 }
591
592 last = parent->firstChild();
593 if (last && !last->goParent)
594 last = 0;
595 for (child = menu->list; child; child = child->next) {
596 item = last ? last->nextSibling() : parent->firstChild();
597 type = child->prompt ? child->prompt->type : P_UNKNOWN;
598
599 switch (mode) {
600 case menuMode:
601 if (!(child->flags & MENU_ROOT))
602 goto hide;
603 break;
604 case symbolMode:
605 if (child->flags & MENU_ROOT)
606 goto hide;
607 break;
608 default:
609 break;
610 }
611
612 visible = menu_is_visible(child);
613 if (!menuSkip(child)) {
614 if (!child->sym && !child->list && !child->prompt)
615 continue;
616 if (!item || item->menu != child)
617 item = new ConfigItem(parent, last, child, visible);
618 else
619 item->testUpdateMenu(visible);
620
621 if (mode == fullMode || mode == menuMode || type != P_MENU)
622 updateMenuList(item, child);
623 else
624 updateMenuList(item, 0);
625 last = item;
626 continue;
627 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200628hide:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700629 if (item && item->menu == child) {
630 last = parent->firstChild();
631 if (last == item)
632 last = 0;
633 else while (last->nextSibling() != item)
634 last = last->nextSibling();
635 delete item;
636 }
637 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700638}
639
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700640void ConfigList::updateMenuList(ConfigList *parent, struct menu* menu)
641{
642 struct menu* child;
643 ConfigItem* item;
644 ConfigItem* last;
645 bool visible;
646 enum prop_type type;
647
648 if (!menu) {
649 while (parent->topLevelItemCount() > 0)
650 {
651 delete parent->takeTopLevelItem(0);
652 }
653
654 return;
655 }
656
657 last = (ConfigItem*)parent->topLevelItem(0);
658 if (last && !last->goParent)
659 last = 0;
660 for (child = menu->list; child; child = child->next) {
661 item = last ? last->nextSibling() : (ConfigItem*)parent->topLevelItem(0);
662 type = child->prompt ? child->prompt->type : P_UNKNOWN;
663
664 switch (mode) {
665 case menuMode:
666 if (!(child->flags & MENU_ROOT))
667 goto hide;
668 break;
669 case symbolMode:
670 if (child->flags & MENU_ROOT)
671 goto hide;
672 break;
673 default:
674 break;
675 }
676
677 visible = menu_is_visible(child);
678 if (!menuSkip(child)) {
679 if (!child->sym && !child->list && !child->prompt)
680 continue;
681 if (!item || item->menu != child)
682 item = new ConfigItem(parent, last, child, visible);
683 else
684 item->testUpdateMenu(visible);
685
686 if (mode == fullMode || mode == menuMode || type != P_MENU)
687 updateMenuList(item, child);
688 else
689 updateMenuList(item, 0);
690 last = item;
691 continue;
692 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200693hide:
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700694 if (item && item->menu == child) {
695 last = (ConfigItem*)parent->topLevelItem(0);
696 if (last == item)
697 last = 0;
698 else while (last->nextSibling() != item)
699 last = last->nextSibling();
700 delete item;
701 }
702 }
703}
704
Boris Barbulovski59e56442015-09-22 11:36:18 -0700705void ConfigList::keyPressEvent(QKeyEvent* ev)
706{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700707 QTreeWidgetItem* i = currentItem();
708 ConfigItem* item;
709 struct menu *menu;
710 enum prop_type type;
711
712 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
713 emit parentSelected();
714 ev->accept();
715 return;
716 }
717
718 if (!i) {
719 Parent::keyPressEvent(ev);
720 return;
721 }
722 item = (ConfigItem*)i;
723
724 switch (ev->key()) {
725 case Qt::Key_Return:
726 case Qt::Key_Enter:
727 if (item->goParent) {
728 emit parentSelected();
729 break;
730 }
731 menu = item->menu;
732 if (!menu)
733 break;
734 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
735 if (type == P_MENU && rootEntry != menu &&
736 mode != fullMode && mode != menuMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200737 if (mode == menuMode)
738 emit menuSelected(menu);
739 else
740 emit itemSelected(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700741 break;
742 }
743 case Qt::Key_Space:
744 changeValue(item);
745 break;
746 case Qt::Key_N:
747 setValue(item, no);
748 break;
749 case Qt::Key_M:
750 setValue(item, mod);
751 break;
752 case Qt::Key_Y:
753 setValue(item, yes);
754 break;
755 default:
756 Parent::keyPressEvent(ev);
757 return;
758 }
759 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700760}
761
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700762void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700763{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700764 //QPoint p(contentsToViewport(e->pos()));
765 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
766 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700767}
768
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700769void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700770{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700771 QPoint p = e->pos();
772 ConfigItem* item = (ConfigItem*)itemAt(p);
773 struct menu *menu;
774 enum prop_type ptype;
775 QIcon icon;
776 int idx, x;
777
778 if (!item)
779 goto skip;
780
781 menu = item->menu;
782 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700783 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700784 switch (idx) {
785 case promptColIdx:
786 icon = item->pixmap(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700787 if (!icon.isNull()) {
788 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
789 if (x >= off && x < off + icon.availableSizes().first().width()) {
790 if (item->goParent) {
791 emit parentSelected();
792 break;
793 } else if (!menu)
794 break;
795 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
796 if (ptype == P_MENU && rootEntry != menu &&
797 mode != fullMode && mode != menuMode)
798 emit menuSelected(menu);
799 else
800 changeValue(item);
801 }
802 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700803 break;
804 case noColIdx:
805 setValue(item, no);
806 break;
807 case modColIdx:
808 setValue(item, mod);
809 break;
810 case yesColIdx:
811 setValue(item, yes);
812 break;
813 case dataColIdx:
814 changeValue(item);
815 break;
816 }
817
818skip:
819 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
820 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700821}
822
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700823void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700824{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700825 //QPoint p(contentsToViewport(e->pos()));
826 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
827 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700828}
829
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700830void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700831{
Mauro Carvalho Chehabe1f77692020-04-02 11:28:02 +0200832 QPoint p = e->pos();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700833 ConfigItem* item = (ConfigItem*)itemAt(p);
834 struct menu *menu;
835 enum prop_type ptype;
836
837 if (!item)
838 goto skip;
839 if (item->goParent) {
840 emit parentSelected();
841 goto skip;
842 }
843 menu = item->menu;
844 if (!menu)
845 goto skip;
846 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200847 if (ptype == P_MENU) {
848 if (mode == singleMode)
849 emit itemSelected(menu);
850 else if (mode == symbolMode)
851 emit menuSelected(menu);
852 } else if (menu->sym)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700853 changeValue(item);
854
855skip:
856 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
857 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700858}
859
860void ConfigList::focusInEvent(QFocusEvent *e)
861{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700862 struct menu *menu = NULL;
863
864 Parent::focusInEvent(e);
865
866 ConfigItem* item = (ConfigItem *)currentItem();
867 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200868 setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700869 menu = item->menu;
870 }
871 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700872}
873
874void ConfigList::contextMenuEvent(QContextMenuEvent *e)
875{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700876 if (e->y() <= header()->geometry().bottom()) {
877 if (!headerPopup) {
878 QAction *action;
879
880 headerPopup = new QMenu(this);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200881 action = new QAction("Show Name", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700882 action->setCheckable(true);
883 connect(action, SIGNAL(toggled(bool)),
884 parent(), SLOT(setShowName(bool)));
885 connect(parent(), SIGNAL(showNameChanged(bool)),
886 action, SLOT(setOn(bool)));
887 action->setChecked(showName);
888 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200889 action = new QAction("Show Range", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700890 action->setCheckable(true);
891 connect(action, SIGNAL(toggled(bool)),
892 parent(), SLOT(setShowRange(bool)));
893 connect(parent(), SIGNAL(showRangeChanged(bool)),
894 action, SLOT(setOn(bool)));
895 action->setChecked(showRange);
896 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200897 action = new QAction("Show Data", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700898 action->setCheckable(true);
899 connect(action, SIGNAL(toggled(bool)),
900 parent(), SLOT(setShowData(bool)));
901 connect(parent(), SIGNAL(showDataChanged(bool)),
902 action, SLOT(setOn(bool)));
903 action->setChecked(showData);
904 headerPopup->addAction(action);
905 }
906 headerPopup->exec(e->globalPos());
907 e->accept();
908 } else
909 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700910}
911
Li Zefan39a48972010-05-10 16:33:41 +0800912ConfigView*ConfigView::viewList;
913QAction *ConfigView::showNormalAction;
914QAction *ConfigView::showAllAction;
915QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Roman Zippel7fc925f2006-06-08 22:12:46 -0700917ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700918 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700920 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700921 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700922 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700923
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700924 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700925 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 lineEdit = new ConfigLineEdit(this);
927 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700928 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 this->nextView = viewList;
931 viewList = this;
932}
933
934ConfigView::~ConfigView(void)
935{
936 ConfigView** vp;
937
938 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
939 if (*vp == this) {
940 *vp = nextView;
941 break;
942 }
943 }
944}
945
Li Zefan39a48972010-05-10 16:33:41 +0800946void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700947{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700948 if (act == showNormalAction)
949 list->optMode = normalOpt;
950 else if (act == showAllAction)
951 list->optMode = allOpt;
952 else
953 list->optMode = promptOpt;
954
955 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700956}
957
958void ConfigView::setShowName(bool b)
959{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700960 if (list->showName != b) {
961 list->showName = b;
962 list->reinit();
963 emit showNameChanged(b);
964 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700965}
966
967void ConfigView::setShowRange(bool b)
968{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700969 if (list->showRange != b) {
970 list->showRange = b;
971 list->reinit();
972 emit showRangeChanged(b);
973 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700974}
975
976void ConfigView::setShowData(bool b)
977{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700978 if (list->showData != b) {
979 list->showData = b;
980 list->reinit();
981 emit showDataChanged(b);
982 }
983}
984
985void ConfigList::setAllOpen(bool open)
986{
987 QTreeWidgetItemIterator it(this);
988
989 while (*it) {
990 (*it)->setExpanded(open);
991
992 ++it;
993 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700994}
995
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700996void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700997{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700998 ConfigView* v;
999
1000 for (v = viewList; v; v = v->nextView)
1001 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
1004void ConfigView::updateListAll(void)
1005{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001006 ConfigView* v;
1007
1008 for (v = viewList; v; v = v->nextView)
1009 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
Roman Zippel43bf6122006-06-08 22:12:45 -07001012ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001013 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -07001014{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001015 setObjectName(name);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001016 setOpenLinks(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001017
1018 if (!objectName().isEmpty()) {
1019 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001020 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001021 configSettings->endGroup();
1022 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1023 }
1024}
1025
1026void ConfigInfoView::saveSettings(void)
1027{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001028 if (!objectName().isEmpty()) {
1029 configSettings->beginGroup(objectName());
1030 configSettings->setValue("/showDebug", showDebug());
1031 configSettings->endGroup();
1032 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001033}
1034
1035void ConfigInfoView::setShowDebug(bool b)
1036{
1037 if (_showDebug != b) {
1038 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001039 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001040 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001041 else if (sym)
1042 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001043 emit showDebugChanged(b);
1044 }
1045}
1046
1047void ConfigInfoView::setInfo(struct menu *m)
1048{
Alexander Stein133c5f72010-08-31 17:34:37 +02001049 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001050 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001051 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001052 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001053 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001054 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001055 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001056 menuInfo();
1057}
1058
Roman Zippelab45d192006-06-08 22:12:47 -07001059void ConfigInfoView::symbolInfo(void)
1060{
1061 QString str;
1062
1063 str += "<big>Symbol: <b>";
1064 str += print_filter(sym->name);
1065 str += "</b></big><br><br>value: ";
1066 str += print_filter(sym_get_string_value(sym));
1067 str += "<br>visibility: ";
1068 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1069 str += "<br>";
1070 str += debug_info(sym);
1071
1072 setText(str);
1073}
1074
Roman Zippel43bf6122006-06-08 22:12:45 -07001075void ConfigInfoView::menuInfo(void)
1076{
1077 struct symbol* sym;
1078 QString head, debug, help;
1079
Alexander Stein133c5f72010-08-31 17:34:37 +02001080 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001081 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001082 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001083 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001084 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001085 head += "</b></big>";
1086 if (sym->name) {
1087 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001088 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001089 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001090 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001091 if (showDebug())
1092 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001093 head += ")";
1094 }
1095 } else if (sym->name) {
1096 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001097 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001098 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001099 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001100 if (showDebug())
1101 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001102 head += "</b></big>";
1103 }
1104 head += "<br><br>";
1105
1106 if (showDebug())
1107 debug = debug_info(sym);
1108
Cheng Renquand74c15f2009-07-12 16:11:47 +08001109 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001110 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001111 help = print_filter(str_get(&help_gstr));
1112 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001113 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001114 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001115 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001116 head += "</b></big><br><br>";
1117 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001118 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001119 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001120 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001121 debug += "<br><br>";
1122 }
1123 }
1124 }
1125 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001126 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001127
1128 setText(head + debug + help);
1129}
1130
1131QString ConfigInfoView::debug_info(struct symbol *sym)
1132{
1133 QString debug;
1134
1135 debug += "type: ";
1136 debug += print_filter(sym_type_name(sym->type));
1137 if (sym_is_choice(sym))
1138 debug += " (choice)";
1139 debug += "<br>";
1140 if (sym->rev_dep.expr) {
1141 debug += "reverse dep: ";
1142 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1143 debug += "<br>";
1144 }
1145 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1146 switch (prop->type) {
1147 case P_PROMPT:
1148 case P_MENU:
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001149 debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001150 debug += print_filter(prop->text);
Roman Zippelab45d192006-06-08 22:12:47 -07001151 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001152 break;
1153 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001154 case P_SELECT:
1155 case P_RANGE:
Mauro Carvalho Chehab8f8499a2020-06-30 08:48:53 +02001156 case P_COMMENT:
1157 case P_IMPLY:
1158 case P_SYMBOL:
Roman Zippel93449082008-01-14 04:50:54 +01001159 debug += prop_get_type_name(prop->type);
1160 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001161 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1162 debug += "<br>";
1163 break;
1164 case P_CHOICE:
1165 if (sym_is_choice(sym)) {
1166 debug += "choice: ";
1167 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1168 debug += "<br>";
1169 }
1170 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001171 default:
1172 debug += "unknown property: ";
1173 debug += prop_get_type_name(prop->type);
1174 debug += "<br>";
1175 }
1176 if (prop->visible.expr) {
1177 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1178 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1179 debug += "<br>";
1180 }
1181 }
1182 debug += "<br>";
1183
1184 return debug;
1185}
1186
1187QString ConfigInfoView::print_filter(const QString &str)
1188{
1189 QRegExp re("[<>&\"\\n]");
1190 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001191 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1192 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001193 case '<':
1194 res.replace(i, 1, "&lt;");
1195 i += 4;
1196 break;
1197 case '>':
1198 res.replace(i, 1, "&gt;");
1199 i += 4;
1200 break;
1201 case '&':
1202 res.replace(i, 1, "&amp;");
1203 i += 5;
1204 break;
1205 case '"':
1206 res.replace(i, 1, "&quot;");
1207 i += 6;
1208 break;
1209 case '\n':
1210 res.replace(i, 1, "<br>");
1211 i += 4;
1212 break;
1213 }
1214 }
1215 return res;
1216}
1217
Roman Zippelab45d192006-06-08 22:12:47 -07001218void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001219{
Roman Zippelab45d192006-06-08 22:12:47 -07001220 QString* text = reinterpret_cast<QString*>(data);
1221 QString str2 = print_filter(str);
1222
1223 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001224 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001225 *text += str2;
1226 *text += "</a>";
1227 } else
1228 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001229}
1230
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001231void ConfigInfoView::clicked(const QUrl &url)
1232{
1233 QByteArray str = url.toEncoded();
1234 const std::size_t count = str.size();
1235 char *data = new char[count + 1];
1236 struct symbol **result;
1237 struct menu *m = NULL;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001238
1239 if (count < 1) {
1240 qInfo() << "Clicked link is empty";
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001241 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001242 return;
1243 }
1244
1245 memcpy(data, str.constData(), count);
1246 data[count] = '\0';
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001247
1248 /* Seek for exact match */
1249 data[0] = '^';
1250 strcat(data, "$");
1251 result = sym_re_search(data);
1252 if (!result) {
1253 qInfo() << "Clicked symbol is invalid:" << data;
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001254 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001255 return;
1256 }
1257
1258 sym = *result;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001259
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001260 /* Seek for the menu which holds the symbol */
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001261 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1262 if (prop->type != P_PROMPT && prop->type != P_MENU)
1263 continue;
1264 m = prop->menu;
1265 break;
1266 }
1267
1268 if (!m) {
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001269 /* Symbol is not visible as a menu */
1270 symbolInfo();
1271 emit showDebugChanged(true);
1272 } else {
1273 emit menuSelected(m);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001274 }
1275
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001276 free(result);
1277 delete data;
1278}
1279
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001280QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001281{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001282 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001283 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001284
1285 action->setCheckable(true);
1286 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1287 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1288 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001289 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001290 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001291 return popup;
1292}
1293
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001294void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001295{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001296 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001297}
1298
Marco Costalba63431e72006-10-05 19:12:59 +02001299ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001300 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001301{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001302 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001303 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001304
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001305 QVBoxLayout* layout1 = new QVBoxLayout(this);
1306 layout1->setContentsMargins(11, 11, 11, 11);
1307 layout1->setSpacing(6);
1308 QHBoxLayout* layout2 = new QHBoxLayout(0);
1309 layout2->setContentsMargins(0, 0, 0, 0);
1310 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001311 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001312 editField = new QLineEdit(this);
1313 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1314 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001315 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001316 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001317 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1318 layout2->addWidget(searchButton);
1319 layout1->addLayout(layout2);
1320
Roman Zippel7fc925f2006-06-08 22:12:46 -07001321 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001322 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001323 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001324 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001325 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001326 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1327 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001328 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1329 parent, SLOT(setMenuLink(struct menu *)));
1330
Roman Zippel43bf6122006-06-08 22:12:45 -07001331 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001332
1333 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001334 QVariant x, y;
1335 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001336 bool ok;
1337
1338 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001339 width = configSettings->value("/window width", parent->width() / 2).toInt();
1340 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001341 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001342 x = configSettings->value("/window x");
1343 y = configSettings->value("/window y");
1344 if ((x.isValid())&&(y.isValid()))
1345 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001346 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001347 if (ok)
1348 split->setSizes(sizes);
1349 configSettings->endGroup();
1350 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1351 }
1352}
1353
1354void ConfigSearchWindow::saveSettings(void)
1355{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001356 if (!objectName().isEmpty()) {
1357 configSettings->beginGroup(objectName());
1358 configSettings->setValue("/window x", pos().x());
1359 configSettings->setValue("/window y", pos().y());
1360 configSettings->setValue("/window width", size().width());
1361 configSettings->setValue("/window height", size().height());
1362 configSettings->writeSizes("/split", split->sizes());
1363 configSettings->endGroup();
1364 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001365}
1366
1367void ConfigSearchWindow::search(void)
1368{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001369 struct symbol **p;
1370 struct property *prop;
1371 ConfigItem *lastItem = NULL;
1372
1373 free(result);
1374 list->list->clear();
1375 info->clear();
1376
1377 result = sym_re_search(editField->text().toLatin1());
1378 if (!result)
1379 return;
1380 for (p = result; *p; p++) {
1381 for_all_prompts((*p), prop)
1382 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1383 menu_is_visible(prop->menu));
1384 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001385}
1386
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387/*
1388 * Construct the complete config widget
1389 */
1390ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001391 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
1393 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001394 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001395 QVariant x, y;
1396 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001397 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001399 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001400 snprintf(title, sizeof(title), "%s%s",
1401 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001402 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001403 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001404 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001406 width = configSettings->value("/window width", d->width() - 64).toInt();
1407 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001409 x = configSettings->value("/window x");
1410 y = configSettings->value("/window y");
1411 if ((x.isValid())&&(y.isValid()))
1412 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001414 QWidget *widget = new QWidget(this);
1415 QVBoxLayout *layout = new QVBoxLayout(widget);
1416 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001418 split1 = new QSplitter(widget);
1419 split1->setOrientation(Qt::Horizontal);
1420 split1->setChildrenCollapsible(false);
1421
1422 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 menuList = menuView->list;
1424
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001425 split2 = new QSplitter(widget);
1426 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001427 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
1429 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001430 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 configList = configView->list;
1432
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001433 helpText = new ConfigInfoView(widget, "help");
1434
1435 layout->addWidget(split2);
1436 split2->addWidget(split1);
1437 split1->addWidget(configView);
1438 split1->addWidget(menuView);
1439 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
1441 setTabOrder(configList, helpText);
1442 configList->setFocus();
1443
1444 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001445 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001446 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001448 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001449 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1450
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001451 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001452 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001453 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1454
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001455 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001456 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001457 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1458
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001459 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001460 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001461 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1462
Karsten Wiese3b354c52006-12-13 00:34:08 -08001463 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001464
Karsten Wiese3b354c52006-12-13 00:34:08 -08001465 // Set saveAction's initial state
1466 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001467 configname = xstrdup(conf_get_configname());
1468
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001469 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001470 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001471 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001472 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001473 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001474 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001475 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001476 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001477 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001478 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001479 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001480 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001481 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001482 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001484 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001485 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001486 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001487 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001488 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001489 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001490 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001491 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001492 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001493 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001494
1495 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001496 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001497 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001498 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001499 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001500 SLOT(setOptionMode(QAction *)));
1501
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001502 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1503 configView->showAllAction = new QAction("Show All Options", optGroup);
1504 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001505 configView->showNormalAction->setCheckable(true);
1506 configView->showAllAction->setCheckable(true);
1507 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001508
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001509 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001510 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001511 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001512 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001514 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001515 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001516 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001517 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001520 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001522 toolBar->addAction(loadAction);
1523 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001525 toolBar->addAction(singleViewAction);
1526 toolBar->addAction(splitViewAction);
1527 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001530 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001531 config->addAction(loadAction);
1532 config->addAction(saveAction);
1533 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001534 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001535 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Shlomi Fish66e7c722007-02-14 00:32:58 -08001537 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001538 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001539 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001540
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001542 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001543 optionMenu->addAction(showNameAction);
1544 optionMenu->addAction(showRangeAction);
1545 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001546 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001547 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001548 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001549 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
1551 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001552 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001553 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001554 helpMenu->addAction(showIntroAction);
1555 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001557 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1558 helpText, SLOT (clicked (const QUrl &)) );
1559
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001560 connect(configList, SIGNAL(menuChanged(struct menu *)),
1561 helpText, SLOT(setInfo(struct menu *)));
1562 connect(configList, SIGNAL(menuSelected(struct menu *)),
1563 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001564 connect(configList, SIGNAL(itemSelected(struct menu *)),
1565 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001566 connect(configList, SIGNAL(parentSelected()),
1567 SLOT(goBack()));
1568 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1569 helpText, SLOT(setInfo(struct menu *)));
1570 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1571 SLOT(changeMenu(struct menu *)));
1572
1573 connect(configList, SIGNAL(gotFocus(struct menu *)),
1574 helpText, SLOT(setInfo(struct menu *)));
1575 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1576 helpText, SLOT(setInfo(struct menu *)));
1577 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1578 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001579 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1580 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001582 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 if (listMode == "single")
1584 showSingleView();
1585 else if (listMode == "full")
1586 showFullView();
1587 else /*if (listMode == "split")*/
1588 showSplitView();
1589
1590 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001591 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 if (ok)
1593 split1->setSizes(sizes);
1594
Roman Zippel7fc925f2006-06-08 22:12:46 -07001595 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 if (ok)
1597 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598}
1599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600void ConfigMainWindow::loadConfig(void)
1601{
Masahiro Yamada87419082019-03-11 01:13:15 +09001602 QString str;
1603 QByteArray ba;
1604 const char *name;
1605
1606 str = QFileDialog::getOpenFileName(this, "", configname);
1607 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001609
1610 ba = str.toLocal8Bit();
1611 name = ba.data();
1612
1613 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001614 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001615
1616 free(configname);
1617 configname = xstrdup(name);
1618
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 ConfigView::updateListAll();
1620}
1621
Michal Marekbac6aa82011-05-25 15:10:25 +02001622bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Masahiro Yamada87419082019-03-11 01:13:15 +09001624 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001625 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001626 return false;
1627 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001628 conf_write_autoconf(0);
1629
Michal Marekbac6aa82011-05-25 15:10:25 +02001630 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
1633void ConfigMainWindow::saveConfigAs(void)
1634{
Masahiro Yamada87419082019-03-11 01:13:15 +09001635 QString str;
1636 QByteArray ba;
1637 const char *name;
1638
1639 str = QFileDialog::getSaveFileName(this, "", configname);
1640 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001642
1643 ba = str.toLocal8Bit();
1644 name = ba.data();
1645
1646 if (conf_write(name)) {
1647 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1648 }
1649 conf_write_autoconf(0);
1650
1651 free(configname);
1652 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Roman Zippel43bf6122006-06-08 22:12:45 -07001655void ConfigMainWindow::searchConfig(void)
1656{
1657 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001658 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001659 searchWindow->show();
1660}
1661
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001662void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001664 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
1666
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001667void ConfigMainWindow::changeMenu(struct menu *menu)
1668{
1669 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001670}
1671
Roman Zippelb65a47e2006-06-08 22:12:47 -07001672void ConfigMainWindow::setMenuLink(struct menu *menu)
1673{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001674 struct menu *parent;
1675 ConfigList* list = NULL;
1676 ConfigItem* item;
1677
1678 if (configList->menuSkip(menu))
1679 return;
1680
1681 switch (configList->mode) {
1682 case singleMode:
1683 list = configList;
1684 parent = menu_get_parent_menu(menu);
1685 if (!parent)
1686 return;
1687 list->setRootMenu(parent);
1688 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001689 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001690 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001691 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001692 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001693 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001694 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001695 parent = menu_get_parent_menu(menu->parent);
1696 if (!parent)
1697 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001698
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001699 /* Select the config view */
1700 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001701 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001702 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001703 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001704 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001705
1706 menuList->setRootMenu(parent);
1707 menuList->clearSelection();
1708 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001709 }
1710 break;
1711 case fullMode:
1712 list = configList;
1713 break;
1714 default:
1715 break;
1716 }
1717
1718 if (list) {
1719 item = list->findConfigItem(menu);
1720 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001721 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001722 list->scrollToItem(item);
1723 list->setFocus();
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001724 helpText->setInfo(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001725 }
1726 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001727}
1728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729void ConfigMainWindow::listFocusChanged(void)
1730{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001731 if (menuList->mode == menuMode)
1732 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
1734
1735void ConfigMainWindow::goBack(void)
1736{
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001737qInfo() << __FUNCTION__;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001738 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001739 return;
1740
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001741 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742}
1743
1744void ConfigMainWindow::showSingleView(void)
1745{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001746 singleViewAction->setEnabled(false);
1747 singleViewAction->setChecked(true);
1748 splitViewAction->setEnabled(true);
1749 splitViewAction->setChecked(false);
1750 fullViewAction->setEnabled(true);
1751 fullViewAction->setChecked(false);
1752
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001753 backAction->setEnabled(true);
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001756 menuList->setRootMenu(0);
1757 configList->mode = singleMode;
1758 if (configList->rootEntry == &rootmenu)
1759 configList->updateListAll();
1760 else
1761 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 configList->setFocus();
1763}
1764
1765void ConfigMainWindow::showSplitView(void)
1766{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001767 singleViewAction->setEnabled(true);
1768 singleViewAction->setChecked(false);
1769 splitViewAction->setEnabled(false);
1770 splitViewAction->setChecked(true);
1771 fullViewAction->setEnabled(true);
1772 fullViewAction->setChecked(false);
1773
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001774 backAction->setEnabled(false);
1775
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001776 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001777 if (configList->rootEntry == &rootmenu)
1778 configList->updateListAll();
1779 else
1780 configList->setRootMenu(&rootmenu);
1781 configList->setAllOpen(true);
1782 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001783 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001784 menuList->setRootMenu(&rootmenu);
1785 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 menuView->show();
1787 menuList->setFocus();
1788}
1789
1790void ConfigMainWindow::showFullView(void)
1791{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001792 singleViewAction->setEnabled(true);
1793 singleViewAction->setChecked(false);
1794 splitViewAction->setEnabled(true);
1795 splitViewAction->setChecked(false);
1796 fullViewAction->setEnabled(false);
1797 fullViewAction->setChecked(true);
1798
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001799 backAction->setEnabled(false);
1800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001802 menuList->setRootMenu(0);
1803 configList->mode = fullMode;
1804 if (configList->rootEntry == &rootmenu)
1805 configList->updateListAll();
1806 else
1807 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 configList->setFocus();
1809}
1810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811/*
1812 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 */
1814void ConfigMainWindow::closeEvent(QCloseEvent* e)
1815{
Karsten Wieseb3214292006-12-13 00:34:06 -08001816 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 e->accept();
1818 return;
1819 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001820 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001822 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1823 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1824 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 switch (mb.exec()) {
1826 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001827 if (saveConfig())
1828 e->accept();
1829 else
1830 e->ignore();
1831 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 case QMessageBox::No:
1833 e->accept();
1834 break;
1835 case QMessageBox::Cancel:
1836 e->ignore();
1837 break;
1838 }
1839}
1840
1841void ConfigMainWindow::showIntro(void)
1842{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001843 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 "For each option, a blank box indicates the feature is disabled, a check\n"
1845 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1846 "as a module. Clicking on the box will cycle through the three states.\n\n"
1847 "If you do not see an option (e.g., a device driver) that you believe\n"
1848 "should be present, try turning on Show All Options under the Options menu.\n"
1849 "Although there is no cross reference yet to help you figure out what other\n"
1850 "options must be enabled to support the option you are interested in, you can\n"
1851 "still view the help of a grayed-out option.\n\n"
1852 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001853 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
1855 QMessageBox::information(this, "qconf", str);
1856}
1857
1858void ConfigMainWindow::showAbout(void)
1859{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001860 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001861 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001862 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 QMessageBox::information(this, "qconf", str);
1865}
1866
1867void ConfigMainWindow::saveSettings(void)
1868{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001869 configSettings->setValue("/window x", pos().x());
1870 configSettings->setValue("/window y", pos().y());
1871 configSettings->setValue("/window width", size().width());
1872 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
1874 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001875 switch(configList->mode) {
1876 case singleMode :
1877 entry = "single";
1878 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001880 case symbolMode :
1881 entry = "split";
1882 break;
1883
1884 case fullMode :
1885 entry = "full";
1886 break;
1887
1888 default:
1889 break;
1890 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001891 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
Roman Zippel7fc925f2006-06-08 22:12:46 -07001893 configSettings->writeSizes("/split1", split1->sizes());
1894 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895}
1896
Karsten Wiese3b354c52006-12-13 00:34:08 -08001897void ConfigMainWindow::conf_changed(void)
1898{
1899 if (saveAction)
1900 saveAction->setEnabled(conf_get_changed());
1901}
1902
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903void fixup_rootmenu(struct menu *menu)
1904{
1905 struct menu *child;
1906 static int menu_cnt = 0;
1907
1908 menu->flags |= MENU_ROOT;
1909 for (child = menu->list; child; child = child->next) {
1910 if (child->prompt && child->prompt->type == P_MENU) {
1911 menu_cnt++;
1912 fixup_rootmenu(child);
1913 menu_cnt--;
1914 } else if (!menu_cnt)
1915 fixup_rootmenu(child);
1916 }
1917}
1918
1919static const char *progname;
1920
1921static void usage(void)
1922{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001923 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 exit(0);
1925}
1926
1927int main(int ac, char** av)
1928{
1929 ConfigMainWindow* v;
1930 const char *name;
1931
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 progname = av[0];
1933 configApp = new QApplication(ac, av);
1934 if (ac > 1 && av[1][0] == '-') {
1935 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001936 case 's':
1937 conf_set_message_callback(NULL);
1938 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 case 'h':
1940 case '?':
1941 usage();
1942 }
1943 name = av[2];
1944 } else
1945 name = av[1];
1946 if (!name)
1947 usage();
1948
1949 conf_parse(name);
1950 fixup_rootmenu(&rootmenu);
1951 conf_read(NULL);
1952 //zconfdump(stdout);
1953
Roman Zippel7fc925f2006-06-08 22:12:46 -07001954 configSettings = new ConfigSettings();
1955 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 v = new ConfigMainWindow();
1957
1958 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1960 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001961 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 configApp->exec();
1963
Roman Zippel7fc925f2006-06-08 22:12:46 -07001964 configSettings->endGroup();
1965 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001966 delete v;
1967 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001968
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 return 0;
1970}