changeset 10074:2e225cd35615

[gaim-migrate @ 11054] This is some sound related stuff. Add a "No Sounds" sound method for those who like their Gaim to be really really quiet, switched to using the prefs API for mute_sounds, added a Mute Sounds entry to the buddy list tools menu so those without a system tray icon can use this, and kill off old child sound processes (any older than 15 seconds) which should fix bug #1034209. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 02 Oct 2004 18:53:19 +0000
parents 06fa76a16ac0
children 4670b7fd1a89
files plugins/ChangeLog.API plugins/docklet/docklet.c src/gtkblist.c src/gtkprefs.c src/gtksound.c src/gtksound.h
diffstat 6 files changed, 107 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Sat Oct 02 15:28:03 2004 +0000
+++ b/plugins/ChangeLog.API	Sat Oct 02 18:53:19 2004 +0000
@@ -1,5 +1,10 @@
 Gaim: The Pimpin' Penguin IM Client that's good for the soul!
 
+version 2.0.0cvs:
+	* Changed: All the status stuff. Yay!
+	* Removed: gaim_gtk_sound_{get,set}_mute() (replaced by the
+	           /gaim/gtk/sound/mute preference)
+
 version 1.0.0 (09/17/2004):
 	* Added: get_chat_name to the GaimPluginProtocolInfo struct
 	* Changed: gaim_blist_update_buddy_presence(), presence changed to
--- a/plugins/docklet/docklet.c	Sat Oct 02 15:28:03 2004 +0000
+++ b/plugins/docklet/docklet.c	Sat Oct 02 18:53:19 2004 +0000
@@ -72,7 +72,7 @@
 static void
 docklet_toggle_mute(GtkWidget *toggle, void *data)
 {
-	gaim_gtk_sound_set_mute(GTK_CHECK_MENU_ITEM(toggle)->active);
+	gaim_prefs_set_bool("/gaim/gtk/sound/mute", GTK_CHECK_MENU_ITEM(toggle)->active);
 }
 
 static void
@@ -201,7 +201,9 @@
 	gaim_separator(menu);
 
 	entry = gtk_check_menu_item_new_with_label(_("Mute Sounds"));
-	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(entry), gaim_gtk_sound_get_mute());
+	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(entry), gaim_prefs_get_bool("/gaim/gtk/sound/mute"));
+	if (!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none"))
+		gtk_widget_set_sensitive(GTK_WIDGET(entry), FALSE);
 	g_signal_connect(G_OBJECT(entry), "toggled", G_CALLBACK(docklet_toggle_mute), NULL);
 	gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry);
 
@@ -515,9 +517,6 @@
 	if (ui_ops && ui_ops->destroy)
 		ui_ops->destroy();
 
-	/* XXX: do this while gaim has no other way to toggle the global mute */
-	gaim_gtk_sound_set_mute(FALSE);
-
 	docklet_remove_callbacks();
 
 	gaim_debug(GAIM_DEBUG_INFO, "tray icon", "plugin unloaded\n");
--- a/src/gtkblist.c	Sat Oct 02 15:28:03 2004 +0000
+++ b/src/gtkblist.c	Sat Oct 02 18:53:19 2004 +0000
@@ -48,6 +48,7 @@
 #include "gtkprefs.h"
 #include "gtkprivacy.h"
 #include "gtkroomlist.h"
+#include "gtksound.h"
 #include "gtkutils.h"
 
 #include "gaim.h"
@@ -1540,6 +1541,27 @@
 	}
 }
 
+static void gaim_gtk_blist_mute_sounds_cb(gpointer data, guint action, GtkWidget *item)
+{
+	gaim_prefs_set_bool("/gaim/gtk/sound/mute", GTK_CHECK_MENU_ITEM(item)->active);
+}
+
+static void gaim_gtk_blist_mute_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data)
+{
+	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(gtkblist->ift,
+						N_("/Tools/Mute Sounds"))),	(gboolean)GPOINTER_TO_INT(value));
+}
+
+static void gaim_gtk_blist_sound_method_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data)
+{
+	gboolean sensitive = TRUE;
+
+	if(!strcmp(value, "none"))
+		sensitive = FALSE;
+
+	gtk_widget_set_sensitive(gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Mute Sounds")), sensitive);
+}
+
 static void
 add_buddies_from_vcard(const char *prpl_id, GaimGroup *group, GList *list,
 					   const char *alias)
@@ -2423,6 +2445,7 @@
 	{ N_("/Tools/R_oom List"), NULL, gaim_gtk_roomlist_dialog_show, 0, NULL },
 	{ N_("/Tools/Pr_eferences"), "<CTL>P", gaim_gtk_prefs_show, 0, "<StockItem>", GTK_STOCK_PREFERENCES },
 	{ N_("/Tools/Pr_ivacy"), NULL, gaim_gtk_privacy_dialog_show, 0, NULL },
+	{ N_("/Tools/Mute _Sounds"), "<CTL>S", gaim_gtk_blist_mute_sounds_cb, 0, "<CheckItem>"},
 	{ "/Tools/sep2", NULL, NULL, 0, "<Separator>" },
 	{ N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL },
 
@@ -3299,6 +3322,10 @@
 			gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies"));
 	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Empty Groups"))),
 			gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups"));
+	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Tools/Mute Sounds"))),
+			gaim_prefs_get_bool("/gaim/gtk/sound/mute"));
+	if(!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none"))
+		gtk_widget_set_sensitive(gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Mute Sounds")), FALSE); 
 
 	/* OK... let's show this bad boy. */
 	gaim_gtk_blist_refresh(list);
@@ -3423,6 +3450,16 @@
 				gaim_prefs_connect_callback("/gaim/gtk/blist/show_warning_level",
 					gaim_gtk_blist_update_columns, NULL)));
 
