Exemple #1
0
int main()
{
	GoaObject *goa_object;	
	GDataPicasaWebService *service;
	GDataPicasaWebAlbum *album, *inserted_album;
	GDataGoaAuthorizer *authorizer;
	GError *error;
	GoaClient *client;
	GList *accounts_list, *l;

	error = NULL;
	/*I am using sync version just to avoid some complexity and keeping it simple.*/
	client = goa_client_new_sync (NULL, &error);

	/*FYI, I have only experimented this with just one google account so account_lists assume 1 account only.*/
	accounts_list = goa_client_get_accounts (client);
	printf ("Accounts : %d\n", g_list_length (accounts_list));

	goa_object = accounts_list->data;
	authorizer = gdata_goa_authorizer_new (goa_object);	
	service = gdata_picasaweb_service_new (GDATA_AUTHORIZER (authorizer));

	/* Create a GDataPicasaWebAlbum entry for the new album, setting some information about it */
	album = gdata_picasaweb_album_new (NULL);
	gdata_entry_set_title (GDATA_ENTRY (album), "Test Album");
	gdata_entry_set_summary (GDATA_ENTRY (album), "This is just a testing album");
	gdata_picasaweb_album_set_location (album, "Ahmedabad");

	/* Insert the new album on the server. Note that this is a blocking operation. */
	inserted_album = gdata_picasaweb_service_insert_album (service, album, NULL, NULL);

	g_object_unref (album);
	g_object_unref (inserted_album);
	g_object_unref (service);
	g_object_unref (authorizer);
	printf("Album Created!");
}
/**
 * tmp_picasaweb_upload_async:
 *
 * Temporary solution to provide asynchronous uploading and stop
 * blocking the UI until gdata_picasaweb_service_upload_file_async()
 * becomes available (bgo #600262).  This method does the synchronous
 * file upload, but is run asynchronously via
 * g_simple_async_result_run_in_thread().
 *
 * This sets up a minimal #GDataPicasaWebFile entry, using the
 * basename of the filepath for the file's title (which is not the
 * caption, but might be something we would consider doing).  The
 * image file and the minimal entry are then uploaded to PicasaWeb's
 * default album of "Drop Box".  In the future, we might consider
 * adding an Album Chooser to the Preferences/login window, but only
 * if there's demand.
 **/
static void
tmp_picasaweb_upload_async (GSimpleAsyncResult *result, GObject *source_object, GCancellable *cancellable)
{
	GDataPicasaWebFile *new_file = NULL;
	XviewerPostasaPlugin *plugin = XVIEWER_POSTASA_PLUGIN (source_object);
	GDataPicasaWebService *service = plugin->priv->service;
	GDataPicasaWebFile *file_entry;
	PicasaWebUploadFileAsyncData *data;
#ifdef HAVE_LIBGDATA_0_8
	GDataUploadStream *upload_stream;
	GFileInputStream *in_stream;
	GFileInfo *file_info;
#endif
	gchar *filename;
	GError *error = NULL;

	data = (PicasaWebUploadFileAsyncData*)g_async_result_get_user_data (G_ASYNC_RESULT (result));

	/* get filename to set image title */
	file_entry = gdata_picasaweb_file_new (NULL);
	filename = g_file_get_basename (data->imgfile);
	gdata_entry_set_title (GDATA_ENTRY (file_entry), filename);
	g_free (filename);

#ifdef HAVE_LIBGDATA_0_8
	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);
		}
		/* Clear errors always as cancelling creates errors too */
		g_clear_error (&error);
	} else {
		g_simple_async_result_set_op_res_gboolean (result, TRUE);
	}

	if (new_file != NULL)
		g_object_unref (new_file);
}