PATCH: Use new gnome file selector



Hi,

 here's a patch to use the new gnome file selector. After this patch is
applied, the file selector can be enabled by giving
--enable-gnome-file-selector to configure.
Currently it is used for saving MIME attachments only, not for attaching
files to emails. That's where the old one was most annoying, IMHO.
Unfortunately the new file selector has some serious shortcomings so far,
some of which make it no better than the old one. I have also included a
patch against gnome-file-selector-0.1 to correct these problems. That patch
will be submitted to the gnome-fileselector maintainers and will hopefully
make it into the file selector in due time.
For now, you will need to get gnome-file-selector-0.1, apply the patch,
compile and install. Make sure that any files that are placed in
/usr/local/share/oaf are moved to /usr/share/oaf or the file selector will
not work. This is done best by giving --prefix=/usr to configure.
After Balsa is comiled with the new option, you can then enjoy a file
selector that does not lose the default file name everytime you change
directories.

Melanie
diff -b -B -r -u -P --exclude-from=ignore ../balsa-cvs/acconfig.h ./acconfig.h
--- ../balsa-cvs/acconfig.h	Mon Aug  6 00:30:51 2001
+++ ./acconfig.h	Fri Aug 10 13:43:32 2001
@@ -51,3 +51,6 @@
 
 /* use pcre instead of `standard' rexexp's? */
 #undef HAVE_PCRE
+
+/* Use the new gnome file selector= */
+#undef HAVE_GNOME_FILESEL
diff -b -B -r -u -P --exclude-from=ignore ../balsa-cvs/configure.in ./configure.in
--- ../balsa-cvs/configure.in	Mon Aug  6 00:30:51 2001
+++ ./configure.in	Fri Aug 10 13:45:07 2001
@@ -73,6 +73,53 @@
 LDFLAGS="$balsa_save_LDFLAGS"
 LIBS="$balsa_save_LIBS"
 
+dnl
+dnl Embraced from Evolution
+dnl
+AC_DEFUN(EVO_CHECK_LIB, [
+	dispname="$1"
+	pkgname="$2"
+	minvers="$3"
+	maxvers="$4"
+
+	AC_MSG_CHECKING(for $dispname)
+
+	if gnome-config --libs $pkgname > /dev/null 2>&1; then
+		pkgvers=`gnome-config --modversion $pkgname | sed -e 's/^[[^0-9]]*//'`
+	else
+		pkgvers=not
+	fi
+	AC_MSG_RESULT($pkgvers found)
+
+	pkgvers=`echo $pkgvers | awk -F. '{ print $[]1 * 1000000 + $[]2 * 10000 + $[]3 * 100 + $[]4;}'`
+	cmpminvers=`echo $minvers | awk -F. '{ print $[]1 * 1000000 + $[]2 * 10000 + $[]3 * 100 + $[]4;}'`
+	cmpmaxvers=`echo $maxvers | awk -F. '{ print $[]1 * 1000000 + $[]2 * 10000 + $[]3 * 100 + $[]4;}'`
+	ok=yes
+	if test "$pkgvers" -lt $cmpminvers; then
+		ok=no
+	elif test -n "$maxvers" -a "$pkgvers" -ge $cmpmaxvers; then
+		ok=no
+	fi
+	if test $ok = no; then
+		case $maxvers in
+		"")
+			dispvers="$minvers or higher"
+			;;
+		$minvers)
+			dispvers="$minvers (exactly)"
+			;;
+		*)
+			dispvers="$minvers or higher, but less than $maxvers,"
+			;;
+		esac
+
+		AC_MSG_ERROR([
+""
+"You need $dispname $dispvers to build file-sel."
+"If you think you already have this installed, consult the README."])
+	fi
+])
+
 dnl ######################################################################################
 dnl Check for a recent enough version of gnome-libs.
 dnl ######################################################################################
@@ -246,6 +293,62 @@
 	AC_MSG_RESULT([no])
 fi
 
