Fix for bug #93: changes to the columns has no effect until restart
These changes allow the packet list clist to be destroyed and recreated with the new column titles/values/order that the user changed in the preferences without restarting Wireshark. svn path=/trunk/; revision=22038
This commit is contained in:
parent
c4b66c82e7
commit
d1d72fd232
|
@ -37,6 +37,9 @@
|
|||
|
||||
#include <epan/timestamp.h>
|
||||
#include <epan/prefs.h>
|
||||
#include <epan/nstime.h>
|
||||
#include <epan/dfilter/dfilter.h>
|
||||
#include "cfile.h"
|
||||
#include <epan/column.h>
|
||||
#include <epan/packet.h>
|
||||
|
||||
|
@ -752,3 +755,46 @@ get_column_title(gint col) {
|
|||
|
||||
return(cfmt->title);
|
||||
}
|
||||
|
||||
void
|
||||
build_column_format_array(capture_file *cfile, gboolean reset_fences)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
col_setup(&cfile->cinfo, prefs.num_cols);
|
||||
|
||||
for (i = 0; i < cfile->cinfo.num_cols; i++) {
|
||||
cfile->cinfo.col_fmt[i] = get_column_format(i);
|
||||
cfile->cinfo.col_title[i] = g_strdup(get_column_title(i));
|
||||
cfile->cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) *
|
||||
NUM_COL_FMTS);
|
||||
get_column_format_matches(cfile->cinfo.fmt_matx[i],
|
||||
cfile->cinfo.col_fmt[i]);
|
||||
cfile->cinfo.col_data[i] = NULL;
|
||||
|
||||
if (cfile->cinfo.col_fmt[i] == COL_INFO)
|
||||
cfile->cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) *
|
||||
COL_MAX_INFO_LEN);
|
||||
else
|
||||
cfile->cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
|
||||
|
||||
if(reset_fences)
|
||||
cfile->cinfo.col_fence[i] = 0;
|
||||
|
||||
cfile->cinfo.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
|
||||
cfile->cinfo.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) *
|
||||
COL_MAX_LEN);
|
||||
}
|
||||
|
||||
for (i = 0; i < cfile->cinfo.num_cols; i++) {
|
||||
for (j = 0; j < NUM_COL_FMTS; j++) {
|
||||
if (!cfile->cinfo.fmt_matx[i][j])
|
||||
continue;
|
||||
|
||||
if (cfile->cinfo.col_first[j] == -1)
|
||||
cfile->cinfo.col_first[j] = i;
|
||||
|
||||
cfile->cinfo.col_last[j] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,9 @@ const gchar *get_column_width_string(gint, gint);
|
|||
const char *get_column_longest_string(gint);
|
||||
gint get_column_char_width(gint format);
|
||||
|
||||
void
|
||||
build_column_format_array(capture_file *cfile, gboolean reset_fences);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -47,6 +47,7 @@ typedef struct _column_info {
|
|||
gchar **col_expr; /* Filter expression */
|
||||
gchar **col_expr_val; /* Value for filter expression */
|
||||
gboolean writable; /* Are we still writing to the columns? */
|
||||
gboolean columns_changed; /* Have the columns been changed in the prefs? */
|
||||
} column_info;
|
||||
|
||||
/*
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include <epan/packet.h>
|
||||
#include <epan/prefs.h>
|
||||
#include <epan/proto.h>
|
||||
#include "cfile.h"
|
||||
#include <epan/column.h>
|
||||
#include "print.h"
|
||||
#include <wiretap/file_util.h>
|
||||
|
|
1
file.c
1
file.c
|
@ -52,6 +52,7 @@
|
|||
|
||||
#include "color.h"
|
||||
#include "color_filters.h"
|
||||
#include "cfile.h"
|
||||
#include <epan/column.h>
|
||||
#include <epan/packet.h>
|
||||
#include "packet-range.h"
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <epan/column.h>
|
||||
#include "compat_macros.h"
|
||||
#include "gui_utils.h"
|
||||
#include "packet_list.h"
|
||||
|
||||
static GtkWidget *column_l, *del_bt, *title_te, *fmt_m, *up_bt, *dn_bt;
|
||||
static gint cur_fmt, cur_row;
|
||||
|
@ -264,7 +265,6 @@ column_prefs_show() {
|
|||
|
||||
title_te = gtk_entry_new();
|
||||
gtk_table_attach_defaults(GTK_TABLE(tb), title_te, 1, 2, 0, 1);
|
||||
SIGNAL_CONNECT(title_te, "changed", column_entry_changed_cb, column_l);
|
||||
gtk_widget_set_sensitive(title_te, FALSE);
|
||||
gtk_widget_show(title_te);
|
||||
|
||||
|
@ -293,11 +293,6 @@ column_prefs_show() {
|
|||
gtk_box_pack_start(GTK_BOX(props_hb), fmt_m, FALSE, FALSE, 0);
|
||||
gtk_widget_show(fmt_m);
|
||||
|
||||
lb = gtk_label_new("Unlike all other preferences, you have to restart Wireshark to let column changes take effect!");
|
||||
gtk_misc_set_alignment(GTK_MISC(lb), 0.5, 0.5);
|
||||
gtk_box_pack_start (GTK_BOX (main_vb), lb, FALSE, FALSE, 0);
|
||||
gtk_widget_show(lb);
|
||||
|
||||
/* select the first row */
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
gtk_clist_select_row(GTK_CLIST(column_l), 0, 0);
|
||||
|
@ -386,7 +381,8 @@ column_list_select_cb(GtkTreeSelection *sel, gpointer user_data _U_)
|
|||
gtk_tree_path_free(path);
|
||||
|
||||
title = g_strdup(cfmt->title);
|
||||
gtk_entry_set_text(GTK_ENTRY(title_te), title);
|
||||
gtk_entry_set_text(GTK_ENTRY(title_te), title);
|
||||
SIGNAL_CONNECT(title_te, "changed", column_entry_changed_cb, column_l);
|
||||
g_free(title);
|
||||
|
||||
gtk_editable_select_region(GTK_EDITABLE(title_te), 0, -1);
|
||||
|
@ -458,6 +454,7 @@ column_list_new_cb(GtkWidget *w _U_, gpointer data _U_) {
|
|||
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(column_l)),
|
||||
&iter);
|
||||
#endif
|
||||
cfile.cinfo.columns_changed = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -494,6 +491,7 @@ column_list_delete_cb(GtkWidget *w _U_, gpointer data _U_) {
|
|||
|
||||
gtk_clist_remove(GTK_CLIST(column_l), cur_row);
|
||||
#endif
|
||||
cfile.cinfo.columns_changed = TRUE;
|
||||
}
|
||||
|
||||
/* The user changed the column title entry box. */
|
||||
|
@ -532,6 +530,7 @@ column_entry_changed_cb(GtkEditable *te, gpointer data) {
|
|||
cfmt->title = title;
|
||||
}
|
||||
#endif
|
||||
cfile.cinfo.columns_changed = TRUE;
|
||||
}
|
||||
|
||||
/* The user changed the format menu. */
|
||||
|
@ -569,6 +568,7 @@ column_menu_changed_cb(GtkWidget *w _U_, gpointer data) {
|
|||
cfmt->fmt = g_strdup(col_format_to_string(cur_fmt));
|
||||
}
|
||||
#endif
|
||||
cfile.cinfo.columns_changed = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -655,6 +655,7 @@ column_arrow_cb(GtkWidget *w, gpointer data _U_) {
|
|||
g_free(format2);
|
||||
}
|
||||
#endif
|
||||
cfile.cinfo.columns_changed = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -675,7 +676,13 @@ column_prefs_fetch(GtkWidget *w _U_) {
|
|||
}
|
||||
|
||||
void
|
||||
column_prefs_apply(GtkWidget *w _U_) {
|
||||
column_prefs_apply(GtkWidget *w _U_)
|
||||
{
|
||||
/* Redraw the packet list if the columns were changed */
|
||||
if(cfile.cinfo.columns_changed) {
|
||||
packet_list_recreate();
|
||||
cfile.cinfo.columns_changed = FALSE; /* Reset value */
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -190,6 +190,9 @@ gui_prefs_show(void)
|
|||
/* The font haven't been changed yet. */
|
||||
font_changed = FALSE;
|
||||
|
||||
/* The columns haven't been changed yet */
|
||||
cfile.cinfo.columns_changed = FALSE;
|
||||
|
||||
/* Main vertical box */
|
||||
main_vb = gtk_vbox_new(FALSE, 7);
|
||||
gtk_container_border_width( GTK_CONTAINER(main_vb), 5 );
|
||||
|
@ -473,9 +476,9 @@ gui_prefs_apply(GtkWidget *w _U_)
|
|||
|
||||
/* XXX: redraw the toolbar only, if style changed */
|
||||
toolbar_redraw_all();
|
||||
|
||||
|
||||
set_scrollbar_placement_all();
|
||||
packet_list_set_sel_browse(prefs.gui_plist_sel_browse);
|
||||
packet_list_set_sel_browse(prefs.gui_plist_sel_browse, FALSE);
|
||||
set_ptree_sel_browse_all(prefs.gui_ptree_sel_browse);
|
||||
set_tree_styles_all();
|
||||
main_widgets_rearrange();
|
||||
|
|
35
gtk/main.c
35
gtk/main.c
|
@ -199,10 +199,11 @@
|
|||
capture_file cfile;
|
||||
GtkWidget *main_display_filter_widget=NULL;
|
||||
GtkWidget *top_level = NULL, *tree_view, *byte_nb_ptr, *tv_scrollw;
|
||||
GtkWidget *pkt_scrollw;
|
||||
static GtkWidget *main_pane_v1, *main_pane_v2, *main_pane_h1, *main_pane_h2;
|
||||
static GtkWidget *main_first_pane, *main_second_pane;
|
||||
static GtkWidget *status_pane;
|
||||
static GtkWidget *menubar, *main_vbox, *main_tb, *pkt_scrollw, *stat_hbox, *filter_tb;
|
||||
static GtkWidget *menubar, *main_vbox, *main_tb, *stat_hbox, *filter_tb;
|
||||
|
||||
#ifdef HAVE_AIRPCAP
|
||||
GtkWidget *airpcap_tb;
|
||||
|
@ -2090,7 +2091,6 @@ main(int argc, char *argv[])
|
|||
{
|
||||
char *init_progfile_dir_error;
|
||||
char *s;
|
||||
int i;
|
||||
int opt;
|
||||
extern char *optarg;
|
||||
gboolean arg_error = FALSE;
|
||||
|
@ -2841,36 +2841,7 @@ main(int argc, char *argv[])
|
|||
set_disabled_protos_list();
|
||||
}
|
||||
|
||||
/* Build the column format array */
|
||||
col_setup(&cfile.cinfo, prefs->num_cols);
|
||||
for (i = 0; i < cfile.cinfo.num_cols; i++) {
|
||||
cfile.cinfo.col_fmt[i] = get_column_format(i);
|
||||
cfile.cinfo.col_title[i] = g_strdup(get_column_title(i));
|
||||
cfile.cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) *
|
||||
NUM_COL_FMTS);
|
||||
get_column_format_matches(cfile.cinfo.fmt_matx[i], cfile.cinfo.col_fmt[i]);
|
||||
cfile.cinfo.col_data[i] = NULL;
|
||||
if (cfile.cinfo.col_fmt[i] == COL_INFO)
|
||||
cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
|
||||
else
|
||||
cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
|
||||
cfile.cinfo.col_fence[i] = 0;
|
||||
cfile.cinfo.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
|
||||
cfile.cinfo.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
|
||||
}
|
||||
|
||||
for (i = 0; i < cfile.cinfo.num_cols; i++) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < NUM_COL_FMTS; j++) {
|
||||
if (!cfile.cinfo.fmt_matx[i][j])
|
||||
continue;
|
||||
|
||||
if (cfile.cinfo.col_first[j] == -1)
|
||||
cfile.cinfo.col_first[j] = i;
|
||||
cfile.cinfo.col_last[j] = i;
|
||||
}
|
||||
}
|
||||
build_column_format_array(&cfile, TRUE);
|
||||
|
||||
/* read in rc file from global and personal configuration paths. */
|
||||
rc_file = get_datafile_path(RC_FILE);
|
||||
|
|
|
@ -330,4 +330,6 @@ extern void create_console(void);
|
|||
/* Fill in capture options with values from the preferences */
|
||||
extern void prefs_to_capture_opts(void);
|
||||
|
||||
extern GtkWidget *pkt_scrollw;
|
||||
|
||||
#endif /* __MAIN_H__ */
|
||||
|
|
|
@ -433,7 +433,7 @@ packet_list_button_pressed_cb(GtkWidget *w, GdkEvent *event, gpointer data _U_)
|
|||
|
||||
/* Set the selection mode of the packet list window. */
|
||||
void
|
||||
packet_list_set_sel_browse(gboolean val)
|
||||
packet_list_set_sel_browse(gboolean val, gboolean force_set)
|
||||
{
|
||||
GtkSelectionMode new_mode;
|
||||
/* initialize with a mode we don't use, so that the mode == new_mode
|
||||
|
@ -444,7 +444,7 @@ packet_list_set_sel_browse(gboolean val)
|
|||
* think "browse" in Wireshark makes more sense than "SINGLE" in GTK+ */
|
||||
new_mode = val ? GTK_SELECTION_SINGLE : GTK_SELECTION_BROWSE;
|
||||
|
||||
if (mode == new_mode) {
|
||||
if ((mode == new_mode) && !force_set) {
|
||||
/*
|
||||
* The mode isn't changing, so don't do anything.
|
||||
* In particular, don't gratuitiously unselect the
|
||||
|
@ -538,7 +538,7 @@ packet_list_new(e_prefs *prefs)
|
|||
/* Column titles are filled in below */
|
||||
gtk_container_add(GTK_CONTAINER(pkt_scrollw), packet_list);
|
||||
|
||||
packet_list_set_sel_browse(prefs->gui_plist_sel_browse);
|
||||
packet_list_set_sel_browse(prefs->gui_plist_sel_browse, FALSE);
|
||||
packet_list_set_font(user_font_get_regular());
|
||||
gtk_widget_set_name(packet_list, "packet list");
|
||||
SIGNAL_CONNECT(packet_list, "select-row", packet_list_select_cb, NULL);
|
||||
|
@ -568,6 +568,26 @@ packet_list_new(e_prefs *prefs)
|
|||
return pkt_scrollw;
|
||||
}
|
||||
|
||||
void
|
||||
packet_list_recreate(void)
|
||||
{
|
||||
gtk_widget_destroy(pkt_scrollw);
|
||||
|
||||
prefs.num_cols = g_list_length(prefs.col_list);
|
||||
|
||||
build_column_format_array(&cfile, FALSE);
|
||||
|
||||
pkt_scrollw = packet_list_new(&prefs);
|
||||
gtk_widget_show(pkt_scrollw);
|
||||
packet_list_set_column_titles();
|
||||
packet_list_set_sel_browse(prefs.gui_plist_sel_browse, TRUE);
|
||||
|
||||
main_widgets_rearrange();
|
||||
|
||||
if(cfile.state != FILE_CLOSED)
|
||||
cf_reload(&cfile);
|
||||
}
|
||||
|
||||
void
|
||||
packet_list_set_column_titles(void)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,9 @@
|
|||
*/
|
||||
extern GtkWidget *packet_list_new(e_prefs *prefs);
|
||||
|
||||
/** Recreate the packet list (for use after columns are changed) */
|
||||
extern void packet_list_recreate(void);
|
||||
|
||||
/** Fill in column titles. This must be done after the top level window
|
||||
* is displayed.
|
||||
*
|
||||
|
@ -95,8 +98,10 @@ extern void packet_list_set_font(FONT_TYPE *font);
|
|||
/** Set the selection mode of the packet list window.
|
||||
*
|
||||
* @param val TRUE for GTK_SELECTION_SINGLE, FALSE for GTK_SELECTION_BROWSE
|
||||
* @param force_set TRUE to force setting of the selection mode even if it
|
||||
* was already set (used within packet_list_recreate).
|
||||
*/
|
||||
extern void packet_list_set_sel_browse(gboolean val);
|
||||
extern void packet_list_set_sel_browse(gboolean val, gboolean force_set);
|
||||
|
||||
/** Move to the next packet
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue