[libgdata/wip/oholy/documents-shared-drives-support: 1/3] documents: Add Shared Drives support




commit ccffea9faed509228c4d084b343c84d9220b9687
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Jan 20 09:38:50 2021 +0100

    documents: Add Shared Drives support
    
    It seems that the existing documents APIs works nicely with the files
    on Shared Drives (formerly Team Drives), although it is possible that
    some small changes will be needed to handle differences:
    https://developers.google.com/drive/api/v2/shared-drives-diffs
    
    However, the main problem is that there is no way currently to get the
    list of Shared Drives IDs and their names. Let's add new APIs for it
    which will be consequently used by GVfs.
    
    Relates: https://gitlab.gnome.org/GNOME/gvfs/-/issues/377
    Fixes: https://gitlab.gnome.org/GNOME/libgdata/-/issues/25

 docs/reference/gdata-sections.txt.in               |  38 ++++++
 gdata/gdata-core.symbols                           |   6 +
 gdata/gdata-query.h                                |   1 +
 gdata/gdata.h                                      |   2 +
 .../documents/gdata-documents-drive-query.c        |  98 ++++++++++++++
 .../documents/gdata-documents-drive-query.h        |  55 ++++++++
 gdata/services/documents/gdata-documents-drive.c   | 145 +++++++++++++++++++++
 gdata/services/documents/gdata-documents-drive.h   |  55 ++++++++
 gdata/services/documents/gdata-documents-entry.c   |   2 +-
 gdata/services/documents/gdata-documents-feed.c    |   3 +
 gdata/services/documents/gdata-documents-query.c   |   5 +
 gdata/services/documents/gdata-documents-service.c | 100 ++++++++++++++
 gdata/services/documents/gdata-documents-service.h |   9 ++
 gdata/services/documents/meson.build               |   4 +
 gdata/symbol.map                                   |   6 +
 15 files changed, 528 insertions(+), 1 deletion(-)
---
diff --git a/docs/reference/gdata-sections.txt.in b/docs/reference/gdata-sections.txt.in
index e159b00b..ca562bc8 100644
--- a/docs/reference/gdata-sections.txt.in
+++ b/docs/reference/gdata-sections.txt.in
@@ -1817,6 +1817,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
@@ -1865,6 +1867,42 @@ GDATA_TYPE_DOCUMENTS_METADATA
 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>
diff --git a/gdata/gdata-core.symbols b/gdata/gdata-core.symbols
index 29e94fdb..d742e535 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
@@ -669,6 +671,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..770a449b
--- /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 
<ulink type="http"
+ * url="https://developers.google.com/drive/api/v2/ref-search-terms#drive_properties";>online 
documentation</ulink>.
+ *
+ * Since: UNRELEASED
+ */
+
+#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: UNRELEASED
+ */
+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..ab0f003a
--- /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: UNRELEASED
+ */
+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..aaa88f3d
--- /dev/null
+++ b/gdata/services/documents/gdata-documents-drive.c
@@ -0,0 +1,145 @@
+/* -*- 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
+ * <ulink type="http" url="https://developers.google.com/drive/v2/web/about-sdk";>online 
documentation</ulink>.
+ *
+ * Since: UNRELEASED
+ */
+
+#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: UNRELEASED
+        */
+       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 human-readable drives's name, or %NULL
+ *
+ * Since: UNRELEASED
+ */
+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..6a9938f5
--- /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: UNRELEASED
+ */
+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..07a86386 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -1058,7 +1058,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);
 }
 
 /**
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..8c56e24a 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,105 @@ 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: UNRELEASED
+ */
+GDataDocumentsFeed *
+gdata_documents_service_query_drives (GDataDocumentsService *self, GDataDocumentsDriveQuery *query, 
GCancellable *cancellable,
+                                      GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data,
+                                      GError **error)
+{
+       GDataFeed *feed;
+       gchar *request_uri;
+
+       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;
+       }
+
+       request_uri = g_strdup ("https://www.googleapis.com/drive/v2/drives";);
+       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);
+       g_free (request_uri);
+
+       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: UNRELEASED
+ */
+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)
+{
+       gchar *request_uri;
+
+       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;
+       }
+
+       request_uri = g_strdup ("https://www.googleapis.com/drive/v2/drives";);
+       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);
+       g_free (request_uri);
+}
+
 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..15e58a7b 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;
@@ -378,6 +382,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;


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