blob: 1500c38f0ccabf5908f7704f683759b0e754ebce [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
8#if QT_VERSION < 0x040000
Tiana Rakotovao Andriamahefaaed99342013-01-24 16:20:39 +00009#include <stddef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <qmainwindow.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020011#include <qvbox.h>
12#include <qvaluelist.h>
13#include <qtextbrowser.h>
14#include <qaction.h>
15#include <qheader.h>
16#include <qfiledialog.h>
17#include <qdragobject.h>
18#include <qpopupmenu.h>
19#else
20#include <q3mainwindow.h>
21#include <q3vbox.h>
22#include <q3valuelist.h>
23#include <q3textbrowser.h>
24#include <q3action.h>
25#include <q3header.h>
26#include <q3filedialog.h>
27#include <q3dragobject.h>
28#include <q3popupmenu.h>
29#endif
30
31#include <qapplication.h>
Markus Heidelberg8d90c972009-05-18 01:36:52 +020032#include <qdesktopwidget.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <qtoolbar.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070034#include <qlayout.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <qsplitter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <qlineedit.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070037#include <qlabel.h>
38#include <qpushbutton.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <qmenubar.h>
40#include <qmessagebox.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <qregexp.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020042#include <qevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#include <stdlib.h>
45
46#include "lkc.h"
47#include "qconf.h"
48
49#include "qconf.moc"
50#include "images.c"
51
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070052#ifdef _
53# undef _
54# define _ qgettext
55#endif
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070058static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Alexander Stein133c5f72010-08-31 17:34:37 +020060Q3Action *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080061
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070062static inline QString qgettext(const char* str)
63{
Roman Zippel43bf6122006-06-08 22:12:45 -070064 return QString::fromLocal8Bit(gettext(str));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070065}
66
67static inline QString qgettext(const QString& str)
68{
Roman Zippel43bf6122006-06-08 22:12:45 -070069 return QString::fromLocal8Bit(gettext(str.latin1()));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070070}
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/**
73 * Reads a list of integer values from the application settings.
74 */
Alexander Stein133c5f72010-08-31 17:34:37 +020075Q3ValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Alexander Stein133c5f72010-08-31 17:34:37 +020077 Q3ValueList<int> result;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 QStringList entryList = readListEntry(key, ok);
Li Zefanc1f96f02010-05-07 13:58:04 +080079 QStringList::Iterator it;
80
81 for (it = entryList.begin(); it != entryList.end(); ++it)
82 result.push_back((*it).toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 return result;
85}
86
87/**
88 * Writes a list of integer values to the application settings.
89 */
Alexander Stein133c5f72010-08-31 17:34:37 +020090bool ConfigSettings::writeSizes(const QString& key, const Q3ValueList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 QStringList stringList;
Alexander Stein133c5f72010-08-31 17:34:37 +020093 Q3ValueList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 for (it = value.begin(); it != value.end(); ++it)
96 stringList.push_back(QString::number(*it));
97 return writeEntry(key, stringList);
98}
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/*
102 * set the new data
103 * TODO check the value
104 */
105void ConfigItem::okRename(int col)
106{
107 Parent::okRename(col);
108 sym_set_string_value(menu->sym, text(dataColIdx).latin1());
Karsten Wiese49e56462007-02-14 00:32:57 -0800109 listView()->updateList(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112/*
113 * update the displayed of a menu entry
114 */
115void ConfigItem::updateMenu(void)
116{
117 ConfigList* list;
118 struct symbol* sym;
119 struct property *prop;
120 QString prompt;
121 int type;
122 tristate expr;
123
124 list = listView();
125 if (goParent) {
126 setPixmap(promptColIdx, list->menuBackPix);
127 prompt = "..";
128 goto set_prompt;
129 }
130
131 sym = menu->sym;
132 prop = menu->prompt;
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100133 prompt = _(menu_get_prompt(menu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 if (prop) switch (prop->type) {
136 case P_MENU:
137 if (list->mode == singleMode || list->mode == symbolMode) {
138 /* a menuconfig entry is displayed differently
139 * depending whether it's at the view root or a child.
140 */
141 if (sym && list->rootEntry == menu)
142 break;
143 setPixmap(promptColIdx, list->menuPix);
144 } else {
145 if (sym)
146 break;
147 setPixmap(promptColIdx, 0);
148 }
149 goto set_prompt;
150 case P_COMMENT:
151 setPixmap(promptColIdx, 0);
152 goto set_prompt;
153 default:
154 ;
155 }
156 if (!sym)
157 goto set_prompt;
158
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700159 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 type = sym_get_type(sym);
162 switch (type) {
163 case S_BOOLEAN:
164 case S_TRISTATE:
165 char ch;
166
Li Zefan39a48972010-05-10 16:33:41 +0800167 if (!sym_is_changable(sym) && list->optMode == normalOpt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 setPixmap(promptColIdx, 0);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700169 setText(noColIdx, QString::null);
170 setText(modColIdx, QString::null);
171 setText(yesColIdx, QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 break;
173 }
174 expr = sym_get_tristate_value(sym);
175 switch (expr) {
176 case yes:
177 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
178 setPixmap(promptColIdx, list->choiceYesPix);
179 else
180 setPixmap(promptColIdx, list->symbolYesPix);
181 setText(yesColIdx, "Y");
182 ch = 'Y';
183 break;
184 case mod:
185 setPixmap(promptColIdx, list->symbolModPix);
186 setText(modColIdx, "M");
187 ch = 'M';
188 break;
189 default:
190 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
191 setPixmap(promptColIdx, list->choiceNoPix);
192 else
193 setPixmap(promptColIdx, list->symbolNoPix);
194 setText(noColIdx, "N");
195 ch = 'N';
196 break;
197 }
198 if (expr != no)
199 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
200 if (expr != mod)
201 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
202 if (expr != yes)
203 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
204
205 setText(dataColIdx, QChar(ch));
206 break;
207 case S_INT:
208 case S_HEX:
209 case S_STRING:
210 const char* data;
211
212 data = sym_get_string_value(sym);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 int i = list->mapIdx(dataColIdx);
215 if (i >= 0)
216 setRenameEnabled(i, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 setText(dataColIdx, data);
218 if (type == S_STRING)
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700219 prompt = QString("%1: %2").arg(prompt).arg(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 else
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700221 prompt = QString("(%2) %1").arg(prompt).arg(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 break;
223 }
224 if (!sym_has_value(sym) && visible)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100225 prompt += _(" (NEW)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226set_prompt:
227 setText(promptColIdx, prompt);
228}
229
230void ConfigItem::testUpdateMenu(bool v)
231{
232 ConfigItem* i;
233
234 visible = v;
235 if (!menu)
236 return;
237
238 sym_calc_value(menu->sym);
239 if (menu->flags & MENU_CHANGED) {
240 /* the menu entry changed, so update all list items */
241 menu->flags &= ~MENU_CHANGED;
242 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
243 i->updateMenu();
244 } else if (listView()->updateAll)
245 updateMenu();
246}
247
248void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
249{
250 ConfigList* list = listView();
251
252 if (visible) {
253 if (isSelected() && !list->hasFocus() && list->mode == menuMode)
254 Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
255 else
256 Parent::paintCell(p, cg, column, width, align);
257 } else
258 Parent::paintCell(p, list->disabledColorGroup, column, width, align);
259}
260
261/*
262 * construct a menu entry
263 */
264void ConfigItem::init(void)
265{
266 if (menu) {
267 ConfigList* list = listView();
268 nextItem = (ConfigItem*)menu->data;
269 menu->data = this;
270
271 if (list->mode != fullMode)
272 setOpen(TRUE);
273 sym_calc_value(menu->sym);
274 }
275 updateMenu();
276}
277
278/*
279 * destruct a menu entry
280 */
281ConfigItem::~ConfigItem(void)
282{
283 if (menu) {
284 ConfigItem** ip = (ConfigItem**)&menu->data;
285 for (; *ip; ip = &(*ip)->nextItem) {
286 if (*ip == this) {
287 *ip = nextItem;
288 break;
289 }
290 }
291 }
292}
293
Roman Zippel43bf6122006-06-08 22:12:45 -0700294ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
295 : Parent(parent)
296{
297 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300void ConfigLineEdit::show(ConfigItem* i)
301{
302 item = i;
303 if (sym_get_string_value(item->menu->sym))
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700304 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 else
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700306 setText(QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 Parent::show();
308 setFocus();
309}
310
311void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
312{
313 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200314 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200316 case Qt::Key_Return:
317 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 sym_set_string_value(item->menu->sym, text().latin1());
319 parent()->updateList(item);
320 break;
321 default:
322 Parent::keyPressEvent(e);
323 return;
324 }
325 e->accept();
326 parent()->list->setFocus();
327 hide();
328}
329
Roman Zippel7fc925f2006-06-08 22:12:46 -0700330ConfigList::ConfigList(ConfigView* p, const char *name)
331 : Parent(p, name),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 updateAll(false),
333 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
334 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
335 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
Li Zefan39a48972010-05-10 16:33:41 +0800336 showName(false), showRange(false), showData(false), optMode(normalOpt),
Roman Zippel7fc925f2006-06-08 22:12:46 -0700337 rootEntry(0), headerPopup(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 int i;
340
341 setSorting(-1);
342 setRootIsDecorated(TRUE);
343 disabledColorGroup = palette().active();
344 disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
345 inactivedColorGroup = palette().active();
346 inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
347
348 connect(this, SIGNAL(selectionChanged(void)),
349 SLOT(updateSelection(void)));
350
Roman Zippel7fc925f2006-06-08 22:12:46 -0700351 if (name) {
352 configSettings->beginGroup(name);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700353 showName = configSettings->readBoolEntry("/showName", false);
354 showRange = configSettings->readBoolEntry("/showRange", false);
355 showData = configSettings->readBoolEntry("/showData", false);
Li Zefan39a48972010-05-10 16:33:41 +0800356 optMode = (enum optionMode)configSettings->readNumEntry("/optionMode", false);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700357 configSettings->endGroup();
358 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
360
361 for (i = 0; i < colNr; i++)
362 colMap[i] = colRevMap[i] = -1;
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100363 addColumn(promptColIdx, _("Option"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 reinit();
366}
367
Li Zefan39a48972010-05-10 16:33:41 +0800368bool ConfigList::menuSkip(struct menu *menu)
369{
370 if (optMode == normalOpt && menu_is_visible(menu))
371 return false;
372 if (optMode == promptOpt && menu_has_prompt(menu))
373 return false;
374 if (optMode == allOpt)
375 return false;
376 return true;
377}
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379void ConfigList::reinit(void)
380{
381 removeColumn(dataColIdx);
382 removeColumn(yesColIdx);
383 removeColumn(modColIdx);
384 removeColumn(noColIdx);
385 removeColumn(nameColIdx);
386
387 if (showName)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100388 addColumn(nameColIdx, _("Name"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 if (showRange) {
390 addColumn(noColIdx, "N");
391 addColumn(modColIdx, "M");
392 addColumn(yesColIdx, "Y");
393 }
394 if (showData)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100395 addColumn(dataColIdx, _("Value"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 updateListAll();
398}
399
Roman Zippel7fc925f2006-06-08 22:12:46 -0700400void ConfigList::saveSettings(void)
401{
402 if (name()) {
403 configSettings->beginGroup(name());
404 configSettings->writeEntry("/showName", showName);
405 configSettings->writeEntry("/showRange", showRange);
406 configSettings->writeEntry("/showData", showData);
Li Zefan39a48972010-05-10 16:33:41 +0800407 configSettings->writeEntry("/optionMode", (int)optMode);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700408 configSettings->endGroup();
409 }
410}
411
Roman Zippelb65a47e2006-06-08 22:12:47 -0700412ConfigItem* ConfigList::findConfigItem(struct menu *menu)
413{
414 ConfigItem* item = (ConfigItem*)menu->data;
415
416 for (; item; item = item->nextItem) {
417 if (this == item->listView())
418 break;
419 }
420
421 return item;
422}
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424void ConfigList::updateSelection(void)
425{
426 struct menu *menu;
427 enum prop_type type;
428
429 ConfigItem* item = (ConfigItem*)selectedItem();
430 if (!item)
431 return;
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 menu = item->menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700434 emit menuChanged(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 if (!menu)
436 return;
437 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
438 if (mode == menuMode && type == P_MENU)
439 emit menuSelected(menu);
440}
441
442void ConfigList::updateList(ConfigItem* item)
443{
444 ConfigItem* last = 0;
445
Roman Zippel43bf6122006-06-08 22:12:45 -0700446 if (!rootEntry) {
447 if (mode != listMode)
448 goto update;
Alexander Stein133c5f72010-08-31 17:34:37 +0200449 Q3ListViewItemIterator it(this);
Roman Zippel43bf6122006-06-08 22:12:45 -0700450 ConfigItem* item;
451
452 for (; it.current(); ++it) {
453 item = (ConfigItem*)it.current();
454 if (!item->menu)
455 continue;
456 item->testUpdateMenu(menu_is_visible(item->menu));
457 }
458 return;
459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 if (rootEntry != &rootmenu && (mode == singleMode ||
462 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
463 item = firstChild();
464 if (!item)
465 item = new ConfigItem(this, 0, true);
466 last = item;
467 }
468 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
469 rootEntry->sym && rootEntry->prompt) {
470 item = last ? last->nextSibling() : firstChild();
471 if (!item)
472 item = new ConfigItem(this, last, rootEntry, true);
473 else
474 item->testUpdateMenu(true);
475
476 updateMenuList(item, rootEntry);
477 triggerUpdate();
478 return;
479 }
480update:
481 updateMenuList(this, rootEntry);
482 triggerUpdate();
483}
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485void ConfigList::setValue(ConfigItem* item, tristate val)
486{
487 struct symbol* sym;
488 int type;
489 tristate oldval;
490
491 sym = item->menu ? item->menu->sym : 0;
492 if (!sym)
493 return;
494
495 type = sym_get_type(sym);
496 switch (type) {
497 case S_BOOLEAN:
498 case S_TRISTATE:
499 oldval = sym_get_tristate_value(sym);
500
501 if (!sym_set_tristate_value(sym, val))
502 return;
503 if (oldval == no && item->menu->list)
504 item->setOpen(TRUE);
505 parent()->updateList(item);
506 break;
507 }
508}
509
510void ConfigList::changeValue(ConfigItem* item)
511{
512 struct symbol* sym;
513 struct menu* menu;
514 int type, oldexpr, newexpr;
515
516 menu = item->menu;
517 if (!menu)
518 return;
519 sym = menu->sym;
520 if (!sym) {
521 if (item->menu->list)
522 item->setOpen(!item->isOpen());
523 return;
524 }
525
526 type = sym_get_type(sym);
527 switch (type) {
528 case S_BOOLEAN:
529 case S_TRISTATE:
530 oldexpr = sym_get_tristate_value(sym);
531 newexpr = sym_toggle_tristate_value(sym);
532 if (item->menu->list) {
533 if (oldexpr == newexpr)
534 item->setOpen(!item->isOpen());
535 else if (oldexpr == no)
536 item->setOpen(TRUE);
537 }
538 if (oldexpr != newexpr)
539 parent()->updateList(item);
540 break;
541 case S_INT:
542 case S_HEX:
543 case S_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (colMap[dataColIdx] >= 0)
545 item->startRename(colMap[dataColIdx]);
546 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 parent()->lineEdit->show(item);
548 break;
549 }
550}
551
552void ConfigList::setRootMenu(struct menu *menu)
553{
554 enum prop_type type;
555
556 if (rootEntry == menu)
557 return;
558 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
559 if (type != P_MENU)
560 return;
561 updateMenuList(this, 0);
562 rootEntry = menu;
563 updateListAll();
564 setSelected(currentItem(), hasFocus());
Roman Zippelb65a47e2006-06-08 22:12:47 -0700565 ensureItemVisible(currentItem());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
568void ConfigList::setParentMenu(void)
569{
570 ConfigItem* item;
571 struct menu *oldroot;
572
573 oldroot = rootEntry;
574 if (rootEntry == &rootmenu)
575 return;
576 setRootMenu(menu_get_parent_menu(rootEntry->parent));
577
Alexander Stein133c5f72010-08-31 17:34:37 +0200578 Q3ListViewItemIterator it(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 for (; (item = (ConfigItem*)it.current()); it++) {
580 if (item->menu == oldroot) {
581 setCurrentItem(item);
582 ensureItemVisible(item);
583 break;
584 }
585 }
586}
587
Roman Zippel7fc925f2006-06-08 22:12:46 -0700588/*
589 * update all the children of a menu entry
590 * removes/adds the entries from the parent widget as necessary
591 *
592 * parent: either the menu list widget or a menu entry widget
593 * menu: entry to be updated
594 */
595template <class P>
596void ConfigList::updateMenuList(P* parent, struct menu* menu)
597{
598 struct menu* child;
599 ConfigItem* item;
600 ConfigItem* last;
601 bool visible;
602 enum prop_type type;
603
604 if (!menu) {
605 while ((item = parent->firstChild()))
606 delete item;
607 return;
608 }
609
610 last = parent->firstChild();
611 if (last && !last->goParent)
612 last = 0;
613 for (child = menu->list; child; child = child->next) {
614 item = last ? last->nextSibling() : parent->firstChild();
615 type = child->prompt ? child->prompt->type : P_UNKNOWN;
616
617 switch (mode) {
618 case menuMode:
619 if (!(child->flags & MENU_ROOT))
620 goto hide;
621 break;
622 case symbolMode:
623 if (child->flags & MENU_ROOT)
624 goto hide;
625 break;
626 default:
627 break;
628 }
629
630 visible = menu_is_visible(child);
Li Zefan39a48972010-05-10 16:33:41 +0800631 if (!menuSkip(child)) {
Cyrill V. Gorcunoved8b4d42007-02-14 00:33:03 -0800632 if (!child->sym && !child->list && !child->prompt)
633 continue;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700634 if (!item || item->menu != child)
635 item = new ConfigItem(parent, last, child, visible);
636 else
637 item->testUpdateMenu(visible);
638
639 if (mode == fullMode || mode == menuMode || type != P_MENU)
640 updateMenuList(item, child);
641 else
642 updateMenuList(item, 0);
643 last = item;
644 continue;
645 }
646 hide:
647 if (item && item->menu == child) {
648 last = parent->firstChild();
649 if (last == item)
650 last = 0;
651 else while (last->nextSibling() != item)
652 last = last->nextSibling();
653 delete item;
654 }
655 }
656}
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658void ConfigList::keyPressEvent(QKeyEvent* ev)
659{
Alexander Stein133c5f72010-08-31 17:34:37 +0200660 Q3ListViewItem* i = currentItem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 ConfigItem* item;
662 struct menu *menu;
663 enum prop_type type;
664
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200665 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 emit parentSelected();
667 ev->accept();
668 return;
669 }
670
671 if (!i) {
672 Parent::keyPressEvent(ev);
673 return;
674 }
675 item = (ConfigItem*)i;
676
677 switch (ev->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200678 case Qt::Key_Return:
679 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 if (item->goParent) {
681 emit parentSelected();
682 break;
683 }
684 menu = item->menu;
685 if (!menu)
686 break;
687 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
688 if (type == P_MENU && rootEntry != menu &&
689 mode != fullMode && mode != menuMode) {
690 emit menuSelected(menu);
691 break;
692 }
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200693 case Qt::Key_Space:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 changeValue(item);
695 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200696 case Qt::Key_N:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 setValue(item, no);
698 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200699 case Qt::Key_M:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 setValue(item, mod);
701 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200702 case Qt::Key_Y:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 setValue(item, yes);
704 break;
705 default:
706 Parent::keyPressEvent(ev);
707 return;
708 }
709 ev->accept();
710}
711
712void ConfigList::contentsMousePressEvent(QMouseEvent* e)
713{
714 //QPoint p(contentsToViewport(e->pos()));
715 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
716 Parent::contentsMousePressEvent(e);
717}
718
719void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
720{
721 QPoint p(contentsToViewport(e->pos()));
722 ConfigItem* item = (ConfigItem*)itemAt(p);
723 struct menu *menu;
724 enum prop_type ptype;
725 const QPixmap* pm;
726 int idx, x;
727
728 if (!item)
729 goto skip;
730
731 menu = item->menu;
732 x = header()->offset() + p.x();
733 idx = colRevMap[header()->sectionAt(x)];
734 switch (idx) {
735 case promptColIdx:
736 pm = item->pixmap(promptColIdx);
737 if (pm) {
738 int off = header()->sectionPos(0) + itemMargin() +
739 treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
740 if (x >= off && x < off + pm->width()) {
741 if (item->goParent) {
742 emit parentSelected();
743 break;
744 } else if (!menu)
745 break;
746 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
747 if (ptype == P_MENU && rootEntry != menu &&
748 mode != fullMode && mode != menuMode)
749 emit menuSelected(menu);
750 else
751 changeValue(item);
752 }
753 }
754 break;
755 case noColIdx:
756 setValue(item, no);
757 break;
758 case modColIdx:
759 setValue(item, mod);
760 break;
761 case yesColIdx:
762 setValue(item, yes);
763 break;
764 case dataColIdx:
765 changeValue(item);
766 break;
767 }
768
769skip:
770 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
771 Parent::contentsMouseReleaseEvent(e);
772}
773
774void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
775{
776 //QPoint p(contentsToViewport(e->pos()));
777 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
778 Parent::contentsMouseMoveEvent(e);
779}
780
781void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
782{
783 QPoint p(contentsToViewport(e->pos()));
784 ConfigItem* item = (ConfigItem*)itemAt(p);
785 struct menu *menu;
786 enum prop_type ptype;
787
788 if (!item)
789 goto skip;
790 if (item->goParent) {
791 emit parentSelected();
792 goto skip;
793 }
794 menu = item->menu;
795 if (!menu)
796 goto skip;
797 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
798 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
799 emit menuSelected(menu);
800 else if (menu->sym)
801 changeValue(item);
802
803skip:
804 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
805 Parent::contentsMouseDoubleClickEvent(e);
806}
807
808void ConfigList::focusInEvent(QFocusEvent *e)
809{
Roman Zippelb65a47e2006-06-08 22:12:47 -0700810 struct menu *menu = NULL;
811
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 Parent::focusInEvent(e);
813
Roman Zippelb65a47e2006-06-08 22:12:47 -0700814 ConfigItem* item = (ConfigItem *)currentItem();
815 if (item) {
816 setSelected(item, TRUE);
817 menu = item->menu;
818 }
819 emit gotFocus(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820}
821
Roman Zippel7fc925f2006-06-08 22:12:46 -0700822void ConfigList::contextMenuEvent(QContextMenuEvent *e)
823{
824 if (e->y() <= header()->geometry().bottom()) {
825 if (!headerPopup) {
Alexander Stein133c5f72010-08-31 17:34:37 +0200826 Q3Action *action;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700827
Alexander Stein133c5f72010-08-31 17:34:37 +0200828 headerPopup = new Q3PopupMenu(this);
829 action = new Q3Action(NULL, _("Show Name"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700830 action->setToggleAction(TRUE);
831 connect(action, SIGNAL(toggled(bool)),
832 parent(), SLOT(setShowName(bool)));
833 connect(parent(), SIGNAL(showNameChanged(bool)),
834 action, SLOT(setOn(bool)));
835 action->setOn(showName);
836 action->addTo(headerPopup);
Alexander Stein133c5f72010-08-31 17:34:37 +0200837 action = new Q3Action(NULL, _("Show Range"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700838 action->setToggleAction(TRUE);
839 connect(action, SIGNAL(toggled(bool)),
840 parent(), SLOT(setShowRange(bool)));
841 connect(parent(), SIGNAL(showRangeChanged(bool)),
842 action, SLOT(setOn(bool)));
843 action->setOn(showRange);
844 action->addTo(headerPopup);
Alexander Stein133c5f72010-08-31 17:34:37 +0200845 action = new Q3Action(NULL, _("Show Data"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700846 action->setToggleAction(TRUE);
847 connect(action, SIGNAL(toggled(bool)),
848 parent(), SLOT(setShowData(bool)));
849 connect(parent(), SIGNAL(showDataChanged(bool)),
850 action, SLOT(setOn(bool)));
851 action->setOn(showData);
852 action->addTo(headerPopup);
853 }
854 headerPopup->exec(e->globalPos());
855 e->accept();
856 } else
857 e->ignore();
858}
859
Li Zefan39a48972010-05-10 16:33:41 +0800860ConfigView*ConfigView::viewList;
861QAction *ConfigView::showNormalAction;
862QAction *ConfigView::showAllAction;
863QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Roman Zippel7fc925f2006-06-08 22:12:46 -0700865ConfigView::ConfigView(QWidget* parent, const char *name)
866 : Parent(parent, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700868 list = new ConfigList(this, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 lineEdit = new ConfigLineEdit(this);
870 lineEdit->hide();
871
872 this->nextView = viewList;
873 viewList = this;
874}
875
876ConfigView::~ConfigView(void)
877{
878 ConfigView** vp;
879
880 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
881 if (*vp == this) {
882 *vp = nextView;
883 break;
884 }
885 }
886}
887
Li Zefan39a48972010-05-10 16:33:41 +0800888void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700889{
Li Zefan39a48972010-05-10 16:33:41 +0800890 if (act == showNormalAction)
891 list->optMode = normalOpt;
892 else if (act == showAllAction)
893 list->optMode = allOpt;
894 else
895 list->optMode = promptOpt;
896
897 list->updateListAll();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700898}
899
900void ConfigView::setShowName(bool b)
901{
902 if (list->showName != b) {
903 list->showName = b;
904 list->reinit();
905 emit showNameChanged(b);
906 }
907}
908
909void ConfigView::setShowRange(bool b)
910{
911 if (list->showRange != b) {
912 list->showRange = b;
913 list->reinit();
914 emit showRangeChanged(b);
915 }
916}
917
918void ConfigView::setShowData(bool b)
919{
920 if (list->showData != b) {
921 list->showData = b;
922 list->reinit();
923 emit showDataChanged(b);
924 }
925}
926
927void ConfigList::setAllOpen(bool open)
928{
Alexander Stein133c5f72010-08-31 17:34:37 +0200929 Q3ListViewItemIterator it(this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700930
931 for (; it.current(); it++)
932 it.current()->setOpen(open);
933}
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935void ConfigView::updateList(ConfigItem* item)
936{
937 ConfigView* v;
938
939 for (v = viewList; v; v = v->nextView)
940 v->list->updateList(item);
941}
942
943void ConfigView::updateListAll(void)
944{
945 ConfigView* v;
946
947 for (v = viewList; v; v = v->nextView)
948 v->list->updateListAll();
949}
950
Roman Zippel43bf6122006-06-08 22:12:45 -0700951ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Alexander Stein133c5f72010-08-31 17:34:37 +0200952 : Parent(parent, name), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700953{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700954 if (name) {
955 configSettings->beginGroup(name);
956 _showDebug = configSettings->readBoolEntry("/showDebug", false);
957 configSettings->endGroup();
958 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
959 }
960}
961
962void ConfigInfoView::saveSettings(void)
963{
964 if (name()) {
965 configSettings->beginGroup(name());
966 configSettings->writeEntry("/showDebug", showDebug());
967 configSettings->endGroup();
968 }
Roman Zippel43bf6122006-06-08 22:12:45 -0700969}
970
971void ConfigInfoView::setShowDebug(bool b)
972{
973 if (_showDebug != b) {
974 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +0200975 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700976 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -0700977 else if (sym)
978 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -0700979 emit showDebugChanged(b);
980 }
981}
982
983void ConfigInfoView::setInfo(struct menu *m)
984{
Alexander Stein133c5f72010-08-31 17:34:37 +0200985 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -0700986 return;
Alexander Stein133c5f72010-08-31 17:34:37 +0200987 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -0800988 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +0200989 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700990 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -0800991 else
Roman Zippel43bf6122006-06-08 22:12:45 -0700992 menuInfo();
993}
994
Roman Zippelab45d192006-06-08 22:12:47 -0700995void ConfigInfoView::symbolInfo(void)
996{
997 QString str;
998
999 str += "<big>Symbol: <b>";
1000 str += print_filter(sym->name);
1001 str += "</b></big><br><br>value: ";
1002 str += print_filter(sym_get_string_value(sym));
1003 str += "<br>visibility: ";
1004 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1005 str += "<br>";
1006 str += debug_info(sym);
1007
1008 setText(str);
1009}
1010
Roman Zippel43bf6122006-06-08 22:12:45 -07001011void ConfigInfoView::menuInfo(void)
1012{
1013 struct symbol* sym;
1014 QString head, debug, help;
1015
Alexander Stein133c5f72010-08-31 17:34:37 +02001016 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -07001017 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001018 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001019 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001020 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001021 head += "</b></big>";
1022 if (sym->name) {
1023 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -07001024 if (showDebug())
1025 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001026 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001027 if (showDebug())
1028 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001029 head += ")";
1030 }
1031 } else if (sym->name) {
1032 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001033 if (showDebug())
1034 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001035 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001036 if (showDebug())
1037 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001038 head += "</b></big>";
1039 }
1040 head += "<br><br>";
1041
1042 if (showDebug())
1043 debug = debug_info(sym);
1044
Cheng Renquand74c15f2009-07-12 16:11:47 +08001045 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +02001046 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +08001047 help = print_filter(str_get(&help_gstr));
1048 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +02001049 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001050 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +02001051 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -07001052 head += "</b></big><br><br>";
1053 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +02001054 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -07001055 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +02001056 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001057 debug += "<br><br>";
1058 }
1059 }
1060 }
1061 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +02001062 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -07001063
1064 setText(head + debug + help);
1065}
1066
1067QString ConfigInfoView::debug_info(struct symbol *sym)
1068{
1069 QString debug;
1070
1071 debug += "type: ";
1072 debug += print_filter(sym_type_name(sym->type));
1073 if (sym_is_choice(sym))
1074 debug += " (choice)";
1075 debug += "<br>";
1076 if (sym->rev_dep.expr) {
1077 debug += "reverse dep: ";
1078 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1079 debug += "<br>";
1080 }
1081 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1082 switch (prop->type) {
1083 case P_PROMPT:
1084 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -07001085 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Roman Zippel43bf6122006-06-08 22:12:45 -07001086 debug += print_filter(_(prop->text));
Roman Zippelab45d192006-06-08 22:12:47 -07001087 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001088 break;
1089 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001090 case P_SELECT:
1091 case P_RANGE:
1092 case P_ENV:
1093 debug += prop_get_type_name(prop->type);
1094 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001095 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1096 debug += "<br>";
1097 break;
1098 case P_CHOICE:
1099 if (sym_is_choice(sym)) {
1100 debug += "choice: ";
1101 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1102 debug += "<br>";
1103 }
1104 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001105 default:
1106 debug += "unknown property: ";
1107 debug += prop_get_type_name(prop->type);
1108 debug += "<br>";
1109 }
1110 if (prop->visible.expr) {
1111 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1112 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1113 debug += "<br>";
1114 }
1115 }
1116 debug += "<br>";
1117
1118 return debug;
1119}
1120
1121QString ConfigInfoView::print_filter(const QString &str)
1122{
1123 QRegExp re("[<>&\"\\n]");
1124 QString res = str;
1125 for (int i = 0; (i = res.find(re, i)) >= 0;) {
1126 switch (res[i].latin1()) {
1127 case '<':
1128 res.replace(i, 1, "&lt;");
1129 i += 4;
1130 break;
1131 case '>':
1132 res.replace(i, 1, "&gt;");
1133 i += 4;
1134 break;
1135 case '&':
1136 res.replace(i, 1, "&amp;");
1137 i += 5;
1138 break;
1139 case '"':
1140 res.replace(i, 1, "&quot;");
1141 i += 6;
1142 break;
1143 case '\n':
1144 res.replace(i, 1, "<br>");
1145 i += 4;
1146 break;
1147 }
1148 }
1149 return res;
1150}
1151
Roman Zippelab45d192006-06-08 22:12:47 -07001152void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001153{
Roman Zippelab45d192006-06-08 22:12:47 -07001154 QString* text = reinterpret_cast<QString*>(data);
1155 QString str2 = print_filter(str);
1156
1157 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1158 *text += QString().sprintf("<a href=\"s%p\">", sym);
1159 *text += str2;
1160 *text += "</a>";
1161 } else
1162 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001163}
1164
Alexander Stein133c5f72010-08-31 17:34:37 +02001165Q3PopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001166{
Alexander Stein133c5f72010-08-31 17:34:37 +02001167 Q3PopupMenu* popup = Parent::createPopupMenu(pos);
1168 Q3Action* action = new Q3Action(NULL, _("Show Debug Info"), 0, popup);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001169 action->setToggleAction(TRUE);
1170 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1171 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1172 action->setOn(showDebug());
1173 popup->insertSeparator();
1174 action->addTo(popup);
1175 return popup;
1176}
1177
1178void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
1179{
1180 Parent::contentsContextMenuEvent(e);
1181}
1182
Marco Costalba63431e72006-10-05 19:12:59 +02001183ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001184 : Parent(parent, name), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001185{
1186 setCaption("Search Config");
1187
1188 QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
1189 QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001190 layout2->addWidget(new QLabel(_("Find:"), this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001191 editField = new QLineEdit(this);
1192 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1193 layout2->addWidget(editField);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001194 searchButton = new QPushButton(_("Search"), this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001195 searchButton->setAutoDefault(FALSE);
1196 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1197 layout2->addWidget(searchButton);
1198 layout1->addLayout(layout2);
1199
Roman Zippel7fc925f2006-06-08 22:12:46 -07001200 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001201 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001202 list = new ConfigView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001203 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001204 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001205 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1206 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001207 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1208 parent, SLOT(setMenuLink(struct menu *)));
1209
Roman Zippel43bf6122006-06-08 22:12:45 -07001210 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001211
1212 if (name) {
1213 int x, y, width, height;
1214 bool ok;
1215
1216 configSettings->beginGroup(name);
1217 width = configSettings->readNumEntry("/window width", parent->width() / 2);
1218 height = configSettings->readNumEntry("/window height", parent->height() / 2);
1219 resize(width, height);
1220 x = configSettings->readNumEntry("/window x", 0, &ok);
1221 if (ok)
1222 y = configSettings->readNumEntry("/window y", 0, &ok);
1223 if (ok)
1224 move(x, y);
Alexander Stein133c5f72010-08-31 17:34:37 +02001225 Q3ValueList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001226 if (ok)
1227 split->setSizes(sizes);
1228 configSettings->endGroup();
1229 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1230 }
1231}
1232
1233void ConfigSearchWindow::saveSettings(void)
1234{
1235 if (name()) {
1236 configSettings->beginGroup(name());
1237 configSettings->writeEntry("/window x", pos().x());
1238 configSettings->writeEntry("/window y", pos().y());
1239 configSettings->writeEntry("/window width", size().width());
1240 configSettings->writeEntry("/window height", size().height());
1241 configSettings->writeSizes("/split", split->sizes());
1242 configSettings->endGroup();
1243 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001244}
1245
1246void ConfigSearchWindow::search(void)
1247{
1248 struct symbol **p;
1249 struct property *prop;
1250 ConfigItem *lastItem = NULL;
1251
1252 free(result);
1253 list->list->clear();
Cyrill V. Gorcunov786fb182007-02-14 00:32:59 -08001254 info->clear();
Roman Zippel43bf6122006-06-08 22:12:45 -07001255
1256 result = sym_re_search(editField->text().latin1());
1257 if (!result)
1258 return;
1259 for (p = result; *p; p++) {
1260 for_all_prompts((*p), prop)
1261 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1262 menu_is_visible(prop->menu));
1263 }
1264}
1265
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266/*
1267 * Construct the complete config widget
1268 */
1269ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001270 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
1272 QMenuBar* menu;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001273 bool ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 int x, y, width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001275 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001277 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -04001278 snprintf(title, sizeof(title), "%s%s",
1279 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +02001280#if QT_VERSION < 0x040000
1281 " (Qt3)"
1282#else
1283 ""
1284#endif
1285 );
Randy Dunlapa54bb702007-10-20 11:18:47 -07001286 setCaption(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Roman Zippel7fc925f2006-06-08 22:12:46 -07001288 width = configSettings->readNumEntry("/window width", d->width() - 64);
1289 height = configSettings->readNumEntry("/window height", d->height() - 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 resize(width, height);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001291 x = configSettings->readNumEntry("/window x", 0, &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 if (ok)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001293 y = configSettings->readNumEntry("/window y", 0, &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 if (ok)
1295 move(x, y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
1297 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001298 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 setCentralWidget(split1);
1300
Roman Zippel7fc925f2006-06-08 22:12:46 -07001301 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 menuList = menuView->list;
1303
1304 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001305 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -07001308 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 configList = configView->list;
1310
Roman Zippel7fc925f2006-06-08 22:12:46 -07001311 helpText = new ConfigInfoView(split2, "help");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 helpText->setTextFormat(Qt::RichText);
1313
1314 setTabOrder(configList, helpText);
1315 configList->setFocus();
1316
1317 menu = menuBar();
Alexander Stein133c5f72010-08-31 17:34:37 +02001318 toolBar = new Q3ToolBar("Tools", this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Alexander Stein133c5f72010-08-31 17:34:37 +02001320 backAction = new Q3Action("Back", QPixmap(xpm_back), _("Back"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 connect(backAction, SIGNAL(activated()), SLOT(goBack()));
1322 backAction->setEnabled(FALSE);
Alexander Stein133c5f72010-08-31 17:34:37 +02001323 Q3Action *quitAction = new Q3Action("Quit", _("&Quit"), Qt::CTRL + Qt::Key_Q, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 connect(quitAction, SIGNAL(activated()), SLOT(close()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001325 Q3Action *loadAction = new Q3Action("Load", QPixmap(xpm_load), _("&Load"), Qt::CTRL + Qt::Key_L, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001327 saveAction = new Q3Action("Save", QPixmap(xpm_save), _("&Save"), Qt::CTRL + Qt::Key_S, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001329 conf_set_changed_callback(conf_changed);
1330 // Set saveAction's initial state
1331 conf_changed();
Alexander Stein133c5f72010-08-31 17:34:37 +02001332 Q3Action *saveAsAction = new Q3Action("Save As...", _("Save &As..."), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001334 Q3Action *searchAction = new Q3Action("Find", _("&Find"), Qt::CTRL + Qt::Key_F, this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001335 connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001336 Q3Action *singleViewAction = new Q3Action("Single View", QPixmap(xpm_single_view), _("Single View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001338 Q3Action *splitViewAction = new Q3Action("Split View", QPixmap(xpm_split_view), _("Split View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001340 Q3Action *fullViewAction = new Q3Action("Full View", QPixmap(xpm_tree_view), _("Full View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
1342
Alexander Stein133c5f72010-08-31 17:34:37 +02001343 Q3Action *showNameAction = new Q3Action(NULL, _("Show Name"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 showNameAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001345 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
1346 connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
1347 showNameAction->setOn(configView->showName());
Alexander Stein133c5f72010-08-31 17:34:37 +02001348 Q3Action *showRangeAction = new Q3Action(NULL, _("Show Range"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 showRangeAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001350 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
1351 connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 showRangeAction->setOn(configList->showRange);
Alexander Stein133c5f72010-08-31 17:34:37 +02001353 Q3Action *showDataAction = new Q3Action(NULL, _("Show Data"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 showDataAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001355 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
1356 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 showDataAction->setOn(configList->showData);
Li Zefan39a48972010-05-10 16:33:41 +08001358
1359 QActionGroup *optGroup = new QActionGroup(this);
1360 optGroup->setExclusive(TRUE);
1361 connect(optGroup, SIGNAL(selected(QAction *)), configView,
1362 SLOT(setOptionMode(QAction *)));
1363 connect(optGroup, SIGNAL(selected(QAction *)), menuView,
1364 SLOT(setOptionMode(QAction *)));
1365
Alexander Stein133c5f72010-08-31 17:34:37 +02001366#if QT_VERSION >= 0x040000
1367 configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
1368 configView->showAllAction = new QAction(_("Show All Options"), optGroup);
1369 configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
1370#else
1371 configView->showNormalAction = new QAction(_("Show Normal Options"), 0, optGroup);
1372 configView->showAllAction = new QAction(_("Show All Options"), 0, optGroup);
1373 configView->showPromptAction = new QAction(_("Show Prompt Options"), 0, optGroup);
1374#endif
Li Zefan39a48972010-05-10 16:33:41 +08001375 configView->showNormalAction->setToggleAction(TRUE);
1376 configView->showNormalAction->setOn(configList->optMode == normalOpt);
1377 configView->showAllAction->setToggleAction(TRUE);
1378 configView->showAllAction->setOn(configList->optMode == allOpt);
1379 configView->showPromptAction->setToggleAction(TRUE);
1380 configView->showPromptAction->setOn(configList->optMode == promptOpt);
1381
Alexander Stein133c5f72010-08-31 17:34:37 +02001382 Q3Action *showDebugAction = new Q3Action(NULL, _("Show Debug Info"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 showDebugAction->setToggleAction(TRUE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001384 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
1385 connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
Roman Zippel7fc925f2006-06-08 22:12:46 -07001386 showDebugAction->setOn(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Alexander Stein133c5f72010-08-31 17:34:37 +02001388 Q3Action *showIntroAction = new Q3Action(NULL, _("Introduction"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
Alexander Stein133c5f72010-08-31 17:34:37 +02001390 Q3Action *showAboutAction = new Q3Action(NULL, _("About"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
1392
1393 // init tool bar
1394 backAction->addTo(toolBar);
1395 toolBar->addSeparator();
1396 loadAction->addTo(toolBar);
1397 saveAction->addTo(toolBar);
1398 toolBar->addSeparator();
1399 singleViewAction->addTo(toolBar);
1400 splitViewAction->addTo(toolBar);
1401 fullViewAction->addTo(toolBar);
1402
1403 // create config menu
Alexander Stein133c5f72010-08-31 17:34:37 +02001404 Q3PopupMenu* config = new Q3PopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001405 menu->insertItem(_("&File"), config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 loadAction->addTo(config);
1407 saveAction->addTo(config);
1408 saveAsAction->addTo(config);
1409 config->insertSeparator();
1410 quitAction->addTo(config);
1411
Shlomi Fish66e7c722007-02-14 00:32:58 -08001412 // create edit menu
Alexander Stein133c5f72010-08-31 17:34:37 +02001413 Q3PopupMenu* editMenu = new Q3PopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001414 menu->insertItem(_("&Edit"), editMenu);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001415 searchAction->addTo(editMenu);
1416
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 // create options menu
Alexander Stein133c5f72010-08-31 17:34:37 +02001418 Q3PopupMenu* optionMenu = new Q3PopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001419 menu->insertItem(_("&Option"), optionMenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 showNameAction->addTo(optionMenu);
1421 showRangeAction->addTo(optionMenu);
1422 showDataAction->addTo(optionMenu);
1423 optionMenu->insertSeparator();
Li Zefan39a48972010-05-10 16:33:41 +08001424 optGroup->addTo(optionMenu);
1425 optionMenu->insertSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 // create help menu
Alexander Stein133c5f72010-08-31 17:34:37 +02001428 Q3PopupMenu* helpMenu = new Q3PopupMenu(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 menu->insertSeparator();
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001430 menu->insertItem(_("&Help"), helpMenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 showIntroAction->addTo(helpMenu);
1432 showAboutAction->addTo(helpMenu);
1433
Roman Zippel43bf6122006-06-08 22:12:45 -07001434 connect(configList, SIGNAL(menuChanged(struct menu *)),
1435 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 connect(configList, SIGNAL(menuSelected(struct menu *)),
1437 SLOT(changeMenu(struct menu *)));
1438 connect(configList, SIGNAL(parentSelected()),
1439 SLOT(goBack()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001440 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1441 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1443 SLOT(changeMenu(struct menu *)));
1444
Roman Zippelb65a47e2006-06-08 22:12:47 -07001445 connect(configList, SIGNAL(gotFocus(struct menu *)),
1446 helpText, SLOT(setInfo(struct menu *)));
1447 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1448 helpText, SLOT(setInfo(struct menu *)));
1449 connect(menuList, SIGNAL(gotFocus(struct menu *)),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001451 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1452 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Roman Zippel7fc925f2006-06-08 22:12:46 -07001454 QString listMode = configSettings->readEntry("/listMode", "symbol");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 if (listMode == "single")
1456 showSingleView();
1457 else if (listMode == "full")
1458 showFullView();
1459 else /*if (listMode == "split")*/
1460 showSplitView();
1461
1462 // UI setup done, restore splitter positions
Alexander Stein133c5f72010-08-31 17:34:37 +02001463 Q3ValueList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 if (ok)
1465 split1->setSizes(sizes);
1466
Roman Zippel7fc925f2006-06-08 22:12:46 -07001467 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 if (ok)
1469 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470}
1471
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472void ConfigMainWindow::loadConfig(void)
1473{
Alexander Stein133c5f72010-08-31 17:34:37 +02001474 QString s = Q3FileDialog::getOpenFileName(conf_get_configname(), NULL, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 if (s.isNull())
1476 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001477 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001478 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 ConfigView::updateListAll();
1480}
1481
Michal Marekbac6aa82011-05-25 15:10:25 +02001482bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
Michal Marekbac6aa82011-05-25 15:10:25 +02001484 if (conf_write(NULL)) {
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001485 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Michal Marekbac6aa82011-05-25 15:10:25 +02001486 return false;
1487 }
1488 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
1491void ConfigMainWindow::saveConfigAs(void)
1492{
Alexander Stein133c5f72010-08-31 17:34:37 +02001493 QString s = Q3FileDialog::getSaveFileName(conf_get_configname(), NULL, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 if (s.isNull())
1495 return;
Arnaud Lacombed49e4682011-05-24 14:16:18 -04001496 saveConfig();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497}
1498
Roman Zippel43bf6122006-06-08 22:12:45 -07001499void ConfigMainWindow::searchConfig(void)
1500{
1501 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001502 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001503 searchWindow->show();
1504}
1505
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506void ConfigMainWindow::changeMenu(struct menu *menu)
1507{
1508 configList->setRootMenu(menu);
Cyrill V. Gorcunovf253f002007-02-14 00:33:00 -08001509 if (configList->rootEntry->parent == &rootmenu)
1510 backAction->setEnabled(FALSE);
1511 else
1512 backAction->setEnabled(TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Roman Zippelb65a47e2006-06-08 22:12:47 -07001515void ConfigMainWindow::setMenuLink(struct menu *menu)
1516{
1517 struct menu *parent;
1518 ConfigList* list = NULL;
1519 ConfigItem* item;
1520
Li Zefan39a48972010-05-10 16:33:41 +08001521 if (configList->menuSkip(menu))
Roman Zippelb65a47e2006-06-08 22:12:47 -07001522 return;
1523
1524 switch (configList->mode) {
1525 case singleMode:
1526 list = configList;
1527 parent = menu_get_parent_menu(menu);
1528 if (!parent)
1529 return;
1530 list->setRootMenu(parent);
1531 break;
1532 case symbolMode:
1533 if (menu->flags & MENU_ROOT) {
1534 configList->setRootMenu(menu);
1535 configList->clearSelection();
1536 list = menuList;
1537 } else {
1538 list = configList;
1539 parent = menu_get_parent_menu(menu->parent);
1540 if (!parent)
1541 return;
1542 item = menuList->findConfigItem(parent);
1543 if (item) {
1544 menuList->setSelected(item, TRUE);
1545 menuList->ensureItemVisible(item);
1546 }
1547 list->setRootMenu(parent);
1548 }
1549 break;
1550 case fullMode:
1551 list = configList;
1552 break;
Markus Heidelberg98403a92009-05-18 01:36:49 +02001553 default:
1554 break;
Roman Zippelb65a47e2006-06-08 22:12:47 -07001555 }
1556
1557 if (list) {
1558 item = list->findConfigItem(menu);
1559 if (item) {
1560 list->setSelected(item, TRUE);
1561 list->ensureItemVisible(item);
1562 list->setFocus();
1563 }
1564 }
1565}
1566
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567void ConfigMainWindow::listFocusChanged(void)
1568{
Roman Zippelb65a47e2006-06-08 22:12:47 -07001569 if (menuList->mode == menuMode)
1570 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
1573void ConfigMainWindow::goBack(void)
1574{
1575 ConfigItem* item;
1576
1577 configList->setParentMenu();
1578 if (configList->rootEntry == &rootmenu)
1579 backAction->setEnabled(FALSE);
1580 item = (ConfigItem*)menuList->selectedItem();
1581 while (item) {
1582 if (item->menu == configList->rootEntry) {
1583 menuList->setSelected(item, TRUE);
1584 break;
1585 }
1586 item = (ConfigItem*)item->parent();
1587 }
1588}
1589
1590void ConfigMainWindow::showSingleView(void)
1591{
1592 menuView->hide();
1593 menuList->setRootMenu(0);
1594 configList->mode = singleMode;
1595 if (configList->rootEntry == &rootmenu)
1596 configList->updateListAll();
1597 else
1598 configList->setRootMenu(&rootmenu);
1599 configList->setAllOpen(TRUE);
1600 configList->setFocus();
1601}
1602
1603void ConfigMainWindow::showSplitView(void)
1604{
1605 configList->mode = symbolMode;
1606 if (configList->rootEntry == &rootmenu)
1607 configList->updateListAll();
1608 else
1609 configList->setRootMenu(&rootmenu);
1610 configList->setAllOpen(TRUE);
1611 configApp->processEvents();
1612 menuList->mode = menuMode;
1613 menuList->setRootMenu(&rootmenu);
1614 menuList->setAllOpen(TRUE);
1615 menuView->show();
1616 menuList->setFocus();
1617}
1618
1619void ConfigMainWindow::showFullView(void)
1620{
1621 menuView->hide();
1622 menuList->setRootMenu(0);
1623 configList->mode = fullMode;
1624 if (configList->rootEntry == &rootmenu)
1625 configList->updateListAll();
1626 else
1627 configList->setRootMenu(&rootmenu);
1628 configList->setAllOpen(FALSE);
1629 configList->setFocus();
1630}
1631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632/*
1633 * ask for saving configuration before quitting
1634 * TODO ask only when something changed
1635 */
1636void ConfigMainWindow::closeEvent(QCloseEvent* e)
1637{
Karsten Wieseb3214292006-12-13 00:34:06 -08001638 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 e->accept();
1640 return;
1641 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001642 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001644 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1645 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1646 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 switch (mb.exec()) {
1648 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +02001649 if (saveConfig())
1650 e->accept();
1651 else
1652 e->ignore();
1653 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 case QMessageBox::No:
1655 e->accept();
1656 break;
1657 case QMessageBox::Cancel:
1658 e->ignore();
1659 break;
1660 }
1661}
1662
1663void ConfigMainWindow::showIntro(void)
1664{
Arnaud Lacombe652cf982010-08-14 23:51:40 -04001665 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 "For each option, a blank box indicates the feature is disabled, a check\n"
1667 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1668 "as a module. Clicking on the box will cycle through the three states.\n\n"
1669 "If you do not see an option (e.g., a device driver) that you believe\n"
1670 "should be present, try turning on Show All Options under the Options menu.\n"
1671 "Although there is no cross reference yet to help you figure out what other\n"
1672 "options must be enabled to support the option you are interested in, you can\n"
1673 "still view the help of a grayed-out option.\n\n"
1674 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001675 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
1677 QMessageBox::information(this, "qconf", str);
1678}
1679
1680void ConfigMainWindow::showAbout(void)
1681{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001682 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1683 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
1685 QMessageBox::information(this, "qconf", str);
1686}
1687
1688void ConfigMainWindow::saveSettings(void)
1689{
Roman Zippel7fc925f2006-06-08 22:12:46 -07001690 configSettings->writeEntry("/window x", pos().x());
1691 configSettings->writeEntry("/window y", pos().y());
1692 configSettings->writeEntry("/window width", size().width());
1693 configSettings->writeEntry("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
1695 QString entry;
1696 switch(configList->mode) {
1697 case singleMode :
1698 entry = "single";
1699 break;
1700
1701 case symbolMode :
1702 entry = "split";
1703 break;
1704
1705 case fullMode :
1706 entry = "full";
1707 break;
Markus Heidelberg98403a92009-05-18 01:36:49 +02001708
1709 default:
1710 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 }
Roman Zippel7fc925f2006-06-08 22:12:46 -07001712 configSettings->writeEntry("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
Roman Zippel7fc925f2006-06-08 22:12:46 -07001714 configSettings->writeSizes("/split1", split1->sizes());
1715 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Karsten Wiese3b354c52006-12-13 00:34:08 -08001718void ConfigMainWindow::conf_changed(void)
1719{
1720 if (saveAction)
1721 saveAction->setEnabled(conf_get_changed());
1722}
1723
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724void fixup_rootmenu(struct menu *menu)
1725{
1726 struct menu *child;
1727 static int menu_cnt = 0;
1728
1729 menu->flags |= MENU_ROOT;
1730 for (child = menu->list; child; child = child->next) {
1731 if (child->prompt && child->prompt->type == P_MENU) {
1732 menu_cnt++;
1733 fixup_rootmenu(child);
1734 menu_cnt--;
1735 } else if (!menu_cnt)
1736 fixup_rootmenu(child);
1737 }
1738}
1739
1740static const char *progname;
1741
1742static void usage(void)
1743{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001744 printf(_("%s <config>\n"), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 exit(0);
1746}
1747
1748int main(int ac, char** av)
1749{
1750 ConfigMainWindow* v;
1751 const char *name;
1752
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001753 bindtextdomain(PACKAGE, LOCALEDIR);
1754 textdomain(PACKAGE);
1755
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 progname = av[0];
1757 configApp = new QApplication(ac, av);
1758 if (ac > 1 && av[1][0] == '-') {
1759 switch (av[1][1]) {
1760 case 'h':
1761 case '?':
1762 usage();
1763 }
1764 name = av[2];
1765 } else
1766 name = av[1];
1767 if (!name)
1768 usage();
1769
1770 conf_parse(name);
1771 fixup_rootmenu(&rootmenu);
1772 conf_read(NULL);
1773 //zconfdump(stdout);
1774
Roman Zippel7fc925f2006-06-08 22:12:46 -07001775 configSettings = new ConfigSettings();
1776 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 v = new ConfigMainWindow();
1778
1779 //zconfdump(stdout);
Roman Zippel43bf6122006-06-08 22:12:45 -07001780 configApp->setMainWidget(v);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1782 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001783 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 configApp->exec();
1785
Roman Zippel7fc925f2006-06-08 22:12:46 -07001786 configSettings->endGroup();
1787 delete configSettings;
1788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 return 0;
1790}