Mercurial > pidgin.yaz
comparison finch/gntplugin.c @ 20716:227e397d8e80
Add a 'Install plugin...' button in the plugins dialog.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 29 Sep 2007 08:53:53 +0000 |
parents | 8ed95ae6441b |
children | fdefa5eb46e2 e34e56eeb2da |
comparison
equal
deleted
inserted
replaced
20715:df58938e9f61 | 20716:227e397d8e80 |
---|---|
30 #include <gntline.h> | 30 #include <gntline.h> |
31 #include <gnttree.h> | 31 #include <gnttree.h> |
32 | 32 |
33 #include "finch.h" | 33 #include "finch.h" |
34 | 34 |
35 #include "debug.h" | |
35 #include "notify.h" | 36 #include "notify.h" |
36 #include "request.h" | 37 #include "request.h" |
37 | 38 |
38 #include "gntplugin.h" | 39 #include "gntplugin.h" |
39 #include "gntrequest.h" | 40 #include "gntrequest.h" |
235 _("No configuration options for this plugin."), NULL); | 236 _("No configuration options for this plugin."), NULL); |
236 return; | 237 return; |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
241 static void | |
242 install_selected_file_cb(gpointer handle, const char *filename) | |
243 { | |
244 /* Try to init the selected file. | |
245 * If it succeeds, try to make a copy of the file in $USERDIR/plugins/. | |
246 * If the copy succeeds, unload and destroy the plugin in the original | |
247 * location and init+load the new one. | |
248 * Select the plugin in the plugin list. | |
249 */ | |
250 char *path; | |
251 PurplePlugin *plugin; | |
252 | |
253 g_return_if_fail(plugins.window); | |
254 | |
255 plugin = purple_plugin_probe(filename); | |
256 if (!plugin) { | |
257 purple_notify_error(handle, _("Error loading plugin"), | |
258 _("The selected file is not a valid plugin."), | |
259 _("Please open the debug window and try again to see the exact error message.")); | |
260 return; | |
261 } | |
262 if (g_list_find(gnt_tree_get_rows(GNT_TREE(plugins.tree)), plugin)) { | |
263 purple_plugin_load(plugin); | |
264 gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin)); | |
265 gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin); | |
266 return; | |
267 } | |
268 | |
269 path = g_build_filename(purple_user_dir(), "plugins", NULL); | |
270 if (purple_build_dir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0) { | |
271 char *content = NULL; | |
272 gsize length = 0; | |
273 | |
274 if (g_file_get_contents(filename, &content, &length, NULL)) { | |
275 char *file = g_path_get_basename(filename); | |
276 g_free(path); | |
277 path = g_build_filename(purple_user_dir(), "plugins", file, NULL); | |
278 if (purple_util_write_data_to_file_absolute(path, content, length)) { | |
279 purple_plugin_destroy(plugin); | |
280 plugin = purple_plugin_probe(path); | |
281 if (!plugin) { | |
282 purple_debug_warning("gntplugin", "This is really strange. %s can be loaded, but %s can't!\n", | |
283 filename, path); | |
284 g_unlink(path); | |
285 plugin = purple_plugin_probe(filename); | |
286 } | |
287 } else { | |
288 } | |
289 } | |
290 g_free(content); | |
291 } | |
292 g_free(path); | |
293 | |
294 purple_plugin_load(plugin); | |
295 | |
296 if (plugin->info->type == PURPLE_PLUGIN_LOADER) { | |
297 GList *cur; | |
298 for (cur = PURPLE_PLUGIN_LOADER_INFO(plugin)->exts; cur != NULL; | |
299 cur = cur->next) | |
300 purple_plugins_probe(cur->data); | |
301 return; | |
302 } | |
303 | |
304 if (plugin->info->type != PURPLE_PLUGIN_STANDARD || | |
305 (plugin->info->flags & PURPLE_PLUGIN_FLAG_INVISIBLE) || | |
306 plugin->error) | |
307 return; | |
308 | |
309 gnt_tree_add_choice(GNT_TREE(plugins.tree), plugin, | |
310 gnt_tree_create_row(GNT_TREE(plugins.tree), plugin->info->name), NULL, NULL); | |
311 gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin)); | |
312 gnt_tree_set_row_flags(GNT_TREE(plugins.tree), plugin, GNT_TEXT_FLAG_BOLD); | |
313 gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin); | |
314 } | |
315 | |
316 static void | |
317 install_plugin_cb(GntWidget *w, gpointer null) | |
318 { | |
319 static int handle; | |
320 | |
321 purple_request_close_with_handle(&handle); | |
322 purple_request_file(&handle, _("Select plugin to install"), NULL, | |
323 FALSE, G_CALLBACK(install_selected_file_cb), NULL, | |
324 NULL, NULL, NULL, &handle); | |
325 g_signal_connect_swapped(G_OBJECT(w), "destroy", G_CALLBACK(purple_request_close_with_handle), &handle); | |
326 } | |
327 | |
240 void finch_plugins_show_all() | 328 void finch_plugins_show_all() |
241 { | 329 { |
242 GntWidget *window, *tree, *box, *aboot, *button; | 330 GntWidget *window, *tree, *box, *aboot, *button; |
243 GList *iter; | 331 GList *iter; |
244 GList *seen; | 332 GList *seen; |
305 g_signal_connect(G_OBJECT(tree), "selection_changed", G_CALLBACK(selection_changed), NULL); | 393 g_signal_connect(G_OBJECT(tree), "selection_changed", G_CALLBACK(selection_changed), NULL); |
306 g_object_set_data(G_OBJECT(tree), "seen-list", seen); | 394 g_object_set_data(G_OBJECT(tree), "seen-list", seen); |
307 | 395 |
308 box = gnt_hbox_new(FALSE); | 396 box = gnt_hbox_new(FALSE); |
309 gnt_box_add_widget(GNT_BOX(window), box); | 397 gnt_box_add_widget(GNT_BOX(window), box); |
398 | |
399 button = gnt_button_new(_("Install Plugin...")); | |
400 gnt_box_add_widget(GNT_BOX(box), button); | |
401 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(install_plugin_cb), NULL); | |
310 | 402 |
311 button = gnt_button_new(_("Close")); | 403 button = gnt_button_new(_("Close")); |
312 gnt_box_add_widget(GNT_BOX(box), button); | 404 gnt_box_add_widget(GNT_BOX(box), button); |
313 g_signal_connect_swapped(G_OBJECT(button), "activate", | 405 g_signal_connect_swapped(G_OBJECT(button), "activate", |
314 G_CALLBACK(gnt_widget_destroy), window); | 406 G_CALLBACK(gnt_widget_destroy), window); |