gconf.c 40 KB

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