From: Jose Dapena Paz Date: Tue, 31 Jul 2007 08:19:43 +0000 (+0000) Subject: * src/modest-text-utils.[ch]: X-Git-Tag: git_migration_finished~2691 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=85b60b61bf30595fabd3bb9b3c5e2d9a0592912f;ds=sidebyside * src/modest-text-utils.[ch]: * New method (modest_text_utils_text_buffer_get_text): wrapper around gtk_text_buffer_get_slice, that replaces the image pixbuf special character 0xFFFC with a blank space. * src/modest-msg-edit-window.c: * Use the new modest_text_utils_text_buffer_get_text to get the plain body representation of a formatted html mail. This makes a mail with only images return a length greater than 0 (fixes NB#64627). pmo-trunk-r2865 --- diff --git a/src/maemo/modest-msg-edit-window.c b/src/maemo/modest-msg-edit-window.c index c4ba604..de7e2a2 100644 --- a/src/maemo/modest-msg-edit-window.c +++ b/src/maemo/modest-msg-edit-window.c @@ -1215,7 +1215,7 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window) GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body)); GtkTextIter b, e; gtk_text_buffer_get_bounds (buf, &b, &e); - data->plain_body = g_strdup (gtk_text_buffer_get_text (priv->text_buffer, &b, &e, FALSE)); /* returns a copy */ + data->plain_body = modest_text_utils_text_buffer_get_text (priv->text_buffer); /* returns a copy */ if (wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer))) data->html_body = get_formatted_data (edit_window); /* returns a copy. */ diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 3b497bb..fd737cc 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -1239,3 +1239,38 @@ modest_text_utils_get_color_string (GdkColor *color) (color->blue >> 12) & 0xf, (color->blue >> 8) & 0xf, (color->blue >> 4) & 0xf, (color->blue) & 0xf); } + +gchar * +modest_text_utils_text_buffer_get_text (GtkTextBuffer *buffer) +{ + GtkTextIter start, end; + gchar *slice, *current; + GString *result = g_string_new (""); + + g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL); + + gtk_text_buffer_get_start_iter (buffer, &start); + gtk_text_buffer_get_end_iter (buffer, &end); + + slice = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE); + current = slice; + + while (current && current != '\0') { + if (g_utf8_get_char (current) == 0xFFFC) { + result = g_string_append_c (result, ' '); + current = g_utf8_next_char (current); + } else { + gchar *next = g_utf8_strchr (current, -1, 0xFFFC); + if (next == NULL) { + result = g_string_append (result, current); + } else { + result = g_string_append_len (result, current, next - current); + } + current = next; + } + } + g_free (slice); + + return g_string_free (result, FALSE); + +} diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 549bfbd..21bad3f 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -36,6 +36,7 @@ #include #include #include +#include #define _FM(str) dgettext("hildon-fm",str) #define _CS(str) dgettext("hildon-common-strings",str) @@ -316,4 +317,15 @@ void modest_text_utils_get_addresses_indexes (const gchar *addresses, GS */ gchar * modest_text_utils_get_color_string (GdkColor *color); +/** + * modest_text_utils_text_buffer_get_text: + * @buffer: a #GtkTextBuffer + * + * Obtains the contents of a @buffer in a string, replacing image + * pixbufs with blank spaces. + * + * Returns: a newly allocated UTF-8 string + */ +gchar * modest_text_utils_text_buffer_get_text (GtkTextBuffer *buffer); + #endif /* __MODEST_TEXT_UTILS_H__ */