xref: /openbmc/linux/scripts/kconfig/qconf.cc (revision 6fa1da8e)
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 
413b354c55SKarsten Wiese QAction *ConfigMainWindow::saveAction;
423b354c55SKarsten Wiese 
433b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const char* str)
443b9fa093SArnaldo Carvalho de Melo {
453b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str));
463b9fa093SArnaldo Carvalho de Melo }
473b9fa093SArnaldo Carvalho de Melo 
483b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const QString& str)
493b9fa093SArnaldo Carvalho de Melo {
503b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str.latin1()));
513b9fa093SArnaldo Carvalho de Melo }
523b9fa093SArnaldo Carvalho de Melo 
531da177e4SLinus Torvalds /**
541da177e4SLinus Torvalds  * Reads a list of integer values from the application settings.
551da177e4SLinus Torvalds  */
561da177e4SLinus Torvalds QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
571da177e4SLinus Torvalds {
581da177e4SLinus Torvalds 	QValueList<int> result;
591da177e4SLinus Torvalds 	QStringList entryList = readListEntry(key, ok);
601da177e4SLinus Torvalds 	if (ok) {
611da177e4SLinus Torvalds 		QStringList::Iterator it;
621da177e4SLinus Torvalds 		for (it = entryList.begin(); it != entryList.end(); ++it)
631da177e4SLinus Torvalds 			result.push_back((*it).toInt());
641da177e4SLinus Torvalds 	}
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds 	return result;
671da177e4SLinus Torvalds }
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds /**
701da177e4SLinus Torvalds  * Writes a list of integer values to the application settings.
711da177e4SLinus Torvalds  */
721da177e4SLinus Torvalds bool ConfigSettings::writeSizes(const QString& key, const QValueList<int>& value)
731da177e4SLinus Torvalds {
741da177e4SLinus Torvalds 	QStringList stringList;
751da177e4SLinus Torvalds 	QValueList<int>::ConstIterator it;
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds 	for (it = value.begin(); it != value.end(); ++it)
781da177e4SLinus Torvalds 		stringList.push_back(QString::number(*it));
791da177e4SLinus Torvalds 	return writeEntry(key, stringList);
801da177e4SLinus Torvalds }
811da177e4SLinus Torvalds 
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds #if QT_VERSION >= 300
841da177e4SLinus Torvalds /*
851da177e4SLinus Torvalds  * set the new data
861da177e4SLinus Torvalds  * TODO check the value
871da177e4SLinus Torvalds  */
881da177e4SLinus Torvalds void ConfigItem::okRename(int col)
891da177e4SLinus Torvalds {
901da177e4SLinus Torvalds 	Parent::okRename(col);
911da177e4SLinus Torvalds 	sym_set_string_value(menu->sym, text(dataColIdx).latin1());
921da177e4SLinus Torvalds }
931da177e4SLinus Torvalds #endif
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds /*
961da177e4SLinus Torvalds  * update the displayed of a menu entry
971da177e4SLinus Torvalds  */
981da177e4SLinus Torvalds void ConfigItem::updateMenu(void)
991da177e4SLinus Torvalds {
1001da177e4SLinus Torvalds 	ConfigList* list;
1011da177e4SLinus Torvalds 	struct symbol* sym;
1021da177e4SLinus Torvalds 	struct property *prop;
1031da177e4SLinus Torvalds 	QString prompt;
1041da177e4SLinus Torvalds 	int type;
1051da177e4SLinus Torvalds 	tristate expr;
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	list = listView();
1081da177e4SLinus Torvalds 	if (goParent) {
1091da177e4SLinus Torvalds 		setPixmap(promptColIdx, list->menuBackPix);
1101da177e4SLinus Torvalds 		prompt = "..";
1111da177e4SLinus Torvalds 		goto set_prompt;
1121da177e4SLinus Torvalds 	}
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds 	sym = menu->sym;
1151da177e4SLinus Torvalds 	prop = menu->prompt;
1163b9fa093SArnaldo Carvalho de Melo 	prompt = QString::fromLocal8Bit(menu_get_prompt(menu));
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds 	if (prop) switch (prop->type) {
1191da177e4SLinus Torvalds 	case P_MENU:
1201da177e4SLinus Torvalds 		if (list->mode == singleMode || list->mode == symbolMode) {
1211da177e4SLinus Torvalds 			/* a menuconfig entry is displayed differently
1221da177e4SLinus Torvalds 			 * depending whether it's at the view root or a child.
1231da177e4SLinus Torvalds 			 */
1241da177e4SLinus Torvalds 			if (sym && list->rootEntry == menu)
1251da177e4SLinus Torvalds 				break;
1261da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->menuPix);
1271da177e4SLinus Torvalds 		} else {
1281da177e4SLinus Torvalds 			if (sym)
1291da177e4SLinus Torvalds 				break;
1301da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1311da177e4SLinus Torvalds 		}
1321da177e4SLinus Torvalds 		goto set_prompt;
1331da177e4SLinus Torvalds 	case P_COMMENT:
1341da177e4SLinus Torvalds 		setPixmap(promptColIdx, 0);
1351da177e4SLinus Torvalds 		goto set_prompt;
1361da177e4SLinus Torvalds 	default:
1371da177e4SLinus Torvalds 		;
1381da177e4SLinus Torvalds 	}
1391da177e4SLinus Torvalds 	if (!sym)
1401da177e4SLinus Torvalds 		goto set_prompt;
1411da177e4SLinus Torvalds 
1423b9fa093SArnaldo Carvalho de Melo 	setText(nameColIdx, QString::fromLocal8Bit(sym->name));
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds 	type = sym_get_type(sym);
1451da177e4SLinus Torvalds 	switch (type) {
1461da177e4SLinus Torvalds 	case S_BOOLEAN:
1471da177e4SLinus Torvalds 	case S_TRISTATE:
1481da177e4SLinus Torvalds 		char ch;
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds 		if (!sym_is_changable(sym) && !list->showAll) {
1511da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1523b9fa093SArnaldo Carvalho de Melo 			setText(noColIdx, QString::null);
1533b9fa093SArnaldo Carvalho de Melo 			setText(modColIdx, QString::null);
1543b9fa093SArnaldo Carvalho de Melo 			setText(yesColIdx, QString::null);
1551da177e4SLinus Torvalds 			break;
1561da177e4SLinus Torvalds 		}
1571da177e4SLinus Torvalds 		expr = sym_get_tristate_value(sym);
1581da177e4SLinus Torvalds 		switch (expr) {
1591da177e4SLinus Torvalds 		case yes:
1601da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1611da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceYesPix);
1621da177e4SLinus Torvalds 			else
1631da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolYesPix);
1641da177e4SLinus Torvalds 			setText(yesColIdx, "Y");
1651da177e4SLinus Torvalds 			ch = 'Y';
1661da177e4SLinus Torvalds 			break;
1671da177e4SLinus Torvalds 		case mod:
1681da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->symbolModPix);
1691da177e4SLinus Torvalds 			setText(modColIdx, "M");
1701da177e4SLinus Torvalds 			ch = 'M';
1711da177e4SLinus Torvalds 			break;
1721da177e4SLinus Torvalds 		default:
1731da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1741da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceNoPix);
1751da177e4SLinus Torvalds 			else
1761da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolNoPix);
1771da177e4SLinus Torvalds 			setText(noColIdx, "N");
1781da177e4SLinus Torvalds 			ch = 'N';
1791da177e4SLinus Torvalds 			break;
1801da177e4SLinus Torvalds 		}
1811da177e4SLinus Torvalds 		if (expr != no)
1821da177e4SLinus Torvalds 			setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
1831da177e4SLinus Torvalds 		if (expr != mod)
1841da177e4SLinus Torvalds 			setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
1851da177e4SLinus Torvalds 		if (expr != yes)
1861da177e4SLinus Torvalds 			setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds 		setText(dataColIdx, QChar(ch));
1891da177e4SLinus Torvalds 		break;
1901da177e4SLinus Torvalds 	case S_INT:
1911da177e4SLinus Torvalds 	case S_HEX:
1921da177e4SLinus Torvalds 	case S_STRING:
1931da177e4SLinus Torvalds 		const char* data;
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds 		data = sym_get_string_value(sym);
1963b9fa093SArnaldo Carvalho de Melo 
1971da177e4SLinus Torvalds #if QT_VERSION >= 300
1981da177e4SLinus Torvalds 		int i = list->mapIdx(dataColIdx);
1991da177e4SLinus Torvalds 		if (i >= 0)
2001da177e4SLinus Torvalds 			setRenameEnabled(i, TRUE);
2011da177e4SLinus Torvalds #endif
2021da177e4SLinus Torvalds 		setText(dataColIdx, data);
2031da177e4SLinus Torvalds 		if (type == S_STRING)
2043b9fa093SArnaldo Carvalho de Melo 			prompt = QString("%1: %2").arg(prompt).arg(data);
2051da177e4SLinus Torvalds 		else
2063b9fa093SArnaldo Carvalho de Melo 			prompt = QString("(%2) %1").arg(prompt).arg(data);
2071da177e4SLinus Torvalds 		break;
2081da177e4SLinus Torvalds 	}
2091da177e4SLinus Torvalds 	if (!sym_has_value(sym) && visible)
2101da177e4SLinus Torvalds 		prompt += " (NEW)";
2111da177e4SLinus Torvalds set_prompt:
2121da177e4SLinus Torvalds 	setText(promptColIdx, prompt);
2131da177e4SLinus Torvalds }
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds void ConfigItem::testUpdateMenu(bool v)
2161da177e4SLinus Torvalds {
2171da177e4SLinus Torvalds 	ConfigItem* i;
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds 	visible = v;
2201da177e4SLinus Torvalds 	if (!menu)
2211da177e4SLinus Torvalds 		return;
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds 	sym_calc_value(menu->sym);
2241da177e4SLinus Torvalds 	if (menu->flags & MENU_CHANGED) {
2251da177e4SLinus Torvalds 		/* the menu entry changed, so update all list items */
2261da177e4SLinus Torvalds 		menu->flags &= ~MENU_CHANGED;
2271da177e4SLinus Torvalds 		for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
2281da177e4SLinus Torvalds 			i->updateMenu();
2291da177e4SLinus Torvalds 	} else if (listView()->updateAll)
2301da177e4SLinus Torvalds 		updateMenu();
2311da177e4SLinus Torvalds }
2321da177e4SLinus Torvalds 
2331da177e4SLinus Torvalds void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
2341da177e4SLinus Torvalds {
2351da177e4SLinus Torvalds 	ConfigList* list = listView();
2361da177e4SLinus Torvalds 
2371da177e4SLinus Torvalds 	if (visible) {
2381da177e4SLinus Torvalds 		if (isSelected() && !list->hasFocus() && list->mode == menuMode)
2391da177e4SLinus Torvalds 			Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
2401da177e4SLinus Torvalds 		else
2411da177e4SLinus Torvalds 			Parent::paintCell(p, cg, column, width, align);
2421da177e4SLinus Torvalds 	} else
2431da177e4SLinus Torvalds 		Parent::paintCell(p, list->disabledColorGroup, column, width, align);
2441da177e4SLinus Torvalds }
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds /*
2471da177e4SLinus Torvalds  * construct a menu entry
2481da177e4SLinus Torvalds  */
2491da177e4SLinus Torvalds void ConfigItem::init(void)
2501da177e4SLinus Torvalds {
2511da177e4SLinus Torvalds 	if (menu) {
2521da177e4SLinus Torvalds 		ConfigList* list = listView();
2531da177e4SLinus Torvalds 		nextItem = (ConfigItem*)menu->data;
2541da177e4SLinus Torvalds 		menu->data = this;
2551da177e4SLinus Torvalds 
2561da177e4SLinus Torvalds 		if (list->mode != fullMode)
2571da177e4SLinus Torvalds 			setOpen(TRUE);
2581da177e4SLinus Torvalds 		sym_calc_value(menu->sym);
2591da177e4SLinus Torvalds 	}
2601da177e4SLinus Torvalds 	updateMenu();
2611da177e4SLinus Torvalds }
2621da177e4SLinus Torvalds 
2631da177e4SLinus Torvalds /*
2641da177e4SLinus Torvalds  * destruct a menu entry
2651da177e4SLinus Torvalds  */
2661da177e4SLinus Torvalds ConfigItem::~ConfigItem(void)
2671da177e4SLinus Torvalds {
2681da177e4SLinus Torvalds 	if (menu) {
2691da177e4SLinus Torvalds 		ConfigItem** ip = (ConfigItem**)&menu->data;
2701da177e4SLinus Torvalds 		for (; *ip; ip = &(*ip)->nextItem) {
2711da177e4SLinus Torvalds 			if (*ip == this) {
2721da177e4SLinus Torvalds 				*ip = nextItem;
2731da177e4SLinus Torvalds 				break;
2741da177e4SLinus Torvalds 			}
2751da177e4SLinus Torvalds 		}
2761da177e4SLinus Torvalds 	}
2771da177e4SLinus Torvalds }
2781da177e4SLinus Torvalds 
27943bf612aSRoman Zippel ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
28043bf612aSRoman Zippel 	: Parent(parent)
28143bf612aSRoman Zippel {
28243bf612aSRoman Zippel 	connect(this, SIGNAL(lostFocus()), SLOT(hide()));
28343bf612aSRoman Zippel }
28443bf612aSRoman Zippel 
2851da177e4SLinus Torvalds void ConfigLineEdit::show(ConfigItem* i)
2861da177e4SLinus Torvalds {
2871da177e4SLinus Torvalds 	item = i;
2881da177e4SLinus Torvalds 	if (sym_get_string_value(item->menu->sym))
2893b9fa093SArnaldo Carvalho de Melo 		setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
2901da177e4SLinus Torvalds 	else
2913b9fa093SArnaldo Carvalho de Melo 		setText(QString::null);
2921da177e4SLinus Torvalds 	Parent::show();
2931da177e4SLinus Torvalds 	setFocus();
2941da177e4SLinus Torvalds }
2951da177e4SLinus Torvalds 
2961da177e4SLinus Torvalds void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
2971da177e4SLinus Torvalds {
2981da177e4SLinus Torvalds 	switch (e->key()) {
2991da177e4SLinus Torvalds 	case Key_Escape:
3001da177e4SLinus Torvalds 		break;
3011da177e4SLinus Torvalds 	case Key_Return:
3021da177e4SLinus Torvalds 	case Key_Enter:
3031da177e4SLinus Torvalds 		sym_set_string_value(item->menu->sym, text().latin1());
3041da177e4SLinus Torvalds 		parent()->updateList(item);
3051da177e4SLinus Torvalds 		break;
3061da177e4SLinus Torvalds 	default:
3071da177e4SLinus Torvalds 		Parent::keyPressEvent(e);
3081da177e4SLinus Torvalds 		return;
3091da177e4SLinus Torvalds 	}
3101da177e4SLinus Torvalds 	e->accept();
3111da177e4SLinus Torvalds 	parent()->list->setFocus();
3121da177e4SLinus Torvalds 	hide();
3131da177e4SLinus Torvalds }
3141da177e4SLinus Torvalds 
3157fc925fdSRoman Zippel ConfigList::ConfigList(ConfigView* p, const char *name)
3167fc925fdSRoman Zippel 	: Parent(p, name),
3171da177e4SLinus Torvalds 	  updateAll(false),
3181da177e4SLinus Torvalds 	  symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
3191da177e4SLinus Torvalds 	  choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
3201da177e4SLinus Torvalds 	  menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
3211da177e4SLinus Torvalds 	  showAll(false), showName(false), showRange(false), showData(false),
3227fc925fdSRoman Zippel 	  rootEntry(0), headerPopup(0)
3231da177e4SLinus Torvalds {
3241da177e4SLinus Torvalds 	int i;
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds 	setSorting(-1);
3271da177e4SLinus Torvalds 	setRootIsDecorated(TRUE);
3281da177e4SLinus Torvalds 	disabledColorGroup = palette().active();
3291da177e4SLinus Torvalds 	disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
3301da177e4SLinus Torvalds 	inactivedColorGroup = palette().active();
3311da177e4SLinus Torvalds 	inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds 	connect(this, SIGNAL(selectionChanged(void)),
3341da177e4SLinus Torvalds 		SLOT(updateSelection(void)));
3351da177e4SLinus Torvalds 
3367fc925fdSRoman Zippel 	if (name) {
3377fc925fdSRoman Zippel 		configSettings->beginGroup(name);
3387fc925fdSRoman Zippel 		showAll = configSettings->readBoolEntry("/showAll", false);
3397fc925fdSRoman Zippel 		showName = configSettings->readBoolEntry("/showName", false);
3407fc925fdSRoman Zippel 		showRange = configSettings->readBoolEntry("/showRange", false);
3417fc925fdSRoman Zippel 		showData = configSettings->readBoolEntry("/showData", false);
3427fc925fdSRoman Zippel 		configSettings->endGroup();
3437fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
3441da177e4SLinus Torvalds 	}
3451da177e4SLinus Torvalds 
3461da177e4SLinus Torvalds 	for (i = 0; i < colNr; i++)
3471da177e4SLinus Torvalds 		colMap[i] = colRevMap[i] = -1;
3481da177e4SLinus Torvalds 	addColumn(promptColIdx, "Option");
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds 	reinit();
3511da177e4SLinus Torvalds }
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds void ConfigList::reinit(void)
3541da177e4SLinus Torvalds {
3551da177e4SLinus Torvalds 	removeColumn(dataColIdx);
3561da177e4SLinus Torvalds 	removeColumn(yesColIdx);
3571da177e4SLinus Torvalds 	removeColumn(modColIdx);
3581da177e4SLinus Torvalds 	removeColumn(noColIdx);
3591da177e4SLinus Torvalds 	removeColumn(nameColIdx);
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds 	if (showName)
3621da177e4SLinus Torvalds 		addColumn(nameColIdx, "Name");
3631da177e4SLinus Torvalds 	if (showRange) {
3641da177e4SLinus Torvalds 		addColumn(noColIdx, "N");
3651da177e4SLinus Torvalds 		addColumn(modColIdx, "M");
3661da177e4SLinus Torvalds 		addColumn(yesColIdx, "Y");
3671da177e4SLinus Torvalds 	}
3681da177e4SLinus Torvalds 	if (showData)
3691da177e4SLinus Torvalds 		addColumn(dataColIdx, "Value");
3701da177e4SLinus Torvalds 
3711da177e4SLinus Torvalds 	updateListAll();
3721da177e4SLinus Torvalds }
3731da177e4SLinus Torvalds 
3747fc925fdSRoman Zippel void ConfigList::saveSettings(void)
3757fc925fdSRoman Zippel {
3767fc925fdSRoman Zippel 	if (name()) {
3777fc925fdSRoman Zippel 		configSettings->beginGroup(name());
3787fc925fdSRoman Zippel 		configSettings->writeEntry("/showName", showName);
3797fc925fdSRoman Zippel 		configSettings->writeEntry("/showRange", showRange);
3807fc925fdSRoman Zippel 		configSettings->writeEntry("/showData", showData);
3817fc925fdSRoman Zippel 		configSettings->writeEntry("/showAll", showAll);
3827fc925fdSRoman Zippel 		configSettings->endGroup();
3837fc925fdSRoman Zippel 	}
3847fc925fdSRoman Zippel }
3857fc925fdSRoman Zippel 
386b65a47e1SRoman Zippel ConfigItem* ConfigList::findConfigItem(struct menu *menu)
387b65a47e1SRoman Zippel {
388b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem*)menu->data;
389b65a47e1SRoman Zippel 
390b65a47e1SRoman Zippel 	for (; item; item = item->nextItem) {
391b65a47e1SRoman Zippel 		if (this == item->listView())
392b65a47e1SRoman Zippel 			break;
393b65a47e1SRoman Zippel 	}
394b65a47e1SRoman Zippel 
395b65a47e1SRoman Zippel 	return item;
396b65a47e1SRoman Zippel }
397b65a47e1SRoman Zippel 
3981da177e4SLinus Torvalds void ConfigList::updateSelection(void)
3991da177e4SLinus Torvalds {
4001da177e4SLinus Torvalds 	struct menu *menu;
4011da177e4SLinus Torvalds 	enum prop_type type;
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)selectedItem();
4041da177e4SLinus Torvalds 	if (!item)
4051da177e4SLinus Torvalds 		return;
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds 	menu = item->menu;
40843bf612aSRoman Zippel 	emit menuChanged(menu);
4091da177e4SLinus Torvalds 	if (!menu)
4101da177e4SLinus Torvalds 		return;
4111da177e4SLinus Torvalds 	type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
4121da177e4SLinus Torvalds 	if (mode == menuMode && type == P_MENU)
4131da177e4SLinus Torvalds 		emit menuSelected(menu);
4141da177e4SLinus Torvalds }
4151da177e4SLinus Torvalds 
4161da177e4SLinus Torvalds void ConfigList::updateList(ConfigItem* item)
4171da177e4SLinus Torvalds {
4181da177e4SLinus Torvalds 	ConfigItem* last = 0;
4191da177e4SLinus Torvalds 
42043bf612aSRoman Zippel 	if (!rootEntry) {
42143bf612aSRoman Zippel 		if (mode != listMode)
4221da177e4SLinus Torvalds 			goto update;
42343bf612aSRoman Zippel 		QListViewItemIterator it(this);
42443bf612aSRoman Zippel 		ConfigItem* item;
42543bf612aSRoman Zippel 
42643bf612aSRoman Zippel 		for (; it.current(); ++it) {
42743bf612aSRoman Zippel 			item = (ConfigItem*)it.current();
42843bf612aSRoman Zippel 			if (!item->menu)
42943bf612aSRoman Zippel 				continue;
43043bf612aSRoman Zippel 			item->testUpdateMenu(menu_is_visible(item->menu));
43143bf612aSRoman Zippel 		}
43243bf612aSRoman Zippel 		return;
43343bf612aSRoman Zippel 	}
4341da177e4SLinus Torvalds 
4351da177e4SLinus Torvalds 	if (rootEntry != &rootmenu && (mode == singleMode ||
4361da177e4SLinus Torvalds 	    (mode == symbolMode && rootEntry->parent != &rootmenu))) {
4371da177e4SLinus Torvalds 		item = firstChild();
4381da177e4SLinus Torvalds 		if (!item)
4391da177e4SLinus Torvalds 			item = new ConfigItem(this, 0, true);
4401da177e4SLinus Torvalds 		last = item;
4411da177e4SLinus Torvalds 	}
4421da177e4SLinus Torvalds 	if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
4431da177e4SLinus Torvalds 	    rootEntry->sym && rootEntry->prompt) {
4441da177e4SLinus Torvalds 		item = last ? last->nextSibling() : firstChild();
4451da177e4SLinus Torvalds 		if (!item)
4461da177e4SLinus Torvalds 			item = new ConfigItem(this, last, rootEntry, true);
4471da177e4SLinus Torvalds 		else
4481da177e4SLinus Torvalds 			item->testUpdateMenu(true);
4491da177e4SLinus Torvalds 
4501da177e4SLinus Torvalds 		updateMenuList(item, rootEntry);
4511da177e4SLinus Torvalds 		triggerUpdate();
4521da177e4SLinus Torvalds 		return;
4531da177e4SLinus Torvalds 	}
4541da177e4SLinus Torvalds update:
4551da177e4SLinus Torvalds 	updateMenuList(this, rootEntry);
4561da177e4SLinus Torvalds 	triggerUpdate();
4571da177e4SLinus Torvalds }
4581da177e4SLinus Torvalds 
4591da177e4SLinus Torvalds void ConfigList::setValue(ConfigItem* item, tristate val)
4601da177e4SLinus Torvalds {
4611da177e4SLinus Torvalds 	struct symbol* sym;
4621da177e4SLinus Torvalds 	int type;
4631da177e4SLinus Torvalds 	tristate oldval;
4641da177e4SLinus Torvalds 
4651da177e4SLinus Torvalds 	sym = item->menu ? item->menu->sym : 0;
4661da177e4SLinus Torvalds 	if (!sym)
4671da177e4SLinus Torvalds 		return;
4681da177e4SLinus Torvalds 
4691da177e4SLinus Torvalds 	type = sym_get_type(sym);
4701da177e4SLinus Torvalds 	switch (type) {
4711da177e4SLinus Torvalds 	case S_BOOLEAN:
4721da177e4SLinus Torvalds 	case S_TRISTATE:
4731da177e4SLinus Torvalds 		oldval = sym_get_tristate_value(sym);
4741da177e4SLinus Torvalds 
4751da177e4SLinus Torvalds 		if (!sym_set_tristate_value(sym, val))
4761da177e4SLinus Torvalds 			return;
4771da177e4SLinus Torvalds 		if (oldval == no && item->menu->list)
4781da177e4SLinus Torvalds 			item->setOpen(TRUE);
4791da177e4SLinus Torvalds 		parent()->updateList(item);
4801da177e4SLinus Torvalds 		break;
4811da177e4SLinus Torvalds 	}
4821da177e4SLinus Torvalds }
4831da177e4SLinus Torvalds 
4841da177e4SLinus Torvalds void ConfigList::changeValue(ConfigItem* item)
4851da177e4SLinus Torvalds {
4861da177e4SLinus Torvalds 	struct symbol* sym;
4871da177e4SLinus Torvalds 	struct menu* menu;
4881da177e4SLinus Torvalds 	int type, oldexpr, newexpr;
4891da177e4SLinus Torvalds 
4901da177e4SLinus Torvalds 	menu = item->menu;
4911da177e4SLinus Torvalds 	if (!menu)
4921da177e4SLinus Torvalds 		return;
4931da177e4SLinus Torvalds 	sym = menu->sym;
4941da177e4SLinus Torvalds 	if (!sym) {
4951da177e4SLinus Torvalds 		if (item->menu->list)
4961da177e4SLinus Torvalds 			item->setOpen(!item->isOpen());
4971da177e4SLinus Torvalds 		return;
4981da177e4SLinus Torvalds 	}
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 		oldexpr = sym_get_tristate_value(sym);
5051da177e4SLinus Torvalds 		newexpr = sym_toggle_tristate_value(sym);
5061da177e4SLinus Torvalds 		if (item->menu->list) {
5071da177e4SLinus Torvalds 			if (oldexpr == newexpr)
5081da177e4SLinus Torvalds 				item->setOpen(!item->isOpen());
5091da177e4SLinus Torvalds 			else if (oldexpr == no)
5101da177e4SLinus Torvalds 				item->setOpen(TRUE);
5111da177e4SLinus Torvalds 		}
5121da177e4SLinus Torvalds 		if (oldexpr != newexpr)
5131da177e4SLinus Torvalds 			parent()->updateList(item);
5141da177e4SLinus Torvalds 		break;
5151da177e4SLinus Torvalds 	case S_INT:
5161da177e4SLinus Torvalds 	case S_HEX:
5171da177e4SLinus Torvalds 	case S_STRING:
5181da177e4SLinus Torvalds #if QT_VERSION >= 300
5191da177e4SLinus Torvalds 		if (colMap[dataColIdx] >= 0)
5201da177e4SLinus Torvalds 			item->startRename(colMap[dataColIdx]);
5211da177e4SLinus Torvalds 		else
5221da177e4SLinus Torvalds #endif
5231da177e4SLinus Torvalds 			parent()->lineEdit->show(item);
5241da177e4SLinus Torvalds 		break;
5251da177e4SLinus Torvalds 	}
5261da177e4SLinus Torvalds }
5271da177e4SLinus Torvalds 
5281da177e4SLinus Torvalds void ConfigList::setRootMenu(struct menu *menu)
5291da177e4SLinus Torvalds {
5301da177e4SLinus Torvalds 	enum prop_type type;
5311da177e4SLinus Torvalds 
5321da177e4SLinus Torvalds 	if (rootEntry == menu)
5331da177e4SLinus Torvalds 		return;
5341da177e4SLinus Torvalds 	type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
5351da177e4SLinus Torvalds 	if (type != P_MENU)
5361da177e4SLinus Torvalds 		return;
5371da177e4SLinus Torvalds 	updateMenuList(this, 0);
5381da177e4SLinus Torvalds 	rootEntry = menu;
5391da177e4SLinus Torvalds 	updateListAll();
5401da177e4SLinus Torvalds 	setSelected(currentItem(), hasFocus());
541b65a47e1SRoman Zippel 	ensureItemVisible(currentItem());
5421da177e4SLinus Torvalds }
5431da177e4SLinus Torvalds 
5441da177e4SLinus Torvalds void ConfigList::setParentMenu(void)
5451da177e4SLinus Torvalds {
5461da177e4SLinus Torvalds 	ConfigItem* item;
5471da177e4SLinus Torvalds 	struct menu *oldroot;
5481da177e4SLinus Torvalds 
5491da177e4SLinus Torvalds 	oldroot = rootEntry;
5501da177e4SLinus Torvalds 	if (rootEntry == &rootmenu)
5511da177e4SLinus Torvalds 		return;
5521da177e4SLinus Torvalds 	setRootMenu(menu_get_parent_menu(rootEntry->parent));
5531da177e4SLinus Torvalds 
5541da177e4SLinus Torvalds 	QListViewItemIterator it(this);
5551da177e4SLinus Torvalds 	for (; (item = (ConfigItem*)it.current()); it++) {
5561da177e4SLinus Torvalds 		if (item->menu == oldroot) {
5571da177e4SLinus Torvalds 			setCurrentItem(item);
5581da177e4SLinus Torvalds 			ensureItemVisible(item);
5591da177e4SLinus Torvalds 			break;
5601da177e4SLinus Torvalds 		}
5611da177e4SLinus Torvalds 	}
5621da177e4SLinus Torvalds }
5631da177e4SLinus Torvalds 
5647fc925fdSRoman Zippel /*
5657fc925fdSRoman Zippel  * update all the children of a menu entry
5667fc925fdSRoman Zippel  *   removes/adds the entries from the parent widget as necessary
5677fc925fdSRoman Zippel  *
5687fc925fdSRoman Zippel  * parent: either the menu list widget or a menu entry widget
5697fc925fdSRoman Zippel  * menu: entry to be updated
5707fc925fdSRoman Zippel  */
5717fc925fdSRoman Zippel template <class P>
5727fc925fdSRoman Zippel void ConfigList::updateMenuList(P* parent, struct menu* menu)
5737fc925fdSRoman Zippel {
5747fc925fdSRoman Zippel 	struct menu* child;
5757fc925fdSRoman Zippel 	ConfigItem* item;
5767fc925fdSRoman Zippel 	ConfigItem* last;
5777fc925fdSRoman Zippel 	bool visible;
5787fc925fdSRoman Zippel 	enum prop_type type;
5797fc925fdSRoman Zippel 
5807fc925fdSRoman Zippel 	if (!menu) {
5817fc925fdSRoman Zippel 		while ((item = parent->firstChild()))
5827fc925fdSRoman Zippel 			delete item;
5837fc925fdSRoman Zippel 		return;
5847fc925fdSRoman Zippel 	}
5857fc925fdSRoman Zippel 
5867fc925fdSRoman Zippel 	last = parent->firstChild();
5877fc925fdSRoman Zippel 	if (last && !last->goParent)
5887fc925fdSRoman Zippel 		last = 0;
5897fc925fdSRoman Zippel 	for (child = menu->list; child; child = child->next) {
5907fc925fdSRoman Zippel 		item = last ? last->nextSibling() : parent->firstChild();
5917fc925fdSRoman Zippel 		type = child->prompt ? child->prompt->type : P_UNKNOWN;
5927fc925fdSRoman Zippel 
5937fc925fdSRoman Zippel 		switch (mode) {
5947fc925fdSRoman Zippel 		case menuMode:
5957fc925fdSRoman Zippel 			if (!(child->flags & MENU_ROOT))
5967fc925fdSRoman Zippel 				goto hide;
5977fc925fdSRoman Zippel 			break;
5987fc925fdSRoman Zippel 		case symbolMode:
5997fc925fdSRoman Zippel 			if (child->flags & MENU_ROOT)
6007fc925fdSRoman Zippel 				goto hide;
6017fc925fdSRoman Zippel 			break;
6027fc925fdSRoman Zippel 		default:
6037fc925fdSRoman Zippel 			break;
6047fc925fdSRoman Zippel 		}
6057fc925fdSRoman Zippel 
6067fc925fdSRoman Zippel 		visible = menu_is_visible(child);
6077fc925fdSRoman Zippel 		if (showAll || visible) {
6087fc925fdSRoman Zippel 			if (!item || item->menu != child)
6097fc925fdSRoman Zippel 				item = new ConfigItem(parent, last, child, visible);
6107fc925fdSRoman Zippel 			else
6117fc925fdSRoman Zippel 				item->testUpdateMenu(visible);
6127fc925fdSRoman Zippel 
6137fc925fdSRoman Zippel 			if (mode == fullMode || mode == menuMode || type != P_MENU)
6147fc925fdSRoman Zippel 				updateMenuList(item, child);
6157fc925fdSRoman Zippel 			else
6167fc925fdSRoman Zippel 				updateMenuList(item, 0);
6177fc925fdSRoman Zippel 			last = item;
6187fc925fdSRoman Zippel 			continue;
6197fc925fdSRoman Zippel 		}
6207fc925fdSRoman Zippel 	hide:
6217fc925fdSRoman Zippel 		if (item && item->menu == child) {
6227fc925fdSRoman Zippel 			last = parent->firstChild();
6237fc925fdSRoman Zippel 			if (last == item)
6247fc925fdSRoman Zippel 				last = 0;
6257fc925fdSRoman Zippel 			else while (last->nextSibling() != item)
6267fc925fdSRoman Zippel 				last = last->nextSibling();
6277fc925fdSRoman Zippel 			delete item;
6287fc925fdSRoman Zippel 		}
6297fc925fdSRoman Zippel 	}
6307fc925fdSRoman Zippel }
6317fc925fdSRoman Zippel 
6321da177e4SLinus Torvalds void ConfigList::keyPressEvent(QKeyEvent* ev)
6331da177e4SLinus Torvalds {
6341da177e4SLinus Torvalds 	QListViewItem* i = currentItem();
6351da177e4SLinus Torvalds 	ConfigItem* item;
6361da177e4SLinus Torvalds 	struct menu *menu;
6371da177e4SLinus Torvalds 	enum prop_type type;
6381da177e4SLinus Torvalds 
63943bf612aSRoman Zippel 	if (ev->key() == Key_Escape && mode != fullMode && mode != listMode) {
6401da177e4SLinus Torvalds 		emit parentSelected();
6411da177e4SLinus Torvalds 		ev->accept();
6421da177e4SLinus Torvalds 		return;
6431da177e4SLinus Torvalds 	}
6441da177e4SLinus Torvalds 
6451da177e4SLinus Torvalds 	if (!i) {
6461da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
6471da177e4SLinus Torvalds 		return;
6481da177e4SLinus Torvalds 	}
6491da177e4SLinus Torvalds 	item = (ConfigItem*)i;
6501da177e4SLinus Torvalds 
6511da177e4SLinus Torvalds 	switch (ev->key()) {
6521da177e4SLinus Torvalds 	case Key_Return:
6531da177e4SLinus Torvalds 	case Key_Enter:
6541da177e4SLinus Torvalds 		if (item->goParent) {
6551da177e4SLinus Torvalds 			emit parentSelected();
6561da177e4SLinus Torvalds 			break;
6571da177e4SLinus Torvalds 		}
6581da177e4SLinus Torvalds 		menu = item->menu;
6591da177e4SLinus Torvalds 		if (!menu)
6601da177e4SLinus Torvalds 			break;
6611da177e4SLinus Torvalds 		type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
6621da177e4SLinus Torvalds 		if (type == P_MENU && rootEntry != menu &&
6631da177e4SLinus Torvalds 		    mode != fullMode && mode != menuMode) {
6641da177e4SLinus Torvalds 			emit menuSelected(menu);
6651da177e4SLinus Torvalds 			break;
6661da177e4SLinus Torvalds 		}
6671da177e4SLinus Torvalds 	case Key_Space:
6681da177e4SLinus Torvalds 		changeValue(item);
6691da177e4SLinus Torvalds 		break;
6701da177e4SLinus Torvalds 	case Key_N:
6711da177e4SLinus Torvalds 		setValue(item, no);
6721da177e4SLinus Torvalds 		break;
6731da177e4SLinus Torvalds 	case Key_M:
6741da177e4SLinus Torvalds 		setValue(item, mod);
6751da177e4SLinus Torvalds 		break;
6761da177e4SLinus Torvalds 	case Key_Y:
6771da177e4SLinus Torvalds 		setValue(item, yes);
6781da177e4SLinus Torvalds 		break;
6791da177e4SLinus Torvalds 	default:
6801da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
6811da177e4SLinus Torvalds 		return;
6821da177e4SLinus Torvalds 	}
6831da177e4SLinus Torvalds 	ev->accept();
6841da177e4SLinus Torvalds }
6851da177e4SLinus Torvalds 
6861da177e4SLinus Torvalds void ConfigList::contentsMousePressEvent(QMouseEvent* e)
6871da177e4SLinus Torvalds {
6881da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
6891da177e4SLinus Torvalds 	//printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
6901da177e4SLinus Torvalds 	Parent::contentsMousePressEvent(e);
6911da177e4SLinus Torvalds }
6921da177e4SLinus Torvalds 
6931da177e4SLinus Torvalds void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
6941da177e4SLinus Torvalds {
6951da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
6961da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
6971da177e4SLinus Torvalds 	struct menu *menu;
6981da177e4SLinus Torvalds 	enum prop_type ptype;
6991da177e4SLinus Torvalds 	const QPixmap* pm;
7001da177e4SLinus Torvalds 	int idx, x;
7011da177e4SLinus Torvalds 
7021da177e4SLinus Torvalds 	if (!item)
7031da177e4SLinus Torvalds 		goto skip;
7041da177e4SLinus Torvalds 
7051da177e4SLinus Torvalds 	menu = item->menu;
7061da177e4SLinus Torvalds 	x = header()->offset() + p.x();
7071da177e4SLinus Torvalds 	idx = colRevMap[header()->sectionAt(x)];
7081da177e4SLinus Torvalds 	switch (idx) {
7091da177e4SLinus Torvalds 	case promptColIdx:
7101da177e4SLinus Torvalds 		pm = item->pixmap(promptColIdx);
7111da177e4SLinus Torvalds 		if (pm) {
7121da177e4SLinus Torvalds 			int off = header()->sectionPos(0) + itemMargin() +
7131da177e4SLinus Torvalds 				treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
7141da177e4SLinus Torvalds 			if (x >= off && x < off + pm->width()) {
7151da177e4SLinus Torvalds 				if (item->goParent) {
7161da177e4SLinus Torvalds 					emit parentSelected();
7171da177e4SLinus Torvalds 					break;
7181da177e4SLinus Torvalds 				} else if (!menu)
7191da177e4SLinus Torvalds 					break;
7201da177e4SLinus Torvalds 				ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7211da177e4SLinus Torvalds 				if (ptype == P_MENU && rootEntry != menu &&
7221da177e4SLinus Torvalds 				    mode != fullMode && mode != menuMode)
7231da177e4SLinus Torvalds 					emit menuSelected(menu);
7241da177e4SLinus Torvalds 				else
7251da177e4SLinus Torvalds 					changeValue(item);
7261da177e4SLinus Torvalds 			}
7271da177e4SLinus Torvalds 		}
7281da177e4SLinus Torvalds 		break;
7291da177e4SLinus Torvalds 	case noColIdx:
7301da177e4SLinus Torvalds 		setValue(item, no);
7311da177e4SLinus Torvalds 		break;
7321da177e4SLinus Torvalds 	case modColIdx:
7331da177e4SLinus Torvalds 		setValue(item, mod);
7341da177e4SLinus Torvalds 		break;
7351da177e4SLinus Torvalds 	case yesColIdx:
7361da177e4SLinus Torvalds 		setValue(item, yes);
7371da177e4SLinus Torvalds 		break;
7381da177e4SLinus Torvalds 	case dataColIdx:
7391da177e4SLinus Torvalds 		changeValue(item);
7401da177e4SLinus Torvalds 		break;
7411da177e4SLinus Torvalds 	}
7421da177e4SLinus Torvalds 
7431da177e4SLinus Torvalds skip:
7441da177e4SLinus Torvalds 	//printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
7451da177e4SLinus Torvalds 	Parent::contentsMouseReleaseEvent(e);
7461da177e4SLinus Torvalds }
7471da177e4SLinus Torvalds 
7481da177e4SLinus Torvalds void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
7491da177e4SLinus Torvalds {
7501da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
7511da177e4SLinus Torvalds 	//printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
7521da177e4SLinus Torvalds 	Parent::contentsMouseMoveEvent(e);
7531da177e4SLinus Torvalds }
7541da177e4SLinus Torvalds 
7551da177e4SLinus Torvalds void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
7561da177e4SLinus Torvalds {
7571da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
7581da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
7591da177e4SLinus Torvalds 	struct menu *menu;
7601da177e4SLinus Torvalds 	enum prop_type ptype;
7611da177e4SLinus Torvalds 
7621da177e4SLinus Torvalds 	if (!item)
7631da177e4SLinus Torvalds 		goto skip;
7641da177e4SLinus Torvalds 	if (item->goParent) {
7651da177e4SLinus Torvalds 		emit parentSelected();
7661da177e4SLinus Torvalds 		goto skip;
7671da177e4SLinus Torvalds 	}
7681da177e4SLinus Torvalds 	menu = item->menu;
7691da177e4SLinus Torvalds 	if (!menu)
7701da177e4SLinus Torvalds 		goto skip;
7711da177e4SLinus Torvalds 	ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7721da177e4SLinus Torvalds 	if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
7731da177e4SLinus Torvalds 		emit menuSelected(menu);
7741da177e4SLinus Torvalds 	else if (menu->sym)
7751da177e4SLinus Torvalds 		changeValue(item);
7761da177e4SLinus Torvalds 
7771da177e4SLinus Torvalds skip:
7781da177e4SLinus Torvalds 	//printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
7791da177e4SLinus Torvalds 	Parent::contentsMouseDoubleClickEvent(e);
7801da177e4SLinus Torvalds }
7811da177e4SLinus Torvalds 
7821da177e4SLinus Torvalds void ConfigList::focusInEvent(QFocusEvent *e)
7831da177e4SLinus Torvalds {
784b65a47e1SRoman Zippel 	struct menu *menu = NULL;
785b65a47e1SRoman Zippel 
7861da177e4SLinus Torvalds 	Parent::focusInEvent(e);
7871da177e4SLinus Torvalds 
788b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem *)currentItem();
789b65a47e1SRoman Zippel 	if (item) {
7901da177e4SLinus Torvalds 		setSelected(item, TRUE);
791b65a47e1SRoman Zippel 		menu = item->menu;
792b65a47e1SRoman Zippel 	}
793b65a47e1SRoman Zippel 	emit gotFocus(menu);
7941da177e4SLinus Torvalds }
7951da177e4SLinus Torvalds 
7967fc925fdSRoman Zippel void ConfigList::contextMenuEvent(QContextMenuEvent *e)
7977fc925fdSRoman Zippel {
7987fc925fdSRoman Zippel 	if (e->y() <= header()->geometry().bottom()) {
7997fc925fdSRoman Zippel 		if (!headerPopup) {
8007fc925fdSRoman Zippel 			QAction *action;
8017fc925fdSRoman Zippel 
8027fc925fdSRoman Zippel 			headerPopup = new QPopupMenu(this);
80344ddc4f5Sakpm@osdl.org 			action = new QAction(NULL, "Show Name", 0, this);
8047fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8057fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8067fc925fdSRoman Zippel 				  parent(), SLOT(setShowName(bool)));
8077fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showNameChanged(bool)),
8087fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8097fc925fdSRoman Zippel 			  action->setOn(showName);
8107fc925fdSRoman Zippel 			  action->addTo(headerPopup);
81144ddc4f5Sakpm@osdl.org 			action = new QAction(NULL, "Show Range", 0, this);
8127fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8137fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8147fc925fdSRoman Zippel 				  parent(), SLOT(setShowRange(bool)));
8157fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showRangeChanged(bool)),
8167fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8177fc925fdSRoman Zippel 			  action->setOn(showRange);
8187fc925fdSRoman Zippel 			  action->addTo(headerPopup);
81944ddc4f5Sakpm@osdl.org 			action = new QAction(NULL, "Show Data", 0, this);
8207fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8217fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8227fc925fdSRoman Zippel 				  parent(), SLOT(setShowData(bool)));
8237fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showDataChanged(bool)),
8247fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8257fc925fdSRoman Zippel 			  action->setOn(showData);
8267fc925fdSRoman Zippel 			  action->addTo(headerPopup);
8277fc925fdSRoman Zippel 		}
8287fc925fdSRoman Zippel 		headerPopup->exec(e->globalPos());
8297fc925fdSRoman Zippel 		e->accept();
8307fc925fdSRoman Zippel 	} else
8317fc925fdSRoman Zippel 		e->ignore();
8327fc925fdSRoman Zippel }
8337fc925fdSRoman Zippel 
8341da177e4SLinus Torvalds ConfigView* ConfigView::viewList;
8351da177e4SLinus Torvalds 
8367fc925fdSRoman Zippel ConfigView::ConfigView(QWidget* parent, const char *name)
8377fc925fdSRoman Zippel 	: Parent(parent, name)
8381da177e4SLinus Torvalds {
8397fc925fdSRoman Zippel 	list = new ConfigList(this, name);
8401da177e4SLinus Torvalds 	lineEdit = new ConfigLineEdit(this);
8411da177e4SLinus Torvalds 	lineEdit->hide();
8421da177e4SLinus Torvalds 
8431da177e4SLinus Torvalds 	this->nextView = viewList;
8441da177e4SLinus Torvalds 	viewList = this;
8451da177e4SLinus Torvalds }
8461da177e4SLinus Torvalds 
8471da177e4SLinus Torvalds ConfigView::~ConfigView(void)
8481da177e4SLinus Torvalds {
8491da177e4SLinus Torvalds 	ConfigView** vp;
8501da177e4SLinus Torvalds 
8511da177e4SLinus Torvalds 	for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
8521da177e4SLinus Torvalds 		if (*vp == this) {
8531da177e4SLinus Torvalds 			*vp = nextView;
8541da177e4SLinus Torvalds 			break;
8551da177e4SLinus Torvalds 		}
8561da177e4SLinus Torvalds 	}
8571da177e4SLinus Torvalds }
8581da177e4SLinus Torvalds 
8597fc925fdSRoman Zippel void ConfigView::setShowAll(bool b)
8607fc925fdSRoman Zippel {
8617fc925fdSRoman Zippel 	if (list->showAll != b) {
8627fc925fdSRoman Zippel 		list->showAll = b;
8637fc925fdSRoman Zippel 		list->updateListAll();
8647fc925fdSRoman Zippel 		emit showAllChanged(b);
8657fc925fdSRoman Zippel 	}
8667fc925fdSRoman Zippel }
8677fc925fdSRoman Zippel 
8687fc925fdSRoman Zippel void ConfigView::setShowName(bool b)
8697fc925fdSRoman Zippel {
8707fc925fdSRoman Zippel 	if (list->showName != b) {
8717fc925fdSRoman Zippel 		list->showName = b;
8727fc925fdSRoman Zippel 		list->reinit();
8737fc925fdSRoman Zippel 		emit showNameChanged(b);
8747fc925fdSRoman Zippel 	}
8757fc925fdSRoman Zippel }
8767fc925fdSRoman Zippel 
8777fc925fdSRoman Zippel void ConfigView::setShowRange(bool b)
8787fc925fdSRoman Zippel {
8797fc925fdSRoman Zippel 	if (list->showRange != b) {
8807fc925fdSRoman Zippel 		list->showRange = b;
8817fc925fdSRoman Zippel 		list->reinit();
8827fc925fdSRoman Zippel 		emit showRangeChanged(b);
8837fc925fdSRoman Zippel 	}
8847fc925fdSRoman Zippel }
8857fc925fdSRoman Zippel 
8867fc925fdSRoman Zippel void ConfigView::setShowData(bool b)
8877fc925fdSRoman Zippel {
8887fc925fdSRoman Zippel 	if (list->showData != b) {
8897fc925fdSRoman Zippel 		list->showData = b;
8907fc925fdSRoman Zippel 		list->reinit();
8917fc925fdSRoman Zippel 		emit showDataChanged(b);
8927fc925fdSRoman Zippel 	}
8937fc925fdSRoman Zippel }
8947fc925fdSRoman Zippel 
8957fc925fdSRoman Zippel void ConfigList::setAllOpen(bool open)
8967fc925fdSRoman Zippel {
8977fc925fdSRoman Zippel 	QListViewItemIterator it(this);
8987fc925fdSRoman Zippel 
8997fc925fdSRoman Zippel 	for (; it.current(); it++)
9007fc925fdSRoman Zippel 		it.current()->setOpen(open);
9017fc925fdSRoman Zippel }
9027fc925fdSRoman Zippel 
9031da177e4SLinus Torvalds void ConfigView::updateList(ConfigItem* item)
9041da177e4SLinus Torvalds {
9051da177e4SLinus Torvalds 	ConfigView* v;
9061da177e4SLinus Torvalds 
9071da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9081da177e4SLinus Torvalds 		v->list->updateList(item);
9091da177e4SLinus Torvalds }
9101da177e4SLinus Torvalds 
9111da177e4SLinus Torvalds void ConfigView::updateListAll(void)
9121da177e4SLinus Torvalds {
9131da177e4SLinus Torvalds 	ConfigView* v;
9141da177e4SLinus Torvalds 
9151da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9161da177e4SLinus Torvalds 		v->list->updateListAll();
9171da177e4SLinus Torvalds }
9181da177e4SLinus Torvalds 
91943bf612aSRoman Zippel ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
9206fa1da8eSRoman Zippel 	: Parent(parent, name), menu(0), sym(0)
9211da177e4SLinus Torvalds {
9227fc925fdSRoman Zippel 	if (name) {
9237fc925fdSRoman Zippel 		configSettings->beginGroup(name);
9247fc925fdSRoman Zippel 		_showDebug = configSettings->readBoolEntry("/showDebug", false);
9257fc925fdSRoman Zippel 		configSettings->endGroup();
9267fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
9277fc925fdSRoman Zippel 	}
9287fc925fdSRoman Zippel }
9297fc925fdSRoman Zippel 
9307fc925fdSRoman Zippel void ConfigInfoView::saveSettings(void)
9317fc925fdSRoman Zippel {
9327fc925fdSRoman Zippel 	if (name()) {
9337fc925fdSRoman Zippel 		configSettings->beginGroup(name());
9347fc925fdSRoman Zippel 		configSettings->writeEntry("/showDebug", showDebug());
9357fc925fdSRoman Zippel 		configSettings->endGroup();
9367fc925fdSRoman Zippel 	}
9371da177e4SLinus Torvalds }
9381da177e4SLinus Torvalds 
93943bf612aSRoman Zippel void ConfigInfoView::setShowDebug(bool b)
9401da177e4SLinus Torvalds {
94143bf612aSRoman Zippel 	if (_showDebug != b) {
94243bf612aSRoman Zippel 		_showDebug = b;
94343bf612aSRoman Zippel 		if (menu)
94443bf612aSRoman Zippel 			menuInfo();
945ab45d190SRoman Zippel 		else if (sym)
946ab45d190SRoman Zippel 			symbolInfo();
94743bf612aSRoman Zippel 		emit showDebugChanged(b);
9481da177e4SLinus Torvalds 	}
9491da177e4SLinus Torvalds }
9501da177e4SLinus Torvalds 
95143bf612aSRoman Zippel void ConfigInfoView::setInfo(struct menu *m)
9521da177e4SLinus Torvalds {
953b65a47e1SRoman Zippel 	if (menu == m)
954b65a47e1SRoman Zippel 		return;
95543bf612aSRoman Zippel 	menu = m;
9566fa1da8eSRoman Zippel 	sym = NULL;
9576fa1da8eSRoman Zippel 	if (!menu)
95843bf612aSRoman Zippel 		clear();
9596fa1da8eSRoman Zippel 	else
96043bf612aSRoman Zippel 		menuInfo();
9611da177e4SLinus Torvalds }
9621da177e4SLinus Torvalds 
96343bf612aSRoman Zippel void ConfigInfoView::setSource(const QString& name)
96443bf612aSRoman Zippel {
96543bf612aSRoman Zippel 	const char *p = name.latin1();
96643bf612aSRoman Zippel 
96743bf612aSRoman Zippel 	menu = NULL;
968ab45d190SRoman Zippel 	sym = NULL;
96943bf612aSRoman Zippel 
97043bf612aSRoman Zippel 	switch (p[0]) {
97143bf612aSRoman Zippel 	case 'm':
972ab45d190SRoman Zippel 		struct menu *m;
973ab45d190SRoman Zippel 
974ab45d190SRoman Zippel 		if (sscanf(p, "m%p", &m) == 1 && menu != m) {
975ab45d190SRoman Zippel 			menu = m;
97643bf612aSRoman Zippel 			menuInfo();
977b65a47e1SRoman Zippel 			emit menuSelected(menu);
978ab45d190SRoman Zippel 		}
979ab45d190SRoman Zippel 		break;
980ab45d190SRoman Zippel 	case 's':
981ab45d190SRoman Zippel 		struct symbol *s;
982ab45d190SRoman Zippel 
983ab45d190SRoman Zippel 		if (sscanf(p, "s%p", &s) == 1 && sym != s) {
984ab45d190SRoman Zippel 			sym = s;
985ab45d190SRoman Zippel 			symbolInfo();
986ab45d190SRoman Zippel 		}
98743bf612aSRoman Zippel 		break;
98843bf612aSRoman Zippel 	}
98943bf612aSRoman Zippel }
99043bf612aSRoman Zippel 
991ab45d190SRoman Zippel void ConfigInfoView::symbolInfo(void)
992ab45d190SRoman Zippel {
993ab45d190SRoman Zippel 	QString str;
994ab45d190SRoman Zippel 
995ab45d190SRoman Zippel 	str += "<big>Symbol: <b>";
996ab45d190SRoman Zippel 	str += print_filter(sym->name);
997ab45d190SRoman Zippel 	str += "</b></big><br><br>value: ";
998ab45d190SRoman Zippel 	str += print_filter(sym_get_string_value(sym));
999ab45d190SRoman Zippel 	str += "<br>visibility: ";
1000ab45d190SRoman Zippel 	str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1001ab45d190SRoman Zippel 	str += "<br>";
1002ab45d190SRoman Zippel 	str += debug_info(sym);
1003ab45d190SRoman Zippel 
1004ab45d190SRoman Zippel 	setText(str);
1005ab45d190SRoman Zippel }
1006ab45d190SRoman Zippel 
100743bf612aSRoman Zippel void ConfigInfoView::menuInfo(void)
10081da177e4SLinus Torvalds {
10091da177e4SLinus Torvalds 	struct symbol* sym;
10101da177e4SLinus Torvalds 	QString head, debug, help;
101143bf612aSRoman Zippel 
10121da177e4SLinus Torvalds 	sym = menu->sym;
10131da177e4SLinus Torvalds 	if (sym) {
10141da177e4SLinus Torvalds 		if (menu->prompt) {
10151da177e4SLinus Torvalds 			head += "<big><b>";
10163b9fa093SArnaldo Carvalho de Melo 			head += print_filter(_(menu->prompt->text));
10171da177e4SLinus Torvalds 			head += "</b></big>";
10181da177e4SLinus Torvalds 			if (sym->name) {
10191da177e4SLinus Torvalds 				head += " (";
1020ab45d190SRoman Zippel 				if (showDebug())
1021ab45d190SRoman Zippel 					head += QString().sprintf("<a href=\"s%p\">", sym);
102243bf612aSRoman Zippel 				head += print_filter(sym->name);
1023ab45d190SRoman Zippel 				if (showDebug())
1024ab45d190SRoman Zippel 					head += "</a>";
10251da177e4SLinus Torvalds 				head += ")";
10261da177e4SLinus Torvalds 			}
10271da177e4SLinus Torvalds 		} else if (sym->name) {
10281da177e4SLinus Torvalds 			head += "<big><b>";
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 += "</b></big>";
10351da177e4SLinus Torvalds 		}
10361da177e4SLinus Torvalds 		head += "<br><br>";
10371da177e4SLinus Torvalds 
103843bf612aSRoman Zippel 		if (showDebug())
103943bf612aSRoman Zippel 			debug = debug_info(sym);
104043bf612aSRoman Zippel 
104143bf612aSRoman Zippel 		help = print_filter(_(sym->help));
104243bf612aSRoman Zippel 	} else if (menu->prompt) {
104343bf612aSRoman Zippel 		head += "<big><b>";
104443bf612aSRoman Zippel 		head += print_filter(_(menu->prompt->text));
104543bf612aSRoman Zippel 		head += "</b></big><br><br>";
104643bf612aSRoman Zippel 		if (showDebug()) {
104743bf612aSRoman Zippel 			if (menu->prompt->visible.expr) {
104843bf612aSRoman Zippel 				debug += "&nbsp;&nbsp;dep: ";
104943bf612aSRoman Zippel 				expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
105043bf612aSRoman Zippel 				debug += "<br><br>";
105143bf612aSRoman Zippel 			}
105243bf612aSRoman Zippel 		}
105343bf612aSRoman Zippel 	}
105443bf612aSRoman Zippel 	if (showDebug())
105543bf612aSRoman Zippel 		debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno);
105643bf612aSRoman Zippel 
105743bf612aSRoman Zippel 	setText(head + debug + help);
105843bf612aSRoman Zippel }
105943bf612aSRoman Zippel 
106043bf612aSRoman Zippel QString ConfigInfoView::debug_info(struct symbol *sym)
106143bf612aSRoman Zippel {
106243bf612aSRoman Zippel 	QString debug;
106343bf612aSRoman Zippel 
10641da177e4SLinus Torvalds 	debug += "type: ";
10651da177e4SLinus Torvalds 	debug += print_filter(sym_type_name(sym->type));
10661da177e4SLinus Torvalds 	if (sym_is_choice(sym))
10671da177e4SLinus Torvalds 		debug += " (choice)";
10681da177e4SLinus Torvalds 	debug += "<br>";
10691da177e4SLinus Torvalds 	if (sym->rev_dep.expr) {
10701da177e4SLinus Torvalds 		debug += "reverse dep: ";
10711da177e4SLinus Torvalds 		expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
10721da177e4SLinus Torvalds 		debug += "<br>";
10731da177e4SLinus Torvalds 	}
10741da177e4SLinus Torvalds 	for (struct property *prop = sym->prop; prop; prop = prop->next) {
10751da177e4SLinus Torvalds 		switch (prop->type) {
10761da177e4SLinus Torvalds 		case P_PROMPT:
10771da177e4SLinus Torvalds 		case P_MENU:
1078ab45d190SRoman Zippel 			debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
10793b9fa093SArnaldo Carvalho de Melo 			debug += print_filter(_(prop->text));
1080ab45d190SRoman Zippel 			debug += "</a><br>";
10811da177e4SLinus Torvalds 			break;
10821da177e4SLinus Torvalds 		case P_DEFAULT:
10831da177e4SLinus Torvalds 			debug += "default: ";
10841da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10851da177e4SLinus Torvalds 			debug += "<br>";
10861da177e4SLinus Torvalds 			break;
10871da177e4SLinus Torvalds 		case P_CHOICE:
10881da177e4SLinus Torvalds 			if (sym_is_choice(sym)) {
10891da177e4SLinus Torvalds 				debug += "choice: ";
10901da177e4SLinus Torvalds 				expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10911da177e4SLinus Torvalds 				debug += "<br>";
10921da177e4SLinus Torvalds 			}
10931da177e4SLinus Torvalds 			break;
10941da177e4SLinus Torvalds 		case P_SELECT:
10951da177e4SLinus Torvalds 			debug += "select: ";
10961da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10971da177e4SLinus Torvalds 			debug += "<br>";
10981da177e4SLinus Torvalds 			break;
10991da177e4SLinus Torvalds 		case P_RANGE:
11001da177e4SLinus Torvalds 			debug += "range: ";
11011da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
11021da177e4SLinus Torvalds 			debug += "<br>";
11031da177e4SLinus Torvalds 			break;
11041da177e4SLinus Torvalds 		default:
11051da177e4SLinus Torvalds 			debug += "unknown property: ";
11061da177e4SLinus Torvalds 			debug += prop_get_type_name(prop->type);
11071da177e4SLinus Torvalds 			debug += "<br>";
11081da177e4SLinus Torvalds 		}
11091da177e4SLinus Torvalds 		if (prop->visible.expr) {
11101da177e4SLinus Torvalds 			debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
11111da177e4SLinus Torvalds 			expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
11121da177e4SLinus Torvalds 			debug += "<br>";
11131da177e4SLinus Torvalds 		}
11141da177e4SLinus Torvalds 	}
11151da177e4SLinus Torvalds 	debug += "<br>";
111643bf612aSRoman Zippel 
111743bf612aSRoman Zippel 	return debug;
11181da177e4SLinus Torvalds }
11191da177e4SLinus Torvalds 
112043bf612aSRoman Zippel QString ConfigInfoView::print_filter(const QString &str)
112143bf612aSRoman Zippel {
112243bf612aSRoman Zippel 	QRegExp re("[<>&\"\\n]");
112343bf612aSRoman Zippel 	QString res = str;
112443bf612aSRoman Zippel 	for (int i = 0; (i = res.find(re, i)) >= 0;) {
112543bf612aSRoman Zippel 		switch (res[i].latin1()) {
112643bf612aSRoman Zippel 		case '<':
112743bf612aSRoman Zippel 			res.replace(i, 1, "&lt;");
112843bf612aSRoman Zippel 			i += 4;
112943bf612aSRoman Zippel 			break;
113043bf612aSRoman Zippel 		case '>':
113143bf612aSRoman Zippel 			res.replace(i, 1, "&gt;");
113243bf612aSRoman Zippel 			i += 4;
113343bf612aSRoman Zippel 			break;
113443bf612aSRoman Zippel 		case '&':
113543bf612aSRoman Zippel 			res.replace(i, 1, "&amp;");
113643bf612aSRoman Zippel 			i += 5;
113743bf612aSRoman Zippel 			break;
113843bf612aSRoman Zippel 		case '"':
113943bf612aSRoman Zippel 			res.replace(i, 1, "&quot;");
114043bf612aSRoman Zippel 			i += 6;
114143bf612aSRoman Zippel 			break;
114243bf612aSRoman Zippel 		case '\n':
114343bf612aSRoman Zippel 			res.replace(i, 1, "<br>");
114443bf612aSRoman Zippel 			i += 4;
114543bf612aSRoman Zippel 			break;
11461da177e4SLinus Torvalds 		}
11471da177e4SLinus Torvalds 	}
114843bf612aSRoman Zippel 	return res;
11491da177e4SLinus Torvalds }
115043bf612aSRoman Zippel 
1151ab45d190SRoman Zippel void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
115243bf612aSRoman Zippel {
1153ab45d190SRoman Zippel 	QString* text = reinterpret_cast<QString*>(data);
1154ab45d190SRoman Zippel 	QString str2 = print_filter(str);
1155ab45d190SRoman Zippel 
1156ab45d190SRoman Zippel 	if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1157ab45d190SRoman Zippel 		*text += QString().sprintf("<a href=\"s%p\">", sym);
1158ab45d190SRoman Zippel 		*text += str2;
1159ab45d190SRoman Zippel 		*text += "</a>";
1160ab45d190SRoman Zippel 	} else
1161ab45d190SRoman Zippel 		*text += str2;
116243bf612aSRoman Zippel }
116343bf612aSRoman Zippel 
11647fc925fdSRoman Zippel QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
11657fc925fdSRoman Zippel {
11667fc925fdSRoman Zippel 	QPopupMenu* popup = Parent::createPopupMenu(pos);
116744ddc4f5Sakpm@osdl.org 	QAction* action = new QAction(NULL,"Show Debug Info", 0, popup);
11687fc925fdSRoman Zippel 	  action->setToggleAction(TRUE);
11697fc925fdSRoman Zippel 	  connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
11707fc925fdSRoman Zippel 	  connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
11717fc925fdSRoman Zippel 	  action->setOn(showDebug());
11727fc925fdSRoman Zippel 	popup->insertSeparator();
11737fc925fdSRoman Zippel 	action->addTo(popup);
11747fc925fdSRoman Zippel 	return popup;
11757fc925fdSRoman Zippel }
11767fc925fdSRoman Zippel 
11777fc925fdSRoman Zippel void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
11787fc925fdSRoman Zippel {
11797fc925fdSRoman Zippel 	Parent::contentsContextMenuEvent(e);
11807fc925fdSRoman Zippel }
11817fc925fdSRoman Zippel 
11827fc925fdSRoman Zippel ConfigSearchWindow::ConfigSearchWindow(QWidget* parent, const char *name)
11837fc925fdSRoman Zippel 	: Parent(parent, name), result(NULL)
118443bf612aSRoman Zippel {
118543bf612aSRoman Zippel 	setCaption("Search Config");
118643bf612aSRoman Zippel 
118743bf612aSRoman Zippel 	QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
118843bf612aSRoman Zippel 	QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
118943bf612aSRoman Zippel 	layout2->addWidget(new QLabel("Find:", this));
119043bf612aSRoman Zippel 	editField = new QLineEdit(this);
119143bf612aSRoman Zippel 	connect(editField, SIGNAL(returnPressed()), SLOT(search()));
119243bf612aSRoman Zippel 	layout2->addWidget(editField);
119343bf612aSRoman Zippel 	searchButton = new QPushButton("Search", this);
119443bf612aSRoman Zippel 	searchButton->setAutoDefault(FALSE);
119543bf612aSRoman Zippel 	connect(searchButton, SIGNAL(clicked()), SLOT(search()));
119643bf612aSRoman Zippel 	layout2->addWidget(searchButton);
119743bf612aSRoman Zippel 	layout1->addLayout(layout2);
119843bf612aSRoman Zippel 
11997fc925fdSRoman Zippel 	split = new QSplitter(this);
120043bf612aSRoman Zippel 	split->setOrientation(QSplitter::Vertical);
12017fc925fdSRoman Zippel 	list = new ConfigView(split, name);
120243bf612aSRoman Zippel 	list->list->mode = listMode;
12037fc925fdSRoman Zippel 	info = new ConfigInfoView(split, name);
120443bf612aSRoman Zippel 	connect(list->list, SIGNAL(menuChanged(struct menu *)),
120543bf612aSRoman Zippel 		info, SLOT(setInfo(struct menu *)));
120643bf612aSRoman Zippel 	layout1->addWidget(split);
12077fc925fdSRoman Zippel 
12087fc925fdSRoman Zippel 	if (name) {
12097fc925fdSRoman Zippel 		int x, y, width, height;
12107fc925fdSRoman Zippel 		bool ok;
12117fc925fdSRoman Zippel 
12127fc925fdSRoman Zippel 		configSettings->beginGroup(name);
12137fc925fdSRoman Zippel 		width = configSettings->readNumEntry("/window width", parent->width() / 2);
12147fc925fdSRoman Zippel 		height = configSettings->readNumEntry("/window height", parent->height() / 2);
12157fc925fdSRoman Zippel 		resize(width, height);
12167fc925fdSRoman Zippel 		x = configSettings->readNumEntry("/window x", 0, &ok);
12177fc925fdSRoman Zippel 		if (ok)
12187fc925fdSRoman Zippel 			y = configSettings->readNumEntry("/window y", 0, &ok);
12197fc925fdSRoman Zippel 		if (ok)
12207fc925fdSRoman Zippel 			move(x, y);
12217fc925fdSRoman Zippel 		QValueList<int> sizes = configSettings->readSizes("/split", &ok);
12227fc925fdSRoman Zippel 		if (ok)
12237fc925fdSRoman Zippel 			split->setSizes(sizes);
12247fc925fdSRoman Zippel 		configSettings->endGroup();
12257fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
12267fc925fdSRoman Zippel 	}
12277fc925fdSRoman Zippel }
12287fc925fdSRoman Zippel 
12297fc925fdSRoman Zippel void ConfigSearchWindow::saveSettings(void)
12307fc925fdSRoman Zippel {
12317fc925fdSRoman Zippel 	if (name()) {
12327fc925fdSRoman Zippel 		configSettings->beginGroup(name());
12337fc925fdSRoman Zippel 		configSettings->writeEntry("/window x", pos().x());
12347fc925fdSRoman Zippel 		configSettings->writeEntry("/window y", pos().y());
12357fc925fdSRoman Zippel 		configSettings->writeEntry("/window width", size().width());
12367fc925fdSRoman Zippel 		configSettings->writeEntry("/window height", size().height());
12377fc925fdSRoman Zippel 		configSettings->writeSizes("/split", split->sizes());
12387fc925fdSRoman Zippel 		configSettings->endGroup();
12397fc925fdSRoman Zippel 	}
124043bf612aSRoman Zippel }
124143bf612aSRoman Zippel 
124243bf612aSRoman Zippel void ConfigSearchWindow::search(void)
124343bf612aSRoman Zippel {
124443bf612aSRoman Zippel 	struct symbol **p;
124543bf612aSRoman Zippel 	struct property *prop;
124643bf612aSRoman Zippel 	ConfigItem *lastItem = NULL;
124743bf612aSRoman Zippel 
124843bf612aSRoman Zippel 	free(result);
124943bf612aSRoman Zippel 	list->list->clear();
125043bf612aSRoman Zippel 
125143bf612aSRoman Zippel 	result = sym_re_search(editField->text().latin1());
125243bf612aSRoman Zippel 	if (!result)
125343bf612aSRoman Zippel 		return;
125443bf612aSRoman Zippel 	for (p = result; *p; p++) {
125543bf612aSRoman Zippel 		for_all_prompts((*p), prop)
125643bf612aSRoman Zippel 			lastItem = new ConfigItem(list->list, lastItem, prop->menu,
125743bf612aSRoman Zippel 						  menu_is_visible(prop->menu));
125843bf612aSRoman Zippel 	}
125943bf612aSRoman Zippel }
126043bf612aSRoman Zippel 
126143bf612aSRoman Zippel /*
126243bf612aSRoman Zippel  * Construct the complete config widget
126343bf612aSRoman Zippel  */
126443bf612aSRoman Zippel ConfigMainWindow::ConfigMainWindow(void)
1265f12aa704SRoman Zippel 	: searchWindow(0)
126643bf612aSRoman Zippel {
126743bf612aSRoman Zippel 	QMenuBar* menu;
12687fc925fdSRoman Zippel 	bool ok;
126943bf612aSRoman Zippel 	int x, y, width, height;
127043bf612aSRoman Zippel 
127143bf612aSRoman Zippel 	QWidget *d = configApp->desktop();
127243bf612aSRoman Zippel 
12737fc925fdSRoman Zippel 	width = configSettings->readNumEntry("/window width", d->width() - 64);
12747fc925fdSRoman Zippel 	height = configSettings->readNumEntry("/window height", d->height() - 64);
127543bf612aSRoman Zippel 	resize(width, height);
12767fc925fdSRoman Zippel 	x = configSettings->readNumEntry("/window x", 0, &ok);
127743bf612aSRoman Zippel 	if (ok)
12787fc925fdSRoman Zippel 		y = configSettings->readNumEntry("/window y", 0, &ok);
127943bf612aSRoman Zippel 	if (ok)
128043bf612aSRoman Zippel 		move(x, y);
128143bf612aSRoman Zippel 
128243bf612aSRoman Zippel 	split1 = new QSplitter(this);
128343bf612aSRoman Zippel 	split1->setOrientation(QSplitter::Horizontal);
128443bf612aSRoman Zippel 	setCentralWidget(split1);
128543bf612aSRoman Zippel 
12867fc925fdSRoman Zippel 	menuView = new ConfigView(split1, "menu");
128743bf612aSRoman Zippel 	menuList = menuView->list;
128843bf612aSRoman Zippel 
128943bf612aSRoman Zippel 	split2 = new QSplitter(split1);
129043bf612aSRoman Zippel 	split2->setOrientation(QSplitter::Vertical);
129143bf612aSRoman Zippel 
129243bf612aSRoman Zippel 	// create config tree
12937fc925fdSRoman Zippel 	configView = new ConfigView(split2, "config");
129443bf612aSRoman Zippel 	configList = configView->list;
129543bf612aSRoman Zippel 
12967fc925fdSRoman Zippel 	helpText = new ConfigInfoView(split2, "help");
129743bf612aSRoman Zippel 	helpText->setTextFormat(Qt::RichText);
129843bf612aSRoman Zippel 
129943bf612aSRoman Zippel 	setTabOrder(configList, helpText);
130043bf612aSRoman Zippel 	configList->setFocus();
130143bf612aSRoman Zippel 
130243bf612aSRoman Zippel 	menu = menuBar();
130343bf612aSRoman Zippel 	toolBar = new QToolBar("Tools", this);
130443bf612aSRoman Zippel 
130543bf612aSRoman Zippel 	backAction = new QAction("Back", QPixmap(xpm_back), "Back", 0, this);
130643bf612aSRoman Zippel 	  connect(backAction, SIGNAL(activated()), SLOT(goBack()));
130743bf612aSRoman Zippel 	  backAction->setEnabled(FALSE);
130843bf612aSRoman Zippel 	QAction *quitAction = new QAction("Quit", "&Quit", CTRL+Key_Q, this);
130943bf612aSRoman Zippel 	  connect(quitAction, SIGNAL(activated()), SLOT(close()));
131043bf612aSRoman Zippel 	QAction *loadAction = new QAction("Load", QPixmap(xpm_load), "&Load", CTRL+Key_L, this);
131143bf612aSRoman Zippel 	  connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
13123b354c55SKarsten Wiese 	saveAction = new QAction("Save", QPixmap(xpm_save), "&Save", CTRL+Key_S, this);
131343bf612aSRoman Zippel 	  connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
13143b354c55SKarsten Wiese 	conf_set_changed_callback(conf_changed);
13153b354c55SKarsten Wiese 	// Set saveAction's initial state
13163b354c55SKarsten Wiese 	conf_changed();
131743bf612aSRoman Zippel 	QAction *saveAsAction = new QAction("Save As...", "Save &As...", 0, this);
131843bf612aSRoman Zippel 	  connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
131943bf612aSRoman Zippel 	QAction *searchAction = new QAction("Search", "&Search", CTRL+Key_F, this);
132043bf612aSRoman Zippel 	  connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
132143bf612aSRoman Zippel 	QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), "Split View", 0, this);
132243bf612aSRoman Zippel 	  connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
132343bf612aSRoman Zippel 	QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), "Split View", 0, this);
132443bf612aSRoman Zippel 	  connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
132543bf612aSRoman Zippel 	QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), "Full View", 0, this);
132643bf612aSRoman Zippel 	  connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
132743bf612aSRoman Zippel 
132843bf612aSRoman Zippel 	QAction *showNameAction = new QAction(NULL, "Show Name", 0, this);
132943bf612aSRoman Zippel 	  showNameAction->setToggleAction(TRUE);
13307fc925fdSRoman Zippel 	  connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
13317fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
13327fc925fdSRoman Zippel 	  showNameAction->setOn(configView->showName());
133343bf612aSRoman Zippel 	QAction *showRangeAction = new QAction(NULL, "Show Range", 0, this);
133443bf612aSRoman Zippel 	  showRangeAction->setToggleAction(TRUE);
13357fc925fdSRoman Zippel 	  connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
13367fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
133743bf612aSRoman Zippel 	  showRangeAction->setOn(configList->showRange);
133843bf612aSRoman Zippel 	QAction *showDataAction = new QAction(NULL, "Show Data", 0, this);
133943bf612aSRoman Zippel 	  showDataAction->setToggleAction(TRUE);
13407fc925fdSRoman Zippel 	  connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
13417fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
134243bf612aSRoman Zippel 	  showDataAction->setOn(configList->showData);
134343bf612aSRoman Zippel 	QAction *showAllAction = new QAction(NULL, "Show All Options", 0, this);
134443bf612aSRoman Zippel 	  showAllAction->setToggleAction(TRUE);
13457fc925fdSRoman Zippel 	  connect(showAllAction, SIGNAL(toggled(bool)), configView, SLOT(setShowAll(bool)));
13467fc925fdSRoman Zippel 	  connect(showAllAction, SIGNAL(toggled(bool)), menuView, SLOT(setShowAll(bool)));
134743bf612aSRoman Zippel 	  showAllAction->setOn(configList->showAll);
134843bf612aSRoman Zippel 	QAction *showDebugAction = new QAction(NULL, "Show Debug Info", 0, this);
134943bf612aSRoman Zippel 	  showDebugAction->setToggleAction(TRUE);
135043bf612aSRoman Zippel 	  connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
135143bf612aSRoman Zippel 	  connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
13527fc925fdSRoman Zippel 	  showDebugAction->setOn(helpText->showDebug());
135343bf612aSRoman Zippel 
135443bf612aSRoman Zippel 	QAction *showIntroAction = new QAction(NULL, "Introduction", 0, this);
135543bf612aSRoman Zippel 	  connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
135643bf612aSRoman Zippel 	QAction *showAboutAction = new QAction(NULL, "About", 0, this);
135743bf612aSRoman Zippel 	  connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
135843bf612aSRoman Zippel 
135943bf612aSRoman Zippel 	// init tool bar
136043bf612aSRoman Zippel 	backAction->addTo(toolBar);
136143bf612aSRoman Zippel 	toolBar->addSeparator();
136243bf612aSRoman Zippel 	loadAction->addTo(toolBar);
136343bf612aSRoman Zippel 	saveAction->addTo(toolBar);
136443bf612aSRoman Zippel 	toolBar->addSeparator();
136543bf612aSRoman Zippel 	singleViewAction->addTo(toolBar);
136643bf612aSRoman Zippel 	splitViewAction->addTo(toolBar);
136743bf612aSRoman Zippel 	fullViewAction->addTo(toolBar);
136843bf612aSRoman Zippel 
136943bf612aSRoman Zippel 	// create config menu
137043bf612aSRoman Zippel 	QPopupMenu* config = new QPopupMenu(this);
137143bf612aSRoman Zippel 	menu->insertItem("&File", config);
137243bf612aSRoman Zippel 	loadAction->addTo(config);
137343bf612aSRoman Zippel 	saveAction->addTo(config);
137443bf612aSRoman Zippel 	saveAsAction->addTo(config);
137543bf612aSRoman Zippel 	config->insertSeparator();
137643bf612aSRoman Zippel 	searchAction->addTo(config);
137743bf612aSRoman Zippel 	config->insertSeparator();
137843bf612aSRoman Zippel 	quitAction->addTo(config);
137943bf612aSRoman Zippel 
138043bf612aSRoman Zippel 	// create options menu
138143bf612aSRoman Zippel 	QPopupMenu* optionMenu = new QPopupMenu(this);
138243bf612aSRoman Zippel 	menu->insertItem("&Option", optionMenu);
138343bf612aSRoman Zippel 	showNameAction->addTo(optionMenu);
138443bf612aSRoman Zippel 	showRangeAction->addTo(optionMenu);
138543bf612aSRoman Zippel 	showDataAction->addTo(optionMenu);
138643bf612aSRoman Zippel 	optionMenu->insertSeparator();
138743bf612aSRoman Zippel 	showAllAction->addTo(optionMenu);
138843bf612aSRoman Zippel 	showDebugAction->addTo(optionMenu);
138943bf612aSRoman Zippel 
139043bf612aSRoman Zippel 	// create help menu
139143bf612aSRoman Zippel 	QPopupMenu* helpMenu = new QPopupMenu(this);
139243bf612aSRoman Zippel 	menu->insertSeparator();
139343bf612aSRoman Zippel 	menu->insertItem("&Help", helpMenu);
139443bf612aSRoman Zippel 	showIntroAction->addTo(helpMenu);
139543bf612aSRoman Zippel 	showAboutAction->addTo(helpMenu);
139643bf612aSRoman Zippel 
139743bf612aSRoman Zippel 	connect(configList, SIGNAL(menuChanged(struct menu *)),
139843bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
139943bf612aSRoman Zippel 	connect(configList, SIGNAL(menuSelected(struct menu *)),
140043bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
140143bf612aSRoman Zippel 	connect(configList, SIGNAL(parentSelected()),
140243bf612aSRoman Zippel 		SLOT(goBack()));
140343bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuChanged(struct menu *)),
140443bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
140543bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuSelected(struct menu *)),
140643bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
140743bf612aSRoman Zippel 
1408b65a47e1SRoman Zippel 	connect(configList, SIGNAL(gotFocus(struct menu *)),
1409b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1410b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
1411b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1412b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
141343bf612aSRoman Zippel 		SLOT(listFocusChanged(void)));
1414b65a47e1SRoman Zippel 	connect(helpText, SIGNAL(menuSelected(struct menu *)),
1415b65a47e1SRoman Zippel 		SLOT(setMenuLink(struct menu *)));
141643bf612aSRoman Zippel 
14177fc925fdSRoman Zippel 	QString listMode = configSettings->readEntry("/listMode", "symbol");
141843bf612aSRoman Zippel 	if (listMode == "single")
141943bf612aSRoman Zippel 		showSingleView();
142043bf612aSRoman Zippel 	else if (listMode == "full")
142143bf612aSRoman Zippel 		showFullView();
142243bf612aSRoman Zippel 	else /*if (listMode == "split")*/
142343bf612aSRoman Zippel 		showSplitView();
142443bf612aSRoman Zippel 
142543bf612aSRoman Zippel 	// UI setup done, restore splitter positions
14267fc925fdSRoman Zippel 	QValueList<int> sizes = configSettings->readSizes("/split1", &ok);
142743bf612aSRoman Zippel 	if (ok)
142843bf612aSRoman Zippel 		split1->setSizes(sizes);
142943bf612aSRoman Zippel 
14307fc925fdSRoman Zippel 	sizes = configSettings->readSizes("/split2", &ok);
143143bf612aSRoman Zippel 	if (ok)
143243bf612aSRoman Zippel 		split2->setSizes(sizes);
143343bf612aSRoman Zippel }
143443bf612aSRoman Zippel 
14351da177e4SLinus Torvalds void ConfigMainWindow::loadConfig(void)
14361da177e4SLinus Torvalds {
14371da177e4SLinus Torvalds 	QString s = QFileDialog::getOpenFileName(".config", NULL, this);
14381da177e4SLinus Torvalds 	if (s.isNull())
14391da177e4SLinus Torvalds 		return;
14403b9fa093SArnaldo Carvalho de Melo 	if (conf_read(QFile::encodeName(s)))
14411da177e4SLinus Torvalds 		QMessageBox::information(this, "qconf", "Unable to load configuration!");
14421da177e4SLinus Torvalds 	ConfigView::updateListAll();
14431da177e4SLinus Torvalds }
14441da177e4SLinus Torvalds 
14451da177e4SLinus Torvalds void ConfigMainWindow::saveConfig(void)
14461da177e4SLinus Torvalds {
14471da177e4SLinus Torvalds 	if (conf_write(NULL))
14481da177e4SLinus Torvalds 		QMessageBox::information(this, "qconf", "Unable to save configuration!");
14491da177e4SLinus Torvalds }
14501da177e4SLinus Torvalds 
14511da177e4SLinus Torvalds void ConfigMainWindow::saveConfigAs(void)
14521da177e4SLinus Torvalds {
14531da177e4SLinus Torvalds 	QString s = QFileDialog::getSaveFileName(".config", NULL, this);
14541da177e4SLinus Torvalds 	if (s.isNull())
14551da177e4SLinus Torvalds 		return;
14563b9fa093SArnaldo Carvalho de Melo 	if (conf_write(QFile::encodeName(s)))
14571da177e4SLinus Torvalds 		QMessageBox::information(this, "qconf", "Unable to save configuration!");
14581da177e4SLinus Torvalds }
14591da177e4SLinus Torvalds 
146043bf612aSRoman Zippel void ConfigMainWindow::searchConfig(void)
146143bf612aSRoman Zippel {
146243bf612aSRoman Zippel 	if (!searchWindow)
14637fc925fdSRoman Zippel 		searchWindow = new ConfigSearchWindow(this, "search");
146443bf612aSRoman Zippel 	searchWindow->show();
146543bf612aSRoman Zippel }
146643bf612aSRoman Zippel 
14671da177e4SLinus Torvalds void ConfigMainWindow::changeMenu(struct menu *menu)
14681da177e4SLinus Torvalds {
14691da177e4SLinus Torvalds 	configList->setRootMenu(menu);
14701da177e4SLinus Torvalds 	backAction->setEnabled(TRUE);
14711da177e4SLinus Torvalds }
14721da177e4SLinus Torvalds 
1473b65a47e1SRoman Zippel void ConfigMainWindow::setMenuLink(struct menu *menu)
1474b65a47e1SRoman Zippel {
1475b65a47e1SRoman Zippel 	struct menu *parent;
1476b65a47e1SRoman Zippel 	ConfigList* list = NULL;
1477b65a47e1SRoman Zippel 	ConfigItem* item;
1478b65a47e1SRoman Zippel 
1479b65a47e1SRoman Zippel 	if (!menu_is_visible(menu) && !configView->showAll())
1480b65a47e1SRoman Zippel 		return;
1481b65a47e1SRoman Zippel 
1482b65a47e1SRoman Zippel 	switch (configList->mode) {
1483b65a47e1SRoman Zippel 	case singleMode:
1484b65a47e1SRoman Zippel 		list = configList;
1485b65a47e1SRoman Zippel 		parent = menu_get_parent_menu(menu);
1486b65a47e1SRoman Zippel 		if (!parent)
1487b65a47e1SRoman Zippel 			return;
1488b65a47e1SRoman Zippel 		list->setRootMenu(parent);
1489b65a47e1SRoman Zippel 		break;
1490b65a47e1SRoman Zippel 	case symbolMode:
1491b65a47e1SRoman Zippel 		if (menu->flags & MENU_ROOT) {
1492b65a47e1SRoman Zippel 			configList->setRootMenu(menu);
1493b65a47e1SRoman Zippel 			configList->clearSelection();
1494b65a47e1SRoman Zippel 			list = menuList;
1495b65a47e1SRoman Zippel 		} else {
1496b65a47e1SRoman Zippel 			list = configList;
1497b65a47e1SRoman Zippel 			parent = menu_get_parent_menu(menu->parent);
1498b65a47e1SRoman Zippel 			if (!parent)
1499b65a47e1SRoman Zippel 				return;
1500b65a47e1SRoman Zippel 			item = menuList->findConfigItem(parent);
1501b65a47e1SRoman Zippel 			if (item) {
1502b65a47e1SRoman Zippel 				menuList->setSelected(item, TRUE);
1503b65a47e1SRoman Zippel 				menuList->ensureItemVisible(item);
1504b65a47e1SRoman Zippel 			}
1505b65a47e1SRoman Zippel 			list->setRootMenu(parent);
1506b65a47e1SRoman Zippel 		}
1507b65a47e1SRoman Zippel 		break;
1508b65a47e1SRoman Zippel 	case fullMode:
1509b65a47e1SRoman Zippel 		list = configList;
1510b65a47e1SRoman Zippel 		break;
1511b65a47e1SRoman Zippel 	}
1512b65a47e1SRoman Zippel 
1513b65a47e1SRoman Zippel 	if (list) {
1514b65a47e1SRoman Zippel 		item = list->findConfigItem(menu);
1515b65a47e1SRoman Zippel 		if (item) {
1516b65a47e1SRoman Zippel 			list->setSelected(item, TRUE);
1517b65a47e1SRoman Zippel 			list->ensureItemVisible(item);
1518b65a47e1SRoman Zippel 			list->setFocus();
1519b65a47e1SRoman Zippel 		}
1520b65a47e1SRoman Zippel 	}
1521b65a47e1SRoman Zippel }
1522b65a47e1SRoman Zippel 
15231da177e4SLinus Torvalds void ConfigMainWindow::listFocusChanged(void)
15241da177e4SLinus Torvalds {
15251da177e4SLinus Torvalds 	if (menuList->mode == menuMode)
15261da177e4SLinus Torvalds 		configList->clearSelection();
15271da177e4SLinus Torvalds }
15281da177e4SLinus Torvalds 
15291da177e4SLinus Torvalds void ConfigMainWindow::goBack(void)
15301da177e4SLinus Torvalds {
15311da177e4SLinus Torvalds 	ConfigItem* item;
15321da177e4SLinus Torvalds 
15331da177e4SLinus Torvalds 	configList->setParentMenu();
15341da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15351da177e4SLinus Torvalds 		backAction->setEnabled(FALSE);
15361da177e4SLinus Torvalds 	item = (ConfigItem*)menuList->selectedItem();
15371da177e4SLinus Torvalds 	while (item) {
15381da177e4SLinus Torvalds 		if (item->menu == configList->rootEntry) {
15391da177e4SLinus Torvalds 			menuList->setSelected(item, TRUE);
15401da177e4SLinus Torvalds 			break;
15411da177e4SLinus Torvalds 		}
15421da177e4SLinus Torvalds 		item = (ConfigItem*)item->parent();
15431da177e4SLinus Torvalds 	}
15441da177e4SLinus Torvalds }
15451da177e4SLinus Torvalds 
15461da177e4SLinus Torvalds void ConfigMainWindow::showSingleView(void)
15471da177e4SLinus Torvalds {
15481da177e4SLinus Torvalds 	menuView->hide();
15491da177e4SLinus Torvalds 	menuList->setRootMenu(0);
15501da177e4SLinus Torvalds 	configList->mode = singleMode;
15511da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15521da177e4SLinus Torvalds 		configList->updateListAll();
15531da177e4SLinus Torvalds 	else
15541da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15551da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
15561da177e4SLinus Torvalds 	configList->setFocus();
15571da177e4SLinus Torvalds }
15581da177e4SLinus Torvalds 
15591da177e4SLinus Torvalds void ConfigMainWindow::showSplitView(void)
15601da177e4SLinus Torvalds {
15611da177e4SLinus Torvalds 	configList->mode = symbolMode;
15621da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15631da177e4SLinus Torvalds 		configList->updateListAll();
15641da177e4SLinus Torvalds 	else
15651da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15661da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
15671da177e4SLinus Torvalds 	configApp->processEvents();
15681da177e4SLinus Torvalds 	menuList->mode = menuMode;
15691da177e4SLinus Torvalds 	menuList->setRootMenu(&rootmenu);
15701da177e4SLinus Torvalds 	menuList->setAllOpen(TRUE);
15711da177e4SLinus Torvalds 	menuView->show();
15721da177e4SLinus Torvalds 	menuList->setFocus();
15731da177e4SLinus Torvalds }
15741da177e4SLinus Torvalds 
15751da177e4SLinus Torvalds void ConfigMainWindow::showFullView(void)
15761da177e4SLinus Torvalds {
15771da177e4SLinus Torvalds 	menuView->hide();
15781da177e4SLinus Torvalds 	menuList->setRootMenu(0);
15791da177e4SLinus Torvalds 	configList->mode = fullMode;
15801da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15811da177e4SLinus Torvalds 		configList->updateListAll();
15821da177e4SLinus Torvalds 	else
15831da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15841da177e4SLinus Torvalds 	configList->setAllOpen(FALSE);
15851da177e4SLinus Torvalds 	configList->setFocus();
15861da177e4SLinus Torvalds }
15871da177e4SLinus Torvalds 
15881da177e4SLinus Torvalds /*
15891da177e4SLinus Torvalds  * ask for saving configuration before quitting
15901da177e4SLinus Torvalds  * TODO ask only when something changed
15911da177e4SLinus Torvalds  */
15921da177e4SLinus Torvalds void ConfigMainWindow::closeEvent(QCloseEvent* e)
15931da177e4SLinus Torvalds {
1594b3214293SKarsten Wiese 	if (!conf_get_changed()) {
15951da177e4SLinus Torvalds 		e->accept();
15961da177e4SLinus Torvalds 		return;
15971da177e4SLinus Torvalds 	}
15981da177e4SLinus Torvalds 	QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
15991da177e4SLinus Torvalds 			QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
16001da177e4SLinus Torvalds 	mb.setButtonText(QMessageBox::Yes, "&Save Changes");
16011da177e4SLinus Torvalds 	mb.setButtonText(QMessageBox::No, "&Discard Changes");
16021da177e4SLinus Torvalds 	mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
16031da177e4SLinus Torvalds 	switch (mb.exec()) {
16041da177e4SLinus Torvalds 	case QMessageBox::Yes:
16051da177e4SLinus Torvalds 		conf_write(NULL);
16061da177e4SLinus Torvalds 	case QMessageBox::No:
16071da177e4SLinus Torvalds 		e->accept();
16081da177e4SLinus Torvalds 		break;
16091da177e4SLinus Torvalds 	case QMessageBox::Cancel:
16101da177e4SLinus Torvalds 		e->ignore();
16111da177e4SLinus Torvalds 		break;
16121da177e4SLinus Torvalds 	}
16131da177e4SLinus Torvalds }
16141da177e4SLinus Torvalds 
16151da177e4SLinus Torvalds void ConfigMainWindow::showIntro(void)
16161da177e4SLinus Torvalds {
16171da177e4SLinus Torvalds 	static char str[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
16181da177e4SLinus Torvalds 		"For each option, a blank box indicates the feature is disabled, a check\n"
16191da177e4SLinus Torvalds 		"indicates it is enabled, and a dot indicates that it is to be compiled\n"
16201da177e4SLinus Torvalds 		"as a module.  Clicking on the box will cycle through the three states.\n\n"
16211da177e4SLinus Torvalds 		"If you do not see an option (e.g., a device driver) that you believe\n"
16221da177e4SLinus Torvalds 		"should be present, try turning on Show All Options under the Options menu.\n"
16231da177e4SLinus Torvalds 		"Although there is no cross reference yet to help you figure out what other\n"
16241da177e4SLinus Torvalds 		"options must be enabled to support the option you are interested in, you can\n"
16251da177e4SLinus Torvalds 		"still view the help of a grayed-out option.\n\n"
16261da177e4SLinus Torvalds 		"Toggling Show Debug Info under the Options menu will show the dependencies,\n"
16271da177e4SLinus Torvalds 		"which you can then match by examining other options.\n\n";
16281da177e4SLinus Torvalds 
16291da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16301da177e4SLinus Torvalds }
16311da177e4SLinus Torvalds 
16321da177e4SLinus Torvalds void ConfigMainWindow::showAbout(void)
16331da177e4SLinus Torvalds {
16341da177e4SLinus Torvalds 	static char str[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
16351da177e4SLinus Torvalds 		"Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
16361da177e4SLinus Torvalds 
16371da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16381da177e4SLinus Torvalds }
16391da177e4SLinus Torvalds 
16401da177e4SLinus Torvalds void ConfigMainWindow::saveSettings(void)
16411da177e4SLinus Torvalds {
16427fc925fdSRoman Zippel 	configSettings->writeEntry("/window x", pos().x());
16437fc925fdSRoman Zippel 	configSettings->writeEntry("/window y", pos().y());
16447fc925fdSRoman Zippel 	configSettings->writeEntry("/window width", size().width());
16457fc925fdSRoman Zippel 	configSettings->writeEntry("/window height", size().height());
16461da177e4SLinus Torvalds 
16471da177e4SLinus Torvalds 	QString entry;
16481da177e4SLinus Torvalds 	switch(configList->mode) {
16491da177e4SLinus Torvalds 	case singleMode :
16501da177e4SLinus Torvalds 		entry = "single";
16511da177e4SLinus Torvalds 		break;
16521da177e4SLinus Torvalds 
16531da177e4SLinus Torvalds 	case symbolMode :
16541da177e4SLinus Torvalds 		entry = "split";
16551da177e4SLinus Torvalds 		break;
16561da177e4SLinus Torvalds 
16571da177e4SLinus Torvalds 	case fullMode :
16581da177e4SLinus Torvalds 		entry = "full";
16591da177e4SLinus Torvalds 		break;
16601da177e4SLinus Torvalds 	}
16617fc925fdSRoman Zippel 	configSettings->writeEntry("/listMode", entry);
16621da177e4SLinus Torvalds 
16637fc925fdSRoman Zippel 	configSettings->writeSizes("/split1", split1->sizes());
16647fc925fdSRoman Zippel 	configSettings->writeSizes("/split2", split2->sizes());
16651da177e4SLinus Torvalds }
16661da177e4SLinus Torvalds 
16673b354c55SKarsten Wiese void ConfigMainWindow::conf_changed(void)
16683b354c55SKarsten Wiese {
16693b354c55SKarsten Wiese 	if (saveAction)
16703b354c55SKarsten Wiese 		saveAction->setEnabled(conf_get_changed());
16713b354c55SKarsten Wiese }
16723b354c55SKarsten Wiese 
16731da177e4SLinus Torvalds void fixup_rootmenu(struct menu *menu)
16741da177e4SLinus Torvalds {
16751da177e4SLinus Torvalds 	struct menu *child;
16761da177e4SLinus Torvalds 	static int menu_cnt = 0;
16771da177e4SLinus Torvalds 
16781da177e4SLinus Torvalds 	menu->flags |= MENU_ROOT;
16791da177e4SLinus Torvalds 	for (child = menu->list; child; child = child->next) {
16801da177e4SLinus Torvalds 		if (child->prompt && child->prompt->type == P_MENU) {
16811da177e4SLinus Torvalds 			menu_cnt++;
16821da177e4SLinus Torvalds 			fixup_rootmenu(child);
16831da177e4SLinus Torvalds 			menu_cnt--;
16841da177e4SLinus Torvalds 		} else if (!menu_cnt)
16851da177e4SLinus Torvalds 			fixup_rootmenu(child);
16861da177e4SLinus Torvalds 	}
16871da177e4SLinus Torvalds }
16881da177e4SLinus Torvalds 
16891da177e4SLinus Torvalds static const char *progname;
16901da177e4SLinus Torvalds 
16911da177e4SLinus Torvalds static void usage(void)
16921da177e4SLinus Torvalds {
16931da177e4SLinus Torvalds 	printf("%s <config>\n", progname);
16941da177e4SLinus Torvalds 	exit(0);
16951da177e4SLinus Torvalds }
16961da177e4SLinus Torvalds 
16971da177e4SLinus Torvalds int main(int ac, char** av)
16981da177e4SLinus Torvalds {
16991da177e4SLinus Torvalds 	ConfigMainWindow* v;
17001da177e4SLinus Torvalds 	const char *name;
17011da177e4SLinus Torvalds 
17023b9fa093SArnaldo Carvalho de Melo 	bindtextdomain(PACKAGE, LOCALEDIR);
17033b9fa093SArnaldo Carvalho de Melo 	textdomain(PACKAGE);
17043b9fa093SArnaldo Carvalho de Melo 
17051da177e4SLinus Torvalds #ifndef LKC_DIRECT_LINK
17061da177e4SLinus Torvalds 	kconfig_load();
17071da177e4SLinus Torvalds #endif
17081da177e4SLinus Torvalds 
17091da177e4SLinus Torvalds 	progname = av[0];
17101da177e4SLinus Torvalds 	configApp = new QApplication(ac, av);
17111da177e4SLinus Torvalds 	if (ac > 1 && av[1][0] == '-') {
17121da177e4SLinus Torvalds 		switch (av[1][1]) {
17131da177e4SLinus Torvalds 		case 'h':
17141da177e4SLinus Torvalds 		case '?':
17151da177e4SLinus Torvalds 			usage();
17161da177e4SLinus Torvalds 		}
17171da177e4SLinus Torvalds 		name = av[2];
17181da177e4SLinus Torvalds 	} else
17191da177e4SLinus Torvalds 		name = av[1];
17201da177e4SLinus Torvalds 	if (!name)
17211da177e4SLinus Torvalds 		usage();
17221da177e4SLinus Torvalds 
17231da177e4SLinus Torvalds 	conf_parse(name);
17241da177e4SLinus Torvalds 	fixup_rootmenu(&rootmenu);
17251da177e4SLinus Torvalds 	conf_read(NULL);
17261da177e4SLinus Torvalds 	//zconfdump(stdout);
17271da177e4SLinus Torvalds 
17287fc925fdSRoman Zippel 	configSettings = new ConfigSettings();
17297fc925fdSRoman Zippel 	configSettings->beginGroup("/kconfig/qconf");
17301da177e4SLinus Torvalds 	v = new ConfigMainWindow();
17311da177e4SLinus Torvalds 
17321da177e4SLinus Torvalds 	//zconfdump(stdout);
173343bf612aSRoman Zippel 	configApp->setMainWidget(v);
17341da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
17351da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
173643bf612aSRoman Zippel 	v->show();
17371da177e4SLinus Torvalds 	configApp->exec();
17381da177e4SLinus Torvalds 
17397fc925fdSRoman Zippel 	configSettings->endGroup();
17407fc925fdSRoman Zippel 	delete configSettings;
17417fc925fdSRoman Zippel 
17421da177e4SLinus Torvalds 	return 0;
17431da177e4SLinus Torvalds }
1744