[tracker] tracker-extract: add a simple extractor for XPS



commit dc5c1159baba867b3d630c9bc9329be87bf21ca9
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Oct 30 00:03:05 2012 -0400

    tracker-extract: add a simple extractor for XPS
    
    Fixes GB#687160

 configure.ac                              |   34 ++++++++++++++
 src/tracker-extract/10-xps.rule.in        |    4 ++
 src/tracker-extract/Makefile.am           |   19 ++++++++
 src/tracker-extract/tracker-extract-xps.c |   71 +++++++++++++++++++++++++++++
 4 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0a72ccc..3ab0183 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1853,6 +1853,39 @@ fi
 AM_CONDITIONAL(HAVE_POPPLER, test "x$have_poppler" = "xyes")
 
 ##################################################################
+# Check for tracker-extract: libgxps for XPS
+##################################################################
+
+AC_ARG_ENABLE(libgxps,
+              AS_HELP_STRING([--enable-libgxps],
+                             [enable extractor for PDF data [[default=auto]]]),,
+              [enable_libgxps=auto])
+
+if test "x$enable_libgxps" != "xno" ; then
+   PKG_CHECK_MODULES(LIBGXPS,
+                     [libgxps],
+                     [have_libgxps=yes],
+                     [have_libgxps=no])
+
+   AC_SUBST(LIBGXPS_CFLAGS)
+   AC_SUBST(LIBGXPS_LIBS)
+
+   if test "x$have_libgxps" = "xyes"; then
+      AC_DEFINE(HAVE_LIBGXPS, [], [Define if we have libgxps])
+   fi
+else
+   have_libgxps="no  (disabled)"
+fi
+
+if test "x$enable_libgxps" = "xyes"; then
+   if test "x$have_libgxps" != "xyes"; then
+      AC_MSG_ERROR([Couldn't find libgxps.])
+   fi
+fi
+
+AM_CONDITIONAL(HAVE_LIBGXPS, test "x$have_libgxps" = "xyes")
+
+##################################################################
 # Check for tracker-extract: libgsf
 ##################################################################
 
@@ -2425,6 +2458,7 @@ Metadata Extractors:
 	Support libstreamanalyzer:              $have_libstreamanalyzer
 	Support PNG:                            yes
 	Support PDF:                            $have_poppler
+	Support XPS:                            $have_libgxps
 	Support GIF:                            $have_libgif (xmp: $have_exempi)
 	Support JPEG:                           $have_libjpeg (xmp: $have_exempi, exif: $have_libexif, iptc: $have_libiptcdata)
 	Support TIFF:                           $have_libtiff (xmp: $have_exempi, exif: yes, iptc: $have_libiptcdata)
diff --git a/src/tracker-extract/10-xps.rule.in b/src/tracker-extract/10-xps.rule.in
new file mode 100644
index 0000000..0ab63c6
--- /dev/null
+++ b/src/tracker-extract/10-xps.rule.in
@@ -0,0 +1,4 @@
+[ExtractorRule]
+ModulePath= modulesdir@/libextract-xps.so
+MimeTypes=application/oxps;application/vnd.ms-xpsdocument;
+FallbackRdfType=nfo:Document
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index e8d5320..a3ccff9 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -35,6 +35,7 @@ rules_in_files = \
 	10-tiff.rule.in \
 	10-vorbis.rule.in \
 	10-xmp.rule.in \
+	10-xps.rule.in \
 	11-iso.rule.in \
 	11-msoffice-xml.rule.in \
 	15-gstreamer-guess.rule.in \
@@ -114,6 +115,11 @@ modules_LTLIBRARIES += \
 rules_DATA += 10-epub.rule 10-oasis.rule 10-msoffice.rule 11-msoffice-xml.rule
 endif
 
+if HAVE_LIBGXPS
+modules_LTLIBRARIES += libextract-xps.la
+rules_DATA += 10-xps.rule
+endif
+
 if HAVE_POPPLER
 modules_LTLIBRARIES += libextract-pdf.la
 rules_DATA += 10-pdf.rule
@@ -308,6 +314,19 @@ libextract_msoffice_xml_la_LIBADD = \
 	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_MODULES_LIBS)
 
+# XPS
+libextract_xps_la_SOURCES = tracker-extract-xps.c
+libextract_xps_la_CFLAGS = \
+	$(TRACKER_EXTRACT_MODULES_CFLAGS) \
+	$(LIBGXPS_CFLAGS)
+libextract_xps_la_LDFLAGS = $(module_flags)
+libextract_xps_la_LIBADD = \
+	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
+	$(top_builddir)/src/libtracker-common/libtracker-common.la \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_MODULES_LIBS) \
+	$(LIBGXPS_LIBS)
+
 # PDF
 libextract_pdf_la_SOURCES = tracker-extract-pdf.c
 libextract_pdf_la_CFLAGS = \
diff --git a/src/tracker-extract/tracker-extract-xps.c b/src/tracker-extract/tracker-extract-xps.c
new file mode 100644
index 0000000..537f768
--- /dev/null
+++ b/src/tracker-extract/tracker-extract-xps.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012, Red Hat, Inc.
+ *
+ * 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.
+ */
+
+#include <glib.h>
+#include <gmodule.h>
+
+#include <libgxps/gxps.h>
+
+#include <libtracker-extract/tracker-extract.h>
+
+G_MODULE_EXPORT gboolean
+tracker_extract_get_metadata (TrackerExtractInfo *info)
+{
+	TrackerSparqlBuilder *metadata;
+	GXPSDocument *document;
+	GXPSFile *xps_file;
+	GFile *file;
+	gchar *filename;
+	GError *error = NULL;
+
+	g_type_init ();
+
+	metadata = tracker_extract_info_get_metadata_builder (info);
+	file = tracker_extract_info_get_file (info);
+	xps_file = gxps_file_new (file, &error);
+	filename = g_file_get_path (file);
+
+	if (error != NULL) {
+		g_warning ("Unable to open '%s': %s", filename, error->message);
+		g_error_free (error);
+		g_free (filename);
+		return FALSE;
+	}
+
+	document = gxps_file_get_document (xps_file, 0, &error);
+	g_object_unref (xps_file);
+
+	if (error != NULL) {
+		g_warning ("Unable to read '%s': %s", filename, error->message);
+		g_error_free (error);
+		g_free (filename);
+		return FALSE;
+	}
+
+	tracker_sparql_builder_predicate (metadata, "a");
+	tracker_sparql_builder_object (metadata, "nfo:PaginatedTextDocument");
+
+	tracker_sparql_builder_predicate (metadata, "nfo:pageCount");
+	tracker_sparql_builder_object_int64 (metadata, gxps_document_get_n_pages (document));
+
+	g_object_unref (document);
+	g_free (filename);
+
+	return TRUE;
+}



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