xref: /openbmc/linux/scripts/kconfig/qconf.cc (revision aed9934b)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
31da177e4SLinus Torvalds  * Released under the terms of the GNU GPL v2.0.
41da177e4SLinus Torvalds  */
51da177e4SLinus Torvalds 
6133c5f7cSAlexander Stein #include <qglobal.h>
7133c5f7cSAlexander Stein 
8133c5f7cSAlexander Stein #if QT_VERSION < 0x040000
9aed9934bSTiana Rakotovao Andriamahefa #include <stddef.h>
101da177e4SLinus Torvalds #include <qmainwindow.h>
11133c5f7cSAlexander Stein #include <qvbox.h>
12133c5f7cSAlexander Stein #include <qvaluelist.h>
13133c5f7cSAlexander Stein #include <qtextbrowser.h>
14133c5f7cSAlexander Stein #include <qaction.h>
15133c5f7cSAlexander Stein #include <qheader.h>
16133c5f7cSAlexander Stein #include <qfiledialog.h>
17133c5f7cSAlexander Stein #include <qdragobject.h>
18133c5f7cSAlexander Stein #include <qpopupmenu.h>
19133c5f7cSAlexander Stein #else
20133c5f7cSAlexander Stein #include <q3mainwindow.h>
21133c5f7cSAlexander Stein #include <q3vbox.h>
22133c5f7cSAlexander Stein #include <q3valuelist.h>
23133c5f7cSAlexander Stein #include <q3textbrowser.h>
24133c5f7cSAlexander Stein #include <q3action.h>
25133c5f7cSAlexander Stein #include <q3header.h>
26133c5f7cSAlexander Stein #include <q3filedialog.h>
27133c5f7cSAlexander Stein #include <q3dragobject.h>
28133c5f7cSAlexander Stein #include <q3popupmenu.h>
29133c5f7cSAlexander Stein #endif
30133c5f7cSAlexander Stein 
31133c5f7cSAlexander Stein #include <qapplication.h>
328d90c97eSMarkus Heidelberg #include <qdesktopwidget.h>
331da177e4SLinus Torvalds #include <qtoolbar.h>
3443bf612aSRoman Zippel #include <qlayout.h>
351da177e4SLinus Torvalds #include <qsplitter.h>
361da177e4SLinus Torvalds #include <qlineedit.h>
3743bf612aSRoman Zippel #include <qlabel.h>
3843bf612aSRoman Zippel #include <qpushbutton.h>
391da177e4SLinus Torvalds #include <qmenubar.h>
401da177e4SLinus Torvalds #include <qmessagebox.h>
411da177e4SLinus Torvalds #include <qregexp.h>
42133c5f7cSAlexander Stein #include <qevent.h>
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds #include <stdlib.h>
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds #include "lkc.h"
471da177e4SLinus Torvalds #include "qconf.h"
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #include "qconf.moc"
501da177e4SLinus Torvalds #include "images.c"
511da177e4SLinus Torvalds 
523b9fa093SArnaldo Carvalho de Melo #ifdef _
533b9fa093SArnaldo Carvalho de Melo # undef _
543b9fa093SArnaldo Carvalho de Melo # define _ qgettext
553b9fa093SArnaldo Carvalho de Melo #endif
563b9fa093SArnaldo Carvalho de Melo 
571da177e4SLinus Torvalds static QApplication *configApp;
587fc925fdSRoman Zippel static ConfigSettings *configSettings;
591da177e4SLinus Torvalds 
60133c5f7cSAlexander Stein Q3Action *ConfigMainWindow::saveAction;
613b354c55SKarsten Wiese 
623b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const char* str)
633b9fa093SArnaldo Carvalho de Melo {
643b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str));
653b9fa093SArnaldo Carvalho de Melo }
663b9fa093SArnaldo Carvalho de Melo 
673b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const QString& str)
683b9fa093SArnaldo Carvalho de Melo {
693b9fa093SArnaldo Carvalho de Melo 	return QString::fromLocal8Bit(gettext(str.latin1()));
703b9fa093SArnaldo Carvalho de Melo }
713b9fa093SArnaldo Carvalho de Melo 
721da177e4SLinus Torvalds /**
731da177e4SLinus Torvalds  * Reads a list of integer values from the application settings.
741da177e4SLinus Torvalds  */
75133c5f7cSAlexander Stein Q3ValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
761da177e4SLinus Torvalds {
77133c5f7cSAlexander Stein 	Q3ValueList<int> result;
781da177e4SLinus Torvalds 	QStringList entryList = readListEntry(key, ok);
791da177e4SLinus Torvalds 	QStringList::Iterator it;
80c1f96f09SLi Zefan 
811da177e4SLinus Torvalds 	for (it = entryList.begin(); it != entryList.end(); ++it)
821da177e4SLinus Torvalds 		result.push_back((*it).toInt());
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds 	return result;
851da177e4SLinus Torvalds }
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds /**
881da177e4SLinus Torvalds  * Writes a list of integer values to the application settings.
891da177e4SLinus Torvalds  */
90133c5f7cSAlexander Stein bool ConfigSettings::writeSizes(const QString& key, const Q3ValueList<int>& value)
911da177e4SLinus Torvalds {
921da177e4SLinus Torvalds 	QStringList stringList;
93133c5f7cSAlexander Stein 	Q3ValueList<int>::ConstIterator it;
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds 	for (it = value.begin(); it != value.end(); ++it)
961da177e4SLinus Torvalds 		stringList.push_back(QString::number(*it));
971da177e4SLinus Torvalds 	return writeEntry(key, stringList);
981da177e4SLinus Torvalds }
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds /*
1021da177e4SLinus Torvalds  * set the new data
1031da177e4SLinus Torvalds  * TODO check the value
1041da177e4SLinus Torvalds  */
1051da177e4SLinus Torvalds void ConfigItem::okRename(int col)
1061da177e4SLinus Torvalds {
1071da177e4SLinus Torvalds 	Parent::okRename(col);
1081da177e4SLinus Torvalds 	sym_set_string_value(menu->sym, text(dataColIdx).latin1());
10949e5646dSKarsten Wiese 	listView()->updateList(this);
1101da177e4SLinus Torvalds }
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds /*
1131da177e4SLinus Torvalds  * update the displayed of a menu entry
1141da177e4SLinus Torvalds  */
1151da177e4SLinus Torvalds void ConfigItem::updateMenu(void)
1161da177e4SLinus Torvalds {
1171da177e4SLinus Torvalds 	ConfigList* list;
1181da177e4SLinus Torvalds 	struct symbol* sym;
1191da177e4SLinus Torvalds 	struct property *prop;
1201da177e4SLinus Torvalds 	QString prompt;
1211da177e4SLinus Torvalds 	int type;
1221da177e4SLinus Torvalds 	tristate expr;
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds 	list = listView();
1251da177e4SLinus Torvalds 	if (goParent) {
1261da177e4SLinus Torvalds 		setPixmap(promptColIdx, list->menuBackPix);
1271da177e4SLinus Torvalds 		prompt = "..";
1281da177e4SLinus Torvalds 		goto set_prompt;
1291da177e4SLinus Torvalds 	}
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds 	sym = menu->sym;
1321da177e4SLinus Torvalds 	prop = menu->prompt;
133c21a2d95SEGRY Gabor 	prompt = _(menu_get_prompt(menu));
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds 	if (prop) switch (prop->type) {
1361da177e4SLinus Torvalds 	case P_MENU:
1371da177e4SLinus Torvalds 		if (list->mode == singleMode || list->mode == symbolMode) {
1381da177e4SLinus Torvalds 			/* a menuconfig entry is displayed differently
1391da177e4SLinus Torvalds 			 * depending whether it's at the view root or a child.
1401da177e4SLinus Torvalds 			 */
1411da177e4SLinus Torvalds 			if (sym && list->rootEntry == menu)
1421da177e4SLinus Torvalds 				break;
1431da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->menuPix);
1441da177e4SLinus Torvalds 		} else {
1451da177e4SLinus Torvalds 			if (sym)
1461da177e4SLinus Torvalds 				break;
1471da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1481da177e4SLinus Torvalds 		}
1491da177e4SLinus Torvalds 		goto set_prompt;
1501da177e4SLinus Torvalds 	case P_COMMENT:
1511da177e4SLinus Torvalds 		setPixmap(promptColIdx, 0);
1521da177e4SLinus Torvalds 		goto set_prompt;
1531da177e4SLinus Torvalds 	default:
1541da177e4SLinus Torvalds 		;
1551da177e4SLinus Torvalds 	}
1561da177e4SLinus Torvalds 	if (!sym)
1571da177e4SLinus Torvalds 		goto set_prompt;
1581da177e4SLinus Torvalds 
1593b9fa093SArnaldo Carvalho de Melo 	setText(nameColIdx, QString::fromLocal8Bit(sym->name));
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds 	type = sym_get_type(sym);
1621da177e4SLinus Torvalds 	switch (type) {
1631da177e4SLinus Torvalds 	case S_BOOLEAN:
1641da177e4SLinus Torvalds 	case S_TRISTATE:
1651da177e4SLinus Torvalds 		char ch;
1661da177e4SLinus Torvalds 
16739a4897cSLi Zefan 		if (!sym_is_changable(sym) && list->optMode == normalOpt) {
1681da177e4SLinus Torvalds 			setPixmap(promptColIdx, 0);
1693b9fa093SArnaldo Carvalho de Melo 			setText(noColIdx, QString::null);
1703b9fa093SArnaldo Carvalho de Melo 			setText(modColIdx, QString::null);
1713b9fa093SArnaldo Carvalho de Melo 			setText(yesColIdx, QString::null);
1721da177e4SLinus Torvalds 			break;
1731da177e4SLinus Torvalds 		}
1741da177e4SLinus Torvalds 		expr = sym_get_tristate_value(sym);
1751da177e4SLinus Torvalds 		switch (expr) {
1761da177e4SLinus Torvalds 		case yes:
1771da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1781da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceYesPix);
1791da177e4SLinus Torvalds 			else
1801da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolYesPix);
1811da177e4SLinus Torvalds 			setText(yesColIdx, "Y");
1821da177e4SLinus Torvalds 			ch = 'Y';
1831da177e4SLinus Torvalds 			break;
1841da177e4SLinus Torvalds 		case mod:
1851da177e4SLinus Torvalds 			setPixmap(promptColIdx, list->symbolModPix);
1861da177e4SLinus Torvalds 			setText(modColIdx, "M");
1871da177e4SLinus Torvalds 			ch = 'M';
1881da177e4SLinus Torvalds 			break;
1891da177e4SLinus Torvalds 		default:
1901da177e4SLinus Torvalds 			if (sym_is_choice_value(sym) && type == S_BOOLEAN)
1911da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->choiceNoPix);
1921da177e4SLinus Torvalds 			else
1931da177e4SLinus Torvalds 				setPixmap(promptColIdx, list->symbolNoPix);
1941da177e4SLinus Torvalds 			setText(noColIdx, "N");
1951da177e4SLinus Torvalds 			ch = 'N';
1961da177e4SLinus Torvalds 			break;
1971da177e4SLinus Torvalds 		}
1981da177e4SLinus Torvalds 		if (expr != no)
1991da177e4SLinus Torvalds 			setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
2001da177e4SLinus Torvalds 		if (expr != mod)
2011da177e4SLinus Torvalds 			setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
2021da177e4SLinus Torvalds 		if (expr != yes)
2031da177e4SLinus Torvalds 			setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds 		setText(dataColIdx, QChar(ch));
2061da177e4SLinus Torvalds 		break;
2071da177e4SLinus Torvalds 	case S_INT:
2081da177e4SLinus Torvalds 	case S_HEX:
2091da177e4SLinus Torvalds 	case S_STRING:
2101da177e4SLinus Torvalds 		const char* data;
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds 		data = sym_get_string_value(sym);
2133b9fa093SArnaldo Carvalho de Melo 
2141da177e4SLinus Torvalds 		int i = list->mapIdx(dataColIdx);
2151da177e4SLinus Torvalds 		if (i >= 0)
2161da177e4SLinus Torvalds 			setRenameEnabled(i, TRUE);
2171da177e4SLinus Torvalds 		setText(dataColIdx, data);
2181da177e4SLinus Torvalds 		if (type == S_STRING)
2193b9fa093SArnaldo Carvalho de Melo 			prompt = QString("%1: %2").arg(prompt).arg(data);
2201da177e4SLinus Torvalds 		else
2213b9fa093SArnaldo Carvalho de Melo 			prompt = QString("(%2) %1").arg(prompt).arg(data);
2221da177e4SLinus Torvalds 		break;
2231da177e4SLinus Torvalds 	}
2241da177e4SLinus Torvalds 	if (!sym_has_value(sym) && visible)
225c21a2d95SEGRY Gabor 		prompt += _(" (NEW)");
2261da177e4SLinus Torvalds set_prompt:
2271da177e4SLinus Torvalds 	setText(promptColIdx, prompt);
2281da177e4SLinus Torvalds }
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds void ConfigItem::testUpdateMenu(bool v)
2311da177e4SLinus Torvalds {
2321da177e4SLinus Torvalds 	ConfigItem* i;
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds 	visible = v;
2351da177e4SLinus Torvalds 	if (!menu)
2361da177e4SLinus Torvalds 		return;
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds 	sym_calc_value(menu->sym);
2391da177e4SLinus Torvalds 	if (menu->flags & MENU_CHANGED) {
2401da177e4SLinus Torvalds 		/* the menu entry changed, so update all list items */
2411da177e4SLinus Torvalds 		menu->flags &= ~MENU_CHANGED;
2421da177e4SLinus Torvalds 		for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
2431da177e4SLinus Torvalds 			i->updateMenu();
2441da177e4SLinus Torvalds 	} else if (listView()->updateAll)
2451da177e4SLinus Torvalds 		updateMenu();
2461da177e4SLinus Torvalds }
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
2491da177e4SLinus Torvalds {
2501da177e4SLinus Torvalds 	ConfigList* list = listView();
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds 	if (visible) {
2531da177e4SLinus Torvalds 		if (isSelected() && !list->hasFocus() && list->mode == menuMode)
2541da177e4SLinus Torvalds 			Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
2551da177e4SLinus Torvalds 		else
2561da177e4SLinus Torvalds 			Parent::paintCell(p, cg, column, width, align);
2571da177e4SLinus Torvalds 	} else
2581da177e4SLinus Torvalds 		Parent::paintCell(p, list->disabledColorGroup, column, width, align);
2591da177e4SLinus Torvalds }
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds /*
2621da177e4SLinus Torvalds  * construct a menu entry
2631da177e4SLinus Torvalds  */
2641da177e4SLinus Torvalds void ConfigItem::init(void)
2651da177e4SLinus Torvalds {
2661da177e4SLinus Torvalds 	if (menu) {
2671da177e4SLinus Torvalds 		ConfigList* list = listView();
2681da177e4SLinus Torvalds 		nextItem = (ConfigItem*)menu->data;
2691da177e4SLinus Torvalds 		menu->data = this;
2701da177e4SLinus Torvalds 
2711da177e4SLinus Torvalds 		if (list->mode != fullMode)
2721da177e4SLinus Torvalds 			setOpen(TRUE);
2731da177e4SLinus Torvalds 		sym_calc_value(menu->sym);
2741da177e4SLinus Torvalds 	}
2751da177e4SLinus Torvalds 	updateMenu();
2761da177e4SLinus Torvalds }
2771da177e4SLinus Torvalds 
2781da177e4SLinus Torvalds /*
2791da177e4SLinus Torvalds  * destruct a menu entry
2801da177e4SLinus Torvalds  */
2811da177e4SLinus Torvalds ConfigItem::~ConfigItem(void)
2821da177e4SLinus Torvalds {
2831da177e4SLinus Torvalds 	if (menu) {
2841da177e4SLinus Torvalds 		ConfigItem** ip = (ConfigItem**)&menu->data;
2851da177e4SLinus Torvalds 		for (; *ip; ip = &(*ip)->nextItem) {
2861da177e4SLinus Torvalds 			if (*ip == this) {
2871da177e4SLinus Torvalds 				*ip = nextItem;
2881da177e4SLinus Torvalds 				break;
2891da177e4SLinus Torvalds 			}
2901da177e4SLinus Torvalds 		}
2911da177e4SLinus Torvalds 	}
2921da177e4SLinus Torvalds }
2931da177e4SLinus Torvalds 
29443bf612aSRoman Zippel ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
29543bf612aSRoman Zippel 	: Parent(parent)
29643bf612aSRoman Zippel {
29743bf612aSRoman Zippel 	connect(this, SIGNAL(lostFocus()), SLOT(hide()));
29843bf612aSRoman Zippel }
29943bf612aSRoman Zippel 
3001da177e4SLinus Torvalds void ConfigLineEdit::show(ConfigItem* i)
3011da177e4SLinus Torvalds {
3021da177e4SLinus Torvalds 	item = i;
3031da177e4SLinus Torvalds 	if (sym_get_string_value(item->menu->sym))
3043b9fa093SArnaldo Carvalho de Melo 		setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
3051da177e4SLinus Torvalds 	else
3063b9fa093SArnaldo Carvalho de Melo 		setText(QString::null);
3071da177e4SLinus Torvalds 	Parent::show();
3081da177e4SLinus Torvalds 	setFocus();
3091da177e4SLinus Torvalds }
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
3121da177e4SLinus Torvalds {
3131da177e4SLinus Torvalds 	switch (e->key()) {
314fbb86374SMarkus Heidelberg 	case Qt::Key_Escape:
3151da177e4SLinus Torvalds 		break;
316fbb86374SMarkus Heidelberg 	case Qt::Key_Return:
317fbb86374SMarkus Heidelberg 	case Qt::Key_Enter:
3181da177e4SLinus Torvalds 		sym_set_string_value(item->menu->sym, text().latin1());
3191da177e4SLinus Torvalds 		parent()->updateList(item);
3201da177e4SLinus Torvalds 		break;
3211da177e4SLinus Torvalds 	default:
3221da177e4SLinus Torvalds 		Parent::keyPressEvent(e);
3231da177e4SLinus Torvalds 		return;
3241da177e4SLinus Torvalds 	}
3251da177e4SLinus Torvalds 	e->accept();
3261da177e4SLinus Torvalds 	parent()->list->setFocus();
3271da177e4SLinus Torvalds 	hide();
3281da177e4SLinus Torvalds }
3291da177e4SLinus Torvalds 
3307fc925fdSRoman Zippel ConfigList::ConfigList(ConfigView* p, const char *name)
3317fc925fdSRoman Zippel 	: Parent(p, name),
3321da177e4SLinus Torvalds 	  updateAll(false),
3331da177e4SLinus Torvalds 	  symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
3341da177e4SLinus Torvalds 	  choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
3351da177e4SLinus Torvalds 	  menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
33639a4897cSLi Zefan 	  showName(false), showRange(false), showData(false), optMode(normalOpt),
3377fc925fdSRoman Zippel 	  rootEntry(0), headerPopup(0)
3381da177e4SLinus Torvalds {
3391da177e4SLinus Torvalds 	int i;
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds 	setSorting(-1);
3421da177e4SLinus Torvalds 	setRootIsDecorated(TRUE);
3431da177e4SLinus Torvalds 	disabledColorGroup = palette().active();
3441da177e4SLinus Torvalds 	disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
3451da177e4SLinus Torvalds 	inactivedColorGroup = palette().active();
3461da177e4SLinus Torvalds 	inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds 	connect(this, SIGNAL(selectionChanged(void)),
3491da177e4SLinus Torvalds 		SLOT(updateSelection(void)));
3501da177e4SLinus Torvalds 
3517fc925fdSRoman Zippel 	if (name) {
3527fc925fdSRoman Zippel 		configSettings->beginGroup(name);
3537fc925fdSRoman Zippel 		showName = configSettings->readBoolEntry("/showName", false);
3547fc925fdSRoman Zippel 		showRange = configSettings->readBoolEntry("/showRange", false);
3557fc925fdSRoman Zippel 		showData = configSettings->readBoolEntry("/showData", false);
35639a4897cSLi Zefan 		optMode = (enum optionMode)configSettings->readNumEntry("/optionMode", false);
3577fc925fdSRoman Zippel 		configSettings->endGroup();
3587fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
3591da177e4SLinus Torvalds 	}
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds 	for (i = 0; i < colNr; i++)
3621da177e4SLinus Torvalds 		colMap[i] = colRevMap[i] = -1;
363c21a2d95SEGRY Gabor 	addColumn(promptColIdx, _("Option"));
3641da177e4SLinus Torvalds 
3651da177e4SLinus Torvalds 	reinit();
3661da177e4SLinus Torvalds }
3671da177e4SLinus Torvalds 
36839a4897cSLi Zefan bool ConfigList::menuSkip(struct menu *menu)
36939a4897cSLi Zefan {
37039a4897cSLi Zefan 	if (optMode == normalOpt && menu_is_visible(menu))
37139a4897cSLi Zefan 		return false;
37239a4897cSLi Zefan 	if (optMode == promptOpt && menu_has_prompt(menu))
37339a4897cSLi Zefan 		return false;
37439a4897cSLi Zefan 	if (optMode == allOpt)
37539a4897cSLi Zefan 		return false;
37639a4897cSLi Zefan 	return true;
37739a4897cSLi Zefan }
37839a4897cSLi Zefan 
3791da177e4SLinus Torvalds void ConfigList::reinit(void)
3801da177e4SLinus Torvalds {
3811da177e4SLinus Torvalds 	removeColumn(dataColIdx);
3821da177e4SLinus Torvalds 	removeColumn(yesColIdx);
3831da177e4SLinus Torvalds 	removeColumn(modColIdx);
3841da177e4SLinus Torvalds 	removeColumn(noColIdx);
3851da177e4SLinus Torvalds 	removeColumn(nameColIdx);
3861da177e4SLinus Torvalds 
3871da177e4SLinus Torvalds 	if (showName)
388c21a2d95SEGRY Gabor 		addColumn(nameColIdx, _("Name"));
3891da177e4SLinus Torvalds 	if (showRange) {
3901da177e4SLinus Torvalds 		addColumn(noColIdx, "N");
3911da177e4SLinus Torvalds 		addColumn(modColIdx, "M");
3921da177e4SLinus Torvalds 		addColumn(yesColIdx, "Y");
3931da177e4SLinus Torvalds 	}
3941da177e4SLinus Torvalds 	if (showData)
395c21a2d95SEGRY Gabor 		addColumn(dataColIdx, _("Value"));
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds 	updateListAll();
3981da177e4SLinus Torvalds }
3991da177e4SLinus Torvalds 
4007fc925fdSRoman Zippel void ConfigList::saveSettings(void)
4017fc925fdSRoman Zippel {
4027fc925fdSRoman Zippel 	if (name()) {
4037fc925fdSRoman Zippel 		configSettings->beginGroup(name());
4047fc925fdSRoman Zippel 		configSettings->writeEntry("/showName", showName);
4057fc925fdSRoman Zippel 		configSettings->writeEntry("/showRange", showRange);
4067fc925fdSRoman Zippel 		configSettings->writeEntry("/showData", showData);
40739a4897cSLi Zefan 		configSettings->writeEntry("/optionMode", (int)optMode);
4087fc925fdSRoman Zippel 		configSettings->endGroup();
4097fc925fdSRoman Zippel 	}
4107fc925fdSRoman Zippel }
4117fc925fdSRoman Zippel 
412b65a47e1SRoman Zippel ConfigItem* ConfigList::findConfigItem(struct menu *menu)
413b65a47e1SRoman Zippel {
414b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem*)menu->data;
415b65a47e1SRoman Zippel 
416b65a47e1SRoman Zippel 	for (; item; item = item->nextItem) {
417b65a47e1SRoman Zippel 		if (this == item->listView())
418b65a47e1SRoman Zippel 			break;
419b65a47e1SRoman Zippel 	}
420b65a47e1SRoman Zippel 
421b65a47e1SRoman Zippel 	return item;
422b65a47e1SRoman Zippel }
423b65a47e1SRoman Zippel 
4241da177e4SLinus Torvalds void ConfigList::updateSelection(void)
4251da177e4SLinus Torvalds {
4261da177e4SLinus Torvalds 	struct menu *menu;
4271da177e4SLinus Torvalds 	enum prop_type type;
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)selectedItem();
4301da177e4SLinus Torvalds 	if (!item)
4311da177e4SLinus Torvalds 		return;
4321da177e4SLinus Torvalds 
4331da177e4SLinus Torvalds 	menu = item->menu;
43443bf612aSRoman Zippel 	emit menuChanged(menu);
4351da177e4SLinus Torvalds 	if (!menu)
4361da177e4SLinus Torvalds 		return;
4371da177e4SLinus Torvalds 	type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
4381da177e4SLinus Torvalds 	if (mode == menuMode && type == P_MENU)
4391da177e4SLinus Torvalds 		emit menuSelected(menu);
4401da177e4SLinus Torvalds }
4411da177e4SLinus Torvalds 
4421da177e4SLinus Torvalds void ConfigList::updateList(ConfigItem* item)
4431da177e4SLinus Torvalds {
4441da177e4SLinus Torvalds 	ConfigItem* last = 0;
4451da177e4SLinus Torvalds 
44643bf612aSRoman Zippel 	if (!rootEntry) {
44743bf612aSRoman Zippel 		if (mode != listMode)
4481da177e4SLinus Torvalds 			goto update;
449133c5f7cSAlexander Stein 		Q3ListViewItemIterator it(this);
45043bf612aSRoman Zippel 		ConfigItem* item;
45143bf612aSRoman Zippel 
45243bf612aSRoman Zippel 		for (; it.current(); ++it) {
45343bf612aSRoman Zippel 			item = (ConfigItem*)it.current();
45443bf612aSRoman Zippel 			if (!item->menu)
45543bf612aSRoman Zippel 				continue;
45643bf612aSRoman Zippel 			item->testUpdateMenu(menu_is_visible(item->menu));
45743bf612aSRoman Zippel 		}
45843bf612aSRoman Zippel 		return;
45943bf612aSRoman Zippel 	}
4601da177e4SLinus Torvalds 
4611da177e4SLinus Torvalds 	if (rootEntry != &rootmenu && (mode == singleMode ||
4621da177e4SLinus Torvalds 	    (mode == symbolMode && rootEntry->parent != &rootmenu))) {
4631da177e4SLinus Torvalds 		item = firstChild();
4641da177e4SLinus Torvalds 		if (!item)
4651da177e4SLinus Torvalds 			item = new ConfigItem(this, 0, true);
4661da177e4SLinus Torvalds 		last = item;
4671da177e4SLinus Torvalds 	}
4681da177e4SLinus Torvalds 	if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
4691da177e4SLinus Torvalds 	    rootEntry->sym && rootEntry->prompt) {
4701da177e4SLinus Torvalds 		item = last ? last->nextSibling() : firstChild();
4711da177e4SLinus Torvalds 		if (!item)
4721da177e4SLinus Torvalds 			item = new ConfigItem(this, last, rootEntry, true);
4731da177e4SLinus Torvalds 		else
4741da177e4SLinus Torvalds 			item->testUpdateMenu(true);
4751da177e4SLinus Torvalds 
4761da177e4SLinus Torvalds 		updateMenuList(item, rootEntry);
4771da177e4SLinus Torvalds 		triggerUpdate();
4781da177e4SLinus Torvalds 		return;
4791da177e4SLinus Torvalds 	}
4801da177e4SLinus Torvalds update:
4811da177e4SLinus Torvalds 	updateMenuList(this, rootEntry);
4821da177e4SLinus Torvalds 	triggerUpdate();
4831da177e4SLinus Torvalds }
4841da177e4SLinus Torvalds 
4851da177e4SLinus Torvalds void ConfigList::setValue(ConfigItem* item, tristate val)
4861da177e4SLinus Torvalds {
4871da177e4SLinus Torvalds 	struct symbol* sym;
4881da177e4SLinus Torvalds 	int type;
4891da177e4SLinus Torvalds 	tristate oldval;
4901da177e4SLinus Torvalds 
4911da177e4SLinus Torvalds 	sym = item->menu ? item->menu->sym : 0;
4921da177e4SLinus Torvalds 	if (!sym)
4931da177e4SLinus Torvalds 		return;
4941da177e4SLinus Torvalds 
4951da177e4SLinus Torvalds 	type = sym_get_type(sym);
4961da177e4SLinus Torvalds 	switch (type) {
4971da177e4SLinus Torvalds 	case S_BOOLEAN:
4981da177e4SLinus Torvalds 	case S_TRISTATE:
4991da177e4SLinus Torvalds 		oldval = sym_get_tristate_value(sym);
5001da177e4SLinus Torvalds 
5011da177e4SLinus Torvalds 		if (!sym_set_tristate_value(sym, val))
5021da177e4SLinus Torvalds 			return;
5031da177e4SLinus Torvalds 		if (oldval == no && item->menu->list)
5041da177e4SLinus Torvalds 			item->setOpen(TRUE);
5051da177e4SLinus Torvalds 		parent()->updateList(item);
5061da177e4SLinus Torvalds 		break;
5071da177e4SLinus Torvalds 	}
5081da177e4SLinus Torvalds }
5091da177e4SLinus Torvalds 
5101da177e4SLinus Torvalds void ConfigList::changeValue(ConfigItem* item)
5111da177e4SLinus Torvalds {
5121da177e4SLinus Torvalds 	struct symbol* sym;
5131da177e4SLinus Torvalds 	struct menu* menu;
5141da177e4SLinus Torvalds 	int type, oldexpr, newexpr;
5151da177e4SLinus Torvalds 
5161da177e4SLinus Torvalds 	menu = item->menu;
5171da177e4SLinus Torvalds 	if (!menu)
5181da177e4SLinus Torvalds 		return;
5191da177e4SLinus Torvalds 	sym = menu->sym;
5201da177e4SLinus Torvalds 	if (!sym) {
5211da177e4SLinus Torvalds 		if (item->menu->list)
5221da177e4SLinus Torvalds 			item->setOpen(!item->isOpen());
5231da177e4SLinus Torvalds 		return;
5241da177e4SLinus Torvalds 	}
5251da177e4SLinus Torvalds 
5261da177e4SLinus Torvalds 	type = sym_get_type(sym);
5271da177e4SLinus Torvalds 	switch (type) {
5281da177e4SLinus Torvalds 	case S_BOOLEAN:
5291da177e4SLinus Torvalds 	case S_TRISTATE:
5301da177e4SLinus Torvalds 		oldexpr = sym_get_tristate_value(sym);
5311da177e4SLinus Torvalds 		newexpr = sym_toggle_tristate_value(sym);
5321da177e4SLinus Torvalds 		if (item->menu->list) {
5331da177e4SLinus Torvalds 			if (oldexpr == newexpr)
5341da177e4SLinus Torvalds 				item->setOpen(!item->isOpen());
5351da177e4SLinus Torvalds 			else if (oldexpr == no)
5361da177e4SLinus Torvalds 				item->setOpen(TRUE);
5371da177e4SLinus Torvalds 		}
5381da177e4SLinus Torvalds 		if (oldexpr != newexpr)
5391da177e4SLinus Torvalds 			parent()->updateList(item);
5401da177e4SLinus Torvalds 		break;
5411da177e4SLinus Torvalds 	case S_INT:
5421da177e4SLinus Torvalds 	case S_HEX:
5431da177e4SLinus Torvalds 	case S_STRING:
5441da177e4SLinus Torvalds 		if (colMap[dataColIdx] >= 0)
5451da177e4SLinus Torvalds 			item->startRename(colMap[dataColIdx]);
5461da177e4SLinus Torvalds 		else
5471da177e4SLinus Torvalds 			parent()->lineEdit->show(item);
5481da177e4SLinus Torvalds 		break;
5491da177e4SLinus Torvalds 	}
5501da177e4SLinus Torvalds }
5511da177e4SLinus Torvalds 
5521da177e4SLinus Torvalds void ConfigList::setRootMenu(struct menu *menu)
5531da177e4SLinus Torvalds {
5541da177e4SLinus Torvalds 	enum prop_type type;
5551da177e4SLinus Torvalds 
5561da177e4SLinus Torvalds 	if (rootEntry == menu)
5571da177e4SLinus Torvalds 		return;
5581da177e4SLinus Torvalds 	type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
5591da177e4SLinus Torvalds 	if (type != P_MENU)
5601da177e4SLinus Torvalds 		return;
5611da177e4SLinus Torvalds 	updateMenuList(this, 0);
5621da177e4SLinus Torvalds 	rootEntry = menu;
5631da177e4SLinus Torvalds 	updateListAll();
5641da177e4SLinus Torvalds 	setSelected(currentItem(), hasFocus());
565b65a47e1SRoman Zippel 	ensureItemVisible(currentItem());
5661da177e4SLinus Torvalds }
5671da177e4SLinus Torvalds 
5681da177e4SLinus Torvalds void ConfigList::setParentMenu(void)
5691da177e4SLinus Torvalds {
5701da177e4SLinus Torvalds 	ConfigItem* item;
5711da177e4SLinus Torvalds 	struct menu *oldroot;
5721da177e4SLinus Torvalds 
5731da177e4SLinus Torvalds 	oldroot = rootEntry;
5741da177e4SLinus Torvalds 	if (rootEntry == &rootmenu)
5751da177e4SLinus Torvalds 		return;
5761da177e4SLinus Torvalds 	setRootMenu(menu_get_parent_menu(rootEntry->parent));
5771da177e4SLinus Torvalds 
578133c5f7cSAlexander Stein 	Q3ListViewItemIterator it(this);
5791da177e4SLinus Torvalds 	for (; (item = (ConfigItem*)it.current()); it++) {
5801da177e4SLinus Torvalds 		if (item->menu == oldroot) {
5811da177e4SLinus Torvalds 			setCurrentItem(item);
5821da177e4SLinus Torvalds 			ensureItemVisible(item);
5831da177e4SLinus Torvalds 			break;
5841da177e4SLinus Torvalds 		}
5851da177e4SLinus Torvalds 	}
5861da177e4SLinus Torvalds }
5871da177e4SLinus Torvalds 
5887fc925fdSRoman Zippel /*
5897fc925fdSRoman Zippel  * update all the children of a menu entry
5907fc925fdSRoman Zippel  *   removes/adds the entries from the parent widget as necessary
5917fc925fdSRoman Zippel  *
5927fc925fdSRoman Zippel  * parent: either the menu list widget or a menu entry widget
5937fc925fdSRoman Zippel  * menu: entry to be updated
5947fc925fdSRoman Zippel  */
5957fc925fdSRoman Zippel template <class P>
5967fc925fdSRoman Zippel void ConfigList::updateMenuList(P* parent, struct menu* menu)
5977fc925fdSRoman Zippel {
5987fc925fdSRoman Zippel 	struct menu* child;
5997fc925fdSRoman Zippel 	ConfigItem* item;
6007fc925fdSRoman Zippel 	ConfigItem* last;
6017fc925fdSRoman Zippel 	bool visible;
6027fc925fdSRoman Zippel 	enum prop_type type;
6037fc925fdSRoman Zippel 
6047fc925fdSRoman Zippel 	if (!menu) {
6057fc925fdSRoman Zippel 		while ((item = parent->firstChild()))
6067fc925fdSRoman Zippel 			delete item;
6077fc925fdSRoman Zippel 		return;
6087fc925fdSRoman Zippel 	}
6097fc925fdSRoman Zippel 
6107fc925fdSRoman Zippel 	last = parent->firstChild();
6117fc925fdSRoman Zippel 	if (last && !last->goParent)
6127fc925fdSRoman Zippel 		last = 0;
6137fc925fdSRoman Zippel 	for (child = menu->list; child; child = child->next) {
6147fc925fdSRoman Zippel 		item = last ? last->nextSibling() : parent->firstChild();
6157fc925fdSRoman Zippel 		type = child->prompt ? child->prompt->type : P_UNKNOWN;
6167fc925fdSRoman Zippel 
6177fc925fdSRoman Zippel 		switch (mode) {
6187fc925fdSRoman Zippel 		case menuMode:
6197fc925fdSRoman Zippel 			if (!(child->flags & MENU_ROOT))
6207fc925fdSRoman Zippel 				goto hide;
6217fc925fdSRoman Zippel 			break;
6227fc925fdSRoman Zippel 		case symbolMode:
6237fc925fdSRoman Zippel 			if (child->flags & MENU_ROOT)
6247fc925fdSRoman Zippel 				goto hide;
6257fc925fdSRoman Zippel 			break;
6267fc925fdSRoman Zippel 		default:
6277fc925fdSRoman Zippel 			break;
6287fc925fdSRoman Zippel 		}
6297fc925fdSRoman Zippel 
6307fc925fdSRoman Zippel 		visible = menu_is_visible(child);
63139a4897cSLi Zefan 		if (!menuSkip(child)) {
632ed8b4d4dSCyrill V. Gorcunov 			if (!child->sym && !child->list && !child->prompt)
633ed8b4d4dSCyrill V. Gorcunov 				continue;
6347fc925fdSRoman Zippel 			if (!item || item->menu != child)
6357fc925fdSRoman Zippel 				item = new ConfigItem(parent, last, child, visible);
6367fc925fdSRoman Zippel 			else
6377fc925fdSRoman Zippel 				item->testUpdateMenu(visible);
6387fc925fdSRoman Zippel 
6397fc925fdSRoman Zippel 			if (mode == fullMode || mode == menuMode || type != P_MENU)
6407fc925fdSRoman Zippel 				updateMenuList(item, child);
6417fc925fdSRoman Zippel 			else
6427fc925fdSRoman Zippel 				updateMenuList(item, 0);
6437fc925fdSRoman Zippel 			last = item;
6447fc925fdSRoman Zippel 			continue;
6457fc925fdSRoman Zippel 		}
6467fc925fdSRoman Zippel 	hide:
6477fc925fdSRoman Zippel 		if (item && item->menu == child) {
6487fc925fdSRoman Zippel 			last = parent->firstChild();
6497fc925fdSRoman Zippel 			if (last == item)
6507fc925fdSRoman Zippel 				last = 0;
6517fc925fdSRoman Zippel 			else while (last->nextSibling() != item)
6527fc925fdSRoman Zippel 				last = last->nextSibling();
6537fc925fdSRoman Zippel 			delete item;
6547fc925fdSRoman Zippel 		}
6557fc925fdSRoman Zippel 	}
6567fc925fdSRoman Zippel }
6577fc925fdSRoman Zippel 
6581da177e4SLinus Torvalds void ConfigList::keyPressEvent(QKeyEvent* ev)
6591da177e4SLinus Torvalds {
660133c5f7cSAlexander Stein 	Q3ListViewItem* i = currentItem();
6611da177e4SLinus Torvalds 	ConfigItem* item;
6621da177e4SLinus Torvalds 	struct menu *menu;
6631da177e4SLinus Torvalds 	enum prop_type type;
6641da177e4SLinus Torvalds 
665fbb86374SMarkus Heidelberg 	if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
6661da177e4SLinus Torvalds 		emit parentSelected();
6671da177e4SLinus Torvalds 		ev->accept();
6681da177e4SLinus Torvalds 		return;
6691da177e4SLinus Torvalds 	}
6701da177e4SLinus Torvalds 
6711da177e4SLinus Torvalds 	if (!i) {
6721da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
6731da177e4SLinus Torvalds 		return;
6741da177e4SLinus Torvalds 	}
6751da177e4SLinus Torvalds 	item = (ConfigItem*)i;
6761da177e4SLinus Torvalds 
6771da177e4SLinus Torvalds 	switch (ev->key()) {
678fbb86374SMarkus Heidelberg 	case Qt::Key_Return:
679fbb86374SMarkus Heidelberg 	case Qt::Key_Enter:
6801da177e4SLinus Torvalds 		if (item->goParent) {
6811da177e4SLinus Torvalds 			emit parentSelected();
6821da177e4SLinus Torvalds 			break;
6831da177e4SLinus Torvalds 		}
6841da177e4SLinus Torvalds 		menu = item->menu;
6851da177e4SLinus Torvalds 		if (!menu)
6861da177e4SLinus Torvalds 			break;
6871da177e4SLinus Torvalds 		type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
6881da177e4SLinus Torvalds 		if (type == P_MENU && rootEntry != menu &&
6891da177e4SLinus Torvalds 		    mode != fullMode && mode != menuMode) {
6901da177e4SLinus Torvalds 			emit menuSelected(menu);
6911da177e4SLinus Torvalds 			break;
6921da177e4SLinus Torvalds 		}
693fbb86374SMarkus Heidelberg 	case Qt::Key_Space:
6941da177e4SLinus Torvalds 		changeValue(item);
6951da177e4SLinus Torvalds 		break;
696fbb86374SMarkus Heidelberg 	case Qt::Key_N:
6971da177e4SLinus Torvalds 		setValue(item, no);
6981da177e4SLinus Torvalds 		break;
699fbb86374SMarkus Heidelberg 	case Qt::Key_M:
7001da177e4SLinus Torvalds 		setValue(item, mod);
7011da177e4SLinus Torvalds 		break;
702fbb86374SMarkus Heidelberg 	case Qt::Key_Y:
7031da177e4SLinus Torvalds 		setValue(item, yes);
7041da177e4SLinus Torvalds 		break;
7051da177e4SLinus Torvalds 	default:
7061da177e4SLinus Torvalds 		Parent::keyPressEvent(ev);
7071da177e4SLinus Torvalds 		return;
7081da177e4SLinus Torvalds 	}
7091da177e4SLinus Torvalds 	ev->accept();
7101da177e4SLinus Torvalds }
7111da177e4SLinus Torvalds 
7121da177e4SLinus Torvalds void ConfigList::contentsMousePressEvent(QMouseEvent* e)
7131da177e4SLinus Torvalds {
7141da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
7151da177e4SLinus Torvalds 	//printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
7161da177e4SLinus Torvalds 	Parent::contentsMousePressEvent(e);
7171da177e4SLinus Torvalds }
7181da177e4SLinus Torvalds 
7191da177e4SLinus Torvalds void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
7201da177e4SLinus Torvalds {
7211da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
7221da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
7231da177e4SLinus Torvalds 	struct menu *menu;
7241da177e4SLinus Torvalds 	enum prop_type ptype;
7251da177e4SLinus Torvalds 	const QPixmap* pm;
7261da177e4SLinus Torvalds 	int idx, x;
7271da177e4SLinus Torvalds 
7281da177e4SLinus Torvalds 	if (!item)
7291da177e4SLinus Torvalds 		goto skip;
7301da177e4SLinus Torvalds 
7311da177e4SLinus Torvalds 	menu = item->menu;
7321da177e4SLinus Torvalds 	x = header()->offset() + p.x();
7331da177e4SLinus Torvalds 	idx = colRevMap[header()->sectionAt(x)];
7341da177e4SLinus Torvalds 	switch (idx) {
7351da177e4SLinus Torvalds 	case promptColIdx:
7361da177e4SLinus Torvalds 		pm = item->pixmap(promptColIdx);
7371da177e4SLinus Torvalds 		if (pm) {
7381da177e4SLinus Torvalds 			int off = header()->sectionPos(0) + itemMargin() +
7391da177e4SLinus Torvalds 				treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
7401da177e4SLinus Torvalds 			if (x >= off && x < off + pm->width()) {
7411da177e4SLinus Torvalds 				if (item->goParent) {
7421da177e4SLinus Torvalds 					emit parentSelected();
7431da177e4SLinus Torvalds 					break;
7441da177e4SLinus Torvalds 				} else if (!menu)
7451da177e4SLinus Torvalds 					break;
7461da177e4SLinus Torvalds 				ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7471da177e4SLinus Torvalds 				if (ptype == P_MENU && rootEntry != menu &&
7481da177e4SLinus Torvalds 				    mode != fullMode && mode != menuMode)
7491da177e4SLinus Torvalds 					emit menuSelected(menu);
7501da177e4SLinus Torvalds 				else
7511da177e4SLinus Torvalds 					changeValue(item);
7521da177e4SLinus Torvalds 			}
7531da177e4SLinus Torvalds 		}
7541da177e4SLinus Torvalds 		break;
7551da177e4SLinus Torvalds 	case noColIdx:
7561da177e4SLinus Torvalds 		setValue(item, no);
7571da177e4SLinus Torvalds 		break;
7581da177e4SLinus Torvalds 	case modColIdx:
7591da177e4SLinus Torvalds 		setValue(item, mod);
7601da177e4SLinus Torvalds 		break;
7611da177e4SLinus Torvalds 	case yesColIdx:
7621da177e4SLinus Torvalds 		setValue(item, yes);
7631da177e4SLinus Torvalds 		break;
7641da177e4SLinus Torvalds 	case dataColIdx:
7651da177e4SLinus Torvalds 		changeValue(item);
7661da177e4SLinus Torvalds 		break;
7671da177e4SLinus Torvalds 	}
7681da177e4SLinus Torvalds 
7691da177e4SLinus Torvalds skip:
7701da177e4SLinus Torvalds 	//printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
7711da177e4SLinus Torvalds 	Parent::contentsMouseReleaseEvent(e);
7721da177e4SLinus Torvalds }
7731da177e4SLinus Torvalds 
7741da177e4SLinus Torvalds void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
7751da177e4SLinus Torvalds {
7761da177e4SLinus Torvalds 	//QPoint p(contentsToViewport(e->pos()));
7771da177e4SLinus Torvalds 	//printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
7781da177e4SLinus Torvalds 	Parent::contentsMouseMoveEvent(e);
7791da177e4SLinus Torvalds }
7801da177e4SLinus Torvalds 
7811da177e4SLinus Torvalds void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
7821da177e4SLinus Torvalds {
7831da177e4SLinus Torvalds 	QPoint p(contentsToViewport(e->pos()));
7841da177e4SLinus Torvalds 	ConfigItem* item = (ConfigItem*)itemAt(p);
7851da177e4SLinus Torvalds 	struct menu *menu;
7861da177e4SLinus Torvalds 	enum prop_type ptype;
7871da177e4SLinus Torvalds 
7881da177e4SLinus Torvalds 	if (!item)
7891da177e4SLinus Torvalds 		goto skip;
7901da177e4SLinus Torvalds 	if (item->goParent) {
7911da177e4SLinus Torvalds 		emit parentSelected();
7921da177e4SLinus Torvalds 		goto skip;
7931da177e4SLinus Torvalds 	}
7941da177e4SLinus Torvalds 	menu = item->menu;
7951da177e4SLinus Torvalds 	if (!menu)
7961da177e4SLinus Torvalds 		goto skip;
7971da177e4SLinus Torvalds 	ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
7981da177e4SLinus Torvalds 	if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
7991da177e4SLinus Torvalds 		emit menuSelected(menu);
8001da177e4SLinus Torvalds 	else if (menu->sym)
8011da177e4SLinus Torvalds 		changeValue(item);
8021da177e4SLinus Torvalds 
8031da177e4SLinus Torvalds skip:
8041da177e4SLinus Torvalds 	//printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
8051da177e4SLinus Torvalds 	Parent::contentsMouseDoubleClickEvent(e);
8061da177e4SLinus Torvalds }
8071da177e4SLinus Torvalds 
8081da177e4SLinus Torvalds void ConfigList::focusInEvent(QFocusEvent *e)
8091da177e4SLinus Torvalds {
810b65a47e1SRoman Zippel 	struct menu *menu = NULL;
811b65a47e1SRoman Zippel 
8121da177e4SLinus Torvalds 	Parent::focusInEvent(e);
8131da177e4SLinus Torvalds 
814b65a47e1SRoman Zippel 	ConfigItem* item = (ConfigItem *)currentItem();
815b65a47e1SRoman Zippel 	if (item) {
8161da177e4SLinus Torvalds 		setSelected(item, TRUE);
817b65a47e1SRoman Zippel 		menu = item->menu;
818b65a47e1SRoman Zippel 	}
819b65a47e1SRoman Zippel 	emit gotFocus(menu);
8201da177e4SLinus Torvalds }
8211da177e4SLinus Torvalds 
8227fc925fdSRoman Zippel void ConfigList::contextMenuEvent(QContextMenuEvent *e)
8237fc925fdSRoman Zippel {
8247fc925fdSRoman Zippel 	if (e->y() <= header()->geometry().bottom()) {
8257fc925fdSRoman Zippel 		if (!headerPopup) {
826133c5f7cSAlexander Stein 			Q3Action *action;
8277fc925fdSRoman Zippel 
828133c5f7cSAlexander Stein 			headerPopup = new Q3PopupMenu(this);
829133c5f7cSAlexander Stein 			action = new Q3Action(NULL, _("Show Name"), 0, this);
8307fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8317fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8327fc925fdSRoman Zippel 				  parent(), SLOT(setShowName(bool)));
8337fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showNameChanged(bool)),
8347fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8357fc925fdSRoman Zippel 			  action->setOn(showName);
8367fc925fdSRoman Zippel 			  action->addTo(headerPopup);
837133c5f7cSAlexander Stein 			action = new Q3Action(NULL, _("Show Range"), 0, this);
8387fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8397fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8407fc925fdSRoman Zippel 				  parent(), SLOT(setShowRange(bool)));
8417fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showRangeChanged(bool)),
8427fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8437fc925fdSRoman Zippel 			  action->setOn(showRange);
8447fc925fdSRoman Zippel 			  action->addTo(headerPopup);
845133c5f7cSAlexander Stein 			action = new Q3Action(NULL, _("Show Data"), 0, this);
8467fc925fdSRoman Zippel 			  action->setToggleAction(TRUE);
8477fc925fdSRoman Zippel 			  connect(action, SIGNAL(toggled(bool)),
8487fc925fdSRoman Zippel 				  parent(), SLOT(setShowData(bool)));
8497fc925fdSRoman Zippel 			  connect(parent(), SIGNAL(showDataChanged(bool)),
8507fc925fdSRoman Zippel 				  action, SLOT(setOn(bool)));
8517fc925fdSRoman Zippel 			  action->setOn(showData);
8527fc925fdSRoman Zippel 			  action->addTo(headerPopup);
8537fc925fdSRoman Zippel 		}
8547fc925fdSRoman Zippel 		headerPopup->exec(e->globalPos());
8557fc925fdSRoman Zippel 		e->accept();
8567fc925fdSRoman Zippel 	} else
8577fc925fdSRoman Zippel 		e->ignore();
8587fc925fdSRoman Zippel }
8597fc925fdSRoman Zippel 
8601da177e4SLinus Torvalds ConfigView*ConfigView::viewList;
86139a4897cSLi Zefan QAction *ConfigView::showNormalAction;
86239a4897cSLi Zefan QAction *ConfigView::showAllAction;
86339a4897cSLi Zefan QAction *ConfigView::showPromptAction;
8641da177e4SLinus Torvalds 
8657fc925fdSRoman Zippel ConfigView::ConfigView(QWidget* parent, const char *name)
8667fc925fdSRoman Zippel 	: Parent(parent, name)
8671da177e4SLinus Torvalds {
8687fc925fdSRoman Zippel 	list = new ConfigList(this, name);
8691da177e4SLinus Torvalds 	lineEdit = new ConfigLineEdit(this);
8701da177e4SLinus Torvalds 	lineEdit->hide();
8711da177e4SLinus Torvalds 
8721da177e4SLinus Torvalds 	this->nextView = viewList;
8731da177e4SLinus Torvalds 	viewList = this;
8741da177e4SLinus Torvalds }
8751da177e4SLinus Torvalds 
8761da177e4SLinus Torvalds ConfigView::~ConfigView(void)
8771da177e4SLinus Torvalds {
8781da177e4SLinus Torvalds 	ConfigView** vp;
8791da177e4SLinus Torvalds 
8801da177e4SLinus Torvalds 	for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
8811da177e4SLinus Torvalds 		if (*vp == this) {
8821da177e4SLinus Torvalds 			*vp = nextView;
8831da177e4SLinus Torvalds 			break;
8841da177e4SLinus Torvalds 		}
8851da177e4SLinus Torvalds 	}
8861da177e4SLinus Torvalds }
8871da177e4SLinus Torvalds 
88839a4897cSLi Zefan void ConfigView::setOptionMode(QAction *act)
8897fc925fdSRoman Zippel {
89039a4897cSLi Zefan 	if (act == showNormalAction)
89139a4897cSLi Zefan 		list->optMode = normalOpt;
89239a4897cSLi Zefan 	else if (act == showAllAction)
89339a4897cSLi Zefan 		list->optMode = allOpt;
89439a4897cSLi Zefan 	else
89539a4897cSLi Zefan 		list->optMode = promptOpt;
89639a4897cSLi Zefan 
8977fc925fdSRoman Zippel 	list->updateListAll();
8987fc925fdSRoman Zippel }
8997fc925fdSRoman Zippel 
9007fc925fdSRoman Zippel void ConfigView::setShowName(bool b)
9017fc925fdSRoman Zippel {
9027fc925fdSRoman Zippel 	if (list->showName != b) {
9037fc925fdSRoman Zippel 		list->showName = b;
9047fc925fdSRoman Zippel 		list->reinit();
9057fc925fdSRoman Zippel 		emit showNameChanged(b);
9067fc925fdSRoman Zippel 	}
9077fc925fdSRoman Zippel }
9087fc925fdSRoman Zippel 
9097fc925fdSRoman Zippel void ConfigView::setShowRange(bool b)
9107fc925fdSRoman Zippel {
9117fc925fdSRoman Zippel 	if (list->showRange != b) {
9127fc925fdSRoman Zippel 		list->showRange = b;
9137fc925fdSRoman Zippel 		list->reinit();
9147fc925fdSRoman Zippel 		emit showRangeChanged(b);
9157fc925fdSRoman Zippel 	}
9167fc925fdSRoman Zippel }
9177fc925fdSRoman Zippel 
9187fc925fdSRoman Zippel void ConfigView::setShowData(bool b)
9197fc925fdSRoman Zippel {
9207fc925fdSRoman Zippel 	if (list->showData != b) {
9217fc925fdSRoman Zippel 		list->showData = b;
9227fc925fdSRoman Zippel 		list->reinit();
9237fc925fdSRoman Zippel 		emit showDataChanged(b);
9247fc925fdSRoman Zippel 	}
9257fc925fdSRoman Zippel }
9267fc925fdSRoman Zippel 
9277fc925fdSRoman Zippel void ConfigList::setAllOpen(bool open)
9287fc925fdSRoman Zippel {
929133c5f7cSAlexander Stein 	Q3ListViewItemIterator it(this);
9307fc925fdSRoman Zippel 
9317fc925fdSRoman Zippel 	for (; it.current(); it++)
9327fc925fdSRoman Zippel 		it.current()->setOpen(open);
9337fc925fdSRoman Zippel }
9347fc925fdSRoman Zippel 
9351da177e4SLinus Torvalds void ConfigView::updateList(ConfigItem* item)
9361da177e4SLinus Torvalds {
9371da177e4SLinus Torvalds 	ConfigView* v;
9381da177e4SLinus Torvalds 
9391da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9401da177e4SLinus Torvalds 		v->list->updateList(item);
9411da177e4SLinus Torvalds }
9421da177e4SLinus Torvalds 
9431da177e4SLinus Torvalds void ConfigView::updateListAll(void)
9441da177e4SLinus Torvalds {
9451da177e4SLinus Torvalds 	ConfigView* v;
9461da177e4SLinus Torvalds 
9471da177e4SLinus Torvalds 	for (v = viewList; v; v = v->nextView)
9481da177e4SLinus Torvalds 		v->list->updateListAll();
9491da177e4SLinus Torvalds }
9501da177e4SLinus Torvalds 
95143bf612aSRoman Zippel ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
952133c5f7cSAlexander Stein 	: Parent(parent, name), sym(0), _menu(0)
9531da177e4SLinus Torvalds {
9547fc925fdSRoman Zippel 	if (name) {
9557fc925fdSRoman Zippel 		configSettings->beginGroup(name);
9567fc925fdSRoman Zippel 		_showDebug = configSettings->readBoolEntry("/showDebug", false);
9577fc925fdSRoman Zippel 		configSettings->endGroup();
9587fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
9597fc925fdSRoman Zippel 	}
9607fc925fdSRoman Zippel }
9617fc925fdSRoman Zippel 
9627fc925fdSRoman Zippel void ConfigInfoView::saveSettings(void)
9637fc925fdSRoman Zippel {
9647fc925fdSRoman Zippel 	if (name()) {
9657fc925fdSRoman Zippel 		configSettings->beginGroup(name());
9667fc925fdSRoman Zippel 		configSettings->writeEntry("/showDebug", showDebug());
9677fc925fdSRoman Zippel 		configSettings->endGroup();
9687fc925fdSRoman Zippel 	}
9691da177e4SLinus Torvalds }
9701da177e4SLinus Torvalds 
97143bf612aSRoman Zippel void ConfigInfoView::setShowDebug(bool b)
9721da177e4SLinus Torvalds {
97343bf612aSRoman Zippel 	if (_showDebug != b) {
97443bf612aSRoman Zippel 		_showDebug = b;
975133c5f7cSAlexander Stein 		if (_menu)
97643bf612aSRoman Zippel 			menuInfo();
977ab45d190SRoman Zippel 		else if (sym)
978ab45d190SRoman Zippel 			symbolInfo();
97943bf612aSRoman Zippel 		emit showDebugChanged(b);
9801da177e4SLinus Torvalds 	}
9811da177e4SLinus Torvalds }
9821da177e4SLinus Torvalds 
98343bf612aSRoman Zippel void ConfigInfoView::setInfo(struct menu *m)
9841da177e4SLinus Torvalds {
985133c5f7cSAlexander Stein 	if (_menu == m)
986b65a47e1SRoman Zippel 		return;
987133c5f7cSAlexander Stein 	_menu = m;
9886fa1da8eSRoman Zippel 	sym = NULL;
989133c5f7cSAlexander Stein 	if (!_menu)
99043bf612aSRoman Zippel 		clear();
9916fa1da8eSRoman Zippel 	else
99243bf612aSRoman Zippel 		menuInfo();
9931da177e4SLinus Torvalds }
9941da177e4SLinus Torvalds 
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 
1016133c5f7cSAlexander Stein 	sym = _menu->sym;
10171da177e4SLinus Torvalds 	if (sym) {
1018133c5f7cSAlexander Stein 		if (_menu->prompt) {
10191da177e4SLinus Torvalds 			head += "<big><b>";
1020133c5f7cSAlexander Stein 			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 
1045d74c15f3SCheng Renquan 		struct gstr help_gstr = str_new();
1046133c5f7cSAlexander Stein 		menu_get_ext_help(_menu, &help_gstr);
1047d74c15f3SCheng Renquan 		help = print_filter(str_get(&help_gstr));
1048d74c15f3SCheng Renquan 		str_free(&help_gstr);
1049133c5f7cSAlexander Stein 	} else if (_menu->prompt) {
105043bf612aSRoman Zippel 		head += "<big><b>";
1051133c5f7cSAlexander Stein 		head += print_filter(_(_menu->prompt->text));
105243bf612aSRoman Zippel 		head += "</b></big><br><br>";
105343bf612aSRoman Zippel 		if (showDebug()) {
1054133c5f7cSAlexander Stein 			if (_menu->prompt->visible.expr) {
105543bf612aSRoman Zippel 				debug += "&nbsp;&nbsp;dep: ";
1056133c5f7cSAlexander Stein 				expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
105743bf612aSRoman Zippel 				debug += "<br><br>";
105843bf612aSRoman Zippel 			}
105943bf612aSRoman Zippel 		}
106043bf612aSRoman Zippel 	}
106143bf612aSRoman Zippel 	if (showDebug())
1062133c5f7cSAlexander Stein 		debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
106343bf612aSRoman Zippel 
106443bf612aSRoman Zippel 	setText(head + debug + help);
106543bf612aSRoman Zippel }
106643bf612aSRoman Zippel 
106743bf612aSRoman Zippel QString ConfigInfoView::debug_info(struct symbol *sym)
106843bf612aSRoman Zippel {
106943bf612aSRoman Zippel 	QString debug;
107043bf612aSRoman Zippel 
10711da177e4SLinus Torvalds 	debug += "type: ";
10721da177e4SLinus Torvalds 	debug += print_filter(sym_type_name(sym->type));
10731da177e4SLinus Torvalds 	if (sym_is_choice(sym))
10741da177e4SLinus Torvalds 		debug += " (choice)";
10751da177e4SLinus Torvalds 	debug += "<br>";
10761da177e4SLinus Torvalds 	if (sym->rev_dep.expr) {
10771da177e4SLinus Torvalds 		debug += "reverse dep: ";
10781da177e4SLinus Torvalds 		expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
10791da177e4SLinus Torvalds 		debug += "<br>";
10801da177e4SLinus Torvalds 	}
10811da177e4SLinus Torvalds 	for (struct property *prop = sym->prop; prop; prop = prop->next) {
10821da177e4SLinus Torvalds 		switch (prop->type) {
10831da177e4SLinus Torvalds 		case P_PROMPT:
10841da177e4SLinus Torvalds 		case P_MENU:
1085ab45d190SRoman Zippel 			debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
10863b9fa093SArnaldo Carvalho de Melo 			debug += print_filter(_(prop->text));
1087ab45d190SRoman Zippel 			debug += "</a><br>";
10881da177e4SLinus Torvalds 			break;
10891da177e4SLinus Torvalds 		case P_DEFAULT:
109093449082SRoman Zippel 		case P_SELECT:
109193449082SRoman Zippel 		case P_RANGE:
109293449082SRoman Zippel 		case P_ENV:
109393449082SRoman Zippel 			debug += prop_get_type_name(prop->type);
109493449082SRoman Zippel 			debug += ": ";
10951da177e4SLinus Torvalds 			expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10961da177e4SLinus Torvalds 			debug += "<br>";
10971da177e4SLinus Torvalds 			break;
10981da177e4SLinus Torvalds 		case P_CHOICE:
10991da177e4SLinus Torvalds 			if (sym_is_choice(sym)) {
11001da177e4SLinus Torvalds 				debug += "choice: ";
11011da177e4SLinus Torvalds 				expr_print(prop->expr, expr_print_help, &debug, E_NONE);
11021da177e4SLinus Torvalds 				debug += "<br>";
11031da177e4SLinus Torvalds 			}
11041da177e4SLinus Torvalds 			break;
11051da177e4SLinus Torvalds 		default:
11061da177e4SLinus Torvalds 			debug += "unknown property: ";
11071da177e4SLinus Torvalds 			debug += prop_get_type_name(prop->type);
11081da177e4SLinus Torvalds 			debug += "<br>";
11091da177e4SLinus Torvalds 		}
11101da177e4SLinus Torvalds 		if (prop->visible.expr) {
11111da177e4SLinus Torvalds 			debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
11121da177e4SLinus Torvalds 			expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
11131da177e4SLinus Torvalds 			debug += "<br>";
11141da177e4SLinus Torvalds 		}
11151da177e4SLinus Torvalds 	}
11161da177e4SLinus Torvalds 	debug += "<br>";
111743bf612aSRoman Zippel 
111843bf612aSRoman Zippel 	return debug;
11191da177e4SLinus Torvalds }
11201da177e4SLinus Torvalds 
112143bf612aSRoman Zippel QString ConfigInfoView::print_filter(const QString &str)
112243bf612aSRoman Zippel {
112343bf612aSRoman Zippel 	QRegExp re("[<>&\"\\n]");
112443bf612aSRoman Zippel 	QString res = str;
112543bf612aSRoman Zippel 	for (int i = 0; (i = res.find(re, i)) >= 0;) {
112643bf612aSRoman Zippel 		switch (res[i].latin1()) {
112743bf612aSRoman Zippel 		case '<':
112843bf612aSRoman Zippel 			res.replace(i, 1, "&lt;");
112943bf612aSRoman Zippel 			i += 4;
113043bf612aSRoman Zippel 			break;
113143bf612aSRoman Zippel 		case '>':
113243bf612aSRoman Zippel 			res.replace(i, 1, "&gt;");
113343bf612aSRoman Zippel 			i += 4;
113443bf612aSRoman Zippel 			break;
113543bf612aSRoman Zippel 		case '&':
113643bf612aSRoman Zippel 			res.replace(i, 1, "&amp;");
113743bf612aSRoman Zippel 			i += 5;
113843bf612aSRoman Zippel 			break;
113943bf612aSRoman Zippel 		case '"':
114043bf612aSRoman Zippel 			res.replace(i, 1, "&quot;");
114143bf612aSRoman Zippel 			i += 6;
114243bf612aSRoman Zippel 			break;
114343bf612aSRoman Zippel 		case '\n':
114443bf612aSRoman Zippel 			res.replace(i, 1, "<br>");
114543bf612aSRoman Zippel 			i += 4;
114643bf612aSRoman Zippel 			break;
11471da177e4SLinus Torvalds 		}
11481da177e4SLinus Torvalds 	}
114943bf612aSRoman Zippel 	return res;
11501da177e4SLinus Torvalds }
115143bf612aSRoman Zippel 
1152ab45d190SRoman Zippel void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
115343bf612aSRoman Zippel {
1154ab45d190SRoman Zippel 	QString* text = reinterpret_cast<QString*>(data);
1155ab45d190SRoman Zippel 	QString str2 = print_filter(str);
1156ab45d190SRoman Zippel 
1157ab45d190SRoman Zippel 	if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1158ab45d190SRoman Zippel 		*text += QString().sprintf("<a href=\"s%p\">", sym);
1159ab45d190SRoman Zippel 		*text += str2;
1160ab45d190SRoman Zippel 		*text += "</a>";
1161ab45d190SRoman Zippel 	} else
1162ab45d190SRoman Zippel 		*text += str2;
116343bf612aSRoman Zippel }
116443bf612aSRoman Zippel 
1165133c5f7cSAlexander Stein Q3PopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
11667fc925fdSRoman Zippel {
1167133c5f7cSAlexander Stein 	Q3PopupMenu* popup = Parent::createPopupMenu(pos);
1168133c5f7cSAlexander Stein 	Q3Action* action = new Q3Action(NULL, _("Show Debug Info"), 0, popup);
11697fc925fdSRoman Zippel 	  action->setToggleAction(TRUE);
11707fc925fdSRoman Zippel 	  connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
11717fc925fdSRoman Zippel 	  connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
11727fc925fdSRoman Zippel 	  action->setOn(showDebug());
11737fc925fdSRoman Zippel 	popup->insertSeparator();
11747fc925fdSRoman Zippel 	action->addTo(popup);
11757fc925fdSRoman Zippel 	return popup;
11767fc925fdSRoman Zippel }
11777fc925fdSRoman Zippel 
11787fc925fdSRoman Zippel void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e)
11797fc925fdSRoman Zippel {
11807fc925fdSRoman Zippel 	Parent::contentsContextMenuEvent(e);
11817fc925fdSRoman Zippel }
11827fc925fdSRoman Zippel 
118363431e75SMarco Costalba ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
11847fc925fdSRoman Zippel 	: Parent(parent, name), result(NULL)
118543bf612aSRoman Zippel {
118643bf612aSRoman Zippel 	setCaption("Search Config");
118743bf612aSRoman Zippel 
118843bf612aSRoman Zippel 	QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6);
118943bf612aSRoman Zippel 	QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6);
1190c21a2d95SEGRY Gabor 	layout2->addWidget(new QLabel(_("Find:"), this));
119143bf612aSRoman Zippel 	editField = new QLineEdit(this);
119243bf612aSRoman Zippel 	connect(editField, SIGNAL(returnPressed()), SLOT(search()));
119343bf612aSRoman Zippel 	layout2->addWidget(editField);
1194c21a2d95SEGRY Gabor 	searchButton = new QPushButton(_("Search"), this);
119543bf612aSRoman Zippel 	searchButton->setAutoDefault(FALSE);
119643bf612aSRoman Zippel 	connect(searchButton, SIGNAL(clicked()), SLOT(search()));
119743bf612aSRoman Zippel 	layout2->addWidget(searchButton);
119843bf612aSRoman Zippel 	layout1->addLayout(layout2);
119943bf612aSRoman Zippel 
12007fc925fdSRoman Zippel 	split = new QSplitter(this);
12017298b936SMarkus Heidelberg 	split->setOrientation(Qt::Vertical);
12027fc925fdSRoman Zippel 	list = new ConfigView(split, name);
120343bf612aSRoman Zippel 	list->list->mode = listMode;
12047fc925fdSRoman Zippel 	info = new ConfigInfoView(split, name);
120543bf612aSRoman Zippel 	connect(list->list, SIGNAL(menuChanged(struct menu *)),
120643bf612aSRoman Zippel 		info, SLOT(setInfo(struct menu *)));
120763431e75SMarco Costalba 	connect(list->list, SIGNAL(menuChanged(struct menu *)),
120863431e75SMarco Costalba 		parent, SLOT(setMenuLink(struct menu *)));
120963431e75SMarco Costalba 
121043bf612aSRoman Zippel 	layout1->addWidget(split);
12117fc925fdSRoman Zippel 
12127fc925fdSRoman Zippel 	if (name) {
12137fc925fdSRoman Zippel 		int x, y, width, height;
12147fc925fdSRoman Zippel 		bool ok;
12157fc925fdSRoman Zippel 
12167fc925fdSRoman Zippel 		configSettings->beginGroup(name);
12177fc925fdSRoman Zippel 		width = configSettings->readNumEntry("/window width", parent->width() / 2);
12187fc925fdSRoman Zippel 		height = configSettings->readNumEntry("/window height", parent->height() / 2);
12197fc925fdSRoman Zippel 		resize(width, height);
12207fc925fdSRoman Zippel 		x = configSettings->readNumEntry("/window x", 0, &ok);
12217fc925fdSRoman Zippel 		if (ok)
12227fc925fdSRoman Zippel 			y = configSettings->readNumEntry("/window y", 0, &ok);
12237fc925fdSRoman Zippel 		if (ok)
12247fc925fdSRoman Zippel 			move(x, y);
1225133c5f7cSAlexander Stein 		Q3ValueList<int> sizes = configSettings->readSizes("/split", &ok);
12267fc925fdSRoman Zippel 		if (ok)
12277fc925fdSRoman Zippel 			split->setSizes(sizes);
12287fc925fdSRoman Zippel 		configSettings->endGroup();
12297fc925fdSRoman Zippel 		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
12307fc925fdSRoman Zippel 	}
12317fc925fdSRoman Zippel }
12327fc925fdSRoman Zippel 
12337fc925fdSRoman Zippel void ConfigSearchWindow::saveSettings(void)
12347fc925fdSRoman Zippel {
12357fc925fdSRoman Zippel 	if (name()) {
12367fc925fdSRoman Zippel 		configSettings->beginGroup(name());
12377fc925fdSRoman Zippel 		configSettings->writeEntry("/window x", pos().x());
12387fc925fdSRoman Zippel 		configSettings->writeEntry("/window y", pos().y());
12397fc925fdSRoman Zippel 		configSettings->writeEntry("/window width", size().width());
12407fc925fdSRoman Zippel 		configSettings->writeEntry("/window height", size().height());
12417fc925fdSRoman Zippel 		configSettings->writeSizes("/split", split->sizes());
12427fc925fdSRoman Zippel 		configSettings->endGroup();
12437fc925fdSRoman Zippel 	}
124443bf612aSRoman Zippel }
124543bf612aSRoman Zippel 
124643bf612aSRoman Zippel void ConfigSearchWindow::search(void)
124743bf612aSRoman Zippel {
124843bf612aSRoman Zippel 	struct symbol **p;
124943bf612aSRoman Zippel 	struct property *prop;
125043bf612aSRoman Zippel 	ConfigItem *lastItem = NULL;
125143bf612aSRoman Zippel 
125243bf612aSRoman Zippel 	free(result);
125343bf612aSRoman Zippel 	list->list->clear();
1254786fb18dSCyrill V. Gorcunov 	info->clear();
125543bf612aSRoman Zippel 
125643bf612aSRoman Zippel 	result = sym_re_search(editField->text().latin1());
125743bf612aSRoman Zippel 	if (!result)
125843bf612aSRoman Zippel 		return;
125943bf612aSRoman Zippel 	for (p = result; *p; p++) {
126043bf612aSRoman Zippel 		for_all_prompts((*p), prop)
126143bf612aSRoman Zippel 			lastItem = new ConfigItem(list->list, lastItem, prop->menu,
126243bf612aSRoman Zippel 						  menu_is_visible(prop->menu));
126343bf612aSRoman Zippel 	}
126443bf612aSRoman Zippel }
126543bf612aSRoman Zippel 
126643bf612aSRoman Zippel /*
126743bf612aSRoman Zippel  * Construct the complete config widget
126843bf612aSRoman Zippel  */
126943bf612aSRoman Zippel ConfigMainWindow::ConfigMainWindow(void)
1270f12aa704SRoman Zippel 	: searchWindow(0)
127143bf612aSRoman Zippel {
127243bf612aSRoman Zippel 	QMenuBar* menu;
12737fc925fdSRoman Zippel 	bool ok;
127443bf612aSRoman Zippel 	int x, y, width, height;
1275a54bb701SRandy Dunlap 	char title[256];
127643bf612aSRoman Zippel 
12778d90c97eSMarkus Heidelberg 	QDesktopWidget *d = configApp->desktop();
12780954828fSArnaud Lacombe 	snprintf(title, sizeof(title), "%s%s",
12790954828fSArnaud Lacombe 		rootmenu.prompt->text,
128076a136c4SMichal Marek #if QT_VERSION < 0x040000
128176a136c4SMichal Marek 		" (Qt3)"
128276a136c4SMichal Marek #else
128376a136c4SMichal Marek 		""
128476a136c4SMichal Marek #endif
128576a136c4SMichal Marek 		);
1286a54bb701SRandy Dunlap 	setCaption(title);
128743bf612aSRoman Zippel 
12887fc925fdSRoman Zippel 	width = configSettings->readNumEntry("/window width", d->width() - 64);
12897fc925fdSRoman Zippel 	height = configSettings->readNumEntry("/window height", d->height() - 64);
129043bf612aSRoman Zippel 	resize(width, height);
12917fc925fdSRoman Zippel 	x = configSettings->readNumEntry("/window x", 0, &ok);
129243bf612aSRoman Zippel 	if (ok)
12937fc925fdSRoman Zippel 		y = configSettings->readNumEntry("/window y", 0, &ok);
129443bf612aSRoman Zippel 	if (ok)
129543bf612aSRoman Zippel 		move(x, y);
129643bf612aSRoman Zippel 
129743bf612aSRoman Zippel 	split1 = new QSplitter(this);
12987298b936SMarkus Heidelberg 	split1->setOrientation(Qt::Horizontal);
129943bf612aSRoman Zippel 	setCentralWidget(split1);
130043bf612aSRoman Zippel 
13017fc925fdSRoman Zippel 	menuView = new ConfigView(split1, "menu");
130243bf612aSRoman Zippel 	menuList = menuView->list;
130343bf612aSRoman Zippel 
130443bf612aSRoman Zippel 	split2 = new QSplitter(split1);
13057298b936SMarkus Heidelberg 	split2->setOrientation(Qt::Vertical);
130643bf612aSRoman Zippel 
130743bf612aSRoman Zippel 	// create config tree
13087fc925fdSRoman Zippel 	configView = new ConfigView(split2, "config");
130943bf612aSRoman Zippel 	configList = configView->list;
131043bf612aSRoman Zippel 
13117fc925fdSRoman Zippel 	helpText = new ConfigInfoView(split2, "help");
131243bf612aSRoman Zippel 	helpText->setTextFormat(Qt::RichText);
131343bf612aSRoman Zippel 
131443bf612aSRoman Zippel 	setTabOrder(configList, helpText);
131543bf612aSRoman Zippel 	configList->setFocus();
131643bf612aSRoman Zippel 
131743bf612aSRoman Zippel 	menu = menuBar();
1318133c5f7cSAlexander Stein 	toolBar = new Q3ToolBar("Tools", this);
131943bf612aSRoman Zippel 
1320133c5f7cSAlexander Stein 	backAction = new Q3Action("Back", QPixmap(xpm_back), _("Back"), 0, this);
132143bf612aSRoman Zippel 	  connect(backAction, SIGNAL(activated()), SLOT(goBack()));
132243bf612aSRoman Zippel 	  backAction->setEnabled(FALSE);
1323133c5f7cSAlexander Stein 	Q3Action *quitAction = new Q3Action("Quit", _("&Quit"), Qt::CTRL + Qt::Key_Q, this);
132443bf612aSRoman Zippel 	  connect(quitAction, SIGNAL(activated()), SLOT(close()));
1325133c5f7cSAlexander Stein 	Q3Action *loadAction = new Q3Action("Load", QPixmap(xpm_load), _("&Load"), Qt::CTRL + Qt::Key_L, this);
132643bf612aSRoman Zippel 	  connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
1327133c5f7cSAlexander Stein 	saveAction = new Q3Action("Save", QPixmap(xpm_save), _("&Save"), Qt::CTRL + Qt::Key_S, this);
132843bf612aSRoman Zippel 	  connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
13293b354c55SKarsten Wiese 	conf_set_changed_callback(conf_changed);
13303b354c55SKarsten Wiese 	// Set saveAction's initial state
13313b354c55SKarsten Wiese 	conf_changed();
1332133c5f7cSAlexander Stein 	Q3Action *saveAsAction = new Q3Action("Save As...", _("Save &As..."), 0, this);
133343bf612aSRoman Zippel 	  connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
1334133c5f7cSAlexander Stein 	Q3Action *searchAction = new Q3Action("Find", _("&Find"), Qt::CTRL + Qt::Key_F, this);
133543bf612aSRoman Zippel 	  connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
1336133c5f7cSAlexander Stein 	Q3Action *singleViewAction = new Q3Action("Single View", QPixmap(xpm_single_view), _("Single View"), 0, this);
133743bf612aSRoman Zippel 	  connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
1338133c5f7cSAlexander Stein 	Q3Action *splitViewAction = new Q3Action("Split View", QPixmap(xpm_split_view), _("Split View"), 0, this);
133943bf612aSRoman Zippel 	  connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
1340133c5f7cSAlexander Stein 	Q3Action *fullViewAction = new Q3Action("Full View", QPixmap(xpm_tree_view), _("Full View"), 0, this);
134143bf612aSRoman Zippel 	  connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
134243bf612aSRoman Zippel 
1343133c5f7cSAlexander Stein 	Q3Action *showNameAction = new Q3Action(NULL, _("Show Name"), 0, this);
134443bf612aSRoman Zippel 	  showNameAction->setToggleAction(TRUE);
13457fc925fdSRoman Zippel 	  connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
13467fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
13477fc925fdSRoman Zippel 	  showNameAction->setOn(configView->showName());
1348133c5f7cSAlexander Stein 	Q3Action *showRangeAction = new Q3Action(NULL, _("Show Range"), 0, this);
134943bf612aSRoman Zippel 	  showRangeAction->setToggleAction(TRUE);
13507fc925fdSRoman Zippel 	  connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
13517fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
135243bf612aSRoman Zippel 	  showRangeAction->setOn(configList->showRange);
1353133c5f7cSAlexander Stein 	Q3Action *showDataAction = new Q3Action(NULL, _("Show Data"), 0, this);
135443bf612aSRoman Zippel 	  showDataAction->setToggleAction(TRUE);
13557fc925fdSRoman Zippel 	  connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
13567fc925fdSRoman Zippel 	  connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
135743bf612aSRoman Zippel 	  showDataAction->setOn(configList->showData);
135839a4897cSLi Zefan 
135939a4897cSLi Zefan 	QActionGroup *optGroup = new QActionGroup(this);
136039a4897cSLi Zefan 	optGroup->setExclusive(TRUE);
136139a4897cSLi Zefan 	connect(optGroup, SIGNAL(selected(QAction *)), configView,
136239a4897cSLi Zefan 		SLOT(setOptionMode(QAction *)));
136339a4897cSLi Zefan 	connect(optGroup, SIGNAL(selected(QAction *)), menuView,
136439a4897cSLi Zefan 		SLOT(setOptionMode(QAction *)));
136539a4897cSLi Zefan 
1366133c5f7cSAlexander Stein #if QT_VERSION >= 0x040000
1367133c5f7cSAlexander Stein 	configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
1368133c5f7cSAlexander Stein 	configView->showAllAction = new QAction(_("Show All Options"), optGroup);
1369133c5f7cSAlexander Stein 	configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
1370133c5f7cSAlexander Stein #else
1371133c5f7cSAlexander Stein 	configView->showNormalAction = new QAction(_("Show Normal Options"), 0, optGroup);
1372133c5f7cSAlexander Stein 	configView->showAllAction = new QAction(_("Show All Options"), 0, optGroup);
1373133c5f7cSAlexander Stein 	configView->showPromptAction = new QAction(_("Show Prompt Options"), 0, optGroup);
1374133c5f7cSAlexander Stein #endif
137539a4897cSLi Zefan 	configView->showNormalAction->setToggleAction(TRUE);
137639a4897cSLi Zefan 	configView->showNormalAction->setOn(configList->optMode == normalOpt);
137739a4897cSLi Zefan 	configView->showAllAction->setToggleAction(TRUE);
137839a4897cSLi Zefan 	configView->showAllAction->setOn(configList->optMode == allOpt);
137939a4897cSLi Zefan 	configView->showPromptAction->setToggleAction(TRUE);
138039a4897cSLi Zefan 	configView->showPromptAction->setOn(configList->optMode == promptOpt);
138139a4897cSLi Zefan 
1382133c5f7cSAlexander Stein 	Q3Action *showDebugAction = new Q3Action(NULL, _("Show Debug Info"), 0, this);
138343bf612aSRoman Zippel 	  showDebugAction->setToggleAction(TRUE);
138443bf612aSRoman Zippel 	  connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
138543bf612aSRoman Zippel 	  connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
13867fc925fdSRoman Zippel 	  showDebugAction->setOn(helpText->showDebug());
138743bf612aSRoman Zippel 
1388133c5f7cSAlexander Stein 	Q3Action *showIntroAction = new Q3Action(NULL, _("Introduction"), 0, this);
138943bf612aSRoman Zippel 	  connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
1390133c5f7cSAlexander Stein 	Q3Action *showAboutAction = new Q3Action(NULL, _("About"), 0, this);
139143bf612aSRoman Zippel 	  connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
139243bf612aSRoman Zippel 
139343bf612aSRoman Zippel 	// init tool bar
139443bf612aSRoman Zippel 	backAction->addTo(toolBar);
139543bf612aSRoman Zippel 	toolBar->addSeparator();
139643bf612aSRoman Zippel 	loadAction->addTo(toolBar);
139743bf612aSRoman Zippel 	saveAction->addTo(toolBar);
139843bf612aSRoman Zippel 	toolBar->addSeparator();
139943bf612aSRoman Zippel 	singleViewAction->addTo(toolBar);
140043bf612aSRoman Zippel 	splitViewAction->addTo(toolBar);
140143bf612aSRoman Zippel 	fullViewAction->addTo(toolBar);
140243bf612aSRoman Zippel 
140343bf612aSRoman Zippel 	// create config menu
1404133c5f7cSAlexander Stein 	Q3PopupMenu* config = new Q3PopupMenu(this);
1405c21a2d95SEGRY Gabor 	menu->insertItem(_("&File"), config);
140643bf612aSRoman Zippel 	loadAction->addTo(config);
140743bf612aSRoman Zippel 	saveAction->addTo(config);
140843bf612aSRoman Zippel 	saveAsAction->addTo(config);
140943bf612aSRoman Zippel 	config->insertSeparator();
141043bf612aSRoman Zippel 	quitAction->addTo(config);
141143bf612aSRoman Zippel 
141266e7c723SShlomi Fish 	// create edit menu
1413133c5f7cSAlexander Stein 	Q3PopupMenu* editMenu = new Q3PopupMenu(this);
1414c21a2d95SEGRY Gabor 	menu->insertItem(_("&Edit"), editMenu);
141566e7c723SShlomi Fish 	searchAction->addTo(editMenu);
141666e7c723SShlomi Fish 
141743bf612aSRoman Zippel 	// create options menu
1418133c5f7cSAlexander Stein 	Q3PopupMenu* optionMenu = new Q3PopupMenu(this);
1419c21a2d95SEGRY Gabor 	menu->insertItem(_("&Option"), optionMenu);
142043bf612aSRoman Zippel 	showNameAction->addTo(optionMenu);
142143bf612aSRoman Zippel 	showRangeAction->addTo(optionMenu);
142243bf612aSRoman Zippel 	showDataAction->addTo(optionMenu);
142343bf612aSRoman Zippel 	optionMenu->insertSeparator();
142439a4897cSLi Zefan 	optGroup->addTo(optionMenu);
142539a4897cSLi Zefan 	optionMenu->insertSeparator();
142643bf612aSRoman Zippel 
142743bf612aSRoman Zippel 	// create help menu
1428133c5f7cSAlexander Stein 	Q3PopupMenu* helpMenu = new Q3PopupMenu(this);
142943bf612aSRoman Zippel 	menu->insertSeparator();
1430c21a2d95SEGRY Gabor 	menu->insertItem(_("&Help"), helpMenu);
143143bf612aSRoman Zippel 	showIntroAction->addTo(helpMenu);
143243bf612aSRoman Zippel 	showAboutAction->addTo(helpMenu);
143343bf612aSRoman Zippel 
143443bf612aSRoman Zippel 	connect(configList, SIGNAL(menuChanged(struct menu *)),
143543bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
143643bf612aSRoman Zippel 	connect(configList, SIGNAL(menuSelected(struct menu *)),
143743bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
143843bf612aSRoman Zippel 	connect(configList, SIGNAL(parentSelected()),
143943bf612aSRoman Zippel 		SLOT(goBack()));
144043bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuChanged(struct menu *)),
144143bf612aSRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
144243bf612aSRoman Zippel 	connect(menuList, SIGNAL(menuSelected(struct menu *)),
144343bf612aSRoman Zippel 		SLOT(changeMenu(struct menu *)));
144443bf612aSRoman Zippel 
1445b65a47e1SRoman Zippel 	connect(configList, SIGNAL(gotFocus(struct menu *)),
1446b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1447b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
1448b65a47e1SRoman Zippel 		helpText, SLOT(setInfo(struct menu *)));
1449b65a47e1SRoman Zippel 	connect(menuList, SIGNAL(gotFocus(struct menu *)),
145043bf612aSRoman Zippel 		SLOT(listFocusChanged(void)));
1451b65a47e1SRoman Zippel 	connect(helpText, SIGNAL(menuSelected(struct menu *)),
1452b65a47e1SRoman Zippel 		SLOT(setMenuLink(struct menu *)));
145343bf612aSRoman Zippel 
14547fc925fdSRoman Zippel 	QString listMode = configSettings->readEntry("/listMode", "symbol");
145543bf612aSRoman Zippel 	if (listMode == "single")
145643bf612aSRoman Zippel 		showSingleView();
145743bf612aSRoman Zippel 	else if (listMode == "full")
145843bf612aSRoman Zippel 		showFullView();
145943bf612aSRoman Zippel 	else /*if (listMode == "split")*/
146043bf612aSRoman Zippel 		showSplitView();
146143bf612aSRoman Zippel 
146243bf612aSRoman Zippel 	// UI setup done, restore splitter positions
1463133c5f7cSAlexander Stein 	Q3ValueList<int> sizes = configSettings->readSizes("/split1", &ok);
146443bf612aSRoman Zippel 	if (ok)
146543bf612aSRoman Zippel 		split1->setSizes(sizes);
146643bf612aSRoman Zippel 
14677fc925fdSRoman Zippel 	sizes = configSettings->readSizes("/split2", &ok);
146843bf612aSRoman Zippel 	if (ok)
146943bf612aSRoman Zippel 		split2->setSizes(sizes);
147043bf612aSRoman Zippel }
147143bf612aSRoman Zippel 
14721da177e4SLinus Torvalds void ConfigMainWindow::loadConfig(void)
14731da177e4SLinus Torvalds {
1474133c5f7cSAlexander Stein 	QString s = Q3FileDialog::getOpenFileName(conf_get_configname(), NULL, this);
14751da177e4SLinus Torvalds 	if (s.isNull())
14761da177e4SLinus Torvalds 		return;
14773b9fa093SArnaldo Carvalho de Melo 	if (conf_read(QFile::encodeName(s)))
1478c21a2d95SEGRY Gabor 		QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
14791da177e4SLinus Torvalds 	ConfigView::updateListAll();
14801da177e4SLinus Torvalds }
14811da177e4SLinus Torvalds 
1482bac6aa86SMichal Marek bool ConfigMainWindow::saveConfig(void)
14831da177e4SLinus Torvalds {
1484bac6aa86SMichal Marek 	if (conf_write(NULL)) {
1485c21a2d95SEGRY Gabor 		QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
1486bac6aa86SMichal Marek 		return false;
1487bac6aa86SMichal Marek 	}
1488bac6aa86SMichal Marek 	return true;
14891da177e4SLinus Torvalds }
14901da177e4SLinus Torvalds 
14911da177e4SLinus Torvalds void ConfigMainWindow::saveConfigAs(void)
14921da177e4SLinus Torvalds {
1493133c5f7cSAlexander Stein 	QString s = Q3FileDialog::getSaveFileName(conf_get_configname(), NULL, this);
14941da177e4SLinus Torvalds 	if (s.isNull())
14951da177e4SLinus Torvalds 		return;
1496d49e4687SArnaud Lacombe 	saveConfig();
14971da177e4SLinus Torvalds }
14981da177e4SLinus Torvalds 
149943bf612aSRoman Zippel void ConfigMainWindow::searchConfig(void)
150043bf612aSRoman Zippel {
150143bf612aSRoman Zippel 	if (!searchWindow)
15027fc925fdSRoman Zippel 		searchWindow = new ConfigSearchWindow(this, "search");
150343bf612aSRoman Zippel 	searchWindow->show();
150443bf612aSRoman Zippel }
150543bf612aSRoman Zippel 
15061da177e4SLinus Torvalds void ConfigMainWindow::changeMenu(struct menu *menu)
15071da177e4SLinus Torvalds {
15081da177e4SLinus Torvalds 	configList->setRootMenu(menu);
1509f253f000SCyrill V. Gorcunov 	if (configList->rootEntry->parent == &rootmenu)
1510f253f000SCyrill V. Gorcunov 		backAction->setEnabled(FALSE);
1511f253f000SCyrill V. Gorcunov 	else
15121da177e4SLinus Torvalds 		backAction->setEnabled(TRUE);
15131da177e4SLinus Torvalds }
15141da177e4SLinus Torvalds 
1515b65a47e1SRoman Zippel void ConfigMainWindow::setMenuLink(struct menu *menu)
1516b65a47e1SRoman Zippel {
1517b65a47e1SRoman Zippel 	struct menu *parent;
1518b65a47e1SRoman Zippel 	ConfigList* list = NULL;
1519b65a47e1SRoman Zippel 	ConfigItem* item;
1520b65a47e1SRoman Zippel 
152139a4897cSLi Zefan 	if (configList->menuSkip(menu))
1522b65a47e1SRoman Zippel 		return;
1523b65a47e1SRoman Zippel 
1524b65a47e1SRoman Zippel 	switch (configList->mode) {
1525b65a47e1SRoman Zippel 	case singleMode:
1526b65a47e1SRoman Zippel 		list = configList;
1527b65a47e1SRoman Zippel 		parent = menu_get_parent_menu(menu);
1528b65a47e1SRoman Zippel 		if (!parent)
1529b65a47e1SRoman Zippel 			return;
1530b65a47e1SRoman Zippel 		list->setRootMenu(parent);
1531b65a47e1SRoman Zippel 		break;
1532b65a47e1SRoman Zippel 	case symbolMode:
1533b65a47e1SRoman Zippel 		if (menu->flags & MENU_ROOT) {
1534b65a47e1SRoman Zippel 			configList->setRootMenu(menu);
1535b65a47e1SRoman Zippel 			configList->clearSelection();
1536b65a47e1SRoman Zippel 			list = menuList;
1537b65a47e1SRoman Zippel 		} else {
1538b65a47e1SRoman Zippel 			list = configList;
1539b65a47e1SRoman Zippel 			parent = menu_get_parent_menu(menu->parent);
1540b65a47e1SRoman Zippel 			if (!parent)
1541b65a47e1SRoman Zippel 				return;
1542b65a47e1SRoman Zippel 			item = menuList->findConfigItem(parent);
1543b65a47e1SRoman Zippel 			if (item) {
1544b65a47e1SRoman Zippel 				menuList->setSelected(item, TRUE);
1545b65a47e1SRoman Zippel 				menuList->ensureItemVisible(item);
1546b65a47e1SRoman Zippel 			}
1547b65a47e1SRoman Zippel 			list->setRootMenu(parent);
1548b65a47e1SRoman Zippel 		}
1549b65a47e1SRoman Zippel 		break;
1550b65a47e1SRoman Zippel 	case fullMode:
1551b65a47e1SRoman Zippel 		list = configList;
1552b65a47e1SRoman Zippel 		break;
155398403a91SMarkus Heidelberg 	default:
155498403a91SMarkus Heidelberg 		break;
1555b65a47e1SRoman Zippel 	}
1556b65a47e1SRoman Zippel 
1557b65a47e1SRoman Zippel 	if (list) {
1558b65a47e1SRoman Zippel 		item = list->findConfigItem(menu);
1559b65a47e1SRoman Zippel 		if (item) {
1560b65a47e1SRoman Zippel 			list->setSelected(item, TRUE);
1561b65a47e1SRoman Zippel 			list->ensureItemVisible(item);
1562b65a47e1SRoman Zippel 			list->setFocus();
1563b65a47e1SRoman Zippel 		}
1564b65a47e1SRoman Zippel 	}
1565b65a47e1SRoman Zippel }
1566b65a47e1SRoman Zippel 
15671da177e4SLinus Torvalds void ConfigMainWindow::listFocusChanged(void)
15681da177e4SLinus Torvalds {
15691da177e4SLinus Torvalds 	if (menuList->mode == menuMode)
15701da177e4SLinus Torvalds 		configList->clearSelection();
15711da177e4SLinus Torvalds }
15721da177e4SLinus Torvalds 
15731da177e4SLinus Torvalds void ConfigMainWindow::goBack(void)
15741da177e4SLinus Torvalds {
15751da177e4SLinus Torvalds 	ConfigItem* item;
15761da177e4SLinus Torvalds 
15771da177e4SLinus Torvalds 	configList->setParentMenu();
15781da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15791da177e4SLinus Torvalds 		backAction->setEnabled(FALSE);
15801da177e4SLinus Torvalds 	item = (ConfigItem*)menuList->selectedItem();
15811da177e4SLinus Torvalds 	while (item) {
15821da177e4SLinus Torvalds 		if (item->menu == configList->rootEntry) {
15831da177e4SLinus Torvalds 			menuList->setSelected(item, TRUE);
15841da177e4SLinus Torvalds 			break;
15851da177e4SLinus Torvalds 		}
15861da177e4SLinus Torvalds 		item = (ConfigItem*)item->parent();
15871da177e4SLinus Torvalds 	}
15881da177e4SLinus Torvalds }
15891da177e4SLinus Torvalds 
15901da177e4SLinus Torvalds void ConfigMainWindow::showSingleView(void)
15911da177e4SLinus Torvalds {
15921da177e4SLinus Torvalds 	menuView->hide();
15931da177e4SLinus Torvalds 	menuList->setRootMenu(0);
15941da177e4SLinus Torvalds 	configList->mode = singleMode;
15951da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
15961da177e4SLinus Torvalds 		configList->updateListAll();
15971da177e4SLinus Torvalds 	else
15981da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
15991da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
16001da177e4SLinus Torvalds 	configList->setFocus();
16011da177e4SLinus Torvalds }
16021da177e4SLinus Torvalds 
16031da177e4SLinus Torvalds void ConfigMainWindow::showSplitView(void)
16041da177e4SLinus Torvalds {
16051da177e4SLinus Torvalds 	configList->mode = symbolMode;
16061da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
16071da177e4SLinus Torvalds 		configList->updateListAll();
16081da177e4SLinus Torvalds 	else
16091da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
16101da177e4SLinus Torvalds 	configList->setAllOpen(TRUE);
16111da177e4SLinus Torvalds 	configApp->processEvents();
16121da177e4SLinus Torvalds 	menuList->mode = menuMode;
16131da177e4SLinus Torvalds 	menuList->setRootMenu(&rootmenu);
16141da177e4SLinus Torvalds 	menuList->setAllOpen(TRUE);
16151da177e4SLinus Torvalds 	menuView->show();
16161da177e4SLinus Torvalds 	menuList->setFocus();
16171da177e4SLinus Torvalds }
16181da177e4SLinus Torvalds 
16191da177e4SLinus Torvalds void ConfigMainWindow::showFullView(void)
16201da177e4SLinus Torvalds {
16211da177e4SLinus Torvalds 	menuView->hide();
16221da177e4SLinus Torvalds 	menuList->setRootMenu(0);
16231da177e4SLinus Torvalds 	configList->mode = fullMode;
16241da177e4SLinus Torvalds 	if (configList->rootEntry == &rootmenu)
16251da177e4SLinus Torvalds 		configList->updateListAll();
16261da177e4SLinus Torvalds 	else
16271da177e4SLinus Torvalds 		configList->setRootMenu(&rootmenu);
16281da177e4SLinus Torvalds 	configList->setAllOpen(FALSE);
16291da177e4SLinus Torvalds 	configList->setFocus();
16301da177e4SLinus Torvalds }
16311da177e4SLinus Torvalds 
16321da177e4SLinus Torvalds /*
16331da177e4SLinus Torvalds  * ask for saving configuration before quitting
16341da177e4SLinus Torvalds  * TODO ask only when something changed
16351da177e4SLinus Torvalds  */
16361da177e4SLinus Torvalds void ConfigMainWindow::closeEvent(QCloseEvent* e)
16371da177e4SLinus Torvalds {
1638b3214293SKarsten Wiese 	if (!conf_get_changed()) {
16391da177e4SLinus Torvalds 		e->accept();
16401da177e4SLinus Torvalds 		return;
16411da177e4SLinus Torvalds 	}
1642c21a2d95SEGRY Gabor 	QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
16431da177e4SLinus Torvalds 			QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
1644c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
1645c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
1646c21a2d95SEGRY Gabor 	mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
16471da177e4SLinus Torvalds 	switch (mb.exec()) {
16481da177e4SLinus Torvalds 	case QMessageBox::Yes:
1649bac6aa86SMichal Marek 		if (saveConfig())
1650bac6aa86SMichal Marek 			e->accept();
1651bac6aa86SMichal Marek 		else
1652bac6aa86SMichal Marek 			e->ignore();
1653bac6aa86SMichal Marek 		break;
16541da177e4SLinus Torvalds 	case QMessageBox::No:
16551da177e4SLinus Torvalds 		e->accept();
16561da177e4SLinus Torvalds 		break;
16571da177e4SLinus Torvalds 	case QMessageBox::Cancel:
16581da177e4SLinus Torvalds 		e->ignore();
16591da177e4SLinus Torvalds 		break;
16601da177e4SLinus Torvalds 	}
16611da177e4SLinus Torvalds }
16621da177e4SLinus Torvalds 
16631da177e4SLinus Torvalds void ConfigMainWindow::showIntro(void)
16641da177e4SLinus Torvalds {
1665652cf982SArnaud Lacombe 	static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
16661da177e4SLinus Torvalds 		"For each option, a blank box indicates the feature is disabled, a check\n"
16671da177e4SLinus Torvalds 		"indicates it is enabled, and a dot indicates that it is to be compiled\n"
16681da177e4SLinus Torvalds 		"as a module.  Clicking on the box will cycle through the three states.\n\n"
16691da177e4SLinus Torvalds 		"If you do not see an option (e.g., a device driver) that you believe\n"
16701da177e4SLinus Torvalds 		"should be present, try turning on Show All Options under the Options menu.\n"
16711da177e4SLinus Torvalds 		"Although there is no cross reference yet to help you figure out what other\n"
16721da177e4SLinus Torvalds 		"options must be enabled to support the option you are interested in, you can\n"
16731da177e4SLinus Torvalds 		"still view the help of a grayed-out option.\n\n"
16741da177e4SLinus Torvalds 		"Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1675c21a2d95SEGRY Gabor 		"which you can then match by examining other options.\n\n");
16761da177e4SLinus Torvalds 
16771da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16781da177e4SLinus Torvalds }
16791da177e4SLinus Torvalds 
16801da177e4SLinus Torvalds void ConfigMainWindow::showAbout(void)
16811da177e4SLinus Torvalds {
1682c21a2d95SEGRY Gabor 	static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1683c21a2d95SEGRY Gabor 		"Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
16841da177e4SLinus Torvalds 
16851da177e4SLinus Torvalds 	QMessageBox::information(this, "qconf", str);
16861da177e4SLinus Torvalds }
16871da177e4SLinus Torvalds 
16881da177e4SLinus Torvalds void ConfigMainWindow::saveSettings(void)
16891da177e4SLinus Torvalds {
16907fc925fdSRoman Zippel 	configSettings->writeEntry("/window x", pos().x());
16917fc925fdSRoman Zippel 	configSettings->writeEntry("/window y", pos().y());
16927fc925fdSRoman Zippel 	configSettings->writeEntry("/window width", size().width());
16937fc925fdSRoman Zippel 	configSettings->writeEntry("/window height", size().height());
16941da177e4SLinus Torvalds 
16951da177e4SLinus Torvalds 	QString entry;
16961da177e4SLinus Torvalds 	switch(configList->mode) {
16971da177e4SLinus Torvalds 	case singleMode :
16981da177e4SLinus Torvalds 		entry = "single";
16991da177e4SLinus Torvalds 		break;
17001da177e4SLinus Torvalds 
17011da177e4SLinus Torvalds 	case symbolMode :
17021da177e4SLinus Torvalds 		entry = "split";
17031da177e4SLinus Torvalds 		break;
17041da177e4SLinus Torvalds 
17051da177e4SLinus Torvalds 	case fullMode :
17061da177e4SLinus Torvalds 		entry = "full";
17071da177e4SLinus Torvalds 		break;
170898403a91SMarkus Heidelberg 
170998403a91SMarkus Heidelberg 	default:
171098403a91SMarkus Heidelberg 		break;
17111da177e4SLinus Torvalds 	}
17127fc925fdSRoman Zippel 	configSettings->writeEntry("/listMode", entry);
17131da177e4SLinus Torvalds 
17147fc925fdSRoman Zippel 	configSettings->writeSizes("/split1", split1->sizes());
17157fc925fdSRoman Zippel 	configSettings->writeSizes("/split2", split2->sizes());
17161da177e4SLinus Torvalds }
17171da177e4SLinus Torvalds 
17183b354c55SKarsten Wiese void ConfigMainWindow::conf_changed(void)
17193b354c55SKarsten Wiese {
17203b354c55SKarsten Wiese 	if (saveAction)
17213b354c55SKarsten Wiese 		saveAction->setEnabled(conf_get_changed());
17223b354c55SKarsten Wiese }
17233b354c55SKarsten Wiese 
17241da177e4SLinus Torvalds void fixup_rootmenu(struct menu *menu)
17251da177e4SLinus Torvalds {
17261da177e4SLinus Torvalds 	struct menu *child;
17271da177e4SLinus Torvalds 	static int menu_cnt = 0;
17281da177e4SLinus Torvalds 
17291da177e4SLinus Torvalds 	menu->flags |= MENU_ROOT;
17301da177e4SLinus Torvalds 	for (child = menu->list; child; child = child->next) {
17311da177e4SLinus Torvalds 		if (child->prompt && child->prompt->type == P_MENU) {
17321da177e4SLinus Torvalds 			menu_cnt++;
17331da177e4SLinus Torvalds 			fixup_rootmenu(child);
17341da177e4SLinus Torvalds 			menu_cnt--;
17351da177e4SLinus Torvalds 		} else if (!menu_cnt)
17361da177e4SLinus Torvalds 			fixup_rootmenu(child);
17371da177e4SLinus Torvalds 	}
17381da177e4SLinus Torvalds }
17391da177e4SLinus Torvalds 
17401da177e4SLinus Torvalds static const char *progname;
17411da177e4SLinus Torvalds 
17421da177e4SLinus Torvalds static void usage(void)
17431da177e4SLinus Torvalds {
1744c21a2d95SEGRY Gabor 	printf(_("%s <config>\n"), progname);
17451da177e4SLinus Torvalds 	exit(0);
17461da177e4SLinus Torvalds }
17471da177e4SLinus Torvalds 
17481da177e4SLinus Torvalds int main(int ac, char** av)
17491da177e4SLinus Torvalds {
17501da177e4SLinus Torvalds 	ConfigMainWindow* v;
17511da177e4SLinus Torvalds 	const char *name;
17521da177e4SLinus Torvalds 
17533b9fa093SArnaldo Carvalho de Melo 	bindtextdomain(PACKAGE, LOCALEDIR);
17543b9fa093SArnaldo Carvalho de Melo 	textdomain(PACKAGE);
17553b9fa093SArnaldo Carvalho de Melo 
17561da177e4SLinus Torvalds 	progname = av[0];
17571da177e4SLinus Torvalds 	configApp = new QApplication(ac, av);
17581da177e4SLinus Torvalds 	if (ac > 1 && av[1][0] == '-') {
17591da177e4SLinus Torvalds 		switch (av[1][1]) {
17601da177e4SLinus Torvalds 		case 'h':
17611da177e4SLinus Torvalds 		case '?':
17621da177e4SLinus Torvalds 			usage();
17631da177e4SLinus Torvalds 		}
17641da177e4SLinus Torvalds 		name = av[2];
17651da177e4SLinus Torvalds 	} else
17661da177e4SLinus Torvalds 		name = av[1];
17671da177e4SLinus Torvalds 	if (!name)
17681da177e4SLinus Torvalds 		usage();
17691da177e4SLinus Torvalds 
17701da177e4SLinus Torvalds 	conf_parse(name);
17711da177e4SLinus Torvalds 	fixup_rootmenu(&rootmenu);
17721da177e4SLinus Torvalds 	conf_read(NULL);
17731da177e4SLinus Torvalds 	//zconfdump(stdout);
17741da177e4SLinus Torvalds 
17757fc925fdSRoman Zippel 	configSettings = new ConfigSettings();
17767fc925fdSRoman Zippel 	configSettings->beginGroup("/kconfig/qconf");
17771da177e4SLinus Torvalds 	v = new ConfigMainWindow();
17781da177e4SLinus Torvalds 
17791da177e4SLinus Torvalds 	//zconfdump(stdout);
178043bf612aSRoman Zippel 	configApp->setMainWidget(v);
17811da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
17821da177e4SLinus Torvalds 	configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
178343bf612aSRoman Zippel 	v->show();
17841da177e4SLinus Torvalds 	configApp->exec();
17851da177e4SLinus Torvalds 
17867fc925fdSRoman Zippel 	configSettings->endGroup();
17877fc925fdSRoman Zippel 	delete configSettings;
17887fc925fdSRoman Zippel 
17891da177e4SLinus Torvalds 	return 0;
17901da177e4SLinus Torvalds }
1791