Sat, 22 Mar 2008 09:40:38 +0000
Add log-handlers for farsight foo.
| 1 | 1 | /* |
| 15884 | 2 | * purple |
| 1 | 3 | * |
| 15884 | 4 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 6 | * source distribution. | |
| 1 | 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16860
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 1 | 21 | * |
| 22 | */ | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
23 | #include "internal.h" |
| 3630 | 24 | |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
25 | #include "blist.h" |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
26 | #include "prefs.h" |
| 4561 | 27 | #include "sound.h" |
| 1 | 28 | |
| 15884 | 29 | static PurpleSoundUiOps *sound_ui_ops = NULL; |
| 3319 | 30 | |
| 14936 | 31 | #define STATUS_AVAILABLE 1 |
| 32 | #define STATUS_AWAY 2 | |
| 33 | ||
|
16860
e4359f0477c8
Don't play the same sound twice within 2 seconds. Maybe this will fix Luke's gst problems. It fixes #140 in either case
Sean Egan <seanegan@pidgin.im>
parents:
16478
diff
changeset
|
34 | static time_t last_played[PURPLE_NUM_SOUNDS]; |
|
e4359f0477c8
Don't play the same sound twice within 2 seconds. Maybe this will fix Luke's gst problems. It fixes #140 in either case
Sean Egan <seanegan@pidgin.im>
parents:
16478
diff
changeset
|
35 | |
| 14936 | 36 | static gboolean |
| 15884 | 37 | purple_sound_play_required(const PurpleAccount *account) |
| 14936 | 38 | { |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
39 | gint pref_status = purple_prefs_get_int("/purple/sound/while_status"); |
| 14936 | 40 | |
| 41 | if (pref_status == 3) | |
| 42 | { | |
| 43 | /* Play sounds: Always */ | |
| 44 | return TRUE; | |
| 45 | } | |
| 46 | ||
| 47 | if (account != NULL) | |
| 48 | { | |
| 15884 | 49 | PurpleStatus *status = purple_account_get_active_status(account); |
| 14936 | 50 | |
| 15884 | 51 | if (purple_status_is_online(status)) |
| 14936 | 52 | { |
| 15884 | 53 | gboolean available = purple_status_is_available(status); |
| 14936 | 54 | return (( available && pref_status == STATUS_AVAILABLE) || |
| 55 | (!available && pref_status == STATUS_AWAY)); | |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | /* We get here a couple of ways. Either the request has been OK'ed | |
| 15884 | 60 | * by purple_sound_play_event() and we're here because the UI has |
| 61 | * called purple_sound_play_file(), or we're here for something | |
| 14936 | 62 | * not related to an account (like testing a sound). */ |
| 63 | return TRUE; | |
| 64 | } | |
| 65 | ||
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
66 | void |
| 15884 | 67 | purple_sound_play_file(const char *filename, const PurpleAccount *account) |
| 5684 | 68 | { |
| 15884 | 69 | if (!purple_sound_play_required(account)) |
| 14936 | 70 | return; |
|
4430
95df701e8cdf
[gaim-migrate @ 4705]
Robert McQueen <robot101@debian.org>
parents:
4429
diff
changeset
|
71 | |
| 5684 | 72 | if(sound_ui_ops && sound_ui_ops->play_file) |
| 73 | sound_ui_ops->play_file(filename); | |
|
1006
fb2f2a403962
[gaim-migrate @ 1016]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
899
diff
changeset
|
74 | } |
|
fb2f2a403962
[gaim-migrate @ 1016]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
899
diff
changeset
|
75 | |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
76 | void |
| 15884 | 77 | purple_sound_play_event(PurpleSoundEventID event, const PurpleAccount *account) |
| 1 | 78 | { |
| 15884 | 79 | if (!purple_sound_play_required(account)) |
| 14936 | 80 | return; |
| 4561 | 81 | |
|
16860
e4359f0477c8
Don't play the same sound twice within 2 seconds. Maybe this will fix Luke's gst problems. It fixes #140 in either case
Sean Egan <seanegan@pidgin.im>
parents:
16478
diff
changeset
|
82 | if (time(NULL) - last_played[event] < 2) |
|
e4359f0477c8
Don't play the same sound twice within 2 seconds. Maybe this will fix Luke's gst problems. It fixes #140 in either case
Sean Egan <seanegan@pidgin.im>
parents:
16478
diff
changeset
|
83 | return; |
|
e4359f0477c8
Don't play the same sound twice within 2 seconds. Maybe this will fix Luke's gst problems. It fixes #140 in either case
Sean Egan <seanegan@pidgin.im>
parents:
16478
diff
changeset
|
84 | last_played[event] = time(NULL); |
|
e4359f0477c8
Don't play the same sound twice within 2 seconds. Maybe this will fix Luke's gst problems. It fixes #140 in either case
Sean Egan <seanegan@pidgin.im>
parents:
16478
diff
changeset
|
85 | |
| 12291 | 86 | if(sound_ui_ops && sound_ui_ops->play_event) { |
| 87 | int plugin_return; | |
| 88 | ||
| 15884 | 89 | plugin_return = GPOINTER_TO_INT(purple_signal_emit_return_1( |
| 90 | purple_sounds_get_handle(), "playing-sound-event", | |
| 12291 | 91 | event, account)); |
| 92 | ||
| 93 | if (plugin_return) | |
| 94 | return; | |
| 95 | else | |
| 96 | sound_ui_ops->play_event(event); | |
| 97 | } | |
| 4561 | 98 | } |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
99 | |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
100 | void |
| 15884 | 101 | purple_sound_set_ui_ops(PurpleSoundUiOps *ops) |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
102 | { |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
103 | if(sound_ui_ops && sound_ui_ops->uninit) |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
104 | sound_ui_ops->uninit(); |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
105 | |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
106 | sound_ui_ops = ops; |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
107 | |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
108 | if(sound_ui_ops && sound_ui_ops->init) |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
109 | sound_ui_ops->init(); |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
110 | } |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
111 | |
| 15884 | 112 | PurpleSoundUiOps * |
| 113 | purple_sound_get_ui_ops(void) | |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
114 | { |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
115 | return sound_ui_ops; |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
116 | } |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
117 | |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
118 | void |
| 15884 | 119 | purple_sound_init() |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
120 | { |
| 15884 | 121 | void *handle = purple_sounds_get_handle(); |
| 12291 | 122 | |
| 123 | /********************************************************************** | |
| 124 | * Register signals | |
| 125 | **********************************************************************/ | |
| 126 | ||
| 15884 | 127 | purple_signal_register(handle, "playing-sound-event", |
| 128 | purple_marshal_BOOLEAN__INT_POINTER, | |
| 129 | purple_value_new(PURPLE_TYPE_BOOLEAN), 2, | |
| 130 | purple_value_new(PURPLE_TYPE_INT), | |
| 131 | purple_value_new(PURPLE_TYPE_SUBTYPE, | |
| 132 | PURPLE_SUBTYPE_ACCOUNT)); | |
| 12291 | 133 | |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
134 | purple_prefs_add_none("/purple/sound"); |
|
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
135 | purple_prefs_add_int("/purple/sound/while_status", STATUS_AVAILABLE); |
|
16860
e4359f0477c8
Don't play the same sound twice within 2 seconds. Maybe this will fix Luke's gst problems. It fixes #140 in either case
Sean Egan <seanegan@pidgin.im>
parents:
16478
diff
changeset
|
136 | memset(last_played, 0, sizeof(last_played)); |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
137 | } |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
138 | |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
139 | void |
| 15884 | 140 | purple_sound_uninit() |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
141 | { |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
142 | if(sound_ui_ops && sound_ui_ops->uninit) |
|
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
143 | sound_ui_ops->uninit(); |
| 12291 | 144 | |
| 15884 | 145 | purple_signals_unregister_by_instance(purple_sounds_get_handle()); |
|
10322
06e23196da4b
[gaim-migrate @ 11529]
Mark Doliner <markdoliner@pidgin.im>
parents:
9993
diff
changeset
|
146 | } |
| 12291 | 147 | |
| 148 | void * | |
| 15884 | 149 | purple_sounds_get_handle() |
| 12291 | 150 | { |
| 151 | static int handle; | |
| 152 | ||
| 153 | return &handle; | |
| 154 | } |