No issues found
1 /*
2 * Copyright (C) 2012, Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include <glib.h>
21 #include <gmodule.h>
22
23 #include <libgxps/gxps.h>
24
25 #include <libtracker-extract/tracker-extract.h>
26
27 G_MODULE_EXPORT gboolean
28 tracker_extract_get_metadata (TrackerExtractInfo *info)
29 {
30 TrackerSparqlBuilder *metadata;
31 GXPSDocument *document;
32 GXPSFile *xps_file;
33 GFile *file;
34 gchar *filename;
35 GError *error = NULL;
36
37 metadata = tracker_extract_info_get_metadata_builder (info);
38 file = tracker_extract_info_get_file (info);
39 xps_file = gxps_file_new (file, &error);
40 filename = g_file_get_path (file);
41
42 if (error != NULL) {
43 g_warning ("Unable to open '%s': %s", filename, error->message);
44 g_error_free (error);
45 g_free (filename);
46 return FALSE;
47 }
48
49 document = gxps_file_get_document (xps_file, 0, &error);
50 g_object_unref (xps_file);
51
52 if (error != NULL) {
53 g_warning ("Unable to read '%s': %s", filename, error->message);
54 g_error_free (error);
55 g_free (filename);
56 return FALSE;
57 }
58
59 tracker_sparql_builder_predicate (metadata, "a");
60 tracker_sparql_builder_object (metadata, "nfo:PaginatedTextDocument");
61
62 tracker_sparql_builder_predicate (metadata, "nfo:pageCount");
63 tracker_sparql_builder_object_int64 (metadata, gxps_document_get_n_pages (document));
64
65 g_object_unref (document);
66 g_free (filename);
67
68 return TRUE;
69 }