tracker r2554 - in trunk: . src/tracker-extract src/tracker-indexer tests/tracker-indexer thumbnailers/image



Author: pvanhoof
Date: Mon Nov 24 12:57:41 2008
New Revision: 2554
URL: http://svn.gnome.org/viewvc/tracker?rev=2554&view=rev

Log:
2008-11-24  Philip Van Hoof  <philip codeminded be>

	* src/tracker-extract/tracker-albumart.c: Requesting thumbnails of 
	album art

	* src/tracker-indexer/tracker-metadata-utils.c
	* src/tracker-indexer/tracker-main.c
	* src/tracker-indexer/tracker-indexer.c
	* src/tracker-indexer/Makefile.am
	* src/tracker-extract/Makefile.am
	* thumbnailers/image/Makefile.am
	* tests/tracker-indexer/Makefile.am
	* configure.ac
	* src/tracker-indexer/tracker-thumbnailer.c
	* src/tracker-indexer/tracker-thumbnailer.h: Cleaning up thumbnails when
	originals are removed. Refactored the thumbnailing code



Added:
   trunk/src/tracker-indexer/tracker-thumbnailer.c
   trunk/src/tracker-indexer/tracker-thumbnailer.h
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/tracker-extract/Makefile.am
   trunk/src/tracker-indexer/Makefile.am
   trunk/src/tracker-indexer/tracker-indexer.c
   trunk/src/tracker-indexer/tracker-main.c
   trunk/src/tracker-indexer/tracker-metadata-utils.c
   trunk/tests/tracker-indexer/Makefile.am
   trunk/thumbnailers/image/Makefile.am

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Mon Nov 24 12:57:41 2008
@@ -101,6 +101,7 @@
 LIBEXIF_REQUIRED=0.6
 LIBGSF_REQUIRED=1.13
 EXEMPI_REQUIRED=1.99.2
+HILDON_THUMBNAIL_REQUIRED=3.0.10
 
 # Library Checks
 PKG_CHECK_MODULES(GLIB2, [glib-2.0 >= $GLIB_REQUIRED])
@@ -1039,33 +1040,6 @@
 
 AM_CONDITIONAL(HAVE_EXEMPI, test "x$have_exempi" = "xyes")
 
