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

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Nov 3 12:48:18 EET 2008
Author: pvanhoof
Date: 2008-11-03 12:48:08 +0200 (Mon, 03 Nov 2008)
New Revision: 16555

Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c
   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-11-03  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/plugins/epeg-plugin.c
	* daemon/utils.h
	* daemon/thumbnailer.c: Storing as JPEG instead of PNG, since this 
	commit we therefore no longer follow the thumbnail-spec. If you
	set the DoPngs in all your thumbnailer plugin's configurations, then
	you will still follow the thumbnail-spec.

	The reason for this is that a) JPEG thumbnails are smaller
				    b) Smaller files means loading faster
				    c) The device has libraries that load JPEG
				       files faster and better than that it can
				       load PNG files.



Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-11-03 10:48:08 UTC (rev 16555)
@@ -1,3 +1,24 @@
+2008-11-03  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/plugins/epeg-plugin.c
+	* daemon/utils.h
+	* daemon/thumbnailer.c: Storing as JPEG instead of PNG, since this 
+	commit we therefore no longer follow the thumbnail-spec. If you
+	set the DoPngs in all your thumbnailer plugin's configurations, then
+	you will still follow the thumbnail-spec.
+
+	The reason for this is that a) JPEG thumbnails are smaller
+				    b) Smaller files means loading faster
+				    c) The device has libraries that load JPEG
+				       files faster and better than that it can
+				       load PNG files.
+
 2008-10-31  Philip Van Hoof  <philip at codeminded.be>
 
 	* thumbs/hildon-thumbnail-obj.c

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c	2008-11-03 10:48:08 UTC (rev 16555)
@@ -45,6 +45,7 @@
 
 static gchar **supported = NULL;
 static gboolean do_cropped = TRUE;
+static gboolean do_pngs = FALSE;
 static GFileMonitor *monitor = NULL;
 
 const gchar** 
@@ -70,29 +71,35 @@
 save_thumb_file_meta (GdkPixbuf *pixbuf, gchar *file, guint64 mtime, const gchar *uri, GError **error)
 {
 	gboolean ret;
-	char mtime_str[64];
 
-	const char *default_keys[] = {
-	    URI_OPTION,
-	    MTIME_OPTION,
-	    SOFTWARE_OPTION,
-	    NULL
-	};
+	if (do_pngs) {
+		char mtime_str[64];
 
-	const char *default_values[] = {
-	    uri,
-	    mtime_str,
-	    HILDON_THUMBNAIL_APPLICATION "-" VERSION,
-	    NULL
-	};
+		const char *default_keys[] = {
+			URI_OPTION,
+			MTIME_OPTION,
+			SOFTWARE_OPTION,
+			NULL
+		};
 
-	g_sprintf(mtime_str, "%lu", mtime);
+		const char *default_values[] = {
+			uri,
+			mtime_str,
+			HILDON_THUMBNAIL_APPLICATION "-" VERSION,
+			NULL
+		};
 
-	ret = gdk_pixbuf_savev (pixbuf, file, "png", 
-				(char **) default_keys, 
-				(char **) default_values, 
-				error);
+		g_sprintf(mtime_str, "%lu", mtime);
 
+		ret = gdk_pixbuf_savev (pixbuf, file, "png", 
+								(char **) default_keys, 
+								(char **) default_values, 
+								error);
+	} else {
+		ret = gdk_pixbuf_save (pixbuf, file, "jpeg", 
+							   error, NULL);
+	}
+
 	return ret;
 }
 
@@ -177,41 +184,7 @@
 	return dest;
 }
 
