qconf.cc 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  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 configuration tool.\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";
  1173. QMessageBox::information(this, "qconf", str);
  1174. }
  1175. void ConfigMainWindow::saveSettings(void)
  1176. {
  1177. #if QT_VERSION >= 300
  1178. ConfigSettings *configSettings = new ConfigSettings;
  1179. configSettings->writeEntry("/kconfig/qconf/window x", pos().x());
  1180. configSettings->writeEntry("/kconfig/qconf/window y", pos().y());
  1181. configSettings->writeEntry("/kconfig/qconf/window width", size().width());
  1182. configSettings->writeEntry("/kconfig/qconf/window height", size().height());
  1183. configSettings->writeEntry("/kconfig/qconf/showName", configList->showName);
  1184. configSettings->writeEntry("/kconfig/qconf/showRange", configList->showRange);
  1185. configSettings->writeEntry("/kconfig/qconf/showData", configList->showData);
  1186. configSettings->writeEntry("/kconfig/qconf/showAll", configList->showAll);
  1187. configSettings->writeEntry("/kconfig/qconf/showDebug", showDebug);
  1188. QString entry;
  1189. switch(configList->mode) {
  1190. case singleMode :
  1191. entry = "single";
  1192. break;
  1193. case symbolMode :
  1194. entry = "split";
  1195. break;
  1196. case fullMode :
  1197. entry = "full";
  1198. break;
  1199. }
  1200. configSettings->writeEntry("/kconfig/qconf/listMode", entry);
  1201. configSettings->writeSizes("/kconfig/qconf/split1", split1->sizes());
  1202. configSettings->writeSizes("/kconfig/qconf/split2", split2->sizes());
  1203. delete configSettings;
  1204. #endif
  1205. }
  1206. void fixup_rootmenu(struct menu *menu)
  1207. {
  1208. struct menu *child;
  1209. static int menu_cnt = 0;
  1210. menu->flags |= MENU_ROOT;
  1211. for (child = menu->list; child; child = child->next) {
  1212. if (child->prompt && child->prompt->type == P_MENU) {
  1213. menu_cnt++;
  1214. fixup_rootmenu(child);
  1215. menu_cnt--;
  1216. } else if (!menu_cnt)
  1217. fixup_rootmenu(child);
  1218. }
  1219. }
  1220. static const char *progname;
  1221. static void usage(void)
  1222. {
  1223. printf("%s <config>\n", progname);
  1224. exit(0);
  1225. }
  1226. int main(int ac, char** av)
  1227. {
  1228. ConfigMainWindow* v;
  1229. const char *name;
  1230. bindtextdomain(PACKAGE, LOCALEDIR);
  1231. textdomain(PACKAGE);
  1232. #ifndef LKC_DIRECT_LINK
  1233. kconfig_load();
  1234. #endif
  1235. progname = av[0];
  1236. configApp = new QApplication(ac, av);
  1237. if (ac > 1 && av[1][0] == '-') {
  1238. switch (av[1][1]) {
  1239. case 'h':
  1240. case '?':
  1241. usage();
  1242. }
  1243. name = av[2];
  1244. } else
  1245. name = av[1];
  1246. if (!name)
  1247. usage();
  1248. conf_parse(name);
  1249. fixup_rootmenu(&rootmenu);
  1250. conf_read(NULL);
  1251. //zconfdump(stdout);
  1252. v = new ConfigMainWindow();
  1253. //zconfdump(stdout);
  1254. v->show();
  1255. configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
  1256. configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
  1257. configApp->exec();
  1258. return 0;
  1259. }