void e_contact_print (EBookClient *book_client, EBookQuery *query, const GSList *contact_list, GtkPrintOperationAction action) { GtkPrintOperation *operation; EContactPrintContext *ctxt; ctxt = g_new0 (EContactPrintContext, 1); ctxt->action = action; ctxt->contact_list = e_client_util_copy_object_slist (NULL, contact_list); ctxt->style = g_new0 (EContactPrintStyle, 1); ctxt->page_nr = 0; ctxt->pages = 0; operation = e_print_operation_new (); gtk_print_operation_set_n_pages (operation, 1); g_object_set_data_full ( G_OBJECT (operation), "contact-print-ctx", ctxt, g_free); g_signal_connect ( operation, "begin-print", G_CALLBACK (contact_begin_print), ctxt); g_signal_connect ( operation, "draw_page", G_CALLBACK (contact_draw_page), ctxt); g_signal_connect ( operation, "end-print", G_CALLBACK (contact_end_print), ctxt); if (book_client) { gchar *query_str = e_book_query_to_string (query); e_book_client_get_view ( book_client, query_str, NULL, get_view_ready_cb, operation); g_free (query_str); } else { gtk_print_operation_run (operation, action, NULL, NULL); g_object_unref (operation); } }
static gboolean mail_printer_print_timeout_cb (gpointer user_data) { GSimpleAsyncResult *simple; AsyncContext *async_context; GCancellable *cancellable; GtkPrintOperation *print_operation; GtkPrintOperationAction print_action; EMailPrinter *printer; WebKitWebFrame *web_frame; gulong create_custom_widget_handler_id; gulong custom_widget_apply_handler_id; gulong draw_page_handler_id; GError *error = NULL; simple = G_SIMPLE_ASYNC_RESULT (user_data); async_context = g_simple_async_result_get_op_res_gpointer (simple); cancellable = async_context->cancellable; print_action = async_context->print_action; /* Check for cancellation one last time before printing. */ if (g_cancellable_set_error_if_cancelled (cancellable, &error)) goto exit; /* This returns a new reference. */ printer = (EMailPrinter *) g_async_result_get_source_object ( G_ASYNC_RESULT (simple)); print_operation = e_print_operation_new (); gtk_print_operation_set_show_progress (print_operation, TRUE); gtk_print_operation_set_unit (print_operation, GTK_UNIT_PIXEL); if (async_context->print_action == GTK_PRINT_OPERATION_ACTION_EXPORT) { const gchar *export_filename; export_filename = e_mail_printer_get_export_filename (printer); gtk_print_operation_set_export_filename ( print_operation, export_filename); } create_custom_widget_handler_id = g_signal_connect ( print_operation, "create-custom-widget", G_CALLBACK (mail_printer_create_custom_widget_cb), async_context); custom_widget_apply_handler_id = g_signal_connect ( print_operation, "custom-widget-apply", G_CALLBACK (mail_printer_custom_widget_apply_cb), async_context); draw_page_handler_id = g_signal_connect ( print_operation, "draw-page", G_CALLBACK (mail_printer_draw_footer_cb), async_context->cancellable); web_frame = webkit_web_view_get_main_frame (async_context->web_view); async_context->print_result = webkit_web_frame_print_full ( web_frame, print_operation, print_action, &error); /* Sanity check. */ switch (async_context->print_result) { case GTK_PRINT_OPERATION_RESULT_ERROR: if (error == NULL) g_warning ( "WebKit print operation returned " "ERROR result without setting a " "GError"); break; case GTK_PRINT_OPERATION_RESULT_APPLY: if (error != NULL) g_warning ( "WebKit print operation returned " "APPLY result but also set a GError"); break; case GTK_PRINT_OPERATION_RESULT_CANCEL: if (error != NULL) g_warning ( "WebKit print operation returned " "CANCEL result but also set a GError"); break; default: g_warn_if_reached (); } g_signal_handler_disconnect ( print_operation, create_custom_widget_handler_id); g_signal_handler_disconnect ( print_operation, custom_widget_apply_handler_id); g_signal_handler_disconnect ( print_operation, draw_page_handler_id); g_object_unref (print_operation); g_object_unref (printer); exit: if (error != NULL) g_simple_async_result_take_error (simple, error); g_simple_async_result_complete_in_idle (simple); return FALSE; }