From 8ddc855c8aa51bd92c41d47c73a684137c2d4d6f Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Thu, 16 Feb 2006 17:26:29 +0000 Subject: [PATCH] 2006-02-16 [cleroy] 2.0.0cvs59 * src/main.c * src/common/plugin.c * src/common/plugin.h * src/gtk/pluginwindow.c Keep track of requested (but unloaded) plugins in some error cases. --- ChangeLog | 9 +++++++ PATCHSETS | 1 + configure.ac | 2 +- src/common/plugin.c | 59 +++++++++++++++++++++++++++++++++++++----- src/common/plugin.h | 3 ++- src/gtk/pluginwindow.c | 31 ++++++++++++++++++++-- src/main.c | 6 +++++ 7 files changed, 100 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 280941afd..53d9a82db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-02-16 [cleroy] 2.0.0cvs59 + + * src/main.c + * src/common/plugin.c + * src/common/plugin.h + * src/gtk/pluginwindow.c + Keep track of requested (but unloaded) plugins + in some error cases. + 2006-02-16 [wwp] 2.0.0cvs58 * src/gtk/gtkaspell.c diff --git a/PATCHSETS b/PATCHSETS index 4365ac87b..366f01750 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -1242,3 +1242,4 @@ ( cvs diff -u -r 1.83.2.64 -r 1.83.2.65 src/mimeview.c; cvs diff -u -r 1.20.2.7 -r 1.20.2.8 src/mimeview.h; cvs diff -u -r 1.395.2.169 -r 1.395.2.170 src/summaryview.c; cvs diff -u -r 1.1.4.27 -r 1.1.4.28 src/etpan/imap-thread.c; ) > 2.0.0cvs56.patchset ( cvs diff -u -r 1.22.2.18 -r 1.22.2.19 src/quote_fmt_parse.y; ) > 2.0.0cvs57.patchset ( cvs diff -u -r 1.9.2.36 -r 1.9.2.37 src/gtk/gtkaspell.c; cvs diff -u -r 1.5.2.4 -r 1.5.2.5 src/gtk/gtkaspell.h; cvs diff -u -r 1.5.2.18 -r 1.5.2.19 src/prefs_spelling.c; cvs diff -u -r 1.382.2.241 -r 1.382.2.242 src/compose.c; cvs diff -u -r 1.204.2.75 -r 1.204.2.76 src/prefs_common.c; cvs diff -u -r 1.103.2.40 -r 1.103.2.41 src/prefs_common.h; ) > 2.0.0cvs58.patchset +( cvs diff -u -r 1.115.2.75 -r 1.115.2.76 src/main.c; cvs diff -u -r 1.13.2.16 -r 1.13.2.17 src/common/plugin.c; cvs diff -u -r 1.5.2.4 -r 1.5.2.5 src/common/plugin.h; cvs diff -u -r 1.5.2.26 -r 1.5.2.27 src/gtk/pluginwindow.c; ) > 2.0.0cvs59.patchset diff --git a/configure.ac b/configure.ac index a50778a35..7f211ed91 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=0 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=58 +EXTRA_VERSION=59 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/common/plugin.c b/src/common/plugin.c index cdc920642..5bfb8c32a 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -43,6 +43,7 @@ struct _Plugin const gchar *(*type) (void); const gchar *(*licence) (void); GSList *rdeps; + gchar *error; }; /** @@ -51,6 +52,11 @@ struct _Plugin GSList *plugins = NULL; GSList *plugin_types = NULL; +/* + * List of plugins unloaded for some fixable reason + */ +static GSList *unloaded_plugins = NULL; + static gint list_find_by_string(gconstpointer data, gconstpointer str) { return strcmp((gchar *)data, (gchar *)str) ? TRUE : FALSE; @@ -92,6 +98,12 @@ void plugin_save_list(void) if (!strcmp(plugin->type(), type_cur->data)) fprintf(pfile->fp, "%s\n", plugin->filename); } + for (plugin_cur = unloaded_plugins; plugin_cur != NULL; plugin_cur = g_slist_next(plugin_cur)) { + plugin = (Plugin *) plugin_cur->data; + + if (!strcmp(plugin->type(), type_cur->data)) + fprintf(pfile->fp, "%s\n", plugin->filename); + } fprintf(pfile->fp, "\n"); if (prefs_file_close(pfile) < 0) @@ -192,6 +204,22 @@ static void plugin_unload_rdeps(Plugin *plugin) g_slist_free(plugin->rdeps); plugin->rdeps = NULL; } + +static void plugin_remove_from_unloaded_list (const gchar *filename) +{ + GSList *item = g_slist_find_custom(unloaded_plugins, + (gpointer) filename, (GCompareFunc)list_find_by_plugin_filename); + Plugin *unloaded_plugin = item ? ((Plugin *)item->data):NULL; + if (unloaded_plugin != NULL) { + debug_print("removing %s from unloaded list\n", unloaded_plugin->filename); + unloaded_plugins = g_slist_remove(unloaded_plugins, unloaded_plugin); + g_module_close(unloaded_plugin->module); + g_free(unloaded_plugin->filename); + g_free(unloaded_plugin->error); + g_free(unloaded_plugin); + } +} + /** * Loads a plugin * @@ -217,6 +245,8 @@ Plugin *plugin_load(const gchar *filename, gchar **error) return NULL; } + plugin_remove_from_unloaded_list(filename); + if (plugin_load_deps(filename, error) < 0) return NULL; plugin = g_new0(Plugin, 1); @@ -260,18 +290,19 @@ Plugin *plugin_load(const gchar *filename, gchar **error) return NULL; } - if ((ok = plugin_init(error)) < 0) { - g_module_close(plugin->module); - g_free(plugin); - return NULL; - } - plugin->name = plugin_name; plugin->desc = plugin_desc; plugin->version = plugin_version; plugin->type = plugin_type; plugin->licence = plugin_licence; plugin->filename = g_strdup(filename); + plugin->error = NULL; + if ((ok = plugin_init(error)) < 0) { + if (*error) + plugin->error = g_strdup(*error); + unloaded_plugins = g_slist_append(unloaded_plugins, plugin); + return NULL; + } plugins = g_slist_append(plugins, plugin); @@ -286,6 +317,10 @@ void plugin_unload(Plugin *plugin) plugin_unload_rdeps(plugin); + if (plugin->error) { + plugin_remove_from_unloaded_list(plugin->filename); + return; + } if (g_module_symbol(plugin->module, "plugin_done", (gpointer) &plugin_done)) { plugin_done(); } @@ -351,7 +386,7 @@ void plugin_unload_all(const gchar *type) cur = g_slist_find_custom(plugin_types, (gpointer) type, list_find_by_string); if (cur) { g_free(cur->data); - g_slist_remove(plugin_types, cur); + plugin_types = g_slist_remove(plugin_types, cur); } } @@ -360,6 +395,11 @@ GSList *plugin_get_list(void) return g_slist_copy(plugins); } +GSList *plugin_get_unloaded_list(void) +{ + return g_slist_copy(unloaded_plugins); +} + const gchar *plugin_get_name(Plugin *plugin) { return plugin->name(); @@ -374,3 +414,8 @@ const gchar *plugin_get_version(Plugin *plugin) { return plugin->version(); } + +const gchar *plugin_get_error(Plugin *plugin) +{ + return plugin->error; +} diff --git a/src/common/plugin.h b/src/common/plugin.h index d770e9851..9d0869092 100644 --- a/src/common/plugin.h +++ b/src/common/plugin.h @@ -40,8 +40,9 @@ void plugin_unload_all (const gchar *type); void plugin_save_list (void); GSList *plugin_get_list (void); +GSList *plugin_get_unloaded_list(void); const gchar *plugin_get_name (Plugin *plugin); const gchar *plugin_get_desc (Plugin *plugin); const gchar *plugin_get_version (Plugin *plugin); - +const gchar *plugin_get_error (Plugin *plugin); #endif diff --git a/src/gtk/pluginwindow.c b/src/gtk/pluginwindow.c index 764532ff8..56c5883f8 100644 --- a/src/gtk/pluginwindow.c +++ b/src/gtk/pluginwindow.c @@ -38,6 +38,7 @@ enum { PLUGINWINDOW_NAME, /*plugin_list_view))); @@ -102,6 +104,19 @@ static void set_plugin_list(PluginWindow *pluginwindow) gtk_list_store_set(store, &iter, PLUGINWINDOW_NAME, text, PLUGINWINDOW_DATA, plugin, + PLUGINWINDOW_STYLE, PANGO_STYLE_NORMAL, + -1); + } + + for(cur = unloaded; cur != NULL; cur = g_slist_next(cur)) { + Plugin *plugin = (Plugin *) cur->data; + + gtk_list_store_append(store, &iter); + text = plugin_get_name(plugin); + gtk_list_store_set(store, &iter, + PLUGINWINDOW_NAME, text, + PLUGINWINDOW_DATA, plugin, + PLUGINWINDOW_STYLE, PANGO_STYLE_ITALIC, -1); } @@ -123,12 +138,22 @@ static void select_row_cb(Plugin *plugin, PluginWindow *pluginwindow) pluginwindow->selected_plugin = plugin; if (pluginwindow->selected_plugin != NULL) { + const gchar *desc = plugin_get_desc(plugin); + const gchar *err = plugin_get_error(plugin); gtk_text_buffer_get_start_iter(textbuf, &start_iter); gtk_text_buffer_get_end_iter(textbuf, &end_iter); gtk_text_buffer_delete(textbuf, &start_iter, &end_iter); - text = g_strconcat(plugin_get_desc(plugin), _("\n\nVersion: "), + + if (err == NULL) + text = g_strconcat(desc, _("\n\nVersion: "), + plugin_get_version(plugin), "\n", NULL); + else + text = g_strconcat(_("Error: "), + err, "\n", _("Plugin is not functional."), + "\n\n", desc, _("\n\nVersion: "), plugin_get_version(plugin), "\n", NULL); gtk_text_buffer_insert(textbuf, &start_iter, text, strlen(text)); + g_free(text); gtk_widget_set_sensitive(pluginwindow->unload_btn, TRUE); } else { gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE); @@ -365,6 +390,7 @@ static GtkListStore* pluginwindow_create_data_store(void) return gtk_list_store_new(N_PLUGINWINDOW_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, + PANGO_TYPE_STYLE, -1); } @@ -402,6 +428,7 @@ static void pluginwindow_create_list_view_columns(GtkWidget *list_view) (_("Plugins"), renderer, "text", PLUGINWINDOW_NAME, + "style", PLUGINWINDOW_STYLE, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column); } diff --git a/src/main.c b/src/main.c index 324a9d6c2..a1f53eea0 100644 --- a/src/main.c +++ b/src/main.c @@ -521,6 +521,12 @@ int main(int argc, char *argv[]) plugin_load_all("GTK2"); + if (plugin_get_unloaded_list() != NULL) { + alertpanel_warning(_("Some plugin(s) failed to load. " + "Check the Plugins configuration " + "for more information.")); + } + if (!folder_have_mailbox()) { alertpanel_error(_("Sylpheed-Claws has detected a configured " "mailbox, but could not load it. It is " -- 2.25.1