[tracker/anonymous-file-nodes: 4/8] Modify tracker-extract to return 2 sparql strings.



commit 817e1dbf1d6995af97f91b71f7e5cbd07f4123bf
Author: Carlos Garnacho <carlos lanedo com>
Date:   Tue Jan 26 12:13:36 2010 +0100

    Modify tracker-extract to return 2 sparql strings.
    
    The first argument will be preinserts, which are the necessary
    insertions that actual file metadata rely on. The second argument
    is just a collection of data triples so it can be inserted together
    with the rest of the data in the miner.

 data/dbus/tracker-extract.xml                      |    3 +-
 src/libtracker-extract/tracker-extract.h           |   39 ++++++---
 src/tracker-extract/tracker-extract-abw.c          |    3 +-
 .../tracker-extract-gstreamer-helix.c              |   17 +++-
 src/tracker-extract/tracker-extract-gstreamer.c    |   68 +++++++++------
 src/tracker-extract/tracker-extract-html.c         |    3 +-
 src/tracker-extract/tracker-extract-imagemagick.c  |   11 ++-
 src/tracker-extract/tracker-extract-jpeg.c         |    3 +-
 src/tracker-extract/tracker-extract-libxine.c      |   21 +++--
 src/tracker-extract/tracker-extract-mp3.c          |   27 +++---
 src/tracker-extract/tracker-extract-mplayer.c      |   19 ++---
 src/tracker-extract/tracker-extract-msoffice.c     |    5 +-
 src/tracker-extract/tracker-extract-oasis.c        |    7 +-
 src/tracker-extract/tracker-extract-pdf.c          |    3 +-
 src/tracker-extract/tracker-extract-playlist.c     |    7 +-
 src/tracker-extract/tracker-extract-png.c          |    7 +-
 src/tracker-extract/tracker-extract-ps.c           |    7 +-
 src/tracker-extract/tracker-extract-text.c         |    3 +-
 src/tracker-extract/tracker-extract-tiff.c         |    6 +-
 src/tracker-extract/tracker-extract-totem.c        |   27 +++---
 src/tracker-extract/tracker-extract-vorbis.c       |   25 +++---
 src/tracker-extract/tracker-extract-xmp.c          |    2 +
 src/tracker-extract/tracker-extract.c              |   94 +++++++++++++-------
 23 files changed, 247 insertions(+), 160 deletions(-)
---
diff --git a/data/dbus/tracker-extract.xml b/data/dbus/tracker-extract.xml
index 205ac81..acf5be8 100644
--- a/data/dbus/tracker-extract.xml
+++ b/data/dbus/tracker-extract.xml
@@ -19,7 +19,8 @@
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="s" name="uri" direction="in" />
       <arg type="s" name="mime" direction="in" />
-      <arg type="s" name="sparql" direction="out" />
+      <arg type="s" name="preinserts" direction="out" />
+      <arg type="s" name="embedded" direction="out" />
     </method>
   </interface>
 </node>
diff --git a/src/libtracker-extract/tracker-extract.h b/src/libtracker-extract/tracker-extract.h
index 8036af6..27b9595 100644
--- a/src/libtracker-extract/tracker-extract.h
+++ b/src/libtracker-extract/tracker-extract.h
@@ -57,31 +57,30 @@ G_BEGIN_DECLS
  *  };
  * 
  *  static void
- *  extract_png (const gchar         *uri,
- *              TrackerSparqlBuilder *metadata)
+ *  extract_png (const gchar          *uri,
+ *               TrackerSparqlBuilder *preinserts,
+ *               TrackerSparqlBuilder *metadata)
  *  {
- *          goffset size;
  *          gint height, width;
- *          gchar *filename = g_filename_from_uri (uri, NULL, NULL);
- * 
+ *
  *          /&ast; Do data extraction. &ast;/
  *          height = ...
  *          width = ...
  *
  *          /&ast; Insert data into TrackerSparqlBuilder object. &ast;/
- *          tracker_sparql_builder_subject_iri (metadata, uri);
  *          tracker_sparql_builder_predicate (metadata, "a");
  *          tracker_sparql_builder_object (metadata, "nfo:Image");
  *          tracker_sparql_builder_object (metadata, "nmm:Photo");
- * 
+ *
  *          tracker_sparql_builder_predicate (metadata, "nfo:width");
  *          tracker_sparql_builder_object_int64 (metadata, width);
+ *
  *          tracker_sparql_builder_predicate (metadata, "nfo:height");
  *          tracker_sparql_builder_object_int64 (metadata, height);
- * 
+ *
  *          g_free (filename);
  *  }
