From 69ecae2dc46f6cd6292f11e3c397234c0cb375e7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 10 Feb 2012 14:37:59 +0100 Subject: iface-modem-messaging: new method to set preferred SMS storages --- src/mm-iface-modem-messaging.c | 73 ++++++++++++++++++++++++++++++++++++++++++ src/mm-iface-modem-messaging.h | 22 +++++++++++++ 2 files changed, 95 insertions(+) (limited to 'src') diff --git a/src/mm-iface-modem-messaging.c b/src/mm-iface-modem-messaging.c index 0268ca92..e106821f 100644 --- a/src/mm-iface-modem-messaging.c +++ b/src/mm-iface-modem-messaging.c @@ -298,6 +298,79 @@ mm_iface_modem_messaging_take_part (MMIfaceModemMessaging *self, /*****************************************************************************/ +gboolean +mm_iface_modem_messaging_set_preferred_storages_finish (MMIfaceModemMessaging *self, + GAsyncResult *res, + GError **error) +{ + if (MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_preferred_storages_finish) + return MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_preferred_storages_finish (self, res, error); + + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); +} + +static gboolean +is_storage_supported (GArray *supported, + MMSmsStorage preferred, + const gchar *name, + GError **error) +{ + guint i; + + for (i = 0; i < supported->len; i++) { + if (preferred == g_array_index (supported, MMSmsStorage, i)) + return TRUE; + } + + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Storage '%s' is not supported in '%s'", + mm_sms_storage_get_string (preferred), + name); + return FALSE; +} + +void +mm_iface_modem_messaging_set_preferred_storages (MMIfaceModemMessaging *self, + MMSmsStorage mem1, + MMSmsStorage mem2, + MMSmsStorage mem3, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GError *error = NULL; + StorageContext *ctx; + + if (!MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_preferred_storages || + !MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_preferred_storages_finish) { + g_simple_async_report_error_in_idle (G_OBJECT (self), + callback, + user_data, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Setting preferred storage is not supported"); + return; + } + + /* Check if the requested storages are really supported */ + ctx = get_storage_context (self); + if (!is_storage_supported (ctx->supported_mem1, mem1, "mem1", &error) || + !is_storage_supported (ctx->supported_mem2, mem2, "mem2", &error) || + !is_storage_supported (ctx->supported_mem3, mem3, "mem3", &error)) { + g_simple_async_report_take_gerror_in_idle (G_OBJECT (self), + callback, + user_data, + error); + return; + } + + MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_preferred_storages ( + self, mem1, mem2, mem3, callback, user_data); +} + +/*****************************************************************************/ + static void sms_added (MMSmsList *list, const gchar *sms_path, diff --git a/src/mm-iface-modem-messaging.h b/src/mm-iface-modem-messaging.h index fdb6c049..e3268af3 100644 --- a/src/mm-iface-modem-messaging.h +++ b/src/mm-iface-modem-messaging.h @@ -63,6 +63,17 @@ struct _MMIfaceModemMessaging { GArray **mem3, GError **error); + /* Set preferred storages (async) */ + void (* set_preferred_storages) (MMIfaceModemMessaging *self, + MMSmsStorage mem1, + MMSmsStorage mem2, + MMSmsStorage mem3, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (*set_preferred_storages_finish) (MMIfaceModemMessaging *self, + GAsyncResult *res, + GError **error); + /* Setup SMS format (async) */ void (* setup_sms_format) (MMIfaceModemMessaging *self, GAsyncReadyCallback callback, @@ -139,4 +150,15 @@ gboolean mm_iface_modem_messaging_take_part (MMIfaceModemMessaging *self, MMSmsPart *sms_part, MMSmsState state); +/* Set preferred storages */ +void mm_iface_modem_messaging_set_preferred_storages (MMIfaceModemMessaging *self, + MMSmsStorage mem1, + MMSmsStorage mem2, + MMSmsStorage mem3, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_iface_modem_messaging_set_preferred_storages_finish (MMIfaceModemMessaging *self, + GAsyncResult *res, + GError **error); + #endif /* MM_IFACE_MODEM_MESSAGING_H */ -- cgit v1.2.3-70-g09d2