Changeset 3400
- Timestamp:
- 02/13/08 12:21:24
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libtinymailui-gtk/tny-gtk-text-buffer-stream.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r3399 r3400 1 2008-02-12 Alberto Garcia Gonzalez <agarcia@igalia.com> 2 3 * libtinymailui-gtk/tny-gtk-text-buffer-stream.c: 4 Write only full UTF-8 characters into the GtkTextBuffer. If an 5 input buffer contains incomplete UTF-8 chars, save those bytes and 6 write them with the following buffer. 7 1 8 2008-02-11 Alberto Garcia Gonzalez <agarcia@igalia.com> 2 9 trunk/libtinymailui-gtk/tny-gtk-text-buffer-stream.c
r3304 r3400 47 47 GtkTextBuffer *buffer; 48 48 GtkTextIter cur; 49 49 GByteArray *pending_bytes; 50 50 }; 51 51 … … 137 137 TnyGtkTextBufferStreamPriv *priv = TNY_GTK_TEXT_BUFFER_STREAM_GET_PRIVATE (self); 138 138 const gchar *end; 139 140 if (g_utf8_validate (buffer, n, &end)) 141 gtk_text_buffer_insert (priv->buffer, &(priv->cur), buffer, (gint)n); 142 else 143 gtk_text_buffer_insert (priv->buffer, &(priv->cur), end, (gint) (end - buffer)); 139 gint nb_written; 140 141 g_byte_array_append (priv->pending_bytes, buffer, n); 142 143 /* GtkTextBuffer only accepts full UTF-8 chars, but we might 144 * receive a single UTF-8 char split into two different 145 * buffers -see camel_stream_write_to_stream()- so we write 146 * only the part of the buffer that is valid UTF-8 text and 147 * leave the rest for later */ 148 g_utf8_validate (priv->pending_bytes->data, priv->pending_bytes->len, &end); 149 nb_written = (gint) (end - ((char *) priv->pending_bytes->data)); 150 151 /* However if the rest of the buffer is more than 4 bytes long 152 * (4 bytes being the max size of a UTF-8 char) then it's 153 * certainly not a UTF-8 char divided in two. In this case it 154 * means that the buffer is corrupt. There's not much to do 155 * about it but to write it anyway */ 156 if (priv->pending_bytes->len - nb_written >= 4) { 157 nb_written = priv->pending_bytes->len; 158 } 159 160 gtk_text_buffer_insert (priv->buffer, &(priv->cur), priv->pending_bytes->data, nb_written); 161 162 /* Leave the unwritten chars in priv->pending_bytes for later */ 163 g_byte_array_remove_range (priv->pending_bytes, 0, nb_written); 144 164 145 165 return (gssize) n; … … 155 175 tny_gtk_text_buffer_stream_flush_default (TnyStream *self) 156 176 { 177 TnyGtkTextBufferStreamPriv *priv = TNY_GTK_TEXT_BUFFER_STREAM_GET_PRIVATE (self); 178 if (priv->pending_bytes->len > 0) { 179 gtk_text_buffer_insert (priv->buffer, &(priv->cur), 180 priv->pending_bytes->data, priv->pending_bytes->len); 181 g_byte_array_set_size (priv->pending_bytes, 0); 182 } 157 183 return 0; 158 184 } … … 212 238 TnyGtkTextBufferStreamPriv *priv = TNY_GTK_TEXT_BUFFER_STREAM_GET_PRIVATE (self); 213 239 240 tny_gtk_text_buffer_stream_flush (self); 214 241 return tny_gtk_text_buffer_stream_reset_priv (priv); 215 242 } … … 236 263 g_object_ref (G_OBJECT (buffer)); 237 264 priv->buffer = buffer; 265 266 if (!priv->pending_bytes) 267 priv->pending_bytes = g_byte_array_new (); 268 269 g_byte_array_set_size (priv->pending_bytes, 0); 238 270 239 271 tny_gtk_text_buffer_stream_reset_priv (priv); … … 269 301 270 302 priv->buffer = NULL; 303 priv->pending_bytes = NULL; 271 304 272 305 return; … … 279 312 TnyGtkTextBufferStreamPriv *priv = TNY_GTK_TEXT_BUFFER_STREAM_GET_PRIVATE (self); 280 313 314 if (priv->buffer && priv->pending_bytes) 315 tny_gtk_text_buffer_stream_flush (self); 316 281 317 if (priv->buffer) 282 318 g_object_unref (G_OBJECT (priv->buffer)); 319 if (priv->pending_bytes) 320 g_byte_array_free (priv->pending_bytes, TRUE); 283 321 284 322 (*parent_class->finalize) (object);
