qconf.cc 43 KB

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