aboutsummaryrefslogtreecommitdiffstats
path: root/em-format/e-mail-part-list.c
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2012-06-18 19:44:58 +0800
committerDan Vrátil <dvratil@redhat.com>2012-06-18 19:44:58 +0800
commitfe59b10f04b794759f64d97281d907d7dce39972 (patch)
tree812d45440f6cfabe7681a03ad5fc2808306764ad /em-format/e-mail-part-list.c
parent031c40a51791b2ebcd44f880c96860b987e1a00c (diff)
downloadgsoc2013-evolution-fe59b10f04b794759f64d97281d907d7dce39972.tar.gz
gsoc2013-evolution-fe59b10f04b794759f64d97281d907d7dce39972.tar.zst
gsoc2013-evolution-fe59b10f04b794759f64d97281d907d7dce39972.zip
Bug #677608 - Fails to open message which is not yet downloaded
Diffstat (limited to 'em-format/e-mail-part-list.c')
-rw-r--r--em-format/e-mail-part-list.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/em-format/e-mail-part-list.c b/em-format/e-mail-part-list.c
index 743834beef..0ad8a9198f 100644
--- a/em-format/e-mail-part-list.c
+++ b/em-format/e-mail-part-list.c
@@ -22,6 +22,10 @@
G_DEFINE_TYPE (EMailPartList, e_mail_part_list, G_TYPE_OBJECT)
+
+static CamelObjectBag *registry = NULL;
+G_LOCK_DEFINE_STATIC (registry);
+
static void
unref_mail_part (gpointer user_data)
{
@@ -128,3 +132,53 @@ e_mail_part_list_get_iter (GSList *list,
return NULL;
}
+
+/**
+ * e_mail_part_list_get_registry:
+ *
+ * Returns a #CamelObjectBag where parsed #EMailPartLists can be stored.
+ */
+CamelObjectBag *
+e_mail_part_list_get_registry (void)
+{
+ G_LOCK (registry);
+ if (registry == NULL) {
+ registry = camel_object_bag_new (
+ g_str_hash, g_str_equal,
+ (CamelCopyFunc) g_strdup, g_free);
+ }
+ G_UNLOCK (registry);
+
+ return registry;
+}
+
+static void
+part_list_weak_ref_notify (gchar *mail_uri,
+ EMailPartList *part_list)
+{
+ CamelObjectBag *reg = e_mail_part_list_get_registry ();
+
+ camel_object_bag_remove (reg, part_list);
+}
+
+/**
+ * e_mail_part_list_registry_add:
+ *
+ * This method should be used to add a new @part_list to the
+ * #CamelObjectBag registry. It will automatically handle removing
+ * the @part_list from the bag when it's destroyed.
+ *
+ * The @registry don't take any reference to the @part_list.
+ */
+void
+e_mail_part_list_registry_add (CamelObjectBag *registry,
+ const gchar *mail_uri,
+ EMailPartList *part_list)
+{
+ camel_object_bag_add (registry, mail_uri, part_list);
+
+ g_object_weak_ref (
+ G_OBJECT (part_list),
+ (GWeakNotify) part_list_weak_ref_notify,
+ g_strdup (mail_uri));
+} \ No newline at end of file