[evolution/webkit: 175/196] Fix printing of message/rfc822
- From: Dan VrÃtil <dvratil src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/webkit: 175/196] Fix printing of message/rfc822
- Date: Tue, 27 Mar 2012 16:15:26 +0000 (UTC)
commit ebc71bc816faf615856814ee159f4c14c9c66920
Author: Dan VrÃtil <dvratil redhat com>
Date: Tue Feb 28 17:02:16 2012 +0100
Fix printing of message/rfc822
data/Makefile.am | 1 +
data/webview-print.css | 62 +++++++++++++++++++++++++++++++++++++++++
data/webview.css | 2 +
mail/e-mail-printer.c | 11 +++++++
mail/em-format-html-display.c | 15 ++++++++++
mail/em-format-html-print.c | 54 ++++++++++++++++++++++++++---------
mail/em-format-html.c | 55 ++++++++++++++++++++++++++++++++----
7 files changed, 180 insertions(+), 20 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index b5a0baf..9d9a886 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -40,6 +40,7 @@ themedir = $(privdatadir)/theme
dist_theme_DATA = \
default.css \
webview.css \
+ webview-print.css \
tab-bar-background.png \
tab-switcher.png \
tab-switcher-hover.png \
diff --git a/data/webview-print.css b/data/webview-print.css
new file mode 100644
index 0000000..a2c5292
--- /dev/null
+++ b/data/webview-print.css
@@ -0,0 +1,62 @@
+html, body {
+ padding: 0;
+ margin: 0;
+}
+
+body {
+ /* Use margin so that children can safely use width=100% */
+ margin: 10px;
+}
+
+h1,h2,h3 {
+ color: #7f7f7f;
+}
+
+th {
+ color: #7f7f7f;
+ text-align: left;
+ font-weight: normal;
+ vertical-align: top;
+}
+
+.header {
+ color: #7f7f7f;
+}
+
+.pre {
+ font-family: monospace;
+}
+
+.part-container {
+ width: 100%;
+ background: #FFF;
+ margin-top: 2px;
+ margin-bottom: 3px;
+ border-width: 0px;
+ border-style: none;
+}
+
+.part-container-inner-margin {
+ margin: 8px;
+}
+
+/***** PRINTING *******/
+
+.printing-header {
+ margin-bottom: 20px;
+}
+
+.printing-header h1,
+.attachments-list h1 {
+ font-size: 20px;
+}
+
+.printing-header th {
+ text-align: right;
+ font-weight: bold;
+}
+
+.attachments-list th {
+ font-weight: bold;
+}
+
diff --git a/data/webview.css b/data/webview.css
index 076fc8b..30a37dc 100644
--- a/data/webview.css
+++ b/data/webview.css
@@ -63,6 +63,8 @@ img.navigable {
background: #FFF;
margin-top: 2px;
margin-bottom: 3px;
+ border-width: 1px;
+ border-style: solid;
}
.part-container-inner-margin {
diff --git a/mail/e-mail-printer.c b/mail/e-mail-printer.c
index 934ac12..3396769 100644
--- a/mail/e-mail-printer.c
+++ b/mail/e-mail-printer.c
@@ -44,6 +44,8 @@ enum {
BUTTONS_COUNT
};
+#define w(x)
+
struct _EMailPrinterPrivate {
EMFormatHTMLPrint *efhp;
@@ -173,6 +175,15 @@ emp_run_print_operation (EMailPrinter *emp,
emp->priv->webview = WEBKIT_WEB_VIEW (e_web_view_new ());
e_web_view_set_enable_frame_flattening (E_WEB_VIEW (emp->priv->webview), FALSE);
g_object_ref_sink (emp->priv->webview);
+
+ w({
+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (window), sw);
+ gtk_container_add (GTK_CONTAINER (sw),
+ GTK_WIDGET (emp->priv->webview));
+ gtk_widget_show_all (window);
+ });
}
webkit_web_view_load_uri (emp->priv->webview, emp->priv->uri);
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 4b5e877..9a0cc36 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -711,6 +711,9 @@ efhd_write_attachment_bar (EMFormat *emf,
EMFormatAttachmentBarPURI *efab = (EMFormatAttachmentBarPURI *) puri;
gchar *str;
+ if (info->mode == EM_FORMAT_WRITE_MODE_PRINTING)
+ return;
+
if (e_attachment_store_get_num_attachments (efab->store) == 0)
return;
@@ -746,6 +749,14 @@ efhd_write_attachment (EMFormat *emf,
return;
}
+ if (info->mode == EM_FORMAT_WRITE_MODE_PRINTING) {
+
+ if (efa->handle && efa->handle->write_func)
+ efa->handle->write_func (emf, puri, stream, info, cancellable);
+
+ return;
+ }
+
if (efa->handle)
mime_type = efa->handle->mime_type;
else
@@ -809,6 +820,10 @@ efhd_write_secure_button (EMFormat *emf,
{
gchar *str;
+ if ((info->mode != EM_FORMAT_WRITE_MODE_NORMAL) &&
+ (info->mode != EM_FORMAT_WRITE_MODE_RAW))
+ return;
+
str = g_strdup_printf (
"<object type=\"application/x-secure-button\" "
"height=\"20\" width=\"100%%\" "
diff --git a/mail/em-format-html-print.c b/mail/em-format-html-print.c
index 1085183..4df837e 100644
--- a/mail/em-format-html-print.c
+++ b/mail/em-format-html-print.c
@@ -39,6 +39,8 @@
#include "em-format-html-print.h"
+#define d(x)
+
static gpointer parent_class = NULL;
struct _EMFormatHTMLPrintPrivate {
@@ -72,9 +74,11 @@ efhp_write_attachments_list (EMFormatHTMLPrint *efhp,
if (!efhp->priv->attachments)
return;
- str = g_string_new ("<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\" "\
- "class=\"attachments-list\" >\n");
- g_string_append_printf (str, "<tr><th colspan=\"2\"><h1>%s</h1></td></tr>\n" \
+ str = g_string_new (
+ "<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\" "
+ "class=\"attachments-list\" >\n");
+ g_string_append_printf (str,
+ "<tr><th colspan=\"2\"><h1>%s</h1></td></tr>\n"
"<tr><th>%s</th><th>%s</th></tr>\n",
_("Attachments"), _("Name"), _("Size"));
@@ -137,7 +141,11 @@ efhp_write_headers (EMFormat *emf,
subject = camel_header_decode_string (buf, "UTF-8");
str = g_string_new ("<table border=\"0\" cellspacing=\"5\" " \
"cellpadding=\"0\" class=\"printing-header\">\n");
- g_string_append_printf (str, "<tr class='header-item'><td colspan=\"2\"><h1>%s</h1></td></tr>\n",
+ g_string_append_printf (
+ str,
+ "<tr class=\"header-item\">"
+ "<td colspan=\"2\"><h1>%s</h1></td>"
+ "</tr>\n",
subject);
g_free (subject);
@@ -296,12 +304,14 @@ efhp_write_print_layout (EMFormat *emf,
efhp->priv->attachments = NULL;
camel_stream_write_string (stream,
- "<!DOCTYPE HTML>\n<html>\n" \
- "<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\" />\n" \
- "<title>Evolution Mail Display</title>\n" \
- "<link type=\"text/css\" rel=\"stylesheet\" href=\"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview.css\" />\n" \
- "</head>\n" \
- "<body style=\"background: #FFF; color: #000;\">", cancellable, NULL);
+ "<!DOCTYPE HTML>\n<html>\n"
+ "<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\" />\n"
+ "<title>Evolution Mail Display</title>\n"
+ "<link type=\"text/css\" rel=\"stylesheet\" media=\"print\" "
+ "href=\"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview-print.css\" />\n"
+ "</head>\n"
+ "<body style=\"background: #FFF; color: #000;\">",
+ cancellable, NULL);
for (iter = emf->mail_part_list; iter != NULL; iter = iter->next) {
@@ -312,10 +322,26 @@ efhp_write_print_layout (EMFormat *emf,
/* To late to change .headers writer_func, do it manually. */
if (g_str_has_suffix (puri->uri, ".headers")) {
- efhp_write_headers (emf, puri, stream, info, cancellable);
+ efhp_write_headers (emf, puri, stream, &print_info, cancellable);
continue;
}
+ if (g_str_has_suffix (puri->uri, ".rfc822")) {
+
+ while (iter && !g_str_has_suffix (puri->uri, ".rfc822.end")) {
+
+ iter = iter->next;
+ if (iter)
+ puri = iter->data;
+ }
+
+ if (!iter)
+ break;
+
+ continue;
+
+ }
+
if (puri->is_attachment || g_str_has_suffix (puri->uri, ".attachment")) {
const EMFormatHandler *handler;
@@ -323,8 +349,8 @@ efhp_write_print_layout (EMFormat *emf,
gchar *mime_type = camel_content_type_simple (ct);
handler = em_format_find_handler (puri->emf, mime_type);
- g_message ("Handler for PURI %s (%s): %s", puri->uri, mime_type,
- handler ? handler->mime_type : "(null)");
+ d(printf("Handler for PURI %s (%s): %s", puri->uri, mime_type,
+ handler ? handler->mime_type : "(null)"));
g_free (mime_type);
efhp->priv->attachments =
@@ -430,7 +456,7 @@ efhp_set_orig_formatter (EMFormatHTMLPrint *efhp,
}
static EMFormatHandler type_builtin_table[] = {
- //{ (gchar *) "x-evolution/message/headers", 0, efhp_write_headers, },
+ { (gchar *) "x-evolution/message/headers", 0, efhp_write_headers, },
};
static void
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index bde29f0..cde3b16 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -652,7 +652,7 @@ efh_write_text_enriched (EMFormat *emf,
buffer = g_string_new ("");
g_string_append_printf (buffer,
- "<div class=\"part-container\" style=\"border: solid #%06x 1px; "
+ "<div class=\"part-container\" style=\"border-color: #%06x; "
"background-color: #%06x; color: #%06x;\">"
"<div class=\"part-container-inner-margin\">\n",
e_color_to_value (&efh->priv->colors[
@@ -711,7 +711,7 @@ efh_write_text_plain (EMFormat *emf,
g_object_unref (html_filter);
content = g_strdup_printf (
- "<div class=\"part-container\" style=\"border: solid #%06x 1px; "
+ "<div class=\"part-container\" style=\"border-color: #%06x; "
"background-color: #%06x; color: #%06x;\">"
"<div class=\"part-container-inner-margin\">\n",
e_color_to_value (&efh->priv->colors[
@@ -843,11 +843,10 @@ efh_write_headers (EMFormat *emf,
bg_color = e_color_to_value (&efh->priv->colors[EM_FORMAT_HTML_COLOR_BODY]);
}
- /* Headers need some fancy JavaScript */
g_string_append_printf (
buffer,
"<div class=\"headers\" style=\"background: #%06x;\">"
- "<table border=\"0\" width=\"100%%\" height=\"100%%\" style=\"color: #%06x;\">\n"
+ "<table border=\"0\" width=\"100%%\" style=\"color: #%06x;\">\n"
"<tr><td valign=\"top\" width=\"16\">\n",
bg_color,
e_color_to_value (&efh->priv->colors[EM_FORMAT_HTML_COLOR_HEADER]));
@@ -942,6 +941,50 @@ efh_write_message_rfc822 (EMFormat *emf,
g_list_free (puris);
+ } else if (info->mode == EM_FORMAT_WRITE_MODE_PRINTING) {
+
+ GList *iter;
+ gboolean can_write = FALSE;
+
+ iter = g_hash_table_lookup (emf->mail_part_table, puri->uri);
+ if (!iter || !iter->next)
+ return;
+
+ /* Skip everything before attachment bar, inclusive */\
+ iter = iter->next;
+ while (iter) {
+
+ EMFormatPURI *p = iter->data;
+
+ /* EMFormatHTMLPrint has registered a special writer
+ * for headers, try to find it and use it. */
+ if (g_str_has_suffix (p->uri, ".headers")) {
+
+ const EMFormatHandler *handler;
+
+ handler = em_format_find_handler(
+ emf, "x-evolution/message/headers");
+ if (handler && handler->write_func)
+ handler->write_func (emf, p, stream, info, cancellable);
+
+ iter = iter->next;
+ continue;
+ }
+
+ if (g_str_has_suffix (p->uri, ".rfc822.end"))
+ break;
+
+ if (g_str_has_suffix (p->uri, ".attachment-bar"))
+ can_write = TRUE;
+
+ if (can_write && p->write_func) {
+ p->write_func (
+ emf, p, stream, info, cancellable);
+ }
+
+ iter = iter->next;
+ }
+
} else {
gchar *str;
gchar *uri;
@@ -963,7 +1006,7 @@ efh_write_message_rfc822 (EMFormat *emf,
NULL);
str = g_strdup_printf (
- "<div class=\"part-container\" style=\"border: solid #%06x 1px; "
+ "<div class=\"part-container\" style=\"border-color: #%06x; "
"background-color: #%06x;\">"
"<div class=\"part-container-inner-margin\">\n"
"<iframe width=\"100%%\" height=\"auto\""
@@ -1314,7 +1357,7 @@ efh_write_message (EMFormat *emf,
"<style type=\"text/css\">\n"
" table th { color: #000; font-weight: bold; }\n"
"</style>\n"
- "</head><body bgcolor=\"%06x\">",
+ "</head><body bgcolor=\"#%06x\">",
e_color_to_value (&efh->priv->colors[
EM_FORMAT_HTML_COLOR_BODY]));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]