[tracker] Combining Make and Model of image metadata for nmm:camera



commit 431717ad88a182577221c06c44106be8bb4c642a
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Sep 8 16:04:09 2009 +0200

    Combining Make and Model of image metadata for nmm:camera

 src/libtracker-common/tracker-utils.c      |   37 ++++++++++++++++++++++++++++
 src/libtracker-common/tracker-utils.h      |    2 +
 src/tracker-extract/tracker-extract-jpeg.c |   14 +++++++---
 src/tracker-extract/tracker-extract-pdf.c  |    2 +-
 src/tracker-extract/tracker-extract-png.c  |    2 +-
 src/tracker-extract/tracker-extract-tiff.c |   26 +++++++++++++++----
 src/tracker-extract/tracker-xmp.c          |    2 +-
 7 files changed, 72 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-common/tracker-utils.c b/src/libtracker-common/tracker-utils.c
index ed4c4a5..7b54c4f 100644
--- a/src/libtracker-common/tracker-utils.c
+++ b/src/libtracker-common/tracker-utils.c
@@ -532,3 +532,40 @@ tracker_coalesce (gint n_values,
 
 	return result;
 }
+
+
+gchar *
+tracker_merge (const gchar *delim, gint n_values,
+               ...)
+{
+	va_list args;
+	gint    i;
+	GString *str = NULL;
+
+	va_start (args, n_values);
+
+	for (i = 0; i < n_values; i++) {
+		gchar *value;
+
+		value = va_arg (args, gchar *);
+		if (value) {
+			if (!str) {
+				str = g_string_new (value);
+			} else {
+				if (delim) {
+					g_string_append (str, delim);
+				}
+				g_string_append (str, value);
+			}
+			g_free (value);
+		}
+	}
+
+	va_end (args);
+
+	if (!str) {
+		return NULL;
+	}
+
+	return g_string_free (str, FALSE);
+}
diff --git a/src/libtracker-common/tracker-utils.h b/src/libtracker-common/tracker-utils.h
index fafd578..2f0cd29 100644
--- a/src/libtracker-common/tracker-utils.h
+++ b/src/libtracker-common/tracker-utils.h
@@ -47,6 +47,8 @@ gchar*   tracker_uri_printf_escaped         (const gchar *format,
 					     ...);
 gchar *  tracker_coalesce                   (gint n_values,
 					     ...);
+gchar *  tracker_merge                      (const gchar *delim, gint n_values,
+					     ...);
 
 /* Temporary: Just here until we upgrade to GLib 2.18. */
 G_CONST_RETURN gchar *
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index c94416e..c61312e 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -264,10 +264,16 @@ extract_jpeg (const gchar *uri,
 			marker = marker->next;
 		}
 
-		merge_data.camera = tracker_coalesce (4, xmp_data.Model, 
-		                                      xmp_data.Make,
-		                                      exif_data.model,
-		                                      exif_data.make);
+		merge_data.camera = tracker_merge (" ", 2, xmp_data.Make,
+		                                   xmp_data.Model);
+
+		if (!merge_data.camera) {
+			merge_data.camera = tracker_merge (" ", 2, exif_data.make,
+			                                   exif_data.model);
+		} else {
+			g_free (exif_data.model);
+			g_free (exif_data.make);
+		}
 
 		merge_data.title = tracker_coalesce (2, xmp_data.title,
 		                                     exif_data.document_name);
diff --git a/src/tracker-extract/tracker-extract-pdf.c b/src/tracker-extract/tracker-extract-pdf.c
index eb89cd1..78593e0 100644
--- a/src/tracker-extract/tracker-extract-pdf.c
+++ b/src/tracker-extract/tracker-extract-pdf.c
@@ -238,7 +238,7 @@ extract_pdf (const gchar *uri,
 		}
 
 		if (xmp_data.Make || xmp_data.Model) {
-			gchar *final_camera = tracker_coalesce (2, xmp_data.Make, xmp_data.Model); 
+			gchar *final_camera = tracker_merge (" ", 2, xmp_data.Make, xmp_data.Model); 
 			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "camera", final_camera);
 			g_free (final_camera);
 		}
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 4243d70..dad0719 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -297,7 +297,7 @@ read_metadata (png_structp png_ptr, png_infop info_ptr, const gchar *uri, Tracke
 		}
 
 		if (xmp_data.Make || xmp_data.Model) {
-			gchar *final_camera = tracker_coalesce (2, xmp_data.Make, xmp_data.Model); 
+			gchar *final_camera = tracker_merge (" ", 2, xmp_data.Make, xmp_data.Model); 
 			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "camera", final_camera);
 			g_free (final_camera);
 		}
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index af0b195..6fd14fe 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -357,12 +357,26 @@ extract_tiff (const gchar *uri, TrackerSparqlBuilder *metadata)
 	TIFFClose (image);
 	g_free (filename);
 
-	merge_data.camera = tracker_coalesce (6, tiff_data.model,
-	                                      tiff_data.make,
-	                                      xmp_data.Model, 
-	                                      xmp_data.Make,
-	                                      exif_data.model,
-	                                      exif_data.make);
+	merge_data.camera = tracker_merge (" ", 2, tiff_data.make,
+	                                   tiff_data.model);
+
+	if (!merge_data.camera) {
+		merge_data.camera = tracker_merge (" ", 2, xmp_data.Make,
+		                                   xmp_data.Model);
+
+		if (!merge_data.camera) {
+			merge_data.camera = tracker_merge (" ", 2, exif_data.make,
+			                                   exif_data.model);
+		} else {
+			g_free (exif_data.model);
+			g_free (exif_data.make);
+		}
+	} else {
+		g_free (xmp_data.Model);
+		g_free (xmp_data.Make);
+		g_free (exif_data.model);
+		g_free (exif_data.make);
+	}
 
 	merge_data.title = tracker_coalesce (3, tiff_data.documentname,
 	                                     xmp_data.title,
diff --git a/src/tracker-extract/tracker-xmp.c b/src/tracker-extract/tracker-xmp.c
index 645345b..093ad37 100644
--- a/src/tracker-extract/tracker-xmp.c
+++ b/src/tracker-extract/tracker-xmp.c
@@ -596,7 +596,7 @@ tracker_apply_xmp (TrackerSparqlBuilder *metadata, const gchar *uri, TrackerXmpD
 	}
 
 	if (xmp_data->Make || xmp_data->Model) {
-		gchar *final_camera = tracker_coalesce (2, xmp_data->Make, xmp_data->Model); 
+		gchar *final_camera = tracker_merge (" ", 2, xmp_data->Make, xmp_data->Model); 
 		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "camera", final_camera);
 		g_free (final_camera);
 	}



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