Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnomeui/ChangeLog,v
retrieving revision 1.376
diff -u -r1.376 ChangeLog
--- ChangeLog	7 Feb 2004 19:46:24 -0000	1.376
+++ ChangeLog	9 Feb 2004 01:45:13 -0000
@@ -1,3 +1,11 @@
+2004-02-09  Carlos Garnacho Parro  <carlosg@gnome.org>
+
+	* libgnomeui/gnome-file-entry.c: added "use_filechooser" property
+	that enables the explicit use of GtkFileChooser instead of 
+	GtkFileSelection
+	* libgnomeui/gnome-pixmap-entry.c: ditto
+	* libgnomeui/gnome-icon-entry.c: made it to use GtkFileChooser API
+
 2004-02-07  Kjartan Maraas  <kmaraas@gnome.org>
 
 	* libgnomeui/Makefile.am: Remove more deprecated flags.
Index: libgnomeui/gnome-file-entry.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-file-entry.c,v
retrieving revision 1.87
diff -u -r1.87 gnome-file-entry.c
--- libgnomeui/gnome-file-entry.c	6 Jan 2004 01:21:47 -0000	1.87
+++ libgnomeui/gnome-file-entry.c	9 Feb 2004 01:45:19 -0000
@@ -43,6 +43,9 @@
 #include <gtk/gtkdnd.h>
 #include <gtk/gtkentry.h>
 #include <gtk/gtkfilesel.h>
+#include <gtk/gtkfilechooserdialog.h>
+#include <gtk/gtkstock.h>
+#include <gtk/gtkdialog.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtksignal.h>
 
@@ -65,6 +68,8 @@
 
 	gboolean directory_entry : 1; /*optional flag to only do directories*/
 
+	gboolean use_filechooser : 1;
+
 	/* FIXME: Non local files!! */
 	/* FIXME: executable_entry as used in gnome_run */
 	/* FIXME: multiple_entry for entering multiple filenames */
@@ -106,7 +111,8 @@
 	PROP_FILENAME,
 	PROP_DEFAULT_PATH,
 	PROP_GNOME_ENTRY,
-	PROP_GTK_ENTRY
+	PROP_GTK_ENTRY,
+	PROP_USE_FILECHOOSER
 };
 
 /* Note, can't use boilerplate with interfaces yet,
@@ -286,6 +292,15 @@
 						   "or query any of its parameters."),
 						 GTK_TYPE_ENTRY,
 						 G_PARAM_READABLE));
+	g_object_class_install_property (gobject_class,
+					 PROP_USE_FILECHOOSER,
+					 g_param_spec_boolean (
+						 "use_filechooser",
+						 _("Use GtkFileChooser"),
+						 _("Whether to use the new GtkFileChooser widget "
+						   "or the GtkFileSelection widget to select files."),
+						 FALSE,
+						 G_PARAM_READWRITE));
 
 	class->browse_clicked = browse_clicked;
 	class->activate = NULL;
@@ -328,6 +343,9 @@
 		gnome_file_entry_set_default_path (fentry, g_value_get_string (value));
 		break;
 
+	case PROP_USE_FILECHOOSER:
+		priv->use_filechooser = g_value_get_boolean (value);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -382,6 +400,10 @@
 		g_value_set_object (value, gnome_file_entry_gtk_entry (fentry));
 		break;
 
+	case PROP_USE_FILECHOOSER:
+		g_value_set_boolean (value, priv->use_filechooser);
+		break;
+
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -391,24 +413,37 @@
 static void
 browse_dialog_ok (GtkWidget *widget, gpointer data)
 {
-	GtkFileSelection *fs;
+	GtkWidget *fw;
 	GnomeFileEntry *fentry;
 	GtkWidget *entry;
 	const gchar *locale_filename;
 	gchar *utf8_filename;
 
-	fs = GTK_FILE_SELECTION (data);
-	fentry = GNOME_FILE_ENTRY (g_object_get_data (G_OBJECT (fs), "gnome_file_entry"));
+	fw = GTK_WIDGET (data);
+	fentry = GNOME_FILE_ENTRY (g_object_get_data (G_OBJECT (fw), "gnome_file_entry"));
 	entry = gnome_file_entry_gtk_entry (fentry);
 
-	locale_filename = gtk_file_selection_get_filename (fs);
+	if (GTK_IS_FILE_CHOOSER (fentry->fsw))
+		locale_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fw));
+	else
+		locale_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fw));
+
 	utf8_filename = g_filename_to_utf8 (locale_filename, -1, NULL,
 					    NULL, NULL);
 	gtk_entry_set_text (GTK_ENTRY (entry), utf8_filename);
 	g_free (utf8_filename);
 	/* Is this evil? */
 	g_signal_emit_by_name (entry, "changed");
