aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/packet_history.c
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2004-11-01 11:42:08 +0000
committerUlf Lamping <ulf.lamping@web.de>2004-11-01 11:42:08 +0000
commita309bf0a8a74d7185bb155dd1d60e6592f0d4a84 (patch)
tree5b553d60815148cd2d479c22bdd0b762cb70150e /gtk/packet_history.c
parent8a7f77731ef70933936a75a27b65788a8a79d88d (diff)
first implementation of the packet history function
svn path=/trunk/; revision=12460
Diffstat (limited to 'gtk/packet_history.c')
-rw-r--r--gtk/packet_history.c182
1 files changed, 182 insertions, 0 deletions
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();
+}
+