[evolution/webkit: 87/96] Add preparse() virtual method to EMFormat



commit 58b1968b9c85a9ea5aaf6ccfbdd9f602e61dd405
Author: Dan VrÃtil <dvratil redhat com>
Date:   Mon Dec 19 19:16:02 2011 +0100

    Add preparse() virtual method to EMFormat
    
    This method is called when folder and CamelMimeMessage are set in em_format_parse(), but before
    the actual parsing begins. It allows parsers to initialize things that couldn't be
    initialized without knowledge of the message and/or folder

 em-format/em-format.c |   29 +++++++++++++++++------------
 em-format/em-format.h |    2 ++
 mail/em-format-html.c |   31 +++++++++++++++++++++++--------
 3 files changed, 42 insertions(+), 20 deletions(-)
---
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 36b5a2b..2d8bc28 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -1179,6 +1179,7 @@ emf_is_inline (EMFormat *emf,
 	return (handle->flags & EM_FORMAT_HANDLER_INLINE) != 0;
 }
 
+
 /**************************************************************************/
 
 static EMFormatHandler type_handlers[] = {
@@ -1350,31 +1351,31 @@ em_format_finalize (GObject *object)
 }
 
 static void
-em_format_base_init (EMFormatClass *class)
+em_format_base_init (EMFormatClass *klass)
 {
 	gint i;
 
-	class->type_handlers = g_hash_table_new (g_str_hash, g_str_equal);
+	klass->type_handlers = g_hash_table_new (g_str_hash, g_str_equal);
 
 	for (i = 0; i < G_N_ELEMENTS (type_handlers); i++) {
-		g_hash_table_insert (class->type_handlers,
+		g_hash_table_insert (klass->type_handlers,
 				type_handlers[i].mime_type,
 				&type_handlers[i]);
 	}
 }
 
 static void
-em_format_class_init (EMFormatClass *class)
+em_format_class_init (EMFormatClass *klass)
 {
 	GObjectClass *object_class;
 
-	parent_class = g_type_class_peek_parent (class);
+	parent_class = g_type_class_peek_parent (klass);
 
-	g_type_class_add_private (class, sizeof (EMFormatPrivate));
+	g_type_class_add_private (klass, sizeof (EMFormatPrivate));
 
-	class->is_inline = emf_is_inline;
+	klass->is_inline = emf_is_inline;
 
-	object_class = G_OBJECT_CLASS (class);
+	object_class = G_OBJECT_CLASS (klass);
 	object_class->finalize = em_format_finalize;
 	object_class->get_property = em_format_get_property;
 	object_class->set_property = em_format_set_property;
@@ -1864,6 +1865,10 @@ em_format_parse (EMFormat *emf,
 		emf->folder = g_object_ref (folder);
 	}
 
+        /* Before the actual parsing starts, let child classes prepare themselves. */
+        if (EM_FORMAT_GET_CLASS (emf)->preparse)
+                EM_FORMAT_GET_CLASS (emf)->preparse(emf);
+
 	part_id = g_string_new (".message");
 
 	/* Create a special PURI with entire message */
@@ -2002,17 +2007,17 @@ em_format_is_inline (EMFormat *emf,
 		     CamelMimePart *part,
 		     const EMFormatHandler *handler)
 {
-	EMFormatClass *class;
+	EMFormatClass *klass;
 
 	g_return_val_if_fail (EM_IS_FORMAT (emf), FALSE);
 	g_return_val_if_fail (part_id && *part_id, FALSE);
 	g_return_val_if_fail (CAMEL_IS_MIME_PART (part), FALSE);
 	g_return_val_if_fail (handler, FALSE);
 
-	class = EM_FORMAT_GET_CLASS (emf);
-	g_return_val_if_fail (class->is_inline != NULL, FALSE);
+	klass = EM_FORMAT_GET_CLASS (emf);
+	g_return_val_if_fail (klass->is_inline != NULL, FALSE);
 
-	return class->is_inline (emf, part_id, part, handler);
+	return klass->is_inline (emf, part_id, part, handler);
 
 }
 
diff --git a/em-format/em-format.h b/em-format/em-format.h
index 221f6d1..d62d688 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -187,6 +187,8 @@ struct _EMFormatClass {
 							 const gchar *part_id,
 							 CamelMimePart *part,
 							 const EMFormatHandler *handler);
+
+        void            (*preparse)                     (EMFormat *emf);
 };
 
 EMFormat*		em_format_new 			(void);
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index 5c61490..bad3b6e 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -75,7 +75,7 @@ struct _EMFormatHTMLPrivate {
 	GdkColor colors[EM_FORMAT_HTML_NUM_COLOR_TYPES];
 	EMailImageLoadingPolicy image_loading_policy;
 
-	guint load_images_now	: 1;
+	guint can_load_images	: 1;
 	guint only_local_photos	: 1;
 	guint show_sender_photo	: 1;
 	guint show_real_date	: 1;
@@ -1305,20 +1305,35 @@ efh_write_attachment (EMFormat *emf,
 }
 
 static void
-efh_base_init (EMFormatHTMLClass *class)
+efh_preparse (EMFormat *emf)
 {
-	efh_builtin_init (class);
+        CamelInternetAddress *addr;
+
+        EMFormatHTML *efh = EM_FORMAT_HTML (emf);
+
+        addr = camel_mime_message_get_from (emf->message);
+        efh->priv->can_load_images = em_utils_in_addressbook (addr, FALSE);
 }
 
 static void
-efh_class_init (EMFormatHTMLClass *class)
+efh_base_init (EMFormatHTMLClass *klass)
+{
+	efh_builtin_init (klass);
+}
+
+static void
+efh_class_init (EMFormatHTMLClass *klass)
 {
 	GObjectClass *object_class;
+        EMFormatClass *emf_class;
+
+	parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (EMFormatHTMLPrivate));
 
-	parent_class = g_type_class_peek_parent (class);
-	g_type_class_add_private (class, sizeof (EMFormatHTMLPrivate));
+        emf_class = EM_FORMAT_CLASS (klass);
+        emf_class->preparse = efh_preparse;
 
-	object_class = G_OBJECT_CLASS (class);
+	object_class = G_OBJECT_CLASS (klass);
 	object_class->set_property = efh_set_property;
 	object_class->get_property = efh_get_property;
 	object_class->finalize = efh_finalize;
@@ -1443,7 +1458,7 @@ efh_class_init (EMFormatHTMLClass *class)
 
 static void
 efh_init (EMFormatHTML *efh,
-	  EMFormatHTMLClass *class)
+	  EMFormatHTMLClass *klass)
 {
 	GdkColor *color;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]