[geary/wip/774603-configurable-gravatar-uri: 1/4] Print common headers when printing messages



commit e4b71159d7f7ddd449cf7e12cd9c5829a264fcc8
Author: Alex Henrie <alexhenrie24 gmail com>
Date:   Wed Sep 26 18:43:46 2018 -0600

    Print common headers when printing messages

 .gitlab-ci.yml                                     |  4 +--
 INSTALL                                            |  4 +--
 debian/control                                     |  2 ++
 meson.build                                        |  1 +
 .../conversation-viewer/conversation-email.vala    | 37 +++++++++++++++++++---
 src/client/meson.build                             |  1 +
 ui/conversation-web-view.css                       | 35 ++++++++++++++++++++
 ui/conversation-web-view.js                        | 19 +++++++++++
 8 files changed, 95 insertions(+), 8 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 76a0257f..887b6036 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -16,7 +16,7 @@ variables:
                glib2-devel gmime-devel gtk3-devel libnotify-devel sqlite-devel
                webkitgtk4-devel libsecret-devel libxml2-devel vala-tools
                gcr-devel enchant-devel libunwind-devel iso-codes-devel
-               gnome-online-accounts-devel itstool
+               gnome-online-accounts-devel itstool json-glib-devel
   FEDORA_TEST_DEPS: Xvfb tar xz
   UBUNTU_DEPS: valac libgirepository1.0-dev
                meson desktop-file-utils libcanberra-dev
@@ -24,7 +24,7 @@ variables:
                libsecret-1-dev libxml2-dev libnotify-dev libsqlite3-dev
                libwebkit2gtk-4.0-dev libgcr-3-dev libenchant-dev
                libunwind-dev iso-codes libgoa-1.0-dev itstool gettext
-               libmessaging-menu-dev libunity-dev
+               libmessaging-menu-dev libunity-dev libjson-glib-dev
   UBUNTU_TEST_DEPS: xauth xvfb
 
 #
diff --git a/INSTALL b/INSTALL
index 7d6b426b..60094d86 100644
--- a/INSTALL
+++ b/INSTALL
@@ -45,7 +45,7 @@ libraries. Install them by running this command:
         desktop-file-utils iso-codes-devel libcanberra-devel libgee-devel \
         glib2-devel gmime-devel gtk3-devel libnotify-devel sqlite-devel \
         webkitgtk4-devel libsecret-devel libxml2-devel vala-tools \
-        gcr-devel enchant-devel libunwind-devel \
+        gcr-devel enchant-devel libunwind-devel json-glib-devel \
         gnome-online-accounts-devel itstool
 
 Installing dependencies on Ubuntu/Debian
@@ -67,7 +67,7 @@ Install them by running this command:
         libgee-0.8-dev libglib2.0-dev libgmime-2.6-dev libgtk-3-dev \
         libsecret-1-dev libxml2-dev libnotify-dev libsqlite3-dev \
         libwebkit2gtk-4.0-dev libgcr-3-dev libenchant-dev \
-        libunwind-dev libgoa-1.0-dev itstool gettext
+        libunwind-dev libgoa-1.0-dev libjson-glib-dev itstool gettext
 
 And for Ubuntu Unity integration:
 
diff --git a/debian/control b/debian/control
index 0c1a396d..3a3b1d14 100644
--- a/debian/control
+++ b/debian/control
@@ -15,6 +15,7 @@ Build-Depends: debhelper (>= 8),
  libgmime-2.6-dev (>= 2.6.17),
  libgoa-1.0-dev,
  libgtk-3-dev (>= 3.22.26),
+ libjson-glib-dev,
  libmessaging-menu-dev,
  libnotify-dev,
  libsecret-1-dev,
@@ -42,6 +43,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends},
  libgmime-2.6-0 (>= 2.6.17),
  libgoa-1.0-0b,
  libgtk-3-0 (>= 3.22.26),
+ libjson-glib,
  libmessaging-menu0,
  libnotify4,
  libsecret-1-0,
diff --git a/meson.build b/meson.build
index e86cac33..d18d3983 100644
--- a/meson.build
+++ b/meson.build
@@ -61,6 +61,7 @@ gobject_introspection = dependency('gobject-introspection-1.0')
 gthread = dependency('gthread-2.0', version: '>=' + target_glib)
 iso_codes = dependency('iso-codes')
 javascriptcoregtk = dependency('javascriptcoregtk-4.0', version: '>=' + target_webkit)
