Don't add the wiretap directory to the list of include directories.
[gd/wireshark/.git] / ui / gtk / export_pdu_dlg.c
1 /* export_pdu_dlg.c
2  * Dialog for exporting PDUs to file
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 "globals.h"
28 #include <wiretap/pcap-encap.h>
29
30 #include <epan/exported_pdu.h>
31
32
33 #include "ui/gtk/old-gtk-compat.h"
34 #include "ui/gtk/capture_file_dlg.h"
35 #include "ui/gtk/dlg_utils.h"
36 #include "ui/gtk/gui_utils.h"
37 #include "ui/gtk/filter_dlg.h"
38 #include "ui/gtk/gtkglobals.h"
39 #include "ui/gtk/filter_autocomplete.h"
40 #include "ui/gtk/stock_icons.h"
41
42
43 #include "ui/tap_export_pdu.h"
44 #include "ui/gtk/export_pdu_dlg.h"
45
46 static GtkWidget *export_pdu_dlg = NULL;
47
48
49 typedef struct _exp_pdu_dlg_t {
50     GtkWidget   *filter_widget;
51     GtkWidget   *tap_name_widget;
52     exp_pdu_t    exp_pdu_tap_data;
53 } exp_pdu_dlg_t;
54
55
56 static void
57 export_pdu_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
58 {
59     /* Note that we no longer have a export_pdu dialog box. */
60     export_pdu_dlg = NULL;
61 }
62
63 void
64 export_pdu_action(gpointer data)
65 {
66     const char     *filter = NULL;
67     exp_pdu_dlg_t  *exp_pdu_dlg_data = (exp_pdu_dlg_t *)data;
68     gchar      *tap_name = NULL;
69
70     filter = gtk_entry_get_text(GTK_ENTRY(exp_pdu_dlg_data->filter_widget));
71     tap_name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(exp_pdu_dlg_data->tap_name_widget));
72
73     do_export_pdu(filter, tap_name, &(exp_pdu_dlg_data->exp_pdu_tap_data));
74     window_destroy(export_pdu_dlg);
75     g_free(exp_pdu_dlg_data);
76 }
77
78
79 void
80 export_pdu_show_cb(GtkWidget *w _U_, gpointer d _U_)
81 {
82
83     GtkWidget  *main_vb, *bbox, *close_bt, *ok_bt;
84     GtkWidget  *grid, *filter_bt;
85     exp_pdu_dlg_t  *exp_pdu_dlg_data;
86     const char *filter = NULL;
87     guint         row;
88     GSList *tap_name_list;
89
90     static construct_args_t args = {
91         "Wireshark: Export PDUs Filter",
92         TRUE,                         /* dialog should have an Apply button */
93         FALSE,                        /* if parent text widget should be activated on "Ok" or "Apply" */
94         FALSE                         /* dialog is modal and transient to the parent window */
95     };
96
97     if (export_pdu_dlg != NULL) {
98         /* There's already a export_pdu dialog box; reactivate it. */
99         reactivate_window(export_pdu_dlg);
100         return;
101     }
102
103     exp_pdu_dlg_data = (exp_pdu_dlg_t *)g_malloc(sizeof(exp_pdu_dlg_t));
104     exp_pdu_dlg_data->exp_pdu_tap_data.pkt_encap = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
105
106     export_pdu_dlg = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Export PDUs to pcap-ng file");
107
108     g_signal_connect(export_pdu_dlg, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
109     g_signal_connect(export_pdu_dlg, "destroy", G_CALLBACK(export_pdu_destroy_cb), NULL);
110
111     main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
112     gtk_container_set_border_width(GTK_CONTAINER(main_vb), 3);
113     gtk_container_add(GTK_CONTAINER(export_pdu_dlg), main_vb);
114
115     /* grid */
116     grid = ws_gtk_grid_new();
117     ws_gtk_grid_set_column_spacing(GTK_GRID(grid), 6);
118     ws_gtk_grid_set_row_spacing(GTK_GRID(grid), 3);
119     gtk_box_pack_start(GTK_BOX(main_vb), grid, TRUE, TRUE, 0);
120     row = 0;
121
122     /* Filter button */
123     filter_bt=ws_gtk_button_new_from_stock(WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY);
124     g_signal_connect(filter_bt, "clicked", G_CALLBACK(display_filter_construct_cb), &args);
125     ws_gtk_grid_attach_defaults(GTK_GRID(grid), filter_bt, 0, row, 1, 1);
126     gtk_widget_show(filter_bt);
127
128     /* Entry */
129     exp_pdu_dlg_data->filter_widget=gtk_entry_new();
130     g_signal_connect(exp_pdu_dlg_data->filter_widget, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
131     g_object_set_data(G_OBJECT(grid), E_FILT_AUTOCOMP_PTR_KEY, NULL);
132     g_signal_connect(exp_pdu_dlg_data->filter_widget, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
133     g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, exp_pdu_dlg_data->filter_widget);
134
135     filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
136     if(filter){
137         gtk_entry_set_text(GTK_ENTRY(exp_pdu_dlg_data->filter_widget), filter);
138     } else {
139         colorize_filter_te_as_empty(exp_pdu_dlg_data->filter_widget);
140     }
141
142     ws_gtk_grid_attach_defaults(GTK_GRID(grid), exp_pdu_dlg_data->filter_widget, 1, row, 1, 1);
143     gtk_widget_show(exp_pdu_dlg_data->filter_widget);
144     row++;
145
146     /* Select which tap to run */
147     /* Combo box */
148     exp_pdu_dlg_data->tap_name_widget = gtk_combo_box_text_new();
149     for (tap_name_list = get_export_pdu_tap_list(); tap_name_list; tap_name_list = g_slist_next(tap_name_list)) {
150         gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(exp_pdu_dlg_data->tap_name_widget), (const char*)(tap_name_list->data));
151     }
152     gtk_combo_box_set_active(GTK_COMBO_BOX(exp_pdu_dlg_data->tap_name_widget), 0);
153
154     ws_gtk_grid_attach_defaults(GTK_GRID(grid), exp_pdu_dlg_data->tap_name_widget, 0, row, 1, 1);
155     gtk_widget_show(exp_pdu_dlg_data->tap_name_widget);
156
157     /* Setup the button row */
158
159     bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
160     gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
161
162     close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
163     window_set_cancel_button(export_pdu_dlg, close_bt, window_cancel_button_cb);
164     gtk_widget_set_tooltip_text(close_bt, "Close this dialog");
165
166     ok_bt =  (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
167     g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_export_pdu_ok_cb), exp_pdu_dlg_data);
168     gtk_widget_grab_default(ok_bt);
169     gtk_widget_set_tooltip_text(ok_bt, "Export PDUs to a temporary capture file");
170
171     gtk_widget_show_all(export_pdu_dlg);
172     window_present(export_pdu_dlg);
173
174 }
175
176 /*
177  * Editor modelines
178  *
179  * Local Variables:
180  * c-basic-offset: 4
181  * tab-width: 8
182  * indent-tabs-mode: nil
183  * End:
184  *
185  * ex: set shiftwidth=4 tabstop=8 expandtab:
186  * :indentSize=4:tabSize=8:noTabs=true:
187  */