X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=libview%2Fev-jobs.c;h=a0866d508b0ec31d7ef8aed7312b3ae56677ad7f;hb=43f607bda8eef3648f018e433647172603ea1a7f;hp=102cd9083d83e982b8f8eab541d531e69b1941a3;hpb=68d0fc3c59185065d9694ba3f8cb2665b984eb9f;p=evince.git diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c index 102cd908..a0866d50 100644 --- a/libview/ev-jobs.c +++ b/libview/ev-jobs.c @@ -33,11 +33,14 @@ #include "ev-document-security.h" #include "ev-document-find.h" #include "ev-document-layers.h" +#include "ev-document-print.h" +#include "ev-document-annotations.h" +#include "ev-document-attachments.h" #include "ev-debug.h" #include #include -#include +#include #include static void ev_job_init (EvJob *job); @@ -60,6 +63,8 @@ static void ev_job_layers_init (EvJobLayers *job); static void ev_job_layers_class_init (EvJobLayersClass *class); static void ev_job_export_init (EvJobExport *job); static void ev_job_export_class_init (EvJobExportClass *class); +static void ev_job_print_init (EvJobPrint *job); +static void ev_job_print_class_init (EvJobPrintClass *class); enum { CANCELLED, @@ -98,6 +103,7 @@ G_DEFINE_TYPE (EvJobSave, ev_job_save, EV_TYPE_JOB) G_DEFINE_TYPE (EvJobFind, ev_job_find, EV_TYPE_JOB) G_DEFINE_TYPE (EvJobLayers, ev_job_layers, EV_TYPE_JOB) G_DEFINE_TYPE (EvJobExport, ev_job_export, EV_TYPE_JOB) +G_DEFINE_TYPE (EvJobPrint, ev_job_print, EV_TYPE_JOB) /* EvJob */ static void @@ -397,13 +403,14 @@ ev_job_attachments_run (EvJob *job) ev_debug_message (DEBUG_JOBS, NULL); ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job); - + ev_document_doc_mutex_lock (); - job_attachments->attachments = ev_document_get_attachments (job->document); + job_attachments->attachments = + ev_document_attachments_get_attachments (EV_DOCUMENT_ATTACHMENTS (job->document)); ev_document_doc_mutex_unlock (); - + ev_job_succeeded (job); - + return FALSE; } @@ -558,6 +565,10 @@ ev_job_render_run (EvJob *job) job_render->image_mapping = ev_document_images_get_image_mapping (EV_DOCUMENT_IMAGES (job->document), job_render->page); + if ((job_render->flags & EV_RENDER_INCLUDE_ANNOTS) && EV_IS_DOCUMENT_ANNOTATIONS (job->document)) + job_render->annots_mapping = + ev_document_annotations_get_annotations (EV_DOCUMENT_ANNOTATIONS (job->document), + job_render->ev_page); g_object_unref (rc); ev_document_doc_mutex_unlock (); @@ -925,31 +936,17 @@ ev_job_save_run (EvJob *job) { EvJobSave *job_save = EV_JOB_SAVE (job); gint fd; - gchar *filename; - gchar *tmp_filename; + gchar *tmp_filename = NULL; gchar *local_uri; GError *error = NULL; ev_debug_message (DEBUG_JOBS, "uri: %s, document_uri: %s", job_save->uri, job_save->document_uri); ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job); - - filename = ev_tmp_filename ("saveacopy"); - tmp_filename = g_strdup_printf ("%s.XXXXXX", filename); - g_free (filename); - - fd = g_mkstemp (tmp_filename); - if (fd == -1) { - gchar *display_name; - gint save_errno = errno; - display_name = g_filename_display_name (tmp_filename); - ev_job_failed (job, - G_FILE_ERROR, - g_file_error_from_errno (save_errno), - _("Failed to create file “%s”: %s"), - display_name, g_strerror (save_errno)); - g_free (display_name); - g_free (tmp_filename); + fd = ev_mkstemp ("saveacopy.XXXXXX", &tmp_filename, &error); + if (fd == -1) { + ev_job_failed_from_error (job, error); + g_error_free (error); return FALSE; } @@ -957,8 +954,11 @@ ev_job_save_run (EvJob *job) ev_document_doc_mutex_lock (); /* Save document to temp filename */ - local_uri = g_filename_to_uri (tmp_filename, NULL, NULL); - ev_document_save (job->document, local_uri, &error); + local_uri = g_filename_to_uri (tmp_filename, NULL, &error); + if (local_uri != NULL) { + ev_document_save (job->document, local_uri, &error); + } + close (fd); ev_document_doc_mutex_unlock (); @@ -989,7 +989,7 @@ ev_job_save_run (EvJob *job) uri_comp = ev_file_compress (local_uri, ctype, &error); g_free (local_uri); - ev_tmp_filename_unlink (tmp_filename); + g_unlink (tmp_filename); if (!uri_comp || error) { local_uri = NULL; @@ -999,7 +999,7 @@ ev_job_save_run (EvJob *job) } g_free (tmp_filename); - + if (error) { g_free (local_uri); ev_job_failed_from_error (job, error); @@ -1364,3 +1364,111 @@ ev_job_export_set_page (EvJobExport *job, { job->page = page; } + +/* EvJobPrint */ +static void +ev_job_print_init (EvJobPrint *job) +{ + EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD; + job->page = -1; +} + +static void +ev_job_print_dispose (GObject *object) +{ + EvJobPrint *job; + + ev_debug_message (DEBUG_JOBS, NULL); + + job = EV_JOB_PRINT (object); + + if (job->cr) { + cairo_destroy (job->cr); + job->cr = NULL; + } + + (* G_OBJECT_CLASS (ev_job_print_parent_class)->dispose) (object); +} + +static gboolean +ev_job_print_run (EvJob *job) +{ + EvJobPrint *job_print = EV_JOB_PRINT (job); + EvPage *ev_page; + cairo_status_t cr_status; + + g_assert (job_print->page != -1); + g_assert (job_print->cr != NULL); + + ev_debug_message (DEBUG_JOBS, NULL); + ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job); + + job->failed = FALSE; + job->finished = FALSE; + g_clear_error (&job->error); + + ev_document_doc_mutex_lock (); + + ev_page = ev_document_get_page (job->document, job_print->page); + ev_document_print_print_page (EV_DOCUMENT_PRINT (job->document), + ev_page, job_print->cr); + g_object_unref (ev_page); + + ev_document_doc_mutex_unlock (); + + cr_status = cairo_status (job_print->cr); + if (cr_status == CAIRO_STATUS_SUCCESS) { + ev_job_succeeded (job); + } else { + ev_job_failed (job, + GTK_PRINT_ERROR, + GTK_PRINT_ERROR_GENERAL, + _("Failed to print page %d: %s"), + job_print->page, + cairo_status_to_string (cr_status)); + } + + return FALSE; +} + +static void +ev_job_print_class_init (EvJobPrintClass *class) +{ + GObjectClass *oclass = G_OBJECT_CLASS (class); + EvJobClass *job_class = EV_JOB_CLASS (class); + + oclass->dispose = ev_job_print_dispose; + job_class->run = ev_job_print_run; +} + +EvJob * +ev_job_print_new (EvDocument *document) +{ + EvJob *job; + + ev_debug_message (DEBUG_JOBS, NULL); + + job = g_object_new (EV_TYPE_JOB_PRINT, NULL); + job->document = g_object_ref (document); + + return job; +} + +void +ev_job_print_set_page (EvJobPrint *job, + gint page) +{ + job->page = page; +} + +void +ev_job_print_set_cairo (EvJobPrint *job, + cairo_t *cr) +{ + if (job->cr == cr) + return; + + if (job->cr) + cairo_destroy (job->cr); + job->cr = cr ? cairo_reference (cr) : NULL; +}