[tracker] tracker-miner-fs: moved in tracker-albumart code from libtracker-common



commit 61faac23aad8c7c44846fa90f4b476a368114dcf
Author: Martyn Russell <martyn imendio com>
Date:   Mon Jul 27 16:23:53 2009 +0100

    tracker-miner-fs: moved in tracker-albumart code from libtracker-common
    
    All the code in libtracker-common/tracker-albumart.[ch] which was used
    from multiple places is only used in miner-fs now so I moved the
    functions into the tracker-miner-fs/tracker-albumart.[ch] and removed
    the libtracker-common module.

 src/libtracker-common/Makefile.am               |    4 +-
 src/libtracker-common/tracker-albumart.c        |  793 ----------------------
 src/libtracker-common/tracker-albumart.h        |   57 --
 src/tracker-miner-fs/tracker-albumart.c         |  815 ++++++++++++++++++++++-
 tests/libtracker-common/Makefile.am             |   12 -
 tests/libtracker-common/tracker-albumart-test.c |  256 -------
 utils/Makefile.am                               |    1 -
 utils/albumart/.gitignore                       |    1 -
 utils/albumart/Makefile.am                      |   18 -
 utils/albumart/albumart-strip.c                 |   91 ---
 10 files changed, 789 insertions(+), 1259 deletions(-)
---
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am
index 893a704..1c25ffc 100644
--- a/src/libtracker-common/Makefile.am
+++ b/src/libtracker-common/Makefile.am
@@ -75,7 +75,6 @@ libtracker_common_la_SOURCES =	 			\
 	tracker-type-utils.c				\
 	tracker-utils.c					\
 	tracker-thumbnailer.c				\
-	tracker-albumart.c				\
 	libtracker-common.vala.stamp			\
 	$(libtracker_common_la_VALASOURCES:.vala=.c)
 
@@ -86,8 +85,7 @@ noinst_HEADERS =					\
 	tracker-ioprio.h				\
 	tracker-log.h					\
 	tracker-os-dependant.h				\
-	tracker-thumbnailer.h				\
-	tracker-albumart.h
+	tracker-thumbnailer.h
 
 libtracker_commoninclude_HEADERS =			\
 	tracker-config-file.h				\
diff --git a/src/tracker-miner-fs/tracker-albumart.c b/src/tracker-miner-fs/tracker-albumart.c
index b0d1375..c31612c 100644
--- a/src/tracker-miner-fs/tracker-albumart.c
+++ b/src/tracker-miner-fs/tracker-albumart.c
@@ -30,24 +30,36 @@
 #include <glib.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
-
 #include <gio/gio.h>
 
 #ifdef HAVE_GDKPIXBUF
 #include <gdk-pixbuf/gdk-pixbuf.h>
-#endif
+#endif /* HAVE_GDKPIXBUF */
+
+#include <dbus/dbus-glib-bindings.h>
 
 #include <libtracker-common/tracker-thumbnailer.h>
-#include <libtracker-common/tracker-albumart.h>
 
 #include "tracker-albumart.h"
-#include "tracker-dbus.h"
 #include "tracker-marshal.h"
 
-static gboolean initialized;
-static GHashTable *albumart_cache;
-static TrackerStorage *albumart_storage;
+#define ALBUMARTER_SERVICE      "com.nokia.albumart"
+#define ALBUMARTER_PATH         "/com/nokia/albumart/Requester"
+#define ALBUMARTER_INTERFACE    "com.nokia.albumart.Requester"
+
+#define THUMBNAILER_SERVICE     "org.freedesktop.thumbnailer"
+#define THUMBNAILER_PATH        "/org/freedesktop/thumbnailer/Generic"
+#define THUMBNAILER_INTERFACE   "org.freedesktop.thumbnailer.Generic"
 
