* Removed an invalid separator in the File menu
[modest] / src / modest-tny-stream-gtkhtml.c
index c17a4a5..c92cc68 100644 (file)
@@ -1,8 +1,37 @@
-/* modest-tny-stream-gtkhtml.c */
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 
-/* insert (c)/licensing information) */
+/* modest-tny-stream-gtkhtml.c */
 
 #include "modest-tny-stream-gtkhtml.h"
+#include <tny-stream.h>
 #include <gtkhtml/gtkhtml-stream.h>
 #include <gtkhtml/gtkhtml-search.h>
 
@@ -48,6 +77,7 @@ modest_tny_stream_gtkhtml_get_type (void)
                        sizeof(ModestTnyStreamGtkhtml),
                        1,              /* n_preallocs */
                        (GInstanceInitFunc) modest_tny_stream_gtkhtml_init,
+                       NULL
                };
 
                static const GInterfaceInfo iface_info = {
@@ -60,7 +90,7 @@ modest_tny_stream_gtkhtml_get_type (void)
                                                  "ModestTnyStreamGtkhtml",
                                                  &my_info, 0);
 
-               g_type_add_interface_static (my_type, TNY_TYPE_STREAM_IFACE,
+               g_type_add_interface_static (my_type, TNY_TYPE_STREAM,
                                             &iface_info);
 
        }
@@ -118,38 +148,41 @@ modest_tny_stream_gtkhtml_new (GtkHTMLStream *stream)
 
 
 static ssize_t
-gtkhtml_read (TnyStreamIface *self, char *buffer, size_t n)
+gtkhtml_read (TnyStream *self, char *buffer, size_t n)
 {
        return -1; /* we cannot read */
 }
 
 
-ssize_t
-gtkhtml_write (TnyStreamIface *self, const char *buffer, size_t n)
+static ssize_t
+gtkhtml_write (TnyStream *self, const char *buffer, size_t n)
 {
        ModestTnyStreamGtkhtmlPrivate *priv;
        
-       g_return_val_if_fail (self, 0);
-
        priv = MODEST_TNY_STREAM_GTKHTML_GET_PRIVATE(self);
-       if (!priv->stream)
-               g_warning ("cannot write to closed stream");
-       else
-               gtk_html_stream_write (priv->stream, buffer, n);
-       
+
+       if (!priv->stream) {
+               g_print ("modest: cannot write to closed stream\n");
+               return 0;
+       }
+
+       if (n == 0 || !buffer)
+               return 0;
+               
+       gtk_html_stream_write (priv->stream, buffer, n);
        return n; /* hmmm */
 }
 
        
 static gint
-gtkhtml_flush (TnyStreamIface *self)
+gtkhtml_flush (TnyStream *self)
 {
        return 0;
 }
        
 
 static gint
-gtkhtml_close (TnyStreamIface *self)
+gtkhtml_close (TnyStream *self)
 {
        ModestTnyStreamGtkhtmlPrivate *priv;
        g_return_val_if_fail (self, 0);
@@ -163,7 +196,7 @@ gtkhtml_close (TnyStreamIface *self)
 
 
 static gboolean
-gtkhtml_eos (TnyStreamIface *self)
+gtkhtml_is_eos (TnyStream *self)
 {
        return TRUE;
 }
@@ -171,14 +204,14 @@ gtkhtml_eos (TnyStreamIface *self)
 
        
 static gint
-gtkhtml_reset (TnyStreamIface *self)
+gtkhtml_reset (TnyStream *self)
 {
        return 0;
 }
 
        
 static ssize_t
-gtkhtml_write_to_stream (TnyStreamIface *self, TnyStreamIface *output)
+gtkhtml_write_to_stream (TnyStream *self, TnyStream *output)
 {
        return 0;
 }
@@ -187,17 +220,17 @@ gtkhtml_write_to_stream (TnyStreamIface *self, TnyStreamIface *output)
 static void
 modest_tny_stream_gtkhml_iface_init (gpointer g_iface, gpointer iface_data)
 {
-        TnyStreamIfaceClass *klass;
+        TnyStreamIface *klass;
        
        g_return_if_fail (g_iface);
 
-       klass = (TnyStreamIfaceClass *)g_iface;
+       klass = (TnyStreamIface*) g_iface;
        
-        klass->read_func  = gtkhtml_read;
-        klass->write_func = gtkhtml_write;
-        klass->flush_func = gtkhtml_flush;
-        klass->close_func = gtkhtml_close;
-       klass->eos_func   = gtkhtml_eos;
-       klass->reset_func = gtkhtml_reset;
+        klass->read_func            = gtkhtml_read;
+        klass->write_func           = gtkhtml_write;
+        klass->flush_func           = gtkhtml_flush;
+        klass->close_func           = gtkhtml_close;
+       klass->is_eos_func          = gtkhtml_is_eos;
+       klass->reset_func           = gtkhtml_reset;
        klass->write_to_stream_func = gtkhtml_write_to_stream;
 }