aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-05-11 00:44:10 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-05-11 00:44:10 +0800
commit72f465b17342831163422cad05eaa6e648fffa19 (patch)
tree214273c6aa0e125762e0d94f080cf527b29a24e4
parent16a95bfa16b3864268e0ab0916bb6c02ec626fe0 (diff)
downloadgsoc2013-evolution-72f465b17342831163422cad05eaa6e648fffa19.tar
gsoc2013-evolution-72f465b17342831163422cad05eaa6e648fffa19.tar.gz
gsoc2013-evolution-72f465b17342831163422cad05eaa6e648fffa19.tar.bz2
gsoc2013-evolution-72f465b17342831163422cad05eaa6e648fffa19.tar.lz
gsoc2013-evolution-72f465b17342831163422cad05eaa6e648fffa19.tar.xz
gsoc2013-evolution-72f465b17342831163422cad05eaa6e648fffa19.tar.zst
gsoc2013-evolution-72f465b17342831163422cad05eaa6e648fffa19.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.
-rw-r--r--mail/em-utils.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/mail/em-utils.c b/mail/em-utils.c
index a293efabf8..011b49b883 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