2006-08-14 [cleroy] 2.4.0cvs50
[claws.git] / src / gtk / pluginwindow.c
index 3b3fa9153726270e571138b1af103c99b518b887..9fd54e230e2211e2ef09f6ce5e78d0c9080c3100 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
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "defs.h"
 #include "plugin.h"
 
 #include "filesel.h"
 #include "alertpanel.h"
+#include "prefs_common.h"
 #include "../inc.h"
+#include "manual.h"
 
 enum {
        PLUGINWINDOW_NAME,              /*<! plugin name */
        PLUGINWINDOW_DATA,              /*<! Plugin pointer */
+       PLUGINWINDOW_STYLE,             /*<! italic if error */
        N_PLUGINWINDOW_COLUMNS
 };
 
@@ -69,9 +73,8 @@ 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;
-       gint row;
        GtkListStore *store;
        GtkTreeIter iter;
        GtkTextBuffer *textbuf;
@@ -79,9 +82,12 @@ 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)));
+       gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
+                                             0, GTK_SORT_ASCENDING);
        gtk_list_store_clear(store);
        
        textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pluginwindow->plugin_desc));
@@ -100,6 +106,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);
        }
 
@@ -116,16 +135,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 = plugin_get_desc(plugin);
+               
+               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);
@@ -149,20 +179,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(_("Select Plugin to load"), PLUGINDIR);
-       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,
@@ -194,6 +239,19 @@ static gboolean pluginwindow_key_pressed(GtkWidget *widget, GdkEventKey *event,
        return FALSE;
 }
 
+/*!
+ *\brief       Save Gtk object size to prefs dataset
+ */
+static void pluginwindow_size_allocate_cb(GtkWidget *widget,
+                                        GtkAllocation *allocation)
+{
+       g_return_if_fail(allocation != NULL);
+
+       prefs_common.pluginswin_width = allocation->width;
+       prefs_common.pluginswin_height = allocation->height;
+}
+
+
 void pluginwindow_create()
 {
        PluginWindow *pluginwindow;
@@ -208,22 +266,39 @@ void pluginwindow_create()
        GtkWidget *label13;
        GtkWidget *scrolledwindow3;
        GtkWidget *plugin_desc;
-       GtkWidget *hbuttonbox1;
+       GtkWidget *hbuttonbox1, *hbox3;
+       GtkWidget *help_btn;
        GtkWidget *load_btn;
        GtkWidget *unload_btn;
        GtkWidget *close_btn;
+       GtkWidget *get_more_btn;
+       GtkWidget *desc_lbl;
+       static GdkGeometry geometry;
        
+       debug_print("Creating plugins window...\n");
+
        pluginwindow = g_new0(PluginWindow, 1);
 
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
-       gtk_window_set_default_size(GTK_WINDOW(window), 480, 300);
        gtk_window_set_title(GTK_WINDOW(window), _("Plugins"));
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
 
        vbox1 = gtk_vbox_new(FALSE, 4);
        gtk_widget_show(vbox1);
        gtk_container_add(GTK_CONTAINER(window), vbox1);
+       gtk_box_set_homogeneous(GTK_BOX(vbox1), FALSE);
+       gtk_widget_realize(window);
+
+       desc_lbl = gtk_label_new(_("Plugins are a way to greatly extend Sylpheed-Claws' capabilities."));
+       gtk_misc_set_alignment(GTK_MISC(desc_lbl), 0, 0.5);
+       gtk_widget_show(desc_lbl);
+       gtk_box_pack_start(GTK_BOX(vbox1), desc_lbl, FALSE, FALSE, 0);
+
+       get_more_btn = gtkut_get_link_btn(window, PLUGINS_URI, _("Get more..."));
+       gtk_misc_set_alignment(GTK_MISC(GTK_BIN(get_more_btn)->child), 0, 0.5);
+       gtk_widget_show(get_more_btn);
+       gtk_box_pack_start(GTK_BOX(vbox1), get_more_btn, FALSE, FALSE, 0);
 
        hbox2 = gtk_hbox_new(FALSE, 8);
        gtk_widget_show(hbox2);
@@ -266,39 +341,36 @@ void pluginwindow_create()
        gtk_widget_show(plugin_desc);
        gtk_container_add(GTK_CONTAINER(scrolledwindow3), plugin_desc);
 
+       hbox3 = gtk_hbox_new(FALSE, 0);
+       gtk_widget_show(hbox3);
        hbuttonbox1 = gtk_hbutton_box_new();
        gtk_widget_show(hbuttonbox1);
-       gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox1, FALSE, FALSE, 0);
-       gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1),
-                                 GTK_BUTTONBOX_END);
-       gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 6);
-
-       load_btn = gtk_button_new_with_label(_("Load Plugin"));
-       gtk_widget_show(load_btn);
-       gtk_container_add(GTK_CONTAINER(hbuttonbox1), load_btn);
-       GTK_WIDGET_SET_FLAGS(load_btn, GTK_CAN_DEFAULT);
 
