summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2021-02-11 21:32:52 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2021-02-11 21:32:52 +0000
commit1de5b09b58ac025a9c1b1b210abef3073c9e808b (patch)
tree07671ccd88fb992f11f167d4ea88ee31489539b9
parentc42082c8c959933e219a7725b791c51002a6daec (diff)
parentcd53cd6402c0348ce8a85c1d319c0e3a8445563b (diff)
downloadlibgdata-1de5b09b58ac025a9c1b1b210abef3073c9e808b.tar.gz
Merge branch 'wip/oholy/documents-shared-drives-support' into 'master'
documents: Add Shared Drives support Closes #25 See merge request GNOME/libgdata!27
-rw-r--r--docs/reference/gdata-sections.txt.in40
-rw-r--r--gdata/gdata-core.symbols8
-rw-r--r--gdata/gdata-query.h1
-rw-r--r--gdata/gdata.h2
-rw-r--r--gdata/services/documents/gdata-documents-drive-query.c98
-rw-r--r--gdata/services/documents/gdata-documents-drive-query.h55
-rw-r--r--gdata/services/documents/gdata-documents-drive.c144
-rw-r--r--gdata/services/documents/gdata-documents-drive.h55
-rw-r--r--gdata/services/documents/gdata-documents-entry.c97
-rw-r--r--gdata/services/documents/gdata-documents-entry.h4
-rw-r--r--gdata/services/documents/gdata-documents-feed.c3
-rw-r--r--gdata/services/documents/gdata-documents-query.c5
-rw-r--r--gdata/services/documents/gdata-documents-service.c96
-rw-r--r--gdata/services/documents/gdata-documents-service.h9
-rw-r--r--gdata/services/documents/meson.build4
-rw-r--r--gdata/symbol.map8
16 files changed, 628 insertions, 1 deletions
diff --git a/docs/reference/gdata-sections.txt.in b/docs/reference/gdata-sections.txt.in
index e159b00b..42139e44 100644
--- a/docs/reference/gdata-sections.txt.in
+++ b/docs/reference/gdata-sections.txt.in
@@ -1562,6 +1562,8 @@ gdata_documents_entry_is_deleted
gdata_documents_entry_get_document_properties
gdata_documents_entry_add_documents_property
gdata_documents_entry_remove_documents_property
+gdata_documents_entry_get_shared_with_me_date
+gdata_documents_entry_can_edit
<SUBSECTION Standard>
gdata_documents_entry_get_type
GDATA_DOCUMENTS_ENTRY
@@ -1817,6 +1819,8 @@ gdata_documents_service_get_metadata_async
gdata_documents_service_get_metadata_finish
gdata_documents_service_query_documents
gdata_documents_service_query_documents_async
+gdata_documents_service_query_drives
+gdata_documents_service_query_drives_async
gdata_documents_service_upload_document
gdata_documents_service_upload_document_resumable
gdata_documents_service_update_document
@@ -1866,6 +1870,42 @@ GDataDocumentsMetadataPrivate
</SECTION>
<SECTION>
+<FILE>gdata-documents-drive</FILE>
+<TITLE>GDataDocumentsDrive</TITLE>
+GDataDocumentsDrive
+GDataDocumentsDriveClass
+gdata_documents_drive_get_name
+<SUBSECTION Standard>
+gdata_documents_drive_get_type
+GDATA_DOCUMENTS_DRIVE
+GDATA_DOCUMENTS_DRIVE_CLASS
+GDATA_DOCUMENTS_DRIVE_GET_CLASS
+GDATA_IS_DOCUMENTS_DRIVE
+GDATA_IS_DOCUMENTS_DRIVE_CLASS
+GDATA_TYPE_DOCUMENTS_DRIVE
+<SUBSECTION Private>
+GDataDocumentsDrivePrivate
+</SECTION>
+
+<SECTION>
+<FILE>gdata-documents-drive-query</FILE>
+<TITLE>GDataDocumentsDriveQuery</TITLE>
+GDataDocumentsDriveQuery
+GDataDocumentsDriveQueryClass
+gdata_documents_drive_query_new
+<SUBSECTION Standard>
+gdata_documents_drive_query_get_type
+GDATA_DOCUMENTS_DRIVE_QUERY
+GDATA_DOCUMENTS_DRIVE_QUERY_CLASS
+GDATA_DOCUMENTS_DRIVE_QUERY_GET_CLASS
+GDATA_IS_DOCUMENTS_DRIVE_QUERY
+GDATA_IS_DOCUMENTS_DRIVE_QUERY_CLASS
+GDATA_TYPE_DOCUMENTS_DRIVE_QUERY
+<SUBSECTION Private>
+GDataDocumentsDriveQueryPrivate
+</SECTION>
+
+<SECTION>
<FILE>gdata-download-stream</FILE>
<TITLE>GDataDownloadStream</TITLE>
GDataDownloadStream
diff --git a/gdata/gdata-core.symbols b/gdata/gdata-core.symbols
index 29e94fdb..606df7c3 100644
--- a/gdata/gdata-core.symbols
+++ b/gdata/gdata-core.symbols
@@ -633,6 +633,8 @@ gdata_documents_service_get_metadata_async
gdata_documents_service_get_metadata_finish
gdata_documents_service_query_documents
gdata_documents_service_query_documents_async
+gdata_documents_service_query_drives
+gdata_documents_service_query_drives_async
gdata_documents_service_upload_document
gdata_documents_service_update_document
gdata_documents_service_get_upload_uri
@@ -649,6 +651,8 @@ gdata_documents_entry_set_writers_can_invite
gdata_documents_entry_writers_can_invite
gdata_documents_entry_get_last_modified_by
gdata_documents_entry_is_deleted
+gdata_documents_entry_get_shared_with_me_date
+gdata_documents_entry_can_edit
gdata_documents_query_get_type
gdata_documents_query_new
gdata_documents_query_new_with_limits
@@ -669,6 +673,10 @@ gdata_documents_service_error_get_type
gdata_documents_service_error_quark
gdata_documents_access_rule_get_type
gdata_documents_access_rule_new
+gdata_documents_drive_get_type
+gdata_documents_drive_get_name
+gdata_documents_drive_query_get_type
+gdata_documents_drive_query_new
gdata_download_stream_get_type
gdata_download_stream_new
gdata_download_stream_get_service
diff --git a/gdata/gdata-query.h b/gdata/gdata-query.h
index f80cc8c0..52796a4d 100644
--- a/gdata/gdata-query.h
+++ b/gdata/gdata-query.h
@@ -66,6 +66,7 @@ typedef struct {
} GDataQueryClass;
GType gdata_query_get_type (void) G_GNUC_CONST;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GDataQuery, g_object_unref)
GDataQuery *gdata_query_new (const gchar *q) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
GDataQuery *gdata_query_new_with_limits (const gchar *q, guint start_index, guint max_results) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
diff --git a/gdata/gdata.h b/gdata/gdata.h
index a1ff6ec4..0858accd 100644
--- a/gdata/gdata.h
+++ b/gdata/gdata.h
@@ -128,6 +128,8 @@
/* Google Documents*/
#include <gdata/services/documents/gdata-documents-entry.h>
#include <gdata/services/documents/gdata-documents-document.h>
+#include <gdata/services/documents/gdata-documents-drive.h>
+#include <gdata/services/documents/gdata-documents-drive-query.h>
#include <gdata/services/documents/gdata-documents-property.h>
#include <gdata/services/documents/gdata-documents-text.h>
#include <gdata/services/documents/gdata-documents-spreadsheet.h>
diff --git a/gdata/services/documents/gdata-documents-drive-query.c b/gdata/services/documents/gdata-documents-drive-query.c
new file mode 100644
index 00000000..e1914922
--- /dev/null
+++ b/gdata/services/documents/gdata-documents-drive-query.c
@@ -0,0 +1,98 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Ondrej Holy 2020 <oholy@redhat.com>
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * SECTION:gdata-documents-drive-query
+ * @short_description: GData Documents Drive query object
+ * @stability: Stable
+ * @include: gdata/services/documents/gdata-documents-drive-query.h
+ *
+ * #GDataDocumentsDriveQuery represents a collection of query parameters specific to shared drives, which go above and beyond
+ * those catered for by #GDataQuery.
+ *
+ * For more information on the custom GData query parameters supported by #GDataDocumentsDriveQuery, see the
+ * [online documentation](https://developers.google.com/drive/api/v2/ref-search-terms#drive_properties).
+ *
+ * Since: 0.18.0
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+#include <string.h>
+
+#include "gdata-documents-drive-query.h"
+#include "gdata-private.h"
+
+static void get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboolean *params_started);
+
+G_DEFINE_TYPE (GDataDocumentsDriveQuery, gdata_documents_drive_query, GDATA_TYPE_QUERY)
+
+static void
+gdata_documents_drive_query_class_init (GDataDocumentsDriveQueryClass *klass)
+{
+ GDataQueryClass *query_class = GDATA_QUERY_CLASS (klass);
+
+ query_class->get_query_uri = get_query_uri;
+}
+
+static void
+gdata_documents_drive_query_init (GDataDocumentsDriveQuery *self)
+{
+ /* https://developers.google.com/drive/api/v2/reference/drives/list#parameters */
+ _gdata_query_set_pagination_type (GDATA_QUERY (self),
+ GDATA_QUERY_PAGINATION_TOKENS);
+}
+
+static void
+get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboolean *params_started)
+{
+ guint max_results;
+
+ #define APPEND_SEP g_string_append_c (query_uri, (*params_started == FALSE) ? '?' : '&'); *params_started = TRUE;
+
+ _gdata_query_clear_q_internal (self);
+
+ /* Chain up to the parent class */
+ GDATA_QUERY_CLASS (gdata_documents_drive_query_parent_class)->get_query_uri (self, feed_uri, query_uri, params_started);
+
+ /* https://developers.google.com/drive/api/v2/reference/drives/list */
+ max_results = gdata_query_get_max_results (self);
+ if (max_results > 0) {
+ APPEND_SEP
+ max_results = max_results > 100 ? 100 : max_results;
+ g_string_append_printf (query_uri, "maxResults=%u", max_results);
+ }
+}
+
+/**
+ * gdata_documents_drive_query_new:
+ * @q: (nullable): a query string, or %NULL
+ *
+ * Creates a new #GDataDocumentsDriveQuery with its #GDataQuery:q property set to @q.
+ *
+ * Return value: (transfer full): a new #GDataDocumentsDriveQuery
+ *
+ * Since: 0.18.0
+ */
+GDataDocumentsDriveQuery *
+gdata_documents_drive_query_new (const gchar *q)
+{
+ return g_object_new (GDATA_TYPE_DOCUMENTS_DRIVE_QUERY, "q", q, NULL);
+}
diff --git a/gdata/services/documents/gdata-documents-drive-query.h b/gdata/services/documents/gdata-documents-drive-query.h
new file mode 100644
index 00000000..9668830c
--- /dev/null
+++ b/gdata/services/documents/gdata-documents-drive-query.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Ondrej Holy 2020 <oholy@redhat.com>
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GDATA_DOCUMENTS_DRIVE_QUERY_H
+#define GDATA_DOCUMENTS_DRIVE_QUERY_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gdata/gdata-types.h>
+#include <gdata/gdata-query.h>
+
+G_BEGIN_DECLS
+
+#define GDATA_TYPE_DOCUMENTS_DRIVE_QUERY gdata_documents_drive_query_get_type ()
+G_DECLARE_DERIVABLE_TYPE (GDataDocumentsDriveQuery, gdata_documents_drive_query, GDATA, DOCUMENTS_DRIVE_QUERY, GDataQuery)
+
+/**
+ * GDataDocumentsDriveQueryClass:
+ *
+ * All the fields in the #GDataDocumentsDriveQueryClass structure are private and should never be accessed directly.
+ *
+ * Since: 0.18.0
+ */
+struct _GDataDocumentsDriveQueryClass {
+ /*< private >*/
+ GDataQueryClass parent;
+
+ /*< private >*/
+ /* Padding for future expansion */
+ void (*_g_reserved0) (void);
+ void (*_g_reserved1) (void);
+};
+
+GDataDocumentsDriveQuery *gdata_documents_drive_query_new (const gchar *q) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+
+G_END_DECLS
+
+#endif /* !GDATA_DOCUMENTS_DRIVE_QUERY_H */
diff --git a/gdata/services/documents/gdata-documents-drive.c b/gdata/services/documents/gdata-documents-drive.c
new file mode 100644
index 00000000..5063be8b
--- /dev/null
+++ b/gdata/services/documents/gdata-documents-drive.c
@@ -0,0 +1,144 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Ondrej Holy 2020 <oholy@redhat.com>
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * SECTION:gdata-documents-drive
+ * @short_description: GData documents drive object
+ * @stability: Stable
+ * @include: gdata/services/documents/gdata-documents-drive.h
+ *
+ * #GDataDocumentsDrive is a subclass of #GDataEntry to represent an arbitrary Google Drive shared drive.
+ *
+ * For more details of Google Drive’s GData API, see the [online documentation](https://developers.google.com/drive/v2/web/about-sdk).
+ *
+ * Since: 0.18.0
+ */
+
+#include <config.h>
+#include <glib.h>
+
+#include "gdata-documents-drive.h"
+#include "gdata-private.h"
+
+static void gdata_documents_drive_finalize (GObject *object);
+static void gdata_documents_drive_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static gboolean parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error);
+
+typedef struct {
+ gchar *name;
+} GDataDocumentsDrivePrivate;
+
+enum {
+ PROP_NAME = 1,
+};
+
+G_DEFINE_TYPE_WITH_CODE (GDataDocumentsDrive, gdata_documents_drive, GDATA_TYPE_ENTRY,
+ G_ADD_PRIVATE (GDataDocumentsDrive));
+
+static void
+gdata_documents_drive_class_init (GDataDocumentsDriveClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+
+ gobject_class->get_property = gdata_documents_drive_get_property;
+ gobject_class->finalize = gdata_documents_drive_finalize;
+
+ parsable_class->parse_json = parse_json;
+
+ /**
+ * GDataDocumentsDrive:name:
+ *
+ * The human-readable name of this shared drive.
+ *
+ * Since: 0.18.0
+ */
+ g_object_class_install_property (gobject_class, PROP_NAME,
+ g_param_spec_string ("name",
+ "Name", "The human-readable name of this shared drive.",
+ NULL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gdata_documents_drive_init (GDataDocumentsDrive *self)
+{
+}
+
+static void
+gdata_documents_drive_finalize (GObject *object)
+{
+ GDataDocumentsDrivePrivate *priv = gdata_documents_drive_get_instance_private (GDATA_DOCUMENTS_DRIVE (object));
+
+ g_free (priv->name);
+
+ G_OBJECT_CLASS (gdata_documents_drive_parent_class)->finalize (object);
+}
+
+static void
+gdata_documents_drive_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ GDataDocumentsDrivePrivate *priv = gdata_documents_drive_get_instance_private (GDATA_DOCUMENTS_DRIVE (object));
+
+ switch (property_id) {
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+/**
+ * gdata_documents_drive_get_name:
+ * @self: a #GDataDocumentsDrive
+ *
+ * Returns the human-readable name of this shared drive.
+ *
+ * Return value: (nullable): the drives's human-readable name, or %NULL if not set
+ *
+ * Since: 0.18.0
+ */
+const gchar *
+gdata_documents_drive_get_name (GDataDocumentsDrive *self)
+{
+ GDataDocumentsDrivePrivate *priv = gdata_documents_drive_get_instance_private (self);
+
+ return priv->name;
+}
+
+static gboolean
+parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error)
+{
+ GDataDocumentsDrivePrivate *priv = gdata_documents_drive_get_instance_private (GDATA_DOCUMENTS_DRIVE (parsable));
+ gboolean success = TRUE;
+ gchar *name = NULL;
+
+ /* JSON format: https://developers.google.com/drive/v2/reference/drives */
+
+ if (gdata_parser_string_from_json_member (reader, "name", P_DEFAULT, &name, &success, error) == TRUE) {
+ if (success)
+ priv->name = name;
+ return success;
+ }
+
+ return GDATA_PARSABLE_CLASS (gdata_documents_drive_parent_class)->parse_json (parsable, reader, user_data, error);
+}
diff --git a/gdata/services/documents/gdata-documents-drive.h b/gdata/services/documents/gdata-documents-drive.h
new file mode 100644
index 00000000..63598e37
--- /dev/null
+++ b/gdata/services/documents/gdata-documents-drive.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Ondrej Holy 2020 <oholy@redhat.com>
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GDATA_DOCUMENTS_DRIVE_H
+#define GDATA_DOCUMENTS_DRIVE_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gdata/gdata-entry.h>
+
+G_BEGIN_DECLS
+
+#define GDATA_TYPE_DOCUMENTS_DRIVE gdata_documents_drive_get_type ()
+G_DECLARE_DERIVABLE_TYPE (GDataDocumentsDrive, gdata_documents_drive, GDATA, DOCUMENTS_DRIVE, GDataEntry)
+
+
+/**
+ * GDataDocumentsDriveClass:
+ *
+ * All the fields in the #GDataDocumentsDriveClass structure are private and should never be accessed directly.
+ *
+ * Since: 0.18.0
+ */
+struct _GDataDocumentsDriveClass {
+ /*< private >*/
+ GDataEntryClass parent;
+
+ /*< private >*/
+ /* Padding for future expansion */
+ void (*_g_reserved0) (void);
+ void (*_g_reserved1) (void);
+};
+
+const gchar *gdata_documents_drive_get_name (GDataDocumentsDrive *self) G_GNUC_PURE;
+
+G_END_DECLS
+
+#endif /* !GDATA_DOCUMENTS_DRIVE_H */
diff --git a/gdata/services/documents/gdata-documents-entry.c b/gdata/services/documents/gdata-documents-entry.c
index f16cfcd3..b9b1ffe2 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -135,6 +135,8 @@ struct _GDataDocumentsEntryPrivate {
goffset quota_used; /* bytes */
goffset file_size; /* bytes */
GList *properties; /* GDataDocumentsProperty */
+ gint64 shared_with_me_date;
+ gboolean can_edit;
};
enum {
@@ -147,6 +149,8 @@ enum {
PROP_RESOURCE_ID,
PROP_QUOTA_USED,
PROP_FILE_SIZE,
+ PROP_SHARED_WITH_ME_DATE,
+ PROP_CAN_EDIT,
};
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GDataDocumentsEntry, gdata_documents_entry, GDATA_TYPE_ENTRY,
@@ -311,6 +315,32 @@ gdata_documents_entry_class_init (GDataDocumentsEntryClass *klass)
"File size", "The size of the document.",
0, G_MAXINT64, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GDataDocumentsEntry:shared-with-me-date:
+ *
+ * The UNIX timestamp for the time at which this file was shared with the user.
+ *
+ * Since: 0.18.0
+ */
+ g_object_class_install_property (gobject_class, PROP_SHARED_WITH_ME_DATE,
+ g_param_spec_int64 ("shared-with-me-date",
+ "Shared with me date", "The time at which this file was shared with the user.",
+ -1, G_MAXINT64, -1,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GDataDocumentsEntry:can-edit:
+ *
+ * Indicates whether the current user can edit this file.
+ *
+ * Since: 0.18.0
+ */
+ g_object_class_install_property (gobject_class, PROP_CAN_EDIT,
+ g_param_spec_boolean ("can-edit",
+ "Can edit?", "Indicates whether the current user can edit this file.",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
static gboolean
@@ -437,6 +467,12 @@ gdata_documents_entry_get_property (GObject *object, guint property_id, GValue *
case PROP_FILE_SIZE:
g_value_set_int64 (value, priv->file_size);
break;
+ case PROP_SHARED_WITH_ME_DATE:
+ g_value_set_int64 (value, priv->shared_with_me_date);
+ break;
+ case PROP_CAN_EDIT:
+ g_value_set_boolean (value, priv->can_edit);
+ break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -935,6 +971,31 @@ parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GEr
}
return success;
+ } else if (gdata_parser_int64_time_from_json_member (reader, "sharedWithMeDate", P_DEFAULT, &(priv->shared_with_me_date), &success, error) == TRUE) {
+ return success;
+ } else if (g_strcmp0 (json_reader_get_member_name (reader), "capabilities") == 0) {
+ guint i, members;
+
+ if (!json_reader_is_object (reader)) {
+ g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
+ /* Translators: the parameter is an error message */
+ _("Error parsing JSON: %s"),
+ "JSON node ‘capabilities’ is not an object.");
+ return FALSE;
+ }
+
+ for (i = 0, members = (guint) json_reader_count_members (reader); i < members; i++) {
+ json_reader_read_element (reader, i);
+
+ if (gdata_parser_boolean_from_json_member (reader, "canEdit", P_DEFAULT, &(priv->can_edit), &success, error) == TRUE) {
+ json_reader_end_element (reader);
+ break;
+ }
+
+ json_reader_end_element (reader);
+ }
+
+ return success;
}
return GDATA_PARSABLE_CLASS (gdata_documents_entry_parent_class)->parse_json (parsable, reader, user_data, error);
@@ -1058,7 +1119,7 @@ get_namespaces (GDataParsable *parsable, GHashTable *namespaces)
static gchar *
get_entry_uri (const gchar *id)
{
- return g_strconcat ("https://www.googleapis.com/drive/v2/files/", id, NULL);
+ return g_strconcat ("https://www.googleapis.com/drive/v2/files/", id, "?supportsAllDrives=true", NULL);
}
/**
@@ -1419,3 +1480,37 @@ gdata_documents_entry_remove_documents_property (GDataDocumentsEntry *self, GDat
return TRUE;
}
+
+/**
+ * gdata_documents_entry_get_shared_with_me_date:
+ * @self: a #GDataDocumentsEntry
+ *
+ * Gets the #GDataDocumentsEntry:shared-with-me-date property. If the property is unset, `-1` will be returned.
+ *
+ * Return value: the UNIX timestamp for the time at which this file was shared with the user, or `-1`
+ *
+ * Since: 0.18.0
+ */
+gint64
+gdata_documents_entry_get_shared_with_me_date (GDataDocumentsEntry *self)
+{
+ g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (self), -1);
+ return self->priv->shared_with_me_date;
+}
+
+/**
+ * gdata_documents_entry_can_edit:
+ * @self: a #GDataDocumentsEntry
+ *
+ * Gets the #GDataDocumentsEntry:can-edit property.
+ *
+ * Return value: %TRUE if the current user can edit this file, %FALSE otherwise
+ *
+ * Since: 0.18.0
+ */
+gboolean
+gdata_documents_entry_can_edit (GDataDocumentsEntry *self)
+{
+ g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (self), FALSE);
+ return self->priv->can_edit;
+}
diff --git a/gdata/services/documents/gdata-documents-entry.h b/gdata/services/documents/gdata-documents-entry.h
index 558b91d2..4dd0e591 100644
--- a/gdata/services/documents/gdata-documents-entry.h
+++ b/gdata/services/documents/gdata-documents-entry.h
@@ -125,6 +125,10 @@ GList *gdata_documents_entry_get_document_properties (GDataDocumentsEntry *self)
gboolean gdata_documents_entry_add_documents_property (GDataDocumentsEntry *self, GDataDocumentsProperty *property);
gboolean gdata_documents_entry_remove_documents_property (GDataDocumentsEntry *self, GDataDocumentsProperty *property);
+gint64 gdata_documents_entry_get_shared_with_me_date (GDataDocumentsEntry *self);
+
+gboolean gdata_documents_entry_can_edit (GDataDocumentsEntry *self);
+
G_END_DECLS
#endif /* !GDATA_DOCUMENTS_ENTRY_H */
diff --git a/gdata/services/documents/gdata-documents-feed.c b/gdata/services/documents/gdata-documents-feed.c
index 36370975..9a746e28 100644
--- a/gdata/services/documents/gdata-documents-feed.c
+++ b/gdata/services/documents/gdata-documents-feed.c
@@ -41,6 +41,7 @@
#include "gdata-documents-feed.h"
#include "gdata-documents-utils.h"
+#include "gdata-documents-drive.h"
#include "gdata-types.h"
#include "gdata-private.h"
#include "gdata-service.h"
@@ -159,6 +160,8 @@ parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GEr
if (g_strcmp0 (kind, "drive#file") == 0) {
entry_type = gdata_documents_utils_get_type_from_content_type (mime_type);
+ } else if (g_strcmp0 (kind, "drive#drive") == 0) {
+ entry_type = GDATA_TYPE_DOCUMENTS_DRIVE;
} else {
g_warning ("%s files are not handled yet", kind);
}
diff --git a/gdata/services/documents/gdata-documents-query.c b/gdata/services/documents/gdata-documents-query.c
index 6070c1b0..0a5a8d4b 100644
--- a/gdata/services/documents/gdata-documents-query.c
+++ b/gdata/services/documents/gdata-documents-query.c
@@ -404,6 +404,11 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
max_results = max_results > 1000 ? 1000 : max_results;
g_string_append_printf (query_uri, "maxResults=%u", max_results);
}
+
+ APPEND_SEP
+ g_string_append_printf (query_uri, "includeItemsFromAllDrives=true");
+ APPEND_SEP
+ g_string_append_printf (query_uri, "supportsAllDrives=true");
}
/**
diff --git a/gdata/services/documents/gdata-documents-service.c b/gdata/services/documents/gdata-documents-service.c
index 93bc8f71..fa0b81ec 100644
--- a/gdata/services/documents/gdata-documents-service.c
+++ b/gdata/services/documents/gdata-documents-service.c
@@ -261,6 +261,7 @@
#include "gdata-documents-property.h"
#include "gdata-documents-service.h"
#include "gdata-documents-utils.h"
+#include "gdata-documents-drive.h"
#include "gdata-batchable.h"
#include "gdata-service.h"
#include "gdata-private.h"
@@ -643,6 +644,101 @@ gdata_documents_service_query_documents_async (GDataDocumentsService *self, GDat
g_free (request_uri);
}
+/**
+ * gdata_documents_service_query_drives:
+ * @self: a #GDataDocumentsService
+ * @query: (nullable): a #GDataDocumentsDriveQuery with the query parameters, or %NULL
+ * @cancellable: (nullable): optional #GCancellable object, or %NULL
+ * @progress_callback: (nullable) (scope call) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
+ * @progress_user_data: (closure): data to pass to the @progress_callback function
+ * @error: a #GError, or %NULL
+ *
+ * Queries the service to return a list of shared drives matching the given @query.
+ *
+ * For more details, see gdata_service_query().
+ *
+ * Return value: (transfer full): a #GDataDocumentsFeed of query results; unref with g_object_unref()
+ *
+ * Since: 0.18.0
+ */
+GDataDocumentsFeed *
+gdata_documents_service_query_drives (GDataDocumentsService *self, GDataDocumentsDriveQuery *query, GCancellable *cancellable,
+ GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+ GError **error)
+{
+ GDataFeed *feed;
+ const gchar *request_uri = "https://www.googleapis.com/drive/v2/drives";
+
+ g_return_val_if_fail (GDATA_IS_DOCUMENTS_SERVICE (self), NULL);
+ g_return_val_if_fail (query == NULL || GDATA_IS_DOCUMENTS_DRIVE_QUERY (query), NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ /* Ensure we're authenticated first */
+ if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
+ get_documents_authorization_domain ()) == FALSE) {
+ g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
+ _("You must be authenticated to query drives."));
+ return NULL;
+ }
+
+ feed = gdata_service_query (GDATA_SERVICE (self), get_documents_authorization_domain (), request_uri, GDATA_QUERY (query),
+ GDATA_TYPE_DOCUMENTS_DRIVE, cancellable, progress_callback, progress_user_data, error);
+
+ return GDATA_DOCUMENTS_FEED (feed);
+}
+
+/**
+ * gdata_documents_service_query_drives_async:
+ * @self: a #GDataDocumentsService
+ * @query: (nullable): a #GDataDocumentsDriveQuery with the query parameters, or %NULL
+ * @cancellable: (nullable): optional #GCancellable object, or %NULL
+ * @progress_callback: (nullable) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
+ * @progress_user_data: (closure): data to pass to the @progress_callback function
+ * @destroy_progress_user_data: (nullable): the function to call when @progress_callback will not be called any more, or %NULL. This function will be
+ * called with @progress_user_data as a parameter and can be used to free any memory allocated for it.
+ * @callback: a #GAsyncReadyCallback to call when authentication is finished
+ * @user_data: (closure): data to pass to the @callback function
+ *
+ * Queries the service to return a list of shared drives matching the given @query. @self and
+ * @query are both reffed when this function is called, so can safely be unreffed after this function returns.
+ *
+ * For more details, see gdata_documents_service_query_drives(), which is the synchronous version of this function,
+ * and gdata_service_query_async(), which is the base asynchronous query function.
+ *
+ * Since: 0.18.0
+ */
+void
+gdata_documents_service_query_drives_async (GDataDocumentsService *self, GDataDocumentsDriveQuery *query, GCancellable *cancellable,
+ GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+ GDestroyNotify destroy_progress_user_data,
+ GAsyncReadyCallback callback, gpointer user_data)
+{
+ const gchar *request_uri = "https://www.googleapis.com/drive/v2/drives";
+
+ g_return_if_fail (GDATA_IS_DOCUMENTS_SERVICE (self));
+ g_return_if_fail (query == NULL || GDATA_IS_DOCUMENTS_QUERY (query));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+ g_return_if_fail (callback != NULL);
+
+ /* Ensure we're authenticated first */
+ if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
+ get_documents_authorization_domain ()) == FALSE) {
+ g_autoptr(GTask) task = NULL;
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, gdata_service_query_async);
+ g_task_return_new_error (task, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED, "%s",
+ _("You must be authenticated to query drives."));
+
+ return;
+ }
+
+ gdata_service_query_async (GDATA_SERVICE (self), get_documents_authorization_domain (), request_uri, GDATA_QUERY (query),
+ GDATA_TYPE_DOCUMENTS_DRIVE, cancellable, progress_callback, progress_user_data,
+ destroy_progress_user_data, callback, user_data);
+}
+
static void
add_folder_link_to_entry (GDataDocumentsEntry *entry, GDataDocumentsFolder *folder)
{
diff --git a/gdata/services/documents/gdata-documents-service.h b/gdata/services/documents/gdata-documents-service.h
index ab2ea7e2..da173ad0 100644
--- a/gdata/services/documents/gdata-documents-service.h
+++ b/gdata/services/documents/gdata-documents-service.h
@@ -28,6 +28,7 @@
#include <gdata/services/documents/gdata-documents-query.h>
#include <gdata/services/documents/gdata-documents-feed.h>
#include <gdata/services/documents/gdata-documents-metadata.h>
+#include <gdata/services/documents/gdata-documents-drive-query.h>
G_BEGIN_DECLS
@@ -112,6 +113,14 @@ void gdata_documents_service_query_documents_async (GDataDocumentsService *self,
GDestroyNotify destroy_progress_user_data,
GAsyncReadyCallback callback, gpointer user_data);
+GDataDocumentsFeed *gdata_documents_service_query_drives (GDataDocumentsService *self, GDataDocumentsDriveQuery *query, GCancellable *cancellable,
+ GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+ GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+void gdata_documents_service_query_drives_async (GDataDocumentsService *self, GDataDocumentsDriveQuery *query, GCancellable *cancellable,
+ GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+ GDestroyNotify destroy_progress_user_data,
+ GAsyncReadyCallback callback, gpointer user_data);
+
#include <gdata/services/documents/gdata-documents-document.h>
#include <gdata/services/documents/gdata-documents-folder.h>
#include <gdata/services/documents/gdata-documents-upload-query.h>
diff --git a/gdata/services/documents/meson.build b/gdata/services/documents/meson.build
index a0984839..f29cbb0d 100644
--- a/gdata/services/documents/meson.build
+++ b/gdata/services/documents/meson.build
@@ -6,6 +6,8 @@ headers = files(
'gdata-documents-access-rule.h',
'gdata-documents-document.h',
'gdata-documents-drawing.h',
+ 'gdata-documents-drive.h',
+ 'gdata-documents-drive-query.h',
'gdata-documents-entry.h',
'gdata-documents-feed.h',
'gdata-documents-folder.h',
@@ -31,6 +33,8 @@ sources += files(
'gdata-documents-access-rule.c',
'gdata-documents-document.c',
'gdata-documents-drawing.c',
+ 'gdata-documents-drive.c',
+ 'gdata-documents-drive-query.c',
'gdata-documents-entry.c',
'gdata-documents-feed.c',
'gdata-documents-folder.c',
diff --git a/gdata/symbol.map b/gdata/symbol.map
index f8ab89c4..9b9c8de1 100644
--- a/gdata/symbol.map
+++ b/gdata/symbol.map
@@ -310,6 +310,10 @@ global:
gdata_documents_document_new;
gdata_documents_drawing_get_type;
gdata_documents_drawing_new;
+ gdata_documents_drive_get_type;
+ gdata_documents_drive_get_name;
+ gdata_documents_drive_query_get_type;
+ gdata_documents_drive_query_new;
gdata_documents_entry_add_documents_property;
gdata_documents_entry_get_document_id;
gdata_documents_entry_get_document_properties;
@@ -325,6 +329,8 @@ global:
gdata_documents_entry_remove_documents_property;
gdata_documents_entry_set_writers_can_invite;
gdata_documents_entry_writers_can_invite;
+ gdata_documents_entry_get_shared_with_me_date;
+ gdata_documents_entry_can_edit;
gdata_documents_feed_get_type;
gdata_documents_folder_get_type;
gdata_documents_folder_new;
@@ -378,6 +384,8 @@ global:
gdata_documents_service_new;
gdata_documents_service_query_documents;
gdata_documents_service_query_documents_async;
+ gdata_documents_service_query_drives;
+ gdata_documents_service_query_drives_async;
gdata_documents_service_remove_entry_from_folder;
gdata_documents_service_remove_entry_from_folder_async;
gdata_documents_service_remove_entry_from_folder_finish;