blob: 6a327b69ff5fba85101d91ef817b697b32ec5cf2 [file] [log] [blame]
Masahiro Yamada0c874102018-12-18 21:13:35 +09001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07004 * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Boris Barbulovski85eaf282015-09-22 11:36:03 -07007#include <QAction>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +02008#include <QApplication>
9#include <QCloseEvent>
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +020010#include <QDebug>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020011#include <QDesktopWidget>
Boris Barbulovskibea00772015-09-22 11:36:04 -070012#include <QFileDialog>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020013#include <QLabel>
14#include <QLayout>
15#include <QList>
Boris Barbulovski76bede82015-09-22 11:36:07 -070016#include <QMenu>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020017#include <QMenuBar>
18#include <QMessageBox>
19#include <QToolBar>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <stdlib.h>
22
23#include "lkc.h"
24#include "qconf.h"
25
26#include "qconf.moc"
Masahiro Yamada3b541978562018-12-21 17:33:07 +090027#include "images.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070031static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Boris Barbulovski85eaf282015-09-22 11:36:03 -070033QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080034
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070035static inline QString qgettext(const char* str)
36{
Sam Ravnborg694c49a2018-05-22 21:36:12 +020037 return QString::fromLocal8Bit(str);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070038}
39
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010040ConfigSettings::ConfigSettings()
41 : QSettings("kernel.org", "qconf")
42{
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/**
46 * Reads a list of integer values from the application settings.
47 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070048QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070050 QList<int> result;
Li Zefanc1f96f02010-05-07 13:58:04 +080051
Boris Barbulovski83c3a1b2016-11-30 14:57:55 -080052 if (contains(key))
53 {
54 QStringList entryList = value(key).toStringList();
55 QStringList::Iterator it;
56
57 for (it = entryList.begin(); it != entryList.end(); ++it)
58 result.push_back((*it).toInt());
59
60 *ok = true;
61 }
62 else
63 *ok = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 return result;
66}
67
68/**
69 * Writes a list of integer values to the application settings.
70 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070071bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070074 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 for (it = value.begin(); it != value.end(); ++it)
77 stringList.push_back(QString::number(*it));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070078 setValue(key, stringList);
Boris Barbulovski59e56442015-09-22 11:36:18 -070079
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070080 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Boris Barbulovski59e56442015-09-22 11:36:18 -070083
84/*
85 * set the new data
86 * TODO check the value
87 */
88void ConfigItem::okRename(int col)
89{
90}
91
92/*
93 * update the displayed of a menu entry
94 */
95void ConfigItem::updateMenu(void)
96{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070097 ConfigList* list;
98 struct symbol* sym;
99 struct property *prop;
100 QString prompt;
101 int type;
102 tristate expr;
103
104 list = listView();
105 if (goParent) {
106 setPixmap(promptColIdx, list->menuBackPix);
107 prompt = "..";
108 goto set_prompt;
109 }
110
111 sym = menu->sym;
112 prop = menu->prompt;
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200113 prompt = qgettext(menu_get_prompt(menu));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700114
115 if (prop) switch (prop->type) {
116 case P_MENU:
117 if (list->mode == singleMode || list->mode == symbolMode) {
118 /* a menuconfig entry is displayed differently
119 * depending whether it's at the view root or a child.
120 */
121 if (sym && list->rootEntry == menu)
122 break;
123 setPixmap(promptColIdx, list->menuPix);
124 } else {
125 if (sym)
126 break;
127 setPixmap(promptColIdx, QIcon());
128 }
129 goto set_prompt;
130 case P_COMMENT:
131 setPixmap(promptColIdx, QIcon());
132 goto set_prompt;
133 default:
134 ;
135 }
136 if (!sym)
137 goto set_prompt;
138
139 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
140
141 type = sym_get_type(sym);
142 switch (type) {
143 case S_BOOLEAN:
144 case S_TRISTATE:
145 char ch;
146
Marco Ammonbaa23ec2019-07-04 12:50:41 +0200147 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700148 setPixmap(promptColIdx, QIcon());
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200149 setText(noColIdx, QString());
150 setText(modColIdx, QString());
151 setText(yesColIdx, QString());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700152 break;
153 }
154 expr = sym_get_tristate_value(sym);
155 switch (expr) {
156 case yes:
157 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
158 setPixmap(promptColIdx, list->choiceYesPix);
159 else
160 setPixmap(promptColIdx, list->symbolYesPix);
161 setText(yesColIdx, "Y");
162 ch = 'Y';
163 break;
164 case mod:
165 setPixmap(promptColIdx, list->symbolModPix);
166 setText(modColIdx, "M");
167 ch = 'M';
168 break;
169 default:
170 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
171 setPixmap(promptColIdx, list->choiceNoPix);
172 else
173 setPixmap(promptColIdx, list->symbolNoPix);
174 setText(noColIdx, "N");
175 ch = 'N';
176 break;
177 }
178 if (expr != no)
179 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
180 if (expr != mod)
181 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
182 if (expr != yes)
183 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
184
185 setText(dataColIdx, QChar(ch));
186 break;
187 case S_INT:
188 case S_HEX:
189 case S_STRING:
190 const char* data;
191
192 data = sym_get_string_value(sym);
193
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700194 setText(dataColIdx, data);
195 if (type == S_STRING)
196 prompt = QString("%1: %2").arg(prompt).arg(data);
197 else
198 prompt = QString("(%2) %1").arg(prompt).arg(data);
199 break;
200 }
201 if (!sym_has_value(sym) && visible)
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200202 prompt += " (NEW)";
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700203set_prompt:
204 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700205}
206
207void ConfigItem::testUpdateMenu(bool v)
208{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700209 ConfigItem* i;
210
211 visible = v;
212 if (!menu)
213 return;
214
215 sym_calc_value(menu->sym);
216 if (menu->flags & MENU_CHANGED) {
217 /* the menu entry changed, so update all list items */
218 menu->flags &= ~MENU_CHANGED;
219 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
220 i->updateMenu();
221 } else if (listView()->updateAll)
222 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700223}
224
225
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700226/*
227 * construct a menu entry
228 */
229void ConfigItem::init(void)
230{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700231 if (menu) {
232 ConfigList* list = listView();
233 nextItem = (ConfigItem*)menu->data;
234 menu->data = this;
235
236 if (list->mode != fullMode)
237 setExpanded(true);
238 sym_calc_value(menu->sym);
239 }
240 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700241}
242
243/*
244 * destruct a menu entry
245 */
246ConfigItem::~ConfigItem(void)
247{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700248 if (menu) {
249 ConfigItem** ip = (ConfigItem**)&menu->data;
250 for (; *ip; ip = &(*ip)->nextItem) {
251 if (*ip == this) {
252 *ip = nextItem;
253 break;
254 }
255 }
256 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700257}
258
Roman Zippel43bf6122006-06-08 22:12:45 -0700259ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
260 : Parent(parent)
261{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700262 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700263}
264
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700265void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700268 if (sym_get_string_value(item->menu->sym))
269 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
270 else
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200271 setText(QString());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 Parent::show();
273 setFocus();
274}
275
276void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
277{
278 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200279 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200281 case Qt::Key_Return:
282 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700283 sym_set_string_value(item->menu->sym, text().toLatin1());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 parent()->updateList(item);
285 break;
286 default:
287 Parent::keyPressEvent(e);
288 return;
289 }
290 e->accept();
291 parent()->list->setFocus();
292 hide();
293}
294
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700295ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700296 : Parent(p),
297 updateAll(false),
298 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
299 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
300 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700301 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700302 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700303{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700304 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700305 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700306 setRootIsDecorated(true);
307
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700308 setVerticalScrollMode(ScrollPerPixel);
309 setHorizontalScrollMode(ScrollPerPixel);
310
Mauro Carvalho Chehab5752ff02020-04-02 11:27:59 +0200311 if (mode == symbolMode)
312 setHeaderLabels(QStringList() << "Item" << "Name" << "N" << "M" << "Y" << "Value");
313 else
314 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700315
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700316 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700317 SLOT(updateSelection(void)));
318
319 if (name) {
320 configSettings->beginGroup(name);
321 showName = configSettings->value("/showName", false).toBool();
322 showRange = configSettings->value("/showRange", false).toBool();
323 showData = configSettings->value("/showData", false).toBool();
324 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
325 configSettings->endGroup();
326 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
327 }
328
329 addColumn(promptColIdx);
330
331 reinit();
332}
333
334bool ConfigList::menuSkip(struct menu *menu)
335{
336 if (optMode == normalOpt && menu_is_visible(menu))
337 return false;
338 if (optMode == promptOpt && menu_has_prompt(menu))
339 return false;
340 if (optMode == allOpt)
341 return false;
342 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700343}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700344
345void ConfigList::reinit(void)
346{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700347 removeColumn(dataColIdx);
348 removeColumn(yesColIdx);
349 removeColumn(modColIdx);
350 removeColumn(noColIdx);
351 removeColumn(nameColIdx);
352
353 if (showName)
354 addColumn(nameColIdx);
355 if (showRange) {
356 addColumn(noColIdx);
357 addColumn(modColIdx);
358 addColumn(yesColIdx);
359 }
360 if (showData)
361 addColumn(dataColIdx);
362
363 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700364}
365
366void ConfigList::saveSettings(void)
367{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700368 if (!objectName().isEmpty()) {
369 configSettings->beginGroup(objectName());
370 configSettings->setValue("/showName", showName);
371 configSettings->setValue("/showRange", showRange);
372 configSettings->setValue("/showData", showData);
373 configSettings->setValue("/optionMode", (int)optMode);
374 configSettings->endGroup();
375 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700376}
377
378ConfigItem* ConfigList::findConfigItem(struct menu *menu)
379{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700380 ConfigItem* item = (ConfigItem*)menu->data;
381
382 for (; item; item = item->nextItem) {
383 if (this == item->listView())
384 break;
385 }
386
387 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700388}
389
390void ConfigList::updateSelection(void)
391{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700392 struct menu *menu;
393 enum prop_type type;
394
Mauro Carvalho Chehab5752ff02020-04-02 11:27:59 +0200395 if (mode == symbolMode)
396 setHeaderLabels(QStringList() << "Item" << "Name" << "N" << "M" << "Y" << "Value");
397 else
398 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
399
Boris Barbulovskibe596aa2015-09-22 11:36:28 -0700400 if (selectedItems().count() == 0)
401 return;
402
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700403 ConfigItem* item = (ConfigItem*)selectedItems().first();
404 if (!item)
405 return;
406
407 menu = item->menu;
408 emit menuChanged(menu);
409 if (!menu)
410 return;
411 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
412 if (mode == menuMode && type == P_MENU)
413 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700414}
415
416void ConfigList::updateList(ConfigItem* item)
417{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700418 ConfigItem* last = 0;
419
420 if (!rootEntry) {
421 if (mode != listMode)
422 goto update;
423 QTreeWidgetItemIterator it(this);
424 ConfigItem* item;
425
426 while (*it) {
427 item = (ConfigItem*)(*it);
428 if (!item->menu)
429 continue;
430 item->testUpdateMenu(menu_is_visible(item->menu));
431
432 ++it;
433 }
434 return;
435 }
436
437 if (rootEntry != &rootmenu && (mode == singleMode ||
438 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
Boris Barbulovskiee7298f2015-09-22 11:36:37 -0700439 item = (ConfigItem *)topLevelItem(0);
Mauro Carvalho Chehabcc1c08e2020-06-30 08:26:40 +0200440 if (!item && mode != symbolMode) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700441 item = new ConfigItem(this, 0, true);
Mauro Carvalho Chehabcc1c08e2020-06-30 08:26:40 +0200442 last = item;
443 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700444 }
445 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
446 rootEntry->sym && rootEntry->prompt) {
447 item = last ? last->nextSibling() : firstChild();
448 if (!item)
449 item = new ConfigItem(this, last, rootEntry, true);
450 else
451 item->testUpdateMenu(true);
452
453 updateMenuList(item, rootEntry);
454 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700455 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700456 return;
457 }
458update:
459 updateMenuList(this, rootEntry);
460 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700461 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700462}
463
464void ConfigList::setValue(ConfigItem* item, tristate val)
465{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700466 struct symbol* sym;
467 int type;
468 tristate oldval;
469
470 sym = item->menu ? item->menu->sym : 0;
471 if (!sym)
472 return;
473
474 type = sym_get_type(sym);
475 switch (type) {
476 case S_BOOLEAN:
477 case S_TRISTATE:
478 oldval = sym_get_tristate_value(sym);
479
480 if (!sym_set_tristate_value(sym, val))
481 return;
482 if (oldval == no && item->menu->list)
483 item->setExpanded(true);
484 parent()->updateList(item);
485 break;
486 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700487}
488
489void ConfigList::changeValue(ConfigItem* item)
490{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700491 struct symbol* sym;
492 struct menu* menu;
493 int type, oldexpr, newexpr;
494
495 menu = item->menu;
496 if (!menu)
497 return;
498 sym = menu->sym;
499 if (!sym) {
500 if (item->menu->list)
501 item->setExpanded(!item->isExpanded());
502 return;
503 }
504
505 type = sym_get_type(sym);
506 switch (type) {
507 case S_BOOLEAN:
508 case S_TRISTATE:
509 oldexpr = sym_get_tristate_value(sym);
510 newexpr = sym_toggle_tristate_value(sym);
511 if (item->menu->list) {
512 if (oldexpr == newexpr)
513 item->setExpanded(!item->isExpanded());
514 else if (oldexpr == no)
515 item->setExpanded(true);
516 }
517 if (oldexpr != newexpr)
518 parent()->updateList(item);
519 break;
520 case S_INT:
521 case S_HEX:
522 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700523 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700524 break;
525 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700526}
527
528void ConfigList::setRootMenu(struct menu *menu)
529{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700530 enum prop_type type;
531
532 if (rootEntry == menu)
533 return;
534 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
535 if (type != P_MENU)
536 return;
537 updateMenuList(this, 0);
538 rootEntry = menu;
539 updateListAll();
540 if (currentItem()) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200541 setSelected(currentItem(), hasFocus());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700542 scrollToItem(currentItem());
543 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700544}
545
546void ConfigList::setParentMenu(void)
547{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700548 ConfigItem* item;
549 struct menu *oldroot;
550
551 oldroot = rootEntry;
552 if (rootEntry == &rootmenu)
553 return;
554 setRootMenu(menu_get_parent_menu(rootEntry->parent));
555
556 QTreeWidgetItemIterator it(this);
557 while (*it) {
558 item = (ConfigItem *)(*it);
559 if (item->menu == oldroot) {
560 setCurrentItem(item);
561 scrollToItem(item);
562 break;
563 }
564
565 ++it;
566 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700567}
568
569/*
570 * update all the children of a menu entry
571 * removes/adds the entries from the parent widget as necessary
572 *
573 * parent: either the menu list widget or a menu entry widget
574 * menu: entry to be updated
575 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700576void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700577{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700578 struct menu* child;
579 ConfigItem* item;
580 ConfigItem* last;
581 bool visible;
582 enum prop_type type;
583
584 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700585 while (parent->childCount() > 0)
586 {
587 delete parent->takeChild(0);
588 }
589
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700590 return;
591 }
592
593 last = parent->firstChild();
594 if (last && !last->goParent)
595 last = 0;
596 for (child = menu->list; child; child = child->next) {
597 item = last ? last->nextSibling() : parent->firstChild();
598 type = child->prompt ? child->prompt->type : P_UNKNOWN;
599
600 switch (mode) {
601 case menuMode:
602 if (!(child->flags & MENU_ROOT))
603 goto hide;
604 break;
605 case symbolMode:
606 if (child->flags & MENU_ROOT)
607 goto hide;
608 break;
609 default:
610 break;
611 }
612
613 visible = menu_is_visible(child);
614 if (!menuSkip(child)) {
615 if (!child->sym && !child->list && !child->prompt)
616 continue;
617 if (!item || item->menu != child)
618 item = new ConfigItem(parent, last, child, visible);
619 else
620 item->testUpdateMenu(visible);
621
622 if (mode == fullMode || mode == menuMode || type != P_MENU)
623 updateMenuList(item, child);
624 else
625 updateMenuList(item, 0);
626 last = item;
627 continue;
628 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200629hide:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700630 if (item && item->menu == child) {
631 last = parent->firstChild();
632 if (last == item)
633 last = 0;
634 else while (last->nextSibling() != item)
635 last = last->nextSibling();
636 delete item;
637 }
638 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700639}
640
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700641void ConfigList::updateMenuList(ConfigList *parent, struct menu* menu)
642{
643 struct menu* child;
644 ConfigItem* item;
645 ConfigItem* last;
646 bool visible;
647 enum prop_type type;
648
649 if (!menu) {
650 while (parent->topLevelItemCount() > 0)
651 {
652 delete parent->takeTopLevelItem(0);
653 }
654
655 return;
656 }
657
658 last = (ConfigItem*)parent->topLevelItem(0);
659 if (last && !last->goParent)
660 last = 0;
661 for (child = menu->list; child; child = child->next) {
662 item = last ? last->nextSibling() : (ConfigItem*)parent->topLevelItem(0);
663 type = child->prompt ? child->prompt->type : P_UNKNOWN;
664
665 switch (mode) {
666 case menuMode:
667 if (!(child->flags & MENU_ROOT))
668 goto hide;
669 break;
670 case symbolMode:
671 if (child->flags & MENU_ROOT)
672 goto hide;
673 break;
674 default:
675 break;
676 }
677
678 visible = menu_is_visible(child);
679 if (!menuSkip(child)) {
680 if (!child->sym && !child->list && !child->prompt)
681 continue;
682 if (!item || item->menu != child)
683 item = new ConfigItem(parent, last, child, visible);
684 else
685 item->testUpdateMenu(visible);
686
687 if (mode == fullMode || mode == menuMode || type != P_MENU)
688 updateMenuList(item, child);
689 else
690 updateMenuList(item, 0);
691 last = item;
692 continue;
693 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200694hide:
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700695 if (item && item->menu == child) {
696 last = (ConfigItem*)parent->topLevelItem(0);
697 if (last == item)
698 last = 0;
699 else while (last->nextSibling() != item)
700 last = last->nextSibling();
701 delete item;
702 }
703 }
704}
705
Boris Barbulovski59e56442015-09-22 11:36:18 -0700706void ConfigList::keyPressEvent(QKeyEvent* ev)
707{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700708 QTreeWidgetItem* i = currentItem();
709 ConfigItem* item;
710 struct menu *menu;
711 enum prop_type type;
712
713 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
714 emit parentSelected();
715 ev->accept();
716 return;
717 }
718
719 if (!i) {
720 Parent::keyPressEvent(ev);
721 return;
722 }
723 item = (ConfigItem*)i;
724
725 switch (ev->key()) {
726 case Qt::Key_Return:
727 case Qt::Key_Enter:
728 if (item->goParent) {
729 emit parentSelected();
730 break;
731 }
732 menu = item->menu;
733 if (!menu)
734 break;
735 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
736 if (type == P_MENU && rootEntry != menu &&
737 mode != fullMode && mode != menuMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200738 if (mode == menuMode)
739 emit menuSelected(menu);
740 else
741 emit itemSelected(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700742 break;
743 }
744 case Qt::Key_Space:
745 changeValue(item);
746 break;
747 case Qt::Key_N:
748 setValue(item, no);
749 break;
750 case Qt::Key_M:
751 setValue(item, mod);
752 break;
753 case Qt::Key_Y:
754 setValue(item, yes);
755 break;
756 default:
757 Parent::keyPressEvent(ev);
758 return;
759 }
760 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700761}
762
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700763void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700764{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700765 //QPoint p(contentsToViewport(e->pos()));
766 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
767 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700768}
769
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700770void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700771{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700772 QPoint p = e->pos();
773 ConfigItem* item = (ConfigItem*)itemAt(p);
774 struct menu *menu;
775 enum prop_type ptype;
776 QIcon icon;
777 int idx, x;
778
779 if (!item)
780 goto skip;
781
782 menu = item->menu;
783 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700784 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700785 switch (idx) {
786 case promptColIdx:
787 icon = item->pixmap(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700788 if (!icon.isNull()) {
789 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
790 if (x >= off && x < off + icon.availableSizes().first().width()) {
791 if (item->goParent) {
792 emit parentSelected();
793 break;
794 } else if (!menu)
795 break;
796 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
797 if (ptype == P_MENU && rootEntry != menu &&
798 mode != fullMode && mode != menuMode)
799 emit menuSelected(menu);
800 else
801 changeValue(item);
802 }
803 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700804 break;
805 case noColIdx:
806 setValue(item, no);
807 break;
808 case modColIdx:
809 setValue(item, mod);
810 break;
811 case yesColIdx:
812 setValue(item, yes);
813 break;
814 case dataColIdx:
815 changeValue(item);
816 break;
817 }
818
819skip:
820 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
821 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700822}
823
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700824void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700825{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700826 //QPoint p(contentsToViewport(e->pos()));
827 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
828 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700829}
830
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700831void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700832{
Mauro Carvalho Chehabe1f77692020-04-02 11:28:02 +0200833 QPoint p = e->pos();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700834 ConfigItem* item = (ConfigItem*)itemAt(p);
835 struct menu *menu;
836 enum prop_type ptype;
837
838 if (!item)
839 goto skip;
840 if (item->goParent) {
841 emit parentSelected();
842 goto skip;
843 }
844 menu = item->menu;
845 if (!menu)
846 goto skip;
847 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200848 if (ptype == P_MENU) {
849 if (mode == singleMode)
850 emit itemSelected(menu);
851 else if (mode == symbolMode)
852 emit menuSelected(menu);
853 } else if (menu->sym)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700854 changeValue(item);
855
856skip:
857 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
858 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700859}
860
861void ConfigList::focusInEvent(QFocusEvent *e)
862{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700863 struct menu *menu = NULL;
864
865 Parent::focusInEvent(e);
866
867 ConfigItem* item = (ConfigItem *)currentItem();
868 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200869 setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700870 menu = item->menu;
871 }
872 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700873}
874
875void ConfigList::contextMenuEvent(QContextMenuEvent *e)
876{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700877 if (e->y() <= header()->geometry().bottom()) {
878 if (!headerPopup) {
879 QAction *action;
880
881 headerPopup = new QMenu(this);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200882 action = new QAction("Show Name", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700883 action->setCheckable(true);
884 connect(action, SIGNAL(toggled(bool)),
885 parent(), SLOT(setShowName(bool)));
886 connect(parent(), SIGNAL(showNameChanged(bool)),
887 action, SLOT(setOn(bool)));
888 action->setChecked(showName);
889 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200890 action = new QAction("Show Range", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700891 action->setCheckable(true);
892 connect(action, SIGNAL(toggled(bool)),
893 parent(), SLOT(setShowRange(bool)));
894 connect(parent(), SIGNAL(showRangeChanged(bool)),
895 action, SLOT(setOn(bool)));
896 action->setChecked(showRange);
897 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200898 action = new QAction("Show Data", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700899 action->setCheckable(true);
900 connect(action, SIGNAL(toggled(bool)),
901 parent(), SLOT(setShowData(bool)));
902 connect(parent(), SIGNAL(showDataChanged(bool)),
903 action, SLOT(setOn(bool)));
904 action->setChecked(showData);
905 headerPopup->addAction(action);
906 }
907 headerPopup->exec(e->globalPos());
908 e->accept();
909 } else
910 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700911}
912
Li Zefan39a48972010-05-10 16:33:41 +0800913ConfigView*ConfigView::viewList;
914QAction *ConfigView::showNormalAction;
915QAction *ConfigView::showAllAction;
916QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Roman Zippel7fc925f2006-06-08 22:12:46 -0700918ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700919 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700921 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700922 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700923 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700924
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700925 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700926 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 lineEdit = new ConfigLineEdit(this);
928 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700929 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 this->nextView = viewList;
932 viewList = this;
933}
934
935ConfigView::~ConfigView(void)
936{
937 ConfigView** vp;
938
939 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
940 if (*vp == this) {
941 *vp = nextView;
942 break;
943 }
944 }
945}
946
Li Zefan39a48972010-05-10 16:33:41 +0800947void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700948{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700949 if (act == showNormalAction)
950 list->optMode = normalOpt;
951 else if (act == showAllAction)
952 list->optMode = allOpt;
953 else
954 list->optMode = promptOpt;
955
956 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700957}
958
959void ConfigView::setShowName(bool b)
960{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700961 if (list->showName != b) {
962 list->showName = b;
963 list->reinit();
964 emit showNameChanged(b);
965 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700966}
967
968void ConfigView::setShowRange(bool b)
969{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700970 if (list->showRange != b) {
971 list->showRange = b;
972 list->reinit();
973 emit showRangeChanged(b);
974 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700975}
976
977void ConfigView::setShowData(bool b)
978{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700979 if (list->showData != b) {
980 list->showData = b;
981 list->reinit();
982 emit showDataChanged(b);
983 }
984}
985
986void ConfigList::setAllOpen(bool open)
987{
988 QTreeWidgetItemIterator it(this);
989
990 while (*it) {
991 (*it)->setExpanded(open);
992
993 ++it;
994 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700995}
996
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700997void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700998{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700999 ConfigView* v;
1000
1001 for (v = viewList; v; v = v->nextView)
1002 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003}
1004
1005void ConfigView::updateListAll(void)
1006{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001007 ConfigView* v;
1008
1009 for (v = viewList; v; v = v->nextView)
1010 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Roman Zippel43bf6122006-06-08 22:12:45 -07001013ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001014 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -07001015{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001016 setObjectName(name);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001017 setOpenLinks(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001018
1019 if (!objectName().isEmpty()) {
1020 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001021 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001022 configSettings->endGroup();
1023 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1024 }
1025}
1026
1027void ConfigInfoView::saveSettings(void)
1028{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001029 if (!objectName().isEmpty()) {
1030 configSettings->beginGroup(objectName());
1031 configSettings->setValue("/showDebug", showDebug());
1032 configSettings->endGroup();
1033 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001034}
1035
1036void ConfigInfoView::setShowDebug(bool b)
1037{
1038 if (_showDebug != b) {
1039 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001040 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001041 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001042 else if (sym)
1043 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001044 emit showDebugChanged(b);
1045 }
1046}
1047
1048void ConfigInfoView::setInfo(struct menu *m)
1049{
Alexander Stein133c5f72010-08-31 17:34:37 +02001050 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001051 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001052 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001053 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001054 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001055 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001056 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001057 menuInfo();
1058}
1059
Roman Zippelab45d192006-06-08 22:12:47 -07001060void ConfigInfoView::symbolInfo(void)
1061{
1062 QString str;
1063
1064 str += "<big>Symbol: <b>";
1065 str += print_filter(sym->name);
1066 str += "</b></big><br><br>value: ";
1067 str += print_filter(sym_get_string_value(sym));
1068 str += "<br>visibility: ";
1069 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1070 str += "<br>";
1071 str += debug_info(sym);
1072
1073 setText(str);
1074}
1075
Roman Zippel43bf6122006-06-08 22:12:45 -07001076void ConfigInfoView::menuInfo(void)
1077{
1078 struct symbol* sym;
1079 QString head, debug, help;
1080
Alexander Stein133c5f72010-08-31 17:34:37 +02001081 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001082 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001083 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001084 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001085 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001086 head += "</b></big>";
1087 if (sym->name) {
1088 head += " (";
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 += ")";
1095 }
1096 } else if (sym->name) {
1097 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001098 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001099 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001100 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001101 if (showDebug())
1102 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001103 head += "</b></big>";
1104 }
1105 head += "<br><br>";
1106
1107 if (showDebug())
1108 debug = debug_info(sym);
1109
Cheng Renquand74c15f2009-07-12 16:11:47 +08001110 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001111 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001112 help = print_filter(str_get(&help_gstr));
1113 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001114 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001115 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001116 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001117 head += "</b></big><br><br>";
1118 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001119 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001120 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001121 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001122 debug += "<br><br>";
1123 }
1124 }
1125 }
1126 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001127 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001128
1129 setText(head + debug + help);
1130}
1131
1132QString ConfigInfoView::debug_info(struct symbol *sym)
1133{
1134 QString debug;
1135
1136 debug += "type: ";
1137 debug += print_filter(sym_type_name(sym->type));
1138 if (sym_is_choice(sym))
1139 debug += " (choice)";
1140 debug += "<br>";
1141 if (sym->rev_dep.expr) {
1142 debug += "reverse dep: ";
1143 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1144 debug += "<br>";
1145 }
1146 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1147 switch (prop->type) {
1148 case P_PROMPT:
1149 case P_MENU:
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001150 debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001151 debug += print_filter(prop->text);
Roman Zippelab45d192006-06-08 22:12:47 -07001152 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001153 break;
1154 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001155 case P_SELECT:
1156 case P_RANGE:
Roman Zippel93449082008-01-14 04:50:54 +01001157 debug += prop_get_type_name(prop->type);
1158 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001159 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1160 debug += "<br>";
1161 break;
1162 case P_CHOICE:
1163 if (sym_is_choice(sym)) {
1164 debug += "choice: ";
1165 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1166 debug += "<br>";
1167 }
1168 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001169 default:
1170 debug += "unknown property: ";
1171 debug += prop_get_type_name(prop->type);
1172 debug += "<br>";
1173 }
1174 if (prop->visible.expr) {
1175 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1176 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1177 debug += "<br>";
1178 }
1179 }
1180 debug += "<br>";
1181
1182 return debug;
1183}
1184
1185QString ConfigInfoView::print_filter(const QString &str)
1186{
1187 QRegExp re("[<>&\"\\n]");
1188 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001189 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1190 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001191 case '<':
1192 res.replace(i, 1, "&lt;");
1193 i += 4;
1194 break;
1195 case '>':
1196 res.replace(i, 1, "&gt;");
1197 i += 4;
1198 break;
1199 case '&':
1200 res.replace(i, 1, "&amp;");
1201 i += 5;
1202 break;
1203 case '"':
1204 res.replace(i, 1, "&quot;");
1205 i += 6;
1206 break;
1207 case '\n':
1208 res.replace(i, 1, "<br>");
1209 i += 4;
1210 break;
1211 }
1212 }
1213 return res;
1214}
1215
Roman Zippelab45d192006-06-08 22:12:47 -07001216void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001217{
Roman Zippelab45d192006-06-08 22:12:47 -07001218 QString* text = reinterpret_cast<QString*>(data);
1219 QString str2 = print_filter(str);
1220
1221 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001222 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001223 *text += str2;
1224 *text += "</a>";
1225 } else
1226 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001227}
1228
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001229void ConfigInfoView::clicked(const QUrl &url)
1230{
1231 QByteArray str = url.toEncoded();
1232 const std::size_t count = str.size();
1233 char *data = new char[count + 1];
1234 struct symbol **result;
1235 struct menu *m = NULL;
1236 char type;
1237
1238 if (count < 1) {
1239 qInfo() << "Clicked link is empty";
1240 delete data;
1241 return;
1242 }
1243
1244 memcpy(data, str.constData(), count);
1245 data[count] = '\0';
1246 type = data[0];
1247
1248 /* Seek for exact match */
1249 data[0] = '^';
1250 strcat(data, "$");
1251 result = sym_re_search(data);
1252 if (!result) {
1253 qInfo() << "Clicked symbol is invalid:" << data;
1254 delete data;
1255 return;
1256 }
1257
1258 sym = *result;
1259 if (type == 's') {
1260 symbolInfo();
1261 emit showDebugChanged(true);
1262 free(result);
1263 delete data;
1264 return;
1265 }
1266
1267 /* URL is a menu */
1268 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1269 if (prop->type != P_PROMPT && prop->type != P_MENU)
1270 continue;
1271 m = prop->menu;
1272 break;
1273 }
1274
1275 if (!m) {
1276 qInfo() << "Clicked menu is invalid:" << data;
1277 free(result);
1278 delete data;
1279 return;
1280 }
1281
1282 _menu = m;
1283 menuInfo();
1284
1285 emit showDebugChanged(true);
1286 free(result);
1287 delete data;
1288}
1289
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001290QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001291{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001292 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001293 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001294
1295 action->setCheckable(true);
1296 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1297 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1298 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001299 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001300 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001301 return popup;
1302}
1303
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001304void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001305{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001306 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001307}
1308
Marco Costalba63431e72006-10-05 19:12:59 +02001309ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001310 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001311{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001312 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001313 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001314
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001315 QVBoxLayout* layout1 = new QVBoxLayout(this);
1316 layout1->setContentsMargins(11, 11, 11, 11);
1317 layout1->setSpacing(6);
1318 QHBoxLayout* layout2 = new QHBoxLayout(0);
1319 layout2->setContentsMargins(0, 0, 0, 0);
1320 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001321 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001322 editField = new QLineEdit(this);
1323 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1324 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001325 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001326 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001327 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1328 layout2->addWidget(searchButton);
1329 layout1->addLayout(layout2);
1330
Roman Zippel7fc925f2006-06-08 22:12:46 -07001331 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001332 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001333 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001334 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001335 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001336 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1337 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001338 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1339 parent, SLOT(setMenuLink(struct menu *)));
1340
Roman Zippel43bf6122006-06-08 22:12:45 -07001341 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001342
1343 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001344 QVariant x, y;
1345 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001346 bool ok;
1347
1348 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001349 width = configSettings->value("/window width", parent->width() / 2).toInt();
1350 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001351 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001352 x = configSettings->value("/window x");
1353 y = configSettings->value("/window y");
1354 if ((x.isValid())&&(y.isValid()))
1355 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001356 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001357 if (ok)
1358 split->setSizes(sizes);
1359 configSettings->endGroup();
1360 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1361 }
1362}
1363
1364void ConfigSearchWindow::saveSettings(void)
1365{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001366 if (!objectName().isEmpty()) {
1367 configSettings->beginGroup(objectName());
1368 configSettings->setValue("/window x", pos().x());
1369 configSettings->setValue("/window y", pos().y());
1370 configSettings->setValue("/window width", size().width());
1371 configSettings->setValue("/window height", size().height());
1372 configSettings->writeSizes("/split", split->sizes());
1373 configSettings->endGroup();
1374 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001375}
1376
1377void ConfigSearchWindow::search(void)
1378{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001379 struct symbol **p;
1380 struct property *prop;
1381 ConfigItem *lastItem = NULL;
1382
1383 free(result);
1384 list->list->clear();
1385 info->clear();
1386
1387 result = sym_re_search(editField->text().toLatin1());
1388 if (!result)
1389 return;
1390 for (p = result; *p; p++) {
1391 for_all_prompts((*p), prop)
1392 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1393 menu_is_visible(prop->menu));
1394 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001395}
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397/*
1398 * Construct the complete config widget
1399 */
1400ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001401 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
1403 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001404 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001405 QVariant x, y;
1406 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001407 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001409 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001410 snprintf(title, sizeof(title), "%s%s",
1411 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001412 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001413 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001414 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001416 width = configSettings->value("/window width", d->width() - 64).toInt();
1417 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001419 x = configSettings->value("/window x");
1420 y = configSettings->value("/window y");
1421 if ((x.isValid())&&(y.isValid()))
1422 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001424 QWidget *widget = new QWidget(this);
1425 QVBoxLayout *layout = new QVBoxLayout(widget);
1426 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001428 split1 = new QSplitter(widget);
1429 split1->setOrientation(Qt::Horizontal);
1430 split1->setChildrenCollapsible(false);
1431
1432 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 menuList = menuView->list;
1434
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001435 split2 = new QSplitter(widget);
1436 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001437 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
1439 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001440 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 configList = configView->list;
1442
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001443 helpText = new ConfigInfoView(widget, "help");
1444
1445 layout->addWidget(split2);
1446 split2->addWidget(split1);
1447 split1->addWidget(configView);
1448 split1->addWidget(menuView);
1449 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 setTabOrder(configList, helpText);
1452 configList->setFocus();
1453
1454 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001455 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001456 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001458 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001459 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1460
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001461 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001462 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001463 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1464
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001465 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001466 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001467 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1468
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001469 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001470 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001471 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1472
Karsten Wiese3b354c52006-12-13 00:34:08 -08001473 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001474
Karsten Wiese3b354c52006-12-13 00:34:08 -08001475 // Set saveAction's initial state
1476 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001477 configname = xstrdup(conf_get_configname());
1478
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001479 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001480 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001481 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001482 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001483 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001484 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001485 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001486 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001487 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001488 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001489 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001490 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001491 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001492 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001494 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001495 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001496 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001497 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001498 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001499 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001500 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001501 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001502 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001503 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001504
1505 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001506 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001507 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001508 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001509 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001510 SLOT(setOptionMode(QAction *)));
1511
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001512 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1513 configView->showAllAction = new QAction("Show All Options", optGroup);
1514 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001515 configView->showNormalAction->setCheckable(true);
1516 configView->showAllAction->setCheckable(true);
1517 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001518
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001519 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001520 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001521 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001522 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001524 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001525 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001526 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001527 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001530 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001532 toolBar->addAction(loadAction);
1533 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001535 toolBar->addAction(singleViewAction);
1536 toolBar->addAction(splitViewAction);
1537 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
1539 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001540 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001541 config->addAction(loadAction);
1542 config->addAction(saveAction);
1543 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001544 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001545 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Shlomi Fish66e7c722007-02-14 00:32:58 -08001547 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001548 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001549 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001550
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001552 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001553 optionMenu->addAction(showNameAction);
1554 optionMenu->addAction(showRangeAction);
1555 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001556 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001557 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001558 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001559 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001562 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001563 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001564 helpMenu->addAction(showIntroAction);
1565 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001567 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1568 helpText, SLOT (clicked (const QUrl &)) );
1569
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001570 connect(configList, SIGNAL(menuChanged(struct menu *)),
1571 helpText, SLOT(setInfo(struct menu *)));
1572 connect(configList, SIGNAL(menuSelected(struct menu *)),
1573 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001574 connect(configList, SIGNAL(itemSelected(struct menu *)),
1575 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001576 connect(configList, SIGNAL(parentSelected()),
1577 SLOT(goBack()));
1578 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1579 helpText, SLOT(setInfo(struct menu *)));
1580 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1581 SLOT(changeMenu(struct menu *)));
1582
1583 connect(configList, SIGNAL(gotFocus(struct menu *)),
1584 helpText, SLOT(setInfo(struct menu *)));
1585 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1586 helpText, SLOT(setInfo(struct menu *)));
1587 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1588 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001589 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1590 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001592 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 if (listMode == "single")
1594 showSingleView();
1595 else if (listMode == "full")
1596 showFullView();
1597 else /*if (listMode == "split")*/
1598 showSplitView();
1599
1600 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001601 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 if (ok)
1603 split1->setSizes(sizes);
1604
Roman Zippel7fc925f2006-06-08 22:12:46 -07001605 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 if (ok)
1607 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608}
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610void ConfigMainWindow::loadConfig(void)
1611{
Masahiro Yamada87419082019-03-11 01:13:15 +09001612 QString str;
1613 QByteArray ba;
1614 const char *name;
1615
1616 str = QFileDialog::getOpenFileName(this, "", configname);
1617 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001619
1620 ba = str.toLocal8Bit();
1621 name = ba.data();
1622
1623 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001624 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001625
1626 free(configname);
1627 configname = xstrdup(name);
1628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 ConfigView::updateListAll();
1630}
1631
Michal Marekbac6aa82011-05-25 15:10:25 +02001632bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
Masahiro Yamada87419082019-03-11 01:13:15 +09001634 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001635 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001636 return false;
1637 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001638 conf_write_autoconf(0);
1639
Michal Marekbac6aa82011-05-25 15:10:25 +02001640 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
1643void ConfigMainWindow::saveConfigAs(void)
1644{
Masahiro Yamada87419082019-03-11 01:13:15 +09001645 QString str;
1646 QByteArray ba;
1647 const char *name;
1648
1649 str = QFileDialog::getSaveFileName(this, "", configname);
1650 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001652
1653 ba = str.toLocal8Bit();
1654 name = ba.data();
1655
1656 if (conf_write(name)) {
1657 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1658 }
1659 conf_write_autoconf(0);
1660
1661 free(configname);
1662 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Roman Zippel43bf6122006-06-08 22:12:45 -07001665void ConfigMainWindow::searchConfig(void)
1666{
1667 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001668 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001669 searchWindow->show();
1670}
1671
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001672void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001674 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675}
1676
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001677void ConfigMainWindow::changeMenu(struct menu *menu)
1678{
1679 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001680}
1681
Roman Zippelb65a47e2006-06-08 22:12:47 -07001682void ConfigMainWindow::setMenuLink(struct menu *menu)
1683{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001684 struct menu *parent;
1685 ConfigList* list = NULL;
1686 ConfigItem* item;
1687
1688 if (configList->menuSkip(menu))
1689 return;
1690
1691 switch (configList->mode) {
1692 case singleMode:
1693 list = configList;
1694 parent = menu_get_parent_menu(menu);
1695 if (!parent)
1696 return;
1697 list->setRootMenu(parent);
1698 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001699 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001700 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001701 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001702 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001703 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001704 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001705 parent = menu_get_parent_menu(menu->parent);
1706 if (!parent)
1707 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001708
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001709 /* Select the config view */
1710 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001711 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001712 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001713 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001714 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001715
1716 menuList->setRootMenu(parent);
1717 menuList->clearSelection();
1718 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001719 }
1720 break;
1721 case fullMode:
1722 list = configList;
1723 break;
1724 default:
1725 break;
1726 }
1727
1728 if (list) {
1729 item = list->findConfigItem(menu);
1730 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001731 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001732 list->scrollToItem(item);
1733 list->setFocus();
1734 }
1735 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001736}
1737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738void ConfigMainWindow::listFocusChanged(void)
1739{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001740 if (menuList->mode == menuMode)
1741 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742}
1743
1744void ConfigMainWindow::goBack(void)
1745{
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001746qInfo() << __FUNCTION__;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001747 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001748 return;
1749
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001750 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
1753void ConfigMainWindow::showSingleView(void)
1754{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001755 singleViewAction->setEnabled(false);
1756 singleViewAction->setChecked(true);
1757 splitViewAction->setEnabled(true);
1758 splitViewAction->setChecked(false);
1759 fullViewAction->setEnabled(true);
1760 fullViewAction->setChecked(false);
1761
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001762 backAction->setEnabled(true);
1763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001765 menuList->setRootMenu(0);
1766 configList->mode = singleMode;
1767 if (configList->rootEntry == &rootmenu)
1768 configList->updateListAll();
1769 else
1770 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 configList->setFocus();
1772}
1773
1774void ConfigMainWindow::showSplitView(void)
1775{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001776 singleViewAction->setEnabled(true);
1777 singleViewAction->setChecked(false);
1778 splitViewAction->setEnabled(false);
1779 splitViewAction->setChecked(true);
1780 fullViewAction->setEnabled(true);
1781 fullViewAction->setChecked(false);
1782
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001783 backAction->setEnabled(false);
1784
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001785 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001786 if (configList->rootEntry == &rootmenu)
1787 configList->updateListAll();
1788 else
1789 configList->setRootMenu(&rootmenu);
1790 configList->setAllOpen(true);
1791 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001792 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001793 menuList->setRootMenu(&rootmenu);
1794 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 menuView->show();
1796 menuList->setFocus();
1797}
1798
1799void ConfigMainWindow::showFullView(void)
1800{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001801 singleViewAction->setEnabled(true);
1802 singleViewAction->setChecked(false);
1803 splitViewAction->setEnabled(true);
1804 splitViewAction->setChecked(false);
1805 fullViewAction->setEnabled(false);
1806 fullViewAction->setChecked(true);
1807
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001808 backAction->setEnabled(false);
1809
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001811 menuList->setRootMenu(0);
1812 configList->mode = fullMode;
1813 if (configList->rootEntry == &rootmenu)
1814 configList->updateListAll();
1815 else
1816 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 configList->setFocus();
1818}
1819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820/*
1821 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 */
1823void ConfigMainWindow::closeEvent(QCloseEvent* e)
1824{
Karsten Wieseb3214292006-12-13 00:34:06 -08001825 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 e->accept();
1827 return;
1828 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001829 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001831 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1832 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1833 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 switch (mb.exec()) {
1835 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001836 if (saveConfig())
1837 e->accept();
1838 else
1839 e->ignore();
1840 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 case QMessageBox::No:
1842 e->accept();
1843 break;
1844 case QMessageBox::Cancel:
1845 e->ignore();
1846 break;
1847 }
1848}
1849
1850void ConfigMainWindow::showIntro(void)
1851{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001852 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 "For each option, a blank box indicates the feature is disabled, a check\n"
1854 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1855 "as a module. Clicking on the box will cycle through the three states.\n\n"
1856 "If you do not see an option (e.g., a device driver) that you believe\n"
1857 "should be present, try turning on Show All Options under the Options menu.\n"
1858 "Although there is no cross reference yet to help you figure out what other\n"
1859 "options must be enabled to support the option you are interested in, you can\n"
1860 "still view the help of a grayed-out option.\n\n"
1861 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001862 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 QMessageBox::information(this, "qconf", str);
1865}
1866
1867void ConfigMainWindow::showAbout(void)
1868{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001869 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001870 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001871 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
1873 QMessageBox::information(this, "qconf", str);
1874}
1875
1876void ConfigMainWindow::saveSettings(void)
1877{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001878 configSettings->setValue("/window x", pos().x());
1879 configSettings->setValue("/window y", pos().y());
1880 configSettings->setValue("/window width", size().width());
1881 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
1883 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001884 switch(configList->mode) {
1885 case singleMode :
1886 entry = "single";
1887 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001889 case symbolMode :
1890 entry = "split";
1891 break;
1892
1893 case fullMode :
1894 entry = "full";
1895 break;
1896
1897 default:
1898 break;
1899 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001900 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
Roman Zippel7fc925f2006-06-08 22:12:46 -07001902 configSettings->writeSizes("/split1", split1->sizes());
1903 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
1905
Karsten Wiese3b354c52006-12-13 00:34:08 -08001906void ConfigMainWindow::conf_changed(void)
1907{
1908 if (saveAction)
1909 saveAction->setEnabled(conf_get_changed());
1910}
1911
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912void fixup_rootmenu(struct menu *menu)
1913{
1914 struct menu *child;
1915 static int menu_cnt = 0;
1916
1917 menu->flags |= MENU_ROOT;
1918 for (child = menu->list; child; child = child->next) {
1919 if (child->prompt && child->prompt->type == P_MENU) {
1920 menu_cnt++;
1921 fixup_rootmenu(child);
1922 menu_cnt--;
1923 } else if (!menu_cnt)
1924 fixup_rootmenu(child);
1925 }
1926}
1927
1928static const char *progname;
1929
1930static void usage(void)
1931{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001932 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 exit(0);
1934}
1935
1936int main(int ac, char** av)
1937{
1938 ConfigMainWindow* v;
1939 const char *name;
1940
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 progname = av[0];
1942 configApp = new QApplication(ac, av);
1943 if (ac > 1 && av[1][0] == '-') {
1944 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001945 case 's':
1946 conf_set_message_callback(NULL);
1947 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 case 'h':
1949 case '?':
1950 usage();
1951 }
1952 name = av[2];
1953 } else
1954 name = av[1];
1955 if (!name)
1956 usage();
1957
1958 conf_parse(name);
1959 fixup_rootmenu(&rootmenu);
1960 conf_read(NULL);
1961 //zconfdump(stdout);
1962
Roman Zippel7fc925f2006-06-08 22:12:46 -07001963 configSettings = new ConfigSettings();
1964 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 v = new ConfigMainWindow();
1966
1967 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1969 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001970 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 configApp->exec();
1972
Roman Zippel7fc925f2006-06-08 22:12:46 -07001973 configSettings->endGroup();
1974 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001975 delete v;
1976 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 return 0;
1979}