[gnome-documents/wip/skydrive: 21/28] miner: guess the nie:mimeType from the filename extension



commit 678ce6fd82eb7764fc645abfb89adb070a9a8214
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed May 30 23:18:40 2012 +0200

    miner: guess the nie:mimeType from the filename extension
    
    Currently this is needed to differentiate PDFs from other kinds of
    nfo:PaginatedTextDocuments.
    
    Fixes: https://bugzilla.gnome.org/666535

 src/lib/gd-utils.c       |   22 ++++++++++++++++++++++
 src/lib/gd-utils.h       |    4 +++-
 src/miner/gd-zpj-miner.c |   15 ++++++++++++++-
 3 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/src/lib/gd-utils.c b/src/lib/gd-utils.c
index d770ef6..b6f15cf 100644
--- a/src/lib/gd-utils.c
+++ b/src/lib/gd-utils.c
@@ -398,6 +398,28 @@ gd_filename_strip_extension (const char * filename_with_extension)
 }
 
 /**
+ * gd_filename_to_mime_type:
+ * @filename_with_extension:
+ *
+ * Returns: (transfer none):
+ */
+const char *
+gd_filename_to_mime_type (const gchar *filename_with_extension)
+{
+  const gchar *extension;
+  const gchar *type = NULL;
+
+  g_return_val_if_fail (filename_with_extension != NULL, NULL);
+
+  extension = gd_filename_get_extension_offset (filename_with_extension);
+
+  if (g_strcmp0 (extension, ".pdf") == 0)
+    type = "application/pdf";
+
+  return type;
+}
+
+/**
  * gd_filename_to_rdf_type:
  * @filename_with_extension:
  *
diff --git a/src/lib/gd-utils.h b/src/lib/gd-utils.h
index d44ac02..6812c6c 100644
--- a/src/lib/gd-utils.h
+++ b/src/lib/gd-utils.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright (c) 2011, 2012 Red Hat, Inc.
  *
  * Gnome Documents is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by the
@@ -64,6 +64,8 @@ GdkPixbuf *gd_embed_image_in_frame (GdkPixbuf *source_image,
 
 char *gd_filename_strip_extension (const char * filename_with_extension);
 
+const char *gd_filename_to_mime_type (const gchar *filename_with_extension);
+
 const char *gd_filename_to_rdf_type (const gchar *filename_with_extension);
 
 gboolean gd_time_val_from_iso8601 (const gchar *string,
diff --git a/src/miner/gd-zpj-miner.c b/src/miner/gd-zpj-miner.c
index 0c6bea1..c5104ba 100644
--- a/src/miner/gd-zpj-miner.c
+++ b/src/miner/gd-zpj-miner.c
@@ -296,7 +296,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
   if (ZPJ_IS_SKYDRIVE_FILE (entry))
     {
       gchar *parent_resource_urn, *parent_identifier;
-      const gchar *parent_id;
+      const gchar *parent_id, *mime;
 
       parent_id = zpj_skydrive_entry_get_parent_id (entry);
       parent_identifier = g_strconcat ("gd:collection:windows-live:skydrive:", parent_id, NULL);
@@ -318,6 +318,19 @@ account_miner_job_process_entry (AccountMinerJob *job,
 
       if (*error != NULL)
         goto out;
+
+      mime = gd_filename_to_mime_type (name);
+      if (mime != NULL)
+        {
+          gd_miner_tracker_sparql_connection_insert_or_replace_triple
+            (job->connection,
+             job->cancellable, error,
+             datasource_urn, resource,
+             "nie:mimeType", mime);
+
+          if (*error != NULL)
+            goto out;
+        }
     }
 
   gd_miner_tracker_sparql_connection_insert_or_replace_triple



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