diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-05-11 00:44:10 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-05-11 01:17:13 +0800 |
commit | e68fa9016b55ff27cef322c488958876074000e1 (patch) | |
tree | 1fdb259cdfff953cf4fbf118307b3af62f411974 /mail/em-utils.c | |
parent | 13664a883d98f204d3006cc9636551996ea38686 (diff) | |
download | gsoc2013-evolution-e68fa9016b55ff27cef322c488958876074000e1.tar gsoc2013-evolution-e68fa9016b55ff27cef322c488958876074000e1.tar.gz gsoc2013-evolution-e68fa9016b55ff27cef322c488958876074000e1.tar.bz2 gsoc2013-evolution-e68fa9016b55ff27cef322c488958876074000e1.tar.lz gsoc2013-evolution-e68fa9016b55ff27cef322c488958876074000e1.tar.xz gsoc2013-evolution-e68fa9016b55ff27cef322c488958876074000e1.tar.zst gsoc2013-evolution-e68fa9016b55ff27cef322c488958876074000e1.zip |
Bug 7000028 - Drag-n-drop export of a file produces 0 sized PDF file
em_utils_print_messages_to_file() was doing so asynchronously, but
unfortunately drag-n-drop is a synchronous protocol. So by the time
the asynchronous print operation completed, the URI list pointing to
the temporary PDF files had already been passed to the file manager.
The only reason the files were created at all was because we test the
generated file name with open(...O_CREAT...) before starting the print
operation, and I'm not convinced that test is even necessary.
(cherry picked from commit 72f465b17342831163422cad05eaa6e648fffa19)
Diffstat (limited to 'mail/em-utils.c')
-rw-r--r-- | mail/em-utils.c | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/mail/em-utils.c b/mail/em-utils.c index b920b387b4..18977c73aa 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -577,39 +577,17 @@ em_utils_write_messages_to_stream (CamelFolder *folder, return res; } -static void -do_print_msg_to_file (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - EMailParser *parser; - EMailPartList *parts_list; - gchar *filename = user_data; - EMailPrinter *printer; - - parser = E_MAIL_PARSER (source); - parts_list = e_mail_parser_parse_finish (parser, result, NULL); - - printer = e_mail_printer_new (parts_list); - e_mail_printer_set_export_filename (printer, filename); - - e_mail_printer_print ( - printer, GTK_PRINT_OPERATION_ACTION_EXPORT, - NULL, NULL, NULL, NULL); - - g_object_unref (printer); - g_object_unref (parser); -} - static gboolean em_utils_print_messages_to_file (CamelFolder *folder, const gchar *uid, const gchar *filename) { EMailParser *parser; + EMailPartList *parts_list; CamelMimeMessage *message; CamelStore *parent_store; CamelSession *session; + gboolean success = FALSE; message = camel_folder_get_message_sync (folder, uid, NULL, NULL); if (message == NULL) @@ -620,14 +598,43 @@ em_utils_print_messages_to_file (CamelFolder *folder, parser = e_mail_parser_new (session); - e_mail_parser_parse ( - parser, folder, uid, message, - (GAsyncReadyCallback) do_print_msg_to_file, - NULL, g_strdup (filename)); + /* XXX em_utils_selection_set_urilist() is synchronous, + * so this function has to be synchronous as well. + * That means potentially blocking for awhile. */ + parts_list = e_mail_parser_parse_sync ( + parser, folder, uid, message, NULL); + if (parts_list != NULL) { + EAsyncClosure *closure; + GAsyncResult *result; + EMailPrinter *printer; + GtkPrintOperationResult print_result; + printer = e_mail_printer_new (parts_list); + e_mail_printer_set_export_filename (printer, filename); + + closure = e_async_closure_new (); + + e_mail_printer_print ( + printer, GTK_PRINT_OPERATION_ACTION_EXPORT, + NULL, NULL, e_async_closure_callback, closure); + + result = e_async_closure_wait (closure); + + print_result = e_mail_printer_print_finish ( + printer, result, NULL); + + e_async_closure_free (closure); + + g_object_unref (printer); + g_object_unref (parts_list); + + success = (print_result != GTK_PRINT_OPERATION_RESULT_ERROR); + } + + g_object_unref (parser); g_object_unref (session); - return TRUE; + return success; } /* This kind of sucks, because for various reasons most callers need to run |