[tracker/wip/sam/resource: 22/27] libtracker-extract: Add XMP code using TRackerResource



commit 05977b2e6a7674f9a91ada4184bda50a55e1e61d
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Apr 18 14:16:24 2016 +0100

    libtracker-extract: Add XMP code using TRackerResource

 src/libtracker-extract/tracker-xmp.c |  360 ++++++++++++++++++++++++++++++++++
 src/libtracker-extract/tracker-xmp.h |   25 ++-
 2 files changed, 376 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-xmp.c b/src/libtracker-extract/tracker-xmp.c
index dda8368..f915270 100644
--- a/src/libtracker-extract/tracker-xmp.c
+++ b/src/libtracker-extract/tracker-xmp.c
@@ -886,6 +886,7 @@ fix_region_type (const gchar *region_type)
  * otherwise %FALSE is returned.
  *
  * Since: 0.8
+ * Deprecated: 1.10: Use TrackerResource instead
  **/
 gboolean
 tracker_xmp_apply (TrackerSparqlBuilder *preupdate,
@@ -1245,6 +1246,7 @@ tracker_xmp_apply (TrackerSparqlBuilder *preupdate,
  * successfully, otherwise %FALSE is returned.
  *
  * Since: 0.12
+ * Deprecated: 1.10: Use TrackerResource instead
  **/
 gboolean
 tracker_xmp_apply_regions (TrackerSparqlBuilder *preupdate,
@@ -1332,3 +1334,361 @@ tracker_xmp_apply_regions (TrackerSparqlBuilder *preupdate,
 
         return TRUE;
 }
+
+/**
+ * tracker_xmp_apply_to_resource:
+ * @resource: the #TrackerResource to apply XMP data to.
+ * @data: the data to push into @resource.
+ *
+ * This function applies all data in @data to @resource.
+ *
+ * This function also calls tracker_xmp_apply_regions_to_resource(), so there
+ * is no need to call both functions.
+ *
+ * Returns: %TRUE if the @data was applied to @resource successfully,
+ * otherwise %FALSE is returned.
+ *
+ * Since: 1.10
+ **/
+gboolean
+tracker_xmp_apply_to_resource (TrackerResource *resource,
+                               TrackerXmpData  *data)
+{
+       GPtrArray *keywords;
+       guint i;
+
+       g_return_val_if_fail (TRACKER_IS_RESOURCE (resource), FALSE);
+       g_return_val_if_fail (data != NULL, FALSE);
+
+       keywords = g_ptr_array_new ();
+
+       if (data->keywords) {
+               tracker_keywords_parse (keywords, data->keywords);
+       }
+
+       if (data->subject) {
+               tracker_keywords_parse (keywords, data->subject);
+       }
+
+       if (data->pdf_keywords) {
+               tracker_keywords_parse (keywords, data->pdf_keywords);
+       }
+
+       for (i = 0; i < keywords->len; i++) {
+               TrackerResource *label;
+               gchar *p;
+
+               p = g_ptr_array_index (keywords, i);
+
+               /* ensure tag with specified label exists */
+               label = tracker_resource_new (NULL);
+               tracker_resource_set_ensure_unique (label, TRUE);
+               tracker_resource_set_uri (label, "rdf:type", "nao:Tag");
+               tracker_resource_set_string (label, "nao:prefLabel", p);
+
+               /* associate file with tag */
+               tracker_resource_set_relation (resource, "nao:hasTag", label);
+
+               g_free (p);
+               g_object_unref (label);
+       }
+       g_ptr_array_free (keywords, TRUE);
+
+       if (data->publisher) {
+               TrackerResource *publisher;
+
+               publisher = tracker_resource_new (NULL);
+               tracker_resource_set_uri (publisher, "rdf:type", "nco:Contact");
+               tracker_resource_set_string (publisher, "nco:fullname", data->publisher);
+
+               tracker_resource_set_relation (resource, "nco:publisher", publisher);
+               g_object_unref (publisher);
+       }
+
+       if (data->type) {
+               tracker_resource_set_string (resource, "dc:type", data->type);
+       }
+
+       if (data->format) {
+               tracker_resource_set_string (resource, "dc:format", data->format);
+       }
+
+       if (data->identifier) {
+               tracker_resource_set_string (resource, "dc:identifier", data->identifier);
+       }
+
+       if (data->source) {
+               tracker_resource_set_string (resource, "dc:source", data->source);
+       }
+
+       if (data->language) {
+               tracker_resource_set_string (resource, "dc:language", data->language);
+       }
+
+       if (data->relation) {
+               tracker_resource_set_string (resource, "dc:relation", data->relation);
+       }
+
+       if (data->coverage) {
+               tracker_resource_set_string (resource, "dc:coverage", data->coverage);
+       }
+
+       if (data->license) {
+               tracker_resource_set_string (resource, "dc:license", data->license);
+       }
+
+       if (data->make || data->model) {
+               TrackerResource *equipment;
+               gchar *equip_uri;
+
+               equip_uri = tracker_sparql_escape_uri_printf ("urn:equipment:%s:%s:",
+                                                             data->make ? data->make : "",
+                                                             data->model ? data->model : "");
+
+               equipment = tracker_resource_new (equip_uri);
+               tracker_resource_set_uri (equipment, "rdf:type", "nfo:Equipment");
+
+               if (data->make) {
+                       tracker_resource_set_string (equipment, "nfo:manufacturer", data->make);
+               }
+               if (data->model) {
+                       tracker_resource_set_string (equipment, "nfo:model", data->model);
+               }
+
+               tracker_resource_set_relation (resource, "nfo:equipment", equipment);
+               g_free (equip_uri);
+               g_object_unref (equipment);
+       }
+
+       if (data->title || data->title2 || data->pdf_title) {
+               const gchar *final_title = tracker_coalesce_strip (3, data->title,
+                                                                  data->title2,
+                                                                  data->pdf_title);
+
+               tracker_resource_set_string (resource, "nie:title", final_title);
+       }
+
+       if (data->orientation) {
+               tracker_resource_set_string (resource, "nfo:orientation", data->orientation);
+       }
+
+       if (data->rights || data->copyright) {
+               const gchar *final_rights = tracker_coalesce_strip (2, data->copyright, data->rights);
+
+               tracker_resource_set_string (resource, "nie:copyright", final_rights);
+       }
+
+       if (data->white_balance) {
+               tracker_resource_set_string (resource, "nmm:whiteBalance", data->white_balance);
+       }
+
+       if (data->fnumber) {
+               tracker_resource_set_string (resource, "nmm:fnumber", data->fnumber);
+       }
+
+       if (data->flash) {
+               tracker_resource_set_string (resource, "nmm:flash", data->flash);
+       }
+
+       if (data->focal_length) {
+               tracker_resource_set_string (resource, "nmm:focalLength", data->focal_length);
+       }
+
+       if (data->artist || data->contributor) {
+               TrackerResource *contributor;
+               const gchar *final_artist = tracker_coalesce_strip (2, data->artist, data->contributor);
+
+               contributor = tracker_resource_new (NULL);
+               tracker_resource_set_uri (contributor, "rdf:type", "nco:Contact");
+               tracker_resource_set_string (contributor, "nco:fullname", final_artist);
+
+               tracker_resource_set_relation (resource, "nco:contributor", contributor);
+
+               g_object_unref (contributor);
+       }
+
+       if (data->exposure_time) {
+               tracker_resource_set_string (resource, "nmm:exposureTime", data->exposure_time);
+       }
+
+       if (data->iso_speed_ratings) {
+               tracker_resource_set_string (resource, "nmm:isoSpeed", data->iso_speed_ratings);
+       }
+
+       if (data->date || data->time_original) {
+               const gchar *final_date = tracker_coalesce_strip (2, data->date,
+                                                                 data->time_original);
+
+               tracker_resource_set_string (resource, "nie:contentCreated", final_date);
+       }
+
+       if (data->description) {
+               tracker_resource_set_string (resource, "nie:description", data->description);
+       }
+
+       if (data->metering_mode) {
+               tracker_resource_set_string (resource, "nmm:meteringMode", data->metering_mode);
+       }
+
+       if (data->creator) {
+               TrackerResource *creator;
+
+               creator = tracker_resource_new (NULL);
+               tracker_resource_set_uri (creator, "rdf:type", "nco:Contact");
+               tracker_resource_set_string (creator, "nco:fullname", data->creator);
+
+               tracker_resource_set_relation (resource, "nco:creator", creator);
+
+               g_object_unref (creator);
+       }
+
+       if (data->address || data->state || data->country || data->city ||
+           data->gps_altitude || data->gps_latitude || data->gps_longitude) {
+               TrackerResource *geopoint;
+
+               geopoint = tracker_resource_new (NULL);
+               tracker_resource_set_uri (geopoint, "rdf:type", "slo:GeoLocation");
+
+               if (data->address || data->state || data->country || data->city) {
+                       TrackerResource *address;
+                       gchar *addruri;
+
+                       addruri = tracker_sparql_get_uuid_urn ();
+                       address = tracker_resource_new (addruri);
+
+                       tracker_resource_set_string (address, "rdf:type", "nco:PostalAddress");
+
+                       g_free (addruri);
+
+                       if (data->address) {
+                               tracker_resource_set_string (address, "nco:streetAddress", data->address);
+                       }
+
+                       if (data->state) {
+                               tracker_resource_set_string (address, "nco:region", data->state);
+                       }
+
+                       if (data->city) {
+                               tracker_resource_set_string (address, "nco:locality", data->city);
+                       }
+
+                       if (data->country) {
+                               tracker_resource_set_string (address, "nco:country", data->country);
+                       }
+
+                       tracker_resource_set_relation (geopoint, "slo:postalAddress", address);
+                       g_object_unref (address);
+               }
+
+               /* FIXME We are not handling the altitude ref here */
+
+               if (data->gps_altitude) {
+                       tracker_resource_set_string (geopoint, "slo:altitude", data->gps_altitude);
+               }
+
+               if (data->gps_latitude) {
+                       tracker_resource_set_string (geopoint, "slo:latitude", data->gps_latitude);
+               }
+
+               if (data->gps_longitude) {
+                       tracker_resource_set_string (geopoint, "slo:longitude", data->gps_longitude);
+               }
+
+               tracker_resource_set_relation (resource, "slo:location", geopoint);
+               g_object_unref (geopoint);
+       }
+
+       if (data->gps_direction) {
+               tracker_resource_set_string (resource, "nfo:heading", data->gps_direction);
+       }
+
+       if (data->regions) {
+               tracker_xmp_apply_regions_to_resource (resource, data);
+       }
+
+       return TRUE;
+}
+
+/**
+ * tracker_xmp_apply_regions_to_resource:
+ * @resource: the #TrackerResource object to apply XMP data to.
+ * @data: the data to push into @resource
+ *
+ * This function applies all regional @data to @resource. Regional data exists
+ * for image formats like JPEG, PNG, etc. where parts of the image refer to
+ * areas of interest. This can be people's faces, places to focus, barcodes,
+ * etc. The regional data describes the title, height, width, X, Y and can
+ * occur multiple times in a given file.
+ *
+ * This data usually is standardized between image formats and that's
+ * what makes this function different to tracker_xmp_apply_to_resource() which
+ * is useful for XMP files only.
+ *
+ * Returns: %TRUE if the @data was applied to @resource successfully, otherwise
+ * %FALSE is returned.
+ *
+ * Since: 1.10
+ **/
+gboolean
+tracker_xmp_apply_regions_to_resource (TrackerResource *resource,
+                                       TrackerXmpData  *data)
+{
+       GSList *iter;
+
+       g_return_val_if_fail (TRACKER_IS_RESOURCE (resource), FALSE);
+       g_return_val_if_fail (data != NULL, FALSE);
+
+       if (!data->regions) {
+               return TRUE;
+       }
+
+       for (iter = data->regions; iter != NULL; iter = iter->next) {
+               TrackerResource *region_resource;
+               TrackerXmpRegion *region;
+               gchar *uuid;
+
+               region = (TrackerXmpRegion *) iter->data;
+               uuid = tracker_sparql_get_uuid_urn ();
+
+               region_resource = tracker_resource_new (uuid);
+               tracker_resource_set_uri (region_resource, "rdf:type", "nfo:RegionOfInterest");
+
+               g_free (uuid);
+
+               if (region->title) {
+                       tracker_resource_set_string (region_resource, "nie:title", region->title);
+               }
+
+               if (region->description) {
+                       tracker_resource_set_string (region_resource, "nie:description", region->description);
+               }
+
+               if (region->type) {
+                       tracker_resource_set_string (region_resource, "nfo:regionOfInterestType", 
fix_region_type (region->type));
+               }
+
+               if (region->x) {
+                       tracker_resource_set_string (region_resource, "nfo:regionOfInterestX", region->x);
+               }
+
+               if (region->y) {
+                       tracker_resource_set_string (region_resource, "nfo:regionOfInterestY", region->y);
+               }
+
+               if (region->width) {
+                       tracker_resource_set_string (region_resource, "nfo:regionOfInterestWidth", 
region->width);
+               }
+
+               if (region->height) {
+                       tracker_resource_set_string (region_resource, "nfo:regionOfInterestHeight", 
region->height);
+               }
+
+               if (region->link_uri && region->link_class) {
+                       tracker_resource_set_string (region_resource, "nfo:roiRefersTo", region->link_uri);
+               }
+
+               tracker_resource_add_relation (resource, "nfo:hasRegionOfInterest", region_resource);
+       }
+
+       return TRUE;
+}
diff --git a/src/libtracker-extract/tracker-xmp.h b/src/libtracker-extract/tracker-xmp.h
index ce8a2d4..5061900 100644
--- a/src/libtracker-extract/tracker-xmp.h
+++ b/src/libtracker-extract/tracker-xmp.h
@@ -171,23 +171,30 @@ TrackerXmpData *tracker_xmp_new           (const gchar          *buffer,
                                            gsize                 len,
                                            const gchar          *uri);
 void            tracker_xmp_free          (TrackerXmpData       *data);
+
+gboolean        tracker_xmp_apply_to_resource         (TrackerResource *resource,
+                                                       TrackerXmpData  *data);
+gboolean        tracker_xmp_apply_regions_to_resource (TrackerResource *resource,
+                                                       TrackerXmpData  *data);
+
+#ifndef TRACKER_DISABLE_DEPRECATED
+
+gboolean         tracker_xmp_read  (const gchar          *buffer,
+                                    size_t                len,
+                                    const gchar          *uri,
+                                    TrackerXmpData       *data) G_GNUC_DEPRECATED;
+
 gboolean        tracker_xmp_apply         (TrackerSparqlBuilder *preupdate,
                                            TrackerSparqlBuilder *metadata,
                                            const gchar          *graph,
                                            GString              *where,
                                            const gchar          *uri,
-                                           TrackerXmpData       *data);
+                                           TrackerXmpData       *data) G_GNUC_DEPRECATED;
+;
 gboolean        tracker_xmp_apply_regions (TrackerSparqlBuilder *preupdate,
                                            TrackerSparqlBuilder *metadata,
                                            const gchar          *graph,
-                                           TrackerXmpData       *data);
-
-#ifndef TRACKER_DISABLE_DEPRECATED
-
-gboolean         tracker_xmp_read  (const gchar          *buffer,
-                                    size_t                len,
-                                    const gchar          *uri,
-                                    TrackerXmpData       *data) G_GNUC_DEPRECATED;
+                                           TrackerXmpData       *data) G_GNUC_DEPRECATED;
 #endif /* TRACKER_DISABLE_DEPRECATED */
 
 G_END_DECLS


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