Mercurial > pidgin
annotate src/gtksound.c @ 12884:3e9802ef84f9
[gaim-migrate @ 15236]
minor tweak
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 15 Jan 2006 16:31:44 +0000 |
parents | 49b2347863b2 |
children | 33935a6320b8 |
rev | line source |
---|---|
5684 | 1 /* |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10158
diff
changeset
|
2 * @file gtksound.h GTK+ Sound |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10158
diff
changeset
|
3 * @ingroup gtkui |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10158
diff
changeset
|
4 * |
5684 | 5 * gaim |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
5684 | 10 * |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 * | |
25 */ | |
9791 | 26 #include "internal.h" |
27 #include "gtkgaim.h" | |
5684 | 28 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
29 #ifdef _WIN32 |
5684 | 30 #include <windows.h> |
31 #include <mmsystem.h> | |
32 #endif | |
33 | |
34 #ifdef USE_AO | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
35 # include <ao/ao.h> |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
36 # include <audiofile.h> |
5684 | 37 #endif /* USE_AO */ |
38 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
39 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
40 #include "notify.h" |
5684 | 41 #include "prefs.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
42 #include "sound.h" |
7465 | 43 #include "util.h" |
5684 | 44 |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
45 #include "gtkconv.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
46 #include "gtksound.h" |
5684 | 47 |
48 struct gaim_sound_event { | |
49 char *label; | |
50 char *pref; | |
51 char *def; | |
52 }; | |
53 | |
10074 | 54 #define PLAY_SOUND_TIMEOUT 15000 |
5684 | 55 |
10320 | 56 static guint mute_login_sounds_timeout = 0; |
5684 | 57 static gboolean mute_login_sounds = FALSE; |
6199 | 58 static gboolean sound_initialized = FALSE; |
5684 | 59 |
60 static struct gaim_sound_event sounds[GAIM_NUM_SOUNDS] = { | |
10158 | 61 {N_("Buddy logs in"), "login", "login.wav"}, |
62 {N_("Buddy logs out"), "logout", "logout.wav"}, | |
5684 | 63 {N_("Message received"), "im_recv", "receive.wav"}, |
64 {N_("Message received begins conversation"), "first_im_recv", "receive.wav"}, | |
65 {N_("Message sent"), "send_im", "send.wav"}, | |
10158 | 66 {N_("Person enters chat"), "join_chat", "login.wav"}, |
67 {N_("Person leaves chat"), "left_chat", "logout.wav"}, | |
5684 | 68 {N_("You talk in chat"), "send_chat_msg", "send.wav"}, |
69 {N_("Others talk in chat"), "chat_msg_recv", "receive.wav"}, | |
70 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */ | |
10158 | 71 {NULL, "pounce_default", "alert.wav"}, |
72 {N_("Someone says your name in chat"), "nick_said", "alert.wav"} | |
5684 | 73 }; |
74 | |
75 #ifdef USE_AO | |
76 static int ao_driver = -1; | |
77 #endif /* USE_AO */ | |
78 | |
10320 | 79 static gboolean |
11463 | 80 unmute_login_sounds_cb(gpointer data) |
10320 | 81 { |
82 mute_login_sounds = FALSE; | |
83 mute_login_sounds_timeout = 0; | |
84 return FALSE; | |
85 } | |
86 | |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
87 static gboolean |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
88 chat_nick_matches_name(GaimConversation *conv, const char *aname) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
89 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
90 GaimConvChat *chat = NULL; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
91 char *nick = NULL; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
92 char *name = NULL; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
93 gboolean ret = FALSE; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
94 chat = gaim_conversation_get_chat_data(conv); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
95 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
96 if (chat==NULL) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
97 return ret; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
98 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
99 nick = g_strdup(gaim_normalize(conv->account, chat->nick)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
100 name = g_strdup(gaim_normalize(conv->account, aname)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
101 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
102 if (g_utf8_collate(nick, name) == 0) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
103 ret = TRUE; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
104 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
105 g_free(nick); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
106 g_free(name); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
107 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
108 return ret; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
109 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
110 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
111 /* |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
112 * play a sound event for a conversation, honoring make_sound flag |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
113 * of conversation and checking for focus if conv_focus pref is set |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
114 */ |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
115 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
116 play_conv_event(GaimConversation *conv, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
117 { |
11642 | 118 /* If we should not play the sound for some reason, then exit early */ |
119 if (conv != NULL) | |
120 { | |
121 GaimGtkConversation *gtkconv; | |
122 GaimGtkWindow *win; | |
123 gboolean has_focus; | |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
124 |
11642 | 125 gtkconv = GAIM_GTK_CONVERSATION(conv); |
126 win = gtkconv->win; | |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
127 |
11642 | 128 has_focus = gaim_conversation_has_focus(conv); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
129 |
11642 | 130 if (!gtkconv->make_sound || |
11687
941aa045f9f6
[gaim-migrate @ 13973]
Richard Laager <rlaager@wiktel.com>
parents:
11642
diff
changeset
|
131 (has_focus && !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus"))) |
11642 | 132 { |
133 return; | |
134 } | |
135 } | |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
136 |
11642 | 137 gaim_sound_play_event(event, conv ? gaim_conversation_get_account(conv) : NULL); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
138 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
139 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
140 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
141 buddy_state_cb(GaimBuddy *buddy, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
142 { |
11642 | 143 gaim_sound_play_event(event, gaim_buddy_get_account(buddy)); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
144 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
145 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
146 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
147 im_msg_received_cb(GaimAccount *account, char *sender, |
11581 | 148 char *message, GaimConversation *conv, |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
149 int flags, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
150 { |
12850
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
151 if (flags & GAIM_MESSAGE_DELAYED) |
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
152 return; |
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
153 |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
154 if (conv==NULL) |
11642 | 155 gaim_sound_play_event(GAIM_SOUND_FIRST_RECEIVE, account); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
156 else |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
157 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
158 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
159 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
160 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
161 im_msg_sent_cb(GaimAccount *account, const char *receiver, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
162 const char *message, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
163 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
164 GaimConversation *conv = gaim_find_conversation_with_account( |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
165 GAIM_CONV_TYPE_ANY, receiver, account); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
166 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
167 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
168 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
169 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
170 chat_buddy_join_cb(GaimConversation *conv, const char *name, |
12850
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
171 GaimConvChatBuddyFlags flags, gboolean new_arrival, |
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
172 GaimSoundEventID event) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
173 { |
12850
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
174 if (new_arrival && !chat_nick_matches_name(conv, name)) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
175 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
176 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
177 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
178 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
179 chat_buddy_left_cb(GaimConversation *conv, const char *name, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
180 const char *reason, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
181 { |
11581 | 182 if (!chat_nick_matches_name(conv, name)) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
183 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
184 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
185 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
186 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
187 chat_msg_sent_cb(GaimAccount *account, const char *message, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
188 int id, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
189 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
190 GaimConnection *conn = gaim_account_get_connection(account); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
191 GaimConversation *conv = NULL; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
192 |
11581 | 193 if (conn!=NULL) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
194 conv = gaim_find_chat(conn,id); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
195 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
196 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
197 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
198 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
199 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
200 chat_msg_received_cb(GaimAccount *account, char *sender, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
201 char *message, GaimConversation *conv, |
12216 | 202 GaimMessageFlags flags, GaimSoundEventID event) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
203 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
204 GaimConvChat *chat; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
205 |
12850
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
206 if (flags & GAIM_MESSAGE_DELAYED) |
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
207 return; |
49b2347863b2
[gaim-migrate @ 15200]
Richard Laager <rlaager@wiktel.com>
parents:
12828
diff
changeset
|
208 |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
209 chat = gaim_conversation_get_chat_data(conv); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
210 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
211 if (chat!=NULL && gaim_conv_chat_is_user_ignored(chat, sender)) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
212 return; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
213 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
214 if (chat_nick_matches_name(conv, sender)) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
215 return; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
216 |
12216 | 217 if (flags & GAIM_MESSAGE_NICK || gaim_utf8_has_word(message, chat->nick)) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
218 play_conv_event(conv, GAIM_SOUND_CHAT_NICK); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
219 else |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
220 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
221 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
222 |
10320 | 223 /* |
224 * We mute sounds for the 10 seconds after you log in so that | |
225 * you don't get flooded with sounds when the blist shows all | |
226 * your buddies logging in. | |
227 */ | |
228 static void | |
229 account_signon_cb(GaimConnection *gc, gpointer data) | |
230 { | |
231 if (mute_login_sounds_timeout != 0) | |
232 g_source_remove(mute_login_sounds_timeout); | |
233 mute_login_sounds = TRUE; | |
11463 | 234 mute_login_sounds_timeout = gaim_timeout_add(10000, unmute_login_sounds_cb, NULL); |
10320 | 235 } |
236 | |
10322 | 237 static void |
238 _pref_sound_method_changed(const char *name, GaimPrefType type, | |
12816 | 239 gconstpointer val, gpointer data) |
240 { | |
10322 | 241 if(type != GAIM_PREF_STRING || strcmp(name, "/gaim/gtk/sound/method")) |
242 return; | |
243 | |
244 sound_initialized = TRUE; | |
245 | |
246 #ifdef USE_AO | |
247 ao_driver = -1; | |
248 | |
249 if(!strcmp(val, "esd")) | |
250 ao_driver = ao_driver_id("esd"); | |
251 else if(!strcmp(val, "arts")) | |
252 ao_driver = ao_driver_id("arts"); | |
11082 | 253 else if(!strcmp(val, "nas")) |
254 ao_driver = ao_driver_id("nas"); | |
10322 | 255 else if(!strcmp(val, "automatic")) |
256 ao_driver = ao_default_driver_id(); | |
257 | |
258 if(ao_driver != -1) { | |
259 ao_info *info = ao_driver_info(ao_driver); | |
260 gaim_debug_info("sound", | |
261 "Sound output driver loaded: %s\n", info->name); | |
262 } | |
263 #endif /* USE_AO */ | |
264 } | |
265 | |
266 const char * | |
267 gaim_gtk_sound_get_event_option(GaimSoundEventID event) | |
268 { | |
269 if(event >= GAIM_NUM_SOUNDS) | |
270 return 0; | |
271 | |
272 return sounds[event].pref; | |
273 } | |
274 | |
275 char * | |
276 gaim_gtk_sound_get_event_label(GaimSoundEventID event) | |
277 { | |
278 if(event >= GAIM_NUM_SOUNDS) | |
279 return NULL; | |
280 | |
281 return sounds[event].label; | |
282 } | |
283 | |
284 void * | |
285 gaim_gtk_sound_get_handle() | |
286 { | |
287 static int handle; | |
288 | |
289 return &handle; | |
290 } | |
291 | |
292 static void | |
293 gaim_gtk_sound_init(void) | |
5684 | 294 { |
10320 | 295 void *gtk_sound_handle = gaim_gtk_sound_get_handle(); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
296 void *blist_handle = gaim_blist_get_handle(); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
297 void *conv_handle = gaim_conversations_get_handle(); |
10320 | 298 |
299 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
300 gtk_sound_handle, GAIM_CALLBACK(account_signon_cb), | |
301 NULL); | |
302 | |
5684 | 303 gaim_prefs_add_none("/gaim/gtk/sound"); |
304 gaim_prefs_add_none("/gaim/gtk/sound/enabled"); | |
305 gaim_prefs_add_none("/gaim/gtk/sound/file"); | |
306 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/login", TRUE); | |
307 gaim_prefs_add_string("/gaim/gtk/sound/file/login", ""); | |
308 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/logout", TRUE); | |
309 gaim_prefs_add_string("/gaim/gtk/sound/file/logout", ""); | |
310 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/im_recv", TRUE); | |
311 gaim_prefs_add_string("/gaim/gtk/sound/file/im_recv", ""); | |
312 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/first_im_recv", FALSE); | |
313 gaim_prefs_add_string("/gaim/gtk/sound/file/first_im_recv", ""); | |
314 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/send_im", TRUE); | |
315 gaim_prefs_add_string("/gaim/gtk/sound/file/send_im", ""); | |
316 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/join_chat", FALSE); | |
317 gaim_prefs_add_string("/gaim/gtk/sound/file/join_chat", ""); | |
318 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/left_chat", FALSE); | |
319 gaim_prefs_add_string("/gaim/gtk/sound/file/left_chat", ""); | |
320 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/send_chat_msg", FALSE); | |
321 gaim_prefs_add_string("/gaim/gtk/sound/file/send_chat_msg", ""); | |
322 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/chat_msg_recv", FALSE); | |
323 gaim_prefs_add_string("/gaim/gtk/sound/file/chat_msg_recv", ""); | |
324 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/nick_said", FALSE); | |
325 gaim_prefs_add_string("/gaim/gtk/sound/file/nick_said", ""); | |
7460
3973a09525b3
[gaim-migrate @ 8073]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
326 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/pounce_default", TRUE); |
3973a09525b3
[gaim-migrate @ 8073]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
327 gaim_prefs_add_string("/gaim/gtk/sound/file/pounce_default", ""); |
8633 | 328 gaim_prefs_add_bool("/gaim/gtk/sound/conv_focus", TRUE); |
10074 | 329 gaim_prefs_add_bool("/gaim/gtk/sound/mute", FALSE); |
5684 | 330 gaim_prefs_add_string("/gaim/gtk/sound/command", ""); |
331 gaim_prefs_add_string("/gaim/gtk/sound/method", "automatic"); | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
332 gaim_prefs_add_int("/gaim/gtk/sound/volume", 50); |
5684 | 333 |
334 #ifdef USE_AO | |
10322 | 335 gaim_debug_info("sound", "Initializing sound output drivers.\n"); |
5684 | 336 ao_initialize(); |
337 #endif /* USE_AO */ | |
338 | |
10087 | 339 gaim_prefs_connect_callback(gaim_gtk_sound_get_handle(), "/gaim/gtk/sound/method", |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
340 _pref_sound_method_changed, NULL); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
341 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
342 gaim_signal_connect(blist_handle, "buddy-signed-on", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
343 gtk_sound_handle, GAIM_CALLBACK(buddy_state_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
344 GINT_TO_POINTER(GAIM_SOUND_BUDDY_ARRIVE)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
345 gaim_signal_connect(blist_handle, "buddy-signed-off", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
346 gtk_sound_handle, GAIM_CALLBACK(buddy_state_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
347 GINT_TO_POINTER(GAIM_SOUND_BUDDY_LEAVE)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
348 gaim_signal_connect(conv_handle, "received-im-msg", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
349 gtk_sound_handle, GAIM_CALLBACK(im_msg_received_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
350 GINT_TO_POINTER(GAIM_SOUND_RECEIVE)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
351 gaim_signal_connect(conv_handle, "sent-im-msg", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
352 gtk_sound_handle, GAIM_CALLBACK(im_msg_sent_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
353 GINT_TO_POINTER(GAIM_SOUND_SEND)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
354 gaim_signal_connect(conv_handle, "chat-buddy-joined", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
355 gtk_sound_handle, GAIM_CALLBACK(chat_buddy_join_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
356 GINT_TO_POINTER(GAIM_SOUND_CHAT_JOIN)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
357 gaim_signal_connect(conv_handle, "chat-buddy-left", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
358 gtk_sound_handle, GAIM_CALLBACK(chat_buddy_left_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
359 GINT_TO_POINTER(GAIM_SOUND_CHAT_LEAVE)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
360 gaim_signal_connect(conv_handle, "sent-chat-msg", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
361 gtk_sound_handle, GAIM_CALLBACK(chat_msg_sent_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
362 GINT_TO_POINTER(GAIM_SOUND_CHAT_YOU_SAY)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
363 gaim_signal_connect(conv_handle, "received-chat-msg", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
364 gtk_sound_handle, GAIM_CALLBACK(chat_msg_received_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
365 GINT_TO_POINTER(GAIM_SOUND_CHAT_SAY)); |
5684 | 366 } |
367 | |
10322 | 368 static void |
369 gaim_gtk_sound_uninit(void) | |
5684 | 370 { |
371 #ifdef USE_AO | |
372 ao_shutdown(); | |
373 #endif | |
6199 | 374 sound_initialized = FALSE; |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
375 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
376 gaim_signals_disconnect_by_handle(gaim_gtk_sound_get_handle()); |
5684 | 377 } |
378 | |
11463 | 379 #ifdef USE_AO |
10322 | 380 static gboolean |
381 expire_old_child(gpointer data) | |
10074 | 382 { |
383 int ret; | |
384 pid_t pid = GPOINTER_TO_INT(data); | |
385 | |
386 ret = waitpid(pid, NULL, WNOHANG | WUNTRACED); | |
387 | |
388 if(ret == 0) { | |
389 if(kill(pid, SIGKILL) < 0) | |
10322 | 390 gaim_debug_error("gtksound", "Killing process %d failed (%s)\n", |
391 pid, strerror(errno)); | |
10074 | 392 } |
393 | |
394 return FALSE; /* do not run again */ | |
395 } | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
396 |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
397 static void |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
398 scale_pcm_data(char *data, int nframes, ao_sample_format *format, |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
399 double intercept, double minclip, double maxclip, |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
400 float scale) |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
401 { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
402 int i; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
403 float v; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
404 gint16 *data16 = (gint16*)data; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
405 gint32 *data32 = (gint32*)data; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
406 #ifdef G_HAVE_GINT64 |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
407 gint64 *data64 = (gint64*)data; |
10074 | 408 #endif |
409 | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
410 switch(format->bits) { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
411 case 16: |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
412 for(i = 0; i < nframes * format->channels; i++) { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
413 v = ((data16[i] - intercept) * scale) + intercept; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
414 v = CLAMP(v, minclip, maxclip); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
415 data16[i]=(gint16)v; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
416 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
417 break; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
418 case 32: |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
419 for(i = 0; i < nframes * format->channels; i++) { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
420 v = ((data32[i] - intercept) * scale) + intercept; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
421 v = CLAMP(v, minclip, maxclip); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
422 data32[i]=(gint32)v; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
423 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
424 break; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
425 #ifdef G_HAVE_GINT64 |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
426 case 64: |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
427 for(i = 0; i < nframes * format->channels; i++) { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
428 v = ((data64[i] - intercept) * scale) + intercept; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
429 v = CLAMP(v, minclip, maxclip); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
430 data64[i]=(gint64)v; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
431 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
432 break; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
433 #endif |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
434 default: |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
435 gaim_debug_warning("gtksound", "Cannot scale %d bit pcm data.\n", format->bits); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
436 break; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
437 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
438 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
439 #endif /* USE_AO */ |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
440 |
10322 | 441 static void |
442 gaim_gtk_sound_play_file(const char *filename) | |
5684 | 443 { |
444 const char *method; | |
11463 | 445 #ifdef USE_AO |
5684 | 446 pid_t pid; |
447 AFfilehandle file; | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
448 int volume = 50; |
5684 | 449 #endif |
450 | |
6199 | 451 if (!sound_initialized) |
452 gaim_prefs_trigger_callback("/gaim/gtk/sound/method"); | |
453 | |
10074 | 454 if (gaim_prefs_get_bool("/gaim/gtk/sound/mute")) |
5684 | 455 return; |
456 | |
457 method = gaim_prefs_get_string("/gaim/gtk/sound/method"); | |
458 | |
10074 | 459 if (!strcmp(method, "none")) { |
460 return; | |
461 } else if (!strcmp(method, "beep")) { | |
5684 | 462 gdk_beep(); |
463 return; | |
464 } | |
465 | |
466 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
467 char *tmp = g_strdup_printf(_("Unable to play sound because the chosen file (%s) does not exist."), filename); | |
468 gaim_notify_error(NULL, NULL, tmp, NULL); | |
469 g_free(tmp); | |
470 return; | |
471 } | |
472 | |
473 #ifndef _WIN32 | |
474 if (!strcmp(method, "custom")) { | |
475 const char *sound_cmd; | |
476 char *command; | |
477 GError *error = NULL; | |
478 | |
479 sound_cmd = gaim_prefs_get_string("/gaim/gtk/sound/command"); | |
480 | |
481 if (!sound_cmd || *sound_cmd == '\0') { | |
482 gaim_notify_error(NULL, NULL, | |
483 _("Unable to play sound because the " | |
484 "'Command' sound method has been chosen, " | |
485 "but no command has been set."), NULL); | |
486 return; | |
487 } | |
488 | |
7464 | 489 if(strstr(sound_cmd, "%s")) |
490 command = gaim_strreplace(sound_cmd, "%s", filename); | |
491 else | |
492 command = g_strdup_printf("%s %s", sound_cmd, filename); | |
5684 | 493 |
494 if(!g_spawn_command_line_async(command, &error)) { | |
495 char *tmp = g_strdup_printf(_("Unable to play sound because the configured sound command could not be launched: %s"), error->message); | |
496 gaim_notify_error(NULL, NULL, tmp, NULL); | |
497 g_free(tmp); | |
498 g_error_free(error); | |
499 } | |
500 | |
501 g_free(command); | |
502 return; | |
503 } | |
11463 | 504 #ifdef USE_AO |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
505 volume = gaim_prefs_get_int("/gaim/gtk/sound/volume"); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
506 volume = CLAMP(volume, 0, 100); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
507 |
5684 | 508 pid = fork(); |
509 if (pid < 0) | |
510 return; | |
511 else if (pid == 0) { | |
11463 | 512 /* Child process */ |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
513 float scale = ((float) volume * volume) / 2500; |
5684 | 514 file = afOpenFile(filename, "rb", NULL); |
515 if(file) { | |
516 ao_device *device; | |
517 ao_sample_format format; | |
518 int in_fmt; | |
519 int bytes_per_frame; | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
520 double slope, intercept, minclip, maxclip; |
5684 | 521 |
522 format.rate = afGetRate(file, AF_DEFAULT_TRACK); | |
523 format.channels = afGetChannels(file, AF_DEFAULT_TRACK); | |
524 afGetSampleFormat(file, AF_DEFAULT_TRACK, &in_fmt, | |
525 &format.bits); | |
526 | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
527 afGetPCMMapping(file, AF_DEFAULT_TRACK, &slope, |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
528 &intercept, &minclip, &maxclip); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
529 |
5684 | 530 /* XXX: libao doesn't seem to like 8-bit sounds, so we'll |
531 * let libaudiofile make them a bit better for us */ | |
532 if(format.bits == 8) | |
533 format.bits = 16; | |
534 | |
535 afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, | |
536 AF_SAMPFMT_TWOSCOMP, format.bits); | |
537 | |
12411
8c339d9f1bb4
[gaim-migrate @ 14718]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
538 #if G_BYTE_ORDER == G_BIG_ENDIAN |
5684 | 539 format.byte_format = AO_FMT_BIG; |
540 afSetVirtualByteOrder(file, AF_DEFAULT_TRACK, | |
541 AF_BYTEORDER_BIGENDIAN); | |
12411
8c339d9f1bb4
[gaim-migrate @ 14718]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
542 #elif G_BYTE_ORDER == G_LITTLE_ENDIAN |
5684 | 543 format.byte_format = AO_FMT_LITTLE; |
544 afSetVirtualByteOrder(file, AF_DEFAULT_TRACK, | |
545 AF_BYTEORDER_LITTLEENDIAN); | |
12411
8c339d9f1bb4
[gaim-migrate @ 14718]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
546 #else |
8c339d9f1bb4
[gaim-migrate @ 14718]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
547 #warning Unknown endianness |
5684 | 548 #endif |
549 | |
550 bytes_per_frame = format.bits * format.channels / 8; | |
551 | |
552 device = ao_open_live(ao_driver, &format, NULL); | |
553 | |
554 if(device) { | |
555 int frames_read; | |
556 char buf[4096]; | |
557 int buf_frames = sizeof(buf) / bytes_per_frame; | |
558 | |
559 while((frames_read = afReadFrames(file, AF_DEFAULT_TRACK, | |
560 buf, buf_frames))) { | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
561 if(volume != 50) |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
562 scale_pcm_data(buf, frames_read, &format, intercept, |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
563 minclip, maxclip, scale); |
5684 | 564 if(!ao_play(device, buf, frames_read * bytes_per_frame)) |
565 break; | |
566 } | |
567 ao_close(device); | |
568 } | |
569 afCloseFile(file); | |
570 } | |
571 ao_shutdown(); | |
572 _exit(0); | |
10074 | 573 } else { |
11463 | 574 /* Parent process */ |
10074 | 575 gaim_timeout_add(PLAY_SOUND_TIMEOUT, expire_old_child, GINT_TO_POINTER(pid)); |
5684 | 576 } |
11082 | 577 #else /* USE_AO */ |
5684 | 578 gdk_beep(); |
579 return; | |
11082 | 580 #endif /* USE_AO */ |
5684 | 581 #else /* _WIN32 */ |
10322 | 582 gaim_debug_info("sound", "Playing %s\n", filename); |
5684 | 583 |
10922
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
584 if (G_WIN32_HAVE_WIDECHAR_API ()) { |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
585 wchar_t *wc_filename = g_utf8_to_utf16(filename, |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
586 -1, NULL, NULL, NULL); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
587 if (!PlaySoundW(wc_filename, NULL, SND_ASYNC | SND_FILENAME)) |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
588 gaim_debug(GAIM_DEBUG_ERROR, "sound", "Error playing sound.\n"); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
589 g_free(wc_filename); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
590 } else { |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
591 char *l_filename = g_locale_from_utf8(filename, |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
592 -1, NULL, NULL, NULL); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
593 if (!PlaySoundA(l_filename, NULL, SND_ASYNC | SND_FILENAME)) |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
594 gaim_debug(GAIM_DEBUG_ERROR, "sound", "Error playing sound.\n"); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
595 g_free(l_filename); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
596 } |
5684 | 597 #endif /* _WIN32 */ |
598 } | |
599 | |
10322 | 600 static void |
601 gaim_gtk_sound_play_event(GaimSoundEventID event) | |
5684 | 602 { |
603 char *enable_pref; | |
604 char *file_pref; | |
605 | |
606 if ((event == GAIM_SOUND_BUDDY_ARRIVE) && mute_login_sounds) | |
607 return; | |
608 | |
609 if (event >= GAIM_NUM_SOUNDS) { | |
10322 | 610 gaim_debug_error("sound", "got request for unknown sound: %d\n", event); |
5684 | 611 return; |
612 } | |
613 | |
614 enable_pref = g_strdup_printf("/gaim/gtk/sound/enabled/%s", | |
615 sounds[event].pref); | |
616 file_pref = g_strdup_printf("/gaim/gtk/sound/file/%s", sounds[event].pref); | |
617 | |
618 /* check NULL for sounds that don't have an option, ie buddy pounce */ | |
619 if (gaim_prefs_get_bool(enable_pref)) { | |
620 char *filename = g_strdup(gaim_prefs_get_string(file_pref)); | |
621 if(!filename || !strlen(filename)) { | |
622 if(filename) g_free(filename); | |
623 filename = g_build_filename(DATADIR, "sounds", "gaim", sounds[event].def, NULL); | |
624 } | |
625 | |
11642 | 626 gaim_sound_play_file(filename, NULL); |
5684 | 627 g_free(filename); |
628 } | |
629 | |
630 g_free(enable_pref); | |
631 g_free(file_pref); | |
632 } | |
633 | |
634 static GaimSoundUiOps sound_ui_ops = | |
635 { | |
636 gaim_gtk_sound_init, | |
10322 | 637 gaim_gtk_sound_uninit, |
5684 | 638 gaim_gtk_sound_play_file, |
639 gaim_gtk_sound_play_event | |
640 }; | |
641 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6778
diff
changeset
|
642 GaimSoundUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6778
diff
changeset
|
643 gaim_gtk_sound_get_ui_ops(void) |
5684 | 644 { |
645 return &sound_ui_ops; | |
646 } |