Try to fix dummy header settings alignment.
[obnox/wireshark/wip.git] / gtk / file_import_dlg.c
1 /* file_import_dlg.c
2  * Dialog to setup for import of a text file, like text2pcap
3  * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
24  * USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
34 #include <ctype.h>
35 #include <string.h>
36
37 #include "globals.h"
38 #include "wtap.h"
39 #include "pcap-encap.h"
40
41 #include <epan/prefs.h>
42
43 #include <gtk/gtk.h>
44
45 #include "filters.h"
46 #include "simple_dialog.h"
47 #include "alert_box.h"
48
49 #include "gtk/gtkglobals.h"
50 #include "gtk/stock_icons.h"
51 #include "gtk/dlg_utils.h"
52 #include "gtk/gui_utils.h"
53 #include "gtk/file_dlg.h"
54 #include "gtk/capture_file_dlg.h"
55 #include "gtk/help_dlg.h"
56
57 #include "gtk/file_import_dlg.h"
58 #include "gtk/text_import.h"
59 #include "gtk/text_import_scanner.h"
60
61 #include "file.h"
62 #include "wsutil/file_util.h"
63 #include "tempfile.h"
64
65 #define INPUT_FRM_KEY                   "input_frame"
66
67 #define INPUT_FILENAME_TE_KEY           "input_filename_text"
68
69 #define INPUT_OFFSET_HEX_RB_KEY         "input_offset_hex_radio"
70 #define INPUT_OFFSET_OCT_RB_KEY         "input_offset_oct_radio"
71 #define INPUT_OFFSET_DEC_RB_KEY         "input_offset_dec_radio"
72
73 #define INPUT_DATETIME_CB_KEY           "input_datetime_checkbox"
74 #define INPUT_TIMEFMT_LBL_KEY           "input_timeformat_label"
75 #define INPUT_TIMEFMT_TE_KEY            "input_timeformat_entry"
76
77 #define IMPORT_FRM_KEY                  "import_frame"
78 #define IMPORT_ENCAP_CO_KEY             "import_encap_combo"
79
80 #define IMPORT_HEADER_FRM_KEY           "import_header_frame"
81 #define IMPORT_HEADER_CB_KEY            "import_header_checkbox"
82 #define IMPORT_HEADER_ETH_RB_KEY        "import_header_ethernet_radio"
83 #define IMPORT_HEADER_ETYPE_LBL_KEY     "import_header_etype_label"
84 #define IMPORT_HEADER_ETYPE_TE_KEY      "import_header_etype_text"
85 #define IMPORT_HEADER_IPV4_RB_KEY       "import_header_ipv4_radio"
86 #define IMPORT_HEADER_PROT_LBL_KEY      "import_header_prot_label"
87 #define IMPORT_HEADER_PROT_TE_KEY       "import_header_prot_text"
88 #define IMPORT_HEADER_UDP_RB_KEY        "import_header_udp_radio"
89 #define IMPORT_HEADER_SRC_PORT_LBL_KEY  "import_header_src_port_label"
90 #define IMPORT_HEADER_SRC_PORT_TE_KEY   "import_header_src_port_text"
91 #define IMPORT_HEADER_TCP_RB_KEY        "import_header_tcp_radio"
92 #define IMPORT_HEADER_DST_PORT_LBL_KEY  "import_header_dst_port_label"
93 #define IMPORT_HEADER_DST_PORT_TE_KEY   "import_header_dst_port_text"
94 #define IMPORT_HEADER_SCTP_RB_KEY       "import_header_sctp_radio"
95 #define IMPORT_HEADER_TAG_LBL_KEY       "import_header_tag_label"
96 #define IMPORT_HEADER_TAG_TE_KEY        "import_header_tag_text"
97 #define IMPORT_HEADER_SCTP_D_RB_KEY     "import_header_sctp_data_radio"
98 #define IMPORT_HEADER_PPI_LBL_KEY       "import_header_ppi_label"
99 #define IMPORT_HEADER_PPI_TE_KEY        "import_header_ppi_text"
100
101 #define IMPORT_FRAME_LENGTH_TE_KEY      "import_frame_length_text"
102
103 static GtkWidget *file_import_dlg_w = NULL;
104 static GtkListStore *encap_list_store = NULL;
105
106 /*****************************************************************************/
107
108 static void
109 file_import_dlg_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
110 {
111     file_import_dlg_w = NULL;
112 }
113
114 /*****************************************************************************/
115
116 static void
117 browse_file_cb(GtkWidget *browse_bt, GtkWidget *filename_te)
118 {
119     file_selection_browse(browse_bt, filename_te, "Wireshark: Import from Text",
120         FILE_SELECTION_READ_BROWSE);
121 }
122
123 static void
124 timefmt_cb_toggle(GtkWidget *widget, gpointer data _U_)
125 {
126     GtkWidget *timefmt_lbl, *timefmt_te;
127     gboolean apply_fmt;
128
129     timefmt_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_LBL_KEY));
130     timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_TE_KEY));
131
132     apply_fmt = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
133     gtk_widget_set_sensitive(timefmt_lbl, apply_fmt);
134     gtk_widget_set_sensitive(timefmt_te, apply_fmt);
135 }
136
137 /*****************************************************************************/
138 static void
139 create_encap_list_store(void)
140 {
141     GtkTreeIter iter;
142     gint encap;
143     const gchar *name;
144
145     encap_list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT);
146
147     /* Scan all Wiretap encapsulation types */
148     for (encap = 1; encap < wtap_get_num_encap_types(); encap++)
149     {
150         /* Check if we can write it to a PCAP file */
151         if ((wtap_wtap_encap_to_pcap_encap(encap) > 0) &&
152             /*
153              * Exclude wtap encapsulations that require a pseudo header,
154              * because we won't setup one from the text we import and
155              * wiretap doesn't allow us to write 'raw' frames
156              */
157             !((encap == WTAP_ENCAP_ATM_PDUS) ||
158               (encap == WTAP_ENCAP_IRDA) ||
159               (encap == WTAP_ENCAP_MTP2_WITH_PHDR) ||
160               (encap == WTAP_ENCAP_LINUX_LAPD) ||
161               (encap == WTAP_ENCAP_SITA) ||
162               (encap == WTAP_ENCAP_ERF) ||
163               (encap == WTAP_ENCAP_I2C) ||
164               (encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) ||
165               (encap == WTAP_ENCAP_PPP_WITH_PHDR)
166            ) )
167         {
168             /* If it has got a name */
169             if ((name = wtap_encap_string(encap)))
170             {
171                 gtk_list_store_append(encap_list_store, &iter);
172                 gtk_list_store_set(encap_list_store, &iter, 0, name, 1, encap, -1);
173             }
174         }
175     }
176
177 }
178
179 static GtkWidget *
180 fill_encap_combo(void)
181 {
182     GtkWidget *encap_co = NULL;
183     GtkCellRenderer *cell;
184     
185     encap_co = gtk_combo_box_new_with_model(GTK_TREE_MODEL(encap_list_store));
186     cell = gtk_cell_renderer_text_new();
187     gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encap_co), cell, TRUE);
188     gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(encap_co), cell, "text", 0, NULL);
189
190     return encap_co;
191 }
192
193 static void header_frm_child_set(GtkWidget *widget, gpointer data);
194
195 static void
196 encap_co_changed(GtkComboBox *widget, gpointer data)
197 {
198     GtkTreeIter iter;
199     gboolean result;
200     GtkWidget *header_cb;
201
202     result = gtk_combo_box_get_active_iter(widget, &iter);
203
204     if (result)
205     {
206         guint8 encap;
207         GtkTreeModel *model = gtk_combo_box_get_model(widget);
208         gtk_tree_model_get(model, &iter, 1, &encap, -1);
209
210         if (encap != WTAP_ENCAP_ETHERNET)
211             result = FALSE;
212     }
213
214     if (result)
215     {
216         header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_CB_KEY));
217         g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", data);
218     } else {
219         gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set, GUINT_TO_POINTER(result));
220     }
221 }
222
223 /*****************************************************************************/
224
225 static void
226 header_frm_child_set(GtkWidget *widget, gpointer data)
227 {
228     gtk_widget_set_sensitive(widget, GPOINTER_TO_UINT(data));
229 }
230
231 static void
232 header_cb_toggle(GtkWidget *widget, gpointer data)
233 {
234     gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set,
235         GUINT_TO_POINTER(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))));
236     /* The frame's checkbox must stay sensitive, of course... */
237     gtk_widget_set_sensitive(widget, TRUE);
238 }
239
240 /*
241  * Header radio button toggle handlers
242  */
243 static void
244 header_eth_rb_toggle(GtkWidget *widget, gpointer data)
245 {
246     GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
247     GtkWidget *etype_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
248     GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
249     GtkWidget *prot_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
250     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
251     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
252     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
253     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
254     GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
255     GtkWidget *tag_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
256     GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
257     GtkWidget *ppi_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
258
259     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
260     {
261         gtk_widget_set_sensitive(etype_lbl, TRUE);
262         gtk_widget_set_sensitive(etype_te, TRUE);
263         gtk_widget_set_sensitive(prot_lbl, FALSE);
264         gtk_widget_set_sensitive(prot_te, FALSE);
265         gtk_widget_set_sensitive(src_port_lbl, FALSE);
266         gtk_widget_set_sensitive(src_port_te, FALSE);
267         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
268         gtk_widget_set_sensitive(dst_port_te, FALSE);
269         gtk_widget_set_sensitive(tag_lbl, FALSE);
270         gtk_widget_set_sensitive(tag_te, FALSE);
271         gtk_widget_set_sensitive(ppi_lbl, FALSE);
272         gtk_widget_set_sensitive(ppi_te, FALSE);
273     }
274     else
275     {
276         gtk_widget_set_sensitive(etype_lbl, FALSE);
277         gtk_widget_set_sensitive(etype_te, FALSE);
278     }
279 }
280
281 static void
282 header_ipv4_rb_toggle(GtkWidget *widget, gpointer data)
283 {
284     GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
285     GtkWidget *etype_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
286     GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
287     GtkWidget *prot_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
288     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
289     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
290     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
291     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
292     GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
293     GtkWidget *tag_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
294     GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
295     GtkWidget *ppi_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
296
297     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
298     {
299         gtk_widget_set_sensitive(etype_lbl, FALSE);
300         gtk_widget_set_sensitive(etype_te, FALSE);
301         gtk_widget_set_sensitive(prot_lbl, TRUE);
302         gtk_widget_set_sensitive(prot_te, TRUE);
303         gtk_widget_set_sensitive(src_port_lbl, FALSE);
304         gtk_widget_set_sensitive(src_port_te, FALSE);
305         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
306         gtk_widget_set_sensitive(dst_port_te, FALSE);
307         gtk_widget_set_sensitive(tag_lbl, FALSE);
308         gtk_widget_set_sensitive(tag_te, FALSE);
309         gtk_widget_set_sensitive(ppi_lbl, FALSE);
310         gtk_widget_set_sensitive(ppi_te, FALSE);
311     }
312     else
313     {
314         gtk_widget_set_sensitive(prot_lbl, FALSE);
315         gtk_widget_set_sensitive(prot_te, FALSE);
316     }
317 }
318
319 static void
320 header_udp_rb_toggle(GtkWidget *widget, gpointer data)
321 {
322     GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
323     GtkWidget *etype_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
324     GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
325     GtkWidget *prot_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
326     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
327     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
328     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
329     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
330     GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
331     GtkWidget *tag_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
332     GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
333     GtkWidget *ppi_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
334
335     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
336     {
337         gtk_widget_set_sensitive(etype_lbl, FALSE);
338         gtk_widget_set_sensitive(etype_te, FALSE);
339         gtk_widget_set_sensitive(prot_lbl, FALSE);
340         gtk_widget_set_sensitive(prot_te, FALSE);
341         gtk_widget_set_sensitive(src_port_lbl, TRUE);
342         gtk_widget_set_sensitive(src_port_te, TRUE);
343         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
344         gtk_widget_set_sensitive(dst_port_te, TRUE);
345         gtk_widget_set_sensitive(tag_lbl, FALSE);
346         gtk_widget_set_sensitive(tag_te, FALSE);
347         gtk_widget_set_sensitive(ppi_lbl, FALSE);
348         gtk_widget_set_sensitive(ppi_te, FALSE);
349     }
350     else
351     {
352         gtk_widget_set_sensitive(src_port_lbl, FALSE);
353         gtk_widget_set_sensitive(src_port_te, FALSE);
354         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
355         gtk_widget_set_sensitive(dst_port_te, FALSE);
356     }
357 }
358
359 static void
360 header_tcp_rb_toggle(GtkWidget *widget, gpointer data)
361 {
362     GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
363     GtkWidget *etype_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
364     GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
365     GtkWidget *prot_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
366     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
367     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
368     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
369     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
370     GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
371     GtkWidget *tag_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
372     GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
373     GtkWidget *ppi_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
374
375     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
376     {
377         gtk_widget_set_sensitive(etype_lbl, FALSE);
378         gtk_widget_set_sensitive(etype_te, FALSE);
379         gtk_widget_set_sensitive(prot_lbl, FALSE);
380         gtk_widget_set_sensitive(prot_te, FALSE);
381         gtk_widget_set_sensitive(src_port_lbl, TRUE);
382         gtk_widget_set_sensitive(src_port_te, TRUE);
383         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
384         gtk_widget_set_sensitive(dst_port_te, TRUE);
385         gtk_widget_set_sensitive(tag_lbl, FALSE);
386         gtk_widget_set_sensitive(tag_te, FALSE);
387         gtk_widget_set_sensitive(ppi_lbl, FALSE);
388         gtk_widget_set_sensitive(ppi_te, FALSE);
389     }
390     else
391     {
392         gtk_widget_set_sensitive(src_port_lbl, FALSE);
393         gtk_widget_set_sensitive(src_port_te, FALSE);
394         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
395         gtk_widget_set_sensitive(dst_port_te, FALSE);
396     }
397 }
398
399 static void
400 header_sctp_rb_toggle(GtkWidget *widget, gpointer data)
401 {
402     GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
403     GtkWidget *etype_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
404     GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
405     GtkWidget *prot_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
406     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
407     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
408     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
409     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
410     GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
411     GtkWidget *tag_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
412     GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
413     GtkWidget *ppi_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
414
415     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
416     {
417         gtk_widget_set_sensitive(etype_lbl, FALSE);
418         gtk_widget_set_sensitive(etype_te, FALSE);
419         gtk_widget_set_sensitive(prot_lbl, FALSE);
420         gtk_widget_set_sensitive(prot_te, FALSE);
421         gtk_widget_set_sensitive(src_port_lbl, TRUE);
422         gtk_widget_set_sensitive(src_port_te, TRUE);
423         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
424         gtk_widget_set_sensitive(dst_port_te, TRUE);
425         gtk_widget_set_sensitive(tag_lbl, TRUE);
426         gtk_widget_set_sensitive(tag_te, TRUE);
427         gtk_widget_set_sensitive(ppi_lbl, FALSE);
428         gtk_widget_set_sensitive(ppi_te, FALSE);
429     }
430     else
431     {
432         gtk_widget_set_sensitive(src_port_lbl, FALSE);
433         gtk_widget_set_sensitive(src_port_te, FALSE);
434         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
435         gtk_widget_set_sensitive(dst_port_te, FALSE);
436         gtk_widget_set_sensitive(tag_lbl, FALSE);
437         gtk_widget_set_sensitive(tag_te, FALSE);
438     }
439 }
440
441 static void
442 header_sctp_data_rb_toggle(GtkWidget *widget, gpointer data)
443 {
444     GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
445     GtkWidget *etype_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
446     GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
447     GtkWidget *prot_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
448     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
449     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
450     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
451     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
452     GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
453     GtkWidget *tag_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
454     GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
455     GtkWidget *ppi_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
456
457     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
458     {
459         gtk_widget_set_sensitive(etype_lbl, FALSE);
460         gtk_widget_set_sensitive(etype_te, FALSE);
461         gtk_widget_set_sensitive(prot_lbl, FALSE);
462         gtk_widget_set_sensitive(prot_te, FALSE);
463         gtk_widget_set_sensitive(src_port_lbl, TRUE);
464         gtk_widget_set_sensitive(src_port_te, TRUE);
465         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
466         gtk_widget_set_sensitive(dst_port_te, TRUE);
467         gtk_widget_set_sensitive(tag_lbl, FALSE);
468         gtk_widget_set_sensitive(tag_te, FALSE);
469         gtk_widget_set_sensitive(ppi_lbl, TRUE);
470         gtk_widget_set_sensitive(ppi_te, TRUE);
471     }
472     else
473     {
474         gtk_widget_set_sensitive(src_port_lbl, FALSE);
475         gtk_widget_set_sensitive(src_port_te, FALSE);
476         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
477         gtk_widget_set_sensitive(dst_port_te, FALSE);
478         gtk_widget_set_sensitive(ppi_lbl, FALSE);
479         gtk_widget_set_sensitive(ppi_te, FALSE);
480     }
481 }
482
483 /*****************************************************************************/
484
485 static void
486 file_import_open(text_import_info_t *info)
487 {
488     int import_file_fd;
489     char *tmpname, *capfile_name = NULL;
490     int err;
491
492     /* Choose a random name for the temporary import buffer */
493     import_file_fd = create_tempfile(&tmpname, "import");
494     capfile_name = g_strdup(tmpname);
495
496     info->wdh = wtap_dump_fdopen(import_file_fd, WTAP_FILE_PCAP, info->encapsulation, info->max_frame_length, FALSE, &err);
497     if (info->wdh == NULL) {
498         open_failure_alert_box(capfile_name, err, TRUE);
499         fclose(info->import_text_file);
500         goto end;
501     }
502
503     text_import_setup(info);
504
505     text_importin = info->import_text_file;
506     
507     text_importlex();
508
509     text_import_cleanup();
510     
511     if (fclose(info->import_text_file))
512     {
513         read_failure_alert_box(info->import_text_filename, errno);
514     }
515
516     if (!wtap_dump_close(info->wdh, &err))
517     {
518         write_failure_alert_box(capfile_name, err);
519     }
520
521     if (cf_open(&cfile, capfile_name, TRUE /* temporary file */, &err) != CF_OK)
522     {
523         open_failure_alert_box(capfile_name, err, FALSE);
524         goto end;
525     }
526
527     switch (cf_read(&cfile, FALSE)) {
528     case CF_READ_OK:
529     case CF_READ_ERROR:
530     /* Just because we got an error, that doesn't mean we were unable
531        to read any of the file; we handle what we could get from the
532        file. */
533     break;
534
535     case CF_READ_ABORTED:
536     /* The user bailed out of re-reading the capture file; the
537        capture file has been closed - just free the capture file name
538        string and return (without changing the last containing
539        directory). */
540     break;
541     }
542
543 end:
544     g_free(info->import_text_filename);
545     g_free(info->date_timestamp_format);
546     g_free(info);
547     g_free(capfile_name);
548     window_destroy(file_import_dlg_w);
549 }
550
551 static text_import_info_t *
552 setup_file_import(GtkWidget *main_w)
553 {
554     GtkWidget *input_frm, *import_frm;
555
556     text_import_info_t *text_import_info = g_malloc0(sizeof(text_import_info_t));
557     
558     /* Retrieve the input and import settings from the dialog */
559   
560     /* First the main components */
561     input_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), INPUT_FRM_KEY));
562     import_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), IMPORT_FRM_KEY));
563
564     /* Then the input frame controls of interest */
565     {
566         GtkWidget *filename_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY));
567         GtkWidget *offset_hex_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY));
568         GtkWidget *offset_oct_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY));
569         GtkWidget *offset_dec_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY));
570         GtkWidget *timefmt_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY));
571         GtkWidget *timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY));
572
573         text_import_info->import_text_filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(filename_te)));
574
575         /* Try to open the input file */
576         text_import_info->import_text_file = ws_fopen(text_import_info->import_text_filename, "rb");
577         if (!text_import_info->import_text_file) {
578             open_failure_alert_box(text_import_info->import_text_filename, errno, FALSE);
579             g_free(text_import_info->import_text_filename);
580             g_free(text_import_info->date_timestamp_format);
581             g_free(text_import_info);
582             return NULL;
583         }
584
585         text_import_info->offset_type =
586             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_hex_rb)) ? OFFSET_HEX :
587             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_oct_rb)) ? OFFSET_OCT :
588             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_dec_rb)) ? OFFSET_DEC :
589             0;
590         text_import_info->date_timestamp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(timefmt_cb));
591         text_import_info->date_timestamp_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(timefmt_te)));
592     }
593
594     /* Then the import frame controls of interest */
595     {
596         GtkWidget *encap_co = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY));
597         GtkWidget *header_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY));
598         GtkWidget *framelen_te = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY));
599
600         /* Then the header frame controls of interest */
601         GtkWidget *header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY));
602
603         GtkWidget *header_eth_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY));
604         GtkWidget *header_ipv4_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY));
605         GtkWidget *header_udp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY));
606         GtkWidget *header_tcp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY));
607         GtkWidget *header_sctp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY));
608         GtkWidget *header_sctp_data_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY));
609
610         GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY));
611         GtkWidget *protocol_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY));
612         GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY));
613         GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY));
614         GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY));
615         GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY));
616
617         GtkTreeIter iter;
618
619         if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter))
620         {
621             GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
622             gtk_tree_model_get(model, &iter, 1, &text_import_info->encapsulation, -1);
623         }
624
625         if ((text_import_info->encapsulation == WTAP_ENCAP_ETHERNET) &&
626             (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_cb))))
627         {
628             text_import_info->dummy_header_type =
629                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_eth_rb)) ? HEADER_ETH :
630                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_ipv4_rb)) ? HEADER_IPV4 :
631                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_udp_rb)) ? HEADER_UDP :
632                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_tcp_rb)) ? HEADER_TCP :
633                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_rb)) ? HEADER_SCTP :
634                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_data_rb)) ? HEADER_SCTP_DATA :
635                 HEADER_NONE;
636
637             switch (text_import_info->dummy_header_type)
638             {
639             case HEADER_ETH:
640                 text_import_info->pid = strtol(gtk_entry_get_text(GTK_ENTRY(etype_te)), NULL, 16);
641                 if (text_import_info->pid > 0xffff)
642                 {
643                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The Ethertype (%x) is too large.",
644                         text_import_info->pid);
645                     g_free(text_import_info->import_text_filename);
646                     fclose(text_import_info->import_text_file);
647                     g_free(text_import_info->date_timestamp_format);
648                     g_free(text_import_info);
649                     return NULL;
650                 }
651                 break;
652
653             case HEADER_IPV4:
654                 text_import_info->protocol = strtol(gtk_entry_get_text(GTK_ENTRY(protocol_te)), NULL, 10);
655                 if (text_import_info->protocol > 0xff)
656                 {
657                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The IPv4 protocol (%u) is too large.",
658                         text_import_info->protocol);
659                     g_free(text_import_info->import_text_filename);
660                     fclose(text_import_info->import_text_file);
661                     g_free(text_import_info->date_timestamp_format);
662                     g_free(text_import_info);
663                     return NULL;
664                 }
665                 break;
666
667             case HEADER_UDP:
668             case HEADER_TCP:
669                 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
670                 if (text_import_info->src_port > 0xffff)
671                 {
672                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
673                         text_import_info->src_port);
674                     g_free(text_import_info->import_text_filename);
675                     fclose(text_import_info->import_text_file);
676                     g_free(text_import_info->date_timestamp_format);
677                     g_free(text_import_info);
678                     return NULL;
679                 }
680                 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
681                 if (text_import_info->dst_port > 0xffff)
682                 {
683                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
684                         text_import_info->dst_port);
685                     g_free(text_import_info->import_text_filename);
686                     fclose(text_import_info->import_text_file);
687                     g_free(text_import_info->date_timestamp_format);
688                     g_free(text_import_info);
689                     return NULL;
690                 }
691                 break;
692
693             case HEADER_SCTP:
694                 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
695                 if (text_import_info->src_port > 0xffff)
696                 {
697                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
698                         text_import_info->src_port);
699                     g_free(text_import_info->import_text_filename);
700                     fclose(text_import_info->import_text_file);
701                     g_free(text_import_info->date_timestamp_format);
702                     g_free(text_import_info);
703                     return NULL;
704                 }
705                 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
706                 if (text_import_info->dst_port > 0xffff)
707                 {
708                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
709                         text_import_info->dst_port);
710                     g_free(text_import_info->import_text_filename);
711                     fclose(text_import_info->import_text_file);
712                     g_free(text_import_info->date_timestamp_format);
713                     g_free(text_import_info);
714                     return NULL;
715                 }
716                 text_import_info->tag = strtol(gtk_entry_get_text(GTK_ENTRY(tag_te)), NULL, 10);
717                 break;
718
719             case HEADER_SCTP_DATA:
720                 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
721                 if (text_import_info->src_port > 0xffff)
722                 {
723                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
724                         text_import_info->src_port);
725                     g_free(text_import_info->import_text_filename);
726                     fclose(text_import_info->import_text_file);
727                     g_free(text_import_info->date_timestamp_format);
728                     g_free(text_import_info);
729                     return NULL;
730                 }
731                 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
732                 if (text_import_info->dst_port > 0xffff)
733                 {
734                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
735                         text_import_info->dst_port);
736                     g_free(text_import_info->import_text_filename);
737                     fclose(text_import_info->import_text_file);
738                     g_free(text_import_info->date_timestamp_format);
739                     g_free(text_import_info);
740                     return NULL;
741                 }
742                 text_import_info->ppi = strtol(gtk_entry_get_text(GTK_ENTRY(ppi_te)), NULL, 10);
743                 break;
744
745             default:
746                 break;
747             }
748         } else {
749             text_import_info->dummy_header_type = HEADER_NONE;
750         }
751
752         text_import_info->max_frame_length = strtol(gtk_entry_get_text(GTK_ENTRY(framelen_te)), NULL, 10);
753         if (text_import_info->max_frame_length == 0) {
754             text_import_info->max_frame_length = IMPORT_MAX_PACKET;
755         }
756         else if (text_import_info->max_frame_length > IMPORT_MAX_PACKET)
757         {
758             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The maximum frame length (%u) is too long.",
759                 text_import_info->max_frame_length);
760             g_free(text_import_info->import_text_filename);
761             fclose(text_import_info->import_text_file);
762             g_free(text_import_info->date_timestamp_format);
763             g_free(text_import_info);
764             return NULL;
765         }
766     }
767
768     return text_import_info;
769 }
770
771 /*****************************************************************************/
772
773 static void
774 file_import_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
775 {
776     text_import_info_t *text_import_info;
777     
778     switch (btn) {
779     case ESD_BTN_SAVE:
780         /* save file first */
781         file_save_as_cmd(after_save_no_action, NULL);
782         break;
783     case ESD_BTN_DONT_SAVE:
784         cf_close(&cfile);
785         break;
786     case ESD_BTN_CANCEL:
787         return;
788     default:
789         g_assert_not_reached();
790     }
791
792     text_import_info = setup_file_import(data);
793     if (text_import_info)
794         file_import_open(text_import_info);
795 }
796
797 static void
798 file_import_ok_cb(GtkWidget *widget _U_, gpointer data)
799 {
800     text_import_info_t *text_import_info;
801     
802     if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
803         gpointer dialog;
804         /* user didn't save his current file, ask him */
805         dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
806                 "%sSave capture file before opening a new one?%s\n\n"
807                 "If you open a new capture file without saving, your capture data will be discarded.",
808                 simple_dialog_primary_start(), simple_dialog_primary_end());
809         simple_dialog_set_cb(dialog, file_import_answered_cb, data);
810     } else {
811         /* unchanged file, just open a new one */
812         text_import_info = setup_file_import(data);
813         if (text_import_info)
814             file_import_open(text_import_info);
815     }
816
817 }
818
819 /*****************************************************************************/
820
821 /*
822  * Dialog creator
823  */
824 static GtkWidget *
825 file_import_dlg_new()
826 {
827     GtkWidget  *main_w, *main_vb,
828                *input_frm, *input_tb, *input_vb,
829                *filename_hb, *filename_lbl, *filename_te, *browse_bt,
830                *offset_hb, *offset_lbl_vb, *offset_lbl, *offset_rb_vb,
831                *offset_hex_rb, *offset_oct_rb, *offset_dec_rb,
832                *timefmt_hb, *timefmt_cb, *timefmt_lbl, *timefmt_te,
833                *import_frm, *import_vb,
834                *encap_hb, *encap_lbl, *encap_co,
835                *header_cb, *header_frm, *header_hb,
836                *header_eth_rb, *header_ipv4_rb, *header_udp_rb,
837                *header_tcp_rb, *header_sctp_rb, *header_sctp_data_rb,
838                *header_rblbl_vb,
839                *header_rblbl_1_hb, *header_rblbl_1_lbl,
840                *header_rblbl_2_hb, *header_rblbl_2_lbl,
841                *header_rblbl_3_hb, *header_rblbl_3_lbl,
842                *header_rblbl_4_hb, *header_rblbl_4_lbl,
843                *header_rblbl_5_hb, *header_rblbl_5_lbl,
844                *header_rblbl_6_hb, *header_rblbl_6_lbl,
845                *etype_te, *protocol_te, *src_port_te,
846                *dst_port_te, *tag_te, *ppi_te,
847                *framelen_hb, *framelen_lbl, *framelen_te,
848                *bbox, *help_bt, *close_bt, *ok_bt;
849
850     GSList     *offset_grp,       /* Offset radio button group */
851                *header_grp;       /* Dummy header radio button group */
852
853 #if GTK_CHECK_VERSION(2,12,0)
854 #else
855     GtkTooltips *tooltips = gtk_tooltips_new();
856 #endif
857
858     /* Setup the dialog */
859
860     main_w = dlg_window_new("Wireshark: Import from Text");
861     gtk_window_set_default_size(GTK_WINDOW(main_w), 400, 300);
862
863     main_vb = gtk_vbox_new(FALSE, 0);
864     gtk_container_set_border_width(GTK_CONTAINER(main_vb), 3);
865     gtk_container_add(GTK_CONTAINER(main_w), main_vb);
866
867     /* Setup the input frame */
868
869     input_frm = gtk_frame_new("Input");
870     gtk_box_pack_start(GTK_BOX(main_vb), input_frm, FALSE, FALSE, 0);
871
872     g_object_set_data(G_OBJECT(main_w), INPUT_FRM_KEY, input_frm);
873     
874     input_vb = gtk_vbox_new(FALSE, 0);
875     gtk_container_add(GTK_CONTAINER(input_frm), input_vb);
876
877     input_tb = gtk_table_new(2, 3, FALSE);
878     gtk_container_set_border_width(GTK_CONTAINER(input_tb), 5);
879     gtk_box_pack_start(GTK_BOX(input_vb), input_tb, FALSE, FALSE, 0);
880     gtk_table_set_row_spacings(GTK_TABLE(input_tb), 5);
881     gtk_table_set_col_spacings(GTK_TABLE(input_tb), 5);
882
883     /* Filename */
884     filename_hb = gtk_hbox_new(FALSE, 3);
885     gtk_container_set_border_width(GTK_CONTAINER(filename_hb), 3);
886
887     filename_lbl = gtk_label_new("Filename:");
888     gtk_table_attach(GTK_TABLE(input_tb), filename_lbl, 0, 1, 0, 1, 0, 0, 0, 0);
889
890     filename_te = gtk_entry_new();
891 #if GTK_CHECK_VERSION(2,12,0)
892     gtk_widget_set_tooltip_text(filename_te, "Set name of text file to import");
893 #else
894     gtk_tooltips_set_tip(tooltips, filename_te, "Set name of text file to import", NULL);
895 #endif
896     gtk_table_attach_defaults(GTK_TABLE(input_tb), filename_te, 1, 2, 0, 1);
897
898     g_object_set_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY, filename_te);
899     
900     browse_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
901 #if GTK_CHECK_VERSION(2,12,0)
902     gtk_widget_set_tooltip_text(browse_bt, "Browse for text file to import");
903 #else
904     gtk_tooltips_set_tip(tooltips, browse_bt, "Browse for text file to import", NULL);
905 #endif
906     gtk_table_attach(GTK_TABLE(input_tb), browse_bt, 2, 3, 0, 1, 0, 0, 0, 0);
907
908     g_signal_connect(browse_bt, "clicked", G_CALLBACK(browse_file_cb), filename_te);
909
910     /* Offsets */
911     offset_hb = gtk_hbox_new(FALSE, 3);
912     gtk_container_set_border_width(GTK_CONTAINER(offset_hb), 3);
913     gtk_box_pack_start(GTK_BOX(input_vb), offset_hb, FALSE, FALSE, 0);
914
915     offset_lbl_vb = gtk_vbox_new(FALSE, 0);
916     gtk_box_pack_start(GTK_BOX(offset_hb), offset_lbl_vb, FALSE, FALSE, 0);
917
918     offset_lbl = gtk_label_new("Offsets:");
919     gtk_misc_set_alignment(GTK_MISC(offset_lbl), 1.0f, 0.0f);
920     gtk_table_attach(GTK_TABLE(input_tb), offset_lbl, 0, 1, 1, 2, 0, 0, 0, 0);
921
922     offset_rb_vb = gtk_vbox_new(FALSE, 0);
923     gtk_table_attach_defaults(GTK_TABLE(input_tb), offset_rb_vb, 1, 2, 1, 2);
924
925     offset_hex_rb = gtk_radio_button_new_with_label(NULL, "Hexadecimal");
926 #if GTK_CHECK_VERSION(2,12,0)
927     gtk_widget_set_tooltip_text(offset_hex_rb, "Offsets in the text file are in hexadecimal notation");
928 #else
929     gtk_tooltips_set_tip(tooltips, offset_hex_rb, "Offsets in the text file are in hexadecimal notation", NULL);
930 #endif
931     gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_hex_rb, FALSE, FALSE, 0);
932
933     g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY, offset_hex_rb);
934     
935     offset_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(offset_hex_rb));
936     offset_oct_rb = gtk_radio_button_new_with_label(offset_grp, "Octal");
937 #if GTK_CHECK_VERSION(2,12,0)
938     gtk_widget_set_tooltip_text(offset_oct_rb, "Offsets in the text file are in octal notation");
939 #else
940     gtk_tooltips_set_tip(tooltips, offset_oct_rb, "Offsets in the text file are in octal notation", NULL);
941 #endif
942     gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_oct_rb, FALSE, FALSE, 0);
943
944     g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY, offset_oct_rb);
945     
946     offset_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(offset_oct_rb));
947     offset_dec_rb = gtk_radio_button_new_with_label(offset_grp, "Decimal");
948 #if GTK_CHECK_VERSION(2,12,0)
949     gtk_widget_set_tooltip_text(offset_dec_rb, "Offsets in the text file are in decimal notation");
950 #else
951     gtk_tooltips_set_tip(tooltips, offset_dec_rb, "Offsets in the text file are in decimal notation", NULL);
952 #endif
953     gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_dec_rb, FALSE, FALSE, 0);
954
955     g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY, offset_dec_rb);
956         
957     /* Time format */
958     timefmt_hb = gtk_hbox_new(FALSE, 3);
959     gtk_container_set_border_width(GTK_CONTAINER(timefmt_hb), 3);
960     gtk_box_pack_start(GTK_BOX(input_vb), timefmt_hb, FALSE, FALSE, 0);
961
962     timefmt_cb = gtk_check_button_new_with_label("Date/Time");
963 #if GTK_CHECK_VERSION(2,12,0)
964     gtk_widget_set_tooltip_text(timefmt_cb, "Whether or not the text file contains timestamp information");
965 #else
966     gtk_tooltips_set_tip(tooltips, timefmt_cb, "Whether or not the text file contains timestamp information", NULL);
967 #endif
968     gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_cb, FALSE, FALSE, 0);
969
970     g_object_set_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY, timefmt_cb);
971
972     timefmt_lbl = gtk_label_new("   Format:");
973     gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_lbl, FALSE, FALSE, 0);
974
975     g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_LBL_KEY, timefmt_lbl);
976
977     timefmt_te = gtk_entry_new();
978 #if GTK_CHECK_VERSION(2,12,0)
979     gtk_widget_set_tooltip_text(timefmt_te, "The format in which to parse timestamps in the text file (eg. %H:%M:%S.). Format specifiers are based on strptime(3)");
980 #else
981     gtk_tooltips_set_tip(tooltips, timefmt_te, "The format in which to parse timestamps in the text file (eg. %H:%M:%S.). Format specifiers are based on strptime(3)", NULL);
982 #endif
983     gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_te, FALSE, FALSE, 0);
984
985     g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_TE_KEY, timefmt_te);
986     g_object_set_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY, timefmt_te);
987     
988     g_signal_connect(timefmt_cb, "toggled", G_CALLBACK(timefmt_cb_toggle), NULL);
989     g_signal_emit_by_name(G_OBJECT(timefmt_cb), "toggled", NULL);
990
991     /* Setup the import frame */
992
993     import_frm = gtk_frame_new("Import");
994     gtk_box_pack_start(GTK_BOX(main_vb), import_frm, TRUE, TRUE, 3);
995
996     g_object_set_data(G_OBJECT(main_w), IMPORT_FRM_KEY, import_frm);
997         
998     import_vb = gtk_vbox_new(FALSE, 0);
999     gtk_container_add(GTK_CONTAINER(import_frm), import_vb);
1000
1001     /* Encapsulation */
1002     encap_hb = gtk_hbox_new(FALSE, 3);
1003     gtk_container_set_border_width(GTK_CONTAINER(encap_hb), 3);
1004     gtk_box_pack_start(GTK_BOX(import_vb), encap_hb, FALSE, FALSE, 0);
1005
1006     encap_lbl = gtk_label_new("Encapsulation type:");
1007     gtk_box_pack_start(GTK_BOX(encap_hb), encap_lbl, FALSE, FALSE, 0);
1008
1009     encap_co = fill_encap_combo();
1010 #if GTK_CHECK_VERSION(2,12,0)
1011     gtk_widget_set_tooltip_text(encap_co, "Encapsulation type for the frames in the import capture file");
1012 #else
1013     gtk_tooltips_set_tip(tooltips, encap_co, "Encapsulation type for the frames in the import capture file", NULL);
1014 #endif
1015     gtk_box_pack_start(GTK_BOX(encap_hb), encap_co, FALSE, FALSE, 0);
1016
1017     g_object_set_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY, encap_co);
1018     
1019     /* Dummy header */
1020     header_frm = gtk_frame_new(NULL);
1021     header_cb = gtk_check_button_new_with_label("Dummy header");
1022 #if GTK_CHECK_VERSION(2,12,0)
1023     gtk_widget_set_tooltip_text(header_cb, "Whether or not to prefix a dummy header to the frames");
1024 #else
1025     gtk_tooltips_set_tip(tooltips, header_cb, "Whether or not to prefix a dummy header to the frames", NULL);
1026 #endif
1027     gtk_frame_set_label_widget(GTK_FRAME(header_frm), header_cb);
1028     gtk_container_set_border_width(GTK_CONTAINER(header_frm), 3);
1029     gtk_box_pack_start(GTK_BOX(import_vb), header_frm, FALSE, FALSE, 0);
1030
1031     g_object_set_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY, header_frm);
1032     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY, header_cb);
1033     
1034     header_hb = gtk_hbox_new(FALSE, 3);
1035     gtk_container_set_border_width(GTK_CONTAINER(header_hb), 3);
1036     gtk_container_add(GTK_CONTAINER(header_frm), header_hb);
1037
1038     header_rblbl_vb = gtk_vbox_new(FALSE, 0);
1039     gtk_box_pack_start(GTK_BOX(header_hb), header_rblbl_vb, TRUE, TRUE, 0);
1040
1041     /* Line 1 */
1042     header_rblbl_1_hb = gtk_hbox_new(FALSE, 0);
1043     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_1_hb, FALSE, FALSE, 2);
1044
1045     header_eth_rb = gtk_radio_button_new_with_label(NULL, "Ethernet");
1046 #if GTK_CHECK_VERSION(2,12,0)
1047     gtk_widget_set_tooltip_text(header_eth_rb, "Prefix an Ethernet header to the frames");
1048 #else
1049     gtk_tooltips_set_tip(tooltips, header_eth_rb, "Prefix an Ethernet header to the frames", NULL);
1050 #endif
1051     header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_eth_rb));
1052     g_signal_connect(header_eth_rb, "toggled", G_CALLBACK(header_eth_rb_toggle), header_frm);
1053     gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_eth_rb, FALSE, FALSE, 0);
1054
1055     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY, header_eth_rb);
1056     
1057     header_rblbl_1_lbl = gtk_label_new("  Ethertype (hex):");
1058     gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_rblbl_1_lbl, TRUE, TRUE, 0);
1059     gtk_misc_set_alignment(GTK_MISC(header_rblbl_1_lbl), 1.0f, 0.5f);
1060
1061     etype_te = gtk_entry_new();
1062 #if GTK_CHECK_VERSION(2,12,0)
1063     gtk_widget_set_tooltip_text(etype_te, "The type to set in the Ethernet header");
1064 #else
1065     gtk_tooltips_set_tip(tooltips, etype_te, "The type to set in the Ethernet header", NULL);
1066 #endif
1067     gtk_box_pack_end(GTK_BOX(header_rblbl_1_hb), etype_te, FALSE, FALSE, 0);
1068
1069     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_LBL_KEY, header_rblbl_1_lbl);
1070     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY, etype_te);
1071
1072     /* Line 2 */
1073     header_rblbl_2_hb = gtk_hbox_new(FALSE, 0);
1074     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_2_hb, FALSE, FALSE, 2);
1075
1076     header_ipv4_rb = gtk_radio_button_new_with_label(header_grp, "IPv4");
1077 #if GTK_CHECK_VERSION(2,12,0)
1078     gtk_widget_set_tooltip_text(header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames");
1079 #else
1080     gtk_tooltips_set_tip(tooltips, header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames", NULL);
1081 #endif
1082     header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_ipv4_rb));
1083     g_signal_connect(header_ipv4_rb, "toggled", G_CALLBACK(header_ipv4_rb_toggle), header_frm);
1084     gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_ipv4_rb, FALSE, FALSE, 0);
1085
1086     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY, header_ipv4_rb);
1087     
1088     header_rblbl_2_lbl = gtk_label_new("  Protocol (dec):");
1089     gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_rblbl_2_lbl, TRUE, TRUE, 0);
1090     gtk_misc_set_alignment(GTK_MISC(header_rblbl_2_lbl), 1.0f, 0.5f);
1091
1092     protocol_te = gtk_entry_new();
1093 #if GTK_CHECK_VERSION(2,12,0)
1094     gtk_widget_set_tooltip_text(protocol_te, "The protocol id to set in the IPv4 header");
1095 #else
1096     gtk_tooltips_set_tip(tooltips, protocol_te, "The protocol id to set in the IPv4 header", NULL);
1097 #endif
1098     gtk_box_pack_end(GTK_BOX(header_rblbl_2_hb), protocol_te, FALSE, FALSE, 0);
1099
1100     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_LBL_KEY, header_rblbl_2_lbl);
1101     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY, protocol_te);
1102
1103     /* Line 3 */
1104     header_rblbl_3_hb = gtk_hbox_new(FALSE, 0);
1105     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_3_hb, FALSE, FALSE, 2);
1106
1107     header_udp_rb = gtk_radio_button_new_with_label(header_grp, "UDP");
1108 #if GTK_CHECK_VERSION(2,12,0)
1109     gtk_widget_set_tooltip_text(header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames");
1110 #else
1111     gtk_tooltips_set_tip(tooltips, header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames", NULL);
1112 #endif
1113     header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_udp_rb));
1114     g_signal_connect(header_udp_rb, "toggled", G_CALLBACK(header_udp_rb_toggle), header_frm);
1115     gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_udp_rb, FALSE, FALSE, 0);
1116
1117     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY, header_udp_rb);
1118     
1119     header_rblbl_3_lbl = gtk_label_new("  Source port:");
1120     gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_rblbl_3_lbl, TRUE, TRUE, 0);
1121     gtk_misc_set_alignment(GTK_MISC(header_rblbl_3_lbl), 1.0f, 0.5f);
1122
1123     src_port_te = gtk_entry_new();
1124 #if GTK_CHECK_VERSION(2,12,0)
1125     gtk_widget_set_tooltip_text(src_port_te, "The source port to set in the UDP, TCP or SCTP header");
1126 #else
1127     gtk_tooltips_set_tip(tooltips, src_port_te, "The source port to set in the UDP, TCP or SCTP header", NULL);
1128 #endif
1129     gtk_box_pack_end(GTK_BOX(header_rblbl_3_hb), src_port_te, FALSE, FALSE, 0);
1130
1131     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_LBL_KEY, header_rblbl_3_lbl);
1132     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY, src_port_te);
1133
1134     /* Line 4 */
1135     header_rblbl_4_hb = gtk_hbox_new(FALSE, 0);
1136     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_4_hb, FALSE, FALSE, 2);
1137
1138     header_tcp_rb = gtk_radio_button_new_with_label(header_grp, "TCP");
1139 #if GTK_CHECK_VERSION(2,12,0)
1140     gtk_widget_set_tooltip_text(header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames");
1141 #else
1142     gtk_tooltips_set_tip(tooltips, header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames", NULL);
1143 #endif
1144     header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_tcp_rb));
1145     g_signal_connect(header_tcp_rb, "toggled", G_CALLBACK(header_tcp_rb_toggle), header_frm);
1146     gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_tcp_rb, FALSE, FALSE, 0);
1147
1148     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY, header_tcp_rb);
1149     
1150     header_rblbl_4_lbl = gtk_label_new("  Destination port:");
1151     gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_rblbl_4_lbl, TRUE, TRUE, 0);
1152     gtk_misc_set_alignment(GTK_MISC(header_rblbl_4_lbl), 1.0f, 0.5f);
1153
1154     dst_port_te = gtk_entry_new();
1155 #if GTK_CHECK_VERSION(2,12,0)
1156     gtk_widget_set_tooltip_text(dst_port_te, "The destination port to set in the UDP, TCP or SCTP header");
1157 #else
1158     gtk_tooltips_set_tip(tooltips, dst_port_te, "The destination port to set in the UDP, TCP or SCTP header", NULL);
1159 #endif
1160     gtk_box_pack_end(GTK_BOX(header_rblbl_4_hb), dst_port_te, FALSE, FALSE, 0);
1161
1162     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_LBL_KEY, header_rblbl_4_lbl);
1163     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY, dst_port_te);
1164
1165     /* Line 5 */
1166     header_rblbl_5_hb = gtk_hbox_new(FALSE, 0);
1167     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_5_hb, FALSE, FALSE, 2);
1168
1169     header_sctp_rb = gtk_radio_button_new_with_label(header_grp, "SCTP");
1170 #if GTK_CHECK_VERSION(2,12,0)
1171     gtk_widget_set_tooltip_text(header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames");
1172 #else
1173     gtk_tooltips_set_tip(tooltips, header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames", NULL);
1174 #endif
1175     header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_sctp_rb));
1176     g_signal_connect(header_sctp_rb, "toggled", G_CALLBACK(header_sctp_rb_toggle), header_frm);
1177     gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_sctp_rb, FALSE, FALSE, 0);
1178
1179     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY, header_sctp_rb);
1180         
1181     header_rblbl_5_lbl = gtk_label_new("  Tag:");
1182     gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_rblbl_5_lbl, TRUE, TRUE, 0);
1183     gtk_misc_set_alignment(GTK_MISC(header_rblbl_5_lbl), 1.0f, 0.5f);
1184
1185     tag_te = gtk_entry_new();
1186 #if GTK_CHECK_VERSION(2,12,0)
1187     gtk_widget_set_tooltip_text(tag_te, "The verification tag to set in the SCTP header");
1188 #else
1189     gtk_tooltips_set_tip(tooltips, tag_te, "The verification tag to set in the SCTP header", NULL);
1190 #endif
1191     gtk_box_pack_end(GTK_BOX(header_rblbl_5_hb), tag_te, FALSE, FALSE, 0);
1192
1193     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_LBL_KEY, header_rblbl_5_lbl);
1194     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY, tag_te);
1195
1196     /* Line 6 */
1197     header_rblbl_6_hb = gtk_hbox_new(FALSE, 0);
1198     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_6_hb, FALSE, FALSE, 2);
1199
1200     header_sctp_data_rb = gtk_radio_button_new_with_label(header_grp, "SCTP (DATA)");
1201 #if GTK_CHECK_VERSION(2,12,0)
1202     gtk_widget_set_tooltip_text(header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames");
1203 #else
1204     gtk_tooltips_set_tip(tooltips, header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames", NULL);
1205 #endif
1206     header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_sctp_data_rb));
1207     g_signal_connect(header_sctp_data_rb, "toggled", G_CALLBACK(header_sctp_data_rb_toggle), header_frm);
1208     gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_sctp_data_rb, FALSE, FALSE, 0);
1209
1210     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY, header_sctp_data_rb);
1211         
1212     header_rblbl_6_lbl = gtk_label_new("  PPI:");
1213     gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_rblbl_6_lbl, TRUE, TRUE, 0);
1214     gtk_misc_set_alignment(GTK_MISC(header_rblbl_6_lbl), 1.0f, 0.5f);
1215
1216     ppi_te = gtk_entry_new();
1217 #if GTK_CHECK_VERSION(2,12,0)
1218     gtk_widget_set_tooltip_text(ppi_te, "The payload protocol identifier to set in the SCTP DATA header");
1219 #else
1220     gtk_tooltips_set_tip(tooltips, ppi_te, "The payload protocol identifier to set in the SCTP DATA header", NULL);
1221 #endif
1222     gtk_box_pack_end(GTK_BOX(header_rblbl_6_hb), ppi_te, FALSE, FALSE, 0);
1223
1224     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_LBL_KEY, header_rblbl_6_lbl);
1225     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY, ppi_te);
1226
1227     /* Set sensitivity */
1228     g_signal_connect(header_cb, "toggled", G_CALLBACK(header_cb_toggle), header_frm);
1229     g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", header_frm);
1230
1231     g_signal_emit_by_name(G_OBJECT(header_eth_rb), "toggled", header_frm);
1232
1233     g_signal_connect(encap_co, "changed", G_CALLBACK(encap_co_changed), header_frm);
1234     gtk_combo_box_set_active(GTK_COMBO_BOX(encap_co), 0);
1235
1236     /* Frame length */
1237     framelen_hb = gtk_hbox_new(FALSE, 3);
1238     gtk_container_set_border_width(GTK_CONTAINER(framelen_hb), 3);
1239     gtk_box_pack_start(GTK_BOX(import_vb), framelen_hb, FALSE, FALSE, 0);
1240
1241     framelen_lbl = gtk_label_new("Max. frame length:");
1242     gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_lbl, FALSE, FALSE, 0);
1243
1244     framelen_te = gtk_entry_new();
1245 #if GTK_CHECK_VERSION(2,12,0)
1246     gtk_widget_set_tooltip_text(framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)");
1247 #else
1248     gtk_tooltips_set_tip(tooltips, framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)", NULL);
1249 #endif
1250     gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_te, FALSE, FALSE, 0);
1251
1252     g_object_set_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY, framelen_te);
1253     
1254     /* Setup the button row */
1255
1256     bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1257     gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
1258
1259     help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
1260     /* TODO: Create a Help chapter, make a proper reference, add it to help_dlg */
1261     g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_CONTENT);
1262 #if GTK_CHECK_VERSION(2,12,0)
1263     gtk_widget_set_tooltip_text(help_bt, "Show topic specific help");
1264 #else
1265     gtk_tooltips_set_tip(tooltips, help_bt, "Show topic specific help", NULL);
1266 #endif
1267     
1268     close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1269     window_set_cancel_button(main_w, close_bt, window_cancel_button_cb);
1270 #if GTK_CHECK_VERSION(2,12,0)
1271     gtk_widget_set_tooltip_text(close_bt, "Close this dialog");
1272 #else
1273     gtk_tooltips_set_tip(tooltips, close_bt, "Close this dialog", NULL);
1274 #endif
1275    
1276     ok_bt =  g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1277     g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_import_ok_cb), main_w);
1278     gtk_widget_grab_default(ok_bt);
1279 #if GTK_CHECK_VERSION(2,12,0)
1280     gtk_widget_set_tooltip_text(ok_bt, "Import the selected file into a temporary capture file");
1281 #else
1282     gtk_tooltips_set_tip(tooltips, ok_bt, "Import the selected file into a temporary capture file", NULL);
1283 #endif
1284
1285     /* Setup widget handling */
1286
1287     g_signal_connect(main_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1288     g_signal_connect(main_w, "destroy", G_CALLBACK(file_import_dlg_destroy_cb), NULL);
1289
1290     gtk_widget_show_all(main_w);
1291     window_present(main_w);
1292
1293     return main_w;
1294 }
1295
1296 void
1297 file_import_cmd_cb(GtkWidget *widget _U_)
1298 {
1299     /* Do we have an encapsulation type list? */
1300     if (!encap_list_store)
1301     {
1302         /* No. Create one. */
1303         create_encap_list_store();
1304     }
1305   
1306     /* Has a file import dialog already been opened? */
1307     if (file_import_dlg_w)
1308     {
1309         /* Yes. Just re-activate that dialog box. */
1310         reactivate_window(file_import_dlg_w);
1311     } else {
1312         /* No. Create one */
1313         file_import_dlg_w = file_import_dlg_new();
1314     }
1315
1316     return;
1317 }
1318