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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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;
78 GtkTextBuffer *textbuf;
79 GtkTextIter start_iter, end_iter;
80 GtkTreeSelection *selection;
82 plugins = plugin_get_list();
84 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
85 (pluginwindow->plugin_list_view)));
86 gtk_list_store_clear(store);
88 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pluginwindow->plugin_desc));
89 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(pluginwindow->plugin_desc), FALSE);
90 gtk_text_view_set_editable(GTK_TEXT_VIEW(pluginwindow->plugin_desc), FALSE);
91 gtk_text_buffer_get_start_iter(textbuf, &start_iter);
92 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
93 gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
94 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
96 for(cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
97 Plugin *plugin = (Plugin *) cur->data;
99 gtk_list_store_append(store, &iter);
100 text = plugin_get_name(plugin);
101 gtk_list_store_set(store, &iter,
102 PLUGINWINDOW_NAME, text,
103 PLUGINWINDOW_DATA, plugin,
107 if (pluginwindow->selected_plugin == NULL) {
108 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW
109 (pluginwindow->plugin_list_view));
110 gtk_tree_selection_unselect_all(selection);
112 g_slist_free(plugins);
115 static void select_row_cb(Plugin *plugin, PluginWindow *pluginwindow)
117 GtkTextView *plugin_desc = GTK_TEXT_VIEW(pluginwindow->plugin_desc);
118 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(plugin_desc);
119 GtkTextIter start_iter, end_iter;
122 pluginwindow->selected_plugin = plugin;
124 if (pluginwindow->selected_plugin != NULL) {
125 gtk_text_buffer_get_start_iter(textbuf, &start_iter);
126 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
127 gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
128 text = plugin_get_desc(plugin);
129 gtk_text_buffer_insert(textbuf, &start_iter, text, strlen(text));
130 gtk_widget_set_sensitive(pluginwindow->unload_btn, TRUE);
132 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
136 static void unselect_row_cb(Plugin *plugin, PluginWindow *pluginwindow)
138 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
141 static void unload_cb(GtkButton *button, PluginWindow *pluginwindow)
143 Plugin *plugin = pluginwindow->selected_plugin;
145 g_return_if_fail(plugin != NULL);
146 plugin_unload(plugin);
147 pluginwindow->selected_plugin = NULL;
148 set_plugin_list(pluginwindow);
151 static void load_cb(GtkButton *button, PluginWindow *pluginwindow)
153 gchar *file, *error = NULL;
155 file = filesel_select_file_open(_("Select Plugin to load"), PLUGINDIR);
159 plugin_load(file, &error);
161 alertpanel_error("The following error occured while loading the plugin:\n%s\n", error);
165 set_plugin_list(pluginwindow);
169 static gboolean pluginwindow_key_pressed(GtkWidget *widget, GdkEventKey *event,
170 PluginWindow *pluginwindow)
173 switch (event->keyval) {
177 close_cb(NULL, pluginwindow);
183 load_cb(NULL, pluginwindow);
187 case GDK_KP_Subtract :
189 unload_cb(NULL, pluginwindow);
198 void pluginwindow_create()
200 PluginWindow *pluginwindow;
201 /* ---------------------- code made by glade ---------------------- */
205 GtkWidget *scrolledwindow2;
206 GtkWidget *plugin_list_view;
210 GtkWidget *scrolledwindow3;
211 GtkWidget *plugin_desc;
212 GtkWidget *hbuttonbox1;
214 GtkWidget *unload_btn;
215 GtkWidget *close_btn;
217 pluginwindow = g_new0(PluginWindow, 1);
219 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
220 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
221 gtk_window_set_default_size(GTK_WINDOW(window), 480, 300);
222 gtk_window_set_title(GTK_WINDOW(window), _("Plugins"));
223 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
225 vbox1 = gtk_vbox_new(FALSE, 4);
226 gtk_widget_show(vbox1);
227 gtk_container_add(GTK_CONTAINER(window), vbox1);
229 hbox2 = gtk_hbox_new(FALSE, 8);
230 gtk_widget_show(hbox2);
231 gtk_box_pack_start(GTK_BOX(vbox1), hbox2, TRUE, TRUE, 0);
233 scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL);
234 gtk_widget_show(scrolledwindow2);
235 gtk_box_pack_start(GTK_BOX(hbox2), scrolledwindow2, FALSE, FALSE, 0);
236 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
237 (scrolledwindow2), GTK_POLICY_NEVER,
238 GTK_POLICY_AUTOMATIC);
240 plugin_list_view = pluginwindow_list_view_create(pluginwindow);
241 gtk_widget_show(plugin_list_view);
242 gtk_container_add(GTK_CONTAINER(scrolledwindow2), plugin_list_view);
243 gtk_widget_grab_focus(GTK_WIDGET(plugin_list_view));
245 vbox2 = gtk_vbox_new(FALSE, 0);
246 gtk_widget_show(vbox2);
247 gtk_box_pack_start(GTK_BOX(hbox2), vbox2, TRUE, TRUE, 0);
249 frame2 = gtk_frame_new(NULL);
250 gtk_widget_show(frame2);
251 gtk_box_pack_start(GTK_BOX(vbox2), frame2, FALSE, TRUE, 0);
253 label13 = gtk_label_new(_("Description"));
254 gtk_widget_show(label13);
255 gtk_container_add(GTK_CONTAINER(frame2), label13);
256 gtk_misc_set_alignment(GTK_MISC(label13), 0, 0.5);
257 gtk_misc_set_padding(GTK_MISC(label13), 2, 2);
259 scrolledwindow3 = gtk_scrolled_window_new(NULL, NULL);
260 gtk_widget_show(scrolledwindow3);
261 gtk_box_pack_start(GTK_BOX(vbox2), scrolledwindow3, TRUE, TRUE, 0);
262 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
263 (scrolledwindow3), GTK_POLICY_NEVER,
266 plugin_desc = gtk_text_view_new();
267 gtk_widget_show(plugin_desc);
268 gtk_container_add(GTK_CONTAINER(scrolledwindow3), plugin_desc);
270 hbuttonbox1 = gtk_hbutton_box_new();
271 gtk_widget_show(hbuttonbox1);
272 gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox1, FALSE, FALSE, 0);
273 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1),
275 gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 6);
277 load_btn = gtk_button_new_with_label(_("Load Plugin"));
278 gtk_widget_show(load_btn);
279 gtk_container_add(GTK_CONTAINER(hbuttonbox1), load_btn);
280 GTK_WIDGET_SET_FLAGS(load_btn, GTK_CAN_DEFAULT);
282 unload_btn = gtk_button_new_with_label(_("Unload Plugin"));
283 gtk_widget_show(unload_btn);
284 gtk_container_add(GTK_CONTAINER(hbuttonbox1), unload_btn);
285 GTK_WIDGET_SET_FLAGS(unload_btn, GTK_CAN_DEFAULT);
287 close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
288 gtk_widget_show(close_btn);
289 gtk_container_add(GTK_CONTAINER(hbuttonbox1), close_btn);
290 GTK_WIDGET_SET_FLAGS(close_btn, GTK_CAN_DEFAULT);
291 /* ----------------------------------------------------------- */
293 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(plugin_desc), GTK_WRAP_WORD);
294 gtk_widget_set_sensitive(GTK_WIDGET(unload_btn), FALSE);
297 g_signal_connect(G_OBJECT(load_btn), "released",
298 G_CALLBACK(load_cb), pluginwindow);
299 g_signal_connect(G_OBJECT(unload_btn), "released",
300 G_CALLBACK(unload_cb), pluginwindow);
301 g_signal_connect(G_OBJECT(close_btn), "released",
302 G_CALLBACK(close_cb), pluginwindow);
303 g_signal_connect(G_OBJECT(window), "key_press_event",
304 G_CALLBACK(pluginwindow_key_pressed), pluginwindow);
306 pluginwindow->window = window;
307 pluginwindow->plugin_list_view = plugin_list_view;
308 pluginwindow->plugin_desc = plugin_desc;
309 pluginwindow->unload_btn = unload_btn;
310 pluginwindow->selected_plugin = NULL;
312 set_plugin_list(pluginwindow);
315 gtk_widget_show(window);
318 static GtkListStore* pluginwindow_create_data_store(void)
320 return gtk_list_store_new(N_PLUGINWINDOW_COLUMNS,
326 static GtkWidget *pluginwindow_list_view_create(PluginWindow *pluginwindow)
328 GtkTreeView *list_view;
329 GtkTreeSelection *selector;
332 model = GTK_TREE_MODEL(pluginwindow_create_data_store());
333 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
334 g_object_unref(model);
336 gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
338 selector = gtk_tree_view_get_selection(list_view);
339 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
340 gtk_tree_selection_set_select_function(selector, pluginwindow_selected,
343 /* create the columns */
344 pluginwindow_create_list_view_columns(GTK_WIDGET(list_view));
346 return GTK_WIDGET(list_view);
349 static void pluginwindow_create_list_view_columns(GtkWidget *list_view)
351 GtkTreeViewColumn *column;
352 GtkCellRenderer *renderer;
354 renderer = gtk_cell_renderer_text_new();
355 column = gtk_tree_view_column_new_with_attributes
358 "text", PLUGINWINDOW_NAME,
360 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
363 static gboolean pluginwindow_selected(GtkTreeSelection *selector,
366 gboolean currently_selected,
372 if (!gtk_tree_model_get_iter(model, &iter, path))
375 gtk_tree_model_get(model, &iter,
376 PLUGINWINDOW_DATA, &plugin,
379 if (currently_selected)
380 unselect_row_cb(plugin, data);
382 select_row_cb(plugin, data);