changeset 10322:2a132b73a6e6

[gaim-migrate @ 11529] I shuffled around lots of sound code and made the buddy-signon/signoff sounds work again. And I did it by making sound.c connec to the buddy-signon signal. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 05 Dec 2004 23:19:16 +0000
parents 782c1b564906
children bb2514e075db
files src/core.c src/gtkmain.c src/gtksound.c src/gtksound.h src/sound.c src/sound.h src/status.c
diffstat 7 files changed, 186 insertions(+), 152 deletions(-) [+]
line wrap: on
line diff
--- a/src/core.c	Sun Dec 05 21:25:44 2004 +0000
+++ b/src/core.c	Sun Dec 05 23:19:16 2004 +0000
@@ -131,6 +131,7 @@
 	gaim_accounts_uninit();
 	gaim_statuses_uninit();
 	gaim_prefs_uninit();
+	gaim_sound_uninit();
 
 	gaim_debug(GAIM_DEBUG_INFO, "main", "Unloading all plugins\n");
 	gaim_plugins_destroy_all();
--- a/src/gtkmain.c	Sun Dec 05 21:25:44 2004 +0000
+++ b/src/gtkmain.c	Sun Dec 05 23:19:16 2004 +0000
@@ -769,7 +769,6 @@
 
 	gtk_main();
 
-	gaim_sound_shutdown();
 #ifdef _WIN32
 	wgaim_cleanup();
 #endif
--- a/src/gtksound.c	Sun Dec 05 21:25:44 2004 +0000
+++ b/src/gtksound.c	Sun Dec 05 23:19:16 2004 +0000
@@ -49,7 +49,6 @@
 
 #include "gtksound.h"
 
-
 struct gaim_sound_event {
 	char *label;
 	char *pref;
@@ -81,9 +80,6 @@
 static int ao_driver = -1;
 #endif /* USE_AO */
 
-static void _pref_sound_method_changed(const char *name, GaimPrefType type,
-		gpointer val, gpointer data);
-
 static gboolean
 mute_login_sounds_cb(gpointer data)
 {
@@ -106,7 +102,65 @@
 	mute_login_sounds_timeout = gaim_timeout_add(10000, mute_login_sounds_cb, NULL);
 }
 
-static void gaim_gtk_sound_init(void)
+static void
+_pref_sound_method_changed(const char *name, GaimPrefType type,
+		gpointer val, gpointer data) {
+	if(type != GAIM_PREF_STRING || strcmp(name, "/gaim/gtk/sound/method"))
+		return;
+
+	sound_initialized = TRUE;
+
+#ifdef USE_AO
+	ao_driver = -1;
+
+	if(!strcmp(val, "esd"))
+		ao_driver = ao_driver_id("esd");
+	else if(!strcmp(val, "arts"))
+		ao_driver = ao_driver_id("arts");
+	else if(!strcmp(val, "automatic"))
+		ao_driver = ao_default_driver_id();
+
+	if(ao_driver != -1) {
+		ao_info *info = ao_driver_info(ao_driver);
+		gaim_debug_info("sound",
+						"Sound output driver loaded: %s\n", info->name);
+	}
+#endif /* USE_AO */
+#ifdef USE_NAS
+	if (!strcmp(val, "nas"))
+		gaim_debug_info("sound",
+						"Sound output driver loaded: NAS output\n");
+#endif /* USE_NAS */
+}
+
+const char *
+gaim_gtk_sound_get_event_option(GaimSoundEventID event)
+{
+	if(event >= GAIM_NUM_SOUNDS)
+		return 0;
+
+	return sounds[event].pref;
+}
+
+char *
+gaim_gtk_sound_get_event_label(GaimSoundEventID event)
+{
+	if(event >= GAIM_NUM_SOUNDS)
+		return NULL;
+
+	return sounds[event].label;
+}
+
+void *
+gaim_gtk_sound_get_handle()
+{
+	static int handle;
+
+	return &handle;
+}
+
+static void
+gaim_gtk_sound_init(void)
 {
 	void *gtk_sound_handle = gaim_gtk_sound_get_handle();
 
@@ -145,8 +199,7 @@
 	gaim_prefs_add_string("/gaim/gtk/sound/method", "automatic");
 
 #ifdef USE_AO
-	gaim_debug(GAIM_DEBUG_INFO, "sound",
-			"Initializing sound output drivers.\n");
+	gaim_debug_info("sound", "Initializing sound output drivers.\n");
 	ao_initialize();
 #endif /* USE_AO */
 
@@ -154,8 +207,8 @@
 			_pref_sound_method_changed, NULL);
 }
 
