[maemo-commits] [maemo-commits] r16483 - in projects/haf/trunk/hildon-thumbnail: . daemon daemon/plugins thumbs

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Oct 24 12:53:46 EEST 2008
Author: pvanhoof
Date: 2008-10-24 12:53:43 +0300 (Fri, 24 Oct 2008)
New Revision: 16483

Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c
   projects/haf/trunk/hildon-thumbnail/daemon/utils.c
   projects/haf/trunk/hildon-thumbnail/daemon/utils.h
   projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c
   projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c
Log:
2008-10-24  Philip Van Hoof  <philip at codeminded.be>

	* thumbs/hildon-thumbnail-factory.c
	* thumbs/hildon-thumbnail-obj.c
	* daemon/utils.c
	* daemon/plugins/gdkpixbuf-plugin.c
	* daemon/plugins/exec-plugin.c
	* daemon/plugins/gstreamer-video-plugin.c
	* daemon/utils.h
	* daemon/thumbnailer.c: Support for localthumbs



Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-10-24 09:53:43 UTC (rev 16483)
@@ -1,3 +1,14 @@
+2008-10-24  Philip Van Hoof  <philip at codeminded.be>
+
+	* thumbs/hildon-thumbnail-factory.c
+	* thumbs/hildon-thumbnail-obj.c
+	* daemon/utils.c
+	* daemon/plugins/gdkpixbuf-plugin.c
+	* daemon/plugins/exec-plugin.c
+	* daemon/plugins/gstreamer-video-plugin.c
+	* daemon/utils.h
+	* daemon/thumbnailer.c: Support for localthumbs
+
 2008-10-23  Marius Vollmer  <marius.vollmer at nokia.com>
 
 	Released 3.0.8

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c	2008-10-24 09:53:43 UTC (rev 16483)
@@ -269,7 +269,7 @@
 		content_type = g_file_info_get_content_type (info);
 
 		hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
-						       &cropped);
+						       &cropped, NULL, NULL, NULL);
 
 		mime_type = g_strdup (content_type);
 		mime_type_at = g_strdup (content_type);

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2008-10-24 09:53:43 UTC (rev 16483)
@@ -227,7 +227,8 @@
 		gboolean just_crop;
 
 
-		hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped);
+		hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped,
+											   NULL, NULL, NULL);
 
 		just_crop = (g_file_test (large, G_FILE_TEST_EXISTS) && 
 			     g_file_test (normal, G_FILE_TEST_EXISTS) && 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-10-24 09:53:43 UTC (rev 16483)
@@ -433,7 +433,7 @@
 		GError *nerror = NULL;
 
 		hildon_thumbnail_util_get_thumb_paths (uris[i], &large, &normal, 
-						       &cropped);
+						       &cropped, NULL, NULL, NULL);
 
 		/* Create the thumbnailer struct */
 		thumber = g_slice_new0 (VideoThumbnailer);

Modified: projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c	2008-10-24 09:53:43 UTC (rev 16483)
@@ -135,7 +135,8 @@
 		g_object_unref (info);
 	}
 
-	hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped);
+	hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped, 
+					       NULL, NULL, NULL);
 
 	*has_thumb = (g_file_test (large, G_FILE_TEST_EXISTS) && 
 		      g_file_test (normal, G_FILE_TEST_EXISTS) && 
@@ -269,7 +270,9 @@
 		gboolean has_thumb = FALSE;
 		GError *error = NULL;
 
-		get_some_file_infos (urls[i], &mime_type, mime_types?mime_types[i]:NULL, &has_thumb, &error);
+		get_some_file_infos (urls[i], &mime_type, 
+				     mime_types?mime_types[i]:NULL, 
+				     &has_thumb, &error);
 
 		if (error) {
 			
@@ -447,12 +450,14 @@
 
 		hildon_thumbnail_util_get_thumb_paths (from_uri, &from_large, 
 						       &from_normal, 
-						       &from_cropped);
+						       &from_cropped,
+						       NULL, NULL, NULL);
 
 
 		hildon_thumbnail_util_get_thumb_paths (to_uri, &to_large, 
 						       &to_normal, 
-						       &to_cropped);
+						       &to_cropped,
+						       NULL, NULL, NULL);
 
 		g_rename (from_large, to_large);
 		g_rename (from_normal, to_normal);
