Mercurial > audlegacy
annotate src/audlegacy/hook.c @ 4872:9501ad351ac0
When deleting last playlist, set title to "Untitled Playlist", as for a new one.
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Sun, 26 Apr 2009 04:34:53 -0400 |
parents | c97b4291ec8b |
children | 4168232afc19 |
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 | |
4848
b2ee645f3e59
Hook up the equalizer (bug #24)
John Lindgren <john.lindgren@tds.net>
parents:
4811
diff
changeset
|
20 #include <stdio.h> |
2404 | 21 #include <glib.h> |
22 #include "hook.h" | |
23 | |
24 static GSList *hook_list; | |
25 | |
26 static Hook * | |
27 hook_find(const gchar *name) | |
28 { | |
29 GSList *list; | |
30 | |
31 for (list = hook_list; list != NULL; list = g_slist_next(list)) | |
32 { | |
33 Hook *hook = (Hook *) list->data; | |
34 | |
35 if (!g_ascii_strcasecmp(hook->name, name)) | |
36 return hook; | |
37 } | |
38 | |
39 return NULL; | |
40 } | |
41 | |
42 void | |
43 hook_register(const gchar *name) | |
44 { | |
45 Hook *hook; | |
46 | |
47 g_return_if_fail(name != NULL); | |
48 | |
4866
c97b4291ec8b
We do not care about hook_find(name) past the if-statement. Do not assign to a variable.
Tony Vroon <chainsaw@gentoo.org>
parents:
4848
diff
changeset
|
49 if (hook_find(name) != NULL) |
2404 | 50 return; |
51 | |
52 hook = g_new0(Hook, 1); | |
53 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
|
54 hook->items = NULL; |
2404 | 55 |
56 hook_list = g_slist_append(hook_list, hook); | |
57 } | |
58 | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
59 gint |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
60 hook_associate(const gchar *name, HookFunction func, gpointer user_data) |
2404 | 61 { |
62 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
|
63 HookItem *hookitem; |
2404 | 64 |
2457
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(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
|
66 g_return_val_if_fail(func != NULL, -1); |
2404 | 67 |
68 hook = hook_find(name); | |
69 | |
70 if (hook == NULL) | |
2406
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
71 { |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
72 hook_register(name); |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
73 hook = hook_find(name); |
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 |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
76 /* 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
|
77 g_return_val_if_fail(hook != NULL, -1); |
2404 | 78 |
2457
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 = 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
|
80 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
|
81 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
|
82 |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
83 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
|
84 return 0; |
2404 | 85 } |
86 | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
87 gint |
2404 | 88 hook_dissociate(const gchar *name, HookFunction func) |
89 { | |
90 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
|
91 GSList *iter; |
2404 | 92 |
2457
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(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
|
94 g_return_val_if_fail(func != NULL, -1); |
2404 | 95 |
96 hook = hook_find(name); | |
97 | |
98 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
|
99 return -1; |
2404 | 100 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
101 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
|
102 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
|
103 { |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
104 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
|
105 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
|
106 { |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 } |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
111 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
|
112 } |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
113 return -1; |
2404 | 114 } |
115 | |
116 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
|
117 hook_call(const gchar *name, gpointer hook_data) |
2404 | 118 { |
119 Hook *hook; | |
120 GSList *iter; | |
121 | |
122 g_return_if_fail(name != NULL); | |
123 | |
124 hook = hook_find(name); | |
125 | |
4848
b2ee645f3e59
Hook up the equalizer (bug #24)
John Lindgren <john.lindgren@tds.net>
parents:
4811
diff
changeset
|
126 if (hook == NULL) { |
b2ee645f3e59
Hook up the equalizer (bug #24)
John Lindgren <john.lindgren@tds.net>
parents:
4811
diff
changeset
|
127 printf ("Warning: no hook found for \"%s\"\n", name); |
2404 | 128 return; |
4848
b2ee645f3e59
Hook up the equalizer (bug #24)
John Lindgren <john.lindgren@tds.net>
parents:
4811
diff
changeset
|
129 } |
2404 | 130 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
131 for (iter = hook->items; iter != NULL; iter = g_slist_next(iter)) |
2404 | 132 { |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
133 HookItem *hookitem = (HookItem*)iter->data; |
2404 | 134 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
135 g_return_if_fail(hookitem->func != NULL); |
2404 | 136 |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
137 hookitem->func(hook_data, hookitem->user_data); |
2404 | 138 } |
139 } |