]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/gdk-pixbuf-animation.c
Updated Slovenian translation
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf-animation.c
index 0d7df857938da27b509aaf16e8e026d7a0cd3773..290630ef0cfa759e176f9b7de824260329be5453 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
+#include "config.h"
 #include <errno.h>
-#include "gdk-pixbuf-io.h"
 #include "gdk-pixbuf-private.h"
+#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;
@@ -50,9 +55,6 @@ struct _GdkPixbufNonAnimClass {
         
 };
 
-static GType gdk_pixbuf_non_anim_get_type (void) G_GNUC_CONST;
-
-\f
 
 typedef struct _GdkPixbufNonAnimIter GdkPixbufNonAnimIter;
 typedef struct _GdkPixbufNonAnimIterClass GdkPixbufNonAnimIterClass;
@@ -79,39 +81,21 @@ struct _GdkPixbufNonAnimIterClass {
 
 static GType gdk_pixbuf_non_anim_iter_get_type (void) G_GNUC_CONST;
 
-\f
-
-GType
-gdk_pixbuf_animation_get_type (void)
-{
-        static GType object_type = 0;
-
-        if (!object_type) {
-                static const GTypeInfo object_info = {
-                        sizeof (GdkPixbufAnimationClass),
-                        (GBaseInitFunc) NULL,
-                        (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) NULL,
-                        NULL,           /* class_finalize */
-                        NULL,           /* class_data */
-                        sizeof (GdkPixbufAnimation),
-                        0,              /* n_preallocs */
-                        (GInstanceInitFunc) NULL,
-                };
-                
-                object_type = g_type_register_static (G_TYPE_OBJECT,
-                                                      "GdkPixbufAnimation",
-                                                      &object_info, 0);
-        }
-  
-        return object_type;
+G_DEFINE_TYPE (GdkPixbufAnimation, gdk_pixbuf_animation, G_TYPE_OBJECT);
+
+static void
+gdk_pixbuf_animation_class_init (GdkPixbufAnimationClass *klass)
+{
 }
 
-\f
+static void
+gdk_pixbuf_animation_init (GdkPixbufAnimation *animation)
+{
+}
 
 /**
  * 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
@@ -131,18 +115,25 @@ 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 *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) {
+                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"),
-                             filename, g_strerror (errno));
+                             display_name,
+                             g_strerror (save_errno));
+                g_free (display_name);
                return NULL;
         }
 
@@ -153,20 +144,22 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
                              GDK_PIXBUF_ERROR,
                              GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
                              _("Image file '%s' contains no data"),
-                             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;
                 }
@@ -176,18 +169,8 @@ 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, error);
+               pixbuf = _gdk_pixbuf_generic_image_load (image_module, f, error);
                fclose (f);
 
                 if (pixbuf == NULL && error != NULL && *error == NULL) {
@@ -203,16 +186,21 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
                                      GDK_PIXBUF_ERROR,
                                      GDK_PIXBUF_ERROR_FAILED,
                                      _("Failed to load image '%s': reason not known, probably a corrupt image file"),
-                                     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,41 +219,72 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
                                      GDK_PIXBUF_ERROR,
                                      GDK_PIXBUF_ERROR_FAILED,
                                      _("Failed to load animation '%s': reason not known, probably a corrupt animation file"),
-                                     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.
  *
- * Adds a reference to an animation. Deprecated; use
- * g_object_ref(). The reference must be released afterwards using
- * g_object_unref().
+ * Adds a reference to an animation. 
  *
  * Return value: The same as the @animation argument.
+ *
+ * Deprecated: Use g_object_ref(). 
  **/
 GdkPixbufAnimation *
 gdk_pixbuf_animation_ref (GdkPixbufAnimation *animation)
 {
-        return (GdkPixbufAnimation*) g_object_ref (G_OBJECT (animation));
+        return (GdkPixbufAnimation*) g_object_ref (animation);
 }
 
 /**
  * gdk_pixbuf_animation_unref:
  * @animation: An animation.
  * 
- * Removes a reference from an animation. Deprecated; use g_object_unref().
+ * Removes a reference from an animation. 
+ *
+ * Deprecated: Use g_object_unref().
  **/
 void
 gdk_pixbuf_animation_unref (GdkPixbufAnimation *animation)
 {
-        g_object_unref (G_OBJECT (animation));
+        g_object_unref (animation);
 }
 
 /**
@@ -413,38 +432,22 @@ gdk_pixbuf_animation_get_iter (GdkPixbufAnimation *animation,
         return GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_iter (animation, &val);
 }
 
-\f
+G_DEFINE_TYPE (GdkPixbufAnimationIter, gdk_pixbuf_animation_iter, G_TYPE_OBJECT);
 
-GType
-gdk_pixbuf_animation_iter_get_type (void)
+static void
+gdk_pixbuf_animation_iter_class_init (GdkPixbufAnimationIterClass *klass)
 {
-        static GType object_type = 0;
+}
 
-        if (!object_type) {
-                static const GTypeInfo object_info = {
-                        sizeof (GdkPixbufAnimationIterClass),
-                        (GBaseInitFunc) NULL,
-                        (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) NULL,
-                        NULL,           /* class_finalize */
-                        NULL,           /* class_data */
-                        sizeof (GdkPixbufAnimationIter),
-                        0,              /* n_preallocs */
-                        (GInstanceInitFunc) NULL,
-                };
-                
-                object_type = g_type_register_static (G_TYPE_OBJECT,
-                                                      "GdkPixbufAnimationIter",
-                                                      &object_info, 0);
-        }
-  
-        return object_type;
+static void
+gdk_pixbuf_animation_iter_init (GdkPixbufAnimationIter *iter)
+{
 }
 
 /**
  * gdk_pixbuf_animation_iter_get_delay_time:
  * @iter: an animation iterator
- * 
+ *
  * Gets the number of milliseconds the current pixbuf should be displayed,
  * or -1 if the current pixbuf should be displayed forever. g_timeout_add()
  * conveniently takes a timeout in milliseconds, so you can use a timeout
@@ -456,7 +459,8 @@ int
 gdk_pixbuf_animation_iter_get_delay_time (GdkPixbufAnimationIter *iter)
 {
         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), -1);
-  
+        g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_delay_time, -1);
+
         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_delay_time (iter);
 }
 
@@ -466,9 +470,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
@@ -482,7 +486,8 @@ GdkPixbuf*
 gdk_pixbuf_animation_iter_get_pixbuf (GdkPixbufAnimationIter *iter)
 {
         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), NULL);
-  
+        g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_pixbuf, NULL);
+
         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_pixbuf (iter);
 }
 
@@ -495,14 +500,15 @@ gdk_pixbuf_animation_iter_get_pixbuf (GdkPixbufAnimationIter *iter)
  * for an area of the frame currently streaming in to the loader. So if
  * you're on the currently loading frame, you need to redraw the screen for
  * the updated area.
- * 
+ *
  * Return value: %TRUE if the frame we're on is partially loaded, or the last frame
  **/
 gboolean
 gdk_pixbuf_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter)
 {
         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), FALSE);
