[tracker] tracker-miner-fs: Re-enable the thumbnailer communication



commit 7777665d459c348a4acee4545f66454588601173
Author: Martyn Russell <martyn lanedo com>
Date:   Mon Sep 28 15:46:29 2009 +0100

    tracker-miner-fs: Re-enable the thumbnailer communication
    
    This also improves the thumbnailer API used and is a bit more
    efficient in places too.

 src/tracker-miner-fs/tracker-main.c        |    2 +
 src/tracker-miner-fs/tracker-miner-files.c |  131 ++++++++++++++++++----------
 src/tracker-miner-fs/tracker-thumbnailer.c |   36 ++-------
 3 files changed, 94 insertions(+), 75 deletions(-)
---
diff --git a/src/tracker-miner-fs/tracker-main.c b/src/tracker-miner-fs/tracker-main.c
index 0add5c0..7028ae8 100644
--- a/src/tracker-miner-fs/tracker-main.c
+++ b/src/tracker-miner-fs/tracker-main.c
@@ -190,6 +190,8 @@ miner_handle_next (void)
         }
 
         if (!current_miner) {
+                g_message ("All miners are now finished");
+                tracker_thumbnailer_queue_send ();
                 return;
         }
 
diff --git a/src/tracker-miner-fs/tracker-miner-files.c b/src/tracker-miner-fs/tracker-miner-files.c
index 84a634f..d59328f 100644
--- a/src/tracker-miner-fs/tracker-miner-files.c
+++ b/src/tracker-miner-fs/tracker-miner-files.c
@@ -35,6 +35,8 @@
 #include "tracker-miner-files.h"
 #include "tracker-config.h"
 #include "tracker-extract-client.h"
+#include "tracker-thumbnailer.h"
+#include "tracker-marshal.h"
 
 #define DISK_SPACE_CHECK_FREQUENCY 10
 
@@ -123,8 +125,12 @@ static void     low_disk_space_limit_cb       (GObject              *gobject,
 					       GParamSpec           *arg1,
 					       gpointer              user_data);
 
-static DBusGProxy * create_extractor_proxy    (void);
-
+static DBusGProxy * extractor_create_proxy    (void);
+static void    extractor_queue_thumbnail_cb   (DBusGProxy           *proxy,
+					       const gchar          *filename, 
+					       const gchar          *mime_type,
+					       gpointer              user_data);
+	
 static gboolean miner_files_check_file        (TrackerMinerFS       *fs,
 					       GFile                *file);
 static gboolean miner_files_check_directory   (TrackerMinerFS       *fs,
@@ -173,7 +179,6 @@ tracker_miner_files_class_init (TrackerMinerFilesClass *klass)
 	miner_files_error_quark = g_quark_from_static_string ("TrackerMinerFiles");
 }
 
-
 static void
 tracker_miner_files_init (TrackerMinerFiles *mf)
 {
@@ -210,8 +215,24 @@ tracker_miner_files_init (TrackerMinerFiles *mf)
 			  G_CALLBACK (mount_pre_unmount_cb),
 			  mf);
 
-	priv->extractor_proxy = create_extractor_proxy ();
+	/* Set up extractor and signals */
+	priv->extractor_proxy = extractor_create_proxy ();
+
+	dbus_g_object_register_marshaller (tracker_marshal_VOID__STRING_STRING,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING,
+					   G_TYPE_STRING,
+					   G_TYPE_INVALID);
 
+	dbus_g_proxy_add_signal (priv->extractor_proxy, "QueueThumbnail",
+				 G_TYPE_STRING,
+				 G_TYPE_STRING, 
+				 G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal (priv->extractor_proxy, "QueueThumbnail",
+				     G_CALLBACK (extractor_queue_thumbnail_cb),
+				     NULL, NULL);
+	
 	init_mount_points (mf);
 }
 
@@ -264,6 +285,12 @@ miner_files_finalize (GObject *object)
 	mf = TRACKER_MINER_FILES (object);
 	priv = mf->private;
 
