mmcli: allow passing SMS index in --messaging-delete-sms
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
/* Context */
|
/* Context */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
GDBusConnection *connection;
|
||||||
MMManager *manager;
|
MMManager *manager;
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
MMObject *object;
|
MMObject *object;
|
||||||
@@ -69,7 +70,7 @@ static GOptionEntry entries[] = {
|
|||||||
},
|
},
|
||||||
{ "messaging-delete-sms", 0, 0, G_OPTION_ARG_STRING, &delete_str,
|
{ "messaging-delete-sms", 0, 0, G_OPTION_ARG_STRING, &delete_str,
|
||||||
"Delete a SMS from a given modem",
|
"Delete a SMS from a given modem",
|
||||||
"[PATH]"
|
"[PATH|INDEX]"
|
||||||
},
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
@@ -135,6 +136,8 @@ context_free (Context *ctx)
|
|||||||
g_object_unref (ctx->object);
|
g_object_unref (ctx->object);
|
||||||
if (ctx->manager)
|
if (ctx->manager)
|
||||||
g_object_unref (ctx->manager);
|
g_object_unref (ctx->manager);
|
||||||
|
if (ctx->connection)
|
||||||
|
g_object_unref (ctx->connection);
|
||||||
g_free (ctx);
|
g_free (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,6 +338,30 @@ delete_ready (MMModemMessaging *modem,
|
|||||||
mmcli_async_operation_done ();
|
mmcli_async_operation_done ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
get_sms_to_delete_ready (GDBusConnection *connection,
|
||||||
|
GAsyncResult *res)
|
||||||
|
{
|
||||||
|
MMSms *sms;
|
||||||
|
MMObject *obj = NULL;
|
||||||
|
|
||||||
|
sms = mmcli_get_sms_finish (res, NULL, &obj);
|
||||||
|
if (!g_str_equal (mm_object_get_path (obj), mm_modem_messaging_get_path (ctx->modem_messaging))) {
|
||||||
|
g_printerr ("error: SMS '%s' not owned by modem '%s'",
|
||||||
|
mm_sms_get_path (sms),
|
||||||
|
mm_modem_messaging_get_path (ctx->modem_messaging));
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mm_modem_messaging_delete (ctx->modem_messaging,
|
||||||
|
mm_sms_get_path (sms),
|
||||||
|
ctx->cancellable,
|
||||||
|
(GAsyncReadyCallback)delete_ready,
|
||||||
|
NULL);
|
||||||
|
g_object_unref (sms);
|
||||||
|
g_object_unref (obj);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_modem_ready (GObject *source,
|
get_modem_ready (GObject *source,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
@@ -380,11 +407,11 @@ get_modem_ready (GObject *source,
|
|||||||
|
|
||||||
/* Request to delete a given SMS? */
|
/* Request to delete a given SMS? */
|
||||||
if (delete_str) {
|
if (delete_str) {
|
||||||
mm_modem_messaging_delete (ctx->modem_messaging,
|
mmcli_get_sms (ctx->connection,
|
||||||
delete_str,
|
delete_str,
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback)delete_ready,
|
(GAsyncReadyCallback)get_sms_to_delete_ready,
|
||||||
NULL);
|
NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,6 +426,7 @@ mmcli_modem_messaging_run_asynchronous (GDBusConnection *connection,
|
|||||||
ctx = g_new0 (Context, 1);
|
ctx = g_new0 (Context, 1);
|
||||||
if (cancellable)
|
if (cancellable)
|
||||||
ctx->cancellable = g_object_ref (cancellable);
|
ctx->cancellable = g_object_ref (cancellable);
|
||||||
|
ctx->connection = g_object_ref (connection);
|
||||||
|
|
||||||
/* Get proper modem */
|
/* Get proper modem */
|
||||||
mmcli_get_modem (connection,
|
mmcli_get_modem (connection,
|
||||||
@@ -465,11 +493,26 @@ mmcli_modem_messaging_run_synchronous (GDBusConnection *connection)
|
|||||||
/* Request to delete a given SMS? */
|
/* Request to delete a given SMS? */
|
||||||
if (delete_str) {
|
if (delete_str) {
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
MMSms *sms;
|
||||||
|
MMObject *obj = NULL;
|
||||||
|
|
||||||
|
sms = mmcli_get_sms_sync (connection,
|
||||||
|
delete_str,
|
||||||
|
NULL,
|
||||||
|
&obj);
|
||||||
|
if (!g_str_equal (mm_object_get_path (obj), mm_modem_messaging_get_path (ctx->modem_messaging))) {
|
||||||
|
g_printerr ("error: SMS '%s' not owned by modem '%s'",
|
||||||
|
mm_sms_get_path (sms),
|
||||||
|
mm_modem_messaging_get_path (ctx->modem_messaging));
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
result = mm_modem_messaging_delete_sync (ctx->modem_messaging,
|
result = mm_modem_messaging_delete_sync (ctx->modem_messaging,
|
||||||
delete_str,
|
mm_sms_get_path (sms),
|
||||||
NULL,
|
NULL,
|
||||||
&error);
|
&error);
|
||||||
|
g_object_unref (sms);
|
||||||
|
g_object_unref (obj);
|
||||||
|
|
||||||
delete_process_reply (result, error);
|
delete_process_reply (result, error);
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user