1 /* modest-tny-stream-gtkhtml.c */
3 /* insert (c)/licensing information) */
5 #include "modest-tny-stream-gtkhtml.h"
6 #include <gtkhtml/gtkhtml-stream.h>
7 #include <gtkhtml/gtkhtml-search.h>
9 /* 'private'/'protected' functions */
10 static void modest_tny_stream_gtkhtml_class_init (ModestTnyStreamGtkhtmlClass *klass);
11 static void modest_tny_stream_gtkhtml_init (ModestTnyStreamGtkhtml *obj);
12 static void modest_tny_stream_gtkhtml_finalize (GObject *obj);
14 static void modest_tny_stream_gtkhml_iface_init (gpointer g_iface, gpointer iface_data);
23 typedef struct _ModestTnyStreamGtkhtmlPrivate ModestTnyStreamGtkhtmlPrivate;
24 struct _ModestTnyStreamGtkhtmlPrivate {
25 GtkHTMLStream *stream;
27 #define MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
28 MODEST_TYPE_TNY_STREAM_GTKHTML, \
29 ModestTnyStreamGtkhtmlPrivate))
31 static GObjectClass *parent_class = NULL;
33 /* uncomment the following if you have defined any signals */
34 /* static guint signals[LAST_SIGNAL] = {0}; */
37 modest_tny_stream_gtkhtml_get_type (void)
39 static GType my_type = 0;
41 static const GTypeInfo my_info = {
42 sizeof(ModestTnyStreamGtkhtmlClass),
44 NULL, /* base finalize */
45 (GClassInitFunc) modest_tny_stream_gtkhtml_class_init,
46 NULL, /* class finalize */
47 NULL, /* class data */
48 sizeof(ModestTnyStreamGtkhtml),
50 (GInstanceInitFunc) modest_tny_stream_gtkhtml_init,
53 static const GInterfaceInfo iface_info = {
54 (GInterfaceInitFunc) modest_tny_stream_gtkhml_iface_init,
55 NULL, /* interface_finalize */
56 NULL /* interface_data */
59 my_type = g_type_register_static (G_TYPE_OBJECT,
60 "ModestTnyStreamGtkhtml",
63 g_type_add_interface_static (my_type, TNY_TYPE_STREAM_IFACE,
71 modest_tny_stream_gtkhtml_class_init (ModestTnyStreamGtkhtmlClass *klass)
73 GObjectClass *gobject_class;
74 gobject_class = (GObjectClass*) klass;
76 parent_class = g_type_class_peek_parent (klass);
77 gobject_class->finalize = modest_tny_stream_gtkhtml_finalize;
79 g_type_class_add_private (gobject_class, sizeof(ModestTnyStreamGtkhtmlPrivate));
83 modest_tny_stream_gtkhtml_init (ModestTnyStreamGtkhtml *obj)
85 ModestTnyStreamGtkhtmlPrivate *priv;
86 priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(obj);
92 modest_tny_stream_gtkhtml_finalize (GObject *obj)
94 ModestTnyStreamGtkhtmlPrivate *priv;
96 priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(obj);
101 modest_tny_stream_gtkhtml_new (GtkHTMLStream *stream)
104 ModestTnyStreamGtkhtmlPrivate *priv;
106 obj = G_OBJECT(g_object_new(MODEST_TYPE_TNY_STREAM_GTKHTML, NULL));
107 priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(obj);
109 g_return_val_if_fail (stream, NULL);
111 priv->stream = stream;
117 /* the rest are interface functions */
121 gtkhtml_read (TnyStreamIface *self, char *buffer, size_t n)
123 return -1; /* we cannot read */
128 gtkhtml_write (TnyStreamIface *self, const char *buffer, size_t n)
130 ModestTnyStreamGtkhtmlPrivate *priv;
132 g_return_val_if_fail (self, 0);
134 priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(self);
136 g_warning ("cannot write to closed stream");
138 gtk_html_stream_write (priv->stream, buffer, n);
145 gtkhtml_flush (TnyStreamIface *self)
152 gtkhtml_close (TnyStreamIface *self)
154 ModestTnyStreamGtkhtmlPrivate *priv;
155 g_return_val_if_fail (self, 0);
156 priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(self);
158 gtk_html_stream_close (priv->stream, GTK_HTML_STREAM_OK);
166 gtkhtml_eos (TnyStreamIface *self)
174 gtkhtml_reset (TnyStreamIface *self)
181 gtkhtml_write_to_stream (TnyStreamIface *self, TnyStreamIface *output)
188 modest_tny_stream_gtkhml_iface_init (gpointer g_iface, gpointer iface_data)
190 TnyStreamIfaceClass *klass;
192 g_return_if_fail (g_iface);
194 klass = (TnyStreamIfaceClass *)g_iface;
196 klass->read_func = gtkhtml_read;
197 klass->write_func = gtkhtml_write;
198 klass->flush_func = gtkhtml_flush;
199 klass->close_func = gtkhtml_close;
200 klass->eos_func = gtkhtml_eos;
201 klass->reset_func = gtkhtml_reset;
202 klass->write_to_stream_func = gtkhtml_write_to_stream;