@@ -491,11 +496,13 @@
 
 		hildon_thumbnail_util_get_thumb_paths (from_uri, &from_s[0], 
 						       &from_s[1], 
-						       &from_s[2]);
+						       &from_s[2],
+						       NULL, NULL, NULL);
 
 		hildon_thumbnail_util_get_thumb_paths (to_uri, &to_s[0], 
 						       &to_s[1], 
-						       &to_s[2]);
+						       &to_s[2],
+						       NULL, NULL, NULL);
 
 		for (n = 0; n<3; n++) {
 			GFile *from, *to;
@@ -548,7 +555,8 @@
 
 		hildon_thumbnail_util_get_thumb_paths (uri, &large, 
 						       &normal, 
-						       &cropped);
+						       &cropped,
+						       NULL, NULL, NULL);
 
 		g_unlink (large);
 		g_unlink (normal);

Modified: projects/haf/trunk/hildon-thumbnail/daemon/utils.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/utils.c	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/daemon/utils.c	2008-10-24 09:53:43 UTC (rev 16483)
@@ -22,21 +22,49 @@
  *
  */
 
+#include <gio/gio.h>
 #include <string.h>
 #include "utils.h"
 
 
 void
-hildon_thumbnail_util_get_thumb_paths (const gchar *uri, gchar **large, gchar **normal, gchar **cropped)
+hildon_thumbnail_util_get_thumb_paths (const gchar *uri, gchar **large, gchar **normal, gchar **cropped, gchar **local_large, gchar **local_normal, gchar **local_cropped)
 {
-	gchar *ascii_digest;
-	gchar *thumb_filename;
-	gchar *cropped_filename;
-
+	gchar *ascii_digest, *filename = NULL;
+	gchar *lascii_digest = NULL;
+	gchar *thumb_filename, *uri_t = NULL;
+	gchar *cropped_filename, *ptr;
 	static gchar *large_dir = NULL;
 	static gchar *normal_dir = NULL;
 	static gchar *cropped_dir = NULL;
+	gchar *local_dir = NULL;
+	GFile *file; GFileInfo *info;
+	gboolean local = (local_large || local_normal || local_cropped);
 
+	if (local) {
+		uri_t = g_strdup (uri);
+		ptr = strrchr (uri_t, '/');
+
+		if (ptr) {
+			*ptr = '\0';
+			local_dir = g_strdup_printf ("%s/.thumblocal", uri_t);
+			g_free (uri_t);
+		}
+
+		file = g_file_new_for_uri (uri);
+		info = g_file_query_info (file,
+					  G_FILE_ATTRIBUTE_STANDARD_NAME,
+					  G_FILE_QUERY_INFO_NONE,
+					  NULL, NULL);
+
+		if (info) {
+			filename = g_strdup (g_file_info_get_name (info));
+			g_object_unref (info);
+		}
+
+		g_object_unref (file);
+	}
+
 	/* I know we leak, but it's better than doing memory fragementation on 
 	 * these strings ... */
 
@@ -61,6 +89,7 @@
 		g_mkdir_with_parents (cropped_dir, 0770);
 
 	ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
+
 	thumb_filename = g_strdup_printf ("%s.png", ascii_digest);
 	cropped_filename = g_strdup_printf ("%s.jpeg", ascii_digest);
 
@@ -68,6 +97,39 @@
 	*normal = g_build_filename (normal_dir, thumb_filename, NULL);
 	*cropped = g_build_filename (cropped_dir, cropped_filename, NULL);
 
+	if (local) {
+		if (filename && local_dir) {
+			gchar *lthumb_filename;
+			gchar *lcropped_filename;
+
+			lascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, filename, -1);
+			lthumb_filename = g_strdup_printf ("%s.png", lascii_digest);
+			lcropped_filename = g_strdup_printf ("%s.jpeg", lascii_digest);
+
+			if (local_large)
+				*local_large = g_build_filename (local_dir, "large", lthumb_filename, NULL);
+			if (local_normal)
+				*local_normal = g_build_filename (local_dir, "normal", lthumb_filename, NULL);
+			if (local_cropped)
+				*local_cropped = g_build_filename (local_dir, "cropped", lcropped_filename, NULL);
+
+			g_free (lthumb_filename);
+			g_free (lcropped_filename);
+
+		} else {
+			if (local_large)
+				*local_large = g_strdup ("");
+			if (local_normal)
+				*local_normal = g_strdup ("");
+			if (local_cropped)
+				*local_cropped = g_strdup ("");
+		}
+
+		g_free (filename);
+		g_free (lascii_digest);
+		g_free (local_dir);
+	}
+
 	g_free (thumb_filename);
 	g_free (cropped_filename);
 	g_free (ascii_digest);

Modified: projects/haf/trunk/hildon-thumbnail/daemon/utils.h
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/utils.h	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/daemon/utils.h	2008-10-24 09:53:43 UTC (rev 16483)
@@ -28,7 +28,7 @@
 #include <glib.h>
 #include <gio/gio.h>
 
