messaging: part index may be repeated in different storages

This commit is contained in:
Aleksander Morgado
2012-03-05 18:29:27 +01:00
parent 120e117c49
commit 22113859c9
3 changed files with 31 additions and 8 deletions

View File

@@ -211,11 +211,17 @@ cmp_sms_by_concat_reference (MMSms *sms,
return (GPOINTER_TO_UINT (user_data) - mm_sms_get_multipart_reference (sms));
}
typedef struct {
guint part_index;
MMSmsStorage storage;
} PartIndexAndStorage;
static guint
cmp_sms_by_part_index (MMSms *sms,
gpointer user_data)
cmp_sms_by_part_index_and_storage (MMSms *sms,
PartIndexAndStorage *ctx)
{
return !mm_sms_has_part_index (sms, GPOINTER_TO_UINT (user_data));
return !(mm_sms_get_storage (sms) == ctx->storage &&
mm_sms_has_part_index (sms, ctx->part_index));
}
static gboolean
@@ -295,10 +301,15 @@ mm_sms_list_take_part (MMSmsList *self,
MMSmsStorage storage,
GError **error)
{
PartIndexAndStorage ctx;
ctx.part_index = mm_sms_part_get_index (part);
ctx.storage = storage;
/* Ensure we don't have already taken a part with the same index */
if (g_list_find_custom (self->priv->list,
GUINT_TO_POINTER (mm_sms_part_get_index (part)),
(GCompareFunc)cmp_sms_by_part_index)) {
&ctx,
(GCompareFunc)cmp_sms_by_part_index_and_storage)) {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,

View File

@@ -347,6 +347,17 @@ mm_sms_get_path (MMSms *self)
return self->priv->path;
}
MMSmsStorage
mm_sms_get_storage (MMSms *self)
{
MMSmsStorage storage = MM_SMS_STORAGE_UNKNOWN;
g_object_get (self,
"storage", &storage,
NULL);
return storage;
}
gboolean
mm_sms_is_multipart (MMSms *self)
{

View File

@@ -103,9 +103,10 @@ gboolean mm_sms_multipart_take_part (MMSms *self,
MMSmsPart *part,
GError **error);
void mm_sms_export (MMSms *self);
void mm_sms_unexport (MMSms *self);
const gchar *mm_sms_get_path (MMSms *self);
void mm_sms_export (MMSms *self);
void mm_sms_unexport (MMSms *self);
const gchar *mm_sms_get_path (MMSms *self);
MMSmsStorage mm_sms_get_storage (MMSms *self);
gboolean mm_sms_has_part_index (MMSms *self,
guint index);