11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 31da177e4SLinus Torvalds * Released under the terms of the GNU GPL v2.0. 41da177e4SLinus Torvalds */ 51da177e4SLinus Torvalds 6133c5f7cSAlexander Stein #include <qglobal.h> 7133c5f7cSAlexander Stein 8133c5f7cSAlexander Stein #if QT_VERSION < 0x040000 91da177e4SLinus Torvalds #include <qmainwindow.h> 10133c5f7cSAlexander Stein #include <qvbox.h> 11133c5f7cSAlexander Stein #include <qvaluelist.h> 12133c5f7cSAlexander Stein #include <qtextbrowser.h> 13133c5f7cSAlexander Stein #include <qaction.h> 14133c5f7cSAlexander Stein #include <qheader.h> 15133c5f7cSAlexander Stein #include <qfiledialog.h> 16133c5f7cSAlexander Stein #include <qdragobject.h> 17133c5f7cSAlexander Stein #include <qpopupmenu.h> 18133c5f7cSAlexander Stein #else 19133c5f7cSAlexander Stein #include <q3mainwindow.h> 20133c5f7cSAlexander Stein #include <q3vbox.h> 21133c5f7cSAlexander Stein #include <q3valuelist.h> 22133c5f7cSAlexander Stein #include <q3textbrowser.h> 23133c5f7cSAlexander Stein #include <q3action.h> 24133c5f7cSAlexander Stein #include <q3header.h> 25133c5f7cSAlexander Stein #include <q3filedialog.h> 26133c5f7cSAlexander Stein #include <q3dragobject.h> 27133c5f7cSAlexander Stein #include <q3popupmenu.h> 28133c5f7cSAlexander Stein #endif 29133c5f7cSAlexander Stein 30133c5f7cSAlexander Stein #include <qapplication.h> 318d90c97eSMarkus Heidelberg #include <qdesktopwidget.h> 321da177e4SLinus Torvalds #include <qtoolbar.h> 3343bf612aSRoman Zippel #include <qlayout.h> 341da177e4SLinus Torvalds #include <qsplitter.h> 351da177e4SLinus Torvalds #include <qlineedit.h> 3643bf612aSRoman Zippel #include <qlabel.h> 3743bf612aSRoman Zippel #include <qpushbutton.h> 381da177e4SLinus Torvalds #include <qmenubar.h> 391da177e4SLinus Torvalds #include <qmessagebox.h> 401da177e4SLinus Torvalds #include <qregexp.h> 41133c5f7cSAlexander Stein #include <qevent.h> 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds #include <stdlib.h> 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds #include "lkc.h" 461da177e4SLinus Torvalds #include "qconf.h" 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds #include "qconf.moc" 491da177e4SLinus Torvalds #include "images.c" 501da177e4SLinus Torvalds 513b9fa093SArnaldo Carvalho de Melo #ifdef _ 523b9fa093SArnaldo Carvalho de Melo # undef _ 533b9fa093SArnaldo Carvalho de Melo # define _ qgettext 543b9fa093SArnaldo Carvalho de Melo #endif 553b9fa093SArnaldo Carvalho de Melo 561da177e4SLinus Torvalds static QApplication *configApp; 577fc925fdSRoman Zippel static ConfigSettings *configSettings; 581da177e4SLinus Torvalds 59133c5f7cSAlexander Stein Q3Action *ConfigMainWindow::saveAction; 603b354c55SKarsten Wiese 613b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const char* str) 623b9fa093SArnaldo Carvalho de Melo { 633b9fa093SArnaldo Carvalho de Melo return QString::fromLocal8Bit(gettext(str)); 643b9fa093SArnaldo Carvalho de Melo } 653b9fa093SArnaldo Carvalho de Melo 663b9fa093SArnaldo Carvalho de Melo static inline QString qgettext(const QString& str) 673b9fa093SArnaldo Carvalho de Melo { 683b9fa093SArnaldo Carvalho de Melo return QString::fromLocal8Bit(gettext(str.latin1())); 693b9fa093SArnaldo Carvalho de Melo } 703b9fa093SArnaldo Carvalho de Melo 711da177e4SLinus Torvalds /** 721da177e4SLinus Torvalds * Reads a list of integer values from the application settings. 731da177e4SLinus Torvalds */ 74133c5f7cSAlexander Stein Q3ValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok) 751da177e4SLinus Torvalds { 76133c5f7cSAlexander Stein Q3ValueList<int> result; 771da177e4SLinus Torvalds QStringList entryList = readListEntry(key, ok); 781da177e4SLinus Torvalds QStringList::Iterator it; 79c1f96f09SLi Zefan 801da177e4SLinus Torvalds for (it = entryList.begin(); it != entryList.end(); ++it) 811da177e4SLinus Torvalds result.push_back((*it).toInt()); 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds return result; 841da177e4SLinus Torvalds } 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds /** 871da177e4SLinus Torvalds * Writes a list of integer values to the application settings. 881da177e4SLinus Torvalds */ 89133c5f7cSAlexander Stein bool ConfigSettings::writeSizes(const QString& key, const Q3ValueList<int>& value) 901da177e4SLinus Torvalds { 911da177e4SLinus Torvalds QStringList stringList; 92133c5f7cSAlexander Stein Q3ValueList<int>::ConstIterator it; 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds for (it = value.begin(); it != value.end(); ++it) 951da177e4SLinus Torvalds stringList.push_back(QString::number(*it)); 961da177e4SLinus Torvalds return writeEntry(key, stringList); 971da177e4SLinus Torvalds } 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds /* 1011da177e4SLinus Torvalds * set the new data 1021da177e4SLinus Torvalds * TODO check the value 1031da177e4SLinus Torvalds */ 1041da177e4SLinus Torvalds void ConfigItem::okRename(int col) 1051da177e4SLinus Torvalds { 1061da177e4SLinus Torvalds Parent::okRename(col); 1071da177e4SLinus Torvalds sym_set_string_value(menu->sym, text(dataColIdx).latin1()); 10849e5646dSKarsten Wiese listView()->updateList(this); 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* 1121da177e4SLinus Torvalds * update the displayed of a menu entry 1131da177e4SLinus Torvalds */ 1141da177e4SLinus Torvalds void ConfigItem::updateMenu(void) 1151da177e4SLinus Torvalds { 1161da177e4SLinus Torvalds ConfigList* list; 1171da177e4SLinus Torvalds struct symbol* sym; 1181da177e4SLinus Torvalds struct property *prop; 1191da177e4SLinus Torvalds QString prompt; 1201da177e4SLinus Torvalds int type; 1211da177e4SLinus Torvalds tristate expr; 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds list = listView(); 1241da177e4SLinus Torvalds if (goParent) { 1251da177e4SLinus Torvalds setPixmap(promptColIdx, list->menuBackPix); 1261da177e4SLinus Torvalds prompt = ".."; 1271da177e4SLinus Torvalds goto set_prompt; 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds sym = menu->sym; 1311da177e4SLinus Torvalds prop = menu->prompt; 132c21a2d95SEGRY Gabor prompt = _(menu_get_prompt(menu)); 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds if (prop) switch (prop->type) { 1351da177e4SLinus Torvalds case P_MENU: 1361da177e4SLinus Torvalds if (list->mode == singleMode || list->mode == symbolMode) { 1371da177e4SLinus Torvalds /* a menuconfig entry is displayed differently 1381da177e4SLinus Torvalds * depending whether it's at the view root or a child. 1391da177e4SLinus Torvalds */ 1401da177e4SLinus Torvalds if (sym && list->rootEntry == menu) 1411da177e4SLinus Torvalds break; 1421da177e4SLinus Torvalds setPixmap(promptColIdx, list->menuPix); 1431da177e4SLinus Torvalds } else { 1441da177e4SLinus Torvalds if (sym) 1451da177e4SLinus Torvalds break; 1461da177e4SLinus Torvalds setPixmap(promptColIdx, 0); 1471da177e4SLinus Torvalds } 1481da177e4SLinus Torvalds goto set_prompt; 1491da177e4SLinus Torvalds case P_COMMENT: 1501da177e4SLinus Torvalds setPixmap(promptColIdx, 0); 1511da177e4SLinus Torvalds goto set_prompt; 1521da177e4SLinus Torvalds default: 1531da177e4SLinus Torvalds ; 1541da177e4SLinus Torvalds } 1551da177e4SLinus Torvalds if (!sym) 1561da177e4SLinus Torvalds goto set_prompt; 1571da177e4SLinus Torvalds 1583b9fa093SArnaldo Carvalho de Melo setText(nameColIdx, QString::fromLocal8Bit(sym->name)); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds type = sym_get_type(sym); 1611da177e4SLinus Torvalds switch (type) { 1621da177e4SLinus Torvalds case S_BOOLEAN: 1631da177e4SLinus Torvalds case S_TRISTATE: 1641da177e4SLinus Torvalds char ch; 1651da177e4SLinus Torvalds 16639a4897cSLi Zefan if (!sym_is_changable(sym) && list->optMode == normalOpt) { 1671da177e4SLinus Torvalds setPixmap(promptColIdx, 0); 1683b9fa093SArnaldo Carvalho de Melo setText(noColIdx, QString::null); 1693b9fa093SArnaldo Carvalho de Melo setText(modColIdx, QString::null); 1703b9fa093SArnaldo Carvalho de Melo setText(yesColIdx, QString::null); 1711da177e4SLinus Torvalds break; 1721da177e4SLinus Torvalds } 1731da177e4SLinus Torvalds expr = sym_get_tristate_value(sym); 1741da177e4SLinus Torvalds switch (expr) { 1751da177e4SLinus Torvalds case yes: 1761da177e4SLinus Torvalds if (sym_is_choice_value(sym) && type == S_BOOLEAN) 1771da177e4SLinus Torvalds setPixmap(promptColIdx, list->choiceYesPix); 1781da177e4SLinus Torvalds else 1791da177e4SLinus Torvalds setPixmap(promptColIdx, list->symbolYesPix); 1801da177e4SLinus Torvalds setText(yesColIdx, "Y"); 1811da177e4SLinus Torvalds ch = 'Y'; 1821da177e4SLinus Torvalds break; 1831da177e4SLinus Torvalds case mod: 1841da177e4SLinus Torvalds setPixmap(promptColIdx, list->symbolModPix); 1851da177e4SLinus Torvalds setText(modColIdx, "M"); 1861da177e4SLinus Torvalds ch = 'M'; 1871da177e4SLinus Torvalds break; 1881da177e4SLinus Torvalds default: 1891da177e4SLinus Torvalds if (sym_is_choice_value(sym) && type == S_BOOLEAN) 1901da177e4SLinus Torvalds setPixmap(promptColIdx, list->choiceNoPix); 1911da177e4SLinus Torvalds else 1921da177e4SLinus Torvalds setPixmap(promptColIdx, list->symbolNoPix); 1931da177e4SLinus Torvalds setText(noColIdx, "N"); 1941da177e4SLinus Torvalds ch = 'N'; 1951da177e4SLinus Torvalds break; 1961da177e4SLinus Torvalds } 1971da177e4SLinus Torvalds if (expr != no) 1981da177e4SLinus Torvalds setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0); 1991da177e4SLinus Torvalds if (expr != mod) 2001da177e4SLinus Torvalds setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0); 2011da177e4SLinus Torvalds if (expr != yes) 2021da177e4SLinus Torvalds setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0); 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds setText(dataColIdx, QChar(ch)); 2051da177e4SLinus Torvalds break; 2061da177e4SLinus Torvalds case S_INT: 2071da177e4SLinus Torvalds case S_HEX: 2081da177e4SLinus Torvalds case S_STRING: 2091da177e4SLinus Torvalds const char* data; 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds data = sym_get_string_value(sym); 2123b9fa093SArnaldo Carvalho de Melo 2131da177e4SLinus Torvalds int i = list->mapIdx(dataColIdx); 2141da177e4SLinus Torvalds if (i >= 0) 2151da177e4SLinus Torvalds setRenameEnabled(i, TRUE); 2161da177e4SLinus Torvalds setText(dataColIdx, data); 2171da177e4SLinus Torvalds if (type == S_STRING) 2183b9fa093SArnaldo Carvalho de Melo prompt = QString("%1: %2").arg(prompt).arg(data); 2191da177e4SLinus Torvalds else 2203b9fa093SArnaldo Carvalho de Melo prompt = QString("(%2) %1").arg(prompt).arg(data); 2211da177e4SLinus Torvalds break; 2221da177e4SLinus Torvalds } 2231da177e4SLinus Torvalds if (!sym_has_value(sym) && visible) 224c21a2d95SEGRY Gabor prompt += _(" (NEW)"); 2251da177e4SLinus Torvalds set_prompt: 2261da177e4SLinus Torvalds setText(promptColIdx, prompt); 2271da177e4SLinus Torvalds } 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds void ConfigItem::testUpdateMenu(bool v) 2301da177e4SLinus Torvalds { 2311da177e4SLinus Torvalds ConfigItem* i; 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds visible = v; 2341da177e4SLinus Torvalds if (!menu) 2351da177e4SLinus Torvalds return; 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds sym_calc_value(menu->sym); 2381da177e4SLinus Torvalds if (menu->flags & MENU_CHANGED) { 2391da177e4SLinus Torvalds /* the menu entry changed, so update all list items */ 2401da177e4SLinus Torvalds menu->flags &= ~MENU_CHANGED; 2411da177e4SLinus Torvalds for (i = (ConfigItem*)menu->data; i; i = i->nextItem) 2421da177e4SLinus Torvalds i->updateMenu(); 2431da177e4SLinus Torvalds } else if (listView()->updateAll) 2441da177e4SLinus Torvalds updateMenu(); 2451da177e4SLinus Torvalds } 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align) 2481da177e4SLinus Torvalds { 2491da177e4SLinus Torvalds ConfigList* list = listView(); 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds if (visible) { 2521da177e4SLinus Torvalds if (isSelected() && !list->hasFocus() && list->mode == menuMode) 2531da177e4SLinus Torvalds Parent::paintCell(p, list->inactivedColorGroup, column, width, align); 2541da177e4SLinus Torvalds else 2551da177e4SLinus Torvalds Parent::paintCell(p, cg, column, width, align); 2561da177e4SLinus Torvalds } else 2571da177e4SLinus Torvalds Parent::paintCell(p, list->disabledColorGroup, column, width, align); 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds /* 2611da177e4SLinus Torvalds * construct a menu entry 2621da177e4SLinus Torvalds */ 2631da177e4SLinus Torvalds void ConfigItem::init(void) 2641da177e4SLinus Torvalds { 2651da177e4SLinus Torvalds if (menu) { 2661da177e4SLinus Torvalds ConfigList* list = listView(); 2671da177e4SLinus Torvalds nextItem = (ConfigItem*)menu->data; 2681da177e4SLinus Torvalds menu->data = this; 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvalds if (list->mode != fullMode) 2711da177e4SLinus Torvalds setOpen(TRUE); 2721da177e4SLinus Torvalds sym_calc_value(menu->sym); 2731da177e4SLinus Torvalds } 2741da177e4SLinus Torvalds updateMenu(); 2751da177e4SLinus Torvalds } 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds /* 2781da177e4SLinus Torvalds * destruct a menu entry 2791da177e4SLinus Torvalds */ 2801da177e4SLinus Torvalds ConfigItem::~ConfigItem(void) 2811da177e4SLinus Torvalds { 2821da177e4SLinus Torvalds if (menu) { 2831da177e4SLinus Torvalds ConfigItem** ip = (ConfigItem**)&menu->data; 2841da177e4SLinus Torvalds for (; *ip; ip = &(*ip)->nextItem) { 2851da177e4SLinus Torvalds if (*ip == this) { 2861da177e4SLinus Torvalds *ip = nextItem; 2871da177e4SLinus Torvalds break; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds } 2901da177e4SLinus Torvalds } 2911da177e4SLinus Torvalds } 2921da177e4SLinus Torvalds 29343bf612aSRoman Zippel ConfigLineEdit::ConfigLineEdit(ConfigView* parent) 29443bf612aSRoman Zippel : Parent(parent) 29543bf612aSRoman Zippel { 29643bf612aSRoman Zippel connect(this, SIGNAL(lostFocus()), SLOT(hide())); 29743bf612aSRoman Zippel } 29843bf612aSRoman Zippel 2991da177e4SLinus Torvalds void ConfigLineEdit::show(ConfigItem* i) 3001da177e4SLinus Torvalds { 3011da177e4SLinus Torvalds item = i; 3021da177e4SLinus Torvalds if (sym_get_string_value(item->menu->sym)) 3033b9fa093SArnaldo Carvalho de Melo setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym))); 3041da177e4SLinus Torvalds else 3053b9fa093SArnaldo Carvalho de Melo setText(QString::null); 3061da177e4SLinus Torvalds Parent::show(); 3071da177e4SLinus Torvalds setFocus(); 3081da177e4SLinus Torvalds } 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds void ConfigLineEdit::keyPressEvent(QKeyEvent* e) 3111da177e4SLinus Torvalds { 3121da177e4SLinus Torvalds switch (e->key()) { 313fbb86374SMarkus Heidelberg case Qt::Key_Escape: 3141da177e4SLinus Torvalds break; 315fbb86374SMarkus Heidelberg case Qt::Key_Return: 316fbb86374SMarkus Heidelberg case Qt::Key_Enter: 3171da177e4SLinus Torvalds sym_set_string_value(item->menu->sym, text().latin1()); 3181da177e4SLinus Torvalds parent()->updateList(item); 3191da177e4SLinus Torvalds break; 3201da177e4SLinus Torvalds default: 3211da177e4SLinus Torvalds Parent::keyPressEvent(e); 3221da177e4SLinus Torvalds return; 3231da177e4SLinus Torvalds } 3241da177e4SLinus Torvalds e->accept(); 3251da177e4SLinus Torvalds parent()->list->setFocus(); 3261da177e4SLinus Torvalds hide(); 3271da177e4SLinus Torvalds } 3281da177e4SLinus Torvalds 3297fc925fdSRoman Zippel ConfigList::ConfigList(ConfigView* p, const char *name) 3307fc925fdSRoman Zippel : Parent(p, name), 3311da177e4SLinus Torvalds updateAll(false), 3321da177e4SLinus Torvalds symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no), 3331da177e4SLinus Torvalds choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no), 3341da177e4SLinus Torvalds menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void), 33539a4897cSLi Zefan showName(false), showRange(false), showData(false), optMode(normalOpt), 3367fc925fdSRoman Zippel rootEntry(0), headerPopup(0) 3371da177e4SLinus Torvalds { 3381da177e4SLinus Torvalds int i; 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds setSorting(-1); 3411da177e4SLinus Torvalds setRootIsDecorated(TRUE); 3421da177e4SLinus Torvalds disabledColorGroup = palette().active(); 3431da177e4SLinus Torvalds disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text()); 3441da177e4SLinus Torvalds inactivedColorGroup = palette().active(); 3451da177e4SLinus Torvalds inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight()); 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds connect(this, SIGNAL(selectionChanged(void)), 3481da177e4SLinus Torvalds SLOT(updateSelection(void))); 3491da177e4SLinus Torvalds 3507fc925fdSRoman Zippel if (name) { 3517fc925fdSRoman Zippel configSettings->beginGroup(name); 3527fc925fdSRoman Zippel showName = configSettings->readBoolEntry("/showName", false); 3537fc925fdSRoman Zippel showRange = configSettings->readBoolEntry("/showRange", false); 3547fc925fdSRoman Zippel showData = configSettings->readBoolEntry("/showData", false); 35539a4897cSLi Zefan optMode = (enum optionMode)configSettings->readNumEntry("/optionMode", false); 3567fc925fdSRoman Zippel configSettings->endGroup(); 3577fc925fdSRoman Zippel connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); 3581da177e4SLinus Torvalds } 3591da177e4SLinus Torvalds 3601da177e4SLinus Torvalds for (i = 0; i < colNr; i++) 3611da177e4SLinus Torvalds colMap[i] = colRevMap[i] = -1; 362c21a2d95SEGRY Gabor addColumn(promptColIdx, _("Option")); 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds reinit(); 3651da177e4SLinus Torvalds } 3661da177e4SLinus Torvalds 36739a4897cSLi Zefan bool ConfigList::menuSkip(struct menu *menu) 36839a4897cSLi Zefan { 36939a4897cSLi Zefan if (optMode == normalOpt && menu_is_visible(menu)) 37039a4897cSLi Zefan return false; 37139a4897cSLi Zefan if (optMode == promptOpt && menu_has_prompt(menu)) 37239a4897cSLi Zefan return false; 37339a4897cSLi Zefan if (optMode == allOpt) 37439a4897cSLi Zefan return false; 37539a4897cSLi Zefan return true; 37639a4897cSLi Zefan } 37739a4897cSLi Zefan 3781da177e4SLinus Torvalds void ConfigList::reinit(void) 3791da177e4SLinus Torvalds { 3801da177e4SLinus Torvalds removeColumn(dataColIdx); 3811da177e4SLinus Torvalds removeColumn(yesColIdx); 3821da177e4SLinus Torvalds removeColumn(modColIdx); 3831da177e4SLinus Torvalds removeColumn(noColIdx); 3841da177e4SLinus Torvalds removeColumn(nameColIdx); 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds if (showName) 387c21a2d95SEGRY Gabor addColumn(nameColIdx, _("Name")); 3881da177e4SLinus Torvalds if (showRange) { 3891da177e4SLinus Torvalds addColumn(noColIdx, "N"); 3901da177e4SLinus Torvalds addColumn(modColIdx, "M"); 3911da177e4SLinus Torvalds addColumn(yesColIdx, "Y"); 3921da177e4SLinus Torvalds } 3931da177e4SLinus Torvalds if (showData) 394c21a2d95SEGRY Gabor addColumn(dataColIdx, _("Value")); 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds updateListAll(); 3971da177e4SLinus Torvalds } 3981da177e4SLinus Torvalds 3997fc925fdSRoman Zippel void ConfigList::saveSettings(void) 4007fc925fdSRoman Zippel { 4017fc925fdSRoman Zippel if (name()) { 4027fc925fdSRoman Zippel configSettings->beginGroup(name()); 4037fc925fdSRoman Zippel configSettings->writeEntry("/showName", showName); 4047fc925fdSRoman Zippel configSettings->writeEntry("/showRange", showRange); 4057fc925fdSRoman Zippel configSettings->writeEntry("/showData", showData); 40639a4897cSLi Zefan configSettings->writeEntry("/optionMode", (int)optMode); 4077fc925fdSRoman Zippel configSettings->endGroup(); 4087fc925fdSRoman Zippel } 4097fc925fdSRoman Zippel } 4107fc925fdSRoman Zippel 411b65a47e1SRoman Zippel ConfigItem* ConfigList::findConfigItem(struct menu *menu) 412b65a47e1SRoman Zippel { 413b65a47e1SRoman Zippel ConfigItem* item = (ConfigItem*)menu->data; 414b65a47e1SRoman Zippel 415b65a47e1SRoman Zippel for (; item; item = item->nextItem) { 416b65a47e1SRoman Zippel if (this == item->listView()) 417b65a47e1SRoman Zippel break; 418b65a47e1SRoman Zippel } 419b65a47e1SRoman Zippel 420b65a47e1SRoman Zippel return item; 421b65a47e1SRoman Zippel } 422b65a47e1SRoman Zippel 4231da177e4SLinus Torvalds void ConfigList::updateSelection(void) 4241da177e4SLinus Torvalds { 4251da177e4SLinus Torvalds struct menu *menu; 4261da177e4SLinus Torvalds enum prop_type type; 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds ConfigItem* item = (ConfigItem*)selectedItem(); 4291da177e4SLinus Torvalds if (!item) 4301da177e4SLinus Torvalds return; 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds menu = item->menu; 43343bf612aSRoman Zippel emit menuChanged(menu); 4341da177e4SLinus Torvalds if (!menu) 4351da177e4SLinus Torvalds return; 4361da177e4SLinus Torvalds type = menu->prompt ? menu->prompt->type : P_UNKNOWN; 4371da177e4SLinus Torvalds if (mode == menuMode && type == P_MENU) 4381da177e4SLinus Torvalds emit menuSelected(menu); 4391da177e4SLinus Torvalds } 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds void ConfigList::updateList(ConfigItem* item) 4421da177e4SLinus Torvalds { 4431da177e4SLinus Torvalds ConfigItem* last = 0; 4441da177e4SLinus Torvalds 44543bf612aSRoman Zippel if (!rootEntry) { 44643bf612aSRoman Zippel if (mode != listMode) 4471da177e4SLinus Torvalds goto update; 448133c5f7cSAlexander Stein Q3ListViewItemIterator it(this); 44943bf612aSRoman Zippel ConfigItem* item; 45043bf612aSRoman Zippel 45143bf612aSRoman Zippel for (; it.current(); ++it) { 45243bf612aSRoman Zippel item = (ConfigItem*)it.current(); 45343bf612aSRoman Zippel if (!item->menu) 45443bf612aSRoman Zippel continue; 45543bf612aSRoman Zippel item->testUpdateMenu(menu_is_visible(item->menu)); 45643bf612aSRoman Zippel } 45743bf612aSRoman Zippel return; 45843bf612aSRoman Zippel } 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds if (rootEntry != &rootmenu && (mode == singleMode || 4611da177e4SLinus Torvalds (mode == symbolMode && rootEntry->parent != &rootmenu))) { 4621da177e4SLinus Torvalds item = firstChild(); 4631da177e4SLinus Torvalds if (!item) 4641da177e4SLinus Torvalds item = new ConfigItem(this, 0, true); 4651da177e4SLinus Torvalds last = item; 4661da177e4SLinus Torvalds } 4671da177e4SLinus Torvalds if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) && 4681da177e4SLinus Torvalds rootEntry->sym && rootEntry->prompt) { 4691da177e4SLinus Torvalds item = last ? last->nextSibling() : firstChild(); 4701da177e4SLinus Torvalds if (!item) 4711da177e4SLinus Torvalds item = new ConfigItem(this, last, rootEntry, true); 4721da177e4SLinus Torvalds else 4731da177e4SLinus Torvalds item->testUpdateMenu(true); 4741da177e4SLinus Torvalds 4751da177e4SLinus Torvalds updateMenuList(item, rootEntry); 4761da177e4SLinus Torvalds triggerUpdate(); 4771da177e4SLinus Torvalds return; 4781da177e4SLinus Torvalds } 4791da177e4SLinus Torvalds update: 4801da177e4SLinus Torvalds updateMenuList(this, rootEntry); 4811da177e4SLinus Torvalds triggerUpdate(); 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds void ConfigList::setValue(ConfigItem* item, tristate val) 4851da177e4SLinus Torvalds { 4861da177e4SLinus Torvalds struct symbol* sym; 4871da177e4SLinus Torvalds int type; 4881da177e4SLinus Torvalds tristate oldval; 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds sym = item->menu ? item->menu->sym : 0; 4911da177e4SLinus Torvalds if (!sym) 4921da177e4SLinus Torvalds return; 4931da177e4SLinus Torvalds 4941da177e4SLinus Torvalds type = sym_get_type(sym); 4951da177e4SLinus Torvalds switch (type) { 4961da177e4SLinus Torvalds case S_BOOLEAN: 4971da177e4SLinus Torvalds case S_TRISTATE: 4981da177e4SLinus Torvalds oldval = sym_get_tristate_value(sym); 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds if (!sym_set_tristate_value(sym, val)) 5011da177e4SLinus Torvalds return; 5021da177e4SLinus Torvalds if (oldval == no && item->menu->list) 5031da177e4SLinus Torvalds item->setOpen(TRUE); 5041da177e4SLinus Torvalds parent()->updateList(item); 5051da177e4SLinus Torvalds break; 5061da177e4SLinus Torvalds } 5071da177e4SLinus Torvalds } 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds void ConfigList::changeValue(ConfigItem* item) 5101da177e4SLinus Torvalds { 5111da177e4SLinus Torvalds struct symbol* sym; 5121da177e4SLinus Torvalds struct menu* menu; 5131da177e4SLinus Torvalds int type, oldexpr, newexpr; 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds menu = item->menu; 5161da177e4SLinus Torvalds if (!menu) 5171da177e4SLinus Torvalds return; 5181da177e4SLinus Torvalds sym = menu->sym; 5191da177e4SLinus Torvalds if (!sym) { 5201da177e4SLinus Torvalds if (item->menu->list) 5211da177e4SLinus Torvalds item->setOpen(!item->isOpen()); 5221da177e4SLinus Torvalds return; 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds type = sym_get_type(sym); 5261da177e4SLinus Torvalds switch (type) { 5271da177e4SLinus Torvalds case S_BOOLEAN: 5281da177e4SLinus Torvalds case S_TRISTATE: 5291da177e4SLinus Torvalds oldexpr = sym_get_tristate_value(sym); 5301da177e4SLinus Torvalds newexpr = sym_toggle_tristate_value(sym); 5311da177e4SLinus Torvalds if (item->menu->list) { 5321da177e4SLinus Torvalds if (oldexpr == newexpr) 5331da177e4SLinus Torvalds item->setOpen(!item->isOpen()); 5341da177e4SLinus Torvalds else if (oldexpr == no) 5351da177e4SLinus Torvalds item->setOpen(TRUE); 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds if (oldexpr != newexpr) 5381da177e4SLinus Torvalds parent()->updateList(item); 5391da177e4SLinus Torvalds break; 5401da177e4SLinus Torvalds case S_INT: 5411da177e4SLinus Torvalds case S_HEX: 5421da177e4SLinus Torvalds case S_STRING: 5431da177e4SLinus Torvalds if (colMap[dataColIdx] >= 0) 5441da177e4SLinus Torvalds item->startRename(colMap[dataColIdx]); 5451da177e4SLinus Torvalds else 5461da177e4SLinus Torvalds parent()->lineEdit->show(item); 5471da177e4SLinus Torvalds break; 5481da177e4SLinus Torvalds } 5491da177e4SLinus Torvalds } 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds void ConfigList::setRootMenu(struct menu *menu) 5521da177e4SLinus Torvalds { 5531da177e4SLinus Torvalds enum prop_type type; 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds if (rootEntry == menu) 5561da177e4SLinus Torvalds return; 5571da177e4SLinus Torvalds type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN; 5581da177e4SLinus Torvalds if (type != P_MENU) 5591da177e4SLinus Torvalds return; 5601da177e4SLinus Torvalds updateMenuList(this, 0); 5611da177e4SLinus Torvalds rootEntry = menu; 5621da177e4SLinus Torvalds updateListAll(); 5631da177e4SLinus Torvalds setSelected(currentItem(), hasFocus()); 564b65a47e1SRoman Zippel ensureItemVisible(currentItem()); 5651da177e4SLinus Torvalds } 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds void ConfigList::setParentMenu(void) 5681da177e4SLinus Torvalds { 5691da177e4SLinus Torvalds ConfigItem* item; 5701da177e4SLinus Torvalds struct menu *oldroot; 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds oldroot = rootEntry; 5731da177e4SLinus Torvalds if (rootEntry == &rootmenu) 5741da177e4SLinus Torvalds return; 5751da177e4SLinus Torvalds setRootMenu(menu_get_parent_menu(rootEntry->parent)); 5761da177e4SLinus Torvalds 577133c5f7cSAlexander Stein Q3ListViewItemIterator it(this); 5781da177e4SLinus Torvalds for (; (item = (ConfigItem*)it.current()); it++) { 5791da177e4SLinus Torvalds if (item->menu == oldroot) { 5801da177e4SLinus Torvalds setCurrentItem(item); 5811da177e4SLinus Torvalds ensureItemVisible(item); 5821da177e4SLinus Torvalds break; 5831da177e4SLinus Torvalds } 5841da177e4SLinus Torvalds } 5851da177e4SLinus Torvalds } 5861da177e4SLinus Torvalds 5877fc925fdSRoman Zippel /* 5887fc925fdSRoman Zippel * update all the children of a menu entry 5897fc925fdSRoman Zippel * removes/adds the entries from the parent widget as necessary 5907fc925fdSRoman Zippel * 5917fc925fdSRoman Zippel * parent: either the menu list widget or a menu entry widget 5927fc925fdSRoman Zippel * menu: entry to be updated 5937fc925fdSRoman Zippel */ 5947fc925fdSRoman Zippel template <class P> 5957fc925fdSRoman Zippel void ConfigList::updateMenuList(P* parent, struct menu* menu) 5967fc925fdSRoman Zippel { 5977fc925fdSRoman Zippel struct menu* child; 5987fc925fdSRoman Zippel ConfigItem* item; 5997fc925fdSRoman Zippel ConfigItem* last; 6007fc925fdSRoman Zippel bool visible; 6017fc925fdSRoman Zippel enum prop_type type; 6027fc925fdSRoman Zippel 6037fc925fdSRoman Zippel if (!menu) { 6047fc925fdSRoman Zippel while ((item = parent->firstChild())) 6057fc925fdSRoman Zippel delete item; 6067fc925fdSRoman Zippel return; 6077fc925fdSRoman Zippel } 6087fc925fdSRoman Zippel 6097fc925fdSRoman Zippel last = parent->firstChild(); 6107fc925fdSRoman Zippel if (last && !last->goParent) 6117fc925fdSRoman Zippel last = 0; 6127fc925fdSRoman Zippel for (child = menu->list; child; child = child->next) { 6137fc925fdSRoman Zippel item = last ? last->nextSibling() : parent->firstChild(); 6147fc925fdSRoman Zippel type = child->prompt ? child->prompt->type : P_UNKNOWN; 6157fc925fdSRoman Zippel 6167fc925fdSRoman Zippel switch (mode) { 6177fc925fdSRoman Zippel case menuMode: 6187fc925fdSRoman Zippel if (!(child->flags & MENU_ROOT)) 6197fc925fdSRoman Zippel goto hide; 6207fc925fdSRoman Zippel break; 6217fc925fdSRoman Zippel case symbolMode: 6227fc925fdSRoman Zippel if (child->flags & MENU_ROOT) 6237fc925fdSRoman Zippel goto hide; 6247fc925fdSRoman Zippel break; 6257fc925fdSRoman Zippel default: 6267fc925fdSRoman Zippel break; 6277fc925fdSRoman Zippel } 6287fc925fdSRoman Zippel 6297fc925fdSRoman Zippel visible = menu_is_visible(child); 63039a4897cSLi Zefan if (!menuSkip(child)) { 631ed8b4d4dSCyrill V. Gorcunov if (!child->sym && !child->list && !child->prompt) 632ed8b4d4dSCyrill V. Gorcunov continue; 6337fc925fdSRoman Zippel if (!item || item->menu != child) 6347fc925fdSRoman Zippel item = new ConfigItem(parent, last, child, visible); 6357fc925fdSRoman Zippel else 6367fc925fdSRoman Zippel item->testUpdateMenu(visible); 6377fc925fdSRoman Zippel 6387fc925fdSRoman Zippel if (mode == fullMode || mode == menuMode || type != P_MENU) 6397fc925fdSRoman Zippel updateMenuList(item, child); 6407fc925fdSRoman Zippel else 6417fc925fdSRoman Zippel updateMenuList(item, 0); 6427fc925fdSRoman Zippel last = item; 6437fc925fdSRoman Zippel continue; 6447fc925fdSRoman Zippel } 6457fc925fdSRoman Zippel hide: 6467fc925fdSRoman Zippel if (item && item->menu == child) { 6477fc925fdSRoman Zippel last = parent->firstChild(); 6487fc925fdSRoman Zippel if (last == item) 6497fc925fdSRoman Zippel last = 0; 6507fc925fdSRoman Zippel else while (last->nextSibling() != item) 6517fc925fdSRoman Zippel last = last->nextSibling(); 6527fc925fdSRoman Zippel delete item; 6537fc925fdSRoman Zippel } 6547fc925fdSRoman Zippel } 6557fc925fdSRoman Zippel } 6567fc925fdSRoman Zippel 6571da177e4SLinus Torvalds void ConfigList::keyPressEvent(QKeyEvent* ev) 6581da177e4SLinus Torvalds { 659133c5f7cSAlexander Stein Q3ListViewItem* i = currentItem(); 6601da177e4SLinus Torvalds ConfigItem* item; 6611da177e4SLinus Torvalds struct menu *menu; 6621da177e4SLinus Torvalds enum prop_type type; 6631da177e4SLinus Torvalds 664fbb86374SMarkus Heidelberg if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) { 6651da177e4SLinus Torvalds emit parentSelected(); 6661da177e4SLinus Torvalds ev->accept(); 6671da177e4SLinus Torvalds return; 6681da177e4SLinus Torvalds } 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds if (!i) { 6711da177e4SLinus Torvalds Parent::keyPressEvent(ev); 6721da177e4SLinus Torvalds return; 6731da177e4SLinus Torvalds } 6741da177e4SLinus Torvalds item = (ConfigItem*)i; 6751da177e4SLinus Torvalds 6761da177e4SLinus Torvalds switch (ev->key()) { 677fbb86374SMarkus Heidelberg case Qt::Key_Return: 678fbb86374SMarkus Heidelberg case Qt::Key_Enter: 6791da177e4SLinus Torvalds if (item->goParent) { 6801da177e4SLinus Torvalds emit parentSelected(); 6811da177e4SLinus Torvalds break; 6821da177e4SLinus Torvalds } 6831da177e4SLinus Torvalds menu = item->menu; 6841da177e4SLinus Torvalds if (!menu) 6851da177e4SLinus Torvalds break; 6861da177e4SLinus Torvalds type = menu->prompt ? menu->prompt->type : P_UNKNOWN; 6871da177e4SLinus Torvalds if (type == P_MENU && rootEntry != menu && 6881da177e4SLinus Torvalds mode != fullMode && mode != menuMode) { 6891da177e4SLinus Torvalds emit menuSelected(menu); 6901da177e4SLinus Torvalds break; 6911da177e4SLinus Torvalds } 692fbb86374SMarkus Heidelberg case Qt::Key_Space: 6931da177e4SLinus Torvalds changeValue(item); 6941da177e4SLinus Torvalds break; 695fbb86374SMarkus Heidelberg case Qt::Key_N: 6961da177e4SLinus Torvalds setValue(item, no); 6971da177e4SLinus Torvalds break; 698fbb86374SMarkus Heidelberg case Qt::Key_M: 6991da177e4SLinus Torvalds setValue(item, mod); 7001da177e4SLinus Torvalds break; 701fbb86374SMarkus Heidelberg case Qt::Key_Y: 7021da177e4SLinus Torvalds setValue(item, yes); 7031da177e4SLinus Torvalds break; 7041da177e4SLinus Torvalds default: 7051da177e4SLinus Torvalds Parent::keyPressEvent(ev); 7061da177e4SLinus Torvalds return; 7071da177e4SLinus Torvalds } 7081da177e4SLinus Torvalds ev->accept(); 7091da177e4SLinus Torvalds } 7101da177e4SLinus Torvalds 7111da177e4SLinus Torvalds void ConfigList::contentsMousePressEvent(QMouseEvent* e) 7121da177e4SLinus Torvalds { 7131da177e4SLinus Torvalds //QPoint p(contentsToViewport(e->pos())); 7141da177e4SLinus Torvalds //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y()); 7151da177e4SLinus Torvalds Parent::contentsMousePressEvent(e); 7161da177e4SLinus Torvalds } 7171da177e4SLinus Torvalds 7181da177e4SLinus Torvalds void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e) 7191da177e4SLinus Torvalds { 7201da177e4SLinus Torvalds QPoint p(contentsToViewport(e->pos())); 7211da177e4SLinus Torvalds ConfigItem* item = (ConfigItem*)itemAt(p); 7221da177e4SLinus Torvalds struct menu *menu; 7231da177e4SLinus Torvalds enum prop_type ptype; 7241da177e4SLinus Torvalds const QPixmap* pm; 7251da177e4SLinus Torvalds int idx, x; 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds if (!item) 7281da177e4SLinus Torvalds goto skip; 7291da177e4SLinus Torvalds 7301da177e4SLinus Torvalds menu = item->menu; 7311da177e4SLinus Torvalds x = header()->offset() + p.x(); 7321da177e4SLinus Torvalds idx = colRevMap[header()->sectionAt(x)]; 7331da177e4SLinus Torvalds switch (idx) { 7341da177e4SLinus Torvalds case promptColIdx: 7351da177e4SLinus Torvalds pm = item->pixmap(promptColIdx); 7361da177e4SLinus Torvalds if (pm) { 7371da177e4SLinus Torvalds int off = header()->sectionPos(0) + itemMargin() + 7381da177e4SLinus Torvalds treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0)); 7391da177e4SLinus Torvalds if (x >= off && x < off + pm->width()) { 7401da177e4SLinus Torvalds if (item->goParent) { 7411da177e4SLinus Torvalds emit parentSelected(); 7421da177e4SLinus Torvalds break; 7431da177e4SLinus Torvalds } else if (!menu) 7441da177e4SLinus Torvalds break; 7451da177e4SLinus Torvalds ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; 7461da177e4SLinus Torvalds if (ptype == P_MENU && rootEntry != menu && 7471da177e4SLinus Torvalds mode != fullMode && mode != menuMode) 7481da177e4SLinus Torvalds emit menuSelected(menu); 7491da177e4SLinus Torvalds else 7501da177e4SLinus Torvalds changeValue(item); 7511da177e4SLinus Torvalds } 7521da177e4SLinus Torvalds } 7531da177e4SLinus Torvalds break; 7541da177e4SLinus Torvalds case noColIdx: 7551da177e4SLinus Torvalds setValue(item, no); 7561da177e4SLinus Torvalds break; 7571da177e4SLinus Torvalds case modColIdx: 7581da177e4SLinus Torvalds setValue(item, mod); 7591da177e4SLinus Torvalds break; 7601da177e4SLinus Torvalds case yesColIdx: 7611da177e4SLinus Torvalds setValue(item, yes); 7621da177e4SLinus Torvalds break; 7631da177e4SLinus Torvalds case dataColIdx: 7641da177e4SLinus Torvalds changeValue(item); 7651da177e4SLinus Torvalds break; 7661da177e4SLinus Torvalds } 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds skip: 7691da177e4SLinus Torvalds //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y()); 7701da177e4SLinus Torvalds Parent::contentsMouseReleaseEvent(e); 7711da177e4SLinus Torvalds } 7721da177e4SLinus Torvalds 7731da177e4SLinus Torvalds void ConfigList::contentsMouseMoveEvent(QMouseEvent* e) 7741da177e4SLinus Torvalds { 7751da177e4SLinus Torvalds //QPoint p(contentsToViewport(e->pos())); 7761da177e4SLinus Torvalds //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y()); 7771da177e4SLinus Torvalds Parent::contentsMouseMoveEvent(e); 7781da177e4SLinus Torvalds } 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e) 7811da177e4SLinus Torvalds { 7821da177e4SLinus Torvalds QPoint p(contentsToViewport(e->pos())); 7831da177e4SLinus Torvalds ConfigItem* item = (ConfigItem*)itemAt(p); 7841da177e4SLinus Torvalds struct menu *menu; 7851da177e4SLinus Torvalds enum prop_type ptype; 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds if (!item) 7881da177e4SLinus Torvalds goto skip; 7891da177e4SLinus Torvalds if (item->goParent) { 7901da177e4SLinus Torvalds emit parentSelected(); 7911da177e4SLinus Torvalds goto skip; 7921da177e4SLinus Torvalds } 7931da177e4SLinus Torvalds menu = item->menu; 7941da177e4SLinus Torvalds if (!menu) 7951da177e4SLinus Torvalds goto skip; 7961da177e4SLinus Torvalds ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; 7971da177e4SLinus Torvalds if (ptype == P_MENU && (mode == singleMode || mode == symbolMode)) 7981da177e4SLinus Torvalds emit menuSelected(menu); 7991da177e4SLinus Torvalds else if (menu->sym) 8001da177e4SLinus Torvalds changeValue(item); 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds skip: 8031da177e4SLinus Torvalds //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y()); 8041da177e4SLinus Torvalds Parent::contentsMouseDoubleClickEvent(e); 8051da177e4SLinus Torvalds } 8061da177e4SLinus Torvalds 8071da177e4SLinus Torvalds void ConfigList::focusInEvent(QFocusEvent *e) 8081da177e4SLinus Torvalds { 809b65a47e1SRoman Zippel struct menu *menu = NULL; 810b65a47e1SRoman Zippel 8111da177e4SLinus Torvalds Parent::focusInEvent(e); 8121da177e4SLinus Torvalds 813b65a47e1SRoman Zippel ConfigItem* item = (ConfigItem *)currentItem(); 814b65a47e1SRoman Zippel if (item) { 8151da177e4SLinus Torvalds setSelected(item, TRUE); 816b65a47e1SRoman Zippel menu = item->menu; 817b65a47e1SRoman Zippel } 818b65a47e1SRoman Zippel emit gotFocus(menu); 8191da177e4SLinus Torvalds } 8201da177e4SLinus Torvalds 8217fc925fdSRoman Zippel void ConfigList::contextMenuEvent(QContextMenuEvent *e) 8227fc925fdSRoman Zippel { 8237fc925fdSRoman Zippel if (e->y() <= header()->geometry().bottom()) { 8247fc925fdSRoman Zippel if (!headerPopup) { 825133c5f7cSAlexander Stein Q3Action *action; 8267fc925fdSRoman Zippel 827133c5f7cSAlexander Stein headerPopup = new Q3PopupMenu(this); 828133c5f7cSAlexander Stein action = new Q3Action(NULL, _("Show Name"), 0, this); 8297fc925fdSRoman Zippel action->setToggleAction(TRUE); 8307fc925fdSRoman Zippel connect(action, SIGNAL(toggled(bool)), 8317fc925fdSRoman Zippel parent(), SLOT(setShowName(bool))); 8327fc925fdSRoman Zippel connect(parent(), SIGNAL(showNameChanged(bool)), 8337fc925fdSRoman Zippel action, SLOT(setOn(bool))); 8347fc925fdSRoman Zippel action->setOn(showName); 8357fc925fdSRoman Zippel action->addTo(headerPopup); 836133c5f7cSAlexander Stein action = new Q3Action(NULL, _("Show Range"), 0, this); 8377fc925fdSRoman Zippel action->setToggleAction(TRUE); 8387fc925fdSRoman Zippel connect(action, SIGNAL(toggled(bool)), 8397fc925fdSRoman Zippel parent(), SLOT(setShowRange(bool))); 8407fc925fdSRoman Zippel connect(parent(), SIGNAL(showRangeChanged(bool)), 8417fc925fdSRoman Zippel action, SLOT(setOn(bool))); 8427fc925fdSRoman Zippel action->setOn(showRange); 8437fc925fdSRoman Zippel action->addTo(headerPopup); 844133c5f7cSAlexander Stein action = new Q3Action(NULL, _("Show Data"), 0, this); 8457fc925fdSRoman Zippel action->setToggleAction(TRUE); 8467fc925fdSRoman Zippel connect(action, SIGNAL(toggled(bool)), 8477fc925fdSRoman Zippel parent(), SLOT(setShowData(bool))); 8487fc925fdSRoman Zippel connect(parent(), SIGNAL(showDataChanged(bool)), 8497fc925fdSRoman Zippel action, SLOT(setOn(bool))); 8507fc925fdSRoman Zippel action->setOn(showData); 8517fc925fdSRoman Zippel action->addTo(headerPopup); 8527fc925fdSRoman Zippel } 8537fc925fdSRoman Zippel headerPopup->exec(e->globalPos()); 8547fc925fdSRoman Zippel e->accept(); 8557fc925fdSRoman Zippel } else 8567fc925fdSRoman Zippel e->ignore(); 8577fc925fdSRoman Zippel } 8587fc925fdSRoman Zippel 8591da177e4SLinus Torvalds ConfigView*ConfigView::viewList; 86039a4897cSLi Zefan QAction *ConfigView::showNormalAction; 86139a4897cSLi Zefan QAction *ConfigView::showAllAction; 86239a4897cSLi Zefan QAction *ConfigView::showPromptAction; 8631da177e4SLinus Torvalds 8647fc925fdSRoman Zippel ConfigView::ConfigView(QWidget* parent, const char *name) 8657fc925fdSRoman Zippel : Parent(parent, name) 8661da177e4SLinus Torvalds { 8677fc925fdSRoman Zippel list = new ConfigList(this, name); 8681da177e4SLinus Torvalds lineEdit = new ConfigLineEdit(this); 8691da177e4SLinus Torvalds lineEdit->hide(); 8701da177e4SLinus Torvalds 8711da177e4SLinus Torvalds this->nextView = viewList; 8721da177e4SLinus Torvalds viewList = this; 8731da177e4SLinus Torvalds } 8741da177e4SLinus Torvalds 8751da177e4SLinus Torvalds ConfigView::~ConfigView(void) 8761da177e4SLinus Torvalds { 8771da177e4SLinus Torvalds ConfigView** vp; 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds for (vp = &viewList; *vp; vp = &(*vp)->nextView) { 8801da177e4SLinus Torvalds if (*vp == this) { 8811da177e4SLinus Torvalds *vp = nextView; 8821da177e4SLinus Torvalds break; 8831da177e4SLinus Torvalds } 8841da177e4SLinus Torvalds } 8851da177e4SLinus Torvalds } 8861da177e4SLinus Torvalds 88739a4897cSLi Zefan void ConfigView::setOptionMode(QAction *act) 8887fc925fdSRoman Zippel { 88939a4897cSLi Zefan if (act == showNormalAction) 89039a4897cSLi Zefan list->optMode = normalOpt; 89139a4897cSLi Zefan else if (act == showAllAction) 89239a4897cSLi Zefan list->optMode = allOpt; 89339a4897cSLi Zefan else 89439a4897cSLi Zefan list->optMode = promptOpt; 89539a4897cSLi Zefan 8967fc925fdSRoman Zippel list->updateListAll(); 8977fc925fdSRoman Zippel } 8987fc925fdSRoman Zippel 8997fc925fdSRoman Zippel void ConfigView::setShowName(bool b) 9007fc925fdSRoman Zippel { 9017fc925fdSRoman Zippel if (list->showName != b) { 9027fc925fdSRoman Zippel list->showName = b; 9037fc925fdSRoman Zippel list->reinit(); 9047fc925fdSRoman Zippel emit showNameChanged(b); 9057fc925fdSRoman Zippel } 9067fc925fdSRoman Zippel } 9077fc925fdSRoman Zippel 9087fc925fdSRoman Zippel void ConfigView::setShowRange(bool b) 9097fc925fdSRoman Zippel { 9107fc925fdSRoman Zippel if (list->showRange != b) { 9117fc925fdSRoman Zippel list->showRange = b; 9127fc925fdSRoman Zippel list->reinit(); 9137fc925fdSRoman Zippel emit showRangeChanged(b); 9147fc925fdSRoman Zippel } 9157fc925fdSRoman Zippel } 9167fc925fdSRoman Zippel 9177fc925fdSRoman Zippel void ConfigView::setShowData(bool b) 9187fc925fdSRoman Zippel { 9197fc925fdSRoman Zippel if (list->showData != b) { 9207fc925fdSRoman Zippel list->showData = b; 9217fc925fdSRoman Zippel list->reinit(); 9227fc925fdSRoman Zippel emit showDataChanged(b); 9237fc925fdSRoman Zippel } 9247fc925fdSRoman Zippel } 9257fc925fdSRoman Zippel 9267fc925fdSRoman Zippel void ConfigList::setAllOpen(bool open) 9277fc925fdSRoman Zippel { 928133c5f7cSAlexander Stein Q3ListViewItemIterator it(this); 9297fc925fdSRoman Zippel 9307fc925fdSRoman Zippel for (; it.current(); it++) 9317fc925fdSRoman Zippel it.current()->setOpen(open); 9327fc925fdSRoman Zippel } 9337fc925fdSRoman Zippel 9341da177e4SLinus Torvalds void ConfigView::updateList(ConfigItem* item) 9351da177e4SLinus Torvalds { 9361da177e4SLinus Torvalds ConfigView* v; 9371da177e4SLinus Torvalds 9381da177e4SLinus Torvalds for (v = viewList; v; v = v->nextView) 9391da177e4SLinus Torvalds v->list->updateList(item); 9401da177e4SLinus Torvalds } 9411da177e4SLinus Torvalds 9421da177e4SLinus Torvalds void ConfigView::updateListAll(void) 9431da177e4SLinus Torvalds { 9441da177e4SLinus Torvalds ConfigView* v; 9451da177e4SLinus Torvalds 9461da177e4SLinus Torvalds for (v = viewList; v; v = v->nextView) 9471da177e4SLinus Torvalds v->list->updateListAll(); 9481da177e4SLinus Torvalds } 9491da177e4SLinus Torvalds 95043bf612aSRoman Zippel ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name) 951133c5f7cSAlexander Stein : Parent(parent, name), sym(0), _menu(0) 9521da177e4SLinus Torvalds { 9537fc925fdSRoman Zippel if (name) { 9547fc925fdSRoman Zippel configSettings->beginGroup(name); 9557fc925fdSRoman Zippel _showDebug = configSettings->readBoolEntry("/showDebug", false); 9567fc925fdSRoman Zippel configSettings->endGroup(); 9577fc925fdSRoman Zippel connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); 9587fc925fdSRoman Zippel } 9597fc925fdSRoman Zippel } 9607fc925fdSRoman Zippel 9617fc925fdSRoman Zippel void ConfigInfoView::saveSettings(void) 9627fc925fdSRoman Zippel { 9637fc925fdSRoman Zippel if (name()) { 9647fc925fdSRoman Zippel configSettings->beginGroup(name()); 9657fc925fdSRoman Zippel configSettings->writeEntry("/showDebug", showDebug()); 9667fc925fdSRoman Zippel configSettings->endGroup(); 9677fc925fdSRoman Zippel } 9681da177e4SLinus Torvalds } 9691da177e4SLinus Torvalds 97043bf612aSRoman Zippel void ConfigInfoView::setShowDebug(bool b) 9711da177e4SLinus Torvalds { 97243bf612aSRoman Zippel if (_showDebug != b) { 97343bf612aSRoman Zippel _showDebug = b; 974133c5f7cSAlexander Stein if (_menu) 97543bf612aSRoman Zippel menuInfo(); 976ab45d190SRoman Zippel else if (sym) 977ab45d190SRoman Zippel symbolInfo(); 97843bf612aSRoman Zippel emit showDebugChanged(b); 9791da177e4SLinus Torvalds } 9801da177e4SLinus Torvalds } 9811da177e4SLinus Torvalds 98243bf612aSRoman Zippel void ConfigInfoView::setInfo(struct menu *m) 9831da177e4SLinus Torvalds { 984133c5f7cSAlexander Stein if (_menu == m) 985b65a47e1SRoman Zippel return; 986133c5f7cSAlexander Stein _menu = m; 9876fa1da8eSRoman Zippel sym = NULL; 988133c5f7cSAlexander Stein if (!_menu) 98943bf612aSRoman Zippel clear(); 9906fa1da8eSRoman Zippel else 99143bf612aSRoman Zippel menuInfo(); 9921da177e4SLinus Torvalds } 9931da177e4SLinus Torvalds 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 1015133c5f7cSAlexander Stein sym = _menu->sym; 10161da177e4SLinus Torvalds if (sym) { 1017133c5f7cSAlexander Stein if (_menu->prompt) { 10181da177e4SLinus Torvalds head += "<big><b>"; 1019133c5f7cSAlexander Stein 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 1044d74c15f3SCheng Renquan struct gstr help_gstr = str_new(); 1045133c5f7cSAlexander Stein menu_get_ext_help(_menu, &help_gstr); 1046d74c15f3SCheng Renquan help = print_filter(str_get(&help_gstr)); 1047d74c15f3SCheng Renquan str_free(&help_gstr); 1048133c5f7cSAlexander Stein } else if (_menu->prompt) { 104943bf612aSRoman Zippel head += "<big><b>"; 1050133c5f7cSAlexander Stein head += print_filter(_(_menu->prompt->text)); 105143bf612aSRoman Zippel head += "</b></big><br><br>"; 105243bf612aSRoman Zippel if (showDebug()) { 1053133c5f7cSAlexander Stein if (_menu->prompt->visible.expr) { 105443bf612aSRoman Zippel debug += " dep: "; 1055133c5f7cSAlexander Stein expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE); 105643bf612aSRoman Zippel debug += "<br><br>"; 105743bf612aSRoman Zippel } 105843bf612aSRoman Zippel } 105943bf612aSRoman Zippel } 106043bf612aSRoman Zippel if (showDebug()) 1061133c5f7cSAlexander Stein debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno); 106243bf612aSRoman Zippel 106343bf612aSRoman Zippel setText(head + debug + help); 106443bf612aSRoman Zippel } 106543bf612aSRoman Zippel 106643bf612aSRoman Zippel QString ConfigInfoView::debug_info(struct symbol *sym) 106743bf612aSRoman Zippel { 106843bf612aSRoman Zippel QString debug; 106943bf612aSRoman Zippel 10701da177e4SLinus Torvalds debug += "type: "; 10711da177e4SLinus Torvalds debug += print_filter(sym_type_name(sym->type)); 10721da177e4SLinus Torvalds if (sym_is_choice(sym)) 10731da177e4SLinus Torvalds debug += " (choice)"; 10741da177e4SLinus Torvalds debug += "<br>"; 10751da177e4SLinus Torvalds if (sym->rev_dep.expr) { 10761da177e4SLinus Torvalds debug += "reverse dep: "; 10771da177e4SLinus Torvalds expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE); 10781da177e4SLinus Torvalds debug += "<br>"; 10791da177e4SLinus Torvalds } 10801da177e4SLinus Torvalds for (struct property *prop = sym->prop; prop; prop = prop->next) { 10811da177e4SLinus Torvalds switch (prop->type) { 10821da177e4SLinus Torvalds case P_PROMPT: 10831da177e4SLinus Torvalds case P_MENU: 1084ab45d190SRoman Zippel debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu); 10853b9fa093SArnaldo Carvalho de Melo debug += print_filter(_(prop->text)); 1086ab45d190SRoman Zippel debug += "</a><br>"; 10871da177e4SLinus Torvalds break; 10881da177e4SLinus Torvalds case P_DEFAULT: 108993449082SRoman Zippel case P_SELECT: 109093449082SRoman Zippel case P_RANGE: 109193449082SRoman Zippel case P_ENV: 109293449082SRoman Zippel debug += prop_get_type_name(prop->type); 109393449082SRoman Zippel debug += ": "; 10941da177e4SLinus Torvalds expr_print(prop->expr, expr_print_help, &debug, E_NONE); 10951da177e4SLinus Torvalds debug += "<br>"; 10961da177e4SLinus Torvalds break; 10971da177e4SLinus Torvalds case P_CHOICE: 10981da177e4SLinus Torvalds if (sym_is_choice(sym)) { 10991da177e4SLinus Torvalds debug += "choice: "; 11001da177e4SLinus Torvalds expr_print(prop->expr, expr_print_help, &debug, E_NONE); 11011da177e4SLinus Torvalds debug += "<br>"; 11021da177e4SLinus Torvalds } 11031da177e4SLinus Torvalds break; 11041da177e4SLinus Torvalds default: 11051da177e4SLinus Torvalds debug += "unknown property: "; 11061da177e4SLinus Torvalds debug += prop_get_type_name(prop->type); 11071da177e4SLinus Torvalds debug += "<br>"; 11081da177e4SLinus Torvalds } 11091da177e4SLinus Torvalds if (prop->visible.expr) { 11101da177e4SLinus Torvalds debug += " dep: "; 11111da177e4SLinus Torvalds expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE); 11121da177e4SLinus Torvalds debug += "<br>"; 11131da177e4SLinus Torvalds } 11141da177e4SLinus Torvalds } 11151da177e4SLinus Torvalds debug += "<br>"; 111643bf612aSRoman Zippel 111743bf612aSRoman Zippel return debug; 11181da177e4SLinus Torvalds } 11191da177e4SLinus Torvalds 112043bf612aSRoman Zippel QString ConfigInfoView::print_filter(const QString &str) 112143bf612aSRoman Zippel { 112243bf612aSRoman Zippel QRegExp re("[<>&\"\\n]"); 112343bf612aSRoman Zippel QString res = str; 112443bf612aSRoman Zippel for (int i = 0; (i = res.find(re, i)) >= 0;) { 112543bf612aSRoman Zippel switch (res[i].latin1()) { 112643bf612aSRoman Zippel case '<': 112743bf612aSRoman Zippel res.replace(i, 1, "<"); 112843bf612aSRoman Zippel i += 4; 112943bf612aSRoman Zippel break; 113043bf612aSRoman Zippel case '>': 113143bf612aSRoman Zippel res.replace(i, 1, ">"); 113243bf612aSRoman Zippel i += 4; 113343bf612aSRoman Zippel break; 113443bf612aSRoman Zippel case '&': 113543bf612aSRoman Zippel res.replace(i, 1, "&"); 113643bf612aSRoman Zippel i += 5; 113743bf612aSRoman Zippel break; 113843bf612aSRoman Zippel case '"': 113943bf612aSRoman Zippel res.replace(i, 1, """); 114043bf612aSRoman Zippel i += 6; 114143bf612aSRoman Zippel break; 114243bf612aSRoman Zippel case '\n': 114343bf612aSRoman Zippel res.replace(i, 1, "<br>"); 114443bf612aSRoman Zippel i += 4; 114543bf612aSRoman Zippel break; 11461da177e4SLinus Torvalds } 11471da177e4SLinus Torvalds } 114843bf612aSRoman Zippel return res; 11491da177e4SLinus Torvalds } 115043bf612aSRoman Zippel 1151ab45d190SRoman Zippel void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str) 115243bf612aSRoman Zippel { 1153ab45d190SRoman Zippel QString* text = reinterpret_cast<QString*>(data); 1154ab45d190SRoman Zippel QString str2 = print_filter(str); 1155ab45d190SRoman Zippel 1156ab45d190SRoman Zippel if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) { 1157ab45d190SRoman Zippel *text += QString().sprintf("<a href=\"s%p\">", sym); 1158ab45d190SRoman Zippel *text += str2; 1159ab45d190SRoman Zippel *text += "</a>"; 1160ab45d190SRoman Zippel } else 1161ab45d190SRoman Zippel *text += str2; 116243bf612aSRoman Zippel } 116343bf612aSRoman Zippel 1164133c5f7cSAlexander Stein Q3PopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos) 11657fc925fdSRoman Zippel { 1166133c5f7cSAlexander Stein Q3PopupMenu* popup = Parent::createPopupMenu(pos); 1167133c5f7cSAlexander Stein Q3Action* action = new Q3Action(NULL, _("Show Debug Info"), 0, popup); 11687fc925fdSRoman Zippel action->setToggleAction(TRUE); 11697fc925fdSRoman Zippel connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool))); 11707fc925fdSRoman Zippel connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool))); 11717fc925fdSRoman Zippel action->setOn(showDebug()); 11727fc925fdSRoman Zippel popup->insertSeparator(); 11737fc925fdSRoman Zippel action->addTo(popup); 11747fc925fdSRoman Zippel return popup; 11757fc925fdSRoman Zippel } 11767fc925fdSRoman Zippel 11777fc925fdSRoman Zippel void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e) 11787fc925fdSRoman Zippel { 11797fc925fdSRoman Zippel Parent::contentsContextMenuEvent(e); 11807fc925fdSRoman Zippel } 11817fc925fdSRoman Zippel 118263431e75SMarco Costalba ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name) 11837fc925fdSRoman Zippel : Parent(parent, name), result(NULL) 118443bf612aSRoman Zippel { 118543bf612aSRoman Zippel setCaption("Search Config"); 118643bf612aSRoman Zippel 118743bf612aSRoman Zippel QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6); 118843bf612aSRoman Zippel QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6); 1189c21a2d95SEGRY Gabor layout2->addWidget(new QLabel(_("Find:"), this)); 119043bf612aSRoman Zippel editField = new QLineEdit(this); 119143bf612aSRoman Zippel connect(editField, SIGNAL(returnPressed()), SLOT(search())); 119243bf612aSRoman Zippel layout2->addWidget(editField); 1193c21a2d95SEGRY Gabor searchButton = new QPushButton(_("Search"), this); 119443bf612aSRoman Zippel searchButton->setAutoDefault(FALSE); 119543bf612aSRoman Zippel connect(searchButton, SIGNAL(clicked()), SLOT(search())); 119643bf612aSRoman Zippel layout2->addWidget(searchButton); 119743bf612aSRoman Zippel layout1->addLayout(layout2); 119843bf612aSRoman Zippel 11997fc925fdSRoman Zippel split = new QSplitter(this); 12007298b936SMarkus Heidelberg split->setOrientation(Qt::Vertical); 12017fc925fdSRoman Zippel list = new ConfigView(split, name); 120243bf612aSRoman Zippel list->list->mode = listMode; 12037fc925fdSRoman Zippel info = new ConfigInfoView(split, name); 120443bf612aSRoman Zippel connect(list->list, SIGNAL(menuChanged(struct menu *)), 120543bf612aSRoman Zippel info, SLOT(setInfo(struct menu *))); 120663431e75SMarco Costalba connect(list->list, SIGNAL(menuChanged(struct menu *)), 120763431e75SMarco Costalba parent, SLOT(setMenuLink(struct menu *))); 120863431e75SMarco Costalba 120943bf612aSRoman Zippel layout1->addWidget(split); 12107fc925fdSRoman Zippel 12117fc925fdSRoman Zippel if (name) { 12127fc925fdSRoman Zippel int x, y, width, height; 12137fc925fdSRoman Zippel bool ok; 12147fc925fdSRoman Zippel 12157fc925fdSRoman Zippel configSettings->beginGroup(name); 12167fc925fdSRoman Zippel width = configSettings->readNumEntry("/window width", parent->width() / 2); 12177fc925fdSRoman Zippel height = configSettings->readNumEntry("/window height", parent->height() / 2); 12187fc925fdSRoman Zippel resize(width, height); 12197fc925fdSRoman Zippel x = configSettings->readNumEntry("/window x", 0, &ok); 12207fc925fdSRoman Zippel if (ok) 12217fc925fdSRoman Zippel y = configSettings->readNumEntry("/window y", 0, &ok); 12227fc925fdSRoman Zippel if (ok) 12237fc925fdSRoman Zippel move(x, y); 1224133c5f7cSAlexander Stein Q3ValueList<int> sizes = configSettings->readSizes("/split", &ok); 12257fc925fdSRoman Zippel if (ok) 12267fc925fdSRoman Zippel split->setSizes(sizes); 12277fc925fdSRoman Zippel configSettings->endGroup(); 12287fc925fdSRoman Zippel connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); 12297fc925fdSRoman Zippel } 12307fc925fdSRoman Zippel } 12317fc925fdSRoman Zippel 12327fc925fdSRoman Zippel void ConfigSearchWindow::saveSettings(void) 12337fc925fdSRoman Zippel { 12347fc925fdSRoman Zippel if (name()) { 12357fc925fdSRoman Zippel configSettings->beginGroup(name()); 12367fc925fdSRoman Zippel configSettings->writeEntry("/window x", pos().x()); 12377fc925fdSRoman Zippel configSettings->writeEntry("/window y", pos().y()); 12387fc925fdSRoman Zippel configSettings->writeEntry("/window width", size().width()); 12397fc925fdSRoman Zippel configSettings->writeEntry("/window height", size().height()); 12407fc925fdSRoman Zippel configSettings->writeSizes("/split", split->sizes()); 12417fc925fdSRoman Zippel configSettings->endGroup(); 12427fc925fdSRoman Zippel } 124343bf612aSRoman Zippel } 124443bf612aSRoman Zippel 124543bf612aSRoman Zippel void ConfigSearchWindow::search(void) 124643bf612aSRoman Zippel { 124743bf612aSRoman Zippel struct symbol **p; 124843bf612aSRoman Zippel struct property *prop; 124943bf612aSRoman Zippel ConfigItem *lastItem = NULL; 125043bf612aSRoman Zippel 125143bf612aSRoman Zippel free(result); 125243bf612aSRoman Zippel list->list->clear(); 1253786fb18dSCyrill V. Gorcunov info->clear(); 125443bf612aSRoman Zippel 125543bf612aSRoman Zippel result = sym_re_search(editField->text().latin1()); 125643bf612aSRoman Zippel if (!result) 125743bf612aSRoman Zippel return; 125843bf612aSRoman Zippel for (p = result; *p; p++) { 125943bf612aSRoman Zippel for_all_prompts((*p), prop) 126043bf612aSRoman Zippel lastItem = new ConfigItem(list->list, lastItem, prop->menu, 126143bf612aSRoman Zippel menu_is_visible(prop->menu)); 126243bf612aSRoman Zippel } 126343bf612aSRoman Zippel } 126443bf612aSRoman Zippel 126543bf612aSRoman Zippel /* 126643bf612aSRoman Zippel * Construct the complete config widget 126743bf612aSRoman Zippel */ 126843bf612aSRoman Zippel ConfigMainWindow::ConfigMainWindow(void) 1269f12aa704SRoman Zippel : searchWindow(0) 127043bf612aSRoman Zippel { 127143bf612aSRoman Zippel QMenuBar* menu; 12727fc925fdSRoman Zippel bool ok; 127343bf612aSRoman Zippel int x, y, width, height; 1274a54bb701SRandy Dunlap char title[256]; 127543bf612aSRoman Zippel 12768d90c97eSMarkus Heidelberg QDesktopWidget *d = configApp->desktop(); 127776a136c4SMichal Marek snprintf(title, sizeof(title), _("Linux Kernel v%s Configuration%s"), 127876a136c4SMichal Marek getenv("KERNELVERSION"), 127976a136c4SMichal Marek #if QT_VERSION < 0x040000 128076a136c4SMichal Marek " (Qt3)" 128176a136c4SMichal Marek #else 128276a136c4SMichal Marek "" 128376a136c4SMichal Marek #endif 128476a136c4SMichal Marek ); 1285a54bb701SRandy Dunlap setCaption(title); 128643bf612aSRoman Zippel 12877fc925fdSRoman Zippel width = configSettings->readNumEntry("/window width", d->width() - 64); 12887fc925fdSRoman Zippel height = configSettings->readNumEntry("/window height", d->height() - 64); 128943bf612aSRoman Zippel resize(width, height); 12907fc925fdSRoman Zippel x = configSettings->readNumEntry("/window x", 0, &ok); 129143bf612aSRoman Zippel if (ok) 12927fc925fdSRoman Zippel y = configSettings->readNumEntry("/window y", 0, &ok); 129343bf612aSRoman Zippel if (ok) 129443bf612aSRoman Zippel move(x, y); 129543bf612aSRoman Zippel 129643bf612aSRoman Zippel split1 = new QSplitter(this); 12977298b936SMarkus Heidelberg split1->setOrientation(Qt::Horizontal); 129843bf612aSRoman Zippel setCentralWidget(split1); 129943bf612aSRoman Zippel 13007fc925fdSRoman Zippel menuView = new ConfigView(split1, "menu"); 130143bf612aSRoman Zippel menuList = menuView->list; 130243bf612aSRoman Zippel 130343bf612aSRoman Zippel split2 = new QSplitter(split1); 13047298b936SMarkus Heidelberg split2->setOrientation(Qt::Vertical); 130543bf612aSRoman Zippel 130643bf612aSRoman Zippel // create config tree 13077fc925fdSRoman Zippel configView = new ConfigView(split2, "config"); 130843bf612aSRoman Zippel configList = configView->list; 130943bf612aSRoman Zippel 13107fc925fdSRoman Zippel helpText = new ConfigInfoView(split2, "help"); 131143bf612aSRoman Zippel helpText->setTextFormat(Qt::RichText); 131243bf612aSRoman Zippel 131343bf612aSRoman Zippel setTabOrder(configList, helpText); 131443bf612aSRoman Zippel configList->setFocus(); 131543bf612aSRoman Zippel 131643bf612aSRoman Zippel menu = menuBar(); 1317133c5f7cSAlexander Stein toolBar = new Q3ToolBar("Tools", this); 131843bf612aSRoman Zippel 1319133c5f7cSAlexander Stein backAction = new Q3Action("Back", QPixmap(xpm_back), _("Back"), 0, this); 132043bf612aSRoman Zippel connect(backAction, SIGNAL(activated()), SLOT(goBack())); 132143bf612aSRoman Zippel backAction->setEnabled(FALSE); 1322133c5f7cSAlexander Stein Q3Action *quitAction = new Q3Action("Quit", _("&Quit"), Qt::CTRL + Qt::Key_Q, this); 132343bf612aSRoman Zippel connect(quitAction, SIGNAL(activated()), SLOT(close())); 1324133c5f7cSAlexander Stein Q3Action *loadAction = new Q3Action("Load", QPixmap(xpm_load), _("&Load"), Qt::CTRL + Qt::Key_L, this); 132543bf612aSRoman Zippel connect(loadAction, SIGNAL(activated()), SLOT(loadConfig())); 1326133c5f7cSAlexander Stein saveAction = new Q3Action("Save", QPixmap(xpm_save), _("&Save"), Qt::CTRL + Qt::Key_S, this); 132743bf612aSRoman Zippel connect(saveAction, SIGNAL(activated()), SLOT(saveConfig())); 13283b354c55SKarsten Wiese conf_set_changed_callback(conf_changed); 13293b354c55SKarsten Wiese // Set saveAction's initial state 13303b354c55SKarsten Wiese conf_changed(); 1331133c5f7cSAlexander Stein Q3Action *saveAsAction = new Q3Action("Save As...", _("Save &As..."), 0, this); 133243bf612aSRoman Zippel connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs())); 1333133c5f7cSAlexander Stein Q3Action *searchAction = new Q3Action("Find", _("&Find"), Qt::CTRL + Qt::Key_F, this); 133443bf612aSRoman Zippel connect(searchAction, SIGNAL(activated()), SLOT(searchConfig())); 1335133c5f7cSAlexander Stein Q3Action *singleViewAction = new Q3Action("Single View", QPixmap(xpm_single_view), _("Single View"), 0, this); 133643bf612aSRoman Zippel connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView())); 1337133c5f7cSAlexander Stein Q3Action *splitViewAction = new Q3Action("Split View", QPixmap(xpm_split_view), _("Split View"), 0, this); 133843bf612aSRoman Zippel connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView())); 1339133c5f7cSAlexander Stein Q3Action *fullViewAction = new Q3Action("Full View", QPixmap(xpm_tree_view), _("Full View"), 0, this); 134043bf612aSRoman Zippel connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView())); 134143bf612aSRoman Zippel 1342133c5f7cSAlexander Stein Q3Action *showNameAction = new Q3Action(NULL, _("Show Name"), 0, this); 134343bf612aSRoman Zippel showNameAction->setToggleAction(TRUE); 13447fc925fdSRoman Zippel connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool))); 13457fc925fdSRoman Zippel connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool))); 13467fc925fdSRoman Zippel showNameAction->setOn(configView->showName()); 1347133c5f7cSAlexander Stein Q3Action *showRangeAction = new Q3Action(NULL, _("Show Range"), 0, this); 134843bf612aSRoman Zippel showRangeAction->setToggleAction(TRUE); 13497fc925fdSRoman Zippel connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool))); 13507fc925fdSRoman Zippel connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool))); 135143bf612aSRoman Zippel showRangeAction->setOn(configList->showRange); 1352133c5f7cSAlexander Stein Q3Action *showDataAction = new Q3Action(NULL, _("Show Data"), 0, this); 135343bf612aSRoman Zippel showDataAction->setToggleAction(TRUE); 13547fc925fdSRoman Zippel connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool))); 13557fc925fdSRoman Zippel connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool))); 135643bf612aSRoman Zippel showDataAction->setOn(configList->showData); 135739a4897cSLi Zefan 135839a4897cSLi Zefan QActionGroup *optGroup = new QActionGroup(this); 135939a4897cSLi Zefan optGroup->setExclusive(TRUE); 136039a4897cSLi Zefan connect(optGroup, SIGNAL(selected(QAction *)), configView, 136139a4897cSLi Zefan SLOT(setOptionMode(QAction *))); 136239a4897cSLi Zefan connect(optGroup, SIGNAL(selected(QAction *)), menuView, 136339a4897cSLi Zefan SLOT(setOptionMode(QAction *))); 136439a4897cSLi Zefan 1365133c5f7cSAlexander Stein #if QT_VERSION >= 0x040000 1366133c5f7cSAlexander Stein configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup); 1367133c5f7cSAlexander Stein configView->showAllAction = new QAction(_("Show All Options"), optGroup); 1368133c5f7cSAlexander Stein configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup); 1369133c5f7cSAlexander Stein #else 1370133c5f7cSAlexander Stein configView->showNormalAction = new QAction(_("Show Normal Options"), 0, optGroup); 1371133c5f7cSAlexander Stein configView->showAllAction = new QAction(_("Show All Options"), 0, optGroup); 1372133c5f7cSAlexander Stein configView->showPromptAction = new QAction(_("Show Prompt Options"), 0, optGroup); 1373133c5f7cSAlexander Stein #endif 137439a4897cSLi Zefan configView->showNormalAction->setToggleAction(TRUE); 137539a4897cSLi Zefan configView->showNormalAction->setOn(configList->optMode == normalOpt); 137639a4897cSLi Zefan configView->showAllAction->setToggleAction(TRUE); 137739a4897cSLi Zefan configView->showAllAction->setOn(configList->optMode == allOpt); 137839a4897cSLi Zefan configView->showPromptAction->setToggleAction(TRUE); 137939a4897cSLi Zefan configView->showPromptAction->setOn(configList->optMode == promptOpt); 138039a4897cSLi Zefan 1381133c5f7cSAlexander Stein Q3Action *showDebugAction = new Q3Action(NULL, _("Show Debug Info"), 0, this); 138243bf612aSRoman Zippel showDebugAction->setToggleAction(TRUE); 138343bf612aSRoman Zippel connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool))); 138443bf612aSRoman Zippel connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool))); 13857fc925fdSRoman Zippel showDebugAction->setOn(helpText->showDebug()); 138643bf612aSRoman Zippel 1387133c5f7cSAlexander Stein Q3Action *showIntroAction = new Q3Action(NULL, _("Introduction"), 0, this); 138843bf612aSRoman Zippel connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro())); 1389133c5f7cSAlexander Stein Q3Action *showAboutAction = new Q3Action(NULL, _("About"), 0, this); 139043bf612aSRoman Zippel connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout())); 139143bf612aSRoman Zippel 139243bf612aSRoman Zippel // init tool bar 139343bf612aSRoman Zippel backAction->addTo(toolBar); 139443bf612aSRoman Zippel toolBar->addSeparator(); 139543bf612aSRoman Zippel loadAction->addTo(toolBar); 139643bf612aSRoman Zippel saveAction->addTo(toolBar); 139743bf612aSRoman Zippel toolBar->addSeparator(); 139843bf612aSRoman Zippel singleViewAction->addTo(toolBar); 139943bf612aSRoman Zippel splitViewAction->addTo(toolBar); 140043bf612aSRoman Zippel fullViewAction->addTo(toolBar); 140143bf612aSRoman Zippel 140243bf612aSRoman Zippel // create config menu 1403133c5f7cSAlexander Stein Q3PopupMenu* config = new Q3PopupMenu(this); 1404c21a2d95SEGRY Gabor menu->insertItem(_("&File"), config); 140543bf612aSRoman Zippel loadAction->addTo(config); 140643bf612aSRoman Zippel saveAction->addTo(config); 140743bf612aSRoman Zippel saveAsAction->addTo(config); 140843bf612aSRoman Zippel config->insertSeparator(); 140943bf612aSRoman Zippel quitAction->addTo(config); 141043bf612aSRoman Zippel 141166e7c723SShlomi Fish // create edit menu 1412133c5f7cSAlexander Stein Q3PopupMenu* editMenu = new Q3PopupMenu(this); 1413c21a2d95SEGRY Gabor menu->insertItem(_("&Edit"), editMenu); 141466e7c723SShlomi Fish searchAction->addTo(editMenu); 141566e7c723SShlomi Fish 141643bf612aSRoman Zippel // create options menu 1417133c5f7cSAlexander Stein Q3PopupMenu* optionMenu = new Q3PopupMenu(this); 1418c21a2d95SEGRY Gabor menu->insertItem(_("&Option"), optionMenu); 141943bf612aSRoman Zippel showNameAction->addTo(optionMenu); 142043bf612aSRoman Zippel showRangeAction->addTo(optionMenu); 142143bf612aSRoman Zippel showDataAction->addTo(optionMenu); 142243bf612aSRoman Zippel optionMenu->insertSeparator(); 142339a4897cSLi Zefan optGroup->addTo(optionMenu); 142439a4897cSLi Zefan optionMenu->insertSeparator(); 142543bf612aSRoman Zippel 142643bf612aSRoman Zippel // create help menu 1427133c5f7cSAlexander Stein Q3PopupMenu* helpMenu = new Q3PopupMenu(this); 142843bf612aSRoman Zippel menu->insertSeparator(); 1429c21a2d95SEGRY Gabor menu->insertItem(_("&Help"), helpMenu); 143043bf612aSRoman Zippel showIntroAction->addTo(helpMenu); 143143bf612aSRoman Zippel showAboutAction->addTo(helpMenu); 143243bf612aSRoman Zippel 143343bf612aSRoman Zippel connect(configList, SIGNAL(menuChanged(struct menu *)), 143443bf612aSRoman Zippel helpText, SLOT(setInfo(struct menu *))); 143543bf612aSRoman Zippel connect(configList, SIGNAL(menuSelected(struct menu *)), 143643bf612aSRoman Zippel SLOT(changeMenu(struct menu *))); 143743bf612aSRoman Zippel connect(configList, SIGNAL(parentSelected()), 143843bf612aSRoman Zippel SLOT(goBack())); 143943bf612aSRoman Zippel connect(menuList, SIGNAL(menuChanged(struct menu *)), 144043bf612aSRoman Zippel helpText, SLOT(setInfo(struct menu *))); 144143bf612aSRoman Zippel connect(menuList, SIGNAL(menuSelected(struct menu *)), 144243bf612aSRoman Zippel SLOT(changeMenu(struct menu *))); 144343bf612aSRoman Zippel 1444b65a47e1SRoman Zippel connect(configList, SIGNAL(gotFocus(struct menu *)), 1445b65a47e1SRoman Zippel helpText, SLOT(setInfo(struct menu *))); 1446b65a47e1SRoman Zippel connect(menuList, SIGNAL(gotFocus(struct menu *)), 1447b65a47e1SRoman Zippel helpText, SLOT(setInfo(struct menu *))); 1448b65a47e1SRoman Zippel connect(menuList, SIGNAL(gotFocus(struct menu *)), 144943bf612aSRoman Zippel SLOT(listFocusChanged(void))); 1450b65a47e1SRoman Zippel connect(helpText, SIGNAL(menuSelected(struct menu *)), 1451b65a47e1SRoman Zippel SLOT(setMenuLink(struct menu *))); 145243bf612aSRoman Zippel 14537fc925fdSRoman Zippel QString listMode = configSettings->readEntry("/listMode", "symbol"); 145443bf612aSRoman Zippel if (listMode == "single") 145543bf612aSRoman Zippel showSingleView(); 145643bf612aSRoman Zippel else if (listMode == "full") 145743bf612aSRoman Zippel showFullView(); 145843bf612aSRoman Zippel else /*if (listMode == "split")*/ 145943bf612aSRoman Zippel showSplitView(); 146043bf612aSRoman Zippel 146143bf612aSRoman Zippel // UI setup done, restore splitter positions 1462133c5f7cSAlexander Stein Q3ValueList<int> sizes = configSettings->readSizes("/split1", &ok); 146343bf612aSRoman Zippel if (ok) 146443bf612aSRoman Zippel split1->setSizes(sizes); 146543bf612aSRoman Zippel 14667fc925fdSRoman Zippel sizes = configSettings->readSizes("/split2", &ok); 146743bf612aSRoman Zippel if (ok) 146843bf612aSRoman Zippel split2->setSizes(sizes); 146943bf612aSRoman Zippel } 147043bf612aSRoman Zippel 14711da177e4SLinus Torvalds void ConfigMainWindow::loadConfig(void) 14721da177e4SLinus Torvalds { 1473133c5f7cSAlexander Stein QString s = Q3FileDialog::getOpenFileName(conf_get_configname(), NULL, this); 14741da177e4SLinus Torvalds if (s.isNull()) 14751da177e4SLinus Torvalds return; 14763b9fa093SArnaldo Carvalho de Melo if (conf_read(QFile::encodeName(s))) 1477c21a2d95SEGRY Gabor QMessageBox::information(this, "qconf", _("Unable to load configuration!")); 14781da177e4SLinus Torvalds ConfigView::updateListAll(); 14791da177e4SLinus Torvalds } 14801da177e4SLinus Torvalds 14811da177e4SLinus Torvalds void ConfigMainWindow::saveConfig(void) 14821da177e4SLinus Torvalds { 14831da177e4SLinus Torvalds if (conf_write(NULL)) 1484c21a2d95SEGRY Gabor QMessageBox::information(this, "qconf", _("Unable to save configuration!")); 14851da177e4SLinus Torvalds } 14861da177e4SLinus Torvalds 14871da177e4SLinus Torvalds void ConfigMainWindow::saveConfigAs(void) 14881da177e4SLinus Torvalds { 1489133c5f7cSAlexander Stein QString s = Q3FileDialog::getSaveFileName(conf_get_configname(), NULL, this); 14901da177e4SLinus Torvalds if (s.isNull()) 14911da177e4SLinus Torvalds return; 14923b9fa093SArnaldo Carvalho de Melo if (conf_write(QFile::encodeName(s))) 1493c21a2d95SEGRY Gabor QMessageBox::information(this, "qconf", _("Unable to save configuration!")); 14941da177e4SLinus Torvalds } 14951da177e4SLinus Torvalds 149643bf612aSRoman Zippel void ConfigMainWindow::searchConfig(void) 149743bf612aSRoman Zippel { 149843bf612aSRoman Zippel if (!searchWindow) 14997fc925fdSRoman Zippel searchWindow = new ConfigSearchWindow(this, "search"); 150043bf612aSRoman Zippel searchWindow->show(); 150143bf612aSRoman Zippel } 150243bf612aSRoman Zippel 15031da177e4SLinus Torvalds void ConfigMainWindow::changeMenu(struct menu *menu) 15041da177e4SLinus Torvalds { 15051da177e4SLinus Torvalds configList->setRootMenu(menu); 1506f253f000SCyrill V. Gorcunov if (configList->rootEntry->parent == &rootmenu) 1507f253f000SCyrill V. Gorcunov backAction->setEnabled(FALSE); 1508f253f000SCyrill V. Gorcunov else 15091da177e4SLinus Torvalds backAction->setEnabled(TRUE); 15101da177e4SLinus Torvalds } 15111da177e4SLinus Torvalds 1512b65a47e1SRoman Zippel void ConfigMainWindow::setMenuLink(struct menu *menu) 1513b65a47e1SRoman Zippel { 1514b65a47e1SRoman Zippel struct menu *parent; 1515b65a47e1SRoman Zippel ConfigList* list = NULL; 1516b65a47e1SRoman Zippel ConfigItem* item; 1517b65a47e1SRoman Zippel 151839a4897cSLi Zefan if (configList->menuSkip(menu)) 1519b65a47e1SRoman Zippel return; 1520b65a47e1SRoman Zippel 1521b65a47e1SRoman Zippel switch (configList->mode) { 1522b65a47e1SRoman Zippel case singleMode: 1523b65a47e1SRoman Zippel list = configList; 1524b65a47e1SRoman Zippel parent = menu_get_parent_menu(menu); 1525b65a47e1SRoman Zippel if (!parent) 1526b65a47e1SRoman Zippel return; 1527b65a47e1SRoman Zippel list->setRootMenu(parent); 1528b65a47e1SRoman Zippel break; 1529b65a47e1SRoman Zippel case symbolMode: 1530b65a47e1SRoman Zippel if (menu->flags & MENU_ROOT) { 1531b65a47e1SRoman Zippel configList->setRootMenu(menu); 1532b65a47e1SRoman Zippel configList->clearSelection(); 1533b65a47e1SRoman Zippel list = menuList; 1534b65a47e1SRoman Zippel } else { 1535b65a47e1SRoman Zippel list = configList; 1536b65a47e1SRoman Zippel parent = menu_get_parent_menu(menu->parent); 1537b65a47e1SRoman Zippel if (!parent) 1538b65a47e1SRoman Zippel return; 1539b65a47e1SRoman Zippel item = menuList->findConfigItem(parent); 1540b65a47e1SRoman Zippel if (item) { 1541b65a47e1SRoman Zippel menuList->setSelected(item, TRUE); 1542b65a47e1SRoman Zippel menuList->ensureItemVisible(item); 1543b65a47e1SRoman Zippel } 1544b65a47e1SRoman Zippel list->setRootMenu(parent); 1545b65a47e1SRoman Zippel } 1546b65a47e1SRoman Zippel break; 1547b65a47e1SRoman Zippel case fullMode: 1548b65a47e1SRoman Zippel list = configList; 1549b65a47e1SRoman Zippel break; 155098403a91SMarkus Heidelberg default: 155198403a91SMarkus Heidelberg break; 1552b65a47e1SRoman Zippel } 1553b65a47e1SRoman Zippel 1554b65a47e1SRoman Zippel if (list) { 1555b65a47e1SRoman Zippel item = list->findConfigItem(menu); 1556b65a47e1SRoman Zippel if (item) { 1557b65a47e1SRoman Zippel list->setSelected(item, TRUE); 1558b65a47e1SRoman Zippel list->ensureItemVisible(item); 1559b65a47e1SRoman Zippel list->setFocus(); 1560b65a47e1SRoman Zippel } 1561b65a47e1SRoman Zippel } 1562b65a47e1SRoman Zippel } 1563b65a47e1SRoman Zippel 15641da177e4SLinus Torvalds void ConfigMainWindow::listFocusChanged(void) 15651da177e4SLinus Torvalds { 15661da177e4SLinus Torvalds if (menuList->mode == menuMode) 15671da177e4SLinus Torvalds configList->clearSelection(); 15681da177e4SLinus Torvalds } 15691da177e4SLinus Torvalds 15701da177e4SLinus Torvalds void ConfigMainWindow::goBack(void) 15711da177e4SLinus Torvalds { 15721da177e4SLinus Torvalds ConfigItem* item; 15731da177e4SLinus Torvalds 15741da177e4SLinus Torvalds configList->setParentMenu(); 15751da177e4SLinus Torvalds if (configList->rootEntry == &rootmenu) 15761da177e4SLinus Torvalds backAction->setEnabled(FALSE); 15771da177e4SLinus Torvalds item = (ConfigItem*)menuList->selectedItem(); 15781da177e4SLinus Torvalds while (item) { 15791da177e4SLinus Torvalds if (item->menu == configList->rootEntry) { 15801da177e4SLinus Torvalds menuList->setSelected(item, TRUE); 15811da177e4SLinus Torvalds break; 15821da177e4SLinus Torvalds } 15831da177e4SLinus Torvalds item = (ConfigItem*)item->parent(); 15841da177e4SLinus Torvalds } 15851da177e4SLinus Torvalds } 15861da177e4SLinus Torvalds 15871da177e4SLinus Torvalds void ConfigMainWindow::showSingleView(void) 15881da177e4SLinus Torvalds { 15891da177e4SLinus Torvalds menuView->hide(); 15901da177e4SLinus Torvalds menuList->setRootMenu(0); 15911da177e4SLinus Torvalds configList->mode = singleMode; 15921da177e4SLinus Torvalds if (configList->rootEntry == &rootmenu) 15931da177e4SLinus Torvalds configList->updateListAll(); 15941da177e4SLinus Torvalds else 15951da177e4SLinus Torvalds configList->setRootMenu(&rootmenu); 15961da177e4SLinus Torvalds configList->setAllOpen(TRUE); 15971da177e4SLinus Torvalds configList->setFocus(); 15981da177e4SLinus Torvalds } 15991da177e4SLinus Torvalds 16001da177e4SLinus Torvalds void ConfigMainWindow::showSplitView(void) 16011da177e4SLinus Torvalds { 16021da177e4SLinus Torvalds configList->mode = symbolMode; 16031da177e4SLinus Torvalds if (configList->rootEntry == &rootmenu) 16041da177e4SLinus Torvalds configList->updateListAll(); 16051da177e4SLinus Torvalds else 16061da177e4SLinus Torvalds configList->setRootMenu(&rootmenu); 16071da177e4SLinus Torvalds configList->setAllOpen(TRUE); 16081da177e4SLinus Torvalds configApp->processEvents(); 16091da177e4SLinus Torvalds menuList->mode = menuMode; 16101da177e4SLinus Torvalds menuList->setRootMenu(&rootmenu); 16111da177e4SLinus Torvalds menuList->setAllOpen(TRUE); 16121da177e4SLinus Torvalds menuView->show(); 16131da177e4SLinus Torvalds menuList->setFocus(); 16141da177e4SLinus Torvalds } 16151da177e4SLinus Torvalds 16161da177e4SLinus Torvalds void ConfigMainWindow::showFullView(void) 16171da177e4SLinus Torvalds { 16181da177e4SLinus Torvalds menuView->hide(); 16191da177e4SLinus Torvalds menuList->setRootMenu(0); 16201da177e4SLinus Torvalds configList->mode = fullMode; 16211da177e4SLinus Torvalds if (configList->rootEntry == &rootmenu) 16221da177e4SLinus Torvalds configList->updateListAll(); 16231da177e4SLinus Torvalds else 16241da177e4SLinus Torvalds configList->setRootMenu(&rootmenu); 16251da177e4SLinus Torvalds configList->setAllOpen(FALSE); 16261da177e4SLinus Torvalds configList->setFocus(); 16271da177e4SLinus Torvalds } 16281da177e4SLinus Torvalds 16291da177e4SLinus Torvalds /* 16301da177e4SLinus Torvalds * ask for saving configuration before quitting 16311da177e4SLinus Torvalds * TODO ask only when something changed 16321da177e4SLinus Torvalds */ 16331da177e4SLinus Torvalds void ConfigMainWindow::closeEvent(QCloseEvent* e) 16341da177e4SLinus Torvalds { 1635b3214293SKarsten Wiese if (!conf_get_changed()) { 16361da177e4SLinus Torvalds e->accept(); 16371da177e4SLinus Torvalds return; 16381da177e4SLinus Torvalds } 1639c21a2d95SEGRY Gabor QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning, 16401da177e4SLinus Torvalds QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); 1641c21a2d95SEGRY Gabor mb.setButtonText(QMessageBox::Yes, _("&Save Changes")); 1642c21a2d95SEGRY Gabor mb.setButtonText(QMessageBox::No, _("&Discard Changes")); 1643c21a2d95SEGRY Gabor mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit")); 16441da177e4SLinus Torvalds switch (mb.exec()) { 16451da177e4SLinus Torvalds case QMessageBox::Yes: 16461da177e4SLinus Torvalds conf_write(NULL); 16471da177e4SLinus Torvalds case QMessageBox::No: 16481da177e4SLinus Torvalds e->accept(); 16491da177e4SLinus Torvalds break; 16501da177e4SLinus Torvalds case QMessageBox::Cancel: 16511da177e4SLinus Torvalds e->ignore(); 16521da177e4SLinus Torvalds break; 16531da177e4SLinus Torvalds } 16541da177e4SLinus Torvalds } 16551da177e4SLinus Torvalds 16561da177e4SLinus Torvalds void ConfigMainWindow::showIntro(void) 16571da177e4SLinus Torvalds { 1658652cf982SArnaud Lacombe static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n" 16591da177e4SLinus Torvalds "For each option, a blank box indicates the feature is disabled, a check\n" 16601da177e4SLinus Torvalds "indicates it is enabled, and a dot indicates that it is to be compiled\n" 16611da177e4SLinus Torvalds "as a module. Clicking on the box will cycle through the three states.\n\n" 16621da177e4SLinus Torvalds "If you do not see an option (e.g., a device driver) that you believe\n" 16631da177e4SLinus Torvalds "should be present, try turning on Show All Options under the Options menu.\n" 16641da177e4SLinus Torvalds "Although there is no cross reference yet to help you figure out what other\n" 16651da177e4SLinus Torvalds "options must be enabled to support the option you are interested in, you can\n" 16661da177e4SLinus Torvalds "still view the help of a grayed-out option.\n\n" 16671da177e4SLinus Torvalds "Toggling Show Debug Info under the Options menu will show the dependencies,\n" 1668c21a2d95SEGRY Gabor "which you can then match by examining other options.\n\n"); 16691da177e4SLinus Torvalds 16701da177e4SLinus Torvalds QMessageBox::information(this, "qconf", str); 16711da177e4SLinus Torvalds } 16721da177e4SLinus Torvalds 16731da177e4SLinus Torvalds void ConfigMainWindow::showAbout(void) 16741da177e4SLinus Torvalds { 1675c21a2d95SEGRY Gabor static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n" 1676c21a2d95SEGRY Gabor "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n"); 16771da177e4SLinus Torvalds 16781da177e4SLinus Torvalds QMessageBox::information(this, "qconf", str); 16791da177e4SLinus Torvalds } 16801da177e4SLinus Torvalds 16811da177e4SLinus Torvalds void ConfigMainWindow::saveSettings(void) 16821da177e4SLinus Torvalds { 16837fc925fdSRoman Zippel configSettings->writeEntry("/window x", pos().x()); 16847fc925fdSRoman Zippel configSettings->writeEntry("/window y", pos().y()); 16857fc925fdSRoman Zippel configSettings->writeEntry("/window width", size().width()); 16867fc925fdSRoman Zippel configSettings->writeEntry("/window height", size().height()); 16871da177e4SLinus Torvalds 16881da177e4SLinus Torvalds QString entry; 16891da177e4SLinus Torvalds switch(configList->mode) { 16901da177e4SLinus Torvalds case singleMode : 16911da177e4SLinus Torvalds entry = "single"; 16921da177e4SLinus Torvalds break; 16931da177e4SLinus Torvalds 16941da177e4SLinus Torvalds case symbolMode : 16951da177e4SLinus Torvalds entry = "split"; 16961da177e4SLinus Torvalds break; 16971da177e4SLinus Torvalds 16981da177e4SLinus Torvalds case fullMode : 16991da177e4SLinus Torvalds entry = "full"; 17001da177e4SLinus Torvalds break; 170198403a91SMarkus Heidelberg 170298403a91SMarkus Heidelberg default: 170398403a91SMarkus Heidelberg break; 17041da177e4SLinus Torvalds } 17057fc925fdSRoman Zippel configSettings->writeEntry("/listMode", entry); 17061da177e4SLinus Torvalds 17077fc925fdSRoman Zippel configSettings->writeSizes("/split1", split1->sizes()); 17087fc925fdSRoman Zippel configSettings->writeSizes("/split2", split2->sizes()); 17091da177e4SLinus Torvalds } 17101da177e4SLinus Torvalds 17113b354c55SKarsten Wiese void ConfigMainWindow::conf_changed(void) 17123b354c55SKarsten Wiese { 17133b354c55SKarsten Wiese if (saveAction) 17143b354c55SKarsten Wiese saveAction->setEnabled(conf_get_changed()); 17153b354c55SKarsten Wiese } 17163b354c55SKarsten Wiese 17171da177e4SLinus Torvalds void fixup_rootmenu(struct menu *menu) 17181da177e4SLinus Torvalds { 17191da177e4SLinus Torvalds struct menu *child; 17201da177e4SLinus Torvalds static int menu_cnt = 0; 17211da177e4SLinus Torvalds 17221da177e4SLinus Torvalds menu->flags |= MENU_ROOT; 17231da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) { 17241da177e4SLinus Torvalds if (child->prompt && child->prompt->type == P_MENU) { 17251da177e4SLinus Torvalds menu_cnt++; 17261da177e4SLinus Torvalds fixup_rootmenu(child); 17271da177e4SLinus Torvalds menu_cnt--; 17281da177e4SLinus Torvalds } else if (!menu_cnt) 17291da177e4SLinus Torvalds fixup_rootmenu(child); 17301da177e4SLinus Torvalds } 17311da177e4SLinus Torvalds } 17321da177e4SLinus Torvalds 17331da177e4SLinus Torvalds static const char *progname; 17341da177e4SLinus Torvalds 17351da177e4SLinus Torvalds static void usage(void) 17361da177e4SLinus Torvalds { 1737c21a2d95SEGRY Gabor printf(_("%s <config>\n"), progname); 17381da177e4SLinus Torvalds exit(0); 17391da177e4SLinus Torvalds } 17401da177e4SLinus Torvalds 17411da177e4SLinus Torvalds int main(int ac, char** av) 17421da177e4SLinus Torvalds { 17431da177e4SLinus Torvalds ConfigMainWindow* v; 17441da177e4SLinus Torvalds const char *name; 17451da177e4SLinus Torvalds 17463b9fa093SArnaldo Carvalho de Melo bindtextdomain(PACKAGE, LOCALEDIR); 17473b9fa093SArnaldo Carvalho de Melo textdomain(PACKAGE); 17483b9fa093SArnaldo Carvalho de Melo 17491da177e4SLinus Torvalds #ifndef LKC_DIRECT_LINK 17501da177e4SLinus Torvalds kconfig_load(); 17511da177e4SLinus Torvalds #endif 17521da177e4SLinus Torvalds 17531da177e4SLinus Torvalds progname = av[0]; 17541da177e4SLinus Torvalds configApp = new QApplication(ac, av); 17551da177e4SLinus Torvalds if (ac > 1 && av[1][0] == '-') { 17561da177e4SLinus Torvalds switch (av[1][1]) { 17571da177e4SLinus Torvalds case 'h': 17581da177e4SLinus Torvalds case '?': 17591da177e4SLinus Torvalds usage(); 17601da177e4SLinus Torvalds } 17611da177e4SLinus Torvalds name = av[2]; 17621da177e4SLinus Torvalds } else 17631da177e4SLinus Torvalds name = av[1]; 17641da177e4SLinus Torvalds if (!name) 17651da177e4SLinus Torvalds usage(); 17661da177e4SLinus Torvalds 17671da177e4SLinus Torvalds conf_parse(name); 17681da177e4SLinus Torvalds fixup_rootmenu(&rootmenu); 17691da177e4SLinus Torvalds conf_read(NULL); 17701da177e4SLinus Torvalds //zconfdump(stdout); 17711da177e4SLinus Torvalds 17727fc925fdSRoman Zippel configSettings = new ConfigSettings(); 17737fc925fdSRoman Zippel configSettings->beginGroup("/kconfig/qconf"); 17741da177e4SLinus Torvalds v = new ConfigMainWindow(); 17751da177e4SLinus Torvalds 17761da177e4SLinus Torvalds //zconfdump(stdout); 177743bf612aSRoman Zippel configApp->setMainWidget(v); 17781da177e4SLinus Torvalds configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit())); 17791da177e4SLinus Torvalds configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings())); 178043bf612aSRoman Zippel v->show(); 17811da177e4SLinus Torvalds configApp->exec(); 17821da177e4SLinus Torvalds 17837fc925fdSRoman Zippel configSettings->endGroup(); 17847fc925fdSRoman Zippel delete configSettings; 17857fc925fdSRoman Zippel 17861da177e4SLinus Torvalds return 0; 17871da177e4SLinus Torvalds } 1788