2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail 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 3 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, see <http://www.gnu.org/licenses/>.
25 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
35 #include "alertpanel.h"
36 #include "prefs_common.h"
39 #include "manage_window.h"
42 PLUGINWINDOW_NAME, /*<! plugin name */
43 PLUGINWINDOW_DATA, /*<! Plugin pointer */
44 PLUGINWINDOW_STYLE, /*<! italic if error */
45 N_PLUGINWINDOW_COLUMNS
48 typedef struct _PluginWindow
51 GtkWidget *plugin_list_view;
52 GtkWidget *plugin_desc;
53 GtkWidget *unload_btn;
55 Plugin *selected_plugin;
58 static GtkListStore* pluginwindow_create_data_store (void);
59 static GtkWidget *pluginwindow_list_view_create (PluginWindow *pluginwindow);
60 static void pluginwindow_create_list_view_columns (GtkWidget *list_view);
61 static gboolean pluginwindow_selected (GtkTreeSelection *selector,
64 gboolean currently_selected,
67 static void close_cb(GtkButton *button, PluginWindow *pluginwindow)
69 gtk_widget_destroy(pluginwindow->window);
75 static gint pluginwindow_delete_cb(GtkWidget *widget, GdkEventAny *event,
76 PluginWindow *pluginwindow)
78 close_cb(NULL,pluginwindow);
82 static void set_plugin_list(PluginWindow *pluginwindow)
84 GSList *plugins, *cur, *unloaded;
88 GtkTextBuffer *textbuf;
89 GtkTextIter start_iter, end_iter;
90 GtkTreeSelection *selection;
92 plugins = plugin_get_list();
93 unloaded = plugin_get_unloaded_list();
95 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
96 (pluginwindow->plugin_list_view)));
97 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
98 0, GTK_SORT_ASCENDING);
99 gtk_list_store_clear(store);
101 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pluginwindow->plugin_desc));
102 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(pluginwindow->plugin_desc), FALSE);
103 gtk_text_view_set_editable(GTK_TEXT_VIEW(pluginwindow->plugin_desc), FALSE);
104 gtk_text_buffer_get_start_iter(textbuf, &start_iter);
105 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
106 gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
107 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
109 for(cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
110 Plugin *plugin = (Plugin *) cur->data;
112 gtk_list_store_append(store, &iter);
113 text = plugin_get_name(plugin);
114 gtk_list_store_set(store, &iter,
115 PLUGINWINDOW_NAME, text,
116 PLUGINWINDOW_DATA, plugin,
117 PLUGINWINDOW_STYLE, PANGO_STYLE_NORMAL,
121 for(cur = unloaded; cur != NULL; cur = g_slist_next(cur)) {
122 Plugin *plugin = (Plugin *) cur->data;
124 gtk_list_store_append(store, &iter);
125 text = plugin_get_name(plugin);
126 gtk_list_store_set(store, &iter,
127 PLUGINWINDOW_NAME, text,
128 PLUGINWINDOW_DATA, plugin,
129 PLUGINWINDOW_STYLE, PANGO_STYLE_ITALIC,
133 if (pluginwindow->selected_plugin == NULL) {
134 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW
135 (pluginwindow->plugin_list_view));
136 gtk_tree_selection_unselect_all(selection);
138 g_slist_free(plugins);
141 static void select_row_cb(Plugin *plugin, PluginWindow *pluginwindow)
143 GtkTextView *plugin_desc = GTK_TEXT_VIEW(pluginwindow->plugin_desc);
144 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(plugin_desc);
145 GtkTextIter start_iter, end_iter;
148 pluginwindow->selected_plugin = plugin;
150 if (pluginwindow->selected_plugin != NULL) {
151 const gchar *desc = plugin_get_desc(plugin);
152 const gchar *err = plugin_get_error(plugin);
153 gtk_text_buffer_get_start_iter(textbuf, &start_iter);
154 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
155 gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
158 text = g_strconcat(desc, _("\n\nVersion: "),
159 plugin_get_version(plugin), "\n", NULL);
161 text = g_strconcat(_("Error: "),
162 err, "\n", _("Plugin is not functional."),
163 "\n\n", desc, _("\n\nVersion: "),
164 plugin_get_version(plugin), "\n", NULL);
165 gtk_text_buffer_insert(textbuf, &start_iter, text, strlen(text));
167 gtk_widget_set_sensitive(pluginwindow->unload_btn, TRUE);
169 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
173 static void unselect_row_cb(Plugin *plugin, PluginWindow *pluginwindow)
175 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
178 static void unload_cb(GtkButton *button, PluginWindow *pluginwindow)
180 Plugin *plugin = pluginwindow->selected_plugin;
182 g_return_if_fail(plugin != NULL);
183 plugin_unload(plugin);
184 pluginwindow->selected_plugin = NULL;
185 set_plugin_list(pluginwindow);
188 static void load_cb(GtkButton *button, PluginWindow *pluginwindow)
192 file_list = filesel_select_multiple_files_open_with_filter(
193 _("Select the Plugins to load"), get_plugin_dir(),
194 "*." G_MODULE_SUFFIX);
199 for ( tmp = file_list; tmp; tmp = tmp->next) {
200 gchar *file, *error = NULL;
202 file = (gchar *) tmp->data;
204 plugin_load(file, &error);
206 gchar *basename = g_path_get_basename(file);
208 _("The following error occurred while loading %s :\n\n%s\n"),
214 /* FIXME: globally or atom-ly : ? */
215 set_plugin_list(pluginwindow);
219 g_list_free(file_list);
223 static gboolean pluginwindow_key_pressed(GtkWidget *widget, GdkEventKey *event,
224 PluginWindow *pluginwindow)
227 switch (event->keyval) {
231 close_cb(NULL, pluginwindow);
237 load_cb(NULL, pluginwindow);
241 case GDK_KP_Subtract :
243 unload_cb(NULL, pluginwindow);
253 *\brief Save Gtk object size to prefs dataset
255 static void pluginwindow_size_allocate_cb(GtkWidget *widget,
256 GtkAllocation *allocation)
258 g_return_if_fail(allocation != NULL);
260 prefs_common.pluginswin_width = allocation->width;
261 prefs_common.pluginswin_height = allocation->height;
265 void pluginwindow_create()
267 PluginWindow *pluginwindow;
271 GtkWidget *scrolledwindow2;
272 GtkWidget *plugin_list_view;
276 GtkWidget *scrolledwindow3;
277 GtkWidget *plugin_desc;
278 GtkWidget *hbuttonbox1;
279 GtkWidget *hbuttonbox2;
282 GtkWidget *unload_btn;
283 GtkWidget *close_btn;
284 GtkWidget *get_more_btn;
287 GtkWidget *hbox_info;
288 static GdkGeometry geometry;
289 GtkTooltips *tooltips;
291 debug_print("Creating plugins window...\n");
293 pluginwindow = g_new0(PluginWindow, 1);
295 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "pluginwindow");
296 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
297 gtk_window_set_title(GTK_WINDOW(window), _("Plugins"));
298 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
299 manage_window_set_transient(GTK_WINDOW(window));
301 vbox1 = gtk_vbox_new(FALSE, 4);
302 gtk_widget_show(vbox1);
303 gtk_container_add(GTK_CONTAINER(window), vbox1);
304 gtk_box_set_homogeneous(GTK_BOX(vbox1), FALSE);
305 gtk_widget_realize(window);
307 hbox2 = gtk_hbox_new(FALSE, 8);
308 gtk_widget_show(hbox2);
309 gtk_box_pack_start(GTK_BOX(vbox1), hbox2, TRUE, TRUE, 0);
311 vbox3 = gtk_vbox_new(FALSE, 4);
312 gtk_widget_show(vbox3);
313 gtk_box_pack_start(GTK_BOX(hbox2), vbox3, FALSE, FALSE, 0);
315 scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL);
316 gtk_widget_show(scrolledwindow2);
317 gtk_box_pack_start(GTK_BOX(vbox3), scrolledwindow2, TRUE, TRUE, 0);
318 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow2),
319 GTK_SHADOW_ETCHED_IN);
320 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
321 (scrolledwindow2), GTK_POLICY_NEVER,
322 GTK_POLICY_AUTOMATIC);
324 plugin_list_view = pluginwindow_list_view_create(pluginwindow);
325 gtk_widget_show(plugin_list_view);
326 gtk_container_add(GTK_CONTAINER(scrolledwindow2), plugin_list_view);
327 gtk_widget_grab_focus(GTK_WIDGET(plugin_list_view));
329 gtkut_stock_button_set_create(&hbuttonbox1,
330 &load_btn, _("Load..."),
331 &unload_btn, _("Unload"),
333 gtk_widget_show(hbuttonbox1);
334 gtk_box_pack_start(GTK_BOX(vbox3), hbuttonbox1, FALSE, FALSE, 0);
336 vbox2 = gtk_vbox_new(FALSE, 0);
337 gtk_widget_show(vbox2);
338 gtk_box_pack_start(GTK_BOX(hbox2), vbox2, TRUE, TRUE, 0);
340 frame2 = gtk_frame_new(NULL);
341 gtk_widget_show(frame2);
342 gtk_box_pack_start(GTK_BOX(vbox2), frame2, FALSE, TRUE, 0);
344 label13 = gtk_label_new(_("Description"));
345 gtk_widget_show(label13);
346 gtk_container_add(GTK_CONTAINER(frame2), label13);
347 gtk_misc_set_alignment(GTK_MISC(label13), 0, 0.5);
348 gtk_misc_set_padding(GTK_MISC(label13), 2, 2);
350 scrolledwindow3 = gtk_scrolled_window_new(NULL, NULL);
351 gtk_widget_show(scrolledwindow3);
352 gtk_box_pack_start(GTK_BOX(vbox2), scrolledwindow3, TRUE, TRUE, 0);
353 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow3),
354 GTK_SHADOW_ETCHED_IN);
355 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
356 (scrolledwindow3), GTK_POLICY_NEVER,
359 plugin_desc = gtk_text_view_new();
360 gtk_widget_show(plugin_desc);
361 gtk_container_add(GTK_CONTAINER(scrolledwindow3), plugin_desc);
363 hbox_info = gtk_hbox_new(FALSE, 5);
364 gtk_widget_show(hbox_info);
366 desc_lbl = gtk_label_new(_("More plugins are available from the "
367 "Claws Mail website."));
368 gtk_misc_set_alignment(GTK_MISC(desc_lbl), 0, 0.5);
369 gtk_widget_show(desc_lbl);
370 gtk_box_pack_start(GTK_BOX(hbox_info), desc_lbl, FALSE, FALSE, 0);
372 get_more_btn = gtkut_get_link_btn(window, PLUGINS_URI, _("Get more..."));
373 gtk_misc_set_alignment(GTK_MISC(GTK_BIN(get_more_btn)->child), 0, 0.5);
374 gtk_widget_show(get_more_btn);
375 gtk_box_pack_start(GTK_BOX(hbox_info), get_more_btn, FALSE, FALSE, 0);
376 gtk_box_pack_start(GTK_BOX(hbox_info), gtk_label_new(""), TRUE, TRUE, 0);
377 gtk_box_pack_start(GTK_BOX(vbox1), hbox_info, FALSE, FALSE, 0);
379 gtkut_stock_button_set_create_with_help(&hbuttonbox2, &help_btn,
380 &close_btn, GTK_STOCK_CLOSE,
381 NULL, NULL, NULL, NULL);
383 gtk_box_set_spacing(GTK_BOX(hbuttonbox2), 6);
384 gtk_widget_show(hbuttonbox2);
385 gtk_box_pack_end(GTK_BOX(vbox1), hbuttonbox2, FALSE, FALSE, 0);
387 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(plugin_desc), GTK_WRAP_WORD);
388 gtk_widget_set_sensitive(GTK_WIDGET(unload_btn), FALSE);
390 g_signal_connect(G_OBJECT(help_btn), "clicked",
391 G_CALLBACK(manual_open_with_anchor_cb),
392 MANUAL_ANCHOR_PLUGINS);
393 g_signal_connect(G_OBJECT(load_btn), "clicked",
394 G_CALLBACK(load_cb), pluginwindow);
395 g_signal_connect(G_OBJECT(unload_btn), "clicked",
396 G_CALLBACK(unload_cb), pluginwindow);
397 g_signal_connect(G_OBJECT(close_btn), "clicked",
398 G_CALLBACK(close_cb), pluginwindow);
399 g_signal_connect(G_OBJECT(window), "size_allocate",
400 G_CALLBACK(pluginwindow_size_allocate_cb), NULL);
401 g_signal_connect(G_OBJECT(window), "key_press_event",
402 G_CALLBACK(pluginwindow_key_pressed), pluginwindow);
403 g_signal_connect(G_OBJECT(window), "delete_event",
404 G_CALLBACK(pluginwindow_delete_cb), pluginwindow);
406 tooltips = gtk_tooltips_new();
408 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips),
410 _("Click here to load one or more plugins"), NULL);
412 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips),
414 _("Unload the selected plugin"), NULL);
416 pluginwindow->window = window;
417 pluginwindow->plugin_list_view = plugin_list_view;
418 pluginwindow->plugin_desc = plugin_desc;
419 pluginwindow->unload_btn = unload_btn;
420 pluginwindow->selected_plugin = NULL;
422 set_plugin_list(pluginwindow);
426 if (!geometry.min_height) {
427 geometry.min_width = -1;
428 geometry.min_height = 300;
431 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
433 gtk_window_set_default_size(GTK_WINDOW(window), prefs_common.pluginswin_width,
434 prefs_common.pluginswin_height);
436 gtk_widget_show(window);
439 static GtkListStore* pluginwindow_create_data_store(void)
441 return gtk_list_store_new(N_PLUGINWINDOW_COLUMNS,
448 static GtkWidget *pluginwindow_list_view_create(PluginWindow *pluginwindow)
450 GtkTreeView *list_view;
451 GtkTreeSelection *selector;
454 model = GTK_TREE_MODEL(pluginwindow_create_data_store());
455 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
456 g_object_unref(model);
458 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
459 gtk_tree_view_set_search_column (list_view, 0);
461 selector = gtk_tree_view_get_selection(list_view);
462 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
463 gtk_tree_selection_set_select_function(selector, pluginwindow_selected,
466 /* create the columns */
467 pluginwindow_create_list_view_columns(GTK_WIDGET(list_view));
469 return GTK_WIDGET(list_view);
472 static void pluginwindow_create_list_view_columns(GtkWidget *list_view)
474 GtkTreeViewColumn *column;
475 GtkCellRenderer *renderer;
477 renderer = gtk_cell_renderer_text_new();
478 column = gtk_tree_view_column_new_with_attributes
479 (_("Loaded plugins"),
481 "text", PLUGINWINDOW_NAME,
482 "style", PLUGINWINDOW_STYLE,
484 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
487 static gboolean pluginwindow_selected(GtkTreeSelection *selector,
490 gboolean currently_selected,
496 if (!gtk_tree_model_get_iter(model, &iter, path))
499 gtk_tree_model_get(model, &iter,
500 PLUGINWINDOW_DATA, &plugin,
503 if (currently_selected)
504 unselect_row_cb(plugin, data);
506 select_row_cb(plugin, data);