[libgdata] calendar: Add an async method for gdata_calendar_service_query_events()



commit 98cabcd58764cd535b3139a9594d3b0f0245bd1f
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Dec 10 18:08:48 2010 +0000

    calendar: Add an async method for gdata_calendar_service_query_events()
    
    This includes new tests.
    
    The following API has been added:
     â?¢ gdata_calendar_service_query_events_async()
    
    Helps: bgo#633363

 docs/reference/gdata-sections.txt                |    1 +
 gdata/gdata.symbols                              |    1 +
 gdata/services/calendar/gdata-calendar-service.c |   57 +++++++++++++++++++++-
 gdata/services/calendar/gdata-calendar-service.h |    3 +
 gdata/tests/calendar.c                           |   35 +++++++++++++
 5 files changed, 96 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 3b4ed92..8ed2310 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -450,6 +450,7 @@ gdata_calendar_service_query_all_calendars_async
 gdata_calendar_service_query_own_calendars
 gdata_calendar_service_query_own_calendars_async
 gdata_calendar_service_query_events
+gdata_calendar_service_query_events_async
 gdata_calendar_service_insert_event
 <SUBSECTION Standard>
 gdata_calendar_service_get_type
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 5c12768..c22be3c 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -854,3 +854,4 @@ gdata_picasaweb_service_upload_file
 gdata_picasaweb_service_finish_file_upload
 gdata_youtube_service_upload_video
 gdata_youtube_service_finish_video_upload
+gdata_calendar_service_query_events_async
diff --git a/gdata/services/calendar/gdata-calendar-service.c b/gdata/services/calendar/gdata-calendar-service.c
index e7efbb9..6144b45 100644
--- a/gdata/services/calendar/gdata-calendar-service.c
+++ b/gdata/services/calendar/gdata-calendar-service.c
@@ -270,7 +270,6 @@ GDataFeed *
 gdata_calendar_service_query_events (GDataCalendarService *self, GDataCalendarCalendar *calendar, GDataQuery *query, GCancellable *cancellable,
                                      GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError **error)
 {
-	/* TODO: Async variant */
 	const gchar *uri;
 
 	g_return_val_if_fail (GDATA_IS_CALENDAR_SERVICE (self), NULL);
@@ -301,6 +300,62 @@ gdata_calendar_service_query_events (GDataCalendarService *self, GDataCalendarCa
 }
 
 /**
+ * gdata_calendar_service_query_events_async: (skip)
+ * @self: a #GDataCalendarService
+ * @calendar: a #GDataCalendarCalendar
+ * @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 service to return a list of events in the given @calendar, which match @query. @self, @calendar and @query are all reffed when this
+ * function is called, so can safely be unreffed after this function returns.
+ *
+ * Get the results of the query using gdata_service_query_finish() in the @callback.
+ *
+ * For more details, see gdata_calendar_service_query_events(), 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_calendar_service_query_events_async (GDataCalendarService *self, GDataCalendarCalendar *calendar, GDataQuery *query, GCancellable *cancellable,
+                                           GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+                                           GAsyncReadyCallback callback, gpointer user_data)
+{
+	const gchar *uri;
+
+	g_return_if_fail (GDATA_IS_CALENDAR_SERVICE (self));
+	g_return_if_fail (GDATA_IS_CALENDAR_CALENDAR (calendar));
+	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);
+
+	/* Ensure we're authenticated first */
+	if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
+		g_simple_async_report_error_in_idle (G_OBJECT (self), callback, user_data,
+		                                     GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
+		                                     _("You must be authenticated to query your own calendars."));
+		return;
+	}
+
+	/* Use the calendar's content src */
+	uri = gdata_entry_get_content_uri (GDATA_ENTRY (calendar));
+	if (uri == NULL) {
+		/* Erroring out is probably the safest thing to do */
+		g_simple_async_report_error_in_idle (G_OBJECT (self), callback, user_data, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
+		                                     _("The calendar did not have a content URI."));
+		return;
+	}
+
+	/* Execute the query */
+	gdata_service_query_async (GDATA_SERVICE (self), uri, query, GDATA_TYPE_CALENDAR_EVENT, cancellable, progress_callback, progress_user_data,
+	                           callback, user_data);
+}
+
+/**
  * gdata_calendar_service_insert_event:
  * @self: a #GDataCalendarService
  * @event: the #GDataCalendarEvent to insert
diff --git a/gdata/services/calendar/gdata-calendar-service.h b/gdata/services/calendar/gdata-calendar-service.h
index 099211c..42fb292 100644
--- a/gdata/services/calendar/gdata-calendar-service.h
+++ b/gdata/services/calendar/gdata-calendar-service.h
@@ -78,6 +78,9 @@ void gdata_calendar_service_query_own_calendars_async (GDataCalendarService *sel
 GDataFeed *gdata_calendar_service_query_events (GDataCalendarService *self, GDataCalendarCalendar *calendar, GDataQuery *query,
                                                 GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
                                                 GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+void gdata_calendar_service_query_events_async (GDataCalendarService *self, GDataCalendarCalendar *calendar, GDataQuery *query,
+                                                GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+                                                GAsyncReadyCallback callback, gpointer user_data);
 
 #include <gdata/services/calendar/gdata-calendar-event.h>
 
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index 7372e46..5025e04 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -227,6 +227,40 @@ test_query_events (gconstpointer service)
 }
 
 static void
+test_query_events_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_CALENDAR_FEED (feed));
+
+	/* TODO: Tests? */
+	g_main_loop_quit (main_loop);
+
+	g_object_unref (feed);
+}
+
+static void
+test_query_events_async (gconstpointer service)
+{
+	GDataCalendarCalendar *calendar;
+	GMainLoop *main_loop;
+	GError *error = NULL;
+
+	calendar = get_calendar (service, &error);
+	main_loop = g_main_loop_new (NULL, TRUE);
+
+	gdata_calendar_service_query_events_async (GDATA_CALENDAR_SERVICE (service), calendar, NULL, NULL, NULL, NULL,
+	                                           (GAsyncReadyCallback) test_query_events_async_cb, main_loop);
+	g_main_loop_run (main_loop);
+
+	g_main_loop_unref (main_loop);
+	g_object_unref (calendar);
+}
+
+static void
 test_insert_simple (gconstpointer service)
 {
 	GDataCalendarEvent *event, *new_event;
@@ -1040,6 +1074,7 @@ main (int argc, char *argv[])
 		g_test_add_data_func ("/calendar/query/own_calendars", service, test_query_own_calendars);
 		g_test_add_data_func ("/calendar/query/own_calendars_async", service, test_query_own_calendars_async);
 		g_test_add_data_func ("/calendar/query/events", service, test_query_events);
+		g_test_add_data_func ("/calendar/query/events_async", service, test_query_events_async);
 
 		g_test_add_data_func ("/calendar/insert/simple", service, test_insert_simple);
 



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