f24dc7f
--- src/file-manager/fm-icon-view.c	2007/10/21 22:34:58	1.1
f24dc7f
+++ src/file-manager/fm-icon-view.c	2007/10/21 22:42:05
98cbfca
@@ -24,6 +24,7 @@
98cbfca
 
98cbfca
 #include <config.h>
98cbfca
 #include "fm-icon-view.h"
98cbfca
+#include "nautilus-audio-mime-types.h"
98cbfca
 
98cbfca
 #include "fm-actions.h"
98cbfca
 #include "fm-icon-container.h"
f24dc7f
@@ -165,7 +166,6 @@ static const SortCriterion sort_criteria
f24dc7f
 
f24dc7f
 static gboolean default_sort_in_reverse_order = FALSE;
f24dc7f
 static int preview_sound_auto_value;
f24dc7f
-static gboolean gnome_esd_enabled_auto_value;
f24dc7f
 
f24dc7f
 #if USE_OLD_AUDIO_PREVIEW
f24dc7f
 static pid_t audio_preview_pid = 0;
f24dc7f
@@ -1747,6 +1747,28 @@ band_select_ended_callback (NautilusIcon
98cbfca
 
98cbfca
 /* handle the preview signal by inspecting the mime type.  For now, we only preview local sound files. */
98cbfca
 
98cbfca
+#if USE_OLD_AUDIO_PREVIEW
98cbfca
+static char *
98cbfca
+get_preview_command (void)
98cbfca
+{
98cbfca
+	char *command;
98cbfca
+
98cbfca
+	command = g_find_program_in_path ("totem-audio-preview");
98cbfca
+	if (command)
98cbfca
+		return command;
98cbfca
+	command = g_find_program_in_path ("gst-launch-0.10");
98cbfca
+	if (command) {
98cbfca
+		char *new_cmd;
98cbfca
+
f24dc7f
+		new_cmd = g_strdup_printf ("%s playbin uri=fd://0", command);
98cbfca
+		g_free (command);
98cbfca
+		return new_cmd;
98cbfca
+	}
98cbfca
+
98cbfca
+	return NULL;
98cbfca
+}
98cbfca
+#endif /* USE_OLD_AUDIO_PREVIEW */
98cbfca
+
98cbfca
 /* here's the timer task that actually plays the file using mpg123, ogg123 or play. */
98cbfca
 /* FIXME bugzilla.gnome.org 41258: we should get the application from our mime-type stuff */
98cbfca
 static gboolean
f24dc7f
@@ -1757,50 +1779,27 @@ play_file (gpointer callback_data)
98cbfca
 	FMIconView *icon_view;
98cbfca
 	FILE *sound_process;
98cbfca
 	char *file_uri;
98cbfca
-	char *suffix;
98cbfca
-	char *mime_type;
98cbfca
-	const char *command_str;
98cbfca
-	gboolean is_mp3;
98cbfca
-	gboolean is_ogg;
98cbfca
+	char *command_str;
98cbfca
 	pid_t mp3_pid;
98cbfca
 	
98cbfca
 	GnomeVFSResult result;
98cbfca
 	GnomeVFSHandle *handle;
98cbfca
 	char *buffer;
98cbfca
-	const char *audio_device = NULL;
98cbfca
 	GnomeVFSFileSize bytes_read;
98cbfca
 
98cbfca
-	audio_device = g_getenv ("AUDIODEV");
98cbfca
 	icon_view = FM_ICON_VIEW (callback_data);
98cbfca
+
98cbfca
+	command_str = get_preview_command ();
98cbfca
+	if (command_str == NULL)
98cbfca
+		return FALSE;
98cbfca
 	
98cbfca
 	file = icon_view->details->audio_preview_file;
98cbfca
 	file_uri = nautilus_file_get_uri (file);
98cbfca
-	mime_type = nautilus_file_get_mime_type (file);
98cbfca
-	is_mp3 = eel_strcasecmp (mime_type, "audio/mpeg") == 0;
98cbfca
-	is_ogg = eel_strcasecmp (mime_type, "application/ogg") == 0 ||
98cbfca
-                eel_strcasecmp (mime_type, "application/x-ogg") == 0;
98cbfca
 	
98cbfca
 	mp3_pid = fork ();
98cbfca
 	if (mp3_pid == (pid_t) 0) {
98cbfca
 		/* Set the group (session) id to this process for future killing. */
98cbfca
 		setsid();
98cbfca
-		if (is_mp3) {
98cbfca
-			command_str = "mpg123 -y -q -";
98cbfca
-		} else if (is_ogg) {
98cbfca
-			command_str = "ogg123 -q -";
98cbfca
-		} else {
98cbfca
-			suffix = strrchr(file_uri, '.');
98cbfca
-			if (suffix == NULL) {
98cbfca
-				suffix = "wav";
98cbfca
-			} else {
98cbfca
-				suffix += 1; /* skip the period */
98cbfca
-			}
98cbfca
-			if (audio_device) {
98cbfca
-				command_str = g_strdup_printf("play -d %s -t %s -", audio_device, suffix);
98cbfca
-			} else {
98cbfca
-				command_str = g_strdup_printf("play -t %s -", suffix);
98cbfca
-			}
98cbfca
-		}
98cbfca
 
98cbfca
 		/* read the file with gnome-vfs, feeding it to the sound player's standard input */
98cbfca
 		/* First, open the file. */
f24dc7f
@@ -1851,7 +1850,7 @@ play_file (gpointer callback_data)
98cbfca
 	}
98cbfca
 		
98cbfca
 	g_free (file_uri);
98cbfca
-	g_free (mime_type);
98cbfca
+	g_free (command_str);
98cbfca
 
98cbfca
 	icon_view->details->audio_preview_timeout = 0;
98cbfca
 #else
f24dc7f
@@ -1923,15 +1922,30 @@ preview_audio (FMIconView *icon_view, Na
98cbfca
 }
98cbfca
 
98cbfca
 static gboolean
f24dc7f
-should_preview_sound (NautilusFile *file)
98cbfca
+sound_preview_type_supported (NautilusFile *file)
f24dc7f
 {
f24dc7f
-	char *uri;
98cbfca
+	char *mime_type;
98cbfca
+	guint i;
f24dc7f
 
f24dc7f
-	/* Check gnome config sound preference */
f24dc7f
-	if (!gnome_esd_enabled_auto_value) {
98cbfca
+	mime_type = nautilus_file_get_mime_type (file);
98cbfca
+	if (mime_type == NULL)
f24dc7f
 		return FALSE;
98cbfca
+	for (i = 0; i < G_N_ELEMENTS (audio_mime_types); i++) {
f24dc7f
+		GnomeVFSMimeEquivalence equivalence = gnome_vfs_mime_type_get_equivalence (mime_type, audio_mime_types[i]);
f24dc7f
+		if (equivalence == GNOME_VFS_MIME_IDENTICAL || equivalence == GNOME_VFS_MIME_PARENT) {
98cbfca
+			g_free (mime_type);
98cbfca
+			return TRUE;
98cbfca
+		}
f24dc7f
 	}
f24dc7f
 
98cbfca
+	return FALSE;
98cbfca
+}
98cbfca
+
98cbfca
+static gboolean
f24dc7f
+should_preview_sound (NautilusFile *file)
f24dc7f
+{
f24dc7f
+	char *uri;
f24dc7f
+
f24dc7f
 	uri = nautilus_file_get_uri (file);
f24dc7f
 	if (uri && eel_istr_has_prefix (uri, "burn:")) {
f24dc7f
 		g_free (uri);
f24dc7f
@@ -1957,10 +1971,7 @@ can_play_sound (void)
f24dc7f
 	int open_result;
f24dc7f
 
f24dc7f
 #if USE_OLD_AUDIO_PREVIEW			
f24dc7f
-	/* first see if there's already one in progress; if so, return true */
f24dc7f
-	if (audio_preview_pid > 0) {
f24dc7f
-		return TRUE;
f24dc7f
-	}
f24dc7f
+	return TRUE;
f24dc7f
 #endif
f24dc7f
 
f24dc7f
 	/* Now check and see if system has audio out capabilites */
f24dc7f
@@ -1981,25 +1992,17 @@ icon_container_preview_callback (Nautilu
98cbfca
 				 FMIconView *icon_view)
98cbfca
 {
98cbfca
 	int result;
98cbfca
-	char *mime_type, *file_name, *message;
98cbfca
+	char *file_name, *message;
98cbfca
 		
98cbfca
 	result = 0;
98cbfca
 	
98cbfca
 	/* preview files based on the mime_type. */
98cbfca
 	/* at first, we just handle sounds */
98cbfca
 	if (should_preview_sound (file)) {
98cbfca
-		mime_type = nautilus_file_get_mime_type (file);
98cbfca
-
98cbfca
-		if ((eel_istr_has_prefix (mime_type, "audio/")
98cbfca
-		     || eel_istr_has_prefix (mime_type, "application/ogg")
98cbfca
-		     || eel_istr_has_prefix (mime_type, "application/x-ogg"))
98cbfca
-		    && eel_strcasecmp (mime_type, "audio/x-pn-realaudio") != 0
98cbfca
-		    && eel_strcasecmp (mime_type, "audio/x-mpegurl") != 0
98cbfca
-		    && can_play_sound ()) {
98cbfca
+		if (sound_preview_type_supported (file) && can_play_sound ()) {
98cbfca
 			result = 1;
98cbfca
 			preview_audio (icon_view, file, start_flag);
98cbfca
 		}	
98cbfca
-		g_free (mime_type);
98cbfca
 	}
98cbfca
 	
98cbfca
 	/* Display file name in status area at low zoom levels, since
f24dc7f
@@ -2708,10 +2711,6 @@ fm_icon_view_init (FMIconView *icon_view
f24dc7f
 		eel_preferences_add_auto_enum (NAUTILUS_PREFERENCES_PREVIEW_SOUND,
f24dc7f
 					       &preview_sound_auto_value);
f24dc7f
 
f24dc7f
-		eel_preferences_monitor_directory ("/desktop/gnome/sound");
f24dc7f
-		eel_preferences_add_auto_boolean ("/desktop/gnome/sound/enable_esd",
f24dc7f
-						  &gnome_esd_enabled_auto_value);
f24dc7f
-		
f24dc7f
 		setup_sound_preview = TRUE;
f24dc7f
 	}
f24dc7f
 
f24dc7f
--- src/file-manager/nautilus-audio-mime-types.h	2007/10/21 22:36:41	1.1
f24dc7f
+++ src/file-manager/nautilus-audio-mime-types.h	2007/10/21 22:36:50
98cbfca
@@ -0,0 +1,41 @@
98cbfca
+/* generated with mime-types-include.sh in the totem module, don't edit or 
98cbfca
+   commit in the nautilus module without filing a bug against totem */
98cbfca
+static char *audio_mime_types[] = {
98cbfca
+"audio/3gpp",
98cbfca
+"audio/ac3",
98cbfca
+"audio/AMR",
98cbfca
+"audio/AMR-WB",
98cbfca
+"audio/basic",
98cbfca
+"audio/mp4",
98cbfca
+"audio/mpeg",
98cbfca
+"audio/mpegurl",
98cbfca
+"audio/ogg",
98cbfca
+"audio/vnd.rn-realaudio",
98cbfca
+"audio/x-ape",
98cbfca
+"audio/x-flac",
98cbfca
+"audio/x-it",
98cbfca
+"audio/x-m4a",
98cbfca
+"audio/x-matroska",
98cbfca
+"audio/x-mod",
98cbfca
+"audio/x-mp3",
98cbfca
+"audio/x-mpeg",
98cbfca
+"audio/x-mpegurl",
98cbfca
+"audio/x-ms-asf",
98cbfca
+"audio/x-ms-asx",
98cbfca
+"audio/x-ms-wax",
98cbfca
+"audio/x-ms-wma",
98cbfca
+"audio/x-musepack",
98cbfca
+"audio/x-pn-aiff",
98cbfca
+"audio/x-pn-au",
98cbfca
+"audio/x-pn-wav",
98cbfca
+"audio/x-pn-windows-acm",
98cbfca
+"audio/x-realaudio",
98cbfca
+"audio/x-real-audio",
98cbfca
+"audio/x-sbc",
98cbfca
+"audio/x-scpls",
98cbfca
+"audio/x-tta",
98cbfca
+"audio/x-wav",
98cbfca
+"audio/x-wav",
98cbfca
+"audio/x-wavpack",
98cbfca
+"audio/x-vorbis",
98cbfca
+};
f24dc7f
--- src/file-manager/Makefile.am	2007/10/21 22:36:41	1.1
f24dc7f
+++ src/file-manager/Makefile.am	2007/10/21 22:36:50
f24dc7f
@@ -38,6 +38,7 @@ libnautilus_file_manager_la_SOURCES=	\
98cbfca
 	fm-tree-model.h			\
98cbfca
 	fm-tree-view.c			\
98cbfca
 	fm-tree-view.h			\
98cbfca
+	nautilus-audio-mime-types.h	\
98cbfca
 	$(NULL)
98cbfca
 
98cbfca
 EMPTY_VIEW_SOURCES = \