blob: 4440072aa5454f393632f467b61ba6cd78f890ae [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/*
86 * set the new data
87 * TODO check the value
88 */
89void ConfigItem::okRename(int col)
90{
91}
92
93/*
94 * update the displayed of a menu entry
95 */
96void ConfigItem::updateMenu(void)
97{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070098 ConfigList* list;
99 struct symbol* sym;
100 struct property *prop;
101 QString prompt;
102 int type;
103 tristate expr;
104
105 list = listView();
106 if (goParent) {
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900107 setIcon(promptColIdx, menubackIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700108 prompt = "..";
109 goto set_prompt;
110 }
111
112 sym = menu->sym;
113 prop = menu->prompt;
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900114 prompt = menu_get_prompt(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700115
116 if (prop) switch (prop->type) {
117 case P_MENU:
118 if (list->mode == singleMode || list->mode == symbolMode) {
119 /* a menuconfig entry is displayed differently
120 * depending whether it's at the view root or a child.
121 */
122 if (sym && list->rootEntry == menu)
123 break;
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900124 setIcon(promptColIdx, menuIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700125 } else {
126 if (sym)
127 break;
Masahiro Yamada711b8752020-08-07 18:19:03 +0900128 setIcon(promptColIdx, QIcon());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700129 }
130 goto set_prompt;
131 case P_COMMENT:
Masahiro Yamada711b8752020-08-07 18:19:03 +0900132 setIcon(promptColIdx, QIcon());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700133 goto set_prompt;
134 default:
135 ;
136 }
137 if (!sym)
138 goto set_prompt;
139
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900140 setText(nameColIdx, sym->name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700141
142 type = sym_get_type(sym);
143 switch (type) {
144 case S_BOOLEAN:
145 case S_TRISTATE:
146 char ch;
147
Marco Ammonbaa23ec2019-07-04 12:50:41 +0200148 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
Masahiro Yamada711b8752020-08-07 18:19:03 +0900149 setIcon(promptColIdx, QIcon());
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200150 setText(noColIdx, QString());
151 setText(modColIdx, QString());
152 setText(yesColIdx, QString());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700153 break;
154 }
155 expr = sym_get_tristate_value(sym);
156 switch (expr) {
157 case yes:
158 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900159 setIcon(promptColIdx, choiceYesIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700160 else
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900161 setIcon(promptColIdx, symbolYesIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700162 setText(yesColIdx, "Y");
163 ch = 'Y';
164 break;
165 case mod:
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900166 setIcon(promptColIdx, symbolModIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700167 setText(modColIdx, "M");
168 ch = 'M';
169 break;
170 default:
171 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900172 setIcon(promptColIdx, choiceNoIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700173 else
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900174 setIcon(promptColIdx, symbolNoIcon);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700175 setText(noColIdx, "N");
176 ch = 'N';
177 break;
178 }
179 if (expr != no)
180 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
181 if (expr != mod)
182 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
183 if (expr != yes)
184 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
185
186 setText(dataColIdx, QChar(ch));
187 break;
188 case S_INT:
189 case S_HEX:
190 case S_STRING:
191 const char* data;
192
193 data = sym_get_string_value(sym);
194
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700195 setText(dataColIdx, data);
196 if (type == S_STRING)
197 prompt = QString("%1: %2").arg(prompt).arg(data);
198 else
199 prompt = QString("(%2) %1").arg(prompt).arg(data);
200 break;
201 }
202 if (!sym_has_value(sym) && visible)
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200203 prompt += " (NEW)";
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700204set_prompt:
205 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700206}
207
208void ConfigItem::testUpdateMenu(bool v)
209{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700210 ConfigItem* i;
211
212 visible = v;
213 if (!menu)
214 return;
215
216 sym_calc_value(menu->sym);
217 if (menu->flags & MENU_CHANGED) {
218 /* the menu entry changed, so update all list items */
219 menu->flags &= ~MENU_CHANGED;
220 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
221 i->updateMenu();
222 } else if (listView()->updateAll)
223 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700224}
225
226
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700227/*
228 * construct a menu entry
229 */
230void ConfigItem::init(void)
231{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700232 if (menu) {
233 ConfigList* list = listView();
234 nextItem = (ConfigItem*)menu->data;
235 menu->data = this;
236
237 if (list->mode != fullMode)
238 setExpanded(true);
239 sym_calc_value(menu->sym);
240 }
241 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700242}
243
244/*
245 * destruct a menu entry
246 */
247ConfigItem::~ConfigItem(void)
248{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700249 if (menu) {
250 ConfigItem** ip = (ConfigItem**)&menu->data;
251 for (; *ip; ip = &(*ip)->nextItem) {
252 if (*ip == this) {
253 *ip = nextItem;
254 break;
255 }
256 }
257 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700258}
259
Roman Zippel43bf6122006-06-08 22:12:45 -0700260ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
261 : Parent(parent)
262{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700263 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700264}
265
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700266void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700269 if (sym_get_string_value(item->menu->sym))
Masahiro Yamada3c73ff02020-08-07 18:19:02 +0900270 setText(sym_get_string_value(item->menu->sym));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700271 else
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200272 setText(QString());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 Parent::show();
274 setFocus();
275}
276
277void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
278{
279 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200280 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200282 case Qt::Key_Return:
283 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700284 sym_set_string_value(item->menu->sym, text().toLatin1());
Masahiro Yamada10316852020-08-07 18:19:00 +0900285 parent()->updateList();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 break;
287 default:
288 Parent::keyPressEvent(e);
289 return;
290 }
291 e->accept();
292 parent()->list->setFocus();
293 hide();
294}
295
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700296ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700297 : Parent(p),
298 updateAll(false),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700299 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700300 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700301{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700302 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700303 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700304 setRootIsDecorated(true);
305
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700306 setVerticalScrollMode(ScrollPerPixel);
307 setHorizontalScrollMode(ScrollPerPixel);
308
Masahiro Yamada97bebbc2020-07-30 02:46:17 +0900309 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700310
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700311 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700312 SLOT(updateSelection(void)));
313
314 if (name) {
315 configSettings->beginGroup(name);
316 showName = configSettings->value("/showName", false).toBool();
317 showRange = configSettings->value("/showRange", false).toBool();
318 showData = configSettings->value("/showData", false).toBool();
319 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
320 configSettings->endGroup();
321 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
322 }
323
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900324 showColumn(promptColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700325
326 reinit();
327}
328
329bool ConfigList::menuSkip(struct menu *menu)
330{
331 if (optMode == normalOpt && menu_is_visible(menu))
332 return false;
333 if (optMode == promptOpt && menu_has_prompt(menu))
334 return false;
335 if (optMode == allOpt)
336 return false;
337 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700338}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700339
340void ConfigList::reinit(void)
341{
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900342 hideColumn(dataColIdx);
343 hideColumn(yesColIdx);
344 hideColumn(modColIdx);
345 hideColumn(noColIdx);
346 hideColumn(nameColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700347
348 if (showName)
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900349 showColumn(nameColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700350 if (showRange) {
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900351 showColumn(noColIdx);
352 showColumn(modColIdx);
353 showColumn(yesColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700354 }
355 if (showData)
Masahiro Yamadaabf741a2020-08-07 18:19:04 +0900356 showColumn(dataColIdx);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700357
358 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700359}
360
361void ConfigList::saveSettings(void)
362{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700363 if (!objectName().isEmpty()) {
364 configSettings->beginGroup(objectName());
365 configSettings->setValue("/showName", showName);
366 configSettings->setValue("/showRange", showRange);
367 configSettings->setValue("/showData", showData);
368 configSettings->setValue("/optionMode", (int)optMode);
369 configSettings->endGroup();
370 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700371}
372
373ConfigItem* ConfigList::findConfigItem(struct menu *menu)
374{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700375 ConfigItem* item = (ConfigItem*)menu->data;
376
377 for (; item; item = item->nextItem) {
378 if (this == item->listView())
379 break;
380 }
381
382 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700383}
384
385void ConfigList::updateSelection(void)
386{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700387 struct menu *menu;
388 enum prop_type type;
389
Boris Barbulovskibe596aa2015-09-22 11:36:28 -0700390 if (selectedItems().count() == 0)
391 return;
392
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700393 ConfigItem* item = (ConfigItem*)selectedItems().first();
394 if (!item)
395 return;
396
397 menu = item->menu;
398 emit menuChanged(menu);
399 if (!menu)
400 return;
401 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
402 if (mode == menuMode && type == P_MENU)
403 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700404}
405
Masahiro Yamadacb770432020-08-07 18:18:59 +0900406void ConfigList::updateList()
Boris Barbulovski59e56442015-09-22 11:36:18 -0700407{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700408 ConfigItem* last = 0;
Masahiro Yamadacb770432020-08-07 18:18:59 +0900409 ConfigItem *item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700410
411 if (!rootEntry) {
412 if (mode != listMode)
413 goto update;
414 QTreeWidgetItemIterator it(this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700415
416 while (*it) {
417 item = (ConfigItem*)(*it);
418 if (!item->menu)
419 continue;
420 item->testUpdateMenu(menu_is_visible(item->menu));
421
422 ++it;
423 }
424 return;
425 }
426
427 if (rootEntry != &rootmenu && (mode == singleMode ||
428 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
Boris Barbulovskiee7298f2015-09-22 11:36:37 -0700429 item = (ConfigItem *)topLevelItem(0);
Masahiro Yamada4b20e102020-08-01 16:08:49 +0900430 if (!item)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700431 item = new ConfigItem(this, 0, true);
Masahiro Yamada4b20e102020-08-01 16:08:49 +0900432 last = item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700433 }
434 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
435 rootEntry->sym && rootEntry->prompt) {
Masahiro Yamadaccf56e52020-08-01 16:08:50 +0900436 item = last ? last->nextSibling() : nullptr;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700437 if (!item)
438 item = new ConfigItem(this, last, rootEntry, true);
439 else
440 item->testUpdateMenu(true);
441
442 updateMenuList(item, rootEntry);
443 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700444 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700445 return;
446 }
447update:
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900448 updateMenuList(rootEntry);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700449 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700450 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700451}
452
453void ConfigList::setValue(ConfigItem* item, tristate val)
454{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700455 struct symbol* sym;
456 int type;
457 tristate oldval;
458
459 sym = item->menu ? item->menu->sym : 0;
460 if (!sym)
461 return;
462
463 type = sym_get_type(sym);
464 switch (type) {
465 case S_BOOLEAN:
466 case S_TRISTATE:
467 oldval = sym_get_tristate_value(sym);
468
469 if (!sym_set_tristate_value(sym, val))
470 return;
471 if (oldval == no && item->menu->list)
472 item->setExpanded(true);
Masahiro Yamada10316852020-08-07 18:19:00 +0900473 parent()->updateList();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700474 break;
475 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700476}
477
478void ConfigList::changeValue(ConfigItem* item)
479{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700480 struct symbol* sym;
481 struct menu* menu;
482 int type, oldexpr, newexpr;
483
484 menu = item->menu;
485 if (!menu)
486 return;
487 sym = menu->sym;
488 if (!sym) {
489 if (item->menu->list)
490 item->setExpanded(!item->isExpanded());
491 return;
492 }
493
494 type = sym_get_type(sym);
495 switch (type) {
496 case S_BOOLEAN:
497 case S_TRISTATE:
498 oldexpr = sym_get_tristate_value(sym);
499 newexpr = sym_toggle_tristate_value(sym);
500 if (item->menu->list) {
501 if (oldexpr == newexpr)
502 item->setExpanded(!item->isExpanded());
503 else if (oldexpr == no)
504 item->setExpanded(true);
505 }
506 if (oldexpr != newexpr)
Masahiro Yamada10316852020-08-07 18:19:00 +0900507 parent()->updateList();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700508 break;
509 case S_INT:
510 case S_HEX:
511 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700512 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700513 break;
514 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700515}
516
517void ConfigList::setRootMenu(struct menu *menu)
518{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700519 enum prop_type type;
520
521 if (rootEntry == menu)
522 return;
523 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
524 if (type != P_MENU)
525 return;
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900526 updateMenuList(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700527 rootEntry = menu;
528 updateListAll();
529 if (currentItem()) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200530 setSelected(currentItem(), hasFocus());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700531 scrollToItem(currentItem());
532 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700533}
534
535void ConfigList::setParentMenu(void)
536{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700537 ConfigItem* item;
538 struct menu *oldroot;
539
540 oldroot = rootEntry;
541 if (rootEntry == &rootmenu)
542 return;
543 setRootMenu(menu_get_parent_menu(rootEntry->parent));
544
545 QTreeWidgetItemIterator it(this);
546 while (*it) {
547 item = (ConfigItem *)(*it);
548 if (item->menu == oldroot) {
549 setCurrentItem(item);
550 scrollToItem(item);
551 break;
552 }
553
554 ++it;
555 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700556}
557
558/*
559 * update all the children of a menu entry
560 * removes/adds the entries from the parent widget as necessary
561 *
562 * parent: either the menu list widget or a menu entry widget
563 * menu: entry to be updated
564 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700565void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700566{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700567 struct menu* child;
568 ConfigItem* item;
569 ConfigItem* last;
570 bool visible;
571 enum prop_type type;
572
573 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700574 while (parent->childCount() > 0)
575 {
576 delete parent->takeChild(0);
577 }
578
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700579 return;
580 }
581
582 last = parent->firstChild();
583 if (last && !last->goParent)
584 last = 0;
585 for (child = menu->list; child; child = child->next) {
586 item = last ? last->nextSibling() : parent->firstChild();
587 type = child->prompt ? child->prompt->type : P_UNKNOWN;
588
589 switch (mode) {
590 case menuMode:
591 if (!(child->flags & MENU_ROOT))
592 goto hide;
593 break;
594 case symbolMode:
595 if (child->flags & MENU_ROOT)
596 goto hide;
597 break;
598 default:
599 break;
600 }
601
602 visible = menu_is_visible(child);
603 if (!menuSkip(child)) {
604 if (!child->sym && !child->list && !child->prompt)
605 continue;
606 if (!item || item->menu != child)
607 item = new ConfigItem(parent, last, child, visible);
608 else
609 item->testUpdateMenu(visible);
610
611 if (mode == fullMode || mode == menuMode || type != P_MENU)
612 updateMenuList(item, child);
613 else
614 updateMenuList(item, 0);
615 last = item;
616 continue;
617 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200618hide:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700619 if (item && item->menu == child) {
620 last = parent->firstChild();
621 if (last == item)
622 last = 0;
623 else while (last->nextSibling() != item)
624 last = last->nextSibling();
625 delete item;
626 }
627 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700628}
629
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900630void ConfigList::updateMenuList(struct menu *menu)
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700631{
632 struct menu* child;
633 ConfigItem* item;
634 ConfigItem* last;
635 bool visible;
636 enum prop_type type;
637
638 if (!menu) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900639 while (topLevelItemCount() > 0)
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700640 {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900641 delete takeTopLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700642 }
643
644 return;
645 }
646
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900647 last = (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700648 if (last && !last->goParent)
649 last = 0;
650 for (child = menu->list; child; child = child->next) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900651 item = last ? last->nextSibling() : (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700652 type = child->prompt ? child->prompt->type : P_UNKNOWN;
653
654 switch (mode) {
655 case menuMode:
656 if (!(child->flags & MENU_ROOT))
657 goto hide;
658 break;
659 case symbolMode:
660 if (child->flags & MENU_ROOT)
661 goto hide;
662 break;
663 default:
664 break;
665 }
666
667 visible = menu_is_visible(child);
668 if (!menuSkip(child)) {
669 if (!child->sym && !child->list && !child->prompt)
670 continue;
671 if (!item || item->menu != child)
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900672 item = new ConfigItem(this, last, child, visible);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700673 else
674 item->testUpdateMenu(visible);
675
676 if (mode == fullMode || mode == menuMode || type != P_MENU)
677 updateMenuList(item, child);
678 else
679 updateMenuList(item, 0);
680 last = item;
681 continue;
682 }
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +0200683hide:
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700684 if (item && item->menu == child) {
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +0900685 last = (ConfigItem *)topLevelItem(0);
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700686 if (last == item)
687 last = 0;
688 else while (last->nextSibling() != item)
689 last = last->nextSibling();
690 delete item;
691 }
692 }
693}
694
Boris Barbulovski59e56442015-09-22 11:36:18 -0700695void ConfigList::keyPressEvent(QKeyEvent* ev)
696{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700697 QTreeWidgetItem* i = currentItem();
698 ConfigItem* item;
699 struct menu *menu;
700 enum prop_type type;
701
702 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
703 emit parentSelected();
704 ev->accept();
705 return;
706 }
707
708 if (!i) {
709 Parent::keyPressEvent(ev);
710 return;
711 }
712 item = (ConfigItem*)i;
713
714 switch (ev->key()) {
715 case Qt::Key_Return:
716 case Qt::Key_Enter:
717 if (item->goParent) {
718 emit parentSelected();
719 break;
720 }
721 menu = item->menu;
722 if (!menu)
723 break;
724 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
725 if (type == P_MENU && rootEntry != menu &&
726 mode != fullMode && mode != menuMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200727 if (mode == menuMode)
728 emit menuSelected(menu);
729 else
730 emit itemSelected(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700731 break;
732 }
733 case Qt::Key_Space:
734 changeValue(item);
735 break;
736 case Qt::Key_N:
737 setValue(item, no);
738 break;
739 case Qt::Key_M:
740 setValue(item, mod);
741 break;
742 case Qt::Key_Y:
743 setValue(item, yes);
744 break;
745 default:
746 Parent::keyPressEvent(ev);
747 return;
748 }
749 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700750}
751
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700752void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700753{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700754 //QPoint p(contentsToViewport(e->pos()));
755 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
756 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700757}
758
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700759void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700760{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700761 QPoint p = e->pos();
762 ConfigItem* item = (ConfigItem*)itemAt(p);
763 struct menu *menu;
764 enum prop_type ptype;
765 QIcon icon;
766 int idx, x;
767
768 if (!item)
769 goto skip;
770
771 menu = item->menu;
772 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700773 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700774 switch (idx) {
775 case promptColIdx:
Masahiro Yamada711b8752020-08-07 18:19:03 +0900776 icon = item->icon(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700777 if (!icon.isNull()) {
778 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
779 if (x >= off && x < off + icon.availableSizes().first().width()) {
780 if (item->goParent) {
781 emit parentSelected();
782 break;
783 } else if (!menu)
784 break;
785 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
786 if (ptype == P_MENU && rootEntry != menu &&
Maxime Chretien7eb7c106f2020-07-08 15:32:15 +0200787 mode != fullMode && mode != menuMode &&
788 mode != listMode)
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700789 emit menuSelected(menu);
790 else
791 changeValue(item);
792 }
793 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700794 break;
795 case noColIdx:
796 setValue(item, no);
797 break;
798 case modColIdx:
799 setValue(item, mod);
800 break;
801 case yesColIdx:
802 setValue(item, yes);
803 break;
804 case dataColIdx:
805 changeValue(item);
806 break;
807 }
808
809skip:
810 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
811 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700812}
813
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700814void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700815{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700816 //QPoint p(contentsToViewport(e->pos()));
817 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
818 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700819}
820
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700821void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700822{
Mauro Carvalho Chehabe1f77692020-04-02 11:28:02 +0200823 QPoint p = e->pos();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700824 ConfigItem* item = (ConfigItem*)itemAt(p);
825 struct menu *menu;
826 enum prop_type ptype;
827
828 if (!item)
829 goto skip;
830 if (item->goParent) {
831 emit parentSelected();
832 goto skip;
833 }
834 menu = item->menu;
835 if (!menu)
836 goto skip;
837 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
Maxime Chretien7eb7c106f2020-07-08 15:32:15 +0200838 if (ptype == P_MENU && mode != listMode) {
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200839 if (mode == singleMode)
840 emit itemSelected(menu);
841 else if (mode == symbolMode)
842 emit menuSelected(menu);
843 } else if (menu->sym)
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700844 changeValue(item);
845
846skip:
847 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
848 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700849}
850
851void ConfigList::focusInEvent(QFocusEvent *e)
852{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700853 struct menu *menu = NULL;
854
855 Parent::focusInEvent(e);
856
857 ConfigItem* item = (ConfigItem *)currentItem();
858 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +0200859 setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700860 menu = item->menu;
861 }
862 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700863}
864
865void ConfigList::contextMenuEvent(QContextMenuEvent *e)
866{
Masahiro Yamadafa8de0a2020-08-07 18:19:08 +0900867 if (!headerPopup) {
868 QAction *action;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700869
Masahiro Yamadafa8de0a2020-08-07 18:19:08 +0900870 headerPopup = new QMenu(this);
871 action = new QAction("Show Name", this);
872 action->setCheckable(true);
873 connect(action, SIGNAL(toggled(bool)),
874 parent(), SLOT(setShowName(bool)));
875 connect(parent(), SIGNAL(showNameChanged(bool)),
876 action, SLOT(setOn(bool)));
877 action->setChecked(showName);
878 headerPopup->addAction(action);
879
880 action = new QAction("Show Range", this);
881 action->setCheckable(true);
882 connect(action, SIGNAL(toggled(bool)),
883 parent(), SLOT(setShowRange(bool)));
884 connect(parent(), SIGNAL(showRangeChanged(bool)),
885 action, SLOT(setOn(bool)));
886 action->setChecked(showRange);
887 headerPopup->addAction(action);
888
889 action = new QAction("Show Data", this);
890 action->setCheckable(true);
891 connect(action, SIGNAL(toggled(bool)),
892 parent(), SLOT(setShowData(bool)));
893 connect(parent(), SIGNAL(showDataChanged(bool)),
894 action, SLOT(setOn(bool)));
895 action->setChecked(showData);
896 headerPopup->addAction(action);
897 }
898
899 headerPopup->exec(e->globalPos());
900 e->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700901}
902
Li Zefan39a48972010-05-10 16:33:41 +0800903ConfigView*ConfigView::viewList;
904QAction *ConfigView::showNormalAction;
905QAction *ConfigView::showAllAction;
906QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Roman Zippel7fc925f2006-06-08 22:12:46 -0700908ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700909 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700911 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700912 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700913 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700914
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700915 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700916 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 lineEdit = new ConfigLineEdit(this);
918 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700919 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 this->nextView = viewList;
922 viewList = this;
923}
924
925ConfigView::~ConfigView(void)
926{
927 ConfigView** vp;
928
929 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
930 if (*vp == this) {
931 *vp = nextView;
932 break;
933 }
934 }
935}
936
Li Zefan39a48972010-05-10 16:33:41 +0800937void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700938{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700939 if (act == showNormalAction)
940 list->optMode = normalOpt;
941 else if (act == showAllAction)
942 list->optMode = allOpt;
943 else
944 list->optMode = promptOpt;
945
946 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700947}
948
949void ConfigView::setShowName(bool b)
950{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700951 if (list->showName != b) {
952 list->showName = b;
953 list->reinit();
954 emit showNameChanged(b);
955 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700956}
957
958void ConfigView::setShowRange(bool b)
959{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700960 if (list->showRange != b) {
961 list->showRange = b;
962 list->reinit();
963 emit showRangeChanged(b);
964 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700965}
966
967void ConfigView::setShowData(bool b)
968{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700969 if (list->showData != b) {
970 list->showData = b;
971 list->reinit();
972 emit showDataChanged(b);
973 }
974}
975
976void ConfigList::setAllOpen(bool open)
977{
978 QTreeWidgetItemIterator it(this);
979
980 while (*it) {
981 (*it)->setExpanded(open);
982
983 ++it;
984 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700985}
986
Masahiro Yamada10316852020-08-07 18:19:00 +0900987void ConfigView::updateList()
Roman Zippel7fc925f2006-06-08 22:12:46 -0700988{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700989 ConfigView* v;
990
991 for (v = viewList; v; v = v->nextView)
Masahiro Yamadacb770432020-08-07 18:18:59 +0900992 v->list->updateList();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
995void ConfigView::updateListAll(void)
996{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700997 ConfigView* v;
998
999 for (v = viewList; v; v = v->nextView)
1000 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001}
1002
Roman Zippel43bf6122006-06-08 22:12:45 -07001003ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001004 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -07001005{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001006 setObjectName(name);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001007 setOpenLinks(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001008
1009 if (!objectName().isEmpty()) {
1010 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001011 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001012 configSettings->endGroup();
1013 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1014 }
1015}
1016
1017void ConfigInfoView::saveSettings(void)
1018{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001019 if (!objectName().isEmpty()) {
1020 configSettings->beginGroup(objectName());
1021 configSettings->setValue("/showDebug", showDebug());
1022 configSettings->endGroup();
1023 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001024}
1025
1026void ConfigInfoView::setShowDebug(bool b)
1027{
1028 if (_showDebug != b) {
1029 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001030 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001031 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001032 else if (sym)
1033 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001034 emit showDebugChanged(b);
1035 }
1036}
1037
1038void ConfigInfoView::setInfo(struct menu *m)
1039{
Alexander Stein133c5f72010-08-31 17:34:37 +02001040 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001041 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001042 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001043 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001044 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001045 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001046 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001047 menuInfo();
1048}
1049
Roman Zippelab45d192006-06-08 22:12:47 -07001050void ConfigInfoView::symbolInfo(void)
1051{
1052 QString str;
1053
1054 str += "<big>Symbol: <b>";
1055 str += print_filter(sym->name);
1056 str += "</b></big><br><br>value: ";
1057 str += print_filter(sym_get_string_value(sym));
1058 str += "<br>visibility: ";
1059 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1060 str += "<br>";
1061 str += debug_info(sym);
1062
1063 setText(str);
1064}
1065
Roman Zippel43bf6122006-06-08 22:12:45 -07001066void ConfigInfoView::menuInfo(void)
1067{
1068 struct symbol* sym;
1069 QString head, debug, help;
1070
Alexander Stein133c5f72010-08-31 17:34:37 +02001071 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001072 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001073 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001074 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001075 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001076 head += "</b></big>";
1077 if (sym->name) {
1078 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001079 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001080 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001081 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001082 if (showDebug())
1083 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001084 head += ")";
1085 }
1086 } else if (sym->name) {
1087 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001088 if (showDebug())
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001089 head += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001090 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001091 if (showDebug())
1092 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001093 head += "</b></big>";
1094 }
1095 head += "<br><br>";
1096
1097 if (showDebug())
1098 debug = debug_info(sym);
1099
Cheng Renquand74c15f2009-07-12 16:11:47 +08001100 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001101 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001102 help = print_filter(str_get(&help_gstr));
1103 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001104 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001105 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001106 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001107 head += "</b></big><br><br>";
1108 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001109 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001110 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001111 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001112 debug += "<br><br>";
1113 }
1114 }
1115 }
1116 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001117 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001118
1119 setText(head + debug + help);
1120}
1121
1122QString ConfigInfoView::debug_info(struct symbol *sym)
1123{
1124 QString debug;
1125
1126 debug += "type: ";
1127 debug += print_filter(sym_type_name(sym->type));
1128 if (sym_is_choice(sym))
1129 debug += " (choice)";
1130 debug += "<br>";
1131 if (sym->rev_dep.expr) {
1132 debug += "reverse dep: ";
1133 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1134 debug += "<br>";
1135 }
1136 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1137 switch (prop->type) {
1138 case P_PROMPT:
1139 case P_MENU:
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001140 debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001141 debug += print_filter(prop->text);
Roman Zippelab45d192006-06-08 22:12:47 -07001142 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001143 break;
1144 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001145 case P_SELECT:
1146 case P_RANGE:
Mauro Carvalho Chehab8f8499a2020-06-30 08:48:53 +02001147 case P_COMMENT:
1148 case P_IMPLY:
1149 case P_SYMBOL:
Roman Zippel93449082008-01-14 04:50:54 +01001150 debug += prop_get_type_name(prop->type);
1151 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001152 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1153 debug += "<br>";
1154 break;
1155 case P_CHOICE:
1156 if (sym_is_choice(sym)) {
1157 debug += "choice: ";
1158 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1159 debug += "<br>";
1160 }
1161 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001162 default:
1163 debug += "unknown property: ";
1164 debug += prop_get_type_name(prop->type);
1165 debug += "<br>";
1166 }
1167 if (prop->visible.expr) {
1168 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1169 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1170 debug += "<br>";
1171 }
1172 }
1173 debug += "<br>";
1174
1175 return debug;
1176}
1177
1178QString ConfigInfoView::print_filter(const QString &str)
1179{
1180 QRegExp re("[<>&\"\\n]");
1181 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001182 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1183 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001184 case '<':
1185 res.replace(i, 1, "&lt;");
1186 i += 4;
1187 break;
1188 case '>':
1189 res.replace(i, 1, "&gt;");
1190 i += 4;
1191 break;
1192 case '&':
1193 res.replace(i, 1, "&amp;");
1194 i += 5;
1195 break;
1196 case '"':
1197 res.replace(i, 1, "&quot;");
1198 i += 6;
1199 break;
1200 case '\n':
1201 res.replace(i, 1, "<br>");
1202 i += 4;
1203 break;
1204 }
1205 }
1206 return res;
1207}
1208
Roman Zippelab45d192006-06-08 22:12:47 -07001209void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001210{
Roman Zippelab45d192006-06-08 22:12:47 -07001211 QString* text = reinterpret_cast<QString*>(data);
1212 QString str2 = print_filter(str);
1213
1214 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001215 *text += QString().sprintf("<a href=\"s%s\">", sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001216 *text += str2;
1217 *text += "</a>";
1218 } else
1219 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001220}
1221
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001222void ConfigInfoView::clicked(const QUrl &url)
1223{
1224 QByteArray str = url.toEncoded();
1225 const std::size_t count = str.size();
1226 char *data = new char[count + 1];
1227 struct symbol **result;
1228 struct menu *m = NULL;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001229
1230 if (count < 1) {
1231 qInfo() << "Clicked link is empty";
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001232 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001233 return;
1234 }
1235
1236 memcpy(data, str.constData(), count);
1237 data[count] = '\0';
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001238
1239 /* Seek for exact match */
1240 data[0] = '^';
1241 strcat(data, "$");
1242 result = sym_re_search(data);
1243 if (!result) {
1244 qInfo() << "Clicked symbol is invalid:" << data;
Masahiro Yamadac9b09a922020-07-30 02:02:39 +09001245 delete[] data;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001246 return;
1247 }
1248
1249 sym = *result;
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001250
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001251 /* Seek for the menu which holds the symbol */
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001252 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1253 if (prop->type != P_PROMPT && prop->type != P_MENU)
1254 continue;
1255 m = prop->menu;
1256 break;
1257 }
1258
1259 if (!m) {
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001260 /* Symbol is not visible as a menu */
1261 symbolInfo();
1262 emit showDebugChanged(true);
1263 } else {
1264 emit menuSelected(m);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001265 }
1266
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001267 free(result);
1268 delete data;
1269}
1270
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001271QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001272{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001273 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001274 QAction* action = new QAction("Show Debug Info", popup);
Mauro Carvalho Chehab60969f02020-04-02 11:28:03 +02001275
1276 action->setCheckable(true);
1277 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1278 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1279 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001280 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001281 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001282 return popup;
1283}
1284
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001285void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001286{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001287 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001288}
1289
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001290ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow *parent)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001291 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001292{
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001293 setObjectName("search");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001294 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001295
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001296 QVBoxLayout* layout1 = new QVBoxLayout(this);
1297 layout1->setContentsMargins(11, 11, 11, 11);
1298 layout1->setSpacing(6);
Masahiro Yamada92641152020-08-07 18:18:58 +09001299
1300 QHBoxLayout* layout2 = new QHBoxLayout();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001301 layout2->setContentsMargins(0, 0, 0, 0);
1302 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001303 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001304 editField = new QLineEdit(this);
1305 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1306 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001307 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001308 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001309 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1310 layout2->addWidget(searchButton);
1311 layout1->addLayout(layout2);
1312
Roman Zippel7fc925f2006-06-08 22:12:46 -07001313 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001314 split->setOrientation(Qt::Vertical);
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001315 list = new ConfigView(split, "search");
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001316 list->list->mode = listMode;
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001317 info = new ConfigInfoView(split, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001318 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1319 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001320 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1321 parent, SLOT(setMenuLink(struct menu *)));
1322
Roman Zippel43bf6122006-06-08 22:12:45 -07001323 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001324
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001325 QVariant x, y;
1326 int width, height;
1327 bool ok;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001328
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001329 configSettings->beginGroup("search");
1330 width = configSettings->value("/window width", parent->width() / 2).toInt();
1331 height = configSettings->value("/window height", parent->height() / 2).toInt();
1332 resize(width, height);
1333 x = configSettings->value("/window x");
1334 y = configSettings->value("/window y");
1335 if (x.isValid() && y.isValid())
1336 move(x.toInt(), y.toInt());
1337 QList<int> sizes = configSettings->readSizes("/split", &ok);
1338 if (ok)
1339 split->setSizes(sizes);
1340 configSettings->endGroup();
1341 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
Roman Zippel7fc925f2006-06-08 22:12:46 -07001342}
1343
1344void ConfigSearchWindow::saveSettings(void)
1345{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001346 if (!objectName().isEmpty()) {
1347 configSettings->beginGroup(objectName());
1348 configSettings->setValue("/window x", pos().x());
1349 configSettings->setValue("/window y", pos().y());
1350 configSettings->setValue("/window width", size().width());
1351 configSettings->setValue("/window height", size().height());
1352 configSettings->writeSizes("/split", split->sizes());
1353 configSettings->endGroup();
1354 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001355}
1356
1357void ConfigSearchWindow::search(void)
1358{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001359 struct symbol **p;
1360 struct property *prop;
1361 ConfigItem *lastItem = NULL;
1362
1363 free(result);
1364 list->list->clear();
1365 info->clear();
1366
1367 result = sym_re_search(editField->text().toLatin1());
1368 if (!result)
1369 return;
1370 for (p = result; *p; p++) {
1371 for_all_prompts((*p), prop)
1372 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1373 menu_is_visible(prop->menu));
1374 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001375}
1376
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377/*
1378 * Construct the complete config widget
1379 */
1380ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001381 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382{
Boris Barbulovski92119932015-09-22 11:36:16 -07001383 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001384 QVariant x, y;
1385 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001386 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001388 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001389 snprintf(title, sizeof(title), "%s%s",
1390 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001391 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001392 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001393 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001395 width = configSettings->value("/window width", d->width() - 64).toInt();
1396 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001398 x = configSettings->value("/window x");
1399 y = configSettings->value("/window y");
1400 if ((x.isValid())&&(y.isValid()))
1401 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Masahiro Yamada5cb255f2020-08-07 18:19:07 +09001403 // set up icons
1404 ConfigItem::symbolYesIcon = QIcon(QPixmap(xpm_symbol_yes));
1405 ConfigItem::symbolModIcon = QIcon(QPixmap(xpm_symbol_mod));
1406 ConfigItem::symbolNoIcon = QIcon(QPixmap(xpm_symbol_no));
1407 ConfigItem::choiceYesIcon = QIcon(QPixmap(xpm_choice_yes));
1408 ConfigItem::choiceNoIcon = QIcon(QPixmap(xpm_choice_no));
1409 ConfigItem::menuIcon = QIcon(QPixmap(xpm_menu));
1410 ConfigItem::menubackIcon = QIcon(QPixmap(xpm_menuback));
1411
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001412 QWidget *widget = new QWidget(this);
1413 QVBoxLayout *layout = new QVBoxLayout(widget);
1414 setCentralWidget(widget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001416 split1 = new QSplitter(widget);
1417 split1->setOrientation(Qt::Horizontal);
1418 split1->setChildrenCollapsible(false);
1419
1420 menuView = new ConfigView(widget, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 menuList = menuView->list;
1422
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001423 split2 = new QSplitter(widget);
1424 split2->setChildrenCollapsible(false);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001425 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 // create config tree
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001428 configView = new ConfigView(widget, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 configList = configView->list;
1430
Mauro Carvalho Chehabcce1fab2020-04-02 11:28:00 +02001431 helpText = new ConfigInfoView(widget, "help");
1432
1433 layout->addWidget(split2);
1434 split2->addWidget(split1);
1435 split1->addWidget(configView);
1436 split1->addWidget(menuView);
1437 split2->addWidget(helpText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
1439 setTabOrder(configList, helpText);
1440 configList->setFocus();
1441
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001442 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001443 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1444
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001445 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001446 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001447 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1448
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001449 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001450 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001451 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1452
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001453 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001454 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001455 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1456
Karsten Wiese3b354c52006-12-13 00:34:08 -08001457 conf_set_changed_callback(conf_changed);
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001458
Karsten Wiese3b354c52006-12-13 00:34:08 -08001459 // Set saveAction's initial state
1460 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001461 configname = xstrdup(conf_get_configname());
1462
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001463 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001464 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001465 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001466 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001467 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001468 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001469 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001470 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001471 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001472 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001473 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001474 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001475 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001476 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001478 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001479 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001480 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001481 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001482 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001483 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001484 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001485 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001486 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001487 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001488
1489 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001490 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001491 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001492 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001493 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001494 SLOT(setOptionMode(QAction *)));
1495
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001496 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1497 configView->showAllAction = new QAction("Show All Options", optGroup);
1498 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001499 configView->showNormalAction->setCheckable(true);
1500 configView->showAllAction->setCheckable(true);
1501 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001502
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001503 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001504 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001505 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001506 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001508 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001509 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001510 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001511 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
1513 // init tool bar
Masahiro Yamada860ec3f2020-08-07 18:18:55 +09001514 QToolBar *toolBar = addToolBar("Tools");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001515 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001517 toolBar->addAction(loadAction);
1518 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001520 toolBar->addAction(singleViewAction);
1521 toolBar->addAction(splitViewAction);
1522 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001524 // create file menu
1525 QMenu *menu = menuBar()->addMenu("&File");
1526 menu->addAction(loadAction);
1527 menu->addAction(saveAction);
1528 menu->addAction(saveAsAction);
1529 menu->addSeparator();
1530 menu->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Shlomi Fish66e7c722007-02-14 00:32:58 -08001532 // create edit menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001533 menu = menuBar()->addMenu("&Edit");
1534 menu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001535
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 // create options menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001537 menu = menuBar()->addMenu("&Option");
1538 menu->addAction(showNameAction);
1539 menu->addAction(showRangeAction);
1540 menu->addAction(showDataAction);
1541 menu->addSeparator();
1542 menu->addActions(optGroup->actions());
1543 menu->addSeparator();
1544 menu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
1546 // create help menu
Masahiro Yamada93ebaac2020-08-07 18:18:53 +09001547 menu = menuBar()->addMenu("&Help");
1548 menu->addAction(showIntroAction);
1549 menu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +02001551 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1552 helpText, SLOT (clicked (const QUrl &)) );
1553
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001554 connect(configList, SIGNAL(menuChanged(struct menu *)),
1555 helpText, SLOT(setInfo(struct menu *)));
1556 connect(configList, SIGNAL(menuSelected(struct menu *)),
1557 SLOT(changeMenu(struct menu *)));
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001558 connect(configList, SIGNAL(itemSelected(struct menu *)),
1559 SLOT(changeItens(struct menu *)));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001560 connect(configList, SIGNAL(parentSelected()),
1561 SLOT(goBack()));
1562 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1563 helpText, SLOT(setInfo(struct menu *)));
1564 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1565 SLOT(changeMenu(struct menu *)));
1566
1567 connect(configList, SIGNAL(gotFocus(struct menu *)),
1568 helpText, SLOT(setInfo(struct menu *)));
1569 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1570 helpText, SLOT(setInfo(struct menu *)));
1571 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1572 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001573 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1574 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001576 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 if (listMode == "single")
1578 showSingleView();
1579 else if (listMode == "full")
1580 showFullView();
1581 else /*if (listMode == "split")*/
1582 showSplitView();
1583
1584 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001585 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 if (ok)
1587 split1->setSizes(sizes);
1588
Roman Zippel7fc925f2006-06-08 22:12:46 -07001589 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 if (ok)
1591 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592}
1593
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594void ConfigMainWindow::loadConfig(void)
1595{
Masahiro Yamada87419082019-03-11 01:13:15 +09001596 QString str;
1597 QByteArray ba;
1598 const char *name;
1599
1600 str = QFileDialog::getOpenFileName(this, "", configname);
1601 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001603
1604 ba = str.toLocal8Bit();
1605 name = ba.data();
1606
1607 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001608 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001609
1610 free(configname);
1611 configname = xstrdup(name);
1612
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 ConfigView::updateListAll();
1614}
1615
Michal Marekbac6aa82011-05-25 15:10:25 +02001616bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
Masahiro Yamada87419082019-03-11 01:13:15 +09001618 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001619 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001620 return false;
1621 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001622 conf_write_autoconf(0);
1623
Michal Marekbac6aa82011-05-25 15:10:25 +02001624 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
1627void ConfigMainWindow::saveConfigAs(void)
1628{
Masahiro Yamada87419082019-03-11 01:13:15 +09001629 QString str;
1630 QByteArray ba;
1631 const char *name;
1632
1633 str = QFileDialog::getSaveFileName(this, "", configname);
1634 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001636
1637 ba = str.toLocal8Bit();
1638 name = ba.data();
1639
1640 if (conf_write(name)) {
1641 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1642 }
1643 conf_write_autoconf(0);
1644
1645 free(configname);
1646 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647}
1648
Roman Zippel43bf6122006-06-08 22:12:45 -07001649void ConfigMainWindow::searchConfig(void)
1650{
1651 if (!searchWindow)
Masahiro Yamada740fdef2020-08-07 18:18:57 +09001652 searchWindow = new ConfigSearchWindow(this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001653 searchWindow->show();
1654}
1655
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001656void ConfigMainWindow::changeItens(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001658 configList->setRootMenu(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001661void ConfigMainWindow::changeMenu(struct menu *menu)
1662{
1663 menuList->setRootMenu(menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001664}
1665
Roman Zippelb65a47e2006-06-08 22:12:47 -07001666void ConfigMainWindow::setMenuLink(struct menu *menu)
1667{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001668 struct menu *parent;
1669 ConfigList* list = NULL;
1670 ConfigItem* item;
1671
1672 if (configList->menuSkip(menu))
1673 return;
1674
1675 switch (configList->mode) {
1676 case singleMode:
1677 list = configList;
1678 parent = menu_get_parent_menu(menu);
1679 if (!parent)
1680 return;
1681 list->setRootMenu(parent);
1682 break;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001683 case menuMode:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001684 if (menu->flags & MENU_ROOT) {
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001685 menuList->setRootMenu(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001686 configList->clearSelection();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001687 list = configList;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001688 } else {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001689 parent = menu_get_parent_menu(menu->parent);
1690 if (!parent)
1691 return;
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001692
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001693 /* Select the config view */
1694 item = configList->findConfigItem(parent);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001695 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001696 configList->setSelected(item, true);
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001697 configList->scrollToItem(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001698 }
Mauro Carvalho Chehabc699eaa2020-06-30 08:26:36 +02001699
1700 menuList->setRootMenu(parent);
1701 menuList->clearSelection();
1702 list = menuList;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001703 }
1704 break;
1705 case fullMode:
1706 list = configList;
1707 break;
1708 default:
1709 break;
1710 }
1711
1712 if (list) {
1713 item = list->findConfigItem(menu);
1714 if (item) {
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +02001715 list->setSelected(item, true);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001716 list->scrollToItem(item);
1717 list->setFocus();
Mauro Carvalho Chehab8a3b6e52020-06-30 08:48:35 +02001718 helpText->setInfo(menu);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001719 }
1720 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001721}
1722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723void ConfigMainWindow::listFocusChanged(void)
1724{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001725 if (menuList->mode == menuMode)
1726 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727}
1728
1729void ConfigMainWindow::goBack(void)
1730{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001731 if (configList->rootEntry == &rootmenu)
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001732 return;
1733
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001734 configList->setParentMenu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735}
1736
1737void ConfigMainWindow::showSingleView(void)
1738{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001739 singleViewAction->setEnabled(false);
1740 singleViewAction->setChecked(true);
1741 splitViewAction->setEnabled(true);
1742 splitViewAction->setChecked(false);
1743 fullViewAction->setEnabled(true);
1744 fullViewAction->setChecked(false);
1745
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001746 backAction->setEnabled(true);
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001749 menuList->setRootMenu(0);
1750 configList->mode = singleMode;
1751 if (configList->rootEntry == &rootmenu)
1752 configList->updateListAll();
1753 else
1754 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 configList->setFocus();
1756}
1757
1758void ConfigMainWindow::showSplitView(void)
1759{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001760 singleViewAction->setEnabled(true);
1761 singleViewAction->setChecked(false);
1762 splitViewAction->setEnabled(false);
1763 splitViewAction->setChecked(true);
1764 fullViewAction->setEnabled(true);
1765 fullViewAction->setChecked(false);
1766
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001767 backAction->setEnabled(false);
1768
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001769 configList->mode = menuMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001770 if (configList->rootEntry == &rootmenu)
1771 configList->updateListAll();
1772 else
1773 configList->setRootMenu(&rootmenu);
1774 configList->setAllOpen(true);
1775 configApp->processEvents();
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +02001776 menuList->mode = symbolMode;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001777 menuList->setRootMenu(&rootmenu);
1778 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 menuView->show();
1780 menuList->setFocus();
1781}
1782
1783void ConfigMainWindow::showFullView(void)
1784{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001785 singleViewAction->setEnabled(true);
1786 singleViewAction->setChecked(false);
1787 splitViewAction->setEnabled(true);
1788 splitViewAction->setChecked(false);
1789 fullViewAction->setEnabled(false);
1790 fullViewAction->setChecked(true);
1791
Mauro Carvalho Chehabaf737b4d2020-06-30 08:26:39 +02001792 backAction->setEnabled(false);
1793
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001795 menuList->setRootMenu(0);
1796 configList->mode = fullMode;
1797 if (configList->rootEntry == &rootmenu)
1798 configList->updateListAll();
1799 else
1800 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 configList->setFocus();
1802}
1803
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804/*
1805 * ask for saving configuration before quitting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 */
1807void ConfigMainWindow::closeEvent(QCloseEvent* e)
1808{
Karsten Wieseb3214292006-12-13 00:34:06 -08001809 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 e->accept();
1811 return;
1812 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001813 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001815 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1816 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1817 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 switch (mb.exec()) {
1819 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001820 if (saveConfig())
1821 e->accept();
1822 else
1823 e->ignore();
1824 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 case QMessageBox::No:
1826 e->accept();
1827 break;
1828 case QMessageBox::Cancel:
1829 e->ignore();
1830 break;
1831 }
1832}
1833
1834void ConfigMainWindow::showIntro(void)
1835{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001836 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 "For each option, a blank box indicates the feature is disabled, a check\n"
1838 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1839 "as a module. Clicking on the box will cycle through the three states.\n\n"
1840 "If you do not see an option (e.g., a device driver) that you believe\n"
1841 "should be present, try turning on Show All Options under the Options menu.\n"
1842 "Although there is no cross reference yet to help you figure out what other\n"
1843 "options must be enabled to support the option you are interested in, you can\n"
1844 "still view the help of a grayed-out option.\n\n"
1845 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001846 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 QMessageBox::information(this, "qconf", str);
1849}
1850
1851void ConfigMainWindow::showAbout(void)
1852{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001853 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001854 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001855 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
1857 QMessageBox::information(this, "qconf", str);
1858}
1859
1860void ConfigMainWindow::saveSettings(void)
1861{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001862 configSettings->setValue("/window x", pos().x());
1863 configSettings->setValue("/window y", pos().y());
1864 configSettings->setValue("/window width", size().width());
1865 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
1867 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001868 switch(configList->mode) {
1869 case singleMode :
1870 entry = "single";
1871 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001873 case symbolMode :
1874 entry = "split";
1875 break;
1876
1877 case fullMode :
1878 entry = "full";
1879 break;
1880
1881 default:
1882 break;
1883 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001884 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Roman Zippel7fc925f2006-06-08 22:12:46 -07001886 configSettings->writeSizes("/split1", split1->sizes());
1887 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888}
1889
Karsten Wiese3b354c52006-12-13 00:34:08 -08001890void ConfigMainWindow::conf_changed(void)
1891{
1892 if (saveAction)
1893 saveAction->setEnabled(conf_get_changed());
1894}
1895
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896void fixup_rootmenu(struct menu *menu)
1897{
1898 struct menu *child;
1899 static int menu_cnt = 0;
1900
1901 menu->flags |= MENU_ROOT;
1902 for (child = menu->list; child; child = child->next) {
1903 if (child->prompt && child->prompt->type == P_MENU) {
1904 menu_cnt++;
1905 fixup_rootmenu(child);
1906 menu_cnt--;
1907 } else if (!menu_cnt)
1908 fixup_rootmenu(child);
1909 }
1910}
1911
1912static const char *progname;
1913
1914static void usage(void)
1915{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001916 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 exit(0);
1918}
1919
1920int main(int ac, char** av)
1921{
1922 ConfigMainWindow* v;
1923 const char *name;
1924
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 progname = av[0];
1926 configApp = new QApplication(ac, av);
1927 if (ac > 1 && av[1][0] == '-') {
1928 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001929 case 's':
1930 conf_set_message_callback(NULL);
1931 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 case 'h':
1933 case '?':
1934 usage();
1935 }
1936 name = av[2];
1937 } else
1938 name = av[1];
1939 if (!name)
1940 usage();
1941
1942 conf_parse(name);
1943 fixup_rootmenu(&rootmenu);
1944 conf_read(NULL);
1945 //zconfdump(stdout);
1946
Roman Zippel7fc925f2006-06-08 22:12:46 -07001947 configSettings = new ConfigSettings();
1948 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 v = new ConfigMainWindow();
1950
1951 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1953 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001954 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 configApp->exec();
1956
Roman Zippel7fc925f2006-06-08 22:12:46 -07001957 configSettings->endGroup();
1958 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001959 delete v;
1960 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001961
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 return 0;
1963}