summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog29
-rw-r--r--components/music/nautilus-music-view.c17
-rw-r--r--libnautilus-extensions/Makefile.am2
-rw-r--r--libnautilus-extensions/nautilus-global-preferences.h3
-rw-r--r--libnautilus-extensions/nautilus-sound.c96
-rw-r--r--libnautilus-extensions/nautilus-sound.h36
-rw-r--r--libnautilus-private/Makefile.am2
-rw-r--r--libnautilus-private/nautilus-global-preferences.h3
-rw-r--r--libnautilus-private/nautilus-sound.c96
-rw-r--r--libnautilus-private/nautilus-sound.h36
-rw-r--r--src/file-manager/fm-icon-view.c31
-rw-r--r--src/nautilus-application.c4
12 files changed, 323 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 5730a731c..22821cdb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2000-10-02 Andy Hertzfeld <andy@eazel.com>
+
+ implemented sound process management using gconf to store the
+ process ID of the currently playing sound, and switched sound
+ previewing and part of the music view to use it. This also fixed a
+ process leaking bug, as each time a sound preview terminated, it
+ was leaving a zombie process behind.
+
+ * libnautilus-extensions/Makefile.am:
+ added nautilus-sound to the Makefile
+ * libnautilus-extensions/nautilus-sound.c,h:
+ (kill_sound_if_necessary), (nautilus_sound_initialize),
+ (nautilus_sound_kill_sound), (nautilus_sound_register_sound),
+ (nautilus_sound_can_play_sound):
+ set of routines to keep track of the current sound process
+ * libnautilus-extensions/nautilus-global-preferences.h:
+ added NAUTILUS_PREFERENCE_CURRENT_SOUND_STATE
+
+ * components/music/nautilus-music-view.c:
+ (nautilus_music_view_initialize):
+ use nautilus_sound_can_play_sound instead of private routine
+
+ * src/file-manager/fm-icon-view.c: (play_file), (preview_sound),
+ (icon_container_preview_callback):
+ use nautilus_sound for sound previewing
+
+ * src/nautilus-application.c: (nautilus_application_startup):
+ initialize nautilus_sound
+
2000-10-02 Darin Adler <darin@eazel.com>
Saw the Tinderbox broken, so I just had to fix it. Also, I
diff --git a/components/music/nautilus-music-view.c b/components/music/nautilus-music-view.c
index 99bf0c77a..54ae5528a 100644
--- a/components/music/nautilus-music-view.c
+++ b/components/music/nautilus-music-view.c
@@ -49,6 +49,7 @@
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-label.h>
#include <libnautilus-extensions/nautilus-metadata.h>
+#include <libnautilus-extensions/nautilus-sound.h>
#include <libnautilus-extensions/nautilus-stock-dialogs.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-font-factory.h>
@@ -183,20 +184,6 @@ static void play_current_file (NautilusMusicView *musi
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusMusicView, nautilus_music_view, GTK_TYPE_EVENT_BOX)
-/* utility to determine if we can play sounds */
-static gboolean
-can_play_sounds ()
-{
- int open_result;
-
- open_result = esd_audio_open();
- if (open_result < 0) {
- return FALSE;
- }
-
- esd_audio_close ();
- return TRUE;
-}
static void
nautilus_music_view_initialize_class (NautilusMusicViewClass *klass)
@@ -231,7 +218,7 @@ nautilus_music_view_initialize (NautilusMusicView *music_view)
music_view->details->status_timeout = -1;
music_view->details->slider_dragging = FALSE;
- music_view->details->sound_enabled = can_play_sounds ();
+ music_view->details->sound_enabled = nautilus_sound_can_play_sound ();
/* allocate a vbox to contain all of the views */
diff --git a/libnautilus-extensions/Makefile.am b/libnautilus-extensions/Makefile.am
index a688b4192..01b9108b1 100644
--- a/libnautilus-extensions/Makefile.am
+++ b/libnautilus-extensions/Makefile.am
@@ -111,6 +111,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-scalable-font.c \
nautilus-search-uri.c \
nautilus-self-checks.c \
+ nautilus-sound.c \
nautilus-stock-dialogs.c \
nautilus-string-list.c \
nautilus-string-map.c \
@@ -209,6 +210,7 @@ noinst_HEADERS = \
nautilus-scalable-font.h \
nautilus-search-uri.h \
nautilus-self-checks.h \
+ nautilus-sound.h \
nautilus-stock-dialogs.h \
nautilus-string-list.h \
nautilus-string-map.h \
diff --git a/libnautilus-extensions/nautilus-global-preferences.h b/libnautilus-extensions/nautilus-global-preferences.h
index 38ef8fd7c..4eecaf921 100644
--- a/libnautilus-extensions/nautilus-global-preferences.h
+++ b/libnautilus-extensions/nautilus-global-preferences.h
@@ -43,7 +43,8 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS "/apps/nautilus/preferences/hide_built_in_bookmarks"
/* How wide the sidebar is (or how wide it will be when expanded) */
#define NAUTILUS_PREFERENCES_SIDEBAR_WIDTH "/apps/nautilus/preferences/sidebar_width"
-
+/* Keep track of the sound playing process */
+#define NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE "/apps/nautilus/preferences/sound_state"
/*
* The following preferences are coupled to the user level.
diff --git a/libnautilus-extensions/nautilus-sound.c b/libnautilus-extensions/nautilus-sound.c
new file mode 100644
index 000000000..5068f7196
--- /dev/null
+++ b/libnautilus-extensions/nautilus-sound.c
@@ -0,0 +1,96 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-sound.c: manage the sound playing process and other sound utilities
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Andy Hertzfeld <andy@eazel.com>
+*/
+
+#include <config.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <wait.h>
+#include <esd.h>
+
+#include "nautilus-global-preferences.h"
+#include "nautilus-preferences.h"
+#include "nautilus-sound.h"
+
+static void
+kill_sound_if_necessary (void)
+{
+ pid_t child;
+ int status_result;
+ pid_t sound_process;
+
+ /* fetch the sound state */
+ sound_process = nautilus_preferences_get_enum (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, 0);
+
+ /* if there was a sound playing, kill it */
+ if (sound_process > 0) {
+ kill (-sound_process, SIGTERM);
+ child = waitpid (sound_process, &status_result, 0);
+ }
+}
+
+/* initialize_sound is called at application start up time. It puts the sound system
+ into a quiescent state */
+void
+nautilus_sound_initialize (void)
+{
+ nautilus_preferences_set_enum (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, 0);
+}
+
+/* if there is a sound registered, kill it, and register the empty sound */
+void
+nautilus_sound_kill_sound (void)
+{
+ /* if there is a sound in progress, kill it */
+ kill_sound_if_necessary ();
+
+ /* set the process state to quiescent */
+ nautilus_preferences_set_enum (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, 0);
+}
+
+/* register a new sound process, including kill any old one if necessary */
+void
+nautilus_sound_register_sound (pid_t sound_process)
+{
+ /* if there is a sound in progress, kill it */
+ kill_sound_if_necessary ();
+
+ /* record the new sound process ID */
+ nautilus_preferences_set_enum (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, sound_process);
+}
+
+gboolean
+nautilus_sound_can_play_sound (void)
+{
+ int open_result;
+
+ open_result = esd_audio_open();
+ if (open_result < 0) {
+ return FALSE;
+ }
+
+ esd_audio_close ();
+ return TRUE;
+}
+
diff --git a/libnautilus-extensions/nautilus-sound.h b/libnautilus-extensions/nautilus-sound.h
new file mode 100644
index 000000000..e58aa0744
--- /dev/null
+++ b/libnautilus-extensions/nautilus-sound.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-sound.h: manage the sound playing process and other sound utilities
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Andy Hertzfeld <andy@eazel.com>
+*/
+
+#ifndef NAUTILUS_SOUND_H
+#define NAUTILUS_SOUND_H
+
+#include <glib.h>
+#include <sys/wait.h>
+
+gboolean nautilus_sound_can_play_sound (void);
+void nautilus_sound_initialize (void);
+void nautilus_sound_kill_sound (void);
+void nautilus_sound_register_sound (pid_t sound_process);
+
+#endif /* NAUTILUS_SOUND_H */
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index a688b4192..01b9108b1 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -111,6 +111,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-scalable-font.c \
nautilus-search-uri.c \
nautilus-self-checks.c \
+ nautilus-sound.c \
nautilus-stock-dialogs.c \
nautilus-string-list.c \
nautilus-string-map.c \
@@ -209,6 +210,7 @@ noinst_HEADERS = \
nautilus-scalable-font.h \
nautilus-search-uri.h \
nautilus-self-checks.h \
+ nautilus-sound.h \
nautilus-stock-dialogs.h \
nautilus-string-list.h \
nautilus-string-map.h \
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index 38ef8fd7c..4eecaf921 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -43,7 +43,8 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS "/apps/nautilus/preferences/hide_built_in_bookmarks"
/* How wide the sidebar is (or how wide it will be when expanded) */
#define NAUTILUS_PREFERENCES_SIDEBAR_WIDTH "/apps/nautilus/preferences/sidebar_width"
-
+/* Keep track of the sound playing process */
+#define NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE "/apps/nautilus/preferences/sound_state"
/*
* The following preferences are coupled to the user level.
diff --git a/libnautilus-private/nautilus-sound.c b/libnautilus-private/nautilus-sound.c
new file mode 100644
index 000000000..5068f7196
--- /dev/null
+++ b/libnautilus-private/nautilus-sound.c
@@ -0,0 +1,96 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-sound.c: manage the sound playing process and other sound utilities
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Andy Hertzfeld <andy@eazel.com>
+*/
+
+#include <config.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <wait.h>
+#include <esd.h>
+
+#include "nautilus-global-preferences.h"
+#include "nautilus-preferences.h"
+#include "nautilus-sound.h"
+
+static void
+kill_sound_if_necessary (void)
+{
+ pid_t child;
+ int status_result;
+ pid_t sound_process;
+
+ /* fetch the sound state */
+ sound_process = nautilus_preferences_get_enum (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, 0);
+
+ /* if there was a sound playing, kill it */
+ if (sound_process > 0) {
+ kill (-sound_process, SIGTERM);
+ child = waitpid (sound_process, &status_result, 0);
+ }
+}
+
+/* initialize_sound is called at application start up time. It puts the sound system
+ into a quiescent state */
+void
+nautilus_sound_initialize (void)
+{
+ nautilus_preferences_set_enum (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, 0);
+}
+
+/* if there is a sound registered, kill it, and register the empty sound */
+void
+nautilus_sound_kill_sound (void)
+{
+ /* if there is a sound in progress, kill it */
+ kill_sound_if_necessary ();
+
+ /* set the process state to quiescent */
+ nautilus_preferences_set_enum (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, 0);
+}
+
+/* register a new sound process, including kill any old one if necessary */
+void
+nautilus_sound_register_sound (pid_t sound_process)
+{
+ /* if there is a sound in progress, kill it */
+ kill_sound_if_necessary ();
+
+ /* record the new sound process ID */
+ nautilus_preferences_set_enum (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, sound_process);
+}
+
+gboolean
+nautilus_sound_can_play_sound (void)
+{
+ int open_result;
+
+ open_result = esd_audio_open();
+ if (open_result < 0) {
+ return FALSE;
+ }
+
+ esd_audio_close ();
+ return TRUE;
+}
+
diff --git a/libnautilus-private/nautilus-sound.h b/libnautilus-private/nautilus-sound.h
new file mode 100644
index 000000000..e58aa0744
--- /dev/null
+++ b/libnautilus-private/nautilus-sound.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-sound.h: manage the sound playing process and other sound utilities
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Andy Hertzfeld <andy@eazel.com>
+*/
+
+#ifndef NAUTILUS_SOUND_H
+#define NAUTILUS_SOUND_H
+
+#include <glib.h>
+#include <sys/wait.h>
+
+gboolean nautilus_sound_can_play_sound (void);
+void nautilus_sound_initialize (void);
+void nautilus_sound_kill_sound (void);
+void nautilus_sound_register_sound (pid_t sound_process);
+
+#endif /* NAUTILUS_SOUND_H */
diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c
index 985f63c94..2b9429cf7 100644
--- a/src/file-manager/fm-icon-view.c
+++ b/src/file-manager/fm-icon-view.c
@@ -54,10 +54,10 @@
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-link.h>
#include <libnautilus-extensions/nautilus-metadata.h>
+#include <libnautilus-extensions/nautilus-sound.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus/nautilus-bonobo-ui.h>
#include <locale.h>
-#include <esd.h>
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
@@ -172,7 +172,6 @@ static const SortCriterion sort_criteria[] = {
/* some state variables used for sound previewing */
-static pid_t mp3_pid = 0;
static int timeout = -1;
struct FMIconViewDetails
@@ -1756,7 +1755,8 @@ play_file (gpointer callback_data)
char *file_uri;
char *file_path, *mime_type;
gboolean is_mp3;
-
+ pid_t mp3_pid;
+
file = NAUTILUS_FILE (callback_data);
file_uri = nautilus_file_get_uri (file);
file_path = gnome_vfs_get_local_path_from_uri (file_uri);
@@ -1774,8 +1774,9 @@ play_file (gpointer callback_data)
execlp ("play", "play", file_path, NULL);
}
- /* Who cares about storage leaks in the fork? */
_exit (0);
+ } else {
+ nautilus_sound_register_sound (mp3_pid);
}
}
@@ -1799,10 +1800,19 @@ play_file (gpointer callback_data)
static void
preview_sound (NautilusFile *file, gboolean start_flag)
{
+ /*
+ pid_t child;
+ int status_result;
+
if (mp3_pid) {
kill (-mp3_pid, SIGTERM);
+ child = waitpid (mp3_pid, &status_result, 0);
mp3_pid = 0;
}
+ */
+
+ nautilus_sound_kill_sound ();
+
if (timeout >= 0) {
gtk_timeout_remove (timeout);
timeout = -1;
@@ -1820,19 +1830,10 @@ icon_container_preview_callback (NautilusIconContainer *container,
{
int result;
char *mime_type, *file_name, *message;
- static int sound_available = 0;
-
+
result = 0;
-
- /* perform one-time check to see if sound is available. If not, don't try to preview */
- if (sound_available == 0) {
- sound_available = esd_audio_open();
- if (sound_available > 0) {
- esd_audio_close ();
- }
- }
- if (sound_available > 0) {
+ if (nautilus_sound_can_play_sound ()) {
/* preview files based on the mime_type. */
/* for now, we just handle mp3s, soon we'll do more general sounds, eventually, more general types */
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 5615a9de6..c822aa30f 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -45,6 +45,7 @@
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
+#include <libnautilus-extensions/nautilus-sound.h>
#include <libnautilus-extensions/nautilus-stock-dialogs.h>
#include <libnautilus-extensions/nautilus-string-list.h>
#include <libnautilus-extensions/nautilus-undo-manager.h>
@@ -312,6 +313,9 @@ nautilus_application_startup (NautilusApplication *application,
*/
nautilus_application_check_user_directories (application);
+ /* initialize the sound machinery */
+ nautilus_sound_initialize ();
+
CORBA_exception_init (&ev);
/* Start up the factory. */