[libgdata] picasaweb: Add gdata_picasaweb_service_query_files_async()



commit b13fe3d891264b520fa95e6d8512a48976187bbe
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Nov 7 16:15:22 2010 +0000

    picasaweb: Add gdata_picasaweb_service_query_files_async()
    
    Helps: bgo#633363

 docs/reference/gdata-sections.txt                  |    1 +
 gdata/gdata.symbols                                |    1 +
 gdata/services/picasaweb/gdata-picasaweb-service.c |   80 ++++++++++++++++---
 gdata/services/picasaweb/gdata-picasaweb-service.h |    3 +
 gdata/tests/picasaweb.c                            |   55 +++++++++++++
 5 files changed, 127 insertions(+), 13 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 48a4e04..46545b5 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -1334,6 +1334,7 @@ gdata_picasaweb_service_get_user
 gdata_picasaweb_service_query_all_albums
 gdata_picasaweb_service_query_all_albums_async
 gdata_picasaweb_service_query_files
+gdata_picasaweb_service_query_files_async
 gdata_picasaweb_service_upload_file
 gdata_picasaweb_service_upload_file_async
 gdata_picasaweb_service_upload_file_finish
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 9e0c8ed..b2f0dce 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -855,3 +855,4 @@ gdata_contacts_service_insert_group_async
 gdata_youtube_service_upload_video_async
 gdata_youtube_service_upload_video_finish
 gdata_picasaweb_service_insert_album_async
+gdata_picasaweb_service_query_files_async
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.c b/gdata/services/picasaweb/gdata-picasaweb-service.c
index 38e6056..09aa831 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.c
@@ -310,6 +310,25 @@ gdata_picasaweb_service_query_all_albums_async (GDataPicasaWebService *self, GDa
 	g_free (uri);
 }
 
+static const gchar *
+get_query_files_uri (GDataPicasaWebAlbum *album, GError **error)
+{
+	if (album != NULL) {
+		GDataLink *_link = gdata_entry_look_up_link (GDATA_ENTRY (album), "http://schemas.google.com/g/2005#feed";);
+		if (_link == NULL) {
+			/* Error */
+			g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
+			                     _("The album did not have a feed link."));
+			return NULL;
+		}
+
+		return gdata_link_get_uri (_link);
+	} else {
+		/* Default URI */
+		return "http://picasaweb.google.com/data/feed/api/user/default/albumid/default";;
+	}
+}
+
 /**
  * gdata_picasaweb_service_query_files:
  * @self: a #GDataPicasaWebService
@@ -342,25 +361,60 @@ gdata_picasaweb_service_query_files (GDataPicasaWebService *self, GDataPicasaWeb
 	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
 	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-	if (album != NULL) {
-		GDataLink *_link = gdata_entry_look_up_link (GDATA_ENTRY (album), "http://schemas.google.com/g/2005#feed";);
-		if (_link == NULL) {
-			/* Error */
-			g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
-			                     _("The album did not have a feed link."));
-			return NULL;
-		}
-		uri = gdata_link_get_uri (_link);
-	} else {
-		/* Default URI */
-		uri = "http://picasaweb.google.com/data/feed/api/user/default/albumid/default";;
-	}
+	uri = get_query_files_uri (album, error);
+	if (uri == NULL)
+		return NULL;
 
 	/* Execute the query */
 	return gdata_service_query (GDATA_SERVICE (self), uri, GDATA_QUERY (query), GDATA_TYPE_PICASAWEB_FILE, cancellable,
 	                            progress_callback, progress_user_data, error);
 }
 
