blob: 3ea255a66c55c70482034df3f3a764bbf6d0a1db [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
Alexander Stein133c5f72010-08-31 17:34:37 +02007#include <qglobal.h>
8
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07009#include <QMainWindow>
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070010#include <QList>
Boris Barbulovski924bbb52015-09-22 11:36:06 -070011#include <qtextbrowser.h>
Boris Barbulovski85eaf282015-09-22 11:36:03 -070012#include <QAction>
Boris Barbulovskibea00772015-09-22 11:36:04 -070013#include <QFileDialog>
Boris Barbulovski76bede82015-09-22 11:36:07 -070014#include <QMenu>
Alexander Stein133c5f72010-08-31 17:34:37 +020015
16#include <qapplication.h>
Markus Heidelberg8d90c972009-05-18 01:36:52 +020017#include <qdesktopwidget.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <qtoolbar.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070019#include <qlayout.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <qsplitter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <qlineedit.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070022#include <qlabel.h>
23#include <qpushbutton.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <qmenubar.h>
25#include <qmessagebox.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <qregexp.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020027#include <qevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#include <stdlib.h>
30
31#include "lkc.h"
32#include "qconf.h"
33
34#include "qconf.moc"
Masahiro Yamada3b541978562018-12-21 17:33:07 +090035#include "images.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070039static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Boris Barbulovski85eaf282015-09-22 11:36:03 -070041QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080042
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070043static inline QString qgettext(const char* str)
44{
Sam Ravnborg694c49a2018-05-22 21:36:12 +020045 return QString::fromLocal8Bit(str);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070046}
47
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010048ConfigSettings::ConfigSettings()
49 : QSettings("kernel.org", "qconf")
50{
51}
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/**
54 * Reads a list of integer values from the application settings.
55 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070056QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070058 QList<int> result;
Li Zefanc1f96f02010-05-07 13:58:04 +080059
Boris Barbulovski83c3a1b2016-11-30 14:57:55 -080060 if (contains(key))
61 {
62 QStringList entryList = value(key).toStringList();
63 QStringList::Iterator it;
64
65 for (it = entryList.begin(); it != entryList.end(); ++it)
66 result.push_back((*it).toInt());
67
68 *ok = true;
69 }
70 else
71 *ok = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 return result;
74}
75
76/**
77 * Writes a list of integer values to the application settings.
78 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070079bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070082 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 for (it = value.begin(); it != value.end(); ++it)
85 stringList.push_back(QString::number(*it));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070086 setValue(key, stringList);
Boris Barbulovski59e56442015-09-22 11:36:18 -070087
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070088 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Boris Barbulovski59e56442015-09-22 11:36:18 -070091
92/*
93 * set the new data
94 * TODO check the value
95 */
96void ConfigItem::okRename(int col)
97{
98}
99
100/*
101 * update the displayed of a menu entry
102 */
103void ConfigItem::updateMenu(void)
104{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700105 ConfigList* list;
106 struct symbol* sym;
107 struct property *prop;
108 QString prompt;
109 int type;
110 tristate expr;
111
112 list = listView();
113 if (goParent) {
114 setPixmap(promptColIdx, list->menuBackPix);
115 prompt = "..";
116 goto set_prompt;
117 }
118
119 sym = menu->sym;
120 prop = menu->prompt;
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200121 prompt = qgettext(menu_get_prompt(menu));
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700122
123 if (prop) switch (prop->type) {
124 case P_MENU:
125 if (list->mode == singleMode || list->mode == symbolMode) {
126 /* a menuconfig entry is displayed differently
127 * depending whether it's at the view root or a child.
128 */
129 if (sym && list->rootEntry == menu)
130 break;
131 setPixmap(promptColIdx, list->menuPix);
132 } else {
133 if (sym)
134 break;
135 setPixmap(promptColIdx, QIcon());
136 }
137 goto set_prompt;
138 case P_COMMENT:
139 setPixmap(promptColIdx, QIcon());
140 goto set_prompt;
141 default:
142 ;
143 }
144 if (!sym)
145 goto set_prompt;
146
147 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
148
149 type = sym_get_type(sym);
150 switch (type) {
151 case S_BOOLEAN:
152 case S_TRISTATE:
153 char ch;
154
Marco Ammonbaa23ec2019-07-04 12:50:41 +0200155 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700156 setPixmap(promptColIdx, QIcon());
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200157 setText(noColIdx, QString());
158 setText(modColIdx, QString());
159 setText(yesColIdx, QString());
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700160 break;
161 }
162 expr = sym_get_tristate_value(sym);
163 switch (expr) {
164 case yes:
165 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
166 setPixmap(promptColIdx, list->choiceYesPix);
167 else
168 setPixmap(promptColIdx, list->symbolYesPix);
169 setText(yesColIdx, "Y");
170 ch = 'Y';
171 break;
172 case mod:
173 setPixmap(promptColIdx, list->symbolModPix);
174 setText(modColIdx, "M");
175 ch = 'M';
176 break;
177 default:
178 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
179 setPixmap(promptColIdx, list->choiceNoPix);
180 else
181 setPixmap(promptColIdx, list->symbolNoPix);
182 setText(noColIdx, "N");
183 ch = 'N';
184 break;
185 }
186 if (expr != no)
187 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
188 if (expr != mod)
189 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
190 if (expr != yes)
191 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
192
193 setText(dataColIdx, QChar(ch));
194 break;
195 case S_INT:
196 case S_HEX:
197 case S_STRING:
198 const char* data;
199
200 data = sym_get_string_value(sym);
201
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700202 setText(dataColIdx, data);
203 if (type == S_STRING)
204 prompt = QString("%1: %2").arg(prompt).arg(data);
205 else
206 prompt = QString("(%2) %1").arg(prompt).arg(data);
207 break;
208 }
209 if (!sym_has_value(sym) && visible)
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200210 prompt += " (NEW)";
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700211set_prompt:
212 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700213}
214
215void ConfigItem::testUpdateMenu(bool v)
216{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700217 ConfigItem* i;
218
219 visible = v;
220 if (!menu)
221 return;
222
223 sym_calc_value(menu->sym);
224 if (menu->flags & MENU_CHANGED) {
225 /* the menu entry changed, so update all list items */
226 menu->flags &= ~MENU_CHANGED;
227 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
228 i->updateMenu();
229 } else if (listView()->updateAll)
230 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700231}
232
233
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700234/*
235 * construct a menu entry
236 */
237void ConfigItem::init(void)
238{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700239 if (menu) {
240 ConfigList* list = listView();
241 nextItem = (ConfigItem*)menu->data;
242 menu->data = this;
243
244 if (list->mode != fullMode)
245 setExpanded(true);
246 sym_calc_value(menu->sym);
247 }
248 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700249}
250
251/*
252 * destruct a menu entry
253 */
254ConfigItem::~ConfigItem(void)
255{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700256 if (menu) {
257 ConfigItem** ip = (ConfigItem**)&menu->data;
258 for (; *ip; ip = &(*ip)->nextItem) {
259 if (*ip == this) {
260 *ip = nextItem;
261 break;
262 }
263 }
264 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700265}
266
Roman Zippel43bf6122006-06-08 22:12:45 -0700267ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
268 : Parent(parent)
269{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700270 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700271}
272
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700273void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700276 if (sym_get_string_value(item->menu->sym))
277 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
278 else
Mauro Carvalho Chehabcf497b92020-04-02 11:27:58 +0200279 setText(QString());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 Parent::show();
281 setFocus();
282}
283
284void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
285{
286 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200287 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200289 case Qt::Key_Return:
290 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700291 sym_set_string_value(item->menu->sym, text().toLatin1());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 parent()->updateList(item);
293 break;
294 default:
295 Parent::keyPressEvent(e);
296 return;
297 }
298 e->accept();
299 parent()->list->setFocus();
300 hide();
301}
302
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700303ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700304 : Parent(p),
305 updateAll(false),
306 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
307 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
308 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Boris Barbulovskidbf62932015-09-22 11:36:26 -0700309 showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),
Boris Barbulovski59e56442015-09-22 11:36:18 -0700310 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700311{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700312 setObjectName(name);
Boris Barbulovskia5225e92015-09-22 11:36:29 -0700313 setSortingEnabled(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700314 setRootIsDecorated(true);
315
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700316 setVerticalScrollMode(ScrollPerPixel);
317 setHorizontalScrollMode(ScrollPerPixel);
318
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200319 setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value");
Boris Barbulovskia52cb322015-09-22 11:36:24 -0700320
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700321 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700322 SLOT(updateSelection(void)));
323
324 if (name) {
325 configSettings->beginGroup(name);
326 showName = configSettings->value("/showName", false).toBool();
327 showRange = configSettings->value("/showRange", false).toBool();
328 showData = configSettings->value("/showData", false).toBool();
329 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
330 configSettings->endGroup();
331 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
332 }
333
334 addColumn(promptColIdx);
335
336 reinit();
337}
338
339bool ConfigList::menuSkip(struct menu *menu)
340{
341 if (optMode == normalOpt && menu_is_visible(menu))
342 return false;
343 if (optMode == promptOpt && menu_has_prompt(menu))
344 return false;
345 if (optMode == allOpt)
346 return false;
347 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700348}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700349
350void ConfigList::reinit(void)
351{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700352 removeColumn(dataColIdx);
353 removeColumn(yesColIdx);
354 removeColumn(modColIdx);
355 removeColumn(noColIdx);
356 removeColumn(nameColIdx);
357
358 if (showName)
359 addColumn(nameColIdx);
360 if (showRange) {
361 addColumn(noColIdx);
362 addColumn(modColIdx);
363 addColumn(yesColIdx);
364 }
365 if (showData)
366 addColumn(dataColIdx);
367
368 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700369}
370
371void ConfigList::saveSettings(void)
372{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700373 if (!objectName().isEmpty()) {
374 configSettings->beginGroup(objectName());
375 configSettings->setValue("/showName", showName);
376 configSettings->setValue("/showRange", showRange);
377 configSettings->setValue("/showData", showData);
378 configSettings->setValue("/optionMode", (int)optMode);
379 configSettings->endGroup();
380 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700381}
382
383ConfigItem* ConfigList::findConfigItem(struct menu *menu)
384{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700385 ConfigItem* item = (ConfigItem*)menu->data;
386
387 for (; item; item = item->nextItem) {
388 if (this == item->listView())
389 break;
390 }
391
392 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700393}
394
395void ConfigList::updateSelection(void)
396{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700397 struct menu *menu;
398 enum prop_type type;
399
Boris Barbulovskibe596aa2015-09-22 11:36:28 -0700400 if (selectedItems().count() == 0)
401 return;
402
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700403 ConfigItem* item = (ConfigItem*)selectedItems().first();
404 if (!item)
405 return;
406
407 menu = item->menu;
408 emit menuChanged(menu);
409 if (!menu)
410 return;
411 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
412 if (mode == menuMode && type == P_MENU)
413 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700414}
415
416void ConfigList::updateList(ConfigItem* item)
417{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700418 ConfigItem* last = 0;
419
420 if (!rootEntry) {
421 if (mode != listMode)
422 goto update;
423 QTreeWidgetItemIterator it(this);
424 ConfigItem* item;
425
426 while (*it) {
427 item = (ConfigItem*)(*it);
428 if (!item->menu)
429 continue;
430 item->testUpdateMenu(menu_is_visible(item->menu));
431
432 ++it;
433 }
434 return;
435 }
436
437 if (rootEntry != &rootmenu && (mode == singleMode ||
438 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
Boris Barbulovskiee7298f2015-09-22 11:36:37 -0700439 item = (ConfigItem *)topLevelItem(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700440 if (!item)
441 item = new ConfigItem(this, 0, true);
442 last = item;
443 }
444 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
445 rootEntry->sym && rootEntry->prompt) {
446 item = last ? last->nextSibling() : firstChild();
447 if (!item)
448 item = new ConfigItem(this, last, rootEntry, true);
449 else
450 item->testUpdateMenu(true);
451
452 updateMenuList(item, rootEntry);
453 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700454 resizeColumnToContents(0);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700455 return;
456 }
457update:
458 updateMenuList(this, rootEntry);
459 update();
Boris Barbulovskif999cc02015-09-22 11:36:31 -0700460 resizeColumnToContents(0);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700461}
462
463void ConfigList::setValue(ConfigItem* item, tristate val)
464{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700465 struct symbol* sym;
466 int type;
467 tristate oldval;
468
469 sym = item->menu ? item->menu->sym : 0;
470 if (!sym)
471 return;
472
473 type = sym_get_type(sym);
474 switch (type) {
475 case S_BOOLEAN:
476 case S_TRISTATE:
477 oldval = sym_get_tristate_value(sym);
478
479 if (!sym_set_tristate_value(sym, val))
480 return;
481 if (oldval == no && item->menu->list)
482 item->setExpanded(true);
483 parent()->updateList(item);
484 break;
485 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700486}
487
488void ConfigList::changeValue(ConfigItem* item)
489{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700490 struct symbol* sym;
491 struct menu* menu;
492 int type, oldexpr, newexpr;
493
494 menu = item->menu;
495 if (!menu)
496 return;
497 sym = menu->sym;
498 if (!sym) {
499 if (item->menu->list)
500 item->setExpanded(!item->isExpanded());
501 return;
502 }
503
504 type = sym_get_type(sym);
505 switch (type) {
506 case S_BOOLEAN:
507 case S_TRISTATE:
508 oldexpr = sym_get_tristate_value(sym);
509 newexpr = sym_toggle_tristate_value(sym);
510 if (item->menu->list) {
511 if (oldexpr == newexpr)
512 item->setExpanded(!item->isExpanded());
513 else if (oldexpr == no)
514 item->setExpanded(true);
515 }
516 if (oldexpr != newexpr)
517 parent()->updateList(item);
518 break;
519 case S_INT:
520 case S_HEX:
521 case S_STRING:
Boris Barbulovskie336b9f2015-09-22 11:36:34 -0700522 parent()->lineEdit->show(item);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700523 break;
524 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700525}
526
527void ConfigList::setRootMenu(struct menu *menu)
528{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700529 enum prop_type type;
530
531 if (rootEntry == menu)
532 return;
533 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
534 if (type != P_MENU)
535 return;
536 updateMenuList(this, 0);
537 rootEntry = menu;
538 updateListAll();
539 if (currentItem()) {
540 currentItem()->setSelected(hasFocus());
541 scrollToItem(currentItem());
542 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700543}
544
545void ConfigList::setParentMenu(void)
546{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700547 ConfigItem* item;
548 struct menu *oldroot;
549
550 oldroot = rootEntry;
551 if (rootEntry == &rootmenu)
552 return;
553 setRootMenu(menu_get_parent_menu(rootEntry->parent));
554
555 QTreeWidgetItemIterator it(this);
556 while (*it) {
557 item = (ConfigItem *)(*it);
558 if (item->menu == oldroot) {
559 setCurrentItem(item);
560 scrollToItem(item);
561 break;
562 }
563
564 ++it;
565 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700566}
567
568/*
569 * update all the children of a menu entry
570 * removes/adds the entries from the parent widget as necessary
571 *
572 * parent: either the menu list widget or a menu entry widget
573 * menu: entry to be updated
574 */
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700575void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700576{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700577 struct menu* child;
578 ConfigItem* item;
579 ConfigItem* last;
580 bool visible;
581 enum prop_type type;
582
583 if (!menu) {
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700584 while (parent->childCount() > 0)
585 {
586 delete parent->takeChild(0);
587 }
588
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700589 return;
590 }
591
592 last = parent->firstChild();
593 if (last && !last->goParent)
594 last = 0;
595 for (child = menu->list; child; child = child->next) {
596 item = last ? last->nextSibling() : parent->firstChild();
597 type = child->prompt ? child->prompt->type : P_UNKNOWN;
598
599 switch (mode) {
600 case menuMode:
601 if (!(child->flags & MENU_ROOT))
602 goto hide;
603 break;
604 case symbolMode:
605 if (child->flags & MENU_ROOT)
606 goto hide;
607 break;
608 default:
609 break;
610 }
611
612 visible = menu_is_visible(child);
613 if (!menuSkip(child)) {
614 if (!child->sym && !child->list && !child->prompt)
615 continue;
616 if (!item || item->menu != child)
617 item = new ConfigItem(parent, last, child, visible);
618 else
619 item->testUpdateMenu(visible);
620
621 if (mode == fullMode || mode == menuMode || type != P_MENU)
622 updateMenuList(item, child);
623 else
624 updateMenuList(item, 0);
625 last = item;
626 continue;
627 }
628 hide:
629 if (item && item->menu == child) {
630 last = parent->firstChild();
631 if (last == item)
632 last = 0;
633 else while (last->nextSibling() != item)
634 last = last->nextSibling();
635 delete item;
636 }
637 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700638}
639
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700640void ConfigList::updateMenuList(ConfigList *parent, struct menu* menu)
641{
642 struct menu* child;
643 ConfigItem* item;
644 ConfigItem* last;
645 bool visible;
646 enum prop_type type;
647
648 if (!menu) {
649 while (parent->topLevelItemCount() > 0)
650 {
651 delete parent->takeTopLevelItem(0);
652 }
653
654 return;
655 }
656
657 last = (ConfigItem*)parent->topLevelItem(0);
658 if (last && !last->goParent)
659 last = 0;
660 for (child = menu->list; child; child = child->next) {
661 item = last ? last->nextSibling() : (ConfigItem*)parent->topLevelItem(0);
662 type = child->prompt ? child->prompt->type : P_UNKNOWN;
663
664 switch (mode) {
665 case menuMode:
666 if (!(child->flags & MENU_ROOT))
667 goto hide;
668 break;
669 case symbolMode:
670 if (child->flags & MENU_ROOT)
671 goto hide;
672 break;
673 default:
674 break;
675 }
676
677 visible = menu_is_visible(child);
678 if (!menuSkip(child)) {
679 if (!child->sym && !child->list && !child->prompt)
680 continue;
681 if (!item || item->menu != child)
682 item = new ConfigItem(parent, last, child, visible);
683 else
684 item->testUpdateMenu(visible);
685
686 if (mode == fullMode || mode == menuMode || type != P_MENU)
687 updateMenuList(item, child);
688 else
689 updateMenuList(item, 0);
690 last = item;
691 continue;
692 }
693 hide:
694 if (item && item->menu == child) {
695 last = (ConfigItem*)parent->topLevelItem(0);
696 if (last == item)
697 last = 0;
698 else while (last->nextSibling() != item)
699 last = last->nextSibling();
700 delete item;
701 }
702 }
703}
704
Boris Barbulovski59e56442015-09-22 11:36:18 -0700705void ConfigList::keyPressEvent(QKeyEvent* ev)
706{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700707 QTreeWidgetItem* i = currentItem();
708 ConfigItem* item;
709 struct menu *menu;
710 enum prop_type type;
711
712 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
713 emit parentSelected();
714 ev->accept();
715 return;
716 }
717
718 if (!i) {
719 Parent::keyPressEvent(ev);
720 return;
721 }
722 item = (ConfigItem*)i;
723
724 switch (ev->key()) {
725 case Qt::Key_Return:
726 case Qt::Key_Enter:
727 if (item->goParent) {
728 emit parentSelected();
729 break;
730 }
731 menu = item->menu;
732 if (!menu)
733 break;
734 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
735 if (type == P_MENU && rootEntry != menu &&
736 mode != fullMode && mode != menuMode) {
737 emit menuSelected(menu);
738 break;
739 }
740 case Qt::Key_Space:
741 changeValue(item);
742 break;
743 case Qt::Key_N:
744 setValue(item, no);
745 break;
746 case Qt::Key_M:
747 setValue(item, mod);
748 break;
749 case Qt::Key_Y:
750 setValue(item, yes);
751 break;
752 default:
753 Parent::keyPressEvent(ev);
754 return;
755 }
756 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700757}
758
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700759void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700760{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700761 //QPoint p(contentsToViewport(e->pos()));
762 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
763 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700764}
765
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700766void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700767{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700768 QPoint p = e->pos();
769 ConfigItem* item = (ConfigItem*)itemAt(p);
770 struct menu *menu;
771 enum prop_type ptype;
772 QIcon icon;
773 int idx, x;
774
775 if (!item)
776 goto skip;
777
778 menu = item->menu;
779 x = header()->offset() + p.x();
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700780 idx = header()->logicalIndexAt(x);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700781 switch (idx) {
782 case promptColIdx:
783 icon = item->pixmap(promptColIdx);
Boris Barbulovski76d53cb2015-09-22 11:36:35 -0700784 if (!icon.isNull()) {
785 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
786 if (x >= off && x < off + icon.availableSizes().first().width()) {
787 if (item->goParent) {
788 emit parentSelected();
789 break;
790 } else if (!menu)
791 break;
792 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
793 if (ptype == P_MENU && rootEntry != menu &&
794 mode != fullMode && mode != menuMode)
795 emit menuSelected(menu);
796 else
797 changeValue(item);
798 }
799 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700800 break;
801 case noColIdx:
802 setValue(item, no);
803 break;
804 case modColIdx:
805 setValue(item, mod);
806 break;
807 case yesColIdx:
808 setValue(item, yes);
809 break;
810 case dataColIdx:
811 changeValue(item);
812 break;
813 }
814
815skip:
816 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
817 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700818}
819
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700820void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700821{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700822 //QPoint p(contentsToViewport(e->pos()));
823 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
824 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700825}
826
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700827void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700828{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700829 QPoint p = e->pos(); // TODO: Check if this works(was contentsToViewport).
830 ConfigItem* item = (ConfigItem*)itemAt(p);
831 struct menu *menu;
832 enum prop_type ptype;
833
834 if (!item)
835 goto skip;
836 if (item->goParent) {
837 emit parentSelected();
838 goto skip;
839 }
840 menu = item->menu;
841 if (!menu)
842 goto skip;
843 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
844 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
845 emit menuSelected(menu);
846 else if (menu->sym)
847 changeValue(item);
848
849skip:
850 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
851 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700852}
853
854void ConfigList::focusInEvent(QFocusEvent *e)
855{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700856 struct menu *menu = NULL;
857
858 Parent::focusInEvent(e);
859
860 ConfigItem* item = (ConfigItem *)currentItem();
861 if (item) {
862 item->setSelected(true);
863 menu = item->menu;
864 }
865 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700866}
867
868void ConfigList::contextMenuEvent(QContextMenuEvent *e)
869{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700870 if (e->y() <= header()->geometry().bottom()) {
871 if (!headerPopup) {
872 QAction *action;
873
874 headerPopup = new QMenu(this);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200875 action = new QAction("Show Name", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700876 action->setCheckable(true);
877 connect(action, SIGNAL(toggled(bool)),
878 parent(), SLOT(setShowName(bool)));
879 connect(parent(), SIGNAL(showNameChanged(bool)),
880 action, SLOT(setOn(bool)));
881 action->setChecked(showName);
882 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200883 action = new QAction("Show Range", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700884 action->setCheckable(true);
885 connect(action, SIGNAL(toggled(bool)),
886 parent(), SLOT(setShowRange(bool)));
887 connect(parent(), SIGNAL(showRangeChanged(bool)),
888 action, SLOT(setOn(bool)));
889 action->setChecked(showRange);
890 headerPopup->addAction(action);
Sam Ravnborg694c49a2018-05-22 21:36:12 +0200891 action = new QAction("Show Data", this);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700892 action->setCheckable(true);
893 connect(action, SIGNAL(toggled(bool)),
894 parent(), SLOT(setShowData(bool)));
895 connect(parent(), SIGNAL(showDataChanged(bool)),
896 action, SLOT(setOn(bool)));
897 action->setChecked(showData);
898 headerPopup->addAction(action);
899 }
900 headerPopup->exec(e->globalPos());
901 e->accept();
902 } else
903 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700904}
905
Li Zefan39a48972010-05-10 16:33:41 +0800906ConfigView*ConfigView::viewList;
907QAction *ConfigView::showNormalAction;
908QAction *ConfigView::showAllAction;
909QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Roman Zippel7fc925f2006-06-08 22:12:46 -0700911ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700912 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700914 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700915 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700916 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700917
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700918 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700919 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 lineEdit = new ConfigLineEdit(this);
921 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700922 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 this->nextView = viewList;
925 viewList = this;
926}
927
928ConfigView::~ConfigView(void)
929{
930 ConfigView** vp;
931
932 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
933 if (*vp == this) {
934 *vp = nextView;
935 break;
936 }
937 }
938}
939
Li Zefan39a48972010-05-10 16:33:41 +0800940void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700941{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700942 if (act == showNormalAction)
943 list->optMode = normalOpt;
944 else if (act == showAllAction)
945 list->optMode = allOpt;
946 else
947 list->optMode = promptOpt;
948
949 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700950}
951
952void ConfigView::setShowName(bool b)
953{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700954 if (list->showName != b) {
955 list->showName = b;
956 list->reinit();
957 emit showNameChanged(b);
958 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700959}
960
961void ConfigView::setShowRange(bool b)
962{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700963 if (list->showRange != b) {
964 list->showRange = b;
965 list->reinit();
966 emit showRangeChanged(b);
967 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700968}
969
970void ConfigView::setShowData(bool b)
971{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700972 if (list->showData != b) {
973 list->showData = b;
974 list->reinit();
975 emit showDataChanged(b);
976 }
977}
978
979void ConfigList::setAllOpen(bool open)
980{
981 QTreeWidgetItemIterator it(this);
982
983 while (*it) {
984 (*it)->setExpanded(open);
985
986 ++it;
987 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700988}
989
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700990void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700991{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700992 ConfigView* v;
993
994 for (v = viewList; v; v = v->nextView)
995 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
998void ConfigView::updateListAll(void)
999{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001000 ConfigView* v;
1001
1002 for (v = viewList; v; v = v->nextView)
1003 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
Roman Zippel43bf6122006-06-08 22:12:45 -07001006ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001007 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -07001008{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001009 setObjectName(name);
1010
1011
1012 if (!objectName().isEmpty()) {
1013 configSettings->beginGroup(objectName());
Boris Barbulovskie0393032016-11-30 14:57:52 -08001014 setShowDebug(configSettings->value("/showDebug", false).toBool());
Roman Zippel7fc925f2006-06-08 22:12:46 -07001015 configSettings->endGroup();
1016 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1017 }
1018}
1019
1020void ConfigInfoView::saveSettings(void)
1021{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001022 if (!objectName().isEmpty()) {
1023 configSettings->beginGroup(objectName());
1024 configSettings->setValue("/showDebug", showDebug());
1025 configSettings->endGroup();
1026 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001027}
1028
1029void ConfigInfoView::setShowDebug(bool b)
1030{
1031 if (_showDebug != b) {
1032 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +02001033 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001034 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -07001035 else if (sym)
1036 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -07001037 emit showDebugChanged(b);
1038 }
1039}
1040
1041void ConfigInfoView::setInfo(struct menu *m)
1042{
Alexander Stein133c5f72010-08-31 17:34:37 +02001043 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -07001044 return;
Alexander Stein133c5f72010-08-31 17:34:37 +02001045 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -08001046 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +02001047 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -07001048 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -08001049 else
Roman Zippel43bf6122006-06-08 22:12:45 -07001050 menuInfo();
1051}
1052
Roman Zippelab45d192006-06-08 22:12:47 -07001053void ConfigInfoView::symbolInfo(void)
1054{
1055 QString str;
1056
1057 str += "<big>Symbol: <b>";
1058 str += print_filter(sym->name);
1059 str += "</b></big><br><br>value: ";
1060 str += print_filter(sym_get_string_value(sym));
1061 str += "<br>visibility: ";
1062 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1063 str += "<br>";
1064 str += debug_info(sym);
1065
1066 setText(str);
1067}
1068
Roman Zippel43bf6122006-06-08 22:12:45 -07001069void ConfigInfoView::menuInfo(void)
1070{
1071 struct symbol* sym;
1072 QString head, debug, help;
1073
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) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001077 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001078 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001079 head += "</b></big>";
1080 if (sym->name) {
1081 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001082 if (showDebug())
1083 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001084 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001085 if (showDebug())
1086 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001087 head += ")";
1088 }
1089 } else if (sym->name) {
1090 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001091 if (showDebug())
1092 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001093 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001094 if (showDebug())
1095 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001096 head += "</b></big>";
1097 }
1098 head += "<br><br>";
1099
1100 if (showDebug())
1101 debug = debug_info(sym);
1102
Cheng Renquand74c15f2009-07-12 16:11:47 +08001103 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001104 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001105 help = print_filter(str_get(&help_gstr));
1106 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001107 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001108 head += "<big><b>";
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001109 head += print_filter(_menu->prompt->text);
Roman Zippel43bf6122006-06-08 22:12:45 -07001110 head += "</b></big><br><br>";
1111 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001112 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001113 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001114 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001115 debug += "<br><br>";
1116 }
1117 }
1118 }
1119 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001120 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001121
1122 setText(head + debug + help);
1123}
1124
1125QString ConfigInfoView::debug_info(struct symbol *sym)
1126{
1127 QString debug;
1128
1129 debug += "type: ";
1130 debug += print_filter(sym_type_name(sym->type));
1131 if (sym_is_choice(sym))
1132 debug += " (choice)";
1133 debug += "<br>";
1134 if (sym->rev_dep.expr) {
1135 debug += "reverse dep: ";
1136 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1137 debug += "<br>";
1138 }
1139 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1140 switch (prop->type) {
1141 case P_PROMPT:
1142 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -07001143 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001144 debug += print_filter(prop->text);
Roman Zippelab45d192006-06-08 22:12:47 -07001145 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001146 break;
1147 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001148 case P_SELECT:
1149 case P_RANGE:
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)) {
1215 *text += QString().sprintf("<a href=\"s%p\">", sym);
1216 *text += str2;
1217 *text += "</a>";
1218 } else
1219 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001220}
1221
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001222QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001223{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001224 QMenu* popup = Parent::createStandardContextMenu(pos);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001225 QAction* action = new QAction("Show Debug Info", popup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001226 action->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001227 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1228 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001229 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001230 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001231 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001232 return popup;
1233}
1234
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001235void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001236{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001237 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001238}
1239
Marco Costalba63431e72006-10-05 19:12:59 +02001240ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001241 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001242{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001243 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001244 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001245
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001246 QVBoxLayout* layout1 = new QVBoxLayout(this);
1247 layout1->setContentsMargins(11, 11, 11, 11);
1248 layout1->setSpacing(6);
1249 QHBoxLayout* layout2 = new QHBoxLayout(0);
1250 layout2->setContentsMargins(0, 0, 0, 0);
1251 layout2->setSpacing(6);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001252 layout2->addWidget(new QLabel("Find:", this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001253 editField = new QLineEdit(this);
1254 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1255 layout2->addWidget(editField);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001256 searchButton = new QPushButton("Search", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001257 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001258 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1259 layout2->addWidget(searchButton);
1260 layout1->addLayout(layout2);
1261
Roman Zippel7fc925f2006-06-08 22:12:46 -07001262 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001263 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001264 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001265 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001266 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001267 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1268 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001269 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1270 parent, SLOT(setMenuLink(struct menu *)));
1271
Roman Zippel43bf6122006-06-08 22:12:45 -07001272 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001273
1274 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001275 QVariant x, y;
1276 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001277 bool ok;
1278
1279 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001280 width = configSettings->value("/window width", parent->width() / 2).toInt();
1281 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001282 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001283 x = configSettings->value("/window x");
1284 y = configSettings->value("/window y");
1285 if ((x.isValid())&&(y.isValid()))
1286 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001287 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001288 if (ok)
1289 split->setSizes(sizes);
1290 configSettings->endGroup();
1291 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1292 }
1293}
1294
1295void ConfigSearchWindow::saveSettings(void)
1296{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001297 if (!objectName().isEmpty()) {
1298 configSettings->beginGroup(objectName());
1299 configSettings->setValue("/window x", pos().x());
1300 configSettings->setValue("/window y", pos().y());
1301 configSettings->setValue("/window width", size().width());
1302 configSettings->setValue("/window height", size().height());
1303 configSettings->writeSizes("/split", split->sizes());
1304 configSettings->endGroup();
1305 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001306}
1307
1308void ConfigSearchWindow::search(void)
1309{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001310 struct symbol **p;
1311 struct property *prop;
1312 ConfigItem *lastItem = NULL;
1313
1314 free(result);
1315 list->list->clear();
1316 info->clear();
1317
1318 result = sym_re_search(editField->text().toLatin1());
1319 if (!result)
1320 return;
1321 for (p = result; *p; p++) {
1322 for_all_prompts((*p), prop)
1323 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1324 menu_is_visible(prop->menu));
1325 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001326}
1327
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328/*
1329 * Construct the complete config widget
1330 */
1331ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001332 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333{
1334 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001335 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001336 QVariant x, y;
1337 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001338 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001340 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001341 snprintf(title, sizeof(title), "%s%s",
1342 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001343 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001344 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001345 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001347 width = configSettings->value("/window width", d->width() - 64).toInt();
1348 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001350 x = configSettings->value("/window x");
1351 y = configSettings->value("/window y");
1352 if ((x.isValid())&&(y.isValid()))
1353 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001356 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 setCentralWidget(split1);
1358
Roman Zippel7fc925f2006-06-08 22:12:46 -07001359 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 menuList = menuView->list;
1361
1362 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001363 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -07001366 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 configList = configView->list;
1368
Roman Zippel7fc925f2006-06-08 22:12:46 -07001369 helpText = new ConfigInfoView(split2, "help");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 setTabOrder(configList, helpText);
1372 configList->setFocus();
1373
1374 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001375 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001376 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001378 backAction = new QAction(QPixmap(xpm_back), "Back", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001379 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001380 backAction->setEnabled(false);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001381 QAction *quitAction = new QAction("&Quit", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001382 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Boris Barbulovski92119932015-09-22 11:36:16 -07001383 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001384 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001385 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Boris Barbulovski92119932015-09-22 11:36:16 -07001386 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001387 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001388 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Boris Barbulovski92119932015-09-22 11:36:16 -07001389 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001390 conf_set_changed_callback(conf_changed);
1391 // Set saveAction's initial state
1392 conf_changed();
Masahiro Yamada87419082019-03-11 01:13:15 +09001393 configname = xstrdup(conf_get_configname());
1394
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001395 QAction *saveAsAction = new QAction("Save &As...", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001396 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001397 QAction *searchAction = new QAction("&Find", this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001398 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001399 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001400 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001401 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001402 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001403 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001404 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001405 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001406 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001407 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001408 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001410 QAction *showNameAction = new QAction("Show Name", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001411 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001412 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001413 showNameAction->setChecked(configView->showName());
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001414 QAction *showRangeAction = new QAction("Show Range", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001415 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001416 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001417 QAction *showDataAction = new QAction("Show Data", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001418 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001419 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001420
1421 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001422 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001423 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001424 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001425 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001426 SLOT(setOptionMode(QAction *)));
1427
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001428 configView->showNormalAction = new QAction("Show Normal Options", optGroup);
1429 configView->showAllAction = new QAction("Show All Options", optGroup);
1430 configView->showPromptAction = new QAction("Show Prompt Options", optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001431 configView->showNormalAction->setCheckable(true);
1432 configView->showAllAction->setCheckable(true);
1433 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001434
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001435 QAction *showDebugAction = new QAction("Show Debug Info", this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001436 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001437 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001438 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001440 QAction *showIntroAction = new QAction("Introduction", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001441 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001442 QAction *showAboutAction = new QAction("About", this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001443 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
1445 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001446 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001448 toolBar->addAction(loadAction);
1449 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001451 toolBar->addAction(singleViewAction);
1452 toolBar->addAction(splitViewAction);
1453 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
1455 // create config menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001456 QMenu* config = menu->addMenu("&File");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001457 config->addAction(loadAction);
1458 config->addAction(saveAction);
1459 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001460 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001461 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Shlomi Fish66e7c722007-02-14 00:32:58 -08001463 // create edit menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001464 QMenu* editMenu = menu->addMenu("&Edit");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001465 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001466
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 // create options menu
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001468 QMenu* optionMenu = menu->addMenu("&Option");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001469 optionMenu->addAction(showNameAction);
1470 optionMenu->addAction(showRangeAction);
1471 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001472 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001473 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001474 optionMenu->addSeparator();
Boris Barbulovskie0393032016-11-30 14:57:52 -08001475 optionMenu->addAction(showDebugAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001478 menu->addSeparator();
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001479 QMenu* helpMenu = menu->addMenu("&Help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001480 helpMenu->addAction(showIntroAction);
1481 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001483 connect(configList, SIGNAL(menuChanged(struct menu *)),
1484 helpText, SLOT(setInfo(struct menu *)));
1485 connect(configList, SIGNAL(menuSelected(struct menu *)),
1486 SLOT(changeMenu(struct menu *)));
1487 connect(configList, SIGNAL(parentSelected()),
1488 SLOT(goBack()));
1489 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1490 helpText, SLOT(setInfo(struct menu *)));
1491 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1492 SLOT(changeMenu(struct menu *)));
1493
1494 connect(configList, SIGNAL(gotFocus(struct menu *)),
1495 helpText, SLOT(setInfo(struct menu *)));
1496 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1497 helpText, SLOT(setInfo(struct menu *)));
1498 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1499 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001500 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1501 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001503 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 if (listMode == "single")
1505 showSingleView();
1506 else if (listMode == "full")
1507 showFullView();
1508 else /*if (listMode == "split")*/
1509 showSplitView();
1510
1511 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001512 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 if (ok)
1514 split1->setSizes(sizes);
1515
Roman Zippel7fc925f2006-06-08 22:12:46 -07001516 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 if (ok)
1518 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521void ConfigMainWindow::loadConfig(void)
1522{
Masahiro Yamada87419082019-03-11 01:13:15 +09001523 QString str;
1524 QByteArray ba;
1525 const char *name;
1526
1527 str = QFileDialog::getOpenFileName(this, "", configname);
1528 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001530
1531 ba = str.toLocal8Bit();
1532 name = ba.data();
1533
1534 if (conf_read(name))
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001535 QMessageBox::information(this, "qconf", "Unable to load configuration!");
Masahiro Yamada87419082019-03-11 01:13:15 +09001536
1537 free(configname);
1538 configname = xstrdup(name);
1539
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 ConfigView::updateListAll();
1541}
1542
Michal Marekbac6aa82011-05-25 15:10:25 +02001543bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Masahiro Yamada87419082019-03-11 01:13:15 +09001545 if (conf_write(configname)) {
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001546 QMessageBox::information(this, "qconf", "Unable to save configuration!");
Michal Marekbac6aa82011-05-25 15:10:25 +02001547 return false;
1548 }
Masahiro Yamada00c864f2018-07-20 16:46:31 +09001549 conf_write_autoconf(0);
1550
Michal Marekbac6aa82011-05-25 15:10:25 +02001551 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
1554void ConfigMainWindow::saveConfigAs(void)
1555{
Masahiro Yamada87419082019-03-11 01:13:15 +09001556 QString str;
1557 QByteArray ba;
1558 const char *name;
1559
1560 str = QFileDialog::getSaveFileName(this, "", configname);
1561 if (str.isNull())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 return;
Masahiro Yamada87419082019-03-11 01:13:15 +09001563
1564 ba = str.toLocal8Bit();
1565 name = ba.data();
1566
1567 if (conf_write(name)) {
1568 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1569 }
1570 conf_write_autoconf(0);
1571
1572 free(configname);
1573 configname = xstrdup(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574}
1575
Roman Zippel43bf6122006-06-08 22:12:45 -07001576void ConfigMainWindow::searchConfig(void)
1577{
1578 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001579 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001580 searchWindow->show();
1581}
1582
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583void ConfigMainWindow::changeMenu(struct menu *menu)
1584{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001585 configList->setRootMenu(menu);
1586 if (configList->rootEntry->parent == &rootmenu)
1587 backAction->setEnabled(false);
1588 else
1589 backAction->setEnabled(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
Roman Zippelb65a47e2006-06-08 22:12:47 -07001592void ConfigMainWindow::setMenuLink(struct menu *menu)
1593{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001594 struct menu *parent;
1595 ConfigList* list = NULL;
1596 ConfigItem* item;
1597
1598 if (configList->menuSkip(menu))
1599 return;
1600
1601 switch (configList->mode) {
1602 case singleMode:
1603 list = configList;
1604 parent = menu_get_parent_menu(menu);
1605 if (!parent)
1606 return;
1607 list->setRootMenu(parent);
1608 break;
1609 case symbolMode:
1610 if (menu->flags & MENU_ROOT) {
1611 configList->setRootMenu(menu);
1612 configList->clearSelection();
1613 list = menuList;
1614 } else {
1615 list = configList;
1616 parent = menu_get_parent_menu(menu->parent);
1617 if (!parent)
1618 return;
1619 item = menuList->findConfigItem(parent);
1620 if (item) {
1621 item->setSelected(true);
1622 menuList->scrollToItem(item);
1623 }
1624 list->setRootMenu(parent);
1625 }
1626 break;
1627 case fullMode:
1628 list = configList;
1629 break;
1630 default:
1631 break;
1632 }
1633
1634 if (list) {
1635 item = list->findConfigItem(menu);
1636 if (item) {
1637 item->setSelected(true);
1638 list->scrollToItem(item);
1639 list->setFocus();
1640 }
1641 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001642}
1643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644void ConfigMainWindow::listFocusChanged(void)
1645{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001646 if (menuList->mode == menuMode)
1647 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648}
1649
1650void ConfigMainWindow::goBack(void)
1651{
Boris Barbulovski5df9da92015-09-22 11:36:36 -07001652 ConfigItem* item, *oldSelection;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001653
1654 configList->setParentMenu();
1655 if (configList->rootEntry == &rootmenu)
1656 backAction->setEnabled(false);
Boris Barbulovskibe596aa2015-09-22 11:36:28 -07001657
1658 if (menuList->selectedItems().count() == 0)
1659 return;
1660
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001661 item = (ConfigItem*)menuList->selectedItems().first();
Boris Barbulovski5df9da92015-09-22 11:36:36 -07001662 oldSelection = item;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001663 while (item) {
1664 if (item->menu == configList->rootEntry) {
Boris Barbulovski5df9da92015-09-22 11:36:36 -07001665 oldSelection->setSelected(false);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001666 item->setSelected(true);
1667 break;
1668 }
1669 item = (ConfigItem*)item->parent();
1670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671}
1672
1673void ConfigMainWindow::showSingleView(void)
1674{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001675 singleViewAction->setEnabled(false);
1676 singleViewAction->setChecked(true);
1677 splitViewAction->setEnabled(true);
1678 splitViewAction->setChecked(false);
1679 fullViewAction->setEnabled(true);
1680 fullViewAction->setChecked(false);
1681
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001683 menuList->setRootMenu(0);
1684 configList->mode = singleMode;
1685 if (configList->rootEntry == &rootmenu)
1686 configList->updateListAll();
1687 else
1688 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 configList->setFocus();
1690}
1691
1692void ConfigMainWindow::showSplitView(void)
1693{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001694 singleViewAction->setEnabled(true);
1695 singleViewAction->setChecked(false);
1696 splitViewAction->setEnabled(false);
1697 splitViewAction->setChecked(true);
1698 fullViewAction->setEnabled(true);
1699 fullViewAction->setChecked(false);
1700
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001701 configList->mode = symbolMode;
1702 if (configList->rootEntry == &rootmenu)
1703 configList->updateListAll();
1704 else
1705 configList->setRootMenu(&rootmenu);
1706 configList->setAllOpen(true);
1707 configApp->processEvents();
1708 menuList->mode = menuMode;
1709 menuList->setRootMenu(&rootmenu);
1710 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 menuView->show();
1712 menuList->setFocus();
1713}
1714
1715void ConfigMainWindow::showFullView(void)
1716{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001717 singleViewAction->setEnabled(true);
1718 singleViewAction->setChecked(false);
1719 splitViewAction->setEnabled(true);
1720 splitViewAction->setChecked(false);
1721 fullViewAction->setEnabled(false);
1722 fullViewAction->setChecked(true);
1723
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001725 menuList->setRootMenu(0);
1726 configList->mode = fullMode;
1727 if (configList->rootEntry == &rootmenu)
1728 configList->updateListAll();
1729 else
1730 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 configList->setFocus();
1732}
1733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734/*
1735 * ask for saving configuration before quitting
1736 * TODO ask only when something changed
1737 */
1738void ConfigMainWindow::closeEvent(QCloseEvent* e)
1739{
Karsten Wieseb3214292006-12-13 00:34:06 -08001740 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 e->accept();
1742 return;
1743 }
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001744 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001746 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1747 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1748 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 switch (mb.exec()) {
1750 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001751 if (saveConfig())
1752 e->accept();
1753 else
1754 e->ignore();
1755 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 case QMessageBox::No:
1757 e->accept();
1758 break;
1759 case QMessageBox::Cancel:
1760 e->ignore();
1761 break;
1762 }
1763}
1764
1765void ConfigMainWindow::showIntro(void)
1766{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001767 static const QString str = "Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 "For each option, a blank box indicates the feature is disabled, a check\n"
1769 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1770 "as a module. Clicking on the box will cycle through the three states.\n\n"
1771 "If you do not see an option (e.g., a device driver) that you believe\n"
1772 "should be present, try turning on Show All Options under the Options menu.\n"
1773 "Although there is no cross reference yet to help you figure out what other\n"
1774 "options must be enabled to support the option you are interested in, you can\n"
1775 "still view the help of a grayed-out option.\n\n"
1776 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001777 "which you can then match by examining other options.\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
1779 QMessageBox::information(this, "qconf", str);
1780}
1781
1782void ConfigMainWindow::showAbout(void)
1783{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001784 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
Boris Barbulovskib4ff1de2015-09-22 11:36:38 -07001785 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001786 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
1788 QMessageBox::information(this, "qconf", str);
1789}
1790
1791void ConfigMainWindow::saveSettings(void)
1792{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001793 configSettings->setValue("/window x", pos().x());
1794 configSettings->setValue("/window y", pos().y());
1795 configSettings->setValue("/window width", size().width());
1796 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
1798 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001799 switch(configList->mode) {
1800 case singleMode :
1801 entry = "single";
1802 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001804 case symbolMode :
1805 entry = "split";
1806 break;
1807
1808 case fullMode :
1809 entry = "full";
1810 break;
1811
1812 default:
1813 break;
1814 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001815 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Roman Zippel7fc925f2006-06-08 22:12:46 -07001817 configSettings->writeSizes("/split1", split1->sizes());
1818 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819}
1820
Karsten Wiese3b354c52006-12-13 00:34:08 -08001821void ConfigMainWindow::conf_changed(void)
1822{
1823 if (saveAction)
1824 saveAction->setEnabled(conf_get_changed());
1825}
1826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827void fixup_rootmenu(struct menu *menu)
1828{
1829 struct menu *child;
1830 static int menu_cnt = 0;
1831
1832 menu->flags |= MENU_ROOT;
1833 for (child = menu->list; child; child = child->next) {
1834 if (child->prompt && child->prompt->type == P_MENU) {
1835 menu_cnt++;
1836 fixup_rootmenu(child);
1837 menu_cnt--;
1838 } else if (!menu_cnt)
1839 fixup_rootmenu(child);
1840 }
1841}
1842
1843static const char *progname;
1844
1845static void usage(void)
1846{
Sam Ravnborg694c49a2018-05-22 21:36:12 +02001847 printf("%s [-s] <config>\n", progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 exit(0);
1849}
1850
1851int main(int ac, char** av)
1852{
1853 ConfigMainWindow* v;
1854 const char *name;
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 progname = av[0];
1857 configApp = new QApplication(ac, av);
1858 if (ac > 1 && av[1][0] == '-') {
1859 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001860 case 's':
1861 conf_set_message_callback(NULL);
1862 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 case 'h':
1864 case '?':
1865 usage();
1866 }
1867 name = av[2];
1868 } else
1869 name = av[1];
1870 if (!name)
1871 usage();
1872
1873 conf_parse(name);
1874 fixup_rootmenu(&rootmenu);
1875 conf_read(NULL);
1876 //zconfdump(stdout);
1877
Roman Zippel7fc925f2006-06-08 22:12:46 -07001878 configSettings = new ConfigSettings();
1879 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 v = new ConfigMainWindow();
1881
1882 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1884 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001885 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 configApp->exec();
1887
Roman Zippel7fc925f2006-06-08 22:12:46 -07001888 configSettings->endGroup();
1889 delete configSettings;
Chris Bainbridge5b61c7b2016-01-08 20:44:04 +00001890 delete v;
1891 delete configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001892
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 return 0;
1894}