diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-02-01 16:54:25 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:59 +0100 |
commit | 7956fc4e17dbc53c602c0723739c6390c4a05541 (patch) | |
tree | e61169ffee213cd3c1702ff2887208aca059e219 /src/mm-sms-list.c | |
parent | 9dee04a9717c846ae9de004cf3cacccd811845ee (diff) |
sms-list: allow deleting an SMS object and its parts
Diffstat (limited to 'src/mm-sms-list.c')
-rw-r--r-- | src/mm-sms-list.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/mm-sms-list.c b/src/mm-sms-list.c index a206acd1..846628a4 100644 --- a/src/mm-sms-list.c +++ b/src/mm-sms-list.c @@ -79,6 +79,89 @@ mm_sms_list_get_paths (MMSmsList *self) /*****************************************************************************/ +gboolean +mm_sms_list_delete_sms_finish (MMSmsList *self, + GAsyncResult *res, + GError **error) +{ + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); +} + +static void +delete_parts_ready (MMSms *sms, + GAsyncResult *res, + GSimpleAsyncResult *simple) +{ + GError *error = NULL; + + if (!mm_sms_delete_parts_finish (sms, res, &error)) + /* We report the error, but we really get the SMS removed */ + g_simple_async_result_take_error (simple, error); + else + g_simple_async_result_set_op_res_gboolean (simple, TRUE); + + /* We don't need to unref the SMS any more, but we can use the + * reference we got in the method, which is the one kept alive + * during the async operation. */ + g_signal_emit (MM_SMS_LIST (g_async_result_get_source_object (G_ASYNC_RESULT (simple))), + signals[SIGNAL_DELETED], 0, + mm_sms_get_path (sms)); + + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +static guint +cmp_sms_by_path (MMSms *sms, + const gchar *path) +{ + return strcmp (mm_sms_get_path (sms), path); +} + +void +mm_sms_list_delete_sms (MMSmsList *self, + const gchar *sms_path, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + MMSms *sms; + GList *l; + + result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + mm_sms_list_delete_sms); + + l = g_list_find_custom (self->priv->list, + (gpointer)sms_path, + (GCompareFunc)cmp_sms_by_path); + if (!l) { + g_simple_async_result_set_error (result, + MM_CORE_ERROR, + MM_CORE_ERROR_NOT_FOUND, + "No SMS found with path '%s'", + sms_path); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); + return; + } + + /* Remove it from our list of SMS objects */ + sms = l->data; + self->priv->list = g_list_delete_link (self->priv->list, l); + + mm_sms_delete_parts (sms, + (GAsyncReadyCallback)delete_parts_ready, + result); + + /* We do remove here our last reference to the SMS object. The + * async method will keep its own while the operation is ongoing. */ + g_object_unref (sms); +} + +/*****************************************************************************/ + static guint cmp_sms_by_concat_reference (MMSms *sms, gpointer user_data) |