4 * $Id: menu.c,v 1.155 2004/02/01 15:36:15 ulfl Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
37 #include <epan/resolv.h>
39 #include "capture_dlg.h"
40 #include "color_dlg.h"
41 #include "filter_prefs.h"
45 #include "summary_dlg.h"
46 #include "prefs_dlg.h"
47 #include "packet_win.h"
49 #include "follow_dlg.h"
50 #include "decode_as_dlg.h"
52 #include "supported_protos_dlg.h"
53 #include "proto_dlg.h"
54 #include "proto_hier_stats_dlg.h"
56 #include <epan/plugins.h>
57 #include "tcp_graph.h"
58 #include <epan/epan_dissect.h>
59 #include "compat_macros.h"
61 #include "gtkglobals.h"
65 #include "../ipproto.h"
66 #include "packet_list.h"
69 #include "../ui_util.h"
70 #include "proto_draw.h"
71 #include "simple_dialog.h"
73 GtkWidget *popup_menu_object;
75 extern void savehex_cb(GtkWidget * w, gpointer data _U_);
78 clear_menu_recent_capture_file_cmd_cb(GtkWidget *w, gpointer unused _U_);
80 #define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
82 static void menus_init(void);
83 static void set_menu_sensitivity (GtkItemFactory *, const gchar *, gint);
84 static void main_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
85 static void filter_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
86 static void packet_list_show_cb(GtkWidget *w _U_, gpointer d _U_);
87 static void tree_view_show_cb(GtkWidget *w _U_, gpointer d _U_);
88 static void byte_view_show_cb(GtkWidget *w _U_, gpointer d _U_);
89 static void statusbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
90 static void timestamp_absolute_cb(GtkWidget *w _U_, gpointer d _U_);
91 static void timestamp_absolute_date_cb(GtkWidget *w _U_, gpointer d _U_);
92 static void timestamp_relative_cb(GtkWidget *w _U_, gpointer d _U_);
93 static void timestamp_delta_cb(GtkWidget *w _U_, gpointer d _U_);
94 static void name_resolution_mac_cb(GtkWidget *w _U_, gpointer d _U_);
95 static void name_resolution_network_cb(GtkWidget *w _U_, gpointer d _U_);
96 static void name_resolution_transport_cb(GtkWidget *w _U_, gpointer d _U_);
97 static void auto_scroll_live_cb(GtkWidget *w _U_, gpointer d _U_);
99 /* This is the GtkItemFactoryEntry structure used to generate new menus.
100 Item 1: The menu path. The letter after the underscore indicates an
101 accelerator key once the menu is open.
102 Item 2: The accelerator key for the entry
103 Item 3: The callback function.
104 Item 4: The callback action. This changes the parameters with
105 which the function is called. The default is 0.
106 Item 5: The item type, used to define what kind of an item it is.
107 Here are the possible values:
111 "<Title>" -> create a title item
112 "<Item>" -> create a simple item
113 "<ImageItem>" -> create an item holding an image (gtk2)
114 "<StockItem>" -> create an item holding a stock image (gtk2)
115 "<CheckItem>" -> create a check item
116 "<ToggleItem>" -> create a toggle item
117 "<RadioItem>" -> create a radio item
118 <path> -> path of a radio item to link against
119 "<Separator>" -> create a separator
120 "<Tearoff>" -> create a tearoff separator (gtk2)
121 "<Branch>" -> create an item to hold sub items (optional)
122 "<LastBranch>" -> create a right justified branch
123 Item 6: extra data needed for ImageItem and StockItem (gtk2)
127 static GtkItemFactoryEntry menu_items[] =
129 ITEM_FACTORY_ENTRY("/_File", NULL, NULL, 0, "<Branch>", NULL),
130 ITEM_FACTORY_STOCK_ENTRY("/File/_Open...", "<control>O", file_open_cmd_cb,
132 ITEM_FACTORY_ENTRY("/File/Open _Recent", NULL, NULL, 0, "<Branch>", NULL),
133 ITEM_FACTORY_STOCK_ENTRY("/File/_Close", "<control>W", file_close_cmd_cb,
135 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
136 ITEM_FACTORY_STOCK_ENTRY("/File/_Save", "<control>S", file_save_cmd_cb,
138 ITEM_FACTORY_STOCK_ENTRY("/File/Save _As...", "<shift><control>S", file_save_as_cmd_cb,
139 0, GTK_STOCK_SAVE_AS),
140 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
141 ITEM_FACTORY_ENTRY("/File/_Export", NULL, NULL, 0, "<Branch>", NULL),
142 ITEM_FACTORY_ENTRY("/File/_Export/_Selected Packet Bytes...", "<control>H", savehex_cb,
144 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
145 ITEM_FACTORY_STOCK_ENTRY("/File/_Print...", "<control>P", file_print_cmd_cb,
147 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
148 ITEM_FACTORY_STOCK_ENTRY("/File/_Quit", "<control>Q", file_quit_cmd_cb,
150 ITEM_FACTORY_ENTRY("/_Edit", NULL, NULL, 0, "<Branch>", NULL),
152 /* Un-#if this when we actually implement Cut/Copy/Paste. */
153 ITEM_FACTORY_STOCK_ENTRY("/Edit/Cut", "<control>X", NULL,
155 ITEM_FACTORY_STOCK_ENTRY("/Edit/Copy", "<control>C", NULL,
157 ITEM_FACTORY_STOCK_ENTRY("/Edit/Paste", "<control>V", NULL,
159 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>"),
161 ITEM_FACTORY_STOCK_ENTRY("/Edit/_Find Packet...", "<control>F",
162 find_frame_cb, 0, GTK_STOCK_FIND),
163 ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Ne_xt", "<control>N", find_next_cb,
164 0, GTK_STOCK_GO_FORWARD),
165 ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Pre_vious", "<control>B",
166 find_previous_cb, 0, GTK_STOCK_GO_BACK),
167 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
168 ITEM_FACTORY_STOCK_ENTRY("/Edit/Go To Firs_t Packet", NULL,
169 goto_top_frame_cb, 0, GTK_STOCK_GOTO_TOP),
170 ITEM_FACTORY_STOCK_ENTRY("/Edit/Go To _Last Packet", NULL,
171 goto_bottom_frame_cb, 0, GTK_STOCK_GOTO_BOTTOM),
172 ITEM_FACTORY_STOCK_ENTRY("/Edit/_Go To Packet...", "<control>G",
173 goto_frame_cb, 0, GTK_STOCK_JUMP_TO),
174 ITEM_FACTORY_ENTRY("/Edit/Go To _Corresponding Packet", NULL, goto_framenum_cb,
176 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
177 ITEM_FACTORY_ENTRY("/Edit/Time _Reference", NULL, NULL, 0, "<Branch>", NULL),
178 ITEM_FACTORY_ENTRY("/Edit/Time Reference/Set Time Reference (toggle)", "<control>T", reftime_frame_cb, 0, NULL, NULL),
179 ITEM_FACTORY_ENTRY("/Edit/Time Reference/Find Next", NULL, reftime_frame_cb, 1, NULL, NULL),
180 ITEM_FACTORY_ENTRY("/Edit/Time Reference/Find Previous", NULL, reftime_frame_cb, 2, NULL, NULL),
181 ITEM_FACTORY_ENTRY("/Edit/_Mark Packet", "<control>M", mark_frame_cb,
183 ITEM_FACTORY_ENTRY("/Edit/Mark _All Packets", NULL, mark_all_frames_cb,
185 ITEM_FACTORY_ENTRY("/Edit/_Unmark All Packets", NULL, unmark_all_frames_cb,
187 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
188 ITEM_FACTORY_STOCK_ENTRY("/Edit/_Preferences...", "<shift><control>P", prefs_cb,
189 0, GTK_STOCK_PREFERENCES),
190 ITEM_FACTORY_ENTRY("/_View", NULL, NULL, 0, "<Branch>", NULL),
191 ITEM_FACTORY_ENTRY("/View/_Show", NULL, NULL, 0, "<Branch>", NULL),
192 ITEM_FACTORY_ENTRY("/View/Show/Main Toolbar", NULL, main_toolbar_show_cb, 0, "<CheckItem>", NULL),
193 ITEM_FACTORY_ENTRY("/View/Show/Filter Toolbar", NULL, filter_toolbar_show_cb, 0, "<CheckItem>", NULL),
194 ITEM_FACTORY_ENTRY("/View/Show/<separator>", NULL, NULL, 0, "<Separator>", NULL),
195 ITEM_FACTORY_ENTRY("/View/Show/Packet List", NULL, packet_list_show_cb, 0, "<CheckItem>", NULL),
196 ITEM_FACTORY_ENTRY("/View/Show/Packet Details", NULL, tree_view_show_cb, 0, "<CheckItem>", NULL),
197 ITEM_FACTORY_ENTRY("/View/Show/Packet Bytes", NULL, byte_view_show_cb, 0, "<CheckItem>", NULL),
198 ITEM_FACTORY_ENTRY("/View/Show/<separator>", NULL, NULL, 0, "<Separator>", NULL),
199 ITEM_FACTORY_ENTRY("/View/Show/Status Bar", NULL, statusbar_show_cb, 0, "<CheckItem>", NULL),
200 ITEM_FACTORY_ENTRY("/View/_Time Display Format", NULL, NULL, 0, "<Branch>", NULL),
201 ITEM_FACTORY_ENTRY("/View/Time Display Format/Time of Day", NULL, timestamp_absolute_cb,
202 0, "<RadioItem>", NULL),
203 ITEM_FACTORY_ENTRY("/View/Time Display Format/Date and Time of Day", NULL, timestamp_absolute_date_cb,
204 0, "/View/Time Display Format/Time of Day", NULL),
205 ITEM_FACTORY_ENTRY("/View/Time Display Format/Seconds Since Beginning of Capture", NULL, timestamp_relative_cb,
206 0, "/View/Time Display Format/Time of Day", NULL),
207 ITEM_FACTORY_ENTRY("/View/Time Display Format/Seconds Since Previous Packet", NULL, timestamp_delta_cb,
208 0, "/View/Time Display Format/Time of Day", NULL),
209 ITEM_FACTORY_ENTRY("/View/_Name Resolution", NULL, NULL, 0, "<Branch>", NULL),
210 ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _MAC Layer", NULL, name_resolution_mac_cb, 0, "<CheckItem>", NULL),
211 ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Network Layer", NULL, name_resolution_mac_cb, 0, "<CheckItem>", NULL),
212 ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Transport Layer", NULL, name_resolution_transport_cb, 0, "<CheckItem>", NULL),
213 ITEM_FACTORY_ENTRY("/View/Auto Scroll in Live Capture", NULL, auto_scroll_live_cb, 0, "<CheckItem>", NULL),
214 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
215 ITEM_FACTORY_STOCK_ENTRY("/View/Zoom In", "<control>plus", view_zoom_in_cb,
216 0, GTK_STOCK_ZOOM_IN),
217 ITEM_FACTORY_STOCK_ENTRY("/View/Zoom Out", "<control>minus", view_zoom_out_cb,
218 0, GTK_STOCK_ZOOM_OUT),
219 ITEM_FACTORY_STOCK_ENTRY("/View/Normal Size", "<control>equal", view_zoom_100_cb,
220 0, GTK_STOCK_ZOOM_100),
221 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
222 ITEM_FACTORY_ENTRY("/View/Collapse _All", NULL, collapse_all_cb,
224 ITEM_FACTORY_ENTRY("/View/_Expand All", NULL, expand_all_cb,
226 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
227 ITEM_FACTORY_STOCK_ENTRY("/View/_Coloring Rules...", NULL, color_display_cb,
228 0, GTK_STOCK_SELECT_COLOR),
229 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
230 ITEM_FACTORY_ENTRY("/View/_Show Packet In New Window", NULL,
231 new_window_cb, 0, NULL, NULL),
232 ITEM_FACTORY_STOCK_ENTRY("/View/_Reload", "<control>R", file_reload_cmd_cb,
233 0, GTK_STOCK_REFRESH),
235 ITEM_FACTORY_ENTRY("/_Capture", NULL, NULL, 0, "<Branch>", NULL),
236 ITEM_FACTORY_STOCK_ENTRY("/Capture/_Start...", "<control>K",
237 capture_prep_cb, 0, ETHEREAL_STOCK_CAPTURE_START),
238 ITEM_FACTORY_STOCK_ENTRY("/Capture/S_top", "<control>E", capture_stop_cb,
240 ITEM_FACTORY_STOCK_ENTRY("/Capture/_Capture Filters...", NULL, cfilter_dialog_cb,
241 0, ETHEREAL_STOCK_CAPTURE_FILTER),
242 #endif /* HAVE_LIBPCAP */
243 ITEM_FACTORY_ENTRY("/_Analyze", NULL, NULL, 0, "<Branch>", NULL),
244 ITEM_FACTORY_STOCK_ENTRY("/Analyze/_Display Filters...", NULL, dfilter_dialog_cb,
245 0, ETHEREAL_STOCK_DISPLAY_FILTER),
246 ITEM_FACTORY_ENTRY("/Analyze/_Match", NULL, NULL, 0, "<Branch>", NULL),
247 ITEM_FACTORY_ENTRY("/Analyze/Match/_Selected", NULL,
248 match_selected_cb_replace_ptree, 0, NULL, NULL),
249 ITEM_FACTORY_ENTRY("/Analyze/Match/_Not Selected", NULL,
250 match_selected_cb_not_ptree, 0, NULL, NULL),
251 ITEM_FACTORY_ENTRY("/Analyze/Match/_And Selected", NULL,
252 match_selected_cb_and_ptree, 0, NULL, NULL),
253 ITEM_FACTORY_ENTRY("/Analyze/Match/_Or Selected", NULL,
254 match_selected_cb_or_ptree, 0, NULL, NULL),
255 ITEM_FACTORY_ENTRY("/Analyze/Match/A_nd Not Selected", NULL,
256 match_selected_cb_and_ptree_not, 0, NULL, NULL),
257 ITEM_FACTORY_ENTRY("/Analyze/Match/O_r Not Selected", NULL,
258 match_selected_cb_or_ptree_not, 0, NULL, NULL),
259 ITEM_FACTORY_ENTRY("/Analyze/_Prepare", NULL, NULL, 0, "<Branch>", NULL),
260 ITEM_FACTORY_ENTRY("/Analyze/Prepare/_Selected", NULL,
261 prepare_selected_cb_replace_ptree, 0, NULL, NULL),
262 ITEM_FACTORY_ENTRY("/Analyze/Prepare/_Not Selected", NULL,
263 prepare_selected_cb_not_ptree, 0, NULL, NULL),
264 ITEM_FACTORY_ENTRY("/Analyze/Prepare/_And Selected", NULL,
265 prepare_selected_cb_and_ptree, 0, NULL, NULL),
266 ITEM_FACTORY_ENTRY("/Analyze/Prepare/_Or Selected", NULL,
267 prepare_selected_cb_or_ptree, 0, NULL, NULL),
268 ITEM_FACTORY_ENTRY("/Analyze/Prepare/A_nd Not Selected", NULL,
269 prepare_selected_cb_and_ptree_not, 0, NULL, NULL),
270 ITEM_FACTORY_ENTRY("/Analyze/Prepare/O_r Not Selected", NULL,
271 prepare_selected_cb_or_ptree_not, 0, NULL, NULL),
272 ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL),
273 ITEM_FACTORY_ENTRY("/Analyze/_Enabled Protocols...", "<shift><control>R", proto_cb, 0, NULL, NULL),
274 ITEM_FACTORY_ENTRY("/Analyze/Decode _As...", NULL, decode_as_cb,
276 ITEM_FACTORY_ENTRY("/Analyze/_User Specified Decodes...", NULL,
277 decode_show_cb, 0, NULL, NULL),
278 ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL),
279 ITEM_FACTORY_ENTRY("/Analyze/_Follow TCP Stream", NULL, follow_stream_cb,
281 /* {"/Analyze/Graph", NULL, NULL, 0, NULL}, future use */
282 ITEM_FACTORY_ENTRY("/Analyze/_TCP Stream Analysis", NULL, NULL,
283 0, "<Branch>", NULL),
284 ITEM_FACTORY_ENTRY("/Analyze/TCP Stream Analysis/Time-Sequence Graph (Stevens)",
285 NULL, tcp_graph_cb, 0, NULL, NULL),
286 ITEM_FACTORY_ENTRY("/Analyze/TCP Stream Analysis/Time-Sequence Graph (tcptrace)",
287 NULL, tcp_graph_cb, 1, NULL, NULL),
288 ITEM_FACTORY_ENTRY("/Analyze/TCP Stream Analysis/Throughput Graph", NULL,
289 tcp_graph_cb, 2, NULL, NULL),
290 ITEM_FACTORY_ENTRY("/Analyze/TCP Stream Analysis/Round Trip Time Graph", NULL,
291 tcp_graph_cb, 3, NULL, NULL),
292 ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL),
293 ITEM_FACTORY_ENTRY("/Analyze/Summar_y", NULL, summary_open_cb, 0, NULL, NULL),
294 ITEM_FACTORY_ENTRY("/Analyze/Protocol _Hierarchy Statistics", NULL,
295 proto_hier_stats_cb, 0, NULL, NULL),
296 ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "<Branch>", NULL),
297 ITEM_FACTORY_STOCK_ENTRY("/Help/_Contents", "F1", help_cb, 0, GTK_STOCK_HELP),
298 ITEM_FACTORY_ENTRY("/Help/_Supported Protocols", NULL, supported_cb, 0, NULL, NULL),
299 ITEM_FACTORY_ENTRY("/Help/<separator>", NULL, NULL, 0, "<Separator>", NULL),
301 ITEM_FACTORY_ENTRY("/Help/About _Plugins", NULL, tools_plugins_cmd_cb,
303 #endif /* HAVE_PLUGINS */
304 ITEM_FACTORY_ENTRY("/Help/_About Ethereal", NULL, about_ethereal,
309 /* calculate the number of menu_items */
310 static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
312 /* packet list popup */
313 static GtkItemFactoryEntry packet_list_menu_items[] =
315 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
317 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
318 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
320 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
321 ITEM_FACTORY_ENTRY("/Mark Packet", NULL, mark_frame_cb, 0, NULL, NULL),
322 ITEM_FACTORY_ENTRY("/Time Reference", NULL, NULL, 0, "<Branch>", NULL),
323 ITEM_FACTORY_ENTRY("/Time Reference/Set Time Reference (toggle)", NULL, reftime_frame_cb, 0, NULL, NULL),
324 ITEM_FACTORY_ENTRY("/Time Reference/Find Next", NULL, reftime_frame_cb, 1, NULL, NULL),
325 ITEM_FACTORY_ENTRY("/Time Reference/Find Previous", NULL, reftime_frame_cb, 2, NULL, NULL),
326 ITEM_FACTORY_ENTRY("/Match", NULL, NULL, 0, "<Branch>", NULL),
327 ITEM_FACTORY_ENTRY("/Match/_Selected", NULL,
328 match_selected_cb_replace_plist, 0, NULL, NULL),
329 ITEM_FACTORY_ENTRY("/Match/_Not Selected", NULL,
330 match_selected_cb_not_plist, 0, NULL, NULL),
331 ITEM_FACTORY_ENTRY("/Match/_And Selected", NULL,
332 match_selected_cb_and_plist, 0, NULL, NULL),
333 ITEM_FACTORY_ENTRY("/Match/_Or Selected", NULL, match_selected_cb_or_plist,
335 ITEM_FACTORY_ENTRY("/Match/A_nd Not Selected", NULL,
336 match_selected_cb_and_plist_not, 0, NULL, NULL),
337 ITEM_FACTORY_ENTRY("/Match/O_r Not Selected", NULL,
338 match_selected_cb_or_plist_not, 0, NULL, NULL),
339 ITEM_FACTORY_ENTRY("/Prepare", NULL, NULL, 0, "<Branch>", NULL),
340 ITEM_FACTORY_ENTRY("/Prepare/_Selected", NULL,
341 prepare_selected_cb_replace_plist, 0, NULL, NULL),
342 ITEM_FACTORY_ENTRY("/Prepare/_Not Selected", NULL,
343 prepare_selected_cb_not_plist, 0, NULL, NULL),
344 ITEM_FACTORY_ENTRY("/Prepare/_And Selected", NULL,
345 prepare_selected_cb_and_plist, 0, NULL, NULL),
346 ITEM_FACTORY_ENTRY("/Prepare/_Or Selected", NULL,
347 prepare_selected_cb_or_plist, 0, NULL, NULL),
348 ITEM_FACTORY_ENTRY("/Prepare/A_nd Not Selected", NULL,
349 prepare_selected_cb_and_plist_not, 0, NULL, NULL),
350 ITEM_FACTORY_ENTRY("/Prepare/O_r Not Selected", NULL,
351 prepare_selected_cb_or_plist_not, 0, NULL, NULL),
352 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
353 ITEM_FACTORY_ENTRY("/Coloring Rules...", NULL, color_display_cb,
355 ITEM_FACTORY_ENTRY("/Print...", NULL, file_print_cmd_cb, 0, NULL, NULL),
356 ITEM_FACTORY_ENTRY("/Show Packet In New Window", NULL, new_window_cb,
360 static GtkItemFactoryEntry tree_view_menu_items[] =
362 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
364 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
365 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
367 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
368 ITEM_FACTORY_ENTRY("/_Resolve Name", NULL, resolve_name_cb, 0, NULL, NULL),
369 ITEM_FACTORY_ENTRY("/_Go To Corresponding Packet", NULL, goto_framenum_cb, 0, NULL, NULL),
370 ITEM_FACTORY_ENTRY("/_Export Selected Packet Bytes...", NULL, savehex_cb,
372 ITEM_FACTORY_ENTRY("/Protocol Properties...", NULL, properties_cb,
374 ITEM_FACTORY_ENTRY("/Match", NULL, NULL, 0, "<Branch>", NULL),
375 ITEM_FACTORY_ENTRY("/Match/_Selected", NULL,
376 match_selected_cb_replace_ptree, 0, NULL, NULL),
377 ITEM_FACTORY_ENTRY("/Match/_Not Selected", NULL,
378 match_selected_cb_not_ptree, 0, NULL, NULL),
379 ITEM_FACTORY_ENTRY("/Match/_And Selected", NULL,
380 match_selected_cb_and_ptree, 0, NULL, NULL),
381 ITEM_FACTORY_ENTRY("/Match/_Or Selected", NULL, match_selected_cb_or_ptree,
383 ITEM_FACTORY_ENTRY("/Match/A_nd Not Selected", NULL,
384 match_selected_cb_and_ptree_not, 0, NULL, NULL),
385 ITEM_FACTORY_ENTRY("/Match/O_r Not Selected", NULL,
386 match_selected_cb_or_ptree_not, 0, NULL, NULL),
387 ITEM_FACTORY_ENTRY("/Prepare", NULL, NULL, 0, "<Branch>", NULL),
388 ITEM_FACTORY_ENTRY("/Prepare/_Selected", NULL,
389 prepare_selected_cb_replace_ptree, 0, NULL, NULL),
390 ITEM_FACTORY_ENTRY("/Prepare/_Not Selected", NULL,
391 prepare_selected_cb_not_ptree, 0, NULL, NULL),
392 ITEM_FACTORY_ENTRY("/Prepare/_And Selected", NULL,
393 prepare_selected_cb_and_ptree, 0, NULL, NULL),
394 ITEM_FACTORY_ENTRY("/Prepare/_Or Selected", NULL,
395 prepare_selected_cb_or_ptree, 0, NULL, NULL),
396 ITEM_FACTORY_ENTRY("/Prepare/A_nd Not Selected", NULL,
397 prepare_selected_cb_and_ptree_not, 0, NULL, NULL),
398 ITEM_FACTORY_ENTRY("/Prepare/O_r Not Selected", NULL,
399 prepare_selected_cb_or_ptree_not, 0, NULL, NULL),
400 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
401 ITEM_FACTORY_ENTRY("/Collapse All", NULL, collapse_all_cb, 0, NULL, NULL),
402 ITEM_FACTORY_ENTRY("/Expand All", NULL, expand_all_cb, 0, NULL, NULL)
405 static GtkItemFactoryEntry hexdump_menu_items[] =
407 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
409 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
410 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
412 ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb,
416 static int initialize = TRUE;
417 static GtkItemFactory *main_menu_factory = NULL;
418 static GtkItemFactory *packet_list_menu_factory = NULL;
419 static GtkItemFactory *tree_view_menu_factory = NULL;
420 static GtkItemFactory *hexdump_menu_factory = NULL;
422 static GSList *popup_menu_list = NULL;
424 static GtkAccelGroup *grp;
427 main_menu_new(GtkAccelGroup ** table) {
430 grp = gtk_accel_group_new();
435 menubar = main_menu_factory->widget;
450 packet_list_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
451 popup_menu_object = gtk_menu_new();
452 gtk_item_factory_create_items_ac(packet_list_menu_factory, sizeof(packet_list_menu_items)/sizeof(packet_list_menu_items[0]), packet_list_menu_items, popup_menu_object, 2);
453 OBJECT_SET_DATA(popup_menu_object, PM_PACKET_LIST_KEY,
454 packet_list_menu_factory->widget);
455 popup_menu_list = g_slist_append((GSList *)popup_menu_list, packet_list_menu_factory);
457 tree_view_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
458 gtk_item_factory_create_items_ac(tree_view_menu_factory, sizeof(tree_view_menu_items)/sizeof(tree_view_menu_items[0]), tree_view_menu_items, popup_menu_object, 2);
459 OBJECT_SET_DATA(popup_menu_object, PM_TREE_VIEW_KEY,
460 tree_view_menu_factory->widget);
461 popup_menu_list = g_slist_append((GSList *)popup_menu_list, tree_view_menu_factory);
463 hexdump_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
464 gtk_item_factory_create_items_ac(hexdump_menu_factory, sizeof(hexdump_menu_items)/sizeof(hexdump_menu_items[0]), hexdump_menu_items, popup_menu_object, 2);
465 OBJECT_SET_DATA(popup_menu_object, PM_HEXDUMP_KEY,
466 hexdump_menu_factory->widget);
467 popup_menu_list = g_slist_append((GSList *)popup_menu_list, hexdump_menu_factory);
470 main_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", grp);
471 gtk_item_factory_create_items_ac(main_menu_factory, nmenu_items, menu_items, NULL, 2);
472 register_all_tap_menus(); /* must be done after creating the main menu */
474 /* Initialize enabled/disabled state of menu items */
475 set_menus_for_unsaved_capture_file(FALSE);
476 set_menus_for_capture_file(FALSE);
478 /* Un-#if this when we actually implement Cut/Copy/Paste.
479 Then make sure you enable them when they can be done. */
480 set_menu_sensitivity(main_menu_factory, "/Edit/Cut", FALSE);
481 set_menu_sensitivity(main_menu_factory, "/Edit/Copy", FALSE);
482 set_menu_sensitivity(main_menu_factory, "/Edit/Paste", FALSE);
485 set_menus_for_captured_packets(FALSE);
486 set_menus_for_selected_packet(&cfile);
487 set_menus_for_selected_tree_row(&cfile);
489 /* init with an empty recent files list */
490 clear_menu_recent_capture_file_cmd_cb(NULL, NULL);
494 typedef struct _menu_item {
497 gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *);
498 gboolean (*selected_tree_row_enabled)(field_info *);
499 struct _menu_item *parent;
500 struct _menu_item *children;
501 struct _menu_item *next;
504 static menu_item_t tap_menu_tree_root;
507 * Add a new menu item for a tap.
508 * This must be called after we've created the main menu, so it can't
509 * be called from the routine that registers taps - we have to introduce
510 * another per-tap registration routine.
512 * "callback" gets called when the menu item is selected; it should do
513 * the work of creating the tap window.
515 * "selected_packet_enabled" gets called by "set_menus_for_selected_packet()";
516 * it's passed a Boolean that's TRUE if a packet is selected and FALSE
517 * otherwise, and should return TRUE if the tap will work now (which
518 * might depend on whether a packet is selected and, if one is, on the
519 * packet) and FALSE if not.
521 * "selected_tree_row_enabled" gets called by
522 * "set_menus_for_selected_tree_row()"; it's passed a Boolean that's TRUE if
523 * a protocol tree row is selected and FALSE otherwise, and should return
524 * TRUE if the tap will work now (which might depend on whether a tree row
525 * is selected and, if one is, on the tree row) and FALSE if not.
528 register_tap_menu_item(char *name, GtkItemFactoryCallback callback,
529 gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *),
530 gboolean (*selected_tree_row_enabled)(field_info *),
531 gpointer callback_data)
533 static const char toolspath[] = "/Analyze/";
537 GtkItemFactoryEntry *entry;
538 menu_item_t *curnode, *child;
541 * The menu path must be relative.
543 g_assert(*name != '/');
546 * Create any submenus required.
548 curnode = &tap_menu_tree_root;
550 while ((p = strchr(p, '/')) != NULL) {
552 * OK, everything between "name" and "p" is
553 * a menu relative subtree into which the menu item
556 * Construct the absolute path name of that subtree.
558 menupathlen = sizeof toolspath + (p - name);
559 menupath = g_malloc(menupathlen);
560 strcpy(menupath, toolspath);
561 strncat(menupath, name, p - name);
564 * Does there exist an entry with that path at this
565 * level of the Analyze menu tree?
567 for (child = curnode->children; child != NULL;
568 child = child->next) {
569 if (strcmp(child->name, menupath) == 0)
574 * No. Create such an item as a subtree, and
575 * add it to the Tools menu tree.
577 entry = g_malloc0(sizeof (GtkItemFactoryEntry));
578 entry->path = menupath;
579 entry->item_type = "<Branch>";
580 gtk_item_factory_create_item(main_menu_factory, entry,
582 set_menu_sensitivity(main_menu_factory, menupath,
583 FALSE); /* no children yet */
584 child = g_malloc(sizeof (menu_item_t));
585 child->name = menupath;
586 child->selected_packet_enabled = NULL;
587 child->selected_tree_row_enabled = NULL;
588 child->enabled = FALSE; /* no children yet */
589 child->parent = curnode;
590 child->children = NULL;
591 child->next = curnode->children;
592 curnode->children = child;
595 * Yes. We don't need "menupath" any more.
602 * Skip over the '/' we found.
608 * Construct the main menu path for the menu item.
610 * "sizeof toolspath" includes the trailing '\0', so the sum
611 * of that and the length of "name" is enough to hold a string
612 * containing their concatenation.
614 menupathlen = sizeof toolspath + strlen(name);
615 menupath = g_malloc(menupathlen);
616 strcpy(menupath, toolspath);
617 strcat(menupath, name);
620 * Construct an item factory entry for the item, and add it to
623 entry = g_malloc0(sizeof (GtkItemFactoryEntry));
624 entry->path = menupath;
625 entry->callback = callback;
626 gtk_item_factory_create_item(main_menu_factory, entry, callback_data, 2);
627 set_menu_sensitivity(main_menu_factory, menupath, FALSE); /* no capture file yet */
628 child = g_malloc(sizeof (menu_item_t));
629 child->name = menupath;
630 child->enabled = FALSE; /* no capture file yet, hence no taps yet */
631 child->selected_packet_enabled = selected_packet_enabled;
632 child->selected_tree_row_enabled = selected_tree_row_enabled;
633 child->parent = curnode;
634 child->children = NULL;
635 child->next = curnode->children;
636 curnode->children = child;
640 * Enable/disable menu sensitivity.
643 set_menu_sensitivity(GtkItemFactory *ifactory, const gchar *path, gint val)
646 GtkWidget *menu_item;
651 /* the underscore character regularly confuses things, as it will prevent finding
652 * the menu_item, so it has to be removed first */
653 dup = g_strdup(path);
664 if (ifactory == NULL) {
666 * Do it for all pop-up menus.
668 for (menu_list = popup_menu_list; menu_list != NULL;
669 menu_list = g_slist_next(menu_list))
670 set_menu_sensitivity(menu_list->data, dup, val);
673 * Do it for that particular menu.
675 if ((menu_item = gtk_item_factory_get_widget(ifactory, dup)) != NULL) {
676 if (GTK_IS_MENU(menu_item)) {
678 * "dup" refers to a submenu; "gtk_item_factory_get_widget()"
679 * gets the menu, not the item that, when selected, pops up
682 * We have to change the latter item's sensitivity, so that
683 * it shows up normally if sensitive and grayed-out if
686 menu_item = gtk_menu_get_attach_widget(GTK_MENU(menu_item));
688 gtk_widget_set_sensitive(menu_item, val);
690 /* be sure this menu item *is* existing */
691 g_assert_not_reached();
699 set_menu_object_data_meat(GtkItemFactory *ifactory, gchar *path, gchar *key, gpointer data)
701 GtkWidget *menu = NULL;
703 if ((menu = gtk_item_factory_get_widget(ifactory, path)) != NULL)
704 OBJECT_SET_DATA(menu, key, data);
708 set_menu_object_data (gchar *path, gchar *key, gpointer data) {
709 GSList *menu_list = popup_menu_list;
710 gchar *shortpath = strrchr(path, '/');
712 set_menu_object_data_meat(main_menu_factory, path, key, data);
713 while (menu_list != NULL) {
714 set_menu_object_data_meat(menu_list->data, shortpath, key, data);
715 menu_list = g_slist_next(menu_list);
720 /* Recently used capture files submenu:
721 * Submenu containing the recently used capture files.
722 * The capture filenames are always kept with the absolute path, to be independant
723 * of the current path.
724 * They are only stored inside the labels of the submenu (no separate list). */
726 #define MENU_RECENT_FILES_PATH "/File/Open Recent"
727 #define MENU_RECENT_FILES_KEY "Recent File Name"
730 update_menu_recent_capture_file1(GtkWidget *widget, gpointer cnt) {
731 gchar *widget_cf_name;
733 widget_cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY);
735 /* if this menu item is a file, count it */
736 if (widget_cf_name) {
742 /* update the menu */
744 update_menu_recent_capture_file(GtkWidget *submenu_recent_files) {
747 gtk_container_foreach(GTK_CONTAINER(submenu_recent_files),
748 update_menu_recent_capture_file1, &cnt);
750 /* make parent menu item sensitive only, if we have any valid files in the list */
751 set_menu_sensitivity(main_menu_factory, MENU_RECENT_FILES_PATH, cnt);
755 /* remove the capture filename from the "Recent Files" menu */
757 remove_menu_recent_capture_file(GtkWidget *widget, gpointer unused _U_) {
758 GtkWidget *submenu_recent_files;
759 gchar *widget_cf_name;
762 widget_cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY);
763 g_free(widget_cf_name);
765 /* get the submenu container item */
766 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
768 /* XXX: is this all we need to do, to free the menu item and its label?
769 The reference count of widget will go to 0, so it'll be freed;
770 will that free the label? */
771 gtk_container_remove(GTK_CONTAINER(submenu_recent_files), widget);
775 /* callback, if the user pushed the <clear file list> item */
777 clear_menu_recent_capture_file_cmd_cb(GtkWidget *w _U_, gpointer unused _U_) {
778 GtkWidget *submenu_recent_files;
781 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
783 gtk_container_foreach(GTK_CONTAINER(submenu_recent_files),
784 remove_menu_recent_capture_file, NULL);
786 update_menu_recent_capture_file(submenu_recent_files);
790 /* callback, if the user pushed a recent file submenu item */
792 menu_open_recent_file_cmd(GtkWidget *w)
794 GtkWidget *submenu_recent_files;
795 GtkWidget *menu_item_child;
799 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
801 /* get capture filename from the menu item label */
802 menu_item_child = (GTK_BIN(w))->child;
803 gtk_label_get(GTK_LABEL(menu_item_child), &cf_name);
805 /* open and read the capture file (this will close an existing file) */
806 if ((err = cf_open(cf_name, FALSE, &cfile)) == 0) {
809 /* the capture file isn't existing any longer, remove menu item */
810 /* XXX: ask user to remove item, it's maybe only a temporary problem */
811 remove_menu_recent_capture_file(w, NULL);
814 update_menu_recent_capture_file(submenu_recent_files);
817 static void menu_open_recent_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
821 /* save file first */
822 file_save_as_cmd(after_save_open_recent_file, data);
825 menu_open_recent_file_cmd(data);
827 case(ESD_BTN_CANCEL):
830 g_assert_not_reached();
835 menu_open_recent_file_cmd_cb(GtkWidget *widget, gpointer data _U_) {
839 if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
840 /* user didn't saved his current file, ask him */
841 dialog = simple_dialog(ESD_TYPE_WARN | ESD_TYPE_MODAL,
842 ESD_BTN_YES | ESD_BTN_NO | ESD_BTN_CANCEL,
843 PRIMARY_TEXT_START "Save capture file before opening a new one?" PRIMARY_TEXT_END "\n\n"
844 "If you open a new capture file without saving, your current capture data will be discarded.");
845 simple_dialog_set_cb(dialog, menu_open_recent_file_answered_cb, widget);
848 menu_open_recent_file_cmd(widget);
852 /* add the capture filename (with an absolute path) to the "Recent Files" menu */
854 add_menu_recent_capture_file_absolute(gchar *cf_name) {
855 GtkWidget *submenu_recent_files;
856 GList *menu_item_list;
858 gchar *widget_cf_name;
859 GtkWidget *menu_item;
863 /* get the submenu container item */
864 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
866 /* convert container to a GList */
867 menu_item_list = gtk_container_children(GTK_CONTAINER(submenu_recent_files));
869 /* iterate through list items of menu_item_list,
870 * removing special items, a maybe duplicate entry and every item above count_max */
872 for (li = g_list_first(menu_item_list); li; li = li->next, cnt++) {
873 /* get capture filename */
874 menu_item = GTK_WIDGET(li->data);
875 widget_cf_name = OBJECT_GET_DATA(menu_item, MENU_RECENT_FILES_KEY);
877 /* if this element string is one of our special items or
878 * already in the list or
879 * this element is above maximum count (too old), remove it */
880 if (!widget_cf_name ||
881 strncmp(widget_cf_name, cf_name, 1000) == 0 ||
882 cnt >= prefs.gui_recent_files_count_max) {
883 remove_menu_recent_capture_file(li->data, NULL);
888 g_list_free(menu_item_list);
890 /* add new item at latest position */
891 menu_item = gtk_menu_item_new_with_label(cf_name);
892 widget_cf_name = g_strdup(cf_name);
893 OBJECT_SET_DATA(menu_item, MENU_RECENT_FILES_KEY, widget_cf_name);
894 gtk_menu_prepend (GTK_MENU(submenu_recent_files), menu_item);
895 SIGNAL_CONNECT_OBJECT(GTK_OBJECT(menu_item), "activate",
896 menu_open_recent_file_cmd_cb, (GtkObject *) menu_item);
897 gtk_widget_show (menu_item);
899 /* add seperator at last position */
900 menu_item = gtk_menu_item_new();
901 gtk_menu_append (GTK_MENU(submenu_recent_files), menu_item);
902 gtk_widget_show (menu_item);
904 /* add new "clear list" item at last position */
905 menu_item = gtk_menu_item_new_with_label("<clear file list>");
906 gtk_menu_append (GTK_MENU(submenu_recent_files), menu_item);
907 SIGNAL_CONNECT_OBJECT(GTK_OBJECT(menu_item), "activate",
908 clear_menu_recent_capture_file_cmd_cb, (GtkObject *) menu_item);
909 gtk_widget_show (menu_item);
911 update_menu_recent_capture_file(submenu_recent_files);
915 /* add the capture filename to the "Recent Files" menu */
916 /* (will change nothing, if this filename is already in the menu) */
918 add_menu_recent_capture_file(gchar *cf_name) {
923 /* if this filename is an absolute path, we can use it directly */
924 if (g_path_is_absolute(cf_name)) {
925 add_menu_recent_capture_file_absolute(cf_name);
929 /* this filename is not an absolute path, prepend the current dir */
930 curr = g_get_current_dir();
931 absolute = g_strdup_printf("%s%s%s", curr, G_DIR_SEPARATOR_S, cf_name);
932 add_menu_recent_capture_file_absolute(absolute);
939 /* write a single menu item widget label to the user's recent file */
940 /* helper, for menu_recent_file_write_all() */
941 void menu_recent_file_write(GtkWidget *widget, gpointer data) {
943 FILE *rf = (FILE *) data;
946 /* get capture filename from the menu item label */
947 cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY);
950 fprintf (rf, RECENT_KEY_CAPTURE_FILE ": %s\n", cf_name);
955 /* write all capture filenames of the menu to the user's recent file */
957 menu_recent_file_write_all(FILE *rf) {
958 GtkWidget *submenu_recent_files;
961 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
963 gtk_container_foreach(GTK_CONTAINER(submenu_recent_files),
964 menu_recent_file_write, rf);
969 main_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
972 /* save current setting in recent */
973 recent.main_toolbar_show = GTK_CHECK_MENU_ITEM(w)->active;
975 main_widgets_rearrange();
980 filter_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
983 /* save current setting in recent */
984 recent.filter_toolbar_show = GTK_CHECK_MENU_ITEM(w)->active;
986 main_widgets_rearrange();
991 packet_list_show_cb(GtkWidget *w _U_, gpointer d _U_)
994 /* save current setting in recent */
995 recent.packet_list_show = GTK_CHECK_MENU_ITEM(w)->active;
997 main_widgets_rearrange();
1002 tree_view_show_cb(GtkWidget *w _U_, gpointer d _U_)
1005 /* save current setting in recent */
1006 recent.tree_view_show = GTK_CHECK_MENU_ITEM(w)->active;
1008 main_widgets_rearrange();
1013 byte_view_show_cb(GtkWidget *w _U_, gpointer d _U_)
1016 /* save current setting in recent */
1017 recent.byte_view_show = GTK_CHECK_MENU_ITEM(w)->active;
1019 main_widgets_rearrange();
1024 statusbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
1027 /* save current setting in recent */
1028 recent.statusbar_show = GTK_CHECK_MENU_ITEM(w)->active;
1030 main_widgets_rearrange();
1035 timestamp_absolute_cb(GtkWidget *w _U_, gpointer d _U_)
1037 if (recent.gui_time_format != TS_ABSOLUTE) {
1038 timestamp_type = TS_ABSOLUTE;
1039 recent.gui_time_format = timestamp_type;
1040 change_time_formats(&cfile);
1045 timestamp_absolute_date_cb(GtkWidget *w _U_, gpointer d _U_)
1047 if (recent.gui_time_format != TS_ABSOLUTE_WITH_DATE) {
1048 timestamp_type = TS_ABSOLUTE_WITH_DATE;
1049 recent.gui_time_format = timestamp_type;
1050 change_time_formats(&cfile);
1055 timestamp_relative_cb(GtkWidget *w _U_, gpointer d _U_)
1057 if (recent.gui_time_format != TS_RELATIVE) {
1058 timestamp_type = TS_RELATIVE;
1059 recent.gui_time_format = timestamp_type;
1060 change_time_formats(&cfile);
1065 timestamp_delta_cb(GtkWidget *w _U_, gpointer d _U_)
1067 if (recent.gui_time_format != TS_DELTA) {
1068 timestamp_type = TS_DELTA;
1069 recent.gui_time_format = timestamp_type;
1070 change_time_formats(&cfile);
1075 name_resolution_mac_cb(GtkWidget *w _U_, gpointer d _U_)
1077 if (GTK_CHECK_MENU_ITEM(w)->active) {
1078 g_resolv_flags |= RESOLV_MAC;
1080 g_resolv_flags &= ~RESOLV_MAC;
1085 name_resolution_network_cb(GtkWidget *w _U_, gpointer d _U_)
1087 if (GTK_CHECK_MENU_ITEM(w)->active) {
1088 g_resolv_flags |= RESOLV_NETWORK;
1090 g_resolv_flags &= ~RESOLV_NETWORK;
1095 name_resolution_transport_cb(GtkWidget *w _U_, gpointer d _U_)
1097 if (GTK_CHECK_MENU_ITEM(w)->active) {
1098 g_resolv_flags |= RESOLV_TRANSPORT;
1100 g_resolv_flags &= ~RESOLV_TRANSPORT;
1105 auto_scroll_live_cb(GtkWidget *w _U_, gpointer d _U_)
1107 auto_scroll_live = GTK_CHECK_MENU_ITEM(w)->active;
1111 /* the recent file read has finished, update the menu corresponding */
1113 menu_recent_read_finished(void) {
1114 GtkWidget *menu = NULL;
1116 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Show/Main Toolbar");
1117 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.main_toolbar_show);
1119 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Show/Filter Toolbar");
1120 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.filter_toolbar_show);
1122 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Show/Packet List");
1123 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.packet_list_show);
1125 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Show/Packet Details");
1126 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.tree_view_show);
1128 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Show/Packet Bytes");
1129 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.byte_view_show);
1131 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Show/Status Bar");
1132 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.statusbar_show);
1134 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for MAC Layer");
1135 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_MAC);
1137 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for Network Layer");
1138 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_NETWORK);
1140 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for Transport Layer");
1141 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_TRANSPORT);
1143 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Auto Scroll in Live Capture");
1144 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), auto_scroll_live);
1146 main_widgets_rearrange();
1148 /* don't change the time format, if we had a command line value */
1149 if (timestamp_type != TS_NOT_SET) {
1150 recent.gui_time_format = timestamp_type;
1153 switch(recent.gui_time_format) {
1155 menu = gtk_item_factory_get_widget(main_menu_factory,
1156 "/View/Time Display Format/Time of Day");
1157 /* set_active will not trigger the callback when activating an active item! */
1158 recent.gui_time_format = -1;
1159 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), FALSE);
1160 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
1162 case(TS_ABSOLUTE_WITH_DATE):
1163 menu = gtk_item_factory_get_widget(main_menu_factory,
1164 "/View/Time Display Format/Date and Time of Day");
1165 recent.gui_time_format = -1;
1166 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
1169 menu = gtk_item_factory_get_widget(main_menu_factory,
1170 "/View/Time Display Format/Seconds Since Beginning of Capture");
1171 recent.gui_time_format = -1;
1172 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
1175 menu = gtk_item_factory_get_widget(main_menu_factory,
1176 "/View/Time Display Format/Seconds Since Previous Packet");
1177 recent.gui_time_format = -1;
1178 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
1181 g_assert_not_reached();
1187 popup_menu_handler(GtkWidget *widget, GdkEvent *event, gpointer data)
1189 GtkWidget *menu = (GtkWidget *)data;
1190 GdkEventButton *event_button = NULL;
1193 if(widget == NULL || event == NULL || data == NULL) {
1198 * If we ever want to make the menu differ based on what row
1199 * and/or column we're above, we'd use "eth_clist_get_selection_info()"
1200 * to find the row and column number for the coordinates; a CTree is,
1201 * I guess, like a CList with one column(?) and the expander widget
1204 /* Check if we are on packet_list object */
1205 if (widget == OBJECT_GET_DATA(popup_menu_object, E_MPACKET_LIST_KEY)) {
1206 if (packet_list_get_event_row_column(widget, (GdkEventButton *)event,
1208 OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_ROW_KEY,
1209 GINT_TO_POINTER(row));
1210 OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_COL_KEY,
1211 GINT_TO_POINTER(column));
1212 packet_list_set_selected_row(row);
1216 /* Check if we are on tree_view object */
1217 if (widget == tree_view) {
1218 tree_view_select(widget, (GdkEventButton *) event);
1221 /* Check if we are on byte_view object */
1222 if(widget == get_notebook_bv_ptr(byte_nb_ptr)) {
1223 byte_view_select(widget, (GdkEventButton *) event);
1226 if(event->type == GDK_BUTTON_PRESS) {
1227 event_button = (GdkEventButton *) event;
1229 /* To qoute the "Gdk Event Structures" doc:
1230 * "Normally button 1 is the left mouse button, 2 is the middle button, and 3 is the right button" */
1231 if(event_button->button == 3) {
1232 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
1233 event_button->button,
1234 event_button->time);
1235 SIGNAL_EMIT_STOP_BY_NAME(widget, "button_press_event");
1239 #if GTK_MAJOR_VERSION >= 2
1240 /* GDK_2BUTTON_PRESS is a doubleclick -> expand/collapse tree row */
1241 /* GTK version 1 seems to be doing this automatically */
1242 if (widget == tree_view && event->type == GDK_2BUTTON_PRESS) {
1245 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget),
1246 (gint) (((GdkEventButton *)event)->x),
1247 (gint) (((GdkEventButton *)event)->y),
1248 &path, NULL, NULL, NULL))
1250 if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(widget), path))
1251 gtk_tree_view_collapse_row(GTK_TREE_VIEW(widget), path);
1253 gtk_tree_view_expand_row(GTK_TREE_VIEW(widget), path,
1255 gtk_tree_path_free(path);
1262 /* Enable or disable menu items based on whether you have a capture file
1263 you've finished reading. */
1265 set_menus_for_capture_file(gboolean have_capture_file)
1267 set_menu_sensitivity(main_menu_factory, "/File/Open...", have_capture_file);
1268 set_menu_sensitivity(main_menu_factory, "/File/Open Recent", have_capture_file);
1269 set_menu_sensitivity(main_menu_factory, "/File/Close", have_capture_file);
1270 set_menu_sensitivity(main_menu_factory, "/File/Save As...",
1272 set_menu_sensitivity(main_menu_factory, "/File/Export", have_capture_file);
1273 set_menu_sensitivity(main_menu_factory, "/View/Reload", have_capture_file);
1274 set_toolbar_for_capture_file(have_capture_file);
1277 /* Enable or disable menu items based on whether you have an unsaved
1278 capture file you've finished reading. */
1280 set_menus_for_unsaved_capture_file(gboolean have_unsaved_capture_file)
1282 set_menu_sensitivity(main_menu_factory, "/File/Save",
1283 have_unsaved_capture_file);
1284 set_toolbar_for_unsaved_capture_file(have_unsaved_capture_file);
1287 /* Enable or disable menu items based on whether there's a capture in
1290 set_menus_for_capture_in_progress(gboolean capture_in_progress)
1292 set_menu_sensitivity(main_menu_factory, "/File/Open...",
1293 !capture_in_progress);
1294 set_menu_sensitivity(main_menu_factory, "/File/Open Recent",
1295 !capture_in_progress);
1297 set_menu_sensitivity(main_menu_factory, "/Capture/Start...",
1298 !capture_in_progress);
1299 set_menu_sensitivity(main_menu_factory, "/Capture/Stop",
1300 capture_in_progress);
1301 #endif /* HAVE_LIBPCAP */
1302 set_toolbar_for_capture_in_progress(capture_in_progress);
1305 /* Enable or disable menu items based on whether you have some captured
1308 walk_menu_tree_for_captured_packets(menu_item_t *node,
1309 gboolean have_captured_packets)
1311 gboolean is_enabled;
1315 * Is this a leaf node or an interior node?
1317 if (node->children == NULL) {
1321 * If it has no "selected_packet_enabled()" or
1322 * "selected_tree_row_enabled()" routines, we enable
1323 * it. This allows tap windows to be popped up even
1324 * if you have no capture file; this is done to let
1325 * the user pop up multiple tap windows before reading
1326 * in a capture file, so that they can be processed in
1327 * parallel while the capture file is being read rather
1328 * than one at at time as you pop up the windows, and to
1329 * let the user pop up tap windows before starting an
1330 * "Update list of packets in real time" capture, so that
1331 * the statistics can be displayed while the capture is
1334 * If it has either of those routines, we disable it for
1335 * now - as long as, when a capture is first available,
1336 * we don't get called after a packet or tree row is
1337 * selected, that's OK.
1338 * XXX - that should be done better.
1340 if (node->selected_packet_enabled == NULL &&
1341 node->selected_tree_row_enabled == NULL)
1342 node->enabled = TRUE;
1344 node->enabled = FALSE;
1347 * It's an interior node; call
1348 * "walk_menu_tree_for_captured_packets()" on all its
1349 * children and, if any of them are enabled, enable
1350 * this node, otherwise disable it.
1352 * XXX - should we just leave all interior nodes enabled?
1353 * Which is a better UI choice?
1356 for (child = node->children; child != NULL; child =
1358 if (walk_menu_tree_for_captured_packets(child,
1359 have_captured_packets))
1362 node->enabled = is_enabled;
1366 * The root node doesn't correspond to a menu tree item; it
1367 * has a null name pointer.
1369 if (node->name != NULL) {
1370 set_menu_sensitivity(main_menu_factory, node->name,
1373 return node->enabled;
1377 set_menus_for_captured_packets(gboolean have_captured_packets)
1379 set_menu_sensitivity(main_menu_factory, "/File/Print...",
1380 have_captured_packets);
1381 set_menu_sensitivity(packet_list_menu_factory, "/Print...",
1382 have_captured_packets);
1383 set_menu_sensitivity(main_menu_factory, "/Edit/Find Packet...",
1384 have_captured_packets);
1385 set_menu_sensitivity(main_menu_factory, "/Edit/Find Next",
1386 have_captured_packets);
1387 set_menu_sensitivity(main_menu_factory, "/Edit/Find Previous",
1388 have_captured_packets);
1389 set_menu_sensitivity(main_menu_factory, "/Edit/Go To First Packet",
1390 have_captured_packets);
1391 set_menu_sensitivity(main_menu_factory, "/Edit/Go To Last Packet",
1392 have_captured_packets);
1393 set_menu_sensitivity(main_menu_factory, "/Edit/Go To Packet...",
1394 have_captured_packets);
1395 set_menu_sensitivity(main_menu_factory, "/View/Zoom In",
1396 have_captured_packets);
1397 set_menu_sensitivity(main_menu_factory, "/View/Zoom Out",
1398 have_captured_packets);
1399 set_menu_sensitivity(main_menu_factory, "/View/Normal Size",
1400 have_captured_packets);
1401 set_menu_sensitivity(main_menu_factory, "/View/Coloring Rules...",
1402 have_captured_packets);
1403 set_menu_sensitivity(packet_list_menu_factory, "/Coloring Rules...",
1404 have_captured_packets);
1405 set_menu_sensitivity(main_menu_factory, "/Analyze/Summary",
1406 have_captured_packets);
1407 set_menu_sensitivity(main_menu_factory, "/Analyze/Protocol Hierarchy Statistics",
1408 have_captured_packets);
1410 walk_menu_tree_for_captured_packets(&tap_menu_tree_root,
1411 have_captured_packets);
1412 set_toolbar_for_captured_packets(have_captured_packets);
1415 /* Enable or disable menu items based on whether a packet is selected and,
1416 if so, on the properties of the packet. */
1418 walk_menu_tree_for_selected_packet(menu_item_t *node, frame_data *fd,
1419 epan_dissect_t *edt)
1421 gboolean is_enabled;
1425 * Is this a leaf node or an interior node?
1427 if (node->children == NULL) {
1431 * If it has no "selected_packet_enabled()" routine,
1432 * leave its enabled/disabled status alone - it
1433 * doesn't depend on whether we have a packet selected
1434 * or not or on the selected packet.
1436 * If it has a "selected_packet_enabled()" routine,
1437 * call it and set the item's enabled/disabled status
1438 * based on its return value.
1440 if (node->selected_packet_enabled != NULL)
1441 node->enabled = node->selected_packet_enabled(fd, edt);
1444 * It's an interior node; call
1445 * "walk_menu_tree_for_selected_packet()" on all its
1446 * children and, if any of them are enabled, enable
1447 * this node, otherwise disable it.
1449 * XXX - should we just leave all interior nodes enabled?
1450 * Which is a better UI choice?
1453 for (child = node->children; child != NULL; child =
1455 if (walk_menu_tree_for_selected_packet(child, fd, edt))
1458 node->enabled = is_enabled;
1462 * The root node doesn't correspond to a menu tree item; it
1463 * has a null name pointer.
1465 if (node->name != NULL) {
1466 set_menu_sensitivity(main_menu_factory, node->name,
1469 return node->enabled;
1473 set_menus_for_selected_packet(capture_file *cf)
1475 set_menu_sensitivity(main_menu_factory, "/Edit/Mark Packet",
1476 cf->current_frame != NULL);
1477 set_menu_sensitivity(packet_list_menu_factory, "/Mark Packet",
1478 cf->current_frame != NULL);
1479 set_menu_sensitivity(main_menu_factory, "/Edit/Time Reference",
1480 cf->current_frame != NULL);
1481 set_menu_sensitivity(packet_list_menu_factory, "/Time Reference",
1482 cf->current_frame != NULL);
1483 set_menu_sensitivity(main_menu_factory, "/Edit/Mark All Packets",
1484 cf->current_frame != NULL);
1485 set_menu_sensitivity(main_menu_factory, "/Edit/Unmark All Packets",
1486 cf->current_frame != NULL);
1487 set_menu_sensitivity(main_menu_factory, "/View/Collapse All",
1488 cf->current_frame != NULL);
1489 set_menu_sensitivity(tree_view_menu_factory, "/Collapse All",
1490 cf->current_frame != NULL);
1491 set_menu_sensitivity(main_menu_factory, "/View/Expand All",
1492 cf->current_frame != NULL);
1493 set_menu_sensitivity(tree_view_menu_factory, "/Expand All",
1494 cf->current_frame != NULL);
1495 set_menu_sensitivity(main_menu_factory, "/View/Show Packet In New Window",
1496 cf->current_frame != NULL);
1497 set_menu_sensitivity(packet_list_menu_factory, "/Show Packet In New Window",
1498 cf->current_frame != NULL);
1499 set_menu_sensitivity(main_menu_factory, "/Analyze/Follow TCP Stream",
1500 cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
1501 set_menu_sensitivity(NULL, "/Follow TCP Stream",
1502 cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
1503 set_menu_sensitivity(main_menu_factory, "/Analyze/Decode As...",
1504 cf->current_frame != NULL && decode_as_ok());
1505 set_menu_sensitivity(NULL, "/Decode As...",
1506 cf->current_frame != NULL && decode_as_ok());
1507 set_menu_sensitivity(tree_view_menu_factory, "/Resolve Name",
1508 cf->current_frame != NULL && g_resolv_flags == 0);
1509 set_menu_sensitivity(main_menu_factory, "/Analyze/TCP Stream Analysis",
1510 cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
1511 set_menu_sensitivity(packet_list_menu_factory, "/Match",
1512 cf->current_frame != NULL);
1513 set_menu_sensitivity(packet_list_menu_factory, "/Prepare",
1514 cf->current_frame != NULL);
1516 walk_menu_tree_for_selected_packet(&tap_menu_tree_root, cf->current_frame,
1520 /* Enable or disable menu items based on whether a tree row is selected
1521 and, if so, on the properties of the tree row. */
1523 walk_menu_tree_for_selected_tree_row(menu_item_t *node, field_info *fi)
1525 gboolean is_enabled;
1529 * Is this a leaf node or an interior node?
1531 if (node->children == NULL) {
1535 * If it has no "selected_tree_row_enabled()" routine,
1536 * leave its enabled/disabled status alone - it
1537 * doesn't depend on whether we have a tree row selected
1538 * or not or on the selected tree row.
1540 * If it has a "selected_tree_row_enabled()" routine,
1541 * call it and set the item's enabled/disabled status
1542 * based on its return value.
1544 if (node->selected_tree_row_enabled != NULL)
1545 node->enabled = node->selected_tree_row_enabled(fi);
1548 * It's an interior node; call
1549 * "walk_menu_tree_for_selected_tree_row()" on all its
1550 * children and, if any of them are enabled, enable
1551 * this node, otherwise disable it.
1553 * XXX - should we just leave all interior nodes enabled?
1554 * Which is a better UI choice?
1557 for (child = node->children; child != NULL; child =
1559 if (walk_menu_tree_for_selected_tree_row(child, fi))
1562 node->enabled = is_enabled;
1566 * The root node doesn't correspond to a menu tree item; it
1567 * has a null name pointer.
1569 if (node->name != NULL) {
1570 set_menu_sensitivity(main_menu_factory, node->name,
1573 return node->enabled;
1577 set_menus_for_selected_tree_row(capture_file *cf)
1579 gboolean properties;
1582 set_menu_sensitivity(main_menu_factory, "/File/Export/Selected Packet Bytes...",
1583 cf->finfo_selected != NULL);
1584 set_menu_sensitivity(tree_view_menu_factory, "/Export Selected Packet Bytes...",
1585 cf->finfo_selected != NULL);
1586 set_menu_sensitivity(hexdump_menu_factory, "/Export Selected Packet Bytes...",
1587 cf->finfo_selected != NULL);
1589 if (cf->finfo_selected != NULL) {
1590 header_field_info *hfinfo = cf->finfo_selected->hfinfo;
1591 if (hfinfo->parent == -1) {
1592 properties = prefs_is_registered_protocol(hfinfo->abbrev);
1594 properties = prefs_is_registered_protocol(proto_registrar_get_abbrev(hfinfo->parent));
1596 set_menu_sensitivity(main_menu_factory,
1597 "/Edit/Go To Corresponding Packet", hfinfo->type == FT_FRAMENUM);
1598 set_menu_sensitivity(tree_view_menu_factory,
1599 "/Go To Corresponding Packet", hfinfo->type == FT_FRAMENUM);
1600 set_menu_sensitivity(main_menu_factory, "/Analyze/Match",
1601 proto_can_match_selected(cf->finfo_selected, cf->edt));
1602 set_menu_sensitivity(tree_view_menu_factory, "/Match",
1603 proto_can_match_selected(cf->finfo_selected, cf->edt));
1604 set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare",
1605 proto_can_match_selected(cf->finfo_selected, cf->edt));
1606 set_menu_sensitivity(tree_view_menu_factory, "/Prepare",
1607 proto_can_match_selected(cf->finfo_selected, cf->edt));
1608 set_menu_sensitivity(tree_view_menu_factory, "/Protocol Properties...",
1611 set_menu_sensitivity(main_menu_factory,
1612 "/Edit/Go To Corresponding Packet", FALSE);
1613 set_menu_sensitivity(tree_view_menu_factory,
1614 "/Go To Corresponding Packet", FALSE);
1615 set_menu_sensitivity(main_menu_factory, "/Analyze/Match", FALSE);
1616 set_menu_sensitivity(tree_view_menu_factory, "/Match", FALSE);
1617 set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare", FALSE);
1618 set_menu_sensitivity(tree_view_menu_factory, "/Prepare", FALSE);
1619 set_menu_sensitivity(tree_view_menu_factory, "/Protocol Properties...",
1623 walk_menu_tree_for_selected_tree_row(&tap_menu_tree_root, cf->finfo_selected);