aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/filter_utils.c
blob: 18bf1617438dc8c15fa8566a3251d4e6c6c3e9af (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
/* filter_utils.c
 *
 * $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 <gtk/gtk.h>
#include <string.h>

#include "../globals.h"

#include "gtk/main.h"
#include "gtk/gtkglobals.h"
#include "gtk/find_dlg.h"
#include "gtk/color_dlg.h"
#include "gtk/filter_utils.h"

void
apply_selected_filter (guint callback_action, char *filter)
{
 	int action, type;
	char *str = NULL;
	const char *current_filter;

	action = FILTER_ACTION(callback_action);
	type = FILTER_ACTYPE(callback_action);

	current_filter = gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));

	switch(type){
	case ACTYPE_SELECTED:
		str = g_strdup_printf("%s", filter);
		break;
	case ACTYPE_NOT_SELECTED:
		str = g_strdup_printf("!(%s)", filter);
		break;
	case ACTYPE_AND_SELECTED:
		if ((!current_filter) || (0 == strlen(current_filter)))
			str = g_strdup_printf("%s", filter);
		else
			str = g_strdup_printf("(%s) && (%s)", current_filter, filter);
		break;
	case ACTYPE_OR_SELECTED:
		if ((!current_filter) || (0 == strlen(current_filter)))
			str = g_strdup_printf("%s", filter);
		else
			str = g_strdup_printf("(%s) || (%s)", current_filter, filter);
		break;
	case ACTYPE_AND_NOT_SELECTED:
		if ((!current_filter) || (0 == strlen(current_filter)))
			str = g_strdup_printf("!(%s)", filter);
		else
			str = g_strdup_printf("(%s) && !(%s)", current_filter, filter);
		break;
	case ACTYPE_OR_NOT_SELECTED:
		if ((!current_filter) || (0 == strlen(current_filter)))
			str = g_strdup_printf("!(%s)", filter);
		else
			str = g_strdup_printf("(%s) || !(%s)", current_filter, filter);
		break;
	}

	switch(action){
	case ACTION_MATCH:
		gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
		main_filter_packets(&cfile, str, FALSE);
		gdk_window_raise(top_level->window);
		break;
	case ACTION_PREPARE:
		gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
		break;
	case ACTION_FIND_FRAME:
		find_frame_with_filter(str);
		break;
	case ACTION_FIND_NEXT:
		find_previous_next_frame_with_filter(str, FALSE);
		break;
	case ACTION_FIND_PREVIOUS:
		find_previous_next_frame_with_filter(str, TRUE);
		break;
	case ACTION_COLORIZE:
		color_display_with_filter(str);
		break;
	}

	if (str) {
		g_free (str);
	}
}