-##################################################################
-# Check for Imagemagick
-##################################################################
-
-AC_ARG_ENABLE(imagemagick, 
-              AS_HELP_STRING([--disable-imagemagick], 
-	                     [disable thumbnailing with Imagemagick]),,
-	      [enable_imagemagick=no])
-
-if test "x$enable_imagemagic" != "xno" ; then
-   AC_CHECK_PROG(have_imagemagick, convert, "yes", "no",)
-
-   if test "x$have_imagemagick" = "xyes" ; then
-      AC_DEFINE(HAVE_IMAGEMAGICK, 1, [Define if we have imagemagick])
-   fi
-else
-   have_imagemagick="no  (disabled)"
-fi
-
-if test "x$enable_imagemagick" = "xyes"; then
-   if test "x$have_imagemagick" != "xyes"; then
-      AC_MSG_ERROR([Couldn't find imagemagick.])
-   fi
-fi
-
-AM_CONDITIONAL(HAVE_IMAGEMAGICK, test "x$have_imagemagick" = "xyes")
-
 ####################################################################
 # Checking totem-pl-parser
 ####################################################################
@@ -1099,42 +1073,6 @@
 
 AM_CONDITIONAL(HAVE_TOTEM_PL_PARSER, test "x$have_playlist" = "xyes")
 
-####################################################################
-# Check for Hildon-thumbnail
-####################################################################
-
-AC_ARG_ENABLE(hildon-thumbnail, 
-              AS_HELP_STRING([--disable-hildon-thumbnail], 
-	                     [disable thumbnailing with Hildon]),,
-	      [enable_hildon_thumbnail=auto])
-
-if test "x$enable_hildon_thumbnail" != "xno" ; then
-   hildon_thumbnail_pkgconfig_tmp="hildon-thumbnail"
-   PKG_CHECK_MODULES(HILDON_THUMBNAIL, 
-                     $hildon_thumbnail_pkgconfig_tmp,  
-                     [have_hildon_thumbnail=yes], 
-                     [have_hildon_thumbnail=no])
-
-   AC_SUBST(HILDON_THUMBNAIL_CFLAGS)
-   AC_SUBST(HILDON_THUMBNAIL_LIBS)
-
-   if test "x$have_hildon_thumbnail" = "xyes" ; then
-   AC_CHECK_PROG(have_hildon_thumbnail_gdk_pixbuf, hildon-thumb-gdk-pixbuf, "yes", "no",)
-
-      if test "x$have_hildon_thumbnail_gdk_pixbuf" != "xyes" ; then
-      have_hildon_thumbnail="no"      
-   fi
-   fi
-
-   if test "x$have_hildon_thumbnail" = "xyes" ; then
-      AC_DEFINE(HAVE_HILDON_THUMBNAIL, 1, [Define if we have hildon-thumbnail])
-   fi
-else
-   have_hildon_thumbnail="no  (disabled)"
-fi
-
-AM_CONDITIONAL(HAVE_HILDON_THUMBNAIL, test "x$have_hildon_thumbnail" = "xyes")
-
 ##################################################################
 # Enable SQLite FTS support?
 ##################################################################
@@ -1176,6 +1114,8 @@
                 tests/tracker-indexer/tracker-module-file.h:src/tracker-indexer/tracker-module-file.h
                 tests/tracker-indexer/tracker-module-iteratable.c:src/tracker-indexer/tracker-module-iteratable.c
                 tests/tracker-indexer/tracker-module-iteratable.h:src/tracker-indexer/tracker-module-iteratable.h
+		tests/tracker-indexer/tracker-thumbnailer.h:src/tracker-indexer/tracker-thumbnailer.h
+		tests/tracker-indexer/tracker-thumbnailer.c:src/tracker-indexer/tracker-thumbnailer.c
 )
 
 ##################################################################
@@ -1334,11 +1274,6 @@
 	Support MP3 album art (w/ GdkPixbuf):	$have_gdkpixbuf
 	Support Playlists (w/ Totem):           $have_playlist
 
-Thumbnailers:
-
-	Have Imagemagick			$have_imagemagick
-	Have hildon-thumbnail			$have_hildon_thumbnail
-
 Warning:
 
         You must make sure SQLite is compiled with --enable-threadsafe

Modified: trunk/src/tracker-extract/Makefile.am
==============================================================================
--- trunk/src/tracker-extract/Makefile.am	(original)
+++ trunk/src/tracker-extract/Makefile.am	Mon Nov 24 12:57:41 2008
@@ -32,9 +32,9 @@
 	libextract-ps.la 						
 
 
-if HAVE_IMAGEMAGICK
-modules_LTLIBRARIES += libextract-imagemagick.la
-endif
+# if HAVE_IMAGEMAGICK
+# modules_LTLIBRARIES += libextract-imagemagick.la
+# endif
 
 if HAVE_EXEMPI
 modules_LTLIBRARIES += libextract-xmp.la
@@ -106,9 +106,9 @@
 libextract_abw_la_LIBADD = $(GLIB2_LIBS)
 
 # Imagemagick
-libextract_imagemagick_la_SOURCES = tracker-extract-imagemagick.c $(xmp_sources)
-libextract_imagemagick_la_LDFLAGS = $(module_flags)
-libextract_imagemagick_la_LIBADD = $(GLIB2_LIBS) $(EXEMPI_LIBS)
+# libextract_imagemagick_la_SOURCES = tracker-extract-imagemagick.c $(xmp_sources)
+# libextract_imagemagick_la_LDFLAGS = $(module_flags)
+# libextract_imagemagick_la_LIBADD = $(GLIB2_LIBS) $(EXEMPI_LIBS)
 
 # MP3
 libextract_mp3_la_SOURCES = tracker-extract-mp3.c $(albumart_sources)

Modified: trunk/src/tracker-indexer/Makefile.am
==============================================================================
--- trunk/src/tracker-indexer/Makefile.am	(original)
+++ trunk/src/tracker-indexer/Makefile.am	Mon Nov 24 12:57:41 2008
@@ -39,7 +39,9 @@
 	tracker-indexer-module.c					\
 	tracker-indexer-module.h					\
 	tracker-main.c							\
-	tracker-marshal-main.c
+	tracker-marshal-main.c						\
+	tracker-thumbnailer.c						\
+	tracker-thumbnailer.h
 
 tracker_indexer_LDADD =							\
 	libtracker-indexer.la						\

Modified: trunk/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-indexer.c	(original)
+++ trunk/src/tracker-indexer/tracker-indexer.c	Mon Nov 24 12:57:41 2008
@@ -74,6 +74,7 @@
 #include "tracker-indexer.h"
 #include "tracker-indexer-module.h"
 #include "tracker-marshal.h"
+#include "tracker-thumbnailer.h"
 
 #define TRACKER_INDEXER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_INDEXER, TrackerIndexerPrivate))
 
@@ -1463,6 +1464,7 @@
 	gchar *new_path, *new_name, *ext;
 	GFile *file, *other_file;
 	gchar *path, *other_path;
+	gchar *uri, *other_uri, *mime_type;
 	guint32 id;
 
 	service = get_service_for_file (info->other_module_file, info->module);
@@ -1474,8 +1476,21 @@
 	path = g_file_get_path (info->file);
 	other_path = g_file_get_path (info->other_file);
 
+
 	g_debug ("Moving item from '%s' to '%s'", path, other_path);
 
+	/* TODO URI branch: these are URI conversions */
+
+	uri = g_file_get_uri (info->file);
+	other_uri = g_file_get_uri (info->other_file);
+
+	mime_type = tracker_file_get_mime_type (path);
+	tracker_thumbnailer_move (uri, mime_type, other_uri);
+
+	g_free (mime_type);
+	g_free (other_uri);
+	g_free (uri);
+
 	/* Get 'source' ID */
 	if (!tracker_data_query_service_exists (service,
 				       dirname,
@@ -1534,7 +1549,11 @@
 	     const gchar    *basename)
 {
 	TrackerService *service;
-	gchar *content, *metadata;
+	GFile *file;
+	gchar *content;
+	gchar *metadata;
+	gchar *uri;
+	gchar *mime_type;
 	gchar *service_path;
 	const gchar *service_type;
 	guint service_id, service_type_id;
@@ -1545,6 +1564,29 @@
 		 dirname, 
 		 basename);
 
+	/* TODO URI branch: this is a URI conversion */
+	service_path = g_build_path (G_DIR_SEPARATOR_S, 
+				     dirname, 
+				     basename, 
+				     NULL);
+
+	file = g_file_new_for_path (service_path);
+	uri = g_file_get_uri (file);
+	g_object_unref (file);
+
+	/* This is done this way to minimize merging work for URI
+	 * branch (I know the exact same thing is being done later in
+	 * the code. there are no caveats, you can just replace this
+	 * while merging, indeed).
+	 */
+	mime_type = tracker_file_get_mime_type (service_path);
+
+	tracker_thumbnailer_remove (uri, mime_type);
+
+	g_free (mime_type);
+	g_free (uri);
+	g_free (service_path); 
+
 	if (!service_type || !service_type[0]) {
 		const gchar *name;
 

Modified: trunk/src/tracker-indexer/tracker-main.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-main.c	(original)
+++ trunk/src/tracker-indexer/tracker-main.c	Mon Nov 24 12:57:41 2008
@@ -41,9 +41,11 @@
 #include <libtracker-db/tracker-db-manager.h>
 #include <libtracker-db/tracker-db-index-manager.h>
 
+#include <libtracker-data/tracker-data-update.h>
+
 #include "tracker-dbus.h"
 #include "tracker-indexer.h"
-#include <libtracker-data/tracker-data-update.h>
+#include "tracker-thumbnailer.h"
 
 #define ABOUT								  \
 	"Tracker " PACKAGE_VERSION "\n"					  \
@@ -358,6 +360,9 @@
 			  G_CALLBACK (indexer_finished_cb),
 			  NULL);
 
+        /* Set up connections to the thumbnailer if supported */
+        tracker_thumbnailer_init ();
+
 	if (process_all) {
 		/* Tell the indexer to process all configured modules */
 		tracker_indexer_process_all (indexer);
@@ -380,6 +385,7 @@
 	g_object_unref (indexer);
 	g_object_unref (config);
 
+        tracker_thumbnailer_shutdown ();
 	tracker_dbus_shutdown ();
 	tracker_db_index_manager_shutdown ();
 	tracker_db_manager_shutdown ();

Modified: trunk/src/tracker-indexer/tracker-metadata-utils.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-metadata-utils.c	(original)
+++ trunk/src/tracker-indexer/tracker-metadata-utils.c	Mon Nov 24 12:57:41 2008
@@ -31,7 +31,7 @@
 #include <libtracker-common/tracker-ontology.h>
 
 #include "tracker-metadata-utils.h"
-#include "tracker-dbus.h"
+#include "tracker-thumbnailer.h"
 
 #define METADATA_FILE_NAME_DELIMITED "File:NameDelimited"
 #define METADATA_FILE_EXT	     "File:Ext"
@@ -47,11 +47,6 @@
 #define TEXT_MAX_SIZE		     1048576  /* bytes */
 #define TEXT_CHECK_SIZE		     65535    /* bytes */
 
-static gchar   *batch[51] = { 0 };
-static gchar   *hints[51] = { 0 };
-static guint    count = 0;
-static gboolean timeout_runs = FALSE;
-
 typedef struct {
 	GPid pid;
 	guint stdout_watch_id;
@@ -61,9 +56,6 @@
 	gpointer data;
 } ProcessContext;
 
-static void get_file_thumbnail (const gchar *path,
-				const gchar *mime);
-
 static ProcessContext *metadata_context = NULL;
 
 static void
@@ -645,174 +637,6 @@
 	return s ? g_string_free (s, FALSE) : NULL;
 }
 
-#ifdef HAVE_HILDON_THUMBNAIL
-
-static void
-get_file_thumbnail_queue_cb (DBusGProxy     *proxy,
-			     DBusGProxyCall *call,
-			     gpointer	     user_data)
-{
-	GError *error = NULL;
-	guint	handle;
-
-	/* FIXME: What is the point of this? */
-	dbus_g_proxy_end_call (proxy, call, &error,
-			       G_TYPE_UINT, &handle,
-			       G_TYPE_INVALID);
-
-	if (error) {
-		g_warning ("%s", error->message);
-		g_error_free (error);
-	}
-}
-
-static gboolean
-thumbnail_this (GStrv list, const gchar *mime)
-{
-	guint i = 0;
-	gboolean retval = FALSE;
-
-	if (!list)
-		return TRUE;
-
-	while (list[i] != NULL && !retval) {
-		if (g_ascii_strcasecmp (list[i], mime) == 0)
-			retval = TRUE;
-		i++;
-	}
-
-	return retval;
-
-}
-
-static gboolean
-request_thumbnails (gpointer data)
-{
-	if (timeout_runs) {
-		guint i;
-
-		timeout_runs = FALSE;
-		batch[count] = NULL;
-		hints[count] = NULL;
-
-		g_debug ("Requesting thumbnails");
-
-		dbus_g_proxy_begin_call (tracker_dbus_get_thumbnailer (),
-					 "Queue",
-					 get_file_thumbnail_queue_cb,
-					 NULL, NULL,
-					 G_TYPE_STRV, batch,
-					 G_TYPE_STRV, hints,
-					 G_TYPE_UINT, 0,
-					 G_TYPE_INVALID);
-
-		for (i = 0; i <= count; i++) {
-			g_free (batch[i]);
-			g_free (hints[i]);
-			batch[i] = NULL;
-			hints[i] = NULL;
-		}
-
-		count = 0;
-	}
-
-	return FALSE;
-}
-
-#endif /* HAVE_HILDON_THUMBNAIL */
-
-static void
-get_file_thumbnail (const gchar *path,
-		    const gchar *mime)
-{
-#ifdef HAVE_HILDON_THUMBNAIL
-
-	static gboolean tried = FALSE;
-
-
-	/* It's known that this relatively small GStrv is leaked */
-	static GStrv    thumbnailable = NULL;
-
-	if (!tried) {
-		GStrv mimes = NULL;
-		GError *error = NULL;
-
-		dbus_g_proxy_call (tracker_dbus_get_thumb_manager(),
-				   "GetSupported", &error, G_TYPE_INVALID,
-				   G_TYPE_STRV, &mimes, G_TYPE_INVALID);
-		if (error)
-			g_error_free (error);
-		else if (mimes)
-			thumbnailable = mimes;
-		tried = TRUE;
-	}
-
-	if (count < 50 && thumbnail_this (thumbnailable, mime)) {
-		gchar *utf_path;
-
-		utf_path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
-
-		if (utf_path) {
-			batch[count] = g_strdup_printf ("file://%s", utf_path);
-			if (mime)
-				hints[count] = g_strdup (mime);
-			else 
-				hints[count] = g_strdup ("unknown/unknown");
-			g_free (utf_path);
-			count++;
-		}
-
-		if (!timeout_runs) {
-			timeout_runs = TRUE;
-			g_timeout_add_seconds (30, request_thumbnails, NULL);
-		}
-	}
-
-	if (count == 50) {
-		request_thumbnails (NULL);
-	}
-#endif /* HAVE_HILDON_THUMBNAIL */
-
-#ifdef HAVE_IMAGEMAGICK
-	ProcessContext *context;
-
-	GString *thumbnail;
-	gchar *argv[5];
-
-	argv[0] = g_strdup (LIBEXEC_PATH G_DIR_SEPARATOR_S "tracker-thumbnailer");
-	argv[1] = g_filename_from_utf8 (path, -1, NULL, NULL, NULL);
-	argv[2] = g_strdup (mime);
-	argv[3] = g_strdup ("normal");
-	argv[4] = NULL;
-
-	context = process_context_create ((const gchar **) argv,
-					  get_file_content_read_cb);
-
-	if (!context) {
-		return;
-	}
-
-	thumbnail = g_string_new (NULL);
-	context->data = thumbnail;
-
-	g_main_loop_run (context->data_incoming_loop);
-
-	g_free (argv[0]);
-	g_free (argv[1]);
-	g_free (argv[2]);
-	g_free (argv[3]);
-
-	if (!thumbnail->str || !*thumbnail->str) {
-		g_string_free (thumbnail, TRUE);
-		return;
-	}
-
-	g_debug ("Got thumbnail '%s' for '%s'", thumbnail->str, path);
-
-	g_string_free (thumbnail, TRUE);
-#endif /* HAVE_IMAGEMAGICK */
-}
-
 static gchar *
 get_file_content_by_filter (const gchar *path,
 			    const gchar *mime)
@@ -932,7 +756,8 @@
 	ext = strrchr (path, '.');
 
 	if (ext) {
-		tracker_data_metadata_insert (metadata, METADATA_FILE_EXT, g_strdup (ext + 1));
+		ext++;
+		tracker_data_metadata_insert (metadata, METADATA_FILE_EXT, g_strdup (ext));
 	}
 
 	mime_type = tracker_file_get_mime_type (path);
@@ -947,11 +772,11 @@
 				      mime_type);
 
 	if (mime_type) {
-		/* FIXME:
-		 * We should determine here for which items we do and for which
-		 * items we don't want to pre-create the thumbnail. */
+		gchar *uri;
 
-		get_file_thumbnail (path, mime_type);
+		uri = g_file_get_uri (file);
+		tracker_thumbnailer_get_file_thumbnail (uri, mime_type);
+		g_free (uri);
 	}
 
 	if (S_ISLNK (st.st_mode)) {

Added: trunk/src/tracker-indexer/tracker-thumbnailer.c
==============================================================================
--- (empty file)
+++ trunk/src/tracker-indexer/tracker-thumbnailer.c	Mon Nov 24 12:57:41 2008
@@ -0,0 +1,382 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "tracker-dbus.h"
+
+/* Undef this to disable thumbnailing (don't remove unless you
+ * understand that that either you need to put in place another method
+ * to disable/enable this and that what will be used by the packager
+ * is probably *your* default, or unless you want to break expected
+ * functionality on-purpose) (It's not the first time that these
+ * ifdef-else-endifs where rewrapped incorrectly, and that way
+ * obviously broke the feature)
+ */
+
+#ifndef THUMBNAILING_OVER_DBUS
+#define THUMBNAILING_OVER_DBUS
+#endif 
+
+#ifdef THUMBNAILING_OVER_DBUS
+
+#define THUMBNAIL_REQUEST_LIMIT 50
+
+typedef struct {
+	GStrv     supported_mime_types;
+
+	gchar    *uris[THUMBNAIL_REQUEST_LIMIT + 1];
+	gchar    *mime_types[THUMBNAIL_REQUEST_LIMIT + 1];
+
+	guint     request_id;
+	guint     count;
+	guint     timeout_id;
+
+	gboolean  service_is_prepared;
+} TrackerThumbnailerPrivate;
+
+static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
+
+static void
+private_free (gpointer data)
+{
+	TrackerThumbnailerPrivate *private;
+	gint i;
+
+	private = data;
+	
+	g_strfreev (private->supported_mime_types);
+
+	for (i = 0; i <= private->count; i++) {
+		g_free (private->uris[i]);
+		g_free (private->mime_types[i]);
+	}
+
+	if (private->timeout_id) {
+		g_source_remove (private->timeout_id);
+	}
+
+	g_free (private);
+}
+
+static gboolean
+should_be_thumbnailed (GStrv        list, 
+		       const gchar *mime)
+{
+	gboolean should_thumbnail;
+	guint i;
+
+	if (!list) {
+		return TRUE;
+	}
+
+	for (should_thumbnail = FALSE, i = 0; 
+	     should_thumbnail == FALSE && list[i] != NULL; 
+	     i++) {
+		if (g_ascii_strcasecmp (list[i], mime) == 0) {
+			should_thumbnail = TRUE;
+		}
+	}
+
+	return should_thumbnail;
+}
+
+static void
+thumbnailer_reply_cb (DBusGProxy     *proxy,
+		      DBusGProxyCall *call,
+		      gpointer	      user_data)
+{
+	GError *error = NULL;
+	guint	handle;
+
+	/* The point of this is dbus-glib correctness. Answering this
+	 * because this comment used to be the question: what is the
+	 * point of this. It's correct this way because we do
+	 * asynchronous DBus calls using glib-dbus. For asynchronous
+	 * DBus calls it's recommended (if not required for cleaning
+	 * up) to call dbus_g_proxy_end_call.
+	 */
+	dbus_g_proxy_end_call (proxy, call, &error,
+			       G_TYPE_UINT, &handle,
+			       G_TYPE_INVALID);
+
+	if (error) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+		return;
+	}
+
+	g_message ("Received response from thumbnailer, request ID:%d",
+		   GPOINTER_TO_UINT (user_data));
+}
+
+static gboolean
+thumbnailer_request_timeout_cb (gpointer data)
+{
+	TrackerThumbnailerPrivate *private;
+	guint i;
+
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, FALSE);
+
+	private->request_id++;
+
+	private->uris[private->count] = NULL;
+	private->mime_types[private->count] = NULL;
+	
+	g_message ("Sending request to thumbnailer to queue %d files, request ID:%d...", 
+		   private->count,
+		   private->request_id);
+	
+	dbus_g_proxy_begin_call (tracker_dbus_get_thumbnailer (),
+				 "Queue",
+				 thumbnailer_reply_cb,
+				 GUINT_TO_POINTER (private->request_id), 
+				 NULL,
+				 G_TYPE_STRV, private->uris,
+				 G_TYPE_STRV, private->mime_types,
+				 G_TYPE_UINT, 0,
+				 G_TYPE_INVALID);
+	
+	for (i = 0; i <= private->count; i++) {
+		g_free (private->uris[i]);
+		g_free (private->mime_types[i]);
+		private->uris[i] = NULL;
+		private->mime_types[i] = NULL;
+	}
+	
+	private->count = 0;
+	private->timeout_id = 0;
+
+	return FALSE;
+}
+
+static void
+thumbnailer_prepare (void)
+{
+	TrackerThumbnailerPrivate *private;
+	GStrv mime_types = NULL;
+	GError *error = NULL;
+
+	private = g_static_private_get (&private_key);
+	
+	if (private->service_is_prepared) {
+		return;
+	}
+
+	/* It's known that this relatively small GStrv is leaked: it contains
+	 * the MIME types that the DBus thumbnailer supports. If a MIME type
+	 * is not within this list, yet we retrieved it once, then we decide
+	 * not to perform thumbnail actions over DBus. This is a performance
+	 * improvement and the GStrv can be resident in memory until the end
+	 * of the application - it's a cache - 
+	 *
+	 * It doesn't support detecting when the DBus thumbnailer starts 
+	 * supporting more formats (which can indeed start happening). This is
+	 * a known tradeoff and limitation of this cache. We could enhance this
+	 * cache to listen for changes on the bus, and invalidate it once we
+	 * know that more MIME types have become supported. It has no high
+	 * priority now, though (therefore, is this a TODO). 
+	 */
+
+	g_message ("Thumbnailer supported mime types being requested...");
+
+	dbus_g_proxy_call (tracker_dbus_get_thumb_manager (),
+			   "GetSupported", &error, 
+			   G_TYPE_INVALID,
+			   G_TYPE_STRV, &mime_types, 
+			   G_TYPE_INVALID);
+	
+	if (error) {
+		g_warning ("Thumbnailer service did not return supported mime types, %s",
+			   error->message);
+		g_error_free (error);
+	} else if (mime_types) {
+		g_message ("Thumbnailer supports %d mime types", 
+			   g_strv_length (mime_types));
+		private->supported_mime_types = mime_types;
+	}
+	
+	private->service_is_prepared = TRUE;
+}
+
+#endif /* THUMBNAILING_OVER_DBUS */
+
+void
+tracker_thumbnailer_init (void)
+{
+	TrackerThumbnailerPrivate *private;
+
+	private = g_new0 (TrackerThumbnailerPrivate, 1);
+	g_static_private_set (&private_key,
+			      private,
+			      private_free);
+
+	thumbnailer_prepare ();
+}
+
+void
+tracker_thumbnailer_shutdown (void)
+{
+	g_static_private_set (&private_key, NULL, NULL);
+}
+
+void
+tracker_thumbnailer_move (const gchar *from_uri,
+			  const gchar *mime_type,
+			  const gchar *to_uri)
+{
+#ifdef THUMBNAILING_OVER_DBUS
+	TrackerThumbnailerPrivate *private;
+	const gchar *to[2] = { NULL, NULL };
+	const gchar *from[2] = { NULL, NULL };
+
+	g_return_if_fail (from_uri != NULL);
+	g_return_if_fail (mime_type != NULL);
+	g_return_if_fail (to_uri != NULL);
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	if (!should_be_thumbnailed (private->supported_mime_types, mime_type)) {
+		g_debug ("Thumbnailer ignoring mime type:'%s'",
+			 mime_type);
+		return;
+	}
+
+	private->request_id++;
+
+	g_message ("Requesting thumbnailer moves URI from:'%s' to:'%s', request_id:%d...",
+		   from_uri,
+		   to_uri,
+		   private->request_id); 
+
+	to[0] = to_uri;
+	from[0] = from_uri;
+	
+	dbus_g_proxy_begin_call (tracker_dbus_get_thumbnailer (),
+				 "Move",
+				 thumbnailer_reply_cb,
+				 GUINT_TO_POINTER (private->request_id), 
+				 NULL,
+				 G_TYPE_STRV, from,
+				 G_TYPE_STRV, to,
+				 G_TYPE_INVALID);
+#endif /* THUMBNAILING_OVER_DBUS */
+}
+
+void
+tracker_thumbnailer_remove (const gchar *uri, 
+			    const gchar *mime_type)
+{
+#ifdef THUMBNAILING_OVER_DBUS
+	TrackerThumbnailerPrivate *private;
+	const gchar *uris[2] = { NULL, NULL };
+
+	g_return_if_fail (uri != NULL);
+	g_return_if_fail (mime_type != NULL);
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	if (!should_be_thumbnailed (private->supported_mime_types, mime_type)) {
+		g_debug ("Thumbnailer ignoring mime type:'%s' and uri:'%s'",
+			 mime_type,
+			 uri);
+		return;
+	}
+
+	private->request_id++;
+
+	uris[0] = uri;
+
+	g_message ("Requesting thumbnailer removes URI:'%s', request_id:%d...",
+		   uri,
+		   private->request_id); 
+	
+	dbus_g_proxy_begin_call (tracker_dbus_get_thumbnailer (),
+				 "Delete",
+				 thumbnailer_reply_cb,
+				 GUINT_TO_POINTER (private->request_id),
+				 NULL,
+				 G_TYPE_STRV, uri,
+				 G_TYPE_INVALID);
+#endif /* THUMBNAILING_OVER_DBUS */
+}
+
+void
+tracker_thumbnailer_get_file_thumbnail (const gchar *uri,
+					const gchar *mime_type)
+{
+#ifdef THUMBNAILING_OVER_DBUS
+	TrackerThumbnailerPrivate *private;
+
+	g_return_if_fail (uri != NULL);
+	g_return_if_fail (mime_type != NULL);
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	if (!should_be_thumbnailed (private->supported_mime_types, mime_type)) {
+		g_debug ("Thumbnailer ignoring mime type:'%s' and uri:'%s'",
+			 mime_type,
+			 uri);
+		return;
+	}
+
+	private->request_id++;
+
+	g_message ("Requesting thumbnailer to get thumbnail for URI:'%s', request_id:%d...",
+		   uri,
+		   private->request_id); 
+
+	/* We want to deal with the current list first if it is
+	 * already at the limit.
+	 */
+	if (private->count == THUMBNAIL_REQUEST_LIMIT) {
+		g_debug ("Already have %d thumbnails queued, forcing thumbnailer request", 
+			 THUMBNAIL_REQUEST_LIMIT);
+
+		g_source_remove (private->timeout_id);
+		private->timeout_id = 0;
+
+		thumbnailer_request_timeout_cb (NULL);
+	}
+
+	/* Add new URI */
+	private->uris[private->count] = g_strdup (uri);
+
+	if (mime_type) {
+		private->mime_types[private->count] = g_strdup (mime_type);
+	} else if (g_strv_length (private->mime_types) > 0) {
+		private->mime_types[private->count] = g_strdup ("unknown/unknown");
+	}
+	
+	private->count++;
+	
+	if (private->timeout_id == 0) {
+		private->timeout_id = 
+			g_timeout_add_seconds (30, 
+					       thumbnailer_request_timeout_cb, 
+					       NULL);
+	}
+#endif /* THUMBNAILING_OVER_DBUS */
+}

