/* packet_list.c
* packet list related functions 2002 Olivier Abad
*
- * $Id: packet_list.c,v 1.20 2004/06/05 10:27:38 ulfl Exp $
+ * $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
#include "gtkglobals.h"
#include "epan/epan.h"
#include "color.h"
+#include "color_filters.h"
#include "../ui_util.h"
-#include "ui_util.h"
+#include "gui_utils.h"
#include "main.h"
#include "menu.h"
-#include "color_utils.h"
-#include "column.h"
+#include "colors.h"
+#include <epan/column.h>
#include "epan/column_info.h"
#include "compat_macros.h"
-#include "../prefs.h"
-#include "file_dlg.h"
+#include <epan/prefs.h>
+#include "capture_file_dlg.h"
#include "packet_list.h"
#include "keys.h"
+#include "font_utils.h"
+#include "packet_history.h"
+
#include <epan/timestamp.h>
#include "image/clist_ascend.xpm"
#include "image/clist_descend.xpm"
+#include "progress_dlg.h"
+
+#define N_PROGBAR_UPDATES 100
+
+
/*
* XXX - gross hack.
* This lets us use GtkCList in GTK+ 1.3[.x] and later, and EthCList on
a lower time stamp than any frame with a non-reference time;
if both packets' times are reference times, we compare the
times of the packets. */
-#define COMPARE_TS(secs, usecs) \
+#define COMPARE_TS(ts) \
((fdata1->flags.ref_time && !fdata2->flags.ref_time) ? -1 : \
(!fdata1->flags.ref_time && fdata2->flags.ref_time) ? 1 : \
- (fdata1->secs < fdata2->secs) ? -1 : \
- (fdata1->secs > fdata2->secs) ? 1 : \
- (fdata1->usecs < fdata2->usecs) ? -1 :\
- (fdata1->usecs > fdata2->usecs) ? 1 : \
+ (fdata1->ts.secs < fdata2->ts.secs) ? -1 : \
+ (fdata1->ts.secs > fdata2->ts.secs) ? 1 : \
+ (fdata1->ts.nsecs < fdata2->ts.nsecs) ? -1 :\
+ (fdata1->ts.nsecs > fdata2->ts.nsecs) ? 1 : \
COMPARE_FRAME_NUM())
static gint
packet_list_compare(EthCList *clist, gconstpointer ptr1, gconstpointer ptr2)
return COMPARE_FRAME_NUM();
case COL_CLS_TIME:
- switch (get_timestamp_setting()) {
+ switch (timestamp_get_type()) {
case TS_ABSOLUTE:
case TS_ABSOLUTE_WITH_DATE:
- return COMPARE_TS(abs_secs, abs_usecs);
+ case TS_EPOCH:
+ return COMPARE_TS(abs_ts);
case TS_RELATIVE:
- return COMPARE_TS(rel_secs, rel_usecs);
+ return COMPARE_TS(rel_ts);
case TS_DELTA:
- return COMPARE_TS(del_secs, del_usecs);
+ return COMPARE_TS(del_ts);
+
+ case TS_NOT_SET:
+ return 0;
}
return 0;
case COL_ABS_TIME:
- return COMPARE_TS(abs_secs, abs_usecs);
+ case COL_ABS_DATE_TIME:
+ return COMPARE_TS(abs_ts);
case COL_REL_TIME:
- return COMPARE_TS(rel_secs, rel_usecs);
+ return COMPARE_TS(rel_ts);
case COL_DELTA_TIME:
- return COMPARE_TS(del_secs, del_usecs);
+ return COMPARE_TS(del_ts);
case COL_PACKET_LENGTH:
return COMPARE_NUM(pkt_len);
while( (gtk_notebook_get_nth_page( GTK_NOTEBOOK(byte_nb_ptr), 0)))
gtk_notebook_remove_page( GTK_NOTEBOOK(byte_nb_ptr), 0);
- select_packet(&cfile, row);
+ cf_select_packet(&cfile, row);
gtk_widget_grab_focus(packet_list);
+ packet_history_add(row);
}
static void
packet_list_unselect_cb(GtkWidget *w _U_, gint row _U_, gint col _U_, gpointer evt _U_) {
- unselect_packet(&cfile);
+ cf_unselect_packet(&cfile);
}
/* mark packets */
if (row == -1)
return;
if (set) {
- mark_frame(&cfile, frame);
+ cf_mark_frame(&cfile, frame);
color_t_to_gdkcolor(&fg, &prefs.gui_marked_fg);
color_t_to_gdkcolor(&bg, &prefs.gui_marked_bg);
eth_clist_set_foreground(ETH_CLIST(packet_list), row, &fg);
} else {
color_filter_t *cfilter = frame->color_filter;
- unmark_frame(&cfile, frame);
+ cf_unmark_frame(&cfile, frame);
/* Restore the color from the matching color filter if any */
if (cfilter) { /* The packet matches a color filter */
color_t_to_gdkcolor(&fg, &cfilter->fg_color);
}
/* call this after last set_frame_mark is done */
-void mark_frames_ready(void) {
- file_set_save_marked_sensitive();
+static void mark_frames_ready(void) {
+ file_save_update_dynamics();
packets_bar_update();
}
-void mark_frame_cb(GtkWidget *w _U_, gpointer data _U_) {
+void packet_list_mark_frame_cb(GtkWidget *w _U_, gpointer data _U_) {
if (cfile.current_frame) {
/* XXX hum, should better have a "cfile->current_row" here ... */
set_frame_mark(!cfile.current_frame->flags.marked,
static void mark_all_frames(gboolean set) {
frame_data *fdata;
-
+
/* XXX: we might need a progressbar here */
- cfile.marked_count = 0;
for (fdata = cfile.plist; fdata != NULL; fdata = fdata->next) {
set_frame_mark(set,
fdata,
mark_frames_ready();
}
-void update_marked_frames(void) {
+void packet_list_update_marked_frames(void) {
frame_data *fdata;
if (cfile.plist == NULL) return;
mark_frames_ready();
}
-void mark_all_frames_cb(GtkWidget *w _U_, gpointer data _U_) {
+void packet_list_mark_all_frames_cb(GtkWidget *w _U_, gpointer data _U_) {
mark_all_frames(TRUE);
}
-void unmark_all_frames_cb(GtkWidget *w _U_, gpointer data _U_) {
+void packet_list_unmark_all_frames_cb(GtkWidget *w _U_, gpointer data _U_) {
mark_all_frames(FALSE);
}
packet_list_get_event_row_column(GtkWidget *w, GdkEventButton *event_button,
gint *row, gint *column)
{
- return eth_clist_get_selection_info(ETH_CLIST(w),
- (gint) event_button->x, (gint) event_button->y,
+ return eth_clist_get_selection_info(ETH_CLIST(w),
+ (gint) event_button->x, (gint) event_button->y,
row, column);
}
/* Set the selection mode of the packet list window. */
void
-set_plist_sel_browse(gboolean val)
+packet_list_set_sel_browse(gboolean val)
{
GtkSelectionMode new_mode;
/* initialize with a mode we don't use, so that the mode == new_mode
static GtkSelectionMode mode = GTK_SELECTION_MULTIPLE;
/* Yeah, GTK uses "browse" in the case where we do not, but oh well. I
- * think "browse" in Ethereal makes more sense than "SINGLE" in GTK+ */
+ * 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 (cfile.finfo_selected)
- unselect_packet(&cfile);
+ cf_unselect_packet(&cfile);
mode = new_mode;
eth_clist_set_selection_mode(ETH_CLIST(packet_list), mode);
}
/* Set the font of the packet list window. */
-#if GTK_MAJOR_VERSION < 2
void
-set_plist_font(GdkFont *font)
-#else
-void
-set_plist_font(PangoFontDescription *font)
-#endif
+packet_list_set_font(FONT_TYPE *font)
{
int i;
gint col_width;
/* Packet list */
pkt_scrollw = scrolled_window_new(NULL, NULL);
+ /* The usual policy for scrolled windows is to set both scrollbars to automatic,
+ * meaning they'll only appear if the content doesn't fit into the window.
+ *
+ * As this doesn't seem to work in some cases for the vertical scrollbar
+ * (see http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=220),
+ * we show that scrollbar always. */
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(pkt_scrollw),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
#if GTK_MAJOR_VERSION >= 2
- /* the eth_clist will have it's own GTK_SHADOW_IN, so don't use a shadow
+ /* the eth_clist will have it's own GTK_SHADOW_IN, so don't use a shadow
* for both widgets */
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(pkt_scrollw),
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(pkt_scrollw),
GTK_SHADOW_NONE);
#endif
/* Column titles are filled in below */
gtk_container_add(GTK_CONTAINER(pkt_scrollw), packet_list);
- set_plist_sel_browse(prefs->gui_plist_sel_browse);
- set_plist_font(m_r_font);
+ packet_list_set_sel_browse(prefs->gui_plist_sel_browse);
+ 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);
SIGNAL_CONNECT(packet_list, "unselect-row", packet_list_unselect_cb, NULL);
for (i = 0; i < cfile.cinfo.num_cols; i++) {
- /* Columns do not automatically resize, but are resizeable by
- the user. */
+ /* For performance reasons, columns do not automatically resize,
+ but are resizeable by the user. */
eth_clist_set_column_auto_resize(ETH_CLIST(packet_list), i, FALSE);
eth_clist_set_column_resizeable(ETH_CLIST(packet_list), i, TRUE);
- /* Right-justify the packet number column. */
- if (cfile.cinfo.col_fmt[i] == COL_NUMBER)
+ /* Right-justify some special columns. */
+ if (cfile.cinfo.col_fmt[i] == COL_NUMBER ||
+ cfile.cinfo.col_fmt[i] == COL_PACKET_LENGTH ||
+ cfile.cinfo.col_fmt[i] == COL_CUMULATIVE_BYTES ||
+ cfile.cinfo.col_fmt[i] == COL_DCE_CALL ||
+ cfile.cinfo.col_fmt[i] == COL_DCE_CTX)
eth_clist_set_column_justification(ETH_CLIST(packet_list), i,
GTK_JUSTIFY_RIGHT);
}
win_style = gtk_widget_get_style(top_level);
ascend_pm = gdk_pixmap_create_from_xpm_d(top_level->window, &ascend_bm,
&win_style->bg[GTK_STATE_NORMAL],
- (gchar **)clist_ascend_xpm);
+ (gchar **) clist_ascend_xpm);
descend_pm = gdk_pixmap_create_from_xpm_d(top_level->window, &descend_bm,
&win_style->bg[GTK_STATE_NORMAL],
- (gchar **)clist_descend_xpm);
+ (gchar **) clist_descend_xpm);
col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) *
cfile.cinfo.num_cols);
void
packet_list_clear(void)
{
+ packet_history_clear();
+
eth_clist_clear(ETH_CLIST(packet_list));
}
eth_clist_freeze(ETH_CLIST(packet_list));
}
+static void
+packet_list_resize_columns(void) {
+ int i;
+ int progbar_nextstep;
+ int progbar_quantum;
+ gboolean progbar_stop_flag;
+ GTimeVal progbar_start_time;
+ float progbar_val;
+ progdlg_t *progbar = NULL;
+ gchar status_str[100];
+
+ /* Update the progress bar when it gets to this value. */
+ progbar_nextstep = 0;
+ /* When we reach the value that triggers a progress bar update,
+ bump that value by this amount. */
+ progbar_quantum = cfile.cinfo.num_cols/N_PROGBAR_UPDATES;
+ /* Progress so far. */
+ progbar_val = 0.0;
+
+ progbar_stop_flag = FALSE;
+ g_get_current_time(&progbar_start_time);
+
+
+ main_window_update();
+
+ for (i = 0; i < cfile.cinfo.num_cols; i++) {
+ /* Create the progress bar if necessary.
+ We check on every iteration of the loop, so that it takes no
+ longer than the standard time to create it (otherwise, for a
+ large file, we might take considerably longer than that standard
+ time in order to get to the next progress bar step). */
+ if (progbar == NULL)
+ progbar = delayed_create_progress_dlg("Resizing", "Resize Columns",
+ TRUE, &progbar_stop_flag, &progbar_start_time, progbar_val);
+
+ if (i >= progbar_nextstep) {
+ /* let's not divide by zero. I should never be started
+ * with count == 0, so let's assert that
+ */
+ g_assert(cfile.cinfo.num_cols > 0);
+
+ progbar_val = (gfloat) i / cfile.cinfo.num_cols;
+
+ if (progbar != NULL) {
+ g_snprintf(status_str, sizeof(status_str),
+ "%u of %u columns (%s)", i+1, cfile.cinfo.num_cols, cfile.cinfo.col_title[i]);
+ update_progress_dlg(progbar, progbar_val, status_str);
+ }
+
+ progbar_nextstep += progbar_quantum;
+ }
+
+ if (progbar_stop_flag) {
+ /* Well, the user decided to abort the resizing... */
+ break;
+ }
+
+ /* auto resize the current column */
+ eth_clist_set_column_auto_resize(ETH_CLIST(packet_list), i, TRUE);
+
+ /* the current column should be resizeable by the user again */
+ /* (will turn off auto resize again) */
+ eth_clist_set_column_resizeable(ETH_CLIST(packet_list), i, TRUE);
+ }
+
+ /* We're done resizing the columns; destroy the progress bar if it
+ was created. */
+ if (progbar != NULL)
+ destroy_progress_dlg(progbar);
+}
+
+void packet_list_resize_columns_cb(GtkWidget *widget _U_, gpointer data _U_)
+{
+ packet_list_resize_columns();
+}
+
void
packet_list_thaw(void)
{
eth_clist_thaw(ETH_CLIST(packet_list));
packets_bar_update();
+ /*packet_list_resize_columns();*/
}
void
SIGNAL_EMIT_BY_NAME(packet_list, "select_row", row);
}
+static void
+packet_list_next_prev(gboolean next)
+{
+#if GTK_MAJOR_VERSION >= 2
+ GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(top_level));
+#endif
+ SIGNAL_EMIT_BY_NAME(packet_list, "scroll_vertical",
+ next ? GTK_SCROLL_STEP_FORWARD : GTK_SCROLL_STEP_BACKWARD, 0.0);
+#if GTK_MAJOR_VERSION >= 2
+ /* Set the focus back where it was */
+ if (focus)
+ gtk_window_set_focus(GTK_WINDOW(top_level), focus);
+#endif
+}
+
+void
+packet_list_next()
+{
+ packet_list_next_prev(TRUE);
+}
+
+void
+packet_list_prev()
+{
+ packet_list_next_prev(FALSE);
+}
+
void
packet_list_moveto_end(void)
{
}
gint
-packet_list_append(gchar *text[], gpointer data)
+packet_list_append(const gchar *text[], gpointer data)
{
gint row;
- row = eth_clist_append(ETH_CLIST(packet_list), text);
+ row = eth_clist_append(ETH_CLIST(packet_list), (gchar **) text);
eth_clist_set_row_data(ETH_CLIST(packet_list), row, data);
return row;
}
return eth_clist_get_row_data(ETH_CLIST(packet_list), row);
}
+
+/* get the first fully visible row number, given row MUST be visible */
+static gint
+packet_list_first_full_visible_row(gint row) {
+
+ g_assert(eth_clist_row_is_visible(ETH_CLIST(packet_list), row) ==
+ GTK_VISIBILITY_FULL);
+
+ while(eth_clist_row_is_visible(ETH_CLIST(packet_list), row) ==
+ GTK_VISIBILITY_FULL) {
+ row--;
+ }
+
+ return ++row;
+}
+
+/* get the last fully visible row number, given row MUST be visible */
+static gint
+packet_list_last_full_visible_row(gint row) {
+
+ g_assert(eth_clist_row_is_visible(ETH_CLIST(packet_list), row) ==
+ GTK_VISIBILITY_FULL);
+
+ while(eth_clist_row_is_visible(ETH_CLIST(packet_list), row) ==
+ GTK_VISIBILITY_FULL) {
+ row++;
+ }
+
+ return --row;
+}
+
/* Set the selected row and the focus row of the packet list to the specified
* row, and make it visible if it's not currently visible. */
void
packet_list_set_selected_row(gint row)
{
- if (eth_clist_row_is_visible(ETH_CLIST(packet_list), row) !=
- GTK_VISIBILITY_FULL)
- eth_clist_moveto(ETH_CLIST(packet_list), row, -1, 0.0, 0.0);
+ gint visible_rows;
+ gint first_row;
+ gboolean full_visible;
+
+
+ full_visible = eth_clist_row_is_visible(ETH_CLIST(packet_list), row) ==
+ GTK_VISIBILITY_FULL;
/* XXX - why is there no "eth_clist_set_focus_row()", so that we
* can make the row for the frame we found the focus row?
ETH_CLIST(packet_list)->focus_row = row;
eth_clist_select_row(ETH_CLIST(packet_list), row, -1);
+
+ if (!full_visible) {
+
+ eth_clist_freeze(ETH_CLIST(packet_list));
+
+ eth_clist_moveto(ETH_CLIST(packet_list), row, -1, 0.0, 0.0);
+
+ /* even after move still invisible (happens with empty list) -> give up */
+ if(eth_clist_row_is_visible(ETH_CLIST(packet_list), row) !=
+ GTK_VISIBILITY_FULL) {
+ eth_clist_thaw(ETH_CLIST(packet_list));
+ return;
+ }
+
+ /* The now selected row will be the first visible row in the list.
+ * This is inconvenient, as the user is usually interested in some
+ * packets *before* the currently selected one too.
+ *
+ * Try to adjust the visible rows, so the currently selected row will
+ * be shown around the first third of the list screen.
+ *
+ * (This won't even do any harm if the current row is the first or the
+ * last in the list) */
+ visible_rows = packet_list_last_full_visible_row(row) - packet_list_first_full_visible_row(row);
+ first_row = row - visible_rows / 3;
+
+ eth_clist_moveto(ETH_CLIST(packet_list), first_row >= 0 ? first_row : 0, -1, 0.0, 0.0);
+
+ eth_clist_thaw(ETH_CLIST(packet_list));
+ }
}
/* Return the column number that the clist is currently sorted by */