blob: bf6c9187daf5e328824c804d4b1d3549db5b5fd3 [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
Masahiro Yamada5cb255f2020-08-07 18:19:07 +090077QIcon ConfigItem::symbolYesIcon;
78QIcon ConfigItem::symbolModIcon;
79QIcon ConfigItem::symbolNoIcon;
80QIcon ConfigItem::choiceYesIcon;
81QIcon ConfigItem::choiceNoIcon;
82QIcon ConfigItem::menuIcon;
83QIcon ConfigItem::menubackIcon;
Boris Barbulovski59e56442015-09-22 11:36:18 -070084
85/*
Boris Barbulovski59e56442015-09-22 11:36:18 -070086 * update the displayed of a menu entry
87 */
88void ConfigItem::updateMenu(void)
89{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070090 ConfigList* list;
91 struct symbol* sym;
92 struct property *prop;
93 QString prompt;
94 int type;
95 tristate expr;
96
97 list = listView();
98 if (goParent) {
Masahiro Yamada5cb255f2020-08-07 18:19:07 +090099 setIcon(promptColIdx, menubackIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700100 prompt = "..";
101 goto set_prompt;
102 }
103
104 sym = menu->sym;
105 prop = menu->prompt;
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900106 prompt = menu_get_prompt(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700107
108 if (prop) switch (prop->type) {
109 case P_MENU:
110 if (list->mode == singleMode || list->mode == symbolMode) {
111 /* a menuconfig entry is displayed differently
112 * depending whether it's at the view root or a child.
113 */
114 if (sym && list->rootEntry == menu)
115 break;
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900116 setIcon(promptColIdx, menuIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700117 } else {
118 if (sym)
119 break;
Masahiro Yamada711b8752020-08-07 18:19:03 +0900120 setIcon(promptColIdx, QIcon());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700121 }
122 goto set_prompt;
123 case P_COMMENT:
Masahiro Yamada711b8752020-08-07 18:19:03 +0900124 setIcon(promptColIdx, QIcon());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700125 goto set_prompt;
126 default:
127 ;
128 }
129 if (!sym)
130 goto set_prompt;
131
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900132 setText(nameColIdx, sym->name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700133
134 type = sym_get_type(sym);
135 switch (type) {
136 case S_BOOLEAN:
137 case S_TRISTATE:
138 char ch;
139
Marco Ammonbaa23ec2019-07-04 12:50:41 +0200140 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
Masahiro Yamada711b8752020-08-07 18:19:03 +0900141 setIcon(promptColIdx, QIcon());
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200142 setText(noColIdx, QString());
143 setText(modColIdx, QString());
144 setText(yesColIdx, QString());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700145 break;
146 }
147 expr = sym_get_tristate_value(sym);
148 switch (expr) {
149 case yes:
150 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900151 setIcon(promptColIdx, choiceYesIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700152 else
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900153 setIcon(promptColIdx, symbolYesIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700154 setText(yesColIdx, "Y");
155 ch = 'Y';
156 break;
157 case mod:
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900158 setIcon(promptColIdx, symbolModIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700159 setText(modColIdx, "M");
160 ch = 'M';
161 break;
162 default:
163 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900164 setIcon(promptColIdx, choiceNoIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700165 else
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900166 setIcon(promptColIdx, symbolNoIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700167 setText(noColIdx, "N");
168 ch = 'N';
169 break;
170 }
171 if (expr != no)
172 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
173 if (expr != mod)
174 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
175 if (expr != yes)
176 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
177
178 setText(dataColIdx, QChar(ch));
179 break;
180 case S_INT:
181 case S_HEX:
182 case S_STRING:
183 const char* data;
184
185 data = sym_get_string_value(sym);
186
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700187 setText(dataColIdx, data);
188 if (type == S_STRING)
189 prompt = QString("%1: %2").arg(prompt).arg(data);
190 else
191 prompt = QString("(%2) %1").arg(prompt).arg(data);
192 break;
193 }
194 if (!sym_has_value(sym) && visible)
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200195 prompt += " (NEW)";
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700196set_prompt:
197 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700198}
199
200void ConfigItem::testUpdateMenu(bool v)
201{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700202 ConfigItem* i;
203
204 visible = v;
205 if (!menu)
206 return;
207
208 sym_calc_value(menu->sym);
209 if (menu->flags & MENU_CHANGED) {
210 /* the menu entry changed, so update all list items */
211 menu->flags &= ~MENU_CHANGED;
212 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
213 i->updateMenu();
214 } else if (listView()->updateAll)
215 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700216}
217
218
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700219/*
220 * construct a menu entry
221 */
222void ConfigItem::init(void)
223{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700224 if (menu) {
225 ConfigList* list = listView();
226 nextItem = (ConfigItem*)menu->data;
227 menu->data = this;
228
229 if (list->mode != fullMode)
230 setExpanded(true);
231 sym_calc_value(menu->sym);
232 }
233 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700234}
235
236/*
237 * destruct a menu entry
238 */
239ConfigItem::~ConfigItem(void)
240{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700241 if (menu) {
242 ConfigItem** ip = (ConfigItem**)&menu->data;
243 for (; *ip; ip = &(*ip)->nextItem) {
244 if (*ip == this) {
245 *ip = nextItem;
246 break;
247 }
248 }
249 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700250}
251
Roman Zippel43bf6122006-06-08 22:12:45 -0700252ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
253 : Parent(parent)
254{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700255 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700256}
257
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700258void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700261 if (sym_get_string_value(item->menu->sym))
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900262 setText(sym_get_string_value(item->menu->sym));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700263 else
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200264 setText(QString());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 Parent::show();
266 setFocus();
267}
268
269void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
270{
271 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200272 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200274 case Qt::Key_Return:
275 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700276 sym_set_string_value(item->menu->sym, text().toLatin1());
Masahiro Yamada10316852020-08-07 18:19:00 +0900277 parent()->updateList();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 break;
279 default:
280 Parent::keyPressEvent(e);
281 return;
282 }
283 e->accept();
284 parent()->list->setFocus();
285 hide();
286}
287
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700288ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700289 : Parent(p),
290 updateAll(false),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700291 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700292 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700293{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700294 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700295 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700296 setRootIsDecorated(true);
297
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700298 setVerticalScrollMode(ScrollPerPixel);
299 setHorizontalScrollMode(ScrollPerPixel);
300
Masahiro Yamada97bebbc2020-07-30 02:46:17 +0900301 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700302
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700303 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700304 SLOT(updateSelection(void)));
305
306 if (name) {
307 configSettings->beginGroup(name);
308 showName = configSettings->value("/showName", false).toBool();
309 showRange = configSettings->value("/showRange", false).toBool();
310 showData = configSettings->value("/showData", false).toBool();
311 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
312 configSettings->endGroup();
313 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
314 }
315
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900316 showColumn(promptColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700317
318 reinit();
319}
320
321bool ConfigList::menuSkip(struct menu *menu)
322{
323 if (optMode == normalOpt && menu_is_visible(menu))
324 return false;
325 if (optMode == promptOpt && menu_has_prompt(menu))
326 return false;
327 if (optMode == allOpt)
328 return false;
329 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700330}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700331
332void ConfigList::reinit(void)
333{
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900334 hideColumn(dataColIdx);
335 hideColumn(yesColIdx);
336 hideColumn(modColIdx);
337 hideColumn(noColIdx);
338 hideColumn(nameColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700339
340 if (showName)
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900341 showColumn(nameColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700342 if (showRange) {
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900343 showColumn(noColIdx);
344 showColumn(modColIdx);
345 showColumn(yesColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700346 }
347 if (showData)
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900348 showColumn(dataColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700349
350 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700351}
352
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +0900353void ConfigList::setOptionMode(QAction *action)
354{
355 if (action == showNormalAction)
356 optMode = normalOpt;
357 else if (action == showAllAction)
358 optMode = allOpt;
359 else
360 optMode = promptOpt;
361
362 updateListAll();
363}
364
Boris Barbulovski59e56442015-09-22 11:36:18 -0700365void ConfigList::saveSettings(void)
366{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700367 if (!objectName().isEmpty()) {
368 configSettings->beginGroup(objectName());
369 configSettings->setValue("/showName", showName);
370 configSettings->setValue("/showRange", showRange);
371 configSettings->setValue("/showData", showData);
372 configSettings->setValue("/optionMode", (int)optMode);
373 configSettings->endGroup();
374 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700375}
376
377ConfigItem* ConfigList::findConfigItem(struct menu *menu)
378{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700379 ConfigItem* item = (ConfigItem*)menu->data;
380
381 for (; item; item = item->nextItem) {
382 if (this == item->listView())
383 break;
384 }
385
386 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700387}
388
389void ConfigList::updateSelection(void)
390{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700391 struct menu *menu;
392 enum prop_type type;
393
Boris Barbulovskibe596aa2015-09-22 11:36:28 -0700394 if (selectedItems().count() == 0)
395 return;
396
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700397 ConfigItem* item = (ConfigItem*)selectedItems().first();
398 if (!item)
399 return;
400
401 menu = item->menu;
402 emit menuChanged(menu);
403 if (!menu)
404 return;
405 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
406 if (mode == menuMode && type == P_MENU)
407 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700408}
409
Masahiro Yamadacb770432020-08-07 18:18:59 +0900410void ConfigList::updateList()
Boris Barbulovski59e56442015-09-22 11:36:18 -0700411{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700412 ConfigItem* last = 0;
Masahiro Yamadacb770432020-08-07 18:18:59 +0900413 ConfigItem *item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700414
415 if (!rootEntry) {
416 if (mode != listMode)
417 goto update;
418 QTreeWidgetItemIterator it(this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700419
420 while (*it) {
421 item = (ConfigItem*)(*it);
422 if (!item->menu)
423 continue;
424 item->testUpdateMenu(menu_is_visible(item->menu));
425
426 ++it;
427 }
428 return;
429 }
430
431 if (rootEntry != &rootmenu && (mode == singleMode ||
432 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
Boris Barbulovskiee7298f2015-09-22 11:36:37 -0700433 item = (ConfigItem *)topLevelItem(0);
Masahiro Yamada4b20e102020-08-01 16:08:49 +0900434 if (!item)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700435 item = new ConfigItem(this, 0, true);
Masahiro Yamada4b20e102020-08-01 16:08:49 +0900436 last = item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700437 }
438 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
439 rootEntry->sym && rootEntry->prompt) {
Masahiro Yamadaccf56e52020-08-01 16:08:50 +0900440 item = last ? last->nextSibling() : nullptr;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700441 if (!item)
442 item = new ConfigItem(this, last, rootEntry, true);
443 else
444 item->testUpdateMenu(true);
445
446 updateMenuList(item, rootEntry);
447 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700448 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700449 return;
450 }
451update:
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900452 updateMenuList(rootEntry);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700453 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700454 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700455}
456
457void ConfigList::setValue(ConfigItem* item, tristate val)
458{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700459 struct symbol* sym;
460 int type;
461 tristate oldval;
462
463 sym = item->menu ? item->menu->sym : 0;
464 if (!sym)
465 return;
466
467 type = sym_get_type(sym);
468 switch (type) {
469 case S_BOOLEAN:
470 case S_TRISTATE:
471 oldval = sym_get_tristate_value(sym);
472
473 if (!sym_set_tristate_value(sym, val))
474 return;
475 if (oldval == no && item->menu->list)
476 item->setExpanded(true);
Masahiro Yamada10316852020-08-07 18:19:00 +0900477 parent()->updateList();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700478 break;
479 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700480}
481
482void ConfigList::changeValue(ConfigItem* item)
483{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700484 struct symbol* sym;
485 struct menu* menu;
486 int type, oldexpr, newexpr;
487
488 menu = item->menu;
489 if (!menu)
490 return;
491 sym = menu->sym;
492 if (!sym) {
493 if (item->menu->list)
494 item->setExpanded(!item->isExpanded());
495 return;
496 }
497
498 type = sym_get_type(sym);
499 switch (type) {
500 case S_BOOLEAN:
501 case S_TRISTATE:
502 oldexpr = sym_get_tristate_value(sym);
503 newexpr = sym_toggle_tristate_value(sym);
504 if (item->menu->list) {
505 if (oldexpr == newexpr)
506 item->setExpanded(!item->isExpanded());
507 else if (oldexpr == no)
508 item->setExpanded(true);
509 }
510 if (oldexpr != newexpr)
Masahiro Yamada10316852020-08-07 18:19:00 +0900511 parent()->updateList();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700512 break;
513 case S_INT:
514 case S_HEX:
515 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700516 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700517 break;
518 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700519}
520
521void ConfigList::setRootMenu(struct menu *menu)
522{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700523 enum prop_type type;
524
525 if (rootEntry == menu)
526 return;
527 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
528 if (type != P_MENU)
529 return;
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900530 updateMenuList(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700531 rootEntry = menu;
532 updateListAll();
533 if (currentItem()) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200534 setSelected(currentItem(), hasFocus());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700535 scrollToItem(currentItem());
536 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700537}
538
539void ConfigList::setParentMenu(void)
540{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700541 ConfigItem* item;
542 struct menu *oldroot;
543
544 oldroot = rootEntry;
545 if (rootEntry == &rootmenu)
546 return;
547 setRootMenu(menu_get_parent_menu(rootEntry->parent));
548
549 QTreeWidgetItemIterator it(this);
550 while (*it) {
551 item = (ConfigItem *)(*it);
552 if (item->menu == oldroot) {
553 setCurrentItem(item);
554 scrollToItem(item);
555 break;
556 }
557
558 ++it;
559 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700560}
561
562/*
563 * update all the children of a menu entry
564 * removes/adds the entries from the parent widget as necessary
565 *
566 * parent: either the menu list widget or a menu entry widget
567 * menu: entry to be updated
568 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700569void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700570{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700571 struct menu* child;
572 ConfigItem* item;
573 ConfigItem* last;
574 bool visible;
575 enum prop_type type;
576
577 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700578 while (parent->childCount() > 0)
579 {
580 delete parent->takeChild(0);
581 }
582
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700583 return;
584 }
585
586 last = parent->firstChild();
587 if (last && !last->goParent)
588 last = 0;
589 for (child = menu->list; child; child = child->next) {
590 item = last ? last->nextSibling() : parent->firstChild();
591 type = child->prompt ? child->prompt->type : P_UNKNOWN;
592
593 switch (mode) {
594 case menuMode:
595 if (!(child->flags & MENU_ROOT))
596 goto hide;
597 break;
598 case symbolMode:
599 if (child->flags & MENU_ROOT)
600 goto hide;
601 break;
602 default:
603 break;
604 }
605
606 visible = menu_is_visible(child);
607 if (!menuSkip(child)) {
608 if (!child->sym && !child->list && !child->prompt)
609 continue;
610 if (!item || item->menu != child)
611 item = new ConfigItem(parent, last, child, visible);
612 else
613 item->testUpdateMenu(visible);
614
615 if (mode == fullMode || mode == menuMode || type != P_MENU)
616 updateMenuList(item, child);
617 else
618 updateMenuList(item, 0);
619 last = item;
620 continue;
621 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200622hide:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700623 if (item && item->menu == child) {
624 last = parent->firstChild();
625 if (last == item)
626 last = 0;
627 else while (last->nextSibling() != item)
628 last = last->nextSibling();
629 delete item;
630 }
631 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700632}
633
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900634void ConfigList::updateMenuList(struct menu *menu)
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700635{
636 struct menu* child;
637 ConfigItem* item;
638 ConfigItem* last;
639 bool visible;
640 enum prop_type type;
641
642 if (!menu) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900643 while (topLevelItemCount() > 0)
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700644 {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900645 delete takeTopLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700646 }
647
648 return;
649 }
650
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900651 last = (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700652 if (last && !last->goParent)
653 last = 0;
654 for (child = menu->list; child; child = child->next) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900655 item = last ? last->nextSibling() : (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700656 type = child->prompt ? child->prompt->type : P_UNKNOWN;
657
658 switch (mode) {
659 case menuMode:
660 if (!(child->flags & MENU_ROOT))
661 goto hide;
662 break;
663 case symbolMode:
664 if (child->flags & MENU_ROOT)
665 goto hide;
666 break;
667 default:
668 break;
669 }
670
671 visible = menu_is_visible(child);
672 if (!menuSkip(child)) {
673 if (!child->sym && !child->list && !child->prompt)
674 continue;
675 if (!item || item->menu != child)
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900676 item = new ConfigItem(this, last, child, visible);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700677 else
678 item->testUpdateMenu(visible);
679
680 if (mode == fullMode || mode == menuMode || type != P_MENU)
681 updateMenuList(item, child);
682 else
683 updateMenuList(item, 0);
684 last = item;
685 continue;
686 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200687hide:
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700688 if (item && item->menu == child) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900689 last = (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700690 if (last == item)
691 last = 0;
692 else while (last->nextSibling() != item)
693 last = last->nextSibling();
694 delete item;
695 }
696 }
697}
698
Boris Barbulovski59e56442015-09-22 11:36:18 -0700699void ConfigList::keyPressEvent(QKeyEvent* ev)
700{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700701 QTreeWidgetItem* i = currentItem();
702 ConfigItem* item;
703 struct menu *menu;
704 enum prop_type type;
705
706 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
707 emit parentSelected();
708 ev->accept();
709 return;
710 }
711
712 if (!i) {
713 Parent::keyPressEvent(ev);
714 return;
715 }
716 item = (ConfigItem*)i;
717
718 switch (ev->key()) {
719 case Qt::Key_Return:
720 case Qt::Key_Enter:
721 if (item->goParent) {
722 emit parentSelected();
723 break;
724 }
725 menu = item->menu;
726 if (!menu)
727 break;
728 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
729 if (type == P_MENU && rootEntry != menu &&
730 mode != fullMode && mode != menuMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200731 if (mode == menuMode)
732 emit menuSelected(menu);
733 else
734 emit itemSelected(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700735 break;
736 }
737 case Qt::Key_Space:
738 changeValue(item);
739 break;
740 case Qt::Key_N:
741 setValue(item, no);
742 break;
743 case Qt::Key_M:
744 setValue(item, mod);
745 break;
746 case Qt::Key_Y:
747 setValue(item, yes);
748 break;
749 default:
750 Parent::keyPressEvent(ev);
751 return;
752 }
753 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700754}
755
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700756void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700757{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700758 //QPoint p(contentsToViewport(e->pos()));
759 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
760 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700761}
762
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700763void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700764{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700765 QPoint p = e->pos();
766 ConfigItem* item = (ConfigItem*)itemAt(p);
767 struct menu *menu;
768 enum prop_type ptype;
769 QIcon icon;
770 int idx, x;
771
772 if (!item)
773 goto skip;
774
775 menu = item->menu;
776 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700777 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700778 switch (idx) {
779 case promptColIdx:
Masahiro Yamada711b8752020-08-07 18:19:03 +0900780 icon = item->icon(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700781 if (!icon.isNull()) {
782 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
783 if (x >= off && x < off + icon.availableSizes().first().width()) {
784 if (item->goParent) {
785 emit parentSelected();
786 break;
787 } else if (!menu)
788 break;
789 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
790 if (ptype == P_MENU && rootEntry != menu &&
Maxime Chretien7eb7c106f2020-07-08 15:32:15 +0200791 mode != fullMode && mode != menuMode &&
792 mode != listMode)
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700793 emit menuSelected(menu);
794 else
795 changeValue(item);
796 }
797 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700798 break;
799 case noColIdx:
800 setValue(item, no);
801 break;
802 case modColIdx:
803 setValue(item, mod);
804 break;
805 case yesColIdx:
806 setValue(item, yes);
807 break;
808 case dataColIdx:
809 changeValue(item);
810 break;
811 }
812
813skip:
814 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
815 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700816}
817
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700818void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700819{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700820 //QPoint p(contentsToViewport(e->pos()));
821 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
822 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700823}
824
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700825void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700826{
Mauro Carvalho Chehabe1f77692020-04-02 11:28:02 +0200827 QPoint p = e->pos();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700828 ConfigItem* item = (ConfigItem*)itemAt(p);
829 struct menu *menu;
830 enum prop_type ptype;
831
832 if (!item)
833 goto skip;
834 if (item->goParent) {
835 emit parentSelected();
836 goto skip;
837 }
838 menu = item->menu;
839 if (!menu)
840 goto skip;
841 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
Maxime Chretien7eb7c106f2020-07-08 15:32:15 +0200842 if (ptype == P_MENU && mode != listMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200843 if (mode == singleMode)
844 emit itemSelected(menu);
845 else if (mode == symbolMode)
846 emit menuSelected(menu);
847 } else if (menu->sym)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700848 changeValue(item);
849
850skip:
851 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
852 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700853}
854
855void ConfigList::focusInEvent(QFocusEvent *e)
856{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700857 struct menu *menu = NULL;
858
859 Parent::focusInEvent(e);
860
861 ConfigItem* item = (ConfigItem *)currentItem();
862 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200863 setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700864 menu = item->menu;
865 }
866 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700867}
868
869void ConfigList::contextMenuEvent(QContextMenuEvent *e)
870{
Masahiro Yamadafa8de0a2020-08-07 18:19:08 +0900871 if (!headerPopup) {
872 QAction *action;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700873
Masahiro Yamadafa8de0a2020-08-07 18:19:08 +0900874 headerPopup = new QMenu(this);
875 action = new QAction("Show Name", this);
876 action->setCheckable(true);
877 connect(action, SIGNAL(toggled(bool)),
878 parent(), SLOT(setShowName(bool)));
879 connect(parent(), SIGNAL(showNameChanged(bool)),
Masahiro Yamadad85de332020-08-18 01:36:29 +0900880 action, SLOT(setChecked(bool)));
Masahiro Yamadafa8de0a2020-08-07 18:19:08 +0900881 action->setChecked(showName);
882 headerPopup->addAction(action);
883
884 action = new QAction("Show Range", this);
885 action->setCheckable(true);
886 connect(action, SIGNAL(toggled(bool)),
887 parent(), SLOT(setShowRange(bool)));
888 connect(parent(), SIGNAL(showRangeChanged(bool)),
Masahiro Yamadad85de332020-08-18 01:36:29 +0900889 action, SLOT(setChecked(bool)));
Masahiro Yamadafa8de0a2020-08-07 18:19:08 +0900890 action->setChecked(showRange);
891 headerPopup->addAction(action);
892
893 action = new QAction("Show Data", this);
894 action->setCheckable(true);
895 connect(action, SIGNAL(toggled(bool)),
896 parent(), SLOT(setShowData(bool)));
897 connect(parent(), SIGNAL(showDataChanged(bool)),
Masahiro Yamadad85de332020-08-18 01:36:29 +0900898 action, SLOT(setChecked(bool)));
Masahiro Yamadafa8de0a2020-08-07 18:19:08 +0900899 action->setChecked(showData);
900 headerPopup->addAction(action);
901 }
902
903 headerPopup->exec(e->globalPos());
904 e->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700905}
906
Li Zefan39a48972010-05-10 16:33:41 +0800907ConfigView*ConfigView::viewList;
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +0900908QAction *ConfigList::showNormalAction;
909QAction *ConfigList::showAllAction;
910QAction *ConfigList::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Roman Zippel7fc925f2006-06-08 22:12:46 -0700912ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700913 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700915 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700916 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700917 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700918
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700919 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700920 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 lineEdit = new ConfigLineEdit(this);
922 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700923 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925 this->nextView = viewList;
926 viewList = this;
927}
928
929ConfigView::~ConfigView(void)
930{
931 ConfigView** vp;
932
933 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
934 if (*vp == this) {
935 *vp = nextView;
936 break;
937 }
938 }
939}
940
Roman Zippel7fc925f2006-06-08 22:12:46 -0700941void ConfigView::setShowName(bool b)
942{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700943 if (list->showName != b) {
944 list->showName = b;
945 list->reinit();
946 emit showNameChanged(b);
947 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700948}
949
950void ConfigView::setShowRange(bool b)
951{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700952 if (list->showRange != b) {
953 list->showRange = b;
954 list->reinit();
955 emit showRangeChanged(b);
956 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700957}
958
959void ConfigView::setShowData(bool b)
960{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700961 if (list->showData != b) {
962 list->showData = b;
963 list->reinit();
964 emit showDataChanged(b);
965 }
966}
967
968void ConfigList::setAllOpen(bool open)
969{
970 QTreeWidgetItemIterator it(this);
971
972 while (*it) {
973 (*it)->setExpanded(open);
974
975 ++it;
976 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700977}
978
Masahiro Yamada10316852020-08-07 18:19:00 +0900979void ConfigView::updateList()
Roman Zippel7fc925f2006-06-08 22:12:46 -0700980{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700981 ConfigView* v;
982
983 for (v = viewList; v; v = v->nextView)
Masahiro Yamadacb770432020-08-07 18:18:59 +0900984 v->list->updateList();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
987void ConfigView::updateListAll(void)
988{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700989 ConfigView* v;
990
991 for (v = viewList; v; v = v->nextView)
992 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
Roman Zippel43bf6122006-06-08 22:12:45 -0700995ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700996 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700997{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700998 setObjectName(name);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +0200999 setOpenLinks(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001000
1001 if (!objectName().isEmpty()) {
1002 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001003 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001004 configSettings->endGroup();
1005 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1006 }
Masahiro Yamada7d1300e2020-08-18 01:36:30 +09001007
1008 contextMenu = createStandardContextMenu();
1009 QAction *action = new QAction("Show Debug Info", contextMenu);
1010
1011 action->setCheckable(true);
1012 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1013 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setChecked(bool)));
1014 action->setChecked(showDebug());
1015 contextMenu->addSeparator();
1016 contextMenu->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001017}
1018
1019void ConfigInfoView::saveSettings(void)
1020{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001021 if (!objectName().isEmpty()) {
1022 configSettings->beginGroup(objectName());
1023 configSettings->setValue("/showDebug", showDebug());
1024 configSettings->endGroup();
1025 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001026}
1027
1028void ConfigInfoView::setShowDebug(bool b)
1029{
1030 if (_showDebug != b) {
1031 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001032 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001033 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001034 else if (sym)
1035 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001036 emit showDebugChanged(b);
1037 }
1038}
1039
1040void ConfigInfoView::setInfo(struct menu *m)
1041{
Alexander Stein133c5f72010-08-31 17:34:37 +02001042 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001043 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001044 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001045 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001046 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001047 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001048 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001049 menuInfo();
1050}
1051
Roman Zippelab45d192006-06-08 22:12:47 -07001052void ConfigInfoView::symbolInfo(void)
1053{
1054 QString str;
1055
1056 str += "<big>Symbol: <b>";
1057 str += print_filter(sym->name);
1058 str += "</b></big><br><br>value: ";
1059 str += print_filter(sym_get_string_value(sym));
1060 str += "<br>visibility: ";
1061 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1062 str += "<br>";
1063 str += debug_info(sym);
1064
1065 setText(str);
1066}
1067
Roman Zippel43bf6122006-06-08 22:12:45 -07001068void ConfigInfoView::menuInfo(void)
1069{
1070 struct symbol* sym;
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001071 QString info;
1072 QTextStream stream(&info);
Roman Zippel43bf6122006-06-08 22:12:45 -07001073
Alexander Stein133c5f72010-08-31 17:34:37 +02001074 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001075 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001076 if (_menu->prompt) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001077 stream << "<big><b>";
1078 stream << print_filter(_menu->prompt->text);
1079 stream << "</b></big>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001080 if (sym->name) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001081 stream << " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001082 if (showDebug())
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001083 stream << "<a href=\"s" << sym->name << "\">";
1084 stream << print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001085 if (showDebug())
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001086 stream << "</a>";
1087 stream << ")";
Roman Zippel43bf6122006-06-08 22:12:45 -07001088 }
1089 } else if (sym->name) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001090 stream << "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001091 if (showDebug())
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001092 stream << "<a href=\"s" << sym->name << "\">";
1093 stream << print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001094 if (showDebug())
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001095 stream << "</a>";
1096 stream << "</b></big>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001097 }
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001098 stream << "<br><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001099
1100 if (showDebug())
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001101 stream << debug_info(sym);
1102
Masahiro Yamadaa46afd12020-09-14 23:59:48 +09001103 struct gstr help_gstr = str_new();
1104
1105 menu_get_ext_help(_menu, &help_gstr);
1106 stream << print_filter(str_get(&help_gstr));
1107 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001108 } else if (_menu->prompt) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001109 stream << "<big><b>";
1110 stream << print_filter(_menu->prompt->text);
1111 stream << "</b></big><br><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001112 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001113 if (_menu->prompt->visible.expr) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001114 stream << "&nbsp;&nbsp;dep: ";
1115 expr_print(_menu->prompt->visible.expr,
1116 expr_print_help, &stream, E_NONE);
1117 stream << "<br><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001118 }
Masahiro Yamadaa46afd12020-09-14 23:59:48 +09001119
1120 stream << "defined at " << _menu->file->name << ":"
1121 << _menu->lineno << "<br><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001122 }
1123 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001124
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001125 setText(info);
Roman Zippel43bf6122006-06-08 22:12:45 -07001126}
1127
1128QString ConfigInfoView::debug_info(struct symbol *sym)
1129{
1130 QString debug;
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001131 QTextStream stream(&debug);
Roman Zippel43bf6122006-06-08 22:12:45 -07001132
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001133 stream << "type: ";
1134 stream << print_filter(sym_type_name(sym->type));
Roman Zippel43bf6122006-06-08 22:12:45 -07001135 if (sym_is_choice(sym))
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001136 stream << " (choice)";
Roman Zippel43bf6122006-06-08 22:12:45 -07001137 debug += "<br>";
1138 if (sym->rev_dep.expr) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001139 stream << "reverse dep: ";
1140 expr_print(sym->rev_dep.expr, expr_print_help, &stream, E_NONE);
1141 stream << "<br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001142 }
1143 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1144 switch (prop->type) {
1145 case P_PROMPT:
1146 case P_MENU:
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001147 stream << "prompt: <a href=\"m" << sym->name << "\">";
1148 stream << print_filter(prop->text);
1149 stream << "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001150 break;
1151 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001152 case P_SELECT:
1153 case P_RANGE:
Mauro Carvalho Chehab8f8499a2020-06-30 08:48:53 +02001154 case P_COMMENT:
1155 case P_IMPLY:
1156 case P_SYMBOL:
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001157 stream << prop_get_type_name(prop->type);
1158 stream << ": ";
1159 expr_print(prop->expr, expr_print_help,
1160 &stream, E_NONE);
1161 stream << "<br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001162 break;
1163 case P_CHOICE:
1164 if (sym_is_choice(sym)) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001165 stream << "choice: ";
1166 expr_print(prop->expr, expr_print_help,
1167 &stream, E_NONE);
1168 stream << "<br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001169 }
1170 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001171 default:
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001172 stream << "unknown property: ";
1173 stream << prop_get_type_name(prop->type);
1174 stream << "<br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001175 }
1176 if (prop->visible.expr) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001177 stream << "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1178 expr_print(prop->visible.expr, expr_print_help,
1179 &stream, E_NONE);
1180 stream << "<br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001181 }
1182 }
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001183 stream << "<br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001184
1185 return debug;
1186}
1187
1188QString ConfigInfoView::print_filter(const QString &str)
1189{
1190 QRegExp re("[<>&\"\\n]");
1191 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001192 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1193 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001194 case '<':
1195 res.replace(i, 1, "&lt;");
1196 i += 4;
1197 break;
1198 case '>':
1199 res.replace(i, 1, "&gt;");
1200 i += 4;
1201 break;
1202 case '&':
1203 res.replace(i, 1, "&amp;");
1204 i += 5;
1205 break;
1206 case '"':
1207 res.replace(i, 1, "&quot;");
1208 i += 6;
1209 break;
1210 case '\n':
1211 res.replace(i, 1, "<br>");
1212 i += 4;
1213 break;
1214 }
1215 }
1216 return res;
1217}
1218
Roman Zippelab45d192006-06-08 22:12:47 -07001219void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001220{
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001221 QTextStream *stream = reinterpret_cast<QTextStream *>(data);
Roman Zippelab45d192006-06-08 22:12:47 -07001222
1223 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Masahiro Yamada510bc3cb2020-08-21 02:43:28 +09001224 *stream << "<a href=\"s" << sym->name << "\">";
1225 *stream << print_filter(str);
1226 *stream << "</a>";
1227 } else {
1228 *stream << print_filter(str);
1229 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001230}
1231
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001232void ConfigInfoView::clicked(const QUrl &url)
1233{
1234 QByteArray str = url.toEncoded();
1235 const std::size_t count = str.size();
1236 char *data = new char[count + 1];
1237 struct symbol **result;
1238 struct menu *m = NULL;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001239
1240 if (count < 1) {
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001241 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001242 return;
1243 }
1244
1245 memcpy(data, str.constData(), count);
1246 data[count] = '\0';
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001247
1248 /* Seek for exact match */
1249 data[0] = '^';
1250 strcat(data, "$");
1251 result = sym_re_search(data);
1252 if (!result) {
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001253 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001254 return;
1255 }
1256
1257 sym = *result;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001258
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001259 /* Seek for the menu which holds the symbol */
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001260 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1261 if (prop->type != P_PROMPT && prop->type != P_MENU)
1262 continue;
1263 m = prop->menu;
1264 break;
1265 }
1266
1267 if (!m) {
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001268 /* Symbol is not visible as a menu */
1269 symbolInfo();
1270 emit showDebugChanged(true);
1271 } else {
1272 emit menuSelected(m);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001273 }
1274
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001275 free(result);
Masahiro Yamadaa608b6a2020-09-09 07:16:37 +09001276 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001277}
1278
Masahiro Yamada7d1300e2020-08-18 01:36:30 +09001279void ConfigInfoView::contextMenuEvent(QContextMenuEvent *event)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001280{
Masahiro Yamada7d1300e2020-08-18 01:36:30 +09001281 contextMenu->popup(event->globalPos());
1282 event->accept();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001283}
1284
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001285ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow *parent)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001286 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001287{
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001288 setObjectName("search");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001289 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001290
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001291 QVBoxLayout* layout1 = new QVBoxLayout(this);
1292 layout1->setContentsMargins(11, 11, 11, 11);
1293 layout1->setSpacing(6);
Masahiro Yamada92641152020-08-07 18:18:58 +09001294
1295 QHBoxLayout* layout2 = new QHBoxLayout();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001296 layout2->setContentsMargins(0, 0, 0, 0);
1297 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001298 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001299 editField = new QLineEdit(this);
1300 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1301 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001302 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001303 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001304 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1305 layout2->addWidget(searchButton);
1306 layout1->addLayout(layout2);
1307
Roman Zippel7fc925f2006-06-08 22:12:46 -07001308 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001309 split->setOrientation(Qt::Vertical);
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001310 list = new ConfigView(split, "search");
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001311 list->list->mode = listMode;
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001312 info = new ConfigInfoView(split, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001313 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1314 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001315 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1316 parent, SLOT(setMenuLink(struct menu *)));
1317
Roman Zippel43bf6122006-06-08 22:12:45 -07001318 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001319
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001320 QVariant x, y;
1321 int width, height;
1322 bool ok;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001323
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001324 configSettings->beginGroup("search");
1325 width = configSettings->value("/window width", parent->width() / 2).toInt();
1326 height = configSettings->value("/window height", parent->height() / 2).toInt();
1327 resize(width, height);
1328 x = configSettings->value("/window x");
1329 y = configSettings->value("/window y");
1330 if (x.isValid() && y.isValid())
1331 move(x.toInt(), y.toInt());
1332 QList<int> sizes = configSettings->readSizes("/split", &ok);
1333 if (ok)
1334 split->setSizes(sizes);
1335 configSettings->endGroup();
1336 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
Roman Zippel7fc925f2006-06-08 22:12:46 -07001337}
1338
1339void ConfigSearchWindow::saveSettings(void)
1340{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001341 if (!objectName().isEmpty()) {
1342 configSettings->beginGroup(objectName());
1343 configSettings->setValue("/window x", pos().x());
1344 configSettings->setValue("/window y", pos().y());
1345 configSettings->setValue("/window width", size().width());
1346 configSettings->setValue("/window height", size().height());
1347 configSettings->writeSizes("/split", split->sizes());
1348 configSettings->endGroup();
1349 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001350}
1351
1352void ConfigSearchWindow::search(void)
1353{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001354 struct symbol **p;
1355 struct property *prop;
1356 ConfigItem *lastItem = NULL;
1357
1358 free(result);
1359 list->list->clear();
1360 info->clear();
1361
1362 result = sym_re_search(editField->text().toLatin1());
1363 if (!result)
1364 return;
1365 for (p = result; *p; p++) {
1366 for_all_prompts((*p), prop)
1367 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1368 menu_is_visible(prop->menu));
1369 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001370}
1371
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372/*
1373 * Construct the complete config widget
1374 */
1375ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001376 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
Boris Barbulovski92119932015-09-22 11:36:16 -07001378 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001379 QVariant x, y;
1380 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001381 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001383 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001384 snprintf(title, sizeof(title), "%s%s",
1385 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001386 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001387 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001388 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001390 width = configSettings->value("/window width", d->width() - 64).toInt();
1391 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001393 x = configSettings->value("/window x");
1394 y = configSettings->value("/window y");
1395 if ((x.isValid())&&(y.isValid()))
1396 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Masahiro Yamada5cb255f2020-08-07 18:19:07 +09001398 // set up icons
1399 ConfigItem::symbolYesIcon = QIcon(QPixmap(xpm_symbol_yes));
1400 ConfigItem::symbolModIcon = QIcon(QPixmap(xpm_symbol_mod));
1401 ConfigItem::symbolNoIcon = QIcon(QPixmap(xpm_symbol_no));
1402 ConfigItem::choiceYesIcon = QIcon(QPixmap(xpm_choice_yes));
1403 ConfigItem::choiceNoIcon = QIcon(QPixmap(xpm_choice_no));
1404 ConfigItem::menuIcon = QIcon(QPixmap(xpm_menu));
1405 ConfigItem::menubackIcon = QIcon(QPixmap(xpm_menuback));
1406
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001407 QWidget *widget = new QWidget(this);
1408 QVBoxLayout *layout = new QVBoxLayout(widget);
1409 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001411 split1 = new QSplitter(widget);
1412 split1->setOrientation(Qt::Horizontal);
1413 split1->setChildrenCollapsible(false);
1414
1415 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 menuList = menuView->list;
1417
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001418 split2 = new QSplitter(widget);
1419 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001420 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001423 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 configList = configView->list;
1425
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001426 helpText = new ConfigInfoView(widget, "help");
1427
1428 layout->addWidget(split2);
1429 split2->addWidget(split1);
1430 split1->addWidget(configView);
1431 split1->addWidget(menuView);
1432 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 setTabOrder(configList, helpText);
1435 configList->setFocus();
1436
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001437 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001438 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1439
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001440 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001441 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001442 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1443
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001444 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001445 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001446 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1447
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001448 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001449 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001450 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1451
Karsten Wiese3b354c52006-12-13 00:34:08 -08001452 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001453
Karsten Wiese3b354c52006-12-13 00:34:08 -08001454 // Set saveAction's initial state
1455 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001456 configname = xstrdup(conf_get_configname());
1457
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001458 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001459 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001460 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001461 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001462 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001463 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001464 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001465 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001466 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001467 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001468 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001469 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001470 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001471 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001473 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001474 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001475 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001476 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001477 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001478 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001479 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001480 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001481 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001482 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001483
1484 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001485 optGroup->setExclusive(true);
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +09001486 connect(optGroup, SIGNAL(triggered(QAction*)), configList,
Li Zefan39a48972010-05-10 16:33:41 +08001487 SLOT(setOptionMode(QAction *)));
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +09001488 connect(optGroup, SIGNAL(triggered(QAction *)), menuList,
Li Zefan39a48972010-05-10 16:33:41 +08001489 SLOT(setOptionMode(QAction *)));
1490
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +09001491 ConfigList::showNormalAction = new QAction("Show Normal Options", optGroup);
1492 ConfigList::showNormalAction->setCheckable(true);
1493 ConfigList::showAllAction = new QAction("Show All Options", optGroup);
1494 ConfigList::showAllAction->setCheckable(true);
1495 ConfigList::showPromptAction = new QAction("Show Prompt Options", optGroup);
1496 ConfigList::showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001497
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001498 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001499 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001500 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001501 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001503 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001504 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001505 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001506 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508 // init tool bar
Masahiro Yamada860ec3f2020-08-07 18:18:55 +09001509 QToolBar *toolBar = addToolBar("Tools");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001510 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001512 toolBar->addAction(loadAction);
1513 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001515 toolBar->addAction(singleViewAction);
1516 toolBar->addAction(splitViewAction);
1517 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001519 // create file menu
1520 QMenu *menu = menuBar()->addMenu("&File");
1521 menu->addAction(loadAction);
1522 menu->addAction(saveAction);
1523 menu->addAction(saveAsAction);
1524 menu->addSeparator();
1525 menu->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Shlomi Fish66e7c722007-02-14 00:32:58 -08001527 // create edit menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001528 menu = menuBar()->addMenu("&Edit");
1529 menu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001530
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 // create options menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001532 menu = menuBar()->addMenu("&Option");
1533 menu->addAction(showNameAction);
1534 menu->addAction(showRangeAction);
1535 menu->addAction(showDataAction);
1536 menu->addSeparator();
1537 menu->addActions(optGroup->actions());
1538 menu->addSeparator();
1539 menu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
1541 // create help menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001542 menu = menuBar()->addMenu("&Help");
1543 menu->addAction(showIntroAction);
1544 menu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001546 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1547 helpText, SLOT (clicked (const QUrl &)) );
1548
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001549 connect(configList, SIGNAL(menuChanged(struct menu *)),
1550 helpText, SLOT(setInfo(struct menu *)));
1551 connect(configList, SIGNAL(menuSelected(struct menu *)),
1552 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001553 connect(configList, SIGNAL(itemSelected(struct menu *)),
1554 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001555 connect(configList, SIGNAL(parentSelected()),
1556 SLOT(goBack()));
1557 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1558 helpText, SLOT(setInfo(struct menu *)));
1559 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1560 SLOT(changeMenu(struct menu *)));
1561
1562 connect(configList, SIGNAL(gotFocus(struct menu *)),
1563 helpText, SLOT(setInfo(struct menu *)));
1564 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1565 helpText, SLOT(setInfo(struct menu *)));
1566 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1567 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001568 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1569 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001571 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 if (listMode == "single")
1573 showSingleView();
1574 else if (listMode == "full")
1575 showFullView();
1576 else /*if (listMode == "split")*/
1577 showSplitView();
1578
1579 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001580 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 if (ok)
1582 split1->setSizes(sizes);
1583
Roman Zippel7fc925f2006-06-08 22:12:46 -07001584 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 if (ok)
1586 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
1588
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589void ConfigMainWindow::loadConfig(void)
1590{
Masahiro Yamada87419082019-03-11 01:13:15 +09001591 QString str;
1592 QByteArray ba;
1593 const char *name;
1594
1595 str = QFileDialog::getOpenFileName(this, "", configname);
1596 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001598
1599 ba = str.toLocal8Bit();
1600 name = ba.data();
1601
1602 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001603 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001604
1605 free(configname);
1606 configname = xstrdup(name);
1607
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 ConfigView::updateListAll();
1609}
1610
Michal Marekbac6aa82011-05-25 15:10:25 +02001611bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
Masahiro Yamada87419082019-03-11 01:13:15 +09001613 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001614 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001615 return false;
1616 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001617 conf_write_autoconf(0);
1618
Michal Marekbac6aa82011-05-25 15:10:25 +02001619 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
1622void ConfigMainWindow::saveConfigAs(void)
1623{
Masahiro Yamada87419082019-03-11 01:13:15 +09001624 QString str;
1625 QByteArray ba;
1626 const char *name;
1627
1628 str = QFileDialog::getSaveFileName(this, "", configname);
1629 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001631
1632 ba = str.toLocal8Bit();
1633 name = ba.data();
1634
1635 if (conf_write(name)) {
1636 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1637 }
1638 conf_write_autoconf(0);
1639
1640 free(configname);
1641 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642}
1643
Roman Zippel43bf6122006-06-08 22:12:45 -07001644void ConfigMainWindow::searchConfig(void)
1645{
1646 if (!searchWindow)
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001647 searchWindow = new ConfigSearchWindow(this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001648 searchWindow->show();
1649}
1650
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001651void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001653 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654}
1655
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001656void ConfigMainWindow::changeMenu(struct menu *menu)
1657{
1658 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001659}
1660
Roman Zippelb65a47e2006-06-08 22:12:47 -07001661void ConfigMainWindow::setMenuLink(struct menu *menu)
1662{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001663 struct menu *parent;
1664 ConfigList* list = NULL;
1665 ConfigItem* item;
1666
1667 if (configList->menuSkip(menu))
1668 return;
1669
1670 switch (configList->mode) {
1671 case singleMode:
1672 list = configList;
1673 parent = menu_get_parent_menu(menu);
1674 if (!parent)
1675 return;
1676 list->setRootMenu(parent);
1677 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001678 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001679 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001680 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001681 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001682 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001683 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001684 parent = menu_get_parent_menu(menu->parent);
1685 if (!parent)
1686 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001687
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001688 /* Select the config view */
1689 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001690 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001691 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001692 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001693 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001694
1695 menuList->setRootMenu(parent);
1696 menuList->clearSelection();
1697 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001698 }
1699 break;
1700 case fullMode:
1701 list = configList;
1702 break;
1703 default:
1704 break;
1705 }
1706
1707 if (list) {
1708 item = list->findConfigItem(menu);
1709 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001710 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001711 list->scrollToItem(item);
1712 list->setFocus();
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001713 helpText->setInfo(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001714 }
1715 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001716}
1717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718void ConfigMainWindow::listFocusChanged(void)
1719{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001720 if (menuList->mode == menuMode)
1721 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
1724void ConfigMainWindow::goBack(void)
1725{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001726 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001727 return;
1728
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001729 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
1731
1732void ConfigMainWindow::showSingleView(void)
1733{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001734 singleViewAction->setEnabled(false);
1735 singleViewAction->setChecked(true);
1736 splitViewAction->setEnabled(true);
1737 splitViewAction->setChecked(false);
1738 fullViewAction->setEnabled(true);
1739 fullViewAction->setChecked(false);
1740
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001741 backAction->setEnabled(true);
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001744 menuList->setRootMenu(0);
1745 configList->mode = singleMode;
1746 if (configList->rootEntry == &rootmenu)
1747 configList->updateListAll();
1748 else
1749 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 configList->setFocus();
1751}
1752
1753void ConfigMainWindow::showSplitView(void)
1754{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001755 singleViewAction->setEnabled(true);
1756 singleViewAction->setChecked(false);
1757 splitViewAction->setEnabled(false);
1758 splitViewAction->setChecked(true);
1759 fullViewAction->setEnabled(true);
1760 fullViewAction->setChecked(false);
1761
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001762 backAction->setEnabled(false);
1763
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001764 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001765 if (configList->rootEntry == &rootmenu)
1766 configList->updateListAll();
1767 else
1768 configList->setRootMenu(&rootmenu);
1769 configList->setAllOpen(true);
1770 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001771 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001772 menuList->setRootMenu(&rootmenu);
1773 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 menuView->show();
1775 menuList->setFocus();
1776}
1777
1778void ConfigMainWindow::showFullView(void)
1779{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001780 singleViewAction->setEnabled(true);
1781 singleViewAction->setChecked(false);
1782 splitViewAction->setEnabled(true);
1783 splitViewAction->setChecked(false);
1784 fullViewAction->setEnabled(false);
1785 fullViewAction->setChecked(true);
1786
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001787 backAction->setEnabled(false);
1788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001790 menuList->setRootMenu(0);
1791 configList->mode = fullMode;
1792 if (configList->rootEntry == &rootmenu)
1793 configList->updateListAll();
1794 else
1795 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 configList->setFocus();
1797}
1798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799/*
1800 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 */
1802void ConfigMainWindow::closeEvent(QCloseEvent* e)
1803{
Karsten Wieseb3214292006-12-13 00:34:06 -08001804 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 e->accept();
1806 return;
1807 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001808 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001810 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1811 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1812 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 switch (mb.exec()) {
1814 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001815 if (saveConfig())
1816 e->accept();
1817 else
1818 e->ignore();
1819 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 case QMessageBox::No:
1821 e->accept();
1822 break;
1823 case QMessageBox::Cancel:
1824 e->ignore();
1825 break;
1826 }
1827}
1828
1829void ConfigMainWindow::showIntro(void)
1830{
Masahiro Yamada8c30e7e2020-08-29 17:14:07 +09001831 static const QString str =
1832 "Welcome to the qconf graphical configuration tool.\n"
1833 "\n"
1834 "For each option, a blank box indicates the feature is "
1835 "disabled, a check indicates it is enabled, and a dot "
1836 "indicates that it is to be compiled as a module. Clicking on "
1837 "the box will cycle through the three states.\n"
1838 "\n"
1839 "If you do not see an option (e.g., a device driver) that you "
1840 "believe should be present, try turning on Show All Options "
Masahiro Yamada1fb75242020-08-29 17:14:08 +09001841 "under the Options menu. Enabling Show Debug Info will help you"
1842 "figure out what other options must be enabled to support the "
1843 "option you are interested in, and hyperlinks will navigate to "
1844 "them.\n"
Masahiro Yamada8c30e7e2020-08-29 17:14:07 +09001845 "\n"
1846 "Toggling Show Debug Info under the Options menu will show the "
1847 "dependencies, which you can then match by examining other "
1848 "options.\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
1850 QMessageBox::information(this, "qconf", str);
1851}
1852
1853void ConfigMainWindow::showAbout(void)
1854{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001855 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001856 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001857 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
1859 QMessageBox::information(this, "qconf", str);
1860}
1861
1862void ConfigMainWindow::saveSettings(void)
1863{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001864 configSettings->setValue("/window x", pos().x());
1865 configSettings->setValue("/window y", pos().y());
1866 configSettings->setValue("/window width", size().width());
1867 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
1869 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001870 switch(configList->mode) {
1871 case singleMode :
1872 entry = "single";
1873 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001875 case symbolMode :
1876 entry = "split";
1877 break;
1878
1879 case fullMode :
1880 entry = "full";
1881 break;
1882
1883 default:
1884 break;
1885 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001886 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Roman Zippel7fc925f2006-06-08 22:12:46 -07001888 configSettings->writeSizes("/split1", split1->sizes());
1889 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890}
1891
Karsten Wiese3b354c52006-12-13 00:34:08 -08001892void ConfigMainWindow::conf_changed(void)
1893{
1894 if (saveAction)
1895 saveAction->setEnabled(conf_get_changed());
1896}
1897
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898void fixup_rootmenu(struct menu *menu)
1899{
1900 struct menu *child;
1901 static int menu_cnt = 0;
1902
1903 menu->flags |= MENU_ROOT;
1904 for (child = menu->list; child; child = child->next) {
1905 if (child->prompt && child->prompt->type == P_MENU) {
1906 menu_cnt++;
1907 fixup_rootmenu(child);
1908 menu_cnt--;
1909 } else if (!menu_cnt)
1910 fixup_rootmenu(child);
1911 }
1912}
1913
1914static const char *progname;
1915
1916static void usage(void)
1917{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001918 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 exit(0);
1920}
1921
1922int main(int ac, char** av)
1923{
1924 ConfigMainWindow* v;
1925 const char *name;
1926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 progname = av[0];
1928 configApp = new QApplication(ac, av);
1929 if (ac > 1 && av[1][0] == '-') {
1930 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001931 case 's':
1932 conf_set_message_callback(NULL);
1933 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 case 'h':
1935 case '?':
1936 usage();
1937 }
1938 name = av[2];
1939 } else
1940 name = av[1];
1941 if (!name)
1942 usage();
1943
1944 conf_parse(name);
1945 fixup_rootmenu(&rootmenu);
1946 conf_read(NULL);
1947 //zconfdump(stdout);
1948
Roman Zippel7fc925f2006-06-08 22:12:46 -07001949 configSettings = new ConfigSettings();
1950 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 v = new ConfigMainWindow();
1952
1953 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1955 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001956 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 configApp->exec();
1958
Roman Zippel7fc925f2006-06-08 22:12:46 -07001959 configSettings->endGroup();
1960 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001961 delete v;
1962 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001963
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 return 0;
1965}