blob: 29ca4823cfb99cdaf624d11caff585099afe0253 [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);
Boris Barbulovski92119932015-09-22 11:36:16 -07001458 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001459 backAction->setEnabled(false);
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);
Boris Barbulovski92119932015-09-22 11:36:16 -07001462 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001463 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001464 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Boris Barbulovski92119932015-09-22 11:36:16 -07001465 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001466 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001467 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Boris Barbulovski92119932015-09-22 11:36:16 -07001468 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001469 conf_set_changed_callback(conf_changed);
1470 // Set saveAction's initial state
1471 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001472 configname = xstrdup(conf_get_configname());
1473
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001474 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001475 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001476 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001477 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001478 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001479 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001480 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001481 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001482 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001483 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001484 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001485 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001486 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001487 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001489 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001490 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001491 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001492 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001493 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001494 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001495 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001496 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001497 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001498 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001499
1500 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001501 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001502 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001503 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001504 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001505 SLOT(setOptionMode(QAction *)));
1506
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001507 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1508 configView->showAllAction = new QAction("Show All Options", optGroup);
1509 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001510 configView->showNormalAction->setCheckable(true);
1511 configView->showAllAction->setCheckable(true);
1512 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001513
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001514 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001515 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001516 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001517 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001519 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001520 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001521 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001522 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001525 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001527 toolBar->addAction(loadAction);
1528 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001530 toolBar->addAction(singleViewAction);
1531 toolBar->addAction(splitViewAction);
1532 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
1534 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001535 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001536 config->addAction(loadAction);
1537 config->addAction(saveAction);
1538 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001539 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001540 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Shlomi Fish66e7c722007-02-14 00:32:58 -08001542 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001543 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001544 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001545
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001547 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001548 optionMenu->addAction(showNameAction);
1549 optionMenu->addAction(showRangeAction);
1550 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001551 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001552 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001553 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001554 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001557 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001558 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001559 helpMenu->addAction(showIntroAction);
1560 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001562 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1563 helpText, SLOT (clicked (const QUrl &)) );
1564
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001565 connect(configList, SIGNAL(menuChanged(struct menu *)),
1566 helpText, SLOT(setInfo(struct menu *)));
1567 connect(configList, SIGNAL(menuSelected(struct menu *)),
1568 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001569 connect(configList, SIGNAL(itemSelected(struct menu *)),
1570 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001571 connect(configList, SIGNAL(parentSelected()),
1572 SLOT(goBack()));
1573 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1574 helpText, SLOT(setInfo(struct menu *)));
1575 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1576 SLOT(changeMenu(struct menu *)));
1577
1578 connect(configList, SIGNAL(gotFocus(struct menu *)),
1579 helpText, SLOT(setInfo(struct menu *)));
1580 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1581 helpText, SLOT(setInfo(struct menu *)));
1582 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1583 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001584 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1585 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001587 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 if (listMode == "single")
1589 showSingleView();
1590 else if (listMode == "full")
1591 showFullView();
1592 else /*if (listMode == "split")*/
1593 showSplitView();
1594
1595 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001596 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 if (ok)
1598 split1->setSizes(sizes);
1599
Roman Zippel7fc925f2006-06-08 22:12:46 -07001600 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 if (ok)
1602 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605void ConfigMainWindow::loadConfig(void)
1606{
Masahiro Yamada87419082019-03-11 01:13:15 +09001607 QString str;
1608 QByteArray ba;
1609 const char *name;
1610
1611 str = QFileDialog::getOpenFileName(this, "", configname);
1612 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001614
1615 ba = str.toLocal8Bit();
1616 name = ba.data();
1617
1618 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001619 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001620
1621 free(configname);
1622 configname = xstrdup(name);
1623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 ConfigView::updateListAll();
1625}
1626
Michal Marekbac6aa82011-05-25 15:10:25 +02001627bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Masahiro Yamada87419082019-03-11 01:13:15 +09001629 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001630 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001631 return false;
1632 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001633 conf_write_autoconf(0);
1634
Michal Marekbac6aa82011-05-25 15:10:25 +02001635 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
1637
1638void ConfigMainWindow::saveConfigAs(void)
1639{
Masahiro Yamada87419082019-03-11 01:13:15 +09001640 QString str;
1641 QByteArray ba;
1642 const char *name;
1643
1644 str = QFileDialog::getSaveFileName(this, "", configname);
1645 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001647
1648 ba = str.toLocal8Bit();
1649 name = ba.data();
1650
1651 if (conf_write(name)) {
1652 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1653 }
1654 conf_write_autoconf(0);
1655
1656 free(configname);
1657 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Roman Zippel43bf6122006-06-08 22:12:45 -07001660void ConfigMainWindow::searchConfig(void)
1661{
1662 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001663 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001664 searchWindow->show();
1665}
1666
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001667void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001669 configList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001670
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001671 if (configList->rootEntry->parent == &rootmenu)
1672 backAction->setEnabled(false);
1673 else
1674 backAction->setEnabled(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675}
1676
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001677void ConfigMainWindow::changeMenu(struct menu *menu)
1678{
1679 menuList->setRootMenu(menu);
1680
1681 if (menuList->rootEntry->parent == &rootmenu)
1682 backAction->setEnabled(false);
1683 else
1684 backAction->setEnabled(true);
1685}
1686
Roman Zippelb65a47e2006-06-08 22:12:47 -07001687void ConfigMainWindow::setMenuLink(struct menu *menu)
1688{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001689 struct menu *parent;
1690 ConfigList* list = NULL;
1691 ConfigItem* item;
1692
1693 if (configList->menuSkip(menu))
1694 return;
1695
1696 switch (configList->mode) {
1697 case singleMode:
1698 list = configList;
1699 parent = menu_get_parent_menu(menu);
1700 if (!parent)
1701 return;
1702 list->setRootMenu(parent);
1703 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001704 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001705 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001706 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001707 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001708 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001709 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001710 parent = menu_get_parent_menu(menu->parent);
1711 if (!parent)
1712 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001713
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001714 /* Select the config view */
1715 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001716 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001717 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001718 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001719 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001720
1721 menuList->setRootMenu(parent);
1722 menuList->clearSelection();
1723 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001724 }
1725 break;
1726 case fullMode:
1727 list = configList;
1728 break;
1729 default:
1730 break;
1731 }
1732
1733 if (list) {
1734 item = list->findConfigItem(menu);
1735 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001736 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001737 list->scrollToItem(item);
1738 list->setFocus();
1739 }
1740 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001741}
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743void ConfigMainWindow::listFocusChanged(void)
1744{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001745 if (menuList->mode == menuMode)
1746 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}
1748
1749void ConfigMainWindow::goBack(void)
1750{
Boris Barbulovski5df9da92015-09-22 11:36:36 -07001751 ConfigItem* item, *oldSelection;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001752
1753 configList->setParentMenu();
1754 if (configList->rootEntry == &rootmenu)
1755 backAction->setEnabled(false);
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001756
1757 if (menuList->selectedItems().count() == 0)
1758 return;
1759
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001760 item = (ConfigItem*)menuList->selectedItems().first();
Boris Barbulovski5df9da92015-09-22 11:36:36 -07001761 oldSelection = item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001762 while (item) {
1763 if (item->menu == configList->rootEntry) {
Boris Barbulovski5df9da92015-09-22 11:36:36 -07001764 oldSelection->setSelected(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001765 item->setSelected(true);
1766 break;
1767 }
1768 item = (ConfigItem*)item->parent();
1769 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770}
1771
1772void ConfigMainWindow::showSingleView(void)
1773{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001774 singleViewAction->setEnabled(false);
1775 singleViewAction->setChecked(true);
1776 splitViewAction->setEnabled(true);
1777 splitViewAction->setChecked(false);
1778 fullViewAction->setEnabled(true);
1779 fullViewAction->setChecked(false);
1780
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001782 menuList->setRootMenu(0);
1783 configList->mode = singleMode;
1784 if (configList->rootEntry == &rootmenu)
1785 configList->updateListAll();
1786 else
1787 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 configList->setFocus();
1789}
1790
1791void ConfigMainWindow::showSplitView(void)
1792{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001793 singleViewAction->setEnabled(true);
1794 singleViewAction->setChecked(false);
1795 splitViewAction->setEnabled(false);
1796 splitViewAction->setChecked(true);
1797 fullViewAction->setEnabled(true);
1798 fullViewAction->setChecked(false);
1799
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001800 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001801 if (configList->rootEntry == &rootmenu)
1802 configList->updateListAll();
1803 else
1804 configList->setRootMenu(&rootmenu);
1805 configList->setAllOpen(true);
1806 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001807 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001808 menuList->setRootMenu(&rootmenu);
1809 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 menuView->show();
1811 menuList->setFocus();
1812}
1813
1814void ConfigMainWindow::showFullView(void)
1815{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001816 singleViewAction->setEnabled(true);
1817 singleViewAction->setChecked(false);
1818 splitViewAction->setEnabled(true);
1819 splitViewAction->setChecked(false);
1820 fullViewAction->setEnabled(false);
1821 fullViewAction->setChecked(true);
1822
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001824 menuList->setRootMenu(0);
1825 configList->mode = fullMode;
1826 if (configList->rootEntry == &rootmenu)
1827 configList->updateListAll();
1828 else
1829 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 configList->setFocus();
1831}
1832
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833/*
1834 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 */
1836void ConfigMainWindow::closeEvent(QCloseEvent* e)
1837{
Karsten Wieseb3214292006-12-13 00:34:06 -08001838 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 e->accept();
1840 return;
1841 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001842 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001844 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1845 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1846 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 switch (mb.exec()) {
1848 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001849 if (saveConfig())
1850 e->accept();
1851 else
1852 e->ignore();
1853 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 case QMessageBox::No:
1855 e->accept();
1856 break;
1857 case QMessageBox::Cancel:
1858 e->ignore();
1859 break;
1860 }
1861}
1862
1863void ConfigMainWindow::showIntro(void)
1864{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001865 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 "For each option, a blank box indicates the feature is disabled, a check\n"
1867 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1868 "as a module. Clicking on the box will cycle through the three states.\n\n"
1869 "If you do not see an option (e.g., a device driver) that you believe\n"
1870 "should be present, try turning on Show All Options under the Options menu.\n"
1871 "Although there is no cross reference yet to help you figure out what other\n"
1872 "options must be enabled to support the option you are interested in, you can\n"
1873 "still view the help of a grayed-out option.\n\n"
1874 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001875 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
1877 QMessageBox::information(this, "qconf", str);
1878}
1879
1880void ConfigMainWindow::showAbout(void)
1881{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001882 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001883 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001884 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 QMessageBox::information(this, "qconf", str);
1887}
1888
1889void ConfigMainWindow::saveSettings(void)
1890{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001891 configSettings->setValue("/window x", pos().x());
1892 configSettings->setValue("/window y", pos().y());
1893 configSettings->setValue("/window width", size().width());
1894 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
1896 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001897 switch(configList->mode) {
1898 case singleMode :
1899 entry = "single";
1900 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001902 case symbolMode :
1903 entry = "split";
1904 break;
1905
1906 case fullMode :
1907 entry = "full";
1908 break;
1909
1910 default:
1911 break;
1912 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001913 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
Roman Zippel7fc925f2006-06-08 22:12:46 -07001915 configSettings->writeSizes("/split1", split1->sizes());
1916 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917}
1918
Karsten Wiese3b354c52006-12-13 00:34:08 -08001919void ConfigMainWindow::conf_changed(void)
1920{
1921 if (saveAction)
1922 saveAction->setEnabled(conf_get_changed());
1923}
1924
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925void fixup_rootmenu(struct menu *menu)
1926{
1927 struct menu *child;
1928 static int menu_cnt = 0;
1929
1930 menu->flags |= MENU_ROOT;
1931 for (child = menu->list; child; child = child->next) {
1932 if (child->prompt && child->prompt->type == P_MENU) {
1933 menu_cnt++;
1934 fixup_rootmenu(child);
1935 menu_cnt--;
1936 } else if (!menu_cnt)
1937 fixup_rootmenu(child);
1938 }
1939}
1940
1941static const char *progname;
1942
1943static void usage(void)
1944{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001945 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 exit(0);
1947}
1948
1949int main(int ac, char** av)
1950{
1951 ConfigMainWindow* v;
1952 const char *name;
1953
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 progname = av[0];
1955 configApp = new QApplication(ac, av);
1956 if (ac > 1 && av[1][0] == '-') {
1957 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001958 case 's':
1959 conf_set_message_callback(NULL);
1960 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 case 'h':
1962 case '?':
1963 usage();
1964 }
1965 name = av[2];
1966 } else
1967 name = av[1];
1968 if (!name)
1969 usage();
1970
1971 conf_parse(name);
1972 fixup_rootmenu(&rootmenu);
1973 conf_read(NULL);
1974 //zconfdump(stdout);
1975
Roman Zippel7fc925f2006-06-08 22:12:46 -07001976 configSettings = new ConfigSettings();
1977 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 v = new ConfigMainWindow();
1979
1980 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1982 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001983 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 configApp->exec();
1985
Roman Zippel7fc925f2006-06-08 22:12:46 -07001986 configSettings->endGroup();
1987 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001988 delete v;
1989 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 return 0;
1992}