[tracker/writeback: 3/7] Added a few fields to the XMP writeback support



commit 946f3f4ce324aff66a5189d26db17b8213305a5a
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Dec 15 15:00:39 2009 +0100

    Added a few fields to the XMP writeback support
    
    Added some more fields to the XMP writeback module

 data/ontologies/30-nie.ontology               |    3 +-
 data/ontologies/32-nco.ontology               |    3 +-
 data/ontologies/38-nmm.ontology               |   24 ++-
 src/tracker-writeback/Makefile.am             |   12 +-
 src/tracker-writeback/tracker-writeback-xmp.c |  200 +++++++++++++++++++------
 tests/tracker-writeback/01-writeback.py       |  104 +++++++++++++
 6 files changed, 287 insertions(+), 59 deletions(-)
---
diff --git a/data/ontologies/30-nie.ontology b/data/ontologies/30-nie.ontology
index 5571fec..d6e0e61 100644
--- a/data/ontologies/30-nie.ontology
+++ b/data/ontologies/30-nie.ontology
@@ -137,7 +137,8 @@ nie:copyright a rdf:Property ;
 	rdfs:subPropertyOf dc:rights , nie:legal ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nie:InformationElement ;
-	rdfs:range xsd:string .
+	rdfs:range xsd:string ;
+	tracker:writeback true .
 
 nie:comment a rdf:Property ;
 	nrl:maxCardinality 1 ;
diff --git a/data/ontologies/32-nco.ontology b/data/ontologies/32-nco.ontology
index f79d2e0..1f622bb 100644
--- a/data/ontologies/32-nco.ontology
+++ b/data/ontologies/32-nco.ontology
@@ -208,7 +208,8 @@ nco:contributor a rdf:Property ;
 	rdfs:comment "An entity responsible for making contributions to the content of the InformationElement." ;
 	rdfs:subPropertyOf dc:contributor ;
 	rdfs:domain nie:InformationElement ;
-	rdfs:range nco:Contact .
+	rdfs:range nco:Contact ;
+	tracker:writeback true .
 
 nco:creator a rdf:Property ;
 	rdfs:label "creator" ;
diff --git a/data/ontologies/38-nmm.ontology b/data/ontologies/38-nmm.ontology
index c38fdcb..cf42877 100644
--- a/data/ontologies/38-nmm.ontology
+++ b/data/ontologies/38-nmm.ontology
@@ -323,14 +323,16 @@ nmm:camera a rdf:Property ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nmm:Photo ;
 	rdfs:range xsd:string ;
-	tracker:weight 3 .
+	tracker:weight 3 ;
+	tracker:writeback true .
 
 nmm:exposureTime a rdf:Property ;
 	rdfs:label "Exposure time" ;
 	rdfs:comment "Exposure time of the photo" ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nmm:Photo ;
-	rdfs:range xsd:double .
+	rdfs:range xsd:double ;
+	tracker:writeback true .
 
 nmm:Flash a rdfs:Class ;
 	rdfs:label "Flash values" ;
@@ -344,28 +346,32 @@ nmm:flash a rdf:Property ;
 	rdfs:comment "Specifies whether flash was used" ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nmm:Photo ;
-	rdfs:range nmm:Flash .
+	rdfs:range nmm:Flash ;
+	tracker:writeback true .
 
 nmm:fnumber a rdf:Property ;
 	rdfs:label "F number" ;
 	rdfs:comment "The diameter of the entrance pupil in terms of the focal length of the lens" ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nmm:Photo ;
-	rdfs:range xsd:double .
+	rdfs:range xsd:double ;
+	tracker:writeback true .
 
 nmm:focalLength a rdf:Property ;
 	rdfs:label "Focal length" ;
 	rdfs:comment "A measure of how strongly the lens converges light" ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nmm:Photo ;
-	rdfs:range xsd:double .
+	rdfs:range xsd:double ;
+	tracker:writeback true .
 
 nmm:isoSpeed a rdf:Property ;
 	rdfs:label "ISO speed" ;
 	rdfs:comment "Measure of a photographic film's sensitivity to light as ISO value" ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nmm:Photo ;
