blob: 86bc8ded8de8ce9f14dc4724ae55bce208f62bb3 [file] [log] [blame]
Masahiro Yamada0c874102018-12-18 21:13:35 +09001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07004 * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Boris Barbulovski85eaf282015-09-22 11:36:03 -07007#include <QAction>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +02008#include <QApplication>
9#include <QCloseEvent>
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +020010#include <QDebug>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020011#include <QDesktopWidget>
Boris Barbulovskibea00772015-09-22 11:36:04 -070012#include <QFileDialog>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020013#include <QLabel>
14#include <QLayout>
15#include <QList>
Boris Barbulovski76bede82015-09-22 11:36:07 -070016#include <QMenu>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020017#include <QMenuBar>
18#include <QMessageBox>
19#include <QToolBar>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <stdlib.h>
22
23#include "lkc.h"
24#include "qconf.h"
25
Masahiro Yamada3b541978562018-12-21 17:33:07 +090026#include "images.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070030static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Boris Barbulovski85eaf282015-09-22 11:36:03 -070032QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080033
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070034static inline QString qgettext(const char* str)
35{
Sam Ravnborg694c49a2018-05-22 21:36:12 +020036 return QString::fromLocal8Bit(str);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070037}
38
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010039ConfigSettings::ConfigSettings()
40 : QSettings("kernel.org", "qconf")
41{
42}
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/**
45 * Reads a list of integer values from the application settings.
46 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070047QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070049 QList<int> result;
Li Zefanc1f96f02010-05-07 13:58:04 +080050
Boris Barbulovski83c3a1b2016-11-30 14:57:55 -080051 if (contains(key))
52 {
53 QStringList entryList = value(key).toStringList();
54 QStringList::Iterator it;
55
56 for (it = entryList.begin(); it != entryList.end(); ++it)
57 result.push_back((*it).toInt());
58
59 *ok = true;
60 }
61 else
62 *ok = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 return result;
65}
66
67/**
68 * Writes a list of integer values to the application settings.
69 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070070bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
72 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070073 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 for (it = value.begin(); it != value.end(); ++it)
76 stringList.push_back(QString::number(*it));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070077 setValue(key, stringList);
Boris Barbulovski59e56442015-09-22 11:36:18 -070078
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070079 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Boris Barbulovski59e56442015-09-22 11:36:18 -070082
83/*
84 * set the new data
85 * TODO check the value
86 */
87void ConfigItem::okRename(int col)
88{
89}
90
91/*
92 * update the displayed of a menu entry
93 */
94void ConfigItem::updateMenu(void)
95{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070096 ConfigList* list;
97 struct symbol* sym;
98 struct property *prop;
99 QString prompt;
100 int type;
101 tristate expr;
102
103 list = listView();
104 if (goParent) {
105 setPixmap(promptColIdx, list->menuBackPix);
106 prompt = "..";
107 goto set_prompt;
108 }
109
110 sym = menu->sym;
111 prop = menu->prompt;
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200112 prompt = qgettext(menu_get_prompt(menu));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700113
114 if (prop) switch (prop->type) {
115 case P_MENU:
116 if (list->mode == singleMode || list->mode == symbolMode) {
117 /* a menuconfig entry is displayed differently
118 * depending whether it's at the view root or a child.
119 */
120 if (sym && list->rootEntry == menu)
121 break;
122 setPixmap(promptColIdx, list->menuPix);
123 } else {
124 if (sym)
125 break;
126 setPixmap(promptColIdx, QIcon());
127 }
128 goto set_prompt;
129 case P_COMMENT:
130 setPixmap(promptColIdx, QIcon());
131 goto set_prompt;
132 default:
133 ;
134 }
135 if (!sym)
136 goto set_prompt;
137
138 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
139
140 type = sym_get_type(sym);
141 switch (type) {
142 case S_BOOLEAN:
143 case S_TRISTATE:
144 char ch;
145
Marco Ammonbaa23ec2019-07-04 12:50:41 +0200146 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700147 setPixmap(promptColIdx, QIcon());
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200148 setText(noColIdx, QString());
149 setText(modColIdx, QString());
150 setText(yesColIdx, QString());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700151 break;
152 }
153 expr = sym_get_tristate_value(sym);
154 switch (expr) {
155 case yes:
156 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
157 setPixmap(promptColIdx, list->choiceYesPix);
158 else
159 setPixmap(promptColIdx, list->symbolYesPix);
160 setText(yesColIdx, "Y");
161 ch = 'Y';
162 break;
163 case mod:
164 setPixmap(promptColIdx, list->symbolModPix);
165 setText(modColIdx, "M");
166 ch = 'M';
167 break;
168 default:
169 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
170 setPixmap(promptColIdx, list->choiceNoPix);
171 else
172 setPixmap(promptColIdx, list->symbolNoPix);
173 setText(noColIdx, "N");
174 ch = 'N';
175 break;
176 }
177 if (expr != no)
178 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
179 if (expr != mod)
180 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
181 if (expr != yes)
182 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
183
184 setText(dataColIdx, QChar(ch));
185 break;
186 case S_INT:
187 case S_HEX:
188 case S_STRING:
189 const char* data;
190
191 data = sym_get_string_value(sym);
192
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700193 setText(dataColIdx, data);
194 if (type == S_STRING)
195 prompt = QString("%1: %2").arg(prompt).arg(data);
196 else
197 prompt = QString("(%2) %1").arg(prompt).arg(data);
198 break;
199 }
200 if (!sym_has_value(sym) && visible)
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200201 prompt += " (NEW)";
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700202set_prompt:
203 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700204}
205
206void ConfigItem::testUpdateMenu(bool v)
207{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700208 ConfigItem* i;
209
210 visible = v;
211 if (!menu)
212 return;
213
214 sym_calc_value(menu->sym);
215 if (menu->flags & MENU_CHANGED) {
216 /* the menu entry changed, so update all list items */
217 menu->flags &= ~MENU_CHANGED;
218 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
219 i->updateMenu();
220 } else if (listView()->updateAll)
221 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700222}
223
224
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700225/*
226 * construct a menu entry
227 */
228void ConfigItem::init(void)
229{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700230 if (menu) {
231 ConfigList* list = listView();
232 nextItem = (ConfigItem*)menu->data;
233 menu->data = this;
234
235 if (list->mode != fullMode)
236 setExpanded(true);
237 sym_calc_value(menu->sym);
238 }
239 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700240}
241
242/*
243 * destruct a menu entry
244 */
245ConfigItem::~ConfigItem(void)
246{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700247 if (menu) {
248 ConfigItem** ip = (ConfigItem**)&menu->data;
249 for (; *ip; ip = &(*ip)->nextItem) {
250 if (*ip == this) {
251 *ip = nextItem;
252 break;
253 }
254 }
255 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700256}
257
Roman Zippel43bf6122006-06-08 22:12:45 -0700258ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
259 : Parent(parent)
260{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700261 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700262}
263
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700264void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700267 if (sym_get_string_value(item->menu->sym))
268 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
269 else
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200270 setText(QString());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 Parent::show();
272 setFocus();
273}
274
275void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
276{
277 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200278 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200280 case Qt::Key_Return:
281 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700282 sym_set_string_value(item->menu->sym, text().toLatin1());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 parent()->updateList(item);
284 break;
285 default:
286 Parent::keyPressEvent(e);
287 return;
288 }
289 e->accept();
290 parent()->list->setFocus();
291 hide();
292}
293
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700294ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700295 : Parent(p),
296 updateAll(false),
297 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
298 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
299 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700300 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700301 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700302{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700303 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700304 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700305 setRootIsDecorated(true);
306
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700307 setVerticalScrollMode(ScrollPerPixel);
308 setHorizontalScrollMode(ScrollPerPixel);
309
Masahiro Yamada97bebbc2020-07-30 02:46:17 +0900310 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700311
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700312 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700313 SLOT(updateSelection(void)));
314
315 if (name) {
316 configSettings->beginGroup(name);
317 showName = configSettings->value("/showName", false).toBool();
318 showRange = configSettings->value("/showRange", false).toBool();
319 showData = configSettings->value("/showData", false).toBool();
320 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
321 configSettings->endGroup();
322 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
323 }
324
325 addColumn(promptColIdx);
326
327 reinit();
328}
329
330bool ConfigList::menuSkip(struct menu *menu)
331{
332 if (optMode == normalOpt && menu_is_visible(menu))
333 return false;
334 if (optMode == promptOpt && menu_has_prompt(menu))
335 return false;
336 if (optMode == allOpt)
337 return false;
338 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700339}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700340
341void ConfigList::reinit(void)
342{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700343 removeColumn(dataColIdx);
344 removeColumn(yesColIdx);
345 removeColumn(modColIdx);
346 removeColumn(noColIdx);
347 removeColumn(nameColIdx);
348
349 if (showName)
350 addColumn(nameColIdx);
351 if (showRange) {
352 addColumn(noColIdx);
353 addColumn(modColIdx);
354 addColumn(yesColIdx);
355 }
356 if (showData)
357 addColumn(dataColIdx);
358
359 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700360}
361
362void ConfigList::saveSettings(void)
363{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700364 if (!objectName().isEmpty()) {
365 configSettings->beginGroup(objectName());
366 configSettings->setValue("/showName", showName);
367 configSettings->setValue("/showRange", showRange);
368 configSettings->setValue("/showData", showData);
369 configSettings->setValue("/optionMode", (int)optMode);
370 configSettings->endGroup();
371 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700372}
373
374ConfigItem* ConfigList::findConfigItem(struct menu *menu)
375{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700376 ConfigItem* item = (ConfigItem*)menu->data;
377
378 for (; item; item = item->nextItem) {
379 if (this == item->listView())
380 break;
381 }
382
383 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700384}
385
386void ConfigList::updateSelection(void)
387{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700388 struct menu *menu;
389 enum prop_type type;
390
Boris Barbulovskibe596aa2015-09-22 11:36:28 -0700391 if (selectedItems().count() == 0)
392 return;
393
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700394 ConfigItem* item = (ConfigItem*)selectedItems().first();
395 if (!item)
396 return;
397
398 menu = item->menu;
399 emit menuChanged(menu);
400 if (!menu)
401 return;
402 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
403 if (mode == menuMode && type == P_MENU)
404 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700405}
406
407void ConfigList::updateList(ConfigItem* item)
408{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700409 ConfigItem* last = 0;
410
411 if (!rootEntry) {
412 if (mode != listMode)
413 goto update;
414 QTreeWidgetItemIterator it(this);
415 ConfigItem* item;
416
417 while (*it) {
418 item = (ConfigItem*)(*it);
419 if (!item->menu)
420 continue;
421 item->testUpdateMenu(menu_is_visible(item->menu));
422
423 ++it;
424 }
425 return;
426 }
427
428 if (rootEntry != &rootmenu && (mode == singleMode ||
429 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
Boris Barbulovskiee7298f2015-09-22 11:36:37 -0700430 item = (ConfigItem *)topLevelItem(0);
Mauro Carvalho Chehabcc1c08e2020-06-30 08:26:40 +0200431 if (!item && mode != symbolMode) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700432 item = new ConfigItem(this, 0, true);
Mauro Carvalho Chehabcc1c08e2020-06-30 08:26:40 +0200433 last = item;
434 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700435 }
436 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
437 rootEntry->sym && rootEntry->prompt) {
438 item = last ? last->nextSibling() : firstChild();
439 if (!item)
440 item = new ConfigItem(this, last, rootEntry, true);
441 else
442 item->testUpdateMenu(true);
443
444 updateMenuList(item, rootEntry);
445 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700446 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700447 return;
448 }
449update:
450 updateMenuList(this, rootEntry);
451 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700452 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700453}
454
455void ConfigList::setValue(ConfigItem* item, tristate val)
456{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700457 struct symbol* sym;
458 int type;
459 tristate oldval;
460
461 sym = item->menu ? item->menu->sym : 0;
462 if (!sym)
463 return;
464
465 type = sym_get_type(sym);
466 switch (type) {
467 case S_BOOLEAN:
468 case S_TRISTATE:
469 oldval = sym_get_tristate_value(sym);
470
471 if (!sym_set_tristate_value(sym, val))
472 return;
473 if (oldval == no && item->menu->list)
474 item->setExpanded(true);
475 parent()->updateList(item);
476 break;
477 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700478}
479
480void ConfigList::changeValue(ConfigItem* item)
481{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700482 struct symbol* sym;
483 struct menu* menu;
484 int type, oldexpr, newexpr;
485
486 menu = item->menu;
487 if (!menu)
488 return;
489 sym = menu->sym;
490 if (!sym) {
491 if (item->menu->list)
492 item->setExpanded(!item->isExpanded());
493 return;
494 }
495
496 type = sym_get_type(sym);
497 switch (type) {
498 case S_BOOLEAN:
499 case S_TRISTATE:
500 oldexpr = sym_get_tristate_value(sym);
501 newexpr = sym_toggle_tristate_value(sym);
502 if (item->menu->list) {
503 if (oldexpr == newexpr)
504 item->setExpanded(!item->isExpanded());
505 else if (oldexpr == no)
506 item->setExpanded(true);
507 }
508 if (oldexpr != newexpr)
509 parent()->updateList(item);
510 break;
511 case S_INT:
512 case S_HEX:
513 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700514 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700515 break;
516 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700517}
518
519void ConfigList::setRootMenu(struct menu *menu)
520{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700521 enum prop_type type;
522
523 if (rootEntry == menu)
524 return;
525 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
526 if (type != P_MENU)
527 return;
528 updateMenuList(this, 0);
529 rootEntry = menu;
530 updateListAll();
531 if (currentItem()) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200532 setSelected(currentItem(), hasFocus());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700533 scrollToItem(currentItem());
534 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700535}
536
537void ConfigList::setParentMenu(void)
538{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700539 ConfigItem* item;
540 struct menu *oldroot;
541
542 oldroot = rootEntry;
543 if (rootEntry == &rootmenu)
544 return;
545 setRootMenu(menu_get_parent_menu(rootEntry->parent));
546
547 QTreeWidgetItemIterator it(this);
548 while (*it) {
549 item = (ConfigItem *)(*it);
550 if (item->menu == oldroot) {
551 setCurrentItem(item);
552 scrollToItem(item);
553 break;
554 }
555
556 ++it;
557 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700558}
559
560/*
561 * update all the children of a menu entry
562 * removes/adds the entries from the parent widget as necessary
563 *
564 * parent: either the menu list widget or a menu entry widget
565 * menu: entry to be updated
566 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700567void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700568{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700569 struct menu* child;
570 ConfigItem* item;
571 ConfigItem* last;
572 bool visible;
573 enum prop_type type;
574
575 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700576 while (parent->childCount() > 0)
577 {
578 delete parent->takeChild(0);
579 }
580
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700581 return;
582 }
583
584 last = parent->firstChild();
585 if (last && !last->goParent)
586 last = 0;
587 for (child = menu->list; child; child = child->next) {
588 item = last ? last->nextSibling() : parent->firstChild();
589 type = child->prompt ? child->prompt->type : P_UNKNOWN;
590
591 switch (mode) {
592 case menuMode:
593 if (!(child->flags & MENU_ROOT))
594 goto hide;
595 break;
596 case symbolMode:
597 if (child->flags & MENU_ROOT)
598 goto hide;
599 break;
600 default:
601 break;
602 }
603
604 visible = menu_is_visible(child);
605 if (!menuSkip(child)) {
606 if (!child->sym && !child->list && !child->prompt)
607 continue;
608 if (!item || item->menu != child)
609 item = new ConfigItem(parent, last, child, visible);
610 else
611 item->testUpdateMenu(visible);
612
613 if (mode == fullMode || mode == menuMode || type != P_MENU)
614 updateMenuList(item, child);
615 else
616 updateMenuList(item, 0);
617 last = item;
618 continue;
619 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200620hide:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700621 if (item && item->menu == child) {
622 last = parent->firstChild();
623 if (last == item)
624 last = 0;
625 else while (last->nextSibling() != item)
626 last = last->nextSibling();
627 delete item;
628 }
629 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700630}
631
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700632void ConfigList::updateMenuList(ConfigList *parent, struct menu* menu)
633{
634 struct menu* child;
635 ConfigItem* item;
636 ConfigItem* last;
637 bool visible;
638 enum prop_type type;
639
640 if (!menu) {
641 while (parent->topLevelItemCount() > 0)
642 {
643 delete parent->takeTopLevelItem(0);
644 }
645
646 return;
647 }
648
649 last = (ConfigItem*)parent->topLevelItem(0);
650 if (last && !last->goParent)
651 last = 0;
652 for (child = menu->list; child; child = child->next) {
653 item = last ? last->nextSibling() : (ConfigItem*)parent->topLevelItem(0);
654 type = child->prompt ? child->prompt->type : P_UNKNOWN;
655
656 switch (mode) {
657 case menuMode:
658 if (!(child->flags & MENU_ROOT))
659 goto hide;
660 break;
661 case symbolMode:
662 if (child->flags & MENU_ROOT)
663 goto hide;
664 break;
665 default:
666 break;
667 }
668
669 visible = menu_is_visible(child);
670 if (!menuSkip(child)) {
671 if (!child->sym && !child->list && !child->prompt)
672 continue;
673 if (!item || item->menu != child)
674 item = new ConfigItem(parent, last, child, visible);
675 else
676 item->testUpdateMenu(visible);
677
678 if (mode == fullMode || mode == menuMode || type != P_MENU)
679 updateMenuList(item, child);
680 else
681 updateMenuList(item, 0);
682 last = item;
683 continue;
684 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200685hide:
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700686 if (item && item->menu == child) {
687 last = (ConfigItem*)parent->topLevelItem(0);
688 if (last == item)
689 last = 0;
690 else while (last->nextSibling() != item)
691 last = last->nextSibling();
692 delete item;
693 }
694 }
695}
696
Boris Barbulovski59e56442015-09-22 11:36:18 -0700697void ConfigList::keyPressEvent(QKeyEvent* ev)
698{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700699 QTreeWidgetItem* i = currentItem();
700 ConfigItem* item;
701 struct menu *menu;
702 enum prop_type type;
703
704 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
705 emit parentSelected();
706 ev->accept();
707 return;
708 }
709
710 if (!i) {
711 Parent::keyPressEvent(ev);
712 return;
713 }
714 item = (ConfigItem*)i;
715
716 switch (ev->key()) {
717 case Qt::Key_Return:
718 case Qt::Key_Enter:
719 if (item->goParent) {
720 emit parentSelected();
721 break;
722 }
723 menu = item->menu;
724 if (!menu)
725 break;
726 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
727 if (type == P_MENU && rootEntry != menu &&
728 mode != fullMode && mode != menuMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200729 if (mode == menuMode)
730 emit menuSelected(menu);
731 else
732 emit itemSelected(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700733 break;
734 }
735 case Qt::Key_Space:
736 changeValue(item);
737 break;
738 case Qt::Key_N:
739 setValue(item, no);
740 break;
741 case Qt::Key_M:
742 setValue(item, mod);
743 break;
744 case Qt::Key_Y:
745 setValue(item, yes);
746 break;
747 default:
748 Parent::keyPressEvent(ev);
749 return;
750 }
751 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700752}
753
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700754void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700755{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700756 //QPoint p(contentsToViewport(e->pos()));
757 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
758 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700759}
760
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700761void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700762{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700763 QPoint p = e->pos();
764 ConfigItem* item = (ConfigItem*)itemAt(p);
765 struct menu *menu;
766 enum prop_type ptype;
767 QIcon icon;
768 int idx, x;
769
770 if (!item)
771 goto skip;
772
773 menu = item->menu;
774 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700775 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700776 switch (idx) {
777 case promptColIdx:
778 icon = item->pixmap(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700779 if (!icon.isNull()) {
780 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
781 if (x >= off && x < off + icon.availableSizes().first().width()) {
782 if (item->goParent) {
783 emit parentSelected();
784 break;
785 } else if (!menu)
786 break;
787 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
788 if (ptype == P_MENU && rootEntry != menu &&
789 mode != fullMode && mode != menuMode)
790 emit menuSelected(menu);
791 else
792 changeValue(item);
793 }
794 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700795 break;
796 case noColIdx:
797 setValue(item, no);
798 break;
799 case modColIdx:
800 setValue(item, mod);
801 break;
802 case yesColIdx:
803 setValue(item, yes);
804 break;
805 case dataColIdx:
806 changeValue(item);
807 break;
808 }
809
810skip:
811 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
812 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700813}
814
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700815void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700816{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700817 //QPoint p(contentsToViewport(e->pos()));
818 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
819 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700820}
821
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700822void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700823{
Mauro Carvalho Chehabe1f77692020-04-02 11:28:02 +0200824 QPoint p = e->pos();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700825 ConfigItem* item = (ConfigItem*)itemAt(p);
826 struct menu *menu;
827 enum prop_type ptype;
828
829 if (!item)
830 goto skip;
831 if (item->goParent) {
832 emit parentSelected();
833 goto skip;
834 }
835 menu = item->menu;
836 if (!menu)
837 goto skip;
838 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200839 if (ptype == P_MENU) {
840 if (mode == singleMode)
841 emit itemSelected(menu);
842 else if (mode == symbolMode)
843 emit menuSelected(menu);
844 } else if (menu->sym)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700845 changeValue(item);
846
847skip:
848 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
849 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700850}
851
852void ConfigList::focusInEvent(QFocusEvent *e)
853{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700854 struct menu *menu = NULL;
855
856 Parent::focusInEvent(e);
857
858 ConfigItem* item = (ConfigItem *)currentItem();
859 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200860 setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700861 menu = item->menu;
862 }
863 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700864}
865
866void ConfigList::contextMenuEvent(QContextMenuEvent *e)
867{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700868 if (e->y() <= header()->geometry().bottom()) {
869 if (!headerPopup) {
870 QAction *action;
871
872 headerPopup = new QMenu(this);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200873 action = new QAction("Show Name", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700874 action->setCheckable(true);
875 connect(action, SIGNAL(toggled(bool)),
876 parent(), SLOT(setShowName(bool)));
877 connect(parent(), SIGNAL(showNameChanged(bool)),
878 action, SLOT(setOn(bool)));
879 action->setChecked(showName);
880 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200881 action = new QAction("Show Range", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700882 action->setCheckable(true);
883 connect(action, SIGNAL(toggled(bool)),
884 parent(), SLOT(setShowRange(bool)));
885 connect(parent(), SIGNAL(showRangeChanged(bool)),
886 action, SLOT(setOn(bool)));
887 action->setChecked(showRange);
888 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200889 action = new QAction("Show Data", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700890 action->setCheckable(true);
891 connect(action, SIGNAL(toggled(bool)),
892 parent(), SLOT(setShowData(bool)));
893 connect(parent(), SIGNAL(showDataChanged(bool)),
894 action, SLOT(setOn(bool)));
895 action->setChecked(showData);
896 headerPopup->addAction(action);
897 }
898 headerPopup->exec(e->globalPos());
899 e->accept();
900 } else
901 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700902}
903
Li Zefan39a48972010-05-10 16:33:41 +0800904ConfigView*ConfigView::viewList;
905QAction *ConfigView::showNormalAction;
906QAction *ConfigView::showAllAction;
907QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Roman Zippel7fc925f2006-06-08 22:12:46 -0700909ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700910 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700912 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700913 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700914 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700915
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700916 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700917 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 lineEdit = new ConfigLineEdit(this);
919 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700920 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 this->nextView = viewList;
923 viewList = this;
924}
925
926ConfigView::~ConfigView(void)
927{
928 ConfigView** vp;
929
930 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
931 if (*vp == this) {
932 *vp = nextView;
933 break;
934 }
935 }
936}
937
Li Zefan39a48972010-05-10 16:33:41 +0800938void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700939{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700940 if (act == showNormalAction)
941 list->optMode = normalOpt;
942 else if (act == showAllAction)
943 list->optMode = allOpt;
944 else
945 list->optMode = promptOpt;
946
947 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700948}
949
950void ConfigView::setShowName(bool b)
951{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700952 if (list->showName != b) {
953 list->showName = b;
954 list->reinit();
955 emit showNameChanged(b);
956 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700957}
958
959void ConfigView::setShowRange(bool b)
960{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700961 if (list->showRange != b) {
962 list->showRange = b;
963 list->reinit();
964 emit showRangeChanged(b);
965 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700966}
967
968void ConfigView::setShowData(bool b)
969{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700970 if (list->showData != b) {
971 list->showData = b;
972 list->reinit();
973 emit showDataChanged(b);
974 }
975}
976
977void ConfigList::setAllOpen(bool open)
978{
979 QTreeWidgetItemIterator it(this);
980
981 while (*it) {
982 (*it)->setExpanded(open);
983
984 ++it;
985 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700986}
987
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700988void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700989{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700990 ConfigView* v;
991
992 for (v = viewList; v; v = v->nextView)
993 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994}
995
996void ConfigView::updateListAll(void)
997{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700998 ConfigView* v;
999
1000 for (v = viewList; v; v = v->nextView)
1001 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
Roman Zippel43bf6122006-06-08 22:12:45 -07001004ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001005 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -07001006{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001007 setObjectName(name);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001008 setOpenLinks(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001009
1010 if (!objectName().isEmpty()) {
1011 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001012 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001013 configSettings->endGroup();
1014 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1015 }
1016}
1017
1018void ConfigInfoView::saveSettings(void)
1019{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001020 if (!objectName().isEmpty()) {
1021 configSettings->beginGroup(objectName());
1022 configSettings->setValue("/showDebug", showDebug());
1023 configSettings->endGroup();
1024 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001025}
1026
1027void ConfigInfoView::setShowDebug(bool b)
1028{
1029 if (_showDebug != b) {
1030 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001031 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001032 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001033 else if (sym)
1034 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001035 emit showDebugChanged(b);
1036 }
1037}
1038
1039void ConfigInfoView::setInfo(struct menu *m)
1040{
Alexander Stein133c5f72010-08-31 17:34:37 +02001041 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001042 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001043 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001044 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001045 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001046 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001047 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001048 menuInfo();
1049}
1050
Roman Zippelab45d192006-06-08 22:12:47 -07001051void ConfigInfoView::symbolInfo(void)
1052{
1053 QString str;
1054
1055 str += "<big>Symbol: <b>";
1056 str += print_filter(sym->name);
1057 str += "</b></big><br><br>value: ";
1058 str += print_filter(sym_get_string_value(sym));
1059 str += "<br>visibility: ";
1060 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1061 str += "<br>";
1062 str += debug_info(sym);
1063
1064 setText(str);
1065}
1066
Roman Zippel43bf6122006-06-08 22:12:45 -07001067void ConfigInfoView::menuInfo(void)
1068{
1069 struct symbol* sym;
1070 QString head, debug, help;
1071
Alexander Stein133c5f72010-08-31 17:34:37 +02001072 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001073 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001074 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001075 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001076 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001077 head += "</b></big>";
1078 if (sym->name) {
1079 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001080 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001081 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001082 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001083 if (showDebug())
1084 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001085 head += ")";
1086 }
1087 } else if (sym->name) {
1088 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001089 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001090 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001091 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001092 if (showDebug())
1093 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001094 head += "</b></big>";
1095 }
1096 head += "<br><br>";
1097
1098 if (showDebug())
1099 debug = debug_info(sym);
1100
Cheng Renquand74c15f2009-07-12 16:11:47 +08001101 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001102 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001103 help = print_filter(str_get(&help_gstr));
1104 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001105 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001106 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001107 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001108 head += "</b></big><br><br>";
1109 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001110 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001111 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001112 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001113 debug += "<br><br>";
1114 }
1115 }
1116 }
1117 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001118 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001119
1120 setText(head + debug + help);
1121}
1122
1123QString ConfigInfoView::debug_info(struct symbol *sym)
1124{
1125 QString debug;
1126
1127 debug += "type: ";
1128 debug += print_filter(sym_type_name(sym->type));
1129 if (sym_is_choice(sym))
1130 debug += " (choice)";
1131 debug += "<br>";
1132 if (sym->rev_dep.expr) {
1133 debug += "reverse dep: ";
1134 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1135 debug += "<br>";
1136 }
1137 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1138 switch (prop->type) {
1139 case P_PROMPT:
1140 case P_MENU:
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001141 debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001142 debug += print_filter(prop->text);
Roman Zippelab45d192006-06-08 22:12:47 -07001143 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001144 break;
1145 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001146 case P_SELECT:
1147 case P_RANGE:
Mauro Carvalho Chehab8f8499a2020-06-30 08:48:53 +02001148 case P_COMMENT:
1149 case P_IMPLY:
1150 case P_SYMBOL:
Roman Zippel93449082008-01-14 04:50:54 +01001151 debug += prop_get_type_name(prop->type);
1152 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001153 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1154 debug += "<br>";
1155 break;
1156 case P_CHOICE:
1157 if (sym_is_choice(sym)) {
1158 debug += "choice: ";
1159 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1160 debug += "<br>";
1161 }
1162 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001163 default:
1164 debug += "unknown property: ";
1165 debug += prop_get_type_name(prop->type);
1166 debug += "<br>";
1167 }
1168 if (prop->visible.expr) {
1169 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1170 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1171 debug += "<br>";
1172 }
1173 }
1174 debug += "<br>";
1175
1176 return debug;
1177}
1178
1179QString ConfigInfoView::print_filter(const QString &str)
1180{
1181 QRegExp re("[<>&\"\\n]");
1182 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001183 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1184 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001185 case '<':
1186 res.replace(i, 1, "&lt;");
1187 i += 4;
1188 break;
1189 case '>':
1190 res.replace(i, 1, "&gt;");
1191 i += 4;
1192 break;
1193 case '&':
1194 res.replace(i, 1, "&amp;");
1195 i += 5;
1196 break;
1197 case '"':
1198 res.replace(i, 1, "&quot;");
1199 i += 6;
1200 break;
1201 case '\n':
1202 res.replace(i, 1, "<br>");
1203 i += 4;
1204 break;
1205 }
1206 }
1207 return res;
1208}
1209
Roman Zippelab45d192006-06-08 22:12:47 -07001210void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001211{
Roman Zippelab45d192006-06-08 22:12:47 -07001212 QString* text = reinterpret_cast<QString*>(data);
1213 QString str2 = print_filter(str);
1214
1215 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001216 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001217 *text += str2;
1218 *text += "</a>";
1219 } else
1220 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001221}
1222
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001223void ConfigInfoView::clicked(const QUrl &url)
1224{
1225 QByteArray str = url.toEncoded();
1226 const std::size_t count = str.size();
1227 char *data = new char[count + 1];
1228 struct symbol **result;
1229 struct menu *m = NULL;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001230
1231 if (count < 1) {
1232 qInfo() << "Clicked link is empty";
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001233 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001234 return;
1235 }
1236
1237 memcpy(data, str.constData(), count);
1238 data[count] = '\0';
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001239
1240 /* Seek for exact match */
1241 data[0] = '^';
1242 strcat(data, "$");
1243 result = sym_re_search(data);
1244 if (!result) {
1245 qInfo() << "Clicked symbol is invalid:" << data;
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001246 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001247 return;
1248 }
1249
1250 sym = *result;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001251
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001252 /* Seek for the menu which holds the symbol */
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001253 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1254 if (prop->type != P_PROMPT && prop->type != P_MENU)
1255 continue;
1256 m = prop->menu;
1257 break;
1258 }
1259
1260 if (!m) {
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001261 /* Symbol is not visible as a menu */
1262 symbolInfo();
1263 emit showDebugChanged(true);
1264 } else {
1265 emit menuSelected(m);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001266 }
1267
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001268 free(result);
1269 delete data;
1270}
1271
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001272QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001273{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001274 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001275 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001276
1277 action->setCheckable(true);
1278 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1279 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1280 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001281 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001282 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001283 return popup;
1284}
1285
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001286void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001287{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001288 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001289}
1290
Marco Costalba63431e72006-10-05 19:12:59 +02001291ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001292 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001293{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001294 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001295 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001296
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001297 QVBoxLayout* layout1 = new QVBoxLayout(this);
1298 layout1->setContentsMargins(11, 11, 11, 11);
1299 layout1->setSpacing(6);
1300 QHBoxLayout* layout2 = new QHBoxLayout(0);
1301 layout2->setContentsMargins(0, 0, 0, 0);
1302 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001303 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001304 editField = new QLineEdit(this);
1305 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1306 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001307 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001308 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001309 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1310 layout2->addWidget(searchButton);
1311 layout1->addLayout(layout2);
1312
Roman Zippel7fc925f2006-06-08 22:12:46 -07001313 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001314 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001315 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001316 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001317 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001318 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1319 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001320 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1321 parent, SLOT(setMenuLink(struct menu *)));
1322
Roman Zippel43bf6122006-06-08 22:12:45 -07001323 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001324
1325 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001326 QVariant x, y;
1327 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001328 bool ok;
1329
1330 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001331 width = configSettings->value("/window width", parent->width() / 2).toInt();
1332 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001333 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001334 x = configSettings->value("/window x");
1335 y = configSettings->value("/window y");
1336 if ((x.isValid())&&(y.isValid()))
1337 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001338 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001339 if (ok)
1340 split->setSizes(sizes);
1341 configSettings->endGroup();
1342 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1343 }
1344}
1345
1346void ConfigSearchWindow::saveSettings(void)
1347{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001348 if (!objectName().isEmpty()) {
1349 configSettings->beginGroup(objectName());
1350 configSettings->setValue("/window x", pos().x());
1351 configSettings->setValue("/window y", pos().y());
1352 configSettings->setValue("/window width", size().width());
1353 configSettings->setValue("/window height", size().height());
1354 configSettings->writeSizes("/split", split->sizes());
1355 configSettings->endGroup();
1356 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001357}
1358
1359void ConfigSearchWindow::search(void)
1360{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001361 struct symbol **p;
1362 struct property *prop;
1363 ConfigItem *lastItem = NULL;
1364
1365 free(result);
1366 list->list->clear();
1367 info->clear();
1368
1369 result = sym_re_search(editField->text().toLatin1());
1370 if (!result)
1371 return;
1372 for (p = result; *p; p++) {
1373 for_all_prompts((*p), prop)
1374 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1375 menu_is_visible(prop->menu));
1376 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001377}
1378
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379/*
1380 * Construct the complete config widget
1381 */
1382ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001383 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
1385 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001386 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001387 QVariant x, y;
1388 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001389 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001391 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001392 snprintf(title, sizeof(title), "%s%s",
1393 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001394 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001395 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001396 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001398 width = configSettings->value("/window width", d->width() - 64).toInt();
1399 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001401 x = configSettings->value("/window x");
1402 y = configSettings->value("/window y");
1403 if ((x.isValid())&&(y.isValid()))
1404 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001406 QWidget *widget = new QWidget(this);
1407 QVBoxLayout *layout = new QVBoxLayout(widget);
1408 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001410 split1 = new QSplitter(widget);
1411 split1->setOrientation(Qt::Horizontal);
1412 split1->setChildrenCollapsible(false);
1413
1414 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 menuList = menuView->list;
1416
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001417 split2 = new QSplitter(widget);
1418 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001419 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
1421 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001422 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 configList = configView->list;
1424
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001425 helpText = new ConfigInfoView(widget, "help");
1426
1427 layout->addWidget(split2);
1428 split2->addWidget(split1);
1429 split1->addWidget(configView);
1430 split1->addWidget(menuView);
1431 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
1433 setTabOrder(configList, helpText);
1434 configList->setFocus();
1435
1436 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001437 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001438 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001440 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001441 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1442
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001443 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001444 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001445 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1446
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001447 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001448 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001449 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1450
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001451 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001452 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001453 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1454
Karsten Wiese3b354c52006-12-13 00:34:08 -08001455 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001456
Karsten Wiese3b354c52006-12-13 00:34:08 -08001457 // Set saveAction's initial state
1458 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001459 configname = xstrdup(conf_get_configname());
1460
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001461 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001462 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001463 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001464 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001465 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001466 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001467 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001468 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001469 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001470 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001471 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001472 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001473 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001474 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001476 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001477 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001478 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001479 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001480 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001481 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001482 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001483 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001484 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001485 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001486
1487 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001488 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001489 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001490 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001491 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001492 SLOT(setOptionMode(QAction *)));
1493
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001494 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1495 configView->showAllAction = new QAction("Show All Options", optGroup);
1496 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001497 configView->showNormalAction->setCheckable(true);
1498 configView->showAllAction->setCheckable(true);
1499 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001500
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001501 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001502 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001503 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001504 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001506 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001507 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001508 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001509 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
1511 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001512 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001514 toolBar->addAction(loadAction);
1515 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001517 toolBar->addAction(singleViewAction);
1518 toolBar->addAction(splitViewAction);
1519 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
1521 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001522 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001523 config->addAction(loadAction);
1524 config->addAction(saveAction);
1525 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001526 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001527 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Shlomi Fish66e7c722007-02-14 00:32:58 -08001529 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001530 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001531 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001532
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001534 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001535 optionMenu->addAction(showNameAction);
1536 optionMenu->addAction(showRangeAction);
1537 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001538 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001539 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001540 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001541 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001544 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001545 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001546 helpMenu->addAction(showIntroAction);
1547 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001549 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1550 helpText, SLOT (clicked (const QUrl &)) );
1551
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001552 connect(configList, SIGNAL(menuChanged(struct menu *)),
1553 helpText, SLOT(setInfo(struct menu *)));
1554 connect(configList, SIGNAL(menuSelected(struct menu *)),
1555 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001556 connect(configList, SIGNAL(itemSelected(struct menu *)),
1557 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001558 connect(configList, SIGNAL(parentSelected()),
1559 SLOT(goBack()));
1560 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1561 helpText, SLOT(setInfo(struct menu *)));
1562 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1563 SLOT(changeMenu(struct menu *)));
1564
1565 connect(configList, SIGNAL(gotFocus(struct menu *)),
1566 helpText, SLOT(setInfo(struct menu *)));
1567 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1568 helpText, SLOT(setInfo(struct menu *)));
1569 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1570 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001571 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1572 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001574 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 if (listMode == "single")
1576 showSingleView();
1577 else if (listMode == "full")
1578 showFullView();
1579 else /*if (listMode == "split")*/
1580 showSplitView();
1581
1582 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001583 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 if (ok)
1585 split1->setSizes(sizes);
1586
Roman Zippel7fc925f2006-06-08 22:12:46 -07001587 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 if (ok)
1589 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592void ConfigMainWindow::loadConfig(void)
1593{
Masahiro Yamada87419082019-03-11 01:13:15 +09001594 QString str;
1595 QByteArray ba;
1596 const char *name;
1597
1598 str = QFileDialog::getOpenFileName(this, "", configname);
1599 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001601
1602 ba = str.toLocal8Bit();
1603 name = ba.data();
1604
1605 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001606 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001607
1608 free(configname);
1609 configname = xstrdup(name);
1610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 ConfigView::updateListAll();
1612}
1613
Michal Marekbac6aa82011-05-25 15:10:25 +02001614bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
Masahiro Yamada87419082019-03-11 01:13:15 +09001616 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001617 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001618 return false;
1619 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001620 conf_write_autoconf(0);
1621
Michal Marekbac6aa82011-05-25 15:10:25 +02001622 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623}
1624
1625void ConfigMainWindow::saveConfigAs(void)
1626{
Masahiro Yamada87419082019-03-11 01:13:15 +09001627 QString str;
1628 QByteArray ba;
1629 const char *name;
1630
1631 str = QFileDialog::getSaveFileName(this, "", configname);
1632 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001634
1635 ba = str.toLocal8Bit();
1636 name = ba.data();
1637
1638 if (conf_write(name)) {
1639 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1640 }
1641 conf_write_autoconf(0);
1642
1643 free(configname);
1644 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Roman Zippel43bf6122006-06-08 22:12:45 -07001647void ConfigMainWindow::searchConfig(void)
1648{
1649 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001650 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001651 searchWindow->show();
1652}
1653
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001654void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001656 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657}
1658
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001659void ConfigMainWindow::changeMenu(struct menu *menu)
1660{
1661 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001662}
1663
Roman Zippelb65a47e2006-06-08 22:12:47 -07001664void ConfigMainWindow::setMenuLink(struct menu *menu)
1665{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001666 struct menu *parent;
1667 ConfigList* list = NULL;
1668 ConfigItem* item;
1669
1670 if (configList->menuSkip(menu))
1671 return;
1672
1673 switch (configList->mode) {
1674 case singleMode:
1675 list = configList;
1676 parent = menu_get_parent_menu(menu);
1677 if (!parent)
1678 return;
1679 list->setRootMenu(parent);
1680 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001681 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001682 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001683 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001684 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001685 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001686 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001687 parent = menu_get_parent_menu(menu->parent);
1688 if (!parent)
1689 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001690
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001691 /* Select the config view */
1692 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001693 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001694 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001695 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001696 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001697
1698 menuList->setRootMenu(parent);
1699 menuList->clearSelection();
1700 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001701 }
1702 break;
1703 case fullMode:
1704 list = configList;
1705 break;
1706 default:
1707 break;
1708 }
1709
1710 if (list) {
1711 item = list->findConfigItem(menu);
1712 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001713 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001714 list->scrollToItem(item);
1715 list->setFocus();
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001716 helpText->setInfo(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001717 }
1718 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001719}
1720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721void ConfigMainWindow::listFocusChanged(void)
1722{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001723 if (menuList->mode == menuMode)
1724 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
1727void ConfigMainWindow::goBack(void)
1728{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001729 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001730 return;
1731
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001732 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
1734
1735void ConfigMainWindow::showSingleView(void)
1736{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001737 singleViewAction->setEnabled(false);
1738 singleViewAction->setChecked(true);
1739 splitViewAction->setEnabled(true);
1740 splitViewAction->setChecked(false);
1741 fullViewAction->setEnabled(true);
1742 fullViewAction->setChecked(false);
1743
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001744 backAction->setEnabled(true);
1745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001747 menuList->setRootMenu(0);
1748 configList->mode = singleMode;
1749 if (configList->rootEntry == &rootmenu)
1750 configList->updateListAll();
1751 else
1752 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 configList->setFocus();
1754}
1755
1756void ConfigMainWindow::showSplitView(void)
1757{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001758 singleViewAction->setEnabled(true);
1759 singleViewAction->setChecked(false);
1760 splitViewAction->setEnabled(false);
1761 splitViewAction->setChecked(true);
1762 fullViewAction->setEnabled(true);
1763 fullViewAction->setChecked(false);
1764
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001765 backAction->setEnabled(false);
1766
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001767 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001768 if (configList->rootEntry == &rootmenu)
1769 configList->updateListAll();
1770 else
1771 configList->setRootMenu(&rootmenu);
1772 configList->setAllOpen(true);
1773 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001774 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001775 menuList->setRootMenu(&rootmenu);
1776 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 menuView->show();
1778 menuList->setFocus();
1779}
1780
1781void ConfigMainWindow::showFullView(void)
1782{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001783 singleViewAction->setEnabled(true);
1784 singleViewAction->setChecked(false);
1785 splitViewAction->setEnabled(true);
1786 splitViewAction->setChecked(false);
1787 fullViewAction->setEnabled(false);
1788 fullViewAction->setChecked(true);
1789
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001790 backAction->setEnabled(false);
1791
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001793 menuList->setRootMenu(0);
1794 configList->mode = fullMode;
1795 if (configList->rootEntry == &rootmenu)
1796 configList->updateListAll();
1797 else
1798 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 configList->setFocus();
1800}
1801
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802/*
1803 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 */
1805void ConfigMainWindow::closeEvent(QCloseEvent* e)
1806{
Karsten Wieseb3214292006-12-13 00:34:06 -08001807 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 e->accept();
1809 return;
1810 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001811 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001813 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1814 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1815 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 switch (mb.exec()) {
1817 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001818 if (saveConfig())
1819 e->accept();
1820 else
1821 e->ignore();
1822 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 case QMessageBox::No:
1824 e->accept();
1825 break;
1826 case QMessageBox::Cancel:
1827 e->ignore();
1828 break;
1829 }
1830}
1831
1832void ConfigMainWindow::showIntro(void)
1833{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001834 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 "For each option, a blank box indicates the feature is disabled, a check\n"
1836 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1837 "as a module. Clicking on the box will cycle through the three states.\n\n"
1838 "If you do not see an option (e.g., a device driver) that you believe\n"
1839 "should be present, try turning on Show All Options under the Options menu.\n"
1840 "Although there is no cross reference yet to help you figure out what other\n"
1841 "options must be enabled to support the option you are interested in, you can\n"
1842 "still view the help of a grayed-out option.\n\n"
1843 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001844 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 QMessageBox::information(this, "qconf", str);
1847}
1848
1849void ConfigMainWindow::showAbout(void)
1850{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001851 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001852 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001853 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
1855 QMessageBox::information(this, "qconf", str);
1856}
1857
1858void ConfigMainWindow::saveSettings(void)
1859{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001860 configSettings->setValue("/window x", pos().x());
1861 configSettings->setValue("/window y", pos().y());
1862 configSettings->setValue("/window width", size().width());
1863 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001866 switch(configList->mode) {
1867 case singleMode :
1868 entry = "single";
1869 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001871 case symbolMode :
1872 entry = "split";
1873 break;
1874
1875 case fullMode :
1876 entry = "full";
1877 break;
1878
1879 default:
1880 break;
1881 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001882 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Roman Zippel7fc925f2006-06-08 22:12:46 -07001884 configSettings->writeSizes("/split1", split1->sizes());
1885 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886}
1887
Karsten Wiese3b354c52006-12-13 00:34:08 -08001888void ConfigMainWindow::conf_changed(void)
1889{
1890 if (saveAction)
1891 saveAction->setEnabled(conf_get_changed());
1892}
1893
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894void fixup_rootmenu(struct menu *menu)
1895{
1896 struct menu *child;
1897 static int menu_cnt = 0;
1898
1899 menu->flags |= MENU_ROOT;
1900 for (child = menu->list; child; child = child->next) {
1901 if (child->prompt && child->prompt->type == P_MENU) {
1902 menu_cnt++;
1903 fixup_rootmenu(child);
1904 menu_cnt--;
1905 } else if (!menu_cnt)
1906 fixup_rootmenu(child);
1907 }
1908}
1909
1910static const char *progname;
1911
1912static void usage(void)
1913{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001914 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 exit(0);
1916}
1917
1918int main(int ac, char** av)
1919{
1920 ConfigMainWindow* v;
1921 const char *name;
1922
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 progname = av[0];
1924 configApp = new QApplication(ac, av);
1925 if (ac > 1 && av[1][0] == '-') {
1926 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001927 case 's':
1928 conf_set_message_callback(NULL);
1929 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 case 'h':
1931 case '?':
1932 usage();
1933 }
1934 name = av[2];
1935 } else
1936 name = av[1];
1937 if (!name)
1938 usage();
1939
1940 conf_parse(name);
1941 fixup_rootmenu(&rootmenu);
1942 conf_read(NULL);
1943 //zconfdump(stdout);
1944
Roman Zippel7fc925f2006-06-08 22:12:46 -07001945 configSettings = new ConfigSettings();
1946 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 v = new ConfigMainWindow();
1948
1949 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1951 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001952 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 configApp->exec();
1954
Roman Zippel7fc925f2006-06-08 22:12:46 -07001955 configSettings->endGroup();
1956 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001957 delete v;
1958 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001959
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 return 0;
1961}