[evolution/webkit: 85/196] Finish porting of printing - solves all print-out rendering issues
- From: Dan VrÃtil <dvratil src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/webkit: 85/196] Finish porting of printing - solves all print-out rendering issues
- Date: Tue, 27 Mar 2012 16:07:52 +0000 (UTC)
commit e8e62f713749bf1fd2154fa63e330b14566b04f8
Author: Dan VrÃtil <dvratil redhat com>
Date: Fri Dec 16 17:17:24 2011 +0100
Finish porting of printing - solves all print-out rendering issues
Selecting which headers to print or re-ordering them is now reflected
in real time in the webkit webview using DOM API so there is no need
to reload the document after the printing dialog is confirmed. This
solution seems to solve all problems with incorrectly rendered print-out.
mail/e-mail-printer.c | 255 +++++++++++++++++++++++++------------------
mail/e-mail-printer.h | 4 +-
mail/e-mail-reader-utils.c | 53 +---------
mail/em-composer-utils.c | 4 +-
mail/em-format-html-print.c | 65 ++---------
mail/em-format-html-print.h | 5 +-
mail/em-format-html.c | 35 +++++--
mail/em-format-html.h | 1 +
mail/em-utils.c | 2 +-
9 files changed, 197 insertions(+), 227 deletions(-)
---
diff --git a/mail/e-mail-printer.c b/mail/e-mail-printer.c
index e53bf41..b67936e 100644
--- a/mail/e-mail-printer.c
+++ b/mail/e-mail-printer.c
@@ -24,8 +24,11 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include <e-util/e-print.h>
#include <e-util/e-marshal.h>
+#include <webkit/webkitdom.h>
+
#include "e-mail-printer.h"
#include "em-format-html-print.h"
@@ -45,13 +48,13 @@ struct _EMailPrinterPrivate {
EMFormatHTMLPrint *efhp;
GtkListStore *headers;
-
+
WebKitWebView *webview; /* WebView to print from */
gchar *uri;
- GtkWidget *buttons[BUTTONS_COUNT];
- GtkWidget *treeview;
+ GtkWidget *buttons[BUTTONS_COUNT];
+ GtkWidget *treeview;
- GtkPrintOperation *operation;
+ GtkPrintOperation *operation;
};
G_DEFINE_TYPE (
@@ -142,7 +145,8 @@ emp_printing_done (GtkPrintOperation *operation,
}
static void
-emp_run_print_operation (EMailPrinter *emp)
+emp_run_print_operation (EMailPrinter *emp,
+ gboolean export)
{
EMFormat *emf;
SoupSession *session;
@@ -166,17 +170,16 @@ emp_run_print_operation (EMailPrinter *emp)
emp->priv->uri = g_strconcat (mail_uri, "?part_id=print_layout", NULL);
if (emp->priv->webview == NULL) {
- emp->priv->webview = WEBKIT_WEB_VIEW (webkit_web_view_new ());
- g_object_ref_sink (emp->priv->webview);
- g_signal_connect_swapped (emp->priv->operation, "begin-print",
- G_CALLBACK (webkit_web_view_reload), emp->priv->webview);
+ 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);
}
webkit_web_view_load_uri (emp->priv->webview, emp->priv->uri);
frame = webkit_web_view_get_main_frame (emp->priv->webview);
- if (em_format_html_print_get_action (emp->priv->efhp) == GTK_PRINT_OPERATION_ACTION_EXPORT) {
+ if (export) {
gtk_print_operation_set_export_filename (emp->priv->operation, emp->priv->efhp->export_filename);
webkit_web_frame_print_full (frame, emp->priv->operation, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL);
} else {
@@ -186,16 +189,38 @@ emp_run_print_operation (EMailPrinter *emp)
g_free (mail_uri);
}
+static void
+set_header_visible (EMailPrinter *emp,
+ EMFormatHeader *header,
+ gint index,
+ gboolean visible)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMNodeList *headers;
+ WebKitDOMElement *element;
+ WebKitDOMCSSStyleDeclaration *style;
+
+ document = webkit_web_view_get_dom_document (emp->priv->webview);
+ headers = webkit_dom_document_get_elements_by_class_name (document, "header-item");
+
+ g_return_if_fail (index < webkit_dom_node_list_get_length (headers));
+
+ element = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (headers, index));
+ style = webkit_dom_element_get_style (element);
+ webkit_dom_css_style_declaration_set_property (style,
+ "display", (visible ? "table-row" : "none"), "", NULL);
+}
static void
header_active_renderer_toggled_cb (GtkCellRendererToggle *renderer,
gchar *path,
EMailPrinter *emp)
{
- EMFormat *emf = (EMFormat *)emp->priv->efhp;
GtkTreeIter iter;
+ GtkTreePath *p;
gboolean active;
EMFormatHeader *header;
+ gint *indices;
gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (emp->priv->headers),
&iter, path);
@@ -206,13 +231,11 @@ header_active_renderer_toggled_cb (GtkCellRendererToggle *renderer,
COLUMN_HEADER_STRUCT, &header, -1);
gtk_list_store_set (GTK_LIST_STORE (emp->priv->headers), &iter,
COLUMN_ACTIVE, !active, -1);
-
- /* If the new state is active */
- if ((!active) == TRUE) {
- em_format_add_header_struct (emf, header);
- } else {
- em_format_remove_header_struct (emf, header);
- }
+
+ p = gtk_tree_path_new_from_string (path);
+ indices = gtk_tree_path_get_indices (p);
+ set_header_visible (emp, header, indices[0], !active);
+ gtk_tree_path_free (p);
}
static void
@@ -220,7 +243,6 @@ emp_headers_tab_toggle_selection (GtkWidget *button,
gpointer user_data)
{
EMailPrinter *emp = user_data;
- EMFormat *emf = (EMFormat *) emp->priv->efhp;
GtkTreeIter iter;
gboolean select;
@@ -236,16 +258,18 @@ emp_headers_tab_toggle_selection (GtkWidget *button,
do {
EMFormatHeader *header;
+ GtkTreePath *path;
+ gint *indices;
gtk_tree_model_get (GTK_TREE_MODEL (emp->priv->headers), &iter,
COLUMN_HEADER_STRUCT, &header, -1);
gtk_list_store_set (GTK_LIST_STORE (emp->priv->headers), &iter,
COLUMN_ACTIVE, select, -1);
- if (select)
- em_format_add_header_struct (emf, header);
- else
- em_format_remove_header_struct (emf, header);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (emp->priv->headers), &iter);
+ indices = gtk_tree_path_get_indices (path);
+ set_header_visible (emp, header, indices[0], select);
+ gtk_tree_path_free (path);
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (emp->priv->headers), &iter));
}
@@ -299,77 +323,127 @@ emp_headers_tab_move (GtkWidget *button,
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreeRowReference *selection_middle;
+ gint *indices;
+
+ WebKitDOMDocument *document;
+ WebKitDOMNodeList *headers;
+ WebKitDOMNode *header, *parent;
model = GTK_TREE_MODEL (emp->priv->headers);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (emp->priv->treeview));
selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
+ /* The order of header rows in the HMTL document should be in sync with
+ order of headers in the listview and in efhp->headers_list */
+ document = webkit_web_view_get_dom_document (emp->priv->webview);
+ headers = webkit_dom_document_get_elements_by_class_name (document, "header-item");
+
l = g_list_nth (selected_rows, g_list_length (selected_rows) / 2);
selection_middle = gtk_tree_row_reference_new (model, l->data);
- references = NULL;
+ for (l = selected_rows; l; l = l->next) {
+ references = g_list_prepend (references,
+ gtk_tree_row_reference_new (model, l->data));
+ }
if (button == emp->priv->buttons[BUTTON_TOP]) {
- for (l = selected_rows; l; l = l->next) {
- references = g_list_prepend (references,
- gtk_tree_row_reference_new (model, l->data));
- }
-
for (l = references; l; l = l->next) {
+ /* Move the rows in the view */
path = gtk_tree_row_reference_get_path (l->data);
gtk_tree_model_get_iter (model, &iter, path);
gtk_list_store_move_after (emp->priv->headers, &iter, NULL);
+
+ /* Move the header row in HTML document */
+ indices = gtk_tree_path_get_indices (path);
+ header = webkit_dom_node_list_item (headers, indices[0]);
+ parent = webkit_dom_node_get_parent_node (header);
+ webkit_dom_node_remove_child (parent, header, NULL);
+ webkit_dom_node_insert_before (parent, header,
+ webkit_dom_node_get_first_child (parent), NULL);
+
gtk_tree_path_free (path);
}
- g_list_foreach (references, (GFunc) gtk_tree_row_reference_free, NULL);
- g_list_free (references);
+ } else if (button == emp->priv->buttons[BUTTON_UP]) {
+
+ GtkTreeIter *iter_prev;
+ WebKitDOMNode *node2;
+
+ references = g_list_reverse (references);
+
+ for (l = references; l; l = l->next) {
- } else if (button == emp->priv->buttons[BUTTON_UP]) {
+ path = gtk_tree_row_reference_get_path (l->data);
+ gtk_tree_model_get_iter (model, &iter, path);
+ iter_prev = gtk_tree_iter_copy (&iter);
+ gtk_tree_model_iter_previous (model, iter_prev);
- GtkTreeIter iter_last;
+ gtk_list_store_move_before (emp->priv->headers, &iter, iter_prev);
- gtk_tree_model_get_iter (model, &iter, selected_rows->data);
- gtk_tree_model_iter_previous (model, &iter);
+ indices = gtk_tree_path_get_indices (path);
+ header = webkit_dom_node_list_item (headers, indices[0]);
+ node2 = webkit_dom_node_get_previous_sibling (header);
+ parent = webkit_dom_node_get_parent_node (header);
- gtk_tree_model_get_iter (model, &iter_last,
- g_list_last (selected_rows)->data);
+ webkit_dom_node_remove_child (parent, header, NULL);
+ webkit_dom_node_insert_before (parent, header, node2, NULL);
- gtk_list_store_move_after (emp->priv->headers, &iter, &iter_last);
+ gtk_tree_path_free (path);
+ gtk_tree_iter_free (iter_prev);
+ }
} else if (button == emp->priv->buttons[BUTTON_DOWN]) {
- GtkTreeIter iter_last;
+ GtkTreeIter *iter_next;
+ WebKitDOMNode *node2;
+
+ for (l = references; l; l = l->next) {
- gtk_tree_model_get_iter (model, &iter, selected_rows->data);
+ path = gtk_tree_row_reference_get_path (l->data);
+ gtk_tree_model_get_iter (model, &iter, path);
+ iter_next = gtk_tree_iter_copy (&iter);
+ gtk_tree_model_iter_next (model, iter_next);
- gtk_tree_model_get_iter (model, &iter_last,
- g_list_last (selected_rows)->data);
- gtk_tree_model_iter_next (model, &iter_last);
+ gtk_list_store_move_after (emp->priv->headers, &iter, iter_next);
- gtk_list_store_move_before (emp->priv->headers, &iter_last, &iter);
+ indices = gtk_tree_path_get_indices (path);
+ header = webkit_dom_node_list_item (headers, indices[0]);
+ node2 = webkit_dom_node_get_next_sibling (header);
+ parent = webkit_dom_node_get_parent_node (header);
- } else if (button == emp->priv->buttons[BUTTON_BOTTOM]) {
+ webkit_dom_node_remove_child (parent, header, NULL);
+ webkit_dom_node_insert_before (parent, header,
+ webkit_dom_node_get_next_sibling (node2), NULL);
- for (l = selected_rows; l; l = l->next) {
- references = g_list_prepend (references,
- gtk_tree_row_reference_new (model, l->data));
+ gtk_tree_path_free (path);
+ gtk_tree_iter_free (iter_next);
}
+
+ } else if (button == emp->priv->buttons[BUTTON_BOTTOM]) {
+
references = g_list_reverse (references);
for (l = references; l; l = l->next) {
path = gtk_tree_row_reference_get_path (l->data);
gtk_tree_model_get_iter (model, &iter, path);
gtk_list_store_move_before (emp->priv->headers, &iter, NULL);
- gtk_tree_path_free (path);
- }
- g_list_foreach (references, (GFunc) gtk_tree_row_reference_free, NULL);
- g_list_free (references);
+ /* Move the header row in HTML document */
+ indices = gtk_tree_path_get_indices (path);
+ header = webkit_dom_node_list_item (headers, indices[0]);
+ parent = webkit_dom_node_get_parent_node (header);
+ webkit_dom_node_remove_child (parent, header, NULL);
+ webkit_dom_node_append_child (parent, header, NULL);
+ gtk_tree_path_free (path);
+ }
};
+ g_list_foreach (references, (GFunc) gtk_tree_row_reference_free, NULL);
+ g_list_free (references);
+
+ /* Keep the selection in middle of the screen */
path = gtk_tree_row_reference_get_path (selection_middle);
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (emp->priv->treeview),
path, COLUMN_ACTIVE, TRUE, 0.5, 0.5);
@@ -386,7 +460,7 @@ static GtkWidget*
emp_create_headers_tab (GtkPrintOperation *operation,
EMailPrinter *emp)
{
- GtkWidget *vbox, *hbox, *label, *scw, *button;
+ GtkWidget *vbox, *hbox, *scw, *button;
GtkTreeView *view;
GtkTreeSelection *selection;
GtkTreeViewColumn *column;
@@ -395,11 +469,8 @@ emp_create_headers_tab (GtkPrintOperation *operation,
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_box_pack_end (GTK_BOX (hbox), vbox, FALSE, FALSE, 5);
-/*
- label = gtk_label_new (_("Select headers you want to print"));
- gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 2, 1);
-*/
- emp->priv->treeview = gtk_tree_view_new_with_model (
+
+ emp->priv->treeview = gtk_tree_view_new_with_model (
GTK_TREE_MODEL (emp->priv->headers));
view = GTK_TREE_VIEW (emp->priv->treeview);
selection = gtk_tree_view_get_selection (view);
@@ -437,7 +508,7 @@ emp_create_headers_tab (GtkPrintOperation *operation,
G_CALLBACK (emp_headers_tab_toggle_selection), emp);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, TRUE, 5);
- button = gtk_button_new_with_label (_("Unselect All"));
+ button = gtk_button_new_from_stock (GTK_STOCK_CLEAR);
emp->priv->buttons[BUTTON_SELECT_NONE] = button;
g_signal_connect (button, "clicked",
G_CALLBACK (emp_headers_tab_toggle_selection), emp);
@@ -478,36 +549,6 @@ emp_create_headers_tab (GtkPrintOperation *operation,
}
static void
-emp_headers_tab_apply (GtkPrintOperation *operation,
- GtkWidget *widget,
- gpointer user_data)
-{
- EMailPrinter *emp = user_data;
- GtkTreeIter iter;
- GtkTreeModel *model;
- EMFormat *emf;
-
- emf = EM_FORMAT (emp->priv->efhp);
- model = GTK_TREE_MODEL (emp->priv->headers);
-
- g_queue_clear (&emf->header_list);
- gtk_tree_model_get_iter_first (model, &iter);
- do {
- gboolean active;
- EMFormatHeader *header;
-
- gtk_tree_model_get (model, &iter,
- COLUMN_ACTIVE, &active,
- COLUMN_HEADER_STRUCT, &header, -1);
-
- if (active)
- em_format_add_header_struct (emf, header);
-
- } while (gtk_tree_model_iter_next (model, &iter));
-
-}
-
-static void
emp_set_formatter (EMailPrinter *emp,
EMFormatHTMLPrint *formatter)
{
@@ -515,6 +556,7 @@ emp_set_formatter (EMailPrinter *emp,
CamelMediumHeader *header;
GArray *headers;
gint i;
+ GtkTreeIter last_known;
g_return_if_fail (EM_IS_FORMAT_HTML_PRINT (formatter));
@@ -538,27 +580,31 @@ emp_set_formatter (EMailPrinter *emp,
GtkTreeIter iter;
GList *found_header;
EMFormatHeader *emfh;
- gint index = G_MAXINT;
header = &g_array_index (headers, CamelMediumHeader, i);
emfh = em_format_header_new (header->name, header->value);
-
+
found_header = g_queue_find_custom (&EM_FORMAT (formatter)->header_list,
emfh, (GCompareFunc) emp_header_name_equal);
- if (found_header) {
- index = g_queue_link_index (&EM_FORMAT (formatter)->header_list,
- found_header);
- }
-
- gtk_list_store_insert (emp->priv->headers, &iter, index);
+ if (!found_header) {
+ emfh->flags |= EM_FORMAT_HTML_HEADER_HIDDEN;
+ em_format_add_header_struct (EM_FORMAT (formatter), emfh);
+ gtk_list_store_append (emp->priv->headers, &iter);
+ } else {
+ if (gtk_list_store_iter_is_valid (emp->priv->headers, &last_known))
+ gtk_list_store_insert_after (emp->priv->headers, &iter, &last_known);
+ else
+ gtk_list_store_insert_after (emp->priv->headers, &iter, NULL);
+
+ last_known = iter;
+ }
gtk_list_store_set (emp->priv->headers, &iter,
COLUMN_ACTIVE, (found_header != NULL),
COLUMN_HEADER_NAME, emfh->name,
COLUMN_HEADER_VALUE, emfh->value,
COLUMN_HEADER_STRUCT, emfh, -1);
-
}
camel_medium_free_headers (CAMEL_MEDIUM (emf->message), headers);
@@ -690,13 +736,12 @@ e_mail_printer_init (EMailPrinter *emp)
}
EMailPrinter*
-e_mail_printer_new (EMFormatHTML* source,
- GtkPrintOperationAction action)
+e_mail_printer_new (EMFormatHTML* source)
{
EMailPrinter *emp;
EMFormatHTMLPrint *efhp;
- efhp = em_format_html_print_new (source, action);
+ efhp = em_format_html_print_new (source);
emp = g_object_new (E_TYPE_MAIL_PRINTER,
"print-formatter", efhp, NULL);
@@ -708,19 +753,19 @@ e_mail_printer_new (EMFormatHTML* source,
void
e_mail_printer_print (EMailPrinter *emp,
+ gboolean export,
GCancellable *cancellable)
{
g_return_if_fail (E_IS_MAIL_PRINTER (emp));
if (emp->priv->operation)
g_object_unref (emp->priv->operation);
- emp->priv->operation = gtk_print_operation_new ();
+ emp->priv->operation = e_print_operation_new ();
+ gtk_print_operation_set_unit (emp->priv->operation, GTK_UNIT_PIXEL);
gtk_print_operation_set_show_progress (emp->priv->operation, TRUE);
g_signal_connect (emp->priv->operation, "create-custom-widget",
G_CALLBACK (emp_create_headers_tab), emp);
- g_signal_connect (emp->priv->operation, "custom-widget-apply",
- G_CALLBACK (emp_headers_tab_apply), emp);
g_signal_connect (emp->priv->operation, "done",
G_CALLBACK (emp_printing_done), emp);
g_signal_connect (emp->priv->operation, "draw-page",
@@ -730,7 +775,7 @@ e_mail_printer_print (EMailPrinter *emp,
g_signal_connect_swapped (cancellable, "cancelled",
G_CALLBACK (gtk_print_operation_cancel), emp->priv->operation);
- emp_run_print_operation (emp);
+ emp_run_print_operation (emp, export);
}
EMFormatHTMLPrint*
diff --git a/mail/e-mail-printer.h b/mail/e-mail-printer.h
index e8eea75..95d38a3 100644
--- a/mail/e-mail-printer.h
+++ b/mail/e-mail-printer.h
@@ -63,10 +63,10 @@ struct _EMailPrinterClass {
GType e_mail_printer_get_type (void);
-EMailPrinter * e_mail_printer_new (EMFormatHTML *source,
- GtkPrintOperationAction action);
+EMailPrinter * e_mail_printer_new (EMFormatHTML *source);
void e_mail_printer_print (EMailPrinter *printer,
+ gboolean export,
GCancellable *cancellable);
EMFormatHTMLPrint *
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 8bfc996..0166f44 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -433,55 +433,6 @@ e_mail_reader_open_selected (EMailReader *reader)
}
static void
-mail_reader_printing_finished (GtkPrintOperation *operation,
- GtkPrintOperationResult result,
- EActivity *activity)
-{
- WebKitWebView *webview;
-
- webview = g_object_get_data (G_OBJECT (activity), "webview");
-
- /* Destroy the webview */
- g_object_unref (webview);
-
- e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
-}
-
-
-static void
-webview_document_load_finished_cb (WebKitWebView *webview,
- GParamSpec *pspec,
- EActivity *activity)
-{
- GtkPrintOperation *operation;
- GtkPrintOperationAction action;
- EMFormatHTMLPrint *efhp;
- WebKitWebFrame *frame;
-
- WebKitLoadStatus status = webkit_web_view_get_load_status (webview);
-
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- frame = webkit_web_view_get_main_frame (webview);
- efhp = g_object_get_data (G_OBJECT (activity), "efhp");
- action = em_format_html_print_get_action (efhp);
-
- operation = gtk_print_operation_new ();
- gtk_print_operation_set_show_progress (operation, TRUE);
-
- g_object_set_data (G_OBJECT (operation), "webview", webview);
- g_signal_connect (operation, "done",
- G_CALLBACK (mail_reader_printing_finished), activity);
-
- action = em_format_html_print_get_action (efhp);
- webkit_web_frame_print_full (frame,
- operation, action, NULL);
-
- g_object_unref (efhp);
-}
-
-static void
printing_done_cb (EMailPrinter *printer,
GtkPrintOperation *operation,
GtkPrintOperationResult result,
@@ -537,10 +488,10 @@ e_mail_reader_print (EMailReader *reader,
e_activity_set_state (activity, E_ACTIVITY_RUNNING);
cancellable = e_activity_get_cancellable (activity);
- printer = e_mail_printer_new (formatter, action);
+ printer = e_mail_printer_new (formatter);
g_signal_connect (printer, "done",
G_CALLBACK (printing_done_cb), activity);
- e_mail_printer_print (printer, cancellable);
+ e_mail_printer_print (printer, FALSE, cancellable);
}
static void
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index aa272a1..2ab73ad 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -958,11 +958,11 @@ em_utils_composer_print_cb (EMsgComposer *composer,
em_format_parse ((EMFormat *) efhd, message, NULL, NULL);
/* Use EMailPrinter and WebKit to print the message */
- emp = e_mail_printer_new ((EMFormatHTML *) efhd, action);
+ emp = e_mail_printer_new ((EMFormatHTML *) efhd);
g_signal_connect (emp, "done",
G_CALLBACK (composer_print_done_cb), efhd);
- e_mail_printer_print (emp, NULL);
+ e_mail_printer_print (emp, FALSE, NULL);
}
/* Composing messages... */
diff --git a/mail/em-format-html-print.c b/mail/em-format-html-print.c
index 46aebad..8fb06c8 100644
--- a/mail/em-format-html-print.c
+++ b/mail/em-format-html-print.c
@@ -45,7 +45,6 @@ struct _EMFormatHTMLPrintPrivate {
EMFormatHTML *original_formatter;
EMFormatPURI *top_level_puri;
- GtkPrintOperationAction print_action;
/* List of attachment PURIs */
GList *attachments;
@@ -54,8 +53,7 @@ struct _EMFormatHTMLPrintPrivate {
enum {
PROP_0,
- PROP_ORIGINAL_FORMATTER,
- PROP_PRINT_ACTION
+ PROP_ORIGINAL_FORMATTER
};
static void efhp_write_print_layout (EMFormat *emf, EMFormatPURI *puri, CamelStream *stream, EMFormatWriterInfo *info, GCancellable *cancellable);
@@ -139,7 +137,7 @@ 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><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);
@@ -161,7 +159,7 @@ efhp_write_headers (EMFormat *emf,
} else {
raw_header.value = g_strdup (camel_medium_get_header (
CAMEL_MEDIUM (emf->message), header->name));
-
+
if (raw_header.value && *raw_header.value) {
em_format_html_format_header (emf, str,
CAMEL_MEDIUM (puri->part), &raw_header,
@@ -176,7 +174,7 @@ efhp_write_headers (EMFormat *emf,
/* Get prefix of this PURI */
puri_prefix = g_strndup (puri->uri, g_strrstr (puri->uri, ".") - puri->uri);
-
+
/* Add encryption/signature header */
raw_header.name = _("Security");
tmp = g_string_new ("");
@@ -203,7 +201,7 @@ efhp_write_headers (EMFormat *emf,
if ((p->validity_type & EM_FORMAT_VALIDITY_FOUND_SMIME) &&
(p->validity_type & EM_FORMAT_VALIDITY_FOUND_SIGNED)) {
- if (tmp->len > 0) g_string_append (tmp, ", ");
+ if (tmp->len > 0) g_string_append (tmp, ", ");
g_string_append (tmp, _("S/MIME signed"));
}
if ((p->validity_type & EM_FORMAT_VALIDITY_FOUND_SMIME) &&
@@ -221,7 +219,7 @@ efhp_write_headers (EMFormat *emf,
em_format_html_format_header (emf, str, CAMEL_MEDIUM (p->part),
&raw_header, EM_FORMAT_HEADER_BOLD | EM_FORMAT_HTML_HEADER_NOLINKS, "UTF-8");
}
- g_string_free (tmp, TRUE);
+ g_string_free (tmp, TRUE);
/* Count attachments and display the number as a header */
attachments_count = 0;
@@ -329,12 +327,12 @@ efhp_write_print_layout (EMFormat *emf,
handler ? handler->mime_type : "(null)");
g_free (mime_type);
- efhp->priv->attachments =
+ efhp->priv->attachments =
g_list_append (efhp->priv->attachments, puri);
/* If we can't inline this attachment, skip it */
if (handler && puri->write_func) {
- efhp_write_inline_attachment (puri->emf, puri,
+ efhp_write_inline_attachment (puri->emf, puri,
stream, &print_info, cancellable);
}
@@ -344,7 +342,7 @@ efhp_write_print_layout (EMFormat *emf,
/* Ignore widget parts and unwritable non-attachment parts */
if (puri->write_func == NULL)
continue;
-
+
/* Passed all tests, probably a regular part - display it */
puri->write_func(puri->emf, puri, stream, &print_info, cancellable);
@@ -454,23 +452,13 @@ efhp_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- EMFormatHTMLPrintPrivate *priv;
-
- priv = EM_FORMAT_HTML_PRINT (object)->priv;
-
switch (prop_id) {
-
+
case PROP_ORIGINAL_FORMATTER:
efhp_set_orig_formatter (
EM_FORMAT_HTML_PRINT (object),
(EMFormat *) g_value_get_object (value));
return;
-
- case PROP_PRINT_ACTION:
- priv->print_action =
- g_value_get_int (value);
- return;
-
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -487,16 +475,11 @@ efhp_get_property (GObject *object,
priv = EM_FORMAT_HTML_PRINT (object)->priv;
switch (prop_id) {
-
+
case PROP_ORIGINAL_FORMATTER:
g_value_set_pointer (value,
priv->original_formatter);
return;
-
- case PROP_PRINT_ACTION:
- g_value_set_int (value,
- priv->print_action);
- return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -535,19 +518,6 @@ em_format_html_print_class_init (EMFormatHTMLPrintClass *klass)
EM_TYPE_FORMAT,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property (
- object_class,
- PROP_PRINT_ACTION,
- g_param_spec_int (
- "print-action",
- NULL,
- NULL,
- GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
- GTK_PRINT_OPERATION_ACTION_EXPORT,
- GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
}
static void
@@ -588,14 +558,12 @@ em_format_html_print_get_type (void)
}
EMFormatHTMLPrint *
-em_format_html_print_new (EMFormatHTML *source,
- GtkPrintOperationAction action)
+em_format_html_print_new (EMFormatHTML *source)
{
EMFormatHTMLPrint *efhp;
efhp = g_object_new (EM_TYPE_FORMAT_HTML_PRINT,
"original-formatter", source,
- "print-action", action,
NULL);
return efhp;
@@ -619,12 +587,3 @@ em_format_html_print_message (EMFormatHTMLPrint *efhp,
/* FIXME Not passing a GCancellable here. */
em_format_parse ((EMFormat *) efhp, message, folder, NULL);
}
-
-GtkPrintOperationAction
-em_format_html_print_get_action (EMFormatHTMLPrint *efhp)
-{
- g_return_val_if_fail (EM_IS_FORMAT_HTML_PRINT (efhp),
- GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
-
- return efhp->priv->print_action;
-}
diff --git a/mail/em-format-html-print.h b/mail/em-format-html-print.h
index cba1e8f..7d16fa9 100644
--- a/mail/em-format-html-print.h
+++ b/mail/em-format-html-print.h
@@ -59,14 +59,11 @@ struct _EMFormatHTMLPrintClass {
GType em_format_html_print_get_type (void);
EMFormatHTMLPrint *
- em_format_html_print_new (EMFormatHTML *source,
- GtkPrintOperationAction action);
+ em_format_html_print_new (EMFormatHTML *source);
void em_format_html_print_message (EMFormatHTMLPrint *efhp,
CamelMimeMessage *message,
CamelFolder *folder,
const gchar *uid);
-GtkPrintOperationAction
- em_format_html_print_get_action (EMFormatHTMLPrint *efhp);
G_END_DECLS
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index 39aca85..a4402da 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -928,6 +928,22 @@ efh_write_headers (EMFormat *emf,
" else { f.display=\"block\"; s.display=\"none\";\n"
" i.src=i.src.substr(0,i.src.lastIndexOf(\"/\"))+\"/minus.png\"; window.headers_collapsed(false, window.em_format_html); }\n"
"}\n"
+ "function set_header_visible(header,value,visible) {\n}"
+ " var hdrs=window.document.getElementsByClassName('header-item');\n"
+ " for (var i = 0; i < hdrs.length; i++) { \n"
+ " var hdr = hdrs[i]; \n"
+ " if (hdr.className.indexOf('rtl') == -1) { \n"
+ " if ((hdr.firstChild.textContent == header) && \n"
+ " (hdr.firstChild.nextSibling.textContent == value)) { \n"
+ " hdr.style.display=(visible ? 'block' : 'none');\n"
+ " }\n"
+ " } else { \n"
+ " if ((hdr.firstChild.textContent == value) && \n"
+ " (hdr.firstChild.nextSibling.textContent == header)) { \n"
+ " hdr.style.display=(visible ? 'block' : 'none');\n"
+ " }\n"
+ " }\n"
+ "}\n"
"</script>\n"
"<style type=\"text/css\">body { background: #%06x; }</style>"
"<table border=\"0\" width=\"100%%\" height=\"100%%\" style=\"color: #%06x;\">\n"
@@ -1791,30 +1807,31 @@ efh_format_text_header (EMFormatHTML *emfh,
if (flags & EM_FORMAT_HTML_HEADER_NOCOLUMNS) {
if (flags & EM_FORMAT_HEADER_BOLD) {
- fmt = "<tr><td><b>%s:</b> %s</td></tr>";
+ fmt = "<tr class=\"header-item\" style=\"display: %s\"><td><b>%s:</b> %s</td></tr>";
} else {
- fmt = "<tr><td>%s: %s</td></tr>";
+ fmt = "<tr class=\"header-item\" style=\"display: %s\"><td>%s: %s</td></tr>";
}
} else if (flags & EM_FORMAT_HTML_HEADER_NODEC) {
if (is_rtl)
- fmt = "<tr><td align=\"right\" valign=\"top\" width=\"100%%\">%2$s</td><th valign=top align=\"left\" nowrap>%1$s<b> </b></th></tr>";
+ 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>";
else
- fmt = "<tr><th align=\"right\" valign=\"top\" nowrap>%s<b> </b></th><td valign=top>%s</td></tr>";
+ fmt = "<tr class=\"header-item\" style=\"display: %s\"><th align=\"right\" valign=\"top\" nowrap>%s<b> </b></th><td valign=top>%s</td></tr>";
} else {
if (flags & EM_FORMAT_HEADER_BOLD) {
if (is_rtl)
- fmt = "<tr><td align=\"right\" valign=\"top\" width=\"100%%\">%2$s</td><th align=\"left\" nowrap>%1$s:<b> </b></th></tr>";
+ 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><th align=\"right\" valign=\"top\" nowrap>%s:<b> </b></th><td>%s</td></tr>";
+ 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><td align=\"right\" valign=\"top\" width=\"100%\">%2$s</td><td align=\"left\" nowrap>%1$s:<b> </b></td></tr>";
+ 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><td align=\"right\" valign=\"top\" nowrap>%s:<b> </b></td><td>%s</td></tr>";
+ fmt = "<tr class=\"header-item\" style=\"display: %s\"><td align=\"right\" valign=\"top\" nowrap>%s:<b> </b></td><td>%s</td></tr>";
}
}
- g_string_append_printf (buffer, fmt, label, html);
+ g_string_append_printf (buffer, fmt,
+ (flags & EM_FORMAT_HTML_HEADER_HIDDEN ? "none" : "table-row"), label, html);
g_free (mhtml);
}
diff --git a/mail/em-format-html.h b/mail/em-format-html.h
index f3fb33d..d91ed8b 100644
--- a/mail/em-format-html.h
+++ b/mail/em-format-html.h
@@ -80,6 +80,7 @@ typedef enum {
#define EM_FORMAT_HTML_HEADER_HTML (EM_FORMAT_HEADER_LAST<<1)
#define EM_FORMAT_HTML_HEADER_NODEC (EM_FORMAT_HEADER_LAST<<2)
#define EM_FORMAT_HTML_HEADER_NOLINKS (EM_FORMAT_HEADER_LAST<<3)
+#define EM_FORMAT_HTML_HEADER_HIDDEN (EM_FORMAT_HEADER_LAST<<4)
#define EM_FORMAT_HTML_HEADER_LAST (EM_FORMAT_HEADER_LAST<<8)
diff --git a/mail/em-utils.c b/mail/em-utils.c
index a053e05..dd50c17 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -628,7 +628,7 @@ em_utils_print_messages_to_file (CamelFolder *folder,
if (message == NULL)
return FALSE;
- efhp = em_format_html_print_new (NULL, GTK_PRINT_OPERATION_ACTION_EXPORT);
+ efhp = em_format_html_print_new (NULL);
efhp->export_filename = g_strdup (filename);
efhp->async = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]