From 0ab8d7a8cc5ba8bf9ccf805a0a16111049d79c5b Mon Sep 17 00:00:00 2001 From: Diego Escalante Urrelo Date: Fri, 28 Sep 2007 04:59:47 +0000 Subject: Add a preview for the FileChooser. The default size is 150x150. Fixes bug * lib/ephy-file-chooser.c: Add a preview for the FileChooser. The default size is 150x150. Fixes bug #440859. svn path=/trunk/; revision=7502 --- lib/ephy-file-chooser.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lib') diff --git a/lib/ephy-file-chooser.c b/lib/ephy-file-chooser.c index 2edfb11bc..0bdc52f48 100644 --- a/lib/ephy-file-chooser.c +++ b/lib/ephy-file-chooser.c @@ -30,6 +30,7 @@ #include "ephy-stock-icons.h" #include +#include #include #include @@ -42,6 +43,8 @@ struct _EphyFileChooserPrivate static void ephy_file_chooser_class_init (EphyFileChooserClass *klass); static void ephy_file_chooser_init (EphyFileChooser *dialog); +static void ephy_file_chooser_image_preview (GtkFileChooser *file_chooser, + gpointer user_data); enum { @@ -49,6 +52,9 @@ enum PROP_PERSIST_KEY }; +#define PREVIEW_WIDTH 150 +#define PREVIEW_HEIGHT 150 + static GObjectClass *parent_class = NULL; GType @@ -314,6 +320,34 @@ ephy_file_chooser_class_init (EphyFileChooserClass *klass) g_type_class_add_private (object_class, sizeof (EphyFileChooserPrivate)); } +static void +ephy_file_chooser_image_preview (GtkFileChooser *file_chooser, + gpointer user_data) +{ + char *filename; + GtkWidget *preview; + GdkPixbuf *pixbuf; + gboolean have_preview; + + pixbuf = NULL; + preview = GTK_WIDGET (user_data); + filename = gtk_file_chooser_get_preview_filename (file_chooser); + + if (filename) + pixbuf = gdk_pixbuf_new_from_file_at_size (filename, + PREVIEW_WIDTH, PREVIEW_HEIGHT, NULL); + g_free (filename); + + have_preview = (pixbuf != NULL); + 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); + +} + EphyFileChooser * ephy_file_chooser_new (const char *title, GtkWidget *parent, @@ -323,6 +357,7 @@ ephy_file_chooser_new (const char *title, { EphyFileChooser *dialog; GtkFileFilter *filter[EPHY_FILE_FILTER_LAST]; + GtkWidget *preview; g_return_val_if_fail (default_filter >= 0 && default_filter <= EPHY_FILE_FILTER_LAST, NULL); @@ -363,6 +398,10 @@ ephy_file_chooser_new (const char *title, GTK_RESPONSE_ACCEPT); } + preview = gtk_image_new (); + gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview); + g_signal_connect (dialog, "update-preview", G_CALLBACK (ephy_file_chooser_image_preview), preview); + if (default_filter != EPHY_FILE_FILTER_NONE) { filter[EPHY_FILE_FILTER_ALL_SUPPORTED] = -- cgit v1.2.3