+AC_ARG_ENABLE([gnome-file-selector], [  --enable-gnome-file-selector Use the gnome file selector if available (experimental) [default=no]],[
+	check_gnome_file_selector=$enableval
+],[
+	check_gnome_file_selector=no
+])
+
+gnome_file_selector=no
+if test x"$use_threads" = xyes -a x"$check_gnome_file_selector" = xyes ; then
+dnl 
+dnl GNOME Libraries
+dnl 
+	EVO_CHECK_LIB(Bonobo, bonobox, 1.0)
+	EVO_CHECK_LIB(libglade, libglade, 0.14)
+	EVO_CHECK_LIB(gdk-pixbuf canvas item, gnomecanvaspixbuf, 0.9.0)
+	EVO_CHECK_LIB(gal, gal, 0.8.99.2)
+	EVO_CHECK_LIB(vfs, vfs, 1.0)
+	EVO_CHECK_LIB(eel, eel, 1.0)
+
+dnl
+dnl IDL flags
+dnl
+	IDL_FLAGS=`gnome-config --cflags idl`
+	for path in `echo $GNOME_PATH | awk 'BEGIN { RS = ":"; } { print;}'`; do
+		IDL_FLAGS="$IDL_FLAGS -I$path/share/idl"
+	done
+	AC_SUBST(IDL_FLAGS)
+
+dnl
+dnl The libraries exported
+dnl
+
+	WIDGET_LIBRARIES="bonobo gnomeui gal gnomecanvaspixbuf"
+	WIDGET_LIBS=`gnome-config --libs $WIDGET_LIBRARIES`
+	WIDGET_CFLAGS=`gnome-config --cflags $WIDGET_LIBRARIES`
+
+	AC_SUBST(WIDGET_LIBS)
+	AC_SUBST(WIDGET_CFLAGS)
+
+	FLIST_LIBRARIES="bonobox gal vfs eel $WIDGET_LIBRARIES"
+	FLIST_LIBS=`gnome-config --libs $FLIST_LIBRARIES`
+	FLIST_CFLAGS=`gnome-config --cflags $FLIST_LIBRARIES`
+
+	AC_SUBST(FLIST_LIBS)
+	AC_SUBST(FLIST_CFLAGS)
+
+	FILESEL_LIBRARIES="bonobox libglade gal vfs $WIDGET_LIBRARIES"
+	FILESEL_LIBS=`gnome-config --libs $FILESEL_LIBRARIES`
+	FILESEL_CFLAGS=`gnome-config --cflags $FILESEL_LIBRARIES`
+		
+	AC_SUBST(FILESEL_LIBS)
+	AC_SUBST(FILESEL_CFLAGS)
+
+	AC_DEFINE(HAVE_GNOME_FILESEL)
+	gnome_file_selector=yes
+
+fi
 
 dnl #########################################################################
 dnl  Check for LDAP if available.
@@ -595,6 +698,7 @@
 echo "                   Use SSL: $with_ssl"
 echo "                  Use SASL: $need_sasl"
 echo "          Printing support: $printing_support"
+echo "       Gnome file selector: $gnome_file_selector"
 echo ""
 
 if test x"$BALSA_FROM_CVS" = xyes ; then
diff -b -B -r -u -P --exclude-from=ignore ../balsa-cvs/src/balsa-message.c ./src/balsa-message.c
--- ../balsa-cvs/src/balsa-message.c	Mon Aug  6 00:30:53 2001
+++ ./src/balsa-message.c	Fri Aug 10 19:06:20 2001
@@ -72,6 +73,9 @@
 
     /* True if balsa knows how to display this part */
     gboolean can_display;
+
+	/* BalsaMessage this part belongs to */
+	BalsaMessage *bmessage;
 };
 
 static gint balsa_message_signals[LAST_SIGNAL];
@@ -175,6 +179,11 @@
 				    LibBalsaMessage* msg);
 static void part_info_free(BalsaPartInfo* info);
 
