[libgdata] documents: Set mimeType in JSON



commit 656207baff1e288c0c7d6020555316a53b9faa1c
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Jun 16 15:06:51 2015 +0200

    documents: Set mimeType in JSON
    
    A Drive v2 folder is a file with the MIME type
    application/vnd.google-apps.folder (and with no extension). Therefore,
    setting the MIME type is crucial for creating new folders.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684920

 gdata/services/documents/gdata-documents-entry.c  |   18 ++++++++++++++++++
 gdata/services/documents/gdata-documents-folder.c |   20 ++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-entry.c 
b/gdata/services/documents/gdata-documents-entry.c
index 630d622..a459bd6 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -803,11 +803,29 @@ get_content_type (void)
 static void
 get_json (GDataParsable *parsable, JsonBuilder *builder)
 {
+       GList *categories;
        GList *i;
        GList *parent_folders_list;
 
        GDATA_PARSABLE_CLASS (gdata_documents_entry_parent_class)->get_json (parsable, builder);
 
+       /* Inserting files: https://developers.google.com/drive/v2/reference/files/insert */
+
+       categories = gdata_entry_get_categories (GDATA_ENTRY (parsable));
+       for (i = categories; i != NULL; i = i->next) {
+               GDataCategory *category = GDATA_CATEGORY (i->data);
+               const gchar *label;
+               const gchar *scheme;
+
+               label = gdata_category_get_label (category);
+               scheme = gdata_category_get_scheme (category);
+               if (label != NULL && label[0] != '\0' && g_strcmp0 (scheme, 
"http://schemas.google.com/g/2005#kind";) == 0) {
+                       json_builder_set_member_name (builder, "mimeType");
+                       json_builder_add_string_value (builder, label);
+                       break;
+               }
+       }
+
        /* Upload to a folder: https://developers.google.com/drive/web/folder */
 
        json_builder_set_member_name (builder, "parents");
diff --git a/gdata/services/documents/gdata-documents-folder.c 
b/gdata/services/documents/gdata-documents-folder.c
index 3f1cd76..46c958c 100644
--- a/gdata/services/documents/gdata-documents-folder.c
+++ b/gdata/services/documents/gdata-documents-folder.c
@@ -3,6 +3,7 @@
  * GData Client
  * Copyright (C) Thibault Saunier 2009 <saunierthibault gmail com>
  * Copyright (C) Philip Withnall 2010 <philip tecnocode co uk>
+ * Copyright (C) Red Hat, Inc. 2015
  *
  * GData Client is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -78,13 +79,17 @@
 #include "gdata-types.h"
 #include "gdata-private.h"
 
+static void gdata_documents_folder_constructed (GObject *object);
+
 G_DEFINE_TYPE (GDataDocumentsFolder, gdata_documents_folder, GDATA_TYPE_DOCUMENTS_ENTRY)
 
 static void
 gdata_documents_folder_class_init (GDataDocumentsFolderClass *klass)
 {
+       GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
        GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
 
+       gobject_class->constructed = gdata_documents_folder_constructed;
        entry_class->kind_term = "http://schemas.google.com/docs/2007#folder";;
 }
 
@@ -94,6 +99,21 @@ gdata_documents_folder_init (GDataDocumentsFolder *self)
        /* Why am I writing it? */
 }
 
+static void
+gdata_documents_folder_constructed (GObject *object)
+{
+       G_OBJECT_CLASS (gdata_documents_folder_parent_class)->constructed (object);
+
+       if (!_gdata_parsable_is_constructed_from_xml (GDATA_PARSABLE (object))) {
+               GDataCategory *category;
+               GDataEntryClass *klass = GDATA_ENTRY_GET_CLASS (object);
+
+               category = gdata_category_new (klass->kind_term, "http://schemas.google.com/g/2005#kind";, 
"application/vnd.google-apps.folder");
+               gdata_entry_add_category (GDATA_ENTRY (object), category);
+               g_object_unref (category);
+       }
+}
+
 /**
  * gdata_documents_folder_new:
  * @id: (allow-none): the entry's ID (not the document ID of the folder), or %NULL


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