[evolution-data-server] ECalClient: Include the ESource display name in connect errors.



commit fb2b1ebbc177fd73ce296a88cb834ad1fd4b4af3
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Jan 30 11:37:42 2013 -0500

    ECalClient: Include the ESource display name in connect errors.
    
    For error handling convenience, any error message returned by
    e_cal_client_connect_sync() or e_cal_client_connect_finish() will have
    a descriptive prefix that includes the display name of the ESource.
    
    Mention this in the API documentation.
    
    This is motivated more by asynchronous usage.  It relieves callers from
    having to bundle the ESource with every e_cal_client_connect() just so
    they can provide a descriptive error message on failure.

 calendar/libecal/e-cal-client.c |   60 +++++++++++++++++++++++++++++++-------
 1 files changed, 49 insertions(+), 11 deletions(-)
---
diff --git a/calendar/libecal/e-cal-client.c b/calendar/libecal/e-cal-client.c
index 3feaba7..79c49f5 100644
--- a/calendar/libecal/e-cal-client.c
+++ b/calendar/libecal/e-cal-client.c
@@ -50,6 +50,7 @@
 
 typedef struct _AsyncContext AsyncContext;
 typedef struct _SignalClosure SignalClosure;
+typedef struct _ConnectClosure ConnectClosure;
 typedef struct _RunInThreadClosure RunInThreadClosure;
 
 struct _ECalClientPrivate {
@@ -93,6 +94,11 @@ struct _SignalClosure {
 	gchar **free_busy_data;
 };
 
+struct _ConnectClosure {
+	ESource *source;
+	GCancellable *cancellable;
+};
+
 struct _RunInThreadClosure {
 	GSimpleAsyncThreadFunc func;
 	GSimpleAsyncResult *simple;
@@ -183,6 +189,18 @@ signal_closure_free (SignalClosure *signal_closure)
 }
 
 static void
+connect_closure_free (ConnectClosure *connect_closure)
+{
+	if (connect_closure->source != NULL)
+		g_object_unref (connect_closure->source);
+
+	if (connect_closure->cancellable != NULL)
+		g_object_unref (connect_closure->cancellable);
+
+	g_slice_free (ConnectClosure, connect_closure);
+}
+
+static void
 run_in_thread_closure_free (RunInThreadClosure *run_in_thread_closure)
 {
 	if (run_in_thread_closure->simple != NULL)
@@ -1515,6 +1533,10 @@ e_cal_client_init (ECalClient *client)
  * Unlike with e_cal_client_new(), there is no need to call
  * e_client_open_sync() after obtaining the #ECalClient.
  *
+ * For error handling convenience, any error message returned by this
+ * function will have a descriptive prefix that includes the display
+ * name of @source.
+ *
  * Returns: a new #ECalClient, or %NULL
  *
  * Since: 3.8
@@ -1547,6 +1569,9 @@ e_cal_client_connect_sync (ESource *source,
 			client->priv->dbus_proxy, cancellable, error);
 
 	if (!success) {
+		g_prefix_error (
+			error,_("Unable to connect to '%s': "),
+			e_source_get_display_name (source));
 		g_object_unref (client);
 		return NULL;
 	}
@@ -1583,8 +1608,8 @@ cal_client_connect_init_cb (GObject *source_object,
                             gpointer user_data)
 {
 	GSimpleAsyncResult *simple;
-	GCancellable *cancellable;
 	ECalClientPrivate *priv;
+	ConnectClosure *closure;
 	GError *error = NULL;
 
 	simple = G_SIMPLE_ASYNC_RESULT (user_data);
@@ -1602,12 +1627,13 @@ cal_client_connect_init_cb (GObject *source_object,
 
 	result = G_ASYNC_RESULT (simple);
 	source_object = g_async_result_get_source_object (result);
-	cancellable = g_simple_async_result_get_op_res_gpointer (simple);
+	closure = g_simple_async_result_get_op_res_gpointer (simple);
 
 	priv = E_CAL_CLIENT_GET_PRIVATE (source_object);
 
 	e_dbus_calendar_call_open (
-		priv->dbus_proxy, cancellable,
+		priv->dbus_proxy,
+		closure->cancellable,
 		cal_client_connect_open_cb,
 		g_object_ref (simple));
 
@@ -1644,6 +1670,7 @@ e_cal_client_connect (ESource *source,
                       gpointer user_data)
 {
 	GSimpleAsyncResult *simple;
+	ConnectClosure *closure;
 	ECalClient *client;
 
 	g_return_if_fail (E_IS_SOURCE (source));
@@ -1658,6 +1685,12 @@ e_cal_client_connect (ESource *source,
 	 * from our designated D-Bus thread -- it may take a long
 	 * time and block other clients from receiving signals. */
 
+	closure = g_slice_new0 (ConnectClosure);
+	closure->source = g_object_ref (source);
+
+	if (G_IS_CANCELLABLE (cancellable))
+		closure->cancellable = g_object_ref (cancellable);
+
 	client = g_object_new (
 		E_TYPE_CAL_CLIENT,
 		"source", source,
@@ -1669,13 +1702,8 @@ e_cal_client_connect (ESource *source,
 
 	g_simple_async_result_set_check_cancellable (simple, cancellable);
 
-	if (G_IS_CANCELLABLE (cancellable)) {
-		/* XXX Stuff the GCancellable in the GSimpleAsyncResult
-		 *     so we don't have to carry an AsyncContext struct. */
-		g_simple_async_result_set_op_res_gpointer (
-			simple, g_object_ref (cancellable),
-			(GDestroyNotify) g_object_unref);
-	}
+	g_simple_async_result_set_op_res_gpointer (
+		simple, closure, (GDestroyNotify) connect_closure_free);
 
 	g_async_initable_init_async (
 		G_ASYNC_INITABLE (client),
@@ -1696,6 +1724,10 @@ e_cal_client_connect (ESource *source,
  * error occurs in connecting to the D-Bus service, the function sets
  * @error and returns %NULL.
  *
+ * For error handling convenience, any error message returned by this
+ * function will have a descriptive prefix that includes the display
+ * name of the #ESource passed to e_cal_client_connect().
+ *
  * Returns: a new #ECalClient, or %NULL
  *
  * Since: 3.8
@@ -1705,17 +1737,23 @@ e_cal_client_connect_finish (GAsyncResult *result,
                              GError **error)
 {
 	GSimpleAsyncResult *simple;
+	ConnectClosure *closure;
 	gpointer source_tag;
 
 	g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
 
 	simple = G_SIMPLE_ASYNC_RESULT (result);
+	closure = g_simple_async_result_get_op_res_gpointer (simple);
 
 	source_tag = g_simple_async_result_get_source_tag (simple);
 	g_return_val_if_fail (source_tag == e_cal_client_connect, NULL);
 
-	if (g_simple_async_result_propagate_error (simple, error))
+	if (g_simple_async_result_propagate_error (simple, error)) {
+		g_prefix_error (
+			error, _("Unable to connect to '%s': "),
+			e_source_get_display_name (closure->source));
 		return NULL;
+	}
 
 	return E_CLIENT (g_async_result_get_source_object (result));
 }



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