2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 GHashTable *hooklist_table;
30 GHookList *hooks_get_hooklist(gchar *hooklist_name)
34 if (hooklist_table == NULL)
35 hooklist_table = g_hash_table_new(g_str_hash, g_str_equal);
37 hooklist = (GHookList *) g_hash_table_lookup(hooklist_table, hooklist_name);
41 hooklist = g_new0(GHookList, 1);
42 g_hook_list_init(hooklist, sizeof(GHook));
43 g_hash_table_insert(hooklist_table, hooklist_name, hooklist);
48 guint hooks_register_hook(gchar *hooklist_name,
49 SylpheedHookFunction hook_func,
55 g_return_val_if_fail(hooklist_name != NULL, (guint)-1);
56 g_return_val_if_fail(hook_func != NULL, (guint)-1);
58 hooklist = hooks_get_hooklist(hooklist_name);
59 g_return_val_if_fail(hooklist != NULL, (guint)-1);
61 hook = g_hook_alloc(hooklist);
62 g_return_val_if_fail(hook != NULL, (guint)-1);
64 hook->func = hook_func;
65 hook->data = userdata;
67 g_hook_append(hooklist, hook);
72 void hooks_unregister_hook(gchar *hooklist_name,
78 g_return_if_fail(hooklist_name != NULL);
80 hooklist = hooks_get_hooklist(hooklist_name);
81 g_return_if_fail(hooklist != NULL);
83 hook = g_hook_get(hooklist, hook_id);
84 g_return_if_fail(hook != NULL);
86 g_hook_destroy_link(hooklist, hook);
95 static void hooks_marshal(GHook *hook, gpointer data)
97 gboolean (*func) (gpointer source, gpointer data);
98 struct MarshalData *marshal_data = (struct MarshalData *)data;
100 if (!marshal_data->abort) {
102 marshal_data->abort = func(marshal_data->source, hook->data);
106 gboolean hooks_invoke(gchar *hooklist_name,
110 struct MarshalData marshal_data;
112 g_return_val_if_fail(hooklist_name != NULL, FALSE);
114 hooklist = hooks_get_hooklist(hooklist_name);
115 g_return_val_if_fail(hooklist != NULL, FALSE);
117 marshal_data.source = source;
118 marshal_data.abort = FALSE;
120 g_hook_list_marshal(hooklist, TRUE, hooks_marshal, &marshal_data);
122 return marshal_data.abort;