diff options
-rw-r--r-- | ui/gtk/capture_file_dlg.c | 70 | ||||
-rw-r--r-- | ui/gtk/capture_file_dlg.h | 8 | ||||
-rw-r--r-- | ui/gtk/export_pdu_dlg.c | 63 | ||||
-rw-r--r-- | ui/gtk/export_pdu_dlg.h | 1 |
4 files changed, 109 insertions, 33 deletions
diff --git a/ui/gtk/capture_file_dlg.c b/ui/gtk/capture_file_dlg.c index 0c97311512..36523058ed 100644 --- a/ui/gtk/capture_file_dlg.c +++ b/ui/gtk/capture_file_dlg.c @@ -58,6 +58,7 @@ #include "ui/gtk/file_dlg.h" #include "ui/gtk/capture_file_dlg.h" #include "ui/gtk/drag_and_drop.h" +#include "ui/gtk/export_pdu_dlg.h" #include "ui/gtk/main.h" #include "ui/gtk/color_dlg.h" #include "ui/gtk/packet_list.h" @@ -2114,6 +2115,75 @@ file_export_specified_packets_cmd_cb(GtkWidget *w _U_, gpointer data _U_) { } +void +file_export_pdu_ok_cb(GtkWidget *widget _U_, gpointer data) +{ + GtkWidget *msg_dialog; + gchar *display_basename; + gint response; + + if (prefs.gui_ask_unsaved && cf_has_unsaved_data(&cfile)) { + if (cfile.is_tempfile) { + msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level), + (GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT), + GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, + "Do you want to save the captured packets before exporting PDUs?"); + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog), + "After the export, the captured packets will no longer be accessible."); + } + else { + display_basename = g_filename_display_basename(cfile.filename); + msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level), + (GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT), + GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, + "Do you want to save the changes you've made " + "to the capture file \"%s\" before exporting PDUs from it?", + display_basename); + g_free(display_basename); + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog), + "Unsaved changes will be discarded when PDUs are exported."); + } + + gtk_dialog_add_button(GTK_DIALOG(msg_dialog), + WIRESHARK_STOCK_DONT_SAVE, GTK_RESPONSE_CLOSE); + gtk_dialog_add_button(GTK_DIALOG(msg_dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_dialog_add_button(GTK_DIALOG(msg_dialog), + WIRESHARK_STOCK_SAVE, GTK_RESPONSE_ACCEPT); + gtk_dialog_set_alternative_button_order(GTK_DIALOG(msg_dialog), + GTK_RESPONSE_ACCEPT, + GTK_RESPONSE_CANCEL, + GTK_RESPONSE_CLOSE, + -1); + gtk_dialog_set_default_response(GTK_DIALOG(msg_dialog), GTK_RESPONSE_ACCEPT); + + response = gtk_dialog_run(GTK_DIALOG(msg_dialog)); + gtk_widget_destroy(msg_dialog); + + switch (response) { + case GTK_RESPONSE_CLOSE: + /* nothing to do, user chose to discard the unsaved data */ + break; + + case GTK_RESPONSE_ACCEPT: + /* save the file but don't close it */ + do_file_save(&cfile, FALSE); + break; + + case GTK_RESPONSE_CANCEL: + case GTK_RESPONSE_NONE: + case GTK_RESPONSE_DELETE_EVENT: + default: + /* don't do the export. */ + return; + } + } + + do_export_pdu(data); +} + + /* Reload a file using the current read and display filters */ void file_reload_cmd_cb(GtkWidget *w _U_, gpointer data _U_) { diff --git a/ui/gtk/capture_file_dlg.h b/ui/gtk/capture_file_dlg.h index 7517a24da4..ef1342cb1c 100644 --- a/ui/gtk/capture_file_dlg.h +++ b/ui/gtk/capture_file_dlg.h @@ -85,6 +85,14 @@ void file_close_cmd_cb(GtkWidget *widget, gpointer data); */ void file_export_specified_packets_cmd_cb(GtkWidget *widget, gpointer data); +/** User requested the "Export PDUs to file" dialogue box + * and pressed OK to start the export + * + * @param widget parent widget + * @param data pointer to internal data used by the export pdu part + */ +void file_export_pdu_ok_cb(GtkWidget *widget, gpointer data); + /** User requested "Reload". * * @param widget parent widget diff --git a/ui/gtk/export_pdu_dlg.c b/ui/gtk/export_pdu_dlg.c index 99752a4b8c..a8799a7dc7 100644 --- a/ui/gtk/export_pdu_dlg.c +++ b/ui/gtk/export_pdu_dlg.c @@ -38,6 +38,7 @@ #include "ui/alert_box.h" #include "ui/simple_dialog.h" +#include "ui/gtk/capture_file_dlg.h" #include "ui/gtk/dlg_utils.h" #include "ui/gtk/gui_utils.h" #include "ui/gtk/filter_dlg.h" @@ -229,40 +230,36 @@ export_pdu_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_) export_pdu_dlg = NULL; } -static void -export_pdu_ok_cb(GtkWidget *widget _U_, gpointer data) +void +do_export_pdu(gpointer data) { - const char *filter = NULL; - GString *error_string; - exp_pdu_t *exp_pdu_tap_data = (exp_pdu_t *)data; - gchar *tap_name = NULL; - - filter = gtk_entry_get_text(GTK_ENTRY(exp_pdu_tap_data->filter_widget)); - tap_name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(exp_pdu_tap_data->tap_name_widget)); - - /* Register this tap listener now */ - error_string = register_tap_listener(tap_name, /* The name of the tap we want to listen to */ - exp_pdu_tap_data, /* instance identifier/pointer to a struct holding - * all state variables - */ - filter, /* pointer to a filter string */ - TL_REQUIRES_NOTHING, /* flags for the tap listener */ - export_pdu_reset, - export_pdu_packet, - export_pdu_draw); - if (error_string){ - /* Error. We failed to attach to the tap. Clean up */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str); - g_free(exp_pdu_tap_data); - g_string_free(error_string, TRUE); - return; - } - - - exp_pdu_file_open(exp_pdu_tap_data); - - window_destroy(export_pdu_dlg); + const char *filter = NULL; + GString *error_string; + exp_pdu_t *exp_pdu_tap_data = (exp_pdu_t *)data; + gchar *tap_name = NULL; + + filter = gtk_entry_get_text(GTK_ENTRY(exp_pdu_tap_data->filter_widget)); + tap_name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(exp_pdu_tap_data->tap_name_widget)); + + /* Register this tap listener now */ + error_string = register_tap_listener(tap_name, /* The name of the tap we want to listen to */ + exp_pdu_tap_data, /* instance identifier/pointer to a struct holding + * all state variables */ + filter, /* pointer to a filter string */ + TL_REQUIRES_NOTHING, /* flags for the tap listener */ + export_pdu_reset, + export_pdu_packet, + export_pdu_draw); + if (error_string){ + /* Error. We failed to attach to the tap. Clean up */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str); + g_free(exp_pdu_tap_data); + g_string_free(error_string, TRUE); + return; + } + exp_pdu_file_open(exp_pdu_tap_data); + window_destroy(export_pdu_dlg); } @@ -353,7 +350,7 @@ export_pdu_show_cb(GtkWidget *w _U_, gpointer d _U_) gtk_widget_set_tooltip_text(close_bt, "Close this dialog"); ok_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK); - g_signal_connect(ok_bt, "clicked", G_CALLBACK(export_pdu_ok_cb), exp_pdu_tap_data); + g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_export_pdu_ok_cb), exp_pdu_tap_data); gtk_widget_grab_default(ok_bt); gtk_widget_set_tooltip_text(ok_bt, "Export PDU:s to a temporary capture file"); diff --git a/ui/gtk/export_pdu_dlg.h b/ui/gtk/export_pdu_dlg.h index 593961934a..f443ec4564 100644 --- a/ui/gtk/export_pdu_dlg.h +++ b/ui/gtk/export_pdu_dlg.h @@ -27,5 +27,6 @@ #define __EXPORT_PDU_DLG_H__ void export_pdu_show_cb(GtkWidget *widget, gpointer data); +void do_export_pdu(gpointer data); #endif /* __EXPORT_PDU_DLG_H__ */ |