-
-static void gaim_gtk_sound_shutdown(void)
+static void
+gaim_gtk_sound_uninit(void)
 {
 #ifdef USE_AO
 	ao_shutdown();
@@ -163,8 +216,26 @@
 	sound_initialized = FALSE;
 }
 
+#ifdef USE_NAS_AUDIO
+static gboolean
+play_file_nas(const char *filename)
+{
+	AuServer *nas_serv;
+	gboolean ret = FALSE;
+
+	if((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) {
+		ret = AuSoundPlaySynchronousFromFile(nas_serv, filename, 100);
+		AuCloseServer(nas_serv);
+	}
+
+	return ret;
+}
+
+#endif /* USE_NAS_AUDIO */
+
 #if defined(USE_NAS_AUDIO) || defined(USE_AO)
-gboolean expire_old_child(gpointer data)
+static gboolean
+expire_old_child(gpointer data)
 {
 	int ret;
 	pid_t pid = GPOINTER_TO_INT(data);
@@ -173,14 +244,16 @@
 
 	if(ret == 0) {
 		if(kill(pid, SIGKILL) < 0)
-			gaim_debug_error("gtksound", "Killing process %d failed (%s)\n", pid, strerror(errno));
+			gaim_debug_error("gtksound", "Killing process %d failed (%s)\n",
+							 pid, strerror(errno));
 	}
 
     return FALSE; /* do not run again */
 }
 #endif
 
-static void gaim_gtk_sound_play_file(const char *filename)
+static void
+gaim_gtk_sound_play_file(const char *filename)
 {
 	const char *method;
 #if defined(USE_NAS_AUDIO) || defined(USE_AO)
@@ -315,14 +388,15 @@
 	return;
 #endif /* USE_NAS_AUDIO || USE_AO */
 #else /* _WIN32 */
-	gaim_debug(GAIM_DEBUG_INFO, "sound", "Playing %s\n", filename);
+	gaim_debug_info("sound", "Playing %s\n", filename);
 
 	if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME))
-		gaim_debug(GAIM_DEBUG_ERROR, "sound", "Error playing sound.\n");
+		gaim_debug_error("sound", "Error playing sound.\n");
 #endif /* _WIN32 */
 }
 
