qconf.cc 42 KB

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