tracker r2237 - in branches/indexer-split: . src/tracker-extract src/tracker-indexer



Author: mr
Date: Tue Sep 16 11:01:39 2008
New Revision: 2237
URL: http://svn.gnome.org/viewvc/tracker?rev=2237&view=rev

Log:
	* src/tracker-extract/tracker-extract-png.c: Reworked the code
	here and fixed adding NULL values with sensible keys to the hash
	table. 

	* src/tracker-extract/tracker-extract.c:
	(tracker_get_file_metadata): Check the key and value separately so
	we don't just get one warning for either not knowing which is
	NULL.

	* src/tracker-indexer/tracker-indexer-module.c: 
	(tracker_indexer_module_file_get_uri): Removed the '\n' from the
	debug statement.

	* src/tracker-indexer/tracker-metadata-utils.c: Fixed a nasty
	crash where the watch is not removed when cleaning up IO channels.
	Grouped the functions more logically so it is clearer what this
	module does by function names.

	* src/tracker-indexer/tracker-metadata-utils.h: Removed unused
	function signatures and structs/enums.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/tracker-extract/tracker-extract-png.c
   branches/indexer-split/src/tracker-extract/tracker-extract.c
   branches/indexer-split/src/tracker-indexer/tracker-indexer-module.c
   branches/indexer-split/src/tracker-indexer/tracker-indexer.c
   branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c
   branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.h

Modified: branches/indexer-split/src/tracker-extract/tracker-extract-png.c
==============================================================================
--- branches/indexer-split/src/tracker-extract/tracker-extract-png.c	(original)
+++ branches/indexer-split/src/tracker-extract/tracker-extract-png.c	Tue Sep 16 11:01:39 2008
@@ -1,5 +1,7 @@
-/* Tracker Extract - extracts embedded metadata from files
+/* -*- 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 program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
@@ -17,72 +19,80 @@
  * Boston, MA  02110-1301, USA.
  */
 
+#include "config.h"
+
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
 #endif
 
-#include "config.h"
-#include "tracker-extract.h"
-#include "tracker-xmp.h"
-
 #include <fcntl.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <png.h>
 
-#define RFC1123_DATE_FORMAT "%d %B %Y %H:%M:%S %z"
+#include <png.h>
 
+#include <glib.h>
+#include <glib/gstdio.h>
 
-static gchar *
-rfc1123_to_iso8601_date (gchar *rfc_date)
-{
-        /* ex. RFC1123 date: "22 May 1997 18:07:10 -0600"
-           To
-           ex. ISO8601 date: "2007-05-22T18:07:10-0600"
-        */
-        return tracker_generic_date_to_iso8601 (rfc_date, RFC1123_DATE_FORMAT);
-}
+#include "tracker-extract.h"
+#include "tracker-xmp.h"
 
+#define RFC1123_DATE_FORMAT "%d %B %Y %H:%M:%S %z"
 
 typedef gchar * (*PostProcessor) (gchar *);
 
