annotate finch/gntsound.c @ 19105:fd27baf1711b

disapproval of revision 'c80d121e4fd54ef1ba9c1ce9e4afa059f6b777e9'
author Eric Polino <aluink@pidgin.im>
date Tue, 19 Jun 2007 19:33:16 +0000
parents 68a3b83795c6
children 4c26b23e7859
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19100
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
1 /**
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
2 * @file gntsound.c GNT Sound API
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
3 * @ingroup finch
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
4 *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
5 * finch
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
6 *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
7 * Finch is the legal property of its developers, whose names are too numerous
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
9 * source distribution.
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
10 *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
14 * (at your option) any later version.
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
15 *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
19 * GNU General Public License for more details.
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
20 *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
24 */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
25 #include "internal.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
26 #include "finch.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
27
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
28 #ifdef _WIN32
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
29 #include <windows.h>
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
30 #include <mmsystem.h>
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
31 #endif
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
32
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
33 #ifdef USE_GSTREAMER
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
34 #include <gst/gst.h>
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
35 #endif /* USE_GSTREAMER */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
36
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
37 #include "debug.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
38 #include "notify.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
39 #include "prefs.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
40 #include "sound.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
41 #include "util.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
42
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
43 #include "gntconv.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
44 #include "gntsound.h"
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
45
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
46 struct finch_sound_event {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
47 char *label;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
48 char *pref;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
49 char *def;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
50 };
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
51
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
52 #define PLAY_SOUND_TIMEOUT 15000
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
53
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
54 static guint mute_login_sounds_timeout = 0;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
55 static gboolean mute_login_sounds = FALSE;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
56
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
57 #ifdef USE_GSTREAMER
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
58 static gboolean gst_init_failed;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
59 #endif /* USE_GSTREAMER */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
60
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
61 static struct finch_sound_event sounds[PURPLE_NUM_SOUNDS] = {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
62 {N_("Buddy logs in"), "login", "login.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
63 {N_("Buddy logs out"), "logout", "logout.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
64 {N_("Message received"), "im_recv", "receive.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
65 {N_("Message received begins conversation"), "first_im_recv", "receive.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
66 {N_("Message sent"), "send_im", "send.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
67 {N_("Person enters chat"), "join_chat", "login.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
68 {N_("Person leaves chat"), "left_chat", "logout.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
69 {N_("You talk in chat"), "send_chat_msg", "send.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
70 {N_("Others talk in chat"), "chat_msg_recv", "receive.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
71 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
72 {NULL, "pounce_default", "alert.wav"},
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
73 {N_("Someone says your screen name in chat"), "nick_said", "alert.wav"}
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
74 };
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
75
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
76 static gboolean
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
77 unmute_login_sounds_cb(gpointer data)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
78 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
79 mute_login_sounds = FALSE;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
80 mute_login_sounds_timeout = 0;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
81 return FALSE;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
82 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
83
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
84 static gboolean
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
85 chat_nick_matches_name(PurpleConversation *conv, const char *aname)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
86 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
87 PurpleConvChat *chat = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
88 char *nick = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
89 char *name = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
90 gboolean ret = FALSE;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
91 chat = purple_conversation_get_chat_data(conv);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
92
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
93 if (chat==NULL)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
94 return ret;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
95
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
96 nick = g_strdup(purple_normalize(conv->account, chat->nick));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
97 name = g_strdup(purple_normalize(conv->account, aname));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
98
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
99 if (g_utf8_collate(nick, name) == 0)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
100 ret = TRUE;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
101
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
102 g_free(nick);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
103 g_free(name);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
104
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
105 return ret;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
106 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
107
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
108 /*
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
109 * play a sound event for a conversation, honoring make_sound flag
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
110 * of conversation and checking for focus if conv_focus pref is set
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
111 */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
112 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
113 play_conv_event(PurpleConversation *conv, PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
114 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
115 /* If we should not play the sound for some reason, then exit early */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
116 if (conv != NULL)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
117 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
118 FinchConv *gntconv;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
119 gboolean has_focus;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
120
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
121 gntconv = FINCH_CONV(conv);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
122
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
123 has_focus = purple_conversation_has_focus(conv);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
124
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
125 if (has_focus && !purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/conv_focus"))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
126 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
127 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
128 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
129 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
130
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
131 purple_sound_play_event(event, conv ? purple_conversation_get_account(conv) : NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
132 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
133
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
134 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
135 buddy_state_cb(PurpleBuddy *buddy, PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
136 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
137 purple_sound_play_event(event, purple_buddy_get_account(buddy));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
138 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
139
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
140 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
141 im_msg_received_cb(PurpleAccount *account, char *sender,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
142 char *message, PurpleConversation *conv,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
143 PurpleMessageFlags flags, PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
144 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
145 if (flags & PURPLE_MESSAGE_DELAYED)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
146 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
147
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
148 if (conv==NULL){
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
149 purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE, account);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
150 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
151 else{
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
152 play_conv_event(conv, event);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
153 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
154 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
155
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
156 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
157 im_msg_sent_cb(PurpleAccount *account, const char *receiver,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
158 const char *message, PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
159 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
160 PurpleConversation *conv = purple_find_conversation_with_account(
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
161 PURPLE_CONV_TYPE_ANY, receiver, account);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
162 play_conv_event(conv, event);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
163 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
164
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
165 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
166 chat_buddy_join_cb(PurpleConversation *conv, const char *name,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
167 PurpleConvChatBuddyFlags flags, gboolean new_arrival,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
168 PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
169 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
170 if (new_arrival && !chat_nick_matches_name(conv, name))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
171 play_conv_event(conv, event);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
172 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
173
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
174 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
175 chat_buddy_left_cb(PurpleConversation *conv, const char *name,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
176 const char *reason, PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
177 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
178 if (!chat_nick_matches_name(conv, name))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
179 play_conv_event(conv, event);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
180 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
181
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
182 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
183 chat_msg_sent_cb(PurpleAccount *account, const char *message,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
184 int id, PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
185 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
186 PurpleConnection *conn = purple_account_get_connection(account);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
187 PurpleConversation *conv = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
188
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
189 if (conn!=NULL)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
190 conv = purple_find_chat(conn,id);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
191
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
192 play_conv_event(conv, event);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
193 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
194
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
195 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
196 chat_msg_received_cb(PurpleAccount *account, char *sender,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
197 char *message, PurpleConversation *conv,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
198 PurpleMessageFlags flags, PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
199 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
200 PurpleConvChat *chat;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
201
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
202 if (flags & PURPLE_MESSAGE_DELAYED)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
203 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
204
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
205 chat = purple_conversation_get_chat_data(conv);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
206 g_return_if_fail(chat != NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
207
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
208 if (purple_conv_chat_is_user_ignored(chat, sender))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
209 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
210
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
211 if (chat_nick_matches_name(conv, sender))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
212 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
213
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
214 if (flags & PURPLE_MESSAGE_NICK || purple_utf8_has_word(message, chat->nick))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
215 play_conv_event(conv, PURPLE_SOUND_CHAT_NICK);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
216 else
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
217 play_conv_event(conv, event);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
218 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
219
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
220 /*
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
221 * We mute sounds for the 10 seconds after you log in so that
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
222 * you don't get flooded with sounds when the blist shows all
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
223 * your buddies logging in.
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
224 */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
225 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
226 account_signon_cb(PurpleConnection *gc, gpointer data)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
227 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
228 if (mute_login_sounds_timeout != 0)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
229 g_source_remove(mute_login_sounds_timeout);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
230 mute_login_sounds = TRUE;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
231 mute_login_sounds_timeout = purple_timeout_add(10000, unmute_login_sounds_cb, NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
232 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
233
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
234 const char *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
235 finch_sound_get_event_option(PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
236 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
237 if(event >= PURPLE_NUM_SOUNDS)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
238 return 0;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
239
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
240 return sounds[event].pref;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
241 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
242
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
243 const char *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
244 finch_sound_get_event_label(PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
245 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
246 if(event >= PURPLE_NUM_SOUNDS)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
247 return NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
248
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
249 return sounds[event].label;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
250 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
251
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
252 void *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
253 finch_sound_get_handle()
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
254 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
255 static int handle;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
256
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
257 return &handle;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
258 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
259
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
260 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
261 finch_sound_init(void)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
262 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
263 void *gnt_sound_handle = finch_sound_get_handle();
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
264 void *blist_handle = purple_blist_get_handle();
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
265 void *conv_handle = purple_conversations_get_handle();
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
266 #ifdef USE_GSTREAMER
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
267 GError *error = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
268 #endif
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
269
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
270 purple_signal_connect(purple_connections_get_handle(), "signed-on",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
271 gnt_sound_handle, PURPLE_CALLBACK(account_signon_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
272 NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
273
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
274 purple_prefs_add_none(FINCH_PREFS_ROOT "/sound");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
275 purple_prefs_add_none(FINCH_PREFS_ROOT "/sound/enabled");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
276 purple_prefs_add_none(FINCH_PREFS_ROOT "/sound/file");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
277 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/login", TRUE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
278 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/login", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
279 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/logout", TRUE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
280 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/logout", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
281 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/im_recv", TRUE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
282 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/im_recv", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
283 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/first_im_recv", FALSE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
284 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/first_im_recv", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
285 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/send_im", TRUE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
286 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/send_im", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
287 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/join_chat", FALSE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
288 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/join_chat", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
289 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/left_chat", FALSE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
290 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/left_chat", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
291 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/send_chat_msg", FALSE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
292 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/send_chat_msg", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
293 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/chat_msg_recv", FALSE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
294 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/chat_msg_recv", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
295 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/nick_said", FALSE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
296 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/nick_said", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
297 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/pounce_default", TRUE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
298 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/pounce_default", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
299 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/conv_focus", TRUE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
300 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/mute", FALSE);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
301 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/command", "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
302 purple_prefs_add_string(FINCH_PREFS_ROOT "/sound/method", "automatic");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
303 purple_prefs_add_int(FINCH_PREFS_ROOT "/sound/volume", 50);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
304
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
305 #ifdef USE_GSTREAMER
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
306 purple_debug_info("sound", "Initializing sound output drivers.\n");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
307 if ((gst_init_failed = !gst_init_check(NULL, NULL, &error))) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
308 purple_notify_error(NULL, _("GStreamer Failure"),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
309 _("GStreamer failed to initialize."),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
310 error ? error->message : "");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
311 if (error) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
312 g_error_free(error);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
313 error = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
314 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
315 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
316 #endif /* USE_GSTREAMER */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
317
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
318 purple_signal_connect(blist_handle, "buddy-signed-on",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
319 gnt_sound_handle, PURPLE_CALLBACK(buddy_state_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
320 GINT_TO_POINTER(PURPLE_SOUND_BUDDY_ARRIVE));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
321 purple_signal_connect(blist_handle, "buddy-signed-off",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
322 gnt_sound_handle, PURPLE_CALLBACK(buddy_state_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
323 GINT_TO_POINTER(PURPLE_SOUND_BUDDY_LEAVE));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
324 purple_signal_connect(conv_handle, "received-im-msg",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
325 gnt_sound_handle, PURPLE_CALLBACK(im_msg_received_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
326 GINT_TO_POINTER(PURPLE_SOUND_RECEIVE));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
327 purple_signal_connect(conv_handle, "sent-im-msg",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
328 gnt_sound_handle, PURPLE_CALLBACK(im_msg_sent_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
329 GINT_TO_POINTER(PURPLE_SOUND_SEND));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
330 purple_signal_connect(conv_handle, "chat-buddy-joined",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
331 gnt_sound_handle, PURPLE_CALLBACK(chat_buddy_join_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
332 GINT_TO_POINTER(PURPLE_SOUND_CHAT_JOIN));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
333 purple_signal_connect(conv_handle, "chat-buddy-left",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
334 gnt_sound_handle, PURPLE_CALLBACK(chat_buddy_left_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
335 GINT_TO_POINTER(PURPLE_SOUND_CHAT_LEAVE));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
336 purple_signal_connect(conv_handle, "sent-chat-msg",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
337 gnt_sound_handle, PURPLE_CALLBACK(chat_msg_sent_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
338 GINT_TO_POINTER(PURPLE_SOUND_CHAT_YOU_SAY));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
339 purple_signal_connect(conv_handle, "received-chat-msg",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
340 gnt_sound_handle, PURPLE_CALLBACK(chat_msg_received_cb),
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
341 GINT_TO_POINTER(PURPLE_SOUND_CHAT_SAY));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
342 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
343
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
344 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
345 finch_sound_uninit(void)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
346 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
347 #ifdef USE_GSTREAMER
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
348 if (!gst_init_failed)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
349 gst_deinit();
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
350 #endif
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
351
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
352 purple_signals_disconnect_by_handle(finch_sound_get_handle());
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
353 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
354
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
355 #ifdef USE_GSTREAMER
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
356 static gboolean
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
357 bus_call (GstBus *bus, GstMessage *msg, gpointer data)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
358 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
359 GstElement *play = data;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
360 GError *err = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
361
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
362 switch (GST_MESSAGE_TYPE (msg)) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
363 case GST_MESSAGE_EOS:
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
364 gst_element_set_state(play, GST_STATE_NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
365 gst_object_unref(GST_OBJECT(play));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
366 break;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
367 case GST_MESSAGE_ERROR:
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
368 gst_message_parse_error(msg, &err, NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
369 purple_debug_error("gstreamer", err->message);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
370 g_error_free(err);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
371 break;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
372 case GST_MESSAGE_WARNING:
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
373 gst_message_parse_warning(msg, &err, NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
374 purple_debug_warning("gstreamer", err->message);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
375 g_error_free(err);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
376 break;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
377 default:
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
378 break;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
379 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
380 return TRUE;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
381 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
382 #endif
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
383
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
384 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
385 finch_sound_play_file(const char *filename)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
386 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
387 const char *method;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
388 #ifdef USE_GSTREAMER
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
389 float volume;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
390 char *uri;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
391 GstElement *sink = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
392 GstElement *play = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
393 GstBus *bus = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
394 #endif
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
395 if (purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/mute"))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
396 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
397
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
398 method = purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/method");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
399
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
400 if (!strcmp(method, "none")) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
401 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
402 } else if (!strcmp(method, "beep")) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
403 beep();
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
404 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
405 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
406
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
407 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
408 purple_debug_error("gntsound", "sound file (%s) does not exist.\n", filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
409 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
410 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
411
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
412 #ifndef _WIN32
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
413 if (!strcmp(method, "custom")) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
414 const char *sound_cmd;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
415 char *command;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
416 char *esc_filename;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
417 GError *error = NULL;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
418
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
419 sound_cmd = purple_prefs_get_path(FINCH_PREFS_ROOT "/sound/command");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
420
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
421 if (!sound_cmd || *sound_cmd == '\0') {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
422 purple_debug_error("gntsound",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
423 "'Command' sound method has been chosen, "
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
424 "but no command has been set.");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
425 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
426 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
427
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
428 esc_filename = g_shell_quote(filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
429
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
430 if(strstr(sound_cmd, "%s"))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
431 command = purple_strreplace(sound_cmd, "%s", esc_filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
432 else
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
433 command = g_strdup_printf("%s %s", sound_cmd, esc_filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
434
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
435 if(!g_spawn_command_line_async(command, &error)) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
436 purple_debug_error("gntsound", "sound command could not be launched: %s\n", error->message);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
437 g_error_free(error);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
438 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
439
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
440 g_free(esc_filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
441 g_free(command);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
442 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
443 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
444 #ifdef USE_GSTREAMER
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
445 if (gst_init_failed) /* Perhaps do beep instead? */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
446 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
447 volume = (float)(CLAMP(purple_prefs_get_int(FINCH_PREFS_ROOT "/sound/volume"),0,100)) / 50;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
448 if (!strcmp(method, "automatic")) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
449 if (purple_running_gnome()) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
450 sink = gst_element_factory_make("gconfaudiosink", "sink");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
451 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
452 if (!sink)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
453 sink = gst_element_factory_make("autoaudiosink", "sink");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
454 if (!sink) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
455 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
456 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
457 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
458 } else if (!strcmp(method, "esd")) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
459 sink = gst_element_factory_make("esdsink", "sink");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
460 if (!sink) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
461 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
462 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
463 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
464 } else if (!strcmp(method, "alsa")) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
465 sink = gst_element_factory_make("alsasink", "sink");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
466 if (!sink) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
467 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
468 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
469 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
470 } else {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
471 purple_debug_error("sound", "Unknown sound method '%s'\n", method);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
472 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
473 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
474
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
475 play = gst_element_factory_make("playbin", "play");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
476
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
477 if (play == NULL) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
478 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
479 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
480
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
481 uri = g_strdup_printf("file://%s", filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
482
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
483 g_object_set(G_OBJECT(play), "uri", uri,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
484 "volume", volume,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
485 "audio-sink", sink, NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
486
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
487 bus = gst_pipeline_get_bus(GST_PIPELINE(play));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
488 gst_bus_add_watch(bus, bus_call, play);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
489
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
490 gst_element_set_state(play, GST_STATE_PLAYING);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
491
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
492 gst_object_unref(bus);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
493 g_free(uri);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
494
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
495 #else /* USE_GSTREAMER */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
496 beep();
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
497 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
498 #endif /* USE_GSTREAMER */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
499 #else /* _WIN32 */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
500 purple_debug_info("sound", "Playing %s\n", filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
501
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
502 if (G_WIN32_HAVE_WIDECHAR_API ()) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
503 wchar_t *wc_filename = g_utf8_to_utf16(filename,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
504 -1, NULL, NULL, NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
505 if (!PlaySoundW(wc_filename, NULL, SND_ASYNC | SND_FILENAME))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
506 purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
507 g_free(wc_filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
508 } else {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
509 char *l_filename = g_locale_from_utf8(filename,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
510 -1, NULL, NULL, NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
511 if (!PlaySoundA(l_filename, NULL, SND_ASYNC | SND_FILENAME))
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
512 purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n");
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
513 g_free(l_filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
514 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
515 #endif /* _WIN32 */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
516 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
517
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
518 static void
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
519 finch_sound_play_event(PurpleSoundEventID event)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
520 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
521 char *enable_pref;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
522 char *file_pref;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
523 if ((event == PURPLE_SOUND_BUDDY_ARRIVE) && mute_login_sounds)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
524 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
525
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
526 if (event >= PURPLE_NUM_SOUNDS) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
527 purple_debug_error("sound", "got request for unknown sound: %d\n", event);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
528 return;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
529 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
530
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
531 enable_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s",
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
532 sounds[event].pref);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
533 file_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/file/%s", sounds[event].pref);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
534
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
535 /* check NULL for sounds that don't have an option, ie buddy pounce */
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
536 if (purple_prefs_get_bool(enable_pref)) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
537 char *filename = g_strdup(purple_prefs_get_path(file_pref));
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
538 if(!filename || !strlen(filename)) {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
539 g_free(filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
540 filename = g_build_filename(DATADIR, "sounds", "finch", sounds[event].def, NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
541 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
542
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
543 purple_sound_play_file(filename, NULL);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
544 g_free(filename);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
545 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
546
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
547 g_free(enable_pref);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
548 g_free(file_pref);
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
549 }
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
550
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
551 static PurpleSoundUiOps sound_ui_ops =
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
552 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
553 finch_sound_init,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
554 finch_sound_uninit,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
555 finch_sound_play_file,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
556 finch_sound_play_event,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
557 NULL,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
558 NULL,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
559 NULL,
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
560 NULL
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
561 };
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
562
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
563 PurpleSoundUiOps *
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
564 finch_sound_get_ui_ops(void)
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
565 {
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
566 return &sound_ui_ops;
68a3b83795c6 Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
567 }