blob: 5e01af2f41ace45707fb678734f613a23cf6b977 [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
6#include <qapplication.h>
7#include <qmainwindow.h>
Markus Heidelberg8d90c972009-05-18 01:36:52 +02008#include <qdesktopwidget.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <qtoolbar.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070010#include <qlayout.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <qvbox.h>
12#include <qsplitter.h>
13#include <qlistview.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070014#include <qtextbrowser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <qlineedit.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070016#include <qlabel.h>
17#include <qpushbutton.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <qmenubar.h>
19#include <qmessagebox.h>
20#include <qaction.h>
21#include <qheader.h>
22#include <qfiledialog.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070023#include <qdragobject.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <qregexp.h>
25
26#include <stdlib.h>
27
28#include "lkc.h"
29#include "qconf.h"
30
31#include "qconf.moc"
32#include "images.c"
33
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070034#ifdef _
35# undef _
36# define _ qgettext
37#endif
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070040static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Karsten Wiese3b354c52006-12-13 00:34:08 -080042QAction *ConfigMainWindow::saveAction;
43
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070044static inline QString qgettext(const char* str)
45{
Roman Zippel43bf6122006-06-08 22:12:45 -070046 return QString::fromLocal8Bit(gettext(str));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070047}
48
49static inline QString qgettext(const QString& str)
50{
Roman Zippel43bf6122006-06-08 22:12:45 -070051 return QString::fromLocal8Bit(gettext(str.latin1()));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070052}
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/**
55 * Reads a list of integer values from the application settings.
56 */
57QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
58{
59 QValueList<int> result;
60 QStringList entryList = readListEntry(key, ok);
Li Zefanc1f96f02010-05-07 13:58:04 +080061 QStringList::Iterator it;
62
63 for (it = entryList.begin(); it != entryList.end(); ++it)
64 result.push_back((*it).toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 return result;
67}
68
69/**
70 * Writes a list of integer values to the application settings.
71 */
72bool ConfigSettings::writeSizes(const QString& key, const QValueList<int>& value)
73{
74 QStringList stringList;
75 QValueList<int>::ConstIterator it;
76
77 for (it = value.begin(); it != value.end(); ++it)
78 stringList.push_back(QString::number(*it));
79 return writeEntry(key, stringList);
80}
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#if QT_VERSION >= 300
84/*
85 * set the new data
86 * TODO check the value
87 */
88void ConfigItem::okRename(int col)
89{
90 Parent::okRename(col);
91 sym_set_string_value(menu->sym, text(dataColIdx).latin1());
Karsten Wiese49e56462007-02-14 00:32:57 -080092 listView()->updateList(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94#endif
95
96/*
97 * update the displayed of a menu entry
98 */
99void ConfigItem::updateMenu(void)
100{
101 ConfigList* list;
102 struct symbol* sym;
103 struct property *prop;
104 QString prompt;
105 int type;
106 tristate expr;
107
108 list = listView();
109 if (goParent) {
110 setPixmap(promptColIdx, list->menuBackPix);
111 prompt = "..";
112 goto set_prompt;
113 }
114
115 sym = menu->sym;
116 prop = menu->prompt;
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100117 prompt = _(menu_get_prompt(menu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 if (prop) switch (prop->type) {
120 case P_MENU:
121 if (list->mode == singleMode || list->mode == symbolMode) {
122 /* a menuconfig entry is displayed differently
123 * depending whether it's at the view root or a child.
124 */
125 if (sym && list->rootEntry == menu)
126 break;
127 setPixmap(promptColIdx, list->menuPix);
128 } else {
129 if (sym)
130 break;
131 setPixmap(promptColIdx, 0);
132 }
133 goto set_prompt;
134 case P_COMMENT:
135 setPixmap(promptColIdx, 0);
136 goto set_prompt;
137 default:
138 ;
139 }
140 if (!sym)
141 goto set_prompt;
142
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700143 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 type = sym_get_type(sym);
146 switch (type) {
147 case S_BOOLEAN:
148 case S_TRISTATE:
149 char ch;
150
151 if (!sym_is_changable(sym) && !list->showAll) {
152 setPixmap(promptColIdx, 0);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700153 setText(noColIdx, QString::null);
154 setText(modColIdx, QString::null);
155 setText(yesColIdx, QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 break;
157 }
158 expr = sym_get_tristate_value(sym);
159 switch (expr) {
160 case yes:
161 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
162 setPixmap(promptColIdx, list->choiceYesPix);
163 else
164 setPixmap(promptColIdx, list->symbolYesPix);
165 setText(yesColIdx, "Y");
166 ch = 'Y';
167 break;
168 case mod:
169 setPixmap(promptColIdx, list->symbolModPix);
170 setText(modColIdx, "M");
171 ch = 'M';
172 break;
173 default:
174 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
175 setPixmap(promptColIdx, list->choiceNoPix);
176 else
177 setPixmap(promptColIdx, list->symbolNoPix);
178 setText(noColIdx, "N");
179 ch = 'N';
180 break;
181 }
182 if (expr != no)
183 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
184 if (expr != mod)
185 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
186 if (expr != yes)
187 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
188
189 setText(dataColIdx, QChar(ch));
190 break;
191 case S_INT:
192 case S_HEX:
193 case S_STRING:
194 const char* data;
195
196 data = sym_get_string_value(sym);
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#if QT_VERSION >= 300
199 int i = list->mapIdx(dataColIdx);
200 if (i >= 0)
201 setRenameEnabled(i, TRUE);
202#endif
203 setText(dataColIdx, data);
204 if (type == S_STRING)
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700205 prompt = QString("%1: %2").arg(prompt).arg(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 else
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700207 prompt = QString("(%2) %1").arg(prompt).arg(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 break;
209 }
210 if (!sym_has_value(sym) && visible)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100211 prompt += _(" (NEW)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212set_prompt:
213 setText(promptColIdx, prompt);
214}
215
216void ConfigItem::testUpdateMenu(bool v)
217{
218 ConfigItem* i;
219
220 visible = v;
221 if (!menu)
222 return;
223
224 sym_calc_value(menu->sym);
225 if (menu->flags & MENU_CHANGED) {
226 /* the menu entry changed, so update all list items */
227 menu->flags &= ~MENU_CHANGED;
228 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
229 i->updateMenu();
230 } else if (listView()->updateAll)
231 updateMenu();
232}
233
234void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
235{
236 ConfigList* list = listView();
237
238 if (visible) {
239 if (isSelected() && !list->hasFocus() && list->mode == menuMode)
240 Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
241 else
242 Parent::paintCell(p, cg, column, width, align);
243 } else
244 Parent::paintCell(p, list->disabledColorGroup, column, width, align);
245}
246
247/*
248 * construct a menu entry
249 */
250void ConfigItem::init(void)
251{
252 if (menu) {
253 ConfigList* list = listView();
254 nextItem = (ConfigItem*)menu->data;
255 menu->data = this;
256
257 if (list->mode != fullMode)
258 setOpen(TRUE);
259 sym_calc_value(menu->sym);
260 }
261 updateMenu();
262}
263
264/*
265 * destruct a menu entry
266 */
267ConfigItem::~ConfigItem(void)
268{
269 if (menu) {
270 ConfigItem** ip = (ConfigItem**)&menu->data;
271 for (; *ip; ip = &(*ip)->nextItem) {
272 if (*ip == this) {
273 *ip = nextItem;
274 break;
275 }
276 }
277 }
278}
279
Roman Zippel43bf6122006-06-08 22:12:45 -0700280ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
281 : Parent(parent)
282{
283 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
284}
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286void ConfigLineEdit::show(ConfigItem* i)
287{
288 item = i;
289 if (sym_get_string_value(item->menu->sym))
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700290 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 else
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700292 setText(QString::null);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 Parent::show();
294 setFocus();
295}
296
297void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
298{
299 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200300 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200302 case Qt::Key_Return:
303 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 sym_set_string_value(item->menu->sym, text().latin1());
305 parent()->updateList(item);
306 break;
307 default:
308 Parent::keyPressEvent(e);
309 return;
310 }
311 e->accept();
312 parent()->list->setFocus();
313 hide();
314}
315
Roman Zippel7fc925f2006-06-08 22:12:46 -0700316ConfigList::ConfigList(ConfigView* p, const char *name)
317 : Parent(p, name),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 updateAll(false),
319 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
320 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
321 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
322 showAll(false), showName(false), showRange(false), showData(false),
Roman Zippel7fc925f2006-06-08 22:12:46 -0700323 rootEntry(0), headerPopup(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
325 int i;
326
327 setSorting(-1);
328 setRootIsDecorated(TRUE);
329 disabledColorGroup = palette().active();
330 disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
331 inactivedColorGroup = palette().active();
332 inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
333
334 connect(this, SIGNAL(selectionChanged(void)),
335 SLOT(updateSelection(void)));
336
Roman Zippel7fc925f2006-06-08 22:12:46 -0700337 if (name) {
338 configSettings->beginGroup(name);
339 showAll = configSettings->readBoolEntry("/showAll", false);
340 showName = configSettings->readBoolEntry("/showName", false);
341 showRange = configSettings->readBoolEntry("/showRange", false);
342 showData = configSettings->readBoolEntry("/showData", false);
343 configSettings->endGroup();
344 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346
347 for (i = 0; i < colNr; i++)
348 colMap[i] = colRevMap[i] = -1;
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100349 addColumn(promptColIdx, _("Option"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 reinit();
352}
353
354void ConfigList::reinit(void)
355{
356 removeColumn(dataColIdx);
357 removeColumn(yesColIdx);
358 removeColumn(modColIdx);
359 removeColumn(noColIdx);
360 removeColumn(nameColIdx);
361
362 if (showName)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100363 addColumn(nameColIdx, _("Name"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 if (showRange) {
365 addColumn(noColIdx, "N");
366 addColumn(modColIdx, "M");
367 addColumn(yesColIdx, "Y");
368 }
369 if (showData)
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100370 addColumn(dataColIdx, _("Value"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 updateListAll();
373}
374
Roman Zippel7fc925f2006-06-08 22:12:46 -0700375void ConfigList::saveSettings(void)
376{
377 if (name()) {
378 configSettings->beginGroup(name());
379 configSettings->writeEntry("/showName", showName);
380 configSettings->writeEntry("/showRange", showRange);
381 configSettings->writeEntry("/showData", showData);
382 configSettings->writeEntry("/showAll", showAll);
383 configSettings->endGroup();
384 }
385}
386
Roman Zippelb65a47e2006-06-08 22:12:47 -0700387ConfigItem* ConfigList::findConfigItem(struct menu *menu)
388{
389 ConfigItem* item = (ConfigItem*)menu->data;
390
391 for (; item; item = item->nextItem) {
392 if (this == item->listView())
393 break;
394 }
395
396 return item;
397}
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399void ConfigList::updateSelection(void)
400{
401 struct menu *menu;
402 enum prop_type type;
403
404 ConfigItem* item = (ConfigItem*)selectedItem();
405 if (!item)
406 return;
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 menu = item->menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700409 emit menuChanged(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (!menu)
411 return;
412 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
413 if (mode == menuMode && type == P_MENU)
414 emit menuSelected(menu);
415}
416
417void ConfigList::updateList(ConfigItem* item)
418{
419 ConfigItem* last = 0;
420
Roman Zippel43bf6122006-06-08 22:12:45 -0700421 if (!rootEntry) {
422 if (mode != listMode)
423 goto update;
424 QListViewItemIterator it(this);
425 ConfigItem* item;
426
427 for (; it.current(); ++it) {
428 item = (ConfigItem*)it.current();
429 if (!item->menu)
430 continue;
431 item->testUpdateMenu(menu_is_visible(item->menu));
432 }
433 return;
434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 if (rootEntry != &rootmenu && (mode == singleMode ||
437 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
438 item = firstChild();
439 if (!item)
440 item = new ConfigItem(this, 0, true);
441 last = item;
442 }
443 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
444 rootEntry->sym && rootEntry->prompt) {
445 item = last ? last->nextSibling() : firstChild();
446 if (!item)
447 item = new ConfigItem(this, last, rootEntry, true);
448 else
449 item->testUpdateMenu(true);
450
451 updateMenuList(item, rootEntry);
452 triggerUpdate();
453 return;
454 }
455update:
456 updateMenuList(this, rootEntry);
457 triggerUpdate();
458}
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460void ConfigList::setValue(ConfigItem* item, tristate val)
461{
462 struct symbol* sym;
463 int type;
464 tristate oldval;
465
466 sym = item->menu ? item->menu->sym : 0;
467 if (!sym)
468 return;
469
470 type = sym_get_type(sym);
471 switch (type) {
472 case S_BOOLEAN:
473 case S_TRISTATE:
474 oldval = sym_get_tristate_value(sym);
475
476 if (!sym_set_tristate_value(sym, val))
477 return;
478 if (oldval == no && item->menu->list)
479 item->setOpen(TRUE);
480 parent()->updateList(item);
481 break;
482 }
483}
484
485void ConfigList::changeValue(ConfigItem* item)
486{
487 struct symbol* sym;
488 struct menu* menu;
489 int type, oldexpr, newexpr;
490
491 menu = item->menu;
492 if (!menu)
493 return;
494 sym = menu->sym;
495 if (!sym) {
496 if (item->menu->list)
497 item->setOpen(!item->isOpen());
498 return;
499 }
500
501 type = sym_get_type(sym);
502 switch (type) {
503 case S_BOOLEAN:
504 case S_TRISTATE:
505 oldexpr = sym_get_tristate_value(sym);
506 newexpr = sym_toggle_tristate_value(sym);
507 if (item->menu->list) {
508 if (oldexpr == newexpr)
509 item->setOpen(!item->isOpen());
510 else if (oldexpr == no)
511 item->setOpen(TRUE);
512 }
513 if (oldexpr != newexpr)
514 parent()->updateList(item);
515 break;
516 case S_INT:
517 case S_HEX:
518 case S_STRING:
519#if QT_VERSION >= 300
520 if (colMap[dataColIdx] >= 0)
521 item->startRename(colMap[dataColIdx]);
522 else
523#endif
524 parent()->lineEdit->show(item);
525 break;
526 }
527}
528
529void ConfigList::setRootMenu(struct menu *menu)
530{
531 enum prop_type type;
532
533 if (rootEntry == menu)
534 return;
535 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
536 if (type != P_MENU)
537 return;
538 updateMenuList(this, 0);
539 rootEntry = menu;
540 updateListAll();
541 setSelected(currentItem(), hasFocus());
Roman Zippelb65a47e2006-06-08 22:12:47 -0700542 ensureItemVisible(currentItem());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
545void ConfigList::setParentMenu(void)
546{
547 ConfigItem* item;
548 struct menu *oldroot;
549
550 oldroot = rootEntry;
551 if (rootEntry == &rootmenu)
552 return;
553 setRootMenu(menu_get_parent_menu(rootEntry->parent));
554
555 QListViewItemIterator it(this);
556 for (; (item = (ConfigItem*)it.current()); it++) {
557 if (item->menu == oldroot) {
558 setCurrentItem(item);
559 ensureItemVisible(item);
560 break;
561 }
562 }
563}
564
Roman Zippel7fc925f2006-06-08 22:12:46 -0700565/*
566 * update all the children of a menu entry
567 * removes/adds the entries from the parent widget as necessary
568 *
569 * parent: either the menu list widget or a menu entry widget
570 * menu: entry to be updated
571 */
572template <class P>
573void ConfigList::updateMenuList(P* parent, struct menu* menu)
574{
575 struct menu* child;
576 ConfigItem* item;
577 ConfigItem* last;
578 bool visible;
579 enum prop_type type;
580
581 if (!menu) {
582 while ((item = parent->firstChild()))
583 delete item;
584 return;
585 }
586
587 last = parent->firstChild();
588 if (last && !last->goParent)
589 last = 0;
590 for (child = menu->list; child; child = child->next) {
591 item = last ? last->nextSibling() : parent->firstChild();
592 type = child->prompt ? child->prompt->type : P_UNKNOWN;
593
594 switch (mode) {
595 case menuMode:
596 if (!(child->flags & MENU_ROOT))
597 goto hide;
598 break;
599 case symbolMode:
600 if (child->flags & MENU_ROOT)
601 goto hide;
602 break;
603 default:
604 break;
605 }
606
607 visible = menu_is_visible(child);
608 if (showAll || visible) {
Cyrill V. Gorcunoved8b4d42007-02-14 00:33:03 -0800609 if (!child->sym && !child->list && !child->prompt)
610 continue;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700611 if (!item || item->menu != child)
612 item = new ConfigItem(parent, last, child, visible);
613 else
614 item->testUpdateMenu(visible);
615
616 if (mode == fullMode || mode == menuMode || type != P_MENU)
617 updateMenuList(item, child);
618 else
619 updateMenuList(item, 0);
620 last = item;
621 continue;
622 }
623 hide:
624 if (item && item->menu == child) {
625 last = parent->firstChild();
626 if (last == item)
627 last = 0;
628 else while (last->nextSibling() != item)
629 last = last->nextSibling();
630 delete item;
631 }
632 }
633}
634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635void ConfigList::keyPressEvent(QKeyEvent* ev)
636{
637 QListViewItem* i = currentItem();
638 ConfigItem* item;
639 struct menu *menu;
640 enum prop_type type;
641
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200642 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 emit parentSelected();
644 ev->accept();
645 return;
646 }
647
648 if (!i) {
649 Parent::keyPressEvent(ev);
650 return;
651 }
652 item = (ConfigItem*)i;
653
654 switch (ev->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200655 case Qt::Key_Return:
656 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 if (item->goParent) {
658 emit parentSelected();
659 break;
660 }
661 menu = item->menu;
662 if (!menu)
663 break;
664 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
665 if (type == P_MENU && rootEntry != menu &&
666 mode != fullMode && mode != menuMode) {
667 emit menuSelected(menu);
668 break;
669 }
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200670 case Qt::Key_Space:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 changeValue(item);
672 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200673 case Qt::Key_N:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 setValue(item, no);
675 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200676 case Qt::Key_M:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 setValue(item, mod);
678 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200679 case Qt::Key_Y:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 setValue(item, yes);
681 break;
682 default:
683 Parent::keyPressEvent(ev);
684 return;
685 }
686 ev->accept();
687}
688
689void ConfigList::contentsMousePressEvent(QMouseEvent* e)
690{
691 //QPoint p(contentsToViewport(e->pos()));
692 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
693 Parent::contentsMousePressEvent(e);
694}
695
696void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
697{
698 QPoint p(contentsToViewport(e->pos()));
699 ConfigItem* item = (ConfigItem*)itemAt(p);
700 struct menu *menu;
701 enum prop_type ptype;
702 const QPixmap* pm;
703 int idx, x;
704
705 if (!item)
706 goto skip;
707
708 menu = item->menu;
709 x = header()->offset() + p.x();
710 idx = colRevMap[header()->sectionAt(x)];
711 switch (idx) {
712 case promptColIdx:
713 pm = item->pixmap(promptColIdx);
714 if (pm) {
715 int off = header()->sectionPos(0) + itemMargin() +
716 treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
717 if (x >= off && x < off + pm->width()) {
718 if (item->goParent) {
719 emit parentSelected();
720 break;
721 } else if (!menu)
722 break;
723 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
724 if (ptype == P_MENU && rootEntry != menu &&
725 mode != fullMode && mode != menuMode)
726 emit menuSelected(menu);
727 else
728 changeValue(item);
729 }
730 }
731 break;
732 case noColIdx:
733 setValue(item, no);
734 break;
735 case modColIdx:
736 setValue(item, mod);
737 break;
738 case yesColIdx:
739 setValue(item, yes);
740 break;
741 case dataColIdx:
742 changeValue(item);
743 break;
744 }
745
746skip:
747 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
748 Parent::contentsMouseReleaseEvent(e);
749}
750
751void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
752{
753 //QPoint p(contentsToViewport(e->pos()));
754 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
755 Parent::contentsMouseMoveEvent(e);
756}
757
758void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
759{
760 QPoint p(contentsToViewport(e->pos()));
761 ConfigItem* item = (ConfigItem*)itemAt(p);
762 struct menu *menu;
763 enum prop_type ptype;
764
765 if (!item)
766 goto skip;
767 if (item->goParent) {
768 emit parentSelected();
769 goto skip;
770 }
771 menu = item->menu;
772 if (!menu)
773 goto skip;
774 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
775 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
776 emit menuSelected(menu);
777 else if (menu->sym)
778 changeValue(item);
779
780skip:
781 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
782 Parent::contentsMouseDoubleClickEvent(e);
783}
784
785void ConfigList::focusInEvent(QFocusEvent *e)
786{
Roman Zippelb65a47e2006-06-08 22:12:47 -0700787 struct menu *menu = NULL;
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 Parent::focusInEvent(e);
790
Roman Zippelb65a47e2006-06-08 22:12:47 -0700791 ConfigItem* item = (ConfigItem *)currentItem();
792 if (item) {
793 setSelected(item, TRUE);
794 menu = item->menu;
795 }
796 emit gotFocus(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
798
Roman Zippel7fc925f2006-06-08 22:12:46 -0700799void ConfigList::contextMenuEvent(QContextMenuEvent *e)
800{
801 if (e->y() <= header()->geometry().bottom()) {
802 if (!headerPopup) {
803 QAction *action;
804
805 headerPopup = new QPopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100806 action = new QAction(NULL, _("Show Name"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700807 action->setToggleAction(TRUE);
808 connect(action, SIGNAL(toggled(bool)),
809 parent(), SLOT(setShowName(bool)));
810 connect(parent(), SIGNAL(showNameChanged(bool)),
811 action, SLOT(setOn(bool)));
812 action->setOn(showName);
813 action->addTo(headerPopup);
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100814 action = new QAction(NULL, _("Show Range"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700815 action->setToggleAction(TRUE);
816 connect(action, SIGNAL(toggled(bool)),
817 parent(), SLOT(setShowRange(bool)));
818 connect(parent(), SIGNAL(showRangeChanged(bool)),
819 action, SLOT(setOn(bool)));
820 action->setOn(showRange);
821 action->addTo(headerPopup);
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100822 action = new QAction(NULL, _("Show Data"), 0, this);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700823 action->setToggleAction(TRUE);
824 connect(action, SIGNAL(toggled(bool)),
825 parent(), SLOT(setShowData(bool)));
826 connect(parent(), SIGNAL(showDataChanged(bool)),
827 action, SLOT(setOn(bool)));
828 action->setOn(showData);
829 action->addTo(headerPopup);
830 }
831 headerPopup->exec(e->globalPos());
832 e->accept();
833 } else
834 e->ignore();
835}
836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837ConfigView* ConfigView::viewList;
838
Roman Zippel7fc925f2006-06-08 22:12:46 -0700839ConfigView::ConfigView(QWidget* parent, const char *name)
840 : Parent(parent, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700842 list = new ConfigList(this, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 lineEdit = new ConfigLineEdit(this);
844 lineEdit->hide();
845
846 this->nextView = viewList;
847 viewList = this;
848}
849
850ConfigView::~ConfigView(void)
851{
852 ConfigView** vp;
853
854 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
855 if (*vp == this) {
856 *vp = nextView;
857 break;
858 }
859 }
860}
861
Roman Zippel7fc925f2006-06-08 22:12:46 -0700862void ConfigView::setShowAll(bool b)
863{
864 if (list->showAll != b) {
865 list->showAll = b;
866 list->updateListAll();
867 emit showAllChanged(b);
868 }
869}
870
871void ConfigView::setShowName(bool b)
872{
873 if (list->showName != b) {
874 list->showName = b;
875 list->reinit();
876 emit showNameChanged(b);
877 }
878}
879
880void ConfigView::setShowRange(bool b)
881{
882 if (list->showRange != b) {
883 list->showRange = b;
884 list->reinit();
885 emit showRangeChanged(b);
886 }
887}
888
889void ConfigView::setShowData(bool b)
890{
891 if (list->showData != b) {
892 list->showData = b;
893 list->reinit();
894 emit showDataChanged(b);
895 }
896}
897
898void ConfigList::setAllOpen(bool open)
899{
900 QListViewItemIterator it(this);
901
902 for (; it.current(); it++)
903 it.current()->setOpen(open);
904}
905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906void ConfigView::updateList(ConfigItem* item)
907{
908 ConfigView* v;
909
910 for (v = viewList; v; v = v->nextView)
911 v->list->updateList(item);
912}
913
914void ConfigView::updateListAll(void)
915{
916 ConfigView* v;
917
918 for (v = viewList; v; v = v->nextView)
919 v->list->updateListAll();
920}
921
Roman Zippel43bf6122006-06-08 22:12:45 -0700922ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Markus Heidelberg98403a92009-05-18 01:36:49 +0200923 : Parent(parent, name), sym(0), menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700924{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700925 if (name) {
926 configSettings->beginGroup(name);
927 _showDebug = configSettings->readBoolEntry("/showDebug", false);
928 configSettings->endGroup();
929 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
930 }
931}
932
933void ConfigInfoView::saveSettings(void)
934{
935 if (name()) {
936 configSettings->beginGroup(name());
937 configSettings->writeEntry("/showDebug", showDebug());
938 configSettings->endGroup();
939 }
Roman Zippel43bf6122006-06-08 22:12:45 -0700940}
941
942void ConfigInfoView::setShowDebug(bool b)
943{
944 if (_showDebug != b) {
945 _showDebug = b;
946 if (menu)
947 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -0700948 else if (sym)
949 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -0700950 emit showDebugChanged(b);
951 }
952}
953
954void ConfigInfoView::setInfo(struct menu *m)
955{
Roman Zippelb65a47e2006-06-08 22:12:47 -0700956 if (menu == m)
957 return;
Roman Zippel43bf6122006-06-08 22:12:45 -0700958 menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -0800959 sym = NULL;
960 if (!menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700961 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -0800962 else
Roman Zippel43bf6122006-06-08 22:12:45 -0700963 menuInfo();
964}
965
Roman Zippelab45d192006-06-08 22:12:47 -0700966void ConfigInfoView::symbolInfo(void)
967{
968 QString str;
969
970 str += "<big>Symbol: <b>";
971 str += print_filter(sym->name);
972 str += "</b></big><br><br>value: ";
973 str += print_filter(sym_get_string_value(sym));
974 str += "<br>visibility: ";
975 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
976 str += "<br>";
977 str += debug_info(sym);
978
979 setText(str);
980}
981
Roman Zippel43bf6122006-06-08 22:12:45 -0700982void ConfigInfoView::menuInfo(void)
983{
984 struct symbol* sym;
985 QString head, debug, help;
986
987 sym = menu->sym;
988 if (sym) {
989 if (menu->prompt) {
990 head += "<big><b>";
991 head += print_filter(_(menu->prompt->text));
992 head += "</b></big>";
993 if (sym->name) {
994 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -0700995 if (showDebug())
996 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -0700997 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -0700998 if (showDebug())
999 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001000 head += ")";
1001 }
1002 } else if (sym->name) {
1003 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -07001004 if (showDebug())
1005 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -07001006 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -07001007 if (showDebug())
1008 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001009 head += "</b></big>";
1010 }
1011 head += "<br><br>";
1012
1013 if (showDebug())
1014 debug = debug_info(sym);
1015
Cheng Renquand74c15f2009-07-12 16:11:47 +08001016 struct gstr help_gstr = str_new();
1017 menu_get_ext_help(menu, &help_gstr);
1018 help = print_filter(str_get(&help_gstr));
1019 str_free(&help_gstr);
Roman Zippel43bf6122006-06-08 22:12:45 -07001020 } else if (menu->prompt) {
1021 head += "<big><b>";
1022 head += print_filter(_(menu->prompt->text));
1023 head += "</b></big><br><br>";
1024 if (showDebug()) {
1025 if (menu->prompt->visible.expr) {
1026 debug += "&nbsp;&nbsp;dep: ";
1027 expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
1028 debug += "<br><br>";
1029 }
1030 }
1031 }
1032 if (showDebug())
1033 debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno);
1034
1035 setText(head + debug + help);
1036}
1037
1038QString ConfigInfoView::debug_info(struct symbol *sym)
1039{
1040 QString debug;
1041
1042 debug += "type: ";
1043 debug += print_filter(sym_type_name(sym->type));
1044 if (sym_is_choice(sym))
1045 debug += " (choice)";
1046 debug += "<br>";
1047 if (sym->rev_dep.expr) {
1048 debug += "reverse dep: ";
1049 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1050 debug += "<br>";
1051 }
1052 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1053 switch (prop->type) {
1054 case P_PROMPT:
1055 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -07001056 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Roman Zippel43bf6122006-06-08 22:12:45 -07001057 debug += print_filter(_(prop->text));
Roman Zippelab45d192006-06-08 22:12:47 -07001058 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -07001059 break;
1060 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +01001061 case P_SELECT:
1062 case P_RANGE:
1063 case P_ENV:
1064 debug += prop_get_type_name(prop->type);
1065 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -07001066 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1067 debug += "<br>";
1068 break;
1069 case P_CHOICE:
1070 if (sym_is_choice(sym)) {
1071 debug += "choice: ";
1072 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1073 debug += "<br>";
1074 }
1075 break;
Roman Zippel43bf6122006-06-08 22:12:45 -07001076 default:
1077 debug += "unknown property: ";
1078 debug += prop_get_type_name(prop->type);
1079 debug += "<br>";
1080 }
1081 if (prop->visible.expr) {
1082 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1083 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1084 debug += "<br>";
1085 }
1086 }
1087 debug += "<br>";
1088
1089 return debug;
1090}
1091
1092QString ConfigInfoView::print_filter(const QString &str)
1093{
1094 QRegExp re("[<>&\"\\n]");
1095 QString res = str;
1096 for (int i = 0; (i = res.find(re, i)) >= 0;) {
1097 switch (res[i].latin1()) {
1098 case '<':
1099 res.replace(i, 1, "&lt;");
1100 i += 4;
1101 break;
1102 case '>':
1103 res.replace(i, 1, "&gt;");
1104 i += 4;
1105 break;
1106 case '&':
1107 res.replace(i, 1, "&amp;");
1108 i += 5;
1109 break;
1110 case '"':
1111 res.replace(i, 1, "&quot;");
1112 i += 6;
1113 break;
1114 case '\n':
1115 res.replace(i, 1, "<br>");
1116 i += 4;
1117 break;
1118 }
1119 }
1120 return res;
1121}
1122
Roman Zippelab45d192006-06-08 22:12:47 -07001123void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -07001124{
Roman Zippelab45d192006-06-08 22:12:47 -07001125 QString* text = reinterpret_cast<QString*>(data);
1126 QString str2 = print_filter(str);
1127
1128 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1129 *text += QString().sprintf("<a href=\"s%p\">", sym);
1130 *text += str2;
1131 *text += "</a>";
1132 } else
1133 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -07001134}
1135
Roman Zippel7fc925f2006-06-08 22:12:46 -07001136QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
1137{
1138 QPopupMenu* popup = Parent::createPopupMenu(pos);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001139 QAction* action = new QAction(NULL, _("Show Debug Info"), 0, popup);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001140 action->setToggleAction(TRUE);
1141 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1142 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
1143 action->setOn(showDebug());
1144 popup->insertSeparator();
1145 action->addTo(popup);
1146 return popup;
1147}
1148
1149void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
1150{
1151 Parent::contentsContextMenuEvent(e);
1152}
1153
Marco Costalba63431e72006-10-05 19:12:59 +02001154ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001155 : Parent(parent, name), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -07001156{
1157 setCaption("Search Config");
1158
1159 QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
1160 QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001161 layout2->addWidget(new QLabel(_("Find:"), this));
Roman Zippel43bf6122006-06-08 22:12:45 -07001162 editField = new QLineEdit(this);
1163 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1164 layout2->addWidget(editField);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001165 searchButton = new QPushButton(_("Search"), this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001166 searchButton->setAutoDefault(FALSE);
1167 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1168 layout2->addWidget(searchButton);
1169 layout1->addLayout(layout2);
1170
Roman Zippel7fc925f2006-06-08 22:12:46 -07001171 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001172 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001173 list = new ConfigView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001174 list->list->mode = listMode;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001175 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -07001176 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1177 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +02001178 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1179 parent, SLOT(setMenuLink(struct menu *)));
1180
Roman Zippel43bf6122006-06-08 22:12:45 -07001181 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001182
1183 if (name) {
1184 int x, y, width, height;
1185 bool ok;
1186
1187 configSettings->beginGroup(name);
1188 width = configSettings->readNumEntry("/window width", parent->width() / 2);
1189 height = configSettings->readNumEntry("/window height", parent->height() / 2);
1190 resize(width, height);
1191 x = configSettings->readNumEntry("/window x", 0, &ok);
1192 if (ok)
1193 y = configSettings->readNumEntry("/window y", 0, &ok);
1194 if (ok)
1195 move(x, y);
1196 QValueList<int> sizes = configSettings->readSizes("/split", &ok);
1197 if (ok)
1198 split->setSizes(sizes);
1199 configSettings->endGroup();
1200 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1201 }
1202}
1203
1204void ConfigSearchWindow::saveSettings(void)
1205{
1206 if (name()) {
1207 configSettings->beginGroup(name());
1208 configSettings->writeEntry("/window x", pos().x());
1209 configSettings->writeEntry("/window y", pos().y());
1210 configSettings->writeEntry("/window width", size().width());
1211 configSettings->writeEntry("/window height", size().height());
1212 configSettings->writeSizes("/split", split->sizes());
1213 configSettings->endGroup();
1214 }
Roman Zippel43bf6122006-06-08 22:12:45 -07001215}
1216
1217void ConfigSearchWindow::search(void)
1218{
1219 struct symbol **p;
1220 struct property *prop;
1221 ConfigItem *lastItem = NULL;
1222
1223 free(result);
1224 list->list->clear();
Cyrill V. Gorcunov786fb182007-02-14 00:32:59 -08001225 info->clear();
Roman Zippel43bf6122006-06-08 22:12:45 -07001226
1227 result = sym_re_search(editField->text().latin1());
1228 if (!result)
1229 return;
1230 for (p = result; *p; p++) {
1231 for_all_prompts((*p), prop)
1232 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1233 menu_is_visible(prop->menu));
1234 }
1235}
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237/*
1238 * Construct the complete config widget
1239 */
1240ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -08001241 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242{
1243 QMenuBar* menu;
Roman Zippel7fc925f2006-06-08 22:12:46 -07001244 bool ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 int x, y, width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -07001246 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Markus Heidelberg8d90c972009-05-18 01:36:52 +02001248 QDesktopWidget *d = configApp->desktop();
Randy Dunlapa54bb702007-10-20 11:18:47 -07001249 snprintf(title, sizeof(title), _("Linux Kernel v%s Configuration"),
1250 getenv("KERNELVERSION"));
1251 setCaption(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Roman Zippel7fc925f2006-06-08 22:12:46 -07001253 width = configSettings->readNumEntry("/window width", d->width() - 64);
1254 height = configSettings->readNumEntry("/window height", d->height() - 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 resize(width, height);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001256 x = configSettings->readNumEntry("/window x", 0, &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (ok)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001258 y = configSettings->readNumEntry("/window y", 0, &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 if (ok)
1260 move(x, y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001263 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 setCentralWidget(split1);
1265
Roman Zippel7fc925f2006-06-08 22:12:46 -07001266 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 menuList = menuView->list;
1268
1269 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +02001270 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -07001273 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 configList = configView->list;
1275
Roman Zippel7fc925f2006-06-08 22:12:46 -07001276 helpText = new ConfigInfoView(split2, "help");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 helpText->setTextFormat(Qt::RichText);
1278
1279 setTabOrder(configList, helpText);
1280 configList->setFocus();
1281
1282 menu = menuBar();
1283 toolBar = new QToolBar("Tools", this);
1284
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001285 backAction = new QAction("Back", QPixmap(xpm_back), _("Back"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 connect(backAction, SIGNAL(activated()), SLOT(goBack()));
1287 backAction->setEnabled(FALSE);
Markus Heidelbergfbb86372009-05-18 01:36:51 +02001288 QAction *quitAction = new QAction("Quit", _("&Quit"), Qt::CTRL + Qt::Key_Q, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 connect(quitAction, SIGNAL(activated()), SLOT(close()));
Markus Heidelbergfbb86372009-05-18 01:36:51 +02001290 QAction *loadAction = new QAction("Load", QPixmap(xpm_load), _("&Load"), Qt::CTRL + Qt::Key_L, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
Markus Heidelbergfbb86372009-05-18 01:36:51 +02001292 saveAction = new QAction("Save", QPixmap(xpm_save), _("&Save"), Qt::CTRL + Qt::Key_S, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -08001294 conf_set_changed_callback(conf_changed);
1295 // Set saveAction's initial state
1296 conf_changed();
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001297 QAction *saveAsAction = new QAction("Save As...", _("Save &As..."), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
Markus Heidelbergfbb86372009-05-18 01:36:51 +02001299 QAction *searchAction = new QAction("Find", _("&Find"), Qt::CTRL + Qt::Key_F, this);
Roman Zippel43bf6122006-06-08 22:12:45 -07001300 connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001301 QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), _("Single View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001303 QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), _("Split View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001305 QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), _("Full View"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
1307
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001308 QAction *showNameAction = new QAction(NULL, _("Show Name"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 showNameAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001310 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
1311 connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
1312 showNameAction->setOn(configView->showName());
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001313 QAction *showRangeAction = new QAction(NULL, _("Show Range"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 showRangeAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001315 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
1316 connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 showRangeAction->setOn(configList->showRange);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001318 QAction *showDataAction = new QAction(NULL, _("Show Data"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 showDataAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001320 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
1321 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 showDataAction->setOn(configList->showData);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001323 QAction *showAllAction = new QAction(NULL, _("Show All Options"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 showAllAction->setToggleAction(TRUE);
Roman Zippel7fc925f2006-06-08 22:12:46 -07001325 connect(showAllAction, SIGNAL(toggled(bool)), configView, SLOT(setShowAll(bool)));
1326 connect(showAllAction, SIGNAL(toggled(bool)), menuView, SLOT(setShowAll(bool)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 showAllAction->setOn(configList->showAll);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001328 QAction *showDebugAction = new QAction(NULL, _("Show Debug Info"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 showDebugAction->setToggleAction(TRUE);
Roman Zippel43bf6122006-06-08 22:12:45 -07001330 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
1331 connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
Roman Zippel7fc925f2006-06-08 22:12:46 -07001332 showDebugAction->setOn(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001334 QAction *showIntroAction = new QAction(NULL, _("Introduction"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001336 QAction *showAboutAction = new QAction(NULL, _("About"), 0, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
1338
1339 // init tool bar
1340 backAction->addTo(toolBar);
1341 toolBar->addSeparator();
1342 loadAction->addTo(toolBar);
1343 saveAction->addTo(toolBar);
1344 toolBar->addSeparator();
1345 singleViewAction->addTo(toolBar);
1346 splitViewAction->addTo(toolBar);
1347 fullViewAction->addTo(toolBar);
1348
1349 // create config menu
1350 QPopupMenu* config = new QPopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001351 menu->insertItem(_("&File"), config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 loadAction->addTo(config);
1353 saveAction->addTo(config);
1354 saveAsAction->addTo(config);
1355 config->insertSeparator();
1356 quitAction->addTo(config);
1357
Shlomi Fish66e7c722007-02-14 00:32:58 -08001358 // create edit menu
1359 QPopupMenu* editMenu = new QPopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001360 menu->insertItem(_("&Edit"), editMenu);
Shlomi Fish66e7c722007-02-14 00:32:58 -08001361 searchAction->addTo(editMenu);
1362
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 // create options menu
1364 QPopupMenu* optionMenu = new QPopupMenu(this);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001365 menu->insertItem(_("&Option"), optionMenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 showNameAction->addTo(optionMenu);
1367 showRangeAction->addTo(optionMenu);
1368 showDataAction->addTo(optionMenu);
1369 optionMenu->insertSeparator();
1370 showAllAction->addTo(optionMenu);
1371 showDebugAction->addTo(optionMenu);
1372
1373 // create help menu
1374 QPopupMenu* helpMenu = new QPopupMenu(this);
1375 menu->insertSeparator();
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001376 menu->insertItem(_("&Help"), helpMenu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 showIntroAction->addTo(helpMenu);
1378 showAboutAction->addTo(helpMenu);
1379
Roman Zippel43bf6122006-06-08 22:12:45 -07001380 connect(configList, SIGNAL(menuChanged(struct menu *)),
1381 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 connect(configList, SIGNAL(menuSelected(struct menu *)),
1383 SLOT(changeMenu(struct menu *)));
1384 connect(configList, SIGNAL(parentSelected()),
1385 SLOT(goBack()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001386 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1387 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1389 SLOT(changeMenu(struct menu *)));
1390
Roman Zippelb65a47e2006-06-08 22:12:47 -07001391 connect(configList, SIGNAL(gotFocus(struct menu *)),
1392 helpText, SLOT(setInfo(struct menu *)));
1393 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1394 helpText, SLOT(setInfo(struct menu *)));
1395 connect(menuList, SIGNAL(gotFocus(struct menu *)),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -07001397 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1398 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Roman Zippel7fc925f2006-06-08 22:12:46 -07001400 QString listMode = configSettings->readEntry("/listMode", "symbol");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 if (listMode == "single")
1402 showSingleView();
1403 else if (listMode == "full")
1404 showFullView();
1405 else /*if (listMode == "split")*/
1406 showSplitView();
1407
1408 // UI setup done, restore splitter positions
Roman Zippel7fc925f2006-06-08 22:12:46 -07001409 QValueList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 if (ok)
1411 split1->setSizes(sizes);
1412
Roman Zippel7fc925f2006-06-08 22:12:46 -07001413 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 if (ok)
1415 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418void ConfigMainWindow::loadConfig(void)
1419{
Markus Heidelberg284026c2009-05-18 01:36:53 +02001420 QString s = QFileDialog::getOpenFileName(conf_get_configname(), NULL, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 if (s.isNull())
1422 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001423 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001424 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 ConfigView::updateListAll();
1426}
1427
1428void ConfigMainWindow::saveConfig(void)
1429{
1430 if (conf_write(NULL))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001431 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432}
1433
1434void ConfigMainWindow::saveConfigAs(void)
1435{
Markus Heidelberg284026c2009-05-18 01:36:53 +02001436 QString s = QFileDialog::getSaveFileName(conf_get_configname(), NULL, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 if (s.isNull())
1438 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001439 if (conf_write(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001440 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
1442
Roman Zippel43bf6122006-06-08 22:12:45 -07001443void ConfigMainWindow::searchConfig(void)
1444{
1445 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -07001446 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -07001447 searchWindow->show();
1448}
1449
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450void ConfigMainWindow::changeMenu(struct menu *menu)
1451{
1452 configList->setRootMenu(menu);
Cyrill V. Gorcunovf253f002007-02-14 00:33:00 -08001453 if (configList->rootEntry->parent == &rootmenu)
1454 backAction->setEnabled(FALSE);
1455 else
1456 backAction->setEnabled(TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
Roman Zippelb65a47e2006-06-08 22:12:47 -07001459void ConfigMainWindow::setMenuLink(struct menu *menu)
1460{
1461 struct menu *parent;
1462 ConfigList* list = NULL;
1463 ConfigItem* item;
1464
1465 if (!menu_is_visible(menu) && !configView->showAll())
1466 return;
1467
1468 switch (configList->mode) {
1469 case singleMode:
1470 list = configList;
1471 parent = menu_get_parent_menu(menu);
1472 if (!parent)
1473 return;
1474 list->setRootMenu(parent);
1475 break;
1476 case symbolMode:
1477 if (menu->flags & MENU_ROOT) {
1478 configList->setRootMenu(menu);
1479 configList->clearSelection();
1480 list = menuList;
1481 } else {
1482 list = configList;
1483 parent = menu_get_parent_menu(menu->parent);
1484 if (!parent)
1485 return;
1486 item = menuList->findConfigItem(parent);
1487 if (item) {
1488 menuList->setSelected(item, TRUE);
1489 menuList->ensureItemVisible(item);
1490 }
1491 list->setRootMenu(parent);
1492 }
1493 break;
1494 case fullMode:
1495 list = configList;
1496 break;
Markus Heidelberg98403a92009-05-18 01:36:49 +02001497 default:
1498 break;
Roman Zippelb65a47e2006-06-08 22:12:47 -07001499 }
1500
1501 if (list) {
1502 item = list->findConfigItem(menu);
1503 if (item) {
1504 list->setSelected(item, TRUE);
1505 list->ensureItemVisible(item);
1506 list->setFocus();
1507 }
1508 }
1509}
1510
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511void ConfigMainWindow::listFocusChanged(void)
1512{
Roman Zippelb65a47e2006-06-08 22:12:47 -07001513 if (menuList->mode == menuMode)
1514 configList->clearSelection();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
1517void ConfigMainWindow::goBack(void)
1518{
1519 ConfigItem* item;
1520
1521 configList->setParentMenu();
1522 if (configList->rootEntry == &rootmenu)
1523 backAction->setEnabled(FALSE);
1524 item = (ConfigItem*)menuList->selectedItem();
1525 while (item) {
1526 if (item->menu == configList->rootEntry) {
1527 menuList->setSelected(item, TRUE);
1528 break;
1529 }
1530 item = (ConfigItem*)item->parent();
1531 }
1532}
1533
1534void ConfigMainWindow::showSingleView(void)
1535{
1536 menuView->hide();
1537 menuList->setRootMenu(0);
1538 configList->mode = singleMode;
1539 if (configList->rootEntry == &rootmenu)
1540 configList->updateListAll();
1541 else
1542 configList->setRootMenu(&rootmenu);
1543 configList->setAllOpen(TRUE);
1544 configList->setFocus();
1545}
1546
1547void ConfigMainWindow::showSplitView(void)
1548{
1549 configList->mode = symbolMode;
1550 if (configList->rootEntry == &rootmenu)
1551 configList->updateListAll();
1552 else
1553 configList->setRootMenu(&rootmenu);
1554 configList->setAllOpen(TRUE);
1555 configApp->processEvents();
1556 menuList->mode = menuMode;
1557 menuList->setRootMenu(&rootmenu);
1558 menuList->setAllOpen(TRUE);
1559 menuView->show();
1560 menuList->setFocus();
1561}
1562
1563void ConfigMainWindow::showFullView(void)
1564{
1565 menuView->hide();
1566 menuList->setRootMenu(0);
1567 configList->mode = fullMode;
1568 if (configList->rootEntry == &rootmenu)
1569 configList->updateListAll();
1570 else
1571 configList->setRootMenu(&rootmenu);
1572 configList->setAllOpen(FALSE);
1573 configList->setFocus();
1574}
1575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576/*
1577 * ask for saving configuration before quitting
1578 * TODO ask only when something changed
1579 */
1580void ConfigMainWindow::closeEvent(QCloseEvent* e)
1581{
Karsten Wieseb3214292006-12-13 00:34:06 -08001582 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 e->accept();
1584 return;
1585 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001586 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001588 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1589 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1590 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 switch (mb.exec()) {
1592 case QMessageBox::Yes:
1593 conf_write(NULL);
1594 case QMessageBox::No:
1595 e->accept();
1596 break;
1597 case QMessageBox::Cancel:
1598 e->ignore();
1599 break;
1600 }
1601}
1602
1603void ConfigMainWindow::showIntro(void)
1604{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001605 static const QString str = _("Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 "For each option, a blank box indicates the feature is disabled, a check\n"
1607 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1608 "as a module. Clicking on the box will cycle through the three states.\n\n"
1609 "If you do not see an option (e.g., a device driver) that you believe\n"
1610 "should be present, try turning on Show All Options under the Options menu.\n"
1611 "Although there is no cross reference yet to help you figure out what other\n"
1612 "options must be enabled to support the option you are interested in, you can\n"
1613 "still view the help of a grayed-out option.\n\n"
1614 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001615 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
1617 QMessageBox::information(this, "qconf", str);
1618}
1619
1620void ConfigMainWindow::showAbout(void)
1621{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001622 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1623 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625 QMessageBox::information(this, "qconf", str);
1626}
1627
1628void ConfigMainWindow::saveSettings(void)
1629{
Roman Zippel7fc925f2006-06-08 22:12:46 -07001630 configSettings->writeEntry("/window x", pos().x());
1631 configSettings->writeEntry("/window y", pos().y());
1632 configSettings->writeEntry("/window width", size().width());
1633 configSettings->writeEntry("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
1635 QString entry;
1636 switch(configList->mode) {
1637 case singleMode :
1638 entry = "single";
1639 break;
1640
1641 case symbolMode :
1642 entry = "split";
1643 break;
1644
1645 case fullMode :
1646 entry = "full";
1647 break;
Markus Heidelberg98403a92009-05-18 01:36:49 +02001648
1649 default:
1650 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 }
Roman Zippel7fc925f2006-06-08 22:12:46 -07001652 configSettings->writeEntry("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Roman Zippel7fc925f2006-06-08 22:12:46 -07001654 configSettings->writeSizes("/split1", split1->sizes());
1655 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Karsten Wiese3b354c52006-12-13 00:34:08 -08001658void ConfigMainWindow::conf_changed(void)
1659{
1660 if (saveAction)
1661 saveAction->setEnabled(conf_get_changed());
1662}
1663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664void fixup_rootmenu(struct menu *menu)
1665{
1666 struct menu *child;
1667 static int menu_cnt = 0;
1668
1669 menu->flags |= MENU_ROOT;
1670 for (child = menu->list; child; child = child->next) {
1671 if (child->prompt && child->prompt->type == P_MENU) {
1672 menu_cnt++;
1673 fixup_rootmenu(child);
1674 menu_cnt--;
1675 } else if (!menu_cnt)
1676 fixup_rootmenu(child);
1677 }
1678}
1679
1680static const char *progname;
1681
1682static void usage(void)
1683{
EGRY Gaborc21a2d92008-01-11 23:52:07 +01001684 printf(_("%s <config>\n"), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 exit(0);
1686}
1687
1688int main(int ac, char** av)
1689{
1690 ConfigMainWindow* v;
1691 const char *name;
1692
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -07001693 bindtextdomain(PACKAGE, LOCALEDIR);
1694 textdomain(PACKAGE);
1695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696#ifndef LKC_DIRECT_LINK
1697 kconfig_load();
1698#endif
1699
1700 progname = av[0];
1701 configApp = new QApplication(ac, av);
1702 if (ac > 1 && av[1][0] == '-') {
1703 switch (av[1][1]) {
1704 case 'h':
1705 case '?':
1706 usage();
1707 }
1708 name = av[2];
1709 } else
1710 name = av[1];
1711 if (!name)
1712 usage();
1713
1714 conf_parse(name);
1715 fixup_rootmenu(&rootmenu);
1716 conf_read(NULL);
1717 //zconfdump(stdout);
1718
Roman Zippel7fc925f2006-06-08 22:12:46 -07001719 configSettings = new ConfigSettings();
1720 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 v = new ConfigMainWindow();
1722
1723 //zconfdump(stdout);
Roman Zippel43bf6122006-06-08 22:12:45 -07001724 configApp->setMainWidget(v);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1726 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -07001727 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 configApp->exec();
1729
Roman Zippel7fc925f2006-06-08 22:12:46 -07001730 configSettings->endGroup();
1731 delete configSettings;
1732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 return 0;
1734}