X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-stream-text-to-html.c;h=bd43e00e7cfd3974e25262f498598dac95501faa;hp=4eee0f08ae6166ffe81f34486fb90c1ae6150f08;hb=d3152f5a6ea0f939f9535fd8024538d95f14b588;hpb=e61d161744d31c7799d1a7b5246b53a7a03d9ea5 diff --git a/src/modest-stream-text-to-html.c b/src/modest-stream-text-to-html.c index 4eee0f0..bd43e00 100644 --- a/src/modest-stream-text-to-html.c +++ b/src/modest-stream-text-to-html.c @@ -38,8 +38,8 @@ #define HTML_PREFIX "" \ "" \ "" \ - "" -#define HTML_SUFFIX "" + "

" +#define HTML_SUFFIX "

" /* 'private'/'protected' functions */ @@ -58,7 +58,9 @@ struct _ModestStreamTextToHtmlPrivate { gboolean written_prefix; gsize linkify_limit; gsize full_limit; + gsize line_limit; gsize total_output; + gsize total_lines_output; }; #define MODEST_STREAM_TEXT_TO_HTML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_STREAM_TEXT_TO_HTML, \ @@ -125,6 +127,8 @@ modest_stream_text_to_html_init (ModestStreamTextToHtml *obj) priv->linkify_limit = 0; priv->full_limit = 0; priv->total_output = 0; + priv->total_lines_output = 0; + modest_text_utils_hyperlinkify_begin (); } static void @@ -139,6 +143,7 @@ modest_stream_text_to_html_finalize (GObject *obj) if (priv->line_buffer != NULL) { g_string_free (priv->line_buffer, TRUE); } + modest_text_utils_hyperlinkify_end (); } GObject* @@ -158,6 +163,13 @@ modest_stream_text_to_html_new (TnyStream *out_stream) } void +modest_stream_text_to_html_set_line_limit (ModestStreamTextToHtml *self, gssize limit) +{ + ModestStreamTextToHtmlPrivate *priv = MODEST_STREAM_TEXT_TO_HTML_GET_PRIVATE (self); + priv->line_limit = limit; +} + +void modest_stream_text_to_html_set_linkify_limit (ModestStreamTextToHtml *self, gssize limit) { ModestStreamTextToHtmlPrivate *priv = MODEST_STREAM_TEXT_TO_HTML_GET_PRIVATE (self); @@ -171,6 +183,16 @@ modest_stream_text_to_html_set_full_limit (ModestStreamTextToHtml *self, gssize priv->full_limit = limit; } +gboolean +modest_stream_text_to_html_limit_reached (ModestStreamTextToHtml *self) +{ + ModestStreamTextToHtmlPrivate *priv = MODEST_STREAM_TEXT_TO_HTML_GET_PRIVATE (self); + + return (priv->full_limit > 0 && priv->total_output > priv->full_limit) || + (priv->line_limit > 0 && priv->total_lines_output > priv->line_limit); + +} + /* the rest are interface functions */ @@ -193,6 +215,8 @@ write_line (TnyStream *self, const gchar *str, gboolean convert_to_html) preserve the prefix and suffix */ if (convert_to_html && (priv->full_limit > 0) &&(priv->total_output > priv->full_limit)) return TRUE; + if (convert_to_html && (priv->line_limit > 0) && (priv->total_lines_output > priv->line_limit)) + return TRUE; if ((priv->linkify_limit > 0) && (priv->total_output > priv->linkify_limit)) hyperlinkify = FALSE; if (convert_to_html) { @@ -203,6 +227,7 @@ write_line (TnyStream *self, const gchar *str, gboolean convert_to_html) pending_bytes = strlen (html_buffer); priv->total_output += pending_bytes; + priv->total_lines_output ++; offset = html_buffer; while (pending_bytes > 0) { @@ -240,6 +265,12 @@ text_to_html_write (TnyStream *self, const char *buffer, size_t n) while (n > 0) { gchar c = *buffer; + + if ((priv->full_limit > 0) && (priv->total_output > priv->full_limit)) + return n; + if ((priv->line_limit > 0) && (priv->total_lines_output > priv->line_limit)) + return n; + if (priv->line_buffer == NULL) priv->line_buffer = g_string_new (NULL); @@ -323,11 +354,11 @@ modest_stream_text_to_html_iface_init (gpointer g_iface, gpointer iface_data) klass = (TnyStreamIface*) g_iface; - klass->read_func = text_to_html_read; - klass->write_func = text_to_html_write; - klass->flush_func = text_to_html_flush; - klass->close_func = text_to_html_close; - klass->is_eos_func = text_to_html_is_eos; - klass->reset_func = text_to_html_reset; - klass->write_to_stream_func = text_to_html_write_to_stream; + klass->read = text_to_html_read; + klass->write = text_to_html_write; + klass->flush = text_to_html_flush; + klass->close = text_to_html_close; + klass->is_eos = text_to_html_is_eos; + klass->reset = text_to_html_reset; + klass->write_to_stream = text_to_html_write_to_stream; }