11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 31da177e4SLinus Torvalds * Released under the terms of the GNU GPL v2.0. 41da177e4SLinus Torvalds */ 51da177e4SLinus Torvalds 61da177e4SLinus Torvalds #include <qapplication.h> 71da177e4SLinus Torvalds #include <qmainwindow.h> 81da177e4SLinus Torvalds #include <qtoolbar.h> 943bf612aSRoman Zippel #include <qlayout.h> 101da177e4SLinus Torvalds #include <qvbox.h> 111da177e4SLinus Torvalds #include <qsplitter.h> 121da177e4SLinus Torvalds #include <qlistview.h> 1343bf612aSRoman Zippel #include <qtextbrowser.h> 141da177e4SLinus Torvalds #include <qlineedit.h> 1543bf612aSRoman Zippel #include <qlabel.h> 1643bf612aSRoman Zippel #include <qpushbutton.h> 171da177e4SLinus Torvalds #include <qmenubar.h> 181da177e4SLinus Torvalds #include <qmessagebox.h> 191da177e4SLinus Torvalds #include <qaction.h> 201da177e4SLinus Torvalds #include <qheader.h> 211da177e4SLinus Torvalds #include <qfiledialog.h> 2243bf612aSRoman Zippel #include <qdragobject.h> 231da177e4SLinus Torvalds #include <qregexp.h> 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include <stdlib.h> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds #include "lkc.h" 281da177e4SLinus Torvalds #include "qconf.h" 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds #include "qconf.moc" 311da177e4SLinus Torvalds #include "images.c" 321da177e4SLinus Torvalds 333b9fa093SArnaldo Carvalho de Melo #ifdef _ 343b9fa093SArnaldo Carvalho de Melo # undef _ 353b9fa093SArnaldo Carvalho de Melo # define _ qgettext 363b9fa093SArnaldo Carvalho de Melo #endif 373b9fa093SArnaldo Carvalho de Melo 381da177e4SLinus Torvalds static QApplication *configApp; 397fc925fdSRoman Zippel static ConfigSettings *configSettings; 401da177e4SLinus Torvalds 413b354c55SKarsten Wiese QAction *ConfigMainWindow::saveAction; 423b354c55SKarsten Wiese 433b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const char* str) 443b9fa093SArnaldo Carvalho de Melo { 453b9fa093SArnaldo Carvalho de Melo return QString::fromLocal8Bit(gettext(str)); 463b9fa093SArnaldo Carvalho de Melo } 473b9fa093SArnaldo Carvalho de Melo 483b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const QString& str) 493b9fa093SArnaldo Carvalho de Melo { 503b9fa093SArnaldo Carvalho de Melo return QString::fromLocal8Bit(gettext(str.latin1())); 513b9fa093SArnaldo Carvalho de Melo } 523b9fa093SArnaldo Carvalho de Melo 531da177e4SLinus Torvalds /** 541da177e4SLinus Torvalds * Reads a list of integer values from the application settings. 551da177e4SLinus Torvalds */ 561da177e4SLinus Torvalds QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok) 571da177e4SLinus Torvalds { 581da177e4SLinus Torvalds QValueList<int> result; 591da177e4SLinus Torvalds QStringList entryList = readListEntry(key, ok); 601da177e4SLinus Torvalds if (ok) { 611da177e4SLinus Torvalds QStringList::Iterator it; 621da177e4SLinus Torvalds for (it = entryList.begin(); it != entryList.end(); ++it) 631da177e4SLinus Torvalds result.push_back((*it).toInt()); 641da177e4SLinus Torvalds } 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds return result; 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /** 701da177e4SLinus Torvalds * Writes a list of integer values to the application settings. 711da177e4SLinus Torvalds */ 721da177e4SLinus Torvalds bool ConfigSettings::writeSizes(const QString& key, const QValueList<int>& value) 731da177e4SLinus Torvalds { 741da177e4SLinus Torvalds QStringList stringList; 751da177e4SLinus Torvalds QValueList<int>::ConstIterator it; 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds for (it = value.begin(); it != value.end(); ++it) 781da177e4SLinus Torvalds stringList.push_back(QString::number(*it)); 791da177e4SLinus Torvalds return writeEntry(key, stringList); 801da177e4SLinus Torvalds } 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds #if QT_VERSION >= 300 841da177e4SLinus Torvalds /* 851da177e4SLinus Torvalds * set the new data 861da177e4SLinus Torvalds * TODO check the value 871da177e4SLinus Torvalds */ 881da177e4SLinus Torvalds void ConfigItem::okRename(int col) 891da177e4SLinus Torvalds { 901da177e4SLinus Torvalds Parent::okRename(col); 911da177e4SLinus Torvalds sym_set_string_value(menu->sym, text(dataColIdx).latin1()); 9249e5646dSKarsten Wiese listView()->updateList(this); 931da177e4SLinus Torvalds } 941da177e4SLinus Torvalds #endif 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds /* 971da177e4SLinus Torvalds * update the displayed of a menu entry 981da177e4SLinus Torvalds */ 991da177e4SLinus Torvalds void ConfigItem::updateMenu(void) 1001da177e4SLinus Torvalds { 1011da177e4SLinus Torvalds ConfigList* list; 1021da177e4SLinus Torvalds struct symbol* sym; 1031da177e4SLinus Torvalds struct property *prop; 1041da177e4SLinus Torvalds QString prompt; 1051da177e4SLinus Torvalds int type; 1061da177e4SLinus Torvalds tristate expr; 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds list = listView(); 1091da177e4SLinus Torvalds if (goParent) { 1101da177e4SLinus Torvalds setPixmap(promptColIdx, list->menuBackPix); 1111da177e4SLinus Torvalds prompt = ".."; 1121da177e4SLinus Torvalds goto set_prompt; 1131da177e4SLinus Torvalds } 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds sym = menu->sym; 1161da177e4SLinus Torvalds prop = menu->prompt; 117c21a2d95SEGRY Gabor prompt = _(menu_get_prompt(menu)); 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds if (prop) switch (prop->type) { 1201da177e4SLinus Torvalds case P_MENU: 1211da177e4SLinus Torvalds if (list->mode == singleMode || list->mode == symbolMode) { 1221da177e4SLinus Torvalds /* a menuconfig entry is displayed differently 1231da177e4SLinus Torvalds * depending whether it's at the view root or a child. 1241da177e4SLinus Torvalds */ 1251da177e4SLinus Torvalds if (sym && list->rootEntry == menu) 1261da177e4SLinus Torvalds break; 1271da177e4SLinus Torvalds setPixmap(promptColIdx, list->menuPix); 1281da177e4SLinus Torvalds } else { 1291da177e4SLinus Torvalds if (sym) 1301da177e4SLinus Torvalds break; 1311da177e4SLinus Torvalds setPixmap(promptColIdx, 0); 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds goto set_prompt; 1341da177e4SLinus Torvalds case P_COMMENT: 1351da177e4SLinus Torvalds setPixmap(promptColIdx, 0); 1361da177e4SLinus Torvalds goto set_prompt; 1371da177e4SLinus Torvalds default: 1381da177e4SLinus Torvalds ; 1391da177e4SLinus Torvalds } 1401da177e4SLinus Torvalds if (!sym) 1411da177e4SLinus Torvalds goto set_prompt; 1421da177e4SLinus Torvalds 1433b9fa093SArnaldo Carvalho de Melo setText(nameColIdx, QString::fromLocal8Bit(sym->name)); 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds type = sym_get_type(sym); 1461da177e4SLinus Torvalds switch (type) { 1471da177e4SLinus Torvalds case S_BOOLEAN: 1481da177e4SLinus Torvalds case S_TRISTATE: 1491da177e4SLinus Torvalds char ch; 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds if (!sym_is_changable(sym) && !list->showAll) { 1521da177e4SLinus Torvalds setPixmap(promptColIdx, 0); 1533b9fa093SArnaldo Carvalho de Melo setText(noColIdx, QString::null); 1543b9fa093SArnaldo Carvalho de Melo setText(modColIdx, QString::null); 1553b9fa093SArnaldo Carvalho de Melo setText(yesColIdx, QString::null); 1561da177e4SLinus Torvalds break; 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds expr = sym_get_tristate_value(sym); 1591da177e4SLinus Torvalds switch (expr) { 1601da177e4SLinus Torvalds case yes: 1611da177e4SLinus Torvalds if (sym_is_choice_value(sym) && type == S_BOOLEAN) 1621da177e4SLinus Torvalds setPixmap(promptColIdx, list->choiceYesPix); 1631da177e4SLinus Torvalds else 1641da177e4SLinus Torvalds setPixmap(promptColIdx, list->symbolYesPix); 1651da177e4SLinus Torvalds setText(yesColIdx, "Y"); 1661da177e4SLinus Torvalds ch = 'Y'; 1671da177e4SLinus Torvalds break; 1681da177e4SLinus Torvalds case mod: 1691da177e4SLinus Torvalds setPixmap(promptColIdx, list->symbolModPix); 1701da177e4SLinus Torvalds setText(modColIdx, "M"); 1711da177e4SLinus Torvalds ch = 'M'; 1721da177e4SLinus Torvalds break; 1731da177e4SLinus Torvalds default: 1741da177e4SLinus Torvalds if (sym_is_choice_value(sym) && type == S_BOOLEAN) 1751da177e4SLinus Torvalds setPixmap(promptColIdx, list->choiceNoPix); 1761da177e4SLinus Torvalds else 1771da177e4SLinus Torvalds setPixmap(promptColIdx, list->symbolNoPix); 1781da177e4SLinus Torvalds setText(noColIdx, "N"); 1791da177e4SLinus Torvalds ch = 'N'; 1801da177e4SLinus Torvalds break; 1811da177e4SLinus Torvalds } 1821da177e4SLinus Torvalds if (expr != no) 1831da177e4SLinus Torvalds setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0); 1841da177e4SLinus Torvalds if (expr != mod) 1851da177e4SLinus Torvalds setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0); 1861da177e4SLinus Torvalds if (expr != yes) 1871da177e4SLinus Torvalds setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0); 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds setText(dataColIdx, QChar(ch)); 1901da177e4SLinus Torvalds break; 1911da177e4SLinus Torvalds case S_INT: 1921da177e4SLinus Torvalds case S_HEX: 1931da177e4SLinus Torvalds case S_STRING: 1941da177e4SLinus Torvalds const char* data; 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds data = sym_get_string_value(sym); 1973b9fa093SArnaldo Carvalho de Melo 1981da177e4SLinus Torvalds #if QT_VERSION >= 300 1991da177e4SLinus Torvalds int i = list->mapIdx(dataColIdx); 2001da177e4SLinus Torvalds if (i >= 0) 2011da177e4SLinus Torvalds setRenameEnabled(i, TRUE); 2021da177e4SLinus Torvalds #endif 2031da177e4SLinus Torvalds setText(dataColIdx, data); 2041da177e4SLinus Torvalds if (type == S_STRING) 2053b9fa093SArnaldo Carvalho de Melo prompt = QString("%1: %2").arg(prompt).arg(data); 2061da177e4SLinus Torvalds else 2073b9fa093SArnaldo Carvalho de Melo prompt = QString("(%2) %1").arg(prompt).arg(data); 2081da177e4SLinus Torvalds break; 2091da177e4SLinus Torvalds } 2101da177e4SLinus Torvalds if (!sym_has_value(sym) && visible) 211c21a2d95SEGRY Gabor prompt += _(" (NEW)"); 2121da177e4SLinus Torvalds set_prompt: 2131da177e4SLinus Torvalds setText(promptColIdx, prompt); 2141da177e4SLinus Torvalds } 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds void ConfigItem::testUpdateMenu(bool v) 2171da177e4SLinus Torvalds { 2181da177e4SLinus Torvalds ConfigItem* i; 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds visible = v; 2211da177e4SLinus Torvalds if (!menu) 2221da177e4SLinus Torvalds return; 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds sym_calc_value(menu->sym); 2251da177e4SLinus Torvalds if (menu->flags & MENU_CHANGED) { 2261da177e4SLinus Torvalds /* the menu entry changed, so update all list items */ 2271da177e4SLinus Torvalds menu->flags &= ~MENU_CHANGED; 2281da177e4SLinus Torvalds for (i = (ConfigItem*)menu->data; i; i = i->nextItem) 2291da177e4SLinus Torvalds i->updateMenu(); 2301da177e4SLinus Torvalds } else if (listView()->updateAll) 2311da177e4SLinus Torvalds updateMenu(); 2321da177e4SLinus Torvalds } 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align) 2351da177e4SLinus Torvalds { 2361da177e4SLinus Torvalds ConfigList* list = listView(); 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds if (visible) { 2391da177e4SLinus Torvalds if (isSelected() && !list->hasFocus() && list->mode == menuMode) 2401da177e4SLinus Torvalds Parent::paintCell(p, list->inactivedColorGroup, column, width, align); 2411da177e4SLinus Torvalds else 2421da177e4SLinus Torvalds Parent::paintCell(p, cg, column, width, align); 2431da177e4SLinus Torvalds } else 2441da177e4SLinus Torvalds Parent::paintCell(p, list->disabledColorGroup, column, width, align); 2451da177e4SLinus Torvalds } 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds /* 2481da177e4SLinus Torvalds * construct a menu entry 2491da177e4SLinus Torvalds */ 2501da177e4SLinus Torvalds void ConfigItem::init(void) 2511da177e4SLinus Torvalds { 2521da177e4SLinus Torvalds if (menu) { 2531da177e4SLinus Torvalds ConfigList* list = listView(); 2541da177e4SLinus Torvalds nextItem = (ConfigItem*)menu->data; 2551da177e4SLinus Torvalds menu->data = this; 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds if (list->mode != fullMode) 2581da177e4SLinus Torvalds setOpen(TRUE); 2591da177e4SLinus Torvalds sym_calc_value(menu->sym); 2601da177e4SLinus Torvalds } 2611da177e4SLinus Torvalds updateMenu(); 2621da177e4SLinus Torvalds } 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds /* 2651da177e4SLinus Torvalds * destruct a menu entry 2661da177e4SLinus Torvalds */ 2671da177e4SLinus Torvalds ConfigItem::~ConfigItem(void) 2681da177e4SLinus Torvalds { 2691da177e4SLinus Torvalds if (menu) { 2701da177e4SLinus Torvalds ConfigItem** ip = (ConfigItem**)&menu->data; 2711da177e4SLinus Torvalds for (; *ip; ip = &(*ip)->nextItem) { 2721da177e4SLinus Torvalds if (*ip == this) { 2731da177e4SLinus Torvalds *ip = nextItem; 2741da177e4SLinus Torvalds break; 2751da177e4SLinus Torvalds } 2761da177e4SLinus Torvalds } 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds } 2791da177e4SLinus Torvalds 28043bf612aSRoman Zippel ConfigLineEdit::ConfigLineEdit(ConfigView* parent) 28143bf612aSRoman Zippel : Parent(parent) 28243bf612aSRoman Zippel { 28343bf612aSRoman Zippel connect(this, SIGNAL(lostFocus()), SLOT(hide())); 28443bf612aSRoman Zippel } 28543bf612aSRoman Zippel 2861da177e4SLinus Torvalds void ConfigLineEdit::show(ConfigItem* i) 2871da177e4SLinus Torvalds { 2881da177e4SLinus Torvalds item = i; 2891da177e4SLinus Torvalds if (sym_get_string_value(item->menu->sym)) 2903b9fa093SArnaldo Carvalho de Melo setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym))); 2911da177e4SLinus Torvalds else 2923b9fa093SArnaldo Carvalho de Melo setText(QString::null); 2931da177e4SLinus Torvalds Parent::show(); 2941da177e4SLinus Torvalds setFocus(); 2951da177e4SLinus Torvalds } 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds void ConfigLineEdit::keyPressEvent(QKeyEvent* e) 2981da177e4SLinus Torvalds { 2991da177e4SLinus Torvalds switch (e->key()) { 300fbb86374SMarkus Heidelberg case Qt::Key_Escape: 3011da177e4SLinus Torvalds break; 302fbb86374SMarkus Heidelberg case Qt::Key_Return: 303fbb86374SMarkus Heidelberg case Qt::Key_Enter: 3041da177e4SLinus Torvalds sym_set_string_value(item->menu->sym, text().latin1()); 3051da177e4SLinus Torvalds parent()->updateList(item); 3061da177e4SLinus Torvalds break; 3071da177e4SLinus Torvalds default: 3081da177e4SLinus Torvalds Parent::keyPressEvent(e); 3091da177e4SLinus Torvalds return; 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds e->accept(); 3121da177e4SLinus Torvalds parent()->list->setFocus(); 3131da177e4SLinus Torvalds hide(); 3141da177e4SLinus Torvalds } 3151da177e4SLinus Torvalds 3167fc925fdSRoman Zippel ConfigList::ConfigList(ConfigView* p, const char *name) 3177fc925fdSRoman Zippel : Parent(p, name), 3181da177e4SLinus Torvalds updateAll(false), 3191da177e4SLinus Torvalds symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no), 3201da177e4SLinus Torvalds choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no), 3211da177e4SLinus Torvalds menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void), 3221da177e4SLinus Torvalds showAll(false), showName(false), showRange(false), showData(false), 3237fc925fdSRoman Zippel rootEntry(0), headerPopup(0) 3241da177e4SLinus Torvalds { 3251da177e4SLinus Torvalds int i; 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds setSorting(-1); 3281da177e4SLinus Torvalds setRootIsDecorated(TRUE); 3291da177e4SLinus Torvalds disabledColorGroup = palette().active(); 3301da177e4SLinus Torvalds disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text()); 3311da177e4SLinus Torvalds inactivedColorGroup = palette().active(); 3321da177e4SLinus Torvalds inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight()); 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds connect(this, SIGNAL(selectionChanged(void)), 3351da177e4SLinus Torvalds SLOT(updateSelection(void))); 3361da177e4SLinus Torvalds 3377fc925fdSRoman Zippel if (name) { 3387fc925fdSRoman Zippel configSettings->beginGroup(name); 3397fc925fdSRoman Zippel showAll = configSettings->readBoolEntry("/showAll", false); 3407fc925fdSRoman Zippel showName = configSettings->readBoolEntry("/showName", false); 3417fc925fdSRoman Zippel showRange = configSettings->readBoolEntry("/showRange", false); 3427fc925fdSRoman Zippel showData = configSettings->readBoolEntry("/showData", false); 3437fc925fdSRoman Zippel configSettings->endGroup(); 3447fc925fdSRoman Zippel connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); 3451da177e4SLinus Torvalds } 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds for (i = 0; i < colNr; i++) 3481da177e4SLinus Torvalds colMap[i] = colRevMap[i] = -1; 349c21a2d95SEGRY Gabor addColumn(promptColIdx, _("Option")); 3501da177e4SLinus Torvalds 3511da177e4SLinus Torvalds reinit(); 3521da177e4SLinus Torvalds } 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvalds void ConfigList::reinit(void) 3551da177e4SLinus Torvalds { 3561da177e4SLinus Torvalds removeColumn(dataColIdx); 3571da177e4SLinus Torvalds removeColumn(yesColIdx); 3581da177e4SLinus Torvalds removeColumn(modColIdx); 3591da177e4SLinus Torvalds removeColumn(noColIdx); 3601da177e4SLinus Torvalds removeColumn(nameColIdx); 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds if (showName) 363c21a2d95SEGRY Gabor addColumn(nameColIdx, _("Name")); 3641da177e4SLinus Torvalds if (showRange) { 3651da177e4SLinus Torvalds addColumn(noColIdx, "N"); 3661da177e4SLinus Torvalds addColumn(modColIdx, "M"); 3671da177e4SLinus Torvalds addColumn(yesColIdx, "Y"); 3681da177e4SLinus Torvalds } 3691da177e4SLinus Torvalds if (showData) 370c21a2d95SEGRY Gabor addColumn(dataColIdx, _("Value")); 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds updateListAll(); 3731da177e4SLinus Torvalds } 3741da177e4SLinus Torvalds 3757fc925fdSRoman Zippel void ConfigList::saveSettings(void) 3767fc925fdSRoman Zippel { 3777fc925fdSRoman Zippel if (name()) { 3787fc925fdSRoman Zippel configSettings->beginGroup(name()); 3797fc925fdSRoman Zippel configSettings->writeEntry("/showName", showName); 3807fc925fdSRoman Zippel configSettings->writeEntry("/showRange", showRange); 3817fc925fdSRoman Zippel configSettings->writeEntry("/showData", showData); 3827fc925fdSRoman Zippel configSettings->writeEntry("/showAll", showAll); 3837fc925fdSRoman Zippel configSettings->endGroup(); 3847fc925fdSRoman Zippel } 3857fc925fdSRoman Zippel } 3867fc925fdSRoman Zippel 387b65a47e1SRoman Zippel ConfigItem* ConfigList::findConfigItem(struct menu *menu) 388b65a47e1SRoman Zippel { 389b65a47e1SRoman Zippel ConfigItem* item = (ConfigItem*)menu->data; 390b65a47e1SRoman Zippel 391b65a47e1SRoman Zippel for (; item; item = item->nextItem) { 392b65a47e1SRoman Zippel if (this == item->listView()) 393b65a47e1SRoman Zippel break; 394b65a47e1SRoman Zippel } 395b65a47e1SRoman Zippel 396b65a47e1SRoman Zippel return item; 397b65a47e1SRoman Zippel } 398b65a47e1SRoman Zippel 3991da177e4SLinus Torvalds void ConfigList::updateSelection(void) 4001da177e4SLinus Torvalds { 4011da177e4SLinus Torvalds struct menu *menu; 4021da177e4SLinus Torvalds enum prop_type type; 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds ConfigItem* item = (ConfigItem*)selectedItem(); 4051da177e4SLinus Torvalds if (!item) 4061da177e4SLinus Torvalds return; 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds menu = item->menu; 40943bf612aSRoman Zippel emit menuChanged(menu); 4101da177e4SLinus Torvalds if (!menu) 4111da177e4SLinus Torvalds return; 4121da177e4SLinus Torvalds type = menu->prompt ? menu->prompt->type : P_UNKNOWN; 4131da177e4SLinus Torvalds if (mode == menuMode && type == P_MENU) 4141da177e4SLinus Torvalds emit menuSelected(menu); 4151da177e4SLinus Torvalds } 4161da177e4SLinus Torvalds 4171da177e4SLinus Torvalds void ConfigList::updateList(ConfigItem* item) 4181da177e4SLinus Torvalds { 4191da177e4SLinus Torvalds ConfigItem* last = 0; 4201da177e4SLinus Torvalds 42143bf612aSRoman Zippel if (!rootEntry) { 42243bf612aSRoman Zippel if (mode != listMode) 4231da177e4SLinus Torvalds goto update; 42443bf612aSRoman Zippel QListViewItemIterator it(this); 42543bf612aSRoman Zippel ConfigItem* item; 42643bf612aSRoman Zippel 42743bf612aSRoman Zippel for (; it.current(); ++it) { 42843bf612aSRoman Zippel item = (ConfigItem*)it.current(); 42943bf612aSRoman Zippel if (!item->menu) 43043bf612aSRoman Zippel continue; 43143bf612aSRoman Zippel item->testUpdateMenu(menu_is_visible(item->menu)); 43243bf612aSRoman Zippel } 43343bf612aSRoman Zippel return; 43443bf612aSRoman Zippel } 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds if (rootEntry != &rootmenu && (mode == singleMode || 4371da177e4SLinus Torvalds (mode == symbolMode && rootEntry->parent != &rootmenu))) { 4381da177e4SLinus Torvalds item = firstChild(); 4391da177e4SLinus Torvalds if (!item) 4401da177e4SLinus Torvalds item = new ConfigItem(this, 0, true); 4411da177e4SLinus Torvalds last = item; 4421da177e4SLinus Torvalds } 4431da177e4SLinus Torvalds if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) && 4441da177e4SLinus Torvalds rootEntry->sym && rootEntry->prompt) { 4451da177e4SLinus Torvalds item = last ? last->nextSibling() : firstChild(); 4461da177e4SLinus Torvalds if (!item) 4471da177e4SLinus Torvalds item = new ConfigItem(this, last, rootEntry, true); 4481da177e4SLinus Torvalds else 4491da177e4SLinus Torvalds item->testUpdateMenu(true); 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds updateMenuList(item, rootEntry); 4521da177e4SLinus Torvalds triggerUpdate(); 4531da177e4SLinus Torvalds return; 4541da177e4SLinus Torvalds } 4551da177e4SLinus Torvalds update: 4561da177e4SLinus Torvalds updateMenuList(this, rootEntry); 4571da177e4SLinus Torvalds triggerUpdate(); 4581da177e4SLinus Torvalds } 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds void ConfigList::setValue(ConfigItem* item, tristate val) 4611da177e4SLinus Torvalds { 4621da177e4SLinus Torvalds struct symbol* sym; 4631da177e4SLinus Torvalds int type; 4641da177e4SLinus Torvalds tristate oldval; 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds sym = item->menu ? item->menu->sym : 0; 4671da177e4SLinus Torvalds if (!sym) 4681da177e4SLinus Torvalds return; 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds type = sym_get_type(sym); 4711da177e4SLinus Torvalds switch (type) { 4721da177e4SLinus Torvalds case S_BOOLEAN: 4731da177e4SLinus Torvalds case S_TRISTATE: 4741da177e4SLinus Torvalds oldval = sym_get_tristate_value(sym); 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds if (!sym_set_tristate_value(sym, val)) 4771da177e4SLinus Torvalds return; 4781da177e4SLinus Torvalds if (oldval == no && item->menu->list) 4791da177e4SLinus Torvalds item->setOpen(TRUE); 4801da177e4SLinus Torvalds parent()->updateList(item); 4811da177e4SLinus Torvalds break; 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds } 4841da177e4SLinus Torvalds 4851da177e4SLinus Torvalds void ConfigList::changeValue(ConfigItem* item) 4861da177e4SLinus Torvalds { 4871da177e4SLinus Torvalds struct symbol* sym; 4881da177e4SLinus Torvalds struct menu* menu; 4891da177e4SLinus Torvalds int type, oldexpr, newexpr; 4901da177e4SLinus Torvalds 4911da177e4SLinus Torvalds menu = item->menu; 4921da177e4SLinus Torvalds if (!menu) 4931da177e4SLinus Torvalds return; 4941da177e4SLinus Torvalds sym = menu->sym; 4951da177e4SLinus Torvalds if (!sym) { 4961da177e4SLinus Torvalds if (item->menu->list) 4971da177e4SLinus Torvalds item->setOpen(!item->isOpen()); 4981da177e4SLinus Torvalds return; 4991da177e4SLinus Torvalds } 5001da177e4SLinus Torvalds 5011da177e4SLinus Torvalds type = sym_get_type(sym); 5021da177e4SLinus Torvalds switch (type) { 5031da177e4SLinus Torvalds case S_BOOLEAN: 5041da177e4SLinus Torvalds case S_TRISTATE: 5051da177e4SLinus Torvalds oldexpr = sym_get_tristate_value(sym); 5061da177e4SLinus Torvalds newexpr = sym_toggle_tristate_value(sym); 5071da177e4SLinus Torvalds if (item->menu->list) { 5081da177e4SLinus Torvalds if (oldexpr == newexpr) 5091da177e4SLinus Torvalds item->setOpen(!item->isOpen()); 5101da177e4SLinus Torvalds else if (oldexpr == no) 5111da177e4SLinus Torvalds item->setOpen(TRUE); 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds if (oldexpr != newexpr) 5141da177e4SLinus Torvalds parent()->updateList(item); 5151da177e4SLinus Torvalds break; 5161da177e4SLinus Torvalds case S_INT: 5171da177e4SLinus Torvalds case S_HEX: 5181da177e4SLinus Torvalds case S_STRING: 5191da177e4SLinus Torvalds #if QT_VERSION >= 300 5201da177e4SLinus Torvalds if (colMap[dataColIdx] >= 0) 5211da177e4SLinus Torvalds item->startRename(colMap[dataColIdx]); 5221da177e4SLinus Torvalds else 5231da177e4SLinus Torvalds #endif 5241da177e4SLinus Torvalds parent()->lineEdit->show(item); 5251da177e4SLinus Torvalds break; 5261da177e4SLinus Torvalds } 5271da177e4SLinus Torvalds } 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds void ConfigList::setRootMenu(struct menu *menu) 5301da177e4SLinus Torvalds { 5311da177e4SLinus Torvalds enum prop_type type; 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds if (rootEntry == menu) 5341da177e4SLinus Torvalds return; 5351da177e4SLinus Torvalds type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN; 5361da177e4SLinus Torvalds if (type != P_MENU) 5371da177e4SLinus Torvalds return; 5381da177e4SLinus Torvalds updateMenuList(this, 0); 5391da177e4SLinus Torvalds rootEntry = menu; 5401da177e4SLinus Torvalds updateListAll(); 5411da177e4SLinus Torvalds setSelected(currentItem(), hasFocus()); 542b65a47e1SRoman Zippel ensureItemVisible(currentItem()); 5431da177e4SLinus Torvalds } 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds void ConfigList::setParentMenu(void) 5461da177e4SLinus Torvalds { 5471da177e4SLinus Torvalds ConfigItem* item; 5481da177e4SLinus Torvalds struct menu *oldroot; 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds oldroot = rootEntry; 5511da177e4SLinus Torvalds if (rootEntry == &rootmenu) 5521da177e4SLinus Torvalds return; 5531da177e4SLinus Torvalds setRootMenu(menu_get_parent_menu(rootEntry->parent)); 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds QListViewItemIterator it(this); 5561da177e4SLinus Torvalds for (; (item = (ConfigItem*)it.current()); it++) { 5571da177e4SLinus Torvalds if (item->menu == oldroot) { 5581da177e4SLinus Torvalds setCurrentItem(item); 5591da177e4SLinus Torvalds ensureItemVisible(item); 5601da177e4SLinus Torvalds break; 5611da177e4SLinus Torvalds } 5621da177e4SLinus Torvalds } 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds 5657fc925fdSRoman Zippel /* 5667fc925fdSRoman Zippel * update all the children of a menu entry 5677fc925fdSRoman Zippel * removes/adds the entries from the parent widget as necessary 5687fc925fdSRoman Zippel * 5697fc925fdSRoman Zippel * parent: either the menu list widget or a menu entry widget 5707fc925fdSRoman Zippel * menu: entry to be updated 5717fc925fdSRoman Zippel */ 5727fc925fdSRoman Zippel template <class P> 5737fc925fdSRoman Zippel void ConfigList::updateMenuList(P* parent, struct menu* menu) 5747fc925fdSRoman Zippel { 5757fc925fdSRoman Zippel struct menu* child; 5767fc925fdSRoman Zippel ConfigItem* item; 5777fc925fdSRoman Zippel ConfigItem* last; 5787fc925fdSRoman Zippel bool visible; 5797fc925fdSRoman Zippel enum prop_type type; 5807fc925fdSRoman Zippel 5817fc925fdSRoman Zippel if (!menu) { 5827fc925fdSRoman Zippel while ((item = parent->firstChild())) 5837fc925fdSRoman Zippel delete item; 5847fc925fdSRoman Zippel return; 5857fc925fdSRoman Zippel } 5867fc925fdSRoman Zippel 5877fc925fdSRoman Zippel last = parent->firstChild(); 5887fc925fdSRoman Zippel if (last && !last->goParent) 5897fc925fdSRoman Zippel last = 0; 5907fc925fdSRoman Zippel for (child = menu->list; child; child = child->next) { 5917fc925fdSRoman Zippel item = last ? last->nextSibling() : parent->firstChild(); 5927fc925fdSRoman Zippel type = child->prompt ? child->prompt->type : P_UNKNOWN; 5937fc925fdSRoman Zippel 5947fc925fdSRoman Zippel switch (mode) { 5957fc925fdSRoman Zippel case menuMode: 5967fc925fdSRoman Zippel if (!(child->flags & MENU_ROOT)) 5977fc925fdSRoman Zippel goto hide; 5987fc925fdSRoman Zippel break; 5997fc925fdSRoman Zippel case symbolMode: 6007fc925fdSRoman Zippel if (child->flags & MENU_ROOT) 6017fc925fdSRoman Zippel goto hide; 6027fc925fdSRoman Zippel break; 6037fc925fdSRoman Zippel default: 6047fc925fdSRoman Zippel break; 6057fc925fdSRoman Zippel } 6067fc925fdSRoman Zippel 6077fc925fdSRoman Zippel visible = menu_is_visible(child); 6087fc925fdSRoman Zippel if (showAll || visible) { 609ed8b4d4dSCyrill V. Gorcunov if (!child->sym && !child->list && !child->prompt) 610ed8b4d4dSCyrill V. Gorcunov continue; 6117fc925fdSRoman Zippel if (!item || item->menu != child) 6127fc925fdSRoman Zippel item = new ConfigItem(parent, last, child, visible); 6137fc925fdSRoman Zippel else 6147fc925fdSRoman Zippel item->testUpdateMenu(visible); 6157fc925fdSRoman Zippel 6167fc925fdSRoman Zippel if (mode == fullMode || mode == menuMode || type != P_MENU) 6177fc925fdSRoman Zippel updateMenuList(item, child); 6187fc925fdSRoman Zippel else 6197fc925fdSRoman Zippel updateMenuList(item, 0); 6207fc925fdSRoman Zippel last = item; 6217fc925fdSRoman Zippel continue; 6227fc925fdSRoman Zippel } 6237fc925fdSRoman Zippel hide: 6247fc925fdSRoman Zippel if (item && item->menu == child) { 6257fc925fdSRoman Zippel last = parent->firstChild(); 6267fc925fdSRoman Zippel if (last == item) 6277fc925fdSRoman Zippel last = 0; 6287fc925fdSRoman Zippel else while (last->nextSibling() != item) 6297fc925fdSRoman Zippel last = last->nextSibling(); 6307fc925fdSRoman Zippel delete item; 6317fc925fdSRoman Zippel } 6327fc925fdSRoman Zippel } 6337fc925fdSRoman Zippel } 6347fc925fdSRoman Zippel 6351da177e4SLinus Torvalds void ConfigList::keyPressEvent(QKeyEvent* ev) 6361da177e4SLinus Torvalds { 6371da177e4SLinus Torvalds QListViewItem* i = currentItem(); 6381da177e4SLinus Torvalds ConfigItem* item; 6391da177e4SLinus Torvalds struct menu *menu; 6401da177e4SLinus Torvalds enum prop_type type; 6411da177e4SLinus Torvalds 642fbb86374SMarkus Heidelberg if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) { 6431da177e4SLinus Torvalds emit parentSelected(); 6441da177e4SLinus Torvalds ev->accept(); 6451da177e4SLinus Torvalds return; 6461da177e4SLinus Torvalds } 6471da177e4SLinus Torvalds 6481da177e4SLinus Torvalds if (!i) { 6491da177e4SLinus Torvalds Parent::keyPressEvent(ev); 6501da177e4SLinus Torvalds return; 6511da177e4SLinus Torvalds } 6521da177e4SLinus Torvalds item = (ConfigItem*)i; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds switch (ev->key()) { 655fbb86374SMarkus Heidelberg case Qt::Key_Return: 656fbb86374SMarkus Heidelberg case Qt::Key_Enter: 6571da177e4SLinus Torvalds if (item->goParent) { 6581da177e4SLinus Torvalds emit parentSelected(); 6591da177e4SLinus Torvalds break; 6601da177e4SLinus Torvalds } 6611da177e4SLinus Torvalds menu = item->menu; 6621da177e4SLinus Torvalds if (!menu) 6631da177e4SLinus Torvalds break; 6641da177e4SLinus Torvalds type = menu->prompt ? menu->prompt->type : P_UNKNOWN; 6651da177e4SLinus Torvalds if (type == P_MENU && rootEntry != menu && 6661da177e4SLinus Torvalds mode != fullMode && mode != menuMode) { 6671da177e4SLinus Torvalds emit menuSelected(menu); 6681da177e4SLinus Torvalds break; 6691da177e4SLinus Torvalds } 670fbb86374SMarkus Heidelberg case Qt::Key_Space: 6711da177e4SLinus Torvalds changeValue(item); 6721da177e4SLinus Torvalds break; 673fbb86374SMarkus Heidelberg case Qt::Key_N: 6741da177e4SLinus Torvalds setValue(item, no); 6751da177e4SLinus Torvalds break; 676fbb86374SMarkus Heidelberg case Qt::Key_M: 6771da177e4SLinus Torvalds setValue(item, mod); 6781da177e4SLinus Torvalds break; 679fbb86374SMarkus Heidelberg case Qt::Key_Y: 6801da177e4SLinus Torvalds setValue(item, yes); 6811da177e4SLinus Torvalds break; 6821da177e4SLinus Torvalds default: 6831da177e4SLinus Torvalds Parent::keyPressEvent(ev); 6841da177e4SLinus Torvalds return; 6851da177e4SLinus Torvalds } 6861da177e4SLinus Torvalds ev->accept(); 6871da177e4SLinus Torvalds } 6881da177e4SLinus Torvalds 6891da177e4SLinus Torvalds void ConfigList::contentsMousePressEvent(QMouseEvent* e) 6901da177e4SLinus Torvalds { 6911da177e4SLinus Torvalds //QPoint p(contentsToViewport(e->pos())); 6921da177e4SLinus Torvalds //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y()); 6931da177e4SLinus Torvalds Parent::contentsMousePressEvent(e); 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e) 6971da177e4SLinus Torvalds { 6981da177e4SLinus Torvalds QPoint p(contentsToViewport(e->pos())); 6991da177e4SLinus Torvalds ConfigItem* item = (ConfigItem*)itemAt(p); 7001da177e4SLinus Torvalds struct menu *menu; 7011da177e4SLinus Torvalds enum prop_type ptype; 7021da177e4SLinus Torvalds const QPixmap* pm; 7031da177e4SLinus Torvalds int idx, x; 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds if (!item) 7061da177e4SLinus Torvalds goto skip; 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds menu = item->menu; 7091da177e4SLinus Torvalds x = header()->offset() + p.x(); 7101da177e4SLinus Torvalds idx = colRevMap[header()->sectionAt(x)]; 7111da177e4SLinus Torvalds switch (idx) { 7121da177e4SLinus Torvalds case promptColIdx: 7131da177e4SLinus Torvalds pm = item->pixmap(promptColIdx); 7141da177e4SLinus Torvalds if (pm) { 7151da177e4SLinus Torvalds int off = header()->sectionPos(0) + itemMargin() + 7161da177e4SLinus Torvalds treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0)); 7171da177e4SLinus Torvalds if (x >= off && x < off + pm->width()) { 7181da177e4SLinus Torvalds if (item->goParent) { 7191da177e4SLinus Torvalds emit parentSelected(); 7201da177e4SLinus Torvalds break; 7211da177e4SLinus Torvalds } else if (!menu) 7221da177e4SLinus Torvalds break; 7231da177e4SLinus Torvalds ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; 7241da177e4SLinus Torvalds if (ptype == P_MENU && rootEntry != menu && 7251da177e4SLinus Torvalds mode != fullMode && mode != menuMode) 7261da177e4SLinus Torvalds emit menuSelected(menu); 7271da177e4SLinus Torvalds else 7281da177e4SLinus Torvalds changeValue(item); 7291da177e4SLinus Torvalds } 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds break; 7321da177e4SLinus Torvalds case noColIdx: 7331da177e4SLinus Torvalds setValue(item, no); 7341da177e4SLinus Torvalds break; 7351da177e4SLinus Torvalds case modColIdx: 7361da177e4SLinus Torvalds setValue(item, mod); 7371da177e4SLinus Torvalds break; 7381da177e4SLinus Torvalds case yesColIdx: 7391da177e4SLinus Torvalds setValue(item, yes); 7401da177e4SLinus Torvalds break; 7411da177e4SLinus Torvalds case dataColIdx: 7421da177e4SLinus Torvalds changeValue(item); 7431da177e4SLinus Torvalds break; 7441da177e4SLinus Torvalds } 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds skip: 7471da177e4SLinus Torvalds //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y()); 7481da177e4SLinus Torvalds Parent::contentsMouseReleaseEvent(e); 7491da177e4SLinus Torvalds } 7501da177e4SLinus Torvalds 7511da177e4SLinus Torvalds void ConfigList::contentsMouseMoveEvent(QMouseEvent* e) 7521da177e4SLinus Torvalds { 7531da177e4SLinus Torvalds //QPoint p(contentsToViewport(e->pos())); 7541da177e4SLinus Torvalds //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y()); 7551da177e4SLinus Torvalds Parent::contentsMouseMoveEvent(e); 7561da177e4SLinus Torvalds } 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e) 7591da177e4SLinus Torvalds { 7601da177e4SLinus Torvalds QPoint p(contentsToViewport(e->pos())); 7611da177e4SLinus Torvalds ConfigItem* item = (ConfigItem*)itemAt(p); 7621da177e4SLinus Torvalds struct menu *menu; 7631da177e4SLinus Torvalds enum prop_type ptype; 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds if (!item) 7661da177e4SLinus Torvalds goto skip; 7671da177e4SLinus Torvalds if (item->goParent) { 7681da177e4SLinus Torvalds emit parentSelected(); 7691da177e4SLinus Torvalds goto skip; 7701da177e4SLinus Torvalds } 7711da177e4SLinus Torvalds menu = item->menu; 7721da177e4SLinus Torvalds if (!menu) 7731da177e4SLinus Torvalds goto skip; 7741da177e4SLinus Torvalds ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; 7751da177e4SLinus Torvalds if (ptype == P_MENU && (mode == singleMode || mode == symbolMode)) 7761da177e4SLinus Torvalds emit menuSelected(menu); 7771da177e4SLinus Torvalds else if (menu->sym) 7781da177e4SLinus Torvalds changeValue(item); 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds skip: 7811da177e4SLinus Torvalds //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y()); 7821da177e4SLinus Torvalds Parent::contentsMouseDoubleClickEvent(e); 7831da177e4SLinus Torvalds } 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds void ConfigList::focusInEvent(QFocusEvent *e) 7861da177e4SLinus Torvalds { 787b65a47e1SRoman Zippel struct menu *menu = NULL; 788b65a47e1SRoman Zippel 7891da177e4SLinus Torvalds Parent::focusInEvent(e); 7901da177e4SLinus Torvalds 791b65a47e1SRoman Zippel ConfigItem* item = (ConfigItem *)currentItem(); 792b65a47e1SRoman Zippel if (item) { 7931da177e4SLinus Torvalds setSelected(item, TRUE); 794b65a47e1SRoman Zippel menu = item->menu; 795b65a47e1SRoman Zippel } 796b65a47e1SRoman Zippel emit gotFocus(menu); 7971da177e4SLinus Torvalds } 7981da177e4SLinus Torvalds 7997fc925fdSRoman Zippel void ConfigList::contextMenuEvent(QContextMenuEvent *e) 8007fc925fdSRoman Zippel { 8017fc925fdSRoman Zippel if (e->y() <= header()->geometry().bottom()) { 8027fc925fdSRoman Zippel if (!headerPopup) { 8037fc925fdSRoman Zippel QAction *action; 8047fc925fdSRoman Zippel 8057fc925fdSRoman Zippel headerPopup = new QPopupMenu(this); 806c21a2d95SEGRY Gabor action = new QAction(NULL, _("Show Name"), 0, this); 8077fc925fdSRoman Zippel action->setToggleAction(TRUE); 8087fc925fdSRoman Zippel connect(action, SIGNAL(toggled(bool)), 8097fc925fdSRoman Zippel parent(), SLOT(setShowName(bool))); 8107fc925fdSRoman Zippel connect(parent(), SIGNAL(showNameChanged(bool)), 8117fc925fdSRoman Zippel action, SLOT(setOn(bool))); 8127fc925fdSRoman Zippel action->setOn(showName); 8137fc925fdSRoman Zippel action->addTo(headerPopup); 814c21a2d95SEGRY Gabor action = new QAction(NULL, _("Show Range"), 0, this); 8157fc925fdSRoman Zippel action->setToggleAction(TRUE); 8167fc925fdSRoman Zippel connect(action, SIGNAL(toggled(bool)), 8177fc925fdSRoman Zippel parent(), SLOT(setShowRange(bool))); 8187fc925fdSRoman Zippel connect(parent(), SIGNAL(showRangeChanged(bool)), 8197fc925fdSRoman Zippel action, SLOT(setOn(bool))); 8207fc925fdSRoman Zippel action->setOn(showRange); 8217fc925fdSRoman Zippel action->addTo(headerPopup); 822c21a2d95SEGRY Gabor action = new QAction(NULL, _("Show Data"), 0, this); 8237fc925fdSRoman Zippel action->setToggleAction(TRUE); 8247fc925fdSRoman Zippel connect(action, SIGNAL(toggled(bool)), 8257fc925fdSRoman Zippel parent(), SLOT(setShowData(bool))); 8267fc925fdSRoman Zippel connect(parent(), SIGNAL(showDataChanged(bool)), 8277fc925fdSRoman Zippel action, SLOT(setOn(bool))); 8287fc925fdSRoman Zippel action->setOn(showData); 8297fc925fdSRoman Zippel action->addTo(headerPopup); 8307fc925fdSRoman Zippel } 8317fc925fdSRoman Zippel headerPopup->exec(e->globalPos()); 8327fc925fdSRoman Zippel e->accept(); 8337fc925fdSRoman Zippel } else 8347fc925fdSRoman Zippel e->ignore(); 8357fc925fdSRoman Zippel } 8367fc925fdSRoman Zippel 8371da177e4SLinus Torvalds ConfigView* ConfigView::viewList; 8381da177e4SLinus Torvalds 8397fc925fdSRoman Zippel ConfigView::ConfigView(QWidget* parent, const char *name) 8407fc925fdSRoman Zippel : Parent(parent, name) 8411da177e4SLinus Torvalds { 8427fc925fdSRoman Zippel list = new ConfigList(this, name); 8431da177e4SLinus Torvalds lineEdit = new ConfigLineEdit(this); 8441da177e4SLinus Torvalds lineEdit->hide(); 8451da177e4SLinus Torvalds 8461da177e4SLinus Torvalds this->nextView = viewList; 8471da177e4SLinus Torvalds viewList = this; 8481da177e4SLinus Torvalds } 8491da177e4SLinus Torvalds 8501da177e4SLinus Torvalds ConfigView::~ConfigView(void) 8511da177e4SLinus Torvalds { 8521da177e4SLinus Torvalds ConfigView** vp; 8531da177e4SLinus Torvalds 8541da177e4SLinus Torvalds for (vp = &viewList; *vp; vp = &(*vp)->nextView) { 8551da177e4SLinus Torvalds if (*vp == this) { 8561da177e4SLinus Torvalds *vp = nextView; 8571da177e4SLinus Torvalds break; 8581da177e4SLinus Torvalds } 8591da177e4SLinus Torvalds } 8601da177e4SLinus Torvalds } 8611da177e4SLinus Torvalds 8627fc925fdSRoman Zippel void ConfigView::setShowAll(bool b) 8637fc925fdSRoman Zippel { 8647fc925fdSRoman Zippel if (list->showAll != b) { 8657fc925fdSRoman Zippel list->showAll = b; 8667fc925fdSRoman Zippel list->updateListAll(); 8677fc925fdSRoman Zippel emit showAllChanged(b); 8687fc925fdSRoman Zippel } 8697fc925fdSRoman Zippel } 8707fc925fdSRoman Zippel 8717fc925fdSRoman Zippel void ConfigView::setShowName(bool b) 8727fc925fdSRoman Zippel { 8737fc925fdSRoman Zippel if (list->showName != b) { 8747fc925fdSRoman Zippel list->showName = b; 8757fc925fdSRoman Zippel list->reinit(); 8767fc925fdSRoman Zippel emit showNameChanged(b); 8777fc925fdSRoman Zippel } 8787fc925fdSRoman Zippel } 8797fc925fdSRoman Zippel 8807fc925fdSRoman Zippel void ConfigView::setShowRange(bool b) 8817fc925fdSRoman Zippel { 8827fc925fdSRoman Zippel if (list->showRange != b) { 8837fc925fdSRoman Zippel list->showRange = b; 8847fc925fdSRoman Zippel list->reinit(); 8857fc925fdSRoman Zippel emit showRangeChanged(b); 8867fc925fdSRoman Zippel } 8877fc925fdSRoman Zippel } 8887fc925fdSRoman Zippel 8897fc925fdSRoman Zippel void ConfigView::setShowData(bool b) 8907fc925fdSRoman Zippel { 8917fc925fdSRoman Zippel if (list->showData != b) { 8927fc925fdSRoman Zippel list->showData = b; 8937fc925fdSRoman Zippel list->reinit(); 8947fc925fdSRoman Zippel emit showDataChanged(b); 8957fc925fdSRoman Zippel } 8967fc925fdSRoman Zippel } 8977fc925fdSRoman Zippel 8987fc925fdSRoman Zippel void ConfigList::setAllOpen(bool open) 8997fc925fdSRoman Zippel { 9007fc925fdSRoman Zippel QListViewItemIterator it(this); 9017fc925fdSRoman Zippel 9027fc925fdSRoman Zippel for (; it.current(); it++) 9037fc925fdSRoman Zippel it.current()->setOpen(open); 9047fc925fdSRoman Zippel } 9057fc925fdSRoman Zippel 9061da177e4SLinus Torvalds void ConfigView::updateList(ConfigItem* item) 9071da177e4SLinus Torvalds { 9081da177e4SLinus Torvalds ConfigView* v; 9091da177e4SLinus Torvalds 9101da177e4SLinus Torvalds for (v = viewList; v; v = v->nextView) 9111da177e4SLinus Torvalds v->list->updateList(item); 9121da177e4SLinus Torvalds } 9131da177e4SLinus Torvalds 9141da177e4SLinus Torvalds void ConfigView::updateListAll(void) 9151da177e4SLinus Torvalds { 9161da177e4SLinus Torvalds ConfigView* v; 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds for (v = viewList; v; v = v->nextView) 9191da177e4SLinus Torvalds v->list->updateListAll(); 9201da177e4SLinus Torvalds } 9211da177e4SLinus Torvalds 92243bf612aSRoman Zippel ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name) 92398403a91SMarkus Heidelberg : Parent(parent, name), sym(0), menu(0) 9241da177e4SLinus Torvalds { 9257fc925fdSRoman Zippel if (name) { 9267fc925fdSRoman Zippel configSettings->beginGroup(name); 9277fc925fdSRoman Zippel _showDebug = configSettings->readBoolEntry("/showDebug", false); 9287fc925fdSRoman Zippel configSettings->endGroup(); 9297fc925fdSRoman Zippel connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); 9307fc925fdSRoman Zippel } 9317fc925fdSRoman Zippel } 9327fc925fdSRoman Zippel 9337fc925fdSRoman Zippel void ConfigInfoView::saveSettings(void) 9347fc925fdSRoman Zippel { 9357fc925fdSRoman Zippel if (name()) { 9367fc925fdSRoman Zippel configSettings->beginGroup(name()); 9377fc925fdSRoman Zippel configSettings->writeEntry("/showDebug", showDebug()); 9387fc925fdSRoman Zippel configSettings->endGroup(); 9397fc925fdSRoman Zippel } 9401da177e4SLinus Torvalds } 9411da177e4SLinus Torvalds 94243bf612aSRoman Zippel void ConfigInfoView::setShowDebug(bool b) 9431da177e4SLinus Torvalds { 94443bf612aSRoman Zippel if (_showDebug != b) { 94543bf612aSRoman Zippel _showDebug = b; 94643bf612aSRoman Zippel if (menu) 94743bf612aSRoman Zippel menuInfo(); 948ab45d190SRoman Zippel else if (sym) 949ab45d190SRoman Zippel symbolInfo(); 95043bf612aSRoman Zippel emit showDebugChanged(b); 9511da177e4SLinus Torvalds } 9521da177e4SLinus Torvalds } 9531da177e4SLinus Torvalds 95443bf612aSRoman Zippel void ConfigInfoView::setInfo(struct menu *m) 9551da177e4SLinus Torvalds { 956b65a47e1SRoman Zippel if (menu == m) 957b65a47e1SRoman Zippel return; 95843bf612aSRoman Zippel menu = m; 9596fa1da8eSRoman Zippel sym = NULL; 9606fa1da8eSRoman Zippel if (!menu) 96143bf612aSRoman Zippel clear(); 9626fa1da8eSRoman Zippel else 96343bf612aSRoman Zippel menuInfo(); 9641da177e4SLinus Torvalds } 9651da177e4SLinus Torvalds 96643bf612aSRoman Zippel void ConfigInfoView::setSource(const QString& name) 96743bf612aSRoman Zippel { 96843bf612aSRoman Zippel const char *p = name.latin1(); 96943bf612aSRoman Zippel 97043bf612aSRoman Zippel menu = NULL; 971ab45d190SRoman Zippel sym = NULL; 97243bf612aSRoman Zippel 97343bf612aSRoman Zippel switch (p[0]) { 97443bf612aSRoman Zippel case 'm': 975ab45d190SRoman Zippel struct menu *m; 976ab45d190SRoman Zippel 977ab45d190SRoman Zippel if (sscanf(p, "m%p", &m) == 1 && menu != m) { 978ab45d190SRoman Zippel menu = m; 97943bf612aSRoman Zippel menuInfo(); 980b65a47e1SRoman Zippel emit menuSelected(menu); 981ab45d190SRoman Zippel } 982ab45d190SRoman Zippel break; 983ab45d190SRoman Zippel case 's': 984ab45d190SRoman Zippel struct symbol *s; 985ab45d190SRoman Zippel 986ab45d190SRoman Zippel if (sscanf(p, "s%p", &s) == 1 && sym != s) { 987ab45d190SRoman Zippel sym = s; 988ab45d190SRoman Zippel symbolInfo(); 989ab45d190SRoman Zippel } 99043bf612aSRoman Zippel break; 99143bf612aSRoman Zippel } 99243bf612aSRoman Zippel } 99343bf612aSRoman Zippel 994ab45d190SRoman Zippel void ConfigInfoView::symbolInfo(void) 995ab45d190SRoman Zippel { 996ab45d190SRoman Zippel QString str; 997ab45d190SRoman Zippel 998ab45d190SRoman Zippel str += "<big>Symbol: <b>"; 999ab45d190SRoman Zippel str += print_filter(sym->name); 1000ab45d190SRoman Zippel str += "</b></big><br><br>value: "; 1001ab45d190SRoman Zippel str += print_filter(sym_get_string_value(sym)); 1002ab45d190SRoman Zippel str += "<br>visibility: "; 1003ab45d190SRoman Zippel str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n"; 1004ab45d190SRoman Zippel str += "<br>"; 1005ab45d190SRoman Zippel str += debug_info(sym); 1006ab45d190SRoman Zippel 1007ab45d190SRoman Zippel setText(str); 1008ab45d190SRoman Zippel } 1009ab45d190SRoman Zippel 101043bf612aSRoman Zippel void ConfigInfoView::menuInfo(void) 10111da177e4SLinus Torvalds { 10121da177e4SLinus Torvalds struct symbol* sym; 10131da177e4SLinus Torvalds QString head, debug, help; 101443bf612aSRoman Zippel 10151da177e4SLinus Torvalds sym = menu->sym; 10161da177e4SLinus Torvalds if (sym) { 10171da177e4SLinus Torvalds if (menu->prompt) { 10181da177e4SLinus Torvalds head += "<big><b>"; 10193b9fa093SArnaldo Carvalho de Melo head += print_filter(_(menu->prompt->text)); 10201da177e4SLinus Torvalds head += "</b></big>"; 10211da177e4SLinus Torvalds if (sym->name) { 10221da177e4SLinus Torvalds head += " ("; 1023ab45d190SRoman Zippel if (showDebug()) 1024ab45d190SRoman Zippel head += QString().sprintf("<a href=\"s%p\">", sym); 102543bf612aSRoman Zippel head += print_filter(sym->name); 1026ab45d190SRoman Zippel if (showDebug()) 1027ab45d190SRoman Zippel head += "</a>"; 10281da177e4SLinus Torvalds head += ")"; 10291da177e4SLinus Torvalds } 10301da177e4SLinus Torvalds } else if (sym->name) { 10311da177e4SLinus Torvalds head += "<big><b>"; 1032ab45d190SRoman Zippel if (showDebug()) 1033ab45d190SRoman Zippel head += QString().sprintf("<a href=\"s%p\">", sym); 103443bf612aSRoman Zippel head += print_filter(sym->name); 1035ab45d190SRoman Zippel if (showDebug()) 1036ab45d190SRoman Zippel head += "</a>"; 10371da177e4SLinus Torvalds head += "</b></big>"; 10381da177e4SLinus Torvalds } 10391da177e4SLinus Torvalds head += "<br><br>"; 10401da177e4SLinus Torvalds 104143bf612aSRoman Zippel if (showDebug()) 104243bf612aSRoman Zippel debug = debug_info(sym); 104343bf612aSRoman Zippel 1044c21a2d95SEGRY Gabor help = menu_get_help(menu); 1045c21a2d95SEGRY Gabor /* Gettextize if the help text not empty */ 1046c21a2d95SEGRY Gabor if (help.isEmpty()) 1047c21a2d95SEGRY Gabor help = print_filter(menu_get_help(menu)); 1048c21a2d95SEGRY Gabor else 104903d29122SSam Ravnborg help = print_filter(_(menu_get_help(menu))); 105043bf612aSRoman Zippel } else if (menu->prompt) { 105143bf612aSRoman Zippel head += "<big><b>"; 105243bf612aSRoman Zippel head += print_filter(_(menu->prompt->text)); 105343bf612aSRoman Zippel head += "</b></big><br><br>"; 105443bf612aSRoman Zippel if (showDebug()) { 105543bf612aSRoman Zippel if (menu->prompt->visible.expr) { 105643bf612aSRoman Zippel debug += " dep: "; 105743bf612aSRoman Zippel expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE); 105843bf612aSRoman Zippel debug += "<br><br>"; 105943bf612aSRoman Zippel } 106043bf612aSRoman Zippel } 106143bf612aSRoman Zippel } 106243bf612aSRoman Zippel if (showDebug()) 106343bf612aSRoman Zippel debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno); 106443bf612aSRoman Zippel 106543bf612aSRoman Zippel setText(head + debug + help); 106643bf612aSRoman Zippel } 106743bf612aSRoman Zippel 106843bf612aSRoman Zippel QString ConfigInfoView::debug_info(struct symbol *sym) 106943bf612aSRoman Zippel { 107043bf612aSRoman Zippel QString debug; 107143bf612aSRoman Zippel 10721da177e4SLinus Torvalds debug += "type: "; 10731da177e4SLinus Torvalds debug += print_filter(sym_type_name(sym->type)); 10741da177e4SLinus Torvalds if (sym_is_choice(sym)) 10751da177e4SLinus Torvalds debug += " (choice)"; 10761da177e4SLinus Torvalds debug += "<br>"; 10771da177e4SLinus Torvalds if (sym->rev_dep.expr) { 10781da177e4SLinus Torvalds debug += "reverse dep: "; 10791da177e4SLinus Torvalds expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE); 10801da177e4SLinus Torvalds debug += "<br>"; 10811da177e4SLinus Torvalds } 10821da177e4SLinus Torvalds for (struct property *prop = sym->prop; prop; prop = prop->next) { 10831da177e4SLinus Torvalds switch (prop->type) { 10841da177e4SLinus Torvalds case P_PROMPT: 10851da177e4SLinus Torvalds case P_MENU: 1086ab45d190SRoman Zippel debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu); 10873b9fa093SArnaldo Carvalho de Melo debug += print_filter(_(prop->text)); 1088ab45d190SRoman Zippel debug += "</a><br>"; 10891da177e4SLinus Torvalds break; 10901da177e4SLinus Torvalds case P_DEFAULT: 109193449082SRoman Zippel case P_SELECT: 109293449082SRoman Zippel case P_RANGE: 109393449082SRoman Zippel case P_ENV: 109493449082SRoman Zippel debug += prop_get_type_name(prop->type); 109593449082SRoman Zippel debug += ": "; 10961da177e4SLinus Torvalds expr_print(prop->expr, expr_print_help, &debug, E_NONE); 10971da177e4SLinus Torvalds debug += "<br>"; 10981da177e4SLinus Torvalds break; 10991da177e4SLinus Torvalds case P_CHOICE: 11001da177e4SLinus Torvalds if (sym_is_choice(sym)) { 11011da177e4SLinus Torvalds debug += "choice: "; 11021da177e4SLinus Torvalds expr_print(prop->expr, expr_print_help, &debug, E_NONE); 11031da177e4SLinus Torvalds debug += "<br>"; 11041da177e4SLinus Torvalds } 11051da177e4SLinus Torvalds break; 11061da177e4SLinus Torvalds default: 11071da177e4SLinus Torvalds debug += "unknown property: "; 11081da177e4SLinus Torvalds debug += prop_get_type_name(prop->type); 11091da177e4SLinus Torvalds debug += "<br>"; 11101da177e4SLinus Torvalds } 11111da177e4SLinus Torvalds if (prop->visible.expr) { 11121da177e4SLinus Torvalds debug += " dep: "; 11131da177e4SLinus Torvalds expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE); 11141da177e4SLinus Torvalds debug += "<br>"; 11151da177e4SLinus Torvalds } 11161da177e4SLinus Torvalds } 11171da177e4SLinus Torvalds debug += "<br>"; 111843bf612aSRoman Zippel 111943bf612aSRoman Zippel return debug; 11201da177e4SLinus Torvalds } 11211da177e4SLinus Torvalds 112243bf612aSRoman Zippel QString ConfigInfoView::print_filter(const QString &str) 112343bf612aSRoman Zippel { 112443bf612aSRoman Zippel QRegExp re("[<>&\"\\n]"); 112543bf612aSRoman Zippel QString res = str; 112643bf612aSRoman Zippel for (int i = 0; (i = res.find(re, i)) >= 0;) { 112743bf612aSRoman Zippel switch (res[i].latin1()) { 112843bf612aSRoman Zippel case '<': 112943bf612aSRoman Zippel res.replace(i, 1, "<"); 113043bf612aSRoman Zippel i += 4; 113143bf612aSRoman Zippel break; 113243bf612aSRoman Zippel case '>': 113343bf612aSRoman Zippel res.replace(i, 1, ">"); 113443bf612aSRoman Zippel i += 4; 113543bf612aSRoman Zippel break; 113643bf612aSRoman Zippel case '&': 113743bf612aSRoman Zippel res.replace(i, 1, "&"); 113843bf612aSRoman Zippel i += 5; 113943bf612aSRoman Zippel break; 114043bf612aSRoman Zippel case '"': 114143bf612aSRoman Zippel res.replace(i, 1, """); 114243bf612aSRoman Zippel i += 6; 114343bf612aSRoman Zippel break; 114443bf612aSRoman Zippel case '\n': 114543bf612aSRoman Zippel res.replace(i, 1, "<br>"); 114643bf612aSRoman Zippel i += 4; 114743bf612aSRoman Zippel break; 11481da177e4SLinus Torvalds } 11491da177e4SLinus Torvalds } 115043bf612aSRoman Zippel return res; 11511da177e4SLinus Torvalds } 115243bf612aSRoman Zippel 1153ab45d190SRoman Zippel void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str) 115443bf612aSRoman Zippel { 1155ab45d190SRoman Zippel QString* text = reinterpret_cast<QString*>(data); 1156ab45d190SRoman Zippel QString str2 = print_filter(str); 1157ab45d190SRoman Zippel 1158ab45d190SRoman Zippel if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) { 1159ab45d190SRoman Zippel *text += QString().sprintf("<a href=\"s%p\">", sym); 1160ab45d190SRoman Zippel *text += str2; 1161ab45d190SRoman Zippel *text += "</a>"; 1162ab45d190SRoman Zippel } else 1163ab45d190SRoman Zippel *text += str2; 116443bf612aSRoman Zippel } 116543bf612aSRoman Zippel 11667fc925fdSRoman Zippel QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos) 11677fc925fdSRoman Zippel { 11687fc925fdSRoman Zippel QPopupMenu* popup = Parent::createPopupMenu(pos); 1169c21a2d95SEGRY Gabor QAction* action = new QAction(NULL, _("Show Debug Info"), 0, popup); 11707fc925fdSRoman Zippel action->setToggleAction(TRUE); 11717fc925fdSRoman Zippel connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool))); 11727fc925fdSRoman Zippel connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool))); 11737fc925fdSRoman Zippel action->setOn(showDebug()); 11747fc925fdSRoman Zippel popup->insertSeparator(); 11757fc925fdSRoman Zippel action->addTo(popup); 11767fc925fdSRoman Zippel return popup; 11777fc925fdSRoman Zippel } 11787fc925fdSRoman Zippel 11797fc925fdSRoman Zippel void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e) 11807fc925fdSRoman Zippel { 11817fc925fdSRoman Zippel Parent::contentsContextMenuEvent(e); 11827fc925fdSRoman Zippel } 11837fc925fdSRoman Zippel 118463431e75SMarco Costalba ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name) 11857fc925fdSRoman Zippel : Parent(parent, name), result(NULL) 118643bf612aSRoman Zippel { 118743bf612aSRoman Zippel setCaption("Search Config"); 118843bf612aSRoman Zippel 118943bf612aSRoman Zippel QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6); 119043bf612aSRoman Zippel QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6); 1191c21a2d95SEGRY Gabor layout2->addWidget(new QLabel(_("Find:"), this)); 119243bf612aSRoman Zippel editField = new QLineEdit(this); 119343bf612aSRoman Zippel connect(editField, SIGNAL(returnPressed()), SLOT(search())); 119443bf612aSRoman Zippel layout2->addWidget(editField); 1195c21a2d95SEGRY Gabor searchButton = new QPushButton(_("Search"), this); 119643bf612aSRoman Zippel searchButton->setAutoDefault(FALSE); 119743bf612aSRoman Zippel connect(searchButton, SIGNAL(clicked()), SLOT(search())); 119843bf612aSRoman Zippel layout2->addWidget(searchButton); 119943bf612aSRoman Zippel layout1->addLayout(layout2); 120043bf612aSRoman Zippel 12017fc925fdSRoman Zippel split = new QSplitter(this); 12027298b936SMarkus Heidelberg split->setOrientation(Qt::Vertical); 12037fc925fdSRoman Zippel list = new ConfigView(split, name); 120443bf612aSRoman Zippel list->list->mode = listMode; 12057fc925fdSRoman Zippel info = new ConfigInfoView(split, name); 120643bf612aSRoman Zippel connect(list->list, SIGNAL(menuChanged(struct menu *)), 120743bf612aSRoman Zippel info, SLOT(setInfo(struct menu *))); 120863431e75SMarco Costalba connect(list->list, SIGNAL(menuChanged(struct menu *)), 120963431e75SMarco Costalba parent, SLOT(setMenuLink(struct menu *))); 121063431e75SMarco Costalba 121143bf612aSRoman Zippel layout1->addWidget(split); 12127fc925fdSRoman Zippel 12137fc925fdSRoman Zippel if (name) { 12147fc925fdSRoman Zippel int x, y, width, height; 12157fc925fdSRoman Zippel bool ok; 12167fc925fdSRoman Zippel 12177fc925fdSRoman Zippel configSettings->beginGroup(name); 12187fc925fdSRoman Zippel width = configSettings->readNumEntry("/window width", parent->width() / 2); 12197fc925fdSRoman Zippel height = configSettings->readNumEntry("/window height", parent->height() / 2); 12207fc925fdSRoman Zippel resize(width, height); 12217fc925fdSRoman Zippel x = configSettings->readNumEntry("/window x", 0, &ok); 12227fc925fdSRoman Zippel if (ok) 12237fc925fdSRoman Zippel y = configSettings->readNumEntry("/window y", 0, &ok); 12247fc925fdSRoman Zippel if (ok) 12257fc925fdSRoman Zippel move(x, y); 12267fc925fdSRoman Zippel QValueList<int> sizes = configSettings->readSizes("/split", &ok); 12277fc925fdSRoman Zippel if (ok) 12287fc925fdSRoman Zippel split->setSizes(sizes); 12297fc925fdSRoman Zippel configSettings->endGroup(); 12307fc925fdSRoman Zippel connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); 12317fc925fdSRoman Zippel } 12327fc925fdSRoman Zippel } 12337fc925fdSRoman Zippel 12347fc925fdSRoman Zippel void ConfigSearchWindow::saveSettings(void) 12357fc925fdSRoman Zippel { 12367fc925fdSRoman Zippel if (name()) { 12377fc925fdSRoman Zippel configSettings->beginGroup(name()); 12387fc925fdSRoman Zippel configSettings->writeEntry("/window x", pos().x()); 12397fc925fdSRoman Zippel configSettings->writeEntry("/window y", pos().y()); 12407fc925fdSRoman Zippel configSettings->writeEntry("/window width", size().width()); 12417fc925fdSRoman Zippel configSettings->writeEntry("/window height", size().height()); 12427fc925fdSRoman Zippel configSettings->writeSizes("/split", split->sizes()); 12437fc925fdSRoman Zippel configSettings->endGroup(); 12447fc925fdSRoman Zippel } 124543bf612aSRoman Zippel } 124643bf612aSRoman Zippel 124743bf612aSRoman Zippel void ConfigSearchWindow::search(void) 124843bf612aSRoman Zippel { 124943bf612aSRoman Zippel struct symbol **p; 125043bf612aSRoman Zippel struct property *prop; 125143bf612aSRoman Zippel ConfigItem *lastItem = NULL; 125243bf612aSRoman Zippel 125343bf612aSRoman Zippel free(result); 125443bf612aSRoman Zippel list->list->clear(); 1255786fb18dSCyrill V. Gorcunov info->clear(); 125643bf612aSRoman Zippel 125743bf612aSRoman Zippel result = sym_re_search(editField->text().latin1()); 125843bf612aSRoman Zippel if (!result) 125943bf612aSRoman Zippel return; 126043bf612aSRoman Zippel for (p = result; *p; p++) { 126143bf612aSRoman Zippel for_all_prompts((*p), prop) 126243bf612aSRoman Zippel lastItem = new ConfigItem(list->list, lastItem, prop->menu, 126343bf612aSRoman Zippel menu_is_visible(prop->menu)); 126443bf612aSRoman Zippel } 126543bf612aSRoman Zippel } 126643bf612aSRoman Zippel 126743bf612aSRoman Zippel /* 126843bf612aSRoman Zippel * Construct the complete config widget 126943bf612aSRoman Zippel */ 127043bf612aSRoman Zippel ConfigMainWindow::ConfigMainWindow(void) 1271f12aa704SRoman Zippel : searchWindow(0) 127243bf612aSRoman Zippel { 127343bf612aSRoman Zippel QMenuBar* menu; 12747fc925fdSRoman Zippel bool ok; 127543bf612aSRoman Zippel int x, y, width, height; 1276a54bb701SRandy Dunlap char title[256]; 127743bf612aSRoman Zippel 127843bf612aSRoman Zippel QWidget *d = configApp->desktop(); 1279a54bb701SRandy Dunlap snprintf(title, sizeof(title), _("Linux Kernel v%s Configuration"), 1280a54bb701SRandy Dunlap getenv("KERNELVERSION")); 1281a54bb701SRandy Dunlap setCaption(title); 128243bf612aSRoman Zippel 12837fc925fdSRoman Zippel width = configSettings->readNumEntry("/window width", d->width() - 64); 12847fc925fdSRoman Zippel height = configSettings->readNumEntry("/window height", d->height() - 64); 128543bf612aSRoman Zippel resize(width, height); 12867fc925fdSRoman Zippel x = configSettings->readNumEntry("/window x", 0, &ok); 128743bf612aSRoman Zippel if (ok) 12887fc925fdSRoman Zippel y = configSettings->readNumEntry("/window y", 0, &ok); 128943bf612aSRoman Zippel if (ok) 129043bf612aSRoman Zippel move(x, y); 129143bf612aSRoman Zippel 129243bf612aSRoman Zippel split1 = new QSplitter(this); 12937298b936SMarkus Heidelberg split1->setOrientation(Qt::Horizontal); 129443bf612aSRoman Zippel setCentralWidget(split1); 129543bf612aSRoman Zippel 12967fc925fdSRoman Zippel menuView = new ConfigView(split1, "menu"); 129743bf612aSRoman Zippel menuList = menuView->list; 129843bf612aSRoman Zippel 129943bf612aSRoman Zippel split2 = new QSplitter(split1); 13007298b936SMarkus Heidelberg split2->setOrientation(Qt::Vertical); 130143bf612aSRoman Zippel 130243bf612aSRoman Zippel // create config tree 13037fc925fdSRoman Zippel configView = new ConfigView(split2, "config"); 130443bf612aSRoman Zippel configList = configView->list; 130543bf612aSRoman Zippel 13067fc925fdSRoman Zippel helpText = new ConfigInfoView(split2, "help"); 130743bf612aSRoman Zippel helpText->setTextFormat(Qt::RichText); 130843bf612aSRoman Zippel 130943bf612aSRoman Zippel setTabOrder(configList, helpText); 131043bf612aSRoman Zippel configList->setFocus(); 131143bf612aSRoman Zippel 131243bf612aSRoman Zippel menu = menuBar(); 131343bf612aSRoman Zippel toolBar = new QToolBar("Tools", this); 131443bf612aSRoman Zippel 1315c21a2d95SEGRY Gabor backAction = new QAction("Back", QPixmap(xpm_back), _("Back"), 0, this); 131643bf612aSRoman Zippel connect(backAction, SIGNAL(activated()), SLOT(goBack())); 131743bf612aSRoman Zippel backAction->setEnabled(FALSE); 1318fbb86374SMarkus Heidelberg QAction *quitAction = new QAction("Quit", _("&Quit"), Qt::CTRL + Qt::Key_Q, this); 131943bf612aSRoman Zippel connect(quitAction, SIGNAL(activated()), SLOT(close())); 1320fbb86374SMarkus Heidelberg QAction *loadAction = new QAction("Load", QPixmap(xpm_load), _("&Load"), Qt::CTRL + Qt::Key_L, this); 132143bf612aSRoman Zippel connect(loadAction, SIGNAL(activated()), SLOT(loadConfig())); 1322fbb86374SMarkus Heidelberg saveAction = new QAction("Save", QPixmap(xpm_save), _("&Save"), Qt::CTRL + Qt::Key_S, this); 132343bf612aSRoman Zippel connect(saveAction, SIGNAL(activated()), SLOT(saveConfig())); 13243b354c55SKarsten Wiese conf_set_changed_callback(conf_changed); 13253b354c55SKarsten Wiese // Set saveAction's initial state 13263b354c55SKarsten Wiese conf_changed(); 1327c21a2d95SEGRY Gabor QAction *saveAsAction = new QAction("Save As...", _("Save &As..."), 0, this); 132843bf612aSRoman Zippel connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs())); 1329fbb86374SMarkus Heidelberg QAction *searchAction = new QAction("Find", _("&Find"), Qt::CTRL + Qt::Key_F, this); 133043bf612aSRoman Zippel connect(searchAction, SIGNAL(activated()), SLOT(searchConfig())); 1331c21a2d95SEGRY Gabor QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), _("Single View"), 0, this); 133243bf612aSRoman Zippel connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView())); 1333c21a2d95SEGRY Gabor QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), _("Split View"), 0, this); 133443bf612aSRoman Zippel connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView())); 1335c21a2d95SEGRY Gabor QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), _("Full View"), 0, this); 133643bf612aSRoman Zippel connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView())); 133743bf612aSRoman Zippel 1338c21a2d95SEGRY Gabor QAction *showNameAction = new QAction(NULL, _("Show Name"), 0, this); 133943bf612aSRoman Zippel showNameAction->setToggleAction(TRUE); 13407fc925fdSRoman Zippel connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool))); 13417fc925fdSRoman Zippel connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool))); 13427fc925fdSRoman Zippel showNameAction->setOn(configView->showName()); 1343c21a2d95SEGRY Gabor QAction *showRangeAction = new QAction(NULL, _("Show Range"), 0, this); 134443bf612aSRoman Zippel showRangeAction->setToggleAction(TRUE); 13457fc925fdSRoman Zippel connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool))); 13467fc925fdSRoman Zippel connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool))); 134743bf612aSRoman Zippel showRangeAction->setOn(configList->showRange); 1348c21a2d95SEGRY Gabor QAction *showDataAction = new QAction(NULL, _("Show Data"), 0, this); 134943bf612aSRoman Zippel showDataAction->setToggleAction(TRUE); 13507fc925fdSRoman Zippel connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool))); 13517fc925fdSRoman Zippel connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool))); 135243bf612aSRoman Zippel showDataAction->setOn(configList->showData); 1353c21a2d95SEGRY Gabor QAction *showAllAction = new QAction(NULL, _("Show All Options"), 0, this); 135443bf612aSRoman Zippel showAllAction->setToggleAction(TRUE); 13557fc925fdSRoman Zippel connect(showAllAction, SIGNAL(toggled(bool)), configView, SLOT(setShowAll(bool))); 13567fc925fdSRoman Zippel connect(showAllAction, SIGNAL(toggled(bool)), menuView, SLOT(setShowAll(bool))); 135743bf612aSRoman Zippel showAllAction->setOn(configList->showAll); 1358c21a2d95SEGRY Gabor QAction *showDebugAction = new QAction(NULL, _("Show Debug Info"), 0, this); 135943bf612aSRoman Zippel showDebugAction->setToggleAction(TRUE); 136043bf612aSRoman Zippel connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool))); 136143bf612aSRoman Zippel connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool))); 13627fc925fdSRoman Zippel showDebugAction->setOn(helpText->showDebug()); 136343bf612aSRoman Zippel 1364c21a2d95SEGRY Gabor QAction *showIntroAction = new QAction(NULL, _("Introduction"), 0, this); 136543bf612aSRoman Zippel connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro())); 1366c21a2d95SEGRY Gabor QAction *showAboutAction = new QAction(NULL, _("About"), 0, this); 136743bf612aSRoman Zippel connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout())); 136843bf612aSRoman Zippel 136943bf612aSRoman Zippel // init tool bar 137043bf612aSRoman Zippel backAction->addTo(toolBar); 137143bf612aSRoman Zippel toolBar->addSeparator(); 137243bf612aSRoman Zippel loadAction->addTo(toolBar); 137343bf612aSRoman Zippel saveAction->addTo(toolBar); 137443bf612aSRoman Zippel toolBar->addSeparator(); 137543bf612aSRoman Zippel singleViewAction->addTo(toolBar); 137643bf612aSRoman Zippel splitViewAction->addTo(toolBar); 137743bf612aSRoman Zippel fullViewAction->addTo(toolBar); 137843bf612aSRoman Zippel 137943bf612aSRoman Zippel // create config menu 138043bf612aSRoman Zippel QPopupMenu* config = new QPopupMenu(this); 1381c21a2d95SEGRY Gabor menu->insertItem(_("&File"), config); 138243bf612aSRoman Zippel loadAction->addTo(config); 138343bf612aSRoman Zippel saveAction->addTo(config); 138443bf612aSRoman Zippel saveAsAction->addTo(config); 138543bf612aSRoman Zippel config->insertSeparator(); 138643bf612aSRoman Zippel quitAction->addTo(config); 138743bf612aSRoman Zippel 138866e7c723SShlomi Fish // create edit menu 138966e7c723SShlomi Fish QPopupMenu* editMenu = new QPopupMenu(this); 1390c21a2d95SEGRY Gabor menu->insertItem(_("&Edit"), editMenu); 139166e7c723SShlomi Fish searchAction->addTo(editMenu); 139266e7c723SShlomi Fish 139343bf612aSRoman Zippel // create options menu 139443bf612aSRoman Zippel QPopupMenu* optionMenu = new QPopupMenu(this); 1395c21a2d95SEGRY Gabor menu->insertItem(_("&Option"), optionMenu); 139643bf612aSRoman Zippel showNameAction->addTo(optionMenu); 139743bf612aSRoman Zippel showRangeAction->addTo(optionMenu); 139843bf612aSRoman Zippel showDataAction->addTo(optionMenu); 139943bf612aSRoman Zippel optionMenu->insertSeparator(); 140043bf612aSRoman Zippel showAllAction->addTo(optionMenu); 140143bf612aSRoman Zippel showDebugAction->addTo(optionMenu); 140243bf612aSRoman Zippel 140343bf612aSRoman Zippel // create help menu 140443bf612aSRoman Zippel QPopupMenu* helpMenu = new QPopupMenu(this); 140543bf612aSRoman Zippel menu->insertSeparator(); 1406c21a2d95SEGRY Gabor menu->insertItem(_("&Help"), helpMenu); 140743bf612aSRoman Zippel showIntroAction->addTo(helpMenu); 140843bf612aSRoman Zippel showAboutAction->addTo(helpMenu); 140943bf612aSRoman Zippel 141043bf612aSRoman Zippel connect(configList, SIGNAL(menuChanged(struct menu *)), 141143bf612aSRoman Zippel helpText, SLOT(setInfo(struct menu *))); 141243bf612aSRoman Zippel connect(configList, SIGNAL(menuSelected(struct menu *)), 141343bf612aSRoman Zippel SLOT(changeMenu(struct menu *))); 141443bf612aSRoman Zippel connect(configList, SIGNAL(parentSelected()), 141543bf612aSRoman Zippel SLOT(goBack())); 141643bf612aSRoman Zippel connect(menuList, SIGNAL(menuChanged(struct menu *)), 141743bf612aSRoman Zippel helpText, SLOT(setInfo(struct menu *))); 141843bf612aSRoman Zippel connect(menuList, SIGNAL(menuSelected(struct menu *)), 141943bf612aSRoman Zippel SLOT(changeMenu(struct menu *))); 142043bf612aSRoman Zippel 1421b65a47e1SRoman Zippel connect(configList, SIGNAL(gotFocus(struct menu *)), 1422b65a47e1SRoman Zippel helpText, SLOT(setInfo(struct menu *))); 1423b65a47e1SRoman Zippel connect(menuList, SIGNAL(gotFocus(struct menu *)), 1424b65a47e1SRoman Zippel helpText, SLOT(setInfo(struct menu *))); 1425b65a47e1SRoman Zippel connect(menuList, SIGNAL(gotFocus(struct menu *)), 142643bf612aSRoman Zippel SLOT(listFocusChanged(void))); 1427b65a47e1SRoman Zippel connect(helpText, SIGNAL(menuSelected(struct menu *)), 1428b65a47e1SRoman Zippel SLOT(setMenuLink(struct menu *))); 142943bf612aSRoman Zippel 14307fc925fdSRoman Zippel QString listMode = configSettings->readEntry("/listMode", "symbol"); 143143bf612aSRoman Zippel if (listMode == "single") 143243bf612aSRoman Zippel showSingleView(); 143343bf612aSRoman Zippel else if (listMode == "full") 143443bf612aSRoman Zippel showFullView(); 143543bf612aSRoman Zippel else /*if (listMode == "split")*/ 143643bf612aSRoman Zippel showSplitView(); 143743bf612aSRoman Zippel 143843bf612aSRoman Zippel // UI setup done, restore splitter positions 14397fc925fdSRoman Zippel QValueList<int> sizes = configSettings->readSizes("/split1", &ok); 144043bf612aSRoman Zippel if (ok) 144143bf612aSRoman Zippel split1->setSizes(sizes); 144243bf612aSRoman Zippel 14437fc925fdSRoman Zippel sizes = configSettings->readSizes("/split2", &ok); 144443bf612aSRoman Zippel if (ok) 144543bf612aSRoman Zippel split2->setSizes(sizes); 144643bf612aSRoman Zippel } 144743bf612aSRoman Zippel 14481da177e4SLinus Torvalds void ConfigMainWindow::loadConfig(void) 14491da177e4SLinus Torvalds { 14501da177e4SLinus Torvalds QString s = QFileDialog::getOpenFileName(".config", NULL, this); 14511da177e4SLinus Torvalds if (s.isNull()) 14521da177e4SLinus Torvalds return; 14533b9fa093SArnaldo Carvalho de Melo if (conf_read(QFile::encodeName(s))) 1454c21a2d95SEGRY Gabor QMessageBox::information(this, "qconf", _("Unable to load configuration!")); 14551da177e4SLinus Torvalds ConfigView::updateListAll(); 14561da177e4SLinus Torvalds } 14571da177e4SLinus Torvalds 14581da177e4SLinus Torvalds void ConfigMainWindow::saveConfig(void) 14591da177e4SLinus Torvalds { 14601da177e4SLinus Torvalds if (conf_write(NULL)) 1461c21a2d95SEGRY Gabor QMessageBox::information(this, "qconf", _("Unable to save configuration!")); 14621da177e4SLinus Torvalds } 14631da177e4SLinus Torvalds 14641da177e4SLinus Torvalds void ConfigMainWindow::saveConfigAs(void) 14651da177e4SLinus Torvalds { 14661da177e4SLinus Torvalds QString s = QFileDialog::getSaveFileName(".config", NULL, this); 14671da177e4SLinus Torvalds if (s.isNull()) 14681da177e4SLinus Torvalds return; 14693b9fa093SArnaldo Carvalho de Melo if (conf_write(QFile::encodeName(s))) 1470c21a2d95SEGRY Gabor QMessageBox::information(this, "qconf", _("Unable to save configuration!")); 14711da177e4SLinus Torvalds } 14721da177e4SLinus Torvalds 147343bf612aSRoman Zippel void ConfigMainWindow::searchConfig(void) 147443bf612aSRoman Zippel { 147543bf612aSRoman Zippel if (!searchWindow) 14767fc925fdSRoman Zippel searchWindow = new ConfigSearchWindow(this, "search"); 147743bf612aSRoman Zippel searchWindow->show(); 147843bf612aSRoman Zippel } 147943bf612aSRoman Zippel 14801da177e4SLinus Torvalds void ConfigMainWindow::changeMenu(struct menu *menu) 14811da177e4SLinus Torvalds { 14821da177e4SLinus Torvalds configList->setRootMenu(menu); 1483f253f000SCyrill V. Gorcunov if (configList->rootEntry->parent == &rootmenu) 1484f253f000SCyrill V. Gorcunov backAction->setEnabled(FALSE); 1485f253f000SCyrill V. Gorcunov else 14861da177e4SLinus Torvalds backAction->setEnabled(TRUE); 14871da177e4SLinus Torvalds } 14881da177e4SLinus Torvalds 1489b65a47e1SRoman Zippel void ConfigMainWindow::setMenuLink(struct menu *menu) 1490b65a47e1SRoman Zippel { 1491b65a47e1SRoman Zippel struct menu *parent; 1492b65a47e1SRoman Zippel ConfigList* list = NULL; 1493b65a47e1SRoman Zippel ConfigItem* item; 1494b65a47e1SRoman Zippel 1495b65a47e1SRoman Zippel if (!menu_is_visible(menu) && !configView->showAll()) 1496b65a47e1SRoman Zippel return; 1497b65a47e1SRoman Zippel 1498b65a47e1SRoman Zippel switch (configList->mode) { 1499b65a47e1SRoman Zippel case singleMode: 1500b65a47e1SRoman Zippel list = configList; 1501b65a47e1SRoman Zippel parent = menu_get_parent_menu(menu); 1502b65a47e1SRoman Zippel if (!parent) 1503b65a47e1SRoman Zippel return; 1504b65a47e1SRoman Zippel list->setRootMenu(parent); 1505b65a47e1SRoman Zippel break; 1506b65a47e1SRoman Zippel case symbolMode: 1507b65a47e1SRoman Zippel if (menu->flags & MENU_ROOT) { 1508b65a47e1SRoman Zippel configList->setRootMenu(menu); 1509b65a47e1SRoman Zippel configList->clearSelection(); 1510b65a47e1SRoman Zippel list = menuList; 1511b65a47e1SRoman Zippel } else { 1512b65a47e1SRoman Zippel list = configList; 1513b65a47e1SRoman Zippel parent = menu_get_parent_menu(menu->parent); 1514b65a47e1SRoman Zippel if (!parent) 1515b65a47e1SRoman Zippel return; 1516b65a47e1SRoman Zippel item = menuList->findConfigItem(parent); 1517b65a47e1SRoman Zippel if (item) { 1518b65a47e1SRoman Zippel menuList->setSelected(item, TRUE); 1519b65a47e1SRoman Zippel menuList->ensureItemVisible(item); 1520b65a47e1SRoman Zippel } 1521b65a47e1SRoman Zippel list->setRootMenu(parent); 1522b65a47e1SRoman Zippel } 1523b65a47e1SRoman Zippel break; 1524b65a47e1SRoman Zippel case fullMode: 1525b65a47e1SRoman Zippel list = configList; 1526b65a47e1SRoman Zippel break; 152798403a91SMarkus Heidelberg default: 152898403a91SMarkus Heidelberg break; 1529b65a47e1SRoman Zippel } 1530b65a47e1SRoman Zippel 1531b65a47e1SRoman Zippel if (list) { 1532b65a47e1SRoman Zippel item = list->findConfigItem(menu); 1533b65a47e1SRoman Zippel if (item) { 1534b65a47e1SRoman Zippel list->setSelected(item, TRUE); 1535b65a47e1SRoman Zippel list->ensureItemVisible(item); 1536b65a47e1SRoman Zippel list->setFocus(); 1537b65a47e1SRoman Zippel } 1538b65a47e1SRoman Zippel } 1539b65a47e1SRoman Zippel } 1540b65a47e1SRoman Zippel 15411da177e4SLinus Torvalds void ConfigMainWindow::listFocusChanged(void) 15421da177e4SLinus Torvalds { 15431da177e4SLinus Torvalds if (menuList->mode == menuMode) 15441da177e4SLinus Torvalds configList->clearSelection(); 15451da177e4SLinus Torvalds } 15461da177e4SLinus Torvalds 15471da177e4SLinus Torvalds void ConfigMainWindow::goBack(void) 15481da177e4SLinus Torvalds { 15491da177e4SLinus Torvalds ConfigItem* item; 15501da177e4SLinus Torvalds 15511da177e4SLinus Torvalds configList->setParentMenu(); 15521da177e4SLinus Torvalds if (configList->rootEntry == &rootmenu) 15531da177e4SLinus Torvalds backAction->setEnabled(FALSE); 15541da177e4SLinus Torvalds item = (ConfigItem*)menuList->selectedItem(); 15551da177e4SLinus Torvalds while (item) { 15561da177e4SLinus Torvalds if (item->menu == configList->rootEntry) { 15571da177e4SLinus Torvalds menuList->setSelected(item, TRUE); 15581da177e4SLinus Torvalds break; 15591da177e4SLinus Torvalds } 15601da177e4SLinus Torvalds item = (ConfigItem*)item->parent(); 15611da177e4SLinus Torvalds } 15621da177e4SLinus Torvalds } 15631da177e4SLinus Torvalds 15641da177e4SLinus Torvalds void ConfigMainWindow::showSingleView(void) 15651da177e4SLinus Torvalds { 15661da177e4SLinus Torvalds menuView->hide(); 15671da177e4SLinus Torvalds menuList->setRootMenu(0); 15681da177e4SLinus Torvalds configList->mode = singleMode; 15691da177e4SLinus Torvalds if (configList->rootEntry == &rootmenu) 15701da177e4SLinus Torvalds configList->updateListAll(); 15711da177e4SLinus Torvalds else 15721da177e4SLinus Torvalds configList->setRootMenu(&rootmenu); 15731da177e4SLinus Torvalds configList->setAllOpen(TRUE); 15741da177e4SLinus Torvalds configList->setFocus(); 15751da177e4SLinus Torvalds } 15761da177e4SLinus Torvalds 15771da177e4SLinus Torvalds void ConfigMainWindow::showSplitView(void) 15781da177e4SLinus Torvalds { 15791da177e4SLinus Torvalds configList->mode = symbolMode; 15801da177e4SLinus Torvalds if (configList->rootEntry == &rootmenu) 15811da177e4SLinus Torvalds configList->updateListAll(); 15821da177e4SLinus Torvalds else 15831da177e4SLinus Torvalds configList->setRootMenu(&rootmenu); 15841da177e4SLinus Torvalds configList->setAllOpen(TRUE); 15851da177e4SLinus Torvalds configApp->processEvents(); 15861da177e4SLinus Torvalds menuList->mode = menuMode; 15871da177e4SLinus Torvalds menuList->setRootMenu(&rootmenu); 15881da177e4SLinus Torvalds menuList->setAllOpen(TRUE); 15891da177e4SLinus Torvalds menuView->show(); 15901da177e4SLinus Torvalds menuList->setFocus(); 15911da177e4SLinus Torvalds } 15921da177e4SLinus Torvalds 15931da177e4SLinus Torvalds void ConfigMainWindow::showFullView(void) 15941da177e4SLinus Torvalds { 15951da177e4SLinus Torvalds menuView->hide(); 15961da177e4SLinus Torvalds menuList->setRootMenu(0); 15971da177e4SLinus Torvalds configList->mode = fullMode; 15981da177e4SLinus Torvalds if (configList->rootEntry == &rootmenu) 15991da177e4SLinus Torvalds configList->updateListAll(); 16001da177e4SLinus Torvalds else 16011da177e4SLinus Torvalds configList->setRootMenu(&rootmenu); 16021da177e4SLinus Torvalds configList->setAllOpen(FALSE); 16031da177e4SLinus Torvalds configList->setFocus(); 16041da177e4SLinus Torvalds } 16051da177e4SLinus Torvalds 16061da177e4SLinus Torvalds /* 16071da177e4SLinus Torvalds * ask for saving configuration before quitting 16081da177e4SLinus Torvalds * TODO ask only when something changed 16091da177e4SLinus Torvalds */ 16101da177e4SLinus Torvalds void ConfigMainWindow::closeEvent(QCloseEvent* e) 16111da177e4SLinus Torvalds { 1612b3214293SKarsten Wiese if (!conf_get_changed()) { 16131da177e4SLinus Torvalds e->accept(); 16141da177e4SLinus Torvalds return; 16151da177e4SLinus Torvalds } 1616c21a2d95SEGRY Gabor QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning, 16171da177e4SLinus Torvalds QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); 1618c21a2d95SEGRY Gabor mb.setButtonText(QMessageBox::Yes, _("&Save Changes")); 1619c21a2d95SEGRY Gabor mb.setButtonText(QMessageBox::No, _("&Discard Changes")); 1620c21a2d95SEGRY Gabor mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit")); 16211da177e4SLinus Torvalds switch (mb.exec()) { 16221da177e4SLinus Torvalds case QMessageBox::Yes: 16231da177e4SLinus Torvalds conf_write(NULL); 16241da177e4SLinus Torvalds case QMessageBox::No: 16251da177e4SLinus Torvalds e->accept(); 16261da177e4SLinus Torvalds break; 16271da177e4SLinus Torvalds case QMessageBox::Cancel: 16281da177e4SLinus Torvalds e->ignore(); 16291da177e4SLinus Torvalds break; 16301da177e4SLinus Torvalds } 16311da177e4SLinus Torvalds } 16321da177e4SLinus Torvalds 16331da177e4SLinus Torvalds void ConfigMainWindow::showIntro(void) 16341da177e4SLinus Torvalds { 1635c21a2d95SEGRY Gabor static const QString str = _("Welcome to the qconf graphical kernel configuration tool for Linux.\n\n" 16361da177e4SLinus Torvalds "For each option, a blank box indicates the feature is disabled, a check\n" 16371da177e4SLinus Torvalds "indicates it is enabled, and a dot indicates that it is to be compiled\n" 16381da177e4SLinus Torvalds "as a module. Clicking on the box will cycle through the three states.\n\n" 16391da177e4SLinus Torvalds "If you do not see an option (e.g., a device driver) that you believe\n" 16401da177e4SLinus Torvalds "should be present, try turning on Show All Options under the Options menu.\n" 16411da177e4SLinus Torvalds "Although there is no cross reference yet to help you figure out what other\n" 16421da177e4SLinus Torvalds "options must be enabled to support the option you are interested in, you can\n" 16431da177e4SLinus Torvalds "still view the help of a grayed-out option.\n\n" 16441da177e4SLinus Torvalds "Toggling Show Debug Info under the Options menu will show the dependencies,\n" 1645c21a2d95SEGRY Gabor "which you can then match by examining other options.\n\n"); 16461da177e4SLinus Torvalds 16471da177e4SLinus Torvalds QMessageBox::information(this, "qconf", str); 16481da177e4SLinus Torvalds } 16491da177e4SLinus Torvalds 16501da177e4SLinus Torvalds void ConfigMainWindow::showAbout(void) 16511da177e4SLinus Torvalds { 1652c21a2d95SEGRY Gabor static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n" 1653c21a2d95SEGRY Gabor "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n"); 16541da177e4SLinus Torvalds 16551da177e4SLinus Torvalds QMessageBox::information(this, "qconf", str); 16561da177e4SLinus Torvalds } 16571da177e4SLinus Torvalds 16581da177e4SLinus Torvalds void ConfigMainWindow::saveSettings(void) 16591da177e4SLinus Torvalds { 16607fc925fdSRoman Zippel configSettings->writeEntry("/window x", pos().x()); 16617fc925fdSRoman Zippel configSettings->writeEntry("/window y", pos().y()); 16627fc925fdSRoman Zippel configSettings->writeEntry("/window width", size().width()); 16637fc925fdSRoman Zippel configSettings->writeEntry("/window height", size().height()); 16641da177e4SLinus Torvalds 16651da177e4SLinus Torvalds QString entry; 16661da177e4SLinus Torvalds switch(configList->mode) { 16671da177e4SLinus Torvalds case singleMode : 16681da177e4SLinus Torvalds entry = "single"; 16691da177e4SLinus Torvalds break; 16701da177e4SLinus Torvalds 16711da177e4SLinus Torvalds case symbolMode : 16721da177e4SLinus Torvalds entry = "split"; 16731da177e4SLinus Torvalds break; 16741da177e4SLinus Torvalds 16751da177e4SLinus Torvalds case fullMode : 16761da177e4SLinus Torvalds entry = "full"; 16771da177e4SLinus Torvalds break; 167898403a91SMarkus Heidelberg 167998403a91SMarkus Heidelberg default: 168098403a91SMarkus Heidelberg break; 16811da177e4SLinus Torvalds } 16827fc925fdSRoman Zippel configSettings->writeEntry("/listMode", entry); 16831da177e4SLinus Torvalds 16847fc925fdSRoman Zippel configSettings->writeSizes("/split1", split1->sizes()); 16857fc925fdSRoman Zippel configSettings->writeSizes("/split2", split2->sizes()); 16861da177e4SLinus Torvalds } 16871da177e4SLinus Torvalds 16883b354c55SKarsten Wiese void ConfigMainWindow::conf_changed(void) 16893b354c55SKarsten Wiese { 16903b354c55SKarsten Wiese if (saveAction) 16913b354c55SKarsten Wiese saveAction->setEnabled(conf_get_changed()); 16923b354c55SKarsten Wiese } 16933b354c55SKarsten Wiese 16941da177e4SLinus Torvalds void fixup_rootmenu(struct menu *menu) 16951da177e4SLinus Torvalds { 16961da177e4SLinus Torvalds struct menu *child; 16971da177e4SLinus Torvalds static int menu_cnt = 0; 16981da177e4SLinus Torvalds 16991da177e4SLinus Torvalds menu->flags |= MENU_ROOT; 17001da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) { 17011da177e4SLinus Torvalds if (child->prompt && child->prompt->type == P_MENU) { 17021da177e4SLinus Torvalds menu_cnt++; 17031da177e4SLinus Torvalds fixup_rootmenu(child); 17041da177e4SLinus Torvalds menu_cnt--; 17051da177e4SLinus Torvalds } else if (!menu_cnt) 17061da177e4SLinus Torvalds fixup_rootmenu(child); 17071da177e4SLinus Torvalds } 17081da177e4SLinus Torvalds } 17091da177e4SLinus Torvalds 17101da177e4SLinus Torvalds static const char *progname; 17111da177e4SLinus Torvalds 17121da177e4SLinus Torvalds static void usage(void) 17131da177e4SLinus Torvalds { 1714c21a2d95SEGRY Gabor printf(_("%s <config>\n"), progname); 17151da177e4SLinus Torvalds exit(0); 17161da177e4SLinus Torvalds } 17171da177e4SLinus Torvalds 17181da177e4SLinus Torvalds int main(int ac, char** av) 17191da177e4SLinus Torvalds { 17201da177e4SLinus Torvalds ConfigMainWindow* v; 17211da177e4SLinus Torvalds const char *name; 17221da177e4SLinus Torvalds 17233b9fa093SArnaldo Carvalho de Melo bindtextdomain(PACKAGE, LOCALEDIR); 17243b9fa093SArnaldo Carvalho de Melo textdomain(PACKAGE); 17253b9fa093SArnaldo Carvalho de Melo 17261da177e4SLinus Torvalds #ifndef LKC_DIRECT_LINK 17271da177e4SLinus Torvalds kconfig_load(); 17281da177e4SLinus Torvalds #endif 17291da177e4SLinus Torvalds 17301da177e4SLinus Torvalds progname = av[0]; 17311da177e4SLinus Torvalds configApp = new QApplication(ac, av); 17321da177e4SLinus Torvalds if (ac > 1 && av[1][0] == '-') { 17331da177e4SLinus Torvalds switch (av[1][1]) { 17341da177e4SLinus Torvalds case 'h': 17351da177e4SLinus Torvalds case '?': 17361da177e4SLinus Torvalds usage(); 17371da177e4SLinus Torvalds } 17381da177e4SLinus Torvalds name = av[2]; 17391da177e4SLinus Torvalds } else 17401da177e4SLinus Torvalds name = av[1]; 17411da177e4SLinus Torvalds if (!name) 17421da177e4SLinus Torvalds usage(); 17431da177e4SLinus Torvalds 17441da177e4SLinus Torvalds conf_parse(name); 17451da177e4SLinus Torvalds fixup_rootmenu(&rootmenu); 17461da177e4SLinus Torvalds conf_read(NULL); 17471da177e4SLinus Torvalds //zconfdump(stdout); 17481da177e4SLinus Torvalds 17497fc925fdSRoman Zippel configSettings = new ConfigSettings(); 17507fc925fdSRoman Zippel configSettings->beginGroup("/kconfig/qconf"); 17511da177e4SLinus Torvalds v = new ConfigMainWindow(); 17521da177e4SLinus Torvalds 17531da177e4SLinus Torvalds //zconfdump(stdout); 175443bf612aSRoman Zippel configApp->setMainWidget(v); 17551da177e4SLinus Torvalds configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit())); 17561da177e4SLinus Torvalds configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings())); 175743bf612aSRoman Zippel v->show(); 17581da177e4SLinus Torvalds configApp->exec(); 17591da177e4SLinus Torvalds 17607fc925fdSRoman Zippel configSettings->endGroup(); 17617fc925fdSRoman Zippel delete configSettings; 17627fc925fdSRoman Zippel 17631da177e4SLinus Torvalds return 0; 17641da177e4SLinus Torvalds } 1765