gconf.c 40 KB

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