xref: /openbmc/linux/scripts/kconfig/qconf.cc (revision 284026cd)
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>
88d90c97eSMarkus Heidelberg #include <qdesktopwidget.h>
91da177e4SLinus Torvalds #include <qtoolbar.h>
1043bf612aSRoman Zippel #include <qlayout.h>
111da177e4SLinus Torvalds #include <qvbox.h>
121da177e4SLinus Torvalds #include <qsplitter.h>
131da177e4SLinus Torvalds #include <qlistview.h>
1443bf612aSRoman Zippel #include <qtextbrowser.h>
151da177e4SLinus Torvalds #include <qlineedit.h>
1643bf612aSRoman Zippel #include <qlabel.h>
1743bf612aSRoman Zippel #include <qpushbutton.h>
181da177e4SLinus Torvalds #include <qmenubar.h>
191da177e4SLinus Torvalds #include <qmessagebox.h>
201da177e4SLinus Torvalds #include <qaction.h>
211da177e4SLinus Torvalds #include <qheader.h>
221da177e4SLinus Torvalds #include <qfiledialog.h>
2343bf612aSRoman Zippel #include <qdragobject.h>
241da177e4SLinus Torvalds #include <qregexp.h>
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include <stdlib.h>
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #include "lkc.h"
291da177e4SLinus Torvalds #include "qconf.h"
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds #include "qconf.moc"
321da177e4SLinus Torvalds #include "images.c"
331da177e4SLinus Torvalds 
343b9fa093SArnaldo Carvalho de Melo #ifdef _
353b9fa093SArnaldo Carvalho de Melo # undef _
363b9fa093SArnaldo Carvalho de Melo # define _ qgettext
373b9fa093SArnaldo Carvalho de Melo #endif
383b9fa093SArnaldo Carvalho de Melo 
391da177e4SLinus Torvalds static QApplication *configApp;
407fc925fdSRoman Zippel static ConfigSettings *configSettings;
411da177e4SLinus Torvalds 
423b354c55SKarsten Wiese QAction *ConfigMainWindow::saveAction;
433b354c55SKarsten Wiese 
443b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const char* str)
453b9fa093SArnaldo Carvalho de Melo {
463b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str));
473b9fa093SArnaldo Carvalho de Melo }
483b9fa093SArnaldo Carvalho de Melo 
493b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const QString& str)
503b9fa093SArnaldo Carvalho de Melo {
513b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str.latin1()));
523b9fa093SArnaldo Carvalho de Melo }
533b9fa093SArnaldo Carvalho de Melo 
541da177e4SLinus Torvalds /**
551da177e4SLinus Torvalds  * Reads a list of integer values from the application settings.
561da177e4SLinus Torvalds  */
571da177e4SLinus Torvalds QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
581da177e4SLinus Torvalds {
591da177e4SLinus Torvalds 	QValueList<int> result;
601da177e4SLinus Torvalds 	QStringList entryList = readListEntry(key, ok);
611da177e4SLinus Torvalds 	if (ok) {
621da177e4SLinus Torvalds 		QStringList::Iterator it;
631da177e4SLinus Torvalds 		for (it = entryList.begin(); it != entryList.end(); ++it)
641da177e4SLinus Torvalds 			result.push_back((*it).toInt());
651da177e4SLinus Torvalds 	}
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds 	return result;
681da177e4SLinus Torvalds }
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds /**
711da177e4SLinus Torvalds  * Writes a list of integer values to the application settings.
721da177e4SLinus Torvalds  */
731da177e4SLinus Torvalds bool ConfigSettings::writeSizes(const QString& key, const QValueList<int>& value)
741da177e4SLinus Torvalds {
751da177e4SLinus Torvalds 	QStringList stringList;
761da177e4SLinus Torvalds 	QValueList<int>::ConstIterator it;
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds 	for (it = value.begin(); it != value.end(); ++it)
791da177e4SLinus Torvalds 		stringList.push_back(QString::number(*it));
801da177e4SLinus Torvalds 	return writeEntry(key, stringList);
811da177e4SLinus Torvalds }
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds #if QT_VERSION >= 300
851da177e4SLinus Torvalds /*
861da177e4SLinus Torvalds  * set the new data
871da177e4SLinus Torvalds  * TODO check the value
881da177e4SLinus Torvalds  */
891da177e4SLinus Torvalds void ConfigItem::okRename(int col)
901da177e4SLinus Torvalds {
911da177e4SLinus Torvalds 	Parent::okRename(col);
921da177e4SLinus Torvalds 	sym_set_string_value(menu->sym, text(dataColIdx).latin1());
9349e5646dSKarsten Wiese 	listView()->updateList(this);
941da177e4SLinus Torvalds }
951da177e4SLinus Torvalds #endif
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds /*
981da177e4SLinus Torvalds  * update the displayed of a menu entry
991da177e4SLinus Torvalds  */
1001da177e4SLinus Torvalds void ConfigItem::updateMenu(void)
1011da177e4SLinus Torvalds {
1021da177e4SLinus Torvalds 	ConfigList* list;
1031da177e4SLinus Torvalds 	struct symbol* sym;
1041da177e4SLinus Torvalds 	struct property *prop;
1051da177e4SLinus Torvalds 	QString prompt;
1061da177e4SLinus Torvalds 	int type;
1071da177e4SLinus Torvalds 	tristate expr;
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds 	list = listView();
1101da177e4SLinus Torvalds 	if (goParent) {
1111da177e4SLinus Torvalds 		setPixmap(promptColIdx, list->menuBackPix);
1121da177e4SLinus Torvalds 		prompt = "..";
1131da177e4SLinus Torvalds 		goto set_prompt;
1141da177e4SLinus Torvalds 	}
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	sym = menu->sym;
1171da177e4SLinus Torvalds 	prop = menu->prompt;
118c21a2d95SEGRY Gabor 	prompt = _(menu_get_prompt(menu));
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds 	if (prop) switch (prop->type) {
1211da177e4SLinus Torvalds 	case P_MENU:
1221da177e4SLinus Torvalds 		if (list->mode == singleMode || list->mode == symbolMode) {
1231da177e4SLinus Torvalds 			/* a menuconfig entry is displayed differently
1241da177e4SLinus Torvalds 			 * depending whether it's at the view root or a child.
1251da177e4SLinus Torvalds 			 */
1261da177e4SLinus Torvalds 			if (sym && list->rootEntry == menu)
1271da177e4SLinus Torvalds 				break;
1281da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->menuPix);
1291da177e4SLinus Torvalds 		} else {
1301da177e4SLinus Torvalds 			if (sym)
1311da177e4SLinus Torvalds 				break;
1321da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1331da177e4SLinus Torvalds 		}
1341da177e4SLinus Torvalds 		goto set_prompt;
1351da177e4SLinus Torvalds 	case P_COMMENT:
1361da177e4SLinus Torvalds 		setPixmap(promptColIdx, 0);
1371da177e4SLinus Torvalds 		goto set_prompt;
1381da177e4SLinus Torvalds 	default:
1391da177e4SLinus Torvalds 		;
1401da177e4SLinus Torvalds 	}
1411da177e4SLinus Torvalds 	if (!sym)
1421da177e4SLinus Torvalds 		goto set_prompt;
1431da177e4SLinus Torvalds 
1443b9fa093SArnaldo Carvalho de Melo 	setText(nameColIdx, QString::fromLocal8Bit(sym->name));
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds 	type = sym_get_type(sym);
1471da177e4SLinus Torvalds 	switch (type) {
1481da177e4SLinus Torvalds 	case S_BOOLEAN:
1491da177e4SLinus Torvalds 	case S_TRISTATE:
1501da177e4SLinus Torvalds 		char ch;
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds 		if (!sym_is_changable(sym) && !list->showAll) {
1531da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1543b9fa093SArnaldo Carvalho de Melo 			setText(noColIdx, QString::null);
1553b9fa093SArnaldo Carvalho de Melo 			setText(modColIdx, QString::null);
1563b9fa093SArnaldo Carvalho de Melo 			setText(yesColIdx, QString::null);
1571da177e4SLinus Torvalds 			break;
1581da177e4SLinus Torvalds 		}
1591da177e4SLinus Torvalds 		expr = sym_get_tristate_value(sym);
1601da177e4SLinus Torvalds 		switch (expr) {
1611da177e4SLinus Torvalds 		case yes:
1621da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1631da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceYesPix);
1641da177e4SLinus Torvalds 			else
1651da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolYesPix);
1661da177e4SLinus Torvalds 			setText(yesColIdx, "Y");
1671da177e4SLinus Torvalds 			ch = 'Y';
1681da177e4SLinus Torvalds 			break;
1691da177e4SLinus Torvalds 		case mod:
1701da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->symbolModPix);
1711da177e4SLinus Torvalds 			setText(modColIdx, "M");
1721da177e4SLinus Torvalds 			ch = 'M';
1731da177e4SLinus Torvalds 			break;
1741da177e4SLinus Torvalds 		default:
1751da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1761da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceNoPix);
1771da177e4SLinus Torvalds 			else
1781da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolNoPix);
1791da177e4SLinus Torvalds 			setText(noColIdx, "N");
1801da177e4SLinus Torvalds 			ch = 'N';
1811da177e4SLinus Torvalds 			break;
1821da177e4SLinus Torvalds 		}
1831da177e4SLinus Torvalds 		if (expr != no)
1841da177e4SLinus Torvalds 			setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
1851da177e4SLinus Torvalds 		if (expr != mod)
1861da177e4SLinus Torvalds 			setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
1871da177e4SLinus Torvalds 		if (expr != yes)
1881da177e4SLinus Torvalds 			setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
1891da177e4SLinus Torvalds 
1901da177e4SLinus Torvalds 		setText(dataColIdx, QChar(ch));
1911da177e4SLinus Torvalds 		break;
1921da177e4SLinus Torvalds 	case S_INT:
1931da177e4SLinus Torvalds 	case S_HEX:
1941da177e4SLinus Torvalds 	case S_STRING:
1951da177e4SLinus Torvalds 		const char* data;
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds 		data = sym_get_string_value(sym);
1983b9fa093SArnaldo Carvalho de Melo 
1991da177e4SLinus Torvalds #if QT_VERSION >= 300
2001da177e4SLinus Torvalds 		int i = list->mapIdx(dataColIdx);
2011da177e4SLinus Torvalds 		if (i >= 0)
2021da177e4SLinus Torvalds 			setRenameEnabled(i, TRUE);
2031da177e4SLinus Torvalds #endif
2041da177e4SLinus Torvalds 		setText(dataColIdx, data);
2051da177e4SLinus Torvalds 		if (type == S_STRING)
2063b9fa093SArnaldo Carvalho de Melo 			prompt = QString("%1: %2").arg(prompt).arg(data);
2071da177e4SLinus Torvalds 		else
2083b9fa093SArnaldo Carvalho de Melo 			prompt = QString("(%2) %1").arg(prompt).arg(data);
2091da177e4SLinus Torvalds 		break;
2101da177e4SLinus Torvalds 	}
2111da177e4SLinus Torvalds 	if (!sym_has_value(sym) && visible)
212c21a2d95SEGRY Gabor 		prompt += _(" (NEW)");
2131da177e4SLinus Torvalds set_prompt:
2141da177e4SLinus Torvalds 	setText(promptColIdx, prompt);
2151da177e4SLinus Torvalds }
2161da177e4SLinus Torvalds 
2171da177e4SLinus Torvalds void ConfigItem::testUpdateMenu(bool v)
2181da177e4SLinus Torvalds {
2191da177e4SLinus Torvalds 	ConfigItem* i;
2201da177e4SLinus Torvalds 
2211da177e4SLinus Torvalds 	visible = v;
2221da177e4SLinus Torvalds 	if (!menu)
2231da177e4SLinus Torvalds 		return;
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds 	sym_calc_value(menu->sym);
2261da177e4SLinus Torvalds 	if (menu->flags & MENU_CHANGED) {
2271da177e4SLinus Torvalds 		/* the menu entry changed, so update all list items */
2281da177e4SLinus Torvalds 		menu->flags &= ~MENU_CHANGED;
2291da177e4SLinus Torvalds 		for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
2301da177e4SLinus Torvalds 			i->updateMenu();
2311da177e4SLinus Torvalds 	} else if (listView()->updateAll)
2321da177e4SLinus Torvalds 		updateMenu();
2331da177e4SLinus Torvalds }
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
2361da177e4SLinus Torvalds {
2371da177e4SLinus Torvalds 	ConfigList* list = listView();
2381da177e4SLinus Torvalds 
2391da177e4SLinus Torvalds 	if (visible) {
2401da177e4SLinus Torvalds 		if (isSelected() && !list->hasFocus() && list->mode == menuMode)
2411da177e4SLinus Torvalds 			Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
2421da177e4SLinus Torvalds 		else
2431da177e4SLinus Torvalds 			Parent::paintCell(p, cg, column, width, align);
2441da177e4SLinus Torvalds 	} else
2451da177e4SLinus Torvalds 		Parent::paintCell(p, list->disabledColorGroup, column, width, align);
2461da177e4SLinus Torvalds }
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds /*
2491da177e4SLinus Torvalds  * construct a menu entry
2501da177e4SLinus Torvalds  */
2511da177e4SLinus Torvalds void ConfigItem::init(void)
2521da177e4SLinus Torvalds {
2531da177e4SLinus Torvalds 	if (menu) {
2541da177e4SLinus Torvalds 		ConfigList* list = listView();
2551da177e4SLinus Torvalds 		nextItem = (ConfigItem*)menu->data;
2561da177e4SLinus Torvalds 		menu->data = this;
2571da177e4SLinus Torvalds 
2581da177e4SLinus Torvalds 		if (list->mode != fullMode)
2591da177e4SLinus Torvalds 			setOpen(TRUE);
2601da177e4SLinus Torvalds 		sym_calc_value(menu->sym);
2611da177e4SLinus Torvalds 	}
2621da177e4SLinus Torvalds 	updateMenu();
2631da177e4SLinus Torvalds }
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds /*
2661da177e4SLinus Torvalds  * destruct a menu entry
2671da177e4SLinus Torvalds  */
2681da177e4SLinus Torvalds ConfigItem::~ConfigItem(void)
2691da177e4SLinus Torvalds {
2701da177e4SLinus Torvalds 	if (menu) {
2711da177e4SLinus Torvalds 		ConfigItem** ip = (ConfigItem**)&menu->data;
2721da177e4SLinus Torvalds 		for (; *ip; ip = &(*ip)->nextItem) {
2731da177e4SLinus Torvalds 			if (*ip == this) {
2741da177e4SLinus Torvalds 				*ip = nextItem;
2751da177e4SLinus Torvalds 				break;
2761da177e4SLinus Torvalds 			}
2771da177e4SLinus Torvalds 		}
2781da177e4SLinus Torvalds 	}
2791da177e4SLinus Torvalds }
2801da177e4SLinus Torvalds 
28143bf612aSRoman Zippel ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
28243bf612aSRoman Zippel 	: Parent(parent)
28343bf612aSRoman Zippel {
28443bf612aSRoman Zippel 	connect(this, SIGNAL(lostFocus()), SLOT(hide()));
28543bf612aSRoman Zippel }
28643bf612aSRoman Zippel 
2871da177e4SLinus Torvalds void ConfigLineEdit::show(ConfigItem* i)
2881da177e4SLinus Torvalds {
2891da177e4SLinus Torvalds 	item = i;
2901da177e4SLinus Torvalds 	if (sym_get_string_value(item->menu->sym))
2913b9fa093SArnaldo Carvalho de Melo 		setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
2921da177e4SLinus Torvalds 	else
2933b9fa093SArnaldo Carvalho de Melo 		setText(QString::null);
2941da177e4SLinus Torvalds 	Parent::show();
2951da177e4SLinus Torvalds 	setFocus();
2961da177e4SLinus Torvalds }
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
2991da177e4SLinus Torvalds {
3001da177e4SLinus Torvalds 	switch (e->key()) {
301fbb86374SMarkus Heidelberg 	case Qt::Key_Escape:
3021da177e4SLinus Torvalds 		break;
303fbb86374SMarkus Heidelberg 	case Qt::Key_Return:
304fbb86374SMarkus Heidelberg 	case Qt::Key_Enter:
3051da177e4SLinus Torvalds 		sym_set_string_value(item->menu->sym, text().latin1());
3061da177e4SLinus Torvalds 		parent()->updateList(item);
3071da177e4SLinus Torvalds 		break;
3081da177e4SLinus Torvalds 	default:
3091da177e4SLinus Torvalds 		Parent::keyPressEvent(e);
3101da177e4SLinus Torvalds 		return;
3111da177e4SLinus Torvalds 	}
3121da177e4SLinus Torvalds 	e->accept();
3131da177e4SLinus Torvalds 	parent()->list->setFocus();
3141da177e4SLinus Torvalds 	hide();
3151da177e4SLinus Torvalds }
3161da177e4SLinus Torvalds 
3177fc925fdSRoman Zippel ConfigList::ConfigList(ConfigView* p, const char *name)
3187fc925fdSRoman Zippel 	: Parent(p, name),
3191da177e4SLinus Torvalds 	  updateAll(false),
3201da177e4SLinus Torvalds 	  symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
3211da177e4SLinus Torvalds 	  choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
3221da177e4SLinus Torvalds 	  menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
3231da177e4SLinus Torvalds 	  showAll(false), showName(false), showRange(false), showData(false),
3247fc925fdSRoman Zippel 	  rootEntry(0), headerPopup(0)
3251da177e4SLinus Torvalds {
3261da177e4SLinus Torvalds 	int i;
3271da177e4SLinus Torvalds 
3281da177e4SLinus Torvalds 	setSorting(-1);
3291da177e4SLinus Torvalds 	setRootIsDecorated(TRUE);
3301da177e4SLinus Torvalds 	disabledColorGroup = palette().active();
3311da177e4SLinus Torvalds 	disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
3321da177e4SLinus Torvalds 	inactivedColorGroup = palette().active();
3331da177e4SLinus Torvalds 	inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds 	connect(this, SIGNAL(selectionChanged(void)),
3361da177e4SLinus Torvalds 		SLOT(updateSelection(void)));
3371da177e4SLinus Torvalds 
3387fc925fdSRoman Zippel 	if (name) {
3397fc925fdSRoman Zippel 		configSettings->beginGroup(name);
3407fc925fdSRoman Zippel 		showAll = configSettings->readBoolEntry("/showAll", false);
3417fc925fdSRoman Zippel 		showName = configSettings->readBoolEntry("/showName", false);
3427fc925fdSRoman Zippel 		showRange = configSettings->readBoolEntry("/showRange", false);
3437fc925fdSRoman Zippel 		showData = configSettings->readBoolEntry("/showData", false);
3447fc925fdSRoman Zippel 		configSettings->endGroup();
3457fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
3461da177e4SLinus Torvalds 	}
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds 	for (i = 0; i < colNr; i++)
3491da177e4SLinus Torvalds 		colMap[i] = colRevMap[i] = -1;
350c21a2d95SEGRY Gabor 	addColumn(promptColIdx, _("Option"));
3511da177e4SLinus Torvalds 
3521da177e4SLinus Torvalds 	reinit();
3531da177e4SLinus Torvalds }
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds void ConfigList::reinit(void)
3561da177e4SLinus Torvalds {
3571da177e4SLinus Torvalds 	removeColumn(dataColIdx);
3581da177e4SLinus Torvalds 	removeColumn(yesColIdx);
3591da177e4SLinus Torvalds 	removeColumn(modColIdx);
3601da177e4SLinus Torvalds 	removeColumn(noColIdx);
3611da177e4SLinus Torvalds 	removeColumn(nameColIdx);
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds 	if (showName)
364c21a2d95SEGRY Gabor 		addColumn(nameColIdx, _("Name"));
3651da177e4SLinus Torvalds 	if (showRange) {
3661da177e4SLinus Torvalds 		addColumn(noColIdx, "N");
3671da177e4SLinus Torvalds 		addColumn(modColIdx, "M");
3681da177e4SLinus Torvalds 		addColumn(yesColIdx, "Y");
3691da177e4SLinus Torvalds 	}
3701da177e4SLinus Torvalds 	if (showData)
371c21a2d95SEGRY Gabor 		addColumn(dataColIdx, _("Value"));
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds 	updateListAll();
3741da177e4SLinus Torvalds }
3751da177e4SLinus Torvalds 
3767fc925fdSRoman Zippel void ConfigList::saveSettings(void)
3777fc925fdSRoman Zippel {
3787fc925fdSRoman Zippel 	if (name()) {
3797fc925fdSRoman Zippel 		configSettings->beginGroup(name());
3807fc925fdSRoman Zippel 		configSettings->writeEntry("/showName", showName);
3817fc925fdSRoman Zippel 		configSettings->writeEntry("/showRange", showRange);
3827fc925fdSRoman Zippel 		configSettings->writeEntry("/showData", showData);
3837fc925fdSRoman Zippel 		configSettings->writeEntry("/showAll", showAll);
3847fc925fdSRoman Zippel 		configSettings->endGroup();
3857fc925fdSRoman Zippel 	}
3867fc925fdSRoman Zippel }
3877fc925fdSRoman Zippel 
388b65a47e1SRoman Zippel ConfigItem* ConfigList::findConfigItem(struct menu *menu)
389b65a47e1SRoman Zippel {
390b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem*)menu->data;
391b65a47e1SRoman Zippel 
392b65a47e1SRoman Zippel 	for (; item; item = item->nextItem) {
393b65a47e1SRoman Zippel 		if (this == item->listView())
394b65a47e1SRoman Zippel 			break;
395b65a47e1SRoman Zippel 	}
396b65a47e1SRoman Zippel 
397b65a47e1SRoman Zippel 	return item;
398b65a47e1SRoman Zippel }
399b65a47e1SRoman Zippel 
4001da177e4SLinus Torvalds void ConfigList::updateSelection(void)
4011da177e4SLinus Torvalds {
4021da177e4SLinus Torvalds 	struct menu *menu;
4031da177e4SLinus Torvalds 	enum prop_type type;
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)selectedItem();
4061da177e4SLinus Torvalds 	if (!item)
4071da177e4SLinus Torvalds 		return;
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds 	menu = item->menu;
41043bf612aSRoman Zippel 	emit menuChanged(menu);
4111da177e4SLinus Torvalds 	if (!menu)
4121da177e4SLinus Torvalds 		return;
4131da177e4SLinus Torvalds 	type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
4141da177e4SLinus Torvalds 	if (mode == menuMode && type == P_MENU)
4151da177e4SLinus Torvalds 		emit menuSelected(menu);
4161da177e4SLinus Torvalds }
4171da177e4SLinus Torvalds 
4181da177e4SLinus Torvalds void ConfigList::updateList(ConfigItem* item)
4191da177e4SLinus Torvalds {
4201da177e4SLinus Torvalds 	ConfigItem* last = 0;
4211da177e4SLinus Torvalds 
42243bf612aSRoman Zippel 	if (!rootEntry) {
42343bf612aSRoman Zippel 		if (mode != listMode)
4241da177e4SLinus Torvalds 			goto update;
42543bf612aSRoman Zippel 		QListViewItemIterator it(this);
42643bf612aSRoman Zippel 		ConfigItem* item;
42743bf612aSRoman Zippel 
42843bf612aSRoman Zippel 		for (; it.current(); ++it) {
42943bf612aSRoman Zippel 			item = (ConfigItem*)it.current();
43043bf612aSRoman Zippel 			if (!item->menu)
43143bf612aSRoman Zippel 				continue;
43243bf612aSRoman Zippel 			item->testUpdateMenu(menu_is_visible(item->menu));
43343bf612aSRoman Zippel 		}
43443bf612aSRoman Zippel 		return;
43543bf612aSRoman Zippel 	}
4361da177e4SLinus Torvalds 
4371da177e4SLinus Torvalds 	if (rootEntry != &rootmenu && (mode == singleMode ||
4381da177e4SLinus Torvalds 	    (mode == symbolMode && rootEntry->parent != &rootmenu))) {
4391da177e4SLinus Torvalds 		item = firstChild();
4401da177e4SLinus Torvalds 		if (!item)
4411da177e4SLinus Torvalds 			item = new ConfigItem(this, 0, true);
4421da177e4SLinus Torvalds 		last = item;
4431da177e4SLinus Torvalds 	}
4441da177e4SLinus Torvalds 	if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
4451da177e4SLinus Torvalds 	    rootEntry->sym && rootEntry->prompt) {
4461da177e4SLinus Torvalds 		item = last ? last->nextSibling() : firstChild();
4471da177e4SLinus Torvalds 		if (!item)
4481da177e4SLinus Torvalds 			item = new ConfigItem(this, last, rootEntry, true);
4491da177e4SLinus Torvalds 		else
4501da177e4SLinus Torvalds 			item->testUpdateMenu(true);
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds 		updateMenuList(item, rootEntry);
4531da177e4SLinus Torvalds 		triggerUpdate();
4541da177e4SLinus Torvalds 		return;
4551da177e4SLinus Torvalds 	}
4561da177e4SLinus Torvalds update:
4571da177e4SLinus Torvalds 	updateMenuList(this, rootEntry);
4581da177e4SLinus Torvalds 	triggerUpdate();
4591da177e4SLinus Torvalds }
4601da177e4SLinus Torvalds 
4611da177e4SLinus Torvalds void ConfigList::setValue(ConfigItem* item, tristate val)
4621da177e4SLinus Torvalds {
4631da177e4SLinus Torvalds 	struct symbol* sym;
4641da177e4SLinus Torvalds 	int type;
4651da177e4SLinus Torvalds 	tristate oldval;
4661da177e4SLinus Torvalds 
4671da177e4SLinus Torvalds 	sym = item->menu ? item->menu->sym : 0;
4681da177e4SLinus Torvalds 	if (!sym)
4691da177e4SLinus Torvalds 		return;
4701da177e4SLinus Torvalds 
4711da177e4SLinus Torvalds 	type = sym_get_type(sym);
4721da177e4SLinus Torvalds 	switch (type) {
4731da177e4SLinus Torvalds 	case S_BOOLEAN:
4741da177e4SLinus Torvalds 	case S_TRISTATE:
4751da177e4SLinus Torvalds 		oldval = sym_get_tristate_value(sym);
4761da177e4SLinus Torvalds 
4771da177e4SLinus Torvalds 		if (!sym_set_tristate_value(sym, val))
4781da177e4SLinus Torvalds 			return;
4791da177e4SLinus Torvalds 		if (oldval == no && item->menu->list)
4801da177e4SLinus Torvalds 			item->setOpen(TRUE);
4811da177e4SLinus Torvalds 		parent()->updateList(item);
4821da177e4SLinus Torvalds 		break;
4831da177e4SLinus Torvalds 	}
4841da177e4SLinus Torvalds }
4851da177e4SLinus Torvalds 
4861da177e4SLinus Torvalds void ConfigList::changeValue(ConfigItem* item)
4871da177e4SLinus Torvalds {
4881da177e4SLinus Torvalds 	struct symbol* sym;
4891da177e4SLinus Torvalds 	struct menu* menu;
4901da177e4SLinus Torvalds 	int type, oldexpr, newexpr;
4911da177e4SLinus Torvalds 
4921da177e4SLinus Torvalds 	menu = item->menu;
4931da177e4SLinus Torvalds 	if (!menu)
4941da177e4SLinus Torvalds 		return;
4951da177e4SLinus Torvalds 	sym = menu->sym;
4961da177e4SLinus Torvalds 	if (!sym) {
4971da177e4SLinus Torvalds 		if (item->menu->list)
4981da177e4SLinus Torvalds 			item->setOpen(!item->isOpen());
4991da177e4SLinus Torvalds 		return;
5001da177e4SLinus Torvalds 	}
5011da177e4SLinus Torvalds 
5021da177e4SLinus Torvalds 	type = sym_get_type(sym);
5031da177e4SLinus Torvalds 	switch (type) {
5041da177e4SLinus Torvalds 	case S_BOOLEAN:
5051da177e4SLinus Torvalds 	case S_TRISTATE:
5061da177e4SLinus Torvalds 		oldexpr = sym_get_tristate_value(sym);
5071da177e4SLinus Torvalds 		newexpr = sym_toggle_tristate_value(sym);
5081da177e4SLinus Torvalds 		if (item->menu->list) {
5091da177e4SLinus Torvalds 			if (oldexpr == newexpr)
5101da177e4SLinus Torvalds 				item->setOpen(!item->isOpen());
5111da177e4SLinus Torvalds 			else if (oldexpr == no)
5121da177e4SLinus Torvalds 				item->setOpen(TRUE);
5131da177e4SLinus Torvalds 		}
5141da177e4SLinus Torvalds 		if (oldexpr != newexpr)
5151da177e4SLinus Torvalds 			parent()->updateList(item);
5161da177e4SLinus Torvalds 		break;
5171da177e4SLinus Torvalds 	case S_INT:
5181da177e4SLinus Torvalds 	case S_HEX:
5191da177e4SLinus Torvalds 	case S_STRING:
5201da177e4SLinus Torvalds #if QT_VERSION >= 300
5211da177e4SLinus Torvalds 		if (colMap[dataColIdx] >= 0)
5221da177e4SLinus Torvalds 			item->startRename(colMap[dataColIdx]);
5231da177e4SLinus Torvalds 		else
5241da177e4SLinus Torvalds #endif
5251da177e4SLinus Torvalds 			parent()->lineEdit->show(item);
5261da177e4SLinus Torvalds 		break;
5271da177e4SLinus Torvalds 	}
5281da177e4SLinus Torvalds }
5291da177e4SLinus Torvalds 
5301da177e4SLinus Torvalds void ConfigList::setRootMenu(struct menu *menu)
5311da177e4SLinus Torvalds {
5321da177e4SLinus Torvalds 	enum prop_type type;
5331da177e4SLinus Torvalds 
5341da177e4SLinus Torvalds 	if (rootEntry == menu)
5351da177e4SLinus Torvalds 		return;
5361da177e4SLinus Torvalds 	type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
5371da177e4SLinus Torvalds 	if (type != P_MENU)
5381da177e4SLinus Torvalds 		return;
5391da177e4SLinus Torvalds 	updateMenuList(this, 0);
5401da177e4SLinus Torvalds 	rootEntry = menu;
5411da177e4SLinus Torvalds 	updateListAll();
5421da177e4SLinus Torvalds 	setSelected(currentItem(), hasFocus());
543b65a47e1SRoman Zippel 	ensureItemVisible(currentItem());
5441da177e4SLinus Torvalds }
5451da177e4SLinus Torvalds 
5461da177e4SLinus Torvalds void ConfigList::setParentMenu(void)
5471da177e4SLinus Torvalds {
5481da177e4SLinus Torvalds 	ConfigItem* item;
5491da177e4SLinus Torvalds 	struct menu *oldroot;
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds 	oldroot = rootEntry;
5521da177e4SLinus Torvalds 	if (rootEntry == &rootmenu)
5531da177e4SLinus Torvalds 		return;
5541da177e4SLinus Torvalds 	setRootMenu(menu_get_parent_menu(rootEntry->parent));
5551da177e4SLinus Torvalds 
5561da177e4SLinus Torvalds 	QListViewItemIterator it(this);
5571da177e4SLinus Torvalds 	for (; (item = (ConfigItem*)it.current()); it++) {
5581da177e4SLinus Torvalds 		if (item->menu == oldroot) {
5591da177e4SLinus Torvalds 			setCurrentItem(item);
5601da177e4SLinus Torvalds 			ensureItemVisible(item);
5611da177e4SLinus Torvalds 			break;
5621da177e4SLinus Torvalds 		}
5631da177e4SLinus Torvalds 	}
5641da177e4SLinus Torvalds }
5651da177e4SLinus Torvalds 
5667fc925fdSRoman Zippel /*
5677fc925fdSRoman Zippel  * update all the children of a menu entry
5687fc925fdSRoman Zippel  *   removes/adds the entries from the parent widget as necessary
5697fc925fdSRoman Zippel  *
5707fc925fdSRoman Zippel  * parent: either the menu list widget or a menu entry widget
5717fc925fdSRoman Zippel  * menu: entry to be updated
5727fc925fdSRoman Zippel  */
5737fc925fdSRoman Zippel template <class P>
5747fc925fdSRoman Zippel void ConfigList::updateMenuList(P* parent, struct menu* menu)
5757fc925fdSRoman Zippel {
5767fc925fdSRoman Zippel 	struct menu* child;
5777fc925fdSRoman Zippel 	ConfigItem* item;
5787fc925fdSRoman Zippel 	ConfigItem* last;
5797fc925fdSRoman Zippel 	bool visible;
5807fc925fdSRoman Zippel 	enum prop_type type;
5817fc925fdSRoman Zippel 
5827fc925fdSRoman Zippel 	if (!menu) {
5837fc925fdSRoman Zippel 		while ((item = parent->firstChild()))
5847fc925fdSRoman Zippel 			delete item;
5857fc925fdSRoman Zippel 		return;
5867fc925fdSRoman Zippel 	}
5877fc925fdSRoman Zippel 
5887fc925fdSRoman Zippel 	last = parent->firstChild();
5897fc925fdSRoman Zippel 	if (last && !last->goParent)
5907fc925fdSRoman Zippel 		last = 0;
5917fc925fdSRoman Zippel 	for (child = menu->list; child; child = child->next) {
5927fc925fdSRoman Zippel 		item = last ? last->nextSibling() : parent->firstChild();
5937fc925fdSRoman Zippel 		type = child->prompt ? child->prompt->type : P_UNKNOWN;
5947fc925fdSRoman Zippel 
5957fc925fdSRoman Zippel 		switch (mode) {
5967fc925fdSRoman Zippel 		case menuMode:
5977fc925fdSRoman Zippel 			if (!(child->flags & MENU_ROOT))
5987fc925fdSRoman Zippel 				goto hide;
5997fc925fdSRoman Zippel 			break;
6007fc925fdSRoman Zippel 		case symbolMode:
6017fc925fdSRoman Zippel 			if (child->flags & MENU_ROOT)
6027fc925fdSRoman Zippel 				goto hide;
6037fc925fdSRoman Zippel 			break;
6047fc925fdSRoman Zippel 		default:
6057fc925fdSRoman Zippel 			break;
6067fc925fdSRoman Zippel 		}
6077fc925fdSRoman Zippel 
6087fc925fdSRoman Zippel 		visible = menu_is_visible(child);
6097fc925fdSRoman Zippel 		if (showAll || visible) {
610ed8b4d4dSCyrill V. Gorcunov 			if (!child->sym && !child->list && !child->prompt)
611ed8b4d4dSCyrill V. Gorcunov 				continue;
6127fc925fdSRoman Zippel 			if (!item || item->menu != child)
6137fc925fdSRoman Zippel 				item = new ConfigItem(parent, last, child, visible);
6147fc925fdSRoman Zippel 			else
6157fc925fdSRoman Zippel 				item->testUpdateMenu(visible);
6167fc925fdSRoman Zippel 
6177fc925fdSRoman Zippel 			if (mode == fullMode || mode == menuMode || type != P_MENU)
6187fc925fdSRoman Zippel 				updateMenuList(item, child);
6197fc925fdSRoman Zippel 			else
6207fc925fdSRoman Zippel 				updateMenuList(item, 0);
6217fc925fdSRoman Zippel 			last = item;
6227fc925fdSRoman Zippel 			continue;
6237fc925fdSRoman Zippel 		}
6247fc925fdSRoman Zippel 	hide:
6257fc925fdSRoman Zippel 		if (item && item->menu == child) {
6267fc925fdSRoman Zippel 			last = parent->firstChild();
6277fc925fdSRoman Zippel 			if (last == item)
6287fc925fdSRoman Zippel 				last = 0;
6297fc925fdSRoman Zippel 			else while (last->nextSibling() != item)
6307fc925fdSRoman Zippel 				last = last->nextSibling();
6317fc925fdSRoman Zippel 			delete item;
6327fc925fdSRoman Zippel 		}
6337fc925fdSRoman Zippel 	}
6347fc925fdSRoman Zippel }
6357fc925fdSRoman Zippel 
6361da177e4SLinus Torvalds void ConfigList::keyPressEvent(QKeyEvent* ev)
6371da177e4SLinus Torvalds {
6381da177e4SLinus Torvalds 	QListViewItem* i = currentItem();
6391da177e4SLinus Torvalds 	ConfigItem* item;
6401da177e4SLinus Torvalds 	struct menu *menu;
6411da177e4SLinus Torvalds 	enum prop_type type;
6421da177e4SLinus Torvalds 
643fbb86374SMarkus Heidelberg 	if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
6441da177e4SLinus Torvalds 		emit parentSelected();
6451da177e4SLinus Torvalds 		ev->accept();
6461da177e4SLinus Torvalds 		return;
6471da177e4SLinus Torvalds 	}
6481da177e4SLinus Torvalds 
6491da177e4SLinus Torvalds 	if (!i) {
6501da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
6511da177e4SLinus Torvalds 		return;
6521da177e4SLinus Torvalds 	}
6531da177e4SLinus Torvalds 	item = (ConfigItem*)i;
6541da177e4SLinus Torvalds 
6551da177e4SLinus Torvalds 	switch (ev->key()) {
656fbb86374SMarkus Heidelberg 	case Qt::Key_Return:
657fbb86374SMarkus Heidelberg 	case Qt::Key_Enter:
6581da177e4SLinus Torvalds 		if (item->goParent) {
6591da177e4SLinus Torvalds 			emit parentSelected();
6601da177e4SLinus Torvalds 			break;
6611da177e4SLinus Torvalds 		}
6621da177e4SLinus Torvalds 		menu = item->menu;
6631da177e4SLinus Torvalds 		if (!menu)
6641da177e4SLinus Torvalds 			break;
6651da177e4SLinus Torvalds 		type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
6661da177e4SLinus Torvalds 		if (type == P_MENU && rootEntry != menu &&
6671da177e4SLinus Torvalds 		    mode != fullMode && mode != menuMode) {
6681da177e4SLinus Torvalds 			emit menuSelected(menu);
6691da177e4SLinus Torvalds 			break;
6701da177e4SLinus Torvalds 		}
671fbb86374SMarkus Heidelberg 	case Qt::Key_Space:
6721da177e4SLinus Torvalds 		changeValue(item);
6731da177e4SLinus Torvalds 		break;
674fbb86374SMarkus Heidelberg 	case Qt::Key_N:
6751da177e4SLinus Torvalds 		setValue(item, no);
6761da177e4SLinus Torvalds 		break;
677fbb86374SMarkus Heidelberg 	case Qt::Key_M:
6781da177e4SLinus Torvalds 		setValue(item, mod);
6791da177e4SLinus Torvalds 		break;
680fbb86374SMarkus Heidelberg 	case Qt::Key_Y:
6811da177e4SLinus Torvalds 		setValue(item, yes);
6821da177e4SLinus Torvalds 		break;
6831da177e4SLinus Torvalds 	default:
6841da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
6851da177e4SLinus Torvalds 		return;
6861da177e4SLinus Torvalds 	}
6871da177e4SLinus Torvalds 	ev->accept();
6881da177e4SLinus Torvalds }
6891da177e4SLinus Torvalds 
6901da177e4SLinus Torvalds void ConfigList::contentsMousePressEvent(QMouseEvent* e)
6911da177e4SLinus Torvalds {
6921da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
6931da177e4SLinus Torvalds 	//printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
6941da177e4SLinus Torvalds 	Parent::contentsMousePressEvent(e);
6951da177e4SLinus Torvalds }
6961da177e4SLinus Torvalds 
6971da177e4SLinus Torvalds void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
6981da177e4SLinus Torvalds {
6991da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
7001da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
7011da177e4SLinus Torvalds 	struct menu *menu;
7021da177e4SLinus Torvalds 	enum prop_type ptype;
7031da177e4SLinus Torvalds 	const QPixmap* pm;
7041da177e4SLinus Torvalds 	int idx, x;
7051da177e4SLinus Torvalds 
7061da177e4SLinus Torvalds 	if (!item)
7071da177e4SLinus Torvalds 		goto skip;
7081da177e4SLinus Torvalds 
7091da177e4SLinus Torvalds 	menu = item->menu;
7101da177e4SLinus Torvalds 	x = header()->offset() + p.x();
7111da177e4SLinus Torvalds 	idx = colRevMap[header()->sectionAt(x)];
7121da177e4SLinus Torvalds 	switch (idx) {
7131da177e4SLinus Torvalds 	case promptColIdx:
7141da177e4SLinus Torvalds 		pm = item->pixmap(promptColIdx);
7151da177e4SLinus Torvalds 		if (pm) {
7161da177e4SLinus Torvalds 			int off = header()->sectionPos(0) + itemMargin() +
7171da177e4SLinus Torvalds 				treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
7181da177e4SLinus Torvalds 			if (x >= off && x < off + pm->width()) {
7191da177e4SLinus Torvalds 				if (item->goParent) {
7201da177e4SLinus Torvalds 					emit parentSelected();
7211da177e4SLinus Torvalds 					break;
7221da177e4SLinus Torvalds 				} else if (!menu)
7231da177e4SLinus Torvalds 					break;
7241da177e4SLinus Torvalds 				ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7251da177e4SLinus Torvalds 				if (ptype == P_MENU && rootEntry != menu &&
7261da177e4SLinus Torvalds 				    mode != fullMode && mode != menuMode)
7271da177e4SLinus Torvalds 					emit menuSelected(menu);
7281da177e4SLinus Torvalds 				else
7291da177e4SLinus Torvalds 					changeValue(item);
7301da177e4SLinus Torvalds 			}
7311da177e4SLinus Torvalds 		}
7321da177e4SLinus Torvalds 		break;
7331da177e4SLinus Torvalds 	case noColIdx:
7341da177e4SLinus Torvalds 		setValue(item, no);
7351da177e4SLinus Torvalds 		break;
7361da177e4SLinus Torvalds 	case modColIdx:
7371da177e4SLinus Torvalds 		setValue(item, mod);
7381da177e4SLinus Torvalds 		break;
7391da177e4SLinus Torvalds 	case yesColIdx:
7401da177e4SLinus Torvalds 		setValue(item, yes);
7411da177e4SLinus Torvalds 		break;
7421da177e4SLinus Torvalds 	case dataColIdx:
7431da177e4SLinus Torvalds 		changeValue(item);
7441da177e4SLinus Torvalds 		break;
7451da177e4SLinus Torvalds 	}
7461da177e4SLinus Torvalds 
7471da177e4SLinus Torvalds skip:
7481da177e4SLinus Torvalds 	//printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
7491da177e4SLinus Torvalds 	Parent::contentsMouseReleaseEvent(e);
7501da177e4SLinus Torvalds }
7511da177e4SLinus Torvalds 
7521da177e4SLinus Torvalds void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
7531da177e4SLinus Torvalds {
7541da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
7551da177e4SLinus Torvalds 	//printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
7561da177e4SLinus Torvalds 	Parent::contentsMouseMoveEvent(e);
7571da177e4SLinus Torvalds }
7581da177e4SLinus Torvalds 
7591da177e4SLinus Torvalds void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
7601da177e4SLinus Torvalds {
7611da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
7621da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
7631da177e4SLinus Torvalds 	struct menu *menu;
7641da177e4SLinus Torvalds 	enum prop_type ptype;
7651da177e4SLinus Torvalds 
7661da177e4SLinus Torvalds 	if (!item)
7671da177e4SLinus Torvalds 		goto skip;
7681da177e4SLinus Torvalds 	if (item->goParent) {
7691da177e4SLinus Torvalds 		emit parentSelected();
7701da177e4SLinus Torvalds 		goto skip;
7711da177e4SLinus Torvalds 	}
7721da177e4SLinus Torvalds 	menu = item->menu;
7731da177e4SLinus Torvalds 	if (!menu)
7741da177e4SLinus Torvalds 		goto skip;
7751da177e4SLinus Torvalds 	ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7761da177e4SLinus Torvalds 	if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
7771da177e4SLinus Torvalds 		emit menuSelected(menu);
7781da177e4SLinus Torvalds 	else if (menu->sym)
7791da177e4SLinus Torvalds 		changeValue(item);
7801da177e4SLinus Torvalds 
7811da177e4SLinus Torvalds skip:
7821da177e4SLinus Torvalds 	//printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
7831da177e4SLinus Torvalds 	Parent::contentsMouseDoubleClickEvent(e);
7841da177e4SLinus Torvalds }
7851da177e4SLinus Torvalds 
7861da177e4SLinus Torvalds void ConfigList::focusInEvent(QFocusEvent *e)
7871da177e4SLinus Torvalds {
788b65a47e1SRoman Zippel 	struct menu *menu = NULL;
789b65a47e1SRoman Zippel 
7901da177e4SLinus Torvalds 	Parent::focusInEvent(e);
7911da177e4SLinus Torvalds 
792b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem *)currentItem();
793b65a47e1SRoman Zippel 	if (item) {
7941da177e4SLinus Torvalds 		setSelected(item, TRUE);
795b65a47e1SRoman Zippel 		menu = item->menu;
796b65a47e1SRoman Zippel 	}
797b65a47e1SRoman Zippel 	emit gotFocus(menu);
7981da177e4SLinus Torvalds }
7991da177e4SLinus Torvalds 
8007fc925fdSRoman Zippel void ConfigList::contextMenuEvent(QContextMenuEvent *e)
8017fc925fdSRoman Zippel {
8027fc925fdSRoman Zippel 	if (e->y() <= header()->geometry().bottom()) {
8037fc925fdSRoman Zippel 		if (!headerPopup) {
8047fc925fdSRoman Zippel 			QAction *action;
8057fc925fdSRoman Zippel 
8067fc925fdSRoman Zippel 			headerPopup = new QPopupMenu(this);
807c21a2d95SEGRY Gabor 			action = new QAction(NULL, _("Show Name"), 0, this);
8087fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8097fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8107fc925fdSRoman Zippel 				  parent(), SLOT(setShowName(bool)));
8117fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showNameChanged(bool)),
8127fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8137fc925fdSRoman Zippel 			  action->setOn(showName);
8147fc925fdSRoman Zippel 			  action->addTo(headerPopup);
815c21a2d95SEGRY Gabor 			action = new QAction(NULL, _("Show Range"), 0, this);
8167fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8177fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8187fc925fdSRoman Zippel 				  parent(), SLOT(setShowRange(bool)));
8197fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showRangeChanged(bool)),
8207fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8217fc925fdSRoman Zippel 			  action->setOn(showRange);
8227fc925fdSRoman Zippel 			  action->addTo(headerPopup);
823c21a2d95SEGRY Gabor 			action = new QAction(NULL, _("Show Data"), 0, this);
8247fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8257fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8267fc925fdSRoman Zippel 				  parent(), SLOT(setShowData(bool)));
8277fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showDataChanged(bool)),
8287fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8297fc925fdSRoman Zippel 			  action->setOn(showData);
8307fc925fdSRoman Zippel 			  action->addTo(headerPopup);
8317fc925fdSRoman Zippel 		}
8327fc925fdSRoman Zippel 		headerPopup->exec(e->globalPos());
8337fc925fdSRoman Zippel 		e->accept();
8347fc925fdSRoman Zippel 	} else
8357fc925fdSRoman Zippel 		e->ignore();
8367fc925fdSRoman Zippel }
8377fc925fdSRoman Zippel 
8381da177e4SLinus Torvalds ConfigView* ConfigView::viewList;
8391da177e4SLinus Torvalds 
8407fc925fdSRoman Zippel ConfigView::ConfigView(QWidget* parent, const char *name)
8417fc925fdSRoman Zippel 	: Parent(parent, name)
8421da177e4SLinus Torvalds {
8437fc925fdSRoman Zippel 	list = new ConfigList(this, name);
8441da177e4SLinus Torvalds 	lineEdit = new ConfigLineEdit(this);
8451da177e4SLinus Torvalds 	lineEdit->hide();
8461da177e4SLinus Torvalds 
8471da177e4SLinus Torvalds 	this->nextView = viewList;
8481da177e4SLinus Torvalds 	viewList = this;
8491da177e4SLinus Torvalds }
8501da177e4SLinus Torvalds 
8511da177e4SLinus Torvalds ConfigView::~ConfigView(void)
8521da177e4SLinus Torvalds {
8531da177e4SLinus Torvalds 	ConfigView** vp;
8541da177e4SLinus Torvalds 
8551da177e4SLinus Torvalds 	for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
8561da177e4SLinus Torvalds 		if (*vp == this) {
8571da177e4SLinus Torvalds 			*vp = nextView;
8581da177e4SLinus Torvalds 			break;
8591da177e4SLinus Torvalds 		}
8601da177e4SLinus Torvalds 	}
8611da177e4SLinus Torvalds }
8621da177e4SLinus Torvalds 
8637fc925fdSRoman Zippel void ConfigView::setShowAll(bool b)
8647fc925fdSRoman Zippel {
8657fc925fdSRoman Zippel 	if (list->showAll != b) {
8667fc925fdSRoman Zippel 		list->showAll = b;
8677fc925fdSRoman Zippel 		list->updateListAll();
8687fc925fdSRoman Zippel 		emit showAllChanged(b);
8697fc925fdSRoman Zippel 	}
8707fc925fdSRoman Zippel }
8717fc925fdSRoman Zippel 
8727fc925fdSRoman Zippel void ConfigView::setShowName(bool b)
8737fc925fdSRoman Zippel {
8747fc925fdSRoman Zippel 	if (list->showName != b) {
8757fc925fdSRoman Zippel 		list->showName = b;
8767fc925fdSRoman Zippel 		list->reinit();
8777fc925fdSRoman Zippel 		emit showNameChanged(b);
8787fc925fdSRoman Zippel 	}
8797fc925fdSRoman Zippel }
8807fc925fdSRoman Zippel 
8817fc925fdSRoman Zippel void ConfigView::setShowRange(bool b)
8827fc925fdSRoman Zippel {
8837fc925fdSRoman Zippel 	if (list->showRange != b) {
8847fc925fdSRoman Zippel 		list->showRange = b;
8857fc925fdSRoman Zippel 		list->reinit();
8867fc925fdSRoman Zippel 		emit showRangeChanged(b);
8877fc925fdSRoman Zippel 	}
8887fc925fdSRoman Zippel }
8897fc925fdSRoman Zippel 
8907fc925fdSRoman Zippel void ConfigView::setShowData(bool b)
8917fc925fdSRoman Zippel {
8927fc925fdSRoman Zippel 	if (list->showData != b) {
8937fc925fdSRoman Zippel 		list->showData = b;
8947fc925fdSRoman Zippel 		list->reinit();
8957fc925fdSRoman Zippel 		emit showDataChanged(b);
8967fc925fdSRoman Zippel 	}
8977fc925fdSRoman Zippel }
8987fc925fdSRoman Zippel 
8997fc925fdSRoman Zippel void ConfigList::setAllOpen(bool open)
9007fc925fdSRoman Zippel {
9017fc925fdSRoman Zippel 	QListViewItemIterator it(this);
9027fc925fdSRoman Zippel 
9037fc925fdSRoman Zippel 	for (; it.current(); it++)
9047fc925fdSRoman Zippel 		it.current()->setOpen(open);
9057fc925fdSRoman Zippel }
9067fc925fdSRoman Zippel 
9071da177e4SLinus Torvalds void ConfigView::updateList(ConfigItem* item)
9081da177e4SLinus Torvalds {
9091da177e4SLinus Torvalds 	ConfigView* v;
9101da177e4SLinus Torvalds 
9111da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9121da177e4SLinus Torvalds 		v->list->updateList(item);
9131da177e4SLinus Torvalds }
9141da177e4SLinus Torvalds 
9151da177e4SLinus Torvalds void ConfigView::updateListAll(void)
9161da177e4SLinus Torvalds {
9171da177e4SLinus Torvalds 	ConfigView* v;
9181da177e4SLinus Torvalds 
9191da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9201da177e4SLinus Torvalds 		v->list->updateListAll();
9211da177e4SLinus Torvalds }
9221da177e4SLinus Torvalds 
92343bf612aSRoman Zippel ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
92498403a91SMarkus Heidelberg 	: Parent(parent, name), sym(0), menu(0)
9251da177e4SLinus Torvalds {
9267fc925fdSRoman Zippel 	if (name) {
9277fc925fdSRoman Zippel 		configSettings->beginGroup(name);
9287fc925fdSRoman Zippel 		_showDebug = configSettings->readBoolEntry("/showDebug", false);
9297fc925fdSRoman Zippel 		configSettings->endGroup();
9307fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
9317fc925fdSRoman Zippel 	}
9327fc925fdSRoman Zippel }
9337fc925fdSRoman Zippel 
9347fc925fdSRoman Zippel void ConfigInfoView::saveSettings(void)
9357fc925fdSRoman Zippel {
9367fc925fdSRoman Zippel 	if (name()) {
9377fc925fdSRoman Zippel 		configSettings->beginGroup(name());
9387fc925fdSRoman Zippel 		configSettings->writeEntry("/showDebug", showDebug());
9397fc925fdSRoman Zippel 		configSettings->endGroup();
9407fc925fdSRoman Zippel 	}
9411da177e4SLinus Torvalds }
9421da177e4SLinus Torvalds 
94343bf612aSRoman Zippel void ConfigInfoView::setShowDebug(bool b)
9441da177e4SLinus Torvalds {
94543bf612aSRoman Zippel 	if (_showDebug != b) {
94643bf612aSRoman Zippel 		_showDebug = b;
94743bf612aSRoman Zippel 		if (menu)
94843bf612aSRoman Zippel 			menuInfo();
949ab45d190SRoman Zippel 		else if (sym)
950ab45d190SRoman Zippel 			symbolInfo();
95143bf612aSRoman Zippel 		emit showDebugChanged(b);
9521da177e4SLinus Torvalds 	}
9531da177e4SLinus Torvalds }
9541da177e4SLinus Torvalds 
95543bf612aSRoman Zippel void ConfigInfoView::setInfo(struct menu *m)
9561da177e4SLinus Torvalds {
957b65a47e1SRoman Zippel 	if (menu == m)
958b65a47e1SRoman Zippel 		return;
95943bf612aSRoman Zippel 	menu = m;
9606fa1da8eSRoman Zippel 	sym = NULL;
9616fa1da8eSRoman Zippel 	if (!menu)
96243bf612aSRoman Zippel 		clear();
9636fa1da8eSRoman Zippel 	else
96443bf612aSRoman Zippel 		menuInfo();
9651da177e4SLinus Torvalds }
9661da177e4SLinus Torvalds 
96743bf612aSRoman Zippel void ConfigInfoView::setSource(const QString& name)
96843bf612aSRoman Zippel {
96943bf612aSRoman Zippel 	const char *p = name.latin1();
97043bf612aSRoman Zippel 
97143bf612aSRoman Zippel 	menu = NULL;
972ab45d190SRoman Zippel 	sym = NULL;
97343bf612aSRoman Zippel 
97443bf612aSRoman Zippel 	switch (p[0]) {
97543bf612aSRoman Zippel 	case 'm':
976ab45d190SRoman Zippel 		struct menu *m;
977ab45d190SRoman Zippel 
978ab45d190SRoman Zippel 		if (sscanf(p, "m%p", &m) == 1 && menu != m) {
979ab45d190SRoman Zippel 			menu = m;
98043bf612aSRoman Zippel 			menuInfo();
981b65a47e1SRoman Zippel 			emit menuSelected(menu);
982ab45d190SRoman Zippel 		}
983ab45d190SRoman Zippel 		break;
984ab45d190SRoman Zippel 	case 's':
985ab45d190SRoman Zippel 		struct symbol *s;
986ab45d190SRoman Zippel 
987ab45d190SRoman Zippel 		if (sscanf(p, "s%p", &s) == 1 && sym != s) {
988ab45d190SRoman Zippel 			sym = s;
989ab45d190SRoman Zippel 			symbolInfo();
990ab45d190SRoman Zippel 		}
99143bf612aSRoman Zippel 		break;
99243bf612aSRoman Zippel 	}
99343bf612aSRoman Zippel }
99443bf612aSRoman Zippel 
995ab45d190SRoman Zippel void ConfigInfoView::symbolInfo(void)
996ab45d190SRoman Zippel {
997ab45d190SRoman Zippel 	QString str;
998ab45d190SRoman Zippel 
999ab45d190SRoman Zippel 	str += "<big>Symbol: <b>";
1000ab45d190SRoman Zippel 	str += print_filter(sym->name);
1001ab45d190SRoman Zippel 	str += "</b></big><br><br>value: ";
1002ab45d190SRoman Zippel 	str += print_filter(sym_get_string_value(sym));
1003ab45d190SRoman Zippel 	str += "<br>visibility: ";
1004ab45d190SRoman Zippel 	str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1005ab45d190SRoman Zippel 	str += "<br>";
1006ab45d190SRoman Zippel 	str += debug_info(sym);
1007ab45d190SRoman Zippel 
1008ab45d190SRoman Zippel 	setText(str);
1009ab45d190SRoman Zippel }
1010ab45d190SRoman Zippel 
101143bf612aSRoman Zippel void ConfigInfoView::menuInfo(void)
10121da177e4SLinus Torvalds {
10131da177e4SLinus Torvalds 	struct symbol* sym;
10141da177e4SLinus Torvalds 	QString head, debug, help;
101543bf612aSRoman Zippel 
10161da177e4SLinus Torvalds 	sym = menu->sym;
10171da177e4SLinus Torvalds 	if (sym) {
10181da177e4SLinus Torvalds 		if (menu->prompt) {
10191da177e4SLinus Torvalds 			head += "<big><b>";
10203b9fa093SArnaldo Carvalho de Melo 			head += print_filter(_(menu->prompt->text));
10211da177e4SLinus Torvalds 			head += "</b></big>";
10221da177e4SLinus Torvalds 			if (sym->name) {
10231da177e4SLinus Torvalds 				head += " (";
1024ab45d190SRoman Zippel 				if (showDebug())
1025ab45d190SRoman Zippel 					head += QString().sprintf("<a href=\"s%p\">", sym);
102643bf612aSRoman Zippel 				head += print_filter(sym->name);
1027ab45d190SRoman Zippel 				if (showDebug())
1028ab45d190SRoman Zippel 					head += "</a>";
10291da177e4SLinus Torvalds 				head += ")";
10301da177e4SLinus Torvalds 			}
10311da177e4SLinus Torvalds 		} else if (sym->name) {
10321da177e4SLinus Torvalds 			head += "<big><b>";
1033ab45d190SRoman Zippel 			if (showDebug())
1034ab45d190SRoman Zippel 				head += QString().sprintf("<a href=\"s%p\">", sym);
103543bf612aSRoman Zippel 			head += print_filter(sym->name);
1036ab45d190SRoman Zippel 			if (showDebug())
1037ab45d190SRoman Zippel 				head += "</a>";
10381da177e4SLinus Torvalds 			head += "</b></big>";
10391da177e4SLinus Torvalds 		}
10401da177e4SLinus Torvalds 		head += "<br><br>";
10411da177e4SLinus Torvalds 
104243bf612aSRoman Zippel 		if (showDebug())
104343bf612aSRoman Zippel 			debug = debug_info(sym);
104443bf612aSRoman Zippel 
1045c21a2d95SEGRY Gabor 		help = menu_get_help(menu);
1046c21a2d95SEGRY Gabor 		/* Gettextize if the help text not empty */
1047c21a2d95SEGRY Gabor 		if (help.isEmpty())
1048c21a2d95SEGRY Gabor 			help = print_filter(menu_get_help(menu));
1049c21a2d95SEGRY Gabor 		else
105003d29122SSam Ravnborg 			help = print_filter(_(menu_get_help(menu)));
105143bf612aSRoman Zippel 	} else if (menu->prompt) {
105243bf612aSRoman Zippel 		head += "<big><b>";
105343bf612aSRoman Zippel 		head += print_filter(_(menu->prompt->text));
105443bf612aSRoman Zippel 		head += "</b></big><br><br>";
105543bf612aSRoman Zippel 		if (showDebug()) {
105643bf612aSRoman Zippel 			if (menu->prompt->visible.expr) {
105743bf612aSRoman Zippel 				debug += "&nbsp;&nbsp;dep: ";
105843bf612aSRoman Zippel 				expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
105943bf612aSRoman Zippel 				debug += "<br><br>";
106043bf612aSRoman Zippel 			}
106143bf612aSRoman Zippel 		}
106243bf612aSRoman Zippel 	}
106343bf612aSRoman Zippel 	if (showDebug())
106443bf612aSRoman Zippel 		debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno);
106543bf612aSRoman Zippel 
106643bf612aSRoman Zippel 	setText(head + debug + help);
106743bf612aSRoman Zippel }
106843bf612aSRoman Zippel 
106943bf612aSRoman Zippel QString ConfigInfoView::debug_info(struct symbol *sym)
107043bf612aSRoman Zippel {
107143bf612aSRoman Zippel 	QString debug;
107243bf612aSRoman Zippel 
10731da177e4SLinus Torvalds 	debug += "type: ";
10741da177e4SLinus Torvalds 	debug += print_filter(sym_type_name(sym->type));
10751da177e4SLinus Torvalds 	if (sym_is_choice(sym))
10761da177e4SLinus Torvalds 		debug += " (choice)";
10771da177e4SLinus Torvalds 	debug += "<br>";
10781da177e4SLinus Torvalds 	if (sym->rev_dep.expr) {
10791da177e4SLinus Torvalds 		debug += "reverse dep: ";
10801da177e4SLinus Torvalds 		expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
10811da177e4SLinus Torvalds 		debug += "<br>";
10821da177e4SLinus Torvalds 	}
10831da177e4SLinus Torvalds 	for (struct property *prop = sym->prop; prop; prop = prop->next) {
10841da177e4SLinus Torvalds 		switch (prop->type) {
10851da177e4SLinus Torvalds 		case P_PROMPT:
10861da177e4SLinus Torvalds 		case P_MENU:
1087ab45d190SRoman Zippel 			debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
10883b9fa093SArnaldo Carvalho de Melo 			debug += print_filter(_(prop->text));
1089ab45d190SRoman Zippel 			debug += "</a><br>";
10901da177e4SLinus Torvalds 			break;
10911da177e4SLinus Torvalds 		case P_DEFAULT:
109293449082SRoman Zippel 		case P_SELECT:
109393449082SRoman Zippel 		case P_RANGE:
109493449082SRoman Zippel 		case P_ENV:
109593449082SRoman Zippel 			debug += prop_get_type_name(prop->type);
109693449082SRoman Zippel 			debug += ": ";
10971da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10981da177e4SLinus Torvalds 			debug += "<br>";
10991da177e4SLinus Torvalds 			break;
11001da177e4SLinus Torvalds 		case P_CHOICE:
11011da177e4SLinus Torvalds 			if (sym_is_choice(sym)) {
11021da177e4SLinus Torvalds 				debug += "choice: ";
11031da177e4SLinus Torvalds 				expr_print(prop->expr, expr_print_help, &debug, E_NONE);
11041da177e4SLinus Torvalds 				debug += "<br>";
11051da177e4SLinus Torvalds 			}
11061da177e4SLinus Torvalds 			break;
11071da177e4SLinus Torvalds 		default:
11081da177e4SLinus Torvalds 			debug += "unknown property: ";
11091da177e4SLinus Torvalds 			debug += prop_get_type_name(prop->type);
11101da177e4SLinus Torvalds 			debug += "<br>";
11111da177e4SLinus Torvalds 		}
11121da177e4SLinus Torvalds 		if (prop->visible.expr) {
11131da177e4SLinus Torvalds 			debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
11141da177e4SLinus Torvalds 			expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
11151da177e4SLinus Torvalds 			debug += "<br>";
11161da177e4SLinus Torvalds 		}
11171da177e4SLinus Torvalds 	}
11181da177e4SLinus Torvalds 	debug += "<br>";
111943bf612aSRoman Zippel 
112043bf612aSRoman Zippel 	return debug;
11211da177e4SLinus Torvalds }
11221da177e4SLinus Torvalds 
112343bf612aSRoman Zippel QString ConfigInfoView::print_filter(const QString &str)
112443bf612aSRoman Zippel {
112543bf612aSRoman Zippel 	QRegExp re("[<>&\"\\n]");
112643bf612aSRoman Zippel 	QString res = str;
112743bf612aSRoman Zippel 	for (int i = 0; (i = res.find(re, i)) >= 0;) {
112843bf612aSRoman Zippel 		switch (res[i].latin1()) {
112943bf612aSRoman Zippel 		case '<':
113043bf612aSRoman Zippel 			res.replace(i, 1, "&lt;");
113143bf612aSRoman Zippel 			i += 4;
113243bf612aSRoman Zippel 			break;
113343bf612aSRoman Zippel 		case '>':
113443bf612aSRoman Zippel 			res.replace(i, 1, "&gt;");
113543bf612aSRoman Zippel 			i += 4;
113643bf612aSRoman Zippel 			break;
113743bf612aSRoman Zippel 		case '&':
113843bf612aSRoman Zippel 			res.replace(i, 1, "&amp;");
113943bf612aSRoman Zippel 			i += 5;
114043bf612aSRoman Zippel 			break;
114143bf612aSRoman Zippel 		case '"':
114243bf612aSRoman Zippel 			res.replace(i, 1, "&quot;");
114343bf612aSRoman Zippel 			i += 6;
114443bf612aSRoman Zippel 			break;
114543bf612aSRoman Zippel 		case '\n':
114643bf612aSRoman Zippel 			res.replace(i, 1, "<br>");
114743bf612aSRoman Zippel 			i += 4;
114843bf612aSRoman Zippel 			break;
11491da177e4SLinus Torvalds 		}
11501da177e4SLinus Torvalds 	}
115143bf612aSRoman Zippel 	return res;
11521da177e4SLinus Torvalds }
115343bf612aSRoman Zippel 
1154ab45d190SRoman Zippel void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
115543bf612aSRoman Zippel {
1156ab45d190SRoman Zippel 	QString* text = reinterpret_cast<QString*>(data);
1157ab45d190SRoman Zippel 	QString str2 = print_filter(str);
1158ab45d190SRoman Zippel 
1159ab45d190SRoman Zippel 	if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1160ab45d190SRoman Zippel 		*text += QString().sprintf("<a href=\"s%p\">", sym);
1161ab45d190SRoman Zippel 		*text += str2;
1162ab45d190SRoman Zippel 		*text += "</a>";
1163ab45d190SRoman Zippel 	} else
1164ab45d190SRoman Zippel 		*text += str2;
116543bf612aSRoman Zippel }
116643bf612aSRoman Zippel 
11677fc925fdSRoman Zippel QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
11687fc925fdSRoman Zippel {
11697fc925fdSRoman Zippel 	QPopupMenu* popup = Parent::createPopupMenu(pos);
1170c21a2d95SEGRY Gabor 	QAction* action = new QAction(NULL, _("Show Debug Info"), 0, popup);
11717fc925fdSRoman Zippel 	  action->setToggleAction(TRUE);
11727fc925fdSRoman Zippel 	  connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
11737fc925fdSRoman Zippel 	  connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
11747fc925fdSRoman Zippel 	  action->setOn(showDebug());
11757fc925fdSRoman Zippel 	popup->insertSeparator();
11767fc925fdSRoman Zippel 	action->addTo(popup);
11777fc925fdSRoman Zippel 	return popup;
11787fc925fdSRoman Zippel }
11797fc925fdSRoman Zippel 
11807fc925fdSRoman Zippel void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
11817fc925fdSRoman Zippel {
11827fc925fdSRoman Zippel 	Parent::contentsContextMenuEvent(e);
11837fc925fdSRoman Zippel }
11847fc925fdSRoman Zippel 
118563431e75SMarco Costalba ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
11867fc925fdSRoman Zippel 	: Parent(parent, name), result(NULL)
118743bf612aSRoman Zippel {
118843bf612aSRoman Zippel 	setCaption("Search Config");
118943bf612aSRoman Zippel 
119043bf612aSRoman Zippel 	QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
119143bf612aSRoman Zippel 	QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
1192c21a2d95SEGRY Gabor 	layout2->addWidget(new QLabel(_("Find:"), this));
119343bf612aSRoman Zippel 	editField = new QLineEdit(this);
119443bf612aSRoman Zippel 	connect(editField, SIGNAL(returnPressed()), SLOT(search()));
119543bf612aSRoman Zippel 	layout2->addWidget(editField);
1196c21a2d95SEGRY Gabor 	searchButton = new QPushButton(_("Search"), this);
119743bf612aSRoman Zippel 	searchButton->setAutoDefault(FALSE);
119843bf612aSRoman Zippel 	connect(searchButton, SIGNAL(clicked()), SLOT(search()));
119943bf612aSRoman Zippel 	layout2->addWidget(searchButton);
120043bf612aSRoman Zippel 	layout1->addLayout(layout2);
120143bf612aSRoman Zippel 
12027fc925fdSRoman Zippel 	split = new QSplitter(this);
12037298b936SMarkus Heidelberg 	split->setOrientation(Qt::Vertical);
12047fc925fdSRoman Zippel 	list = new ConfigView(split, name);
120543bf612aSRoman Zippel 	list->list->mode = listMode;
12067fc925fdSRoman Zippel 	info = new ConfigInfoView(split, name);
120743bf612aSRoman Zippel 	connect(list->list, SIGNAL(menuChanged(struct menu *)),
120843bf612aSRoman Zippel 		info, SLOT(setInfo(struct menu *)));
120963431e75SMarco Costalba 	connect(list->list, SIGNAL(menuChanged(struct menu *)),
121063431e75SMarco Costalba 		parent, SLOT(setMenuLink(struct menu *)));
121163431e75SMarco Costalba 
121243bf612aSRoman Zippel 	layout1->addWidget(split);
12137fc925fdSRoman Zippel 
12147fc925fdSRoman Zippel 	if (name) {
12157fc925fdSRoman Zippel 		int x, y, width, height;
12167fc925fdSRoman Zippel 		bool ok;
12177fc925fdSRoman Zippel 
12187fc925fdSRoman Zippel 		configSettings->beginGroup(name);
12197fc925fdSRoman Zippel 		width = configSettings->readNumEntry("/window width", parent->width() / 2);
12207fc925fdSRoman Zippel 		height = configSettings->readNumEntry("/window height", parent->height() / 2);
12217fc925fdSRoman Zippel 		resize(width, height);
12227fc925fdSRoman Zippel 		x = configSettings->readNumEntry("/window x", 0, &ok);
12237fc925fdSRoman Zippel 		if (ok)
12247fc925fdSRoman Zippel 			y = configSettings->readNumEntry("/window y", 0, &ok);
12257fc925fdSRoman Zippel 		if (ok)
12267fc925fdSRoman Zippel 			move(x, y);
12277fc925fdSRoman Zippel 		QValueList<int> sizes = configSettings->readSizes("/split", &ok);
12287fc925fdSRoman Zippel 		if (ok)
12297fc925fdSRoman Zippel 			split->setSizes(sizes);
12307fc925fdSRoman Zippel 		configSettings->endGroup();
12317fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
12327fc925fdSRoman Zippel 	}
12337fc925fdSRoman Zippel }
12347fc925fdSRoman Zippel 
12357fc925fdSRoman Zippel void ConfigSearchWindow::saveSettings(void)
12367fc925fdSRoman Zippel {
12377fc925fdSRoman Zippel 	if (name()) {
12387fc925fdSRoman Zippel 		configSettings->beginGroup(name());
12397fc925fdSRoman Zippel 		configSettings->writeEntry("/window x", pos().x());
12407fc925fdSRoman Zippel 		configSettings->writeEntry("/window y", pos().y());
12417fc925fdSRoman Zippel 		configSettings->writeEntry("/window width", size().width());
12427fc925fdSRoman Zippel 		configSettings->writeEntry("/window height", size().height());
12437fc925fdSRoman Zippel 		configSettings->writeSizes("/split", split->sizes());
12447fc925fdSRoman Zippel 		configSettings->endGroup();
12457fc925fdSRoman Zippel 	}
124643bf612aSRoman Zippel }
124743bf612aSRoman Zippel 
124843bf612aSRoman Zippel void ConfigSearchWindow::search(void)
124943bf612aSRoman Zippel {
125043bf612aSRoman Zippel 	struct symbol **p;
125143bf612aSRoman Zippel 	struct property *prop;
125243bf612aSRoman Zippel 	ConfigItem *lastItem = NULL;
125343bf612aSRoman Zippel 
125443bf612aSRoman Zippel 	free(result);
125543bf612aSRoman Zippel 	list->list->clear();
1256786fb18dSCyrill V. Gorcunov 	info->clear();
125743bf612aSRoman Zippel 
125843bf612aSRoman Zippel 	result = sym_re_search(editField->text().latin1());
125943bf612aSRoman Zippel 	if (!result)
126043bf612aSRoman Zippel 		return;
126143bf612aSRoman Zippel 	for (p = result; *p; p++) {
126243bf612aSRoman Zippel 		for_all_prompts((*p), prop)
126343bf612aSRoman Zippel 			lastItem = new ConfigItem(list->list, lastItem, prop->menu,
126443bf612aSRoman Zippel 						  menu_is_visible(prop->menu));
126543bf612aSRoman Zippel 	}
126643bf612aSRoman Zippel }
126743bf612aSRoman Zippel 
126843bf612aSRoman Zippel /*
126943bf612aSRoman Zippel  * Construct the complete config widget
127043bf612aSRoman Zippel  */
127143bf612aSRoman Zippel ConfigMainWindow::ConfigMainWindow(void)
1272f12aa704SRoman Zippel 	: searchWindow(0)
127343bf612aSRoman Zippel {
127443bf612aSRoman Zippel 	QMenuBar* menu;
12757fc925fdSRoman Zippel 	bool ok;
127643bf612aSRoman Zippel 	int x, y, width, height;
1277a54bb701SRandy Dunlap 	char title[256];
127843bf612aSRoman Zippel 
12798d90c97eSMarkus Heidelberg 	QDesktopWidget *d = configApp->desktop();
1280a54bb701SRandy Dunlap 	snprintf(title, sizeof(title), _("Linux Kernel v%s Configuration"),
1281a54bb701SRandy Dunlap 		getenv("KERNELVERSION"));
1282a54bb701SRandy Dunlap 	setCaption(title);
128343bf612aSRoman Zippel 
12847fc925fdSRoman Zippel 	width = configSettings->readNumEntry("/window width", d->width() - 64);
12857fc925fdSRoman Zippel 	height = configSettings->readNumEntry("/window height", d->height() - 64);
128643bf612aSRoman Zippel 	resize(width, height);
12877fc925fdSRoman Zippel 	x = configSettings->readNumEntry("/window x", 0, &ok);
128843bf612aSRoman Zippel 	if (ok)
12897fc925fdSRoman Zippel 		y = configSettings->readNumEntry("/window y", 0, &ok);
129043bf612aSRoman Zippel 	if (ok)
129143bf612aSRoman Zippel 		move(x, y);
129243bf612aSRoman Zippel 
129343bf612aSRoman Zippel 	split1 = new QSplitter(this);
12947298b936SMarkus Heidelberg 	split1->setOrientation(Qt::Horizontal);
129543bf612aSRoman Zippel 	setCentralWidget(split1);
129643bf612aSRoman Zippel 
12977fc925fdSRoman Zippel 	menuView = new ConfigView(split1, "menu");
129843bf612aSRoman Zippel 	menuList = menuView->list;
129943bf612aSRoman Zippel 
130043bf612aSRoman Zippel 	split2 = new QSplitter(split1);
13017298b936SMarkus Heidelberg 	split2->setOrientation(Qt::Vertical);
130243bf612aSRoman Zippel 
130343bf612aSRoman Zippel 	// create config tree
13047fc925fdSRoman Zippel 	configView = new ConfigView(split2, "config");
130543bf612aSRoman Zippel 	configList = configView->list;
130643bf612aSRoman Zippel 
13077fc925fdSRoman Zippel 	helpText = new ConfigInfoView(split2, "help");
130843bf612aSRoman Zippel 	helpText->setTextFormat(Qt::RichText);
130943bf612aSRoman Zippel 
131043bf612aSRoman Zippel 	setTabOrder(configList, helpText);
131143bf612aSRoman Zippel 	configList->setFocus();
131243bf612aSRoman Zippel 
131343bf612aSRoman Zippel 	menu = menuBar();
131443bf612aSRoman Zippel 	toolBar = new QToolBar("Tools", this);
131543bf612aSRoman Zippel 
1316c21a2d95SEGRY Gabor 	backAction = new QAction("Back", QPixmap(xpm_back), _("Back"), 0, this);
131743bf612aSRoman Zippel 	  connect(backAction, SIGNAL(activated()), SLOT(goBack()));
131843bf612aSRoman Zippel 	  backAction->setEnabled(FALSE);
1319fbb86374SMarkus Heidelberg 	QAction *quitAction = new QAction("Quit", _("&Quit"), Qt::CTRL + Qt::Key_Q, this);
132043bf612aSRoman Zippel 	  connect(quitAction, SIGNAL(activated()), SLOT(close()));
1321fbb86374SMarkus Heidelberg 	QAction *loadAction = new QAction("Load", QPixmap(xpm_load), _("&Load"), Qt::CTRL + Qt::Key_L, this);
132243bf612aSRoman Zippel 	  connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
1323fbb86374SMarkus Heidelberg 	saveAction = new QAction("Save", QPixmap(xpm_save), _("&Save"), Qt::CTRL + Qt::Key_S, this);
132443bf612aSRoman Zippel 	  connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
13253b354c55SKarsten Wiese 	conf_set_changed_callback(conf_changed);
13263b354c55SKarsten Wiese 	// Set saveAction's initial state
13273b354c55SKarsten Wiese 	conf_changed();
1328c21a2d95SEGRY Gabor 	QAction *saveAsAction = new QAction("Save As...", _("Save &As..."), 0, this);
132943bf612aSRoman Zippel 	  connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
1330fbb86374SMarkus Heidelberg 	QAction *searchAction = new QAction("Find", _("&Find"), Qt::CTRL + Qt::Key_F, this);
133143bf612aSRoman Zippel 	  connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
1332c21a2d95SEGRY Gabor 	QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), _("Single View"), 0, this);
133343bf612aSRoman Zippel 	  connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
1334c21a2d95SEGRY Gabor 	QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), _("Split View"), 0, this);
133543bf612aSRoman Zippel 	  connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
1336c21a2d95SEGRY Gabor 	QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), _("Full View"), 0, this);
133743bf612aSRoman Zippel 	  connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
133843bf612aSRoman Zippel 
1339c21a2d95SEGRY Gabor 	QAction *showNameAction = new QAction(NULL, _("Show Name"), 0, this);
134043bf612aSRoman Zippel 	  showNameAction->setToggleAction(TRUE);
13417fc925fdSRoman Zippel 	  connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
13427fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
13437fc925fdSRoman Zippel 	  showNameAction->setOn(configView->showName());
1344c21a2d95SEGRY Gabor 	QAction *showRangeAction = new QAction(NULL, _("Show Range"), 0, this);
134543bf612aSRoman Zippel 	  showRangeAction->setToggleAction(TRUE);
13467fc925fdSRoman Zippel 	  connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
13477fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
134843bf612aSRoman Zippel 	  showRangeAction->setOn(configList->showRange);
1349c21a2d95SEGRY Gabor 	QAction *showDataAction = new QAction(NULL, _("Show Data"), 0, this);
135043bf612aSRoman Zippel 	  showDataAction->setToggleAction(TRUE);
13517fc925fdSRoman Zippel 	  connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
13527fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
135343bf612aSRoman Zippel 	  showDataAction->setOn(configList->showData);
1354c21a2d95SEGRY Gabor 	QAction *showAllAction = new QAction(NULL, _("Show All Options"), 0, this);
135543bf612aSRoman Zippel 	  showAllAction->setToggleAction(TRUE);
13567fc925fdSRoman Zippel 	  connect(showAllAction, SIGNAL(toggled(bool)), configView, SLOT(setShowAll(bool)));
13577fc925fdSRoman Zippel 	  connect(showAllAction, SIGNAL(toggled(bool)), menuView, SLOT(setShowAll(bool)));
135843bf612aSRoman Zippel 	  showAllAction->setOn(configList->showAll);
1359c21a2d95SEGRY Gabor 	QAction *showDebugAction = new QAction(NULL, _("Show Debug Info"), 0, this);
136043bf612aSRoman Zippel 	  showDebugAction->setToggleAction(TRUE);
136143bf612aSRoman Zippel 	  connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
136243bf612aSRoman Zippel 	  connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
13637fc925fdSRoman Zippel 	  showDebugAction->setOn(helpText->showDebug());
136443bf612aSRoman Zippel 
1365c21a2d95SEGRY Gabor 	QAction *showIntroAction = new QAction(NULL, _("Introduction"), 0, this);
136643bf612aSRoman Zippel 	  connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
1367c21a2d95SEGRY Gabor 	QAction *showAboutAction = new QAction(NULL, _("About"), 0, this);
136843bf612aSRoman Zippel 	  connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
136943bf612aSRoman Zippel 
137043bf612aSRoman Zippel 	// init tool bar
137143bf612aSRoman Zippel 	backAction->addTo(toolBar);
137243bf612aSRoman Zippel 	toolBar->addSeparator();
137343bf612aSRoman Zippel 	loadAction->addTo(toolBar);
137443bf612aSRoman Zippel 	saveAction->addTo(toolBar);
137543bf612aSRoman Zippel 	toolBar->addSeparator();
137643bf612aSRoman Zippel 	singleViewAction->addTo(toolBar);
137743bf612aSRoman Zippel 	splitViewAction->addTo(toolBar);
137843bf612aSRoman Zippel 	fullViewAction->addTo(toolBar);
137943bf612aSRoman Zippel 
138043bf612aSRoman Zippel 	// create config menu
138143bf612aSRoman Zippel 	QPopupMenu* config = new QPopupMenu(this);
1382c21a2d95SEGRY Gabor 	menu->insertItem(_("&File"), config);
138343bf612aSRoman Zippel 	loadAction->addTo(config);
138443bf612aSRoman Zippel 	saveAction->addTo(config);
138543bf612aSRoman Zippel 	saveAsAction->addTo(config);
138643bf612aSRoman Zippel 	config->insertSeparator();
138743bf612aSRoman Zippel 	quitAction->addTo(config);
138843bf612aSRoman Zippel 
138966e7c723SShlomi Fish 	// create edit menu
139066e7c723SShlomi Fish 	QPopupMenu* editMenu = new QPopupMenu(this);
1391c21a2d95SEGRY Gabor 	menu->insertItem(_("&Edit"), editMenu);
139266e7c723SShlomi Fish 	searchAction->addTo(editMenu);
139366e7c723SShlomi Fish 
139443bf612aSRoman Zippel 	// create options menu
139543bf612aSRoman Zippel 	QPopupMenu* optionMenu = new QPopupMenu(this);
1396c21a2d95SEGRY Gabor 	menu->insertItem(_("&Option"), optionMenu);
139743bf612aSRoman Zippel 	showNameAction->addTo(optionMenu);
139843bf612aSRoman Zippel 	showRangeAction->addTo(optionMenu);
139943bf612aSRoman Zippel 	showDataAction->addTo(optionMenu);
140043bf612aSRoman Zippel 	optionMenu->insertSeparator();
140143bf612aSRoman Zippel 	showAllAction->addTo(optionMenu);
140243bf612aSRoman Zippel 	showDebugAction->addTo(optionMenu);
140343bf612aSRoman Zippel 
140443bf612aSRoman Zippel 	// create help menu
140543bf612aSRoman Zippel 	QPopupMenu* helpMenu = new QPopupMenu(this);
140643bf612aSRoman Zippel 	menu->insertSeparator();
1407c21a2d95SEGRY Gabor 	menu->insertItem(_("&Help"), helpMenu);
140843bf612aSRoman Zippel 	showIntroAction->addTo(helpMenu);
140943bf612aSRoman Zippel 	showAboutAction->addTo(helpMenu);
141043bf612aSRoman Zippel 
141143bf612aSRoman Zippel 	connect(configList, SIGNAL(menuChanged(struct menu *)),
141243bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
141343bf612aSRoman Zippel 	connect(configList, SIGNAL(menuSelected(struct menu *)),
141443bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
141543bf612aSRoman Zippel 	connect(configList, SIGNAL(parentSelected()),
141643bf612aSRoman Zippel 		SLOT(goBack()));
141743bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuChanged(struct menu *)),
141843bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
141943bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuSelected(struct menu *)),
142043bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
142143bf612aSRoman Zippel 
1422b65a47e1SRoman Zippel 	connect(configList, SIGNAL(gotFocus(struct menu *)),
1423b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1424b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
1425b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1426b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
142743bf612aSRoman Zippel 		SLOT(listFocusChanged(void)));
1428b65a47e1SRoman Zippel 	connect(helpText, SIGNAL(menuSelected(struct menu *)),
1429b65a47e1SRoman Zippel 		SLOT(setMenuLink(struct menu *)));
143043bf612aSRoman Zippel 
14317fc925fdSRoman Zippel 	QString listMode = configSettings->readEntry("/listMode", "symbol");
143243bf612aSRoman Zippel 	if (listMode == "single")
143343bf612aSRoman Zippel 		showSingleView();
143443bf612aSRoman Zippel 	else if (listMode == "full")
143543bf612aSRoman Zippel 		showFullView();
143643bf612aSRoman Zippel 	else /*if (listMode == "split")*/
143743bf612aSRoman Zippel 		showSplitView();
143843bf612aSRoman Zippel 
143943bf612aSRoman Zippel 	// UI setup done, restore splitter positions
14407fc925fdSRoman Zippel 	QValueList<int> sizes = configSettings->readSizes("/split1", &ok);
144143bf612aSRoman Zippel 	if (ok)
144243bf612aSRoman Zippel 		split1->setSizes(sizes);
144343bf612aSRoman Zippel 
14447fc925fdSRoman Zippel 	sizes = configSettings->readSizes("/split2", &ok);
144543bf612aSRoman Zippel 	if (ok)
144643bf612aSRoman Zippel 		split2->setSizes(sizes);
144743bf612aSRoman Zippel }
144843bf612aSRoman Zippel 
14491da177e4SLinus Torvalds void ConfigMainWindow::loadConfig(void)
14501da177e4SLinus Torvalds {
1451284026cdSMarkus Heidelberg 	QString s = QFileDialog::getOpenFileName(conf_get_configname(), NULL, this);
14521da177e4SLinus Torvalds 	if (s.isNull())
14531da177e4SLinus Torvalds 		return;
14543b9fa093SArnaldo Carvalho de Melo 	if (conf_read(QFile::encodeName(s)))
1455c21a2d95SEGRY Gabor 		QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
14561da177e4SLinus Torvalds 	ConfigView::updateListAll();
14571da177e4SLinus Torvalds }
14581da177e4SLinus Torvalds 
14591da177e4SLinus Torvalds void ConfigMainWindow::saveConfig(void)
14601da177e4SLinus Torvalds {
14611da177e4SLinus Torvalds 	if (conf_write(NULL))
1462c21a2d95SEGRY Gabor 		QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
14631da177e4SLinus Torvalds }
14641da177e4SLinus Torvalds 
14651da177e4SLinus Torvalds void ConfigMainWindow::saveConfigAs(void)
14661da177e4SLinus Torvalds {
1467284026cdSMarkus Heidelberg 	QString s = QFileDialog::getSaveFileName(conf_get_configname(), NULL, this);
14681da177e4SLinus Torvalds 	if (s.isNull())
14691da177e4SLinus Torvalds 		return;
14703b9fa093SArnaldo Carvalho de Melo 	if (conf_write(QFile::encodeName(s)))
1471c21a2d95SEGRY Gabor 		QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
14721da177e4SLinus Torvalds }
14731da177e4SLinus Torvalds 
147443bf612aSRoman Zippel void ConfigMainWindow::searchConfig(void)
147543bf612aSRoman Zippel {
147643bf612aSRoman Zippel 	if (!searchWindow)
14777fc925fdSRoman Zippel 		searchWindow = new ConfigSearchWindow(this, "search");
147843bf612aSRoman Zippel 	searchWindow->show();
147943bf612aSRoman Zippel }
148043bf612aSRoman Zippel 
14811da177e4SLinus Torvalds void ConfigMainWindow::changeMenu(struct menu *menu)
14821da177e4SLinus Torvalds {
14831da177e4SLinus Torvalds 	configList->setRootMenu(menu);
1484f253f000SCyrill V. Gorcunov 	if (configList->rootEntry->parent == &rootmenu)
1485f253f000SCyrill V. Gorcunov 		backAction->setEnabled(FALSE);
1486f253f000SCyrill V. Gorcunov 	else
14871da177e4SLinus Torvalds 		backAction->setEnabled(TRUE);
14881da177e4SLinus Torvalds }
14891da177e4SLinus Torvalds 
1490b65a47e1SRoman Zippel void ConfigMainWindow::setMenuLink(struct menu *menu)
1491b65a47e1SRoman Zippel {
1492b65a47e1SRoman Zippel 	struct menu *parent;
1493b65a47e1SRoman Zippel 	ConfigList* list = NULL;
1494b65a47e1SRoman Zippel 	ConfigItem* item;
1495b65a47e1SRoman Zippel 
1496b65a47e1SRoman Zippel 	if (!menu_is_visible(menu) && !configView->showAll())
1497b65a47e1SRoman Zippel 		return;
1498b65a47e1SRoman Zippel 
1499b65a47e1SRoman Zippel 	switch (configList->mode) {
1500b65a47e1SRoman Zippel 	case singleMode:
1501b65a47e1SRoman Zippel 		list = configList;
1502b65a47e1SRoman Zippel 		parent = menu_get_parent_menu(menu);
1503b65a47e1SRoman Zippel 		if (!parent)
1504b65a47e1SRoman Zippel 			return;
1505b65a47e1SRoman Zippel 		list->setRootMenu(parent);
1506b65a47e1SRoman Zippel 		break;
1507b65a47e1SRoman Zippel 	case symbolMode:
1508b65a47e1SRoman Zippel 		if (menu->flags & MENU_ROOT) {
1509b65a47e1SRoman Zippel 			configList->setRootMenu(menu);
1510b65a47e1SRoman Zippel 			configList->clearSelection();
1511b65a47e1SRoman Zippel 			list = menuList;
1512b65a47e1SRoman Zippel 		} else {
1513b65a47e1SRoman Zippel 			list = configList;
1514b65a47e1SRoman Zippel 			parent = menu_get_parent_menu(menu->parent);
1515b65a47e1SRoman Zippel 			if (!parent)
1516b65a47e1SRoman Zippel 				return;
1517b65a47e1SRoman Zippel 			item = menuList->findConfigItem(parent);
1518b65a47e1SRoman Zippel 			if (item) {
1519b65a47e1SRoman Zippel 				menuList->setSelected(item, TRUE);
1520b65a47e1SRoman Zippel 				menuList->ensureItemVisible(item);
1521b65a47e1SRoman Zippel 			}
1522b65a47e1SRoman Zippel 			list->setRootMenu(parent);
1523b65a47e1SRoman Zippel 		}
1524b65a47e1SRoman Zippel 		break;
1525b65a47e1SRoman Zippel 	case fullMode:
1526b65a47e1SRoman Zippel 		list = configList;
1527b65a47e1SRoman Zippel 		break;
152898403a91SMarkus Heidelberg 	default:
152998403a91SMarkus Heidelberg 		break;
1530b65a47e1SRoman Zippel 	}
1531b65a47e1SRoman Zippel 
1532b65a47e1SRoman Zippel 	if (list) {
1533b65a47e1SRoman Zippel 		item = list->findConfigItem(menu);
1534b65a47e1SRoman Zippel 		if (item) {
1535b65a47e1SRoman Zippel 			list->setSelected(item, TRUE);
1536b65a47e1SRoman Zippel 			list->ensureItemVisible(item);
1537b65a47e1SRoman Zippel 			list->setFocus();
1538b65a47e1SRoman Zippel 		}
1539b65a47e1SRoman Zippel 	}
1540b65a47e1SRoman Zippel }
1541b65a47e1SRoman Zippel 
15421da177e4SLinus Torvalds void ConfigMainWindow::listFocusChanged(void)
15431da177e4SLinus Torvalds {
15441da177e4SLinus Torvalds 	if (menuList->mode == menuMode)
15451da177e4SLinus Torvalds 		configList->clearSelection();
15461da177e4SLinus Torvalds }
15471da177e4SLinus Torvalds 
15481da177e4SLinus Torvalds void ConfigMainWindow::goBack(void)
15491da177e4SLinus Torvalds {
15501da177e4SLinus Torvalds 	ConfigItem* item;
15511da177e4SLinus Torvalds 
15521da177e4SLinus Torvalds 	configList->setParentMenu();
15531da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15541da177e4SLinus Torvalds 		backAction->setEnabled(FALSE);
15551da177e4SLinus Torvalds 	item = (ConfigItem*)menuList->selectedItem();
15561da177e4SLinus Torvalds 	while (item) {
15571da177e4SLinus Torvalds 		if (item->menu == configList->rootEntry) {
15581da177e4SLinus Torvalds 			menuList->setSelected(item, TRUE);
15591da177e4SLinus Torvalds 			break;
15601da177e4SLinus Torvalds 		}
15611da177e4SLinus Torvalds 		item = (ConfigItem*)item->parent();
15621da177e4SLinus Torvalds 	}
15631da177e4SLinus Torvalds }
15641da177e4SLinus Torvalds 
15651da177e4SLinus Torvalds void ConfigMainWindow::showSingleView(void)
15661da177e4SLinus Torvalds {
15671da177e4SLinus Torvalds 	menuView->hide();
15681da177e4SLinus Torvalds 	menuList->setRootMenu(0);
15691da177e4SLinus Torvalds 	configList->mode = singleMode;
15701da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15711da177e4SLinus Torvalds 		configList->updateListAll();
15721da177e4SLinus Torvalds 	else
15731da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15741da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
15751da177e4SLinus Torvalds 	configList->setFocus();
15761da177e4SLinus Torvalds }
15771da177e4SLinus Torvalds 
15781da177e4SLinus Torvalds void ConfigMainWindow::showSplitView(void)
15791da177e4SLinus Torvalds {
15801da177e4SLinus Torvalds 	configList->mode = symbolMode;
15811da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15821da177e4SLinus Torvalds 		configList->updateListAll();
15831da177e4SLinus Torvalds 	else
15841da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15851da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
15861da177e4SLinus Torvalds 	configApp->processEvents();
15871da177e4SLinus Torvalds 	menuList->mode = menuMode;
15881da177e4SLinus Torvalds 	menuList->setRootMenu(&rootmenu);
15891da177e4SLinus Torvalds 	menuList->setAllOpen(TRUE);
15901da177e4SLinus Torvalds 	menuView->show();
15911da177e4SLinus Torvalds 	menuList->setFocus();
15921da177e4SLinus Torvalds }
15931da177e4SLinus Torvalds 
15941da177e4SLinus Torvalds void ConfigMainWindow::showFullView(void)
15951da177e4SLinus Torvalds {
15961da177e4SLinus Torvalds 	menuView->hide();
15971da177e4SLinus Torvalds 	menuList->setRootMenu(0);
15981da177e4SLinus Torvalds 	configList->mode = fullMode;
15991da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
16001da177e4SLinus Torvalds 		configList->updateListAll();
16011da177e4SLinus Torvalds 	else
16021da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
16031da177e4SLinus Torvalds 	configList->setAllOpen(FALSE);
16041da177e4SLinus Torvalds 	configList->setFocus();
16051da177e4SLinus Torvalds }
16061da177e4SLinus Torvalds 
16071da177e4SLinus Torvalds /*
16081da177e4SLinus Torvalds  * ask for saving configuration before quitting
16091da177e4SLinus Torvalds  * TODO ask only when something changed
16101da177e4SLinus Torvalds  */
16111da177e4SLinus Torvalds void ConfigMainWindow::closeEvent(QCloseEvent* e)
16121da177e4SLinus Torvalds {
1613b3214293SKarsten Wiese 	if (!conf_get_changed()) {
16141da177e4SLinus Torvalds 		e->accept();
16151da177e4SLinus Torvalds 		return;
16161da177e4SLinus Torvalds 	}
1617c21a2d95SEGRY Gabor 	QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
16181da177e4SLinus Torvalds 			QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
1619c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1620c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1621c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
16221da177e4SLinus Torvalds 	switch (mb.exec()) {
16231da177e4SLinus Torvalds 	case QMessageBox::Yes:
16241da177e4SLinus Torvalds 		conf_write(NULL);
16251da177e4SLinus Torvalds 	case QMessageBox::No:
16261da177e4SLinus Torvalds 		e->accept();
16271da177e4SLinus Torvalds 		break;
16281da177e4SLinus Torvalds 	case QMessageBox::Cancel:
16291da177e4SLinus Torvalds 		e->ignore();
16301da177e4SLinus Torvalds 		break;
16311da177e4SLinus Torvalds 	}
16321da177e4SLinus Torvalds }
16331da177e4SLinus Torvalds 
16341da177e4SLinus Torvalds void ConfigMainWindow::showIntro(void)
16351da177e4SLinus Torvalds {
1636c21a2d95SEGRY Gabor 	static const QString str = _("Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
16371da177e4SLinus Torvalds 		"For each option, a blank box indicates the feature is disabled, a check\n"
16381da177e4SLinus Torvalds 		"indicates it is enabled, and a dot indicates that it is to be compiled\n"
16391da177e4SLinus Torvalds 		"as a module.  Clicking on the box will cycle through the three states.\n\n"
16401da177e4SLinus Torvalds 		"If you do not see an option (e.g., a device driver) that you believe\n"
16411da177e4SLinus Torvalds 		"should be present, try turning on Show All Options under the Options menu.\n"
16421da177e4SLinus Torvalds 		"Although there is no cross reference yet to help you figure out what other\n"
16431da177e4SLinus Torvalds 		"options must be enabled to support the option you are interested in, you can\n"
16441da177e4SLinus Torvalds 		"still view the help of a grayed-out option.\n\n"
16451da177e4SLinus Torvalds 		"Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1646c21a2d95SEGRY Gabor 		"which you can then match by examining other options.\n\n");
16471da177e4SLinus Torvalds 
16481da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16491da177e4SLinus Torvalds }
16501da177e4SLinus Torvalds 
16511da177e4SLinus Torvalds void ConfigMainWindow::showAbout(void)
16521da177e4SLinus Torvalds {
1653c21a2d95SEGRY Gabor 	static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1654c21a2d95SEGRY Gabor 		"Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
16551da177e4SLinus Torvalds 
16561da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16571da177e4SLinus Torvalds }
16581da177e4SLinus Torvalds 
16591da177e4SLinus Torvalds void ConfigMainWindow::saveSettings(void)
16601da177e4SLinus Torvalds {
16617fc925fdSRoman Zippel 	configSettings->writeEntry("/window x", pos().x());
16627fc925fdSRoman Zippel 	configSettings->writeEntry("/window y", pos().y());
16637fc925fdSRoman Zippel 	configSettings->writeEntry("/window width", size().width());
16647fc925fdSRoman Zippel 	configSettings->writeEntry("/window height", size().height());
16651da177e4SLinus Torvalds 
16661da177e4SLinus Torvalds 	QString entry;
16671da177e4SLinus Torvalds 	switch(configList->mode) {
16681da177e4SLinus Torvalds 	case singleMode :
16691da177e4SLinus Torvalds 		entry = "single";
16701da177e4SLinus Torvalds 		break;
16711da177e4SLinus Torvalds 
16721da177e4SLinus Torvalds 	case symbolMode :
16731da177e4SLinus Torvalds 		entry = "split";
16741da177e4SLinus Torvalds 		break;
16751da177e4SLinus Torvalds 
16761da177e4SLinus Torvalds 	case fullMode :
16771da177e4SLinus Torvalds 		entry = "full";
16781da177e4SLinus Torvalds 		break;
167998403a91SMarkus Heidelberg 
168098403a91SMarkus Heidelberg 	default:
168198403a91SMarkus Heidelberg 		break;
16821da177e4SLinus Torvalds 	}
16837fc925fdSRoman Zippel 	configSettings->writeEntry("/listMode", entry);
16841da177e4SLinus Torvalds 
16857fc925fdSRoman Zippel 	configSettings->writeSizes("/split1", split1->sizes());
16867fc925fdSRoman Zippel 	configSettings->writeSizes("/split2", split2->sizes());
16871da177e4SLinus Torvalds }
16881da177e4SLinus Torvalds 
16893b354c55SKarsten Wiese void ConfigMainWindow::conf_changed(void)
16903b354c55SKarsten Wiese {
16913b354c55SKarsten Wiese 	if (saveAction)
16923b354c55SKarsten Wiese 		saveAction->setEnabled(conf_get_changed());
16933b354c55SKarsten Wiese }
16943b354c55SKarsten Wiese 
16951da177e4SLinus Torvalds void fixup_rootmenu(struct menu *menu)
16961da177e4SLinus Torvalds {
16971da177e4SLinus Torvalds 	struct menu *child;
16981da177e4SLinus Torvalds 	static int menu_cnt = 0;
16991da177e4SLinus Torvalds 
17001da177e4SLinus Torvalds 	menu->flags |= MENU_ROOT;
17011da177e4SLinus Torvalds 	for (child = menu->list; child; child = child->next) {
17021da177e4SLinus Torvalds 		if (child->prompt && child->prompt->type == P_MENU) {
17031da177e4SLinus Torvalds 			menu_cnt++;
17041da177e4SLinus Torvalds 			fixup_rootmenu(child);
17051da177e4SLinus Torvalds 			menu_cnt--;
17061da177e4SLinus Torvalds 		} else if (!menu_cnt)
17071da177e4SLinus Torvalds 			fixup_rootmenu(child);
17081da177e4SLinus Torvalds 	}
17091da177e4SLinus Torvalds }
17101da177e4SLinus Torvalds 
17111da177e4SLinus Torvalds static const char *progname;
17121da177e4SLinus Torvalds 
17131da177e4SLinus Torvalds static void usage(void)
17141da177e4SLinus Torvalds {
1715c21a2d95SEGRY Gabor 	printf(_("%s <config>\n"), progname);
17161da177e4SLinus Torvalds 	exit(0);
17171da177e4SLinus Torvalds }
17181da177e4SLinus Torvalds 
17191da177e4SLinus Torvalds int main(int ac, char** av)
17201da177e4SLinus Torvalds {
17211da177e4SLinus Torvalds 	ConfigMainWindow* v;
17221da177e4SLinus Torvalds 	const char *name;
17231da177e4SLinus Torvalds 
17243b9fa093SArnaldo Carvalho de Melo 	bindtextdomain(PACKAGE, LOCALEDIR);
17253b9fa093SArnaldo Carvalho de Melo 	textdomain(PACKAGE);
17263b9fa093SArnaldo Carvalho de Melo 
17271da177e4SLinus Torvalds #ifndef LKC_DIRECT_LINK
17281da177e4SLinus Torvalds 	kconfig_load();
17291da177e4SLinus Torvalds #endif
17301da177e4SLinus Torvalds 
17311da177e4SLinus Torvalds 	progname = av[0];
17321da177e4SLinus Torvalds 	configApp = new QApplication(ac, av);
17331da177e4SLinus Torvalds 	if (ac > 1 && av[1][0] == '-') {
17341da177e4SLinus Torvalds 		switch (av[1][1]) {
17351da177e4SLinus Torvalds 		case 'h':
17361da177e4SLinus Torvalds 		case '?':
17371da177e4SLinus Torvalds 			usage();
17381da177e4SLinus Torvalds 		}
17391da177e4SLinus Torvalds 		name = av[2];
17401da177e4SLinus Torvalds 	} else
17411da177e4SLinus Torvalds 		name = av[1];
17421da177e4SLinus Torvalds 	if (!name)
17431da177e4SLinus Torvalds 		usage();
17441da177e4SLinus Torvalds 
17451da177e4SLinus Torvalds 	conf_parse(name);
17461da177e4SLinus Torvalds 	fixup_rootmenu(&rootmenu);
17471da177e4SLinus Torvalds 	conf_read(NULL);
17481da177e4SLinus Torvalds 	//zconfdump(stdout);
17491da177e4SLinus Torvalds 
17507fc925fdSRoman Zippel 	configSettings = new ConfigSettings();
17517fc925fdSRoman Zippel 	configSettings->beginGroup("/kconfig/qconf");
17521da177e4SLinus Torvalds 	v = new ConfigMainWindow();
17531da177e4SLinus Torvalds 
17541da177e4SLinus Torvalds 	//zconfdump(stdout);
175543bf612aSRoman Zippel 	configApp->setMainWidget(v);
17561da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
17571da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
175843bf612aSRoman Zippel 	v->show();
17591da177e4SLinus Torvalds 	configApp->exec();
17601da177e4SLinus Torvalds 
17617fc925fdSRoman Zippel 	configSettings->endGroup();
17627fc925fdSRoman Zippel 	delete configSettings;
17637fc925fdSRoman Zippel 
17641da177e4SLinus Torvalds 	return 0;
17651da177e4SLinus Torvalds }
1766