aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/packet_history.c
blob: 4a3370028c2722e1613622f22b0a17b601c2bfaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* 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(
            (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(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) +1);
            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) +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();
}