-	rdfs:range xsd:double .
+	rdfs:range xsd:double ;
+	tracker:writeback true .
 
 nmm:MeteringMode a rdfs:Class ;
 	rdfs:label "Metering mode values" ;
@@ -383,7 +389,8 @@ nmm:meteringMode a rdf:Property ;
 	rdfs:comment "Metering mode refers to the way in which a camera determines the exposure." ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nmm:Photo ;
-	rdfs:range nmm:MeteringMode .
+	rdfs:range nmm:MeteringMode ;
+	tracker:writeback true .
 
 nmm:WhiteBalance a rdfs:Class ;
 	rdfs:label "White balance" ;
@@ -395,7 +402,8 @@ nmm:white-balance-manual a nmm:WhiteBalance .
 nmm:whiteBalance a rdf:Property ;
 	nrl:maxCardinality 1 ;
 	rdfs:domain nmm:Photo ;
-	rdfs:range nmm:WhiteBalance .
+	rdfs:range nmm:WhiteBalance ;
+	tracker:writeback true .
 
 nmm:isCropped a rdf:Property ;
 	nrl:maxCardinality 1 ;
diff --git a/src/tracker-writeback/Makefile.am b/src/tracker-writeback/Makefile.am
index 4655653..ea895d3 100644
--- a/src/tracker-writeback/Makefile.am
+++ b/src/tracker-writeback/Makefile.am
@@ -39,12 +39,12 @@ libwriteback_xmp_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS) $(EXEMPI_LIBS)
 endif
 
 # Playlists
-if HAVE_TOTEM_PL_PARSER
-modules_LTLIBRARIES += libwriteback-playlist.la
-libwriteback_playlist_la_SOURCES = tracker-writeback-playlist.c
-libwriteback_playlist_la_LDFLAGS = $(module_flags)
-libwriteback_playlist_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS) $(TOTEM_PL_PARSER_LIBS)
-endif
+#if HAVE_TOTEM_PL_PARSER
+#modules_LTLIBRARIES += libwriteback-playlist.la
+#libwriteback_playlist_la_SOURCES = tracker-writeback-playlist.c
+#libwriteback_playlist_la_LDFLAGS = $(module_flags)
+#libwriteback_playlist_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS) $(TOTEM_PL_PARSER_LIBS)
+#endif
 
 #
 # Binaries
diff --git a/src/tracker-writeback/tracker-writeback-xmp.c b/src/tracker-writeback/tracker-writeback-xmp.c
index 8135bb9..fd92ca0 100644
--- a/src/tracker-writeback/tracker-writeback-xmp.c
+++ b/src/tracker-writeback/tracker-writeback-xmp.c
@@ -185,11 +185,56 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
 			}
 		}
 
+		if (g_strcmp0 (row[1], TRACKER_NCO_PREFIX "contributor") == 0) {
+			GPtrArray *name_array;
+			GError *error = NULL;
+			gchar *query;
+
+			query = g_strdup_printf ("SELECT ?fullname { "
+			                         "  <%s> nco:fullname ?fullname "
+			                         "}", row[2]);
+
+			name_array = tracker_resources_sparql_query (client, query, &error);
+
+			g_free (query);
+
+			if (!error) {
+				if (name_array && name_array->len > 0) {
+					GStrv name_row;
+
+					name_row = g_ptr_array_index (name_array, 0);
+
+					if (name_row[0]) {
+						xmp_delete_property (xmp, NS_DC, "contributor");
+						xmp_set_property (xmp, NS_DC, "contributor", name_row[0], 0);
+					}
+				}
+
+				if (name_array) {
+					g_ptr_array_foreach (name_array, (GFunc) g_strfreev, NULL);
+					g_ptr_array_free (name_array, TRUE);
+				}
+
+			} else {
+				g_clear_error (&error);
+			}
+		}
+
 		if (g_strcmp0 (row[1], TRACKER_NIE_PREFIX "description") == 0) {
 			xmp_delete_property (xmp, NS_DC, "description");
 			xmp_set_property (xmp, NS_DC, "description", row[2], 0);
 		}
 