-static void gaim_gtk_sound_play_event(GaimSoundEventID event)
+static void
+gaim_gtk_sound_play_event(GaimSoundEventID event)
 {
 	char *enable_pref;
 	char *file_pref;
@@ -331,8 +405,7 @@
 		return;
 
 	if (event >= GAIM_NUM_SOUNDS) {
-		gaim_debug(GAIM_DEBUG_MISC, "sound",
-				   "got request for unknown sound: %d\n", event);
+		gaim_debug_error("sound", "got request for unknown sound: %d\n", event);
 		return;
 	}
 
@@ -359,7 +432,7 @@
 static GaimSoundUiOps sound_ui_ops =
 {
 	gaim_gtk_sound_init,
-	gaim_gtk_sound_shutdown,
+	gaim_gtk_sound_uninit,
 	gaim_gtk_sound_play_file,
 	gaim_gtk_sound_play_event
 };
@@ -369,73 +442,3 @@
 {
 	return &sound_ui_ops;
 }
-
-
-static void _pref_sound_method_changed(const char *name, GaimPrefType type,
-		gpointer val, gpointer data) {
-	if(type != GAIM_PREF_STRING || strcmp(name, "/gaim/gtk/sound/method"))
-		return;
-
-	sound_initialized = TRUE;
-
-#ifdef USE_AO
-	ao_driver = -1;
-
-	if(!strcmp(val, "esd"))
-		ao_driver = ao_driver_id("esd");
-	else if(!strcmp(val, "arts"))
-		ao_driver = ao_driver_id("arts");
-	else if(!strcmp(val, "automatic"))
-		ao_driver = ao_default_driver_id();
-
-	if(ao_driver != -1) {
-		ao_info *info = ao_driver_info(ao_driver);
-		gaim_debug(GAIM_DEBUG_INFO, "sound",
-				   "Sound output driver loaded: %s\n", info->name);
-	}
-#endif /* USE_AO */
-#ifdef USE_NAS
-	if (!strcmp(val, "nas"))
-		gaim_debug(GAIM_DEBUG_INFO, "sound",
-				   "Sound output driver loaded: NAS output\n");
-#endif /* USE_NAS */
-}
-
-#ifdef USE_NAS_AUDIO
-static gboolean play_file_nas(const char *filename)
-{
-	AuServer *nas_serv;
-	gboolean ret = FALSE;
-
-	if((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) {
-		ret = AuSoundPlaySynchronousFromFile(nas_serv, filename, 100);
-		AuCloseServer(nas_serv);
-	}
-
-	return ret;
-}
-
-#endif /* USE_NAS_AUDIO */
-
-const char *gaim_gtk_sound_get_event_option(GaimSoundEventID event)
-{
-	if(event >= GAIM_NUM_SOUNDS)
-		return 0;
-
-	return sounds[event].pref;
-}
-
-char *gaim_gtk_sound_get_event_label(GaimSoundEventID event)
-{
-	if(event >= GAIM_NUM_SOUNDS)
-		return NULL;
-
-	return sounds[event].label;
-}
-
-void *gaim_gtk_sound_get_handle()
-{
-	static int handle;
-
-	return &handle;
-}
--- a/src/gtksound.h	Sun Dec 05 21:25:44 2004 +0000
+++ b/src/gtksound.h	Sun Dec 05 23:19:16 2004 +0000
@@ -1,5 +1,6 @@
 /**
  * @file gtksound.h GTK+ Sound API
+ * @ingroup gtkui
  *
  * gaim
  *
@@ -30,20 +31,6 @@
 /*@{*/
 
 /**
- * Get the handle for the GTK+ sound system.
- *
- * @return the handle to the sound system
- */
-void *gaim_gtk_sound_get_handle();
-
-/**
- * Gets GTK Sound UI opsA
- *
- * @return UI operations struct
- */
-GaimSoundUiOps *gaim_gtk_sound_get_ui_ops(void);
-
-/**
  * Get the prefs option for an event.
  *
  * @param event The event.
@@ -59,6 +46,20 @@
  */
 char *gaim_gtk_sound_get_event_label(GaimSoundEventID event);
 
+/**
+ * Gets GTK+ sound UI ops.
+ *
+ * @return The UI operations structure.
+ */
+GaimSoundUiOps *gaim_gtk_sound_get_ui_ops(void);
+
+/**
+ * Get the handle for the GTK+ sound system.
+ *
+ * @return The handle to the sound system
+ */
+void *gaim_gtk_sound_get_handle();
+
 /*@}*/
 
 #endif /* _GAIM_GTKSOUND_H_ */
--- a/src/sound.c	Sun Dec 05 21:25:44 2004 +0000
+++ b/src/sound.c	Sun Dec 05 23:19:16 2004 +0000
@@ -22,38 +22,14 @@
  */
 #include "internal.h"
 
+#include "blist.h"
+#include "prefs.h"
 #include "sound.h"
-#include "prefs.h"
 
 static GaimSoundUiOps *sound_ui_ops = NULL;
 
-void gaim_sound_set_ui_ops(GaimSoundUiOps *ops)
-{
-	if(sound_ui_ops && sound_ui_ops->shutdown)
-		sound_ui_ops->shutdown();
-	sound_ui_ops = ops;
-	if(sound_ui_ops && sound_ui_ops->init)
-		sound_ui_ops->init();
-}
-
-GaimSoundUiOps *gaim_sound_get_ui_ops(void)
-{
-	return sound_ui_ops;
-}
-
-void gaim_sound_init()
-{
-	gaim_prefs_add_none("/core/sound");
-	gaim_prefs_add_bool("/core/sound/while_away", FALSE);
-}
-
-void gaim_sound_shutdown()
-{
-	if(sound_ui_ops && sound_ui_ops->shutdown)
-		sound_ui_ops->shutdown();
-}
-
-void gaim_sound_play_file(const char *filename)
+void
+gaim_sound_play_file(const char *filename)
 {
 	/* FIXME */
 #if 0
@@ -65,7 +41,8 @@
 		sound_ui_ops->play_file(filename);
 }
 
-void gaim_sound_play_event(GaimSoundEventID event)
+void
+gaim_sound_play_event(GaimSoundEventID event)
 {
 	/* FIXME */
 #if 0
@@ -76,3 +53,60 @@
 	if(sound_ui_ops && sound_ui_ops->play_event)
 		sound_ui_ops->play_event(event);
 }
+
+static void
+sound_triggered_cb(GaimBuddy *buddy, GaimSoundEventID event)
+{
+	gaim_sound_play_event(event);
+}
+
+void
+gaim_sound_set_ui_ops(GaimSoundUiOps *ops)
+{
+	if(sound_ui_ops && sound_ui_ops->uninit)
+		sound_ui_ops->uninit();
+
+	sound_ui_ops = ops;
+
+	if(sound_ui_ops && sound_ui_ops->init)
+		sound_ui_ops->init();
+}
+
+GaimSoundUiOps *
+gaim_sound_get_ui_ops(void)
+{
+	return sound_ui_ops;
+}
+
+void *
+gaim_sound_get_handle() {
+	static int handle;
+
+	return &handle;
+}
+
+void
+gaim_sound_init()
+{
+	void *handle       = gaim_sound_get_handle();
+	void *blist_handle = gaim_blist_get_handle();
+
+	gaim_prefs_add_none("/core/sound");
+	gaim_prefs_add_bool("/core/sound/while_away", FALSE);
+
+	gaim_signal_connect(blist_handle, "buddy-signed-on",
+						handle, GAIM_CALLBACK(sound_triggered_cb),
+						GINT_TO_POINTER(GAIM_SOUND_BUDDY_ARRIVE));
+	gaim_signal_connect(blist_handle, "buddy-signed-off",
+						handle, GAIM_CALLBACK(sound_triggered_cb),
+						GINT_TO_POINTER(GAIM_SOUND_BUDDY_LEAVE));
+}
+
+void
+gaim_sound_uninit()
+{
+	gaim_signals_disconnect_by_handle(gaim_sound_get_handle());
+
+	if(sound_ui_ops && sound_ui_ops->uninit)
+		sound_ui_ops->uninit();
+}
--- a/src/sound.h	Sun Dec 05 21:25:44 2004 +0000
+++ b/src/sound.h	Sun Dec 05 23:19:16 2004 +0000
@@ -54,7 +54,7 @@
 typedef struct _GaimSoundUiOps
 {
 	void (*init)(void);
-	void (*shutdown)(void);
+	void (*uninit)(void);
 	void (*play_file)(const char *filename);
 	void (*play_event)(GaimSoundEventID event);
 
@@ -70,6 +70,20 @@
 /*@{*/
 
 /**
+ * Plays the specified sound file.
+ *
+ * @param filename The file to play.
+ */
+void gaim_sound_play_file(const char *filename);
+
+/**
+ * Plays the sound associated with the specified event.
+ *
+ * @param event The event.
+ */
+void gaim_sound_play_event(GaimSoundEventID event);
+
+/**
  * Sets the UI sound operations
  *
  * @param ops The UI sound operations structure.
@@ -91,21 +105,7 @@
 /**
  * Shuts down the sound subsystem
  */
-void gaim_sound_shutdown(void);
-
-/**
- * Plays the specified sound file.
- *
- * @param filename The file to play.
- */
-void gaim_sound_play_file(const char *filename);
-
-/**
- * Plays the sound associated with the specified event.
- *
- * @param event The event.
- */
-void gaim_sound_play_event(GaimSoundEventID event);
+void gaim_sound_uninit(void);
 
 /*@}*/
 
--- a/src/status.c	Sun Dec 05 21:25:44 2004 +0000
+++ b/src/status.c	Sun Dec 05 23:19:16 2004 +0000
@@ -1179,8 +1179,6 @@
  *           gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp);
  *           g_free(tmp);
  *
- *           gaim_sound_play_event(GAIM_SOUND_BUDDY_ARRIVE); 
- *
  *           char *tmp = g_strdup_printf(_("%s logged out."), alias);
  *           gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL));
  *           g_free(tmp); 
@@ -1191,8 +1189,6 @@
  *
  *           serv_got_typing_stopped(gc, name);
  *
- *           gaim_sound_play_event(GAIM_SOUND_BUDDY_LEAVE); 
- *
  *           gaim_conversation_update(c, GAIM_CONV_UPDATE_AWAY);
  *
  */