xref: /openbmc/linux/scripts/kconfig/qconf.cc (revision b3214293)
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 
61da177e4SLinus Torvalds #include <qapplication.h>
71da177e4SLinus Torvalds #include <qmainwindow.h>
81da177e4SLinus Torvalds #include <qtoolbar.h>
943bf612aSRoman Zippel #include <qlayout.h>
101da177e4SLinus Torvalds #include <qvbox.h>
111da177e4SLinus Torvalds #include <qsplitter.h>
121da177e4SLinus Torvalds #include <qlistview.h>
1343bf612aSRoman Zippel #include <qtextbrowser.h>
141da177e4SLinus Torvalds #include <qlineedit.h>
1543bf612aSRoman Zippel #include <qlabel.h>
1643bf612aSRoman Zippel #include <qpushbutton.h>
171da177e4SLinus Torvalds #include <qmenubar.h>
181da177e4SLinus Torvalds #include <qmessagebox.h>
191da177e4SLinus Torvalds #include <qaction.h>
201da177e4SLinus Torvalds #include <qheader.h>
211da177e4SLinus Torvalds #include <qfiledialog.h>
2243bf612aSRoman Zippel #include <qdragobject.h>
231da177e4SLinus Torvalds #include <qregexp.h>
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #include <stdlib.h>
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #include "lkc.h"
281da177e4SLinus Torvalds #include "qconf.h"
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds #include "qconf.moc"
311da177e4SLinus Torvalds #include "images.c"
321da177e4SLinus Torvalds 
333b9fa093SArnaldo Carvalho de Melo #ifdef _
343b9fa093SArnaldo Carvalho de Melo # undef _
353b9fa093SArnaldo Carvalho de Melo # define _ qgettext
363b9fa093SArnaldo Carvalho de Melo #endif
373b9fa093SArnaldo Carvalho de Melo 
381da177e4SLinus Torvalds static QApplication *configApp;
397fc925fdSRoman Zippel static ConfigSettings *configSettings;
401da177e4SLinus Torvalds 
413b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const char* str)
423b9fa093SArnaldo Carvalho de Melo {
433b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str));
443b9fa093SArnaldo Carvalho de Melo }
453b9fa093SArnaldo Carvalho de Melo 
463b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const QString& str)
473b9fa093SArnaldo Carvalho de Melo {
483b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str.latin1()));
493b9fa093SArnaldo Carvalho de Melo }
503b9fa093SArnaldo Carvalho de Melo 
511da177e4SLinus Torvalds /**
521da177e4SLinus Torvalds  * Reads a list of integer values from the application settings.
531da177e4SLinus Torvalds  */
541da177e4SLinus Torvalds QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
551da177e4SLinus Torvalds {
561da177e4SLinus Torvalds 	QValueList<int> result;
571da177e4SLinus Torvalds 	QStringList entryList = readListEntry(key, ok);
581da177e4SLinus Torvalds 	if (ok) {
591da177e4SLinus Torvalds 		QStringList::Iterator it;
601da177e4SLinus Torvalds 		for (it = entryList.begin(); it != entryList.end(); ++it)
611da177e4SLinus Torvalds 			result.push_back((*it).toInt());
621da177e4SLinus Torvalds 	}
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds 	return result;
651da177e4SLinus Torvalds }
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds /**
681da177e4SLinus Torvalds  * Writes a list of integer values to the application settings.
691da177e4SLinus Torvalds  */
701da177e4SLinus Torvalds bool ConfigSettings::writeSizes(const QString& key, const QValueList<int>& value)
711da177e4SLinus Torvalds {
721da177e4SLinus Torvalds 	QStringList stringList;
731da177e4SLinus Torvalds 	QValueList<int>::ConstIterator it;
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds 	for (it = value.begin(); it != value.end(); ++it)
761da177e4SLinus Torvalds 		stringList.push_back(QString::number(*it));
771da177e4SLinus Torvalds 	return writeEntry(key, stringList);
781da177e4SLinus Torvalds }
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds #if QT_VERSION >= 300
821da177e4SLinus Torvalds /*
831da177e4SLinus Torvalds  * set the new data
841da177e4SLinus Torvalds  * TODO check the value
851da177e4SLinus Torvalds  */
861da177e4SLinus Torvalds void ConfigItem::okRename(int col)
871da177e4SLinus Torvalds {
881da177e4SLinus Torvalds 	Parent::okRename(col);
891da177e4SLinus Torvalds 	sym_set_string_value(menu->sym, text(dataColIdx).latin1());
901da177e4SLinus Torvalds }
911da177e4SLinus Torvalds #endif
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds /*
941da177e4SLinus Torvalds  * update the displayed of a menu entry
951da177e4SLinus Torvalds  */
961da177e4SLinus Torvalds void ConfigItem::updateMenu(void)
971da177e4SLinus Torvalds {
981da177e4SLinus Torvalds 	ConfigList* list;
991da177e4SLinus Torvalds 	struct symbol* sym;
1001da177e4SLinus Torvalds 	struct property *prop;
1011da177e4SLinus Torvalds 	QString prompt;
1021da177e4SLinus Torvalds 	int type;
1031da177e4SLinus Torvalds 	tristate expr;
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	list = listView();
1061da177e4SLinus Torvalds 	if (goParent) {
1071da177e4SLinus Torvalds 		setPixmap(promptColIdx, list->menuBackPix);
1081da177e4SLinus Torvalds 		prompt = "..";
1091da177e4SLinus Torvalds 		goto set_prompt;
1101da177e4SLinus Torvalds 	}
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds 	sym = menu->sym;
1131da177e4SLinus Torvalds 	prop = menu->prompt;
1143b9fa093SArnaldo Carvalho de Melo 	prompt = QString::fromLocal8Bit(menu_get_prompt(menu));
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	if (prop) switch (prop->type) {
1171da177e4SLinus Torvalds 	case P_MENU:
1181da177e4SLinus Torvalds 		if (list->mode == singleMode || list->mode == symbolMode) {
1191da177e4SLinus Torvalds 			/* a menuconfig entry is displayed differently
1201da177e4SLinus Torvalds 			 * depending whether it's at the view root or a child.
1211da177e4SLinus Torvalds 			 */
1221da177e4SLinus Torvalds 			if (sym && list->rootEntry == menu)
1231da177e4SLinus Torvalds 				break;
1241da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->menuPix);
1251da177e4SLinus Torvalds 		} else {
1261da177e4SLinus Torvalds 			if (sym)
1271da177e4SLinus Torvalds 				break;
1281da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1291da177e4SLinus Torvalds 		}
1301da177e4SLinus Torvalds 		goto set_prompt;
1311da177e4SLinus Torvalds 	case P_COMMENT:
1321da177e4SLinus Torvalds 		setPixmap(promptColIdx, 0);
1331da177e4SLinus Torvalds 		goto set_prompt;
1341da177e4SLinus Torvalds 	default:
1351da177e4SLinus Torvalds 		;
1361da177e4SLinus Torvalds 	}
1371da177e4SLinus Torvalds 	if (!sym)
1381da177e4SLinus Torvalds 		goto set_prompt;
1391da177e4SLinus Torvalds 
1403b9fa093SArnaldo Carvalho de Melo 	setText(nameColIdx, QString::fromLocal8Bit(sym->name));
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds 	type = sym_get_type(sym);
1431da177e4SLinus Torvalds 	switch (type) {
1441da177e4SLinus Torvalds 	case S_BOOLEAN:
1451da177e4SLinus Torvalds 	case S_TRISTATE:
1461da177e4SLinus Torvalds 		char ch;
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds 		if (!sym_is_changable(sym) && !list->showAll) {
1491da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1503b9fa093SArnaldo Carvalho de Melo 			setText(noColIdx, QString::null);
1513b9fa093SArnaldo Carvalho de Melo 			setText(modColIdx, QString::null);
1523b9fa093SArnaldo Carvalho de Melo 			setText(yesColIdx, QString::null);
1531da177e4SLinus Torvalds 			break;
1541da177e4SLinus Torvalds 		}
1551da177e4SLinus Torvalds 		expr = sym_get_tristate_value(sym);
1561da177e4SLinus Torvalds 		switch (expr) {
1571da177e4SLinus Torvalds 		case yes:
1581da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1591da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceYesPix);
1601da177e4SLinus Torvalds 			else
1611da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolYesPix);
1621da177e4SLinus Torvalds 			setText(yesColIdx, "Y");
1631da177e4SLinus Torvalds 			ch = 'Y';
1641da177e4SLinus Torvalds 			break;
1651da177e4SLinus Torvalds 		case mod:
1661da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->symbolModPix);
1671da177e4SLinus Torvalds 			setText(modColIdx, "M");
1681da177e4SLinus Torvalds 			ch = 'M';
1691da177e4SLinus Torvalds 			break;
1701da177e4SLinus Torvalds 		default:
1711da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1721da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceNoPix);
1731da177e4SLinus Torvalds 			else
1741da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolNoPix);
1751da177e4SLinus Torvalds 			setText(noColIdx, "N");
1761da177e4SLinus Torvalds 			ch = 'N';
1771da177e4SLinus Torvalds 			break;
1781da177e4SLinus Torvalds 		}
1791da177e4SLinus Torvalds 		if (expr != no)
1801da177e4SLinus Torvalds 			setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
1811da177e4SLinus Torvalds 		if (expr != mod)
1821da177e4SLinus Torvalds 			setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
1831da177e4SLinus Torvalds 		if (expr != yes)
1841da177e4SLinus Torvalds 			setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
1851da177e4SLinus Torvalds 
1861da177e4SLinus Torvalds 		setText(dataColIdx, QChar(ch));
1871da177e4SLinus Torvalds 		break;
1881da177e4SLinus Torvalds 	case S_INT:
1891da177e4SLinus Torvalds 	case S_HEX:
1901da177e4SLinus Torvalds 	case S_STRING:
1911da177e4SLinus Torvalds 		const char* data;
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds 		data = sym_get_string_value(sym);
1943b9fa093SArnaldo Carvalho de Melo 
1951da177e4SLinus Torvalds #if QT_VERSION >= 300
1961da177e4SLinus Torvalds 		int i = list->mapIdx(dataColIdx);
1971da177e4SLinus Torvalds 		if (i >= 0)
1981da177e4SLinus Torvalds 			setRenameEnabled(i, TRUE);
1991da177e4SLinus Torvalds #endif
2001da177e4SLinus Torvalds 		setText(dataColIdx, data);
2011da177e4SLinus Torvalds 		if (type == S_STRING)
2023b9fa093SArnaldo Carvalho de Melo 			prompt = QString("%1: %2").arg(prompt).arg(data);
2031da177e4SLinus Torvalds 		else
2043b9fa093SArnaldo Carvalho de Melo 			prompt = QString("(%2) %1").arg(prompt).arg(data);
2051da177e4SLinus Torvalds 		break;
2061da177e4SLinus Torvalds 	}
2071da177e4SLinus Torvalds 	if (!sym_has_value(sym) && visible)
2081da177e4SLinus Torvalds 		prompt += " (NEW)";
2091da177e4SLinus Torvalds set_prompt:
2101da177e4SLinus Torvalds 	setText(promptColIdx, prompt);
2111da177e4SLinus Torvalds }
2121da177e4SLinus Torvalds 
2131da177e4SLinus Torvalds void ConfigItem::testUpdateMenu(bool v)
2141da177e4SLinus Torvalds {
2151da177e4SLinus Torvalds 	ConfigItem* i;
2161da177e4SLinus Torvalds 
2171da177e4SLinus Torvalds 	visible = v;
2181da177e4SLinus Torvalds 	if (!menu)
2191da177e4SLinus Torvalds 		return;
2201da177e4SLinus Torvalds 
2211da177e4SLinus Torvalds 	sym_calc_value(menu->sym);
2221da177e4SLinus Torvalds 	if (menu->flags & MENU_CHANGED) {
2231da177e4SLinus Torvalds 		/* the menu entry changed, so update all list items */
2241da177e4SLinus Torvalds 		menu->flags &= ~MENU_CHANGED;
2251da177e4SLinus Torvalds 		for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
2261da177e4SLinus Torvalds 			i->updateMenu();
2271da177e4SLinus Torvalds 	} else if (listView()->updateAll)
2281da177e4SLinus Torvalds 		updateMenu();
2291da177e4SLinus Torvalds }
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
2321da177e4SLinus Torvalds {
2331da177e4SLinus Torvalds 	ConfigList* list = listView();
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds 	if (visible) {
2361da177e4SLinus Torvalds 		if (isSelected() && !list->hasFocus() && list->mode == menuMode)
2371da177e4SLinus Torvalds 			Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
2381da177e4SLinus Torvalds 		else
2391da177e4SLinus Torvalds 			Parent::paintCell(p, cg, column, width, align);
2401da177e4SLinus Torvalds 	} else
2411da177e4SLinus Torvalds 		Parent::paintCell(p, list->disabledColorGroup, column, width, align);
2421da177e4SLinus Torvalds }
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds /*
2451da177e4SLinus Torvalds  * construct a menu entry
2461da177e4SLinus Torvalds  */
2471da177e4SLinus Torvalds void ConfigItem::init(void)
2481da177e4SLinus Torvalds {
2491da177e4SLinus Torvalds 	if (menu) {
2501da177e4SLinus Torvalds 		ConfigList* list = listView();
2511da177e4SLinus Torvalds 		nextItem = (ConfigItem*)menu->data;
2521da177e4SLinus Torvalds 		menu->data = this;
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds 		if (list->mode != fullMode)
2551da177e4SLinus Torvalds 			setOpen(TRUE);
2561da177e4SLinus Torvalds 		sym_calc_value(menu->sym);
2571da177e4SLinus Torvalds 	}
2581da177e4SLinus Torvalds 	updateMenu();
2591da177e4SLinus Torvalds }
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds /*
2621da177e4SLinus Torvalds  * destruct a menu entry
2631da177e4SLinus Torvalds  */
2641da177e4SLinus Torvalds ConfigItem::~ConfigItem(void)
2651da177e4SLinus Torvalds {
2661da177e4SLinus Torvalds 	if (menu) {
2671da177e4SLinus Torvalds 		ConfigItem** ip = (ConfigItem**)&menu->data;
2681da177e4SLinus Torvalds 		for (; *ip; ip = &(*ip)->nextItem) {
2691da177e4SLinus Torvalds 			if (*ip == this) {
2701da177e4SLinus Torvalds 				*ip = nextItem;
2711da177e4SLinus Torvalds 				break;
2721da177e4SLinus Torvalds 			}
2731da177e4SLinus Torvalds 		}
2741da177e4SLinus Torvalds 	}
2751da177e4SLinus Torvalds }
2761da177e4SLinus Torvalds 
27743bf612aSRoman Zippel ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
27843bf612aSRoman Zippel 	: Parent(parent)
27943bf612aSRoman Zippel {
28043bf612aSRoman Zippel 	connect(this, SIGNAL(lostFocus()), SLOT(hide()));
28143bf612aSRoman Zippel }
28243bf612aSRoman Zippel 
2831da177e4SLinus Torvalds void ConfigLineEdit::show(ConfigItem* i)
2841da177e4SLinus Torvalds {
2851da177e4SLinus Torvalds 	item = i;
2861da177e4SLinus Torvalds 	if (sym_get_string_value(item->menu->sym))
2873b9fa093SArnaldo Carvalho de Melo 		setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
2881da177e4SLinus Torvalds 	else
2893b9fa093SArnaldo Carvalho de Melo 		setText(QString::null);
2901da177e4SLinus Torvalds 	Parent::show();
2911da177e4SLinus Torvalds 	setFocus();
2921da177e4SLinus Torvalds }
2931da177e4SLinus Torvalds 
2941da177e4SLinus Torvalds void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
2951da177e4SLinus Torvalds {
2961da177e4SLinus Torvalds 	switch (e->key()) {
2971da177e4SLinus Torvalds 	case Key_Escape:
2981da177e4SLinus Torvalds 		break;
2991da177e4SLinus Torvalds 	case Key_Return:
3001da177e4SLinus Torvalds 	case Key_Enter:
3011da177e4SLinus Torvalds 		sym_set_string_value(item->menu->sym, text().latin1());
3021da177e4SLinus Torvalds 		parent()->updateList(item);
3031da177e4SLinus Torvalds 		break;
3041da177e4SLinus Torvalds 	default:
3051da177e4SLinus Torvalds 		Parent::keyPressEvent(e);
3061da177e4SLinus Torvalds 		return;
3071da177e4SLinus Torvalds 	}
3081da177e4SLinus Torvalds 	e->accept();
3091da177e4SLinus Torvalds 	parent()->list->setFocus();
3101da177e4SLinus Torvalds 	hide();
3111da177e4SLinus Torvalds }
3121da177e4SLinus Torvalds 
3137fc925fdSRoman Zippel ConfigList::ConfigList(ConfigView* p, const char *name)
3147fc925fdSRoman Zippel 	: Parent(p, name),
3151da177e4SLinus Torvalds 	  updateAll(false),
3161da177e4SLinus Torvalds 	  symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
3171da177e4SLinus Torvalds 	  choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
3181da177e4SLinus Torvalds 	  menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
3191da177e4SLinus Torvalds 	  showAll(false), showName(false), showRange(false), showData(false),
3207fc925fdSRoman Zippel 	  rootEntry(0), headerPopup(0)
3211da177e4SLinus Torvalds {
3221da177e4SLinus Torvalds 	int i;
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds 	setSorting(-1);
3251da177e4SLinus Torvalds 	setRootIsDecorated(TRUE);
3261da177e4SLinus Torvalds 	disabledColorGroup = palette().active();
3271da177e4SLinus Torvalds 	disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
3281da177e4SLinus Torvalds 	inactivedColorGroup = palette().active();
3291da177e4SLinus Torvalds 	inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
3301da177e4SLinus Torvalds 
3311da177e4SLinus Torvalds 	connect(this, SIGNAL(selectionChanged(void)),
3321da177e4SLinus Torvalds 		SLOT(updateSelection(void)));
3331da177e4SLinus Torvalds 
3347fc925fdSRoman Zippel 	if (name) {
3357fc925fdSRoman Zippel 		configSettings->beginGroup(name);
3367fc925fdSRoman Zippel 		showAll = configSettings->readBoolEntry("/showAll", false);
3377fc925fdSRoman Zippel 		showName = configSettings->readBoolEntry("/showName", false);
3387fc925fdSRoman Zippel 		showRange = configSettings->readBoolEntry("/showRange", false);
3397fc925fdSRoman Zippel 		showData = configSettings->readBoolEntry("/showData", false);
3407fc925fdSRoman Zippel 		configSettings->endGroup();
3417fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
3421da177e4SLinus Torvalds 	}
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds 	for (i = 0; i < colNr; i++)
3451da177e4SLinus Torvalds 		colMap[i] = colRevMap[i] = -1;
3461da177e4SLinus Torvalds 	addColumn(promptColIdx, "Option");
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds 	reinit();
3491da177e4SLinus Torvalds }
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds void ConfigList::reinit(void)
3521da177e4SLinus Torvalds {
3531da177e4SLinus Torvalds 	removeColumn(dataColIdx);
3541da177e4SLinus Torvalds 	removeColumn(yesColIdx);
3551da177e4SLinus Torvalds 	removeColumn(modColIdx);
3561da177e4SLinus Torvalds 	removeColumn(noColIdx);
3571da177e4SLinus Torvalds 	removeColumn(nameColIdx);
3581da177e4SLinus Torvalds 
3591da177e4SLinus Torvalds 	if (showName)
3601da177e4SLinus Torvalds 		addColumn(nameColIdx, "Name");
3611da177e4SLinus Torvalds 	if (showRange) {
3621da177e4SLinus Torvalds 		addColumn(noColIdx, "N");
3631da177e4SLinus Torvalds 		addColumn(modColIdx, "M");
3641da177e4SLinus Torvalds 		addColumn(yesColIdx, "Y");
3651da177e4SLinus Torvalds 	}
3661da177e4SLinus Torvalds 	if (showData)
3671da177e4SLinus Torvalds 		addColumn(dataColIdx, "Value");
3681da177e4SLinus Torvalds 
3691da177e4SLinus Torvalds 	updateListAll();
3701da177e4SLinus Torvalds }
3711da177e4SLinus Torvalds 
3727fc925fdSRoman Zippel void ConfigList::saveSettings(void)
3737fc925fdSRoman Zippel {
3747fc925fdSRoman Zippel 	if (name()) {
3757fc925fdSRoman Zippel 		configSettings->beginGroup(name());
3767fc925fdSRoman Zippel 		configSettings->writeEntry("/showName", showName);
3777fc925fdSRoman Zippel 		configSettings->writeEntry("/showRange", showRange);
3787fc925fdSRoman Zippel 		configSettings->writeEntry("/showData", showData);
3797fc925fdSRoman Zippel 		configSettings->writeEntry("/showAll", showAll);
3807fc925fdSRoman Zippel 		configSettings->endGroup();
3817fc925fdSRoman Zippel 	}
3827fc925fdSRoman Zippel }
3837fc925fdSRoman Zippel 
384b65a47e1SRoman Zippel ConfigItem* ConfigList::findConfigItem(struct menu *menu)
385b65a47e1SRoman Zippel {
386b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem*)menu->data;
387b65a47e1SRoman Zippel 
388b65a47e1SRoman Zippel 	for (; item; item = item->nextItem) {
389b65a47e1SRoman Zippel 		if (this == item->listView())
390b65a47e1SRoman Zippel 			break;
391b65a47e1SRoman Zippel 	}
392b65a47e1SRoman Zippel 
393b65a47e1SRoman Zippel 	return item;
394b65a47e1SRoman Zippel }
395b65a47e1SRoman Zippel 
3961da177e4SLinus Torvalds void ConfigList::updateSelection(void)
3971da177e4SLinus Torvalds {
3981da177e4SLinus Torvalds 	struct menu *menu;
3991da177e4SLinus Torvalds 	enum prop_type type;
4001da177e4SLinus Torvalds 
4011da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)selectedItem();
4021da177e4SLinus Torvalds 	if (!item)
4031da177e4SLinus Torvalds 		return;
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds 	menu = item->menu;
40643bf612aSRoman Zippel 	emit menuChanged(menu);
4071da177e4SLinus Torvalds 	if (!menu)
4081da177e4SLinus Torvalds 		return;
4091da177e4SLinus Torvalds 	type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
4101da177e4SLinus Torvalds 	if (mode == menuMode && type == P_MENU)
4111da177e4SLinus Torvalds 		emit menuSelected(menu);
4121da177e4SLinus Torvalds }
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds void ConfigList::updateList(ConfigItem* item)
4151da177e4SLinus Torvalds {
4161da177e4SLinus Torvalds 	ConfigItem* last = 0;
4171da177e4SLinus Torvalds 
41843bf612aSRoman Zippel 	if (!rootEntry) {
41943bf612aSRoman Zippel 		if (mode != listMode)
4201da177e4SLinus Torvalds 			goto update;
42143bf612aSRoman Zippel 		QListViewItemIterator it(this);
42243bf612aSRoman Zippel 		ConfigItem* item;
42343bf612aSRoman Zippel 
42443bf612aSRoman Zippel 		for (; it.current(); ++it) {
42543bf612aSRoman Zippel 			item = (ConfigItem*)it.current();
42643bf612aSRoman Zippel 			if (!item->menu)
42743bf612aSRoman Zippel 				continue;
42843bf612aSRoman Zippel 			item->testUpdateMenu(menu_is_visible(item->menu));
42943bf612aSRoman Zippel 		}
43043bf612aSRoman Zippel 		return;
43143bf612aSRoman Zippel 	}
4321da177e4SLinus Torvalds 
4331da177e4SLinus Torvalds 	if (rootEntry != &rootmenu && (mode == singleMode ||
4341da177e4SLinus Torvalds 	    (mode == symbolMode && rootEntry->parent != &rootmenu))) {
4351da177e4SLinus Torvalds 		item = firstChild();
4361da177e4SLinus Torvalds 		if (!item)
4371da177e4SLinus Torvalds 			item = new ConfigItem(this, 0, true);
4381da177e4SLinus Torvalds 		last = item;
4391da177e4SLinus Torvalds 	}
4401da177e4SLinus Torvalds 	if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
4411da177e4SLinus Torvalds 	    rootEntry->sym && rootEntry->prompt) {
4421da177e4SLinus Torvalds 		item = last ? last->nextSibling() : firstChild();
4431da177e4SLinus Torvalds 		if (!item)
4441da177e4SLinus Torvalds 			item = new ConfigItem(this, last, rootEntry, true);
4451da177e4SLinus Torvalds 		else
4461da177e4SLinus Torvalds 			item->testUpdateMenu(true);
4471da177e4SLinus Torvalds 
4481da177e4SLinus Torvalds 		updateMenuList(item, rootEntry);
4491da177e4SLinus Torvalds 		triggerUpdate();
4501da177e4SLinus Torvalds 		return;
4511da177e4SLinus Torvalds 	}
4521da177e4SLinus Torvalds update:
4531da177e4SLinus Torvalds 	updateMenuList(this, rootEntry);
4541da177e4SLinus Torvalds 	triggerUpdate();
4551da177e4SLinus Torvalds }
4561da177e4SLinus Torvalds 
4571da177e4SLinus Torvalds void ConfigList::setValue(ConfigItem* item, tristate val)
4581da177e4SLinus Torvalds {
4591da177e4SLinus Torvalds 	struct symbol* sym;
4601da177e4SLinus Torvalds 	int type;
4611da177e4SLinus Torvalds 	tristate oldval;
4621da177e4SLinus Torvalds 
4631da177e4SLinus Torvalds 	sym = item->menu ? item->menu->sym : 0;
4641da177e4SLinus Torvalds 	if (!sym)
4651da177e4SLinus Torvalds 		return;
4661da177e4SLinus Torvalds 
4671da177e4SLinus Torvalds 	type = sym_get_type(sym);
4681da177e4SLinus Torvalds 	switch (type) {
4691da177e4SLinus Torvalds 	case S_BOOLEAN:
4701da177e4SLinus Torvalds 	case S_TRISTATE:
4711da177e4SLinus Torvalds 		oldval = sym_get_tristate_value(sym);
4721da177e4SLinus Torvalds 
4731da177e4SLinus Torvalds 		if (!sym_set_tristate_value(sym, val))
4741da177e4SLinus Torvalds 			return;
4751da177e4SLinus Torvalds 		if (oldval == no && item->menu->list)
4761da177e4SLinus Torvalds 			item->setOpen(TRUE);
4771da177e4SLinus Torvalds 		parent()->updateList(item);
4781da177e4SLinus Torvalds 		break;
4791da177e4SLinus Torvalds 	}
4801da177e4SLinus Torvalds }
4811da177e4SLinus Torvalds 
4821da177e4SLinus Torvalds void ConfigList::changeValue(ConfigItem* item)
4831da177e4SLinus Torvalds {
4841da177e4SLinus Torvalds 	struct symbol* sym;
4851da177e4SLinus Torvalds 	struct menu* menu;
4861da177e4SLinus Torvalds 	int type, oldexpr, newexpr;
4871da177e4SLinus Torvalds 
4881da177e4SLinus Torvalds 	menu = item->menu;
4891da177e4SLinus Torvalds 	if (!menu)
4901da177e4SLinus Torvalds 		return;
4911da177e4SLinus Torvalds 	sym = menu->sym;
4921da177e4SLinus Torvalds 	if (!sym) {
4931da177e4SLinus Torvalds 		if (item->menu->list)
4941da177e4SLinus Torvalds 			item->setOpen(!item->isOpen());
4951da177e4SLinus Torvalds 		return;
4961da177e4SLinus Torvalds 	}
4971da177e4SLinus Torvalds 
4981da177e4SLinus Torvalds 	type = sym_get_type(sym);
4991da177e4SLinus Torvalds 	switch (type) {
5001da177e4SLinus Torvalds 	case S_BOOLEAN:
5011da177e4SLinus Torvalds 	case S_TRISTATE:
5021da177e4SLinus Torvalds 		oldexpr = sym_get_tristate_value(sym);
5031da177e4SLinus Torvalds 		newexpr = sym_toggle_tristate_value(sym);
5041da177e4SLinus Torvalds 		if (item->menu->list) {
5051da177e4SLinus Torvalds 			if (oldexpr == newexpr)
5061da177e4SLinus Torvalds 				item->setOpen(!item->isOpen());
5071da177e4SLinus Torvalds 			else if (oldexpr == no)
5081da177e4SLinus Torvalds 				item->setOpen(TRUE);
5091da177e4SLinus Torvalds 		}
5101da177e4SLinus Torvalds 		if (oldexpr != newexpr)
5111da177e4SLinus Torvalds 			parent()->updateList(item);
5121da177e4SLinus Torvalds 		break;
5131da177e4SLinus Torvalds 	case S_INT:
5141da177e4SLinus Torvalds 	case S_HEX:
5151da177e4SLinus Torvalds 	case S_STRING:
5161da177e4SLinus Torvalds #if QT_VERSION >= 300
5171da177e4SLinus Torvalds 		if (colMap[dataColIdx] >= 0)
5181da177e4SLinus Torvalds 			item->startRename(colMap[dataColIdx]);
5191da177e4SLinus Torvalds 		else
5201da177e4SLinus Torvalds #endif
5211da177e4SLinus Torvalds 			parent()->lineEdit->show(item);
5221da177e4SLinus Torvalds 		break;
5231da177e4SLinus Torvalds 	}
5241da177e4SLinus Torvalds }
5251da177e4SLinus Torvalds 
5261da177e4SLinus Torvalds void ConfigList::setRootMenu(struct menu *menu)
5271da177e4SLinus Torvalds {
5281da177e4SLinus Torvalds 	enum prop_type type;
5291da177e4SLinus Torvalds 
5301da177e4SLinus Torvalds 	if (rootEntry == menu)
5311da177e4SLinus Torvalds 		return;
5321da177e4SLinus Torvalds 	type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
5331da177e4SLinus Torvalds 	if (type != P_MENU)
5341da177e4SLinus Torvalds 		return;
5351da177e4SLinus Torvalds 	updateMenuList(this, 0);
5361da177e4SLinus Torvalds 	rootEntry = menu;
5371da177e4SLinus Torvalds 	updateListAll();
5381da177e4SLinus Torvalds 	setSelected(currentItem(), hasFocus());
539b65a47e1SRoman Zippel 	ensureItemVisible(currentItem());
5401da177e4SLinus Torvalds }
5411da177e4SLinus Torvalds 
5421da177e4SLinus Torvalds void ConfigList::setParentMenu(void)
5431da177e4SLinus Torvalds {
5441da177e4SLinus Torvalds 	ConfigItem* item;
5451da177e4SLinus Torvalds 	struct menu *oldroot;
5461da177e4SLinus Torvalds 
5471da177e4SLinus Torvalds 	oldroot = rootEntry;
5481da177e4SLinus Torvalds 	if (rootEntry == &rootmenu)
5491da177e4SLinus Torvalds 		return;
5501da177e4SLinus Torvalds 	setRootMenu(menu_get_parent_menu(rootEntry->parent));
5511da177e4SLinus Torvalds 
5521da177e4SLinus Torvalds 	QListViewItemIterator it(this);
5531da177e4SLinus Torvalds 	for (; (item = (ConfigItem*)it.current()); it++) {
5541da177e4SLinus Torvalds 		if (item->menu == oldroot) {
5551da177e4SLinus Torvalds 			setCurrentItem(item);
5561da177e4SLinus Torvalds 			ensureItemVisible(item);
5571da177e4SLinus Torvalds 			break;
5581da177e4SLinus Torvalds 		}
5591da177e4SLinus Torvalds 	}
5601da177e4SLinus Torvalds }
5611da177e4SLinus Torvalds 
5627fc925fdSRoman Zippel /*
5637fc925fdSRoman Zippel  * update all the children of a menu entry
5647fc925fdSRoman Zippel  *   removes/adds the entries from the parent widget as necessary
5657fc925fdSRoman Zippel  *
5667fc925fdSRoman Zippel  * parent: either the menu list widget or a menu entry widget
5677fc925fdSRoman Zippel  * menu: entry to be updated
5687fc925fdSRoman Zippel  */
5697fc925fdSRoman Zippel template <class P>
5707fc925fdSRoman Zippel void ConfigList::updateMenuList(P* parent, struct menu* menu)
5717fc925fdSRoman Zippel {
5727fc925fdSRoman Zippel 	struct menu* child;
5737fc925fdSRoman Zippel 	ConfigItem* item;
5747fc925fdSRoman Zippel 	ConfigItem* last;
5757fc925fdSRoman Zippel 	bool visible;
5767fc925fdSRoman Zippel 	enum prop_type type;
5777fc925fdSRoman Zippel 
5787fc925fdSRoman Zippel 	if (!menu) {
5797fc925fdSRoman Zippel 		while ((item = parent->firstChild()))
5807fc925fdSRoman Zippel 			delete item;
5817fc925fdSRoman Zippel 		return;
5827fc925fdSRoman Zippel 	}
5837fc925fdSRoman Zippel 
5847fc925fdSRoman Zippel 	last = parent->firstChild();
5857fc925fdSRoman Zippel 	if (last && !last->goParent)
5867fc925fdSRoman Zippel 		last = 0;
5877fc925fdSRoman Zippel 	for (child = menu->list; child; child = child->next) {
5887fc925fdSRoman Zippel 		item = last ? last->nextSibling() : parent->firstChild();
5897fc925fdSRoman Zippel 		type = child->prompt ? child->prompt->type : P_UNKNOWN;
5907fc925fdSRoman Zippel 
5917fc925fdSRoman Zippel 		switch (mode) {
5927fc925fdSRoman Zippel 		case menuMode:
5937fc925fdSRoman Zippel 			if (!(child->flags & MENU_ROOT))
5947fc925fdSRoman Zippel 				goto hide;
5957fc925fdSRoman Zippel 			break;
5967fc925fdSRoman Zippel 		case symbolMode:
5977fc925fdSRoman Zippel 			if (child->flags & MENU_ROOT)
5987fc925fdSRoman Zippel 				goto hide;
5997fc925fdSRoman Zippel 			break;
6007fc925fdSRoman Zippel 		default:
6017fc925fdSRoman Zippel 			break;
6027fc925fdSRoman Zippel 		}
6037fc925fdSRoman Zippel 
6047fc925fdSRoman Zippel 		visible = menu_is_visible(child);
6057fc925fdSRoman Zippel 		if (showAll || visible) {
6067fc925fdSRoman Zippel 			if (!item || item->menu != child)
6077fc925fdSRoman Zippel 				item = new ConfigItem(parent, last, child, visible);
6087fc925fdSRoman Zippel 			else
6097fc925fdSRoman Zippel 				item->testUpdateMenu(visible);
6107fc925fdSRoman Zippel 
6117fc925fdSRoman Zippel 			if (mode == fullMode || mode == menuMode || type != P_MENU)
6127fc925fdSRoman Zippel 				updateMenuList(item, child);
6137fc925fdSRoman Zippel 			else
6147fc925fdSRoman Zippel 				updateMenuList(item, 0);
6157fc925fdSRoman Zippel 			last = item;
6167fc925fdSRoman Zippel 			continue;
6177fc925fdSRoman Zippel 		}
6187fc925fdSRoman Zippel 	hide:
6197fc925fdSRoman Zippel 		if (item && item->menu == child) {
6207fc925fdSRoman Zippel 			last = parent->firstChild();
6217fc925fdSRoman Zippel 			if (last == item)
6227fc925fdSRoman Zippel 				last = 0;
6237fc925fdSRoman Zippel 			else while (last->nextSibling() != item)
6247fc925fdSRoman Zippel 				last = last->nextSibling();
6257fc925fdSRoman Zippel 			delete item;
6267fc925fdSRoman Zippel 		}
6277fc925fdSRoman Zippel 	}
6287fc925fdSRoman Zippel }
6297fc925fdSRoman Zippel 
6301da177e4SLinus Torvalds void ConfigList::keyPressEvent(QKeyEvent* ev)
6311da177e4SLinus Torvalds {
6321da177e4SLinus Torvalds 	QListViewItem* i = currentItem();
6331da177e4SLinus Torvalds 	ConfigItem* item;
6341da177e4SLinus Torvalds 	struct menu *menu;
6351da177e4SLinus Torvalds 	enum prop_type type;
6361da177e4SLinus Torvalds 
63743bf612aSRoman Zippel 	if (ev->key() == Key_Escape && mode != fullMode && mode != listMode) {
6381da177e4SLinus Torvalds 		emit parentSelected();
6391da177e4SLinus Torvalds 		ev->accept();
6401da177e4SLinus Torvalds 		return;
6411da177e4SLinus Torvalds 	}
6421da177e4SLinus Torvalds 
6431da177e4SLinus Torvalds 	if (!i) {
6441da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
6451da177e4SLinus Torvalds 		return;
6461da177e4SLinus Torvalds 	}
6471da177e4SLinus Torvalds 	item = (ConfigItem*)i;
6481da177e4SLinus Torvalds 
6491da177e4SLinus Torvalds 	switch (ev->key()) {
6501da177e4SLinus Torvalds 	case Key_Return:
6511da177e4SLinus Torvalds 	case Key_Enter:
6521da177e4SLinus Torvalds 		if (item->goParent) {
6531da177e4SLinus Torvalds 			emit parentSelected();
6541da177e4SLinus Torvalds 			break;
6551da177e4SLinus Torvalds 		}
6561da177e4SLinus Torvalds 		menu = item->menu;
6571da177e4SLinus Torvalds 		if (!menu)
6581da177e4SLinus Torvalds 			break;
6591da177e4SLinus Torvalds 		type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
6601da177e4SLinus Torvalds 		if (type == P_MENU && rootEntry != menu &&
6611da177e4SLinus Torvalds 		    mode != fullMode && mode != menuMode) {
6621da177e4SLinus Torvalds 			emit menuSelected(menu);
6631da177e4SLinus Torvalds 			break;
6641da177e4SLinus Torvalds 		}
6651da177e4SLinus Torvalds 	case Key_Space:
6661da177e4SLinus Torvalds 		changeValue(item);
6671da177e4SLinus Torvalds 		break;
6681da177e4SLinus Torvalds 	case Key_N:
6691da177e4SLinus Torvalds 		setValue(item, no);
6701da177e4SLinus Torvalds 		break;
6711da177e4SLinus Torvalds 	case Key_M:
6721da177e4SLinus Torvalds 		setValue(item, mod);
6731da177e4SLinus Torvalds 		break;
6741da177e4SLinus Torvalds 	case Key_Y:
6751da177e4SLinus Torvalds 		setValue(item, yes);
6761da177e4SLinus Torvalds 		break;
6771da177e4SLinus Torvalds 	default:
6781da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
6791da177e4SLinus Torvalds 		return;
6801da177e4SLinus Torvalds 	}
6811da177e4SLinus Torvalds 	ev->accept();
6821da177e4SLinus Torvalds }
6831da177e4SLinus Torvalds 
6841da177e4SLinus Torvalds void ConfigList::contentsMousePressEvent(QMouseEvent* e)
6851da177e4SLinus Torvalds {
6861da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
6871da177e4SLinus Torvalds 	//printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
6881da177e4SLinus Torvalds 	Parent::contentsMousePressEvent(e);
6891da177e4SLinus Torvalds }
6901da177e4SLinus Torvalds 
6911da177e4SLinus Torvalds void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
6921da177e4SLinus Torvalds {
6931da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
6941da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
6951da177e4SLinus Torvalds 	struct menu *menu;
6961da177e4SLinus Torvalds 	enum prop_type ptype;
6971da177e4SLinus Torvalds 	const QPixmap* pm;
6981da177e4SLinus Torvalds 	int idx, x;
6991da177e4SLinus Torvalds 
7001da177e4SLinus Torvalds 	if (!item)
7011da177e4SLinus Torvalds 		goto skip;
7021da177e4SLinus Torvalds 
7031da177e4SLinus Torvalds 	menu = item->menu;
7041da177e4SLinus Torvalds 	x = header()->offset() + p.x();
7051da177e4SLinus Torvalds 	idx = colRevMap[header()->sectionAt(x)];
7061da177e4SLinus Torvalds 	switch (idx) {
7071da177e4SLinus Torvalds 	case promptColIdx:
7081da177e4SLinus Torvalds 		pm = item->pixmap(promptColIdx);
7091da177e4SLinus Torvalds 		if (pm) {
7101da177e4SLinus Torvalds 			int off = header()->sectionPos(0) + itemMargin() +
7111da177e4SLinus Torvalds 				treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
7121da177e4SLinus Torvalds 			if (x >= off && x < off + pm->width()) {
7131da177e4SLinus Torvalds 				if (item->goParent) {
7141da177e4SLinus Torvalds 					emit parentSelected();
7151da177e4SLinus Torvalds 					break;
7161da177e4SLinus Torvalds 				} else if (!menu)
7171da177e4SLinus Torvalds 					break;
7181da177e4SLinus Torvalds 				ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7191da177e4SLinus Torvalds 				if (ptype == P_MENU && rootEntry != menu &&
7201da177e4SLinus Torvalds 				    mode != fullMode && mode != menuMode)
7211da177e4SLinus Torvalds 					emit menuSelected(menu);
7221da177e4SLinus Torvalds 				else
7231da177e4SLinus Torvalds 					changeValue(item);
7241da177e4SLinus Torvalds 			}
7251da177e4SLinus Torvalds 		}
7261da177e4SLinus Torvalds 		break;
7271da177e4SLinus Torvalds 	case noColIdx:
7281da177e4SLinus Torvalds 		setValue(item, no);
7291da177e4SLinus Torvalds 		break;
7301da177e4SLinus Torvalds 	case modColIdx:
7311da177e4SLinus Torvalds 		setValue(item, mod);
7321da177e4SLinus Torvalds 		break;
7331da177e4SLinus Torvalds 	case yesColIdx:
7341da177e4SLinus Torvalds 		setValue(item, yes);
7351da177e4SLinus Torvalds 		break;
7361da177e4SLinus Torvalds 	case dataColIdx:
7371da177e4SLinus Torvalds 		changeValue(item);
7381da177e4SLinus Torvalds 		break;
7391da177e4SLinus Torvalds 	}
7401da177e4SLinus Torvalds 
7411da177e4SLinus Torvalds skip:
7421da177e4SLinus Torvalds 	//printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
7431da177e4SLinus Torvalds 	Parent::contentsMouseReleaseEvent(e);
7441da177e4SLinus Torvalds }
7451da177e4SLinus Torvalds 
7461da177e4SLinus Torvalds void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
7471da177e4SLinus Torvalds {
7481da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
7491da177e4SLinus Torvalds 	//printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
7501da177e4SLinus Torvalds 	Parent::contentsMouseMoveEvent(e);
7511da177e4SLinus Torvalds }
7521da177e4SLinus Torvalds 
7531da177e4SLinus Torvalds void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
7541da177e4SLinus Torvalds {
7551da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
7561da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
7571da177e4SLinus Torvalds 	struct menu *menu;
7581da177e4SLinus Torvalds 	enum prop_type ptype;
7591da177e4SLinus Torvalds 
7601da177e4SLinus Torvalds 	if (!item)
7611da177e4SLinus Torvalds 		goto skip;
7621da177e4SLinus Torvalds 	if (item->goParent) {
7631da177e4SLinus Torvalds 		emit parentSelected();
7641da177e4SLinus Torvalds 		goto skip;
7651da177e4SLinus Torvalds 	}
7661da177e4SLinus Torvalds 	menu = item->menu;
7671da177e4SLinus Torvalds 	if (!menu)
7681da177e4SLinus Torvalds 		goto skip;
7691da177e4SLinus Torvalds 	ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7701da177e4SLinus Torvalds 	if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
7711da177e4SLinus Torvalds 		emit menuSelected(menu);
7721da177e4SLinus Torvalds 	else if (menu->sym)
7731da177e4SLinus Torvalds 		changeValue(item);
7741da177e4SLinus Torvalds 
7751da177e4SLinus Torvalds skip:
7761da177e4SLinus Torvalds 	//printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
7771da177e4SLinus Torvalds 	Parent::contentsMouseDoubleClickEvent(e);
7781da177e4SLinus Torvalds }
7791da177e4SLinus Torvalds 
7801da177e4SLinus Torvalds void ConfigList::focusInEvent(QFocusEvent *e)
7811da177e4SLinus Torvalds {
782b65a47e1SRoman Zippel 	struct menu *menu = NULL;
783b65a47e1SRoman Zippel 
7841da177e4SLinus Torvalds 	Parent::focusInEvent(e);
7851da177e4SLinus Torvalds 
786b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem *)currentItem();
787b65a47e1SRoman Zippel 	if (item) {
7881da177e4SLinus Torvalds 		setSelected(item, TRUE);
789b65a47e1SRoman Zippel 		menu = item->menu;
790b65a47e1SRoman Zippel 	}
791b65a47e1SRoman Zippel 	emit gotFocus(menu);
7921da177e4SLinus Torvalds }
7931da177e4SLinus Torvalds 
7947fc925fdSRoman Zippel void ConfigList::contextMenuEvent(QContextMenuEvent *e)
7957fc925fdSRoman Zippel {
7967fc925fdSRoman Zippel 	if (e->y() <= header()->geometry().bottom()) {
7977fc925fdSRoman Zippel 		if (!headerPopup) {
7987fc925fdSRoman Zippel 			QAction *action;
7997fc925fdSRoman Zippel 
8007fc925fdSRoman Zippel 			headerPopup = new QPopupMenu(this);
80144ddc4f5Sakpm@osdl.org 			action = new QAction(NULL, "Show Name", 0, this);
8027fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8037fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8047fc925fdSRoman Zippel 				  parent(), SLOT(setShowName(bool)));
8057fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showNameChanged(bool)),
8067fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8077fc925fdSRoman Zippel 			  action->setOn(showName);
8087fc925fdSRoman Zippel 			  action->addTo(headerPopup);
80944ddc4f5Sakpm@osdl.org 			action = new QAction(NULL, "Show Range", 0, this);
8107fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8117fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8127fc925fdSRoman Zippel 				  parent(), SLOT(setShowRange(bool)));
8137fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showRangeChanged(bool)),
8147fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8157fc925fdSRoman Zippel 			  action->setOn(showRange);
8167fc925fdSRoman Zippel 			  action->addTo(headerPopup);
81744ddc4f5Sakpm@osdl.org 			action = new QAction(NULL, "Show Data", 0, this);
8187fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8197fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8207fc925fdSRoman Zippel 				  parent(), SLOT(setShowData(bool)));
8217fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showDataChanged(bool)),
8227fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8237fc925fdSRoman Zippel 			  action->setOn(showData);
8247fc925fdSRoman Zippel 			  action->addTo(headerPopup);
8257fc925fdSRoman Zippel 		}
8267fc925fdSRoman Zippel 		headerPopup->exec(e->globalPos());
8277fc925fdSRoman Zippel 		e->accept();
8287fc925fdSRoman Zippel 	} else
8297fc925fdSRoman Zippel 		e->ignore();
8307fc925fdSRoman Zippel }
8317fc925fdSRoman Zippel 
8321da177e4SLinus Torvalds ConfigView* ConfigView::viewList;
8331da177e4SLinus Torvalds 
8347fc925fdSRoman Zippel ConfigView::ConfigView(QWidget* parent, const char *name)
8357fc925fdSRoman Zippel 	: Parent(parent, name)
8361da177e4SLinus Torvalds {
8377fc925fdSRoman Zippel 	list = new ConfigList(this, name);
8381da177e4SLinus Torvalds 	lineEdit = new ConfigLineEdit(this);
8391da177e4SLinus Torvalds 	lineEdit->hide();
8401da177e4SLinus Torvalds 
8411da177e4SLinus Torvalds 	this->nextView = viewList;
8421da177e4SLinus Torvalds 	viewList = this;
8431da177e4SLinus Torvalds }
8441da177e4SLinus Torvalds 
8451da177e4SLinus Torvalds ConfigView::~ConfigView(void)
8461da177e4SLinus Torvalds {
8471da177e4SLinus Torvalds 	ConfigView** vp;
8481da177e4SLinus Torvalds 
8491da177e4SLinus Torvalds 	for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
8501da177e4SLinus Torvalds 		if (*vp == this) {
8511da177e4SLinus Torvalds 			*vp = nextView;
8521da177e4SLinus Torvalds 			break;
8531da177e4SLinus Torvalds 		}
8541da177e4SLinus Torvalds 	}
8551da177e4SLinus Torvalds }
8561da177e4SLinus Torvalds 
8577fc925fdSRoman Zippel void ConfigView::setShowAll(bool b)
8587fc925fdSRoman Zippel {
8597fc925fdSRoman Zippel 	if (list->showAll != b) {
8607fc925fdSRoman Zippel 		list->showAll = b;
8617fc925fdSRoman Zippel 		list->updateListAll();
8627fc925fdSRoman Zippel 		emit showAllChanged(b);
8637fc925fdSRoman Zippel 	}
8647fc925fdSRoman Zippel }
8657fc925fdSRoman Zippel 
8667fc925fdSRoman Zippel void ConfigView::setShowName(bool b)
8677fc925fdSRoman Zippel {
8687fc925fdSRoman Zippel 	if (list->showName != b) {
8697fc925fdSRoman Zippel 		list->showName = b;
8707fc925fdSRoman Zippel 		list->reinit();
8717fc925fdSRoman Zippel 		emit showNameChanged(b);
8727fc925fdSRoman Zippel 	}
8737fc925fdSRoman Zippel }
8747fc925fdSRoman Zippel 
8757fc925fdSRoman Zippel void ConfigView::setShowRange(bool b)
8767fc925fdSRoman Zippel {
8777fc925fdSRoman Zippel 	if (list->showRange != b) {
8787fc925fdSRoman Zippel 		list->showRange = b;
8797fc925fdSRoman Zippel 		list->reinit();
8807fc925fdSRoman Zippel 		emit showRangeChanged(b);
8817fc925fdSRoman Zippel 	}
8827fc925fdSRoman Zippel }
8837fc925fdSRoman Zippel 
8847fc925fdSRoman Zippel void ConfigView::setShowData(bool b)
8857fc925fdSRoman Zippel {
8867fc925fdSRoman Zippel 	if (list->showData != b) {
8877fc925fdSRoman Zippel 		list->showData = b;
8887fc925fdSRoman Zippel 		list->reinit();
8897fc925fdSRoman Zippel 		emit showDataChanged(b);
8907fc925fdSRoman Zippel 	}
8917fc925fdSRoman Zippel }
8927fc925fdSRoman Zippel 
8937fc925fdSRoman Zippel void ConfigList::setAllOpen(bool open)
8947fc925fdSRoman Zippel {
8957fc925fdSRoman Zippel 	QListViewItemIterator it(this);
8967fc925fdSRoman Zippel 
8977fc925fdSRoman Zippel 	for (; it.current(); it++)
8987fc925fdSRoman Zippel 		it.current()->setOpen(open);
8997fc925fdSRoman Zippel }
9007fc925fdSRoman Zippel 
9011da177e4SLinus Torvalds void ConfigView::updateList(ConfigItem* item)
9021da177e4SLinus Torvalds {
9031da177e4SLinus Torvalds 	ConfigView* v;
9041da177e4SLinus Torvalds 
9051da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9061da177e4SLinus Torvalds 		v->list->updateList(item);
9071da177e4SLinus Torvalds }
9081da177e4SLinus Torvalds 
9091da177e4SLinus Torvalds void ConfigView::updateListAll(void)
9101da177e4SLinus Torvalds {
9111da177e4SLinus Torvalds 	ConfigView* v;
9121da177e4SLinus Torvalds 
9131da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9141da177e4SLinus Torvalds 		v->list->updateListAll();
9151da177e4SLinus Torvalds }
9161da177e4SLinus Torvalds 
91743bf612aSRoman Zippel ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
91843bf612aSRoman Zippel 	: Parent(parent, name), menu(0)
9191da177e4SLinus Torvalds {
9207fc925fdSRoman Zippel 	if (name) {
9217fc925fdSRoman Zippel 		configSettings->beginGroup(name);
9227fc925fdSRoman Zippel 		_showDebug = configSettings->readBoolEntry("/showDebug", false);
9237fc925fdSRoman Zippel 		configSettings->endGroup();
9247fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
9257fc925fdSRoman Zippel 	}
9267fc925fdSRoman Zippel }
9277fc925fdSRoman Zippel 
9287fc925fdSRoman Zippel void ConfigInfoView::saveSettings(void)
9297fc925fdSRoman Zippel {
9307fc925fdSRoman Zippel 	if (name()) {
9317fc925fdSRoman Zippel 		configSettings->beginGroup(name());
9327fc925fdSRoman Zippel 		configSettings->writeEntry("/showDebug", showDebug());
9337fc925fdSRoman Zippel 		configSettings->endGroup();
9347fc925fdSRoman Zippel 	}
9351da177e4SLinus Torvalds }
9361da177e4SLinus Torvalds 
93743bf612aSRoman Zippel void ConfigInfoView::setShowDebug(bool b)
9381da177e4SLinus Torvalds {
93943bf612aSRoman Zippel 	if (_showDebug != b) {
94043bf612aSRoman Zippel 		_showDebug = b;
94143bf612aSRoman Zippel 		if (menu)
94243bf612aSRoman Zippel 			menuInfo();
943ab45d190SRoman Zippel 		else if (sym)
944ab45d190SRoman Zippel 			symbolInfo();
94543bf612aSRoman Zippel 		emit showDebugChanged(b);
9461da177e4SLinus Torvalds 	}
9471da177e4SLinus Torvalds }
9481da177e4SLinus Torvalds 
94943bf612aSRoman Zippel void ConfigInfoView::setInfo(struct menu *m)
9501da177e4SLinus Torvalds {
951b65a47e1SRoman Zippel 	if (menu == m)
952b65a47e1SRoman Zippel 		return;
95343bf612aSRoman Zippel 	menu = m;
95443bf612aSRoman Zippel 	if (!menu)
95543bf612aSRoman Zippel 		clear();
95643bf612aSRoman Zippel 	else
95743bf612aSRoman Zippel 		menuInfo();
9581da177e4SLinus Torvalds }
9591da177e4SLinus Torvalds 
96043bf612aSRoman Zippel void ConfigInfoView::setSource(const QString& name)
96143bf612aSRoman Zippel {
96243bf612aSRoman Zippel 	const char *p = name.latin1();
96343bf612aSRoman Zippel 
96443bf612aSRoman Zippel 	menu = NULL;
965ab45d190SRoman Zippel 	sym = NULL;
96643bf612aSRoman Zippel 
96743bf612aSRoman Zippel 	switch (p[0]) {
96843bf612aSRoman Zippel 	case 'm':
969ab45d190SRoman Zippel 		struct menu *m;
970ab45d190SRoman Zippel 
971ab45d190SRoman Zippel 		if (sscanf(p, "m%p", &m) == 1 && menu != m) {
972ab45d190SRoman Zippel 			menu = m;
97343bf612aSRoman Zippel 			menuInfo();
974b65a47e1SRoman Zippel 			emit menuSelected(menu);
975ab45d190SRoman Zippel 		}
976ab45d190SRoman Zippel 		break;
977ab45d190SRoman Zippel 	case 's':
978ab45d190SRoman Zippel 		struct symbol *s;
979ab45d190SRoman Zippel 
980ab45d190SRoman Zippel 		if (sscanf(p, "s%p", &s) == 1 && sym != s) {
981ab45d190SRoman Zippel 			sym = s;
982ab45d190SRoman Zippel 			symbolInfo();
983ab45d190SRoman Zippel 		}
98443bf612aSRoman Zippel 		break;
98543bf612aSRoman Zippel 	}
98643bf612aSRoman Zippel }
98743bf612aSRoman Zippel 
988ab45d190SRoman Zippel void ConfigInfoView::symbolInfo(void)
989ab45d190SRoman Zippel {
990ab45d190SRoman Zippel 	QString str;
991ab45d190SRoman Zippel 
992ab45d190SRoman Zippel 	str += "<big>Symbol: <b>";
993ab45d190SRoman Zippel 	str += print_filter(sym->name);
994ab45d190SRoman Zippel 	str += "</b></big><br><br>value: ";
995ab45d190SRoman Zippel 	str += print_filter(sym_get_string_value(sym));
996ab45d190SRoman Zippel 	str += "<br>visibility: ";
997ab45d190SRoman Zippel 	str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
998ab45d190SRoman Zippel 	str += "<br>";
999ab45d190SRoman Zippel 	str += debug_info(sym);
1000ab45d190SRoman Zippel 
1001ab45d190SRoman Zippel 	setText(str);
1002ab45d190SRoman Zippel }
1003ab45d190SRoman Zippel 
100443bf612aSRoman Zippel void ConfigInfoView::menuInfo(void)
10051da177e4SLinus Torvalds {
10061da177e4SLinus Torvalds 	struct symbol* sym;
10071da177e4SLinus Torvalds 	QString head, debug, help;
100843bf612aSRoman Zippel 
10091da177e4SLinus Torvalds 	sym = menu->sym;
10101da177e4SLinus Torvalds 	if (sym) {
10111da177e4SLinus Torvalds 		if (menu->prompt) {
10121da177e4SLinus Torvalds 			head += "<big><b>";
10133b9fa093SArnaldo Carvalho de Melo 			head += print_filter(_(menu->prompt->text));
10141da177e4SLinus Torvalds 			head += "</b></big>";
10151da177e4SLinus Torvalds 			if (sym->name) {
10161da177e4SLinus Torvalds 				head += " (";
1017ab45d190SRoman Zippel 				if (showDebug())
1018ab45d190SRoman Zippel 					head += QString().sprintf("<a href=\"s%p\">", sym);
101943bf612aSRoman Zippel 				head += print_filter(sym->name);
1020ab45d190SRoman Zippel 				if (showDebug())
1021ab45d190SRoman Zippel 					head += "</a>";
10221da177e4SLinus Torvalds 				head += ")";
10231da177e4SLinus Torvalds 			}
10241da177e4SLinus Torvalds 		} else if (sym->name) {
10251da177e4SLinus Torvalds 			head += "<big><b>";
1026ab45d190SRoman Zippel 			if (showDebug())
1027ab45d190SRoman Zippel 				head += QString().sprintf("<a href=\"s%p\">", sym);
102843bf612aSRoman Zippel 			head += print_filter(sym->name);
1029ab45d190SRoman Zippel 			if (showDebug())
1030ab45d190SRoman Zippel 				head += "</a>";
10311da177e4SLinus Torvalds 			head += "</b></big>";
10321da177e4SLinus Torvalds 		}
10331da177e4SLinus Torvalds 		head += "<br><br>";
10341da177e4SLinus Torvalds 
103543bf612aSRoman Zippel 		if (showDebug())
103643bf612aSRoman Zippel 			debug = debug_info(sym);
103743bf612aSRoman Zippel 
103843bf612aSRoman Zippel 		help = print_filter(_(sym->help));
103943bf612aSRoman Zippel 	} else if (menu->prompt) {
104043bf612aSRoman Zippel 		head += "<big><b>";
104143bf612aSRoman Zippel 		head += print_filter(_(menu->prompt->text));
104243bf612aSRoman Zippel 		head += "</b></big><br><br>";
104343bf612aSRoman Zippel 		if (showDebug()) {
104443bf612aSRoman Zippel 			if (menu->prompt->visible.expr) {
104543bf612aSRoman Zippel 				debug += "&nbsp;&nbsp;dep: ";
104643bf612aSRoman Zippel 				expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
104743bf612aSRoman Zippel 				debug += "<br><br>";
104843bf612aSRoman Zippel 			}
104943bf612aSRoman Zippel 		}
105043bf612aSRoman Zippel 	}
105143bf612aSRoman Zippel 	if (showDebug())
105243bf612aSRoman Zippel 		debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno);
105343bf612aSRoman Zippel 
105443bf612aSRoman Zippel 	setText(head + debug + help);
105543bf612aSRoman Zippel }
105643bf612aSRoman Zippel 
105743bf612aSRoman Zippel QString ConfigInfoView::debug_info(struct symbol *sym)
105843bf612aSRoman Zippel {
105943bf612aSRoman Zippel 	QString debug;
106043bf612aSRoman Zippel 
10611da177e4SLinus Torvalds 	debug += "type: ";
10621da177e4SLinus Torvalds 	debug += print_filter(sym_type_name(sym->type));
10631da177e4SLinus Torvalds 	if (sym_is_choice(sym))
10641da177e4SLinus Torvalds 		debug += " (choice)";
10651da177e4SLinus Torvalds 	debug += "<br>";
10661da177e4SLinus Torvalds 	if (sym->rev_dep.expr) {
10671da177e4SLinus Torvalds 		debug += "reverse dep: ";
10681da177e4SLinus Torvalds 		expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
10691da177e4SLinus Torvalds 		debug += "<br>";
10701da177e4SLinus Torvalds 	}
10711da177e4SLinus Torvalds 	for (struct property *prop = sym->prop; prop; prop = prop->next) {
10721da177e4SLinus Torvalds 		switch (prop->type) {
10731da177e4SLinus Torvalds 		case P_PROMPT:
10741da177e4SLinus Torvalds 		case P_MENU:
1075ab45d190SRoman Zippel 			debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
10763b9fa093SArnaldo Carvalho de Melo 			debug += print_filter(_(prop->text));
1077ab45d190SRoman Zippel 			debug += "</a><br>";
10781da177e4SLinus Torvalds 			break;
10791da177e4SLinus Torvalds 		case P_DEFAULT:
10801da177e4SLinus Torvalds 			debug += "default: ";
10811da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10821da177e4SLinus Torvalds 			debug += "<br>";
10831da177e4SLinus Torvalds 			break;
10841da177e4SLinus Torvalds 		case P_CHOICE:
10851da177e4SLinus Torvalds 			if (sym_is_choice(sym)) {
10861da177e4SLinus Torvalds 				debug += "choice: ";
10871da177e4SLinus Torvalds 				expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10881da177e4SLinus Torvalds 				debug += "<br>";
10891da177e4SLinus Torvalds 			}
10901da177e4SLinus Torvalds 			break;
10911da177e4SLinus Torvalds 		case P_SELECT:
10921da177e4SLinus Torvalds 			debug += "select: ";
10931da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10941da177e4SLinus Torvalds 			debug += "<br>";
10951da177e4SLinus Torvalds 			break;
10961da177e4SLinus Torvalds 		case P_RANGE:
10971da177e4SLinus Torvalds 			debug += "range: ";
10981da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10991da177e4SLinus Torvalds 			debug += "<br>";
11001da177e4SLinus Torvalds 			break;
11011da177e4SLinus Torvalds 		default:
11021da177e4SLinus Torvalds 			debug += "unknown property: ";
11031da177e4SLinus Torvalds 			debug += prop_get_type_name(prop->type);
11041da177e4SLinus Torvalds 			debug += "<br>";
11051da177e4SLinus Torvalds 		}
11061da177e4SLinus Torvalds 		if (prop->visible.expr) {
11071da177e4SLinus Torvalds 			debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
11081da177e4SLinus Torvalds 			expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
11091da177e4SLinus Torvalds 			debug += "<br>";
11101da177e4SLinus Torvalds 		}
11111da177e4SLinus Torvalds 	}
11121da177e4SLinus Torvalds 	debug += "<br>";
111343bf612aSRoman Zippel 
111443bf612aSRoman Zippel 	return debug;
11151da177e4SLinus Torvalds }
11161da177e4SLinus Torvalds 
111743bf612aSRoman Zippel QString ConfigInfoView::print_filter(const QString &str)
111843bf612aSRoman Zippel {
111943bf612aSRoman Zippel 	QRegExp re("[<>&\"\\n]");
112043bf612aSRoman Zippel 	QString res = str;
112143bf612aSRoman Zippel 	for (int i = 0; (i = res.find(re, i)) >= 0;) {
112243bf612aSRoman Zippel 		switch (res[i].latin1()) {
112343bf612aSRoman Zippel 		case '<':
112443bf612aSRoman Zippel 			res.replace(i, 1, "&lt;");
112543bf612aSRoman Zippel 			i += 4;
112643bf612aSRoman Zippel 			break;
112743bf612aSRoman Zippel 		case '>':
112843bf612aSRoman Zippel 			res.replace(i, 1, "&gt;");
112943bf612aSRoman Zippel 			i += 4;
113043bf612aSRoman Zippel 			break;
113143bf612aSRoman Zippel 		case '&':
113243bf612aSRoman Zippel 			res.replace(i, 1, "&amp;");
113343bf612aSRoman Zippel 			i += 5;
113443bf612aSRoman Zippel 			break;
113543bf612aSRoman Zippel 		case '"':
113643bf612aSRoman Zippel 			res.replace(i, 1, "&quot;");
113743bf612aSRoman Zippel 			i += 6;
113843bf612aSRoman Zippel 			break;
113943bf612aSRoman Zippel 		case '\n':
114043bf612aSRoman Zippel 			res.replace(i, 1, "<br>");
114143bf612aSRoman Zippel 			i += 4;
114243bf612aSRoman Zippel 			break;
11431da177e4SLinus Torvalds 		}
11441da177e4SLinus Torvalds 	}
114543bf612aSRoman Zippel 	return res;
11461da177e4SLinus Torvalds }
114743bf612aSRoman Zippel 
1148ab45d190SRoman Zippel void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
114943bf612aSRoman Zippel {
1150ab45d190SRoman Zippel 	QString* text = reinterpret_cast<QString*>(data);
1151ab45d190SRoman Zippel 	QString str2 = print_filter(str);
1152ab45d190SRoman Zippel 
1153ab45d190SRoman Zippel 	if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1154ab45d190SRoman Zippel 		*text += QString().sprintf("<a href=\"s%p\">", sym);
1155ab45d190SRoman Zippel 		*text += str2;
1156ab45d190SRoman Zippel 		*text += "</a>";
1157ab45d190SRoman Zippel 	} else
1158ab45d190SRoman Zippel 		*text += str2;
115943bf612aSRoman Zippel }
116043bf612aSRoman Zippel 
11617fc925fdSRoman Zippel QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
11627fc925fdSRoman Zippel {
11637fc925fdSRoman Zippel 	QPopupMenu* popup = Parent::createPopupMenu(pos);
116444ddc4f5Sakpm@osdl.org 	QAction* action = new QAction(NULL,"Show Debug Info", 0, popup);
11657fc925fdSRoman Zippel 	  action->setToggleAction(TRUE);
11667fc925fdSRoman Zippel 	  connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
11677fc925fdSRoman Zippel 	  connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
11687fc925fdSRoman Zippel 	  action->setOn(showDebug());
11697fc925fdSRoman Zippel 	popup->insertSeparator();
11707fc925fdSRoman Zippel 	action->addTo(popup);
11717fc925fdSRoman Zippel 	return popup;
11727fc925fdSRoman Zippel }
11737fc925fdSRoman Zippel 
11747fc925fdSRoman Zippel void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
11757fc925fdSRoman Zippel {
11767fc925fdSRoman Zippel 	Parent::contentsContextMenuEvent(e);
11777fc925fdSRoman Zippel }
11787fc925fdSRoman Zippel 
11797fc925fdSRoman Zippel ConfigSearchWindow::ConfigSearchWindow(QWidget* parent, const char *name)
11807fc925fdSRoman Zippel 	: Parent(parent, name), result(NULL)
118143bf612aSRoman Zippel {
118243bf612aSRoman Zippel 	setCaption("Search Config");
118343bf612aSRoman Zippel 
118443bf612aSRoman Zippel 	QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
118543bf612aSRoman Zippel 	QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
118643bf612aSRoman Zippel 	layout2->addWidget(new QLabel("Find:", this));
118743bf612aSRoman Zippel 	editField = new QLineEdit(this);
118843bf612aSRoman Zippel 	connect(editField, SIGNAL(returnPressed()), SLOT(search()));
118943bf612aSRoman Zippel 	layout2->addWidget(editField);
119043bf612aSRoman Zippel 	searchButton = new QPushButton("Search", this);
119143bf612aSRoman Zippel 	searchButton->setAutoDefault(FALSE);
119243bf612aSRoman Zippel 	connect(searchButton, SIGNAL(clicked()), SLOT(search()));
119343bf612aSRoman Zippel 	layout2->addWidget(searchButton);
119443bf612aSRoman Zippel 	layout1->addLayout(layout2);
119543bf612aSRoman Zippel 
11967fc925fdSRoman Zippel 	split = new QSplitter(this);
119743bf612aSRoman Zippel 	split->setOrientation(QSplitter::Vertical);
11987fc925fdSRoman Zippel 	list = new ConfigView(split, name);
119943bf612aSRoman Zippel 	list->list->mode = listMode;
12007fc925fdSRoman Zippel 	info = new ConfigInfoView(split, name);
120143bf612aSRoman Zippel 	connect(list->list, SIGNAL(menuChanged(struct menu *)),
120243bf612aSRoman Zippel 		info, SLOT(setInfo(struct menu *)));
120343bf612aSRoman Zippel 	layout1->addWidget(split);
12047fc925fdSRoman Zippel 
12057fc925fdSRoman Zippel 	if (name) {
12067fc925fdSRoman Zippel 		int x, y, width, height;
12077fc925fdSRoman Zippel 		bool ok;
12087fc925fdSRoman Zippel 
12097fc925fdSRoman Zippel 		configSettings->beginGroup(name);
12107fc925fdSRoman Zippel 		width = configSettings->readNumEntry("/window width", parent->width() / 2);
12117fc925fdSRoman Zippel 		height = configSettings->readNumEntry("/window height", parent->height() / 2);
12127fc925fdSRoman Zippel 		resize(width, height);
12137fc925fdSRoman Zippel 		x = configSettings->readNumEntry("/window x", 0, &ok);
12147fc925fdSRoman Zippel 		if (ok)
12157fc925fdSRoman Zippel 			y = configSettings->readNumEntry("/window y", 0, &ok);
12167fc925fdSRoman Zippel 		if (ok)
12177fc925fdSRoman Zippel 			move(x, y);
12187fc925fdSRoman Zippel 		QValueList<int> sizes = configSettings->readSizes("/split", &ok);
12197fc925fdSRoman Zippel 		if (ok)
12207fc925fdSRoman Zippel 			split->setSizes(sizes);
12217fc925fdSRoman Zippel 		configSettings->endGroup();
12227fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
12237fc925fdSRoman Zippel 	}
12247fc925fdSRoman Zippel }
12257fc925fdSRoman Zippel 
12267fc925fdSRoman Zippel void ConfigSearchWindow::saveSettings(void)
12277fc925fdSRoman Zippel {
12287fc925fdSRoman Zippel 	if (name()) {
12297fc925fdSRoman Zippel 		configSettings->beginGroup(name());
12307fc925fdSRoman Zippel 		configSettings->writeEntry("/window x", pos().x());
12317fc925fdSRoman Zippel 		configSettings->writeEntry("/window y", pos().y());
12327fc925fdSRoman Zippel 		configSettings->writeEntry("/window width", size().width());
12337fc925fdSRoman Zippel 		configSettings->writeEntry("/window height", size().height());
12347fc925fdSRoman Zippel 		configSettings->writeSizes("/split", split->sizes());
12357fc925fdSRoman Zippel 		configSettings->endGroup();
12367fc925fdSRoman Zippel 	}
123743bf612aSRoman Zippel }
123843bf612aSRoman Zippel 
123943bf612aSRoman Zippel void ConfigSearchWindow::search(void)
124043bf612aSRoman Zippel {
124143bf612aSRoman Zippel 	struct symbol **p;
124243bf612aSRoman Zippel 	struct property *prop;
124343bf612aSRoman Zippel 	ConfigItem *lastItem = NULL;
124443bf612aSRoman Zippel 
124543bf612aSRoman Zippel 	free(result);
124643bf612aSRoman Zippel 	list->list->clear();
124743bf612aSRoman Zippel 
124843bf612aSRoman Zippel 	result = sym_re_search(editField->text().latin1());
124943bf612aSRoman Zippel 	if (!result)
125043bf612aSRoman Zippel 		return;
125143bf612aSRoman Zippel 	for (p = result; *p; p++) {
125243bf612aSRoman Zippel 		for_all_prompts((*p), prop)
125343bf612aSRoman Zippel 			lastItem = new ConfigItem(list->list, lastItem, prop->menu,
125443bf612aSRoman Zippel 						  menu_is_visible(prop->menu));
125543bf612aSRoman Zippel 	}
125643bf612aSRoman Zippel }
125743bf612aSRoman Zippel 
125843bf612aSRoman Zippel /*
125943bf612aSRoman Zippel  * Construct the complete config widget
126043bf612aSRoman Zippel  */
126143bf612aSRoman Zippel ConfigMainWindow::ConfigMainWindow(void)
1262f12aa704SRoman Zippel 	: searchWindow(0)
126343bf612aSRoman Zippel {
126443bf612aSRoman Zippel 	QMenuBar* menu;
12657fc925fdSRoman Zippel 	bool ok;
126643bf612aSRoman Zippel 	int x, y, width, height;
126743bf612aSRoman Zippel 
126843bf612aSRoman Zippel 	QWidget *d = configApp->desktop();
126943bf612aSRoman Zippel 
12707fc925fdSRoman Zippel 	width = configSettings->readNumEntry("/window width", d->width() - 64);
12717fc925fdSRoman Zippel 	height = configSettings->readNumEntry("/window height", d->height() - 64);
127243bf612aSRoman Zippel 	resize(width, height);
12737fc925fdSRoman Zippel 	x = configSettings->readNumEntry("/window x", 0, &ok);
127443bf612aSRoman Zippel 	if (ok)
12757fc925fdSRoman Zippel 		y = configSettings->readNumEntry("/window y", 0, &ok);
127643bf612aSRoman Zippel 	if (ok)
127743bf612aSRoman Zippel 		move(x, y);
127843bf612aSRoman Zippel 
127943bf612aSRoman Zippel 	split1 = new QSplitter(this);
128043bf612aSRoman Zippel 	split1->setOrientation(QSplitter::Horizontal);
128143bf612aSRoman Zippel 	setCentralWidget(split1);
128243bf612aSRoman Zippel 
12837fc925fdSRoman Zippel 	menuView = new ConfigView(split1, "menu");
128443bf612aSRoman Zippel 	menuList = menuView->list;
128543bf612aSRoman Zippel 
128643bf612aSRoman Zippel 	split2 = new QSplitter(split1);
128743bf612aSRoman Zippel 	split2->setOrientation(QSplitter::Vertical);
128843bf612aSRoman Zippel 
128943bf612aSRoman Zippel 	// create config tree
12907fc925fdSRoman Zippel 	configView = new ConfigView(split2, "config");
129143bf612aSRoman Zippel 	configList = configView->list;
129243bf612aSRoman Zippel 
12937fc925fdSRoman Zippel 	helpText = new ConfigInfoView(split2, "help");
129443bf612aSRoman Zippel 	helpText->setTextFormat(Qt::RichText);
129543bf612aSRoman Zippel 
129643bf612aSRoman Zippel 	setTabOrder(configList, helpText);
129743bf612aSRoman Zippel 	configList->setFocus();
129843bf612aSRoman Zippel 
129943bf612aSRoman Zippel 	menu = menuBar();
130043bf612aSRoman Zippel 	toolBar = new QToolBar("Tools", this);
130143bf612aSRoman Zippel 
130243bf612aSRoman Zippel 	backAction = new QAction("Back", QPixmap(xpm_back), "Back", 0, this);
130343bf612aSRoman Zippel 	  connect(backAction, SIGNAL(activated()), SLOT(goBack()));
130443bf612aSRoman Zippel 	  backAction->setEnabled(FALSE);
130543bf612aSRoman Zippel 	QAction *quitAction = new QAction("Quit", "&Quit", CTRL+Key_Q, this);
130643bf612aSRoman Zippel 	  connect(quitAction, SIGNAL(activated()), SLOT(close()));
130743bf612aSRoman Zippel 	QAction *loadAction = new QAction("Load", QPixmap(xpm_load), "&Load", CTRL+Key_L, this);
130843bf612aSRoman Zippel 	  connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
130943bf612aSRoman Zippel 	QAction *saveAction = new QAction("Save", QPixmap(xpm_save), "&Save", CTRL+Key_S, this);
131043bf612aSRoman Zippel 	  connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
131143bf612aSRoman Zippel 	QAction *saveAsAction = new QAction("Save As...", "Save &As...", 0, this);
131243bf612aSRoman Zippel 	  connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
131343bf612aSRoman Zippel 	QAction *searchAction = new QAction("Search", "&Search", CTRL+Key_F, this);
131443bf612aSRoman Zippel 	  connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
131543bf612aSRoman Zippel 	QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), "Split View", 0, this);
131643bf612aSRoman Zippel 	  connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
131743bf612aSRoman Zippel 	QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), "Split View", 0, this);
131843bf612aSRoman Zippel 	  connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
131943bf612aSRoman Zippel 	QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), "Full View", 0, this);
132043bf612aSRoman Zippel 	  connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
132143bf612aSRoman Zippel 
132243bf612aSRoman Zippel 	QAction *showNameAction = new QAction(NULL, "Show Name", 0, this);
132343bf612aSRoman Zippel 	  showNameAction->setToggleAction(TRUE);
13247fc925fdSRoman Zippel 	  connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
13257fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
13267fc925fdSRoman Zippel 	  showNameAction->setOn(configView->showName());
132743bf612aSRoman Zippel 	QAction *showRangeAction = new QAction(NULL, "Show Range", 0, this);
132843bf612aSRoman Zippel 	  showRangeAction->setToggleAction(TRUE);
13297fc925fdSRoman Zippel 	  connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
13307fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
133143bf612aSRoman Zippel 	  showRangeAction->setOn(configList->showRange);
133243bf612aSRoman Zippel 	QAction *showDataAction = new QAction(NULL, "Show Data", 0, this);
133343bf612aSRoman Zippel 	  showDataAction->setToggleAction(TRUE);
13347fc925fdSRoman Zippel 	  connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
13357fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
133643bf612aSRoman Zippel 	  showDataAction->setOn(configList->showData);
133743bf612aSRoman Zippel 	QAction *showAllAction = new QAction(NULL, "Show All Options", 0, this);
133843bf612aSRoman Zippel 	  showAllAction->setToggleAction(TRUE);
13397fc925fdSRoman Zippel 	  connect(showAllAction, SIGNAL(toggled(bool)), configView, SLOT(setShowAll(bool)));
13407fc925fdSRoman Zippel 	  connect(showAllAction, SIGNAL(toggled(bool)), menuView, SLOT(setShowAll(bool)));
134143bf612aSRoman Zippel 	  showAllAction->setOn(configList->showAll);
134243bf612aSRoman Zippel 	QAction *showDebugAction = new QAction(NULL, "Show Debug Info", 0, this);
134343bf612aSRoman Zippel 	  showDebugAction->setToggleAction(TRUE);
134443bf612aSRoman Zippel 	  connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
134543bf612aSRoman Zippel 	  connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
13467fc925fdSRoman Zippel 	  showDebugAction->setOn(helpText->showDebug());
134743bf612aSRoman Zippel 
134843bf612aSRoman Zippel 	QAction *showIntroAction = new QAction(NULL, "Introduction", 0, this);
134943bf612aSRoman Zippel 	  connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
135043bf612aSRoman Zippel 	QAction *showAboutAction = new QAction(NULL, "About", 0, this);
135143bf612aSRoman Zippel 	  connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
135243bf612aSRoman Zippel 
135343bf612aSRoman Zippel 	// init tool bar
135443bf612aSRoman Zippel 	backAction->addTo(toolBar);
135543bf612aSRoman Zippel 	toolBar->addSeparator();
135643bf612aSRoman Zippel 	loadAction->addTo(toolBar);
135743bf612aSRoman Zippel 	saveAction->addTo(toolBar);
135843bf612aSRoman Zippel 	toolBar->addSeparator();
135943bf612aSRoman Zippel 	singleViewAction->addTo(toolBar);
136043bf612aSRoman Zippel 	splitViewAction->addTo(toolBar);
136143bf612aSRoman Zippel 	fullViewAction->addTo(toolBar);
136243bf612aSRoman Zippel 
136343bf612aSRoman Zippel 	// create config menu
136443bf612aSRoman Zippel 	QPopupMenu* config = new QPopupMenu(this);
136543bf612aSRoman Zippel 	menu->insertItem("&File", config);
136643bf612aSRoman Zippel 	loadAction->addTo(config);
136743bf612aSRoman Zippel 	saveAction->addTo(config);
136843bf612aSRoman Zippel 	saveAsAction->addTo(config);
136943bf612aSRoman Zippel 	config->insertSeparator();
137043bf612aSRoman Zippel 	searchAction->addTo(config);
137143bf612aSRoman Zippel 	config->insertSeparator();
137243bf612aSRoman Zippel 	quitAction->addTo(config);
137343bf612aSRoman Zippel 
137443bf612aSRoman Zippel 	// create options menu
137543bf612aSRoman Zippel 	QPopupMenu* optionMenu = new QPopupMenu(this);
137643bf612aSRoman Zippel 	menu->insertItem("&Option", optionMenu);
137743bf612aSRoman Zippel 	showNameAction->addTo(optionMenu);
137843bf612aSRoman Zippel 	showRangeAction->addTo(optionMenu);
137943bf612aSRoman Zippel 	showDataAction->addTo(optionMenu);
138043bf612aSRoman Zippel 	optionMenu->insertSeparator();
138143bf612aSRoman Zippel 	showAllAction->addTo(optionMenu);
138243bf612aSRoman Zippel 	showDebugAction->addTo(optionMenu);
138343bf612aSRoman Zippel 
138443bf612aSRoman Zippel 	// create help menu
138543bf612aSRoman Zippel 	QPopupMenu* helpMenu = new QPopupMenu(this);
138643bf612aSRoman Zippel 	menu->insertSeparator();
138743bf612aSRoman Zippel 	menu->insertItem("&Help", helpMenu);
138843bf612aSRoman Zippel 	showIntroAction->addTo(helpMenu);
138943bf612aSRoman Zippel 	showAboutAction->addTo(helpMenu);
139043bf612aSRoman Zippel 
139143bf612aSRoman Zippel 	connect(configList, SIGNAL(menuChanged(struct menu *)),
139243bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
139343bf612aSRoman Zippel 	connect(configList, SIGNAL(menuSelected(struct menu *)),
139443bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
139543bf612aSRoman Zippel 	connect(configList, SIGNAL(parentSelected()),
139643bf612aSRoman Zippel 		SLOT(goBack()));
139743bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuChanged(struct menu *)),
139843bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
139943bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuSelected(struct menu *)),
140043bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
140143bf612aSRoman Zippel 
1402b65a47e1SRoman Zippel 	connect(configList, SIGNAL(gotFocus(struct menu *)),
1403b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1404b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
1405b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1406b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
140743bf612aSRoman Zippel 		SLOT(listFocusChanged(void)));
1408b65a47e1SRoman Zippel 	connect(helpText, SIGNAL(menuSelected(struct menu *)),
1409b65a47e1SRoman Zippel 		SLOT(setMenuLink(struct menu *)));
141043bf612aSRoman Zippel 
14117fc925fdSRoman Zippel 	QString listMode = configSettings->readEntry("/listMode", "symbol");
141243bf612aSRoman Zippel 	if (listMode == "single")
141343bf612aSRoman Zippel 		showSingleView();
141443bf612aSRoman Zippel 	else if (listMode == "full")
141543bf612aSRoman Zippel 		showFullView();
141643bf612aSRoman Zippel 	else /*if (listMode == "split")*/
141743bf612aSRoman Zippel 		showSplitView();
141843bf612aSRoman Zippel 
141943bf612aSRoman Zippel 	// UI setup done, restore splitter positions
14207fc925fdSRoman Zippel 	QValueList<int> sizes = configSettings->readSizes("/split1", &ok);
142143bf612aSRoman Zippel 	if (ok)
142243bf612aSRoman Zippel 		split1->setSizes(sizes);
142343bf612aSRoman Zippel 
14247fc925fdSRoman Zippel 	sizes = configSettings->readSizes("/split2", &ok);
142543bf612aSRoman Zippel 	if (ok)
142643bf612aSRoman Zippel 		split2->setSizes(sizes);
142743bf612aSRoman Zippel }
142843bf612aSRoman Zippel 
14291da177e4SLinus Torvalds void ConfigMainWindow::loadConfig(void)
14301da177e4SLinus Torvalds {
14311da177e4SLinus Torvalds 	QString s = QFileDialog::getOpenFileName(".config", NULL, this);
14321da177e4SLinus Torvalds 	if (s.isNull())
14331da177e4SLinus Torvalds 		return;
14343b9fa093SArnaldo Carvalho de Melo 	if (conf_read(QFile::encodeName(s)))
14351da177e4SLinus Torvalds 		QMessageBox::information(this, "qconf", "Unable to load configuration!");
14361da177e4SLinus Torvalds 	ConfigView::updateListAll();
14371da177e4SLinus Torvalds }
14381da177e4SLinus Torvalds 
14391da177e4SLinus Torvalds void ConfigMainWindow::saveConfig(void)
14401da177e4SLinus Torvalds {
14411da177e4SLinus Torvalds 	if (conf_write(NULL))
14421da177e4SLinus Torvalds 		QMessageBox::information(this, "qconf", "Unable to save configuration!");
14431da177e4SLinus Torvalds }
14441da177e4SLinus Torvalds 
14451da177e4SLinus Torvalds void ConfigMainWindow::saveConfigAs(void)
14461da177e4SLinus Torvalds {
14471da177e4SLinus Torvalds 	QString s = QFileDialog::getSaveFileName(".config", NULL, this);
14481da177e4SLinus Torvalds 	if (s.isNull())
14491da177e4SLinus Torvalds 		return;
14503b9fa093SArnaldo Carvalho de Melo 	if (conf_write(QFile::encodeName(s)))
14511da177e4SLinus Torvalds 		QMessageBox::information(this, "qconf", "Unable to save configuration!");
14521da177e4SLinus Torvalds }
14531da177e4SLinus Torvalds 
145443bf612aSRoman Zippel void ConfigMainWindow::searchConfig(void)
145543bf612aSRoman Zippel {
145643bf612aSRoman Zippel 	if (!searchWindow)
14577fc925fdSRoman Zippel 		searchWindow = new ConfigSearchWindow(this, "search");
145843bf612aSRoman Zippel 	searchWindow->show();
145943bf612aSRoman Zippel }
146043bf612aSRoman Zippel 
14611da177e4SLinus Torvalds void ConfigMainWindow::changeMenu(struct menu *menu)
14621da177e4SLinus Torvalds {
14631da177e4SLinus Torvalds 	configList->setRootMenu(menu);
14641da177e4SLinus Torvalds 	backAction->setEnabled(TRUE);
14651da177e4SLinus Torvalds }
14661da177e4SLinus Torvalds 
1467b65a47e1SRoman Zippel void ConfigMainWindow::setMenuLink(struct menu *menu)
1468b65a47e1SRoman Zippel {
1469b65a47e1SRoman Zippel 	struct menu *parent;
1470b65a47e1SRoman Zippel 	ConfigList* list = NULL;
1471b65a47e1SRoman Zippel 	ConfigItem* item;
1472b65a47e1SRoman Zippel 
1473b65a47e1SRoman Zippel 	if (!menu_is_visible(menu) && !configView->showAll())
1474b65a47e1SRoman Zippel 		return;
1475b65a47e1SRoman Zippel 
1476b65a47e1SRoman Zippel 	switch (configList->mode) {
1477b65a47e1SRoman Zippel 	case singleMode:
1478b65a47e1SRoman Zippel 		list = configList;
1479b65a47e1SRoman Zippel 		parent = menu_get_parent_menu(menu);
1480b65a47e1SRoman Zippel 		if (!parent)
1481b65a47e1SRoman Zippel 			return;
1482b65a47e1SRoman Zippel 		list->setRootMenu(parent);
1483b65a47e1SRoman Zippel 		break;
1484b65a47e1SRoman Zippel 	case symbolMode:
1485b65a47e1SRoman Zippel 		if (menu->flags & MENU_ROOT) {
1486b65a47e1SRoman Zippel 			configList->setRootMenu(menu);
1487b65a47e1SRoman Zippel 			configList->clearSelection();
1488b65a47e1SRoman Zippel 			list = menuList;
1489b65a47e1SRoman Zippel 		} else {
1490b65a47e1SRoman Zippel 			list = configList;
1491b65a47e1SRoman Zippel 			parent = menu_get_parent_menu(menu->parent);
1492b65a47e1SRoman Zippel 			if (!parent)
1493b65a47e1SRoman Zippel 				return;
1494b65a47e1SRoman Zippel 			item = menuList->findConfigItem(parent);
1495b65a47e1SRoman Zippel 			if (item) {
1496b65a47e1SRoman Zippel 				menuList->setSelected(item, TRUE);
1497b65a47e1SRoman Zippel 				menuList->ensureItemVisible(item);
1498b65a47e1SRoman Zippel 			}
1499b65a47e1SRoman Zippel 			list->setRootMenu(parent);
1500b65a47e1SRoman Zippel 		}
1501b65a47e1SRoman Zippel 		break;
1502b65a47e1SRoman Zippel 	case fullMode:
1503b65a47e1SRoman Zippel 		list = configList;
1504b65a47e1SRoman Zippel 		break;
1505b65a47e1SRoman Zippel 	}
1506b65a47e1SRoman Zippel 
1507b65a47e1SRoman Zippel 	if (list) {
1508b65a47e1SRoman Zippel 		item = list->findConfigItem(menu);
1509b65a47e1SRoman Zippel 		if (item) {
1510b65a47e1SRoman Zippel 			list->setSelected(item, TRUE);
1511b65a47e1SRoman Zippel 			list->ensureItemVisible(item);
1512b65a47e1SRoman Zippel 			list->setFocus();
1513b65a47e1SRoman Zippel 		}
1514b65a47e1SRoman Zippel 	}
1515b65a47e1SRoman Zippel }
1516b65a47e1SRoman Zippel 
15171da177e4SLinus Torvalds void ConfigMainWindow::listFocusChanged(void)
15181da177e4SLinus Torvalds {
15191da177e4SLinus Torvalds 	if (menuList->mode == menuMode)
15201da177e4SLinus Torvalds 		configList->clearSelection();
15211da177e4SLinus Torvalds }
15221da177e4SLinus Torvalds 
15231da177e4SLinus Torvalds void ConfigMainWindow::goBack(void)
15241da177e4SLinus Torvalds {
15251da177e4SLinus Torvalds 	ConfigItem* item;
15261da177e4SLinus Torvalds 
15271da177e4SLinus Torvalds 	configList->setParentMenu();
15281da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15291da177e4SLinus Torvalds 		backAction->setEnabled(FALSE);
15301da177e4SLinus Torvalds 	item = (ConfigItem*)menuList->selectedItem();
15311da177e4SLinus Torvalds 	while (item) {
15321da177e4SLinus Torvalds 		if (item->menu == configList->rootEntry) {
15331da177e4SLinus Torvalds 			menuList->setSelected(item, TRUE);
15341da177e4SLinus Torvalds 			break;
15351da177e4SLinus Torvalds 		}
15361da177e4SLinus Torvalds 		item = (ConfigItem*)item->parent();
15371da177e4SLinus Torvalds 	}
15381da177e4SLinus Torvalds }
15391da177e4SLinus Torvalds 
15401da177e4SLinus Torvalds void ConfigMainWindow::showSingleView(void)
15411da177e4SLinus Torvalds {
15421da177e4SLinus Torvalds 	menuView->hide();
15431da177e4SLinus Torvalds 	menuList->setRootMenu(0);
15441da177e4SLinus Torvalds 	configList->mode = singleMode;
15451da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15461da177e4SLinus Torvalds 		configList->updateListAll();
15471da177e4SLinus Torvalds 	else
15481da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15491da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
15501da177e4SLinus Torvalds 	configList->setFocus();
15511da177e4SLinus Torvalds }
15521da177e4SLinus Torvalds 
15531da177e4SLinus Torvalds void ConfigMainWindow::showSplitView(void)
15541da177e4SLinus Torvalds {
15551da177e4SLinus Torvalds 	configList->mode = symbolMode;
15561da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15571da177e4SLinus Torvalds 		configList->updateListAll();
15581da177e4SLinus Torvalds 	else
15591da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15601da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
15611da177e4SLinus Torvalds 	configApp->processEvents();
15621da177e4SLinus Torvalds 	menuList->mode = menuMode;
15631da177e4SLinus Torvalds 	menuList->setRootMenu(&rootmenu);
15641da177e4SLinus Torvalds 	menuList->setAllOpen(TRUE);
15651da177e4SLinus Torvalds 	menuView->show();
15661da177e4SLinus Torvalds 	menuList->setFocus();
15671da177e4SLinus Torvalds }
15681da177e4SLinus Torvalds 
15691da177e4SLinus Torvalds void ConfigMainWindow::showFullView(void)
15701da177e4SLinus Torvalds {
15711da177e4SLinus Torvalds 	menuView->hide();
15721da177e4SLinus Torvalds 	menuList->setRootMenu(0);
15731da177e4SLinus Torvalds 	configList->mode = fullMode;
15741da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15751da177e4SLinus Torvalds 		configList->updateListAll();
15761da177e4SLinus Torvalds 	else
15771da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15781da177e4SLinus Torvalds 	configList->setAllOpen(FALSE);
15791da177e4SLinus Torvalds 	configList->setFocus();
15801da177e4SLinus Torvalds }
15811da177e4SLinus Torvalds 
15821da177e4SLinus Torvalds /*
15831da177e4SLinus Torvalds  * ask for saving configuration before quitting
15841da177e4SLinus Torvalds  * TODO ask only when something changed
15851da177e4SLinus Torvalds  */
15861da177e4SLinus Torvalds void ConfigMainWindow::closeEvent(QCloseEvent* e)
15871da177e4SLinus Torvalds {
1588b3214293SKarsten Wiese 	if (!conf_get_changed()) {
15891da177e4SLinus Torvalds 		e->accept();
15901da177e4SLinus Torvalds 		return;
15911da177e4SLinus Torvalds 	}
15921da177e4SLinus Torvalds 	QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
15931da177e4SLinus Torvalds 			QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
15941da177e4SLinus Torvalds 	mb.setButtonText(QMessageBox::Yes, "&Save Changes");
15951da177e4SLinus Torvalds 	mb.setButtonText(QMessageBox::No, "&Discard Changes");
15961da177e4SLinus Torvalds 	mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
15971da177e4SLinus Torvalds 	switch (mb.exec()) {
15981da177e4SLinus Torvalds 	case QMessageBox::Yes:
15991da177e4SLinus Torvalds 		conf_write(NULL);
16001da177e4SLinus Torvalds 	case QMessageBox::No:
16011da177e4SLinus Torvalds 		e->accept();
16021da177e4SLinus Torvalds 		break;
16031da177e4SLinus Torvalds 	case QMessageBox::Cancel:
16041da177e4SLinus Torvalds 		e->ignore();
16051da177e4SLinus Torvalds 		break;
16061da177e4SLinus Torvalds 	}
16071da177e4SLinus Torvalds }
16081da177e4SLinus Torvalds 
16091da177e4SLinus Torvalds void ConfigMainWindow::showIntro(void)
16101da177e4SLinus Torvalds {
16111da177e4SLinus Torvalds 	static char str[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
16121da177e4SLinus Torvalds 		"For each option, a blank box indicates the feature is disabled, a check\n"
16131da177e4SLinus Torvalds 		"indicates it is enabled, and a dot indicates that it is to be compiled\n"
16141da177e4SLinus Torvalds 		"as a module.  Clicking on the box will cycle through the three states.\n\n"
16151da177e4SLinus Torvalds 		"If you do not see an option (e.g., a device driver) that you believe\n"
16161da177e4SLinus Torvalds 		"should be present, try turning on Show All Options under the Options menu.\n"
16171da177e4SLinus Torvalds 		"Although there is no cross reference yet to help you figure out what other\n"
16181da177e4SLinus Torvalds 		"options must be enabled to support the option you are interested in, you can\n"
16191da177e4SLinus Torvalds 		"still view the help of a grayed-out option.\n\n"
16201da177e4SLinus Torvalds 		"Toggling Show Debug Info under the Options menu will show the dependencies,\n"
16211da177e4SLinus Torvalds 		"which you can then match by examining other options.\n\n";
16221da177e4SLinus Torvalds 
16231da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16241da177e4SLinus Torvalds }
16251da177e4SLinus Torvalds 
16261da177e4SLinus Torvalds void ConfigMainWindow::showAbout(void)
16271da177e4SLinus Torvalds {
16281da177e4SLinus Torvalds 	static char str[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
16291da177e4SLinus Torvalds 		"Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
16301da177e4SLinus Torvalds 
16311da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16321da177e4SLinus Torvalds }
16331da177e4SLinus Torvalds 
16341da177e4SLinus Torvalds void ConfigMainWindow::saveSettings(void)
16351da177e4SLinus Torvalds {
16367fc925fdSRoman Zippel 	configSettings->writeEntry("/window x", pos().x());
16377fc925fdSRoman Zippel 	configSettings->writeEntry("/window y", pos().y());
16387fc925fdSRoman Zippel 	configSettings->writeEntry("/window width", size().width());
16397fc925fdSRoman Zippel 	configSettings->writeEntry("/window height", size().height());
16401da177e4SLinus Torvalds 
16411da177e4SLinus Torvalds 	QString entry;
16421da177e4SLinus Torvalds 	switch(configList->mode) {
16431da177e4SLinus Torvalds 	case singleMode :
16441da177e4SLinus Torvalds 		entry = "single";
16451da177e4SLinus Torvalds 		break;
16461da177e4SLinus Torvalds 
16471da177e4SLinus Torvalds 	case symbolMode :
16481da177e4SLinus Torvalds 		entry = "split";
16491da177e4SLinus Torvalds 		break;
16501da177e4SLinus Torvalds 
16511da177e4SLinus Torvalds 	case fullMode :
16521da177e4SLinus Torvalds 		entry = "full";
16531da177e4SLinus Torvalds 		break;
16541da177e4SLinus Torvalds 	}
16557fc925fdSRoman Zippel 	configSettings->writeEntry("/listMode", entry);
16561da177e4SLinus Torvalds 
16577fc925fdSRoman Zippel 	configSettings->writeSizes("/split1", split1->sizes());
16587fc925fdSRoman Zippel 	configSettings->writeSizes("/split2", split2->sizes());
16591da177e4SLinus Torvalds }
16601da177e4SLinus Torvalds 
16611da177e4SLinus Torvalds void fixup_rootmenu(struct menu *menu)
16621da177e4SLinus Torvalds {
16631da177e4SLinus Torvalds 	struct menu *child;
16641da177e4SLinus Torvalds 	static int menu_cnt = 0;
16651da177e4SLinus Torvalds 
16661da177e4SLinus Torvalds 	menu->flags |= MENU_ROOT;
16671da177e4SLinus Torvalds 	for (child = menu->list; child; child = child->next) {
16681da177e4SLinus Torvalds 		if (child->prompt && child->prompt->type == P_MENU) {
16691da177e4SLinus Torvalds 			menu_cnt++;
16701da177e4SLinus Torvalds 			fixup_rootmenu(child);
16711da177e4SLinus Torvalds 			menu_cnt--;
16721da177e4SLinus Torvalds 		} else if (!menu_cnt)
16731da177e4SLinus Torvalds 			fixup_rootmenu(child);
16741da177e4SLinus Torvalds 	}
16751da177e4SLinus Torvalds }
16761da177e4SLinus Torvalds 
16771da177e4SLinus Torvalds static const char *progname;
16781da177e4SLinus Torvalds 
16791da177e4SLinus Torvalds static void usage(void)
16801da177e4SLinus Torvalds {
16811da177e4SLinus Torvalds 	printf("%s <config>\n", progname);
16821da177e4SLinus Torvalds 	exit(0);
16831da177e4SLinus Torvalds }
16841da177e4SLinus Torvalds 
16851da177e4SLinus Torvalds int main(int ac, char** av)
16861da177e4SLinus Torvalds {
16871da177e4SLinus Torvalds 	ConfigMainWindow* v;
16881da177e4SLinus Torvalds 	const char *name;
16891da177e4SLinus Torvalds 
16903b9fa093SArnaldo Carvalho de Melo 	bindtextdomain(PACKAGE, LOCALEDIR);
16913b9fa093SArnaldo Carvalho de Melo 	textdomain(PACKAGE);
16923b9fa093SArnaldo Carvalho de Melo 
16931da177e4SLinus Torvalds #ifndef LKC_DIRECT_LINK
16941da177e4SLinus Torvalds 	kconfig_load();
16951da177e4SLinus Torvalds #endif
16961da177e4SLinus Torvalds 
16971da177e4SLinus Torvalds 	progname = av[0];
16981da177e4SLinus Torvalds 	configApp = new QApplication(ac, av);
16991da177e4SLinus Torvalds 	if (ac > 1 && av[1][0] == '-') {
17001da177e4SLinus Torvalds 		switch (av[1][1]) {
17011da177e4SLinus Torvalds 		case 'h':
17021da177e4SLinus Torvalds 		case '?':
17031da177e4SLinus Torvalds 			usage();
17041da177e4SLinus Torvalds 		}
17051da177e4SLinus Torvalds 		name = av[2];
17061da177e4SLinus Torvalds 	} else
17071da177e4SLinus Torvalds 		name = av[1];
17081da177e4SLinus Torvalds 	if (!name)
17091da177e4SLinus Torvalds 		usage();
17101da177e4SLinus Torvalds 
17111da177e4SLinus Torvalds 	conf_parse(name);
17121da177e4SLinus Torvalds 	fixup_rootmenu(&rootmenu);
17131da177e4SLinus Torvalds 	conf_read(NULL);
17141da177e4SLinus Torvalds 	//zconfdump(stdout);
17151da177e4SLinus Torvalds 
17167fc925fdSRoman Zippel 	configSettings = new ConfigSettings();
17177fc925fdSRoman Zippel 	configSettings->beginGroup("/kconfig/qconf");
17181da177e4SLinus Torvalds 	v = new ConfigMainWindow();
17191da177e4SLinus Torvalds 
17201da177e4SLinus Torvalds 	//zconfdump(stdout);
172143bf612aSRoman Zippel 	configApp->setMainWidget(v);
17221da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
17231da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
172443bf612aSRoman Zippel 	v->show();
17251da177e4SLinus Torvalds 	configApp->exec();
17261da177e4SLinus Torvalds 
17277fc925fdSRoman Zippel 	configSettings->endGroup();
17287fc925fdSRoman Zippel 	delete configSettings;
17297fc925fdSRoman Zippel 
17301da177e4SLinus Torvalds 	return 0;
17311da177e4SLinus Torvalds }
1732