[maemo-commits] [maemo-commits] r16388 - in projects/haf/trunk/hildon-thumbnail: . albumart-providers/googleimages daemon

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Oct 14 13:36:19 EEST 2008
Author: pvanhoof
Date: 2008-10-14 13:36:17 +0300 (Tue, 14 Oct 2008)
New Revision: 16388

Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   projects/haf/trunk/hildon-thumbnail/albumart-providers/googleimages/google-images-art-downloader.vala
   projects/haf/trunk/hildon-thumbnail/daemon/albumart.c
   projects/haf/trunk/hildon-thumbnail/daemon/albumart.h
   projects/haf/trunk/hildon-thumbnail/daemon/albumart.xml
   projects/haf/trunk/hildon-thumbnail/daemon/utils.c
   projects/haf/trunk/hildon-thumbnail/daemon/utils.h
Log:
2008-10-14  Philip Van Hoof  <philip at codeminded.be>

	* albumart-providers/googleimages/google-images-art-downloader.vala
	* daemon/utils.c
	* daemon/utils.h
	* daemon/albumart.c
	* daemon/albumart.h
	* daemon/albumart.xml: Support for the new mediaart storage spec:
	http://live.gnome.org/MediaArtStorageSpec. Note that this spec is
	still very volatile.



Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-10-13 13:46:43 UTC (rev 16387)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-10-14 10:36:17 UTC (rev 16388)
@@ -1,3 +1,14 @@
+2008-10-14  Philip Van Hoof  <philip at codeminded.be>
+
+	* albumart-providers/googleimages/google-images-art-downloader.vala
+	* daemon/utils.c
+	* daemon/utils.h
+	* daemon/albumart.c
+	* daemon/albumart.h
+	* daemon/albumart.xml: Support for the new mediaart storage spec:
+	http://live.gnome.org/MediaArtStorageSpec. Note that this spec is
+	still very volatile.
+
 2008-10-08  Philip Van Hoof  <philip at codeminded.be>
 
 	* thumbs/hildon-thumbnail-obj.c: Memory leak oeps, fix

Modified: projects/haf/trunk/hildon-thumbnail/albumart-providers/googleimages/google-images-art-downloader.vala
===================================================================
--- projects/haf/trunk/hildon-thumbnail/albumart-providers/googleimages/google-images-art-downloader.vala	2008-10-13 13:46:43 UTC (rev 16387)
+++ projects/haf/trunk/hildon-thumbnail/albumart-providers/googleimages/google-images-art-downloader.vala	2008-10-14 10:36:17 UTC (rev 16388)
@@ -4,7 +4,7 @@
 
 [DBus (name = "com.nokia.albumart.Provider")]
 public interface Provider {
-	public abstract void Fetch (string artist, string album, string uri);
+	public abstract void Fetch (string artist, string album, string kind);
 }
 
 // Sample implementation of com.nokia.albumart.Provider that uses Google 
