qconf.cc 42 KB

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