-/* 
-static void
-get_thumbnail_paths (const gchar  *uri, 
-				     gchar       **epeg_path,
-					 gchar       **large_path,
-					 gchar       **normal_path,
-					 gchar       **cropped_path)
-{
-	gchar *filename;
-	gchar *dir, *str;
 
-	hildon_thumbnail_util_get_thumb_paths (uri, large_path, normal_path, 
-										   cropped_path,
-										   NULL, NULL, NULL);
-
-	*epeg_path = NULL;
-
-	dir = g_build_filename (g_get_home_dir (), ".thumbnails", "epeg", NULL);
-
-	if (!g_file_test (dir, G_FILE_TEST_EXISTS)) {
-		g_mkdir_with_parents (dir, 0770);
-	}
-
-	str = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
-
-	filename = g_strdup_printf ("%s.jpeg", str);
-	g_free (str);
-
-	*epeg_path = g_build_filename (dir, filename, NULL);
-
-	g_free (dir);
-	g_free (filename);
-}
-*/
-
 static void
 destroy_pixbuf (guchar *pixels, gpointer data)
 {
@@ -239,17 +212,15 @@
 		gchar *large = NULL, 
 			  *normal = NULL, 
 			  *cropped = NULL;
-			  /* *epeg = NULL; */
 		guint64 mtime;
 		gboolean just_crop;
 		GFileInfo *finfo = NULL;
 		GError *nerror = NULL;
 
-		/* get_thumbnail_paths (uri, &epeg, &large, &normal, &cropped); */
 
 		hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
 										   &cropped,
-										   NULL, NULL, NULL);
+										   NULL, NULL, NULL, do_pngs);
 
 		just_crop = (g_file_test (large, G_FILE_TEST_EXISTS) && 
 					/* g_file_test (epeg, G_FILE_TEST_EXISTS) && */
@@ -302,9 +273,6 @@
 								  8, 256, 256, 256*3,
 								  destroy_pixbuf, im);
 
-		/* epeg_file_output_set (im, epeg); 
-		epeg_encode (im); */
-
 		save_thumb_file_meta (pixbuf_large, large, mtime, uri, &nerror);
 
 		if (nerror)
@@ -407,17 +375,25 @@
 	GKeyFile *keyfile;
 	GStrv mimetypes;
 	guint i = 0, length;
+	GError *error = NULL;
 
 	keyfile = g_key_file_new ();
 
 	if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
 		do_cropped = TRUE;
+		do_pngs = FALSE;
 		g_key_file_free (keyfile);
 		return;
 	}
 
 	do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", NULL);
+	do_pngs = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoPngs", &error);
 
+	if (error) {
+		do_pngs = FALSE;
+		g_error_free (error);
+	}
+
 	g_key_file_free (keyfile);
 }
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c	2008-11-03 10:48:08 UTC (rev 16555)
@@ -43,6 +43,7 @@
 
 static gchar **supported = NULL;
 static gboolean do_cropped = TRUE;
+static gboolean do_pngs = FALSE;
 static GHashTable *execs = NULL;
 static GFileMonitor *monitor = NULL;
 
@@ -270,7 +271,7 @@
 		content_type = g_file_info_get_content_type (info);
 
 		hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
-						       &cropped, NULL, NULL, NULL);
+						       &cropped, NULL, NULL, NULL, do_pngs);
 
 		mime_type = g_strdup (content_type);
 		mime_type_at = g_strdup (content_type);
@@ -360,6 +361,7 @@
 	GKeyFile *keyfile;
 	GStrv mimetypes;
 	guint i = 0, length;
+	GError *error = NULL;
 
 	if (!execs)
 		execs = g_hash_table_new_full (g_str_hash, g_str_equal,
@@ -370,12 +372,19 @@
 
 	if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
 		do_cropped = TRUE;
+		do_pngs = FALSE;
 		g_key_file_free (keyfile);
 		return;
 	}
 
 	do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", NULL);
+	do_pngs = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoPngs", &error);
 
