Mercurial > pidgin
comparison src/gtksound.c @ 11552:11d30825c1bb
[gaim-migrate @ 13812]
Source Forge patch 1273590 from Casey Harkins to move all sound playing events into gtksound.[ch] as well as a few other clean ups to make sure that all sounds are being played by the ui.
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Sat, 17 Sep 2005 03:00:12 +0000 |
parents | 448ebda0f7ec |
children | 9b3833da6840 |
comparison
equal
deleted
inserted
replaced
11551:78aad676fdb2 | 11552:11d30825c1bb |
---|---|
40 #include "notify.h" | 40 #include "notify.h" |
41 #include "prefs.h" | 41 #include "prefs.h" |
42 #include "sound.h" | 42 #include "sound.h" |
43 #include "util.h" | 43 #include "util.h" |
44 | 44 |
45 #include "gtkconv.h" | |
45 #include "gtksound.h" | 46 #include "gtksound.h" |
46 | 47 |
47 struct gaim_sound_event { | 48 struct gaim_sound_event { |
48 char *label; | 49 char *label; |
49 char *pref; | 50 char *pref; |
81 mute_login_sounds = FALSE; | 82 mute_login_sounds = FALSE; |
82 mute_login_sounds_timeout = 0; | 83 mute_login_sounds_timeout = 0; |
83 return FALSE; | 84 return FALSE; |
84 } | 85 } |
85 | 86 |
87 static gboolean | |
88 chat_nick_matches_name(GaimConversation *conv, const char *aname) | |
89 { | |
90 GaimConvChat *chat = NULL; | |
91 char *nick = NULL; | |
92 char *name = NULL; | |
93 gboolean ret = FALSE; | |
94 chat = gaim_conversation_get_chat_data(conv); | |
95 | |
96 if (chat==NULL) | |
97 return ret; | |
98 | |
99 nick = g_strdup(gaim_normalize(conv->account, chat->nick)); | |
100 name = g_strdup(gaim_normalize(conv->account, aname)); | |
101 | |
102 if (g_utf8_collate(nick, name) == 0) | |
103 ret = TRUE; | |
104 | |
105 g_free(nick); | |
106 g_free(name); | |
107 | |
108 return ret; | |
109 } | |
110 | |
111 /* | |
112 * play a sound event for a conversation, honoring make_sound flag | |
113 * of conversation and checking for focus if conv_focus pref is set | |
114 */ | |
115 static void | |
116 play_conv_event(GaimConversation *conv, GaimSoundEventID event) | |
117 { | |
118 GaimGtkConversation *gtkconv; | |
119 GaimConvWindow *gaimwin; | |
120 GaimGtkWindow *gtkwin; | |
121 gboolean has_focus; | |
122 | |
123 if (conv==NULL) | |
124 gaim_sound_play_event(event); | |
125 | |
126 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
127 gaimwin = gaim_conversation_get_window(conv); | |
128 gtkwin = GAIM_GTK_WINDOW(gaimwin); | |
129 | |
130 g_object_get(G_OBJECT(gtkwin->window), "has-toplevel-focus", | |
131 &has_focus, NULL); | |
132 | |
133 if (gtkconv->make_sound && | |
134 !((gaim_conv_window_get_active_conversation(gaimwin) == conv) && | |
135 !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus") && has_focus)) { | |
136 | |
137 gaim_sound_play_event(event); | |
138 } | |
139 } | |
140 | |
141 static void | |
142 buddy_state_cb(GaimBuddy *buddy, GaimSoundEventID event) | |
143 { | |
144 gaim_sound_play_event(event); | |
145 } | |
146 | |
147 static void | |
148 im_msg_received_cb(GaimAccount *account, char *sender, | |
149 char *message, GaimConversation *conv, | |
150 int flags, GaimSoundEventID event) | |
151 { | |
152 if (conv==NULL) | |
153 gaim_sound_play_event(GAIM_SOUND_FIRST_RECEIVE); | |
154 else | |
155 play_conv_event(conv, event); | |
156 } | |
157 | |
158 static void | |
159 im_msg_sent_cb(GaimAccount *account, const char *receiver, | |
160 const char *message, GaimSoundEventID event) | |
161 { | |
162 GaimConversation *conv = gaim_find_conversation_with_account( | |
163 GAIM_CONV_TYPE_ANY, receiver, account); | |
164 play_conv_event(conv, event); | |
165 } | |
166 | |
167 static void | |
168 chat_buddy_join_cb(GaimConversation *conv, const char *name, | |
169 GaimConvChatBuddyFlags flags, GaimSoundEventID event) | |
170 { | |
171 if (!chat_nick_matches_name(conv, name)) | |
172 play_conv_event(conv, event); | |
173 } | |
174 | |
175 static void | |
176 chat_buddy_left_cb(GaimConversation *conv, const char *name, | |
177 const char *reason, GaimSoundEventID event) | |
178 { | |
179 if (!chat_nick_matches_name(conv, name)) | |
180 play_conv_event(conv, event); | |
181 } | |
182 | |
183 static void | |
184 chat_msg_sent_cb(GaimAccount *account, const char *message, | |
185 int id, GaimSoundEventID event) | |
186 { | |
187 GaimConnection *conn = gaim_account_get_connection(account); | |
188 GaimConversation *conv = NULL; | |
189 | |
190 if (conn!=NULL) | |
191 conv = gaim_find_chat(conn,id); | |
192 | |
193 play_conv_event(conv, event); | |
194 } | |
195 | |
196 static void | |
197 chat_msg_received_cb(GaimAccount *account, char *sender, | |
198 char *message, GaimConversation *conv, | |
199 int flags, GaimSoundEventID event) | |
200 { | |
201 GaimConvChat *chat; | |
202 | |
203 chat = gaim_conversation_get_chat_data(conv); | |
204 | |
205 if (chat!=NULL && gaim_conv_chat_is_user_ignored(chat, sender)) | |
206 return; | |
207 | |
208 if (chat_nick_matches_name(conv, sender)) | |
209 return; | |
210 | |
211 if (flags & GAIM_CONV_CHAT_ALERT || gaim_utf8_has_word(message, chat->nick)) | |
212 play_conv_event(conv, GAIM_SOUND_CHAT_NICK); | |
213 else | |
214 play_conv_event(conv, event); | |
215 } | |
216 | |
86 /* | 217 /* |
87 * We mute sounds for the 10 seconds after you log in so that | 218 * We mute sounds for the 10 seconds after you log in so that |
88 * you don't get flooded with sounds when the blist shows all | 219 * you don't get flooded with sounds when the blist shows all |
89 * your buddies logging in. | 220 * your buddies logging in. |
90 */ | 221 */ |
153 | 284 |
154 static void | 285 static void |
155 gaim_gtk_sound_init(void) | 286 gaim_gtk_sound_init(void) |
156 { | 287 { |
157 void *gtk_sound_handle = gaim_gtk_sound_get_handle(); | 288 void *gtk_sound_handle = gaim_gtk_sound_get_handle(); |
289 void *blist_handle = gaim_blist_get_handle(); | |
290 void *conv_handle = gaim_conversations_get_handle(); | |
158 | 291 |
159 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | 292 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", |
160 gtk_sound_handle, GAIM_CALLBACK(account_signon_cb), | 293 gtk_sound_handle, GAIM_CALLBACK(account_signon_cb), |
161 NULL); | 294 NULL); |
162 | 295 |
195 ao_initialize(); | 328 ao_initialize(); |
196 #endif /* USE_AO */ | 329 #endif /* USE_AO */ |
197 | 330 |
198 gaim_prefs_connect_callback(gaim_gtk_sound_get_handle(), "/gaim/gtk/sound/method", | 331 gaim_prefs_connect_callback(gaim_gtk_sound_get_handle(), "/gaim/gtk/sound/method", |
199 _pref_sound_method_changed, NULL); | 332 _pref_sound_method_changed, NULL); |
333 | |
334 gaim_signal_connect(blist_handle, "buddy-signed-on", | |
335 gtk_sound_handle, GAIM_CALLBACK(buddy_state_cb), | |
336 GINT_TO_POINTER(GAIM_SOUND_BUDDY_ARRIVE)); | |
337 gaim_signal_connect(blist_handle, "buddy-signed-off", | |
338 gtk_sound_handle, GAIM_CALLBACK(buddy_state_cb), | |
339 GINT_TO_POINTER(GAIM_SOUND_BUDDY_LEAVE)); | |
340 gaim_signal_connect(conv_handle, "received-im-msg", | |
341 gtk_sound_handle, GAIM_CALLBACK(im_msg_received_cb), | |
342 GINT_TO_POINTER(GAIM_SOUND_RECEIVE)); | |
343 gaim_signal_connect(conv_handle, "sent-im-msg", | |
344 gtk_sound_handle, GAIM_CALLBACK(im_msg_sent_cb), | |
345 GINT_TO_POINTER(GAIM_SOUND_SEND)); | |
346 gaim_signal_connect(conv_handle, "chat-buddy-joined", | |
347 gtk_sound_handle, GAIM_CALLBACK(chat_buddy_join_cb), | |
348 GINT_TO_POINTER(GAIM_SOUND_CHAT_JOIN)); | |
349 gaim_signal_connect(conv_handle, "chat-buddy-left", | |
350 gtk_sound_handle, GAIM_CALLBACK(chat_buddy_left_cb), | |
351 GINT_TO_POINTER(GAIM_SOUND_CHAT_LEAVE)); | |
352 gaim_signal_connect(conv_handle, "sent-chat-msg", | |
353 gtk_sound_handle, GAIM_CALLBACK(chat_msg_sent_cb), | |
354 GINT_TO_POINTER(GAIM_SOUND_CHAT_YOU_SAY)); | |
355 gaim_signal_connect(conv_handle, "received-chat-msg", | |
356 gtk_sound_handle, GAIM_CALLBACK(chat_msg_received_cb), | |
357 GINT_TO_POINTER(GAIM_SOUND_CHAT_SAY)); | |
200 } | 358 } |
201 | 359 |
202 static void | 360 static void |
203 gaim_gtk_sound_uninit(void) | 361 gaim_gtk_sound_uninit(void) |
204 { | 362 { |
205 #ifdef USE_AO | 363 #ifdef USE_AO |
206 ao_shutdown(); | 364 ao_shutdown(); |
207 #endif | 365 #endif |
208 sound_initialized = FALSE; | 366 sound_initialized = FALSE; |
367 | |
368 gaim_signals_disconnect_by_handle(gaim_gtk_sound_get_handle()); | |
209 } | 369 } |
210 | 370 |
211 #ifdef USE_AO | 371 #ifdef USE_AO |
212 static gboolean | 372 static gboolean |
213 expire_old_child(gpointer data) | 373 expire_old_child(gpointer data) |