From: Sergio Villar Senin Date: Mon, 25 May 2009 10:10:13 +0000 (+0200) Subject: Refactored code in modest_text_utils_get_display_addresses to get a list of display... X-Git-Tag: 3.0.17-rc8~9 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=4927d2ba3643bba250d1c0e12a8c732db905fad3;ds=sidebyside Refactored code in modest_text_utils_get_display_addresses to get a list of display addresses Fixes NB#118506, message viewer shows only the first recipient when opening a message of the sent folder --- diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 7a89d08..5426b0b 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -1274,7 +1274,37 @@ modest_text_utils_get_display_address (gchar *address) } +gchar * +modest_text_utils_get_display_addresses (const gchar *recipients) +{ + gchar *addresses; + GSList *recipient_list; + + addresses = NULL; + recipient_list = modest_text_utils_split_addresses_list (recipients); + if (recipient_list) { + GString *add_string = g_string_sized_new (strlen (recipients)); + GSList *iter = recipient_list; + gboolean first = TRUE; + + while (iter) { + /* Strings are changed in place */ + modest_text_utils_get_display_address ((gchar *) iter->data); + if (G_UNLIKELY (first)) { + g_string_append_printf (add_string, "%s", (gchar *) iter->data); + first = FALSE; + } else { + g_string_append_printf (add_string, ", %s", (gchar *) iter->data); + } + iter = g_slist_next (iter); + } + g_slist_foreach (recipient_list, (GFunc) g_free, NULL); + g_slist_free (recipient_list); + addresses = g_string_free (add_string, FALSE); + } + return addresses; +} gchar * diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index f10562f..f2c59c9 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -246,6 +246,19 @@ void modest_text_utils_hyperlinkify (GString *string_buffer); void modest_text_utils_get_display_address (gchar *address); /** + * modest_text_utils_get_display_addresses: + * @addresses: a list of comma-separated addresses + * + * Transforms a list of email addresses in a list of recipients, + * replacing each plain email address by the correspondent display + * address. + * + * Returns: a newly allocated string, that must be freed by the caller + **/ +gchar *modest_text_utils_get_display_addresses (const gchar *addresses); + + +/** * modest_text_utils_get_email_address: * @full_address: original address (UTF8 string) * @@ -487,5 +500,4 @@ gchar *modest_text_utils_escape_mnemonics (const gchar *text); */ gchar *modest_text_utils_simplify_recipients (const gchar *recipient); - #endif /* __MODEST_TEXT_UTILS_H__ */ diff --git a/src/widgets/modest-compact-mail-header-view.c b/src/widgets/modest-compact-mail-header-view.c index d5652e1..d248f03 100644 --- a/src/widgets/modest-compact-mail-header-view.c +++ b/src/widgets/modest-compact-mail-header-view.c @@ -656,9 +656,7 @@ fill_address (ModestCompactMailHeaderView *self) ModestCompactMailHeaderViewPriv *priv; gchar *recipients; const gchar *label; - GSList *recipient_list; - gchar *first_address; - + g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (self)); priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self); @@ -670,25 +668,18 @@ fill_address (ModestCompactMailHeaderView *self) recipients = tny_header_dup_from (TNY_HEADER (priv->header)); } - recipient_list = modest_text_utils_split_addresses_list (recipients); - if (recipient_list == NULL) { - first_address = NULL; - } else { - gchar *first_recipient; - - first_recipient = (gchar *) recipient_list->data; - first_address = first_recipient?g_strdup (first_recipient):NULL; - } - g_slist_foreach (recipient_list, (GFunc) g_free, NULL); - g_slist_free (recipient_list); - + /* Set label */ gtk_label_set_text (GTK_LABEL (priv->fromto_label), label); + + /* Set recipients */ if (recipients) { - modest_text_utils_get_display_address (first_address); - gtk_label_set_text (GTK_LABEL (priv->fromto_contents), first_address); + gchar *addresses; + + addresses = modest_text_utils_get_display_addresses ((const gchar *) recipients); + gtk_label_set_text (GTK_LABEL (priv->fromto_contents), + (addresses) ? addresses : _("mail_va_no_to")); + g_free (addresses); g_free (recipients); - g_free (first_address); } - } diff --git a/src/widgets/modest-header-view-render.c b/src/widgets/modest-header-view-render.c index 85465af..a7a242a 100644 --- a/src/widgets/modest-header-view-render.c +++ b/src/widgets/modest-header-view-render.c @@ -264,7 +264,6 @@ _modest_header_view_compact_header_cell_data (GtkTreeViewColumn *column, GtkCe { TnyHeaderFlags flags = 0; gchar *recipients = NULL, *addresses; - GSList *recipient_list; gchar *subject = NULL; time_t date; GtkCellRenderer *recipient_cell, *date_or_status_cell, *subject_cell, @@ -339,29 +338,7 @@ _modest_header_view_compact_header_cell_data (GtkTreeViewColumn *column, GtkCe g_free (subject); /* Show the list of senders/recipients */ - addresses = NULL; - recipient_list = modest_text_utils_split_addresses_list (recipients); - if (recipient_list) { - GString *add_string = g_string_sized_new (strlen (recipients)); - GSList *iter = recipient_list; - gboolean first = TRUE; - - while (iter) { - /* Strings are changed in place */ - modest_text_utils_get_display_address ((gchar *) iter->data); - if (G_UNLIKELY (first)) { - g_string_append_printf (add_string, "%s", (gchar *) iter->data); - first = FALSE; - } else { - g_string_append_printf (add_string, ", %s", (gchar *) iter->data); - } - iter = g_slist_next (iter); - } - g_slist_foreach (recipient_list, (GFunc) g_free, NULL); - g_slist_free (recipient_list); - addresses = g_string_free (add_string, FALSE); - } - + addresses = modest_text_utils_get_display_addresses ((const gchar *) recipients); set_cell_text (recipient_cell, (addresses) ? addresses : _("mail_va_no_to"), flags); g_free (addresses); g_free (recipients);