Commit 0f63d2d3 authored by Philip Withnall's avatar Philip Withnall

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
parent c04a3fa9
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -193,6 +193,68 @@ gdata_documents_service_query_documents (GDataDocumentsService *self, GDataDocum
GDATA_TYPE_DOCUMENTS_ENTRY, cancellable, progress_callback, progress_user_data, error));
}
/**
* 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
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment