[evolution/webkit: 55/171] Apply the ordering of headers to the generated message



commit dfcc05719f04e3b4b4d131ead387f2d8048c67cc
Author: Dan VrÃtil <dvratil redhat com>
Date:   Wed Jan 4 12:24:06 2012 +0100

    Apply the ordering of headers to the generated message
    
    TODO: the message is still not reloaded before actual printing, so the changes
    in headers are not visible on the printout.

 em-format/em-format.c       |   46 ++++++++++++++++++------------------------
 em-format/em-format.h       |    4 +-
 mail/e-mail-printer.c       |   42 ++++++++++++++++++++++++++++++++++++--
 mail/em-format-html-print.c |    8 +++---
 4 files changed, 65 insertions(+), 35 deletions(-)
---
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 27593f4..eac82dd 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -1684,33 +1684,18 @@ em_format_add_header_struct (EMFormat *emf,
 	g_return_if_fail (EM_IS_FORMAT (emf));
 	g_return_if_fail (header && header->name);
 
-	g_queue_push_tail (&emf->header_list, header);
+	em_format_add_header (emf, header->name, header->value, header->flags);
 }
 
 void
-em_format_add_puri (EMFormat *emf,
-		    EMFormatPURI *puri)
-{
-	g_return_if_fail (EM_IS_FORMAT (emf));
-	g_return_if_fail (puri != NULL);
-
-	emf->mail_part_list = g_list_append (emf->mail_part_list, puri);
-
-	g_hash_table_insert (emf->mail_part_table,
-			puri->uri, puri);
-
-	d(printf("Added PURI %s\n", puri->uri));
-}
-
-EMFormatHeader*
 em_format_remove_header (EMFormat* emf,
 			 const gchar* name,
 			 const gchar* value)
 {
 	GList *iter = NULL;
 
-	g_return_val_if_fail (EM_IS_FORMAT (emf), NULL);
-	g_return_val_if_fail (name && *name, NULL);
+	g_return_if_fail (EM_IS_FORMAT (emf));
+	g_return_if_fail (name && *name);
 
         iter = g_queue_peek_head_link (&emf->header_list);
         while (iter) {
@@ -1738,25 +1723,34 @@ em_format_remove_header (EMFormat* emf,
 	}
 
 	if (iter) {
-		EMFormatHeader *header = iter->data;
+                em_format_header_free (iter->data);
 		g_queue_delete_link (&emf->header_list, iter);
-
-		return header;
 	}
-
-	return NULL;
 }
 
-EMFormatHeader*
+void
 em_format_remove_header_struct (EMFormat* emf,
 				const EMFormatHeader* header)
 {
-	g_return_val_if_fail (header, NULL);
+	g_return_if_fail (header);
 
-	return em_format_remove_header (emf, header->name, header->value);
+	em_format_remove_header (emf, header->name, header->value);
 }
 
+void
+em_format_add_puri (EMFormat *emf,
+                    EMFormatPURI *puri)
+{
+        g_return_if_fail (EM_IS_FORMAT (emf));
+        g_return_if_fail (puri != NULL);
 
+        emf->mail_part_list = g_list_append (emf->mail_part_list, puri);
+
+        g_hash_table_insert (emf->mail_part_table,
+                        puri->uri, puri);
+
+        d(printf("Added PURI %s\n", puri->uri));
+}
 
 EMFormatPURI*
 em_format_find_puri (EMFormat *emf,
diff --git a/em-format/em-format.h b/em-format/em-format.h
index c7d1160..1422b18 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -233,10 +233,10 @@ void			em_format_add_header		(EMFormat *emf,
 							 guint32 flags);
 void			em_format_add_header_struct	(EMFormat *emf,
 							 EMFormatHeader *header);
-EMFormatHeader*		em_format_remove_header		(EMFormat *emf,
+void	        	em_format_remove_header		(EMFormat *emf,
 							 const gchar *name,
 							 const gchar *value);
-EMFormatHeader*		em_format_remove_header_struct	(EMFormat *emf,
+void                    em_format_remove_header_struct	(EMFormat *emf,
 							 const EMFormatHeader *header);
 
 void			em_format_add_puri		(EMFormat *emf,
diff --git a/mail/e-mail-printer.c b/mail/e-mail-printer.c
index 3fccca6..45ed25f 100644
--- a/mail/e-mail-printer.c
+++ b/mail/e-mail-printer.c
@@ -168,8 +168,12 @@ emp_run_print_operation (EMailPrinter *emp)
         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);
 	}
 
+        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) {
@@ -379,8 +383,8 @@ emp_headers_tab_move (GtkWidget *button,
 }
 
 static GtkWidget*
-emp_get_headers_tab (GtkPrintOperation *operation,
-		     EMailPrinter *emp)
+emp_create_headers_tab (GtkPrintOperation *operation,
+                        EMailPrinter *emp)
 {
 	GtkWidget *vbox, *hbox, *label, *scw, *button;
 	GtkTreeView *view;
@@ -474,6 +478,36 @@ emp_get_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)
 {
@@ -681,7 +715,9 @@ e_mail_printer_print (EMailPrinter *emp,
 
 	gtk_print_operation_set_show_progress (emp->priv->operation, TRUE);
 	g_signal_connect (emp->priv->operation, "create-custom-widget",
-		G_CALLBACK (emp_get_headers_tab), emp);
+		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_swapped (cancellable, "cancelled",
diff --git a/mail/em-format-html-print.c b/mail/em-format-html-print.c
index ccc3c63..59750b3 100644
--- a/mail/em-format-html-print.c
+++ b/mail/em-format-html-print.c
@@ -81,8 +81,7 @@ efhp_write_headers (EMFormat *emf,
 		subject);
 	g_free (subject);
 
-	for (iter = g_queue_peek_head_link (&emf->header_list); 
-	     iter->next != NULL; iter = iter->next) {
+	for (iter = g_queue_peek_head_link (&emf->header_list); iter; iter = iter->next) {
 
 		EMFormatHeader *header = iter->data;
 		raw_header.name = header->name;
@@ -117,7 +116,7 @@ efhp_write_headers (EMFormat *emf,
 	raw_header.name = _("Security");
 	tmp = g_string_new ("");
 	/* Find first secured part. */
-	for (iter = g_list_find (emf->mail_part_list, puri)->next; iter->next != NULL; iter = iter->next) {
+	for (iter = emf->mail_part_list, puri; iter; iter = iter->next) {
 
 		p = iter->data;
 
@@ -163,7 +162,8 @@ efhp_write_headers (EMFormat *emf,
 
 	/* Count attachments and display the number as a header */
 	attachments_count = 0;
-	for (iter = emf->mail_part_list; iter->next != NULL; iter = iter->next) {
+
+	for (iter = emf->mail_part_list; iter; iter = iter->next) {
 
 		p = iter->data;
 



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