[libgdata] picasaweb: Add a cancellable parameter to the upload file method
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] picasaweb: Add a cancellable parameter to the upload file method
- Date: Mon, 20 Dec 2010 13:48:48 +0000 (UTC)
commit c512dd50e0c5c5561dae0ad333cf35e29ff5c1ae
Author: Philip Withnall <philip tecnocode co uk>
Date: Fri Dec 17 23:28:30 2010 +0000
picasaweb: Add a cancellable parameter to the upload file method
Add a cancellable parameter to gdata_picasaweb_service_upload_file() to mirror
GDataUploadStream:cancellable. The tests have been updated accordingly.
This breaks the following API:
â?¢ gdata_picasaweb_service_upload_file()
Helps: bgo#637036
gdata/services/picasaweb/gdata-picasaweb-service.c | 12 +++++++++---
gdata/services/picasaweb/gdata-picasaweb-service.h | 2 +-
gdata/tests/picasaweb.c | 12 ++++++------
3 files changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.c b/gdata/services/picasaweb/gdata-picasaweb-service.c
index b19e384..dacffac 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.c
@@ -79,7 +79,7 @@
*
* /<!-- -->* Create an upload stream for the file. This is non-blocking. *<!-- -->/
* upload_stream = gdata_picasaweb_service_upload_file (service, album, file_entry, g_file_info_get_display_name (file_info),
- * g_file_info_get_content_type (file_info), NULL);
+ * g_file_info_get_content_type (file_info), NULL, NULL);
* g_object_unref (file_info);
* g_object_unref (file_entry);
*
@@ -446,6 +446,7 @@ gdata_picasaweb_service_query_files_async (GDataPicasaWebService *self, GDataPic
* @file_entry: a #GDataPicasaWebFile to insert
* @slug: the filename to give to the uploaded file
* @content_type: the content type of the uploaded data
+ * @cancellable: (allow-none): a #GCancellable for the entire upload stream, or %NULL
* @error: a #GError, or %NULL
*
* Uploads a file (photo or video) to the given PicasaWeb @album, using the metadata from @file and the file data written to the resulting
@@ -459,6 +460,10 @@ gdata_picasaweb_service_query_files_async (GDataPicasaWebService *self, GDataPic
* is closed (using g_output_stream_close()), gdata_picasaweb_service_finish_file_upload() should be called on it to parse and return the updated
* #GDataPicasaWebFile for the uploaded file. This must be done, as @file_entry isn't updated in-place.
*
+ * In order to cancel the upload, a #GCancellable passed in to @cancellable must be cancelled using g_cancellable_cancel(). Cancelling the individual
+ * #GOutputStream operations on the #GDataUploadStream will not cancel the entire upload; merely the write or close operation in question. See the
+ * #GDataUploadStream:cancellable for more details.
+ *
* Any upload errors will be thrown by the stream methods, and may come from the #GDataServiceError domain.
*
* Return value: (transfer full): a #GDataUploadStream to write the file data to, or %NULL; unref with g_object_unref()
@@ -467,7 +472,7 @@ gdata_picasaweb_service_query_files_async (GDataPicasaWebService *self, GDataPic
**/
GDataUploadStream *
gdata_picasaweb_service_upload_file (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GDataPicasaWebFile *file_entry, const gchar *slug,
- const gchar *content_type, GError **error)
+ const gchar *content_type, GCancellable *cancellable, GError **error)
{
const gchar *user_id = NULL, *album_id = NULL;
GDataUploadStream *upload_stream;
@@ -478,6 +483,7 @@ gdata_picasaweb_service_upload_file (GDataPicasaWebService *self, GDataPicasaWeb
g_return_val_if_fail (GDATA_IS_PICASAWEB_FILE (file_entry), 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 (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (gdata_entry_is_inserted (GDATA_ENTRY (file_entry)) == TRUE) {
@@ -499,7 +505,7 @@ gdata_picasaweb_service_upload_file (GDataPicasaWebService *self, GDataPicasaWeb
/* Build the upload URI and upload stream */
upload_uri = _gdata_service_build_uri (TRUE, "http://picasaweb.google.com/data/feed/api/user/%s/albumid/%s", user_id, album_id);
upload_stream = GDATA_UPLOAD_STREAM (gdata_upload_stream_new (GDATA_SERVICE (self), SOUP_METHOD_POST, upload_uri, GDATA_ENTRY (file_entry),
- slug, content_type, NULL));
+ slug, content_type, cancellable));
g_free (upload_uri);
return upload_stream;
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.h b/gdata/services/picasaweb/gdata-picasaweb-service.h
index 7b3012b..ced89d8 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.h
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.h
@@ -87,7 +87,7 @@ void gdata_picasaweb_service_query_files_async (GDataPicasaWebService *self, GDa
#include <gdata/services/picasaweb/gdata-picasaweb-file.h>
GDataUploadStream *gdata_picasaweb_service_upload_file (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GDataPicasaWebFile *file_entry,
- const gchar *slug, const gchar *content_type,
+ const gchar *slug, const gchar *content_type, GCancellable *cancellable,
GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
GDataPicasaWebFile *gdata_picasaweb_service_finish_file_upload (GDataPicasaWebService *self, GDataUploadStream *upload_stream,
GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index b027f33..cf12fe2 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -1075,7 +1075,7 @@ test_upload_default_album (UploadData *data, gconstpointer service)
/* Prepare the upload stream */
/* TODO right now, it will just go to the default album, we want an uploading one :| */
upload_stream = gdata_picasaweb_service_upload_file (GDATA_PICASAWEB_SERVICE (service), NULL, data->photo, data->slug, data->content_type,
- &error);
+ NULL, &error);
g_assert_no_error (error);
g_assert (GDATA_IS_UPLOAD_STREAM (upload_stream));
@@ -1162,7 +1162,7 @@ test_upload_default_album_async (UploadAsyncData *data, gconstpointer service)
/* Prepare the upload stream */
upload_stream = gdata_picasaweb_service_upload_file (GDATA_PICASAWEB_SERVICE (service), NULL, data->data.photo, data->data.slug,
- data->data.content_type, &error);
+ data->data.content_type, NULL, &error);
g_assert_no_error (error);
g_assert (GDATA_IS_UPLOAD_STREAM (upload_stream));
@@ -1215,13 +1215,13 @@ test_upload_default_album_cancellation (UploadAsyncData *data, gconstpointer ser
/* Prepare the upload stream */
upload_stream = gdata_picasaweb_service_upload_file (GDATA_PICASAWEB_SERVICE (service), NULL, data->data.photo, data->data.slug,
- data->data.content_type, &error);
+ data->data.content_type, cancellable, &error);
g_assert_no_error (error);
g_assert (GDATA_IS_UPLOAD_STREAM (upload_stream));
/* Upload the photo asynchronously */
g_output_stream_splice_async (G_OUTPUT_STREAM (upload_stream), G_INPUT_STREAM (data->data.file_stream),
- G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, G_PRIORITY_DEFAULT, cancellable,
+ G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, G_PRIORITY_DEFAULT, NULL,
(GAsyncReadyCallback) test_upload_default_album_cancellation_cb, data);
g_main_loop_run (data->main_loop);
@@ -1242,13 +1242,13 @@ test_upload_default_album_cancellation2 (UploadAsyncData *data, gconstpointer se
/* Prepare the upload stream */
upload_stream = gdata_picasaweb_service_upload_file (GDATA_PICASAWEB_SERVICE (service), NULL, data->data.photo, data->data.slug,
- data->data.content_type, &error);
+ data->data.content_type, cancellable, &error);
g_assert_no_error (error);
g_assert (GDATA_IS_UPLOAD_STREAM (upload_stream));
/* Upload the photo asynchronously */
g_output_stream_splice_async (G_OUTPUT_STREAM (upload_stream), G_INPUT_STREAM (data->data.file_stream),
- G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, G_PRIORITY_DEFAULT, cancellable,
+ G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, G_PRIORITY_DEFAULT, NULL,
(GAsyncReadyCallback) test_upload_default_album_cancellation_cb, data);
g_main_loop_run (data->main_loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]