-	gtk_widget_destroy (GTK_WIDGET (fs));
+	gtk_widget_destroy (fw);
+}
+
+static void
+browse_dialog_response (GtkWidget *widget, gint response, gpointer data)
+{
+	if (response == GTK_RESPONSE_ACCEPT)
+		browse_dialog_ok (widget, data);
+	else
+		gtk_widget_destroy (GTK_WIDGET (data));
 }
 
 static void
@@ -507,66 +542,123 @@
 static void
 browse_clicked(GnomeFileEntry *fentry)
 {
-	GtkFileSelection *fs;
+	GtkWidget *fw;
 	char *p;
 	GtkWidget *toplevel;
 	GClosure *closure;
 
 	/*if it already exists make sure it's shown and raised*/
-	if(fentry->fsw) {
-		gtk_widget_show(fentry->fsw);
-		if(fentry->fsw->window)
-			gdk_window_raise(fentry->fsw->window);
-		fs = GTK_FILE_SELECTION(fentry->fsw);
-		gtk_widget_set_sensitive(fs->file_list,
-					 ! fentry->_priv->directory_entry);
+	if (fentry->fsw) {
+		if (GTK_IS_FILE_CHOOSER (fentry->fsw)) {
+			fw = fentry->fsw;
+		
+			gtk_widget_show (fw);
+
+			if (fw->window)
+				gdk_window_raise (fw->window);
+
+			gtk_file_chooser_set_folder_mode (GTK_FILE_CHOOSER (fw),
+							  fentry->_priv->directory_entry);
+
+			p = build_filename (fentry);
+			if (p) {
+				gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fw), p);
+				g_free (p);
+			}
+
+			return;
+		} else {
+			fw = fentry->fsw;
+		
+			gtk_widget_show(fw);
+			if(fw->window)
+				gdk_window_raise(fw->window);
+
+			gtk_widget_set_sensitive(GTK_FILE_SELECTION (fw)->file_list,
+						 ! fentry->_priv->directory_entry);
+
+			p = build_filename (fentry);
+			if (p) {
+				gtk_file_selection_set_filename (GTK_FILE_SELECTION (fw), p);
+				g_free (p);
+			}
+			
+			return;
+		}
+	}
+
+	/* doesn't exist, create it */
+	if (fentry->_priv->use_filechooser) {
+		fentry->fsw = gtk_file_chooser_dialog_new (fentry->_priv->browse_dialog_title
+							   ? fentry->_priv->browse_dialog_title
+							   : _("Select file"),
+							   NULL,
+							   GTK_FILE_CHOOSER_ACTION_OPEN,
+							   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+							   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+							   NULL);
+		fw = fentry->fsw;
+
+		gtk_dialog_set_default_response (GTK_DIALOG (fw), GTK_RESPONSE_ACCEPT);
+
+		gtk_file_chooser_set_folder_mode (GTK_FILE_CHOOSER (fw),
+						  fentry->_priv->directory_entry);
 
 		p = build_filename (fentry);
-		if (p != NULL) {
-			gtk_file_selection_set_filename (fs, p);
+		if (p) {
+			gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fw), p);
 			g_free (p);
 		}
