#include <gtk/gtk.h>

static void
chooser_preview_update (GtkFileChooser *file_chooser,
			gpointer data)
{
	GtkWidget *preview;
	char      *filename;
	GdkPixbuf *pixbuf;
	gboolean   have_preview;

	preview = GTK_WIDGET (data);
	filename = gtk_file_chooser_get_preview_filename (file_chooser);

	pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
	have_preview = (pixbuf != NULL);
	g_free (filename);

	gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
	if (pixbuf)
		g_object_unref (pixbuf);

	gtk_file_chooser_set_preview_widget_active (file_chooser,
						    have_preview);
}

int main (int argc, char *argv []) {
	GtkWidget *chooser_preview;
	GtkWidget *button;
	GtkWidget *window;

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

	button = gtk_file_chooser_button_new ("Test",
					      GTK_FILE_CHOOSER_ACTION_OPEN);
	gtk_container_add (GTK_CONTAINER (window), button);

	chooser_preview = gtk_image_new ();
	gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (button),
					     chooser_preview);
	g_signal_connect (button, "update-preview",
			  G_CALLBACK (chooser_preview_update), chooser_preview);

	gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (button),
				       "/usr/share/gnome/panel/pixmaps/fishanim.png");

	gtk_widget_show_all (window);

	gtk_main ();

	return 0;
}