+#ifdef HAVE_GNOME_FILESEL
+static void listener_cb (BonoboListener *listener, gchar *event_name,
+             CORBA_any *any, CORBA_Environment *ev, gpointer text);
+#endif
+
 guint balsa_message_get_type()
 {
     static guint balsa_message_type = 0;
@@ -227,6 +236,10 @@
 static void
 balsa_message_init(BalsaMessage * bm)
 {
+#ifdef HAVE_GNOME_FILESEL
+	bm->fsel_global.es = CORBA_OBJECT_NIL; 
+	bm->fsel_global.dialog = NULL;
+#endif
     bm->table = gtk_table_new(3, 1, FALSE);
     gtk_container_add(GTK_CONTAINER(bm), bm->table);
     gtk_widget_show(bm->table);
@@ -301,6 +314,7 @@
 
 }
 
+#ifndef HAVE_GNOME_FILESEL
 static void
 save_dialog_ok(GtkWidget* button, GtkWidget* save_dialog)
 {
@@ -345,7 +359,97 @@
     }
     gtk_object_destroy(GTK_OBJECT(save_dialog));
 }
+#endif
+
+#ifdef HAVE_GNOME_FILESEL
+static void
+save_part(BalsaPartInfo * info)
+{
+	GtkWidget *filesel;
+	char *moniker;
+	char moniker_final[1024];
+	char open_uri[1024];
+	Bonobo_Unknown	corba_control;
+	CORBA_Environment ev;
+
+	BalsaMessage *bm=info->bmessage;
+
+    g_return_if_fail(info != 0);
+
+	if(bm->fsel_global.dialog) {
+		gtk_widget_show(bm->fsel_global.dialog);
+		gdk_window_raise(bm->fsel_global.dialog->window);
+		return;
+	}
+
+	moniker = "OAFIID:GNOME_FileSelector!"
+		"AcceptDirectories=False;"
+		"Application=balsa;"
+		"LocalURIsOnly=True;"
+		"MultipleSelection=False;";
+
+	strcpy(moniker_final, moniker);
+printf("%s\n", moniker_final);
+	filesel = bonobo_widget_new_control (moniker_final, CORBA_OBJECT_NIL);
+
+	if(!filesel) {
+		bm->fsel_global.dialog = gnome_error_dialog ("Could not create a File Selector.\n");
+		gnome_dialog_run_and_close(GNOME_DIALOG(bm->fsel_global.dialog));
+		bm->fsel_global.dialog=NULL;
+		return;
+	}
+
+	bm->fsel_global.filesel=filesel;
+
+	if(info->body->filename)
+		bonobo_widget_set_property(BONOBO_WIDGET(filesel),
+				"DefaultFileName", info->body->filename,
+				NULL);
+	if(balsa_app.save_dir)
+	{
+		sprintf(open_uri, "file://%s", balsa_app.save_dir);
+		bonobo_widget_set_property(BONOBO_WIDGET(filesel),
+				"RequestedURI", open_uri,
+				NULL);
+	}
+
+	corba_control = bonobo_widget_get_objref (BONOBO_WIDGET (filesel));
+
+	CORBA_exception_init (&ev);
+
+	bm->fsel_global.es = Bonobo_Unknown_queryInterface (corba_control,
+			"IDL:Bonobo/EventSource:1.0",
+			&ev);
+
+	if(BONOBO_EX(&ev)) {
+		bm->fsel_global.dialog = gnome_error_dialog ("There was an error getting an event source from the file selector.\n");
+		gnome_dialog_run_and_close(GNOME_DIALOG(bm->fsel_global.dialog));
+		bonobo_object_release_unref (corba_control, &ev);
+		CORBA_exception_free (&ev);
+		bm->fsel_global.dialog=NULL;
+		return;
+	}
+
+	bm->fsel_global.listener = bonobo_listener_new (listener_cb, info);
+
+	bm->fsel_global.id = Bonobo_EventSource_addListenerWithMask (
+			bm->fsel_global.es, BONOBO_OBJREF (bm->fsel_global.listener),
+			"GNOME/FileSelector:ButtonClicked",
+			&ev);
+
+	CORBA_exception_free (&ev);
 
+	bm->fsel_global.dialog = gtk_window_new (GTK_WINDOW_DIALOG);
+	gtk_container_add (GTK_CONTAINER (bm->fsel_global.dialog), filesel);
+	gtk_widget_set_usize (bm->fsel_global.dialog, 560, 450);
+	gtk_window_set_title (GTK_WINDOW (bm->fsel_global.dialog),
+			"Save MIME part");
+	gtk_window_set_modal (GTK_WINDOW (bm->fsel_global.dialog), TRUE);
+
+	gtk_widget_show_all (bm->fsel_global.dialog);
+
+}
+#else /* HAVE_GNOME_FILESEL */
 static void
 save_part(BalsaPartInfo * info)
 {
@@ -384,6 +488,7 @@
     gtk_window_set_modal(GTK_WINDOW(save_dialog), TRUE);
     gtk_widget_show_all(GTK_WIDGET(save_dialog));
 }
