[evolution] Bug #679404 - Read colors for message preview from Gtk theme



commit 440e43d2894fdd517cc91302d4364b082e7d1d8b
Author: Dan VrÃtil <dvratil redhat com>
Date:   Fri Jul 27 12:12:39 2012 +0200

    Bug #679404 - Read colors for message preview from Gtk theme

 data/webview.css                               |   10 --------
 e-util/e-util.c                                |   25 ++++++++++++++++++++
 e-util/e-util.h                                |    2 +
 em-format/e-mail-formatter.c                   |   12 +++++++--
 mail/e-mail-display.c                          |   29 ++++++++++++-----------
 modules/itip-formatter/e-mail-formatter-itip.c |    2 +-
 modules/itip-formatter/itip-view.c             |   13 ++++------
 modules/itip-formatter/itip-view.h             |    4 ++-
 widgets/misc/e-web-view.c                      |   19 ++++++++++++++-
 9 files changed, 78 insertions(+), 38 deletions(-)
---
diff --git a/data/webview.css b/data/webview.css
index a8a936d..8d4c339 100644
--- a/data/webview.css
+++ b/data/webview.css
@@ -12,21 +12,12 @@ body {
   margin: 10px;
 }
 
-h1, h2, h3 {
-  color: #7f7f7f;
-}
-
 th {
-  color: #7f7f7f;
   text-align: left;
   font-weight: normal;
   vertical-align: top;
 }
 
-.header {
-  color: #7f7f7f;
-}
-
 span.navigable, div.navigable, p.navigable {
   cursor: pointer;
   text-decoration: underline;
@@ -123,7 +114,6 @@ object { /* GtkWidgets */
 }
 
 .itip th {
-  color: #000;
   vertical-align: middle;
 }
 
diff --git a/e-util/e-util.c b/e-util/e-util.c
index a579985..2f84c34 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -835,6 +835,31 @@ e_color_to_value (GdkColor *color)
 	return (guint32) (((red << 16) | (green << 8) | blue) & 0xffffff);
 }
 
+/**
+ * e_rgba_to_value:
+ * @rgba: a #GdkRGBA
+ *
+
+ * Converts #GdkRGBA to a 24-bit RGB color value
+ *
+ * Returns: a 24-bit color value
+ **/
+guint32
+e_rgba_to_value (GdkRGBA *rgba)
+{
+	guint16 red;
+	guint16 green;
+	guint16 blue;
+
+	g_return_val_if_fail (rgba != NULL, 0);
+
+	red = ((guint16) (G_MAXUINT16 * rgba->red)) >> 8;
+	green = ((guint16) (G_MAXUINT16 * rgba->green)) >> 8;
+	blue = ((guint16) (G_MAXUINT16 * rgba->blue)) >> 8;
+
+	return (guint32) (((red << 16) | (green << 8) | blue) & 0xffffff);
+}
+
 static gint
 epow10 (gint number)
 {
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 11dd775..fa98153 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -86,6 +86,8 @@ gint		e_int_compare                   (gconstpointer x,
 						 gconstpointer y);
 guint32		e_color_to_value		(GdkColor *color);
 
+guint32		e_rgba_to_value			(GdkRGBA *rgba);
+
 /* This only makes a filename safe for usage as a filename.
  * It still may have shell meta-characters in it. */
 gchar *		e_format_number			(gint number);
diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c
index 2957f86..99b0036 100644
--- a/em-format/e-mail-formatter.c
+++ b/em-format/e-mail-formatter.c
@@ -1060,12 +1060,18 @@ e_mail_formatter_get_html_header (EMailFormatter *formatter)
 		"<title>Evolution Mail Display</title>\n"
 		"<link type=\"text/css\" rel=\"stylesheet\" href=\"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview.css\" />\n"
 		"<style type=\"text/css\">\n"
-		"  table th { color: #000; font-weight: bold; }\n"
+		"  table th { color: #%06x; font-weight: bold; }\n"
 		"</style>\n"
-		"</head><body bgcolor=\"#%06x\">",
+		"</head><body bgcolor=\"#%06x\" text=\"#%06x\">",
 		e_color_to_value ((GdkColor *)
 			e_mail_formatter_get_color (
-				formatter, E_MAIL_FORMATTER_COLOR_BODY)));
+				formatter, E_MAIL_FORMATTER_COLOR_HEADER)),
+		e_color_to_value ((GdkColor *)
+			e_mail_formatter_get_color (
+				formatter, E_MAIL_FORMATTER_COLOR_BODY)),
+		e_color_to_value ((GdkColor *)
+			e_mail_formatter_get_color (
+				formatter, E_MAIL_FORMATTER_COLOR_TEXT)));
 }
 
 EMailExtensionRegistry *
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 6cbbaa6..57666ea 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -1802,24 +1802,25 @@ void
 e_mail_display_set_status (EMailDisplay *display,
                            const gchar *status)
 {
-	gchar *str;
+	gchar *str, *header;
 
 	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
+	header = e_mail_formatter_get_html_header (display->priv->formatter);
 	str = g_strdup_printf (
-		"<!DOCTYPE>"
-		"<html>"
-		  "<head><title>Evolution Mail Display</title></head>"
-		  "<body>"
-		    "<table border=\"0\" width=\"100%%\" height=\"100%%\">"
-		      "<tr height=\"100%%\" valign=\"middle\">"
-			"<td width=\"100%%\" align=\"center\">"
-			  "<strong>%s</strong>"
-			"</td>"
-		      "</tr>"
-		    "</table>"
-		  "</body>"
-		"</html>", status);
+		"%s\n"
+		"  <style>html, body { height: 100%%; }</style>\n"
+		"  <table border=\"0\" width=\"100%%\" height=\"100%%\">\n"
+		"    <tr height=\"100%%\" valign=\"middle\">\n"
+		"      <td width=\"100%%\" align=\"center\">\n"
+		"        <strong>%s</strong>\n"
+		"      </td>\n"
+		"    </tr>\n"
+		"  </table>\n"
+		"</body>\n"
+		"</html>\n",
+		header, status);
+	g_free (header);
 
 	e_web_view_load_string (E_WEB_VIEW (display), str);
 	g_free (str);
