Mercurial > audlegacy
annotate src/audacious/hook.c @ 3865:97b6075a7590
re-added VOLUME and BALANCE text
author | mf0102 <0102@gmx.at> |
---|---|
date | Sun, 28 Oct 2007 21:18:40 +0100 |
parents | f1c756f39e6c |
children |
rev | line source |
---|---|
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
1 /* Audacious |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
2 * Copyright (c) 2006-2007 William Pitcock |
2404 | 3 * |
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3112
diff
changeset
|
6 * the Free Software Foundation; under version 3 of the License. |
2404 | 7 * |
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
11 * GNU General Public License for more details. |
2404 | 12 * |
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
13 * You should have received a copy of the GNU General Public License |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3112
diff
changeset
|
14 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
15 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
16 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
17 * Audacious or using our public API to be a derived work. |
2404 | 18 */ |
19 | |
20 #include <glib.h> | |
21 #include "hook.h" | |
22 | |
23 static GSList *hook_list; | |
24 | |
25 static Hook * | |
26 hook_find(const gchar *name) | |
27 { | |
28 GSList *list; | |
29 | |
30 for (list = hook_list; list != NULL; list = g_slist_next(list)) | |
31 { | |
32 Hook *hook = (Hook *) list->data; | |
33 | |
34 if (!g_ascii_strcasecmp(hook->name, name)) | |
35 return hook; | |
36 } | |
37 | |
38 return NULL; | |
39 } | |
40 | |
41 void | |
42 hook_register(const gchar *name) | |
43 { | |
44 Hook *hook; | |
45 | |
46 g_return_if_fail(name != NULL); | |
47 | |
48 if ((hook = hook_find(name)) != NULL) | |
49 return; | |
50 | |
51 hook = g_new0(Hook, 1); | |
52 hook->name = g_strdup(name); | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
53 hook->items = NULL; |
2404 | 54 |
55 hook_list = g_slist_append(hook_list, hook); | |
56 } | |
57 | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
58 gint |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
59 hook_associate(const gchar *name, HookFunction func, gpointer user_data) |
2404 | 60 { |
61 Hook *hook; | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
62 HookItem *hookitem; |
2404 | 63 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
64 g_return_val_if_fail(name != NULL, -1); |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
65 g_return_val_if_fail(func != NULL, -1); |
2404 | 66 |
67 hook = hook_find(name); | |
68 | |
69 if (hook == NULL) | |
2406
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
70 { |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
71 hook_register(name); |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
72 hook = hook_find(name); |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
73 } |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
74 |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
75 /* this *cant* happen */ |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
76 g_return_val_if_fail(hook != NULL, -1); |
2404 | 77 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
78 hookitem = g_new0(HookItem, 1); |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
79 hookitem->func = func; |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
80 hookitem->user_data = user_data; |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
81 |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
82 hook->items = g_slist_append(hook->items, hookitem); |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
83 return 0; |
2404 | 84 } |
85 | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
86 gint |
2404 | 87 hook_dissociate(const gchar *name, HookFunction func) |
88 { | |
89 Hook *hook; | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
90 GSList *iter; |
2404 | 91 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
92 g_return_val_if_fail(name != NULL, -1); |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
93 g_return_val_if_fail(func != NULL, -1); |
2404 | 94 |
95 hook = hook_find(name); | |
96 | |
97 if (hook == NULL) | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
98 return -1; |
2404 | 99 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
100 iter = hook->items; |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
101 while (iter != NULL) |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
102 { |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
103 HookItem *hookitem = (HookItem*)iter->data; |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
104 if (hookitem->func == func) |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
105 { |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
106 hook->items = g_slist_delete_link(hook->items, iter); |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
107 g_free( hookitem ); |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
108 return 0; |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
109 } |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
110 iter = g_slist_next(iter); |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
111 } |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
112 return -1; |
2404 | 113 } |
114 | |
115 void | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
116 hook_call(const gchar *name, gpointer hook_data) |
2404 | 117 { |
118 Hook *hook; | |
119 GSList *iter; | |
120 | |
121 g_return_if_fail(name != NULL); | |
122 | |
123 hook = hook_find(name); | |
124 | |
125 if (hook == NULL) | |
126 return; | |
127 | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
128 for (iter = hook->items; iter != NULL; iter = g_slist_next(iter)) |
2404 | 129 { |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
130 HookItem *hookitem = (HookItem*)iter->data; |
2404 | 131 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
132 g_return_if_fail(hookitem->func != NULL); |
2404 | 133 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
134 hookitem->func(hook_data, hookitem->user_data); |
2404 | 135 } |
136 } |