[tracker] tracker-extract: Cleaned up png, tiff, jpeg and xmp source



commit e3b1dea6e7a6002239a2f92942f9c82a40ea499e
Author: Martyn Russell <martyn lanedo com>
Date:   Wed Mar 31 17:50:38 2010 +0100

    tracker-extract: Cleaned up png, tiff, jpeg and xmp source

 src/tracker-extract/tracker-extract-jpeg.c |  768 ++++++++++++++--------------
 src/tracker-extract/tracker-extract-png.c  |  715 +++++++++++++--------------
 src/tracker-extract/tracker-extract-tiff.c |  679 ++++++++++++-------------
 src/tracker-extract/tracker-extract-xmp.c  |   24 +-
 4 files changed, 1053 insertions(+), 1133 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index b98a22b..dc539ba 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -21,24 +21,12 @@
 #include "config.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+#include <setjmp.h>
 
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE /* strcasestr() */
 #endif
 
-#include <ctype.h>
-#include <string.h>
-#include <fcntl.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <setjmp.h>
-
-#include <glib.h>
-#include <glib/gstdio.h>
-
 #include <jpeglib.h>
 
 #include <libtracker-common/tracker-file-utils.h>
@@ -153,9 +141,14 @@ extract_jpeg (const gchar          *uri,
 	struct jpeg_decompress_struct cinfo;
 	struct tej_error_mgr tejerr;
 	struct jpeg_marker_struct *marker;
+	TrackerXmpData xd = { 0 };
+	TrackerExifData ed = { 0 };
+	TrackerIptcData id = { 0 };
+	MergeData md = { 0 };
 	FILE *f;
 	goffset size;
 	gchar *filename;
+	gchar *comment = NULL;
 
 	filename = g_filename_from_uri (uri, NULL, NULL);
 
@@ -167,469 +160,464 @@ extract_jpeg (const gchar          *uri,
 	}
 
 	f = tracker_file_open (filename, "rb", FALSE);
+	g_free (filename);
 
-	if (f) {
-		TrackerXmpData xd = { 0 };
-		TrackerExifData ed = { 0 };
-		TrackerIptcData id = { 0 };
-		MergeData md = { 0 };
-		gchar *comment = NULL;
+	if (!f) {
+		return;
+	}
 
-		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "nfo:Image");
-		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "nmm:Photo");
+	tracker_sparql_builder_predicate (metadata, "a");
+	tracker_sparql_builder_object (metadata, "nfo:Image");
+	tracker_sparql_builder_predicate (metadata, "a");
+	tracker_sparql_builder_object (metadata, "nmm:Photo");
 
-		cinfo.err = jpeg_std_error (&tejerr.jpeg);
-		tejerr.jpeg.error_exit = extract_jpeg_error_exit;
-		if (setjmp (tejerr.setjmp_buffer)) {
-			goto fail;
-		}
+	cinfo.err = jpeg_std_error (&tejerr.jpeg);
+	tejerr.jpeg.error_exit = extract_jpeg_error_exit;
+	if (setjmp (tejerr.setjmp_buffer)) {
+		goto fail;
+	}
 
-		jpeg_create_decompress (&cinfo);
+	jpeg_create_decompress (&cinfo);
 
-		jpeg_save_markers (&cinfo, JPEG_COM, 0xFFFF);
-		jpeg_save_markers (&cinfo, JPEG_APP0 + 1, 0xFFFF);
-		jpeg_save_markers (&cinfo, JPEG_APP0 + 13, 0xFFFF);
+	jpeg_save_markers (&cinfo, JPEG_COM, 0xFFFF);
+	jpeg_save_markers (&cinfo, JPEG_APP0 + 1, 0xFFFF);
+	jpeg_save_markers (&cinfo, JPEG_APP0 + 13, 0xFFFF);
 
-		jpeg_stdio_src (&cinfo, f);
+	jpeg_stdio_src (&cinfo, f);
 
-		jpeg_read_header (&cinfo, TRUE);
+	jpeg_read_header (&cinfo, TRUE);
 
-		/* FIXME? It is possible that there are markers after SOS,
-		 * but there shouldn't be. Should we decompress the whole file?
-		 *
-		 * jpeg_start_decompress(&cinfo);
-		 * jpeg_finish_decompress(&cinfo);
-		 *
-		 * jpeg_calc_output_dimensions(&cinfo);
-		 */
+	/* FIXME? It is possible that there are markers after SOS,
+	 * but there shouldn't be. Should we decompress the whole file?
+	 *
+	 * jpeg_start_decompress(&cinfo);
+	 * jpeg_finish_decompress(&cinfo);
+	 *
+	 * jpeg_calc_output_dimensions(&cinfo);
+	 */
 
-		marker = (struct jpeg_marker_struct *) &cinfo.marker_list;
+	marker = (struct jpeg_marker_struct *) &cinfo.marker_list;
 
-		while (marker) {
-			gchar *str;
-			gsize len;
+	while (marker) {
+		gchar *str;
+		gsize len;
 #ifdef HAVE_LIBIPTCDATA
-			gsize offset;
-			guint sublen;
+		gsize offset;
+		guint sublen;
 #endif /* HAVE_LIBIPTCDATA */
 
-			switch (marker->marker) {
-			case JPEG_COM:
-				g_free (comment);
-				comment = g_strndup ((gchar*) marker->data, marker->data_length);
-				break;
+		switch (marker->marker) {
+		case JPEG_COM:
+			g_free (comment);
+			comment = g_strndup ((gchar*) marker->data, marker->data_length);
+			break;
 
-			case JPEG_APP0 + 1:
-				str = (gchar*) marker->data;
-				len = marker->data_length;
+		case JPEG_APP0 + 1:
+			str = (gchar*) marker->data;
+			len = marker->data_length;
 
 #ifdef HAVE_LIBEXIF
-				if (strncmp (EXIF_NAMESPACE, str, EXIF_NAMESPACE_LENGTH) == 0) {
-					tracker_exif_read ((unsigned char*) marker->data,
-					                   len,
-					                   uri,
-					                   &ed);
-				}
+			if (strncmp (EXIF_NAMESPACE, str, EXIF_NAMESPACE_LENGTH) == 0) {
+				tracker_exif_read ((unsigned char*) marker->data,
+				                   len,
+				                   uri,
+				                   &ed);
+			}
 #endif /* HAVE_LIBEXIF */
 
 #ifdef HAVE_EXEMPI
-				if (strncmp (XMP_NAMESPACE, str, XMP_NAMESPACE_LENGTH) == 0) {
-					tracker_xmp_read (str + XMP_NAMESPACE_LENGTH,
-					                  len - XMP_NAMESPACE_LENGTH,
-					                  uri,
-					                  &xd);
-				}
+			if (strncmp (XMP_NAMESPACE, str, XMP_NAMESPACE_LENGTH) == 0) {
+				tracker_xmp_read (str + XMP_NAMESPACE_LENGTH,
+				                  len - XMP_NAMESPACE_LENGTH,
+				                  uri,
+				                  &xd);
+			}
 #endif /* HAVE_EXEMPI */
 
-				break;
+			break;
 
-			case JPEG_APP0 + 13:
-				str = (gchar*) marker->data;
-				len = marker->data_length;
+		case JPEG_APP0 + 13:
+			str = (gchar*) marker->data;
+			len = marker->data_length;
 #ifdef HAVE_LIBIPTCDATA
-				if (strncmp (PS3_NAMESPACE, str, PS3_NAMESPACE_LENGTH) == 0) {
-					offset = iptc_jpeg_ps3_find_iptc (str, len, &sublen);
-					if (offset > 0) {
-						tracker_iptc_read (str + offset,
-						                   sublen,
-						                   uri,
-						                   &id);
-					}
+			if (strncmp (PS3_NAMESPACE, str, PS3_NAMESPACE_LENGTH) == 0) {
+				offset = iptc_jpeg_ps3_find_iptc (str, len, &sublen);
+				if (offset > 0) {
+					tracker_iptc_read (str + offset,
+					                   sublen,
+					                   uri,
+					                   &id);
 				}
+			}
 #endif /* HAVE_LIBIPTCDATA */
 
-				break;
-
-			default:
-				marker = marker->next;
-				continue;
-			}
+			break;
 
+		default:
 			marker = marker->next;
+			continue;
 		}
 
-		/* Don't merge if the make is in the model */
-		if ((xd.make == NULL || xd.model == NULL) ||
-		    (xd.make && xd.model && strstr (xd.model, xd.make) == NULL)) {
-			md.camera = tracker_merge (" ", 2, xd.make, xd.model);
-		} else {
-			md.camera = g_strdup (xd.model);
-			g_free (xd.model);
-			g_free (xd.make);
-		}
+		marker = marker->next;
+	}
 
-		if (!md.camera) {
-			if ((ed.make == NULL || ed.model == NULL) ||
-			    (ed.make && ed.model && strstr (ed.model, ed.make) == NULL)) {
-				md.camera = tracker_merge (" ", 2, ed.make, ed.model);
-			} else {
-				md.camera = g_strdup (ed.model);
-				g_free (ed.model);
-				g_free (ed.make);
-			}
+	/* Don't merge if the make is in the model */
+	if ((xd.make == NULL || xd.model == NULL) ||
+	    (xd.make && xd.model && strstr (xd.model, xd.make) == NULL)) {
+		md.camera = tracker_merge (" ", 2, xd.make, xd.model);
+	} else {
+		md.camera = g_strdup (xd.model);
+		g_free (xd.model);
+		g_free (xd.make);
+	}
+
+	if (!md.camera) {
+		if ((ed.make == NULL || ed.model == NULL) ||
+		    (ed.make && ed.model && strstr (ed.model, ed.make) == NULL)) {
+			md.camera = tracker_merge (" ", 2, ed.make, ed.model);
 		} else {
+			md.camera = g_strdup (ed.model);
 			g_free (ed.model);
 			g_free (ed.make);
 		}
+	} else {
+		g_free (ed.model);
+		g_free (ed.make);
+	}
 
-		md.title = tracker_coalesce (4, xd.title, ed.document_name, xd.title2, xd.pdf_title);
-		md.orientation = tracker_coalesce (3, xd.orientation, ed.orientation, id.image_orientation);
-		md.copyright = tracker_coalesce (4, xd.copyright, xd.rights, ed.copyright, id.copyright_notice);
-		md.white_balance = tracker_coalesce (2, xd.white_balance, ed.white_balance);
-		md.fnumber = tracker_coalesce (2, xd.fnumber, ed.fnumber);
-		md.flash = tracker_coalesce (2, xd.flash, ed.flash);
-		md.focal_length =  tracker_coalesce (2, xd.focal_length, ed.focal_length);
-		md.artist =  tracker_coalesce (3, xd.artist, ed.artist, xd.contributor);
-		md.exposure_time =  tracker_coalesce (2, xd.exposure_time, ed.exposure_time);
-		md.iso_speed_ratings = tracker_coalesce (2, xd.iso_speed_ratings, ed.iso_speed_ratings);
-		md.date = tracker_coalesce (5, xd.date, xd.time_original, ed.time, id.date_created, ed.time_original);
-		md.description = tracker_coalesce (2, xd.description, ed.description);
-		md.metering_mode = tracker_coalesce (2, xd.metering_mode, ed.metering_mode);
-
-		md.city = tracker_coalesce (2, xd.city, id.city);
-		md.state = tracker_coalesce (2, xd.state, id.state);
-		md.address = tracker_coalesce (2, xd.address, id.sublocation);
-		md.country = tracker_coalesce (2, xd.country, id.country_name);
-
-		md.creator = tracker_coalesce (3, xd.creator, id.byline, id.credit);
-		md.comment = tracker_coalesce (2, comment, ed.user_comment);
-
-		/* Prioritize on native dimention in all cases */
-		tracker_sparql_builder_predicate (metadata, "nfo:width");
-		tracker_sparql_builder_object_int64 (metadata, cinfo.image_width);
-		g_free (ed.x_dimension);
-
-		/* TODO: add ontology and store this */
-		g_free (ed.software);
-
-		tracker_sparql_builder_predicate (metadata, "nfo:height");
-		tracker_sparql_builder_object_int64 (metadata, cinfo.image_height);
-		g_free (ed.y_dimension);
-
-		if (id.contact) {
-			gchar* uri = tracker_uri_printf_escaped ("urn:artist:%s", id.contact);
-
-			tracker_sparql_builder_insert_open (preupdate, NULL);
-			tracker_sparql_builder_subject_iri (preupdate, uri);
-			tracker_sparql_builder_predicate (preupdate, "a");
-			tracker_sparql_builder_object (preupdate, "nco:Contact");
-			tracker_sparql_builder_predicate (preupdate, "nco:fullname");
-			tracker_sparql_builder_object_unvalidated (preupdate, id.contact);
-			tracker_sparql_builder_insert_close (preupdate);
-			g_free (id.contact);
-
-			tracker_sparql_builder_predicate (metadata, "nco:representative");
-			tracker_sparql_builder_object_iri (metadata, uri);
-			g_free (uri);
-		}
-
-		if (xd.keywords) {
-			insert_keywords (metadata, xd.keywords);
-			g_free (xd.keywords);
-		}
-
-		if (xd.pdf_keywords) {
-			insert_keywords (metadata, xd.pdf_keywords);
-			g_free (xd.pdf_keywords);
-		}
-
-		if (xd.subject) {
-			insert_keywords (metadata, xd.subject);
-			g_free (xd.subject);
-		}
-
-		if (xd.publisher) {
-			gchar* uri = tracker_uri_printf_escaped ("uri:artist:%s", xd.publisher);
-
-			tracker_sparql_builder_insert_open (preupdate, NULL);
-			tracker_sparql_builder_predicate (preupdate, "a");
-			tracker_sparql_builder_object (preupdate, "nco:Contact");
-			tracker_sparql_builder_predicate (preupdate, "nco:fullname");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd.publisher);
-			tracker_sparql_builder_insert_close (metadata);
-			g_free (xd.publisher);
+	md.title = tracker_coalesce (4, xd.title, ed.document_name, xd.title2, xd.pdf_title);
+	md.orientation = tracker_coalesce (3, xd.orientation, ed.orientation, id.image_orientation);
+	md.copyright = tracker_coalesce (4, xd.copyright, xd.rights, ed.copyright, id.copyright_notice);
+	md.white_balance = tracker_coalesce (2, xd.white_balance, ed.white_balance);
+	md.fnumber = tracker_coalesce (2, xd.fnumber, ed.fnumber);
+	md.flash = tracker_coalesce (2, xd.flash, ed.flash);
+	md.focal_length =  tracker_coalesce (2, xd.focal_length, ed.focal_length);
+	md.artist = tracker_coalesce (3, xd.artist, ed.artist, xd.contributor);
+	md.exposure_time = tracker_coalesce (2, xd.exposure_time, ed.exposure_time);
+	md.iso_speed_ratings = tracker_coalesce (2, xd.iso_speed_ratings, ed.iso_speed_ratings);
+	md.date = tracker_coalesce (5, xd.date, xd.time_original, ed.time, id.date_created, ed.time_original);
+	md.description = tracker_coalesce (2, xd.description, ed.description);
+	md.metering_mode = tracker_coalesce (2, xd.metering_mode, ed.metering_mode);
+	md.city = tracker_coalesce (2, xd.city, id.city);
+	md.state = tracker_coalesce (2, xd.state, id.state);
+	md.address = tracker_coalesce (2, xd.address, id.sublocation);
+	md.country = tracker_coalesce (2, xd.country, id.country_name);
+	md.creator = tracker_coalesce (3, xd.creator, id.byline, id.credit);
+	md.comment = tracker_coalesce (2, comment, ed.user_comment);
+
+	/* Prioritize on native dimention in all cases */
+	tracker_sparql_builder_predicate (metadata, "nfo:width");
+	tracker_sparql_builder_object_int64 (metadata, cinfo.image_width);
+	g_free (ed.x_dimension);
+
+	/* TODO: add ontology and store this */
+	g_free (ed.software);
+
+	tracker_sparql_builder_predicate (metadata, "nfo:height");
+	tracker_sparql_builder_object_int64 (metadata, cinfo.image_height);
+	g_free (ed.y_dimension);
+
+	if (id.contact) {
+		gchar *uri = tracker_uri_printf_escaped ("urn:artist:%s", id.contact);
+
+		tracker_sparql_builder_insert_open (preupdate, NULL);
+		tracker_sparql_builder_subject_iri (preupdate, uri);
+		tracker_sparql_builder_predicate (preupdate, "a");
+		tracker_sparql_builder_object (preupdate, "nco:Contact");
+		tracker_sparql_builder_predicate (preupdate, "nco:fullname");
+		tracker_sparql_builder_object_unvalidated (preupdate, id.contact);
+		tracker_sparql_builder_insert_close (preupdate);
+		g_free (id.contact);
+
+		tracker_sparql_builder_predicate (metadata, "nco:representative");
+		tracker_sparql_builder_object_iri (metadata, uri);
+		g_free (uri);
+	}
 
-			tracker_sparql_builder_predicate (metadata, "nco:publisher");
-			tracker_sparql_builder_object_iri (metadata, uri);
-			g_free (uri);
-		}
+	if (xd.keywords) {
+		insert_keywords (metadata, xd.keywords);
+		g_free (xd.keywords);
+	}
 
-		if (xd.type) {
-			tracker_sparql_builder_predicate (metadata, "dc:type");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.type);
-			g_free (xd.type);
-		}
+	if (xd.pdf_keywords) {
+		insert_keywords (metadata, xd.pdf_keywords);
+		g_free (xd.pdf_keywords);
+	}
 
-		if (xd.rating) {
-			tracker_sparql_builder_predicate (metadata, "nao:numericRating");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.rating);
-			g_free (xd.rating);
-		}
+	if (xd.subject) {
+		insert_keywords (metadata, xd.subject);
+		g_free (xd.subject);
+	}
 
