[evolution-data-server] Insufficient return values from e_cal_backend_get_object/_list()



commit f9ee1477151f2747745f2e90e1a7d34bc992b931
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 16 12:05:30 2013 +0200

    Insufficient return values from e_cal_backend_get_object/_list()
    
    These also returned ECalComponent, but it cannot hold a vCalendar,
    which is returned when the component has detached instances.

 calendar/libedata-cal/e-cal-backend.c |   42 +++++++++++++--------------
 calendar/libedata-cal/e-cal-backend.h |    4 +-
 calendar/libedata-cal/e-data-cal.c    |   51 ++++++++++++--------------------
 3 files changed, 41 insertions(+), 56 deletions(-)
---
diff --git a/calendar/libedata-cal/e-cal-backend.c b/calendar/libedata-cal/e-cal-backend.c
index 5c13393..0446087 100644
--- a/calendar/libedata-cal/e-cal-backend.c
+++ b/calendar/libedata-cal/e-cal-backend.c
@@ -1601,17 +1601,17 @@ e_cal_backend_refresh_finish (ECalBackend *backend,
 }
 
 /**
- * e_cal_backend_get_objects_sync:
+ * e_cal_backend_get_object_sync:
  * @backend: an #ECalBackend
  * @uid: a unique ID for an iCalendar object
  * @rid: a recurrence ID, or %NULL
  * @cancellable: optional #GCancellable object, or %NULL
  * @error: return location for a #GError, or %NULL
  *
- * Obtains an #ECalComponent by its @uid and, optionally, @rid.
+ * Obtains an iCalendar string for an object identified by its @uid and,
+ * optionally, @rid.
  *
- * The returned #ECalComponent is referenced for thread-safety and must be
- * unreferenced with g_object_unref() when finished with it.
+ * The returned string should be freed with g_free() when finished with it.
  *
  * If an error occurs, the function will set @error and return %NULL.
  *
@@ -1619,7 +1619,7 @@ e_cal_backend_refresh_finish (ECalBackend *backend,
  *
  * Since: 3.10
  **/