+	/* menus */
+	blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks,
+			GINT_TO_POINTER(
+				gaim_prefs_connect_callback("/gaim/gtk/sound/mute",
+					gaim_gtk_blist_mute_pref_cb, NULL)));
+	blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks,
+			GINT_TO_POINTER(
+				gaim_prefs_connect_callback("/gaim/gtk/sound/method",
+					gaim_gtk_blist_sound_method_pref_cb, NULL)));
+
 	/* Setup some gaim signal handlers. */
 	gaim_signal_connect(gaim_connections_get_handle(), "signed-on",
 						gtkblist, GAIM_CALLBACK(sign_on_off_cb), list);
--- a/src/gtkprefs.c	Sat Oct 02 15:28:03 2004 +0000
+++ b/src/gtkprefs.c	Sat Oct 02 18:53:19 2004 +0000
@@ -80,7 +80,9 @@
 static guint browser_pref1_id = 0;
 static guint browser_pref2_id = 0;
 static guint proxy_pref_id = 0;
-static guint sound_pref_id = 0;
+static guint sound_pref1_id = 0;
+static guint sound_pref2_id = 0;
+static guint sound_pref3_id = 0;
 static guint auto_resp_pref_id = 0;
 static guint placement_pref_id = 0;
 
@@ -383,7 +385,9 @@
 	gaim_prefs_disconnect_callback(browser_pref1_id);
 	gaim_prefs_disconnect_callback(browser_pref2_id);
 	gaim_prefs_disconnect_callback(proxy_pref_id);
-	gaim_prefs_disconnect_callback(sound_pref_id);
+	gaim_prefs_disconnect_callback(sound_pref1_id);
+	gaim_prefs_disconnect_callback(sound_pref2_id);
+	gaim_prefs_disconnect_callback(sound_pref3_id);
 	gaim_prefs_disconnect_callback(auto_resp_pref_id);
 	gaim_prefs_disconnect_callback(placement_pref_id);
 
@@ -1487,7 +1491,7 @@
 }
 
 static void
-sound_changed_cb(const char *name, GaimPrefType type, gpointer value,
+sound_changed1_cb(const char *name, GaimPrefType type, gpointer value,
 				   gpointer data)
 {
 	GtkWidget *hbox = data;
@@ -1495,6 +1499,16 @@
 
 	gtk_widget_set_sensitive(hbox, !strcmp(method, "custom"));
 }
+
+static void
+sound_changed2_cb(const char *name, GaimPrefType type, gpointer value,
+				   gpointer data)
+{
+	GtkWidget *vbox = data;
+	const char *method = value;
+
+	gtk_widget_set_sensitive(vbox, strcmp(method, "none"));
+}
 #endif
 
 
@@ -1645,12 +1659,6 @@
 
 	sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
 
-	vbox = gaim_gtk_make_frame (ret, _("Sound Options"));
-	gaim_gtk_prefs_checkbox(_("Sounds when conversation has _focus"),
-				   "/gaim/gtk/sound/conv_focus", vbox);
-	gaim_gtk_prefs_checkbox(_("_Sounds while away"),
-				   "/core/sound/while_away", vbox);
-
 #ifndef _WIN32
 	vbox = gaim_gtk_make_frame (ret, _("Sound Method"));
 	dd = gaim_gtk_prefs_dropdown(vbox, _("_Method:"), GAIM_PREF_STRING,
@@ -1665,6 +1673,7 @@
 			"NAS", "nas",
 #endif
 			_("Command"), "custom",
+			_("No sounds"), "none",
 			NULL);
 	gtk_size_group_add_widget(sg, dd);
 	gtk_misc_set_alignment(GTK_MISC(dd), 0, 0);
@@ -1693,12 +1702,23 @@
 	gtk_widget_set_sensitive(hbox,
 			!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"),
 					"custom"));
-	sound_pref_id = gaim_prefs_connect_callback("/gaim/gtk/sound/method",
-												  sound_changed_cb, hbox);
+	sound_pref1_id = gaim_prefs_connect_callback("/gaim/gtk/sound/method",
+												  sound_changed1_cb, hbox);
 
 	gaim_set_accessible_label (entry, label);
 #endif /* _WIN32 */
 
