3
0

qconf.cc 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. /*
  2. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  3. * Released under the terms of the GNU GPL v2.0.
  4. */
  5. #include <qapplication.h>
  6. #include <qmainwindow.h>
  7. #include <qtoolbar.h>
  8. #include <qvbox.h>
  9. #include <qsplitter.h>
  10. #include <qlistview.h>
  11. #include <qtextview.h>
  12. #include <qlineedit.h>
  13. #include <qmenubar.h>
  14. #include <qmessagebox.h>
  15. #include <qaction.h>
  16. #include <qheader.h>
  17. #include <qfiledialog.h>
  18. #include <qregexp.h>
  19. #include <stdlib.h>
  20. #include "lkc.h"
  21. #include "qconf.h"
  22. #include "qconf.moc"
  23. #include "images.c"
  24. #ifdef _
  25. # undef _
  26. # define _ qgettext
  27. #endif
  28. static QApplication *configApp;
  29. static inline QString qgettext(const char* str)
  30. {
  31. return QString::fromLocal8Bit(gettext(str));
  32. }
  33. static inline QString qgettext(const QString& str)
  34. {
  35. return QString::fromLocal8Bit(gettext(str.latin1()));
  36. }
  37. ConfigSettings::ConfigSettings()
  38. : showAll(false), showName(false), showRange(false), showData(false)
  39. {
  40. }
  41. #if QT_VERSION >= 300
  42. /**
  43. * Reads the list column settings from the application settings.
  44. */
  45. void ConfigSettings::readListSettings()
  46. {
  47. showAll = readBoolEntry("/kconfig/qconf/showAll", false);
  48. showName = readBoolEntry("/kconfig/qconf/showName", false);
  49. showRange = readBoolEntry("/kconfig/qconf/showRange", false);
  50. showData = readBoolEntry("/kconfig/qconf/showData", false);
  51. }
  52. /**
  53. * Reads a list of integer values from the application settings.
  54. */
  55. QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
  56. {
  57. QValueList<int> result;
  58. QStringList entryList = readListEntry(key, ok);
  59. if (ok) {
  60. QStringList::Iterator it;
  61. for (it = entryList.begin(); it != entryList.end(); ++it)
  62. result.push_back((*it).toInt());
  63. }
  64. return result;
  65. }
  66. /**
  67. * Writes a list of integer values to the application settings.
  68. */
  69. bool ConfigSettings::writeSizes(const QString& key, const QValueList<int>& value)
  70. {
  71. QStringList stringList;
  72. QValueList<int>::ConstIterator it;
  73. for (it = value.begin(); it != value.end(); ++it)
  74. stringList.push_back(QString::number(*it));
  75. return writeEntry(key, stringList);
  76. }
  77. #endif
  78. /*
  79. * update all the children of a menu entry
  80. * removes/adds the entries from the parent widget as necessary
  81. *
  82. * parent: either the menu list widget or a menu entry widget
  83. * menu: entry to be updated
  84. */
  85. template <class P>
  86. void ConfigList::updateMenuList(P* parent, struct menu* menu)
  87. {
  88. struct menu* child;
  89. ConfigItem* item;
  90. ConfigItem* last;
  91. bool visible;
  92. enum prop_type type;
  93. if (!menu) {
  94. while ((item = parent->firstChild()))
  95. delete item;
  96. return;
  97. }
  98. last = parent->firstChild();
  99. if (last && !last->goParent)
  100. last = 0;
  101. for (child = menu->list; child; child = child->next) {
  102. item = last ? last->nextSibling() : parent->firstChild();
  103. type = child->prompt ? child->prompt->type : P_UNKNOWN;
  104. switch (mode) {
  105. case menuMode:
  106. if (!(child->flags & MENU_ROOT))
  107. goto hide;
  108. break;
  109. case symbolMode:
  110. if (child->flags & MENU_ROOT)
  111. goto hide;
  112. break;
  113. default:
  114. break;
  115. }
  116. visible = menu_is_visible(child);
  117. if (showAll || visible) {
  118. if (!item || item->menu != child)
  119. item = new ConfigItem(parent, last, child, visible);
  120. else
  121. item->testUpdateMenu(visible);
  122. if (mode == fullMode || mode == menuMode || type != P_MENU)
  123. updateMenuList(item, child);
  124. else
  125. updateMenuList(item, 0);
  126. last = item;
  127. continue;
  128. }
  129. hide:
  130. if (item && item->menu == child) {
  131. last = parent->firstChild();
  132. if (last == item)
  133. last = 0;
  134. else while (last->nextSibling() != item)
  135. last = last->nextSibling();
  136. delete item;
  137. }
  138. }
  139. }
  140. #if QT_VERSION >= 300
  141. /*
  142. * set the new data
  143. * TODO check the value
  144. */
  145. void ConfigItem::okRename(int col)
  146. {
  147. Parent::okRename(col);
  148. sym_set_string_value(menu->sym, text(dataColIdx).latin1());
  149. }
  150. #endif
  151. /*
  152. * update the displayed of a menu entry
  153. */
  154. void ConfigItem::updateMenu(void)
  155. {
  156. ConfigList* list;
  157. struct symbol* sym;
  158. struct property *prop;
  159. QString prompt;
  160. int type;
  161. tristate expr;
  162. list = listView();
  163. if (goParent) {
  164. setPixmap(promptColIdx, list->menuBackPix);
  165. prompt = "..";
  166. goto set_prompt;
  167. }
  168. sym = menu->sym;
  169. prop = menu->prompt;
  170. prompt = QString::fromLocal8Bit(menu_get_prompt(menu));
  171. if (prop) switch (prop->type) {
  172. case P_MENU:
  173. if (list->mode == singleMode || list->mode == symbolMode) {
  174. /* a menuconfig entry is displayed differently
  175. * depending whether it's at the view root or a child.
  176. */
  177. if (sym && list->rootEntry == menu)
  178. break;
  179. setPixmap(promptColIdx, list->menuPix);
  180. } else {
  181. if (sym)
  182. break;
  183. setPixmap(promptColIdx, 0);
  184. }
  185. goto set_prompt;
  186. case P_COMMENT:
  187. setPixmap(promptColIdx, 0);
  188. goto set_prompt;
  189. default:
  190. ;
  191. }
  192. if (!sym)
  193. goto set_prompt;
  194. setText(nameColIdx, QString::fromLocal8Bit(sym->name));
  195. type = sym_get_type(sym);
  196. switch (type) {
  197. case S_BOOLEAN:
  198. case S_TRISTATE:
  199. char ch;
  200. if (!sym_is_changable(sym) && !list->showAll) {
  201. setPixmap(promptColIdx, 0);
  202. setText(noColIdx, QString::null);
  203. setText(modColIdx, QString::null);
  204. setText(yesColIdx, QString::null);
  205. break;
  206. }
  207. expr = sym_get_tristate_value(sym);
  208. switch (expr) {
  209. case yes:
  210. if (sym_is_choice_value(sym) && type == S_BOOLEAN)
  211. setPixmap(promptColIdx, list->choiceYesPix);
  212. else
  213. setPixmap(promptColIdx, list->symbolYesPix);
  214. setText(yesColIdx, "Y");
  215. ch = 'Y';
  216. break;
  217. case mod:
  218. setPixmap(promptColIdx, list->symbolModPix);
  219. setText(modColIdx, "M");
  220. ch = 'M';
  221. break;
  222. default:
  223. if (sym_is_choice_value(sym) && type == S_BOOLEAN)
  224. setPixmap(promptColIdx, list->choiceNoPix);
  225. else
  226. setPixmap(promptColIdx, list->symbolNoPix);
  227. setText(noColIdx, "N");
  228. ch = 'N';
  229. break;
  230. }
  231. if (expr != no)
  232. setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
  233. if (expr != mod)
  234. setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
  235. if (expr != yes)
  236. setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
  237. setText(dataColIdx, QChar(ch));
  238. break;
  239. case S_INT:
  240. case S_HEX:
  241. case S_STRING:
  242. const char* data;
  243. data = sym_get_string_value(sym);
  244. #if QT_VERSION >= 300
  245. int i = list->mapIdx(dataColIdx);
  246. if (i >= 0)
  247. setRenameEnabled(i, TRUE);
  248. #endif
  249. setText(dataColIdx, data);
  250. if (type == S_STRING)
  251. prompt = QString("%1: %2").arg(prompt).arg(data);
  252. else
  253. prompt = QString("(%2) %1").arg(prompt).arg(data);
  254. break;
  255. }
  256. if (!sym_has_value(sym) && visible)
  257. prompt += " (NEW)";
  258. set_prompt:
  259. setText(promptColIdx, prompt);
  260. }
  261. void ConfigItem::testUpdateMenu(bool v)
  262. {
  263. ConfigItem* i;
  264. visible = v;
  265. if (!menu)
  266. return;
  267. sym_calc_value(menu->sym);
  268. if (menu->flags & MENU_CHANGED) {
  269. /* the menu entry changed, so update all list items */
  270. menu->flags &= ~MENU_CHANGED;
  271. for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
  272. i->updateMenu();
  273. } else if (listView()->updateAll)
  274. updateMenu();
  275. }
  276. void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
  277. {
  278. ConfigList* list = listView();
  279. if (visible) {
  280. if (isSelected() && !list->hasFocus() && list->mode == menuMode)
  281. Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
  282. else
  283. Parent::paintCell(p, cg, column, width, align);
  284. } else
  285. Parent::paintCell(p, list->disabledColorGroup, column, width, align);
  286. }
  287. /*
  288. * construct a menu entry
  289. */
  290. void ConfigItem::init(void)
  291. {
  292. if (menu) {
  293. ConfigList* list = listView();
  294. nextItem = (ConfigItem*)menu->data;
  295. menu->data = this;
  296. if (list->mode != fullMode)
  297. setOpen(TRUE);
  298. sym_calc_value(menu->sym);
  299. }
  300. updateMenu();
  301. }
  302. /*
  303. * destruct a menu entry
  304. */
  305. ConfigItem::~ConfigItem(void)
  306. {
  307. if (menu) {
  308. ConfigItem** ip = (ConfigItem**)&menu->data;
  309. for (; *ip; ip = &(*ip)->nextItem) {
  310. if (*ip == this) {
  311. *ip = nextItem;
  312. break;
  313. }
  314. }
  315. }
  316. }
  317. void ConfigLineEdit::show(ConfigItem* i)
  318. {
  319. item = i;
  320. if (sym_get_string_value(item->menu->sym))
  321. setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
  322. else
  323. setText(QString::null);
  324. Parent::show();
  325. setFocus();
  326. }
  327. void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
  328. {
  329. switch (e->key()) {
  330. case Key_Escape:
  331. break;
  332. case Key_Return:
  333. case Key_Enter:
  334. sym_set_string_value(item->menu->sym, text().latin1());
  335. parent()->updateList(item);
  336. break;
  337. default:
  338. Parent::keyPressEvent(e);
  339. return;
  340. }
  341. e->accept();
  342. parent()->list->setFocus();
  343. hide();
  344. }
  345. ConfigList::ConfigList(ConfigView* p, ConfigMainWindow* cv, ConfigSettings* configSettings)
  346. : Parent(p), cview(cv),
  347. updateAll(false),
  348. symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
  349. choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
  350. menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
  351. showAll(false), showName(false), showRange(false), showData(false),
  352. rootEntry(0)
  353. {
  354. int i;
  355. setSorting(-1);
  356. setRootIsDecorated(TRUE);
  357. disabledColorGroup = palette().active();
  358. disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
  359. inactivedColorGroup = palette().active();
  360. inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
  361. connect(this, SIGNAL(selectionChanged(void)),
  362. SLOT(updateSelection(void)));
  363. if (configSettings) {
  364. showAll = configSettings->showAll;
  365. showName = configSettings->showName;
  366. showRange = configSettings->showRange;
  367. showData = configSettings->showData;
  368. }
  369. for (i = 0; i < colNr; i++)
  370. colMap[i] = colRevMap[i] = -1;
  371. addColumn(promptColIdx, "Option");
  372. reinit();
  373. }
  374. void ConfigList::reinit(void)
  375. {
  376. removeColumn(dataColIdx);
  377. removeColumn(yesColIdx);
  378. removeColumn(modColIdx);
  379. removeColumn(noColIdx);
  380. removeColumn(nameColIdx);
  381. if (showName)
  382. addColumn(nameColIdx, "Name");
  383. if (showRange) {
  384. addColumn(noColIdx, "N");
  385. addColumn(modColIdx, "M");
  386. addColumn(yesColIdx, "Y");
  387. }
  388. if (showData)
  389. addColumn(dataColIdx, "Value");
  390. updateListAll();
  391. }
  392. void ConfigList::updateSelection(void)
  393. {
  394. struct menu *menu;
  395. enum prop_type type;
  396. ConfigItem* item = (ConfigItem*)selectedItem();
  397. if (!item)
  398. return;
  399. cview->setHelp(item);
  400. menu = item->menu;
  401. if (!menu)
  402. return;
  403. type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  404. if (mode == menuMode && type == P_MENU)
  405. emit menuSelected(menu);
  406. }
  407. void ConfigList::updateList(ConfigItem* item)
  408. {
  409. ConfigItem* last = 0;
  410. if (!rootEntry)
  411. goto update;
  412. if (rootEntry != &rootmenu && (mode == singleMode ||
  413. (mode == symbolMode && rootEntry->parent != &rootmenu))) {
  414. item = firstChild();
  415. if (!item)
  416. item = new ConfigItem(this, 0, true);
  417. last = item;
  418. }
  419. if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
  420. rootEntry->sym && rootEntry->prompt) {
  421. item = last ? last->nextSibling() : firstChild();
  422. if (!item)
  423. item = new ConfigItem(this, last, rootEntry, true);
  424. else
  425. item->testUpdateMenu(true);
  426. updateMenuList(item, rootEntry);
  427. triggerUpdate();
  428. return;
  429. }
  430. update:
  431. updateMenuList(this, rootEntry);
  432. triggerUpdate();
  433. }
  434. void ConfigList::setAllOpen(bool open)
  435. {
  436. QListViewItemIterator it(this);
  437. for (; it.current(); it++)
  438. it.current()->setOpen(open);
  439. }
  440. void ConfigList::setValue(ConfigItem* item, tristate val)
  441. {
  442. struct symbol* sym;
  443. int type;
  444. tristate oldval;
  445. sym = item->menu ? item->menu->sym : 0;
  446. if (!sym)
  447. return;
  448. type = sym_get_type(sym);
  449. switch (type) {
  450. case S_BOOLEAN:
  451. case S_TRISTATE:
  452. oldval = sym_get_tristate_value(sym);
  453. if (!sym_set_tristate_value(sym, val))
  454. return;
  455. if (oldval == no && item->menu->list)
  456. item->setOpen(TRUE);
  457. parent()->updateList(item);
  458. break;
  459. }
  460. }
  461. void ConfigList::changeValue(ConfigItem* item)
  462. {
  463. struct symbol* sym;
  464. struct menu* menu;
  465. int type, oldexpr, newexpr;
  466. menu = item->menu;
  467. if (!menu)
  468. return;
  469. sym = menu->sym;
  470. if (!sym) {
  471. if (item->menu->list)
  472. item->setOpen(!item->isOpen());
  473. return;
  474. }
  475. type = sym_get_type(sym);
  476. switch (type) {
  477. case S_BOOLEAN:
  478. case S_TRISTATE:
  479. oldexpr = sym_get_tristate_value(sym);
  480. newexpr = sym_toggle_tristate_value(sym);
  481. if (item->menu->list) {
  482. if (oldexpr == newexpr)
  483. item->setOpen(!item->isOpen());
  484. else if (oldexpr == no)
  485. item->setOpen(TRUE);
  486. }
  487. if (oldexpr != newexpr)
  488. parent()->updateList(item);
  489. break;
  490. case S_INT:
  491. case S_HEX:
  492. case S_STRING:
  493. #if QT_VERSION >= 300
  494. if (colMap[dataColIdx] >= 0)
  495. item->startRename(colMap[dataColIdx]);
  496. else
  497. #endif
  498. parent()->lineEdit->show(item);
  499. break;
  500. }
  501. }
  502. void ConfigList::setRootMenu(struct menu *menu)
  503. {
  504. enum prop_type type;
  505. if (rootEntry == menu)
  506. return;
  507. type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
  508. if (type != P_MENU)
  509. return;
  510. updateMenuList(this, 0);
  511. rootEntry = menu;
  512. updateListAll();
  513. setSelected(currentItem(), hasFocus());
  514. }
  515. void ConfigList::setParentMenu(void)
  516. {
  517. ConfigItem* item;
  518. struct menu *oldroot;
  519. oldroot = rootEntry;
  520. if (rootEntry == &rootmenu)
  521. return;
  522. setRootMenu(menu_get_parent_menu(rootEntry->parent));
  523. QListViewItemIterator it(this);
  524. for (; (item = (ConfigItem*)it.current()); it++) {
  525. if (item->menu == oldroot) {
  526. setCurrentItem(item);
  527. ensureItemVisible(item);
  528. break;
  529. }
  530. }
  531. }
  532. void ConfigList::keyPressEvent(QKeyEvent* ev)
  533. {
  534. QListViewItem* i = currentItem();
  535. ConfigItem* item;
  536. struct menu *menu;
  537. enum prop_type type;
  538. if (ev->key() == Key_Escape && mode != fullMode) {
  539. emit parentSelected();
  540. ev->accept();
  541. return;
  542. }
  543. if (!i) {
  544. Parent::keyPressEvent(ev);
  545. return;
  546. }
  547. item = (ConfigItem*)i;
  548. switch (ev->key()) {
  549. case Key_Return:
  550. case Key_Enter:
  551. if (item->goParent) {
  552. emit parentSelected();
  553. break;
  554. }
  555. menu = item->menu;
  556. if (!menu)
  557. break;
  558. type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  559. if (type == P_MENU && rootEntry != menu &&
  560. mode != fullMode && mode != menuMode) {
  561. emit menuSelected(menu);
  562. break;
  563. }
  564. case Key_Space:
  565. changeValue(item);
  566. break;
  567. case Key_N:
  568. setValue(item, no);
  569. break;
  570. case Key_M:
  571. setValue(item, mod);
  572. break;
  573. case Key_Y:
  574. setValue(item, yes);
  575. break;
  576. default:
  577. Parent::keyPressEvent(ev);
  578. return;
  579. }
  580. ev->accept();
  581. }
  582. void ConfigList::contentsMousePressEvent(QMouseEvent* e)
  583. {
  584. //QPoint p(contentsToViewport(e->pos()));
  585. //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
  586. Parent::contentsMousePressEvent(e);
  587. }
  588. void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
  589. {
  590. QPoint p(contentsToViewport(e->pos()));
  591. ConfigItem* item = (ConfigItem*)itemAt(p);
  592. struct menu *menu;
  593. enum prop_type ptype;
  594. const QPixmap* pm;
  595. int idx, x;
  596. if (!item)
  597. goto skip;
  598. menu = item->menu;
  599. x = header()->offset() + p.x();
  600. idx = colRevMap[header()->sectionAt(x)];
  601. switch (idx) {
  602. case promptColIdx:
  603. pm = item->pixmap(promptColIdx);
  604. if (pm) {
  605. int off = header()->sectionPos(0) + itemMargin() +
  606. treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
  607. if (x >= off && x < off + pm->width()) {
  608. if (item->goParent) {
  609. emit parentSelected();
  610. break;
  611. } else if (!menu)
  612. break;
  613. ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  614. if (ptype == P_MENU && rootEntry != menu &&
  615. mode != fullMode && mode != menuMode)
  616. emit menuSelected(menu);
  617. else
  618. changeValue(item);
  619. }
  620. }
  621. break;
  622. case noColIdx:
  623. setValue(item, no);
  624. break;
  625. case modColIdx:
  626. setValue(item, mod);
  627. break;
  628. case yesColIdx:
  629. setValue(item, yes);
  630. break;
  631. case dataColIdx:
  632. changeValue(item);
  633. break;
  634. }
  635. skip:
  636. //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
  637. Parent::contentsMouseReleaseEvent(e);
  638. }
  639. void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
  640. {
  641. //QPoint p(contentsToViewport(e->pos()));
  642. //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
  643. Parent::contentsMouseMoveEvent(e);
  644. }
  645. void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
  646. {
  647. QPoint p(contentsToViewport(e->pos()));
  648. ConfigItem* item = (ConfigItem*)itemAt(p);
  649. struct menu *menu;
  650. enum prop_type ptype;
  651. if (!item)
  652. goto skip;
  653. if (item->goParent) {
  654. emit parentSelected();
  655. goto skip;
  656. }
  657. menu = item->menu;
  658. if (!menu)
  659. goto skip;
  660. ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  661. if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
  662. emit menuSelected(menu);
  663. else if (menu->sym)
  664. changeValue(item);
  665. skip:
  666. //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
  667. Parent::contentsMouseDoubleClickEvent(e);
  668. }
  669. void ConfigList::focusInEvent(QFocusEvent *e)
  670. {
  671. Parent::focusInEvent(e);
  672. QListViewItem* item = currentItem();
  673. if (!item)
  674. return;
  675. setSelected(item, TRUE);
  676. emit gotFocus();
  677. }
  678. ConfigView* ConfigView::viewList;
  679. ConfigView::ConfigView(QWidget* parent, ConfigMainWindow* cview,
  680. ConfigSettings *configSettings)
  681. : Parent(parent)
  682. {
  683. list = new ConfigList(this, cview, configSettings);
  684. lineEdit = new ConfigLineEdit(this);
  685. lineEdit->hide();
  686. this->nextView = viewList;
  687. viewList = this;
  688. }
  689. ConfigView::~ConfigView(void)
  690. {
  691. ConfigView** vp;
  692. for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
  693. if (*vp == this) {
  694. *vp = nextView;
  695. break;
  696. }
  697. }
  698. }
  699. void ConfigView::updateList(ConfigItem* item)
  700. {
  701. ConfigView* v;
  702. for (v = viewList; v; v = v->nextView)
  703. v->list->updateList(item);
  704. }
  705. void ConfigView::updateListAll(void)
  706. {
  707. ConfigView* v;
  708. for (v = viewList; v; v = v->nextView)
  709. v->list->updateListAll();
  710. }
  711. /*
  712. * Construct the complete config widget
  713. */
  714. ConfigMainWindow::ConfigMainWindow(void)
  715. {
  716. QMenuBar* menu;
  717. bool ok;
  718. int x, y, width, height;
  719. QWidget *d = configApp->desktop();
  720. ConfigSettings* configSettings = new ConfigSettings();
  721. #if QT_VERSION >= 300
  722. width = configSettings->readNumEntry("/kconfig/qconf/window width", d->width() - 64);
  723. height = configSettings->readNumEntry("/kconfig/qconf/window height", d->height() - 64);
  724. resize(width, height);
  725. x = configSettings->readNumEntry("/kconfig/qconf/window x", 0, &ok);
  726. if (ok)
  727. y = configSettings->readNumEntry("/kconfig/qconf/window y", 0, &ok);
  728. if (ok)
  729. move(x, y);
  730. showDebug = configSettings->readBoolEntry("/kconfig/qconf/showDebug", false);
  731. // read list settings into configSettings, will be used later for ConfigList setup
  732. configSettings->readListSettings();
  733. #else
  734. width = d->width() - 64;
  735. height = d->height() - 64;
  736. resize(width, height);
  737. showDebug = false;
  738. #endif
  739. split1 = new QSplitter(this);
  740. split1->setOrientation(QSplitter::Horizontal);
  741. setCentralWidget(split1);
  742. menuView = new ConfigView(split1, this, configSettings);
  743. menuList = menuView->list;
  744. split2 = new QSplitter(split1);
  745. split2->setOrientation(QSplitter::Vertical);
  746. // create config tree
  747. configView = new ConfigView(split2, this, configSettings);
  748. configList = configView->list;
  749. helpText = new QTextView(split2);
  750. helpText->setTextFormat(Qt::RichText);
  751. setTabOrder(configList, helpText);
  752. configList->setFocus();
  753. menu = menuBar();
  754. toolBar = new QToolBar("Tools", this);
  755. backAction = new QAction("Back", QPixmap(xpm_back), "Back", 0, this);
  756. connect(backAction, SIGNAL(activated()), SLOT(goBack()));
  757. backAction->setEnabled(FALSE);
  758. QAction *quitAction = new QAction("Quit", "&Quit", CTRL+Key_Q, this);
  759. connect(quitAction, SIGNAL(activated()), SLOT(close()));
  760. QAction *loadAction = new QAction("Load", QPixmap(xpm_load), "&Load", CTRL+Key_L, this);
  761. connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
  762. QAction *saveAction = new QAction("Save", QPixmap(xpm_save), "&Save", CTRL+Key_S, this);
  763. connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
  764. QAction *saveAsAction = new QAction("Save As...", "Save &As...", 0, this);
  765. connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
  766. QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), "Split View", 0, this);
  767. connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
  768. QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), "Split View", 0, this);
  769. connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
  770. QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), "Full View", 0, this);
  771. connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
  772. QAction *showNameAction = new QAction(NULL, "Show Name", 0, this);
  773. showNameAction->setToggleAction(TRUE);
  774. showNameAction->setOn(configList->showName);
  775. connect(showNameAction, SIGNAL(toggled(bool)), SLOT(setShowName(bool)));
  776. QAction *showRangeAction = new QAction(NULL, "Show Range", 0, this);
  777. showRangeAction->setToggleAction(TRUE);
  778. showRangeAction->setOn(configList->showRange);
  779. connect(showRangeAction, SIGNAL(toggled(bool)), SLOT(setShowRange(bool)));
  780. QAction *showDataAction = new QAction(NULL, "Show Data", 0, this);
  781. showDataAction->setToggleAction(TRUE);
  782. showDataAction->setOn(configList->showData);
  783. connect(showDataAction, SIGNAL(toggled(bool)), SLOT(setShowData(bool)));
  784. QAction *showAllAction = new QAction(NULL, "Show All Options", 0, this);
  785. showAllAction->setToggleAction(TRUE);
  786. showAllAction->setOn(configList->showAll);
  787. connect(showAllAction, SIGNAL(toggled(bool)), SLOT(setShowAll(bool)));
  788. QAction *showDebugAction = new QAction(NULL, "Show Debug Info", 0, this);
  789. showDebugAction->setToggleAction(TRUE);
  790. showDebugAction->setOn(showDebug);
  791. connect(showDebugAction, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
  792. QAction *showIntroAction = new QAction(NULL, "Introduction", 0, this);
  793. connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
  794. QAction *showAboutAction = new QAction(NULL, "About", 0, this);
  795. connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
  796. // init tool bar
  797. backAction->addTo(toolBar);
  798. toolBar->addSeparator();
  799. loadAction->addTo(toolBar);
  800. saveAction->addTo(toolBar);
  801. toolBar->addSeparator();
  802. singleViewAction->addTo(toolBar);
  803. splitViewAction->addTo(toolBar);
  804. fullViewAction->addTo(toolBar);
  805. // create config menu
  806. QPopupMenu* config = new QPopupMenu(this);
  807. menu->insertItem("&File", config);
  808. loadAction->addTo(config);
  809. saveAction->addTo(config);
  810. saveAsAction->addTo(config);
  811. config->insertSeparator();
  812. quitAction->addTo(config);
  813. // create options menu
  814. QPopupMenu* optionMenu = new QPopupMenu(this);
  815. menu->insertItem("&Option", optionMenu);
  816. showNameAction->addTo(optionMenu);
  817. showRangeAction->addTo(optionMenu);
  818. showDataAction->addTo(optionMenu);
  819. optionMenu->insertSeparator();
  820. showAllAction->addTo(optionMenu);
  821. showDebugAction->addTo(optionMenu);
  822. // create help menu
  823. QPopupMenu* helpMenu = new QPopupMenu(this);
  824. menu->insertSeparator();
  825. menu->insertItem("&Help", helpMenu);
  826. showIntroAction->addTo(helpMenu);
  827. showAboutAction->addTo(helpMenu);
  828. connect(configList, SIGNAL(menuSelected(struct menu *)),
  829. SLOT(changeMenu(struct menu *)));
  830. connect(configList, SIGNAL(parentSelected()),
  831. SLOT(goBack()));
  832. connect(menuList, SIGNAL(menuSelected(struct menu *)),
  833. SLOT(changeMenu(struct menu *)));
  834. connect(configList, SIGNAL(gotFocus(void)),
  835. SLOT(listFocusChanged(void)));
  836. connect(menuList, SIGNAL(gotFocus(void)),
  837. SLOT(listFocusChanged(void)));
  838. #if QT_VERSION >= 300
  839. QString listMode = configSettings->readEntry("/kconfig/qconf/listMode", "symbol");
  840. if (listMode == "single")
  841. showSingleView();
  842. else if (listMode == "full")
  843. showFullView();
  844. else /*if (listMode == "split")*/
  845. showSplitView();
  846. // UI setup done, restore splitter positions
  847. QValueList<int> sizes = configSettings->readSizes("/kconfig/qconf/split1", &ok);
  848. if (ok)
  849. split1->setSizes(sizes);
  850. sizes = configSettings->readSizes("/kconfig/qconf/split2", &ok);
  851. if (ok)
  852. split2->setSizes(sizes);
  853. #else
  854. showSplitView();
  855. #endif
  856. delete configSettings;
  857. }
  858. static QString print_filter(const QString &str)
  859. {
  860. QRegExp re("[<>&\"\\n]");
  861. QString res = str;
  862. for (int i = 0; (i = res.find(re, i)) >= 0;) {
  863. switch (res[i].latin1()) {
  864. case '<':
  865. res.replace(i, 1, "&lt;");
  866. i += 4;
  867. break;
  868. case '>':
  869. res.replace(i, 1, "&gt;");
  870. i += 4;
  871. break;
  872. case '&':
  873. res.replace(i, 1, "&amp;");
  874. i += 5;
  875. break;
  876. case '"':
  877. res.replace(i, 1, "&quot;");
  878. i += 6;
  879. break;
  880. case '\n':
  881. res.replace(i, 1, "<br>");
  882. i += 4;
  883. break;
  884. }
  885. }
  886. return res;
  887. }
  888. static void expr_print_help(void *data, const char *str)
  889. {
  890. reinterpret_cast<QString*>(data)->append(print_filter(str));
  891. }
  892. /*
  893. * display a new help entry as soon as a new menu entry is selected
  894. */
  895. void ConfigMainWindow::setHelp(QListViewItem* item)
  896. {
  897. struct symbol* sym;
  898. struct menu* menu = 0;
  899. configList->parent()->lineEdit->hide();
  900. if (item)
  901. menu = ((ConfigItem*)item)->menu;
  902. if (!menu) {
  903. helpText->setText(QString::null);
  904. return;
  905. }
  906. QString head, debug, help;
  907. menu = ((ConfigItem*)item)->menu;
  908. sym = menu->sym;
  909. if (sym) {
  910. if (menu->prompt) {
  911. head += "<big><b>";
  912. head += print_filter(_(menu->prompt->text));
  913. head += "</b></big>";
  914. if (sym->name) {
  915. head += " (";
  916. head += print_filter(_(sym->name));
  917. head += ")";
  918. }
  919. } else if (sym->name) {
  920. head += "<big><b>";
  921. head += print_filter(_(sym->name));
  922. head += "</b></big>";
  923. }
  924. head += "<br><br>";
  925. if (showDebug) {
  926. debug += "type: ";
  927. debug += print_filter(sym_type_name(sym->type));
  928. if (sym_is_choice(sym))
  929. debug += " (choice)";
  930. debug += "<br>";
  931. if (sym->rev_dep.expr) {
  932. debug += "reverse dep: ";
  933. expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
  934. debug += "<br>";
  935. }
  936. for (struct property *prop = sym->prop; prop; prop = prop->next) {
  937. switch (prop->type) {
  938. case P_PROMPT:
  939. case P_MENU:
  940. debug += "prompt: ";
  941. debug += print_filter(_(prop->text));
  942. debug += "<br>";
  943. break;
  944. case P_DEFAULT:
  945. debug += "default: ";
  946. expr_print(prop->expr, expr_print_help, &debug, E_NONE);
  947. debug += "<br>";
  948. break;
  949. case P_CHOICE:
  950. if (sym_is_choice(sym)) {
  951. debug += "choice: ";
  952. expr_print(prop->expr, expr_print_help, &debug, E_NONE);
  953. debug += "<br>";
  954. }
  955. break;
  956. case P_SELECT:
  957. debug += "select: ";
  958. expr_print(prop->expr, expr_print_help, &debug, E_NONE);
  959. debug += "<br>";
  960. break;
  961. case P_RANGE:
  962. debug += "range: ";
  963. expr_print(prop->expr, expr_print_help, &debug, E_NONE);
  964. debug += "<br>";
  965. break;
  966. default:
  967. debug += "unknown property: ";
  968. debug += prop_get_type_name(prop->type);
  969. debug += "<br>";
  970. }
  971. if (prop->visible.expr) {
  972. debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
  973. expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
  974. debug += "<br>";
  975. }
  976. }
  977. debug += "<br>";
  978. }
  979. help = print_filter(_(sym->help));
  980. } else if (menu->prompt) {
  981. head += "<big><b>";
  982. head += print_filter(_(menu->prompt->text));
  983. head += "</b></big><br><br>";
  984. if (showDebug) {
  985. if (menu->prompt->visible.expr) {
  986. debug += "&nbsp;&nbsp;dep: ";
  987. expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
  988. debug += "<br><br>";
  989. }
  990. }
  991. }
  992. if (showDebug)
  993. debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno);
  994. helpText->setText(head + debug + help);
  995. }
  996. void ConfigMainWindow::loadConfig(void)
  997. {
  998. QString s = QFileDialog::getOpenFileName(".config", NULL, this);
  999. if (s.isNull())
  1000. return;
  1001. if (conf_read(QFile::encodeName(s)))
  1002. QMessageBox::information(this, "qconf", "Unable to load configuration!");
  1003. ConfigView::updateListAll();
  1004. }
  1005. void ConfigMainWindow::saveConfig(void)
  1006. {
  1007. if (conf_write(NULL))
  1008. QMessageBox::information(this, "qconf", "Unable to save configuration!");
  1009. }
  1010. void ConfigMainWindow::saveConfigAs(void)
  1011. {
  1012. QString s = QFileDialog::getSaveFileName(".config", NULL, this);
  1013. if (s.isNull())
  1014. return;
  1015. if (conf_write(QFile::encodeName(s)))
  1016. QMessageBox::information(this, "qconf", "Unable to save configuration!");
  1017. }
  1018. void ConfigMainWindow::changeMenu(struct menu *menu)
  1019. {
  1020. configList->setRootMenu(menu);
  1021. backAction->setEnabled(TRUE);
  1022. }
  1023. void ConfigMainWindow::listFocusChanged(void)
  1024. {
  1025. if (menuList->hasFocus()) {
  1026. if (menuList->mode == menuMode)
  1027. configList->clearSelection();
  1028. setHelp(menuList->selectedItem());
  1029. } else if (configList->hasFocus()) {
  1030. setHelp(configList->selectedItem());
  1031. }
  1032. }
  1033. void ConfigMainWindow::goBack(void)
  1034. {
  1035. ConfigItem* item;
  1036. configList->setParentMenu();
  1037. if (configList->rootEntry == &rootmenu)
  1038. backAction->setEnabled(FALSE);
  1039. item = (ConfigItem*)menuList->selectedItem();
  1040. while (item) {
  1041. if (item->menu == configList->rootEntry) {
  1042. menuList->setSelected(item, TRUE);
  1043. break;
  1044. }
  1045. item = (ConfigItem*)item->parent();
  1046. }
  1047. }
  1048. void ConfigMainWindow::showSingleView(void)
  1049. {
  1050. menuView->hide();
  1051. menuList->setRootMenu(0);
  1052. configList->mode = singleMode;
  1053. if (configList->rootEntry == &rootmenu)
  1054. configList->updateListAll();
  1055. else
  1056. configList->setRootMenu(&rootmenu);
  1057. configList->setAllOpen(TRUE);
  1058. configList->setFocus();
  1059. }
  1060. void ConfigMainWindow::showSplitView(void)
  1061. {
  1062. configList->mode = symbolMode;
  1063. if (configList->rootEntry == &rootmenu)
  1064. configList->updateListAll();
  1065. else
  1066. configList->setRootMenu(&rootmenu);
  1067. configList->setAllOpen(TRUE);
  1068. configApp->processEvents();
  1069. menuList->mode = menuMode;
  1070. menuList->setRootMenu(&rootmenu);
  1071. menuList->setAllOpen(TRUE);
  1072. menuView->show();
  1073. menuList->setFocus();
  1074. }
  1075. void ConfigMainWindow::showFullView(void)
  1076. {
  1077. menuView->hide();
  1078. menuList->setRootMenu(0);
  1079. configList->mode = fullMode;
  1080. if (configList->rootEntry == &rootmenu)
  1081. configList->updateListAll();
  1082. else
  1083. configList->setRootMenu(&rootmenu);
  1084. configList->setAllOpen(FALSE);
  1085. configList->setFocus();
  1086. }
  1087. void ConfigMainWindow::setShowAll(bool b)
  1088. {
  1089. if (configList->showAll == b)
  1090. return;
  1091. configList->showAll = b;
  1092. configList->updateListAll();
  1093. menuList->showAll = b;
  1094. menuList->updateListAll();
  1095. }
  1096. void ConfigMainWindow::setShowDebug(bool b)
  1097. {
  1098. if (showDebug == b)
  1099. return;
  1100. showDebug = b;
  1101. }
  1102. void ConfigMainWindow::setShowName(bool b)
  1103. {
  1104. if (configList->showName == b)
  1105. return;
  1106. configList->showName = b;
  1107. configList->reinit();
  1108. menuList->showName = b;
  1109. menuList->reinit();
  1110. }
  1111. void ConfigMainWindow::setShowRange(bool b)
  1112. {
  1113. if (configList->showRange == b)
  1114. return;
  1115. configList->showRange = b;
  1116. configList->reinit();
  1117. menuList->showRange = b;
  1118. menuList->reinit();
  1119. }
  1120. void ConfigMainWindow::setShowData(bool b)
  1121. {
  1122. if (configList->showData == b)
  1123. return;
  1124. configList->showData = b;
  1125. configList->reinit();
  1126. menuList->showData = b;
  1127. menuList->reinit();
  1128. }
  1129. /*
  1130. * ask for saving configuration before quitting
  1131. * TODO ask only when something changed
  1132. */
  1133. void ConfigMainWindow::closeEvent(QCloseEvent* e)
  1134. {
  1135. if (!sym_change_count) {
  1136. e->accept();
  1137. return;
  1138. }
  1139. QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
  1140. QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
  1141. mb.setButtonText(QMessageBox::Yes, "&Save Changes");
  1142. mb.setButtonText(QMessageBox::No, "&Discard Changes");
  1143. mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
  1144. switch (mb.exec()) {
  1145. case QMessageBox::Yes:
  1146. conf_write(NULL);
  1147. case QMessageBox::No:
  1148. e->accept();
  1149. break;
  1150. case QMessageBox::Cancel:
  1151. e->ignore();
  1152. break;
  1153. }
  1154. }
  1155. void ConfigMainWindow::showIntro(void)
  1156. {
  1157. static char str[] = "Welcome to the qconf graphical busybox configuration tool for Linux.\n\n"
  1158. "For each option, a blank box indicates the feature is disabled, a check\n"
  1159. "indicates it is enabled, and a dot indicates that it is to be compiled\n"
  1160. "as a module. Clicking on the box will cycle through the three states.\n\n"
  1161. "If you do not see an option (e.g., a device driver) that you believe\n"
  1162. "should be present, try turning on Show All Options under the Options menu.\n"
  1163. "Although there is no cross reference yet to help you figure out what other\n"
  1164. "options must be enabled to support the option you are interested in, you can\n"
  1165. "still view the help of a grayed-out option.\n\n"
  1166. "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
  1167. "which you can then match by examining other options.\n\n";
  1168. QMessageBox::information(this, "qconf", str);
  1169. }
  1170. void ConfigMainWindow::showAbout(void)
  1171. {
  1172. static char str[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
  1173. "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
  1174. QMessageBox::information(this, "qconf", str);
  1175. }
  1176. void ConfigMainWindow::saveSettings(void)
  1177. {
  1178. #if QT_VERSION >= 300
  1179. ConfigSettings *configSettings = new ConfigSettings;
  1180. configSettings->writeEntry("/kconfig/qconf/window x", pos().x());
  1181. configSettings->writeEntry("/kconfig/qconf/window y", pos().y());
  1182. configSettings->writeEntry("/kconfig/qconf/window width", size().width());
  1183. configSettings->writeEntry("/kconfig/qconf/window height", size().height());
  1184. configSettings->writeEntry("/kconfig/qconf/showName", configList->showName);
  1185. configSettings->writeEntry("/kconfig/qconf/showRange", configList->showRange);
  1186. configSettings->writeEntry("/kconfig/qconf/showData", configList->showData);
  1187. configSettings->writeEntry("/kconfig/qconf/showAll", configList->showAll);
  1188. configSettings->writeEntry("/kconfig/qconf/showDebug", showDebug);
  1189. QString entry;
  1190. switch(configList->mode) {
  1191. case singleMode :
  1192. entry = "single";
  1193. break;
  1194. case symbolMode :
  1195. entry = "split";
  1196. break;
  1197. case fullMode :
  1198. entry = "full";
  1199. break;
  1200. }
  1201. configSettings->writeEntry("/kconfig/qconf/listMode", entry);
  1202. configSettings->writeSizes("/kconfig/qconf/split1", split1->sizes());
  1203. configSettings->writeSizes("/kconfig/qconf/split2", split2->sizes());
  1204. delete configSettings;
  1205. #endif
  1206. }
  1207. void fixup_rootmenu(struct menu *menu)
  1208. {
  1209. struct menu *child;
  1210. static int menu_cnt = 0;
  1211. menu->flags |= MENU_ROOT;
  1212. for (child = menu->list; child; child = child->next) {
  1213. if (child->prompt && child->prompt->type == P_MENU) {
  1214. menu_cnt++;
  1215. fixup_rootmenu(child);
  1216. menu_cnt--;
  1217. } else if (!menu_cnt)
  1218. fixup_rootmenu(child);
  1219. }
  1220. }
  1221. static const char *progname;
  1222. static void usage(void)
  1223. {
  1224. printf("%s <config>\n", progname);
  1225. exit(0);
  1226. }
  1227. int main(int ac, char** av)
  1228. {
  1229. ConfigMainWindow* v;
  1230. const char *name;
  1231. bindtextdomain(PACKAGE, LOCALEDIR);
  1232. textdomain(PACKAGE);
  1233. #ifndef LKC_DIRECT_LINK
  1234. kconfig_load();
  1235. #endif
  1236. progname = av[0];
  1237. configApp = new QApplication(ac, av);
  1238. if (ac > 1 && av[1][0] == '-') {
  1239. switch (av[1][1]) {
  1240. case 'h':
  1241. case '?':
  1242. usage();
  1243. }
  1244. name = av[2];
  1245. } else
  1246. name = av[1];
  1247. if (!name)
  1248. usage();
  1249. conf_parse(name);
  1250. fixup_rootmenu(&rootmenu);
  1251. conf_read(NULL);
  1252. //zconfdump(stdout);
  1253. v = new ConfigMainWindow();
  1254. //zconfdump(stdout);
  1255. v->show();
  1256. configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
  1257. configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
  1258. configApp->exec();
  1259. return 0;
  1260. }