# HG changeset patch # User giacomo # Date 1170296495 28800 # Node ID b7f77224ea0390bc7be55d8c5ea318c11a825843 # Parent 63115d6e8ba8ded755af51d540efcad0cc38dd9e [svn] - now it's possible to pass user_data along with the hook function in hook_associate diff -r 63115d6e8ba8 -r b7f77224ea03 ChangeLog --- a/ChangeLog Wed Jan 31 16:47:18 2007 -0800 +++ b/ChangeLog Wed Jan 31 18:21:35 2007 -0800 @@ -1,3 +1,11 @@ +2007-02-01 00:47:18 +0000 Troels Bang Jensen + revision [3922] + - Make the voiceprint use the skin's foreground and background color for the gradient in 'normal' mode + + trunk/src/audacious/widgets/vis.c | 112 ++++++++++++++++++++++---------------- + 1 file changed, 66 insertions(+), 46 deletions(-) + + 2007-01-31 16:29:07 +0000 William Pitcock revision [3920] - update-po diff -r 63115d6e8ba8 -r b7f77224ea03 src/audacious/hook.c --- a/src/audacious/hook.c Wed Jan 31 16:47:18 2007 -0800 +++ b/src/audacious/hook.c Wed Jan 31 18:21:35 2007 -0800 @@ -48,17 +48,19 @@ hook = g_new0(Hook, 1); hook->name = g_strdup(name); + hook->items = NULL; hook_list = g_slist_append(hook_list, hook); } -void -hook_associate(const gchar *name, HookFunction func) +gint +hook_associate(const gchar *name, HookFunction func, gpointer user_data) { Hook *hook; + HookItem *hookitem; - g_return_if_fail(name != NULL); - g_return_if_fail(func != NULL); + g_return_val_if_fail(name != NULL, -1); + g_return_val_if_fail(func != NULL, -1); hook = hook_find(name); @@ -69,29 +71,47 @@ } /* this *cant* happen */ - g_return_if_fail(hook != NULL); + g_return_val_if_fail(hook != NULL, -1); - hook->funcs = g_slist_append(hook->funcs, func); + hookitem = g_new0(HookItem, 1); + hookitem->func = func; + hookitem->user_data = user_data; + + hook->items = g_slist_append(hook->items, hookitem); + return 0; } -void +gint hook_dissociate(const gchar *name, HookFunction func) { Hook *hook; + GSList *iter; - g_return_if_fail(name != NULL); - g_return_if_fail(func != NULL); + g_return_val_if_fail(name != NULL, -1); + g_return_val_if_fail(func != NULL, -1); hook = hook_find(name); if (hook == NULL) - return; + return -1; - hook->funcs = g_slist_remove(hook->funcs, func); + iter = hook->items; + while (iter != NULL) + { + HookItem *hookitem = (HookItem*)iter->data; + if (hookitem->func == func) + { + hook->items = g_slist_delete_link(hook->items, iter); + g_free( hookitem ); + return 0; + } + iter = g_slist_next(iter); + } + return -1; } void -hook_call(const gchar *name, gpointer user_data) +hook_call(const gchar *name, gpointer hook_data) { Hook *hook; GSList *iter; @@ -103,12 +123,12 @@ if (hook == NULL) return; - for (iter = hook->funcs; iter != NULL; iter = g_slist_next(iter)) + for (iter = hook->items; iter != NULL; iter = g_slist_next(iter)) { - HookFunction func = (HookFunction) iter->data; + HookItem *hookitem = (HookItem*)iter->data; - g_return_if_fail(func != NULL); + g_return_if_fail(hookitem->func != NULL); - func(user_data); + hookitem->func(hook_data, hookitem->user_data); } } diff -r 63115d6e8ba8 -r b7f77224ea03 src/audacious/hook.h --- a/src/audacious/hook.h Wed Jan 31 16:47:18 2007 -0800 +++ b/src/audacious/hook.h Wed Jan 31 18:21:35 2007 -0800 @@ -18,16 +18,23 @@ #ifndef __AUDACIOUS_HOOK_H__ #define __AUDACIOUS_HOOK_H__ -typedef void (*HookFunction)(gpointer user_data); +#include + +typedef void (*HookFunction)(gpointer hook_data, gpointer user_data); + +typedef struct { + HookFunction func; + gpointer user_data; +} HookItem; typedef struct { const gchar *name; - GSList *funcs; + GSList *items; } Hook; void hook_register(const gchar *name); -void hook_associate(const gchar *name, HookFunction func); -void hook_dissociate(const gchar *name, HookFunction func); -void hook_call(const gchar *name, gpointer user_data); +gint hook_associate(const gchar *name, HookFunction func, gpointer user_data); +gint hook_dissociate(const gchar *name, HookFunction func); +void hook_call(const gchar *name, gpointer hook_data); #endif