+#endif /* HAVE_GNOME_FILESEL */
 
 GtkWidget *
 balsa_message_new(void)
@@ -764,6 +869,7 @@
 
     GtkWidget *image;
 
+	info->bmessage=bm;
     libbalsa_message_body_save_temporary(info->body, NULL);
 
 #ifndef USE_PIXBUF
@@ -820,7 +926,7 @@
     const gchar *cmd;
     gchar *content_type;
     
-
+	info->bmessage=bm;
     vbox = gtk_vbox_new(FALSE, 1);
     gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
 
@@ -2505,3 +2611,95 @@
     gtk_object_destroy(GTK_OBJECT(dialog));
 }
 #endif
+
+#ifdef HAVE_GNOME_FILESEL
+
+static void
+listener_cb (BonoboListener *listener, 
+             gchar *event_name,
+             CORBA_any *any,
+             CORBA_Environment *ev,
+             gpointer data)
+{
+	CORBA_sequence_CORBA_string *seq;
+	static char *subtype;
+	char *file;
+	char *current_dir;
+	char file_final[1024];
+    gboolean do_save, result;
+    BalsaPartInfo * info;
+	BalsaMessage *bm;
+
+	info=data;
+	bm=info->bmessage;
+
+	subtype = bonobo_event_subtype (event_name);
+
+	gtk_widget_hide (bm->fsel_global.dialog);
+
+	if (!strcmp (subtype, "Cancel")) {
+		g_free (subtype);
+		return;
+	}
+
+	g_free (subtype);
+
+	seq = any->_value;
+	g_assert (seq->_length == 1);
+
+	file = seq->_buffer[0];
+	if (!strncasecmp (file, "file:", 5))
+		file += 5;
+
+	bonobo_widget_get_property(BONOBO_WIDGET(bm->fsel_global.filesel),
+			"CurrentWorkingURI", &current_dir,
+			NULL);
+
+	if (!strncasecmp (current_dir, "file:", 5))
+		current_dir += 5;
+
+	file_final[0]='\0';
+	if(file[0] != '/') {
+		strcpy(file_final, current_dir);
+		strcat(file_final, "/");
+	}
+
+	strcat(file_final, file);
+
+	gtk_widget_destroy(bm->fsel_global.dialog);
+	bm->fsel_global.dialog=NULL;
+
+    g_free(balsa_app.save_dir);
+    balsa_app.save_dir = g_dirname(file_final);
+    
+    if ( access(file_final, F_OK) == 0 ) {
+	GtkWidget *confirm;
+	
+	/* File exists. check if they really want to overwrite */
+	confirm = gnome_question_dialog_modal_parented(
+	    _("File already exists. Overwrite?"),
+	    NULL, NULL, GTK_WINDOW(balsa_app.main_window));
+	do_save = (gnome_dialog_run_and_close(GNOME_DIALOG(confirm)) == 0);
+	if(do_save)
+	    unlink(file_final);
+    } else
+	do_save = TRUE;
+    
+    if ( do_save ) {
+	result = libbalsa_message_body_save(info->body, NULL, file_final);
+	if (!result) {
+	    gchar *msg;
+	    GtkWidget *msgbox;
+	    
+	    msg = g_strdup_printf(_(" Could not save %s: %s"), 
+				  file_final, strerror(errno));
+	    msgbox = gnome_error_dialog_parented(msg, GTK_WINDOW
+						 (balsa_app.main_window));
+	    g_free(msg);
+	    gnome_dialog_run_and_close(GNOME_DIALOG(msgbox));
+	}
+    }
+	return; 
+}
+
+#endif /* HAVE_GNOME_FILESEL */
diff -b -B -r -u -P --exclude-from=ignore ../balsa-cvs/src/balsa-message.h ./src/balsa-message.h
--- ../balsa-cvs/src/balsa-message.h	Mon Aug  6 00:30:53 2001
+++ ./src/balsa-message.h	Fri Aug 10 18:13:31 2001
@@ -22,6 +22,18 @@
 #ifndef __BALSA_MESSAGE_H__
 #define __BALSA_MESSAGE_H__
 