+typedef struct {
+	TrackerStorage *hal;
+	gchar *art_path;
+	gchar *local_uri;
+} GetFileInfo;
+
+static void     albumart_queue_cb   (DBusGProxy          *proxy,
+				     DBusGProxyCall      *call,
+				     gpointer             user_data);
 static gboolean albumart_process_cb (DBusGProxy          *proxy,
 				     const unsigned char *buffer,
 				     size_t               len,
@@ -57,6 +69,574 @@ static gboolean albumart_process_cb (DBusGProxy          *proxy,
 				     const gchar         *filename,
 				     gpointer             user_data);
 
+
+static gboolean initialized;
+static GHashTable *albumart_cache;
+static TrackerStorage *albumart_storage;
+static gboolean no_more_requesting;
+static DBusGProxy *albumart_proxy;
+
+#ifndef HAVE_STRCASESTR
+
+static gchar *
+strcasestr (const gchar *haystack, 
+	    const gchar *needle)
+{
+	gchar *p;
+	gchar *startn = NULL;
+	gchar *np = NULL;
+
+	for (p = (gchar *) haystack; *p; p++) {
+		if (np) {
+			if (toupper (*p) == toupper (*np)) {
+				if (!*++np) {
+					return startn;
+				}
+			} else {
+				np = 0;
+			}
+		} else if (toupper (*p) == toupper (*needle)) {
+			np = (gchar *) needle + 1;
+			startn = p;
+		}
+	}
+
+	return NULL;
+}
+
+#endif /* HAVE_STRCASESTR */
+
+/* NOTE: This function was stolen from GLib 2.18.x. Since upstream and
+ * the Maemo branch don't have this in circulation yet, we have copied
+ * it here. This can be removed an replaced with
+ * g_file_make_directory_with_parents() when we get it. -mr
+ */
+static gboolean
+make_directory_with_parents (GFile         *file,
+			     GCancellable  *cancellable,
+			     GError       **error)
+{
+	gboolean result;
+	GFile *parent_file, *work_file;
+	GList *list = NULL, *l;
+	GError *my_error = NULL;
+
+	if (g_cancellable_set_error_if_cancelled (cancellable, error))
+		return FALSE;
+
+	result = g_file_make_directory (file, cancellable, &my_error);
+	if (result || my_error->code != G_IO_ERROR_NOT_FOUND)
+	{
+		if (my_error)
+			g_propagate_error (error, my_error);
+		return result;
+	}
+
+	work_file = file;
+
+	while (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
+	{
+		g_clear_error (&my_error);
+
+		parent_file = g_file_get_parent (work_file);
+		if (parent_file == NULL)
+			break;
+		result = g_file_make_directory (parent_file, cancellable, &my_error);
+
+		if (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
+			list = g_list_prepend (list, parent_file);
+
+		work_file = parent_file;
+	}
+
+	for (l = list; result && l; l = l->next)
+	{
+		result = g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
+	}
+
+	/* Clean up */
+	while (list != NULL)
+	{
+		g_object_unref ((GFile *) list->data);
+		list = g_list_remove (list, list->data);
+	}
+
+	if (!result)
+	{
+		g_propagate_error (error, my_error);
+		return result;
+	}
+
+	return g_file_make_directory (file, cancellable, error);
+}
+
+static gboolean
+albumart_strip_find_next_block (const gchar    *original,
+				const gunichar  open_char,
+				const gunichar  close_char,
+				gint           *open_pos,
+				gint           *close_pos)
+{
+	const gchar *p1, *p2;
+
+	if (open_pos) {
+		*open_pos = -1;
+	}
+
+	if (close_pos) {
+		*close_pos = -1;
+	}
+
+	p1 = g_utf8_strchr (original, -1, open_char);
+	if (p1) {
+		if (open_pos) {
+			*open_pos = p1 - original;
+		}
+
+		p2 = g_utf8_strchr (g_utf8_next_char (p1), -1, close_char);
+		if (p2) {
+			if (close_pos) {
+				*close_pos = p2 - original;
+			}
+			
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
+static gchar *
+albumart_strip_invalid_entities (const gchar *original)
+{
+	GString         *str_no_blocks;
+	gchar          **strv;
+	gchar           *str;
+	gboolean         blocks_done = FALSE;
+	const gchar     *p;
+	const gchar     *invalid_chars = "()[]<>{}_! #$^&*+=|\\/\"'?~";
+	const gchar     *invalid_chars_delimiter = "*";
+	const gchar     *convert_chars = "\t";
+	const gchar     *convert_chars_delimiter = " ";
+	const gunichar   blocks[5][2] = {
+		{ '(', ')' },
+		{ '{', '}' }, 
+		{ '[', ']' }, 
+		{ '<', '>' }, 
+		{  0,   0  }
+	};
+
+	str_no_blocks = g_string_new ("");
+
+	p = original;
+
+	while (!blocks_done) {
+		gint pos1, pos2, i;
+
+		pos1 = -1;
+		pos2 = -1;
+	
+		for (i = 0; blocks[i][0] != 0; i++) {
+			gint start, end;
+			
+			/* Go through blocks, find the earliest block we can */
+			if (albumart_strip_find_next_block (p, blocks[i][0], blocks[i][1], &start, &end)) {
+				if (pos1 == -1 || start < pos1) {
+					pos1 = start;
+					pos2 = end;
+				}
+			}
+		}
+		
+		/* If either are -1 we didn't find any */
+		if (pos1 == -1) {
+			/* This means no blocks were found */
+			g_string_append (str_no_blocks, p);
+			blocks_done = TRUE;
+		} else {
+			/* Append the test BEFORE the block */
+                        if (pos1 > 0) {
+                                g_string_append_len (str_no_blocks, p, pos1);
+                        }
+
+                        p = g_utf8_next_char (p + pos2);
+
+			/* Do same again for position AFTER block */
+			if (*p == '\0') {
+				blocks_done = TRUE;
+			}
+		}	
+	}
+
+	/* Now convert chars to lower case */
+	str = g_utf8_strdown (str_no_blocks->str, -1);
+	g_string_free (str_no_blocks, TRUE);
+
+	/* Now strip invalid chars */
+	g_strdelimit (str, invalid_chars, *invalid_chars_delimiter);
+	strv = g_strsplit (str, invalid_chars_delimiter, -1);
+	g_free (str);
+        str = g_strjoinv (NULL, strv);
+	g_strfreev (strv);
+
+	/* Now convert chars */
+	g_strdelimit (str, convert_chars, *convert_chars_delimiter);
+	strv = g_strsplit (str, convert_chars_delimiter, -1);
+	g_free (str);
+        str = g_strjoinv (convert_chars_delimiter, strv);
+	g_strfreev (strv);
+
+        /* Now remove double spaces */
+	strv = g_strsplit (str, "  ", -1);
+	g_free (str);
+        str = g_strjoinv (" ", strv);
+	g_strfreev (strv);
+        
+        /* Now strip leading/trailing white space */
+        g_strstrip (str);
+
+	return str;
+}
+
+static gchar *
+albumart_checksum_for_data (GChecksumType  checksum_type,
+			    const guchar  *data,
+			    gsize          length)
+{
+	GChecksum *checksum;
+	gchar *retval;
+	
+	checksum = g_checksum_new (checksum_type);
+	if (!checksum) {
+		return NULL;
+	}
+	
+	g_checksum_update (checksum, data, length);
+	retval = g_strdup (g_checksum_get_string (checksum));
+	g_checksum_free (checksum);
+	
+	return retval;
+}
+
+static void
+albumart_get_path (const gchar  *artist, 
+		   const gchar  *album, 
+		   const gchar  *prefix, 
+		   const gchar  *uri,
+		   gchar       **path,
+		   gchar       **local_uri)
+{
+	gchar *art_filename;
+	gchar *dir;
+	gchar *artist_down, *album_down;
+	gchar *artist_stripped, *album_stripped;
+	gchar *artist_checksum, *album_checksum;
+
+	/* g_return_if_fail ((local_uri != NULL && uri != NULL) || local_uri == NULL); */
+	/* g_return_if_fail (artist != NULL || album != NULL); */
+
+	/* http://live.gnome.org/MediaArtStorageSpec */
+
+	if (path) {
+		*path = NULL;
+	}
+
+	if (local_uri) {
+		*local_uri = NULL;
+	}
+
+	if (!artist && !album) {
+		return;
+	}
+
+	if (!artist) {
+		artist_stripped = g_strdup (" ");
+	} else {
+		artist_stripped = albumart_strip_invalid_entities (artist);
+	}
+
+	if (!album) {
+		album_stripped = g_strdup (" ");
+	} else {
+		album_stripped = albumart_strip_invalid_entities (album); 
+	}
+
+	artist_down = g_utf8_strdown (artist_stripped, -1);
+	album_down = g_utf8_strdown (album_stripped, -1);
+
+	g_free (artist_stripped);
+	g_free (album_stripped);
+
+	dir = g_build_filename (g_get_user_cache_dir (), 
+				"media-art", 
+				NULL);
+
+	if (!g_file_test (dir, G_FILE_TEST_EXISTS)) {
+		g_mkdir_with_parents (dir, 0770);
+	}
+
+	artist_checksum = albumart_checksum_for_data (G_CHECKSUM_MD5, 
+						      (const guchar *) artist_down, 
+						      strlen (artist_down));
+	album_checksum = albumart_checksum_for_data (G_CHECKSUM_MD5, 
+						     (const guchar *) album_down, 
+						     strlen (album_down));
+	
+	g_free (artist_down);
+	g_free (album_down);
+
+	art_filename = g_strdup_printf ("%s-%s-%s.jpeg", 
+					prefix ? prefix : "album", 
+					artist_checksum, 
+					album_checksum);
+
+	if (path) {
+		*path = g_build_filename (dir, art_filename, NULL);
+	}
+
+	if (local_uri) {
+		gchar *local_dir;
+		GFile *file, *parent;
+
+		if (strstr (uri, "://")) {
+			file = g_file_new_for_uri (uri);
+		} else {
+			file = g_file_new_for_path (uri); 
+		}
+
+		parent = g_file_get_parent (file);
+		local_dir = g_file_get_uri (parent);
+
+		/* This is a URI, don't use g_build_filename here */
+		*local_uri = g_strdup_printf ("%s/.mediaartlocal/%s", local_dir, art_filename);
+
+		g_free (local_dir);
+		g_object_unref (file);
+		g_object_unref (parent);
+	}
+
+	g_free (dir);
+	g_free (art_filename);
+	g_free (artist_checksum);
+	g_free (album_checksum);
+}
+
+
+static gboolean 
+albumart_heuristic (const gchar *artist,  
+		    const gchar *album, 
+		    const gchar *filename,
+		    const gchar *local_uri,
+		    gboolean    *copied)
+{
+	GFile *file, *dirf;
+	GDir *dir;
+	struct stat st;
+	gchar *target = NULL;
+	gchar *dirname;
+	const gchar *name;
+	gboolean retval;
+	gint count;
+	gchar *artist_stripped = NULL;
+	gchar *album_stripped = NULL;
+
+	g_return_val_if_fail (artist != NULL, FALSE);
+	g_return_val_if_fail (album != NULL, FALSE);
+	g_return_val_if_fail (filename != NULL, FALSE);
+
+	if (copied) {
+		*copied = FALSE;
+	}
+
+	if (artist) {
+		artist_stripped = albumart_strip_invalid_entities (artist);
+	}
+
+	if (album) {
+		album_stripped = albumart_strip_invalid_entities (album);
+	}
+
+	/* Copy from local album art (.mediaartlocal) to spec */
+	if (local_uri) {
+		GFile *local_file;
+		
+		local_file = g_file_new_for_uri (local_uri);
+		
+		if (g_file_query_exists (local_file, NULL)) {
+			albumart_get_path (artist_stripped, 
+					   album_stripped, 
+					   "album", NULL, 
+					   &target, NULL);
+			if (target) {
+				file = g_file_new_for_path (target);
+				
+				g_file_copy_async (local_file, file, 0, 0, 
+						   NULL, NULL, NULL, NULL, NULL);
+				
+				g_object_unref (file);
+			}
+			g_object_unref (local_file);
+			
+			if (copied) {
+				*copied = TRUE;
+			}
+
+			g_free (target);
+			g_free (artist_stripped);
+			g_free (album_stripped);
+			
+			return TRUE;
+		}
+		
+		g_object_unref (local_file);
+	}
+
+	file = g_file_new_for_path (filename);
+	dirf = g_file_get_parent (file);
+	dirname = g_file_get_path (dirf);
+	g_object_unref (file);
+	g_object_unref (dirf);
+
+	if (!dirname) {
+		g_free (artist_stripped);
+		g_free (album_stripped);
+
+		return FALSE;
+	}
+
+	dir = g_dir_open (dirname, 0, NULL);
+
+	if (!dir) {
+		g_free (artist_stripped);
+		g_free (album_stripped);
+		g_free (dirname);
+
+		return FALSE;
+	}
+
+	retval = FALSE;
+	file = NULL;
+
+	if (g_stat (dirname, &st) == -1) {
+		g_warning ("Could not g_stat() directory:'%s' for albumart heuristic",
+			   dirname);
+
+		g_free (dirname);
+		g_free (artist_stripped);
+		g_free (album_stripped);
+
+		return FALSE;
+	}
+
+	/* do not count . and .. */
+	count = st.st_nlink - 2;
+	
+	/* If amount of files and amount of tracks in the album somewhat match */
+
+	if (count >= 2 && count < 50) {
+		gchar *found = NULL;
+
+		/* Try to find cover art in the directory */
+		for (name = g_dir_read_name (dir); name; name = g_dir_read_name (dir)) {
+			if ((artist_stripped && strcasestr (name, artist_stripped)) || 
+			    (album_stripped && strcasestr (name, album_stripped))   || 
+			    (strcasestr (name, "cover"))) {
+				GError *error = NULL;
+				
+				if (g_str_has_suffix (name, "jpeg") || 
+				    g_str_has_suffix (name, "jpg")) {
+					if (!target) {
+						albumart_get_path (artist_stripped,
+								   album_stripped, 
+								   "album", 
+								   NULL, 
+								   &target, 
+								   NULL);
+					}
+					
+					if (!file && target) {
+						file = g_file_new_for_path (target);
+					}
+
+					if (file) {
+						GFile *file_found;
+
+						found = g_build_filename (dirname, name, NULL);
+						file_found = g_file_new_for_path (found);
+						g_file_copy (file_found, file, 0, NULL, NULL, NULL, &error);
+
+						if (!error) {
+							retval = TRUE;
+						} else {
+							g_error_free (error);
+							error = NULL;
+							retval = FALSE;
+						}
+						
+						g_free (found);
+						g_object_unref (file_found);
+					}
+				} else {
+#ifdef HAVE_GDKPIXBUF
+					if (g_str_has_suffix (name, "png")) {
+						GdkPixbuf *pixbuf;
+						
+						found = g_build_filename (dirname, name, NULL);
+						pixbuf = gdk_pixbuf_new_from_file (found, &error);
+						
+						if (error) {
+							g_error_free (error);
+							error = NULL;
+							retval = FALSE;
+						} else {
+							if (!target) {
+								albumart_get_path (artist_stripped, 
+										   album_stripped, 
+										   "album", 
+										   NULL, 
+										   &target, 
+										   NULL);
+							}
+							
+							gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL);
+							
+							if (!error) {
+								retval = TRUE;
+							} else {
+								g_error_free (error);
+								retval = FALSE;
+							}
+						}
+						
+						g_free (found);
+					}
+#else  /* HAVE_GDKPIXBUF */
+					retval = FALSE;
+#endif /* HAVE_GDKPIXBUF */
+				}
+
+				if (retval) {
+					break;
+				}
+			}
+		}
+		
+	}
+	
+	g_dir_close (dir);
+	
+	if (file) {
+		g_object_unref (file);
+	}
+
+	g_free (target);
+	g_free (dirname);
+	g_free (artist_stripped);
+	g_free (album_stripped);
+
+	return retval;
+}
+
 #ifdef HAVE_GDKPIXBUF
 
 static gboolean
@@ -74,7 +654,7 @@ albumart_set (const unsigned char *buffer,
 		return FALSE;
 	}
 
-	tracker_albumart_get_path (artist, album, "album", NULL, &local_path, NULL);
+	albumart_get_path (artist, album, "album", NULL, &local_path, NULL);
 
 	g_message ("Saving album art using GdkPixbuf for uri:'%s'", 
 		   local_path);
@@ -131,6 +711,125 @@ albumart_set (const unsigned char *buffer,
 
 #endif /* HAVE_GDKPIXBUF */
 
+static void
+albumart_request_download (TrackerStorage *hal,
+			   const gchar    *album, 
+			   const gchar    *artist, 
+			   const gchar    *local_uri, 
+			   const gchar    *art_path)
+{
+	GetFileInfo *info;
+
+	if (no_more_requesting) {
+		return;
+	}
+
+	info = g_slice_new (GetFileInfo);
+
+#ifdef HAVE_HAL
+	info->hal = hal ? g_object_ref (hal) : NULL;
+#else 
+	info->hal = NULL;
+#endif
+
+	info->local_uri = g_strdup (local_uri);
+	info->art_path = g_strdup (art_path);
+
+	if (!albumart_proxy) {
+		GError          *error = NULL;
+		DBusGConnection *connection;
+
+		connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+		if (!error) {
+			albumart_proxy = dbus_g_proxy_new_for_name (connection,
+								    ALBUMARTER_SERVICE,
+								    ALBUMARTER_PATH,
+								    ALBUMARTER_INTERFACE);
+		} else {
+			g_error_free (error);
+		}
+	}
+
+	dbus_g_proxy_begin_call (albumart_proxy,
+				 "Queue",
+				 albumart_queue_cb,
+				 info, 
+				 NULL,
+				 G_TYPE_STRING, artist,
+				 G_TYPE_STRING, album,
+				 G_TYPE_STRING, "album",
+				 G_TYPE_UINT, 0,
+				 G_TYPE_INVALID);
+}
+
+static void
+albumart_copy_to_local (TrackerStorage *hal,
+			const gchar    *filename, 
+			const gchar    *local_uri)
+{
+	GList *removable_roots, *l;
+	gboolean on_removable_device = FALSE;
+	guint flen;
+
+	g_return_if_fail (filename != NULL);
+	g_return_if_fail (local_uri != NULL);
+
+	flen = strlen (filename);
+
+	/* Determining if we are on a removable device */
+#ifdef HAVE_HAL
+	g_return_if_fail (hal != NULL);
+
+	removable_roots = tracker_storage_get_removable_device_roots (hal);
+#else
+	removable_roots = g_list_append (removable_roots, "/media");
+	removable_roots = g_list_append (removable_roots, "/mnt");
+#endif
+
+	for (l = removable_roots; l; l = l->next) {
+		guint len;
+		
+		len = strlen (l->data);
+
+		if (flen >= len && strncmp (filename, l->data, len)) {
+			on_removable_device = TRUE;
+			break;
+		}
+	}
+
+#ifdef HAVE_HAL
+	g_list_foreach (removable_roots, (GFunc) g_free, NULL);
+#endif
+
+	g_list_free (removable_roots);
+
+	if (on_removable_device) {
+		GFile *local_file, *from;
+
+		from = g_file_new_for_path (filename);
+		local_file = g_file_new_for_uri (local_uri);
+
+		/* We don't try to overwrite, but we also ignore all errors.
+		 * Such an error could be that the removable device is 
+		 * read-only. Well that's fine then ... ignore */
+
+		if (!g_file_query_exists (local_file, NULL)) {
+			GFile *dirf;
+
+			dirf = g_file_get_parent (local_file);
+			make_directory_with_parents (dirf, NULL, NULL);
+			g_object_unref (dirf);
+
+			g_file_copy_async (from, local_file, 0, 0, 
+					   NULL, NULL, NULL, NULL, NULL);
+		}
+
+		g_object_unref (local_file);
+		g_object_unref (from);
+	}
+}
+
 static gboolean
 albumart_process_cb (DBusGProxy          *proxy,
 		     const unsigned char *buffer,
@@ -154,12 +853,12 @@ albumart_process_cb (DBusGProxy          *proxy,
 		filename_uri = g_filename_to_uri (filename, NULL, NULL);
 	}
 
-	tracker_albumart_get_path (artist, 
-				   album, 
-				   "album", 
-				   filename_uri, 
-				   &art_path, 
-				   &local_uri);
+	albumart_get_path (artist, 
+			   album, 
+			   "album", 
+			   filename_uri, 
+			   &art_path, 
+			   &local_uri);
 
 	if (!art_path) {
 		g_warning ("Albumart path could not be obtained, not processing any further");
@@ -201,21 +900,21 @@ albumart_process_cb (DBusGProxy          *proxy,
 			g_free (dirname);
 
 			if (!g_hash_table_lookup (albumart_cache, key)) {
-				if (!tracker_albumart_heuristic (artist, 
-								 album, 
-					                         filename, 
-					                         local_uri, 
-					                         NULL)) {
+				if (!albumart_heuristic (artist, 
+							 album, 
+							 filename, 
+							 local_uri, 
+							 NULL)) {
 					/* If the heuristic failed, we
 					 * request the download the
 					 * media-art to the media-art
 					 * downloaders
 					 */
-					tracker_albumart_request_download (albumart_storage, 
-									   artist,
-									   album,
-									   local_uri,
-									   art_path);
+					albumart_request_download (albumart_storage, 
+								   artist,
+								   album,
+								   local_uri,
+								   art_path);
 				}
 
 				g_hash_table_insert (albumart_cache, 
@@ -241,9 +940,9 @@ albumart_process_cb (DBusGProxy          *proxy,
 		 * situation might have changed
 		 */
 		if (g_file_test (art_path, G_FILE_TEST_EXISTS)) {
-			tracker_albumart_copy_to_local (albumart_storage,
-							art_path, 
-							local_uri);
+			albumart_copy_to_local (albumart_storage,
+						art_path, 
+						local_uri);
 		}
 	}
 
@@ -254,6 +953,54 @@ albumart_process_cb (DBusGProxy          *proxy,
 	return processed;
 }
 
+static void
+albumart_queue_cb (DBusGProxy     *proxy,
+		   DBusGProxyCall *call,
+		   gpointer	   user_data)
+{
+	GError      *error = NULL;
+	guint        handle;
+	GetFileInfo *info;
+
+	info = user_data;
+
+	dbus_g_proxy_end_call (proxy, call, &error,
+			       G_TYPE_UINT, &handle,
+			       G_TYPE_INVALID);
+
+	if (error) {
+		if (error->code == DBUS_GERROR_SERVICE_UNKNOWN) {
+			no_more_requesting = TRUE;
+		} else {
+			g_warning ("%s", error->message);
+		}
+
+		g_clear_error (&error);
+	}
+
+	if (info->hal && info->art_path &&
+	    g_file_test (info->art_path, G_FILE_TEST_EXISTS)) {
+		gchar *uri;
+		
+		uri = g_filename_to_uri (info->art_path, NULL, NULL);
+		tracker_thumbnailer_queue_add (uri, "image/jpeg");
+		g_free (uri);
+
+		albumart_copy_to_local (info->hal,
+					info->art_path, 
+					info->local_uri);
+	}
+
+	g_free (info->art_path);
+	g_free (info->local_uri);
+
+	if (info->hal) {
+		g_object_unref (info->hal);
+	}
+
+	g_slice_free (GetFileInfo, info);
+}
+
 gboolean
 tracker_albumart_init (TrackerStorage *storage)
 {
@@ -320,6 +1067,14 @@ tracker_albumart_init (TrackerStorage *storage)
                                      NULL,
                                      NULL);
 
+	/* Get album art downloader proxy */
+	albumart_proxy = dbus_g_proxy_new_for_name (connection,
+						    ALBUMARTER_SERVICE,
+						    ALBUMARTER_PATH,
+						    ALBUMARTER_INTERFACE);
+
+	initialized = TRUE;
+
 	return TRUE;
 }
 
@@ -337,4 +1092,10 @@ tracker_albumart_shutdown (void)
 		g_object_unref (albumart_storage);
 	}
 #endif /* HAVE_HAL */
+
+	if (albumart_proxy) {
+		g_object_unref (albumart_proxy);
+	}
+
+	initialized = FALSE;
 }
diff --git a/tests/libtracker-common/Makefile.am b/tests/libtracker-common/Makefile.am
index 00702e5..3cb8775 100644
--- a/tests/libtracker-common/Makefile.am
+++ b/tests/libtracker-common/Makefile.am
@@ -18,7 +18,6 @@ TEST_PROGS += 								\
 	tracker-dbus 							\
 	tracker-type-utils 						\
 	tracker-file-utils						\
-	tracker-albumart						\
 	tracker-thumbnailer
 
 INCLUDES = 								\
@@ -93,17 +92,6 @@ tracker_file_utils_LDADD =						\
 # 	$(PANGO_LIBS)							\
 # 	$(GLIB2_LIBS)							
 
-tracker_albumart_SOURCES = 						\
-	tracker-albumart-test.c 
-
-tracker_albumart_LDADD =						\
-	$(top_builddir)/src/libtracker-common/libtracker-common.la 	\
-	$(top_builddir)/tests/common/libtracker-testcommon.la 		\
-	$(GMODULE_LIBS)							\
-	$(GCOV_LIBS)							\
-	$(GTHREAD_LIBS)							\
-	$(GLIB2_LIBS)							
-
 tracker_thumbnailer_SOURCES = 						\
 	tracker-thumbnailer-test.c					\
 	mock-dbus-gproxy.c						\
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 0f2ec1b..fe3bece 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -1,7 +1,6 @@
 include $(top_srcdir)/Makefile.decl
 
 SUBDIRS = 			\
-	albumart		\
 	services		\
 	playlists		\
 	tracker-fts



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]