-
-static struct {
+typedef struct {
 	gchar         *name;
 	gchar         *type;
-        PostProcessor post;
+        PostProcessor  post;
+} TagProcessors;
 
-} tagmap[] = {
-  { "Author",             "Image:Creator",      NULL},
-  { "Creator",            "Image:Creator",      NULL},
-  { "Description",        "Image:Description",  NULL},
-  { "Comment",            "Image:Comments",     NULL},
-  { "Copyright",          "File:Copyright",     NULL},
-  { "Creation Time",      "Image:Date",         rfc1123_to_iso8601_date},
-  { "Title",              "Image:Title",        NULL},
-  { "Software",           "Image:Software",     NULL},
-  { "Disclaimer",         "File:License",       NULL},
-  { NULL,                 NULL,                 NULL},
+static gchar *rfc1123_to_iso8601_date (gchar       *rfc_date);
+static void   extract_png             (const gchar *filename,
+                                       GHashTable  *metadata);
+
+static TagProcessors tag_processors[] = {
+        { "Author",             "Image:Creator",      NULL},
+        { "Creator",            "Image:Creator",      NULL},
+        { "Description",        "Image:Description",  NULL},
+        { "Comment",            "Image:Comments",     NULL},
+        { "Copyright",          "File:Copyright",     NULL},
+        { "Creation Time",      "Image:Date",         rfc1123_to_iso8601_date},
+        { "Title",              "Image:Title",        NULL},
+        { "Software",           "Image:Software",     NULL},
+        { "Disclaimer",         "File:License",       NULL},
+        { NULL,                 NULL,                 NULL},
 };
 
+static TrackerExtractorData data[] = {
+	{ "image/png", extract_png },
+	{ NULL, NULL }
+};
+
+static gchar *
+rfc1123_to_iso8601_date (gchar *rfc_date)
+{
+        /* From: ex. RFC1123 date: "22 May 1997 18:07:10 -0600"
+         * To  : ex. ISO8601 date: "2007-05-22T18:07:10-0600"
+         */
+        return tracker_generic_date_to_iso8601 (rfc_date, RFC1123_DATE_FORMAT);
+}
 
 static void
-tracker_extract_png (const gchar *filename, GHashTable *metadata)
+extract_png (const gchar *filename, 
+             GHashTable  *metadata)
 {
-        gint        fd_png;
+        gint         fd_png;
 	FILE        *png;
-	png_structp png_ptr;
-	png_infop   info_ptr;
-	png_uint_32 width, height;
-	gint        num_text;
-	png_textp   text_ptr;
-
-	gint bit_depth, color_type;
-	gint interlace_type, compression_type, filter_type;
+	png_structp  png_ptr;
+	png_infop    info_ptr;
+	png_uint_32  width, height;
+	gint         num_text;
+	png_textp    text_ptr;
+	gint         bit_depth, color_type;
+	gint         interlace_type, compression_type, filter_type;
 
 #if defined(__linux__)
         if ((fd_png = g_open (filename, (O_RDONLY | O_NOATIME))) == -1) {
@@ -94,7 +104,9 @@
 
 	if ((png = fdopen (fd_png, "r"))) {
 		png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
-		                                  NULL, NULL, NULL);
+		                                  NULL, 
+                                                  NULL,
+                                                  NULL);
 		if (!png_ptr) {
 			fclose (png);
 			return;
@@ -112,63 +124,76 @@
 
 		if (png_get_text (png_ptr, info_ptr, &text_ptr, &num_text) > 0) {
                         gint i;
+                        gint j;
+
 			for (i = 0; i < num_text; i++) {
-				if (text_ptr[i].key) {
-                                        gint j;
-					#if defined(HAVE_EXEMPI) && defined(PNG_iTXt_SUPPORTED)
-					if (strcmp ("XML:com.adobe.xmp", text_ptr[i].key) == 0) {
-						tracker_read_xmp (text_ptr[i].text,
-                                                                  text_ptr[i].itxt_length,
-                                                                  metadata);
-						continue;
-					}
-					#endif
+				if (!text_ptr[i].key) {
+                                        continue;
+                                }
+
+#if defined(HAVE_EXEMPI) && defined(PNG_iTXt_SUPPORTED)
+                                if (strcmp ("XML:com.adobe.xmp", text_ptr[i].key) == 0) {
+                                        tracker_read_xmp (text_ptr[i].text,
+                                                          text_ptr[i].itxt_length,
+                                                          metadata);
+                                        continue;
+                                }
+#endif
 	
-					for (j = 0; tagmap[j].type; j++) {
-						if (strcasecmp (tagmap[j].name, text_ptr[i].key) == 0) {
-							if (text_ptr[i].text && text_ptr[i].text[0] != '\0') {
-                                                                if (tagmap[j].post) {
-                                                                        g_hash_table_insert (metadata,
-                                                                                             g_strdup (tagmap[j].type),
-                                                                                             (*tagmap[j].post) (text_ptr[i].text));
-                                                                } else {
-                                                                        g_hash_table_insert (metadata,
-                                                                                             g_strdup (tagmap[j].type),
-                                                                                             g_strdup (text_ptr[i].text));
-                                                                }
-                                                                break;
+                                for (j = 0; tag_processors[j].type; j++) {
+                                        if (strcasecmp (tag_processors[j].name, text_ptr[i].key) != 0) {
+                                                continue;
+                                        }
+
+                                        if (text_ptr[i].text && text_ptr[i].text[0] != '\0') {
+                                                if (tag_processors[j].post) {
+                                                        gchar *str;
+
+                                                        str = (*tag_processors[j].post) (text_ptr[i].text);
+                                                        if (str) {
+                                                                g_hash_table_insert (metadata,
+                                                                                     g_strdup (tag_processors[j].type),
+                                                                                     str);
                                                         }
+                                                } else {
+                                                        g_hash_table_insert (metadata,
+                                                                             g_strdup (tag_processors[j].type),
+                                                                             g_strdup (text_ptr[i].text));
                                                 }
-					}
-				}
-			}
+
+                                                break;
+                                        }
+                                }
+                        }
 		}
 
-		/* Read size from header. We want native have higher priority than EXIF etc */
-		if (png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth,
-		                 &color_type, &interlace_type, &compression_type, &filter_type)) {
-			g_hash_table_insert (metadata, g_strdup ("Image:Width"),
+		/* Read size from header. We want native have higher
+                 * priority than EXIF etc.
+                 */
+		if (png_get_IHDR (png_ptr, 
+                                  info_ptr, 
+                                  &width, 
+                                  &height, 
+                                  &bit_depth,
+                                  &color_type,
+                                  &interlace_type,
+                                  &compression_type,
+                                  &filter_type)) {
+			g_hash_table_insert (metadata, 
+                                             g_strdup ("Image:Width"),
 			                     g_strdup_printf ("%ld", width));
-			g_hash_table_insert (metadata, g_strdup ("Image:Height"),
+			g_hash_table_insert (metadata, 
+                                             g_strdup ("Image:Height"),
 			                     g_strdup_printf ("%ld", height));
 		}
 
 		png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
-
 		fclose (png);
-
         } else {
                 close (fd_png);
         }
 }
 
-
-TrackerExtractorData data[] = {
-	{ "image/png", tracker_extract_png },
-	{ NULL, NULL }
-};
-
-
 TrackerExtractorData *
 tracker_get_extractor_data (void)
 {

Modified: branches/indexer-split/src/tracker-extract/tracker-extract.c
==============================================================================
--- branches/indexer-split/src/tracker-extract/tracker-extract.c	(original)
+++ branches/indexer-split/src/tracker-extract/tracker-extract.c	Tue Sep 16 11:01:39 2008
@@ -271,31 +271,32 @@
 }
 
 static void
-print_meta_table_data (gpointer pkey,
-                       gpointer pvalue,
+print_meta_table_data (gpointer key,
+                       gpointer value,
                        gpointer user_data)
 {
-	gchar *value;
-
-	g_return_if_fail (pkey && pvalue);
-
-	value = g_locale_to_utf8 (pvalue, -1, NULL, NULL, NULL);
-
-	if (value) {
-		if (value[0] != '\0') {
-			/* replace any embedded semicolons or "=" as we use them for delimiters */
-			value = g_strdelimit (value, ";", ',');
-			value = g_strdelimit (value, "=", '-');
-			value = g_strstrip (value);
+	gchar *value_utf8;
+	
+	g_return_if_fail (key != NULL);
+	g_return_if_fail (value != NULL);
+
+	value_utf8 = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
+
+	if (value_utf8) {
+		if (value_utf8[0] != '\0') {
+			/* Replace any embedded semicolons or "=" as we use them for delimiters */
+			value_utf8 = g_strdelimit (value_utf8, ";", ',');
+			value_utf8 = g_strdelimit (value_utf8, "=", '-');
+			value_utf8 = g_strstrip (value_utf8);
 
 			debug ("Extractor - Found '%s' = '%s'", 
-                               (gchar*) pkey, 
-                               value);
+                               (gchar*) key, 
+                               value_utf8);
 
-                        g_print ("%s=%s;\n", (gchar*) pkey, value);
+                        g_print ("%s=%s;\n", (gchar*) key, value_utf8);
 		}
 
-		g_free (value);
+		g_free (value_utf8);
 	}
 }
 

Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer-module.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer-module.c	(original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer-module.c	Tue Sep 16 11:01:39 2008
@@ -146,7 +146,7 @@
 
 		return TRUE;
 	} else {
-		g_debug ("Could not get URI for '%s'\n", file->path);
+		g_debug ("Could not get URI for '%s'", file->path);
 
 		g_free (tmp_dirname);
 		g_free (tmp_basename);

Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer.c	(original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer.c	Tue Sep 16 11:01:39 2008
@@ -1426,7 +1426,7 @@
 	tracker_db_check_service (service_def, dirname, basename, &service_id, NULL);
 
 	if (service_id < 1) {
-		g_debug ("Can not delete file, it doesnt exist in DB");
+		g_debug ("  Can not delete file, it doesnt exist in DB");
 		return;
 	}
 
@@ -1754,6 +1754,20 @@
 		return TRUE;
 	}
 
+	/* Here we do a quick check to see if this is an email URI or
+	 * not. For emails we don't check for the parent cache the
+	 * same way, we simply index it. If the first character is not
+	 * '/' then the path is usually something like:
+	 *
+	 *   email://1192717939 16218 20 petunia//INBOX;uid=(null)
+	 *
+	 * What we should do, is check the summary mtime to know if
+	 * we should index the content I think.
+	 */
+	if (info->file->path[0] != G_DIR_SEPARATOR) {
+		return TRUE;
+	}
+
 	/* So, if we are here, then the file or directory DID exist
 	 * in the database already. Now we need to check if the
 	 * parent directory mtime matches the mtime we have for it in

Modified: branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c	(original)
+++ branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c	Tue Sep 16 11:01:39 2008
@@ -19,25 +19,23 @@
  * Boston, MA  02110-1301, USA.
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #include <string.h>
 
 #include <gio/gio.h>
 
+#define THUMBNAIL_RETRIEVAL_ENABLED
+
+#ifdef HAVE_HILDON_THUMBNAIL
+#include <hildon-thumbnail-factory.h>
+#endif
+
 #include <libtracker-common/tracker-file-utils.h>
 #include <libtracker-common/tracker-type-utils.h>
 #include <libtracker-common/tracker-os-dependant.h>
 #include <libtracker-common/tracker-ontology.h>
 
-#define THUMBNAIL_RETRIEVAL_ENABLED
-
-#ifndef TEST
-#include "tracker-dbus.h"
-#endif
-
 #include "tracker-metadata-utils.h"
 
 #define METADATA_FILE_NAME_DELIMITED "File:NameDelimited"
@@ -56,23 +54,25 @@
 
 typedef struct {
 	GPid pid;
+	guint stdout_watch_id;
 	GIOChannel *stdin_channel;
 	GIOChannel *stdout_channel;
 	GMainLoop  *data_incoming_loop;
 	gpointer data;
 } ProcessContext;
 
-static void tracker_metadata_utils_get_thumbnail (const gchar *path,
-						  const gchar *mime);
+static void get_file_thumbnail (const gchar *path,
+				const gchar *mime);
 
 static ProcessContext *metadata_context = NULL;
 
 static void
-destroy_process_context (ProcessContext *context)
+process_context_destroy (ProcessContext *context)
 {
 	g_io_channel_shutdown (context->stdin_channel, FALSE, NULL);
 	g_io_channel_unref (context->stdin_channel);
 
+	g_source_remove (context->stdout_watch_id);
 	g_io_channel_shutdown (context->stdout_channel, FALSE, NULL);
 	g_io_channel_unref (context->stdout_channel);
 
@@ -88,9 +88,9 @@
 }
 
 static void
-process_watch_cb (GPid     pid,
-		  gint     status,
-		  gpointer user_data)
+process_context_child_watch_cb (GPid     pid,
+				gint     status,
+				gpointer user_data)
 {
 	g_debug ("Process '%d' exited with code: %d->'%s'", 
 		 pid, 
@@ -98,13 +98,14 @@
 		 g_strerror (status));
 
 	if (user_data == metadata_context) {
-		destroy_process_context (metadata_context);
+		process_context_destroy (metadata_context);
 		metadata_context = NULL;
 	}
 }
 
 static ProcessContext *
-create_process_context (const gchar **argv)
+process_context_create (const gchar **argv,
+			GIOFunc       stdout_watch_func)
 {
 	ProcessContext *context;
 	GIOChannel *stdin_channel, *stdout_channel;
@@ -129,33 +130,43 @@
 	context->stdin_channel = stdin_channel;
 	context->stdout_channel = stdout_channel;
 	context->data_incoming_loop = g_main_loop_new (NULL, FALSE);
-
+	context->stdout_watch_id = g_io_add_watch (stdout_channel,
+						   G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
+						   stdout_watch_func,
+						   context);
+	
 	flags = g_io_channel_get_flags (context->stdout_channel);
 	flags |= G_IO_FLAG_NONBLOCK;
 
 	g_io_channel_set_flags (context->stdout_channel, flags, NULL);
 
-	g_child_watch_add (context->pid, process_watch_cb, context);
+	g_child_watch_add (context->pid, process_context_child_watch_cb, context);
 
 	return context;
 }
 
 static gboolean
-tracker_metadata_read (GIOChannel   *channel,
-		       GIOCondition  condition,
-		       gpointer      user_data)
+metadata_read_cb (GIOChannel   *channel,
+		  GIOCondition  condition,
+		  gpointer      user_data)
 {
 	GPtrArray *array;
-	GIOStatus status = G_IO_STATUS_NORMAL;
+	GIOStatus status;
 	gchar *line;
 
 	if (!metadata_context) {
 		return FALSE;
 	}
 
-	if (condition & G_IO_IN || condition & G_IO_PRI) {
-		array = metadata_context->data;
+	if ((condition & G_IO_HUP) || (condition & G_IO_ERR)) {
+		return FALSE;
+	}
+
+	array = metadata_context->data;
+	status = G_IO_STATUS_NORMAL;
+	line = NULL;
 
+	if ((condition & G_IO_IN) || (condition & G_IO_PRI)) {
 		do {
 			status = g_io_channel_read_line (metadata_context->stdout_channel, 
 							 &line, 
@@ -173,21 +184,16 @@
 		if (status == G_IO_STATUS_EOF ||
 		    status == G_IO_STATUS_ERROR ||
 		    (status == G_IO_STATUS_NORMAL && !*line)) {
-			/* all extractor output has been processed */
+			/* All extractor output has been processed */
 			g_main_loop_quit (metadata_context->data_incoming_loop);
-			return TRUE;
 		}
 	}
 
-	if (condition & G_IO_HUP || condition & G_IO_ERR) {
-		return FALSE;
-	}
-
 	return TRUE;
 }
 
 static gboolean
-create_metadata_context (void)
+metadata_setup (void)
 {
 	const gchar *argv[2] = { 
 		LIBEXEC_PATH G_DIR_SEPARATOR_S "tracker-extract", 
@@ -195,27 +201,22 @@
 	};
 
 	if (metadata_context) {
-		destroy_process_context (metadata_context);
+		process_context_destroy (metadata_context);
 		metadata_context = NULL;
 	}
 
-	metadata_context = create_process_context (argv);
+	metadata_context = process_context_create (argv, metadata_read_cb);
 
 	if (!metadata_context) {
 		return FALSE;
 	}
 
-	g_io_add_watch (metadata_context->stdout_channel,
-			G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
-			tracker_metadata_read,
-			metadata_context);
-
 	return TRUE;
 }
 
 static gchar **
-tracker_metadata_query_file (const gchar *path,
-			     const gchar *mimetype)
+metadata_query_file (const gchar *path,
+		     const gchar *mimetype)
 {
 	gchar *utf_path, *str;
 	GPtrArray *array;
@@ -226,7 +227,7 @@
 		return NULL;
 	}
 
-	if (!metadata_context && !create_metadata_context ()) {
+	if (!metadata_context && !metadata_setup ()) {
 		return NULL;
 	}
 
@@ -243,7 +244,7 @@
 	str = g_strdup_printf ("%s\n%s\n", utf_path, mimetype);
 	g_free (utf_path);
 
-	/* write path and mimetype */
+	/* Write path and mimetype */
 	g_io_channel_write_chars (metadata_context->stdin_channel, str, -1, NULL, NULL);
 	status = g_io_channel_flush (metadata_context->stdin_channel, &error);
 
@@ -256,7 +257,7 @@
 		 */
 		g_error_free (error);
 
-		create_metadata_context ();
+		metadata_setup ();
 		metadata_context->data = array;
 
 		g_io_channel_write_chars (metadata_context->stdin_channel, str, -1, NULL, NULL);
@@ -286,9 +287,9 @@
 }
 
 static void
-tracker_metadata_utils_get_embedded (const char      *path,
-				     const char      *mimetype,
-				     TrackerMetadata *metadata)
+metadata_utils_get_embedded (const char      *path,
+			     const char      *mimetype,
+			     TrackerMetadata *metadata)
 {
 	gchar **values, *service_type;
 	gint i;
@@ -306,7 +307,7 @@
 
         g_free (service_type);
 
-	values = tracker_metadata_query_file (path, mimetype);
+	values = metadata_query_file (path, mimetype);
 
 	if (!values) {
 		return;
@@ -349,68 +350,10 @@
 	g_strfreev (values);
 }
 
-TrackerMetadata *
-tracker_metadata_utils_get_data (const gchar *path)
-{
-        TrackerMetadata *metadata;
-	struct stat st;
-	const gchar *ext;
-	gchar *mimetype;
-
-	if (g_lstat (path, &st) < 0) {
-                return NULL;
-        }
-
-        metadata = tracker_metadata_new ();
-	ext = strrchr (path, '.');
-
-	if (ext) {
-		tracker_metadata_insert (metadata, METADATA_FILE_EXT, g_strdup (ext + 1));
-	}
-
-	mimetype = tracker_file_get_mime_type (path);
-
-        tracker_metadata_insert (metadata, METADATA_FILE_NAME, g_filename_display_basename (path));
-	tracker_metadata_insert (metadata, METADATA_FILE_PATH, g_path_get_dirname (path));
-	tracker_metadata_insert (metadata, METADATA_FILE_NAME_DELIMITED,
-                                 g_filename_to_utf8 (path, -1, NULL, NULL, NULL));
-	tracker_metadata_insert (metadata, METADATA_FILE_MIMETYPE, mimetype);
-
-	if (mimetype) {
-
-		/* FIXME: 
-		 * We should determine here for which items we do and for which
-		 * items we don't want to pre-create the thumbnail. */
-
-		tracker_metadata_utils_get_thumbnail (path, mimetype);
-	}
-
-	if (S_ISLNK (st.st_mode)) {
-		gchar *link_path;
-
-		link_path = g_file_read_link (path, NULL);
-		tracker_metadata_insert (metadata, METADATA_FILE_LINK,
-                                         g_filename_to_utf8 (link_path, -1, NULL, NULL, NULL));
-		g_free (link_path);
-	}
-
-	/* FIXME: These should be dealt directly as integer/times/whatever, not strings */
-	tracker_metadata_insert (metadata, METADATA_FILE_SIZE,
-                                 tracker_guint_to_string (st.st_size));
-	tracker_metadata_insert (metadata, METADATA_FILE_MODIFIED,
-                                 tracker_date_to_string (st.st_mtime));
-	tracker_metadata_insert (metadata, METADATA_FILE_ACCESSED,
-                                 tracker_date_to_string (st.st_atime));
-
-	tracker_metadata_utils_get_embedded (path, mimetype, metadata);
-
-        return metadata;
-}
-
 static gboolean
-tracker_text_read (GIOChannel   *channel,
-		   GIOCondition  condition,
-		   gpointer      user_data)
+get_file_content_read_cb (GIOChannel   *channel,
+			  GIOCondition  condition,
+			  gpointer      user_data)
 {
 	ProcessContext *context;
 	GString *text;
@@ -446,67 +389,6 @@
 	return TRUE;
 }
 
-static gchar *
-call_text_filter (const gchar *path,
-		  const gchar *mime)
-{
-	ProcessContext *context;
-	gchar *str, *text_filter_file;
-	gchar **argv;
-	GString *text;
-
-#ifdef OS_WIN32
-	str = g_strconcat (mime, "_filter.bat", NULL);
-#else
-	str = g_strconcat (mime, "_filter", NULL);
-#endif
-
-	text_filter_file = g_build_filename (LIBDIR,
-					     "tracker",
-					     "filters",
-					     str,
-					     NULL);
-
-	g_free (str);
-
-	if (!g_file_test (text_filter_file, G_FILE_TEST_EXISTS)) {
-		g_free (text_filter_file);
-		return NULL;
-	}
-
-	argv = g_new0 (gchar *, 3);
-	argv[0] = text_filter_file;
-	argv[1] = (gchar *) path;
-
-	g_message ("Extracting text for:'%s' using filter:'%s'", argv[1], argv[0]);
-
-	context = create_process_context ((const gchar **) argv);
-
-	g_free (text_filter_file);
-	g_free (argv);
-
-	if (!context) {
-		return NULL;
-	}
-
-	text = g_string_new (NULL);
-	context->data = text;
-
-	g_io_add_watch (context->stdout_channel,
-			G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
-			tracker_text_read,
-			context);
-
-	/* It will block here until all incoming
-	 * text has been processed
-	 */
-	g_main_loop_run (context->data_incoming_loop);
-
-	destroy_process_context (context);
-
-	return g_string_free (text, FALSE);
-}
-
 static gboolean 
 get_file_is_utf8 (GString *s,
 		  gssize  *bytes_valid)
@@ -732,6 +614,111 @@
         return s ? g_string_free (s, FALSE) : NULL;
 }
 
+static void
+get_file_thumbnail (const gchar *path,
+		    const gchar *mime)
+{
+#ifdef THUMBNAIL_RETRIEVAL_ENABLED
+#ifdef HAVE_HILDON_THUMBNAIL
+	hildon_thumbnail_factory_load (path, mime, 128, 128, NULL, NULL);
+#else
+	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]);
+
+	process_context_destroy (context);
+
+	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_HILDON_THUMBNAIL */
+#endif /* THUMBNIAL_RETRIEVAL_ENABLED */
+}
+
+static gchar *
+get_file_content_by_filter (const gchar *path,
+			    const gchar *mime)
+{
+	ProcessContext *context;
+	gchar *str, *text_filter_file;
+	gchar **argv;
+	GString *text;
+
+#ifdef OS_WIN32
+	str = g_strconcat (mime, "_filter.bat", NULL);
+#else
+	str = g_strconcat (mime, "_filter", NULL);
+#endif
+
+	text_filter_file = g_build_filename (LIBDIR,
+					     "tracker",
+					     "filters",
+					     str,
+					     NULL);
+
+	g_free (str);
+
+	if (!g_file_test (text_filter_file, G_FILE_TEST_EXISTS)) {
+		g_free (text_filter_file);
+		return NULL;
+	}
+
+	argv = g_new0 (gchar *, 3);
+	argv[0] = text_filter_file;
+	argv[1] = (gchar *) path;
+
+	g_message ("Extracting text for:'%s' using filter:'%s'", argv[1], argv[0]);
+
+	context = process_context_create ((const gchar **) argv, get_file_content_read_cb);
+
+	g_free (text_filter_file);
+	g_free (argv);
+
+	if (!context) {
+		return NULL;
+	}
+
+	text = g_string_new (NULL);
+	context->data = text;
+
+	/* It will block here until all incoming
+	 * text has been processed
+	 */
+	g_main_loop_run (context->data_incoming_loop);
+
+	process_context_destroy (context);
+
+	return g_string_free (text, FALSE);
+}
+
 gchar *
 tracker_metadata_utils_get_text (const gchar *path)
 {
@@ -747,7 +734,7 @@
              strcmp (service_type, "Development") == 0)) {
                 text = get_file_content (path);
 	} else {
-		text = call_text_filter (path, mimetype);
+		text = get_file_content_by_filter (path, mimetype);
 	}
 
 	g_free (mimetype);
@@ -756,60 +743,60 @@
 	return text;
 }
 