+	dbus_g_proxy_disconnect_signal (priv->extractor_proxy, "QueueThumbnail",
+					G_CALLBACK (extractor_queue_thumbnail_cb),
+					NULL);
+	
+	g_object_unref (priv->extractor_proxy);
+
 	g_signal_handlers_disconnect_by_func (priv->config,
 					      low_disk_space_limit_cb,
 					      NULL);
@@ -778,35 +805,6 @@ mount_pre_unmount_cb (GVolumeMonitor    *volume_monitor,
 	g_object_unref (mount_root);
 }
 
-static DBusGProxy *
-create_extractor_proxy (void)
-{
-	DBusGProxy *proxy;
-	DBusGConnection *connection;
-	GError *error = NULL;
-
-	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-
-	if (!connection) {
-		g_critical ("Could not connect to the D-Bus session bus, %s",
-			    error ? error->message : "no error given.");
-		g_clear_error (&error);
-		return FALSE;
-	}
-
-	/* Get proxy for the extractor */
-	proxy = dbus_g_proxy_new_for_name (connection,
-					   "org.freedesktop.Tracker1.Extract",
-					   "/org/freedesktop/Tracker1/Extract",
-					   "org.freedesktop.Tracker1.Extract");
-
-	if (!proxy) {
-		g_critical ("Could not create a DBusGProxy to the extract service");
-	}
-
-	return proxy;
-}
-
 static gboolean
 disk_space_check (TrackerMinerFiles *mf)
 {
@@ -1145,11 +1143,49 @@ process_file_data_free (ProcessFileData *data)
 	g_slice_free (ProcessFileData, data);
 }
 
+static DBusGProxy *
+extractor_create_proxy (void)
+{
+	DBusGProxy *proxy;
+	DBusGConnection *connection;
+	GError *error = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (!connection) {
+		g_critical ("Could not connect to the D-Bus session bus, %s",
+			    error ? error->message : "no error given.");
+		g_clear_error (&error);
+		return FALSE;
+	}
+
+	/* Get proxy for the extractor */
+	proxy = dbus_g_proxy_new_for_name (connection,
+					   "org.freedesktop.Tracker1.Extract",
+					   "/org/freedesktop/Tracker1/Extract",
+					   "org.freedesktop.Tracker1.Extract");
+
+	if (!proxy) {
+		g_critical ("Could not create a DBusGProxy to the extract service");
+	}
+
+	return proxy;
+}
+
 static void
