[gnome-documents/wip/skydrive: 19/24] miner: guess the rdf:type from the filename extension



commit 4407ad2604c54892784fd7f495b52cee629672f9
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed May 30 23:01:33 2012 +0200

    miner: guess the rdf:type from the filename extension
    
    Fixes: https://bugzilla.gnome.org/666535

 src/lib/gd-utils.c       |   53 +++++++++++++++++++++++++++++++++++++++++++++-
 src/lib/gd-utils.h       |    2 +
 src/miner/gd-zpj-miner.c |    8 ++++--
 3 files changed, 59 insertions(+), 4 deletions(-)
---
diff --git a/src/lib/gd-utils.c b/src/lib/gd-utils.c
index fab24de..d770ef6 100644
--- a/src/lib/gd-utils.c
+++ b/src/lib/gd-utils.c
@@ -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
@@ -398,6 +398,57 @@ gd_filename_strip_extension (const char * filename_with_extension)
 }
 
 /**
+ * gd_filename_to_rdf_type:
+ * @filename_with_extension:
+ *
+ * Returns: (transfer none):
+ */
+const char *
+gd_filename_to_rdf_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, ".txt") == 0)
+    type = "nfo:HtmlDocument";
+
+  else if (g_strcmp0 (extension, ".doc") == 0
+      || g_strcmp0 (extension, ".docm") == 0
+      || g_strcmp0 (extension, ".docx") == 0
+      || g_strcmp0 (extension, ".dot") == 0
+      || g_strcmp0 (extension, ".dotx") == 0
+      || g_strcmp0 (extension, ".epub") == 0
+      || g_strcmp0 (extension, ".pdf") == 0)
+    type = "nfo:PaginatedTextDocument";
+
+  else if (g_strcmp0 (extension, ".pot") == 0
+           || g_strcmp0 (extension, ".potm") == 0
+           || g_strcmp0 (extension, ".potx") == 0
+           || g_strcmp0 (extension, ".pps") == 0
+           || g_strcmp0 (extension, ".ppsm") == 0
+           || g_strcmp0 (extension, ".ppsx") == 0
+           || g_strcmp0 (extension, ".ppt") == 0
+           || g_strcmp0 (extension, ".pptm") == 0
+           || g_strcmp0 (extension, ".pptx") == 0)
+    type = "nfo:Presentation";
+
+  else if (g_strcmp0 (extension, ".txt") == 0)
+    type = "nfo:PlainTextDocument";
+
+  else if (g_strcmp0 (extension, ".xls") == 0
+           || g_strcmp0 (extension, ".xlsb") == 0
+           || g_strcmp0 (extension, ".xlsm") == 0
+           || g_strcmp0 (extension, ".xlsx") == 0)
+    type = "nfo:Spreadsheet";
+
+  return type;
+}
+
+/**
  * gd_time_val_from_iso8601:
  * @string: (allow-none):
  * @timeval: (out):
diff --git a/src/lib/gd-utils.h b/src/lib/gd-utils.h
index 2adbb50..d44ac02 100644
--- a/src/lib/gd-utils.h
+++ b/src/lib/gd-utils.h
@@ -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_rdf_type (const gchar *filename_with_extension);
+
 gboolean gd_time_val_from_iso8601 (const gchar *string,
                                    GTimeVal *timeval);
 gchar *gd_iso8601_from_timestamp (gint64 timestamp);
diff --git a/src/miner/gd-zpj-miner.c b/src/miner/gd-zpj-miner.c
index 2d95502..0c6bea1 100644
--- a/src/miner/gd-zpj-miner.c
+++ b/src/miner/gd-zpj-miner.c
@@ -261,7 +261,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
   gchar *contact_resource;
   gchar *resource = NULL;
   gchar *date, *identifier;
-  const gchar *class = NULL, *id;
+  const gchar *class = NULL, *id, *name;
 
   id = zpj_skydrive_entry_get_id (entry);
 
@@ -272,8 +272,10 @@ account_miner_job_process_entry (AccountMinerJob *job,
   /* remove from the list of the previous resources */
   g_hash_table_remove (job->previous_resources, identifier);
 
+  name = zpj_skydrive_entry_get_name (entry);
+
   if (ZPJ_IS_SKYDRIVE_FILE (entry))
-    class = "nfo:Document";
+    class = gd_filename_to_rdf_type (name);
   else if (ZPJ_IS_SKYDRIVE_FOLDER (entry))
     class = "nfo:DataContainer";
 
@@ -331,7 +333,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
     (job->connection,
      job->cancellable, error,
      datasource_urn, resource,
-     "nfo:fileName", zpj_skydrive_entry_get_name (entry));
+     "nfo:fileName", name);
 
   if (*error != NULL)
     goto out;



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