[eog-plugins] [postasa] Be compatible with libgdata-0.8 as well
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog-plugins] [postasa] Be compatible with libgdata-0.8 as well
- Date: Sat, 5 Feb 2011 17:19:43 +0000 (UTC)
commit 66b4e5a6696c14f416223a65658a5124b52f996b
Author: Felix Riemann <friemann gnome org>
Date: Fri Jan 14 15:27:40 2011 +0100
[postasa] Be compatible with libgdata-0.8 as well
The file upload API changed from libgdata-0.6 to 0.8.
This checks the used library version on build time and
switches between APIs accordingly. Fixes bug #639261.
configure.ac | 6 +++-
plugins/postasa/eog-postasa-plugin.c | 67 ++++++++++++++++++++++++++++++++--
2 files changed, 69 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0aa3461..60f805e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -297,7 +297,11 @@ if test "$?" = 1
then
PKG_CHECK_MODULES(POSTASA,
[ libgdata >= 0.6.0 ],
- [],[have_postasa=no])
+ PKG_CHECK_EXISTS( libgdata >= 0.8 ,
+ AC_DEFINE([HAVE_LIBGDATA_80], [1],
+ [Define to be compatible with the API of libgdata-0.8])
+ ),
+ [have_postasa=no])
AC_SUBST(POSTASA_LIBS)
AC_SUBST(POSTASA_CFLAGS)
if test "x$have_postasa" = "xno"
diff --git a/plugins/postasa/eog-postasa-plugin.c b/plugins/postasa/eog-postasa-plugin.c
index 7b29b5b..834e7cf 100644
--- a/plugins/postasa/eog-postasa-plugin.c
+++ b/plugins/postasa/eog-postasa-plugin.c
@@ -402,8 +402,14 @@ tmp_picasaweb_upload_async (GSimpleAsyncResult *result, GObject *source_object,
{
GDataPicasaWebFile *new_file = NULL;
EogPostasaPlugin *plugin = EOG_POSTASA_PLUGIN (source_object);
+ GDataPicasaWebService *service = plugin->priv->service;
GDataPicasaWebFile *file_entry;
PicasaWebUploadFileAsyncData *data;
+#ifdef HAVE_LIBGDATA_80
+ GDataUploadStream *upload_stream;
+ GFileInputStream *in_stream;
+ GFileInfo *file_info;
+#endif
gchar *filename;
GError *error = NULL;
@@ -415,15 +421,70 @@ tmp_picasaweb_upload_async (GSimpleAsyncResult *result, GObject *source_object,
gdata_entry_set_title (GDATA_ENTRY (file_entry), filename);
g_free (filename);
- new_file = gdata_picasaweb_service_upload_file (plugin->priv->service, NULL /* Uploading to Drop Box */, file_entry,
- data->imgfile, cancellable, &error);
+#ifdef HAVE_LIBGDATA_80
+ file_info = g_file_query_info (data->imgfile,
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE, cancellable,
+ &error);
+
+ if (file_info == NULL)
+ goto got_err;
+
+ upload_stream = gdata_picasaweb_service_upload_file (service,
+ NULL /* Upload to Dropbox */, file_entry,
+ g_file_info_get_display_name (file_info),
+ g_file_info_get_content_type (file_info),
+ cancellable, &error);
+ g_object_unref (file_info);
+
+ if (upload_stream == NULL)
+ goto got_err;
+
+ in_stream = g_file_read (data->imgfile, cancellable, &error);
+
+ if (in_stream == NULL) {
+ g_object_unref (upload_stream);
+ goto got_err;
+ }
+
+ if (g_output_stream_splice (G_OUTPUT_STREAM (upload_stream),
+ G_INPUT_STREAM (in_stream),
+ G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
+ G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+ cancellable, &error) == -1)
+ {
+ g_object_unref (upload_stream);
+ g_object_unref (in_stream);
+ goto got_err;
+ }
+
+
+ new_file = gdata_picasaweb_service_finish_file_upload (service,
+ upload_stream,
+ &error);
+
+ g_object_unref (upload_stream);
+ g_object_unref (in_stream);
+got_err:
+ /* Jump here if any GIO/GData call doesn't return successfully.
+ * Error handling happens below. */
+
+#else
+ /* libgdata-0.6 */
+ new_file = gdata_picasaweb_service_upload_file (service,
+ NULL /* Uploading to Drop Box */,
+ file_entry, data->imgfile,
+ cancellable, &error);
+#endif
g_object_unref (file_entry);
if (new_file == NULL || error) {
if (g_cancellable_is_cancelled (cancellable) == FALSE) {
g_simple_async_result_set_from_error (result, error);
- g_clear_error (&error); /* we can clear this, because set_from_error() does a g_error_copy() */
}
+ /* Clear errors always as cancelling creates errors too */
+ g_clear_error (&error);
} else {
g_simple_async_result_set_op_res_gboolean (result, TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]