+#ifdef HAVE_GNOME_FILESEL
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <bonobo/bonobo-exception.h>
+#include <bonobo/bonobo-listener.h>
+#include <bonobo/bonobo-main.h>
+#include <bonobo/bonobo-widget.h>
+
+#endif /* HAVE_GNOME_FILESEL */
+
 #include <gnome.h>
 #include "libbalsa.h"
 
@@ -40,6 +52,16 @@
 
 typedef struct _BalsaPartInfo BalsaPartInfo;
 
+#ifdef HAVE_GNOME_FILESEL
+struct _fsel_global{
+	Bonobo_EventSource es;
+	GtkWidget *dialog;
+	Bonobo_EventSource_ListenerId id;
+	BonoboListener *listener;
+	GtkWidget *filesel;
+};
+#endif /* HAVE_GNOME_FILESEL */
+
 struct _BalsaMessage {
 	GtkViewport parent;
 
@@ -63,6 +85,9 @@
 	BalsaPartInfo *current_part;
 
 	LibBalsaMessage *message;
+#ifdef HAVE_GNOME_FILESEL
+	struct _fsel_global fsel_global;
+#endif
 };
 
 struct _BalsaMessageClass {
diff -b -B -r -u -P --exclude-from=ignore ../balsa-cvs/src/main.c ./src/main.c
--- ../balsa-cvs/src/main.c	Mon Aug  6 00:30:53 2001
+++ ./src/main.c	Fri Aug 10 16:10:47 2001
@@ -39,6 +39,19 @@
 #include <pthread.h>
 #endif
 
+#ifdef HAVE_GNOME_FILESEL
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <bonobo/bonobo-exception.h>
+#include <bonobo/bonobo-listener.h>
+#include <bonobo/bonobo-main.h>
+#include <bonobo/bonobo-widget.h>
+
+#include <liboaf/oaf-mainloop.h>
+#endif /* HAVE_GNOME_FILESEL */
+
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
 #endif
@@ -128,6 +141,9 @@
 
     gnome_init_with_popt_table(PACKAGE, VERSION, argc, argv, options, 0,
 			       NULL);
+#ifdef HAVE_GNOME_FILESEL
+	bonobo_init (oaf_init (argc, argv), NULL, NULL);
+#endif
 }
 
 /* check_special_mailboxes: 
@@ -429,7 +445,11 @@
     signal( SIGPIPE, SIG_IGN );
 
     gdk_threads_enter();
+#ifdef HAVE_GNOME_FILESEL
+	bonobo_main();
+#else
     gtk_main();
+#endif
     gdk_threads_leave();
 
     gdk_colormap_unref(balsa_app.colormap);
diff -b -B -r -u -P --exclude-from=ignore ../gnome-file-selector-0.1/fsel/file-selector.c ./fsel/file-selector.c
--- ../gnome-file-selector-0.1/fsel/file-selector.c	Mon Aug  6 16:23:05 2001
+++ ./fsel/file-selector.c	Fri Aug 10 18:43:25 2001
@@ -65,6 +65,7 @@
 	PROP_MIME_TYPES,
 	PROP_MIME_TYPES_SEQUENCE,
 	PROP_MULTIPLE_SELECTION,
+	PROP_REQUESTED_URI,
 	PROP_LAST
 };
 
@@ -78,7 +79,8 @@
 	"LocalURIsOnly",
 	"MimeTypes",
 	"MimeTypesSequence",
-	"MultipleSelection"
+	"MultipleSelection",
+	"RequestedURI"
 };
 
 static const char *prop_desc[] = {
@@ -337,6 +339,12 @@
 	FileSelector *fs = FILE_SELECTOR (user_data);
 
 	switch (arg_id) {
+	case PROP_REQUESTED_URI:
+		bonobo_widget_set_property (BONOBO_WIDGET (fs->priv->file_list),
+					    prop_name[PROP_REQUESTED_URI],
+					    BONOBO_ARG_GET_STRING (arg),
+					    NULL);
+		break;
 	case PROP_ACCEPT_DIRS:
 		bonobo_widget_set_property (BONOBO_WIDGET (fs->priv->file_list),
 					    prop_name[PROP_ACCEPT_DIRS],
@@ -415,6 +423,12 @@
 	char *s;
 
 	switch (arg_id) {
+	case PROP_REQUESTED_URI:
+		bonobo_widget_get_property (BONOBO_WIDGET (fs->priv->file_list),
+					    prop_name[PROP_REQUESTED_URI],
+					    &s, NULL);
+		BONOBO_ARG_SET_STRING (arg, s);
+		break;
 	case PROP_ACCEPT_DIRS:
 		bonobo_widget_get_property (BONOBO_WIDGET (fs->priv->file_list),
 					    prop_name[PROP_ACCEPT_DIRS],
@@ -643,7 +657,7 @@
 
 		if (!strcmp (subtype, prop_name[PROP_CURRENT_URI])) {
 			uri_str = BONOBO_ARG_GET_STRING (any);
-			
+printf("URI is %s\n", uri_str);			
 			if (fs->priv->current_uri)
 				gnome_vfs_uri_unref (fs->priv->current_uri);
 			
@@ -653,14 +667,22 @@
 			
 			update_path_tree (fs, uri_str);
 			bonobo_widget_set_property (BONOBO_WIDGET (fs->priv->name_entry),
-						    "Text", "", NULL);
+						    "Text", fs->priv->default_name, NULL);
+			if(fs->priv->default_name && fs->priv->default_name[0])
+				gtk_widget_set_sensitive(fs->priv->action_button,
+				TRUE);
 			proxy_event = TRUE;
 		} else if (!strcmp (subtype, "SelectedURICount")) {
-			fs->priv->flist_is_active = BONOBO_ARG_GET_INT (any) > 0;
+			if((fs->priv->flist_is_active = BONOBO_ARG_GET_INT (any) > 0)) {
+				bonobo_widget_set_property (BONOBO_WIDGET (fs->priv->name_entry),
+							    "Text", "", NULL);
+			}
 			update_action_enabled (fs);
 		} else if (!strcmp (subtype, prop_name[PROP_ACCEPT_DIRS])) {
 			fs->priv->accept_dirs = BONOBO_ARG_GET_BOOLEAN (any);
 			proxy_event = TRUE;
+		} else if (!strcmp (subtype, prop_name[PROP_REQUESTED_URI])) {
+			proxy_event = TRUE;
 		} else if (!strcmp (subtype, prop_name[PROP_MULTIPLE_SELECTION]) ||
 			   !strcmp (subtype, prop_name[PROP_LOCAL_URIS_ONLY]))
 			proxy_event = TRUE;
@@ -971,6 +993,7 @@
 	ADD_PROP (PROP_MIME_TYPES_SEQUENCE, TC_CORBA_sequence_CORBA_string, RW);
 	ADD_PROP (PROP_MULTIPLE_SELECTION,  BONOBO_ARG_BOOLEAN, RW);
 	ADD_PROP (PROP_LOCAL_URIS_ONLY,     BONOBO_ARG_BOOLEAN, RW);
+	ADD_PROP (PROP_REQUESTED_URI,       BONOBO_ARG_STRING,  RW);
 
 	fs->priv->properties = pb;
 	bonobo_control_set_properties (fs->priv->control, pb);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]