1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/* pixmap_save.c
* Routines for saving pixmaps using the Gdk-Pixmap library
* Copyright 2007, Stephen Fisher (see AUTHORS file)
*
* $Id: pixmap_save.c 43382 2012-06-19 19:22:04Z guy $
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <gtk/gtk.h>
#include <epan/filesystem.h>
#include "ui/last_open_dir.h"
#include "ui/simple_dialog.h"
#include "ui/gtk/pixmap_save.h"
#include "ui/gtk/gui_utils.h"
#include "ui/gtk/file_dlg.h"
#include "ui/gtk/old-gtk-compat.h"
#if GTK_CHECK_VERSION(2,22,0)
#if !GTK_CHECK_VERSION(3,0,0)
#include "ui/gtk/gui_utils.h"
#endif
#endif
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;
}
}
|