-#ifndef TEST
-static void
-have_thumbnail (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+TrackerMetadata *
+tracker_metadata_utils_get_data (const gchar *path)
 {
-	GError *error = NULL;
-	guint   OUT_handle;
-
-	dbus_g_proxy_end_call (proxy, call, &error, 
-			       G_TYPE_UINT, &OUT_handle, 
-			       G_TYPE_INVALID);
-
-}
-#endif
+        TrackerMetadata *metadata;
+	struct stat st;
+	const gchar *ext;
+	gchar *mimetype;
 
-static void
-tracker_metadata_utils_get_thumbnail (const gchar *path,
-				      const gchar *mime)
-{
-#ifndef TEST
-	static gchar   *batch[51];
-	static guint    count = 0;
-	static gboolean not_available = FALSE;
+	if (g_lstat (path, &st) < 0) {
+                return NULL;
+        }
 
-	if (not_available)
-		return;
+        metadata = tracker_metadata_new ();
+	ext = strrchr (path, '.');
 
-	if (count < 51) {
-		batch[count++] = g_strdup (path);
+	if (ext) {
+		tracker_metadata_insert (metadata, METADATA_FILE_EXT, g_strdup (ext + 1));
 	}
 
-	if (count == 51) {
-		guint       i;
-		GError     *error = NULL;
-		DBusGProxy *proxy = tracker_dbus_get_thumbnailer ();
+	mimetype = tracker_file_get_mime_type (path);
 
-		batch[51] = NULL;
+        tracker_metadata_insert (metadata, METADATA_FILE_NAME, g_filename_display_basename (path));
+	tracker_metadata_insert (metadata, METADATA_FILE_PATH, g_path_get_dirname (path));
+	tracker_metadata_insert (metadata, METADATA_FILE_NAME_DELIMITED,
+                                 g_filename_to_utf8 (path, -1, NULL, NULL, NULL));
+	tracker_metadata_insert (metadata, METADATA_FILE_MIMETYPE, mimetype);
 
-		dbus_g_proxy_begin_call (proxy, "Queue", 
-					 have_thumbnail, 
-					 NULL, NULL, 
-					 G_TYPE_STRV, batch, 
-					 G_TYPE_UINT, 0, 
-					 G_TYPE_INVALID);
+	if (mimetype) {
 
+		/* FIXME: 
+		 * We should determine here for which items we do and for which
+		 * items we don't want to pre-create the thumbnail. */
 
-		if (error) {
-			not_available = TRUE;
-			g_error_free (error);
-		}
+		get_file_thumbnail (path, mimetype);
+	}
 
-		for (i = 0; i < count; i++)
-			g_free (batch[i]);
+	if (S_ISLNK (st.st_mode)) {
+		gchar *link_path;
 
-		count = 0;
+		link_path = g_file_read_link (path, NULL);
+		tracker_metadata_insert (metadata, METADATA_FILE_LINK,
+                                         g_filename_to_utf8 (link_path, -1, NULL, NULL, NULL));
+		g_free (link_path);
 	}
-#endif
+
+	/* FIXME: These should be dealt directly as integer/times/whatever, not strings */
+	tracker_metadata_insert (metadata, METADATA_FILE_SIZE,
+                                 tracker_guint_to_string (st.st_size));
+	tracker_metadata_insert (metadata, METADATA_FILE_MODIFIED,
+                                 tracker_date_to_string (st.st_mtime));
+	tracker_metadata_insert (metadata, METADATA_FILE_ACCESSED,
+                                 tracker_date_to_string (st.st_atime));
+
+	metadata_utils_get_embedded (path, mimetype, metadata);
+
+        return metadata;
 }

Modified: branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.h
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.h	(original)
+++ branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.h	Tue Sep 16 11:01:39 2008
@@ -26,33 +26,8 @@
 
 G_BEGIN_DECLS
 
-typedef enum {
-        TRACKER_METADATA_ACTION_NEW,
-        TRACKER_METADATA_ACTION_DELETE,
-        TRACKER_METADATA_ACTION_UPDATE
-} MetadataMergeAction;
-
-typedef struct {
-        MetadataMergeAction action;
-        gchar *metadata_type;
-	/* Metadata type with single value */
-        gchar *old_value;
-        gchar *new_value;
-	/* Metadata type with ultiple value */
-	GList *old_values;
-	GList *new_values;
-} MetadataActionItem;
-
-void              tracker_metadata_utils_action_item_free (MetadataActionItem *item,
-							   gpointer user_data);
-
-TrackerMetadata * tracker_metadata_utils_get_data      (const gchar *path);
-gchar *           tracker_metadata_utils_get_text      (const gchar *path);
-
-GSList *          tracker_metadata_utils_calculate_merge (TrackerMetadata *old_metadata,
-							  TrackerMetadata *new_metadata);
-
-
+TrackerMetadata *tracker_metadata_utils_get_data (const gchar *path);
+gchar *          tracker_metadata_utils_get_text (const gchar *path);
 
 G_END_DECLS
 



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