qconf.cc 44 KB

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