return TRUE;
}
+/*
+ * Can this capture file be saved in any format except by copying the raw data?
+ */
+gboolean
+cf_can_save_as(capture_file *cf)
+{
+ int ft;
+
+ for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
+ /* To save a file with Wiretap, Wiretap has to handle that format,
+ and its code to handle that format must be able to write a file
+ with this file's encapsulation type. */
+ if (wtap_dump_can_open(ft) && wtap_dump_can_write_encap(ft, cf->lnk_t)) {
+ /* OK, we can write it out in this type. */
+ return TRUE;
+ }
+ }
+
+ /* No, we couldn't save it in any format. */
+ return FALSE;
+}
+
cf_status_t
cf_save(capture_file *cf, const char *fname, packet_range_t *range, guint save_format, gboolean compressed)
{
set_main_window_name("The Wireshark Network Analyzer");
/* Disable all menu items that make sense only if you have a capture. */
- set_menus_for_capture_file(FALSE);
- set_menus_for_unsaved_capture_file(FALSE);
+ set_menus_for_capture_file(NULL);
set_menus_for_captured_packets(FALSE);
set_menus_for_selected_packet(cf);
set_menus_for_capture_in_progress(FALSE);
set_display_filename(cf);
/* Enable menu items that make sense if you have a capture file you've
- finished reading. */
- set_menus_for_capture_file(TRUE);
- set_menus_for_unsaved_capture_file(!cf->user_saved);
+ finished reading. */
+ set_menus_for_capture_file(cf);
/* Enable menu items that make sense if you have some captured packets. */
set_menus_for_captured_packets(TRUE);
set_menus_for_capture_in_progress(FALSE);
/* Enable menu items that make sense if you have a capture file
- you've finished reading. */
- set_menus_for_capture_file(TRUE);
- set_menus_for_unsaved_capture_file(!cf->user_saved);
+ you've finished reading. */
+ set_menus_for_capture_file(cf);
/* Set up main window for a capture file. */
main_set_for_capture_file(TRUE);
static void
main_cf_cb_file_safe_reload_finished(gpointer data _U_)
{
- set_menus_for_unsaved_capture_file(FALSE);
+ set_menus_for_capture_file(&cfile);
}
static void main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
merge_all_tap_menus(tap_menu_tree_root);
/* Initialize enabled/disabled state of menu items */
- set_menus_for_unsaved_capture_file(FALSE);
- set_menus_for_capture_file(FALSE);
+ set_menus_for_capture_file(NULL);
#if 0
/* Un-#if this when we actually implement Cut/Copy/Paste.
Then make sure you enable them when they can be done. */
}
/* Enable or disable menu items based on whether you have a capture file
- you've finished reading. */
+ you've finished reading and, if you have one, whether it's been saved
+ and whether it could be saved except by copying the raw packet data. */
void
-set_menus_for_capture_file(gboolean have_capture_file)
+set_menus_for_capture_file(capture_file *cf)
{
- set_menu_sensitivity(main_menu_factory, "/File/Open...", have_capture_file);
- set_menu_sensitivity(main_menu_factory, "/File/Open Recent", have_capture_file);
- set_menu_sensitivity(main_menu_factory, "/File/Merge...", have_capture_file);
- set_menu_sensitivity(main_menu_factory, "/File/Close", have_capture_file);
- set_menu_sensitivity(main_menu_factory, "/File/Save As...",
- have_capture_file);
- set_menu_sensitivity(main_menu_factory, "/File/Export", have_capture_file);
- set_menu_sensitivity(main_menu_factory, "/View/Reload", have_capture_file);
- set_toolbar_for_capture_file(have_capture_file);
+ if (cf == NULL) {
+ /* We have no capture file */
+ set_menu_sensitivity(main_menu_factory, "/File/Merge...", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/File/Close", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/File/Save", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/File/Save As...", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/File/Export", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/View/Reload", FALSE);
+ set_toolbar_for_capture_file(FALSE);
+ set_toolbar_for_unsaved_capture_file(FALSE);
+ } else {
+ set_menu_sensitivity(main_menu_factory, "/File/Merge...", TRUE);
+ set_menu_sensitivity(main_menu_factory, "/File/Close", TRUE);
+ set_menu_sensitivity(main_menu_factory, "/File/Save", !cf->user_saved);
+ /*
+ * "Save As..." works only if we can write the file out in at least
+ * one format (so we can save the whole file or just a subset) or
+ * if we have an unsaved capture (so writing the whole file out
+ * with a raw data copy makes sense).
+ */
+ set_menu_sensitivity(main_menu_factory, "/File/Save As...",
+ cf_can_save_as(cf) || !cf->user_saved);
+ set_menu_sensitivity(main_menu_factory, "/File/Export", TRUE);
+ set_menu_sensitivity(main_menu_factory, "/View/Reload", TRUE);
+ set_toolbar_for_unsaved_capture_file(!cf->user_saved);
+ set_toolbar_for_capture_file(TRUE);
+ }
packets_bar_update();
}
-/* Enable or disable menu items based on whether you have an unsaved
- capture file you've finished reading. */
-void
-set_menus_for_unsaved_capture_file(gboolean have_unsaved_capture_file)
-{
- set_menu_sensitivity(main_menu_factory, "/File/Save",
- have_unsaved_capture_file);
- set_toolbar_for_unsaved_capture_file(have_unsaved_capture_file);
-}
-
/* Enable or disable menu items based on whether there's a capture in
progress. */
void