[evolution/webkit: 96/182] Port 'drop&drop to PDF' to EMailPrinter



commit 9d5be9021a386ea85ccd1822c17d678c0fb511ab
Author: Dan VrÃtil <dvratil redhat com>
Date:   Wed Jan 4 14:53:15 2012 +0100

    Port 'drop&drop to PDF' to EMailPrinter
    
    This adds ability to run GTK_PRINT_OPERATION_ACTION_EXPORT via EMailPrinter

 mail/e-mail-printer.c    |   26 ++++++++++++++++++++++++++
 mail/e-mail-printer.h    |    8 ++++++++
 mail/em-composer-utils.c |    2 +-
 mail/em-utils.c          |   36 ++++++++++++++++++++++++++++--------
 4 files changed, 63 insertions(+), 9 deletions(-)
---
diff --git a/mail/e-mail-printer.c b/mail/e-mail-printer.c
index b67936e..dc2f5f7 100644
--- a/mail/e-mail-printer.c
+++ b/mail/e-mail-printer.c
@@ -778,6 +778,32 @@ e_mail_printer_print (EMailPrinter *emp,
 	emp_run_print_operation (emp, export);
 }
 
+const gchar*
+e_mail_printer_get_export_filename (EMailPrinter * printer)
+{
+        g_return_val_if_fail (E_IS_MAIL_PRINTER (printer), NULL);
+
+        if (!printer->priv->efhp)
+          return NULL;
+
+        return printer->priv->efhp->export_filename;
+}
+
+void
+e_mail_printer_set_export_filename (EMailPrinter * printer,
+                                    const gchar * filename)
+{
+        g_return_if_fail (E_IS_MAIL_PRINTER (printer));
+        g_return_if_fail (printer->priv->efhp != NULL);
+
+        if (printer->priv->efhp->export_filename && *printer->priv->efhp->export_filename)
+          g_free (printer->priv->efhp->export_filename);
+
+        printer->priv->efhp->export_filename = g_strdup (filename);
+}
+
+
+
 EMFormatHTMLPrint*
 e_mail_printer_get_print_formatter (EMailPrinter *emp)
 {
diff --git a/mail/e-mail-printer.h b/mail/e-mail-printer.h
index 95d38a3..f0ebb0a 100644
--- a/mail/e-mail-printer.h
+++ b/mail/e-mail-printer.h
@@ -69,6 +69,14 @@ void		e_mail_printer_print	(EMailPrinter *printer,
 					 gboolean export,
 					 GCancellable *cancellable);
 
+void            e_mail_printer_set_export_filename 
+                                        (EMailPrinter *printer,
+                                         const gchar *filename);
+
+const gchar*    e_mail_printer_get_export_filename
+                                        (EMailPrinter *printer);
+
+
 EMFormatHTMLPrint *
 		e_mail_printer_get_print_formatter
 					(EMailPrinter *printer);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 915c7c9..aa10baa 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -951,7 +951,7 @@ em_utils_composer_print_cb (EMsgComposer *composer,
         EMailPrinter *emp;
         EMFormatHTMLDisplay *efhd;
 
-        efhd = g_object_new (EM_TYPE_FORMAT_HTML_DISPLAY, NULL);
+	efhd = em_format_html_display_new ();
         ((EMFormat *) efhd)->message_uid = g_strdup (camel_mime_message_get_message_id (message));
 
         /* Parse the message */
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 4bcbe5d..f019863 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -72,8 +72,10 @@
 
 #include "e-mail-tag-editor.h"
 #include "em-composer-utils.h"
+#include "em-format-html-display.h"
 #include "em-format-html-print.h"
 #include "em-utils.h"
+#include "e-mail-printer.h"
 #include "em-format/em-format-quote.h"
 
 /* XXX This is a dirty hack on a dirty hack.  We really need
@@ -616,26 +618,44 @@ em_utils_write_messages_to_stream (CamelFolder *folder,
 	return res;
 }
 
+static void
+do_print_msg_to_file (GObject *source,
+		      GAsyncResult *result,
+		      gpointer user_data)
+{
+
+	EMFormatHTML *efh = EM_FORMAT_HTML (source);
+	gchar *filename = user_data;
+
+	EMailPrinter *printer;
+
+	printer = e_mail_printer_new (efh);
+        e_mail_printer_set_export_filename (printer, filename);
+	g_signal_connect_swapped (printer, "done",
+		G_CALLBACK (g_object_unref), printer);
+
+        e_mail_printer_print (printer, TRUE, NULL);
+
+	g_object_unref (efh);
+}
+
 static gboolean
 em_utils_print_messages_to_file (CamelFolder *folder,
                                  const gchar *uid,
                                  const gchar *filename)
 {
-	EMFormatHTMLPrint *efhp;
+	EMFormatHTMLDisplay *efhd;
 	CamelMimeMessage *message;
 
 	message = camel_folder_get_message_sync (folder, uid, NULL, NULL);
 	if (message == NULL)
 		return FALSE;
 
-	efhp = em_format_html_print_new (NULL);
-	efhp->export_filename = g_strdup (filename);
-	efhp->async = FALSE;
-
-	em_format_html_print_message (efhp, message, folder, uid);
+	efhd = em_format_html_display_new ();
+	((EMFormat *) efhd)->message_uid = g_strdup (uid);
 
-	g_object_unref (efhp);
-	g_object_unref (message);
+	em_format_parse_async ((EMFormat *) efhd, message, folder, NULL,
+		(GAsyncReadyCallback) do_print_msg_to_file, g_strdup (filename));
 
 	return TRUE;
 }



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