diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-05-09 09:09:52 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-05-09 11:06:23 +0800 |
commit | 448aa307c324899a45b56d00c23d247b789eca27 (patch) | |
tree | a7586b97a878083e8aee59b018f52828baa6b5eb /em-format | |
parent | 26ca1f2c563d5b4b2f3d3adcf427b8c3db62f4c4 (diff) | |
download | gsoc2013-evolution-448aa307c324899a45b56d00c23d247b789eca27.tar gsoc2013-evolution-448aa307c324899a45b56d00c23d247b789eca27.tar.gz gsoc2013-evolution-448aa307c324899a45b56d00c23d247b789eca27.tar.bz2 gsoc2013-evolution-448aa307c324899a45b56d00c23d247b789eca27.tar.lz gsoc2013-evolution-448aa307c324899a45b56d00c23d247b789eca27.tar.xz gsoc2013-evolution-448aa307c324899a45b56d00c23d247b789eca27.tar.zst gsoc2013-evolution-448aa307c324899a45b56d00c23d247b789eca27.zip |
Right-align mail header names.
We used to do this before WebKit and it looked better.
Also fix up the header section for right-to-left locales:
put the collapse button on the right, and images on the left.
Diffstat (limited to 'em-format')
-rw-r--r-- | em-format/e-mail-formatter-headers.c | 147 | ||||
-rw-r--r-- | em-format/e-mail-formatter-utils.c | 43 |
2 files changed, 119 insertions, 71 deletions
diff --git a/em-format/e-mail-formatter-headers.c b/em-format/e-mail-formatter-headers.c index 89ac5f677a..a3d7b20680 100644 --- a/em-format/e-mail-formatter-headers.c +++ b/em-format/e-mail-formatter-headers.c @@ -54,6 +54,7 @@ format_short_headers (EMailFormatter *formatter, guint32 flags, GCancellable *cancellable) { + GtkTextDirection direction; const gchar *charset; CamelContentType *ct; gchar *hdr_charset; @@ -62,11 +63,12 @@ format_short_headers (EMailFormatter *formatter, struct _camel_header_address *addrs = NULL; struct _camel_header_raw *header; GString *from; - gboolean is_rtl; if (g_cancellable_is_cancelled (cancellable)) return; + direction = gtk_widget_get_default_direction (); + ct = camel_mime_part_get_content_type ((CamelMimePart *) part); charset = camel_content_type_param (ct, "charset"); charset = camel_iconv_charset_name (charset); @@ -79,9 +81,9 @@ format_short_headers (EMailFormatter *formatter, g_string_append_printf ( buffer, - "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" " + "<table class=\"header\" " "id=\"__evo-short-headers\" style=\"display: %s\">", - flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSED ? "block" : "none"); + flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSED ? "table" : "none"); header = ((CamelMimePart *) part)->headers; while (header) { @@ -96,8 +98,10 @@ format_short_headers (EMailFormatter *formatter, formatter, tmp, addrs, header->name, FALSE, !(flags & E_MAIL_FORMATTER_HEADER_FLAG_NOELIPSIZE)); - if (tmp->len) - g_string_printf (from, _("From: %s"), tmp->str); + if (tmp->len > 0) + g_string_printf ( + from, "%s: %s", + _("From"), tmp->str); g_string_free (tmp, TRUE); } else if (!g_ascii_strcasecmp (header->name, "Subject")) { @@ -114,32 +118,20 @@ format_short_headers (EMailFormatter *formatter, g_free (hdr_charset); - is_rtl = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL; - if (is_rtl) { - g_string_append ( - buffer, "<tr><td width=\"100%%\" align=\"right\">"); - if (from->len > 0) - g_string_append_printf (buffer, "(%s) ", from->str); - g_string_append (buffer, "<strong>"); - if (subject != NULL && *subject != '\0') - g_string_append (buffer, subject); - else - g_string_append (buffer, _("(no subject)")); - g_string_append (buffer, "</strong>"); - g_string_append (buffer, "</td></tr>"); - } else { - g_string_append ( - buffer, "<tr><td width=\"100%%\" align=\"left\">"); - g_string_append (buffer, "<strong>"); - if (subject != NULL && *subject != '\0') - g_string_append (buffer, subject); - else - g_string_append (buffer, _("(no subject)")); - g_string_append (buffer, "</strong>"); - if (from->len > 0) - g_string_append_printf (buffer, " (%s)", from->str); - g_string_append (buffer, "</td></tr>"); - } + g_string_append (buffer, "<tr class=\"header\">"); + if (direction == GTK_TEXT_DIR_RTL) + g_string_append (buffer, "<td class=\"header rtl\">"); + else + g_string_append (buffer, "<td class=\"header ltr\">"); + g_string_append (buffer, "<strong>"); + if (subject != NULL && *subject != '\0') + g_string_append (buffer, subject); + else + g_string_append (buffer, _("(no subject)")); + g_string_append (buffer, "</strong>"); + if (from->len > 0) + g_string_append_printf (buffer, " (%s)", from->str); + g_string_append (buffer, "</td></tr>"); g_string_append (buffer, "</table>"); @@ -257,10 +249,23 @@ format_full_headers (EMailFormatter *formatter, gboolean mail_from_delegate = FALSE; gchar *hdr_charset; gchar *evolution_imagesdir; + const gchar *direction; if (g_cancellable_is_cancelled (cancellable)) return; + switch (gtk_widget_get_default_direction ()) { + case GTK_TEXT_DIR_RTL: + direction = "rtl"; + break; + case GTK_TEXT_DIR_LTR: + direction = "ltr"; + break; + default: + direction = "inherit"; + break; + } + ct = camel_mime_part_get_content_type ((CamelMimePart *) part); charset = camel_content_type_param (ct, "charset"); charset = camel_iconv_charset_name (charset); @@ -272,9 +277,12 @@ format_full_headers (EMailFormatter *formatter, g_string_append_printf ( buffer, - "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" " - "id=\"__evo-full-headers\" style=\"display: %s\" width=\"100%%\">", - flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSED ? "none" : "block"); + "<table cellspacing=\"0\" cellpadding=\"0\" " + "border=\"0\" width=\"100%%\" " + "id=\"__evo-full-headers\" " + "style=\"display: %s; direction: %s;\">", + flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSED ? "none" : "table", + direction); header = ((CamelMimePart *) part)->headers; while (header != NULL) { @@ -356,7 +364,7 @@ format_full_headers (EMailFormatter *formatter, g_string_append ( buffer, "<tr valign=\"top\"><td width=\"100%\">" - "<table border=0 cellpadding=\"0\">\n"); + "<table class=\"header\">\n"); g_free (evolution_imagesdir); @@ -456,8 +464,9 @@ format_full_headers (EMailFormatter *formatter, gchar *name; name = g_uri_escape_string (photo_name, NULL, FALSE); - g_string_append (buffer, "<td align=\"right\" valign=\"top\">"); - + g_string_append ( + buffer, + "<td align=\"right\" valign=\"top\">"); g_string_append_printf ( buffer, "<img src=\"mail://contact-photo?mailaddr=\" " @@ -477,7 +486,9 @@ format_full_headers (EMailFormatter *formatter, (const gchar *) face_header_value, face_header_len, "image/png"); - g_string_append (buffer, "<td align=\"right\" valign=\"top\">"); + g_string_append ( + buffer, + "<td align=\"right\" valign=\"top\">"); write_contact_picture (part, 48, buffer); g_string_append (buffer, "</td>"); @@ -490,16 +501,19 @@ format_full_headers (EMailFormatter *formatter, CamelMimePart *iconpart = NULL; icon_info = gtk_icon_theme_lookup_icon ( - gtk_icon_theme_get_default (), - "evolution", 16, GTK_ICON_LOOKUP_NO_SVG); + gtk_icon_theme_get_default (), + "evolution", 16, GTK_ICON_LOOKUP_NO_SVG); if (icon_info != NULL) { iconpart = load_picture_from_file ( - "image/png", gtk_icon_info_get_filename (icon_info), + "image/png", + gtk_icon_info_get_filename (icon_info), cancellable); gtk_icon_info_free (icon_info); } - if (iconpart) { - g_string_append (buffer, "<td align=\"right\" valign=\"top\">"); + if (iconpart != NULL) { + g_string_append ( + buffer, + "<td align=\"right\" valign=\"top\">"); write_contact_picture (iconpart, 16, buffer); g_string_append (buffer, "</td>"); @@ -522,6 +536,9 @@ emfe_headers_format (EMailFormatterExtension *extension, const GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 }; const GdkRGBA *body_rgba = &white; const GdkRGBA *header_rgba; + const gchar *direction; + gboolean is_collapsable; + gboolean is_collapsed; if (g_cancellable_is_cancelled (cancellable)) return FALSE; @@ -529,6 +546,24 @@ emfe_headers_format (EMailFormatterExtension *extension, if (!part->part) return FALSE; + switch (gtk_widget_get_default_direction ()) { + case GTK_TEXT_DIR_RTL: + direction = "rtl"; + break; + case GTK_TEXT_DIR_LTR: + direction = "ltr"; + break; + default: + direction = "inherit"; + break; + } + + is_collapsable = + (context->flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSABLE); + + is_collapsed = + (context->flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSED); + buffer = g_string_new (""); if (context->mode != E_MAIL_FORMATTER_MODE_PRINTING) @@ -541,28 +576,32 @@ emfe_headers_format (EMailFormatterExtension *extension, g_string_append_printf ( buffer, "<div class=\"headers\" style=\"background: #%06x;\" id=\"%s\">" - "<table border=\"0\" width=\"100%%\" style=\"color: #%06x;\">\n" - "<tr><td valign=\"top\" width=\"16\">\n", + "<table border=\"0\" width=\"100%%\" " + "style=\"color: #%06x; direction: %s\">" + "<tr>", e_rgba_to_value (body_rgba), part->id, - e_rgba_to_value (header_rgba)); + e_rgba_to_value (header_rgba), + direction); - if (context->flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSABLE) { + if (is_collapsable) g_string_append_printf ( buffer, + "<td valign=\"top\" width=\"16\">" "<img src=\"evo-file://%s/%s\" class=\"navigable\" " - "id=\"__evo-collapse-headers-img\" />" - "</td><td>", + " id=\"__evo-collapse-headers-img\" />" + "</td>", EVOLUTION_IMAGESDIR, - (context->flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSED) ? - "plus.png" : "minus.png"); + is_collapsed ? "plus.png" : "minus.png"); + + g_string_append (buffer, "<td>"); + if (is_collapsable) format_short_headers ( formatter, buffer, CAMEL_MEDIUM (part->part), context->flags, cancellable); - } format_full_headers ( formatter, buffer, @@ -571,7 +610,9 @@ emfe_headers_format (EMailFormatterExtension *extension, context->flags, cancellable); - g_string_append (buffer, "</td></tr></table></div>"); + g_string_append (buffer, "</td>"); + + g_string_append (buffer, "</tr></table></div>"); camel_stream_write_string (stream, buffer->str, cancellable, NULL); diff --git a/em-format/e-mail-formatter-utils.c b/em-format/e-mail-formatter-utils.c index a2e0d43ff1..d5bff2ecd0 100644 --- a/em-format/e-mail-formatter-utils.c +++ b/em-format/e-mail-formatter-utils.c @@ -45,9 +45,9 @@ e_mail_formatter_format_text_header (EMailFormatter *formatter, const gchar *value, guint32 flags) { + GtkTextDirection direction; const gchar *fmt, *html; gchar *mhtml = NULL; - gboolean is_rtl; g_return_if_fail (E_IS_MAIL_FORMATTER (formatter)); g_return_if_fail (buffer != NULL); @@ -70,31 +70,38 @@ e_mail_formatter_format_text_header (EMailFormatter *formatter, html = value; } - is_rtl = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL; + direction = gtk_widget_get_default_direction (); if (flags & E_MAIL_FORMATTER_HEADER_FLAG_NOCOLUMNS) { if (flags & E_MAIL_FORMATTER_HEADER_FLAG_BOLD) { - fmt = "<tr class=\"header-item\" style=\"display: %s\"><td><b>%s:</b> %s</td></tr>"; + fmt = "<tr style=\"display: %s\">" + "<td><b>%s:</b> %s</td></tr>"; } else { - fmt = "<tr class=\"header-item\" style=\"display: %s\"><td>%s: %s</td></tr>"; + fmt = "<tr style=\"display: %s\">" + "<td>%s: %s</td></tr>"; } } else if (flags & E_MAIL_FORMATTER_HEADER_FLAG_NODEC) { - if (is_rtl) - fmt = "<tr class=\"header-item rtl\" style=\"display: %s\"><td align=\"right\" valign=\"top\" width=\"100%%\">%2$s</td><th valign=top align=\"left\" nowrap>%1$s<b> </b></th></tr>"; + if (direction == GTK_TEXT_DIR_RTL) + fmt = "<tr class=\"header\" style=\"display: %s\">" + "<th class=\"header rtl\">%s</th>" + "<td class=\"header rtl\">%s</td>" + "</tr>"; else - fmt = "<tr class=\"header-item\" style=\"display: %s\"><th align=\"right\" valign=\"top\" nowrap>%s<b> </b></th><td valign=top>%s</td></tr>"; + fmt = "<tr class=\"header\" style=\"display: %s\">" + "<th class=\"header ltr\">%s</th>" + "<td class=\"header ltr\">%s</td>" + "</tr>"; } else { - if (flags & E_MAIL_FORMATTER_HEADER_FLAG_BOLD) { - if (is_rtl) - fmt = "<tr class=\"header-item rtl\" style=\"display: %s\"><td align=\"right\" valign=\"top\" width=\"100%%\">%2$s</td><th align=\"left\" nowrap>%1$s:<b> </b></th></tr>"; - else - fmt = "<tr class=\"header-item\" style=\"display: %s\"><th align=\"right\" valign=\"top\" nowrap>%s:<b> </b></th><td>%s</td></tr>"; - } else { - if (is_rtl) - fmt = "<tr class=\"header-item rtl\" style=\"display: %s\"><td align=\"right\" valign=\"top\" width=\"100%\">%2$s</td><td align=\"left\" nowrap>%1$s:<b> </b></td></tr>"; - else - fmt = "<tr class=\"header-item\" style=\"display: %s\"><td align=\"right\" valign=\"top\" nowrap>%s:<b> </b></td><td>%s</td></tr>"; - } + if (direction == GTK_TEXT_DIR_RTL) + fmt = "<tr class=\"header\" style=\"display: %s\">" + "<th class=\"header rtl\">%s:</th>" + "<td class=\"header rtl\">%s</td>" + "</tr>"; + else + fmt = "<tr class=\"header\" style=\"display: %s\">" + "<th class=\"header ltr\">%s:</th>" + "<td class=\"header ltr\">%s</td>" + "</tr>"; } g_string_append_printf ( |