blob: 3454c4361c8ea5576907156a40733585ad77b8a9 [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 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
400 ConfigItem* item = (ConfigItem*)selectedItems().first();
401 if (!item)
402 return;
403
404 menu = item->menu;
405 emit menuChanged(menu);
406 if (!menu)
407 return;
408 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
409 if (mode == menuMode && type == P_MENU)
410 emit menuSelected(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700411}
412
413void ConfigList::updateList(ConfigItem* item)
414{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700415 ConfigItem* last = 0;
416
417 if (!rootEntry) {
418 if (mode != listMode)
419 goto update;
420 QTreeWidgetItemIterator it(this);
421 ConfigItem* item;
422
423 while (*it) {
424 item = (ConfigItem*)(*it);
425 if (!item->menu)
426 continue;
427 item->testUpdateMenu(menu_is_visible(item->menu));
428
429 ++it;
430 }
431 return;
432 }
433
434 if (rootEntry != &rootmenu && (mode == singleMode ||
435 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
436 item = firstChild();
437 if (!item)
438 item = new ConfigItem(this, 0, true);
439 last = item;
440 }
441 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
442 rootEntry->sym && rootEntry->prompt) {
443 item = last ? last->nextSibling() : firstChild();
444 if (!item)
445 item = new ConfigItem(this, last, rootEntry, true);
446 else
447 item->testUpdateMenu(true);
448
449 updateMenuList(item, rootEntry);
450 update();
451 return;
452 }
453update:
454 updateMenuList(this, rootEntry);
455 update();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700456}
457
458void ConfigList::setValue(ConfigItem* item, tristate val)
459{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700460 struct symbol* sym;
461 int type;
462 tristate oldval;
463
464 sym = item->menu ? item->menu->sym : 0;
465 if (!sym)
466 return;
467
468 type = sym_get_type(sym);
469 switch (type) {
470 case S_BOOLEAN:
471 case S_TRISTATE:
472 oldval = sym_get_tristate_value(sym);
473
474 if (!sym_set_tristate_value(sym, val))
475 return;
476 if (oldval == no && item->menu->list)
477 item->setExpanded(true);
478 parent()->updateList(item);
479 break;
480 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700481}
482
483void ConfigList::changeValue(ConfigItem* item)
484{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700485 struct symbol* sym;
486 struct menu* menu;
487 int type, oldexpr, newexpr;
488
489 menu = item->menu;
490 if (!menu)
491 return;
492 sym = menu->sym;
493 if (!sym) {
494 if (item->menu->list)
495 item->setExpanded(!item->isExpanded());
496 return;
497 }
498
499 type = sym_get_type(sym);
500 switch (type) {
501 case S_BOOLEAN:
502 case S_TRISTATE:
503 oldexpr = sym_get_tristate_value(sym);
504 newexpr = sym_toggle_tristate_value(sym);
505 if (item->menu->list) {
506 if (oldexpr == newexpr)
507 item->setExpanded(!item->isExpanded());
508 else if (oldexpr == no)
509 item->setExpanded(true);
510 }
511 if (oldexpr != newexpr)
512 parent()->updateList(item);
513 break;
514 case S_INT:
515 case S_HEX:
516 case S_STRING:
517 break;
518 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700519}
520
521void ConfigList::setRootMenu(struct menu *menu)
522{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700523 enum prop_type type;
524
525 if (rootEntry == menu)
526 return;
527 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
528 if (type != P_MENU)
529 return;
530 updateMenuList(this, 0);
531 rootEntry = menu;
532 updateListAll();
533 if (currentItem()) {
534 currentItem()->setSelected(hasFocus());
535 scrollToItem(currentItem());
536 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700537}
538
539void ConfigList::setParentMenu(void)
540{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700541 ConfigItem* item;
542 struct menu *oldroot;
543
544 oldroot = rootEntry;
545 if (rootEntry == &rootmenu)
546 return;
547 setRootMenu(menu_get_parent_menu(rootEntry->parent));
548
549 QTreeWidgetItemIterator it(this);
550 while (*it) {
551 item = (ConfigItem *)(*it);
552 if (item->menu == oldroot) {
553 setCurrentItem(item);
554 scrollToItem(item);
555 break;
556 }
557
558 ++it;
559 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700560}
561
562/*
563 * update all the children of a menu entry
564 * removes/adds the entries from the parent widget as necessary
565 *
566 * parent: either the menu list widget or a menu entry widget
567 * menu: entry to be updated
568 */
569template <class P>
570void ConfigList::updateMenuList(P* parent, struct menu* menu)
571{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700572 struct menu* child;
573 ConfigItem* item;
574 ConfigItem* last;
575 bool visible;
576 enum prop_type type;
577
578 if (!menu) {
579 while ((item = parent->firstChild()))
580 item->parent()->removeChild(item);
581 delete item;
582 return;
583 }
584
585 last = parent->firstChild();
586 if (last && !last->goParent)
587 last = 0;
588 for (child = menu->list; child; child = child->next) {
589 item = last ? last->nextSibling() : parent->firstChild();
590 type = child->prompt ? child->prompt->type : P_UNKNOWN;
591
592 switch (mode) {
593 case menuMode:
594 if (!(child->flags & MENU_ROOT))
595 goto hide;
596 break;
597 case symbolMode:
598 if (child->flags & MENU_ROOT)
599 goto hide;
600 break;
601 default:
602 break;
603 }
604
605 visible = menu_is_visible(child);
606 if (!menuSkip(child)) {
607 if (!child->sym && !child->list && !child->prompt)
608 continue;
609 if (!item || item->menu != child)
610 item = new ConfigItem(parent, last, child, visible);
611 else
612 item->testUpdateMenu(visible);
613
614 if (mode == fullMode || mode == menuMode || type != P_MENU)
615 updateMenuList(item, child);
616 else
617 updateMenuList(item, 0);
618 last = item;
619 continue;
620 }
621 hide:
622 if (item && item->menu == child) {
623 last = parent->firstChild();
624 if (last == item)
625 last = 0;
626 else while (last->nextSibling() != item)
627 last = last->nextSibling();
628 delete item;
629 }
630 }
Boris Barbulovski59e56442015-09-22 11:36:18 -0700631}
632
633void ConfigList::keyPressEvent(QKeyEvent* ev)
634{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700635 QTreeWidgetItem* i = currentItem();
636 ConfigItem* item;
637 struct menu *menu;
638 enum prop_type type;
639
640 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
641 emit parentSelected();
642 ev->accept();
643 return;
644 }
645
646 if (!i) {
647 Parent::keyPressEvent(ev);
648 return;
649 }
650 item = (ConfigItem*)i;
651
652 switch (ev->key()) {
653 case Qt::Key_Return:
654 case Qt::Key_Enter:
655 if (item->goParent) {
656 emit parentSelected();
657 break;
658 }
659 menu = item->menu;
660 if (!menu)
661 break;
662 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
663 if (type == P_MENU && rootEntry != menu &&
664 mode != fullMode && mode != menuMode) {
665 emit menuSelected(menu);
666 break;
667 }
668 case Qt::Key_Space:
669 changeValue(item);
670 break;
671 case Qt::Key_N:
672 setValue(item, no);
673 break;
674 case Qt::Key_M:
675 setValue(item, mod);
676 break;
677 case Qt::Key_Y:
678 setValue(item, yes);
679 break;
680 default:
681 Parent::keyPressEvent(ev);
682 return;
683 }
684 ev->accept();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700685}
686
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700687void ConfigList::mousePressEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700688{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700689 //QPoint p(contentsToViewport(e->pos()));
690 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
691 Parent::mousePressEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700692}
693
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700694void ConfigList::mouseReleaseEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700695{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700696 QPoint p = e->pos();
697 ConfigItem* item = (ConfigItem*)itemAt(p);
698 struct menu *menu;
699 enum prop_type ptype;
700 QIcon icon;
701 int idx, x;
702
703 if (!item)
704 goto skip;
705
706 menu = item->menu;
707 x = header()->offset() + p.x();
708 idx = header()->sectionPosition(x);
709 switch (idx) {
710 case promptColIdx:
711 icon = item->pixmap(promptColIdx);
712 break;
713 case noColIdx:
714 setValue(item, no);
715 break;
716 case modColIdx:
717 setValue(item, mod);
718 break;
719 case yesColIdx:
720 setValue(item, yes);
721 break;
722 case dataColIdx:
723 changeValue(item);
724 break;
725 }
726
727skip:
728 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
729 Parent::mouseReleaseEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700730}
731
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700732void ConfigList::mouseMoveEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700733{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700734 //QPoint p(contentsToViewport(e->pos()));
735 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
736 Parent::mouseMoveEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700737}
738
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700739void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700740{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700741 QPoint p = e->pos(); // TODO: Check if this works(was contentsToViewport).
742 ConfigItem* item = (ConfigItem*)itemAt(p);
743 struct menu *menu;
744 enum prop_type ptype;
745
746 if (!item)
747 goto skip;
748 if (item->goParent) {
749 emit parentSelected();
750 goto skip;
751 }
752 menu = item->menu;
753 if (!menu)
754 goto skip;
755 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
756 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
757 emit menuSelected(menu);
758 else if (menu->sym)
759 changeValue(item);
760
761skip:
762 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
763 Parent::mouseDoubleClickEvent(e);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700764}
765
766void ConfigList::focusInEvent(QFocusEvent *e)
767{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700768 struct menu *menu = NULL;
769
770 Parent::focusInEvent(e);
771
772 ConfigItem* item = (ConfigItem *)currentItem();
773 if (item) {
774 item->setSelected(true);
775 menu = item->menu;
776 }
777 emit gotFocus(menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700778}
779
780void ConfigList::contextMenuEvent(QContextMenuEvent *e)
781{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700782 if (e->y() <= header()->geometry().bottom()) {
783 if (!headerPopup) {
784 QAction *action;
785
786 headerPopup = new QMenu(this);
787 action = new QAction(_("Show Name"), this);
788 action->setCheckable(true);
789 connect(action, SIGNAL(toggled(bool)),
790 parent(), SLOT(setShowName(bool)));
791 connect(parent(), SIGNAL(showNameChanged(bool)),
792 action, SLOT(setOn(bool)));
793 action->setChecked(showName);
794 headerPopup->addAction(action);
795 action = new QAction(_("Show Range"), this);
796 action->setCheckable(true);
797 connect(action, SIGNAL(toggled(bool)),
798 parent(), SLOT(setShowRange(bool)));
799 connect(parent(), SIGNAL(showRangeChanged(bool)),
800 action, SLOT(setOn(bool)));
801 action->setChecked(showRange);
802 headerPopup->addAction(action);
803 action = new QAction(_("Show Data"), this);
804 action->setCheckable(true);
805 connect(action, SIGNAL(toggled(bool)),
806 parent(), SLOT(setShowData(bool)));
807 connect(parent(), SIGNAL(showDataChanged(bool)),
808 action, SLOT(setOn(bool)));
809 action->setChecked(showData);
810 headerPopup->addAction(action);
811 }
812 headerPopup->exec(e->globalPos());
813 e->accept();
814 } else
815 e->ignore();
Boris Barbulovski59e56442015-09-22 11:36:18 -0700816}
817
Li Zefan39a48972010-05-10 16:33:41 +0800818ConfigView*ConfigView::viewList;
819QAction *ConfigView::showNormalAction;
820QAction *ConfigView::showAllAction;
821QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Roman Zippel7fc925f2006-06-08 22:12:46 -0700823ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700824 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
Boris Barbulovski9bd36ed2015-09-22 11:36:22 -0700826 setObjectName(name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700827 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700828 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700829
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700830 list = new ConfigList(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700831 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 lineEdit = new ConfigLineEdit(this);
833 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700834 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 this->nextView = viewList;
837 viewList = this;
838}
839
840ConfigView::~ConfigView(void)
841{
842 ConfigView** vp;
843
844 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
845 if (*vp == this) {
846 *vp = nextView;
847 break;
848 }
849 }
850}
851
Li Zefan39a48972010-05-10 16:33:41 +0800852void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700853{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700854 if (act == showNormalAction)
855 list->optMode = normalOpt;
856 else if (act == showAllAction)
857 list->optMode = allOpt;
858 else
859 list->optMode = promptOpt;
860
861 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700862}
863
864void ConfigView::setShowName(bool b)
865{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700866 if (list->showName != b) {
867 list->showName = b;
868 list->reinit();
869 emit showNameChanged(b);
870 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700871}
872
873void ConfigView::setShowRange(bool b)
874{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700875 if (list->showRange != b) {
876 list->showRange = b;
877 list->reinit();
878 emit showRangeChanged(b);
879 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700880}
881
882void ConfigView::setShowData(bool b)
883{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700884 if (list->showData != b) {
885 list->showData = b;
886 list->reinit();
887 emit showDataChanged(b);
888 }
889}
890
891void ConfigList::setAllOpen(bool open)
892{
893 QTreeWidgetItemIterator it(this);
894
895 while (*it) {
896 (*it)->setExpanded(open);
897
898 ++it;
899 }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700900}
901
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700902void ConfigView::updateList(ConfigItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700903{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700904 ConfigView* v;
905
906 for (v = viewList; v; v = v->nextView)
907 v->list->updateList(item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908}
909
910void ConfigView::updateListAll(void)
911{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700912 ConfigView* v;
913
914 for (v = viewList; v; v = v->nextView)
915 v->list->updateListAll();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916}
917
Roman Zippel43bf6122006-06-08 22:12:45 -0700918ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700919 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700920{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700921 setObjectName(name);
922
923
924 if (!objectName().isEmpty()) {
925 configSettings->beginGroup(objectName());
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700926 _showDebug = configSettings->value("/showDebug", false).toBool();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700927 configSettings->endGroup();
928 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
929 }
930}
931
932void ConfigInfoView::saveSettings(void)
933{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700934 if (!objectName().isEmpty()) {
935 configSettings->beginGroup(objectName());
936 configSettings->setValue("/showDebug", showDebug());
937 configSettings->endGroup();
938 }
Roman Zippel43bf6122006-06-08 22:12:45 -0700939}
940
941void ConfigInfoView::setShowDebug(bool b)
942{
943 if (_showDebug != b) {
944 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +0200945 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700946 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -0700947 else if (sym)
948 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -0700949 emit showDebugChanged(b);
950 }
951}
952
953void ConfigInfoView::setInfo(struct menu *m)
954{
Alexander Stein133c5f72010-08-31 17:34:37 +0200955 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -0700956 return;
Alexander Stein133c5f72010-08-31 17:34:37 +0200957 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -0800958 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +0200959 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700960 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -0800961 else
Roman Zippel43bf6122006-06-08 22:12:45 -0700962 menuInfo();
963}
964
Roman Zippelab45d192006-06-08 22:12:47 -0700965void ConfigInfoView::symbolInfo(void)
966{
967 QString str;
968
969 str += "<big>Symbol: <b>";
970 str += print_filter(sym->name);
971 str += "</b></big><br><br>value: ";
972 str += print_filter(sym_get_string_value(sym));
973 str += "<br>visibility: ";
974 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
975 str += "<br>";
976 str += debug_info(sym);
977
978 setText(str);
979}
980
Roman Zippel43bf6122006-06-08 22:12:45 -0700981void ConfigInfoView::menuInfo(void)
982{
983 struct symbol* sym;
984 QString head, debug, help;
985
Alexander Stein133c5f72010-08-31 17:34:37 +0200986 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -0700987 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +0200988 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -0700989 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +0200990 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -0700991 head += "</b></big>";
992 if (sym->name) {
993 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -0700994 if (showDebug())
995 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -0700996 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -0700997 if (showDebug())
998 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -0700999 head += ")";
1000 }
1001 } else if (sym->name) {
1002 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001003 if (showDebug())
1004 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001005 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001006 if (showDebug())
1007 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001008 head += "</b></big>";
1009 }
1010 head += "<br><br>";
1011
1012 if (showDebug())
1013 debug = debug_info(sym);
1014
Cheng Renquand74c15f2009-07-12 16:11:47 +08001015 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001016 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001017 help = print_filter(str_get(&help_gstr));
1018 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001019 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001020 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001021 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001022 head += "</b></big><br><br>";
1023 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001024 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001025 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001026 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001027 debug += "<br><br>";
1028 }
1029 }
1030 }
1031 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001032 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001033
1034 setText(head + debug + help);
1035}
1036
1037QString ConfigInfoView::debug_info(struct symbol *sym)
1038{
1039 QString debug;
1040
1041 debug += "type: ";
1042 debug += print_filter(sym_type_name(sym->type));
1043 if (sym_is_choice(sym))
1044 debug += " (choice)";
1045 debug += "<br>";
1046 if (sym->rev_dep.expr) {
1047 debug += "reverse dep: ";
1048 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1049 debug += "<br>";
1050 }
1051 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1052 switch (prop->type) {
1053 case P_PROMPT:
1054 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -07001055 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Roman Zippel43bf6122006-06-08 22:12:45 -07001056 debug += print_filter(_(prop->text));
Roman Zippelab45d192006-06-08 22:12:47 -07001057 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001058 break;
1059 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001060 case P_SELECT:
1061 case P_RANGE:
1062 case P_ENV:
1063 debug += prop_get_type_name(prop->type);
1064 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001065 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1066 debug += "<br>";
1067 break;
1068 case P_CHOICE:
1069 if (sym_is_choice(sym)) {
1070 debug += "choice: ";
1071 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1072 debug += "<br>";
1073 }
1074 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001075 default:
1076 debug += "unknown property: ";
1077 debug += prop_get_type_name(prop->type);
1078 debug += "<br>";
1079 }
1080 if (prop->visible.expr) {
1081 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1082 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1083 debug += "<br>";
1084 }
1085 }
1086 debug += "<br>";
1087
1088 return debug;
1089}
1090
1091QString ConfigInfoView::print_filter(const QString &str)
1092{
1093 QRegExp re("[<>&\"\\n]");
1094 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001095 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1096 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001097 case '<':
1098 res.replace(i, 1, "&lt;");
1099 i += 4;
1100 break;
1101 case '>':
1102 res.replace(i, 1, "&gt;");
1103 i += 4;
1104 break;
1105 case '&':
1106 res.replace(i, 1, "&amp;");
1107 i += 5;
1108 break;
1109 case '"':
1110 res.replace(i, 1, "&quot;");
1111 i += 6;
1112 break;
1113 case '\n':
1114 res.replace(i, 1, "<br>");
1115 i += 4;
1116 break;
1117 }
1118 }
1119 return res;
1120}
1121
Roman Zippelab45d192006-06-08 22:12:47 -07001122void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001123{
Roman Zippelab45d192006-06-08 22:12:47 -07001124 QString* text = reinterpret_cast<QString*>(data);
1125 QString str2 = print_filter(str);
1126
1127 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1128 *text += QString().sprintf("<a href=\"s%p\">", sym);
1129 *text += str2;
1130 *text += "</a>";
1131 } else
1132 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001133}
1134
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001135QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001136{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001137 QMenu* popup = Parent::createStandardContextMenu(pos);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001138 QAction* action = new QAction(_("Show Debug Info"), popup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001139 action->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001140 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1141 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001142 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001143 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001144 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001145 return popup;
1146}
1147
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001148void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001149{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001150 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001151}
1152
Marco Costalba63431e72006-10-05 19:12:59 +02001153ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001154 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001155{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001156 setObjectName(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001157 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -07001158
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001159 QVBoxLayout* layout1 = new QVBoxLayout(this);
1160 layout1->setContentsMargins(11, 11, 11, 11);
1161 layout1->setSpacing(6);
1162 QHBoxLayout* layout2 = new QHBoxLayout(0);
1163 layout2->setContentsMargins(0, 0, 0, 0);
1164 layout2->setSpacing(6);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001165 layout2->addWidget(new QLabel(_("Find:"), this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001166 editField = new QLineEdit(this);
1167 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1168 layout2->addWidget(editField);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001169 searchButton = new QPushButton(_("Search"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001170 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -07001171 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1172 layout2->addWidget(searchButton);
1173 layout1->addLayout(layout2);
1174
Roman Zippel7fc925f2006-06-08 22:12:46 -07001175 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001176 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001177 list = new ConfigView(split, name);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001178 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001179 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001180 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1181 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001182 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1183 parent, SLOT(setMenuLink(struct menu *)));
1184
Roman Zippel43bf6122006-06-08 22:12:45 -07001185 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001186
1187 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001188 QVariant x, y;
1189 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001190 bool ok;
1191
1192 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001193 width = configSettings->value("/window width", parent->width() / 2).toInt();
1194 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001195 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001196 x = configSettings->value("/window x");
1197 y = configSettings->value("/window y");
1198 if ((x.isValid())&&(y.isValid()))
1199 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001200 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001201 if (ok)
1202 split->setSizes(sizes);
1203 configSettings->endGroup();
1204 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1205 }
1206}
1207
1208void ConfigSearchWindow::saveSettings(void)
1209{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001210 if (!objectName().isEmpty()) {
1211 configSettings->beginGroup(objectName());
1212 configSettings->setValue("/window x", pos().x());
1213 configSettings->setValue("/window y", pos().y());
1214 configSettings->setValue("/window width", size().width());
1215 configSettings->setValue("/window height", size().height());
1216 configSettings->writeSizes("/split", split->sizes());
1217 configSettings->endGroup();
1218 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001219}
1220
1221void ConfigSearchWindow::search(void)
1222{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001223 struct symbol **p;
1224 struct property *prop;
1225 ConfigItem *lastItem = NULL;
1226
1227 free(result);
1228 list->list->clear();
1229 info->clear();
1230
1231 result = sym_re_search(editField->text().toLatin1());
1232 if (!result)
1233 return;
1234 for (p = result; *p; p++) {
1235 for_all_prompts((*p), prop)
1236 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1237 menu_is_visible(prop->menu));
1238 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001239}
1240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241/*
1242 * Construct the complete config widget
1243 */
1244ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001245 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
1247 QMenuBar* menu;
Boris Barbulovski92119932015-09-22 11:36:16 -07001248 bool ok = true;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001249 QVariant x, y;
1250 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001251 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001253 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001254 snprintf(title, sizeof(title), "%s%s",
1255 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001256 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001257 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001258 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001260 width = configSettings->value("/window width", d->width() - 64).toInt();
1261 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001263 x = configSettings->value("/window x");
1264 y = configSettings->value("/window y");
1265 if ((x.isValid())&&(y.isValid()))
1266 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001269 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 setCentralWidget(split1);
1271
Roman Zippel7fc925f2006-06-08 22:12:46 -07001272 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 menuList = menuView->list;
1274
1275 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001276 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
1278 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -07001279 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 configList = configView->list;
1281
Roman Zippel7fc925f2006-06-08 22:12:46 -07001282 helpText = new ConfigInfoView(split2, "help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001283 //helpText->setTextFormat(Qt::RichText);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 setTabOrder(configList, helpText);
1286 configList->setFocus();
1287
1288 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001289 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001290 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001292 backAction = new QAction(QPixmap(xpm_back), _("Back"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001293 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001294 backAction->setEnabled(false);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001295 QAction *quitAction = new QAction(_("&Quit"), this);
1296 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Boris Barbulovski92119932015-09-22 11:36:16 -07001297 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001298 QAction *loadAction = new QAction(QPixmap(xpm_load), _("&Load"), this);
1299 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Boris Barbulovski92119932015-09-22 11:36:16 -07001300 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001301 saveAction = new QAction(QPixmap(xpm_save), _("&Save"), this);
1302 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Boris Barbulovski92119932015-09-22 11:36:16 -07001303 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001304 conf_set_changed_callback(conf_changed);
1305 // Set saveAction's initial state
1306 conf_changed();
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001307 QAction *saveAsAction = new QAction(_("Save &As..."), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001308 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001309 QAction *searchAction = new QAction(_("&Find"), this);
1310 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -07001311 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001312 singleViewAction = new QAction(QPixmap(xpm_single_view), _("Single View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001313 singleViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001314 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001315 splitViewAction = new QAction(QPixmap(xpm_split_view), _("Split View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001316 splitViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001317 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
Boris Barbulovski780505e2015-09-22 11:36:13 -07001318 fullViewAction = new QAction(QPixmap(xpm_tree_view), _("Full View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001319 fullViewAction->setCheckable(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001320 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001322 QAction *showNameAction = new QAction(_("Show Name"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001323 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001324 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001325 showNameAction->setChecked(configView->showName());
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001326 QAction *showRangeAction = new QAction(_("Show Range"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001327 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001328 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001329 QAction *showDataAction = new QAction(_("Show Data"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001330 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001331 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +08001332
1333 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001334 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -07001335 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +08001336 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -07001337 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +08001338 SLOT(setOptionMode(QAction *)));
1339
Alexander Stein133c5f72010-08-31 17:34:37 +02001340 configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
1341 configView->showAllAction = new QAction(_("Show All Options"), optGroup);
1342 configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001343 configView->showNormalAction->setCheckable(true);
1344 configView->showAllAction->setCheckable(true);
1345 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +08001346
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001347 QAction *showDebugAction = new QAction( _("Show Debug Info"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001348 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -07001349 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001350 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001352 QAction *showIntroAction = new QAction( _("Introduction"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001353 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001354 QAction *showAboutAction = new QAction( _("About"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -07001355 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001358 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001360 toolBar->addAction(loadAction);
1361 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001363 toolBar->addAction(singleViewAction);
1364 toolBar->addAction(splitViewAction);
1365 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 // create config menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001368 QMenu* config = menu->addMenu(_("&File"));
1369 config->addAction(loadAction);
1370 config->addAction(saveAction);
1371 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001372 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001373 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Shlomi Fish66e7c722007-02-14 00:32:58 -08001375 // create edit menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001376 QMenu* editMenu = menu->addMenu(_("&Edit"));
1377 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001378
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 // create options menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001380 QMenu* optionMenu = menu->addMenu(_("&Option"));
1381 optionMenu->addAction(showNameAction);
1382 optionMenu->addAction(showRangeAction);
1383 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001384 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001385 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -07001386 optionMenu->addSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
1388 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001389 menu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001390 QMenu* helpMenu = menu->addMenu(_("&Help"));
1391 helpMenu->addAction(showIntroAction);
1392 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001394 connect(configList, SIGNAL(menuChanged(struct menu *)),
1395 helpText, SLOT(setInfo(struct menu *)));
1396 connect(configList, SIGNAL(menuSelected(struct menu *)),
1397 SLOT(changeMenu(struct menu *)));
1398 connect(configList, SIGNAL(parentSelected()),
1399 SLOT(goBack()));
1400 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1401 helpText, SLOT(setInfo(struct menu *)));
1402 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1403 SLOT(changeMenu(struct menu *)));
1404
1405 connect(configList, SIGNAL(gotFocus(struct menu *)),
1406 helpText, SLOT(setInfo(struct menu *)));
1407 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1408 helpText, SLOT(setInfo(struct menu *)));
1409 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1410 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001411 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1412 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001414 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 if (listMode == "single")
1416 showSingleView();
1417 else if (listMode == "full")
1418 showFullView();
1419 else /*if (listMode == "split")*/
1420 showSplitView();
1421
1422 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001423 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 if (ok)
1425 split1->setSizes(sizes);
1426
Roman Zippel7fc925f2006-06-08 22:12:46 -07001427 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 if (ok)
1429 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430}
1431
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432void ConfigMainWindow::loadConfig(void)
1433{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001434 QString s = QFileDialog::getOpenFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 if (s.isNull())
1436 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001437 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001438 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 ConfigView::updateListAll();
1440}
1441
Michal Marekbac6aa82011-05-25 15:10:25 +02001442bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
Michal Marekbac6aa82011-05-25 15:10:25 +02001444 if (conf_write(NULL)) {
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001445 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Michal Marekbac6aa82011-05-25 15:10:25 +02001446 return false;
1447 }
1448 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
1451void ConfigMainWindow::saveConfigAs(void)
1452{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001453 QString s = QFileDialog::getSaveFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 if (s.isNull())
1455 return;
Arnaud Lacombed49e4682011-05-24 14:16:18 -04001456 saveConfig();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
Roman Zippel43bf6122006-06-08 22:12:45 -07001459void ConfigMainWindow::searchConfig(void)
1460{
1461 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001462 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001463 searchWindow->show();
1464}
1465
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466void ConfigMainWindow::changeMenu(struct menu *menu)
1467{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001468 configList->setRootMenu(menu);
1469 if (configList->rootEntry->parent == &rootmenu)
1470 backAction->setEnabled(false);
1471 else
1472 backAction->setEnabled(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Roman Zippelb65a47e2006-06-08 22:12:47 -07001475void ConfigMainWindow::setMenuLink(struct menu *menu)
1476{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001477 struct menu *parent;
1478 ConfigList* list = NULL;
1479 ConfigItem* item;
1480
1481 if (configList->menuSkip(menu))
1482 return;
1483
1484 switch (configList->mode) {
1485 case singleMode:
1486 list = configList;
1487 parent = menu_get_parent_menu(menu);
1488 if (!parent)
1489 return;
1490 list->setRootMenu(parent);
1491 break;
1492 case symbolMode:
1493 if (menu->flags & MENU_ROOT) {
1494 configList->setRootMenu(menu);
1495 configList->clearSelection();
1496 list = menuList;
1497 } else {
1498 list = configList;
1499 parent = menu_get_parent_menu(menu->parent);
1500 if (!parent)
1501 return;
1502 item = menuList->findConfigItem(parent);
1503 if (item) {
1504 item->setSelected(true);
1505 menuList->scrollToItem(item);
1506 }
1507 list->setRootMenu(parent);
1508 }
1509 break;
1510 case fullMode:
1511 list = configList;
1512 break;
1513 default:
1514 break;
1515 }
1516
1517 if (list) {
1518 item = list->findConfigItem(menu);
1519 if (item) {
1520 item->setSelected(true);
1521 list->scrollToItem(item);
1522 list->setFocus();
1523 }
1524 }
Roman Zippelb65a47e2006-06-08 22:12:47 -07001525}
1526
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527void ConfigMainWindow::listFocusChanged(void)
1528{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001529 if (menuList->mode == menuMode)
1530 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531}
1532
1533void ConfigMainWindow::goBack(void)
1534{
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001535 ConfigItem* item;
1536
1537 configList->setParentMenu();
1538 if (configList->rootEntry == &rootmenu)
1539 backAction->setEnabled(false);
1540 item = (ConfigItem*)menuList->selectedItems().first();
1541 while (item) {
1542 if (item->menu == configList->rootEntry) {
1543 item->setSelected(true);
1544 break;
1545 }
1546 item = (ConfigItem*)item->parent();
1547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
1550void ConfigMainWindow::showSingleView(void)
1551{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001552 singleViewAction->setEnabled(false);
1553 singleViewAction->setChecked(true);
1554 splitViewAction->setEnabled(true);
1555 splitViewAction->setChecked(false);
1556 fullViewAction->setEnabled(true);
1557 fullViewAction->setChecked(false);
1558
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001560 menuList->setRootMenu(0);
1561 configList->mode = singleMode;
1562 if (configList->rootEntry == &rootmenu)
1563 configList->updateListAll();
1564 else
1565 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 configList->setFocus();
1567}
1568
1569void ConfigMainWindow::showSplitView(void)
1570{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001571 singleViewAction->setEnabled(true);
1572 singleViewAction->setChecked(false);
1573 splitViewAction->setEnabled(false);
1574 splitViewAction->setChecked(true);
1575 fullViewAction->setEnabled(true);
1576 fullViewAction->setChecked(false);
1577
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001578 configList->mode = symbolMode;
1579 if (configList->rootEntry == &rootmenu)
1580 configList->updateListAll();
1581 else
1582 configList->setRootMenu(&rootmenu);
1583 configList->setAllOpen(true);
1584 configApp->processEvents();
1585 menuList->mode = menuMode;
1586 menuList->setRootMenu(&rootmenu);
1587 menuList->setAllOpen(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 menuView->show();
1589 menuList->setFocus();
1590}
1591
1592void ConfigMainWindow::showFullView(void)
1593{
Boris Barbulovski780505e2015-09-22 11:36:13 -07001594 singleViewAction->setEnabled(true);
1595 singleViewAction->setChecked(false);
1596 splitViewAction->setEnabled(true);
1597 splitViewAction->setChecked(false);
1598 fullViewAction->setEnabled(false);
1599 fullViewAction->setChecked(true);
1600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 menuView->hide();
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001602 menuList->setRootMenu(0);
1603 configList->mode = fullMode;
1604 if (configList->rootEntry == &rootmenu)
1605 configList->updateListAll();
1606 else
1607 configList->setRootMenu(&rootmenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 configList->setFocus();
1609}
1610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611/*
1612 * ask for saving configuration before quitting
1613 * TODO ask only when something changed
1614 */
1615void ConfigMainWindow::closeEvent(QCloseEvent* e)
1616{
Karsten Wieseb3214292006-12-13 00:34:06 -08001617 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 e->accept();
1619 return;
1620 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001621 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001623 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1624 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1625 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 switch (mb.exec()) {
1627 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001628 if (saveConfig())
1629 e->accept();
1630 else
1631 e->ignore();
1632 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 case QMessageBox::No:
1634 e->accept();
1635 break;
1636 case QMessageBox::Cancel:
1637 e->ignore();
1638 break;
1639 }
1640}
1641
1642void ConfigMainWindow::showIntro(void)
1643{
Arnaud Lacombe652cf982010-08-14 23:51:40 -04001644 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 "For each option, a blank box indicates the feature is disabled, a check\n"
1646 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1647 "as a module. Clicking on the box will cycle through the three states.\n\n"
1648 "If you do not see an option (e.g., a device driver) that you believe\n"
1649 "should be present, try turning on Show All Options under the Options menu.\n"
1650 "Although there is no cross reference yet to help you figure out what other\n"
1651 "options must be enabled to support the option you are interested in, you can\n"
1652 "still view the help of a grayed-out option.\n\n"
1653 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001654 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
1656 QMessageBox::information(this, "qconf", str);
1657}
1658
1659void ConfigMainWindow::showAbout(void)
1660{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001661 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1662 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
1664 QMessageBox::information(this, "qconf", str);
1665}
1666
1667void ConfigMainWindow::saveSettings(void)
1668{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001669 configSettings->setValue("/window x", pos().x());
1670 configSettings->setValue("/window y", pos().y());
1671 configSettings->setValue("/window width", size().width());
1672 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674 QString entry;
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001675 switch(configList->mode) {
1676 case singleMode :
1677 entry = "single";
1678 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Boris Barbulovskid5d973c2015-09-22 11:36:19 -07001680 case symbolMode :
1681 entry = "split";
1682 break;
1683
1684 case fullMode :
1685 entry = "full";
1686 break;
1687
1688 default:
1689 break;
1690 }
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001691 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Roman Zippel7fc925f2006-06-08 22:12:46 -07001693 configSettings->writeSizes("/split1", split1->sizes());
1694 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695}
1696
Karsten Wiese3b354c52006-12-13 00:34:08 -08001697void ConfigMainWindow::conf_changed(void)
1698{
1699 if (saveAction)
1700 saveAction->setEnabled(conf_get_changed());
1701}
1702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703void fixup_rootmenu(struct menu *menu)
1704{
1705 struct menu *child;
1706 static int menu_cnt = 0;
1707
1708 menu->flags |= MENU_ROOT;
1709 for (child = menu->list; child; child = child->next) {
1710 if (child->prompt && child->prompt->type == P_MENU) {
1711 menu_cnt++;
1712 fixup_rootmenu(child);
1713 menu_cnt--;
1714 } else if (!menu_cnt)
1715 fixup_rootmenu(child);
1716 }
1717}
1718
1719static const char *progname;
1720
1721static void usage(void)
1722{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07001723 printf(_("%s [-s] <config>\n").toLatin1().constData(), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 exit(0);
1725}
1726
1727int main(int ac, char** av)
1728{
1729 ConfigMainWindow* v;
1730 const char *name;
1731
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001732 bindtextdomain(PACKAGE, LOCALEDIR);
1733 textdomain(PACKAGE);
1734
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 progname = av[0];
1736 configApp = new QApplication(ac, av);
1737 if (ac > 1 && av[1][0] == '-') {
1738 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001739 case 's':
1740 conf_set_message_callback(NULL);
1741 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 case 'h':
1743 case '?':
1744 usage();
1745 }
1746 name = av[2];
1747 } else
1748 name = av[1];
1749 if (!name)
1750 usage();
1751
1752 conf_parse(name);
1753 fixup_rootmenu(&rootmenu);
1754 conf_read(NULL);
1755 //zconfdump(stdout);
1756
Roman Zippel7fc925f2006-06-08 22:12:46 -07001757 configSettings = new ConfigSettings();
1758 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 v = new ConfigMainWindow();
1760
1761 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1763 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001764 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 configApp->exec();
1766
Roman Zippel7fc925f2006-06-08 22:12:46 -07001767 configSettings->endGroup();
1768 delete configSettings;
1769
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 return 0;
1771}