From 23f65bd71f61807691eabec97055714ba085caed Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Tue, 20 Jan 2009 15:44:31 +0000 Subject: [PATCH] Add to contacts now also works with only a TnyHeader in viewer pmo-trunk-r7202 --- src/hildon2/modest-msg-view-window.c | 15 ++++++++++++--- src/modest-tny-msg.c | 26 ++++++++++++++++++++------ src/modest-tny-msg.h | 11 +++++++++++ src/modest-ui-dimming-rules.c | 20 ++++++++++++++++---- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/hildon2/modest-msg-view-window.c b/src/hildon2/modest-msg-view-window.c index 5519206..790e3cd 100644 --- a/src/hildon2/modest-msg-view-window.c +++ b/src/hildon2/modest-msg-view-window.c @@ -3137,8 +3137,18 @@ modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self) gboolean contacts_to_add = FALSE; msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view)); - if (msg == NULL) return; - recipients = modest_tny_msg_get_all_recipients_list (msg); + if (msg == NULL) { + TnyHeader *header; + + header = modest_msg_view_window_get_header (self); + if (header == NULL) + return; + recipients = modest_tny_msg_header_get_all_recipients_list (header); + g_object_unref (header); + } else { + recipients = modest_tny_msg_get_all_recipients_list (msg); + g_object_unref (msg); + } if (recipients != NULL) { GtkWidget *picker_dialog; @@ -3185,5 +3195,4 @@ modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self) } if (recipients) {g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients);} - g_object_unref (msg); } diff --git a/src/modest-tny-msg.c b/src/modest-tny-msg.c index 40ecc2f..e481d9f 100644 --- a/src/modest-tny-msg.c +++ b/src/modest-tny-msg.c @@ -959,16 +959,11 @@ modest_tny_msg_estimate_size (const gchar *plain_body, const gchar *html_body, } GSList * -modest_tny_msg_get_all_recipients_list (TnyMsg *msg) +modest_tny_msg_header_get_all_recipients_list (TnyHeader *header) { - TnyHeader *header = NULL; GSList *recipients = NULL; gchar *from = NULL, *to = NULL, *cc = NULL, *bcc = NULL; - if (msg == NULL) - return NULL; - - header = tny_msg_get_header (msg); if (header == NULL) return NULL; @@ -995,3 +990,22 @@ modest_tny_msg_get_all_recipients_list (TnyMsg *msg) return recipients; } +GSList * +modest_tny_msg_get_all_recipients_list (TnyMsg *msg) +{ + TnyHeader *header = NULL; + GSList *recipients = NULL; + + if (msg == NULL) + return NULL; + + header = tny_msg_get_header (msg); + if (header == NULL) + return NULL; + + recipients = modest_tny_msg_header_get_all_recipients_list (header); + g_object_unref (header); + + return recipients; +} + diff --git a/src/modest-tny-msg.h b/src/modest-tny-msg.h index 88d4532..91ae148 100644 --- a/src/modest-tny-msg.h +++ b/src/modest-tny-msg.h @@ -199,6 +199,17 @@ modest_tny_msg_estimate_size (const gchar *plain_body, const gchar *html_body, /** * modest_tny_msg_get_all_recipients_list: + * @header: a #TnyHeader + * + * Obtains a list of all the addresses available in @header. + * + * Returns: a newly allocated #GSList of strings. Caller should free strings and list. + */ +GSList * +modest_tny_msg_header_get_all_recipients_list (TnyHeader *header); + +/** + * modest_tny_msg_get_all_recipients_list: * @msg: a #TnyMsg * * Obtains a list of all the addresses available in a message header. diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index 79f9447..9dc3076 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -1915,10 +1915,23 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win)); /* Message is loaded asynchronously, so this could happen */ - if (!msg) - return TRUE; + if (!msg) { +#ifdef MODEST_TOOLKIT_HILDON2 + TnyHeader *header; + + header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win)); + if (!header) + return TRUE; - recipients = modest_tny_msg_get_all_recipients_list (msg); + recipients = modest_tny_msg_header_get_all_recipients_list (header); + g_object_unref (header); +#else + return TRUE; +#endif + } else { + recipients = modest_tny_msg_get_all_recipients_list (msg); + g_object_unref (msg); + } has_recipients_to_add = FALSE; for (node = recipients; node != NULL; node = g_slist_next (node)) { @@ -1930,7 +1943,6 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients); - g_object_unref (msg); return !has_recipients_to_add; } -- 1.7.9.5