Mercurial > pidgin
comparison gtk/plugins/gevolution/gevolution.c @ 14964:89ef5680f228
[gaim-migrate @ 17743]
Split out the logic for finding a buddy's e-mail address into a separate function. Show the "Send E-mail" menu item only if an e-mail address was found.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 13 Nov 2006 04:16:49 +0000 |
parents | 1aa9839ca599 |
children |
comparison
equal
deleted
inserted
replaced
14963:1aa9839ca599 | 14964:89ef5680f228 |
---|---|
216 | 216 |
217 static void | 217 static void |
218 menu_item_send_mail_activate_cb(GaimBlistNode *node, gpointer user_data) | 218 menu_item_send_mail_activate_cb(GaimBlistNode *node, gpointer user_data) |
219 { | 219 { |
220 GaimBuddy *buddy = (GaimBuddy *)node; | 220 GaimBuddy *buddy = (GaimBuddy *)node; |
221 EContact *contact; | |
222 char *mail = NULL; | 221 char *mail = NULL; |
223 | 222 |
224 contact = gevo_search_buddy_in_contacts(buddy, NULL); | 223 mail = gevo_get_email_for_buddy(buddy); |
225 | |
226 if (contact != NULL) | |
227 { | |
228 mail = g_strdup(e_contact_get(contact, E_CONTACT_EMAIL_1)); | |
229 g_object_unref(contact); | |
230 } | |
231 else | |
232 { | |
233 GaimAccount *account = gaim_buddy_get_account(buddy); | |
234 const char *prpl_id = gaim_account_get_protocol_id(account); | |
235 | |
236 if (!strcmp(prpl_id, "prpl-msn")) | |
237 { | |
238 mail = g_strdup(gaim_normalize(account, | |
239 gaim_buddy_get_name(buddy))); | |
240 } | |
241 else if (!strcmp(prpl_id, "prpl-yahoo")) | |
242 { | |
243 mail = g_strdup_printf("%s@yahoo.com", | |
244 gaim_normalize(account, | |
245 gaim_buddy_get_name(buddy))); | |
246 } | |
247 } | |
248 | 224 |
249 if (mail != NULL) | 225 if (mail != NULL) |
250 { | 226 { |
251 char *app = g_find_program_in_path("evolution"); | 227 char *app = g_find_program_in_path("evolution"); |
252 if (app != NULL) | 228 if (app != NULL) |
265 } | 241 } |
266 } | 242 } |
267 else | 243 else |
268 { | 244 { |
269 gaim_notify_error(NULL, NULL, _("Unable to send e-mail"), | 245 gaim_notify_error(NULL, NULL, _("Unable to send e-mail"), |
270 _("The specified buddy was not found in the Evolution Contacts.")); | 246 _("An e-mail address was not found for this buddy.")); |
271 } | 247 } |
272 } | 248 } |
273 | 249 |
274 static void | 250 static void |
275 blist_node_extended_menu_cb(GaimBlistNode *node, GList **menu) | 251 blist_node_extended_menu_cb(GaimBlistNode *node, GList **menu) |
276 { | 252 { |
277 GaimMenuAction *act; | 253 GaimMenuAction *act; |
278 GaimBuddy *buddy; | 254 GaimBuddy *buddy; |
255 GaimAccount *account; | |
279 EContact *contact; | 256 EContact *contact; |
257 char *mail; | |
280 | 258 |
281 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) | 259 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) |
282 return; | 260 return; |
283 | 261 |
284 buddy = (GaimBuddy *)node; | 262 buddy = (GaimBuddy *)node; |
285 | 263 account = gaim_buddy_get_account(buddy); |
286 if (!gevo_prpl_is_supported(gaim_buddy_get_account(buddy), buddy)) | 264 |
265 if (!gevo_prpl_is_supported(account, buddy)) | |
287 return; | 266 return; |
288 | 267 |
289 contact = gevo_search_buddy_in_contacts(buddy, NULL); | 268 contact = gevo_search_buddy_in_contacts(buddy, NULL); |
290 | 269 |
291 if (contact == NULL) | 270 if (contact == NULL) |
293 act = gaim_menu_action_new(_("Add to Address Book"), | 272 act = gaim_menu_action_new(_("Add to Address Book"), |
294 GAIM_CALLBACK(menu_item_activate_cb), | 273 GAIM_CALLBACK(menu_item_activate_cb), |
295 NULL, NULL); | 274 NULL, NULL); |
296 *menu = g_list_append(*menu, act); | 275 *menu = g_list_append(*menu, act); |
297 } | 276 } |
298 | 277 else |
299 act = gaim_menu_action_new(_("Send E-Mail"), | 278 g_object_unref(contact); |
300 GAIM_CALLBACK(menu_item_send_mail_activate_cb), | 279 |
301 NULL, NULL); | 280 mail = gevo_get_email_for_buddy(buddy); |
302 *menu = g_list_append(*menu, act); | 281 |
282 if (mail != NULL) | |
283 { | |
284 act = gaim_menu_action_new(_("Send E-Mail"), | |
285 GAIM_CALLBACK(menu_item_send_mail_activate_cb), NULL, NULL); | |
286 *menu = g_list_append(*menu, act); | |
287 g_free(mail); | |
288 } | |
303 } | 289 } |
304 | 290 |
305 /* TODO: Something in here leaks 1 reference to a bonobo object! */ | 291 /* TODO: Something in here leaks 1 reference to a bonobo object! */ |
306 static gboolean | 292 static gboolean |
307 load_timeout(gpointer data) | 293 load_timeout(gpointer data) |