diff -up libgnomeui-2.21.91/test-gnome/Makefile.am.gio-thumbnail libgnomeui-2.21.91/test-gnome/Makefile.am
--- libgnomeui-2.21.91/test-gnome/Makefile.am.gio-thumbnail 2006-12-31 05:47:38.000000000 -0500
+++ libgnomeui-2.21.91/test-gnome/Makefile.am 2008-02-19 12:36:06.000000000 -0500
@@ -14,7 +14,7 @@ LDADD = \
$(top_builddir)/libgnomeui/libgnomeui-2.la $(GNOME_TEST_LIBS)
noinst_PROGRAMS = \
- test-gnome test-druid test-entry test-iconlist test-password-dialog
+ test-gnome test-druid test-entry test-iconlist test-password-dialog test-gnomegdkpixbuf
test_gnome_SOURCES = \
testgnome.c \
@@ -34,6 +34,9 @@ test_entry_SOURCES = \
test_iconlist_SOURCES = \
testiconlist.c
+test_gnomegdkpixbuf_SOURCES = \
+ testgnomegdkpixbuf.c
+
EXTRA_DIST = \
bomb.xpm \
testgnome.xml
diff -up /dev/null libgnomeui-2.21.91/test-gnome/testgnomegdkpixbuf.c
--- /dev/null 2008-02-19 08:34:07.012713418 -0500
+++ libgnomeui-2.21.91/test-gnome/testgnomegdkpixbuf.c 2008-02-19 12:36:06.000000000 -0500
@@ -0,0 +1,101 @@
+
+#include <config.h>
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <gio/gio.h>
+#include <libgnomeui.h>
+#include <libgnomeui/gnome-thumbnail.h>
+
+static gboolean async_ok;
+
+static void
+pixbuf_done (GnomeGdkPixbufAsyncHandle *handle, gpointer user_data)
+{
+ gtk_main_quit ();
+}
+
+static void
+pixbuf_loaded (GnomeGdkPixbufAsyncHandle *handle,
+ GnomeVFSResult error,
+ GdkPixbuf *pixbuf,
+ gpointer user_data)
+{
+ if (pixbuf != NULL) {
+ GError *error = NULL;
+
+ if (!gdk_pixbuf_save (pixbuf, "pixbuf-async.png", "png", &error, NULL)) {
+ g_warning ("Error saving file pixbuf-async.png: %s", error->message);
+ } else {
+ async_ok = TRUE;
+ }
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ int ret;
+ char *uri;
+ GdkPixbuf *pixbuf;
+ GFile *file;
+ GError *error;
+ GnomeGdkPixbufAsyncHandle *handle;
+
+ uri = NULL;
+ error = NULL;
+ async_ok = FALSE;
+ ret = 1;
+
+ gtk_init (&argc, &argv);
+
+ if (argc != 2) {
+ g_warning ("usage: %s <uri_to_imagefile>", argv[0]);
+ goto out;
+ }
+
+ /* this is a cheap trick to get file:/// properly appended */
+ file = g_file_new_for_commandline_arg (argv[1]);
+ uri = g_file_get_uri (file);
+ g_object_unref (file);
+
+ /* first, test the sync version */
+ g_message ("Using gnome_gdk_pixbuf_new_from_uri() to load file with uri '%s'", uri);
+
+ pixbuf = gnome_gdk_pixbuf_new_from_uri (uri);
+ if (pixbuf == NULL) {
+ g_warning ("gnome_gdk_pixbuf_new_from_uri() failed");
+ goto out;
+ }
+ if (!gdk_pixbuf_save (pixbuf, "pixbuf-sync.png", "png", &error, NULL)) {
+ g_warning ("Error saving file pixbuf-sync.png: %s", error->message);
+ goto out;
+ }
+ g_object_unref (pixbuf);
+
+ g_message ("Saved pixbuf to pixbuf-sync.png");
+
+ /* now, the async version */
+ g_message ("Using gnome_gdk_pixbuf_new_from_uri_async() to load file with uri '%s'", uri);
+
+ handle = gnome_gdk_pixbuf_new_from_uri_async (uri,
+ pixbuf_loaded,
+ pixbuf_done,
+ NULL);
+
+ gtk_main ();
+
+ if (!async_ok) {
+ g_warning ("Error saving file pixbuf-async.png");
+ goto out;
+ }
+
+ g_message ("Saved pixbuf to pixbuf-async.png");
+
+ ret = 0;
+
+out:
+ g_free (uri);
+ return ret;
+}
diff -up libgnomeui-2.21.91/libgnomeui/gnome-vfs-util.c.gio-thumbnail libgnomeui-2.21.91/libgnomeui/gnome-vfs-util.c
--- libgnomeui-2.21.91/libgnomeui/gnome-vfs-util.c.gio-thumbnail 2007-09-23 11:36:33.000000000 -0400
+++ libgnomeui-2.21.91/libgnomeui/gnome-vfs-util.c 2008-02-19 12:55:23.000000000 -0500
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <string.h>
#include <glib-object.h>
+#include <gio/gio.h>
#include "gnome-vfs-util.h"
@@ -48,7 +49,10 @@
#define LOAD_BUFFER_SIZE 4096
struct GnomeGdkPixbufAsyncHandle {
- GnomeVFSAsyncHandle *vfs_handle;
+ GFile *file;
+ GFileInputStream *file_input_stream;
+ GCancellable *cancellable;
+
GnomeGdkPixbufLoadCallback load_callback;
GnomeGdkPixbufDoneCallback done_callback;
gpointer callback_data;
@@ -65,18 +69,12 @@ typedef struct {
} SizePrepareContext;
-static void file_opened_callback (GnomeVFSAsyncHandle *vfs_handle,
- GnomeVFSResult result,
- gpointer callback_data);
-static void file_read_callback (GnomeVFSAsyncHandle *vfs_handle,
- GnomeVFSResult result,
- gpointer buffer,
- GnomeVFSFileSize bytes_requested,
- GnomeVFSFileSize bytes_read,
- gpointer callback_data);
-static void file_closed_callback (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer callback_data);
+static void input_stream_read_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+static void input_stream_ready_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
static void load_done (GnomeGdkPixbufAsyncHandle *handle,
GnomeVFSResult result,
GdkPixbuf *pixbuf);
@@ -165,7 +163,6 @@ gnome_gdk_pixbuf_new_from_uri_at_scale (
gboolean preserve_aspect_ratio)
{
GnomeVFSResult result;
- GnomeVFSHandle *handle;
char buffer[LOAD_BUFFER_SIZE];
GnomeVFSFileSize bytes_read;
GdkPixbufLoader *loader;
@@ -174,13 +171,15 @@ gnome_gdk_pixbuf_new_from_uri_at_scale (
GdkPixbufAnimationIter *iter;
gboolean has_frame;
SizePrepareContext info;
+ GFile *file;
+ GFileInputStream *file_input_stream;
g_return_val_if_fail (uri != NULL, NULL);
- result = gnome_vfs_open (&handle,
- uri,
- GNOME_VFS_OPEN_READ);
- if (result != GNOME_VFS_OK) {
+ file = g_file_new_for_uri (uri);
+ file_input_stream = g_file_read (file, NULL, NULL);
+ if (file_input_stream == NULL) {
+ g_object_unref (file);
return NULL;
}
@@ -195,17 +194,22 @@ gnome_gdk_pixbuf_new_from_uri_at_scale (
has_frame = FALSE;
+ result = GNOME_VFS_ERROR_GENERIC;
while (!has_frame) {
- result = gnome_vfs_read (handle,
- buffer,
- sizeof (buffer),
- &bytes_read);
- if (result != GNOME_VFS_OK) {
+
+ bytes_read = g_input_stream_read (G_INPUT_STREAM (file_input_stream),
+ buffer,
+ sizeof (buffer),
+ NULL,
+ NULL);
+ if (bytes_read == -1) {
break;
}
+ result = GNOME_VFS_OK;
if (bytes_read == 0) {
break;
}
+
if (!gdk_pixbuf_loader_write (loader,
(unsigned char *)buffer,
bytes_read,
@@ -226,13 +230,17 @@ gnome_gdk_pixbuf_new_from_uri_at_scale (
gdk_pixbuf_loader_close (loader, NULL);
- if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
+ if (result != GNOME_VFS_OK) {
g_object_unref (G_OBJECT (loader));
- gnome_vfs_close (handle);
+ g_input_stream_close (G_INPUT_STREAM (file_input_stream), NULL, NULL);
+ g_object_unref (file_input_stream);
+ g_object_unref (file);
return NULL;
}
- gnome_vfs_close (handle);
+ g_input_stream_close (G_INPUT_STREAM (file_input_stream), NULL, NULL);
+ g_object_unref (file_input_stream);
+ g_object_unref (file);
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (pixbuf != NULL) {
@@ -260,101 +268,89 @@ gnome_gdk_pixbuf_new_from_uri_async (con
handle->done_callback = done_callback;
handle->callback_data = callback_data;
- gnome_vfs_async_open (&handle->vfs_handle,
- uri,
- GNOME_VFS_OPEN_READ,
- GNOME_VFS_PRIORITY_DEFAULT,
- file_opened_callback,
- handle);
-
+ handle->file = g_file_new_for_uri (uri);
+ handle->cancellable = g_cancellable_new ();
+ g_file_read_async (handle->file,
+ G_PRIORITY_DEFAULT,
+ handle->cancellable,
+ input_stream_ready_callback,
+ handle);
return handle;
}
-static void
-file_opened_callback (GnomeVFSAsyncHandle *vfs_handle,
- GnomeVFSResult result,
- gpointer callback_data)
+static void
+input_stream_ready_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GnomeGdkPixbufAsyncHandle *handle;
+ GError *error = NULL;
+ GnomeGdkPixbufAsyncHandle *handle = user_data;
- handle = callback_data;
- g_assert (handle->vfs_handle == vfs_handle);
-
- if (result != GNOME_VFS_OK) {
- load_done (handle, result, NULL);
+ handle->file_input_stream = g_file_read_finish (G_FILE (source_object),
+ res, NULL);
+ if (handle->file_input_stream == NULL) {
+ /* TODO: could map the GError more precisely to the GnomeVFSError */
+ load_done (handle, GNOME_VFS_ERROR_GENERIC, NULL);
return;
}
handle->loader = gdk_pixbuf_loader_new ();
- gnome_vfs_async_read (handle->vfs_handle,
- handle->buffer,
- sizeof (handle->buffer),
- file_read_callback,
- handle);
+ g_input_stream_read_async (G_INPUT_STREAM (handle->file_input_stream),
+ handle->buffer,
+ sizeof (handle->buffer),
+ G_PRIORITY_DEFAULT,
+ handle->cancellable,
+ input_stream_read_callback,
+ handle);
}
-static void
-file_read_callback (GnomeVFSAsyncHandle *vfs_handle,
- GnomeVFSResult result,
- gpointer buffer,
- GnomeVFSFileSize bytes_requested,
- GnomeVFSFileSize bytes_read,
- gpointer callback_data)
+static void
+input_stream_read_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GnomeGdkPixbufAsyncHandle *handle;
-
- handle = callback_data;
- g_assert (handle->vfs_handle == vfs_handle);
- g_assert (handle->buffer == buffer);
+ GnomeGdkPixbufAsyncHandle *handle = user_data;
+ gssize bytes_read;
+ GnomeVFSResult result;
- if (result == GNOME_VFS_OK && bytes_read != 0) {
+ bytes_read = g_input_stream_read_finish (G_INPUT_STREAM (source_object),
+ res, NULL);
+ if (bytes_read == -1) {
+ /* TODO: could map the GError more precisely */
+ result = GNOME_VFS_ERROR_GENERIC;
+ } else if (bytes_read > 0) {
if (!gdk_pixbuf_loader_write (handle->loader,
- buffer,
+ (const guchar *) handle->buffer,
bytes_read,
NULL)) {
result = GNOME_VFS_ERROR_WRONG_FORMAT;
+ } else {
+ /* read more */
+ g_input_stream_read_async (G_INPUT_STREAM (handle->file_input_stream),
+ handle->buffer,
+ sizeof (handle->buffer),
+ G_PRIORITY_DEFAULT,
+ handle->cancellable,
+ input_stream_read_callback,
+ handle);
+ return;
}
- gnome_vfs_async_read (handle->vfs_handle,
- handle->buffer,
- sizeof (handle->buffer),
- file_read_callback,
- handle);
- return;
+ } else {
+ /* EOF */
+ result = GNOME_VFS_OK;
}
- switch (result) {
- case GNOME_VFS_OK:
- if (bytes_read == 0) {
- GdkPixbuf *pixbuf;
-
- pixbuf = gdk_pixbuf_loader_get_pixbuf (handle->loader);
- load_done (handle, result, pixbuf);
- }
- break;
- case GNOME_VFS_ERROR_EOF:
- {
- GdkPixbuf *pixbuf;
-
- pixbuf = gdk_pixbuf_loader_get_pixbuf (handle->loader);
- load_done (handle, pixbuf ? GNOME_VFS_OK : result, pixbuf);
- }
- break;
- default:
+ if (result == GNOME_VFS_OK) {
+ GdkPixbuf *pixbuf;
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (handle->loader);
+ load_done (handle, result, pixbuf);
+ } else {
load_done (handle, result, NULL);
- break;
}
}
static void
-file_closed_callback (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer callback_data)
-{
- g_assert (callback_data == NULL);
-}
-
-static void
free_pixbuf_load_handle (GnomeGdkPixbufAsyncHandle *handle)
{
if (handle->done_callback)
@@ -363,6 +359,17 @@ free_pixbuf_load_handle (GnomeGdkPixbufA
gdk_pixbuf_loader_close (handle->loader, NULL);
g_object_unref (G_OBJECT (handle->loader));
}
+ if (handle->file_input_stream != NULL) {
+ g_input_stream_close (G_INPUT_STREAM (handle->file_input_stream), NULL, NULL);
+ g_object_unref (handle->file_input_stream);
+ }
+ if (handle->file != NULL) {
+ g_object_unref (handle->file);
+ }
+ if (handle->cancellable != NULL) {
+ g_object_unref (handle->cancellable);
+ }
+
g_free (handle);
}
@@ -371,12 +378,6 @@ load_done (GnomeGdkPixbufAsyncHandle *ha
GnomeVFSResult result,
GdkPixbuf *pixbuf)
{
- if (handle->vfs_handle != NULL) {
- if (result != GNOME_VFS_OK)
- gnome_vfs_async_cancel (handle->vfs_handle);
- else
- gnome_vfs_async_close (handle->vfs_handle, file_closed_callback, NULL);
- }
(* handle->load_callback) (handle, result, pixbuf, handle->callback_data);
free_pixbuf_load_handle (handle);
}
@@ -387,8 +388,8 @@ gnome_gdk_pixbuf_new_from_uri_cancel (Gn
if (handle == NULL) {
return;
}
- if (handle->vfs_handle != NULL) {
- gnome_vfs_async_cancel (handle->vfs_handle);
+ if (handle->cancellable != NULL) {
+ g_cancellable_cancel (handle->cancellable);
}
free_pixbuf_load_handle (handle);
}
diff -up libgnomeui-2.21.91/configure.in.gio-thumbnail libgnomeui-2.21.91/configure.in
--- libgnomeui-2.21.91/configure.in.gio-thumbnail 2008-02-11 19:36:38.000000000 -0500
+++ libgnomeui-2.21.91/configure.in 2008-02-19 12:36:06.000000000 -0500
@@ -24,6 +24,7 @@ m4_define([libbonoboui_required_version]
m4_define([gconf_required_version], [1.1.11])
m4_define([pango_required_version], [1.1.2])
m4_define([glib_required_version], [2.15.0])
+m4_define([gio_required_version], [2.15.0])
m4_define([gtk_required_version], [2.11.5])
m4_define([gnomevfs_required_version], [2.7.3])
m4_define([libglade_required_version], [2.0.0])
@@ -205,6 +206,7 @@ GNOMEUI_MODULES="dnl
gconf-2.0 >= gconf_required_version dnl
pango >= pango_required_version dnl
glib-2.0 >= glib_required_version
+ gio-2.0 >= gio_required_version
gnome-vfs-2.0 >= gnomevfs_required_version dnl
$gnome_keyring_requirement"
PKG_CHECK_MODULES(LIBGNOMEUI, [$GNOMEUI_MODULES])