+		if (g_strcmp0 (row[1], TRACKER_NIE_PREFIX "copyright") == 0) {
+			xmp_delete_property (xmp, NS_EXIF, "Copyright");
+			xmp_set_property (xmp, NS_EXIF, "Copyright", row[2], 0);
+		}
+
+		if (g_strcmp0 (row[1], TRACKER_NIE_PREFIX "comment") == 0) {
+			xmp_delete_property (xmp, NS_EXIF, "UserComment");
+			xmp_set_property (xmp, NS_EXIF, "UserComment", row[2], 0);
+		}
+
 		if (g_strcmp0 (row[1], TRACKER_NIE_PREFIX "keyword") == 0) {
 			if (!keywords) {
 				keywords = g_string_new (row[2]);
@@ -204,55 +249,124 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
 		}
 
 		if (g_strcmp0 (row[1], TRACKER_NFO_PREFIX "orientation") == 0) {
-			guint i;
-
-			static const gchar *ostr[8] = {
-				/* 0 */ TRACKER_NFO_PREFIX "orientation-top",
-				/* 1 */ TRACKER_NFO_PREFIX "orientation-top-mirror",
-				/* 2 */ TRACKER_NFO_PREFIX "orientation-bottom",
-				/* 3 */ TRACKER_NFO_PREFIX "orientation-bottom-mirror",
-				/* 4 */ TRACKER_NFO_PREFIX "orientation-left-mirror",
-				/* 5 */ TRACKER_NFO_PREFIX "orientation-right",
-				/* 6 */ TRACKER_NFO_PREFIX "orientation-right-mirror",
-				/* 7 */ TRACKER_NFO_PREFIX "orientation-left"
-			};
 
 			xmp_delete_property (xmp, NS_EXIF, "Orientation");
 
-			for (i=0; i < 8; i++) {
-				if (g_strcmp0 (row[2], ostr[i]) == 0) {
-					switch (i) {
-					case 0:
-						xmp_set_property (xmp, NS_EXIF, "Orientation", "top - left", 0);
-						break;
-					case 1:
-						xmp_set_property (xmp, NS_EXIF, "Orientation", "top - right", 0);
-						break;
-					case 2:
-						xmp_set_property (xmp, NS_EXIF, "Orientation", "bottom - right", 0);
-						break;
-					case 3:
-						xmp_set_property (xmp, NS_EXIF, "Orientation", "bottom - left", 0);
-						break;
-					case 4:
-						xmp_set_property (xmp, NS_EXIF, "Orientation", "left - top", 0);
-						break;
-					case 5:
-						xmp_set_property (xmp, NS_EXIF, "Orientation", "right - top", 0);
-						break;
-					case 6:
-						xmp_set_property (xmp, NS_EXIF, "Orientation", "right - bottom", 0);
-						break;
-					case 7:
-						xmp_set_property (xmp, NS_EXIF, "Orientation", "left - bottom", 0);
-						break;
-					default:
-						break;
-					}
-				}
+			if        (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "orientation-top") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "Orientation", "top - left", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "orientation-top-mirror") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "Orientation", "top - right", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "orientation-bottom") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "Orientation", "bottom - right", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "orientation-bottom-mirror") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "Orientation", "bottom - left", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "orientation-left-mirror") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "Orientation", "left - top", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "orientation-right") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "Orientation", "right - top", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "orientation-right-mirror") == 0) {
+					xmp_set_property (xmp, NS_EXIF, "Orientation", "right - bottom", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "orientation-left") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "Orientation", "left - bottom", 0);
+			}
+		}
+
+		if (g_strcmp0 (row[1], TRACKER_NMM_PREFIX "meteringMode") == 0) {
+
+			xmp_delete_property (xmp, NS_EXIF, "MeteringMode");
+
+			/* 0 = Unknown
+			   1 = Average
+			   2 = CenterWeightedAverage
+			   3 = Spot
+			   4 = MultiSpot
+			   5 = Pattern
+			   6 = Partial
+			   255 = other  */
+
+			if        (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "meteringMode-center-weighted-average") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "MeteringMode", "center", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "meteringMode-average") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "MeteringMode", "average", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "meteringMode-spot") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "MeteringMode", "spot", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "meteringMode-multispot") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "MeteringMode", "multispot", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "meteringMode-pattern") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "MeteringMode", "pattern", 0);
+			} else if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "meteringMode-partial") == 0) {
+				xmp_set_property (xmp, NS_EXIF, "MeteringMode", "partial", 0);
+			} else {
+				xmp_set_property (xmp, NS_EXIF, "MeteringMode", "other", 0);
+			}
+		}
+
+		if (g_strcmp0 (row[1], TRACKER_NMM_PREFIX "whiteBalance") == 0) {
+
+			xmp_delete_property (xmp, NS_EXIF, "WhiteBalance");
+
+			if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "whiteBalance-auto") == 0) {
+				/* 0 = Auto white balance
+				 * 1 = Manual white balance */
+				xmp_set_property (xmp, NS_EXIF, "WhiteBalance", "auto", 0);
+			} else {
+				xmp_set_property (xmp, NS_EXIF, "MeteringMode", "manual", 0);
+			}
+		}
+
+		if (g_strcmp0 (row[1], TRACKER_NMM_PREFIX "flash") == 0) {
+
+			xmp_delete_property (xmp, NS_EXIF, "Flash");
+
+			if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "flash-on") == 0) {
+				/* 0 = Flash did not fire
+				   1 = Flash fired */
+				xmp_set_property (xmp, NS_EXIF, "Flash", "on", 0);
+			} else {
+				xmp_set_property (xmp, NS_EXIF, "Flash", "off", 0);
 			}
 		}
 