-		return;
-	}
 
+		closure = g_cclosure_new (G_CALLBACK (browse_dialog_response), fw, NULL);
+		g_object_watch_closure (G_OBJECT (fw), closure);
 
-	fentry->fsw = gtk_file_selection_new (fentry->_priv->browse_dialog_title
-					      ? fentry->_priv->browse_dialog_title
-					      : _("Select file"));
+		g_signal_connect_closure_by_id (fw,
+						g_signal_lookup ("response", G_OBJECT_TYPE (GTK_FILE_CHOOSER (fw))),
+						0, closure, FALSE);
+	} else {
+		fentry->fsw = gtk_file_selection_new (fentry->_priv->browse_dialog_title
+						      ? fentry->_priv->browse_dialog_title
+						      : _("Select file"));
+
+		fw = fentry->fsw;
+		
+		gtk_widget_set_sensitive(GTK_FILE_SELECTION (fw)->file_list,
+					 ! fentry->_priv->directory_entry);
 
-	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (fentry));
-	if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
-		gtk_window_set_transient_for (GTK_WINDOW (fentry->fsw), GTK_WINDOW(toplevel));
+		p = build_filename (fentry);
+		if (p) {
+			gtk_file_selection_set_filename (GTK_FILE_SELECTION (fw), p);
+			g_free (p);
+		}
 
-	g_object_set_data (G_OBJECT (fentry->fsw), "gnome_file_entry", fentry);
+		closure = g_cclosure_new (G_CALLBACK (browse_dialog_ok), fw, NULL);
+		g_object_watch_closure (G_OBJECT (fw), closure);
 
-	fs = GTK_FILE_SELECTION (fentry->fsw);
-	gtk_widget_set_sensitive(fs->file_list,
-				 ! fentry->_priv->directory_entry);
-
-	p = build_filename (fentry);
-	if (p != NULL) {
-		gtk_file_selection_set_filename (fs, p);
-		g_free (p);
+		g_signal_connect_closure_by_id (GTK_FILE_SELECTION (fw)->ok_button,
+						g_signal_lookup ("clicked", G_OBJECT_TYPE (GTK_FILE_SELECTION (fw)->ok_button)),
+						0, closure, FALSE);
+
+		g_signal_connect_swapped (GTK_FILE_SELECTION (fw)->cancel_button, "clicked",
+					  G_CALLBACK (gtk_widget_destroy),
+					  fw);
 	}
 
-	closure = g_cclosure_new (G_CALLBACK (browse_dialog_ok), fs, NULL);
-	g_object_watch_closure (G_OBJECT (fentry->fsw), closure);
-	g_signal_connect_closure_by_id (fs->ok_button,
-					g_signal_lookup ("clicked", G_OBJECT_TYPE (fs->ok_button)),
-					0, closure, FALSE);
-
-	g_signal_connect_swapped (fs->cancel_button, "clicked",
-				  G_CALLBACK (gtk_widget_destroy),
-				  fentry->fsw);
-	g_signal_connect (fentry->fsw, "destroy",
+	g_signal_connect (fw, "destroy",
 			  G_CALLBACK (browse_dialog_kill),
 			  fentry);
 
+	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (fentry));
+
+	if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
+		gtk_window_set_transient_for (GTK_WINDOW (fw), GTK_WINDOW(toplevel));
+
+	g_object_set_data (G_OBJECT (fw), "gnome_file_entry", fentry);
+
 	if (fentry->_priv->is_modal)
-		gtk_window_set_modal (GTK_WINDOW (fentry->fsw), TRUE);
+		gtk_window_set_modal (GTK_WINDOW (fw), TRUE);
 
-	gtk_widget_show (fentry->fsw);
+	gtk_widget_show (fw);
 }
 
 static void
