summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf-loader.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2000-10-18 18:42:54 +0000
committerHavoc Pennington <hp@src.gnome.org>2000-10-18 18:42:54 +0000
commit7a4c68938789206bfec3c6d15cc4bb922daf6443 (patch)
treee5f031fc609e50a8b7b12e7d6abf63cc78cc88e7 /gdk-pixbuf/gdk-pixbuf-loader.c
parent7420908815651a1ff2ceb1c0fb5e92fe9b260619 (diff)
downloadgtk+-7a4c68938789206bfec3c6d15cc4bb922daf6443.tar.gz
Some updates
2000-10-18 Havoc Pennington <hp@redhat.com> * gtk/gtk-sections.txt: Some updates * gdk/gdk-sections.txt: remove GdkPixbufAlphaMode * gdk-pixbuf/gdk-pixbuf-sections.txt: Add new API, remove GdkPixbufClass/GdkAnimationClass since those are private * gdk-pixbuf/Makefile.am (IGNORE_HFILES): ignore more headers 2000-10-18 Havoc Pennington <hp@redhat.com> * gtk/gtktextiter.c (gtk_text_iter_forward_to_newline): Fix a bug where any number of empty lines would get skipped * gtk/gtktextiter.h: Remove padding from GtkTextIter; live on the edge. * gtk/gtktextiter.c (gtk_text_iter_make_surreal): enhance the warning about invalid iterators (explain more thoroughly) (gtk_text_iter_in_region): rename gtk_text_iter_in_range * gtk/gtktextview.c (FOCUS_EDGE_WIDTH): Make focus rectangle less big * demos/*.c: Add error handling * gtk/gtktextbuffer.c: don't modify const iterators * gtk/gdk-pixbuf-loader.c: Add full error handling here * gtk/gtkimage.c (gtk_image_set_from_file): ignore errors on file load * gtk/gtkiconfactory.c: Update to reflect addition of error handling to gdk-pixbuf loaders 2000-10-16 Havoc Pennington <hp@redhat.com> * gdk-pixbuf-io.c (gdk_pixbuf_get_module) (gdk_pixbuf_get_named_module) (gdk_pixbuf_load_module): add error reporting here also * make-inline-pixbuf.c (main): use GError * io-xpm.c: include unistd.h * gdk-pixbuf-util.c: include string.h * io-*.c: add error reporting * gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file): add error reporting * gdk-pixbuf-io.c (gdk_pixbuf_new_from_file): Add error reporting * gdk-pixbuf-io.h: Add GError** to load_increment and load methods * gdk-pixbuf-io.c (gdk_pixbuf_save) (gdk_pixbuf_savev): return a G_FILE_ERROR if we fail to write or close the file. * gdk-pixbuf.h: remove GDK_PIXBUF_ERROR_IO, instead we'll use G_FILE_ERROR_*. Rename enum to GdkPixbufError, properly following the GError naming rules. Add GError** to load functions.
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf-loader.c')
-rw-r--r--gdk-pixbuf/gdk-pixbuf-loader.c114
1 files changed, 90 insertions, 24 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c
index 5f4320f22f..42aec5d4c7 100644
--- a/gdk-pixbuf/gdk-pixbuf-loader.c
+++ b/gdk-pixbuf/gdk-pixbuf-loader.c
@@ -338,20 +338,32 @@ gdk_pixbuf_loader_animation_done (GdkPixbuf *pixbuf,
}
static gint
-gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader, const char *image_type)
+gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
+ const char *image_type,
+ GError **error)
{
GdkPixbufLoaderPrivate *priv = loader->private;
- if(image_type)
- priv->image_module = gdk_pixbuf_get_named_module (image_type);
+ if (image_type)
+ {
+ priv->image_module = gdk_pixbuf_get_named_module (image_type,
+ error);
+ }
else
- priv->image_module = gdk_pixbuf_get_module (priv->header_buf, priv->header_buf_offset);
+ {
+ g_return_val_if_fail (priv->header_buf_offset > 0, 0);
+ priv->image_module = gdk_pixbuf_get_module (priv->header_buf,
+ priv->header_buf_offset,
+ NULL,
+ error);
+ }
if (priv->image_module == NULL)
return 0;
if (priv->image_module->module == NULL)
- gdk_pixbuf_load_module (priv->image_module);
+ if (!gdk_pixbuf_load_module (priv->image_module, error))
+ return 0;
if (priv->image_module->module == NULL)
return 0;
@@ -360,8 +372,12 @@ gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader, const char *image_type)
(priv->image_module->stop_load == NULL) ||
(priv->image_module->load_increment == NULL))
{
- g_warning (G_STRLOC ": module %s does not support incremental loading.\n",
- priv->image_module->module_name);
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
+ _("Incremental loading of image type '%s' is not supported"),
+ image_type);
+
return 0;
}
@@ -369,16 +385,33 @@ gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader, const char *image_type)
gdk_pixbuf_loader_update,
gdk_pixbuf_loader_frame_done,
gdk_pixbuf_loader_animation_done,
- loader);
+ loader,
+ error);
if (priv->context == NULL)
{
- g_warning (G_STRLOC ": Failed to begin progressive load");
+ /* Defense against broken loaders; DO NOT take this as a GError
+ * example
+ */
+ if (error && *error == NULL)
+ {
+ g_warning ("Bug! loader '%s' didn't set an error on failure",
+ priv->image_module->module_name);
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_FAILED,
+ _("Internal error: Image loader module '%s'"
+ " failed to begin loading an image, but didn't"
+ " give a reason for the failure"),
+ priv->image_module->module_name);
+
+ }
+
return 0;
}
if (priv->header_buf_offset
- && priv->image_module->load_increment (priv->context, priv->header_buf, priv->header_buf_offset))
+ && priv->image_module->load_increment (priv->context, priv->header_buf, priv->header_buf_offset, error))
return priv->header_buf_offset;
return 0;
@@ -387,7 +420,8 @@ gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader, const char *image_type)
static int
gdk_pixbuf_loader_eat_header_write (GdkPixbufLoader *loader,
const guchar *buf,
- gsize count)
+ gsize count,
+ GError **error)
{
gint n_bytes;
GdkPixbufLoaderPrivate *priv = loader->private;
@@ -399,7 +433,7 @@ gdk_pixbuf_loader_eat_header_write (GdkPixbufLoader *loader,
if (priv->header_buf_offset >= LOADER_HEADER_SIZE)
{
- if (gdk_pixbuf_loader_load_module (loader, NULL) == 0)
+ if (gdk_pixbuf_loader_load_module (loader, NULL, error) == 0)
return 0;
}
@@ -411,11 +445,14 @@ gdk_pixbuf_loader_eat_header_write (GdkPixbufLoader *loader,
* @loader: A pixbuf loader.
* @buf: Pointer to image data.
* @count: Length of the @buf buffer in bytes.
+ * @error: return location for errors
*
- * This will cause a pixbuf loader to parse the next @count bytes of an image.
- * It will return TRUE if the data was loaded successfully, and FALSE if an
- * error occurred. In the latter case, the loader will be closed, and will not
- * accept further writes.
+ * This will cause a pixbuf loader to parse the next @count bytes of
+ * an image. It will return TRUE if the data was loaded successfully,
+ * and FALSE if an error occurred. In the latter case, the loader
+ * will be closed, and will not accept further writes. If FALSE is
+ * returned, @error will be set to an error from the #GDK_PIXBUF_ERROR
+ * domain.
*
* Return value: #TRUE if the write was successful, or #FALSE if the loader
* cannot parse the buffer.
@@ -423,7 +460,8 @@ gdk_pixbuf_loader_eat_header_write (GdkPixbufLoader *loader,
gboolean
gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
const guchar *buf,
- gsize count)
+ gsize count,
+ GError **error)
{
GdkPixbufLoaderPrivate *priv;
@@ -442,7 +480,7 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
{
gint eaten;
- eaten = gdk_pixbuf_loader_eat_header_write(loader, buf, count);
+ eaten = gdk_pixbuf_loader_eat_header_write(loader, buf, count, error);
if (eaten <= 0)
return FALSE;
@@ -451,8 +489,27 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
}
if (count > 0 && priv->image_module->load_increment)
- return priv->image_module->load_increment (priv->context, buf, count);
-
+ {
+ gboolean retval;
+ retval = priv->image_module->load_increment (priv->context, buf, count,
+ error);
+ if (!retval && error && *error == NULL)
+ {
+ /* Fix up busted image loader */
+ g_warning ("Bug! loader '%s' didn't set an error on failure",
+ priv->image_module->module_name);
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_FAILED,
+ _("Internal error: Image loader module '%s'"
+ " failed to begin loading an image, but didn't"
+ " give a reason for the failure"),
+ priv->image_module->module_name);
+ }
+
+ return retval;
+ }
+
return TRUE;
}
@@ -477,13 +534,22 @@ gdk_pixbuf_loader_new (void)
* Return value: A newly-created pixbuf loader.
**/
GdkPixbufLoader *
-gdk_pixbuf_loader_new_with_type (const char *image_type)
+gdk_pixbuf_loader_new_with_type (const char *image_type,
+ GError **error)
{
GdkPixbufLoader *retval;
-
+ GError *tmp;
+
retval = g_object_new (GDK_TYPE_PIXBUF_LOADER, NULL);
- gdk_pixbuf_loader_load_module(retval, image_type);
+ tmp = NULL;
+ gdk_pixbuf_loader_load_module(retval, image_type, &tmp);
+ if (tmp != NULL)
+ {
+ g_propagate_error (error, tmp);
+ g_object_unref (G_OBJECT (retval));
+ return NULL;
+ }
return retval;
}
@@ -579,7 +645,7 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader)
/* We have less the 128 bytes in the image. Flush it, and keep going. */
if (priv->image_module == NULL)
- gdk_pixbuf_loader_load_module (loader, NULL);
+ gdk_pixbuf_loader_load_module (loader, NULL, NULL);
if (priv->image_module && priv->image_module->stop_load)
priv->image_module->stop_load (priv->context);