[gdk-pixbuf] API: Add gdk_pixbuf_animation_new_from_stream_async()



commit cf8fdae73bfa959748a6fc6eec26a7d3fc6b3e2d
Author: Benjamin Otte <otte redhat com>
Date:   Wed Jan 30 03:10:36 2013 +0100

    API: Add gdk_pixbuf_animation_new_from_stream_async()

 docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt |    2 +
 gdk-pixbuf/gdk-pixbuf-animation.c                 |   82 +++++++++++++++++++++
 gdk-pixbuf/gdk-pixbuf-animation.h                 |    6 ++
 3 files changed, 90 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
index 6b41f16..a78b53b 100644
--- a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
+++ b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
@@ -130,6 +130,8 @@ GdkPixbufAnimation
 GdkPixbufAnimationIter
 gdk_pixbuf_animation_new_from_file
 gdk_pixbuf_animation_new_from_stream
+gdk_pixbuf_animation_new_from_stream_async
+gdk_pixbuf_animation_new_from_stream_finish
 gdk_pixbuf_animation_ref
 gdk_pixbuf_animation_unref
 gdk_pixbuf_animation_get_width
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c
index 60ef4a1..a7e31fa 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.c
+++ b/gdk-pixbuf/gdk-pixbuf-animation.c
@@ -395,6 +395,88 @@ gdk_pixbuf_animation_new_from_stream  (GInputStream  *stream,
         return animation;
 }
 
+static void
+animation_new_from_stream_thread (GSimpleAsyncResult *result,
+                                  GInputStream       *stream,
+                                  GCancellable       *cancellable)
+{
+	GdkPixbufAnimation *animation;
+	GError *error = NULL;
+
+	animation = gdk_pixbuf_animation_new_from_stream (stream, cancellable, &error);
+
+	/* Set the new pixbuf as the result, or error out */
+	if (animation == NULL) {
+		g_simple_async_result_take_error (result, error);
+	} else {
+		g_simple_async_result_set_op_res_gpointer (result, g_object_ref (animation), g_object_unref);
+	}
+}
+
+/**
+ * gdk_pixbuf_animation_new_from_stream_async:
+ * @stream: a #GInputStream from which to load the animation
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
+ * @callback: a #GAsyncReadyCallback to call when the the pixbuf is loaded
+ * @user_data: the data to pass to the callback function
+ *
+ * Creates a new animation by asynchronously loading an image from an input stream.
+ *
+ * For more details see gdk_pixbuf_new_from_stream(), which is the synchronous
+ * version of this function.
+ *
+ * When the operation is finished, @callback will be called in the main thread.
+ * You can then call gdk_pixbuf_animation_new_from_stream_finish() to get the
+ * result of the operation.
+ *
+ * Since: 2.28
+ **/
+void
+gdk_pixbuf_animation_new_from_stream_async (GInputStream        *stream,
+                                            GCancellable        *cancellable,
+                                            GAsyncReadyCallback  callback,
+                                            gpointer             user_data)
+{
+	GSimpleAsyncResult *result;
+
+	g_return_if_fail (G_IS_INPUT_STREAM (stream));
+	g_return_if_fail (callback != NULL);
+	g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+	result = g_simple_async_result_new (G_OBJECT (stream), callback, user_data, gdk_pixbuf_animation_new_from_stream_async);
+	g_simple_async_result_run_in_thread (result, (GSimpleAsyncThreadFunc) animation_new_from_stream_thread, G_PRIORITY_DEFAULT, cancellable);
+	g_object_unref (result);
+}
+
+/**
+ * gdk_pixbuf_animation_new_from_stream_finish:
+ * @async_result: a #GAsyncResult
+ * @error: a #GError, or %NULL
+ *
+ * Finishes an asynchronous pixbuf animation creation operation started with
+ * gdk_pixbuf_animation_new_from_stream_async().
+ *
+ * Return value: a #GdkPixbufAnimation or %NULL on error. Free the returned
+ * object with g_object_unref().
+ *
+ * Since: 2.24
+ **/
+GdkPixbufAnimation *
+gdk_pixbuf_animation_new_from_stream_finish (GAsyncResult  *async_result,
+			              	     GError       **error)
+{
+	GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (async_result);
+
+	g_return_val_if_fail (G_IS_ASYNC_RESULT (async_result), NULL);
+	g_return_val_if_fail (!error || (error && !*error), NULL);
+	g_warn_if_fail (g_simple_async_result_get_source_tag (result) == gdk_pixbuf_animation_new_from_stream_async);
+
+	if (g_simple_async_result_propagate_error (result, error))
+		return NULL;
+
+	return g_simple_async_result_get_op_res_gpointer (result);
+}
+
 /**
  * gdk_pixbuf_animation_ref: (skip)
  * @animation: An animation.
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.h b/gdk-pixbuf/gdk-pixbuf-animation.h
index 38dfc02..63d476e 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.h
+++ b/gdk-pixbuf/gdk-pixbuf-animation.h
@@ -75,6 +75,12 @@ GdkPixbufAnimation *gdk_pixbuf_animation_new_from_file   (const char         *fi
 GdkPixbufAnimation *gdk_pixbuf_animation_new_from_stream (GInputStream       *stream,
                                                           GCancellable       *cancellable,
                                                           GError            **error);
+void                gdk_pixbuf_animation_new_from_stream_async (GInputStream *stream,
+                                                          GCancellable       *cancellable,
+                                                          GAsyncReadyCallback callback,
+                                                          gpointer            user_data);
+GdkPixbufAnimation *gdk_pixbuf_animation_new_from_stream_finish (GAsyncResult*async_result,
+                                                          GError            **error);
 
 #ifndef GDK_PIXBUF_DISABLE_DEPRECATED
 G_DEPRECATED_FOR(g_object_ref)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]