Exemple #1
0
/* Create a file selection dialog box window that belongs to a top-level
   window. */
GtkWidget *
file_selection_new(const gchar *title, GtkWindow *parent,
                   file_selection_action_t action)
{
    GtkWidget *win;
    GtkFileChooserAction gtk_action;
#ifdef _WIN32
    char *u3devicedocumentpath;
#endif
    const gchar *ok_button_text;

    switch (action) {

    case FILE_SELECTION_OPEN:
        gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN;
        ok_button_text = GTK_STOCK_OPEN;
        break;

    case FILE_SELECTION_READ_BROWSE:
        gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN;
        ok_button_text = GTK_STOCK_OK;
        break;

    case FILE_SELECTION_SAVE:
        gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE;
        ok_button_text = WIRESHARK_STOCK_SAVE;
        break;

    case FILE_SELECTION_WRITE_BROWSE:
        gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE;
        ok_button_text = GTK_STOCK_OK;
        break;

    case FILE_SELECTION_CREATE_FOLDER:
        gtk_action = GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
        ok_button_text = GTK_STOCK_OK;
        break;

    default:
        g_assert_not_reached();
        gtk_action = (GtkFileChooserAction)-1;
        ok_button_text = NULL;
        break;
    }
    win = gtk_file_chooser_dialog_new(title, parent, gtk_action,
                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                      ok_button_text, GTK_RESPONSE_ACCEPT,
                                      NULL);
    gtk_dialog_set_alternative_button_order(GTK_DIALOG(win),
                                            GTK_RESPONSE_ACCEPT,
                                            GTK_RESPONSE_CANCEL,
                                            -1);
    if (action == FILE_SELECTION_SAVE)
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(win), TRUE);

    /* If we've opened a file before, start out by showing the files in the directory
       in which that file resided. */
    if (last_open_dir)
        file_selection_set_current_folder(win, last_open_dir);
#ifdef _WIN32
    else {
        u3devicedocumentpath = getenv_utf8("U3_DEVICE_DOCUMENT_PATH");
        if(u3devicedocumentpath != NULL)
            file_selection_set_current_folder(win, u3devicedocumentpath);

    }
#endif
    return win;
}
Exemple #2
0
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;
	}
}
Exemple #3
0
/* Create a file selection dialog box window that belongs to Wireshark's
   main window. */
GtkWidget *
file_selection_new(const gchar *title, file_selection_action_t action)
{
    GtkWidget *win;
    GtkFileChooserAction gtk_action;
#ifdef _WIN32
    char *u3devicedocumentpath;
#endif
    const gchar *ok_button_text;

    switch (action) {

    case FILE_SELECTION_OPEN:
        gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN;
        ok_button_text = GTK_STOCK_OPEN;
        break;

    case FILE_SELECTION_READ_BROWSE:
        gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN;
        ok_button_text = GTK_STOCK_OK;
        break;

    case FILE_SELECTION_SAVE:
        gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE;
        ok_button_text = GTK_STOCK_SAVE;
        break;

    case FILE_SELECTION_WRITE_BROWSE:
        gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE;
        ok_button_text = GTK_STOCK_OK;
        break;

    case FILE_SELECTION_CREATE_FOLDER:
        gtk_action = GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
        ok_button_text = GTK_STOCK_OK;
        break;

    default:
        g_assert_not_reached();
        gtk_action = -1;
        ok_button_text = NULL;
        break;
    }
    win = gtk_file_chooser_dialog_new(title, GTK_WINDOW(top_level), gtk_action,
#ifndef _WIN32
                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                      ok_button_text, GTK_RESPONSE_ACCEPT,
#else
                                      ok_button_text, GTK_RESPONSE_ACCEPT,
                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
#endif
                                      NULL);

    /* If we've opened a file before, start out by showing the files in the directory
       in which that file resided. */
    if (last_open_dir)
        file_selection_set_current_folder(win, last_open_dir);
#ifdef _WIN32
    else {
        u3devicedocumentpath = getenv_utf8("U3_DEVICE_DOCUMENT_PATH");
        if(u3devicedocumentpath != NULL)
            file_selection_set_current_folder(win, u3devicedocumentpath);

    }
#endif
    return win;
}