Mercurial > pidgin.yaz
annotate libgaim/sound.c @ 15204:f814b2df9cce
[gaim-migrate @ 17993]
Blocking on Google Talk. Our Privacy API sucks so bad that even with no prior support for blocking in Jabber, this has no interface changes. If someone wanted to implement the deprecated Jabber privacy lists API, though, that would be ok by me.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 14 Dec 2006 04:56:54 +0000 |
parents | 71149a751439 |
children |
rev | line source |
---|---|
14192 | 1 /* |
2 * gaim | |
3 * | |
4 * Gaim is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
23 #include "internal.h" | |
24 | |
25 #include "blist.h" | |
26 #include "prefs.h" | |
27 #include "sound.h" | |
28 | |
29 static GaimSoundUiOps *sound_ui_ops = NULL; | |
30 | |
14874
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
31 #define STATUS_AVAILABLE 1 |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
32 #define STATUS_AWAY 2 |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
33 |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
34 static gboolean |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
35 gaim_sound_play_required(const GaimAccount *account) |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
36 { |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
37 gint pref_status = gaim_prefs_get_int("/core/sound/while_status"); |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
38 |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
39 if (pref_status == 3) |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
40 { |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
41 /* Play sounds: Always */ |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
42 return TRUE; |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
43 } |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
44 |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
45 if (account != NULL) |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
46 { |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
47 GaimStatus *status = gaim_account_get_active_status(account); |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
48 |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
49 if (gaim_status_is_online(status)) |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
50 { |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
51 gboolean available = gaim_status_is_available(status); |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
52 return (( available && pref_status == STATUS_AVAILABLE) || |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
53 (!available && pref_status == STATUS_AWAY)); |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
54 } |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
55 } |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
56 |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
57 /* We get here a couple of ways. Either the request has been OK'ed |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
58 * by gaim_sound_play_event() and we're here because the UI has |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
59 * called gaim_sound_play_file(), or we're here for something |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
60 * not related to an account (like testing a sound). */ |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
61 return TRUE; |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
62 } |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
63 |
14192 | 64 void |
65 gaim_sound_play_file(const char *filename, const GaimAccount *account) | |
66 { | |
14874
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
67 if (!gaim_sound_play_required(account)) |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
68 return; |
14192 | 69 |
70 if(sound_ui_ops && sound_ui_ops->play_file) | |
71 sound_ui_ops->play_file(filename); | |
72 } | |
73 | |
74 void | |
75 gaim_sound_play_event(GaimSoundEventID event, const GaimAccount *account) | |
76 { | |
14874
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
77 if (!gaim_sound_play_required(account)) |
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
78 return; |
14192 | 79 |
80 if(sound_ui_ops && sound_ui_ops->play_event) { | |
81 int plugin_return; | |
82 | |
83 plugin_return = GPOINTER_TO_INT(gaim_signal_emit_return_1( | |
84 gaim_sounds_get_handle(), "playing-sound-event", | |
85 event, account)); | |
86 | |
87 if (plugin_return) | |
88 return; | |
89 else | |
90 sound_ui_ops->play_event(event); | |
91 } | |
92 } | |
93 | |
94 void | |
95 gaim_sound_set_ui_ops(GaimSoundUiOps *ops) | |
96 { | |
97 if(sound_ui_ops && sound_ui_ops->uninit) | |
98 sound_ui_ops->uninit(); | |
99 | |
100 sound_ui_ops = ops; | |
101 | |
102 if(sound_ui_ops && sound_ui_ops->init) | |
103 sound_ui_ops->init(); | |
104 } | |
105 | |
106 GaimSoundUiOps * | |
107 gaim_sound_get_ui_ops(void) | |
108 { | |
109 return sound_ui_ops; | |
110 } | |
111 | |
112 void | |
113 gaim_sound_init() | |
114 { | |
115 void *handle = gaim_sounds_get_handle(); | |
116 | |
117 /********************************************************************** | |
118 * Register signals | |
119 **********************************************************************/ | |
120 | |
121 gaim_signal_register(handle, "playing-sound-event", | |
122 gaim_marshal_BOOLEAN__INT_POINTER, | |
123 gaim_value_new(GAIM_TYPE_BOOLEAN), 2, | |
124 gaim_value_new(GAIM_TYPE_INT), | |
14618
2f0b4d0de5bb
[gaim-migrate @ 17346]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
125 gaim_value_new(GAIM_TYPE_SUBTYPE, |
2f0b4d0de5bb
[gaim-migrate @ 17346]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
126 GAIM_SUBTYPE_ACCOUNT)); |
14192 | 127 |
128 gaim_prefs_add_none("/core/sound"); | |
14874
71149a751439
[gaim-migrate @ 17643]
Richard Laager <rlaager@wiktel.com>
parents:
14618
diff
changeset
|
129 gaim_prefs_add_int("/core/sound/while_status", STATUS_AVAILABLE); |
14192 | 130 } |
131 | |
132 void | |
133 gaim_sound_uninit() | |
134 { | |
135 if(sound_ui_ops && sound_ui_ops->uninit) | |
136 sound_ui_ops->uninit(); | |
137 | |
138 gaim_signals_unregister_by_instance(gaim_sounds_get_handle()); | |
139 } | |
140 | |
141 void * | |
142 gaim_sounds_get_handle() | |
143 { | |
144 static int handle; | |
145 | |
146 return &handle; | |
147 } |