2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
10 #include <qtextbrowser.h>
13 #include <QFileDialog>
16 #include <qapplication.h>
17 #include <qdesktopwidget.h>
20 #include <qsplitter.h>
21 #include <qlineedit.h>
23 #include <qpushbutton.h>
25 #include <qmessagebox.h>
42 static QApplication
*configApp
;
43 static ConfigSettings
*configSettings
;
45 QAction
*ConfigMainWindow::saveAction
;
47 static inline QString
qgettext(const char* str
)
49 return QString::fromLocal8Bit(gettext(str
));
52 static inline QString
qgettext(const QString
& str
)
54 return QString::fromLocal8Bit(gettext(str
.latin1()));
57 ConfigSettings::ConfigSettings()
58 : QSettings("kernel.org", "qconf")
63 * Reads a list of integer values from the application settings.
65 QList
<int> ConfigSettings::readSizes(const QString
& key
, bool *ok
)
68 QStringList entryList
= readListEntry(key
, ok
);
69 QStringList::Iterator it
;
71 for (it
= entryList
.begin(); it
!= entryList
.end(); ++it
)
72 result
.push_back((*it
).toInt());
78 * Writes a list of integer values to the application settings.
80 bool ConfigSettings::writeSizes(const QString
& key
, const QList
<int>& value
)
82 QStringList stringList
;
83 QList
<int>::ConstIterator it
;
85 for (it
= value
.begin(); it
!= value
.end(); ++it
)
86 stringList
.push_back(QString::number(*it
));
87 return writeEntry(key
, stringList
);
93 * TODO check the value
95 void ConfigItem::okRename(int col
)
97 Parent::okRename(col
);
98 sym_set_string_value(menu
->sym
, text(dataColIdx
).latin1());
99 listView()->updateList(this);
103 * update the displayed of a menu entry
105 void ConfigItem::updateMenu(void)
109 struct property
*prop
;
116 setPixmap(promptColIdx
, list
->menuBackPix
);
123 prompt
= _(menu_get_prompt(menu
));
125 if (prop
) switch (prop
->type
) {
127 if (list
->mode
== singleMode
|| list
->mode
== symbolMode
) {
128 /* a menuconfig entry is displayed differently
129 * depending whether it's at the view root or a child.
131 if (sym
&& list
->rootEntry
== menu
)
133 setPixmap(promptColIdx
, list
->menuPix
);
137 setPixmap(promptColIdx
, 0);
141 setPixmap(promptColIdx
, 0);
149 setText(nameColIdx
, QString::fromLocal8Bit(sym
->name
));
151 type
= sym_get_type(sym
);
157 if (!sym_is_changable(sym
) && list
->optMode
== normalOpt
) {
158 setPixmap(promptColIdx
, 0);
159 setText(noColIdx
, QString::null
);
160 setText(modColIdx
, QString::null
);
161 setText(yesColIdx
, QString::null
);
164 expr
= sym_get_tristate_value(sym
);
167 if (sym_is_choice_value(sym
) && type
== S_BOOLEAN
)
168 setPixmap(promptColIdx
, list
->choiceYesPix
);
170 setPixmap(promptColIdx
, list
->symbolYesPix
);
171 setText(yesColIdx
, "Y");
175 setPixmap(promptColIdx
, list
->symbolModPix
);
176 setText(modColIdx
, "M");
180 if (sym_is_choice_value(sym
) && type
== S_BOOLEAN
)
181 setPixmap(promptColIdx
, list
->choiceNoPix
);
183 setPixmap(promptColIdx
, list
->symbolNoPix
);
184 setText(noColIdx
, "N");
189 setText(noColIdx
, sym_tristate_within_range(sym
, no
) ? "_" : 0);
191 setText(modColIdx
, sym_tristate_within_range(sym
, mod
) ? "_" : 0);
193 setText(yesColIdx
, sym_tristate_within_range(sym
, yes
) ? "_" : 0);
195 setText(dataColIdx
, QChar(ch
));
202 data
= sym_get_string_value(sym
);
204 int i
= list
->mapIdx(dataColIdx
);
206 setRenameEnabled(i
, TRUE
);
207 setText(dataColIdx
, data
);
208 if (type
== S_STRING
)
209 prompt
= QString("%1: %2").arg(prompt
).arg(data
);
211 prompt
= QString("(%2) %1").arg(prompt
).arg(data
);
214 if (!sym_has_value(sym
) && visible
)
215 prompt
+= _(" (NEW)");
217 setText(promptColIdx
, prompt
);
220 void ConfigItem::testUpdateMenu(bool v
)
228 sym_calc_value(menu
->sym
);
229 if (menu
->flags
& MENU_CHANGED
) {
230 /* the menu entry changed, so update all list items */
231 menu
->flags
&= ~MENU_CHANGED
;
232 for (i
= (ConfigItem
*)menu
->data
; i
; i
= i
->nextItem
)
234 } else if (listView()->updateAll
)
238 void ConfigItem::paintCell(QPainter
* p
, const QColorGroup
& cg
, int column
, int width
, int align
)
240 ConfigList
* list
= listView();
243 if (isSelected() && !list
->hasFocus() && list
->mode
== menuMode
)
244 Parent::paintCell(p
, list
->inactivedColorGroup
, column
, width
, align
);
246 Parent::paintCell(p
, cg
, column
, width
, align
);
248 Parent::paintCell(p
, list
->disabledColorGroup
, column
, width
, align
);
252 * construct a menu entry
254 void ConfigItem::init(void)
257 ConfigList
* list
= listView();
258 nextItem
= (ConfigItem
*)menu
->data
;
261 if (list
->mode
!= fullMode
)
263 sym_calc_value(menu
->sym
);
269 * destruct a menu entry
271 ConfigItem::~ConfigItem(void)
274 ConfigItem
** ip
= (ConfigItem
**)&menu
->data
;
275 for (; *ip
; ip
= &(*ip
)->nextItem
) {
284 ConfigLineEdit::ConfigLineEdit(ConfigView
* parent
)
287 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
290 void ConfigLineEdit::show(ConfigItem
* i
)
293 if (sym_get_string_value(item
->menu
->sym
))
294 setText(QString::fromLocal8Bit(sym_get_string_value(item
->menu
->sym
)));
296 setText(QString::null
);
301 void ConfigLineEdit::keyPressEvent(QKeyEvent
* e
)
308 sym_set_string_value(item
->menu
->sym
, text().latin1());
309 parent()->updateList(item
);
312 Parent::keyPressEvent(e
);
316 parent()->list
->setFocus();
320 ConfigList::ConfigList(ConfigView
* p
, const char *name
)
323 symbolYesPix(xpm_symbol_yes
), symbolModPix(xpm_symbol_mod
), symbolNoPix(xpm_symbol_no
),
324 choiceYesPix(xpm_choice_yes
), choiceNoPix(xpm_choice_no
),
325 menuPix(xpm_menu
), menuInvPix(xpm_menu_inv
), menuBackPix(xpm_menuback
), voidPix(xpm_void
),
326 showName(false), showRange(false), showData(false), optMode(normalOpt
),
327 rootEntry(0), headerPopup(0)
332 setRootIsDecorated(TRUE
);
333 disabledColorGroup
= palette().active();
334 disabledColorGroup
.setColor(QColorGroup::Text
, palette().disabled().text());
335 inactivedColorGroup
= palette().active();
336 inactivedColorGroup
.setColor(QColorGroup::Highlight
, palette().disabled().highlight());
338 connect(this, SIGNAL(selectionChanged(void)),
339 SLOT(updateSelection(void)));
342 configSettings
->beginGroup(name
);
343 showName
= configSettings
->readBoolEntry("/showName", false);
344 showRange
= configSettings
->readBoolEntry("/showRange", false);
345 showData
= configSettings
->readBoolEntry("/showData", false);
346 optMode
= (enum optionMode
)configSettings
->readNumEntry("/optionMode", false);
347 configSettings
->endGroup();
348 connect(configApp
, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
351 for (i
= 0; i
< colNr
; i
++)
352 colMap
[i
] = colRevMap
[i
] = -1;
353 addColumn(promptColIdx
, _("Option"));
358 bool ConfigList::menuSkip(struct menu
*menu
)
360 if (optMode
== normalOpt
&& menu_is_visible(menu
))
362 if (optMode
== promptOpt
&& menu_has_prompt(menu
))
364 if (optMode
== allOpt
)
369 void ConfigList::reinit(void)
371 removeColumn(dataColIdx
);
372 removeColumn(yesColIdx
);
373 removeColumn(modColIdx
);
374 removeColumn(noColIdx
);
375 removeColumn(nameColIdx
);
378 addColumn(nameColIdx
, _("Name"));
380 addColumn(noColIdx
, "N");
381 addColumn(modColIdx
, "M");
382 addColumn(yesColIdx
, "Y");
385 addColumn(dataColIdx
, _("Value"));
390 void ConfigList::saveSettings(void)
393 configSettings
->beginGroup(name());
394 configSettings
->writeEntry("/showName", showName
);
395 configSettings
->writeEntry("/showRange", showRange
);
396 configSettings
->writeEntry("/showData", showData
);
397 configSettings
->writeEntry("/optionMode", (int)optMode
);
398 configSettings
->endGroup();
402 ConfigItem
* ConfigList::findConfigItem(struct menu
*menu
)
404 ConfigItem
* item
= (ConfigItem
*)menu
->data
;
406 for (; item
; item
= item
->nextItem
) {
407 if (this == item
->listView())
414 void ConfigList::updateSelection(void)
419 ConfigItem
* item
= (ConfigItem
*)selectedItem();
424 emit
menuChanged(menu
);
427 type
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
428 if (mode
== menuMode
&& type
== P_MENU
)
429 emit
menuSelected(menu
);
432 void ConfigList::updateList(ConfigItem
* item
)
434 ConfigItem
* last
= 0;
437 if (mode
!= listMode
)
439 Q3ListViewItemIterator
it(this);
442 for (; it
.current(); ++it
) {
443 item
= (ConfigItem
*)it
.current();
446 item
->testUpdateMenu(menu_is_visible(item
->menu
));
451 if (rootEntry
!= &rootmenu
&& (mode
== singleMode
||
452 (mode
== symbolMode
&& rootEntry
->parent
!= &rootmenu
))) {
455 item
= new ConfigItem(this, 0, true);
458 if ((mode
== singleMode
|| (mode
== symbolMode
&& !(rootEntry
->flags
& MENU_ROOT
))) &&
459 rootEntry
->sym
&& rootEntry
->prompt
) {
460 item
= last
? last
->nextSibling() : firstChild();
462 item
= new ConfigItem(this, last
, rootEntry
, true);
464 item
->testUpdateMenu(true);
466 updateMenuList(item
, rootEntry
);
471 updateMenuList(this, rootEntry
);
475 void ConfigList::setValue(ConfigItem
* item
, tristate val
)
481 sym
= item
->menu
? item
->menu
->sym
: 0;
485 type
= sym_get_type(sym
);
489 oldval
= sym_get_tristate_value(sym
);
491 if (!sym_set_tristate_value(sym
, val
))
493 if (oldval
== no
&& item
->menu
->list
)
495 parent()->updateList(item
);
500 void ConfigList::changeValue(ConfigItem
* item
)
504 int type
, oldexpr
, newexpr
;
511 if (item
->menu
->list
)
512 item
->setOpen(!item
->isOpen());
516 type
= sym_get_type(sym
);
520 oldexpr
= sym_get_tristate_value(sym
);
521 newexpr
= sym_toggle_tristate_value(sym
);
522 if (item
->menu
->list
) {
523 if (oldexpr
== newexpr
)
524 item
->setOpen(!item
->isOpen());
525 else if (oldexpr
== no
)
528 if (oldexpr
!= newexpr
)
529 parent()->updateList(item
);
534 if (colMap
[dataColIdx
] >= 0)
535 item
->startRename(colMap
[dataColIdx
]);
537 parent()->lineEdit
->show(item
);
542 void ConfigList::setRootMenu(struct menu
*menu
)
546 if (rootEntry
== menu
)
548 type
= menu
&& menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
551 updateMenuList(this, 0);
554 setSelected(currentItem(), hasFocus());
555 ensureItemVisible(currentItem());
558 void ConfigList::setParentMenu(void)
561 struct menu
*oldroot
;
564 if (rootEntry
== &rootmenu
)
566 setRootMenu(menu_get_parent_menu(rootEntry
->parent
));
568 Q3ListViewItemIterator
it(this);
569 for (; (item
= (ConfigItem
*)it
.current()); it
++) {
570 if (item
->menu
== oldroot
) {
571 setCurrentItem(item
);
572 ensureItemVisible(item
);
579 * update all the children of a menu entry
580 * removes/adds the entries from the parent widget as necessary
582 * parent: either the menu list widget or a menu entry widget
583 * menu: entry to be updated
586 void ConfigList::updateMenuList(P
* parent
, struct menu
* menu
)
595 while ((item
= parent
->firstChild()))
600 last
= parent
->firstChild();
601 if (last
&& !last
->goParent
)
603 for (child
= menu
->list
; child
; child
= child
->next
) {
604 item
= last
? last
->nextSibling() : parent
->firstChild();
605 type
= child
->prompt
? child
->prompt
->type
: P_UNKNOWN
;
609 if (!(child
->flags
& MENU_ROOT
))
613 if (child
->flags
& MENU_ROOT
)
620 visible
= menu_is_visible(child
);
621 if (!menuSkip(child
)) {
622 if (!child
->sym
&& !child
->list
&& !child
->prompt
)
624 if (!item
|| item
->menu
!= child
)
625 item
= new ConfigItem(parent
, last
, child
, visible
);
627 item
->testUpdateMenu(visible
);
629 if (mode
== fullMode
|| mode
== menuMode
|| type
!= P_MENU
)
630 updateMenuList(item
, child
);
632 updateMenuList(item
, 0);
637 if (item
&& item
->menu
== child
) {
638 last
= parent
->firstChild();
641 else while (last
->nextSibling() != item
)
642 last
= last
->nextSibling();
648 void ConfigList::keyPressEvent(QKeyEvent
* ev
)
650 Q3ListViewItem
* i
= currentItem();
655 if (ev
->key() == Qt::Key_Escape
&& mode
!= fullMode
&& mode
!= listMode
) {
656 emit
parentSelected();
662 Parent::keyPressEvent(ev
);
665 item
= (ConfigItem
*)i
;
670 if (item
->goParent
) {
671 emit
parentSelected();
677 type
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
678 if (type
== P_MENU
&& rootEntry
!= menu
&&
679 mode
!= fullMode
&& mode
!= menuMode
) {
680 emit
menuSelected(menu
);
696 Parent::keyPressEvent(ev
);
702 void ConfigList::contentsMousePressEvent(QMouseEvent
* e
)
704 //QPoint p(contentsToViewport(e->pos()));
705 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
706 Parent::contentsMousePressEvent(e
);
709 void ConfigList::contentsMouseReleaseEvent(QMouseEvent
* e
)
711 QPoint
p(contentsToViewport(e
->pos()));
712 ConfigItem
* item
= (ConfigItem
*)itemAt(p
);
714 enum prop_type ptype
;
722 x
= header()->offset() + p
.x();
723 idx
= colRevMap
[header()->sectionAt(x
)];
726 pm
= item
->pixmap(promptColIdx
);
728 int off
= header()->sectionPos(0) + itemMargin() +
729 treeStepSize() * (item
->depth() + (rootIsDecorated() ? 1 : 0));
730 if (x
>= off
&& x
< off
+ pm
->width()) {
731 if (item
->goParent
) {
732 emit
parentSelected();
736 ptype
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
737 if (ptype
== P_MENU
&& rootEntry
!= menu
&&
738 mode
!= fullMode
&& mode
!= menuMode
)
739 emit
menuSelected(menu
);
760 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
761 Parent::contentsMouseReleaseEvent(e
);
764 void ConfigList::contentsMouseMoveEvent(QMouseEvent
* e
)
766 //QPoint p(contentsToViewport(e->pos()));
767 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
768 Parent::contentsMouseMoveEvent(e
);
771 void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent
* e
)
773 QPoint
p(contentsToViewport(e
->pos()));
774 ConfigItem
* item
= (ConfigItem
*)itemAt(p
);
776 enum prop_type ptype
;
780 if (item
->goParent
) {
781 emit
parentSelected();
787 ptype
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
788 if (ptype
== P_MENU
&& (mode
== singleMode
|| mode
== symbolMode
))
789 emit
menuSelected(menu
);
794 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
795 Parent::contentsMouseDoubleClickEvent(e
);
798 void ConfigList::focusInEvent(QFocusEvent
*e
)
800 struct menu
*menu
= NULL
;
802 Parent::focusInEvent(e
);
804 ConfigItem
* item
= (ConfigItem
*)currentItem();
806 setSelected(item
, TRUE
);
812 void ConfigList::contextMenuEvent(QContextMenuEvent
*e
)
814 if (e
->y() <= header()->geometry().bottom()) {
818 headerPopup
= new QMenu(this);
819 action
= new QAction(_("Show Name"), this);
820 action
->setToggleAction(TRUE
);
821 connect(action
, SIGNAL(toggled(bool)),
822 parent(), SLOT(setShowName(bool)));
823 connect(parent(), SIGNAL(showNameChanged(bool)),
824 action
, SLOT(setOn(bool)));
825 action
->setOn(showName
);
826 action
->addTo(headerPopup
);
827 action
= new QAction(_("Show Range"), this);
828 action
->setToggleAction(TRUE
);
829 connect(action
, SIGNAL(toggled(bool)),
830 parent(), SLOT(setShowRange(bool)));
831 connect(parent(), SIGNAL(showRangeChanged(bool)),
832 action
, SLOT(setOn(bool)));
833 action
->setOn(showRange
);
834 action
->addTo(headerPopup
);
835 action
= new QAction( _("Show Data"), this);
836 action
->setToggleAction(TRUE
);
837 connect(action
, SIGNAL(toggled(bool)),
838 parent(), SLOT(setShowData(bool)));
839 connect(parent(), SIGNAL(showDataChanged(bool)),
840 action
, SLOT(setOn(bool)));
841 action
->setOn(showData
);
842 action
->addTo(headerPopup
);
844 headerPopup
->exec(e
->globalPos());
850 ConfigView
*ConfigView::viewList
;
851 QAction
*ConfigView::showNormalAction
;
852 QAction
*ConfigView::showAllAction
;
853 QAction
*ConfigView::showPromptAction
;
855 ConfigView::ConfigView(QWidget
* parent
, const char *name
)
856 : Parent(parent
, name
)
858 QVBoxLayout
*verticalLayout
= new QVBoxLayout(this);
859 verticalLayout
->setContentsMargins(0, 0, 0, 0);
861 list
= new ConfigList(this, name
);
862 verticalLayout
->addWidget(list
);
863 lineEdit
= new ConfigLineEdit(this);
865 verticalLayout
->addWidget(lineEdit
);
867 this->nextView
= viewList
;
871 ConfigView::~ConfigView(void)
875 for (vp
= &viewList
; *vp
; vp
= &(*vp
)->nextView
) {
883 void ConfigView::setOptionMode(QAction
*act
)
885 if (act
== showNormalAction
)
886 list
->optMode
= normalOpt
;
887 else if (act
== showAllAction
)
888 list
->optMode
= allOpt
;
890 list
->optMode
= promptOpt
;
892 list
->updateListAll();
895 void ConfigView::setShowName(bool b
)
897 if (list
->showName
!= b
) {
900 emit
showNameChanged(b
);
904 void ConfigView::setShowRange(bool b
)
906 if (list
->showRange
!= b
) {
909 emit
showRangeChanged(b
);
913 void ConfigView::setShowData(bool b
)
915 if (list
->showData
!= b
) {
918 emit
showDataChanged(b
);
922 void ConfigList::setAllOpen(bool open
)
924 Q3ListViewItemIterator
it(this);
926 for (; it
.current(); it
++)
927 it
.current()->setOpen(open
);
930 void ConfigView::updateList(ConfigItem
* item
)
934 for (v
= viewList
; v
; v
= v
->nextView
)
935 v
->list
->updateList(item
);
938 void ConfigView::updateListAll(void)
942 for (v
= viewList
; v
; v
= v
->nextView
)
943 v
->list
->updateListAll();
946 ConfigInfoView::ConfigInfoView(QWidget
* parent
, const char *name
)
947 : Parent(parent
, name
), sym(0), _menu(0)
950 configSettings
->beginGroup(name
);
951 _showDebug
= configSettings
->readBoolEntry("/showDebug", false);
952 configSettings
->endGroup();
953 connect(configApp
, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
957 void ConfigInfoView::saveSettings(void)
960 configSettings
->beginGroup(name());
961 configSettings
->writeEntry("/showDebug", showDebug());
962 configSettings
->endGroup();
966 void ConfigInfoView::setShowDebug(bool b
)
968 if (_showDebug
!= b
) {
974 emit
showDebugChanged(b
);
978 void ConfigInfoView::setInfo(struct menu
*m
)
990 void ConfigInfoView::symbolInfo(void)
994 str
+= "<big>Symbol: <b>";
995 str
+= print_filter(sym
->name
);
996 str
+= "</b></big><br><br>value: ";
997 str
+= print_filter(sym_get_string_value(sym
));
998 str
+= "<br>visibility: ";
999 str
+= sym
->visible
== yes
? "y" : sym
->visible
== mod
? "m" : "n";
1001 str
+= debug_info(sym
);
1006 void ConfigInfoView::menuInfo(void)
1009 QString head
, debug
, help
;
1013 if (_menu
->prompt
) {
1015 head
+= print_filter(_(_menu
->prompt
->text
));
1016 head
+= "</b></big>";
1020 head
+= QString().sprintf("<a href=\"s%p\">", sym
);
1021 head
+= print_filter(sym
->name
);
1026 } else if (sym
->name
) {
1029 head
+= QString().sprintf("<a href=\"s%p\">", sym
);
1030 head
+= print_filter(sym
->name
);
1033 head
+= "</b></big>";
1038 debug
= debug_info(sym
);
1040 struct gstr help_gstr
= str_new();
1041 menu_get_ext_help(_menu
, &help_gstr
);
1042 help
= print_filter(str_get(&help_gstr
));
1043 str_free(&help_gstr
);
1044 } else if (_menu
->prompt
) {
1046 head
+= print_filter(_(_menu
->prompt
->text
));
1047 head
+= "</b></big><br><br>";
1049 if (_menu
->prompt
->visible
.expr
) {
1050 debug
+= " dep: ";
1051 expr_print(_menu
->prompt
->visible
.expr
, expr_print_help
, &debug
, E_NONE
);
1052 debug
+= "<br><br>";
1057 debug
+= QString().sprintf("defined at %s:%d<br><br>", _menu
->file
->name
, _menu
->lineno
);
1059 setText(head
+ debug
+ help
);
1062 QString
ConfigInfoView::debug_info(struct symbol
*sym
)
1067 debug
+= print_filter(sym_type_name(sym
->type
));
1068 if (sym_is_choice(sym
))
1069 debug
+= " (choice)";
1071 if (sym
->rev_dep
.expr
) {
1072 debug
+= "reverse dep: ";
1073 expr_print(sym
->rev_dep
.expr
, expr_print_help
, &debug
, E_NONE
);
1076 for (struct property
*prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1077 switch (prop
->type
) {
1080 debug
+= QString().sprintf("prompt: <a href=\"m%p\">", prop
->menu
);
1081 debug
+= print_filter(_(prop
->text
));
1082 debug
+= "</a><br>";
1088 debug
+= prop_get_type_name(prop
->type
);
1090 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1094 if (sym_is_choice(sym
)) {
1095 debug
+= "choice: ";
1096 expr_print(prop
->expr
, expr_print_help
, &debug
, E_NONE
);
1101 debug
+= "unknown property: ";
1102 debug
+= prop_get_type_name(prop
->type
);
1105 if (prop
->visible
.expr
) {
1106 debug
+= " dep: ";
1107 expr_print(prop
->visible
.expr
, expr_print_help
, &debug
, E_NONE
);
1116 QString
ConfigInfoView::print_filter(const QString
&str
)
1118 QRegExp
re("[<>&\"\\n]");
1120 for (int i
= 0; (i
= res
.find(re
, i
)) >= 0;) {
1121 switch (res
[i
].latin1()) {
1123 res
.replace(i
, 1, "<");
1127 res
.replace(i
, 1, ">");
1131 res
.replace(i
, 1, "&");
1135 res
.replace(i
, 1, """);
1139 res
.replace(i
, 1, "<br>");
1147 void ConfigInfoView::expr_print_help(void *data
, struct symbol
*sym
, const char *str
)
1149 QString
* text
= reinterpret_cast<QString
*>(data
);
1150 QString str2
= print_filter(str
);
1152 if (sym
&& sym
->name
&& !(sym
->flags
& SYMBOL_CONST
)) {
1153 *text
+= QString().sprintf("<a href=\"s%p\">", sym
);
1160 QMenu
* ConfigInfoView::createStandardContextMenu(const QPoint
& pos
)
1162 QMenu
* popup
= Parent::createStandardContextMenu(pos
);
1163 QAction
* action
= new QAction(_("Show Debug Info"), popup
);
1164 action
->setToggleAction(TRUE
);
1165 connect(action
, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
1166 connect(this, SIGNAL(showDebugChanged(bool)), action
, SLOT(setOn(bool)));
1167 action
->setOn(showDebug());
1168 popup
->addSeparator();
1169 action
->addTo(popup
);
1173 void ConfigInfoView::contextMenuEvent(QContextMenuEvent
*e
)
1175 Parent::contextMenuEvent(e
);
1178 ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow
* parent
, const char *name
)
1179 : Parent(parent
, name
), result(NULL
)
1181 setCaption("Search Config");
1183 QVBoxLayout
* layout1
= new QVBoxLayout(this, 11, 6);
1184 QHBoxLayout
* layout2
= new QHBoxLayout(0, 0, 6);
1185 layout2
->addWidget(new QLabel(_("Find:"), this));
1186 editField
= new QLineEdit(this);
1187 connect(editField
, SIGNAL(returnPressed()), SLOT(search()));
1188 layout2
->addWidget(editField
);
1189 searchButton
= new QPushButton(_("Search"), this);
1190 searchButton
->setAutoDefault(FALSE
);
1191 connect(searchButton
, SIGNAL(clicked()), SLOT(search()));
1192 layout2
->addWidget(searchButton
);
1193 layout1
->addLayout(layout2
);
1195 split
= new QSplitter(this);
1196 split
->setOrientation(Qt::Vertical
);
1197 list
= new ConfigView(split
, name
);
1198 list
->list
->mode
= listMode
;
1199 info
= new ConfigInfoView(split
, name
);
1200 connect(list
->list
, SIGNAL(menuChanged(struct menu
*)),
1201 info
, SLOT(setInfo(struct menu
*)));
1202 connect(list
->list
, SIGNAL(menuChanged(struct menu
*)),
1203 parent
, SLOT(setMenuLink(struct menu
*)));
1205 layout1
->addWidget(split
);
1208 int x
, y
, width
, height
;
1211 configSettings
->beginGroup(name
);
1212 width
= configSettings
->readNumEntry("/window width", parent
->width() / 2);
1213 height
= configSettings
->readNumEntry("/window height", parent
->height() / 2);
1214 resize(width
, height
);
1215 x
= configSettings
->readNumEntry("/window x", 0, &ok
);
1217 y
= configSettings
->readNumEntry("/window y", 0, &ok
);
1220 QList
<int> sizes
= configSettings
->readSizes("/split", &ok
);
1222 split
->setSizes(sizes
);
1223 configSettings
->endGroup();
1224 connect(configApp
, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1228 void ConfigSearchWindow::saveSettings(void)
1231 configSettings
->beginGroup(name());
1232 configSettings
->writeEntry("/window x", pos().x());
1233 configSettings
->writeEntry("/window y", pos().y());
1234 configSettings
->writeEntry("/window width", size().width());
1235 configSettings
->writeEntry("/window height", size().height());
1236 configSettings
->writeSizes("/split", split
->sizes());
1237 configSettings
->endGroup();
1241 void ConfigSearchWindow::search(void)
1244 struct property
*prop
;
1245 ConfigItem
*lastItem
= NULL
;
1248 list
->list
->clear();
1251 result
= sym_re_search(editField
->text().latin1());
1254 for (p
= result
; *p
; p
++) {
1255 for_all_prompts((*p
), prop
)
1256 lastItem
= new ConfigItem(list
->list
, lastItem
, prop
->menu
,
1257 menu_is_visible(prop
->menu
));
1262 * Construct the complete config widget
1264 ConfigMainWindow::ConfigMainWindow(void)
1269 int x
, y
, width
, height
;
1272 QDesktopWidget
*d
= configApp
->desktop();
1273 snprintf(title
, sizeof(title
), "%s%s",
1274 rootmenu
.prompt
->text
,
1279 width
= configSettings
->readNumEntry("/window width", d
->width() - 64);
1280 height
= configSettings
->readNumEntry("/window height", d
->height() - 64);
1281 resize(width
, height
);
1282 x
= configSettings
->readNumEntry("/window x", 0, &ok
);
1284 y
= configSettings
->readNumEntry("/window y", 0, &ok
);
1288 split1
= new QSplitter(this);
1289 split1
->setOrientation(Qt::Horizontal
);
1290 setCentralWidget(split1
);
1292 menuView
= new ConfigView(split1
, "menu");
1293 menuList
= menuView
->list
;
1295 split2
= new QSplitter(split1
);
1296 split2
->setOrientation(Qt::Vertical
);
1298 // create config tree
1299 configView
= new ConfigView(split2
, "config");
1300 configList
= configView
->list
;
1302 helpText
= new ConfigInfoView(split2
, "help");
1303 helpText
->setTextFormat(Qt::RichText
);
1305 setTabOrder(configList
, helpText
);
1306 configList
->setFocus();
1309 toolBar
= new QToolBar("Tools", this);
1310 addToolBar(toolBar
);
1312 backAction
= new QAction(QPixmap(xpm_back
), _("Back"), this);
1313 connect(backAction
, SIGNAL(activated()), SLOT(goBack()));
1314 backAction
->setEnabled(FALSE
);
1315 QAction
*quitAction
= new QAction(_("&Quit"), this);
1316 quitAction
->setShortcut(Qt::CTRL
+ Qt::Key_Q
);
1317 connect(quitAction
, SIGNAL(activated()), SLOT(close()));
1318 QAction
*loadAction
= new QAction(QPixmap(xpm_load
), _("&Load"), this);
1319 loadAction
->setShortcut(Qt::CTRL
+ Qt::Key_L
);
1320 connect(loadAction
, SIGNAL(activated()), SLOT(loadConfig()));
1321 saveAction
= new QAction(QPixmap(xpm_save
), _("&Save"), this);
1322 saveAction
->setShortcut(Qt::CTRL
+ Qt::Key_S
);
1323 connect(saveAction
, SIGNAL(activated()), SLOT(saveConfig()));
1324 conf_set_changed_callback(conf_changed
);
1325 // Set saveAction's initial state
1327 QAction
*saveAsAction
= new QAction(_("Save &As..."), this);
1328 connect(saveAsAction
, SIGNAL(activated()), SLOT(saveConfigAs()));
1329 QAction
*searchAction
= new QAction(_("&Find"), this);
1330 searchAction
->setShortcut(Qt::CTRL
+ Qt::Key_F
);
1331 connect(searchAction
, SIGNAL(activated()), SLOT(searchConfig()));
1332 QAction
*singleViewAction
= new QAction(QPixmap(xpm_single_view
), _("Single View"), this);
1333 connect(singleViewAction
, SIGNAL(activated()), SLOT(showSingleView()));
1334 QAction
*splitViewAction
= new QAction(QPixmap(xpm_split_view
), _("Split View"), this);
1335 connect(splitViewAction
, SIGNAL(activated()), SLOT(showSplitView()));
1336 QAction
*fullViewAction
= new QAction(QPixmap(xpm_tree_view
), _("Full View"), this);
1337 connect(fullViewAction
, SIGNAL(activated()), SLOT(showFullView()));
1339 QAction
*showNameAction
= new QAction(_("Show Name"), this);
1340 showNameAction
->setToggleAction(TRUE
);
1341 connect(showNameAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowName(bool)));
1342 connect(configView
, SIGNAL(showNameChanged(bool)), showNameAction
, SLOT(setOn(bool)));
1343 showNameAction
->setOn(configView
->showName());
1344 QAction
*showRangeAction
= new QAction(_("Show Range"), this);
1345 showRangeAction
->setToggleAction(TRUE
);
1346 connect(showRangeAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowRange(bool)));
1347 connect(configView
, SIGNAL(showRangeChanged(bool)), showRangeAction
, SLOT(setOn(bool)));
1348 showRangeAction
->setOn(configList
->showRange
);
1349 QAction
*showDataAction
= new QAction(_("Show Data"), this);
1350 showDataAction
->setToggleAction(TRUE
);
1351 connect(showDataAction
, SIGNAL(toggled(bool)), configView
, SLOT(setShowData(bool)));
1352 connect(configView
, SIGNAL(showDataChanged(bool)), showDataAction
, SLOT(setOn(bool)));
1353 showDataAction
->setOn(configList
->showData
);
1355 QActionGroup
*optGroup
= new QActionGroup(this);
1356 optGroup
->setExclusive(TRUE
);
1357 connect(optGroup
, SIGNAL(selected(QAction
*)), configView
,
1358 SLOT(setOptionMode(QAction
*)));
1359 connect(optGroup
, SIGNAL(selected(QAction
*)), menuView
,
1360 SLOT(setOptionMode(QAction
*)));
1362 configView
->showNormalAction
= new QAction(_("Show Normal Options"), optGroup
);
1363 configView
->showAllAction
= new QAction(_("Show All Options"), optGroup
);
1364 configView
->showPromptAction
= new QAction(_("Show Prompt Options"), optGroup
);
1365 configView
->showNormalAction
->setToggleAction(TRUE
);
1366 configView
->showNormalAction
->setOn(configList
->optMode
== normalOpt
);
1367 configView
->showAllAction
->setToggleAction(TRUE
);
1368 configView
->showAllAction
->setOn(configList
->optMode
== allOpt
);
1369 configView
->showPromptAction
->setToggleAction(TRUE
);
1370 configView
->showPromptAction
->setOn(configList
->optMode
== promptOpt
);
1372 QAction
*showDebugAction
= new QAction( _("Show Debug Info"), this);
1373 showDebugAction
->setToggleAction(TRUE
);
1374 connect(showDebugAction
, SIGNAL(toggled(bool)), helpText
, SLOT(setShowDebug(bool)));
1375 connect(helpText
, SIGNAL(showDebugChanged(bool)), showDebugAction
, SLOT(setOn(bool)));
1376 showDebugAction
->setOn(helpText
->showDebug());
1378 QAction
*showIntroAction
= new QAction( _("Introduction"), this);
1379 connect(showIntroAction
, SIGNAL(activated()), SLOT(showIntro()));
1380 QAction
*showAboutAction
= new QAction( _("About"), this);
1381 connect(showAboutAction
, SIGNAL(activated()), SLOT(showAbout()));
1384 backAction
->addTo(toolBar
);
1385 toolBar
->addSeparator();
1386 loadAction
->addTo(toolBar
);
1387 saveAction
->addTo(toolBar
);
1388 toolBar
->addSeparator();
1389 singleViewAction
->addTo(toolBar
);
1390 splitViewAction
->addTo(toolBar
);
1391 fullViewAction
->addTo(toolBar
);
1393 // create config menu
1394 QMenu
* config
= new QMenu(this);
1395 menu
->insertItem(_("&File"), config
);
1396 loadAction
->addTo(config
);
1397 saveAction
->addTo(config
);
1398 saveAsAction
->addTo(config
);
1399 config
->addSeparator();
1400 quitAction
->addTo(config
);
1403 QMenu
* editMenu
= new QMenu(this);
1404 menu
->insertItem(_("&Edit"), editMenu
);
1405 searchAction
->addTo(editMenu
);
1407 // create options menu
1408 QMenu
* optionMenu
= new QMenu(this);
1409 menu
->insertItem(_("&Option"), optionMenu
);
1410 showNameAction
->addTo(optionMenu
);
1411 showRangeAction
->addTo(optionMenu
);
1412 showDataAction
->addTo(optionMenu
);
1413 optionMenu
->addSeparator();
1414 optGroup
->addTo(optionMenu
);
1415 optionMenu
->addSeparator();
1418 QMenu
* helpMenu
= new QMenu(this);
1419 menu
->addSeparator();
1420 menu
->insertItem(_("&Help"), helpMenu
);
1421 showIntroAction
->addTo(helpMenu
);
1422 showAboutAction
->addTo(helpMenu
);
1424 connect(configList
, SIGNAL(menuChanged(struct menu
*)),
1425 helpText
, SLOT(setInfo(struct menu
*)));
1426 connect(configList
, SIGNAL(menuSelected(struct menu
*)),
1427 SLOT(changeMenu(struct menu
*)));
1428 connect(configList
, SIGNAL(parentSelected()),
1430 connect(menuList
, SIGNAL(menuChanged(struct menu
*)),
1431 helpText
, SLOT(setInfo(struct menu
*)));
1432 connect(menuList
, SIGNAL(menuSelected(struct menu
*)),
1433 SLOT(changeMenu(struct menu
*)));
1435 connect(configList
, SIGNAL(gotFocus(struct menu
*)),
1436 helpText
, SLOT(setInfo(struct menu
*)));
1437 connect(menuList
, SIGNAL(gotFocus(struct menu
*)),
1438 helpText
, SLOT(setInfo(struct menu
*)));
1439 connect(menuList
, SIGNAL(gotFocus(struct menu
*)),
1440 SLOT(listFocusChanged(void)));
1441 connect(helpText
, SIGNAL(menuSelected(struct menu
*)),
1442 SLOT(setMenuLink(struct menu
*)));
1444 QString listMode
= configSettings
->readEntry("/listMode", "symbol");
1445 if (listMode
== "single")
1447 else if (listMode
== "full")
1449 else /*if (listMode == "split")*/
1452 // UI setup done, restore splitter positions
1453 QList
<int> sizes
= configSettings
->readSizes("/split1", &ok
);
1455 split1
->setSizes(sizes
);
1457 sizes
= configSettings
->readSizes("/split2", &ok
);
1459 split2
->setSizes(sizes
);
1462 void ConfigMainWindow::loadConfig(void)
1464 QString s
= QFileDialog::getOpenFileName(conf_get_configname(), NULL
, this);
1467 if (conf_read(QFile::encodeName(s
)))
1468 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
1469 ConfigView::updateListAll();
1472 bool ConfigMainWindow::saveConfig(void)
1474 if (conf_write(NULL
)) {
1475 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
1481 void ConfigMainWindow::saveConfigAs(void)
1483 QString s
= QFileDialog::getSaveFileName(conf_get_configname(), NULL
, this);
1489 void ConfigMainWindow::searchConfig(void)
1492 searchWindow
= new ConfigSearchWindow(this, "search");
1493 searchWindow
->show();
1496 void ConfigMainWindow::changeMenu(struct menu
*menu
)
1498 configList
->setRootMenu(menu
);
1499 if (configList
->rootEntry
->parent
== &rootmenu
)
1500 backAction
->setEnabled(FALSE
);
1502 backAction
->setEnabled(TRUE
);
1505 void ConfigMainWindow::setMenuLink(struct menu
*menu
)
1507 struct menu
*parent
;
1508 ConfigList
* list
= NULL
;
1511 if (configList
->menuSkip(menu
))
1514 switch (configList
->mode
) {
1517 parent
= menu_get_parent_menu(menu
);
1520 list
->setRootMenu(parent
);
1523 if (menu
->flags
& MENU_ROOT
) {
1524 configList
->setRootMenu(menu
);
1525 configList
->clearSelection();
1529 parent
= menu_get_parent_menu(menu
->parent
);
1532 item
= menuList
->findConfigItem(parent
);
1534 menuList
->setSelected(item
, TRUE
);
1535 menuList
->ensureItemVisible(item
);
1537 list
->setRootMenu(parent
);
1548 item
= list
->findConfigItem(menu
);
1550 list
->setSelected(item
, TRUE
);
1551 list
->ensureItemVisible(item
);
1557 void ConfigMainWindow::listFocusChanged(void)
1559 if (menuList
->mode
== menuMode
)
1560 configList
->clearSelection();
1563 void ConfigMainWindow::goBack(void)
1567 configList
->setParentMenu();
1568 if (configList
->rootEntry
== &rootmenu
)
1569 backAction
->setEnabled(FALSE
);
1570 item
= (ConfigItem
*)menuList
->selectedItem();
1572 if (item
->menu
== configList
->rootEntry
) {
1573 menuList
->setSelected(item
, TRUE
);
1576 item
= (ConfigItem
*)item
->parent();
1580 void ConfigMainWindow::showSingleView(void)
1583 menuList
->setRootMenu(0);
1584 configList
->mode
= singleMode
;
1585 if (configList
->rootEntry
== &rootmenu
)
1586 configList
->updateListAll();
1588 configList
->setRootMenu(&rootmenu
);
1589 configList
->setAllOpen(TRUE
);
1590 configList
->setFocus();
1593 void ConfigMainWindow::showSplitView(void)
1595 configList
->mode
= symbolMode
;
1596 if (configList
->rootEntry
== &rootmenu
)
1597 configList
->updateListAll();
1599 configList
->setRootMenu(&rootmenu
);
1600 configList
->setAllOpen(TRUE
);
1601 configApp
->processEvents();
1602 menuList
->mode
= menuMode
;
1603 menuList
->setRootMenu(&rootmenu
);
1604 menuList
->setAllOpen(TRUE
);
1606 menuList
->setFocus();
1609 void ConfigMainWindow::showFullView(void)
1612 menuList
->setRootMenu(0);
1613 configList
->mode
= fullMode
;
1614 if (configList
->rootEntry
== &rootmenu
)
1615 configList
->updateListAll();
1617 configList
->setRootMenu(&rootmenu
);
1618 configList
->setAllOpen(FALSE
);
1619 configList
->setFocus();
1623 * ask for saving configuration before quitting
1624 * TODO ask only when something changed
1626 void ConfigMainWindow::closeEvent(QCloseEvent
* e
)
1628 if (!conf_get_changed()) {
1632 QMessageBox
mb("qconf", _("Save configuration?"), QMessageBox::Warning
,
1633 QMessageBox::Yes
| QMessageBox::Default
, QMessageBox::No
, QMessageBox::Cancel
| QMessageBox::Escape
);
1634 mb
.setButtonText(QMessageBox::Yes
, _("&Save Changes"));
1635 mb
.setButtonText(QMessageBox::No
, _("&Discard Changes"));
1636 mb
.setButtonText(QMessageBox::Cancel
, _("Cancel Exit"));
1637 switch (mb
.exec()) {
1638 case QMessageBox::Yes
:
1644 case QMessageBox::No
:
1647 case QMessageBox::Cancel
:
1653 void ConfigMainWindow::showIntro(void)
1655 static const QString str
= _("Welcome to the qconf graphical configuration tool.\n\n"
1656 "For each option, a blank box indicates the feature is disabled, a check\n"
1657 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1658 "as a module. Clicking on the box will cycle through the three states.\n\n"
1659 "If you do not see an option (e.g., a device driver) that you believe\n"
1660 "should be present, try turning on Show All Options under the Options menu.\n"
1661 "Although there is no cross reference yet to help you figure out what other\n"
1662 "options must be enabled to support the option you are interested in, you can\n"
1663 "still view the help of a grayed-out option.\n\n"
1664 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1665 "which you can then match by examining other options.\n\n");
1667 QMessageBox::information(this, "qconf", str
);
1670 void ConfigMainWindow::showAbout(void)
1672 static const QString str
= _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1673 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
1675 QMessageBox::information(this, "qconf", str
);
1678 void ConfigMainWindow::saveSettings(void)
1680 configSettings
->writeEntry("/window x", pos().x());
1681 configSettings
->writeEntry("/window y", pos().y());
1682 configSettings
->writeEntry("/window width", size().width());
1683 configSettings
->writeEntry("/window height", size().height());
1686 switch(configList
->mode
) {
1702 configSettings
->writeEntry("/listMode", entry
);
1704 configSettings
->writeSizes("/split1", split1
->sizes());
1705 configSettings
->writeSizes("/split2", split2
->sizes());
1708 void ConfigMainWindow::conf_changed(void)
1711 saveAction
->setEnabled(conf_get_changed());
1714 void fixup_rootmenu(struct menu
*menu
)
1717 static int menu_cnt
= 0;
1719 menu
->flags
|= MENU_ROOT
;
1720 for (child
= menu
->list
; child
; child
= child
->next
) {
1721 if (child
->prompt
&& child
->prompt
->type
== P_MENU
) {
1723 fixup_rootmenu(child
);
1725 } else if (!menu_cnt
)
1726 fixup_rootmenu(child
);
1730 static const char *progname
;
1732 static void usage(void)
1734 printf(_("%s [-s] <config>\n"), progname
);
1738 int main(int ac
, char** av
)
1740 ConfigMainWindow
* v
;
1743 bindtextdomain(PACKAGE
, LOCALEDIR
);
1744 textdomain(PACKAGE
);
1747 configApp
= new QApplication(ac
, av
);
1748 if (ac
> 1 && av
[1][0] == '-') {
1751 conf_set_message_callback(NULL
);
1764 fixup_rootmenu(&rootmenu
);
1766 //zconfdump(stdout);
1768 configSettings
= new ConfigSettings();
1769 configSettings
->beginGroup("/kconfig/qconf");
1770 v
= new ConfigMainWindow();
1772 //zconfdump(stdout);
1773 configApp
->setMainWidget(v
);
1774 configApp
->connect(configApp
, SIGNAL(lastWindowClosed()), SLOT(quit()));
1775 configApp
->connect(configApp
, SIGNAL(aboutToQuit()), v
, SLOT(saveSettings()));
1779 configSettings
->endGroup();
1780 delete configSettings
;
This page took 0.101204 seconds and 5 git commands to generate.