int ExportDissectionDialog::exec() { #if !defined(Q_OS_WIN) int retval; if (!cap_file_) return QDialog::Rejected; retval = QFileDialog::exec(); if (retval == QDialog::Accepted && selectedFiles().length() > 0) { cf_print_status_t status; QString file_name = selectedFiles()[0]; /* Fill in our print (and export) args */ print_args_.file = file_name.toUtf8().data(); print_args_.format = PR_FMT_TEXT; print_args_.to_file = TRUE; print_args_.cmd = NULL; print_args_.print_summary = TRUE; print_args_.print_dissections = print_dissections_as_displayed; print_args_.print_hex = FALSE; print_args_.print_formfeed = FALSE; switch (export_type_) { case export_type_text: /* Text */ print_args_.print_summary = packet_format_group_box_.summaryEnabled(); print_args_.print_dissections = print_dissections_none; if (packet_format_group_box_.detailsEnabled()) { if (packet_format_group_box_.allCollapsedEnabled()) print_args_.print_dissections = print_dissections_collapsed; else if (packet_format_group_box_.asDisplayedEnabled()) print_args_.print_dissections = print_dissections_as_displayed; else if (packet_format_group_box_.allExpandedEnabled()) print_args_.print_dissections = print_dissections_expanded; } print_args_.print_hex = packet_format_group_box_.bytesEnabled(); print_args_.stream = print_stream_text_new(TRUE, print_args_.file); if (print_args_.stream == NULL) { open_failure_alert_box(print_args_.file, errno, TRUE); return QDialog::Rejected; } status = cf_print_packets(cap_file_, &print_args_); break; case export_type_csv: /* CSV */ status = cf_write_csv_packets(cap_file_, &print_args_); break; case export_type_carrays: /* C Arrays */ status = cf_write_carrays_packets(cap_file_, &print_args_); break; case export_type_psml: /* PSML */ status = cf_write_psml_packets(cap_file_, &print_args_); break; case export_type_pdml: /* PDML */ status = cf_write_pdml_packets(cap_file_, &print_args_); break; default: return QDialog::Rejected; } switch (status) { case CF_PRINT_OK: break; case CF_PRINT_OPEN_ERROR: open_failure_alert_box(print_args_.file, errno, TRUE); break; case CF_PRINT_WRITE_ERROR: write_failure_alert_box(print_args_.file, errno); break; } if (selectedFiles().length() > 0) { gchar *dirname; /* Save the directory name for future file dialogs. */ dirname = get_dirname(print_args_.file); /* Overwrites file_name data */ set_last_open_dir(dirname); } } return retval; #else // Q_OS_WIN win32_export_file(parentWidget()->effectiveWinId(), cap_file_, export_type_); return QDialog::Accepted; #endif // Q_OS_WIN }
void pixmap_save_cb(GtkWidget *w, gpointer pixmap_ptr _U_) { GtkWidget *save_as_w; #if GTK_CHECK_VERSION(2,22,0) surface_info_t *surface_info = g_object_get_data(G_OBJECT(w), "surface-info"); #else GdkPixmap *pixmap = g_object_get_data(G_OBJECT(w), "pixmap"); #endif GdkPixbuf *pixbuf; GdkPixbufFormat *pixbuf_format; GtkWidget *main_vb, *save_as_type_hb, *type_lb, *type_cm; GSList *file_formats,*ffp; GdkWindow *parent; gchar *format_name; guint format_index = 0; guint default_index = 0; gchar *filename, *file_type; GError *error = NULL; gboolean ret; GtkWidget *msg_dialog; #if GTK_CHECK_VERSION(2,22,0) pixbuf = gdk_pixbuf_get_from_surface (surface_info->surface, 0, 0, surface_info->width, surface_info->height); #else pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0, -1, -1); #endif if(!pixbuf) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%sCould not get image from graph%s", simple_dialog_primary_start(), simple_dialog_primary_end()); return; } save_as_w = file_selection_new("Wireshark: Save Graph As ...", FILE_SELECTION_SAVE); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(save_as_w), TRUE); /* Container for each row of widgets */ main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); file_selection_set_extra_widget(save_as_w, main_vb); gtk_widget_show(main_vb); save_as_type_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE); gtk_box_pack_start(GTK_BOX(main_vb), save_as_type_hb, FALSE, FALSE, 0); gtk_widget_show(save_as_type_hb); type_lb = gtk_label_new("File type: "); gtk_box_pack_start(GTK_BOX(save_as_type_hb), type_lb, FALSE, FALSE, 0); gtk_widget_show(type_lb); type_cm = gtk_combo_box_text_new(); gtk_box_pack_start(GTK_BOX(save_as_type_hb), type_cm, FALSE, FALSE, 0); /* List all of the file formats the gdk-pixbuf library supports */ file_formats = gdk_pixbuf_get_formats(); ffp = file_formats; while(ffp) { pixbuf_format = ffp->data; if (gdk_pixbuf_format_is_writable(pixbuf_format)) { format_name = gdk_pixbuf_format_get_name(pixbuf_format); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(type_cm), format_name); if (!(g_ascii_strcasecmp(format_name, "png"))) default_index = format_index; format_index++; } ffp = g_slist_next(ffp); } g_slist_free(file_formats); gtk_combo_box_set_active(GTK_COMBO_BOX(type_cm), default_index); gtk_widget_show(type_cm); gtk_widget_show(save_as_w); window_present(save_as_w); parent = gtk_widget_get_parent_window(w); gdk_window_set_transient_for(gtk_widget_get_window(save_as_w), parent); /* * Loop until the user either selects a file or gives up. */ for (;;) { if (gtk_dialog_run(GTK_DIALOG(save_as_w)) != GTK_RESPONSE_ACCEPT) { /* They clicked "Cancel" or closed the dialog or.... */ window_destroy(save_as_w); return; } filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(save_as_w)); /* Perhaps the user specified a directory instead of a file. Check whether they did. */ if (test_for_directory(filename) == EISDIR) { /* It's a directory - set the file selection box to display that directory, and leave the selection box displayed. */ set_last_open_dir(filename); g_free(filename); file_selection_set_current_folder(save_as_w, get_last_open_dir()); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(save_as_w), ""); continue; } file_type = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(type_cm)); ret = gdk_pixbuf_save(pixbuf, filename, file_type, &error, NULL); g_free(filename); g_free(file_type); if (!ret) { msg_dialog = gtk_message_dialog_new(GTK_WINDOW(save_as_w), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", error->message); gtk_dialog_run(GTK_DIALOG(msg_dialog)); gtk_widget_destroy(msg_dialog); continue; } window_destroy(save_as_w); return; } }
void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) { char *gdp_path, *dp_path; char *rf_path; int rf_open_errno; gchar *err_msg = NULL; /* First check if profile exists */ if (!profile_exists(profile_name, FALSE)) { if (profile_exists(profile_name, TRUE)) { char *pf_dir_path, *pf_dir_path2, *pf_filename; /* Copy from global profile */ if (create_persconffile_profile(profile_name, &pf_dir_path) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't create directory\n\"%s\":\n%s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); } if (copy_persconffile_profile(profile_name, profile_name, TRUE, &pf_filename, &pf_dir_path, &pf_dir_path2) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.", pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno)); g_free(pf_filename); g_free(pf_dir_path); g_free(pf_dir_path2); } } else { /* No personal and no global profile exists */ return; } } /* Then check if changing to another profile */ if (profile_name && strcmp (profile_name, get_profile_name()) == 0) { return; } /* Get the current geometry, before writing it to disk */ emit profileChanging(); if (profile_exists(get_profile_name(), FALSE)) { /* Write recent file for profile we are leaving, if it still exists */ write_profile_recent(); } /* Set profile name and update the status bar */ set_profile_name (profile_name); emit profileNameChanged(profile_name); /* Apply new preferences */ readConfigurationFiles (&gdp_path, &dp_path, true); if (!recent_read_profile_static(&rf_path, &rf_open_errno)) { simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open common recent file\n\"%s\": %s.", rf_path, g_strerror(rf_open_errno)); g_free(rf_path); } if (recent.gui_fileopen_remembered_dir && test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) { set_last_open_dir(recent.gui_fileopen_remembered_dir); } timestamp_set_type (recent.gui_time_format); timestamp_set_precision(recent.gui_time_precision); timestamp_set_seconds_type (recent.gui_seconds_format); packet_list_enable_color(recent.packet_list_colorize); tap_update_timer_.setInterval(prefs.tap_update_interval); prefs_to_capture_opts(); prefs_apply_all(); #ifdef HAVE_LIBPCAP update_local_interfaces(); #endif setMonospaceFont(prefs.gui_qt_font_name); emit columnsChanged(); emit preferencesChanged(); emit recentFilesRead(); emit filterExpressionsChanged(); emit checkDisplayFilter(); /* Enable all protocols and disable from the disabled list */ proto_enable_all(); if (gdp_path == NULL && dp_path == NULL) { set_disabled_protos_list(); set_disabled_heur_dissector_list(); } /* Reload color filters */ if (!color_filters_reload(&err_msg, color_filter_add_cb)) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); g_free(err_msg); } emit localInterfaceListChanged(); emit packetDissectionChanged(); }
void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) { char *gdp_path, *dp_path; char *rf_path; int rf_open_errno; /* First check if profile exists */ if (!profile_exists(profile_name, FALSE)) { if (profile_exists(profile_name, TRUE)) { char *pf_dir_path, *pf_dir_path2, *pf_filename; /* Copy from global profile */ if (create_persconffile_profile(profile_name, &pf_dir_path) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't create directory\n\"%s\":\n%s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); } if (copy_persconffile_profile(profile_name, profile_name, TRUE, &pf_filename, &pf_dir_path, &pf_dir_path2) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.", pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno)); g_free(pf_filename); g_free(pf_dir_path); g_free(pf_dir_path2); } } else { /* No personal and no global profile exists */ return; } } /* Then check if changing to another profile */ if (profile_name && strcmp (profile_name, get_profile_name()) == 0) { return; } /* Get the current geometry, before writing it to disk */ emit profileChanging(); if (profile_exists(get_profile_name(), FALSE)) { /* Write recent file for profile we are leaving, if it still exists */ write_profile_recent(); } /* Set profile name and update the status bar */ set_profile_name (profile_name); emit profileNameChanged(profile_name); /* Reset current preferences and apply the new */ prefs_reset(); // menu_prefs_reset(); (void) readConfigurationFiles (&gdp_path, &dp_path); recent_read_profile_static(&rf_path, &rf_open_errno); if (rf_path != NULL && rf_open_errno != 0) { simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open common recent file\n\"%s\": %s.", rf_path, g_strerror(rf_open_errno)); } if (recent.gui_fileopen_remembered_dir && test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) { set_last_open_dir(recent.gui_fileopen_remembered_dir); } timestamp_set_type (recent.gui_time_format); timestamp_set_seconds_type (recent.gui_seconds_format); color_filters_enable(recent.packet_list_colorize); tap_update_timer_.setInterval(prefs.tap_update_interval); prefs_to_capture_opts(); prefs_apply_all(); emit preferencesChanged(); emit columnsChanged(); emit recentFilesRead(); emit filterExpressionsChanged(); // macros_post_update(); /* Enable all protocols and disable from the disabled list */ proto_enable_all(); if (gdp_path == NULL && dp_path == NULL) { set_disabled_protos_list(); set_disabled_heur_dissector_list(); } /* Reload color filters */ color_filters_reload(); // user_font_apply(); /* Update menus with new recent values */ // menu_recent_read_finished(); }