? gtkfilechooser.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnomeui/ChangeLog,v
retrieving revision 1.372
diff -u -r1.372 ChangeLog
--- ChangeLog	21 Jan 2004 18:11:40 -0000	1.372
+++ ChangeLog	24 Jan 2004 18:15:33 -0000
@@ -1,3 +1,9 @@
+2004-01-23  Carlos Garnacho Parro  <carlosg@gnome.org>
+
+	* libgnomeui/gnome-file-entry.[ch]: made it to use GtkFileChooser API
+	* libgnomeui/gnome-icon-entry.c: ditto
+	* libgnomeui/gnome-pixmap-entry.c: ditto
+
 2004-01-21  Iain <iain@prettypeople.org>
 
 	* libgnomeui/gnome_segv.c (main): Remove the separator from the window
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	24 Jan 2004 18:15:41 -0000
@@ -42,7 +42,9 @@
 #include <gtk/gtkbutton.h>
 #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>
 
@@ -389,26 +391,30 @@
 }
 
 static void
-browse_dialog_ok (GtkWidget *widget, gpointer data)
+browse_dialog_response (GtkWidget *widget, gint response, gpointer data)
 {
-	GtkFileSelection *fs;
+	GtkFileChooser *fc;
 	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"));
-	entry = gnome_file_entry_gtk_entry (fentry);
-
-	locale_filename = gtk_file_selection_get_filename (fs);
-	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));
+	if (response == GTK_RESPONSE_ACCEPT) {
+		fc = GTK_FILE_CHOOSER (data);
+		fentry = GNOME_FILE_ENTRY (g_object_get_data (G_OBJECT (fc), "gnome_file_entry"));
+		entry = gnome_file_entry_gtk_entry (fentry);
+
+		locale_filename = gtk_file_chooser_get_filename (fc);
+		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 (fc));
+	} else {
+		gtk_widget_destroy (widget);
+	}
 }
 
 static void
@@ -417,7 +423,7 @@
 	GnomeFileEntry *fentry;
 	fentry = GNOME_FILE_ENTRY (data);
 
-	fentry->fsw = NULL;
+	fentry->fcw = NULL;
 }
 
 /* Does tilde (home directory) expansion on a string */
@@ -507,66 +513,70 @@
 static void
 browse_clicked(GnomeFileEntry *fentry)
 {
-	GtkFileSelection *fs;
+	GtkFileChooser *fc;
 	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->fcw) {
+		gtk_widget_show (fentry->fcw);
+		if (fentry->fcw->window)
+			gdk_window_raise (fentry->fcw->window);
+		fc = GTK_FILE_CHOOSER (fentry->fcw);
+
+		gtk_file_chooser_set_folder_mode (fc, fentry->_priv->directory_entry);
 
 		p = build_filename (fentry);
 		if (p != NULL) {
-			gtk_file_selection_set_filename (fs, p);
+			gtk_file_chooser_set_filename (fc, p);
 			g_free (p);
 		}
 		return;
 	}
 
+	fentry->fcw = 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);
 
-	fentry->fsw = gtk_file_selection_new (fentry->_priv->browse_dialog_title
-					      ? fentry->_priv->browse_dialog_title
-					      : _("Select file"));
+	gtk_dialog_set_default_response (GTK_DIALOG (fentry->fcw), GTK_RESPONSE_ACCEPT);
 
 	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));
+		gtk_window_set_transient_for (GTK_WINDOW (fentry->fcw), GTK_WINDOW(toplevel));
+
+	g_object_set_data (G_OBJECT (fentry->fcw), "gnome_file_entry", fentry);
 
-	g_object_set_data (G_OBJECT (fentry->fsw), "gnome_file_entry", fentry);
+	fc = GTK_FILE_CHOOSER (fentry->fcw);
 
-	fs = GTK_FILE_SELECTION (fentry->fsw);
-	gtk_widget_set_sensitive(fs->file_list,
-				 ! fentry->_priv->directory_entry);
+	gtk_file_chooser_set_folder_mode (fc, fentry->_priv->directory_entry);
 
 	p = build_filename (fentry);
 	if (p != NULL) {
-		gtk_file_selection_set_filename (fs, p);
+		gtk_file_chooser_set_filename (fc, p);
 		g_free (p);
 	}
 
-	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)),
+	closure = g_cclosure_new (G_CALLBACK (browse_dialog_response), fc, NULL);
+	g_object_watch_closure (G_OBJECT (fentry->fcw), closure);
+
+	g_signal_connect_closure_by_id (fc,
+					g_signal_lookup ("response", G_OBJECT_TYPE (fc)),
 					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 (fentry->fcw, "destroy",
 			  G_CALLBACK (browse_dialog_kill),
 			  fentry);
 
 	if (fentry->_priv->is_modal)
-		gtk_window_set_modal (GTK_WINDOW (fentry->fsw), TRUE);
+		gtk_window_set_modal (GTK_WINDOW (fentry->fcw), TRUE);
 
-	gtk_widget_show (fentry->fsw);
+	gtk_widget_show (fentry->fcw);
 }
 
 static void
