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