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(NULL
, "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(NULL
, "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(NULL
, "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(NULL
,"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)
1266 int x
, y
, width
, height
;
1268 QWidget
*d
= configApp
->desktop();
1270 width
= configSettings
->readNumEntry("/window width", d
->width() - 64);
1271 height
= configSettings
->readNumEntry("/window height", d
->height() - 64);
1272 resize(width
, height
);
1273 x
= configSettings
->readNumEntry("/window x", 0, &ok
);
1275 y
= configSettings
->readNumEntry("/window y", 0, &ok
);
1279 split1
= new QSplitter(this);
1280 split1
->setOrientation(QSplitter::Horizontal
);
1281 setCentralWidget(split1
);
1283 menuView
= new ConfigView(split1
, "menu");
1284 menuList
= menuView
->list
;
1286 split2
= new QSplitter(split1
);
1287 split2
->setOrientation(QSplitter::Vertical
);
1289 // create config tree
1290 configView
= new ConfigView(split2
, "config");
1291 configList
= configView
->list
;
1293 helpText
= new ConfigInfoView(split2
, "help");
1294 helpText
->setTextFormat(Qt::RichText
);
1296 setTabOrder(configList
, helpText
);
1297 configList
->setFocus();
1300 toolBar
= new QToolBar("Tools", this);
1302 backAction
= new QAction("Back", QPixmap(xpm_back
), "Back", 0, this);
1303 connect(backAction
, SIGNAL(activated()), SLOT(goBack()));
1304 backAction
->setEnabled(FALSE
);
1305 QAction
*quitAction
= new QAction("Quit", "&Quit", CTRL
+Key_Q
, this);
1306 connect(quitAction
, SIGNAL(activated()), SLOT(close()));
1307 QAction
*loadAction
= new QAction("Load", QPixmap(xpm_load
), "&Load", CTRL
+Key_L
, this);
1308 connect(loadAction
, SIGNAL(activated()), SLOT(loadConfig()));
1309 QAction
*saveAction
= new QAction("Save", QPixmap(xpm_save
), "&Save", CTRL
+Key_S
, this);
1310 connect(saveAction
, SIGNAL(activated()), SLOT(saveConfig()));
1311 QAction
*saveAsAction
= new QAction("Save As...", "Save &As...", 0, this);
1312 connect(saveAsAction
, SIGNAL(activated()), SLOT(saveConfigAs()));
1313 QAction
*searchAction
= new QAction("Search", "&Search", CTRL
+Key_F
, this);
1314 connect(searchAction
, SIGNAL(activated()), SLOT(searchConfig()));
1315 QAction
*singleViewAction
= new QAction("Single View", QPixmap(xpm_single_view
), "Split View", 0, this);
1316 connect(singleViewAction
, SIGNAL(activated()), SLOT(showSingleView()));
1317 QAction
*splitViewAction
= new QAction("Split View", QPixmap(xpm_split_view
), "Split View", 0, this);
1318 connect(splitViewAction
, SIGNAL(activated()), SLOT(showSplitView()));
1319 QAction
*fullViewAction
= new QAction("Full View", QPixmap(xpm_tree_view
), "Full View", 0, this);
1320 connect(fullViewAction
, SIGNAL(activated()), SLOT(showFullView()));
1322 QAction
*showNameAction
= new QAction(NULL
, "Show Name", 0, this);
1323 showNameAction
->setToggleAction(TRUE
);
1324 connect(showNameAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowName(bool)));
1325 connect(configView
, SIGNAL(showNameChanged(bool)), showNameAction
, SLOT(setOn(bool)));
1326 showNameAction
->setOn(configView
->showName());
1327 QAction
*showRangeAction
= new QAction(NULL
, "Show Range", 0, this);
1328 showRangeAction
->setToggleAction(TRUE
);
1329 connect(showRangeAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowRange(bool)));
1330 connect(configView
, SIGNAL(showRangeChanged(bool)), showRangeAction
, SLOT(setOn(bool)));
1331 showRangeAction
->setOn(configList
->showRange
);
1332 QAction
*showDataAction
= new QAction(NULL
, "Show Data", 0, this);
1333 showDataAction
->setToggleAction(TRUE
);
1334 connect(showDataAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowData(bool)));
1335 connect(configView
, SIGNAL(showDataChanged(bool)), showDataAction
, SLOT(setOn(bool)));
1336 showDataAction
->setOn(configList
->showData
);
1337 QAction
*showAllAction
= new QAction(NULL
, "Show All Options", 0, this);
1338 showAllAction
->setToggleAction(TRUE
);
1339 connect(showAllAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowAll(bool)));
1340 connect(showAllAction
, SIGNAL(toggled(bool)), menuView
, SLOT(setShowAll(bool)));
1341 showAllAction
->setOn(configList
->showAll
);
1342 QAction
*showDebugAction
= new QAction(NULL
, "Show Debug Info", 0, this);
1343 showDebugAction
->setToggleAction(TRUE
);
1344 connect(showDebugAction
, SIGNAL(toggled(bool)), helpText
, SLOT(setShowDebug(bool)));
1345 connect(helpText
, SIGNAL(showDebugChanged(bool)), showDebugAction
, SLOT(setOn(bool)));
1346 showDebugAction
->setOn(helpText
->showDebug());
1348 QAction
*showIntroAction
= new QAction(NULL
, "Introduction", 0, this);
1349 connect(showIntroAction
, SIGNAL(activated()), SLOT(showIntro()));
1350 QAction
*showAboutAction
= new QAction(NULL
, "About", 0, this);
1351 connect(showAboutAction
, SIGNAL(activated()), SLOT(showAbout()));
1354 backAction
->addTo(toolBar
);
1355 toolBar
->addSeparator();
1356 loadAction
->addTo(toolBar
);
1357 saveAction
->addTo(toolBar
);
1358 toolBar
->addSeparator();
1359 singleViewAction
->addTo(toolBar
);
1360 splitViewAction
->addTo(toolBar
);
1361 fullViewAction
->addTo(toolBar
);
1363 // create config menu
1364 QPopupMenu
* config
= new QPopupMenu(this);
1365 menu
->insertItem("&File", config
);
1366 loadAction
->addTo(config
);
1367 saveAction
->addTo(config
);
1368 saveAsAction
->addTo(config
);
1369 config
->insertSeparator();
1370 searchAction
->addTo(config
);
1371 config
->insertSeparator();
1372 quitAction
->addTo(config
);
1374 // create options menu
1375 QPopupMenu
* optionMenu
= new QPopupMenu(this);
1376 menu
->insertItem("&Option", optionMenu
);
1377 showNameAction
->addTo(optionMenu
);
1378 showRangeAction
->addTo(optionMenu
);
1379 showDataAction
->addTo(optionMenu
);
1380 optionMenu
->insertSeparator();
1381 showAllAction
->addTo(optionMenu
);
1382 showDebugAction
->addTo(optionMenu
);
1385 QPopupMenu
* helpMenu
= new QPopupMenu(this);
1386 menu
->insertSeparator();
1387 menu
->insertItem("&Help", helpMenu
);
1388 showIntroAction
->addTo(helpMenu
);
1389 showAboutAction
->addTo(helpMenu
);
1391 connect(configList
, SIGNAL(menuChanged(struct menu
*)),
1392 helpText
, SLOT(setInfo(struct menu
*)));
1393 connect(configList
, SIGNAL(menuSelected(struct menu
*)),
1394 SLOT(changeMenu(struct menu
*)));
1395 connect(configList
, SIGNAL(parentSelected()),
1397 connect(menuList
, SIGNAL(menuChanged(struct menu
*)),
1398 helpText
, SLOT(setInfo(struct menu
*)));
1399 connect(menuList
, SIGNAL(menuSelected(struct menu
*)),
1400 SLOT(changeMenu(struct menu
*)));
1402 connect(configList
, SIGNAL(gotFocus(struct menu
*)),
1403 helpText
, SLOT(setInfo(struct menu
*)));
1404 connect(menuList
, SIGNAL(gotFocus(struct menu
*)),
1405 helpText
, SLOT(setInfo(struct menu
*)));
1406 connect(menuList
, SIGNAL(gotFocus(struct menu
*)),
1407 SLOT(listFocusChanged(void)));
1408 connect(helpText
, SIGNAL(menuSelected(struct menu
*)),
1409 SLOT(setMenuLink(struct menu
*)));
1411 QString listMode
= configSettings
->readEntry("/listMode", "symbol");
1412 if (listMode
== "single")
1414 else if (listMode
== "full")
1416 else /*if (listMode == "split")*/
1419 // UI setup done, restore splitter positions
1420 QValueList
<int> sizes
= configSettings
->readSizes("/split1", &ok
);
1422 split1
->setSizes(sizes
);
1424 sizes
= configSettings
->readSizes("/split2", &ok
);
1426 split2
->setSizes(sizes
);
1429 void ConfigMainWindow::loadConfig(void)
1431 QString s
= QFileDialog::getOpenFileName(".config", NULL
, this);
1434 if (conf_read(QFile::encodeName(s
)))
1435 QMessageBox::information(this, "qconf", "Unable to load configuration!");
1436 ConfigView::updateListAll();
1439 void ConfigMainWindow::saveConfig(void)
1441 if (conf_write(NULL
))
1442 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1445 void ConfigMainWindow::saveConfigAs(void)
1447 QString s
= QFileDialog::getSaveFileName(".config", NULL
, this);
1450 if (conf_write(QFile::encodeName(s
)))
1451 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1454 void ConfigMainWindow::searchConfig(void)
1457 searchWindow
= new ConfigSearchWindow(this, "search");
1458 searchWindow
->show();
1461 void ConfigMainWindow::changeMenu(struct menu
*menu
)
1463 configList
->setRootMenu(menu
);
1464 backAction
->setEnabled(TRUE
);
1467 void ConfigMainWindow::setMenuLink(struct menu
*menu
)
1469 struct menu
*parent
;
1470 ConfigList
* list
= NULL
;
1473 if (!menu_is_visible(menu
) && !configView
->showAll())
1476 switch (configList
->mode
) {
1479 parent
= menu_get_parent_menu(menu
);
1482 list
->setRootMenu(parent
);
1485 if (menu
->flags
& MENU_ROOT
) {
1486 configList
->setRootMenu(menu
);
1487 configList
->clearSelection();
1491 parent
= menu_get_parent_menu(menu
->parent
);
1494 item
= menuList
->findConfigItem(parent
);
1496 menuList
->setSelected(item
, TRUE
);
1497 menuList
->ensureItemVisible(item
);
1499 list
->setRootMenu(parent
);
1508 item
= list
->findConfigItem(menu
);
1510 list
->setSelected(item
, TRUE
);
1511 list
->ensureItemVisible(item
);
1517 void ConfigMainWindow::listFocusChanged(void)
1519 if (menuList
->mode
== menuMode
)
1520 configList
->clearSelection();
1523 void ConfigMainWindow::goBack(void)
1527 configList
->setParentMenu();
1528 if (configList
->rootEntry
== &rootmenu
)
1529 backAction
->setEnabled(FALSE
);
1530 item
= (ConfigItem
*)menuList
->selectedItem();
1532 if (item
->menu
== configList
->rootEntry
) {
1533 menuList
->setSelected(item
, TRUE
);
1536 item
= (ConfigItem
*)item
->parent();
1540 void ConfigMainWindow::showSingleView(void)
1543 menuList
->setRootMenu(0);
1544 configList
->mode
= singleMode
;
1545 if (configList
->rootEntry
== &rootmenu
)
1546 configList
->updateListAll();
1548 configList
->setRootMenu(&rootmenu
);
1549 configList
->setAllOpen(TRUE
);
1550 configList
->setFocus();
1553 void ConfigMainWindow::showSplitView(void)
1555 configList
->mode
= symbolMode
;
1556 if (configList
->rootEntry
== &rootmenu
)
1557 configList
->updateListAll();
1559 configList
->setRootMenu(&rootmenu
);
1560 configList
->setAllOpen(TRUE
);
1561 configApp
->processEvents();
1562 menuList
->mode
= menuMode
;
1563 menuList
->setRootMenu(&rootmenu
);
1564 menuList
->setAllOpen(TRUE
);
1566 menuList
->setFocus();
1569 void ConfigMainWindow::showFullView(void)
1572 menuList
->setRootMenu(0);
1573 configList
->mode
= fullMode
;
1574 if (configList
->rootEntry
== &rootmenu
)
1575 configList
->updateListAll();
1577 configList
->setRootMenu(&rootmenu
);
1578 configList
->setAllOpen(FALSE
);
1579 configList
->setFocus();
1583 * ask for saving configuration before quitting
1584 * TODO ask only when something changed
1586 void ConfigMainWindow::closeEvent(QCloseEvent
* e
)
1588 if (!sym_change_count
) {
1592 QMessageBox
mb("qconf", "Save configuration?", QMessageBox::Warning
,
1593 QMessageBox::Yes
| QMessageBox::Default
, QMessageBox::No
, QMessageBox::Cancel
| QMessageBox::Escape
);
1594 mb
.setButtonText(QMessageBox::Yes
, "&Save Changes");
1595 mb
.setButtonText(QMessageBox::No
, "&Discard Changes");
1596 mb
.setButtonText(QMessageBox::Cancel
, "Cancel Exit");
1597 switch (mb
.exec()) {
1598 case QMessageBox::Yes
:
1600 case QMessageBox::No
:
1603 case QMessageBox::Cancel
:
1609 void ConfigMainWindow::showIntro(void)
1611 static char str
[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
1612 "For each option, a blank box indicates the feature is disabled, a check\n"
1613 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1614 "as a module. Clicking on the box will cycle through the three states.\n\n"
1615 "If you do not see an option (e.g., a device driver) that you believe\n"
1616 "should be present, try turning on Show All Options under the Options menu.\n"
1617 "Although there is no cross reference yet to help you figure out what other\n"
1618 "options must be enabled to support the option you are interested in, you can\n"
1619 "still view the help of a grayed-out option.\n\n"
1620 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1621 "which you can then match by examining other options.\n\n";
1623 QMessageBox::information(this, "qconf", str
);
1626 void ConfigMainWindow::showAbout(void)
1628 static char str
[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1629 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
1631 QMessageBox::information(this, "qconf", str
);
1634 void ConfigMainWindow::saveSettings(void)
1636 configSettings
->writeEntry("/window x", pos().x());
1637 configSettings
->writeEntry("/window y", pos().y());
1638 configSettings
->writeEntry("/window width", size().width());
1639 configSettings
->writeEntry("/window height", size().height());
1642 switch(configList
->mode
) {
1655 configSettings
->writeEntry("/listMode", entry
);
1657 configSettings
->writeSizes("/split1", split1
->sizes());
1658 configSettings
->writeSizes("/split2", split2
->sizes());
1661 void fixup_rootmenu(struct menu
*menu
)
1664 static int menu_cnt
= 0;
1666 menu
->flags
|= MENU_ROOT
;
1667 for (child
= menu
->list
; child
; child
= child
->next
) {
1668 if (child
->prompt
&& child
->prompt
->type
== P_MENU
) {
1670 fixup_rootmenu(child
);
1672 } else if (!menu_cnt
)
1673 fixup_rootmenu(child
);
1677 static const char *progname
;
1679 static void usage(void)
1681 printf("%s <config>\n", progname
);
1685 int main(int ac
, char** av
)
1687 ConfigMainWindow
* v
;
1690 bindtextdomain(PACKAGE
, LOCALEDIR
);
1691 textdomain(PACKAGE
);
1693 #ifndef LKC_DIRECT_LINK
1698 configApp
= new QApplication(ac
, av
);
1699 if (ac
> 1 && av
[1][0] == '-') {
1712 fixup_rootmenu(&rootmenu
);
1714 //zconfdump(stdout);
1716 configSettings
= new ConfigSettings();
1717 configSettings
->beginGroup("/kconfig/qconf");
1718 v
= new ConfigMainWindow();
1720 //zconfdump(stdout);
1721 configApp
->setMainWidget(v
);
1722 configApp
->connect(configApp
, SIGNAL(lastWindowClosed()), SLOT(quit()));
1723 configApp
->connect(configApp
, SIGNAL(aboutToQuit()), v
, SLOT(saveSettings()));
1727 configSettings
->endGroup();
1728 delete configSettings
;
This page took 0.072023 seconds and 6 git commands to generate.