aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2002-01-13 20:35:12 +0000
committerGuy Harris <guy@alum.mit.edu>2002-01-13 20:35:12 +0000
commit0a03b0f73ef7595d7281097c94cccefa13059f7e (patch)
treec255fb8cb7e40c899ad998c9846d1dabb5bb9562 /gtk
parent649cc279d6dad12744f67a23fa335e9ee2f55627 (diff)
Add a preferences page for the name resolution flags.
Separate the preferences value for those flags and the name resolution code's value into separate variables; this means that the resolution code no longer depends on the preferences code, and may let us eventually have the current setting and the preference setting differ (so that a user can temporarily override the preference setting without causing subsequent saves of the preferences to save the temporary value). Add routines to create various types of widgets for preferences, and to fetch the values for "enumerated" preferences, and use them both in the code to handle hardwired preference pages and table-driven preference pages. svn path=/trunk/; revision=4536
Diffstat (limited to 'gtk')
-rw-r--r--gtk/Makefile.am4
-rw-r--r--gtk/Makefile.nmake1
-rw-r--r--gtk/capture_dlg.c16
-rw-r--r--gtk/capture_prefs.c41
-rw-r--r--gtk/display_opts.c18
-rw-r--r--gtk/file_dlg.c17
-rw-r--r--gtk/gui_prefs.c124
-rw-r--r--gtk/main.c19
-rw-r--r--gtk/menu.c4
-rw-r--r--gtk/nameres_prefs.c129
-rw-r--r--gtk/nameres_prefs.h33
-rw-r--r--gtk/prefs_dlg.c305
-rw-r--r--gtk/prefs_dlg.h16
-rw-r--r--gtk/print_prefs.c147
14 files changed, 530 insertions, 344 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 07c4e69731..30e648d52e 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1,7 +1,7 @@
# Makefile.am
# Automake file for the GTK interface routines for Ethereal
#
-# $Id: Makefile.am,v 1.37 2002/01/10 07:43:39 guy Exp $
+# $Id: Makefile.am,v 1.38 2002/01/13 20:35:11 guy Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
@@ -71,6 +71,8 @@ libui_a_SOURCES = \
main.h \
menu.c \
menu.h \
+ nameres_prefs.c \
+ nameres_prefs.h \
packet_win.c \
packet_win.h \
plugins_dlg.c \
diff --git a/gtk/Makefile.nmake b/gtk/Makefile.nmake
index 666425a54d..8b7488a059 100644
--- a/gtk/Makefile.nmake
+++ b/gtk/Makefile.nmake
@@ -37,6 +37,7 @@ OBJECTS=capture_dlg.obj \
help_dlg.obj \
main.obj \
menu.obj \
+ nameres_prefs.obj \
packet_win.obj \
plugins_dlg.obj \
prefs_dlg.obj \
diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c
index 7c62def83d..8bf437d433 100644
--- a/gtk/capture_dlg.c
+++ b/gtk/capture_dlg.c
@@ -1,7 +1,7 @@
/* capture_dlg.c
* Routines for packet capture windows
*
- * $Id: capture_dlg.c,v 1.55 2002/01/11 08:55:02 guy Exp $
+ * $Id: capture_dlg.c,v 1.56 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -386,21 +386,21 @@ capture_prep_cb(GtkWidget *w, gpointer d)
m_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _MAC name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(m_resolv_cb),
- prefs.name_resolve & PREFS_RESOLV_MAC);
+ g_resolv_flags & RESOLV_MAC);
gtk_container_add(GTK_CONTAINER(main_vb), m_resolv_cb);
gtk_widget_show(m_resolv_cb);
n_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _network name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(n_resolv_cb),
- prefs.name_resolve & PREFS_RESOLV_NETWORK);
+ g_resolv_flags & RESOLV_NETWORK);
gtk_container_add(GTK_CONTAINER(main_vb), n_resolv_cb);
gtk_widget_show(n_resolv_cb);
t_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _transport name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(t_resolv_cb),
- prefs.name_resolve & PREFS_RESOLV_TRANSPORT);
+ g_resolv_flags & RESOLV_TRANSPORT);
gtk_container_add(GTK_CONTAINER(main_vb), t_resolv_cb);
gtk_widget_show(t_resolv_cb);
@@ -688,10 +688,10 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) {
auto_scroll_live = GTK_TOGGLE_BUTTON (auto_scroll_cb)->active;
- prefs.name_resolve = PREFS_RESOLV_NONE;
- prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? PREFS_RESOLV_MAC : PREFS_RESOLV_NONE);
- prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? PREFS_RESOLV_NETWORK : PREFS_RESOLV_NONE);
- prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? PREFS_RESOLV_TRANSPORT : PREFS_RESOLV_NONE);
+ g_resolv_flags = RESOLV_NONE;
+ g_resolv_flags |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE);
+ g_resolv_flags |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE);
+ g_resolv_flags |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
cfile.ringbuffer_on = GTK_TOGGLE_BUTTON (ringbuffer_on_tb)->active && !(sync_mode);
if (cfile.ringbuffer_on == TRUE) {
diff --git a/gtk/capture_prefs.c b/gtk/capture_prefs.c
index d7b85eda63..4ae81e22b3 100644
--- a/gtk/capture_prefs.c
+++ b/gtk/capture_prefs.c
@@ -1,7 +1,7 @@
/* capture_prefs.c
* Dialog box for capture preferences
*
- * $Id: capture_prefs.c,v 1.6 2002/01/12 11:02:47 guy Exp $
+ * $Id: capture_prefs.c,v 1.7 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -38,17 +38,13 @@
#include "capture_prefs.h"
#include "gtkglobals.h"
#include "prefs.h"
-#include "prefs-int.h"
+#include "prefs_dlg.h"
#include "ui_util.h"
#include "pcap-util.h"
#include "main.h"
#ifdef HAVE_LIBPCAP
-static void create_option_check_button(GtkWidget *main_vb, const gchar *key,
- GtkWidget *main_tb, int table_position, const gchar *label_text,
- gboolean active);
-
#define DEVICE_KEY "device"
#define PROM_MODE_KEY "prom_mode"
#define CAPTURE_REAL_TIME_KEY "capture_real_time"
@@ -59,7 +55,7 @@ GtkWidget*
capture_prefs_show(void)
{
GtkWidget *main_tb, *main_vb;
- GtkWidget *if_cb, *if_lb;
+ GtkWidget *if_cb, *if_lb, *promisc_cb, *sync_cb, *auto_scroll_cb;
GList *if_list;
int err;
char err_str[PCAP_ERRBUF_SIZE];
@@ -98,16 +94,21 @@ capture_prefs_show(void)
free_interface_list(if_list);
/* Promiscuous mode */
- create_option_check_button(main_vb, PROM_MODE_KEY, main_tb, 1,
+ promisc_cb = create_preference_check_button(main_tb, 1,
"Capture packets in promiscuous mode:", prefs.capture_prom_mode);
+ gtk_object_set_data(GTK_OBJECT(main_vb), PROM_MODE_KEY, promisc_cb);
/* Real-time capture */
- create_option_check_button(main_vb, CAPTURE_REAL_TIME_KEY, main_tb, 2,
+ sync_cb = create_preference_check_button(main_tb, 2,
"Update list of packets in real time:", prefs.capture_real_time);
+ gtk_object_set_data(GTK_OBJECT(main_vb), CAPTURE_REAL_TIME_KEY,
+ sync_cb);
/* Auto-scroll real-time capture */
- create_option_check_button(main_vb, AUTO_SCROLL_KEY, main_tb, 3,
+ auto_scroll_cb = create_preference_check_button(main_tb, 3,
"Automatic scrolling in live capture:", prefs.capture_auto_scroll);
+ gtk_object_set_data(GTK_OBJECT(main_vb), AUTO_SCROLL_KEY,
+ auto_scroll_cb);
/* Show 'em what we got */
gtk_widget_show_all(main_vb);
@@ -115,26 +116,6 @@ capture_prefs_show(void)
return(main_vb);
}
-static void
-create_option_check_button(GtkWidget *main_vb, const gchar *key,
- GtkWidget *main_tb, int table_position, const gchar *label_text,
- gboolean active)
-{
- GtkWidget *label, *check_box;
-
- label = gtk_label_new(label_text);
- gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1,
- table_position, table_position + 1);
-
- check_box = gtk_check_button_new();
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), active);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), check_box, 1, 2,
- table_position, table_position + 1);
-
- gtk_object_set_data(GTK_OBJECT(main_vb), key, check_box);
-}
-
void
capture_prefs_fetch(GtkWidget *w)
{
diff --git a/gtk/display_opts.c b/gtk/display_opts.c
index 126c11109a..5c493e660b 100644
--- a/gtk/display_opts.c
+++ b/gtk/display_opts.c
@@ -1,7 +1,7 @@
/* display_opts.c
* Routines for packet display windows
*
- * $Id: display_opts.c,v 1.23 2002/01/10 11:05:50 guy Exp $
+ * $Id: display_opts.c,v 1.24 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -22,7 +22,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@@ -59,7 +58,6 @@
#include "display_opts.h"
#include "ui_util.h"
#include "dlg_utils.h"
-#include "prefs.h"
extern capture_file cfile;
@@ -184,7 +182,7 @@ display_opt_cb(GtkWidget *w, gpointer d) {
button = dlg_check_button_new_with_label_with_mnemonic(
"Enable _MAC name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
- prefs.name_resolve & PREFS_RESOLV_MAC);
+ g_resolv_flags & RESOLV_MAC);
gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_M_NAME_RESOLUTION_KEY,
button);
gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
@@ -193,7 +191,7 @@ display_opt_cb(GtkWidget *w, gpointer d) {
button = dlg_check_button_new_with_label_with_mnemonic(
"Enable _network name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
- prefs.name_resolve & PREFS_RESOLV_NETWORK);
+ g_resolv_flags & RESOLV_NETWORK);
gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_N_NAME_RESOLUTION_KEY,
button);
gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
@@ -202,7 +200,7 @@ display_opt_cb(GtkWidget *w, gpointer d) {
button = dlg_check_button_new_with_label_with_mnemonic(
"Enable _transport name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
- prefs.name_resolve & PREFS_RESOLV_TRANSPORT);
+ g_resolv_flags & RESOLV_TRANSPORT);
gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_T_NAME_RESOLUTION_KEY,
button);
gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
@@ -292,16 +290,16 @@ get_display_options(GtkWidget *parent_w)
auto_scroll_live = (GTK_TOGGLE_BUTTON (button)->active);
#endif
- prefs.name_resolve = PREFS_RESOLV_NONE;
+ g_resolv_flags = RESOLV_NONE;
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
E_DISPLAY_M_NAME_RESOLUTION_KEY);
- prefs.name_resolve |= (GTK_TOGGLE_BUTTON (button)->active ? PREFS_RESOLV_MAC : PREFS_RESOLV_NONE);
+ g_resolv_flags |= (GTK_TOGGLE_BUTTON (button)->active ? RESOLV_MAC : RESOLV_NONE);
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
E_DISPLAY_N_NAME_RESOLUTION_KEY);
- prefs.name_resolve |= (GTK_TOGGLE_BUTTON (button)->active ? PREFS_RESOLV_NETWORK : PREFS_RESOLV_NONE);
+ g_resolv_flags |= (GTK_TOGGLE_BUTTON (button)->active ? RESOLV_NETWORK : RESOLV_NONE);
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
E_DISPLAY_T_NAME_RESOLUTION_KEY);
- prefs.name_resolve |= (GTK_TOGGLE_BUTTON (button)->active ? PREFS_RESOLV_TRANSPORT : PREFS_RESOLV_NONE);
+ g_resolv_flags |= (GTK_TOGGLE_BUTTON (button)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
}
diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c
index 0be2b62997..2257894a5f 100644
--- a/gtk/file_dlg.c
+++ b/gtk/file_dlg.c
@@ -1,7 +1,7 @@
/* file_dlg.c
* Dialog boxes for handling files
*
- * $Id: file_dlg.c,v 1.46 2001/12/06 03:09:28 guy Exp $
+ * $Id: file_dlg.c,v 1.47 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -42,7 +42,6 @@
#include "globals.h"
#include "gtkglobals.h"
-#include "prefs.h"
#include "resolv.h"
#include "keys.h"
#include "filter_prefs.h"
@@ -136,7 +135,7 @@ file_open_cmd_cb(GtkWidget *w, gpointer data)
m_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _MAC name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(m_resolv_cb),
- prefs.name_resolve & PREFS_RESOLV_MAC);
+ g_resolv_flags & RESOLV_MAC);
gtk_box_pack_start(GTK_BOX(main_vb), m_resolv_cb, FALSE, FALSE, 0);
gtk_widget_show(m_resolv_cb);
gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(file_open_w)->ok_button),
@@ -145,7 +144,7 @@ file_open_cmd_cb(GtkWidget *w, gpointer data)
n_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _network name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(n_resolv_cb),
- prefs.name_resolve & PREFS_RESOLV_NETWORK);
+ g_resolv_flags & RESOLV_NETWORK);
gtk_box_pack_start(GTK_BOX(main_vb), n_resolv_cb, FALSE, FALSE, 0);
gtk_widget_show(n_resolv_cb);
gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(file_open_w)->ok_button),
@@ -154,7 +153,7 @@ file_open_cmd_cb(GtkWidget *w, gpointer data)
t_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _transport name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(t_resolv_cb),
- prefs.name_resolve & PREFS_RESOLV_TRANSPORT);
+ g_resolv_flags & RESOLV_TRANSPORT);
gtk_box_pack_start(GTK_BOX(main_vb), t_resolv_cb, FALSE, FALSE, 0);
gtk_widget_show(t_resolv_cb);
gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(file_open_w)->ok_button),
@@ -224,13 +223,13 @@ file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
cfile.rfcode = rfcode;
/* Set the global resolving variable */
- prefs.name_resolve = 0;
+ g_resolv_flags = 0;
m_resolv_cb = gtk_object_get_data(GTK_OBJECT(w), E_FILE_M_RESOLVE_KEY);
- prefs.name_resolve |= GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? PREFS_RESOLV_MAC : PREFS_RESOLV_NONE;
+ g_resolv_flags |= GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE;
n_resolv_cb = gtk_object_get_data(GTK_OBJECT(w), E_FILE_N_RESOLVE_KEY);
- prefs.name_resolve |= GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? PREFS_RESOLV_NETWORK : PREFS_RESOLV_NONE;
+ g_resolv_flags |= GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE;
t_resolv_cb = gtk_object_get_data(GTK_OBJECT(w), E_FILE_T_RESOLVE_KEY);
- prefs.name_resolve |= GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? PREFS_RESOLV_TRANSPORT : PREFS_RESOLV_NONE;
+ g_resolv_flags |= GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE;
/* We've crossed the Rubicon; get rid of the file selection box. */
gtk_widget_hide(GTK_WIDGET (fs));
diff --git a/gtk/gui_prefs.c b/gtk/gui_prefs.c
index 912a6b0c76..2be9382f1b 100644
--- a/gtk/gui_prefs.c
+++ b/gtk/gui_prefs.c
@@ -1,7 +1,7 @@
/* gui_prefs.c
* Dialog box for GUI preferences
*
- * $Id: gui_prefs.c,v 1.31 2002/01/12 11:09:09 guy Exp $
+ * $Id: gui_prefs.c,v 1.32 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -37,19 +37,13 @@
#include "follow_dlg.h"
#include "help_dlg.h"
#include "prefs.h"
-#include "prefs-int.h"
+#include "prefs_dlg.h"
#include "ui_util.h"
#include "simple_dialog.h"
#include "dlg_utils.h"
#include "proto_draw.h"
#include "main.h"
-static void create_option_menu(GtkWidget *main_vb, const gchar *key,
- GtkWidget *main_tb, int table_position,
- const gchar *label_text, const enum_val_t *enumvals, gint current_val);
-static void create_option_check_button(GtkWidget *main_vb, const gchar *key,
- GtkWidget *main_tb, int table_position, const gchar *label_text,
- gboolean active);
static void font_browse_cb(GtkWidget *w, gpointer data);
static void font_browse_ok_cb(GtkWidget *w, GtkFontSelectionDialog *fs);
static void font_browse_destroy(GtkWidget *win, gpointer data);
@@ -134,7 +128,10 @@ GtkWidget*
gui_prefs_show(void)
{
GtkWidget *main_tb, *main_vb, *hbox, *font_bt, *color_bt;
- GtkWidget *geom_cb;
+ GtkWidget *scrollbar_om, *plist_browse_om;
+ GtkWidget *ptree_browse_om, *line_style_om;
+ GtkWidget *expander_style_om, *highlight_style_om;
+ GtkWidget *save_position_cb, *save_size_cb;
/* The colors or font haven't been changed yet. */
colors_changed = FALSE;
@@ -157,42 +154,58 @@ gui_prefs_show(void)
gtk_table_set_col_spacing( GTK_TABLE(main_tb), 1, 50 );
/* Scrollbar placement */
- create_option_menu(main_vb, SCROLLBAR_PLACEMENT_KEY, main_tb, 0,
+ scrollbar_om = create_preference_option_menu(main_tb, 0,
"Vertical scrollbar placement:", scrollbar_placement_vals,
prefs.gui_scrollbar_on_right);
+ gtk_object_set_data(GTK_OBJECT(main_vb), SCROLLBAR_PLACEMENT_KEY,
+ scrollbar_om);
/* Packet list selection browseable */
- create_option_menu(main_vb, PLIST_SEL_BROWSE_KEY, main_tb, 1,
+ plist_browse_om = create_preference_option_menu(main_tb, 1,
"Packet list mouse behavior:", selection_mode_vals,
prefs.gui_plist_sel_browse);
+ gtk_object_set_data(GTK_OBJECT(main_vb), PLIST_SEL_BROWSE_KEY,
+ plist_browse_om);
/* Proto tree selection browseable */
- create_option_menu(main_vb, PTREE_SEL_BROWSE_KEY, main_tb, 2,
+ ptree_browse_om = create_preference_option_menu(main_tb, 2,
"Protocol tree mouse behavior:", selection_mode_vals,
prefs.gui_ptree_sel_browse);
+ gtk_object_set_data(GTK_OBJECT(main_vb), PTREE_SEL_BROWSE_KEY,
+ ptree_browse_om);
/* Tree line style */
- create_option_menu(main_vb, PTREE_LINE_STYLE_KEY, main_tb, 3,
+ line_style_om = create_preference_option_menu(main_tb, 3,
"Tree line style:", line_style_vals,
prefs.gui_ptree_line_style);
+ gtk_object_set_data(GTK_OBJECT(main_vb), PTREE_LINE_STYLE_KEY,
+ line_style_om);
/* Tree expander style */
- create_option_menu(main_vb, PTREE_EXPANDER_STYLE_KEY, main_tb, 4,
+ expander_style_om = create_preference_option_menu(main_tb, 4,
"Tree expander style:", expander_style_vals,
prefs.gui_ptree_expander_style);
+ gtk_object_set_data(GTK_OBJECT(main_vb), PTREE_EXPANDER_STYLE_KEY,
+ expander_style_om);
/* Hex Dump highlight style */
- create_option_menu(main_vb, HEX_DUMP_HIGHLIGHT_STYLE_KEY, main_tb, 5,
+ highlight_style_om = create_preference_option_menu(main_tb, 5,
"Hex display highlight style:", highlight_style_vals,
prefs.gui_hex_dump_highlight_style);
+ gtk_object_set_data(GTK_OBJECT(main_vb), HEX_DUMP_HIGHLIGHT_STYLE_KEY,
+ highlight_style_om);
/* Geometry prefs */
- create_option_check_button(main_vb, GEOMETRY_POSITION_KEY, main_tb,
+ save_position_cb = create_preference_check_button(main_tb,
6, "Save window position:", prefs.gui_geometry_save_position);
+ gtk_object_set_data(GTK_OBJECT(main_vb), GEOMETRY_POSITION_KEY,
+ save_position_cb);
- create_option_check_button(main_vb, GEOMETRY_SIZE_KEY, main_tb,
+ save_size_cb = create_preference_check_button(main_tb,
7, "Save window size:", prefs.gui_geometry_save_size);
-
+ gtk_object_set_data(GTK_OBJECT(main_vb), GEOMETRY_SIZE_KEY,
+ save_size_cb);
+
/* "Font..." button - click to open a font selection dialog box. */
font_bt = gtk_button_new_with_label("Font...");
gtk_signal_connect(GTK_OBJECT(font_bt), "clicked",
@@ -211,68 +224,6 @@ gui_prefs_show(void)
return(main_vb);
}
-static void
-create_option_menu(GtkWidget *main_vb, const gchar *key,
- GtkWidget *main_tb, int table_position,
- const gchar *label_text, const enum_val_t *enumvals, gint current_val)
-{
- GtkWidget *label, *menu_box, *menu, *menu_item, *option_menu;
- int menu_index, index;
- const enum_val_t *enum_valp;
-
- label = gtk_label_new(label_text);
- gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1,
- table_position, table_position + 1);
- menu_box = gtk_hbox_new(FALSE, 0);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), menu_box,
- 1, 2, table_position, table_position + 1);
-
- /* Create a menu from the enumvals */
- menu = gtk_menu_new();
- menu_index = -1;
- for (enum_valp = enumvals, index = 0;
- enum_valp->name != NULL; enum_valp++, index++) {
- menu_item = gtk_menu_item_new_with_label(enum_valp->name);
- gtk_menu_append(GTK_MENU(menu), menu_item);
- if (enum_valp->value == current_val)
- menu_index = index;
- gtk_widget_show(menu_item);
- }
-
- /* Create the option menu from the menu */
- option_menu = gtk_option_menu_new();
- gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
-
- /* Set its current value to the variable's current value */
- if (menu_index != -1)
- gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu),
- menu_index);
-
- gtk_box_pack_start(GTK_BOX(menu_box), option_menu, FALSE, FALSE, 0);
- gtk_object_set_data(GTK_OBJECT(main_vb), key, option_menu);
-}
-
-static void
-create_option_check_button(GtkWidget *main_vb, const gchar *key,
- GtkWidget *main_tb, int table_position, const gchar *label_text,
- gboolean active)
-{
- GtkWidget *label, *check_box;
-
- label = gtk_label_new(label_text);
- gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1,
- table_position, table_position + 1);
-
- check_box = gtk_check_button_new();
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), active);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), check_box, 1, 2,
- table_position, table_position + 1);
-
- gtk_object_set_data(GTK_OBJECT(main_vb), key, check_box);
-}
-
/* Create a font dialog for browsing. */
static void
font_browse_cb(GtkWidget *w, gpointer data)
@@ -432,16 +383,7 @@ font_browse_destroy(GtkWidget *win, gpointer data)
static gint
fetch_enum_value(gpointer control, const enum_val_t *enumvals)
{
- GtkWidget *label;
- char *label_string;
-
- /* Get the label for the currently active entry in the option menu.
- Yes, this is how you do it. See FAQ 6.8 in the GTK+ FAQ. */
- label = GTK_BIN(control)->child;
-
- /* Get the label string, and translate it to a value. */
- gtk_label_get(GTK_LABEL(label), &label_string);
- return find_val_for_string(label_string, enumvals, 1);
+ return fetch_preference_option_menu_val(GTK_WIDGET(control), enumvals);
}
void
@@ -479,7 +421,7 @@ gui_prefs_fetch(GtkWidget *w)
}
if (colors_changed)
- fetch_colors();
+ fetch_colors();
}
void
diff --git a/gtk/main.c b/gtk/main.c
index d1ec5fb830..42fc595eb5 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -1,6 +1,6 @@
/* main.c
*
- * $Id: main.c,v 1.228 2002/01/11 08:21:02 guy Exp $
+ * $Id: main.c,v 1.229 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -854,11 +854,11 @@ void expand_all_cb(GtkWidget *widget, gpointer data) {
void resolve_name_cb(GtkWidget *widget, gpointer data) {
if (cfile.edt->tree) {
- gint tmp = prefs.name_resolve;
- prefs.name_resolve = PREFS_RESOLV_ALL;
+ guint32 tmp = g_resolv_flags;
+ g_resolv_flags = RESOLV_ALL;
gtk_clist_clear ( GTK_CLIST(tree_view) );
proto_tree_draw(cfile.edt->tree, tree_view);
- prefs.name_resolve = tmp;
+ g_resolv_flags = tmp;
}
}
@@ -1309,6 +1309,9 @@ main(int argc, char *argv[])
auto_scroll_live = prefs->capture_auto_scroll;
#endif
+ /* Set the name resolution code's flags from the preferences. */
+ g_resolv_flags = prefs->name_resolve;
+
/* Read the capture filter file. */
read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
@@ -1481,12 +1484,12 @@ main(int argc, char *argv[])
prefs->gui_font_name = g_strdup(optarg);
break;
case 'n': /* No name resolution */
- prefs->name_resolve = PREFS_RESOLV_NONE;
+ g_resolv_flags = RESOLV_NONE;
break;
case 'N': /* Select what types of addresses/port #s to resolve */
- if (prefs->name_resolve == PREFS_RESOLV_ALL)
- prefs->name_resolve = PREFS_RESOLV_NONE;
- badopt = string_to_name_resolve(optarg, &prefs->name_resolve);
+ if (g_resolv_flags == RESOLV_ALL)
+ g_resolv_flags = RESOLV_NONE;
+ badopt = string_to_name_resolve(optarg, &g_resolv_flags);
if (badopt != '\0') {
fprintf(stderr, "ethereal: -N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'\n",
badopt);
diff --git a/gtk/menu.c b/gtk/menu.c
index 76e8e579af..732daf8b24 100644
--- a/gtk/menu.c
+++ b/gtk/menu.c
@@ -1,7 +1,7 @@
/* menu.c
* Menu routines
*
- * $Id: menu.c,v 1.60 2002/01/11 08:21:02 guy Exp $
+ * $Id: menu.c,v 1.61 2002/01/13 20:35:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -489,7 +489,7 @@ set_menus_for_selected_packet(gboolean have_selected_packet)
set_menu_sensitivity("/Tools/Decode As...",
have_selected_packet && decode_as_ok());
set_menu_sensitivity("/Resolve Name",
- have_selected_packet && !prefs.name_resolve);
+ have_selected_packet && g_resolv_flags == 0);
set_menu_sensitivity("/Tools/TCP Stream Analysis",
have_selected_packet ? (cfile.edt->pi.ipproto == 6) : FALSE);
}
diff --git a/gtk/nameres_prefs.c b/gtk/nameres_prefs.c
new file mode 100644
index 0000000000..bd2c22e8fd
--- /dev/null
+++ b/gtk/nameres_prefs.c
@@ -0,0 +1,129 @@
+/* nameres_prefs.c
+ * Dialog box for name resolution preferences
+ *
+ * $Id: nameres_prefs.c,v 1.1 2002/01/13 20:35:12 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <errno.h>
+#include <gtk/gtk.h>
+
+#include "globals.h"
+#include "nameres_prefs.h"
+#include "gtkglobals.h"
+#include "resolv.h"
+#include "prefs.h"
+#include "prefs_dlg.h"
+#include "ui_util.h"
+#include "main.h"
+
+#define M_RESOLVE_KEY "m_resolve"
+#define N_RESOLVE_KEY "n_resolve"
+#define T_RESOLVE_KEY "t_resolve"
+
+#define RESOLV_TABLE_ROWS 3
+GtkWidget*
+nameres_prefs_show(void)
+{
+ GtkWidget *main_tb, *main_vb;
+ GtkWidget *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
+
+ /*
+ * XXX - it would be nice if the current setting of the resolver
+ * flags could be different from the preference flags, so that
+ * the preference flags would represent what the user *typically*
+ * wants, but they could override them for particular captures
+ * without a subsequent editing of the preferences recording the
+ * temporary settings as permanent preferences.
+ */
+ prefs.name_resolve = g_resolv_flags;
+
+ /* Main vertical box */
+ main_vb = gtk_vbox_new(FALSE, 7);
+ gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
+
+ /* Main table */
+ main_tb = gtk_table_new(RESOLV_TABLE_ROWS, 3, FALSE);
+ gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
+ gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
+ gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
+ gtk_widget_show(main_tb);
+
+ /* Resolve MAC addresses */
+ m_resolv_cb = create_preference_check_button(main_tb, 0,
+ "Enable MAC name resolution:",
+ prefs.name_resolve & RESOLV_MAC);
+ gtk_object_set_data(GTK_OBJECT(main_vb), M_RESOLVE_KEY, m_resolv_cb);
+
+ /* Resolve network addresses */
+ n_resolv_cb = create_preference_check_button(main_tb, 1,
+ "Enable network name resolution:",
+ prefs.name_resolve & RESOLV_NETWORK);
+ gtk_object_set_data(GTK_OBJECT(main_vb), N_RESOLVE_KEY, n_resolv_cb);
+
+ /* Resolve transport addresses */
+ t_resolv_cb = create_preference_check_button(main_tb, 2,
+ "Enable transport name resolution:",
+ prefs.name_resolve & RESOLV_TRANSPORT);
+ gtk_object_set_data(GTK_OBJECT(main_vb), T_RESOLVE_KEY, t_resolv_cb);
+
+ /* Show 'em what we got */
+ gtk_widget_show_all(main_vb);
+
+ return(main_vb);
+}
+
+void
+nameres_prefs_fetch(GtkWidget *w)
+{
+ GtkWidget *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
+
+ m_resolv_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(w),
+ M_RESOLVE_KEY);
+ n_resolv_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(w),
+ N_RESOLVE_KEY);
+ t_resolv_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(w),
+ T_RESOLVE_KEY);
+
+ prefs.name_resolve = RESOLV_NONE;
+ prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE);
+ prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE);
+ prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
+}
+
+void
+nameres_prefs_apply(GtkWidget *w)
+{
+ /*
+ * XXX - force a regeneration of the protocol list if this has
+ * changed?
+ */
+ g_resolv_flags = prefs.name_resolve;
+}
+
+void
+nameres_prefs_destroy(GtkWidget *w)
+{
+}
diff --git a/gtk/nameres_prefs.h b/gtk/nameres_prefs.h
new file mode 100644
index 0000000000..22a216e556
--- /dev/null
+++ b/gtk/nameres_prefs.h
@@ -0,0 +1,33 @@
+/* nameres_prefs.h
+ * Definitions for name resolution preferences window
+ *
+ * $Id: nameres_prefs.h,v 1.1 2002/01/13 20:35:12 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __NAMERES_PREFS_H__
+#define __NAMERES_PREFS_H__
+
+GtkWidget *nameres_prefs_show(void);
+void nameres_prefs_fetch(GtkWidget *w);
+void nameres_prefs_apply(GtkWidget *w);
+void nameres_prefs_destroy(GtkWidget *w);
+
+#endif
diff --git a/gtk/prefs_dlg.c b/gtk/prefs_dlg.c
index 9712545cfc..3fba2a0c66 100644
--- a/gtk/prefs_dlg.c
+++ b/gtk/prefs_dlg.c
@@ -1,7 +1,7 @@
/* prefs_dlg.c
* Routines for handling preferences
*
- * $Id: prefs_dlg.c,v 1.37 2002/01/11 07:40:31 guy Exp $
+ * $Id: prefs_dlg.c,v 1.38 2002/01/13 20:35:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -58,6 +58,7 @@
#include "stream_prefs.h"
#include "gui_prefs.h"
#include "capture_prefs.h"
+#include "nameres_prefs.h"
#include "ui_util.h"
#include "dlg_utils.h"
#include "simple_dialog.h"
@@ -77,6 +78,7 @@ static void prefs_tree_select_cb(GtkCTree *, GtkCTreeNode *, gint, gpointer);
#define E_STREAM_PAGE_KEY "tcp_stream_options_page"
#define E_GUI_PAGE_KEY "gui_options_page"
#define E_CAPTURE_PAGE_KEY "capture_options_page"
+#define E_NAMERES_PAGE_KEY "nameres_options_page"
#define FIRST_PROTO_PREFS_PAGE 4
@@ -114,11 +116,7 @@ pref_show(pref_t *pref, gpointer user_data)
GtkWidget *main_tb = user_data;
const char *title;
char *label_string;
- GtkWidget *label, *menu, *menu_item, *widget, *button;
- GSList *rb_group;
char uint_str[10+1];
- const enum_val_t *enum_valp;
- int menu_index, index;
/* Give this preference a label which is its title, followed by a colon,
and left-align it. */
@@ -126,18 +124,10 @@ pref_show(pref_t *pref, gpointer user_data)
label_string = g_malloc(strlen(title) + 2);
strcpy(label_string, title);
strcat(label_string, ":");
- label = gtk_label_new(label_string);
- g_free(label_string);
- gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
-
- /* Attach it to the table. */
- gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1, pref->ordinal,
- pref->ordinal+1);
/* Save the current value of the preference, so that we can revert it if
the user does "Apply" and then "Cancel", and create the control for
editing the preference. */
- widget = NULL; /* squelch GCC complaints */
switch (pref->type) {
case PREF_UINT:
@@ -147,7 +137,6 @@ pref_show(pref_t *pref, gpointer user_data)
Even more annoyingly, even if there were, GLib doesn't define
G_MAXUINT - but I think ANSI C may define UINT_MAX, so we could
use that. */
- widget = gtk_entry_new();
switch (pref->info.base) {
case 10:
@@ -162,74 +151,47 @@ pref_show(pref_t *pref, gpointer user_data)
sprintf(uint_str, "%x", pref->saved_val.uint);
break;
}
- gtk_entry_set_text(GTK_ENTRY(widget), uint_str);
- pref->control = widget;
+ pref->control = create_preference_entry(main_tb, pref->ordinal,
+ label_string, uint_str);
break;
case PREF_BOOL:
- pref->saved_val.bool = *pref->varp.bool;
- widget = gtk_check_button_new();
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(widget), pref->saved_val.bool);
- pref->control = widget;
+ pref->control = create_preference_check_button(main_tb, pref->ordinal,
+ label_string,
+ pref->saved_val.bool);
break;
case PREF_ENUM:
pref->saved_val.enumval = *pref->varp.enump;
if (pref->info.enum_info.radio_buttons) {
/* Show it as radio buttons. */
- widget = gtk_hbox_new(FALSE, 0);
- rb_group = NULL;
- for (enum_valp = pref->info.enum_info.enumvals, index = 0;
- enum_valp->name != NULL; enum_valp++, index++) {
- button = gtk_radio_button_new_with_label(rb_group, enum_valp->name);
- if (rb_group == NULL)
- rb_group = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
- gtk_box_pack_start(GTK_BOX(widget), button, FALSE, FALSE, 10);
- if (enum_valp->value == pref->saved_val.enumval)
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
- pref->control = button;
- }
+ pref->control = create_preference_radio_buttons(main_tb, pref->ordinal,
+ label_string,
+ pref->info.enum_info.enumvals,
+ pref->saved_val.enumval);
} else {
/* Show it as an option menu. */
- menu = gtk_menu_new();
- menu_index = -1;
- for (enum_valp = pref->info.enum_info.enumvals, index = 0;
- enum_valp->name != NULL; enum_valp++, index++) {
- menu_item = gtk_menu_item_new_with_label(enum_valp->name);
- gtk_menu_append(GTK_MENU(menu), menu_item);
- if (enum_valp->value == pref->saved_val.enumval)
- menu_index = index;
- gtk_widget_show(menu_item);
- }
-
- /* Create the option menu from the option */
- widget = gtk_option_menu_new();
- gtk_option_menu_set_menu(GTK_OPTION_MENU(widget), menu);
-
- /* Set its current value to the variable's current value */
- if (menu_index != -1)
- gtk_option_menu_set_history(GTK_OPTION_MENU(widget), menu_index);
- pref->control = widget;
+ pref->control = create_preference_option_menu(main_tb, pref->ordinal,
+ label_string,
+ pref->info.enum_info.enumvals,
+ pref->saved_val.enumval);
}
break;
case PREF_STRING:
- widget = gtk_entry_new();
if (pref->saved_val.string != NULL)
g_free(pref->saved_val.string);
pref->saved_val.string = g_strdup(*pref->varp.string);
- gtk_entry_set_text(GTK_ENTRY(widget), pref->saved_val.string);
- pref->control = widget;
+ pref->control = create_preference_entry(main_tb, pref->ordinal,
+ label_string,
+ pref->saved_val.string);
break;
case PREF_OBSOLETE:
g_assert_not_reached();
- widget = NULL;
break;
}
-
- gtk_table_attach_defaults(GTK_TABLE(main_tb), widget, 1, 2, pref->ordinal,
- pref->ordinal+1);
+ g_free(label_string);
}
#define MAX_TREE_NODE_NAME_LEN 64
@@ -276,6 +238,7 @@ prefs_cb(GtkWidget *w, gpointer dummy) {
GtkWidget *main_vb, *top_hb, *bbox, *prefs_nb, *ct_sb, *frame,
*ok_bt, *apply_bt, *save_bt, *cancel_bt;
GtkWidget *print_pg, *column_pg, *stream_pg, *gui_pg, *capture_pg;
+ GtkWidget *nameres_pg;
gchar label_str[MAX_TREE_NODE_NAME_LEN], *label_ptr = label_str;
GtkCTreeNode *ct_node;
struct ct_struct cts;
@@ -403,6 +366,20 @@ prefs_cb(GtkWidget *w, gpointer dummy) {
cts.page++;
#endif
+ /* Name resolution prefs */
+ frame = gtk_frame_new("Name resolution");
+ gtk_widget_show(GTK_WIDGET(frame));
+ nameres_pg = nameres_prefs_show();
+ gtk_container_add(GTK_CONTAINER(frame), nameres_pg);
+ gtk_object_set_data(GTK_OBJECT(prefs_w), E_NAMERES_PAGE_KEY, nameres_pg);
+ gtk_notebook_append_page (GTK_NOTEBOOK(prefs_nb), frame, NULL);
+ strcpy(label_str, "Name resolution");
+ ct_node = gtk_ctree_insert_node(GTK_CTREE(cts.ctree), NULL, NULL,
+ &label_ptr, 5, NULL, NULL, NULL, NULL, TRUE, TRUE);
+ gtk_ctree_node_set_row_data(GTK_CTREE(cts.ctree), ct_node,
+ GINT_TO_POINTER(cts.page));
+ cts.page++;
+
/* Registered prefs */
cts.notebook = prefs_nb;
strcpy(label_str, "Protocols");
@@ -460,6 +437,185 @@ prefs_cb(GtkWidget *w, gpointer dummy) {
}
static void
+set_option_label(GtkWidget *main_tb, int table_position,
+ const gchar *label_text)
+{
+ GtkWidget *label;
+
+ label = gtk_label_new(label_text);
+ gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
+ gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1,
+ table_position, table_position + 1);
+ gtk_widget_show(label);
+}
+
+GtkWidget *
+create_preference_check_button(GtkWidget *main_tb, int table_position,
+ const gchar *label_text, gboolean active)
+{
+ GtkWidget *check_box;
+
+ set_option_label(main_tb, table_position, label_text);
+
+ check_box = gtk_check_button_new();
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), active);
+ gtk_table_attach_defaults(GTK_TABLE(main_tb), check_box, 1, 2,
+ table_position, table_position + 1);
+
+ return check_box;
+}
+
+GtkWidget *
+create_preference_radio_buttons(GtkWidget *main_tb, int table_position,
+ const gchar *label_text, const enum_val_t *enumvals, gint current_val)
+{
+ GtkWidget *radio_button_hbox, *button = NULL;
+ GSList *rb_group;
+ int index;
+ const enum_val_t *enum_valp;
+
+ set_option_label(main_tb, table_position, label_text);
+
+ radio_button_hbox = gtk_hbox_new(FALSE, 0);
+ rb_group = NULL;
+ for (enum_valp = enumvals, index = 0; enum_valp->name != NULL;
+ enum_valp++, index++) {
+ button = gtk_radio_button_new_with_label(rb_group,
+ enum_valp->name);
+ gtk_widget_show(button);
+ if (rb_group == NULL)
+ rb_group = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
+ gtk_box_pack_start(GTK_BOX(radio_button_hbox), button, FALSE,
+ FALSE, 10);
+ if (enum_valp->value == current_val) {
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
+ TRUE);
+ }
+ }
+ gtk_widget_show(radio_button_hbox);
+ gtk_table_attach_defaults(GTK_TABLE(main_tb), radio_button_hbox, 1, 2,
+ table_position, table_position+1);
+
+ /*
+ * It doesn't matter which of the buttons we return - we fetch
+ * the value by looking at the entire radio button group to
+ * which it belongs, and we can get that from any button.
+ */
+ return button;
+}
+
+static gint
+label_to_enum_val(GtkWidget *label, const enum_val_t *enumvals)
+{
+ char *label_string;
+ gint enumval;
+
+ /* Get the label's text, and translate it to a value. */
+ gtk_label_get(GTK_LABEL(label), &label_string);
+ enumval = find_val_for_string(label_string, enumvals, 1);
+
+ return enumval;
+}
+
+gint
+fetch_preference_radio_buttons_val(GtkWidget *button,
+ const enum_val_t *enumvals)
+{
+ GSList *rb_group;
+ GSList *rb_entry;
+
+ /*
+ * Go through the list of of radio buttons in the button's group,
+ * and find the first one that's active.
+ */
+ rb_group = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
+ button = NULL;
+ for (rb_entry = rb_group; rb_entry != NULL;
+ rb_entry = g_slist_next(rb_entry)) {
+ button = rb_entry->data;
+ if (GTK_TOGGLE_BUTTON(button)->active)
+ break;
+ }
+
+ /* OK, now return the value corresponding to that button's label. */
+ return label_to_enum_val(GTK_BIN(button)->child, enumvals);
+}
+
+GtkWidget *
+create_preference_option_menu(GtkWidget *main_tb, int table_position,
+ const gchar *label_text, const enum_val_t *enumvals, gint current_val)
+{
+ GtkWidget *label, *menu_box, *menu, *menu_item, *option_menu;
+ int menu_index, index;
+ const enum_val_t *enum_valp;
+
+ set_option_label(main_tb, table_position, label_text);
+
+ /* Create a menu from the enumvals */
+ menu = gtk_menu_new();
+ menu_index = -1;
+ for (enum_valp = enumvals, index = 0; enum_valp->name != NULL;
+ enum_valp++, index++) {
+ menu_item = gtk_menu_item_new_with_label(enum_valp->name);
+ gtk_menu_append(GTK_MENU(menu), menu_item);
+ if (enum_valp->value == current_val)
+ menu_index = index;
+ gtk_widget_show(menu_item);
+ }
+
+ /* Create the option menu from the menu */
+ option_menu = gtk_option_menu_new();
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
+
+ /* Set its current value to the variable's current value */
+ if (menu_index != -1)
+ gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu),
+ menu_index);
+
+ /*
+ * Put the option menu in an hbox, so that it's only as wide
+ * as the widest entry, rather than being as wide as the table
+ * space.
+ */
+ menu_box = gtk_hbox_new(FALSE, 0);
+ gtk_table_attach_defaults(GTK_TABLE(main_tb), menu_box,
+ 1, 2, table_position, table_position + 1);
+ gtk_box_pack_start(GTK_BOX(menu_box), option_menu, FALSE, FALSE, 0);
+ return option_menu;
+}
+
+gint
+fetch_preference_option_menu_val(GtkWidget *optmenu, const enum_val_t *enumvals)
+{
+ /*
+ * OK, now return the value corresponding to the label for the
+ * currently active entry in the option menu.
+ *
+ * Yes, this is how you get the label for that entry. See FAQ
+ * 6.8 in the GTK+ FAQ.
+ */
+ return label_to_enum_val(GTK_BIN(optmenu)->child, enumvals);
+}
+
+GtkWidget *
+create_preference_entry(GtkWidget *main_tb, int table_position,
+ const gchar *label_text, char *value)
+{
+ GtkWidget *entry;
+
+ set_option_label(main_tb, table_position, label_text);
+
+ entry = gtk_entry_new();
+ if (value != NULL)
+ gtk_entry_set_text(GTK_ENTRY(entry), value);
+ gtk_table_attach_defaults(GTK_TABLE(main_tb), entry, 1, 2,
+ table_position, table_position + 1);
+ gtk_widget_show(entry);
+
+ return entry;
+}
+
+static void
pref_fetch(pref_t *pref, gpointer user_data)
{
GtkWidget *label;
@@ -500,28 +656,13 @@ pref_fetch(pref_t *pref, gpointer user_data)
case PREF_ENUM:
if (pref->info.enum_info.radio_buttons) {
- /* Go through the list of of radio buttons in the group, and find
- the first one that's active. */
- button = NULL;
- for (rb_entry = gtk_radio_button_group(GTK_RADIO_BUTTON(pref->control));
- rb_entry != NULL;
- rb_entry = g_slist_next(rb_entry)) {
- button = rb_entry->data;
- if (GTK_TOGGLE_BUTTON(button)->active)
- break;
- }
- /* OK, now find that button's label. */
- label = GTK_BIN(button)->child;
+ enumval = fetch_preference_radio_buttons_val(pref->control,
+ pref->info.enum_info.enumvals);
} else {
- /* Get the label for the currently active entry in the option menu.
- Yes, this is how you do it. See FAQ 6.8 in the GTK+ FAQ. */
- label = GTK_BIN(pref->control)->child;
+ enumval = fetch_preference_option_menu_val(pref->control,
+ pref->info.enum_info.enumvals);
}
- /* Get the label, and translate it to a value. */
- gtk_label_get(GTK_LABEL(label), &label_string);
- enumval = find_val_for_string(label_string,
- pref->info.enum_info.enumvals, 1);
if (*pref->varp.enump != enumval) {
*pref_changed_p = TRUE;
*pref->varp.enump = enumval;
@@ -609,6 +750,7 @@ prefs_main_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
stream_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
+ nameres_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_module_foreach(module_prefs_fetch, &must_redissect);
/* Now apply those preferences. */
@@ -617,6 +759,7 @@ prefs_main_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
stream_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
+ nameres_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_apply_all();
/* Now destroy the "Preferences" dialog. */
@@ -641,6 +784,7 @@ prefs_main_apply_cb(GtkWidget *apply_bt, gpointer parent_w)
stream_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
+ nameres_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_module_foreach(module_prefs_fetch, &must_redissect);
/* Now apply those preferences. */
@@ -649,6 +793,7 @@ prefs_main_apply_cb(GtkWidget *apply_bt, gpointer parent_w)
stream_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
+ nameres_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_apply_all();
if (must_redissect) {
@@ -673,6 +818,7 @@ prefs_main_save_cb(GtkWidget *save_bt, gpointer parent_w)
stream_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
+ nameres_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_module_foreach(module_prefs_fetch, &must_redissect);
/* Create the directory that holds personal configuration files, if
@@ -711,6 +857,7 @@ prefs_main_save_cb(GtkWidget *save_bt, gpointer parent_w)
stream_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
+ nameres_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_apply_all();
if (must_redissect) {
@@ -802,7 +949,7 @@ prefs_main_cancel_cb(GtkWidget *cancel_bt, gpointer parent_w)
column_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_COLUMN_PAGE_KEY));
stream_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
- capture_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
+ nameres_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_apply_all();
gtk_widget_destroy(GTK_WIDGET(parent_w));
@@ -833,6 +980,7 @@ prefs_main_destroy_cb(GtkWidget *win, gpointer user_data)
stream_prefs_destroy(gtk_object_get_data(GTK_OBJECT(prefs_w), E_STREAM_PAGE_KEY));
gui_prefs_destroy(gtk_object_get_data(GTK_OBJECT(prefs_w), E_GUI_PAGE_KEY));
capture_prefs_destroy(gtk_object_get_data(GTK_OBJECT(prefs_w), E_CAPTURE_PAGE_KEY));
+ nameres_prefs_destroy(gtk_object_get_data(GTK_OBJECT(prefs_w), E_NAMERES_PAGE_KEY));
/* Free up the saved preferences (both for "prefs" and for registered
preferences). */
@@ -909,4 +1057,3 @@ prefs_tree_select_cb(GtkCTree *ct, GtkCTreeNode *node, gint col, gpointer dummy)
if (page >= 0)
gtk_notebook_set_page(GTK_NOTEBOOK(notebook), page);
}
-
diff --git a/gtk/prefs_dlg.h b/gtk/prefs_dlg.h
index bc7a316e98..612547248a 100644
--- a/gtk/prefs_dlg.h
+++ b/gtk/prefs_dlg.h
@@ -1,7 +1,7 @@
/* prefs_dlg.h
* Definitions for preference handling routines
*
- * $Id: prefs_dlg.h,v 1.6 2002/01/11 07:40:31 guy Exp $
+ * $Id: prefs_dlg.h,v 1.7 2002/01/13 20:35:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -25,7 +25,17 @@
#ifndef __PREFS_DLG_H__
#define __PREFS_DLG_H__
-void prefs_cb(GtkWidget *, gpointer);
-void properties_cb(GtkWidget *, gpointer);
+void prefs_cb(GtkWidget *, gpointer);
+void properties_cb(GtkWidget *, gpointer);
+
+GtkWidget *create_preference_check_button(GtkWidget *, int, const gchar *,
+ gboolean);
+GtkWidget *create_preference_radio_buttons(GtkWidget *, int, const gchar *,
+ const enum_val_t *, gint);
+gint fetch_preference_radio_buttons_val(GtkWidget *, const enum_val_t *);
+GtkWidget *create_preference_option_menu(GtkWidget *, int, const gchar *,
+ const enum_val_t *, gint);
+gint fetch_preference_option_menu_val(GtkWidget *, const enum_val_t *);
+GtkWidget *create_preference_entry(GtkWidget *, int, const gchar *, char *);
#endif
diff --git a/gtk/print_prefs.c b/gtk/print_prefs.c
index bb547fb8ee..888915bb72 100644
--- a/gtk/print_prefs.c
+++ b/gtk/print_prefs.c
@@ -1,7 +1,7 @@
/* print_prefs.c
* Dialog boxes for preferences for printing
*
- * $Id: print_prefs.c,v 1.9 2002/01/11 07:40:31 guy Exp $
+ * $Id: print_prefs.c,v 1.10 2002/01/13 20:35:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -34,6 +34,7 @@
#include "keys.h"
#include "print.h"
#include "prefs.h"
+#include "prefs_dlg.h"
#include "util.h"
#include "ui_util.h"
#include "dlg_utils.h"
@@ -42,20 +43,29 @@ static void printer_opts_file_cb(GtkWidget *w, gpointer te);
static void printer_opts_fs_ok_cb(GtkWidget *w, gpointer data);
static void printer_opts_fs_cancel_cb(GtkWidget *w, gpointer data);
static void printer_opts_fs_destroy_cb(GtkWidget *win, gpointer data);
-static void printer_opts_toggle_format(GtkWidget *widget, gpointer data);
-static void printer_opts_toggle_dest(GtkWidget *widget, gpointer data);
#define E_FS_CALLER_PTR_KEY "fs_caller_ptr"
#define E_FILE_SEL_DIALOG_PTR_KEY "file_sel_dialog_ptr"
+#define E_PRINT_FORMAT_KEY "print_format"
+#define E_PRINT_DESTINATION_KEY "print_destination"
+
+static const enum_val_t print_format_vals[] = {
+ { "Plain Text", PR_FMT_TEXT },
+ { "Postscript", PR_FMT_PS },
+ { NULL, 0 }
+};
+
+static const enum_val_t print_dest_vals[] = {
+ { "Command", PR_DEST_CMD },
+ { "File", PR_DEST_FILE },
+ { NULL, 0 }
+};
GtkWidget * printer_prefs_show(void)
{
GtkWidget *main_vb, *main_tb, *button;
- GtkWidget *format_hb, *format_lb;
- GtkWidget *dest_hb, *dest_lb;
- GtkWidget *cmd_lb, *cmd_te;
+ GtkWidget *cmd_te;
GtkWidget *file_bt_hb, *file_bt, *file_te;
- GSList *format_grp, *dest_grp;
/* Enclosing containers for each row of widgets */
main_vb = gtk_vbox_new(FALSE, 5);
@@ -68,70 +78,19 @@ GtkWidget * printer_prefs_show(void)
gtk_widget_show(main_tb);
/* Output format */
- format_lb = gtk_label_new("Format:");
- gtk_misc_set_alignment(GTK_MISC(format_lb), 1.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), format_lb, 0, 1, 0, 1);
- gtk_widget_show(format_lb);
-
- format_hb = gtk_hbox_new(FALSE, 0);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), format_hb, 1, 2, 0, 1);
- gtk_widget_show(format_hb);
-
- button = gtk_radio_button_new_with_label(NULL, "Plain Text");
- if (prefs.pr_format == PR_FMT_TEXT) {
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
- }
- format_grp = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
- gtk_box_pack_start(GTK_BOX(format_hb), button, FALSE, FALSE, 10);
- gtk_widget_show(button);
-
- button = gtk_radio_button_new_with_label(format_grp, "PostScript");
- if (prefs.pr_format == PR_FMT_PS) {
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
- }
- gtk_signal_connect(GTK_OBJECT(button), "toggled",
- GTK_SIGNAL_FUNC(printer_opts_toggle_format), NULL);
- gtk_box_pack_start(GTK_BOX(format_hb), button, FALSE, FALSE, 10);
- gtk_widget_show(button);
+ button = create_preference_radio_buttons(main_tb, 0, "Format:",
+ print_format_vals, prefs.pr_format);
+ gtk_object_set_data(GTK_OBJECT(main_vb), E_PRINT_FORMAT_KEY, button);
/* Output destination */
- dest_lb = gtk_label_new("Print to:");
- gtk_misc_set_alignment(GTK_MISC(dest_lb), 1.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), dest_lb, 0, 1, 1, 2);
- gtk_widget_show(dest_lb);
-
- dest_hb = gtk_hbox_new(FALSE, 0);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), dest_hb, 1, 2, 1, 2);
- gtk_widget_show(dest_hb);
-
- button = gtk_radio_button_new_with_label(NULL, "Command");
- if (prefs.pr_dest == PR_DEST_CMD) {
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
- }
- dest_grp = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
- gtk_box_pack_start(GTK_BOX(dest_hb), button, FALSE, FALSE, 10);
- gtk_widget_show(button);
-
- button = gtk_radio_button_new_with_label(dest_grp, "File");
- if (prefs.pr_dest == PR_DEST_FILE) {
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
- }
- gtk_signal_connect(GTK_OBJECT(button), "toggled",
- GTK_SIGNAL_FUNC(printer_opts_toggle_dest), NULL);
- gtk_box_pack_start(GTK_BOX(dest_hb), button, FALSE, FALSE, 10);
- gtk_widget_show(button);
+ button = create_preference_radio_buttons(main_tb, 1, "Print to:",
+ print_dest_vals, prefs.pr_dest);
+ gtk_object_set_data(GTK_OBJECT(main_vb), E_PRINT_DESTINATION_KEY,
+ button);
/* Command text entry */
- cmd_lb = gtk_label_new("Command:");
- gtk_misc_set_alignment(GTK_MISC(cmd_lb), 1.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), cmd_lb, 0, 1, 2, 3);
- gtk_widget_show(cmd_lb);
-
- cmd_te = gtk_entry_new();
+ cmd_te = create_preference_entry(main_tb, 2, "Command:", prefs.pr_cmd);
gtk_object_set_data(GTK_OBJECT(main_vb), PRINT_CMD_TE_KEY, cmd_te);
- if (prefs.pr_cmd) gtk_entry_set_text(GTK_ENTRY(cmd_te), prefs.pr_cmd);
- gtk_table_attach_defaults(GTK_TABLE(main_tb), cmd_te, 1, 2, 2, 3);
- gtk_widget_show(cmd_te);
/* File button and text entry */
file_bt_hb = gtk_hbox_new(FALSE, 0);
@@ -236,19 +195,25 @@ printer_opts_fs_destroy_cb(GtkWidget *win, gpointer data)
void
printer_prefs_fetch(GtkWidget *w)
{
- if (prefs.pr_cmd)
- g_free(prefs.pr_cmd);
- prefs.pr_cmd =
- g_strdup(gtk_entry_get_text(
- GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
- PRINT_CMD_TE_KEY))));
-
- if (prefs.pr_file)
- g_free(prefs.pr_file);
- prefs.pr_file =
- g_strdup(gtk_entry_get_text(
- GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
- PRINT_FILE_TE_KEY))));
+ prefs.pr_format = fetch_preference_radio_buttons_val(
+ gtk_object_get_data(GTK_OBJECT(w), E_PRINT_FORMAT_KEY),
+ print_format_vals);
+
+ prefs.pr_dest = fetch_preference_radio_buttons_val(
+ gtk_object_get_data(GTK_OBJECT(w), E_PRINT_DESTINATION_KEY),
+ print_dest_vals);
+
+ if (prefs.pr_cmd)
+ g_free(prefs.pr_cmd);
+ prefs.pr_cmd = g_strdup(gtk_entry_get_text(
+ GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
+ PRINT_CMD_TE_KEY))));
+
+ if (prefs.pr_file)
+ g_free(prefs.pr_file);
+ prefs.pr_file = g_strdup(gtk_entry_get_text(
+ GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
+ PRINT_FILE_TE_KEY))));
}
void
@@ -271,27 +236,3 @@ printer_prefs_destroy(GtkWidget *w)
gtk_widget_destroy(fs);
}
}
-
-static void
-printer_opts_toggle_format(GtkWidget *widget, gpointer data)
-{
- if (GTK_TOGGLE_BUTTON (widget)->active) {
- prefs.pr_format = PR_FMT_PS;
- /* toggle file/cmd */
- }
- else {
- prefs.pr_format = PR_FMT_TEXT;
- /* toggle file/cmd */
- }
-}
-
-static void
-printer_opts_toggle_dest(GtkWidget *widget, gpointer data)
-{
- if (GTK_TOGGLE_BUTTON (widget)->active) {
- prefs.pr_dest = PR_DEST_FILE;
- }
- else {
- prefs.pr_dest = PR_DEST_CMD;
- }
-}