annotate src/gtksound.c @ 5697:fc659d75fcf7

[gaim-migrate @ 6118] Several fixes. Checks for empty strings, and the buddy icon gets set now. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 03 Jun 2003 09:03:40 +0000
parents b61520e71679
children 5e93fc46d1af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5684
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * gaim
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 *
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 *
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 *
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 *
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include <config.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #endif
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #ifdef HAVE_ENDIAN_H
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 #include <endian.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #endif
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 #include <stdio.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 #include <string.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 #include <glib.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 #ifndef _WIN32
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 #include <unistd.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 #else
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 #include <windows.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 #include <mmsystem.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 #endif
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 #ifdef USE_AO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 #include <ao/ao.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44 #include <audiofile.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 #endif /* USE_AO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 #ifdef USE_NAS_AUDIO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48 #include <audio/audiolib.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 #include <audio/soundlib.h>
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 #endif /* USE_NAS_AUDIO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 #include "gaim.h" /* for gettext stuff */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 #include "sound.h"
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 #include "gtksound.h"
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 #include "prefs.h"
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 #ifdef _WIN32
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 #include "win32dep.h"
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 #endif
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 struct gaim_sound_event {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 char *label;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64 char *pref;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 char *def;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 };
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 static gboolean mute_login_sounds = FALSE;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 static gboolean mute_sounds = FALSE;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 static char *sound_cmd = NULL;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74 static struct gaim_sound_event sounds[GAIM_NUM_SOUNDS] = {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 {N_("Buddy logs in"), "login", "arrive.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76 {N_("Buddy logs out"), "logout", "leave.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 {N_("Message received"), "im_recv", "receive.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 {N_("Message received begins conversation"), "first_im_recv", "receive.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79 {N_("Message sent"), "send_im", "send.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 {N_("Person enters chat"), "join_chat", "arrive.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 {N_("Person leaves chat"), "left_chat", "leave.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 {N_("You talk in chat"), "send_chat_msg", "send.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 {N_("Others talk in chat"), "chat_msg_recv", "receive.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 {NULL, "pounce_default", "redalert.wav"},
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 {N_("Someone says your name in chat"), "nick_said", "redalert.wav"}
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 };
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 #ifdef USE_AO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 static int ao_driver = -1;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 #endif /* USE_AO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 static void __pref_sound_method_changed(const char *name, GaimPrefType type,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94 gpointer val, gpointer data);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96 static void gaim_gtk_sound_init(void)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 gaim_prefs_add_none("/gaim/gtk/sound");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 gaim_prefs_add_none("/gaim/gtk/sound/enabled");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 gaim_prefs_add_none("/gaim/gtk/sound/file");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/login", TRUE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 gaim_prefs_add_string("/gaim/gtk/sound/file/login", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/logout", TRUE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 gaim_prefs_add_string("/gaim/gtk/sound/file/logout", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/im_recv", TRUE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 gaim_prefs_add_string("/gaim/gtk/sound/file/im_recv", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/first_im_recv", FALSE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 gaim_prefs_add_string("/gaim/gtk/sound/file/first_im_recv", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/send_im", TRUE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 gaim_prefs_add_string("/gaim/gtk/sound/file/send_im", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/join_chat", FALSE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112 gaim_prefs_add_string("/gaim/gtk/sound/file/join_chat", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/left_chat", FALSE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114 gaim_prefs_add_string("/gaim/gtk/sound/file/left_chat", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/send_chat_msg", FALSE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116 gaim_prefs_add_string("/gaim/gtk/sound/file/send_chat_msg", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/chat_msg_recv", FALSE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 gaim_prefs_add_string("/gaim/gtk/sound/file/chat_msg_recv", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/nick_said", FALSE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 gaim_prefs_add_string("/gaim/gtk/sound/file/nick_said", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 gaim_prefs_add_bool("/gaim/gtk/sound/silent_signon", TRUE);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 gaim_prefs_add_string("/gaim/gtk/sound/command", "");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 gaim_prefs_add_string("/gaim/gtk/sound/method", "automatic");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125 #ifdef USE_AO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 gaim_debug(GAIM_DEBUG_INFO, "sound",
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 "Initializing sound output drivers.\n");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128 ao_initialize();
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 #endif /* USE_AO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 gaim_prefs_connect_callback("/gaim/gtk/sound/method",
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 __pref_sound_method_changed, NULL);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
133 gaim_prefs_trigger_callback("/gaim/gtk/sound/method");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 static void gaim_gtk_sound_shutdown(void)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139 #ifdef USE_AO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140 ao_shutdown();
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 #endif
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 static void gaim_gtk_sound_play_file(const char *filename)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 const char *method;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 #if defined(USE_NAS_AUDIO) || defined(USE_AO)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 pid_t pid;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 #ifdef USE_AO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 AFfilehandle file;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 #endif
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152 #endif
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 if (mute_sounds)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157 method = gaim_prefs_get_string("/gaim/gtk/sound/method");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 if (!strcmp(method, "beep")) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 gdk_beep();
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 char *tmp = g_strdup_printf(_("Unable to play sound because the chosen file (%s) does not exist."), filename);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 gaim_notify_error(NULL, NULL, tmp, NULL);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167 g_free(tmp);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171 #ifndef _WIN32
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
172 if (!strcmp(method, "custom")) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
173 const char *sound_cmd;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
174 char *command;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 GError *error = NULL;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
177 sound_cmd = gaim_prefs_get_string("/gaim/gtk/sound/command");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
178
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
179 if (!sound_cmd || *sound_cmd == '\0') {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
180 gaim_notify_error(NULL, NULL,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
181 _("Unable to play sound because the "
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
182 "'Command' sound method has been chosen, "
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
183 "but no command has been set."), NULL);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
185 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
187 command = g_strdup_printf(sound_cmd, filename);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
188
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
189 if(!g_spawn_command_line_async(command, &error)) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
190 char *tmp = g_strdup_printf(_("Unable to play sound because the configured sound command could not be launched: %s"), error->message);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191 gaim_notify_error(NULL, NULL, tmp, NULL);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
192 g_free(tmp);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
193 g_error_free(error);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
194 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
196 g_free(command);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199 #if defined(USE_NAS_AUDIO) || defined(USE_AO)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 pid = fork();
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 if (pid < 0)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
203 else if (pid == 0) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204 #ifdef USE_NAS_AUDIO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205 if (!strcmp(method, "nas")) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206 if (play_file_nas(filename))
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 _exit(0);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 #endif /* USE_NAS_AUDIO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 #ifdef USE_AO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 file = afOpenFile(filename, "rb", NULL);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 if(file) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 ao_device *device;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 ao_sample_format format;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 int in_fmt;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217 int bytes_per_frame;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 format.rate = afGetRate(file, AF_DEFAULT_TRACK);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 format.channels = afGetChannels(file, AF_DEFAULT_TRACK);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 afGetSampleFormat(file, AF_DEFAULT_TRACK, &in_fmt,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 &format.bits);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224 /* XXX: libao doesn't seem to like 8-bit sounds, so we'll
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225 * let libaudiofile make them a bit better for us */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226 if(format.bits == 8)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227 format.bits = 16;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229 afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230 AF_SAMPFMT_TWOSCOMP, format.bits);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 #if __BYTE_ORDER == __BIG_ENDIAN
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 format.byte_format = AO_FMT_BIG;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234 afSetVirtualByteOrder(file, AF_DEFAULT_TRACK,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235 AF_BYTEORDER_BIGENDIAN);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 #elif __BYTE_ORDER == __LITTLE_ENDIAN
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 format.byte_format = AO_FMT_LITTLE;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 afSetVirtualByteOrder(file, AF_DEFAULT_TRACK,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 AF_BYTEORDER_LITTLEENDIAN);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 #endif
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 bytes_per_frame = format.bits * format.channels / 8;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 device = ao_open_live(ao_driver, &format, NULL);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 if(device) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 int frames_read;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248 char buf[4096];
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 int buf_frames = sizeof(buf) / bytes_per_frame;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 while((frames_read = afReadFrames(file, AF_DEFAULT_TRACK,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 buf, buf_frames))) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 if(!ao_play(device, buf, frames_read * bytes_per_frame))
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 break;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 ao_close(device);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 afCloseFile(file);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 ao_shutdown();
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261 #endif /* USE_AO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 _exit(0);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 #else /* USE_NAS_AUDIO || USE_AO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265 gdk_beep();
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267 #endif /* USE_NAS_AUDIO || USE_AO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 #else /* _WIN32 */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 gaim_debug(GAIM_DEBUG_INFO, "sound", "Playing %s\n", filename);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME))
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 gaim_debug(GAIM_DEBUG_ERROR, "sound", "Error playing sound.\n");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273 #endif /* _WIN32 */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 static void gaim_gtk_sound_play_event(GaimSoundEventID event)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 char *enable_pref;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 char *file_pref;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281 if ((event == GAIM_SOUND_BUDDY_ARRIVE) && mute_login_sounds)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
282 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
284 if (event >= GAIM_NUM_SOUNDS) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285 gaim_debug(GAIM_DEBUG_MISC, "sound",
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 "got request for unknown sound: %d\n", event);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
287 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
290 enable_pref = g_strdup_printf("/gaim/gtk/sound/enabled/%s",
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291 sounds[event].pref);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292 file_pref = g_strdup_printf("/gaim/gtk/sound/file/%s", sounds[event].pref);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294 /* check NULL for sounds that don't have an option, ie buddy pounce */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
295 if (gaim_prefs_get_bool(enable_pref)) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296 char *filename = g_strdup(gaim_prefs_get_string(file_pref));
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297 if(!filename || !strlen(filename)) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298 if(filename) g_free(filename);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 filename = g_build_filename(DATADIR, "sounds", "gaim", sounds[event].def, NULL);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
302 gaim_sound_play_file(filename);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303 g_free(filename);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
304 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306 g_free(enable_pref);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307 g_free(file_pref);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310 static GaimSoundUiOps sound_ui_ops =
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
311 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
312 gaim_gtk_sound_init,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 gaim_gtk_sound_shutdown,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314 gaim_gtk_sound_play_file,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 gaim_gtk_sound_play_event
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316 };
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
317
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
318 GaimSoundUiOps *gaim_get_gtk_sound_ui_ops(void)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320 return &sound_ui_ops;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
323
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324 static void __pref_sound_method_changed(const char *name, GaimPrefType type,
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325 gpointer val, gpointer data) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326 if(type != GAIM_PREF_STRING || strcmp(name, "/gaim/gtk/sound/method"))
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 return;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328 #ifdef USE_AO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329 ao_driver = -1;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
331 if(!strcmp(val, "esd"))
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332 ao_driver = ao_driver_id("esd");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 else if(!strcmp(val, "arts"))
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
334 ao_driver = ao_driver_id("arts");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335 else if(!strcmp(val, "automatic"))
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336 ao_driver = ao_default_driver_id();
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 if(ao_driver != -1) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339 ao_info *info = ao_driver_info(ao_driver);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 gaim_debug(GAIM_DEBUG_INFO, "sound",
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 "Sound output driver loaded: %s\n", info->name);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343 #endif /* USE_AO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344 #ifdef USE_NAS
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345 if (!strcmp(val, "nas"))
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346 gaim_debug(GAIM_DEBUG_INFO, "sound",
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347 "Sound output driver loaded: NAS output\n");
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348 #endif /* USE_NAS */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
349 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
350
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
351 #ifdef USE_NAS_AUDIO
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
352 static gboolean play_file_nas(const char *filename)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
353 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
354 AuServer *nas_serv;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
355 gboolean ret = FALSE;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
356
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
357 if((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
358 ret = AuSoundPlaySynchronousFromFile(nas_serv, filename, 100);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
359 AuCloseServer(nas_serv);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
360 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
361
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
362 return ret;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
363 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
364
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
365 #endif /* USE_NAS_AUDIO */
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
366
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
367 void gaim_gtk_sound_set_mute(gboolean mute)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
368 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
369 mute_sounds = mute;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
370 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
371
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
372 gboolean gaim_gtk_sound_get_mute()
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
373 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
374 return mute_sounds;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
375 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
376
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
377 void gaim_gtk_sound_set_login_mute(gboolean mute)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
378 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
379 mute_login_sounds = mute;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
380 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
381
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
382 const char *gaim_gtk_sound_get_event_option(GaimSoundEventID event)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
383 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
384 if(event >= GAIM_NUM_SOUNDS)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
385 return 0;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
386
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
387 return sounds[event].pref;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
388 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
389
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
390 char *gaim_gtk_sound_get_event_label(GaimSoundEventID event)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
391 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
392 if(event >= GAIM_NUM_SOUNDS)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
393 return NULL;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
394
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
395 return sounds[event].label;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
396 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
397
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
398
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
399 void gaim_sound_set_command(const char *cmd)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
400 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
401 if(sound_cmd)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
402 g_free(sound_cmd);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
403 if(strlen(cmd) > 0)
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
404 sound_cmd = g_strdup(cmd);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
405 else
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
406 sound_cmd = NULL;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
407 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
408
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
409 char *gaim_sound_get_command()
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
410 {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
411 return sound_cmd;
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
412 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
413