gtkhtml2 r1161 - in trunk: . tests
- From: dobey svn gnome org
- To: svn-commits-list gnome org
- Subject: gtkhtml2 r1161 - in trunk: . tests
- Date: Sat, 2 Aug 2008 18:02:58 +0000 (UTC)
Author: dobey
Date: Sat Aug 2 18:02:57 2008
New Revision: 1161
URL: http://svn.gnome.org/viewvc/gtkhtml2?rev=1161&view=rev
Log:
2008-08-02 Rodney Dawes <dobey pwns gmail com>
* configure.in:
Use gio and libsoup for the test program instead of gnome-vfs
* tests/main.c (main):
Remove usage of gnome-vfs
* tests/browser-window.c:
Replace all the gnome-vfs calls with GIO and libsoup usage
Add necessary methods for using libsoup
Remove no longer used methods from gnome-vfs usage
Use libsoup for HTTP(S), and GIO for other I/O operations
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/tests/browser-window.c
trunk/tests/main.c
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Sat Aug 2 18:02:57 2008
@@ -54,8 +54,8 @@
AM_CONDITIONAL(ENABLE_ACCESSIBILITY, test x$enable_accessibility = xyes)
-PKG_CHECK_MODULES(GNOME_VFS, gnome-vfs-2.0 >= 1.9.8, have_vfs=true,
- AC_MSG_WARN([*** test apps will be built without GNOME VFS support.])
+PKG_CHECK_MODULES(GNOME_VFS, gio-2.0 libsoup-2.4 >= 2.3.0.1, have_vfs=true,
+ AC_MSG_WARN([*** test apps will be built without VFS support.])
have_vfs=false)
AM_CONDITIONAL(HAVE_GNOME_VFS, test x$have_vfs = xtrue)
Modified: trunk/tests/browser-window.c
==============================================================================
--- trunk/tests/browser-window.c (original)
+++ trunk/tests/browser-window.c Sat Aug 2 18:02:57 2008
@@ -27,7 +27,8 @@
#include <libxml/debugXML.h>
#include <sys/time.h>
#include <unistd.h>
-#include <libgnomevfs/gnome-vfs.h>
+#include <gio/gio.h>
+#include <libsoup/soup.h>
#include <graphics/htmlpainter.h>
#include <util/htmlstream.h>
@@ -43,41 +44,44 @@
static void browser_window_class_init (BrowserWindowClass *klass);
static void browser_window_load_file (BrowserWindow *window, const gchar *name, HtmlParserType type);
static void link_clicked (HtmlDocument *doc, const gchar *url, gpointer data);
+static void url_requested (HtmlDocument *doc, const gchar *uri, HtmlStream *stream, gpointer data);
static GtkWindowClass *parent_class = NULL;
-static GnomeVFSURI *baseURI = NULL;
+static SoupURI *baseURI = NULL;
typedef struct {
HtmlDocument *doc;
HtmlStream *stream;
- GnomeVFSAsyncHandle *handle;
+ GFile *file;
+ GFileInputStream *istream;
+ char buffer[BUFFER_SIZE];
} StreamData;
static gboolean
set_base (BrowserWindow *window, const gchar *url)
{
gchar *str, *Old, *New;
- GnomeVFSURI *new_uri;
+ SoupURI *new_uri;
gboolean equal = FALSE;
if (baseURI) {
- new_uri = gnome_vfs_uri_resolve_relative (baseURI, url);
+ new_uri = soup_uri_new_with_base (baseURI, url);
- Old = gnome_vfs_uri_to_string (baseURI, GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER);
- New = gnome_vfs_uri_to_string (new_uri, GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER);
+ Old = soup_uri_to_string (baseURI, TRUE);
+ New = soup_uri_to_string (new_uri, TRUE);
equal = (strcmp (Old, New) == 0);
g_free (Old);
g_free (New);
- gnome_vfs_uri_unref (baseURI);
+ soup_uri_free (baseURI);
baseURI = new_uri;
}
else
- baseURI = gnome_vfs_uri_new (url);
+ baseURI = soup_uri_new (url);
- str = gnome_vfs_uri_to_string (baseURI, GNOME_VFS_URI_HIDE_NONE);
+ str = soup_uri_to_string (baseURI, FALSE);
gtk_entry_set_text (GTK_ENTRY (window->entry), str);
g_free (str);
@@ -104,50 +108,63 @@
stream_cancel (HtmlStream *stream, gpointer user_data, gpointer cancel_data)
{
StreamData *sdata = (StreamData *)cancel_data;
- gnome_vfs_async_cancel (sdata->handle);
+
+ g_input_stream_close (G_INPUT_STREAM (sdata->istream), NULL, NULL);
free_stream_data (sdata, TRUE);
}
static void
-vfs_close_callback (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer callback_data)
+vfs_read_callback (GObject * source, GAsyncResult * res, gpointer read_data)
{
-}
+ StreamData *sdata = (StreamData *)read_data;
+ GError *error = NULL;
+ gssize size;
-static void
-vfs_read_callback (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
- gpointer buffer, GnomeVFSFileSize bytes_requested,
- GnomeVFSFileSize bytes_read, gpointer callback_data)
-{
- StreamData *sdata = (StreamData *)callback_data;
+ g_return_if_fail (source != NULL);
+ g_return_if_fail (G_IS_INPUT_STREAM (source));
- if (result != GNOME_VFS_OK) {
- gnome_vfs_async_close (handle, vfs_close_callback, sdata);
- free_stream_data (sdata, TRUE);
- g_free (buffer);
- } else {
- html_stream_write (sdata->stream, buffer, bytes_read);
-
- gnome_vfs_async_read (handle, buffer, bytes_requested,
- vfs_read_callback, sdata);
+ size = g_input_stream_read_finish (G_INPUT_STREAM (sdata->istream), res, &error);
+
+ if (error || size <= 0) {
+ if (error)
+ g_error_free (error);
+
+ stream_cancel (sdata->stream, NULL, sdata);
+ return;
+ }
+
+ if (size != 0) {
+ html_stream_write (sdata->stream, sdata->buffer, size);
+ g_input_stream_read_async (G_INPUT_STREAM (sdata->istream),
+ sdata->buffer, BUFFER_SIZE - 1,
+ G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback) vfs_read_callback, sdata);
}
}
+static SoupSession * session;
+
static void
-vfs_open_callback (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer callback_data)
+vfs_http_read (SoupSession * session, SoupMessage * msg, gpointer read_data)
{
- StreamData *sdata = (StreamData *)callback_data;
+ StreamData *sdata = (StreamData *)read_data;
+ const gchar *header;
- if (result != GNOME_VFS_OK) {
+ if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
+ header = soup_message_headers_get (msg->response_headers, "Location");
+ if (header)
+ url_requested (sdata->doc, header, sdata->stream, sdata);
+ return;
+ }
- g_warning ("Open failed: %s.\n", gnome_vfs_result_to_string (result));
- free_stream_data (sdata, TRUE);
- } else {
- gchar *buffer;
+ if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+ html_stream_close (sdata->stream);
+ return;
+ }
- buffer = g_malloc (BUFFER_SIZE);
- gnome_vfs_async_read (handle, buffer, BUFFER_SIZE, vfs_read_callback, sdata);
+ if (msg->response_body->length > 0) {
+ html_stream_write (sdata->stream, msg->response_body->data, msg->response_body->length);
+ html_stream_close (sdata->stream);
}
}
@@ -201,14 +218,17 @@
static void
url_requested (HtmlDocument *doc, const gchar *uri, HtmlStream *stream, gpointer data)
{
- GnomeVFSURI *vfs_uri;
+ SoupURI *vfs_uri;
StreamData *sdata;
GSList *connection_list;
+ char *uri_string;
if (baseURI)
- vfs_uri = gnome_vfs_uri_resolve_relative (baseURI, uri);
+ vfs_uri = soup_uri_new_with_base (baseURI, uri);
else
- vfs_uri = gnome_vfs_uri_new(uri);
+ vfs_uri = soup_uri_new (uri);
+
+ uri_string = soup_uri_to_string (vfs_uri, FALSE);
g_assert (HTML_IS_DOCUMENT(doc));
g_assert (stream != NULL);
@@ -221,12 +241,46 @@
connection_list = g_slist_prepend (connection_list, sdata);
g_object_set_data (G_OBJECT (doc), "connection_list", connection_list);
- gnome_vfs_async_open_uri (&sdata->handle, vfs_uri, GNOME_VFS_OPEN_READ,
- GNOME_VFS_PRIORITY_DEFAULT, vfs_open_callback, sdata);
- gnome_vfs_uri_unref (vfs_uri);
+ if (!strncmp (uri_string, "http://", strlen ("http://")) ||
+ !strncmp (uri_string, "https://", strlen ("https://"))) {
+ static SoupMessage *message;
+
+ if (!session)
+ session = soup_session_async_new ();
+
+ message = soup_message_new (SOUP_METHOD_GET, uri_string);
+ if (!SOUP_IS_MESSAGE (message))
+ goto out;
+
+ soup_message_set_flags (message, SOUP_MESSAGE_NO_REDIRECT);
+
+ soup_message_headers_replace (message->request_headers,
+ "User-Agent",
+ "Mozilla/5.0 (compatible; testgtkhtml)");
- html_stream_set_cancel_func (stream, stream_cancel, sdata);
+ soup_message_headers_replace (message->request_headers,
+ "Accept-Charset", "UTF-8,*");
+
+ soup_session_queue_message (session, message,
+ (SoupSessionCallback) vfs_http_read,
+ sdata);
+ } else {
+ sdata->file = g_file_new_for_uri (uri_string);
+
+ sdata->istream = g_file_read (sdata->file, NULL, NULL);
+ if (sdata->istream)
+ g_input_stream_read_async (G_INPUT_STREAM (sdata->istream),
+ sdata->buffer, BUFFER_SIZE - 1,
+ G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback) vfs_read_callback, sdata);
+
+ html_stream_set_cancel_func (stream, stream_cancel, sdata);
+ }
+
+ out:
+ g_free (uri_string);
+ soup_uri_free (vfs_uri);
}
static void
@@ -238,8 +292,10 @@
while(tmp) {
StreamData *sdata = (StreamData *)tmp->data;
- gnome_vfs_async_cancel (sdata->handle);
- free_stream_data (sdata, FALSE);
+ if (sdata->istream) {
+ g_input_stream_close (G_INPUT_STREAM (sdata->istream), NULL, NULL);
+ free_stream_data (sdata, FALSE);
+ }
tmp = tmp->next;
}
@@ -266,7 +322,7 @@
if (set_base (window, url) == TRUE) {
/* Same document, just jump to the anchor */
- anchor = gnome_vfs_uri_get_fragment_identifier (baseURI);
+ anchor = baseURI->fragment;
if (anchor != NULL)
html_view_jump_to_anchor (window->view, anchor);
}
@@ -278,12 +334,12 @@
html_document_open_stream (window->doc, "text/html");
gtk_adjustment_set_value (gtk_layout_get_vadjustment (GTK_LAYOUT (window->view)), 0);
- str_url = gnome_vfs_uri_to_string (baseURI, GNOME_VFS_URI_HIDE_NONE);
+ str_url = soup_uri_to_string (baseURI, FALSE);
url_requested (window->doc, str_url, window->doc->current_stream, NULL);
g_free (str_url);
if (baseURI) {
- anchor = gnome_vfs_uri_get_fragment_identifier (baseURI);
+ anchor = baseURI->fragment;
if (anchor != NULL)
html_view_jump_to_anchor (window->view, anchor);
}
@@ -467,7 +523,7 @@
static void
browser_window_exit (gpointer data, guint action, GtkWidget *widget)
{
- gnome_vfs_uri_unref (baseURI);
+ soup_uri_free (baseURI);
gtk_main_quit ();
}
Modified: trunk/tests/main.c
==============================================================================
--- trunk/tests/main.c (original)
+++ trunk/tests/main.c Sat Aug 2 18:02:57 2008
@@ -21,7 +21,6 @@
*/
#include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs.h>
#include "gtkhtmlcontext.h"
#include "browser-window.h"
@@ -35,9 +34,6 @@
gtk_init (&argc, &argv);
- puts ("Initializing gnome-vfs...");
- gnome_vfs_init ();
-
browser = browser_window_new (NULL);
g_signal_connect (G_OBJECT (browser), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]