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.
29 static GHashTable *hooklist_table;
31 GHookList *hooks_get_hooklist(const gchar *hooklist_name)
35 if (hooklist_table == NULL)
36 hooklist_table = g_hash_table_new(g_str_hash, g_str_equal);
38 hooklist = (GHookList *) g_hash_table_lookup(hooklist_table, hooklist_name);
42 hooklist = g_new0(GHookList, 1);
43 g_hook_list_init(hooklist, sizeof(GHook));
44 g_hash_table_insert(hooklist_table, hooklist_name, hooklist);
49 guint hooks_register_hook(const gchar *hooklist_name,
50 SylpheedHookFunction hook_func,
56 g_return_val_if_fail(hooklist_name != NULL, (guint)-1);
57 g_return_val_if_fail(hook_func != NULL, (guint)-1);
59 hooklist = hooks_get_hooklist(hooklist_name);
60 g_return_val_if_fail(hooklist != NULL, (guint)-1);
62 hook = g_hook_alloc(hooklist);
63 g_return_val_if_fail(hook != NULL, (guint)-1);
65 hook->func = hook_func;
66 hook->data = userdata;
68 g_hook_append(hooklist, hook);
70 debug_print("registed new hook for '%s' as id %d\n", hooklist_name, hook->hook_id);
75 void hooks_unregister_hook(const gchar *hooklist_name,
81 g_return_if_fail(hooklist_name != NULL);
83 hooklist = hooks_get_hooklist(hooklist_name);
84 g_return_if_fail(hooklist != NULL);
86 hook = g_hook_get(hooklist, hook_id);
87 g_return_if_fail(hook != NULL);
89 debug_print("unregisted hook %d in '%s'\n", hook->hook_id, hooklist_name);
91 g_hook_destroy(hooklist, hook_id);
100 static void hooks_marshal(GHook *hook, gpointer data)
102 gboolean (*func) (gpointer source, gpointer data);
103 struct MarshalData *marshal_data = (struct MarshalData *)data;
105 if (!marshal_data->abort) {
107 marshal_data->abort = func(marshal_data->source, hook->data);
111 gboolean hooks_invoke(const gchar *hooklist_name,
115 struct MarshalData marshal_data;
117 g_return_val_if_fail(hooklist_name != NULL, FALSE);
119 hooklist = hooks_get_hooklist(hooklist_name);
120 g_return_val_if_fail(hooklist != NULL, FALSE);
122 marshal_data.source = source;
123 marshal_data.abort = FALSE;
125 g_hook_list_marshal(hooklist, TRUE, hooks_marshal, &marshal_data);
127 return marshal_data.abort;