+typedef struct {
+ gpointer buffer;
+ GtkHTML *html;
+ GtkHTMLStream *stream;
+ gboolean html_finalized;
+} ImageFetcherInfo;
+
+static void
+html_finalized_notify (ImageFetcherInfo *ifinfo,
+ GObject *destroyed)
+{
+ ifinfo->html_finalized = TRUE;
+}
+
+static void
+image_fetcher_close (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ gpointer data)
+{
+}
+
+static void
+image_fetcher_read (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ gpointer buffer,
+ GnomeVFSFileSize bytes_requested,
+ GnomeVFSFileSize bytes_read,
+ ImageFetcherInfo *ifinfo)
+{
+
+ if (ifinfo->html_finalized || result != GNOME_VFS_OK) {
+ gnome_vfs_async_close (handle, (GnomeVFSAsyncCloseCallback) image_fetcher_close, (gpointer) NULL);
+ if (!ifinfo->html_finalized) {
+ gtk_html_stream_close (ifinfo->stream, GTK_HTML_STREAM_OK);
+ g_object_weak_unref ((GObject *) ifinfo->html, (GWeakNotify) html_finalized_notify, (gpointer) ifinfo);
+ }
+ g_slice_free1 (128, ifinfo->buffer);
+ g_slice_free (ImageFetcherInfo, ifinfo);
+ return;
+ }
+ gtk_html_stream_write (ifinfo->stream, buffer, bytes_read);
+ gnome_vfs_async_read (handle, ifinfo->buffer, 128,
+ (GnomeVFSAsyncReadCallback)image_fetcher_read, ifinfo);
+ return;
+}
+
+static void
+image_fetcher_open (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ ImageFetcherInfo *ifinfo)
+{
+ if (!ifinfo->html_finalized && result == GNOME_VFS_OK) {
+ ifinfo->buffer = g_slice_alloc (128);
+ gnome_vfs_async_read (handle, ifinfo->buffer, 128,
+ (GnomeVFSAsyncReadCallback) image_fetcher_read, ifinfo);
+ } else {
+ if (!ifinfo->html_finalized) {
+ gtk_html_stream_close (ifinfo->stream, GTK_HTML_STREAM_OK);
+ g_object_weak_unref ((GObject *) ifinfo->html, (GWeakNotify) html_finalized_notify, (gpointer) ifinfo);
+ }
+ g_slice_free (ImageFetcherInfo, ifinfo);
+ }
+}
+