-        
+        g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->on_currently_loading_frame, FALSE);
+
         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->on_currently_loading_frame (iter);
 }
 
@@ -513,7 +519,7 @@ gdk_pixbuf_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *it
  *
  * Possibly advances an animation to a new frame. Chooses the frame based
  * on the start time passed to gdk_pixbuf_animation_get_iter().
- * 
+ *
  * @current_time would normally come from g_get_current_time(), and
  * must be greater than or equal to the time passed to
  * gdk_pixbuf_animation_get_iter(), and must increase or remain
@@ -539,22 +545,19 @@ gdk_pixbuf_animation_iter_advance (GdkPixbufAnimationIter *iter,
                                    const GTimeVal         *current_time)
 {
         GTimeVal val;
-        
+
         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), FALSE);
+        g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->advance, FALSE);
 
         if (current_time)
                 val = *current_time;
         else
                 g_get_current_time (&val);
-        
+
         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->advance (iter, &val);
 }
 
-\f
-
-static void gdk_pixbuf_non_anim_class_init (GdkPixbufNonAnimClass *klass);
-static void gdk_pixbuf_non_anim_finalize   (GObject        *object);
-
+static void                    gdk_pixbuf_non_anim_finalize         (GObject            *object);
 static gboolean                gdk_pixbuf_non_anim_is_static_image  (GdkPixbufAnimation *animation);
 static GdkPixbuf*              gdk_pixbuf_non_anim_get_static_image (GdkPixbufAnimation *animation);
 static void                    gdk_pixbuf_non_anim_get_size         (GdkPixbufAnimation *anim,
@@ -563,37 +566,7 @@ static void                    gdk_pixbuf_non_anim_get_size         (GdkPixbufAn
 static GdkPixbufAnimationIter* gdk_pixbuf_non_anim_get_iter         (GdkPixbufAnimation *anim,
                                                                      const GTimeVal     *start_time);
 
-
-
-\f
-
-static gpointer non_parent_class;
-
-GType
-gdk_pixbuf_non_anim_get_type (void)
-{
-        static GType object_type = 0;
-
-        if (!object_type) {
-                static const GTypeInfo object_info = {
-                        sizeof (GdkPixbufNonAnimClass),
-                        (GBaseInitFunc) NULL,
-                        (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) gdk_pixbuf_non_anim_class_init,
-                        NULL,           /* class_finalize */
-                        NULL,           /* class_data */
-                        sizeof (GdkPixbufNonAnim),
-                        0,              /* n_preallocs */
-                        (GInstanceInitFunc) NULL,
-                };
-                
-                object_type = g_type_register_static (GDK_TYPE_PIXBUF_ANIMATION,
-                                                      "GdkPixbufNonAnim",
-                                                      &object_info, 0);
-        }
-        
-        return object_type;
-}
+G_DEFINE_TYPE (GdkPixbufNonAnim, gdk_pixbuf_non_anim, GDK_TYPE_PIXBUF_ANIMATION);
 
 static void
 gdk_pixbuf_non_anim_class_init (GdkPixbufNonAnimClass *klass)
@@ -601,8 +574,6 @@ gdk_pixbuf_non_anim_class_init (GdkPixbufNonAnimClass *klass)
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
         GdkPixbufAnimationClass *anim_class = GDK_PIXBUF_ANIMATION_CLASS (klass);
         
-        non_parent_class = g_type_class_peek_parent (klass);
-        
         object_class->finalize = gdk_pixbuf_non_anim_finalize;
 
         anim_class->is_static_image = gdk_pixbuf_non_anim_is_static_image;
@@ -611,6 +582,11 @@ gdk_pixbuf_non_anim_class_init (GdkPixbufNonAnimClass *klass)
         anim_class->get_iter = gdk_pixbuf_non_anim_get_iter;
 }
 
+static void
+gdk_pixbuf_non_anim_init (GdkPixbufNonAnim *non_anim)
+{
+}
+
 static void
 gdk_pixbuf_non_anim_finalize (GObject *object)
 {
@@ -619,7 +595,7 @@ gdk_pixbuf_non_anim_finalize (GObject *object)
         if (non_anim->pixbuf)
                 g_object_unref (non_anim->pixbuf);
         
-        G_OBJECT_CLASS (non_parent_class)->finalize (object);
+        G_OBJECT_CLASS (gdk_pixbuf_non_anim_parent_class)->finalize (object);
 }
 
 GdkPixbufAnimation*
@@ -670,7 +646,6 @@ gdk_pixbuf_non_anim_get_size (GdkPixbufAnimation *anim,
                 *height = gdk_pixbuf_get_height (non_anim->pixbuf);
 }
 
-
 static GdkPixbufAnimationIter*
 gdk_pixbuf_non_anim_get_iter (GdkPixbufAnimation *anim,
                               const GTimeVal     *start_time)
@@ -686,47 +661,16 @@ gdk_pixbuf_non_anim_get_iter (GdkPixbufAnimation *anim,
         return GDK_PIXBUF_ANIMATION_ITER (iter);
 }
 
-\f
-
-static void gdk_pixbuf_non_anim_iter_class_init (GdkPixbufNonAnimIterClass *klass);
-static void gdk_pixbuf_non_anim_iter_finalize   (GObject                   *object);
+static void       gdk_pixbuf_non_anim_iter_finalize                   (GObject                *object);
 static int        gdk_pixbuf_non_anim_iter_get_delay_time             (GdkPixbufAnimationIter *iter);
 static GdkPixbuf* gdk_pixbuf_non_anim_iter_get_pixbuf                 (GdkPixbufAnimationIter *iter);
 static gboolean   gdk_pixbuf_non_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter);
 static gboolean   gdk_pixbuf_non_anim_iter_advance                    (GdkPixbufAnimationIter *iter,
                                                                        const GTimeVal         *current_time);
 
