[libgdata] documents: add file-size property



commit 1b1b06343611c4665b0369b9bf1a64e8fc1e289c
Author: David Newgas <dnewgas google com>
Date:   Sun Oct 16 15:38:52 2016 -0700

    documents: add file-size property
    
    This property applies to all non-doc/sheet/slide/form documents. It is
    similar but distinct from the quota-used property, which is not set if
    the file's size isn't counting against the current user's quota.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=773057

 docs/reference/gdata-sections.txt                |    1 +
 gdata/gdata-core.symbols                         |    1 +
 gdata/services/documents/gdata-documents-entry.c |   53 ++++++++++++++++++++++
 gdata/services/documents/gdata-documents-entry.h |    1 +
 4 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index fba50b3..231c2b5 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -1553,6 +1553,7 @@ gdata_documents_entry_get_edited
 gdata_documents_entry_get_last_modified_by
 gdata_documents_entry_get_last_viewed
 gdata_documents_entry_get_quota_used
+gdata_documents_entry_get_file_size
 gdata_documents_entry_writers_can_invite
 gdata_documents_entry_set_writers_can_invite
 gdata_documents_entry_is_deleted
diff --git a/gdata/gdata-core.symbols b/gdata/gdata-core.symbols
index 7cda0b6..c04188d 100644
--- a/gdata/gdata-core.symbols
+++ b/gdata/gdata-core.symbols
@@ -968,6 +968,7 @@ gdata_documents_document_new
 gdata_documents_upload_query_get_convert
 gdata_documents_upload_query_set_convert
 gdata_documents_entry_get_quota_used
+gdata_documents_entry_get_file_size
 gdata_documents_service_copy_document
 gdata_documents_service_copy_document_async
 gdata_documents_service_copy_document_finish
diff --git a/gdata/services/documents/gdata-documents-entry.c 
b/gdata/services/documents/gdata-documents-entry.c
index 32f51ef..56a5daa 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -132,6 +132,7 @@ struct _GDataDocumentsEntryPrivate {
        gboolean is_deleted;
        GDataAuthor *last_modified_by;
        goffset quota_used; /* bytes */
+       goffset file_size; /* bytes */
 };
 
 enum {
@@ -143,6 +144,7 @@ enum {
        PROP_WRITERS_CAN_INVITE,
        PROP_RESOURCE_ID,
        PROP_QUOTA_USED,
+       PROP_FILE_SIZE,
 };
 
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GDataDocumentsEntry, gdata_documents_entry, GDATA_TYPE_ENTRY,
@@ -291,6 +293,22 @@ gdata_documents_entry_class_init (GDataDocumentsEntryClass *klass)
                                                             "Quota used", "The amount of user quota the 
document is occupying.",
                                                             0, G_MAXINT64, 0,
                                                             G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GDataDocumentsEntry:file-size:
+        *
+         * The size of the document. This is only set for non-document files.
+         * Standard formats, such as #GDataDocumentsText,
+         * #GDataDocumentsSpreadsheet and #GDataDocumentsFolder are not binary
+         * data and so have no size. Measured in bytes.
+        *
+        * Since: UNRELEASED
+        */
+       g_object_class_install_property (gobject_class, PROP_FILE_SIZE,
+                                        g_param_spec_int64 ("file-size",
+                                                            "File size", "The size of the document.",
+                                                            0, G_MAXINT64, 0,
+                                                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 }
 
 static gboolean
@@ -411,6 +429,9 @@ gdata_documents_entry_get_property (GObject *object, guint property_id, GValue *
                case PROP_QUOTA_USED:
                        g_value_set_int64 (value, priv->quota_used);
                        break;
+               case PROP_FILE_SIZE:
+                       g_value_set_int64 (value, priv->file_size);
+                       break;
                default:
                        /* We don't have any other property... */
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -428,6 +449,7 @@ gdata_documents_entry_set_property (GObject *object, guint property_id, const GV
                        gdata_documents_entry_set_writers_can_invite (self, g_value_get_boolean (value));
                        break;
                case PROP_QUOTA_USED:
+               case PROP_FILE_SIZE:
                        /* Read only. */
                default:
                        /* We don't have any other property... */
@@ -570,6 +592,7 @@ parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GEr
        gchar *kind = NULL;
        gchar *mime_type = NULL;
        gchar *quota_used = NULL;
+       gchar *file_size = NULL;
        gint64 published;
        gint64 updated;
 
@@ -615,6 +638,18 @@ parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GEr
                        priv->quota_used = (goffset) val;
                g_free (quota_used);
                return success;
+       } else if (gdata_parser_string_from_json_member (reader, "fileSize", P_DEFAULT, &file_size, &success, 
error) == TRUE) {
+               gchar *end_ptr;
+               guint64 val;
+
+               /* like 'quotaBytesUsed', 'fileSize' is also a string
+                * in the JSON.
+                */
+               val = g_ascii_strtoull (file_size, &end_ptr, 10);
+               if (*end_ptr == '\0')
+                       priv->file_size = (goffset) val;
+               g_free (file_size);
+               return success;
        } else if (gdata_parser_boolean_from_json_member (reader, "shared", P_DEFAULT, &shared, &success, 
error) == TRUE) {
                if (success && shared) {
                        category = gdata_category_new ("http://schemas.google.com/g/2005/labels#shared";, 
GDATA_CATEGORY_SCHEMA_LABELS, "shared");
@@ -1087,6 +1122,24 @@ gdata_documents_entry_get_quota_used (GDataDocumentsEntry *self)
 }
 
 /**
+ * gdata_documents_entry_get_file_size:
+ * @self: a #GDataDocumentsEntry
+ *
+ * Gets the #GDataDocumentsEntry:file-size property.
+ *
+ * Return value: the size of the document in bytes
+ *
+ * Since: UNRELEASED
+ */
+goffset
+gdata_documents_entry_get_file_size (GDataDocumentsEntry *self)
+{
+       g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (self), 0);
+
+       return self->priv->file_size;
+}
+
+/**
  * gdata_documents_entry_is_deleted:
  * @self: a #GDataDocumentsEntry
  *
diff --git a/gdata/services/documents/gdata-documents-entry.h 
b/gdata/services/documents/gdata-documents-entry.h
index 9f21035..dfb38df 100644
--- a/gdata/services/documents/gdata-documents-entry.h
+++ b/gdata/services/documents/gdata-documents-entry.h
@@ -114,6 +114,7 @@ gboolean gdata_documents_entry_writers_can_invite (GDataDocumentsEntry *self) G_
 GDataAuthor *gdata_documents_entry_get_last_modified_by (GDataDocumentsEntry *self) G_GNUC_PURE;
 
 goffset gdata_documents_entry_get_quota_used (GDataDocumentsEntry *self) G_GNUC_PURE;
+goffset gdata_documents_entry_get_file_size (GDataDocumentsEntry *self) G_GNUC_PURE;
 
 gboolean gdata_documents_entry_is_deleted (GDataDocumentsEntry *self) G_GNUC_PURE;
 


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