2
0

qconf.cc 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870
  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. }