-		if (xd.format) {
-			tracker_sparql_builder_predicate (metadata, "dc:format");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.format);
-			g_free (xd.format);
-		}
+	if (xd.publisher) {
+		gchar *uri = tracker_uri_printf_escaped ("urn:artist:%s", xd.publisher);
+
+		tracker_sparql_builder_insert_open (preupdate, NULL);
+		tracker_sparql_builder_subject_iri (preupdate, uri);
+		tracker_sparql_builder_predicate (preupdate, "a");
+		tracker_sparql_builder_object (preupdate, "nco:Contact");
+		tracker_sparql_builder_predicate (preupdate, "nco:fullname");
+		tracker_sparql_builder_object_unvalidated (preupdate, xd.publisher);
+		tracker_sparql_builder_insert_close (preupdate);
+		g_free (xd.publisher);
+
+		tracker_sparql_builder_predicate (metadata, "nco:publisher");
+		tracker_sparql_builder_object_iri (metadata, uri);
+		g_free (uri);
+	}
 
-		if (xd.identifier) {
-			tracker_sparql_builder_predicate (metadata, "dc:indentifier");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.identifier);
-			g_free (xd.identifier);
-		}
+	if (xd.type) {
+		tracker_sparql_builder_predicate (metadata, "dc:type");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.type);
+		g_free (xd.type);
+	}
 
-		if (xd.source) {
-			tracker_sparql_builder_predicate (metadata, "dc:source");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.source);
-			g_free (xd.source);
-		}
+	if (xd.rating) {
+		tracker_sparql_builder_predicate (metadata, "nao:numericRating");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.rating);
+		g_free (xd.rating);
+	}
 
-		if (xd.language) {
-			tracker_sparql_builder_predicate (metadata, "dc:language");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.language);
-			g_free (xd.language);
-		}
+	if (xd.format) {
+		tracker_sparql_builder_predicate (metadata, "dc:format");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.format);
+		g_free (xd.format);
+	}
 
-		if (xd.relation) {
-			tracker_sparql_builder_predicate (metadata, "dc:relation");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.relation);
-			g_free (xd.relation);
-		}
+	if (xd.identifier) {
+		tracker_sparql_builder_predicate (metadata, "dc:indentifier");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.identifier);
+		g_free (xd.identifier);
+	}
 
-		if (xd.coverage) {
-			tracker_sparql_builder_predicate (metadata, "dc:coverage");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.coverage);
-			g_free (xd.coverage);
-		}
+	if (xd.source) {
+		tracker_sparql_builder_predicate (metadata, "dc:source");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.source);
+		g_free (xd.source);
+	}
 
-		if (xd.license) {
-			tracker_sparql_builder_predicate (metadata, "nie:license");
-			tracker_sparql_builder_object_unvalidated (metadata, xd.license);
-			g_free (xd.license);
-		}
+	if (xd.language) {
+		tracker_sparql_builder_predicate (metadata, "dc:language");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.language);
+		g_free (xd.language);
+	}
 
-		if (id.keywords) {
-			insert_keywords (metadata, id.keywords);
-			g_free (id.keywords);
-		}
+	if (xd.relation) {
+		tracker_sparql_builder_predicate (metadata, "dc:relation");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.relation);
+		g_free (xd.relation);
+	}
 
-		if (md.camera) {
-			tracker_sparql_builder_predicate (metadata, "nmm:camera");
-			tracker_sparql_builder_object_unvalidated (metadata, md.camera);
-			g_free (md.camera);
-		}
+	if (xd.coverage) {
+		tracker_sparql_builder_predicate (metadata, "dc:coverage");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.coverage);
+		g_free (xd.coverage);
+	}
 
-		if (md.title) {
-			tracker_sparql_builder_predicate (metadata, "nie:title");
-			tracker_sparql_builder_object_unvalidated (metadata, md.title);
-			g_free (md.title);
-		}
+	if (xd.license) {
+		tracker_sparql_builder_predicate (metadata, "nie:license");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.license);
+		g_free (xd.license);
+	}
 
-		if (md.orientation) {
-			tracker_sparql_builder_predicate (metadata, "nfo:orientation");
-			tracker_sparql_builder_object (metadata, md.orientation);
-			g_free (md.orientation);
-		}
+	if (id.keywords) {
+		insert_keywords (metadata, id.keywords);
+		g_free (id.keywords);
+	}
 
-		if (md.copyright) {
-			tracker_sparql_builder_predicate (metadata, "nie:copyright");
-			tracker_sparql_builder_object_unvalidated (metadata, md.copyright);
-			g_free (md.copyright);
-		}
+	if (md.camera) {
+		tracker_sparql_builder_predicate (metadata, "nmm:camera");
+		tracker_sparql_builder_object_unvalidated (metadata, md.camera);
+		g_free (md.camera);
+	}
 
-		if (md.white_balance) {
-			tracker_sparql_builder_predicate (metadata, "nmm:whiteBalance");
-			tracker_sparql_builder_object (metadata, md.white_balance);
-			g_free (md.white_balance);
-		}
+	if (md.title) {
+		tracker_sparql_builder_predicate (metadata, "nie:title");
+		tracker_sparql_builder_object_unvalidated (metadata, md.title);
+		g_free (md.title);
+	}
 
-		if (md.fnumber) {
-			gdouble value;
+	if (md.orientation) {
+		tracker_sparql_builder_predicate (metadata, "nfo:orientation");
+		tracker_sparql_builder_object (metadata, md.orientation);
+		g_free (md.orientation);
+	}
 
-			value = g_strtod (md.fnumber, NULL);
-			tracker_sparql_builder_predicate (metadata, "nmm:fnumber");
-			tracker_sparql_builder_object_double (metadata, value);
-			g_free (md.fnumber);
-		}
+	if (md.copyright) {
+		tracker_sparql_builder_predicate (metadata, "nie:copyright");
+		tracker_sparql_builder_object_unvalidated (metadata, md.copyright);
+		g_free (md.copyright);
+	}
 
-		if (md.flash) {
-			tracker_sparql_builder_predicate (metadata, "nmm:flash");
-			tracker_sparql_builder_object (metadata, md.flash);
-			g_free (md.flash);
-		}
+	if (md.white_balance) {
+		tracker_sparql_builder_predicate (metadata, "nmm:whiteBalance");
+		tracker_sparql_builder_object (metadata, md.white_balance);
+		g_free (md.white_balance);
+	}
 
-		if (md.focal_length) {
-			gdouble value;
+	if (md.fnumber) {
+		gdouble value;
 
-			value = g_strtod (md.focal_length, NULL);
-			tracker_sparql_builder_predicate (metadata, "nmm:focalLength");
-			tracker_sparql_builder_object_double (metadata, value);
-			g_free (md.focal_length);
-		}
+		value = g_strtod (md.fnumber, NULL);
+		tracker_sparql_builder_predicate (metadata, "nmm:fnumber");
+		tracker_sparql_builder_object_double (metadata, value);
+		g_free (md.fnumber);
+	}
 
-		if (md.artist) {
-			gchar* uri = tracker_uri_printf_escaped ("urn:artist:%s", md.artist);
-
-			tracker_sparql_builder_insert_open (preupdate, NULL);
-			tracker_sparql_builder_subject_iri (preupdate, uri);
-			tracker_sparql_builder_predicate (preupdate, "a");
-			tracker_sparql_builder_object (preupdate, "nco:Contact");
-			tracker_sparql_builder_predicate (preupdate, "nco:fullname");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.artist);
-			tracker_sparql_builder_insert_close (preupdate);
-			g_free (md.artist);
-
-			tracker_sparql_builder_predicate (metadata, "nco:contributor");
-			tracker_sparql_builder_object_iri (metadata, uri);
-			g_free (uri);
-		}
+	if (md.flash) {
+		tracker_sparql_builder_predicate (metadata, "nmm:flash");
+		tracker_sparql_builder_object (metadata, md.flash);
+		g_free (md.flash);
+	}
 
-		if (md.exposure_time) {
-			gdouble value;
+	if (md.focal_length) {
+		gdouble value;
 
-			value = g_strtod (md.exposure_time, NULL);
-			tracker_sparql_builder_predicate (metadata, "nmm:exposureTime");
-			tracker_sparql_builder_object_double (metadata, value);
-			g_free (md.exposure_time);
-		}
+		value = g_strtod (md.focal_length, NULL);
+		tracker_sparql_builder_predicate (metadata, "nmm:focalLength");
+		tracker_sparql_builder_object_double (metadata, value);
+		g_free (md.focal_length);
+	}
 
-		if (md.iso_speed_ratings) {
-			gdouble value;
+	if (md.artist) {
+		gchar *uri = tracker_uri_printf_escaped ("urn:artist:%s", md.artist);
+
+		tracker_sparql_builder_insert_open (preupdate, NULL);
+		tracker_sparql_builder_subject_iri (preupdate, uri);
+		tracker_sparql_builder_predicate (preupdate, "a");
+		tracker_sparql_builder_object (preupdate, "nco:Contact");
+		tracker_sparql_builder_predicate (preupdate, "nco:fullname");
+		tracker_sparql_builder_object_unvalidated (preupdate, md.artist);
+		tracker_sparql_builder_insert_close (preupdate);
+		g_free (md.artist);
+
+		tracker_sparql_builder_predicate (metadata, "nco:contributor");
+		tracker_sparql_builder_object_iri (metadata, uri);
+		g_free (uri);
+	}
 
-			value = g_strtod (md.iso_speed_ratings, NULL);
-			tracker_sparql_builder_predicate (metadata, "nmm:isoSpeed");
-			tracker_sparql_builder_object_double (metadata, value);
-			g_free (md.iso_speed_ratings);
-		}
+	if (md.exposure_time) {
+		gdouble value;
 
-		if (md.date) {
-			tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
-			tracker_sparql_builder_object_unvalidated (metadata, md.date);
-			g_free (md.date);
-		}
+		value = g_strtod (md.exposure_time, NULL);
+		tracker_sparql_builder_predicate (metadata, "nmm:exposureTime");
+		tracker_sparql_builder_object_double (metadata, value);
+		g_free (md.exposure_time);
+	}
 