-void hildon_thumbnail_util_get_thumb_paths (const gchar *uri, gchar **large, gchar **normal, gchar **cropped);
+void hildon_thumbnail_util_get_thumb_paths (const gchar *uri, gchar **large, gchar **normal, gchar **cropped, gchar **local_large, gchar **local_normal, gchar **local_cropped);
 void hildon_thumbnail_util_get_albumart_path (const gchar *a, const gchar *b, const gchar *prefix, gchar **path);
 
 #ifndef g_sprintf

Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c	2008-10-24 09:53:43 UTC (rev 16483)
@@ -101,7 +101,7 @@
 }
 
 static void
-create_pixbuf_and_callback (ThumbsItem *item, gchar *large, gchar *normal, gchar *cropped)
+create_pixbuf_and_callback (ThumbsItem *item, gchar *large, gchar *normal, gchar *cropped, gboolean uris_as_paths)
 {
 		GFile *filei = NULL;
 		GInputStream *stream = NULL;
@@ -120,7 +120,11 @@
 		}
 
 		/* Open the original thumbnail as a stream */
-		filei = g_file_new_for_path (path);
+		if (uris_as_paths)
+			filei = g_file_new_for_uri (path);
+		else
+			filei = g_file_new_for_path (path);
+
 		stream = G_INPUT_STREAM (g_file_read (filei, NULL, &error));
 		g_free (path);
 
@@ -169,9 +173,10 @@
 		 * URI */
 		
 		hildon_thumbnail_util_get_thumb_paths (item->uri, &large, 
-											   &normal, &cropped);
+											   &normal, &cropped,
+											   NULL, NULL, NULL);
 
-		create_pixbuf_and_callback (item, large, normal, cropped);
+		create_pixbuf_and_callback (item, large, normal, cropped, FALSE);
 
 		g_free (cropped);
 		g_free (normal);
@@ -319,6 +324,7 @@
 
 typedef struct {
 	gchar *large, *normal, *cropped;
+	gchar *local_large, *local_normal, *local_cropped;
 	ThumbsItem *item;
 } ThumbsItemAndPaths;
 
@@ -328,6 +334,9 @@
 	g_free (info->large);
 	g_free (info->normal);
 	g_free (info->cropped);
+	g_free (info->local_large);
+	g_free (info->local_normal);
+	g_free (info->local_cropped);
 	thumb_item_free (info->item);
 	g_slice_free (ThumbsItemAndPaths, info);
 }
@@ -337,9 +346,42 @@
 {
 	ThumbsItemAndPaths *info = user_data;
 	ThumbsItem *item = info->item;
+	gchar *large, *normal, *cropped;
+	gboolean uris = FALSE;
+	GFile *local;
 
-	create_pixbuf_and_callback (item, info->large, info->normal, info->cropped);
+	local = g_file_new_for_uri (info->local_large);
 
+	if (g_file_query_exists (local, NULL)) {
+		large = info->local_large;
+		uris = TRUE;
+	} else 
+		large = info->large;
+
+	g_object_unref (local);
+
+	local = g_file_new_for_uri (info->local_normal);
+
+	if (g_file_query_exists (local, NULL)) {
+		normal = info->local_normal;
+		uris = TRUE;
+	} else 
+		normal = info->local_normal;
+
+	g_object_unref (local);
+
+	local = g_file_new_for_uri (info->local_cropped);
+
+	if (g_file_query_exists (local, NULL)) {
+		cropped = info->local_cropped;
+		uris = TRUE;
+	} else 
+		cropped = info->cropped;
+
+	g_object_unref (local);
+
+	create_pixbuf_and_callback (item, large, normal, cropped, uris);
+
 	return FALSE;
 }
 
@@ -351,6 +393,7 @@
 				HildonThumbnailFlags flags, ...)
 {
 	gchar *large, *normal, *cropped;
+	gchar *local_large, *local_normal, *local_cropped;
 	ThumbsItem *item;
 	GStrv uris;
 	GStrv mimes;
@@ -360,22 +403,30 @@
 			     NULL);
 
 	hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
-						       &cropped);
+								&cropped, &local_large, 
+								&local_normal, &local_cropped);
 
 	if (flags & HILDON_THUMBNAIL_FLAG_RECREATE) {
 		g_unlink (large);
 		g_unlink (normal);
 		g_unlink (cropped);
 	} else {
-		gchar *path;
+		gchar *path, *luri;
+		GFile *local;
+
 		if (flags & HILDON_THUMBNAIL_FLAG_CROP) {
 			path = cropped;
+			luri = local_cropped;
 		} else if (width > 128) {
 			path = large;
+			luri = local_large;
 		} else {
 			path = normal;
+			luri = local_normal;
 		}
-		have_all = g_file_test (path, G_FILE_TEST_EXISTS);
+		local = g_file_new_for_uri (luri);
+		have_all = (g_file_test (path, G_FILE_TEST_EXISTS) || g_file_query_exists (local, NULL));
+		g_object_unref (local);
 	}
 
 	item = g_new (ThumbsItem, 1);
