Implements the "Properties" menu item which displays the preferences window

at the correct notebook page when a particular protocol (which has registered
some preferences) is selected in the tree view.

- add set_menus_for_selected_tree_row() in menu.[ch]

- add prefs_is_registered_protocol() and
      prefs_get_title_by_name() in prefs.[ch]

svn path=/trunk/; revision=2275
This commit is contained in:
Laurent Deniel 2000-08-15 20:46:17 +00:00
parent e784cb0c0f
commit 5a326952de
8 changed files with 127 additions and 9 deletions

View File

@ -43,6 +43,7 @@ Laurent Deniel <deniel@worldnet.fr> {
GUI enhancements (about & help windows)
Follow TCP stream for IPv6
Protocol activation/deactivation (Edit:protocols)
"Properties..." menu item
Miscellaneous enhancements and fixes
}

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.133 2000/08/11 13:33:06 deniel Exp $
* $Id: main.c,v 1.134 2000/08/15 20:46:17 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -483,6 +483,8 @@ tree_view_select_row_cb(GtkCTree *ctree, GList *node, gint column, gpointer user
finfo_selected = finfo;
set_menus_for_selected_tree_row(TRUE);
packet_hex_print(GTK_TEXT(byte_view), cfile.pd, cfile.current_frame->cap_len,
finfo->start, finfo->length, cfile.current_frame->flags.encoding);
}
@ -491,6 +493,7 @@ static void
tree_view_unselect_row_cb(GtkCTree *ctree, GList *node, gint column, gpointer user_data)
{
finfo_selected = NULL;
set_menus_for_selected_tree_row(FALSE);
packet_hex_print(GTK_TEXT(byte_view), cfile.pd, cfile.current_frame->cap_len,
-1, -1, cfile.current_frame->flags.encoding);
}

View File

@ -1,7 +1,7 @@
/* menu.c
* Menu routines
*
* $Id: menu.c,v 1.35 2000/08/13 14:03:50 deniel Exp $
* $Id: menu.c,v 1.36 2000/08/15 20:41:59 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -158,6 +158,7 @@ static GtkItemFactoryEntry tree_view_menu_items[] =
{
{"/Match Selected", NULL, GTK_MENU_FUNC(match_selected_cb), 0, NULL},
{"/Resolve Name", NULL, GTK_MENU_FUNC(resolve_name_cb), 0, NULL},
{"/Properties...", NULL, GTK_MENU_FUNC(properties_cb), 0, NULL},
{"/Follow TCP Stream", NULL, GTK_MENU_FUNC(follow_stream_cb), 0, NULL},
{"/Filters...", NULL, GTK_MENU_FUNC(filter_dialog_cb), 0, NULL},
{"/<separator>", NULL, NULL, 0, "<Separator>"},
@ -345,5 +346,21 @@ set_menus_for_selected_packet(gboolean have_selected_packet)
set_menu_sensitivity("/Tools/Follow TCP Stream",
have_selected_packet ? (pi.ipproto == 6) : FALSE);
set_menu_sensitivity("/Resolve Name",
have_selected_packet && !g_resolving_actif);
have_selected_packet && !g_resolving_actif);
}
/* Enable or disable menu items based on whether a tree row is selected. */
void
set_menus_for_selected_tree_row(gboolean have_selected_tree)
{
gboolean properties = FALSE;
if (finfo_selected) {
header_field_info *hfinfo = finfo_selected->hfinfo;
if (hfinfo->parent == -1) {
properties = prefs_is_registered_protocol(hfinfo->abbrev);
} else {
properties = prefs_is_registered_protocol(proto_registrar_get_abbrev(hfinfo->parent));
}
}
set_menu_sensitivity("/Properties...", have_selected_tree && properties);
}

View File

