[geary: 1/2] Print common headers when printing messages
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary: 1/2] Print common headers when printing messages
- Date: Sun, 23 Sep 2018 02:18:13 +0000 (UTC)
commit 2b2c587e6c48edd62080db390455ac581f962ba9
Author: Alex Henrie <alexhenrie24 gmail com>
Date: Sat Sep 22 09:48:51 2018 -0600
Print common headers when printing messages
.../conversation-viewer/conversation-email.vala | 3 --
.../conversation-viewer/conversation-message.vala | 7 +++++
.../conversation-viewer/conversation-web-view.vala | 12 ++++++++
ui/conversation-web-view.css | 9 ++++++
ui/conversation-web-view.js | 36 ++++++++++++++++++++++
5 files changed, 64 insertions(+), 3 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-email.vala
b/src/client/conversation-viewer/conversation-email.vala
index 493e462c..0bf6c121 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -805,9 +805,6 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
}
private void print() {
- // XXX This isn't anywhere near good enough - headers aren't
- // being printed.
-
Gtk.Window? window = get_toplevel() as Gtk.Window;
WebKit.PrintOperation op = new WebKit.PrintOperation(
this.primary_message.web_view
diff --git a/src/client/conversation-viewer/conversation-message.vala
b/src/client/conversation-viewer/conversation-message.vala
index dfbce2ce..6c68c7c4 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -482,6 +482,13 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
load_cancelled.cancelled.connect(() => { web_view.stop_loading(); });
+ this.web_view.set_print_headers(
+ this.message.from != null ? this.message.from.to_string() : null,
+ this.message.to != null ? this.message.to.to_string() : null,
+ this.message.cc != null ? this.message.cc.to_string() : null,
+ this.message.bcc != null ? this.message.bcc.to_string() : null,
+ this.message.date != null ? this.message.date.to_string() : null,
+ this.message.subject != null ? this.message.subject.to_string() : null);
this.web_view.load_html(body_text ?? "");
}
diff --git a/src/client/conversation-viewer/conversation-web-view.vala
b/src/client/conversation-viewer/conversation-web-view.vala
index 217d0a64..62323b2a 100644
--- a/src/client/conversation-viewer/conversation-web-view.vala
+++ b/src/client/conversation-viewer/conversation-web-view.vala
@@ -54,6 +54,18 @@ public class ConversationWebView : ClientWebView {
);
}
+ public void set_print_headers(string? from, string? to, string? cc, string? bcc, string? date, string?
subject) {
+ StringBuilder js = new StringBuilder("var gearyEmailHeaders = {");
+ if (from != null) js.append(_("'From:':'") + from.replace("'", "\\'") + "',");
+ if (to != null) js.append(_("'To:':'") + to.replace("'", "\\'") + "',");
+ if (cc != null) js.append(_("'CC:':'") + cc.replace("'", "\\'") + "',");
+ if (bcc != null) js.append(_("'BCC:':'") + bcc.replace("'", "\\'") + "',");
+ if (date != null) js.append(_("'Date:':'") + date.replace("'", "\\'") + "',");
+ if (subject != null) js.append(_("'Subject:':'") + subject.replace("'", "\\'") + "',");
+ js.append("};");
+ this.run_javascript(js.str, null);
+ }
+
/** Emitted when the user clicks on a link with deceptive text. */
public signal void deceptive_link_clicked(
diff --git a/ui/conversation-web-view.css b/ui/conversation-web-view.css
index 0040bca3..70de0047 100644
--- a/ui/conversation-web-view.css
+++ b/ui/conversation-web-view.css
@@ -193,8 +193,17 @@ pre {
}
}
+#geary-message-headers {
+ display: none;
+}
+
@media print {
.geary-button {
display: none;
}
+
+ #geary-message-headers {
+ all: initial;
+ display: block;
+ }
}
diff --git a/ui/conversation-web-view.js b/ui/conversation-web-view.js
index b24beb33..6b9dc262 100644
--- a/ui/conversation-web-view.js
+++ b/ui/conversation-web-view.js
@@ -314,3 +314,39 @@ ConversationPageState.isDescendantOf = function(node, ancestorTag) {
};
var geary = new ConversationPageState();
+
+/**
+ * Add email headers for printing
+ */
+
+document.addEventListener('DOMContentLoaded', () => {
+ let headerBlock = document.createElement('div');
+ headerBlock.id = 'geary-message-headers';
+
+ let shadowRoot = headerBlock.attachShadow({mode: 'closed'});
+
+ let shadowStyle = document.createElement('style');
+ shadowStyle.textContent = "\
+ table, tr, th, td, hr { all:initial; }\
+ table { display:table; }\
+ tr { display:table-row; }\
+ td, th { display:table-cell; line-height:1.5em; }\
+ th { font-weight:bold; padding-right:2ex; }\
+ hr { display:block; border-style:inset; border-width:1px; margin-top:0.5em; margin-bottom:0.5em; }";
+ shadowRoot.appendChild(shadowStyle);
+
+ let headerTable = document.createElement('table');
+ shadowRoot.appendChild(headerTable);
+
+ for (header in gearyEmailHeaders) {
+ let row = headerTable.appendChild(document.createElement('tr'));
+ let name = row.appendChild(document.createElement('th'));
+ let value = row.appendChild(document.createElement('td'));
+ name.textContent = header;
+ value.textContent = gearyEmailHeaders[header];
+ }
+
+ shadowRoot.appendChild(document.createElement('hr'));
+
+ document.body.insertBefore(headerBlock, document.body.firstChild);
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]