X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-tny-stream-gtkhtml.c;h=f17200fa77e0af1e937b45b5b420f7e24c9a7cf2;hp=d01fae29e03133f771743a6ed84e82e00cb5ea6a;hb=05f3f5ede295c4dbe92d291dd719b38721619e7d;hpb=b8d794860f2d0f78c9aff5f295b1c325acbcbe88 diff --git a/src/widgets/modest-tny-stream-gtkhtml.c b/src/widgets/modest-tny-stream-gtkhtml.c index d01fae2..f17200f 100644 --- a/src/widgets/modest-tny-stream-gtkhtml.c +++ b/src/widgets/modest-tny-stream-gtkhtml.c @@ -57,6 +57,9 @@ struct _ModestTnyStreamGtkhtmlPrivate { GtkHTMLStream *stream; GtkHTML *html; guint stop_streams_id; + + gssize max_size; + gssize current_size; }; #define MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_TNY_STREAM_GTKHTML, \ @@ -123,6 +126,9 @@ modest_tny_stream_gtkhtml_init (ModestTnyStreamGtkhtml *obj) priv->stream = NULL; priv->html = NULL; priv->stop_streams_id = 0; + + priv->max_size = 0; + priv->current_size = 0; } static void @@ -160,6 +166,7 @@ modest_tny_stream_gtkhtml_new (GtkHTMLStream *stream, GtkHTML *html) priv->stop_streams_id = g_signal_connect (G_OBJECT (html), "stop-streams", G_CALLBACK (stop_streams), obj); + priv->current_size = 0; return obj; } @@ -193,7 +200,26 @@ gtkhtml_write (TnyStream *self, const char *buffer, size_t n) if (!priv->html || !GTK_WIDGET_VISIBLE (priv->html)) return -1; + if (priv->max_size > 0) { + + /* We only use the maximum size for write method, and even we + * ignore and fake as we would do a successfull read */ + if (priv->current_size >= priv->max_size) + return n; + + if (priv->current_size + n > priv->max_size) + n = priv->max_size - priv->current_size; + } + + if (!g_main_context_is_owner (NULL)) + gdk_threads_enter (); + gtk_html_stream_write (priv->stream, buffer, n); + + if (!g_main_context_is_owner (NULL)) + gdk_threads_leave (); + priv->current_size += n; + return n; /* hmmm */ } @@ -213,7 +239,14 @@ gtkhtml_close (TnyStream *self) priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(self); if (priv->html && GTK_WIDGET_VISIBLE (priv->html)) { + if (!g_main_context_is_owner (NULL)) + gdk_threads_enter (); + gtk_html_stream_close (priv->stream, GTK_HTML_STREAM_OK); + + if (!g_main_context_is_owner (NULL)) + gdk_threads_leave (); + } priv->stream = NULL; if (priv->html && priv->stop_streams_id > 0) { @@ -270,6 +303,29 @@ stop_streams (ModestGtkhtmlMimePartView *view, gpointer userdata) } } +void +modest_tny_stream_gtkhtml_set_max_size (ModestTnyStreamGtkhtml *stream, + gssize max_size) +{ + ModestTnyStreamGtkhtmlPrivate *priv; + + g_return_if_fail (MODEST_IS_TNY_STREAM_GTKHTML (stream)); + priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE (stream); + + priv->max_size = max_size; +} + +gssize +modest_tny_stream_gtkhtml_get_max_size (ModestTnyStreamGtkhtml *stream) +{ + ModestTnyStreamGtkhtmlPrivate *priv; + + g_return_val_if_fail (MODEST_IS_TNY_STREAM_GTKHTML (stream), 0); + priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE (stream); + + return priv->max_size; +} + static void modest_tny_stream_gtkhml_iface_init (gpointer g_iface, gpointer iface_data) {