* src/modest-text-utils.[ch]:
authorJose Dapena Paz <jdapena@igalia.com>
Tue, 31 Jul 2007 08:19:43 +0000 (08:19 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Tue, 31 Jul 2007 08:19:43 +0000 (08:19 +0000)
        * 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

src/maemo/modest-msg-edit-window.c
src/modest-text-utils.c
src/modest-text-utils.h

index c4ba604..de7e2a2 100644 (file)
@@ -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. */
index 3b497bb..fd737cc 100644 (file)
@@ -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);
+       
+}
index 549bfbd..21bad3f 100644 (file)
@@ -36,6 +36,7 @@
 #include <time.h>
 #include <glib.h>
 #include <gdk/gdkcolor.h>
+#include <gtk/gtktextbuffer.h>
 
 #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__ */