diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2004-11-01 11:42:08 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2004-11-01 11:42:08 +0000 |
commit | a309bf0a8a74d7185bb155dd1d60e6592f0d4a84 (patch) | |
tree | 5b553d60815148cd2d479c22bdd0b762cb70150e /gtk | |
parent | 8a7f77731ef70933936a75a27b65788a8a79d88d (diff) |
first implementation of the packet history function
svn path=/trunk/; revision=12460
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/Makefile.am | 1 | ||||
-rw-r--r-- | gtk/Makefile.common | 1 | ||||
-rw-r--r-- | gtk/menu.c | 22 | ||||
-rw-r--r-- | gtk/menu.h | 7 | ||||
-rw-r--r-- | gtk/packet_history.c | 182 | ||||
-rw-r--r-- | gtk/packet_history.h | 35 | ||||
-rw-r--r-- | gtk/packet_list.c | 4 | ||||
-rw-r--r-- | gtk/toolbar.c | 26 | ||||
-rw-r--r-- | gtk/toolbar.h | 7 |
9 files changed, 271 insertions, 14 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index f99f2793e8..b0d2017a62 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -69,6 +69,7 @@ noinst_HEADERS = \ menu.h \ mtp3_stat.h \ nameres_prefs.h \ + packet_history.h \ packet_list.h \ packet_win.h \ prefs_dlg.h \ diff --git a/gtk/Makefile.common b/gtk/Makefile.common index 379e3f4273..f651bce996 100644 --- a/gtk/Makefile.common +++ b/gtk/Makefile.common @@ -61,6 +61,7 @@ ETHEREAL_GTK_SRC = \ main.c \ menu.c \ nameres_prefs.c \ + packet_history.c \ packet_list.c \ packet_win.c \ plugins_dlg.c \ diff --git a/gtk/menu.c b/gtk/menu.c index eae4b3f487..d8aa0a9e02 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -74,6 +74,7 @@ #include "conversations_table.h" #include "hostlist_table.h" #include "simple_dialog.h" +#include "packet_history.h" GtkWidget *popup_menu_object; @@ -207,10 +208,8 @@ static GtkItemFactoryEntry menu_items[] = #endif ITEM_FACTORY_STOCK_ENTRY("/Edit/_Find Packet...", "<control>F", find_frame_cb, 0, GTK_STOCK_FIND), - ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Ne_xt", "<control>N", find_next_cb, - 0, GTK_STOCK_GO_FORWARD), - ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Pre_vious", "<control>B", - find_previous_cb, 0, GTK_STOCK_GO_BACK), + ITEM_FACTORY_ENTRY("/Edit/Find Ne_xt", "<control>N", find_next_cb, 0, NULL, NULL), + ITEM_FACTORY_ENTRY("/Edit/Find Pre_vious", "<control>B", find_previous_cb, 0, NULL, NULL), ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL), ITEM_FACTORY_ENTRY("/Edit/_Time Reference", NULL, NULL, 0, "<Branch>", NULL), ITEM_FACTORY_ENTRY("/Edit/Time Reference/Set Time Reference (toggle)", "<control>T", reftime_frame_cb, REFTIME_TOGGLE, NULL, NULL), @@ -274,12 +273,16 @@ static GtkItemFactoryEntry menu_items[] = ITEM_FACTORY_STOCK_ENTRY("/View/_Reload", "<control>R", file_reload_cmd_cb, 0, GTK_STOCK_REFRESH), ITEM_FACTORY_ENTRY("/_Go", NULL, NULL, 0, "<Branch>", NULL), + ITEM_FACTORY_STOCK_ENTRY("/Go/_Back", "<alt>Left", + history_back_cb, 0, GTK_STOCK_GO_BACK), + ITEM_FACTORY_STOCK_ENTRY("/Go/_Forward", "<alt>Right", + history_forward_cb, 0, GTK_STOCK_GO_FORWARD), ITEM_FACTORY_STOCK_ENTRY("/Go/_Go to Packet...", "<control>G", goto_frame_cb, 0, GTK_STOCK_JUMP_TO), ITEM_FACTORY_ENTRY("/Go/Go to _Corresponding Packet", NULL, goto_framenum_cb, 0, NULL, NULL), ITEM_FACTORY_ENTRY("/Go/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/Go/_First Packet", NULL, + ITEM_FACTORY_STOCK_ENTRY("/Go/F_irst Packet", NULL, goto_top_frame_cb, 0, GTK_STOCK_GOTO_TOP), ITEM_FACTORY_STOCK_ENTRY("/Go/_Last Packet", NULL, goto_bottom_frame_cb, 0, GTK_STOCK_GOTO_BOTTOM), @@ -1848,3 +1851,12 @@ set_menus_for_selected_tree_row(capture_file *cf) walk_menu_tree_for_selected_tree_row(tap_menu_tree_root, cf->finfo_selected); } + +void set_menus_for_packet_history(gboolean back_history, gboolean forward_history) { + + set_menu_sensitivity(main_menu_factory, "/Go/Back", back_history); + set_menu_sensitivity(main_menu_factory, "/Go/Forward", forward_history); + + set_toolbar_for_packet_history(back_history, forward_history); +} + diff --git a/gtk/menu.h b/gtk/menu.h index e79637c322..c02acfb568 100644 --- a/gtk/menu.h +++ b/gtk/menu.h @@ -74,6 +74,13 @@ extern void set_menu_object_data(gchar *path, gchar *key, gpointer data); */ extern gint popup_menu_handler(GtkWidget *widget, GdkEvent *event, gpointer data); +/** The packet history has changed, we need to update the menu. + * + * @param back_history some back history entries available + * @param forward_history some forward history entries available + */ +extern void set_menus_for_packet_history(gboolean back_history, gboolean forward_history); + /** The popup menu. */ extern GtkWidget *popup_menu_object; diff --git a/gtk/packet_history.c b/gtk/packet_history.c new file mode 100644 index 0000000000..77adc36533 --- /dev/null +++ b/gtk/packet_history.c @@ -0,0 +1,182 @@ +/* packet_history.c + * packet history related functions 2004 Ulf Lamping + * + * $Id$ + * + * 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 <gtk/gtk.h> + +#include <stdio.h> + +#include "file.h" +#include "globals.h" + +#include "menu.h" +#include "packet_history.h" + + +GList *history_current = NULL; +GList *history_list = NULL; +gboolean ignore_jump = FALSE; + + +#if 0 +/* print the complete packet history to console */ +static void history_print(void) { + GList *current = g_list_first(history_list); + + printf(" List:\n"); + + while(current) { + if(current == history_current) { + printf(" Row: %u *\n", GPOINTER_TO_INT(current->data)); + } else { + printf(" Row: %u\n", GPOINTER_TO_INT(current->data)); + } + current = g_list_next(current); + } +} +#endif + + +/* adjust menu and toolbar sensitivity depending on the history entries */ +static void adjust_menus(void) { + + if(history_current) { + set_menus_for_packet_history( + (gboolean) g_list_previous(history_current), + (gboolean) g_list_next(history_current)); + } else { + /* we don't have any history */ + set_menus_for_packet_history(FALSE, FALSE); + } + + /* history_print(); */ +} + + +/* clear the history list from the given entry to the end of the list */ +static void clear_list(GList *current) { + GList *next_packet; + + + while(current) { + next_packet = g_list_next(current); + history_list = g_list_remove(history_list, current->data); + current = next_packet; + } +} + + +/* add an entry to the history list */ +void packet_history_add(gint row) { + + if(ignore_jump) { + /* we jumping back and forward in history, so don't change list */ + return; + } + + if (history_current) { + /* clear list behind current position */ + clear_list(g_list_next(history_current)); + + /* ignore duplicates */ + if(GPOINTER_TO_INT(history_current->data) == row) { + adjust_menus(); + return; + } + } + + /* add row */ + history_list = g_list_append(history_list, GINT_TO_POINTER(row)); + history_current = g_list_last(history_list); + + adjust_menus(); +} + + +void packet_history_clear(void) { + + /* clear "old" list */ + clear_list(g_list_first(history_current)); + + /* add the currently selected first row */ + packet_history_add(0); + + adjust_menus(); +} + + +void packet_history_back(void) { + GList *previous; + + if(history_current) { + previous = g_list_previous(history_current); + + /* do we have a previous entry */ + if(previous) { + history_current = previous; + + /* goto that packet but don't change history */ + ignore_jump = TRUE; + goto_frame(&cfile, GPOINTER_TO_INT(previous->data) +1); + ignore_jump = FALSE; + } + } + + adjust_menus(); +} + + +void packet_history_forward(void) { + GList *next; + + if(history_current) { + next = g_list_next(history_current); + + /* do we have a forward entry? */ + if(next) { + history_current = next; + + /* goto that packet but don't change history */ + ignore_jump = TRUE; + goto_frame(&cfile, GPOINTER_TO_INT(next->data) +1); + ignore_jump = FALSE; + } + } + + adjust_menus(); +} + + +void history_forward_cb(GtkWidget *widget _U_, gpointer data _U_) { + packet_history_forward(); +} + + +void history_back_cb(GtkWidget *widget _U_, gpointer data _U_) { + packet_history_back(); +} + diff --git a/gtk/packet_history.h b/gtk/packet_history.h new file mode 100644 index 0000000000..9957ce976f --- /dev/null +++ b/gtk/packet_history.h @@ -0,0 +1,35 @@ +/* packet_history.h + * packet history related functions 2004 Ulf Lamping + * + * $Id$ + * + * 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. + */ + + + +extern void packet_history_add(gint row); + +extern void packet_history_clear(void); + +extern void history_forward_cb(GtkWidget *widget, gpointer data); + +extern void history_back_cb(GtkWidget *widget, gpointer data); + + diff --git a/gtk/packet_list.c b/gtk/packet_list.c index 5a20fca0a8..b79f6ceaab 100644 --- a/gtk/packet_list.c +++ b/gtk/packet_list.c @@ -47,6 +47,7 @@ #include "packet_list.h" #include "keys.h" #include "font_utils.h" +#include "packet_history.h" #include <epan/timestamp.h> @@ -263,6 +264,7 @@ packet_list_select_cb(GtkWidget *w _U_, gint row, gint col _U_, gpointer evt _U_ select_packet(&cfile, row); gtk_widget_grab_focus(packet_list); + packet_history_add(row); } static void @@ -576,6 +578,8 @@ packet_list_set_column_titles(void) void packet_list_clear(void) { + packet_history_clear(); + eth_clist_clear(ETH_CLIST(packet_list)); } diff --git a/gtk/toolbar.c b/gtk/toolbar.c index 31625aa43f..2ebe954f79 100644 --- a/gtk/toolbar.c +++ b/gtk/toolbar.c @@ -61,6 +61,7 @@ #include "keys.h" #include "compat_macros.h" #include "recent.h" +#include "packet_history.h" /* All of the icons used here are coming (or are derived) from GTK2 stock icons. * They were converted using "The Gimp" with standard conversion from png to xpm. @@ -120,7 +121,7 @@ static GtkWidget *new_button, *stop_button; static GtkWidget *capture_filter_button; #endif /* HAVE_LIBPCAP */ static GtkWidget *open_button, *save_button, *save_as_button, *close_button, *reload_button; -static GtkWidget *print_button, *find_button, *find_next_button, *find_prev_button; +static GtkWidget *print_button, *find_button, *history_forward_button, *history_back_button; static GtkWidget *go_to_button, *go_to_top_button, *go_to_bottom_button; static GtkWidget *display_filter_button; static GtkWidget *zoom_in_button, *zoom_out_button, *zoom_100_button; @@ -253,6 +254,17 @@ void set_toolbar_for_unsaved_capture_file(gboolean have_unsaved_capture_file) { } +/** The packet history has changed, we need to update the menu. + * + * @param back_history some back history entries available + * @param forward_history some forward history entries available + */ +void set_toolbar_for_packet_history(gboolean back_history, gboolean forward_history) { + gtk_widget_set_sensitive(history_back_button, back_history); + gtk_widget_set_sensitive(history_forward_button, forward_history); +} + + /* XXX - this is a quick and dirty hack to get the current state of capturing. * this has to be improved, and should be reside somewhere in the capture engine. */ gboolean g_is_capture_in_progress = FALSE; @@ -289,8 +301,6 @@ void set_toolbar_for_captured_packets(gboolean have_captured_packets) { if (toolbar_init) { gtk_widget_set_sensitive(print_button, have_captured_packets); gtk_widget_set_sensitive(find_button, have_captured_packets); - gtk_widget_set_sensitive(find_next_button, have_captured_packets); - gtk_widget_set_sensitive(find_prev_button, have_captured_packets); gtk_widget_set_sensitive(go_to_button, have_captured_packets); gtk_widget_set_sensitive(go_to_top_button, have_captured_packets); gtk_widget_set_sensitive(go_to_bottom_button, have_captured_packets); @@ -407,12 +417,10 @@ toolbar_new(void) toolbar_item(find_button, window, main_tb, GTK_STOCK_FIND, "Find a packet...", stock_search_24_xpm, find_frame_cb); - toolbar_item(find_prev_button, window, main_tb, - GTK_STOCK_GO_BACK, "Find the previous matching packet", stock_left_arrow_24_xpm, find_previous_cb); - toolbar_item(find_next_button, window, main_tb, - GTK_STOCK_GO_FORWARD, "Find the next matching packet", stock_right_arrow_24_xpm, find_next_cb); - toolbar_append_separator(main_tb); - + toolbar_item(history_back_button, window, main_tb, + GTK_STOCK_GO_BACK, "Go back in packet history", stock_left_arrow_24_xpm, history_back_cb); + toolbar_item(history_forward_button, window, main_tb, + GTK_STOCK_GO_FORWARD, "Go forward in packet history", stock_right_arrow_24_xpm, history_forward_cb); toolbar_item(go_to_button, window, main_tb, GTK_STOCK_JUMP_TO, "Go to the packet with number...", stock_jump_to_24_xpm, goto_frame_cb); toolbar_item(go_to_top_button, window, main_tb, diff --git a/gtk/toolbar.h b/gtk/toolbar.h index ad01fe4ab2..5b9bb362cd 100644 --- a/gtk/toolbar.h +++ b/gtk/toolbar.h @@ -63,6 +63,13 @@ void set_toolbar_for_capture_in_progress(gboolean have_capture_file); */ void set_toolbar_for_captured_packets(gboolean have_captured_packets); +/** The packet history has changed, we need to update the menu. + * + * @param back_history some back history entries available + * @param forward_history some forward history entries available + */ +void set_toolbar_for_packet_history(gboolean back_history, gboolean forward_history); + /** Set object data of some buttons (where needed). It's needed so callback * functions can read back their required data. Acts like OBJECT_SET_DATA() * on multiple buttons. |