-		if (md.description) {
-			tracker_sparql_builder_predicate (metadata, "nie:description");
-			tracker_sparql_builder_object_unvalidated (metadata, md.description);
-			g_free (md.description);
-		}
+	if (md.iso_speed_ratings) {
+		gdouble value;
 
-		if (md.metering_mode) {
-			tracker_sparql_builder_predicate (metadata, "nmm:meteringMode");
-			tracker_sparql_builder_object (metadata, md.metering_mode);
-			g_free (md.metering_mode);
-		}
+		value = g_strtod (md.iso_speed_ratings, NULL);
+		tracker_sparql_builder_predicate (metadata, "nmm:isoSpeed");
+		tracker_sparql_builder_object_double (metadata, value);
+		g_free (md.iso_speed_ratings);
+	}
 
-		if (md.creator) {
-			gchar *uri = tracker_uri_printf_escaped ("urn:author:%s", md.creator);
+	if (md.date) {
+		tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
+		tracker_sparql_builder_object_unvalidated (metadata, md.date);
+		g_free (md.date);
+	}
 
-			tracker_sparql_builder_insert_open (preupdate, NULL);
-			tracker_sparql_builder_predicate (preupdate, "a");
-			tracker_sparql_builder_object (preupdate, "nco:Contact");
-			tracker_sparql_builder_predicate (preupdate, "nco:fullname");
-			tracker_sparql_builder_object_unvalidated (preupdate, uri);
-			tracker_sparql_builder_insert_close (preupdate);
+	if (md.description) {
+		tracker_sparql_builder_predicate (metadata, "nie:description");
+		tracker_sparql_builder_object_unvalidated (metadata, md.description);
+		g_free (md.description);
+	}
 
-			/* NOTE: We only have affiliation with
-			 * nco:PersonContact and we are using
-			 * nco:Contact here.
-			 */
+	if (md.metering_mode) {
+		tracker_sparql_builder_predicate (metadata, "nmm:meteringMode");
+		tracker_sparql_builder_object (metadata, md.metering_mode);
+		g_free (md.metering_mode);
+	}
 
-			/* if (id.byline_title) { */
-			/* 	tracker_sparql_builder_insert_open (preupdate, NULL); */
+	if (md.creator) {
+		gchar *uri = tracker_uri_printf_escaped ("urn:author:%s", md.creator);
+
+		tracker_sparql_builder_insert_open (preupdate, NULL);
+		tracker_sparql_builder_subject_iri (preupdate, uri);
+		tracker_sparql_builder_predicate (preupdate, "a");
+		tracker_sparql_builder_object (preupdate, "nco:Contact");
+		tracker_sparql_builder_predicate (preupdate, "nco:fullname");
+		tracker_sparql_builder_object_unvalidated (preupdate, md.creator);
+		tracker_sparql_builder_insert_close (preupdate);
+		g_free (md.creator);
+
+		/* NOTE: We only have affiliation with
+		 * nco:PersonContact and we are using
+		 * nco:Contact here.
+		 */
 
-			/* 	tracker_sparql_builder_subject (preupdate, "_:affiliation_by_line"); */
-			/* 	tracker_sparql_builder_predicate (preupdate, "a"); */
-			/* 	tracker_sparql_builder_object (preupdate, "nco:Affiliation"); */
+		/* if (id.byline_title) { */
+		/* 	tracker_sparql_builder_insert_open (preupdate, NULL); */
 
-			/* 	tracker_sparql_builder_predicate (preupdate, "nco:title"); */
-			/* 	tracker_sparql_builder_object_unvalidated (preupdate, id.byline_title); */
+		/* 	tracker_sparql_builder_subject (preupdate, "_:affiliation_by_line"); */
+		/* 	tracker_sparql_builder_predicate (preupdate, "a"); */
+		/* 	tracker_sparql_builder_object (preupdate, "nco:Affiliation"); */
 
-			/* 	tracker_sparql_builder_insert_close (preupdate); */
+		/* 	tracker_sparql_builder_predicate (preupdate, "nco:title"); */
+		/* 	tracker_sparql_builder_object_unvalidated (preupdate, id.byline_title); */
 
-	                /*         tracker_sparql_builder_predicate (preupdate, "a"); */
-	                /*         tracker_sparql_builder_object (preupdate, "nco:Contact"); */
-	                /*         tracker_sparql_builder_predicate (preupdate, "nco:hasAffiliation"); */
-	                /*         tracker_sparql_builder_object (preupdate, "_:affiliation_by_line"); */
-                        /* } */
+		/* 	tracker_sparql_builder_insert_close (preupdate); */
 
-                        tracker_sparql_builder_predicate (metadata, "nco:creator");
-                        tracker_sparql_builder_object_iri (metadata, uri);
-                        g_free (uri);
+		/*      tracker_sparql_builder_predicate (preupdate, "a"); */
+		/*      tracker_sparql_builder_object (preupdate, "nco:Contact"); */
+		/*      tracker_sparql_builder_predicate (preupdate, "nco:hasAffiliation"); */
+		/*      tracker_sparql_builder_object (preupdate, "_:affiliation_by_line"); */
+		/* } */
 
-                        g_free (md.creator);
-		}
+		tracker_sparql_builder_predicate (metadata, "nco:creator");
+		tracker_sparql_builder_object_iri (metadata, uri);
+		g_free (uri);
+	}
 
-		g_free (id.byline_title);
+	g_free (id.byline_title);
 
-		if (md.comment) {
-			tracker_sparql_builder_predicate (metadata, "nie:comment");
-			tracker_sparql_builder_object_unvalidated (metadata, md.comment);
-			g_free (md.comment);
-		}
+	if (md.comment) {
+		tracker_sparql_builder_predicate (metadata, "nie:comment");
+		tracker_sparql_builder_object_unvalidated (metadata, md.comment);
+		g_free (md.comment);
+	}
 
-		if (md.city || md.state || md.address || md.country) {
-			tracker_sparql_builder_predicate (metadata, "mlo:location");
+	if (md.city || md.state || md.address || md.country) {
+		tracker_sparql_builder_predicate (metadata, "mlo:location");
 
-			tracker_sparql_builder_object_blank_open (metadata);
-			tracker_sparql_builder_predicate (metadata, "a");
-			tracker_sparql_builder_object (metadata, "mlo:GeoPoint");
+		tracker_sparql_builder_object_blank_open (metadata);
+		tracker_sparql_builder_predicate (metadata, "a");
+		tracker_sparql_builder_object (metadata, "mlo:GeoPoint");
 	
-			if (md.address) {
-				tracker_sparql_builder_predicate (metadata, "mlo:address");
-				tracker_sparql_builder_object_unvalidated (metadata, md.address);
-				g_free (md.address);
-			}
+		if (md.address) {
+			tracker_sparql_builder_predicate (metadata, "mlo:address");
+			tracker_sparql_builder_object_unvalidated (metadata, md.address);
+			g_free (md.address);
+		}
 	
-			if (md.state) {
-				tracker_sparql_builder_predicate (metadata, "mlo:state");
-				tracker_sparql_builder_object_unvalidated (metadata, md.state);
-				g_free (md.state);
-			}
+		if (md.state) {
+			tracker_sparql_builder_predicate (metadata, "mlo:state");
+			tracker_sparql_builder_object_unvalidated (metadata, md.state);
+			g_free (md.state);
+		}
 	
-			if (md.city) {
-				tracker_sparql_builder_predicate (metadata, "mlo:city");
-				tracker_sparql_builder_object_unvalidated (metadata, md.city);
-				g_free (md.city);
-			}
+		if (md.city) {
+			tracker_sparql_builder_predicate (metadata, "mlo:city");
+			tracker_sparql_builder_object_unvalidated (metadata, md.city);
+			g_free (md.city);
+		}
 	
-			if (md.country) {
-				tracker_sparql_builder_predicate (metadata, "mlo:country");
-				tracker_sparql_builder_object_unvalidated (metadata, md.country);
-				g_free (md.country);
-			}
-		
-			tracker_sparql_builder_object_blank_close (metadata);
+		if (md.country) {
+			tracker_sparql_builder_predicate (metadata, "mlo:country");
+			tracker_sparql_builder_object_unvalidated (metadata, md.country);
+			g_free (md.country);
 		}
-
-		jpeg_destroy_decompress (&cinfo);
-	fail:
-		tracker_file_close (f, FALSE);
+		
+		tracker_sparql_builder_object_blank_close (metadata);
 	}
 
-	g_free (filename);
+	jpeg_destroy_decompress (&cinfo);
+
+fail:
+	tracker_file_close (f, FALSE);
 }
 
 TrackerExtractData *
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 7ec714b..b4e17a0 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -43,7 +43,12 @@
 #define RFC1123_DATE_FORMAT "%d %B %Y %H:%M:%S %z"
 
 typedef struct {
-	gchar *title, *copyright, *creator, *description, *date, *license;
+	gchar *title;
+	gchar *copyright;
+	gchar *creator;
+	gchar *description;
+	gchar *date;
+	gchar *license;
 	gchar *artist;
 	gchar *camera;
 	gchar *orientation;
@@ -59,17 +64,22 @@ typedef struct {
 	gchar *state;
 	gchar *address;
 	gchar *country;
-} PngNeedsMergeData;
+} MergeData;
 
 typedef struct {
-	gchar *author, *creator, *description, *comment, *copyright,
-		*creation_time, *title, *disclaimer;
+	gchar *author;
+	gchar *creator;
+	gchar *description;
+	gchar *comment;
+	gchar *copyright;
+	gchar *creation_time;
+	gchar *title;
+	gchar *disclaimer;
 } PngData;
 
