[gvfs/wip/rishi/goa: 4/6] Use shortcuts instead of Link-type desktop files for native Drive files



commit 3521e0e76d91195fe2967d36173922f323fbc157
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Aug 20 10:02:04 2015 +0200

    Use shortcuts instead of Link-type desktop files for native Drive files

 daemon/gvfsbackendgoogle.c |   76 ++++++++++----------------------------------
 1 files changed, 17 insertions(+), 59 deletions(-)
---
diff --git a/daemon/gvfsbackendgoogle.c b/daemon/gvfsbackendgoogle.c
index d724107..5fd0ea5 100644
--- a/daemon/gvfsbackendgoogle.c
+++ b/daemon/gvfsbackendgoogle.c
@@ -367,7 +367,6 @@ build_file_info (GVfsBackendGoogle      *self,
   GFileType file_type;
   GList *authors;
   GMountSpec *spec;
-  gboolean content_type_override = FALSE;
   gboolean is_folder;
   gboolean is_root;
   const gchar *etag;
@@ -431,19 +430,21 @@ build_file_info (GVfsBackendGoogle      *self,
   if (content_type != NULL)
     {
       GIcon *icon;
-      const gchar *virtual_content_type = content_type;
 
-      /* We want native Drive content to open in the browser. We
-       * accomplish this by creating fake Link-type desktop files.
-       */
-      if (g_str_has_prefix (content_type, CONTENT_TYPE_PREFIX_GOOGLE))
+      /* We want native Drive content to open in the browser. */
+      if (!is_symlink && g_str_has_prefix (content_type, CONTENT_TYPE_PREFIX_GOOGLE))
         {
-          content_type_override = TRUE;
-          virtual_content_type = "application/x-desktop";
+          GDataLink *alternate;
+          const gchar *uri;
+
+          file_type = G_FILE_TYPE_SHORTCUT;
+          alternate = gdata_entry_look_up_link (entry, GDATA_LINK_ALTERNATE);
+          uri = gdata_link_get_uri (alternate);
+          g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, uri);
         }
 
-      g_file_info_set_content_type (info, virtual_content_type);
-      g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, 
virtual_content_type);
+      g_file_info_set_content_type (info, content_type);
+      g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, content_type);
 
       icon = g_content_type_get_icon (content_type);
       g_file_info_set_icon (info, icon);
@@ -478,10 +479,7 @@ build_file_info (GVfsBackendGoogle      *self,
   g_file_info_set_display_name (info, title);
   g_file_info_set_edit_name (info, title);
 
-  if (content_type_override)
-    copy_name = g_strconcat (title, ".desktop", NULL);
-  else
-    copy_name = g_strdup (title);
+  copy_name = g_strdup (title);
 
   /* Sanitize copy-name by replacing slashes with dashes. This is
    * what nautilus does (for desktop files).
@@ -1594,13 +1592,14 @@ g_vfs_backend_google_open_for_read (GVfsBackend        *_self,
 {
   GVfsBackendGoogle *self = G_VFS_BACKEND_GOOGLE (_self);
   GCancellable *cancellable = G_VFS_JOB (job)->cancellable;
+  GDataAuthorizationDomain *auth_domain;
   GDataEntry *entry;
   GInputStream *stream;
   GError *error;
   gboolean is_folder;
   gboolean is_root;
   gboolean is_volatile;
-  gchar *content_type = NULL;
+  const gchar *uri;
   gchar *id = NULL;
   gchar *unescaped_filename = NULL;
 
@@ -1659,49 +1658,9 @@ g_vfs_backend_google_open_for_read (GVfsBackend        *_self,
       goto out;
     }
 
-  content_type = get_content_type_from_entry (entry);
-  if (content_type == NULL)
-    {
-      g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED, _("Unknown content type"));
-      goto out;
-    }
-
-  /* We want native Drive content to open in the browser. We
-   * accomplish this by creating fake Link-type desktop files.
-   */
-  if (g_str_has_prefix (content_type, CONTENT_TYPE_PREFIX_GOOGLE))
-    {
-      GDataLink *alternate;
-      GKeyFile *file;
-      const gchar *title;
-      const gchar *uri;
-      gchar *data;
-      gsize length;
-
-      file = g_key_file_new ();
-
-      title = gdata_entry_get_title (entry);
-      g_key_file_set_string (file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, title);
-      g_key_file_set_string (file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, "Link");
-
-      alternate = gdata_entry_look_up_link (entry, GDATA_LINK_ALTERNATE);
-      uri = gdata_link_get_uri (alternate);
-      g_key_file_set_string (file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, uri);
-
-      data = g_key_file_to_data (file, &length, NULL);
-      stream = g_memory_input_stream_new_from_data (data, (gssize) length, g_free);
-
-      g_key_file_free (file);
-    }
-  else
-    {
-      GDataAuthorizationDomain *auth_domain;
-      const gchar *uri;
-
-      auth_domain = gdata_documents_service_get_primary_authorization_domain ();
-      uri = gdata_entry_get_content_uri (entry);
-      stream = gdata_download_stream_new (GDATA_SERVICE (self->service), auth_domain, uri, cancellable);
-    }
+  auth_domain = gdata_documents_service_get_primary_authorization_domain ();
+  uri = gdata_entry_get_content_uri (entry);
+  stream = gdata_download_stream_new (GDATA_SERVICE (self->service), auth_domain, uri, cancellable);
 
   g_object_set_data_full (G_OBJECT (stream), "g-vfs-backend-google-entry", g_object_ref (entry), 
g_object_unref);
 
@@ -1710,7 +1669,6 @@ g_vfs_backend_google_open_for_read (GVfsBackend        *_self,
   g_vfs_job_succeeded (G_VFS_JOB (job));
 
  out:
-  g_free (content_type);
   g_free (id);
   g_free (unescaped_filename);
   g_debug ("- open_for_read\n");


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