+		if (g_strcmp0 (row[1], TRACKER_NMM_PREFIX "focalLength") == 0) {
+			xmp_delete_property (xmp, NS_EXIF, "FocalLength");
+			xmp_set_property (xmp, NS_EXIF, "FocalLength", row[2], 0);
+		}
+
+		if (g_strcmp0 (row[1], TRACKER_NMM_PREFIX "exposureTime") == 0) {
+			xmp_delete_property (xmp, NS_EXIF, "ExposureTime");
+			xmp_set_property (xmp, NS_EXIF, "ExposureTime", row[2], 0);
+		}
+
+		if (g_strcmp0 (row[1], TRACKER_NMM_PREFIX "isoSpeed") == 0) {
+			xmp_delete_property (xmp, NS_EXIF, "ISOSpeedRatings");
+			xmp_set_property (xmp, NS_EXIF, "ISOSpeedRatings", row[2], 0);
+		}
+
+		if (g_strcmp0 (row[1], TRACKER_NMM_PREFIX "fnumber") == 0) {
+			xmp_delete_property (xmp, NS_EXIF, "FNumber");
+			xmp_set_property (xmp, NS_EXIF, "FNumber", row[2], 0);
+		}
+
+		if (g_strcmp0 (row[1], TRACKER_NMM_PREFIX "camera") == 0) {
+			gchar *work_on = g_strdup (row[2]);
+			gchar *ptr = strchr (work_on, ' ');
+
+			if (ptr) {
+
+				*ptr = '\0';
+				ptr++;
+
+				xmp_delete_property (xmp, NS_EXIF, "Make");
+				xmp_set_property (xmp, NS_EXIF, "Make", work_on, 0);
+				xmp_delete_property (xmp, NS_EXIF, "Model");
+				xmp_set_property (xmp, NS_EXIF, "Model", ptr, 0);
+			} else {
+				xmp_delete_property (xmp, NS_EXIF, "Model");
+				xmp_set_property (xmp, NS_EXIF, "Model", work_on, 0);
+			}
+
+			g_free (work_on);
+		}
 
 		/*
 		  if (g_strcmp0 (row[1], PHOTO_HAS "contact") == 0) {
diff --git a/tests/tracker-writeback/01-writeback.py b/tests/tracker-writeback/01-writeback.py
new file mode 100755
index 0000000..aa23596
--- /dev/null
+++ b/tests/tracker-writeback/01-writeback.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python2.5
+
+# Copyright (C) 2008, Nokia (urho konttori nokia com)
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA  02110-1301, USA.
+#
+
+
+import dbus
+import unittest
+import random
+import os
+import shutil
+import re
+import time
+import commands
+
+TRACKER = 'org.freedesktop.Tracker1'
+TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
+RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
+
+class TestInsertion (unittest.TestCase):
+
+    def setUp (self):
+        bus = dbus.SessionBus ()
+        tracker = bus.get_object (TRACKER, TRACKER_OBJ)
+        self.resources = dbus.Interface (tracker,
+                                         dbus_interface=RESOURCES_IFACE);
+
+    def test_simple_insertion (self):
+	try:        
+	        os.mkdir (os.getcwd() + "/tmp")
+	except:
+		print ""
+
+        shutil.copy2 (os.getcwd() + "/data/test01.jpg",
+                      os.getcwd() + "/tmp/test01.jpg")
+
+        uri = "file://" + os.getcwd() + "/tmp/test01.jpg"
+        
+        insert = """INSERT { <%s> a nfo:Image, nmm:Photo, nfo:FileDataObject;
+                      nie:isStoredAs <%s> ;
+                      nie:url '%s' ;
+                      nie:title 'test_title_1' ;
+                      nco:creator [ a nco:Contact ;
+                                    nco:fullname 'test_fullname_1' ] ;
+                      nie:description 'test_description_1' ;
+                      nie:keyword 'test_keyword_1' ;
+                      nie:keyword 'test_keyword_2' ;
+                      nie:keyword 'test_keyword_3' ;
+                      nie:contentCreated '2001-10-26T21:32:52' ;
+                      nfo:orientation nfo:orientation-top-mirror ;
+                      nmm:meteringMode nmm:meteringMode-average ;
+                      nmm:whiteBalance nmm:whiteBalance-auto ;
+                      nmm:flash nmm:flash-on ;
+                      nmm:focalLength '1' ;
+                      nmm:exposureTime '1' ;
+                      nmm:isoSpeed '1' ;
+                      nmm:fnumber '1' ;
+                      nmm:camera 'Some Test Model' ;
+                      nco:contributor [ a nco:Contact ;
+                                        nco:fullname 'test_fullname_2' ] ;
+                      nie:copyright 'test_copyright_1'
+               }""" % (uri, uri, uri)
+
+
+        self.resources.SparqlUpdate (insert)
+
+	time.sleep (3)
+
+	ret = os.system ("exiftool " + os.getcwd() + "/tmp/test01.jpg | grep test_title_1")
+        self.assertEqual (ret, 0)
+
+	ret = os.system ("exiftool " + os.getcwd() + "/tmp/test01.jpg | grep test_fullname_1")
+        self.assertEqual (ret, 0)
+
+	ret = os.system ("exiftool " + os.getcwd() + "/tmp/test01.jpg | grep test_description_1")
+        self.assertEqual (ret, 0)
+
+	ret = os.system ("exiftool " + os.getcwd() + "/tmp/test01.jpg | grep test_keyword_1")
+        self.assertEqual (ret, 0)
+
+	ret = os.system ("exiftool " + os.getcwd() + "/tmp/test01.jpg | grep test_keyword_2")
+        self.assertEqual (ret, 0)
+
+	ret = os.system ("exiftool " + os.getcwd() + "/tmp/test01.jpg | grep test_keyword_3")
+        self.assertEqual (ret, 0)
+
+
+if __name__ == '__main__':
+    unittest.main()



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