gconf.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644
  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, _("BusyBox %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 configuration tool.\n"
  614. "For each option, a blank box indicates the feature is disabled, a\n"
  615. "check indicates it is enabled, and a dot indicates that it is to\n"
  616. "be compiled as a module. Clicking on the box will cycle through the three states.\n"
  617. "\n"
  618. "If you do not see an option (e.g., a device driver) that you\n"
  619. "believe should be present, try turning on Show All Options\n"
  620. "under the Options menu.\n"
  621. "Although there is no cross reference yet to help you figure out\n"
  622. "what other options must be enabled to support the option you\n"
  623. "are interested in, you can still view the help of a grayed-out\n"
  624. "option.\n"
  625. "\n"
  626. "Toggling Show Debug Info under the Options menu will show\n"
  627. "the dependencies, which you can then match by examining other options.");
  628. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  629. GTK_DIALOG_DESTROY_WITH_PARENT,
  630. GTK_MESSAGE_INFO,
  631. GTK_BUTTONS_CLOSE, intro_text);
  632. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  633. G_CALLBACK(gtk_widget_destroy),
  634. GTK_OBJECT(dialog));
  635. gtk_widget_show_all(dialog);
  636. }
  637. void on_about1_activate(GtkMenuItem * menuitem, gpointer user_data)
  638. {
  639. GtkWidget *dialog;
  640. const gchar *about_text =
  641. _("gkc is copyright (c) 2002 Romain Lievin <roms@lpg.ticalc.org>.\n"
  642. "Based on the source code from Roman Zippel.\n");
  643. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  644. GTK_DIALOG_DESTROY_WITH_PARENT,
  645. GTK_MESSAGE_INFO,
  646. GTK_BUTTONS_CLOSE, about_text);
  647. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  648. G_CALLBACK(gtk_widget_destroy),
  649. GTK_OBJECT(dialog));
  650. gtk_widget_show_all(dialog);
  651. }
  652. void on_license1_activate(GtkMenuItem * menuitem, gpointer user_data)
  653. {
  654. GtkWidget *dialog;
  655. const gchar *license_text =
  656. _("gkc is released under the terms of the GNU GPL v2.\n"
  657. "For more information, please see the source code or\n"
  658. "visit http://www.fsf.org/licenses/licenses.html\n");
  659. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  660. GTK_DIALOG_DESTROY_WITH_PARENT,
  661. GTK_MESSAGE_INFO,
  662. GTK_BUTTONS_CLOSE, license_text);
  663. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  664. G_CALLBACK(gtk_widget_destroy),
  665. GTK_OBJECT(dialog));
  666. gtk_widget_show_all(dialog);
  667. }
  668. void on_back_clicked(GtkButton * button, gpointer user_data)
  669. {
  670. enum prop_type ptype;
  671. current = current->parent;
  672. ptype = current->prompt ? current->prompt->type : P_UNKNOWN;
  673. if (ptype != P_MENU)
  674. current = current->parent;
  675. display_tree_part();
  676. if (current == &rootmenu)
  677. gtk_widget_set_sensitive(back_btn, FALSE);
  678. }
  679. void on_load_clicked(GtkButton * button, gpointer user_data)
  680. {
  681. on_load1_activate(NULL, user_data);
  682. }
  683. void on_save_clicked(GtkButton * button, gpointer user_data)
  684. {
  685. on_save1_activate(NULL, user_data);
  686. }
  687. void on_single_clicked(GtkButton * button, gpointer user_data)
  688. {
  689. view_mode = SINGLE_VIEW;
  690. gtk_paned_set_position(GTK_PANED(hpaned), 0);
  691. gtk_widget_hide(tree1_w);
  692. current = &rootmenu;
  693. display_tree_part();
  694. }
  695. void on_split_clicked(GtkButton * button, gpointer user_data)
  696. {
  697. gint w, h;
  698. view_mode = SPLIT_VIEW;
  699. gtk_widget_show(tree1_w);
  700. gtk_window_get_default_size(GTK_WINDOW(main_wnd), &w, &h);
  701. gtk_paned_set_position(GTK_PANED(hpaned), w / 2);
  702. if (tree2)
  703. gtk_tree_store_clear(tree2);
  704. display_list();
  705. /* Disable back btn, like in full mode. */
  706. gtk_widget_set_sensitive(back_btn, FALSE);
  707. }
  708. void on_full_clicked(GtkButton * button, gpointer user_data)
  709. {
  710. view_mode = FULL_VIEW;
  711. gtk_paned_set_position(GTK_PANED(hpaned), 0);
  712. gtk_widget_hide(tree1_w);
  713. if (tree2)
  714. gtk_tree_store_clear(tree2);
  715. display_tree(&rootmenu);
  716. gtk_widget_set_sensitive(back_btn, FALSE);
  717. }
  718. void on_collapse_clicked(GtkButton * button, gpointer user_data)
  719. {
  720. gtk_tree_view_collapse_all(GTK_TREE_VIEW(tree2_w));
  721. }
  722. void on_expand_clicked(GtkButton * button, gpointer user_data)
  723. {
  724. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w));
  725. }
  726. /* CTree Callbacks */
  727. /* Change hex/int/string value in the cell */
  728. static void renderer_edited(GtkCellRendererText * cell,
  729. const gchar * path_string,
  730. const gchar * new_text, gpointer user_data)
  731. {
  732. GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
  733. GtkTreeIter iter;
  734. const char *old_def, *new_def;
  735. struct menu *menu;
  736. struct symbol *sym;
  737. if (!gtk_tree_model_get_iter(model2, &iter, path))
  738. return;
  739. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  740. sym = menu->sym;
  741. gtk_tree_model_get(model2, &iter, COL_VALUE, &old_def, -1);
  742. new_def = new_text;
  743. sym_set_string_value(sym, new_def);
  744. config_changed = TRUE;
  745. update_tree(&rootmenu, NULL);
  746. gtk_tree_path_free(path);
  747. }
  748. /* Change the value of a symbol and update the tree */
  749. static void change_sym_value(struct menu *menu, gint col)
  750. {
  751. struct symbol *sym = menu->sym;
  752. tristate oldval, newval;
  753. if (!sym)
  754. return;
  755. if (col == COL_NO)
  756. newval = no;
  757. else if (col == COL_MOD)
  758. newval = mod;
  759. else if (col == COL_YES)
  760. newval = yes;
  761. else
  762. return;
  763. switch (sym_get_type(sym)) {
  764. case S_BOOLEAN:
  765. case S_TRISTATE:
  766. oldval = sym_get_tristate_value(sym);
  767. if (!sym_tristate_within_range(sym, newval))
  768. newval = yes;
  769. sym_set_tristate_value(sym, newval);
  770. config_changed = TRUE;
  771. if (view_mode == FULL_VIEW)
  772. update_tree(&rootmenu, NULL);
  773. else if (view_mode == SPLIT_VIEW) {
  774. update_tree(browsed, NULL);
  775. display_list();
  776. }
  777. else if (view_mode == SINGLE_VIEW)
  778. display_tree_part(); //fixme: keep exp/coll
  779. break;
  780. case S_INT:
  781. case S_HEX:
  782. case S_STRING:
  783. default:
  784. break;
  785. }
  786. }
  787. static void toggle_sym_value(struct menu *menu)
  788. {
  789. if (!menu->sym)
  790. return;
  791. sym_toggle_tristate_value(menu->sym);
  792. if (view_mode == FULL_VIEW)
  793. update_tree(&rootmenu, NULL);
  794. else if (view_mode == SPLIT_VIEW) {
  795. update_tree(browsed, NULL);
  796. display_list();
  797. }
  798. else if (view_mode == SINGLE_VIEW)
  799. display_tree_part(); //fixme: keep exp/coll
  800. }
  801. static void renderer_toggled(GtkCellRendererToggle * cell,
  802. gchar * path_string, gpointer user_data)
  803. {
  804. GtkTreePath *path, *sel_path = NULL;
  805. GtkTreeIter iter, sel_iter;
  806. GtkTreeSelection *sel;
  807. struct menu *menu;
  808. path = gtk_tree_path_new_from_string(path_string);
  809. if (!gtk_tree_model_get_iter(model2, &iter, path))
  810. return;
  811. sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree2_w));
  812. if (gtk_tree_selection_get_selected(sel, NULL, &sel_iter))
  813. sel_path = gtk_tree_model_get_path(model2, &sel_iter);
  814. if (!sel_path)
  815. goto out1;
  816. if (gtk_tree_path_compare(path, sel_path))
  817. goto out2;
  818. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  819. toggle_sym_value(menu);
  820. out2:
  821. gtk_tree_path_free(sel_path);
  822. out1:
  823. gtk_tree_path_free(path);
  824. }
  825. static gint column2index(GtkTreeViewColumn * column)
  826. {
  827. gint i;
  828. for (i = 0; i < COL_NUMBER; i++) {
  829. GtkTreeViewColumn *col;
  830. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), i);
  831. if (col == column)
  832. return i;
  833. }
  834. return -1;
  835. }
  836. /* User click: update choice (full) or goes down (single) */
  837. gboolean
  838. on_treeview2_button_press_event(GtkWidget * widget,
  839. GdkEventButton * event, gpointer user_data)
  840. {
  841. GtkTreeView *view = GTK_TREE_VIEW(widget);
  842. GtkTreePath *path;
  843. GtkTreeViewColumn *column;
  844. GtkTreeIter iter;
  845. struct menu *menu;
  846. gint col;
  847. #if GTK_CHECK_VERSION(2,1,4) // bug in ctree with earlier version of GTK
  848. gint tx = (gint) event->x;
  849. gint ty = (gint) event->y;
  850. gint cx, cy;
  851. gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx,
  852. &cy);
  853. #else
  854. gtk_tree_view_get_cursor(view, &path, &column);
  855. #endif
  856. if (path == NULL)
  857. return FALSE;
  858. if (!gtk_tree_model_get_iter(model2, &iter, path))
  859. return FALSE;
  860. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  861. col = column2index(column);
  862. if (event->type == GDK_2BUTTON_PRESS) {
  863. enum prop_type ptype;
  864. ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  865. if (ptype == P_MENU && view_mode != FULL_VIEW && col == COL_OPTION) {
  866. // goes down into menu
  867. current = menu;
  868. display_tree_part();
  869. gtk_widget_set_sensitive(back_btn, TRUE);
  870. } else if ((col == COL_OPTION)) {
  871. toggle_sym_value(menu);
  872. gtk_tree_view_expand_row(view, path, TRUE);
  873. }
  874. } else {
  875. if (col == COL_VALUE) {
  876. toggle_sym_value(menu);
  877. gtk_tree_view_expand_row(view, path, TRUE);
  878. } else if (col == COL_NO || col == COL_MOD
  879. || col == COL_YES) {
  880. change_sym_value(menu, col);
  881. gtk_tree_view_expand_row(view, path, TRUE);
  882. }
  883. }
  884. return FALSE;
  885. }
  886. /* Key pressed: update choice */
  887. gboolean
  888. on_treeview2_key_press_event(GtkWidget * widget,
  889. GdkEventKey * event, gpointer user_data)
  890. {
  891. GtkTreeView *view = GTK_TREE_VIEW(widget);
  892. GtkTreePath *path;
  893. GtkTreeViewColumn *column;
  894. GtkTreeIter iter;
  895. struct menu *menu;
  896. gint col;
  897. gtk_tree_view_get_cursor(view, &path, &column);
  898. if (path == NULL)
  899. return FALSE;
  900. if (event->keyval == GDK_space) {
  901. if (gtk_tree_view_row_expanded(view, path))
  902. gtk_tree_view_collapse_row(view, path);
  903. else
  904. gtk_tree_view_expand_row(view, path, FALSE);
  905. return TRUE;
  906. }
  907. if (event->keyval == GDK_KP_Enter) {
  908. }
  909. if (widget == tree1_w)
  910. return FALSE;
  911. gtk_tree_model_get_iter(model2, &iter, path);
  912. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  913. if (!strcasecmp(event->string, "n"))
  914. col = COL_NO;
  915. else if (!strcasecmp(event->string, "m"))
  916. col = COL_MOD;
  917. else if (!strcasecmp(event->string, "y"))
  918. col = COL_YES;
  919. else
  920. col = -1;
  921. change_sym_value(menu, col);
  922. return FALSE;
  923. }
  924. /* Row selection changed: update help */
  925. void
  926. on_treeview2_cursor_changed(GtkTreeView * treeview, gpointer user_data)
  927. {
  928. GtkTreeSelection *selection;
  929. GtkTreeIter iter;
  930. struct menu *menu;
  931. selection = gtk_tree_view_get_selection(treeview);
  932. if (gtk_tree_selection_get_selected(selection, &model2, &iter)) {
  933. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  934. text_insert_help(menu);
  935. }
  936. }
  937. /* User click: display sub-tree in the right frame. */
  938. gboolean
  939. on_treeview1_button_press_event(GtkWidget * widget,
  940. GdkEventButton * event, gpointer user_data)
  941. {
  942. GtkTreeView *view = GTK_TREE_VIEW(widget);
  943. GtkTreePath *path;
  944. GtkTreeViewColumn *column;
  945. GtkTreeIter iter;
  946. struct menu *menu;
  947. gint tx = (gint) event->x;
  948. gint ty = (gint) event->y;
  949. gint cx, cy;
  950. gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx,
  951. &cy);
  952. if (path == NULL)
  953. return FALSE;
  954. gtk_tree_model_get_iter(model1, &iter, path);
  955. gtk_tree_model_get(model1, &iter, COL_MENU, &menu, -1);
  956. if (event->type == GDK_2BUTTON_PRESS) {
  957. toggle_sym_value(menu);
  958. current = menu;
  959. display_tree_part();
  960. } else {
  961. browsed = menu;
  962. display_tree_part();
  963. }
  964. gtk_widget_realize(tree2_w);
  965. gtk_tree_view_set_cursor(view, path, NULL, FALSE);
  966. gtk_widget_grab_focus(tree2_w);
  967. return FALSE;
  968. }
  969. /* Fill a row of strings */
  970. static gchar **fill_row(struct menu *menu)
  971. {
  972. static gchar *row[COL_NUMBER];
  973. struct symbol *sym = menu->sym;
  974. const char *def;
  975. int stype;
  976. tristate val;
  977. enum prop_type ptype;
  978. int i;
  979. for (i = COL_OPTION; i <= COL_COLOR; i++)
  980. g_free(row[i]);
  981. memset(row, 0, sizeof(row));
  982. row[COL_OPTION] =
  983. g_strdup_printf("%s %s", menu_get_prompt(menu),
  984. sym ? (sym->
  985. flags & SYMBOL_NEW ? "(NEW)" : "") :
  986. "");
  987. if (show_all && !menu_is_visible(menu))
  988. row[COL_COLOR] = g_strdup("DarkGray");
  989. else
  990. row[COL_COLOR] = g_strdup("Black");
  991. ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  992. switch (ptype) {
  993. case P_MENU:
  994. row[COL_PIXBUF] = (gchar *) xpm_menu;
  995. if (view_mode == SINGLE_VIEW)
  996. row[COL_PIXVIS] = GINT_TO_POINTER(TRUE);
  997. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  998. break;
  999. case P_COMMENT:
  1000. row[COL_PIXBUF] = (gchar *) xpm_void;
  1001. row[COL_PIXVIS] = GINT_TO_POINTER(FALSE);
  1002. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  1003. break;
  1004. default:
  1005. row[COL_PIXBUF] = (gchar *) xpm_void;
  1006. row[COL_PIXVIS] = GINT_TO_POINTER(FALSE);
  1007. row[COL_BTNVIS] = GINT_TO_POINTER(TRUE);
  1008. break;
  1009. }
  1010. if (!sym)
  1011. return row;
  1012. row[COL_NAME] = g_strdup(sym->name);
  1013. sym_calc_value(sym);
  1014. sym->flags &= ~SYMBOL_CHANGED;
  1015. if (sym_is_choice(sym)) { // parse childs for getting final value
  1016. struct menu *child;
  1017. struct symbol *def_sym = sym_get_choice_value(sym);
  1018. struct menu *def_menu = NULL;
  1019. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  1020. for (child = menu->list; child; child = child->next) {
  1021. if (menu_is_visible(child)
  1022. && child->sym == def_sym)
  1023. def_menu = child;
  1024. }
  1025. if (def_menu)
  1026. row[COL_VALUE] =
  1027. g_strdup(menu_get_prompt(def_menu));
  1028. }
  1029. if (sym->flags & SYMBOL_CHOICEVAL)
  1030. row[COL_BTNRAD] = GINT_TO_POINTER(TRUE);
  1031. stype = sym_get_type(sym);
  1032. switch (stype) {
  1033. case S_BOOLEAN:
  1034. if (GPOINTER_TO_INT(row[COL_PIXVIS]) == FALSE)
  1035. row[COL_BTNVIS] = GINT_TO_POINTER(TRUE);
  1036. if (sym_is_choice(sym))
  1037. break;
  1038. case S_TRISTATE:
  1039. val = sym_get_tristate_value(sym);
  1040. switch (val) {
  1041. case no:
  1042. row[COL_NO] = g_strdup("N");
  1043. row[COL_VALUE] = g_strdup("N");
  1044. row[COL_BTNACT] = GINT_TO_POINTER(FALSE);
  1045. row[COL_BTNINC] = GINT_TO_POINTER(FALSE);
  1046. break;
  1047. case mod:
  1048. row[COL_MOD] = g_strdup("M");
  1049. row[COL_VALUE] = g_strdup("M");
  1050. row[COL_BTNINC] = GINT_TO_POINTER(TRUE);
  1051. break;
  1052. case yes:
  1053. row[COL_YES] = g_strdup("Y");
  1054. row[COL_VALUE] = g_strdup("Y");
  1055. row[COL_BTNACT] = GINT_TO_POINTER(TRUE);
  1056. row[COL_BTNINC] = GINT_TO_POINTER(FALSE);
  1057. break;
  1058. }
  1059. if (val != no && sym_tristate_within_range(sym, no))
  1060. row[COL_NO] = g_strdup("_");
  1061. if (val != mod && sym_tristate_within_range(sym, mod))
  1062. row[COL_MOD] = g_strdup("_");
  1063. if (val != yes && sym_tristate_within_range(sym, yes))
  1064. row[COL_YES] = g_strdup("_");
  1065. break;
  1066. case S_INT:
  1067. case S_HEX:
  1068. case S_STRING:
  1069. def = sym_get_string_value(sym);
  1070. row[COL_VALUE] = g_strdup(def);
  1071. row[COL_EDIT] = GINT_TO_POINTER(TRUE);
  1072. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  1073. break;
  1074. }
  1075. return row;
  1076. }
  1077. /* Set the node content with a row of strings */
  1078. static void set_node(GtkTreeIter * node, struct menu *menu, gchar ** row)
  1079. {
  1080. GdkColor color;
  1081. gboolean success;
  1082. GdkPixbuf *pix;
  1083. pix = gdk_pixbuf_new_from_xpm_data((const char **)
  1084. row[COL_PIXBUF]);
  1085. gdk_color_parse(row[COL_COLOR], &color);
  1086. gdk_colormap_alloc_colors(gdk_colormap_get_system(), &color, 1,
  1087. FALSE, FALSE, &success);
  1088. gtk_tree_store_set(tree, node,
  1089. COL_OPTION, row[COL_OPTION],
  1090. COL_NAME, row[COL_NAME],
  1091. COL_NO, row[COL_NO],
  1092. COL_MOD, row[COL_MOD],
  1093. COL_YES, row[COL_YES],
  1094. COL_VALUE, row[COL_VALUE],
  1095. COL_MENU, (gpointer) menu,
  1096. COL_COLOR, &color,
  1097. COL_EDIT, GPOINTER_TO_INT(row[COL_EDIT]),
  1098. COL_PIXBUF, pix,
  1099. COL_PIXVIS, GPOINTER_TO_INT(row[COL_PIXVIS]),
  1100. COL_BTNVIS, GPOINTER_TO_INT(row[COL_BTNVIS]),
  1101. COL_BTNACT, GPOINTER_TO_INT(row[COL_BTNACT]),
  1102. COL_BTNINC, GPOINTER_TO_INT(row[COL_BTNINC]),
  1103. COL_BTNRAD, GPOINTER_TO_INT(row[COL_BTNRAD]),
  1104. -1);
  1105. g_object_unref(pix);
  1106. }
  1107. /* Add a node to the tree */
  1108. static void place_node(struct menu *menu, char **row)
  1109. {
  1110. GtkTreeIter *parent = parents[indent - 1];
  1111. GtkTreeIter *node = parents[indent];
  1112. gtk_tree_store_append(tree, node, parent);
  1113. set_node(node, menu, row);
  1114. }
  1115. /* Find a node in the GTK+ tree */
  1116. static GtkTreeIter found;
  1117. /*
  1118. * Find a menu in the GtkTree starting at parent.
  1119. */
  1120. GtkTreeIter *gtktree_iter_find_node(GtkTreeIter * parent,
  1121. struct menu *tofind)
  1122. {
  1123. GtkTreeIter iter;
  1124. GtkTreeIter *child = &iter;
  1125. gboolean valid;
  1126. GtkTreeIter *ret;
  1127. valid = gtk_tree_model_iter_children(model2, child, parent);
  1128. while (valid) {
  1129. struct menu *menu;
  1130. gtk_tree_model_get(model2, child, 6, &menu, -1);
  1131. if (menu == tofind) {
  1132. memcpy(&found, child, sizeof(GtkTreeIter));
  1133. return &found;
  1134. }
  1135. ret = gtktree_iter_find_node(child, tofind);
  1136. if (ret)
  1137. return ret;
  1138. valid = gtk_tree_model_iter_next(model2, child);
  1139. }
  1140. return NULL;
  1141. }
  1142. /*
  1143. * Update the tree by adding/removing entries
  1144. * Does not change other nodes
  1145. */
  1146. static void update_tree(struct menu *src, GtkTreeIter * dst)
  1147. {
  1148. struct menu *child1;
  1149. GtkTreeIter iter, tmp;
  1150. GtkTreeIter *child2 = &iter;
  1151. gboolean valid;
  1152. GtkTreeIter *sibling;
  1153. struct symbol *sym;
  1154. struct property *prop;
  1155. struct menu *menu1, *menu2;
  1156. if (src == &rootmenu)
  1157. indent = 1;
  1158. valid = gtk_tree_model_iter_children(model2, child2, dst);
  1159. for (child1 = src->list; child1; child1 = child1->next) {
  1160. prop = child1->prompt;
  1161. sym = child1->sym;
  1162. reparse:
  1163. menu1 = child1;
  1164. if (valid)
  1165. gtk_tree_model_get(model2, child2, COL_MENU,
  1166. &menu2, -1);
  1167. else
  1168. menu2 = NULL; // force adding of a first child
  1169. #ifdef DEBUG
  1170. printf("%*c%s | %s\n", indent, ' ',
  1171. menu1 ? menu_get_prompt(menu1) : "nil",
  1172. menu2 ? menu_get_prompt(menu2) : "nil");
  1173. #endif
  1174. if (!menu_is_visible(child1) && !show_all) { // remove node
  1175. if (gtktree_iter_find_node(dst, menu1) != NULL) {
  1176. memcpy(&tmp, child2, sizeof(GtkTreeIter));
  1177. valid = gtk_tree_model_iter_next(model2,
  1178. child2);
  1179. gtk_tree_store_remove(tree2, &tmp);
  1180. if (!valid)
  1181. return; // next parent
  1182. else
  1183. goto reparse; // next child
  1184. } else
  1185. continue;
  1186. }
  1187. if (menu1 != menu2) {
  1188. if (gtktree_iter_find_node(dst, menu1) == NULL) { // add node
  1189. if (!valid && !menu2)
  1190. sibling = NULL;
  1191. else
  1192. sibling = child2;
  1193. gtk_tree_store_insert_before(tree2,
  1194. child2,
  1195. dst, sibling);
  1196. set_node(child2, menu1, fill_row(menu1));
  1197. if (menu2 == NULL)
  1198. valid = TRUE;
  1199. } else { // remove node
  1200. memcpy(&tmp, child2, sizeof(GtkTreeIter));
  1201. valid = gtk_tree_model_iter_next(model2,
  1202. child2);
  1203. gtk_tree_store_remove(tree2, &tmp);
  1204. if (!valid)
  1205. return; // next parent
  1206. else
  1207. goto reparse; // next child
  1208. }
  1209. } else if (sym && (sym->flags & SYMBOL_CHANGED)) {
  1210. set_node(child2, menu1, fill_row(menu1));
  1211. }
  1212. indent++;
  1213. update_tree(child1, child2);
  1214. indent--;
  1215. valid = gtk_tree_model_iter_next(model2, child2);
  1216. }
  1217. }
  1218. /* Display the whole tree (single/split/full view) */
  1219. static void display_tree(struct menu *menu)
  1220. {
  1221. struct symbol *sym;
  1222. struct property *prop;
  1223. struct menu *child;
  1224. enum prop_type ptype;
  1225. if (menu == &rootmenu) {
  1226. indent = 1;
  1227. current = &rootmenu;
  1228. }
  1229. for (child = menu->list; child; child = child->next) {
  1230. prop = child->prompt;
  1231. sym = child->sym;
  1232. ptype = prop ? prop->type : P_UNKNOWN;
  1233. if (sym)
  1234. sym->flags &= ~SYMBOL_CHANGED;
  1235. if ((view_mode == SPLIT_VIEW)
  1236. && !(child->flags & MENU_ROOT) && (tree == tree1))
  1237. continue;
  1238. if ((view_mode == SPLIT_VIEW) && (child->flags & MENU_ROOT)
  1239. && (tree == tree2))
  1240. continue;
  1241. if (menu_is_visible(child) || show_all)
  1242. place_node(child, fill_row(child));
  1243. #ifdef DEBUG
  1244. printf("%*c%s: ", indent, ' ', menu_get_prompt(child));
  1245. printf("%s", child->flags & MENU_ROOT ? "rootmenu | " : "");
  1246. dbg_print_ptype(ptype);
  1247. printf(" | ");
  1248. if (sym) {
  1249. dbg_print_stype(sym->type);
  1250. printf(" | ");
  1251. dbg_print_flags(sym->flags);
  1252. printf("\n");
  1253. } else
  1254. printf("\n");
  1255. #endif
  1256. if ((view_mode != FULL_VIEW) && (ptype == P_MENU)
  1257. && (tree == tree2))
  1258. continue;
  1259. /*
  1260. if (((menu != &rootmenu) && !(menu->flags & MENU_ROOT))
  1261. || (view_mode == FULL_VIEW)
  1262. || (view_mode == SPLIT_VIEW))*/
  1263. if (((view_mode == SINGLE_VIEW) && (menu->flags & MENU_ROOT))
  1264. || (view_mode == FULL_VIEW)
  1265. || (view_mode == SPLIT_VIEW)) {
  1266. indent++;
  1267. display_tree(child);
  1268. indent--;
  1269. }
  1270. }
  1271. }
  1272. /* Display a part of the tree starting at current node (single/split view) */
  1273. static void display_tree_part(void)
  1274. {
  1275. if (tree2)
  1276. gtk_tree_store_clear(tree2);
  1277. if (view_mode == SINGLE_VIEW)
  1278. display_tree(current);
  1279. else if (view_mode == SPLIT_VIEW)
  1280. display_tree(browsed);
  1281. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w));
  1282. }
  1283. /* Display the list in the left frame (split view) */
  1284. static void display_list(void)
  1285. {
  1286. if (tree1)
  1287. gtk_tree_store_clear(tree1);
  1288. tree = tree1;
  1289. display_tree(&rootmenu);
  1290. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree1_w));
  1291. tree = tree2;
  1292. }
  1293. void fixup_rootmenu(struct menu *menu)
  1294. {
  1295. struct menu *child;
  1296. static int menu_cnt = 0;
  1297. menu->flags |= MENU_ROOT;
  1298. for (child = menu->list; child; child = child->next) {
  1299. if (child->prompt && child->prompt->type == P_MENU) {
  1300. menu_cnt++;
  1301. fixup_rootmenu(child);
  1302. menu_cnt--;
  1303. } else if (!menu_cnt)
  1304. fixup_rootmenu(child);
  1305. }
  1306. }
  1307. /* Main */
  1308. int main(int ac, char *av[])
  1309. {
  1310. const char *name;
  1311. char *env;
  1312. gchar *glade_file;
  1313. #ifndef LKC_DIRECT_LINK
  1314. kconfig_load();
  1315. #endif
  1316. bindtextdomain(PACKAGE, LOCALEDIR);
  1317. bind_textdomain_codeset(PACKAGE, "UTF-8");
  1318. textdomain(PACKAGE);
  1319. /* GTK stuffs */
  1320. gtk_set_locale();
  1321. gtk_init(&ac, &av);
  1322. glade_init();
  1323. //add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
  1324. //add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
  1325. /* Determine GUI path */
  1326. env = getenv(SRCTREE);
  1327. if (env)
  1328. glade_file = g_strconcat(env, "/scripts/kconfig/gconf.glade", NULL);
  1329. else if (av[0][0] == '/')
  1330. glade_file = g_strconcat(av[0], ".glade", NULL);
  1331. else
  1332. glade_file = g_strconcat(g_get_current_dir(), "/", av[0], ".glade", NULL);
  1333. /* Load the interface and connect signals */
  1334. init_main_window(glade_file);
  1335. init_tree_model();
  1336. init_left_tree();
  1337. init_right_tree();
  1338. /* Conf stuffs */
  1339. if (ac > 1 && av[1][0] == '-') {
  1340. switch (av[1][1]) {
  1341. case 'a':
  1342. //showAll = 1;
  1343. break;
  1344. case 'h':
  1345. case '?':
  1346. printf("%s <config>\n", av[0]);
  1347. exit(0);
  1348. }
  1349. name = av[2];
  1350. } else
  1351. name = av[1];
  1352. conf_parse(name);
  1353. fixup_rootmenu(&rootmenu);
  1354. conf_read(NULL);
  1355. switch (view_mode) {
  1356. case SINGLE_VIEW:
  1357. display_tree_part();
  1358. break;
  1359. case SPLIT_VIEW:
  1360. display_list();
  1361. break;
  1362. case FULL_VIEW:
  1363. display_tree(&rootmenu);
  1364. break;
  1365. }
  1366. gtk_main();
  1367. return 0;
  1368. }