[maemo-commits] [maemo-commits] r16545 - in projects/haf/trunk/hildon-thumbnail: . thumbs
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Fri Oct 31 16:26:09 EET 2008
- Previous message: [maemo-commits] r16544 - in projects/haf/trunk/hildon-thumbnail: . thumbs
- Next message: [maemo-commits] r16546 - projects/haf/trunk/hildon-thumbnail/thumbs
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2008-10-31 16:26:07 +0200 (Fri, 31 Oct 2008) New Revision: 16545 Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog projects/haf/trunk/hildon-thumbnail/thumbs/hildon-albumart-obj.c projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.h projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c Log: 2008-10-31 Philip Van Hoof <philip at codeminded.be> * thumbs/hildon-thumbnail-obj.c * thumbs/hildon-thumbnail-factory.h * thumbs/hildon-albumart-obj.c: New API, improvements Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog =================================================================== --- projects/haf/trunk/hildon-thumbnail/ChangeLog 2008-10-31 13:51:13 UTC (rev 16544) +++ projects/haf/trunk/hildon-thumbnail/ChangeLog 2008-10-31 14:26:07 UTC (rev 16545) @@ -1,5 +1,11 @@ 2008-10-31 Philip Van Hoof <philip at codeminded.be> + * thumbs/hildon-thumbnail-obj.c + * thumbs/hildon-thumbnail-factory.h + * thumbs/hildon-albumart-obj.c: New API, improvements + +2008-10-31 Philip Van Hoof <philip at codeminded.be> + * thumbs/hildon-thumbnail-factory.c * thumbs/hildon-thumbnail-factory.h: Error reporting and added to convenience APIs Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-albumart-obj.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-albumart-obj.c 2008-10-31 13:51:13 UTC (rev 16544) +++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-albumart-obj.c 2008-10-31 14:26:07 UTC (rev 16545) @@ -77,14 +77,20 @@ gchar *path; GError *error = NULL; - filei = g_file_new_for_path (path); - stream = G_INPUT_STREAM (g_file_read (filei, NULL, &error)); + hildon_thumbnail_util_get_albumart_path (r_priv->artist_or_title, + r_priv->album, r_priv->kind, + &path); - if (error) - goto error_handler; + if (r_priv->callback) { + filei = g_file_new_for_path (path); + stream = G_INPUT_STREAM (g_file_read (filei, NULL, &error)); - pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error); + if (error) + goto error_handler; + pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error); + } + error_handler: /* Callback user function, passing the pixbuf and error */ @@ -92,9 +98,6 @@ if (r_priv->callback) r_priv->callback (r_priv->factory, pixbuf, error, r_priv->user_data); - if (r_priv->destroy) - r_priv->destroy (r_priv->destroy); - /* Cleanup */ if (filei) @@ -110,6 +113,12 @@ if (pixbuf) gdk_pixbuf_unref (pixbuf); + + g_free (path); + + if (r_priv->destroy) + r_priv->destroy (r_priv->user_data); + } Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.h =================================================================== --- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.h 2008-10-31 13:51:13 UTC (rev 16544) +++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.h 2008-10-31 14:26:07 UTC (rev 16545) @@ -70,7 +70,7 @@ GType hildon_thumbnail_request_get_type (void); /** - * HildonThumbnailRequestCallback: + * HildonThumbnailRequestPixbufCallback: * @self: the factory * @thumbnail: (allow-none): A pixbuf containing the thumbnail or %NULL. If application wishes to keep the structure, it must call g_object_ref() on it. The library does not cache returned pixbufs. * @error: (allow-none): The error or %NULL if there was none. Freed after callback returns. @@ -78,9 +78,22 @@ * * Called when the thumbnailing process finishes or there is an error **/ -typedef void (*HildonThumbnailRequestCallback) (HildonThumbnailFactory *self, +typedef void (*HildonThumbnailRequestPixbufCallback) (HildonThumbnailFactory *self, GdkPixbuf *thumbnail, GError *error, gpointer user_data); + +/** + * HildonThumbnailRequestUriCallback: + * @self: the factory + * @thumbnail: (allow-none): A URI containing the best fit thumbnail or %NULL. + * @error: (allow-none): The error or %NULL if there was none. Freed after callback returns. + * @user_data: (allow-none): User-supplied data when thumbnail was requested + * + * Called when the thumbnailing process finishes or there is an error + **/ +typedef void (*HildonThumbnailRequestUriCallback) (HildonThumbnailFactory *self, + const gchar *thumbnail, GError *error, gpointer user_data); + /** * hildon_thumbnail_factory_get_instance: * @@ -92,7 +105,7 @@ HildonThumbnailFactory* hildon_thumbnail_factory_get_instance (void); /** - * hildon_thumbnail_factory_request: + * hildon_thumbnail_factory_request_pixbuf: * @self: the factory * @uri: an URI to the file which you want to request a thumbnail for * @width: Wanted width of the thumbnail @@ -111,16 +124,45 @@ * Returns: (transfer full): A handle for the request that got created on a queue **/ HildonThumbnailRequest* - hildon_thumbnail_factory_request (HildonThumbnailFactory *self, + hildon_thumbnail_factory_request_pixbuf (HildonThumbnailFactory *self, const gchar *uri, guint width, guint height, gboolean cropped, const gchar *mime_type, - HildonThumbnailRequestCallback callback, + HildonThumbnailRequestPixbufCallback callback, gpointer user_data, GDestroyNotify destroy); + /** + * hildon_thumbnail_factory_request_uri: + * @self: the factory + * @uri: an URI to the file which you want to request a thumbnail for + * @width: Wanted width of the thumbnail + * @height: Wanted height of the thumbnail + * @mime_type: (allow-none): A MIME type hint for @uri + * @callback: (allow-none): A callback that will be executed when the thumbnail is ready + * @user_data: (allow-none): User-supplied data for @callback and @destroy + * @destroy: (allow-none): a #GDestroyNotify to destroy @user_data as soon as @callback has ran + * + * Request the preparation, if needed, of a thumbnail and return it in @callback + * as a #GdkPixbuf as soon as it's ready. This operation is asynchronous, the + * creation of the thumbnail will not affect your running mainloop unless you + * use one of the join methods on either #HildonThumbnailFactory or the + * #HildonThumbnailRequest being returned. + * + * Returns: (transfer full): A handle for the request that got created on a queue + **/ +HildonThumbnailRequest* + hildon_thumbnail_factory_request_uri (HildonThumbnailFactory *self, + const gchar *uri, + guint width, guint height, + gboolean cropped, + const gchar *mime_type, + HildonThumbnailRequestUriCallback callback, + gpointer user_data, + GDestroyNotify destroy); +/** * hildon_thumbnail_factory_join: * @self: the factory * Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c 2008-10-31 13:51:13 UTC (rev 16544) +++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c 2008-10-31 14:26:07 UTC (rev 16545) @@ -45,10 +45,12 @@ gchar *lpaths[3]; guint width, height; gboolean cropped; - HildonThumbnailRequestCallback callback; + HildonThumbnailRequestPixbufCallback pcallback; + HildonThumbnailRequestUriCallback ucallback; GDestroyNotify destroy; HildonThumbnailFactory *factory; gpointer user_data; + GString *errors; } HildonThumbnailRequestPrivate; typedef struct { @@ -75,6 +77,8 @@ GError **error); #endif +#define HILDON_THUMBNAIL_APPLICATION "hildon-thumbnail" +#define FACTORY_ERROR g_quark_from_static_string (HILDON_THUMBNAIL_APPLICATION) static void create_pixbuf_and_callback (HildonThumbnailRequestPrivate *r_priv) @@ -112,41 +116,69 @@ } } - stream = G_INPUT_STREAM (g_file_read (filei, NULL, &error)); - if (error) - goto error_handler; + if (r_priv->pcallback) { - /* Read the stream as a pixbuf at the requested exact scale */ - pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, - r_priv->width, r_priv->height, TRUE, - NULL, &error); + stream = G_INPUT_STREAM (g_file_read (filei, NULL, &error)); - error_handler: + if (!error) { + /* Read the stream as a pixbuf at the requested exact scale */ + pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, + r_priv->width, r_priv->height, TRUE, + NULL, &error); + } - /* Callback user function, passing the pixbuf and error */ + /* Callback user function, passing the pixbuf and error */ - if (r_priv->callback) - r_priv->callback (r_priv->factory, pixbuf, error, r_priv->user_data); + if (r_priv->errors) { + if (!error) + g_set_error (&error, FACTORY_ERROR, 0, r_priv->errors->str); + else { + g_string_append (r_priv->errors, " - "); + g_string_append (r_priv->errors, error->message); + g_set_error (&error, FACTORY_ERROR, 0, r_priv->errors->str); + } + } - if (r_priv->destroy) - r_priv->destroy (r_priv->destroy); + r_priv->pcallback (r_priv->factory, pixbuf, error, r_priv->user_data); - /* Cleanup */ + /* Cleanup */ + if (stream) { + g_input_stream_close (G_INPUT_STREAM (stream), NULL, NULL); + g_object_unref (stream); + } + + if (error) + g_error_free (error); + + if (pixbuf) + gdk_pixbuf_unref (pixbuf); + } + + if (r_priv->ucallback) { + gchar *u = g_file_get_uri (filei); + + if (r_priv->errors) { + if (!error) + g_set_error (&error, FACTORY_ERROR, 0, r_priv->errors->str); + else { + g_string_append (r_priv->errors, " - "); + g_string_append (r_priv->errors, error->message); + g_set_error (&error, FACTORY_ERROR, 0, r_priv->errors->str); + } + } + + r_priv->ucallback (r_priv->factory, (const gchar *) u, error, r_priv->user_data); + g_free (u); + } + if (filei) g_object_unref (filei); - if (stream) { - g_input_stream_close (G_INPUT_STREAM (stream), NULL, NULL); - g_object_unref (stream); - } + if (r_priv->destroy) + r_priv->destroy (r_priv->user_data); - if (error) - g_error_free (error); - - if (pixbuf) - gdk_pixbuf_unref (pixbuf); } @@ -168,6 +200,34 @@ g_free (key); } + +static void +on_task_error (DBusGProxy *proxy, + guint handle, + GStrv failed_uris, + gint error_code, + gchar *error_message, + gpointer user_data) +{ + HildonThumbnailFactoryPrivate *f_priv = FACTORY_GET_PRIVATE (user_data); + gchar *key = g_strdup_printf ("%d", handle); + HildonThumbnailRequest *request = g_hash_table_lookup (f_priv->tasks, key); + + if (request) { + HildonThumbnailRequestPrivate *r_priv = REQUEST_GET_PRIVATE (request); + + if (!r_priv->errors) { + r_priv->errors = g_string_new (error_message); + } else { + g_string_append (r_priv->errors, " - "); + g_string_append (r_priv->errors, error_message); + } + } + + g_free (key); +} + + static gboolean have_all_for_request_cb (gpointer user_data) { @@ -205,8 +265,19 @@ dbus_g_proxy_connect_signal (f_priv->proxy, "Finished", G_CALLBACK (on_task_finished), - g_object_ref (self), - (GClosureNotify) g_object_unref); + self, + NULL); + + dbus_g_proxy_add_signal (f_priv->proxy, "Error", + G_TYPE_UINT, + G_TYPE_BOXED, + G_TYPE_INT, + G_TYPE_STRING, G_TYPE_INVALID); + + dbus_g_proxy_connect_signal (f_priv->proxy, "Error", + G_CALLBACK (on_task_error), + self, + NULL); } static void @@ -224,9 +295,11 @@ r_priv->lpaths[1] = NULL; r_priv->lpaths[2] = NULL; r_priv->factory = NULL; - r_priv->callback = NULL; + r_priv->pcallback = NULL; + r_priv->ucallback = NULL; r_priv->destroy = NULL; r_priv->user_data = NULL; + r_priv->errors = NULL; } @@ -285,20 +358,30 @@ gchar *key = g_strdup_printf ("%d", OUT_handle); r_priv->key = g_strdup (key); - g_hash_table_replace (f_priv->tasks, key, + + if (!error) { + g_hash_table_replace (f_priv->tasks, key, g_object_ref (request)); + } else { + if (r_priv->pcallback) + r_priv->pcallback (r_priv->factory, NULL, error, r_priv->user_data); + if (r_priv->ucallback) + r_priv->ucallback (r_priv->factory, NULL, error, r_priv->user_data); + } + g_object_unref (request); } -HildonThumbnailRequest* -hildon_thumbnail_factory_request (HildonThumbnailFactory *self, - const gchar *uri, - guint width, guint height, - gboolean cropped, - const gchar *mime_type, - HildonThumbnailRequestCallback callback, - gpointer user_data, - GDestroyNotify destroy) +static HildonThumbnailRequest* +hildon_thumbnail_factory_request_generic (HildonThumbnailFactory *self, + const gchar *uri, + guint width, guint height, + gboolean cropped, + const gchar *mime_type, + HildonThumbnailRequestUriCallback ucallback, + HildonThumbnailRequestPixbufCallback pcallback, + gpointer user_data, + GDestroyNotify destroy) { HildonThumbnailRequest *request = g_object_new (HILDON_TYPE_THUMBNAIL_REQUEST, NULL); HildonThumbnailRequestPrivate *r_priv = REQUEST_GET_PRIVATE (request); @@ -321,7 +404,8 @@ r_priv->uris[0] = g_strdup (uri); r_priv->factory = g_object_ref (self); r_priv->user_data = user_data; - r_priv->callback = callback; + r_priv->pcallback = pcallback; + r_priv->ucallback = ucallback; r_priv->destroy = destroy; r_priv->cropped = cropped; @@ -349,6 +433,42 @@ return request; } +HildonThumbnailRequest* +hildon_thumbnail_factory_request_pixbuf (HildonThumbnailFactory *self, + const gchar *uri, + guint width, guint height, + gboolean cropped, + const gchar *mime_type, + HildonThumbnailRequestPixbufCallback callback, + gpointer user_data, + GDestroyNotify destroy) +{ + return hildon_thumbnail_factory_request_generic (self, uri, width, height, + cropped, mime_type, + NULL, + callback, + user_data, + destroy); +} + +HildonThumbnailRequest* +hildon_thumbnail_factory_request_uri (HildonThumbnailFactory *self, + const gchar *uri, + guint width, guint height, + gboolean cropped, + const gchar *mime_type, + HildonThumbnailRequestUriCallback callback, + gpointer user_data, + GDestroyNotify destroy) +{ + return hildon_thumbnail_factory_request_generic (self, uri, width, height, + cropped, mime_type, + callback, + NULL, + user_data, + destroy); +} + void hildon_thumbnail_factory_join (HildonThumbnailFactory *self) {
- Previous message: [maemo-commits] r16544 - in projects/haf/trunk/hildon-thumbnail: . thumbs
- Next message: [maemo-commits] r16546 - projects/haf/trunk/hildon-thumbnail/thumbs
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]