Mercurial > pidgin
comparison console/gntplugin.c @ 14010:7573bd40a190
[gaim-migrate @ 16602]
Allow plugins to be loaded and unloaded.
Remember the window positions and sizes.
All turning on/off shadow from ~/.gntrc (off by default).
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 31 Jul 2006 23:19:12 +0000 |
parents | |
children | 7109e6397a31 |
comparison
equal
deleted
inserted
replaced
14009:1e283c3566ab | 14010:7573bd40a190 |
---|---|
1 #include <gnt.h> | |
2 #include <gntbox.h> | |
3 #include <gntlabel.h> | |
4 #include <gntline.h> | |
5 #include <gnttree.h> | |
6 | |
7 #include "notify.h" | |
8 | |
9 #include "gntgaim.h" | |
10 #include "gntplugin.h" | |
11 | |
12 static struct | |
13 { | |
14 GntWidget *tree; | |
15 GntWidget *window; | |
16 GntWidget *aboot; | |
17 } plugins; | |
18 | |
19 static void | |
20 plugin_toggled_cb(GntWidget *tree, GaimPlugin *plugin, gpointer null) | |
21 { | |
22 if (gnt_tree_get_choice(GNT_TREE(tree), plugin)) | |
23 { | |
24 if(!gaim_plugin_load(plugin)) | |
25 gaim_notify_error(NULL, "ERROR", "loading plugin failed", NULL); | |
26 } | |
27 else | |
28 { | |
29 if (!gaim_plugin_unload(plugin)) | |
30 gaim_notify_error(NULL, "ERROR", "unloading plugin failed", NULL); | |
31 } | |
32 gg_plugins_save_loaded(); | |
33 } | |
34 | |
35 /* Xerox */ | |
36 void | |
37 gg_plugins_save_loaded(void) | |
38 { | |
39 GList *pl; | |
40 GList *files = NULL; | |
41 GaimPlugin *p; | |
42 | |
43 for (pl = gaim_plugins_get_loaded(); pl != NULL; pl = pl->next) { | |
44 p = pl->data; | |
45 | |
46 if (p->info->type != GAIM_PLUGIN_PROTOCOL && | |
47 p->info->type != GAIM_PLUGIN_LOADER) { | |
48 | |
49 files = g_list_append(files, p->path); | |
50 } | |
51 } | |
52 | |
53 gaim_prefs_set_string_list("/gaim/gnt/plugins/loaded", files); | |
54 g_list_free(files); | |
55 } | |
56 | |
57 static void | |
58 selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null) | |
59 { | |
60 GaimPlugin *plugin = current; | |
61 char *text; | |
62 | |
63 /* XXX: Use formatting and stuff */ | |
64 gnt_text_view_clear(GNT_TEXT_VIEW(plugins.aboot)); | |
65 text = g_strdup_printf(_("Name: %s\nVersion: %s\nDescription: %s\nAuthor: %s\nWebsite: %s\nFilename: %s\n"), | |
66 plugin->info->name, plugin->info->version, plugin->info->description, | |
67 plugin->info->author, plugin->info->homepage, plugin->path); | |
68 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(plugins.aboot), | |
69 text, GNT_TEXT_FLAG_NORMAL); | |
70 gnt_text_view_scroll(GNT_TEXT_VIEW(plugins.aboot), 0); | |
71 } | |
72 | |
73 void gg_plugins_show_all() | |
74 { | |
75 GntWidget *window, *tree, *box, *aboot; | |
76 GList *iter; | |
77 if (plugins.window) | |
78 return; | |
79 | |
80 gaim_plugins_probe(G_MODULE_SUFFIX); | |
81 | |
82 plugins.window = window = gnt_vbox_new(FALSE); | |
83 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
84 gnt_box_set_title(GNT_BOX(window), _("Plugins")); | |
85 gnt_box_set_pad(GNT_BOX(window), 0); | |
86 | |
87 gnt_box_add_widget(GNT_BOX(window), | |
88 gnt_label_new(_("You can (un)load plugins from the following list."))); | |
89 gnt_box_add_widget(GNT_BOX(window), gnt_hline_new()); | |
90 | |
91 box = gnt_hbox_new(FALSE); | |
92 gnt_box_add_widget(GNT_BOX(window), box); | |
93 gnt_box_add_widget(GNT_BOX(window), gnt_hline_new()); | |
94 | |
95 gnt_box_set_pad(GNT_BOX(box), 0); | |
96 plugins.tree = tree = gnt_tree_new(); | |
97 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | |
98 gnt_box_add_widget(GNT_BOX(box), tree); | |
99 gnt_box_add_widget(GNT_BOX(box), gnt_vline_new()); | |
100 | |
101 plugins.aboot = aboot = gnt_text_view_new(); | |
102 gnt_widget_set_size(aboot, 40, 20); | |
103 gnt_box_add_widget(GNT_BOX(box), aboot); | |
104 | |
105 for (iter = gaim_plugins_get_all(); iter; iter = iter->next) | |
106 { | |
107 GaimPlugin *plug = iter->data; | |
108 | |
109 if (plug->info->type != GAIM_PLUGIN_STANDARD || | |
110 (plug->info->flags & GAIM_PLUGIN_FLAG_INVISIBLE) || | |
111 plug->error) | |
112 continue; | |
113 | |
114 gnt_tree_add_choice(GNT_TREE(tree), plug, | |
115 gnt_tree_create_row(GNT_TREE(tree), plug->info->name), NULL, NULL); | |
116 gnt_tree_set_choice(GNT_TREE(tree), plug, gaim_plugin_is_loaded(plug)); | |
117 } | |
118 gnt_tree_set_col_width(GNT_TREE(tree), 0, 30); | |
119 g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(plugin_toggled_cb), NULL); | |
120 g_signal_connect(G_OBJECT(tree), "selection_changed", G_CALLBACK(selection_changed), NULL); | |
121 | |
122 gnt_widget_show(window); | |
123 } | |
124 |