[tracker/writeback: 5/5] Location writeback support for XMP formats



commit 4b7b5767fbe5784b4ead2516bc918d3a8ede7970
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Dec 21 13:35:23 2009 +0100

    Location writeback support for XMP formats

 data/ontologies/40-mlo.ontology               |    5 +
 src/libtracker-common/tracker-ontology.h      |    1 +
 src/tracker-extract/tracker-xmp.c             |    8 ++
 src/tracker-writeback/tracker-writeback-xmp.c |   99 +++++++++++++++++++++---
 4 files changed, 100 insertions(+), 13 deletions(-)
---
diff --git a/data/ontologies/40-mlo.ontology b/data/ontologies/40-mlo.ontology
index a124b7f..ed6cae2 100644
--- a/data/ontologies/40-mlo.ontology
+++ b/data/ontologies/40-mlo.ontology
@@ -95,6 +95,7 @@ mlo:routeDetails a rdf:Property ;
 
 # FIXME Domain rdfs:Resource?? to link files and not only content?
 mlo:location a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "Property linking something to a location" ;
     rdfs:comment "This can be subclassed to add semantics" ;
     rdfs:domain nie:InformationElement ;
@@ -102,21 +103,25 @@ mlo:location a rdf:Property ;
 
 # TODO: These are ad-hoc added by Philip to support writeback of locations
 mlo:city a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "City" ;
     rdfs:domain mlo:GeoPoint ;
     rdfs:range  xsd:string .
 
 mlo:country a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "Country" ;
     rdfs:domain mlo:GeoPoint ;
     rdfs:range  xsd:string .
 
 mlo:state a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "State" ;
     rdfs:domain mlo:GeoPoint ;
     rdfs:range  xsd:string .
 
 mlo:address a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "Address" ;
     rdfs:domain mlo:GeoPoint ;
     rdfs:range  xsd:string .
diff --git a/src/libtracker-common/tracker-ontology.h b/src/libtracker-common/tracker-ontology.h
index 537a5e2..ca8cc38 100644
--- a/src/libtracker-common/tracker-ontology.h
+++ b/src/libtracker-common/tracker-ontology.h
@@ -52,6 +52,7 @@ G_BEGIN_DECLS
 
 /* Temporary */
 #define TRACKER_NMM_PREFIX      "http://www.tracker-project.org/temp/nmm#";
+#define TRACKER_MLO_PREFIX      "http://www.tracker-project.org/temp/mlo#";
 
 #define TRACKER_DATASOURCE_URN_PREFIX	  \
 	"urn:nepomuk:datasource:"
diff --git a/src/tracker-extract/tracker-xmp.c b/src/tracker-extract/tracker-xmp.c
index d5d9474..278fe03 100644
--- a/src/tracker-extract/tracker-xmp.c
+++ b/src/tracker-extract/tracker-xmp.c
@@ -373,6 +373,11 @@ tracker_xmp_iter_simple (const gchar          *uri,
 			data->license = g_strdup (value);
 		}
 	} else
