diff --git a/print.c b/print.c index 3ac1fd8..95ef057 100644 --- a/print.c +++ b/print.c @@ -7,14 +7,19 @@ #include #include +#include static void cb_print_draw_page(GtkPrintOperation* print_operation, - GtkPrintContext* context, gint page_number, zathura_t* zathura); + GtkPrintContext* context, gint page_number, + zathura_t* zathura); static void cb_print_end(GtkPrintOperation* print_operation, GtkPrintContext* context, zathura_t* zathura); static void cb_print_request_page_setup(GtkPrintOperation* print_operation, - GtkPrintContext* context, gint page_number, GtkPageSetup* setup, zathura_t* - zathura); + GtkPrintContext* context, + gint page_number, GtkPageSetup* setup, + zathura_t* zathura); +static void cb_print_done(GtkPrintOperation* operation, + GtkPrintOperationResult result, zathura_t* zathura); void print(zathura_t* zathura) @@ -25,6 +30,12 @@ print(zathura_t* zathura) GtkPrintOperation* print_operation = gtk_print_operation_new(); /* print operation settings */ + gtk_print_operation_set_job_name(print_operation, zathura_document_get_path(zathura->document)); + gtk_print_operation_set_allow_async(print_operation, TRUE); + gtk_print_operation_set_n_pages(print_operation, zathura_document_get_number_of_pages(zathura->document)); + gtk_print_operation_set_current_page(print_operation, zathura_document_get_current_page_number(zathura->document)); + gtk_print_operation_set_use_full_page(print_operation, TRUE); + if (zathura->print.settings != NULL) { gtk_print_operation_set_print_settings(print_operation, zathura->print.settings); } @@ -32,35 +43,20 @@ print(zathura_t* zathura) if (zathura->print.page_setup != NULL) { gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup); } - - gtk_print_operation_set_allow_async(print_operation, TRUE); - gtk_print_operation_set_n_pages(print_operation, zathura_document_get_number_of_pages(zathura->document)); - gtk_print_operation_set_current_page(print_operation, zathura_document_get_current_page_number(zathura->document)); - gtk_print_operation_set_use_full_page(print_operation, TRUE); gtk_print_operation_set_embed_page_setup(print_operation, TRUE); /* print operation signals */ g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura); g_signal_connect(print_operation, "end-print", G_CALLBACK(cb_print_end), zathura); g_signal_connect(print_operation, "request-page-setup", G_CALLBACK(cb_print_request_page_setup), zathura); + g_signal_connect(print_operation, "done", G_CALLBACK(cb_print_done), zathura); /* print */ GtkPrintOperationResult result = gtk_print_operation_run(print_operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); - if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { - if (zathura->print.settings != NULL) { - g_object_unref(zathura->print.settings); - } - if (zathura->print.page_setup != NULL) { - g_object_unref(zathura->print.page_setup); - } - - /* save previous settings */ - zathura->print.settings = g_object_ref(gtk_print_operation_get_print_settings(print_operation)); - zathura->print.page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(print_operation)); - } else if (result == GTK_PRINT_OPERATION_RESULT_ERROR) { - girara_error("Error pccurred while printing progress"); + if (result == GTK_PRINT_OPERATION_RESULT_ERROR) { + girara_error("Error occurred while printing progress"); } g_object_unref(print_operation); @@ -185,3 +181,28 @@ cb_print_request_page_setup(GtkPrintOperation* UNUSED(print_operation), gtk_page_setup_set_orientation(setup, GTK_PAGE_ORIENTATION_PORTRAIT); } } + +static void +cb_print_done(GtkPrintOperation* operation, GtkPrintOperationResult result, + zathura_t* zathura) +{ + if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { + if (zathura->print.settings != NULL) { + g_object_unref(zathura->print.settings); + } + if (zathura->print.page_setup != NULL) { + g_object_unref(zathura->print.page_setup); + } + + /* save previous settings */ + zathura->print.settings = g_object_ref(gtk_print_operation_get_print_settings(operation)); + zathura->print.page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(operation)); + } else if (result == GTK_PRINT_OPERATION_RESULT_ERROR) { + GError* error = NULL; + gtk_print_operation_get_error(operation, &error); + girara_notify(zathura->ui.session, GIRARA_ERROR, "Printing failed: %s", + error->message); + g_error_free(error); + } +} +