1963 lines · 45.1 KB · C++
RawDownload
// SPDX-License-Identifier: GPL-2.0/* * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com> */ #include <QAction>#include <QApplication>#include <QCloseEvent>#include <QDebug>#include <QDesktopWidget>#include <QFileDialog>#include <QLabel>#include <QLayout>#include <QList>#include <QMenu>#include <QMenuBar>#include <QMessageBox>#include <QToolBar> #include <stdlib.h> #include "lkc.h"#include "qconf.h" #include "images.h"  static QApplication *configApp;static ConfigSettings *configSettings; QAction *ConfigMainWindow::saveAction; 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;} QIcon ConfigItem::symbolYesIcon;QIcon ConfigItem::symbolModIcon;QIcon ConfigItem::symbolNoIcon;QIcon ConfigItem::choiceYesIcon;QIcon ConfigItem::choiceNoIcon;QIcon ConfigItem::menuIcon;QIcon ConfigItem::menubackIcon; /* * 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) {		setIcon(promptColIdx, menubackIcon);		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;			setIcon(promptColIdx, menuIcon);		} else {			if (sym)				break;			setIcon(promptColIdx, QIcon());		}		goto set_prompt;	case P_COMMENT:		setIcon(promptColIdx, QIcon());		goto set_prompt;	default:		;	}	if (!sym)		goto set_prompt; 	setText(nameColIdx, sym->name); 	type = sym_get_type(sym);	switch (type) {	case S_BOOLEAN:	case S_TRISTATE:		char ch; 		if (!sym_is_changeable(sym) && list->optMode == normalOpt) {			setIcon(promptColIdx, QIcon());			setText(noColIdx, QString());			setText(modColIdx, QString());			setText(yesColIdx, QString());			break;		}		expr = sym_get_tristate_value(sym);		switch (expr) {		case yes:			if (sym_is_choice_value(sym) && type == S_BOOLEAN)				setIcon(promptColIdx, choiceYesIcon);			else				setIcon(promptColIdx, symbolYesIcon);			setText(yesColIdx, "Y");			ch = 'Y';			break;		case mod:			setIcon(promptColIdx, symbolModIcon);			setText(modColIdx, "M");			ch = 'M';			break;		default:			if (sym_is_choice_value(sym) && type == S_BOOLEAN)				setIcon(promptColIdx, choiceNoIcon);			else				setIcon(promptColIdx, symbolNoIcon);			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(sym_get_string_value(item->menu->sym));	else		setText(QString());	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();		break;	default:		Parent::keyPressEvent(e);		return;	}	e->accept();	parent()->list->setFocus();	hide();} ConfigList::ConfigList(ConfigView* p, const char *name)	: Parent(p),	  updateAll(false),	  showName(false), showRange(false), showData(false), mode(singleMode), optMode(normalOpt),	  rootEntry(0), headerPopup(0){	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()));	} 	showColumn(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){	hideColumn(dataColIdx);	hideColumn(yesColIdx);	hideColumn(modColIdx);	hideColumn(noColIdx);	hideColumn(nameColIdx); 	if (showName)		showColumn(nameColIdx);	if (showRange) {		showColumn(noColIdx);		showColumn(modColIdx);		showColumn(yesColIdx);	}	if (showData)		showColumn(dataColIdx); 	updateListAll();} void ConfigList::setOptionMode(QAction *action){	if (action == showNormalAction)		optMode = normalOpt;	else if (action == showAllAction)		optMode = allOpt;	else		optMode = promptOpt; 	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* last = 0;	ConfigItem *item; 	if (!rootEntry) {		if (mode != listMode)			goto update;		QTreeWidgetItemIterator it(this); 		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() : nullptr;		if (!item)			item = new ConfigItem(this, last, rootEntry, true);		else			item->testUpdateMenu(true); 		updateMenuList(item, rootEntry);		update();		resizeColumnToContents(0);		return;	}update:	updateMenuList(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();		break;	}} void ConfigList::changeValue(ConfigItem* item){	struct symbol* sym;	struct menu* menu;	int type, oldexpr, newexpr; 	menu = item->menu;	if (!menu)		return;	sym = menu->sym;	if (!sym) {

Lines 1–500 of 1963.

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