Sophie

Sophie

distrib > Mandriva > 2008.0 > x86_64 > by-pkgid > 55838e6f250a50b6f5e2bddfbbe510d2 > files > 8

gnome-session-2.20.0-2mdv2008.0.src.rpm

--- gnome-session-2.20.0/gnome-session/gsm-sound.c.esd	2007-09-17 20:36:00.000000000 +0200
+++ gnome-session-2.20.0/gnome-session/gsm-sound.c	2007-09-21 11:43:24.000000000 +0200
@@ -11,6 +11,9 @@
 
 #include <libgnome/gnome-sound.h>
 #include <libgnome/gnome-triggers.h>
+#include <libgnome/gnome-util.h>
+#include <libgnome/gnome-config.h>
+#include <libgnome/gnome-exec.h>
 
 #define ENABLE_SOUND_KEY        "/desktop/gnome/sound/enable_esd"
 #define ENABLE_EVENT_SOUNDS_KEY "/desktop/gnome/sound/event_sounds"
@@ -56,33 +59,20 @@ sound_events_enabled (void)
 }
 
 #ifdef HAVE_ESD
-static GPid esd_pid = 0;
-
-static void
-reset_esd_pid (GPid     pid,
-	       gint     status,
-	       gpointer ignore)
-{
-  if (pid == esd_pid)
-    esd_pid = 0;
-}
-
 static void
 start_esd (void) 
 {
-  gchar  *argv[] = {ESD_SERVER, "-nobeeps", NULL};
+  const char args[] = ESD_SERVER " -terminate -nobeeps";
   GError *err = NULL;
   time_t  starttime;
 
-  if (!gsm_exec_async (NULL, argv, NULL, &esd_pid, &err))
+  if (gnome_execute_shell (NULL, args) == -1)
     {
       g_warning ("Could not start esd: %s\n", err->message);
       g_error_free (err);
       return;
     }
 
-  g_child_watch_add (esd_pid, reset_esd_pid, NULL);
-
   starttime = time (NULL);
   gnome_sound_init (NULL);
 
@@ -94,19 +84,80 @@ start_esd (void) 
     }
 }
 
-static void
-stop_esd (void)
+
+static gboolean
+load_login_sample_from (const char *file,
+		gboolean   *isset)
 {
-  gnome_sound_shutdown ();
+	char *key;
+	char *sample_file;
+	int sample_id;
 
-  if (esd_pid)
-    {
-      if (kill (esd_pid, SIGTERM) == -1)
-        g_printerr ("Failed to kill esd (pid %d)\n", esd_pid);
-      else
-        esd_pid = 0;
-    }
+	if (!file)
+		return FALSE;
+
+	key = g_strconcat ("=", file, "=login/file", NULL);
+	sample_file = gnome_config_get_string (key);
+	g_free (key);
+
+	if (sample_file && isset)
+		*isset = TRUE;
+	else if (isset)
+		*isset = FALSE;
+
+	if (sample_file && *sample_file && *sample_file != '/')
+	{
+		char *tmp_sample_file;
+		tmp_sample_file = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_SOUND, sample_file, TRUE, NULL);
+		g_free (sample_file);
+		sample_file = tmp_sample_file;
+	}
+
+	if (!(sample_file && *sample_file))
+	{
+		g_free (sample_file);
+		return FALSE;
+	}
+
+	sample_id = esd_sample_getid (gnome_sound_connection_get (), "gnome-2/login");
+	if (sample_id >= 0)
+		esd_sample_free (gnome_sound_connection_get (), sample_id);
+
+	sample_id = gnome_sound_sample_load ("gnome-2/login", sample_file);
+
+	if (sample_id < 0)
+	{
+		g_warning ("Couldn't load sound file %s\n", sample_file);
+		return FALSE;
+	}
+
+	g_free (sample_file);
+
+	return TRUE;
 }
+
+#define SOUND_EVENT_FILE "sound/events/gnome-2.soundlist"
+	static gboolean
+load_login_sample (void)
+{
+	char *s;
+	gboolean loaded;
+	gboolean isset;
+
+	s = gnome_util_home_file (SOUND_EVENT_FILE);
+	loaded = load_login_sample_from (s, &isset);
+	g_free (s);
+
+	if (isset)
+		return loaded;
+
+	s = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_CONFIG, SOUND_EVENT_FILE, TRUE, NULL);
+	loaded = load_login_sample_from (s, NULL);
+	g_free (s);
+
+	return loaded;
+}
+
 #endif /* HAVE_ESD */
 
 static gboolean
@@ -127,14 +178,14 @@ sound_init (void)
       return FALSE;
     }
 
-  return TRUE;
+  return load_login_sample();
 }
 
 static void 
 sound_shutdown (void)
 {
 #ifdef HAVE_ESD
-  stop_esd ();
+  gnome_sound_shutdown ();
 #endif
 }