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



commit f7a0cc289fc2fa82a5ae4d1af6adceb8ed7f5934
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Dec 10 18:21:26 2010 +0000

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

 docs/reference/gdata-sections.txt                |    1 +
 gdata/gdata.symbols                              |    1 +
 gdata/services/calendar/gdata-calendar-service.c |   35 +++++++++++++-
 gdata/services/calendar/gdata-calendar-service.h |    2 +
 gdata/tests/calendar.c                           |   58 ++++++++++++++++++++++
 5 files changed, 96 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 8ed2310..fe656b3 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -452,6 +452,7 @@ gdata_calendar_service_query_own_calendars_async
 gdata_calendar_service_query_events
 gdata_calendar_service_query_events_async
 gdata_calendar_service_insert_event
+gdata_calendar_service_insert_event_async
 <SUBSECTION Standard>
 gdata_calendar_service_get_type
 GDATA_CALENDAR_SERVICE
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index c22be3c..195c935 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -855,3 +855,4 @@ gdata_picasaweb_service_finish_file_upload
 gdata_youtube_service_upload_video
 gdata_youtube_service_finish_video_upload
 gdata_calendar_service_query_events_async
+gdata_calendar_service_insert_event_async
diff --git a/gdata/services/calendar/gdata-calendar-service.c b/gdata/services/calendar/gdata-calendar-service.c
index 6144b45..fda7746 100644
--- a/gdata/services/calendar/gdata-calendar-service.c
+++ b/gdata/services/calendar/gdata-calendar-service.c
@@ -373,7 +373,6 @@ gdata_calendar_service_query_events_async (GDataCalendarService *self, GDataCale
 GDataCalendarEvent *
 gdata_calendar_service_insert_event (GDataCalendarService *self, GDataCalendarEvent *event, GCancellable *cancellable, GError **error)
 {
-	/* TODO: Async variant */
 	/* TODO: How do we choose which calendar? */
 	gchar *uri;
 	GDataEntry *entry;
@@ -389,3 +388,37 @@ gdata_calendar_service_insert_event (GDataCalendarService *self, GDataCalendarEv
 
 	return GDATA_CALENDAR_EVENT (entry);
 }
+
+/**
+ * gdata_calendar_service_insert_event_async:
+ * @self: a #GDataCalendarService
+ * @event: the #GDataCalendarEvent to insert
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @callback: a #GAsyncReadyCallback to call when insertion is finished
+ * @user_data: (closure): data to pass to the @callback function
+ *
+ * Inserts @event by uploading it to the online calendar service. @self and @event are both reffed when this function is called, so can safely be
+ * unreffed after this function returns.
+ *
+ * @callback should call gdata_service_insert_entry_finish() to obtain a #GDataCalendarEvent representing the inserted event and to check for possible
+ * errors.
+ *
+ * For more details, see gdata_calendar_service_insert_event(), which is the synchronous version of this function, and
+ * gdata_service_insert_entry_async(), which is the base asynchronous insertion function.
+ *
+ * Since: 0.8.0
+ **/
+void
+gdata_calendar_service_insert_event_async (GDataCalendarService *self, GDataCalendarEvent *event, GCancellable *cancellable,
+                                           GAsyncReadyCallback callback, gpointer user_data)
+{
+	gchar *uri;
+
+	g_return_if_fail (GDATA_IS_CALENDAR_SERVICE (self));
+	g_return_if_fail (GDATA_IS_CALENDAR_EVENT (event));
+	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
+	uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/calendar/feeds/default/private/full", NULL);
+	gdata_service_insert_entry_async (GDATA_SERVICE (self), uri, GDATA_ENTRY (event), cancellable, callback, user_data);
+	g_free (uri);
+}
diff --git a/gdata/services/calendar/gdata-calendar-service.h b/gdata/services/calendar/gdata-calendar-service.h
index 42fb292..f7924f3 100644
--- a/gdata/services/calendar/gdata-calendar-service.h
+++ b/gdata/services/calendar/gdata-calendar-service.h
@@ -86,6 +86,8 @@ void gdata_calendar_service_query_events_async (GDataCalendarService *self, GDat
 
 GDataCalendarEvent *gdata_calendar_service_insert_event (GDataCalendarService *self, GDataCalendarEvent *event,
                                                          GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+void gdata_calendar_service_insert_event_async (GDataCalendarService *self, GDataCalendarEvent *event, GCancellable *cancellable,
+                                                GAsyncReadyCallback callback, gpointer user_data);
 
 G_END_DECLS
 
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index 5025e04..391ea07 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -327,6 +327,63 @@ test_insert_simple (gconstpointer service)
 }
 
 static void
+test_insert_simple_async_cb (GDataService *service, GAsyncResult *result, GMainLoop *main_loop)
+{
+	GDataEntry *event;
+	GError *error = NULL;
+
+	event = gdata_service_insert_entry_finish (service, result, &error);
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_CALENDAR_EVENT (event));
+
+	/* Check the event is correct */
+	g_assert_cmpstr (gdata_entry_get_title (event), ==, "Tennis with Beth");
+
+	g_main_loop_quit (main_loop);
+
+	g_object_unref (event);
+}
+
+static void
+test_insert_simple_async (gconstpointer service)
+{
+	GDataCalendarEvent *event;
+	GDataGDWhere *where;
+	GDataGDWho *who;
+	GDataGDWhen *when;
+	GTimeVal start_time, end_time;
+	GMainLoop *main_loop;
+
+	event = gdata_calendar_event_new (NULL);
+
+	gdata_entry_set_title (GDATA_ENTRY (event), "Tennis with Beth");
+	gdata_entry_set_content (GDATA_ENTRY (event), "Meet for a quick lesson.");
+	gdata_calendar_event_set_transparency (event, GDATA_GD_EVENT_TRANSPARENCY_OPAQUE);
+	gdata_calendar_event_set_status (event, GDATA_GD_EVENT_STATUS_CONFIRMED);
+	where = gdata_gd_where_new (NULL, "Rolling Lawn Courts", NULL);
+	gdata_calendar_event_add_place (event, where);
+	g_object_unref (where);
+	who = gdata_gd_who_new (GDATA_GD_WHO_EVENT_ORGANIZER, "John Smithâ?½", "john smith example com");
+	gdata_calendar_event_add_person (event, who);
+	g_object_unref (who);
+	g_time_val_from_iso8601 ("2009-04-17T15:00:00.000Z", &start_time);
+	g_time_val_from_iso8601 ("2009-04-17T17:00:00.000Z", &end_time);
+	when = gdata_gd_when_new (start_time.tv_sec, end_time.tv_sec, FALSE);
+	gdata_calendar_event_add_time (event, when);
+	g_object_unref (when);
+
+	main_loop = g_main_loop_new (NULL, TRUE);
+
+	/* Insert the event */
+	gdata_calendar_service_insert_event_async (GDATA_CALENDAR_SERVICE (service), event, NULL, (GAsyncReadyCallback) test_insert_simple_async_cb,
+	                                           main_loop);
+	g_main_loop_run (main_loop);
+
+	g_main_loop_unref (main_loop);
+	g_object_unref (event);
+}
+
+static void
 test_xml_dates (void)
 {
 	GDataCalendarEvent *event;
@@ -1077,6 +1134,7 @@ main (int argc, char *argv[])
 		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);
+		g_test_add_data_func ("/calendar/insert/simple/async", service, test_insert_simple_async);
 
 		g_test_add_data_func ("/calendar/acls/get_rules", service, test_acls_get_rules);
 		g_test_add_data_func ("/calendar/acls/insert_rule", service, test_acls_insert_rule);



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