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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
34 #include "alertpanel.h"
35 #include "prefs_common.h"
39 PLUGINWINDOW_NAME, /*<! plugin name */
40 PLUGINWINDOW_DATA, /*<! Plugin pointer */
41 N_PLUGINWINDOW_COLUMNS
44 typedef struct _PluginWindow
47 GtkWidget *plugin_list_view;
48 GtkWidget *plugin_desc;
49 GtkWidget *unload_btn;
51 Plugin *selected_plugin;
54 static GtkListStore* pluginwindow_create_data_store (void);
55 static GtkWidget *pluginwindow_list_view_create (PluginWindow *pluginwindow);
56 static void pluginwindow_create_list_view_columns (GtkWidget *list_view);
57 static gboolean pluginwindow_selected (GtkTreeSelection *selector,
60 gboolean currently_selected,
63 static void close_cb(GtkButton *button, PluginWindow *pluginwindow)
65 gtk_widget_destroy(pluginwindow->window);
71 static void set_plugin_list(PluginWindow *pluginwindow)
73 GSList *plugins, *cur;
77 GtkTextBuffer *textbuf;
78 GtkTextIter start_iter, end_iter;
79 GtkTreeSelection *selection;
81 plugins = plugin_get_list();
83 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
84 (pluginwindow->plugin_list_view)));
85 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
86 0, GTK_SORT_ASCENDING);
87 gtk_list_store_clear(store);
89 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pluginwindow->plugin_desc));
90 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(pluginwindow->plugin_desc), FALSE);
91 gtk_text_view_set_editable(GTK_TEXT_VIEW(pluginwindow->plugin_desc), FALSE);
92 gtk_text_buffer_get_start_iter(textbuf, &start_iter);
93 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
94 gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
95 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
97 for(cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
98 Plugin *plugin = (Plugin *) cur->data;
100 gtk_list_store_append(store, &iter);
101 text = plugin_get_name(plugin);
102 gtk_list_store_set(store, &iter,
103 PLUGINWINDOW_NAME, text,
104 PLUGINWINDOW_DATA, plugin,
108 if (pluginwindow->selected_plugin == NULL) {
109 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW
110 (pluginwindow->plugin_list_view));
111 gtk_tree_selection_unselect_all(selection);
113 g_slist_free(plugins);
116 static void select_row_cb(Plugin *plugin, PluginWindow *pluginwindow)
118 GtkTextView *plugin_desc = GTK_TEXT_VIEW(pluginwindow->plugin_desc);
119 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(plugin_desc);
120 GtkTextIter start_iter, end_iter;
123 pluginwindow->selected_plugin = plugin;
125 if (pluginwindow->selected_plugin != NULL) {
126 gtk_text_buffer_get_start_iter(textbuf, &start_iter);
127 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
128 gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
129 text = g_strconcat(plugin_get_desc(plugin), _("\n\nVersion: "),
130 plugin_get_version(plugin), "\n", NULL);
131 gtk_text_buffer_insert(textbuf, &start_iter, text, strlen(text));
132 gtk_widget_set_sensitive(pluginwindow->unload_btn, TRUE);
134 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
138 static void unselect_row_cb(Plugin *plugin, PluginWindow *pluginwindow)
140 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
143 static void unload_cb(GtkButton *button, PluginWindow *pluginwindow)
145 Plugin *plugin = pluginwindow->selected_plugin;
147 g_return_if_fail(plugin != NULL);
148 plugin_unload(plugin);
149 pluginwindow->selected_plugin = NULL;
150 set_plugin_list(pluginwindow);
153 static void load_cb(GtkButton *button, PluginWindow *pluginwindow)
155 gchar *file, *error = NULL;
157 file = filesel_select_file_open_with_filter(_("Select Plugin to load"),
159 "*." G_MODULE_SUFFIX);
163 plugin_load(file, &error);
165 alertpanel_error(_("The following error occured while loading the plugin:\n%s\n"), error);
169 set_plugin_list(pluginwindow);
173 static gboolean pluginwindow_key_pressed(GtkWidget *widget, GdkEventKey *event,
174 PluginWindow *pluginwindow)
177 switch (event->keyval) {
181 close_cb(NULL, pluginwindow);
187 load_cb(NULL, pluginwindow);
191 case GDK_KP_Subtract :
193 unload_cb(NULL, pluginwindow);
203 *\brief Save Gtk object size to prefs dataset
205 static void pluginwindow_size_allocate_cb(GtkWidget *widget,
206 GtkAllocation *allocation)
208 g_return_if_fail(allocation != NULL);
210 prefs_common.pluginswin_width = allocation->width;
211 prefs_common.pluginswin_height = allocation->height;
215 void pluginwindow_create()
217 PluginWindow *pluginwindow;
218 /* ---------------------- code made by glade ---------------------- */
222 GtkWidget *scrolledwindow2;
223 GtkWidget *plugin_list_view;
227 GtkWidget *scrolledwindow3;
228 GtkWidget *plugin_desc;
229 GtkWidget *hbuttonbox1;
231 GtkWidget *unload_btn;
232 GtkWidget *close_btn;
233 static GdkGeometry geometry;
235 debug_print("Creating plugins window...\n");
237 pluginwindow = g_new0(PluginWindow, 1);
239 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
240 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
241 gtk_window_set_title(GTK_WINDOW(window), _("Plugins"));
242 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
244 vbox1 = gtk_vbox_new(FALSE, 4);
245 gtk_widget_show(vbox1);
246 gtk_container_add(GTK_CONTAINER(window), vbox1);
248 hbox2 = gtk_hbox_new(FALSE, 8);
249 gtk_widget_show(hbox2);
250 gtk_box_pack_start(GTK_BOX(vbox1), hbox2, TRUE, TRUE, 0);
252 scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL);
253 gtk_widget_show(scrolledwindow2);
254 gtk_box_pack_start(GTK_BOX(hbox2), scrolledwindow2, FALSE, FALSE, 0);
255 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
256 (scrolledwindow2), GTK_POLICY_NEVER,
257 GTK_POLICY_AUTOMATIC);
259 plugin_list_view = pluginwindow_list_view_create(pluginwindow);
260 gtk_widget_show(plugin_list_view);
261 gtk_container_add(GTK_CONTAINER(scrolledwindow2), plugin_list_view);
262 gtk_widget_grab_focus(GTK_WIDGET(plugin_list_view));
264 vbox2 = gtk_vbox_new(FALSE, 0);
265 gtk_widget_show(vbox2);
266 gtk_box_pack_start(GTK_BOX(hbox2), vbox2, TRUE, TRUE, 0);
268 frame2 = gtk_frame_new(NULL);
269 gtk_widget_show(frame2);
270 gtk_box_pack_start(GTK_BOX(vbox2), frame2, FALSE, TRUE, 0);
272 label13 = gtk_label_new(_("Description"));
273 gtk_widget_show(label13);
274 gtk_container_add(GTK_CONTAINER(frame2), label13);
275 gtk_misc_set_alignment(GTK_MISC(label13), 0, 0.5);
276 gtk_misc_set_padding(GTK_MISC(label13), 2, 2);
278 scrolledwindow3 = gtk_scrolled_window_new(NULL, NULL);
279 gtk_widget_show(scrolledwindow3);
280 gtk_box_pack_start(GTK_BOX(vbox2), scrolledwindow3, TRUE, TRUE, 0);
281 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
282 (scrolledwindow3), GTK_POLICY_NEVER,
285 plugin_desc = gtk_text_view_new();
286 gtk_widget_show(plugin_desc);
287 gtk_container_add(GTK_CONTAINER(scrolledwindow3), plugin_desc);
289 hbuttonbox1 = gtk_hbutton_box_new();
290 gtk_widget_show(hbuttonbox1);
291 gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox1, FALSE, FALSE, 0);
292 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1),
294 gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 6);
296 load_btn = gtk_button_new_with_label(_("Load Plugin..."));
297 gtk_widget_show(load_btn);
298 gtk_container_add(GTK_CONTAINER(hbuttonbox1), load_btn);
299 GTK_WIDGET_SET_FLAGS(load_btn, GTK_CAN_DEFAULT);
301 unload_btn = gtk_button_new_with_label(_("Unload Plugin"));
302 gtk_widget_show(unload_btn);
303 gtk_container_add(GTK_CONTAINER(hbuttonbox1), unload_btn);
304 GTK_WIDGET_SET_FLAGS(unload_btn, GTK_CAN_DEFAULT);
306 close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
307 gtk_widget_show(close_btn);
308 gtk_container_add(GTK_CONTAINER(hbuttonbox1), close_btn);
309 GTK_WIDGET_SET_FLAGS(close_btn, GTK_CAN_DEFAULT);
310 /* ----------------------------------------------------------- */
312 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(plugin_desc), GTK_WRAP_WORD);
313 gtk_widget_set_sensitive(GTK_WIDGET(unload_btn), FALSE);
316 g_signal_connect(G_OBJECT(load_btn), "released",
317 G_CALLBACK(load_cb), pluginwindow);
318 g_signal_connect(G_OBJECT(unload_btn), "released",
319 G_CALLBACK(unload_cb), pluginwindow);
320 g_signal_connect(G_OBJECT(close_btn), "released",
321 G_CALLBACK(close_cb), pluginwindow);
322 g_signal_connect(G_OBJECT(window), "size_allocate",
323 G_CALLBACK(pluginwindow_size_allocate_cb), NULL);
324 g_signal_connect(G_OBJECT(window), "key_press_event",
325 G_CALLBACK(pluginwindow_key_pressed), pluginwindow);
327 pluginwindow->window = window;
328 pluginwindow->plugin_list_view = plugin_list_view;
329 pluginwindow->plugin_desc = plugin_desc;
330 pluginwindow->unload_btn = unload_btn;
331 pluginwindow->selected_plugin = NULL;
333 set_plugin_list(pluginwindow);
337 if (!geometry.min_height) {
338 geometry.min_width = 480;
339 geometry.min_height = 300;
342 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
344 gtk_widget_set_size_request(window, prefs_common.pluginswin_width,
345 prefs_common.pluginswin_height);
347 gtk_widget_show(window);
350 static GtkListStore* pluginwindow_create_data_store(void)
352 return gtk_list_store_new(N_PLUGINWINDOW_COLUMNS,
358 static GtkWidget *pluginwindow_list_view_create(PluginWindow *pluginwindow)
360 GtkTreeView *list_view;
361 GtkTreeSelection *selector;
364 model = GTK_TREE_MODEL(pluginwindow_create_data_store());
365 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
366 g_object_unref(model);
368 gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
370 selector = gtk_tree_view_get_selection(list_view);
371 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
372 gtk_tree_selection_set_select_function(selector, pluginwindow_selected,
375 /* create the columns */
376 pluginwindow_create_list_view_columns(GTK_WIDGET(list_view));
378 return GTK_WIDGET(list_view);
381 static void pluginwindow_create_list_view_columns(GtkWidget *list_view)
383 GtkTreeViewColumn *column;
384 GtkCellRenderer *renderer;
386 renderer = gtk_cell_renderer_text_new();
387 column = gtk_tree_view_column_new_with_attributes
390 "text", PLUGINWINDOW_NAME,
392 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
395 static gboolean pluginwindow_selected(GtkTreeSelection *selector,
398 gboolean currently_selected,
404 if (!gtk_tree_model_get_iter(model, &iter, path))
407 gtk_tree_model_get(model, &iter,
408 PLUGINWINDOW_DATA, &plugin,
411 if (currently_selected)
412 unselect_row_cb(plugin, data);
414 select_row_cb(plugin, data);