sms: create SMS parts only when storing or sending

When a user creates an SMS object, we will expose all its properties in DBus
properly, but we will not create the internal list of SMS parts.

The list of SMS parts will be created when the SMS is stored or sent, whatever
comes first. When the message is sent and it was previously stored, the list of
parts is not re-created.

If the message requires multiple parts, the multipart reference is computed as
follows:
 * If the SMS was not stored and is being sent, we just use a random number.
 * If the SMS is being stored, we will use a multipart reference which is not
   being used already in another SMS to the same destination.
This commit is contained in:
Aleksander Morgado
2012-09-13 12:00:37 +02:00
parent 2da9474d0c
commit e212f6b6ed
7 changed files with 320 additions and 145 deletions

View File

@@ -31,6 +31,54 @@ static GQuark storage_context_quark;
/*****************************************************************************/
guint8
mm_iface_modem_messaging_get_local_multipart_reference (MMIfaceModemMessaging *self,
const gchar *number,
GError **error)
{
MMSmsList *list = NULL;
guint8 reference;
guint8 first;
/* Start by looking for a random number */
reference = g_random_int_range (1,255);
/* Then, look for the given reference in user-created messages */
g_object_get (self,
MM_IFACE_MODEM_MESSAGING_SMS_LIST, &list,
NULL);
if (!list)
return reference;
first = reference;
do {
if (!mm_sms_list_has_local_multipart_reference (list, number, reference)) {
g_object_unref (list);
return reference;
}
if (reference == 255)
reference = 1;
else
reference++;
}
while (reference != first);
g_object_unref (list);
/* We were not able to find a new valid multipart reference :/
* return an error */
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_TOO_MANY,
"Cannot create multipart SMS: No valid multipart reference "
"available for destination number '%s'",
number);
return 0;
}
/*****************************************************************************/
void
mm_iface_modem_messaging_bind_simple_status (MMIfaceModemMessaging *self,
MMSimpleStatus *status)