Index: libgnomeui/gnome-icon-entry.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-icon-entry.c,v
retrieving revision 1.96
diff -u -r1.96 gnome-icon-entry.c
--- libgnomeui/gnome-icon-entry.c	24 May 2003 17:44:34 -0000	1.96
+++ libgnomeui/gnome-icon-entry.c	9 Feb 2004 01:45:25 -0000
@@ -43,6 +43,7 @@
 #include <gtk/gtkdnd.h>
 #include <gtk/gtkentry.h>
 #include <gtk/gtkfilesel.h>
+#include <gtk/gtkfilechooser.h>
 #include <gtk/gtkframe.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtkmain.h>
@@ -213,7 +214,6 @@
 						   "or query any of its properties."),
 						 GTK_TYPE_DIALOG,
 						 G_PARAM_READABLE));
-
 }
 
 /* set_property handler for the icon entry */
@@ -412,14 +412,14 @@
         GdkPixbuf *pixbuf, *scaled;
 	int w,h;
 	GtkWidget *frame;
-	GtkFileSelection *fs;
+	GtkFileChooser *fc;
 
 	g_return_if_fail (widget != NULL);
 	g_return_if_fail (GTK_IS_WIDGET (widget));
 
-	frame = g_object_get_data(G_OBJECT(widget),"frame");
-	fs = g_object_get_data(G_OBJECT(frame),"fs");
-
+	fc = GTK_FILE_CHOOSER (widget);
+	frame = gtk_file_chooser_get_preview_widget (fc);
+	
 	if((l = gtk_container_get_children(GTK_CONTAINER(frame))) != NULL) {
 		pp = l->data;
 		g_list_free(l);
@@ -428,7 +428,7 @@
 	if(pp)
 		gtk_widget_destroy(pp);
 
-	p = gtk_file_selection_get_filename(fs);
+	p = gtk_file_chooser_get_filename(fc);
 	if(!p || !g_file_test (p,G_FILE_TEST_IS_SYMLINK | G_FILE_TEST_IS_REGULAR) ||
 	   !(pixbuf = gdk_pixbuf_new_from_file (p, NULL)))
 		return;
@@ -511,9 +511,9 @@
 browse_clicked(GnomeFileEntry *fentry, GnomeIconEntry *ientry)
 {
 	GtkWidget *w;
-	GtkWidget *hbox;
-	GtkFileSelection *fs;
+	GtkFileChooser *fc;
 	GClosure *closure;
+	gchar *path;
 
 	g_return_if_fail (fentry != NULL);
 	g_return_if_fail (GNOME_IS_FILE_ENTRY (fentry));
@@ -522,33 +522,27 @@
 
 	if(!fentry->fsw)
 		return;
-	fs = GTK_FILE_SELECTION(fentry->fsw);
+	
+	fc = GTK_FILE_CHOOSER (fentry->fsw);
 
-	hbox = fs->file_list;
-	g_return_if_fail (g_object_get_data(G_OBJECT(hbox),"frame") == NULL);
+	g_return_if_fail (gtk_file_chooser_get_preview_widget (fc) == NULL);
 
-	do {
-		hbox = hbox->parent;
-		if(!hbox) {
-			g_warning(_("Can't find an hbox, using a normal file "
-				    "selection"));
-			return;
-		}
-	} while(!GTK_IS_HBOX(hbox));
+	w = gtk_frame_new("");
+	gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_NONE);
 
-	w = gtk_frame_new(_("Preview"));
-	gtk_widget_show(w);
-	gtk_box_pack_end(GTK_BOX(hbox),w,FALSE,FALSE,0);
-	gtk_widget_set_size_request (w,110,110);
-	g_object_set_data(G_OBJECT(w),"fs",fs);
-
-	g_object_set_data(G_OBJECT(fs->file_list),"frame",w);
-	g_object_set_data(G_OBJECT(fs->selection_entry),"frame",w);
+	gtk_file_chooser_set_preview_widget (fc, w);
+	gtk_widget_set_size_request (w, 110, 110);
 
 	closure = g_cclosure_new (G_CALLBACK (setup_preview), NULL, NULL);
-	g_object_watch_closure (G_OBJECT (fs), closure);
-	g_signal_connect_closure (fs->selection_entry, "changed",
+	g_object_watch_closure (G_OBJECT (fc), closure);
+	g_signal_connect_closure (fc, "update-preview",
 				  closure, FALSE);
+
+	/* the path can be already set */
+	if ((path = gtk_file_chooser_get_filename (fc)) != NULL)
+		setup_preview (fc);
+
+	g_free (path);
 }
 
 static void
@@ -969,6 +963,7 @@
 	GtkWidget *w;
 	gchar *p;
 	GClosure *closure;
+	GValue value = {0, };
 
 	ientry->_priv = g_new0(GnomeIconEntryPrivate, 1);
 
@@ -1019,6 +1014,12 @@
 				G_CALLBACK (browse_clicked),
 				ientry);
 
