# HG changeset patch # User Christian Hammond # Date 1163391409 0 # Node ID 89ef5680f228bf09a55060b0bdd2bc3f493a43d5 # Parent 1aa9839ca5993a52eca3a337a3b144f3ca67daa4 [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 diff -r 1aa9839ca599 -r 89ef5680f228 gtk/plugins/gevolution/gevo-util.c --- a/gtk/plugins/gevolution/gevo-util.c Mon Nov 13 03:53:46 2006 +0000 +++ b/gtk/plugins/gevolution/gevo-util.c Mon Nov 13 04:16:49 2006 +0000 @@ -146,3 +146,38 @@ return result; } + +char * +gevo_get_email_for_buddy(GaimBuddy *buddy) +{ + EContact *contact; + char *mail = NULL; + + contact = gevo_search_buddy_in_contacts(buddy, NULL); + + if (contact != NULL) + { + mail = g_strdup(e_contact_get(contact, E_CONTACT_EMAIL_1)); + g_object_unref(contact); + } + + if (mail == NULL) + { + GaimAccount *account = gaim_buddy_get_account(buddy); + const char *prpl_id = gaim_account_get_protocol_id(account); + + if (!strcmp(prpl_id, "prpl-msn")) + { + mail = g_strdup(gaim_normalize(account, + gaim_buddy_get_name(buddy))); + } + else if (!strcmp(prpl_id, "prpl-yahoo")) + { + mail = g_strdup_printf("%s@yahoo.com", + gaim_normalize(account, + gaim_buddy_get_name(buddy))); + } + } + + return mail; +} diff -r 1aa9839ca599 -r 89ef5680f228 gtk/plugins/gevolution/gevolution.c --- a/gtk/plugins/gevolution/gevolution.c Mon Nov 13 03:53:46 2006 +0000 +++ b/gtk/plugins/gevolution/gevolution.c Mon Nov 13 04:16:49 2006 +0000 @@ -218,33 +218,9 @@ menu_item_send_mail_activate_cb(GaimBlistNode *node, gpointer user_data) { GaimBuddy *buddy = (GaimBuddy *)node; - EContact *contact; char *mail = NULL; - contact = gevo_search_buddy_in_contacts(buddy, NULL); - - if (contact != NULL) - { - mail = g_strdup(e_contact_get(contact, E_CONTACT_EMAIL_1)); - g_object_unref(contact); - } - else - { - GaimAccount *account = gaim_buddy_get_account(buddy); - const char *prpl_id = gaim_account_get_protocol_id(account); - - if (!strcmp(prpl_id, "prpl-msn")) - { - mail = g_strdup(gaim_normalize(account, - gaim_buddy_get_name(buddy))); - } - else if (!strcmp(prpl_id, "prpl-yahoo")) - { - mail = g_strdup_printf("%s@yahoo.com", - gaim_normalize(account, - gaim_buddy_get_name(buddy))); - } - } + mail = gevo_get_email_for_buddy(buddy); if (mail != NULL) { @@ -267,7 +243,7 @@ else { gaim_notify_error(NULL, NULL, _("Unable to send e-mail"), - _("The specified buddy was not found in the Evolution Contacts.")); + _("An e-mail address was not found for this buddy.")); } } @@ -276,14 +252,17 @@ { GaimMenuAction *act; GaimBuddy *buddy; + GaimAccount *account; EContact *contact; + char *mail; if (!GAIM_BLIST_NODE_IS_BUDDY(node)) return; buddy = (GaimBuddy *)node; + account = gaim_buddy_get_account(buddy); - if (!gevo_prpl_is_supported(gaim_buddy_get_account(buddy), buddy)) + if (!gevo_prpl_is_supported(account, buddy)) return; contact = gevo_search_buddy_in_contacts(buddy, NULL); @@ -295,11 +274,18 @@ NULL, NULL); *menu = g_list_append(*menu, act); } + else + g_object_unref(contact); - act = gaim_menu_action_new(_("Send E-Mail"), - GAIM_CALLBACK(menu_item_send_mail_activate_cb), - NULL, NULL); - *menu = g_list_append(*menu, act); + mail = gevo_get_email_for_buddy(buddy); + + if (mail != NULL) + { + act = gaim_menu_action_new(_("Send E-Mail"), + GAIM_CALLBACK(menu_item_send_mail_activate_cb), NULL, NULL); + *menu = g_list_append(*menu, act); + g_free(mail); + } } /* TODO: Something in here leaks 1 reference to a bonobo object! */ diff -r 1aa9839ca599 -r 89ef5680f228 gtk/plugins/gevolution/gevolution.h --- a/gtk/plugins/gevolution/gevolution.h Mon Nov 13 03:53:46 2006 +0000 +++ b/gtk/plugins/gevolution/gevolution.h Mon Nov 13 04:16:49 2006 +0000 @@ -124,6 +124,7 @@ EContactField gevo_prpl_get_field(GaimAccount *account, GaimBuddy *buddy); gboolean gevo_prpl_is_supported(GaimAccount *account, GaimBuddy *buddy); gboolean gevo_load_addressbook(const gchar *uri, EBook **book, GError **error); +char *gevo_get_email_for_buddy(GaimBuddy *buddy); GevoAssociateBuddyDialog *gevo_associate_buddy_dialog_new(GaimBuddy *buddy);