gconf.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  1. /* Hey EMACS -*- linux-c -*- */
  2. /*
  3. *
  4. * Copyright (C) 2002-2003 Romain Lievin <roms@tilp.info>
  5. * Released under the terms of the GNU GPL v2.0.
  6. *
  7. */
  8. #ifdef HAVE_CONFIG_H
  9. # include <config.h>
  10. #endif
  11. #include "lkc.h"
  12. #include "images.c"
  13. #include <glade/glade.h>
  14. #include <gtk/gtk.h>
  15. #include <glib.h>
  16. #include <gdk/gdkkeysyms.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. #include <time.h>
  21. #include <stdlib.h>
  22. //#define DEBUG
  23. enum {
  24. SINGLE_VIEW, SPLIT_VIEW, FULL_VIEW
  25. };
  26. static gint view_mode = FULL_VIEW;
  27. static gboolean show_name = TRUE;
  28. static gboolean show_range = TRUE;
  29. static gboolean show_value = TRUE;
  30. static gboolean show_all = FALSE;
  31. static gboolean show_debug = FALSE;
  32. static gboolean resizeable = FALSE;
  33. static char nohelp_text[] =
  34. N_("Sorry, no help available for this option yet.\n");
  35. GtkWidget *main_wnd = NULL;
  36. GtkWidget *tree1_w = NULL; // left frame
  37. GtkWidget *tree2_w = NULL; // right frame
  38. GtkWidget *text_w = NULL;
  39. GtkWidget *hpaned = NULL;
  40. GtkWidget *vpaned = NULL;
  41. GtkWidget *back_btn = NULL;
  42. GtkWidget *save_btn = NULL;
  43. GtkWidget *save_menu_item = NULL;
  44. GtkTextTag *tag1, *tag2;
  45. GdkColor color;
  46. GtkTreeStore *tree1, *tree2, *tree;
  47. GtkTreeModel *model1, *model2;
  48. static GtkTreeIter *parents[256];
  49. static gint indent;
  50. static struct menu *current; // current node for SINGLE view
  51. static struct menu *browsed; // browsed node for SPLIT view
  52. enum {
  53. COL_OPTION, COL_NAME, COL_NO, COL_MOD, COL_YES, COL_VALUE,
  54. COL_MENU, COL_COLOR, COL_EDIT, COL_PIXBUF,
  55. COL_PIXVIS, COL_BTNVIS, COL_BTNACT, COL_BTNINC, COL_BTNRAD,
  56. COL_NUMBER
  57. };
  58. static void display_list(void);
  59. static void display_tree(struct menu *menu);
  60. static void display_tree_part(void);
  61. static void update_tree(struct menu *src, GtkTreeIter * dst);
  62. static void set_node(GtkTreeIter * node, struct menu *menu, gchar ** row);
  63. static gchar **fill_row(struct menu *menu);
  64. static void conf_changed(void);
  65. /* Helping/Debugging Functions */
  66. const char *dbg_print_stype(int val)
  67. {
  68. static char buf[256];
  69. bzero(buf, 256);
  70. if (val == S_UNKNOWN)
  71. strcpy(buf, "unknown");
  72. if (val == S_BOOLEAN)
  73. strcpy(buf, "boolean");
  74. if (val == S_TRISTATE)
  75. strcpy(buf, "tristate");
  76. if (val == S_INT)
  77. strcpy(buf, "int");
  78. if (val == S_HEX)
  79. strcpy(buf, "hex");
  80. if (val == S_STRING)
  81. strcpy(buf, "string");
  82. if (val == S_OTHER)
  83. strcpy(buf, "other");
  84. #ifdef DEBUG
  85. printf("%s", buf);
  86. #endif
  87. return buf;
  88. }
  89. const char *dbg_print_flags(int val)
  90. {
  91. static char buf[256];
  92. bzero(buf, 256);
  93. if (val & SYMBOL_CONST)
  94. strcat(buf, "const/");
  95. if (val & SYMBOL_CHECK)
  96. strcat(buf, "check/");
  97. if (val & SYMBOL_CHOICE)
  98. strcat(buf, "choice/");
  99. if (val & SYMBOL_CHOICEVAL)
  100. strcat(buf, "choiceval/");
  101. if (val & SYMBOL_PRINTED)
  102. strcat(buf, "printed/");
  103. if (val & SYMBOL_VALID)
  104. strcat(buf, "valid/");
  105. if (val & SYMBOL_OPTIONAL)
  106. strcat(buf, "optional/");
  107. if (val & SYMBOL_WRITE)
  108. strcat(buf, "write/");
  109. if (val & SYMBOL_CHANGED)
  110. strcat(buf, "changed/");
  111. if (val & SYMBOL_AUTO)
  112. strcat(buf, "auto/");
  113. buf[strlen(buf) - 1] = '\0';
  114. #ifdef DEBUG
  115. printf("%s", buf);
  116. #endif
  117. return buf;
  118. }
  119. const char *dbg_print_ptype(int val)
  120. {
  121. static char buf[256];
  122. bzero(buf, 256);
  123. if (val == P_UNKNOWN)
  124. strcpy(buf, "unknown");
  125. if (val == P_PROMPT)
  126. strcpy(buf, "prompt");
  127. if (val == P_COMMENT)
  128. strcpy(buf, "comment");
  129. if (val == P_MENU)
  130. strcpy(buf, "menu");
  131. if (val == P_DEFAULT)
  132. strcpy(buf, "default");
  133. if (val == P_CHOICE)
  134. strcpy(buf, "choice");
  135. #ifdef DEBUG
  136. printf("%s", buf);
  137. #endif
  138. return buf;
  139. }
  140. void replace_button_icon(GladeXML * xml, GdkDrawable * window,
  141. GtkStyle * style, gchar * btn_name, gchar ** xpm)
  142. {
  143. GdkPixmap *pixmap;
  144. GdkBitmap *mask;
  145. GtkToolButton *button;
  146. GtkWidget *image;
  147. pixmap = gdk_pixmap_create_from_xpm_d(window, &mask,
  148. &style->bg[GTK_STATE_NORMAL],
  149. xpm);
  150. button = GTK_TOOL_BUTTON(glade_xml_get_widget(xml, btn_name));
  151. image = gtk_image_new_from_pixmap(pixmap, mask);
  152. gtk_widget_show(image);
  153. gtk_tool_button_set_icon_widget(button, image);
  154. }
  155. /* Main Window Initialization */
  156. void init_main_window(const gchar * glade_file)
  157. {
  158. GladeXML *xml;
  159. GtkWidget *widget;
  160. GtkTextBuffer *txtbuf;
  161. char title[256];
  162. GtkStyle *style;
  163. xml = glade_xml_new(glade_file, "window1", NULL);
  164. if (!xml)
  165. g_error(_("GUI loading failed !\n"));
  166. glade_xml_signal_autoconnect(xml);
  167. main_wnd = glade_xml_get_widget(xml, "window1");
  168. hpaned = glade_xml_get_widget(xml, "hpaned1");
  169. vpaned = glade_xml_get_widget(xml, "vpaned1");
  170. tree1_w = glade_xml_get_widget(xml, "treeview1");
  171. tree2_w = glade_xml_get_widget(xml, "treeview2");
  172. text_w = glade_xml_get_widget(xml, "textview3");
  173. back_btn = glade_xml_get_widget(xml, "button1");
  174. gtk_widget_set_sensitive(back_btn, FALSE);
  175. widget = glade_xml_get_widget(xml, "show_name1");
  176. gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
  177. show_name);
  178. widget = glade_xml_get_widget(xml, "show_range1");
  179. gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
  180. show_range);
  181. widget = glade_xml_get_widget(xml, "show_data1");
  182. gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
  183. show_value);
  184. save_btn = glade_xml_get_widget(xml, "button3");
  185. save_menu_item = glade_xml_get_widget(xml, "save1");
  186. conf_set_changed_callback(conf_changed);
  187. style = gtk_widget_get_style(main_wnd);
  188. widget = glade_xml_get_widget(xml, "toolbar1");
  189. #if 0 /* Use stock Gtk icons instead */
  190. replace_button_icon(xml, main_wnd->window, style,
  191. "button1", (gchar **) xpm_back);
  192. replace_button_icon(xml, main_wnd->window, style,
  193. "button2", (gchar **) xpm_load);
  194. replace_button_icon(xml, main_wnd->window, style,
  195. "button3", (gchar **) xpm_save);
  196. #endif
  197. replace_button_icon(xml, main_wnd->window, style,
  198. "button4", (gchar **) xpm_single_view);
  199. replace_button_icon(xml, main_wnd->window, style,
  200. "button5", (gchar **) xpm_split_view);
  201. replace_button_icon(xml, main_wnd->window, style,
  202. "button6", (gchar **) xpm_tree_view);
  203. #if 0
  204. switch (view_mode) {
  205. case SINGLE_VIEW:
  206. widget = glade_xml_get_widget(xml, "button4");
  207. g_signal_emit_by_name(widget, "clicked");
  208. break;
  209. case SPLIT_VIEW:
  210. widget = glade_xml_get_widget(xml, "button5");
  211. g_signal_emit_by_name(widget, "clicked");
  212. break;
  213. case FULL_VIEW:
  214. widget = glade_xml_get_widget(xml, "button6");
  215. g_signal_emit_by_name(widget, "clicked");
  216. break;
  217. }
  218. #endif
  219. txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w));
  220. tag1 = gtk_text_buffer_create_tag(txtbuf, "mytag1",
  221. "foreground", "red",
  222. "weight", PANGO_WEIGHT_BOLD,
  223. NULL);
  224. tag2 = gtk_text_buffer_create_tag(txtbuf, "mytag2",
  225. /*"style", PANGO_STYLE_OBLIQUE, */
  226. NULL);
  227. sprintf(title, _("uClibc v%s Configuration"),
  228. getenv("VERSION"));
  229. gtk_window_set_title(GTK_WINDOW(main_wnd), title);
  230. gtk_widget_show(main_wnd);
  231. }
  232. void init_tree_model(void)
  233. {
  234. gint i;
  235. tree = tree2 = gtk_tree_store_new(COL_NUMBER,
  236. G_TYPE_STRING, G_TYPE_STRING,
  237. G_TYPE_STRING, G_TYPE_STRING,
  238. G_TYPE_STRING, G_TYPE_STRING,
  239. G_TYPE_POINTER, GDK_TYPE_COLOR,
  240. G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF,
  241. G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
  242. G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
  243. G_TYPE_BOOLEAN);
  244. model2 = GTK_TREE_MODEL(tree2);
  245. for (parents[0] = NULL, i = 1; i < 256; i++)
  246. parents[i] = (GtkTreeIter *) g_malloc(sizeof(GtkTreeIter));
  247. tree1 = gtk_tree_store_new(COL_NUMBER,
  248. G_TYPE_STRING, G_TYPE_STRING,
  249. G_TYPE_STRING, G_TYPE_STRING,
  250. G_TYPE_STRING, G_TYPE_STRING,
  251. G_TYPE_POINTER, GDK_TYPE_COLOR,
  252. G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF,
  253. G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
  254. G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
  255. G_TYPE_BOOLEAN);
  256. model1 = GTK_TREE_MODEL(tree1);
  257. }
  258. void init_left_tree(void)
  259. {
  260. GtkTreeView *view = GTK_TREE_VIEW(tree1_w);
  261. GtkCellRenderer *renderer;
  262. GtkTreeSelection *sel;
  263. GtkTreeViewColumn *column;
  264. gtk_tree_view_set_model(view, model1);
  265. gtk_tree_view_set_headers_visible(view, TRUE);
  266. gtk_tree_view_set_rules_hint(view, FALSE);
  267. column = gtk_tree_view_column_new();
  268. gtk_tree_view_append_column(view, column);
  269. gtk_tree_view_column_set_title(column, _("Options"));
  270. renderer = gtk_cell_renderer_toggle_new();
  271. gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
  272. renderer, FALSE);
  273. gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
  274. renderer,
  275. "active", COL_BTNACT,
  276. "inconsistent", COL_BTNINC,
  277. "visible", COL_BTNVIS,
  278. "radio", COL_BTNRAD, NULL);
  279. renderer = gtk_cell_renderer_text_new();
  280. gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
  281. renderer, FALSE);
  282. gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
  283. renderer,
  284. "text", COL_OPTION,
  285. "foreground-gdk",
  286. COL_COLOR, NULL);
  287. sel = gtk_tree_view_get_selection(view);
  288. gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
  289. gtk_widget_realize(tree1_w);
  290. }
  291. static void renderer_edited(GtkCellRendererText * cell,
  292. const gchar * path_string,
  293. const gchar * new_text, gpointer user_data);
  294. static void renderer_toggled(GtkCellRendererToggle * cellrenderertoggle,
  295. gchar * arg1, gpointer user_data);
  296. void init_right_tree(void)
  297. {
  298. GtkTreeView *view = GTK_TREE_VIEW(tree2_w);
  299. GtkCellRenderer *renderer;
  300. GtkTreeSelection *sel;
  301. GtkTreeViewColumn *column;
  302. gint i;
  303. gtk_tree_view_set_model(view, model2);
  304. gtk_tree_view_set_headers_visible(view, TRUE);
  305. gtk_tree_view_set_rules_hint(view, FALSE);
  306. column = gtk_tree_view_column_new();
  307. gtk_tree_view_append_column(view, column);
  308. gtk_tree_view_column_set_title(column, _("Options"));
  309. renderer = gtk_cell_renderer_pixbuf_new();
  310. gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
  311. renderer, FALSE);
  312. gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
  313. renderer,
  314. "pixbuf", COL_PIXBUF,
  315. "visible", COL_PIXVIS, NULL);
  316. renderer = gtk_cell_renderer_toggle_new();
  317. gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
  318. renderer, FALSE);
  319. gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
  320. renderer,
  321. "active", COL_BTNACT,
  322. "inconsistent", COL_BTNINC,
  323. "visible", COL_BTNVIS,
  324. "radio", COL_BTNRAD, NULL);
  325. /*g_signal_connect(G_OBJECT(renderer), "toggled",
  326. G_CALLBACK(renderer_toggled), NULL); */
  327. renderer = gtk_cell_renderer_text_new();
  328. gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
  329. renderer, FALSE);
  330. gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
  331. renderer,
  332. "text", COL_OPTION,
  333. "foreground-gdk",
  334. COL_COLOR, NULL);
  335. renderer = gtk_cell_renderer_text_new();
  336. gtk_tree_view_insert_column_with_attributes(view, -1,
  337. _("Name"), renderer,
  338. "text", COL_NAME,
  339. "foreground-gdk",
  340. COL_COLOR, NULL);
  341. renderer = gtk_cell_renderer_text_new();
  342. gtk_tree_view_insert_column_with_attributes(view, -1,
  343. "N", renderer,
  344. "text", COL_NO,
  345. "foreground-gdk",
  346. COL_COLOR, NULL);
  347. renderer = gtk_cell_renderer_text_new();
  348. gtk_tree_view_insert_column_with_attributes(view, -1,
  349. "M", renderer,
  350. "text", COL_MOD,
  351. "foreground-gdk",
  352. COL_COLOR, NULL);
  353. renderer = gtk_cell_renderer_text_new();
  354. gtk_tree_view_insert_column_with_attributes(view, -1,
  355. "Y", renderer,
  356. "text", COL_YES,
  357. "foreground-gdk",
  358. COL_COLOR, NULL);
  359. renderer = gtk_cell_renderer_text_new();
  360. gtk_tree_view_insert_column_with_attributes(view, -1,
  361. _("Value"), renderer,
  362. "text", COL_VALUE,
  363. "editable",
  364. COL_EDIT,
  365. "foreground-gdk",
  366. COL_COLOR, NULL);
  367. g_signal_connect(G_OBJECT(renderer), "edited",
  368. G_CALLBACK(renderer_edited), NULL);
  369. column = gtk_tree_view_get_column(view, COL_NAME);
  370. gtk_tree_view_column_set_visible(column, show_name);
  371. column = gtk_tree_view_get_column(view, COL_NO);
  372. gtk_tree_view_column_set_visible(column, show_range);
  373. column = gtk_tree_view_get_column(view, COL_MOD);
  374. gtk_tree_view_column_set_visible(column, show_range);
  375. column = gtk_tree_view_get_column(view, COL_YES);
  376. gtk_tree_view_column_set_visible(column, show_range);
  377. column = gtk_tree_view_get_column(view, COL_VALUE);
  378. gtk_tree_view_column_set_visible(column, show_value);
  379. if (resizeable) {
  380. for (i = 0; i < COL_VALUE; i++) {
  381. column = gtk_tree_view_get_column(view, i);
  382. gtk_tree_view_column_set_resizable(column, TRUE);
  383. }
  384. }
  385. sel = gtk_tree_view_get_selection(view);
  386. gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
  387. }
  388. /* Utility Functions */
  389. static void text_insert_help(struct menu *menu)
  390. {
  391. GtkTextBuffer *buffer;
  392. GtkTextIter start, end;
  393. const char *prompt = menu_get_prompt(menu);
  394. gchar *name;
  395. const char *help = _(nohelp_text);
  396. if (!menu->sym)
  397. help = "";
  398. else if (menu->sym->help)
  399. help = _(menu->sym->help);
  400. if (menu->sym && menu->sym->name)
  401. name = g_strdup_printf(_(menu->sym->name));
  402. else
  403. name = g_strdup("");
  404. buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w));
  405. gtk_text_buffer_get_bounds(buffer, &start, &end);
  406. gtk_text_buffer_delete(buffer, &start, &end);
  407. gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_w), 15);
  408. gtk_text_buffer_get_end_iter(buffer, &end);
  409. gtk_text_buffer_insert_with_tags(buffer, &end, prompt, -1, tag1,
  410. NULL);
  411. gtk_text_buffer_insert_at_cursor(buffer, " ", 1);
  412. gtk_text_buffer_get_end_iter(buffer, &end);
  413. gtk_text_buffer_insert_with_tags(buffer, &end, name, -1, tag1,
  414. NULL);
  415. gtk_text_buffer_insert_at_cursor(buffer, "\n\n", 2);
  416. gtk_text_buffer_get_end_iter(buffer, &end);
  417. gtk_text_buffer_insert_with_tags(buffer, &end, help, -1, tag2,
  418. NULL);
  419. }
  420. static void text_insert_msg(const char *title, const char *message)
  421. {
  422. GtkTextBuffer *buffer;
  423. GtkTextIter start, end;
  424. const char *msg = message;
  425. buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w));
  426. gtk_text_buffer_get_bounds(buffer, &start, &end);
  427. gtk_text_buffer_delete(buffer, &start, &end);
  428. gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_w), 15);
  429. gtk_text_buffer_get_end_iter(buffer, &end);
  430. gtk_text_buffer_insert_with_tags(buffer, &end, title, -1, tag1,
  431. NULL);
  432. gtk_text_buffer_insert_at_cursor(buffer, "\n\n", 2);
  433. gtk_text_buffer_get_end_iter(buffer, &end);
  434. gtk_text_buffer_insert_with_tags(buffer, &end, msg, -1, tag2,
  435. NULL);
  436. }
  437. /* Main Windows Callbacks */
  438. void on_save_activate(GtkMenuItem * menuitem, gpointer user_data);
  439. gboolean on_window1_delete_event(GtkWidget * widget, GdkEvent * event,
  440. gpointer user_data)
  441. {
  442. GtkWidget *dialog, *label;
  443. gint result;
  444. if (!conf_get_changed())
  445. return FALSE;
  446. dialog = gtk_dialog_new_with_buttons(_("Warning !"),
  447. GTK_WINDOW(main_wnd),
  448. (GtkDialogFlags)
  449. (GTK_DIALOG_MODAL |
  450. GTK_DIALOG_DESTROY_WITH_PARENT),
  451. GTK_STOCK_OK,
  452. GTK_RESPONSE_YES,
  453. GTK_STOCK_NO,
  454. GTK_RESPONSE_NO,
  455. GTK_STOCK_CANCEL,
  456. GTK_RESPONSE_CANCEL, NULL);
  457. gtk_dialog_set_default_response(GTK_DIALOG(dialog),
  458. GTK_RESPONSE_CANCEL);
  459. label = gtk_label_new(_("\nSave configuration ?\n"));
  460. gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
  461. gtk_widget_show(label);
  462. result = gtk_dialog_run(GTK_DIALOG(dialog));
  463. switch (result) {
  464. case GTK_RESPONSE_YES:
  465. on_save_activate(NULL, NULL);
  466. return FALSE;
  467. case GTK_RESPONSE_NO:
  468. return FALSE;
  469. case GTK_RESPONSE_CANCEL:
  470. case GTK_RESPONSE_DELETE_EVENT:
  471. default:
  472. gtk_widget_destroy(dialog);
  473. return TRUE;
  474. }
  475. return FALSE;
  476. }
  477. void on_window1_destroy(GtkObject * object, gpointer user_data)
  478. {
  479. gtk_main_quit();
  480. }
  481. void
  482. on_window1_size_request(GtkWidget * widget,
  483. GtkRequisition * requisition, gpointer user_data)
  484. {
  485. static gint old_h;
  486. gint w, h;
  487. if (widget->window == NULL)
  488. gtk_window_get_default_size(GTK_WINDOW(main_wnd), &w, &h);
  489. else
  490. gdk_window_get_size(widget->window, &w, &h);
  491. if (h == old_h)
  492. return;
  493. old_h = h;
  494. gtk_paned_set_position(GTK_PANED(vpaned), 2 * h / 3);
  495. }
  496. /* Menu & Toolbar Callbacks */
  497. static void
  498. load_filename(GtkFileSelection * file_selector, gpointer user_data)
  499. {
  500. const gchar *fn;
  501. fn = gtk_file_selection_get_filename(GTK_FILE_SELECTION
  502. (user_data));
  503. if (conf_read(fn))
  504. text_insert_msg(_("Error"), _("Unable to load configuration !"));
  505. else
  506. display_tree(&rootmenu);
  507. }
  508. void on_load1_activate(GtkMenuItem * menuitem, gpointer user_data)
  509. {
  510. GtkWidget *fs;
  511. fs = gtk_file_selection_new(_("Load file..."));
  512. g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
  513. "clicked",
  514. G_CALLBACK(load_filename), (gpointer) fs);
  515. g_signal_connect_swapped(GTK_OBJECT
  516. (GTK_FILE_SELECTION(fs)->ok_button),
  517. "clicked", G_CALLBACK(gtk_widget_destroy),
  518. (gpointer) fs);
  519. g_signal_connect_swapped(GTK_OBJECT
  520. (GTK_FILE_SELECTION(fs)->cancel_button),
  521. "clicked", G_CALLBACK(gtk_widget_destroy),
  522. (gpointer) fs);
  523. gtk_widget_show(fs);
  524. }
  525. void on_save_activate(GtkMenuItem * menuitem, gpointer user_data)
  526. {
  527. if (conf_write(NULL))
  528. text_insert_msg(_("Error"), _("Unable to save configuration !"));
  529. }
  530. static void
  531. store_filename(GtkFileSelection * file_selector, gpointer user_data)
  532. {
  533. const gchar *fn;
  534. fn = gtk_file_selection_get_filename(GTK_FILE_SELECTION
  535. (user_data));
  536. if (conf_write(fn))
  537. text_insert_msg(_("Error"), _("Unable to save configuration !"));
  538. gtk_widget_destroy(GTK_WIDGET(user_data));
  539. }
  540. void on_save_as1_activate(GtkMenuItem * menuitem, gpointer user_data)
  541. {
  542. GtkWidget *fs;
  543. fs = gtk_file_selection_new(_("Save file as..."));
  544. g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
  545. "clicked",
  546. G_CALLBACK(store_filename), (gpointer) fs);
  547. g_signal_connect_swapped(GTK_OBJECT
  548. (GTK_FILE_SELECTION(fs)->ok_button),
  549. "clicked", G_CALLBACK(gtk_widget_destroy),
  550. (gpointer) fs);
  551. g_signal_connect_swapped(GTK_OBJECT
  552. (GTK_FILE_SELECTION(fs)->cancel_button),
  553. "clicked", G_CALLBACK(gtk_widget_destroy),
  554. (gpointer) fs);
  555. gtk_widget_show(fs);
  556. }
  557. void on_quit1_activate(GtkMenuItem * menuitem, gpointer user_data)
  558. {
  559. if (!on_window1_delete_event(NULL, NULL, NULL))
  560. gtk_widget_destroy(GTK_WIDGET(main_wnd));
  561. }
  562. void on_show_name1_activate(GtkMenuItem * menuitem, gpointer user_data)
  563. {
  564. GtkTreeViewColumn *col;
  565. show_name = GTK_CHECK_MENU_ITEM(menuitem)->active;
  566. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_NAME);
  567. if (col)
  568. gtk_tree_view_column_set_visible(col, show_name);
  569. }
  570. void on_show_range1_activate(GtkMenuItem * menuitem, gpointer user_data)
  571. {
  572. GtkTreeViewColumn *col;
  573. show_range = GTK_CHECK_MENU_ITEM(menuitem)->active;
  574. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_NO);
  575. if (col)
  576. gtk_tree_view_column_set_visible(col, show_range);
  577. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_MOD);
  578. if (col)
  579. gtk_tree_view_column_set_visible(col, show_range);
  580. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_YES);
  581. if (col)
  582. gtk_tree_view_column_set_visible(col, show_range);
  583. }
  584. void on_show_data1_activate(GtkMenuItem * menuitem, gpointer user_data)
  585. {
  586. GtkTreeViewColumn *col;
  587. show_value = GTK_CHECK_MENU_ITEM(menuitem)->active;
  588. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_VALUE);
  589. if (col)
  590. gtk_tree_view_column_set_visible(col, show_value);
  591. }
  592. void
  593. on_show_all_options1_activate(GtkMenuItem * menuitem, gpointer user_data)
  594. {
  595. show_all = GTK_CHECK_MENU_ITEM(menuitem)->active;
  596. gtk_tree_store_clear(tree2);
  597. display_tree(&rootmenu); // instead of update_tree to speed-up
  598. }
  599. void
  600. on_show_debug_info1_activate(GtkMenuItem * menuitem, gpointer user_data)
  601. {
  602. show_debug = GTK_CHECK_MENU_ITEM(menuitem)->active;
  603. update_tree(&rootmenu, NULL);
  604. }
  605. void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data)
  606. {
  607. GtkWidget *dialog;
  608. const gchar *intro_text = _(
  609. "Welcome to gkc, the GTK+ graphical kernel configuration tool\n"
  610. "for Linux.\n"
  611. "For each option, a blank box indicates the feature is disabled, a\n"
  612. "check indicates it is enabled, and a dot indicates that it is to\n"
  613. "be compiled as a module. Clicking on the box will cycle through the three states.\n"
  614. "\n"
  615. "If you do not see an option (e.g., a device driver) that you\n"
  616. "believe should be present, try turning on Show All Options\n"
  617. "under the Options menu.\n"
  618. "Although there is no cross reference yet to help you figure out\n"
  619. "what other options must be enabled to support the option you\n"
  620. "are interested in, you can still view the help of a grayed-out\n"
  621. "option.\n"
  622. "\n"
  623. "Toggling Show Debug Info under the Options menu will show \n"
  624. "the dependencies, which you can then match by examining other options.");
  625. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  626. GTK_DIALOG_DESTROY_WITH_PARENT,
  627. GTK_MESSAGE_INFO,
  628. GTK_BUTTONS_CLOSE, intro_text);
  629. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  630. G_CALLBACK(gtk_widget_destroy),
  631. GTK_OBJECT(dialog));
  632. gtk_widget_show_all(dialog);
  633. }
  634. void on_about1_activate(GtkMenuItem * menuitem, gpointer user_data)
  635. {
  636. GtkWidget *dialog;
  637. const gchar *about_text =
  638. _("gkc is copyright (c) 2002 Romain Lievin <roms@lpg.ticalc.org>.\n"
  639. "Based on the source code from Roman Zippel.\n");
  640. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  641. GTK_DIALOG_DESTROY_WITH_PARENT,
  642. GTK_MESSAGE_INFO,
  643. GTK_BUTTONS_CLOSE, about_text);
  644. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  645. G_CALLBACK(gtk_widget_destroy),
  646. GTK_OBJECT(dialog));
  647. gtk_widget_show_all(dialog);
  648. }
  649. void on_license1_activate(GtkMenuItem * menuitem, gpointer user_data)
  650. {
  651. GtkWidget *dialog;
  652. const gchar *license_text =
  653. _("gkc is released under the terms of the GNU GPL v2.\n"
  654. "For more information, please see the source code or\n"
  655. "visit http://www.fsf.org/licenses/licenses.html\n");
  656. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  657. GTK_DIALOG_DESTROY_WITH_PARENT,
  658. GTK_MESSAGE_INFO,
  659. GTK_BUTTONS_CLOSE, license_text);
  660. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  661. G_CALLBACK(gtk_widget_destroy),
  662. GTK_OBJECT(dialog));
  663. gtk_widget_show_all(dialog);
  664. }
  665. void on_back_clicked(GtkButton * button, gpointer user_data)
  666. {
  667. enum prop_type ptype;
  668. current = current->parent;
  669. ptype = current->prompt ? current->prompt->type : P_UNKNOWN;
  670. if (ptype != P_MENU)
  671. current = current->parent;
  672. display_tree_part();
  673. if (current == &rootmenu)
  674. gtk_widget_set_sensitive(back_btn, FALSE);
  675. }
  676. void on_load_clicked(GtkButton * button, gpointer user_data)
  677. {
  678. on_load1_activate(NULL, user_data);
  679. }
  680. void on_single_clicked(GtkButton * button, gpointer user_data)
  681. {
  682. view_mode = SINGLE_VIEW;
  683. gtk_paned_set_position(GTK_PANED(hpaned), 0);
  684. gtk_widget_hide(tree1_w);
  685. current = &rootmenu;
  686. display_tree_part();
  687. }
  688. void on_split_clicked(GtkButton * button, gpointer user_data)
  689. {
  690. gint w, h;
  691. view_mode = SPLIT_VIEW;
  692. gtk_widget_show(tree1_w);
  693. gtk_window_get_default_size(GTK_WINDOW(main_wnd), &w, &h);
  694. gtk_paned_set_position(GTK_PANED(hpaned), w / 2);
  695. if (tree2)
  696. gtk_tree_store_clear(tree2);
  697. display_list();
  698. /* Disable back btn, like in full mode. */
  699. gtk_widget_set_sensitive(back_btn, FALSE);
  700. }
  701. void on_full_clicked(GtkButton * button, gpointer user_data)
  702. {
  703. view_mode = FULL_VIEW;
  704. gtk_paned_set_position(GTK_PANED(hpaned), 0);
  705. gtk_widget_hide(tree1_w);
  706. if (tree2)
  707. gtk_tree_store_clear(tree2);
  708. display_tree(&rootmenu);
  709. gtk_widget_set_sensitive(back_btn, FALSE);
  710. }
  711. void on_collapse_clicked(GtkButton * button, gpointer user_data)
  712. {
  713. gtk_tree_view_collapse_all(GTK_TREE_VIEW(tree2_w));
  714. }
  715. void on_expand_clicked(GtkButton * button, gpointer user_data)
  716. {
  717. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w));
  718. }
  719. /* CTree Callbacks */
  720. /* Change hex/int/string value in the cell */
  721. static void renderer_edited(GtkCellRendererText * cell,
  722. const gchar * path_string,
  723. const gchar * new_text, gpointer user_data)
  724. {
  725. GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
  726. GtkTreeIter iter;
  727. const char *old_def, *new_def;
  728. struct menu *menu;
  729. struct symbol *sym;
  730. if (!gtk_tree_model_get_iter(model2, &iter, path))
  731. return;
  732. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  733. sym = menu->sym;
  734. gtk_tree_model_get(model2, &iter, COL_VALUE, &old_def, -1);
  735. new_def = new_text;
  736. sym_set_string_value(sym, new_def);
  737. update_tree(&rootmenu, NULL);
  738. gtk_tree_path_free(path);
  739. }
  740. /* Change the value of a symbol and update the tree */
  741. static void change_sym_value(struct menu *menu, gint col)
  742. {
  743. struct symbol *sym = menu->sym;
  744. tristate oldval, newval;
  745. if (!sym)
  746. return;
  747. if (col == COL_NO)
  748. newval = no;
  749. else if (col == COL_MOD)
  750. newval = mod;
  751. else if (col == COL_YES)
  752. newval = yes;
  753. else
  754. return;
  755. switch (sym_get_type(sym)) {
  756. case S_BOOLEAN:
  757. case S_TRISTATE:
  758. oldval = sym_get_tristate_value(sym);
  759. if (!sym_tristate_within_range(sym, newval))
  760. newval = yes;
  761. sym_set_tristate_value(sym, newval);
  762. if (view_mode == FULL_VIEW)
  763. update_tree(&rootmenu, NULL);
  764. else if (view_mode == SPLIT_VIEW) {
  765. update_tree(browsed, NULL);
  766. display_list();
  767. }
  768. else if (view_mode == SINGLE_VIEW)
  769. display_tree_part(); //fixme: keep exp/coll
  770. break;
  771. case S_INT:
  772. case S_HEX:
  773. case S_STRING:
  774. default:
  775. break;
  776. }
  777. }
  778. static void toggle_sym_value(struct menu *menu)
  779. {
  780. if (!menu->sym)
  781. return;
  782. sym_toggle_tristate_value(menu->sym);
  783. if (view_mode == FULL_VIEW)
  784. update_tree(&rootmenu, NULL);
  785. else if (view_mode == SPLIT_VIEW) {
  786. update_tree(browsed, NULL);
  787. display_list();
  788. }
  789. else if (view_mode == SINGLE_VIEW)
  790. display_tree_part(); //fixme: keep exp/coll
  791. }
  792. static void renderer_toggled(GtkCellRendererToggle * cell,
  793. gchar * path_string, gpointer user_data)
  794. {
  795. GtkTreePath *path, *sel_path = NULL;
  796. GtkTreeIter iter, sel_iter;
  797. GtkTreeSelection *sel;
  798. struct menu *menu;
  799. path = gtk_tree_path_new_from_string(path_string);
  800. if (!gtk_tree_model_get_iter(model2, &iter, path))
  801. return;
  802. sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree2_w));
  803. if (gtk_tree_selection_get_selected(sel, NULL, &sel_iter))
  804. sel_path = gtk_tree_model_get_path(model2, &sel_iter);
  805. if (!sel_path)
  806. goto out1;
  807. if (gtk_tree_path_compare(path, sel_path))
  808. goto out2;
  809. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  810. toggle_sym_value(menu);
  811. out2:
  812. gtk_tree_path_free(sel_path);
  813. out1:
  814. gtk_tree_path_free(path);
  815. }
  816. static gint column2index(GtkTreeViewColumn * column)
  817. {
  818. gint i;
  819. for (i = 0; i < COL_NUMBER; i++) {
  820. GtkTreeViewColumn *col;
  821. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), i);
  822. if (col == column)
  823. return i;
  824. }
  825. return -1;
  826. }
  827. /* User click: update choice (full) or goes down (single) */
  828. gboolean
  829. on_treeview2_button_press_event(GtkWidget * widget,
  830. GdkEventButton * event, gpointer user_data)
  831. {
  832. GtkTreeView *view = GTK_TREE_VIEW(widget);
  833. GtkTreePath *path;
  834. GtkTreeViewColumn *column;
  835. GtkTreeIter iter;
  836. struct menu *menu;
  837. gint col;
  838. #if GTK_CHECK_VERSION(2,1,4) // bug in ctree with earlier version of GTK
  839. gint tx = (gint) event->x;
  840. gint ty = (gint) event->y;
  841. gint cx, cy;
  842. gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx,
  843. &cy);
  844. #else
  845. gtk_tree_view_get_cursor(view, &path, &column);
  846. #endif
  847. if (path == NULL)
  848. return FALSE;
  849. if (!gtk_tree_model_get_iter(model2, &iter, path))
  850. return FALSE;
  851. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  852. col = column2index(column);
  853. if (event->type == GDK_2BUTTON_PRESS) {
  854. enum prop_type ptype;
  855. ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  856. if (ptype == P_MENU && view_mode != FULL_VIEW && col == COL_OPTION) {
  857. // goes down into menu
  858. current = menu;
  859. display_tree_part();
  860. gtk_widget_set_sensitive(back_btn, TRUE);
  861. } else if ((col == COL_OPTION)) {
  862. toggle_sym_value(menu);
  863. gtk_tree_view_expand_row(view, path, TRUE);
  864. }
  865. } else {
  866. if (col == COL_VALUE) {
  867. toggle_sym_value(menu);
  868. gtk_tree_view_expand_row(view, path, TRUE);
  869. } else if (col == COL_NO || col == COL_MOD
  870. || col == COL_YES) {
  871. change_sym_value(menu, col);
  872. gtk_tree_view_expand_row(view, path, TRUE);
  873. }
  874. }
  875. return FALSE;
  876. }
  877. /* Key pressed: update choice */
  878. gboolean
  879. on_treeview2_key_press_event(GtkWidget * widget,
  880. GdkEventKey * event, gpointer user_data)
  881. {
  882. GtkTreeView *view = GTK_TREE_VIEW(widget);
  883. GtkTreePath *path;
  884. GtkTreeViewColumn *column;
  885. GtkTreeIter iter;
  886. struct menu *menu;
  887. gint col;
  888. gtk_tree_view_get_cursor(view, &path, &column);
  889. if (path == NULL)
  890. return FALSE;
  891. if (event->keyval == GDK_space) {
  892. if (gtk_tree_view_row_expanded(view, path))
  893. gtk_tree_view_collapse_row(view, path);
  894. else
  895. gtk_tree_view_expand_row(view, path, FALSE);
  896. return TRUE;
  897. }
  898. if (event->keyval == GDK_KP_Enter) {
  899. }
  900. if (widget == tree1_w)
  901. return FALSE;
  902. gtk_tree_model_get_iter(model2, &iter, path);
  903. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  904. if (!strcasecmp(event->string, "n"))
  905. col = COL_NO;
  906. else if (!strcasecmp(event->string, "m"))
  907. col = COL_MOD;
  908. else if (!strcasecmp(event->string, "y"))
  909. col = COL_YES;
  910. else
  911. col = -1;
  912. change_sym_value(menu, col);
  913. return FALSE;
  914. }
  915. /* Row selection changed: update help */
  916. void
  917. on_treeview2_cursor_changed(GtkTreeView * treeview, gpointer user_data)
  918. {
  919. GtkTreeSelection *selection;
  920. GtkTreeIter iter;
  921. struct menu *menu;
  922. selection = gtk_tree_view_get_selection(treeview);
  923. if (gtk_tree_selection_get_selected(selection, &model2, &iter)) {
  924. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  925. text_insert_help(menu);
  926. }
  927. }
  928. /* User click: display sub-tree in the right frame. */
  929. gboolean
  930. on_treeview1_button_press_event(GtkWidget * widget,
  931. GdkEventButton * event, gpointer user_data)
  932. {
  933. GtkTreeView *view = GTK_TREE_VIEW(widget);
  934. GtkTreePath *path;
  935. GtkTreeViewColumn *column;
  936. GtkTreeIter iter;
  937. struct menu *menu;
  938. gint tx = (gint) event->x;
  939. gint ty = (gint) event->y;
  940. gint cx, cy;
  941. gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx,
  942. &cy);
  943. if (path == NULL)
  944. return FALSE;
  945. gtk_tree_model_get_iter(model1, &iter, path);
  946. gtk_tree_model_get(model1, &iter, COL_MENU, &menu, -1);
  947. if (event->type == GDK_2BUTTON_PRESS) {
  948. toggle_sym_value(menu);
  949. current = menu;
  950. display_tree_part();
  951. } else {
  952. browsed = menu;
  953. display_tree_part();
  954. }
  955. gtk_widget_realize(tree2_w);
  956. gtk_tree_view_set_cursor(view, path, NULL, FALSE);
  957. gtk_widget_grab_focus(tree2_w);
  958. return FALSE;
  959. }
  960. /* Fill a row of strings */
  961. static gchar **fill_row(struct menu *menu)
  962. {
  963. static gchar *row[COL_NUMBER];
  964. struct symbol *sym = menu->sym;
  965. const char *def;
  966. int stype;
  967. tristate val;
  968. enum prop_type ptype;
  969. int i;
  970. for (i = COL_OPTION; i <= COL_COLOR; i++)
  971. g_free(row[i]);
  972. bzero(row, sizeof(row));
  973. row[COL_OPTION] =
  974. g_strdup_printf("%s %s", menu_get_prompt(menu),
  975. sym && sym_has_value(sym) ? "(NEW)" : "");
  976. if (show_all && !menu_is_visible(menu))
  977. row[COL_COLOR] = g_strdup("DarkGray");
  978. else
  979. row[COL_COLOR] = g_strdup("Black");
  980. ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  981. switch (ptype) {
  982. case P_MENU:
  983. row[COL_PIXBUF] = (gchar *) xpm_menu;
  984. if (view_mode == SINGLE_VIEW)
  985. row[COL_PIXVIS] = GINT_TO_POINTER(TRUE);
  986. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  987. break;
  988. case P_COMMENT:
  989. row[COL_PIXBUF] = (gchar *) xpm_void;
  990. row[COL_PIXVIS] = GINT_TO_POINTER(FALSE);
  991. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  992. break;
  993. default:
  994. row[COL_PIXBUF] = (gchar *) xpm_void;
  995. row[COL_PIXVIS] = GINT_TO_POINTER(FALSE);
  996. row[COL_BTNVIS] = GINT_TO_POINTER(TRUE);
  997. break;
  998. }
  999. if (!sym)
  1000. return row;
  1001. row[COL_NAME] = g_strdup(sym->name);
  1002. sym_calc_value(sym);
  1003. sym->flags &= ~SYMBOL_CHANGED;
  1004. if (sym_is_choice(sym)) { // parse childs for getting final value
  1005. struct menu *child;
  1006. struct symbol *def_sym = sym_get_choice_value(sym);
  1007. struct menu *def_menu = NULL;
  1008. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  1009. for (child = menu->list; child; child = child->next) {
  1010. if (menu_is_visible(child)
  1011. && child->sym == def_sym)
  1012. def_menu = child;
  1013. }
  1014. if (def_menu)
  1015. row[COL_VALUE] =
  1016. g_strdup(menu_get_prompt(def_menu));
  1017. }
  1018. if (sym->flags & SYMBOL_CHOICEVAL)
  1019. row[COL_BTNRAD] = GINT_TO_POINTER(TRUE);
  1020. stype = sym_get_type(sym);
  1021. switch (stype) {
  1022. case S_BOOLEAN:
  1023. if (GPOINTER_TO_INT(row[COL_PIXVIS]) == FALSE)
  1024. row[COL_BTNVIS] = GINT_TO_POINTER(TRUE);
  1025. if (sym_is_choice(sym))
  1026. break;
  1027. case S_TRISTATE:
  1028. val = sym_get_tristate_value(sym);
  1029. switch (val) {
  1030. case no:
  1031. row[COL_NO] = g_strdup("N");
  1032. row[COL_VALUE] = g_strdup("N");
  1033. row[COL_BTNACT] = GINT_TO_POINTER(FALSE);
  1034. row[COL_BTNINC] = GINT_TO_POINTER(FALSE);
  1035. break;
  1036. case mod:
  1037. row[COL_MOD] = g_strdup("M");
  1038. row[COL_VALUE] = g_strdup("M");
  1039. row[COL_BTNINC] = GINT_TO_POINTER(TRUE);
  1040. break;
  1041. case yes:
  1042. row[COL_YES] = g_strdup("Y");
  1043. row[COL_VALUE] = g_strdup("Y");
  1044. row[COL_BTNACT] = GINT_TO_POINTER(TRUE);
  1045. row[COL_BTNINC] = GINT_TO_POINTER(FALSE);
  1046. break;
  1047. }
  1048. if (val != no && sym_tristate_within_range(sym, no))
  1049. row[COL_NO] = g_strdup("_");
  1050. if (val != mod && sym_tristate_within_range(sym, mod))
  1051. row[COL_MOD] = g_strdup("_");
  1052. if (val != yes && sym_tristate_within_range(sym, yes))
  1053. row[COL_YES] = g_strdup("_");
  1054. break;
  1055. case S_INT:
  1056. case S_HEX:
  1057. case S_STRING:
  1058. def = sym_get_string_value(sym);
  1059. row[COL_VALUE] = g_strdup(def);
  1060. row[COL_EDIT] = GINT_TO_POINTER(TRUE);
  1061. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  1062. break;
  1063. }
  1064. return row;
  1065. }
  1066. /* Set the node content with a row of strings */
  1067. static void set_node(GtkTreeIter * node, struct menu *menu, gchar ** row)
  1068. {
  1069. GdkColor color;
  1070. gboolean success;
  1071. GdkPixbuf *pix;
  1072. pix = gdk_pixbuf_new_from_xpm_data((const char **)
  1073. row[COL_PIXBUF]);
  1074. gdk_color_parse(row[COL_COLOR], &color);
  1075. gdk_colormap_alloc_colors(gdk_colormap_get_system(), &color, 1,
  1076. FALSE, FALSE, &success);
  1077. gtk_tree_store_set(tree, node,
  1078. COL_OPTION, row[COL_OPTION],
  1079. COL_NAME, row[COL_NAME],
  1080. COL_NO, row[COL_NO],
  1081. COL_MOD, row[COL_MOD],
  1082. COL_YES, row[COL_YES],
  1083. COL_VALUE, row[COL_VALUE],
  1084. COL_MENU, (gpointer) menu,
  1085. COL_COLOR, &color,
  1086. COL_EDIT, GPOINTER_TO_INT(row[COL_EDIT]),
  1087. COL_PIXBUF, pix,
  1088. COL_PIXVIS, GPOINTER_TO_INT(row[COL_PIXVIS]),
  1089. COL_BTNVIS, GPOINTER_TO_INT(row[COL_BTNVIS]),
  1090. COL_BTNACT, GPOINTER_TO_INT(row[COL_BTNACT]),
  1091. COL_BTNINC, GPOINTER_TO_INT(row[COL_BTNINC]),
  1092. COL_BTNRAD, GPOINTER_TO_INT(row[COL_BTNRAD]),
  1093. -1);
  1094. g_object_unref(pix);
  1095. }
  1096. /* Add a node to the tree */
  1097. static void place_node(struct menu *menu, char **row)
  1098. {
  1099. GtkTreeIter *parent = parents[indent - 1];
  1100. GtkTreeIter *node = parents[indent];
  1101. gtk_tree_store_append(tree, node, parent);
  1102. set_node(node, menu, row);
  1103. }
  1104. /* Find a node in the GTK+ tree */
  1105. static GtkTreeIter found;
  1106. /*
  1107. * Find a menu in the GtkTree starting at parent.
  1108. */
  1109. GtkTreeIter *gtktree_iter_find_node(GtkTreeIter * parent,
  1110. struct menu *tofind)
  1111. {
  1112. GtkTreeIter iter;
  1113. GtkTreeIter *child = &iter;
  1114. gboolean valid;
  1115. GtkTreeIter *ret;
  1116. valid = gtk_tree_model_iter_children(model2, child, parent);
  1117. while (valid) {
  1118. struct menu *menu;
  1119. gtk_tree_model_get(model2, child, 6, &menu, -1);
  1120. if (menu == tofind) {
  1121. memcpy(&found, child, sizeof(GtkTreeIter));
  1122. return &found;
  1123. }
  1124. ret = gtktree_iter_find_node(child, tofind);
  1125. if (ret)
  1126. return ret;
  1127. valid = gtk_tree_model_iter_next(model2, child);
  1128. }
  1129. return NULL;
  1130. }
  1131. /*
  1132. * Update the tree by adding/removing entries
  1133. * Does not change other nodes
  1134. */
  1135. static void update_tree(struct menu *src, GtkTreeIter * dst)
  1136. {
  1137. struct menu *child1;
  1138. GtkTreeIter iter, tmp;
  1139. GtkTreeIter *child2 = &iter;
  1140. gboolean valid;
  1141. GtkTreeIter *sibling;
  1142. struct symbol *sym;
  1143. struct property *prop;
  1144. struct menu *menu1, *menu2;
  1145. if (src == &rootmenu)
  1146. indent = 1;
  1147. valid = gtk_tree_model_iter_children(model2, child2, dst);
  1148. for (child1 = src->list; child1; child1 = child1->next) {
  1149. prop = child1->prompt;
  1150. sym = child1->sym;
  1151. reparse:
  1152. menu1 = child1;
  1153. if (valid)
  1154. gtk_tree_model_get(model2, child2, COL_MENU,
  1155. &menu2, -1);
  1156. else
  1157. menu2 = NULL; // force adding of a first child
  1158. #ifdef DEBUG
  1159. printf("%*c%s | %s\n", indent, ' ',
  1160. menu1 ? menu_get_prompt(menu1) : "nil",
  1161. menu2 ? menu_get_prompt(menu2) : "nil");
  1162. #endif
  1163. if (!menu_is_visible(child1) && !show_all) { // remove node
  1164. if (gtktree_iter_find_node(dst, menu1) != NULL) {
  1165. memcpy(&tmp, child2, sizeof(GtkTreeIter));
  1166. valid = gtk_tree_model_iter_next(model2,
  1167. child2);
  1168. gtk_tree_store_remove(tree2, &tmp);
  1169. if (!valid)
  1170. return; // next parent
  1171. else
  1172. goto reparse; // next child
  1173. } else
  1174. continue;
  1175. }
  1176. if (menu1 != menu2) {
  1177. if (gtktree_iter_find_node(dst, menu1) == NULL) { // add node
  1178. if (!valid && !menu2)
  1179. sibling = NULL;
  1180. else
  1181. sibling = child2;
  1182. gtk_tree_store_insert_before(tree2,
  1183. child2,
  1184. dst, sibling);
  1185. set_node(child2, menu1, fill_row(menu1));
  1186. if (menu2 == NULL)
  1187. valid = TRUE;
  1188. } else { // remove node
  1189. memcpy(&tmp, child2, sizeof(GtkTreeIter));
  1190. valid = gtk_tree_model_iter_next(model2,
  1191. child2);
  1192. gtk_tree_store_remove(tree2, &tmp);
  1193. if (!valid)
  1194. return; // next parent
  1195. else
  1196. goto reparse; // next child
  1197. }
  1198. } else if (sym && (sym->flags & SYMBOL_CHANGED)) {
  1199. set_node(child2, menu1, fill_row(menu1));
  1200. }
  1201. indent++;
  1202. update_tree(child1, child2);
  1203. indent--;
  1204. valid = gtk_tree_model_iter_next(model2, child2);
  1205. }
  1206. }
  1207. /* Display the whole tree (single/split/full view) */
  1208. static void display_tree(struct menu *menu)
  1209. {
  1210. struct symbol *sym;
  1211. struct property *prop;
  1212. struct menu *child;
  1213. enum prop_type ptype;
  1214. if (menu == &rootmenu) {
  1215. indent = 1;
  1216. current = &rootmenu;
  1217. }
  1218. for (child = menu->list; child; child = child->next) {
  1219. prop = child->prompt;
  1220. sym = child->sym;
  1221. ptype = prop ? prop->type : P_UNKNOWN;
  1222. if (sym)
  1223. sym->flags &= ~SYMBOL_CHANGED;
  1224. if ((view_mode == SPLIT_VIEW)
  1225. && !(child->flags & MENU_ROOT) && (tree == tree1))
  1226. continue;
  1227. if ((view_mode == SPLIT_VIEW) && (child->flags & MENU_ROOT)
  1228. && (tree == tree2))
  1229. continue;
  1230. if (menu_is_visible(child) || show_all)
  1231. place_node(child, fill_row(child));
  1232. #ifdef DEBUG
  1233. printf("%*c%s: ", indent, ' ', menu_get_prompt(child));
  1234. printf("%s", child->flags & MENU_ROOT ? "rootmenu | " : "");
  1235. dbg_print_ptype(ptype);
  1236. printf(" | ");
  1237. if (sym) {
  1238. dbg_print_stype(sym->type);
  1239. printf(" | ");
  1240. dbg_print_flags(sym->flags);
  1241. printf("\n");
  1242. } else
  1243. printf("\n");
  1244. #endif
  1245. if ((view_mode != FULL_VIEW) && (ptype == P_MENU)
  1246. && (tree == tree2))
  1247. continue;
  1248. /*
  1249. if (((menu != &rootmenu) && !(menu->flags & MENU_ROOT))
  1250. || (view_mode == FULL_VIEW)
  1251. || (view_mode == SPLIT_VIEW))*/
  1252. if (((view_mode == SINGLE_VIEW) && (menu->flags & MENU_ROOT))
  1253. || (view_mode == FULL_VIEW)
  1254. || (view_mode == SPLIT_VIEW)) {
  1255. indent++;
  1256. display_tree(child);
  1257. indent--;
  1258. }
  1259. }
  1260. }
  1261. /* Display a part of the tree starting at current node (single/split view) */
  1262. static void display_tree_part(void)
  1263. {
  1264. if (tree2)
  1265. gtk_tree_store_clear(tree2);
  1266. if (view_mode == SINGLE_VIEW)
  1267. display_tree(current);
  1268. else if (view_mode == SPLIT_VIEW)
  1269. display_tree(browsed);
  1270. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w));
  1271. }
  1272. /* Display the list in the left frame (split view) */
  1273. static void display_list(void)
  1274. {
  1275. if (tree1)
  1276. gtk_tree_store_clear(tree1);
  1277. tree = tree1;
  1278. display_tree(&rootmenu);
  1279. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree1_w));
  1280. tree = tree2;
  1281. }
  1282. void fixup_rootmenu(struct menu *menu)
  1283. {
  1284. struct menu *child;
  1285. static int menu_cnt = 0;
  1286. menu->flags |= MENU_ROOT;
  1287. for (child = menu->list; child; child = child->next) {
  1288. if (child->prompt && child->prompt->type == P_MENU) {
  1289. menu_cnt++;
  1290. fixup_rootmenu(child);
  1291. menu_cnt--;
  1292. } else if (!menu_cnt)
  1293. fixup_rootmenu(child);
  1294. }
  1295. }
  1296. /* Main */
  1297. int main(int ac, char *av[])
  1298. {
  1299. const char *name;
  1300. char *env;
  1301. gchar *glade_file;
  1302. #ifndef LKC_DIRECT_LINK
  1303. kconfig_load();
  1304. #endif
  1305. bindtextdomain(PACKAGE, LOCALEDIR);
  1306. bind_textdomain_codeset(PACKAGE, "UTF-8");
  1307. textdomain(PACKAGE);
  1308. /* GTK stuffs */
  1309. gtk_set_locale();
  1310. gtk_init(&ac, &av);
  1311. glade_init();
  1312. //add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
  1313. //add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
  1314. /* Determine GUI path */
  1315. env = getenv(SRCTREE);
  1316. if (env)
  1317. glade_file = g_strconcat(env, "/scripts/kconfig/gconf.glade", NULL);
  1318. else if (av[0][0] == '/')
  1319. glade_file = g_strconcat(av[0], ".glade", NULL);
  1320. else
  1321. glade_file = g_strconcat(g_get_current_dir(), "/", av[0], ".glade", NULL);
  1322. /* Load the interface and connect signals */
  1323. init_main_window(glade_file);
  1324. init_tree_model();
  1325. init_left_tree();
  1326. init_right_tree();
  1327. /* Conf stuffs */
  1328. if (ac > 1 && av[1][0] == '-') {
  1329. switch (av[1][1]) {
  1330. case 'a':
  1331. //showAll = 1;
  1332. break;
  1333. case 'h':
  1334. case '?':
  1335. printf("%s <config>\n", av[0]);
  1336. exit(0);
  1337. }
  1338. name = av[2];
  1339. } else
  1340. name = av[1];
  1341. conf_parse(name);
  1342. fixup_rootmenu(&rootmenu);
  1343. conf_read(NULL);
  1344. switch (view_mode) {
  1345. case SINGLE_VIEW:
  1346. display_tree_part();
  1347. break;
  1348. case SPLIT_VIEW:
  1349. display_list();
  1350. break;
  1351. case FULL_VIEW:
  1352. display_tree(&rootmenu);
  1353. break;
  1354. }
  1355. gtk_main();
  1356. return 0;
  1357. }
  1358. static void conf_changed(void)
  1359. {
  1360. bool changed = conf_get_changed();
  1361. gtk_widget_set_sensitive(save_btn, changed);
  1362. gtk_widget_set_sensitive(save_menu_item, changed);
  1363. }