+	if (error) {
+		do_pngs = FALSE;
+		g_error_free (error);
+	}
+
 	mimetypes = g_key_file_get_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", &length, NULL);
 
 	while (mimetypes && mimetypes[i] != NULL) {

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2008-11-03 10:48:08 UTC (rev 16555)
@@ -58,6 +58,7 @@
 
 static gchar **supported = NULL;
 static gboolean do_cropped = TRUE;
+static gboolean do_pngs = FALSE;
 static GFileMonitor *monitor = NULL;
 
 const gchar** 
@@ -97,28 +98,33 @@
 save_thumb_file_meta (GdkPixbuf *pixbuf, gchar *file, guint64 mtime, const gchar *uri, GError **error)
 {
 	gboolean ret;
-	char mtime_str[64];
+	if (do_pngs) {
+		char mtime_str[64];
 
-	const char *default_keys[] = {
-	    URI_OPTION,
-	    MTIME_OPTION,
-	    SOFTWARE_OPTION,
-	    NULL
-	};
+		const char *default_keys[] = {
+			URI_OPTION,
+			MTIME_OPTION,
+			SOFTWARE_OPTION,
+			NULL
+		};
 
-	const char *default_values[] = {
-	    uri,
-	    mtime_str,
-	    HILDON_THUMBNAIL_APPLICATION "-" VERSION,
-	    NULL
-	};
+		const char *default_values[] = {
+			uri,
+			mtime_str,
+			HILDON_THUMBNAIL_APPLICATION "-" VERSION,
+			NULL
+		};
 
-	g_sprintf(mtime_str, "%lu", mtime);
+		g_sprintf(mtime_str, "%lu", mtime);
 
-	ret = gdk_pixbuf_savev (pixbuf, file, "png", 
-				(char **) default_keys, 
-				(char **) default_values, 
-				error);
+		ret = gdk_pixbuf_savev (pixbuf, file, "png", 
+								(char **) default_keys, 
+								(char **) default_values, 
+								error);
+	} else {
+		ret = gdk_pixbuf_save (pixbuf, file, "jpeg", 
+							   error, NULL);
+	}
 
 	return ret;
 }
@@ -227,13 +233,12 @@
 		      *cropped = NULL;
 		gboolean just_crop;
 
-
 		hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped,
-											   NULL, NULL, NULL);
+											   NULL, NULL, NULL, do_pngs);
 
 		just_crop = (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_file_test (normal, G_FILE_TEST_EXISTS) && 
+				    !g_file_test (cropped, G_FILE_TEST_EXISTS));
 
 		if (just_crop && !do_cropped) {
 			g_free (cropped);
@@ -385,16 +390,25 @@
 reload_config (const gchar *config)
 {
 	GKeyFile *keyfile;
+	GError *error = NULL;
 
 	keyfile = g_key_file_new ();
 
 	if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
 		do_cropped = TRUE;
+		do_pngs = FALSE;
 		g_key_file_free (keyfile);
 		return;
 	}
 
 	do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", NULL);
+	do_pngs = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoPngs", &error);
+
+	if (error) {
+		do_pngs = FALSE;
+		g_error_free (error);
+	}
+
 	g_key_file_free (keyfile);
 }
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-11-03 10:48:08 UTC (rev 16555)
@@ -48,6 +48,7 @@
 
 static gchar *supported[] = { "video/mp4", "video/mpeg", NULL };
 static gboolean do_cropped = TRUE;
+static gboolean do_pngs = FALSE;
 static gboolean do_vidthumbs = TRUE;
 static GFileMonitor *monitor = NULL;
 
