Mercurial > pidgin.yaz
annotate finch/gntplugin.c @ 16307:9326d4cf5497
If anyone sees the "Unable to add buddy 1" message after
this commit, please let me know.
More changes in an effort to get rid of the "Unable to Add,
Could not add the buddy 1 for an unknown reason. The
most common reason for this is that you have the
maximum number of allowed buddies in your buddy list" message.
My previous checkin fixed a problem that resulted in the same
error, but the cause was completely different. The important
change in this commit is the one in aim_ssi_itemlist_add().
Apparently there's this funky thing where items in the master
group can't have a buddy ID equal to any group ID. Who knew?
There are a few other minor changes in this commit. I added
a "break" when looping through the items making sure we don't
pick a buddy ID that's already in use. And added some checks
to make sure we never try to update our data if we haven't
received the list from the server yet. Oh, and the 2 bytes
that specify the length of the checksum for the icon are
two separate values. The first byte is either a 0 or a 1 and
I don't know what it means. The second byte is the length of
the checksum.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 23 Apr 2007 01:05:27 +0000 |
parents | c3052de39110 |
children | 8c89913276b3 |
rev | line source |
---|---|
15818 | 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:
15871
diff
changeset
|
3 * @ingroup finch |
15818 | 4 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 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 | |
15823 | 34 #include "finch.h" |
15818 | 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 | |
15823 | 48 decide_conf_button(PurplePlugin *plugin) |
15818 | 49 { |
15823 | 50 if (purple_plugin_is_loaded(plugin) && |
51 ((PURPLE_IS_GNT_PLUGIN(plugin) && | |
52 FINCH_PLUGIN_UI_INFO(plugin) != NULL) || | |
15818 | 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 | |
15823 | 64 plugin_toggled_cb(GntWidget *tree, PurplePlugin *plugin, gpointer null) |
15818 | 65 { |
16254
c3052de39110
If a plugin failed to load/unload, don't pretend that it worked
Richard Nelson <wabz@pidgin.im>
parents:
16194
diff
changeset
|
66 /* TODO: Mark these strings for translation after the freeze */ |
15818 | 67 if (gnt_tree_get_choice(GNT_TREE(tree), plugin)) |
68 { | |
16254
c3052de39110
If a plugin failed to load/unload, don't pretend that it worked
Richard Nelson <wabz@pidgin.im>
parents:
16194
diff
changeset
|
69 if (!purple_plugin_load(plugin)) { |
15823 | 70 purple_notify_error(NULL, "ERROR", "loading plugin failed", NULL); |
16254
c3052de39110
If a plugin failed to load/unload, don't pretend that it worked
Richard Nelson <wabz@pidgin.im>
parents:
16194
diff
changeset
|
71 gnt_tree_set_choice(GNT_TREE(tree), plugin, FALSE); |
c3052de39110
If a plugin failed to load/unload, don't pretend that it worked
Richard Nelson <wabz@pidgin.im>
parents:
16194
diff
changeset
|
72 } |
15818 | 73 } |
74 else | |
75 { | |
76 GntWidget *win; | |
77 | |
16254
c3052de39110
If a plugin failed to load/unload, don't pretend that it worked
Richard Nelson <wabz@pidgin.im>
parents:
16194
diff
changeset
|
78 if (!purple_plugin_unload(plugin)) { |
15823 | 79 purple_notify_error(NULL, "ERROR", "unloading plugin failed", NULL); |
16254
c3052de39110
If a plugin failed to load/unload, don't pretend that it worked
Richard Nelson <wabz@pidgin.im>
parents:
16194
diff
changeset
|
80 gnt_tree_set_choice(GNT_TREE(tree), plugin, TRUE); |
c3052de39110
If a plugin failed to load/unload, don't pretend that it worked
Richard Nelson <wabz@pidgin.im>
parents:
16194
diff
changeset
|
81 } |
15818 | 82 |
83 if ((win = g_hash_table_lookup(confwins, plugin)) != NULL) | |
84 { | |
85 gnt_widget_destroy(win); | |
86 } | |
87 } | |
88 decide_conf_button(plugin); | |
89 finch_plugins_save_loaded(); | |
90 } | |
91 | |
92 /* Xerox */ | |
93 void | |
94 finch_plugins_save_loaded(void) | |
95 { | |
15823 | 96 purple_plugins_save_loaded("/purple/gnt/plugins/loaded"); |
15818 | 97 } |
98 | |
99 static void | |
100 selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null) | |
101 { | |
15823 | 102 PurplePlugin *plugin = current; |
15818 | 103 char *text; |
104 | |
105 /* XXX: Use formatting and stuff */ | |
106 gnt_text_view_clear(GNT_TEXT_VIEW(plugins.aboot)); | |
107 text = g_strdup_printf(_("Name: %s\nVersion: %s\nDescription: %s\nAuthor: %s\nWebsite: %s\nFilename: %s\n"), | |
108 SAFE(plugin->info->name), SAFE(plugin->info->version), SAFE(plugin->info->description), | |
109 SAFE(plugin->info->author), SAFE(plugin->info->homepage), SAFE(plugin->path)); | |
110 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(plugins.aboot), | |
111 text, GNT_TEXT_FLAG_NORMAL); | |
112 gnt_text_view_scroll(GNT_TEXT_VIEW(plugins.aboot), 0); | |
113 g_free(text); | |
114 decide_conf_button(plugin); | |
115 } | |
116 | |
117 static void | |
118 reset_plugin_window(GntWidget *window, gpointer null) | |
119 { | |
120 plugins.window = NULL; | |
121 plugins.tree = NULL; | |
122 plugins.aboot = NULL; | |
123 } | |
124 | |
125 static int | |
15823 | 126 plugin_compare(PurplePlugin *p1, PurplePlugin *p2) |
15818 | 127 { |
128 char *s1 = g_utf8_strup(p1->info->name, -1); | |
129 char *s2 = g_utf8_strup(p2->info->name, -1); | |
130 int ret = g_utf8_collate(s1, s2); | |
131 g_free(s1); | |
132 g_free(s2); | |
133 return ret; | |
134 } | |
135 | |
136 static void | |
137 confwin_init() | |
138 { | |
139 confwins = g_hash_table_new(g_direct_hash, g_direct_equal); | |
140 } | |
141 | |
142 static void | |
143 remove_confwin(GntWidget *window, gpointer plugin) | |
144 { | |
145 g_hash_table_remove(confwins, plugin); | |
146 } | |
147 | |
148 static void | |
149 configure_plugin_cb(GntWidget *button, gpointer null) | |
150 { | |
15823 | 151 PurplePlugin *plugin; |
15818 | 152 FinchPluginFrame callback; |
153 | |
154 g_return_if_fail(plugins.tree != NULL); | |
155 | |
156 plugin = gnt_tree_get_selection_data(GNT_TREE(plugins.tree)); | |
15823 | 157 if (!purple_plugin_is_loaded(plugin)) |
15818 | 158 { |
15823 | 159 purple_notify_error(plugin, _("Error"), |
15818 | 160 _("Plugin need to be loaded before you can configure it."), NULL); |
161 return; | |
162 } | |
163 | |
164 if (confwins && g_hash_table_lookup(confwins, plugin)) | |
165 return; | |
166 | |
15823 | 167 if (PURPLE_IS_GNT_PLUGIN(plugin) && |
168 (callback = FINCH_PLUGIN_UI_INFO(plugin)) != NULL) | |
15818 | 169 { |
170 GntWidget *window = gnt_vbox_new(FALSE); | |
171 GntWidget *box, *button; | |
172 | |
173 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
174 gnt_box_set_title(GNT_BOX(window), plugin->info->name); | |
175 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
176 | |
177 box = callback(); | |
178 gnt_box_add_widget(GNT_BOX(window), box); | |
179 | |
180 box = gnt_hbox_new(FALSE); | |
181 gnt_box_add_widget(GNT_BOX(window), box); | |
182 | |
183 button = gnt_button_new(_("Close")); | |
184 gnt_box_add_widget(GNT_BOX(box), button); | |
185 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
186 G_CALLBACK(gnt_widget_destroy), window); | |
187 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(remove_confwin), plugin); | |
188 | |
189 gnt_widget_show(window); | |
190 | |
191 if (confwins == NULL) | |
192 confwin_init(); | |
193 g_hash_table_insert(confwins, plugin, window); | |
194 } | |
195 else if (plugin->info->prefs_info && | |
196 plugin->info->prefs_info->get_plugin_pref_frame) | |
197 { | |
15823 | 198 purple_notify_info(plugin, _("..."), |
15818 | 199 _("Still need to do something about this."), NULL); |
200 return; | |
201 } | |
202 else | |
203 { | |
15823 | 204 purple_notify_info(plugin, _("Error"), |
15818 | 205 _("No configuration options for this plugin."), NULL); |
206 return; | |
207 } | |
208 } | |
209 | |
210 void finch_plugins_show_all() | |
211 { | |
212 GntWidget *window, *tree, *box, *aboot, *button; | |
213 GList *iter; | |
214 if (plugins.window) | |
215 return; | |
216 | |
15823 | 217 purple_plugins_probe(G_MODULE_SUFFIX); |
15818 | 218 |
219 plugins.window = window = gnt_vbox_new(FALSE); | |
220 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
221 gnt_box_set_title(GNT_BOX(window), _("Plugins")); | |
222 gnt_box_set_pad(GNT_BOX(window), 0); | |
223 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
224 | |
225 gnt_box_add_widget(GNT_BOX(window), | |
226 gnt_label_new(_("You can (un)load plugins from the following list."))); | |
227 gnt_box_add_widget(GNT_BOX(window), gnt_hline_new()); | |
228 | |
229 box = gnt_hbox_new(FALSE); | |
230 gnt_box_add_widget(GNT_BOX(window), box); | |
231 gnt_box_add_widget(GNT_BOX(window), gnt_hline_new()); | |
232 | |
233 gnt_box_set_pad(GNT_BOX(box), 0); | |
234 plugins.tree = tree = gnt_tree_new(); | |
235 gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)plugin_compare); | |
236 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | |
237 gnt_box_add_widget(GNT_BOX(box), tree); | |
238 gnt_box_add_widget(GNT_BOX(box), gnt_vline_new()); | |
239 | |
240 plugins.aboot = aboot = gnt_text_view_new(); | |
241 gnt_widget_set_size(aboot, 40, 20); | |
242 gnt_box_add_widget(GNT_BOX(box), aboot); | |
243 | |
15823 | 244 for (iter = purple_plugins_get_all(); iter; iter = iter->next) |
15818 | 245 { |
15823 | 246 PurplePlugin *plug = iter->data; |
15818 | 247 |
15823 | 248 if (plug->info->type != PURPLE_PLUGIN_STANDARD || |
249 (plug->info->flags & PURPLE_PLUGIN_FLAG_INVISIBLE) || | |
15818 | 250 plug->error) |
251 continue; | |
252 | |
253 gnt_tree_add_choice(GNT_TREE(tree), plug, | |
254 gnt_tree_create_row(GNT_TREE(tree), plug->info->name), NULL, NULL); | |
15823 | 255 gnt_tree_set_choice(GNT_TREE(tree), plug, purple_plugin_is_loaded(plug)); |
15818 | 256 } |
257 gnt_tree_set_col_width(GNT_TREE(tree), 0, 30); | |
258 g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(plugin_toggled_cb), NULL); | |
259 g_signal_connect(G_OBJECT(tree), "selection_changed", G_CALLBACK(selection_changed), NULL); | |
260 | |
261 box = gnt_hbox_new(FALSE); | |
262 gnt_box_add_widget(GNT_BOX(window), box); | |
263 | |
264 button = gnt_button_new(_("Close")); | |
265 gnt_box_add_widget(GNT_BOX(box), button); | |
266 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
267 G_CALLBACK(gnt_widget_destroy), window); | |
268 | |
269 plugins.conf = button = gnt_button_new(_("Configure Plugin")); | |
270 gnt_box_add_widget(GNT_BOX(box), button); | |
271 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(configure_plugin_cb), NULL); | |
272 | |
273 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(reset_plugin_window), NULL); | |
274 | |
275 gnt_widget_show(window); | |
276 | |
277 decide_conf_button(gnt_tree_get_selection_data(GNT_TREE(tree))); | |
278 } | |
279 |