qconf.cc 42 KB

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