aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-html-stream.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@src.gnome.org>2009-03-01 21:16:31 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2009-03-01 21:16:31 +0800
commit08b1d0ae8e36ef20da800bf6358ca0cd9fb4e026 (patch)
tree2731ee3191355d6bdc90b16d249f711cb1e78afd /mail/em-html-stream.c
parent24abc4f17353ed818a09f324f5ed8822ad9b5a7e (diff)
downloadgsoc2013-evolution-08b1d0ae8e36ef20da800bf6358ca0cd9fb4e026.tar.gz
gsoc2013-evolution-08b1d0ae8e36ef20da800bf6358ca0cd9fb4e026.tar.zst
gsoc2013-evolution-08b1d0ae8e36ef20da800bf6358ca0cd9fb4e026.zip
Split the interactive parts of the message display out of EMFormatHTMLDisplay
to a new GtkHTML subclass named EMailDisplay, and have EMFormatHTML create an instance of that. EMailDisplay will handle link clicking, mousing over URIs, popup menus, and interactive search. This makes EMFormatHTMLDisplay and EMailReader more lightweight. Clean up more of the EMFormat stack. svn path=/branches/kill-bonobo/; revision=37346
Diffstat (limited to 'mail/em-html-stream.c')
-rw-r--r--mail/em-html-stream.c147
1 files changed, 74 insertions, 73 deletions
diff --git a/mail/em-html-stream.c b/mail/em-html-stream.c
index daa81d356d..096e1c9aa5 100644
--- a/mail/em-html-stream.c
+++ b/mail/em-html-stream.c
@@ -27,84 +27,39 @@
#endif
#include <stdio.h>
-#include <gtkhtml/gtkhtml.h>
-#include <gtkhtml/gtkhtml-stream.h>
#include <gtk/gtk.h>
#include "em-html-stream.h"
#define d(x)
-static void em_html_stream_class_init (EMHTMLStreamClass *klass);
-static void em_html_stream_init (CamelObject *object);
-static void em_html_stream_finalize (CamelObject *object);
-
-static ssize_t emhs_sync_write(CamelStream *stream, const char *buffer, size_t n);
-static int emhs_sync_close(CamelStream *stream);
-static int emhs_sync_flush(CamelStream *stream);
-
static EMSyncStreamClass *parent_class = NULL;
-CamelType
-em_html_stream_get_type (void)
-{
- static CamelType type = CAMEL_INVALID_TYPE;
-
- if (type == CAMEL_INVALID_TYPE) {
- parent_class = (EMSyncStreamClass *)em_sync_stream_get_type();
- type = camel_type_register (em_sync_stream_get_type(),
- "EMHTMLStream",
- sizeof (EMHTMLStream),
- sizeof (EMHTMLStreamClass),
- (CamelObjectClassInitFunc) em_html_stream_class_init,
- NULL,
- (CamelObjectInitFunc) em_html_stream_init,
- (CamelObjectFinalizeFunc) em_html_stream_finalize);
- }
-
- return type;
-}
-
-static void
-em_html_stream_class_init (EMHTMLStreamClass *klass)
-{
- ((EMSyncStreamClass *)klass)->sync_write = emhs_sync_write;
- ((EMSyncStreamClass *)klass)->sync_flush = emhs_sync_flush;
- ((EMSyncStreamClass *)klass)->sync_close = emhs_sync_close;
-}
-
-static void
-em_html_stream_init (CamelObject *object)
-{
- /*EMHTMLStream *emhs = (EMHTMLStream *)object;*/
-}
-
static void
-emhs_cleanup(EMHTMLStream *emhs)
+emhs_cleanup (EMHTMLStream *emhs)
{
if (emhs->sync.cancel && emhs->html_stream)
- gtk_html_stream_close (emhs->html_stream, GTK_HTML_STREAM_ERROR);
+ gtk_html_stream_close (
+ emhs->html_stream, GTK_HTML_STREAM_ERROR);
+
emhs->html_stream = NULL;
emhs->sync.cancel = TRUE;
- g_signal_handler_disconnect(emhs->html, emhs->destroy_id);
- g_object_unref(emhs->html);
+ g_signal_handler_disconnect (emhs->html, emhs->destroy_id);
+ g_object_unref (emhs->html);
emhs->html = NULL;
}
static void
-em_html_stream_finalize (CamelObject *object)
+emhs_gtkhtml_destroy (GtkHTML *html,
+ EMHTMLStream *emhs)
{
- EMHTMLStream *emhs = (EMHTMLStream *)object;
-
- d(printf("%p: finalising stream\n", object));
- if (emhs->html_stream) {
- d(printf("%p: html stream still open - error\n", object));
- /* set 'in finalise' flag */
- camel_stream_close((CamelStream *)emhs);
- }
+ emhs->sync.cancel = TRUE;
+ emhs_cleanup (emhs);
}
static ssize_t
-emhs_sync_write(CamelStream *stream, const char *buffer, size_t n)
+emhs_sync_write (CamelStream *stream,
+ const char *buffer,
+ size_t n)
{
EMHTMLStream *emhs = EM_HTML_STREAM (stream);
@@ -112,9 +67,10 @@ emhs_sync_write(CamelStream *stream, const char *buffer, size_t n)
return -1;
if (emhs->html_stream == NULL)
- emhs->html_stream = gtk_html_begin_full (emhs->html, NULL, NULL, emhs->flags);
+ emhs->html_stream = gtk_html_begin_full (
+ emhs->html, NULL, NULL, emhs->flags);
- gtk_html_stream_write(emhs->html_stream, buffer, n);
+ gtk_html_stream_write (emhs->html_stream, buffer, n);
return (ssize_t) n;
}
@@ -133,48 +89,93 @@ emhs_sync_flush(CamelStream *stream)
}
static int
-emhs_sync_close(CamelStream *stream)
+emhs_sync_close (CamelStream *stream)
{
EMHTMLStream *emhs = (EMHTMLStream *)stream;
if (emhs->html_stream == NULL)
return -1;
- gtk_html_stream_close(emhs->html_stream, GTK_HTML_STREAM_OK);
- emhs_cleanup(emhs);
+ gtk_html_stream_close (emhs->html_stream, GTK_HTML_STREAM_OK);
+ emhs_cleanup (emhs);
return 0;
}
static void
-emhs_gtkhtml_destroy(struct _GtkHTML *html, EMHTMLStream *emhs)
+em_html_stream_class_init (EMHTMLStreamClass *class)
{
- d(printf("%p: emhs gtkhtml destroy\n", emhs));
- emhs->sync.cancel = TRUE;
- emhs_cleanup(emhs);
+ EMSyncStreamClass *sync_stream_class;
+
+ parent_class = (EMSyncStreamClass *)em_sync_stream_get_type();
+
+ sync_stream_class = EM_SYNC_STREAM_CLASS (class);
+ sync_stream_class->sync_write = emhs_sync_write;
+ sync_stream_class->sync_flush = emhs_sync_flush;
+ sync_stream_class->sync_close = emhs_sync_close;
+}
+
+static void
+em_html_stream_init (EMHTMLStream *emhs)
+{
+}
+
+static void
+em_html_stream_finalize (EMHTMLStream *emhs)
+{
+ if (emhs->html_stream) {
+ /* set 'in finalise' flag */
+ camel_stream_close (CAMEL_STREAM (emhs));
+ }
+}
+
+CamelType
+em_html_stream_get_type (void)
+{
+ static CamelType type = CAMEL_INVALID_TYPE;
+
+ if (G_UNLIKELY (type == CAMEL_INVALID_TYPE)) {
+ type = camel_type_register (
+ em_sync_stream_get_type(),
+ "EMHTMLStream",
+ sizeof (EMHTMLStream),
+ sizeof (EMHTMLStreamClass),
+ (CamelObjectClassInitFunc) em_html_stream_class_init,
+ NULL,
+ (CamelObjectInitFunc) em_html_stream_init,
+ (CamelObjectFinalizeFunc) em_html_stream_finalize);
+ }
+
+ return type;
}
/* TODO: Could pass NULL for html_stream, and do a gtk_html_begin
on first data -> less flashing */
CamelStream *
-em_html_stream_new(struct _GtkHTML *html, struct _GtkHTMLStream *html_stream)
+em_html_stream_new (GtkHTML *html,
+ GtkHTMLStream *html_stream)
{
EMHTMLStream *new;
+ g_return_val_if_fail (GTK_IS_HTML (html), NULL);
+
new = EM_HTML_STREAM (camel_object_new (EM_HTML_STREAM_TYPE));
new->html_stream = html_stream;
- new->html = html;
+ new->html = g_object_ref (html);
new->flags = 0;
- g_object_ref(html);
- new->destroy_id = g_signal_connect(html, "destroy", G_CALLBACK(emhs_gtkhtml_destroy), new);
+ new->destroy_id = g_signal_connect (
+ html, "destroy",
+ G_CALLBACK (emhs_gtkhtml_destroy), new);
- em_sync_stream_set_buffer_size(&new->sync, 8192);
+ em_sync_stream_set_buffer_size (&new->sync, 8192);
- return (CamelStream *)new;
+ return CAMEL_STREAM (new);
}
void
em_html_stream_set_flags (EMHTMLStream *emhs, GtkHTMLBeginFlags flags)
{
+ g_return_if_fail (EM_IS_HTML_STREAM (emhs));
+
emhs->flags = flags;
}