# HG changeset patch # User Mark Doliner # Date 1129084052 0 # Node ID 58bc500cf22639b9c5e78a40f55b8620e60b56ad # Parent 925c1960af349c9d16eee845704150eed716ced9 [gaim-migrate @ 13919] sf patch #1324285, from Casey Harkins fix "sounds while away" in HEAD This patch adds a GaimAccount as a parameter to the sound playing functions, allowing the caller to specify the account the sound is related to. If the account is not NULL and the while_away preference is not set, then the account is checked to see if it is away, if so, the sound is not played. committer: Tailor Script diff -r 925c1960af34 -r 58bc500cf226 plugins/mailchk.c --- a/plugins/mailchk.c Tue Oct 11 16:20:29 2005 +0000 +++ b/plugins/mailchk.c Wed Oct 12 02:27:32 2005 +0000 @@ -75,7 +75,7 @@ } if (count & NEW_MAIL) - gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); + gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT, NULL); if (count & UNREAD_MAIL) gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); diff -r 925c1960af34 -r 58bc500cf226 plugins/perl/common/Sound.xs --- a/plugins/perl/common/Sound.xs Tue Oct 11 16:20:29 2005 +0000 +++ b/plugins/perl/common/Sound.xs Wed Oct 12 02:27:32 2005 +0000 @@ -12,12 +12,14 @@ void -gaim_sound_play_event(event) +gaim_sound_play_event(event, account) Gaim::SoundEventID event + Gaim::Account account void -gaim_sound_play_file(filename) +gaim_sound_play_file(filename, account) const char *filename + Gaim::Account account void gaim_sound_set_ui_ops(ops) diff -r 925c1960af34 -r 58bc500cf226 src/gtkpounce.c --- a/src/gtkpounce.c Tue Oct 11 16:20:29 2005 +0000 +++ b/src/gtkpounce.c Wed Oct 12 02:27:32 2005 +0000 @@ -139,9 +139,9 @@ filename = gtk_entry_get_text(GTK_ENTRY(entry)); if (filename != NULL && *filename != '\0') - gaim_sound_play_file((char *) filename); + gaim_sound_play_file(filename, NULL); else - gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); + gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT, NULL); } static void @@ -1102,9 +1102,9 @@ "play-sound", "filename"); if (sound != NULL) - gaim_sound_play_file(sound); + gaim_sound_play_file(sound, account); else - gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); + gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT, account); } } diff -r 925c1960af34 -r 58bc500cf226 src/gtkprefs.c --- a/src/gtkprefs.c Tue Oct 11 16:20:29 2005 +0000 +++ b/src/gtkprefs.c Wed Oct 12 02:27:32 2005 +0000 @@ -1497,21 +1497,18 @@ test_sound(GtkWidget *button, gpointer i_am_NULL) { char *pref; - gboolean temp_value1, temp_value2; + gboolean temp_value; pref = g_strdup_printf("/gaim/gtk/sound/enabled/%s", gaim_gtk_sound_get_event_option(sound_row_sel)); - temp_value1 = gaim_prefs_get_bool("/core/sound/while_away"); - temp_value2 = gaim_prefs_get_bool(pref); - - if (!temp_value1) gaim_prefs_set_bool("/core/sound/while_away", TRUE); - if (!temp_value2) gaim_prefs_set_bool(pref, TRUE); - - gaim_sound_play_event(sound_row_sel); - - if (!temp_value1) gaim_prefs_set_bool("/core/sound/while_away", FALSE); - if (!temp_value2) gaim_prefs_set_bool(pref, FALSE); + temp_value = gaim_prefs_get_bool(pref); + + if (!temp_value) gaim_prefs_set_bool(pref, TRUE); + + gaim_sound_play_event(sound_row_sel, NULL); + + if (!temp_value) gaim_prefs_set_bool(pref, FALSE); g_free(pref); } diff -r 925c1960af34 -r 58bc500cf226 src/gtksound.c --- a/src/gtksound.c Tue Oct 11 16:20:29 2005 +0000 +++ b/src/gtksound.c Wed Oct 12 02:27:32 2005 +0000 @@ -115,31 +115,33 @@ static void play_conv_event(GaimConversation *conv, GaimSoundEventID event) { - GaimGtkConversation *gtkconv; - GaimGtkWindow *win; - gboolean has_focus; + /* If we should not play the sound for some reason, then exit early */ + if (conv != NULL) + { + GaimGtkConversation *gtkconv; + GaimGtkWindow *win; + gboolean has_focus; - if (conv==NULL) - gaim_sound_play_event(event); - - gtkconv = GAIM_GTK_CONVERSATION(conv); - win = gtkconv->win; + gtkconv = GAIM_GTK_CONVERSATION(conv); + win = gtkconv->win; - g_object_get(G_OBJECT(win->window), "has-toplevel-focus", - &has_focus, NULL); + has_focus = gaim_conversation_has_focus(conv); - if (gtkconv->make_sound && - !((gaim_gtk_conv_window_get_active_conversation(win) == conv) && - !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus") && has_focus)) { + if (!gtkconv->make_sound || + (gaim_gtk_conv_window_get_active_conversation(win) == conv) || + (gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus") && has_focus)) + { + return; + } + } - gaim_sound_play_event(event); - } + gaim_sound_play_event(event, conv ? gaim_conversation_get_account(conv) : NULL); } static void buddy_state_cb(GaimBuddy *buddy, GaimSoundEventID event) { - gaim_sound_play_event(event); + gaim_sound_play_event(event, gaim_buddy_get_account(buddy)); } static void @@ -148,7 +150,7 @@ int flags, GaimSoundEventID event) { if (conv==NULL) - gaim_sound_play_event(GAIM_SOUND_FIRST_RECEIVE); + gaim_sound_play_event(GAIM_SOUND_FIRST_RECEIVE, account); else play_conv_event(conv, event); } @@ -556,7 +558,7 @@ filename = g_build_filename(DATADIR, "sounds", "gaim", sounds[event].def, NULL); } - gaim_sound_play_file(filename); + gaim_sound_play_file(filename, NULL); g_free(filename); } diff -r 925c1960af34 -r 58bc500cf226 src/sound.c --- a/src/sound.c Tue Oct 11 16:20:29 2005 +0000 +++ b/src/sound.c Wed Oct 12 02:27:32 2005 +0000 @@ -29,26 +29,32 @@ static GaimSoundUiOps *sound_ui_ops = NULL; void -gaim_sound_play_file(const char *filename) +gaim_sound_play_file(const char *filename, const GaimAccount *account) { - /* FIXME */ -#if 0 - if(awaymessage && !gaim_prefs_get_bool("/core/sound/while_away")) - return; -#endif + GaimStatus *status; + + if ((account != NULL) && (!gaim_prefs_get_bool("/core/sounds/while_away"))) + { + status = gaim_account_get_active_status(account); + if (gaim_status_is_online(status) && !gaim_status_is_available(status)) + return; + } if(sound_ui_ops && sound_ui_ops->play_file) sound_ui_ops->play_file(filename); } void -gaim_sound_play_event(GaimSoundEventID event) +gaim_sound_play_event(GaimSoundEventID event, const GaimAccount *account) { - /* FIXME */ -#if 0 - if(awaymessage && !gaim_prefs_get_bool("/core/sound/while_away")) - return; -#endif + GaimStatus *status; + + if ((account != NULL) && (!gaim_prefs_get_bool("/core/sounds/while_away"))) + { + status = gaim_account_get_active_status(account); + if (gaim_status_is_online(status) && !gaim_status_is_available(status)) + return; + } if(sound_ui_ops && sound_ui_ops->play_event) sound_ui_ops->play_event(event); diff -r 925c1960af34 -r 58bc500cf226 src/sound.h --- a/src/sound.h Tue Oct 11 16:20:29 2005 +0000 +++ b/src/sound.h Wed Oct 12 02:27:32 2005 +0000 @@ -25,6 +25,8 @@ #ifndef _GAIM_SOUND_H_ #define _GAIM_SOUND_H_ +#include "account.h" + /**************************************************************************/ /** Data Structures */ /**************************************************************************/ @@ -73,15 +75,23 @@ * Plays the specified sound file. * * @param filename The file to play. + * @param account The account that this sound is associated with, or + * NULL if the sound is not associated with any specific + * account. This is needed for the "sounds while away?" + * preference to work correctly. */ -void gaim_sound_play_file(const char *filename); +void gaim_sound_play_file(const char *filename, const GaimAccount *account); /** * Plays the sound associated with the specified event. * * @param event The event. + * @param account The account that this sound is associated with, or + * NULL if the sound is not associated with any specific + * account. This is needed for the "sounds while away?" + * preference to work correctly. */ -void gaim_sound_play_event(GaimSoundEventID event); +void gaim_sound_play_event(GaimSoundEventID event, const GaimAccount *account); /** * Sets the UI sound operations