sms-list: allow deleting an SMS object and its parts
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -69,4 +69,12 @@ gboolean mm_sms_list_take_part (MMSmsList *self,
|
||||
gboolean received,
|
||||
GError **error);
|
||||
|
||||
void mm_sms_list_delete_sms (MMSmsList *self,
|
||||
const gchar *sms_path,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gboolean mm_sms_list_delete_sms_finish (MMSmsList *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_SMS_LIST_H */
|
||||
|
||||
Reference in New Issue
Block a user