]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/gdk-pixbuf-animation.c
Updated French translation.
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf-animation.c
index 863ea6e7ca5a8463685a31a24ed4a97fef363189..e45bcfcd2b4676e8bd7142031acf10710267339c 100644 (file)
@@ -28,6 +28,9 @@
 #include "gdk-pixbuf-io.h"
 #include "gdk-pixbuf-i18n.h"
 #include "gdk-pixbuf-animation.h"
+#include "gdk-pixbuf-alias.h"
+
+#include <glib/gstdio.h>
 
 typedef struct _GdkPixbufNonAnim GdkPixbufNonAnim;
 typedef struct _GdkPixbufNonAnimClass GdkPixbufNonAnimClass;
@@ -102,7 +105,7 @@ gdk_pixbuf_animation_get_type (void)
                 };
                 
                 object_type = g_type_register_static (G_TYPE_OBJECT,
-                                                      "GdkPixbufAnimation",
+                                                      g_intern_static_string ("GdkPixbufAnimation"),
                                                       &object_info, 0);
         }
   
@@ -113,7 +116,7 @@ gdk_pixbuf_animation_get_type (void)
 
 /**
  * gdk_pixbuf_animation_new_from_file:
- * @filename: Name of file to load.
+ * @filename: Name of file to load, in the GLib file name encoding
  * @error: return location for error
  *
  * Creates a new animation by loading it from a file.  The file format is
@@ -133,51 +136,51 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
        GdkPixbufAnimation *animation;
        int size;
        FILE *f;
-       guchar buffer [128];
+       guchar buffer [1024];
        GdkPixbufModule *image_module;
-        gchar *utf8_filename;
+        gchar *display_name;
+        gboolean locked = FALSE;
 
        g_return_val_if_fail (filename != NULL, NULL);
         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-       f = fopen (filename, "rb");
+        display_name = g_filename_display_name (filename);
+       f = g_fopen (filename, "rb");
        if (!f) {
-                utf8_filename = g_filename_to_utf8 (filename, -1,
-                                                    NULL, NULL, NULL);
+                gint save_errno = errno;
                 g_set_error (error,
                              G_FILE_ERROR,
-                             g_file_error_from_errno (errno),
+                             g_file_error_from_errno (save_errno),
                              _("Failed to open file '%s': %s"),
-                             utf8_filename ? utf8_filename : "???",
-                             g_strerror (errno));
-                g_free (utf8_filename);
+                             display_name,
+                             g_strerror (save_errno));
+                g_free (display_name);
                return NULL;
         }
 
        size = fread (&buffer, 1, sizeof (buffer), f);
 
        if (size == 0) {
-                utf8_filename = g_filename_to_utf8 (filename, -1,
-                                                    NULL, NULL, NULL);
                 g_set_error (error,
                              GDK_PIXBUF_ERROR,
                              GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
                              _("Image file '%s' contains no data"),
-                             utf8_filename ? utf8_filename : "???");
-                g_free (utf8_filename);
-                
+                             display_name);
+                g_free (display_name);
                fclose (f);
                return NULL;
        }
 
        image_module = _gdk_pixbuf_get_module (buffer, size, filename, error);
        if (!image_module) {
+                g_free (display_name);
                fclose (f);
                return NULL;
        }
 
        if (image_module->module == NULL)
                 if (!_gdk_pixbuf_load_module (image_module, error)) {
+                        g_free (display_name);
                         fclose (f);
                         return NULL;
                 }
@@ -200,23 +203,25 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
                         
                         g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
                                    image_module->module_name);
-                        utf8_filename = g_filename_to_utf8 (filename, -1,
-                                                            NULL, NULL, NULL);
                         g_set_error (error,
                                      GDK_PIXBUF_ERROR,
                                      GDK_PIXBUF_ERROR_FAILED,
                                      _("Failed to load image '%s': reason not known, probably a corrupt image file"),
-                                     utf8_filename ? utf8_filename : "???");
-                        g_free (utf8_filename);
+                                     display_name);
                 }
                 
-               if (pixbuf == NULL)
-                        return NULL;
+               if (pixbuf == NULL) {
+                        g_free (display_name);
+                        animation = NULL;
+                        goto out_unlock;
+                }
 
                 animation = gdk_pixbuf_non_anim_new (pixbuf);
 
                 g_object_unref (pixbuf);
        } else {
+                locked = _gdk_pixbuf_lock (image_module);
+
                fseek (f, 0, SEEK_SET);
                animation = (* image_module->load_animation) (f, error);
 
@@ -231,22 +236,48 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
                         
                         g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
                                    image_module->module_name);
-                        utf8_filename = g_filename_to_utf8 (filename, -1,
-                                                            NULL, NULL, NULL);
                         g_set_error (error,
                                      GDK_PIXBUF_ERROR,
                                      GDK_PIXBUF_ERROR_FAILED,
                                      _("Failed to load animation '%s': reason not known, probably a corrupt animation file"),
-                                     utf8_filename ? utf8_filename : "???");
-                        g_free (utf8_filename);
+                                     display_name);
                 }
                 
                fclose (f);
        }
 
+        g_free (display_name);
+
+ out_unlock:
+        if (locked)
+                _gdk_pixbuf_unlock (image_module);
        return animation;
 }
 
+#ifdef G_OS_WIN32
+
+#undef gdk_pixbuf_animation_new_from_file
+
+GdkPixbufAnimation *
+gdk_pixbuf_animation_new_from_file (const char *filename,
+                                    GError    **error)
+{
+       gchar *utf8_filename =
+               g_locale_to_utf8 (filename, -1, NULL, NULL, error);
+       GdkPixbufAnimation *retval;
+
+       if (utf8_filename == NULL)
+               return NULL;
+
+       retval = gdk_pixbuf_animation_new_from_file_utf8 (utf8_filename, error);
+
+       g_free (utf8_filename);
+
+       return retval;
+}
+
+#endif
+
 /**
  * gdk_pixbuf_animation_ref:
  * @animation: An animation.
@@ -475,9 +506,9 @@ gdk_pixbuf_animation_iter_get_delay_time (GdkPixbufAnimationIter *iter)
  * 
  * Gets the current pixbuf which should be displayed; the pixbuf will
  * be the same size as the animation itself
- * (gdk_pixbuf_animation_get_width(),
- * gdk_pixbuf_animation_get_height()). This pixbuf should be displayed
- * for gdk_pixbuf_animation_get_delay_time() milliseconds.  The caller
+ * (gdk_pixbuf_animation_get_width(), gdk_pixbuf_animation_get_height()). 
+ * This pixbuf should be displayed for 
+ * gdk_pixbuf_animation_iter_get_delay_time() milliseconds.  The caller
  * of this function does not own a reference to the returned pixbuf;
  * the returned pixbuf will become invalid when the iterator advances
  * to the next frame, which may happen anytime you call
@@ -792,3 +823,5 @@ gdk_pixbuf_non_anim_iter_advance (GdkPixbufAnimationIter *iter,
         return FALSE;
 }
 
+#define __GDK_PIXBUF_ANIMATION_C__
+#include "gdk-pixbuf-aliasdef.c"