4 * $Id: menu.c,v 1.206 2004/06/22 16:28:27 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 "about_dlg.h"
40 #include "capture_dlg.h"
41 #include "color_dlg.h"
42 #include "filter_prefs.h"
43 #include "dlg_utils.h"
47 #include "summary_dlg.h"
48 #include "prefs_dlg.h"
49 #include "packet_win.h"
51 #include "follow_dlg.h"
52 #include "decode_as_dlg.h"
54 #include "supported_protos_dlg.h"
55 #include "proto_dlg.h"
56 #include "proto_hier_stats_dlg.h"
58 #include <epan/plugins.h>
59 #include <epan/epan_dissect.h>
60 #include "compat_macros.h"
62 #include "gtkglobals.h"
66 #include "../ipproto.h"
67 #include "packet_list.h"
70 #include "../ui_util.h"
71 #include "proto_draw.h"
72 #include "endpoint_talkers_table.h"
73 #include "hostlist_table.h"
74 #include "simple_dialog.h"
75 #include <epan/timestamp.h>
77 GtkWidget *popup_menu_object;
80 clear_menu_recent_capture_file_cmd_cb(GtkWidget *w, gpointer unused _U_);
82 typedef struct _menu_item {
86 GtkItemFactoryCallback callback;
87 gpointer callback_data;
88 gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *);
89 gboolean (*selected_tree_row_enabled)(field_info *);
93 static GList *tap_menu_tree_root = NULL;
96 merge_all_tap_menus(GList *node);
98 #define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
100 static void menus_init(void);
101 static void set_menu_sensitivity (GtkItemFactory *, const gchar *, gint);
102 static void main_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
103 static void filter_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
104 static void packet_list_show_cb(GtkWidget *w _U_, gpointer d _U_);
105 static void tree_view_show_cb(GtkWidget *w _U_, gpointer d _U_);
106 static void byte_view_show_cb(GtkWidget *w _U_, gpointer d _U_);
107 static void statusbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
108 static void timestamp_absolute_cb(GtkWidget *w _U_, gpointer d _U_);
109 static void timestamp_absolute_date_cb(GtkWidget *w _U_, gpointer d _U_);
110 static void timestamp_relative_cb(GtkWidget *w _U_, gpointer d _U_);
111 static void timestamp_delta_cb(GtkWidget *w _U_, gpointer d _U_);
112 static void name_resolution_mac_cb(GtkWidget *w _U_, gpointer d _U_);
113 static void name_resolution_network_cb(GtkWidget *w _U_, gpointer d _U_);
114 static void name_resolution_transport_cb(GtkWidget *w _U_, gpointer d _U_);
116 static void auto_scroll_live_cb(GtkWidget *w _U_, gpointer d _U_);
119 /* This is the GtkItemFactoryEntry structure used to generate new menus.
120 Item 1: The menu path. The letter after the underscore indicates an
121 accelerator key once the menu is open.
122 Item 2: The accelerator key for the entry
123 Item 3: The callback function.
124 Item 4: The callback action. This changes the parameters with
125 which the function is called. The default is 0.
126 Item 5: The item type, used to define what kind of an item it is.
127 Here are the possible values:
131 "<Title>" -> create a title item
132 "<Item>" -> create a simple item
133 "<ImageItem>" -> create an item holding an image (gtk2)
134 "<StockItem>" -> create an item holding a stock image (gtk2)
135 "<CheckItem>" -> create a check item
136 "<ToggleItem>" -> create a toggle item
137 "<RadioItem>" -> create a radio item
138 <path> -> path of a radio item to link against
139 "<Separator>" -> create a separator
140 "<Tearoff>" -> create a tearoff separator (gtk2)
141 "<Branch>" -> create an item to hold sub items (optional)
142 "<LastBranch>" -> create a right justified branch
143 Item 6: extra data needed for ImageItem and StockItem (gtk2)
147 static GtkItemFactoryEntry menu_items[] =
149 ITEM_FACTORY_ENTRY("/_File", NULL, NULL, 0, "<Branch>", NULL),
150 ITEM_FACTORY_STOCK_ENTRY("/File/_Open...", "<control>O", file_open_cmd_cb,
152 ITEM_FACTORY_ENTRY("/File/Open _Recent", NULL, NULL, 0, "<Branch>", NULL),
153 ITEM_FACTORY_ENTRY("/File/_Merge...", NULL, file_merge_cmd_cb, 0, NULL, NULL),
154 ITEM_FACTORY_STOCK_ENTRY("/File/_Close", "<control>W", file_close_cmd_cb,
156 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
157 ITEM_FACTORY_STOCK_ENTRY("/File/_Save", "<control>S", file_save_cmd_cb,
159 ITEM_FACTORY_STOCK_ENTRY("/File/Save _As...", "<shift><control>S", file_save_as_cmd_cb,
160 0, GTK_STOCK_SAVE_AS),
161 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
162 ITEM_FACTORY_ENTRY("/File/_Export", NULL, NULL, 0, "<Branch>", NULL),
163 ITEM_FACTORY_ENTRY("/File/Export/as \"Plain _Text\" file...", NULL, export_text_cmd_cb,
165 ITEM_FACTORY_ENTRY("/File/Export/as \"_PostScript\" file...", NULL, export_ps_cmd_cb,
167 ITEM_FACTORY_ENTRY("/File/Export/as XML - \"P_SML\" (packet summary) file...", NULL, export_psml_cmd_cb,
169 ITEM_FACTORY_ENTRY("/File/Export/as XML - \"P_DML\" (packet details) file...", NULL, export_pdml_cmd_cb,
171 ITEM_FACTORY_ENTRY("/File/Export/<separator>", NULL, NULL, 0, "<Separator>", NULL),
172 ITEM_FACTORY_ENTRY("/File/Export/Selected Packet _Bytes...", "<control>H", savehex_cb,
174 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
175 ITEM_FACTORY_STOCK_ENTRY("/File/_Print...", "<control>P", file_print_cmd_cb,
177 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
178 ITEM_FACTORY_STOCK_ENTRY("/File/_Quit", "<control>Q", file_quit_cmd_cb,
180 ITEM_FACTORY_ENTRY("/_Edit", NULL, NULL, 0, "<Branch>", NULL),
182 /* Un-#if this when we actually implement Cut/Copy/Paste. */
183 ITEM_FACTORY_STOCK_ENTRY("/Edit/Cut", "<control>X", NULL,
185 ITEM_FACTORY_STOCK_ENTRY("/Edit/Copy", "<control>C", NULL,
187 ITEM_FACTORY_STOCK_ENTRY("/Edit/Paste", "<control>V", NULL,
189 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>"),
191 ITEM_FACTORY_STOCK_ENTRY("/Edit/_Find Packet...", "<control>F",
192 find_frame_cb, 0, GTK_STOCK_FIND),
193 ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Ne_xt", "<control>N", find_next_cb,
194 0, GTK_STOCK_GO_FORWARD),
195 ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Pre_vious", "<control>B",
196 find_previous_cb, 0, GTK_STOCK_GO_BACK),
197 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
198 ITEM_FACTORY_ENTRY("/Edit/_Time Reference", NULL, NULL, 0, "<Branch>", NULL),
199 ITEM_FACTORY_ENTRY("/Edit/Time Reference/Set Time Reference (toggle)", "<control>T", reftime_frame_cb, REFTIME_TOGGLE, NULL, NULL),
200 ITEM_FACTORY_ENTRY("/Edit/Time Reference/Find Next", NULL, reftime_frame_cb, REFTIME_FIND_NEXT, NULL, NULL),
201 ITEM_FACTORY_ENTRY("/Edit/Time Reference/Find Previous", NULL, reftime_frame_cb, REFTIME_FIND_PREV, NULL, NULL),
202 ITEM_FACTORY_ENTRY("/Edit/_Mark Packet", "<control>M", mark_frame_cb,
204 ITEM_FACTORY_ENTRY("/Edit/Mark _All Packets", NULL, mark_all_frames_cb,
206 ITEM_FACTORY_ENTRY("/Edit/_Unmark All Packets", NULL, unmark_all_frames_cb,
208 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
209 ITEM_FACTORY_STOCK_ENTRY("/Edit/_Preferences...", "<shift><control>P", prefs_cb,
210 0, GTK_STOCK_PREFERENCES),
211 ITEM_FACTORY_ENTRY("/_View", NULL, NULL, 0, "<Branch>", NULL),
212 ITEM_FACTORY_ENTRY("/View/_Main Toolbar", NULL, main_toolbar_show_cb, 0, "<CheckItem>", NULL),
213 ITEM_FACTORY_ENTRY("/View/_Filter Toolbar", NULL, filter_toolbar_show_cb, 0, "<CheckItem>", NULL),
214 ITEM_FACTORY_ENTRY("/View/_Statusbar", NULL, statusbar_show_cb, 0, "<CheckItem>", NULL),
215 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
216 ITEM_FACTORY_ENTRY("/View/Packet _List", NULL, packet_list_show_cb, 0, "<CheckItem>", NULL),
217 ITEM_FACTORY_ENTRY("/View/Packet _Details", NULL, tree_view_show_cb, 0, "<CheckItem>", NULL),
218 ITEM_FACTORY_ENTRY("/View/Packet _Bytes", NULL, byte_view_show_cb, 0, "<CheckItem>", NULL),
219 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
220 ITEM_FACTORY_ENTRY("/View/_Time Display Format", NULL, NULL, 0, "<Branch>", NULL),
221 ITEM_FACTORY_ENTRY("/View/Time Display Format/Time of Day", NULL, timestamp_absolute_cb,
222 0, "<RadioItem>", NULL),
223 ITEM_FACTORY_ENTRY("/View/Time Display Format/Date and Time of Day", NULL, timestamp_absolute_date_cb,
224 0, "/View/Time Display Format/Time of Day", NULL),
225 ITEM_FACTORY_ENTRY("/View/Time Display Format/Seconds Since Beginning of Capture", NULL, timestamp_relative_cb,
226 0, "/View/Time Display Format/Time of Day", NULL),
227 ITEM_FACTORY_ENTRY("/View/Time Display Format/Seconds Since Previous Packet", NULL, timestamp_delta_cb,
228 0, "/View/Time Display Format/Time of Day", NULL),
229 ITEM_FACTORY_ENTRY("/View/Name Resol_ution", NULL, NULL, 0, "<Branch>", NULL),
230 ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _MAC Layer", NULL, name_resolution_mac_cb, 0, "<CheckItem>", NULL),
231 ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Network Layer", NULL, name_resolution_network_cb, 0, "<CheckItem>", NULL),
232 ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Transport Layer", NULL, name_resolution_transport_cb, 0, "<CheckItem>", NULL),
234 ITEM_FACTORY_ENTRY("/View/Auto Scroll in Li_ve Capture", NULL, auto_scroll_live_cb, 0, "<CheckItem>", NULL),
236 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
237 ITEM_FACTORY_STOCK_ENTRY("/View/_Zoom In", "<control>plus", view_zoom_in_cb,
238 0, GTK_STOCK_ZOOM_IN),
239 ITEM_FACTORY_STOCK_ENTRY("/View/Zoom _Out", "<control>minus", view_zoom_out_cb,
240 0, GTK_STOCK_ZOOM_OUT),
241 ITEM_FACTORY_STOCK_ENTRY("/View/_Normal Size", "<control>equal", view_zoom_100_cb,
242 0, GTK_STOCK_ZOOM_100),
243 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
244 ITEM_FACTORY_ENTRY("/View/Collapse _All", NULL, collapse_all_cb,
246 ITEM_FACTORY_ENTRY("/View/_Expand All", NULL, expand_all_cb,
248 ITEM_FACTORY_ENTRY("/View/Expand Tree", NULL, expand_tree_cb, 0, NULL, NULL),
249 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
250 ITEM_FACTORY_STOCK_ENTRY("/View/_Coloring Rules...", NULL, color_display_cb,
251 0, GTK_STOCK_SELECT_COLOR),
252 ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
253 ITEM_FACTORY_ENTRY("/View/Show Packet in New _Window", NULL,
254 new_window_cb, 0, NULL, NULL),
255 ITEM_FACTORY_STOCK_ENTRY("/View/_Reload", "<control>R", file_reload_cmd_cb,
256 0, GTK_STOCK_REFRESH),
257 ITEM_FACTORY_ENTRY("/_Go", NULL, NULL, 0, "<Branch>", NULL),
258 ITEM_FACTORY_STOCK_ENTRY("/Go/_Go to Packet...", "<control>G",
259 goto_frame_cb, 0, GTK_STOCK_JUMP_TO),
260 ITEM_FACTORY_ENTRY("/Go/Go to _Corresponding Packet", NULL, goto_framenum_cb,
262 ITEM_FACTORY_ENTRY("/Go/<separator>", NULL, NULL, 0, "<Separator>", NULL),
263 ITEM_FACTORY_STOCK_ENTRY("/Go/_First Packet", NULL,
264 goto_top_frame_cb, 0, GTK_STOCK_GOTO_TOP),
265 ITEM_FACTORY_STOCK_ENTRY("/Go/_Last Packet", NULL,
266 goto_bottom_frame_cb, 0, GTK_STOCK_GOTO_BOTTOM),
268 ITEM_FACTORY_ENTRY("/_Capture", NULL, NULL, 0, "<Branch>", NULL),
269 ITEM_FACTORY_STOCK_ENTRY("/Capture/_Start...", "<control>K",
270 capture_prep_cb, 0, ETHEREAL_STOCK_CAPTURE_START),
271 ITEM_FACTORY_STOCK_ENTRY("/Capture/S_top", "<control>E", capture_stop_cb,
273 ITEM_FACTORY_STOCK_ENTRY("/Capture/_Capture Filters...", NULL, cfilter_dialog_cb,
274 0, ETHEREAL_STOCK_CAPTURE_FILTER),
275 #endif /* HAVE_LIBPCAP */
276 ITEM_FACTORY_ENTRY("/_Analyze", NULL, NULL, 0, "<Branch>", NULL),
277 ITEM_FACTORY_STOCK_ENTRY("/Analyze/_Display Filters...", NULL, dfilter_dialog_cb,
278 0, ETHEREAL_STOCK_DISPLAY_FILTER),
279 ITEM_FACTORY_ENTRY("/Analyze/Appl_y as Filter", NULL, NULL, 0, "<Branch>", NULL),
280 ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/_Selected", NULL, match_selected_ptree_cb,
281 MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
282 ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/_Not Selected", NULL, match_selected_ptree_cb,
283 MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
284 ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... _and Selected", NULL, match_selected_ptree_cb,
285 MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
286 ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... _or Selected", NULL, match_selected_ptree_cb,
287 MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
288 ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... a_nd not Selected", NULL, match_selected_ptree_cb,
289 MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
290 ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... o_r not Selected", NULL, match_selected_ptree_cb,
291 MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
292 ITEM_FACTORY_ENTRY("/Analyze/_Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
293 ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/_Selected", NULL, match_selected_ptree_cb,
294 MATCH_SELECTED_REPLACE, NULL, NULL),
295 ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/_Not Selected", NULL, match_selected_ptree_cb,
296 MATCH_SELECTED_NOT, NULL, NULL),
297 ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... _and Selected", NULL, match_selected_ptree_cb,
298 MATCH_SELECTED_AND, NULL, NULL),
299 ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... _or Selected", NULL, match_selected_ptree_cb,
300 MATCH_SELECTED_OR, NULL, NULL),
301 ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... a_nd not Selected", NULL, match_selected_ptree_cb,
302 MATCH_SELECTED_AND_NOT, NULL, NULL),
303 ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... o_r not Selected", NULL, match_selected_ptree_cb,
304 MATCH_SELECTED_OR_NOT, NULL, NULL),
305 ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL),
306 ITEM_FACTORY_ENTRY("/Analyze/_Enabled Protocols...", "<shift><control>R", proto_cb, 0, NULL, NULL),
307 ITEM_FACTORY_ENTRY("/Analyze/Decode _As...", NULL, decode_as_cb,
309 ITEM_FACTORY_ENTRY("/Analyze/_User Specified Decodes...", NULL,
310 decode_show_cb, 0, NULL, NULL),
311 ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL),
312 ITEM_FACTORY_ENTRY("/Analyze/_Follow TCP Stream", NULL,
313 follow_stream_cb, 0, NULL, NULL),
314 ITEM_FACTORY_ENTRY("/_Statistics", NULL, NULL, 0, "<Branch>", NULL),
315 ITEM_FACTORY_ENTRY("/Statistics/_Summary", NULL, summary_open_cb, 0, NULL, NULL),
316 ITEM_FACTORY_ENTRY("/Statistics/_Protocol Hierarchy", NULL,
317 proto_hier_stats_cb, 0, NULL, NULL),
318 ITEM_FACTORY_ENTRY("/Statistics/Conversations", NULL,
319 init_ett_notebook_cb, 0, NULL, NULL),
320 ITEM_FACTORY_ENTRY("/Statistics/Endpoints", NULL,
321 init_hostlist_notebook_cb, 0, NULL, NULL),
322 ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "<Branch>", NULL),
323 ITEM_FACTORY_STOCK_ENTRY("/Help/_Contents", "F1", help_cb, 0, GTK_STOCK_HELP),
324 ITEM_FACTORY_ENTRY("/Help/_Supported Protocols", NULL, supported_cb, 0, NULL, NULL),
325 ITEM_FACTORY_ENTRY("/Help/Manual Pages", NULL, NULL, 0, "<Branch>", NULL),
326 ITEM_FACTORY_ENTRY("/Help/Manual Pages/Ethereal", NULL, url_localpage_cb, LOCALPAGE_MAN_ETHEREAL, NULL, NULL),
327 ITEM_FACTORY_ENTRY("/Help/Manual Pages/Ethereal Filter", NULL, url_localpage_cb, LOCALPAGE_MAN_ETHEREAL_FILTER, NULL, NULL),
328 ITEM_FACTORY_ENTRY("/Help/Manual Pages/<separator>", NULL, NULL, 0, "<Separator>", NULL),
329 ITEM_FACTORY_ENTRY("/Help/Manual Pages/Tethereal", NULL, url_localpage_cb, LOCALPAGE_MAN_TETHEREAL, NULL, NULL),
330 ITEM_FACTORY_ENTRY("/Help/Manual Pages/Mergecap", NULL, url_localpage_cb, LOCALPAGE_MAN_MERGECAP, NULL, NULL),
331 ITEM_FACTORY_ENTRY("/Help/Manual Pages/Editcap", NULL, url_localpage_cb, LOCALPAGE_MAN_EDITCAP, NULL, NULL),
332 ITEM_FACTORY_ENTRY("/Help/Manual Pages/Text2pcap", NULL, url_localpage_cb, LOCALPAGE_MAN_TEXT2PCAP, NULL, NULL),
333 ITEM_FACTORY_ENTRY("/Help/Ethereal Online", NULL, NULL, 0, "<Branch>", NULL),
334 ITEM_FACTORY_STOCK_ENTRY("/Help/Ethereal Online/Home Page", NULL, url_onlinepage_cb, ONLINEPAGE_HOME, GTK_STOCK_HOME),
335 ITEM_FACTORY_ENTRY("/Help/Ethereal Online/User's Guide", NULL, url_onlinepage_cb, ONLINEPAGE_USERGUIDE, NULL, NULL),
336 ITEM_FACTORY_ENTRY("/Help/Ethereal Online/FAQ's", NULL, url_onlinepage_cb, ONLINEPAGE_FAQ, NULL, NULL),
337 ITEM_FACTORY_ENTRY("/Help/Ethereal Online/Downloads", NULL, url_onlinepage_cb, ONLINEPAGE_DOWNLOAD, NULL, NULL),
338 ITEM_FACTORY_ENTRY("/Help/Ethereal Online/Example Files", NULL, url_onlinepage_cb, ONLINEPAGE_SAMPLE, NULL, NULL),
339 ITEM_FACTORY_ENTRY("/Help/<separator>", NULL, NULL, 0, "<Separator>", NULL),
340 ITEM_FACTORY_ENTRY("/Help/_About Ethereal", NULL, about_ethereal_cb,
345 /* calculate the number of menu_items */
346 static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
348 /* packet list popup */
349 static GtkItemFactoryEntry packet_list_menu_items[] =
351 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
353 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
354 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
356 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
357 ITEM_FACTORY_ENTRY("/Mark Packet", NULL, mark_frame_cb, 0, NULL, NULL),
358 ITEM_FACTORY_ENTRY("/Time Reference", NULL, NULL, 0, "<Branch>", NULL),
359 ITEM_FACTORY_ENTRY("/Time Reference/Set Time Reference (toggle)", NULL, reftime_frame_cb, REFTIME_TOGGLE, NULL, NULL),
360 ITEM_FACTORY_ENTRY("/Time Reference/Find Next", NULL, reftime_frame_cb, REFTIME_FIND_NEXT, NULL, NULL),
361 ITEM_FACTORY_ENTRY("/Time Reference/Find Previous", NULL, reftime_frame_cb, REFTIME_FIND_PREV, NULL, NULL),
362 ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
363 ITEM_FACTORY_ENTRY("/Apply as Filter/_Selected", NULL, match_selected_plist_cb,
364 MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
365 ITEM_FACTORY_ENTRY("/Apply as Filter/_Not Selected", NULL, match_selected_plist_cb,
366 MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
367 ITEM_FACTORY_ENTRY("/Apply as Filter/... _and Selected", NULL, match_selected_plist_cb,
368 MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
369 ITEM_FACTORY_ENTRY("/Apply as Filter/... _or Selected", NULL, match_selected_plist_cb,
370 MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
371 ITEM_FACTORY_ENTRY("/Apply as Filter/... a_nd not Selected", NULL, match_selected_plist_cb,
372 MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
373 ITEM_FACTORY_ENTRY("/Apply as Filter/... o_r not Selected", NULL, match_selected_plist_cb,
374 MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
376 ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
377 ITEM_FACTORY_ENTRY("/Prepare a Filter/_Selected", NULL, match_selected_plist_cb,
378 MATCH_SELECTED_REPLACE, NULL, NULL),
379 ITEM_FACTORY_ENTRY("/Prepare a Filter/_Not Selected", NULL, match_selected_plist_cb,
380 MATCH_SELECTED_NOT, NULL, NULL),
381 ITEM_FACTORY_ENTRY("/Prepare a Filter/... _and Selected", NULL, match_selected_plist_cb,
382 MATCH_SELECTED_AND, NULL, NULL),
383 ITEM_FACTORY_ENTRY("/Prepare a Filter/... _or Selected", NULL, match_selected_plist_cb,
384 MATCH_SELECTED_OR, NULL, NULL),
385 ITEM_FACTORY_ENTRY("/Prepare a Filter/... a_nd not Selected", NULL, match_selected_plist_cb,
386 MATCH_SELECTED_AND_NOT, NULL, NULL),
387 ITEM_FACTORY_ENTRY("/Prepare a Filter/... o_r not Selected", NULL, match_selected_plist_cb,
388 MATCH_SELECTED_OR_NOT, NULL, NULL),
390 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
391 ITEM_FACTORY_ENTRY("/Coloring Rules...", NULL, color_display_cb,
393 ITEM_FACTORY_ENTRY("/Print...", NULL, file_print_cmd_cb, 0, NULL, NULL),
394 ITEM_FACTORY_ENTRY("/Show Packet in New Window", NULL, new_window_cb,
398 static GtkItemFactoryEntry tree_view_menu_items[] =
400 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
402 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
403 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
405 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
406 ITEM_FACTORY_ENTRY("/_Resolve Name", NULL, resolve_name_cb, 0, NULL, NULL),
407 ITEM_FACTORY_ENTRY("/_Go to Corresponding Packet", NULL, goto_framenum_cb, 0, NULL, NULL),
408 ITEM_FACTORY_ENTRY("/_Export Selected Packet Bytes...", NULL, savehex_cb,
410 ITEM_FACTORY_ENTRY("/Protocol Properties...", NULL, properties_cb,
412 ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
413 ITEM_FACTORY_ENTRY("/Apply as Filter/_Selected", NULL, match_selected_ptree_cb,
414 MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
415 ITEM_FACTORY_ENTRY("/Apply as Filter/_Not Selected", NULL, match_selected_ptree_cb,
416 MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
417 ITEM_FACTORY_ENTRY("/Apply as Filter/... _and Selected", NULL, match_selected_ptree_cb,
418 MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
419 ITEM_FACTORY_ENTRY("/Apply as Filter/... _or Selected", NULL, match_selected_ptree_cb,
420 MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
421 ITEM_FACTORY_ENTRY("/Apply as Filter/... a_nd not Selected", NULL, match_selected_ptree_cb,
422 MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
423 ITEM_FACTORY_ENTRY("/Apply as Filter/... o_r not Selected", NULL, match_selected_ptree_cb,
424 MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
426 ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
427 ITEM_FACTORY_ENTRY("/Prepare a Filter/_Selected", NULL, match_selected_ptree_cb,
428 MATCH_SELECTED_REPLACE, NULL, NULL),
429 ITEM_FACTORY_ENTRY("/Prepare a Filter/_Not Selected", NULL, match_selected_ptree_cb,
430 MATCH_SELECTED_NOT, NULL, NULL),
431 ITEM_FACTORY_ENTRY("/Prepare a Filter/... _and Selected", NULL, match_selected_ptree_cb,
432 MATCH_SELECTED_AND, NULL, NULL),
433 ITEM_FACTORY_ENTRY("/Prepare a Filter/... _or Selected", NULL, match_selected_ptree_cb,
434 MATCH_SELECTED_OR, NULL, NULL),
435 ITEM_FACTORY_ENTRY("/Prepare a Filter/... a_nd not Selected", NULL, match_selected_ptree_cb,
436 MATCH_SELECTED_AND_NOT, NULL, NULL),
437 ITEM_FACTORY_ENTRY("/Prepare a Filter/... o_r not Selected", NULL, match_selected_ptree_cb,
438 MATCH_SELECTED_OR_NOT, NULL, NULL),
439 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
440 ITEM_FACTORY_ENTRY("/Collapse All", NULL, collapse_all_cb, 0, NULL, NULL),
441 ITEM_FACTORY_ENTRY("/Expand All", NULL, expand_all_cb, 0, NULL, NULL),
442 ITEM_FACTORY_ENTRY("/Expand Tree", NULL, expand_tree_cb, 0, NULL, NULL)
445 static GtkItemFactoryEntry hexdump_menu_items[] =
447 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
449 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
450 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
452 ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb,
456 static int initialize = TRUE;
457 static GtkItemFactory *main_menu_factory = NULL;
458 static GtkItemFactory *packet_list_menu_factory = NULL;
459 static GtkItemFactory *tree_view_menu_factory = NULL;
460 static GtkItemFactory *hexdump_menu_factory = NULL;
462 static GSList *popup_menu_list = NULL;
464 static GtkAccelGroup *grp;
467 main_menu_new(GtkAccelGroup ** table) {
470 grp = gtk_accel_group_new();
475 menubar = main_menu_factory->widget;
489 packet_list_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
490 popup_menu_object = gtk_menu_new();
491 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);
492 OBJECT_SET_DATA(popup_menu_object, PM_PACKET_LIST_KEY,
493 packet_list_menu_factory->widget);
494 popup_menu_list = g_slist_append((GSList *)popup_menu_list, packet_list_menu_factory);
496 tree_view_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
497 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);
498 OBJECT_SET_DATA(popup_menu_object, PM_TREE_VIEW_KEY,
499 tree_view_menu_factory->widget);
500 popup_menu_list = g_slist_append((GSList *)popup_menu_list, tree_view_menu_factory);
502 hexdump_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
503 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);
504 OBJECT_SET_DATA(popup_menu_object, PM_HEXDUMP_KEY,
505 hexdump_menu_factory->widget);
506 popup_menu_list = g_slist_append((GSList *)popup_menu_list, hexdump_menu_factory);
509 main_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", grp);
510 gtk_item_factory_create_items_ac(main_menu_factory, nmenu_items, menu_items, NULL, 2);
512 merge_all_tap_menus(tap_menu_tree_root);
514 /* Initialize enabled/disabled state of menu items */
515 set_menus_for_unsaved_capture_file(FALSE);
516 set_menus_for_capture_file(FALSE);
518 /* Un-#if this when we actually implement Cut/Copy/Paste.
519 Then make sure you enable them when they can be done. */
520 set_menu_sensitivity(main_menu_factory, "/Edit/Cut", FALSE);
521 set_menu_sensitivity(main_menu_factory, "/Edit/Copy", FALSE);
522 set_menu_sensitivity(main_menu_factory, "/Edit/Paste", FALSE);
525 set_menus_for_captured_packets(FALSE);
526 set_menus_for_selected_packet(&cfile);
527 set_menus_for_selected_tree_row(&cfile);
529 /* init with an empty recent files list */
530 clear_menu_recent_capture_file_cmd_cb(NULL, NULL);
535 gint tap_menu_item_add_compare(gconstpointer a, gconstpointer b)
538 ((const menu_item_t *) a)->name,
539 ((const menu_item_t *) b)->name);
543 /* add a menuitem below the current node */
544 GList * tap_menu_item_add(
547 GtkItemFactoryCallback callback,
548 gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *),
549 gboolean (*selected_tree_row_enabled)(field_info *),
550 gpointer callback_data,
557 child = g_malloc(sizeof (menu_item_t));
558 child->group = group;
560 child->callback = callback;
561 child->selected_packet_enabled = selected_packet_enabled;
562 child->selected_tree_row_enabled = selected_tree_row_enabled;
563 child->callback_data = callback_data;
564 child->enabled = FALSE;
565 child->children = NULL;
567 /* insert the new child node into the parent */
568 curr = curnode->data;
569 curr->children = g_list_insert_sorted(curr->children, child, tap_menu_item_add_compare);
571 /* return the new node */
572 /* XXX: improve this */
573 return g_list_find(curr->children, child);
577 * Add a new menu item for a tap.
578 * This must be called after we've created the main menu, so it can't
579 * be called from the routine that registers taps - we have to introduce
580 * another per-tap registration routine.
582 * "callback" gets called when the menu item is selected; it should do
583 * the work of creating the tap window.
585 * "selected_packet_enabled" gets called by "set_menus_for_selected_packet()";
586 * it's passed a Boolean that's TRUE if a packet is selected and FALSE
587 * otherwise, and should return TRUE if the tap will work now (which
588 * might depend on whether a packet is selected and, if one is, on the
589 * packet) and FALSE if not.
591 * "selected_tree_row_enabled" gets called by
592 * "set_menus_for_selected_tree_row()"; it's passed a Boolean that's TRUE if
593 * a protocol tree row is selected and FALSE otherwise, and should return
594 * TRUE if the tap will work now (which might depend on whether a tree row
595 * is selected and, if one is, on the tree row) and FALSE if not.
598 register_tap_menu_item(
600 REGISTER_TAP_GROUP_E group,
601 GtkItemFactoryCallback callback,
602 gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *),
603 gboolean (*selected_tree_row_enabled)(field_info *),
604 gpointer callback_data)
606 /*static const char toolspath[] = "/Statistics/";*/
616 * The menu path must be relative.
618 g_assert(*name != '/');
621 case(REGISTER_TAP_GROUP_GENERIC): toolspath = "/Statistics/"; break;
622 case(REGISTER_TAP_GROUP_CONVERSATION_LIST): toolspath = "/Statistics/_Conversation List/"; break;
623 case(REGISTER_TAP_GROUP_ENDPOINT_LIST): toolspath = "/Statistics/_Endpoint List/"; break;
624 case(REGISTER_TAP_GROUP_RESPONSE_TIME): toolspath = "/Statistics/Service _Response Time/"; break;
625 case(REGISTER_TAP_GROUP_NONE): toolspath = "/Statistics/"; break;
631 /* add the (empty) root node, if not already done */
632 if(tap_menu_tree_root == NULL) {
633 child = g_malloc0(sizeof (menu_item_t));
634 tap_menu_tree_root = g_list_append(NULL, child);
638 * Create any submenus required.
640 curnode = tap_menu_tree_root;
642 while ((p = strchr(p, '/')) != NULL) {
644 * OK, everything between "name" and "p" is
645 * a menu relative subtree into which the menu item
648 * Construct the absolute path name of that subtree.
650 menupathlen = strlen(toolspath) + 1 + (p - name);
651 menupath = g_malloc(menupathlen);
652 strcpy(menupath, toolspath);
653 strncat(menupath, name, p - name);
656 * Does there exist an entry with that path at this
657 * level of the Analyze menu tree?
659 child = curnode->data;
660 for (childnode = child->children; childnode != NULL; childnode = childnode->next) {
661 child = childnode->data;
662 if (strcmp(child->name, menupath) == 0)
665 if (childnode == NULL) {
667 * No. Create such an item as a subtree, and
668 * add it to the Tools menu tree.
670 childnode = tap_menu_item_add(
671 menupath, group, NULL, NULL ,NULL, NULL, curnode);
674 * Yes. We don't need this "menupath" any longer.
681 * Skip over the '/' we found.
687 * Construct the main menu path for the menu item.
689 menupathlen = strlen(toolspath) + 1 + strlen(name);
690 menupath = g_malloc(menupathlen);
691 strcpy(menupath, toolspath);
692 strcat(menupath, name);
695 * Construct an item factory entry for the item, and add it to
699 menupath, group, callback,
700 selected_packet_enabled, selected_tree_row_enabled,
701 callback_data, curnode);
705 guint merge_tap_menus_layered(GList *node, gint group) {
706 GtkItemFactoryEntry *entry;
709 menu_item_t *node_data = node->data;
712 * Is this a leaf node or an interior node?
714 if (node_data->children == NULL) {
720 * The root node doesn't correspond to a menu tree item; it
721 * has a null name pointer.
723 if (node_data->name != NULL && group == node_data->group) {
724 entry = g_malloc0(sizeof (GtkItemFactoryEntry));
725 entry->path = node_data->name;
726 entry->callback = node_data->callback;
727 gtk_item_factory_create_item(main_menu_factory, entry, node_data->callback_data, 2);
728 set_menu_sensitivity(main_menu_factory, node_data->name, FALSE); /* no capture file yet */
733 * It's an interior node; call
734 * "merge_tap_menus_layered()" on all its children
738 * The root node doesn't correspond to a menu tree item; it
739 * has a null name pointer.
741 if (node_data->name != NULL && group == node_data->group) {
742 entry = g_malloc0(sizeof (GtkItemFactoryEntry));
743 entry->path = node_data->name;
744 entry->item_type = "<Branch>";
745 gtk_item_factory_create_item(main_menu_factory, entry,
747 set_menu_sensitivity(main_menu_factory, node_data->name,
748 FALSE); /* no children yet */
752 for (child = node_data->children; child != NULL; child =
754 added += merge_tap_menus_layered(child, group);
762 void merge_all_tap_menus(GList *node) {
763 GtkItemFactoryEntry *entry;
765 entry = g_malloc0(sizeof (GtkItemFactoryEntry));
766 entry->item_type = "<Separator>";
767 entry->path = "/Statistics/";
770 * merge only the menu items of the specific group,
771 * and then append a seperator
773 if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_GENERIC)) {
774 gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);
776 if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_CONVERSATION_LIST)) {
777 /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/
779 if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_ENDPOINT_LIST)) {
780 /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/
782 if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_RESPONSE_TIME)) {
783 gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);
785 if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_NONE)) {
786 /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/
793 * Enable/disable menu sensitivity.
796 set_menu_sensitivity(GtkItemFactory *ifactory, const gchar *path, gint val)
799 GtkWidget *menu_item;
804 /* the underscore character regularly confuses things, as it will prevent finding
805 * the menu_item, so it has to be removed first */
806 dup = g_strdup(path);
817 if (ifactory == NULL) {
819 * Do it for all pop-up menus.
821 for (menu_list = popup_menu_list; menu_list != NULL;
822 menu_list = g_slist_next(menu_list))
823 set_menu_sensitivity(menu_list->data, dup, val);
826 * Do it for that particular menu.
828 if ((menu_item = gtk_item_factory_get_widget(ifactory, dup)) != NULL) {
829 if (GTK_IS_MENU(menu_item)) {
831 * "dup" refers to a submenu; "gtk_item_factory_get_widget()"
832 * gets the menu, not the item that, when selected, pops up
835 * We have to change the latter item's sensitivity, so that
836 * it shows up normally if sensitive and grayed-out if
839 menu_item = gtk_menu_get_attach_widget(GTK_MENU(menu_item));
841 gtk_widget_set_sensitive(menu_item, val);
843 /* be sure this menu item *is* existing */
844 g_assert_not_reached();
852 set_menu_object_data_meat(GtkItemFactory *ifactory, gchar *path, gchar *key, gpointer data)
854 GtkWidget *menu = NULL;
856 if ((menu = gtk_item_factory_get_widget(ifactory, path)) != NULL)
857 OBJECT_SET_DATA(menu, key, data);
861 set_menu_object_data (gchar *path, gchar *key, gpointer data) {
862 GSList *menu_list = popup_menu_list;
863 gchar *shortpath = strrchr(path, '/');
865 set_menu_object_data_meat(main_menu_factory, path, key, data);
866 while (menu_list != NULL) {
867 set_menu_object_data_meat(menu_list->data, shortpath, key, data);
868 menu_list = g_slist_next(menu_list);
873 /* Recently used capture files submenu:
874 * Submenu containing the recently used capture files.
875 * The capture filenames are always kept with the absolute path, to be independant
876 * of the current path.
877 * They are only stored inside the labels of the submenu (no separate list). */
879 #define MENU_RECENT_FILES_PATH "/File/Open Recent"
880 #define MENU_RECENT_FILES_KEY "Recent File Name"
883 update_menu_recent_capture_file1(GtkWidget *widget, gpointer cnt) {
884 gchar *widget_cf_name;
886 widget_cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY);
888 /* if this menu item is a file, count it */
889 if (widget_cf_name) {
895 /* update the menu */
897 update_menu_recent_capture_file(GtkWidget *submenu_recent_files) {
900 gtk_container_foreach(GTK_CONTAINER(submenu_recent_files),
901 update_menu_recent_capture_file1, &cnt);
903 /* make parent menu item sensitive only, if we have any valid files in the list */
904 set_menu_sensitivity(main_menu_factory, MENU_RECENT_FILES_PATH, cnt);
908 /* remove the capture filename from the "Recent Files" menu */
910 remove_menu_recent_capture_file(GtkWidget *widget, gpointer unused _U_) {
911 GtkWidget *submenu_recent_files;
912 gchar *widget_cf_name;
915 widget_cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY);
916 g_free(widget_cf_name);
918 /* get the submenu container item */
919 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
921 /* XXX: is this all we need to do, to free the menu item and its label?
922 The reference count of widget will go to 0, so it'll be freed;
923 will that free the label? */
924 gtk_container_remove(GTK_CONTAINER(submenu_recent_files), widget);
928 /* callback, if the user pushed the <Clear File List> item */
930 clear_menu_recent_capture_file_cmd_cb(GtkWidget *w _U_, gpointer unused _U_) {
931 GtkWidget *submenu_recent_files;
934 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
936 gtk_container_foreach(GTK_CONTAINER(submenu_recent_files),
937 remove_menu_recent_capture_file, NULL);
939 update_menu_recent_capture_file(submenu_recent_files);
943 /* callback, if the user pushed a recent file submenu item */
945 menu_open_recent_file_cmd(GtkWidget *w)
947 GtkWidget *submenu_recent_files;
948 GtkWidget *menu_item_child;
952 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
954 /* get capture filename from the menu item label */
955 menu_item_child = (GTK_BIN(w))->child;
956 gtk_label_get(GTK_LABEL(menu_item_child), &cf_name);
958 /* open and read the capture file (this will close an existing file) */
959 if ((err = cf_open(cf_name, FALSE, &cfile)) == 0) {
962 /* the capture file isn't existing any longer, remove menu item */
963 /* XXX: ask user to remove item, it's maybe only a temporary problem */
964 remove_menu_recent_capture_file(w, NULL);
967 update_menu_recent_capture_file(submenu_recent_files);
970 static void menu_open_recent_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
974 /* save file first */
975 file_save_as_cmd(after_save_open_recent_file, data);
979 menu_open_recent_file_cmd(data);
981 case(ESD_BTN_CANCEL):
984 g_assert_not_reached();
989 menu_open_recent_file_cmd_cb(GtkWidget *widget, gpointer data _U_) {
993 if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
994 /* user didn't saved his current file, ask him */
995 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL,
996 PRIMARY_TEXT_START "Save capture file before opening a new one?" PRIMARY_TEXT_END "\n\n"
997 "If you open a new capture file without saving, your current capture data will be discarded.");
998 simple_dialog_set_cb(dialog, menu_open_recent_file_answered_cb, widget);
1000 /* unchanged file */
1001 menu_open_recent_file_cmd(widget);
1005 /* add the capture filename (with an absolute path) to the "Recent Files" menu */
1007 add_menu_recent_capture_file_absolute(gchar *cf_name) {
1008 GtkWidget *submenu_recent_files;
1009 GList *menu_item_list;
1011 gchar *widget_cf_name;
1012 gchar *normalized_cf_name;
1013 GtkWidget *menu_item;
1018 normalized_cf_name = g_strdup(cf_name);
1020 /* replace all slashes by backslashes */
1021 g_strdelimit(normalized_cf_name, "/", '\\');
1024 /* get the submenu container item */
1025 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
1027 /* convert container to a GList */
1028 menu_item_list = gtk_container_children(GTK_CONTAINER(submenu_recent_files));
1030 /* iterate through list items of menu_item_list,
1031 * removing special items, a maybe duplicate entry and every item above count_max */
1033 for (li = g_list_first(menu_item_list); li; li = li->next, cnt++) {
1034 /* get capture filename */
1035 menu_item = GTK_WIDGET(li->data);
1036 widget_cf_name = OBJECT_GET_DATA(menu_item, MENU_RECENT_FILES_KEY);
1038 /* if this element string is one of our special items (seperator, ...) or
1039 * already in the list or
1040 * this element is above maximum count (too old), remove it */
1041 if (!widget_cf_name ||
1043 /* do a case insensitive compare on win32 */
1044 #if GLIB_MAJOR_VERSION < 2
1045 g_strncasecmp(widget_cf_name, normalized_cf_name, 1000) == 0 ||
1047 g_ascii_strncasecmp(widget_cf_name, normalized_cf_name, 1000) == 0 ||
1050 /* do a case sensitive compare on unix */
1051 strncmp(widget_cf_name, normalized_cf_name, 1000) == 0 ||
1053 cnt >= prefs.gui_recent_files_count_max) {
1054 remove_menu_recent_capture_file(li->data, NULL);
1059 g_list_free(menu_item_list);
1061 /* add new item at latest position */
1062 menu_item = gtk_menu_item_new_with_label(normalized_cf_name);
1063 OBJECT_SET_DATA(menu_item, MENU_RECENT_FILES_KEY, normalized_cf_name);
1064 gtk_menu_prepend (GTK_MENU(submenu_recent_files), menu_item);
1065 SIGNAL_CONNECT_OBJECT(GTK_OBJECT(menu_item), "activate",
1066 menu_open_recent_file_cmd_cb, (GtkObject *) menu_item);
1067 gtk_widget_show (menu_item);
1069 /* add seperator at last position */
1070 menu_item = gtk_menu_item_new();
1071 gtk_menu_append (GTK_MENU(submenu_recent_files), menu_item);
1072 gtk_widget_show (menu_item);
1074 /* add new "clear list" item at last position */
1075 #if GTK_MAJOR_VERSION < 2
1076 menu_item = gtk_menu_item_new_with_label("<Clear File List>");
1078 menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLEAR, NULL);
1080 gtk_menu_append (GTK_MENU(submenu_recent_files), menu_item);
1081 SIGNAL_CONNECT_OBJECT(GTK_OBJECT(menu_item), "activate",
1082 clear_menu_recent_capture_file_cmd_cb, (GtkObject *) menu_item);
1083 gtk_widget_show (menu_item);
1085 update_menu_recent_capture_file(submenu_recent_files);
1089 /* add the capture filename to the "Recent Files" menu */
1090 /* (will change nothing, if this filename is already in the menu) */
1092 add_menu_recent_capture_file(gchar *cf_name) {
1097 /* if this filename is an absolute path, we can use it directly */
1098 if (g_path_is_absolute(cf_name)) {
1099 add_menu_recent_capture_file_absolute(cf_name);
1103 /* this filename is not an absolute path, prepend the current dir */
1104 curr = g_get_current_dir();
1105 absolute = g_strdup_printf("%s%s%s", curr, G_DIR_SEPARATOR_S, cf_name);
1106 add_menu_recent_capture_file_absolute(absolute);
1112 /* write all capture filenames of the menu to the user's recent file */
1114 menu_recent_file_write_all(FILE *rf) {
1115 GtkWidget *submenu_recent_files;
1121 submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
1123 /* we have to iterate backwards through the children's list,
1124 * so we get the latest item last in the file.
1125 * (don't use gtk_container_foreach() here, it will return the wrong iteration order) */
1126 children = gtk_container_children(GTK_CONTAINER(submenu_recent_files));
1127 child = g_list_last(children);
1128 while(child != NULL) {
1129 /* get capture filename from the menu item label */
1130 cf_name = OBJECT_GET_DATA(child->data, MENU_RECENT_FILES_KEY);
1132 fprintf (rf, RECENT_KEY_CAPTURE_FILE ": %s\n", cf_name);
1135 child = g_list_previous(child);
1138 g_list_free(children);
1143 main_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
1146 /* save current setting in recent */
1147 recent.main_toolbar_show = GTK_CHECK_MENU_ITEM(w)->active;
1149 main_widgets_show_or_hide();
1154 filter_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
1157 /* save current setting in recent */
1158 recent.filter_toolbar_show = GTK_CHECK_MENU_ITEM(w)->active;
1160 main_widgets_show_or_hide();
1165 packet_list_show_cb(GtkWidget *w _U_, gpointer d _U_)
1168 /* save current setting in recent */
1169 recent.packet_list_show = GTK_CHECK_MENU_ITEM(w)->active;
1171 main_widgets_show_or_hide();
1176 tree_view_show_cb(GtkWidget *w _U_, gpointer d _U_)
1179 /* save current setting in recent */
1180 recent.tree_view_show = GTK_CHECK_MENU_ITEM(w)->active;
1182 main_widgets_show_or_hide();
1187 byte_view_show_cb(GtkWidget *w _U_, gpointer d _U_)
1190 /* save current setting in recent */
1191 recent.byte_view_show = GTK_CHECK_MENU_ITEM(w)->active;
1193 main_widgets_show_or_hide();
1198 statusbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
1201 /* save current setting in recent */
1202 recent.statusbar_show = GTK_CHECK_MENU_ITEM(w)->active;
1204 main_widgets_show_or_hide();
1209 timestamp_absolute_cb(GtkWidget *w _U_, gpointer d _U_)
1211 if (recent.gui_time_format != TS_ABSOLUTE) {
1212 set_timestamp_setting(TS_ABSOLUTE);
1213 recent.gui_time_format = TS_ABSOLUTE;
1214 change_time_formats(&cfile);
1219 timestamp_absolute_date_cb(GtkWidget *w _U_, gpointer d _U_)
1221 if (recent.gui_time_format != TS_ABSOLUTE_WITH_DATE) {
1222 set_timestamp_setting(TS_ABSOLUTE_WITH_DATE);
1223 recent.gui_time_format = TS_ABSOLUTE_WITH_DATE;
1224 change_time_formats(&cfile);
1229 timestamp_relative_cb(GtkWidget *w _U_, gpointer d _U_)
1231 if (recent.gui_time_format != TS_RELATIVE) {
1232 set_timestamp_setting(TS_RELATIVE);
1233 recent.gui_time_format = TS_RELATIVE;
1234 change_time_formats(&cfile);
1239 timestamp_delta_cb(GtkWidget *w _U_, gpointer d _U_)
1241 if (recent.gui_time_format != TS_DELTA) {
1242 set_timestamp_setting(TS_DELTA);
1243 recent.gui_time_format = TS_DELTA;
1244 change_time_formats(&cfile);
1249 menu_name_resolution_changed(void)
1251 GtkWidget *menu = NULL;
1253 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for MAC Layer");
1254 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_MAC);
1256 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for Network Layer");
1257 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_NETWORK);
1259 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for Transport Layer");
1260 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_TRANSPORT);
1264 name_resolution_mac_cb(GtkWidget *w _U_, gpointer d _U_)
1266 if (GTK_CHECK_MENU_ITEM(w)->active) {
1267 g_resolv_flags |= RESOLV_MAC;
1269 g_resolv_flags &= ~RESOLV_MAC;
1274 name_resolution_network_cb(GtkWidget *w _U_, gpointer d _U_)
1276 if (GTK_CHECK_MENU_ITEM(w)->active) {
1277 g_resolv_flags |= RESOLV_NETWORK;
1279 g_resolv_flags &= ~RESOLV_NETWORK;
1284 name_resolution_transport_cb(GtkWidget *w _U_, gpointer d _U_)
1286 if (GTK_CHECK_MENU_ITEM(w)->active) {
1287 g_resolv_flags |= RESOLV_TRANSPORT;
1289 g_resolv_flags &= ~RESOLV_TRANSPORT;
1295 auto_scroll_live_cb(GtkWidget *w _U_, gpointer d _U_)
1297 auto_scroll_live = GTK_CHECK_MENU_ITEM(w)->active;
1301 /* the recent file read has finished, update the menu corresponding */
1303 menu_recent_read_finished(void) {
1304 GtkWidget *menu = NULL;
1306 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Main Toolbar");
1307 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.main_toolbar_show);
1309 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Filter Toolbar");
1310 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.filter_toolbar_show);
1312 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Statusbar");
1313 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.statusbar_show);
1315 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet List");
1316 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.packet_list_show);
1318 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet Details");
1319 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.tree_view_show);
1321 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet Bytes");
1322 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.byte_view_show);
1324 menu_name_resolution_changed();
1327 menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Auto Scroll in Live Capture");
1328 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), auto_scroll_live);
1331 main_widgets_rearrange();
1333 /* don't change the time format, if we had a command line value */
1334 if (get_timestamp_setting() != TS_NOT_SET) {
1335 recent.gui_time_format = get_timestamp_setting();
1338 switch(recent.gui_time_format) {
1340 menu = gtk_item_factory_get_widget(main_menu_factory,
1341 "/View/Time Display Format/Time of Day");
1342 /* set_active will not trigger the callback when activating an active item! */
1343 recent.gui_time_format = -1;
1344 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), FALSE);
1345 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
1347 case(TS_ABSOLUTE_WITH_DATE):
1348 menu = gtk_item_factory_get_widget(main_menu_factory,
1349 "/View/Time Display Format/Date and Time of Day");
1350 recent.gui_time_format = -1;
1351 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
1354 menu = gtk_item_factory_get_widget(main_menu_factory,
1355 "/View/Time Display Format/Seconds Since Beginning of Capture");
1356 recent.gui_time_format = -1;
1357 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
1360 menu = gtk_item_factory_get_widget(main_menu_factory,
1361 "/View/Time Display Format/Seconds Since Previous Packet");
1362 recent.gui_time_format = -1;
1363 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
1366 g_assert_not_reached();
1372 popup_menu_handler(GtkWidget *widget, GdkEvent *event, gpointer data)
1374 GtkWidget *menu = (GtkWidget *)data;
1375 GdkEventButton *event_button = NULL;
1378 if(widget == NULL || event == NULL || data == NULL) {
1383 * If we ever want to make the menu differ based on what row
1384 * and/or column we're above, we'd use "eth_clist_get_selection_info()"
1385 * to find the row and column number for the coordinates; a CTree is,
1386 * I guess, like a CList with one column(?) and the expander widget
1389 /* Check if we are on packet_list object */
1390 if (widget == OBJECT_GET_DATA(popup_menu_object, E_MPACKET_LIST_KEY)) {
1391 if (packet_list_get_event_row_column(widget, (GdkEventButton *)event,
1393 OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_ROW_KEY,
1394 GINT_TO_POINTER(row));
1395 OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_COL_KEY,
1396 GINT_TO_POINTER(column));
1397 packet_list_set_selected_row(row);
1401 /* Check if we are on tree_view object */
1402 if (widget == tree_view) {
1403 tree_view_select(widget, (GdkEventButton *) event);
1406 /* Check if we are on byte_view object */
1407 if(widget == get_notebook_bv_ptr(byte_nb_ptr)) {
1408 byte_view_select(widget, (GdkEventButton *) event);
1411 /* context menu handler (but the byte view notebook pages have their own handler) */
1412 if(event->type == GDK_BUTTON_PRESS && widget != byte_nb_ptr) {
1413 event_button = (GdkEventButton *) event;
1415 /* To qoute the "Gdk Event Structures" doc:
1416 * "Normally button 1 is the left mouse button, 2 is the middle button, and 3 is the right button" */
1417 if(event_button->button == 3) {
1418 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
1419 event_button->button,
1420 event_button->time);
1421 SIGNAL_EMIT_STOP_BY_NAME(widget, "button_press_event");
1425 #if GTK_MAJOR_VERSION >= 2
1426 /* GDK_2BUTTON_PRESS is a doubleclick -> expand/collapse tree row */
1427 /* GTK version 1 seems to be doing this automatically */
1428 if (widget == tree_view && event->type == GDK_2BUTTON_PRESS) {
1431 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget),
1432 (gint) (((GdkEventButton *)event)->x),
1433 (gint) (((GdkEventButton *)event)->y),
1434 &path, NULL, NULL, NULL))
1436 if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(widget), path))
1437 gtk_tree_view_collapse_row(GTK_TREE_VIEW(widget), path);
1439 gtk_tree_view_expand_row(GTK_TREE_VIEW(widget), path,
1441 gtk_tree_path_free(path);
1448 /* Enable or disable menu items based on whether you have a capture file
1449 you've finished reading. */
1451 set_menus_for_capture_file(gboolean have_capture_file)
1453 set_menu_sensitivity(main_menu_factory, "/File/Open...", have_capture_file);
1454 set_menu_sensitivity(main_menu_factory, "/File/Open Recent", have_capture_file);
1455 set_menu_sensitivity(main_menu_factory, "/File/Merge...", have_capture_file);
1456 set_menu_sensitivity(main_menu_factory, "/File/Close", have_capture_file);
1457 set_menu_sensitivity(main_menu_factory, "/File/Save As...",
1459 set_menu_sensitivity(main_menu_factory, "/File/Export", have_capture_file);
1460 set_menu_sensitivity(main_menu_factory, "/View/Reload", have_capture_file);
1461 set_toolbar_for_capture_file(have_capture_file);
1462 packets_bar_update();
1465 /* Enable or disable menu items based on whether you have an unsaved
1466 capture file you've finished reading. */
1468 set_menus_for_unsaved_capture_file(gboolean have_unsaved_capture_file)
1470 set_menu_sensitivity(main_menu_factory, "/File/Save",
1471 have_unsaved_capture_file);
1472 set_toolbar_for_unsaved_capture_file(have_unsaved_capture_file);
1475 /* Enable or disable menu items based on whether there's a capture in
1478 set_menus_for_capture_in_progress(gboolean capture_in_progress)
1480 set_menu_sensitivity(main_menu_factory, "/File/Open...",
1481 !capture_in_progress);
1482 set_menu_sensitivity(main_menu_factory, "/File/Open Recent",
1483 !capture_in_progress);
1485 set_menu_sensitivity(main_menu_factory, "/Capture/Start...",
1486 !capture_in_progress);
1487 set_menu_sensitivity(main_menu_factory, "/Capture/Stop",
1488 capture_in_progress);
1489 #endif /* HAVE_LIBPCAP */
1490 set_toolbar_for_capture_in_progress(capture_in_progress);
1493 /* Enable or disable menu items based on whether you have some captured
1496 walk_menu_tree_for_captured_packets(GList *node,
1497 gboolean have_captured_packets)
1499 gboolean is_enabled;
1501 menu_item_t *node_data = node->data;
1504 * Is this a leaf node or an interior node?
1506 if (node_data->children == NULL) {
1510 * If it has no "selected_packet_enabled()" or
1511 * "selected_tree_row_enabled()" routines, we enable
1512 * it. This allows tap windows to be popped up even
1513 * if you have no capture file; this is done to let
1514 * the user pop up multiple tap windows before reading
1515 * in a capture file, so that they can be processed in
1516 * parallel while the capture file is being read rather
1517 * than one at at time as you pop up the windows, and to
1518 * let the user pop up tap windows before starting an
1519 * "Update list of packets in real time" capture, so that
1520 * the statistics can be displayed while the capture is
1523 * If it has either of those routines, we disable it for
1524 * now - as long as, when a capture is first available,
1525 * we don't get called after a packet or tree row is
1526 * selected, that's OK.
1527 * XXX - that should be done better.
1529 if (node_data->selected_packet_enabled == NULL &&
1530 node_data->selected_tree_row_enabled == NULL)
1531 node_data->enabled = TRUE;
1533 node_data->enabled = FALSE;
1536 * It's an interior node; call
1537 * "walk_menu_tree_for_captured_packets()" on all its
1538 * children and, if any of them are enabled, enable
1539 * this node, otherwise disable it.
1541 * XXX - should we just leave all interior nodes enabled?
1542 * Which is a better UI choice?
1545 for (child = node_data->children; child != NULL; child =
1547 if (walk_menu_tree_for_captured_packets(child,
1548 have_captured_packets))
1551 node_data->enabled = is_enabled;
1555 * The root node doesn't correspond to a menu tree item; it
1556 * has a null name pointer.
1558 if (node_data->name != NULL) {
1559 set_menu_sensitivity(main_menu_factory, node_data->name,
1560 node_data->enabled);
1562 return node_data->enabled;
1566 set_menus_for_captured_packets(gboolean have_captured_packets)
1568 set_menu_sensitivity(main_menu_factory, "/File/Print...",
1569 have_captured_packets);
1570 set_menu_sensitivity(packet_list_menu_factory, "/Print...",
1571 have_captured_packets);
1572 set_menu_sensitivity(main_menu_factory, "/Edit/Find Packet...",
1573 have_captured_packets);
1574 set_menu_sensitivity(main_menu_factory, "/Edit/Find Next",
1575 have_captured_packets);
1576 set_menu_sensitivity(main_menu_factory, "/Edit/Find Previous",
1577 have_captured_packets);
1578 set_menu_sensitivity(main_menu_factory, "/View/Zoom In",
1579 have_captured_packets);
1580 set_menu_sensitivity(main_menu_factory, "/View/Zoom Out",
1581 have_captured_packets);
1582 set_menu_sensitivity(main_menu_factory, "/View/Normal Size",
1583 have_captured_packets);
1584 set_menu_sensitivity(packet_list_menu_factory, "/Coloring Rules...",
1585 have_captured_packets);
1586 set_menu_sensitivity(main_menu_factory, "/Go/Go to Packet...",
1587 have_captured_packets);
1588 set_menu_sensitivity(main_menu_factory, "/Go/First Packet",
1589 have_captured_packets);
1590 set_menu_sensitivity(main_menu_factory, "/Go/Last Packet",
1591 have_captured_packets);
1592 set_menu_sensitivity(main_menu_factory, "/Statistics/Summary",
1593 have_captured_packets);
1594 set_menu_sensitivity(main_menu_factory, "/Statistics/Protocol Hierarchy",
1595 have_captured_packets);
1597 walk_menu_tree_for_captured_packets(tap_menu_tree_root,
1598 have_captured_packets);
1599 set_toolbar_for_captured_packets(have_captured_packets);
1600 packets_bar_update();
1603 /* Enable or disable menu items based on whether a packet is selected and,
1604 if so, on the properties of the packet. */
1606 walk_menu_tree_for_selected_packet(GList *node, frame_data *fd,
1607 epan_dissect_t *edt)
1609 gboolean is_enabled;
1611 menu_item_t *node_data = node->data;
1614 * Is this a leaf node or an interior node?
1616 if (node_data->children == NULL) {
1620 * If it has no "selected_packet_enabled()" routine,
1621 * leave its enabled/disabled status alone - it
1622 * doesn't depend on whether we have a packet selected
1623 * or not or on the selected packet.
1625 * If it has a "selected_packet_enabled()" routine,
1626 * call it and set the item's enabled/disabled status
1627 * based on its return value.
1629 if (node_data->selected_packet_enabled != NULL)
1630 node_data->enabled = node_data->selected_packet_enabled(fd, edt);
1633 * It's an interior node; call
1634 * "walk_menu_tree_for_selected_packet()" on all its
1635 * children and, if any of them are enabled, enable
1636 * this node, otherwise disable it.
1638 * XXX - should we just leave all interior nodes enabled?
1639 * Which is a better UI choice?
1642 for (child = node_data->children; child != NULL; child =
1644 if (walk_menu_tree_for_selected_packet(child, fd, edt))
1647 node_data->enabled = is_enabled;
1651 * The root node doesn't correspond to a menu tree item; it
1652 * has a null name pointer.
1654 if (node_data->name != NULL) {
1655 set_menu_sensitivity(main_menu_factory, node_data->name,
1656 node_data->enabled);
1658 return node_data->enabled;
1662 set_menus_for_selected_packet(capture_file *cf)
1664 set_menu_sensitivity(main_menu_factory, "/Edit/Mark Packet",
1665 cf->current_frame != NULL);
1666 set_menu_sensitivity(packet_list_menu_factory, "/Mark Packet",
1667 cf->current_frame != NULL);
1668 set_menu_sensitivity(main_menu_factory, "/Edit/Time Reference",
1669 cf->current_frame != NULL);
1670 set_menu_sensitivity(packet_list_menu_factory, "/Time Reference",
1671 cf->current_frame != NULL);
1672 set_menu_sensitivity(main_menu_factory, "/Edit/Mark All Packets",
1673 cf->current_frame != NULL);
1674 set_menu_sensitivity(main_menu_factory, "/Edit/Unmark All Packets",
1675 cf->current_frame != NULL);
1676 set_menu_sensitivity(main_menu_factory, "/View/Collapse All",
1677 cf->current_frame != NULL);
1678 set_menu_sensitivity(tree_view_menu_factory, "/Collapse All",
1679 cf->current_frame != NULL);
1680 set_menu_sensitivity(main_menu_factory, "/View/Expand All",
1681 cf->current_frame != NULL);
1682 set_menu_sensitivity(tree_view_menu_factory, "/Expand All",
1683 cf->current_frame != NULL);
1684 set_menu_sensitivity(main_menu_factory, "/View/Show Packet in New Window",
1685 cf->current_frame != NULL);
1686 set_menu_sensitivity(packet_list_menu_factory, "/Show Packet in New Window",
1687 cf->current_frame != NULL);
1688 set_menu_sensitivity(main_menu_factory, "/Analyze/Follow TCP Stream",
1689 cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
1690 set_menu_sensitivity(NULL, "/Follow TCP Stream",
1691 cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
1692 set_menu_sensitivity(main_menu_factory, "/Analyze/Decode As...",
1693 cf->current_frame != NULL && decode_as_ok());
1694 set_menu_sensitivity(NULL, "/Decode As...",
1695 cf->current_frame != NULL && decode_as_ok());
1696 set_menu_sensitivity(tree_view_menu_factory, "/Resolve Name",
1697 cf->current_frame != NULL && (g_resolv_flags & RESOLV_ALL_ADDRS) != RESOLV_ALL_ADDRS);
1698 set_menu_sensitivity(packet_list_menu_factory, "/Apply as Filter",
1699 cf->current_frame != NULL);
1700 set_menu_sensitivity(packet_list_menu_factory, "/Prepare a Filter",
1701 cf->current_frame != NULL);
1703 walk_menu_tree_for_selected_packet(tap_menu_tree_root, cf->current_frame,
1705 packets_bar_update();
1708 /* Enable or disable menu items based on whether a tree row is selected
1709 and, if so, on the properties of the tree row. */
1711 walk_menu_tree_for_selected_tree_row(GList *node, field_info *fi)
1713 gboolean is_enabled;
1715 menu_item_t *node_data = node->data;
1718 * Is this a leaf node or an interior node?
1720 if (node_data->children == NULL) {
1724 * If it has no "selected_tree_row_enabled()" routine,
1725 * leave its enabled/disabled status alone - it
1726 * doesn't depend on whether we have a tree row selected
1727 * or not or on the selected tree row.
1729 * If it has a "selected_tree_row_enabled()" routine,
1730 * call it and set the item's enabled/disabled status
1731 * based on its return value.
1733 if (node_data->selected_tree_row_enabled != NULL)
1734 node_data->enabled = node_data->selected_tree_row_enabled(fi);
1737 * It's an interior node; call
1738 * "walk_menu_tree_for_selected_tree_row()" on all its
1739 * children and, if any of them are enabled, enable
1740 * this node, otherwise disable it.
1742 * XXX - should we just leave all interior nodes enabled?
1743 * Which is a better UI choice?
1746 for (child = node_data->children; child != NULL; child =
1748 if (walk_menu_tree_for_selected_tree_row(child, fi))
1751 node_data->enabled = is_enabled;
1755 * The root node doesn't correspond to a menu tree item; it
1756 * has a null name pointer.
1758 if (node_data->name != NULL) {
1759 set_menu_sensitivity(main_menu_factory, node_data->name,
1760 node_data->enabled);
1762 return node_data->enabled;
1766 set_menus_for_selected_tree_row(capture_file *cf)
1768 gboolean properties;
1771 set_menu_sensitivity(main_menu_factory, "/File/Export/Selected Packet Bytes...",
1772 cf->finfo_selected != NULL);
1773 set_menu_sensitivity(tree_view_menu_factory, "/Export Selected Packet Bytes...",
1774 cf->finfo_selected != NULL);
1775 set_menu_sensitivity(hexdump_menu_factory, "/Export Selected Packet Bytes...",
1776 cf->finfo_selected != NULL);
1778 if (cf->finfo_selected != NULL) {
1779 header_field_info *hfinfo = cf->finfo_selected->hfinfo;
1780 if (hfinfo->parent == -1) {
1781 properties = prefs_is_registered_protocol(hfinfo->abbrev);
1783 properties = prefs_is_registered_protocol(proto_registrar_get_abbrev(hfinfo->parent));
1785 set_menu_sensitivity(main_menu_factory,
1786 "/Go/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM);
1787 set_menu_sensitivity(tree_view_menu_factory,
1788 "/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM);
1789 set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter",
1790 proto_can_match_selected(cf->finfo_selected, cf->edt));
1791 set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter",
1792 proto_can_match_selected(cf->finfo_selected, cf->edt));
1793 set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter",
1794 proto_can_match_selected(cf->finfo_selected, cf->edt));
1795 set_menu_sensitivity(tree_view_menu_factory, "/Prepare a Filter",
1796 proto_can_match_selected(cf->finfo_selected, cf->edt));
1797 set_menu_sensitivity(tree_view_menu_factory, "/Protocol Properties...",
1799 set_menu_sensitivity(main_menu_factory, "/View/Expand Tree", cf->finfo_selected->tree_type != -1);
1800 set_menu_sensitivity(tree_view_menu_factory, "/Expand Tree", cf->finfo_selected->tree_type != -1);
1802 set_menu_sensitivity(main_menu_factory,
1803 "/Go/Go to Corresponding Packet", FALSE);
1804 set_menu_sensitivity(tree_view_menu_factory,
1805 "/Go to Corresponding Packet", FALSE);
1806 set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter", FALSE);
1807 set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter", FALSE);
1808 set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter", FALSE);
1809 set_menu_sensitivity(tree_view_menu_factory, "/Prepare a Filter", FALSE);
1810 set_menu_sensitivity(tree_view_menu_factory, "/Protocol Properties...",
1812 set_menu_sensitivity(main_menu_factory, "/View/Expand Tree", FALSE);
1813 set_menu_sensitivity(tree_view_menu_factory, "/Expand Tree", FALSE);
1816 walk_menu_tree_for_selected_tree_row(tap_menu_tree_root, cf->finfo_selected);