[PATCH] qconf: relocate Search Command
[linux-2.6/verdex.git] / scripts / kconfig / qconf.cc
blob83a270347c258d95b0cd35c55ea4a37f04c8d2b3
1 /*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
6 #include <qapplication.h>
7 #include <qmainwindow.h>
8 #include <qtoolbar.h>
9 #include <qlayout.h>
10 #include <qvbox.h>
11 #include <qsplitter.h>
12 #include <qlistview.h>
13 #include <qtextbrowser.h>
14 #include <qlineedit.h>
15 #include <qlabel.h>
16 #include <qpushbutton.h>
17 #include <qmenubar.h>
18 #include <qmessagebox.h>
19 #include <qaction.h>
20 #include <qheader.h>
21 #include <qfiledialog.h>
22 #include <qdragobject.h>
23 #include <qregexp.h>
25 #include <stdlib.h>
27 #include "lkc.h"
28 #include "qconf.h"
30 #include "qconf.moc"
31 #include "images.c"
33 #ifdef _
34 # undef _
35 # define _ qgettext
36 #endif
38 static QApplication *configApp;
39 static ConfigSettings *configSettings;
41 QAction *ConfigMainWindow::saveAction;
43 static inline QString qgettext(const char* str)
45 return QString::fromLocal8Bit(gettext(str));
48 static inline QString qgettext(const QString& str)
50 return QString::fromLocal8Bit(gettext(str.latin1()));
53 /**
54 * Reads a list of integer values from the application settings.
56 QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
58 QValueList<int> result;
59 QStringList entryList = readListEntry(key, ok);
60 if (ok) {
61 QStringList::Iterator it;
62 for (it = entryList.begin(); it != entryList.end(); ++it)
63 result.push_back((*it).toInt());
66 return result;
69 /**
70 * Writes a list of integer values to the application settings.
72 bool ConfigSettings::writeSizes(const QString& key, const QValueList<int>& value)
74 QStringList stringList;
75 QValueList<int>::ConstIterator it;
77 for (it = value.begin(); it != value.end(); ++it)
78 stringList.push_back(QString::number(*it));
79 return writeEntry(key, stringList);
83 #if QT_VERSION >= 300
85 * set the new data
86 * TODO check the value
88 void ConfigItem::okRename(int col)
90 Parent::okRename(col);
91 sym_set_string_value(menu->sym, text(dataColIdx).latin1());
92 listView()->updateList(this);
94 #endif
97 * update the displayed of a menu entry
99 void ConfigItem::updateMenu(void)
101 ConfigList* list;
102 struct symbol* sym;
103 struct property *prop;
104 QString prompt;
105 int type;
106 tristate expr;
108 list = listView();
109 if (goParent) {
110 setPixmap(promptColIdx, list->menuBackPix);
111 prompt = "..";
112 goto set_prompt;
115 sym = menu->sym;
116 prop = menu->prompt;
117 prompt = QString::fromLocal8Bit(menu_get_prompt(menu));
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.
125 if (sym && list->rootEntry == menu)
126 break;
127 setPixmap(promptColIdx, list->menuPix);
128 } else {
129 if (sym)
130 break;
131 setPixmap(promptColIdx, 0);
133 goto set_prompt;
134 case P_COMMENT:
135 setPixmap(promptColIdx, 0);
136 goto set_prompt;
137 default:
140 if (!sym)
141 goto set_prompt;
143 setText(nameColIdx, QString::fromLocal8Bit(sym->name));
145 type = sym_get_type(sym);
146 switch (type) {
147 case S_BOOLEAN:
148 case S_TRISTATE:
149 char ch;
151 if (!sym_is_changable(sym) && !list->showAll) {
152 setPixmap(promptColIdx, 0);
153 setText(noColIdx, QString::null);
154 setText(modColIdx, QString::null);
155 setText(yesColIdx, QString::null);
156 break;
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;
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);
189 setText(dataColIdx, QChar(ch));
190 break;
191 case S_INT:
192 case S_HEX:
193 case S_STRING:
194 const char* data;
196 data = sym_get_string_value(sym);
198 #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)
205 prompt = QString("%1: %2").arg(prompt).arg(data);
206 else
207 prompt = QString("(%2) %1").arg(prompt).arg(data);
208 break;
210 if (!sym_has_value(sym) && visible)
211 prompt += " (NEW)";
212 set_prompt:
213 setText(promptColIdx, prompt);
216 void ConfigItem::testUpdateMenu(bool v)
218 ConfigItem* i;
220 visible = v;
221 if (!menu)
222 return;
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();
234 void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
236 ConfigList* list = listView();
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);
248 * construct a menu entry
250 void ConfigItem::init(void)
252 if (menu) {
253 ConfigList* list = listView();
254 nextItem = (ConfigItem*)menu->data;
255 menu->data = this;
257 if (list->mode != fullMode)
258 setOpen(TRUE);
259 sym_calc_value(menu->sym);
261 updateMenu();
265 * destruct a menu entry
267 ConfigItem::~ConfigItem(void)
269 if (menu) {
270 ConfigItem** ip = (ConfigItem**)&menu->data;
271 for (; *ip; ip = &(*ip)->nextItem) {
272 if (*ip == this) {
273 *ip = nextItem;
274 break;
280 ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
281 : Parent(parent)
283 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
286 void ConfigLineEdit::show(ConfigItem* i)
288 item = i;
289 if (sym_get_string_value(item->menu->sym))
290 setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
291 else
292 setText(QString::null);
293 Parent::show();
294 setFocus();
297 void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
299 switch (e->key()) {
300 case Key_Escape:
301 break;
302 case Key_Return:
303 case Key_Enter:
304 sym_set_string_value(item->menu->sym, text().latin1());
305 parent()->updateList(item);
306 break;
307 default:
308 Parent::keyPressEvent(e);
309 return;
311 e->accept();
312 parent()->list->setFocus();
313 hide();
316 ConfigList::ConfigList(ConfigView* p, const char *name)
317 : Parent(p, name),
318 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),
323 rootEntry(0), headerPopup(0)
325 int i;
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());
334 connect(this, SIGNAL(selectionChanged(void)),
335 SLOT(updateSelection(void)));
337 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()));
347 for (i = 0; i < colNr; i++)
348 colMap[i] = colRevMap[i] = -1;
349 addColumn(promptColIdx, "Option");
351 reinit();
354 void ConfigList::reinit(void)
356 removeColumn(dataColIdx);
357 removeColumn(yesColIdx);
358 removeColumn(modColIdx);
359 removeColumn(noColIdx);
360 removeColumn(nameColIdx);
362 if (showName)
363 addColumn(nameColIdx, "Name");
364 if (showRange) {
365 addColumn(noColIdx, "N");
366 addColumn(modColIdx, "M");
367 addColumn(yesColIdx, "Y");
369 if (showData)
370 addColumn(dataColIdx, "Value");
372 updateListAll();
375 void ConfigList::saveSettings(void)
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();
387 ConfigItem* ConfigList::findConfigItem(struct menu *menu)
389 ConfigItem* item = (ConfigItem*)menu->data;
391 for (; item; item = item->nextItem) {
392 if (this == item->listView())
393 break;
396 return item;
399 void ConfigList::updateSelection(void)
401 struct menu *menu;
402 enum prop_type type;
404 ConfigItem* item = (ConfigItem*)selectedItem();
405 if (!item)
406 return;
408 menu = item->menu;
409 emit menuChanged(menu);
410 if (!menu)
411 return;
412 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
413 if (mode == menuMode && type == P_MENU)
414 emit menuSelected(menu);
417 void ConfigList::updateList(ConfigItem* item)
419 ConfigItem* last = 0;
421 if (!rootEntry) {
422 if (mode != listMode)
423 goto update;
424 QListViewItemIterator it(this);
425 ConfigItem* item;
427 for (; it.current(); ++it) {
428 item = (ConfigItem*)it.current();
429 if (!item->menu)
430 continue;
431 item->testUpdateMenu(menu_is_visible(item->menu));
433 return;
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;
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);
451 updateMenuList(item, rootEntry);
452 triggerUpdate();
453 return;
455 update:
456 updateMenuList(this, rootEntry);
457 triggerUpdate();
460 void ConfigList::setValue(ConfigItem* item, tristate val)
462 struct symbol* sym;
463 int type;
464 tristate oldval;
466 sym = item->menu ? item->menu->sym : 0;
467 if (!sym)
468 return;
470 type = sym_get_type(sym);
471 switch (type) {
472 case S_BOOLEAN:
473 case S_TRISTATE:
474 oldval = sym_get_tristate_value(sym);
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;
485 void ConfigList::changeValue(ConfigItem* item)
487 struct symbol* sym;
488 struct menu* menu;
489 int type, oldexpr, newexpr;
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;
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);
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;
529 void ConfigList::setRootMenu(struct menu *menu)
531 enum prop_type type;
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());
542 ensureItemVisible(currentItem());
545 void ConfigList::setParentMenu(void)
547 ConfigItem* item;
548 struct menu *oldroot;
550 oldroot = rootEntry;
551 if (rootEntry == &rootmenu)
552 return;
553 setRootMenu(menu_get_parent_menu(rootEntry->parent));
555 QListViewItemIterator it(this);
556 for (; (item = (ConfigItem*)it.current()); it++) {
557 if (item->menu == oldroot) {
558 setCurrentItem(item);
559 ensureItemVisible(item);
560 break;
566 * update all the children of a menu entry
567 * removes/adds the entries from the parent widget as necessary
569 * parent: either the menu list widget or a menu entry widget
570 * menu: entry to be updated
572 template <class P>
573 void ConfigList::updateMenuList(P* parent, struct menu* menu)
575 struct menu* child;
576 ConfigItem* item;
577 ConfigItem* last;
578 bool visible;
579 enum prop_type type;
581 if (!menu) {
582 while ((item = parent->firstChild()))
583 delete item;
584 return;
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;
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;
607 visible = menu_is_visible(child);
608 if (showAll || visible) {
609 if (!item || item->menu != child)
610 item = new ConfigItem(parent, last, child, visible);
611 else
612 item->testUpdateMenu(visible);
614 if (mode == fullMode || mode == menuMode || type != P_MENU)
615 updateMenuList(item, child);
616 else
617 updateMenuList(item, 0);
618 last = item;
619 continue;
621 hide:
622 if (item && item->menu == child) {
623 last = parent->firstChild();
624 if (last == item)
625 last = 0;
626 else while (last->nextSibling() != item)
627 last = last->nextSibling();
628 delete item;
633 void ConfigList::keyPressEvent(QKeyEvent* ev)
635 QListViewItem* i = currentItem();
636 ConfigItem* item;
637 struct menu *menu;
638 enum prop_type type;
640 if (ev->key() == Key_Escape && mode != fullMode && mode != listMode) {
641 emit parentSelected();
642 ev->accept();
643 return;
646 if (!i) {
647 Parent::keyPressEvent(ev);
648 return;
650 item = (ConfigItem*)i;
652 switch (ev->key()) {
653 case Key_Return:
654 case Key_Enter:
655 if (item->goParent) {
656 emit parentSelected();
657 break;
659 menu = item->menu;
660 if (!menu)
661 break;
662 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
663 if (type == P_MENU && rootEntry != menu &&
664 mode != fullMode && mode != menuMode) {
665 emit menuSelected(menu);
666 break;
668 case Key_Space:
669 changeValue(item);
670 break;
671 case Key_N:
672 setValue(item, no);
673 break;
674 case Key_M:
675 setValue(item, mod);
676 break;
677 case Key_Y:
678 setValue(item, yes);
679 break;
680 default:
681 Parent::keyPressEvent(ev);
682 return;
684 ev->accept();
687 void ConfigList::contentsMousePressEvent(QMouseEvent* e)
689 //QPoint p(contentsToViewport(e->pos()));
690 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
691 Parent::contentsMousePressEvent(e);
694 void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
696 QPoint p(contentsToViewport(e->pos()));
697 ConfigItem* item = (ConfigItem*)itemAt(p);
698 struct menu *menu;
699 enum prop_type ptype;
700 const QPixmap* pm;
701 int idx, x;
703 if (!item)
704 goto skip;
706 menu = item->menu;
707 x = header()->offset() + p.x();
708 idx = colRevMap[header()->sectionAt(x)];
709 switch (idx) {
710 case promptColIdx:
711 pm = item->pixmap(promptColIdx);
712 if (pm) {
713 int off = header()->sectionPos(0) + itemMargin() +
714 treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
715 if (x >= off && x < off + pm->width()) {
716 if (item->goParent) {
717 emit parentSelected();
718 break;
719 } else if (!menu)
720 break;
721 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
722 if (ptype == P_MENU && rootEntry != menu &&
723 mode != fullMode && mode != menuMode)
724 emit menuSelected(menu);
725 else
726 changeValue(item);
729 break;
730 case noColIdx:
731 setValue(item, no);
732 break;
733 case modColIdx:
734 setValue(item, mod);
735 break;
736 case yesColIdx:
737 setValue(item, yes);
738 break;
739 case dataColIdx:
740 changeValue(item);
741 break;
744 skip:
745 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
746 Parent::contentsMouseReleaseEvent(e);
749 void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
751 //QPoint p(contentsToViewport(e->pos()));
752 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
753 Parent::contentsMouseMoveEvent(e);
756 void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
758 QPoint p(contentsToViewport(e->pos()));
759 ConfigItem* item = (ConfigItem*)itemAt(p);
760 struct menu *menu;
761 enum prop_type ptype;
763 if (!item)
764 goto skip;
765 if (item->goParent) {
766 emit parentSelected();
767 goto skip;
769 menu = item->menu;
770 if (!menu)
771 goto skip;
772 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
773 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
774 emit menuSelected(menu);
775 else if (menu->sym)
776 changeValue(item);
778 skip:
779 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
780 Parent::contentsMouseDoubleClickEvent(e);
783 void ConfigList::focusInEvent(QFocusEvent *e)
785 struct menu *menu = NULL;
787 Parent::focusInEvent(e);
789 ConfigItem* item = (ConfigItem *)currentItem();
790 if (item) {
791 setSelected(item, TRUE);
792 menu = item->menu;
794 emit gotFocus(menu);
797 void ConfigList::contextMenuEvent(QContextMenuEvent *e)
799 if (e->y() <= header()->geometry().bottom()) {
800 if (!headerPopup) {
801 QAction *action;
803 headerPopup = new QPopupMenu(this);
804 action = new QAction(NULL, "Show Name", 0, this);
805 action->setToggleAction(TRUE);
806 connect(action, SIGNAL(toggled(bool)),
807 parent(), SLOT(setShowName(bool)));
808 connect(parent(), SIGNAL(showNameChanged(bool)),
809 action, SLOT(setOn(bool)));
810 action->setOn(showName);
811 action->addTo(headerPopup);
812 action = new QAction(NULL, "Show Range", 0, this);
813 action->setToggleAction(TRUE);
814 connect(action, SIGNAL(toggled(bool)),
815 parent(), SLOT(setShowRange(bool)));
816 connect(parent(), SIGNAL(showRangeChanged(bool)),
817 action, SLOT(setOn(bool)));
818 action->setOn(showRange);
819 action->addTo(headerPopup);
820 action = new QAction(NULL, "Show Data", 0, this);
821 action->setToggleAction(TRUE);
822 connect(action, SIGNAL(toggled(bool)),
823 parent(), SLOT(setShowData(bool)));
824 connect(parent(), SIGNAL(showDataChanged(bool)),
825 action, SLOT(setOn(bool)));
826 action->setOn(showData);
827 action->addTo(headerPopup);
829 headerPopup->exec(e->globalPos());
830 e->accept();
831 } else
832 e->ignore();
835 ConfigView* ConfigView::viewList;
837 ConfigView::ConfigView(QWidget* parent, const char *name)
838 : Parent(parent, name)
840 list = new ConfigList(this, name);
841 lineEdit = new ConfigLineEdit(this);
842 lineEdit->hide();
844 this->nextView = viewList;
845 viewList = this;
848 ConfigView::~ConfigView(void)
850 ConfigView** vp;
852 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
853 if (*vp == this) {
854 *vp = nextView;
855 break;
860 void ConfigView::setShowAll(bool b)
862 if (list->showAll != b) {
863 list->showAll = b;
864 list->updateListAll();
865 emit showAllChanged(b);
869 void ConfigView::setShowName(bool b)
871 if (list->showName != b) {
872 list->showName = b;
873 list->reinit();
874 emit showNameChanged(b);
878 void ConfigView::setShowRange(bool b)
880 if (list->showRange != b) {
881 list->showRange = b;
882 list->reinit();
883 emit showRangeChanged(b);
887 void ConfigView::setShowData(bool b)
889 if (list->showData != b) {
890 list->showData = b;
891 list->reinit();
892 emit showDataChanged(b);
896 void ConfigList::setAllOpen(bool open)
898 QListViewItemIterator it(this);
900 for (; it.current(); it++)
901 it.current()->setOpen(open);
904 void ConfigView::updateList(ConfigItem* item)
906 ConfigView* v;
908 for (v = viewList; v; v = v->nextView)
909 v->list->updateList(item);
912 void ConfigView::updateListAll(void)
914 ConfigView* v;
916 for (v = viewList; v; v = v->nextView)
917 v->list->updateListAll();
920 ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
921 : Parent(parent, name), menu(0), sym(0)
923 if (name) {
924 configSettings->beginGroup(name);
925 _showDebug = configSettings->readBoolEntry("/showDebug", false);
926 configSettings->endGroup();
927 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
931 void ConfigInfoView::saveSettings(void)
933 if (name()) {
934 configSettings->beginGroup(name());
935 configSettings->writeEntry("/showDebug", showDebug());
936 configSettings->endGroup();
940 void ConfigInfoView::setShowDebug(bool b)
942 if (_showDebug != b) {
943 _showDebug = b;
944 if (menu)
945 menuInfo();
946 else if (sym)
947 symbolInfo();
948 emit showDebugChanged(b);
952 void ConfigInfoView::setInfo(struct menu *m)
954 if (menu == m)
955 return;
956 menu = m;
957 sym = NULL;
958 if (!menu)
959 clear();
960 else
961 menuInfo();
964 void ConfigInfoView::setSource(const QString& name)
966 const char *p = name.latin1();
968 menu = NULL;
969 sym = NULL;
971 switch (p[0]) {
972 case 'm':
973 struct menu *m;
975 if (sscanf(p, "m%p", &m) == 1 && menu != m) {
976 menu = m;
977 menuInfo();
978 emit menuSelected(menu);
980 break;
981 case 's':
982 struct symbol *s;
984 if (sscanf(p, "s%p", &s) == 1 && sym != s) {
985 sym = s;
986 symbolInfo();
988 break;
992 void ConfigInfoView::symbolInfo(void)
994 QString str;
996 str += "<big>Symbol: <b>";
997 str += print_filter(sym->name);
998 str += "</b></big><br><br>value: ";
999 str += print_filter(sym_get_string_value(sym));
1000 str += "<br>visibility: ";
1001 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1002 str += "<br>";
1003 str += debug_info(sym);
1005 setText(str);
1008 void ConfigInfoView::menuInfo(void)
1010 struct symbol* sym;
1011 QString head, debug, help;
1013 sym = menu->sym;
1014 if (sym) {
1015 if (menu->prompt) {
1016 head += "<big><b>";
1017 head += print_filter(_(menu->prompt->text));
1018 head += "</b></big>";
1019 if (sym->name) {
1020 head += " (";
1021 if (showDebug())
1022 head += QString().sprintf("<a href=\"s%p\">", sym);
1023 head += print_filter(sym->name);
1024 if (showDebug())
1025 head += "</a>";
1026 head += ")";
1028 } else if (sym->name) {
1029 head += "<big><b>";
1030 if (showDebug())
1031 head += QString().sprintf("<a href=\"s%p\">", sym);
1032 head += print_filter(sym->name);
1033 if (showDebug())
1034 head += "</a>";
1035 head += "</b></big>";
1037 head += "<br><br>";
1039 if (showDebug())
1040 debug = debug_info(sym);
1042 help = print_filter(_(sym->help));
1043 } else if (menu->prompt) {
1044 head += "<big><b>";
1045 head += print_filter(_(menu->prompt->text));
1046 head += "</b></big><br><br>";
1047 if (showDebug()) {
1048 if (menu->prompt->visible.expr) {
1049 debug += "&nbsp;&nbsp;dep: ";
1050 expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
1051 debug += "<br><br>";
1055 if (showDebug())
1056 debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno);
1058 setText(head + debug + help);
1061 QString ConfigInfoView::debug_info(struct symbol *sym)
1063 QString debug;
1065 debug += "type: ";
1066 debug += print_filter(sym_type_name(sym->type));
1067 if (sym_is_choice(sym))
1068 debug += " (choice)";
1069 debug += "<br>";
1070 if (sym->rev_dep.expr) {
1071 debug += "reverse dep: ";
1072 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1073 debug += "<br>";
1075 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1076 switch (prop->type) {
1077 case P_PROMPT:
1078 case P_MENU:
1079 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
1080 debug += print_filter(_(prop->text));
1081 debug += "</a><br>";
1082 break;
1083 case P_DEFAULT:
1084 debug += "default: ";
1085 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1086 debug += "<br>";
1087 break;
1088 case P_CHOICE:
1089 if (sym_is_choice(sym)) {
1090 debug += "choice: ";
1091 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1092 debug += "<br>";
1094 break;
1095 case P_SELECT:
1096 debug += "select: ";
1097 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1098 debug += "<br>";
1099 break;
1100 case P_RANGE:
1101 debug += "range: ";
1102 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1103 debug += "<br>";
1104 break;
1105 default:
1106 debug += "unknown property: ";
1107 debug += prop_get_type_name(prop->type);
1108 debug += "<br>";
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>";
1116 debug += "<br>";
1118 return debug;
1121 QString ConfigInfoView::print_filter(const QString &str)
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;
1149 return res;
1152 void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
1154 QString* text = reinterpret_cast<QString*>(data);
1155 QString str2 = print_filter(str);
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;
1165 QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
1167 QPopupMenu* popup = Parent::createPopupMenu(pos);
1168 QAction* action = new QAction(NULL,"Show Debug Info", 0, popup);
1169 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;
1178 void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
1180 Parent::contentsContextMenuEvent(e);
1183 ConfigSearchWindow::ConfigSearchWindow(QWidget* parent, const char *name)
1184 : Parent(parent, name), result(NULL)
1186 setCaption("Search Config");
1188 QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
1189 QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
1190 layout2->addWidget(new QLabel("Find:", this));
1191 editField = new QLineEdit(this);
1192 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1193 layout2->addWidget(editField);
1194 searchButton = new QPushButton("Search", this);
1195 searchButton->setAutoDefault(FALSE);
1196 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1197 layout2->addWidget(searchButton);
1198 layout1->addLayout(layout2);
1200 split = new QSplitter(this);
1201 split->setOrientation(QSplitter::Vertical);
1202 list = new ConfigView(split, name);
1203 list->list->mode = listMode;
1204 info = new ConfigInfoView(split, name);
1205 connect(list->list, SIGNAL(menuChanged(struct menu *)),
1206 info, SLOT(setInfo(struct menu *)));
1207 layout1->addWidget(split);
1209 if (name) {
1210 int x, y, width, height;
1211 bool ok;
1213 configSettings->beginGroup(name);
1214 width = configSettings->readNumEntry("/window width", parent->width() / 2);
1215 height = configSettings->readNumEntry("/window height", parent->height() / 2);
1216 resize(width, height);
1217 x = configSettings->readNumEntry("/window x", 0, &ok);
1218 if (ok)
1219 y = configSettings->readNumEntry("/window y", 0, &ok);
1220 if (ok)
1221 move(x, y);
1222 QValueList<int> sizes = configSettings->readSizes("/split", &ok);
1223 if (ok)
1224 split->setSizes(sizes);
1225 configSettings->endGroup();
1226 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1230 void ConfigSearchWindow::saveSettings(void)
1232 if (name()) {
1233 configSettings->beginGroup(name());
1234 configSettings->writeEntry("/window x", pos().x());
1235 configSettings->writeEntry("/window y", pos().y());
1236 configSettings->writeEntry("/window width", size().width());
1237 configSettings->writeEntry("/window height", size().height());
1238 configSettings->writeSizes("/split", split->sizes());
1239 configSettings->endGroup();
1243 void ConfigSearchWindow::search(void)
1245 struct symbol **p;
1246 struct property *prop;
1247 ConfigItem *lastItem = NULL;
1249 free(result);
1250 list->list->clear();
1252 result = sym_re_search(editField->text().latin1());
1253 if (!result)
1254 return;
1255 for (p = result; *p; p++) {
1256 for_all_prompts((*p), prop)
1257 lastItem = new ConfigItem(list->list, lastItem, prop->menu,
1258 menu_is_visible(prop->menu));
1263 * Construct the complete config widget
1265 ConfigMainWindow::ConfigMainWindow(void)
1266 : searchWindow(0)
1268 QMenuBar* menu;
1269 bool ok;
1270 int x, y, width, height;
1272 QWidget *d = configApp->desktop();
1274 width = configSettings->readNumEntry("/window width", d->width() - 64);
1275 height = configSettings->readNumEntry("/window height", d->height() - 64);
1276 resize(width, height);
1277 x = configSettings->readNumEntry("/window x", 0, &ok);
1278 if (ok)
1279 y = configSettings->readNumEntry("/window y", 0, &ok);
1280 if (ok)
1281 move(x, y);
1283 split1 = new QSplitter(this);
1284 split1->setOrientation(QSplitter::Horizontal);
1285 setCentralWidget(split1);
1287 menuView = new ConfigView(split1, "menu");
1288 menuList = menuView->list;
1290 split2 = new QSplitter(split1);
1291 split2->setOrientation(QSplitter::Vertical);
1293 // create config tree
1294 configView = new ConfigView(split2, "config");
1295 configList = configView->list;
1297 helpText = new ConfigInfoView(split2, "help");
1298 helpText->setTextFormat(Qt::RichText);
1300 setTabOrder(configList, helpText);
1301 configList->setFocus();
1303 menu = menuBar();
1304 toolBar = new QToolBar("Tools", this);
1306 backAction = new QAction("Back", QPixmap(xpm_back), "Back", 0, this);
1307 connect(backAction, SIGNAL(activated()), SLOT(goBack()));
1308 backAction->setEnabled(FALSE);
1309 QAction *quitAction = new QAction("Quit", "&Quit", CTRL+Key_Q, this);
1310 connect(quitAction, SIGNAL(activated()), SLOT(close()));
1311 QAction *loadAction = new QAction("Load", QPixmap(xpm_load), "&Load", CTRL+Key_L, this);
1312 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
1313 saveAction = new QAction("Save", QPixmap(xpm_save), "&Save", CTRL+Key_S, this);
1314 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
1315 conf_set_changed_callback(conf_changed);
1316 // Set saveAction's initial state
1317 conf_changed();
1318 QAction *saveAsAction = new QAction("Save As...", "Save &As...", 0, this);
1319 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
1320 QAction *searchAction = new QAction("Find", "&Find", CTRL+Key_F, this);
1321 connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
1322 QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), "Split View", 0, this);
1323 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
1324 QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), "Split View", 0, this);
1325 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
1326 QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), "Full View", 0, this);
1327 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
1329 QAction *showNameAction = new QAction(NULL, "Show Name", 0, this);
1330 showNameAction->setToggleAction(TRUE);
1331 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
1332 connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
1333 showNameAction->setOn(configView->showName());
1334 QAction *showRangeAction = new QAction(NULL, "Show Range", 0, this);
1335 showRangeAction->setToggleAction(TRUE);
1336 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
1337 connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
1338 showRangeAction->setOn(configList->showRange);
1339 QAction *showDataAction = new QAction(NULL, "Show Data", 0, this);
1340 showDataAction->setToggleAction(TRUE);
1341 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
1342 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
1343 showDataAction->setOn(configList->showData);
1344 QAction *showAllAction = new QAction(NULL, "Show All Options", 0, this);
1345 showAllAction->setToggleAction(TRUE);
1346 connect(showAllAction, SIGNAL(toggled(bool)), configView, SLOT(setShowAll(bool)));
1347 connect(showAllAction, SIGNAL(toggled(bool)), menuView, SLOT(setShowAll(bool)));
1348 showAllAction->setOn(configList->showAll);
1349 QAction *showDebugAction = new QAction(NULL, "Show Debug Info", 0, this);
1350 showDebugAction->setToggleAction(TRUE);
1351 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
1352 connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
1353 showDebugAction->setOn(helpText->showDebug());
1355 QAction *showIntroAction = new QAction(NULL, "Introduction", 0, this);
1356 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
1357 QAction *showAboutAction = new QAction(NULL, "About", 0, this);
1358 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
1360 // init tool bar
1361 backAction->addTo(toolBar);
1362 toolBar->addSeparator();
1363 loadAction->addTo(toolBar);
1364 saveAction->addTo(toolBar);
1365 toolBar->addSeparator();
1366 singleViewAction->addTo(toolBar);
1367 splitViewAction->addTo(toolBar);
1368 fullViewAction->addTo(toolBar);
1370 // create config menu
1371 QPopupMenu* config = new QPopupMenu(this);
1372 menu->insertItem("&File", config);
1373 loadAction->addTo(config);
1374 saveAction->addTo(config);
1375 saveAsAction->addTo(config);
1376 config->insertSeparator();
1377 quitAction->addTo(config);
1379 // create edit menu
1380 QPopupMenu* editMenu = new QPopupMenu(this);
1381 menu->insertItem("&Edit", editMenu);
1382 searchAction->addTo(editMenu);
1384 // create options menu
1385 QPopupMenu* optionMenu = new QPopupMenu(this);
1386 menu->insertItem("&Option", optionMenu);
1387 showNameAction->addTo(optionMenu);
1388 showRangeAction->addTo(optionMenu);
1389 showDataAction->addTo(optionMenu);
1390 optionMenu->insertSeparator();
1391 showAllAction->addTo(optionMenu);
1392 showDebugAction->addTo(optionMenu);
1394 // create help menu
1395 QPopupMenu* helpMenu = new QPopupMenu(this);
1396 menu->insertSeparator();
1397 menu->insertItem("&Help", helpMenu);
1398 showIntroAction->addTo(helpMenu);
1399 showAboutAction->addTo(helpMenu);
1401 connect(configList, SIGNAL(menuChanged(struct menu *)),
1402 helpText, SLOT(setInfo(struct menu *)));
1403 connect(configList, SIGNAL(menuSelected(struct menu *)),
1404 SLOT(changeMenu(struct menu *)));
1405 connect(configList, SIGNAL(parentSelected()),
1406 SLOT(goBack()));
1407 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1408 helpText, SLOT(setInfo(struct menu *)));
1409 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1410 SLOT(changeMenu(struct menu *)));
1412 connect(configList, SIGNAL(gotFocus(struct menu *)),
1413 helpText, SLOT(setInfo(struct menu *)));
1414 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1415 helpText, SLOT(setInfo(struct menu *)));
1416 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1417 SLOT(listFocusChanged(void)));
1418 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1419 SLOT(setMenuLink(struct menu *)));
1421 QString listMode = configSettings->readEntry("/listMode", "symbol");
1422 if (listMode == "single")
1423 showSingleView();
1424 else if (listMode == "full")
1425 showFullView();
1426 else /*if (listMode == "split")*/
1427 showSplitView();
1429 // UI setup done, restore splitter positions
1430 QValueList<int> sizes = configSettings->readSizes("/split1", &ok);
1431 if (ok)
1432 split1->setSizes(sizes);
1434 sizes = configSettings->readSizes("/split2", &ok);
1435 if (ok)
1436 split2->setSizes(sizes);
1439 void ConfigMainWindow::loadConfig(void)
1441 QString s = QFileDialog::getOpenFileName(".config", NULL, this);
1442 if (s.isNull())
1443 return;
1444 if (conf_read(QFile::encodeName(s)))
1445 QMessageBox::information(this, "qconf", "Unable to load configuration!");
1446 ConfigView::updateListAll();
1449 void ConfigMainWindow::saveConfig(void)
1451 if (conf_write(NULL))
1452 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1455 void ConfigMainWindow::saveConfigAs(void)
1457 QString s = QFileDialog::getSaveFileName(".config", NULL, this);
1458 if (s.isNull())
1459 return;
1460 if (conf_write(QFile::encodeName(s)))
1461 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1464 void ConfigMainWindow::searchConfig(void)
1466 if (!searchWindow)
1467 searchWindow = new ConfigSearchWindow(this, "search");
1468 searchWindow->show();
1471 void ConfigMainWindow::changeMenu(struct menu *menu)
1473 configList->setRootMenu(menu);
1474 backAction->setEnabled(TRUE);
1477 void ConfigMainWindow::setMenuLink(struct menu *menu)
1479 struct menu *parent;
1480 ConfigList* list = NULL;
1481 ConfigItem* item;
1483 if (!menu_is_visible(menu) && !configView->showAll())
1484 return;
1486 switch (configList->mode) {
1487 case singleMode:
1488 list = configList;
1489 parent = menu_get_parent_menu(menu);
1490 if (!parent)
1491 return;
1492 list->setRootMenu(parent);
1493 break;
1494 case symbolMode:
1495 if (menu->flags & MENU_ROOT) {
1496 configList->setRootMenu(menu);
1497 configList->clearSelection();
1498 list = menuList;
1499 } else {
1500 list = configList;
1501 parent = menu_get_parent_menu(menu->parent);
1502 if (!parent)
1503 return;
1504 item = menuList->findConfigItem(parent);
1505 if (item) {
1506 menuList->setSelected(item, TRUE);
1507 menuList->ensureItemVisible(item);
1509 list->setRootMenu(parent);
1511 break;
1512 case fullMode:
1513 list = configList;
1514 break;
1517 if (list) {
1518 item = list->findConfigItem(menu);
1519 if (item) {
1520 list->setSelected(item, TRUE);
1521 list->ensureItemVisible(item);
1522 list->setFocus();
1527 void ConfigMainWindow::listFocusChanged(void)
1529 if (menuList->mode == menuMode)
1530 configList->clearSelection();
1533 void ConfigMainWindow::goBack(void)
1535 ConfigItem* item;
1537 configList->setParentMenu();
1538 if (configList->rootEntry == &rootmenu)
1539 backAction->setEnabled(FALSE);
1540 item = (ConfigItem*)menuList->selectedItem();
1541 while (item) {
1542 if (item->menu == configList->rootEntry) {
1543 menuList->setSelected(item, TRUE);
1544 break;
1546 item = (ConfigItem*)item->parent();
1550 void ConfigMainWindow::showSingleView(void)
1552 menuView->hide();
1553 menuList->setRootMenu(0);
1554 configList->mode = singleMode;
1555 if (configList->rootEntry == &rootmenu)
1556 configList->updateListAll();
1557 else
1558 configList->setRootMenu(&rootmenu);
1559 configList->setAllOpen(TRUE);
1560 configList->setFocus();
1563 void ConfigMainWindow::showSplitView(void)
1565 configList->mode = symbolMode;
1566 if (configList->rootEntry == &rootmenu)
1567 configList->updateListAll();
1568 else
1569 configList->setRootMenu(&rootmenu);
1570 configList->setAllOpen(TRUE);
1571 configApp->processEvents();
1572 menuList->mode = menuMode;
1573 menuList->setRootMenu(&rootmenu);
1574 menuList->setAllOpen(TRUE);
1575 menuView->show();
1576 menuList->setFocus();
1579 void ConfigMainWindow::showFullView(void)
1581 menuView->hide();
1582 menuList->setRootMenu(0);
1583 configList->mode = fullMode;
1584 if (configList->rootEntry == &rootmenu)
1585 configList->updateListAll();
1586 else
1587 configList->setRootMenu(&rootmenu);
1588 configList->setAllOpen(FALSE);
1589 configList->setFocus();
1593 * ask for saving configuration before quitting
1594 * TODO ask only when something changed
1596 void ConfigMainWindow::closeEvent(QCloseEvent* e)
1598 if (!conf_get_changed()) {
1599 e->accept();
1600 return;
1602 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
1603 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
1604 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1605 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1606 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
1607 switch (mb.exec()) {
1608 case QMessageBox::Yes:
1609 conf_write(NULL);
1610 case QMessageBox::No:
1611 e->accept();
1612 break;
1613 case QMessageBox::Cancel:
1614 e->ignore();
1615 break;
1619 void ConfigMainWindow::showIntro(void)
1621 static char str[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
1622 "For each option, a blank box indicates the feature is disabled, a check\n"
1623 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1624 "as a module. Clicking on the box will cycle through the three states.\n\n"
1625 "If you do not see an option (e.g., a device driver) that you believe\n"
1626 "should be present, try turning on Show All Options under the Options menu.\n"
1627 "Although there is no cross reference yet to help you figure out what other\n"
1628 "options must be enabled to support the option you are interested in, you can\n"
1629 "still view the help of a grayed-out option.\n\n"
1630 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1631 "which you can then match by examining other options.\n\n";
1633 QMessageBox::information(this, "qconf", str);
1636 void ConfigMainWindow::showAbout(void)
1638 static char str[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1639 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
1641 QMessageBox::information(this, "qconf", str);
1644 void ConfigMainWindow::saveSettings(void)
1646 configSettings->writeEntry("/window x", pos().x());
1647 configSettings->writeEntry("/window y", pos().y());
1648 configSettings->writeEntry("/window width", size().width());
1649 configSettings->writeEntry("/window height", size().height());
1651 QString entry;
1652 switch(configList->mode) {
1653 case singleMode :
1654 entry = "single";
1655 break;
1657 case symbolMode :
1658 entry = "split";
1659 break;
1661 case fullMode :
1662 entry = "full";
1663 break;
1665 configSettings->writeEntry("/listMode", entry);
1667 configSettings->writeSizes("/split1", split1->sizes());
1668 configSettings->writeSizes("/split2", split2->sizes());
1671 void ConfigMainWindow::conf_changed(void)
1673 if (saveAction)
1674 saveAction->setEnabled(conf_get_changed());
1677 void fixup_rootmenu(struct menu *menu)
1679 struct menu *child;
1680 static int menu_cnt = 0;
1682 menu->flags |= MENU_ROOT;
1683 for (child = menu->list; child; child = child->next) {
1684 if (child->prompt && child->prompt->type == P_MENU) {
1685 menu_cnt++;
1686 fixup_rootmenu(child);
1687 menu_cnt--;
1688 } else if (!menu_cnt)
1689 fixup_rootmenu(child);
1693 static const char *progname;
1695 static void usage(void)
1697 printf("%s <config>\n", progname);
1698 exit(0);
1701 int main(int ac, char** av)
1703 ConfigMainWindow* v;
1704 const char *name;
1706 bindtextdomain(PACKAGE, LOCALEDIR);
1707 textdomain(PACKAGE);
1709 #ifndef LKC_DIRECT_LINK
1710 kconfig_load();
1711 #endif
1713 progname = av[0];
1714 configApp = new QApplication(ac, av);
1715 if (ac > 1 && av[1][0] == '-') {
1716 switch (av[1][1]) {
1717 case 'h':
1718 case '?':
1719 usage();
1721 name = av[2];
1722 } else
1723 name = av[1];
1724 if (!name)
1725 usage();
1727 conf_parse(name);
1728 fixup_rootmenu(&rootmenu);
1729 conf_read(NULL);
1730 //zconfdump(stdout);
1732 configSettings = new ConfigSettings();
1733 configSettings->beginGroup("/kconfig/qconf");
1734 v = new ConfigMainWindow();
1736 //zconfdump(stdout);
1737 configApp->setMainWidget(v);
1738 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1739 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
1740 v->show();
1741 configApp->exec();
1743 configSettings->endGroup();
1744 delete configSettings;
1746 return 0;