@@ -93,28 +94,33 @@
 save_thumb_file_meta (GdkPixbuf *pixbuf, const gchar *file, guint64 mtime, const gchar *uri, GError **error)
 {
 	gboolean ret;
-	char mtime_str[64];
+	if (do_pngs) {
+		char mtime_str[64];
 
-	const char *default_keys[] = {
-	    URI_OPTION,
-	    MTIME_OPTION,
-	    SOFTWARE_OPTION,
-	    NULL
-	};
+		const char *default_keys[] = {
+			URI_OPTION,
+			MTIME_OPTION,
+			SOFTWARE_OPTION,
+			NULL
+		};
 
-	const char *default_values[] = {
-	    uri,
-	    mtime_str,
-	    HILDON_THUMBNAIL_APPLICATION "-" VERSION,
-	    NULL
-	};
+		const char *default_values[] = {
+			uri,
+			mtime_str,
+			HILDON_THUMBNAIL_APPLICATION "-" VERSION,
+			NULL
+		};
 
-	g_sprintf(mtime_str, "%lu", mtime);
+		g_sprintf(mtime_str, "%lu", mtime);
 
-	ret = gdk_pixbuf_savev (pixbuf, file, "png", 
-				(char **) default_keys, 
-				(char **) default_values, 
-				error);
+		ret = gdk_pixbuf_savev (pixbuf, file, "png", 
+					(char **) default_keys, 
+					(char **) default_values, 
+					error);
+	} else {
+		ret = gdk_pixbuf_save (pixbuf, file, "jpeg", 
+							   error, NULL);
+	}
 
 	return ret;
 }
@@ -434,7 +440,8 @@
 		GError *nerror = NULL;
 
 		hildon_thumbnail_util_get_thumb_paths (uris[i], &large, &normal, 
-						       &cropped, NULL, NULL, NULL);
+						       &cropped, NULL, NULL, NULL,
+						       do_pngs);
 
 		/* Create the thumbnailer struct */
 		thumber = g_slice_new0 (VideoThumbnailer);
@@ -512,16 +519,25 @@
 reload_config (const gchar *config)
 {
 	GKeyFile *keyfile;
+	GError *error = NULL;
 
 	keyfile = g_key_file_new ();
 
 	if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
 		do_cropped = TRUE;
+		do_pngs = FALSE;
 		g_key_file_free (keyfile);
 		return;
 	}
 
 	do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", NULL);
+	do_pngs = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoPngs", &error);
+
+	if (error) {
+		do_pngs = FALSE;
+		g_error_free (error);
+	}
+
 	do_vidthumbs = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoVideoThumbnails", NULL);
 
 	g_key_file_free (keyfile);

Modified: projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c	2008-11-03 10:48:08 UTC (rev 16555)
@@ -424,7 +424,7 @@
 		gchar *normal = NULL, *large = NULL, *cropped = NULL;
 
 		hildon_thumbnail_util_get_thumb_paths (urls[i], &large, &normal, &cropped, 
-						       NULL, NULL, NULL);
+						       NULL, NULL, NULL, FALSE);
 
 		get_some_file_infos (urls[i], &mime_type, 
 				     mime_types?mime_types[i]:NULL, 
@@ -434,6 +434,28 @@
 			     g_file_test (normal, G_FILE_TEST_EXISTS) && 
 			     g_file_test (cropped, G_FILE_TEST_EXISTS));
 
+		if (!has_thumb) {
+			gchar *pnormal = NULL, *plarge = NULL, *pcropped = NULL;
+			hildon_thumbnail_util_get_thumb_paths (urls[i], &plarge, &pnormal, &pcropped, 
+						       NULL, NULL, NULL, FALSE);
+			has_thumb = (g_file_test (plarge, G_FILE_TEST_EXISTS) && 
+				     g_file_test (pnormal, G_FILE_TEST_EXISTS) && 
+				     g_file_test (pcropped, G_FILE_TEST_EXISTS));
+
+			if (has_thumb) {
+				g_free (normal);
+				normal = pnormal;
+				g_free (large);
+				large = plarge;
+				g_free (cropped);
+				cropped = pcropped;
+			} else {
+				g_free (pcropped);
+				g_free (pnormal);
+				g_free (plarge);
+			}
+		}
+
 		g_free (normal);
 		g_free (large);
 		g_free (cropped);
