blob: c2f9767514deb154d167962f50306028482d591d [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>
Alexander Stein133c5f72010-08-31 17:34:37 +020012#include <q3header.h>
Boris Barbulovskibea00772015-09-22 11:36:04 -070013#include <QFileDialog>
Boris Barbulovski76bede82015-09-22 11:36:07 -070014#include <QMenu>
Alexander Stein133c5f72010-08-31 17:34:37 +020015
16#include <qapplication.h>
Markus Heidelberg8d90c972009-05-18 01:36:52 +020017#include <qdesktopwidget.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <qtoolbar.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070019#include <qlayout.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <qsplitter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <qlineedit.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070022#include <qlabel.h>
23#include <qpushbutton.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <qmenubar.h>
25#include <qmessagebox.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <qregexp.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020027#include <qevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#include <stdlib.h>
30
31#include "lkc.h"
32#include "qconf.h"
33
34#include "qconf.moc"
35#include "images.c"
36
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070037#ifdef _
38# undef _
39# define _ qgettext
40#endif
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070043static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Boris Barbulovski85eaf282015-09-22 11:36:03 -070045QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080046
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070047static inline QString qgettext(const char* str)
48{
Roman Zippel43bf6122006-06-08 22:12:45 -070049 return QString::fromLocal8Bit(gettext(str));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070050}
51
52static inline QString qgettext(const QString& str)
53{
Roman Zippel43bf6122006-06-08 22:12:45 -070054 return QString::fromLocal8Bit(gettext(str.latin1()));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070055}
56
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010057ConfigSettings::ConfigSettings()
58 : QSettings("kernel.org", "qconf")
59{
60}
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/**
63 * Reads a list of integer values from the application settings.
64 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070065QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070067 QList<int> result;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 QStringList entryList = readListEntry(key, ok);
Li Zefanc1f96f02010-05-07 13:58:04 +080069 QStringList::Iterator it;
70
71 for (it = entryList.begin(); it != entryList.end(); ++it)
72 result.push_back((*it).toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 return result;
75}
76
77/**
78 * Writes a list of integer values to the application settings.
79 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070080bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070083 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 for (it = value.begin(); it != value.end(); ++it)
86 stringList.push_back(QString::number(*it));
87 return writeEntry(key, stringList);
88}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091/*
92 * set the new data
93 * TODO check the value
94 */
95void ConfigItem::okRename(int col)
96{
97 Parent::okRename(col);
98 sym_set_string_value(menu->sym, text(dataColIdx).latin1());
Karsten Wiese49e56462007-02-14 00:32:57 -080099 listView()->updateList(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102/*
103 * update the displayed of a menu entry
104 */
105void ConfigItem::updateMenu(void)
106{
107 ConfigList* list;
108 struct symbol* sym;
109 struct property *prop;
110 QString prompt;
111 int type;
112 tristate expr;
113
114 list = listView();
115 if (goParent) {
116 setPixmap(promptColIdx, list->menuBackPix);
117 prompt = "..";
118 goto set_prompt;
119 }
120
121 sym = menu->sym;
122 prop = menu->prompt;
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100123 prompt = _(menu_get_prompt(menu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 if (prop) switch (prop->type) {
126 case P_MENU:
127 if (list->mode == singleMode || list->mode == symbolMode) {
128 /* a menuconfig entry is displayed differently
129 * depending whether it's at the view root or a child.
130 */
131 if (sym && list->rootEntry == menu)
132 break;
133 setPixmap(promptColIdx, list->menuPix);
134 } else {
135 if (sym)
136 break;
137 setPixmap(promptColIdx, 0);
138 }
139 goto set_prompt;
140 case P_COMMENT:
141 setPixmap(promptColIdx, 0);
142 goto set_prompt;
143 default:
144 ;
145 }
146 if (!sym)
147 goto set_prompt;
148
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700149 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 type = sym_get_type(sym);
152 switch (type) {
153 case S_BOOLEAN:
154 case S_TRISTATE:
155 char ch;
156
Li Zefan39a48972010-05-10 16:33:41 +0800157 if (!sym_is_changable(sym) && list->optMode == normalOpt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 setPixmap(promptColIdx, 0);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700159 setText(noColIdx, QString::null);
160 setText(modColIdx, QString::null);
161 setText(yesColIdx, QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 break;
163 }
164 expr = sym_get_tristate_value(sym);
165 switch (expr) {
166 case yes:
167 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
168 setPixmap(promptColIdx, list->choiceYesPix);
169 else
170 setPixmap(promptColIdx, list->symbolYesPix);
171 setText(yesColIdx, "Y");
172 ch = 'Y';
173 break;
174 case mod:
175 setPixmap(promptColIdx, list->symbolModPix);
176 setText(modColIdx, "M");
177 ch = 'M';
178 break;
179 default:
180 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
181 setPixmap(promptColIdx, list->choiceNoPix);
182 else
183 setPixmap(promptColIdx, list->symbolNoPix);
184 setText(noColIdx, "N");
185 ch = 'N';
186 break;
187 }
188 if (expr != no)
189 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
190 if (expr != mod)
191 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
192 if (expr != yes)
193 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
194
195 setText(dataColIdx, QChar(ch));
196 break;
197 case S_INT:
198 case S_HEX:
199 case S_STRING:
200 const char* data;
201
202 data = sym_get_string_value(sym);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 int i = list->mapIdx(dataColIdx);
205 if (i >= 0)
206 setRenameEnabled(i, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 setText(dataColIdx, data);
208 if (type == S_STRING)
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700209 prompt = QString("%1: %2").arg(prompt).arg(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 else
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700211 prompt = QString("(%2) %1").arg(prompt).arg(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 break;
213 }
214 if (!sym_has_value(sym) && visible)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100215 prompt += _(" (NEW)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216set_prompt:
217 setText(promptColIdx, prompt);
218}
219
220void ConfigItem::testUpdateMenu(bool v)
221{
222 ConfigItem* i;
223
224 visible = v;
225 if (!menu)
226 return;
227
228 sym_calc_value(menu->sym);
229 if (menu->flags & MENU_CHANGED) {
230 /* the menu entry changed, so update all list items */
231 menu->flags &= ~MENU_CHANGED;
232 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
233 i->updateMenu();
234 } else if (listView()->updateAll)
235 updateMenu();
236}
237
238void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
239{
240 ConfigList* list = listView();
241
242 if (visible) {
243 if (isSelected() && !list->hasFocus() && list->mode == menuMode)
244 Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
245 else
246 Parent::paintCell(p, cg, column, width, align);
247 } else
248 Parent::paintCell(p, list->disabledColorGroup, column, width, align);
249}
250
251/*
252 * construct a menu entry
253 */
254void ConfigItem::init(void)
255{
256 if (menu) {
257 ConfigList* list = listView();
258 nextItem = (ConfigItem*)menu->data;
259 menu->data = this;
260
261 if (list->mode != fullMode)
262 setOpen(TRUE);
263 sym_calc_value(menu->sym);
264 }
265 updateMenu();
266}
267
268/*
269 * destruct a menu entry
270 */
271ConfigItem::~ConfigItem(void)
272{
273 if (menu) {
274 ConfigItem** ip = (ConfigItem**)&menu->data;
275 for (; *ip; ip = &(*ip)->nextItem) {
276 if (*ip == this) {
277 *ip = nextItem;
278 break;
279 }
280 }
281 }
282}
283
Roman Zippel43bf6122006-06-08 22:12:45 -0700284ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
285 : Parent(parent)
286{
287 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
288}
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290void ConfigLineEdit::show(ConfigItem* i)
291{
292 item = i;
293 if (sym_get_string_value(item->menu->sym))
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700294 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 else
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700296 setText(QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 Parent::show();
298 setFocus();
299}
300
301void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
302{
303 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200304 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200306 case Qt::Key_Return:
307 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 sym_set_string_value(item->menu->sym, text().latin1());
309 parent()->updateList(item);
310 break;
311 default:
312 Parent::keyPressEvent(e);
313 return;
314 }
315 e->accept();
316 parent()->list->setFocus();
317 hide();
318}
319
Roman Zippel7fc925f2006-06-08 22:12:46 -0700320ConfigList::ConfigList(ConfigView* p, const char *name)
321 : Parent(p, name),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 updateAll(false),
323 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
324 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
325 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Li Zefan39a48972010-05-10 16:33:41 +0800326 showName(false), showRange(false), showData(false), optMode(normalOpt),
Roman Zippel7fc925f2006-06-08 22:12:46 -0700327 rootEntry(0), headerPopup(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
329 int i;
330
331 setSorting(-1);
332 setRootIsDecorated(TRUE);
333 disabledColorGroup = palette().active();
334 disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
335 inactivedColorGroup = palette().active();
336 inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
337
338 connect(this, SIGNAL(selectionChanged(void)),
339 SLOT(updateSelection(void)));
340
Roman Zippel7fc925f2006-06-08 22:12:46 -0700341 if (name) {
342 configSettings->beginGroup(name);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700343 showName = configSettings->readBoolEntry("/showName", false);
344 showRange = configSettings->readBoolEntry("/showRange", false);
345 showData = configSettings->readBoolEntry("/showData", false);
Li Zefan39a48972010-05-10 16:33:41 +0800346 optMode = (enum optionMode)configSettings->readNumEntry("/optionMode", false);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700347 configSettings->endGroup();
348 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350
351 for (i = 0; i < colNr; i++)
352 colMap[i] = colRevMap[i] = -1;
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100353 addColumn(promptColIdx, _("Option"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 reinit();
356}
357
Li Zefan39a48972010-05-10 16:33:41 +0800358bool ConfigList::menuSkip(struct menu *menu)
359{
360 if (optMode == normalOpt && menu_is_visible(menu))
361 return false;
362 if (optMode == promptOpt && menu_has_prompt(menu))
363 return false;
364 if (optMode == allOpt)
365 return false;
366 return true;
367}
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369void ConfigList::reinit(void)
370{
371 removeColumn(dataColIdx);
372 removeColumn(yesColIdx);
373 removeColumn(modColIdx);
374 removeColumn(noColIdx);
375 removeColumn(nameColIdx);
376
377 if (showName)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100378 addColumn(nameColIdx, _("Name"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 if (showRange) {
380 addColumn(noColIdx, "N");
381 addColumn(modColIdx, "M");
382 addColumn(yesColIdx, "Y");
383 }
384 if (showData)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100385 addColumn(dataColIdx, _("Value"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 updateListAll();
388}
389
Roman Zippel7fc925f2006-06-08 22:12:46 -0700390void ConfigList::saveSettings(void)
391{
392 if (name()) {
393 configSettings->beginGroup(name());
394 configSettings->writeEntry("/showName", showName);
395 configSettings->writeEntry("/showRange", showRange);
396 configSettings->writeEntry("/showData", showData);
Li Zefan39a48972010-05-10 16:33:41 +0800397 configSettings->writeEntry("/optionMode", (int)optMode);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700398 configSettings->endGroup();
399 }
400}
401
Roman Zippelb65a47e2006-06-08 22:12:47 -0700402ConfigItem* ConfigList::findConfigItem(struct menu *menu)
403{
404 ConfigItem* item = (ConfigItem*)menu->data;
405
406 for (; item; item = item->nextItem) {
407 if (this == item->listView())
408 break;
409 }
410
411 return item;
412}
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414void ConfigList::updateSelection(void)
415{
416 struct menu *menu;
417 enum prop_type type;
418
419 ConfigItem* item = (ConfigItem*)selectedItem();
420 if (!item)
421 return;
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 menu = item->menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700424 emit menuChanged(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 if (!menu)
426 return;
427 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
428 if (mode == menuMode && type == P_MENU)
429 emit menuSelected(menu);
430}
431
432void ConfigList::updateList(ConfigItem* item)
433{
434 ConfigItem* last = 0;
435
Roman Zippel43bf6122006-06-08 22:12:45 -0700436 if (!rootEntry) {
437 if (mode != listMode)
438 goto update;
Alexander Stein133c5f72010-08-31 17:34:37 +0200439 Q3ListViewItemIterator it(this);
Roman Zippel43bf6122006-06-08 22:12:45 -0700440 ConfigItem* item;
441
442 for (; it.current(); ++it) {
443 item = (ConfigItem*)it.current();
444 if (!item->menu)
445 continue;
446 item->testUpdateMenu(menu_is_visible(item->menu));
447 }
448 return;
449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 if (rootEntry != &rootmenu && (mode == singleMode ||
452 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
453 item = firstChild();
454 if (!item)
455 item = new ConfigItem(this, 0, true);
456 last = item;
457 }
458 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
459 rootEntry->sym && rootEntry->prompt) {
460 item = last ? last->nextSibling() : firstChild();
461 if (!item)
462 item = new ConfigItem(this, last, rootEntry, true);
463 else
464 item->testUpdateMenu(true);
465
466 updateMenuList(item, rootEntry);
467 triggerUpdate();
468 return;
469 }
470update:
471 updateMenuList(this, rootEntry);
472 triggerUpdate();
473}
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475void ConfigList::setValue(ConfigItem* item, tristate val)
476{
477 struct symbol* sym;
478 int type;
479 tristate oldval;
480
481 sym = item->menu ? item->menu->sym : 0;
482 if (!sym)
483 return;
484
485 type = sym_get_type(sym);
486 switch (type) {
487 case S_BOOLEAN:
488 case S_TRISTATE:
489 oldval = sym_get_tristate_value(sym);
490
491 if (!sym_set_tristate_value(sym, val))
492 return;
493 if (oldval == no && item->menu->list)
494 item->setOpen(TRUE);
495 parent()->updateList(item);
496 break;
497 }
498}
499
500void ConfigList::changeValue(ConfigItem* item)
501{
502 struct symbol* sym;
503 struct menu* menu;
504 int type, oldexpr, newexpr;
505
506 menu = item->menu;
507 if (!menu)
508 return;
509 sym = menu->sym;
510 if (!sym) {
511 if (item->menu->list)
512 item->setOpen(!item->isOpen());
513 return;
514 }
515
516 type = sym_get_type(sym);
517 switch (type) {
518 case S_BOOLEAN:
519 case S_TRISTATE:
520 oldexpr = sym_get_tristate_value(sym);
521 newexpr = sym_toggle_tristate_value(sym);
522 if (item->menu->list) {
523 if (oldexpr == newexpr)
524 item->setOpen(!item->isOpen());
525 else if (oldexpr == no)
526 item->setOpen(TRUE);
527 }
528 if (oldexpr != newexpr)
529 parent()->updateList(item);
530 break;
531 case S_INT:
532 case S_HEX:
533 case S_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (colMap[dataColIdx] >= 0)
535 item->startRename(colMap[dataColIdx]);
536 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 parent()->lineEdit->show(item);
538 break;
539 }
540}
541
542void ConfigList::setRootMenu(struct menu *menu)
543{
544 enum prop_type type;
545
546 if (rootEntry == menu)
547 return;
548 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
549 if (type != P_MENU)
550 return;
551 updateMenuList(this, 0);
552 rootEntry = menu;
553 updateListAll();
554 setSelected(currentItem(), hasFocus());
Roman Zippelb65a47e2006-06-08 22:12:47 -0700555 ensureItemVisible(currentItem());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558void ConfigList::setParentMenu(void)
559{
560 ConfigItem* item;
561 struct menu *oldroot;
562
563 oldroot = rootEntry;
564 if (rootEntry == &rootmenu)
565 return;
566 setRootMenu(menu_get_parent_menu(rootEntry->parent));
567
Alexander Stein133c5f72010-08-31 17:34:37 +0200568 Q3ListViewItemIterator it(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 for (; (item = (ConfigItem*)it.current()); it++) {
570 if (item->menu == oldroot) {
571 setCurrentItem(item);
572 ensureItemVisible(item);
573 break;
574 }
575 }
576}
577
Roman Zippel7fc925f2006-06-08 22:12:46 -0700578/*
579 * update all the children of a menu entry
580 * removes/adds the entries from the parent widget as necessary
581 *
582 * parent: either the menu list widget or a menu entry widget
583 * menu: entry to be updated
584 */
585template <class P>
586void ConfigList::updateMenuList(P* parent, struct menu* menu)
587{
588 struct menu* child;
589 ConfigItem* item;
590 ConfigItem* last;
591 bool visible;
592 enum prop_type type;
593
594 if (!menu) {
595 while ((item = parent->firstChild()))
596 delete item;
597 return;
598 }
599
600 last = parent->firstChild();
601 if (last && !last->goParent)
602 last = 0;
603 for (child = menu->list; child; child = child->next) {
604 item = last ? last->nextSibling() : parent->firstChild();
605 type = child->prompt ? child->prompt->type : P_UNKNOWN;
606
607 switch (mode) {
608 case menuMode:
609 if (!(child->flags & MENU_ROOT))
610 goto hide;
611 break;
612 case symbolMode:
613 if (child->flags & MENU_ROOT)
614 goto hide;
615 break;
616 default:
617 break;
618 }
619
620 visible = menu_is_visible(child);
Li Zefan39a48972010-05-10 16:33:41 +0800621 if (!menuSkip(child)) {
Cyrill V. Gorcunoved8b4d42007-02-14 00:33:03 -0800622 if (!child->sym && !child->list && !child->prompt)
623 continue;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700624 if (!item || item->menu != child)
625 item = new ConfigItem(parent, last, child, visible);
626 else
627 item->testUpdateMenu(visible);
628
629 if (mode == fullMode || mode == menuMode || type != P_MENU)
630 updateMenuList(item, child);
631 else
632 updateMenuList(item, 0);
633 last = item;
634 continue;
635 }
636 hide:
637 if (item && item->menu == child) {
638 last = parent->firstChild();
639 if (last == item)
640 last = 0;
641 else while (last->nextSibling() != item)
642 last = last->nextSibling();
643 delete item;
644 }
645 }
646}
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648void ConfigList::keyPressEvent(QKeyEvent* ev)
649{
Alexander Stein133c5f72010-08-31 17:34:37 +0200650 Q3ListViewItem* i = currentItem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 ConfigItem* item;
652 struct menu *menu;
653 enum prop_type type;
654
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200655 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 emit parentSelected();
657 ev->accept();
658 return;
659 }
660
661 if (!i) {
662 Parent::keyPressEvent(ev);
663 return;
664 }
665 item = (ConfigItem*)i;
666
667 switch (ev->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200668 case Qt::Key_Return:
669 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 if (item->goParent) {
671 emit parentSelected();
672 break;
673 }
674 menu = item->menu;
675 if (!menu)
676 break;
677 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
678 if (type == P_MENU && rootEntry != menu &&
679 mode != fullMode && mode != menuMode) {
680 emit menuSelected(menu);
681 break;
682 }
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200683 case Qt::Key_Space:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 changeValue(item);
685 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200686 case Qt::Key_N:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 setValue(item, no);
688 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200689 case Qt::Key_M:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 setValue(item, mod);
691 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200692 case Qt::Key_Y:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 setValue(item, yes);
694 break;
695 default:
696 Parent::keyPressEvent(ev);
697 return;
698 }
699 ev->accept();
700}
701
702void ConfigList::contentsMousePressEvent(QMouseEvent* e)
703{
704 //QPoint p(contentsToViewport(e->pos()));
705 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
706 Parent::contentsMousePressEvent(e);
707}
708
709void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
710{
711 QPoint p(contentsToViewport(e->pos()));
712 ConfigItem* item = (ConfigItem*)itemAt(p);
713 struct menu *menu;
714 enum prop_type ptype;
715 const QPixmap* pm;
716 int idx, x;
717
718 if (!item)
719 goto skip;
720
721 menu = item->menu;
722 x = header()->offset() + p.x();
723 idx = colRevMap[header()->sectionAt(x)];
724 switch (idx) {
725 case promptColIdx:
726 pm = item->pixmap(promptColIdx);
727 if (pm) {
728 int off = header()->sectionPos(0) + itemMargin() +
729 treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
730 if (x >= off && x < off + pm->width()) {
731 if (item->goParent) {
732 emit parentSelected();
733 break;
734 } else if (!menu)
735 break;
736 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
737 if (ptype == P_MENU && rootEntry != menu &&
738 mode != fullMode && mode != menuMode)
739 emit menuSelected(menu);
740 else
741 changeValue(item);
742 }
743 }
744 break;
745 case noColIdx:
746 setValue(item, no);
747 break;
748 case modColIdx:
749 setValue(item, mod);
750 break;
751 case yesColIdx:
752 setValue(item, yes);
753 break;
754 case dataColIdx:
755 changeValue(item);
756 break;
757 }
758
759skip:
760 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
761 Parent::contentsMouseReleaseEvent(e);
762}
763
764void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
765{
766 //QPoint p(contentsToViewport(e->pos()));
767 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
768 Parent::contentsMouseMoveEvent(e);
769}
770
771void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
772{
773 QPoint p(contentsToViewport(e->pos()));
774 ConfigItem* item = (ConfigItem*)itemAt(p);
775 struct menu *menu;
776 enum prop_type ptype;
777
778 if (!item)
779 goto skip;
780 if (item->goParent) {
781 emit parentSelected();
782 goto skip;
783 }
784 menu = item->menu;
785 if (!menu)
786 goto skip;
787 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
788 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
789 emit menuSelected(menu);
790 else if (menu->sym)
791 changeValue(item);
792
793skip:
794 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
795 Parent::contentsMouseDoubleClickEvent(e);
796}
797
798void ConfigList::focusInEvent(QFocusEvent *e)
799{
Roman Zippelb65a47e2006-06-08 22:12:47 -0700800 struct menu *menu = NULL;
801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 Parent::focusInEvent(e);
803
Roman Zippelb65a47e2006-06-08 22:12:47 -0700804 ConfigItem* item = (ConfigItem *)currentItem();
805 if (item) {
806 setSelected(item, TRUE);
807 menu = item->menu;
808 }
809 emit gotFocus(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
Roman Zippel7fc925f2006-06-08 22:12:46 -0700812void ConfigList::contextMenuEvent(QContextMenuEvent *e)
813{
814 if (e->y() <= header()->geometry().bottom()) {
815 if (!headerPopup) {
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700816 QAction *action;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700817
Boris Barbulovski76bede82015-09-22 11:36:07 -0700818 headerPopup = new QMenu(this);
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700819 action = new QAction(_("Show Name"), this);
Boris Barbulovski9c862352015-09-22 11:36:12 -0700820 action->setCheckable(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700821 connect(action, SIGNAL(toggled(bool)),
822 parent(), SLOT(setShowName(bool)));
823 connect(parent(), SIGNAL(showNameChanged(bool)),
824 action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -0700825 action->setChecked(showName);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700826 action->addTo(headerPopup);
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700827 action = new QAction(_("Show Range"), this);
Boris Barbulovski9c862352015-09-22 11:36:12 -0700828 action->setCheckable(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700829 connect(action, SIGNAL(toggled(bool)),
830 parent(), SLOT(setShowRange(bool)));
831 connect(parent(), SIGNAL(showRangeChanged(bool)),
832 action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -0700833 action->setChecked(showRange);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700834 action->addTo(headerPopup);
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700835 action = new QAction( _("Show Data"), this);
Boris Barbulovski9c862352015-09-22 11:36:12 -0700836 action->setCheckable(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700837 connect(action, SIGNAL(toggled(bool)),
838 parent(), SLOT(setShowData(bool)));
839 connect(parent(), SIGNAL(showDataChanged(bool)),
840 action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -0700841 action->setChecked(showData);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700842 action->addTo(headerPopup);
843 }
844 headerPopup->exec(e->globalPos());
845 e->accept();
846 } else
847 e->ignore();
848}
849
Li Zefan39a48972010-05-10 16:33:41 +0800850ConfigView*ConfigView::viewList;
851QAction *ConfigView::showNormalAction;
852QAction *ConfigView::showAllAction;
853QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Roman Zippel7fc925f2006-06-08 22:12:46 -0700855ConfigView::ConfigView(QWidget* parent, const char *name)
856 : Parent(parent, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
Boris Barbulovski29a70162015-09-22 11:36:10 -0700858 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700859 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700860
Roman Zippel7fc925f2006-06-08 22:12:46 -0700861 list = new ConfigList(this, name);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700862 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 lineEdit = new ConfigLineEdit(this);
864 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700865 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867 this->nextView = viewList;
868 viewList = this;
869}
870
871ConfigView::~ConfigView(void)
872{
873 ConfigView** vp;
874
875 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
876 if (*vp == this) {
877 *vp = nextView;
878 break;
879 }
880 }
881}
882
Li Zefan39a48972010-05-10 16:33:41 +0800883void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700884{
Li Zefan39a48972010-05-10 16:33:41 +0800885 if (act == showNormalAction)
886 list->optMode = normalOpt;
887 else if (act == showAllAction)
888 list->optMode = allOpt;
889 else
890 list->optMode = promptOpt;
891
892 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700893}
894
895void ConfigView::setShowName(bool b)
896{
897 if (list->showName != b) {
898 list->showName = b;
899 list->reinit();
900 emit showNameChanged(b);
901 }
902}
903
904void ConfigView::setShowRange(bool b)
905{
906 if (list->showRange != b) {
907 list->showRange = b;
908 list->reinit();
909 emit showRangeChanged(b);
910 }
911}
912
913void ConfigView::setShowData(bool b)
914{
915 if (list->showData != b) {
916 list->showData = b;
917 list->reinit();
918 emit showDataChanged(b);
919 }
920}
921
922void ConfigList::setAllOpen(bool open)
923{
Alexander Stein133c5f72010-08-31 17:34:37 +0200924 Q3ListViewItemIterator it(this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700925
926 for (; it.current(); it++)
927 it.current()->setOpen(open);
928}
929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930void ConfigView::updateList(ConfigItem* item)
931{
932 ConfigView* v;
933
934 for (v = viewList; v; v = v->nextView)
935 v->list->updateList(item);
936}
937
938void ConfigView::updateListAll(void)
939{
940 ConfigView* v;
941
942 for (v = viewList; v; v = v->nextView)
943 v->list->updateListAll();
944}
945
Roman Zippel43bf6122006-06-08 22:12:45 -0700946ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Alexander Stein133c5f72010-08-31 17:34:37 +0200947 : Parent(parent, name), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700948{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700949 if (name) {
950 configSettings->beginGroup(name);
951 _showDebug = configSettings->readBoolEntry("/showDebug", false);
952 configSettings->endGroup();
953 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
954 }
955}
956
957void ConfigInfoView::saveSettings(void)
958{
959 if (name()) {
960 configSettings->beginGroup(name());
961 configSettings->writeEntry("/showDebug", showDebug());
962 configSettings->endGroup();
963 }
Roman Zippel43bf6122006-06-08 22:12:45 -0700964}
965
966void ConfigInfoView::setShowDebug(bool b)
967{
968 if (_showDebug != b) {
969 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +0200970 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700971 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -0700972 else if (sym)
973 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -0700974 emit showDebugChanged(b);
975 }
976}
977
978void ConfigInfoView::setInfo(struct menu *m)
979{
Alexander Stein133c5f72010-08-31 17:34:37 +0200980 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -0700981 return;
Alexander Stein133c5f72010-08-31 17:34:37 +0200982 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -0800983 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +0200984 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700985 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -0800986 else
Roman Zippel43bf6122006-06-08 22:12:45 -0700987 menuInfo();
988}
989
Roman Zippelab45d192006-06-08 22:12:47 -0700990void ConfigInfoView::symbolInfo(void)
991{
992 QString str;
993
994 str += "<big>Symbol: <b>";
995 str += print_filter(sym->name);
996 str += "</b></big><br><br>value: ";
997 str += print_filter(sym_get_string_value(sym));
998 str += "<br>visibility: ";
999 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1000 str += "<br>";
1001 str += debug_info(sym);
1002
1003 setText(str);
1004}
1005
Roman Zippel43bf6122006-06-08 22:12:45 -07001006void ConfigInfoView::menuInfo(void)
1007{
1008 struct symbol* sym;
1009 QString head, debug, help;
1010
Alexander Stein133c5f72010-08-31 17:34:37 +02001011 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001012 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001013 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001014 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001015 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001016 head += "</b></big>";
1017 if (sym->name) {
1018 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001019 if (showDebug())
1020 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001021 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001022 if (showDebug())
1023 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001024 head += ")";
1025 }
1026 } else if (sym->name) {
1027 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001028 if (showDebug())
1029 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001030 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001031 if (showDebug())
1032 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001033 head += "</b></big>";
1034 }
1035 head += "<br><br>";
1036
1037 if (showDebug())
1038 debug = debug_info(sym);
1039
Cheng Renquand74c15f2009-07-12 16:11:47 +08001040 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001041 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001042 help = print_filter(str_get(&help_gstr));
1043 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001044 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001045 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001046 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001047 head += "</b></big><br><br>";
1048 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001049 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001050 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001051 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001052 debug += "<br><br>";
1053 }
1054 }
1055 }
1056 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001057 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001058
1059 setText(head + debug + help);
1060}
1061
1062QString ConfigInfoView::debug_info(struct symbol *sym)
1063{
1064 QString debug;
1065
1066 debug += "type: ";
1067 debug += print_filter(sym_type_name(sym->type));
1068 if (sym_is_choice(sym))
1069 debug += " (choice)";
1070 debug += "<br>";
1071 if (sym->rev_dep.expr) {
1072 debug += "reverse dep: ";
1073 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1074 debug += "<br>";
1075 }
1076 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1077 switch (prop->type) {
1078 case P_PROMPT:
1079 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -07001080 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Roman Zippel43bf6122006-06-08 22:12:45 -07001081 debug += print_filter(_(prop->text));
Roman Zippelab45d192006-06-08 22:12:47 -07001082 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001083 break;
1084 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001085 case P_SELECT:
1086 case P_RANGE:
1087 case P_ENV:
1088 debug += prop_get_type_name(prop->type);
1089 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001090 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1091 debug += "<br>";
1092 break;
1093 case P_CHOICE:
1094 if (sym_is_choice(sym)) {
1095 debug += "choice: ";
1096 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1097 debug += "<br>";
1098 }
1099 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001100 default:
1101 debug += "unknown property: ";
1102 debug += prop_get_type_name(prop->type);
1103 debug += "<br>";
1104 }
1105 if (prop->visible.expr) {
1106 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1107 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1108 debug += "<br>";
1109 }
1110 }
1111 debug += "<br>";
1112
1113 return debug;
1114}
1115
1116QString ConfigInfoView::print_filter(const QString &str)
1117{
1118 QRegExp re("[<>&\"\\n]");
1119 QString res = str;
1120 for (int i = 0; (i = res.find(re, i)) >= 0;) {
1121 switch (res[i].latin1()) {
1122 case '<':
1123 res.replace(i, 1, "&lt;");
1124 i += 4;
1125 break;
1126 case '>':
1127 res.replace(i, 1, "&gt;");
1128 i += 4;
1129 break;
1130 case '&':
1131 res.replace(i, 1, "&amp;");
1132 i += 5;
1133 break;
1134 case '"':
1135 res.replace(i, 1, "&quot;");
1136 i += 6;
1137 break;
1138 case '\n':
1139 res.replace(i, 1, "<br>");
1140 i += 4;
1141 break;
1142 }
1143 }
1144 return res;
1145}
1146
Roman Zippelab45d192006-06-08 22:12:47 -07001147void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001148{
Roman Zippelab45d192006-06-08 22:12:47 -07001149 QString* text = reinterpret_cast<QString*>(data);
1150 QString str2 = print_filter(str);
1151
1152 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1153 *text += QString().sprintf("<a href=\"s%p\">", sym);
1154 *text += str2;
1155 *text += "</a>";
1156 } else
1157 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001158}
1159
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001160QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001161{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001162 QMenu* popup = Parent::createStandardContextMenu(pos);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001163 QAction* action = new QAction(_("Show Debug Info"), popup);
Boris Barbulovski9c862352015-09-22 11:36:12 -07001164 action->setCheckable(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001165 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1166 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001167 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001168 popup->addSeparator();
Roman Zippel7fc925f2006-06-08 22:12:46 -07001169 action->addTo(popup);
1170 return popup;
1171}
1172
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001173void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001174{
Boris Barbulovski924bbb52015-09-22 11:36:06 -07001175 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001176}
1177
Marco Costalba63431e72006-10-05 19:12:59 +02001178ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001179 : Parent(parent, name), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001180{
1181 setCaption("Search Config");
1182
1183 QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
1184 QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001185 layout2->addWidget(new QLabel(_("Find:"), this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001186 editField = new QLineEdit(this);
1187 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1188 layout2->addWidget(editField);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001189 searchButton = new QPushButton(_("Search"), this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001190 searchButton->setAutoDefault(FALSE);
1191 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1192 layout2->addWidget(searchButton);
1193 layout1->addLayout(layout2);
1194
Roman Zippel7fc925f2006-06-08 22:12:46 -07001195 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001196 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001197 list = new ConfigView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001198 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001199 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001200 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1201 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001202 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1203 parent, SLOT(setMenuLink(struct menu *)));
1204
Roman Zippel43bf6122006-06-08 22:12:45 -07001205 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001206
1207 if (name) {
1208 int x, y, width, height;
1209 bool ok;
1210
1211 configSettings->beginGroup(name);
1212 width = configSettings->readNumEntry("/window width", parent->width() / 2);
1213 height = configSettings->readNumEntry("/window height", parent->height() / 2);
1214 resize(width, height);
1215 x = configSettings->readNumEntry("/window x", 0, &ok);
1216 if (ok)
1217 y = configSettings->readNumEntry("/window y", 0, &ok);
1218 if (ok)
1219 move(x, y);
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001220 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001221 if (ok)
1222 split->setSizes(sizes);
1223 configSettings->endGroup();
1224 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1225 }
1226}
1227
1228void ConfigSearchWindow::saveSettings(void)
1229{
1230 if (name()) {
1231 configSettings->beginGroup(name());
1232 configSettings->writeEntry("/window x", pos().x());
1233 configSettings->writeEntry("/window y", pos().y());
1234 configSettings->writeEntry("/window width", size().width());
1235 configSettings->writeEntry("/window height", size().height());
1236 configSettings->writeSizes("/split", split->sizes());
1237 configSettings->endGroup();
1238 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001239}
1240
1241void ConfigSearchWindow::search(void)
1242{
1243 struct symbol **p;
1244 struct property *prop;
1245 ConfigItem *lastItem = NULL;
1246
1247 free(result);
1248 list->list->clear();
Cyrill V. Gorcunov786fb182007-02-14 00:32:59 -08001249 info->clear();
Roman Zippel43bf6122006-06-08 22:12:45 -07001250
1251 result = sym_re_search(editField->text().latin1());
1252 if (!result)
1253 return;
1254 for (p = result; *p; p++) {
1255 for_all_prompts((*p), prop)
1256 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1257 menu_is_visible(prop->menu));
1258 }
1259}
1260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261/*
1262 * Construct the complete config widget
1263 */
1264ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001265 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266{
1267 QMenuBar* menu;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001268 bool ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 int x, y, width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001270 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001272 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001273 snprintf(title, sizeof(title), "%s%s",
1274 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001275 ""
Michal Marek76a136c2010-09-01 17:39:27 +02001276 );
Randy Dunlapa54bb702007-10-20 11:18:47 -07001277 setCaption(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Roman Zippel7fc925f2006-06-08 22:12:46 -07001279 width = configSettings->readNumEntry("/window width", d->width() - 64);
1280 height = configSettings->readNumEntry("/window height", d->height() - 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 resize(width, height);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001282 x = configSettings->readNumEntry("/window x", 0, &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 if (ok)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001284 y = configSettings->readNumEntry("/window y", 0, &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 if (ok)
1286 move(x, y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
1288 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001289 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 setCentralWidget(split1);
1291
Roman Zippel7fc925f2006-06-08 22:12:46 -07001292 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 menuList = menuView->list;
1294
1295 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001296 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -07001299 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 configList = configView->list;
1301
Roman Zippel7fc925f2006-06-08 22:12:46 -07001302 helpText = new ConfigInfoView(split2, "help");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 helpText->setTextFormat(Qt::RichText);
1304
1305 setTabOrder(configList, helpText);
1306 configList->setFocus();
1307
1308 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07001309 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -07001310 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001312 backAction = new QAction(QPixmap(xpm_back), _("Back"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 connect(backAction, SIGNAL(activated()), SLOT(goBack()));
1314 backAction->setEnabled(FALSE);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001315 QAction *quitAction = new QAction(_("&Quit"), this);
1316 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 connect(quitAction, SIGNAL(activated()), SLOT(close()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001318 QAction *loadAction = new QAction(QPixmap(xpm_load), _("&Load"), this);
1319 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001321 saveAction = new QAction(QPixmap(xpm_save), _("&Save"), this);
1322 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001324 conf_set_changed_callback(conf_changed);
1325 // Set saveAction's initial state
1326 conf_changed();
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001327 QAction *saveAsAction = new QAction(_("Save &As..."), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001329 QAction *searchAction = new QAction(_("&Find"), this);
1330 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Roman Zippel43bf6122006-06-08 22:12:45 -07001331 connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001332 QAction *singleViewAction = new QAction(QPixmap(xpm_single_view), _("Single View"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001334 QAction *splitViewAction = new QAction(QPixmap(xpm_split_view), _("Split View"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001336 QAction *fullViewAction = new QAction(QPixmap(xpm_tree_view), _("Full View"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
1338
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001339 QAction *showNameAction = new QAction(_("Show Name"), this);
Boris Barbulovski9c862352015-09-22 11:36:12 -07001340 showNameAction->setCheckable(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001341 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
1342 connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001343 showNameAction->setChecked(configView->showName());
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001344 QAction *showRangeAction = new QAction(_("Show Range"), this);
Boris Barbulovski9c862352015-09-22 11:36:12 -07001345 showRangeAction->setCheckable(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001346 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
1347 connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001348 showRangeAction->setChecked(configList->showRange);
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001349 QAction *showDataAction = new QAction(_("Show Data"), this);
Boris Barbulovski9c862352015-09-22 11:36:12 -07001350 showDataAction->setCheckable(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001351 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
1352 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001353 showDataAction->setChecked(configList->showData);
Li Zefan39a48972010-05-10 16:33:41 +08001354
1355 QActionGroup *optGroup = new QActionGroup(this);
1356 optGroup->setExclusive(TRUE);
1357 connect(optGroup, SIGNAL(selected(QAction *)), configView,
1358 SLOT(setOptionMode(QAction *)));
1359 connect(optGroup, SIGNAL(selected(QAction *)), menuView,
1360 SLOT(setOptionMode(QAction *)));
1361
Alexander Stein133c5f72010-08-31 17:34:37 +02001362 configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
1363 configView->showAllAction = new QAction(_("Show All Options"), optGroup);
1364 configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
Boris Barbulovski9c862352015-09-22 11:36:12 -07001365 configView->showNormalAction->setCheckable(TRUE);
1366 configView->showNormalAction->setChecked(configList->optMode == normalOpt);
1367 configView->showAllAction->setCheckable(TRUE);
1368 configView->showAllAction->setChecked(configList->optMode == allOpt);
1369 configView->showPromptAction->setCheckable(TRUE);
1370 configView->showPromptAction->setChecked(configList->optMode == promptOpt);
Li Zefan39a48972010-05-10 16:33:41 +08001371
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001372 QAction *showDebugAction = new QAction( _("Show Debug Info"), this);
Boris Barbulovski9c862352015-09-22 11:36:12 -07001373 showDebugAction->setCheckable(TRUE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001374 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
1375 connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -07001376 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001378 QAction *showIntroAction = new QAction( _("Introduction"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -07001380 QAction *showAboutAction = new QAction( _("About"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
1382
1383 // init tool bar
1384 backAction->addTo(toolBar);
1385 toolBar->addSeparator();
1386 loadAction->addTo(toolBar);
1387 saveAction->addTo(toolBar);
1388 toolBar->addSeparator();
1389 singleViewAction->addTo(toolBar);
1390 splitViewAction->addTo(toolBar);
1391 fullViewAction->addTo(toolBar);
1392
1393 // create config menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001394 QMenu* config = new QMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001395 menu->insertItem(_("&File"), config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 loadAction->addTo(config);
1397 saveAction->addTo(config);
1398 saveAsAction->addTo(config);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001399 config->addSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 quitAction->addTo(config);
1401
Shlomi Fish66e7c722007-02-14 00:32:58 -08001402 // create edit menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001403 QMenu* editMenu = new QMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001404 menu->insertItem(_("&Edit"), editMenu);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001405 searchAction->addTo(editMenu);
1406
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 // create options menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001408 QMenu* optionMenu = new QMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001409 menu->insertItem(_("&Option"), optionMenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 showNameAction->addTo(optionMenu);
1411 showRangeAction->addTo(optionMenu);
1412 showDataAction->addTo(optionMenu);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001413 optionMenu->addSeparator();
Li Zefan39a48972010-05-10 16:33:41 +08001414 optGroup->addTo(optionMenu);
Boris Barbulovski76bede82015-09-22 11:36:07 -07001415 optionMenu->addSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
1417 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -07001418 QMenu* helpMenu = new QMenu(this);
1419 menu->addSeparator();
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001420 menu->insertItem(_("&Help"), helpMenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 showIntroAction->addTo(helpMenu);
1422 showAboutAction->addTo(helpMenu);
1423
Roman Zippel43bf6122006-06-08 22:12:45 -07001424 connect(configList, SIGNAL(menuChanged(struct menu *)),
1425 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 connect(configList, SIGNAL(menuSelected(struct menu *)),
1427 SLOT(changeMenu(struct menu *)));
1428 connect(configList, SIGNAL(parentSelected()),
1429 SLOT(goBack()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001430 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1431 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1433 SLOT(changeMenu(struct menu *)));
1434
Roman Zippelb65a47e2006-06-08 22:12:47 -07001435 connect(configList, SIGNAL(gotFocus(struct menu *)),
1436 helpText, SLOT(setInfo(struct menu *)));
1437 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1438 helpText, SLOT(setInfo(struct menu *)));
1439 connect(menuList, SIGNAL(gotFocus(struct menu *)),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001441 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1442 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Roman Zippel7fc925f2006-06-08 22:12:46 -07001444 QString listMode = configSettings->readEntry("/listMode", "symbol");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 if (listMode == "single")
1446 showSingleView();
1447 else if (listMode == "full")
1448 showFullView();
1449 else /*if (listMode == "split")*/
1450 showSplitView();
1451
1452 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07001453 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 if (ok)
1455 split1->setSizes(sizes);
1456
Roman Zippel7fc925f2006-06-08 22:12:46 -07001457 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 if (ok)
1459 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460}
1461
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462void ConfigMainWindow::loadConfig(void)
1463{
Boris Barbulovskibea00772015-09-22 11:36:04 -07001464 QString s = QFileDialog::getOpenFileName(conf_get_configname(), NULL, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 if (s.isNull())
1466 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001467 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001468 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 ConfigView::updateListAll();
1470}
1471
Michal Marekbac6aa82011-05-25 15:10:25 +02001472bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
Michal Marekbac6aa82011-05-25 15:10:25 +02001474 if (conf_write(NULL)) {
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001475 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Michal Marekbac6aa82011-05-25 15:10:25 +02001476 return false;
1477 }
1478 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
1481void ConfigMainWindow::saveConfigAs(void)
1482{
Boris Barbulovskibea00772015-09-22 11:36:04 -07001483 QString s = QFileDialog::getSaveFileName(conf_get_configname(), NULL, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 if (s.isNull())
1485 return;
Arnaud Lacombed49e4682011-05-24 14:16:18 -04001486 saveConfig();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487}
1488
Roman Zippel43bf6122006-06-08 22:12:45 -07001489void ConfigMainWindow::searchConfig(void)
1490{
1491 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001492 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001493 searchWindow->show();
1494}
1495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496void ConfigMainWindow::changeMenu(struct menu *menu)
1497{
1498 configList->setRootMenu(menu);
Cyrill V. Gorcunovf253f002007-02-14 00:33:00 -08001499 if (configList->rootEntry->parent == &rootmenu)
1500 backAction->setEnabled(FALSE);
1501 else
1502 backAction->setEnabled(TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Roman Zippelb65a47e2006-06-08 22:12:47 -07001505void ConfigMainWindow::setMenuLink(struct menu *menu)
1506{
1507 struct menu *parent;
1508 ConfigList* list = NULL;
1509 ConfigItem* item;
1510
Li Zefan39a48972010-05-10 16:33:41 +08001511 if (configList->menuSkip(menu))
Roman Zippelb65a47e2006-06-08 22:12:47 -07001512 return;
1513
1514 switch (configList->mode) {
1515 case singleMode:
1516 list = configList;
1517 parent = menu_get_parent_menu(menu);
1518 if (!parent)
1519 return;
1520 list->setRootMenu(parent);
1521 break;
1522 case symbolMode:
1523 if (menu->flags & MENU_ROOT) {
1524 configList->setRootMenu(menu);
1525 configList->clearSelection();
1526 list = menuList;
1527 } else {
1528 list = configList;
1529 parent = menu_get_parent_menu(menu->parent);
1530 if (!parent)
1531 return;
1532 item = menuList->findConfigItem(parent);
1533 if (item) {
1534 menuList->setSelected(item, TRUE);
1535 menuList->ensureItemVisible(item);
1536 }
1537 list->setRootMenu(parent);
1538 }
1539 break;
1540 case fullMode:
1541 list = configList;
1542 break;
Markus Heidelberg98403a92009-05-18 01:36:49 +02001543 default:
1544 break;
Roman Zippelb65a47e2006-06-08 22:12:47 -07001545 }
1546
1547 if (list) {
1548 item = list->findConfigItem(menu);
1549 if (item) {
1550 list->setSelected(item, TRUE);
1551 list->ensureItemVisible(item);
1552 list->setFocus();
1553 }
1554 }
1555}
1556
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557void ConfigMainWindow::listFocusChanged(void)
1558{
Roman Zippelb65a47e2006-06-08 22:12:47 -07001559 if (menuList->mode == menuMode)
1560 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
1563void ConfigMainWindow::goBack(void)
1564{
1565 ConfigItem* item;
1566
1567 configList->setParentMenu();
1568 if (configList->rootEntry == &rootmenu)
1569 backAction->setEnabled(FALSE);
1570 item = (ConfigItem*)menuList->selectedItem();
1571 while (item) {
1572 if (item->menu == configList->rootEntry) {
1573 menuList->setSelected(item, TRUE);
1574 break;
1575 }
1576 item = (ConfigItem*)item->parent();
1577 }
1578}
1579
1580void ConfigMainWindow::showSingleView(void)
1581{
1582 menuView->hide();
1583 menuList->setRootMenu(0);
1584 configList->mode = singleMode;
1585 if (configList->rootEntry == &rootmenu)
1586 configList->updateListAll();
1587 else
1588 configList->setRootMenu(&rootmenu);
1589 configList->setAllOpen(TRUE);
1590 configList->setFocus();
1591}
1592
1593void ConfigMainWindow::showSplitView(void)
1594{
1595 configList->mode = symbolMode;
1596 if (configList->rootEntry == &rootmenu)
1597 configList->updateListAll();
1598 else
1599 configList->setRootMenu(&rootmenu);
1600 configList->setAllOpen(TRUE);
1601 configApp->processEvents();
1602 menuList->mode = menuMode;
1603 menuList->setRootMenu(&rootmenu);
1604 menuList->setAllOpen(TRUE);
1605 menuView->show();
1606 menuList->setFocus();
1607}
1608
1609void ConfigMainWindow::showFullView(void)
1610{
1611 menuView->hide();
1612 menuList->setRootMenu(0);
1613 configList->mode = fullMode;
1614 if (configList->rootEntry == &rootmenu)
1615 configList->updateListAll();
1616 else
1617 configList->setRootMenu(&rootmenu);
1618 configList->setAllOpen(FALSE);
1619 configList->setFocus();
1620}
1621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622/*
1623 * ask for saving configuration before quitting
1624 * TODO ask only when something changed
1625 */
1626void ConfigMainWindow::closeEvent(QCloseEvent* e)
1627{
Karsten Wieseb3214292006-12-13 00:34:06 -08001628 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 e->accept();
1630 return;
1631 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001632 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001634 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1635 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1636 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 switch (mb.exec()) {
1638 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001639 if (saveConfig())
1640 e->accept();
1641 else
1642 e->ignore();
1643 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 case QMessageBox::No:
1645 e->accept();
1646 break;
1647 case QMessageBox::Cancel:
1648 e->ignore();
1649 break;
1650 }
1651}
1652
1653void ConfigMainWindow::showIntro(void)
1654{
Arnaud Lacombe652cf982010-08-14 23:51:40 -04001655 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 "For each option, a blank box indicates the feature is disabled, a check\n"
1657 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1658 "as a module. Clicking on the box will cycle through the three states.\n\n"
1659 "If you do not see an option (e.g., a device driver) that you believe\n"
1660 "should be present, try turning on Show All Options under the Options menu.\n"
1661 "Although there is no cross reference yet to help you figure out what other\n"
1662 "options must be enabled to support the option you are interested in, you can\n"
1663 "still view the help of a grayed-out option.\n\n"
1664 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001665 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 QMessageBox::information(this, "qconf", str);
1668}
1669
1670void ConfigMainWindow::showAbout(void)
1671{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001672 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1673 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675 QMessageBox::information(this, "qconf", str);
1676}
1677
1678void ConfigMainWindow::saveSettings(void)
1679{
Roman Zippel7fc925f2006-06-08 22:12:46 -07001680 configSettings->writeEntry("/window x", pos().x());
1681 configSettings->writeEntry("/window y", pos().y());
1682 configSettings->writeEntry("/window width", size().width());
1683 configSettings->writeEntry("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
1685 QString entry;
1686 switch(configList->mode) {
1687 case singleMode :
1688 entry = "single";
1689 break;
1690
1691 case symbolMode :
1692 entry = "split";
1693 break;
1694
1695 case fullMode :
1696 entry = "full";
1697 break;
Markus Heidelberg98403a92009-05-18 01:36:49 +02001698
1699 default:
1700 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
Roman Zippel7fc925f2006-06-08 22:12:46 -07001702 configSettings->writeEntry("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Roman Zippel7fc925f2006-06-08 22:12:46 -07001704 configSettings->writeSizes("/split1", split1->sizes());
1705 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
Karsten Wiese3b354c52006-12-13 00:34:08 -08001708void ConfigMainWindow::conf_changed(void)
1709{
1710 if (saveAction)
1711 saveAction->setEnabled(conf_get_changed());
1712}
1713
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714void fixup_rootmenu(struct menu *menu)
1715{
1716 struct menu *child;
1717 static int menu_cnt = 0;
1718
1719 menu->flags |= MENU_ROOT;
1720 for (child = menu->list; child; child = child->next) {
1721 if (child->prompt && child->prompt->type == P_MENU) {
1722 menu_cnt++;
1723 fixup_rootmenu(child);
1724 menu_cnt--;
1725 } else if (!menu_cnt)
1726 fixup_rootmenu(child);
1727 }
1728}
1729
1730static const char *progname;
1731
1732static void usage(void)
1733{
Michal Marek0a1f00a2015-04-08 13:30:42 +02001734 printf(_("%s [-s] <config>\n"), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 exit(0);
1736}
1737
1738int main(int ac, char** av)
1739{
1740 ConfigMainWindow* v;
1741 const char *name;
1742
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001743 bindtextdomain(PACKAGE, LOCALEDIR);
1744 textdomain(PACKAGE);
1745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 progname = av[0];
1747 configApp = new QApplication(ac, av);
1748 if (ac > 1 && av[1][0] == '-') {
1749 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +02001750 case 's':
1751 conf_set_message_callback(NULL);
1752 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 case 'h':
1754 case '?':
1755 usage();
1756 }
1757 name = av[2];
1758 } else
1759 name = av[1];
1760 if (!name)
1761 usage();
1762
1763 conf_parse(name);
1764 fixup_rootmenu(&rootmenu);
1765 conf_read(NULL);
1766 //zconfdump(stdout);
1767
Roman Zippel7fc925f2006-06-08 22:12:46 -07001768 configSettings = new ConfigSettings();
1769 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 v = new ConfigMainWindow();
1771
1772 //zconfdump(stdout);
Roman Zippel43bf6122006-06-08 22:12:45 -07001773 configApp->setMainWidget(v);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1775 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001776 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 configApp->exec();
1778
Roman Zippel7fc925f2006-06-08 22:12:46 -07001779 configSettings->endGroup();
1780 delete configSettings;
1781
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 return 0;
1783}