[maemo-commits] [maemo-commits] r16210 - in projects/haf/branches/hildon-thumbnail/daemonize: . thumbs

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Sep 24 16:19:54 EEST 2008
Author: pvanhoof
Date: 2008-09-24 16:19:53 +0300 (Wed, 24 Sep 2008)
New Revision: 16210

Modified:
   projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnail-factory.c
Log:
2008-09-24  Philip Van Hoof  <pvanhoof at gnome.org>

	* thumbs/hildon-thumbnail-factory.c: Performance improvement when a
	thumbnail already exists (avoiding a dbus call)



Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-24 11:47:55 UTC (rev 16209)
+++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-24 13:19:53 UTC (rev 16210)
@@ -1,3 +1,8 @@
+2008-09-24  Philip Van Hoof  <pvanhoof at gnome.org>
+
+	* thumbs/hildon-thumbnail-factory.c: Performance improvement when a
+	thumbnail already exists (avoiding a dbus call)
+
 2008-09-23  Philip Van Hoof  <pvanhoof at gnome.org>
 
 	* daemon/manager.c: Fixed a crash

Modified: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnail-factory.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnail-factory.c	2008-09-24 11:47:55 UTC (rev 16209)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnail-factory.c	2008-09-24 13:19:53 UTC (rev 16210)
@@ -101,33 +101,16 @@
 }
 
 static void
-on_task_finished (DBusGProxy *proxy,
-		  guint       handle,
-		  gpointer    user_data)
+create_pixbuf_and_callback (ThumbsItem *item, gchar *large, gchar *normal, gchar *cropped)
 {
-	gchar *key = g_strdup_printf ("%d", handle);
-	ThumbsItem *item = g_hash_table_lookup (tasks, key);
-
-	if (item) {
+		GFile *filei = NULL;
+		GInputStream *stream = NULL;
 		GdkPixbuf *pixbuf = NULL;
-		gchar *large = NULL, *normal = NULL, *cropped = NULL;
+		gchar *path;
 		GError *error = NULL;
-		gchar *path = NULL;
-		GFile *filei = NULL;
-		GInputStream *stream = NULL;
 
-		/* Get the large small and cropped path for the original
-		 * URI */
-		
-		hildon_thumbnail_util_get_thumb_paths (item->uri, &large, 
-											   &normal, &cropped, 
-											   &error);
+		/* Determine the exact type of thumbnail being requested */
 
-		if (error)
-			goto error_handler;
-
-		/* Determine the exact type of thumbnail being requested */
-		
 		if (item->flags & HILDON_THUMBNAIL_FLAG_CROP) {
 			path = g_strdup (cropped);
 		} else if (item->width > 128) {
@@ -137,9 +120,9 @@
 		}
 
 		/* Open the original thumbnail as a stream */
-	
 		filei = g_file_new_for_path (path);
 		stream = G_INPUT_STREAM (g_file_read (filei, NULL, &error));
+		g_free (path);
 
 		if (error)
 			goto error_handler;
@@ -152,7 +135,7 @@
 		error_handler:
 
 		/* Callback user function, passing the pixbuf and error */
-			
+
 		item->callback (item, item->user_data, pixbuf, error);
 
 		/* Cleanup */
@@ -169,7 +152,34 @@
 
 		if (pixbuf)
 			gdk_pixbuf_unref (pixbuf);
+}
 
+static void
+on_task_finished (DBusGProxy *proxy,
+		  guint       handle,
+		  gpointer    user_data)
+{
+	gchar *key = g_strdup_printf ("%d", handle);
+	ThumbsItem *item = g_hash_table_lookup (tasks, key);
+
+	if (item) {
+		gchar *large = NULL, *normal = NULL, *cropped = NULL;
+		GError *error = NULL;
+
+		/* Get the large small and cropped path for the original
+		 * URI */
+		
+		hildon_thumbnail_util_get_thumb_paths (item->uri, &large, 
+											   &normal, &cropped, 
+											   &error);
+
+		if (error)
+			goto error_handler;
+
+		create_pixbuf_and_callback (item, large, normal, cropped);
+
+		error_handler:
+
 		g_free (cropped);
 		g_free (normal);
 		g_free (large);
@@ -314,6 +324,32 @@
 	g_hash_table_replace (tasks, key, item);
 }
 
+typedef struct {
+	gchar *large, *normal, *cropped;
+	ThumbsItem *item;
+} ThumbsItemAndPaths;
+
+static void
+free_thumbsitem_and_paths (ThumbsItemAndPaths *info) 
+{
+	g_free (info->large);
+	g_free (info->normal);
+	g_free (info->cropped);
+	thumb_item_free (info->item);
+	g_slice_free (ThumbsItemAndPaths, info);
+}
+
+static gboolean
+have_all_cb (gpointer user_data)
+{
+	ThumbsItemAndPaths *info = user_data;
+	ThumbsItem *item = info->item;
+
+	create_pixbuf_and_callback (item, info->large, info->normal, info->cropped);
+
+	return FALSE;
+}
+
 HildonThumbnailFactoryHandle hildon_thumbnail_factory_load_custom(
 				const gchar *uri, const gchar *mime_type,
 				guint width, guint height,
@@ -321,32 +357,33 @@
 				gpointer user_data, 
 				HildonThumbnailFlags flags, ...)
 {
+	gchar *large, *normal, *cropped;
+	GError *error = NULL;
 	ThumbsItem *item;
-	GStrv uris = (GStrv) g_malloc0 (sizeof (gchar *) * 2);
+	GStrv uris;
+	gboolean have_all = FALSE;
 
 	g_return_val_if_fail(uri != NULL && mime_type != NULL && callback != NULL,
 			     NULL);
 
-	init ();
+	hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
+						       &cropped, &error);
 
 	if (flags & HILDON_THUMBNAIL_FLAG_RECREATE) {
-		gchar *large, *normal, *cropped;
-		GError *error = NULL;
-
-		hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
-						       &cropped, &error);
-
 		if (!error) {
 			g_unlink (large);
 			g_unlink (normal);
 			g_unlink (cropped);
-		} else
-			g_error_free (error);
+		}
+	} else
+		have_all = (g_file_test (large, G_FILE_TEST_EXISTS) && 
+				    g_file_test (normal, G_FILE_TEST_EXISTS) && 
+				    g_file_test (cropped, G_FILE_TEST_EXISTS));
 
-		g_free (large);
-		g_free (normal);
-		g_free (cropped);
-	}
+	if (error)
+		g_error_free (error);
+	else
+		have_all = FALSE;
 
 	item = g_new (ThumbsItem, 1);
 
@@ -360,6 +397,27 @@
 	item->canceled = FALSE;
 	item->handle_id = 0;
 
+	if (have_all) {
+		ThumbsItemAndPaths *info = g_slice_new (ThumbsItemAndPaths);
+
+		info->item = item;
+		info->normal = g_strdup (normal);
+		info->large = g_strdup (large);
+		info->cropped = g_strdup (cropped);
+
+		g_idle_add_full (G_PRIORITY_DEFAULT, have_all_cb, info,
+						 (GDestroyNotify) free_thumbsitem_and_paths);
+	}
+
+	g_free (large);
+	g_free (normal);
+	g_free (cropped);
+
+	init ();
+
+	uris = (GStrv) g_malloc0 (sizeof (gchar *) * 2);
+
+
 	uris[0] = g_strdup (uri);
 
 	org_freedesktop_thumbnailer_Generic_queue_async (proxy, (const char **) uris, 0, 


More information about the maemo-commits mailing list