3
0

gconf.c 41 KB

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