Have the frame_tvbuff.c routines not use the global cfile.
[metze/wireshark/wip.git] / ui / gtk / packet_history.c
1 /* packet_history.c
2  * packet history related functions   2004 Ulf Lamping
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <gtk/gtk.h>
26
27 #include "ui/gtk/main.h"
28 #include "ui/gtk/packet_history.h"
29
30 #include "globals.h"
31
32 static GList *history_current = NULL;
33 static GList *history_list = NULL;
34 static gboolean ignore_jump = FALSE;
35
36
37 #if 0
38 /* print the complete packet history to console */
39 static void history_print(void) {
40     GList *current = g_list_first(history_list);
41
42     printf(" List:\n");
43
44     while(current) {
45         if(current == history_current) {
46             printf(" Row: %u *\n", GPOINTER_TO_INT(current->data));
47         } else {
48             printf(" Row: %u\n", GPOINTER_TO_INT(current->data));
49         }
50         current = g_list_next(current);
51     }
52 }
53 #endif
54
55
56 /* adjust menu and toolbar sensitivity depending on the history entries */
57 static void adjust_menus(void) {
58
59     if(history_current) {
60         main_set_for_packet_history(
61             (g_list_previous(history_current) != NULL),
62             (g_list_next(history_current) != NULL));
63     } else {
64         /* we don't have any history */
65         main_set_for_packet_history(FALSE, FALSE);
66     }
67
68     /* history_print(); */
69 }
70
71
72 /* clear the history list from the given entry to the end of the list */
73 static void clear_list(GList *current) {
74     GList *next_packet;
75
76
77     while(current) {
78         next_packet = g_list_next(current);
79         history_list = g_list_remove(history_list, current->data);
80         current = next_packet;
81     }
82 }
83
84
85 /* add an entry to the history list */
86 void packet_history_add(gint row) {
87
88     if(row < 1) {
89         /* Not a valid row number */
90         return;
91     }
92
93     if(ignore_jump) {
94         /* we jumping back and forward in history, so don't change list */
95         return;
96     }
97
98     if (history_current) {
99         /* clear list behind current position */
100         clear_list(g_list_next(history_current));
101
102         /* ignore duplicates */
103         if(GPOINTER_TO_INT(history_current->data) == row) {
104             adjust_menus();
105             return;
106         }
107     }
108
109     /* add row */
110     history_list = g_list_append(history_list, GINT_TO_POINTER(row));
111     history_current = g_list_last(history_list);
112
113     adjust_menus();
114 }
115
116
117 void packet_history_clear(void) {
118
119     /* clear "old" list */
120     clear_list(history_list);
121     history_current = NULL;
122
123     /* add the currently selected first row */
124     packet_history_add(0);
125
126     adjust_menus();
127 }
128
129
130 static void packet_history_back(void) {
131     GList *previous;
132
133     if(history_current) {
134         previous = g_list_previous(history_current);
135
136         /* do we have a previous entry */
137         if(previous) {
138             history_current = previous;
139
140             /* goto that packet but don't change history */
141             ignore_jump = TRUE;
142             cf_goto_frame(&cfile, GPOINTER_TO_INT(previous->data));
143             ignore_jump = FALSE;
144         }
145     }
146
147     adjust_menus();
148 }
149
150
151 static void packet_history_forward(void) {
152     GList *next;
153
154     if(history_current) {
155         next = g_list_next(history_current);
156
157         /* do we have a forward entry? */
158         if(next) {
159             history_current = next;
160
161             /* goto that packet but don't change history */
162             ignore_jump = TRUE;
163             cf_goto_frame(&cfile, GPOINTER_TO_INT(next->data));
164             ignore_jump = FALSE;
165         }
166     }
167
168     adjust_menus();
169 }
170
171
172 void history_forward_cb(GtkWidget *widget _U_, gpointer data _U_) {
173     packet_history_forward();
174 }
175
176
177 void history_back_cb(GtkWidget *widget _U_, gpointer data _U_) {
178     packet_history_back();
179 }
180
181
182 /*
183  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
184  *
185  * Local variables:
186  * c-basic-offset: 4
187  * tab-width: 8
188  * indent-tabs-mode: nil
189  * End:
190  *
191  * vi: set shiftwidth=4 tabstop=8 expandtab:
192  * :indentSize=4:tabSize=8:noTabs=true:
193  */