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>
11 #include <qsplitter.h>
12 #include <qlistview.h>
13 #include <qtextbrowser.h>
14 #include <qlineedit.h>
16 #include <qpushbutton.h>
18 #include <qmessagebox.h>
21 #include <qfiledialog.h>
22 #include <qdragobject.h>
38 static QApplication
*configApp
;
39 static ConfigSettings
*configSettings
;
41 static inline QString
qgettext(const char* str
)
43 return QString::fromLocal8Bit(gettext(str
));
46 static inline QString
qgettext(const QString
& str
)
48 return QString::fromLocal8Bit(gettext(str
.latin1()));
52 * Reads a list of integer values from the application settings.
54 QValueList
<int> ConfigSettings::readSizes(const QString
& key
, bool *ok
)
56 QValueList
<int> result
;
57 QStringList entryList
= readListEntry(key
, ok
);
59 QStringList::Iterator it
;
60 for (it
= entryList
.begin(); it
!= entryList
.end(); ++it
)
61 result
.push_back((*it
).toInt());
68 * Writes a list of integer values to the application settings.
70 bool ConfigSettings::writeSizes(const QString
& key
, const QValueList
<int>& value
)
72 QStringList stringList
;
73 QValueList
<int>::ConstIterator it
;
75 for (it
= value
.begin(); it
!= value
.end(); ++it
)
76 stringList
.push_back(QString::number(*it
));
77 return writeEntry(key
, stringList
);
84 * TODO check the value
86 void ConfigItem::okRename(int col
)
88 Parent::okRename(col
);
89 sym_set_string_value(menu
->sym
, text(dataColIdx
).latin1());
94 * update the displayed of a menu entry
96 void ConfigItem::updateMenu(void)
100 struct property
*prop
;
107 setPixmap(promptColIdx
, list
->menuBackPix
);
114 prompt
= QString::fromLocal8Bit(menu_get_prompt(menu
));
116 if (prop
) switch (prop
->type
) {
118 if (list
->mode
== singleMode
|| list
->mode
== symbolMode
) {
119 /* a menuconfig entry is displayed differently
120 * depending whether it's at the view root or a child.
122 if (sym
&& list
->rootEntry
== menu
)
124 setPixmap(promptColIdx
, list
->menuPix
);
128 setPixmap(promptColIdx
, 0);
132 setPixmap(promptColIdx
, 0);
140 setText(nameColIdx
, QString::fromLocal8Bit(sym
->name
));
142 type
= sym_get_type(sym
);
148 if (!sym_is_changable(sym
) && !list
->showAll
) {
149 setPixmap(promptColIdx
, 0);
150 setText(noColIdx
, QString::null
);
151 setText(modColIdx
, QString::null
);
152 setText(yesColIdx
, QString::null
);
155 expr
= sym_get_tristate_value(sym
);
158 if (sym_is_choice_value(sym
) && type
== S_BOOLEAN
)
159 setPixmap(promptColIdx
, list
->choiceYesPix
);
161 setPixmap(promptColIdx
, list
->symbolYesPix
);
162 setText(yesColIdx
, "Y");
166 setPixmap(promptColIdx
, list
->symbolModPix
);
167 setText(modColIdx
, "M");
171 if (sym_is_choice_value(sym
) && type
== S_BOOLEAN
)
172 setPixmap(promptColIdx
, list
->choiceNoPix
);
174 setPixmap(promptColIdx
, list
->symbolNoPix
);
175 setText(noColIdx
, "N");
180 setText(noColIdx
, sym_tristate_within_range(sym
, no
) ? "_" : 0);
182 setText(modColIdx
, sym_tristate_within_range(sym
, mod
) ? "_" : 0);
184 setText(yesColIdx
, sym_tristate_within_range(sym
, yes
) ? "_" : 0);
186 setText(dataColIdx
, QChar(ch
));
193 data
= sym_get_string_value(sym
);
195 #if QT_VERSION >= 300
196 int i
= list
->mapIdx(dataColIdx
);
198 setRenameEnabled(i
, TRUE
);
200 setText(dataColIdx
, data
);
201 if (type
== S_STRING
)
202 prompt
= QString("%1: %2").arg(prompt
).arg(data
);
204 prompt
= QString("(%2) %1").arg(prompt
).arg(data
);
207 if (!sym_has_value(sym
) && visible
)
210 setText(promptColIdx
, prompt
);
213 void ConfigItem::testUpdateMenu(bool v
)
221 sym_calc_value(menu
->sym
);
222 if (menu
->flags
& MENU_CHANGED
) {
223 /* the menu entry changed, so update all list items */
224 menu
->flags
&= ~MENU_CHANGED
;
225 for (i
= (ConfigItem
*)menu
->data
; i
; i
= i
->nextItem
)
227 } else if (listView()->updateAll
)
231 void ConfigItem::paintCell(QPainter
* p
, const QColorGroup
& cg
, int column
, int width
, int align
)
233 ConfigList
* list
= listView();
236 if (isSelected() && !list
->hasFocus() && list
->mode
== menuMode
)
237 Parent::paintCell(p
, list
->inactivedColorGroup
, column
, width
, align
);
239 Parent::paintCell(p
, cg
, column
, width
, align
);
241 Parent::paintCell(p
, list
->disabledColorGroup
, column
, width
, align
);
245 * construct a menu entry
247 void ConfigItem::init(void)
250 ConfigList
* list
= listView();
251 nextItem
= (ConfigItem
*)menu
->data
;
254 if (list
->mode
!= fullMode
)
256 sym_calc_value(menu
->sym
);
262 * destruct a menu entry
264 ConfigItem::~ConfigItem(void)
267 ConfigItem
** ip
= (ConfigItem
**)&menu
->data
;
268 for (; *ip
; ip
= &(*ip
)->nextItem
) {
277 ConfigLineEdit::ConfigLineEdit(ConfigView
* parent
)
280 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
283 void ConfigLineEdit::show(ConfigItem
* i
)
286 if (sym_get_string_value(item
->menu
->sym
))
287 setText(QString::fromLocal8Bit(sym_get_string_value(item
->menu
->sym
)));
289 setText(QString::null
);
294 void ConfigLineEdit::keyPressEvent(QKeyEvent
* e
)
301 sym_set_string_value(item
->menu
->sym
, text().latin1());
302 parent()->updateList(item
);
305 Parent::keyPressEvent(e
);
309 parent()->list
->setFocus();
313 ConfigList::ConfigList(ConfigView
* p
, const char *name
)
316 symbolYesPix(xpm_symbol_yes
), symbolModPix(xpm_symbol_mod
), symbolNoPix(xpm_symbol_no
),
317 choiceYesPix(xpm_choice_yes
), choiceNoPix(xpm_choice_no
),
318 menuPix(xpm_menu
), menuInvPix(xpm_menu_inv
), menuBackPix(xpm_menuback
), voidPix(xpm_void
),
319 showAll(false), showName(false), showRange(false), showData(false),
320 rootEntry(0), headerPopup(0)
325 setRootIsDecorated(TRUE
);
326 disabledColorGroup
= palette().active();
327 disabledColorGroup
.setColor(QColorGroup::Text
, palette().disabled().text());
328 inactivedColorGroup
= palette().active();
329 inactivedColorGroup
.setColor(QColorGroup::Highlight
, palette().disabled().highlight());
331 connect(this, SIGNAL(selectionChanged(void)),
332 SLOT(updateSelection(void)));
335 configSettings
->beginGroup(name
);
336 showAll
= configSettings
->readBoolEntry("/showAll", false);
337 showName
= configSettings
->readBoolEntry("/showName", false);
338 showRange
= configSettings
->readBoolEntry("/showRange", false);
339 showData
= configSettings
->readBoolEntry("/showData", false);
340 configSettings
->endGroup();
341 connect(configApp
, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
344 for (i
= 0; i
< colNr
; i
++)
345 colMap
[i
] = colRevMap
[i
] = -1;
346 addColumn(promptColIdx
, "Option");
351 void ConfigList::reinit(void)
353 removeColumn(dataColIdx
);
354 removeColumn(yesColIdx
);
355 removeColumn(modColIdx
);
356 removeColumn(noColIdx
);
357 removeColumn(nameColIdx
);
360 addColumn(nameColIdx
, "Name");
362 addColumn(noColIdx
, "N");
363 addColumn(modColIdx
, "M");
364 addColumn(yesColIdx
, "Y");
367 addColumn(dataColIdx
, "Value");
372 void ConfigList::saveSettings(void)
375 configSettings
->beginGroup(name());
376 configSettings
->writeEntry("/showName", showName
);
377 configSettings
->writeEntry("/showRange", showRange
);
378 configSettings
->writeEntry("/showData", showData
);
379 configSettings
->writeEntry("/showAll", showAll
);
380 configSettings
->endGroup();
384 ConfigItem
* ConfigList::findConfigItem(struct menu
*menu
)
386 ConfigItem
* item
= (ConfigItem
*)menu
->data
;
388 for (; item
; item
= item
->nextItem
) {
389 if (this == item
->listView())
396 void ConfigList::updateSelection(void)
401 ConfigItem
* item
= (ConfigItem
*)selectedItem();
406 emit
menuChanged(menu
);
409 type
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
410 if (mode
== menuMode
&& type
== P_MENU
)
411 emit
menuSelected(menu
);
414 void ConfigList::updateList(ConfigItem
* item
)
416 ConfigItem
* last
= 0;
419 if (mode
!= listMode
)
421 QListViewItemIterator
it(this);
424 for (; it
.current(); ++it
) {
425 item
= (ConfigItem
*)it
.current();
428 item
->testUpdateMenu(menu_is_visible(item
->menu
));
433 if (rootEntry
!= &rootmenu
&& (mode
== singleMode
||
434 (mode
== symbolMode
&& rootEntry
->parent
!= &rootmenu
))) {
437 item
= new ConfigItem(this, 0, true);
440 if ((mode
== singleMode
|| (mode
== symbolMode
&& !(rootEntry
->flags
& MENU_ROOT
))) &&
441 rootEntry
->sym
&& rootEntry
->prompt
) {
442 item
= last
? last
->nextSibling() : firstChild();
444 item
= new ConfigItem(this, last
, rootEntry
, true);
446 item
->testUpdateMenu(true);
448 updateMenuList(item
, rootEntry
);
453 updateMenuList(this, rootEntry
);
457 void ConfigList::setValue(ConfigItem
* item
, tristate val
)
463 sym
= item
->menu
? item
->menu
->sym
: 0;
467 type
= sym_get_type(sym
);
471 oldval
= sym_get_tristate_value(sym
);
473 if (!sym_set_tristate_value(sym
, val
))
475 if (oldval
== no
&& item
->menu
->list
)
477 parent()->updateList(item
);
482 void ConfigList::changeValue(ConfigItem
* item
)
486 int type
, oldexpr
, newexpr
;
493 if (item
->menu
->list
)
494 item
->setOpen(!item
->isOpen());
498 type
= sym_get_type(sym
);
502 oldexpr
= sym_get_tristate_value(sym
);
503 newexpr
= sym_toggle_tristate_value(sym
);
504 if (item
->menu
->list
) {
505 if (oldexpr
== newexpr
)
506 item
->setOpen(!item
->isOpen());
507 else if (oldexpr
== no
)
510 if (oldexpr
!= newexpr
)
511 parent()->updateList(item
);
516 #if QT_VERSION >= 300
517 if (colMap
[dataColIdx
] >= 0)
518 item
->startRename(colMap
[dataColIdx
]);
521 parent()->lineEdit
->show(item
);
526 void ConfigList::setRootMenu(struct menu
*menu
)
530 if (rootEntry
== menu
)
532 type
= menu
&& menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
535 updateMenuList(this, 0);
538 setSelected(currentItem(), hasFocus());
539 ensureItemVisible(currentItem());
542 void ConfigList::setParentMenu(void)
545 struct menu
*oldroot
;
548 if (rootEntry
== &rootmenu
)
550 setRootMenu(menu_get_parent_menu(rootEntry
->parent
));
552 QListViewItemIterator
it(this);
553 for (; (item
= (ConfigItem
*)it
.current()); it
++) {
554 if (item
->menu
== oldroot
) {
555 setCurrentItem(item
);
556 ensureItemVisible(item
);
563 * update all the children of a menu entry
564 * removes/adds the entries from the parent widget as necessary
566 * parent: either the menu list widget or a menu entry widget
567 * menu: entry to be updated
570 void ConfigList::updateMenuList(P
* parent
, struct menu
* menu
)
579 while ((item
= parent
->firstChild()))
584 last
= parent
->firstChild();
585 if (last
&& !last
->goParent
)
587 for (child
= menu
->list
; child
; child
= child
->next
) {
588 item
= last
? last
->nextSibling() : parent
->firstChild();
589 type
= child
->prompt
? child
->prompt
->type
: P_UNKNOWN
;
593 if (!(child
->flags
& MENU_ROOT
))
597 if (child
->flags
& MENU_ROOT
)
604 visible
= menu_is_visible(child
);
605 if (showAll
|| visible
) {
606 if (!item
|| item
->menu
!= child
)
607 item
= new ConfigItem(parent
, last
, child
, visible
);
609 item
->testUpdateMenu(visible
);
611 if (mode
== fullMode
|| mode
== menuMode
|| type
!= P_MENU
)
612 updateMenuList(item
, child
);
614 updateMenuList(item
, 0);
619 if (item
&& item
->menu
== child
) {
620 last
= parent
->firstChild();
623 else while (last
->nextSibling() != item
)
624 last
= last
->nextSibling();
630 void ConfigList::keyPressEvent(QKeyEvent
* ev
)
632 QListViewItem
* i
= currentItem();
637 if (ev
->key() == Key_Escape
&& mode
!= fullMode
&& mode
!= listMode
) {
638 emit
parentSelected();
644 Parent::keyPressEvent(ev
);
647 item
= (ConfigItem
*)i
;
652 if (item
->goParent
) {
653 emit
parentSelected();
659 type
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
660 if (type
== P_MENU
&& rootEntry
!= menu
&&
661 mode
!= fullMode
&& mode
!= menuMode
) {
662 emit
menuSelected(menu
);
678 Parent::keyPressEvent(ev
);
684 void ConfigList::contentsMousePressEvent(QMouseEvent
* e
)
686 //QPoint p(contentsToViewport(e->pos()));
687 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
688 Parent::contentsMousePressEvent(e
);
691 void ConfigList::contentsMouseReleaseEvent(QMouseEvent
* e
)
693 QPoint
p(contentsToViewport(e
->pos()));
694 ConfigItem
* item
= (ConfigItem
*)itemAt(p
);
696 enum prop_type ptype
;
704 x
= header()->offset() + p
.x();
705 idx
= colRevMap
[header()->sectionAt(x
)];
708 pm
= item
->pixmap(promptColIdx
);
710 int off
= header()->sectionPos(0) + itemMargin() +
711 treeStepSize() * (item
->depth() + (rootIsDecorated() ? 1 : 0));
712 if (x
>= off
&& x
< off
+ pm
->width()) {
713 if (item
->goParent
) {
714 emit
parentSelected();
718 ptype
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
719 if (ptype
== P_MENU
&& rootEntry
!= menu
&&
720 mode
!= fullMode
&& mode
!= menuMode
)
721 emit
menuSelected(menu
);
742 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
743 Parent::contentsMouseReleaseEvent(e
);
746 void ConfigList::contentsMouseMoveEvent(QMouseEvent
* e
)
748 //QPoint p(contentsToViewport(e->pos()));
749 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
750 Parent::contentsMouseMoveEvent(e
);
753 void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent
* e
)
755 QPoint
p(contentsToViewport(e
->pos()));
756 ConfigItem
* item
= (ConfigItem
*)itemAt(p
);
758 enum prop_type ptype
;
762 if (item
->goParent
) {
763 emit
parentSelected();
769 ptype
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
770 if (ptype
== P_MENU
&& (mode
== singleMode
|| mode
== symbolMode
))
771 emit
menuSelected(menu
);
776 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
777 Parent::contentsMouseDoubleClickEvent(e
);
780 void ConfigList::focusInEvent(QFocusEvent
*e
)
782 struct menu
*menu
= NULL
;
784 Parent::focusInEvent(e
);
786 ConfigItem
* item
= (ConfigItem
*)currentItem();
788 setSelected(item
, TRUE
);
794 void ConfigList::contextMenuEvent(QContextMenuEvent
*e
)
796 if (e
->y() <= header()->geometry().bottom()) {
800 headerPopup
= new QPopupMenu(this);
801 action
= new QAction("Show Name", 0, this);
802 action
->setToggleAction(TRUE
);
803 connect(action
, SIGNAL(toggled(bool)),
804 parent(), SLOT(setShowName(bool)));
805 connect(parent(), SIGNAL(showNameChanged(bool)),
806 action
, SLOT(setOn(bool)));
807 action
->setOn(showName
);
808 action
->addTo(headerPopup
);
809 action
= new QAction("Show Range", 0, this);
810 action
->setToggleAction(TRUE
);
811 connect(action
, SIGNAL(toggled(bool)),
812 parent(), SLOT(setShowRange(bool)));
813 connect(parent(), SIGNAL(showRangeChanged(bool)),
814 action
, SLOT(setOn(bool)));
815 action
->setOn(showRange
);
816 action
->addTo(headerPopup
);
817 action
= new QAction("Show Data", 0, this);
818 action
->setToggleAction(TRUE
);
819 connect(action
, SIGNAL(toggled(bool)),
820 parent(), SLOT(setShowData(bool)));
821 connect(parent(), SIGNAL(showDataChanged(bool)),
822 action
, SLOT(setOn(bool)));
823 action
->setOn(showData
);
824 action
->addTo(headerPopup
);
826 headerPopup
->exec(e
->globalPos());
832 ConfigView
* ConfigView::viewList
;
834 ConfigView::ConfigView(QWidget
* parent
, const char *name
)
835 : Parent(parent
, name
)
837 list
= new ConfigList(this, name
);
838 lineEdit
= new ConfigLineEdit(this);
841 this->nextView
= viewList
;
845 ConfigView::~ConfigView(void)
849 for (vp
= &viewList
; *vp
; vp
= &(*vp
)->nextView
) {
857 void ConfigView::setShowAll(bool b
)
859 if (list
->showAll
!= b
) {
861 list
->updateListAll();
862 emit
showAllChanged(b
);
866 void ConfigView::setShowName(bool b
)
868 if (list
->showName
!= b
) {
871 emit
showNameChanged(b
);
875 void ConfigView::setShowRange(bool b
)
877 if (list
->showRange
!= b
) {
880 emit
showRangeChanged(b
);
884 void ConfigView::setShowData(bool b
)
886 if (list
->showData
!= b
) {
889 emit
showDataChanged(b
);
893 void ConfigList::setAllOpen(bool open
)
895 QListViewItemIterator
it(this);
897 for (; it
.current(); it
++)
898 it
.current()->setOpen(open
);
901 void ConfigView::updateList(ConfigItem
* item
)
905 for (v
= viewList
; v
; v
= v
->nextView
)
906 v
->list
->updateList(item
);
909 void ConfigView::updateListAll(void)
913 for (v
= viewList
; v
; v
= v
->nextView
)
914 v
->list
->updateListAll();
917 ConfigInfoView::ConfigInfoView(QWidget
* parent
, const char *name
)
918 : Parent(parent
, name
), menu(0)
921 configSettings
->beginGroup(name
);
922 _showDebug
= configSettings
->readBoolEntry("/showDebug", false);
923 configSettings
->endGroup();
924 connect(configApp
, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
928 void ConfigInfoView::saveSettings(void)
931 configSettings
->beginGroup(name());
932 configSettings
->writeEntry("/showDebug", showDebug());
933 configSettings
->endGroup();
937 void ConfigInfoView::setShowDebug(bool b
)
939 if (_showDebug
!= b
) {
945 emit
showDebugChanged(b
);
949 void ConfigInfoView::setInfo(struct menu
*m
)
960 void ConfigInfoView::setSource(const QString
& name
)
962 const char *p
= name
.latin1();
971 if (sscanf(p
, "m%p", &m
) == 1 && menu
!= m
) {
974 emit
menuSelected(menu
);
980 if (sscanf(p
, "s%p", &s
) == 1 && sym
!= s
) {
988 void ConfigInfoView::symbolInfo(void)
992 str
+= "<big>Symbol: <b>";
993 str
+= print_filter(sym
->name
);
994 str
+= "</b></big><br><br>value: ";
995 str
+= print_filter(sym_get_string_value(sym
));
996 str
+= "<br>visibility: ";
997 str
+= sym
->visible
== yes
? "y" : sym
->visible
== mod
? "m" : "n";
999 str
+= debug_info(sym
);
1004 void ConfigInfoView::menuInfo(void)
1007 QString head
, debug
, help
;
1013 head
+= print_filter(_(menu
->prompt
->text
));
1014 head
+= "</b></big>";
1018 head
+= QString().sprintf("<a href=\"s%p\">", sym
);
1019 head
+= print_filter(sym
->name
);
1024 } else if (sym
->name
) {
1027 head
+= QString().sprintf("<a href=\"s%p\">", sym
);
1028 head
+= print_filter(sym
->name
);
1031 head
+= "</b></big>";
1036 debug
= debug_info(sym
);
1038 help
= print_filter(_(sym
->help
));
1039 } else if (menu
->prompt
) {
1041 head
+= print_filter(_(menu
->prompt
->text
));
1042 head
+= "</b></big><br><br>";
1044 if (menu
->prompt
->visible
.expr
) {
1045 debug
+= " dep: ";
1046 expr_print(menu
->prompt
->visible
.expr
, expr_print_help
, &debug
, E_NONE
);
1047 debug
+= "<br><br>";
1052 debug
+= QString().sprintf("defined at %s:%d<br><br>", menu
->file
->name
, menu
->lineno
);
1054 setText(head
+ debug
+ help
);
1057 QString
ConfigInfoView::debug_info(struct symbol
*sym
)
1062 debug
+= print_filter(sym_type_name(sym
->type
));
1063 if (sym_is_choice(sym
))
1064 debug
+= " (choice)";
1066 if (sym
->rev_dep
.expr
) {
1067 debug
+= "reverse dep: ";
1068 expr_print(sym
->rev_dep
.expr
, expr_print_help
, &debug
, E_NONE
);
1071 for (struct property
*prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1072 switch (prop
->type
) {
1075 debug
+= QString().sprintf("prompt: <a href=\"m%p\">", prop
->menu
);
1076 debug
+= print_filter(_(prop
->text
));
1077 debug
+= "</a><br>";
1080 debug
+= "default: ";
1081 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1085 if (sym_is_choice(sym
)) {
1086 debug
+= "choice: ";
1087 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1092 debug
+= "select: ";
1093 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1098 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1102 debug
+= "unknown property: ";
1103 debug
+= prop_get_type_name(prop
->type
);
1106 if (prop
->visible
.expr
) {
1107 debug
+= " dep: ";
1108 expr_print(prop
->visible
.expr
, expr_print_help
, &debug
, E_NONE
);
1117 QString
ConfigInfoView::print_filter(const QString
&str
)
1119 QRegExp
re("[<>&\"\\n]");
1121 for (int i
= 0; (i
= res
.find(re
, i
)) >= 0;) {
1122 switch (res
[i
].latin1()) {
1124 res
.replace(i
, 1, "<");
1128 res
.replace(i
, 1, ">");
1132 res
.replace(i
, 1, "&");
1136 res
.replace(i
, 1, """);
1140 res
.replace(i
, 1, "<br>");
1148 void ConfigInfoView::expr_print_help(void *data
, struct symbol
*sym
, const char *str
)
1150 QString
* text
= reinterpret_cast<QString
*>(data
);
1151 QString str2
= print_filter(str
);
1153 if (sym
&& sym
->name
&& !(sym
->flags
& SYMBOL_CONST
)) {
1154 *text
+= QString().sprintf("<a href=\"s%p\">", sym
);
1161 QPopupMenu
* ConfigInfoView::createPopupMenu(const QPoint
& pos
)
1163 QPopupMenu
* popup
= Parent::createPopupMenu(pos
);
1164 QAction
* action
= new QAction("Show Debug Info", 0, popup
);
1165 action
->setToggleAction(TRUE
);
1166 connect(action
, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1167 connect(this, SIGNAL(showDebugChanged(bool)), action
, SLOT(setOn(bool)));
1168 action
->setOn(showDebug());
1169 popup
->insertSeparator();
1170 action
->addTo(popup
);
1174 void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent
*e
)
1176 Parent::contentsContextMenuEvent(e
);
1179 ConfigSearchWindow::ConfigSearchWindow(QWidget
* parent
, const char *name
)
1180 : Parent(parent
, name
), result(NULL
)
1182 setCaption("Search Config");
1184 QVBoxLayout
* layout1
= new QVBoxLayout(this, 11, 6);
1185 QHBoxLayout
* layout2
= new QHBoxLayout(0, 0, 6);
1186 layout2
->addWidget(new QLabel("Find:", this));
1187 editField
= new QLineEdit(this);
1188 connect(editField
, SIGNAL(returnPressed()), SLOT(search()));
1189 layout2
->addWidget(editField
);
1190 searchButton
= new QPushButton("Search", this);
1191 searchButton
->setAutoDefault(FALSE
);
1192 connect(searchButton
, SIGNAL(clicked()), SLOT(search()));
1193 layout2
->addWidget(searchButton
);
1194 layout1
->addLayout(layout2
);
1196 split
= new QSplitter(this);
1197 split
->setOrientation(QSplitter::Vertical
);
1198 list
= new ConfigView(split
, name
);
1199 list
->list
->mode
= listMode
;
1200 info
= new ConfigInfoView(split
, name
);
1201 connect(list
->list
, SIGNAL(menuChanged(struct menu
*)),
1202 info
, SLOT(setInfo(struct menu
*)));
1203 layout1
->addWidget(split
);
1206 int x
, y
, width
, height
;
1209 configSettings
->beginGroup(name
);
1210 width
= configSettings
->readNumEntry("/window width", parent
->width() / 2);
1211 height
= configSettings
->readNumEntry("/window height", parent
->height() / 2);
1212 resize(width
, height
);
1213 x
= configSettings
->readNumEntry("/window x", 0, &ok
);
1215 y
= configSettings
->readNumEntry("/window y", 0, &ok
);
1218 QValueList
<int> sizes
= configSettings
->readSizes("/split", &ok
);
1220 split
->setSizes(sizes
);
1221 configSettings
->endGroup();
1222 connect(configApp
, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1226 void ConfigSearchWindow::saveSettings(void)
1229 configSettings
->beginGroup(name());
1230 configSettings
->writeEntry("/window x", pos().x());
1231 configSettings
->writeEntry("/window y", pos().y());
1232 configSettings
->writeEntry("/window width", size().width());
1233 configSettings
->writeEntry("/window height", size().height());
1234 configSettings
->writeSizes("/split", split
->sizes());
1235 configSettings
->endGroup();
1239 void ConfigSearchWindow::search(void)
1242 struct property
*prop
;
1243 ConfigItem
*lastItem
= NULL
;
1246 list
->list
->clear();
1248 result
= sym_re_search(editField
->text().latin1());
1251 for (p
= result
; *p
; p
++) {
1252 for_all_prompts((*p
), prop
)
1253 lastItem
= new ConfigItem(list
->list
, lastItem
, prop
->menu
,
1254 menu_is_visible(prop
->menu
));
1259 * Construct the complete config widget
1261 ConfigMainWindow::ConfigMainWindow(void)
1265 int x
, y
, width
, height
;
1267 QWidget
*d
= configApp
->desktop();
1269 width
= configSettings
->readNumEntry("/window width", d
->width() - 64);
1270 height
= configSettings
->readNumEntry("/window height", d
->height() - 64);
1271 resize(width
, height
);
1272 x
= configSettings
->readNumEntry("/window x", 0, &ok
);
1274 y
= configSettings
->readNumEntry("/window y", 0, &ok
);
1278 split1
= new QSplitter(this);
1279 split1
->setOrientation(QSplitter::Horizontal
);
1280 setCentralWidget(split1
);
1282 menuView
= new ConfigView(split1
, "menu");
1283 menuList
= menuView
->list
;
1285 split2
= new QSplitter(split1
);
1286 split2
->setOrientation(QSplitter::Vertical
);
1288 // create config tree
1289 configView
= new ConfigView(split2
, "config");
1290 configList
= configView
->list
;
1292 helpText
= new ConfigInfoView(split2
, "help");
1293 helpText
->setTextFormat(Qt::RichText
);
1295 setTabOrder(configList
, helpText
);
1296 configList
->setFocus();
1299 toolBar
= new QToolBar("Tools", this);
1301 backAction
= new QAction("Back", QPixmap(xpm_back
), "Back", 0, this);
1302 connect(backAction
, SIGNAL(activated()), SLOT(goBack()));
1303 backAction
->setEnabled(FALSE
);
1304 QAction
*quitAction
= new QAction("Quit", "&Quit", CTRL
+Key_Q
, this);
1305 connect(quitAction
, SIGNAL(activated()), SLOT(close()));
1306 QAction
*loadAction
= new QAction("Load", QPixmap(xpm_load
), "&Load", CTRL
+Key_L
, this);
1307 connect(loadAction
, SIGNAL(activated()), SLOT(loadConfig()));
1308 QAction
*saveAction
= new QAction("Save", QPixmap(xpm_save
), "&Save", CTRL
+Key_S
, this);
1309 connect(saveAction
, SIGNAL(activated()), SLOT(saveConfig()));
1310 QAction
*saveAsAction
= new QAction("Save As...", "Save &As...", 0, this);
1311 connect(saveAsAction
, SIGNAL(activated()), SLOT(saveConfigAs()));
1312 QAction
*searchAction
= new QAction("Search", "&Search", CTRL
+Key_F
, this);
1313 connect(searchAction
, SIGNAL(activated()), SLOT(searchConfig()));
1314 QAction
*singleViewAction
= new QAction("Single View", QPixmap(xpm_single_view
), "Split View", 0, this);
1315 connect(singleViewAction
, SIGNAL(activated()), SLOT(showSingleView()));
1316 QAction
*splitViewAction
= new QAction("Split View", QPixmap(xpm_split_view
), "Split View", 0, this);
1317 connect(splitViewAction
, SIGNAL(activated()), SLOT(showSplitView()));
1318 QAction
*fullViewAction
= new QAction("Full View", QPixmap(xpm_tree_view
), "Full View", 0, this);
1319 connect(fullViewAction
, SIGNAL(activated()), SLOT(showFullView()));
1321 QAction
*showNameAction
= new QAction(NULL
, "Show Name", 0, this);
1322 showNameAction
->setToggleAction(TRUE
);
1323 connect(showNameAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowName(bool)));
1324 connect(configView
, SIGNAL(showNameChanged(bool)), showNameAction
, SLOT(setOn(bool)));
1325 showNameAction
->setOn(configView
->showName());
1326 QAction
*showRangeAction
= new QAction(NULL
, "Show Range", 0, this);
1327 showRangeAction
->setToggleAction(TRUE
);
1328 connect(showRangeAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowRange(bool)));
1329 connect(configView
, SIGNAL(showRangeChanged(bool)), showRangeAction
, SLOT(setOn(bool)));
1330 showRangeAction
->setOn(configList
->showRange
);
1331 QAction
*showDataAction
= new QAction(NULL
, "Show Data", 0, this);
1332 showDataAction
->setToggleAction(TRUE
);
1333 connect(showDataAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowData(bool)));
1334 connect(configView
, SIGNAL(showDataChanged(bool)), showDataAction
, SLOT(setOn(bool)));
1335 showDataAction
->setOn(configList
->showData
);
1336 QAction
*showAllAction
= new QAction(NULL
, "Show All Options", 0, this);
1337 showAllAction
->setToggleAction(TRUE
);
1338 connect(showAllAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowAll(bool)));
1339 connect(showAllAction
, SIGNAL(toggled(bool)), menuView
, SLOT(setShowAll(bool)));
1340 showAllAction
->setOn(configList
->showAll
);
1341 QAction
*showDebugAction
= new QAction(NULL
, "Show Debug Info", 0, this);
1342 showDebugAction
->setToggleAction(TRUE
);
1343 connect(showDebugAction
, SIGNAL(toggled(bool)), helpText
, SLOT(setShowDebug(bool)));
1344 connect(helpText
, SIGNAL(showDebugChanged(bool)), showDebugAction
, SLOT(setOn(bool)));
1345 showDebugAction
->setOn(helpText
->showDebug());
1347 QAction
*showIntroAction
= new QAction(NULL
, "Introduction", 0, this);
1348 connect(showIntroAction
, SIGNAL(activated()), SLOT(showIntro()));
1349 QAction
*showAboutAction
= new QAction(NULL
, "About", 0, this);
1350 connect(showAboutAction
, SIGNAL(activated()), SLOT(showAbout()));
1353 backAction
->addTo(toolBar
);
1354 toolBar
->addSeparator();
1355 loadAction
->addTo(toolBar
);
1356 saveAction
->addTo(toolBar
);
1357 toolBar
->addSeparator();
1358 singleViewAction
->addTo(toolBar
);
1359 splitViewAction
->addTo(toolBar
);
1360 fullViewAction
->addTo(toolBar
);
1362 // create config menu
1363 QPopupMenu
* config
= new QPopupMenu(this);
1364 menu
->insertItem("&File", config
);
1365 loadAction
->addTo(config
);
1366 saveAction
->addTo(config
);
1367 saveAsAction
->addTo(config
);
1368 config
->insertSeparator();
1369 searchAction
->addTo(config
);
1370 config
->insertSeparator();
1371 quitAction
->addTo(config
);
1373 // create options menu
1374 QPopupMenu
* optionMenu
= new QPopupMenu(this);
1375 menu
->insertItem("&Option", optionMenu
);
1376 showNameAction
->addTo(optionMenu
);
1377 showRangeAction
->addTo(optionMenu
);
1378 showDataAction
->addTo(optionMenu
);
1379 optionMenu
->insertSeparator();
1380 showAllAction
->addTo(optionMenu
);
1381 showDebugAction
->addTo(optionMenu
);
1384 QPopupMenu
* helpMenu
= new QPopupMenu(this);
1385 menu
->insertSeparator();
1386 menu
->insertItem("&Help", helpMenu
);
1387 showIntroAction
->addTo(helpMenu
);
1388 showAboutAction
->addTo(helpMenu
);
1390 connect(configList
, SIGNAL(menuChanged(struct menu
*)),
1391 helpText
, SLOT(setInfo(struct menu
*)));
1392 connect(configList
, SIGNAL(menuSelected(struct menu
*)),
1393 SLOT(changeMenu(struct menu
*)));
1394 connect(configList
, SIGNAL(parentSelected()),
1396 connect(menuList
, SIGNAL(menuChanged(struct menu
*)),
1397 helpText
, SLOT(setInfo(struct menu
*)));
1398 connect(menuList
, SIGNAL(menuSelected(struct menu
*)),
1399 SLOT(changeMenu(struct menu
*)));
1401 connect(configList
, SIGNAL(gotFocus(struct menu
*)),
1402 helpText
, SLOT(setInfo(struct menu
*)));
1403 connect(menuList
, SIGNAL(gotFocus(struct menu
*)),
1404 helpText
, SLOT(setInfo(struct menu
*)));
1405 connect(menuList
, SIGNAL(gotFocus(struct menu
*)),
1406 SLOT(listFocusChanged(void)));
1407 connect(helpText
, SIGNAL(menuSelected(struct menu
*)),
1408 SLOT(setMenuLink(struct menu
*)));
1410 QString listMode
= configSettings
->readEntry("/listMode", "symbol");
1411 if (listMode
== "single")
1413 else if (listMode
== "full")
1415 else /*if (listMode == "split")*/
1418 // UI setup done, restore splitter positions
1419 QValueList
<int> sizes
= configSettings
->readSizes("/split1", &ok
);
1421 split1
->setSizes(sizes
);
1423 sizes
= configSettings
->readSizes("/split2", &ok
);
1425 split2
->setSizes(sizes
);
1428 void ConfigMainWindow::loadConfig(void)
1430 QString s
= QFileDialog::getOpenFileName(".config", NULL
, this);
1433 if (conf_read(QFile::encodeName(s
)))
1434 QMessageBox::information(this, "qconf", "Unable to load configuration!");
1435 ConfigView::updateListAll();
1438 void ConfigMainWindow::saveConfig(void)
1440 if (conf_write(NULL
))
1441 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1444 void ConfigMainWindow::saveConfigAs(void)
1446 QString s
= QFileDialog::getSaveFileName(".config", NULL
, this);
1449 if (conf_write(QFile::encodeName(s
)))
1450 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1453 void ConfigMainWindow::searchConfig(void)
1456 searchWindow
= new ConfigSearchWindow(this, "search");
1457 searchWindow
->show();
1460 void ConfigMainWindow::changeMenu(struct menu
*menu
)
1462 configList
->setRootMenu(menu
);
1463 backAction
->setEnabled(TRUE
);
1466 void ConfigMainWindow::setMenuLink(struct menu
*menu
)
1468 struct menu
*parent
;
1469 ConfigList
* list
= NULL
;
1472 if (!menu_is_visible(menu
) && !configView
->showAll())
1475 switch (configList
->mode
) {
1478 parent
= menu_get_parent_menu(menu
);
1481 list
->setRootMenu(parent
);
1484 if (menu
->flags
& MENU_ROOT
) {
1485 configList
->setRootMenu(menu
);
1486 configList
->clearSelection();
1490 parent
= menu_get_parent_menu(menu
->parent
);
1493 item
= menuList
->findConfigItem(parent
);
1495 menuList
->setSelected(item
, TRUE
);
1496 menuList
->ensureItemVisible(item
);
1498 list
->setRootMenu(parent
);
1507 item
= list
->findConfigItem(menu
);
1509 list
->setSelected(item
, TRUE
);
1510 list
->ensureItemVisible(item
);
1516 void ConfigMainWindow::listFocusChanged(void)
1518 if (menuList
->mode
== menuMode
)
1519 configList
->clearSelection();
1522 void ConfigMainWindow::goBack(void)
1526 configList
->setParentMenu();
1527 if (configList
->rootEntry
== &rootmenu
)
1528 backAction
->setEnabled(FALSE
);
1529 item
= (ConfigItem
*)menuList
->selectedItem();
1531 if (item
->menu
== configList
->rootEntry
) {
1532 menuList
->setSelected(item
, TRUE
);
1535 item
= (ConfigItem
*)item
->parent();
1539 void ConfigMainWindow::showSingleView(void)
1542 menuList
->setRootMenu(0);
1543 configList
->mode
= singleMode
;
1544 if (configList
->rootEntry
== &rootmenu
)
1545 configList
->updateListAll();
1547 configList
->setRootMenu(&rootmenu
);
1548 configList
->setAllOpen(TRUE
);
1549 configList
->setFocus();
1552 void ConfigMainWindow::showSplitView(void)
1554 configList
->mode
= symbolMode
;
1555 if (configList
->rootEntry
== &rootmenu
)
1556 configList
->updateListAll();
1558 configList
->setRootMenu(&rootmenu
);
1559 configList
->setAllOpen(TRUE
);
1560 configApp
->processEvents();
1561 menuList
->mode
= menuMode
;
1562 menuList
->setRootMenu(&rootmenu
);
1563 menuList
->setAllOpen(TRUE
);
1565 menuList
->setFocus();
1568 void ConfigMainWindow::showFullView(void)
1571 menuList
->setRootMenu(0);
1572 configList
->mode
= fullMode
;
1573 if (configList
->rootEntry
== &rootmenu
)
1574 configList
->updateListAll();
1576 configList
->setRootMenu(&rootmenu
);
1577 configList
->setAllOpen(FALSE
);
1578 configList
->setFocus();
1582 * ask for saving configuration before quitting
1583 * TODO ask only when something changed
1585 void ConfigMainWindow::closeEvent(QCloseEvent
* e
)
1587 if (!sym_change_count
) {
1591 QMessageBox
mb("qconf", "Save configuration?", QMessageBox::Warning
,
1592 QMessageBox::Yes
| QMessageBox::Default
, QMessageBox::No
, QMessageBox::Cancel
| QMessageBox::Escape
);
1593 mb
.setButtonText(QMessageBox::Yes
, "&Save Changes");
1594 mb
.setButtonText(QMessageBox::No
, "&Discard Changes");
1595 mb
.setButtonText(QMessageBox::Cancel
, "Cancel Exit");
1596 switch (mb
.exec()) {
1597 case QMessageBox::Yes
:
1599 case QMessageBox::No
:
1602 case QMessageBox::Cancel
:
1608 void ConfigMainWindow::showIntro(void)
1610 static char str
[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
1611 "For each option, a blank box indicates the feature is disabled, a check\n"
1612 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1613 "as a module. Clicking on the box will cycle through the three states.\n\n"
1614 "If you do not see an option (e.g., a device driver) that you believe\n"
1615 "should be present, try turning on Show All Options under the Options menu.\n"
1616 "Although there is no cross reference yet to help you figure out what other\n"
1617 "options must be enabled to support the option you are interested in, you can\n"
1618 "still view the help of a grayed-out option.\n\n"
1619 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1620 "which you can then match by examining other options.\n\n";
1622 QMessageBox::information(this, "qconf", str
);
1625 void ConfigMainWindow::showAbout(void)
1627 static char str
[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1628 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
1630 QMessageBox::information(this, "qconf", str
);
1633 void ConfigMainWindow::saveSettings(void)
1635 configSettings
->writeEntry("/window x", pos().x());
1636 configSettings
->writeEntry("/window y", pos().y());
1637 configSettings
->writeEntry("/window width", size().width());
1638 configSettings
->writeEntry("/window height", size().height());
1641 switch(configList
->mode
) {
1654 configSettings
->writeEntry("/listMode", entry
);
1656 configSettings
->writeSizes("/split1", split1
->sizes());
1657 configSettings
->writeSizes("/split2", split2
->sizes());
1660 void fixup_rootmenu(struct menu
*menu
)
1663 static int menu_cnt
= 0;
1665 menu
->flags
|= MENU_ROOT
;
1666 for (child
= menu
->list
; child
; child
= child
->next
) {
1667 if (child
->prompt
&& child
->prompt
->type
== P_MENU
) {
1669 fixup_rootmenu(child
);
1671 } else if (!menu_cnt
)
1672 fixup_rootmenu(child
);
1676 static const char *progname
;
1678 static void usage(void)
1680 printf("%s <config>\n", progname
);
1684 int main(int ac
, char** av
)
1686 ConfigMainWindow
* v
;
1689 bindtextdomain(PACKAGE
, LOCALEDIR
);
1690 textdomain(PACKAGE
);
1692 #ifndef LKC_DIRECT_LINK
1697 configApp
= new QApplication(ac
, av
);
1698 if (ac
> 1 && av
[1][0] == '-') {
1711 fixup_rootmenu(&rootmenu
);
1713 //zconfdump(stdout);
1715 configSettings
= new ConfigSettings();
1716 configSettings
->beginGroup("/kconfig/qconf");
1717 v
= new ConfigMainWindow();
1719 //zconfdump(stdout);
1720 configApp
->setMainWidget(v
);
1721 configApp
->connect(configApp
, SIGNAL(lastWindowClosed()), SLOT(quit()));
1722 configApp
->connect(configApp
, SIGNAL(aboutToQuit()), v
, SLOT(saveSettings()));
1726 configSettings
->endGroup();
1727 delete configSettings
;