Mercurial > pidgin.yaz
comparison plugins/gevolution/eds-utils.c @ 11117:5a8bc4b1f5b6
[gaim-migrate @ 13173]
Patch #1052811, from Szilard Novaki
"gevolution plugin should register a "Send Email" popup
menuitem to send mail for users using gaim contact list.
See the attached patch (patched for gaim-1.0.2 release)."
I made a number of changes to this to simplify it. Thanks to shres and NotZed in #evolution on irc.gnome.org for their help.
Other changes:
- I may have squashed some leaks in existing code as I tracked down leaks in the new code. I'm not really sure. It still leaks something that I can't track down, but that happens even if you don't call any of the new code. I verified that it was happening pre-patch, so it's no worse with this feature addition.
- It's not really Ximian Evolution anymore, so I changed the summary and description to remove "Ximian", leaving it just Evolution.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 18 Jul 2005 07:26:09 +0000 |
parents | 455c0830d108 |
children | 8d7c99f20e4c |
comparison
equal
deleted
inserted
replaced
11116:bbb28c529be0 | 11117:5a8bc4b1f5b6 |
---|---|
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 g_object_unref(addressbooks); | 114 g_object_unref(addressbooks); |
115 } | 115 } |
116 | |
117 EContact * | |
118 gevo_run_query_in_uri(const gchar *uri, EBookQuery *query) | |
119 { | |
120 EBook *book; | |
121 gboolean status; | |
122 GList *cards; | |
123 | |
124 if (!gevo_load_addressbook(uri, &book, NULL)) | |
125 { | |
126 gaim_debug_error("evolution", | |
127 "Error retrieving addressbook\n"); | |
128 return NULL; | |
129 } | |
130 | |
131 status = e_book_get_contacts(book, query, &cards, NULL); | |
132 if (!status) | |
133 { | |
134 gaim_debug_error("evolution", "Error %d in getting card list\n", | |
135 status); | |
136 g_object_unref(book); | |
137 return NULL; | |
138 } | |
139 g_object_unref(book); | |
140 | |
141 if (cards != NULL) | |
142 { | |
143 EContact *contact = E_CONTACT(cards->data); | |
144 GList *cards2 = cards->next; | |
145 | |
146 if (cards2 != NULL) | |
147 { | |
148 /* Break off the first contact and free the rest. */ | |
149 cards->next = NULL; | |
150 cards2->prev = NULL; | |
151 g_list_foreach(cards2, (GFunc)g_object_unref, NULL); | |
152 } | |
153 | |
154 /* Free the whole list. */ | |
155 g_list_free(cards); | |
156 | |
157 return contact; | |
158 } | |
159 | |
160 return NULL; | |
161 } | |
162 | |
163 /* | |
164 * Search for a buddy in the Evolution contacts. | |
165 * | |
166 * @param buddy The buddy to search for. | |
167 * @param query An optional query. This function takes ownership of @a query, | |
168 * so callers must e_book_query_ref() it in advance (to obtain a | |
169 * second reference) if they want to reuse @a query. | |
170 */ | |
171 EContact * | |
172 gevo_search_buddy_in_contacts(GaimBuddy *buddy, EBookQuery *query) | |
173 { | |
174 ESourceList *addressbooks; | |
175 GError *err; | |
176 EBookQuery *full_query; | |
177 GSList *groups, *g; | |
178 EContact *result; | |
179 EContactField protocol_field = gevo_prpl_get_field(buddy->account, buddy); | |
180 | |
181 if (protocol_field == 0) | |
182 return NULL; | |
183 | |
184 if (query != NULL) | |
185 { | |
186 EBookQuery *queries[2]; | |
187 | |
188 queries[0] = query; | |
189 queries[1] = e_book_query_field_test(protocol_field, E_BOOK_QUERY_IS, buddy->name); | |
190 if (queries[1] == NULL) | |
191 { | |
192 gaim_debug_error("evolution", "Error in creating protocol query\n"); | |
193 e_book_query_unref(query); | |
194 return NULL; | |
195 } | |
196 | |
197 full_query = e_book_query_and(2, queries, TRUE); | |
198 } | |
199 else | |
200 { | |
201 full_query = e_book_query_field_test(protocol_field, E_BOOK_QUERY_IS, buddy->name); | |
202 if (full_query == NULL) | |
203 { | |
204 gaim_debug_error("evolution", "Error in creating protocol query\n"); | |
205 return NULL; | |
206 } | |
207 } | |
208 | |
209 if (!e_book_get_addressbooks(&addressbooks, &err)) | |
210 { | |
211 gaim_debug_error("evolution", | |
212 "Unable to fetch list of address books.\n"); | |
213 e_book_query_unref(full_query); | |
214 if (err != NULL) | |
215 g_error_free(err); | |
216 return NULL; | |
217 } | |
218 | |
219 groups = e_source_list_peek_groups(addressbooks); | |
220 if (groups == NULL) | |
221 { | |
222 g_object_unref(addressbooks); | |
223 e_book_query_unref(full_query); | |
224 return NULL; | |
225 } | |
226 | |
227 for (g = groups; g != NULL; g = g->next) | |
228 { | |
229 GSList *sources, *s; | |
230 sources = e_source_group_peek_sources(g->data); | |
231 for (s = sources; s != NULL; s = s->next) | |
232 { | |
233 result = gevo_run_query_in_uri(e_source_get_uri(E_SOURCE(s->data)), full_query); | |
234 if (result != NULL) { | |
235 g_object_unref(addressbooks); | |
236 e_book_query_unref(full_query); | |
237 return result; | |
238 } | |
239 } | |
240 } | |
241 | |
242 g_object_unref(addressbooks); | |
243 e_book_query_unref(full_query); | |
244 return NULL; | |
245 } |