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, COMMON_RC, NULL);
52 if ((pfile = prefs_write_open(rcpath)) == NULL ||
53 (prefs_set_block_label(pfile, "Plugins") < 0)) {
54 g_warning("failed to write plugin list\n");
59 for (cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
60 plugin = (Plugin *)cur->data;
62 fprintf(pfile->fp, "%s\n", plugin->filename);
65 if (prefs_file_close(pfile) < 0)
66 g_warning("failed to write plugin list\n");
74 * \param filename The filename of the plugin to load
75 * \param error The location where an error string can be stored
76 * \return 0 on success, -1 otherwise
78 gint plugin_load(const gchar *filename, gchar **error)
81 gint (*plugin_init) (gchar **error);
82 gchar *plugin_name, *plugin_desc;
85 g_return_val_if_fail(filename != NULL, -1);
86 g_return_val_if_fail(error != NULL, -1);
88 plugin = g_new0(Plugin, 1);
90 *error = g_strdup(_("Failed to allocate memory for Plugin"));
94 plugin->module = g_module_open(filename, 0);
95 if (plugin->module == NULL) {
96 *error = g_strdup(g_module_error());
101 if (!g_module_symbol(plugin->module, "plugin_name", (gpointer *)&plugin_name) ||
102 !g_module_symbol(plugin->module, "plugin_desc", (gpointer *)&plugin_desc) ||
103 !g_module_symbol(plugin->module, "plugin_init", (gpointer *)&plugin_init)) {
104 *error = g_strdup(g_module_error());
105 g_module_close(plugin->module);
110 if ((ok = plugin_init(error)) < 0) {
111 g_module_close(plugin->module);
116 plugin->name = plugin_name;
117 plugin->desc = plugin_desc;
118 plugin->filename = g_strdup(filename);
120 plugins = g_slist_append(plugins, plugin);
122 debug_print("Plugin %s (from file %s) loaded\n", plugin->name(), filename);
127 void plugin_unload(Plugin *plugin)
129 void (*plugin_done) ();
131 if (g_module_symbol(plugin->module, "plugin_done", (gpointer *)&plugin_done)) {
135 g_module_close(plugin->module);
139 void plugin_load_all()
146 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
147 if ((pfile = prefs_read_open(rcpath)) == NULL ||
148 (prefs_set_block_label(pfile, "Plugins") < 0)) {
153 while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
158 if ((buf[0] != '\0') && (plugin_load(buf, &error) < 0)) {
159 g_warning("plugin loading error: %s\n", error);
163 prefs_file_close(pfile);
168 void plugin_unload_all()
172 for (cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
173 plugin_unload((Plugin *)cur->data);
175 g_slist_free(plugins);
179 GSList *plugin_get_list()
181 return g_slist_copy(plugins);
184 const gchar *plugin_get_name(Plugin *plugin)
186 return plugin->name();
189 const gchar *plugin_get_desc(Plugin *plugin)
191 return plugin->desc();