diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2012-08-03 05:19:30 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2012-08-03 23:40:13 +0800 |
commit | aa8b7b68fc3ac2f877cde7afcac096477f3b3e56 (patch) | |
tree | b1df38305630b66e5081446c07c57d8b0f6ce141 | |
parent | d2f9d47b214d636109759239c49ddfe22e7b8326 (diff) | |
download | gsoc2013-evolution-aa8b7b68fc3ac2f877cde7afcac096477f3b3e56.tar gsoc2013-evolution-aa8b7b68fc3ac2f877cde7afcac096477f3b3e56.tar.gz gsoc2013-evolution-aa8b7b68fc3ac2f877cde7afcac096477f3b3e56.tar.bz2 gsoc2013-evolution-aa8b7b68fc3ac2f877cde7afcac096477f3b3e56.tar.lz gsoc2013-evolution-aa8b7b68fc3ac2f877cde7afcac096477f3b3e56.tar.xz gsoc2013-evolution-aa8b7b68fc3ac2f877cde7afcac096477f3b3e56.tar.zst gsoc2013-evolution-aa8b7b68fc3ac2f877cde7afcac096477f3b3e56.zip |
Add e_source_util_remote_delete().
Wraps e_source_remote_delete() in an EActivity and submits errors to the
given EAlertSink.
-rw-r--r-- | e-util/e-source-util.c | 83 | ||||
-rw-r--r-- | e-util/e-source-util.h | 2 | ||||
-rw-r--r-- | e-util/e-system.error.xml | 5 |
3 files changed, 90 insertions, 0 deletions
diff --git a/e-util/e-source-util.c b/e-util/e-source-util.c index 44a60bcee1..5488c46e5d 100644 --- a/e-util/e-source-util.c +++ b/e-util/e-source-util.c @@ -195,3 +195,86 @@ e_source_util_write (ESource *source, return async_context->activity; } +static void +source_util_remote_delete_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + ESource *source; + EActivity *activity; + EAlertSink *alert_sink; + AsyncContext *async_context; + const gchar *display_name; + GError *error = NULL; + + 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_remote_delete_finish (source, result, &error); + + if (e_activity_handle_cancellation (activity, error)) { + g_error_free (error); + + } else if (error != NULL) { + e_alert_submit ( + alert_sink, + "system:delete-resource-fail", + display_name, error->message, NULL); + g_error_free (error); + + } else { + e_activity_set_state (activity, E_ACTIVITY_COMPLETED); + } + + async_context_free (async_context); +} + +/** + * e_source_util_remote_delete: + * @source: an #ESource + * @alert_sink: an #EAlertSink + * + * Deletes the resource represented by @source from a remote server. + * The @source must be #ESource:remote-deletable. This will also delete + * the key file for @source and broadcast its removal to all clients, + * similar to e_source_util_remove(). If an error occurs, an #EAlert + * will be posted to @alert_sink. + * + * This function does not block. The returned #EActivity can either be + * ignored or passed to something that can display activity status to the + * user, such as e_shell_backend_add_activity(). + * + * Returns: an #EActivity to track the operation + **/ +EActivity * +e_source_util_remote_delete (ESource *source, + EAlertSink *alert_sink) +{ + AsyncContext *async_context; + GCancellable *cancellable; + + g_return_val_if_fail (E_IS_SOURCE (source), NULL); + g_return_val_if_fail (E_IS_ALERT_SINK (alert_sink), NULL); + + cancellable = g_cancellable_new (); + + async_context = g_slice_new0 (AsyncContext); + async_context->activity = e_activity_new (); + + e_activity_set_alert_sink (async_context->activity, alert_sink); + e_activity_set_cancellable (async_context->activity, cancellable); + + e_source_remote_delete ( + source, cancellable, + source_util_remote_delete_cb, + async_context); + + g_object_unref (cancellable); + + return async_context->activity; +} + diff --git a/e-util/e-source-util.h b/e-util/e-source-util.h index 304a55f696..452e91113d 100644 --- a/e-util/e-source-util.h +++ b/e-util/e-source-util.h @@ -36,6 +36,8 @@ EActivity * e_source_util_remove (ESource *source, EAlertSink *alert_sink); EActivity * e_source_util_write (ESource *source, EAlertSink *alert_sink); +EActivity * e_source_util_remote_delete (ESource *source, + EAlertSink *alert_sink); G_END_DECLS diff --git a/e-util/e-system.error.xml b/e-util/e-system.error.xml index 04d3f3a758..c1a68c5881 100644 --- a/e-util/e-system.error.xml +++ b/e-util/e-system.error.xml @@ -40,4 +40,9 @@ <_secondary>The reported error was "{1}".</_secondary> </error> + <error id="delete-resource-fail" type="error"> + <_primary>Failed to delete resource "{0}".</_primary> + <_secondary>The reported error was "{1}".</_secondary> + </error> + </error-list> |