@@ -401,6 +452,10 @@
 		info->large = large;
 		info->cropped = cropped;
 
+		info->local_normal = local_normal;
+		info->local_large = local_large;
+		info->local_cropped = local_cropped;
+
 		g_idle_add_full (G_PRIORITY_DEFAULT, have_all_cb, info,
 						 (GDestroyNotify) free_thumbsitem_and_paths);
 
@@ -411,6 +466,10 @@
 	g_free (normal);
 	g_free (cropped);
 
+	g_free (local_large);
+	g_free (local_normal);
+	g_free (local_cropped);
+
 	if (!have_all) {
 
 		init ();

Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c	2008-10-24 08:49:54 UTC (rev 16482)
+++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c	2008-10-24 09:53:43 UTC (rev 16483)
@@ -42,6 +42,7 @@
 	GStrv uris;
 	gchar *key;
 	gchar *paths[3];
+	gchar *lpaths[3];
 	guint width, height;
 	gboolean cropped;
 	HildonThumbnailRequestCallback callback;
@@ -83,18 +84,39 @@
 	GdkPixbuf *pixbuf = NULL;
 	gchar *path;
 	GError *error = NULL;
-
+	gboolean uris = FALSE;
+	
 	/* Determine the exact type of thumbnail being requested */
 
-	if (r_priv->cropped)
-		path = r_priv->paths[2];
-	else if (r_priv->width > 128)
-		path = r_priv->paths[1];
+	if (r_priv->cropped) {
+		if (!g_file_test (r_priv->lpaths[2], G_FILE_TEST_EXISTS))
+			path = r_priv->paths[2];
+		else {
+			path = r_priv->lpaths[2];
+			uris = TRUE;
+		}
+	} else if (r_priv->width > 128) {
+		if (!g_file_test (r_priv->lpaths[1], G_FILE_TEST_EXISTS))
+			path = r_priv->paths[1];
+		else {
+			path = r_priv->lpaths[1];
+			uris = TRUE;
+		}
+	} else {
+		if (!g_file_test (r_priv->lpaths[0], G_FILE_TEST_EXISTS))
+			path = r_priv->paths[0];
+		else {
+			path = r_priv->lpaths[0];
+			uris = TRUE;
+		}
+	}
+
+	/* Open the original thumbnail as a stream */
+	if (uris)
+		filei = g_file_new_for_uri (path);
 	else
-		path = r_priv->paths[0];
+		filei = g_file_new_for_path (path);
 
-	/* Open the original thumbnail as a stream */
-	filei = g_file_new_for_path (path);
 	stream = G_INPUT_STREAM (g_file_read (filei, NULL, &error));
 
 	if (error)
@@ -203,6 +225,9 @@
 	r_priv->paths[0] = NULL;
 	r_priv->paths[1] = NULL;
 	r_priv->paths[2] = NULL;
+	r_priv->lpaths[0] = NULL;
+	r_priv->lpaths[1] = NULL;
+	r_priv->lpaths[2] = NULL;
 	r_priv->factory = NULL;
 	r_priv->callback = NULL;
 	r_priv->destroy = NULL;
@@ -225,8 +250,10 @@
 	HildonThumbnailRequestPrivate *r_priv = REQUEST_GET_PRIVATE (object);
 	guint i;
 
-	for (i = 0; i < 3; i++)
+	for (i = 0; i < 3; i++) {
 		g_free (r_priv->paths[i]);
+		g_free (r_priv->lpaths[i]);
+	}
 	if (r_priv->uris)
 		g_strfreev (r_priv->uris);
 	g_free (r_priv->key);
@@ -287,10 +314,13 @@
 
 	hildon_thumbnail_util_get_thumb_paths (uri, &r_priv->paths[0], 
 					       &r_priv->paths[1], 
-					       &r_priv->paths[2]);
+					       &r_priv->paths[2],
+					       &r_priv->lpaths[0],
+					       &r_priv->lpaths[1],
+					       &r_priv->lpaths[2]);
 
 	for (i = 0; i< 3 && !have; i++)
-		have = g_file_test (r_priv->paths[i], G_FILE_TEST_EXISTS);
+		have = (g_file_test (r_priv->paths[i], G_FILE_TEST_EXISTS) || g_file_test (r_priv->lpaths[i], G_FILE_TEST_EXISTS));
 
 	r_priv->uris = (GStrv) g_malloc0 (sizeof (gchar *) * 2);
 	r_priv->uris[0] = g_strdup (uri);


More information about the maemo-commits mailing list