[tracker] tracker-extract: Cleaned up IPTC code/API



commit 7f0a63e9106cad8b29d41c396383a786bd05b2ee
Author: Martyn Russell <martyn lanedo com>
Date:   Mon Jan 18 11:12:10 2010 +0000

    tracker-extract: Cleaned up IPTC code/API
    
    We are going to be exposing this API soon.

 src/tracker-extract/tracker-extract-jpeg.c |   12 +-
 src/tracker-extract/tracker-extract-tiff.c |   17 ++-
 src/tracker-extract/tracker-iptc.c         |  210 ++++++++++++++--------------
 src/tracker-extract/tracker-iptc.h         |   38 ++++--
 4 files changed, 147 insertions(+), 130 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index b88458a..f03095b 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -216,7 +216,7 @@ extract_jpeg (const gchar          *uri,
 			gsize len;
 #ifdef HAVE_LIBIPTCDATA
 			gsize offset;
-			gsize sublen;
+			guint sublen;
 #endif /* HAVE_LIBIPTCDATA */
 
 			switch (marker->marker) {
@@ -256,7 +256,7 @@ extract_jpeg (const gchar          *uri,
 				if (strncmp (PS3_NAMESPACE, str, PS3_NAMESPACE_LENGTH) == 0) {
 					offset = iptc_jpeg_ps3_find_iptc (str, len, &sublen);
 					if (offset > 0) {
-						tracker_read_iptc (str + offset,
+						tracker_iptc_read (str + offset,
 						                   sublen,
 						                   uri,
 						                   &id);
@@ -315,7 +315,7 @@ extract_jpeg (const gchar          *uri,
 		md.city = tracker_coalesce (2, id.city, xd.City);
 		md.state = tracker_coalesce (2, id.state, xd.State);
 		md.address = tracker_coalesce (2, id.sublocation, xd.Address);
-		md.country  = tracker_coalesce (2, id.countryname, xd.Country);
+		md.country  = tracker_coalesce (2, id.country_name, xd.Country);
 
 		md.creator =  tracker_coalesce (3, id.byline, xd.creator, id.credit);
 		md.comment = tracker_coalesce (2, comment, ed.user_comment);
@@ -340,15 +340,15 @@ extract_jpeg (const gchar          *uri,
 			g_free (id.contact);
 		}
 
-		if (id.bylinetitle) {
+		if (id.byline_title) {
 			tracker_sparql_builder_predicate (metadata, "nco:hasAffiliation");
 			tracker_sparql_builder_object_blank_open (metadata);
 			tracker_sparql_builder_predicate (metadata, "a");
 			tracker_sparql_builder_object (metadata, "nco:Affiliation");
 			tracker_sparql_builder_predicate (metadata, "nco:title");
-			tracker_sparql_builder_object_unvalidated (metadata, id.bylinetitle);
+			tracker_sparql_builder_object_unvalidated (metadata, id.byline_title);
 			tracker_sparql_builder_object_blank_close (metadata);
-			g_free (id.bylinetitle);
+			g_free (id.byline_title);
 		}
 
 		if (xd.keywords) {
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index 99bc8dc..7f58523 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -304,10 +304,11 @@ extract_tiff (const gchar *uri, TrackerSparqlBuilder *metadata)
 #ifdef HAVE_LIBIPTCDATA
 	if (TIFFGetField (image, TIFFTAG_RICHTIFFIPTC, &iptcSize, &iptcOffset)) {
 		if (TIFFIsByteSwapped(image) != 0)
-			TIFFSwabArrayOfLong((uint32 *) iptcOffset,(unsigned long) iptcSize);
-		tracker_read_iptc (iptcOffset,
-		                   4*iptcSize,
-		                   uri, &iptc_data);
+			TIFFSwabArrayOfLong((uint32 *) iptcOffset, (unsigned long) iptcSize);
+		tracker_iptc_read (iptcOffset,
+		                   4 * iptcSize,
+		                   uri, 
+		                   &iptc_data);
 	}
 #endif /* HAVE_LIBIPTCDATA */
 
@@ -441,7 +442,7 @@ extract_tiff (const gchar *uri, TrackerSparqlBuilder *metadata)
 	merge_data.city = tracker_coalesce (2, iptc_data.city, xmp_data.City);
 	merge_data.state = tracker_coalesce (2, iptc_data.state, xmp_data.State);
 	merge_data.address = tracker_coalesce (2, iptc_data.sublocation, xmp_data.Address);
-	merge_data.country  = tracker_coalesce (2, iptc_data.countryname, xmp_data.Country);
+	merge_data.country  = tracker_coalesce (2, iptc_data.country_name, xmp_data.Country);
 
 	merge_data.creator =  tracker_coalesce (3, iptc_data.byline,
 	                                        xmp_data.creator,
@@ -496,15 +497,15 @@ extract_tiff (const gchar *uri, TrackerSparqlBuilder *metadata)
 		g_free (iptc_data.contact);
 	}
 
-	if (iptc_data.bylinetitle) {
+	if (iptc_data.byline_title) {
 		tracker_sparql_builder_predicate (metadata, "nco:hasAffiliation");
 		tracker_sparql_builder_object_blank_open (metadata);
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "nco:Affiliation");
 		tracker_sparql_builder_predicate (metadata, "nco:title");
-		tracker_sparql_builder_object_unvalidated (metadata, iptc_data.bylinetitle);
+		tracker_sparql_builder_object_unvalidated (metadata, iptc_data.byline_title);
 		tracker_sparql_builder_object_blank_close (metadata);
-		g_free (iptc_data.bylinetitle);
+		g_free (iptc_data.byline_title);
 	}
 
 	if (xmp_data.publisher) {
diff --git a/src/tracker-extract/tracker-iptc.c b/src/tracker-extract/tracker-iptc.c
index 774cff4..b32043e 100644
--- a/src/tracker-extract/tracker-iptc.c
+++ b/src/tracker-extract/tracker-iptc.c
@@ -1,4 +1,4 @@
-/* Tracker Iptc - Iptc helper functions
+/*
  * Copyright (C) 2009, Nokia
  *
  * This program is free software; you can redistribute it and/or
@@ -19,14 +19,15 @@
 
 #include "config.h"
 
-#include "tracker-iptc.h"
-#include "tracker-main.h"
+#include <string.h>
 
 #include <glib.h>
-#include <string.h>
 
 #include <libtracker-common/tracker-type-utils.h>
 
+#include "tracker-iptc.h"
+#include "tracker-main.h"
+
 #ifdef HAVE_LIBIPTCDATA
 
 #include <libiptcdata/iptc-data.h>
@@ -44,117 +45,118 @@ fix_iptc_orientation (const gchar *orientation)
 	return "nfo:orientation-top"; /* We take this as default */
 }
 
-
 static void
-foreach_dataset (IptcDataSet *dataset, void *user_data)
+foreach_dataset (IptcDataSet *dataset, 
+                 void        *user_data)
 {
 	TrackerIptcData *data = user_data;
 	gchar mbuffer[1024];
 
 	switch (dataset->tag) {
-			case IPTC_TAG_KEYWORDS:
-			if (!data->keywords) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->keywords = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_DATE_CREATED:
-			if (!data->date_created) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				/* From: ex; date "2007:04:15 15:35:58"
-				 * To : ex. "2007-04-15T17:35:58+0200 where +0200 is localtime */
-				data->date_created = tracker_date_format_to_iso8601 (mbuffer, IPTC_DATE_FORMAT);
-			}
-			break;
-
-			case IPTC_TAG_BYLINE:
-			if (!data->byline) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->byline = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_CREDIT:
-			if (!data->credit) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->credit = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_COPYRIGHT_NOTICE:
-			if (!data->copyright_notice) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->copyright_notice = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_IMAGE_ORIENTATION:
-			if (!data->image_orientation) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->image_orientation = g_strdup (fix_iptc_orientation (mbuffer));
-			}
-			break;
-
-			case IPTC_TAG_BYLINE_TITLE:
-			if (!data->bylinetitle) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->bylinetitle = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_CITY:
-			if (!data->city) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->city = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_STATE:
-			if (!data->state) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->state = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_SUBLOCATION:
-			if (!data->sublocation) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->sublocation = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_COUNTRY_NAME:
-			if (!data->countryname) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->countryname = g_strdup (mbuffer);
-			}
-			break;
-
-			case IPTC_TAG_CONTACT:
-			if (!data->contact) {
-				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-				data->contact = g_strdup (mbuffer);
-			}
-			break;
-
-			default:
-			break;
+	case IPTC_TAG_KEYWORDS:
+		if (!data->keywords) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->keywords = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_DATE_CREATED:
+		if (!data->date_created) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			/* From: ex; date "2007:04:15 15:35:58"
+			 * To : ex. "2007-04-15T17:35:58+0200 where +0200 is localtime */
+			data->date_created = tracker_date_format_to_iso8601 (mbuffer, IPTC_DATE_FORMAT);
+		}
+		break;
+
+	case IPTC_TAG_BYLINE:
+		if (!data->byline) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->byline = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_CREDIT:
+		if (!data->credit) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->credit = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_COPYRIGHT_NOTICE:
+		if (!data->copyright_notice) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->copyright_notice = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_IMAGE_ORIENTATION:
+		if (!data->image_orientation) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->image_orientation = g_strdup (fix_iptc_orientation (mbuffer));
+		}
+		break;
+
+	case IPTC_TAG_BYLINE_TITLE:
+		if (!data->byline_title) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->byline_title = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_CITY:
+		if (!data->city) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->city = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_STATE:
+		if (!data->state) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->state = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_SUBLOCATION:
+		if (!data->sublocation) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->sublocation = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_COUNTRY_NAME:
+		if (!data->country_name) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->country_name = g_strdup (mbuffer);
+		}
+		break;
+
+	case IPTC_TAG_CONTACT:
+		if (!data->contact) {
+			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+			data->contact = g_strdup (mbuffer);
+		}
+		break;
+
+	default:
+		break;
 	}
 }
 
+#endif /* HAVE_LIBIPTCDATA */
 
-#endif
-
-
-void
-tracker_read_iptc (const unsigned char *buffer,
+gboolean
+tracker_iptc_read (const unsigned char *buffer,
                    size_t               len,
                    const gchar         *uri,
                    TrackerIptcData     *data)
 {
+	g_return_val_if_fail (buffer != NULL, FALSE);
+	g_return_val_if_fail (uri != NULL, FALSE);
+
 #ifdef HAVE_LIBIPTCDATA
-	IptcData *iptc = NULL;
+	IptcData *iptc;
 
 	/* FIXME According to valgrind this is leaking (together with the unref).
 	 * Problem in libiptc (I replaced this with the _free equivalent) */
@@ -162,16 +164,16 @@ tracker_read_iptc (const unsigned char *buffer,
 	iptc = iptc_data_new ();
 
 	if (!iptc)
-		return;
+		return FALSE;
 
 	if (iptc_data_load (iptc, buffer, len) < 0) {
 		iptc_data_free (iptc);
-		return;
+		return FALSE;
 	}
 
 	iptc_data_foreach_dataset (iptc, foreach_dataset, data);
-
 	iptc_data_free (iptc);
+#endif /* HAVE_LIBIPTCDATA */
 
-#endif
+	return TRUE;
 }
diff --git a/src/tracker-extract/tracker-iptc.h b/src/tracker-extract/tracker-iptc.h
index 416b0bd..de97d82 100644
--- a/src/tracker-extract/tracker-iptc.h
+++ b/src/tracker-extract/tracker-iptc.h
@@ -1,5 +1,5 @@
-/* Tracker IPTC - Iptc helper functions
- * Copyright (C) 2008, Nokia
+/*
+ * Copyright (C) 2009, Nokia
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
@@ -19,21 +19,35 @@
  * Author: Philip Van Hoof <philip codeminded be>
  */
 
-#ifndef _TRACKER_IPTC_H_
-#define _TRACKER_IPTC_H_
+#ifndef __TRACKER_EXTRACT_IPTC_H__
+#define __TRACKER_EXTRACT_IPTC_H__
 
 #include <glib.h>
 
+/* IPTC Information Interchange Model */
+
+G_BEGIN_DECLS
+
 typedef struct {
-	gchar *keywords, *date_created, *byline, *credit, *copyright_notice,
-		*image_orientation, *bylinetitle, *city, *state, *sublocation,
-		*countryname, *contact;
+	gchar *keywords;
+	gchar *date_created;
+	gchar *byline;
+	gchar *credit;
+	gchar *copyright_notice;
+	gchar *image_orientation;
+	gchar *byline_title;
+	gchar *city;
+	gchar *state;
+	gchar *sublocation;
+	gchar *country_name;
+	gchar *contact;
 } TrackerIptcData;
 
+gboolean tracker_iptc_read (const unsigned char *buffer,
+                            size_t               len,
+                            const gchar         *uri,
+                            TrackerIptcData     *data);
 
-void tracker_read_iptc (const unsigned char *buffer,
-                        size_t               len,
-                        const gchar         *uri,
-                        TrackerIptcData     *data);
+G_END_DECLS
 
-#endif
+#endif /* __TRACKER_EXTRACT_IPTC_H__ */



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