blob: e43fe4dcd4e7497c64d548ca7ff37802fa2828dc [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);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700440 if (!item)
441 item = new ConfigItem(this, 0, true);
442 last = item;
443 }
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:
Roman Zippel93449082008-01-14 04:50:54 +01001156 debug += prop_get_type_name(prop->type);
1157 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001158 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1159 debug += "<br>";
1160 break;
1161 case P_CHOICE:
1162 if (sym_is_choice(sym)) {
1163 debug += "choice: ";
1164 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1165 debug += "<br>";
1166 }
1167 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001168 default:
1169 debug += "unknown property: ";
1170 debug += prop_get_type_name(prop->type);
1171 debug += "<br>";
1172 }
1173 if (prop->visible.expr) {
1174 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1175 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1176 debug += "<br>";
1177 }
1178 }
1179 debug += "<br>";
1180
1181 return debug;
1182}
1183
1184QString ConfigInfoView::print_filter(const QString &str)
1185{
1186 QRegExp re("[<>&\"\\n]");
1187 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001188 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1189 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001190 case '<':
1191 res.replace(i, 1, "&lt;");
1192 i += 4;
1193 break;
1194 case '>':
1195 res.replace(i, 1, "&gt;");
1196 i += 4;
1197 break;
1198 case '&':
1199 res.replace(i, 1, "&amp;");
1200 i += 5;
1201 break;
1202 case '"':
1203 res.replace(i, 1, "&quot;");
1204 i += 6;
1205 break;
1206 case '\n':
1207 res.replace(i, 1, "<br>");
1208 i += 4;
1209 break;
1210 }
1211 }
1212 return res;
1213}
1214
Roman Zippelab45d192006-06-08 22:12:47 -07001215void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001216{
Roman Zippelab45d192006-06-08 22:12:47 -07001217 QString* text = reinterpret_cast<QString*>(data);
1218 QString str2 = print_filter(str);
1219
1220 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001221 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001222 *text += str2;
1223 *text += "</a>";
1224 } else
1225 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001226}
1227
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001228void ConfigInfoView::clicked(const QUrl &url)
1229{
1230 QByteArray str = url.toEncoded();
1231 const std::size_t count = str.size();
1232 char *data = new char[count + 1];
1233 struct symbol **result;
1234 struct menu *m = NULL;
1235 char type;
1236
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';
1245 type = data[0];
1246
1247 /* Seek for exact match */
1248 data[0] = '^';
1249 strcat(data, "$");
1250 result = sym_re_search(data);
1251 if (!result) {
1252 qInfo() << "Clicked symbol is invalid:" << data;
1253 delete data;
1254 return;
1255 }
1256
1257 sym = *result;
1258 if (type == 's') {
1259 symbolInfo();
1260 emit showDebugChanged(true);
1261 free(result);
1262 delete data;
1263 return;
1264 }
1265
1266 /* URL is a menu */
1267 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1268 if (prop->type != P_PROMPT && prop->type != P_MENU)
1269 continue;
1270 m = prop->menu;
1271 break;
1272 }
1273
1274 if (!m) {
1275 qInfo() << "Clicked menu is invalid:" << data;
1276 free(result);
1277 delete data;
1278 return;
1279 }
1280
1281 _menu = m;
1282 menuInfo();
1283
1284 emit showDebugChanged(true);
1285 free(result);
1286 delete data;
1287}
1288
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001289QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001290{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001291 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001292 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001293
1294 action->setCheckable(true);
1295 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1296 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1297 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001298 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001299 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001300 return popup;
1301}
1302
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001303void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001304{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001305 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001306}
1307
Marco Costalba63431e72006-10-05 19:12:59 +02001308ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001309 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001310{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001311 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001312 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001313
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001314 QVBoxLayout* layout1 = new QVBoxLayout(this);
1315 layout1->setContentsMargins(11, 11, 11, 11);
1316 layout1->setSpacing(6);
1317 QHBoxLayout* layout2 = new QHBoxLayout(0);
1318 layout2->setContentsMargins(0, 0, 0, 0);
1319 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001320 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001321 editField = new QLineEdit(this);
1322 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1323 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001324 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001325 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001326 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1327 layout2->addWidget(searchButton);
1328 layout1->addLayout(layout2);
1329
Roman Zippel7fc925f2006-06-08 22:12:46 -07001330 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001331 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001332 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001333 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001334 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001335 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1336 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001337 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1338 parent, SLOT(setMenuLink(struct menu *)));
1339
Roman Zippel43bf6122006-06-08 22:12:45 -07001340 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001341
1342 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001343 QVariant x, y;
1344 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001345 bool ok;
1346
1347 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001348 width = configSettings->value("/window width", parent->width() / 2).toInt();
1349 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001350 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001351 x = configSettings->value("/window x");
1352 y = configSettings->value("/window y");
1353 if ((x.isValid())&&(y.isValid()))
1354 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001355 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001356 if (ok)
1357 split->setSizes(sizes);
1358 configSettings->endGroup();
1359 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1360 }
1361}
1362
1363void ConfigSearchWindow::saveSettings(void)
1364{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001365 if (!objectName().isEmpty()) {
1366 configSettings->beginGroup(objectName());
1367 configSettings->setValue("/window x", pos().x());
1368 configSettings->setValue("/window y", pos().y());
1369 configSettings->setValue("/window width", size().width());
1370 configSettings->setValue("/window height", size().height());
1371 configSettings->writeSizes("/split", split->sizes());
1372 configSettings->endGroup();
1373 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001374}
1375
1376void ConfigSearchWindow::search(void)
1377{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001378 struct symbol **p;
1379 struct property *prop;
1380 ConfigItem *lastItem = NULL;
1381
1382 free(result);
1383 list->list->clear();
1384 info->clear();
1385
1386 result = sym_re_search(editField->text().toLatin1());
1387 if (!result)
1388 return;
1389 for (p = result; *p; p++) {
1390 for_all_prompts((*p), prop)
1391 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1392 menu_is_visible(prop->menu));
1393 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001394}
1395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396/*
1397 * Construct the complete config widget
1398 */
1399ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001400 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401{
1402 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001403 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001404 QVariant x, y;
1405 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001406 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001408 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001409 snprintf(title, sizeof(title), "%s%s",
1410 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001411 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001412 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001413 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001415 width = configSettings->value("/window width", d->width() - 64).toInt();
1416 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001418 x = configSettings->value("/window x");
1419 y = configSettings->value("/window y");
1420 if ((x.isValid())&&(y.isValid()))
1421 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001423 QWidget *widget = new QWidget(this);
1424 QVBoxLayout *layout = new QVBoxLayout(widget);
1425 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001427 split1 = new QSplitter(widget);
1428 split1->setOrientation(Qt::Horizontal);
1429 split1->setChildrenCollapsible(false);
1430
1431 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 menuList = menuView->list;
1433
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001434 split2 = new QSplitter(widget);
1435 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001436 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
1438 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001439 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 configList = configView->list;
1441
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001442 helpText = new ConfigInfoView(widget, "help");
1443
1444 layout->addWidget(split2);
1445 split2->addWidget(split1);
1446 split1->addWidget(configView);
1447 split1->addWidget(menuView);
1448 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450 setTabOrder(configList, helpText);
1451 configList->setFocus();
1452
1453 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001454 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001455 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001457 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001458 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1459
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001460 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001461 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001462 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1463
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001464 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001465 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001466 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1467
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001468 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001469 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001470 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1471
Karsten Wiese3b354c52006-12-13 00:34:08 -08001472 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001473
Karsten Wiese3b354c52006-12-13 00:34:08 -08001474 // Set saveAction's initial state
1475 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001476 configname = xstrdup(conf_get_configname());
1477
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001478 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001479 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001480 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001481 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001482 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001483 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001484 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001485 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001486 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001487 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001488 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001489 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001490 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001491 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001493 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001494 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001495 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001496 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001497 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001498 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001499 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001500 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001501 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001502 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001503
1504 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001505 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001506 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001507 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001508 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001509 SLOT(setOptionMode(QAction *)));
1510
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001511 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1512 configView->showAllAction = new QAction("Show All Options", optGroup);
1513 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001514 configView->showNormalAction->setCheckable(true);
1515 configView->showAllAction->setCheckable(true);
1516 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001517
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001518 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001519 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001520 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001521 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001523 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001524 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001525 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001526 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001529 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001531 toolBar->addAction(loadAction);
1532 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001534 toolBar->addAction(singleViewAction);
1535 toolBar->addAction(splitViewAction);
1536 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001539 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001540 config->addAction(loadAction);
1541 config->addAction(saveAction);
1542 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001543 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001544 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Shlomi Fish66e7c722007-02-14 00:32:58 -08001546 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001547 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001548 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001549
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001551 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001552 optionMenu->addAction(showNameAction);
1553 optionMenu->addAction(showRangeAction);
1554 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001555 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001556 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001557 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001558 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001561 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001562 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001563 helpMenu->addAction(showIntroAction);
1564 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001566 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1567 helpText, SLOT (clicked (const QUrl &)) );
1568
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001569 connect(configList, SIGNAL(menuChanged(struct menu *)),
1570 helpText, SLOT(setInfo(struct menu *)));
1571 connect(configList, SIGNAL(menuSelected(struct menu *)),
1572 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001573 connect(configList, SIGNAL(itemSelected(struct menu *)),
1574 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001575 connect(configList, SIGNAL(parentSelected()),
1576 SLOT(goBack()));
1577 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1578 helpText, SLOT(setInfo(struct menu *)));
1579 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1580 SLOT(changeMenu(struct menu *)));
1581
1582 connect(configList, SIGNAL(gotFocus(struct menu *)),
1583 helpText, SLOT(setInfo(struct menu *)));
1584 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1585 helpText, SLOT(setInfo(struct menu *)));
1586 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1587 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001588 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1589 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001591 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 if (listMode == "single")
1593 showSingleView();
1594 else if (listMode == "full")
1595 showFullView();
1596 else /*if (listMode == "split")*/
1597 showSplitView();
1598
1599 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001600 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 if (ok)
1602 split1->setSizes(sizes);
1603
Roman Zippel7fc925f2006-06-08 22:12:46 -07001604 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 if (ok)
1606 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607}
1608
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609void ConfigMainWindow::loadConfig(void)
1610{
Masahiro Yamada87419082019-03-11 01:13:15 +09001611 QString str;
1612 QByteArray ba;
1613 const char *name;
1614
1615 str = QFileDialog::getOpenFileName(this, "", configname);
1616 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001618
1619 ba = str.toLocal8Bit();
1620 name = ba.data();
1621
1622 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001623 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001624
1625 free(configname);
1626 configname = xstrdup(name);
1627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 ConfigView::updateListAll();
1629}
1630
Michal Marekbac6aa82011-05-25 15:10:25 +02001631bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
Masahiro Yamada87419082019-03-11 01:13:15 +09001633 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001634 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001635 return false;
1636 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001637 conf_write_autoconf(0);
1638
Michal Marekbac6aa82011-05-25 15:10:25 +02001639 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
1642void ConfigMainWindow::saveConfigAs(void)
1643{
Masahiro Yamada87419082019-03-11 01:13:15 +09001644 QString str;
1645 QByteArray ba;
1646 const char *name;
1647
1648 str = QFileDialog::getSaveFileName(this, "", configname);
1649 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001651
1652 ba = str.toLocal8Bit();
1653 name = ba.data();
1654
1655 if (conf_write(name)) {
1656 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1657 }
1658 conf_write_autoconf(0);
1659
1660 free(configname);
1661 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662}
1663
Roman Zippel43bf6122006-06-08 22:12:45 -07001664void ConfigMainWindow::searchConfig(void)
1665{
1666 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001667 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001668 searchWindow->show();
1669}
1670
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001671void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001673 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674}
1675
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001676void ConfigMainWindow::changeMenu(struct menu *menu)
1677{
1678 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001679}
1680
Roman Zippelb65a47e2006-06-08 22:12:47 -07001681void ConfigMainWindow::setMenuLink(struct menu *menu)
1682{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001683 struct menu *parent;
1684 ConfigList* list = NULL;
1685 ConfigItem* item;
1686
1687 if (configList->menuSkip(menu))
1688 return;
1689
1690 switch (configList->mode) {
1691 case singleMode:
1692 list = configList;
1693 parent = menu_get_parent_menu(menu);
1694 if (!parent)
1695 return;
1696 list->setRootMenu(parent);
1697 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001698 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001699 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001700 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001701 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001702 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001703 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001704 parent = menu_get_parent_menu(menu->parent);
1705 if (!parent)
1706 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001707
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001708 /* Select the config view */
1709 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001710 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001711 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001712 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001713 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001714
1715 menuList->setRootMenu(parent);
1716 menuList->clearSelection();
1717 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001718 }
1719 break;
1720 case fullMode:
1721 list = configList;
1722 break;
1723 default:
1724 break;
1725 }
1726
1727 if (list) {
1728 item = list->findConfigItem(menu);
1729 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001730 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001731 list->scrollToItem(item);
1732 list->setFocus();
1733 }
1734 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001735}
1736
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737void ConfigMainWindow::listFocusChanged(void)
1738{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001739 if (menuList->mode == menuMode)
1740 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741}
1742
1743void ConfigMainWindow::goBack(void)
1744{
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001745qInfo() << __FUNCTION__;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001746 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001747 return;
1748
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001749 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750}
1751
1752void ConfigMainWindow::showSingleView(void)
1753{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001754 singleViewAction->setEnabled(false);
1755 singleViewAction->setChecked(true);
1756 splitViewAction->setEnabled(true);
1757 splitViewAction->setChecked(false);
1758 fullViewAction->setEnabled(true);
1759 fullViewAction->setChecked(false);
1760
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001761 backAction->setEnabled(true);
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001764 menuList->setRootMenu(0);
1765 configList->mode = singleMode;
1766 if (configList->rootEntry == &rootmenu)
1767 configList->updateListAll();
1768 else
1769 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 configList->setFocus();
1771}
1772
1773void ConfigMainWindow::showSplitView(void)
1774{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001775 singleViewAction->setEnabled(true);
1776 singleViewAction->setChecked(false);
1777 splitViewAction->setEnabled(false);
1778 splitViewAction->setChecked(true);
1779 fullViewAction->setEnabled(true);
1780 fullViewAction->setChecked(false);
1781
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001782 backAction->setEnabled(false);
1783
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001784 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001785 if (configList->rootEntry == &rootmenu)
1786 configList->updateListAll();
1787 else
1788 configList->setRootMenu(&rootmenu);
1789 configList->setAllOpen(true);
1790 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001791 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001792 menuList->setRootMenu(&rootmenu);
1793 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 menuView->show();
1795 menuList->setFocus();
1796}
1797
1798void ConfigMainWindow::showFullView(void)
1799{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001800 singleViewAction->setEnabled(true);
1801 singleViewAction->setChecked(false);
1802 splitViewAction->setEnabled(true);
1803 splitViewAction->setChecked(false);
1804 fullViewAction->setEnabled(false);
1805 fullViewAction->setChecked(true);
1806
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001807 backAction->setEnabled(false);
1808
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001810 menuList->setRootMenu(0);
1811 configList->mode = fullMode;
1812 if (configList->rootEntry == &rootmenu)
1813 configList->updateListAll();
1814 else
1815 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 configList->setFocus();
1817}
1818
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819/*
1820 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 */
1822void ConfigMainWindow::closeEvent(QCloseEvent* e)
1823{
Karsten Wieseb3214292006-12-13 00:34:06 -08001824 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 e->accept();
1826 return;
1827 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001828 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001830 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1831 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1832 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 switch (mb.exec()) {
1834 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001835 if (saveConfig())
1836 e->accept();
1837 else
1838 e->ignore();
1839 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 case QMessageBox::No:
1841 e->accept();
1842 break;
1843 case QMessageBox::Cancel:
1844 e->ignore();
1845 break;
1846 }
1847}
1848
1849void ConfigMainWindow::showIntro(void)
1850{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001851 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 "For each option, a blank box indicates the feature is disabled, a check\n"
1853 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1854 "as a module. Clicking on the box will cycle through the three states.\n\n"
1855 "If you do not see an option (e.g., a device driver) that you believe\n"
1856 "should be present, try turning on Show All Options under the Options menu.\n"
1857 "Although there is no cross reference yet to help you figure out what other\n"
1858 "options must be enabled to support the option you are interested in, you can\n"
1859 "still view the help of a grayed-out option.\n\n"
1860 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001861 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
1863 QMessageBox::information(this, "qconf", str);
1864}
1865
1866void ConfigMainWindow::showAbout(void)
1867{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001868 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001869 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001870 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
1872 QMessageBox::information(this, "qconf", str);
1873}
1874
1875void ConfigMainWindow::saveSettings(void)
1876{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001877 configSettings->setValue("/window x", pos().x());
1878 configSettings->setValue("/window y", pos().y());
1879 configSettings->setValue("/window width", size().width());
1880 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
1882 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001883 switch(configList->mode) {
1884 case singleMode :
1885 entry = "single";
1886 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001888 case symbolMode :
1889 entry = "split";
1890 break;
1891
1892 case fullMode :
1893 entry = "full";
1894 break;
1895
1896 default:
1897 break;
1898 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001899 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Roman Zippel7fc925f2006-06-08 22:12:46 -07001901 configSettings->writeSizes("/split1", split1->sizes());
1902 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903}
1904
Karsten Wiese3b354c52006-12-13 00:34:08 -08001905void ConfigMainWindow::conf_changed(void)
1906{
1907 if (saveAction)
1908 saveAction->setEnabled(conf_get_changed());
1909}
1910
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911void fixup_rootmenu(struct menu *menu)
1912{
1913 struct menu *child;
1914 static int menu_cnt = 0;
1915
1916 menu->flags |= MENU_ROOT;
1917 for (child = menu->list; child; child = child->next) {
1918 if (child->prompt && child->prompt->type == P_MENU) {
1919 menu_cnt++;
1920 fixup_rootmenu(child);
1921 menu_cnt--;
1922 } else if (!menu_cnt)
1923 fixup_rootmenu(child);
1924 }
1925}
1926
1927static const char *progname;
1928
1929static void usage(void)
1930{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001931 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 exit(0);
1933}
1934
1935int main(int ac, char** av)
1936{
1937 ConfigMainWindow* v;
1938 const char *name;
1939
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 progname = av[0];
1941 configApp = new QApplication(ac, av);
1942 if (ac > 1 && av[1][0] == '-') {
1943 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001944 case 's':
1945 conf_set_message_callback(NULL);
1946 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 case 'h':
1948 case '?':
1949 usage();
1950 }
1951 name = av[2];
1952 } else
1953 name = av[1];
1954 if (!name)
1955 usage();
1956
1957 conf_parse(name);
1958 fixup_rootmenu(&rootmenu);
1959 conf_read(NULL);
1960 //zconfdump(stdout);
1961
Roman Zippel7fc925f2006-06-08 22:12:46 -07001962 configSettings = new ConfigSettings();
1963 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 v = new ConfigMainWindow();
1965
1966 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1968 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001969 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 configApp->exec();
1971
Roman Zippel7fc925f2006-06-08 22:12:46 -07001972 configSettings->endGroup();
1973 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001974 delete v;
1975 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001976
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 return 0;
1978}