Fix some typos and spelling
[obnox/wireshark/wip.git] / gtk / prefs_gui.c
1 /* gui_prefs.c
2  * Dialog box for GUI preferences
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 #include <string.h>
29
30 #include <gtk/gtk.h>
31
32 #include <epan/prefs.h>
33
34 #include "../globals.h"
35 #include "../simple_dialog.h"
36
37 #include "gtk/prefs_gui.h"
38 #include "gtk/gtkglobals.h"
39 #include "gtk/help_dlg.h"
40 #include "gtk/supported_protos_dlg.h"
41 #include "gtk/prefs_dlg.h"
42 #include "gtk/gui_utils.h"
43 #include "gtk/dlg_utils.h"
44 #include "gtk/main.h"
45 #include "gtk/main_packet_list.h"
46 #include "gtk/main_proto_draw.h"
47 #include "gtk/main_toolbar.h"
48 #include "gtk/font_utils.h"
49 #include "gtk/recent.h"
50 #include "gtk/webbrowser.h"
51
52
53 static gint fetch_enum_value(gpointer control, const enum_val_t *enumvals);
54 static gint fileopen_dir_changed_cb(GtkWidget *myentry _U_, GdkEvent *event, gpointer parent_w);
55 static gint fileopen_preview_changed_cb(GtkWidget *myentry _U_, GdkEvent *event, gpointer parent_w);
56 static void fileopen_selected_cb(GtkWidget *mybutton_rb _U_, gpointer parent_w);
57 static gint recent_files_count_changed_cb(GtkWidget *recent_files_entry _U_, 
58                                           GdkEvent *event _U_, gpointer parent_w);
59 static gint recent_df_entries_changed_cb(GtkWidget *recent_df_entry _U_,
60                                           GdkEvent *event _U_, gpointer parent_w);
61 #define PLIST_SEL_BROWSE_KEY            "plist_sel_browse"
62 #define PTREE_SEL_BROWSE_KEY            "ptree_sel_browse"
63 #define GEOMETRY_POSITION_KEY           "geometry_position"
64 #define GEOMETRY_SIZE_KEY               "geometry_size"
65 #define GEOMETRY_MAXIMIZED_KEY          "geometry_maximized"
66
67 #define MACOSX_STYLE_KEY                "macosx_style"
68
69 #define GUI_CONSOLE_OPEN_KEY "console_open"
70 #define GUI_FILEOPEN_KEY        "fileopen_behavior"
71 #define GUI_FILEOPEN_PREVIEW_KEY "fileopen_preview_timeout"
72 #define GUI_RECENT_FILES_COUNT_KEY "recent_files_count"
73 #define GUI_RECENT_DF_ENTRIES_KEY "recent_display_filter_entries"
74 #define GUI_FILEOPEN_DIR_KEY    "fileopen_directory"
75 #define GUI_ASK_UNSAVED_KEY     "ask_unsaved"
76 #define GUI_WEBBROWSER_KEY          "webbrowser"
77 #define GUI_FIND_WRAP_KEY       "find_wrap"
78 #define GUI_USE_PREF_SAVE_KEY   "use_pref_save"
79 #define GUI_SHOW_VERSION_KEY    "show_version"
80
81 static const enum_val_t scrollbar_placement_vals[] _U_ = {
82         { "FALSE", "Left", FALSE },
83         { "TRUE",  "Right", TRUE },
84         { NULL,    NULL,    0 }
85 };
86
87 static const enum_val_t selection_mode_vals[] = {
88         { "FALSE", "Selects", FALSE },
89         { "TRUE",  "Browses", TRUE },
90         { NULL,    NULL,      0 }
91 };
92
93 static const enum_val_t altern_colors_vals[] _U_ = {
94         { "FALSE", "No",  FALSE },
95         { "TRUE",  "Yes", TRUE },
96         { NULL,    NULL,  0 }
97 };
98
99 static const enum_val_t filter_toolbar_placement_vals[] _U_ = {
100         { "FALSE", "Below the main toolbar", FALSE },
101         { "TRUE",  "Insert into statusbar",  TRUE },
102         { NULL,    NULL,                     0 }
103 };
104
105 static const enum_val_t highlight_style_vals[] _U_ = {
106         { "FALSE", "Bold",     FALSE },
107         { "TRUE",  "Inverse",  TRUE },
108         { NULL,    NULL,       0 }
109 };
110
111
112 static const enum_val_t toolbar_style_vals[] _U_ = {
113         { "ICONS", "Icons only",     TB_STYLE_ICONS },
114         { "TEXT",  "Text only",      TB_STYLE_TEXT },
115         { "BOTH",  "Icons & Text",   TB_STYLE_BOTH },
116         { NULL,    NULL,             0 }
117 };
118
119 #ifdef _WIN32
120 static const enum_val_t gui_console_open_vals[] = {
121         { "NEVER",     "Never",                      console_open_never },
122         { "AUTOMATIC", "Automatic (advanced user)",  console_open_auto },
123         { "ALWAYS",    "Always (debugging)",         console_open_always },
124         { NULL,        NULL,                         0 }
125 };
126 #endif
127
128 static const enum_val_t gui_fileopen_vals[] = {
129         { "LAST_OPENED", "Remember last directory", FO_STYLE_LAST_OPENED },
130         { "SPECIFIED",   "Always start in:",        FO_STYLE_SPECIFIED },
131         { NULL,          NULL,                      0 }
132 };
133
134 /* Set to FALSE initially; set to TRUE if the user ever hits "OK" on
135    the "Font..." dialog, so that we know that they (probably) changed
136    the font, and therefore that the "apply" function needs to take care
137    of that */
138 static gboolean font_changed;
139
140 /* Font name from the font dialog box; if "font_changed" is TRUE, this
141    has been set to the name of the font the user selected. */
142 static gchar *new_font_name;
143
144 static GtkWidget *font_browse_w;
145
146 /* Used to contain the string from the Recent Files Count Max pref item */
147 static char recent_files_count_max_str[128] = "";
148
149 /* Used to contain the string from the Recent Display Filter Max Entries pref item */
150 static char recent_df_entries_max_str[128] = "";
151
152 /* Used to contain the string from the Open File preview timeout pref item */
153 static char open_file_preview_str[128] = "";
154
155 #define GUI_TABLE_ROWS 4
156
157 GtkWidget*
158 gui_prefs_show(void)
159 {
160         GtkWidget *main_tb, *main_vb;
161         GtkWidget *plist_browse_om;
162         GtkWidget *ptree_browse_om;
163 #ifdef _WIN32
164         GtkWidget *console_open_om;
165 #endif
166         GtkWidget *fileopen_rb, *fileopen_dir_te, *fileopen_preview_te;
167         GtkWidget *recent_files_count_max_te, *recent_df_entries_max_te, *ask_unsaved_cb, *find_wrap_cb;
168         GtkWidget *use_pref_save_cb;
169         GtkWidget *show_version_cb;
170         GtkWidget *webbrowser_te;
171         GtkWidget *save_position_cb, *save_size_cb, *save_maximized_cb;
172 #ifdef HAVE_IGE_MAC_INTEGRATION
173         GtkWidget *macosx_style_cb;
174 #endif
175
176         GtkTooltips *tooltips = gtk_tooltips_new();
177
178         int        pos = 0;
179         char       current_val_str[128];
180
181         /* The font haven't been changed yet. */
182         font_changed = FALSE;
183
184         /* The columns haven't been changed yet */
185         cfile.cinfo.columns_changed = FALSE;
186
187         /* Main vertical box */
188         main_vb = gtk_vbox_new(FALSE, 7);
189         gtk_container_set_border_width( GTK_CONTAINER(main_vb), 5 );
190
191         /* Main table */
192         main_tb = gtk_table_new(GUI_TABLE_ROWS, 2, FALSE);
193         gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
194         gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
195         gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
196
197         /* Packet list selection browseable */
198         plist_browse_om = create_preference_option_menu(main_tb, pos++,
199             "Packet list selection mode:", NULL, selection_mode_vals,
200             prefs.gui_plist_sel_browse);
201         gtk_tooltips_set_tip(tooltips, plist_browse_om, "Choose to browse "
202                 "or select a packet for detailed dissection.", NULL);
203         g_object_set_data(G_OBJECT(main_vb), PLIST_SEL_BROWSE_KEY, plist_browse_om);
204
205         /* Proto tree selection browseable */
206         ptree_browse_om = create_preference_option_menu(main_tb, pos++,
207             "Protocol tree selection mode:", NULL, selection_mode_vals,
208             prefs.gui_ptree_sel_browse);
209         gtk_tooltips_set_tip(tooltips, ptree_browse_om, "Choose to browse "
210                 "or select.", NULL);
211         g_object_set_data(G_OBJECT(main_vb), PTREE_SEL_BROWSE_KEY, ptree_browse_om);
212
213         /* Geometry prefs */
214         save_position_cb = create_preference_check_button(main_tb, pos++,
215             "Save window position:", NULL, prefs.gui_geometry_save_position);
216         gtk_tooltips_set_tip(tooltips, save_position_cb, "Whether to save the "
217                 "position of the main window.", NULL);
218         g_object_set_data(G_OBJECT(main_vb), GEOMETRY_POSITION_KEY, save_position_cb);
219
220         save_size_cb = create_preference_check_button(main_tb, pos++,
221             "Save window size:", NULL, prefs.gui_geometry_save_size);
222         gtk_tooltips_set_tip(tooltips, save_size_cb, "Whether to save the "
223                 "size of the main window.", NULL);
224         g_object_set_data(G_OBJECT(main_vb), GEOMETRY_SIZE_KEY, save_size_cb);
225
226         save_maximized_cb = create_preference_check_button(main_tb, pos++,
227             "Save maximized state:", NULL, prefs.gui_geometry_save_maximized);
228         gtk_tooltips_set_tip(tooltips, save_maximized_cb, "Whether to save the "
229                 "maximized state of the main window.", NULL);
230         g_object_set_data(G_OBJECT(main_vb), GEOMETRY_MAXIMIZED_KEY, save_maximized_cb);
231
232 #ifdef HAVE_IGE_MAC_INTEGRATION
233         macosx_style_cb = create_preference_check_button(main_tb, pos++,
234             "MacOS X style", NULL, prefs.gui_macosx_style);
235         gtk_tooltips_set_tip(tooltips, macosx_style_cb, "Whether to create a "
236            "MacOS X look and feel. Checking this box will move the menu bar to "
237            "the top of the screen instead of the top of the Wireshark window. "
238            "Requires a restart of Wireshark to take effect.", NULL);
239         g_object_set_data(G_OBJECT(main_vb), MACOSX_STYLE_KEY, macosx_style_cb);
240 #endif
241
242 #ifdef _WIN32
243         /* How the console window should be opened */
244         console_open_om = create_preference_option_menu(main_tb, pos++,
245                 "Open a console window", NULL, gui_console_open_vals, 
246                 prefs.gui_console_open);
247         gtk_tooltips_set_tip(tooltips, console_open_om, "Whether to open a console window "
248                 "(Automatic will open a console if messages appear).", NULL);
249         g_object_set_data(G_OBJECT(main_vb), GUI_CONSOLE_OPEN_KEY, console_open_om);
250 #endif
251
252         /* Allow user to select where they want the File Open dialog to open to
253          * by default */
254         fileopen_rb = create_preference_radio_buttons(main_tb, pos++,
255             "\"File Open\" dialog behavior:", 
256         "Which directory the \"File Open\" dialog should start with.", gui_fileopen_vals,
257             prefs.gui_fileopen_style);
258
259         /* Directory to default File Open dialog to */
260         fileopen_dir_te = create_preference_entry(main_tb, pos++, 
261         "Directory:", NULL, prefs.gui_fileopen_dir);
262         gtk_tooltips_set_tip(tooltips, fileopen_dir_te,
263                 "The \"File Open\" dialog defaults always to this directory.", NULL);
264         g_object_set_data(G_OBJECT(main_vb), GUI_FILEOPEN_KEY, fileopen_rb);
265         g_object_set_data(G_OBJECT(main_vb), GUI_FILEOPEN_DIR_KEY, fileopen_dir_te);
266         g_signal_connect(fileopen_rb, "clicked", G_CALLBACK(fileopen_selected_cb), main_vb);
267         g_signal_connect(fileopen_dir_te, "focus-out-event",
268             G_CALLBACK(fileopen_dir_changed_cb), main_vb);
269
270         /* File Open dialog preview timeout */
271         fileopen_preview_te = create_preference_entry(main_tb, pos++,
272             "\"File Open\" preview timeout:", "Timeout, until preview gives up scanning the capture file content.", open_file_preview_str);
273         g_snprintf(current_val_str, 128, "%d", prefs.gui_fileopen_preview);
274         gtk_entry_set_text(GTK_ENTRY(fileopen_preview_te), current_val_str);
275         gtk_tooltips_set_tip(tooltips, fileopen_preview_te, 
276         "Reading preview data in the \"File Open\" dialog will be stopped after given seconds.", NULL);
277         g_object_set_data(G_OBJECT(main_vb), GUI_FILEOPEN_PREVIEW_KEY, fileopen_preview_te);
278         g_signal_connect(fileopen_preview_te, "focus_out_event", G_CALLBACK(fileopen_preview_changed_cb), main_vb);
279
280         /* Number of recent entries in the display filter list ... */
281         recent_df_entries_max_te = create_preference_entry(main_tb, pos++,
282             "Filter display max. list entries:", "Maximum number of recent entries in filter display list", recent_df_entries_max_str);
283         g_snprintf(current_val_str, 128, "%d", prefs.gui_recent_df_entries_max);
284         gtk_entry_set_text(GTK_ENTRY(recent_df_entries_max_te), current_val_str);
285         g_object_set_data(G_OBJECT(main_vb), GUI_RECENT_DF_ENTRIES_KEY, recent_df_entries_max_te);
286         g_signal_connect(recent_df_entries_max_te, "focus_out_event", G_CALLBACK(recent_df_entries_changed_cb), main_vb);
287
288         /* Number of entries in the recent_files list ... */
289         recent_files_count_max_te = create_preference_entry(main_tb, pos++,
290             "\"Open Recent\" max. list entries:", "Maximum number of recent files", recent_files_count_max_str);
291         g_snprintf(current_val_str, 128, "%d", prefs.gui_recent_files_count_max);
292         gtk_entry_set_text(GTK_ENTRY(recent_files_count_max_te), current_val_str);
293         gtk_tooltips_set_tip(tooltips, recent_files_count_max_te, 
294         "Maximum number of entries in the \"File/Open Recent\" list.", NULL);
295         g_object_set_data(G_OBJECT(main_vb), GUI_RECENT_FILES_COUNT_KEY, recent_files_count_max_te);
296         g_signal_connect(recent_files_count_max_te, "focus_out_event", G_CALLBACK(recent_files_count_changed_cb), main_vb);
297
298         fileopen_selected_cb(NULL, main_vb);
299
300         /* ask for unsaved capture files? */
301         ask_unsaved_cb = create_preference_check_button(main_tb, pos++,
302             "Ask for unsaved capture files:", NULL, prefs.gui_ask_unsaved);
303         gtk_tooltips_set_tip(tooltips, ask_unsaved_cb, "Whether a dialog should "
304                 "pop up in case of an unsaved capture file.", NULL);
305         g_object_set_data(G_OBJECT(main_vb), GUI_ASK_UNSAVED_KEY, ask_unsaved_cb);
306
307         /* do we want to wrap when searching for data? */
308         find_wrap_cb = create_preference_check_button(main_tb, pos++,
309             "Wrap to end/beginning of file during a find:", NULL, prefs.gui_find_wrap);
310         gtk_tooltips_set_tip(tooltips, find_wrap_cb, "Whether a search should "
311                 "wrap in a capture file.", NULL);
312         g_object_set_data(G_OBJECT(main_vb), GUI_FIND_WRAP_KEY, find_wrap_cb);
313
314         /* show an explicit Save button for settings dialogs (preferences and alike)? */
315         use_pref_save_cb = create_preference_check_button(main_tb, pos++,
316             "Settings dialogs show a save button:", NULL, prefs.gui_use_pref_save);
317         gtk_tooltips_set_tip(tooltips, use_pref_save_cb, 
318                 "Whether the various settings dialogs (e.g. Preferences) should "
319                 "use an explicit save button - for advanced users.", NULL);
320         g_object_set_data(G_OBJECT(main_vb), GUI_USE_PREF_SAVE_KEY, use_pref_save_cb);
321
322         /* Show version in welcome screen */
323         show_version_cb = create_preference_check_button(main_tb, pos++,
324             "Welcome screen shows version:", NULL, prefs.gui_version_in_start_page );
325         gtk_tooltips_set_tip(tooltips, show_version_cb, 
326                 "Whether version should be shown in the start page or not", NULL);
327         g_object_set_data(G_OBJECT(main_vb), GUI_SHOW_VERSION_KEY, show_version_cb);
328
329         /* Webbrowser */
330         if (browser_needs_pref()) {
331             webbrowser_te = create_preference_entry(main_tb, pos++, 
332             "Web browser command:", NULL, prefs.gui_webbrowser);
333             gtk_entry_set_text(GTK_ENTRY(webbrowser_te), prefs.gui_webbrowser);
334             gtk_tooltips_set_tip(tooltips, webbrowser_te, "Command line to "
335                 "desired browser.", NULL);
336             g_object_set_data(G_OBJECT(main_vb), GUI_WEBBROWSER_KEY, webbrowser_te);
337         }
338
339         /* Show 'em what we got */
340         gtk_widget_show_all(main_vb);
341
342         return(main_vb);
343 }
344
345
346 /* Create a font widget for browsing. */
347 GtkWidget *
348 gui_font_prefs_show(void)
349 {
350         /* Create the font selection widget. */
351         font_browse_w = (GtkWidget *) gtk_font_selection_new();
352         gtk_widget_show(font_browse_w);
353
354         return font_browse_w;
355 }
356
357
358 static gboolean
359 font_fetch(void)
360 {
361         gchar   *font_name;
362
363         font_name = g_strdup(gtk_font_selection_get_font_name(
364               GTK_FONT_SELECTION(font_browse_w)));
365         if (font_name == NULL) {
366                 /* No font was selected; let the user know, but don't
367                    tear down the font selection dialog, so they can
368                    try again. */
369                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
370                    "You have not selected a font.");
371                 return FALSE;
372         }
373
374         if (!user_font_test(font_name)) {
375                 /* The font isn't usable; "user_font_test()" has already
376                    told the user why.  Don't tear down the font selection
377                    dialog. */
378                 g_free(font_name);
379                 return FALSE;
380         }
381         new_font_name = font_name;
382         return TRUE;
383 }
384
385
386 static gint
387 fetch_enum_value(gpointer control, const enum_val_t *enumvals)
388 {
389         return fetch_preference_option_menu_val(GTK_WIDGET(control), enumvals);
390 }
391
392 void
393 gui_prefs_fetch(GtkWidget *w)
394 {
395         prefs.gui_plist_sel_browse = fetch_enum_value(
396             g_object_get_data(G_OBJECT(w), PLIST_SEL_BROWSE_KEY), selection_mode_vals);
397         prefs.gui_ptree_sel_browse = fetch_enum_value(
398             g_object_get_data(G_OBJECT(w), PTREE_SEL_BROWSE_KEY), selection_mode_vals);
399         prefs.gui_geometry_save_position =
400             gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(w), GEOMETRY_POSITION_KEY));
401         prefs.gui_geometry_save_size =
402             gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(w), GEOMETRY_SIZE_KEY));
403         prefs.gui_geometry_save_maximized =
404             gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(w), GEOMETRY_MAXIMIZED_KEY));
405
406 #ifdef HAVE_IGE_MAC_INTEGRATION
407         prefs.gui_macosx_style =
408             gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(w), MACOSX_STYLE_KEY));
409 #endif
410
411 #ifdef _WIN32
412         prefs.gui_console_open = fetch_enum_value(
413             g_object_get_data(G_OBJECT(w), GUI_CONSOLE_OPEN_KEY), gui_console_open_vals);
414 #endif
415         prefs.gui_fileopen_style = fetch_preference_radio_buttons_val(
416             g_object_get_data(G_OBJECT(w), GUI_FILEOPEN_KEY), gui_fileopen_vals);
417         
418         if (prefs.gui_fileopen_dir != NULL)
419                 g_free(prefs.gui_fileopen_dir);
420         prefs.gui_fileopen_dir = g_strdup(gtk_entry_get_text(
421                                               GTK_ENTRY(g_object_get_data(G_OBJECT(w), GUI_FILEOPEN_DIR_KEY))));
422
423     prefs.gui_ask_unsaved = 
424         gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(w), GUI_ASK_UNSAVED_KEY));
425
426     prefs.gui_find_wrap = 
427         gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(w), GUI_FIND_WRAP_KEY));
428
429     prefs.gui_use_pref_save = 
430         gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(w), GUI_USE_PREF_SAVE_KEY));
431
432         prefs.gui_version_in_start_page  = 
433         gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(w), GUI_SHOW_VERSION_KEY));
434
435     if (browser_needs_pref()) {
436                 g_free(prefs.gui_webbrowser);
437             prefs.gui_webbrowser = g_strdup(gtk_entry_get_text(
438                                                 GTK_ENTRY(g_object_get_data(G_OBJECT(w), GUI_WEBBROWSER_KEY))));
439     }
440         /*
441          * XXX - we need to have a way to fetch the preferences into
442          * local storage and only set the permanent preferences if there
443          * weren't any errors in those fetches, as there are several
444          * places where there *can* be a bad preference value.
445          */
446         if (font_fetch()) {
447                 if (strcmp(new_font_name, prefs.gui_font_name) != 0) {
448                         font_changed = TRUE;
449                         if (prefs.gui_font_name != NULL)
450                                 g_free(prefs.gui_font_name);
451                         prefs.gui_font_name = g_strdup(new_font_name);
452                 }
453         }
454 }
455
456
457
458 void
459 gui_prefs_apply(GtkWidget *w _U_ , gboolean redissect)
460 {
461
462 #ifdef _WIN32
463     /* user immediately wants to see a console */
464     if (prefs.gui_console_open == console_open_always) {
465         create_console();
466     }
467 #endif
468
469         if (font_changed) {
470                 /* This redraws the hex dump windows. */
471                 switch (user_font_apply()) {
472
473                 case FA_SUCCESS:
474                         break;
475
476                 case FA_FONT_NOT_RESIZEABLE:
477                         /* "user_font_apply()" popped up an alert box. */
478                         /* turn off zooming - font can't be resized */
479                         recent.gui_zoom_level = 0;
480                         break;
481
482                 case FA_FONT_NOT_AVAILABLE:
483                         /* We assume this means that the specified size
484                            isn't available. */
485                         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
486                             "That font isn't available at the specified zoom level;\n"
487                             "turning zooming off.");
488                         recent.gui_zoom_level = 0;
489                         break;
490                 }
491         } else if (!redissect) {
492                 /* Redraw the hex dump windows, in case the
493                    highlight style changed, only if we aren't redissecting the whole file.
494                    XXX - do it only if the highlight style *did* change. */
495                 redraw_hex_dump_all();
496         }
497
498         /* Redraw the help window(s). */
499         supported_redraw();
500         help_redraw();
501
502         /* XXX: redraw the toolbar only, if style changed */
503         toolbar_redraw_all();
504
505         set_scrollbar_placement_all();
506         packet_list_set_sel_browse(prefs.gui_plist_sel_browse, FALSE);
507         set_ptree_sel_browse_all(prefs.gui_ptree_sel_browse);
508         set_tree_styles_all();
509         main_widgets_rearrange();
510 }
511
512 void
513 gui_prefs_destroy(GtkWidget *w _U_)
514 {
515         /* Free up any saved font name. */
516         if (new_font_name != NULL) {
517                 g_free(new_font_name);
518                 new_font_name = NULL;
519         }
520 }
521
522 static gint
523 recent_df_entries_changed_cb(GtkWidget *recent_df_entry _U_,
524                               GdkEvent *event _U_, gpointer parent_w)
525 {
526     GtkWidget   *recent_df_entries_count_te;
527     guint newval;
528
529     recent_df_entries_count_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), GUI_RECENT_DF_ENTRIES_KEY);
530
531     /*
532      * Now, just convert the string to a number and store it in the prefs
533      * filed ...
534      */
535
536     newval = strtol(gtk_entry_get_text (GTK_ENTRY(recent_df_entries_count_te)), NULL, 10);
537
538     if (newval > 0) {
539       prefs.gui_recent_df_entries_max = newval;
540     }
541
542     /* We really should pop up a nasty dialog box if newval <= 0 */
543
544     return FALSE;
545 }
546
547 static gint
548 recent_files_count_changed_cb(GtkWidget *recent_files_entry _U_, 
549                               GdkEvent *event _U_, gpointer parent_w)
550 {
551     GtkWidget   *recent_files_count_te;
552     guint newval;
553     
554     recent_files_count_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), GUI_RECENT_FILES_COUNT_KEY);
555
556     /*
557      * Now, just convert the string to a number and store it in the prefs
558      * filed ...
559      */
560
561     newval = strtol(gtk_entry_get_text (GTK_ENTRY(recent_files_count_te)), NULL, 10);
562
563     if (newval > 0) {
564       prefs.gui_recent_files_count_max = newval;
565     }
566
567     /* We really should pop up a nasty dialog box if newval <= 0 */
568
569     return FALSE;
570 }
571
572 static gint
573 fileopen_preview_changed_cb(GtkWidget *recent_files_entry _U_, 
574                               GdkEvent *event _U_, gpointer parent_w)
575 {
576     GtkWidget   *fileopen_preview_te;
577     guint newval;
578     
579     fileopen_preview_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), GUI_FILEOPEN_PREVIEW_KEY);
580
581     /*
582      * Now, just convert the string to a number and store it in the prefs
583      * filed ...
584      */
585
586     newval = strtol(gtk_entry_get_text (GTK_ENTRY(fileopen_preview_te)), NULL, 10);
587
588     if (newval > 0) {
589       prefs.gui_fileopen_preview = newval;
590     }
591
592     /* We really should pop up a nasty dialog box if newval <= 0 */
593
594     return FALSE;
595 }
596
597 static gint
598 fileopen_dir_changed_cb(GtkWidget *fileopen_entry _U_, GdkEvent *event _U_, gpointer parent_w)
599 {
600     GtkWidget   *fileopen_dir_te;
601     char *lastchar;
602     gint fileopen_dir_te_length;
603     
604     fileopen_dir_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), GUI_FILEOPEN_DIR_KEY);
605     fileopen_dir_te_length = strlen(gtk_entry_get_text (GTK_ENTRY(fileopen_entry)));
606     if (fileopen_dir_te_length == 0)
607         return FALSE;
608     lastchar = gtk_editable_get_chars(GTK_EDITABLE(fileopen_entry), fileopen_dir_te_length-1, -1);
609     if (strcmp(lastchar, G_DIR_SEPARATOR_S) != 0)
610         gtk_entry_append_text(GTK_ENTRY(fileopen_entry), G_DIR_SEPARATOR_S);
611     return FALSE;
612 }
613
614 static void
615 fileopen_selected_cb(GtkWidget *mybutton_rb _U_, gpointer parent_w)
616 {
617     GtkWidget   *fileopen_rb, *fileopen_dir_te;
618     
619     fileopen_rb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), GUI_FILEOPEN_KEY);
620     fileopen_dir_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), GUI_FILEOPEN_DIR_KEY);
621     
622     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fileopen_rb)))
623     {
624         gtk_widget_set_sensitive(GTK_WIDGET(fileopen_dir_te), TRUE);
625     }
626     else
627     {
628         gtk_widget_set_sensitive(GTK_WIDGET(fileopen_dir_te), FALSE);
629     }
630     return;
631 }
632