@@ -648,6 +670,8 @@
 
 		while (!had_err && urlss[i] != NULL) {
 			if (strv_contains (remotefss, urlss[i])) {
+			  guint y = 0;
+			  for (y = 0; y < 2; y++) {
 				gchar *from[4] = { NULL, NULL, NULL, NULL };
 				gchar *to[4] = { NULL, NULL, NULL, NULL };
 				guint z = 0;
@@ -659,7 +683,8 @@
 								       &from[2], 
 								       &to[0], 
 								       &to[1], 
-								       &to[2]);
+								       &to[2], 
+								       (y == 0));
 
 				for (z = 0; z < 3 && !error; z++) {
 					GFile *from_file, *to_file;
@@ -678,6 +703,7 @@
 
 				if (error)
 					g_error_free (error);
+			  }
 			}
 			i++;
 		}
@@ -719,6 +745,8 @@
 
 	while (from_urls[i] != NULL && to_urls[i] != NULL) {
 
+	  guint y = 0;
+	  for (y = 0; i < 2; y++ ) {
 		const gchar *from_uri = from_urls[i];
 		const gchar *to_uri = to_urls[i];
 		gchar *from_normal = NULL, 
@@ -731,13 +759,15 @@
 		hildon_thumbnail_util_get_thumb_paths (from_uri, &from_large, 
 						       &from_normal, 
 						       &from_cropped,
-						       NULL, NULL, NULL);
+						       NULL, NULL, NULL,
+						       (y == 0));
 
 
 		hildon_thumbnail_util_get_thumb_paths (to_uri, &to_large, 
 						       &to_normal, 
 						       &to_cropped,
-						       NULL, NULL, NULL);
+						       NULL, NULL, NULL,
+						       (y == 0));
 
 		g_rename (from_large, to_large);
 		g_rename (from_normal, to_normal);
@@ -750,7 +780,8 @@
 		g_free (to_large);
 		g_free (to_cropped);
 
-		i++;
+	  }
+	  i++;
 	}
 
 	dbus_g_method_return (context);
@@ -767,7 +798,8 @@
 	keep_alive ();
 
 	while (from_urls[i] != NULL && to_urls[i] != NULL) {
-
+	  guint y = 0;
+	  for (y = 0; i < 2; y++ ) {
 		const gchar *from_uri = from_urls[i];
 		const gchar *to_uri = to_urls[i];
 		gchar *from_s[3] = { NULL, NULL, NULL };
@@ -777,12 +809,14 @@
 		hildon_thumbnail_util_get_thumb_paths (from_uri, &from_s[0], 
 						       &from_s[1], 
 						       &from_s[2],
-						       NULL, NULL, NULL);
+						       NULL, NULL, NULL,
+						       (y == 0));
 
 		hildon_thumbnail_util_get_thumb_paths (to_uri, &to_s[0], 
 						       &to_s[1], 
 						       &to_s[2],
-						       NULL, NULL, NULL);
+						       NULL, NULL, NULL,
+						       (y == 0));
 
 		for (n = 0; n<3; n++) {
 			GFile *from, *to;
@@ -810,8 +844,8 @@
 			g_free (from_s[n]);
 			g_free (to_s[n]);
 		}
-
-		i++;
+	  }
+	  i++;
 	}
 
 	dbus_g_method_return (context);
@@ -827,7 +861,8 @@
 	keep_alive ();
 
 	while (urls[i] != NULL) {
-
+	  guint y = 0;
+	  for (y = 0; i < 2; y++ ) {
 		const gchar *uri = urls[i];
 		gchar *normal = NULL, 
 		      *large = NULL, 
@@ -836,7 +871,8 @@
 		hildon_thumbnail_util_get_thumb_paths (uri, &large, 
 						       &normal, 
 						       &cropped,
-						       NULL, NULL, NULL);
+						       NULL, NULL, NULL,
+						       (y == 0));
 
 		g_unlink (large);
 		g_unlink (normal);
@@ -845,8 +881,8 @@
 		g_free (normal);
 		g_free (large);
 		g_free (cropped);
-
-		i++;
+	  }
+	  i++;
 	}
 
 	dbus_g_method_return (context);

