xref: /openbmc/linux/scripts/kconfig/qconf.cc (revision 00d4f8fc)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
31da177e4SLinus Torvalds  * Released under the terms of the GNU GPL v2.0.
41da177e4SLinus Torvalds  */
51da177e4SLinus Torvalds 
6133c5f7cSAlexander Stein #include <qglobal.h>
7133c5f7cSAlexander Stein 
8133c5f7cSAlexander Stein #if QT_VERSION < 0x040000
9aed9934bSTiana Rakotovao Andriamahefa #include <stddef.h>
101da177e4SLinus Torvalds #include <qmainwindow.h>
11133c5f7cSAlexander Stein #include <qvbox.h>
12133c5f7cSAlexander Stein #include <qvaluelist.h>
13133c5f7cSAlexander Stein #include <qtextbrowser.h>
14133c5f7cSAlexander Stein #include <qaction.h>
15133c5f7cSAlexander Stein #include <qheader.h>
16133c5f7cSAlexander Stein #include <qfiledialog.h>
17133c5f7cSAlexander Stein #include <qdragobject.h>
18133c5f7cSAlexander Stein #include <qpopupmenu.h>
19133c5f7cSAlexander Stein #else
20133c5f7cSAlexander Stein #include <q3mainwindow.h>
21133c5f7cSAlexander Stein #include <q3vbox.h>
22133c5f7cSAlexander Stein #include <q3valuelist.h>
23133c5f7cSAlexander Stein #include <q3textbrowser.h>
24133c5f7cSAlexander Stein #include <q3action.h>
25133c5f7cSAlexander Stein #include <q3header.h>
26133c5f7cSAlexander Stein #include <q3filedialog.h>
27133c5f7cSAlexander Stein #include <q3dragobject.h>
28133c5f7cSAlexander Stein #include <q3popupmenu.h>
29133c5f7cSAlexander Stein #endif
30133c5f7cSAlexander Stein 
31133c5f7cSAlexander Stein #include <qapplication.h>
328d90c97eSMarkus Heidelberg #include <qdesktopwidget.h>
331da177e4SLinus Torvalds #include <qtoolbar.h>
3443bf612aSRoman Zippel #include <qlayout.h>
351da177e4SLinus Torvalds #include <qsplitter.h>
361da177e4SLinus Torvalds #include <qlineedit.h>
3743bf612aSRoman Zippel #include <qlabel.h>
3843bf612aSRoman Zippel #include <qpushbutton.h>
391da177e4SLinus Torvalds #include <qmenubar.h>
401da177e4SLinus Torvalds #include <qmessagebox.h>
411da177e4SLinus Torvalds #include <qregexp.h>
42133c5f7cSAlexander Stein #include <qevent.h>
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds #include <stdlib.h>
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds #include "lkc.h"
471da177e4SLinus Torvalds #include "qconf.h"
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #include "qconf.moc"
501da177e4SLinus Torvalds #include "images.c"
511da177e4SLinus Torvalds 
523b9fa093SArnaldo Carvalho de Melo #ifdef _
533b9fa093SArnaldo Carvalho de Melo # undef _
543b9fa093SArnaldo Carvalho de Melo # define _ qgettext
553b9fa093SArnaldo Carvalho de Melo #endif
563b9fa093SArnaldo Carvalho de Melo 
571da177e4SLinus Torvalds static QApplication *configApp;
587fc925fdSRoman Zippel static ConfigSettings *configSettings;
591da177e4SLinus Torvalds 
60133c5f7cSAlexander Stein Q3Action *ConfigMainWindow::saveAction;
613b354c55SKarsten Wiese 
623b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const char* str)
633b9fa093SArnaldo Carvalho de Melo {
643b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str));
653b9fa093SArnaldo Carvalho de Melo }
663b9fa093SArnaldo Carvalho de Melo 
673b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const QString& str)
683b9fa093SArnaldo Carvalho de Melo {
693b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str.latin1()));
703b9fa093SArnaldo Carvalho de Melo }
713b9fa093SArnaldo Carvalho de Melo 
7200d4f8fcSBen Hutchings ConfigSettings::ConfigSettings()
7300d4f8fcSBen Hutchings 	: QSettings("kernel.org", "qconf")
7400d4f8fcSBen Hutchings {
7500d4f8fcSBen Hutchings }
7600d4f8fcSBen Hutchings 
771da177e4SLinus Torvalds /**
781da177e4SLinus Torvalds  * Reads a list of integer values from the application settings.
791da177e4SLinus Torvalds  */
80133c5f7cSAlexander Stein Q3ValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
811da177e4SLinus Torvalds {
82133c5f7cSAlexander Stein 	Q3ValueList<int> result;
831da177e4SLinus Torvalds 	QStringList entryList = readListEntry(key, ok);
841da177e4SLinus Torvalds 	QStringList::Iterator it;
85c1f96f09SLi Zefan 
861da177e4SLinus Torvalds 	for (it = entryList.begin(); it != entryList.end(); ++it)
871da177e4SLinus Torvalds 		result.push_back((*it).toInt());
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds 	return result;
901da177e4SLinus Torvalds }
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds /**
931da177e4SLinus Torvalds  * Writes a list of integer values to the application settings.
941da177e4SLinus Torvalds  */
95133c5f7cSAlexander Stein bool ConfigSettings::writeSizes(const QString& key, const Q3ValueList<int>& value)
961da177e4SLinus Torvalds {
971da177e4SLinus Torvalds 	QStringList stringList;
98133c5f7cSAlexander Stein 	Q3ValueList<int>::ConstIterator it;
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds 	for (it = value.begin(); it != value.end(); ++it)
1011da177e4SLinus Torvalds 		stringList.push_back(QString::number(*it));
1021da177e4SLinus Torvalds 	return writeEntry(key, stringList);
1031da177e4SLinus Torvalds }
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds /*
1071da177e4SLinus Torvalds  * set the new data
1081da177e4SLinus Torvalds  * TODO check the value
1091da177e4SLinus Torvalds  */
1101da177e4SLinus Torvalds void ConfigItem::okRename(int col)
1111da177e4SLinus Torvalds {
1121da177e4SLinus Torvalds 	Parent::okRename(col);
1131da177e4SLinus Torvalds 	sym_set_string_value(menu->sym, text(dataColIdx).latin1());
11449e5646dSKarsten Wiese 	listView()->updateList(this);
1151da177e4SLinus Torvalds }
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds /*
1181da177e4SLinus Torvalds  * update the displayed of a menu entry
1191da177e4SLinus Torvalds  */
1201da177e4SLinus Torvalds void ConfigItem::updateMenu(void)
1211da177e4SLinus Torvalds {
1221da177e4SLinus Torvalds 	ConfigList* list;
1231da177e4SLinus Torvalds 	struct symbol* sym;
1241da177e4SLinus Torvalds 	struct property *prop;
1251da177e4SLinus Torvalds 	QString prompt;
1261da177e4SLinus Torvalds 	int type;
1271da177e4SLinus Torvalds 	tristate expr;
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds 	list = listView();
1301da177e4SLinus Torvalds 	if (goParent) {
1311da177e4SLinus Torvalds 		setPixmap(promptColIdx, list->menuBackPix);
1321da177e4SLinus Torvalds 		prompt = "..";
1331da177e4SLinus Torvalds 		goto set_prompt;
1341da177e4SLinus Torvalds 	}
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds 	sym = menu->sym;
1371da177e4SLinus Torvalds 	prop = menu->prompt;
138c21a2d95SEGRY Gabor 	prompt = _(menu_get_prompt(menu));
1391da177e4SLinus Torvalds 
1401da177e4SLinus Torvalds 	if (prop) switch (prop->type) {
1411da177e4SLinus Torvalds 	case P_MENU:
1421da177e4SLinus Torvalds 		if (list->mode == singleMode || list->mode == symbolMode) {
1431da177e4SLinus Torvalds 			/* a menuconfig entry is displayed differently
1441da177e4SLinus Torvalds 			 * depending whether it's at the view root or a child.
1451da177e4SLinus Torvalds 			 */
1461da177e4SLinus Torvalds 			if (sym && list->rootEntry == menu)
1471da177e4SLinus Torvalds 				break;
1481da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->menuPix);
1491da177e4SLinus Torvalds 		} else {
1501da177e4SLinus Torvalds 			if (sym)
1511da177e4SLinus Torvalds 				break;
1521da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1531da177e4SLinus Torvalds 		}
1541da177e4SLinus Torvalds 		goto set_prompt;
1551da177e4SLinus Torvalds 	case P_COMMENT:
1561da177e4SLinus Torvalds 		setPixmap(promptColIdx, 0);
1571da177e4SLinus Torvalds 		goto set_prompt;
1581da177e4SLinus Torvalds 	default:
1591da177e4SLinus Torvalds 		;
1601da177e4SLinus Torvalds 	}
1611da177e4SLinus Torvalds 	if (!sym)
1621da177e4SLinus Torvalds 		goto set_prompt;
1631da177e4SLinus Torvalds 
1643b9fa093SArnaldo Carvalho de Melo 	setText(nameColIdx, QString::fromLocal8Bit(sym->name));
1651da177e4SLinus Torvalds 
1661da177e4SLinus Torvalds 	type = sym_get_type(sym);
1671da177e4SLinus Torvalds 	switch (type) {
1681da177e4SLinus Torvalds 	case S_BOOLEAN:
1691da177e4SLinus Torvalds 	case S_TRISTATE:
1701da177e4SLinus Torvalds 		char ch;
1711da177e4SLinus Torvalds 
17239a4897cSLi Zefan 		if (!sym_is_changable(sym) && list->optMode == normalOpt) {
1731da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1743b9fa093SArnaldo Carvalho de Melo 			setText(noColIdx, QString::null);
1753b9fa093SArnaldo Carvalho de Melo 			setText(modColIdx, QString::null);
1763b9fa093SArnaldo Carvalho de Melo 			setText(yesColIdx, QString::null);
1771da177e4SLinus Torvalds 			break;
1781da177e4SLinus Torvalds 		}
1791da177e4SLinus Torvalds 		expr = sym_get_tristate_value(sym);
1801da177e4SLinus Torvalds 		switch (expr) {
1811da177e4SLinus Torvalds 		case yes:
1821da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1831da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceYesPix);
1841da177e4SLinus Torvalds 			else
1851da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolYesPix);
1861da177e4SLinus Torvalds 			setText(yesColIdx, "Y");
1871da177e4SLinus Torvalds 			ch = 'Y';
1881da177e4SLinus Torvalds 			break;
1891da177e4SLinus Torvalds 		case mod:
1901da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->symbolModPix);
1911da177e4SLinus Torvalds 			setText(modColIdx, "M");
1921da177e4SLinus Torvalds 			ch = 'M';
1931da177e4SLinus Torvalds 			break;
1941da177e4SLinus Torvalds 		default:
1951da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1961da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceNoPix);
1971da177e4SLinus Torvalds 			else
1981da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolNoPix);
1991da177e4SLinus Torvalds 			setText(noColIdx, "N");
2001da177e4SLinus Torvalds 			ch = 'N';
2011da177e4SLinus Torvalds 			break;
2021da177e4SLinus Torvalds 		}
2031da177e4SLinus Torvalds 		if (expr != no)
2041da177e4SLinus Torvalds 			setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
2051da177e4SLinus Torvalds 		if (expr != mod)
2061da177e4SLinus Torvalds 			setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
2071da177e4SLinus Torvalds 		if (expr != yes)
2081da177e4SLinus Torvalds 			setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds 		setText(dataColIdx, QChar(ch));
2111da177e4SLinus Torvalds 		break;
2121da177e4SLinus Torvalds 	case S_INT:
2131da177e4SLinus Torvalds 	case S_HEX:
2141da177e4SLinus Torvalds 	case S_STRING:
2151da177e4SLinus Torvalds 		const char* data;
2161da177e4SLinus Torvalds 
2171da177e4SLinus Torvalds 		data = sym_get_string_value(sym);
2183b9fa093SArnaldo Carvalho de Melo 
2191da177e4SLinus Torvalds 		int i = list->mapIdx(dataColIdx);
2201da177e4SLinus Torvalds 		if (i >= 0)
2211da177e4SLinus Torvalds 			setRenameEnabled(i, TRUE);
2221da177e4SLinus Torvalds 		setText(dataColIdx, data);
2231da177e4SLinus Torvalds 		if (type == S_STRING)
2243b9fa093SArnaldo Carvalho de Melo 			prompt = QString("%1: %2").arg(prompt).arg(data);
2251da177e4SLinus Torvalds 		else
2263b9fa093SArnaldo Carvalho de Melo 			prompt = QString("(%2) %1").arg(prompt).arg(data);
2271da177e4SLinus Torvalds 		break;
2281da177e4SLinus Torvalds 	}
2291da177e4SLinus Torvalds 	if (!sym_has_value(sym) && visible)
230c21a2d95SEGRY Gabor 		prompt += _(" (NEW)");
2311da177e4SLinus Torvalds set_prompt:
2321da177e4SLinus Torvalds 	setText(promptColIdx, prompt);
2331da177e4SLinus Torvalds }
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds void ConfigItem::testUpdateMenu(bool v)
2361da177e4SLinus Torvalds {
2371da177e4SLinus Torvalds 	ConfigItem* i;
2381da177e4SLinus Torvalds 
2391da177e4SLinus Torvalds 	visible = v;
2401da177e4SLinus Torvalds 	if (!menu)
2411da177e4SLinus Torvalds 		return;
2421da177e4SLinus Torvalds 
2431da177e4SLinus Torvalds 	sym_calc_value(menu->sym);
2441da177e4SLinus Torvalds 	if (menu->flags & MENU_CHANGED) {
2451da177e4SLinus Torvalds 		/* the menu entry changed, so update all list items */
2461da177e4SLinus Torvalds 		menu->flags &= ~MENU_CHANGED;
2471da177e4SLinus Torvalds 		for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
2481da177e4SLinus Torvalds 			i->updateMenu();
2491da177e4SLinus Torvalds 	} else if (listView()->updateAll)
2501da177e4SLinus Torvalds 		updateMenu();
2511da177e4SLinus Torvalds }
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
2541da177e4SLinus Torvalds {
2551da177e4SLinus Torvalds 	ConfigList* list = listView();
2561da177e4SLinus Torvalds 
2571da177e4SLinus Torvalds 	if (visible) {
2581da177e4SLinus Torvalds 		if (isSelected() && !list->hasFocus() && list->mode == menuMode)
2591da177e4SLinus Torvalds 			Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
2601da177e4SLinus Torvalds 		else
2611da177e4SLinus Torvalds 			Parent::paintCell(p, cg, column, width, align);
2621da177e4SLinus Torvalds 	} else
2631da177e4SLinus Torvalds 		Parent::paintCell(p, list->disabledColorGroup, column, width, align);
2641da177e4SLinus Torvalds }
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds /*
2671da177e4SLinus Torvalds  * construct a menu entry
2681da177e4SLinus Torvalds  */
2691da177e4SLinus Torvalds void ConfigItem::init(void)
2701da177e4SLinus Torvalds {
2711da177e4SLinus Torvalds 	if (menu) {
2721da177e4SLinus Torvalds 		ConfigList* list = listView();
2731da177e4SLinus Torvalds 		nextItem = (ConfigItem*)menu->data;
2741da177e4SLinus Torvalds 		menu->data = this;
2751da177e4SLinus Torvalds 
2761da177e4SLinus Torvalds 		if (list->mode != fullMode)
2771da177e4SLinus Torvalds 			setOpen(TRUE);
2781da177e4SLinus Torvalds 		sym_calc_value(menu->sym);
2791da177e4SLinus Torvalds 	}
2801da177e4SLinus Torvalds 	updateMenu();
2811da177e4SLinus Torvalds }
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds /*
2841da177e4SLinus Torvalds  * destruct a menu entry
2851da177e4SLinus Torvalds  */
2861da177e4SLinus Torvalds ConfigItem::~ConfigItem(void)
2871da177e4SLinus Torvalds {
2881da177e4SLinus Torvalds 	if (menu) {
2891da177e4SLinus Torvalds 		ConfigItem** ip = (ConfigItem**)&menu->data;
2901da177e4SLinus Torvalds 		for (; *ip; ip = &(*ip)->nextItem) {
2911da177e4SLinus Torvalds 			if (*ip == this) {
2921da177e4SLinus Torvalds 				*ip = nextItem;
2931da177e4SLinus Torvalds 				break;
2941da177e4SLinus Torvalds 			}
2951da177e4SLinus Torvalds 		}
2961da177e4SLinus Torvalds 	}
2971da177e4SLinus Torvalds }
2981da177e4SLinus Torvalds 
29943bf612aSRoman Zippel ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
30043bf612aSRoman Zippel 	: Parent(parent)
30143bf612aSRoman Zippel {
30243bf612aSRoman Zippel 	connect(this, SIGNAL(lostFocus()), SLOT(hide()));
30343bf612aSRoman Zippel }
30443bf612aSRoman Zippel 
3051da177e4SLinus Torvalds void ConfigLineEdit::show(ConfigItem* i)
3061da177e4SLinus Torvalds {
3071da177e4SLinus Torvalds 	item = i;
3081da177e4SLinus Torvalds 	if (sym_get_string_value(item->menu->sym))
3093b9fa093SArnaldo Carvalho de Melo 		setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
3101da177e4SLinus Torvalds 	else
3113b9fa093SArnaldo Carvalho de Melo 		setText(QString::null);
3121da177e4SLinus Torvalds 	Parent::show();
3131da177e4SLinus Torvalds 	setFocus();
3141da177e4SLinus Torvalds }
3151da177e4SLinus Torvalds 
3161da177e4SLinus Torvalds void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
3171da177e4SLinus Torvalds {
3181da177e4SLinus Torvalds 	switch (e->key()) {
319fbb86374SMarkus Heidelberg 	case Qt::Key_Escape:
3201da177e4SLinus Torvalds 		break;
321fbb86374SMarkus Heidelberg 	case Qt::Key_Return:
322fbb86374SMarkus Heidelberg 	case Qt::Key_Enter:
3231da177e4SLinus Torvalds 		sym_set_string_value(item->menu->sym, text().latin1());
3241da177e4SLinus Torvalds 		parent()->updateList(item);
3251da177e4SLinus Torvalds 		break;
3261da177e4SLinus Torvalds 	default:
3271da177e4SLinus Torvalds 		Parent::keyPressEvent(e);
3281da177e4SLinus Torvalds 		return;
3291da177e4SLinus Torvalds 	}
3301da177e4SLinus Torvalds 	e->accept();
3311da177e4SLinus Torvalds 	parent()->list->setFocus();
3321da177e4SLinus Torvalds 	hide();
3331da177e4SLinus Torvalds }
3341da177e4SLinus Torvalds 
3357fc925fdSRoman Zippel ConfigList::ConfigList(ConfigView* p, const char *name)
3367fc925fdSRoman Zippel 	: Parent(p, name),
3371da177e4SLinus Torvalds 	  updateAll(false),
3381da177e4SLinus Torvalds 	  symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
3391da177e4SLinus Torvalds 	  choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
3401da177e4SLinus Torvalds 	  menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
34139a4897cSLi Zefan 	  showName(false), showRange(false), showData(false), optMode(normalOpt),
3427fc925fdSRoman Zippel 	  rootEntry(0), headerPopup(0)
3431da177e4SLinus Torvalds {
3441da177e4SLinus Torvalds 	int i;
3451da177e4SLinus Torvalds 
3461da177e4SLinus Torvalds 	setSorting(-1);
3471da177e4SLinus Torvalds 	setRootIsDecorated(TRUE);
3481da177e4SLinus Torvalds 	disabledColorGroup = palette().active();
3491da177e4SLinus Torvalds 	disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
3501da177e4SLinus Torvalds 	inactivedColorGroup = palette().active();
3511da177e4SLinus Torvalds 	inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds 	connect(this, SIGNAL(selectionChanged(void)),
3541da177e4SLinus Torvalds 		SLOT(updateSelection(void)));
3551da177e4SLinus Torvalds 
3567fc925fdSRoman Zippel 	if (name) {
3577fc925fdSRoman Zippel 		configSettings->beginGroup(name);
3587fc925fdSRoman Zippel 		showName = configSettings->readBoolEntry("/showName", false);
3597fc925fdSRoman Zippel 		showRange = configSettings->readBoolEntry("/showRange", false);
3607fc925fdSRoman Zippel 		showData = configSettings->readBoolEntry("/showData", false);
36139a4897cSLi Zefan 		optMode = (enum optionMode)configSettings->readNumEntry("/optionMode", false);
3627fc925fdSRoman Zippel 		configSettings->endGroup();
3637fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
3641da177e4SLinus Torvalds 	}
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds 	for (i = 0; i < colNr; i++)
3671da177e4SLinus Torvalds 		colMap[i] = colRevMap[i] = -1;
368c21a2d95SEGRY Gabor 	addColumn(promptColIdx, _("Option"));
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds 	reinit();
3711da177e4SLinus Torvalds }
3721da177e4SLinus Torvalds 
37339a4897cSLi Zefan bool ConfigList::menuSkip(struct menu *menu)
37439a4897cSLi Zefan {
37539a4897cSLi Zefan 	if (optMode == normalOpt && menu_is_visible(menu))
37639a4897cSLi Zefan 		return false;
37739a4897cSLi Zefan 	if (optMode == promptOpt && menu_has_prompt(menu))
37839a4897cSLi Zefan 		return false;
37939a4897cSLi Zefan 	if (optMode == allOpt)
38039a4897cSLi Zefan 		return false;
38139a4897cSLi Zefan 	return true;
38239a4897cSLi Zefan }
38339a4897cSLi Zefan 
3841da177e4SLinus Torvalds void ConfigList::reinit(void)
3851da177e4SLinus Torvalds {
3861da177e4SLinus Torvalds 	removeColumn(dataColIdx);
3871da177e4SLinus Torvalds 	removeColumn(yesColIdx);
3881da177e4SLinus Torvalds 	removeColumn(modColIdx);
3891da177e4SLinus Torvalds 	removeColumn(noColIdx);
3901da177e4SLinus Torvalds 	removeColumn(nameColIdx);
3911da177e4SLinus Torvalds 
3921da177e4SLinus Torvalds 	if (showName)
393c21a2d95SEGRY Gabor 		addColumn(nameColIdx, _("Name"));
3941da177e4SLinus Torvalds 	if (showRange) {
3951da177e4SLinus Torvalds 		addColumn(noColIdx, "N");
3961da177e4SLinus Torvalds 		addColumn(modColIdx, "M");
3971da177e4SLinus Torvalds 		addColumn(yesColIdx, "Y");
3981da177e4SLinus Torvalds 	}
3991da177e4SLinus Torvalds 	if (showData)
400c21a2d95SEGRY Gabor 		addColumn(dataColIdx, _("Value"));
4011da177e4SLinus Torvalds 
4021da177e4SLinus Torvalds 	updateListAll();
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds 
4057fc925fdSRoman Zippel void ConfigList::saveSettings(void)
4067fc925fdSRoman Zippel {
4077fc925fdSRoman Zippel 	if (name()) {
4087fc925fdSRoman Zippel 		configSettings->beginGroup(name());
4097fc925fdSRoman Zippel 		configSettings->writeEntry("/showName", showName);
4107fc925fdSRoman Zippel 		configSettings->writeEntry("/showRange", showRange);
4117fc925fdSRoman Zippel 		configSettings->writeEntry("/showData", showData);
41239a4897cSLi Zefan 		configSettings->writeEntry("/optionMode", (int)optMode);
4137fc925fdSRoman Zippel 		configSettings->endGroup();
4147fc925fdSRoman Zippel 	}
4157fc925fdSRoman Zippel }
4167fc925fdSRoman Zippel 
417b65a47e1SRoman Zippel ConfigItem* ConfigList::findConfigItem(struct menu *menu)
418b65a47e1SRoman Zippel {
419b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem*)menu->data;
420b65a47e1SRoman Zippel 
421b65a47e1SRoman Zippel 	for (; item; item = item->nextItem) {
422b65a47e1SRoman Zippel 		if (this == item->listView())
423b65a47e1SRoman Zippel 			break;
424b65a47e1SRoman Zippel 	}
425b65a47e1SRoman Zippel 
426b65a47e1SRoman Zippel 	return item;
427b65a47e1SRoman Zippel }
428b65a47e1SRoman Zippel 
4291da177e4SLinus Torvalds void ConfigList::updateSelection(void)
4301da177e4SLinus Torvalds {
4311da177e4SLinus Torvalds 	struct menu *menu;
4321da177e4SLinus Torvalds 	enum prop_type type;
4331da177e4SLinus Torvalds 
4341da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)selectedItem();
4351da177e4SLinus Torvalds 	if (!item)
4361da177e4SLinus Torvalds 		return;
4371da177e4SLinus Torvalds 
4381da177e4SLinus Torvalds 	menu = item->menu;
43943bf612aSRoman Zippel 	emit menuChanged(menu);
4401da177e4SLinus Torvalds 	if (!menu)
4411da177e4SLinus Torvalds 		return;
4421da177e4SLinus Torvalds 	type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
4431da177e4SLinus Torvalds 	if (mode == menuMode && type == P_MENU)
4441da177e4SLinus Torvalds 		emit menuSelected(menu);
4451da177e4SLinus Torvalds }
4461da177e4SLinus Torvalds 
4471da177e4SLinus Torvalds void ConfigList::updateList(ConfigItem* item)
4481da177e4SLinus Torvalds {
4491da177e4SLinus Torvalds 	ConfigItem* last = 0;
4501da177e4SLinus Torvalds 
45143bf612aSRoman Zippel 	if (!rootEntry) {
45243bf612aSRoman Zippel 		if (mode != listMode)
4531da177e4SLinus Torvalds 			goto update;
454133c5f7cSAlexander Stein 		Q3ListViewItemIterator it(this);
45543bf612aSRoman Zippel 		ConfigItem* item;
45643bf612aSRoman Zippel 
45743bf612aSRoman Zippel 		for (; it.current(); ++it) {
45843bf612aSRoman Zippel 			item = (ConfigItem*)it.current();
45943bf612aSRoman Zippel 			if (!item->menu)
46043bf612aSRoman Zippel 				continue;
46143bf612aSRoman Zippel 			item->testUpdateMenu(menu_is_visible(item->menu));
46243bf612aSRoman Zippel 		}
46343bf612aSRoman Zippel 		return;
46443bf612aSRoman Zippel 	}
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds 	if (rootEntry != &rootmenu && (mode == singleMode ||
4671da177e4SLinus Torvalds 	    (mode == symbolMode && rootEntry->parent != &rootmenu))) {
4681da177e4SLinus Torvalds 		item = firstChild();
4691da177e4SLinus Torvalds 		if (!item)
4701da177e4SLinus Torvalds 			item = new ConfigItem(this, 0, true);
4711da177e4SLinus Torvalds 		last = item;
4721da177e4SLinus Torvalds 	}
4731da177e4SLinus Torvalds 	if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
4741da177e4SLinus Torvalds 	    rootEntry->sym && rootEntry->prompt) {
4751da177e4SLinus Torvalds 		item = last ? last->nextSibling() : firstChild();
4761da177e4SLinus Torvalds 		if (!item)
4771da177e4SLinus Torvalds 			item = new ConfigItem(this, last, rootEntry, true);
4781da177e4SLinus Torvalds 		else
4791da177e4SLinus Torvalds 			item->testUpdateMenu(true);
4801da177e4SLinus Torvalds 
4811da177e4SLinus Torvalds 		updateMenuList(item, rootEntry);
4821da177e4SLinus Torvalds 		triggerUpdate();
4831da177e4SLinus Torvalds 		return;
4841da177e4SLinus Torvalds 	}
4851da177e4SLinus Torvalds update:
4861da177e4SLinus Torvalds 	updateMenuList(this, rootEntry);
4871da177e4SLinus Torvalds 	triggerUpdate();
4881da177e4SLinus Torvalds }
4891da177e4SLinus Torvalds 
4901da177e4SLinus Torvalds void ConfigList::setValue(ConfigItem* item, tristate val)
4911da177e4SLinus Torvalds {
4921da177e4SLinus Torvalds 	struct symbol* sym;
4931da177e4SLinus Torvalds 	int type;
4941da177e4SLinus Torvalds 	tristate oldval;
4951da177e4SLinus Torvalds 
4961da177e4SLinus Torvalds 	sym = item->menu ? item->menu->sym : 0;
4971da177e4SLinus Torvalds 	if (!sym)
4981da177e4SLinus Torvalds 		return;
4991da177e4SLinus Torvalds 
5001da177e4SLinus Torvalds 	type = sym_get_type(sym);
5011da177e4SLinus Torvalds 	switch (type) {
5021da177e4SLinus Torvalds 	case S_BOOLEAN:
5031da177e4SLinus Torvalds 	case S_TRISTATE:
5041da177e4SLinus Torvalds 		oldval = sym_get_tristate_value(sym);
5051da177e4SLinus Torvalds 
5061da177e4SLinus Torvalds 		if (!sym_set_tristate_value(sym, val))
5071da177e4SLinus Torvalds 			return;
5081da177e4SLinus Torvalds 		if (oldval == no && item->menu->list)
5091da177e4SLinus Torvalds 			item->setOpen(TRUE);
5101da177e4SLinus Torvalds 		parent()->updateList(item);
5111da177e4SLinus Torvalds 		break;
5121da177e4SLinus Torvalds 	}
5131da177e4SLinus Torvalds }
5141da177e4SLinus Torvalds 
5151da177e4SLinus Torvalds void ConfigList::changeValue(ConfigItem* item)
5161da177e4SLinus Torvalds {
5171da177e4SLinus Torvalds 	struct symbol* sym;
5181da177e4SLinus Torvalds 	struct menu* menu;
5191da177e4SLinus Torvalds 	int type, oldexpr, newexpr;
5201da177e4SLinus Torvalds 
5211da177e4SLinus Torvalds 	menu = item->menu;
5221da177e4SLinus Torvalds 	if (!menu)
5231da177e4SLinus Torvalds 		return;
5241da177e4SLinus Torvalds 	sym = menu->sym;
5251da177e4SLinus Torvalds 	if (!sym) {
5261da177e4SLinus Torvalds 		if (item->menu->list)
5271da177e4SLinus Torvalds 			item->setOpen(!item->isOpen());
5281da177e4SLinus Torvalds 		return;
5291da177e4SLinus Torvalds 	}
5301da177e4SLinus Torvalds 
5311da177e4SLinus Torvalds 	type = sym_get_type(sym);
5321da177e4SLinus Torvalds 	switch (type) {
5331da177e4SLinus Torvalds 	case S_BOOLEAN:
5341da177e4SLinus Torvalds 	case S_TRISTATE:
5351da177e4SLinus Torvalds 		oldexpr = sym_get_tristate_value(sym);
5361da177e4SLinus Torvalds 		newexpr = sym_toggle_tristate_value(sym);
5371da177e4SLinus Torvalds 		if (item->menu->list) {
5381da177e4SLinus Torvalds 			if (oldexpr == newexpr)
5391da177e4SLinus Torvalds 				item->setOpen(!item->isOpen());
5401da177e4SLinus Torvalds 			else if (oldexpr == no)
5411da177e4SLinus Torvalds 				item->setOpen(TRUE);
5421da177e4SLinus Torvalds 		}
5431da177e4SLinus Torvalds 		if (oldexpr != newexpr)
5441da177e4SLinus Torvalds 			parent()->updateList(item);
5451da177e4SLinus Torvalds 		break;
5461da177e4SLinus Torvalds 	case S_INT:
5471da177e4SLinus Torvalds 	case S_HEX:
5481da177e4SLinus Torvalds 	case S_STRING:
5491da177e4SLinus Torvalds 		if (colMap[dataColIdx] >= 0)
5501da177e4SLinus Torvalds 			item->startRename(colMap[dataColIdx]);
5511da177e4SLinus Torvalds 		else
5521da177e4SLinus Torvalds 			parent()->lineEdit->show(item);
5531da177e4SLinus Torvalds 		break;
5541da177e4SLinus Torvalds 	}
5551da177e4SLinus Torvalds }
5561da177e4SLinus Torvalds 
5571da177e4SLinus Torvalds void ConfigList::setRootMenu(struct menu *menu)
5581da177e4SLinus Torvalds {
5591da177e4SLinus Torvalds 	enum prop_type type;
5601da177e4SLinus Torvalds 
5611da177e4SLinus Torvalds 	if (rootEntry == menu)
5621da177e4SLinus Torvalds 		return;
5631da177e4SLinus Torvalds 	type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
5641da177e4SLinus Torvalds 	if (type != P_MENU)
5651da177e4SLinus Torvalds 		return;
5661da177e4SLinus Torvalds 	updateMenuList(this, 0);
5671da177e4SLinus Torvalds 	rootEntry = menu;
5681da177e4SLinus Torvalds 	updateListAll();
5691da177e4SLinus Torvalds 	setSelected(currentItem(), hasFocus());
570b65a47e1SRoman Zippel 	ensureItemVisible(currentItem());
5711da177e4SLinus Torvalds }
5721da177e4SLinus Torvalds 
5731da177e4SLinus Torvalds void ConfigList::setParentMenu(void)
5741da177e4SLinus Torvalds {
5751da177e4SLinus Torvalds 	ConfigItem* item;
5761da177e4SLinus Torvalds 	struct menu *oldroot;
5771da177e4SLinus Torvalds 
5781da177e4SLinus Torvalds 	oldroot = rootEntry;
5791da177e4SLinus Torvalds 	if (rootEntry == &rootmenu)
5801da177e4SLinus Torvalds 		return;
5811da177e4SLinus Torvalds 	setRootMenu(menu_get_parent_menu(rootEntry->parent));
5821da177e4SLinus Torvalds 
583133c5f7cSAlexander Stein 	Q3ListViewItemIterator it(this);
5841da177e4SLinus Torvalds 	for (; (item = (ConfigItem*)it.current()); it++) {
5851da177e4SLinus Torvalds 		if (item->menu == oldroot) {
5861da177e4SLinus Torvalds 			setCurrentItem(item);
5871da177e4SLinus Torvalds 			ensureItemVisible(item);
5881da177e4SLinus Torvalds 			break;
5891da177e4SLinus Torvalds 		}
5901da177e4SLinus Torvalds 	}
5911da177e4SLinus Torvalds }
5921da177e4SLinus Torvalds 
5937fc925fdSRoman Zippel /*
5947fc925fdSRoman Zippel  * update all the children of a menu entry
5957fc925fdSRoman Zippel  *   removes/adds the entries from the parent widget as necessary
5967fc925fdSRoman Zippel  *
5977fc925fdSRoman Zippel  * parent: either the menu list widget or a menu entry widget
5987fc925fdSRoman Zippel  * menu: entry to be updated
5997fc925fdSRoman Zippel  */
6007fc925fdSRoman Zippel template <class P>
6017fc925fdSRoman Zippel void ConfigList::updateMenuList(P* parent, struct menu* menu)
6027fc925fdSRoman Zippel {
6037fc925fdSRoman Zippel 	struct menu* child;
6047fc925fdSRoman Zippel 	ConfigItem* item;
6057fc925fdSRoman Zippel 	ConfigItem* last;
6067fc925fdSRoman Zippel 	bool visible;
6077fc925fdSRoman Zippel 	enum prop_type type;
6087fc925fdSRoman Zippel 
6097fc925fdSRoman Zippel 	if (!menu) {
6107fc925fdSRoman Zippel 		while ((item = parent->firstChild()))
6117fc925fdSRoman Zippel 			delete item;
6127fc925fdSRoman Zippel 		return;
6137fc925fdSRoman Zippel 	}
6147fc925fdSRoman Zippel 
6157fc925fdSRoman Zippel 	last = parent->firstChild();
6167fc925fdSRoman Zippel 	if (last && !last->goParent)
6177fc925fdSRoman Zippel 		last = 0;
6187fc925fdSRoman Zippel 	for (child = menu->list; child; child = child->next) {
6197fc925fdSRoman Zippel 		item = last ? last->nextSibling() : parent->firstChild();
6207fc925fdSRoman Zippel 		type = child->prompt ? child->prompt->type : P_UNKNOWN;
6217fc925fdSRoman Zippel 
6227fc925fdSRoman Zippel 		switch (mode) {
6237fc925fdSRoman Zippel 		case menuMode:
6247fc925fdSRoman Zippel 			if (!(child->flags & MENU_ROOT))
6257fc925fdSRoman Zippel 				goto hide;
6267fc925fdSRoman Zippel 			break;
6277fc925fdSRoman Zippel 		case symbolMode:
6287fc925fdSRoman Zippel 			if (child->flags & MENU_ROOT)
6297fc925fdSRoman Zippel 				goto hide;
6307fc925fdSRoman Zippel 			break;
6317fc925fdSRoman Zippel 		default:
6327fc925fdSRoman Zippel 			break;
6337fc925fdSRoman Zippel 		}
6347fc925fdSRoman Zippel 
6357fc925fdSRoman Zippel 		visible = menu_is_visible(child);
63639a4897cSLi Zefan 		if (!menuSkip(child)) {
637ed8b4d4dSCyrill V. Gorcunov 			if (!child->sym && !child->list && !child->prompt)
638ed8b4d4dSCyrill V. Gorcunov 				continue;
6397fc925fdSRoman Zippel 			if (!item || item->menu != child)
6407fc925fdSRoman Zippel 				item = new ConfigItem(parent, last, child, visible);
6417fc925fdSRoman Zippel 			else
6427fc925fdSRoman Zippel 				item->testUpdateMenu(visible);
6437fc925fdSRoman Zippel 
6447fc925fdSRoman Zippel 			if (mode == fullMode || mode == menuMode || type != P_MENU)
6457fc925fdSRoman Zippel 				updateMenuList(item, child);
6467fc925fdSRoman Zippel 			else
6477fc925fdSRoman Zippel 				updateMenuList(item, 0);
6487fc925fdSRoman Zippel 			last = item;
6497fc925fdSRoman Zippel 			continue;
6507fc925fdSRoman Zippel 		}
6517fc925fdSRoman Zippel 	hide:
6527fc925fdSRoman Zippel 		if (item && item->menu == child) {
6537fc925fdSRoman Zippel 			last = parent->firstChild();
6547fc925fdSRoman Zippel 			if (last == item)
6557fc925fdSRoman Zippel 				last = 0;
6567fc925fdSRoman Zippel 			else while (last->nextSibling() != item)
6577fc925fdSRoman Zippel 				last = last->nextSibling();
6587fc925fdSRoman Zippel 			delete item;
6597fc925fdSRoman Zippel 		}
6607fc925fdSRoman Zippel 	}
6617fc925fdSRoman Zippel }
6627fc925fdSRoman Zippel 
6631da177e4SLinus Torvalds void ConfigList::keyPressEvent(QKeyEvent* ev)
6641da177e4SLinus Torvalds {
665133c5f7cSAlexander Stein 	Q3ListViewItem* i = currentItem();
6661da177e4SLinus Torvalds 	ConfigItem* item;
6671da177e4SLinus Torvalds 	struct menu *menu;
6681da177e4SLinus Torvalds 	enum prop_type type;
6691da177e4SLinus Torvalds 
670fbb86374SMarkus Heidelberg 	if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
6711da177e4SLinus Torvalds 		emit parentSelected();
6721da177e4SLinus Torvalds 		ev->accept();
6731da177e4SLinus Torvalds 		return;
6741da177e4SLinus Torvalds 	}
6751da177e4SLinus Torvalds 
6761da177e4SLinus Torvalds 	if (!i) {
6771da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
6781da177e4SLinus Torvalds 		return;
6791da177e4SLinus Torvalds 	}
6801da177e4SLinus Torvalds 	item = (ConfigItem*)i;
6811da177e4SLinus Torvalds 
6821da177e4SLinus Torvalds 	switch (ev->key()) {
683fbb86374SMarkus Heidelberg 	case Qt::Key_Return:
684fbb86374SMarkus Heidelberg 	case Qt::Key_Enter:
6851da177e4SLinus Torvalds 		if (item->goParent) {
6861da177e4SLinus Torvalds 			emit parentSelected();
6871da177e4SLinus Torvalds 			break;
6881da177e4SLinus Torvalds 		}
6891da177e4SLinus Torvalds 		menu = item->menu;
6901da177e4SLinus Torvalds 		if (!menu)
6911da177e4SLinus Torvalds 			break;
6921da177e4SLinus Torvalds 		type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
6931da177e4SLinus Torvalds 		if (type == P_MENU && rootEntry != menu &&
6941da177e4SLinus Torvalds 		    mode != fullMode && mode != menuMode) {
6951da177e4SLinus Torvalds 			emit menuSelected(menu);
6961da177e4SLinus Torvalds 			break;
6971da177e4SLinus Torvalds 		}
698fbb86374SMarkus Heidelberg 	case Qt::Key_Space:
6991da177e4SLinus Torvalds 		changeValue(item);
7001da177e4SLinus Torvalds 		break;
701fbb86374SMarkus Heidelberg 	case Qt::Key_N:
7021da177e4SLinus Torvalds 		setValue(item, no);
7031da177e4SLinus Torvalds 		break;
704fbb86374SMarkus Heidelberg 	case Qt::Key_M:
7051da177e4SLinus Torvalds 		setValue(item, mod);
7061da177e4SLinus Torvalds 		break;
707fbb86374SMarkus Heidelberg 	case Qt::Key_Y:
7081da177e4SLinus Torvalds 		setValue(item, yes);
7091da177e4SLinus Torvalds 		break;
7101da177e4SLinus Torvalds 	default:
7111da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
7121da177e4SLinus Torvalds 		return;
7131da177e4SLinus Torvalds 	}
7141da177e4SLinus Torvalds 	ev->accept();
7151da177e4SLinus Torvalds }
7161da177e4SLinus Torvalds 
7171da177e4SLinus Torvalds void ConfigList::contentsMousePressEvent(QMouseEvent* e)
7181da177e4SLinus Torvalds {
7191da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
7201da177e4SLinus Torvalds 	//printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
7211da177e4SLinus Torvalds 	Parent::contentsMousePressEvent(e);
7221da177e4SLinus Torvalds }
7231da177e4SLinus Torvalds 
7241da177e4SLinus Torvalds void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
7251da177e4SLinus Torvalds {
7261da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
7271da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
7281da177e4SLinus Torvalds 	struct menu *menu;
7291da177e4SLinus Torvalds 	enum prop_type ptype;
7301da177e4SLinus Torvalds 	const QPixmap* pm;
7311da177e4SLinus Torvalds 	int idx, x;
7321da177e4SLinus Torvalds 
7331da177e4SLinus Torvalds 	if (!item)
7341da177e4SLinus Torvalds 		goto skip;
7351da177e4SLinus Torvalds 
7361da177e4SLinus Torvalds 	menu = item->menu;
7371da177e4SLinus Torvalds 	x = header()->offset() + p.x();
7381da177e4SLinus Torvalds 	idx = colRevMap[header()->sectionAt(x)];
7391da177e4SLinus Torvalds 	switch (idx) {
7401da177e4SLinus Torvalds 	case promptColIdx:
7411da177e4SLinus Torvalds 		pm = item->pixmap(promptColIdx);
7421da177e4SLinus Torvalds 		if (pm) {
7431da177e4SLinus Torvalds 			int off = header()->sectionPos(0) + itemMargin() +
7441da177e4SLinus Torvalds 				treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
7451da177e4SLinus Torvalds 			if (x >= off && x < off + pm->width()) {
7461da177e4SLinus Torvalds 				if (item->goParent) {
7471da177e4SLinus Torvalds 					emit parentSelected();
7481da177e4SLinus Torvalds 					break;
7491da177e4SLinus Torvalds 				} else if (!menu)
7501da177e4SLinus Torvalds 					break;
7511da177e4SLinus Torvalds 				ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7521da177e4SLinus Torvalds 				if (ptype == P_MENU && rootEntry != menu &&
7531da177e4SLinus Torvalds 				    mode != fullMode && mode != menuMode)
7541da177e4SLinus Torvalds 					emit menuSelected(menu);
7551da177e4SLinus Torvalds 				else
7561da177e4SLinus Torvalds 					changeValue(item);
7571da177e4SLinus Torvalds 			}
7581da177e4SLinus Torvalds 		}
7591da177e4SLinus Torvalds 		break;
7601da177e4SLinus Torvalds 	case noColIdx:
7611da177e4SLinus Torvalds 		setValue(item, no);
7621da177e4SLinus Torvalds 		break;
7631da177e4SLinus Torvalds 	case modColIdx:
7641da177e4SLinus Torvalds 		setValue(item, mod);
7651da177e4SLinus Torvalds 		break;
7661da177e4SLinus Torvalds 	case yesColIdx:
7671da177e4SLinus Torvalds 		setValue(item, yes);
7681da177e4SLinus Torvalds 		break;
7691da177e4SLinus Torvalds 	case dataColIdx:
7701da177e4SLinus Torvalds 		changeValue(item);
7711da177e4SLinus Torvalds 		break;
7721da177e4SLinus Torvalds 	}
7731da177e4SLinus Torvalds 
7741da177e4SLinus Torvalds skip:
7751da177e4SLinus Torvalds 	//printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
7761da177e4SLinus Torvalds 	Parent::contentsMouseReleaseEvent(e);
7771da177e4SLinus Torvalds }
7781da177e4SLinus Torvalds 
7791da177e4SLinus Torvalds void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
7801da177e4SLinus Torvalds {
7811da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
7821da177e4SLinus Torvalds 	//printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
7831da177e4SLinus Torvalds 	Parent::contentsMouseMoveEvent(e);
7841da177e4SLinus Torvalds }
7851da177e4SLinus Torvalds 
7861da177e4SLinus Torvalds void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
7871da177e4SLinus Torvalds {
7881da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
7891da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
7901da177e4SLinus Torvalds 	struct menu *menu;
7911da177e4SLinus Torvalds 	enum prop_type ptype;
7921da177e4SLinus Torvalds 
7931da177e4SLinus Torvalds 	if (!item)
7941da177e4SLinus Torvalds 		goto skip;
7951da177e4SLinus Torvalds 	if (item->goParent) {
7961da177e4SLinus Torvalds 		emit parentSelected();
7971da177e4SLinus Torvalds 		goto skip;
7981da177e4SLinus Torvalds 	}
7991da177e4SLinus Torvalds 	menu = item->menu;
8001da177e4SLinus Torvalds 	if (!menu)
8011da177e4SLinus Torvalds 		goto skip;
8021da177e4SLinus Torvalds 	ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
8031da177e4SLinus Torvalds 	if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
8041da177e4SLinus Torvalds 		emit menuSelected(menu);
8051da177e4SLinus Torvalds 	else if (menu->sym)
8061da177e4SLinus Torvalds 		changeValue(item);
8071da177e4SLinus Torvalds 
8081da177e4SLinus Torvalds skip:
8091da177e4SLinus Torvalds 	//printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
8101da177e4SLinus Torvalds 	Parent::contentsMouseDoubleClickEvent(e);
8111da177e4SLinus Torvalds }
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds void ConfigList::focusInEvent(QFocusEvent *e)
8141da177e4SLinus Torvalds {
815b65a47e1SRoman Zippel 	struct menu *menu = NULL;
816b65a47e1SRoman Zippel 
8171da177e4SLinus Torvalds 	Parent::focusInEvent(e);
8181da177e4SLinus Torvalds 
819b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem *)currentItem();
820b65a47e1SRoman Zippel 	if (item) {
8211da177e4SLinus Torvalds 		setSelected(item, TRUE);
822b65a47e1SRoman Zippel 		menu = item->menu;
823b65a47e1SRoman Zippel 	}
824b65a47e1SRoman Zippel 	emit gotFocus(menu);
8251da177e4SLinus Torvalds }
8261da177e4SLinus Torvalds 
8277fc925fdSRoman Zippel void ConfigList::contextMenuEvent(QContextMenuEvent *e)
8287fc925fdSRoman Zippel {
8297fc925fdSRoman Zippel 	if (e->y() <= header()->geometry().bottom()) {
8307fc925fdSRoman Zippel 		if (!headerPopup) {
831133c5f7cSAlexander Stein 			Q3Action *action;
8327fc925fdSRoman Zippel 
833133c5f7cSAlexander Stein 			headerPopup = new Q3PopupMenu(this);
834133c5f7cSAlexander Stein 			action = new Q3Action(NULL, _("Show Name"), 0, this);
8357fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8367fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8377fc925fdSRoman Zippel 				  parent(), SLOT(setShowName(bool)));
8387fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showNameChanged(bool)),
8397fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8407fc925fdSRoman Zippel 			  action->setOn(showName);
8417fc925fdSRoman Zippel 			  action->addTo(headerPopup);
842133c5f7cSAlexander Stein 			action = new Q3Action(NULL, _("Show Range"), 0, this);
8437fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8447fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8457fc925fdSRoman Zippel 				  parent(), SLOT(setShowRange(bool)));
8467fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showRangeChanged(bool)),
8477fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8487fc925fdSRoman Zippel 			  action->setOn(showRange);
8497fc925fdSRoman Zippel 			  action->addTo(headerPopup);
850133c5f7cSAlexander Stein 			action = new Q3Action(NULL, _("Show Data"), 0, this);
8517fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8527fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8537fc925fdSRoman Zippel 				  parent(), SLOT(setShowData(bool)));
8547fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showDataChanged(bool)),
8557fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8567fc925fdSRoman Zippel 			  action->setOn(showData);
8577fc925fdSRoman Zippel 			  action->addTo(headerPopup);
8587fc925fdSRoman Zippel 		}
8597fc925fdSRoman Zippel 		headerPopup->exec(e->globalPos());
8607fc925fdSRoman Zippel 		e->accept();
8617fc925fdSRoman Zippel 	} else
8627fc925fdSRoman Zippel 		e->ignore();
8637fc925fdSRoman Zippel }
8647fc925fdSRoman Zippel 
8651da177e4SLinus Torvalds ConfigView*ConfigView::viewList;
86639a4897cSLi Zefan QAction *ConfigView::showNormalAction;
86739a4897cSLi Zefan QAction *ConfigView::showAllAction;
86839a4897cSLi Zefan QAction *ConfigView::showPromptAction;
8691da177e4SLinus Torvalds 
8707fc925fdSRoman Zippel ConfigView::ConfigView(QWidget* parent, const char *name)
8717fc925fdSRoman Zippel 	: Parent(parent, name)
8721da177e4SLinus Torvalds {
8737fc925fdSRoman Zippel 	list = new ConfigList(this, name);
8741da177e4SLinus Torvalds 	lineEdit = new ConfigLineEdit(this);
8751da177e4SLinus Torvalds 	lineEdit->hide();
8761da177e4SLinus Torvalds 
8771da177e4SLinus Torvalds 	this->nextView = viewList;
8781da177e4SLinus Torvalds 	viewList = this;
8791da177e4SLinus Torvalds }
8801da177e4SLinus Torvalds 
8811da177e4SLinus Torvalds ConfigView::~ConfigView(void)
8821da177e4SLinus Torvalds {
8831da177e4SLinus Torvalds 	ConfigView** vp;
8841da177e4SLinus Torvalds 
8851da177e4SLinus Torvalds 	for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
8861da177e4SLinus Torvalds 		if (*vp == this) {
8871da177e4SLinus Torvalds 			*vp = nextView;
8881da177e4SLinus Torvalds 			break;
8891da177e4SLinus Torvalds 		}
8901da177e4SLinus Torvalds 	}
8911da177e4SLinus Torvalds }
8921da177e4SLinus Torvalds 
89339a4897cSLi Zefan void ConfigView::setOptionMode(QAction *act)
8947fc925fdSRoman Zippel {
89539a4897cSLi Zefan 	if (act == showNormalAction)
89639a4897cSLi Zefan 		list->optMode = normalOpt;
89739a4897cSLi Zefan 	else if (act == showAllAction)
89839a4897cSLi Zefan 		list->optMode = allOpt;
89939a4897cSLi Zefan 	else
90039a4897cSLi Zefan 		list->optMode = promptOpt;
90139a4897cSLi Zefan 
9027fc925fdSRoman Zippel 	list->updateListAll();
9037fc925fdSRoman Zippel }
9047fc925fdSRoman Zippel 
9057fc925fdSRoman Zippel void ConfigView::setShowName(bool b)
9067fc925fdSRoman Zippel {
9077fc925fdSRoman Zippel 	if (list->showName != b) {
9087fc925fdSRoman Zippel 		list->showName = b;
9097fc925fdSRoman Zippel 		list->reinit();
9107fc925fdSRoman Zippel 		emit showNameChanged(b);
9117fc925fdSRoman Zippel 	}
9127fc925fdSRoman Zippel }
9137fc925fdSRoman Zippel 
9147fc925fdSRoman Zippel void ConfigView::setShowRange(bool b)
9157fc925fdSRoman Zippel {
9167fc925fdSRoman Zippel 	if (list->showRange != b) {
9177fc925fdSRoman Zippel 		list->showRange = b;
9187fc925fdSRoman Zippel 		list->reinit();
9197fc925fdSRoman Zippel 		emit showRangeChanged(b);
9207fc925fdSRoman Zippel 	}
9217fc925fdSRoman Zippel }
9227fc925fdSRoman Zippel 
9237fc925fdSRoman Zippel void ConfigView::setShowData(bool b)
9247fc925fdSRoman Zippel {
9257fc925fdSRoman Zippel 	if (list->showData != b) {
9267fc925fdSRoman Zippel 		list->showData = b;
9277fc925fdSRoman Zippel 		list->reinit();
9287fc925fdSRoman Zippel 		emit showDataChanged(b);
9297fc925fdSRoman Zippel 	}
9307fc925fdSRoman Zippel }
9317fc925fdSRoman Zippel 
9327fc925fdSRoman Zippel void ConfigList::setAllOpen(bool open)
9337fc925fdSRoman Zippel {
934133c5f7cSAlexander Stein 	Q3ListViewItemIterator it(this);
9357fc925fdSRoman Zippel 
9367fc925fdSRoman Zippel 	for (; it.current(); it++)
9377fc925fdSRoman Zippel 		it.current()->setOpen(open);
9387fc925fdSRoman Zippel }
9397fc925fdSRoman Zippel 
9401da177e4SLinus Torvalds void ConfigView::updateList(ConfigItem* item)
9411da177e4SLinus Torvalds {
9421da177e4SLinus Torvalds 	ConfigView* v;
9431da177e4SLinus Torvalds 
9441da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9451da177e4SLinus Torvalds 		v->list->updateList(item);
9461da177e4SLinus Torvalds }
9471da177e4SLinus Torvalds 
9481da177e4SLinus Torvalds void ConfigView::updateListAll(void)
9491da177e4SLinus Torvalds {
9501da177e4SLinus Torvalds 	ConfigView* v;
9511da177e4SLinus Torvalds 
9521da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9531da177e4SLinus Torvalds 		v->list->updateListAll();
9541da177e4SLinus Torvalds }
9551da177e4SLinus Torvalds 
95643bf612aSRoman Zippel ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
957133c5f7cSAlexander Stein 	: Parent(parent, name), sym(0), _menu(0)
9581da177e4SLinus Torvalds {
9597fc925fdSRoman Zippel 	if (name) {
9607fc925fdSRoman Zippel 		configSettings->beginGroup(name);
9617fc925fdSRoman Zippel 		_showDebug = configSettings->readBoolEntry("/showDebug", false);
9627fc925fdSRoman Zippel 		configSettings->endGroup();
9637fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
9647fc925fdSRoman Zippel 	}
9657fc925fdSRoman Zippel }
9667fc925fdSRoman Zippel 
9677fc925fdSRoman Zippel void ConfigInfoView::saveSettings(void)
9687fc925fdSRoman Zippel {
9697fc925fdSRoman Zippel 	if (name()) {
9707fc925fdSRoman Zippel 		configSettings->beginGroup(name());
9717fc925fdSRoman Zippel 		configSettings->writeEntry("/showDebug", showDebug());
9727fc925fdSRoman Zippel 		configSettings->endGroup();
9737fc925fdSRoman Zippel 	}
9741da177e4SLinus Torvalds }
9751da177e4SLinus Torvalds 
97643bf612aSRoman Zippel void ConfigInfoView::setShowDebug(bool b)
9771da177e4SLinus Torvalds {
97843bf612aSRoman Zippel 	if (_showDebug != b) {
97943bf612aSRoman Zippel 		_showDebug = b;
980133c5f7cSAlexander Stein 		if (_menu)
98143bf612aSRoman Zippel 			menuInfo();
982ab45d190SRoman Zippel 		else if (sym)
983ab45d190SRoman Zippel 			symbolInfo();
98443bf612aSRoman Zippel 		emit showDebugChanged(b);
9851da177e4SLinus Torvalds 	}
9861da177e4SLinus Torvalds }
9871da177e4SLinus Torvalds 
98843bf612aSRoman Zippel void ConfigInfoView::setInfo(struct menu *m)
9891da177e4SLinus Torvalds {
990133c5f7cSAlexander Stein 	if (_menu == m)
991b65a47e1SRoman Zippel 		return;
992133c5f7cSAlexander Stein 	_menu = m;
9936fa1da8eSRoman Zippel 	sym = NULL;
994133c5f7cSAlexander Stein 	if (!_menu)
99543bf612aSRoman Zippel 		clear();
9966fa1da8eSRoman Zippel 	else
99743bf612aSRoman Zippel 		menuInfo();
9981da177e4SLinus Torvalds }
9991da177e4SLinus Torvalds 
1000ab45d190SRoman Zippel void ConfigInfoView::symbolInfo(void)
1001ab45d190SRoman Zippel {
1002ab45d190SRoman Zippel 	QString str;
1003ab45d190SRoman Zippel 
1004ab45d190SRoman Zippel 	str += "<big>Symbol: <b>";
1005ab45d190SRoman Zippel 	str += print_filter(sym->name);
1006ab45d190SRoman Zippel 	str += "</b></big><br><br>value: ";
1007ab45d190SRoman Zippel 	str += print_filter(sym_get_string_value(sym));
1008ab45d190SRoman Zippel 	str += "<br>visibility: ";
1009ab45d190SRoman Zippel 	str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1010ab45d190SRoman Zippel 	str += "<br>";
1011ab45d190SRoman Zippel 	str += debug_info(sym);
1012ab45d190SRoman Zippel 
1013ab45d190SRoman Zippel 	setText(str);
1014ab45d190SRoman Zippel }
1015ab45d190SRoman Zippel 
101643bf612aSRoman Zippel void ConfigInfoView::menuInfo(void)
10171da177e4SLinus Torvalds {
10181da177e4SLinus Torvalds 	struct symbol* sym;
10191da177e4SLinus Torvalds 	QString head, debug, help;
102043bf612aSRoman Zippel 
1021133c5f7cSAlexander Stein 	sym = _menu->sym;
10221da177e4SLinus Torvalds 	if (sym) {
1023133c5f7cSAlexander Stein 		if (_menu->prompt) {
10241da177e4SLinus Torvalds 			head += "<big><b>";
1025133c5f7cSAlexander Stein 			head += print_filter(_(_menu->prompt->text));
10261da177e4SLinus Torvalds 			head += "</b></big>";
10271da177e4SLinus Torvalds 			if (sym->name) {
10281da177e4SLinus Torvalds 				head += " (";
1029ab45d190SRoman Zippel 				if (showDebug())
1030ab45d190SRoman Zippel 					head += QString().sprintf("<a href=\"s%p\">", sym);
103143bf612aSRoman Zippel 				head += print_filter(sym->name);
1032ab45d190SRoman Zippel 				if (showDebug())
1033ab45d190SRoman Zippel 					head += "</a>";
10341da177e4SLinus Torvalds 				head += ")";
10351da177e4SLinus Torvalds 			}
10361da177e4SLinus Torvalds 		} else if (sym->name) {
10371da177e4SLinus Torvalds 			head += "<big><b>";
1038ab45d190SRoman Zippel 			if (showDebug())
1039ab45d190SRoman Zippel 				head += QString().sprintf("<a href=\"s%p\">", sym);
104043bf612aSRoman Zippel 			head += print_filter(sym->name);
1041ab45d190SRoman Zippel 			if (showDebug())
1042ab45d190SRoman Zippel 				head += "</a>";
10431da177e4SLinus Torvalds 			head += "</b></big>";
10441da177e4SLinus Torvalds 		}
10451da177e4SLinus Torvalds 		head += "<br><br>";
10461da177e4SLinus Torvalds 
104743bf612aSRoman Zippel 		if (showDebug())
104843bf612aSRoman Zippel 			debug = debug_info(sym);
104943bf612aSRoman Zippel 
1050d74c15f3SCheng Renquan 		struct gstr help_gstr = str_new();
1051133c5f7cSAlexander Stein 		menu_get_ext_help(_menu, &help_gstr);
1052d74c15f3SCheng Renquan 		help = print_filter(str_get(&help_gstr));
1053d74c15f3SCheng Renquan 		str_free(&help_gstr);
1054133c5f7cSAlexander Stein 	} else if (_menu->prompt) {
105543bf612aSRoman Zippel 		head += "<big><b>";
1056133c5f7cSAlexander Stein 		head += print_filter(_(_menu->prompt->text));
105743bf612aSRoman Zippel 		head += "</b></big><br><br>";
105843bf612aSRoman Zippel 		if (showDebug()) {
1059133c5f7cSAlexander Stein 			if (_menu->prompt->visible.expr) {
106043bf612aSRoman Zippel 				debug += "&nbsp;&nbsp;dep: ";
1061133c5f7cSAlexander Stein 				expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
106243bf612aSRoman Zippel 				debug += "<br><br>";
106343bf612aSRoman Zippel 			}
106443bf612aSRoman Zippel 		}
106543bf612aSRoman Zippel 	}
106643bf612aSRoman Zippel 	if (showDebug())
1067133c5f7cSAlexander Stein 		debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
106843bf612aSRoman Zippel 
106943bf612aSRoman Zippel 	setText(head + debug + help);
107043bf612aSRoman Zippel }
107143bf612aSRoman Zippel 
107243bf612aSRoman Zippel QString ConfigInfoView::debug_info(struct symbol *sym)
107343bf612aSRoman Zippel {
107443bf612aSRoman Zippel 	QString debug;
107543bf612aSRoman Zippel 
10761da177e4SLinus Torvalds 	debug += "type: ";
10771da177e4SLinus Torvalds 	debug += print_filter(sym_type_name(sym->type));
10781da177e4SLinus Torvalds 	if (sym_is_choice(sym))
10791da177e4SLinus Torvalds 		debug += " (choice)";
10801da177e4SLinus Torvalds 	debug += "<br>";
10811da177e4SLinus Torvalds 	if (sym->rev_dep.expr) {
10821da177e4SLinus Torvalds 		debug += "reverse dep: ";
10831da177e4SLinus Torvalds 		expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
10841da177e4SLinus Torvalds 		debug += "<br>";
10851da177e4SLinus Torvalds 	}
10861da177e4SLinus Torvalds 	for (struct property *prop = sym->prop; prop; prop = prop->next) {
10871da177e4SLinus Torvalds 		switch (prop->type) {
10881da177e4SLinus Torvalds 		case P_PROMPT:
10891da177e4SLinus Torvalds 		case P_MENU:
1090ab45d190SRoman Zippel 			debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
10913b9fa093SArnaldo Carvalho de Melo 			debug += print_filter(_(prop->text));
1092ab45d190SRoman Zippel 			debug += "</a><br>";
10931da177e4SLinus Torvalds 			break;
10941da177e4SLinus Torvalds 		case P_DEFAULT:
109593449082SRoman Zippel 		case P_SELECT:
109693449082SRoman Zippel 		case P_RANGE:
109793449082SRoman Zippel 		case P_ENV:
109893449082SRoman Zippel 			debug += prop_get_type_name(prop->type);
109993449082SRoman Zippel 			debug += ": ";
11001da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
11011da177e4SLinus Torvalds 			debug += "<br>";
11021da177e4SLinus Torvalds 			break;
11031da177e4SLinus Torvalds 		case P_CHOICE:
11041da177e4SLinus Torvalds 			if (sym_is_choice(sym)) {
11051da177e4SLinus Torvalds 				debug += "choice: ";
11061da177e4SLinus Torvalds 				expr_print(prop->expr, expr_print_help, &debug, E_NONE);
11071da177e4SLinus Torvalds 				debug += "<br>";
11081da177e4SLinus Torvalds 			}
11091da177e4SLinus Torvalds 			break;
11101da177e4SLinus Torvalds 		default:
11111da177e4SLinus Torvalds 			debug += "unknown property: ";
11121da177e4SLinus Torvalds 			debug += prop_get_type_name(prop->type);
11131da177e4SLinus Torvalds 			debug += "<br>";
11141da177e4SLinus Torvalds 		}
11151da177e4SLinus Torvalds 		if (prop->visible.expr) {
11161da177e4SLinus Torvalds 			debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
11171da177e4SLinus Torvalds 			expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
11181da177e4SLinus Torvalds 			debug += "<br>";
11191da177e4SLinus Torvalds 		}
11201da177e4SLinus Torvalds 	}
11211da177e4SLinus Torvalds 	debug += "<br>";
112243bf612aSRoman Zippel 
112343bf612aSRoman Zippel 	return debug;
11241da177e4SLinus Torvalds }
11251da177e4SLinus Torvalds 
112643bf612aSRoman Zippel QString ConfigInfoView::print_filter(const QString &str)
112743bf612aSRoman Zippel {
112843bf612aSRoman Zippel 	QRegExp re("[<>&\"\\n]");
112943bf612aSRoman Zippel 	QString res = str;
113043bf612aSRoman Zippel 	for (int i = 0; (i = res.find(re, i)) >= 0;) {
113143bf612aSRoman Zippel 		switch (res[i].latin1()) {
113243bf612aSRoman Zippel 		case '<':
113343bf612aSRoman Zippel 			res.replace(i, 1, "&lt;");
113443bf612aSRoman Zippel 			i += 4;
113543bf612aSRoman Zippel 			break;
113643bf612aSRoman Zippel 		case '>':
113743bf612aSRoman Zippel 			res.replace(i, 1, "&gt;");
113843bf612aSRoman Zippel 			i += 4;
113943bf612aSRoman Zippel 			break;
114043bf612aSRoman Zippel 		case '&':
114143bf612aSRoman Zippel 			res.replace(i, 1, "&amp;");
114243bf612aSRoman Zippel 			i += 5;
114343bf612aSRoman Zippel 			break;
114443bf612aSRoman Zippel 		case '"':
114543bf612aSRoman Zippel 			res.replace(i, 1, "&quot;");
114643bf612aSRoman Zippel 			i += 6;
114743bf612aSRoman Zippel 			break;
114843bf612aSRoman Zippel 		case '\n':
114943bf612aSRoman Zippel 			res.replace(i, 1, "<br>");
115043bf612aSRoman Zippel 			i += 4;
115143bf612aSRoman Zippel 			break;
11521da177e4SLinus Torvalds 		}
11531da177e4SLinus Torvalds 	}
115443bf612aSRoman Zippel 	return res;
11551da177e4SLinus Torvalds }
115643bf612aSRoman Zippel 
1157ab45d190SRoman Zippel void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
115843bf612aSRoman Zippel {
1159ab45d190SRoman Zippel 	QString* text = reinterpret_cast<QString*>(data);
1160ab45d190SRoman Zippel 	QString str2 = print_filter(str);
1161ab45d190SRoman Zippel 
1162ab45d190SRoman Zippel 	if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1163ab45d190SRoman Zippel 		*text += QString().sprintf("<a href=\"s%p\">", sym);
1164ab45d190SRoman Zippel 		*text += str2;
1165ab45d190SRoman Zippel 		*text += "</a>";
1166ab45d190SRoman Zippel 	} else
1167ab45d190SRoman Zippel 		*text += str2;
116843bf612aSRoman Zippel }
116943bf612aSRoman Zippel 
1170133c5f7cSAlexander Stein Q3PopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
11717fc925fdSRoman Zippel {
1172133c5f7cSAlexander Stein 	Q3PopupMenu* popup = Parent::createPopupMenu(pos);
1173133c5f7cSAlexander Stein 	Q3Action* action = new Q3Action(NULL, _("Show Debug Info"), 0, popup);
11747fc925fdSRoman Zippel 	  action->setToggleAction(TRUE);
11757fc925fdSRoman Zippel 	  connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
11767fc925fdSRoman Zippel 	  connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
11777fc925fdSRoman Zippel 	  action->setOn(showDebug());
11787fc925fdSRoman Zippel 	popup->insertSeparator();
11797fc925fdSRoman Zippel 	action->addTo(popup);
11807fc925fdSRoman Zippel 	return popup;
11817fc925fdSRoman Zippel }
11827fc925fdSRoman Zippel 
11837fc925fdSRoman Zippel void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
11847fc925fdSRoman Zippel {
11857fc925fdSRoman Zippel 	Parent::contentsContextMenuEvent(e);
11867fc925fdSRoman Zippel }
11877fc925fdSRoman Zippel 
118863431e75SMarco Costalba ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
11897fc925fdSRoman Zippel 	: Parent(parent, name), result(NULL)
119043bf612aSRoman Zippel {
119143bf612aSRoman Zippel 	setCaption("Search Config");
119243bf612aSRoman Zippel 
119343bf612aSRoman Zippel 	QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
119443bf612aSRoman Zippel 	QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
1195c21a2d95SEGRY Gabor 	layout2->addWidget(new QLabel(_("Find:"), this));
119643bf612aSRoman Zippel 	editField = new QLineEdit(this);
119743bf612aSRoman Zippel 	connect(editField, SIGNAL(returnPressed()), SLOT(search()));
119843bf612aSRoman Zippel 	layout2->addWidget(editField);
1199c21a2d95SEGRY Gabor 	searchButton = new QPushButton(_("Search"), this);
120043bf612aSRoman Zippel 	searchButton->setAutoDefault(FALSE);
120143bf612aSRoman Zippel 	connect(searchButton, SIGNAL(clicked()), SLOT(search()));
120243bf612aSRoman Zippel 	layout2->addWidget(searchButton);
120343bf612aSRoman Zippel 	layout1->addLayout(layout2);
120443bf612aSRoman Zippel 
12057fc925fdSRoman Zippel 	split = new QSplitter(this);
12067298b936SMarkus Heidelberg 	split->setOrientation(Qt::Vertical);
12077fc925fdSRoman Zippel 	list = new ConfigView(split, name);
120843bf612aSRoman Zippel 	list->list->mode = listMode;
12097fc925fdSRoman Zippel 	info = new ConfigInfoView(split, name);
121043bf612aSRoman Zippel 	connect(list->list, SIGNAL(menuChanged(struct menu *)),
121143bf612aSRoman Zippel 		info, SLOT(setInfo(struct menu *)));
121263431e75SMarco Costalba 	connect(list->list, SIGNAL(menuChanged(struct menu *)),
121363431e75SMarco Costalba 		parent, SLOT(setMenuLink(struct menu *)));
121463431e75SMarco Costalba 
121543bf612aSRoman Zippel 	layout1->addWidget(split);
12167fc925fdSRoman Zippel 
12177fc925fdSRoman Zippel 	if (name) {
12187fc925fdSRoman Zippel 		int x, y, width, height;
12197fc925fdSRoman Zippel 		bool ok;
12207fc925fdSRoman Zippel 
12217fc925fdSRoman Zippel 		configSettings->beginGroup(name);
12227fc925fdSRoman Zippel 		width = configSettings->readNumEntry("/window width", parent->width() / 2);
12237fc925fdSRoman Zippel 		height = configSettings->readNumEntry("/window height", parent->height() / 2);
12247fc925fdSRoman Zippel 		resize(width, height);
12257fc925fdSRoman Zippel 		x = configSettings->readNumEntry("/window x", 0, &ok);
12267fc925fdSRoman Zippel 		if (ok)
12277fc925fdSRoman Zippel 			y = configSettings->readNumEntry("/window y", 0, &ok);
12287fc925fdSRoman Zippel 		if (ok)
12297fc925fdSRoman Zippel 			move(x, y);
1230133c5f7cSAlexander Stein 		Q3ValueList<int> sizes = configSettings->readSizes("/split", &ok);
12317fc925fdSRoman Zippel 		if (ok)
12327fc925fdSRoman Zippel 			split->setSizes(sizes);
12337fc925fdSRoman Zippel 		configSettings->endGroup();
12347fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
12357fc925fdSRoman Zippel 	}
12367fc925fdSRoman Zippel }
12377fc925fdSRoman Zippel 
12387fc925fdSRoman Zippel void ConfigSearchWindow::saveSettings(void)
12397fc925fdSRoman Zippel {
12407fc925fdSRoman Zippel 	if (name()) {
12417fc925fdSRoman Zippel 		configSettings->beginGroup(name());
12427fc925fdSRoman Zippel 		configSettings->writeEntry("/window x", pos().x());
12437fc925fdSRoman Zippel 		configSettings->writeEntry("/window y", pos().y());
12447fc925fdSRoman Zippel 		configSettings->writeEntry("/window width", size().width());
12457fc925fdSRoman Zippel 		configSettings->writeEntry("/window height", size().height());
12467fc925fdSRoman Zippel 		configSettings->writeSizes("/split", split->sizes());
12477fc925fdSRoman Zippel 		configSettings->endGroup();
12487fc925fdSRoman Zippel 	}
124943bf612aSRoman Zippel }
125043bf612aSRoman Zippel 
125143bf612aSRoman Zippel void ConfigSearchWindow::search(void)
125243bf612aSRoman Zippel {
125343bf612aSRoman Zippel 	struct symbol **p;
125443bf612aSRoman Zippel 	struct property *prop;
125543bf612aSRoman Zippel 	ConfigItem *lastItem = NULL;
125643bf612aSRoman Zippel 
125743bf612aSRoman Zippel 	free(result);
125843bf612aSRoman Zippel 	list->list->clear();
1259786fb18dSCyrill V. Gorcunov 	info->clear();
126043bf612aSRoman Zippel 
126143bf612aSRoman Zippel 	result = sym_re_search(editField->text().latin1());
126243bf612aSRoman Zippel 	if (!result)
126343bf612aSRoman Zippel 		return;
126443bf612aSRoman Zippel 	for (p = result; *p; p++) {
126543bf612aSRoman Zippel 		for_all_prompts((*p), prop)
126643bf612aSRoman Zippel 			lastItem = new ConfigItem(list->list, lastItem, prop->menu,
126743bf612aSRoman Zippel 						  menu_is_visible(prop->menu));
126843bf612aSRoman Zippel 	}
126943bf612aSRoman Zippel }
127043bf612aSRoman Zippel 
127143bf612aSRoman Zippel /*
127243bf612aSRoman Zippel  * Construct the complete config widget
127343bf612aSRoman Zippel  */
127443bf612aSRoman Zippel ConfigMainWindow::ConfigMainWindow(void)
1275f12aa704SRoman Zippel 	: searchWindow(0)
127643bf612aSRoman Zippel {
127743bf612aSRoman Zippel 	QMenuBar* menu;
12787fc925fdSRoman Zippel 	bool ok;
127943bf612aSRoman Zippel 	int x, y, width, height;
1280a54bb701SRandy Dunlap 	char title[256];
128143bf612aSRoman Zippel 
12828d90c97eSMarkus Heidelberg 	QDesktopWidget *d = configApp->desktop();
12830954828fSArnaud Lacombe 	snprintf(title, sizeof(title), "%s%s",
12840954828fSArnaud Lacombe 		rootmenu.prompt->text,
128576a136c4SMichal Marek #if QT_VERSION < 0x040000
128676a136c4SMichal Marek 		" (Qt3)"
128776a136c4SMichal Marek #else
128876a136c4SMichal Marek 		""
128976a136c4SMichal Marek #endif
129076a136c4SMichal Marek 		);
1291a54bb701SRandy Dunlap 	setCaption(title);
129243bf612aSRoman Zippel 
12937fc925fdSRoman Zippel 	width = configSettings->readNumEntry("/window width", d->width() - 64);
12947fc925fdSRoman Zippel 	height = configSettings->readNumEntry("/window height", d->height() - 64);
129543bf612aSRoman Zippel 	resize(width, height);
12967fc925fdSRoman Zippel 	x = configSettings->readNumEntry("/window x", 0, &ok);
129743bf612aSRoman Zippel 	if (ok)
12987fc925fdSRoman Zippel 		y = configSettings->readNumEntry("/window y", 0, &ok);
129943bf612aSRoman Zippel 	if (ok)
130043bf612aSRoman Zippel 		move(x, y);
130143bf612aSRoman Zippel 
130243bf612aSRoman Zippel 	split1 = new QSplitter(this);
13037298b936SMarkus Heidelberg 	split1->setOrientation(Qt::Horizontal);
130443bf612aSRoman Zippel 	setCentralWidget(split1);
130543bf612aSRoman Zippel 
13067fc925fdSRoman Zippel 	menuView = new ConfigView(split1, "menu");
130743bf612aSRoman Zippel 	menuList = menuView->list;
130843bf612aSRoman Zippel 
130943bf612aSRoman Zippel 	split2 = new QSplitter(split1);
13107298b936SMarkus Heidelberg 	split2->setOrientation(Qt::Vertical);
131143bf612aSRoman Zippel 
131243bf612aSRoman Zippel 	// create config tree
13137fc925fdSRoman Zippel 	configView = new ConfigView(split2, "config");
131443bf612aSRoman Zippel 	configList = configView->list;
131543bf612aSRoman Zippel 
13167fc925fdSRoman Zippel 	helpText = new ConfigInfoView(split2, "help");
131743bf612aSRoman Zippel 	helpText->setTextFormat(Qt::RichText);
131843bf612aSRoman Zippel 
131943bf612aSRoman Zippel 	setTabOrder(configList, helpText);
132043bf612aSRoman Zippel 	configList->setFocus();
132143bf612aSRoman Zippel 
132243bf612aSRoman Zippel 	menu = menuBar();
1323133c5f7cSAlexander Stein 	toolBar = new Q3ToolBar("Tools", this);
132443bf612aSRoman Zippel 
1325133c5f7cSAlexander Stein 	backAction = new Q3Action("Back", QPixmap(xpm_back), _("Back"), 0, this);
132643bf612aSRoman Zippel 	  connect(backAction, SIGNAL(activated()), SLOT(goBack()));
132743bf612aSRoman Zippel 	  backAction->setEnabled(FALSE);
1328133c5f7cSAlexander Stein 	Q3Action *quitAction = new Q3Action("Quit", _("&Quit"), Qt::CTRL + Qt::Key_Q, this);
132943bf612aSRoman Zippel 	  connect(quitAction, SIGNAL(activated()), SLOT(close()));
1330133c5f7cSAlexander Stein 	Q3Action *loadAction = new Q3Action("Load", QPixmap(xpm_load), _("&Load"), Qt::CTRL + Qt::Key_L, this);
133143bf612aSRoman Zippel 	  connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
1332133c5f7cSAlexander Stein 	saveAction = new Q3Action("Save", QPixmap(xpm_save), _("&Save"), Qt::CTRL + Qt::Key_S, this);
133343bf612aSRoman Zippel 	  connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
13343b354c55SKarsten Wiese 	conf_set_changed_callback(conf_changed);
13353b354c55SKarsten Wiese 	// Set saveAction's initial state
13363b354c55SKarsten Wiese 	conf_changed();
1337133c5f7cSAlexander Stein 	Q3Action *saveAsAction = new Q3Action("Save As...", _("Save &As..."), 0, this);
133843bf612aSRoman Zippel 	  connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
1339133c5f7cSAlexander Stein 	Q3Action *searchAction = new Q3Action("Find", _("&Find"), Qt::CTRL + Qt::Key_F, this);
134043bf612aSRoman Zippel 	  connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
1341133c5f7cSAlexander Stein 	Q3Action *singleViewAction = new Q3Action("Single View", QPixmap(xpm_single_view), _("Single View"), 0, this);
134243bf612aSRoman Zippel 	  connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
1343133c5f7cSAlexander Stein 	Q3Action *splitViewAction = new Q3Action("Split View", QPixmap(xpm_split_view), _("Split View"), 0, this);
134443bf612aSRoman Zippel 	  connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
1345133c5f7cSAlexander Stein 	Q3Action *fullViewAction = new Q3Action("Full View", QPixmap(xpm_tree_view), _("Full View"), 0, this);
134643bf612aSRoman Zippel 	  connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
134743bf612aSRoman Zippel 
1348133c5f7cSAlexander Stein 	Q3Action *showNameAction = new Q3Action(NULL, _("Show Name"), 0, this);
134943bf612aSRoman Zippel 	  showNameAction->setToggleAction(TRUE);
13507fc925fdSRoman Zippel 	  connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
13517fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
13527fc925fdSRoman Zippel 	  showNameAction->setOn(configView->showName());
1353133c5f7cSAlexander Stein 	Q3Action *showRangeAction = new Q3Action(NULL, _("Show Range"), 0, this);
135443bf612aSRoman Zippel 	  showRangeAction->setToggleAction(TRUE);
13557fc925fdSRoman Zippel 	  connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
13567fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
135743bf612aSRoman Zippel 	  showRangeAction->setOn(configList->showRange);
1358133c5f7cSAlexander Stein 	Q3Action *showDataAction = new Q3Action(NULL, _("Show Data"), 0, this);
135943bf612aSRoman Zippel 	  showDataAction->setToggleAction(TRUE);
13607fc925fdSRoman Zippel 	  connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
13617fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
136243bf612aSRoman Zippel 	  showDataAction->setOn(configList->showData);
136339a4897cSLi Zefan 
136439a4897cSLi Zefan 	QActionGroup *optGroup = new QActionGroup(this);
136539a4897cSLi Zefan 	optGroup->setExclusive(TRUE);
136639a4897cSLi Zefan 	connect(optGroup, SIGNAL(selected(QAction *)), configView,
136739a4897cSLi Zefan 		SLOT(setOptionMode(QAction *)));
136839a4897cSLi Zefan 	connect(optGroup, SIGNAL(selected(QAction *)), menuView,
136939a4897cSLi Zefan 		SLOT(setOptionMode(QAction *)));
137039a4897cSLi Zefan 
1371133c5f7cSAlexander Stein #if QT_VERSION >= 0x040000
1372133c5f7cSAlexander Stein 	configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
1373133c5f7cSAlexander Stein 	configView->showAllAction = new QAction(_("Show All Options"), optGroup);
1374133c5f7cSAlexander Stein 	configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
1375133c5f7cSAlexander Stein #else
1376133c5f7cSAlexander Stein 	configView->showNormalAction = new QAction(_("Show Normal Options"), 0, optGroup);
1377133c5f7cSAlexander Stein 	configView->showAllAction = new QAction(_("Show All Options"), 0, optGroup);
1378133c5f7cSAlexander Stein 	configView->showPromptAction = new QAction(_("Show Prompt Options"), 0, optGroup);
1379133c5f7cSAlexander Stein #endif
138039a4897cSLi Zefan 	configView->showNormalAction->setToggleAction(TRUE);
138139a4897cSLi Zefan 	configView->showNormalAction->setOn(configList->optMode == normalOpt);
138239a4897cSLi Zefan 	configView->showAllAction->setToggleAction(TRUE);
138339a4897cSLi Zefan 	configView->showAllAction->setOn(configList->optMode == allOpt);
138439a4897cSLi Zefan 	configView->showPromptAction->setToggleAction(TRUE);
138539a4897cSLi Zefan 	configView->showPromptAction->setOn(configList->optMode == promptOpt);
138639a4897cSLi Zefan 
1387133c5f7cSAlexander Stein 	Q3Action *showDebugAction = new Q3Action(NULL, _("Show Debug Info"), 0, this);
138843bf612aSRoman Zippel 	  showDebugAction->setToggleAction(TRUE);
138943bf612aSRoman Zippel 	  connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
139043bf612aSRoman Zippel 	  connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
13917fc925fdSRoman Zippel 	  showDebugAction->setOn(helpText->showDebug());
139243bf612aSRoman Zippel 
1393133c5f7cSAlexander Stein 	Q3Action *showIntroAction = new Q3Action(NULL, _("Introduction"), 0, this);
139443bf612aSRoman Zippel 	  connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
1395133c5f7cSAlexander Stein 	Q3Action *showAboutAction = new Q3Action(NULL, _("About"), 0, this);
139643bf612aSRoman Zippel 	  connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
139743bf612aSRoman Zippel 
139843bf612aSRoman Zippel 	// init tool bar
139943bf612aSRoman Zippel 	backAction->addTo(toolBar);
140043bf612aSRoman Zippel 	toolBar->addSeparator();
140143bf612aSRoman Zippel 	loadAction->addTo(toolBar);
140243bf612aSRoman Zippel 	saveAction->addTo(toolBar);
140343bf612aSRoman Zippel 	toolBar->addSeparator();
140443bf612aSRoman Zippel 	singleViewAction->addTo(toolBar);
140543bf612aSRoman Zippel 	splitViewAction->addTo(toolBar);
140643bf612aSRoman Zippel 	fullViewAction->addTo(toolBar);
140743bf612aSRoman Zippel 
140843bf612aSRoman Zippel 	// create config menu
1409133c5f7cSAlexander Stein 	Q3PopupMenu* config = new Q3PopupMenu(this);
1410c21a2d95SEGRY Gabor 	menu->insertItem(_("&File"), config);
141143bf612aSRoman Zippel 	loadAction->addTo(config);
141243bf612aSRoman Zippel 	saveAction->addTo(config);
141343bf612aSRoman Zippel 	saveAsAction->addTo(config);
141443bf612aSRoman Zippel 	config->insertSeparator();
141543bf612aSRoman Zippel 	quitAction->addTo(config);
141643bf612aSRoman Zippel 
141766e7c723SShlomi Fish 	// create edit menu
1418133c5f7cSAlexander Stein 	Q3PopupMenu* editMenu = new Q3PopupMenu(this);
1419c21a2d95SEGRY Gabor 	menu->insertItem(_("&Edit"), editMenu);
142066e7c723SShlomi Fish 	searchAction->addTo(editMenu);
142166e7c723SShlomi Fish 
142243bf612aSRoman Zippel 	// create options menu
1423133c5f7cSAlexander Stein 	Q3PopupMenu* optionMenu = new Q3PopupMenu(this);
1424c21a2d95SEGRY Gabor 	menu->insertItem(_("&Option"), optionMenu);
142543bf612aSRoman Zippel 	showNameAction->addTo(optionMenu);
142643bf612aSRoman Zippel 	showRangeAction->addTo(optionMenu);
142743bf612aSRoman Zippel 	showDataAction->addTo(optionMenu);
142843bf612aSRoman Zippel 	optionMenu->insertSeparator();
142939a4897cSLi Zefan 	optGroup->addTo(optionMenu);
143039a4897cSLi Zefan 	optionMenu->insertSeparator();
143143bf612aSRoman Zippel 
143243bf612aSRoman Zippel 	// create help menu
1433133c5f7cSAlexander Stein 	Q3PopupMenu* helpMenu = new Q3PopupMenu(this);
143443bf612aSRoman Zippel 	menu->insertSeparator();
1435c21a2d95SEGRY Gabor 	menu->insertItem(_("&Help"), helpMenu);
143643bf612aSRoman Zippel 	showIntroAction->addTo(helpMenu);
143743bf612aSRoman Zippel 	showAboutAction->addTo(helpMenu);
143843bf612aSRoman Zippel 
143943bf612aSRoman Zippel 	connect(configList, SIGNAL(menuChanged(struct menu *)),
144043bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
144143bf612aSRoman Zippel 	connect(configList, SIGNAL(menuSelected(struct menu *)),
144243bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
144343bf612aSRoman Zippel 	connect(configList, SIGNAL(parentSelected()),
144443bf612aSRoman Zippel 		SLOT(goBack()));
144543bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuChanged(struct menu *)),
144643bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
144743bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuSelected(struct menu *)),
144843bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
144943bf612aSRoman Zippel 
1450b65a47e1SRoman Zippel 	connect(configList, SIGNAL(gotFocus(struct menu *)),
1451b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1452b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
1453b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1454b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
145543bf612aSRoman Zippel 		SLOT(listFocusChanged(void)));
1456b65a47e1SRoman Zippel 	connect(helpText, SIGNAL(menuSelected(struct menu *)),
1457b65a47e1SRoman Zippel 		SLOT(setMenuLink(struct menu *)));
145843bf612aSRoman Zippel 
14597fc925fdSRoman Zippel 	QString listMode = configSettings->readEntry("/listMode", "symbol");
146043bf612aSRoman Zippel 	if (listMode == "single")
146143bf612aSRoman Zippel 		showSingleView();
146243bf612aSRoman Zippel 	else if (listMode == "full")
146343bf612aSRoman Zippel 		showFullView();
146443bf612aSRoman Zippel 	else /*if (listMode == "split")*/
146543bf612aSRoman Zippel 		showSplitView();
146643bf612aSRoman Zippel 
146743bf612aSRoman Zippel 	// UI setup done, restore splitter positions
1468133c5f7cSAlexander Stein 	Q3ValueList<int> sizes = configSettings->readSizes("/split1", &ok);
146943bf612aSRoman Zippel 	if (ok)
147043bf612aSRoman Zippel 		split1->setSizes(sizes);
147143bf612aSRoman Zippel 
14727fc925fdSRoman Zippel 	sizes = configSettings->readSizes("/split2", &ok);
147343bf612aSRoman Zippel 	if (ok)
147443bf612aSRoman Zippel 		split2->setSizes(sizes);
147543bf612aSRoman Zippel }
147643bf612aSRoman Zippel 
14771da177e4SLinus Torvalds void ConfigMainWindow::loadConfig(void)
14781da177e4SLinus Torvalds {
1479133c5f7cSAlexander Stein 	QString s = Q3FileDialog::getOpenFileName(conf_get_configname(), NULL, this);
14801da177e4SLinus Torvalds 	if (s.isNull())
14811da177e4SLinus Torvalds 		return;
14823b9fa093SArnaldo Carvalho de Melo 	if (conf_read(QFile::encodeName(s)))
1483c21a2d95SEGRY Gabor 		QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
14841da177e4SLinus Torvalds 	ConfigView::updateListAll();
14851da177e4SLinus Torvalds }
14861da177e4SLinus Torvalds 
1487bac6aa86SMichal Marek bool ConfigMainWindow::saveConfig(void)
14881da177e4SLinus Torvalds {
1489bac6aa86SMichal Marek 	if (conf_write(NULL)) {
1490c21a2d95SEGRY Gabor 		QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
1491bac6aa86SMichal Marek 		return false;
1492bac6aa86SMichal Marek 	}
1493bac6aa86SMichal Marek 	return true;
14941da177e4SLinus Torvalds }
14951da177e4SLinus Torvalds 
14961da177e4SLinus Torvalds void ConfigMainWindow::saveConfigAs(void)
14971da177e4SLinus Torvalds {
1498133c5f7cSAlexander Stein 	QString s = Q3FileDialog::getSaveFileName(conf_get_configname(), NULL, this);
14991da177e4SLinus Torvalds 	if (s.isNull())
15001da177e4SLinus Torvalds 		return;
1501d49e4687SArnaud Lacombe 	saveConfig();
15021da177e4SLinus Torvalds }
15031da177e4SLinus Torvalds 
150443bf612aSRoman Zippel void ConfigMainWindow::searchConfig(void)
150543bf612aSRoman Zippel {
150643bf612aSRoman Zippel 	if (!searchWindow)
15077fc925fdSRoman Zippel 		searchWindow = new ConfigSearchWindow(this, "search");
150843bf612aSRoman Zippel 	searchWindow->show();
150943bf612aSRoman Zippel }
151043bf612aSRoman Zippel 
15111da177e4SLinus Torvalds void ConfigMainWindow::changeMenu(struct menu *menu)
15121da177e4SLinus Torvalds {
15131da177e4SLinus Torvalds 	configList->setRootMenu(menu);
1514f253f000SCyrill V. Gorcunov 	if (configList->rootEntry->parent == &rootmenu)
1515f253f000SCyrill V. Gorcunov 		backAction->setEnabled(FALSE);
1516f253f000SCyrill V. Gorcunov 	else
15171da177e4SLinus Torvalds 		backAction->setEnabled(TRUE);
15181da177e4SLinus Torvalds }
15191da177e4SLinus Torvalds 
1520b65a47e1SRoman Zippel void ConfigMainWindow::setMenuLink(struct menu *menu)
1521b65a47e1SRoman Zippel {
1522b65a47e1SRoman Zippel 	struct menu *parent;
1523b65a47e1SRoman Zippel 	ConfigList* list = NULL;
1524b65a47e1SRoman Zippel 	ConfigItem* item;
1525b65a47e1SRoman Zippel 
152639a4897cSLi Zefan 	if (configList->menuSkip(menu))
1527b65a47e1SRoman Zippel 		return;
1528b65a47e1SRoman Zippel 
1529b65a47e1SRoman Zippel 	switch (configList->mode) {
1530b65a47e1SRoman Zippel 	case singleMode:
1531b65a47e1SRoman Zippel 		list = configList;
1532b65a47e1SRoman Zippel 		parent = menu_get_parent_menu(menu);
1533b65a47e1SRoman Zippel 		if (!parent)
1534b65a47e1SRoman Zippel 			return;
1535b65a47e1SRoman Zippel 		list->setRootMenu(parent);
1536b65a47e1SRoman Zippel 		break;
1537b65a47e1SRoman Zippel 	case symbolMode:
1538b65a47e1SRoman Zippel 		if (menu->flags & MENU_ROOT) {
1539b65a47e1SRoman Zippel 			configList->setRootMenu(menu);
1540b65a47e1SRoman Zippel 			configList->clearSelection();
1541b65a47e1SRoman Zippel 			list = menuList;
1542b65a47e1SRoman Zippel 		} else {
1543b65a47e1SRoman Zippel 			list = configList;
1544b65a47e1SRoman Zippel 			parent = menu_get_parent_menu(menu->parent);
1545b65a47e1SRoman Zippel 			if (!parent)
1546b65a47e1SRoman Zippel 				return;
1547b65a47e1SRoman Zippel 			item = menuList->findConfigItem(parent);
1548b65a47e1SRoman Zippel 			if (item) {
1549b65a47e1SRoman Zippel 				menuList->setSelected(item, TRUE);
1550b65a47e1SRoman Zippel 				menuList->ensureItemVisible(item);
1551b65a47e1SRoman Zippel 			}
1552b65a47e1SRoman Zippel 			list->setRootMenu(parent);
1553b65a47e1SRoman Zippel 		}
1554b65a47e1SRoman Zippel 		break;
1555b65a47e1SRoman Zippel 	case fullMode:
1556b65a47e1SRoman Zippel 		list = configList;
1557b65a47e1SRoman Zippel 		break;
155898403a91SMarkus Heidelberg 	default:
155998403a91SMarkus Heidelberg 		break;
1560b65a47e1SRoman Zippel 	}
1561b65a47e1SRoman Zippel 
1562b65a47e1SRoman Zippel 	if (list) {
1563b65a47e1SRoman Zippel 		item = list->findConfigItem(menu);
1564b65a47e1SRoman Zippel 		if (item) {
1565b65a47e1SRoman Zippel 			list->setSelected(item, TRUE);
1566b65a47e1SRoman Zippel 			list->ensureItemVisible(item);
1567b65a47e1SRoman Zippel 			list->setFocus();
1568b65a47e1SRoman Zippel 		}
1569b65a47e1SRoman Zippel 	}
1570b65a47e1SRoman Zippel }
1571b65a47e1SRoman Zippel 
15721da177e4SLinus Torvalds void ConfigMainWindow::listFocusChanged(void)
15731da177e4SLinus Torvalds {
15741da177e4SLinus Torvalds 	if (menuList->mode == menuMode)
15751da177e4SLinus Torvalds 		configList->clearSelection();
15761da177e4SLinus Torvalds }
15771da177e4SLinus Torvalds 
15781da177e4SLinus Torvalds void ConfigMainWindow::goBack(void)
15791da177e4SLinus Torvalds {
15801da177e4SLinus Torvalds 	ConfigItem* item;
15811da177e4SLinus Torvalds 
15821da177e4SLinus Torvalds 	configList->setParentMenu();
15831da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15841da177e4SLinus Torvalds 		backAction->setEnabled(FALSE);
15851da177e4SLinus Torvalds 	item = (ConfigItem*)menuList->selectedItem();
15861da177e4SLinus Torvalds 	while (item) {
15871da177e4SLinus Torvalds 		if (item->menu == configList->rootEntry) {
15881da177e4SLinus Torvalds 			menuList->setSelected(item, TRUE);
15891da177e4SLinus Torvalds 			break;
15901da177e4SLinus Torvalds 		}
15911da177e4SLinus Torvalds 		item = (ConfigItem*)item->parent();
15921da177e4SLinus Torvalds 	}
15931da177e4SLinus Torvalds }
15941da177e4SLinus Torvalds 
15951da177e4SLinus Torvalds void ConfigMainWindow::showSingleView(void)
15961da177e4SLinus Torvalds {
15971da177e4SLinus Torvalds 	menuView->hide();
15981da177e4SLinus Torvalds 	menuList->setRootMenu(0);
15991da177e4SLinus Torvalds 	configList->mode = singleMode;
16001da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
16011da177e4SLinus Torvalds 		configList->updateListAll();
16021da177e4SLinus Torvalds 	else
16031da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
16041da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
16051da177e4SLinus Torvalds 	configList->setFocus();
16061da177e4SLinus Torvalds }
16071da177e4SLinus Torvalds 
16081da177e4SLinus Torvalds void ConfigMainWindow::showSplitView(void)
16091da177e4SLinus Torvalds {
16101da177e4SLinus Torvalds 	configList->mode = symbolMode;
16111da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
16121da177e4SLinus Torvalds 		configList->updateListAll();
16131da177e4SLinus Torvalds 	else
16141da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
16151da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
16161da177e4SLinus Torvalds 	configApp->processEvents();
16171da177e4SLinus Torvalds 	menuList->mode = menuMode;
16181da177e4SLinus Torvalds 	menuList->setRootMenu(&rootmenu);
16191da177e4SLinus Torvalds 	menuList->setAllOpen(TRUE);
16201da177e4SLinus Torvalds 	menuView->show();
16211da177e4SLinus Torvalds 	menuList->setFocus();
16221da177e4SLinus Torvalds }
16231da177e4SLinus Torvalds 
16241da177e4SLinus Torvalds void ConfigMainWindow::showFullView(void)
16251da177e4SLinus Torvalds {
16261da177e4SLinus Torvalds 	menuView->hide();
16271da177e4SLinus Torvalds 	menuList->setRootMenu(0);
16281da177e4SLinus Torvalds 	configList->mode = fullMode;
16291da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
16301da177e4SLinus Torvalds 		configList->updateListAll();
16311da177e4SLinus Torvalds 	else
16321da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
16331da177e4SLinus Torvalds 	configList->setAllOpen(FALSE);
16341da177e4SLinus Torvalds 	configList->setFocus();
16351da177e4SLinus Torvalds }
16361da177e4SLinus Torvalds 
16371da177e4SLinus Torvalds /*
16381da177e4SLinus Torvalds  * ask for saving configuration before quitting
16391da177e4SLinus Torvalds  * TODO ask only when something changed
16401da177e4SLinus Torvalds  */
16411da177e4SLinus Torvalds void ConfigMainWindow::closeEvent(QCloseEvent* e)
16421da177e4SLinus Torvalds {
1643b3214293SKarsten Wiese 	if (!conf_get_changed()) {
16441da177e4SLinus Torvalds 		e->accept();
16451da177e4SLinus Torvalds 		return;
16461da177e4SLinus Torvalds 	}
1647c21a2d95SEGRY Gabor 	QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
16481da177e4SLinus Torvalds 			QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
1649c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1650c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1651c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
16521da177e4SLinus Torvalds 	switch (mb.exec()) {
16531da177e4SLinus Torvalds 	case QMessageBox::Yes:
1654bac6aa86SMichal Marek 		if (saveConfig())
1655bac6aa86SMichal Marek 			e->accept();
1656bac6aa86SMichal Marek 		else
1657bac6aa86SMichal Marek 			e->ignore();
1658bac6aa86SMichal Marek 		break;
16591da177e4SLinus Torvalds 	case QMessageBox::No:
16601da177e4SLinus Torvalds 		e->accept();
16611da177e4SLinus Torvalds 		break;
16621da177e4SLinus Torvalds 	case QMessageBox::Cancel:
16631da177e4SLinus Torvalds 		e->ignore();
16641da177e4SLinus Torvalds 		break;
16651da177e4SLinus Torvalds 	}
16661da177e4SLinus Torvalds }
16671da177e4SLinus Torvalds 
16681da177e4SLinus Torvalds void ConfigMainWindow::showIntro(void)
16691da177e4SLinus Torvalds {
1670652cf982SArnaud Lacombe 	static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
16711da177e4SLinus Torvalds 		"For each option, a blank box indicates the feature is disabled, a check\n"
16721da177e4SLinus Torvalds 		"indicates it is enabled, and a dot indicates that it is to be compiled\n"
16731da177e4SLinus Torvalds 		"as a module.  Clicking on the box will cycle through the three states.\n\n"
16741da177e4SLinus Torvalds 		"If you do not see an option (e.g., a device driver) that you believe\n"
16751da177e4SLinus Torvalds 		"should be present, try turning on Show All Options under the Options menu.\n"
16761da177e4SLinus Torvalds 		"Although there is no cross reference yet to help you figure out what other\n"
16771da177e4SLinus Torvalds 		"options must be enabled to support the option you are interested in, you can\n"
16781da177e4SLinus Torvalds 		"still view the help of a grayed-out option.\n\n"
16791da177e4SLinus Torvalds 		"Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1680c21a2d95SEGRY Gabor 		"which you can then match by examining other options.\n\n");
16811da177e4SLinus Torvalds 
16821da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16831da177e4SLinus Torvalds }
16841da177e4SLinus Torvalds 
16851da177e4SLinus Torvalds void ConfigMainWindow::showAbout(void)
16861da177e4SLinus Torvalds {
1687c21a2d95SEGRY Gabor 	static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1688c21a2d95SEGRY Gabor 		"Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
16891da177e4SLinus Torvalds 
16901da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16911da177e4SLinus Torvalds }
16921da177e4SLinus Torvalds 
16931da177e4SLinus Torvalds void ConfigMainWindow::saveSettings(void)
16941da177e4SLinus Torvalds {
16957fc925fdSRoman Zippel 	configSettings->writeEntry("/window x", pos().x());
16967fc925fdSRoman Zippel 	configSettings->writeEntry("/window y", pos().y());
16977fc925fdSRoman Zippel 	configSettings->writeEntry("/window width", size().width());
16987fc925fdSRoman Zippel 	configSettings->writeEntry("/window height", size().height());
16991da177e4SLinus Torvalds 
17001da177e4SLinus Torvalds 	QString entry;
17011da177e4SLinus Torvalds 	switch(configList->mode) {
17021da177e4SLinus Torvalds 	case singleMode :
17031da177e4SLinus Torvalds 		entry = "single";
17041da177e4SLinus Torvalds 		break;
17051da177e4SLinus Torvalds 
17061da177e4SLinus Torvalds 	case symbolMode :
17071da177e4SLinus Torvalds 		entry = "split";
17081da177e4SLinus Torvalds 		break;
17091da177e4SLinus Torvalds 
17101da177e4SLinus Torvalds 	case fullMode :
17111da177e4SLinus Torvalds 		entry = "full";
17121da177e4SLinus Torvalds 		break;
171398403a91SMarkus Heidelberg 
171498403a91SMarkus Heidelberg 	default:
171598403a91SMarkus Heidelberg 		break;
17161da177e4SLinus Torvalds 	}
17177fc925fdSRoman Zippel 	configSettings->writeEntry("/listMode", entry);
17181da177e4SLinus Torvalds 
17197fc925fdSRoman Zippel 	configSettings->writeSizes("/split1", split1->sizes());
17207fc925fdSRoman Zippel 	configSettings->writeSizes("/split2", split2->sizes());
17211da177e4SLinus Torvalds }
17221da177e4SLinus Torvalds 
17233b354c55SKarsten Wiese void ConfigMainWindow::conf_changed(void)
17243b354c55SKarsten Wiese {
17253b354c55SKarsten Wiese 	if (saveAction)
17263b354c55SKarsten Wiese 		saveAction->setEnabled(conf_get_changed());
17273b354c55SKarsten Wiese }
17283b354c55SKarsten Wiese 
17291da177e4SLinus Torvalds void fixup_rootmenu(struct menu *menu)
17301da177e4SLinus Torvalds {
17311da177e4SLinus Torvalds 	struct menu *child;
17321da177e4SLinus Torvalds 	static int menu_cnt = 0;
17331da177e4SLinus Torvalds 
17341da177e4SLinus Torvalds 	menu->flags |= MENU_ROOT;
17351da177e4SLinus Torvalds 	for (child = menu->list; child; child = child->next) {
17361da177e4SLinus Torvalds 		if (child->prompt && child->prompt->type == P_MENU) {
17371da177e4SLinus Torvalds 			menu_cnt++;
17381da177e4SLinus Torvalds 			fixup_rootmenu(child);
17391da177e4SLinus Torvalds 			menu_cnt--;
17401da177e4SLinus Torvalds 		} else if (!menu_cnt)
17411da177e4SLinus Torvalds 			fixup_rootmenu(child);
17421da177e4SLinus Torvalds 	}
17431da177e4SLinus Torvalds }
17441da177e4SLinus Torvalds 
17451da177e4SLinus Torvalds static const char *progname;
17461da177e4SLinus Torvalds 
17471da177e4SLinus Torvalds static void usage(void)
17481da177e4SLinus Torvalds {
1749c21a2d95SEGRY Gabor 	printf(_("%s <config>\n"), progname);
17501da177e4SLinus Torvalds 	exit(0);
17511da177e4SLinus Torvalds }
17521da177e4SLinus Torvalds 
17531da177e4SLinus Torvalds int main(int ac, char** av)
17541da177e4SLinus Torvalds {
17551da177e4SLinus Torvalds 	ConfigMainWindow* v;
17561da177e4SLinus Torvalds 	const char *name;
17571da177e4SLinus Torvalds 
17583b9fa093SArnaldo Carvalho de Melo 	bindtextdomain(PACKAGE, LOCALEDIR);
17593b9fa093SArnaldo Carvalho de Melo 	textdomain(PACKAGE);
17603b9fa093SArnaldo Carvalho de Melo 
17611da177e4SLinus Torvalds 	progname = av[0];
17621da177e4SLinus Torvalds 	configApp = new QApplication(ac, av);
17631da177e4SLinus Torvalds 	if (ac > 1 && av[1][0] == '-') {
17641da177e4SLinus Torvalds 		switch (av[1][1]) {
17651da177e4SLinus Torvalds 		case 'h':
17661da177e4SLinus Torvalds 		case '?':
17671da177e4SLinus Torvalds 			usage();
17681da177e4SLinus Torvalds 		}
17691da177e4SLinus Torvalds 		name = av[2];
17701da177e4SLinus Torvalds 	} else
17711da177e4SLinus Torvalds 		name = av[1];
17721da177e4SLinus Torvalds 	if (!name)
17731da177e4SLinus Torvalds 		usage();
17741da177e4SLinus Torvalds 
17751da177e4SLinus Torvalds 	conf_parse(name);
17761da177e4SLinus Torvalds 	fixup_rootmenu(&rootmenu);
17771da177e4SLinus Torvalds 	conf_read(NULL);
17781da177e4SLinus Torvalds 	//zconfdump(stdout);
17791da177e4SLinus Torvalds 
17807fc925fdSRoman Zippel 	configSettings = new ConfigSettings();
17817fc925fdSRoman Zippel 	configSettings->beginGroup("/kconfig/qconf");
17821da177e4SLinus Torvalds 	v = new ConfigMainWindow();
17831da177e4SLinus Torvalds 
17841da177e4SLinus Torvalds 	//zconfdump(stdout);
178543bf612aSRoman Zippel 	configApp->setMainWidget(v);
17861da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
17871da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
178843bf612aSRoman Zippel 	v->show();
17891da177e4SLinus Torvalds 	configApp->exec();
17901da177e4SLinus Torvalds 
17917fc925fdSRoman Zippel 	configSettings->endGroup();
17927fc925fdSRoman Zippel 	delete configSettings;
17937fc925fdSRoman Zippel 
17941da177e4SLinus Torvalds 	return 0;
17951da177e4SLinus Torvalds }
1796