blob: c64b90517bdb6fdf0688ce9798974518d4a9acdd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
Alexander Stein133c5f72010-08-31 17:34:37 +02006#include <qglobal.h>
7
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07008#include <QMainWindow>
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07009#include <QList>
Boris Barbulovski924bbb52015-09-22 11:36:06 -070010#include <qtextbrowser.h>
Boris Barbulovski85eaf282015-09-22 11:36:03 -070011#include <QAction>
Boris Barbulovskibea00772015-09-22 11:36:04 -070012#include <QFileDialog>
Boris Barbulovski76bede82015-09-22 11:36:07 -070013#include <QMenu>
Alexander Stein133c5f72010-08-31 17:34:37 +020014
15#include <qapplication.h>
Markus Heidelberg8d90c972009-05-18 01:36:52 +020016#include <qdesktopwidget.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <qtoolbar.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070018#include <qlayout.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <qsplitter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <qlineedit.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070021#include <qlabel.h>
22#include <qpushbutton.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <qmenubar.h>
24#include <qmessagebox.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <qregexp.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020026#include <qevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <stdlib.h>
29
30#include "lkc.h"
31#include "qconf.h"
32
33#include "qconf.moc"
34#include "images.c"
35
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070036#ifdef _
37# undef _
38# define _ qgettext
39#endif
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070042static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Boris Barbulovski85eaf282015-09-22 11:36:03 -070044QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080045
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070046static inline QString qgettext(const char* str)
47{
Roman Zippel43bf6122006-06-08 22:12:45 -070048 return QString::fromLocal8Bit(gettext(str));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070049}
50
51static inline QString qgettext(const QString& str)
52{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070053 return QString::fromLocal8Bit(gettext(str.toLatin1()));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070054}
55
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010056ConfigSettings::ConfigSettings()
57 : QSettings("kernel.org", "qconf")
58{
59}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/**
62 * Reads a list of integer values from the application settings.
63 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070064QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070066 QList<int> result;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070067 QStringList entryList = value(key).toStringList();
Li Zefanc1f96f02010-05-07 13:58:04 +080068 QStringList::Iterator it;
69
70 for (it = entryList.begin(); it != entryList.end(); ++it)
71 result.push_back((*it).toInt());
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;
121 prompt = _(menu_get_prompt(menu));
122
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
155 if (!sym_is_changable(sym) && list->optMode == normalOpt) {
156 setPixmap(promptColIdx, QIcon());
157 setText(noColIdx, QString::null);
158 setText(modColIdx, QString::null);
159 setText(yesColIdx, QString::null);
160 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
202 //int i = list->mapIdx(dataColIdx);
203 //if (i >= 0)
204 // setRenameEnabled(i, true);
205 setText(dataColIdx, data);
206 if (type == S_STRING)
207 prompt = QString("%1: %2").arg(prompt).arg(data);
208 else
209 prompt = QString("(%2) %1").arg(prompt).arg(data);
210 break;
211 }
212 if (!sym_has_value(sym) && visible)
213 prompt += _(" (NEW)");
214set_prompt:
215 setText(promptColIdx, prompt);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700216}
217
218void ConfigItem::testUpdateMenu(bool v)
219{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700220 ConfigItem* i;
221
222 visible = v;
223 if (!menu)
224 return;
225
226 sym_calc_value(menu->sym);
227 if (menu->flags & MENU_CHANGED) {
228 /* the menu entry changed, so update all list items */
229 menu->flags &= ~MENU_CHANGED;
230 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
231 i->updateMenu();
232 } else if (listView()->updateAll)
233 updateMenu();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700234}
235
236
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700237/*
238 * construct a menu entry
239 */
240void ConfigItem::init(void)
241{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700242 if (menu) {
243 ConfigList* list = listView();
244 nextItem = (ConfigItem*)menu->data;
245 menu->data = this;
246
247 if (list->mode != fullMode)
248 setExpanded(true);
249 sym_calc_value(menu->sym);
250 }
251 updateMenu();
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700252}
253
254/*
255 * destruct a menu entry
256 */
257ConfigItem::~ConfigItem(void)
258{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700259 if (menu) {
260 ConfigItem** ip = (ConfigItem**)&menu->data;
261 for (; *ip; ip = &(*ip)->nextItem) {
262 if (*ip == this) {
263 *ip = nextItem;
264 break;
265 }
266 }
267 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700268}
269
Roman Zippel43bf6122006-06-08 22:12:45 -0700270ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
271 : Parent(parent)
272{
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700273 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700274}
275
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700276void ConfigLineEdit::show(ConfigItem* i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 item = i;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700279 if (sym_get_string_value(item->menu->sym))
280 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
281 else
282 setText(QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 Parent::show();
284 setFocus();
285}
286
287void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
288{
289 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200290 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200292 case Qt::Key_Return:
293 case Qt::Key_Enter:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700294 sym_set_string_value(item->menu->sym, text().toLatin1());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 parent()->updateList(item);
296 break;
297 default:
298 Parent::keyPressEvent(e);
299 return;
300 }
301 e->accept();
302 parent()->list->setFocus();
303 hide();
304}
305
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700306ConfigList::ConfigList(ConfigView* p, const char *name)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700307 : Parent(p),
308 updateAll(false),
309 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
310 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
311 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
312 showName(false), showRange(false), showData(false), optMode(normalOpt),
313 rootEntry(0), headerPopup(0)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700314{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700315 int i;
316
317 setObjectName(name);
318 setSortingEnabled(-1);
319 setRootIsDecorated(true);
320
Boris Barbulovskia52cb3212015-09-22 11:36:24 -0700321 setHeaderLabels(QStringList() << _("Option") << _("Name") << "N" << "M" << "Y" << _("Value"));
322
Boris Barbulovskic14fa5e2015-09-22 11:36:21 -0700323 connect(this, SIGNAL(itemSelectionChanged(void)),
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700324 SLOT(updateSelection(void)));
325
326 if (name) {
327 configSettings->beginGroup(name);
328 showName = configSettings->value("/showName", false).toBool();
329 showRange = configSettings->value("/showRange", false).toBool();
330 showData = configSettings->value("/showData", false).toBool();
331 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
332 configSettings->endGroup();
333 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
334 }
335
336 addColumn(promptColIdx);
337
338 reinit();
339}
340
341bool ConfigList::menuSkip(struct menu *menu)
342{
343 if (optMode == normalOpt && menu_is_visible(menu))
344 return false;
345 if (optMode == promptOpt && menu_has_prompt(menu))
346 return false;
347 if (optMode == allOpt)
348 return false;
349 return true;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700350}
Boris Barbulovski59e56442015-09-22 11:36:18 -0700351
352void ConfigList::reinit(void)
353{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700354 removeColumn(dataColIdx);
355 removeColumn(yesColIdx);
356 removeColumn(modColIdx);
357 removeColumn(noColIdx);
358 removeColumn(nameColIdx);
359
360 if (showName)
361 addColumn(nameColIdx);
362 if (showRange) {
363 addColumn(noColIdx);
364 addColumn(modColIdx);
365 addColumn(yesColIdx);
366 }
367 if (showData)
368 addColumn(dataColIdx);
369
370 updateListAll();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700371}
372
373void ConfigList::saveSettings(void)
374{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700375 if (!objectName().isEmpty()) {
376 configSettings->beginGroup(objectName());
377 configSettings->setValue("/showName", showName);
378 configSettings->setValue("/showRange", showRange);
379 configSettings->setValue("/showData", showData);
380 configSettings->setValue("/optionMode", (int)optMode);
381 configSettings->endGroup();
382 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700383}
384
385ConfigItem* ConfigList::findConfigItem(struct menu *menu)
386{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700387 ConfigItem* item = (ConfigItem*)menu->data;
388
389 for (; item; item = item->nextItem) {
390 if (this == item->listView())
391 break;
392 }
393
394 return item;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700395}
396
397void ConfigList::updateSelection(void)
398{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700399 struct menu *menu;
400 enum prop_type type;
401
402 ConfigItem* item = (ConfigItem*)selectedItems().first();
403 if (!item)
404 return;
405
406 menu = item->menu;
407 emit menuChanged(menu);
408 if (!menu)
409 return;
410 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
411 if (mode == menuMode && type == P_MENU)
412 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700413}
414
415void ConfigList::updateList(ConfigItem* item)
416{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700417 ConfigItem* last = 0;
418
419 if (!rootEntry) {
420 if (mode != listMode)
421 goto update;
422 QTreeWidgetItemIterator it(this);
423 ConfigItem* item;
424
425 while (*it) {
426 item = (ConfigItem*)(*it);
427 if (!item->menu)
428 continue;
429 item->testUpdateMenu(menu_is_visible(item->menu));
430
431 ++it;
432 }
433 return;
434 }
435
436 if (rootEntry != &rootmenu && (mode == singleMode ||
437 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
438 item = firstChild();
439 if (!item)
440 item = new ConfigItem(this, 0, true);
441 last = item;
442 }
443 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
444 rootEntry->sym && rootEntry->prompt) {
445 item = last ? last->nextSibling() : firstChild();
446 if (!item)
447 item = new ConfigItem(this, last, rootEntry, true);
448 else
449 item->testUpdateMenu(true);
450
451 updateMenuList(item, rootEntry);
452 update();
453 return;
454 }
455update:
456 updateMenuList(this, rootEntry);
457 update();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700458}
459
460void ConfigList::setValue(ConfigItem* item, tristate val)
461{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700462 struct symbol* sym;
463 int type;
464 tristate oldval;
465
466 sym = item->menu ? item->menu->sym : 0;
467 if (!sym)
468 return;
469
470 type = sym_get_type(sym);
471 switch (type) {
472 case S_BOOLEAN:
473 case S_TRISTATE:
474 oldval = sym_get_tristate_value(sym);
475
476 if (!sym_set_tristate_value(sym, val))
477 return;
478 if (oldval == no && item->menu->list)
479 item->setExpanded(true);
480 parent()->updateList(item);
481 break;
482 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700483}
484
485void ConfigList::changeValue(ConfigItem* item)
486{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700487 struct symbol* sym;
488 struct menu* menu;
489 int type, oldexpr, newexpr;
490
491 menu = item->menu;
492 if (!menu)
493 return;
494 sym = menu->sym;
495 if (!sym) {
496 if (item->menu->list)
497 item->setExpanded(!item->isExpanded());
498 return;
499 }
500
501 type = sym_get_type(sym);
502 switch (type) {
503 case S_BOOLEAN:
504 case S_TRISTATE:
505 oldexpr = sym_get_tristate_value(sym);
506 newexpr = sym_toggle_tristate_value(sym);
507 if (item->menu->list) {
508 if (oldexpr == newexpr)
509 item->setExpanded(!item->isExpanded());
510 else if (oldexpr == no)
511 item->setExpanded(true);
512 }
513 if (oldexpr != newexpr)
514 parent()->updateList(item);
515 break;
516 case S_INT:
517 case S_HEX:
518 case S_STRING:
519 break;
520 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700521}
522
523void ConfigList::setRootMenu(struct menu *menu)
524{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700525 enum prop_type type;
526
527 if (rootEntry == menu)
528 return;
529 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
530 if (type != P_MENU)
531 return;
532 updateMenuList(this, 0);
533 rootEntry = menu;
534 updateListAll();
535 if (currentItem()) {
536 currentItem()->setSelected(hasFocus());
537 scrollToItem(currentItem());
538 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700539}
540
541void ConfigList::setParentMenu(void)
542{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700543 ConfigItem* item;
544 struct menu *oldroot;
545
546 oldroot = rootEntry;
547 if (rootEntry == &rootmenu)
548 return;
549 setRootMenu(menu_get_parent_menu(rootEntry->parent));
550
551 QTreeWidgetItemIterator it(this);
552 while (*it) {
553 item = (ConfigItem *)(*it);
554 if (item->menu == oldroot) {
555 setCurrentItem(item);
556 scrollToItem(item);
557 break;
558 }
559
560 ++it;
561 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700562}
563
564/*
565 * update all the children of a menu entry
566 * removes/adds the entries from the parent widget as necessary
567 *
568 * parent: either the menu list widget or a menu entry widget
569 * menu: entry to be updated
570 */
571template <class P>
572void ConfigList::updateMenuList(P* parent, struct menu* menu)
573{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700574 struct menu* child;
575 ConfigItem* item;
576 ConfigItem* last;
577 bool visible;
578 enum prop_type type;
579
580 if (!menu) {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700581 return;
582 }
583
584 last = parent->firstChild();
585 if (last && !last->goParent)
586 last = 0;
587 for (child = menu->list; child; child = child->next) {
588 item = last ? last->nextSibling() : parent->firstChild();
589 type = child->prompt ? child->prompt->type : P_UNKNOWN;
590
591 switch (mode) {
592 case menuMode:
593 if (!(child->flags & MENU_ROOT))
594 goto hide;
595 break;
596 case symbolMode:
597 if (child->flags & MENU_ROOT)
598 goto hide;
599 break;
600 default:
601 break;
602 }
603
604 visible = menu_is_visible(child);
605 if (!menuSkip(child)) {
606 if (!child->sym && !child->list && !child->prompt)
607 continue;
608 if (!item || item->menu != child)
609 item = new ConfigItem(parent, last, child, visible);
610 else
611 item->testUpdateMenu(visible);
612
613 if (mode == fullMode || mode == menuMode || type != P_MENU)
614 updateMenuList(item, child);
615 else
616 updateMenuList(item, 0);
617 last = item;
618 continue;
619 }
620 hide:
621 if (item && item->menu == child) {
622 last = parent->firstChild();
623 if (last == item)
624 last = 0;
625 else while (last->nextSibling() != item)
626 last = last->nextSibling();
627 delete item;
628 }
629 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700630}
631
632void ConfigList::keyPressEvent(QKeyEvent* ev)
633{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700634 QTreeWidgetItem* i = currentItem();
635 ConfigItem* item;
636 struct menu *menu;
637 enum prop_type type;
638
639 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
640 emit parentSelected();
641 ev->accept();
642 return;
643 }
644
645 if (!i) {
646 Parent::keyPressEvent(ev);
647 return;
648 }
649 item = (ConfigItem*)i;
650
651 switch (ev->key()) {
652 case Qt::Key_Return:
653 case Qt::Key_Enter:
654 if (item->goParent) {
655 emit parentSelected();
656 break;
657 }
658 menu = item->menu;
659 if (!menu)
660 break;
661 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
662 if (type == P_MENU && rootEntry != menu &&
663 mode != fullMode && mode != menuMode) {
664 emit menuSelected(menu);
665 break;
666 }
667 case Qt::Key_Space:
668 changeValue(item);
669 break;
670 case Qt::Key_N:
671 setValue(item, no);
672 break;
673 case Qt::Key_M:
674 setValue(item, mod);
675 break;
676 case Qt::Key_Y:
677 setValue(item, yes);
678 break;
679 default:
680 Parent::keyPressEvent(ev);
681 return;
682 }
683 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700684}
685
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700686void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700687{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700688 //QPoint p(contentsToViewport(e->pos()));
689 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
690 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700691}
692
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700693void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700694{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700695 QPoint p = e->pos();
696 ConfigItem* item = (ConfigItem*)itemAt(p);
697 struct menu *menu;
698 enum prop_type ptype;
699 QIcon icon;
700 int idx, x;
701
702 if (!item)
703 goto skip;
704
705 menu = item->menu;
706 x = header()->offset() + p.x();
707 idx = header()->sectionPosition(x);
708 switch (idx) {
709 case promptColIdx:
710 icon = item->pixmap(promptColIdx);
711 break;
712 case noColIdx:
713 setValue(item, no);
714 break;
715 case modColIdx:
716 setValue(item, mod);
717 break;
718 case yesColIdx:
719 setValue(item, yes);
720 break;
721 case dataColIdx:
722 changeValue(item);
723 break;
724 }
725
726skip:
727 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
728 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700729}
730
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700731void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700732{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700733 //QPoint p(contentsToViewport(e->pos()));
734 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
735 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700736}
737
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700738void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700739{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700740 QPoint p = e->pos(); // TODO: Check if this works(was contentsToViewport).
741 ConfigItem* item = (ConfigItem*)itemAt(p);
742 struct menu *menu;
743 enum prop_type ptype;
744
745 if (!item)
746 goto skip;
747 if (item->goParent) {
748 emit parentSelected();
749 goto skip;
750 }
751 menu = item->menu;
752 if (!menu)
753 goto skip;
754 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
755 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
756 emit menuSelected(menu);
757 else if (menu->sym)
758 changeValue(item);
759
760skip:
761 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
762 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700763}
764
765void ConfigList::focusInEvent(QFocusEvent *e)
766{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700767 struct menu *menu = NULL;
768
769 Parent::focusInEvent(e);
770
771 ConfigItem* item = (ConfigItem *)currentItem();
772 if (item) {
773 item->setSelected(true);
774 menu = item->menu;
775 }
776 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700777}
778
779void ConfigList::contextMenuEvent(QContextMenuEvent *e)
780{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700781 if (e->y() <= header()->geometry().bottom()) {
782 if (!headerPopup) {
783 QAction *action;
784
785 headerPopup = new QMenu(this);
786 action = new QAction(_("Show Name"), this);
787 action->setCheckable(true);
788 connect(action, SIGNAL(toggled(bool)),
789 parent(), SLOT(setShowName(bool)));
790 connect(parent(), SIGNAL(showNameChanged(bool)),
791 action, SLOT(setOn(bool)));
792 action->setChecked(showName);
793 headerPopup->addAction(action);
794 action = new QAction(_("Show Range"), this);
795 action->setCheckable(true);
796 connect(action, SIGNAL(toggled(bool)),
797 parent(), SLOT(setShowRange(bool)));
798 connect(parent(), SIGNAL(showRangeChanged(bool)),
799 action, SLOT(setOn(bool)));
800 action->setChecked(showRange);
801 headerPopup->addAction(action);
802 action = new QAction(_("Show Data"), this);
803 action->setCheckable(true);
804 connect(action, SIGNAL(toggled(bool)),
805 parent(), SLOT(setShowData(bool)));
806 connect(parent(), SIGNAL(showDataChanged(bool)),
807 action, SLOT(setOn(bool)));
808 action->setChecked(showData);
809 headerPopup->addAction(action);
810 }
811 headerPopup->exec(e->globalPos());
812 e->accept();
813 } else
814 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700815}
816
Li Zefan39a48972010-05-10 16:33:41 +0800817ConfigView*ConfigView::viewList;
818QAction *ConfigView::showNormalAction;
819QAction *ConfigView::showAllAction;
820QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Roman Zippel7fc925f2006-06-08 22:12:46 -0700822ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700823 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700825 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700826 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700827 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700828
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700829 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700830 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 lineEdit = new ConfigLineEdit(this);
832 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700833 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 this->nextView = viewList;
836 viewList = this;
837}
838
839ConfigView::~ConfigView(void)
840{
841 ConfigView** vp;
842
843 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
844 if (*vp == this) {
845 *vp = nextView;
846 break;
847 }
848 }
849}
850
Li Zefan39a48972010-05-10 16:33:41 +0800851void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700852{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700853 if (act == showNormalAction)
854 list->optMode = normalOpt;
855 else if (act == showAllAction)
856 list->optMode = allOpt;
857 else
858 list->optMode = promptOpt;
859
860 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700861}
862
863void ConfigView::setShowName(bool b)
864{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700865 if (list->showName != b) {
866 list->showName = b;
867 list->reinit();
868 emit showNameChanged(b);
869 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700870}
871
872void ConfigView::setShowRange(bool b)
873{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700874 if (list->showRange != b) {
875 list->showRange = b;
876 list->reinit();
877 emit showRangeChanged(b);
878 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700879}
880
881void ConfigView::setShowData(bool b)
882{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700883 if (list->showData != b) {
884 list->showData = b;
885 list->reinit();
886 emit showDataChanged(b);
887 }
888}
889
890void ConfigList::setAllOpen(bool open)
891{
892 QTreeWidgetItemIterator it(this);
893
894 while (*it) {
895 (*it)->setExpanded(open);
896
897 ++it;
898 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700899}
900
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700901void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700902{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700903 ConfigView* v;
904
905 for (v = viewList; v; v = v->nextView)
906 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907}
908
909void ConfigView::updateListAll(void)
910{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700911 ConfigView* v;
912
913 for (v = viewList; v; v = v->nextView)
914 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915}
916
Roman Zippel43bf6122006-06-08 22:12:45 -0700917ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700918 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700919{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700920 setObjectName(name);
921
922
923 if (!objectName().isEmpty()) {
924 configSettings->beginGroup(objectName());
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700925 _showDebug = configSettings->value("/showDebug", false).toBool();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700926 configSettings->endGroup();
927 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
928 }
929}
930
931void ConfigInfoView::saveSettings(void)
932{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700933 if (!objectName().isEmpty()) {
934 configSettings->beginGroup(objectName());
935 configSettings->setValue("/showDebug", showDebug());
936 configSettings->endGroup();
937 }
Roman Zippel43bf6122006-06-08 22:12:45 -0700938}
939
940void ConfigInfoView::setShowDebug(bool b)
941{
942 if (_showDebug != b) {
943 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +0200944 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700945 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -0700946 else if (sym)
947 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -0700948 emit showDebugChanged(b);
949 }
950}
951
952void ConfigInfoView::setInfo(struct menu *m)
953{
Alexander Stein133c5f72010-08-31 17:34:37 +0200954 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -0700955 return;
Alexander Stein133c5f72010-08-31 17:34:37 +0200956 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -0800957 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +0200958 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700959 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -0800960 else
Roman Zippel43bf6122006-06-08 22:12:45 -0700961 menuInfo();
962}
963
Roman Zippelab45d192006-06-08 22:12:47 -0700964void ConfigInfoView::symbolInfo(void)
965{
966 QString str;
967
968 str += "<big>Symbol: <b>";
969 str += print_filter(sym->name);
970 str += "</b></big><br><br>value: ";
971 str += print_filter(sym_get_string_value(sym));
972 str += "<br>visibility: ";
973 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
974 str += "<br>";
975 str += debug_info(sym);
976
977 setText(str);
978}
979
Roman Zippel43bf6122006-06-08 22:12:45 -0700980void ConfigInfoView::menuInfo(void)
981{
982 struct symbol* sym;
983 QString head, debug, help;
984
Alexander Stein133c5f72010-08-31 17:34:37 +0200985 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -0700986 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +0200987 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -0700988 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +0200989 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -0700990 head += "</b></big>";
991 if (sym->name) {
992 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -0700993 if (showDebug())
994 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -0700995 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -0700996 if (showDebug())
997 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -0700998 head += ")";
999 }
1000 } else if (sym->name) {
1001 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001002 if (showDebug())
1003 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001004 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001005 if (showDebug())
1006 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001007 head += "</b></big>";
1008 }
1009 head += "<br><br>";
1010
1011 if (showDebug())
1012 debug = debug_info(sym);
1013
Cheng Renquand74c15f2009-07-12 16:11:47 +08001014 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001015 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001016 help = print_filter(str_get(&help_gstr));
1017 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001018 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001019 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001020 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001021 head += "</b></big><br><br>";
1022 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001023 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001024 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001025 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001026 debug += "<br><br>";
1027 }
1028 }
1029 }
1030 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001031 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001032
1033 setText(head + debug + help);
1034}
1035
1036QString ConfigInfoView::debug_info(struct symbol *sym)
1037{
1038 QString debug;
1039
1040 debug += "type: ";
1041 debug += print_filter(sym_type_name(sym->type));
1042 if (sym_is_choice(sym))
1043 debug += " (choice)";
1044 debug += "<br>";
1045 if (sym->rev_dep.expr) {
1046 debug += "reverse dep: ";
1047 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1048 debug += "<br>";
1049 }
1050 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1051 switch (prop->type) {
1052 case P_PROMPT:
1053 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -07001054 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Roman Zippel43bf6122006-06-08 22:12:45 -07001055 debug += print_filter(_(prop->text));
Roman Zippelab45d192006-06-08 22:12:47 -07001056 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001057 break;
1058 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001059 case P_SELECT:
1060 case P_RANGE:
1061 case P_ENV:
1062 debug += prop_get_type_name(prop->type);
1063 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001064 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1065 debug += "<br>";
1066 break;
1067 case P_CHOICE:
1068 if (sym_is_choice(sym)) {
1069 debug += "choice: ";
1070 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1071 debug += "<br>";
1072 }
1073 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001074 default:
1075 debug += "unknown property: ";
1076 debug += prop_get_type_name(prop->type);
1077 debug += "<br>";
1078 }
1079 if (prop->visible.expr) {
1080 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1081 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1082 debug += "<br>";
1083 }
1084 }
1085 debug += "<br>";
1086
1087 return debug;
1088}
1089
1090QString ConfigInfoView::print_filter(const QString &str)
1091{
1092 QRegExp re("[<>&\"\\n]");
1093 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001094 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1095 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001096 case '<':
1097 res.replace(i, 1, "&lt;");
1098 i += 4;
1099 break;
1100 case '>':
1101 res.replace(i, 1, "&gt;");
1102 i += 4;
1103 break;
1104 case '&':
1105 res.replace(i, 1, "&amp;");
1106 i += 5;
1107 break;
1108 case '"':
1109 res.replace(i, 1, "&quot;");
1110 i += 6;
1111 break;
1112 case '\n':
1113 res.replace(i, 1, "<br>");
1114 i += 4;
1115 break;
1116 }
1117 }
1118 return res;
1119}
1120
Roman Zippelab45d192006-06-08 22:12:47 -07001121void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001122{
Roman Zippelab45d192006-06-08 22:12:47 -07001123 QString* text = reinterpret_cast<QString*>(data);
1124 QString str2 = print_filter(str);
1125
1126 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1127 *text += QString().sprintf("<a href=\"s%p\">", sym);
1128 *text += str2;
1129 *text += "</a>";
1130 } else
1131 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001132}
1133
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001134QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001135{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001136 QMenu* popup = Parent::createStandardContextMenu(pos);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001137 QAction* action = new QAction(_("Show Debug Info"), popup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001138 action->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001139 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1140 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001141 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001142 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001143 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001144 return popup;
1145}
1146
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001147void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001148{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001149 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001150}
1151
Marco Costalba63431e72006-10-05 19:12:59 +02001152ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001153 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001154{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001155 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001156 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001157
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001158 QVBoxLayout* layout1 = new QVBoxLayout(this);
1159 layout1->setContentsMargins(11, 11, 11, 11);
1160 layout1->setSpacing(6);
1161 QHBoxLayout* layout2 = new QHBoxLayout(0);
1162 layout2->setContentsMargins(0, 0, 0, 0);
1163 layout2->setSpacing(6);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001164 layout2->addWidget(new QLabel(_("Find:"), this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001165 editField = new QLineEdit(this);
1166 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1167 layout2->addWidget(editField);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001168 searchButton = new QPushButton(_("Search"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001169 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001170 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1171 layout2->addWidget(searchButton);
1172 layout1->addLayout(layout2);
1173
Roman Zippel7fc925f2006-06-08 22:12:46 -07001174 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001175 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001176 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001177 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001178 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001179 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1180 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001181 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1182 parent, SLOT(setMenuLink(struct menu *)));
1183
Roman Zippel43bf6122006-06-08 22:12:45 -07001184 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001185
1186 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001187 QVariant x, y;
1188 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001189 bool ok;
1190
1191 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001192 width = configSettings->value("/window width", parent->width() / 2).toInt();
1193 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001194 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001195 x = configSettings->value("/window x");
1196 y = configSettings->value("/window y");
1197 if ((x.isValid())&&(y.isValid()))
1198 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001199 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001200 if (ok)
1201 split->setSizes(sizes);
1202 configSettings->endGroup();
1203 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1204 }
1205}
1206
1207void ConfigSearchWindow::saveSettings(void)
1208{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001209 if (!objectName().isEmpty()) {
1210 configSettings->beginGroup(objectName());
1211 configSettings->setValue("/window x", pos().x());
1212 configSettings->setValue("/window y", pos().y());
1213 configSettings->setValue("/window width", size().width());
1214 configSettings->setValue("/window height", size().height());
1215 configSettings->writeSizes("/split", split->sizes());
1216 configSettings->endGroup();
1217 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001218}
1219
1220void ConfigSearchWindow::search(void)
1221{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001222 struct symbol **p;
1223 struct property *prop;
1224 ConfigItem *lastItem = NULL;
1225
1226 free(result);
1227 list->list->clear();
1228 info->clear();
1229
1230 result = sym_re_search(editField->text().toLatin1());
1231 if (!result)
1232 return;
1233 for (p = result; *p; p++) {
1234 for_all_prompts((*p), prop)
1235 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1236 menu_is_visible(prop->menu));
1237 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001238}
1239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240/*
1241 * Construct the complete config widget
1242 */
1243ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001244 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
1246 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001247 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001248 QVariant x, y;
1249 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001250 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001252 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001253 snprintf(title, sizeof(title), "%s%s",
1254 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001255 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001256 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001257 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001259 width = configSettings->value("/window width", d->width() - 64).toInt();
1260 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001262 x = configSettings->value("/window x");
1263 y = configSettings->value("/window y");
1264 if ((x.isValid())&&(y.isValid()))
1265 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001268 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 setCentralWidget(split1);
1270
Roman Zippel7fc925f2006-06-08 22:12:46 -07001271 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 menuList = menuView->list;
1273
1274 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001275 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -07001278 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 configList = configView->list;
1280
Roman Zippel7fc925f2006-06-08 22:12:46 -07001281 helpText = new ConfigInfoView(split2, "help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001282 //helpText->setTextFormat(Qt::RichText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 setTabOrder(configList, helpText);
1285 configList->setFocus();
1286
1287 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001288 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001289 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001291 backAction = new QAction(QPixmap(xpm_back), _("Back"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001292 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001293 backAction->setEnabled(false);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001294 QAction *quitAction = new QAction(_("&Quit"), this);
1295 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Boris Barbulovski92119932015-09-22 11:36:16 -07001296 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001297 QAction *loadAction = new QAction(QPixmap(xpm_load), _("&Load"), this);
1298 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Boris Barbulovski92119932015-09-22 11:36:16 -07001299 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001300 saveAction = new QAction(QPixmap(xpm_save), _("&Save"), this);
1301 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Boris Barbulovski92119932015-09-22 11:36:16 -07001302 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001303 conf_set_changed_callback(conf_changed);
1304 // Set saveAction's initial state
1305 conf_changed();
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001306 QAction *saveAsAction = new QAction(_("Save &As..."), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001307 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001308 QAction *searchAction = new QAction(_("&Find"), this);
1309 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001310 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001311 singleViewAction = new QAction(QPixmap(xpm_single_view), _("Single View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001312 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001313 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001314 splitViewAction = new QAction(QPixmap(xpm_split_view), _("Split View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001315 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001316 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001317 fullViewAction = new QAction(QPixmap(xpm_tree_view), _("Full View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001318 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001319 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001321 QAction *showNameAction = new QAction(_("Show Name"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001322 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001323 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001324 showNameAction->setChecked(configView->showName());
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001325 QAction *showRangeAction = new QAction(_("Show Range"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001326 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001327 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001328 QAction *showDataAction = new QAction(_("Show Data"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001329 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001330 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001331
1332 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001333 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001334 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001335 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001336 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001337 SLOT(setOptionMode(QAction *)));
1338
Alexander Stein133c5f72010-08-31 17:34:37 +02001339 configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
1340 configView->showAllAction = new QAction(_("Show All Options"), optGroup);
1341 configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001342 configView->showNormalAction->setCheckable(true);
1343 configView->showAllAction->setCheckable(true);
1344 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001345
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001346 QAction *showDebugAction = new QAction( _("Show Debug Info"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001347 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001348 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001349 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001351 QAction *showIntroAction = new QAction( _("Introduction"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001352 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001353 QAction *showAboutAction = new QAction( _("About"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001354 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
1356 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001357 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001359 toolBar->addAction(loadAction);
1360 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001362 toolBar->addAction(singleViewAction);
1363 toolBar->addAction(splitViewAction);
1364 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
1366 // create config menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001367 QMenu* config = menu->addMenu(_("&File"));
1368 config->addAction(loadAction);
1369 config->addAction(saveAction);
1370 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001371 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001372 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Shlomi Fish66e7c722007-02-14 00:32:58 -08001374 // create edit menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001375 QMenu* editMenu = menu->addMenu(_("&Edit"));
1376 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001377
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 // create options menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001379 QMenu* optionMenu = menu->addMenu(_("&Option"));
1380 optionMenu->addAction(showNameAction);
1381 optionMenu->addAction(showRangeAction);
1382 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001383 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001384 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001385 optionMenu->addSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001388 menu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001389 QMenu* helpMenu = menu->addMenu(_("&Help"));
1390 helpMenu->addAction(showIntroAction);
1391 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001393 connect(configList, SIGNAL(menuChanged(struct menu *)),
1394 helpText, SLOT(setInfo(struct menu *)));
1395 connect(configList, SIGNAL(menuSelected(struct menu *)),
1396 SLOT(changeMenu(struct menu *)));
1397 connect(configList, SIGNAL(parentSelected()),
1398 SLOT(goBack()));
1399 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1400 helpText, SLOT(setInfo(struct menu *)));
1401 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1402 SLOT(changeMenu(struct menu *)));
1403
1404 connect(configList, SIGNAL(gotFocus(struct menu *)),
1405 helpText, SLOT(setInfo(struct menu *)));
1406 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1407 helpText, SLOT(setInfo(struct menu *)));
1408 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1409 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001410 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1411 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001413 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 if (listMode == "single")
1415 showSingleView();
1416 else if (listMode == "full")
1417 showFullView();
1418 else /*if (listMode == "split")*/
1419 showSplitView();
1420
1421 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001422 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 if (ok)
1424 split1->setSizes(sizes);
1425
Roman Zippel7fc925f2006-06-08 22:12:46 -07001426 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 if (ok)
1428 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429}
1430
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431void ConfigMainWindow::loadConfig(void)
1432{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001433 QString s = QFileDialog::getOpenFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 if (s.isNull())
1435 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001436 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001437 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 ConfigView::updateListAll();
1439}
1440
Michal Marekbac6aa82011-05-25 15:10:25 +02001441bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
Michal Marekbac6aa82011-05-25 15:10:25 +02001443 if (conf_write(NULL)) {
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001444 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Michal Marekbac6aa82011-05-25 15:10:25 +02001445 return false;
1446 }
1447 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
1450void ConfigMainWindow::saveConfigAs(void)
1451{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001452 QString s = QFileDialog::getSaveFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 if (s.isNull())
1454 return;
Arnaud Lacombed49e4682011-05-24 14:16:18 -04001455 saveConfig();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456}
1457
Roman Zippel43bf6122006-06-08 22:12:45 -07001458void ConfigMainWindow::searchConfig(void)
1459{
1460 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001461 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001462 searchWindow->show();
1463}
1464
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465void ConfigMainWindow::changeMenu(struct menu *menu)
1466{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001467 configList->setRootMenu(menu);
1468 if (configList->rootEntry->parent == &rootmenu)
1469 backAction->setEnabled(false);
1470 else
1471 backAction->setEnabled(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Roman Zippelb65a47e2006-06-08 22:12:47 -07001474void ConfigMainWindow::setMenuLink(struct menu *menu)
1475{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001476 struct menu *parent;
1477 ConfigList* list = NULL;
1478 ConfigItem* item;
1479
1480 if (configList->menuSkip(menu))
1481 return;
1482
1483 switch (configList->mode) {
1484 case singleMode:
1485 list = configList;
1486 parent = menu_get_parent_menu(menu);
1487 if (!parent)
1488 return;
1489 list->setRootMenu(parent);
1490 break;
1491 case symbolMode:
1492 if (menu->flags & MENU_ROOT) {
1493 configList->setRootMenu(menu);
1494 configList->clearSelection();
1495 list = menuList;
1496 } else {
1497 list = configList;
1498 parent = menu_get_parent_menu(menu->parent);
1499 if (!parent)
1500 return;
1501 item = menuList->findConfigItem(parent);
1502 if (item) {
1503 item->setSelected(true);
1504 menuList->scrollToItem(item);
1505 }
1506 list->setRootMenu(parent);
1507 }
1508 break;
1509 case fullMode:
1510 list = configList;
1511 break;
1512 default:
1513 break;
1514 }
1515
1516 if (list) {
1517 item = list->findConfigItem(menu);
1518 if (item) {
1519 item->setSelected(true);
1520 list->scrollToItem(item);
1521 list->setFocus();
1522 }
1523 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001524}
1525
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526void ConfigMainWindow::listFocusChanged(void)
1527{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001528 if (menuList->mode == menuMode)
1529 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
1532void ConfigMainWindow::goBack(void)
1533{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001534 ConfigItem* item;
1535
1536 configList->setParentMenu();
1537 if (configList->rootEntry == &rootmenu)
1538 backAction->setEnabled(false);
1539 item = (ConfigItem*)menuList->selectedItems().first();
1540 while (item) {
1541 if (item->menu == configList->rootEntry) {
1542 item->setSelected(true);
1543 break;
1544 }
1545 item = (ConfigItem*)item->parent();
1546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
1548
1549void ConfigMainWindow::showSingleView(void)
1550{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001551 singleViewAction->setEnabled(false);
1552 singleViewAction->setChecked(true);
1553 splitViewAction->setEnabled(true);
1554 splitViewAction->setChecked(false);
1555 fullViewAction->setEnabled(true);
1556 fullViewAction->setChecked(false);
1557
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001559 menuList->setRootMenu(0);
1560 configList->mode = singleMode;
1561 if (configList->rootEntry == &rootmenu)
1562 configList->updateListAll();
1563 else
1564 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 configList->setFocus();
1566}
1567
1568void ConfigMainWindow::showSplitView(void)
1569{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001570 singleViewAction->setEnabled(true);
1571 singleViewAction->setChecked(false);
1572 splitViewAction->setEnabled(false);
1573 splitViewAction->setChecked(true);
1574 fullViewAction->setEnabled(true);
1575 fullViewAction->setChecked(false);
1576
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001577 configList->mode = symbolMode;
1578 if (configList->rootEntry == &rootmenu)
1579 configList->updateListAll();
1580 else
1581 configList->setRootMenu(&rootmenu);
1582 configList->setAllOpen(true);
1583 configApp->processEvents();
1584 menuList->mode = menuMode;
1585 menuList->setRootMenu(&rootmenu);
1586 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 menuView->show();
1588 menuList->setFocus();
1589}
1590
1591void ConfigMainWindow::showFullView(void)
1592{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001593 singleViewAction->setEnabled(true);
1594 singleViewAction->setChecked(false);
1595 splitViewAction->setEnabled(true);
1596 splitViewAction->setChecked(false);
1597 fullViewAction->setEnabled(false);
1598 fullViewAction->setChecked(true);
1599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001601 menuList->setRootMenu(0);
1602 configList->mode = fullMode;
1603 if (configList->rootEntry == &rootmenu)
1604 configList->updateListAll();
1605 else
1606 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 configList->setFocus();
1608}
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610/*
1611 * ask for saving configuration before quitting
1612 * TODO ask only when something changed
1613 */
1614void ConfigMainWindow::closeEvent(QCloseEvent* e)
1615{
Karsten Wieseb3214292006-12-13 00:34:06 -08001616 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 e->accept();
1618 return;
1619 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001620 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001622 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1623 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1624 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 switch (mb.exec()) {
1626 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001627 if (saveConfig())
1628 e->accept();
1629 else
1630 e->ignore();
1631 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 case QMessageBox::No:
1633 e->accept();
1634 break;
1635 case QMessageBox::Cancel:
1636 e->ignore();
1637 break;
1638 }
1639}
1640
1641void ConfigMainWindow::showIntro(void)
1642{
Arnaud Lacombe652cf982010-08-14 23:51:40 -04001643 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 "For each option, a blank box indicates the feature is disabled, a check\n"
1645 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1646 "as a module. Clicking on the box will cycle through the three states.\n\n"
1647 "If you do not see an option (e.g., a device driver) that you believe\n"
1648 "should be present, try turning on Show All Options under the Options menu.\n"
1649 "Although there is no cross reference yet to help you figure out what other\n"
1650 "options must be enabled to support the option you are interested in, you can\n"
1651 "still view the help of a grayed-out option.\n\n"
1652 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001653 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655 QMessageBox::information(this, "qconf", str);
1656}
1657
1658void ConfigMainWindow::showAbout(void)
1659{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001660 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1661 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663 QMessageBox::information(this, "qconf", str);
1664}
1665
1666void ConfigMainWindow::saveSettings(void)
1667{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001668 configSettings->setValue("/window x", pos().x());
1669 configSettings->setValue("/window y", pos().y());
1670 configSettings->setValue("/window width", size().width());
1671 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001674 switch(configList->mode) {
1675 case singleMode :
1676 entry = "single";
1677 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001679 case symbolMode :
1680 entry = "split";
1681 break;
1682
1683 case fullMode :
1684 entry = "full";
1685 break;
1686
1687 default:
1688 break;
1689 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001690 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Roman Zippel7fc925f2006-06-08 22:12:46 -07001692 configSettings->writeSizes("/split1", split1->sizes());
1693 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694}
1695
Karsten Wiese3b354c52006-12-13 00:34:08 -08001696void ConfigMainWindow::conf_changed(void)
1697{
1698 if (saveAction)
1699 saveAction->setEnabled(conf_get_changed());
1700}
1701
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702void fixup_rootmenu(struct menu *menu)
1703{
1704 struct menu *child;
1705 static int menu_cnt = 0;
1706
1707 menu->flags |= MENU_ROOT;
1708 for (child = menu->list; child; child = child->next) {
1709 if (child->prompt && child->prompt->type == P_MENU) {
1710 menu_cnt++;
1711 fixup_rootmenu(child);
1712 menu_cnt--;
1713 } else if (!menu_cnt)
1714 fixup_rootmenu(child);
1715 }
1716}
1717
1718static const char *progname;
1719
1720static void usage(void)
1721{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001722 printf(_("%s [-s] <config>\n").toLatin1().constData(), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 exit(0);
1724}
1725
1726int main(int ac, char** av)
1727{
1728 ConfigMainWindow* v;
1729 const char *name;
1730
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001731 bindtextdomain(PACKAGE, LOCALEDIR);
1732 textdomain(PACKAGE);
1733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 progname = av[0];
1735 configApp = new QApplication(ac, av);
1736 if (ac > 1 && av[1][0] == '-') {
1737 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001738 case 's':
1739 conf_set_message_callback(NULL);
1740 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 case 'h':
1742 case '?':
1743 usage();
1744 }
1745 name = av[2];
1746 } else
1747 name = av[1];
1748 if (!name)
1749 usage();
1750
1751 conf_parse(name);
1752 fixup_rootmenu(&rootmenu);
1753 conf_read(NULL);
1754 //zconfdump(stdout);
1755
Roman Zippel7fc925f2006-06-08 22:12:46 -07001756 configSettings = new ConfigSettings();
1757 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 v = new ConfigMainWindow();
1759
1760 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1762 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001763 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 configApp->exec();
1765
Roman Zippel7fc925f2006-06-08 22:12:46 -07001766 configSettings->endGroup();
1767 delete configSettings;
1768
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 return 0;
1770}