-       unload_btn = gtk_button_new_with_label(_("Unload Plugin"));
-       gtk_widget_show(unload_btn);
-       gtk_container_add(GTK_CONTAINER(hbuttonbox1), unload_btn);
-       GTK_WIDGET_SET_FLAGS(unload_btn, GTK_CAN_DEFAULT);
+       gtk_box_pack_start(GTK_BOX(hbox3), hbuttonbox1, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox1), hbox3, FALSE, FALSE, 0);
 
-       close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
-       gtk_widget_show(close_btn);
-       gtk_container_add(GTK_CONTAINER(hbuttonbox1), close_btn);
-       GTK_WIDGET_SET_FLAGS(close_btn, GTK_CAN_DEFAULT);
-       /* ----------------------------------------------------------- */
+       gtkut_stock_button_set_create_with_help(&hbuttonbox1, &help_btn,
+                       &load_btn, _("Load Plugin..."),
+                       &unload_btn, _("Unload Plugin"),
+                       &close_btn, GTK_STOCK_CLOSE);
+       gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 6);
+       gtk_widget_show(hbuttonbox1);
+       gtk_box_pack_end (GTK_BOX (hbox3), hbuttonbox1, FALSE, FALSE, 0);
 
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(plugin_desc), GTK_WRAP_WORD);
        gtk_widget_set_sensitive(GTK_WIDGET(unload_btn), FALSE);
 
-
-       g_signal_connect(G_OBJECT(load_btn), "released",
+       g_signal_connect(G_OBJECT(help_btn), "clicked",
+                        G_CALLBACK(manual_open_with_anchor_cb),
+                        MANUAL_ANCHOR_PLUGINS);
+       g_signal_connect(G_OBJECT(load_btn), "clicked",
                         G_CALLBACK(load_cb), pluginwindow);
-       g_signal_connect(G_OBJECT(unload_btn), "released",
+       g_signal_connect(G_OBJECT(unload_btn), "clicked",
                         G_CALLBACK(unload_cb), pluginwindow);
-       g_signal_connect(G_OBJECT(close_btn), "released",
+       g_signal_connect(G_OBJECT(close_btn), "clicked",
                         G_CALLBACK(close_cb), pluginwindow);
+       g_signal_connect(G_OBJECT(window), "size_allocate",
+                        G_CALLBACK(pluginwindow_size_allocate_cb), NULL);
        g_signal_connect(G_OBJECT(window), "key_press_event",
                           G_CALLBACK(pluginwindow_key_pressed), pluginwindow);
 
@@ -311,6 +383,17 @@ void pluginwindow_create()
        set_plugin_list(pluginwindow);
 
        inc_lock();
+
+       if (!geometry.min_height) {
+               geometry.min_width = 480;
+               geometry.min_height = 300;
+       }
+
+       gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
+                                     GDK_HINT_MIN_SIZE);
+       gtk_widget_set_size_request(window, prefs_common.pluginswin_width,
+                                   prefs_common.pluginswin_height);
+
        gtk_widget_show(window);
 }
 
@@ -319,6 +402,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);
 }
 
@@ -331,9 +415,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, TRUE);
-       
+
+       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,
@@ -352,9 +437,10 @@ static void pluginwindow_create_list_view_columns(GtkWidget *list_view)
 
        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
-               (_("Plugins"),
+               (_("Loaded plugins"),
                 renderer,
                 "text", PLUGINWINDOW_NAME,
+                "style", PLUGINWINDOW_STYLE,
                 NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
 }