[libgdata] documents: Fix the API of the document upload methods



commit c5954219e84d94ee70cbde9390ed2f0da8d20893
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Dec 9 15:25:30 2010 +0000

    documents: Fix the API of the document upload methods
    
    Since the upload methods are now only for uploading documents with data,
    they should no longer be used to insert folders
    (gdata_service_insert_entry() should be used instead). Consequently, they
    can accept the more specific GDataDocumentsDocument rather than
    GDataDocumentsEntry.
    
    This changes the API of the following methods (again):
     â?¢ gdata_documents_service_upload_document()
     â?¢ gdata_documents_service_update_document()
     â?¢ gdata_documents_service_finish_upload()

 .../services/documents/gdata-documents-document.h  |    3 +-
 gdata/services/documents/gdata-documents-service.c |   34 +++++++-------
 gdata/services/documents/gdata-documents-service.h |    9 ++--
 gdata/tests/documents.c                            |   49 +++++++++++---------
 4 files changed, 51 insertions(+), 44 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-document.h b/gdata/services/documents/gdata-documents-document.h
index b52a980..1493d3e 100644
--- a/gdata/services/documents/gdata-documents-document.h
+++ b/gdata/services/documents/gdata-documents-document.h
@@ -25,7 +25,6 @@
 
 #include <gdata/gdata-download-stream.h>
 #include <gdata/services/documents/gdata-documents-entry.h>
-#include <gdata/services/documents/gdata-documents-service.h>
 
 G_BEGIN_DECLS
 