+	g_value_init (&value, G_TYPE_BOOLEAN);
+	g_value_set_boolean (&value, TRUE);
+
+	g_object_set_property (G_OBJECT (ientry->_priv->fentry),
+			       "use_filechooser", &value);
+
 	gtk_widget_show (ientry->_priv->fentry);
 
 	p = gnome_program_locate_file (NULL /* program */,
Index: libgnomeui/gnome-pixmap-entry.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-pixmap-entry.c,v
retrieving revision 1.53
diff -u -r1.53 gnome-pixmap-entry.c
--- libgnomeui/gnome-pixmap-entry.c	31 May 2002 01:40:32 -0000	1.53
+++ libgnomeui/gnome-pixmap-entry.c	9 Feb 2004 01:45:29 -0000
@@ -40,6 +40,7 @@
 #include <gtk/gtkdnd.h>
 #include <gtk/gtkentry.h>
 #include <gtk/gtkfilesel.h>
+#include <gtk/gtkfilechooser.h>
 #include <gtk/gtkframe.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtkmain.h>
@@ -275,13 +276,21 @@
 	GtkWidget *pp = NULL;
         GdkPixbuf *pixbuf, *scaled;
 	int w,h;
-	GtkWidget *frame;
-	GtkFileSelection *fs;
+	GtkWidget *frame, *fw;
 
 	g_return_if_fail (GTK_IS_WIDGET (widget));
 
-	frame = g_object_get_data (G_OBJECT (widget), "frame");
-	fs = g_object_get_data (G_OBJECT (frame), "fs");
+	if (GTK_IS_FILE_CHOOSER (widget)) {
+		fw = widget;
+		frame = gtk_file_chooser_get_preview_widget (GTK_FILE_CHOOSER (fw));
+
+		p = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (fw));
+	} else {
+		frame = g_object_get_data (G_OBJECT (widget), "frame");
+		fw = g_object_get_data (G_OBJECT (frame), "fs");
+
+		p = gtk_file_selection_get_filename(GTK_FILE_SELECTION (fw));
+	}
 
 	if((l = gtk_container_get_children(GTK_CONTAINER(frame))) != NULL) {
 		pp = l->data;
@@ -291,7 +300,6 @@
 	if(pp)
 		gtk_widget_destroy(pp);
 
-	p = gtk_file_selection_get_filename(fs);
 	if(!p || !g_file_test(p,G_FILE_TEST_IS_SYMLINK|G_FILE_TEST_IS_REGULAR) ||
 	   !(pixbuf = gdk_pixbuf_new_from_file (p, NULL)))
 		return;
@@ -318,7 +326,6 @@
 	gtk_widget_show(pp);
 
 	gtk_container_add(GTK_CONTAINER(frame),pp);
-
 }
 
 static void
