gconf.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  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_NO_WRITE)
  87. strcat(buf, "no_write/");
  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. conf_write_autoconf(0);
  439. }
  440. static void
  441. store_filename(GtkFileSelection * file_selector, gpointer user_data)
  442. {
  443. const gchar *fn;
  444. fn = gtk_file_selection_get_filename(GTK_FILE_SELECTION
  445. (user_data));
  446. if (conf_write(fn))
  447. text_insert_msg("Error", "Unable to save configuration !");
  448. gtk_widget_destroy(GTK_WIDGET(user_data));
  449. }
  450. void on_save_as1_activate(GtkMenuItem * menuitem, gpointer user_data)
  451. {
  452. GtkWidget *fs;
  453. fs = gtk_file_selection_new("Save file as...");
  454. g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
  455. "clicked",
  456. G_CALLBACK(store_filename), (gpointer) fs);
  457. g_signal_connect_swapped(GTK_OBJECT
  458. (GTK_FILE_SELECTION(fs)->ok_button),
  459. "clicked", G_CALLBACK(gtk_widget_destroy),
  460. (gpointer) fs);
  461. g_signal_connect_swapped(GTK_OBJECT
  462. (GTK_FILE_SELECTION(fs)->cancel_button),
  463. "clicked", G_CALLBACK(gtk_widget_destroy),
  464. (gpointer) fs);
  465. gtk_widget_show(fs);
  466. }
  467. void on_quit1_activate(GtkMenuItem * menuitem, gpointer user_data)
  468. {
  469. if (!on_window1_delete_event(NULL, NULL, NULL))
  470. gtk_widget_destroy(GTK_WIDGET(main_wnd));
  471. }
  472. void on_show_name1_activate(GtkMenuItem * menuitem, gpointer user_data)
  473. {
  474. GtkTreeViewColumn *col;
  475. show_name = GTK_CHECK_MENU_ITEM(menuitem)->active;
  476. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_NAME);
  477. if (col)
  478. gtk_tree_view_column_set_visible(col, show_name);
  479. }
  480. void on_show_range1_activate(GtkMenuItem * menuitem, gpointer user_data)
  481. {
  482. GtkTreeViewColumn *col;
  483. show_range = GTK_CHECK_MENU_ITEM(menuitem)->active;
  484. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_NO);
  485. if (col)
  486. gtk_tree_view_column_set_visible(col, show_range);
  487. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_MOD);
  488. if (col)
  489. gtk_tree_view_column_set_visible(col, show_range);
  490. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_YES);
  491. if (col)
  492. gtk_tree_view_column_set_visible(col, show_range);
  493. }
  494. void on_show_data1_activate(GtkMenuItem * menuitem, gpointer user_data)
  495. {
  496. GtkTreeViewColumn *col;
  497. show_value = GTK_CHECK_MENU_ITEM(menuitem)->active;
  498. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_VALUE);
  499. if (col)
  500. gtk_tree_view_column_set_visible(col, show_value);
  501. }
  502. void
  503. on_set_option_mode1_activate(GtkMenuItem *menuitem, gpointer user_data)
  504. {
  505. opt_mode = OPT_NORMAL;
  506. gtk_tree_store_clear(tree2);
  507. display_tree(&rootmenu); /* instead of update_tree to speed-up */
  508. }
  509. void
  510. on_set_option_mode2_activate(GtkMenuItem *menuitem, gpointer user_data)
  511. {
  512. opt_mode = OPT_ALL;
  513. gtk_tree_store_clear(tree2);
  514. display_tree(&rootmenu); /* instead of update_tree to speed-up */
  515. }
  516. void
  517. on_set_option_mode3_activate(GtkMenuItem *menuitem, gpointer user_data)
  518. {
  519. opt_mode = OPT_PROMPT;
  520. gtk_tree_store_clear(tree2);
  521. display_tree(&rootmenu); /* instead of update_tree to speed-up */
  522. }
  523. void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data)
  524. {
  525. GtkWidget *dialog;
  526. const gchar *intro_text =
  527. "Welcome to gkc, the GTK+ graphical configuration tool\n"
  528. "For each option, a blank box indicates the feature is disabled, a\n"
  529. "check indicates it is enabled, and a dot indicates that it is to\n"
  530. "be compiled as a module. Clicking on the box will cycle through the three states.\n"
  531. "\n"
  532. "If you do not see an option (e.g., a device driver) that you\n"
  533. "believe should be present, try turning on Show All Options\n"
  534. "under the Options menu.\n"
  535. "Although there is no cross reference yet to help you figure out\n"
  536. "what other options must be enabled to support the option you\n"
  537. "are interested in, you can still view the help of a grayed-out\n"
  538. "option.\n"
  539. "\n"
  540. "Toggling Show Debug Info under the Options menu will show \n"
  541. "the dependencies, which you can then match by examining other options.";
  542. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  543. GTK_DIALOG_DESTROY_WITH_PARENT,
  544. GTK_MESSAGE_INFO,
  545. GTK_BUTTONS_CLOSE, "%s", intro_text);
  546. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  547. G_CALLBACK(gtk_widget_destroy),
  548. GTK_OBJECT(dialog));
  549. gtk_widget_show_all(dialog);
  550. }
  551. void on_about1_activate(GtkMenuItem * menuitem, gpointer user_data)
  552. {
  553. GtkWidget *dialog;
  554. const gchar *about_text =
  555. "gkc is copyright (c) 2002 Romain Lievin <roms@lpg.ticalc.org>.\n"
  556. "Based on the source code from Roman Zippel.\n";
  557. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  558. GTK_DIALOG_DESTROY_WITH_PARENT,
  559. GTK_MESSAGE_INFO,
  560. GTK_BUTTONS_CLOSE, "%s", about_text);
  561. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  562. G_CALLBACK(gtk_widget_destroy),
  563. GTK_OBJECT(dialog));
  564. gtk_widget_show_all(dialog);
  565. }
  566. void on_license1_activate(GtkMenuItem * menuitem, gpointer user_data)
  567. {
  568. GtkWidget *dialog;
  569. const gchar *license_text =
  570. "gkc is released under the terms of the GNU GPL v2.\n"
  571. "For more information, please see the source code or\n"
  572. "visit http://www.fsf.org/licenses/licenses.html\n";
  573. dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
  574. GTK_DIALOG_DESTROY_WITH_PARENT,
  575. GTK_MESSAGE_INFO,
  576. GTK_BUTTONS_CLOSE, "%s", license_text);
  577. g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
  578. G_CALLBACK(gtk_widget_destroy),
  579. GTK_OBJECT(dialog));
  580. gtk_widget_show_all(dialog);
  581. }
  582. void on_back_clicked(GtkButton * button, gpointer user_data)
  583. {
  584. enum prop_type ptype;
  585. current = current->parent;
  586. ptype = current->prompt ? current->prompt->type : P_UNKNOWN;
  587. if (ptype != P_MENU)
  588. current = current->parent;
  589. display_tree_part();
  590. if (current == &rootmenu)
  591. gtk_widget_set_sensitive(back_btn, FALSE);
  592. }
  593. void on_load_clicked(GtkButton * button, gpointer user_data)
  594. {
  595. on_load1_activate(NULL, user_data);
  596. }
  597. void on_single_clicked(GtkButton * button, gpointer user_data)
  598. {
  599. view_mode = SINGLE_VIEW;
  600. gtk_widget_hide(tree1_w);
  601. current = &rootmenu;
  602. display_tree_part();
  603. }
  604. void on_split_clicked(GtkButton * button, gpointer user_data)
  605. {
  606. gint w, h;
  607. view_mode = SPLIT_VIEW;
  608. gtk_widget_show(tree1_w);
  609. gtk_window_get_default_size(GTK_WINDOW(main_wnd), &w, &h);
  610. gtk_paned_set_position(GTK_PANED(hpaned), w / 2);
  611. if (tree2)
  612. gtk_tree_store_clear(tree2);
  613. display_list();
  614. /* Disable back btn, like in full mode. */
  615. gtk_widget_set_sensitive(back_btn, FALSE);
  616. }
  617. void on_full_clicked(GtkButton * button, gpointer user_data)
  618. {
  619. view_mode = FULL_VIEW;
  620. gtk_widget_hide(tree1_w);
  621. if (tree2)
  622. gtk_tree_store_clear(tree2);
  623. display_tree(&rootmenu);
  624. gtk_widget_set_sensitive(back_btn, FALSE);
  625. }
  626. void on_collapse_clicked(GtkButton * button, gpointer user_data)
  627. {
  628. gtk_tree_view_collapse_all(GTK_TREE_VIEW(tree2_w));
  629. }
  630. void on_expand_clicked(GtkButton * button, gpointer user_data)
  631. {
  632. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w));
  633. }
  634. /* CTree Callbacks */
  635. /* Change hex/int/string value in the cell */
  636. static void renderer_edited(GtkCellRendererText * cell,
  637. const gchar * path_string,
  638. const gchar * new_text, gpointer user_data)
  639. {
  640. GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
  641. GtkTreeIter iter;
  642. const char *old_def, *new_def;
  643. struct menu *menu;
  644. struct symbol *sym;
  645. if (!gtk_tree_model_get_iter(model2, &iter, path))
  646. return;
  647. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  648. sym = menu->sym;
  649. gtk_tree_model_get(model2, &iter, COL_VALUE, &old_def, -1);
  650. new_def = new_text;
  651. sym_set_string_value(sym, new_def);
  652. update_tree(&rootmenu, NULL);
  653. gtk_tree_path_free(path);
  654. }
  655. /* Change the value of a symbol and update the tree */
  656. static void change_sym_value(struct menu *menu, gint col)
  657. {
  658. struct symbol *sym = menu->sym;
  659. tristate newval;
  660. if (!sym)
  661. return;
  662. if (col == COL_NO)
  663. newval = no;
  664. else if (col == COL_MOD)
  665. newval = mod;
  666. else if (col == COL_YES)
  667. newval = yes;
  668. else
  669. return;
  670. switch (sym_get_type(sym)) {
  671. case S_BOOLEAN:
  672. case S_TRISTATE:
  673. if (!sym_tristate_within_range(sym, newval))
  674. newval = yes;
  675. sym_set_tristate_value(sym, newval);
  676. if (view_mode == FULL_VIEW)
  677. update_tree(&rootmenu, NULL);
  678. else if (view_mode == SPLIT_VIEW) {
  679. update_tree(browsed, NULL);
  680. display_list();
  681. }
  682. else if (view_mode == SINGLE_VIEW)
  683. display_tree_part(); //fixme: keep exp/coll
  684. break;
  685. case S_INT:
  686. case S_HEX:
  687. case S_STRING:
  688. default:
  689. break;
  690. }
  691. }
  692. static void toggle_sym_value(struct menu *menu)
  693. {
  694. if (!menu->sym)
  695. return;
  696. sym_toggle_tristate_value(menu->sym);
  697. if (view_mode == FULL_VIEW)
  698. update_tree(&rootmenu, NULL);
  699. else if (view_mode == SPLIT_VIEW) {
  700. update_tree(browsed, NULL);
  701. display_list();
  702. }
  703. else if (view_mode == SINGLE_VIEW)
  704. display_tree_part(); //fixme: keep exp/coll
  705. }
  706. static gint column2index(GtkTreeViewColumn * column)
  707. {
  708. gint i;
  709. for (i = 0; i < COL_NUMBER; i++) {
  710. GtkTreeViewColumn *col;
  711. col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), i);
  712. if (col == column)
  713. return i;
  714. }
  715. return -1;
  716. }
  717. /* User click: update choice (full) or goes down (single) */
  718. gboolean
  719. on_treeview2_button_press_event(GtkWidget * widget,
  720. GdkEventButton * event, gpointer user_data)
  721. {
  722. GtkTreeView *view = GTK_TREE_VIEW(widget);
  723. GtkTreePath *path;
  724. GtkTreeViewColumn *column;
  725. GtkTreeIter iter;
  726. struct menu *menu;
  727. gint col;
  728. #if GTK_CHECK_VERSION(2,1,4) // bug in ctree with earlier version of GTK
  729. gint tx = (gint) event->x;
  730. gint ty = (gint) event->y;
  731. gint cx, cy;
  732. gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx,
  733. &cy);
  734. #else
  735. gtk_tree_view_get_cursor(view, &path, &column);
  736. #endif
  737. if (path == NULL)
  738. return FALSE;
  739. if (!gtk_tree_model_get_iter(model2, &iter, path))
  740. return FALSE;
  741. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  742. col = column2index(column);
  743. if (event->type == GDK_2BUTTON_PRESS) {
  744. enum prop_type ptype;
  745. ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  746. if (ptype == P_MENU && view_mode != FULL_VIEW && col == COL_OPTION) {
  747. // goes down into menu
  748. current = menu;
  749. display_tree_part();
  750. gtk_widget_set_sensitive(back_btn, TRUE);
  751. } else if (col == COL_OPTION) {
  752. toggle_sym_value(menu);
  753. gtk_tree_view_expand_row(view, path, TRUE);
  754. }
  755. } else {
  756. if (col == COL_VALUE) {
  757. toggle_sym_value(menu);
  758. gtk_tree_view_expand_row(view, path, TRUE);
  759. } else if (col == COL_NO || col == COL_MOD
  760. || col == COL_YES) {
  761. change_sym_value(menu, col);
  762. gtk_tree_view_expand_row(view, path, TRUE);
  763. }
  764. }
  765. return FALSE;
  766. }
  767. /* Key pressed: update choice */
  768. gboolean
  769. on_treeview2_key_press_event(GtkWidget * widget,
  770. GdkEventKey * event, gpointer user_data)
  771. {
  772. GtkTreeView *view = GTK_TREE_VIEW(widget);
  773. GtkTreePath *path;
  774. GtkTreeViewColumn *column;
  775. GtkTreeIter iter;
  776. struct menu *menu;
  777. gint col;
  778. gtk_tree_view_get_cursor(view, &path, &column);
  779. if (path == NULL)
  780. return FALSE;
  781. if (event->keyval == GDK_space) {
  782. if (gtk_tree_view_row_expanded(view, path))
  783. gtk_tree_view_collapse_row(view, path);
  784. else
  785. gtk_tree_view_expand_row(view, path, FALSE);
  786. return TRUE;
  787. }
  788. if (event->keyval == GDK_KP_Enter) {
  789. }
  790. if (widget == tree1_w)
  791. return FALSE;
  792. gtk_tree_model_get_iter(model2, &iter, path);
  793. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  794. if (!strcasecmp(event->string, "n"))
  795. col = COL_NO;
  796. else if (!strcasecmp(event->string, "m"))
  797. col = COL_MOD;
  798. else if (!strcasecmp(event->string, "y"))
  799. col = COL_YES;
  800. else
  801. col = -1;
  802. change_sym_value(menu, col);
  803. return FALSE;
  804. }
  805. /* Row selection changed: update help */
  806. void
  807. on_treeview2_cursor_changed(GtkTreeView * treeview, gpointer user_data)
  808. {
  809. GtkTreeSelection *selection;
  810. GtkTreeIter iter;
  811. struct menu *menu;
  812. selection = gtk_tree_view_get_selection(treeview);
  813. if (gtk_tree_selection_get_selected(selection, &model2, &iter)) {
  814. gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
  815. text_insert_help(menu);
  816. }
  817. }
  818. /* User click: display sub-tree in the right frame. */
  819. gboolean
  820. on_treeview1_button_press_event(GtkWidget * widget,
  821. GdkEventButton * event, gpointer user_data)
  822. {
  823. GtkTreeView *view = GTK_TREE_VIEW(widget);
  824. GtkTreePath *path;
  825. GtkTreeViewColumn *column;
  826. GtkTreeIter iter;
  827. struct menu *menu;
  828. gint tx = (gint) event->x;
  829. gint ty = (gint) event->y;
  830. gint cx, cy;
  831. gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx,
  832. &cy);
  833. if (path == NULL)
  834. return FALSE;
  835. gtk_tree_model_get_iter(model1, &iter, path);
  836. gtk_tree_model_get(model1, &iter, COL_MENU, &menu, -1);
  837. if (event->type == GDK_2BUTTON_PRESS) {
  838. toggle_sym_value(menu);
  839. current = menu;
  840. display_tree_part();
  841. } else {
  842. browsed = menu;
  843. display_tree_part();
  844. }
  845. gtk_widget_realize(tree2_w);
  846. gtk_tree_view_set_cursor(view, path, NULL, FALSE);
  847. gtk_widget_grab_focus(tree2_w);
  848. return FALSE;
  849. }
  850. /* Fill a row of strings */
  851. static gchar **fill_row(struct menu *menu)
  852. {
  853. static gchar *row[COL_NUMBER];
  854. struct symbol *sym = menu->sym;
  855. const char *def;
  856. int stype;
  857. tristate val;
  858. enum prop_type ptype;
  859. int i;
  860. for (i = COL_OPTION; i <= COL_COLOR; i++)
  861. g_free(row[i]);
  862. bzero(row, sizeof(row));
  863. row[COL_OPTION] =
  864. g_strdup_printf("%s %s", menu_get_prompt(menu),
  865. sym && !sym_has_value(sym) ? "(NEW)" : "");
  866. if (opt_mode == OPT_ALL && !menu_is_visible(menu))
  867. row[COL_COLOR] = g_strdup("DarkGray");
  868. else if (opt_mode == OPT_PROMPT &&
  869. menu_has_prompt(menu) && !menu_is_visible(menu))
  870. row[COL_COLOR] = g_strdup("DarkGray");
  871. else
  872. row[COL_COLOR] = g_strdup("Black");
  873. ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
  874. switch (ptype) {
  875. case P_MENU:
  876. row[COL_PIXBUF] = (gchar *) xpm_menu;
  877. if (view_mode == SINGLE_VIEW)
  878. row[COL_PIXVIS] = GINT_TO_POINTER(TRUE);
  879. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  880. break;
  881. case P_COMMENT:
  882. row[COL_PIXBUF] = (gchar *) xpm_void;
  883. row[COL_PIXVIS] = GINT_TO_POINTER(FALSE);
  884. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  885. break;
  886. default:
  887. row[COL_PIXBUF] = (gchar *) xpm_void;
  888. row[COL_PIXVIS] = GINT_TO_POINTER(FALSE);
  889. row[COL_BTNVIS] = GINT_TO_POINTER(TRUE);
  890. break;
  891. }
  892. if (!sym)
  893. return row;
  894. row[COL_NAME] = g_strdup(sym->name);
  895. sym_calc_value(sym);
  896. sym->flags &= ~SYMBOL_CHANGED;
  897. if (sym_is_choice(sym)) { // parse childs for getting final value
  898. struct menu *child;
  899. struct symbol *def_sym = sym_get_choice_value(sym);
  900. struct menu *def_menu = NULL;
  901. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  902. for (child = menu->list; child; child = child->next) {
  903. if (menu_is_visible(child)
  904. && child->sym == def_sym)
  905. def_menu = child;
  906. }
  907. if (def_menu)
  908. row[COL_VALUE] =
  909. g_strdup(menu_get_prompt(def_menu));
  910. }
  911. if (sym->flags & SYMBOL_CHOICEVAL)
  912. row[COL_BTNRAD] = GINT_TO_POINTER(TRUE);
  913. stype = sym_get_type(sym);
  914. switch (stype) {
  915. case S_BOOLEAN:
  916. if (GPOINTER_TO_INT(row[COL_PIXVIS]) == FALSE)
  917. row[COL_BTNVIS] = GINT_TO_POINTER(TRUE);
  918. if (sym_is_choice(sym))
  919. break;
  920. /* fall through */
  921. case S_TRISTATE:
  922. val = sym_get_tristate_value(sym);
  923. switch (val) {
  924. case no:
  925. row[COL_NO] = g_strdup("N");
  926. row[COL_VALUE] = g_strdup("N");
  927. row[COL_BTNACT] = GINT_TO_POINTER(FALSE);
  928. row[COL_BTNINC] = GINT_TO_POINTER(FALSE);
  929. break;
  930. case mod:
  931. row[COL_MOD] = g_strdup("M");
  932. row[COL_VALUE] = g_strdup("M");
  933. row[COL_BTNINC] = GINT_TO_POINTER(TRUE);
  934. break;
  935. case yes:
  936. row[COL_YES] = g_strdup("Y");
  937. row[COL_VALUE] = g_strdup("Y");
  938. row[COL_BTNACT] = GINT_TO_POINTER(TRUE);
  939. row[COL_BTNINC] = GINT_TO_POINTER(FALSE);
  940. break;
  941. }
  942. if (val != no && sym_tristate_within_range(sym, no))
  943. row[COL_NO] = g_strdup("_");
  944. if (val != mod && sym_tristate_within_range(sym, mod))
  945. row[COL_MOD] = g_strdup("_");
  946. if (val != yes && sym_tristate_within_range(sym, yes))
  947. row[COL_YES] = g_strdup("_");
  948. break;
  949. case S_INT:
  950. case S_HEX:
  951. case S_STRING:
  952. def = sym_get_string_value(sym);
  953. row[COL_VALUE] = g_strdup(def);
  954. row[COL_EDIT] = GINT_TO_POINTER(TRUE);
  955. row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
  956. break;
  957. }
  958. return row;
  959. }
  960. /* Set the node content with a row of strings */
  961. static void set_node(GtkTreeIter * node, struct menu *menu, gchar ** row)
  962. {
  963. GdkColor color;
  964. gboolean success;
  965. GdkPixbuf *pix;
  966. pix = gdk_pixbuf_new_from_xpm_data((const char **)
  967. row[COL_PIXBUF]);
  968. gdk_color_parse(row[COL_COLOR], &color);
  969. gdk_colormap_alloc_colors(gdk_colormap_get_system(), &color, 1,
  970. FALSE, FALSE, &success);
  971. gtk_tree_store_set(tree, node,
  972. COL_OPTION, row[COL_OPTION],
  973. COL_NAME, row[COL_NAME],
  974. COL_NO, row[COL_NO],
  975. COL_MOD, row[COL_MOD],
  976. COL_YES, row[COL_YES],
  977. COL_VALUE, row[COL_VALUE],
  978. COL_MENU, (gpointer) menu,
  979. COL_COLOR, &color,
  980. COL_EDIT, GPOINTER_TO_INT(row[COL_EDIT]),
  981. COL_PIXBUF, pix,
  982. COL_PIXVIS, GPOINTER_TO_INT(row[COL_PIXVIS]),
  983. COL_BTNVIS, GPOINTER_TO_INT(row[COL_BTNVIS]),
  984. COL_BTNACT, GPOINTER_TO_INT(row[COL_BTNACT]),
  985. COL_BTNINC, GPOINTER_TO_INT(row[COL_BTNINC]),
  986. COL_BTNRAD, GPOINTER_TO_INT(row[COL_BTNRAD]),
  987. -1);
  988. g_object_unref(pix);
  989. }
  990. /* Add a node to the tree */
  991. static void place_node(struct menu *menu, char **row)
  992. {
  993. GtkTreeIter *parent = parents[indent - 1];
  994. GtkTreeIter *node = parents[indent];
  995. gtk_tree_store_append(tree, node, parent);
  996. set_node(node, menu, row);
  997. }
  998. /* Find a node in the GTK+ tree */
  999. static GtkTreeIter found;
  1000. /*
  1001. * Find a menu in the GtkTree starting at parent.
  1002. */
  1003. GtkTreeIter *gtktree_iter_find_node(GtkTreeIter * parent,
  1004. struct menu *tofind)
  1005. {
  1006. GtkTreeIter iter;
  1007. GtkTreeIter *child = &iter;
  1008. gboolean valid;
  1009. GtkTreeIter *ret;
  1010. valid = gtk_tree_model_iter_children(model2, child, parent);
  1011. while (valid) {
  1012. struct menu *menu;
  1013. gtk_tree_model_get(model2, child, 6, &menu, -1);
  1014. if (menu == tofind) {
  1015. memcpy(&found, child, sizeof(GtkTreeIter));
  1016. return &found;
  1017. }
  1018. ret = gtktree_iter_find_node(child, tofind);
  1019. if (ret)
  1020. return ret;
  1021. valid = gtk_tree_model_iter_next(model2, child);
  1022. }
  1023. return NULL;
  1024. }
  1025. /*
  1026. * Update the tree by adding/removing entries
  1027. * Does not change other nodes
  1028. */
  1029. static void update_tree(struct menu *src, GtkTreeIter * dst)
  1030. {
  1031. struct menu *child1;
  1032. GtkTreeIter iter, tmp;
  1033. GtkTreeIter *child2 = &iter;
  1034. gboolean valid;
  1035. GtkTreeIter *sibling;
  1036. struct symbol *sym;
  1037. struct menu *menu1, *menu2;
  1038. if (src == &rootmenu)
  1039. indent = 1;
  1040. valid = gtk_tree_model_iter_children(model2, child2, dst);
  1041. for (child1 = src->list; child1; child1 = child1->next) {
  1042. sym = child1->sym;
  1043. reparse:
  1044. menu1 = child1;
  1045. if (valid)
  1046. gtk_tree_model_get(model2, child2, COL_MENU,
  1047. &menu2, -1);
  1048. else
  1049. menu2 = NULL; // force adding of a first child
  1050. #ifdef DEBUG
  1051. printf("%*c%s | %s\n", indent, ' ',
  1052. menu1 ? menu_get_prompt(menu1) : "nil",
  1053. menu2 ? menu_get_prompt(menu2) : "nil");
  1054. #endif
  1055. if ((opt_mode == OPT_NORMAL && !menu_is_visible(child1)) ||
  1056. (opt_mode == OPT_PROMPT && !menu_has_prompt(child1)) ||
  1057. (opt_mode == OPT_ALL && !menu_get_prompt(child1))) {
  1058. /* remove node */
  1059. if (gtktree_iter_find_node(dst, menu1) != NULL) {
  1060. memcpy(&tmp, child2, sizeof(GtkTreeIter));
  1061. valid = gtk_tree_model_iter_next(model2,
  1062. child2);
  1063. gtk_tree_store_remove(tree2, &tmp);
  1064. if (!valid)
  1065. return; /* next parent */
  1066. else
  1067. goto reparse; /* next child */
  1068. } else
  1069. continue;
  1070. }
  1071. if (menu1 != menu2) {
  1072. if (gtktree_iter_find_node(dst, menu1) == NULL) { // add node
  1073. if (!valid && !menu2)
  1074. sibling = NULL;
  1075. else
  1076. sibling = child2;
  1077. gtk_tree_store_insert_before(tree2,
  1078. child2,
  1079. dst, sibling);
  1080. set_node(child2, menu1, fill_row(menu1));
  1081. if (menu2 == NULL)
  1082. valid = TRUE;
  1083. } else { // remove node
  1084. memcpy(&tmp, child2, sizeof(GtkTreeIter));
  1085. valid = gtk_tree_model_iter_next(model2,
  1086. child2);
  1087. gtk_tree_store_remove(tree2, &tmp);
  1088. if (!valid)
  1089. return; // next parent
  1090. else
  1091. goto reparse; // next child
  1092. }
  1093. } else if (sym && (sym->flags & SYMBOL_CHANGED)) {
  1094. set_node(child2, menu1, fill_row(menu1));
  1095. }
  1096. indent++;
  1097. update_tree(child1, child2);
  1098. indent--;
  1099. valid = gtk_tree_model_iter_next(model2, child2);
  1100. }
  1101. }
  1102. /* Display the whole tree (single/split/full view) */
  1103. static void display_tree(struct menu *menu)
  1104. {
  1105. struct symbol *sym;
  1106. struct property *prop;
  1107. struct menu *child;
  1108. enum prop_type ptype;
  1109. if (menu == &rootmenu) {
  1110. indent = 1;
  1111. current = &rootmenu;
  1112. }
  1113. for (child = menu->list; child; child = child->next) {
  1114. prop = child->prompt;
  1115. sym = child->sym;
  1116. ptype = prop ? prop->type : P_UNKNOWN;
  1117. if (sym)
  1118. sym->flags &= ~SYMBOL_CHANGED;
  1119. if ((view_mode == SPLIT_VIEW)
  1120. && !(child->flags & MENU_ROOT) && (tree == tree1))
  1121. continue;
  1122. if ((view_mode == SPLIT_VIEW) && (child->flags & MENU_ROOT)
  1123. && (tree == tree2))
  1124. continue;
  1125. if ((opt_mode == OPT_NORMAL && menu_is_visible(child)) ||
  1126. (opt_mode == OPT_PROMPT && menu_has_prompt(child)) ||
  1127. (opt_mode == OPT_ALL && menu_get_prompt(child)))
  1128. place_node(child, fill_row(child));
  1129. #ifdef DEBUG
  1130. printf("%*c%s: ", indent, ' ', menu_get_prompt(child));
  1131. printf("%s", child->flags & MENU_ROOT ? "rootmenu | " : "");
  1132. printf("%s", prop_get_type_name(ptype));
  1133. printf(" | ");
  1134. if (sym) {
  1135. printf("%s", sym_type_name(sym->type));
  1136. printf(" | ");
  1137. printf("%s", dbg_sym_flags(sym->flags));
  1138. printf("\n");
  1139. } else
  1140. printf("\n");
  1141. #endif
  1142. if ((view_mode != FULL_VIEW) && (ptype == P_MENU)
  1143. && (tree == tree2))
  1144. continue;
  1145. /*
  1146. if (((menu != &rootmenu) && !(menu->flags & MENU_ROOT))
  1147. || (view_mode == FULL_VIEW)
  1148. || (view_mode == SPLIT_VIEW))*/
  1149. /* Change paned position if the view is not in 'split mode' */
  1150. if (view_mode == SINGLE_VIEW || view_mode == FULL_VIEW) {
  1151. gtk_paned_set_position(GTK_PANED(hpaned), 0);
  1152. }
  1153. if (((view_mode == SINGLE_VIEW) && (menu->flags & MENU_ROOT))
  1154. || (view_mode == FULL_VIEW)
  1155. || (view_mode == SPLIT_VIEW)) {
  1156. indent++;
  1157. display_tree(child);
  1158. indent--;
  1159. }
  1160. }
  1161. }
  1162. /* Display a part of the tree starting at current node (single/split view) */
  1163. static void display_tree_part(void)
  1164. {
  1165. if (tree2)
  1166. gtk_tree_store_clear(tree2);
  1167. if (view_mode == SINGLE_VIEW)
  1168. display_tree(current);
  1169. else if (view_mode == SPLIT_VIEW)
  1170. display_tree(browsed);
  1171. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w));
  1172. }
  1173. /* Display the list in the left frame (split view) */
  1174. static void display_list(void)
  1175. {
  1176. if (tree1)
  1177. gtk_tree_store_clear(tree1);
  1178. tree = tree1;
  1179. display_tree(&rootmenu);
  1180. gtk_tree_view_expand_all(GTK_TREE_VIEW(tree1_w));
  1181. tree = tree2;
  1182. }
  1183. void fixup_rootmenu(struct menu *menu)
  1184. {
  1185. struct menu *child;
  1186. static int menu_cnt = 0;
  1187. menu->flags |= MENU_ROOT;
  1188. for (child = menu->list; child; child = child->next) {
  1189. if (child->prompt && child->prompt->type == P_MENU) {
  1190. menu_cnt++;
  1191. fixup_rootmenu(child);
  1192. menu_cnt--;
  1193. } else if (!menu_cnt)
  1194. fixup_rootmenu(child);
  1195. }
  1196. }
  1197. /* Main */
  1198. int main(int ac, char *av[])
  1199. {
  1200. const char *name;
  1201. char *env;
  1202. gchar *glade_file;
  1203. /* GTK stuffs */
  1204. gtk_set_locale();
  1205. gtk_init(&ac, &av);
  1206. glade_init();
  1207. //add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
  1208. //add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
  1209. /* Determine GUI path */
  1210. env = getenv(SRCTREE);
  1211. if (env)
  1212. glade_file = g_strconcat(env, "/scripts/kconfig/gconf.glade", NULL);
  1213. else if (av[0][0] == '/')
  1214. glade_file = g_strconcat(av[0], ".glade", NULL);
  1215. else
  1216. glade_file = g_strconcat(g_get_current_dir(), "/", av[0], ".glade", NULL);
  1217. /* Conf stuffs */
  1218. if (ac > 1 && av[1][0] == '-') {
  1219. switch (av[1][1]) {
  1220. case 'a':
  1221. //showAll = 1;
  1222. break;
  1223. case 's':
  1224. conf_set_message_callback(NULL);
  1225. break;
  1226. case 'h':
  1227. case '?':
  1228. printf("%s [-s] <config>\n", av[0]);
  1229. exit(0);
  1230. }
  1231. name = av[2];
  1232. } else
  1233. name = av[1];
  1234. conf_parse(name);
  1235. fixup_rootmenu(&rootmenu);
  1236. conf_read(NULL);
  1237. /* Load the interface and connect signals */
  1238. init_main_window(glade_file);
  1239. init_tree_model();
  1240. init_left_tree();
  1241. init_right_tree();
  1242. switch (view_mode) {
  1243. case SINGLE_VIEW:
  1244. display_tree_part();
  1245. break;
  1246. case SPLIT_VIEW:
  1247. display_list();
  1248. break;
  1249. case FULL_VIEW:
  1250. display_tree(&rootmenu);
  1251. break;
  1252. }
  1253. gtk_main();
  1254. return 0;
  1255. }
  1256. static void conf_changed(void)
  1257. {
  1258. bool changed = conf_get_changed();
  1259. gtk_widget_set_sensitive(save_btn, changed);
  1260. gtk_widget_set_sensitive(save_menu_item, changed);
  1261. }