-
-
-\f
-
-static gpointer non_iter_parent_class;
-
-GType
-gdk_pixbuf_non_anim_iter_get_type (void)
-{
-        static GType object_type = 0;
-
-        if (!object_type) {
-                static const GTypeInfo object_info = {
-                        sizeof (GdkPixbufNonAnimIterClass),
-                        (GBaseInitFunc) NULL,
-                        (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) gdk_pixbuf_non_anim_iter_class_init,
-                        NULL,           /* class_finalize */
-                        NULL,           /* class_data */
-                        sizeof (GdkPixbufNonAnimIter),
-                        0,              /* n_preallocs */
-                        (GInstanceInitFunc) NULL,
-                };
-                
-                object_type = g_type_register_static (GDK_TYPE_PIXBUF_ANIMATION_ITER,
-                                                      "GdkPixbufNonAnimIter",
-                                                      &object_info, 0);
-        }
-        
-        return object_type;
-}
+G_DEFINE_TYPE (GdkPixbufNonAnimIter,
+               gdk_pixbuf_non_anim_iter,
+               GDK_TYPE_PIXBUF_ANIMATION_ITER);
 
 static void
 gdk_pixbuf_non_anim_iter_class_init (GdkPixbufNonAnimIterClass *klass)
@@ -735,8 +679,6 @@ gdk_pixbuf_non_anim_iter_class_init (GdkPixbufNonAnimIterClass *klass)
         GdkPixbufAnimationIterClass *anim_iter_class =
                 GDK_PIXBUF_ANIMATION_ITER_CLASS (klass);
         