Modified: projects/haf/trunk/hildon-thumbnail/daemon/utils.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/utils.c	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/daemon/utils.c	2008-11-03 10:48:08 UTC (rev 16555)
@@ -28,7 +28,7 @@
 
 
 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)
+hildon_thumbnail_util_get_thumb_paths (const gchar *uri, gchar **large, gchar **normal, gchar **cropped, gchar **local_large, gchar **local_normal, gchar **local_cropped, gboolean as_png)
 {
 	gchar *ascii_digest, *filename = NULL;
 	gchar *lascii_digest = NULL;
@@ -47,7 +47,7 @@
 
 		if (ptr) {
 			*ptr = '\0';
-			local_dir = g_build_filename ("%s/.thumblocal", uri_t);
+			local_dir = g_strdup_printf ("%s/.thumblocal", uri_t);
 		}
 
 		g_free (uri_t);
@@ -91,9 +91,14 @@
 
 	ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
 
-	thumb_filename = g_strdup_printf ("%s.png", ascii_digest);
+	if (as_png)
+		thumb_filename = g_strdup_printf ("%s.png", ascii_digest);
+	else
+		thumb_filename = g_strdup_printf ("%s.jpeg", ascii_digest);
+
 	cropped_filename = g_strdup_printf ("%s.jpeg", ascii_digest);
 
+
 	*large = g_build_filename (large_dir, thumb_filename, NULL);
 	*normal = g_build_filename (normal_dir, thumb_filename, NULL);
 	*cropped = g_build_filename (cropped_dir, cropped_filename, NULL);
@@ -104,7 +109,10 @@
 			gchar *lcropped_filename;
 
 			lascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, filename, -1);
-			lthumb_filename = g_strdup_printf ("%s.png", lascii_digest);
+			if (as_png)
+				lthumb_filename = g_strdup_printf ("%s.png", lascii_digest);
+			else
+				lthumb_filename = g_strdup_printf ("%s.jpeg", lascii_digest);
 			lcropped_filename = g_strdup_printf ("%s.jpeg", lascii_digest);
 
 			if (local_large)

Modified: projects/haf/trunk/hildon-thumbnail/daemon/utils.h
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/utils.h	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/daemon/utils.h	2008-11-03 10:48:08 UTC (rev 16555)
@@ -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, gchar **local_large, gchar **local_normal, gchar **local_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, gboolean as_png);
 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-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c	2008-11-03 10:48:08 UTC (rev 16555)
@@ -206,14 +206,36 @@
 
 	if (item) {
 			gchar *large = NULL, *normal = NULL, *cropped = NULL;
+			gchar *path;
 
 			/* Get the large small and cropped path for the original
 			 * URI */
 			
 			hildon_thumbnail_util_get_thumb_paths (item->uri, &large, 
 												   &normal, &cropped,
-												   NULL, NULL, NULL);
+												   NULL, NULL, NULL,
+												   FALSE);
 
+			if (item->flags & HILDON_THUMBNAIL_FLAG_CROP) {
+				path = cropped;
+			} else if (item->width >= 128) {
+				path = large;
+			} else {
+				path = normal;
+			}
+
+			if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
+
+				g_free (large); large = NULL;
+				g_free (normal); normal = NULL;
+				g_free (cropped); cropped = NULL;
+
+				hildon_thumbnail_util_get_thumb_paths (item->uri, &large, 
+												   &normal, &cropped,
+												   NULL, NULL, NULL,
+												   TRUE);
+			}
+
 			create_pixbuf_and_callback (item, large, normal, cropped, FALSE);
 
 			g_free (cropped);