@ -1,7 +1,7 @@
/* prefs_dlg.c
* Routines for handling preferences
*
* $Id: prefs_dlg.c,v 1.17 2000/08/11 13:33:05 deniel Exp $
* $Id: prefs_dlg.c,v 1.18 2000/08/15 20:41:58 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -74,6 +74,14 @@ static void prefs_main_destroy_cb(GtkWidget *, gpointer);
#define E_STREAM_PAGE_KEY "tcp_stream_options_page"
#define E_GUI_PAGE_KEY "gui_options_page"
#define FIRST_PROTO_PREFS_PAGE 4
/*
* Keep a static pointer to the notebook to be able to choose the
* displayed page.
*/
static GtkWidget *notebook;
/*
* Keep a static pointer to the current "Preferences" window, if any, so that
* if somebody tries to do "Edit:Preferences" while there's already a
@ -260,7 +268,7 @@ prefs_cb(GtkWidget *w, gpointer dummy) {
gtk_container_add(GTK_CONTAINER(main_vb), top_hb);
gtk_widget_show(top_hb);
prefs_nb = gtk_notebook_new();
notebook = prefs_nb = gtk_notebook_new();
gtk_container_add(GTK_CONTAINER(main_vb), prefs_nb);
gtk_widget_show(prefs_nb);
@ -603,3 +611,59 @@ prefs_main_destroy_cb(GtkWidget *win, gpointer user_data)
/* Note that we no longer have a "Preferences" dialog box. */
prefs_w = NULL;
}
struct properties_data {
GtkWidget *w;
int page_num;
char *title;
};
/* XXX this way of searching the correct page number is really ugly ... */
static void
module_search_properties(module_t *module, gpointer user_data)
{
struct properties_data *p = (struct properties_data *)user_data;
if (p->title == NULL) return;
if (strcmp(module->title, p->title) == 0) {
/* found it */
gtk_notebook_set_page(GTK_NOTEBOOK(p->w), p->page_num);
p->title = NULL;
} else {
p->page_num++;
}
}
void
properties_cb(GtkWidget *w, gpointer dummy)
{
gchar *title = NULL;
struct properties_data p;
if (finfo_selected) {
header_field_info *hfinfo = finfo_selected->hfinfo;
if (hfinfo->parent == -1) {
title = prefs_get_title_by_name(hfinfo->abbrev);
} else {
title =
prefs_get_title_by_name(proto_registrar_get_abbrev(hfinfo->parent));
}
} else {
return;
}
if (!title) return;
if (prefs_w != NULL) {
reactivate_window(prefs_w);
} else {
prefs_cb(w, dummy);
}
p.w = notebook;
p.page_num = FIRST_PROTO_PREFS_PAGE;
p.title = title;
prefs_module_foreach(module_search_properties, &p);
}

View File

@ -1,7 +1,7 @@
/* prefs_dlg.h
* Definitions for preference handling routines
*
* $Id: prefs_dlg.h,v 1.4 2000/08/11 13:32:59 deniel Exp $
* $Id: prefs_dlg.h,v 1.5 2000/08/15 20:41:59 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -29,5 +29,6 @@
#include "prefs.h"
void prefs_cb(GtkWidget *, gpointer);
void properties_cb(GtkWidget *, gpointer);
#endif

5
menu.h
View File

@ -2,7 +2,7 @@
* Definitions for menu routines with toolkit-independent APIs but
* toolkit-dependent implementations.
*
* $Id: menu.h,v 1.7 2000/01/03 03:56:55 guy Exp $
* $Id: menu.h,v 1.8 2000/08/15 20:42:09 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -52,6 +52,9 @@ void set_menus_for_captured_packets(gboolean);
/* Enable or disable menu items based on whether a packet is selected. */
void set_menus_for_selected_packet(gboolean);
/* Enable or disable menu items based on whether a tree row is selected. */
void set_menus_for_selected_tree_row(gboolean);
#ifdef __cplusplus
}
#endif /* __cplusplus */

21
prefs.c
View File

@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
* $Id: prefs.c,v 1.34 2000/08/11 13:34:44 deniel Exp $
* $Id: prefs.c,v 1.35 2000/08/15 20:42:09 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -228,6 +228,25 @@ find_preference(module_t *module, char *name)
return (struct preference *) list_entry->data;
}
/*
* Returns TRUE if the given protocol has registered preferences
*/
gboolean
prefs_is_registered_protocol(char *name)
{
return (find_module(name) != NULL);
}
/*
* Returns the module title of a registered protocol
*/
char *
prefs_get_title_by_name(char *name)
{
module_t *m = find_module(name);
return (m) ? m->title : NULL;
}
/*
* Register a preference with an unsigned integral value.
*/

12
prefs.h
View File

@ -1,7 +1,7 @@
/* prefs.h
* Definitions for preference handling routines
*
* $Id: prefs.h,v 1.17 2000/07/09 03:29:28 guy Exp $
* $Id: prefs.h,v 1.18 2000/08/15 20:42:10 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -87,6 +87,16 @@ struct preference;
typedef struct preference pref_t;
/*
* Returns TRUE if the given protocol has registered preferences
*/
gboolean prefs_is_registered_protocol(char *name);
/*
* Returns the module title of a registered protocol (or NULL if unknown)
*/
char *prefs_get_title_by_name(char *name);
/*
* Register a preference with an unsigned integral value.
*/