Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evince/ChangeLog,v
retrieving revision 1.255
diff -u -u -r1.255 ChangeLog
--- ChangeLog	25 Mar 2005 21:57:13 -0000	1.255
+++ ChangeLog	25 Mar 2005 23:01:09 -0000
@@ -1,3 +1,8 @@
+2005-03-25  Fernando Herrera  <fherrera@onirica.com>
+
+	* shell/ev-application.c: (update_preview), (ev_application_open):
+	add a preview widget showing pdf or pixbuf thumbnails.
+
 Fri Mar 25 16:55:58 2005  Jonathan Blandford  <jrb@redhat.com>
 
 	* pdf/pdf-document.cc: Patch from Fernando Herrera
Index: shell/ev-application.c
===================================================================
RCS file: /cvs/gnome/evince/shell/ev-application.c,v
retrieving revision 1.10
diff -u -u -r1.10 ev-application.c
--- shell/ev-application.c	4 Feb 2005 15:17:10 -0000	1.10
+++ shell/ev-application.c	25 Mar 2005 23:01:09 -0000
@@ -20,15 +20,32 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <pdf-document.h>
+
 #include "ev-application.h"
+#include "ev-document.h"
+#include "ev-document-thumbnails.h"
 
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <glib-object.h>
 #include <gtk/gtkfilechooserdialog.h>
+#include <gtk/gtkimage.h>
+#include <gtk/gtklabel.h>
 #include <gtk/gtkstock.h>
+#include <gtk/gtkvbox.h>
 #include <gtk/gtkwidget.h>
 #include <gtk/gtkmain.h>
+#include <libgnomevfs/gnome-vfs-mime-utils.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
+
+#include <string.h>
+
+struct _DocumentPreview {
+	GtkWidget *box, *image, *label;
+};
+
+typedef struct _DocumentPreview DocumentPreview;
 
 struct _EvApplicationPrivate {
 	GList *windows;
@@ -108,12 +125,69 @@
 		: ev_application_new_window (application);
 }
 
+static void
+update_preview (GtkFileChooser *chooser, DocumentPreview *preview)
+{
+	gchar *uri;
+	GdkPixbuf *pixbuf = NULL ;
+	char *title = NULL;
+	int n_pages = 0;
+
+
+	uri = gtk_file_chooser_get_preview_uri (chooser);
+	if (uri) {
+		gchar *mime_type;
+		GError *error = NULL;
+
+		mime_type = gnome_vfs_get_mime_type (uri);
+		if (mime_type && !strcmp (mime_type, "application/pdf")) {
+			EvDocument *document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
+			if (ev_document_load (document, uri, &error)) {
+				pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (document), 1, 128, FALSE);
+				title = ev_document_get_title (document);
+				n_pages = ev_document_get_n_pages (document);
+				g_object_unref (document);
+			}
+		} else if (mime_type && !strncmp (mime_type, "image", 5)) {
+			char *file = gnome_vfs_get_local_path_from_uri (uri);
+			if (file) {
+				pixbuf = gdk_pixbuf_new_from_file_at_scale (file, 128, 128, TRUE, &error);
+				g_free (file);
+			}
+		}
+
+		if (error) {
+			g_error_free (error);
+		}
+	}
+
+	if (pixbuf != NULL) {
+		gtk_image_set_from_pixbuf (GTK_IMAGE (preview->image), pixbuf);
+		gdk_pixbuf_unref (pixbuf);
+	} else {
+		gtk_image_set_from_stock (GTK_IMAGE (preview->image), "gtk-dialog-question",
+					  GTK_ICON_SIZE_DIALOG);
+	}
+	if (title != NULL && n_pages > 0) {
+		char *markup;
+		markup = g_markup_printf_escaped (_("<span weight=\"bold\">Title:</span>%s\n"
+						    "<span weight=\"bold\">Pages:</span>%d"), title, n_pages);
+		gtk_label_set_markup (GTK_LABEL (preview->label), markup);
+		g_free (title);
+		g_free (markup);
+	} else {
+		gtk_label_set_text (GTK_LABEL (preview->label), "");
+	}
+	gtk_file_chooser_set_preview_widget_active (chooser, TRUE);
+}
+				
 void
 ev_application_open (EvApplication *application, GError *err)
 {
 	EvWindow *ev_window;
 	GtkWidget *chooser;
 	GtkFileFilter *both_filter, *pdf_filter, *ps_filter, *pixbuf_filter, *all_filter;
+	DocumentPreview *preview;
 
 	ev_window = ev_application_get_empty_window (application);
 
@@ -158,6 +232,17 @@
 	
 	gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), both_filter);
 
+	preview = g_new0 (DocumentPreview, 1);
+	preview->box = gtk_vbox_new (FALSE, 6);
+	preview->label = gtk_label_new ("");
+	preview->image = gtk_image_new ();
+	gtk_box_pack_start (GTK_BOX (preview->box), preview->image, TRUE, FALSE, 2);
+	gtk_box_pack_start (GTK_BOX (preview->box), preview->label, FALSE, FALSE, 2);
+	gtk_widget_show_all (preview->box);
+	gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (chooser), preview->box);
+	gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (chooser), FALSE);
+	g_signal_connect (chooser, "update-preview", G_CALLBACK (update_preview), preview);
+
 	if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) {
 		char *uri;
 
@@ -168,6 +253,7 @@
 	}
 
 	gtk_widget_destroy (GTK_WIDGET (chooser));
+	g_free (preview);
 }
 
 static void
