qconf.cc 43 KB

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