aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk/packet_history.c
diff options
context:
space:
mode:
authorJörg Mayer <jmayer@loplof.de>2012-01-15 21:59:11 +0000
committerJörg Mayer <jmayer@loplof.de>2012-01-15 21:59:11 +0000
commitbe706c63801fb98d42fb743b27b16cc36273651e (patch)
tree62ed0b552191eb0753d26a3edcbab73459a15f7f /ui/gtk/packet_history.c
parent6d69ef093cd6868ab51f8b52477a510172033353 (diff)
Move gtk to ui/gtk.
This looses the last checkin to gtk, will add this manually back. svn path=/trunk/; revision=40518
Diffstat (limited to 'ui/gtk/packet_history.c')
-rw-r--r--ui/gtk/packet_history.c188
1 files changed, 188 insertions, 0 deletions
diff --git a/ui/gtk/packet_history.c b/ui/gtk/packet_history.c
new file mode 100644
index 0000000000..5951da3b02
--- /dev/null
+++ b/ui/gtk/packet_history.c
@@ -0,0 +1,188 @@
+/* packet_history.c
+ * packet history related functions 2004 Ulf Lamping
+ *
+ * $Id$
+ *
+ * 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
+ * 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 <stdio.h>
+
+#include <gtk/gtk.h>
+
+#include "../file.h"
+#include "../globals.h"
+
+#include "ui/gtk/menus.h"
+#include "ui/gtk/packet_history.h"
+
+
+static GList *history_current = NULL;
+static GList *history_list = NULL;
+static 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(
+ (g_list_previous(history_current) != NULL),
+ (g_list_next(history_current) != NULL));
+ } 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(row < 1) {
+ /* Not a valid row number */
+ return;
+ }
+
+ 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(history_list);
+ history_current = NULL;
+
+ /* add the currently selected first row */
+ packet_history_add(0);
+
+ adjust_menus();
+}
+
+
+static 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;
+ cf_goto_frame(&cfile, GPOINTER_TO_INT(previous->data));
+ ignore_jump = FALSE;
+ }
+ }
+
+ adjust_menus();
+}
+
+
+static 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;
+ cf_goto_frame(&cfile, GPOINTER_TO_INT(next->data));
+ 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();
+}
+