+
+	/* TODO: A lot of these location fields are pretty vague and ambigious.
+	 * We should go through them one by one and ensure that all of them are
+	 * used sanely */
+
 	/* Photoshop */
 	if (g_ascii_strcasecmp (schema,  NS_PHOTOSHOP) == 0) {
 		if (data->City && g_ascii_strcasecmp (name, "City") == 0) {
@@ -398,6 +403,9 @@ tracker_xmp_iter_simple (const gchar          *uri,
 		} else 
 		if (!data->Country && g_ascii_strcasecmp (name, "PrimaryLocationName") == 0) {
 			data->Country = g_strdup (value);
+		} else
+		if (!data->State && g_ascii_strcasecmp (name, "State") == 0) {
+			data->State = g_strdup (value);
 		} else 
 		if (!data->State && g_ascii_strcasecmp (name, "Province") == 0) {
 			data->State = g_strdup (value);
diff --git a/src/tracker-writeback/tracker-writeback-xmp.c b/src/tracker-writeback/tracker-writeback-xmp.c
index b396ded..300d2e5 100644
--- a/src/tracker-writeback/tracker-writeback-xmp.c
+++ b/src/tracker-writeback/tracker-writeback-xmp.c
@@ -31,6 +31,7 @@
 #include <gio/gio.h>
 
 #include <libtracker-common/tracker-ontology.h>
+#include <libtracker-common/tracker-utils.h>
 
 #include "tracker-writeback-file.h"
 
@@ -367,23 +368,95 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
 			g_free (work_on);
 		}
 
-		/*
-		  if (g_strcmp0 (row[1], PHOTO_HAS "contact") == 0) {
-		  Face recognition on the photos
+		if (g_strcmp0 (row[1], TRACKER_MLO_PREFIX "location") == 0 || 
+		    g_strcmp0 (row[1], TRACKER_MLO_PREFIX "city") == 0     ||
+		    g_strcmp0 (row[1], TRACKER_MLO_PREFIX "country") == 0  ||
+		    g_strcmp0 (row[1], TRACKER_MLO_PREFIX "state") == 0    ||
+		    g_strcmp0 (row[1], TRACKER_MLO_PREFIX "address") == 0) 
+		{
+			GPtrArray *array;
+			GError *error = NULL;
+			gchar *query;
+
+			query = g_strdup_printf ("SELECT ?city ?state ?address ?country "
+			                         "WHERE { <%s> mlo:location ?location . "
+			                                 "OPTIONAL { ?location mlo:address ?address } . "
+			                                 "OPTIONAL { ?location mlo:city ?city } . "
+			                                 "OPTIONAL { ?location mlo:country ?country } . "
+			                                 "OPTIONAL { ?location mlo:state ?state} "
+			                         "}", row[0]);
+
+			array = tracker_resources_sparql_query (client, query, &error);
+
+			g_free (query);
+
+			if (!error) {
+				if (array && array->len > 0) {
+					GStrv qrow;
+
+					qrow = g_ptr_array_index (array, 0);
+
+					/* TODO: A lot of these location fields are pretty vague and ambigious.
+					 * We should go through them one by one and ensure that all of them are
+					 * used sanely */
+
+					if (!tracker_is_empty_string (qrow[0])) {
+						xmp_delete_property (xmp, NS_IPTC4XMP, "City");
+						xmp_set_property (xmp, NS_IPTC4XMP, "City", qrow[0], 0);
+						xmp_delete_property (xmp, NS_PHOTOSHOP, "City");
+						xmp_set_property (xmp, NS_PHOTOSHOP, "City", qrow[0], 0);
+					}
+					g_free (qrow[0]);
+
+					if (!tracker_is_empty_string (qrow[1])) {
+						xmp_delete_property (xmp, NS_IPTC4XMP, "State");
+						xmp_set_property (xmp, NS_IPTC4XMP, "State", qrow[1], 0);
+						xmp_delete_property (xmp, NS_IPTC4XMP, "Province");
+						xmp_set_property (xmp, NS_IPTC4XMP, "Province", qrow[1], 0);
+						xmp_delete_property (xmp, NS_PHOTOSHOP, "State");
+						xmp_set_property (xmp, NS_PHOTOSHOP, "State", qrow[1], 0);
+					}
+					g_free (qrow[1]);
+
+					if (!tracker_is_empty_string (qrow[2])) {
+						xmp_delete_property (xmp, NS_IPTC4XMP, "SubLocation");
+						xmp_set_property (xmp, NS_IPTC4XMP, "SubLocation", qrow[2], 0);
+						xmp_delete_property (xmp, NS_PHOTOSHOP, "Location");
+						xmp_set_property (xmp, NS_PHOTOSHOP, "Location", qrow[2], 0);
+					}
+					g_free (qrow[2]);
+
+					if (!tracker_is_empty_string (qrow[3])) {
+						xmp_delete_property (xmp, NS_PHOTOSHOP, "Country");
+						xmp_set_property (xmp, NS_PHOTOSHOP, "Country", qrow[3], 0);
+						xmp_delete_property (xmp, NS_IPTC4XMP, "Country");
+						xmp_set_property (xmp, NS_IPTC4XMP, "Country", qrow[3], 0);
+						xmp_delete_property (xmp, NS_IPTC4XMP, "PrimaryLocationName");
+						xmp_set_property (xmp, NS_IPTC4XMP, "PrimaryLocationName", qrow[3], 0);
+					}
+					g_free (qrow[3]);
+
+				}
+
+				if (array) {
+					g_ptr_array_free (array, TRUE);
+				}
+
+			} else {
+				g_clear_error (&error);
+			}
+	
+	
+		}
+
+		/* TODO: When a photo contains a known face
+		 * 
+		 * if (g_strcmp0 (row[1], PHOTO_HAS "contact") == 0) {
 		  xmp_delete_property (xmp, FACE, "contact");
 		  Fetch full name of the contact?
 		  xmp_set_array_item (xmp, FACE, "contact", 1, fetched, 0);
 		  }
-
-		  if (g_strcmp0 (row[1], LOCATION_PREFIX "country") == 0) {
-		  xmp_delete_property (xmp, NS_PHOTOSHOP, "Country");
-		  xmp_set_array_item (xmp, NS_PHOTOSHOP, "Country", 1, row[2], 0);
-		  }
-
-		  if (g_strcmp0 (row[1], LOCATION_PREFIX "city") == 0) {
-		  xmp_delete_property (xmp, NS_PHOTOSHOP, "City");
-		  xmp_set_array_item (xmp, NS_PHOTOSHOP, "City", 1, row[2], 0);
-		  } */
+		*/
 
 	}
 



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