@@ -434,20 +456,43 @@
 				gpointer user_data, 
 				HildonThumbnailFlags flags, ...)
 {
-	gchar *large, *normal, *cropped;
-	gchar *local_large, *local_normal, *local_cropped;
+	gchar *large = NULL, *normal = NULL, *cropped = NULL;
+	gchar *local_large = NULL, *local_normal = NULL, *local_cropped = NULL;
 	ThumbsItem *item;
 	GStrv uris;
 	GStrv mimes;
 	gboolean have_all = FALSE;
+	guint y = 0;
 
 	g_return_val_if_fail(uri != NULL && mime_type != NULL && callback != NULL,
 			     NULL);
 
-	hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
-								&cropped, &local_large, 
-								&local_normal, &local_cropped);
+	for (y = 0; y < 2; y++) {
 
+		g_free (normal); normal = NULL;
+		g_free (large); large = NULL;
+		g_free (cropped); cropped = NULL;
+		g_free (local_normal); local_normal = NULL;
+		g_free (local_large); local_large = NULL;
+		g_free (local_cropped); local_cropped = NULL;
+
+		hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
+									&cropped, &local_large, 
+									&local_normal, &local_cropped,
+									(y == 1));
+
+		if (flags & HILDON_THUMBNAIL_FLAG_CROP) {
+			if (g_file_test (cropped, G_FILE_TEST_EXISTS))
+				break;
+		} else if (width >= 128) {
+			if (g_file_test (large, G_FILE_TEST_EXISTS))
+				break;
+		} else {
+			if (g_file_test (normal, G_FILE_TEST_EXISTS))
+				break;
+		}
+	}
+
 	if (flags & HILDON_THUMBNAIL_FLAG_RECREATE) {
 		g_unlink (large);
 		g_unlink (normal);
@@ -772,7 +817,7 @@
 
 	hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, 
 								&cropped, &local_large, 
-								&local_normal, &local_cropped);
+								&local_normal, &local_cropped, FALSE);
 
 	if (is_cropped) {
 

Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c	2008-11-01 21:12:50 UTC (rev 16554)
+++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c	2008-11-03 10:48:08 UTC (rev 16555)
@@ -391,19 +391,33 @@
 	HildonThumbnailRequestPrivate *r_priv = REQUEST_GET_PRIVATE (request);
 	HildonThumbnailFactoryPrivate *f_priv = FACTORY_GET_PRIVATE (self);
 	guint i;
-	gboolean have = TRUE;
+	gboolean have = FALSE;
 	GStrv mime_types = NULL;
+	guint y;
 
-	hildon_thumbnail_util_get_thumb_paths (uri, &r_priv->paths[0], 
-					       &r_priv->paths[1], 
-					       &r_priv->paths[2],
-					       &r_priv->lpaths[0],
-					       &r_priv->lpaths[1],
-					       &r_priv->lpaths[2]);
+	for (y = 0 ; y < 2 && !have; y++ ) {
 
-	for (i = 0; i< 3 && have; i++) {
-		have = (g_file_test (r_priv->paths[i], G_FILE_TEST_EXISTS) || 
-			g_file_test (r_priv->lpaths[i], G_FILE_TEST_EXISTS));
+		have = TRUE;
+
+		g_free (r_priv->paths[0]); r_priv->paths[0] = NULL;
+		g_free (r_priv->paths[1]); r_priv->paths[1] = NULL;
+		g_free (r_priv->paths[2]); r_priv->paths[2] = NULL;
+		g_free (r_priv->lpaths[0]); r_priv->lpaths[0] = NULL;
+		g_free (r_priv->lpaths[1]); r_priv->lpaths[1] = NULL;
+		g_free (r_priv->lpaths[2]); r_priv->lpaths[2] = NULL;
+
+		hildon_thumbnail_util_get_thumb_paths (uri, &r_priv->paths[0], 
+						       &r_priv->paths[1], 
+						       &r_priv->paths[2],
+						       &r_priv->lpaths[0],
+						       &r_priv->lpaths[1],
+						       &r_priv->lpaths[2], 
+						       (y==1));
+
+		for (i = 0; i < 3 && have; i++) {
+			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);


More information about the maemo-commits mailing list