@@ -706,9 +716,9 @@
 
 	fentry = GNOME_FILE_ENTRY (object);
 
-	if (fentry->fsw != NULL)
-		gtk_widget_destroy (fentry->fsw);
-	fentry->fsw = NULL;
+	if (fentry->fcw != NULL)
+		gtk_widget_destroy (fentry->fcw);
+	fentry->fcw = NULL;
 
 	GNOME_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
 }
Index: libgnomeui/gnome-file-entry.h
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-file-entry.h,v
retrieving revision 1.34
diff -u -r1.34 gnome-file-entry.h
--- libgnomeui/gnome-file-entry.h	14 Oct 2003 21:23:36 -0000	1.34
+++ libgnomeui/gnome-file-entry.h	24 Jan 2004 18:15:43 -0000
@@ -62,7 +62,7 @@
 	 * some apps bind it and mess with the file selector.
 	 * this is evil, but can't be helped unless we provide
 	 * alternatives. */
-	GtkWidget *fsw;
+	GtkWidget *fcw;
 
 	/* gnome-icon-entry needs to access this, but it's
 	 * not for public consumption, think of it as protected */
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	24 Jan 2004 18:15:53 -0000
@@ -42,7 +42,7 @@
 #include <gtk/gtkbutton.h>
 #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>
@@ -412,13 +412,13 @@
         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;
@@ -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,8 +511,7 @@
 browse_clicked(GnomeFileEntry *fentry, GnomeIconEntry *ientry)
 {
 	GtkWidget *w;
-	GtkWidget *hbox;
-	GtkFileSelection *fs;
+	GtkFileChooser *fc;
 	GClosure *closure;
 
 	g_return_if_fail (fentry != NULL);
@@ -520,34 +519,22 @@
 	g_return_if_fail (ientry != NULL);
 	g_return_if_fail (GNOME_IS_ICON_ENTRY (ientry));
 
-	if(!fentry->fsw)
+	if(!fentry->fcw)
 		return;
-	fs = GTK_FILE_SELECTION(fentry->fsw);
+	fc = GTK_FILE_CHOOSER (fentry->fcw);
 
-	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(_("Preview"));
+	w = gtk_frame_new("");
+	gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_NONE);
 	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);
 }
 
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	24 Jan 2004 18:16:00 -0000
@@ -39,7 +39,7 @@
 #include <gtk/gtkbutton.h>
 #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>
@@ -268,7 +268,7 @@
 }
 
 static void
-setup_preview(GtkTreeSelection *selection, GtkWidget *widget)
+setup_preview (GtkWidget *widget, gpointer data)
 {
 	const char *p;
 	GList *l;
@@ -276,12 +276,12 @@
         GdkPixbuf *pixbuf, *scaled;
 	int w,h;
 	GtkWidget *frame;
-	GtkFileSelection *fs;
+	GtkFileChooser *fc;
 
 	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;
@@ -291,7 +291,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;
@@ -318,7 +318,6 @@
 	gtk_widget_show(pp);
 
 	gtk_container_add(GTK_CONTAINER(frame),pp);
-
 }
 
 static void
@@ -361,46 +360,38 @@
 browse_clicked(GnomeFileEntry *fentry, GnomePixmapEntry *pentry)
 {
 	GtkWidget *w;
-	GtkWidget *hbox;
-
-	GtkFileSelection *fs;
+	GtkFileChooser *fc;
+	gchar *path;
 
 	g_return_if_fail (fentry != NULL);
 	g_return_if_fail (GNOME_IS_FILE_ENTRY (fentry));
 	g_return_if_fail (pentry != NULL);
 	g_return_if_fail (GNOME_IS_PIXMAP_ENTRY (pentry));
 
-	if(!fentry->fsw)
+	if(!fentry->fcw)
 		return;
 
-	fs = GTK_FILE_SELECTION(fentry->fsw);
+	fc = GTK_FILE_CHOOSER (fentry->fcw);
 
 	/* we already got this */
-	if (g_object_get_data (G_OBJECT (fs->file_list), "frame") != NULL)
+	if (gtk_file_chooser_get_preview_widget (fc) != NULL)
 		return;
 
-	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 ("");
+	gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_NONE);
+	gtk_widget_show (w);
 
-	w = gtk_frame_new(_("Preview"));
-	gtk_widget_show(w);
-	gtk_box_pack_end(GTK_BOX(hbox),w,FALSE,FALSE,0);
+	gtk_file_chooser_set_preview_widget (fc, w);
 	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);
+	g_signal_connect (G_OBJECT (fc), "update-preview",
+			  G_CALLBACK (setup_preview), NULL);
+
+	/* the path can be already set */
+	if ((path = gtk_file_chooser_get_filename (fc)) != NULL)
+		setup_preview (fc, NULL);
+
+	g_free (path);
 }
 
 static void
