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