4 * Purple 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
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
28 #include "sound-theme-loader.h"
29 #include "theme-manager.h"
31 static PurpleSoundUiOps
*sound_ui_ops
= NULL
;
33 #define STATUS_AVAILABLE 1
36 static time_t last_played
[PURPLE_NUM_SOUNDS
];
39 purple_sound_play_required(const PurpleAccount
*account
)
41 gint pref_status
= purple_prefs_get_int("/purple/sound/while_status");
45 /* Play sounds: Always */
51 PurpleStatus
*status
= purple_account_get_active_status(account
);
53 if (purple_status_is_online(status
))
55 gboolean available
= purple_status_is_available(status
);
56 return (( available
&& pref_status
== STATUS_AVAILABLE
) ||
57 (!available
&& pref_status
== STATUS_AWAY
));
61 /* We get here a couple of ways. Either the request has been OK'ed
62 * by purple_sound_play_event() and we're here because the UI has
63 * called purple_sound_play_file(), or we're here for something
64 * not related to an account (like testing a sound). */
69 purple_sound_play_file(const char *filename
, const PurpleAccount
*account
)
71 if (!purple_sound_play_required(account
))
74 if(sound_ui_ops
&& sound_ui_ops
->play_file
)
75 sound_ui_ops
->play_file(filename
);
79 purple_sound_play_event(PurpleSoundEventID event
, const PurpleAccount
*account
)
81 if (!purple_sound_play_required(account
))
84 if (time(NULL
) - last_played
[event
] < 2)
86 last_played
[event
] = time(NULL
);
88 if(sound_ui_ops
&& sound_ui_ops
->play_event
) {
91 plugin_return
= GPOINTER_TO_INT(purple_signal_emit_return_1(
92 purple_sounds_get_handle(), "playing-sound-event",
98 sound_ui_ops
->play_event(event
);
103 purple_sound_set_ui_ops(PurpleSoundUiOps
*ops
)
105 if(sound_ui_ops
&& sound_ui_ops
->uninit
)
106 sound_ui_ops
->uninit();
110 if(sound_ui_ops
&& sound_ui_ops
->init
)
111 sound_ui_ops
->init();
115 purple_sound_get_ui_ops(void)
123 void *handle
= purple_sounds_get_handle();
125 /**********************************************************************
127 **********************************************************************/
129 purple_signal_register(handle
, "playing-sound-event",
130 purple_marshal_BOOLEAN__INT_POINTER
,
131 purple_value_new(PURPLE_TYPE_BOOLEAN
), 2,
132 purple_value_new(PURPLE_TYPE_INT
),
133 purple_value_new(PURPLE_TYPE_SUBTYPE
,
134 PURPLE_SUBTYPE_ACCOUNT
));
136 purple_prefs_add_none("/purple/sound");
137 purple_prefs_add_int("/purple/sound/while_status", STATUS_AVAILABLE
);
138 memset(last_played
, 0, sizeof(last_played
));
140 purple_theme_manager_register_type(g_object_new(PURPLE_TYPE_SOUND_THEME_LOADER
, "type", "sound", NULL
));
144 purple_sound_uninit()
146 if(sound_ui_ops
&& sound_ui_ops
->uninit
)
147 sound_ui_ops
->uninit();
149 purple_signals_unregister_by_instance(purple_sounds_get_handle());
153 purple_sounds_get_handle()