2006-02-21 [wwp] 2.0.0cvs69
[claws.git] / src / gtk / pluginwindow.c
index 134ea12aba4b9d7a03fc2d7d41b0919be20aab93..86b60d5c3133955b1d1f5111ed75836bc506086e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto and the Sylpheed-Claws Team
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -38,6 +38,7 @@
 enum {
        PLUGINWINDOW_NAME,              /*<! plugin name */
        PLUGINWINDOW_DATA,              /*<! Plugin pointer */
+       PLUGINWINDOW_STYLE,             /*<! italic if error */
        N_PLUGINWINDOW_COLUMNS
 };
 
@@ -70,7 +71,7 @@ static void close_cb(GtkButton *button, PluginWindow *pluginwindow)
 
 static void set_plugin_list(PluginWindow *pluginwindow)
 {
-       GSList *plugins, *cur;
+       GSList *plugins, *cur, *unloaded;
        const gchar *text;
        GtkListStore *store;
        GtkTreeIter iter;
@@ -79,6 +80,7 @@ static void set_plugin_list(PluginWindow *pluginwindow)
        GtkTreeSelection *selection;
 
        plugins = plugin_get_list();
+       unloaded = plugin_get_unloaded_list();
 
        store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
                                (pluginwindow->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);
        }
 
@@ -118,17 +133,27 @@ static void select_row_cb(Plugin *plugin, PluginWindow *pluginwindow)
        GtkTextView *plugin_desc = GTK_TEXT_VIEW(pluginwindow->plugin_desc);
        GtkTextBuffer *textbuf = gtk_text_view_get_buffer(plugin_desc);
        GtkTextIter start_iter, end_iter;
-       const gchar *text;
+       gchar *text;
 
        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);
@@ -152,22 +177,35 @@ static void unload_cb(GtkButton *button, PluginWindow *pluginwindow)
 
 static void load_cb(GtkButton *button, PluginWindow *pluginwindow)
 {
-       gchar *file, *error = NULL;
-
-       file = filesel_select_file_open_with_filter(_("Select Plugin to load"), 
-                                                   PLUGINDIR, 
-                                                   "*." G_MODULE_SUFFIX);
-       if (file == NULL)
-               return;
-
-       plugin_load(file, &error);
-       if (error != NULL) {
-               alertpanel_error(_("The following error occured while loading the plugin:\n%s\n"), error);
-               g_free(error);
-       }
+       GList *file_list;
+
+       file_list = filesel_select_multiple_files_open_with_filter(
+                       _("Select Plugin to load"), get_plugin_dir(), 
+                       "*." G_MODULE_SUFFIX);
+
+       if (file_list) {
+               GList *tmp;
+
+               for ( tmp = file_list; tmp; tmp = tmp->next) {
+                       gchar *file, *error = NULL;
+
+                       file = (gchar *) tmp->data;
+                       if (!file) continue;
+                       plugin_load(file, &error);
+                       if (error != NULL) {
+                               alertpanel_error(
+                               _("The following error occured while loading the plugin [%s] :\n%s\n"),
+                               file, error);
+                               g_free(error);
+                       }
+
+                       /* FIXME: globally or atom-ly : ? */
+                       set_plugin_list(pluginwindow);
+                       g_free(file);
+               }
 
-       set_plugin_list(pluginwindow);
-       g_free(file);
+               g_list_free(file_list);
+       }               
 }
 
 static gboolean pluginwindow_key_pressed(GtkWidget *widget, GdkEventKey *event,
@@ -352,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);
 }
 
@@ -364,9 +403,10 @@ static GtkWidget *pluginwindow_list_view_create(PluginWindow *pluginwindow)
        model = GTK_TREE_MODEL(pluginwindow_create_data_store());
        list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
        g_object_unref(model);  
-       
+
        gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
-       
+       gtk_tree_view_set_search_column (list_view, 0);
+
        selector = gtk_tree_view_get_selection(list_view);
        gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
        gtk_tree_selection_set_select_function(selector, pluginwindow_selected,
@@ -388,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);          
 }