Mercurial > pidgin
comparison finch/gntplugin.c @ 15817:0e3a8505ebbe
renamed gaim-text to finch
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 18 Mar 2007 19:38:15 +0000 |
parents | |
children | 32c366eeeb99 |
comparison
equal
deleted
inserted
replaced
15816:317e7613e581 | 15817:0e3a8505ebbe |
---|---|
1 /** | |
2 * @file gntplugin.c GNT Plugins API | |
3 * @ingroup gntui | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
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 | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include <gnt.h> | |
26 #include <gntbox.h> | |
27 #include <gntbutton.h> | |
28 #include <gntlabel.h> | |
29 #include <gntline.h> | |
30 #include <gnttree.h> | |
31 | |
32 #include "notify.h" | |
33 | |
34 #include "gntgaim.h" | |
35 #include "gntplugin.h" | |
36 | |
37 static struct | |
38 { | |
39 GntWidget *tree; | |
40 GntWidget *window; | |
41 GntWidget *aboot; | |
42 GntWidget *conf; | |
43 } plugins; | |
44 | |
45 static GHashTable *confwins; | |
46 | |
47 static void | |
48 decide_conf_button(GaimPlugin *plugin) | |
49 { | |
50 if (gaim_plugin_is_loaded(plugin) && | |
51 ((GAIM_IS_GNT_PLUGIN(plugin) && | |
52 GAIM_GNT_PLUGIN_UI_INFO(plugin) != NULL) || | |
53 (plugin->info->prefs_info && | |
54 plugin->info->prefs_info->get_plugin_pref_frame))) | |
55 gnt_widget_set_visible(plugins.conf, TRUE); | |
56 else | |
57 gnt_widget_set_visible(plugins.conf, FALSE); | |
58 | |
59 gnt_box_readjust(GNT_BOX(plugins.window)); | |
60 gnt_widget_draw(plugins.window); | |
61 } | |
62 | |
63 static void | |
64 plugin_toggled_cb(GntWidget *tree, GaimPlugin *plugin, gpointer null) | |
65 { | |
66 if (gnt_tree_get_choice(GNT_TREE(tree), plugin)) | |
67 { | |
68 if(!gaim_plugin_load(plugin)) | |
69 gaim_notify_error(NULL, "ERROR", "loading plugin failed", NULL); | |
70 } | |
71 else | |
72 { | |
73 GntWidget *win; | |
74 | |
75 if (!gaim_plugin_unload(plugin)) | |
76 gaim_notify_error(NULL, "ERROR", "unloading plugin failed", NULL); | |
77 | |
78 if ((win = g_hash_table_lookup(confwins, plugin)) != NULL) | |
79 { | |
80 gnt_widget_destroy(win); | |
81 } | |
82 } | |
83 decide_conf_button(plugin); | |
84 finch_plugins_save_loaded(); | |
85 } | |
86 | |
87 /* Xerox */ | |
88 void | |
89 finch_plugins_save_loaded(void) | |
90 { | |
91 gaim_plugins_save_loaded("/gaim/gnt/plugins/loaded"); | |
92 } | |
93 | |
94 static void | |
95 selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null) | |
96 { | |
97 GaimPlugin *plugin = current; | |
98 char *text; | |
99 | |
100 /* XXX: Use formatting and stuff */ | |
101 gnt_text_view_clear(GNT_TEXT_VIEW(plugins.aboot)); | |
102 text = g_strdup_printf(_("Name: %s\nVersion: %s\nDescription: %s\nAuthor: %s\nWebsite: %s\nFilename: %s\n"), | |
103 SAFE(plugin->info->name), SAFE(plugin->info->version), SAFE(plugin->info->description), | |
104 SAFE(plugin->info->author), SAFE(plugin->info->homepage), SAFE(plugin->path)); | |
105 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(plugins.aboot), | |
106 text, GNT_TEXT_FLAG_NORMAL); | |
107 gnt_text_view_scroll(GNT_TEXT_VIEW(plugins.aboot), 0); | |
108 g_free(text); | |
109 decide_conf_button(plugin); | |
110 } | |
111 | |
112 static void | |
113 reset_plugin_window(GntWidget *window, gpointer null) | |
114 { | |
115 plugins.window = NULL; | |
116 plugins.tree = NULL; | |
117 plugins.aboot = NULL; | |
118 } | |
119 | |
120 static int | |
121 plugin_compare(GaimPlugin *p1, GaimPlugin *p2) | |
122 { | |
123 char *s1 = g_utf8_strup(p1->info->name, -1); | |
124 char *s2 = g_utf8_strup(p2->info->name, -1); | |
125 int ret = g_utf8_collate(s1, s2); | |
126 g_free(s1); | |
127 g_free(s2); | |
128 return ret; | |
129 } | |
130 | |
131 static void | |
132 confwin_init() | |
133 { | |
134 confwins = g_hash_table_new(g_direct_hash, g_direct_equal); | |
135 } | |
136 | |
137 static void | |
138 remove_confwin(GntWidget *window, gpointer plugin) | |
139 { | |
140 g_hash_table_remove(confwins, plugin); | |
141 } | |
142 | |
143 static void | |
144 configure_plugin_cb(GntWidget *button, gpointer null) | |
145 { | |
146 GaimPlugin *plugin; | |
147 FinchPluginFrame callback; | |
148 | |
149 g_return_if_fail(plugins.tree != NULL); | |
150 | |
151 plugin = gnt_tree_get_selection_data(GNT_TREE(plugins.tree)); | |
152 if (!gaim_plugin_is_loaded(plugin)) | |
153 { | |
154 gaim_notify_error(plugin, _("Error"), | |
155 _("Plugin need to be loaded before you can configure it."), NULL); | |
156 return; | |
157 } | |
158 | |
159 if (confwins && g_hash_table_lookup(confwins, plugin)) | |
160 return; | |
161 | |
162 if (GAIM_IS_GNT_PLUGIN(plugin) && | |
163 (callback = GAIM_GNT_PLUGIN_UI_INFO(plugin)) != NULL) | |
164 { | |
165 GntWidget *window = gnt_vbox_new(FALSE); | |
166 GntWidget *box, *button; | |
167 | |
168 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
169 gnt_box_set_title(GNT_BOX(window), plugin->info->name); | |
170 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
171 | |
172 box = callback(); | |
173 gnt_box_add_widget(GNT_BOX(window), box); | |
174 | |
175 box = gnt_hbox_new(FALSE); | |
176 gnt_box_add_widget(GNT_BOX(window), box); | |
177 | |
178 button = gnt_button_new(_("Close")); | |
179 gnt_box_add_widget(GNT_BOX(box), button); | |
180 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
181 G_CALLBACK(gnt_widget_destroy), window); | |
182 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(remove_confwin), plugin); | |
183 | |
184 gnt_widget_show(window); | |
185 | |
186 if (confwins == NULL) | |
187 confwin_init(); | |
188 g_hash_table_insert(confwins, plugin, window); | |
189 } | |
190 else if (plugin->info->prefs_info && | |
191 plugin->info->prefs_info->get_plugin_pref_frame) | |
192 { | |
193 gaim_notify_info(plugin, _("..."), | |
194 _("Still need to do something about this."), NULL); | |
195 return; | |
196 } | |
197 else | |
198 { | |
199 gaim_notify_info(plugin, _("Error"), | |
200 _("No configuration options for this plugin."), NULL); | |
201 return; | |
202 } | |
203 } | |
204 | |
205 void finch_plugins_show_all() | |
206 { | |
207 GntWidget *window, *tree, *box, *aboot, *button; | |
208 GList *iter; | |
209 if (plugins.window) | |
210 return; | |
211 | |
212 gaim_plugins_probe(G_MODULE_SUFFIX); | |
213 | |
214 plugins.window = window = gnt_vbox_new(FALSE); | |
215 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
216 gnt_box_set_title(GNT_BOX(window), _("Plugins")); | |
217 gnt_box_set_pad(GNT_BOX(window), 0); | |
218 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
219 | |
220 gnt_box_add_widget(GNT_BOX(window), | |
221 gnt_label_new(_("You can (un)load plugins from the following list."))); | |
222 gnt_box_add_widget(GNT_BOX(window), gnt_hline_new()); | |
223 | |
224 box = gnt_hbox_new(FALSE); | |
225 gnt_box_add_widget(GNT_BOX(window), box); | |
226 gnt_box_add_widget(GNT_BOX(window), gnt_hline_new()); | |
227 | |
228 gnt_box_set_pad(GNT_BOX(box), 0); | |
229 plugins.tree = tree = gnt_tree_new(); | |
230 gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)plugin_compare); | |
231 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | |
232 gnt_box_add_widget(GNT_BOX(box), tree); | |
233 gnt_box_add_widget(GNT_BOX(box), gnt_vline_new()); | |
234 | |
235 plugins.aboot = aboot = gnt_text_view_new(); | |
236 gnt_widget_set_size(aboot, 40, 20); | |
237 gnt_box_add_widget(GNT_BOX(box), aboot); | |
238 | |
239 for (iter = gaim_plugins_get_all(); iter; iter = iter->next) | |
240 { | |
241 GaimPlugin *plug = iter->data; | |
242 | |
243 if (plug->info->type != GAIM_PLUGIN_STANDARD || | |
244 (plug->info->flags & GAIM_PLUGIN_FLAG_INVISIBLE) || | |
245 plug->error) | |
246 continue; | |
247 | |
248 gnt_tree_add_choice(GNT_TREE(tree), plug, | |
249 gnt_tree_create_row(GNT_TREE(tree), plug->info->name), NULL, NULL); | |
250 gnt_tree_set_choice(GNT_TREE(tree), plug, gaim_plugin_is_loaded(plug)); | |
251 } | |
252 gnt_tree_set_col_width(GNT_TREE(tree), 0, 30); | |
253 g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(plugin_toggled_cb), NULL); | |
254 g_signal_connect(G_OBJECT(tree), "selection_changed", G_CALLBACK(selection_changed), NULL); | |
255 | |
256 box = gnt_hbox_new(FALSE); | |
257 gnt_box_add_widget(GNT_BOX(window), box); | |
258 | |
259 button = gnt_button_new(_("Close")); | |
260 gnt_box_add_widget(GNT_BOX(box), button); | |
261 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
262 G_CALLBACK(gnt_widget_destroy), window); | |
263 | |
264 plugins.conf = button = gnt_button_new(_("Configure Plugin")); | |
265 gnt_box_add_widget(GNT_BOX(box), button); | |
266 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(configure_plugin_cb), NULL); | |
267 | |
268 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(reset_plugin_window), NULL); | |
269 | |
270 gnt_widget_show(window); | |
271 | |
272 decide_conf_button(gnt_tree_get_selection_data(GNT_TREE(tree))); | |
273 } | |
274 |