+json_glib = dependency('json-glib-1.0', version: '>= 1.0')
 libcanberra = dependency('libcanberra', version: '>= 0.28')
 libmath = cc.find_library('m')
 libnotify = dependency('libnotify', version: '>= 0.7.5')
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index 493e462c..5fdd75e1 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -385,7 +385,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
                 forward_message();
             });
         add_action(ACTION_PRINT).activate.connect(() => {
-                print();
+                print.begin();
             });
         add_action(ACTION_MARK_READ).activate.connect(() => {
                 mark_email(null, Geary.EmailFlags.UNREAD);
@@ -804,9 +804,38 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
         }
     }
 
-    private void print() {
-        // XXX This isn't anywhere near good enough - headers aren't
-        // being printed.
+    private async void print() throws Error {
+        Json.Builder builder = new Json.Builder();
+        builder.begin_object();
+        if (this.email.from != null) {
+            builder.set_member_name(_("From:"));
+            builder.add_string_value(this.email.from.to_string());
+        }
+        if (this.email.to != null) {
+            builder.set_member_name(_("To:"));
+            builder.add_string_value(this.email.to.to_string());
+        }
+        if (this.email.cc != null) {
+            builder.set_member_name(_("CC:"));
+            builder.add_string_value(this.email.cc.to_string());
+        }
+        if (this.email.bcc != null) {
+            builder.set_member_name(_("BCC:"));
+            builder.add_string_value(this.email.bcc.to_string());
+        }
+        if (this.email.date != null) {
+            builder.set_member_name(_("Date:"));
+            builder.add_string_value(this.email.date.to_string());
+        }
+        if (this.email.subject != null) {
+            builder.set_member_name(_("Subject:"));
+            builder.add_string_value(this.email.subject.to_string());
+        }
+        builder.end_object();
+        Json.Generator generator = new Json.Generator();
+        generator.set_root(builder.get_root());
+        string js = "geary.addPrintHeaders(" + generator.to_data(null) + ");";
+        yield this.primary_message.web_view.run_javascript(js, null);
 
         Gtk.Window? window = get_toplevel() as Gtk.Window;
         WebKit.PrintOperation op = new WebKit.PrintOperation(
diff --git a/src/client/meson.build b/src/client/meson.build
index b0559b8d..7fba7c62 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -116,6 +116,7 @@ geary_client_dependencies = [
   gio,
   goa,
   gtk,
+  json_glib,
   libcanberra,
   libnotify,
   libsecret,
diff --git a/ui/conversation-web-view.css b/ui/conversation-web-view.css
index 0040bca3..a41c4d0f 100644
--- a/ui/conversation-web-view.css
+++ b/ui/conversation-web-view.css
@@ -193,8 +193,43 @@ pre {
   }
 }
 
+#geary-message-headers {
+  display: none !important;
+}
+
 @media print {
   .geary-button {
     display: none;
   }
+
+  #geary-message-headers, #geary-message-headers * {
+    all: initial !important;
+  }
+
+  #geary-message-headers {
+    display: table !important;
+    width: 100% !important;
+    transition: height 2s !important;
+    padding-bottom: 0.5em !important;
+    border-bottom: 2px inset black !important;
+    margin-bottom: 0.75em !important;
+  }
+
+  #geary-message-headers tr {
+    display: table-row !important;
+  }
+
+  #geary-message-headers th, #geary-message-headers td {
+    display: table-cell !important;
+    line-height: 1.5em !important;
+  }
+
+  #geary-message-headers th {
+    font-weight: bold !important;
+    padding-right: 2ex !important;
+  }
+
+  #geary-message-headers td {
+    width: 100% !important;
+  }
 }
diff --git a/ui/conversation-web-view.js b/ui/conversation-web-view.js
index b24beb33..da44f4a0 100644
--- a/ui/conversation-web-view.js
+++ b/ui/conversation-web-view.js
@@ -34,6 +34,25 @@ ConversationPageState.prototype = {
             }
         }, true);
     },
+    /**
+     * Add email headers for printing
+     */
+    addPrintHeaders: function(headers) {
+        let headerTable = document.getElementById('geary-message-headers');
+        if (headerTable) headerTable.parentNode.removeChild(headerTable);
+
+        headerTable = document.createElement('table');
+        headerTable.id = 'geary-message-headers';
+        for (header in headers) {
+            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 = headers[header];
+        }
+
+        document.body.insertBefore(headerTable, document.body.firstChild);
+    },
     loaded: function() {
         this.updateDirection();
         this.createControllableQuotes();


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