[tracker] tracker-extract: Sort parts before extracting .pptx files content
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-extract: Sort parts before extracting .pptx files content
- Date: Wed, 27 Apr 2011 14:31:55 +0000 (UTC)
commit 1c28c12cbf4771dba51ae5a087da9b11e6380531
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Apr 27 16:03:07 2011 +0200
tracker-extract: Sort parts before extracting .pptx files content
Fixes GB#632876, Reported by Aleksander Morgado.
src/tracker-extract/tracker-extract-msoffice-xml.c | 75 +++++++++++++++-----
1 files changed, 58 insertions(+), 17 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-msoffice-xml.c b/src/tracker-extract/tracker-extract-msoffice-xml.c
index 5c2ef81..f43bfca 100644
--- a/src/tracker-extract/tracker-extract-msoffice-xml.c
+++ b/src/tracker-extract/tracker-extract-msoffice-xml.c
@@ -89,7 +89,7 @@ typedef struct {
gboolean style_element_present;
gboolean preserve_attribute_present;
GTimer *timer;
- gboolean limit_reached;
+ GList *parts;
} MsOfficeXMLParserInfo;
static void msoffice_xml_content_parse_start (GMarkupParseContext *context,
@@ -587,6 +587,23 @@ xml_read (MsOfficeXMLParserInfo *parser_info,
return TRUE;
}
+static gint
+compare_slide_name (gconstpointer a,
+ gconstpointer b)
+{
+ gchar *col_a, *col_b;
+ gint result;
+
+ col_a = g_utf8_collate_key_for_filename (a, -1);
+ col_b = g_utf8_collate_key_for_filename (b, -1);
+ result = strcmp (col_a, col_b);
+
+ g_free (col_a);
+ g_free (col_b);
+
+ return result;
+}
+
static void
msoffice_xml_content_types_parse_start (GMarkupParseContext *context,
const gchar *element_name,
@@ -644,21 +661,11 @@ msoffice_xml_content_types_parse_start (GMarkupParseContext *context,
(info->file_type == FILE_TYPE_XLSX &&
(g_ascii_strcasecmp (content_type, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml") == 0 ||
g_ascii_strcasecmp (content_type, "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml") == 0))) {
- /* If reached max bytes to extract, don't event start parsing the file... just return */
- if (info->bytes_pending == 0) {
- if (!info->limit_reached) {
- g_debug ("Skipping '%s' as already reached max bytes to extract",
- part_name + 1);
- info->limit_reached = TRUE;
- }
- } else if (g_timer_elapsed (info->timer, NULL) > 5) {
- if (!info->limit_reached) {
- g_debug ("Skipping '%s' as already reached max time to extract",
- part_name + 1);
- info->limit_reached = TRUE;
- }
+ if (info->file_type == FILE_TYPE_PPTX) {
+ info->parts = g_list_insert_sorted (info->parts, g_strdup (part_name + 1),
+ compare_slide_name);
} else {
- xml_read (info, part_name + 1, MS_OFFICE_XML_TAG_DOCUMENT_TEXT_DATA);
+ info->parts = g_list_append (info->parts, g_strdup (part_name + 1));
}
}
}
@@ -717,6 +724,34 @@ msoffice_xml_get_file_type (const gchar *uri)
return file_type;
}
+static void
+extract_content (MsOfficeXMLParserInfo *info)
+{
+ GList *parts;
+
+ if (!info->parts) {
+ return;
+ }
+
+ for (parts = info->parts; parts; parts = parts->next) {
+ const gchar *part_name;
+
+ part_name = parts->data;
+ /* If reached max bytes to extract, don't event start parsing the file... just return */
+ if (info->bytes_pending == 0) {
+ g_debug ("Skipping '%s' as already reached max bytes to extract",
+ part_name);
+ break;
+ } else if (g_timer_elapsed (info->timer, NULL) > 5) {
+ g_debug ("Skipping '%s' as already reached max time to extract",
+ part_name);
+ break;
+ } else {
+ xml_read (info, part_name, MS_OFFICE_XML_TAG_DOCUMENT_TEXT_DATA);
+ }
+ }
+}
+
G_MODULE_EXPORT gboolean
tracker_extract_get_metadata (const gchar *uri,
const gchar *mimetype,
@@ -724,7 +759,7 @@ tracker_extract_get_metadata (const gchar *uri,
TrackerSparqlBuilder *metadata,
GString *where)
{
- MsOfficeXMLParserInfo info;
+ MsOfficeXMLParserInfo info = { 0 };
MsOfficeXMLFileType file_type;
TrackerConfig *config;
GMarkupParseContext *context = NULL;
@@ -763,7 +798,6 @@ tracker_extract_get_metadata (const gchar *uri,
&info,
NULL);
- info.limit_reached = FALSE;
info.timer = g_timer_new ();
/* Load the internal XML file from the Zip archive, and parse it
* using the given context */
@@ -777,6 +811,8 @@ tracker_extract_get_metadata (const gchar *uri,
g_error_free (error);
}
+ extract_content (&info);
+
/* If we got any content, add it */
if (info.content) {
gchar *content;
@@ -791,6 +827,11 @@ tracker_extract_get_metadata (const gchar *uri,
}
}
+ if (info.parts) {
+ g_list_foreach (info.parts, (GFunc) g_free, NULL);
+ g_list_free (info.parts);
+ }
+
g_timer_destroy (info.timer);
g_markup_parse_context_free (context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]