-static gchar *rfc1123_to_iso8601_date (gchar                *rfc_date);
-static void   extract_png             (const gchar          *filename,
-                                       TrackerSparqlBuilder *preupdate,
-                                       TrackerSparqlBuilder *metadata);
+static void extract_png (const gchar          *filename,
+                         TrackerSparqlBuilder *preupdate,
+                         TrackerSparqlBuilder *metadata);
 
 static TrackerExtractData data[] = {
 	{ "image/png", extract_png },
@@ -78,7 +88,7 @@ static TrackerExtractData data[] = {
 };
 
 static gchar *
-rfc1123_to_iso8601_date (gchar *date)
+rfc1123_to_iso8601_date (const gchar *date)
 {
 	/* From: ex. RFC1123 date: "22 May 1997 18:07:10 -0600"
 	 * To  : ex. ISO8601 date: "2007-05-22T18:07:10-0600"
@@ -87,23 +97,28 @@ rfc1123_to_iso8601_date (gchar *date)
 }
 
 static void
-insert_keywords (TrackerSparqlBuilder *metadata, const gchar *uri, gchar *keywords)
+insert_keywords (TrackerSparqlBuilder *metadata, 
+                 const gchar          *uri, 
+                 gchar                *keywords)
 {
 	char *lasts, *keyw;
 	size_t len;
 
 	keyw = keywords;
 	keywords = strchr (keywords, '"');
-	if (keywords)
+	if (keywords) {
 		keywords++;
-	else
+	} else {
 		keywords = keyw;
+	}
 
 	len = strlen (keywords);
-	if (keywords[len - 1] == '"')
+	if (keywords[len - 1] == '"') {
 		keywords[len - 1] = '\0';
+	}
 
-	for (keyw = strtok_r (keywords, ",; ", &lasts); keyw;
+	for (keyw = strtok_r (keywords, ",; ", &lasts); 
+	     keyw;
 	     keyw = strtok_r (NULL, ",; ", &lasts)) {
 		tracker_sparql_builder_predicate (metadata, "nao:hasTag");
 
@@ -119,411 +134,371 @@ insert_keywords (TrackerSparqlBuilder *metadata, const gchar *uri, gchar *keywor
 }
 
 static void
-read_metadata (png_structp png_ptr, png_infop info_ptr, const gchar *uri, TrackerSparqlBuilder *metadata)
+read_metadata (png_structp           png_ptr, 
+               png_infop             info_ptr, 
+               const gchar          *uri, 
+               TrackerSparqlBuilder *metadata)
 {
-	gint         num_text;
-	png_textp    text_ptr;
-	PngNeedsMergeData merge_data = { 0 };
-	PngData png_data = { 0 };
-	TrackerExifData exif_data = { 0 };
-	TrackerXmpData xmp_data = { 0 };
-
-	if (png_get_text (png_ptr, info_ptr, &text_ptr, &num_text) > 0) {
-		gint i;
-
-		for (i = 0; i < num_text; i++) {
-
-			if (!text_ptr[i].key || !text_ptr[i].text || text_ptr[i].text[0] == '\0') {
-				continue;
-			}
+	MergeData md = { 0 };
+	PngData pd = { 0 };
+	TrackerExifData ed = { 0 };
+	TrackerXmpData xd = { 0 };
+	png_textp text_ptr;
+	gint num_text;
+	gint i;
+
+	if (png_get_text (png_ptr, info_ptr, &text_ptr, &num_text) < 1) {
+		g_warning ("Calling png_get_text() returned < 1");
+		return;
+	}
 
+	for (i = 0; i < num_text; i++) {
+		if (!text_ptr[i].key || !text_ptr[i].text || text_ptr[i].text[0] == '\0') {
+			continue;
+		}
+		
 #if defined(HAVE_EXEMPI) && defined(PNG_iTXt_SUPPORTED)
-
-			if (g_strcmp0 ("XML:com.adobe.xmp", text_ptr[i].key) == 0) {
-
-				/* ATM tracker_extract_xmp_read supports setting xmp_data
-				 * multiple times, keep it that way as here it's
-				 * theoretically possible that the function gets
-				 * called multiple times */
-
-				tracker_extract_xmp_read (text_ptr[i].text,
-				                          text_ptr[i].itxt_length,
-				                          uri, &xmp_data);
-
-				continue;
-			}
+		if (g_strcmp0 ("XML:com.adobe.xmp", text_ptr[i].key) == 0) {
+			/* ATM tracker_extract_xmp_read supports setting xd
+			 * multiple times, keep it that way as here it's
+			 * theoretically possible that the function gets
+			 * called multiple times 
+			 */
+			tracker_extract_xmp_read (text_ptr[i].text,
+			                          text_ptr[i].itxt_length,
+			                          uri, &xd);
+
+			continue;
+		}
 #endif
 
 #if defined(HAVE_LIBEXIF) && defined(PNG_iTXt_SUPPORTED)
-
-			/* I'm not certain this is the key for EXIF. Using key according to
-			 * this document about exiftool:
-			 * http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/PNG.html#TextualData */
-
-			if (g_strcmp0 ("Raw profile type exif", text_ptr[i].key) == 0) {
-				tracker_extract_exif_read (text_ptr[i].text,
-				                           text_ptr[i].itxt_length, 
-				                           uri, &exif_data);
-				continue;
-			}
+		/* I'm not certain this is the key for EXIF. Using key according to
+		 * this document about exiftool:
+		 * http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/PNG.html#TextualData 
+		 */
+		if (g_strcmp0 ("Raw profile type exif", text_ptr[i].key) == 0) {
+			tracker_extract_exif_read (text_ptr[i].text,
+			                           text_ptr[i].itxt_length, 
+			                           uri, &ed);
+			continue;
+		}
 #endif /* HAVE_LIBEXIF */
 
-			if (g_strcmp0 (text_ptr[i].key, "Author") == 0) {
-				png_data.author = g_strdup (text_ptr[i].text);
-				continue;
-			}
-
-			if (g_strcmp0 (text_ptr[i].key, "Creator") == 0) {
-				png_data.creator = g_strdup (text_ptr[i].text);
-				continue;
-			}
-
-			if (g_strcmp0 (text_ptr[i].key, "Description") == 0) {
-				png_data.description = g_strdup (text_ptr[i].text);
-				continue;
-			}
-
-			if (g_strcmp0 (text_ptr[i].key, "Comment") == 0) {
-				png_data.comment = g_strdup (text_ptr[i].text);
-				continue;
-			}
-
-			if (g_strcmp0 (text_ptr[i].key, "Copyright") == 0) {
-				png_data.copyright = g_strdup (text_ptr[i].text);
-				continue;
-			}
-
-			if (g_strcmp0 (text_ptr[i].key, "Creation Time") == 0) {
-				png_data.creation_time = rfc1123_to_iso8601_date (text_ptr[i].text);
-				continue;
-			}
-
-			if (g_strcmp0 (text_ptr[i].key, "Title") == 0) {
-				png_data.title = g_strdup (text_ptr[i].text);
-				continue;
-			}
-
-			if (g_strcmp0 (text_ptr[i].key, "Disclaimer") == 0) {
-				png_data.disclaimer = g_strdup (text_ptr[i].text);
-				continue;
-			}
+		if (g_strcmp0 (text_ptr[i].key, "Author") == 0) {
+			pd.author = g_strdup (text_ptr[i].text);
+			continue;
 		}
 
-		/* Don't merge if the make is in the model */
-		if ((xmp_data.make == NULL || xmp_data.model == NULL) ||
-		    (xmp_data.make && xmp_data.model && strstr (xmp_data.model, xmp_data.make) == NULL)) {
-			merge_data.camera = tracker_merge (" ", 2, xmp_data.make, xmp_data.model);
-		} else {
-			merge_data.camera = g_strdup (xmp_data.model);
-			g_free (xmp_data.model);
-			g_free (xmp_data.make);
+		if (g_strcmp0 (text_ptr[i].key, "Creator") == 0) {
+			pd.creator = g_strdup (text_ptr[i].text);
+			continue;
 		}
 
-		if (!merge_data.camera) {
-			if ((exif_data.make == NULL || exif_data.model == NULL) ||
-			    (exif_data.make && exif_data.model && strstr (exif_data.model, exif_data.make) == NULL)) {
-				merge_data.camera = tracker_merge (" ", 2, exif_data.make, exif_data.model);
-			} else {
-				merge_data.camera = g_strdup (exif_data.model);
-				g_free (exif_data.model);
-				g_free (exif_data.make);
-			}
-		} else {
-			g_free (exif_data.model);
-			g_free (exif_data.make);
+		if (g_strcmp0 (text_ptr[i].key, "Description") == 0) {
+			pd.description = g_strdup (text_ptr[i].text);
+			continue;
 		}
 
-		merge_data.creator = tracker_coalesce (3, xmp_data.creator, 
-		                                       png_data.creator,
-		                                       png_data.author);
-
-		merge_data.title = tracker_coalesce (5, xmp_data.title, 
-		                                     png_data.title,
-		                                     exif_data.document_name,
-		                                     xmp_data.title2,
-		                                     xmp_data.pdf_title);
-
-		merge_data.copyright = tracker_coalesce (3, xmp_data.rights, 
-		                                         png_data.copyright,
-		                                         exif_data.copyright);
-
-		merge_data.license = tracker_coalesce (2, xmp_data.license, 
-		                                       png_data.disclaimer);
-
-		merge_data.description = tracker_coalesce (3, xmp_data.description,
-		                                           png_data.description,
-		                                           exif_data.description);
-
-		merge_data.date = tracker_coalesce (5, xmp_data.date,
-		                                    xmp_data.time_original,
-		                                    png_data.creation_time,
-		                                    exif_data.time,
-		                                    exif_data.time_original);
-
-		merge_data.comment = tracker_coalesce (2, png_data.comment,
-		                                       exif_data.user_comment);
-
-		merge_data.artist = tracker_coalesce (3, xmp_data.artist,
-		                                      exif_data.artist,
-		                                      xmp_data.contributor);
-
-		merge_data.orientation = tracker_coalesce (2, xmp_data.orientation, 
-		                                           exif_data.orientation);
-
-		merge_data.exposure_time = tracker_coalesce (2, xmp_data.exposure_time, 
-		                                             exif_data.exposure_time);
-
-		merge_data.iso_speed_ratings = tracker_coalesce (2, xmp_data.iso_speed_ratings, 
-		                                                 exif_data.iso_speed_ratings);
+		if (g_strcmp0 (text_ptr[i].key, "Comment") == 0) {
+			pd.comment = g_strdup (text_ptr[i].text);
+			continue;
+		}
 
-		merge_data.fnumber = tracker_coalesce (2, xmp_data.fnumber, 
-		                                       exif_data.fnumber);
+		if (g_strcmp0 (text_ptr[i].key, "Copyright") == 0) {
+			pd.copyright = g_strdup (text_ptr[i].text);
+			continue;
+		}
 
-		merge_data.flash = tracker_coalesce (2, xmp_data.flash, 
-		                                     exif_data.flash);
+		if (g_strcmp0 (text_ptr[i].key, "Creation Time") == 0) {
+			pd.creation_time = rfc1123_to_iso8601_date (text_ptr[i].text);
+			continue;
+		}
 
-		merge_data.focal_length = tracker_coalesce (2, xmp_data.focal_length, 
-		                                            exif_data.focal_length);
+		if (g_strcmp0 (text_ptr[i].key, "Title") == 0) {
+			pd.title = g_strdup (text_ptr[i].text);
+			continue;
+		}
 
-		merge_data.metering_mode = tracker_coalesce (2, xmp_data.metering_mode, 
-		                                             exif_data.metering_mode);
+		if (g_strcmp0 (text_ptr[i].key, "Disclaimer") == 0) {
+			pd.disclaimer = g_strdup (text_ptr[i].text);
+			continue;
+		}
+	}
 
-		merge_data.white_balance = tracker_coalesce (2, xmp_data.white_balance, 
-		                                             exif_data.white_balance);
+	/* Don't merge if the make is in the model */
+	if ((xd.make == NULL || xd.model == NULL) ||
+	    (xd.make && xd.model && strstr (xd.model, xd.make) == NULL)) {
+		md.camera = tracker_merge (" ", 2, xd.make, xd.model);
+	} else {
+		md.camera = g_strdup (xd.model);
+		g_free (xd.model);
+		g_free (xd.make);
+	}
 
-		if (merge_data.comment) {
-			tracker_sparql_builder_predicate (metadata, "nie:comment");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.comment);
-			g_free (merge_data.comment);
+	if (!md.camera) {
+		if ((ed.make == NULL || ed.model == NULL) ||
+		    (ed.make && ed.model && strstr (ed.model, ed.make) == NULL)) {
+			md.camera = tracker_merge (" ", 2, ed.make, ed.model);
+		} else {
+			md.camera = g_strdup (ed.model);
+			g_free (ed.model);
+			g_free (ed.make);
 		}
+	} else {
+		g_free (ed.model);
+		g_free (ed.make);
+	}
 
-		if (merge_data.license) {
-			tracker_sparql_builder_predicate (metadata, "nie:license");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.license);
-			g_free (merge_data.license);
-		}
+	md.creator = tracker_coalesce (3, xd.creator, pd.creator, pd.author);
+	md.title = tracker_coalesce (5, xd.title, pd.title, ed.document_name, xd.title2, xd.pdf_title);
+	md.copyright = tracker_coalesce (3, xd.rights, pd.copyright, ed.copyright);
+	md.license = tracker_coalesce (2, xd.license, pd.disclaimer);
+	md.description = tracker_coalesce (3, xd.description, pd.description, ed.description);
+	md.date = tracker_coalesce (5, xd.date, xd.time_original, pd.creation_time, ed.time, ed.time_original);
+	md.comment = tracker_coalesce (2, pd.comment, ed.user_comment);
+	md.artist = tracker_coalesce (3, xd.artist, ed.artist, xd.contributor);
+	md.orientation = tracker_coalesce (2, xd.orientation, ed.orientation);
+	md.exposure_time = tracker_coalesce (2, xd.exposure_time, ed.exposure_time);
+	md.iso_speed_ratings = tracker_coalesce (2, xd.iso_speed_ratings, ed.iso_speed_ratings);
+	md.fnumber = tracker_coalesce (2, xd.fnumber, ed.fnumber);
+	md.flash = tracker_coalesce (2, xd.flash, ed.flash);
+	md.focal_length = tracker_coalesce (2, xd.focal_length, ed.focal_length);
+	md.metering_mode = tracker_coalesce (2, xd.metering_mode, ed.metering_mode);
+	md.white_balance = tracker_coalesce (2, xd.white_balance, ed.white_balance);
+
+	if (md.comment) {
+		tracker_sparql_builder_predicate (metadata, "nie:comment");
+		tracker_sparql_builder_object_unvalidated (metadata, md.comment);
+		g_free (md.comment);
+	}
 
-		/* TODO: add ontology and store this */
-		g_free (exif_data.software);
+	if (md.license) {
+		tracker_sparql_builder_predicate (metadata, "nie:license");
+		tracker_sparql_builder_object_unvalidated (metadata, md.license);
+		g_free (md.license);
+	}
 
-		g_free (exif_data.x_dimension);
-		g_free (exif_data.y_dimension);
-		g_free (exif_data.image_width);
+	/* TODO: add ontology and store this */
+	g_free (ed.software);
 
-		if (merge_data.creator) {
-			tracker_sparql_builder_predicate (metadata, "nco:creator");
+	g_free (ed.x_dimension);
+	g_free (ed.y_dimension);
+	g_free (ed.image_width);
 
-			tracker_sparql_builder_object_blank_open (metadata);
-			tracker_sparql_builder_predicate (metadata, "a");
-			tracker_sparql_builder_object (metadata, "nco:Contact");
+	if (md.creator) {
+		tracker_sparql_builder_predicate (metadata, "nco:creator");
 
-			tracker_sparql_builder_predicate (metadata, "nco:fullname");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.creator);
-			tracker_sparql_builder_object_blank_close (metadata);
-			g_free (merge_data.creator);
-		}
+		tracker_sparql_builder_object_blank_open (metadata);
+		tracker_sparql_builder_predicate (metadata, "a");
+		tracker_sparql_builder_object (metadata, "nco:Contact");
 
-		if (merge_data.date) {
-			tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.date);
-			g_free (merge_data.date);
-		}
+		tracker_sparql_builder_predicate (metadata, "nco:fullname");
+		tracker_sparql_builder_object_unvalidated (metadata, md.creator);
+		tracker_sparql_builder_object_blank_close (metadata);
+		g_free (md.creator);
+	}
 
-		if (merge_data.description) {
-			tracker_sparql_builder_predicate (metadata, "nie:description");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.description);
-			g_free (merge_data.description);
-		}
+	if (md.date) {
+		tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
+		tracker_sparql_builder_object_unvalidated (metadata, md.date);
+		g_free (md.date);
+	}
 
-		if (merge_data.copyright) {
-			tracker_sparql_builder_predicate (metadata, "nie:copyright");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.copyright);
-			g_free (merge_data.copyright);
-		}
+	if (md.description) {
+		tracker_sparql_builder_predicate (metadata, "nie:description");
+		tracker_sparql_builder_object_unvalidated (metadata, md.description);
+		g_free (md.description);
+	}
 
-		if (merge_data.title) {
-			tracker_sparql_builder_predicate (metadata, "nie:title");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.title);
-			g_free (merge_data.title);
-		}
+	if (md.copyright) {
+		tracker_sparql_builder_predicate (metadata, "nie:copyright");
+		tracker_sparql_builder_object_unvalidated (metadata, md.copyright);
+		g_free (md.copyright);
+	}
 
-		if (merge_data.camera) {
-			tracker_sparql_builder_predicate (metadata, "nmm:camera");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.camera);
-			g_free (merge_data.camera);
-		}
+	if (md.title) {
+		tracker_sparql_builder_predicate (metadata, "nie:title");
+		tracker_sparql_builder_object_unvalidated (metadata, md.title);
+		g_free (md.title);
+	}
 
