blob: 23d1cb01a41aef4c0675c2b46b6cda4a4015a129 [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);
Masahiro Yamada4b20e102020-08-01 16:08:49 +0900431 if (!item)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700432 item = new ConfigItem(this, 0, true);
Masahiro Yamada4b20e102020-08-01 16:08:49 +0900433 last = item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700434 }
435 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
436 rootEntry->sym && rootEntry->prompt) {
Masahiro Yamadaccf56e52020-08-01 16:08:50 +0900437 item = last ? last->nextSibling() : nullptr;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700438 if (!item)
439 item = new ConfigItem(this, last, rootEntry, true);
440 else
441 item->testUpdateMenu(true);
442
443 updateMenuList(item, rootEntry);
444 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700445 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700446 return;
447 }
448update:
449 updateMenuList(this, rootEntry);
450 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700451 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700452}
453
454void ConfigList::setValue(ConfigItem* item, tristate val)
455{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700456 struct symbol* sym;
457 int type;
458 tristate oldval;
459
460 sym = item->menu ? item->menu->sym : 0;
461 if (!sym)
462 return;
463
464 type = sym_get_type(sym);
465 switch (type) {
466 case S_BOOLEAN:
467 case S_TRISTATE:
468 oldval = sym_get_tristate_value(sym);
469
470 if (!sym_set_tristate_value(sym, val))
471 return;
472 if (oldval == no && item->menu->list)
473 item->setExpanded(true);
474 parent()->updateList(item);
475 break;
476 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700477}
478
479void ConfigList::changeValue(ConfigItem* item)
480{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700481 struct symbol* sym;
482 struct menu* menu;
483 int type, oldexpr, newexpr;
484
485 menu = item->menu;
486 if (!menu)
487 return;
488 sym = menu->sym;
489 if (!sym) {
490 if (item->menu->list)
491 item->setExpanded(!item->isExpanded());
492 return;
493 }
494
495 type = sym_get_type(sym);
496 switch (type) {
497 case S_BOOLEAN:
498 case S_TRISTATE:
499 oldexpr = sym_get_tristate_value(sym);
500 newexpr = sym_toggle_tristate_value(sym);
501 if (item->menu->list) {
502 if (oldexpr == newexpr)
503 item->setExpanded(!item->isExpanded());
504 else if (oldexpr == no)
505 item->setExpanded(true);
506 }
507 if (oldexpr != newexpr)
508 parent()->updateList(item);
509 break;
510 case S_INT:
511 case S_HEX:
512 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700513 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700514 break;
515 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700516}
517
518void ConfigList::setRootMenu(struct menu *menu)
519{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700520 enum prop_type type;
521
522 if (rootEntry == menu)
523 return;
524 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
525 if (type != P_MENU)
526 return;
527 updateMenuList(this, 0);
528 rootEntry = menu;
529 updateListAll();
530 if (currentItem()) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200531 setSelected(currentItem(), hasFocus());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700532 scrollToItem(currentItem());
533 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700534}
535
536void ConfigList::setParentMenu(void)
537{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700538 ConfigItem* item;
539 struct menu *oldroot;
540
541 oldroot = rootEntry;
542 if (rootEntry == &rootmenu)
543 return;
544 setRootMenu(menu_get_parent_menu(rootEntry->parent));
545
546 QTreeWidgetItemIterator it(this);
547 while (*it) {
548 item = (ConfigItem *)(*it);
549 if (item->menu == oldroot) {
550 setCurrentItem(item);
551 scrollToItem(item);
552 break;
553 }
554
555 ++it;
556 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700557}
558
559/*
560 * update all the children of a menu entry
561 * removes/adds the entries from the parent widget as necessary
562 *
563 * parent: either the menu list widget or a menu entry widget
564 * menu: entry to be updated
565 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700566void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700567{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700568 struct menu* child;
569 ConfigItem* item;
570 ConfigItem* last;
571 bool visible;
572 enum prop_type type;
573
574 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700575 while (parent->childCount() > 0)
576 {
577 delete parent->takeChild(0);
578 }
579
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700580 return;
581 }
582
583 last = parent->firstChild();
584 if (last && !last->goParent)
585 last = 0;
586 for (child = menu->list; child; child = child->next) {
587 item = last ? last->nextSibling() : parent->firstChild();
588 type = child->prompt ? child->prompt->type : P_UNKNOWN;
589
590 switch (mode) {
591 case menuMode:
592 if (!(child->flags & MENU_ROOT))
593 goto hide;
594 break;
595 case symbolMode:
596 if (child->flags & MENU_ROOT)
597 goto hide;
598 break;
599 default:
600 break;
601 }
602
603 visible = menu_is_visible(child);
604 if (!menuSkip(child)) {
605 if (!child->sym && !child->list && !child->prompt)
606 continue;
607 if (!item || item->menu != child)
608 item = new ConfigItem(parent, last, child, visible);
609 else
610 item->testUpdateMenu(visible);
611
612 if (mode == fullMode || mode == menuMode || type != P_MENU)
613 updateMenuList(item, child);
614 else
615 updateMenuList(item, 0);
616 last = item;
617 continue;
618 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200619hide:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700620 if (item && item->menu == child) {
621 last = parent->firstChild();
622 if (last == item)
623 last = 0;
624 else while (last->nextSibling() != item)
625 last = last->nextSibling();
626 delete item;
627 }
628 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700629}
630
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700631void ConfigList::updateMenuList(ConfigList *parent, struct menu* menu)
632{
633 struct menu* child;
634 ConfigItem* item;
635 ConfigItem* last;
636 bool visible;
637 enum prop_type type;
638
639 if (!menu) {
640 while (parent->topLevelItemCount() > 0)
641 {
642 delete parent->takeTopLevelItem(0);
643 }
644
645 return;
646 }
647
648 last = (ConfigItem*)parent->topLevelItem(0);
649 if (last && !last->goParent)
650 last = 0;
651 for (child = menu->list; child; child = child->next) {
652 item = last ? last->nextSibling() : (ConfigItem*)parent->topLevelItem(0);
653 type = child->prompt ? child->prompt->type : P_UNKNOWN;
654
655 switch (mode) {
656 case menuMode:
657 if (!(child->flags & MENU_ROOT))
658 goto hide;
659 break;
660 case symbolMode:
661 if (child->flags & MENU_ROOT)
662 goto hide;
663 break;
664 default:
665 break;
666 }
667
668 visible = menu_is_visible(child);
669 if (!menuSkip(child)) {
670 if (!child->sym && !child->list && !child->prompt)
671 continue;
672 if (!item || item->menu != child)
673 item = new ConfigItem(parent, last, child, visible);
674 else
675 item->testUpdateMenu(visible);
676
677 if (mode == fullMode || mode == menuMode || type != P_MENU)
678 updateMenuList(item, child);
679 else
680 updateMenuList(item, 0);
681 last = item;
682 continue;
683 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200684hide:
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700685 if (item && item->menu == child) {
686 last = (ConfigItem*)parent->topLevelItem(0);
687 if (last == item)
688 last = 0;
689 else while (last->nextSibling() != item)
690 last = last->nextSibling();
691 delete item;
692 }
693 }
694}
695
Boris Barbulovski59e56442015-09-22 11:36:18 -0700696void ConfigList::keyPressEvent(QKeyEvent* ev)
697{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700698 QTreeWidgetItem* i = currentItem();
699 ConfigItem* item;
700 struct menu *menu;
701 enum prop_type type;
702
703 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
704 emit parentSelected();
705 ev->accept();
706 return;
707 }
708
709 if (!i) {
710 Parent::keyPressEvent(ev);
711 return;
712 }
713 item = (ConfigItem*)i;
714
715 switch (ev->key()) {
716 case Qt::Key_Return:
717 case Qt::Key_Enter:
718 if (item->goParent) {
719 emit parentSelected();
720 break;
721 }
722 menu = item->menu;
723 if (!menu)
724 break;
725 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
726 if (type == P_MENU && rootEntry != menu &&
727 mode != fullMode && mode != menuMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200728 if (mode == menuMode)
729 emit menuSelected(menu);
730 else
731 emit itemSelected(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700732 break;
733 }
734 case Qt::Key_Space:
735 changeValue(item);
736 break;
737 case Qt::Key_N:
738 setValue(item, no);
739 break;
740 case Qt::Key_M:
741 setValue(item, mod);
742 break;
743 case Qt::Key_Y:
744 setValue(item, yes);
745 break;
746 default:
747 Parent::keyPressEvent(ev);
748 return;
749 }
750 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700751}
752
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700753void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700754{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700755 //QPoint p(contentsToViewport(e->pos()));
756 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
757 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700758}
759
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700760void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700761{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700762 QPoint p = e->pos();
763 ConfigItem* item = (ConfigItem*)itemAt(p);
764 struct menu *menu;
765 enum prop_type ptype;
766 QIcon icon;
767 int idx, x;
768
769 if (!item)
770 goto skip;
771
772 menu = item->menu;
773 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700774 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700775 switch (idx) {
776 case promptColIdx:
777 icon = item->pixmap(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700778 if (!icon.isNull()) {
779 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
780 if (x >= off && x < off + icon.availableSizes().first().width()) {
781 if (item->goParent) {
782 emit parentSelected();
783 break;
784 } else if (!menu)
785 break;
786 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
787 if (ptype == P_MENU && rootEntry != menu &&
788 mode != fullMode && mode != menuMode)
789 emit menuSelected(menu);
790 else
791 changeValue(item);
792 }
793 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700794 break;
795 case noColIdx:
796 setValue(item, no);
797 break;
798 case modColIdx:
799 setValue(item, mod);
800 break;
801 case yesColIdx:
802 setValue(item, yes);
803 break;
804 case dataColIdx:
805 changeValue(item);
806 break;
807 }
808
809skip:
810 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
811 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700812}
813
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700814void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700815{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700816 //QPoint p(contentsToViewport(e->pos()));
817 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
818 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700819}
820
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700821void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700822{
Mauro Carvalho Chehabe1f77692020-04-02 11:28:02 +0200823 QPoint p = e->pos();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700824 ConfigItem* item = (ConfigItem*)itemAt(p);
825 struct menu *menu;
826 enum prop_type ptype;
827
828 if (!item)
829 goto skip;
830 if (item->goParent) {
831 emit parentSelected();
832 goto skip;
833 }
834 menu = item->menu;
835 if (!menu)
836 goto skip;
837 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200838 if (ptype == P_MENU) {
839 if (mode == singleMode)
840 emit itemSelected(menu);
841 else if (mode == symbolMode)
842 emit menuSelected(menu);
843 } else if (menu->sym)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700844 changeValue(item);
845
846skip:
847 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
848 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700849}
850
851void ConfigList::focusInEvent(QFocusEvent *e)
852{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700853 struct menu *menu = NULL;
854
855 Parent::focusInEvent(e);
856
857 ConfigItem* item = (ConfigItem *)currentItem();
858 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200859 setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700860 menu = item->menu;
861 }
862 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700863}
864
865void ConfigList::contextMenuEvent(QContextMenuEvent *e)
866{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700867 if (e->y() <= header()->geometry().bottom()) {
868 if (!headerPopup) {
869 QAction *action;
870
871 headerPopup = new QMenu(this);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200872 action = new QAction("Show Name", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700873 action->setCheckable(true);
874 connect(action, SIGNAL(toggled(bool)),
875 parent(), SLOT(setShowName(bool)));
876 connect(parent(), SIGNAL(showNameChanged(bool)),
877 action, SLOT(setOn(bool)));
878 action->setChecked(showName);
879 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200880 action = new QAction("Show Range", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700881 action->setCheckable(true);
882 connect(action, SIGNAL(toggled(bool)),
883 parent(), SLOT(setShowRange(bool)));
884 connect(parent(), SIGNAL(showRangeChanged(bool)),
885 action, SLOT(setOn(bool)));
886 action->setChecked(showRange);
887 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200888 action = new QAction("Show Data", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700889 action->setCheckable(true);
890 connect(action, SIGNAL(toggled(bool)),
891 parent(), SLOT(setShowData(bool)));
892 connect(parent(), SIGNAL(showDataChanged(bool)),
893 action, SLOT(setOn(bool)));
894 action->setChecked(showData);
895 headerPopup->addAction(action);
896 }
897 headerPopup->exec(e->globalPos());
898 e->accept();
899 } else
900 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700901}
902
Li Zefan39a48972010-05-10 16:33:41 +0800903ConfigView*ConfigView::viewList;
904QAction *ConfigView::showNormalAction;
905QAction *ConfigView::showAllAction;
906QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Roman Zippel7fc925f2006-06-08 22:12:46 -0700908ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700909 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700911 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700912 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700913 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700914
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700915 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700916 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 lineEdit = new ConfigLineEdit(this);
918 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700919 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 this->nextView = viewList;
922 viewList = this;
923}
924
925ConfigView::~ConfigView(void)
926{
927 ConfigView** vp;
928
929 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
930 if (*vp == this) {
931 *vp = nextView;
932 break;
933 }
934 }
935}
936
Li Zefan39a48972010-05-10 16:33:41 +0800937void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700938{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700939 if (act == showNormalAction)
940 list->optMode = normalOpt;
941 else if (act == showAllAction)
942 list->optMode = allOpt;
943 else
944 list->optMode = promptOpt;
945
946 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700947}
948
949void ConfigView::setShowName(bool b)
950{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700951 if (list->showName != b) {
952 list->showName = b;
953 list->reinit();
954 emit showNameChanged(b);
955 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700956}
957
958void ConfigView::setShowRange(bool b)
959{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700960 if (list->showRange != b) {
961 list->showRange = b;
962 list->reinit();
963 emit showRangeChanged(b);
964 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700965}
966
967void ConfigView::setShowData(bool b)
968{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700969 if (list->showData != b) {
970 list->showData = b;
971 list->reinit();
972 emit showDataChanged(b);
973 }
974}
975
976void ConfigList::setAllOpen(bool open)
977{
978 QTreeWidgetItemIterator it(this);
979
980 while (*it) {
981 (*it)->setExpanded(open);
982
983 ++it;
984 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700985}
986
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700987void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700988{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700989 ConfigView* v;
990
991 for (v = viewList; v; v = v->nextView)
992 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
995void ConfigView::updateListAll(void)
996{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700997 ConfigView* v;
998
999 for (v = viewList; v; v = v->nextView)
1000 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001}
1002
Roman Zippel43bf6122006-06-08 22:12:45 -07001003ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001004 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -07001005{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001006 setObjectName(name);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001007 setOpenLinks(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001008
1009 if (!objectName().isEmpty()) {
1010 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001011 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001012 configSettings->endGroup();
1013 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1014 }
1015}
1016
1017void ConfigInfoView::saveSettings(void)
1018{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001019 if (!objectName().isEmpty()) {
1020 configSettings->beginGroup(objectName());
1021 configSettings->setValue("/showDebug", showDebug());
1022 configSettings->endGroup();
1023 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001024}
1025
1026void ConfigInfoView::setShowDebug(bool b)
1027{
1028 if (_showDebug != b) {
1029 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001030 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001031 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001032 else if (sym)
1033 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001034 emit showDebugChanged(b);
1035 }
1036}
1037
1038void ConfigInfoView::setInfo(struct menu *m)
1039{
Alexander Stein133c5f72010-08-31 17:34:37 +02001040 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001041 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001042 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001043 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001044 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001045 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001046 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001047 menuInfo();
1048}
1049
Roman Zippelab45d192006-06-08 22:12:47 -07001050void ConfigInfoView::symbolInfo(void)
1051{
1052 QString str;
1053
1054 str += "<big>Symbol: <b>";
1055 str += print_filter(sym->name);
1056 str += "</b></big><br><br>value: ";
1057 str += print_filter(sym_get_string_value(sym));
1058 str += "<br>visibility: ";
1059 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1060 str += "<br>";
1061 str += debug_info(sym);
1062
1063 setText(str);
1064}
1065
Roman Zippel43bf6122006-06-08 22:12:45 -07001066void ConfigInfoView::menuInfo(void)
1067{
1068 struct symbol* sym;
1069 QString head, debug, help;
1070
Alexander Stein133c5f72010-08-31 17:34:37 +02001071 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001072 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001073 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001074 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001075 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001076 head += "</b></big>";
1077 if (sym->name) {
1078 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001079 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001080 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001081 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001082 if (showDebug())
1083 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001084 head += ")";
1085 }
1086 } else if (sym->name) {
1087 head += "<big><b>";
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 += "</b></big>";
1094 }
1095 head += "<br><br>";
1096
1097 if (showDebug())
1098 debug = debug_info(sym);
1099
Cheng Renquand74c15f2009-07-12 16:11:47 +08001100 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001101 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001102 help = print_filter(str_get(&help_gstr));
1103 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001104 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001105 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001106 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001107 head += "</b></big><br><br>";
1108 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001109 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001110 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001111 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001112 debug += "<br><br>";
1113 }
1114 }
1115 }
1116 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001117 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001118
1119 setText(head + debug + help);
1120}
1121
1122QString ConfigInfoView::debug_info(struct symbol *sym)
1123{
1124 QString debug;
1125
1126 debug += "type: ";
1127 debug += print_filter(sym_type_name(sym->type));
1128 if (sym_is_choice(sym))
1129 debug += " (choice)";
1130 debug += "<br>";
1131 if (sym->rev_dep.expr) {
1132 debug += "reverse dep: ";
1133 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1134 debug += "<br>";
1135 }
1136 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1137 switch (prop->type) {
1138 case P_PROMPT:
1139 case P_MENU:
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001140 debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001141 debug += print_filter(prop->text);
Roman Zippelab45d192006-06-08 22:12:47 -07001142 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001143 break;
1144 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001145 case P_SELECT:
1146 case P_RANGE:
Mauro Carvalho Chehab8f8499a2020-06-30 08:48:53 +02001147 case P_COMMENT:
1148 case P_IMPLY:
1149 case P_SYMBOL:
Roman Zippel93449082008-01-14 04:50:54 +01001150 debug += prop_get_type_name(prop->type);
1151 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001152 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1153 debug += "<br>";
1154 break;
1155 case P_CHOICE:
1156 if (sym_is_choice(sym)) {
1157 debug += "choice: ";
1158 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1159 debug += "<br>";
1160 }
1161 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001162 default:
1163 debug += "unknown property: ";
1164 debug += prop_get_type_name(prop->type);
1165 debug += "<br>";
1166 }
1167 if (prop->visible.expr) {
1168 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1169 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1170 debug += "<br>";
1171 }
1172 }
1173 debug += "<br>";
1174
1175 return debug;
1176}
1177
1178QString ConfigInfoView::print_filter(const QString &str)
1179{
1180 QRegExp re("[<>&\"\\n]");
1181 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001182 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1183 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001184 case '<':
1185 res.replace(i, 1, "&lt;");
1186 i += 4;
1187 break;
1188 case '>':
1189 res.replace(i, 1, "&gt;");
1190 i += 4;
1191 break;
1192 case '&':
1193 res.replace(i, 1, "&amp;");
1194 i += 5;
1195 break;
1196 case '"':
1197 res.replace(i, 1, "&quot;");
1198 i += 6;
1199 break;
1200 case '\n':
1201 res.replace(i, 1, "<br>");
1202 i += 4;
1203 break;
1204 }
1205 }
1206 return res;
1207}
1208
Roman Zippelab45d192006-06-08 22:12:47 -07001209void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001210{
Roman Zippelab45d192006-06-08 22:12:47 -07001211 QString* text = reinterpret_cast<QString*>(data);
1212 QString str2 = print_filter(str);
1213
1214 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001215 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001216 *text += str2;
1217 *text += "</a>";
1218 } else
1219 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001220}
1221
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001222void ConfigInfoView::clicked(const QUrl &url)
1223{
1224 QByteArray str = url.toEncoded();
1225 const std::size_t count = str.size();
1226 char *data = new char[count + 1];
1227 struct symbol **result;
1228 struct menu *m = NULL;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001229
1230 if (count < 1) {
1231 qInfo() << "Clicked link is empty";
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001232 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001233 return;
1234 }
1235
1236 memcpy(data, str.constData(), count);
1237 data[count] = '\0';
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001238
1239 /* Seek for exact match */
1240 data[0] = '^';
1241 strcat(data, "$");
1242 result = sym_re_search(data);
1243 if (!result) {
1244 qInfo() << "Clicked symbol is invalid:" << data;
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001245 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001246 return;
1247 }
1248
1249 sym = *result;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001250
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001251 /* Seek for the menu which holds the symbol */
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001252 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1253 if (prop->type != P_PROMPT && prop->type != P_MENU)
1254 continue;
1255 m = prop->menu;
1256 break;
1257 }
1258
1259 if (!m) {
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001260 /* Symbol is not visible as a menu */
1261 symbolInfo();
1262 emit showDebugChanged(true);
1263 } else {
1264 emit menuSelected(m);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001265 }
1266
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001267 free(result);
1268 delete data;
1269}
1270
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001271QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001272{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001273 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001274 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001275
1276 action->setCheckable(true);
1277 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1278 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1279 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001280 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001281 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001282 return popup;
1283}
1284
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001285void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001286{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001287 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001288}
1289
Marco Costalba63431e72006-10-05 19:12:59 +02001290ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001291 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001292{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001293 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001294 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001295
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001296 QVBoxLayout* layout1 = new QVBoxLayout(this);
1297 layout1->setContentsMargins(11, 11, 11, 11);
1298 layout1->setSpacing(6);
1299 QHBoxLayout* layout2 = new QHBoxLayout(0);
1300 layout2->setContentsMargins(0, 0, 0, 0);
1301 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001302 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001303 editField = new QLineEdit(this);
1304 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1305 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001306 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001307 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001308 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1309 layout2->addWidget(searchButton);
1310 layout1->addLayout(layout2);
1311
Roman Zippel7fc925f2006-06-08 22:12:46 -07001312 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001313 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001314 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001315 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001316 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001317 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1318 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001319 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1320 parent, SLOT(setMenuLink(struct menu *)));
1321
Roman Zippel43bf6122006-06-08 22:12:45 -07001322 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001323
1324 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001325 QVariant x, y;
1326 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001327 bool ok;
1328
1329 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001330 width = configSettings->value("/window width", parent->width() / 2).toInt();
1331 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001332 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001333 x = configSettings->value("/window x");
1334 y = configSettings->value("/window y");
1335 if ((x.isValid())&&(y.isValid()))
1336 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001337 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001338 if (ok)
1339 split->setSizes(sizes);
1340 configSettings->endGroup();
1341 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1342 }
1343}
1344
1345void ConfigSearchWindow::saveSettings(void)
1346{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001347 if (!objectName().isEmpty()) {
1348 configSettings->beginGroup(objectName());
1349 configSettings->setValue("/window x", pos().x());
1350 configSettings->setValue("/window y", pos().y());
1351 configSettings->setValue("/window width", size().width());
1352 configSettings->setValue("/window height", size().height());
1353 configSettings->writeSizes("/split", split->sizes());
1354 configSettings->endGroup();
1355 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001356}
1357
1358void ConfigSearchWindow::search(void)
1359{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001360 struct symbol **p;
1361 struct property *prop;
1362 ConfigItem *lastItem = NULL;
1363
1364 free(result);
1365 list->list->clear();
1366 info->clear();
1367
1368 result = sym_re_search(editField->text().toLatin1());
1369 if (!result)
1370 return;
1371 for (p = result; *p; p++) {
1372 for_all_prompts((*p), prop)
1373 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1374 menu_is_visible(prop->menu));
1375 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001376}
1377
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378/*
1379 * Construct the complete config widget
1380 */
1381ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001382 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
1384 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001385 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001386 QVariant x, y;
1387 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001388 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001390 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001391 snprintf(title, sizeof(title), "%s%s",
1392 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001393 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001394 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001395 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001397 width = configSettings->value("/window width", d->width() - 64).toInt();
1398 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001400 x = configSettings->value("/window x");
1401 y = configSettings->value("/window y");
1402 if ((x.isValid())&&(y.isValid()))
1403 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001405 QWidget *widget = new QWidget(this);
1406 QVBoxLayout *layout = new QVBoxLayout(widget);
1407 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001409 split1 = new QSplitter(widget);
1410 split1->setOrientation(Qt::Horizontal);
1411 split1->setChildrenCollapsible(false);
1412
1413 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 menuList = menuView->list;
1415
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001416 split2 = new QSplitter(widget);
1417 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001418 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
1420 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001421 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 configList = configView->list;
1423
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001424 helpText = new ConfigInfoView(widget, "help");
1425
1426 layout->addWidget(split2);
1427 split2->addWidget(split1);
1428 split1->addWidget(configView);
1429 split1->addWidget(menuView);
1430 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432 setTabOrder(configList, helpText);
1433 configList->setFocus();
1434
1435 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001436 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001437 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001439 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001440 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1441
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001442 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001443 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001444 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1445
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001446 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001447 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001448 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1449
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001450 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001451 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001452 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1453
Karsten Wiese3b354c52006-12-13 00:34:08 -08001454 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001455
Karsten Wiese3b354c52006-12-13 00:34:08 -08001456 // Set saveAction's initial state
1457 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001458 configname = xstrdup(conf_get_configname());
1459
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001460 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001461 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001462 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001463 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001464 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001465 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001466 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001467 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001468 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001469 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001470 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001471 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001472 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001473 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001475 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001476 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001477 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001478 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001479 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001480 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001481 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001482 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001483 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001484 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001485
1486 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001487 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001488 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001489 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001490 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001491 SLOT(setOptionMode(QAction *)));
1492
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001493 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1494 configView->showAllAction = new QAction("Show All Options", optGroup);
1495 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001496 configView->showNormalAction->setCheckable(true);
1497 configView->showAllAction->setCheckable(true);
1498 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001499
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001500 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001501 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001502 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001503 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001505 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001506 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001507 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001508 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001511 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001513 toolBar->addAction(loadAction);
1514 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001516 toolBar->addAction(singleViewAction);
1517 toolBar->addAction(splitViewAction);
1518 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001521 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001522 config->addAction(loadAction);
1523 config->addAction(saveAction);
1524 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001525 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001526 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Shlomi Fish66e7c722007-02-14 00:32:58 -08001528 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001529 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001530 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001531
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001533 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001534 optionMenu->addAction(showNameAction);
1535 optionMenu->addAction(showRangeAction);
1536 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001537 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001538 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001539 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001540 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
1542 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001543 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001544 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001545 helpMenu->addAction(showIntroAction);
1546 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001548 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1549 helpText, SLOT (clicked (const QUrl &)) );
1550
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001551 connect(configList, SIGNAL(menuChanged(struct menu *)),
1552 helpText, SLOT(setInfo(struct menu *)));
1553 connect(configList, SIGNAL(menuSelected(struct menu *)),
1554 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001555 connect(configList, SIGNAL(itemSelected(struct menu *)),
1556 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001557 connect(configList, SIGNAL(parentSelected()),
1558 SLOT(goBack()));
1559 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1560 helpText, SLOT(setInfo(struct menu *)));
1561 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1562 SLOT(changeMenu(struct menu *)));
1563
1564 connect(configList, SIGNAL(gotFocus(struct menu *)),
1565 helpText, SLOT(setInfo(struct menu *)));
1566 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1567 helpText, SLOT(setInfo(struct menu *)));
1568 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1569 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001570 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1571 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001573 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 if (listMode == "single")
1575 showSingleView();
1576 else if (listMode == "full")
1577 showFullView();
1578 else /*if (listMode == "split")*/
1579 showSplitView();
1580
1581 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001582 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 if (ok)
1584 split1->setSizes(sizes);
1585
Roman Zippel7fc925f2006-06-08 22:12:46 -07001586 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 if (ok)
1588 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
1590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591void ConfigMainWindow::loadConfig(void)
1592{
Masahiro Yamada87419082019-03-11 01:13:15 +09001593 QString str;
1594 QByteArray ba;
1595 const char *name;
1596
1597 str = QFileDialog::getOpenFileName(this, "", configname);
1598 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001600
1601 ba = str.toLocal8Bit();
1602 name = ba.data();
1603
1604 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001605 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001606
1607 free(configname);
1608 configname = xstrdup(name);
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 ConfigView::updateListAll();
1611}
1612
Michal Marekbac6aa82011-05-25 15:10:25 +02001613bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614{
Masahiro Yamada87419082019-03-11 01:13:15 +09001615 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001616 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001617 return false;
1618 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001619 conf_write_autoconf(0);
1620
Michal Marekbac6aa82011-05-25 15:10:25 +02001621 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622}
1623
1624void ConfigMainWindow::saveConfigAs(void)
1625{
Masahiro Yamada87419082019-03-11 01:13:15 +09001626 QString str;
1627 QByteArray ba;
1628 const char *name;
1629
1630 str = QFileDialog::getSaveFileName(this, "", configname);
1631 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001633
1634 ba = str.toLocal8Bit();
1635 name = ba.data();
1636
1637 if (conf_write(name)) {
1638 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1639 }
1640 conf_write_autoconf(0);
1641
1642 free(configname);
1643 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644}
1645
Roman Zippel43bf6122006-06-08 22:12:45 -07001646void ConfigMainWindow::searchConfig(void)
1647{
1648 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001649 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001650 searchWindow->show();
1651}
1652
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001653void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001655 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001658void ConfigMainWindow::changeMenu(struct menu *menu)
1659{
1660 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001661}
1662
Roman Zippelb65a47e2006-06-08 22:12:47 -07001663void ConfigMainWindow::setMenuLink(struct menu *menu)
1664{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001665 struct menu *parent;
1666 ConfigList* list = NULL;
1667 ConfigItem* item;
1668
1669 if (configList->menuSkip(menu))
1670 return;
1671
1672 switch (configList->mode) {
1673 case singleMode:
1674 list = configList;
1675 parent = menu_get_parent_menu(menu);
1676 if (!parent)
1677 return;
1678 list->setRootMenu(parent);
1679 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001680 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001681 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001682 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001683 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001684 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001685 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001686 parent = menu_get_parent_menu(menu->parent);
1687 if (!parent)
1688 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001689
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001690 /* Select the config view */
1691 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001692 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001693 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001694 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001695 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001696
1697 menuList->setRootMenu(parent);
1698 menuList->clearSelection();
1699 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001700 }
1701 break;
1702 case fullMode:
1703 list = configList;
1704 break;
1705 default:
1706 break;
1707 }
1708
1709 if (list) {
1710 item = list->findConfigItem(menu);
1711 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001712 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001713 list->scrollToItem(item);
1714 list->setFocus();
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001715 helpText->setInfo(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001716 }
1717 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001718}
1719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720void ConfigMainWindow::listFocusChanged(void)
1721{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001722 if (menuList->mode == menuMode)
1723 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724}
1725
1726void ConfigMainWindow::goBack(void)
1727{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001728 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001729 return;
1730
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001731 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
1734void ConfigMainWindow::showSingleView(void)
1735{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001736 singleViewAction->setEnabled(false);
1737 singleViewAction->setChecked(true);
1738 splitViewAction->setEnabled(true);
1739 splitViewAction->setChecked(false);
1740 fullViewAction->setEnabled(true);
1741 fullViewAction->setChecked(false);
1742
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001743 backAction->setEnabled(true);
1744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001746 menuList->setRootMenu(0);
1747 configList->mode = singleMode;
1748 if (configList->rootEntry == &rootmenu)
1749 configList->updateListAll();
1750 else
1751 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 configList->setFocus();
1753}
1754
1755void ConfigMainWindow::showSplitView(void)
1756{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001757 singleViewAction->setEnabled(true);
1758 singleViewAction->setChecked(false);
1759 splitViewAction->setEnabled(false);
1760 splitViewAction->setChecked(true);
1761 fullViewAction->setEnabled(true);
1762 fullViewAction->setChecked(false);
1763
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001764 backAction->setEnabled(false);
1765
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001766 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001767 if (configList->rootEntry == &rootmenu)
1768 configList->updateListAll();
1769 else
1770 configList->setRootMenu(&rootmenu);
1771 configList->setAllOpen(true);
1772 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001773 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001774 menuList->setRootMenu(&rootmenu);
1775 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 menuView->show();
1777 menuList->setFocus();
1778}
1779
1780void ConfigMainWindow::showFullView(void)
1781{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001782 singleViewAction->setEnabled(true);
1783 singleViewAction->setChecked(false);
1784 splitViewAction->setEnabled(true);
1785 splitViewAction->setChecked(false);
1786 fullViewAction->setEnabled(false);
1787 fullViewAction->setChecked(true);
1788
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001789 backAction->setEnabled(false);
1790
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001792 menuList->setRootMenu(0);
1793 configList->mode = fullMode;
1794 if (configList->rootEntry == &rootmenu)
1795 configList->updateListAll();
1796 else
1797 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 configList->setFocus();
1799}
1800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801/*
1802 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 */
1804void ConfigMainWindow::closeEvent(QCloseEvent* e)
1805{
Karsten Wieseb3214292006-12-13 00:34:06 -08001806 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 e->accept();
1808 return;
1809 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001810 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001812 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1813 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1814 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 switch (mb.exec()) {
1816 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001817 if (saveConfig())
1818 e->accept();
1819 else
1820 e->ignore();
1821 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 case QMessageBox::No:
1823 e->accept();
1824 break;
1825 case QMessageBox::Cancel:
1826 e->ignore();
1827 break;
1828 }
1829}
1830
1831void ConfigMainWindow::showIntro(void)
1832{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001833 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 "For each option, a blank box indicates the feature is disabled, a check\n"
1835 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1836 "as a module. Clicking on the box will cycle through the three states.\n\n"
1837 "If you do not see an option (e.g., a device driver) that you believe\n"
1838 "should be present, try turning on Show All Options under the Options menu.\n"
1839 "Although there is no cross reference yet to help you figure out what other\n"
1840 "options must be enabled to support the option you are interested in, you can\n"
1841 "still view the help of a grayed-out option.\n\n"
1842 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001843 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
1845 QMessageBox::information(this, "qconf", str);
1846}
1847
1848void ConfigMainWindow::showAbout(void)
1849{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001850 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001851 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001852 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
1854 QMessageBox::information(this, "qconf", str);
1855}
1856
1857void ConfigMainWindow::saveSettings(void)
1858{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001859 configSettings->setValue("/window x", pos().x());
1860 configSettings->setValue("/window y", pos().y());
1861 configSettings->setValue("/window width", size().width());
1862 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001865 switch(configList->mode) {
1866 case singleMode :
1867 entry = "single";
1868 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001870 case symbolMode :
1871 entry = "split";
1872 break;
1873
1874 case fullMode :
1875 entry = "full";
1876 break;
1877
1878 default:
1879 break;
1880 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001881 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
Roman Zippel7fc925f2006-06-08 22:12:46 -07001883 configSettings->writeSizes("/split1", split1->sizes());
1884 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885}
1886
Karsten Wiese3b354c52006-12-13 00:34:08 -08001887void ConfigMainWindow::conf_changed(void)
1888{
1889 if (saveAction)
1890 saveAction->setEnabled(conf_get_changed());
1891}
1892
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893void fixup_rootmenu(struct menu *menu)
1894{
1895 struct menu *child;
1896 static int menu_cnt = 0;
1897
1898 menu->flags |= MENU_ROOT;
1899 for (child = menu->list; child; child = child->next) {
1900 if (child->prompt && child->prompt->type == P_MENU) {
1901 menu_cnt++;
1902 fixup_rootmenu(child);
1903 menu_cnt--;
1904 } else if (!menu_cnt)
1905 fixup_rootmenu(child);
1906 }
1907}
1908
1909static const char *progname;
1910
1911static void usage(void)
1912{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001913 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 exit(0);
1915}
1916
1917int main(int ac, char** av)
1918{
1919 ConfigMainWindow* v;
1920 const char *name;
1921
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 progname = av[0];
1923 configApp = new QApplication(ac, av);
1924 if (ac > 1 && av[1][0] == '-') {
1925 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001926 case 's':
1927 conf_set_message_callback(NULL);
1928 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 case 'h':
1930 case '?':
1931 usage();
1932 }
1933 name = av[2];
1934 } else
1935 name = av[1];
1936 if (!name)
1937 usage();
1938
1939 conf_parse(name);
1940 fixup_rootmenu(&rootmenu);
1941 conf_read(NULL);
1942 //zconfdump(stdout);
1943
Roman Zippel7fc925f2006-06-08 22:12:46 -07001944 configSettings = new ConfigSettings();
1945 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 v = new ConfigMainWindow();
1947
1948 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1950 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001951 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 configApp->exec();
1953
Roman Zippel7fc925f2006-06-08 22:12:46 -07001954 configSettings->endGroup();
1955 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001956 delete v;
1957 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001958
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 return 0;
1960}