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.
32 #include "alertpanel.h"
34 typedef struct _PluginWindow
37 GtkWidget *plugin_list;
38 GtkWidget *plugin_desc;
39 GtkWidget *unload_btn;
41 Plugin *selected_plugin;
44 static void close_cb(GtkButton *button, PluginWindow *pluginwindow)
46 gtk_widget_destroy(pluginwindow->window);
52 static void set_plugin_list(PluginWindow *pluginwindow)
54 GSList *plugins, *cur;
57 GtkCList *clist = GTK_CLIST(pluginwindow->plugin_list);
58 GtkTextBuffer *textbuf;
59 GtkTextIter start_iter, end_iter;
61 plugins = plugin_get_list();
62 gtk_clist_freeze(clist);
63 gtk_clist_clear(clist);
64 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pluginwindow->plugin_desc));
65 gtk_text_buffer_get_start_iter(textbuf, &start_iter);
66 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
67 gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
68 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
70 for(cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
71 Plugin *plugin = (Plugin *) cur->data;
73 text[0] = (gchar *) plugin_get_name(plugin);
74 row = gtk_clist_append(clist, text);
75 gtk_clist_set_row_data(clist, row, plugin);
77 gtk_clist_thaw(clist);
80 static void select_row_cb(GtkCList *clist, gint row, gint column,
81 GdkEventButton *event, PluginWindow *pluginwindow)
84 GtkTextView *plugin_desc = GTK_TEXT_VIEW(pluginwindow->plugin_desc);
85 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(plugin_desc);
86 GtkTextIter start_iter, end_iter;
89 plugin = (Plugin *) gtk_clist_get_row_data(clist, row);
90 pluginwindow->selected_plugin = plugin;
92 if (pluginwindow->selected_plugin != NULL) {
93 gtk_text_buffer_get_start_iter(textbuf, &start_iter);
94 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
95 gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
96 text = plugin_get_desc(plugin);
97 gtk_text_buffer_insert(textbuf, &start_iter, text, strlen(text));
98 gtk_widget_set_sensitive(pluginwindow->unload_btn, TRUE);
100 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
104 static void unselect_row_cb(GtkCList * clist, gint row, gint column,
105 GdkEventButton * event, PluginWindow *pluginwindow)
107 gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);
110 static void unload_cb(GtkButton *button, PluginWindow *pluginwindow)
112 Plugin *plugin = pluginwindow->selected_plugin;
114 g_return_if_fail(plugin != NULL);
115 plugin_unload(plugin);
116 set_plugin_list(pluginwindow);
119 static void load_cb(GtkButton *button, PluginWindow *pluginwindow)
121 gchar *file, *error = NULL;
123 file = filesel_select_file(_("Select Plugin to load"), PLUGINDIR);
127 plugin_load(file, &error);
129 alertpanel_error("The following error occured while loading the plugin:\n%s\n", error);
133 set_plugin_list(pluginwindow);
136 void pluginwindow_create()
138 PluginWindow *pluginwindow;
139 /* ---------------------- code made by glade ---------------------- */
143 GtkWidget *scrolledwindow2;
144 GtkWidget *plugin_list;
149 GtkWidget *scrolledwindow3;
150 GtkWidget *plugin_desc;
151 GtkWidget *hbuttonbox1;
153 GtkWidget *unload_btn;
154 GtkWidget *close_btn;
156 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
157 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
158 gtk_window_set_default_size(GTK_WINDOW(window), 480, 300);
159 gtk_window_set_title(GTK_WINDOW(window), _("Plugins"));
160 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
162 vbox1 = gtk_vbox_new(FALSE, 4);
163 gtk_widget_show(vbox1);
164 gtk_container_add(GTK_CONTAINER(window), vbox1);
166 hbox2 = gtk_hbox_new(FALSE, 8);
167 gtk_widget_show(hbox2);
168 gtk_box_pack_start(GTK_BOX(vbox1), hbox2, TRUE, TRUE, 0);
170 scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL);
171 gtk_widget_show(scrolledwindow2);
172 gtk_box_pack_start(GTK_BOX(hbox2), scrolledwindow2, TRUE, TRUE, 0);
173 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
174 (scrolledwindow2), GTK_POLICY_NEVER,
177 plugin_list = gtk_clist_new(1);
178 gtk_widget_show(plugin_list);
179 gtk_container_add(GTK_CONTAINER(scrolledwindow2), plugin_list);
180 gtk_clist_set_column_width(GTK_CLIST(plugin_list), 0, 80);
181 gtk_clist_column_titles_show(GTK_CLIST(plugin_list));
183 label12 = gtk_label_new(_("Plugins"));
184 gtk_widget_show(label12);
185 gtk_clist_set_column_widget(GTK_CLIST(plugin_list), 0, label12);
186 gtk_label_set_justify(GTK_LABEL(label12), GTK_JUSTIFY_LEFT);
187 gtk_misc_set_alignment(GTK_MISC(label12), 0, 0.5);
189 vbox2 = gtk_vbox_new(FALSE, 0);
190 gtk_widget_show(vbox2);
191 gtk_box_pack_start(GTK_BOX(hbox2), vbox2, TRUE, TRUE, 0);
193 frame2 = gtk_frame_new(NULL);
194 gtk_widget_show(frame2);
195 gtk_box_pack_start(GTK_BOX(vbox2), frame2, FALSE, TRUE, 0);
197 label13 = gtk_label_new(_("Description"));
198 gtk_widget_show(label13);
199 gtk_container_add(GTK_CONTAINER(frame2), label13);
200 gtk_misc_set_alignment(GTK_MISC(label13), 0, 0.5);
201 gtk_misc_set_padding(GTK_MISC(label13), 2, 2);
203 scrolledwindow3 = gtk_scrolled_window_new(NULL, NULL);
204 gtk_widget_show(scrolledwindow3);
205 gtk_box_pack_start(GTK_BOX(vbox2), scrolledwindow3, TRUE, TRUE, 0);
206 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
207 (scrolledwindow3), GTK_POLICY_NEVER,
210 plugin_desc = gtk_text_view_new();
211 gtk_widget_show(plugin_desc);
212 gtk_container_add(GTK_CONTAINER(scrolledwindow3), plugin_desc);
214 hbuttonbox1 = gtk_hbutton_box_new();
215 gtk_widget_show(hbuttonbox1);
216 gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox1, FALSE, FALSE, 0);
217 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1),
219 gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 0);
221 load_btn = gtk_button_new_with_label(_("Load Plugin"));
222 gtk_widget_show(load_btn);
223 gtk_container_add(GTK_CONTAINER(hbuttonbox1), load_btn);
224 GTK_WIDGET_SET_FLAGS(load_btn, GTK_CAN_DEFAULT);
226 unload_btn = gtk_button_new_with_label(_("Unload Plugin"));
227 gtk_widget_show(unload_btn);
228 gtk_container_add(GTK_CONTAINER(hbuttonbox1), unload_btn);
229 GTK_WIDGET_SET_FLAGS(unload_btn, GTK_CAN_DEFAULT);
231 close_btn = gtk_button_new_with_label(_("Close"));
232 gtk_widget_show(close_btn);
233 gtk_container_add(GTK_CONTAINER(hbuttonbox1), close_btn);
234 GTK_WIDGET_SET_FLAGS(close_btn, GTK_CAN_DEFAULT);
235 /* ----------------------------------------------------------- */
237 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(plugin_desc), GTK_WRAP_WORD);
238 gtk_widget_set_sensitive(GTK_WIDGET(unload_btn), FALSE);
240 pluginwindow = g_new0(PluginWindow, 1);
242 g_signal_connect(G_OBJECT(load_btn), "released",
243 G_CALLBACK(load_cb), pluginwindow);
244 g_signal_connect(G_OBJECT(unload_btn), "released",
245 G_CALLBACK(unload_cb), pluginwindow);
246 g_signal_connect(G_OBJECT(close_btn), "released",
247 G_CALLBACK(close_cb), pluginwindow);
248 g_signal_connect(G_OBJECT(plugin_list), "select-row",
249 G_CALLBACK(select_row_cb), pluginwindow);
250 g_signal_connect(G_OBJECT(plugin_list), "unselect-row",
251 G_CALLBACK(unselect_row_cb), pluginwindow);
253 pluginwindow->window = window;
254 pluginwindow->plugin_list = plugin_list;
255 pluginwindow->plugin_desc = plugin_desc;
256 pluginwindow->unload_btn = unload_btn;
257 pluginwindow->selected_plugin = NULL;
259 set_plugin_list(pluginwindow);
262 gtk_widget_show(window);