- * 
+ *
  *  TrackerExtractData *
  *  tracker_extract_get_data (void)
  *  {
@@ -96,14 +95,30 @@ G_BEGIN_DECLS
 /**
  * TrackerExtractMimeFunc:
  * @uri: a string representing a URI.
- * @metadata: used to populate with metadata.
- *
- * The @metadata is used to populate the extracted metadata from the
- * file using the #TrackerSparqlBuilder APIs.
+ * @preinserts: used to populate with data inserts that
+ *              are a prerequisite for the actual file
+ *              metadata insertion.
+ * @metadata: used to populate with file metadata predicate/object(s).
+ *
+ * Extracts metadata from a file, and inserts it into @metadata.
+ *
+ * The @metadata parameter is a #TrackerSparqlBuilder constructed
+ * through tracker_sparql_builder_new_embedded_insert(), The subject
+ * is already set to be the file URN, so implementations of this
+ * function should just provide predicate/object(s) pairs. the data
+ * triples contained in there at the end of the function will be
+ * merged with further file information from miners.
+ *
+ * Whenever any of the inserted triples rely on entities that
+ * should also be provided by this extractor (for example, album
+ * or artist information from a song), such insertions should be
+ * added to @preinserts, which is a #TrackerSparqlBuilder constructed.
+ * through tracker_sparql_builder_new_update().
  *
  * Since: 0.8
  **/
 typedef void (*TrackerExtractMimeFunc) (const gchar          *uri,
+					TrackerSparqlBuilder *preinsert,
                                         TrackerSparqlBuilder *metadata);
 
 /**
diff --git a/src/tracker-extract/tracker-extract-abw.c b/src/tracker-extract/tracker-extract-abw.c
index 90452dc..ad151b7 100644
--- a/src/tracker-extract/tracker-extract-abw.c
+++ b/src/tracker-extract/tracker-extract-abw.c
@@ -46,6 +46,7 @@
 #define RDF_TYPE RDF_PREFIX "type"
 
 static void extract_abw (const gchar          *uri,
+			 TrackerSparqlBuilder *preinserts,
                          TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -55,6 +56,7 @@ static TrackerExtractData data[] = {
 
 static void
 extract_abw (const gchar          *uri,
+	     TrackerSparqlBuilder *preinserts,
              TrackerSparqlBuilder *metadata)
 {
 	FILE *f;
@@ -72,7 +74,6 @@ extract_abw (const gchar          *uri,
 		line = NULL;
 		length = 0;
 
-		tracker_sparql_builder_subject_iri (metadata, uri);
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "nfo:Document");
 
diff --git a/src/tracker-extract/tracker-extract-gstreamer-helix.c b/src/tracker-extract/tracker-extract-gstreamer-helix.c
index 712036b..bf8d2da 100644
--- a/src/tracker-extract/tracker-extract-gstreamer-helix.c
+++ b/src/tracker-extract/tracker-extract-gstreamer-helix.c
@@ -69,8 +69,10 @@ typedef struct {
 } MetadataExtractor;
 
 static void extract_gstreamer_helix_audio (const gchar          *uri,
+					   TrackerSparqlBuilder *preinserts,
                                            TrackerSparqlBuilder *metadata);
 static void extract_gstreamer_helix_video (const gchar          *uri,
+					   TrackerSparqlBuilder *preinserts,
                                            TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -765,7 +767,8 @@ poll_for_state_change (MetadataExtractor *extractor,
 
 static void
 tracker_extract_gstreamer_helix (const gchar *uri,
-                                 TrackerSparqlBuilder  *metadata,
+				 TrackerSparqlBuilder *preinserts,
+                                 TrackerSparqlBuilder *metadata,
                                  ExtractMime    type)
 {
 	MetadataExtractor *extractor;
@@ -845,15 +848,19 @@ tracker_extract_gstreamer_helix (const gchar *uri,
 }
 
 static void
-extract_gstreamer_helix_audio (const gchar *uri, TrackerSparqlBuilder *metadata)
+extract_gstreamer_helix_audio (const gchar          *uri,
+			       TrackerSparqlBuilder *preinserts,
+			       TrackerSparqlBuilder *metadata)
 {
-	tracker_extract_gstreamer_helix (uri, metadata, EXTRACT_MIME_AUDIO);
+	tracker_extract_gstreamer_helix (uri, preinserts, metadata, EXTRACT_MIME_AUDIO);
 }
 
 static void
-extract_gstreamer_helix_video (const gchar *uri, TrackerSparqlBuilder *metadata)
+extract_gstreamer_helix_video (const gchar          *uri,
+			       TrackerSparqlBuilder *preinserts,
+			       TrackerSparqlBuilder *metadata)
 {
-	tracker_extract_gstreamer_helix (uri, metadata, EXTRACT_MIME_VIDEO);
+	tracker_extract_gstreamer_helix (uri, preinserts, metadata, EXTRACT_MIME_VIDEO);
 }
 
 TrackerExtractData *
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 213d44f..4055a67 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -124,12 +124,16 @@ typedef struct {
 } MetadataExtractor;
 
 static void extract_gstreamer_audio (const gchar          *uri,
+				     TrackerSparqlBuilder *preinserts,
                                      TrackerSparqlBuilder *metadata);
 static void extract_gstreamer_video (const gchar          *uri,
+				     TrackerSparqlBuilder *preinserts,
                                      TrackerSparqlBuilder *metadata);
 static void extract_gstreamer_image (const gchar          *uri,
+				     TrackerSparqlBuilder *preinserts,
                                      TrackerSparqlBuilder *metadata);
 static void extract_gstreamer_3gpp  (const gchar          *uri,
+				     TrackerSparqlBuilder *preinserts,
                                      TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -445,6 +449,7 @@ extract_stream_metadata_decodebin (MetadataExtractor *extractor,
 static void
 extract_metadata (MetadataExtractor      *extractor,
                   const gchar            *uri,
+		  TrackerSparqlBuilder   *preinserts,
                   TrackerSparqlBuilder   *metadata,
                   gchar                 **album,
                   gchar                 **scount)
@@ -489,11 +494,11 @@ extract_metadata (MetadataExtractor      *extractor,
 			if (s) {
 				performer_uri = tracker_uri_printf_escaped ("urn:artist:%s", s);
 
-				tracker_sparql_builder_subject_iri (metadata, performer_uri);
-				tracker_sparql_builder_predicate (metadata, "a");
-				tracker_sparql_builder_object (metadata, "nmm:Artist");
-				tracker_sparql_builder_predicate (metadata, "nmm:artistName");
-				tracker_sparql_builder_object_unvalidated (metadata, s);
+				tracker_sparql_builder_subject_iri (preinserts, performer_uri);
+				tracker_sparql_builder_predicate (preinserts, "a");
+				tracker_sparql_builder_object (preinserts, "nmm:Artist");
+				tracker_sparql_builder_predicate (preinserts, "nmm:artistName");
+				tracker_sparql_builder_object_unvalidated (preinserts, s);
 
 				g_free (s);
 			}
@@ -504,9 +509,9 @@ extract_metadata (MetadataExtractor      *extractor,
 			if (s) {
 				gchar *canonical_uri = tracker_uri_printf_escaped ("urn:artist:%s", s);
 
-				tracker_sparql_builder_subject_iri (metadata, canonical_uri);
-				tracker_sparql_builder_predicate (metadata, "a");
-				tracker_sparql_builder_object (metadata, "nmm:Artist");
+				tracker_sparql_builder_subject_iri (preinserts, canonical_uri);
+				tracker_sparql_builder_predicate (preinserts, "a");
+				tracker_sparql_builder_object (preinserts, "nmm:Artist");
 
 				/*
 				if (extractor->mime == EXTRACT_MIME_AUDIO) {
@@ -515,8 +520,8 @@ extract_metadata (MetadataExtractor      *extractor,
 					tracker_sparql_builder_object (metadata, "nmm:director");
 				}
 				*/
-				tracker_sparql_builder_predicate (metadata, "nmm:artistName");
-				tracker_sparql_builder_object_unvalidated (metadata, s);
+				tracker_sparql_builder_predicate (preinserts, "nmm:artistName");
+				tracker_sparql_builder_object_unvalidated (preinserts, s);
 
 				g_free (canonical_uri);
 				g_free (s);
@@ -530,18 +535,18 @@ extract_metadata (MetadataExtractor      *extractor,
 			gst_tag_list_get_string (extractor->tagcache, GST_TAG_ALBUM, &s);
 			if (s) {
 				album_uri = tracker_uri_printf_escaped ("urn:album:%s", s);
-				tracker_sparql_builder_subject_iri (metadata, album_uri);
-				tracker_sparql_builder_predicate (metadata, "a");
-				tracker_sparql_builder_object (metadata, "nmm:MusicAlbum");
-				tracker_sparql_builder_predicate (metadata, "nmm:albumTitle");
-				tracker_sparql_builder_object_unvalidated (metadata, s);
-				add_uint_gst_tag (metadata, album_uri, "nmm:albumTrackCount", extractor->tagcache, GST_TAG_TRACK_COUNT);
-				add_uint_gst_tag (metadata, album_uri, "nmm:setNumber", extractor->tagcache, GST_TAG_ALBUM_VOLUME_NUMBER);
+
+				tracker_sparql_builder_subject_iri (preinserts, album_uri);
+				tracker_sparql_builder_predicate (preinserts, "a");
+				tracker_sparql_builder_object (preinserts, "nmm:MusicAlbum");
+				tracker_sparql_builder_predicate (preinserts, "nmm:albumTitle");
+				tracker_sparql_builder_object_unvalidated (preinserts, s);
+				add_uint_gst_tag (preinserts, album_uri, "nmm:albumTrackCount", extractor->tagcache, GST_TAG_TRACK_COUNT);
+				add_uint_gst_tag (preinserts, album_uri, "nmm:setNumber", extractor->tagcache, GST_TAG_ALBUM_VOLUME_NUMBER);
 				*album = s;
 			}
 		}
 
-		tracker_sparql_builder_subject_iri (metadata, uri);
 		tracker_sparql_builder_predicate (metadata, "a");
 
 		if (extractor->mime == EXTRACT_MIME_AUDIO) {
@@ -893,6 +898,7 @@ create_tagreadbin_pipeline (MetadataExtractor *extractor, const gchar *uri)
 
 static void
 tracker_extract_gstreamer (const gchar *uri,
+			   TrackerSparqlBuilder  *preinserts,
                            TrackerSparqlBuilder  *metadata,
                            ExtractMime  type)
 {
@@ -963,7 +969,7 @@ tracker_extract_gstreamer (const gchar *uri,
 	album = NULL;
 	scount = NULL;
 
-	extract_metadata (extractor, uri, metadata, &album, &scount);
+	extract_metadata (extractor, uri, preinserts, metadata, &album, &scount);
 
 	tracker_albumart_process (extractor->album_art_data,
 	                          extractor->album_art_size,
@@ -989,27 +995,35 @@ tracker_extract_gstreamer (const gchar *uri,
 
 
 static void
-extract_gstreamer_audio (const gchar *uri, TrackerSparqlBuilder *metadata)
+extract_gstreamer_audio (const gchar          *uri,
+			 TrackerSparqlBuilder *preinserts,
+			 TrackerSparqlBuilder *metadata)
 {
-	tracker_extract_gstreamer (uri, metadata, EXTRACT_MIME_AUDIO);
+	tracker_extract_gstreamer (uri, preinserts, metadata, EXTRACT_MIME_AUDIO);
 }
 
 static void
-extract_gstreamer_video (const gchar *uri, TrackerSparqlBuilder *metadata)
+extract_gstreamer_video (const gchar          *uri,
+			 TrackerSparqlBuilder *preinserts,
+			 TrackerSparqlBuilder *metadata)
 {
-	tracker_extract_gstreamer (uri, metadata, EXTRACT_MIME_VIDEO);
+	tracker_extract_gstreamer (uri, preinserts, metadata, EXTRACT_MIME_VIDEO);
 }
 
 static void
-extract_gstreamer_image (const gchar *uri, TrackerSparqlBuilder *metadata)
+extract_gstreamer_image (const gchar          *uri,
+			 TrackerSparqlBuilder *preinserts,
+			 TrackerSparqlBuilder *metadata)
 {
-	tracker_extract_gstreamer (uri, metadata, EXTRACT_MIME_IMAGE);
+	tracker_extract_gstreamer (uri, preinserts, metadata, EXTRACT_MIME_IMAGE);
 }
 
 static void
-extract_gstreamer_3gpp (const gchar *uri, TrackerSparqlBuilder *metadata)
+extract_gstreamer_3gpp (const gchar          *uri,
+			TrackerSparqlBuilder *preinserts,
+			TrackerSparqlBuilder *metadata)
 {
-	tracker_extract_gstreamer (uri, metadata, EXTRACT_MIME_3GPP);
+	tracker_extract_gstreamer (uri, preinserts, metadata, EXTRACT_MIME_3GPP);
 }
 
 TrackerExtractData *
diff --git a/src/tracker-extract/tracker-extract-html.c b/src/tracker-extract/tracker-extract-html.c
index c8dceaf..15578fe 100644
--- a/src/tracker-extract/tracker-extract-html.c
+++ b/src/tracker-extract/tracker-extract-html.c
@@ -43,6 +43,7 @@ typedef struct {
 } parser_data;
 
 static void extract_html (const gchar          *filename,
+			  TrackerSparqlBuilder *preinserts,
                           TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -197,6 +198,7 @@ parser_characters (void          *data,
 
 static void
 extract_html (const gchar          *uri,
+	      TrackerSparqlBuilder *preinserts,
               TrackerSparqlBuilder *metadata)
 {
 	htmlDocPtr doc;
@@ -237,7 +239,6 @@ extract_html (const gchar          *uri,
 		NULL  /* xmlStructuredErrorFunc */
 	};
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nfo:Document");
 
diff --git a/src/tracker-extract/tracker-extract-imagemagick.c b/src/tracker-extract/tracker-extract-imagemagick.c
index d065dec..23a9043 100644
--- a/src/tracker-extract/tracker-extract-imagemagick.c
+++ b/src/tracker-extract/tracker-extract-imagemagick.c
@@ -41,8 +41,9 @@
 #define RDF_PREFIX TRACKER_RDF_PREFIX
 #define RDF_TYPE RDF_PREFIX "type"
 
-static void extract_imagemagick (const gchar *uri,
-                                 TrackerSparqlBuilder   *metadata);
+static void extract_imagemagick (const gchar          *uri,
+				 TrackerSparqlBuilder *preinserts,
+                                 TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
 	{ "image/*", extract_imagemagick },
@@ -50,8 +51,9 @@ static TrackerExtractData data[] = {
 };
 
 static void
-extract_imagemagick (const gchar *uri,
-                     TrackerSparqlBuilder   *metadata)
+extract_imagemagick (const gchar          *uri,
+		     TrackerSparqlBuilder *preinserts,
+                     TrackerSparqlBuilder *metadata)
 {
 	gchar *argv[6];
 	gchar *identify;
@@ -83,7 +85,6 @@ extract_imagemagick (const gchar *uri,
 
 	argv[5] = NULL;
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_predicate (metadata, "nfo:Image");
 
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index d467ec3..f45528d 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -93,6 +93,7 @@ typedef struct {
 } MergeData;
 
 static void extract_jpeg (const gchar          *filename,
+			  TrackerSparqlBuilder *preinserts,
                           TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -152,6 +153,7 @@ extract_jpeg_error_exit (j_common_ptr cinfo)
 
 static void
 extract_jpeg (const gchar          *uri,
+	      TrackerSparqlBuilder *preinserts,
               TrackerSparqlBuilder *metadata)
 {
 	struct jpeg_decompress_struct cinfo;
@@ -179,7 +181,6 @@ extract_jpeg (const gchar          *uri,
 		MergeData md = { 0 };
 		gchar *comment = NULL;
 
-		tracker_sparql_builder_subject_iri (metadata, uri);
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "nfo:Image");
 		tracker_sparql_builder_predicate (metadata, "a");
diff --git a/src/tracker-extract/tracker-extract-libxine.c b/src/tracker-extract/tracker-extract-libxine.c
index 47d5abc..5eb1c51 100644
--- a/src/tracker-extract/tracker-extract-libxine.c
+++ b/src/tracker-extract/tracker-extract-libxine.c
@@ -38,7 +38,9 @@
 #define RDF_TYPE RDF_PREFIX "type"
 
 static void
-tracker_extract_xine (const gchar *uri, TrackerSparqlBuilder *metadata)
+tracker_extract_xine (const gchar          *uri,
+		      TrackerSparqlBuilder *preinserts,
+		      TrackerSparqlBuilder *metadata)
 {
 	xine_t            *xine_base;
 	xine_audio_port_t *audio_port;
@@ -108,9 +110,9 @@ tracker_extract_xine (const gchar *uri, TrackerSparqlBuilder *metadata)
 	if (author) {
 		gchar *canonical_uri = tracker_uri_printf_escaped ("urn:artist:%s", author);
 
-		tracker_sparql_builder_subject_iri (metadata, canonical_uri);
-		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "nmm:Artist");
+		tracker_sparql_builder_subject_iri (preinserts, canonical_uri);
+		tracker_sparql_builder_predicate (preinserts, "a");
+		tracker_sparql_builder_object (preinserts, "nmm:Artist");
 
 		g_free (canonical_uri);
 	}
@@ -119,16 +121,15 @@ tracker_extract_xine (const gchar *uri, TrackerSparqlBuilder *metadata)
 	if (album) {
 		gchar *canonical_uri = tracker_uri_printf_escaped ("urn:album:%s", album);
 
-		tracker_sparql_builder_subject_iri (metadata, canonical_uri);
-		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "nmm:MusicAlbum");
-		tracker_sparql_builder_predicate (metadata, "nmm:albumTitle");
-		tracker_sparql_builder_object_unvalidated (metadata, album);
+		tracker_sparql_builder_subject_iri (preinserts, canonical_uri);
+		tracker_sparql_builder_predicate (preinserts, "a");
+		tracker_sparql_builder_object (preinserts, "nmm:MusicAlbum");
+		tracker_sparql_builder_predicate (preinserts, "nmm:albumTitle");
+		tracker_sparql_builder_object_unvalidated (preinserts, album);
 
 		g_free (canonical_uri);
 	}
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 
 	if (has_video) {
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 1dfe101..aae185c 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -173,6 +173,7 @@ typedef struct {
 } MP3Data;
 
 static void extract_mp3 (const gchar           *uri,
+			 TrackerSparqlBuilder  *preinserts,
                          TrackerSparqlBuilder  *metadata);
 
 enum {
@@ -1853,6 +1854,7 @@ parse_id3v2 (const gchar          *data,
 
 static void
 extract_mp3 (const gchar          *uri,
+	     TrackerSparqlBuilder *preinserts,
              TrackerSparqlBuilder *metadata)
 {
 	gchar *filename;
@@ -1973,31 +1975,30 @@ extract_mp3 (const gchar          *uri,
 
 	if (md.performer) {
 		md.performer_uri = tracker_uri_printf_escaped ("urn:artist:%s", md.performer);
-		tracker_sparql_builder_subject_iri (metadata, md.performer_uri);
-		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "nmm:Artist");
-		tracker_sparql_builder_predicate (metadata, "nmm:artistName");
-		tracker_sparql_builder_object_unvalidated (metadata, md.performer);
+		tracker_sparql_builder_subject_iri (preinserts, md.performer_uri);
+		tracker_sparql_builder_predicate (preinserts, "a");
+		tracker_sparql_builder_object (preinserts, "nmm:Artist");
+		tracker_sparql_builder_predicate (preinserts, "nmm:artistName");
+		tracker_sparql_builder_object_unvalidated (preinserts, md.performer);
 		g_free (md.performer);
 	}
 
 	if (md.album) {
 		md.album_uri = tracker_uri_printf_escaped ("urn:album:%s", md.album);
-		tracker_sparql_builder_subject_iri (metadata, md.album_uri);
-		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "nmm:MusicAlbum");
-		tracker_sparql_builder_predicate (metadata, "nmm:albumTitle");
-		tracker_sparql_builder_object_unvalidated (metadata, md.album);
+		tracker_sparql_builder_subject_iri (preinserts, md.album_uri);
+		tracker_sparql_builder_predicate (preinserts, "a");
+		tracker_sparql_builder_object (preinserts, "nmm:MusicAlbum");
+		tracker_sparql_builder_predicate (preinserts, "nmm:albumTitle");
+		tracker_sparql_builder_object_unvalidated (preinserts, md.album);
 
 		if (md.track_count > 0) {
-			tracker_sparql_builder_predicate (metadata, "nmm:albumTrackCount");
-			tracker_sparql_builder_object_int64 (metadata, md.track_count);
+			tracker_sparql_builder_predicate (preinserts, "nmm:albumTrackCount");
+			tracker_sparql_builder_object_int64 (preinserts, md.track_count);
 		}
 
 		g_free (md.album);
 	}
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
 	tracker_sparql_builder_object (metadata, "nfo:Audio");
diff --git a/src/tracker-extract/tracker-extract-mplayer.c b/src/tracker-extract/tracker-extract-mplayer.c
index 3290a35..d6e7514 100644
--- a/src/tracker-extract/tracker-extract-mplayer.c
+++ b/src/tracker-extract/tracker-extract-mplayer.c
@@ -85,6 +85,7 @@ static const gchar *info_tags[][2] = {
 };
 
 typedef struct {
+	TrackerSparqlBuilder *preinserts;
 	TrackerSparqlBuilder *metadata;
 	const gchar *uri;
 } ForeachCopyInfo;
@@ -99,14 +100,13 @@ copy_hash_table_entry (gpointer key,
 	if (g_strcmp0 (key, "nmm:performer") == 0) {
 		gchar *canonical_uri = tracker_uri_printf_escaped ("urn:artist:%s", value);
 
-		tracker_sparql_builder_subject_iri (info->metadata, canonical_uri);
-		tracker_sparql_builder_predicate (info->metadata, "a");
-		tracker_sparql_builder_object (info->metadata, "nmm:Artist");
+		tracker_sparql_builder_subject_iri (info->preinserts, canonical_uri);
+		tracker_sparql_builder_predicate (info->preinserts, "a");
+		tracker_sparql_builder_object (info->preinserts, "nmm:Artist");
 
-		tracker_sparql_builder_predicate (info->metadata, "nmm:artistName");
-		tracker_sparql_builder_object_unvalidated (info->metadata, value);
+		tracker_sparql_builder_predicate (info->preinserts, "nmm:artistName");
+		tracker_sparql_builder_object_unvalidated (info->preinserts, value);
 
-		tracker_sparql_builder_subject_iri (info->metadata, info->uri);
 		g_free (canonical_uri);
 	} else {
 		tracker_sparql_builder_predicate (info->metadata, key);
@@ -252,12 +252,11 @@ extract_mplayer (const gchar *uri,
 		g_pattern_spec_free (pattern_ID_LENGTH);
 
 		if (has_video) {
-			tracker_sparql_builder_subject_iri (metadata, uri);
 			tracker_sparql_builder_predicate (metadata, "a");
 			tracker_sparql_builder_object (metadata, "nmm:Video");
 
 			if (tmp_metadata_video) {
-				ForeachCopyInfo info = { metadata, uri };
+				ForeachCopyInfo info = { preinserts, metadata, uri };
 				g_hash_table_foreach (tmp_metadata_video,
 				                      copy_hash_table_entry,
 				                      &info);
@@ -271,13 +270,12 @@ extract_mplayer (const gchar *uri,
 				g_free (duration);
 			}
 		} else if (has_audio) {
-			tracker_sparql_builder_subject_iri (metadata, uri);
 			tracker_sparql_builder_predicate (metadata, "a");
 			tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
 			tracker_sparql_builder_object (metadata, "nfo:Audio");
 
 			if (tmp_metadata_audio) {
-				ForeachCopyInfo info = { metadata, uri };
+				ForeachCopyInfo info = { preinserts, metadata, uri };
 				g_hash_table_foreach (tmp_metadata_audio,
 				                      copy_hash_table_entry,
 				                      &info);
@@ -291,7 +289,6 @@ extract_mplayer (const gchar *uri,
 				g_free (duration);
 			}
 		} else {
-			tracker_sparql_builder_subject_iri (metadata, uri);
 			tracker_sparql_builder_predicate (metadata, "a");
 			tracker_sparql_builder_object (metadata, "nfo:FileDataObject");
 		}
diff --git a/src/tracker-extract/tracker-extract-msoffice.c b/src/tracker-extract/tracker-extract-msoffice.c
index c795cf7..b264966 100644
--- a/src/tracker-extract/tracker-extract-msoffice.c
+++ b/src/tracker-extract/tracker-extract-msoffice.c
@@ -83,8 +83,10 @@
 #define SLIDELISTWITHTEXT_RECORD_TYPE           0x0FF0
 
 static void extract_msoffice   (const gchar          *uri,
+				TrackerSparqlBuilder *preinserts,
                                 TrackerSparqlBuilder *metadata);
 static void extract_powerpoint (const gchar          *uri,
+				TrackerSparqlBuilder *preinserts,
                                 TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -894,7 +896,6 @@ extract_summary (TrackerSparqlBuilder *metadata,
 	gchar    *content;
 	gboolean  is_encrypted = FALSE;
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nfo:PaginatedTextDocument");
 
@@ -1002,6 +1003,7 @@ open_uri (const gchar *uri)
  */
 static void
 extract_msoffice (const gchar          *uri,
+		  TrackerSparqlBuilder *preinserts,
                   TrackerSparqlBuilder *metadata)
 {
 	GsfInfile *infile = open_uri(uri);
@@ -1019,6 +1021,7 @@ extract_msoffice (const gchar          *uri,
  */
 static void
 extract_powerpoint (const gchar          *uri,
+		    TrackerSparqlBuilder *preinserts,
                     TrackerSparqlBuilder *metadata)
 {
 	GsfInfile *infile = open_uri(uri);
diff --git a/src/tracker-extract/tracker-extract-oasis.c b/src/tracker-extract/tracker-extract-oasis.c
index 1241912..6ab92a8 100644
--- a/src/tracker-extract/tracker-extract-oasis.c
+++ b/src/tracker-extract/tracker-extract-oasis.c
@@ -71,6 +71,7 @@ static void text_handler          (GMarkupParseContext   *context,
                                    gpointer               user_data,
                                    GError               **error);
 static void extract_oasis         (const gchar           *filename,
+				   TrackerSparqlBuilder  *preinserts,
                                    TrackerSparqlBuilder  *metadata);
 
 static TrackerExtractData extract_data[] = {
@@ -104,8 +105,9 @@ extract_content (const gchar *path,
 }
 
 static void
-extract_oasis (const gchar *uri,
-               TrackerSparqlBuilder   *metadata)
+extract_oasis (const gchar          *uri,
+	       TrackerSparqlBuilder *preinserts,
+               TrackerSparqlBuilder *metadata)
 {
 	gchar         *argv[5];
 	gchar         *xml;
@@ -127,7 +129,6 @@ extract_oasis (const gchar *uri,
 
 	/* Question: shouldn't we g_unlink meta.xml then? */
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nfo:PaginatedTextDocument");
 
diff --git a/src/tracker-extract/tracker-extract-pdf.c b/src/tracker-extract/tracker-extract-pdf.c
index 3b9cfc5..497d1b2 100644
--- a/src/tracker-extract/tracker-extract-pdf.c
+++ b/src/tracker-extract/tracker-extract-pdf.c
@@ -45,6 +45,7 @@ typedef struct {
 } PDFData;
 
 static void extract_pdf (const gchar          *uri,
+			 TrackerSparqlBuilder *preinserts,
                          TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -166,6 +167,7 @@ write_pdf_data (PDFData               data,
 
 static void
 extract_pdf (const gchar          *uri,
+	     TrackerSparqlBuilder *preinserts,
              TrackerSparqlBuilder *metadata)
 {
 	TrackerFTSConfig *fts_config;
@@ -199,7 +201,6 @@ extract_pdf (const gchar          *uri,
 		return;
 	}
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nfo:PaginatedTextDocument");
 
diff --git a/src/tracker-extract/tracker-extract-playlist.c b/src/tracker-extract/tracker-extract-playlist.c
index 92ea002..bfc10fd 100644
--- a/src/tracker-extract/tracker-extract-playlist.c
+++ b/src/tracker-extract/tracker-extract-playlist.c
@@ -60,6 +60,7 @@ typedef struct {
 } PlaylistMetadata;
 
 static void extract_playlist (const gchar          *uri,
+			      TrackerSparqlBuilder *preinserts,
                               TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData playlist_data[] = {
@@ -125,8 +126,9 @@ entry_parsed (TotemPlParser *parser, const gchar *to_uri, GHashTable *to_metadat
 }
 
 static void
-extract_playlist (const gchar *uri,
-                  TrackerSparqlBuilder   *metadata)
+extract_playlist (const gchar          *uri,
+		  TrackerSparqlBuilder *preinserts,
+                  TrackerSparqlBuilder *metadata)
 {
 	TotemPlParser       *pl;
 	TotemPlParserResult  result;
@@ -139,7 +141,6 @@ extract_playlist (const gchar *uri,
 	g_signal_connect (G_OBJECT (pl), "entry-parsed",
 	                  G_CALLBACK (entry_parsed), &data);
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nfo:MediaList");
 
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 54986e6..18be0a6 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -65,6 +65,7 @@ typedef struct {
 
 static gchar *rfc1123_to_iso8601_date (gchar                *rfc_date);
 static void   extract_png             (const gchar          *filename,
+				       TrackerSparqlBuilder *preinserts,
                                        TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -441,8 +442,9 @@ read_metadata (png_structp png_ptr, png_infop info_ptr, const gchar *uri, Tracke
 }
 
 static void
-extract_png (const gchar *uri,
-             TrackerSparqlBuilder   *metadata)
+extract_png (const gchar          *uri,
+	     TrackerSparqlBuilder *preinserts,
+             TrackerSparqlBuilder *metadata)
 {
 	goffset      size;
 	FILE        *f;
@@ -535,7 +537,6 @@ extract_png (const gchar *uri,
 
 		png_read_end (png_ptr, end_ptr);
 
-		tracker_sparql_builder_subject_iri (metadata, uri);
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "nfo:Image");
 		tracker_sparql_builder_object (metadata, "nmm:Photo");
diff --git a/src/tracker-extract/tracker-extract-ps.c b/src/tracker-extract/tracker-extract-ps.c
index 1a8d2e5..3c79077 100644
--- a/src/tracker-extract/tracker-extract-ps.c
+++ b/src/tracker-extract/tracker-extract-ps.c
@@ -56,9 +56,11 @@
 
 #ifdef USING_UNZIPPSFILES
 static void extract_ps_gz (const gchar          *uri,
+			   TrackerSparqlBuilder *preinserts,
                            TrackerSparqlBuilder *metadata);
 #endif
 static void extract_ps    (const gchar          *uri,
+			   TrackerSparqlBuilder *preinserts,
                            TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -205,6 +207,7 @@ date_to_iso8601 (const gchar *date)
 
 static void
 extract_ps (const gchar          *uri,
+	    TrackerSparqlBuilder *preinserts,
             TrackerSparqlBuilder *metadata)
 {
 	FILE *f;
@@ -224,7 +227,6 @@ extract_ps (const gchar          *uri,
 	line = NULL;
 	length = 0;
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nfo:PaginatedTextDocument");
 
@@ -291,6 +293,7 @@ extract_ps (const gchar          *uri,
 
 static void
 extract_ps_gz (const gchar          *uri,
+	       TrackerSparqlBuilder *preinserts,
                TrackerSparqlBuilder *metadata)
 {
 	FILE *fz, *f;
@@ -380,7 +383,7 @@ extract_ps_gz (const gchar          *uri,
 		fclose (f);
 	}
 
-	extract_ps (gunzipped, metadata);
+	extract_ps (gunzipped, preinserts, metadata);
 	g_unlink (gunzipped);
 	g_free (filename);
 }
diff --git a/src/tracker-extract/tracker-extract-text.c b/src/tracker-extract/tracker-extract-text.c
index 8e222ea..6354741 100644
--- a/src/tracker-extract/tracker-extract-text.c
+++ b/src/tracker-extract/tracker-extract-text.c
@@ -31,6 +31,7 @@
 #define TEXT_CHECK_SIZE 65535    /* bytes */
 
 static void extract_text (const gchar          *uri,
+			  TrackerSparqlBuilder *preinserts,
                           TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -274,6 +275,7 @@ get_file_content (const gchar *uri)
 
 static void
 extract_text (const gchar          *uri,
+	      TrackerSparqlBuilder *preinserts,
               TrackerSparqlBuilder *metadata)
 {
 	gchar *content;
@@ -282,7 +284,6 @@ extract_text (const gchar          *uri,
 
 	content = get_file_content (uri);
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nfo:PlainTextDocument");
 
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index 31d5408..6a993f4 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -77,6 +77,7 @@ typedef struct {
 } TiffData;
 
 static void extract_tiff (const gchar          *filename,
+			  TrackerSparqlBuilder *preinserts,
                           TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData extract_data[] = {
@@ -269,7 +270,9 @@ insert_keywords (TrackerSparqlBuilder *metadata, const gchar *uri, gchar *keywor
 }
 
 static void
-extract_tiff (const gchar *uri, TrackerSparqlBuilder *metadata)
+extract_tiff (const gchar          *uri,
+	      TrackerSparqlBuilder *preinserts,
+	      TrackerSparqlBuilder *metadata)
 {
 	TIFF *image;
 	glong exifOffset;
@@ -296,7 +299,6 @@ extract_tiff (const gchar *uri, TrackerSparqlBuilder *metadata)
 		return;
 	}
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nfo:Image");
 	tracker_sparql_builder_object (metadata, "nmm:Photo");
diff --git a/src/tracker-extract/tracker-extract-totem.c b/src/tracker-extract/tracker-extract-totem.c
index 54207ca..8251850 100644
--- a/src/tracker-extract/tracker-extract-totem.c
+++ b/src/tracker-extract/tracker-extract-totem.c
@@ -54,6 +54,7 @@ static const gchar *tags[][2] = {
 };
 
 static void extract_totem (const gchar          *uri,
+			   TrackerSparqlBuilder *preinserts,
                            TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -75,6 +76,7 @@ metadata_write_foreach (gpointer key,
 
 static void
 extract_totem (const gchar          *uri,
+	       TrackerSparqlBuilder *preinserts,
                TrackerSparqlBuilder *metadata)
 {
 	gchar *argv[3];
@@ -124,29 +126,28 @@ extract_totem (const gchar          *uri,
 		}
 
 		if (artist) {
-			tracker_sparql_builder_subject_iri (metadata, artist_uri);
-			tracker_sparql_builder_predicate (metadata, "a");
-			tracker_sparql_builder_object (metadata, "nmm:Artist");
+			tracker_sparql_builder_subject_iri (preinserts, artist_uri);
+			tracker_sparql_builder_predicate (preinserts, "a");
+			tracker_sparql_builder_object (preinserts, "nmm:Artist");
 
 			if (has_video) {
-				tracker_sparql_builder_object (metadata, "nmm:director");
+				tracker_sparql_builder_object (preinserts, "nmm:director");
 			} else {
-				tracker_sparql_builder_object (metadata, "nmm:composer");
+				tracker_sparql_builder_object (preinserts, "nmm:composer");
 			}
 
-			tracker_sparql_builder_predicate (metadata, "nmm:artistName");
-			tracker_sparql_builder_object_unvalidated (metadata, artist);
+			tracker_sparql_builder_predicate (preinserts, "nmm:artistName");
+			tracker_sparql_builder_object_unvalidated (preinserts, artist);
 		}
 
 		if (album) {
-			tracker_sparql_builder_subject_iri (metadata, album_uri);
-			tracker_sparql_builder_predicate (metadata, "a");
-			tracker_sparql_builder_object (metadata, "nmm:MusicAlbum");
-			tracker_sparql_builder_predicate (metadata, "nmm:albumTitle");
-			tracker_sparql_builder_object_unvalidated (metadata, album);
+			tracker_sparql_builder_subject_iri (preinserts, album_uri);
+			tracker_sparql_builder_predicate (preinserts, "a");
+			tracker_sparql_builder_object (preinserts, "nmm:MusicAlbum");
+			tracker_sparql_builder_predicate (preinserts, "nmm:albumTitle");
+			tracker_sparql_builder_object_unvalidated (preinserts, album);
 		}
 
-		tracker_sparql_builder_subject_iri (metadata, uri);
 		tracker_sparql_builder_predicate (metadata, "a");
 
 		if (has_video) {
diff --git a/src/tracker-extract/tracker-extract-vorbis.c b/src/tracker-extract/tracker-extract-vorbis.c
index c3b4b6f..034233a 100644
--- a/src/tracker-extract/tracker-extract-vorbis.c
+++ b/src/tracker-extract/tracker-extract-vorbis.c
@@ -40,7 +40,8 @@
 #define NMM_PREFIX TRACKER_NMM_PREFIX
 #define RDF_PREFIX TRACKER_RDF_PREFIX
 
-static void extract_vorbis (const char *uri,
+static void extract_vorbis (const char            *uri,
+			    TrackerSparqlBuilder  *preinserts,
                             TrackerSparqlBuilder  *metadata);
 
 
@@ -82,6 +83,7 @@ ogg_get_comment (vorbis_comment *vc,
 
 static void
 extract_vorbis (const char *uri,
+		TrackerSparqlBuilder *preinserts,
                 TrackerSparqlBuilder *metadata)
 {
 	FILE           *f;
@@ -149,22 +151,22 @@ extract_vorbis (const char *uri,
 	if (merge_data.creator) {
 		artist_uri = tracker_uri_printf_escaped ("urn:artist:%s", merge_data.creator);
 
-		tracker_sparql_builder_subject_iri (metadata, artist_uri);
-		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "nmm:Artist");
-		tracker_sparql_builder_predicate (metadata, "nmm:artistName");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.creator);
+		tracker_sparql_builder_subject_iri (preinserts, artist_uri);
+		tracker_sparql_builder_predicate (preinserts, "a");
+		tracker_sparql_builder_object (preinserts, "nmm:Artist");
+		tracker_sparql_builder_predicate (preinserts, "nmm:artistName");
+		tracker_sparql_builder_object_unvalidated (preinserts, merge_data.creator);
 		g_free (merge_data.creator);
 	}
 
 	if (vorbis_data.album) {
 		album_uri = tracker_uri_printf_escaped ("urn:album:%s", vorbis_data.album);
 
-		tracker_sparql_builder_subject_iri (metadata, album_uri);
-		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "nmm:MusicAlbum");
-		tracker_sparql_builder_predicate (metadata, "nmm:albumTitle");
-		tracker_sparql_builder_object_unvalidated (metadata, vorbis_data.album);
+		tracker_sparql_builder_subject_iri (preinserts, album_uri);
+		tracker_sparql_builder_predicate (preinserts, "a");
+		tracker_sparql_builder_object (preinserts, "nmm:MusicAlbum");
+		tracker_sparql_builder_predicate (preinserts, "nmm:albumTitle");
+		tracker_sparql_builder_object_unvalidated (preinserts, vorbis_data.album);
 
 
 		if (vorbis_data.trackcount) {
@@ -176,7 +178,6 @@ extract_vorbis (const char *uri,
 		g_free (vorbis_data.album);
 	}
 
-	tracker_sparql_builder_subject_iri (metadata, uri);
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
 	tracker_sparql_builder_object (metadata, "nfo:Audio");
diff --git a/src/tracker-extract/tracker-extract-xmp.c b/src/tracker-extract/tracker-extract-xmp.c
index 3bb6870..6f7759b 100644
--- a/src/tracker-extract/tracker-extract-xmp.c
+++ b/src/tracker-extract/tracker-extract-xmp.c
@@ -31,6 +31,7 @@
 #include <libtracker-extract/tracker-xmp.h>
 
 static void extract_xmp (const gchar          *filename,
+			 TrackerSparqlBuilder *preinserts,
                          TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
@@ -136,6 +137,7 @@ find_orig_uri (const gchar *xmp_filename)
 
 static void
 extract_xmp (const gchar          *uri,
+	     TrackerSparqlBuilder *preinserts,
              TrackerSparqlBuilder *metadata)
 {
 	gchar *contents;
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 49eca3a..45ab5f9 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -207,24 +207,28 @@ tracker_extract_new (gboolean disable_shutdown,
 	return object;
 }
 
-static TrackerSparqlBuilder *
-get_file_metadata (TrackerExtract        *extract,
-                   guint                  request_id,
-                   DBusGMethodInvocation *context,
-                   const gchar           *uri,
-                   const gchar           *mime)
+static gboolean
+get_file_metadata (TrackerExtract         *extract,
+                   guint                   request_id,
+                   DBusGMethodInvocation  *context,
+                   const gchar            *uri,
+                   const gchar            *mime,
+		   TrackerSparqlBuilder  **preinserts_out,
+		   TrackerSparqlBuilder  **statements_out)
 {
 	TrackerExtractPrivate *priv;
-	TrackerSparqlBuilder *statements;
+	TrackerSparqlBuilder *statements, *preinserts;
 	gchar *mime_used = NULL;
 	gchar *content_type = NULL;
 
 	priv = TRACKER_EXTRACT_GET_PRIVATE (extract);
 
-	/* Create hash table to send back */
-	statements = tracker_sparql_builder_new_update ();
+	/* Create sparql builders to send back */
+	preinserts = tracker_sparql_builder_new_update ();
+	statements = tracker_sparql_builder_new_embedded_insert ();
 
-	tracker_sparql_builder_insert_open (statements, uri);
+	tracker_sparql_builder_insert_open (preinserts, NULL);
+	tracker_sparql_builder_subject (statements, "_:foo");
 
 #ifdef HAVE_LIBSTREAMANALYZER
 	if (!priv->force_internal_extractors) {
@@ -236,7 +240,7 @@ get_file_metadata (TrackerExtract        *extract,
 		if (tracker_sparql_builder_get_length (statements) > 0) {
 			g_free (content_type);
 			tracker_sparql_builder_insert_close (statements);
-			return statements;
+			return TRUE;
 		}
 	} else {
 		tracker_dbus_request_comment (request_id,
@@ -262,7 +266,7 @@ get_file_metadata (TrackerExtract        *extract,
 			g_warning ("Could not create GFile for uri:'%s'",
 			           uri);
 			g_object_unref (statements);
-			return NULL;
+			return FALSE;
 		}
 
 		info = g_file_query_info (file,
@@ -284,7 +288,9 @@ get_file_metadata (TrackerExtract        *extract,
 
 			g_object_unref (file);
 			g_object_unref (statements);
-			return NULL;
+			g_object_unref (preinserts);
+
+			return FALSE;
 		}
 
 		mime_used = g_strdup (g_file_info_get_content_type (info));
@@ -320,7 +326,7 @@ get_file_metadata (TrackerExtract        *extract,
 				                              "  Extracting with module:'%s'",
 				                              g_module_name ((GModule*) mdata.module));
 
-				(*edata->func) (uri, statements);
+				(*edata->func) (uri, preinserts, statements);
 
 				items = tracker_sparql_builder_get_length (statements);
 
@@ -332,11 +338,15 @@ get_file_metadata (TrackerExtract        *extract,
 					continue;
 				}
 
+				tracker_sparql_builder_insert_close (preinserts);
 				tracker_sparql_builder_insert_close (statements);
 
 				g_free (mime_used);
 
-				return statements;
+				*preinserts_out = preinserts;
+				*statements_out = statements;
+
+				return TRUE;
 			}
 		}
 
@@ -355,7 +365,7 @@ get_file_metadata (TrackerExtract        *extract,
 				                              "  Extracting with module:'%s'",
 				                              g_module_name ((GModule*) mdata.module));
 
-				(*edata->func) (uri, statements);
+				(*edata->func) (uri, preinserts, statements);
 
 				items = tracker_sparql_builder_get_length (statements);
 
@@ -367,11 +377,15 @@ get_file_metadata (TrackerExtract        *extract,
 					continue;
 				}
 
+				tracker_sparql_builder_insert_close (preinserts);
 				tracker_sparql_builder_insert_close (statements);
 
 				g_free (mime_used);
 
-				return statements;
+				*preinserts_out = preinserts;
+				*statements_out = statements;
+
+				return TRUE;
 			}
 		}
 
@@ -386,9 +400,16 @@ get_file_metadata (TrackerExtract        *extract,
 		                              "  No mime available, not extracting data");
 	}
 
-	tracker_sparql_builder_insert_close (statements);
+	tracker_sparql_builder_insert_close (preinserts);
+
+	if (tracker_sparql_builder_get_length (statements) > 0) {
+		tracker_sparql_builder_insert_close (statements);
+	}
 
-	return statements;
+	*preinserts_out = preinserts;
+	*statements_out = statements;
+
+	return TRUE;
 }
 
 void
@@ -397,7 +418,7 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
                                          const gchar    *mime)
 {
 	guint request_id;
-	TrackerSparqlBuilder *statements = NULL;
+	TrackerSparqlBuilder *statements, *preinserts;
 
 	request_id = tracker_dbus_get_next_request_id ();
 
@@ -411,13 +432,14 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 	                          mime);
 
 	/* NOTE: Don't reset the timeout to shutdown here */
-	statements = get_file_metadata (object, request_id, NULL, uri, mime);
 
-	if (statements) {
-		tracker_dbus_request_info (request_id,
-		                           NULL,
-		                           "%s",
-		                           tracker_sparql_builder_get_result (statements));
+	if (get_file_metadata (object, request_id,
+			       NULL, uri, mime,
+			       &preinserts, &statements)) {
+		tracker_dbus_request_info (request_id, NULL, "%s",
+					   tracker_sparql_builder_get_result (preinserts));
+		tracker_dbus_request_info (request_id, NULL, "%s",
+					   tracker_sparql_builder_get_result (statements));
 		g_object_unref (statements);
 	}
 
@@ -458,7 +480,8 @@ tracker_extract_get_metadata (TrackerExtract         *object,
 {
 	guint request_id;
 	TrackerExtractPrivate *priv;
-	TrackerSparqlBuilder *sparql = NULL;
+	TrackerSparqlBuilder *sparql, *preinserts;
+	gboolean extracted = FALSE;
 
 	request_id = tracker_dbus_get_next_request_id ();
 
@@ -482,16 +505,23 @@ tracker_extract_get_metadata (TrackerExtract         *object,
 		alarm (MAX_EXTRACT_TIME);
 	}
 
-	sparql = get_file_metadata (object, request_id, context, uri, mime);
+	extracted = get_file_metadata (object, request_id, context, uri, mime, &preinserts, &sparql);
 
-	if (sparql) {
+	if (extracted) {
 		tracker_dbus_request_success (request_id, context);
 
 		if (tracker_sparql_builder_get_length (sparql) > 0) {
-			/* tracker_info ("%s", tracker_sparql_builder_get_result (sparql)); */
-			dbus_g_method_return (context, tracker_sparql_builder_get_result (sparql));
+			const gchar *preinserts_str = NULL;
+
+			if (tracker_sparql_builder_get_length (preinserts) > 0) {
+				preinserts_str = tracker_sparql_builder_get_result (preinserts);
+			}
+
+			dbus_g_method_return (context,
+					      (preinserts_str) ? preinserts_str : "",
+					      tracker_sparql_builder_get_result (sparql));
 		} else {
-			dbus_g_method_return (context, "");
+			dbus_g_method_return (context, "", "");
 		}
 		g_object_unref (sparql);
 	} else {



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