aboutsummaryrefslogtreecommitdiffstats
path: root/em-format
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
parent031c40a51791b2ebcd44f880c96860b987e1a00c (diff)
downloadgsoc2013-evolution-fe59b10f04b794759f64d97281d907d7dce39972.tar
gsoc2013-evolution-fe59b10f04b794759f64d97281d907d7dce39972.tar.gz
gsoc2013-evolution-fe59b10f04b794759f64d97281d907d7dce39972.tar.bz2
gsoc2013-evolution-fe59b10f04b794759f64d97281d907d7dce39972.tar.lz
gsoc2013-evolution-fe59b10f04b794759f64d97281d907d7dce39972.tar.xz
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')
-rw-r--r--em-format/e-mail-part-list.c54
-rw-r--r--em-format/e-mail-part-list.h13
2 files changed, 64 insertions, 3 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
diff --git a/em-format/e-mail-part-list.h b/em-format/e-mail-part-list.h
index 12a24f365f..d0c2055b31 100644
--- a/em-format/e-mail-part-list.h
+++ b/em-format/e-mail-part-list.h
@@ -61,16 +61,23 @@ struct _EMailPartListClass {
GObjectClass parent_class;
};
-EMailPartList * e_mail_part_list_new ();
+EMailPartList * e_mail_part_list_new (void);
-GType e_mail_part_list_get_type ();
+GType e_mail_part_list_get_type (void);
EMailPart * e_mail_part_list_find_part (EMailPartList *part_list,
const gchar *id);
-GSList * e_mail_part_list_get_iter (GSList *list,
+GSList * e_mail_part_list_get_iter (GSList *list,
const gchar *id);
+CamelObjectBag *
+ e_mail_part_list_get_registry (void);
+
+void e_mail_part_list_registry_add (CamelObjectBag *registry,
+ const gchar *mail_uri,
+ EMailPartList *part_list);
+
G_END_DECLS
#endif /* E_MAIL_PART_LIST_H_ */