2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto and the Sylpheed-Claws Team
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.
40 * List of all loaded plugins
42 GSList *plugins = NULL;
44 void plugin_save_list()
51 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "pluginsrc", NULL);
52 if ((pfile = prefs_write_open(rcpath)) == NULL) {
53 g_warning("failed to write plugin list\n");
58 for (cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
59 plugin = (Plugin *)cur->data;
61 fprintf(pfile->fp, "%s\n", plugin->filename);
64 if (prefs_write_close(pfile) < 0)
65 g_warning("failed to write plugin list\n");
73 * \param filename The filename of the plugin to load
74 * \param error The location where an error string can be stored
75 * \return 0 on success, -1 otherwise
77 gint plugin_load(const gchar *filename, gchar **error)
80 gint (*plugin_init) (gchar **error);
83 g_return_val_if_fail(filename != NULL, -1);
84 g_return_val_if_fail(error != NULL, -1);
86 plugin = g_new0(Plugin, 1);
88 *error = g_strdup(_("Failed to allocate memory for Plugin"));
92 plugin->module = g_module_open(filename, 0);
93 if (plugin->module == NULL) {
94 *error = g_strdup(g_module_error());
99 if (!g_module_symbol(plugin->module, "plugin_name", (gpointer *)&plugin->name) ||
100 !g_module_symbol(plugin->module, "plugin_desc", (gpointer *)&plugin->desc) ||
101 !g_module_symbol(plugin->module, "plugin_init", (gpointer *)&plugin_init)) {
102 *error = g_strdup(g_module_error());
103 g_module_close(plugin->module);
108 if ((ok = plugin_init(error)) < 0) {
109 g_module_close(plugin->module);
114 plugins = g_slist_append(plugins, plugin);
119 void plugin_unload(Plugin *plugin)
121 void (*plugin_done) ();
123 if (g_module_symbol(plugin->module, "plugin_done", (gpointer *)&plugin_done)) {
127 g_module_close(plugin->module);
131 void plugin_load_all()
137 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "pluginsrc", NULL);
138 if ((fp = fopen(rcpath, "rb")) != NULL) {
141 while(fgets(buf, sizeof(buf), fp) != NULL) {
144 if (plugin_load(buf, &error) < 0) {
145 debug_print("plugin loading error: %s\n", error);
156 void plugin_unload_all()
160 for (cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
161 plugin_unload((Plugin *)cur->data);
163 g_slist_free(plugins);
167 GSList *plugin_get_list()
169 return g_slist_copy(plugins);
172 const gchar *plugin_get_name(Plugin *plugin)
177 const gchar *plugin_get_desc(Plugin *plugin)