[evolution/webkit: 97/182] Put back em_format_default_headers() and allow EMFormat to request redraw



commit 13ca51c7b44a2772d9ac82ce019102b9548f7409
Author: Dan VrÃtil <dvratil redhat com>
Date:   Wed Jan 4 16:46:19 2012 +0100

    Put back em_format_default_headers() and allow EMFormat to request redraw
    
    EMFormat can inform a widget (possibly EMailDisplay) that someting has changed
    and that the message should be re-rendered. This may happen for example when
    list of headers to be displayed changes.

 em-format/em-format.c |   49 ++++++++++++++++++++++++++++++++++++++++++-------
 em-format/em-format.h |    7 +++++++
 mail/e-mail-display.c |   11 +++++++++--
 3 files changed, 58 insertions(+), 9 deletions(-)
---
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 896b096..e881f63 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -63,6 +63,13 @@ enum {
 	PROP_BASE_URL
 };
 
+enum {
+	REDRAW_REQUESTED,
+	LAST_SIGNAL
+};
+
+gint signals[LAST_SIGNAL];
+
 static gpointer parent_class;
 
 /* PARSERS */
@@ -1413,6 +1420,15 @@ em_format_class_init (EMFormatClass *klass)
 					NULL,
 					NULL,
 					G_PARAM_READWRITE));
+
+	signals[REDRAW_REQUESTED] = g_signal_new (
+		"redraw-requested",
+		G_TYPE_FROM_CLASS (klass),
+		G_SIGNAL_RUN_LAST,
+		G_STRUCT_OFFSET (EMFormatClass, redraw_requested),
+		NULL, NULL,
+		g_cclosure_marshal_VOID__VOID,
+		G_TYPE_NONE,0);
 }
 
 static void
@@ -1429,7 +1445,6 @@ em_format_init (EMFormat *emf)
 {
 	EShell *shell;
 	EShellSettings *shell_settings;
-	gint ii;
 
 	emf->priv = G_TYPE_INSTANCE_GET_PRIVATE (emf,
 			EM_TYPE_FORMAT, EMFormatPrivate);
@@ -1451,12 +1466,7 @@ em_format_init (EMFormat *emf)
 
 	g_object_ref (emf->priv->session);
 
-	/* Set the default headers */
-	em_format_clear_headers (emf);
-	for (ii = 0; ii < G_N_ELEMENTS (default_headers); ii++)
-		em_format_add_header (
-			emf, default_headers[ii].name, NULL,
-			default_headers[ii].flags);
+	em_format_default_headers (emf);
 }
 
 EMFormat*
@@ -1617,6 +1627,21 @@ em_format_clear_headers (EMFormat *emf)
 
 }
 
+void
+em_format_default_headers (EMFormat *emf)
+{
+	gint ii;
+
+	g_return_if_fail (EM_IS_FORMAT (emf));
+
+	/* Set the default headers */
+	em_format_clear_headers (emf);
+	for (ii = 0; ii < G_N_ELEMENTS (default_headers); ii++)
+		em_format_add_header (
+			emf, default_headers[ii].name, NULL,
+			default_headers[ii].flags);
+}
+
 /**
  * em_format_add_header:
  * @emf:
@@ -2454,6 +2479,16 @@ em_format_build_mail_uri (CamelFolder *folder,
 	return uri;
 }
 
+void
+em_format_redraw (EMFormat *emf)
+{
+	g_return_if_fail (EM_IS_FORMAT (emf));
+
+	g_signal_emit (emf, signals[REDRAW_REQUESTED], 0);
+}
+
+
+
 
 /**************************************************************************/
 EMFormatPURI*
diff --git a/em-format/em-format.h b/em-format/em-format.h
index d62d688..c9c38be 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -189,6 +189,9 @@ struct _EMFormatClass {
 							 const EMFormatHandler *handler);
 
         void            (*preparse)                     (EMFormat *emf);
+
+	/* signals */
+	void		(*redraw_requested)		(EMFormat *emf);
 };
 
 EMFormat*		em_format_new 			(void);
@@ -215,6 +218,8 @@ CamelURL*		em_format_get_base_url		(EMFormat *emf);
 
 void			em_format_clear_headers		(EMFormat *emf);
 
+void			em_format_default_headers	(EMFormat *emf);
+
 void			em_format_add_header		(EMFormat *emf,
 							 const gchar *name,
 							 const gchar *value,
@@ -306,6 +311,8 @@ void			em_format_empty_writer 		(EMFormat *emf,
 							 EMFormatWriterInfo *info,
 							 GCancellable *cancellable);
 
+void			em_format_redraw		(EMFormat *emf);
+
 
 EMFormatPURI*		em_format_puri_new 		(EMFormat *emf,
 							 gsize puri_size,
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 4c25d81..2502704 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -1069,13 +1069,18 @@ void
 e_mail_display_set_formatter (EMailDisplay *display,
                               EMFormatHTML *formatter)
 {
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
+        g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 	g_return_if_fail (EM_IS_FORMAT_HTML (formatter));
 
 	g_object_ref (formatter);
 	
-	if (display->priv->formatter != NULL)
+	if (display->priv->formatter != NULL) {
+		/* The formatter might still exist after unrefing it, so 
+		 * we need to stop listening to it's request for redrawing */
+		g_signal_handlers_disconnect_by_func (
+			display->priv->formatter, e_mail_display_reload, display);
 		g_object_unref (display->priv->formatter);
+	}
 
 	display->priv->formatter = formatter;
 
@@ -1083,6 +1088,8 @@ e_mail_display_set_formatter (EMailDisplay *display,
 
         g_signal_connect (formatter, "notify::image-loading-policy",
                 G_CALLBACK (formatter_image_loading_policy_changed_cb), display);
+	g_signal_connect_swapped (formatter, "redraw-requested",
+		G_CALLBACK (e_mail_display_reload), display);
 
 	g_object_notify (G_OBJECT (display), "formatter");
 }



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