[libgdata] Bug 590341 – Allow querying of single documents
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgdata] Bug 590341 – Allow querying of single documents
- Date: Sun, 2 Aug 2009 17:25:27 +0000 (UTC)
commit 0f63d2d39d5514bcbd53002a5496a773b2f5cf40
Author: Philip Withnall <philip tecnocode co uk>
Date: Sun Aug 2 18:24:01 2009 +0100
Bug 590341 â?? Allow querying of single documents
Patch from Thibault Saunier <saunierthibault gmail com> to allow querying of
single documents from the Google Documents backend. Closes: bgo#590341
docs/reference/gdata-sections.txt | 1 +
gdata/gdata.symbols | 1 +
gdata/services/documents/gdata-documents-query.c | 12 ++++-
gdata/services/documents/gdata-documents-service.c | 62 ++++++++++++++++++++
gdata/services/documents/gdata-documents-service.h | 2 +
gdata/tests/documents.c | 14 ++++-
6 files changed, 88 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 3a0f518..52eaa68 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -1451,6 +1451,7 @@ GDataDocumentsServiceError
gdata_documents_service_new
gdata_documents_service_query_documents
gdata_documents_service_query_documents_async
+gdata_documents_service_query_single_document
gdata_documents_service_upload_document
gdata_documents_service_update_document
gdata_documents_service_move_document_to_folder
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index d197e05..14fb11e 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -596,6 +596,7 @@ gdata_documents_folder_new
gdata_documents_service_get_type
gdata_documents_service_new
gdata_documents_service_query_documents
+gdata_documents_service_query_single_document
gdata_documents_service_query_documents_async
gdata_documents_service_upload_document
gdata_documents_service_update_document
diff --git a/gdata/services/documents/gdata-documents-query.c b/gdata/services/documents/gdata-documents-query.c
index 55f5275..df6baf5 100644
--- a/gdata/services/documents/gdata-documents-query.c
+++ b/gdata/services/documents/gdata-documents-query.c
@@ -39,6 +39,11 @@
#include "gdata-documents-query.h"
#include "gdata-query.h"
+#include <gdata/services/documents/gdata-documents-spreadsheet.h>
+#include <gdata/services/documents/gdata-documents-presentation.h>
+#include <gdata/services/documents/gdata-documents-text.h>
+#include <gdata/services/documents/gdata-documents-folder.h>
+
static void gdata_documents_query_finalize (GObject *object);
static void gdata_documents_query_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void gdata_documents_query_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
@@ -223,10 +228,11 @@ static void
get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboolean *params_started)
{
GDataDocumentsQueryPrivate *priv = GDATA_DOCUMENTS_QUERY (self)->priv;
+ const gchar *entry_id = gdata_query_get_entry_id (self);
#define APPEND_SEP g_string_append_c (query_uri, (*params_started == FALSE) ? '?' : '&'); *params_started = TRUE;
- if (priv->folder_id != NULL) {
+ if (entry_id == NULL && priv->folder_id != NULL) {
g_string_append (query_uri, "/folder%%3A");
g_string_append_uri_escaped (query_uri, priv->folder_id, NULL, TRUE);
}
@@ -234,6 +240,10 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
/* Chain up to the parent class */
GDATA_QUERY_CLASS (gdata_documents_query_parent_class)->get_query_uri (self, feed_uri, query_uri, params_started);
+ /* Return if the entry ID has been set, since that's handled in the parent class' get_query_uri() function */
+ if (entry_id != NULL)
+ return;
+
if (priv->collaborator_addresses != NULL) {
GList *collaborator_address;
APPEND_SEP
diff --git a/gdata/services/documents/gdata-documents-service.c b/gdata/services/documents/gdata-documents-service.c
index 92aa5d8..2155d44 100644
--- a/gdata/services/documents/gdata-documents-service.c
+++ b/gdata/services/documents/gdata-documents-service.c
@@ -194,6 +194,68 @@ gdata_documents_service_query_documents (GDataDocumentsService *self, GDataDocum
}
/**
+ * gdata_documents_service_query_single_document:
+ * @self: a #GDataDocumentsService
+ * @document_type: the expected #GType of the queried entry
+ * @document_id: the document ID of the queried document
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: a #GError, or %NULL
+ *
+ * Retrieves information about a single document with the given document ID.
+ *
+ * @document_type should be the expected type of the document to be returned. e.g. %GDATA_TYPE_DOCUMENTS_SPREADSHEET if you're querying
+ * for a spreadsheet.
+ *
+ * @document_id should be the ID of the document as returned by gdata_document_entry_get_document_id().
+ *
+ * Parameters and errors are as for gdata_service_query().
+ *
+ * Return value: a #GDataDocumentsEntry, or %NULL; unref with g_object_unref()
+ *
+ * Since: 0.5.0
+ **/
+GDataDocumentsEntry *
+gdata_documents_service_query_single_document (GDataDocumentsService *self, GType document_type, const gchar *document_id,
+ GCancellable *cancellable, GError **error)
+{
+ GDataDocumentsEntry *document;
+ SoupMessage *message;
+ GDataDocumentsQuery *query;
+ gchar *resource_id;
+
+ g_return_val_if_fail (GDATA_IS_DOCUMENTS_SERVICE (self), NULL);
+
+ if (document_type == GDATA_TYPE_DOCUMENTS_FOLDER)
+ resource_id = g_strconcat ("folder:", document_id, NULL);
+ else if (document_type == GDATA_TYPE_DOCUMENTS_SPREADSHEET)
+ resource_id = g_strconcat ("spreasheet:", document_id, NULL);
+ else if (document_type == GDATA_TYPE_DOCUMENTS_TEXT)
+ resource_id = g_strconcat ("document:", document_id, NULL);
+ else if (document_type == GDATA_TYPE_DOCUMENTS_PRESENTATION)
+ resource_id = g_strconcat ("presentation:", document_id, NULL);
+ else
+ g_assert_not_reached ();
+
+ query = gdata_documents_query_new (NULL);
+ gdata_query_set_entry_id (GDATA_QUERY (query), resource_id);
+ g_free (resource_id);
+
+ message = _gdata_service_query (GDATA_SERVICE (self), "http://docs.google.com/feeds/documents/private/full", GDATA_QUERY (query),
+ cancellable, NULL, NULL, error);
+ g_object_unref (query);
+
+ if (message == NULL)
+ return NULL;
+
+ g_assert (message->response_body->data != NULL);
+ document = GDATA_DOCUMENTS_ENTRY (gdata_parsable_new_from_xml (document_type, message->response_body->data,
+ message->response_body->length, error));
+ g_object_unref (message);
+
+ return document;
+}
+
+/**
* gdata_documents_service_query_documents_async:
* @self: a #GDataDocumentsService
* @query: a #GDataQuery with the query parameters, or %NULL
diff --git a/gdata/services/documents/gdata-documents-service.h b/gdata/services/documents/gdata-documents-service.h
index 0378b21..ed5df50 100644
--- a/gdata/services/documents/gdata-documents-service.h
+++ b/gdata/services/documents/gdata-documents-service.h
@@ -89,6 +89,8 @@ void gdata_documents_service_query_documents_async (GDataDocumentsService *self,
#include <gdata/services/documents/gdata-documents-folder.h>
+GDataDocumentsEntry *gdata_documents_service_query_single_document (GDataDocumentsService *self, GType document_type, const gchar *document_id,
+ GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT;
GDataDocumentsEntry *gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocumentsEntry *document, GFile *document_file,
GDataDocumentsFolder *folder, GCancellable *cancellable,
GError **error) G_GNUC_WARN_UNUSED_RESULT;
diff --git a/gdata/tests/documents.c b/gdata/tests/documents.c
index 9872813..345c575 100644
--- a/gdata/tests/documents.c
+++ b/gdata/tests/documents.c
@@ -201,17 +201,18 @@ test_upload_metadata_file (GDataService *service)
}
static void
-test_upload_file (GDataService *service)
+test_upload_file_get_entry (GDataService *service)
{
GDataDocumentsEntry *new_document;
+ GDataDocumentsPresentation *newly_created_presentation;
GFile *document_file;
GDataCategory *category;
+ GDataDocumentsQuery *query;
GError *error = NULL;
g_assert (service != NULL);
document_file = g_file_new_for_path (TEST_FILE_DIR "test.ppt");
-
category = gdata_category_new ("http://schemas.google.com/docs/2007#presentation", "http://schemas.google.com/g/2005#kind", "presentation");
/* Insert the document */
@@ -219,6 +220,13 @@ test_upload_file (GDataService *service)
g_assert_no_error (error);
g_assert (GDATA_IS_DOCUMENTS_PRESENTATION (new_document));
+ /* Get the entry on the server */
+ newly_created_presentation = gdata_documents_service_query_single_document (GDATA_DOCUMENTS_SERVICE (service), GDATA_TYPE_DOCUMENTS_PRESENTATION,
+ gdata_documents_entry_get_document_id (new_document), NULL, &error);
+ g_assert_no_error (error);
+ g_assert (GDATA_IS_DOCUMENTS_PRESENTATION (new_document));
+
+
g_clear_error (&error);
g_object_unref (new_document);
g_object_unref (document_file);
@@ -590,7 +598,7 @@ main (int argc, char *argv[])
g_test_add_data_func ("/documents/remove/all", service, test_remove_all_documents_and_folders);
- g_test_add_data_func ("/documents/upload/only_file", service, test_upload_file);
+ g_test_add_data_func ("/documents/upload/only_file_get_entry", service, test_upload_file_get_entry);
g_test_add_data_func ("/documents/upload/metadata_file", service, test_upload_metadata_file);
g_test_add_data_func ("/documents/upload/only_metadata", service, test_upload_metadata);
g_test_add_data_func ("/documents/upload/metadata_file_in_new_folder", service, test_upload_file_metadata_in_new_folder);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]