-		if (merge_data.artist) {
-			tracker_sparql_builder_predicate (metadata, "nco:contributor");
+	if (md.camera) {
+		tracker_sparql_builder_predicate (metadata, "nmm:camera");
+		tracker_sparql_builder_object_unvalidated (metadata, md.camera);
+		g_free (md.camera);
+	}
 
-			tracker_sparql_builder_object_blank_open (metadata);
-			tracker_sparql_builder_predicate (metadata, "a");
-			tracker_sparql_builder_object (metadata, "nco:Contact");
+	if (md.artist) {
+		tracker_sparql_builder_predicate (metadata, "nco:contributor");
 
-			tracker_sparql_builder_predicate (metadata, "nco:fullname");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.artist);
-			tracker_sparql_builder_object_blank_close (metadata);
-			g_free (merge_data.artist);
-		}
+		tracker_sparql_builder_object_blank_open (metadata);
+		tracker_sparql_builder_predicate (metadata, "a");
+		tracker_sparql_builder_object (metadata, "nco:Contact");
 
-		if (merge_data.orientation) {
-			tracker_sparql_builder_predicate (metadata, "nfo:orientation");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.orientation);
-			g_free (merge_data.orientation);
-		}
+		tracker_sparql_builder_predicate (metadata, "nco:fullname");
+		tracker_sparql_builder_object_unvalidated (metadata, md.artist);
+		tracker_sparql_builder_object_blank_close (metadata);
+		g_free (md.artist);
+	}
 
-		if (merge_data.exposure_time) {
-			tracker_sparql_builder_predicate (metadata, "nmm:exposureTime");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.exposure_time);
-			g_free (merge_data.exposure_time);
-		}
+	if (md.orientation) {
+		tracker_sparql_builder_predicate (metadata, "nfo:orientation");
+		tracker_sparql_builder_object_unvalidated (metadata, md.orientation);
+		g_free (md.orientation);
+	}
 
-		if (merge_data.iso_speed_ratings) {
-			tracker_sparql_builder_predicate (metadata, "nmm:isoSpeed");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.iso_speed_ratings);
-			g_free (merge_data.iso_speed_ratings);
-		}
+	if (md.exposure_time) {
+		tracker_sparql_builder_predicate (metadata, "nmm:exposureTime");
+		tracker_sparql_builder_object_unvalidated (metadata, md.exposure_time);
+		g_free (md.exposure_time);
+	}
 
-		if (merge_data.white_balance) {
-			tracker_sparql_builder_predicate (metadata, "nmm:whiteBalance");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.white_balance);
-			g_free (merge_data.white_balance);
-		}
+	if (md.iso_speed_ratings) {
+		tracker_sparql_builder_predicate (metadata, "nmm:isoSpeed");
+		tracker_sparql_builder_object_unvalidated (metadata, md.iso_speed_ratings);
+		g_free (md.iso_speed_ratings);
+	}
 
-		if (merge_data.fnumber) {
-			tracker_sparql_builder_predicate (metadata, "nmm:fnumber");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.fnumber);
-			g_free (merge_data.fnumber);
-		}
+	if (md.white_balance) {
+		tracker_sparql_builder_predicate (metadata, "nmm:whiteBalance");
+		tracker_sparql_builder_object_unvalidated (metadata, md.white_balance);
+		g_free (md.white_balance);
+	}
 
-		if (merge_data.flash) {
-			tracker_sparql_builder_predicate (metadata, "nmm:flash");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.flash);
-			g_free (merge_data.flash);
-		}
+	if (md.fnumber) {
+		tracker_sparql_builder_predicate (metadata, "nmm:fnumber");
+		tracker_sparql_builder_object_unvalidated (metadata, md.fnumber);
+		g_free (md.fnumber);
+	}
 
-		if (merge_data.focal_length) {
-			tracker_sparql_builder_predicate (metadata, "nmm:focalLength");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.focal_length);
-			g_free (merge_data.focal_length);
-		}
+	if (md.flash) {
+		tracker_sparql_builder_predicate (metadata, "nmm:flash");
+		tracker_sparql_builder_object_unvalidated (metadata, md.flash);
+		g_free (md.flash);
+	}
 
-		if (merge_data.metering_mode) {
-			tracker_sparql_builder_predicate (metadata, "nmm:meteringMode");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.metering_mode);
-			g_free (merge_data.metering_mode);
-		}
+	if (md.focal_length) {
+		tracker_sparql_builder_predicate (metadata, "nmm:focalLength");
+		tracker_sparql_builder_object_unvalidated (metadata, md.focal_length);
+		g_free (md.focal_length);
+	}
 
+	if (md.metering_mode) {
+		tracker_sparql_builder_predicate (metadata, "nmm:meteringMode");
+		tracker_sparql_builder_object_unvalidated (metadata, md.metering_mode);
+		g_free (md.metering_mode);
+	}
 
-		if (xmp_data.keywords) {
-			insert_keywords (metadata, uri, xmp_data.keywords);
-			g_free (xmp_data.keywords);
-		}
 
-		if (xmp_data.pdf_keywords) {
-			insert_keywords (metadata, uri, xmp_data.pdf_keywords);
-			g_free (xmp_data.pdf_keywords);
-		}
+	if (xd.keywords) {
+		insert_keywords (metadata, uri, xd.keywords);
+		g_free (xd.keywords);
+	}
 
-		if (xmp_data.rating) {
-			tracker_sparql_builder_predicate (metadata, "nao:numericRating");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.rating);
-			g_free (xmp_data.rating);
-		}
+	if (xd.pdf_keywords) {
+		insert_keywords (metadata, uri, xd.pdf_keywords);
+		g_free (xd.pdf_keywords);
+	}
 
-		if (xmp_data.subject) {
-			insert_keywords (metadata, uri, xmp_data.subject);
-			g_free (xmp_data.subject);
-		}
+	if (xd.rating) {
+		tracker_sparql_builder_predicate (metadata, "nao:numericRating");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.rating);
+		g_free (xd.rating);
+	}
 
-		if (xmp_data.publisher) {
-			tracker_sparql_builder_predicate (metadata, "nco:publisher");
+	if (xd.subject) {
+		insert_keywords (metadata, uri, xd.subject);
+		g_free (xd.subject);
+	}
 
-			tracker_sparql_builder_object_blank_open (metadata);
-			tracker_sparql_builder_predicate (metadata, "a");
-			tracker_sparql_builder_object (metadata, "nco:Contact");
+	if (xd.publisher) {
+		tracker_sparql_builder_predicate (metadata, "nco:publisher");
 
-			tracker_sparql_builder_predicate (metadata, "nco:fullname");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.publisher);
-			tracker_sparql_builder_object_blank_close (metadata);
-			g_free (xmp_data.publisher);
-		}
+		tracker_sparql_builder_object_blank_open (metadata);
+		tracker_sparql_builder_predicate (metadata, "a");
+		tracker_sparql_builder_object (metadata, "nco:Contact");
 
-		if (xmp_data.type) {
-			tracker_sparql_builder_predicate (metadata, "dc:type");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.type);
-			g_free (xmp_data.type);
-		}
+		tracker_sparql_builder_predicate (metadata, "nco:fullname");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.publisher);
+		tracker_sparql_builder_object_blank_close (metadata);
+		g_free (xd.publisher);
+	}
 
-		if (xmp_data.format) {
-			tracker_sparql_builder_predicate (metadata, "dc:format");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.format);
-			g_free (xmp_data.format);
-		}
+	if (xd.type) {
+		tracker_sparql_builder_predicate (metadata, "dc:type");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.type);
+		g_free (xd.type);
+	}
 
-		if (xmp_data.identifier) {
-			tracker_sparql_builder_predicate (metadata, "dc:identifier");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.identifier);
-			g_free (xmp_data.identifier);
-		}
+	if (xd.format) {
+		tracker_sparql_builder_predicate (metadata, "dc:format");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.format);
+		g_free (xd.format);
+	}
 
-		if (xmp_data.source) {
-			tracker_sparql_builder_predicate (metadata, "dc:source");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.source);
-			g_free (xmp_data.source);
-		}
+	if (xd.identifier) {
+		tracker_sparql_builder_predicate (metadata, "dc:identifier");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.identifier);
+		g_free (xd.identifier);
+	}
 
-		if (xmp_data.language) {
-			tracker_sparql_builder_predicate (metadata, "dc:language");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.language);
-			g_free (xmp_data.language);
-		}
+	if (xd.source) {
+		tracker_sparql_builder_predicate (metadata, "dc:source");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.source);
+		g_free (xd.source);
+	}
 
-		if (xmp_data.relation) {
-			tracker_sparql_builder_predicate (metadata, "dc:relation");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.relation);
-			g_free (xmp_data.relation);
-		}
+	if (xd.language) {
+		tracker_sparql_builder_predicate (metadata, "dc:language");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.language);
+		g_free (xd.language);
+	}
 
-		if (xmp_data.coverage) {
-			tracker_sparql_builder_predicate (metadata, "dc:coverage");
-			tracker_sparql_builder_object_unvalidated (metadata, xmp_data.coverage);
-			g_free (xmp_data.coverage);
-		}
+	if (xd.relation) {
+		tracker_sparql_builder_predicate (metadata, "dc:relation");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.relation);
+		g_free (xd.relation);
+	}
 
-		if (xmp_data.address || xmp_data.country || xmp_data.city) {
-			tracker_sparql_builder_predicate (metadata, "mlo:location");
+	if (xd.coverage) {
+		tracker_sparql_builder_predicate (metadata, "dc:coverage");
+		tracker_sparql_builder_object_unvalidated (metadata, xd.coverage);
+		g_free (xd.coverage);
+	}
+
+	if (xd.address || xd.country || xd.city) {
+		tracker_sparql_builder_predicate (metadata, "mlo:location");
 	
-			tracker_sparql_builder_object_blank_open (metadata);
-			tracker_sparql_builder_predicate (metadata, "a");
-			tracker_sparql_builder_object (metadata, "mlo:GeoPoint");
+		tracker_sparql_builder_object_blank_open (metadata);
+		tracker_sparql_builder_predicate (metadata, "a");
+		tracker_sparql_builder_object (metadata, "mlo:GeoPoint");
 	
-			if (xmp_data.address) {
-				tracker_sparql_builder_predicate (metadata, "mlo:address");
-				tracker_sparql_builder_object_unvalidated (metadata, xmp_data.address);
-				g_free (xmp_data.address);
-			}
+		if (xd.address) {
+			tracker_sparql_builder_predicate (metadata, "mlo:address");
+			tracker_sparql_builder_object_unvalidated (metadata, xd.address);
+			g_free (xd.address);
+		}
 	
-			if (xmp_data.state) {
-				tracker_sparql_builder_predicate (metadata, "mlo:state");
-				tracker_sparql_builder_object_unvalidated (metadata, xmp_data.state);
-				g_free (xmp_data.state);
-			}
+		if (xd.state) {
+			tracker_sparql_builder_predicate (metadata, "mlo:state");
+			tracker_sparql_builder_object_unvalidated (metadata, xd.state);
+			g_free (xd.state);
+		}
 	
-			if (xmp_data.city) {
-				tracker_sparql_builder_predicate (metadata, "mlo:city");
-				tracker_sparql_builder_object_unvalidated (metadata, xmp_data.city);
-				g_free (xmp_data.city);
-			}
+		if (xd.city) {
+			tracker_sparql_builder_predicate (metadata, "mlo:city");
+			tracker_sparql_builder_object_unvalidated (metadata, xd.city);
+			g_free (xd.city);
+		}
 	
-			if (xmp_data.country) {
-				tracker_sparql_builder_predicate (metadata, "mlo:country");
-				tracker_sparql_builder_object_unvalidated (metadata, xmp_data.country);
-				g_free (xmp_data.country);
-			}
-		
-			tracker_sparql_builder_object_blank_close (metadata);
+		if (xd.country) {
+			tracker_sparql_builder_predicate (metadata, "mlo:country");
+			tracker_sparql_builder_object_unvalidated (metadata, xd.country);
+			g_free (xd.country);
 		}
+		
+		tracker_sparql_builder_object_blank_close (metadata);
 	}
 }
 