+/**
+ * gdata_picasaweb_service_query_files_async: (skip)
+ * @self: a #GDataPicasaWeb
+ * @album: (allow-none): a #GDataPicasaWebAlbum from which to retrieve the files, or %NULL
+ * @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @progress_callback: a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
+ * @progress_user_data: (closure): data to pass to the @progress_callback function
+ * @callback: a #GAsyncReadyCallback to call when the query is finished
+ * @user_data: (closure): data to pass to the @callback function
+ *
+ * Queries the specified @album for a list of the files which match the given @query. If @album is %NULL and a user is authenticated with the service,
+ * the user's default album will be queried. @self, @album and @query are all reffed when this function is called, so can safely be unreffed after
+ * this function returns.
+ *
+ * For more details, see gdata_picasaweb_service_query_files(), which is the synchronous version of this function, and gdata_service_query_async(),
+ * which is the base asynchronous query function.
+ *
+ * Since: 0.8.0
+ **/
+void
+gdata_picasaweb_service_query_files_async (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GDataQuery *query, GCancellable *cancellable,
+                                           GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GAsyncReadyCallback callback,
+                                           gpointer user_data)
+{
+	const gchar *request_uri;
+	GError *child_error = NULL;
+
+	g_return_if_fail (GDATA_IS_PICASAWEB_SERVICE (self));
+	g_return_if_fail (album == NULL || GDATA_IS_PICASAWEB_ALBUM (album));
+	g_return_if_fail (query == NULL || GDATA_IS_QUERY (query));
+	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+	g_return_if_fail (callback != NULL);
+
+	request_uri = get_query_files_uri (album, &child_error);
+	if (request_uri == NULL) {
+		g_simple_async_report_gerror_in_idle (G_OBJECT (self), callback, user_data, child_error);
+		g_error_free (child_error);
+		return;
+	}
+
+	gdata_service_query_async (GDATA_SERVICE (self), request_uri, GDATA_QUERY (query), GDATA_TYPE_PICASAWEB_FILE, cancellable, progress_callback,
+	                           progress_user_data, callback, user_data);
+}
+
 static GOutputStream *
 get_file_output_stream (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GDataPicasaWebFile *file_entry, GFile *file_data, GError **error)
 {
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.h b/gdata/services/picasaweb/gdata-picasaweb-service.h
index d368f69..cbbd6be 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.h
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.h
@@ -79,6 +79,9 @@ void gdata_picasaweb_service_query_all_albums_async (GDataPicasaWebService *self
 GDataFeed *gdata_picasaweb_service_query_files (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GDataQuery *query,
                                                 GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
                                                 GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+void gdata_picasaweb_service_query_files_async (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GDataQuery *query, GCancellable *cancellable,
+                                                GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+                                                GAsyncReadyCallback callback, gpointer user_data);
 
 #include <gdata/services/picasaweb/gdata-picasaweb-file.h>
 
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index 72a4c88..e3279ee 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -852,6 +852,60 @@ test_photo_single (gconstpointer service)
 }
 
 static void
+test_photo_async_cb (GDataService *service, GAsyncResult *async_result, GMainLoop *main_loop)
+{
+	GDataFeed *feed;
+	GError *error = NULL;
+
+	feed = gdata_service_query_finish (service, async_result, &error);
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_FEED (feed));
+	g_clear_error (&error);
+
+	/* Tests */
+	g_assert_cmpstr (gdata_feed_get_title (feed), ==, "Test Album 1 - Venice - Public");
+	g_assert_cmpstr (gdata_feed_get_id (feed), ==, "http://picasaweb.google.com/data/feed/user/libgdata.picasaweb/albumid/5328889949261497249";);
+	g_assert_cmpstr (gdata_feed_get_etag (feed), !=, NULL);
+	g_assert_cmpuint (gdata_feed_get_items_per_page (feed), ==, 1000);
+	g_assert_cmpuint (gdata_feed_get_start_index (feed), ==, 1);
+	g_assert_cmpuint (gdata_feed_get_total_results (feed), ==, 1);
+
+	g_main_loop_quit (main_loop);
+
+	g_object_unref (feed);
+}
+
+static void
+test_photo_async (gconstpointer service)
+{
+	GMainLoop *main_loop;
+	GDataFeed *album_feed;
+	GDataEntry *entry;
+	GDataPicasaWebAlbum *album;
+	GList *albums;
+	GError *error = NULL;
+
+	/* Find an album */
+	album_feed = gdata_picasaweb_service_query_all_albums (GDATA_PICASAWEB_SERVICE (service), NULL, NULL, NULL, NULL, NULL, &error);
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_FEED (album_feed));
+	g_clear_error (&error);
+
+	albums = gdata_feed_get_entries (album_feed);
+	entry = GDATA_ENTRY (g_list_nth_data (albums, TEST_ALBUM_INDEX));
+	album = GDATA_PICASAWEB_ALBUM (entry);
+
+	main_loop = g_main_loop_new (NULL, TRUE);
+
+	gdata_picasaweb_service_query_files_async (GDATA_PICASAWEB_SERVICE (service), album, NULL, NULL, NULL, NULL,
+	                                           (GAsyncReadyCallback) test_photo_async_cb, main_loop);
+
+	g_main_loop_run (main_loop);
+	g_main_loop_unref (main_loop);
+	g_object_unref (album_feed);
+}
+
+static void
 test_album (gconstpointer service)
 {
 	GDataFeed *album_feed;
@@ -1386,6 +1440,7 @@ main (int argc, char *argv[])
 		g_test_add_data_func ("/picasaweb/query/photo_feed_entry", service, test_photo_feed_entry);
 		g_test_add_data_func ("/picasaweb/query/photo", service, test_photo);
 		g_test_add_data_func ("/picasaweb/query/photo_single", service, test_photo_single);
+		g_test_add_data_func ("/picasaweb/query/photo/async", service, test_photo_async);
 
 		g_test_add_data_func ("/picasaweb/upload/photo", service, test_upload_simple);
 



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