mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 19:56:01 +01:00
Correctly safe print setting state
Since we are running the operation asynchronsly, we need to store the print settings in a callback for the done signal. Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
parent
ace31581b4
commit
eea53de243
1 changed files with 42 additions and 21 deletions
63
print.c
63
print.c
|
@ -7,14 +7,19 @@
|
||||||
|
|
||||||
#include <girara/utils.h>
|
#include <girara/utils.h>
|
||||||
#include <girara/statusbar.h>
|
#include <girara/statusbar.h>
|
||||||
|
#include <girara/session.h>
|
||||||
|
|
||||||
static void cb_print_draw_page(GtkPrintOperation* print_operation,
|
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*
|
static void cb_print_end(GtkPrintOperation* print_operation, GtkPrintContext*
|
||||||
context, zathura_t* zathura);
|
context, zathura_t* zathura);
|
||||||
static void cb_print_request_page_setup(GtkPrintOperation* print_operation,
|
static void cb_print_request_page_setup(GtkPrintOperation* print_operation,
|
||||||
GtkPrintContext* context, gint page_number, GtkPageSetup* setup, zathura_t*
|
GtkPrintContext* context,
|
||||||
zathura);
|
gint page_number, GtkPageSetup* setup,
|
||||||
|
zathura_t* zathura);
|
||||||
|
static void cb_print_done(GtkPrintOperation* operation,
|
||||||
|
GtkPrintOperationResult result, zathura_t* zathura);
|
||||||
|
|
||||||
void
|
void
|
||||||
print(zathura_t* zathura)
|
print(zathura_t* zathura)
|
||||||
|
@ -25,6 +30,12 @@ print(zathura_t* zathura)
|
||||||
GtkPrintOperation* print_operation = gtk_print_operation_new();
|
GtkPrintOperation* print_operation = gtk_print_operation_new();
|
||||||
|
|
||||||
/* print operation settings */
|
/* 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) {
|
if (zathura->print.settings != NULL) {
|
||||||
gtk_print_operation_set_print_settings(print_operation, zathura->print.settings);
|
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) {
|
if (zathura->print.page_setup != NULL) {
|
||||||
gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup);
|
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);
|
gtk_print_operation_set_embed_page_setup(print_operation, TRUE);
|
||||||
|
|
||||||
/* print operation signals */
|
/* print operation signals */
|
||||||
g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura);
|
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, "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, "request-page-setup", G_CALLBACK(cb_print_request_page_setup), zathura);
|
||||||
|
g_signal_connect(print_operation, "done", G_CALLBACK(cb_print_done), zathura);
|
||||||
|
|
||||||
/* print */
|
/* print */
|
||||||
GtkPrintOperationResult result = gtk_print_operation_run(print_operation,
|
GtkPrintOperationResult result = gtk_print_operation_run(print_operation,
|
||||||
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
|
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
|
||||||
|
|
||||||
if (result == GTK_PRINT_OPERATION_RESULT_APPLY) {
|
if (result == GTK_PRINT_OPERATION_RESULT_ERROR) {
|
||||||
if (zathura->print.settings != NULL) {
|
girara_error("Error occurred while printing progress");
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref(print_operation);
|
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue