aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-02-10 14:37:59 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:15:03 +0100
commit69ecae2dc46f6cd6292f11e3c397234c0cb375e7 (patch)
treeb92ffa8425c7c07e887333dbb52e6a92e627cd69
parente6e7aa1846ec0591f1566a2d111d5775f31f2b74 (diff)
iface-modem-messaging: new method to set preferred SMS storages
-rw-r--r--src/mm-iface-modem-messaging.c73
-rw-r--r--src/mm-iface-modem-messaging.h22
2 files changed, 95 insertions, 0 deletions
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 */