diff --git a/modules/itip-formatter/e-mail-formatter-itip.c b/modules/itip-formatter/e-mail-formatter-itip.c
index bf64a96..c129c89 100644
--- a/modules/itip-formatter/e-mail-formatter-itip.c
+++ b/modules/itip-formatter/e-mail-formatter-itip.c
@@ -85,7 +85,7 @@ emfe_itip_format (EMailFormatterExtension *extension,
 	} else if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
 		buffer = g_string_sized_new (2048);
 
-		itip_view_write (buffer);
+		itip_view_write (formatter, buffer);
 
 	} else {
 		gchar *uri;
diff --git a/modules/itip-formatter/itip-view.c b/modules/itip-formatter/itip-view.c
index 8e651f0..bc54c65 100644
--- a/modules/itip-formatter/itip-view.c
+++ b/modules/itip-formatter/itip-view.c
@@ -1416,15 +1416,12 @@ itip_view_set_extension_name (ItipView *view,
 }
 
 void
-itip_view_write (GString *buffer)
+itip_view_write (EMailFormatter *formatter,
+		 GString *buffer)
 {
-	g_string_append (buffer,
-		"<html>\n"
-		"<head>\n"
-		"<title>ITIP</title>\n"
-		"<link type=\"text/css\" rel=\"stylesheet\" href=\"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview.css\" />\n"
-		"</head>\n"
-		"<body>\n");
+	gchar *header = e_mail_formatter_get_html_header (formatter);
+	g_string_append (buffer, header);
+	g_free (header);
 
 	g_string_append_printf (buffer,
 		"<img src=\"gtk-stock://%s?size=%d\" class=\"itip icon\" />\n",
diff --git a/modules/itip-formatter/itip-view.h b/modules/itip-formatter/itip-view.h
index 60b8b1d..90558e7 100644
--- a/modules/itip-formatter/itip-view.h
+++ b/modules/itip-formatter/itip-view.h
@@ -30,6 +30,7 @@
 #include <webkit/webkitdom.h>
 #include <libecal/libecal.h>
 #include <libedataserver/libedataserver.h>
+#include <em-format/e-mail-formatter.h>
 
 G_BEGIN_DECLS
 
@@ -100,7 +101,8 @@ ItipView *      itip_view_new                   (EMailPartItip *puri,
 						 ESourceRegistry *registry);
 void		itip_view_init_view		(ItipView *view);
 
-void            itip_view_write                 (GString *buffer);
+void            itip_view_write                 (EMailFormatter *formatter,
+						 GString *buffer);
 
 void            itip_view_write_for_printing    (ItipView *view,
                                                  GString *buffer);
diff --git a/widgets/misc/e-web-view.c b/widgets/misc/e-web-view.c
index 5a65ad7..8d6f9fe 100644
--- a/widgets/misc/e-web-view.c
+++ b/widgets/misc/e-web-view.c
@@ -1874,9 +1874,26 @@ e_web_view_new (void)
 void
 e_web_view_clear (EWebView *web_view)
 {
+	GtkStyleContext *style_context;
+	GtkStateFlags state_flags;
+	GdkRGBA rgba;
+	gchar *html;
+
 	g_return_if_fail (E_IS_WEB_VIEW (web_view));
 
-	webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), "about:blank");
+	style_context = gtk_widget_get_style_context (GTK_WIDGET (web_view));
+	state_flags = gtk_widget_get_state_flags (GTK_WIDGET (web_view));
+	gtk_style_context_get_background_color (
+		style_context, state_flags, &rgba);
+
+	html = g_strdup_printf (
+		"<html><head></hea
+		d><body bgcolor=\"#%06x\"></body></html>",
+		e_rgba_to_value (&rgba));
+
+	webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (web_view), html, NULL);
+
+	g_free (html);
 }
 
 void



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