Added: trunk/src/tracker-indexer/tracker-thumbnailer.h
==============================================================================
--- (empty file)
+++ trunk/src/tracker-indexer/tracker-thumbnailer.h	Mon Nov 24 12:57:41 2008
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __TRACKER_METADATA_UTILS_H__
+#define __TRACKER_METADATA_UTILS_H__
+
+#include <libtracker-data/tracker-data-metadata.h>
+#include <tracker-indexer/tracker-module-file.h>
+
+G_BEGIN_DECLS
+
+void tracker_thumbnailer_init               (void);
+void tracker_thumbnailer_shutdown           (void);
+
+void tracker_thumbnailer_get_file_thumbnail (const gchar *path,
+					     const gchar *mime);
+void tracker_thumbnailer_move               (const gchar *from_uri,
+					     const gchar *mime_type,
+					     const gchar *to_uri);
+void tracker_thumbnailer_remove             (const gchar *uri,
+					     const gchar *mime_type);
+
+G_END_DECLS
+
+#endif /* __TRACKER_METADATA_UTILS_H__ */

Modified: trunk/tests/tracker-indexer/Makefile.am
==============================================================================
--- trunk/tests/tracker-indexer/Makefile.am	(original)
+++ trunk/tests/tracker-indexer/Makefile.am	Mon Nov 24 12:57:41 2008
@@ -34,7 +34,9 @@
 	tracker-module-file.c						\
 	tracker-module-file.h						\
 	tracker-module-iteratable.c					\
