[totem] youtube: Use new gdk-pixbuf APIs



commit 38d0cd416a0c7df01619b5c8bfd289b56929c883
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Dec 13 12:30:48 2010 +0000

    youtube: Use new gdk-pixbuf APIs
    
    Instead of the copy/paste version we had so far.

 configure.in                        |    2 +-
 src/plugins/youtube/totem-youtube.c |  155 +----------------------------------
 2 files changed, 3 insertions(+), 154 deletions(-)
---
diff --git a/configure.in b/configure.in
index 1c28b6e..795a1fc 100644
--- a/configure.in
+++ b/configure.in
@@ -480,7 +480,7 @@ for plugin in ${used_plugins}; do
 			fi
 		;;
 		youtube)
-			PKG_CHECK_MODULES(LIBGDATA, libgdata >= 0.4.0,
+			PKG_CHECK_MODULES(LIBGDATA, libgdata >= 0.4.0 gdk-pixbuf-2.0 >= 2.23.0,
 				[HAVE_LIBGDATA=yes], [HAVE_LIBGDATA=no])
 			if test "${HAVE_LIBGDATA}" != "yes" ; then
 				plugin_error_or_ignore "you need libgdata >= 0.4.0 installed for the YouTube plugin"
diff --git a/src/plugins/youtube/totem-youtube.c b/src/plugins/youtube/totem-youtube.c
index cb5edd5..b3a55fc 100644
--- a/src/plugins/youtube/totem-youtube.c
+++ b/src/plugins/youtube/totem-youtube.c
@@ -100,157 +100,6 @@ void open_in_web_browser_activate_cb (GtkAction *action, TotemYouTubePlugin *sel
 void value_changed_cb (GtkAdjustment *adjustment, TotemYouTubePlugin *self);
 gboolean starting_video_cb (TotemVideoList *video_list, GtkTreePath *path, TotemYouTubePlugin *self);
 
-/* ----------------------------------------------------------------------------------------------------------------- */
-/* Copied from http://bugzilla.gnome.org/show_bug.cgi?id=575900 while waiting for them to be committed to gdk-pixbuf */
-
-typedef struct {
-	gint width;
-	gint height;
-	gboolean preserve_aspect_ratio;
-} AtScaleData;
-
-static void
-new_from_stream_thread (GSimpleAsyncResult *result,
-                        GInputStream       *stream,
-                        GCancellable       *cancellable)
-{
-	GdkPixbuf *pixbuf;
-	AtScaleData *data;
-	GError *error = NULL;
-
-	/* If data != NULL, we're scaling the pixbuf while loading it */
-	data = g_simple_async_result_get_op_res_gpointer (result);
-	if (data != NULL)
-		pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, data->width, data->height, data->preserve_aspect_ratio, cancellable, &error);
-	else
-		pixbuf = gdk_pixbuf_new_from_stream (stream, cancellable, &error);
-
-	g_simple_async_result_set_op_res_gpointer (result, NULL, NULL);
-
-	/* Set the new pixbuf as the result, or error out */
-	if (pixbuf == NULL) {
-		g_simple_async_result_set_from_error (result, error);
-		g_error_free (error);
-	} else {
-		g_simple_async_result_set_op_res_gpointer (result, pixbuf, g_object_unref);
-	}
-}
-
- /**
- * gdk_pixbuf_new_from_stream_at_scale_async:
- * @stream: a #GInputStream from which to load the pixbuf
- * @width: the width the image should have or -1 to not constrain the width
- * @height: the height the image should have or -1 to not constrain the height
- * @preserve_aspect_ratio: %TRUE to preserve the image's aspect ratio
- * @cancellable: 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 pixbuf by asynchronously loading an image from an input stream.
- *
- * For more details see gdk_pixbuf_new_from_stream_at_scale(), 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_new_from_stream_finish() to get the result of the operation.
- *
- * Since: 2.18
- **/
-static void
-totem_gdk_pixbuf_new_from_stream_at_scale_async (GInputStream        *stream,
-                                                 gint                 width,
-                                                 gint                 height,
-                                                 gboolean             preserve_aspect_ratio,
-                                                 GCancellable        *cancellable,
-                                                 GAsyncReadyCallback  callback,
-                                                 gpointer             user_data)
-{
-	GSimpleAsyncResult *result;
-	AtScaleData *data;
-
-	g_return_if_fail (G_IS_INPUT_STREAM (stream));
-	g_return_if_fail (callback != NULL);
-
-	data = g_new (AtScaleData, 1);
-	data->width = width;
-	data->height = height;
-	data->preserve_aspect_ratio = preserve_aspect_ratio;
-
-	result = g_simple_async_result_new (G_OBJECT (stream), callback, user_data, totem_gdk_pixbuf_new_from_stream_at_scale_async);
-	g_simple_async_result_set_op_res_gpointer (result, data, (GDestroyNotify) g_free);
-	g_simple_async_result_run_in_thread (result, (GSimpleAsyncThreadFunc) new_from_stream_thread, G_PRIORITY_DEFAULT, cancellable);
-	g_object_unref (result);
-}
-
-/**
- * gdk_pixbuf_new_from_stream_async:
- * @stream: a #GInputStream from which to load the pixbuf
- * @cancellable: 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 pixbuf 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_new_from_stream_finish() to get the result of the operation.
- *
- * Since: 2.18
- **/
-static void
-totem_gdk_pixbuf_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);
-
-	result = g_simple_async_result_new (G_OBJECT (stream), callback, user_data, totem_gdk_pixbuf_new_from_stream_async);
-	g_simple_async_result_run_in_thread (result, (GSimpleAsyncThreadFunc) new_from_stream_thread, G_PRIORITY_DEFAULT, cancellable);
-	g_object_unref (result);
-}
-
-/**
- * gdk_pixbuf_new_from_stream_finish:
- * @async_result: a #GAsyncResult
- * @error: a #GError, or %NULL
- *
- * Finishes an asynchronous pixbuf creation operation started with
- * gdk_pixbuf_new_from_stream_async().
- *
- * Return value: a #GdkPixbuf or %NULL on error. Free the returned
- * object with g_object_unref().
- *
- * Since: 2.18
- **/
-static GdkPixbuf *
-totem_gdk_pixbuf_new_from_stream_finish (GAsyncResult  *async_result,
-                                         GError       **error)
-{
-	GdkPixbuf *pixbuf;
-	GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (async_result);
-
-	g_return_val_if_fail (G_IS_ASYNC_RESULT (async_result), NULL);
-	g_warn_if_fail (g_simple_async_result_get_source_tag (result) == totem_gdk_pixbuf_new_from_stream_async ||
-	                g_simple_async_result_get_source_tag (result) == totem_gdk_pixbuf_new_from_stream_at_scale_async);
-
-	if (g_simple_async_result_propagate_error (result, error))
-		return NULL;
-
-	pixbuf = GDK_PIXBUF (g_simple_async_result_get_op_res_gpointer (result));
-	if (pixbuf != NULL)
-		return g_object_ref (pixbuf);
-
-	return NULL;
-}
-
-/* ----------------------------------------------------------------------------------------------------------------- */
-
 static void
 set_up_tree_view (TotemYouTubePlugin *self, GtkBuilder *builder, guint key)
 {
@@ -651,7 +500,7 @@ thumbnail_loaded_cb (GObject *source_object, GAsyncResult *result, ThumbnailData
 	TotemYouTubePlugin *self = data->plugin;
 
 	/* Finish loading the thumbnail */
-	thumbnail = totem_gdk_pixbuf_new_from_stream_finish (result, &error);
+	thumbnail = gdk_pixbuf_new_from_stream_finish (result, &error);
 
 	if (thumbnail == NULL) {
 		/* Bail out if the operation was cancelled */
@@ -707,7 +556,7 @@ thumbnail_opened_cb (GObject *source_object, GAsyncResult *result, ThumbnailData
 	/* NOTE: There's no need to reset the cancellable before using it again, as we'll have bailed before now if it was ever cancelled. */
 
 	g_debug ("Creating thumbnail from stream");
-	totem_gdk_pixbuf_new_from_stream_at_scale_async (G_INPUT_STREAM (input_stream), THUMBNAIL_WIDTH, -1, TRUE,
+	gdk_pixbuf_new_from_stream_at_scale_async (G_INPUT_STREAM (input_stream), THUMBNAIL_WIDTH, -1, TRUE,
 	                                                 data->cancellable, (GAsyncReadyCallback) thumbnail_loaded_cb, data);
 	g_object_unref (input_stream);
 }



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