1
0

gconf.c 39 KB

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