changeset 2457:b7f77224ea03 trunk

[svn] - now it's possible to pass user_data along with the hook function in hook_associate
author giacomo
date Wed, 31 Jan 2007 18:21:35 -0800
parents 63115d6e8ba8
children 2be58fc9e646
files ChangeLog src/audacious/hook.c src/audacious/hook.h
diffstat 3 files changed, 56 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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 <marvin@fnuck.dk>
+  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 <nenolod@sacredspiral.co.uk>
   revision [3920]
   - update-po
--- 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);
     }
 }
--- 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 <glib.h>
+
+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