@@ -64,6 +63,8 @@ typedef struct {
 
 GType gdata_documents_document_get_type (void) G_GNUC_CONST;
 
+#include <gdata/services/documents/gdata-documents-service.h>
+
 GDataDownloadStream *gdata_documents_document_download (GDataDocumentsDocument *self, GDataDocumentsService *service, const gchar *export_format,
                                                         GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
 gchar *gdata_documents_document_get_download_uri (GDataDocumentsDocument *self, const gchar *export_format) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
diff --git a/gdata/services/documents/gdata-documents-service.c b/gdata/services/documents/gdata-documents-service.c
index 06e39a3..55ab24c 100644
--- a/gdata/services/documents/gdata-documents-service.c
+++ b/gdata/services/documents/gdata-documents-service.c
@@ -290,8 +290,8 @@ notify_proxy_uri_cb (GObject *service, GParamSpec *pspec, GObject *self)
 }
 
 static GDataUploadStream *
-upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *document, const gchar *slug, const gchar *content_type, const gchar *method,
-                        const gchar *upload_uri)
+upload_update_document (GDataDocumentsService *self, GDataDocumentsDocument *document, const gchar *slug, const gchar *content_type,
+                        const gchar *method, const gchar *upload_uri)
 {
 	/* Corrects a bug on spreadsheet content types handling
 	 * The content type for ODF spreadsheets is "application/vnd.oasis.opendocument.spreadsheet" for my ODF spreadsheet;
@@ -308,7 +308,7 @@ upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *docume
 /**
  * gdata_documents_service_upload_document:
  * @self: an authenticated #GDataDocumentsService
- * @document: (allow-none): the #GDataDocumentsEntry to insert, or %NULL
+ * @document: (allow-none): the #GDataDocumentsDocument to insert, or %NULL
  * @slug: the filename to give to the uploaded document
  * @content_type: the content type of the uploaded data
  * @folder: (allow-none): the folder to which the document should be uploaded, or %NULL
@@ -322,7 +322,7 @@ upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *docume
  *
  * The stream returned by this function should be written to using the standard #GOutputStream methods, asychronously or synchronously. Once the stream
  * is closed (using g_output_stream_close()), gdata_documents_service_finish_upload() should be called on it to parse and return the updated
- * #GDataDocumentEntry for the document. This must be done, as @document isn't updated in-place.
+ * #GDataDocumentsDocument for the document. This must be done, as @document isn't updated in-place.
  *
  * Any upload errors will be thrown by the stream methods, and may come from the #GDataServiceError domain.
  *
@@ -331,14 +331,14 @@ upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *docume
  * Since: 0.8.0
  **/
 GDataUploadStream *
-gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocumentsEntry *document, const gchar *slug, const gchar *content_type,
+gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocumentsDocument *document, const gchar *slug, const gchar *content_type,
                                          GDataDocumentsFolder *folder, GError **error)
 {
 	GDataUploadStream *upload_stream;
 	gchar *upload_uri;
 
 	g_return_val_if_fail (GDATA_IS_DOCUMENTS_SERVICE (self), NULL);
-	g_return_val_if_fail (document == NULL || GDATA_IS_DOCUMENTS_ENTRY (document), NULL);
+	g_return_val_if_fail (document == NULL || GDATA_IS_DOCUMENTS_DOCUMENT (document), NULL);
 	g_return_val_if_fail (slug != NULL && *slug != '\0', NULL);
 	g_return_val_if_fail (content_type != NULL && *content_type != '\0', NULL);
 	g_return_val_if_fail (folder == NULL || GDATA_IS_DOCUMENTS_FOLDER (folder), NULL);
@@ -366,7 +366,7 @@ gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocum
 /**
  * gdata_documents_service_update_document:
  * @self: a #GDataDocumentsService
- * @document: the #GDataDocumentsEntry to update
+ * @document: the #GDataDocumentsDocument to update
  * @slug: the filename to give to the uploaded document
  * @content_type: the content type of the uploaded data
  * @error: a #GError, or %NULL
@@ -376,7 +376,7 @@ gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocum
  *
  * The stream returned by this function should be written to using the standard #GOutputStream methods, asychronously or synchronously. Once the stream
  * is closed (using g_output_stream_close()), gdata_documents_service_finish_upload() should be called on it to parse and return the updated
- * #GDataDocumentEntry for the document. This must be done, as @document isn't updated in-place.
+ * #GDataDocumentsDocument for the document. This must be done, as @document isn't updated in-place.
  *
  * Any upload errors will be thrown by the stream methods, and may come from the #GDataServiceError domain.
  *
@@ -387,13 +387,13 @@ gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocum
  * Since: 0.8.0
  **/
 GDataUploadStream *
-gdata_documents_service_update_document (GDataDocumentsService *self, GDataDocumentsEntry *document, const gchar *slug, const gchar *content_type,
+gdata_documents_service_update_document (GDataDocumentsService *self, GDataDocumentsDocument *document, const gchar *slug, const gchar *content_type,
                                          GError **error)
 {
 	GDataLink *update_link;
 
 	g_return_val_if_fail (GDATA_IS_DOCUMENTS_SERVICE (self), NULL);
-	g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (document), NULL);
+	g_return_val_if_fail (GDATA_IS_DOCUMENTS_DOCUMENT (document), NULL);
 	g_return_val_if_fail (slug != NULL && *slug != '\0', NULL);
 	g_return_val_if_fail (content_type != NULL && *content_type != '\0', NULL);
 	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -417,21 +417,21 @@ gdata_documents_service_update_document (GDataDocumentsService *self, GDataDocum
  * @error: a #GError, or %NULL
  *
  * Finish off a document upload or update operation started by gdata_documents_service_upload_document() or gdata_documents_service_update_document(),
- * parsing the result and returning the new or updated #GDataDocumentsEntry.
+ * parsing the result and returning the new or updated #GDataDocumentsDocument.
  *
  * If an error occurred during the upload or update operation, it will have been returned during the operation (e.g. by g_output_stream_splice() or one
  * of the other stream methods). In such a case, %NULL will be returned but @error will remain unset. @error is only set in the case that the server
  * indicates that the operation was successful, but an error is encountered in parsing the result sent by the server.
  *
- * In the case that no #GDataDocumentsEntry was passed (to gdata_documents_service_upload_document() or gdata_documents_service_update_document()) when
- * starting the operation, %GDATA_DOCUMENTS_SERVICE_ERROR_INVALID_CONTENT_TYPE will be thrown in @error if the content type of the uploaded data
+ * In the case that no #GDataDocumentsDocument was passed (to gdata_documents_service_upload_document() or gdata_documents_service_update_document())
+ * when starting the operation, %GDATA_DOCUMENTS_SERVICE_ERROR_INVALID_CONTENT_TYPE will be thrown in @error if the content type of the uploaded data
  * could not be mapped to a document type with which to interpret the response from the server.
  *
- * Return value: (transfer full): the new or updated #GDataDocumentsEntry, or %NULL; unref with g_object_unref()
+ * Return value: (transfer full): the new or updated #GDataDocumentsDocument, or %NULL; unref with g_object_unref()
  *
  * Since: 0.8.0
  */
-GDataDocumentsEntry *
+GDataDocumentsDocument *
 gdata_documents_service_finish_upload (GDataDocumentsService *self, GDataUploadStream *upload_stream, GError **error)
 {
 	const gchar *response_body, *content_type;
@@ -461,7 +461,7 @@ gdata_documents_service_finish_upload (GDataDocumentsService *self, GDataUploadS
 		new_document_type = GDATA_TYPE_DOCUMENTS_PRESENTATION;
 	}
 
-	if (g_type_is_a (new_document_type, GDATA_TYPE_ENTRY) == FALSE) {
+	if (g_type_is_a (new_document_type, GDATA_TYPE_DOCUMENTS_DOCUMENT) == FALSE) {
 		g_set_error (error, GDATA_DOCUMENTS_SERVICE_ERROR, GDATA_DOCUMENTS_SERVICE_ERROR_INVALID_CONTENT_TYPE,
 		             _("The content type of the supplied document ('%s') could not be recognized."), content_type);
 		return NULL;
@@ -472,7 +472,7 @@ gdata_documents_service_finish_upload (GDataDocumentsService *self, GDataUploadS
 	if (response_body == NULL || response_length == 0)
 		return NULL;
 
-	return GDATA_DOCUMENTS_ENTRY (gdata_parsable_new_from_xml (new_document_type, response_body, (gint) response_length, error));
+	return GDATA_DOCUMENTS_DOCUMENT (gdata_parsable_new_from_xml (new_document_type, response_body, (gint) response_length, error));
 }
 
 /**
diff --git a/gdata/services/documents/gdata-documents-service.h b/gdata/services/documents/gdata-documents-service.h
index 78bfc46..0befc1e 100644
--- a/gdata/services/documents/gdata-documents-service.h
+++ b/gdata/services/documents/gdata-documents-service.h
@@ -88,15 +88,16 @@ void gdata_documents_service_query_documents_async (GDataDocumentsService *self,
                                                     GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
                                                     GAsyncReadyCallback callback, gpointer user_data);
 
+#include <gdata/services/documents/gdata-documents-document.h>
 #include <gdata/services/documents/gdata-documents-folder.h>
 
-GDataUploadStream *gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocumentsEntry *document, const gchar *slug,
+GDataUploadStream *gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocumentsDocument *document, const gchar *slug,
                                                             const gchar *content_type, GDataDocumentsFolder *folder,
                                                             GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
-GDataUploadStream *gdata_documents_service_update_document (GDataDocumentsService *self, GDataDocumentsEntry *document, const gchar *slug,
+GDataUploadStream *gdata_documents_service_update_document (GDataDocumentsService *self, GDataDocumentsDocument *document, const gchar *slug,
                                                             const gchar *content_type, GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
-GDataDocumentsEntry *gdata_documents_service_finish_upload (GDataDocumentsService *self, GDataUploadStream *upload_stream,
-                                                            GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+GDataDocumentsDocument *gdata_documents_service_finish_upload (GDataDocumentsService *self, GDataUploadStream *upload_stream,
+                                                               GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
 
 GDataDocumentsEntry *gdata_documents_service_move_document_to_folder (GDataDocumentsService *self, GDataDocumentsEntry *document,
                                                                       GDataDocumentsFolder *folder, GCancellable *cancellable,
diff --git a/gdata/tests/documents.c b/gdata/tests/documents.c
index 30cf762..b7b46a8 100644
--- a/gdata/tests/documents.c
+++ b/gdata/tests/documents.c
@@ -26,7 +26,7 @@
 #include "common.h"
 
 static gboolean
-check_document_is_in_folder (GDataDocumentsEntry *document, GDataDocumentsFolder *folder)
+check_document_is_in_folder (GDataDocumentsDocument *document, GDataDocumentsFolder *folder)
 {
 	GList *categories;
 	gboolean found_folder_category = FALSE;
@@ -208,7 +208,7 @@ test_upload_metadata (gconstpointer service)
 static void
 test_upload_metadata_file (gconstpointer service)
 {
-	GDataDocumentsEntry *document, *new_document;
+	GDataDocumentsDocument *document, *new_document;
 	GFile *document_file;
 	GFileInfo *file_info;
 	GDataUploadStream *upload_stream;
@@ -222,7 +222,7 @@ test_upload_metadata_file (gconstpointer service)
 	                               G_FILE_QUERY_INFO_NONE, NULL, &error);
 	g_assert_no_error (error);
 
-	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
+	document = GDATA_DOCUMENTS_DOCUMENT (gdata_documents_text_new (NULL));
 	gdata_entry_set_title (GDATA_ENTRY (document), "upload_metadata_file");
 
 	/* Prepare the upload stream */
@@ -261,7 +261,7 @@ test_upload_metadata_file (gconstpointer service)
 static void
 test_upload_file_get_entry (gconstpointer service)
 {
-	GDataDocumentsEntry *new_document;
+	GDataDocumentsDocument *new_document;
 	GDataEntry *new_presentation;
 	GDataUploadStream *upload_stream;
 	GFileInputStream *file_stream;
@@ -320,7 +320,7 @@ test_upload_file_get_entry (gconstpointer service)
 static void
 test_add_remove_file_from_folder (gconstpointer service)
 {
-	GDataDocumentsEntry *document, *new_document, *new_document2;
+	GDataDocumentsDocument *document, *new_document, *new_document2;
 	GDataDocumentsFolder *folder, *new_folder;
 	GDataUploadStream *upload_stream;
 	GFile *document_file;
@@ -349,7 +349,7 @@ test_add_remove_file_from_folder (gconstpointer service)
 
 	/* Prepare the file */
 	document_file = g_file_new_for_path (TEST_FILE_DIR "test.ppt");
-	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_presentation_new (NULL));
+	document = GDATA_DOCUMENTS_DOCUMENT (gdata_documents_presentation_new (NULL));
 	gdata_entry_set_title (GDATA_ENTRY (document), "add_remove_from_folder_presentation");
 
 	file_info = g_file_query_info (document_file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -388,7 +388,9 @@ test_add_remove_file_from_folder (gconstpointer service)
 	g_assert (check_document_is_in_folder (new_document, new_folder) == TRUE);
 
 	/* Remove the document from the folder */
-	new_document2 = gdata_documents_service_remove_document_from_folder (GDATA_DOCUMENTS_SERVICE (service), new_document, new_folder, NULL, &error);
+	new_document2 = GDATA_DOCUMENTS_DOCUMENT (gdata_documents_service_remove_document_from_folder (GDATA_DOCUMENTS_SERVICE (service),
+	                                                                                               GDATA_DOCUMENTS_ENTRY (new_document),
+	                                                                                               new_folder, NULL, &error));
 	g_assert_no_error (error);
 	g_assert (GDATA_IS_DOCUMENTS_PRESENTATION (new_document2));
 
@@ -406,7 +408,7 @@ test_add_remove_file_from_folder (gconstpointer service)
 static void
 test_add_file_folder_and_move (gconstpointer service)
 {
-	GDataDocumentsEntry *document, *new_document, *new_document2;
+	GDataDocumentsDocument *document, *new_document, *new_document2;
 	GDataDocumentsFolder *folder, *new_folder;
 	GDataUploadStream *upload_stream;
 	GFileInputStream *file_stream;
@@ -435,7 +437,7 @@ test_add_file_folder_and_move (gconstpointer service)
 
 	/* Prepare the file */
 	document_file = g_file_new_for_path (TEST_FILE_DIR "test.odt");
-	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
+	document = GDATA_DOCUMENTS_DOCUMENT (gdata_documents_text_new (NULL));
 	gdata_entry_set_title (GDATA_ENTRY (document), "add_file_folder_move_text");
 
 	file_info = g_file_query_info (document_file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -474,7 +476,9 @@ test_add_file_folder_and_move (gconstpointer service)
 	g_assert (check_document_is_in_folder (new_document, new_folder) == FALSE);
 
 	/* Move the document from the folder */
-	new_document2 = gdata_documents_service_move_document_to_folder (GDATA_DOCUMENTS_SERVICE (service), new_document, new_folder, NULL, &error);
+	new_document2 = GDATA_DOCUMENTS_DOCUMENT (gdata_documents_service_move_document_to_folder (GDATA_DOCUMENTS_SERVICE (service),
+	                                                                                           GDATA_DOCUMENTS_ENTRY (new_document),
+	                                                                                           new_folder, NULL, &error));
 	g_assert_no_error (error);
 	g_assert (GDATA_IS_DOCUMENTS_TEXT (new_document2));
 
@@ -492,7 +496,7 @@ test_add_file_folder_and_move (gconstpointer service)
 static void
 test_upload_file_metadata_in_new_folder (gconstpointer service)
 {
-	GDataDocumentsEntry *document, *new_document;
+	GDataDocumentsDocument *document, *new_document;
 	GDataDocumentsFolder *folder, *new_folder;
 	GDataUploadStream *upload_stream;
 	GFileInputStream *file_stream;
@@ -518,7 +522,7 @@ test_upload_file_metadata_in_new_folder (gconstpointer service)
 
 	/* Prepare the file */
 	document_file = g_file_new_for_path (TEST_FILE_DIR "test.odt");
-	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
+	document = GDATA_DOCUMENTS_DOCUMENT (gdata_documents_text_new (NULL));
 	gdata_entry_set_title (GDATA_ENTRY (document), "upload_file_metadata_in_new_folder_text");
 
 	file_info = g_file_query_info (document_file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -613,7 +617,7 @@ test_update_metadata (gconstpointer service)
 static void
 test_update_metadata_file (gconstpointer service)
 {
-	GDataDocumentsEntry *document, *new_document, *new_document2, *updated_document;
+	GDataDocumentsDocument *document, *new_document, *new_document2, *updated_document;
 	GDataUploadStream *upload_stream;
 	GFileInputStream *file_stream;
 	GFile *updated_document_file;
@@ -623,12 +627,13 @@ test_update_metadata_file (gconstpointer service)
 
 	g_assert (service != NULL);
 
-	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
+	document = GDATA_DOCUMENTS_DOCUMENT (gdata_documents_text_new (NULL));
 	gdata_entry_set_title (GDATA_ENTRY (document), "update_metadata_file_first_title");
 
 	/* Insert the document's metadata */
 	upload_uri = gdata_documents_service_get_upload_uri (NULL);
-	new_document = GDATA_DOCUMENTS_ENTRY (gdata_service_insert_entry (GDATA_SERVICE (service), upload_uri, GDATA_ENTRY (document), NULL, &error));
+	new_document = GDATA_DOCUMENTS_DOCUMENT (gdata_service_insert_entry (GDATA_SERVICE (service), upload_uri, GDATA_ENTRY (document), NULL,
+	                                                                     &error));
 	g_free (upload_uri);
 	g_assert_no_error (error);
 	g_assert (GDATA_IS_DOCUMENTS_TEXT (new_document));
@@ -639,9 +644,9 @@ test_update_metadata_file (gconstpointer service)
 	 * creating the document: http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=2337. We have to wait a few seconds before
 	 * trying this to allow the various Google servers to catch up with each other. */
 	g_usleep (5 * G_USEC_PER_SEC);
-	new_document2 = GDATA_DOCUMENTS_ENTRY (gdata_service_query_single_entry (GDATA_SERVICE (service),
-	                                                                         gdata_entry_get_id (GDATA_ENTRY (new_document)), NULL,
-	                                                                         GDATA_TYPE_DOCUMENTS_TEXT, NULL, &error));
+	new_document2 = GDATA_DOCUMENTS_DOCUMENT (gdata_service_query_single_entry (GDATA_SERVICE (service),
+	                                                                            gdata_entry_get_id (GDATA_ENTRY (new_document)), NULL,
+	                                                                            GDATA_TYPE_DOCUMENTS_TEXT, NULL, &error));
 
 	g_object_unref (new_document);
 
@@ -694,7 +699,7 @@ test_update_metadata_file (gconstpointer service)
 static void
 test_update_file (gconstpointer service)
 {
-	GDataDocumentsEntry *new_document, *new_document2, *updated_document;
+	GDataDocumentsDocument *new_document, *new_document2, *updated_document;
 	GDataUploadStream *upload_stream;
 	GFileInputStream *file_stream;
 	GFile *document_file;
@@ -743,9 +748,9 @@ test_update_file (gconstpointer service)
 	 * creating the document: http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=2337. We have to wait a few seconds before
 	 * trying this to allow the various Google servers to catch up with each other. */
 	g_usleep (5 * G_USEC_PER_SEC);
-	new_document2 = GDATA_DOCUMENTS_ENTRY (gdata_service_query_single_entry (GDATA_SERVICE (service),
-	                                                                         gdata_entry_get_id (GDATA_ENTRY (new_document)), NULL,
-	                                                                         GDATA_TYPE_DOCUMENTS_PRESENTATION, NULL, &error));
+	new_document2 = GDATA_DOCUMENTS_DOCUMENT (gdata_service_query_single_entry (GDATA_SERVICE (service),
+	                                                                            gdata_entry_get_id (GDATA_ENTRY (new_document)), NULL,
+	                                                                            GDATA_TYPE_DOCUMENTS_PRESENTATION, NULL, &error));
 
 	g_object_unref (new_document);
 



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