--- src/file-manager/fm-icon-view.c	2005/08/19 21:17:42	1.1
+++ src/file-manager/fm-icon-view.c	2005/08/20 02:19:13
@@ -79,8 +79,10 @@
 #include <unistd.h>
 #include <esd.h>
 
+#ifndef USE_GST_LAUNCH_AUDIO_PREVIEW
 #define USE_OLD_AUDIO_PREVIEW 1
 #define READ_CHUNK_SIZE 16384
+#endif
 
 #define POPUP_PATH_ICON_APPEARANCE		"/selection/Icon Appearance Items"
 
@@ -116,6 +119,9 @@ struct FMIconViewDetails
 	NautilusAudioPlayerData *audio_player_data;
 	int audio_preview_timeout;
 	NautilusFile *audio_preview_file;
+#if USE_GST_LAUNCH_AUDIO_PREVIEW
+	pid_t audio_preview_pid;
+#endif
 
 	gboolean filter_by_screen;
 	int num_screens;
@@ -1688,6 +1694,20 @@ band_select_ended_callback (NautilusIcon
 	fm_directory_view_stop_batching_selection_changes (FM_DIRECTORY_VIEW (icon_view));
 }
 
+#if USE_GST_LAUNCH_AUDIO_PREVIEW
+static void
+play_child_watch (GPid pid,
+		  gint status,
+		  gpointer data)
+{
+	FMIconView *icon_view;
+	icon_view = FM_ICON_VIEW (data);
+	if (icon_view->details->audio_preview_pid == (pid_t) pid)
+		icon_view->details->audio_preview_pid = 0;
+	g_spawn_close_pid (pid);
+}
+#endif
+
 /* handle the preview signal by inspecting the mime type.  For now, we only preview local sound files. */
 
 /* here's the timer task that actually plays the file using mpg123, ogg123 or play. */
