[gnome-documents] Adapt to changes in nao:identifier syntax for Google items



commit 253380330031186b52aae34c28d0184187593e77
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Apr 21 17:10:17 2015 +0200

    Adapt to changes in nao:identifier syntax for Google items
    
    The new nao:identifier syntax is "google:drive:<GDataEntry:id>". We no
    longer make implicit assumptions about the value of GDataEntry:id.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=748253

 src/documents.js        |    7 +++++--
 src/lib/gd-pdf-loader.c |   37 ++++---------------------------------
 2 files changed, 9 insertions(+), 35 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index df36cbd..73bbee2 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -767,6 +767,8 @@ const LocalDocument = new Lang.Class({
     }
 });
 
+const GOOGLE_PREFIX = 'google:drive:';
+
 const GoogleDocument = new Lang.Class({
     Name: 'GoogleDocument',
     Extends: DocCommon,
@@ -786,10 +788,11 @@ const GoogleDocument = new Lang.Class({
 
         let authorizer = new GData.GoaAuthorizer({ goa_object: source.object });
         let service = new GData.DocumentsService({ authorizer: authorizer });
+        let gdata_id = this.identifier.substring(GOOGLE_PREFIX.length);
 
         service.query_single_entry_async
             (GData.DocumentsService.get_primary_authorization_domain(),
-             this.identifier, null,
+             gdata_id, null,
              GData.DocumentsText,
              cancellable, Lang.bind(this,
                  function(object, res) {
@@ -1152,7 +1155,7 @@ const DocumentManager = new Lang.Class({
 
     _identifierIsGoogle: function(identifier) {
         return (identifier &&
-                (identifier.indexOf('https://docs.google.com') != -1));
+                (identifier.indexOf(GOOGLE_PREFIX) != -1));
     },
 
     _identifierIsOwncloud: function(identifier) {
diff --git a/src/lib/gd-pdf-loader.c b/src/lib/gd-pdf-loader.c
index 1827259..21d0407 100644
--- a/src/lib/gd-pdf-loader.c
+++ b/src/lib/gd-pdf-loader.c
@@ -561,7 +561,7 @@ pdf_load_job_from_google_documents (PdfLoadJob *job)
   job->original_file_mtime = gdata_entry_get_updated (job->gdata_entry);
 
   tmp_name = g_strdup_printf ("gnome-documents-%u.pdf",
-                              g_str_hash (gdata_documents_entry_get_resource_id (GDATA_DOCUMENTS_ENTRY 
(job->gdata_entry))));
+                              g_str_hash (gdata_entry_get_id (job->gdata_entry)));
   tmp_path = g_build_filename (g_get_user_cache_dir (), "gnome-documents", NULL);
   job->pdf_path = pdf_path =
     g_build_filename (tmp_path, tmp_name, NULL);
@@ -961,44 +961,15 @@ query_info_ready_cb (GObject *obj,
   g_object_unref (info);
 }
 
-static gchar *
-resource_id_from_entry_id (const gchar *entry_id)
-{
-  const gchar *ptr;
-
-  ptr = g_strrstr (entry_id, "%3A");
-
-  if (ptr)
-    {
-      const gchar *p = ptr;
-
-      while (p >= entry_id)
-        {
-          if (*p == '/')
-            {
-              gchar *id;
-              gchar *type = g_strndup (p + 1, ptr - p - 1);
-
-              id = g_strdup_printf ("%s:%s", type, ptr + 3);
-              g_free (type);
-
-              return id;
-            }
-          p--;
-        }
-    }
-
-  return g_strdup (entry_id);
-}
-
 static void
 pdf_load_job_from_regular_file (PdfLoadJob *job)
 {
   GFile *file;
+  const gchar *gdata_prefix = "google:drive:";
   const gchar *zpj_prefix = "windows-live:skydrive:";
 
-  if (g_str_has_prefix (job->uri, "https://docs.google.com";)) {
-    job->resource_id = resource_id_from_entry_id (job->uri);
+  if (g_str_has_prefix (job->uri, gdata_prefix)) {
+    job->resource_id = g_strdup (job->uri + strlen (gdata_prefix));
     pdf_load_job_from_gdata_cache (job);
     return;
   }


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