1879 lines · 44.2 KB · C++
RawDownload
/* * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com> * Released under the terms of the GNU GPL v2.0. */ #include <qglobal.h> #include <QMainWindow>#include <QList>#include <qtextbrowser.h>#include <QAction>#include <QFileDialog>#include <QMenu> #include <qapplication.h>#include <qdesktopwidget.h>#include <qtoolbar.h>#include <qlayout.h>#include <qsplitter.h>#include <qlineedit.h>#include <qlabel.h>#include <qpushbutton.h>#include <qmenubar.h>#include <qmessagebox.h>#include <qregexp.h>#include <qevent.h> #include <stdlib.h> #include "lkc.h"#include "qconf.h" #include "qconf.moc"#include "images.c" #ifdef _# undef _# define _ qgettext#endif static QApplication *configApp;static ConfigSettings *configSettings; QAction *ConfigMainWindow::saveAction; static inline QString qgettext(const char* str){	return QString::fromLocal8Bit(gettext(str));} static inline QString qgettext(const QString& str){	return QString::fromLocal8Bit(gettext(str.toLatin1()));} ConfigSettings::ConfigSettings()	: QSettings("kernel.org", "qconf"){} /** * Reads a list of integer values from the application settings. */QList<int> ConfigSettings::readSizes(const QString& key, bool *ok){	QList<int> result; 	if (contains(key))	{		QStringList entryList = value(key).toStringList();		QStringList::Iterator it; 		for (it = entryList.begin(); it != entryList.end(); ++it)			result.push_back((*it).toInt()); 		*ok = true;	}	else		*ok = false; 	return result;} /** * Writes a list of integer values to the application settings. */bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value){	QStringList stringList;	QList<int>::ConstIterator it; 	for (it = value.begin(); it != value.end(); ++it)		stringList.push_back(QString::number(*it));	setValue(key, stringList); 	return true;}  /* * set the new data * TODO check the value */void ConfigItem::okRename(int col){} /* * update the displayed of a menu entry */void ConfigItem::updateMenu(void){	ConfigList* list;	struct symbol* sym;	struct property *prop;	QString prompt;	int type;	tristate expr; 	list = listView();	if (goParent) {		setPixmap(promptColIdx, list->menuBackPix);		prompt = "..";		goto set_prompt;	} 	sym = menu->sym;	prop = menu->prompt;	prompt = _(menu_get_prompt(menu)); 	if (prop) switch (prop->type) {	case P_MENU:		if (list->mode == singleMode || list->mode == symbolMode) {			/* a menuconfig entry is displayed differently			 * depending whether it's at the view root or a child.			 */			if (sym && list->rootEntry == menu)				break;			setPixmap(promptColIdx, list->menuPix);		} else {			if (sym)				break;			setPixmap(promptColIdx, QIcon());		}		goto set_prompt;	case P_COMMENT:		setPixmap(promptColIdx, QIcon());		goto set_prompt;	default:		;	}	if (!sym)		goto set_prompt; 	setText(nameColIdx, QString::fromLocal8Bit(sym->name)); 	type = sym_get_type(sym);	switch (type) {	case S_BOOLEAN:	case S_TRISTATE:		char ch; 		if (!sym_is_changable(sym) && list->optMode == normalOpt) {			setPixmap(promptColIdx, QIcon());			setText(noColIdx, QString::null);			setText(modColIdx, QString::null);			setText(yesColIdx, QString::null);			break;		}		expr = sym_get_tristate_value(sym);		switch (expr) {		case yes:			if (sym_is_choice_value(sym) && type == S_BOOLEAN)				setPixmap(promptColIdx, list->choiceYesPix);			else				setPixmap(promptColIdx, list->symbolYesPix);			setText(yesColIdx, "Y");			ch = 'Y';			break;		case mod:			setPixmap(promptColIdx, list->symbolModPix);			setText(modColIdx, "M");			ch = 'M';			break;		default:			if (sym_is_choice_value(sym) && type == S_BOOLEAN)				setPixmap(promptColIdx, list->choiceNoPix);			else				setPixmap(promptColIdx, list->symbolNoPix);			setText(noColIdx, "N");			ch = 'N';			break;		}		if (expr != no)			setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);		if (expr != mod)			setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);		if (expr != yes)			setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0); 		setText(dataColIdx, QChar(ch));		break;	case S_INT:	case S_HEX:	case S_STRING:		const char* data; 		data = sym_get_string_value(sym); 		setText(dataColIdx, data);		if (type == S_STRING)			prompt = QString("%1: %2").arg(prompt).arg(data);		else			prompt = QString("(%2) %1").arg(prompt).arg(data);		break;	}	if (!sym_has_value(sym) && visible)		prompt += _(" (NEW)");set_prompt:	setText(promptColIdx, prompt);} void ConfigItem::testUpdateMenu(bool v){	ConfigItem* i; 	visible = v;	if (!menu)		return; 	sym_calc_value(menu->sym);	if (menu->flags & MENU_CHANGED) {		/* the menu entry changed, so update all list items */		menu->flags &= ~MENU_CHANGED;		for (i = (ConfigItem*)menu->data; i; i = i->nextItem)			i->updateMenu();	} else if (listView()->updateAll)		updateMenu();}  /* * construct a menu entry */void ConfigItem::init(void){	if (menu) {		ConfigList* list = listView();		nextItem = (ConfigItem*)menu->data;		menu->data = this; 		if (list->mode != fullMode)			setExpanded(true);		sym_calc_value(menu->sym);	}	updateMenu();} /* * destruct a menu entry */ConfigItem::~ConfigItem(void){	if (menu) {		ConfigItem** ip = (ConfigItem**)&menu->data;		for (; *ip; ip = &(*ip)->nextItem) {			if (*ip == this) {				*ip = nextItem;				break;			}		}	}} ConfigLineEdit::ConfigLineEdit(ConfigView* parent)	: Parent(parent){	connect(this, SIGNAL(editingFinished()), SLOT(hide()));} void ConfigLineEdit::show(ConfigItem* i){	item = i;	if (sym_get_string_value(item->menu->sym))		setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));	else		setText(QString::null);	Parent::show();	setFocus();} void ConfigLineEdit::keyPressEvent(QKeyEvent* e){	switch (e->key()) {	case Qt::Key_Escape:		break;	case Qt::Key_Return:	case Qt::Key_Enter:		sym_set_string_value(item->menu->sym, text().toLatin1());		parent()->updateList(item);		break;	default:		Parent::keyPressEvent(e);		return;	}	e->accept();	parent()->list->setFocus();	hide();} ConfigList::ConfigList(ConfigView* p, const char *name)	: Parent(p),	  updateAll(false),	  symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),	  choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),	  menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),	  showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),	  rootEntry(0), headerPopup(0){	int i; 	setObjectName(name);	setSortingEnabled(false);	setRootIsDecorated(true); 	setVerticalScrollMode(ScrollPerPixel);	setHorizontalScrollMode(ScrollPerPixel); 	setHeaderLabels(QStringList() << _("Option") << _("Name") << "N" << "M" << "Y" << _("Value")); 	connect(this, SIGNAL(itemSelectionChanged(void)),		SLOT(updateSelection(void))); 	if (name) {		configSettings->beginGroup(name);		showName = configSettings->value("/showName", false).toBool();		showRange = configSettings->value("/showRange", false).toBool();		showData = configSettings->value("/showData", false).toBool();		optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();		configSettings->endGroup();		connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));	} 	addColumn(promptColIdx); 	reinit();} bool ConfigList::menuSkip(struct menu *menu){	if (optMode == normalOpt && menu_is_visible(menu))		return false;	if (optMode == promptOpt && menu_has_prompt(menu))		return false;	if (optMode == allOpt)		return false;	return true;} void ConfigList::reinit(void){	removeColumn(dataColIdx);	removeColumn(yesColIdx);	removeColumn(modColIdx);	removeColumn(noColIdx);	removeColumn(nameColIdx); 	if (showName)		addColumn(nameColIdx);	if (showRange) {		addColumn(noColIdx);		addColumn(modColIdx);		addColumn(yesColIdx);	}	if (showData)		addColumn(dataColIdx); 	updateListAll();} void ConfigList::saveSettings(void){	if (!objectName().isEmpty()) {		configSettings->beginGroup(objectName());		configSettings->setValue("/showName", showName);		configSettings->setValue("/showRange", showRange);		configSettings->setValue("/showData", showData);		configSettings->setValue("/optionMode", (int)optMode);		configSettings->endGroup();	}} ConfigItem* ConfigList::findConfigItem(struct menu *menu){	ConfigItem* item = (ConfigItem*)menu->data; 	for (; item; item = item->nextItem) {		if (this == item->listView())			break;	} 	return item;} void ConfigList::updateSelection(void){	struct menu *menu;	enum prop_type type; 	if (selectedItems().count() == 0)		return; 	ConfigItem* item = (ConfigItem*)selectedItems().first();	if (!item)		return; 	menu = item->menu;	emit menuChanged(menu);	if (!menu)		return;	type = menu->prompt ? menu->prompt->type : P_UNKNOWN;	if (mode == menuMode && type == P_MENU)		emit menuSelected(menu);} void ConfigList::updateList(ConfigItem* item){	ConfigItem* last = 0; 	if (!rootEntry) {		if (mode != listMode)			goto update;		QTreeWidgetItemIterator it(this);		ConfigItem* item; 		while (*it) {			item = (ConfigItem*)(*it);			if (!item->menu)				continue;			item->testUpdateMenu(menu_is_visible(item->menu)); 			++it;		}		return;	} 	if (rootEntry != &rootmenu && (mode == singleMode ||	    (mode == symbolMode && rootEntry->parent != &rootmenu))) {		item = (ConfigItem *)topLevelItem(0);		if (!item)			item = new ConfigItem(this, 0, true);		last = item;	}	if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&	    rootEntry->sym && rootEntry->prompt) {		item = last ? last->nextSibling() : firstChild();		if (!item)			item = new ConfigItem(this, last, rootEntry, true);		else			item->testUpdateMenu(true); 		updateMenuList(item, rootEntry);		update();		resizeColumnToContents(0);		return;	}update:	updateMenuList(this, rootEntry);	update();	resizeColumnToContents(0);} void ConfigList::setValue(ConfigItem* item, tristate val){	struct symbol* sym;	int type;	tristate oldval; 	sym = item->menu ? item->menu->sym : 0;	if (!sym)		return; 	type = sym_get_type(sym);	switch (type) {	case S_BOOLEAN:	case S_TRISTATE:		oldval = sym_get_tristate_value(sym); 		if (!sym_set_tristate_value(sym, val))			return;		if (oldval == no && item->menu->list)			item->setExpanded(true);		parent()->updateList(item);		break;	}} void ConfigList::changeValue(ConfigItem* item){

Lines 1–500 of 1879.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t