-        non_iter_parent_class = g_type_class_peek_parent (klass);
-        
         object_class->finalize = gdk_pixbuf_non_anim_iter_finalize;
 
         anim_iter_class->get_delay_time = gdk_pixbuf_non_anim_iter_get_delay_time;
@@ -745,6 +687,11 @@ gdk_pixbuf_non_anim_iter_class_init (GdkPixbufNonAnimIterClass *klass)
         anim_iter_class->advance = gdk_pixbuf_non_anim_iter_advance;
 }
 
+static void
+gdk_pixbuf_non_anim_iter_init (GdkPixbufNonAnimIter *non_iter)
+{
+}
+
 static void
 gdk_pixbuf_non_anim_iter_finalize (GObject *object)
 {
@@ -752,7 +699,7 @@ gdk_pixbuf_non_anim_iter_finalize (GObject *object)
 
         g_object_unref (iter->non_anim);
         
-        G_OBJECT_CLASS (non_iter_parent_class)->finalize (object);
+        G_OBJECT_CLASS (gdk_pixbuf_non_anim_iter_parent_class)->finalize (object);
 }
 
 static int
@@ -783,3 +730,5 @@ gdk_pixbuf_non_anim_iter_advance (GdkPixbufAnimationIter *iter,
         return FALSE;
 }
 
+#define __GDK_PIXBUF_ANIMATION_C__
+#include "gdk-pixbuf-aliasdef.c"