summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf-animation.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-animation.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-animation.c')
-rw-r--r--gdk-pixbuf/gdk-pixbuf-animation.c74
1 files changed, 66 insertions, 8 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c
index 25f5d7d17a..16dc26d6c2 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.c
+++ b/gdk-pixbuf/gdk-pixbuf-animation.c
@@ -22,6 +22,7 @@
*/
#include <config.h>
+#include <errno.h>
#include "gdk-pixbuf-io.h"
#include "gdk-pixbuf-private.h"
@@ -92,10 +93,12 @@ gdk_pixbuf_animation_finalize (GObject *object)
/**
* gdk_pixbuf_animation_new_from_file:
* @filename: Name of file to load.
+ * @error: return location for error
*
* Creates a new animation by loading it from a file. The file format is
* detected automatically. If the file's format does not support multi-frame
- * images, then an animation with a single frame will be created.
+ * images, then an animation with a single frame will be created. Possible errors
+ * are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
*
* Return value: A newly created animation with a reference count of 1, or NULL
* if any of several error conditions ocurred: the file could not be opened,
@@ -103,7 +106,8 @@ gdk_pixbuf_animation_finalize (GObject *object)
* allocate the image buffer, or the image file contained invalid data.
**/
GdkPixbufAnimation *
-gdk_pixbuf_animation_new_from_file (const char *filename)
+gdk_pixbuf_animation_new_from_file (const char *filename,
+ GError **error)
{
GdkPixbufAnimation *animation;
int size;
@@ -114,25 +118,39 @@ gdk_pixbuf_animation_new_from_file (const char *filename)
g_return_val_if_fail (filename != NULL, NULL);
f = fopen (filename, "rb");
- if (!f)
+ if (!f) {
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ _("Failed to open file '%s': %s"),
+ filename, g_strerror (errno));
return NULL;
+ }
size = fread (&buffer, 1, sizeof (buffer), f);
if (size == 0) {
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+ _("Image file '%s' contains no data"),
+ filename);
+
fclose (f);
return NULL;
}
- image_module = gdk_pixbuf_get_module (buffer, size);
+ image_module = gdk_pixbuf_get_module (buffer, size, filename, error);
if (!image_module) {
- g_warning ("Unable to find handler for file: %s", filename);
fclose (f);
return NULL;
}
if (image_module->module == NULL)
- gdk_pixbuf_load_module (image_module);
+ if (!gdk_pixbuf_load_module (image_module, error)) {
+ fclose (f);
+ return NULL;
+ }
if (image_module->load_animation == NULL) {
GdkPixbuf *pixbuf;
@@ -141,14 +159,35 @@ gdk_pixbuf_animation_new_from_file (const char *filename)
/* Keep this logic in sync with gdk_pixbuf_new_from_file() */
if (image_module->load == NULL) {
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
+ _("Don't know how to load the animation in file '%s'"),
+ filename);
fclose (f);
return NULL;
}
fseek (f, 0, SEEK_SET);
- pixbuf = (* image_module->load) (f);
+ pixbuf = (* image_module->load) (f, error);
fclose (f);
+ if (pixbuf == NULL && error != NULL && *error == NULL) {
+ /* I don't trust these crufty longjmp()'ing image libs
+ * to maintain proper error invariants, and I don't
+ * want user code to segfault as a result. We need to maintain
+ * the invariant that error gets set if NULL is returned.
+ */
+
+ g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
+ image_module->module_name);
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_FAILED,
+ _("Failed to load image '%s': reason not known, probably a corrupt image file"),
+ filename);
+ }
+
if (pixbuf == NULL)
return NULL;
@@ -167,7 +206,26 @@ gdk_pixbuf_animation_new_from_file (const char *filename)
animation->height = gdk_pixbuf_get_height (pixbuf);
} else {
fseek (f, 0, SEEK_SET);
- animation = (* image_module->load_animation) (f);
+ animation = (* image_module->load_animation) (f, error);
+
+ if (animation == NULL && error != NULL && *error == NULL) {
+ /* I don't trust these crufty longjmp()'ing
+ * image libs to maintain proper error
+ * invariants, and I don't want user code to
+ * segfault as a result. We need to maintain
+ * the invariant that error gets set if NULL
+ * is returned.
+ */
+
+ g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
+ image_module->module_name);
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_FAILED,
+ _("Failed to load animation '%s': reason not known, probably a corrupt animation file"),
+ filename);
+ }
+
fclose (f);
}