* Purple is the legal property of its developers, whose names are too numerous
* to list here. Please refer to the COPYRIGHT file distributed with this
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#include "sound-theme-loader.h"
#include "theme-manager.h"
static PurpleSoundUiOps *sound_ui_ops = NULL;
static gint64 last_played[PURPLE_NUM_SOUNDS];
purple_sound_play_required(PurpleAccount *account)
gint pref_status = purple_prefs_get_int("/purple/sound/while_status");
if (pref_status == PURPLE_SOUND_STATUS_ALWAYS)
/* Play sounds: Always */
PurpleStatus *status = purple_account_get_active_status(account);
if (purple_status_is_online(status))
gboolean available = purple_status_is_available(status);
return (( available && pref_status == PURPLE_SOUND_STATUS_AVAILABLE) ||
(!available && pref_status == PURPLE_SOUND_STATUS_AWAY));
/* We get here a couple of ways. Either the request has been OK'ed
* by purple_sound_play_event() and we're here because the UI has
* called purple_sound_play_file(), or we're here for something
* not related to an account (like testing a sound). */
purple_sound_play_file(const char *filename, PurpleAccount *account)
if (!purple_sound_play_required(account))
if(sound_ui_ops && sound_ui_ops->play_file)
sound_ui_ops->play_file(filename);
purple_sound_play_event(PurpleSoundEventID event, PurpleAccount *account)
if (!purple_sound_play_required(account))
g_return_if_fail(event < PURPLE_NUM_SOUNDS);
if (g_get_monotonic_time() - last_played[event] < 2 * G_USEC_PER_SEC)
last_played[event] = g_get_monotonic_time();
if(sound_ui_ops && sound_ui_ops->play_event) {
plugin_return = GPOINTER_TO_INT(purple_signal_emit_return_1(
purple_sounds_get_handle(), "playing-sound-event",
sound_ui_ops->play_event(event);
static PurpleSoundUiOps *
purple_sound_ui_ops_copy(PurpleSoundUiOps *ops)
PurpleSoundUiOps *ops_new;
g_return_val_if_fail(ops != NULL, NULL);
ops_new = g_new(PurpleSoundUiOps, 1);
purple_sound_ui_ops_get_type(void)
type = g_boxed_type_register_static("PurpleSoundUiOps",
(GBoxedCopyFunc)purple_sound_ui_ops_copy,
purple_sound_set_ui_ops(PurpleSoundUiOps *ops)
if(sound_ui_ops && sound_ui_ops->uninit)
if(sound_ui_ops && sound_ui_ops->init)
purple_sound_get_ui_ops(void)
void *handle = purple_sounds_get_handle();
/**********************************************************************
**********************************************************************/
purple_signal_register(handle, "playing-sound-event",
purple_marshal_BOOLEAN__INT_POINTER,
G_TYPE_BOOLEAN, 2, G_TYPE_INT, PURPLE_TYPE_ACCOUNT);
purple_prefs_add_none("/purple/sound");
purple_prefs_add_int("/purple/sound/while_status", PURPLE_SOUND_STATUS_AVAILABLE);
memset(last_played, 0, sizeof(last_played));
purple_theme_manager_register_type(g_object_new(PURPLE_TYPE_SOUND_THEME_LOADER, "type", "sound", NULL));
if(sound_ui_ops && sound_ui_ops->uninit)
purple_signals_unregister_by_instance(purple_sounds_get_handle());
purple_sounds_get_handle()