blob: d969beed287a9bf7c2ae72f68b14a7d8263653b7 [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
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010034ConfigSettings::ConfigSettings()
35 : QSettings("kernel.org", "qconf")
36{
37}
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/**
40 * Reads a list of integer values from the application settings.
41 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070042QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070044 QList<int> result;
Li Zefanc1f96f02010-05-07 13:58:04 +080045
Boris Barbulovski83c3a1b2016-11-30 14:57:55 -080046 if (contains(key))
47 {
48 QStringList entryList = value(key).toStringList();
49 QStringList::Iterator it;
50
51 for (it = entryList.begin(); it != entryList.end(); ++it)
52 result.push_back((*it).toInt());
53
54 *ok = true;
55 }
56 else
57 *ok = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 return result;
60}
61
62/**
63 * Writes a list of integer values to the application settings.
64 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070065bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070068 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 for (it = value.begin(); it != value.end(); ++it)
71 stringList.push_back(QString::number(*it));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070072 setValue(key, stringList);
Boris Barbulovski59e56442015-09-22 11:36:18 -070073
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070074 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Boris Barbulovski59e56442015-09-22 11:36:18 -070077
78/*
79 * set the new data
80 * TODO check the value
81 */
82void ConfigItem::okRename(int col)
83{
84}
85
86/*
87 * update the displayed of a menu entry
88 */
89void ConfigItem::updateMenu(void)
90{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070091 ConfigList* list;
92 struct symbol* sym;
93 struct property *prop;
94 QString prompt;
95 int type;
96 tristate expr;
97
98 list = listView();
99 if (goParent) {
100 setPixmap(promptColIdx, list->menuBackPix);
101 prompt = "..";
102 goto set_prompt;
103 }
104
105 sym = menu->sym;
106 prop = menu->prompt;
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900107 prompt = menu_get_prompt(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700108
109 if (prop) switch (prop->type) {
110 case P_MENU:
111 if (list->mode == singleMode || list->mode == symbolMode) {
112 /* a menuconfig entry is displayed differently
113 * depending whether it's at the view root or a child.
114 */
115 if (sym && list->rootEntry == menu)
116 break;
117 setPixmap(promptColIdx, list->menuPix);
118 } else {
119 if (sym)
120 break;
121 setPixmap(promptColIdx, QIcon());
122 }
123 goto set_prompt;
124 case P_COMMENT:
125 setPixmap(promptColIdx, QIcon());
126 goto set_prompt;
127 default:
128 ;
129 }
130 if (!sym)
131 goto set_prompt;
132
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900133 setText(nameColIdx, sym->name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700134
135 type = sym_get_type(sym);
136 switch (type) {
137 case S_BOOLEAN:
138 case S_TRISTATE:
139 char ch;
140
Marco Ammonbaa23ec2019-07-04 12:50:41 +0200141 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700142 setPixmap(promptColIdx, QIcon());
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200143 setText(noColIdx, QString());
144 setText(modColIdx, QString());
145 setText(yesColIdx, QString());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700146 break;
147 }
148 expr = sym_get_tristate_value(sym);
149 switch (expr) {
150 case yes:
151 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
152 setPixmap(promptColIdx, list->choiceYesPix);
153 else
154 setPixmap(promptColIdx, list->symbolYesPix);
155 setText(yesColIdx, "Y");
156 ch = 'Y';
157 break;
158 case mod:
159 setPixmap(promptColIdx, list->symbolModPix);
160 setText(modColIdx, "M");
161 ch = 'M';
162 break;
163 default:
164 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
165 setPixmap(promptColIdx, list->choiceNoPix);
166 else
167 setPixmap(promptColIdx, list->symbolNoPix);
168 setText(noColIdx, "N");
169 ch = 'N';
170 break;
171 }
172 if (expr != no)
173 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
174 if (expr != mod)
175 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
176 if (expr != yes)
177 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
178
179 setText(dataColIdx, QChar(ch));
180 break;
181 case S_INT:
182 case S_HEX:
183 case S_STRING:
184 const char* data;
185
186 data = sym_get_string_value(sym);
187
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700188 setText(dataColIdx, data);
189 if (type == S_STRING)
190 prompt = QString("%1: %2").arg(prompt).arg(data);
191 else
192 prompt = QString("(%2) %1").arg(prompt).arg(data);
193 break;
194 }
195 if (!sym_has_value(sym) && visible)
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200196 prompt += " (NEW)";
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700197set_prompt:
198 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700199}
200
201void ConfigItem::testUpdateMenu(bool v)
202{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700203 ConfigItem* i;
204
205 visible = v;
206 if (!menu)
207 return;
208
209 sym_calc_value(menu->sym);
210 if (menu->flags & MENU_CHANGED) {
211 /* the menu entry changed, so update all list items */
212 menu->flags &= ~MENU_CHANGED;
213 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
214 i->updateMenu();
215 } else if (listView()->updateAll)
216 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700217}
218
219
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700220/*
221 * construct a menu entry
222 */
223void ConfigItem::init(void)
224{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700225 if (menu) {
226 ConfigList* list = listView();
227 nextItem = (ConfigItem*)menu->data;
228 menu->data = this;
229
230 if (list->mode != fullMode)
231 setExpanded(true);
232 sym_calc_value(menu->sym);
233 }
234 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700235}
236
237/*
238 * destruct a menu entry
239 */
240ConfigItem::~ConfigItem(void)
241{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700242 if (menu) {
243 ConfigItem** ip = (ConfigItem**)&menu->data;
244 for (; *ip; ip = &(*ip)->nextItem) {
245 if (*ip == this) {
246 *ip = nextItem;
247 break;
248 }
249 }
250 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700251}
252
Roman Zippel43bf6122006-06-08 22:12:45 -0700253ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
254 : Parent(parent)
255{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700256 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700257}
258
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700259void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
261 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700262 if (sym_get_string_value(item->menu->sym))
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900263 setText(sym_get_string_value(item->menu->sym));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700264 else
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200265 setText(QString());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 Parent::show();
267 setFocus();
268}
269
270void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
271{
272 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200273 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200275 case Qt::Key_Return:
276 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700277 sym_set_string_value(item->menu->sym, text().toLatin1());
Masahiro Yamada10316852020-08-07 18:19:00 +0900278 parent()->updateList();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 break;
280 default:
281 Parent::keyPressEvent(e);
282 return;
283 }
284 e->accept();
285 parent()->list->setFocus();
286 hide();
287}
288
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700289ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700290 : Parent(p),
291 updateAll(false),
292 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
293 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
294 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700295 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700296 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700297{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700298 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700299 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700300 setRootIsDecorated(true);
301
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700302 setVerticalScrollMode(ScrollPerPixel);
303 setHorizontalScrollMode(ScrollPerPixel);
304
Masahiro Yamada97bebbc2020-07-30 02:46:17 +0900305 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700306
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700307 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700308 SLOT(updateSelection(void)));
309
310 if (name) {
311 configSettings->beginGroup(name);
312 showName = configSettings->value("/showName", false).toBool();
313 showRange = configSettings->value("/showRange", false).toBool();
314 showData = configSettings->value("/showData", false).toBool();
315 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
316 configSettings->endGroup();
317 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
318 }
319
320 addColumn(promptColIdx);
321
322 reinit();
323}
324
325bool ConfigList::menuSkip(struct menu *menu)
326{
327 if (optMode == normalOpt && menu_is_visible(menu))
328 return false;
329 if (optMode == promptOpt && menu_has_prompt(menu))
330 return false;
331 if (optMode == allOpt)
332 return false;
333 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700334}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700335
336void ConfigList::reinit(void)
337{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700338 removeColumn(dataColIdx);
339 removeColumn(yesColIdx);
340 removeColumn(modColIdx);
341 removeColumn(noColIdx);
342 removeColumn(nameColIdx);
343
344 if (showName)
345 addColumn(nameColIdx);
346 if (showRange) {
347 addColumn(noColIdx);
348 addColumn(modColIdx);
349 addColumn(yesColIdx);
350 }
351 if (showData)
352 addColumn(dataColIdx);
353
354 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700355}
356
357void ConfigList::saveSettings(void)
358{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700359 if (!objectName().isEmpty()) {
360 configSettings->beginGroup(objectName());
361 configSettings->setValue("/showName", showName);
362 configSettings->setValue("/showRange", showRange);
363 configSettings->setValue("/showData", showData);
364 configSettings->setValue("/optionMode", (int)optMode);
365 configSettings->endGroup();
366 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700367}
368
369ConfigItem* ConfigList::findConfigItem(struct menu *menu)
370{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700371 ConfigItem* item = (ConfigItem*)menu->data;
372
373 for (; item; item = item->nextItem) {
374 if (this == item->listView())
375 break;
376 }
377
378 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700379}
380
381void ConfigList::updateSelection(void)
382{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700383 struct menu *menu;
384 enum prop_type type;
385
Boris Barbulovskibe596aa2015-09-22 11:36:28 -0700386 if (selectedItems().count() == 0)
387 return;
388
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700389 ConfigItem* item = (ConfigItem*)selectedItems().first();
390 if (!item)
391 return;
392
393 menu = item->menu;
394 emit menuChanged(menu);
395 if (!menu)
396 return;
397 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
398 if (mode == menuMode && type == P_MENU)
399 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700400}
401
Masahiro Yamadacb770432020-08-07 18:18:59 +0900402void ConfigList::updateList()
Boris Barbulovski59e56442015-09-22 11:36:18 -0700403{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700404 ConfigItem* last = 0;
Masahiro Yamadacb770432020-08-07 18:18:59 +0900405 ConfigItem *item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700406
407 if (!rootEntry) {
408 if (mode != listMode)
409 goto update;
410 QTreeWidgetItemIterator it(this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700411
412 while (*it) {
413 item = (ConfigItem*)(*it);
414 if (!item->menu)
415 continue;
416 item->testUpdateMenu(menu_is_visible(item->menu));
417
418 ++it;
419 }
420 return;
421 }
422
423 if (rootEntry != &rootmenu && (mode == singleMode ||
424 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
Boris Barbulovskiee7298f2015-09-22 11:36:37 -0700425 item = (ConfigItem *)topLevelItem(0);
Masahiro Yamada4b20e102020-08-01 16:08:49 +0900426 if (!item)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700427 item = new ConfigItem(this, 0, true);
Masahiro Yamada4b20e102020-08-01 16:08:49 +0900428 last = item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700429 }
430 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
431 rootEntry->sym && rootEntry->prompt) {
Masahiro Yamadaccf56e52020-08-01 16:08:50 +0900432 item = last ? last->nextSibling() : nullptr;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700433 if (!item)
434 item = new ConfigItem(this, last, rootEntry, true);
435 else
436 item->testUpdateMenu(true);
437
438 updateMenuList(item, rootEntry);
439 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700440 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700441 return;
442 }
443update:
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900444 updateMenuList(rootEntry);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700445 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700446 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700447}
448
449void ConfigList::setValue(ConfigItem* item, tristate val)
450{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700451 struct symbol* sym;
452 int type;
453 tristate oldval;
454
455 sym = item->menu ? item->menu->sym : 0;
456 if (!sym)
457 return;
458
459 type = sym_get_type(sym);
460 switch (type) {
461 case S_BOOLEAN:
462 case S_TRISTATE:
463 oldval = sym_get_tristate_value(sym);
464
465 if (!sym_set_tristate_value(sym, val))
466 return;
467 if (oldval == no && item->menu->list)
468 item->setExpanded(true);
Masahiro Yamada10316852020-08-07 18:19:00 +0900469 parent()->updateList();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700470 break;
471 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700472}
473
474void ConfigList::changeValue(ConfigItem* item)
475{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700476 struct symbol* sym;
477 struct menu* menu;
478 int type, oldexpr, newexpr;
479
480 menu = item->menu;
481 if (!menu)
482 return;
483 sym = menu->sym;
484 if (!sym) {
485 if (item->menu->list)
486 item->setExpanded(!item->isExpanded());
487 return;
488 }
489
490 type = sym_get_type(sym);
491 switch (type) {
492 case S_BOOLEAN:
493 case S_TRISTATE:
494 oldexpr = sym_get_tristate_value(sym);
495 newexpr = sym_toggle_tristate_value(sym);
496 if (item->menu->list) {
497 if (oldexpr == newexpr)
498 item->setExpanded(!item->isExpanded());
499 else if (oldexpr == no)
500 item->setExpanded(true);
501 }
502 if (oldexpr != newexpr)
Masahiro Yamada10316852020-08-07 18:19:00 +0900503 parent()->updateList();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700504 break;
505 case S_INT:
506 case S_HEX:
507 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700508 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700509 break;
510 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700511}
512
513void ConfigList::setRootMenu(struct menu *menu)
514{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700515 enum prop_type type;
516
517 if (rootEntry == menu)
518 return;
519 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
520 if (type != P_MENU)
521 return;
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900522 updateMenuList(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700523 rootEntry = menu;
524 updateListAll();
525 if (currentItem()) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200526 setSelected(currentItem(), hasFocus());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700527 scrollToItem(currentItem());
528 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700529}
530
531void ConfigList::setParentMenu(void)
532{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700533 ConfigItem* item;
534 struct menu *oldroot;
535
536 oldroot = rootEntry;
537 if (rootEntry == &rootmenu)
538 return;
539 setRootMenu(menu_get_parent_menu(rootEntry->parent));
540
541 QTreeWidgetItemIterator it(this);
542 while (*it) {
543 item = (ConfigItem *)(*it);
544 if (item->menu == oldroot) {
545 setCurrentItem(item);
546 scrollToItem(item);
547 break;
548 }
549
550 ++it;
551 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700552}
553
554/*
555 * update all the children of a menu entry
556 * removes/adds the entries from the parent widget as necessary
557 *
558 * parent: either the menu list widget or a menu entry widget
559 * menu: entry to be updated
560 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700561void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700562{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700563 struct menu* child;
564 ConfigItem* item;
565 ConfigItem* last;
566 bool visible;
567 enum prop_type type;
568
569 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700570 while (parent->childCount() > 0)
571 {
572 delete parent->takeChild(0);
573 }
574
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700575 return;
576 }
577
578 last = parent->firstChild();
579 if (last && !last->goParent)
580 last = 0;
581 for (child = menu->list; child; child = child->next) {
582 item = last ? last->nextSibling() : parent->firstChild();
583 type = child->prompt ? child->prompt->type : P_UNKNOWN;
584
585 switch (mode) {
586 case menuMode:
587 if (!(child->flags & MENU_ROOT))
588 goto hide;
589 break;
590 case symbolMode:
591 if (child->flags & MENU_ROOT)
592 goto hide;
593 break;
594 default:
595 break;
596 }
597
598 visible = menu_is_visible(child);
599 if (!menuSkip(child)) {
600 if (!child->sym && !child->list && !child->prompt)
601 continue;
602 if (!item || item->menu != child)
603 item = new ConfigItem(parent, last, child, visible);
604 else
605 item->testUpdateMenu(visible);
606
607 if (mode == fullMode || mode == menuMode || type != P_MENU)
608 updateMenuList(item, child);
609 else
610 updateMenuList(item, 0);
611 last = item;
612 continue;
613 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200614hide:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700615 if (item && item->menu == child) {
616 last = parent->firstChild();
617 if (last == item)
618 last = 0;
619 else while (last->nextSibling() != item)
620 last = last->nextSibling();
621 delete item;
622 }
623 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700624}
625
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900626void ConfigList::updateMenuList(struct menu *menu)
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700627{
628 struct menu* child;
629 ConfigItem* item;
630 ConfigItem* last;
631 bool visible;
632 enum prop_type type;
633
634 if (!menu) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900635 while (topLevelItemCount() > 0)
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700636 {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900637 delete takeTopLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700638 }
639
640 return;
641 }
642
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900643 last = (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700644 if (last && !last->goParent)
645 last = 0;
646 for (child = menu->list; child; child = child->next) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900647 item = last ? last->nextSibling() : (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700648 type = child->prompt ? child->prompt->type : P_UNKNOWN;
649
650 switch (mode) {
651 case menuMode:
652 if (!(child->flags & MENU_ROOT))
653 goto hide;
654 break;
655 case symbolMode:
656 if (child->flags & MENU_ROOT)
657 goto hide;
658 break;
659 default:
660 break;
661 }
662
663 visible = menu_is_visible(child);
664 if (!menuSkip(child)) {
665 if (!child->sym && !child->list && !child->prompt)
666 continue;
667 if (!item || item->menu != child)
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900668 item = new ConfigItem(this, last, child, visible);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700669 else
670 item->testUpdateMenu(visible);
671
672 if (mode == fullMode || mode == menuMode || type != P_MENU)
673 updateMenuList(item, child);
674 else
675 updateMenuList(item, 0);
676 last = item;
677 continue;
678 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200679hide:
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700680 if (item && item->menu == child) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900681 last = (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700682 if (last == item)
683 last = 0;
684 else while (last->nextSibling() != item)
685 last = last->nextSibling();
686 delete item;
687 }
688 }
689}
690
Boris Barbulovski59e56442015-09-22 11:36:18 -0700691void ConfigList::keyPressEvent(QKeyEvent* ev)
692{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700693 QTreeWidgetItem* i = currentItem();
694 ConfigItem* item;
695 struct menu *menu;
696 enum prop_type type;
697
698 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
699 emit parentSelected();
700 ev->accept();
701 return;
702 }
703
704 if (!i) {
705 Parent::keyPressEvent(ev);
706 return;
707 }
708 item = (ConfigItem*)i;
709
710 switch (ev->key()) {
711 case Qt::Key_Return:
712 case Qt::Key_Enter:
713 if (item->goParent) {
714 emit parentSelected();
715 break;
716 }
717 menu = item->menu;
718 if (!menu)
719 break;
720 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
721 if (type == P_MENU && rootEntry != menu &&
722 mode != fullMode && mode != menuMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200723 if (mode == menuMode)
724 emit menuSelected(menu);
725 else
726 emit itemSelected(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700727 break;
728 }
729 case Qt::Key_Space:
730 changeValue(item);
731 break;
732 case Qt::Key_N:
733 setValue(item, no);
734 break;
735 case Qt::Key_M:
736 setValue(item, mod);
737 break;
738 case Qt::Key_Y:
739 setValue(item, yes);
740 break;
741 default:
742 Parent::keyPressEvent(ev);
743 return;
744 }
745 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700746}
747
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700748void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700749{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700750 //QPoint p(contentsToViewport(e->pos()));
751 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
752 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700753}
754
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700755void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700756{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700757 QPoint p = e->pos();
758 ConfigItem* item = (ConfigItem*)itemAt(p);
759 struct menu *menu;
760 enum prop_type ptype;
761 QIcon icon;
762 int idx, x;
763
764 if (!item)
765 goto skip;
766
767 menu = item->menu;
768 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700769 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700770 switch (idx) {
771 case promptColIdx:
772 icon = item->pixmap(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700773 if (!icon.isNull()) {
774 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
775 if (x >= off && x < off + icon.availableSizes().first().width()) {
776 if (item->goParent) {
777 emit parentSelected();
778 break;
779 } else if (!menu)
780 break;
781 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
782 if (ptype == P_MENU && rootEntry != menu &&
Maxime Chretien7eb7c106f2020-07-08 15:32:15 +0200783 mode != fullMode && mode != menuMode &&
784 mode != listMode)
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700785 emit menuSelected(menu);
786 else
787 changeValue(item);
788 }
789 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700790 break;
791 case noColIdx:
792 setValue(item, no);
793 break;
794 case modColIdx:
795 setValue(item, mod);
796 break;
797 case yesColIdx:
798 setValue(item, yes);
799 break;
800 case dataColIdx:
801 changeValue(item);
802 break;
803 }
804
805skip:
806 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
807 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700808}
809
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700810void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700811{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700812 //QPoint p(contentsToViewport(e->pos()));
813 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
814 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700815}
816
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700817void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700818{
Mauro Carvalho Chehabe1f77692020-04-02 11:28:02 +0200819 QPoint p = e->pos();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700820 ConfigItem* item = (ConfigItem*)itemAt(p);
821 struct menu *menu;
822 enum prop_type ptype;
823
824 if (!item)
825 goto skip;
826 if (item->goParent) {
827 emit parentSelected();
828 goto skip;
829 }
830 menu = item->menu;
831 if (!menu)
832 goto skip;
833 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
Maxime Chretien7eb7c106f2020-07-08 15:32:15 +0200834 if (ptype == P_MENU && mode != listMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200835 if (mode == singleMode)
836 emit itemSelected(menu);
837 else if (mode == symbolMode)
838 emit menuSelected(menu);
839 } else if (menu->sym)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700840 changeValue(item);
841
842skip:
843 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
844 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700845}
846
847void ConfigList::focusInEvent(QFocusEvent *e)
848{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700849 struct menu *menu = NULL;
850
851 Parent::focusInEvent(e);
852
853 ConfigItem* item = (ConfigItem *)currentItem();
854 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200855 setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700856 menu = item->menu;
857 }
858 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700859}
860
861void ConfigList::contextMenuEvent(QContextMenuEvent *e)
862{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700863 if (e->y() <= header()->geometry().bottom()) {
864 if (!headerPopup) {
865 QAction *action;
866
867 headerPopup = new QMenu(this);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200868 action = new QAction("Show Name", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700869 action->setCheckable(true);
870 connect(action, SIGNAL(toggled(bool)),
871 parent(), SLOT(setShowName(bool)));
872 connect(parent(), SIGNAL(showNameChanged(bool)),
873 action, SLOT(setOn(bool)));
874 action->setChecked(showName);
875 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200876 action = new QAction("Show Range", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700877 action->setCheckable(true);
878 connect(action, SIGNAL(toggled(bool)),
879 parent(), SLOT(setShowRange(bool)));
880 connect(parent(), SIGNAL(showRangeChanged(bool)),
881 action, SLOT(setOn(bool)));
882 action->setChecked(showRange);
883 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200884 action = new QAction("Show Data", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700885 action->setCheckable(true);
886 connect(action, SIGNAL(toggled(bool)),
887 parent(), SLOT(setShowData(bool)));
888 connect(parent(), SIGNAL(showDataChanged(bool)),
889 action, SLOT(setOn(bool)));
890 action->setChecked(showData);
891 headerPopup->addAction(action);
892 }
893 headerPopup->exec(e->globalPos());
894 e->accept();
895 } else
896 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700897}
898
Li Zefan39a48972010-05-10 16:33:41 +0800899ConfigView*ConfigView::viewList;
900QAction *ConfigView::showNormalAction;
901QAction *ConfigView::showAllAction;
902QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Roman Zippel7fc925f2006-06-08 22:12:46 -0700904ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700905 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700907 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700908 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700909 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700910
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700911 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700912 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 lineEdit = new ConfigLineEdit(this);
914 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700915 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917 this->nextView = viewList;
918 viewList = this;
919}
920
921ConfigView::~ConfigView(void)
922{
923 ConfigView** vp;
924
925 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
926 if (*vp == this) {
927 *vp = nextView;
928 break;
929 }
930 }
931}
932
Li Zefan39a48972010-05-10 16:33:41 +0800933void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700934{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700935 if (act == showNormalAction)
936 list->optMode = normalOpt;
937 else if (act == showAllAction)
938 list->optMode = allOpt;
939 else
940 list->optMode = promptOpt;
941
942 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700943}
944
945void ConfigView::setShowName(bool b)
946{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700947 if (list->showName != b) {
948 list->showName = b;
949 list->reinit();
950 emit showNameChanged(b);
951 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700952}
953
954void ConfigView::setShowRange(bool b)
955{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700956 if (list->showRange != b) {
957 list->showRange = b;
958 list->reinit();
959 emit showRangeChanged(b);
960 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700961}
962
963void ConfigView::setShowData(bool b)
964{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700965 if (list->showData != b) {
966 list->showData = b;
967 list->reinit();
968 emit showDataChanged(b);
969 }
970}
971
972void ConfigList::setAllOpen(bool open)
973{
974 QTreeWidgetItemIterator it(this);
975
976 while (*it) {
977 (*it)->setExpanded(open);
978
979 ++it;
980 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700981}
982
Masahiro Yamada10316852020-08-07 18:19:00 +0900983void ConfigView::updateList()
Roman Zippel7fc925f2006-06-08 22:12:46 -0700984{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700985 ConfigView* v;
986
987 for (v = viewList; v; v = v->nextView)
Masahiro Yamadacb770432020-08-07 18:18:59 +0900988 v->list->updateList();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
991void ConfigView::updateListAll(void)
992{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700993 ConfigView* v;
994
995 for (v = viewList; v; v = v->nextView)
996 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
Roman Zippel43bf6122006-06-08 22:12:45 -0700999ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001000 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -07001001{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001002 setObjectName(name);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001003 setOpenLinks(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001004
1005 if (!objectName().isEmpty()) {
1006 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001007 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001008 configSettings->endGroup();
1009 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1010 }
1011}
1012
1013void ConfigInfoView::saveSettings(void)
1014{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001015 if (!objectName().isEmpty()) {
1016 configSettings->beginGroup(objectName());
1017 configSettings->setValue("/showDebug", showDebug());
1018 configSettings->endGroup();
1019 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001020}
1021
1022void ConfigInfoView::setShowDebug(bool b)
1023{
1024 if (_showDebug != b) {
1025 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001026 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001027 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001028 else if (sym)
1029 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001030 emit showDebugChanged(b);
1031 }
1032}
1033
1034void ConfigInfoView::setInfo(struct menu *m)
1035{
Alexander Stein133c5f72010-08-31 17:34:37 +02001036 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001037 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001038 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001039 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001040 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001041 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001042 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001043 menuInfo();
1044}
1045
Roman Zippelab45d192006-06-08 22:12:47 -07001046void ConfigInfoView::symbolInfo(void)
1047{
1048 QString str;
1049
1050 str += "<big>Symbol: <b>";
1051 str += print_filter(sym->name);
1052 str += "</b></big><br><br>value: ";
1053 str += print_filter(sym_get_string_value(sym));
1054 str += "<br>visibility: ";
1055 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1056 str += "<br>";
1057 str += debug_info(sym);
1058
1059 setText(str);
1060}
1061
Roman Zippel43bf6122006-06-08 22:12:45 -07001062void ConfigInfoView::menuInfo(void)
1063{
1064 struct symbol* sym;
1065 QString head, debug, help;
1066
Alexander Stein133c5f72010-08-31 17:34:37 +02001067 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001068 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001069 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001070 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001071 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001072 head += "</b></big>";
1073 if (sym->name) {
1074 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001075 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001076 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001077 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001078 if (showDebug())
1079 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001080 head += ")";
1081 }
1082 } else if (sym->name) {
1083 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001084 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001085 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001086 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001087 if (showDebug())
1088 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001089 head += "</b></big>";
1090 }
1091 head += "<br><br>";
1092
1093 if (showDebug())
1094 debug = debug_info(sym);
1095
Cheng Renquand74c15f2009-07-12 16:11:47 +08001096 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001097 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001098 help = print_filter(str_get(&help_gstr));
1099 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001100 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001101 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001102 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001103 head += "</b></big><br><br>";
1104 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001105 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001106 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001107 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001108 debug += "<br><br>";
1109 }
1110 }
1111 }
1112 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001113 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001114
1115 setText(head + debug + help);
1116}
1117
1118QString ConfigInfoView::debug_info(struct symbol *sym)
1119{
1120 QString debug;
1121
1122 debug += "type: ";
1123 debug += print_filter(sym_type_name(sym->type));
1124 if (sym_is_choice(sym))
1125 debug += " (choice)";
1126 debug += "<br>";
1127 if (sym->rev_dep.expr) {
1128 debug += "reverse dep: ";
1129 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1130 debug += "<br>";
1131 }
1132 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1133 switch (prop->type) {
1134 case P_PROMPT:
1135 case P_MENU:
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001136 debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001137 debug += print_filter(prop->text);
Roman Zippelab45d192006-06-08 22:12:47 -07001138 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001139 break;
1140 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001141 case P_SELECT:
1142 case P_RANGE:
Mauro Carvalho Chehab8f8499a2020-06-30 08:48:53 +02001143 case P_COMMENT:
1144 case P_IMPLY:
1145 case P_SYMBOL:
Roman Zippel93449082008-01-14 04:50:54 +01001146 debug += prop_get_type_name(prop->type);
1147 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001148 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1149 debug += "<br>";
1150 break;
1151 case P_CHOICE:
1152 if (sym_is_choice(sym)) {
1153 debug += "choice: ";
1154 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1155 debug += "<br>";
1156 }
1157 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001158 default:
1159 debug += "unknown property: ";
1160 debug += prop_get_type_name(prop->type);
1161 debug += "<br>";
1162 }
1163 if (prop->visible.expr) {
1164 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1165 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1166 debug += "<br>";
1167 }
1168 }
1169 debug += "<br>";
1170
1171 return debug;
1172}
1173
1174QString ConfigInfoView::print_filter(const QString &str)
1175{
1176 QRegExp re("[<>&\"\\n]");
1177 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001178 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1179 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001180 case '<':
1181 res.replace(i, 1, "&lt;");
1182 i += 4;
1183 break;
1184 case '>':
1185 res.replace(i, 1, "&gt;");
1186 i += 4;
1187 break;
1188 case '&':
1189 res.replace(i, 1, "&amp;");
1190 i += 5;
1191 break;
1192 case '"':
1193 res.replace(i, 1, "&quot;");
1194 i += 6;
1195 break;
1196 case '\n':
1197 res.replace(i, 1, "<br>");
1198 i += 4;
1199 break;
1200 }
1201 }
1202 return res;
1203}
1204
Roman Zippelab45d192006-06-08 22:12:47 -07001205void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001206{
Roman Zippelab45d192006-06-08 22:12:47 -07001207 QString* text = reinterpret_cast<QString*>(data);
1208 QString str2 = print_filter(str);
1209
1210 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001211 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001212 *text += str2;
1213 *text += "</a>";
1214 } else
1215 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001216}
1217
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001218void ConfigInfoView::clicked(const QUrl &url)
1219{
1220 QByteArray str = url.toEncoded();
1221 const std::size_t count = str.size();
1222 char *data = new char[count + 1];
1223 struct symbol **result;
1224 struct menu *m = NULL;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001225
1226 if (count < 1) {
1227 qInfo() << "Clicked link is empty";
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001228 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001229 return;
1230 }
1231
1232 memcpy(data, str.constData(), count);
1233 data[count] = '\0';
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001234
1235 /* Seek for exact match */
1236 data[0] = '^';
1237 strcat(data, "$");
1238 result = sym_re_search(data);
1239 if (!result) {
1240 qInfo() << "Clicked symbol is invalid:" << data;
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001241 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001242 return;
1243 }
1244
1245 sym = *result;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001246
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001247 /* Seek for the menu which holds the symbol */
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001248 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1249 if (prop->type != P_PROMPT && prop->type != P_MENU)
1250 continue;
1251 m = prop->menu;
1252 break;
1253 }
1254
1255 if (!m) {
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001256 /* Symbol is not visible as a menu */
1257 symbolInfo();
1258 emit showDebugChanged(true);
1259 } else {
1260 emit menuSelected(m);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001261 }
1262
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001263 free(result);
1264 delete data;
1265}
1266
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001267QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001268{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001269 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001270 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001271
1272 action->setCheckable(true);
1273 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1274 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1275 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001276 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001277 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001278 return popup;
1279}
1280
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001281void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001282{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001283 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001284}
1285
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001286ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow *parent)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001287 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001288{
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001289 setObjectName("search");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001290 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001291
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001292 QVBoxLayout* layout1 = new QVBoxLayout(this);
1293 layout1->setContentsMargins(11, 11, 11, 11);
1294 layout1->setSpacing(6);
Masahiro Yamada92641152020-08-07 18:18:58 +09001295
1296 QHBoxLayout* layout2 = new QHBoxLayout();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001297 layout2->setContentsMargins(0, 0, 0, 0);
1298 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001299 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001300 editField = new QLineEdit(this);
1301 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1302 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001303 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001304 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001305 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1306 layout2->addWidget(searchButton);
1307 layout1->addLayout(layout2);
1308
Roman Zippel7fc925f2006-06-08 22:12:46 -07001309 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001310 split->setOrientation(Qt::Vertical);
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001311 list = new ConfigView(split, "search");
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001312 list->list->mode = listMode;
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001313 info = new ConfigInfoView(split, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001314 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1315 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001316 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1317 parent, SLOT(setMenuLink(struct menu *)));
1318
Roman Zippel43bf6122006-06-08 22:12:45 -07001319 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001320
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001321 QVariant x, y;
1322 int width, height;
1323 bool ok;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001324
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001325 configSettings->beginGroup("search");
1326 width = configSettings->value("/window width", parent->width() / 2).toInt();
1327 height = configSettings->value("/window height", parent->height() / 2).toInt();
1328 resize(width, height);
1329 x = configSettings->value("/window x");
1330 y = configSettings->value("/window y");
1331 if (x.isValid() && y.isValid())
1332 move(x.toInt(), y.toInt());
1333 QList<int> sizes = configSettings->readSizes("/split", &ok);
1334 if (ok)
1335 split->setSizes(sizes);
1336 configSettings->endGroup();
1337 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
Roman Zippel7fc925f2006-06-08 22:12:46 -07001338}
1339
1340void ConfigSearchWindow::saveSettings(void)
1341{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001342 if (!objectName().isEmpty()) {
1343 configSettings->beginGroup(objectName());
1344 configSettings->setValue("/window x", pos().x());
1345 configSettings->setValue("/window y", pos().y());
1346 configSettings->setValue("/window width", size().width());
1347 configSettings->setValue("/window height", size().height());
1348 configSettings->writeSizes("/split", split->sizes());
1349 configSettings->endGroup();
1350 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001351}
1352
1353void ConfigSearchWindow::search(void)
1354{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001355 struct symbol **p;
1356 struct property *prop;
1357 ConfigItem *lastItem = NULL;
1358
1359 free(result);
1360 list->list->clear();
1361 info->clear();
1362
1363 result = sym_re_search(editField->text().toLatin1());
1364 if (!result)
1365 return;
1366 for (p = result; *p; p++) {
1367 for_all_prompts((*p), prop)
1368 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1369 menu_is_visible(prop->menu));
1370 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001371}
1372
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373/*
1374 * Construct the complete config widget
1375 */
1376ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001377 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Boris Barbulovski92119932015-09-22 11:36:16 -07001379 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001380 QVariant x, y;
1381 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001382 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001384 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001385 snprintf(title, sizeof(title), "%s%s",
1386 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001387 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001388 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001389 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001391 width = configSettings->value("/window width", d->width() - 64).toInt();
1392 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001394 x = configSettings->value("/window x");
1395 y = configSettings->value("/window y");
1396 if ((x.isValid())&&(y.isValid()))
1397 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001399 QWidget *widget = new QWidget(this);
1400 QVBoxLayout *layout = new QVBoxLayout(widget);
1401 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001403 split1 = new QSplitter(widget);
1404 split1->setOrientation(Qt::Horizontal);
1405 split1->setChildrenCollapsible(false);
1406
1407 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 menuList = menuView->list;
1409
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001410 split2 = new QSplitter(widget);
1411 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001412 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
1414 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001415 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 configList = configView->list;
1417
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001418 helpText = new ConfigInfoView(widget, "help");
1419
1420 layout->addWidget(split2);
1421 split2->addWidget(split1);
1422 split1->addWidget(configView);
1423 split1->addWidget(menuView);
1424 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
1426 setTabOrder(configList, helpText);
1427 configList->setFocus();
1428
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001429 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001430 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1431
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001432 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001433 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001434 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1435
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001436 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001437 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001438 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1439
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001440 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001441 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001442 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1443
Karsten Wiese3b354c52006-12-13 00:34:08 -08001444 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001445
Karsten Wiese3b354c52006-12-13 00:34:08 -08001446 // Set saveAction's initial state
1447 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001448 configname = xstrdup(conf_get_configname());
1449
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001450 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001451 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001452 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001453 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001454 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001455 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001456 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001457 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001458 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001459 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001460 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001461 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001462 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001463 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001465 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001466 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001467 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001468 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001469 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001470 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001471 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001472 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001473 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001474 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001475
1476 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001477 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001478 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001479 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001480 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001481 SLOT(setOptionMode(QAction *)));
1482
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001483 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1484 configView->showAllAction = new QAction("Show All Options", optGroup);
1485 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001486 configView->showNormalAction->setCheckable(true);
1487 configView->showAllAction->setCheckable(true);
1488 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001489
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001490 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001491 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001492 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001493 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001495 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001496 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001497 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001498 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
1500 // init tool bar
Masahiro Yamada860ec3f2020-08-07 18:18:55 +09001501 QToolBar *toolBar = addToolBar("Tools");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001502 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001504 toolBar->addAction(loadAction);
1505 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001507 toolBar->addAction(singleViewAction);
1508 toolBar->addAction(splitViewAction);
1509 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001511 // create file menu
1512 QMenu *menu = menuBar()->addMenu("&File");
1513 menu->addAction(loadAction);
1514 menu->addAction(saveAction);
1515 menu->addAction(saveAsAction);
1516 menu->addSeparator();
1517 menu->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Shlomi Fish66e7c722007-02-14 00:32:58 -08001519 // create edit menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001520 menu = menuBar()->addMenu("&Edit");
1521 menu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 // create options menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001524 menu = menuBar()->addMenu("&Option");
1525 menu->addAction(showNameAction);
1526 menu->addAction(showRangeAction);
1527 menu->addAction(showDataAction);
1528 menu->addSeparator();
1529 menu->addActions(optGroup->actions());
1530 menu->addSeparator();
1531 menu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
1533 // create help menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001534 menu = menuBar()->addMenu("&Help");
1535 menu->addAction(showIntroAction);
1536 menu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001538 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1539 helpText, SLOT (clicked (const QUrl &)) );
1540
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001541 connect(configList, SIGNAL(menuChanged(struct menu *)),
1542 helpText, SLOT(setInfo(struct menu *)));
1543 connect(configList, SIGNAL(menuSelected(struct menu *)),
1544 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001545 connect(configList, SIGNAL(itemSelected(struct menu *)),
1546 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001547 connect(configList, SIGNAL(parentSelected()),
1548 SLOT(goBack()));
1549 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1550 helpText, SLOT(setInfo(struct menu *)));
1551 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1552 SLOT(changeMenu(struct menu *)));
1553
1554 connect(configList, SIGNAL(gotFocus(struct menu *)),
1555 helpText, SLOT(setInfo(struct menu *)));
1556 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1557 helpText, SLOT(setInfo(struct menu *)));
1558 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1559 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001560 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1561 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001563 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 if (listMode == "single")
1565 showSingleView();
1566 else if (listMode == "full")
1567 showFullView();
1568 else /*if (listMode == "split")*/
1569 showSplitView();
1570
1571 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001572 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 if (ok)
1574 split1->setSizes(sizes);
1575
Roman Zippel7fc925f2006-06-08 22:12:46 -07001576 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 if (ok)
1578 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579}
1580
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581void ConfigMainWindow::loadConfig(void)
1582{
Masahiro Yamada87419082019-03-11 01:13:15 +09001583 QString str;
1584 QByteArray ba;
1585 const char *name;
1586
1587 str = QFileDialog::getOpenFileName(this, "", configname);
1588 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001590
1591 ba = str.toLocal8Bit();
1592 name = ba.data();
1593
1594 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001595 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001596
1597 free(configname);
1598 configname = xstrdup(name);
1599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 ConfigView::updateListAll();
1601}
1602
Michal Marekbac6aa82011-05-25 15:10:25 +02001603bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604{
Masahiro Yamada87419082019-03-11 01:13:15 +09001605 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001606 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001607 return false;
1608 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001609 conf_write_autoconf(0);
1610
Michal Marekbac6aa82011-05-25 15:10:25 +02001611 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
1614void ConfigMainWindow::saveConfigAs(void)
1615{
Masahiro Yamada87419082019-03-11 01:13:15 +09001616 QString str;
1617 QByteArray ba;
1618 const char *name;
1619
1620 str = QFileDialog::getSaveFileName(this, "", configname);
1621 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001623
1624 ba = str.toLocal8Bit();
1625 name = ba.data();
1626
1627 if (conf_write(name)) {
1628 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1629 }
1630 conf_write_autoconf(0);
1631
1632 free(configname);
1633 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
Roman Zippel43bf6122006-06-08 22:12:45 -07001636void ConfigMainWindow::searchConfig(void)
1637{
1638 if (!searchWindow)
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001639 searchWindow = new ConfigSearchWindow(this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001640 searchWindow->show();
1641}
1642
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001643void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001645 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646}
1647
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001648void ConfigMainWindow::changeMenu(struct menu *menu)
1649{
1650 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001651}
1652
Roman Zippelb65a47e2006-06-08 22:12:47 -07001653void ConfigMainWindow::setMenuLink(struct menu *menu)
1654{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001655 struct menu *parent;
1656 ConfigList* list = NULL;
1657 ConfigItem* item;
1658
1659 if (configList->menuSkip(menu))
1660 return;
1661
1662 switch (configList->mode) {
1663 case singleMode:
1664 list = configList;
1665 parent = menu_get_parent_menu(menu);
1666 if (!parent)
1667 return;
1668 list->setRootMenu(parent);
1669 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001670 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001671 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001672 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001673 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001674 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001675 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001676 parent = menu_get_parent_menu(menu->parent);
1677 if (!parent)
1678 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001679
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001680 /* Select the config view */
1681 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001682 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001683 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001684 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001685 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001686
1687 menuList->setRootMenu(parent);
1688 menuList->clearSelection();
1689 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001690 }
1691 break;
1692 case fullMode:
1693 list = configList;
1694 break;
1695 default:
1696 break;
1697 }
1698
1699 if (list) {
1700 item = list->findConfigItem(menu);
1701 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001702 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001703 list->scrollToItem(item);
1704 list->setFocus();
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001705 helpText->setInfo(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001706 }
1707 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001708}
1709
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710void ConfigMainWindow::listFocusChanged(void)
1711{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001712 if (menuList->mode == menuMode)
1713 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
1715
1716void ConfigMainWindow::goBack(void)
1717{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001718 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001719 return;
1720
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001721 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
1724void ConfigMainWindow::showSingleView(void)
1725{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001726 singleViewAction->setEnabled(false);
1727 singleViewAction->setChecked(true);
1728 splitViewAction->setEnabled(true);
1729 splitViewAction->setChecked(false);
1730 fullViewAction->setEnabled(true);
1731 fullViewAction->setChecked(false);
1732
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001733 backAction->setEnabled(true);
1734
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001736 menuList->setRootMenu(0);
1737 configList->mode = singleMode;
1738 if (configList->rootEntry == &rootmenu)
1739 configList->updateListAll();
1740 else
1741 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 configList->setFocus();
1743}
1744
1745void ConfigMainWindow::showSplitView(void)
1746{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001747 singleViewAction->setEnabled(true);
1748 singleViewAction->setChecked(false);
1749 splitViewAction->setEnabled(false);
1750 splitViewAction->setChecked(true);
1751 fullViewAction->setEnabled(true);
1752 fullViewAction->setChecked(false);
1753
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001754 backAction->setEnabled(false);
1755
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001756 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001757 if (configList->rootEntry == &rootmenu)
1758 configList->updateListAll();
1759 else
1760 configList->setRootMenu(&rootmenu);
1761 configList->setAllOpen(true);
1762 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001763 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001764 menuList->setRootMenu(&rootmenu);
1765 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 menuView->show();
1767 menuList->setFocus();
1768}
1769
1770void ConfigMainWindow::showFullView(void)
1771{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001772 singleViewAction->setEnabled(true);
1773 singleViewAction->setChecked(false);
1774 splitViewAction->setEnabled(true);
1775 splitViewAction->setChecked(false);
1776 fullViewAction->setEnabled(false);
1777 fullViewAction->setChecked(true);
1778
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001779 backAction->setEnabled(false);
1780
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001782 menuList->setRootMenu(0);
1783 configList->mode = fullMode;
1784 if (configList->rootEntry == &rootmenu)
1785 configList->updateListAll();
1786 else
1787 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 configList->setFocus();
1789}
1790
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791/*
1792 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 */
1794void ConfigMainWindow::closeEvent(QCloseEvent* e)
1795{
Karsten Wieseb3214292006-12-13 00:34:06 -08001796 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 e->accept();
1798 return;
1799 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001800 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001802 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1803 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1804 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 switch (mb.exec()) {
1806 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001807 if (saveConfig())
1808 e->accept();
1809 else
1810 e->ignore();
1811 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 case QMessageBox::No:
1813 e->accept();
1814 break;
1815 case QMessageBox::Cancel:
1816 e->ignore();
1817 break;
1818 }
1819}
1820
1821void ConfigMainWindow::showIntro(void)
1822{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001823 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 "For each option, a blank box indicates the feature is disabled, a check\n"
1825 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1826 "as a module. Clicking on the box will cycle through the three states.\n\n"
1827 "If you do not see an option (e.g., a device driver) that you believe\n"
1828 "should be present, try turning on Show All Options under the Options menu.\n"
1829 "Although there is no cross reference yet to help you figure out what other\n"
1830 "options must be enabled to support the option you are interested in, you can\n"
1831 "still view the help of a grayed-out option.\n\n"
1832 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001833 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
1835 QMessageBox::information(this, "qconf", str);
1836}
1837
1838void ConfigMainWindow::showAbout(void)
1839{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001840 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001841 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001842 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
1844 QMessageBox::information(this, "qconf", str);
1845}
1846
1847void ConfigMainWindow::saveSettings(void)
1848{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001849 configSettings->setValue("/window x", pos().x());
1850 configSettings->setValue("/window y", pos().y());
1851 configSettings->setValue("/window width", size().width());
1852 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
1854 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001855 switch(configList->mode) {
1856 case singleMode :
1857 entry = "single";
1858 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001860 case symbolMode :
1861 entry = "split";
1862 break;
1863
1864 case fullMode :
1865 entry = "full";
1866 break;
1867
1868 default:
1869 break;
1870 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001871 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Roman Zippel7fc925f2006-06-08 22:12:46 -07001873 configSettings->writeSizes("/split1", split1->sizes());
1874 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875}
1876
Karsten Wiese3b354c52006-12-13 00:34:08 -08001877void ConfigMainWindow::conf_changed(void)
1878{
1879 if (saveAction)
1880 saveAction->setEnabled(conf_get_changed());
1881}
1882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883void fixup_rootmenu(struct menu *menu)
1884{
1885 struct menu *child;
1886 static int menu_cnt = 0;
1887
1888 menu->flags |= MENU_ROOT;
1889 for (child = menu->list; child; child = child->next) {
1890 if (child->prompt && child->prompt->type == P_MENU) {
1891 menu_cnt++;
1892 fixup_rootmenu(child);
1893 menu_cnt--;
1894 } else if (!menu_cnt)
1895 fixup_rootmenu(child);
1896 }
1897}
1898
1899static const char *progname;
1900
1901static void usage(void)
1902{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001903 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 exit(0);
1905}
1906
1907int main(int ac, char** av)
1908{
1909 ConfigMainWindow* v;
1910 const char *name;
1911
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 progname = av[0];
1913 configApp = new QApplication(ac, av);
1914 if (ac > 1 && av[1][0] == '-') {
1915 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001916 case 's':
1917 conf_set_message_callback(NULL);
1918 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 case 'h':
1920 case '?':
1921 usage();
1922 }
1923 name = av[2];
1924 } else
1925 name = av[1];
1926 if (!name)
1927 usage();
1928
1929 conf_parse(name);
1930 fixup_rootmenu(&rootmenu);
1931 conf_read(NULL);
1932 //zconfdump(stdout);
1933
Roman Zippel7fc925f2006-06-08 22:12:46 -07001934 configSettings = new ConfigSettings();
1935 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 v = new ConfigMainWindow();
1937
1938 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1940 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001941 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 configApp->exec();
1943
Roman Zippel7fc925f2006-06-08 22:12:46 -07001944 configSettings->endGroup();
1945 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001946 delete v;
1947 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001948
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 return 0;
1950}