@@ -1695,7 +1715,46 @@ band_select_ended_callback (NautilusIcon
 static gboolean
 play_file (gpointer callback_data)
 {
-#if USE_OLD_AUDIO_PREVIEW	
+#if USE_GST_LAUNCH_AUDIO_PREVIEW
+	char *file_uri;
+	FMIconView *icon_view;
+	GPtrArray *arg_array;
+	gchar **argv;
+	GPid child_pid;
+
+	icon_view = FM_ICON_VIEW (callback_data);
+	
+	file_uri = nautilus_file_get_uri (
+		icon_view->details->audio_preview_file);
+
+	arg_array = g_ptr_array_sized_new (8);
+	g_ptr_array_add (arg_array, g_strdup (GST_LAUNCH_PATH));
+	g_ptr_array_add (arg_array, g_strdup ("gnomevfssrc"));
+	g_ptr_array_add (arg_array, g_strdup_printf ("location=%s", file_uri));
+	g_ptr_array_add (arg_array, g_strdup ("!"));
+	g_ptr_array_add (arg_array, g_strdup ("decodebin"));
+	g_ptr_array_add (arg_array, g_strdup ("!"));
+	g_ptr_array_add (arg_array, g_strdup ("audioconvert"));
+	g_ptr_array_add (arg_array, g_strdup ("!"));
+	g_ptr_array_add (arg_array, g_strdup ("audioscale"));
+	g_ptr_array_add (arg_array, g_strdup ("!"));
+	g_ptr_array_add (arg_array, g_strdup ("gconfaudiosink"));
+	g_ptr_array_add (arg_array, NULL);
+	argv = (gchar **) g_ptr_array_free (arg_array, FALSE);
+
+	if (g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, 
+		    NULL, &child_pid, NULL) == TRUE) {
+		g_child_watch_add (child_pid, play_child_watch, icon_view);
+		if (icon_view->details->audio_preview_pid > 0) {
+			kill (icon_view->details->audio_preview_pid, SIGTERM);
+		}
+		icon_view->details->audio_preview_pid = (pid_t) child_pid;
+	}
+	g_strfreev (argv);
+	g_free (file_uri);
+	
+	icon_view->details->audio_preview_timeout = 0;
+#elif USE_OLD_AUDIO_PREVIEW	
 	NautilusFile *file;
 	FMIconView *icon_view;
 	FILE *sound_process;
@@ -1838,7 +1897,11 @@ static void
 preview_audio (FMIconView *icon_view, NautilusFile *file, gboolean start_flag)
 {		
 	/* Stop current audio playback */
-#if USE_OLD_AUDIO_PREVIEW
+#if USE_GST_LAUNCH_AUDIO_PREVIEW
+	if (icon_view->details->audio_preview_pid > 0) {
+		kill (icon_view->details->audio_preview_pid, SIGTERM);
+	}
+#elif USE_OLD_AUDIO_PREVIEW
 	if (audio_preview_pid > 0) {
 		kill (-audio_preview_pid, SIGTERM);
 		waitpid (audio_preview_pid, NULL, 0);
@@ -1858,7 +1921,9 @@ preview_audio (FMIconView *icon_view, Na
 			
 	if (start_flag) {
 		icon_view->details->audio_preview_file = file;
-#if USE_OLD_AUDIO_PREVIEW			
+#if USE_GST_LAUNCH_AUDIO_PREVIEW			
+		icon_view->details->audio_preview_timeout = g_timeout_add (1000, play_file, icon_view);
+#elif USE_OLD_AUDIO_PREVIEW			
 		icon_view->details->audio_preview_timeout = g_timeout_add (1000, play_file, icon_view);
 #else
 		/* FIXME: Need to kill the existing timeout if there is one? */
@@ -1899,6 +1964,9 @@ should_preview_sound (NautilusFile *file
 static inline gboolean
 can_play_sound (void)
 {
+#if USE_GST_LAUNCH_AUDIO_PREVIEW
+	return TRUE;
+#else
 	int open_result;
 
 #if USE_OLD_AUDIO_PREVIEW			
@@ -1917,6 +1985,7 @@ can_play_sound (void)
 	esd_close (open_result);
 
 	return TRUE;
+#endif
 }
 
 static int
--- configure.in	2005/09/06 01:39:25	1.1
+++ configure.in	2005/09/06 03:49:10
@@ -195,6 +195,35 @@ AC_CHECK_LIB(X11, XOpenDisplay, :, 
 
 dnl ==========================================================================
 
+dnl gst-launch (for audio preview)
+
+AC_MSG_CHECKING([whether to use gst-launch for audio preview])
+AC_ARG_WITH([gst-launch],
+	     AC_HELP_STRING([--with-gst-launch@<:@=path@:>@], 
+			    [Whether to use gst-launch (default: autodetect)]),
+	     [use_gst_launch="$withval"], 
+	     [use_gst_launch=auto])
+AC_MSG_RESULT([$use_gst_launch])
+if test x"$use_gst_launch" = xyes || test x"$use_gst_launch" = xauto ; then
+	AC_PATH_PROGS(GST_LAUNCH_PATH, 
+		      [gst-launch-0.9 gst-launch-0.8 gst-launch], no)
+	if test x"$GST_LAUNCH_PATH" = xno ; then
+		if test x"$use_gst_launch" = xyes; then
+			AC_MSG_ERROR([*** gst-launch not found. Try specifying an argument to --with-gst-launch.])
+		else
+			use_gst_launch=no
+		fi
+	else
+		use_gst_launch="$GST_LAUNCH_PATH"
+	fi
+fi
+if test x"$use_gst_launch" != xno ; then
+	AC_DEFINE(USE_GST_LAUNCH_AUDIO_PREVIEW, 1, [define to use gst-launch for audio preview])
+	AC_DEFINE_UNQUOTED(GST_LAUNCH_PATH, "$use_gst_launch", [the path to gst-launch])
+fi
+
+dnl ==========================================================================
+
 dnl jw (for doc build)
 
 AC_PATH_PROG(JW,jw,no)
@@ -364,4 +393,5 @@ nautilus-$VERSION:
 	compiler:		${CC}
 
 	profiling support:      ${profiling_support}
+	gst-launch audio preview: ${use_gst_launch}
 "