@@ -360,10 +367,10 @@
 static void
 browse_clicked(GnomeFileEntry *fentry, GnomePixmapEntry *pentry)
 {
-	GtkWidget *w;
-	GtkWidget *hbox;
-
+	GtkWidget *w, *hbox;
 	GtkFileSelection *fs;
+	GtkFileChooser *fc;
+	gchar *path;
 
 	g_return_if_fail (fentry != NULL);
 	g_return_if_fail (GNOME_IS_FILE_ENTRY (fentry));
@@ -373,34 +380,56 @@
 	if(!fentry->fsw)
 		return;
 
-	fs = GTK_FILE_SELECTION(fentry->fsw);
+	if (GTK_IS_FILE_CHOOSER (fentry->fsw)) {
+		fc = GTK_FILE_CHOOSER (fentry->fsw);
 
-	/* we already got this */
-	if (g_object_get_data (G_OBJECT (fs->file_list), "frame") != NULL)
-		return;
+		if (gtk_file_chooser_get_preview_widget (fc) != NULL)
+			return;
+
+		w = gtk_frame_new ("");
+		gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_NONE);
+		gtk_widget_show (w);
+		
+		gtk_file_chooser_set_preview_widget (fc, w);
+
+		g_signal_connect (G_OBJECT (fc), "update-preview",
+				  G_CALLBACK (setup_preview), fentry->fsw);
+
+		/* the path can be already set */
+		if ((path = gtk_file_chooser_get_filename (fc)) != NULL)
+			setup_preview (NULL, fentry->fsw);
 
-	hbox = fs->file_list;
-	do {
-		hbox = hbox->parent;
-		if(!hbox) {
-			g_warning(_("Can't find an hbox, using a normal file "
-				    "selection"));
+		g_free (path);
+	} else {
+		fs = GTK_FILE_SELECTION (fentry->fsw);
+		
+		/* we already got this */
+		if (g_object_get_data (G_OBJECT (fs->file_list), "frame") != NULL)
 			return;
-		}
-	} while(!GTK_IS_HBOX(hbox));
 
-	w = gtk_frame_new(_("Preview"));
-	gtk_widget_show(w);
-	gtk_box_pack_end(GTK_BOX(hbox),w,FALSE,FALSE,0);
-	gtk_widget_set_size_request (w, 110, 110);
-	g_object_set_data (G_OBJECT (w), "fs", fs);
-
-	g_object_set_data (G_OBJECT (fs->file_list), "frame", w);
-	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (fs->file_list))), "changed",
-			  G_CALLBACK (setup_preview), fs->file_list);
-	g_object_set_data (G_OBJECT (fs->selection_entry), "frame", w);
-	g_signal_connect (fs->selection_entry, "changed",
-			  G_CALLBACK (setup_preview), fs->selection_entry);
+		hbox = fs->file_list;
+		do {
+			hbox = hbox->parent;
+			if(!hbox) {
+				g_warning(_("Can't find an hbox, using a normal file "
+					    "selection"));
+				return;
+			}
+		} while(!GTK_IS_HBOX(hbox));
+
+		w = gtk_frame_new(_("Preview"));
+		gtk_widget_show(w);
+		gtk_box_pack_end(GTK_BOX(hbox),w,FALSE,FALSE,0);
+		gtk_widget_set_size_request (w, 110, 110);
+		g_object_set_data (G_OBJECT (w), "fs", fs);
+
+		g_object_set_data (G_OBJECT (fs->file_list), "frame", w);
+		g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (fs->file_list))), "changed",
+				  G_CALLBACK (setup_preview), fs->file_list);
+		g_object_set_data (G_OBJECT (fs->selection_entry), "frame", w);
+		g_signal_connect (fs->selection_entry, "changed",
+				  G_CALLBACK (setup_preview), fs->selection_entry);
+	}
 }
 
 static void
