summaryrefslogtreecommitdiff
path: root/gdata/media
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2010-12-10 15:29:58 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2010-12-10 16:27:32 +0000
commit8c6c28dca3cbd84759f7933e8fc29aec0a5eb4ac (patch)
treec320d50ef182027c8d8ef0fa9f3fb7738a2d50fe /gdata/media
parentbee6e510abd2cb63341028d30c59f0f2f374b2dd (diff)
downloadlibgdata-8c6c28dca3cbd84759f7933e8fc29aec0a5eb4ac.tar.gz
media: Switch GDataMediaContent to a stream-based download API
Downloading to a file provided by its path was unnecessarily limiting, forcing downloads to be made directly to disk instead of (e.g.) another network stream, and subjecting clients to libgdata's idea of “Replace this File?” logic. It's not much extra code for the clients to handle this themselves, and offers much greater flexibility. We also get async support for free, as creating the GDataDownloadStream is a cheap operation, and it already has async support. This updates the test suite appropriately. This is an API break which affects: • gdata_media_content_download() Helps: bgo#633363
Diffstat (limited to 'gdata/media')
-rw-r--r--gdata/media/gdata-media-content.c50
-rw-r--r--gdata/media/gdata-media-content.h6
2 files changed, 14 insertions, 42 deletions
diff --git a/gdata/media/gdata-media-content.c b/gdata/media/gdata-media-content.c
index 89c336f6..7f720ee8 100644
--- a/gdata/media/gdata-media-content.c
+++ b/gdata/media/gdata-media-content.c
@@ -538,58 +538,30 @@ gdata_media_content_get_width (GDataMediaContent *self)
* gdata_media_content_download:
* @self: a #GDataMediaContent
* @service: the #GDataService
- * @default_filename: a default filename used if the user selects a directory as the destination
- * @target_dest_file: the destination file or directory to download to
- * @replace_file_if_exists: whether to replace already existing files at the download location
- * @cancellable: optional #GCancellable object, or %NULL
* @error: a #GError, or %NULL
*
- * Downloads and returns a #GFile of the content represented by @self.
+ * Downloads and returns a #GDataDownloadStream allowing the content represented by @self to be read.
*
- * If @target_dest_file is a directory, then the file will be
- * downloaded into this directory with the default filename specified
- * in @default_filename.
+ * To get the content type of the downloaded data, gdata_download_stream_get_content_type() can be called on the returned #GDataDownloadStream.
+ * Calling gdata_download_stream_get_content_length() on the stream will not return a meaningful result, however, as the stream is encoded in chunks,
+ * rather than by content length.
*
- * Return value: (transfer full): the content's data, or %NULL; unref with g_object_unref()
+ * Return value: (transfer full): a #GDataDownloadStream to download the content with, or %NULL; unref with g_object_unref()
*
- * Since: 0.6.0
+ * Since: 0.8.0
**/
-GFile *
-gdata_media_content_download (GDataMediaContent *self, GDataService *service, const gchar *default_filename, GFile *target_dest_file,
- gboolean replace_file_if_exists, GCancellable *cancellable, GError **error)
+GDataDownloadStream *
+gdata_media_content_download (GDataMediaContent *self, GDataService *service, GError **error)
{
- GFileOutputStream *dest_stream;
const gchar *src_uri;
- GInputStream *src_stream;
- GFile *actual_file = NULL;
- GError *child_error = NULL;
g_return_val_if_fail (GDATA_IS_MEDIA_CONTENT (self), NULL);
g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL);
- g_return_val_if_fail (default_filename != NULL, NULL);
- g_return_val_if_fail (G_IS_FILE (target_dest_file), NULL);
- g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- dest_stream = _gdata_download_stream_find_destination (default_filename, target_dest_file, &actual_file, replace_file_if_exists,
- cancellable, error);
- if (dest_stream == NULL)
- return NULL;
+ /* We keep a GError in the argument list so that we can add authentication errors, etc., in future if necessary */
+ /* Get the download URI and create a stream for it */
src_uri = gdata_media_content_get_uri (self);
-
- /* Synchronously splice the data from the download stream to the file stream (network -> disk) */
- src_stream = gdata_download_stream_new (GDATA_SERVICE (service), src_uri);
- g_output_stream_splice (G_OUTPUT_STREAM (dest_stream), src_stream,
- G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, cancellable, &child_error);
- g_object_unref (src_stream);
- g_object_unref (dest_stream);
- if (child_error != NULL) {
- g_object_unref (actual_file);
- g_propagate_error (error, child_error);
- return NULL;
- }
-
- return actual_file;
+ return GDATA_DOWNLOAD_STREAM (gdata_download_stream_new (service, src_uri));
}
-
diff --git a/gdata/media/gdata-media-content.h b/gdata/media/gdata-media-content.h
index e8a1ad1e..da634e38 100644
--- a/gdata/media/gdata-media-content.h
+++ b/gdata/media/gdata-media-content.h
@@ -23,6 +23,7 @@
#include <glib.h>
#include <glib-object.h>
+#include <gdata/gdata-download-stream.h>
#include <gdata/gdata-parsable.h>
#include <gdata/gdata-service.h>
@@ -107,9 +108,8 @@ gint64 gdata_media_content_get_duration (GDataMediaContent *self) G_GNUC_PURE;
guint gdata_media_content_get_height (GDataMediaContent *self) G_GNUC_PURE;
guint gdata_media_content_get_width (GDataMediaContent *self) G_GNUC_PURE;
-GFile *gdata_media_content_download (GDataMediaContent *self, GDataService *service, const gchar *default_filename, GFile *target_dest_file,
- gboolean replace_file_if_exists,
- GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+GDataDownloadStream *gdata_media_content_download (GDataMediaContent *self, GDataService *service,
+ GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
G_END_DECLS