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
25 #include "buddylist.h"
28 #include "sound-theme-loader.h"
29 #include "theme-manager.h"
31 static PurpleSoundUiOps
*sound_ui_ops
= NULL
;
32 static time_t last_played
[PURPLE_NUM_SOUNDS
];
35 purple_sound_play_required(const PurpleAccount
*account
)
37 gint pref_status
= purple_prefs_get_int("/purple/sound/while_status");
39 if (pref_status
== PURPLE_SOUND_STATUS_ALWAYS
)
41 /* Play sounds: Always */
47 PurpleStatus
*status
= purple_account_get_active_status(account
);
49 if (purple_status_is_online(status
))
51 gboolean available
= purple_status_is_available(status
);
52 return (( available
&& pref_status
== PURPLE_SOUND_STATUS_AVAILABLE
) ||
53 (!available
&& pref_status
== PURPLE_SOUND_STATUS_AWAY
));
57 /* We get here a couple of ways. Either the request has been OK'ed
58 * by purple_sound_play_event() and we're here because the UI has
59 * called purple_sound_play_file(), or we're here for something
60 * not related to an account (like testing a sound). */
65 purple_sound_play_file(const char *filename
, const PurpleAccount
*account
)
67 if (!purple_sound_play_required(account
))
70 if(sound_ui_ops
&& sound_ui_ops
->play_file
)
71 sound_ui_ops
->play_file(filename
);
75 purple_sound_play_event(PurpleSoundEventID event
, const PurpleAccount
*account
)
77 if (!purple_sound_play_required(account
))
80 g_return_if_fail(event
< PURPLE_NUM_SOUNDS
);
82 if (time(NULL
) - last_played
[event
] < 2)
84 last_played
[event
] = time(NULL
);
86 if(sound_ui_ops
&& sound_ui_ops
->play_event
) {
89 plugin_return
= GPOINTER_TO_INT(purple_signal_emit_return_1(
90 purple_sounds_get_handle(), "playing-sound-event",
96 sound_ui_ops
->play_event(event
);
100 static PurpleSoundUiOps
*
101 purple_sound_ui_ops_copy(PurpleSoundUiOps
*ops
)
103 PurpleSoundUiOps
*ops_new
;
105 g_return_val_if_fail(ops
!= NULL
, NULL
);
107 ops_new
= g_new(PurpleSoundUiOps
, 1);
114 purple_sound_ui_ops_get_type(void)
116 static GType type
= 0;
119 type
= g_boxed_type_register_static("PurpleSoundUiOps",
120 (GBoxedCopyFunc
)purple_sound_ui_ops_copy
,
121 (GBoxedFreeFunc
)g_free
);
128 purple_sound_set_ui_ops(PurpleSoundUiOps
*ops
)
130 if(sound_ui_ops
&& sound_ui_ops
->uninit
)
131 sound_ui_ops
->uninit();
135 if(sound_ui_ops
&& sound_ui_ops
->init
)
136 sound_ui_ops
->init();
140 purple_sound_get_ui_ops(void)
148 void *handle
= purple_sounds_get_handle();
150 /**********************************************************************
152 **********************************************************************/
154 purple_signal_register(handle
, "playing-sound-event",
155 purple_marshal_BOOLEAN__INT_POINTER
,
156 G_TYPE_BOOLEAN
, 2, G_TYPE_INT
, PURPLE_TYPE_ACCOUNT
);
158 purple_prefs_add_none("/purple/sound");
159 purple_prefs_add_int("/purple/sound/while_status", PURPLE_SOUND_STATUS_AVAILABLE
);
160 memset(last_played
, 0, sizeof(last_played
));
162 purple_theme_manager_register_type(g_object_new(PURPLE_TYPE_SOUND_THEME_LOADER
, "type", "sound", NULL
));
166 purple_sound_uninit()
168 if(sound_ui_ops
&& sound_ui_ops
->uninit
)
169 sound_ui_ops
->uninit();
171 purple_signals_unregister_by_instance(purple_sounds_get_handle());
175 purple_sounds_get_handle()