-	tracker-module-iteratable.h
+	tracker-module-iteratable.h					\
+	tracker-thumbnailer.c						\
+	tracker-thumbnailer.h
 
 tracker_metadata_utils_LDADD =	                                        \
 	$(top_builddir)/src/libtracker-data/libtracker-data.la 		\

Modified: trunk/thumbnailers/image/Makefile.am
==============================================================================
--- trunk/thumbnailers/image/Makefile.am	(original)
+++ trunk/thumbnailers/image/Makefile.am	Mon Nov 24 12:57:41 2008
@@ -1,21 +1,2 @@
 include $(top_srcdir)/Makefile.decl
 
-thumbappbindir = $(libdir)/tracker/thumbnailers/image
-
-if HAVE_IMAGEMAGICK
-thumbappbin_SCRIPTS = 		\
-	png_thumbnailer		\
-	jpeg_thumbnailer 	\
-	gif_thumbnailer		\
-	tiff_thumbnailer
-else
-if HAVE_HILDON_THUMBNAIL
-thumbappbin_SCRIPTS = 		\
-	hildon/png_thumbnailer 	\
-	hildon/jpeg_thumbnailer \
-	hildon/gif_thumbnailer	\
-	hildon/tiff_thumbnailer
-endif
-endif
-
-EXTRA_DIST = $(thumbappbin_SCRIPTS)



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