comparison src/gtkplugin.c @ 11740:7e0ad3b6882a

[gaim-migrate @ 14031] Moved Plugins to Tools > Plugins Made iChat Timestamp plugin instant apply Made Proxy options visible only when needed. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sun, 23 Oct 2005 07:12:12 +0000
parents 4a15962c344a
children 8034f752feae
comparison
equal deleted inserted replaced
11739:a25be0e70a67 11740:7e0ad3b6882a
20 * 20 *
21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 24 */
25 #include "internal.h"
25 #include "gtkgaim.h" 26 #include "gtkgaim.h"
26 #include "gtkplugin.h" 27 #include "gtkplugin.h"
27 #include "debug.h" 28 #include "debug.h"
28 #include "prefs.h" 29 #include "prefs.h"
29 30
30 #include <string.h> 31 #include <string.h>
31 32
33 static GtkWidget *plugin_dialog = NULL;
34 static GtkWidget *plugin_details = NULL;
35 static GtkWidget *pref_button = NULL;
32 GtkWidget * 36 GtkWidget *
33 gaim_gtk_plugin_get_config_frame(GaimPlugin *plugin) 37 gaim_gtk_plugin_get_config_frame(GaimPlugin *plugin)
34 { 38 {
35 GaimGtkPluginUiInfo *ui_info; 39 GaimGtkPluginUiInfo *ui_info;
36 40
66 } 70 }
67 71
68 gaim_prefs_set_string_list("/gaim/gtk/plugins/loaded", files); 72 gaim_prefs_set_string_list("/gaim/gtk/plugins/loaded", files);
69 g_list_free(files); 73 g_list_free(files);
70 } 74 }
75
76 static void
77 update_plugin_list(void *data)
78 {
79 GtkListStore *ls = GTK_LIST_STORE(data);
80 GtkTreeIter iter;
81 GList *probes;
82 GaimPlugin *plug;
83
84 gtk_list_store_clear(ls);
85 gaim_plugins_probe(GAIM_PLUGIN_EXT);
86
87 for (probes = gaim_plugins_get_all();
88 probes != NULL;
89 probes = probes->next)
90 {
91 char *desc;
92 plug = probes->data;
93
94 if (plug->info->type != GAIM_PLUGIN_STANDARD ||
95 (plug->info->flags & GAIM_PLUGIN_FLAG_INVISIBLE))
96 {
97 continue;
98 }
99
100 gtk_list_store_append (ls, &iter);
101 desc = g_strdup_printf("<b>%s</b> %s\n%s", plug->info->name ? _(plug->info->name) : g_basename(plug->path),
102 plug->info->version,
103 plug->info->summary);
104 gtk_list_store_set(ls, &iter,
105 0, gaim_plugin_is_loaded(plug),
106 1, desc,
107 2, plug, -1);
108 g_free(desc);
109 }
110 }
111
112 static void plugin_load (GtkCellRendererToggle *cell, gchar *pth, gpointer data)
113 {
114 GtkTreeModel *model = (GtkTreeModel *)data;
115 GtkTreeIter iter;
116 GtkTreePath *path = gtk_tree_path_new_from_string(pth);
117 GaimPlugin *plug;
118 gchar buf[1024];
119 gchar *name = NULL, *description = NULL;
120
121 GdkCursor *wait = gdk_cursor_new (GDK_WATCH);
122 gdk_window_set_cursor(plugin_dialog, wait);
123 gdk_cursor_unref(wait);
124
125 gtk_tree_model_get_iter (model, &iter, path);
126 gtk_tree_model_get (model, &iter, 2, &plug, -1);
127
128 if (!gaim_plugin_is_loaded(plug))
129 gaim_plugin_load(plug);
130 else
131 gaim_plugin_unload(plug);
132
133
134 gdk_window_set_cursor(plugin_dialog, NULL);
135
136 name = g_markup_escape_text(_(plug->info->name), -1);
137 description = g_markup_escape_text(_(plug->info->description), -1);
138
139 if (plug->error != NULL) {
140 gchar *error = g_markup_escape_text(plug->error, -1);
141 gchar *desc;
142 g_snprintf(buf, sizeof(buf),
143 "<span size=\"larger\">%s %s</span>\n\n"
144 "<span weight=\"bold\" color=\"red\">%s</span>\n\n"
145 "%s",
146 name, plug->info->version, error, description);
147 desc = g_strdup_printf("<b>%s</b> %s\n<span weight=\"bold\" color=\"red\"%s</span>",
148 plug->info->name, plug->info->version, error);
149 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
150 1, desc,
151 -1);
152 g_free(desc);
153 g_free(error);
154 } else {
155 g_snprintf(buf, sizeof(buf),
156 "<span size=\"larger\">%s %s</span>\n\n%s",
157 name, plug->info->version, description);
158 }
159 g_free(name);
160 g_free(description);
161
162
163 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
164 0, gaim_plugin_is_loaded(plug),
165 -1);
166
167 gtk_label_set_markup(GTK_LABEL(plugin_details), buf);
168 gtk_tree_path_free(path);
169 gaim_gtk_plugins_save();
170 }
171
172 static void prefs_plugin_sel (GtkTreeSelection *sel, GtkTreeModel *model)
173 {
174 gchar *buf, *pname, *perr, *pdesc, *pauth, *pweb;
175 GtkTreeIter iter;
176 GValue val = { 0, };
177 GaimPlugin *plug;
178 GaimGtkPluginUiInfo *ui_info;
179
180 if (! gtk_tree_selection_get_selected (sel, &model, &iter))
181 return;
182 gtk_tree_model_get_value (model, &iter, 2, &val);
183 plug = g_value_get_pointer(&val);
184
185 pname = g_markup_escape_text(_(plug->info->name), -1);
186 pdesc = (plug->info->description) ?
187 g_markup_escape_text(_(plug->info->description), -1) : NULL;
188 pauth = (plug->info->author) ?
189 g_markup_escape_text(_(plug->info->author), -1) : NULL;
190 pweb = (plug->info->homepage) ?
191 g_markup_escape_text(_(plug->info->homepage), -1) : NULL;
192 buf = g_strdup_printf(
193 #ifndef _WIN32
194 _("<span size=\"larger\">%s %s</span>\n\n"
195 "%s%s"
196 "<span weight=\"bold\">Written by:</span>\t%s\n"
197 "<span weight=\"bold\">Web site:</span>\t\t%s\n"
198 "<span weight=\"bold\">File name:</span>\t%s"),
199 #else
200 _("<span size=\"larger\">%s %s</span>\n\n"
201 "%s%s"
202 "<span weight=\"bold\">Written by:</span> %s\n"
203 "<span weight=\"bold\">Web site:</span> %s\n"
204 "<span weight=\"bold\">File name:</span> %s"),
205 #endif
206 pname, plug->info->version, pdesc ? pdesc : "", pdesc ? "\n\n" : "",
207 pauth ? pauth : "", pweb ? pweb : "", plug->path);
208
209 gtk_widget_set_sensitive(pref_button,
210 plug->info->ui_info != NULL &&
211 GAIM_GTK_PLUGIN_UI_INFO(plug)->get_config_frame != NULL);
212 gtk_label_set_markup(GTK_LABEL(plugin_details), buf);
213 g_value_unset(&val);
214 g_free(buf);
215 g_free(pname);
216 g_free(pdesc);
217 g_free(pauth);
218 g_free(pweb);
219 }
220
221 static void pref_dialog_response_cb(GtkDialog *d, int response, void *null)
222 {
223 switch (response) {
224 case GTK_RESPONSE_CLOSE:
225 case GTK_RESPONSE_DELETE_EVENT:
226 gtk_widget_destroy(d);
227 plugin_dialog = NULL;
228 break;
229 }
230 }
231 static void plugin_dialog_response_cb(GtkDialog *d, int response, GtkTreeSelection *sel)
232 {
233 GaimPlugin *plug;
234 GtkWidget *dialog, *box;
235 GtkTreeModel *model;
236 GValue val;
237 GtkTreeIter iter;
238
239 switch (response) {
240 case GTK_RESPONSE_CLOSE:
241 case GTK_RESPONSE_DELETE_EVENT:
242 gtk_widget_destroy(d);
243 plugin_dialog = NULL;
244 break;
245 case 98121:
246 if (! gtk_tree_selection_get_selected (sel, &model, &iter))
247 return;
248 gtk_tree_model_get_value (model, &iter, 2, &val);
249 plug = g_value_get_pointer(&val);
250 if (plug == NULL)
251 break;
252 box = gaim_gtk_plugin_get_config_frame(plug);
253 if (box == NULL)
254 break;
255
256 dialog = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, d,
257 GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_MODAL,
258 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
259 NULL);
260 g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(pref_dialog_response_cb), NULL);
261 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box);
262 gtk_widget_show_all(dialog);
263 break;
264 }
265 }
266
267 void gaim_gtk_plugin_dialog_show()
268 {
269 GtkWidget *sw, *vp;
270 GtkWidget *event_view;
271 GtkListStore *ls;
272 GtkCellRenderer *rend, *rendt;
273 GtkTreeViewColumn *col;
274 GtkTreeSelection *sel;
275 GtkTreePath *path;
276 GtkWidget *expander;
277
278 if (plugin_dialog != NULL) {
279 gtk_window_present(GTK_WINDOW(plugin_dialog));
280 return;
281 }
282
283 plugin_dialog = gtk_dialog_new_with_buttons(_("Plugins"),
284 NULL,
285 GTK_DIALOG_NO_SEPARATOR,
286 NULL);
287 pref_button = gtk_dialog_add_button(GTK_DIALOG(plugin_dialog), GTK_STOCK_PREFERENCES, 98121);
288 gtk_dialog_add_button(GTK_DIALOG(plugin_dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
289
290 sw = gtk_scrolled_window_new(NULL,NULL);
291 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
292 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
293
294 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(plugin_dialog)->vbox), sw, TRUE, TRUE, 0);
295
296 ls = gtk_list_store_new (3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER);
297 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls),
298 1, GTK_SORT_ASCENDING);
299
300 update_plugin_list(ls);
301
302 event_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(ls));
303
304 rend = gtk_cell_renderer_toggle_new();
305 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (event_view));
306
307 col = gtk_tree_view_column_new_with_attributes (_("Enabled"),
308 rend,
309 "active", 0,
310 NULL);
311 gtk_tree_view_append_column (GTK_TREE_VIEW(event_view), col);
312 g_signal_connect (G_OBJECT(rend), "toggled",
313 G_CALLBACK(plugin_load), ls);
314
315 rendt = gtk_cell_renderer_text_new();
316 col = gtk_tree_view_column_new_with_attributes (_("Name"),
317 rendt,
318 "markup", 1,
319 NULL);
320 #if GTK_CHECK_VERSION(2,6,0)
321 gtk_tree_view_column_set_expand (col, TRUE);
322 g_object_set(rendt, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
323 #endif
324 gtk_tree_view_append_column (GTK_TREE_VIEW(event_view), col);
325 g_object_unref(G_OBJECT(ls));
326 gtk_container_add(GTK_CONTAINER(sw), event_view);
327
328 expander = gtk_expander_new(_("<b>Plugin Details</b>"));
329 gtk_expander_set_use_markup(GTK_EXPANDER(expander), TRUE);
330 plugin_details = gtk_label_new(NULL);
331 gtk_label_set_line_wrap(GTK_LABEL(plugin_details), TRUE);
332 gtk_container_add(GTK_CONTAINER(expander), plugin_details);
333 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(plugin_dialog)->vbox), expander, FALSE, FALSE, 0);
334
335 g_signal_connect (G_OBJECT (sel), "changed", G_CALLBACK (prefs_plugin_sel), NULL);
336 g_signal_connect(G_OBJECT(plugin_dialog), "response", G_CALLBACK(plugin_dialog_response_cb), sel);
337 gtk_window_set_default_size(GTK_WINDOW(plugin_dialog), 430, 430);
338 gtk_widget_show_all(plugin_dialog);
339 }