aboutsummaryrefslogtreecommitdiffstats
path: root/mail/html-stream.c
blob: 31afe4bd254dd6aa06a0cc224d7b305e8ac76178 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * html-stream.c: A CamelStream class that feeds data into a GtkHTML widget
 *
 * Author:
 *   Miguel de Icaza (miguel@helixcode.com)
 *
 * (C) 2000 Helix Code, Inc.
 */
#include <config.h>
#include "html-stream.h"
#include "e-util/e-util.h"

#define PARENT_TYPE camel_stream_get_type ()

static GtkObjectClass *html_stream_parent_class;

/*
 * CamelStream::read method
 *
 * Return 0 bytes read, as this is a write-only stream
 */
static gint
html_stream_read (CamelStream *stream, gchar *buffer, gint n)
{
    return 0;
}

/*
 * CamelStream::write method
 *
 * Writes @buffer into the HTML widget
 */
static gint
html_stream_write (CamelStream *stream, const gchar *buffer, gint n)
{
    HTMLStream *html_stream = HTML_STREAM (stream);

    if (html_stream->gtk_html_stream)
        gtk_html_write (html_stream->gtk_html, html_stream->gtk_html_stream, buffer, n);
    else 
        n = 0;

    return n;
}

/* 
 * CamelStream::Reset method
 * 
 * Reset the html widget that is, prepare it 
 * for a new display 
 */
static void
html_stream_reset (CamelStream *stream)
{
    HTMLStream *html_stream = HTML_STREAM (stream);
    
    if (html_stream->gtk_html_stream)
        gtk_html_end (html_stream->gtk_html, html_stream->gtk_html_stream, GTK_HTML_STREAM_OK);
    
    html_stream->gtk_html_stream = gtk_html_begin (html_stream->gtk_html, "");
}

/*
 * CamelStream::available method
 *
 * Return 0, as this is only a write-stream
 */
static gint
html_stream_available (CamelStream *stream)
{
    return 0;
}

/*
 * CamelStream::eos method.
 *
 * We just return TRUE, as this is not a read-stream
 */
static gboolean
html_stream_eos (CamelStream *stream)
{
    return TRUE;
}

static void
html_stream_close (CamelStream *stream)
{
    HTMLStream *html_stream = HTML_STREAM (stream);
    
    gtk_html_end (html_stream->gtk_html, html_stream->gtk_html_stream, GTK_HTML_STREAM_OK);
    html_stream->gtk_html_stream = NULL;
}

static void
html_stream_destroy (GtkObject *object)
{
}

static void
html_stream_class_init (GtkObjectClass *object_class)
{
    CamelStreamClass *stream_class = (CamelStreamClass *) object_class;

    html_stream_parent_class = gtk_type_class (PARENT_TYPE);
    
    object_class->destroy = html_stream_destroy;
    
    stream_class->read = html_stream_read;
    stream_class->write = html_stream_write;
    stream_class->reset = html_stream_reset;
    stream_class->available = html_stream_available;
    stream_class->eos = html_stream_eos;
    stream_class->close = html_stream_close;
}

CamelStream *
html_stream_new (GtkHTML *html)
{
    HTMLStream *html_stream;

    g_return_val_if_fail (html != NULL, NULL);
    g_return_val_if_fail (GTK_IS_HTML (html), NULL);
    
    html_stream = gtk_type_new (html_stream_get_type ());

    gtk_object_ref (GTK_OBJECT (html));

    html_stream->gtk_html_stream = gtk_html_begin (html, "");
    
    html_stream->gtk_html = html;

    return CAMEL_STREAM (html_stream);
}

E_MAKE_TYPE (html_stream, "HTMLStream", HTMLStream, html_stream_class_init, NULL, PARENT_TYPE);