comparison libgaim/sound.c @ 14874:71149a751439

[gaim-migrate @ 17643] SF Patch #1469315 from R.Ramkumar - andyetitmoves "This is a small patch to make sounds enabled when available an optional feature. The use case is: Sounds being annoying, I would like them only when I am not seeing the comp. When I am on the comp, I have guifications/gaim-osd to inform me of whatever happens, and that happens to be less intrusive (especially when music is on :) )." The patch originally used: "Play sounds:" ("Always", "When available", "When away") I changed them to the strings KingAnt suggested: "Play sounds:" ("Always", "Only when available", "Only when not available") The ones from the patch submitter are not quite as clear, but they're shorter. What does everyone think about this? committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Wed, 01 Nov 2006 01:27:16 +0000
parents 2f0b4d0de5bb
children
comparison
equal deleted inserted replaced
14873:3a23706f9f4b 14874:71149a751439
26 #include "prefs.h" 26 #include "prefs.h"
27 #include "sound.h" 27 #include "sound.h"
28 28
29 static GaimSoundUiOps *sound_ui_ops = NULL; 29 static GaimSoundUiOps *sound_ui_ops = NULL;
30 30
31 #define STATUS_AVAILABLE 1
32 #define STATUS_AWAY 2
33
34 static gboolean
35 gaim_sound_play_required(const GaimAccount *account)
36 {
37 gint pref_status = gaim_prefs_get_int("/core/sound/while_status");
38
39 if (pref_status == 3)
40 {
41 /* Play sounds: Always */
42 return TRUE;
43 }
44
45 if (account != NULL)
46 {
47 GaimStatus *status = gaim_account_get_active_status(account);
48
49 if (gaim_status_is_online(status))
50 {
51 gboolean available = gaim_status_is_available(status);
52 return (( available && pref_status == STATUS_AVAILABLE) ||
53 (!available && pref_status == STATUS_AWAY));
54 }
55 }
56
57 /* We get here a couple of ways. Either the request has been OK'ed
58 * by gaim_sound_play_event() and we're here because the UI has
59 * called gaim_sound_play_file(), or we're here for something
60 * not related to an account (like testing a sound). */
61 return TRUE;
62 }
63
31 void 64 void
32 gaim_sound_play_file(const char *filename, const GaimAccount *account) 65 gaim_sound_play_file(const char *filename, const GaimAccount *account)
33 { 66 {
34 GaimStatus *status; 67 if (!gaim_sound_play_required(account))
35 68 return;
36 if ((account != NULL) && (!gaim_prefs_get_bool("/core/sound/while_away")))
37 {
38 status = gaim_account_get_active_status(account);
39 if (gaim_status_is_online(status) && !gaim_status_is_available(status))
40 return;
41 }
42 69
43 if(sound_ui_ops && sound_ui_ops->play_file) 70 if(sound_ui_ops && sound_ui_ops->play_file)
44 sound_ui_ops->play_file(filename); 71 sound_ui_ops->play_file(filename);
45 } 72 }
46 73
47 void 74 void
48 gaim_sound_play_event(GaimSoundEventID event, const GaimAccount *account) 75 gaim_sound_play_event(GaimSoundEventID event, const GaimAccount *account)
49 { 76 {
50 GaimStatus *status; 77 if (!gaim_sound_play_required(account))
51 78 return;
52 if ((account != NULL) &&
53 (!gaim_prefs_get_bool("/core/sound/while_away")))
54 {
55 status = gaim_account_get_active_status(account);
56 if (gaim_status_is_online(status) &&
57 !gaim_status_is_available(status))
58 return;
59 }
60 79
61 if(sound_ui_ops && sound_ui_ops->play_event) { 80 if(sound_ui_ops && sound_ui_ops->play_event) {
62 int plugin_return; 81 int plugin_return;
63 82
64 plugin_return = GPOINTER_TO_INT(gaim_signal_emit_return_1( 83 plugin_return = GPOINTER_TO_INT(gaim_signal_emit_return_1(
105 gaim_value_new(GAIM_TYPE_INT), 124 gaim_value_new(GAIM_TYPE_INT),
106 gaim_value_new(GAIM_TYPE_SUBTYPE, 125 gaim_value_new(GAIM_TYPE_SUBTYPE,
107 GAIM_SUBTYPE_ACCOUNT)); 126 GAIM_SUBTYPE_ACCOUNT));
108 127
109 gaim_prefs_add_none("/core/sound"); 128 gaim_prefs_add_none("/core/sound");
110 gaim_prefs_add_bool("/core/sound/while_away", FALSE); 129 gaim_prefs_add_int("/core/sound/while_status", STATUS_AVAILABLE);
111
112 } 130 }
113 131
114 void 132 void
115 gaim_sound_uninit() 133 gaim_sound_uninit()
116 { 134 {