-ECalComponent *
+gchar *
 e_cal_backend_get_object_sync (ECalBackend *backend,
                                const gchar *uid,
                                const gchar *rid,
@@ -1628,7 +1628,7 @@ e_cal_backend_get_object_sync (ECalBackend *backend,
 {
        EAsyncClosure *closure;
        GAsyncResult *result;
-       ECalComponent *component;
+       gchar *calobj;
 
        g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
        g_return_val_if_fail (uid != NULL, NULL);
@@ -1642,11 +1642,11 @@ e_cal_backend_get_object_sync (ECalBackend *backend,
 
        result = e_async_closure_wait (closure);
 
-       component = e_cal_backend_get_object_finish (backend, result, error);
+       calobj = e_cal_backend_get_object_finish (backend, result, error);
 
        e_async_closure_free (closure);
 
-       return component;
+       return calobj;
 }
 
 /* Helper for e_cal_backend_get_object() */
@@ -1753,8 +1753,9 @@ e_cal_backend_get_object (ECalBackend *backend,
  *
  * Finishes the operation started with e_cal_backend_get_object().
  *
- * The returned #ECalComponent is referenced for thread-safety and must be
- * unreferenced with g_object_unref() when finished with it.
+ * The returned string is an iCalendar object describing either single component
+ * or a vCalendar object, which includes also detached instances. It should be
+ * freed when no longer needed.
  *
  * If an error occurs, the function will set @error and return %NULL.
  *
@@ -1762,14 +1763,14 @@ e_cal_backend_get_object (ECalBackend *backend,
  *
  * Since: 3.10
  **/
-ECalComponent *
+gchar *
 e_cal_backend_get_object_finish (ECalBackend *backend,
                                  GAsyncResult *result,
                                  GError **error)
 {
        GSimpleAsyncResult *simple;
        AsyncContext *async_context;
-       ECalComponent *component;
+       gchar *calobj;
 
        g_return_val_if_fail (
                g_simple_async_result_is_valid (
@@ -1784,12 +1785,11 @@ e_cal_backend_get_object_finish (ECalBackend *backend,
        if (g_simple_async_result_propagate_error (simple, error))
                return FALSE;
 
-       component = g_queue_pop_head (&async_context->result_queue);
-       g_return_val_if_fail (E_IS_CAL_COMPONENT (component), NULL);
+       calobj = g_queue_pop_head (&async_context->result_queue);
 
        g_warn_if_fail (g_queue_is_empty (&async_context->result_queue));
 
-       return component;
+       return calobj;
 }
 
 /**
@@ -1800,11 +1800,10 @@ e_cal_backend_get_object_finish (ECalBackend *backend,
  * @cancellable: optional #GCancellable object, or %NULL
  * @error: return location for a #GError, or %NULL
  *
- * Obtains a set of #ECalComponent instances which satisfy the criteria
+ * Obtains a set of iCalendar string instances which satisfy the criteria
  * specified in @query, and deposits them in @out_objects.
  *
- * The returned #ECalComponent instances are referenced for thread-safety
- * and must be unreferenced with g_object_unref() when finished with them.
+ * The returned instances should be freed with g_free() when finished with them.
  *
  * If an error occurs, the function will set @error and return %FALSE.
  * Note that an empty result set does not necessarily imply an error.
@@ -1893,7 +1892,7 @@ cal_backend_get_object_list_thread (GSimpleAsyncResult *simple,
  * @callback: a #GAsyncReadyCallback to call when the request is satisfied
  * @user_data: data to pass to the callback function
  *
- * Asynchronously obtains a set of #ECalComponent instances which satisfy
+ * Asynchronously obtains a set of iCalendar instances which satisfy
  * the criteria specified in @query.
  *
  * When the operation in finished, @callback will be called.  You can then
@@ -1945,9 +1944,8 @@ e_cal_backend_get_object_list (ECalBackend *backend,
  *
  * Finishes the operation started with e_cal_backend_get_object_list().
  *
- * The matching #ECalComponent instances are deposited in @out_objects.
- * The returned #ECalComponent instances are referenced for thread-safety
- * and must be unreferenced with g_object_unref() when finished with them.
+ * The matching iCalendar instances are deposited in @out_objects.
+ * The returned instances should be freed with g_free() when finished with them.
  *
  * If an error occurred, the function will set @error and return %FALSE.
  * Note that an empty result set does not necessarily imply an error.
diff --git a/calendar/libedata-cal/e-cal-backend.h b/calendar/libedata-cal/e-cal-backend.h
index e45dc27..eb9754f 100644
--- a/calendar/libedata-cal/e-cal-backend.h
+++ b/calendar/libedata-cal/e-cal-backend.h
@@ -263,7 +263,7 @@ void                e_cal_backend_refresh           (ECalBackend *backend,
 gboolean       e_cal_backend_refresh_finish    (ECalBackend *backend,
                                                 GAsyncResult *result,
                                                 GError **error);
-ECalComponent *        e_cal_backend_get_object_sync   (ECalBackend *backend,
+gchar *                e_cal_backend_get_object_sync   (ECalBackend *backend,
                                                 const gchar *uid,
                                                 const gchar *rid,
                                                 GCancellable *cancellable,
@@ -274,7 +274,7 @@ void                e_cal_backend_get_object        (ECalBackend *backend,
                                                 GCancellable *cancellable,
                                                 GAsyncReadyCallback callback,
                                                 gpointer user_data);
-ECalComponent *        e_cal_backend_get_object_finish (ECalBackend *backend,
+gchar *                e_cal_backend_get_object_finish (ECalBackend *backend,
                                                 GAsyncResult *result,
                                                 GError **error);
 gboolean       e_cal_backend_get_object_list_sync
diff --git a/calendar/libedata-cal/e-data-cal.c b/calendar/libedata-cal/e-data-cal.c
index 9f718d2..8d774c0 100644
--- a/calendar/libedata-cal/e-data-cal.c
+++ b/calendar/libedata-cal/e-data-cal.c
@@ -583,31 +583,29 @@ data_cal_complete_get_object_cb (GObject *source_object,
                                  gpointer user_data)
 {
        AsyncContext *async_context = user_data;
-       ECalComponent *component;
+       gchar *calobj;
        GError *error = NULL;
 
-       component = e_cal_backend_get_object_finish (
+       calobj = e_cal_backend_get_object_finish (
                E_CAL_BACKEND (source_object), result, &error);
 
        /* Sanity check. */
        g_return_if_fail (
-               ((component != NULL) && (error == NULL)) ||
-               ((component == NULL) && (error != NULL)));
+               ((calobj != NULL) && (error == NULL)) ||
+               ((calobj == NULL) && (error != NULL)));
 
        if (error == NULL) {
-               gchar *string;
-               gchar *utf8_string;
+               gchar *utf8_calobj;
 
-               string = e_cal_component_get_as_string (component);
-               utf8_string = e_util_utf8_make_valid (string);
+               utf8_calobj = e_util_utf8_make_valid (calobj);
 
                e_dbus_calendar_complete_get_object (
                        async_context->interface,
                        async_context->invocation,
-                       utf8_string);
+                       utf8_calobj);
 
-               g_free (utf8_string);
-               g_free (string);
+               g_free (utf8_calobj);
+               g_free (calobj);
        } else {
                data_cal_convert_to_client_error (error);
                g_dbus_method_invocation_take_error (
@@ -668,16 +666,13 @@ data_cal_complete_get_object_list_cb (GObject *source_object,
                strv = g_new0 (gchar *, queue.length + 1);
 
                while (!g_queue_is_empty (&queue)) {
-                       ECalComponent *component;
-                       gchar *string;
+                       gchar *calobj;
 
-                       component = g_queue_pop_head (&queue);
+                       calobj = g_queue_pop_head (&queue);
 
-                       string = e_cal_component_get_as_string (component);
-                       strv[ii++] = e_util_utf8_make_valid (string);
-                       g_free (string);
+                       strv[ii++] = e_util_utf8_make_valid (calobj);
 
-                       g_object_unref (component);
+                       g_free (calobj);
                }
 
                e_dbus_calendar_complete_get_object_list (
@@ -1578,11 +1573,8 @@ e_data_cal_respond_get_object (EDataCal *cal,
        g_prefix_error (&error, "%s", _("Cannot retrieve calendar object path: "));
 
        if (error == NULL) {
-               ECalComponent *component;
-
-               component = e_cal_component_new_from_string (object);
-               if (component != NULL) {
-                       g_queue_push_tail (queue, component);
+               if (object != NULL) {
+                       g_queue_push_tail (queue, g_strdup (object));
                } else {
                        g_simple_async_result_set_error (
                                simple, E_CAL_CLIENT_ERROR,
@@ -1638,15 +1630,10 @@ e_data_cal_respond_get_object_list (EDataCal *cal,
                list = (GSList *) objects;
 
                for (link = list; link != NULL; link = g_slist_next (link)) {
-                       ECalComponent *component;
-                       gchar *string = link->data;
-
-                       component = e_cal_component_new_from_string (string);
-                       if (component != NULL) {
-                               g_queue_push_tail (
-                                       queue, g_object_ref (component));
-                               g_object_unref (component);
-                       }
+                       const gchar *calobj = link->data;
+
+                       if (calobj != NULL)
+                               g_queue_push_tail (queue, g_strdup (calobj));
                }
 
        } else {


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