gconf.c 38 KB

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