finch/gntsound.c

Fri, 29 Jun 2007 21:12:03 +0000

author
Eric Polino <aluink@pidgin.im>
date
Fri, 29 Jun 2007 21:12:03 +0000
branch
soc.2007.finchfeat
changeset 18432
8fd3963b9ce0
parent 18296
9461f264ee5f
child 18433
fdc058213b75
permissions
-rw-r--r--

Changed the volume changer to a GntSlider.

18155
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
1 /**
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
2 * @file gntsound.c GNT Sound API
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
3 * @ingroup finch
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
4 *
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
5 * finch
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
6 *
3bb5605ea11e 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
3bb5605ea11e 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
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
9 * source distribution.
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
10 *
3bb5605ea11e 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
3bb5605ea11e 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
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
14 * (at your option) any later version.
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
15 *
3bb5605ea11e 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,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
19 * GNU General Public License for more details.
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
20 *
3bb5605ea11e 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
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
3bb5605ea11e 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
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
24 */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
25 #include "internal.h"
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
26 #include "finch.h"
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
27
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
28 #ifdef _WIN32
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
29 #include <windows.h>
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
30 #include <mmsystem.h>
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
31 #endif
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
32
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
33 #ifdef USE_GSTREAMER
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
34 #include <gst/gst.h>
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
35 #endif /* USE_GSTREAMER */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
36
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
37 #include "debug.h"
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
38 #include "notify.h"
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
39 #include "prefs.h"
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
40 #include "sound.h"
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
41 #include "util.h"
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
42
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
43 #include "gntbox.h"
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
44 #include "gntwindow.h"
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
45 #include "gntcombobox.h"
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
46 #include "gntlabel.h"
18155
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
47 #include "gntconv.h"
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
48 #include "gntsound.h"
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
49 #include "gntwidget.h"
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
50 #include "gntentry.h"
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
51 #include "gntcheckbox.h"
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
52 #include "gntline.h"
18432
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
53 #include "gntslider.h"
18155
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
54
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
55 struct finch_sound_event {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
56 char *label;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
57 char *pref;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
58 char *def;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
59 };
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
60
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
61 typedef struct {
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
62 GntWidget *method;
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
63 GntWidget *command;
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
64 GntWidget *conv_focus;
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
65 GntWidget *while_status;
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
66 GntWidget *volume;
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
67 GntWidget *window;
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
68 } SoundPrefDialog;
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
69
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
70 static struct {
18432
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
71 gchar *method;
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
72 gchar *command;
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
73 gboolean conv_focus;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
74 gint while_status;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
75 gint volume;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
76 GntTree *events;
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
77 SoundPrefDialog *dialog;
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
78 } sound_pref_data;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
79
18155
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
80 #define PLAY_SOUND_TIMEOUT 15000
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
81
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
82 static guint mute_login_sounds_timeout = 0;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
83 static gboolean mute_login_sounds = FALSE;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
84
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
85 #ifdef USE_GSTREAMER
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
86 static gboolean gst_init_failed;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
87 #endif /* USE_GSTREAMER */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
88
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
89 static struct finch_sound_event sounds[PURPLE_NUM_SOUNDS] = {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
90 {N_("Buddy logs in"), "login", "login.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
91 {N_("Buddy logs out"), "logout", "logout.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
92 {N_("Message received"), "im_recv", "receive.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
93 {N_("Message received begins conversation"), "first_im_recv", "receive.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
94 {N_("Message sent"), "send_im", "send.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
95 {N_("Person enters chat"), "join_chat", "login.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
96 {N_("Person leaves chat"), "left_chat", "logout.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
97 {N_("You talk in chat"), "send_chat_msg", "send.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
98 {N_("Others talk in chat"), "chat_msg_recv", "receive.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
99 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
100 {NULL, "pounce_default", "alert.wav"},
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
101 {N_("Someone says your screen name in chat"), "nick_said", "alert.wav"}
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
102 };
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
103
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
104 static gboolean
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
105 unmute_login_sounds_cb(gpointer data)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
106 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
107 mute_login_sounds = FALSE;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
108 mute_login_sounds_timeout = 0;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
109 return FALSE;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
110 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
111
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
112 static gboolean
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
113 chat_nick_matches_name(PurpleConversation *conv, const char *aname)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
114 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
115 PurpleConvChat *chat = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
116 char *nick = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
117 char *name = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
118 gboolean ret = FALSE;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
119 chat = purple_conversation_get_chat_data(conv);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
120
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
121 if (chat==NULL)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
122 return ret;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
123
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
124 nick = g_strdup(purple_normalize(conv->account, chat->nick));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
125 name = g_strdup(purple_normalize(conv->account, aname));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
126
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
127 if (g_utf8_collate(nick, name) == 0)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
128 ret = TRUE;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
129
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
130 g_free(nick);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
131 g_free(name);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
132
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
133 return ret;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
134 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
135
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
136 /*
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
137 * play a sound event for a conversation, honoring make_sound flag
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
138 * of conversation and checking for focus if conv_focus pref is set
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
139 */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
140 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
141 play_conv_event(PurpleConversation *conv, PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
142 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
143 /* If we should not play the sound for some reason, then exit early */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
144 if (conv != NULL)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
145 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
146 FinchConv *gntconv;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
147 gboolean has_focus;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
148
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
149 gntconv = FINCH_CONV(conv);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
150
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
151 has_focus = purple_conversation_has_focus(conv);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
152
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
153 if (has_focus && !purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/conv_focus"))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
154 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
155 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
156 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
157 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
158
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
159 purple_sound_play_event(event, conv ? purple_conversation_get_account(conv) : NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
160 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
161
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
162 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
163 buddy_state_cb(PurpleBuddy *buddy, PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
164 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
165 purple_sound_play_event(event, purple_buddy_get_account(buddy));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
166 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
167
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
168 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
169 im_msg_received_cb(PurpleAccount *account, char *sender,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
170 char *message, PurpleConversation *conv,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
171 PurpleMessageFlags flags, PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
172 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
173 if (flags & PURPLE_MESSAGE_DELAYED)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
174 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
175
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
176 if (conv==NULL){
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
177 purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE, account);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
178 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
179 else{
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
180 play_conv_event(conv, event);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
181 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
182 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
183
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
184 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
185 im_msg_sent_cb(PurpleAccount *account, const char *receiver,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
186 const char *message, PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
187 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
188 PurpleConversation *conv = purple_find_conversation_with_account(
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
189 PURPLE_CONV_TYPE_ANY, receiver, account);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
190 play_conv_event(conv, event);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
191 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
192
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
193 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
194 chat_buddy_join_cb(PurpleConversation *conv, const char *name,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
195 PurpleConvChatBuddyFlags flags, gboolean new_arrival,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
196 PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
197 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
198 if (new_arrival && !chat_nick_matches_name(conv, name))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
199 play_conv_event(conv, event);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
200 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
201
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
202 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
203 chat_buddy_left_cb(PurpleConversation *conv, const char *name,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
204 const char *reason, PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
205 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
206 if (!chat_nick_matches_name(conv, name))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
207 play_conv_event(conv, event);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
208 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
209
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
210 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
211 chat_msg_sent_cb(PurpleAccount *account, const char *message,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
212 int id, PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
213 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
214 PurpleConnection *conn = purple_account_get_connection(account);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
215 PurpleConversation *conv = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
216
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
217 if (conn!=NULL)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
218 conv = purple_find_chat(conn,id);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
219
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
220 play_conv_event(conv, event);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
221 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
222
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
223 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
224 chat_msg_received_cb(PurpleAccount *account, char *sender,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
225 char *message, PurpleConversation *conv,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
226 PurpleMessageFlags flags, PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
227 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
228 PurpleConvChat *chat;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
229
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
230 if (flags & PURPLE_MESSAGE_DELAYED)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
231 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
232
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
233 chat = purple_conversation_get_chat_data(conv);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
234 g_return_if_fail(chat != NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
235
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
236 if (purple_conv_chat_is_user_ignored(chat, sender))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
237 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
238
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
239 if (chat_nick_matches_name(conv, sender))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
240 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
241
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
242 if (flags & PURPLE_MESSAGE_NICK || purple_utf8_has_word(message, chat->nick))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
243 play_conv_event(conv, PURPLE_SOUND_CHAT_NICK);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
244 else
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
245 play_conv_event(conv, event);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
246 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
247
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
248 /*
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
249 * We mute sounds for the 10 seconds after you log in so that
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
250 * you don't get flooded with sounds when the blist shows all
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
251 * your buddies logging in.
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
252 */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
253 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
254 account_signon_cb(PurpleConnection *gc, gpointer data)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
255 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
256 if (mute_login_sounds_timeout != 0)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
257 g_source_remove(mute_login_sounds_timeout);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
258 mute_login_sounds = TRUE;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
259 mute_login_sounds_timeout = purple_timeout_add(10000, unmute_login_sounds_cb, NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
260 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
261
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
262 const char *
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
263 finch_sound_get_event_option(PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
264 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
265 if(event >= PURPLE_NUM_SOUNDS)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
266 return 0;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
267
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
268 return sounds[event].pref;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
269 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
270
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
271 const char *
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
272 finch_sound_get_event_label(PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
273 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
274 if(event >= PURPLE_NUM_SOUNDS)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
275 return NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
276
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
277 return sounds[event].label;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
278 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
279
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
280 void *
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
281 finch_sound_get_handle()
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
282 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
283 static int handle;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
284
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
285 return &handle;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
286 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
287
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
288 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
289 finch_sound_init(void)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
290 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
291 void *gnt_sound_handle = finch_sound_get_handle();
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
292 void *blist_handle = purple_blist_get_handle();
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
293 void *conv_handle = purple_conversations_get_handle();
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
294 #ifdef USE_GSTREAMER
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
295 GError *error = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
296 #endif
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
297
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
298 purple_signal_connect(purple_connections_get_handle(), "signed-on",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
299 gnt_sound_handle, PURPLE_CALLBACK(account_signon_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
300 NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
301
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
302 purple_prefs_add_none(FINCH_PREFS_ROOT "/sound");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
303 purple_prefs_add_none(FINCH_PREFS_ROOT "/sound/enabled");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
304 purple_prefs_add_none(FINCH_PREFS_ROOT "/sound/file");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
305 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/login", TRUE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
306 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/login", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
307 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/logout", TRUE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
308 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/logout", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
309 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/im_recv", TRUE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
310 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/im_recv", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
311 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/first_im_recv", FALSE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
312 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/first_im_recv", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
313 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/send_im", TRUE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
314 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/send_im", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
315 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/join_chat", FALSE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
316 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/join_chat", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
317 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/left_chat", FALSE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
318 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/left_chat", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
319 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/send_chat_msg", FALSE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
320 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/send_chat_msg", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
321 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/chat_msg_recv", FALSE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
322 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/chat_msg_recv", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
323 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/nick_said", FALSE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
324 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/nick_said", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
325 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/pounce_default", TRUE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
326 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/pounce_default", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
327 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/conv_focus", TRUE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
328 purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/mute", FALSE);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
329 purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/command", "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
330 purple_prefs_add_string(FINCH_PREFS_ROOT "/sound/method", "automatic");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
331 purple_prefs_add_int(FINCH_PREFS_ROOT "/sound/volume", 50);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
332
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
333 #ifdef USE_GSTREAMER
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
334 purple_debug_info("sound", "Initializing sound output drivers.\n");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
335 if ((gst_init_failed = !gst_init_check(NULL, NULL, &error))) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
336 purple_notify_error(NULL, _("GStreamer Failure"),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
337 _("GStreamer failed to initialize."),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
338 error ? error->message : "");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
339 if (error) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
340 g_error_free(error);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
341 error = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
342 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
343 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
344 #endif /* USE_GSTREAMER */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
345
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
346 purple_signal_connect(blist_handle, "buddy-signed-on",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
347 gnt_sound_handle, PURPLE_CALLBACK(buddy_state_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
348 GINT_TO_POINTER(PURPLE_SOUND_BUDDY_ARRIVE));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
349 purple_signal_connect(blist_handle, "buddy-signed-off",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
350 gnt_sound_handle, PURPLE_CALLBACK(buddy_state_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
351 GINT_TO_POINTER(PURPLE_SOUND_BUDDY_LEAVE));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
352 purple_signal_connect(conv_handle, "received-im-msg",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
353 gnt_sound_handle, PURPLE_CALLBACK(im_msg_received_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
354 GINT_TO_POINTER(PURPLE_SOUND_RECEIVE));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
355 purple_signal_connect(conv_handle, "sent-im-msg",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
356 gnt_sound_handle, PURPLE_CALLBACK(im_msg_sent_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
357 GINT_TO_POINTER(PURPLE_SOUND_SEND));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
358 purple_signal_connect(conv_handle, "chat-buddy-joined",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
359 gnt_sound_handle, PURPLE_CALLBACK(chat_buddy_join_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
360 GINT_TO_POINTER(PURPLE_SOUND_CHAT_JOIN));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
361 purple_signal_connect(conv_handle, "chat-buddy-left",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
362 gnt_sound_handle, PURPLE_CALLBACK(chat_buddy_left_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
363 GINT_TO_POINTER(PURPLE_SOUND_CHAT_LEAVE));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
364 purple_signal_connect(conv_handle, "sent-chat-msg",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
365 gnt_sound_handle, PURPLE_CALLBACK(chat_msg_sent_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
366 GINT_TO_POINTER(PURPLE_SOUND_CHAT_YOU_SAY));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
367 purple_signal_connect(conv_handle, "received-chat-msg",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
368 gnt_sound_handle, PURPLE_CALLBACK(chat_msg_received_cb),
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
369 GINT_TO_POINTER(PURPLE_SOUND_CHAT_SAY));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
370 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
371
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
372 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
373 finch_sound_uninit(void)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
374 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
375 #ifdef USE_GSTREAMER
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
376 if (!gst_init_failed)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
377 gst_deinit();
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
378 #endif
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
379
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
380 purple_signals_disconnect_by_handle(finch_sound_get_handle());
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
381 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
382
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
383 #ifdef USE_GSTREAMER
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
384 static gboolean
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
385 bus_call (GstBus *bus, GstMessage *msg, gpointer data)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
386 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
387 GstElement *play = data;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
388 GError *err = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
389
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
390 switch (GST_MESSAGE_TYPE (msg)) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
391 case GST_MESSAGE_EOS:
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
392 gst_element_set_state(play, GST_STATE_NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
393 gst_object_unref(GST_OBJECT(play));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
394 break;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
395 case GST_MESSAGE_ERROR:
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
396 gst_message_parse_error(msg, &err, NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
397 purple_debug_error("gstreamer", err->message);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
398 g_error_free(err);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
399 break;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
400 case GST_MESSAGE_WARNING:
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
401 gst_message_parse_warning(msg, &err, NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
402 purple_debug_warning("gstreamer", err->message);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
403 g_error_free(err);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
404 break;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
405 default:
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
406 break;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
407 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
408 return TRUE;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
409 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
410 #endif
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
411
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
412 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
413 finch_sound_play_file(const char *filename)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
414 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
415 const char *method;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
416 #ifdef USE_GSTREAMER
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
417 float volume;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
418 char *uri;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
419 GstElement *sink = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
420 GstElement *play = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
421 GstBus *bus = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
422 #endif
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
423 if (purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/mute"))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
424 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
425
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
426 method = purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/method");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
427
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
428 if (!strcmp(method, "none")) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
429 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
430 } else if (!strcmp(method, "beep")) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
431 beep();
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
432 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
433 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
434
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
435 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
436 purple_debug_error("gntsound", "sound file (%s) does not exist.\n", filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
437 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
438 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
439
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
440 #ifndef _WIN32
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
441 if (!strcmp(method, "custom")) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
442 const char *sound_cmd;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
443 char *command;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
444 char *esc_filename;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
445 GError *error = NULL;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
446
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
447 sound_cmd = purple_prefs_get_path(FINCH_PREFS_ROOT "/sound/command");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
448
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
449 if (!sound_cmd || *sound_cmd == '\0') {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
450 purple_debug_error("gntsound",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
451 "'Command' sound method has been chosen, "
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
452 "but no command has been set.");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
453 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
454 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
455
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
456 esc_filename = g_shell_quote(filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
457
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
458 if(strstr(sound_cmd, "%s"))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
459 command = purple_strreplace(sound_cmd, "%s", esc_filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
460 else
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
461 command = g_strdup_printf("%s %s", sound_cmd, esc_filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
462
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
463 if(!g_spawn_command_line_async(command, &error)) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
464 purple_debug_error("gntsound", "sound command could not be launched: %s\n", error->message);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
465 g_error_free(error);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
466 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
467
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
468 g_free(esc_filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
469 g_free(command);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
470 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
471 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
472 #ifdef USE_GSTREAMER
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
473 if (gst_init_failed) /* Perhaps do beep instead? */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
474 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
475 volume = (float)(CLAMP(purple_prefs_get_int(FINCH_PREFS_ROOT "/sound/volume"),0,100)) / 50;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
476 if (!strcmp(method, "automatic")) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
477 if (purple_running_gnome()) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
478 sink = gst_element_factory_make("gconfaudiosink", "sink");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
479 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
480 if (!sink)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
481 sink = gst_element_factory_make("autoaudiosink", "sink");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
482 if (!sink) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
483 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
484 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
485 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
486 } else if (!strcmp(method, "esd")) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
487 sink = gst_element_factory_make("esdsink", "sink");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
488 if (!sink) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
489 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
490 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
491 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
492 } else if (!strcmp(method, "alsa")) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
493 sink = gst_element_factory_make("alsasink", "sink");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
494 if (!sink) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
495 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
496 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
497 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
498 } else {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
499 purple_debug_error("sound", "Unknown sound method '%s'\n", method);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
500 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
501 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
502
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
503 play = gst_element_factory_make("playbin", "play");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
504
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
505 if (play == NULL) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
506 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
507 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
508
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
509 uri = g_strdup_printf("file://%s", filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
510
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
511 g_object_set(G_OBJECT(play), "uri", uri,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
512 "volume", volume,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
513 "audio-sink", sink, NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
514
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
515 bus = gst_pipeline_get_bus(GST_PIPELINE(play));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
516 gst_bus_add_watch(bus, bus_call, play);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
517
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
518 gst_element_set_state(play, GST_STATE_PLAYING);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
519
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
520 gst_object_unref(bus);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
521 g_free(uri);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
522
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
523 #else /* USE_GSTREAMER */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
524 beep();
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
525 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
526 #endif /* USE_GSTREAMER */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
527 #else /* _WIN32 */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
528 purple_debug_info("sound", "Playing %s\n", filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
529
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
530 if (G_WIN32_HAVE_WIDECHAR_API ()) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
531 wchar_t *wc_filename = g_utf8_to_utf16(filename,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
532 -1, NULL, NULL, NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
533 if (!PlaySoundW(wc_filename, NULL, SND_ASYNC | SND_FILENAME))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
534 purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
535 g_free(wc_filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
536 } else {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
537 char *l_filename = g_locale_from_utf8(filename,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
538 -1, NULL, NULL, NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
539 if (!PlaySoundA(l_filename, NULL, SND_ASYNC | SND_FILENAME))
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
540 purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n");
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
541 g_free(l_filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
542 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
543 #endif /* _WIN32 */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
544 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
545
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
546 static void
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
547 finch_sound_play_event(PurpleSoundEventID event)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
548 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
549 char *enable_pref;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
550 char *file_pref;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
551 if ((event == PURPLE_SOUND_BUDDY_ARRIVE) && mute_login_sounds)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
552 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
553
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
554 if (event >= PURPLE_NUM_SOUNDS) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
555 purple_debug_error("sound", "got request for unknown sound: %d\n", event);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
556 return;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
557 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
558
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
559 enable_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s",
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
560 sounds[event].pref);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
561 file_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/file/%s", sounds[event].pref);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
562
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
563 /* check NULL for sounds that don't have an option, ie buddy pounce */
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
564 if (purple_prefs_get_bool(enable_pref)) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
565 char *filename = g_strdup(purple_prefs_get_path(file_pref));
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
566 if(!filename || !strlen(filename)) {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
567 g_free(filename);
18292
Eric Polino <aluink@pidgin.im>
parents: 18155
diff changeset
568 /* XXX Consider creating a constant for "sounds/purple" to be shared with Pidgin */
Eric Polino <aluink@pidgin.im>
parents: 18155
diff changeset
569 filename = g_build_filename(DATADIR, "sounds", "purple", sounds[event].def, NULL);
18155
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
570 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
571
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
572 purple_sound_play_file(filename, NULL);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
573 g_free(filename);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
574 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
575
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
576 g_free(enable_pref);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
577 g_free(file_pref);
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
578 }
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
579
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
580 static void init_pref_data()
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
581 {
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
582 GntTree *events = NULL;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
583
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
584 if(sound_pref_data.method){
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
585 return;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
586 }
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
587
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
588 /* TODO Setup the events tree */
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
589
18432
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
590 sound_pref_data.method = g_strdup(purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/method"));
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
591 sound_pref_data.command = g_strdup(purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/command"));
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
592 sound_pref_data.conv_focus = purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/conv_focus");
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
593 sound_pref_data.while_status = purple_prefs_get_int(FINCH_PREFS_ROOT "/purple/sound/while_status");
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
594 sound_pref_data.volume = CLAMP(purple_prefs_get_int(FINCH_PREFS_ROOT "/sound/volume"),0,100);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
595 sound_pref_data.events = events;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
596
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
597 return;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
598 }
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
599
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
600 static gboolean
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
601 save_cb(GntBindable *data, gpointer *win)
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
602 {
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
603 gnt_widget_destroy(GNT_WIDGET(win));
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
604 return TRUE;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
605 }
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
606
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
607 static gboolean
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
608 cancel_cb(GntBindable *data, gpointer win)
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
609 {
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
610 gnt_widget_destroy(GNT_WIDGET(win));
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
611 return TRUE;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
612 }
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
613
18432
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
614 static void
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
615 release_pref_window(GntBindable *data, gpointer null)
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
616 {
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
617 g_free(sound_pref_data.dialog);
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
618 sound_pref_data.dialog = NULL;
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
619 }
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
620
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
621 void
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
622 finch_sounds_show_all(void)
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
623 {
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
624 GntWidget *box;
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
625 GntWidget *cmbox;
18432
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
626 GntWidget *slider;
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
627 GntWidget *entry;
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
628 GntWidget *chkbox;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
629 GntWidget *button;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
630 GntWidget *label;
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
631 GntWidget *win;
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
632
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
633 if(sound_pref_data.dialog){
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
634 gnt_window_present(sound_pref_data.dialog->window);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
635 return;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
636 }
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
637
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
638 init_pref_data();
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
639
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
640 sound_pref_data.dialog = g_new0(SoundPrefDialog,1);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
641
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
642 sound_pref_data.dialog->window = win = gnt_window_box_new(FALSE,TRUE);
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
643 gnt_box_set_pad(GNT_BOX(win),0);
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
644 gnt_box_set_fill(GNT_BOX(win),FALSE);
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
645 gnt_box_set_toplevel(GNT_BOX(win), TRUE);
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
646 gnt_box_set_title(GNT_BOX(win),_("Sound Preferences"));
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
647 gnt_box_set_fill(GNT_BOX(win),TRUE);
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
648 gnt_box_set_alignment(GNT_BOX(win),GNT_ALIGN_MID);
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
649
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
650 sound_pref_data.dialog->method = cmbox = gnt_combo_box_new();
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
651 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"automatic",_("Automatic"));
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
652 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"alsa","ALSA");
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
653 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"esd","ESD");
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
654 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"beep",_("Console Beep"));
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
655 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"custom",_("Command"));
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
656 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"nosound",_("No Sound"));
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
657 gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),sound_pref_data.method);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
658
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
659 label = gnt_label_new_with_format(_("Sound Method"),GNT_TEXT_FLAG_BOLD);
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
660 gnt_box_add_widget(GNT_BOX(win),label);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
661 box = gnt_hbox_new(TRUE);
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
662 gnt_box_set_fill(GNT_BOX(box),FALSE);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
663 gnt_box_set_pad(GNT_BOX(box),0);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
664 gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Method: ")));
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
665 gnt_box_add_widget(GNT_BOX(box),cmbox);
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
666 gnt_box_add_widget(GNT_BOX(win),box);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
667
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
668 box = gnt_hbox_new(TRUE);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
669 gnt_box_set_pad(GNT_BOX(box),0);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
670 gnt_box_set_fill(GNT_BOX(box),FALSE);
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
671 gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Sound Command\n(%s for filename)")));
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
672 sound_pref_data.dialog->command = entry = gnt_entry_new(sound_pref_data.command);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
673 gnt_box_add_widget(GNT_BOX(box),entry);
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
674 gnt_box_add_widget(GNT_BOX(win),box);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
675
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
676 gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE));
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
677
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
678 gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Options"),GNT_TEXT_FLAG_BOLD));
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
679 sound_pref_data.dialog->conv_focus = chkbox = gnt_check_box_new("Sounds when conversation has focus");
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
680 gnt_check_box_set_checked(GNT_CHECK_BOX(chkbox),sound_pref_data.conv_focus);
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
681 gnt_box_add_widget(GNT_BOX(win),chkbox);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
682
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
683 box = gnt_hbox_new(TRUE);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
684 gnt_box_set_pad(GNT_BOX(box),0);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
685 gnt_box_set_fill(GNT_BOX(box),FALSE);
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
686 gnt_box_add_widget(GNT_BOX(box),gnt_label_new("Enable Sounds:"));
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
687 sound_pref_data.dialog->while_status = cmbox = gnt_combo_box_new();
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
688 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"always","Always");
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
689 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"available","Only when available");
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
690 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"away","Only when not available");
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
691 switch(sound_pref_data.while_status){
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
692 case 1:gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),"available");break;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
693 case 2:gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),"away");break;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
694 default:gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),"always");break;
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
695 }
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
696 gnt_box_add_widget(GNT_BOX(box),cmbox);
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
697 gnt_box_add_widget(GNT_BOX(win),box);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
698
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
699 box = gnt_hbox_new(TRUE);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
700 gnt_box_set_pad(GNT_BOX(box),0);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
701 gnt_box_set_fill(GNT_BOX(box),FALSE);
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
702 gnt_box_add_widget(GNT_BOX(box),gnt_label_new("Volume(0-100):"));
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
703
18432
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
704 sound_pref_data.dialog->volume = slider = gnt_slider_new(FALSE,100,0);
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
705 gnt_slider_set_step(GNT_SLIDER(slider),5);
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
706 label = gnt_label_new("");
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
707 gnt_slider_reflect_label(GNT_SLIDER(slider),GNT_LABEL(label));
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
708 gnt_slider_set_value(GNT_SLIDER(slider),sound_pref_data.volume);
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
709 gnt_box_set_pad(GNT_BOX(box),1);
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
710 gnt_box_add_widget(GNT_BOX(box),slider);
8fd3963b9ce0 Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents: 18296
diff changeset
711 gnt_box_add_widget(GNT_BOX(box),label);
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
712 gnt_box_add_widget(GNT_BOX(win),box);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
713
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
714 gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE));
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
715
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
716 gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Events"),GNT_TEXT_FLAG_BOLD));
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
717 /* Put events tree here */
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
718
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
719 box = gnt_hbox_new(TRUE);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
720 gnt_box_set_pad(GNT_BOX(box),0);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
721 gnt_box_set_fill(GNT_BOX(box),TRUE);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
722 button = gnt_button_new("Save");
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
723 g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(save_cb),NULL);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
724 gnt_box_add_widget(GNT_BOX(box),button);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
725 button = gnt_button_new("Cancel");
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
726 g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(cancel_cb),NULL);
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
727 gnt_box_add_widget(GNT_BOX(box),button);
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
728 gnt_box_add_widget(GNT_BOX(win),box);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
729
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
730
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
731 g_signal_connect(G_OBJECT(win),"destroy",G_CALLBACK(release_pref_window),NULL);
18295
bd26c37841f8 Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents: 18294
diff changeset
732
18296
9461f264ee5f Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents: 18295
diff changeset
733 gnt_widget_show(win);
18294
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
734
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
735 }
8186bc6ffbb4 Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents: 18292
diff changeset
736
18155
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
737 static PurpleSoundUiOps sound_ui_ops =
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
738 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
739 finch_sound_init,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
740 finch_sound_uninit,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
741 finch_sound_play_file,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
742 finch_sound_play_event,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
743 NULL,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
744 NULL,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
745 NULL,
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
746 NULL
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
747 };
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
748
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
749 PurpleSoundUiOps *
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
750 finch_sound_get_ui_ops(void)
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
751 {
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
752 return &sound_ui_ops;
3bb5605ea11e Added sound to Finch.
Eric Polino <aluink@pidgin.im>
parents:
diff changeset
753 }

mercurial