1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2002-2003 Romain Lievin <roms@tilp.info>
14 #include <glade/glade.h>
17 #include <gdk/gdkkeysyms.h>
28 SINGLE_VIEW
, SPLIT_VIEW
, FULL_VIEW
32 OPT_NORMAL
, OPT_ALL
, OPT_PROMPT
35 static gint view_mode
= FULL_VIEW
;
36 static gboolean show_name
= TRUE
;
37 static gboolean show_range
= TRUE
;
38 static gboolean show_value
= TRUE
;
39 static gboolean resizeable
= FALSE
;
40 static int opt_mode
= OPT_NORMAL
;
42 GtkWidget
*main_wnd
= NULL
;
43 GtkWidget
*tree1_w
= NULL
; // left frame
44 GtkWidget
*tree2_w
= NULL
; // right frame
45 GtkWidget
*text_w
= NULL
;
46 GtkWidget
*hpaned
= NULL
;
47 GtkWidget
*vpaned
= NULL
;
48 GtkWidget
*back_btn
= NULL
;
49 GtkWidget
*save_btn
= NULL
;
50 GtkWidget
*save_menu_item
= NULL
;
52 GtkTextTag
*tag1
, *tag2
;
55 GtkTreeStore
*tree1
, *tree2
, *tree
;
56 GtkTreeModel
*model1
, *model2
;
57 static GtkTreeIter
*parents
[256];
60 static struct menu
*current
; // current node for SINGLE view
61 static struct menu
*browsed
; // browsed node for SPLIT view
64 COL_OPTION
, COL_NAME
, COL_NO
, COL_MOD
, COL_YES
, COL_VALUE
,
65 COL_MENU
, COL_COLOR
, COL_EDIT
, COL_PIXBUF
,
66 COL_PIXVIS
, COL_BTNVIS
, COL_BTNACT
, COL_BTNINC
, COL_BTNRAD
,
70 static void display_list(void);
71 static void display_tree(struct menu
*menu
);
72 static void display_tree_part(void);
73 static void update_tree(struct menu
*src
, GtkTreeIter
* dst
);
74 static void set_node(GtkTreeIter
* node
, struct menu
*menu
, gchar
** row
);
75 static gchar
**fill_row(struct menu
*menu
);
76 static void conf_changed(void);
78 /* Helping/Debugging Functions */
80 static const char *dbg_sym_flags(int val
)
86 if (val
& SYMBOL_CONST
)
87 strcat(buf
, "const/");
88 if (val
& SYMBOL_CHECK
)
89 strcat(buf
, "check/");
90 if (val
& SYMBOL_CHOICE
)
91 strcat(buf
, "choice/");
92 if (val
& SYMBOL_CHOICEVAL
)
93 strcat(buf
, "choiceval/");
94 if (val
& SYMBOL_VALID
)
95 strcat(buf
, "valid/");
96 if (val
& SYMBOL_OPTIONAL
)
97 strcat(buf
, "optional/");
98 if (val
& SYMBOL_WRITE
)
99 strcat(buf
, "write/");
100 if (val
& SYMBOL_CHANGED
)
101 strcat(buf
, "changed/");
102 if (val
& SYMBOL_NO_WRITE
)
103 strcat(buf
, "no_write/");
105 buf
[strlen(buf
) - 1] = '\0';
111 static void replace_button_icon(GladeXML
*xml
, GdkDrawable
*window
,
112 GtkStyle
*style
, gchar
*btn_name
, gchar
**xpm
)
116 GtkToolButton
*button
;
119 pixmap
= gdk_pixmap_create_from_xpm_d(window
, &mask
,
120 &style
->bg
[GTK_STATE_NORMAL
],
123 button
= GTK_TOOL_BUTTON(glade_xml_get_widget(xml
, btn_name
));
124 image
= gtk_image_new_from_pixmap(pixmap
, mask
);
125 gtk_widget_show(image
);
126 gtk_tool_button_set_icon_widget(button
, image
);
129 /* Main Window Initialization */
130 static void init_main_window(const gchar
*glade_file
)
134 GtkTextBuffer
*txtbuf
;
137 xml
= glade_xml_new(glade_file
, "window1", NULL
);
139 g_error("GUI loading failed !\n");
140 glade_xml_signal_autoconnect(xml
);
142 main_wnd
= glade_xml_get_widget(xml
, "window1");
143 hpaned
= glade_xml_get_widget(xml
, "hpaned1");
144 vpaned
= glade_xml_get_widget(xml
, "vpaned1");
145 tree1_w
= glade_xml_get_widget(xml
, "treeview1");
146 tree2_w
= glade_xml_get_widget(xml
, "treeview2");
147 text_w
= glade_xml_get_widget(xml
, "textview3");
149 back_btn
= glade_xml_get_widget(xml
, "button1");
150 gtk_widget_set_sensitive(back_btn
, FALSE
);
152 widget
= glade_xml_get_widget(xml
, "show_name1");
153 gtk_check_menu_item_set_active((GtkCheckMenuItem
*) widget
,
156 widget
= glade_xml_get_widget(xml
, "show_range1");
157 gtk_check_menu_item_set_active((GtkCheckMenuItem
*) widget
,
160 widget
= glade_xml_get_widget(xml
, "show_data1");
161 gtk_check_menu_item_set_active((GtkCheckMenuItem
*) widget
,
164 save_btn
= glade_xml_get_widget(xml
, "button3");
165 save_menu_item
= glade_xml_get_widget(xml
, "save1");
166 conf_set_changed_callback(conf_changed
);
168 style
= gtk_widget_get_style(main_wnd
);
169 widget
= glade_xml_get_widget(xml
, "toolbar1");
171 replace_button_icon(xml
, main_wnd
->window
, style
,
172 "button4", (gchar
**) xpm_single_view
);
173 replace_button_icon(xml
, main_wnd
->window
, style
,
174 "button5", (gchar
**) xpm_split_view
);
175 replace_button_icon(xml
, main_wnd
->window
, style
,
176 "button6", (gchar
**) xpm_tree_view
);
178 txtbuf
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w
));
179 tag1
= gtk_text_buffer_create_tag(txtbuf
, "mytag1",
181 "weight", PANGO_WEIGHT_BOLD
,
183 tag2
= gtk_text_buffer_create_tag(txtbuf
, "mytag2",
184 /*"style", PANGO_STYLE_OBLIQUE, */
187 gtk_window_set_title(GTK_WINDOW(main_wnd
), rootmenu
.prompt
->text
);
189 gtk_widget_show(main_wnd
);
192 static void init_tree_model(void)
196 tree
= tree2
= gtk_tree_store_new(COL_NUMBER
,
197 G_TYPE_STRING
, G_TYPE_STRING
,
198 G_TYPE_STRING
, G_TYPE_STRING
,
199 G_TYPE_STRING
, G_TYPE_STRING
,
200 G_TYPE_POINTER
, GDK_TYPE_COLOR
,
201 G_TYPE_BOOLEAN
, GDK_TYPE_PIXBUF
,
202 G_TYPE_BOOLEAN
, G_TYPE_BOOLEAN
,
203 G_TYPE_BOOLEAN
, G_TYPE_BOOLEAN
,
205 model2
= GTK_TREE_MODEL(tree2
);
207 for (parents
[0] = NULL
, i
= 1; i
< 256; i
++)
208 parents
[i
] = (GtkTreeIter
*) g_malloc(sizeof(GtkTreeIter
));
210 tree1
= gtk_tree_store_new(COL_NUMBER
,
211 G_TYPE_STRING
, G_TYPE_STRING
,
212 G_TYPE_STRING
, G_TYPE_STRING
,
213 G_TYPE_STRING
, G_TYPE_STRING
,
214 G_TYPE_POINTER
, GDK_TYPE_COLOR
,
215 G_TYPE_BOOLEAN
, GDK_TYPE_PIXBUF
,
216 G_TYPE_BOOLEAN
, G_TYPE_BOOLEAN
,
217 G_TYPE_BOOLEAN
, G_TYPE_BOOLEAN
,
219 model1
= GTK_TREE_MODEL(tree1
);
222 static void init_left_tree(void)
224 GtkTreeView
*view
= GTK_TREE_VIEW(tree1_w
);
225 GtkCellRenderer
*renderer
;
226 GtkTreeSelection
*sel
;
227 GtkTreeViewColumn
*column
;
229 gtk_tree_view_set_model(view
, model1
);
230 gtk_tree_view_set_headers_visible(view
, TRUE
);
231 gtk_tree_view_set_rules_hint(view
, TRUE
);
233 column
= gtk_tree_view_column_new();
234 gtk_tree_view_append_column(view
, column
);
235 gtk_tree_view_column_set_title(column
, "Options");
237 renderer
= gtk_cell_renderer_toggle_new();
238 gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column
),
240 gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column
),
242 "active", COL_BTNACT
,
243 "inconsistent", COL_BTNINC
,
244 "visible", COL_BTNVIS
,
245 "radio", COL_BTNRAD
, NULL
);
246 renderer
= gtk_cell_renderer_text_new();
247 gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column
),
249 gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column
),
255 sel
= gtk_tree_view_get_selection(view
);
256 gtk_tree_selection_set_mode(sel
, GTK_SELECTION_SINGLE
);
257 gtk_widget_realize(tree1_w
);
260 static void renderer_edited(GtkCellRendererText
* cell
,
261 const gchar
* path_string
,
262 const gchar
* new_text
, gpointer user_data
);
264 static void init_right_tree(void)
266 GtkTreeView
*view
= GTK_TREE_VIEW(tree2_w
);
267 GtkCellRenderer
*renderer
;
268 GtkTreeSelection
*sel
;
269 GtkTreeViewColumn
*column
;
272 gtk_tree_view_set_model(view
, model2
);
273 gtk_tree_view_set_headers_visible(view
, TRUE
);
274 gtk_tree_view_set_rules_hint(view
, TRUE
);
276 column
= gtk_tree_view_column_new();
277 gtk_tree_view_append_column(view
, column
);
278 gtk_tree_view_column_set_title(column
, "Options");
280 renderer
= gtk_cell_renderer_pixbuf_new();
281 gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column
),
283 gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column
),
285 "pixbuf", COL_PIXBUF
,
286 "visible", COL_PIXVIS
, NULL
);
287 renderer
= gtk_cell_renderer_toggle_new();
288 gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column
),
290 gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column
),
292 "active", COL_BTNACT
,
293 "inconsistent", COL_BTNINC
,
294 "visible", COL_BTNVIS
,
295 "radio", COL_BTNRAD
, NULL
);
296 renderer
= gtk_cell_renderer_text_new();
297 gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column
),
299 gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column
),
305 renderer
= gtk_cell_renderer_text_new();
306 gtk_tree_view_insert_column_with_attributes(view
, -1,
311 renderer
= gtk_cell_renderer_text_new();
312 gtk_tree_view_insert_column_with_attributes(view
, -1,
317 renderer
= gtk_cell_renderer_text_new();
318 gtk_tree_view_insert_column_with_attributes(view
, -1,
323 renderer
= gtk_cell_renderer_text_new();
324 gtk_tree_view_insert_column_with_attributes(view
, -1,
329 renderer
= gtk_cell_renderer_text_new();
330 gtk_tree_view_insert_column_with_attributes(view
, -1,
337 g_signal_connect(G_OBJECT(renderer
), "edited",
338 G_CALLBACK(renderer_edited
), NULL
);
340 column
= gtk_tree_view_get_column(view
, COL_NAME
);
341 gtk_tree_view_column_set_visible(column
, show_name
);
342 column
= gtk_tree_view_get_column(view
, COL_NO
);
343 gtk_tree_view_column_set_visible(column
, show_range
);
344 column
= gtk_tree_view_get_column(view
, COL_MOD
);
345 gtk_tree_view_column_set_visible(column
, show_range
);
346 column
= gtk_tree_view_get_column(view
, COL_YES
);
347 gtk_tree_view_column_set_visible(column
, show_range
);
348 column
= gtk_tree_view_get_column(view
, COL_VALUE
);
349 gtk_tree_view_column_set_visible(column
, show_value
);
352 for (i
= 0; i
< COL_VALUE
; i
++) {
353 column
= gtk_tree_view_get_column(view
, i
);
354 gtk_tree_view_column_set_resizable(column
, TRUE
);
358 sel
= gtk_tree_view_get_selection(view
);
359 gtk_tree_selection_set_mode(sel
, GTK_SELECTION_SINGLE
);
363 /* Utility Functions */
366 static void text_insert_help(struct menu
*menu
)
368 GtkTextBuffer
*buffer
;
369 GtkTextIter start
, end
;
370 const char *prompt
= menu_get_prompt(menu
);
371 struct gstr help
= str_new();
373 menu_get_ext_help(menu
, &help
);
375 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w
));
376 gtk_text_buffer_get_bounds(buffer
, &start
, &end
);
377 gtk_text_buffer_delete(buffer
, &start
, &end
);
378 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_w
), 15);
380 gtk_text_buffer_get_end_iter(buffer
, &end
);
381 gtk_text_buffer_insert_with_tags(buffer
, &end
, prompt
, -1, tag1
,
383 gtk_text_buffer_insert_at_cursor(buffer
, "\n\n", 2);
384 gtk_text_buffer_get_end_iter(buffer
, &end
);
385 gtk_text_buffer_insert_with_tags(buffer
, &end
, str_get(&help
), -1, tag2
,
391 static void text_insert_msg(const char *title
, const char *message
)
393 GtkTextBuffer
*buffer
;
394 GtkTextIter start
, end
;
395 const char *msg
= message
;
397 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w
));
398 gtk_text_buffer_get_bounds(buffer
, &start
, &end
);
399 gtk_text_buffer_delete(buffer
, &start
, &end
);
400 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_w
), 15);
402 gtk_text_buffer_get_end_iter(buffer
, &end
);
403 gtk_text_buffer_insert_with_tags(buffer
, &end
, title
, -1, tag1
,
405 gtk_text_buffer_insert_at_cursor(buffer
, "\n\n", 2);
406 gtk_text_buffer_get_end_iter(buffer
, &end
);
407 gtk_text_buffer_insert_with_tags(buffer
, &end
, msg
, -1, tag2
,
412 /* Main Windows Callbacks */
414 void on_save_activate(GtkMenuItem
* menuitem
, gpointer user_data
);
415 gboolean
on_window1_delete_event(GtkWidget
* widget
, GdkEvent
* event
,
418 GtkWidget
*dialog
, *label
;
421 if (!conf_get_changed())
424 dialog
= gtk_dialog_new_with_buttons("Warning !",
425 GTK_WINDOW(main_wnd
),
428 GTK_DIALOG_DESTROY_WITH_PARENT
),
434 GTK_RESPONSE_CANCEL
, NULL
);
435 gtk_dialog_set_default_response(GTK_DIALOG(dialog
),
436 GTK_RESPONSE_CANCEL
);
438 label
= gtk_label_new("\nSave configuration ?\n");
439 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), label
);
440 gtk_widget_show(label
);
442 result
= gtk_dialog_run(GTK_DIALOG(dialog
));
444 case GTK_RESPONSE_YES
:
445 on_save_activate(NULL
, NULL
);
447 case GTK_RESPONSE_NO
:
449 case GTK_RESPONSE_CANCEL
:
450 case GTK_RESPONSE_DELETE_EVENT
:
452 gtk_widget_destroy(dialog
);
460 void on_window1_destroy(GtkObject
* object
, gpointer user_data
)
467 on_window1_size_request(GtkWidget
* widget
,
468 GtkRequisition
* requisition
, gpointer user_data
)
473 if (widget
->window
== NULL
)
474 gtk_window_get_default_size(GTK_WINDOW(main_wnd
), &w
, &h
);
476 gdk_window_get_size(widget
->window
, &w
, &h
);
482 gtk_paned_set_position(GTK_PANED(vpaned
), 2 * h
/ 3);
486 /* Menu & Toolbar Callbacks */
490 load_filename(GtkFileSelection
* file_selector
, gpointer user_data
)
494 fn
= gtk_file_selection_get_filename(GTK_FILE_SELECTION
498 text_insert_msg("Error", "Unable to load configuration !");
500 display_tree(&rootmenu
);
503 void on_load1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
507 fs
= gtk_file_selection_new("Load file...");
508 g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs
)->ok_button
),
510 G_CALLBACK(load_filename
), (gpointer
) fs
);
511 g_signal_connect_swapped(GTK_OBJECT
512 (GTK_FILE_SELECTION(fs
)->ok_button
),
513 "clicked", G_CALLBACK(gtk_widget_destroy
),
515 g_signal_connect_swapped(GTK_OBJECT
516 (GTK_FILE_SELECTION(fs
)->cancel_button
),
517 "clicked", G_CALLBACK(gtk_widget_destroy
),
523 void on_save_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
525 if (conf_write(NULL
))
526 text_insert_msg("Error", "Unable to save configuration !");
527 conf_write_autoconf(0);
532 store_filename(GtkFileSelection
* file_selector
, gpointer user_data
)
536 fn
= gtk_file_selection_get_filename(GTK_FILE_SELECTION
540 text_insert_msg("Error", "Unable to save configuration !");
542 gtk_widget_destroy(GTK_WIDGET(user_data
));
545 void on_save_as1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
549 fs
= gtk_file_selection_new("Save file as...");
550 g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs
)->ok_button
),
552 G_CALLBACK(store_filename
), (gpointer
) fs
);
553 g_signal_connect_swapped(GTK_OBJECT
554 (GTK_FILE_SELECTION(fs
)->ok_button
),
555 "clicked", G_CALLBACK(gtk_widget_destroy
),
557 g_signal_connect_swapped(GTK_OBJECT
558 (GTK_FILE_SELECTION(fs
)->cancel_button
),
559 "clicked", G_CALLBACK(gtk_widget_destroy
),
565 void on_quit1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
567 if (!on_window1_delete_event(NULL
, NULL
, NULL
))
568 gtk_widget_destroy(GTK_WIDGET(main_wnd
));
572 void on_show_name1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
574 GtkTreeViewColumn
*col
;
576 show_name
= GTK_CHECK_MENU_ITEM(menuitem
)->active
;
577 col
= gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w
), COL_NAME
);
579 gtk_tree_view_column_set_visible(col
, show_name
);
583 void on_show_range1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
585 GtkTreeViewColumn
*col
;
587 show_range
= GTK_CHECK_MENU_ITEM(menuitem
)->active
;
588 col
= gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w
), COL_NO
);
590 gtk_tree_view_column_set_visible(col
, show_range
);
591 col
= gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w
), COL_MOD
);
593 gtk_tree_view_column_set_visible(col
, show_range
);
594 col
= gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w
), COL_YES
);
596 gtk_tree_view_column_set_visible(col
, show_range
);
601 void on_show_data1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
603 GtkTreeViewColumn
*col
;
605 show_value
= GTK_CHECK_MENU_ITEM(menuitem
)->active
;
606 col
= gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w
), COL_VALUE
);
608 gtk_tree_view_column_set_visible(col
, show_value
);
613 on_set_option_mode1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
615 opt_mode
= OPT_NORMAL
;
616 gtk_tree_store_clear(tree2
);
617 display_tree(&rootmenu
); /* instead of update_tree to speed-up */
622 on_set_option_mode2_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
625 gtk_tree_store_clear(tree2
);
626 display_tree(&rootmenu
); /* instead of update_tree to speed-up */
631 on_set_option_mode3_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
633 opt_mode
= OPT_PROMPT
;
634 gtk_tree_store_clear(tree2
);
635 display_tree(&rootmenu
); /* instead of update_tree to speed-up */
639 void on_introduction1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
642 const gchar
*intro_text
=
643 "Welcome to gkc, the GTK+ graphical configuration tool\n"
644 "For each option, a blank box indicates the feature is disabled, a\n"
645 "check indicates it is enabled, and a dot indicates that it is to\n"
646 "be compiled as a module. Clicking on the box will cycle through the three states.\n"
648 "If you do not see an option (e.g., a device driver) that you\n"
649 "believe should be present, try turning on Show All Options\n"
650 "under the Options menu.\n"
651 "Although there is no cross reference yet to help you figure out\n"
652 "what other options must be enabled to support the option you\n"
653 "are interested in, you can still view the help of a grayed-out\n"
656 "Toggling Show Debug Info under the Options menu will show \n"
657 "the dependencies, which you can then match by examining other options.";
659 dialog
= gtk_message_dialog_new(GTK_WINDOW(main_wnd
),
660 GTK_DIALOG_DESTROY_WITH_PARENT
,
662 GTK_BUTTONS_CLOSE
, "%s", intro_text
);
663 g_signal_connect_swapped(GTK_OBJECT(dialog
), "response",
664 G_CALLBACK(gtk_widget_destroy
),
666 gtk_widget_show_all(dialog
);
670 void on_about1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
673 const gchar
*about_text
=
674 "gkc is copyright (c) 2002 Romain Lievin <roms@lpg.ticalc.org>.\n"
675 "Based on the source code from Roman Zippel.\n";
677 dialog
= gtk_message_dialog_new(GTK_WINDOW(main_wnd
),
678 GTK_DIALOG_DESTROY_WITH_PARENT
,
680 GTK_BUTTONS_CLOSE
, "%s", about_text
);
681 g_signal_connect_swapped(GTK_OBJECT(dialog
), "response",
682 G_CALLBACK(gtk_widget_destroy
),
684 gtk_widget_show_all(dialog
);
688 void on_license1_activate(GtkMenuItem
* menuitem
, gpointer user_data
)
691 const gchar
*license_text
=
692 "gkc is released under the terms of the GNU GPL v2.\n"
693 "For more information, please see the source code or\n"
694 "visit http://www.fsf.org/licenses/licenses.html\n";
696 dialog
= gtk_message_dialog_new(GTK_WINDOW(main_wnd
),
697 GTK_DIALOG_DESTROY_WITH_PARENT
,
699 GTK_BUTTONS_CLOSE
, "%s", license_text
);
700 g_signal_connect_swapped(GTK_OBJECT(dialog
), "response",
701 G_CALLBACK(gtk_widget_destroy
),
703 gtk_widget_show_all(dialog
);
707 void on_back_clicked(GtkButton
* button
, gpointer user_data
)
709 enum prop_type ptype
;
711 current
= current
->parent
;
712 ptype
= current
->prompt
? current
->prompt
->type
: P_UNKNOWN
;
714 current
= current
->parent
;
717 if (current
== &rootmenu
)
718 gtk_widget_set_sensitive(back_btn
, FALSE
);
722 void on_load_clicked(GtkButton
* button
, gpointer user_data
)
724 on_load1_activate(NULL
, user_data
);
728 void on_single_clicked(GtkButton
* button
, gpointer user_data
)
730 view_mode
= SINGLE_VIEW
;
731 gtk_widget_hide(tree1_w
);
737 void on_split_clicked(GtkButton
* button
, gpointer user_data
)
740 view_mode
= SPLIT_VIEW
;
741 gtk_widget_show(tree1_w
);
742 gtk_window_get_default_size(GTK_WINDOW(main_wnd
), &w
, &h
);
743 gtk_paned_set_position(GTK_PANED(hpaned
), w
/ 2);
745 gtk_tree_store_clear(tree2
);
748 /* Disable back btn, like in full mode. */
749 gtk_widget_set_sensitive(back_btn
, FALSE
);
753 void on_full_clicked(GtkButton
* button
, gpointer user_data
)
755 view_mode
= FULL_VIEW
;
756 gtk_widget_hide(tree1_w
);
758 gtk_tree_store_clear(tree2
);
759 display_tree(&rootmenu
);
760 gtk_widget_set_sensitive(back_btn
, FALSE
);
764 void on_collapse_clicked(GtkButton
* button
, gpointer user_data
)
766 gtk_tree_view_collapse_all(GTK_TREE_VIEW(tree2_w
));
770 void on_expand_clicked(GtkButton
* button
, gpointer user_data
)
772 gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w
));
776 /* CTree Callbacks */
778 /* Change hex/int/string value in the cell */
779 static void renderer_edited(GtkCellRendererText
* cell
,
780 const gchar
* path_string
,
781 const gchar
* new_text
, gpointer user_data
)
783 GtkTreePath
*path
= gtk_tree_path_new_from_string(path_string
);
785 const char *old_def
, *new_def
;
789 if (!gtk_tree_model_get_iter(model2
, &iter
, path
))
792 gtk_tree_model_get(model2
, &iter
, COL_MENU
, &menu
, -1);
795 gtk_tree_model_get(model2
, &iter
, COL_VALUE
, &old_def
, -1);
798 sym_set_string_value(sym
, new_def
);
800 update_tree(&rootmenu
, NULL
);
802 gtk_tree_path_free(path
);
805 /* Change the value of a symbol and update the tree */
806 static void change_sym_value(struct menu
*menu
, gint col
)
808 struct symbol
*sym
= menu
->sym
;
816 else if (col
== COL_MOD
)
818 else if (col
== COL_YES
)
823 switch (sym_get_type(sym
)) {
826 if (!sym_tristate_within_range(sym
, newval
))
828 sym_set_tristate_value(sym
, newval
);
829 if (view_mode
== FULL_VIEW
)
830 update_tree(&rootmenu
, NULL
);
831 else if (view_mode
== SPLIT_VIEW
) {
832 update_tree(browsed
, NULL
);
835 else if (view_mode
== SINGLE_VIEW
)
836 display_tree_part(); //fixme: keep exp/coll
846 static void toggle_sym_value(struct menu
*menu
)
851 sym_toggle_tristate_value(menu
->sym
);
852 if (view_mode
== FULL_VIEW
)
853 update_tree(&rootmenu
, NULL
);
854 else if (view_mode
== SPLIT_VIEW
) {
855 update_tree(browsed
, NULL
);
858 else if (view_mode
== SINGLE_VIEW
)
859 display_tree_part(); //fixme: keep exp/coll
862 static gint
column2index(GtkTreeViewColumn
* column
)
866 for (i
= 0; i
< COL_NUMBER
; i
++) {
867 GtkTreeViewColumn
*col
;
869 col
= gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w
), i
);
878 /* User click: update choice (full) or goes down (single) */
880 on_treeview2_button_press_event(GtkWidget
* widget
,
881 GdkEventButton
* event
, gpointer user_data
)
883 GtkTreeView
*view
= GTK_TREE_VIEW(widget
);
885 GtkTreeViewColumn
*column
;
890 #if GTK_CHECK_VERSION(2,1,4) // bug in ctree with earlier version of GTK
891 gint tx
= (gint
) event
->x
;
892 gint ty
= (gint
) event
->y
;
895 gtk_tree_view_get_path_at_pos(view
, tx
, ty
, &path
, &column
, &cx
,
898 gtk_tree_view_get_cursor(view
, &path
, &column
);
903 if (!gtk_tree_model_get_iter(model2
, &iter
, path
))
905 gtk_tree_model_get(model2
, &iter
, COL_MENU
, &menu
, -1);
907 col
= column2index(column
);
908 if (event
->type
== GDK_2BUTTON_PRESS
) {
909 enum prop_type ptype
;
910 ptype
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
912 if (ptype
== P_MENU
&& view_mode
!= FULL_VIEW
&& col
== COL_OPTION
) {
913 // goes down into menu
916 gtk_widget_set_sensitive(back_btn
, TRUE
);
917 } else if (col
== COL_OPTION
) {
918 toggle_sym_value(menu
);
919 gtk_tree_view_expand_row(view
, path
, TRUE
);
922 if (col
== COL_VALUE
) {
923 toggle_sym_value(menu
);
924 gtk_tree_view_expand_row(view
, path
, TRUE
);
925 } else if (col
== COL_NO
|| col
== COL_MOD
927 change_sym_value(menu
, col
);
928 gtk_tree_view_expand_row(view
, path
, TRUE
);
935 /* Key pressed: update choice */
937 on_treeview2_key_press_event(GtkWidget
* widget
,
938 GdkEventKey
* event
, gpointer user_data
)
940 GtkTreeView
*view
= GTK_TREE_VIEW(widget
);
942 GtkTreeViewColumn
*column
;
947 gtk_tree_view_get_cursor(view
, &path
, &column
);
951 if (event
->keyval
== GDK_space
) {
952 if (gtk_tree_view_row_expanded(view
, path
))
953 gtk_tree_view_collapse_row(view
, path
);
955 gtk_tree_view_expand_row(view
, path
, FALSE
);
958 if (event
->keyval
== GDK_KP_Enter
) {
960 if (widget
== tree1_w
)
963 gtk_tree_model_get_iter(model2
, &iter
, path
);
964 gtk_tree_model_get(model2
, &iter
, COL_MENU
, &menu
, -1);
966 if (!strcasecmp(event
->string
, "n"))
968 else if (!strcasecmp(event
->string
, "m"))
970 else if (!strcasecmp(event
->string
, "y"))
974 change_sym_value(menu
, col
);
980 /* Row selection changed: update help */
982 on_treeview2_cursor_changed(GtkTreeView
* treeview
, gpointer user_data
)
984 GtkTreeSelection
*selection
;
988 selection
= gtk_tree_view_get_selection(treeview
);
989 if (gtk_tree_selection_get_selected(selection
, &model2
, &iter
)) {
990 gtk_tree_model_get(model2
, &iter
, COL_MENU
, &menu
, -1);
991 text_insert_help(menu
);
996 /* User click: display sub-tree in the right frame. */
998 on_treeview1_button_press_event(GtkWidget
* widget
,
999 GdkEventButton
* event
, gpointer user_data
)
1001 GtkTreeView
*view
= GTK_TREE_VIEW(widget
);
1003 GtkTreeViewColumn
*column
;
1007 gint tx
= (gint
) event
->x
;
1008 gint ty
= (gint
) event
->y
;
1011 gtk_tree_view_get_path_at_pos(view
, tx
, ty
, &path
, &column
, &cx
,
1016 gtk_tree_model_get_iter(model1
, &iter
, path
);
1017 gtk_tree_model_get(model1
, &iter
, COL_MENU
, &menu
, -1);
1019 if (event
->type
== GDK_2BUTTON_PRESS
) {
1020 toggle_sym_value(menu
);
1022 display_tree_part();
1025 display_tree_part();
1028 gtk_widget_realize(tree2_w
);
1029 gtk_tree_view_set_cursor(view
, path
, NULL
, FALSE
);
1030 gtk_widget_grab_focus(tree2_w
);
1036 /* Fill a row of strings */
1037 static gchar
**fill_row(struct menu
*menu
)
1039 static gchar
*row
[COL_NUMBER
];
1040 struct symbol
*sym
= menu
->sym
;
1044 enum prop_type ptype
;
1047 for (i
= COL_OPTION
; i
<= COL_COLOR
; i
++)
1049 bzero(row
, sizeof(row
));
1052 g_strdup_printf("%s %s", menu_get_prompt(menu
),
1053 sym
&& !sym_has_value(sym
) ? "(NEW)" : "");
1055 if (opt_mode
== OPT_ALL
&& !menu_is_visible(menu
))
1056 row
[COL_COLOR
] = g_strdup("DarkGray");
1057 else if (opt_mode
== OPT_PROMPT
&&
1058 menu_has_prompt(menu
) && !menu_is_visible(menu
))
1059 row
[COL_COLOR
] = g_strdup("DarkGray");
1061 row
[COL_COLOR
] = g_strdup("Black");
1063 ptype
= menu
->prompt
? menu
->prompt
->type
: P_UNKNOWN
;
1066 row
[COL_PIXBUF
] = (gchar
*) xpm_menu
;
1067 if (view_mode
== SINGLE_VIEW
)
1068 row
[COL_PIXVIS
] = GINT_TO_POINTER(TRUE
);
1069 row
[COL_BTNVIS
] = GINT_TO_POINTER(FALSE
);
1072 row
[COL_PIXBUF
] = (gchar
*) xpm_void
;
1073 row
[COL_PIXVIS
] = GINT_TO_POINTER(FALSE
);
1074 row
[COL_BTNVIS
] = GINT_TO_POINTER(FALSE
);
1077 row
[COL_PIXBUF
] = (gchar
*) xpm_void
;
1078 row
[COL_PIXVIS
] = GINT_TO_POINTER(FALSE
);
1079 row
[COL_BTNVIS
] = GINT_TO_POINTER(TRUE
);
1085 row
[COL_NAME
] = g_strdup(sym
->name
);
1087 sym_calc_value(sym
);
1088 sym
->flags
&= ~SYMBOL_CHANGED
;
1090 if (sym_is_choice(sym
)) { // parse childs for getting final value
1092 struct symbol
*def_sym
= sym_get_choice_value(sym
);
1093 struct menu
*def_menu
= NULL
;
1095 row
[COL_BTNVIS
] = GINT_TO_POINTER(FALSE
);
1097 for (child
= menu
->list
; child
; child
= child
->next
) {
1098 if (menu_is_visible(child
)
1099 && child
->sym
== def_sym
)
1105 g_strdup(menu_get_prompt(def_menu
));
1107 if (sym
->flags
& SYMBOL_CHOICEVAL
)
1108 row
[COL_BTNRAD
] = GINT_TO_POINTER(TRUE
);
1110 stype
= sym_get_type(sym
);
1113 if (GPOINTER_TO_INT(row
[COL_PIXVIS
]) == FALSE
)
1114 row
[COL_BTNVIS
] = GINT_TO_POINTER(TRUE
);
1115 if (sym_is_choice(sym
))
1119 val
= sym_get_tristate_value(sym
);
1122 row
[COL_NO
] = g_strdup("N");
1123 row
[COL_VALUE
] = g_strdup("N");
1124 row
[COL_BTNACT
] = GINT_TO_POINTER(FALSE
);
1125 row
[COL_BTNINC
] = GINT_TO_POINTER(FALSE
);
1128 row
[COL_MOD
] = g_strdup("M");
1129 row
[COL_VALUE
] = g_strdup("M");
1130 row
[COL_BTNINC
] = GINT_TO_POINTER(TRUE
);
1133 row
[COL_YES
] = g_strdup("Y");
1134 row
[COL_VALUE
] = g_strdup("Y");
1135 row
[COL_BTNACT
] = GINT_TO_POINTER(TRUE
);
1136 row
[COL_BTNINC
] = GINT_TO_POINTER(FALSE
);
1140 if (val
!= no
&& sym_tristate_within_range(sym
, no
))
1141 row
[COL_NO
] = g_strdup("_");
1142 if (val
!= mod
&& sym_tristate_within_range(sym
, mod
))
1143 row
[COL_MOD
] = g_strdup("_");
1144 if (val
!= yes
&& sym_tristate_within_range(sym
, yes
))
1145 row
[COL_YES
] = g_strdup("_");
1150 def
= sym_get_string_value(sym
);
1151 row
[COL_VALUE
] = g_strdup(def
);
1152 row
[COL_EDIT
] = GINT_TO_POINTER(TRUE
);
1153 row
[COL_BTNVIS
] = GINT_TO_POINTER(FALSE
);
1161 /* Set the node content with a row of strings */
1162 static void set_node(GtkTreeIter
* node
, struct menu
*menu
, gchar
** row
)
1168 pix
= gdk_pixbuf_new_from_xpm_data((const char **)
1171 gdk_color_parse(row
[COL_COLOR
], &color
);
1172 gdk_colormap_alloc_colors(gdk_colormap_get_system(), &color
, 1,
1173 FALSE
, FALSE
, &success
);
1175 gtk_tree_store_set(tree
, node
,
1176 COL_OPTION
, row
[COL_OPTION
],
1177 COL_NAME
, row
[COL_NAME
],
1178 COL_NO
, row
[COL_NO
],
1179 COL_MOD
, row
[COL_MOD
],
1180 COL_YES
, row
[COL_YES
],
1181 COL_VALUE
, row
[COL_VALUE
],
1182 COL_MENU
, (gpointer
) menu
,
1184 COL_EDIT
, GPOINTER_TO_INT(row
[COL_EDIT
]),
1186 COL_PIXVIS
, GPOINTER_TO_INT(row
[COL_PIXVIS
]),
1187 COL_BTNVIS
, GPOINTER_TO_INT(row
[COL_BTNVIS
]),
1188 COL_BTNACT
, GPOINTER_TO_INT(row
[COL_BTNACT
]),
1189 COL_BTNINC
, GPOINTER_TO_INT(row
[COL_BTNINC
]),
1190 COL_BTNRAD
, GPOINTER_TO_INT(row
[COL_BTNRAD
]),
1193 g_object_unref(pix
);
1197 /* Add a node to the tree */
1198 static void place_node(struct menu
*menu
, char **row
)
1200 GtkTreeIter
*parent
= parents
[indent
- 1];
1201 GtkTreeIter
*node
= parents
[indent
];
1203 gtk_tree_store_append(tree
, node
, parent
);
1204 set_node(node
, menu
, row
);
1208 /* Find a node in the GTK+ tree */
1209 static GtkTreeIter found
;
1212 * Find a menu in the GtkTree starting at parent.
1214 static GtkTreeIter
*gtktree_iter_find_node(GtkTreeIter
*parent
,
1215 struct menu
*tofind
)
1218 GtkTreeIter
*child
= &iter
;
1222 valid
= gtk_tree_model_iter_children(model2
, child
, parent
);
1226 gtk_tree_model_get(model2
, child
, 6, &menu
, -1);
1228 if (menu
== tofind
) {
1229 memcpy(&found
, child
, sizeof(GtkTreeIter
));
1233 ret
= gtktree_iter_find_node(child
, tofind
);
1237 valid
= gtk_tree_model_iter_next(model2
, child
);
1245 * Update the tree by adding/removing entries
1246 * Does not change other nodes
1248 static void update_tree(struct menu
*src
, GtkTreeIter
* dst
)
1250 struct menu
*child1
;
1251 GtkTreeIter iter
, tmp
;
1252 GtkTreeIter
*child2
= &iter
;
1254 GtkTreeIter
*sibling
;
1256 struct menu
*menu1
, *menu2
;
1258 if (src
== &rootmenu
)
1261 valid
= gtk_tree_model_iter_children(model2
, child2
, dst
);
1262 for (child1
= src
->list
; child1
; child1
= child1
->next
) {
1269 gtk_tree_model_get(model2
, child2
, COL_MENU
,
1272 menu2
= NULL
; // force adding of a first child
1275 printf("%*c%s | %s\n", indent
, ' ',
1276 menu1
? menu_get_prompt(menu1
) : "nil",
1277 menu2
? menu_get_prompt(menu2
) : "nil");
1280 if ((opt_mode
== OPT_NORMAL
&& !menu_is_visible(child1
)) ||
1281 (opt_mode
== OPT_PROMPT
&& !menu_has_prompt(child1
)) ||
1282 (opt_mode
== OPT_ALL
&& !menu_get_prompt(child1
))) {
1285 if (gtktree_iter_find_node(dst
, menu1
) != NULL
) {
1286 memcpy(&tmp
, child2
, sizeof(GtkTreeIter
));
1287 valid
= gtk_tree_model_iter_next(model2
,
1289 gtk_tree_store_remove(tree2
, &tmp
);
1291 return; /* next parent */
1293 goto reparse
; /* next child */
1298 if (menu1
!= menu2
) {
1299 if (gtktree_iter_find_node(dst
, menu1
) == NULL
) { // add node
1300 if (!valid
&& !menu2
)
1304 gtk_tree_store_insert_before(tree2
,
1307 set_node(child2
, menu1
, fill_row(menu1
));
1310 } else { // remove node
1311 memcpy(&tmp
, child2
, sizeof(GtkTreeIter
));
1312 valid
= gtk_tree_model_iter_next(model2
,
1314 gtk_tree_store_remove(tree2
, &tmp
);
1316 return; // next parent
1318 goto reparse
; // next child
1320 } else if (sym
&& (sym
->flags
& SYMBOL_CHANGED
)) {
1321 set_node(child2
, menu1
, fill_row(menu1
));
1325 update_tree(child1
, child2
);
1328 valid
= gtk_tree_model_iter_next(model2
, child2
);
1333 /* Display the whole tree (single/split/full view) */
1334 static void display_tree(struct menu
*menu
)
1337 struct property
*prop
;
1339 enum prop_type ptype
;
1341 if (menu
== &rootmenu
) {
1343 current
= &rootmenu
;
1346 for (child
= menu
->list
; child
; child
= child
->next
) {
1347 prop
= child
->prompt
;
1349 ptype
= prop
? prop
->type
: P_UNKNOWN
;
1352 sym
->flags
&= ~SYMBOL_CHANGED
;
1354 if ((view_mode
== SPLIT_VIEW
)
1355 && !(child
->flags
& MENU_ROOT
) && (tree
== tree1
))
1358 if ((view_mode
== SPLIT_VIEW
) && (child
->flags
& MENU_ROOT
)
1362 if ((opt_mode
== OPT_NORMAL
&& menu_is_visible(child
)) ||
1363 (opt_mode
== OPT_PROMPT
&& menu_has_prompt(child
)) ||
1364 (opt_mode
== OPT_ALL
&& menu_get_prompt(child
)))
1365 place_node(child
, fill_row(child
));
1367 printf("%*c%s: ", indent
, ' ', menu_get_prompt(child
));
1368 printf("%s", child
->flags
& MENU_ROOT
? "rootmenu | " : "");
1369 printf("%s", prop_get_type_name(ptype
));
1372 printf("%s", sym_type_name(sym
->type
));
1374 printf("%s", dbg_sym_flags(sym
->flags
));
1379 if ((view_mode
!= FULL_VIEW
) && (ptype
== P_MENU
)
1383 if (((menu != &rootmenu) && !(menu->flags & MENU_ROOT))
1384 || (view_mode == FULL_VIEW)
1385 || (view_mode == SPLIT_VIEW))*/
1387 /* Change paned position if the view is not in 'split mode' */
1388 if (view_mode
== SINGLE_VIEW
|| view_mode
== FULL_VIEW
) {
1389 gtk_paned_set_position(GTK_PANED(hpaned
), 0);
1392 if (((view_mode
== SINGLE_VIEW
) && (menu
->flags
& MENU_ROOT
))
1393 || (view_mode
== FULL_VIEW
)
1394 || (view_mode
== SPLIT_VIEW
)) {
1396 display_tree(child
);
1402 /* Display a part of the tree starting at current node (single/split view) */
1403 static void display_tree_part(void)
1406 gtk_tree_store_clear(tree2
);
1407 if (view_mode
== SINGLE_VIEW
)
1408 display_tree(current
);
1409 else if (view_mode
== SPLIT_VIEW
)
1410 display_tree(browsed
);
1411 gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w
));
1414 /* Display the list in the left frame (split view) */
1415 static void display_list(void)
1418 gtk_tree_store_clear(tree1
);
1421 display_tree(&rootmenu
);
1422 gtk_tree_view_expand_all(GTK_TREE_VIEW(tree1_w
));
1426 static void fixup_rootmenu(struct menu
*menu
)
1429 static int menu_cnt
= 0;
1431 menu
->flags
|= MENU_ROOT
;
1432 for (child
= menu
->list
; child
; child
= child
->next
) {
1433 if (child
->prompt
&& child
->prompt
->type
== P_MENU
) {
1435 fixup_rootmenu(child
);
1437 } else if (!menu_cnt
)
1438 fixup_rootmenu(child
);
1444 int main(int ac
, char *av
[])
1455 //add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
1456 //add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
1458 /* Determine GUI path */
1459 env
= getenv(SRCTREE
);
1461 glade_file
= g_strconcat(env
, "/scripts/kconfig/gconf.glade", NULL
);
1462 else if (av
[0][0] == '/')
1463 glade_file
= g_strconcat(av
[0], ".glade", NULL
);
1465 glade_file
= g_strconcat(g_get_current_dir(), "/", av
[0], ".glade", NULL
);
1468 if (ac
> 1 && av
[1][0] == '-') {
1474 conf_set_message_callback(NULL
);
1478 printf("%s [-s] <config>\n", av
[0]);
1486 fixup_rootmenu(&rootmenu
);
1489 /* Load the interface and connect signals */
1490 init_main_window(glade_file
);
1495 switch (view_mode
) {
1497 display_tree_part();
1503 display_tree(&rootmenu
);
1512 static void conf_changed(void)
1514 bool changed
= conf_get_changed();
1515 gtk_widget_set_sensitive(save_btn
, changed
);
1516 gtk_widget_set_sensitive(save_menu_item
, changed
);