2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
6 #include <qapplication.h>
7 #include <qmainwindow.h>
10 #include <qsplitter.h>
11 #include <qlistview.h>
12 #include <qtextview.h>
13 #include <qlineedit.h>
15 #include <qmessagebox.h>
18 #include <qfiledialog.h>
29 static QApplication
*configApp
;
31 ConfigSettings::ConfigSettings()
32 : showAll(false), showName(false), showRange(false), showData(false)
38 * Reads the list column settings from the application settings.
40 void ConfigSettings::readListSettings()
42 showAll
= readBoolEntry("/kconfig/qconf/showAll", false);
43 showName
= readBoolEntry("/kconfig/qconf/showName", false);
44 showRange
= readBoolEntry("/kconfig/qconf/showRange", false);
45 showData
= readBoolEntry("/kconfig/qconf/showData", false);
49 * Reads a list of integer values from the application settings.
51 QValueList
<int> ConfigSettings::readSizes(const QString
& key
, bool *ok
)
53 QValueList
<int> result
;
54 QStringList entryList
= readListEntry(key
, ok
);
56 QStringList::Iterator it
;
57 for (it
= entryList
.begin(); it
!= entryList
.end(); ++it
)
58 result
.push_back((*it
).toInt());
65 * Writes a list of integer values to the application settings.
67 bool ConfigSettings::writeSizes(const QString
& key
, const QValueList
<int>& value
)
69 QStringList stringList
;
70 QValueList
<int>::ConstIterator it
;
72 for (it
= value
.begin(); it
!= value
.end(); ++it
)
73 stringList
.push_back(QString::number(*it
));
74 return writeEntry(key
, stringList
);
80 * update all the children of a menu entry
81 * removes/adds the entries from the parent widget as necessary
83 * parent: either the menu list widget or a menu entry widget
84 * menu: entry to be updated
87 void ConfigList::updateMenuList(P
* parent
, struct menu
* menu
)
96 while ((item
= parent
->firstChild()))
101 last
= parent
->firstChild();
102 if (last
&& !last
->goParent
)
104 for (child
= menu
->list
; child
; child
= child
->next
) {
105 item
= last
? last
->nextSibling() : parent
->firstChild();
106 type
= child
->prompt
? child
->prompt
->type
: P_UNKNOWN
;
110 if (!(child
->flags
& MENU_ROOT
))
114 if (child
->flags
& MENU_ROOT
)
121 visible
= menu_is_visible(child
);
122 if (showAll
|| visible
) {
123 if (!item
|| item
->menu
!= child
)
124 item
= new ConfigItem(parent
, last
, child
, visible
);
126 item
->testUpdateMenu(visible
);
128 if (mode
== fullMode
|| mode
== menuMode
|| type
!= P_MENU
)
129 updateMenuList(item
, child
);
131 updateMenuList(item
, 0);
136 if (item
&& item
->menu
== child
) {
137 last
= parent
->firstChild();
140 else while (last
->nextSibling() != item
)
141 last
= last
->nextSibling();
147 #if QT_VERSION >= 300
150 * TODO check the value
152 void ConfigItem::okRename(int col
)
154 Parent::okRename(col
);
155 sym_set_string_value(menu
->sym
, text(dataColIdx
).latin1());
160 * update the displayed of a menu entry
162 void ConfigItem::updateMenu(void)
166 struct property
*prop
;
173 setPixmap(promptColIdx
, list
->menuBackPix
);
180 prompt
= menu_get_prompt(menu
);
182 if (prop
) switch (prop
->type
) {
184 if (list
->mode
== singleMode
|| list
->mode
== symbolMode
) {
185 /* a menuconfig entry is displayed differently
186 * depending whether it's at the view root or a child.
188 if (sym
&& list
->rootEntry
== menu
)
190 setPixmap(promptColIdx
, list
->menuPix
);
194 setPixmap(promptColIdx
, 0);
198 setPixmap(promptColIdx
, 0);
206 setText(nameColIdx
, sym
->name
);
208 type
= sym_get_type(sym
);
214 if (!sym_is_changable(sym
) && !list
->showAll
) {
215 setPixmap(promptColIdx
, 0);
216 setText(noColIdx
, 0);
217 setText(modColIdx
, 0);
218 setText(yesColIdx
, 0);
221 expr
= sym_get_tristate_value(sym
);
224 if (sym_is_choice_value(sym
) && type
== S_BOOLEAN
)
225 setPixmap(promptColIdx
, list
->choiceYesPix
);
227 setPixmap(promptColIdx
, list
->symbolYesPix
);
228 setText(yesColIdx
, "Y");
232 setPixmap(promptColIdx
, list
->symbolModPix
);
233 setText(modColIdx
, "M");
237 if (sym_is_choice_value(sym
) && type
== S_BOOLEAN
)
238 setPixmap(promptColIdx
, list
->choiceNoPix
);
240 setPixmap(promptColIdx
, list
->symbolNoPix
);
241 setText(noColIdx
, "N");
246 setText(noColIdx
, sym_tristate_within_range(sym
, no
) ? "_" : 0);
248 setText(modColIdx
, sym_tristate_within_range(sym
, mod
) ? "_" : 0);
250 setText(yesColIdx
, sym_tristate_within_range(sym
, yes
) ? "_" : 0);
252 setText(dataColIdx
, QChar(ch
));
259 data
= sym_get_string_value(sym
);
260 #if QT_VERSION >= 300
261 int i
= list
->mapIdx(dataColIdx
);
263 setRenameEnabled(i
, TRUE
);
265 setText(dataColIdx
, data
);
266 if (type
== S_STRING
)
267 prompt
.sprintf("%s: %s", prompt
.latin1(), data
);
269 prompt
.sprintf("(%s) %s", data
, prompt
.latin1());
272 if (!sym_has_value(sym
) && visible
)
275 setText(promptColIdx
, prompt
);
278 void ConfigItem::testUpdateMenu(bool v
)
286 sym_calc_value(menu
->sym
);
287 if (menu
->flags
& MENU_CHANGED
) {
288 /* the menu entry changed, so update all list items */
289 menu
->flags
&= ~MENU_CHANGED
;
290 for (i
= (ConfigItem
*)menu
->data
; i
; i
= i
->nextItem
)
292 } else if (listView()->updateAll
)
296 void ConfigItem::paintCell(QPainter
* p
, const QColorGroup
& cg
, int column
, int width
, int align
)
298 ConfigList
* list
= listView();
301 if (isSelected() && !list
->hasFocus() && list
->mode
== menuMode
)
302 Parent::paintCell(p
, list
->inactivedColorGroup
, column
, width
, align
);
304 Parent::paintCell(p
, cg
, column
, width
, align
);
306 Parent::paintCell(p
, list
->disabledColorGroup
, column
, width
, align
);
310 * construct a menu entry
312 void ConfigItem::init(void)
315 ConfigList
* list
= listView();
316 nextItem
= (ConfigItem
*)menu
->data
;
319 if (list
->mode
!= fullMode
)
321 sym_calc_value(menu
->sym
);
327 * destruct a menu entry
329 ConfigItem::~ConfigItem(void)
332 ConfigItem
** ip
= (ConfigItem
**)&menu
->data
;
333 for (; *ip
; ip
= &(*ip
)->nextItem
) {
342 void ConfigLineEdit::show(ConfigItem
* i
)
345 if (sym_get_string_value(item
->menu
->sym
))
346 setText(sym_get_string_value(item
->menu
->sym
));
353 void ConfigLineEdit::keyPressEvent(QKeyEvent
* e
)
360 sym_set_string_value(item
->menu
->sym
, text().latin1());
361 parent()->updateList(item
);
364 Parent::keyPressEvent(e
);
368 parent()->list
->setFocus();
372 ConfigList::ConfigList(ConfigView
* p
, ConfigMainWindow
* cv
, ConfigSettings
* configSettings
)
373 : Parent(p
), cview(cv
),
375 symbolYesPix(xpm_symbol_yes
), symbolModPix(xpm_symbol_mod
), symbolNoPix(xpm_symbol_no
),
376 choiceYesPix(xpm_choice_yes
), choiceNoPix(xpm_choice_no
),
377 menuPix(xpm_menu
), menuInvPix(xpm_menu_inv
), menuBackPix(xpm_menuback
), voidPix(xpm_void
),
378 showAll(false), showName(false), showRange(false), showData(false),
384 setRootIsDecorated(TRUE
);
385 disabledColorGroup
= palette().active();
386 disabledColorGroup
.setColor(QColorGroup::Text
, palette().disabled().text());
387 inactivedColorGroup
= palette().active();
388 inactivedColorGroup
.setColor(QColorGroup::Highlight
, palette().disabled().highlight());
390 connect(this, SIGNAL(selectionChanged(void)),
391 SLOT(updateSelection(void)));
393 if (configSettings
) {
394 showAll
= configSettings
->showAll
;
395 showName
= configSettings
->showName
;
396 showRange
= configSettings
->showRange
;
397 showData
= configSettings
->showData
;
400 for (i
= 0; i
< colNr
; i
++)
401 colMap
[i
] = colRevMap
[i
] = -1;
402 addColumn(promptColIdx
, "Option");
407 void ConfigList::reinit(void)
409 removeColumn(dataColIdx
);
410 removeColumn(yesColIdx
);
411 removeColumn(modColIdx
);
412 removeColumn(noColIdx
);
413 removeColumn(nameColIdx
);
416 addColumn(nameColIdx
, "Name");
418 addColumn(noColIdx
, "N");
419 addColumn(modColIdx
, "M");
420 addColumn(yesColIdx
, "Y");
423 addColumn(dataColIdx
, "Value");
428 void ConfigList::updateSelection(void)
433 ConfigItem
* item
= (ConfigItem
*)selectedItem();
437 cview
->setHelp(item
);
442 type
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
443 if (mode
== menuMode
&& type
== P_MENU
)
444 emit
menuSelected(menu
);
447 void ConfigList::updateList(ConfigItem
* item
)
449 ConfigItem
* last
= 0;
454 if (rootEntry
!= &rootmenu
&& (mode
== singleMode
||
455 (mode
== symbolMode
&& rootEntry
->parent
!= &rootmenu
))) {
458 item
= new ConfigItem(this, 0, true);
461 if ((mode
== singleMode
|| (mode
== symbolMode
&& !(rootEntry
->flags
& MENU_ROOT
))) &&
462 rootEntry
->sym
&& rootEntry
->prompt
) {
463 item
= last
? last
->nextSibling() : firstChild();
465 item
= new ConfigItem(this, last
, rootEntry
, true);
467 item
->testUpdateMenu(true);
469 updateMenuList(item
, rootEntry
);
474 updateMenuList(this, rootEntry
);
478 void ConfigList::setAllOpen(bool open
)
480 QListViewItemIterator
it(this);
482 for (; it
.current(); it
++)
483 it
.current()->setOpen(open
);
486 void ConfigList::setValue(ConfigItem
* item
, tristate val
)
492 sym
= item
->menu
? item
->menu
->sym
: 0;
496 type
= sym_get_type(sym
);
500 oldval
= sym_get_tristate_value(sym
);
502 if (!sym_set_tristate_value(sym
, val
))
504 if (oldval
== no
&& item
->menu
->list
)
506 parent()->updateList(item
);
511 void ConfigList::changeValue(ConfigItem
* item
)
515 int type
, oldexpr
, newexpr
;
522 if (item
->menu
->list
)
523 item
->setOpen(!item
->isOpen());
527 type
= sym_get_type(sym
);
531 oldexpr
= sym_get_tristate_value(sym
);
532 newexpr
= sym_toggle_tristate_value(sym
);
533 if (item
->menu
->list
) {
534 if (oldexpr
== newexpr
)
535 item
->setOpen(!item
->isOpen());
536 else if (oldexpr
== no
)
539 if (oldexpr
!= newexpr
)
540 parent()->updateList(item
);
545 #if QT_VERSION >= 300
546 if (colMap
[dataColIdx
] >= 0)
547 item
->startRename(colMap
[dataColIdx
]);
550 parent()->lineEdit
->show(item
);
555 void ConfigList::setRootMenu(struct menu
*menu
)
559 if (rootEntry
== menu
)
561 type
= menu
&& menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
564 updateMenuList(this, 0);
567 setSelected(currentItem(), hasFocus());
570 void ConfigList::setParentMenu(void)
573 struct menu
*oldroot
;
576 if (rootEntry
== &rootmenu
)
578 setRootMenu(menu_get_parent_menu(rootEntry
->parent
));
580 QListViewItemIterator
it(this);
581 for (; (item
= (ConfigItem
*)it
.current()); it
++) {
582 if (item
->menu
== oldroot
) {
583 setCurrentItem(item
);
584 ensureItemVisible(item
);
590 void ConfigList::keyPressEvent(QKeyEvent
* ev
)
592 QListViewItem
* i
= currentItem();
597 if (ev
->key() == Key_Escape
&& mode
!= fullMode
) {
598 emit
parentSelected();
604 Parent::keyPressEvent(ev
);
607 item
= (ConfigItem
*)i
;
612 if (item
->goParent
) {
613 emit
parentSelected();
619 type
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
620 if (type
== P_MENU
&& rootEntry
!= menu
&&
621 mode
!= fullMode
&& mode
!= menuMode
) {
622 emit
menuSelected(menu
);
638 Parent::keyPressEvent(ev
);
644 void ConfigList::contentsMousePressEvent(QMouseEvent
* e
)
646 //QPoint p(contentsToViewport(e->pos()));
647 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
648 Parent::contentsMousePressEvent(e
);
651 void ConfigList::contentsMouseReleaseEvent(QMouseEvent
* e
)
653 QPoint
p(contentsToViewport(e
->pos()));
654 ConfigItem
* item
= (ConfigItem
*)itemAt(p
);
656 enum prop_type ptype
;
664 x
= header()->offset() + p
.x();
665 idx
= colRevMap
[header()->sectionAt(x
)];
668 pm
= item
->pixmap(promptColIdx
);
670 int off
= header()->sectionPos(0) + itemMargin() +
671 treeStepSize() * (item
->depth() + (rootIsDecorated() ? 1 : 0));
672 if (x
>= off
&& x
< off
+ pm
->width()) {
673 if (item
->goParent
) {
674 emit
parentSelected();
678 ptype
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
679 if (ptype
== P_MENU
&& rootEntry
!= menu
&&
680 mode
!= fullMode
&& mode
!= menuMode
)
681 emit
menuSelected(menu
);
702 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
703 Parent::contentsMouseReleaseEvent(e
);
706 void ConfigList::contentsMouseMoveEvent(QMouseEvent
* e
)
708 //QPoint p(contentsToViewport(e->pos()));
709 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
710 Parent::contentsMouseMoveEvent(e
);
713 void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent
* e
)
715 QPoint
p(contentsToViewport(e
->pos()));
716 ConfigItem
* item
= (ConfigItem
*)itemAt(p
);
718 enum prop_type ptype
;
722 if (item
->goParent
) {
723 emit
parentSelected();
729 ptype
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
730 if (ptype
== P_MENU
&& (mode
== singleMode
|| mode
== symbolMode
))
731 emit
menuSelected(menu
);
736 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
737 Parent::contentsMouseDoubleClickEvent(e
);
740 void ConfigList::focusInEvent(QFocusEvent
*e
)
742 Parent::focusInEvent(e
);
744 QListViewItem
* item
= currentItem();
748 setSelected(item
, TRUE
);
752 ConfigView
* ConfigView::viewList
;
754 ConfigView::ConfigView(QWidget
* parent
, ConfigMainWindow
* cview
,
755 ConfigSettings
*configSettings
)
758 list
= new ConfigList(this, cview
, configSettings
);
759 lineEdit
= new ConfigLineEdit(this);
762 this->nextView
= viewList
;
766 ConfigView::~ConfigView(void)
770 for (vp
= &viewList
; *vp
; vp
= &(*vp
)->nextView
) {
778 void ConfigView::updateList(ConfigItem
* item
)
782 for (v
= viewList
; v
; v
= v
->nextView
)
783 v
->list
->updateList(item
);
786 void ConfigView::updateListAll(void)
790 for (v
= viewList
; v
; v
= v
->nextView
)
791 v
->list
->updateListAll();
795 * Construct the complete config widget
797 ConfigMainWindow::ConfigMainWindow(void)
801 int x
, y
, width
, height
;
803 QWidget
*d
= configApp
->desktop();
805 ConfigSettings
* configSettings
= new ConfigSettings();
806 #if QT_VERSION >= 300
807 width
= configSettings
->readNumEntry("/kconfig/qconf/window width", d
->width() - 64);
808 height
= configSettings
->readNumEntry("/kconfig/qconf/window height", d
->height() - 64);
809 resize(width
, height
);
810 x
= configSettings
->readNumEntry("/kconfig/qconf/window x", 0, &ok
);
812 y
= configSettings
->readNumEntry("/kconfig/qconf/window y", 0, &ok
);
815 showDebug
= configSettings
->readBoolEntry("/kconfig/qconf/showDebug", false);
817 // read list settings into configSettings, will be used later for ConfigList setup
818 configSettings
->readListSettings();
820 width
= d
->width() - 64;
821 height
= d
->height() - 64;
822 resize(width
, height
);
826 split1
= new QSplitter(this);
827 split1
->setOrientation(QSplitter::Horizontal
);
828 setCentralWidget(split1
);
830 menuView
= new ConfigView(split1
, this, configSettings
);
831 menuList
= menuView
->list
;
833 split2
= new QSplitter(split1
);
834 split2
->setOrientation(QSplitter::Vertical
);
836 // create config tree
837 configView
= new ConfigView(split2
, this, configSettings
);
838 configList
= configView
->list
;
840 helpText
= new QTextView(split2
);
841 helpText
->setTextFormat(Qt::RichText
);
843 setTabOrder(configList
, helpText
);
844 configList
->setFocus();
847 toolBar
= new QToolBar("Tools", this);
849 backAction
= new QAction("Back", QPixmap(xpm_back
), "Back", 0, this);
850 connect(backAction
, SIGNAL(activated()), SLOT(goBack()));
851 backAction
->setEnabled(FALSE
);
852 QAction
*quitAction
= new QAction("Quit", "&Quit", CTRL
+Key_Q
, this);
853 connect(quitAction
, SIGNAL(activated()), SLOT(close()));
854 QAction
*loadAction
= new QAction("Load", QPixmap(xpm_load
), "&Load", CTRL
+Key_L
, this);
855 connect(loadAction
, SIGNAL(activated()), SLOT(loadConfig()));
856 QAction
*saveAction
= new QAction("Save", QPixmap(xpm_save
), "&Save", CTRL
+Key_S
, this);
857 connect(saveAction
, SIGNAL(activated()), SLOT(saveConfig()));
858 QAction
*saveAsAction
= new QAction("Save As...", "Save &As...", 0, this);
859 connect(saveAsAction
, SIGNAL(activated()), SLOT(saveConfigAs()));
860 QAction
*singleViewAction
= new QAction("Single View", QPixmap(xpm_single_view
), "Split View", 0, this);
861 connect(singleViewAction
, SIGNAL(activated()), SLOT(showSingleView()));
862 QAction
*splitViewAction
= new QAction("Split View", QPixmap(xpm_split_view
), "Split View", 0, this);
863 connect(splitViewAction
, SIGNAL(activated()), SLOT(showSplitView()));
864 QAction
*fullViewAction
= new QAction("Full View", QPixmap(xpm_tree_view
), "Full View", 0, this);
865 connect(fullViewAction
, SIGNAL(activated()), SLOT(showFullView()));
867 QAction
*showNameAction
= new QAction(NULL
, "Show Name", 0, this);
868 showNameAction
->setToggleAction(TRUE
);
869 showNameAction
->setOn(configList
->showName
);
870 connect(showNameAction
, SIGNAL(toggled(bool)), SLOT(setShowName(bool)));
871 QAction
*showRangeAction
= new QAction(NULL
, "Show Range", 0, this);
872 showRangeAction
->setToggleAction(TRUE
);
873 showRangeAction
->setOn(configList
->showRange
);
874 connect(showRangeAction
, SIGNAL(toggled(bool)), SLOT(setShowRange(bool)));
875 QAction
*showDataAction
= new QAction(NULL
, "Show Data", 0, this);
876 showDataAction
->setToggleAction(TRUE
);
877 showDataAction
->setOn(configList
->showData
);
878 connect(showDataAction
, SIGNAL(toggled(bool)), SLOT(setShowData(bool)));
879 QAction
*showAllAction
= new QAction(NULL
, "Show All Options", 0, this);
880 showAllAction
->setToggleAction(TRUE
);
881 showAllAction
->setOn(configList
->showAll
);
882 connect(showAllAction
, SIGNAL(toggled(bool)), SLOT(setShowAll(bool)));
883 QAction
*showDebugAction
= new QAction(NULL
, "Show Debug Info", 0, this);
884 showDebugAction
->setToggleAction(TRUE
);
885 showDebugAction
->setOn(showDebug
);
886 connect(showDebugAction
, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
888 QAction
*showIntroAction
= new QAction(NULL
, "Introduction", 0, this);
889 connect(showIntroAction
, SIGNAL(activated()), SLOT(showIntro()));
890 QAction
*showAboutAction
= new QAction(NULL
, "About", 0, this);
891 connect(showAboutAction
, SIGNAL(activated()), SLOT(showAbout()));
894 backAction
->addTo(toolBar
);
895 toolBar
->addSeparator();
896 loadAction
->addTo(toolBar
);
897 saveAction
->addTo(toolBar
);
898 toolBar
->addSeparator();
899 singleViewAction
->addTo(toolBar
);
900 splitViewAction
->addTo(toolBar
);
901 fullViewAction
->addTo(toolBar
);
903 // create config menu
904 QPopupMenu
* config
= new QPopupMenu(this);
905 menu
->insertItem("&File", config
);
906 loadAction
->addTo(config
);
907 saveAction
->addTo(config
);
908 saveAsAction
->addTo(config
);
909 config
->insertSeparator();
910 quitAction
->addTo(config
);
912 // create options menu
913 QPopupMenu
* optionMenu
= new QPopupMenu(this);
914 menu
->insertItem("&Option", optionMenu
);
915 showNameAction
->addTo(optionMenu
);
916 showRangeAction
->addTo(optionMenu
);
917 showDataAction
->addTo(optionMenu
);
918 optionMenu
->insertSeparator();
919 showAllAction
->addTo(optionMenu
);
920 showDebugAction
->addTo(optionMenu
);
923 QPopupMenu
* helpMenu
= new QPopupMenu(this);
924 menu
->insertSeparator();
925 menu
->insertItem("&Help", helpMenu
);
926 showIntroAction
->addTo(helpMenu
);
927 showAboutAction
->addTo(helpMenu
);
929 connect(configList
, SIGNAL(menuSelected(struct menu
*)),
930 SLOT(changeMenu(struct menu
*)));
931 connect(configList
, SIGNAL(parentSelected()),
933 connect(menuList
, SIGNAL(menuSelected(struct menu
*)),
934 SLOT(changeMenu(struct menu
*)));
936 connect(configList
, SIGNAL(gotFocus(void)),
937 SLOT(listFocusChanged(void)));
938 connect(menuList
, SIGNAL(gotFocus(void)),
939 SLOT(listFocusChanged(void)));
941 #if QT_VERSION >= 300
942 QString listMode
= configSettings
->readEntry("/kconfig/qconf/listMode", "symbol");
943 if (listMode
== "single")
945 else if (listMode
== "full")
947 else /*if (listMode == "split")*/
950 // UI setup done, restore splitter positions
951 QValueList
<int> sizes
= configSettings
->readSizes("/kconfig/qconf/split1", &ok
);
953 split1
->setSizes(sizes
);
955 sizes
= configSettings
->readSizes("/kconfig/qconf/split2", &ok
);
957 split2
->setSizes(sizes
);
961 delete configSettings
;
964 static QString
print_filter(const char *str
)
966 QRegExp
re("[<>&\"\\n]");
968 for (int i
= 0; (i
= res
.find(re
, i
)) >= 0;) {
969 switch (res
[i
].latin1()) {
971 res
.replace(i
, 1, "<");
975 res
.replace(i
, 1, ">");
979 res
.replace(i
, 1, "&");
983 res
.replace(i
, 1, """);
987 res
.replace(i
, 1, "<br>");
995 static void expr_print_help(void *data
, const char *str
)
997 ((QString
*)data
)->append(print_filter(str
));
1001 * display a new help entry as soon as a new menu entry is selected
1003 void ConfigMainWindow::setHelp(QListViewItem
* item
)
1006 struct menu
* menu
= 0;
1008 configList
->parent()->lineEdit
->hide();
1010 menu
= ((ConfigItem
*)item
)->menu
;
1012 helpText
->setText(NULL
);
1016 QString head
, debug
, help
;
1017 menu
= ((ConfigItem
*)item
)->menu
;
1022 head
+= print_filter(menu
->prompt
->text
);
1023 head
+= "</b></big>";
1026 head
+= print_filter(sym
->name
);
1029 } else if (sym
->name
) {
1031 head
+= print_filter(sym
->name
);
1032 head
+= "</b></big>";
1038 debug
+= print_filter(sym_type_name(sym
->type
));
1039 if (sym_is_choice(sym
))
1040 debug
+= " (choice)";
1042 if (sym
->rev_dep
.expr
) {
1043 debug
+= "reverse dep: ";
1044 expr_print(sym
->rev_dep
.expr
, expr_print_help
, &debug
, E_NONE
);
1047 for (struct property
*prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1048 switch (prop
->type
) {
1051 debug
+= "prompt: ";
1052 debug
+= print_filter(prop
->text
);
1056 debug
+= "default: ";
1057 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1061 if (sym_is_choice(sym
)) {
1062 debug
+= "choice: ";
1063 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1068 debug
+= "select: ";
1069 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1074 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1078 debug
+= "unknown property: ";
1079 debug
+= prop_get_type_name(prop
->type
);
1082 if (prop
->visible
.expr
) {
1083 debug
+= " dep: ";
1084 expr_print(prop
->visible
.expr
, expr_print_help
, &debug
, E_NONE
);
1091 help
= print_filter(sym
->help
);
1092 } else if (menu
->prompt
) {
1094 head
+= print_filter(menu
->prompt
->text
);
1095 head
+= "</b></big><br><br>";
1097 if (menu
->prompt
->visible
.expr
) {
1098 debug
+= " dep: ";
1099 expr_print(menu
->prompt
->visible
.expr
, expr_print_help
, &debug
, E_NONE
);
1100 debug
+= "<br><br>";
1105 debug
+= QString().sprintf("defined at %s:%d<br><br>", menu
->file
->name
, menu
->lineno
);
1106 helpText
->setText(head
+ debug
+ help
);
1109 void ConfigMainWindow::loadConfig(void)
1111 QString s
= QFileDialog::getOpenFileName(".config", NULL
, this);
1114 if (conf_read(s
.latin1()))
1115 QMessageBox::information(this, "qconf", "Unable to load configuration!");
1116 ConfigView::updateListAll();
1119 void ConfigMainWindow::saveConfig(void)
1121 if (conf_write(NULL
))
1122 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1125 void ConfigMainWindow::saveConfigAs(void)
1127 QString s
= QFileDialog::getSaveFileName(".config", NULL
, this);
1130 if (conf_write(s
.latin1()))
1131 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1134 void ConfigMainWindow::changeMenu(struct menu
*menu
)
1136 configList
->setRootMenu(menu
);
1137 backAction
->setEnabled(TRUE
);
1140 void ConfigMainWindow::listFocusChanged(void)
1142 if (menuList
->hasFocus()) {
1143 if (menuList
->mode
== menuMode
)
1144 configList
->clearSelection();
1145 setHelp(menuList
->selectedItem());
1146 } else if (configList
->hasFocus()) {
1147 setHelp(configList
->selectedItem());
1151 void ConfigMainWindow::goBack(void)
1155 configList
->setParentMenu();
1156 if (configList
->rootEntry
== &rootmenu
)
1157 backAction
->setEnabled(FALSE
);
1158 item
= (ConfigItem
*)menuList
->selectedItem();
1160 if (item
->menu
== configList
->rootEntry
) {
1161 menuList
->setSelected(item
, TRUE
);
1164 item
= (ConfigItem
*)item
->parent();
1168 void ConfigMainWindow::showSingleView(void)
1171 menuList
->setRootMenu(0);
1172 configList
->mode
= singleMode
;
1173 if (configList
->rootEntry
== &rootmenu
)
1174 configList
->updateListAll();
1176 configList
->setRootMenu(&rootmenu
);
1177 configList
->setAllOpen(TRUE
);
1178 configList
->setFocus();
1181 void ConfigMainWindow::showSplitView(void)
1183 configList
->mode
= symbolMode
;
1184 if (configList
->rootEntry
== &rootmenu
)
1185 configList
->updateListAll();
1187 configList
->setRootMenu(&rootmenu
);
1188 configList
->setAllOpen(TRUE
);
1189 configApp
->processEvents();
1190 menuList
->mode
= menuMode
;
1191 menuList
->setRootMenu(&rootmenu
);
1192 menuList
->setAllOpen(TRUE
);
1194 menuList
->setFocus();
1197 void ConfigMainWindow::showFullView(void)
1200 menuList
->setRootMenu(0);
1201 configList
->mode
= fullMode
;
1202 if (configList
->rootEntry
== &rootmenu
)
1203 configList
->updateListAll();
1205 configList
->setRootMenu(&rootmenu
);
1206 configList
->setAllOpen(FALSE
);
1207 configList
->setFocus();
1210 void ConfigMainWindow::setShowAll(bool b
)
1212 if (configList
->showAll
== b
)
1214 configList
->showAll
= b
;
1215 configList
->updateListAll();
1216 menuList
->showAll
= b
;
1217 menuList
->updateListAll();
1220 void ConfigMainWindow::setShowDebug(bool b
)
1227 void ConfigMainWindow::setShowName(bool b
)
1229 if (configList
->showName
== b
)
1231 configList
->showName
= b
;
1232 configList
->reinit();
1233 menuList
->showName
= b
;
1237 void ConfigMainWindow::setShowRange(bool b
)
1239 if (configList
->showRange
== b
)
1241 configList
->showRange
= b
;
1242 configList
->reinit();
1243 menuList
->showRange
= b
;
1247 void ConfigMainWindow::setShowData(bool b
)
1249 if (configList
->showData
== b
)
1251 configList
->showData
= b
;
1252 configList
->reinit();
1253 menuList
->showData
= b
;
1258 * ask for saving configuration before quitting
1259 * TODO ask only when something changed
1261 void ConfigMainWindow::closeEvent(QCloseEvent
* e
)
1263 if (!sym_change_count
) {
1267 QMessageBox
mb("qconf", "Save configuration?", QMessageBox::Warning
,
1268 QMessageBox::Yes
| QMessageBox::Default
, QMessageBox::No
, QMessageBox::Cancel
| QMessageBox::Escape
);
1269 mb
.setButtonText(QMessageBox::Yes
, "&Save Changes");
1270 mb
.setButtonText(QMessageBox::No
, "&Discard Changes");
1271 mb
.setButtonText(QMessageBox::Cancel
, "Cancel Exit");
1272 switch (mb
.exec()) {
1273 case QMessageBox::Yes
:
1275 case QMessageBox::No
:
1278 case QMessageBox::Cancel
:
1284 void ConfigMainWindow::showIntro(void)
1286 static char str
[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
1287 "For each option, a blank box indicates the feature is disabled, a check\n"
1288 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1289 "as a module. Clicking on the box will cycle through the three states.\n\n"
1290 "If you do not see an option (e.g., a device driver) that you believe\n"
1291 "should be present, try turning on Show All Options under the Options menu.\n"
1292 "Although there is no cross reference yet to help you figure out what other\n"
1293 "options must be enabled to support the option you are interested in, you can\n"
1294 "still view the help of a grayed-out option.\n\n"
1295 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1296 "which you can then match by examining other options.\n\n";
1298 QMessageBox::information(this, "qconf", str
);
1301 void ConfigMainWindow::showAbout(void)
1303 static char str
[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1304 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
1306 QMessageBox::information(this, "qconf", str
);
1309 void ConfigMainWindow::saveSettings(void)
1311 #if QT_VERSION >= 300
1312 ConfigSettings
*configSettings
= new ConfigSettings
;
1313 configSettings
->writeEntry("/kconfig/qconf/window x", pos().x());
1314 configSettings
->writeEntry("/kconfig/qconf/window y", pos().y());
1315 configSettings
->writeEntry("/kconfig/qconf/window width", size().width());
1316 configSettings
->writeEntry("/kconfig/qconf/window height", size().height());
1317 configSettings
->writeEntry("/kconfig/qconf/showName", configList
->showName
);
1318 configSettings
->writeEntry("/kconfig/qconf/showRange", configList
->showRange
);
1319 configSettings
->writeEntry("/kconfig/qconf/showData", configList
->showData
);
1320 configSettings
->writeEntry("/kconfig/qconf/showAll", configList
->showAll
);
1321 configSettings
->writeEntry("/kconfig/qconf/showDebug", showDebug
);
1324 switch(configList
->mode
) {
1337 configSettings
->writeEntry("/kconfig/qconf/listMode", entry
);
1339 configSettings
->writeSizes("/kconfig/qconf/split1", split1
->sizes());
1340 configSettings
->writeSizes("/kconfig/qconf/split2", split2
->sizes());
1342 delete configSettings
;
1346 void fixup_rootmenu(struct menu
*menu
)
1349 static int menu_cnt
= 0;
1351 menu
->flags
|= MENU_ROOT
;
1352 for (child
= menu
->list
; child
; child
= child
->next
) {
1353 if (child
->prompt
&& child
->prompt
->type
== P_MENU
) {
1355 fixup_rootmenu(child
);
1357 } else if (!menu_cnt
)
1358 fixup_rootmenu(child
);
1362 static const char *progname
;
1364 static void usage(void)
1366 printf("%s <config>\n", progname
);
1370 int main(int ac
, char** av
)
1372 ConfigMainWindow
* v
;
1375 #ifndef LKC_DIRECT_LINK
1380 configApp
= new QApplication(ac
, av
);
1381 if (ac
> 1 && av
[1][0] == '-') {
1394 fixup_rootmenu(&rootmenu
);
1396 //zconfdump(stdout);
1398 v
= new ConfigMainWindow();
1400 //zconfdump(stdout);
1402 configApp
->connect(configApp
, SIGNAL(lastWindowClosed()), SLOT(quit()));
1403 configApp
->connect(configApp
, SIGNAL(aboutToQuit()), v
, SLOT(saveSettings()));