+	vbox = gaim_gtk_make_frame (ret, _("Sound Options"));
+	gaim_gtk_prefs_checkbox(_("Sounds when conversation has _focus"),
+				   "/gaim/gtk/sound/conv_focus", vbox);
+	gaim_gtk_prefs_checkbox(_("_Sounds while away"),
+				   "/core/sound/while_away", vbox);
+
+	gtk_widget_set_sensitive(vbox,
+			strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none"));
+	sound_pref2_id = gaim_prefs_connect_callback("/gaim/gtk/sound/method",
+												  sound_changed2_cb, vbox);
+
 	vbox = gaim_gtk_make_frame(ret, _("Sound Events"));
 
 	/* The following is an ugly hack to make the frame expand so the
@@ -1789,6 +1809,11 @@
 	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
 	gtk_widget_show_all(ret);
 
+	gtk_widget_set_sensitive(vbox,
+			strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none"));
+	sound_pref3_id = gaim_prefs_connect_callback("/gaim/gtk/sound/method",
+												  sound_changed2_cb, vbox);
+
 	return ret;
 }
 
--- a/src/gtksound.c	Sat Oct 02 15:28:03 2004 +0000
+++ b/src/gtksound.c	Sat Oct 02 18:53:19 2004 +0000
@@ -53,10 +53,9 @@
 	char *def;
 };
 
-
+#define PLAY_SOUND_TIMEOUT 15000
 
 static gboolean mute_login_sounds = FALSE;
-static gboolean mute_sounds = FALSE;
 static gboolean sound_initialized = FALSE;
 
 static struct gaim_sound_event sounds[GAIM_NUM_SOUNDS] = {
@@ -109,6 +108,7 @@
 	gaim_prefs_add_bool("/gaim/gtk/sound/enabled/pounce_default", TRUE);
 	gaim_prefs_add_string("/gaim/gtk/sound/file/pounce_default", "");
 	gaim_prefs_add_bool("/gaim/gtk/sound/conv_focus", TRUE);
+	gaim_prefs_add_bool("/gaim/gtk/sound/mute", FALSE);
 	gaim_prefs_add_string("/gaim/gtk/sound/command", "");
 	gaim_prefs_add_string("/gaim/gtk/sound/method", "automatic");
 
@@ -131,6 +131,23 @@
 	sound_initialized = FALSE;
 }
 
+#if defined(USE_NAS_AUDIO) || defined(USE_AO)
+gboolean expire_old_child(gpointer data)
+{
+	int ret;
+	pid_t pid = GPOINTER_TO_INT(data);
+
+	ret = waitpid(pid, NULL, WNOHANG | WUNTRACED);
+
+	if(ret == 0) {
+		if(kill(pid, SIGKILL) < 0)
+			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)
 {
 	const char *method;
@@ -144,12 +161,14 @@
 	if (!sound_initialized)
 		gaim_prefs_trigger_callback("/gaim/gtk/sound/method");
 
-	if (mute_sounds)
+	if (gaim_prefs_get_bool("/gaim/gtk/sound/mute"))
 		return;
 
 	method = gaim_prefs_get_string("/gaim/gtk/sound/method");
 
-	if (!strcmp(method, "beep")) {
+	if (!strcmp(method, "none")) {
+		return;
+	} else if (!strcmp(method, "beep")) {
 		gdk_beep();
 		return;
 	}
@@ -256,6 +275,8 @@
 		ao_shutdown();
 #endif /* USE_AO */
 		_exit(0);
+	} else {
+		gaim_timeout_add(PLAY_SOUND_TIMEOUT, expire_old_child, GINT_TO_POINTER(pid));
 	}
 #else /* USE_NAS_AUDIO || USE_AO */
 	gdk_beep();
@@ -364,16 +385,6 @@
 
 #endif /* USE_NAS_AUDIO */
 
-void gaim_gtk_sound_set_mute(gboolean mute)
-{
-	mute_sounds = mute;
-}
-
-gboolean gaim_gtk_sound_get_mute()
-{
-	return mute_sounds;
-}
-
 void gaim_gtk_sound_set_login_mute(gboolean mute)
 {
 	mute_login_sounds = mute;
--- a/src/gtksound.h	Sat Oct 02 15:28:03 2004 +0000
+++ b/src/gtksound.h	Sat Oct 02 18:53:19 2004 +0000
@@ -37,20 +37,6 @@
 GaimSoundUiOps *gaim_gtk_sound_get_ui_ops(void);
 
 /**
- * Mutes or un-mutes sounds.
- *
- * @param mute The mute state.
- */
-void gaim_gtk_sound_set_mute(gboolean mute);
-
-/**
- * Gets mute state for sounds.
- *
- * @return The mute state.
- */
-gboolean gaim_gtk_sound_get_mute();
-
-/**
  * Mutes or un-mutes login sounds.
  *
  * @param mute The mute state.