Loading urls from GtkHTML::url_requested using GnomeVFSAsyncRead



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

Context:
Writing a html editor using GtkHTML for Preview and the GtkHTML widget is
emitting the url_requested signal for image files in the webpage.

Problem:
So I catch the GtkHTML::url_requested signal. Now I try to write the data
read by the GnomeVFS asynchronous ops, well just see the code snippet...


#define BUF_SIZE 32

typedef struct {
	GtkHTML *html;
	GtkHTMLStream *stream;
} AsyncReadData;


static void
url_requested_async_read_cb (GnomeVFSAsyncHandle *handle,
			     GnomeVFSResult result,
			     gpointer buffer,
			     GnomeVFSFileSize bytes_requested,
			     GnomeVFSFileSize bytes_read,
			     gpointer data)
{
	GtkHTML       *html;
	GtkHTMLStream *html_handle;
	AsyncReadData *udata;

	udata = (AsyncReadData *) data;
	html = udata->html;
	html_handle = udata->stream;

	if (result != GNOME_VFS_OK) {
		if (result == GNOME_VFS_ERROR_EOF)
			gnome_vfs_async_close (handle, NULL, NULL);

		fprintf (stderr, "async_read_cb (): Read failed - %s", 
			 gnome_vfs_result_to_string (result));

		g_free (data);
		return;
	} else {
		if (bytes_read > 0)
			gtk_html_write (GTK_HTML (html), html_handle,
					buffer, bytes_read);

	}
}


static void
url_requested_async_open_cb (GnomeVFSAsyncHandle *handle,
			     GnomeVFSResult result,
			     gpointer data)
{
	if (result != GNOME_VFS_OK) {
		fprintf (stderr, "async_open_cb (): Error opening url to read - %s", gnome_vfs_result_to_string (result));
		return;
	} else {
	        gchar buffer[BUF_SIZE];

		gnome_vfs_async_read (handle, buffer, BUF_SIZE,
				      url_requested_async_read_cb, NULL);
	}
}


static void
html_view_url_requested_cb (GtkHTML *html, const gchar *url,
			    GtkHTMLStream *handle, gpointer data)
{
  	GnomeVFSAsyncHandle *vfs_handle;
  	GnomeVFSURI         *uri;
  	PeacockFile         *file;
  	AsyncReadData       *udata;

  	file = gtk_object_get_data (GTK_OBJECT (data), "file");
  	uri = gnome_vfs_uri_resolve_relative (file->uri, url);

  	udata = g_new0 (AsyncReadData, 1);
  	udata->html = html;
  	udata->stream = handle;

  	gnome_vfs_async_open_uri (&vfs_handle, uri, GNOME_VFS_OPEN_READ,
  				  url_requested_async_open_cb, udata);

  	gnome_vfs_uri_unref (uri);
	return;
}


Some how in the url_requested_async_read_cb, the GtkHTMLStream * pointer 
points to NULL.

Any ideas?

Thanks in advance
Archit Baweja
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 and Gnu Privacy Guard <http://www.gnupg.org/>

iD8DBQE9dWKP2rWNPKmGjMcRApYbAJ45QkSwDyQulnIBI9Cp6Qt3VoYIjQCfbw/k
5drXnki8fjjnGCiQrS2nKJg=
=8CSp
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]