@@ -532,18 +507,19 @@ extract_png (const gchar          *uri,
              TrackerSparqlBuilder *preupdate,
              TrackerSparqlBuilder *metadata)
 {
-	goffset      size;
-	FILE        *f;
-	png_structp  png_ptr;
-	png_infop    info_ptr;
-	png_infop    end_ptr;
-	png_bytepp   row_pointers;
-	guint        row;
-	png_uint_32  width, height;
-	gint         bit_depth, color_type;
-	gint         interlace_type, compression_type, filter_type;
-	gchar       *filename = g_filename_from_uri (uri, NULL, NULL);
-
+	goffset size;
+	FILE *f;
+	png_structp png_ptr;
+	png_infop info_ptr;
+	png_infop end_ptr;
+	png_bytepp row_pointers;
+	guint row;
+	png_uint_32 width, height;
+	gint bit_depth, color_type;
+	gint interlace_type, compression_type, filter_type;
+	gchar *filename;
+
+	filename = g_filename_from_uri (uri, NULL, NULL);
 	size = tracker_file_get_size (filename);
 
 	if (size < 64) {
@@ -551,6 +527,7 @@ extract_png (const gchar          *uri,
 	}
 
 	f = tracker_file_open (filename, "r", FALSE);
+	g_free (filename);
 
 	if (f) {
 		png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
@@ -559,7 +536,6 @@ extract_png (const gchar          *uri,
 		                                  NULL);
 		if (!png_ptr) {
 			tracker_file_close (f, FALSE);
-			g_free (filename);
 			return;
 		}
 
@@ -567,7 +543,6 @@ extract_png (const gchar          *uri,
 		if (!info_ptr) {
 			png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
 			tracker_file_close (f, FALSE);
-			g_free (filename);
 			return;
 		}
 
@@ -575,7 +550,6 @@ extract_png (const gchar          *uri,
 		if (!end_ptr) {
 			png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
 			tracker_file_close (f, FALSE);
-			g_free (filename);
 			return;
 		}
 
@@ -599,7 +573,6 @@ extract_png (const gchar          *uri,
 		                   &filter_type)) {
 			png_destroy_read_struct (&png_ptr, &info_ptr, &end_ptr);
 			tracker_file_close (f, FALSE);
-			g_free (filename);
 			return;
 		}
 
@@ -639,8 +612,6 @@ extract_png (const gchar          *uri,
 		png_destroy_read_struct (&png_ptr, &info_ptr, &end_ptr);
 		tracker_file_close (f, FALSE);
 	}
-
-	g_free (filename);
 }
 
 TrackerExtractData *
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index 28f87d0..6b79f8a 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -27,28 +27,49 @@
 #include <libtracker-extract/tracker-extract.h>
 
 typedef enum {
-	TIFF_TAGTYPE_UNDEFINED = 0,
-	TIFF_TAGTYPE_STRING,
-	TIFF_TAGTYPE_UINT16,
-	TIFF_TAGTYPE_UINT32,
-	TIFF_TAGTYPE_DOUBLE,
-	TIFF_TAGTYPE_C16_UINT16
+	TAG_TYPE_UNDEFINED = 0,
+	TAG_TYPE_STRING,
+	TAG_TYPE_UINT16,
+	TAG_TYPE_UINT32,
+	TAG_TYPE_DOUBLE,
+	TAG_TYPE_C16_UINT16
 } TagType;
 
 typedef struct {
-	gchar *camera, *title, *orientation, *copyright, *white_balance,
-		*fnumber, *flash, *focal_length, *artist,
-		*exposure_time, *iso_speed_ratings, *date, *description,
-		*metering_mode, *creator, *x_dimension, *y_dimension;
+	gchar *camera;
+	gchar *title;
+	gchar *orientation;
+	gchar *copyright;
+	gchar *white_balance;
+	gchar *fnumber;
+	gchar *flash;
+	gchar *focal_length;
+	gchar *artist;
+	gchar *exposure_time;
+	gchar *iso_speed_ratings;
+	gchar *date;
+	gchar *description;
+	gchar *metering_mode;
+	gchar *creator;
+	gchar *x_dimension;
+	gchar *y_dimension;
 	gchar *city;
 	gchar *state;
 	gchar *address;
-	gchar *country; 
-} TiffNeedsMergeData;
+	gchar *country;
+} MergeData;
 
 typedef struct {
-	gchar *artist, *copyright, *datetime, *documentname, *imagedescription,
-		*imagewidth, *imagelength, *make, *model, *orientation;
+	gchar *artist;
+	gchar *copyright;
+	gchar *date;
+	gchar *title;
+	gchar *description;
+	gchar *width;
+	gchar *length;
+	gchar *make;
+	gchar *model;
+	gchar *orientation;
 } TiffData;
 
 static void extract_tiff (const gchar          *filename,
@@ -63,10 +84,10 @@ static TrackerExtractData extract_data[] = {
 static gchar *
 get_flash (TIFF *image)
 {
-	guint16 varui16 = 0;
+	guint16 data = 0;
 
-	if (TIFFGetField (image, EXIFTAG_FLASH, &varui16)) {
-		switch (varui16) {
+	if (TIFFGetField (image, EXIFTAG_FLASH, &data)) {
+		switch (data) {
 		case 0x0001:
 		case 0x0009:
 		case 0x000D:
@@ -95,54 +116,38 @@ get_flash (TIFF *image)
 static gchar *
 get_orientation (TIFF *image)
 {
-	guint16 varui16 = 0;
-
-	if (TIFFGetField (image, TIFFTAG_ORIENTATION, &varui16)) {
-		switch (varui16) {
-		default:
-		case 0:
-			return  g_strdup ("nfo:orientation-top");
-		case 1:
-			return  g_strdup ("nfo:orientation-top-mirror");
-		case 2:
-			return  g_strdup ("nfo:orientation-bottom");
-		case 3:
-			return  g_strdup ("nfo:orientation-bottom-mirror");
-		case 4:
-			return  g_strdup ("nfo:orientation-left-mirror");
-		case 5:
-			return  g_strdup ("nfo:orientation-right");
-		case 6:
-			return  g_strdup ("nfo:orientation-right-mirror");
-		case 7:
-			return  g_strdup ("nfo:orientation-left");
+	guint16 data = 0;
+
+	if (TIFFGetField (image, TIFFTAG_ORIENTATION, &data)) {
+		switch (data) {
+		case 0: return g_strdup ("nfo:orientation-top");
+		case 1:	return g_strdup ("nfo:orientation-top-mirror");
+		case 2:	return g_strdup ("nfo:orientation-bottom");
+		case 3:	return g_strdup ("nfo:orientation-bottom-mirror");
+		case 4:	return g_strdup ("nfo:orientation-left-mirror");
+		case 5:	return g_strdup ("nfo:orientation-right");
+		case 6:	return g_strdup ("nfo:orientation-right-mirror");
+		case 7:	return g_strdup ("nfo:orientation-left");
 		}
 	}
 
 	return NULL;
 }
 
-
 static gchar *
 get_metering_mode (TIFF *image)
 {
-	guint16 varui16 = 0;
-
-	if (TIFFGetField (image, EXIFTAG_METERINGMODE, &varui16)) {
-		switch (varui16) {
-		case 1:
-			return g_strdup ("nmm:metering-mode-average");
-		case 2:
-			return g_strdup ("nmm:metering-mode-center-weighted-average");
-		case 3:
-			return g_strdup ("nmm:metering-mode-spot");
-		case 4:
-			return g_strdup ("nmm:metering-mode-multispot");
-		case 5:
-			return g_strdup ("nmm:metering-mode-pattern");
-		case 6:
-			return g_strdup ("nmm:metering-mode-partial");
-		default:
+	guint16 data = 0;
+
+	if (TIFFGetField (image, EXIFTAG_METERINGMODE, &data)) {
+		switch (data) {
+		case 1: return g_strdup ("nmm:metering-mode-average");
+		case 2: return g_strdup ("nmm:metering-mode-center-weighted-average");
+		case 3: return g_strdup ("nmm:metering-mode-spot");
+		case 4: return g_strdup ("nmm:metering-mode-multispot");
+		case 5: return g_strdup ("nmm:metering-mode-pattern");
+		case 6: return g_strdup ("nmm:metering-mode-partial");
+		default: 
 			return g_strdup ("nmm:metering-mode-other");
 		}
 	}
@@ -150,60 +155,74 @@ get_metering_mode (TIFF *image)
 	return NULL;
 }
 
-
-
 static gchar *
 get_white_balance (TIFF *image)
 {
-	guint16 varui16 = 0;
+	guint16 data = 0;
 
-	if (TIFFGetField (image, EXIFTAG_WHITEBALANCE, &varui16)) {
-		if (varui16 == 0) {
+	if (TIFFGetField (image, EXIFTAG_WHITEBALANCE, &data)) {
+		if (data == 0) {
 			return g_strdup ("nmm:white-balance-auto");
+		} else {
+			return g_strdup ("nmm:white-balance-manual");
 		}
-		return g_strdup ("nmm:white-balance-manual");
 	}
 
 	return NULL;
 }
 
-
 static gchar *
-get_value (TIFF *image, guint tag, guint type)
+tag_to_string (TIFF    *image, 
+               guint    tag,
+               TagType  type)
 {
-	guint16 count16 = 0;
-	gfloat vardouble = 0;
-	guint16 varui16 = 0;
-	guint32 varui32 = 0;
-	gchar *text = NULL;
-	void *data = NULL;
-
 	switch (type) {
-	case TIFF_TAGTYPE_STRING:
-		if (TIFFGetField (image, tag, &text)) {
-			return g_strdup (text);
+	case TAG_TYPE_STRING: {
+		gchar *data = NULL;
+
+		if (TIFFGetField (image, tag, &data)) {
+			return g_strdup (data);
 		}
 		break;
-	case TIFF_TAGTYPE_UINT16:
-		if (TIFFGetField (image, tag, &varui16)) {
-			return g_strdup_printf ("%i", varui16);
+	}
+
+	case TAG_TYPE_UINT16: {
+		guint16 data = 0;
+
+		if (TIFFGetField (image, tag, &data)) {
+			return g_strdup_printf ("%i", data);
 		}
 		break;
-	case TIFF_TAGTYPE_UINT32:
-		if (TIFFGetField (image, tag, &varui32)) {
-			return g_strdup_printf ("%i", varui32);
+	}
+
+	case TAG_TYPE_UINT32: {
+		guint32 data = 0;
+
+		if (TIFFGetField (image, tag, &data)) {
+			return g_strdup_printf ("%i", data);
 		}
 		break;
-	case TIFF_TAGTYPE_DOUBLE:
-		if (TIFFGetField (image, tag, &vardouble)) {
-			return g_strdup_printf ("%f", vardouble);
+	}
+
+	case TAG_TYPE_DOUBLE: {
+		gfloat data = 0;
+
+		if (TIFFGetField (image, tag, &data)) {
+			return g_strdup_printf ("%f", data);
 		}
 		break;
-	case TIFF_TAGTYPE_C16_UINT16:
-		if (TIFFGetField (image, tag, &count16, &data)) {
-			return g_strdup_printf ("%i", * (guint16 *) data);
+	}
+
+	case TAG_TYPE_C16_UINT16: {
+		void *data = NULL;
+		guint16 count = 0;
+
+		if (TIFFGetField (image, tag, &count, &data)) {
+			return g_strdup_printf ("%i", * (guint16*) data);
 		}
 		break;
+	}
+
 	default:
 		break;
 	}
@@ -211,25 +230,28 @@ get_value (TIFF *image, guint tag, guint type)
 	return NULL;
 }
 
-
 static void
-insert_keywords (TrackerSparqlBuilder *metadata, const gchar *uri, gchar *keywords)
+insert_keywords (TrackerSparqlBuilder *metadata, 
+                 const gchar          *uri, 
+                 gchar                *keywords)
 {
 	char *lasts, *keyw;
 	size_t len;
 
 	keyw = keywords;
 	keywords = strchr (keywords, '"');
-	if (keywords)
+	if (keywords) {
 		keywords++;
-	else
+	} else {
 		keywords = keyw;
+	}
 
 	len = strlen (keywords);
 	if (keywords[len - 1] == '"')
 		keywords[len - 1] = '\0';
 
-	for (keyw = strtok_r (keywords, ",; ", &lasts); keyw;
+	for (keyw = strtok_r (keywords, ",; ", &lasts);
+	     keyw;
 	     keyw = strtok_r (NULL, ",; ", &lasts)) {
 		tracker_sparql_builder_predicate (metadata, "nao:hasTag");
 
@@ -250,24 +272,27 @@ extract_tiff (const gchar          *uri,
 	      TrackerSparqlBuilder *metadata)
 {
 	TIFF *image;
-	glong exifOffset;
-	gchar *filename = g_filename_from_uri (uri, NULL, NULL);
-	TrackerXmpData xmp_data = { 0 };
-	TrackerIptcData iptc_data = { 0 };
-	TrackerExifData exif_data = { 0 };
-	TiffNeedsMergeData merge_data = { 0 };
-	TiffData tiff_data = { 0 };
+	TrackerXmpData xd = { 0 };
+	TrackerIptcData id = { 0 };
+	TrackerExifData ed = { 0 };
+	MergeData md = { 0 };
+	TiffData td = { 0 };
+	gchar *filename;
+	gchar *date;
+	glong exif_offset;
 
 #ifdef HAVE_LIBIPTCDATA
-	gchar   *iptcOffset;
-	guint32  iptcSize;
+	gchar *iptc_offset;
+	guint32 iptc_size;
 #endif
 
 #ifdef HAVE_EXEMPI
-	gchar *xmpOffset;
+	gchar *xmp_offset;
 	guint32 size;
 #endif /* HAVE_EXEMPI */
 
+	filename = g_filename_from_uri (uri, NULL, NULL);
+
 	if ((image = TIFFOpen (filename, "r")) == NULL){
 		g_warning ("Could not open image:'%s'\n", filename);
 		g_free (filename);
@@ -279,215 +304,147 @@ extract_tiff (const gchar          *uri,
 	tracker_sparql_builder_object (metadata, "nmm:Photo");
 
 #ifdef HAVE_LIBIPTCDATA
-	if (TIFFGetField (image, TIFFTAG_RICHTIFFIPTC, &iptcSize, &iptcOffset)) {
-		if (TIFFIsByteSwapped(image) != 0)
-			TIFFSwabArrayOfLong((uint32 *) iptcOffset, (unsigned long) iptcSize);
-		tracker_iptc_read (iptcOffset,
-		                   4 * iptcSize,
-		                   uri, 
-		                   &iptc_data);
+	if (TIFFGetField (image, 
+	                  TIFFTAG_RICHTIFFIPTC, 
+	                  &iptc_size, 
+	                  &iptc_offset)) {
+		if (TIFFIsByteSwapped(image) != 0) {
+			TIFFSwabArrayOfLong((uint32*) iptc_offset, 
+			                    (unsigned long) iptc_size);
+		}
+		tracker_iptc_read (iptc_offset, 4 * iptc_size, uri, &id);
 	}
 #endif /* HAVE_LIBIPTCDATA */
 
 	/* FIXME There are problems between XMP data embedded with different tools
 	   due to bugs in the original spec (type) */
 #ifdef HAVE_EXEMPI
-	if (TIFFGetField (image, TIFFTAG_XMLPACKET, &size, &xmpOffset)) {
-		tracker_xmp_read (xmpOffset,
-		                  size,
-		                  uri,
-		                  &xmp_data);
+	if (TIFFGetField (image, TIFFTAG_XMLPACKET, &size, &xmp_offset)) {
+		tracker_xmp_read (xmp_offset, size, uri, &xd);
 	}
 #endif /* HAVE_EXEMPI */
 
-	if (!tiff_data.imagewidth)
-		tiff_data.imagewidth = get_value (image, TIFFTAG_IMAGEWIDTH, TIFF_TAGTYPE_UINT32);
-	if (!tiff_data.imagelength)
-		tiff_data.imagelength = get_value (image, TIFFTAG_IMAGELENGTH, TIFF_TAGTYPE_UINT32);
-	if (!tiff_data.artist)
-		tiff_data.artist = get_value (image, TIFFTAG_ARTIST, TIFF_TAGTYPE_STRING);
-	if (!tiff_data.copyright)
-		tiff_data.copyright = get_value (image, TIFFTAG_COPYRIGHT, TIFF_TAGTYPE_STRING);
-	if (!tiff_data.datetime) {
-		gchar *date = get_value (image, TIFFTAG_DATETIME, TIFF_TAGTYPE_STRING);
-		tiff_data.datetime = tracker_date_guess (date);
-		g_free (date);
-	}
-	if (!tiff_data.documentname)
-		tiff_data.documentname = get_value (image, TIFFTAG_DOCUMENTNAME, TIFF_TAGTYPE_STRING);
-	if (!tiff_data.imagedescription)
-		tiff_data.imagedescription = get_value (image, TIFFTAG_IMAGEDESCRIPTION, TIFF_TAGTYPE_STRING);
-	if (!tiff_data.make)
-		tiff_data.make = get_value (image, TIFFTAG_MAKE, TIFF_TAGTYPE_STRING);
-	if (!tiff_data.model)
-		tiff_data.model = get_value (image, TIFFTAG_MODEL, TIFF_TAGTYPE_STRING);
-	if (!tiff_data.orientation)
-		tiff_data.orientation = get_orientation (image);
-
-	if (TIFFGetField (image, TIFFTAG_EXIFIFD, &exifOffset)) {
-		if (TIFFReadEXIFDirectory (image, exifOffset)) {
-			if (!exif_data.exposure_time)
-				exif_data.exposure_time = get_value (image, EXIFTAG_EXPOSURETIME, TIFF_TAGTYPE_DOUBLE);
-			if (!exif_data.fnumber)
-				exif_data.fnumber = get_value (image, EXIFTAG_FNUMBER, TIFF_TAGTYPE_DOUBLE);
-			if (!exif_data.iso_speed_ratings)
-				exif_data.iso_speed_ratings = get_value (image, EXIFTAG_ISOSPEEDRATINGS, TIFF_TAGTYPE_C16_UINT16);
-			if (!exif_data.time_original) {
-				gchar *date = get_value (image, EXIFTAG_DATETIMEORIGINAL, TIFF_TAGTYPE_STRING);
-				exif_data.time_original = tracker_date_guess (date);
-				g_free (date);
-			}
-			if (!exif_data.metering_mode)
-				exif_data.metering_mode = get_metering_mode (image);
-			if (!exif_data.flash)
-				exif_data.flash = get_flash (image);
-			if (!exif_data.focal_length)
-				exif_data.focal_length = get_value (image, EXIFTAG_DATETIMEORIGINAL, TIFF_TAGTYPE_DOUBLE);
-			if (!exif_data.white_balance)
-				exif_data.white_balance = get_white_balance (image);
-			/* if (!exif_data.software)
-				exif_data.software = get_value (image, EXIFTAG_SOFTWARE, TIFF_TAGTYPE_STRING); */
+	/* Get Tiff specifics */
+	td.width = tag_to_string (image, TIFFTAG_IMAGEWIDTH, TAG_TYPE_UINT32);
+	td.length = tag_to_string (image, TIFFTAG_IMAGELENGTH, TAG_TYPE_UINT32);
+	td.artist = tag_to_string (image, TIFFTAG_ARTIST, TAG_TYPE_STRING);
+	td.copyright = tag_to_string (image, TIFFTAG_COPYRIGHT, TAG_TYPE_STRING);
+
+	date = tag_to_string (image, TIFFTAG_DATETIME, TAG_TYPE_STRING);
+	td.date = tracker_date_guess (date);
+	g_free (date);
+
+	td.title = tag_to_string (image, TIFFTAG_DOCUMENTNAME, TAG_TYPE_STRING);
+	td.description = tag_to_string (image, TIFFTAG_IMAGEDESCRIPTION, TAG_TYPE_STRING);
+	td.make = tag_to_string (image, TIFFTAG_MAKE, TAG_TYPE_STRING);
+	td.model = tag_to_string (image, TIFFTAG_MODEL, TAG_TYPE_STRING);
+	td.orientation = get_orientation (image);
+
+	/* Get Exif specifics */
+	if (TIFFGetField (image, TIFFTAG_EXIFIFD, &exif_offset)) {
+		if (TIFFReadEXIFDirectory (image, exif_offset)) {
+			ed.exposure_time = tag_to_string (image, EXIFTAG_EXPOSURETIME, TAG_TYPE_DOUBLE);
+			ed.fnumber = tag_to_string (image, EXIFTAG_FNUMBER, TAG_TYPE_DOUBLE);
+			ed.iso_speed_ratings = tag_to_string (image, EXIFTAG_ISOSPEEDRATINGS, TAG_TYPE_C16_UINT16);
+			date = tag_to_string (image, EXIFTAG_DATETIMEORIGINAL, TAG_TYPE_STRING);
+			ed.time_original = tracker_date_guess (date);
+			g_free (date);
+
+			ed.metering_mode = get_metering_mode (image);
+			ed.flash = get_flash (image);
+			ed.focal_length = tag_to_string (image, EXIFTAG_DATETIMEORIGINAL, TAG_TYPE_DOUBLE);
+			ed.white_balance = get_white_balance (image);
+			/* ed.software = tag_to_string (image, EXIFTAG_SOFTWARE, TAG_TYPE_STRING); */
 		}
 	}
 
 	TIFFClose (image);
 	g_free (filename);
 
-	merge_data.camera = tracker_merge (" ", 2, xmp_data.make,
-	                                   xmp_data.model);
+	md.camera = tracker_merge (" ", 2, xd.make, xd.model);
 
-	if (!merge_data.camera) {
-		merge_data.camera = tracker_merge (" ", 2, tiff_data.make,
-		                                   tiff_data.model);
+	if (!md.camera) {
+		md.camera = tracker_merge (" ", 2, td.make, td.model);
 
-		if (!merge_data.camera) {
-			merge_data.camera = tracker_merge (" ", 2, exif_data.make,
-			                                   exif_data.model);
+		if (!md.camera) {
+			md.camera = tracker_merge (" ", 2, ed.make, ed.model);
 		} else {
-			g_free (exif_data.model);
-			g_free (exif_data.make);
+			g_free (ed.model);
+			g_free (ed.make);
 		}
 	} else {
-		g_free (tiff_data.model);
-		g_free (tiff_data.make);
-		g_free (exif_data.model);
-		g_free (exif_data.make);
-	}
-
-	merge_data.title = tracker_coalesce (5, xmp_data.title,
-	                                     xmp_data.pdf_title,
-	                                     tiff_data.documentname,
-	                                     exif_data.document_name,
-	                                     xmp_data.title2);
-
-	merge_data.orientation = tracker_coalesce (4, xmp_data.orientation,
-	                                           tiff_data.orientation,
-	                                           exif_data.orientation,
-	                                           iptc_data.image_orientation);
-
-	merge_data.copyright = tracker_coalesce (4, xmp_data.rights,
-	                                         tiff_data.copyright,
-	                                         exif_data.copyright,
-	                                         iptc_data.copyright_notice);
-
-	merge_data.white_balance = tracker_coalesce (2, xmp_data.white_balance,
-	                                             exif_data.white_balance);
-
-
-	merge_data.fnumber =  tracker_coalesce (2, xmp_data.fnumber,
-	                                        exif_data.fnumber);
-
-	merge_data.flash =  tracker_coalesce (2, xmp_data.flash,
-	                                      exif_data.flash);
-
-	merge_data.focal_length =  tracker_coalesce (2, xmp_data.focal_length,
-	                                             exif_data.focal_length);
-
-	merge_data.artist =  tracker_coalesce (4, xmp_data.artist,
-	                                       tiff_data.artist,
-	                                       exif_data.artist,
-	                                       xmp_data.contributor);
-
-	merge_data.exposure_time =  tracker_coalesce (2, xmp_data.exposure_time,
-	                                              exif_data.exposure_time);
-
-	merge_data.iso_speed_ratings =  tracker_coalesce (2, xmp_data.iso_speed_ratings,
-	                                                  exif_data.iso_speed_ratings);
-
-	merge_data.date =  tracker_coalesce (6, xmp_data.date,
-	                                     xmp_data.time_original,
-	                                     tiff_data.datetime,
-	                                     exif_data.time,
-	                                     iptc_data.date_created,
-	                                     exif_data.time_original);
-
-	merge_data.description = tracker_coalesce (3, xmp_data.description,
-	                                           tiff_data.imagedescription,
-	                                           exif_data.description);
-
-	merge_data.metering_mode =  tracker_coalesce (2, xmp_data.metering_mode,
-	                                              exif_data.metering_mode);
-
-	merge_data.city = tracker_coalesce (2, xmp_data.city, iptc_data.city);
-	merge_data.state = tracker_coalesce (2, xmp_data.state, iptc_data.state);
-	merge_data.address = tracker_coalesce (2, xmp_data.address, iptc_data.sublocation);
-	merge_data.country  = tracker_coalesce (2, xmp_data.country, iptc_data.country_name);
-
-	merge_data.creator =  tracker_coalesce (3, xmp_data.creator,
-	                                        iptc_data.byline,
-	                                        iptc_data.credit);
-
-	merge_data.x_dimension =  tracker_coalesce (2, tiff_data.imagewidth,
-	                                            exif_data.x_dimension);
-	merge_data.y_dimension =  tracker_coalesce (2, tiff_data.imagelength,
-	                                            exif_data.y_dimension);
-
-	if (exif_data.user_comment) {
+		g_free (td.model);
+		g_free (td.make);
+		g_free (ed.model);
+		g_free (ed.make);
+	}
+
+	md.title = tracker_coalesce (5, xd.title, xd.pdf_title, td.title, ed.document_name, xd.title2);
+	md.orientation = tracker_coalesce (4, xd.orientation, td.orientation, ed.orientation, id.image_orientation);
+	md.copyright = tracker_coalesce (4, xd.rights, td.copyright, ed.copyright, id.copyright_notice);
+	md.white_balance = tracker_coalesce (2, xd.white_balance, ed.white_balance);
+	md.fnumber = tracker_coalesce (2, xd.fnumber, ed.fnumber);
+	md.flash = tracker_coalesce (2, xd.flash, ed.flash);
+	md.focal_length = tracker_coalesce (2, xd.focal_length, ed.focal_length);
+	md.artist = tracker_coalesce (4, xd.artist, td.artist, ed.artist, xd.contributor);
+	md.exposure_time = tracker_coalesce (2, xd.exposure_time, ed.exposure_time);
+	md.iso_speed_ratings = tracker_coalesce (2, xd.iso_speed_ratings, ed.iso_speed_ratings);
+	md.date = tracker_coalesce (6, xd.date, xd.time_original, td.date, ed.time, id.date_created, ed.time_original);
+	md.description = tracker_coalesce (3, xd.description, td.description, ed.description);
+	md.metering_mode = tracker_coalesce (2, xd.metering_mode, ed.metering_mode);
+	md.city = tracker_coalesce (2, xd.city, id.city);
+	md.state = tracker_coalesce (2, xd.state, id.state);
+	md.address = tracker_coalesce (2, xd.address, id.sublocation);
+	md.country = tracker_coalesce (2, xd.country, id.country_name);
+	md.creator = tracker_coalesce (3, xd.creator, id.byline, id.credit);
+	md.x_dimension = tracker_coalesce (2, td.width, ed.x_dimension);
+	md.y_dimension = tracker_coalesce (2, td.length, ed.y_dimension);
+
+	if (ed.user_comment) {
 		tracker_sparql_builder_predicate (metadata, "nie:comment");
-		tracker_sparql_builder_object_unvalidated (metadata, exif_data.user_comment);
-		g_free (exif_data.user_comment);
+		tracker_sparql_builder_object_unvalidated (metadata, ed.user_comment);
+		g_free (ed.user_comment);
 	}
 
-	if (merge_data.x_dimension) {
+	if (md.x_dimension) {
 		tracker_sparql_builder_predicate (metadata, "nfo:width");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.x_dimension);
-		g_free (merge_data.x_dimension);
+		tracker_sparql_builder_object_unvalidated (metadata, md.x_dimension);
+		g_free (md.x_dimension);
 	}
 
-	if (merge_data.y_dimension) {
+	if (md.y_dimension) {
 		tracker_sparql_builder_predicate (metadata, "nfo:height");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.y_dimension);
-		g_free (merge_data.y_dimension);
+		tracker_sparql_builder_object_unvalidated (metadata, md.y_dimension);
+		g_free (md.y_dimension);
 	}
 
-	if (xmp_data.keywords) {
-		insert_keywords (metadata, uri, xmp_data.keywords);
-		g_free (xmp_data.keywords);
+	if (xd.keywords) {
+		insert_keywords (metadata, uri, xd.keywords);
+		g_free (xd.keywords);
 	}
 
-	if (xmp_data.pdf_keywords) {
-		insert_keywords (metadata, uri, xmp_data.pdf_keywords);
-		g_free (xmp_data.pdf_keywords);
+	if (xd.pdf_keywords) {
+		insert_keywords (metadata, uri, xd.pdf_keywords);
+		g_free (xd.pdf_keywords);
 	}
 
-	if (xmp_data.subject) {
-		insert_keywords (metadata, uri, xmp_data.subject);
-		g_free (xmp_data.subject);
+	if (xd.subject) {
+		insert_keywords (metadata, uri, xd.subject);
+		g_free (xd.subject);
 	}
 
-	if (iptc_data.contact) {
+	if (id.contact) {
 		tracker_sparql_builder_predicate (metadata, "nco:representative");
 		tracker_sparql_builder_object_blank_open (metadata);
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "nco:Contact");
 		tracker_sparql_builder_predicate (metadata, "nco:fullname");
-		tracker_sparql_builder_object_unvalidated (metadata, iptc_data.contact);
+		tracker_sparql_builder_object_unvalidated (metadata, id.contact);
 		tracker_sparql_builder_object_blank_close (metadata);
-		g_free (iptc_data.contact);
+		g_free (id.contact);
 	}
 
-
-	if (xmp_data.publisher) {
+	if (xd.publisher) {
 		tracker_sparql_builder_predicate (metadata, "nco:publisher");
 
 		tracker_sparql_builder_object_blank_open (metadata);
@@ -495,153 +452,153 @@ extract_tiff (const gchar          *uri,
 		tracker_sparql_builder_object (metadata, "nco:Contact");
 
 		tracker_sparql_builder_predicate (metadata, "nco:fullname");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.publisher);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.publisher);
 		tracker_sparql_builder_object_blank_close (metadata);
-		g_free (xmp_data.publisher);
+		g_free (xd.publisher);
 	}
 
-	if (xmp_data.type) {
+	if (xd.type) {
 		tracker_sparql_builder_predicate (metadata, "dc:type");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.type);
-		g_free (xmp_data.type);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.type);
+		g_free (xd.type);
 	}
 
-	if (xmp_data.format) {
+	if (xd.format) {
 		tracker_sparql_builder_predicate (metadata, "dc:format");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.format);
-		g_free (xmp_data.format);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.format);
+		g_free (xd.format);
 	}
 
-	if (xmp_data.identifier) {
+	if (xd.identifier) {
 		tracker_sparql_builder_predicate (metadata, "dc:identifier");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.identifier);
-		g_free (xmp_data.identifier);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.identifier);
+		g_free (xd.identifier);
 	}
 
-	if (xmp_data.source) {
+	if (xd.source) {
 		tracker_sparql_builder_predicate (metadata, "dc:source");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.source);
-		g_free (xmp_data.source);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.source);
+		g_free (xd.source);
 	}
 
-	if (xmp_data.language) {
+	if (xd.language) {
 		tracker_sparql_builder_predicate (metadata, "dc:language");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.language);
-		g_free (xmp_data.language);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.language);
+		g_free (xd.language);
 	}
 
-	if (xmp_data.relation) {
+	if (xd.relation) {
 		tracker_sparql_builder_predicate (metadata, "dc:relation");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.relation);
-		g_free (xmp_data.relation);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.relation);
+		g_free (xd.relation);
 	}
 
-	if (xmp_data.coverage) {
+	if (xd.coverage) {
 		tracker_sparql_builder_predicate (metadata, "dc:coverage");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.coverage);
-		g_free (xmp_data.coverage);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.coverage);
+		g_free (xd.coverage);
 	}
 
-	if (xmp_data.rating) {
+	if (xd.rating) {
 		tracker_sparql_builder_predicate (metadata, "nao:numericRating");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.rating);
-		g_free (xmp_data.rating);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.rating);
+		g_free (xd.rating);
 	}
 
-	if (xmp_data.license) {
+	if (xd.license) {
 		tracker_sparql_builder_predicate (metadata, "nie:license");
-		tracker_sparql_builder_object_unvalidated (metadata, xmp_data.license);
-		g_free (xmp_data.license);
+		tracker_sparql_builder_object_unvalidated (metadata, xd.license);
+		g_free (xd.license);
 	}
 
-	if (merge_data.city || merge_data.state || merge_data.address || merge_data.country) {
+	if (md.city || md.state || md.address || md.country) {
 		tracker_sparql_builder_predicate (metadata, "mlo:location");
 
 		tracker_sparql_builder_object_blank_open (metadata);
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "mlo:GeoPoint");
 	
-		if (merge_data.address) {
+		if (md.address) {
 			tracker_sparql_builder_predicate (metadata, "mlo:address");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.address);
-			g_free (merge_data.address);
+			tracker_sparql_builder_object_unvalidated (metadata, md.address);
+			g_free (md.address);
 		}
 	
-		if (merge_data.state) {
+		if (md.state) {
 			tracker_sparql_builder_predicate (metadata, "mlo:state");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.state);
-			g_free (merge_data.state);
+			tracker_sparql_builder_object_unvalidated (metadata, md.state);
+			g_free (md.state);
 		}
 	
-		if (merge_data.city) {
+		if (md.city) {
 			tracker_sparql_builder_predicate (metadata, "mlo:city");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.city);
-			g_free (merge_data.city);
+			tracker_sparql_builder_object_unvalidated (metadata, md.city);
+			g_free (md.city);
 		}
 	
-		if (merge_data.country) {
+		if (md.country) {
 			tracker_sparql_builder_predicate (metadata, "mlo:country");
-			tracker_sparql_builder_object_unvalidated (metadata, merge_data.country);
-			g_free (merge_data.country);
+			tracker_sparql_builder_object_unvalidated (metadata, md.country);
+			g_free (md.country);
 		}
 		
 		tracker_sparql_builder_object_blank_close (metadata);
 	}
 
-	if (iptc_data.keywords) {
-		insert_keywords (metadata, uri, iptc_data.keywords);
-		g_free (iptc_data.keywords);
+	if (id.keywords) {
+		insert_keywords (metadata, uri, id.keywords);
+		g_free (id.keywords);
 	}
 
-	if (merge_data.camera) {
+	if (md.camera) {
 		tracker_sparql_builder_predicate (metadata, "nmm:camera");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.camera);
-		g_free (merge_data.camera);
+		tracker_sparql_builder_object_unvalidated (metadata, md.camera);
+		g_free (md.camera);
 	}
 
-	if (merge_data.title) {
+	if (md.title) {
 		tracker_sparql_builder_predicate (metadata, "nie:title");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.title);
-		g_free (merge_data.title);
+		tracker_sparql_builder_object_unvalidated (metadata, md.title);
+		g_free (md.title);
 	}
 
-	if (merge_data.orientation) {
+	if (md.orientation) {
 		tracker_sparql_builder_predicate (metadata, "nfo:orientation");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.orientation);
-		g_free (merge_data.orientation);
+		tracker_sparql_builder_object_unvalidated (metadata, md.orientation);
+		g_free (md.orientation);
 	}
 
-	if (merge_data.copyright) {
+	if (md.copyright) {
 		tracker_sparql_builder_predicate (metadata, "nie:copyright");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.copyright);
-		g_free (merge_data.copyright);
+		tracker_sparql_builder_object_unvalidated (metadata, md.copyright);
+		g_free (md.copyright);
 	}
 
-	if (merge_data.white_balance) {
+	if (md.white_balance) {
 		tracker_sparql_builder_predicate (metadata, "nmm:whiteBalance");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.white_balance);
-		g_free (merge_data.white_balance);
+		tracker_sparql_builder_object_unvalidated (metadata, md.white_balance);
+		g_free (md.white_balance);
 	}
 
-	if (merge_data.fnumber) {
+	if (md.fnumber) {
 		tracker_sparql_builder_predicate (metadata, "nmm:fnumber");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.fnumber);
-		g_free (merge_data.fnumber);
+		tracker_sparql_builder_object_unvalidated (metadata, md.fnumber);
+		g_free (md.fnumber);
 	}
 
-	if (merge_data.flash) {
+	if (md.flash) {
 		tracker_sparql_builder_predicate (metadata, "nmm:flash");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.flash);
-		g_free (merge_data.flash);
+		tracker_sparql_builder_object_unvalidated (metadata, md.flash);
+		g_free (md.flash);
 	}
 
-	if (merge_data.focal_length) {
+	if (md.focal_length) {
 		tracker_sparql_builder_predicate (metadata, "nmm:focalLength");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.focal_length);
-		g_free (merge_data.focal_length);
+		tracker_sparql_builder_object_unvalidated (metadata, md.focal_length);
+		g_free (md.focal_length);
 	}
 
-	if (merge_data.artist) {
+	if (md.artist) {
 		tracker_sparql_builder_predicate (metadata, "nco:contributor");
 
 		tracker_sparql_builder_object_blank_open (metadata);
@@ -649,43 +606,43 @@ extract_tiff (const gchar          *uri,
 		tracker_sparql_builder_object (metadata, "nco:Contact");
 
 		tracker_sparql_builder_predicate (metadata, "nco:fullname");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.artist);
+		tracker_sparql_builder_object_unvalidated (metadata, md.artist);
 		tracker_sparql_builder_object_blank_close (metadata);
-		g_free (merge_data.artist);
+		g_free (md.artist);
 	}
 
-	if (merge_data.exposure_time) {
+	if (md.exposure_time) {
 		tracker_sparql_builder_predicate (metadata, "nmm:exposureTime");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.exposure_time);
-		g_free (merge_data.exposure_time);
+		tracker_sparql_builder_object_unvalidated (metadata, md.exposure_time);
+		g_free (md.exposure_time);
 	}
 
-	if (merge_data.iso_speed_ratings) {
+	if (md.iso_speed_ratings) {
 		tracker_sparql_builder_predicate (metadata, "nmm:isoSpeed");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.iso_speed_ratings);
-		g_free (merge_data.iso_speed_ratings);
+		tracker_sparql_builder_object_unvalidated (metadata, md.iso_speed_ratings);
+		g_free (md.iso_speed_ratings);
 	}
 
-	if (merge_data.date) {
+	if (md.date) {
 		tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.date);
-		g_free (merge_data.date);
+		tracker_sparql_builder_object_unvalidated (metadata, md.date);
+		g_free (md.date);
 	}
 
-	if (merge_data.description) {
+	if (md.description) {
 		tracker_sparql_builder_predicate (metadata, "nie:description");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.description);
-		g_free (merge_data.description);
+		tracker_sparql_builder_object_unvalidated (metadata, md.description);
+		g_free (md.description);
 	}
 
-	if (merge_data.metering_mode) {
+	if (md.metering_mode) {
 		tracker_sparql_builder_predicate (metadata, "nmm:meteringMode");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.metering_mode);
-		g_free (merge_data.metering_mode);
+		tracker_sparql_builder_object_unvalidated (metadata, md.metering_mode);
+		g_free (md.metering_mode);
 	}
 
-	if (merge_data.creator) {
-		if (iptc_data.byline_title) {
+	if (md.creator) {
+		if (id.byline_title) {
 			tracker_sparql_builder_insert_open (preupdate, NULL);
 
 			tracker_sparql_builder_subject (preupdate, "_:affiliation_by_line");
@@ -693,7 +650,7 @@ extract_tiff (const gchar          *uri,
 			tracker_sparql_builder_object (preupdate, "nco:Affiliation");
 
 			tracker_sparql_builder_predicate (preupdate, "nco:title");
-			tracker_sparql_builder_object_unvalidated (preupdate, iptc_data.byline_title);
+			tracker_sparql_builder_object_unvalidated (preupdate, id.byline_title);
 
 			tracker_sparql_builder_insert_close (preupdate);
 		}
@@ -703,7 +660,7 @@ extract_tiff (const gchar          *uri,
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "nco:Contact");
 		tracker_sparql_builder_predicate (metadata, "nco:fullname");
-		tracker_sparql_builder_object_unvalidated (metadata, merge_data.creator);
+		tracker_sparql_builder_object_unvalidated (metadata, md.creator);
 
                 /*
                  * This must be a Contact, not a PersonContact. But hasAffiliation
@@ -711,7 +668,7 @@ extract_tiff (const gchar          *uri,
                  * Commented out the code while figuring out a solution (most
                  * probably to drop the property).
                  *
-                 * if (iptc_data.byline_title) {
+                 * if (id.byline_title) {
                  *  tracker_sparql_builder_predicate (metadata, "a");
                  *  tracker_sparql_builder_object (metadata, "nco:PersonContact");
                  *  tracker_sparql_builder_predicate (metadata, "nco:hasAffiliation");
@@ -719,10 +676,10 @@ extract_tiff (const gchar          *uri,
                  * }
                  */
 		tracker_sparql_builder_object_blank_close (metadata);
-		g_free (merge_data.creator);
+		g_free (md.creator);
 	}
 
-	g_free (iptc_data.byline_title);
+	g_free (id.byline_title);
 }
 
 TrackerExtractData *
diff --git a/src/tracker-extract/tracker-extract-xmp.c b/src/tracker-extract/tracker-extract-xmp.c
index 005e1f6..5e268e5 100644
--- a/src/tracker-extract/tracker-extract-xmp.c
+++ b/src/tracker-extract/tracker-extract-xmp.c
@@ -133,26 +133,30 @@ extract_xmp (const gchar          *uri,
              TrackerSparqlBuilder *preupdate,
              TrackerSparqlBuilder *metadata)
 {
+	TrackerXmpData xd = { 0 };
+	GError *error;
+	gchar *filename;
 	gchar *contents;
 	gsize length;
-	GError *error;
-	gchar *filename = g_filename_from_uri (uri, NULL, NULL);
-	TrackerXmpData xmp_data = { 0 };
+
+	filename = g_filename_from_uri (uri, NULL, NULL);
 
 	if (g_file_get_contents (filename, &contents, &length, &error)) {
-		gchar *orig_uri = find_orig_uri (filename);
+		gchar *original_uri;
 
-		/* If no orig file is found for the sidekick, we use the sidekick to
-		 * describe itself instead, falling back to uri */
+		original_uri = find_orig_uri (filename);
 
+		/* If no orig file is found for the sidekick, we use the sidekick to
+		 * describe itself instead, falling back to uri 
+		 */
 		tracker_xmp_read (contents,
 		                  length,
-		                  orig_uri ? orig_uri : uri,
-		                  &xmp_data);
+		                  original_uri ? original_uri : uri,
+		                  &xd);
 
-		tracker_xmp_apply (metadata, uri, &xmp_data);
+		tracker_xmp_apply (metadata, uri, &xd);
 
-		g_free (orig_uri);
+		g_free (original_uri);
 	}
 
 	g_free (filename);



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