* compile fixes
[modest] / src / modest-tny-stream-gtkhtml.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30
31 /* modest-tny-stream-gtkhtml.c */
32
33 #include "modest-tny-stream-gtkhtml.h"
34 #include <gtkhtml/gtkhtml-stream.h>
35 #include <gtkhtml/gtkhtml-search.h>
36
37 /* 'private'/'protected' functions */
38 static void  modest_tny_stream_gtkhtml_class_init   (ModestTnyStreamGtkhtmlClass *klass);
39 static void  modest_tny_stream_gtkhtml_init         (ModestTnyStreamGtkhtml *obj);
40 static void  modest_tny_stream_gtkhtml_finalize     (GObject *obj);
41
42 static void  modest_tny_stream_gtkhml_iface_init (gpointer g_iface, gpointer iface_data);
43
44 /* list my signals */
45 enum {
46         /* MY_SIGNAL_1, */
47         /* MY_SIGNAL_2, */
48         LAST_SIGNAL
49 };
50
51 typedef struct _ModestTnyStreamGtkhtmlPrivate ModestTnyStreamGtkhtmlPrivate;
52 struct _ModestTnyStreamGtkhtmlPrivate {
53         GtkHTMLStream *stream;
54 };
55 #define MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
56                                                        MODEST_TYPE_TNY_STREAM_GTKHTML, \
57                                                        ModestTnyStreamGtkhtmlPrivate))
58 /* globals */
59 static GObjectClass *parent_class = NULL;
60
61 /* uncomment the following if you have defined any signals */
62 /* static guint signals[LAST_SIGNAL] = {0}; */
63
64 GType
65 modest_tny_stream_gtkhtml_get_type (void)
66 {
67         static GType my_type = 0;
68         if (!my_type) {
69                 static const GTypeInfo my_info = {
70                         sizeof(ModestTnyStreamGtkhtmlClass),
71                         NULL,           /* base init */
72                         NULL,           /* base finalize */
73                         (GClassInitFunc) modest_tny_stream_gtkhtml_class_init,
74                         NULL,           /* class finalize */
75                         NULL,           /* class data */
76                         sizeof(ModestTnyStreamGtkhtml),
77                         1,              /* n_preallocs */
78                         (GInstanceInitFunc) modest_tny_stream_gtkhtml_init,
79                         NULL
80                 };
81
82                 static const GInterfaceInfo iface_info = {
83                         (GInterfaceInitFunc) modest_tny_stream_gtkhml_iface_init,
84                         NULL,         /* interface_finalize */
85                         NULL          /* interface_data */
86                 };
87
88                 my_type = g_type_register_static (G_TYPE_OBJECT,
89                                                   "ModestTnyStreamGtkhtml",
90                                                   &my_info, 0);
91
92                 g_type_add_interface_static (my_type, TNY_TYPE_STREAM_IFACE,
93                                              &iface_info);
94
95         }
96         return my_type;
97 }
98
99 static void
100 modest_tny_stream_gtkhtml_class_init (ModestTnyStreamGtkhtmlClass *klass)
101 {
102         GObjectClass *gobject_class;
103         gobject_class = (GObjectClass*) klass;
104
105         parent_class            = g_type_class_peek_parent (klass);
106         gobject_class->finalize = modest_tny_stream_gtkhtml_finalize;
107
108         g_type_class_add_private (gobject_class, sizeof(ModestTnyStreamGtkhtmlPrivate));
109 }
110
111 static void
112 modest_tny_stream_gtkhtml_init (ModestTnyStreamGtkhtml *obj)
113 {
114         ModestTnyStreamGtkhtmlPrivate *priv;
115         priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(obj);
116
117         priv->stream  = NULL;
118 }
119
120 static void
121 modest_tny_stream_gtkhtml_finalize (GObject *obj)
122 {
123         ModestTnyStreamGtkhtmlPrivate *priv;
124
125         priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(obj);
126         priv->stream = NULL;
127 }
128
129 GObject*
130 modest_tny_stream_gtkhtml_new (GtkHTMLStream *stream)
131 {
132         GObject *obj;
133         ModestTnyStreamGtkhtmlPrivate *priv;
134         
135         obj  = G_OBJECT(g_object_new(MODEST_TYPE_TNY_STREAM_GTKHTML, NULL));
136         priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(obj);
137
138         g_return_val_if_fail (stream, NULL);
139         
140         priv->stream = stream;
141
142         return obj;
143 }
144
145
146 /* the rest are interface functions */
147
148
149 static ssize_t
150 gtkhtml_read (TnyStreamIface *self, char *buffer, size_t n)
151 {
152         return -1; /* we cannot read */
153 }
154
155
156 static ssize_t
157 gtkhtml_write (TnyStreamIface *self, const char *buffer, size_t n)
158 {
159         ModestTnyStreamGtkhtmlPrivate *priv;
160         
161         priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(self);
162
163         if (!priv->stream) {
164                 g_print ("modest: cannot write to closed stream\n");
165                 return 0;
166         }
167
168         if (n == 0 || !buffer)
169                 return 0;
170                 
171         gtk_html_stream_write (priv->stream, buffer, n);
172         return n; /* hmmm */
173 }
174
175         
176 static gint
177 gtkhtml_flush (TnyStreamIface *self)
178 {
179         return 0;
180 }
181         
182
183 static gint
184 gtkhtml_close (TnyStreamIface *self)
185 {
186         ModestTnyStreamGtkhtmlPrivate *priv;
187         g_return_val_if_fail (self, 0);
188         priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(self);
189         
190         gtk_html_stream_close   (priv->stream, GTK_HTML_STREAM_OK);
191         priv->stream = NULL;
192
193         return 0;
194 }
195
196
197 static gboolean
198 gtkhtml_eos (TnyStreamIface *self)
199 {
200         return TRUE;
201 }
202
203
204         
205 static gint
206 gtkhtml_reset (TnyStreamIface *self)
207 {
208         return 0;
209 }
210
211         
212 static ssize_t
213 gtkhtml_write_to_stream (TnyStreamIface *self, TnyStreamIface *output)
214 {
215         return 0;
216 }
217
218
219 static void
220 modest_tny_stream_gtkhml_iface_init (gpointer g_iface, gpointer iface_data)
221 {
222         TnyStreamIfaceClass *klass;
223         
224         g_return_if_fail (g_iface);
225
226         klass = (TnyStreamIfaceClass *)g_iface;
227         
228         klass->read_func            = gtkhtml_read;
229         klass->write_func           = gtkhtml_write;
230         klass->flush_func           = gtkhtml_flush;
231         klass->close_func           = gtkhtml_close;
232         klass->eos_func             = gtkhtml_eos;
233         klass->reset_func           = gtkhtml_reset;
234         klass->write_to_stream_func = gtkhtml_write_to_stream;
235 }