aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-07-26 20:27:53 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-08-03 23:40:13 +0800
commitd2f9d47b214d636109759239c49ddfe22e7b8326 (patch)
treed881046c2e375dfae1284bf3e15211deab84a16a
parent4fedf14c7b90d1bab1906d0e1ffd676af620c15c (diff)
downloadgsoc2013-evolution-d2f9d47b214d636109759239c49ddfe22e7b8326.tar.gz
gsoc2013-evolution-d2f9d47b214d636109759239c49ddfe22e7b8326.tar.zst
gsoc2013-evolution-d2f9d47b214d636109759239c49ddfe22e7b8326.zip
e-source-utils.c cleanups.
Also add missing error definitions.
-rw-r--r--e-util/e-source-util.c86
-rw-r--r--e-util/e-system.error.xml10
2 files changed, 58 insertions, 38 deletions
diff --git a/e-util/e-source-util.c b/e-util/e-source-util.c
index 61b7897d32..44a60bcee1 100644
--- a/e-util/e-source-util.c
+++ b/e-util/e-source-util.c
@@ -22,32 +22,35 @@ typedef struct _AsyncContext AsyncContext;
struct _AsyncContext {
EActivity *activity;
- ESource *source;
};
static void
-async_context_free (AsyncContext *context)
+async_context_free (AsyncContext *async_context)
{
- if (context->activity != NULL)
- g_object_unref (context->activity);
-
- if (context->source != NULL)
- g_object_unref (context->source);
+ if (async_context->activity != NULL)
+ g_object_unref (async_context->activity);
- g_slice_free (AsyncContext, context);
+ g_slice_free (AsyncContext, async_context);
}
static void
-source_util_remove_cb (ESource *source,
+source_util_remove_cb (GObject *source_object,
GAsyncResult *result,
- AsyncContext *context)
+ gpointer user_data)
{
+ ESource *source;
EActivity *activity;
EAlertSink *alert_sink;
+ AsyncContext *async_context;
+ const gchar *display_name;
GError *error = NULL;
- activity = context->activity;
+ source = E_SOURCE (source_object);
+ async_context = (AsyncContext *) user_data;
+
+ activity = async_context->activity;
alert_sink = e_activity_get_alert_sink (activity);
+ display_name = e_source_get_display_name (source);
e_source_remove_finish (source, result, &error);
@@ -57,16 +60,15 @@ source_util_remove_cb (ESource *source,
} else if (error != NULL) {
e_alert_submit (
alert_sink,
- "source:remove-source-fail",
- e_source_get_display_name (context->source),
- error->message, NULL);
+ "system:remove-source-fail",
+ display_name, error->message, NULL);
g_error_free (error);
} else {
e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
}
- async_context_free (context);
+ async_context_free (async_context);
}
/**
@@ -88,7 +90,7 @@ EActivity *
e_source_util_remove (ESource *source,
EAlertSink *alert_sink)
{
- AsyncContext *context;
+ AsyncContext *async_context;
GCancellable *cancellable;
g_return_val_if_fail (E_IS_SOURCE (source), NULL);
@@ -96,33 +98,40 @@ e_source_util_remove (ESource *source,
cancellable = g_cancellable_new ();
- context = g_slice_new0 (AsyncContext);
- context->activity = e_activity_new ();
- context->source = g_object_ref (source);
+ async_context = g_slice_new0 (AsyncContext);
+ async_context->activity = e_activity_new ();
- e_activity_set_alert_sink (context->activity, alert_sink);
- e_activity_set_cancellable (context->activity, cancellable);
+ e_activity_set_alert_sink (async_context->activity, alert_sink);
+ e_activity_set_cancellable (async_context->activity, cancellable);
e_source_remove (
- source, cancellable, (GAsyncReadyCallback)
- source_util_remove_cb, context);
+ source, cancellable,
+ source_util_remove_cb,
+ async_context);
g_object_unref (cancellable);
- return context->activity;
+ return async_context->activity;
}
static void
-source_util_write_cb (ESource *source,
+source_util_write_cb (GObject *source_object,
GAsyncResult *result,
- AsyncContext *context)
+ gpointer user_data)
{
+ ESource *source;
EActivity *activity;
EAlertSink *alert_sink;
+ AsyncContext *async_context;
+ const gchar *display_name;
GError *error = NULL;
- activity = context->activity;
+ source = E_SOURCE (source_object);
+ async_context = (AsyncContext *) user_data;
+
+ activity = async_context->activity;
alert_sink = e_activity_get_alert_sink (activity);
+ display_name = e_source_get_display_name (source);
e_source_write_finish (source, result, &error);
@@ -132,15 +141,15 @@ source_util_write_cb (ESource *source,
} else if (error != NULL) {
e_alert_submit (
alert_sink,
- "source:submit-data-fail",
- error->message, NULL);
+ "system:write-source-fail",
+ display_name, error->message, NULL);
g_error_free (error);
} else {
e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
}
- async_context_free (context);
+ async_context_free (async_context);
}
/**
@@ -162,7 +171,7 @@ EActivity *
e_source_util_write (ESource *source,
EAlertSink *alert_sink)
{
- AsyncContext *context;
+ AsyncContext *async_context;
GCancellable *cancellable;
g_return_val_if_fail (E_IS_SOURCE (source), NULL);
@@ -170,18 +179,19 @@ e_source_util_write (ESource *source,
cancellable = g_cancellable_new ();
- context = g_slice_new0 (AsyncContext);
- context->activity = e_activity_new ();
+ async_context = g_slice_new0 (AsyncContext);
+ async_context->activity = e_activity_new ();
- e_activity_set_alert_sink (context->activity, alert_sink);
- e_activity_set_cancellable (context->activity, cancellable);
+ e_activity_set_alert_sink (async_context->activity, alert_sink);
+ e_activity_set_cancellable (async_context->activity, cancellable);
e_source_write (
- source, cancellable, (GAsyncReadyCallback)
- source_util_write_cb, context);
+ source, cancellable,
+ source_util_write_cb,
+ async_context);
g_object_unref (cancellable);
- return context->activity;
+ return async_context->activity;
}
diff --git a/e-util/e-system.error.xml b/e-util/e-system.error.xml
index 64727e047a..04d3f3a758 100644
--- a/e-util/e-system.error.xml
+++ b/e-util/e-system.error.xml
@@ -30,4 +30,14 @@
<_secondary>Because "{1}".</_secondary>
</error>
+ <error id="remove-source-fail" type="error">
+ <_primary>Failed to remove data source &quot;{0}&quot;.</_primary>
+ <_secondary>The reported error was &quot;{1}&quot;.</_secondary>
+ </error>
+
+ <error id="write-source-fail" type="error">
+ <_primary>Failed to update data source &quot;{0}&quot;.</_primary>
+ <_secondary>The reported error was &quot;{1}&quot;.</_secondary>
+ </error>
+
</error-list>