Add deleted HTTP digest functions to ChangeLog.API.
[pidgin-git.git] / pidgin / gtksound.c
blob450b07a5acbd3c96f2ea0497429e7e62a62ff1e0
1 /* pidgin
3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #include "internal.h"
23 #include "pidgin.h"
25 #ifdef _WIN32
26 #include <windows.h>
27 #include <mmsystem.h>
28 #endif
30 #ifdef USE_GSTREAMER
31 # include <gst/gst.h>
32 #endif /* USE_GSTREAMER */
34 #include "debug.h"
35 #include "notify.h"
36 #include "prefs.h"
37 #include "sound.h"
38 #include "sound-theme.h"
39 #include "theme-manager.h"
40 #include "util.h"
42 #include "gtkconv.h"
43 #include "gtksound.h"
45 struct pidgin_sound_event {
46 char *label;
47 char *pref;
48 char *def;
51 static guint mute_login_sounds_timeout = 0;
52 static gboolean mute_login_sounds = FALSE;
54 #ifdef USE_GSTREAMER
55 static gboolean gst_init_failed;
56 #endif /* USE_GSTREAMER */
58 static const struct pidgin_sound_event sounds[PURPLE_NUM_SOUNDS] = {
59 {N_("Buddy logs in"), "login", "login.wav"},
60 {N_("Buddy logs out"), "logout", "logout.wav"},
61 {N_("Message received"), "im_recv", "receive.wav"},
62 {N_("Message received begins conversation"), "first_im_recv", "receive.wav"},
63 {N_("Message sent"), "send_im", "send.wav"},
64 {N_("Person enters chat"), "join_chat", "login.wav"},
65 {N_("Person leaves chat"), "left_chat", "logout.wav"},
66 {N_("You talk in chat"), "send_chat_msg", "send.wav"},
67 {N_("Others talk in chat"), "chat_msg_recv", "receive.wav"},
68 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */
69 {NULL, "pounce_default", "alert.wav"},
70 {N_("Someone says your username in chat"), "nick_said", "alert.wav"},
71 {N_("Attention received"), "got_attention", "alert.wav"}
74 static gboolean
75 unmute_login_sounds_cb(gpointer data)
77 mute_login_sounds = FALSE;
78 mute_login_sounds_timeout = 0;
79 return FALSE;
82 static gboolean
83 chat_nick_matches_name(PurpleChatConversation *chat, const char *aname)
85 char *nick = NULL;
86 char *name = NULL;
87 gboolean ret = FALSE;
89 if (chat==NULL)
90 return ret;
92 nick = g_strdup(purple_normalize(purple_conversation_get_account(
93 PURPLE_CONVERSATION(chat)), purple_chat_conversation_get_nick(chat)));
94 name = g_strdup(purple_normalize(purple_conversation_get_account(
95 PURPLE_CONVERSATION(chat)), aname));
97 if (g_utf8_collate(nick, name) == 0)
98 ret = TRUE;
100 g_free(nick);
101 g_free(name);
103 return ret;
107 * play a sound event for a conversation, honoring make_sound flag
108 * of conversation and checking for focus if conv_focus pref is set
110 static void
111 play_conv_event(PurpleConversation *conv, PurpleSoundEventID event)
113 g_return_if_fail(event < PURPLE_NUM_SOUNDS);
115 /* If we should not play the sound for some reason, then exit early */
116 if (conv != NULL && PIDGIN_IS_PIDGIN_CONVERSATION(conv))
118 PidginConversation *gtkconv;
119 gboolean has_focus;
121 gtkconv = PIDGIN_CONVERSATION(conv);
122 has_focus = purple_conversation_has_focus(conv);
124 if (!gtkconv->make_sound ||
125 (has_focus && !purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/sound/conv_focus")))
127 return;
131 purple_sound_play_event(event, conv ? purple_conversation_get_account(conv) : NULL);
134 static void
135 buddy_state_cb(PurpleBuddy *buddy, PurpleSoundEventID event)
137 purple_sound_play_event(event, purple_buddy_get_account(buddy));
140 static void
141 im_msg_received_cb(PurpleAccount *account, char *sender,
142 char *message, PurpleConversation *conv,
143 PurpleMessageFlags flags, PurpleSoundEventID event)
145 if (flags & PURPLE_MESSAGE_DELAYED || flags & PURPLE_MESSAGE_NOTIFY)
146 return;
148 if (conv==NULL)
149 purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE, account);
150 else
151 play_conv_event(conv, event);
154 static void
155 im_msg_sent_cb(PurpleAccount *account, PurpleMessage *msg,
156 PurpleSoundEventID event)
158 PurpleConversation *conv = PURPLE_CONVERSATION(
159 purple_conversations_find_im_with_account(
160 purple_message_get_recipient(msg), account));
161 play_conv_event(conv, event);
164 static void
165 chat_user_join_cb(PurpleChatConversation *chat, const char *name,
166 PurpleChatUserFlags flags, gboolean new_arrival,
167 PurpleSoundEventID event)
169 if (new_arrival && !chat_nick_matches_name(chat, name))
170 play_conv_event(PURPLE_CONVERSATION(chat), event);
173 static void
174 chat_user_left_cb(PurpleChatConversation *chat, const char *name,
175 const char *reason, PurpleSoundEventID event)
177 if (!chat_nick_matches_name(chat, name))
178 play_conv_event(PURPLE_CONVERSATION(chat), event);
181 static void
182 chat_msg_sent_cb(PurpleAccount *account, PurpleMessage *msg, int id,
183 PurpleSoundEventID event)
185 PurpleConnection *conn = purple_account_get_connection(account);
186 PurpleConversation *conv = NULL;
188 if (conn!=NULL)
189 conv = PURPLE_CONVERSATION(purple_conversations_find_chat(conn,id));
191 play_conv_event(conv, event);
194 static void
195 chat_msg_received_cb(PurpleAccount *account, char *sender,
196 char *message, PurpleChatConversation *chat,
197 PurpleMessageFlags flags, PurpleSoundEventID event)
199 PurpleConversation *conv = PURPLE_CONVERSATION(chat);
200 if (flags & PURPLE_MESSAGE_DELAYED || flags & PURPLE_MESSAGE_NOTIFY)
201 return;
203 g_return_if_fail(conv != NULL);
205 if (purple_chat_conversation_is_ignored_user(chat, sender))
206 return;
208 if (chat_nick_matches_name(chat, sender))
209 return;
211 if (flags & PURPLE_MESSAGE_NICK || purple_utf8_has_word(message, purple_chat_conversation_get_nick(chat)))
212 /* This isn't quite right; if you have the PURPLE_SOUND_CHAT_NICK event disabled
213 * and the PURPLE_SOUND_CHAT_SAY event enabled, you won't get a sound at all */
214 play_conv_event(conv, PURPLE_SOUND_CHAT_NICK);
215 else
216 play_conv_event(conv, event);
219 static void
220 got_attention_cb(PurpleAccount *account, const char *who,
221 PurpleConversation *conv, guint type, PurpleSoundEventID event)
223 play_conv_event(conv, event);
227 * We mute sounds for the 10 seconds after you log in so that
228 * you don't get flooded with sounds when the blist shows all
229 * your buddies logging in.
231 static void
232 account_signon_cb(PurpleConnection *gc, gpointer data)
234 if (mute_login_sounds_timeout != 0)
235 g_source_remove(mute_login_sounds_timeout);
236 mute_login_sounds = TRUE;
237 mute_login_sounds_timeout = g_timeout_add_seconds(10, unmute_login_sounds_cb, NULL);
240 const char *
241 pidgin_sound_get_event_option(PurpleSoundEventID event)
243 if(event >= PURPLE_NUM_SOUNDS)
244 return 0;
246 return sounds[event].pref;
249 const char *
250 pidgin_sound_get_event_label(PurpleSoundEventID event)
252 if(event >= PURPLE_NUM_SOUNDS)
253 return NULL;
255 return sounds[event].label;
258 void *
259 pidgin_sound_get_handle()
261 static int handle;
263 return &handle;
266 static void
267 pidgin_sound_init(void)
269 void *gtk_sound_handle = pidgin_sound_get_handle();
270 void *blist_handle = purple_blist_get_handle();
271 void *conv_handle = purple_conversations_get_handle();
272 #ifdef USE_GSTREAMER
273 GError *error = NULL;
274 #endif
276 purple_signal_connect(purple_connections_get_handle(), "signed-on",
277 gtk_sound_handle, PURPLE_CALLBACK(account_signon_cb),
278 NULL);
280 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/sound");
281 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/sound/enabled");
282 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/sound/file");
283 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/login", TRUE);
284 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/login", "");
285 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/logout", TRUE);
286 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/logout", "");
287 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/im_recv", TRUE);
288 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/im_recv", "");
289 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/first_im_recv", FALSE);
290 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/first_im_recv", "");
291 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/send_im", TRUE);
292 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/send_im", "");
293 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/join_chat", FALSE);
294 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/join_chat", "");
295 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/left_chat", FALSE);
296 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/left_chat", "");
297 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/send_chat_msg", FALSE);
298 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/send_chat_msg", "");
299 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/chat_msg_recv", FALSE);
300 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/chat_msg_recv", "");
301 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/nick_said", FALSE);
302 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/nick_said", "");
303 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/pounce_default", TRUE);
304 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/pounce_default", "");
305 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/sound/theme", "");
306 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/sent_attention", TRUE);
307 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/sent_attention", "");
308 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/got_attention", TRUE);
309 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/got_attention", "");
310 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/conv_focus", TRUE);
311 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/mute", FALSE);
312 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/command", "");
313 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/sound/method", "automatic");
315 #ifdef USE_GSTREAMER
316 purple_debug_info("sound", "Initializing sound output drivers.\n");
317 gst_registry_fork_set_enabled(FALSE);
318 if ((gst_init_failed = !gst_init_check(NULL, NULL, &error))) {
319 purple_notify_error(NULL, _("GStreamer Failure"),
320 _("GStreamer failed to initialize."),
321 error ? error->message : "", NULL);
322 if (error) {
323 g_error_free(error);
324 error = NULL;
327 #endif /* USE_GSTREAMER */
329 purple_signal_connect(blist_handle, "buddy-signed-on",
330 gtk_sound_handle, PURPLE_CALLBACK(buddy_state_cb),
331 GINT_TO_POINTER(PURPLE_SOUND_BUDDY_ARRIVE));
332 purple_signal_connect(blist_handle, "buddy-signed-off",
333 gtk_sound_handle, PURPLE_CALLBACK(buddy_state_cb),
334 GINT_TO_POINTER(PURPLE_SOUND_BUDDY_LEAVE));
335 purple_signal_connect(conv_handle, "received-im-msg",
336 gtk_sound_handle, PURPLE_CALLBACK(im_msg_received_cb),
337 GINT_TO_POINTER(PURPLE_SOUND_RECEIVE));
338 purple_signal_connect(conv_handle, "sent-im-msg",
339 gtk_sound_handle, PURPLE_CALLBACK(im_msg_sent_cb),
340 GINT_TO_POINTER(PURPLE_SOUND_SEND));
341 purple_signal_connect(conv_handle, "chat-user-joined",
342 gtk_sound_handle, PURPLE_CALLBACK(chat_user_join_cb),
343 GINT_TO_POINTER(PURPLE_SOUND_CHAT_JOIN));
344 purple_signal_connect(conv_handle, "chat-user-left",
345 gtk_sound_handle, PURPLE_CALLBACK(chat_user_left_cb),
346 GINT_TO_POINTER(PURPLE_SOUND_CHAT_LEAVE));
347 purple_signal_connect(conv_handle, "sent-chat-msg",
348 gtk_sound_handle, PURPLE_CALLBACK(chat_msg_sent_cb),
349 GINT_TO_POINTER(PURPLE_SOUND_CHAT_YOU_SAY));
350 purple_signal_connect(conv_handle, "received-chat-msg",
351 gtk_sound_handle, PURPLE_CALLBACK(chat_msg_received_cb),
352 GINT_TO_POINTER(PURPLE_SOUND_CHAT_SAY));
353 purple_signal_connect(conv_handle, "got-attention", gtk_sound_handle,
354 PURPLE_CALLBACK(got_attention_cb),
355 GINT_TO_POINTER(PURPLE_SOUND_GOT_ATTENTION));
356 /* for the time being, don't handle sent-attention here, since playing a
357 sound would result induplicate sounds. And fixing that would require changing the
358 conversation signal for msg-recv */
361 static void
362 pidgin_sound_uninit(void)
364 #ifdef USE_GSTREAMER
365 if (!gst_init_failed)
366 gst_deinit();
367 #endif
369 purple_signals_disconnect_by_handle(pidgin_sound_get_handle());
372 #ifdef USE_GSTREAMER
373 static gboolean
374 bus_call (GstBus *bus,
375 GstMessage *msg,
376 gpointer data)
378 GstElement *play = data;
379 GError *err = NULL;
381 switch (GST_MESSAGE_TYPE (msg)) {
382 case GST_MESSAGE_ERROR:
383 gst_message_parse_error(msg, &err, NULL);
384 purple_debug_error("gstreamer", "%s\n", err->message);
385 g_error_free(err);
386 /* fall-through and clean up */
387 case GST_MESSAGE_EOS:
388 gst_element_set_state(play, GST_STATE_NULL);
389 gst_object_unref(GST_OBJECT(play));
390 return FALSE;
391 break;
392 case GST_MESSAGE_WARNING:
393 gst_message_parse_warning(msg, &err, NULL);
394 purple_debug_warning("gstreamer", "%s\n", err->message);
395 g_error_free(err);
396 break;
397 default:
398 break;
400 return TRUE;
402 #endif
404 #ifndef _WIN32
405 static gboolean
406 expire_old_child(gpointer data)
408 pid_t pid = GPOINTER_TO_INT(data);
410 if (waitpid(pid, NULL, WNOHANG | WUNTRACED) < 0) {
411 if (errno == ECHILD)
412 return FALSE;
413 else
414 purple_debug_warning("gtksound", "Child is ill, pid: %d (%s)\n", pid, strerror(errno));
417 if (kill(pid, SIGKILL) < 0)
418 purple_debug_error("gtksound", "Killing process %d failed (%s)\n", pid, strerror(errno));
420 return FALSE;
422 #endif
424 #ifdef _WIN32
425 static void
426 pidgin_sound_play_file_win32(const char *filename)
428 wchar_t *wc_filename = g_utf8_to_utf16(filename,
429 -1, NULL, NULL, NULL);
430 if (!PlaySoundW(wc_filename, NULL, SND_ASYNC | SND_FILENAME))
431 purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n");
432 g_free(wc_filename);
434 #endif /* _WIN32 */
436 static void
437 pidgin_sound_play_file(const char *filename)
439 const char *method;
440 #ifdef USE_GSTREAMER
441 char *uri;
442 GstElement *sink = NULL;
443 GstElement *play = NULL;
444 GstBus *bus = NULL;
445 #endif
447 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/sound/mute"))
448 return;
450 method = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/method");
452 if (purple_strequal(method, "none")) {
453 return;
454 } else if (purple_strequal(method, "beep")) {
455 gdk_beep();
456 return;
458 #ifdef _WIN32
459 else if (purple_strequal(method, "playsoundw")) {
460 pidgin_sound_play_file_win32(filename);
461 return;
463 #endif /* _WIN32 */
465 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
466 purple_debug_error("gtksound", "sound file (%s) does not exist.\n", filename);
467 return;
470 #ifndef _WIN32
471 if (purple_strequal(method, "custom")) {
472 const char *sound_cmd;
473 char *command;
474 char *esc_filename;
475 char **argv = NULL;
476 GError *error = NULL;
477 GPid pid;
479 sound_cmd = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/sound/command");
481 if (!sound_cmd || *sound_cmd == '\0') {
482 purple_debug_error("gtksound",
483 "'Command' sound method has been chosen, "
484 "but no command has been set.\n");
485 return;
488 esc_filename = g_shell_quote(filename);
490 if(strstr(sound_cmd, "%s"))
491 command = purple_strreplace(sound_cmd, "%s", esc_filename);
492 else
493 command = g_strdup_printf("%s %s", sound_cmd, esc_filename);
495 if (!g_shell_parse_argv(command, NULL, &argv, &error)) {
496 purple_debug_error("gtksound", "error parsing command %s (%s)\n",
497 command, error->message);
498 g_error_free(error);
499 g_free(esc_filename);
500 g_free(command);
501 return;
504 if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
505 NULL, NULL, &pid, &error)) {
506 purple_debug_error("gtksound", "sound command could not be launched: %s\n",
507 error->message);
508 g_error_free(error);
509 } else {
510 g_timeout_add_seconds(15, expire_old_child, GINT_TO_POINTER(pid));
513 g_strfreev(argv);
514 g_free(esc_filename);
515 g_free(command);
516 return;
518 #endif /* _WIN32 */
520 #ifdef USE_GSTREAMER
521 if (gst_init_failed) /* Perhaps do gdk_beep instead? */
522 return;
523 #ifdef _WIN32
524 if (purple_strequal(method, "automatic")) {
525 sink = gst_element_factory_make("directsoundsink", "sink");
526 if (sink == NULL)
527 sink = gst_element_factory_make("waveformsink", "sink");
528 if (sink == NULL)
529 sink = gst_element_factory_make("gconfaudiosink", "sink");
530 } else if (purple_strequal(method, "directsound")) {
531 sink = gst_element_factory_make("directsoundsink", "sink");
532 } else if (purple_strequal(method, "waveform")) {
533 sink = gst_element_factory_make("waveformsink", "sink");
535 #else
536 if (purple_strequal(method, "automatic")) {
537 sink = gst_element_factory_make("gconfaudiosink", "sink");
538 } else if (purple_strequal(method, "esd")) {
539 sink = gst_element_factory_make("esdsink", "sink");
540 } else if (purple_strequal(method, "alsa")) {
541 sink = gst_element_factory_make("alsasink", "sink");
543 #endif
544 else {
545 purple_debug_error("sound", "Unknown sound method '%s'\n", method);
546 return;
549 if (!purple_strequal(method, "automatic") && !sink) {
550 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
551 return;
554 play = gst_element_factory_make("playbin", "play");
556 if (play == NULL) {
557 return;
560 #ifdef _WIN32
561 uri = g_strdup_printf("file:///%s", filename);
562 g_strdelimit(uri, "\\", '/');
563 #else
564 uri = g_strdup_printf("file://%s", filename);
565 #endif
567 g_object_set(G_OBJECT(play), "uri", uri,
568 "audio-sink", sink, NULL);
570 bus = gst_pipeline_get_bus(GST_PIPELINE(play));
571 gst_bus_add_watch(bus, bus_call, play);
573 gst_element_set_state(play, GST_STATE_PLAYING);
575 gst_object_unref(bus);
576 g_free(uri);
578 #else /* #ifdef USE_GSTREAMER */
580 #ifndef _WIN32
581 gdk_beep();
582 #else /* _WIN32 */
583 pidgin_sound_play_file_win32(filename);
584 #endif /* _WIN32 */
586 #endif /* USE_GSTREAMER */
589 static void
590 pidgin_sound_play_event(PurpleSoundEventID event)
592 char *enable_pref;
593 char *file_pref;
594 const char *theme_name;
595 PurpleSoundTheme *theme;
597 if ((event == PURPLE_SOUND_BUDDY_ARRIVE) && mute_login_sounds)
598 return;
600 if (event >= PURPLE_NUM_SOUNDS) {
601 purple_debug_error("sound", "got request for unknown sound: %d\n", event);
602 return;
605 enable_pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/enabled/%s",
606 sounds[event].pref);
607 file_pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s", sounds[event].pref);
609 /* check NULL for sounds that don't have an option, ie buddy pounce */
610 if (purple_prefs_get_bool(enable_pref)) {
611 char *filename = g_strdup(purple_prefs_get_path(file_pref));
612 theme_name = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme");
614 if (theme_name && *theme_name && (!filename || !*filename)) {
615 /* Use theme */
616 g_free(filename);
618 theme = PURPLE_SOUND_THEME(purple_theme_manager_find_theme(theme_name, "sound"));
619 filename = purple_sound_theme_get_file_full(theme, sounds[event].pref);
621 if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR)){ /* Use Default sound in this case */
622 purple_debug_error("sound", "The file: (%s) %s\n from theme: %s, was not found or wasn't readable\n",
623 sounds[event].pref, filename, theme_name);
624 g_free(filename);
625 filename = NULL;
629 if (!filename || *filename == '\0') { /* Use Default sounds */
630 g_free(filename);
632 filename = g_build_filename(PURPLE_DATADIR,
633 "sounds", "purple", sounds[event].def, NULL);
636 purple_sound_play_file(filename, NULL);
638 g_free(filename);
641 g_free(enable_pref);
642 g_free(file_pref);
645 gboolean
646 pidgin_sound_is_customized(void)
648 gint i;
649 gchar *path;
650 const char *file;
652 for (i = 0; i < PURPLE_NUM_SOUNDS; i++) {
653 path = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s", sounds[i].pref);
654 file = purple_prefs_get_path(path);
655 g_free(path);
657 if (file && file[0] != '\0')
658 return TRUE;
661 return FALSE;
665 static PurpleSoundUiOps sound_ui_ops =
667 pidgin_sound_init,
668 pidgin_sound_uninit,
669 pidgin_sound_play_file,
670 pidgin_sound_play_event,
671 NULL,
672 NULL,
673 NULL,
674 NULL
677 PurpleSoundUiOps *
678 pidgin_sound_get_ui_ops(void)
680 return &sound_ui_ops;