Mercurial > pidgin
annotate finch/gntplugin.c @ 16247:3fccb0824005
merge of '52f50d9c1ba2cedab7acbe195e3f223d70f1cc3d'
and '8df7434a7e049cd7d6289d46da66e1b62eef6dc8'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Wed, 18 Apr 2007 21:14:39 +0000 |
parents | 0f0832c13fcb |
children | c3052de39110 |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntplugin.c GNT Plugins API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
15870
diff
changeset
|
3 * @ingroup finch |
15817 | 4 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
5 * finch |
15817 | 6 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15817 | 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 | |
15822 | 34 #include "finch.h" |
15817 | 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 | |
15822 | 48 decide_conf_button(PurplePlugin *plugin) |
15817 | 49 { |
15822 | 50 if (purple_plugin_is_loaded(plugin) && |
51 ((PURPLE_IS_GNT_PLUGIN(plugin) && | |
52 FINCH_PLUGIN_UI_INFO(plugin) != NULL) || | |
15817 | 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 | |
15822 | 64 plugin_toggled_cb(GntWidget *tree, PurplePlugin *plugin, gpointer null) |
15817 | 65 { |
66 if (gnt_tree_get_choice(GNT_TREE(tree), plugin)) | |
67 { | |
15822 | 68 if(!purple_plugin_load(plugin)) |
69 purple_notify_error(NULL, "ERROR", "loading plugin failed", NULL); | |
15817 | 70 } |
71 else | |
72 { | |
73 GntWidget *win; | |
74 | |
15822 | 75 if (!purple_plugin_unload(plugin)) |
76 purple_notify_error(NULL, "ERROR", "unloading plugin failed", NULL); | |
15817 | 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 { | |
15822 | 91 purple_plugins_save_loaded("/purple/gnt/plugins/loaded"); |
15817 | 92 } |
93 | |
94 static void | |
95 selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null) | |
96 { | |
15822 | 97 PurplePlugin *plugin = current; |
15817 | 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 | |
15822 | 121 plugin_compare(PurplePlugin *p1, PurplePlugin *p2) |
15817 | 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 { | |
15822 | 146 PurplePlugin *plugin; |
15817 | 147 FinchPluginFrame callback; |
148 | |
149 g_return_if_fail(plugins.tree != NULL); | |
150 | |
151 plugin = gnt_tree_get_selection_data(GNT_TREE(plugins.tree)); | |
15822 | 152 if (!purple_plugin_is_loaded(plugin)) |
15817 | 153 { |
15822 | 154 purple_notify_error(plugin, _("Error"), |
15817 | 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 | |
15822 | 162 if (PURPLE_IS_GNT_PLUGIN(plugin) && |
163 (callback = FINCH_PLUGIN_UI_INFO(plugin)) != NULL) | |
15817 | 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 { | |
15822 | 193 purple_notify_info(plugin, _("..."), |
15817 | 194 _("Still need to do something about this."), NULL); |
195 return; | |
196 } | |
197 else | |
198 { | |
15822 | 199 purple_notify_info(plugin, _("Error"), |
15817 | 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 | |
15822 | 212 purple_plugins_probe(G_MODULE_SUFFIX); |
15817 | 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 | |
15822 | 239 for (iter = purple_plugins_get_all(); iter; iter = iter->next) |
15817 | 240 { |
15822 | 241 PurplePlugin *plug = iter->data; |
15817 | 242 |
15822 | 243 if (plug->info->type != PURPLE_PLUGIN_STANDARD || |
244 (plug->info->flags & PURPLE_PLUGIN_FLAG_INVISIBLE) || | |
15817 | 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); | |
15822 | 250 gnt_tree_set_choice(GNT_TREE(tree), plug, purple_plugin_is_loaded(plug)); |
15817 | 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 |