@@ -14,12 +14,21 @@
 
 public class GoogleImages : Object, Provider {
 
-	public void Fetch (string artist, string album, string uri) {
+	public void Fetch (string artist, string album, string kind) {
 		uint u = 0, hread = 0;
 		string [] pieces = artist.split (" ", -1);
 		string stitched = "";
 		bool first = true;
 
+		if (kind == null)
+			kind = "album";
+
+		if (album == null)
+			album = "";
+
+		if (artist == null)
+			artist = "";
+
 		// Convert the album and artist into something that will work for Google images
 
 		while (pieces[u] != null) {
@@ -79,14 +88,14 @@
 
 				string cache_path;
 
-				string cache_dir = Path.build_filename (Environment.get_home_dir(),
-								  ".album_art",
+				string cache_dir = Path.build_filename (Environment.get_user_cache_dir(),
+								  "media-art",
 								  null);
 
 				// Define cache path = ~/.album_art/MD5 (down (albumartist)).jpeg
 
-				cache_path = Path.build_filename (Environment.get_home_dir(),
-								  ".album_art",
+				cache_path = Path.build_filename (Environment.get_user_cache_dir(),
+								  "media-art", kind + "-" +
 								  Checksum.compute_for_string (
 										   ChecksumType.MD5, 
 										   (artist + " " + album).down (), 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/albumart.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/albumart.c	2008-10-13 13:46:43 UTC (rev 16387)
+++ projects/haf/trunk/hildon-thumbnail/daemon/albumart.c	2008-10-14 10:36:17 UTC (rev 16388)
@@ -75,7 +75,7 @@
 typedef struct {
 	Albumart *object;
 	gchar *album, *artist;
-	gchar *uri;
+	gchar *kind;
 	guint num;
 	gboolean unqueued;
 } WorkTask;
@@ -112,22 +112,22 @@
 }
 
 void
-albumart_queue (Albumart *object, gchar *artist, gchar *album, gchar *uri, guint handle_to_unqueue, DBusGMethodInvocation *context)
+albumart_queue (Albumart *object, gchar *artist_or_title, gchar *album, gchar *kind, guint handle_to_unqueue, DBusGMethodInvocation *context)
 {
 	AlbumartPrivate *priv = ALBUMART_GET_PRIVATE (object);
 	WorkTask *task;
 	static guint num = 0;
 
-	if (uri && strlen (uri) <= 0)
-		uri = NULL;
+	if (!kind)
+		kind = "album";
 
-	if (artist && strlen (artist) <= 0)
-		artist = NULL;
+	if (artist_or_title && strlen (artist_or_title) <= 0)
+		artist_or_title = NULL;
 
 	if (album && strlen (album) <= 0)
 		album = NULL;
 
-	if (!uri && (!album || !artist)) {
+	if (!artist_or_title && !album) {
 		num++;
 		dbus_g_method_return (context, num);
 		return;
@@ -141,11 +141,9 @@
 	task->num = ++num;
 	task->object = g_object_ref (object);
 
-	if (album && artist) {
-		task->album = g_strdup (album);
-		task->artist = g_strdup (artist);
-	} if (uri)
-		task->uri = g_strdup (uri);
+	task->album = g_strdup (album);
+	task->artist = g_strdup (artist_or_title);
+	task->kind = g_strdup (kind);
 
 	g_mutex_lock (priv->mutex);
 	g_list_foreach (priv->tasks, (GFunc) mark_unqueued, (gpointer) handle_to_unqueue);
@@ -217,12 +215,12 @@
 	AlbumartPrivate *priv = ALBUMART_GET_PRIVATE (task->object);
 	gchar *artist = task->artist;
 	gchar *album = task->album;
-	gchar *uri = task->uri;
+	gchar *kind = task->kind;
 	gchar *path;
 
 	g_mutex_lock (priv->mutex);
 	priv->tasks = g_list_remove (priv->tasks, task);
-	if (task->unqueued || (!uri && (!album && !artist))) {
+	if (task->unqueued) {
 		g_mutex_unlock (priv->mutex);
 		goto unqueued;
 	}
@@ -231,94 +229,45 @@
 	g_signal_emit (task->object, signals[STARTED_SIGNAL], 0,
 			task->num);
 
-	hildon_thumbnail_util_get_albumart_path (artist, album, uri, &path);
+	hildon_thumbnail_util_get_albumart_path (artist, album, kind, &path);
 
 	if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
+		GList *proxies, *copy;
 		gboolean handled = FALSE;
-		GFile *file = g_file_new_for_uri (task->uri);
-		gchar *dpath = g_file_get_path (file);
 
-		// TODO: Perform copy from embedded (in uri) to path
+		proxies = albumart_manager_get_handlers (priv->manager);
+		copy = proxies;
 
-		g_object_unref (file);
+		while (copy && !handled) {
+			DBusGProxy *proxy = copy->data;
+			GError *error = NULL;
 
-		if (dpath) {
-			gchar *dirn = g_path_get_dirname (dpath);
-			GDir *dir = g_dir_open (dirn, 0, NULL);
+			keep_alive ();
 
-			if (dir) {
-				gchar *image;
+			dbus_g_proxy_call (proxy, "Fetch", &error, 
+					   G_TYPE_STRING, artist,
+					   G_TYPE_STRING, album,
+					   G_TYPE_STRING, kind,
+					   G_TYPE_INVALID, 
+					   G_TYPE_INVALID);
 
-				image = find_image_file_in_for (dir, album);
-				if (!image)
-					image = find_image_file_in_for (dir, artist);
-				if (!image)
-					image = find_image_file_in_for (dir, "cover");
-				if (!image)
-					image = find_image_file_in_for (dir, "front");
-				if (!image)
-					image = find_image_file_in_for (dir, "album");
-				if (!image)
-					image = find_image_file_in_for (dir, "");
+			keep_alive ();
 
-				if (image) {
-					GFile *image_file = g_file_new_for_path (image);
-					GFile *cache_file = g_file_new_for_path (path);
-					g_file_copy (image_file, cache_file, 
-						     G_FILE_COPY_NONE, 
-						     NULL, NULL, NULL, NULL);
-					handled = TRUE;
-					g_object_unref (image_file);
-					g_object_unref (cache_file);
-					g_free (image);
-				}
-
-				g_dir_close (dir);
+			if (error) {
+				g_signal_emit (task->object, signals[ERROR_SIGNAL],
+					       0, task->num, 1, error->message);
+				g_clear_error (&error);
+			} else {
+					g_signal_emit (task->object, signals[READY_SIGNAL], 
+					       0, artist, album, kind, path);
+				handled = TRUE;
 			}
-			g_free (dirn);
-			g_free (dpath);
-		}
-		
-		// TODO: Perform heuristics from uri to path
 
-		if (!handled) {
-			GList *proxies, *copy;
-			gboolean handled = FALSE;
+			copy = g_list_next (copy);
 
-			proxies = albumart_manager_get_handlers (priv->manager);
-			copy = proxies;
-
-			while (copy && !handled) {
-				DBusGProxy *proxy = copy->data;
-				GError *error = NULL;
-
-				keep_alive ();
-
-				dbus_g_proxy_call (proxy, "Fetch", &error, 
-						   G_TYPE_STRING, artist,
-						   G_TYPE_STRING, album,
-						   G_TYPE_STRING, uri,
-						   G_TYPE_INVALID, 
-						   G_TYPE_INVALID);
-
-				keep_alive ();
-
-				if (error) {
-					g_signal_emit (task->object, signals[ERROR_SIGNAL],
-						       0, task->num, 1, error->message);
-					g_clear_error (&error);
-				} else {
-					g_signal_emit (task->object, signals[READY_SIGNAL], 
-						       0, artist, album, uri, path);
-					handled = TRUE;
-				}
-
-				copy = g_list_next (copy);
-			} 
-
-			g_list_foreach (proxies, (GFunc) g_object_unref, NULL);
-			if (proxies)
-				g_list_free (proxies);
+		g_list_foreach (proxies, (GFunc) g_object_unref, NULL);
+		if (proxies)
+			g_list_free (proxies);
 		}
 	}
 
@@ -332,7 +281,7 @@
 	g_object_unref (task->object);
 	g_free (task->artist);
 	g_free (task->album);
-	g_free (task->uri);
+	g_free (task->kind);
 	g_slice_free (WorkTask, task);
 
 	return;
@@ -340,13 +289,13 @@
 
 
 void
-albumart_delete (Albumart *object, gchar *artist, gchar *album, gchar *uri, DBusGMethodInvocation *context)
+albumart_delete (Albumart *object, gchar *artist_or_title, gchar *album, gchar *kind, DBusGMethodInvocation *context)
 {
 	gchar *path;
 
 	keep_alive ();
 
-	hildon_thumbnail_util_get_albumart_path (artist, album, uri, &path);
+	hildon_thumbnail_util_get_albumart_path (artist_or_title, album, kind, &path);
 
 	g_unlink (path);
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/albumart.h
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/albumart.h	2008-10-13 13:46:43 UTC (rev 16387)
+++ projects/haf/trunk/hildon-thumbnail/daemon/albumart.h	2008-10-14 10:36:17 UTC (rev 16388)
@@ -57,9 +57,9 @@
 
 GType albumart_get_type (void);
 
-void albumart_queue (Albumart *object, gchar *artist, gchar *album, gchar *uri, guint handle_to_unqueue, DBusGMethodInvocation *context);
+void albumart_queue (Albumart *object, gchar *artist_or_title, gchar *album, gchar *kind, guint handle_to_unqueue, DBusGMethodInvocation *context);
 void albumart_unqueue (Albumart *object, guint handle, DBusGMethodInvocation *context);
-void albumart_delete (Albumart *object, gchar *artist, gchar *album, gchar *uri, DBusGMethodInvocation *context);
+void albumart_delete (Albumart *object, gchar *artist_or_title, gchar *album, gchar *kind, DBusGMethodInvocation *context);
 
 void albumart_do_stop (void);
 void albumart_do_init (DBusGConnection *connection, AlbumartManager *manager, Albumart **albumart, GError **error);

Modified: projects/haf/trunk/hildon-thumbnail/daemon/albumart.xml
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/albumart.xml	2008-10-13 13:46:43 UTC (rev 16387)
+++ projects/haf/trunk/hildon-thumbnail/daemon/albumart.xml	2008-10-14 10:36:17 UTC (rev 16388)
@@ -4,9 +4,9 @@
 
     <method name="Queue">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <arg type="s" name="artist" direction="in" />
+      <arg type="s" name="artist_or_title" direction="in" />
       <arg type="s" name="album" direction="in" />
-      <arg type="s" name="uri" direction="in" />
+      <arg type="s" name="kind" direction="in" />
       <arg type="u" name="handle_to_unqueue" direction="in" />
       <arg type="u" name="handle" direction="out" />
     </method>
@@ -39,9 +39,9 @@
 
     <method name="Delete">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <arg type="s" name="artist" direction="in" />
+      <arg type="s" name="artist_or_title" direction="in" />
       <arg type="s" name="album" direction="in" />
-      <arg type="s" name="uri" direction="in" />
+      <arg type="s" name="kind" direction="in" />
     </method>
 
   </interface>

Modified: projects/haf/trunk/hildon-thumbnail/daemon/utils.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/utils.c	2008-10-13 13:46:43 UTC (rev 16387)
+++ projects/haf/trunk/hildon-thumbnail/daemon/utils.c	2008-10-14 10:36:17 UTC (rev 16388)
@@ -75,29 +75,36 @@
 
 
 void
-hildon_thumbnail_util_get_albumart_path (const gchar *artist, const gchar *album, const gchar *uri, gchar **path)
+hildon_thumbnail_util_get_albumart_path (const gchar *a, const gchar *b, const gchar *prefix, gchar **path)
 {
 	gchar *art_filename, *str;
 	static gchar *dir = NULL;
-	gchar *down;
-	
-	if (album && artist) {
-		gchar *_tmp14, *_tmp13;
-		down = g_utf8_strdown (_tmp14 = (g_strconcat ((_tmp13 = g_strconcat (artist, " ", NULL)), album, NULL)),-1);
-		g_free (_tmp14);
-		g_free (_tmp13);
-	} else if (uri)
-		down = g_strdup (uri);
-	else {
+	gchar *_tmp14, *_tmp13, *down;
+
+	if (!prefix)
+		prefix = "album";
+
+	if (!a && !b) {
 		*path = NULL;
 		return;
 	}
 
+	if (!a)
+		a = "";
+
+	if (!b)
+		b = "";
+
+	down = g_utf8_strdown (_tmp14 = (g_strconcat ((_tmp13 = g_strconcat (a, " ", NULL)), b, NULL)),-1);
+
+	g_free (_tmp14);
+	g_free (_tmp13);
+
 	/* I know we leak, but it's better than doing memory fragementation on 
 	 * these strings ... */
 
 	if (!dir)
-		dir = g_build_filename (g_get_home_dir (), ".album_art", NULL);
+		dir = g_build_filename (g_get_user_cache_dir (), "media-art", NULL);
 
 	*path = NULL;
 
@@ -106,7 +113,7 @@
 
 	str = g_compute_checksum_for_string (G_CHECKSUM_MD5, down, -1);
 
-	art_filename = g_strdup_printf ("%s.jpeg", str);
+	art_filename = g_strdup_printf ("%s-%s.jpeg", prefix, str);
 
 	*path = g_build_filename (dir, art_filename, NULL);
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/utils.h
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/utils.h	2008-10-13 13:46:43 UTC (rev 16387)
+++ projects/haf/trunk/hildon-thumbnail/daemon/utils.h	2008-10-14 10:36:17 UTC (rev 16388)
@@ -29,7 +29,7 @@
 #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_albumart_path (const gchar *artist, const gchar *album, const gchar *uri, gchar **path);
+void hildon_thumbnail_util_get_albumart_path (const gchar *a, const gchar *b, const gchar *prefix, gchar **path);
 
 #ifndef g_sprintf
 gint g_sprintf (gchar *string, gchar const *format, ...);


More information about the maemo-commits mailing list