-get_embedded_metadata_cb (DBusGProxy *proxy,
-			  gchar      *sparql,
-			  GError     *error,
-			  gpointer    user_data)
+extractor_queue_thumbnail_cb (DBusGProxy  *proxy,
+			      const gchar *filename, 
+			      const gchar *mime_type,
+			      gpointer     user_data)
+{
+	tracker_thumbnailer_queue_add (filename, mime_type);
+}
+
+static void
+extractor_get_embedded_metadata_cb (DBusGProxy *proxy,
+				    gchar      *sparql,
+				    GError     *error,
+				    gpointer    user_data)
 {
 	ProcessFileData *data = user_data;
 
@@ -1174,8 +1210,8 @@ get_embedded_metadata_cb (DBusGProxy *proxy,
 }
 
 static void
-get_embedded_metadata_cancel (GCancellable    *cancellable,
-			      ProcessFileData *data)
+extractor_get_embedded_metadata_cancel (GCancellable    *cancellable,
+					ProcessFileData *data)
 {
 	GError *error;
 
@@ -1191,17 +1227,17 @@ get_embedded_metadata_cancel (GCancellable    *cancellable,
 }
 
 static void
-get_embedded_metadata (ProcessFileData *data,
-		       const gchar     *uri,
-		       const gchar     *mime_type)
+extractor_get_embedded_metadata (ProcessFileData *data,
+				 const gchar     *uri,
+				 const gchar     *mime_type)
 {
 	data->call = org_freedesktop_Tracker1_Extract_get_metadata_async (data->miner->private->extractor_proxy,
 									  uri,
 									  mime_type,
-									  get_embedded_metadata_cb,
+									  extractor_get_embedded_metadata_cb,
 									  data);
 	g_signal_connect (data->cancellable, "cancelled",
-			  G_CALLBACK (get_embedded_metadata_cancel), data);
+			  G_CALLBACK (extractor_get_embedded_metadata_cancel), data);
 }
 
 static void
@@ -1279,8 +1315,13 @@ process_file_cb (GObject      *object,
 
         miner_files_add_to_datasource (data->miner, file, sparql);
 
+	/* Send file/mime data to thumbnailer (which adds it to the
+	 * queue if the thumbnailer handles those mime types).
+	 */
+	tracker_thumbnailer_queue_add (uri, mime_type);
+
 	/* Next step, getting embedded metadata */
-	get_embedded_metadata (data, uri, mime_type);
+	extractor_get_embedded_metadata (data, uri, mime_type);
 
 	g_object_unref (file_info);
 	g_free (uri);
diff --git a/src/tracker-miner-fs/tracker-thumbnailer.c b/src/tracker-miner-fs/tracker-thumbnailer.c
index 1103e65..cd92659 100644
--- a/src/tracker-miner-fs/tracker-thumbnailer.c
+++ b/src/tracker-miner-fs/tracker-thumbnailer.c
@@ -77,7 +77,7 @@ private_free (gpointer data)
 	g_free (private);
 }
 
-static gboolean
+inline static gboolean
 should_be_thumbnailed (GStrv        list, 
 		       const gchar *mime)
 {
@@ -109,6 +109,9 @@ tracker_thumbnailer_init (void)
 
 	private = g_new0 (TrackerThumbnailerPrivate, 1);
 
+	/* Don't start at 0, start at 1. */
+	private->request_id = 1;
+
 	g_static_private_set (&private_key,
 			      private,
 			      private_free);
@@ -139,22 +142,6 @@ tracker_thumbnailer_init (void)
 					   THUMBMAN_PATH,
 					   THUMBMAN_INTERFACE);
 	
-
-	/* 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). 
-	 */
-
 	dbus_g_proxy_call (private->manager_proxy,
 			   "GetSupported", &error, 
 			   G_TYPE_INVALID,
@@ -218,8 +205,6 @@ tracker_thumbnailer_move (const gchar *from_uri,
 	}
 
 	if (!should_be_thumbnailed (private->supported_mime_types, mime_type)) {
-		g_debug ("Thumbnailer ignoring mime type:'%s'",
-			 mime_type);
 		return FALSE;
 	}
 
@@ -278,9 +263,6 @@ tracker_thumbnailer_remove (const gchar *uri,
 	}
 
 	if (mime_type && !should_be_thumbnailed (private->supported_mime_types, mime_type)) {
-		g_debug ("Thumbnailer ignoring uri:'%s', mime type:'%s'",
-			 uri,
-			 mime_type);
 		return FALSE;
 	}
 
@@ -360,14 +342,9 @@ tracker_thumbnailer_queue_add (const gchar *uri,
 	}
 
 	if (!should_be_thumbnailed (private->supported_mime_types, mime_type)) {
-		g_debug ("Thumbnailer ignoring uri:'%s', mime type:'%s'",
-			 uri,
-			 mime_type);
 		return FALSE;
 	}
 
-	private->request_id++;
-
 	/* Add new URI (detect if we got passed a path) */
 	if (!strstr (uri, "://")) {
 		used_uri = g_filename_to_uri (uri, NULL, NULL);
@@ -384,10 +361,9 @@ tracker_thumbnailer_queue_add (const gchar *uri,
 	private->uris = g_slist_append (private->uris, used_uri);
 	private->mime_types = g_slist_append (private->mime_types, used_mime_type);
 
-	g_debug ("Thumbnailer queue appended with uri:'%s', mime type:'%s', request_id:%d...",
+	g_debug ("Thumbnailer queue appended with uri:'%s', mime type:'%s'",
 		 used_uri,
-		 used_mime_type,
-		 private->request_id); 
+		 used_mime_type);
 
 	return TRUE;
 }



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