+/* this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
+ * Copyright (C) 2005 Red Hat, Inc
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
#include <config.h>
+
#include "ev-jobs.h"
-#include "ev-job-queue.h"
#include "ev-document-thumbnails.h"
#include "ev-document-links.h"
#include "ev-document-images.h"
#include "ev-document-misc.h"
#include "ev-file-helpers.h"
#include "ev-document-fonts.h"
-#include "ev-async-renderer.h"
+#include "ev-document-security.h"
+#include "ev-document-find.h"
+#include "ev-document-layers.h"
+#include "ev-debug.h"
#include <errno.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <unistd.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-
-static void ev_job_init (EvJob *job);
-static void ev_job_class_init (EvJobClass *class);
-static void ev_job_links_init (EvJobLinks *job);
-static void ev_job_links_class_init (EvJobLinksClass *class);
-static void ev_job_render_init (EvJobRender *job);
-static void ev_job_render_class_init (EvJobRenderClass *class);
-static void ev_job_thumbnail_init (EvJobThumbnail *job);
-static void ev_job_thumbnail_class_init (EvJobThumbnailClass *class);
-static void ev_job_load_init (EvJobLoad *job);
-static void ev_job_load_class_init (EvJobLoadClass *class);
-static void ev_job_save_init (EvJobSave *job);
-static void ev_job_save_class_init (EvJobSaveClass *class);
-static void ev_job_print_init (EvJobPrint *job);
-static void ev_job_print_class_init (EvJobPrintClass *class);
+
+static void ev_job_init (EvJob *job);
+static void ev_job_class_init (EvJobClass *class);
+static void ev_job_links_init (EvJobLinks *job);
+static void ev_job_links_class_init (EvJobLinksClass *class);
+static void ev_job_attachments_init (EvJobAttachments *job);
+static void ev_job_attachments_class_init (EvJobAttachmentsClass *class);
+static void ev_job_render_init (EvJobRender *job);
+static void ev_job_render_class_init (EvJobRenderClass *class);
+static void ev_job_thumbnail_init (EvJobThumbnail *job);
+static void ev_job_thumbnail_class_init (EvJobThumbnailClass *class);
+static void ev_job_load_init (EvJobLoad *job);
+static void ev_job_load_class_init (EvJobLoadClass *class);
+static void ev_job_save_init (EvJobSave *job);
+static void ev_job_save_class_init (EvJobSaveClass *class);
+static void ev_job_find_init (EvJobFind *job);
+static void ev_job_find_class_init (EvJobFindClass *class);
+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);
enum {
+ CANCELLED,
FINISHED,
LAST_SIGNAL
};
RENDER_LAST_SIGNAL
};
+enum {
+ FONTS_UPDATED,
+ FONTS_LAST_SIGNAL
+};
+
+enum {
+ FIND_UPDATED,
+ FIND_LAST_SIGNAL
+};
+
static guint job_signals[LAST_SIGNAL] = { 0 };
static guint job_render_signals[RENDER_LAST_SIGNAL] = { 0 };
+static guint job_fonts_signals[FONTS_LAST_SIGNAL] = { 0 };
+static guint job_find_signals[FIND_LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (EvJob, ev_job, G_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE (EvJob, ev_job, G_TYPE_OBJECT)
G_DEFINE_TYPE (EvJobLinks, ev_job_links, EV_TYPE_JOB)
+G_DEFINE_TYPE (EvJobAttachments, ev_job_attachments, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobRender, ev_job_render, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobThumbnail, ev_job_thumbnail, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobFonts, ev_job_fonts, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobLoad, ev_job_load, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobSave, ev_job_save, EV_TYPE_JOB)
-G_DEFINE_TYPE (EvJobPrint, ev_job_print, 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)
-static void ev_job_init (EvJob *job) { /* Do Nothing */ }
+/* EvJob */
+static void
+ev_job_init (EvJob *job)
+{
+ job->cancellable = g_cancellable_new ();
+}
static void
ev_job_dispose (GObject *object)
job->document = NULL;
}
+ if (job->cancellable) {
+ g_object_unref (job->cancellable);
+ job->cancellable = NULL;
+ }
+
+ if (job->error) {
+ g_error_free (job->error);
+ job->error = NULL;
+ }
+
(* G_OBJECT_CLASS (ev_job_parent_class)->dispose) (object);
}
oclass->dispose = ev_job_dispose;
+ job_signals[CANCELLED] =
+ g_signal_new ("cancelled",
+ EV_TYPE_JOB,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EvJobClass, cancelled),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
job_signals [FINISHED] =
g_signal_new ("finished",
EV_TYPE_JOB,
- G_SIGNAL_RUN_LAST,
+ G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (EvJobClass, finished),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
-
-static void ev_job_links_init (EvJobLinks *job) { /* Do Nothing */ }
-
-static void
-ev_job_links_dispose (GObject *object)
+static gboolean
+emit_finished (EvJob *job)
{
- EvJobLinks *job;
+ ev_debug_message (DEBUG_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
- job = EV_JOB_LINKS (object);
-
- if (job->model) {
- g_object_unref (job->model);
- job->model = NULL;
+ job->idle_finished_id = 0;
+
+ if (job->cancelled) {
+ ev_debug_message (DEBUG_JOBS, "%s (%p) job was cancelled, do not emit finished", EV_GET_TYPE_NAME (job), job);
+ } else {
+ ev_profiler_stop (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
+ g_signal_emit (job, job_signals[FINISHED], 0);
}
-
- (* G_OBJECT_CLASS (ev_job_links_parent_class)->dispose) (object);
+
+ return FALSE;
}
static void
-ev_job_links_class_init (EvJobLinksClass *class)
+ev_job_emit_finished (EvJob *job)
{
- GObjectClass *oclass;
+ ev_debug_message (DEBUG_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
- oclass = G_OBJECT_CLASS (class);
+ if (g_cancellable_is_cancelled (job->cancellable)) {
+ ev_debug_message (DEBUG_JOBS, "%s (%p) job was cancelled, returning", EV_GET_TYPE_NAME (job), job);
+ return;
+ }
+
+ job->finished = TRUE;
+
+ if (job->run_mode == EV_JOB_RUN_THREAD) {
+ job->idle_finished_id =
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ (GSourceFunc)emit_finished,
+ g_object_ref (job),
+ (GDestroyNotify)g_object_unref);
+ } else {
+ ev_profiler_stop (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
+ g_signal_emit (job, job_signals[FINISHED], 0);
+ }
+}
- oclass->dispose = ev_job_links_dispose;
+gboolean
+ev_job_run (EvJob *job)
+{
+ EvJobClass *class = EV_JOB_GET_CLASS (job);
+
+ return class->run (job);
}
+void
+ev_job_cancel (EvJob *job)
+{
+ if (job->cancelled || (job->finished && job->idle_finished_id == 0))
+ return;
-static void ev_job_render_init (EvJobRender *job) { /* Do Nothing */ }
+ ev_debug_message (DEBUG_JOBS, "job %s (%p) cancelled", EV_GET_TYPE_NAME (job), job);
+ ev_profiler_stop (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
+
+ /* This should never be called from a thread */
+ job->cancelled = TRUE;
+ g_cancellable_cancel (job->cancellable);
+ g_signal_emit (job, job_signals[CANCELLED], 0);
+}
-static void
-ev_job_render_dispose (GObject *object)
+void
+ev_job_failed (EvJob *job,
+ GQuark domain,
+ gint code,
+ const gchar *format,
+ ...)
{
- EvJobRender *job;
+ va_list args;
+ gchar *message;
+
+ if (job->failed || job->finished)
+ return;
- job = EV_JOB_RENDER (object);
+ ev_debug_message (DEBUG_JOBS, "job %s (%p) failed", EV_GET_TYPE_NAME (job), job);
+
+ job->failed = TRUE;
+
+ va_start (args, format);
+ message = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ job->error = g_error_new_literal (domain, code, message);
+ g_free (message);
+
+ ev_job_emit_finished (job);
+}
- if (job->surface) {
- cairo_surface_destroy (job->surface);
- job->surface = NULL;
- }
+void
+ev_job_failed_from_error (EvJob *job,
+ GError *error)
+{
+ if (job->failed || job->finished)
+ return;
+
+ ev_debug_message (DEBUG_JOBS, "job %s (%p) failed", EV_GET_TYPE_NAME (job), job);
- if (job->rc) {
- g_object_unref (job->rc);
- job->rc = NULL;
- }
+ job->failed = TRUE;
+ job->error = g_error_copy (error);
- if (job->selection) {
- cairo_surface_destroy (job->selection);
- job->selection = NULL;
- }
+ ev_job_emit_finished (job);
+}
- if (job->selection_region) {
- gdk_region_destroy (job->selection_region);
- job->selection_region = NULL;
- }
+void
+ev_job_succeeded (EvJob *job)
+{
+ if (job->finished)
+ return;
- (* G_OBJECT_CLASS (ev_job_render_parent_class)->dispose) (object);
+ ev_debug_message (DEBUG_JOBS, "job %s (%p) succeeded", EV_GET_TYPE_NAME (job), job);
+
+ job->failed = FALSE;
+ ev_job_emit_finished (job);
}
-static void
-ev_job_render_class_init (EvJobRenderClass *class)
+gboolean
+ev_job_is_finished (EvJob *job)
{
- GObjectClass *oclass;
+ return job->finished;
+}
- oclass = G_OBJECT_CLASS (class);
+gboolean
+ev_job_is_failed (EvJob *job)
+{
+ return job->failed;
+}
- job_render_signals [PAGE_READY] =
- g_signal_new ("page-ready",
- EV_TYPE_JOB_RENDER,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EvJobRenderClass, page_ready),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+EvJobRunMode
+ev_job_get_run_mode (EvJob *job)
+{
+ return job->run_mode;
+}
- oclass->dispose = ev_job_render_dispose;
+void
+ev_job_set_run_mode (EvJob *job,
+ EvJobRunMode run_mode)
+{
+ job->run_mode = run_mode;
}
-static void ev_job_thumbnail_init (EvJobThumbnail *job) { /* Do Nothing */ }
+/* EvJobLinks */
+static void
+ev_job_links_init (EvJobLinks *job)
+{
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
+}
static void
-ev_job_thumbnail_dispose (GObject *object)
+ev_job_links_dispose (GObject *object)
{
- EvJobThumbnail *job;
+ EvJobLinks *job;
- job = EV_JOB_THUMBNAIL (object);
+ ev_debug_message (DEBUG_JOBS, NULL);
+
+ job = EV_JOB_LINKS (object);
- if (job->thumbnail) {
- g_object_unref (job->thumbnail);
- job->thumbnail = NULL;
+ if (job->model) {
+ g_object_unref (job->model);
+ job->model = NULL;
}
- if (job->rc) {
- g_object_unref (job->rc);
- job->rc = NULL;
- }
+ (* G_OBJECT_CLASS (ev_job_links_parent_class)->dispose) (object);
+}
- (* G_OBJECT_CLASS (ev_job_thumbnail_parent_class)->dispose) (object);
+static gboolean
+ev_job_links_run (EvJob *job)
+{
+ EvJobLinks *job_links = EV_JOB_LINKS (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_links->model = ev_document_links_get_links_model (EV_DOCUMENT_LINKS (job->document));
+ ev_document_doc_mutex_unlock ();
+
+ ev_job_succeeded (job);
+
+ return FALSE;
}
static void
-ev_job_thumbnail_class_init (EvJobThumbnailClass *class)
+ev_job_links_class_init (EvJobLinksClass *class)
{
- GObjectClass *oclass;
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
- oclass = G_OBJECT_CLASS (class);
-
- oclass->dispose = ev_job_thumbnail_dispose;
+ oclass->dispose = ev_job_links_dispose;
+ job_class->run = ev_job_links_run;
}
-static void ev_job_print_init (EvJobPrint *job) { /* Do Nothing */ }
+EvJob *
+ev_job_links_new (EvDocument *document)
+{
+ EvJob *job;
+
+ ev_debug_message (DEBUG_JOBS, NULL);
+
+ job = g_object_new (EV_TYPE_JOB_LINKS, NULL);
+ job->document = g_object_ref (document);
+
+ return job;
+}
+/* EvJobAttachments */
static void
-ev_job_print_dispose (GObject *object)
+ev_job_attachments_init (EvJobAttachments *job)
{
- EvJobPrint *job;
-
- job = EV_JOB_PRINT (object);
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
+}
- if (job->temp_file) {
- g_unlink (job->temp_file);
- g_free (job->temp_file);
- job->temp_file = NULL;
- }
+static void
+ev_job_attachments_dispose (GObject *object)
+{
+ EvJobAttachments *job;
- if (job->error) {
- g_error_free (job->error);
- job->error = NULL;
- }
+ ev_debug_message (DEBUG_JOBS, NULL);
+
+ job = EV_JOB_ATTACHMENTS (object);
- if (job->ranges) {
- g_free (job->ranges);
- job->ranges = NULL;
- job->n_ranges = 0;
+ if (job->attachments) {
+ g_list_foreach (job->attachments, (GFunc)g_object_unref, NULL);
+ g_list_free (job->attachments);
+ job->attachments = NULL;
}
- (* G_OBJECT_CLASS (ev_job_print_parent_class)->dispose) (object);
+ (* G_OBJECT_CLASS (ev_job_attachments_parent_class)->dispose) (object);
}
-static void
-ev_job_print_class_init (EvJobPrintClass *class)
+static gboolean
+ev_job_attachments_run (EvJob *job)
{
- GObjectClass *oclass;
+ EvJobAttachments *job_attachments = EV_JOB_ATTACHMENTS (job);
- oclass = G_OBJECT_CLASS (class);
-
- oclass->dispose = ev_job_print_dispose;
+ 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);
+ ev_document_doc_mutex_unlock ();
+
+ ev_job_succeeded (job);
+
+ return FALSE;
}
-/* Public functions */
-void
-ev_job_finished (EvJob *job)
+static void
+ev_job_attachments_class_init (EvJobAttachmentsClass *class)
{
- g_return_if_fail (EV_IS_JOB (job));
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
- g_signal_emit (job, job_signals[FINISHED], 0);
+ oclass->dispose = ev_job_attachments_dispose;
+ job_class->run = ev_job_attachments_run;
}
EvJob *
-ev_job_links_new (EvDocument *document)
+ev_job_attachments_new (EvDocument *document)
{
EvJob *job;
- job = g_object_new (EV_TYPE_JOB_LINKS, NULL);
- job->document = g_object_ref (document);
+ ev_debug_message (DEBUG_JOBS, NULL);
+ job = g_object_new (EV_TYPE_JOB_ATTACHMENTS, NULL);
+ job->document = g_object_ref (document);
+
return job;
}
-void
-ev_job_links_run (EvJobLinks *job)
+/* EvJobRender */
+static void
+ev_job_render_init (EvJobRender *job)
{
- g_return_if_fail (EV_IS_JOB_LINKS (job));
-
- ev_document_doc_mutex_lock ();
- job->model = ev_document_links_get_links_model (EV_DOCUMENT_LINKS (EV_JOB (job)->document));
- EV_JOB (job)->finished = TRUE;
- ev_document_doc_mutex_unlock ();
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
}
-
-EvJob *
-ev_job_render_new (EvDocument *document,
- EvRenderContext *rc,
- gint width,
- gint height,
- EvRectangle *selection_points,
- EvSelectionStyle selection_style,
- GdkColor *text,
- GdkColor *base,
- gboolean include_forms,
- gboolean include_links,
- gboolean include_images,
- gboolean include_text,
- gboolean include_selection)
+static void
+ev_job_render_dispose (GObject *object)
{
EvJobRender *job;
- g_return_val_if_fail (EV_IS_RENDER_CONTEXT (rc), NULL);
- if (include_selection)
- g_return_val_if_fail (selection_points != NULL, NULL);
-
- job = g_object_new (EV_TYPE_JOB_RENDER, NULL);
-
- EV_JOB (job)->document = g_object_ref (document);
- job->rc = g_object_ref (rc);
- job->target_width = width;
- job->target_height = height;
- job->selection_style = selection_style;
- job->text = *text;
- job->base = *base;
- job->include_forms = include_forms;
- job->include_links = include_links;
- job->include_images = include_images;
- job->include_text = include_text;
- job->include_selection = include_selection;
-
- if (include_selection)
- job->selection_points = *selection_points;
+ job = EV_JOB_RENDER (object);
- if (EV_IS_ASYNC_RENDERER (document)) {
- EV_JOB (job)->async = TRUE;
+ if (job->ev_page) {
+ ev_debug_message (DEBUG_JOBS, "page: %d (%p)", job->ev_page->index, job);
+ g_object_unref (job->ev_page);
+ job->ev_page = NULL;
+ }
+
+ if (job->surface) {
+ cairo_surface_destroy (job->surface);
+ job->surface = NULL;
}
- return EV_JOB (job);
-}
+ if (job->selection) {
+ cairo_surface_destroy (job->selection);
+ job->selection = NULL;
+ }
-static void
-render_finished_cb (EvDocument *document,
- GdkPixbuf *pixbuf,
- EvJobRender *job)
-{
- g_signal_handlers_disconnect_by_func (EV_JOB (job)->document,
- render_finished_cb, job);
+ if (job->selection_region) {
+ gdk_region_destroy (job->selection_region);
+ job->selection_region = NULL;
+ }
- /* FIXME: ps backend should be ported to cairo */
- job->surface = ev_document_misc_surface_from_pixbuf (pixbuf);
- job->page_ready = TRUE;
- g_signal_emit (job, job_render_signals[PAGE_READY], 0);
- EV_JOB (job)->finished = TRUE;
- ev_job_finished (EV_JOB (job));
+ (* G_OBJECT_CLASS (ev_job_render_parent_class)->dispose) (object);
}
static gboolean
notify_page_ready (EvJobRender *job)
{
- g_signal_emit (job, job_render_signals[PAGE_READY], 0);
+ ev_debug_message (DEBUG_JOBS, "%d (%p)", job->ev_page->index, job);
+ ev_profiler_stop (EV_PROFILE_JOBS, "Rendering page %d", job->ev_page->index);
+
+ if (EV_JOB (job)->cancelled) {
+ ev_debug_message (DEBUG_JOBS, "%s (%p) job was cancelled, do not emit page_ready", EV_GET_TYPE_NAME (job), job);
+ } else {
+ g_signal_emit (job, job_render_signals[PAGE_READY], 0);
+ }
return FALSE;
}
static void
ev_job_render_page_ready (EvJobRender *job)
{
+ ev_debug_message (DEBUG_JOBS, "%d (%p)", job->ev_page->index, job);
+
job->page_ready = TRUE;
g_idle_add_full (G_PRIORITY_HIGH_IDLE,
(GSourceFunc)notify_page_ready,
(GDestroyNotify)g_object_unref);
}
-void
-ev_job_render_run (EvJobRender *job)
+static gboolean
+ev_job_render_run (EvJob *job)
{
- g_return_if_fail (EV_IS_JOB_RENDER (job));
+ EvJobRender *job_render = EV_JOB_RENDER (job);
+ EvRenderContext *rc;
+ ev_debug_message (DEBUG_JOBS, "page: %d (%p)", job_render->page, job);
+ ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
+
ev_document_doc_mutex_lock ();
- if (EV_JOB (job)->async) {
- EvAsyncRenderer *renderer = EV_ASYNC_RENDERER (EV_JOB (job)->document);
- ev_async_renderer_render_pixbuf (renderer, job->rc->page, job->rc->scale,
- job->rc->rotation);
- g_signal_connect (EV_JOB (job)->document, "render_finished",
- G_CALLBACK (render_finished_cb), job);
- } else {
- ev_document_fc_mutex_lock ();
+ ev_profiler_start (EV_PROFILE_JOBS, "Rendering page %d", job_render->page);
- job->surface = ev_document_render (EV_JOB (job)->document, job->rc);
- if (job->include_selection && EV_IS_SELECTION (EV_JOB (job)->document)) {
- ev_selection_render_selection (EV_SELECTION (EV_JOB (job)->document),
- job->rc,
- &(job->selection),
- &(job->selection_points),
- NULL,
- job->selection_style,
- &(job->text), &(job->base));
- job->selection_region =
- ev_selection_get_selection_region (EV_SELECTION (EV_JOB (job)->document),
- job->rc,
- job->selection_style,
- &(job->selection_points));
- }
+ ev_document_fc_mutex_lock ();
- ev_job_render_page_ready (job);
+ job_render->ev_page = ev_document_get_page (job->document, job_render->page);
+ rc = ev_render_context_new (job_render->ev_page, job_render->rotation, job_render->scale);
+ job_render->surface = ev_document_render (job->document, rc);
+ /* If job was cancelled during the page rendering,
+ * we return now, so that the thread is finished ASAP
+ */
+ if (g_cancellable_is_cancelled (job->cancellable)) {
ev_document_fc_mutex_unlock ();
-
- if (job->include_text && EV_IS_SELECTION (EV_JOB (job)->document))
- job->text_mapping =
- ev_selection_get_selection_map (EV_SELECTION (EV_JOB (job)->document),
- job->rc);
- if (job->include_links && EV_IS_DOCUMENT_LINKS (EV_JOB (job)->document))
- job->link_mapping =
- ev_document_links_get_links (EV_DOCUMENT_LINKS (EV_JOB (job)->document),
- job->rc->page);
- if (job->include_forms && EV_IS_DOCUMENT_FORMS (EV_JOB (job)->document))
- job->form_field_mapping =
- ev_document_forms_get_form_fields (EV_DOCUMENT_FORMS (EV_JOB(job)->document),
- job->rc->page);
- if (job->include_images && EV_IS_DOCUMENT_IMAGES (EV_JOB (job)->document))
- job->image_mapping =
- ev_document_images_get_image_mapping (EV_DOCUMENT_IMAGES (EV_JOB (job)->document),
- job->rc->page);
- EV_JOB (job)->finished = TRUE;
+ ev_document_doc_mutex_unlock ();
+ g_object_unref (rc);
+
+ return FALSE;
+ }
+
+ if ((job_render->flags & EV_RENDER_INCLUDE_SELECTION) && EV_IS_SELECTION (job->document)) {
+ ev_selection_render_selection (EV_SELECTION (job->document),
+ rc,
+ &(job_render->selection),
+ &(job_render->selection_points),
+ NULL,
+ job_render->selection_style,
+ &(job_render->text), &(job_render->base));
+ job_render->selection_region =
+ ev_selection_get_selection_region (EV_SELECTION (job->document),
+ rc,
+ job_render->selection_style,
+ &(job_render->selection_points));
}
+ ev_job_render_page_ready (job_render);
+
+ ev_document_fc_mutex_unlock ();
+
+ if ((job_render->flags & EV_RENDER_INCLUDE_TEXT) && EV_IS_SELECTION (job->document))
+ job_render->text_mapping =
+ ev_selection_get_selection_map (EV_SELECTION (job->document), rc);
+ if ((job_render->flags & EV_RENDER_INCLUDE_LINKS) && EV_IS_DOCUMENT_LINKS (job->document))
+ job_render->link_mapping =
+ ev_document_links_get_links (EV_DOCUMENT_LINKS (job->document), job_render->page);
+ if ((job_render->flags & EV_RENDER_INCLUDE_FORMS) && EV_IS_DOCUMENT_FORMS (job->document))
+ job_render->form_field_mapping =
+ ev_document_forms_get_form_fields (EV_DOCUMENT_FORMS (job->document),
+ job_render->ev_page);
+ if ((job_render->flags & EV_RENDER_INCLUDE_IMAGES) && EV_IS_DOCUMENT_IMAGES (job->document))
+ job_render->image_mapping =
+ ev_document_images_get_image_mapping (EV_DOCUMENT_IMAGES (job->document),
+ job_render->page);
+ g_object_unref (rc);
ev_document_doc_mutex_unlock ();
+
+ ev_job_succeeded (job);
+
+ return FALSE;
+}
+
+static void
+ev_job_render_class_init (EvJobRenderClass *class)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
+
+ job_render_signals [PAGE_READY] =
+ g_signal_new ("page-ready",
+ EV_TYPE_JOB_RENDER,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EvJobRenderClass, page_ready),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ oclass->dispose = ev_job_render_dispose;
+ job_class->run = ev_job_render_run;
}
EvJob *
-ev_job_thumbnail_new (EvDocument *document,
- EvRenderContext *rc)
+ev_job_render_new (EvDocument *document,
+ gint page,
+ gint rotation,
+ gdouble scale,
+ gint width,
+ gint height,
+ EvRenderFlags flags)
{
- EvJobThumbnail *job;
+ EvJobRender *job;
- job = g_object_new (EV_TYPE_JOB_THUMBNAIL, NULL);
+ ev_debug_message (DEBUG_JOBS, "page: %d", page);
+
+ job = g_object_new (EV_TYPE_JOB_RENDER, NULL);
EV_JOB (job)->document = g_object_ref (document);
- job->rc = g_object_ref (rc);
+ job->page = page;
+ job->rotation = rotation;
+ job->scale = scale;
+ job->target_width = width;
+ job->target_height = height;
+ job->flags = flags;
return EV_JOB (job);
}
void
-ev_job_thumbnail_run (EvJobThumbnail *job)
+ev_job_render_set_selection_info (EvJobRender *job,
+ EvRectangle *selection_points,
+ EvSelectionStyle selection_style,
+ GdkColor *text,
+ GdkColor *base)
+{
+ job->flags |= EV_RENDER_INCLUDE_SELECTION;
+
+ job->selection_points = *selection_points;
+ job->selection_style = selection_style;
+ job->text = *text;
+ job->base = *base;
+}
+
+/* EvJobThumbnail */
+static void
+ev_job_thumbnail_init (EvJobThumbnail *job)
+{
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
+}
+
+static void
+ev_job_thumbnail_dispose (GObject *object)
+{
+ EvJobThumbnail *job;
+
+ job = EV_JOB_THUMBNAIL (object);
+
+ ev_debug_message (DEBUG_JOBS, "%d (%p)", job->page, job);
+
+ if (job->thumbnail) {
+ g_object_unref (job->thumbnail);
+ job->thumbnail = NULL;
+ }
+
+ (* G_OBJECT_CLASS (ev_job_thumbnail_parent_class)->dispose) (object);
+}
+
+static gboolean
+ev_job_thumbnail_run (EvJob *job)
{
- g_return_if_fail (EV_IS_JOB_THUMBNAIL (job));
+ EvJobThumbnail *job_thumb = EV_JOB_THUMBNAIL (job);
+ EvRenderContext *rc;
+ EvPage *page;
+ ev_debug_message (DEBUG_JOBS, "%d (%p)", job_thumb->page, job);
+ ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
+
ev_document_doc_mutex_lock ();
- job->thumbnail =
- ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (EV_JOB (job)->document),
- job->rc, TRUE);
- EV_JOB (job)->finished = TRUE;
+ page = ev_document_get_page (job->document, job_thumb->page);
+ rc = ev_render_context_new (page, job_thumb->rotation, job_thumb->scale);
+ g_object_unref (page);
+ job_thumb->thumbnail = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (job->document),
+ rc, TRUE);
+ g_object_unref (rc);
ev_document_doc_mutex_unlock ();
+
+ ev_job_succeeded (job);
+
+ return FALSE;
}
-static void ev_job_fonts_init (EvJobFonts *job) { /* Do Nothing */ }
+static void
+ev_job_thumbnail_class_init (EvJobThumbnailClass *class)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
-static void ev_job_fonts_class_init (EvJobFontsClass *class) { /* Do Nothing */ }
+ oclass->dispose = ev_job_thumbnail_dispose;
+ job_class->run = ev_job_thumbnail_run;
+}
EvJob *
-ev_job_fonts_new (EvDocument *document)
+ev_job_thumbnail_new (EvDocument *document,
+ gint page,
+ gint rotation,
+ gdouble scale)
{
- EvJobFonts *job;
+ EvJobThumbnail *job;
- job = g_object_new (EV_TYPE_JOB_FONTS, NULL);
+ ev_debug_message (DEBUG_JOBS, "%d", page);
+
+ job = g_object_new (EV_TYPE_JOB_THUMBNAIL, NULL);
EV_JOB (job)->document = g_object_ref (document);
+ job->page = page;
+ job->rotation = rotation;
+ job->scale = scale;
return EV_JOB (job);
}
-void
-ev_job_fonts_run (EvJobFonts *job)
+/* EvJobFonts */
+static void
+ev_job_fonts_init (EvJobFonts *job)
{
- EvDocumentFonts *fonts;
+ EV_JOB (job)->run_mode = EV_JOB_RUN_MAIN_LOOP;
+}
- g_return_if_fail (EV_IS_JOB_FONTS (job));
+static gboolean
+ev_job_fonts_run (EvJob *job)
+{
+ EvJobFonts *job_fonts = EV_JOB_FONTS (job);
+ EvDocumentFonts *fonts = EV_DOCUMENT_FONTS (job->document);
- ev_document_doc_mutex_lock ();
+ ev_debug_message (DEBUG_JOBS, NULL);
- fonts = EV_DOCUMENT_FONTS (EV_JOB (job)->document);
- ev_document_fc_mutex_lock ();
- job->scan_completed = !ev_document_fonts_scan (fonts, 20);
+ /* Do not block the main loop */
+ if (!ev_document_doc_mutex_trylock ())
+ return TRUE;
+
+ if (!ev_document_fc_mutex_trylock ())
+ return TRUE;
+
+#ifdef EV_ENABLE_DEBUG
+ /* We use the #ifdef in this case because of the if */
+ if (ev_document_fonts_get_progress (fonts) == 0)
+ ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
+#endif
+
+ job_fonts->scan_completed = !ev_document_fonts_scan (fonts, 20);
+ g_signal_emit (job_fonts, job_fonts_signals[FONTS_UPDATED], 0,
+ ev_document_fonts_get_progress (fonts));
+
ev_document_fc_mutex_unlock ();
+ ev_document_doc_mutex_unlock ();
+
+ if (job_fonts->scan_completed)
+ ev_job_succeeded (job);
+
+ return !job_fonts->scan_completed;
+}
+
+static void
+ev_job_fonts_class_init (EvJobFontsClass *class)
+{
+ EvJobClass *job_class = EV_JOB_CLASS (class);
+
+ job_class->run = ev_job_fonts_run;
+
+ job_fonts_signals[FONTS_UPDATED] =
+ g_signal_new ("updated",
+ EV_TYPE_JOB_FONTS,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EvJobFontsClass, updated),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__DOUBLE,
+ G_TYPE_NONE,
+ 1, G_TYPE_DOUBLE);
+}
+
+EvJob *
+ev_job_fonts_new (EvDocument *document)
+{
+ EvJobFonts *job;
+
+ ev_debug_message (DEBUG_JOBS, NULL);
- EV_JOB (job)->finished = TRUE;
+ job = g_object_new (EV_TYPE_JOB_FONTS, NULL);
+
+ EV_JOB (job)->document = g_object_ref (document);
- ev_document_doc_mutex_unlock ();
+ return EV_JOB (job);
}
-static void ev_job_load_init (EvJobLoad *job) { /* Do Nothing */ }
+/* EvJobLoad */
+static void
+ev_job_load_init (EvJobLoad *job)
+{
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
+}
static void
ev_job_load_dispose (GObject *object)
{
EvJobLoad *job = EV_JOB_LOAD (object);
+ ev_debug_message (DEBUG_JOBS, "%s", job->uri);
+
if (job->uri) {
g_free (job->uri);
job->uri = NULL;
}
- if (job->error) {
- g_error_free (job->error);
- job->error = NULL;
+ if (job->password) {
+ g_free (job->password);
+ job->password = NULL;
}
if (job->dest) {
(* G_OBJECT_CLASS (ev_job_load_parent_class)->dispose) (object);
}
+static gboolean
+ev_job_load_run (EvJob *job)
+{
+ EvJobLoad *job_load = EV_JOB_LOAD (job);
+ GError *error = NULL;
+
+ ev_debug_message (DEBUG_JOBS, "%s", job_load->uri);
+ ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
+
+ ev_document_fc_mutex_lock ();
+
+ /* This job may already have a document even if the job didn't complete
+ because, e.g., a password is required - if so, just reload rather than
+ creating a new instance */
+ if (job->document) {
+ if (job_load->password) {
+ ev_document_security_set_password (EV_DOCUMENT_SECURITY (job->document),
+ job_load->password);
+ }
+
+ job->failed = FALSE;
+ job->finished = FALSE;
+ g_clear_error (&job->error);
+
+ ev_document_load (job->document,
+ job_load->uri,
+ &error);
+ } else {
+ job->document = ev_document_factory_get_document (job_load->uri,
+ &error);
+ }
+
+ ev_document_fc_mutex_unlock ();
+
+ if (error) {
+ ev_job_failed_from_error (job, error);
+ g_error_free (error);
+ } else {
+ ev_job_succeeded (job);
+ }
+
+ return FALSE;
+}
+
static void
ev_job_load_class_init (EvJobLoadClass *class)
{
- GObjectClass *oclass;
-
- oclass = G_OBJECT_CLASS (class);
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
oclass->dispose = ev_job_load_dispose;
+ job_class->run = ev_job_load_run;
}
-
EvJob *
ev_job_load_new (const gchar *uri,
EvLinkDest *dest,
{
EvJobLoad *job;
+ ev_debug_message (DEBUG_JOBS, "%s", uri);
+
job = g_object_new (EV_TYPE_JOB_LOAD, NULL);
job->uri = g_strdup (uri);
- if (dest)
- job->dest = g_object_ref (dest);
-
+ job->dest = dest ? g_object_ref (dest) : NULL;
job->mode = mode;
- if (search_string)
- job->search_string = g_strdup (search_string);
+ job->search_string = search_string ? g_strdup (search_string) : NULL;
return EV_JOB (job);
}
void
ev_job_load_set_uri (EvJobLoad *job, const gchar *uri)
{
+ ev_debug_message (DEBUG_JOBS, "%s", uri);
+
if (job->uri)
g_free (job->uri);
job->uri = g_strdup (uri);
}
void
-ev_job_load_run (EvJobLoad *job)
+ev_job_load_set_password (EvJobLoad *job, const gchar *password)
{
- g_return_if_fail (EV_IS_JOB_LOAD (job));
-
- if (job->error) {
- g_error_free (job->error);
- job->error = NULL;
- }
-
- ev_document_fc_mutex_lock ();
-
- /* This job may already have a document even if the job didn't complete
- because, e.g., a password is required - if so, just reload rather than
- creating a new instance */
- if (EV_JOB (job)->document) {
- ev_document_load (EV_JOB (job)->document,
- job->uri,
- &job->error);
- } else {
- EV_JOB(job)->document =
- ev_document_factory_get_document (job->uri,
- &job->error);
- }
+ ev_debug_message (DEBUG_JOBS, NULL);
- ev_document_fc_mutex_unlock ();
- EV_JOB (job)->finished = TRUE;
+ if (job->password)
+ g_free (job->password);
+ job->password = password ? g_strdup (password) : NULL;
}
-static void ev_job_save_init (EvJobSave *job) { /* Do Nothing */ }
+/* EvJobSave */
+static void
+ev_job_save_init (EvJobSave *job)
+{
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
+}
static void
ev_job_save_dispose (GObject *object)
{
EvJobSave *job = EV_JOB_SAVE (object);
+ ev_debug_message (DEBUG_JOBS, "%s", job->uri);
+
if (job->uri) {
g_free (job->uri);
job->uri = NULL;
job->document_uri = NULL;
}
- if (job->error) {
- g_error_free (job->error);
- job->error = NULL;
- }
-
(* G_OBJECT_CLASS (ev_job_save_parent_class)->dispose) (object);
}
-static void
-ev_job_save_class_init (EvJobSaveClass *class)
-{
- GObjectClass *oclass;
-
- oclass = G_OBJECT_CLASS (class);
-
- oclass->dispose = ev_job_save_dispose;
-}
-
-EvJob *
-ev_job_save_new (EvDocument *document,
- const gchar *uri,
- const gchar *document_uri)
-{
- EvJobSave *job;
-
- job = g_object_new (EV_TYPE_JOB_SAVE, NULL);
-
- EV_JOB (job)->document = g_object_ref (document);
- job->uri = g_strdup (uri);
- job->document_uri = g_strdup (document_uri);
- job->error = NULL;
-
- return EV_JOB (job);
-}
-
-void
-ev_job_save_run (EvJobSave *job)
+static gboolean
+ev_job_save_run (EvJob *job)
{
- gint fd;
- gchar *filename;
- gchar *tmp_filename;
- gchar *local_uri;
+ EvJobSave *job_save = EV_JOB_SAVE (job);
+ gint fd;
+ gchar *filename;
+ gchar *tmp_filename;
+ 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);
gint save_errno = errno;
display_name = g_filename_display_name (tmp_filename);
- g_set_error (&(job->error),
- G_FILE_ERROR,
- g_file_error_from_errno (save_errno),
- _("Failed to create file “%s”: %s"),
- display_name, g_strerror (save_errno));
+ 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);
- return;
+ return FALSE;
}
ev_document_doc_mutex_lock ();
/* Save document to temp filename */
local_uri = g_filename_to_uri (tmp_filename, NULL, NULL);
- ev_document_save (EV_JOB (job)->document, local_uri, &(job->error));
+ ev_document_save (job->document, local_uri, &error);
close (fd);
ev_document_doc_mutex_unlock ();
- if (job->error) {
+ if (error) {
g_free (local_uri);
- return;
+ ev_job_failed_from_error (job, error);
+ g_error_free (error);
+
+ return FALSE;
}
/* If original document was compressed,
* compress it again before saving
*/
- if (g_object_get_data (G_OBJECT (EV_JOB (job)->document),
- "uri-uncompressed")) {
+ if (g_object_get_data (G_OBJECT (job->document), "uri-uncompressed")) {
EvCompressionType ctype = EV_COMPRESSION_NONE;
const gchar *ext;
gchar *uri_comp;
- ext = g_strrstr (job->document_uri, ".gz");
+ ext = g_strrstr (job_save->document_uri, ".gz");
if (ext && g_ascii_strcasecmp (ext, ".gz") == 0)
ctype = EV_COMPRESSION_GZIP;
- ext = g_strrstr (job->document_uri, ".bz2");
+ ext = g_strrstr (job_save->document_uri, ".bz2");
if (ext && g_ascii_strcasecmp (ext, ".bz2") == 0)
ctype = EV_COMPRESSION_BZIP2;
- uri_comp = ev_file_compress (local_uri, ctype, &(job->error));
+ uri_comp = ev_file_compress (local_uri, ctype, &error);
g_free (local_uri);
ev_tmp_filename_unlink (tmp_filename);
- if (!uri_comp || job->error) {
+ if (!uri_comp || error) {
local_uri = NULL;
} else {
local_uri = uri_comp;
g_free (tmp_filename);
- if (job->error) {
+ if (error) {
g_free (local_uri);
- return;
+ ev_job_failed_from_error (job, error);
+ g_error_free (error);
+
+ return FALSE;
}
if (!local_uri)
- return;
+ return FALSE;
- ev_xfer_uri_simple (local_uri, job->uri, &(job->error));
+ ev_xfer_uri_simple (local_uri, job_save->uri, &error);
ev_tmp_uri_unlink (local_uri);
+
+ if (error) {
+ ev_job_failed_from_error (job, error);
+ g_error_free (error);
+ } else {
+ ev_job_succeeded (job);
+ }
+
+ return FALSE;
+}
+
+static void
+ev_job_save_class_init (EvJobSaveClass *class)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
+
+ oclass->dispose = ev_job_save_dispose;
+ job_class->run = ev_job_save_run;
}
EvJob *
-ev_job_print_new (EvDocument *document,
- const gchar *format,
- gdouble width,
- gdouble height,
- EvPrintRange *ranges,
- gint n_ranges,
- EvPrintPageSet page_set,
- gint pages_per_sheet,
- gint copies,
- gdouble collate,
- gdouble reverse)
-{
- EvJobPrint *job;
-
- job = g_object_new (EV_TYPE_JOB_PRINT, NULL);
+ev_job_save_new (EvDocument *document,
+ const gchar *uri,
+ const gchar *document_uri)
+{
+ EvJobSave *job;
+
+ ev_debug_message (DEBUG_JOBS, "uri: %s, document_uri: %s", uri, document_uri);
+
+ job = g_object_new (EV_TYPE_JOB_SAVE, NULL);
EV_JOB (job)->document = g_object_ref (document);
+ job->uri = g_strdup (uri);
+ job->document_uri = g_strdup (document_uri);
- job->format = format;
-
- job->temp_file = NULL;
- job->error = NULL;
+ return EV_JOB (job);
+}
+
+/* EvJobFind */
+static void
+ev_job_find_init (EvJobFind *job)
+{
+ EV_JOB (job)->run_mode = EV_JOB_RUN_MAIN_LOOP;
+}
+
+static void
+ev_job_find_dispose (GObject *object)
+{
+ EvJobFind *job = EV_JOB_FIND (object);
- job->width = width;
- job->height = height;
+ ev_debug_message (DEBUG_JOBS, NULL);
- job->ranges = ranges;
- job->n_ranges = n_ranges;
+ if (job->text) {
+ g_free (job->text);
+ job->text = NULL;
+ }
- job->page_set = page_set;
+ if (job->pages) {
+ gint i;
- job->pages_per_sheet = CLAMP (pages_per_sheet, 1, 16);
-
- job->copies = copies;
- job->collate = collate;
- job->reverse = reverse;
+ for (i = 0; i < job->n_pages; i++) {
+ g_list_foreach (job->pages[i], (GFunc)g_free, NULL);
+ g_list_free (job->pages[i]);
+ }
+
+ g_free (job->pages);
+ job->pages = NULL;
+ }
- return EV_JOB (job);
+ (* G_OBJECT_CLASS (ev_job_find_parent_class)->dispose) (object);
}
-static gint
-ev_print_job_get_first_page (EvJobPrint *job)
+static gboolean
+ev_job_find_run (EvJob *job)
{
- gint i;
- gint first_page = G_MAXINT;
+ EvJobFind *job_find = EV_JOB_FIND (job);
+ EvDocumentFind *find = EV_DOCUMENT_FIND (job->document);
+ EvPage *ev_page;
+ GList *matches;
+
+ ev_debug_message (DEBUG_JOBS, NULL);
- if (job->n_ranges == 0)
- return 0;
+ /* Do not block the main loop */
+ if (!ev_document_doc_mutex_trylock ())
+ return TRUE;
+
+#ifdef EV_ENABLE_DEBUG
+ /* We use the #ifdef in this case because of the if */
+ if (job_find->current_page == job_find->start_page)
+ ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
+#endif
+
+ ev_page = ev_document_get_page (job->document, job_find->current_page);
+ matches = ev_document_find_find_text (find, ev_page, job_find->text,
+ job_find->case_sensitive);
+ g_object_unref (ev_page);
+
+ ev_document_doc_mutex_unlock ();
+
+ if (!job_find->has_results)
+ job_find->has_results = (matches != NULL);
- for (i = 0; i < job->n_ranges; i++) {
- if (job->ranges[i].start < first_page)
- first_page = job->ranges[i].start;
+ job_find->pages[job_find->current_page] = matches;
+ g_signal_emit (job_find, job_find_signals[FIND_UPDATED], 0, job_find->current_page);
+
+ job_find->current_page = (job_find->current_page + 1) % job_find->n_pages;
+ if (job_find->current_page == job_find->start_page) {
+ ev_job_succeeded (job);
+
+ return FALSE;
}
- return MAX (0, first_page);
+ return TRUE;
}
-static gint
-ev_print_job_get_last_page (EvJobPrint *job)
+static void
+ev_job_find_class_init (EvJobFindClass *class)
{
- gint i;
- gint last_page = G_MININT;
- gint max_page;
+ EvJobClass *job_class = EV_JOB_CLASS (class);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+
+ job_class->run = ev_job_find_run;
+ gobject_class->dispose = ev_job_find_dispose;
+
+ job_find_signals[FIND_UPDATED] =
+ g_signal_new ("updated",
+ EV_TYPE_JOB_FIND,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EvJobFindClass, updated),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__INT,
+ G_TYPE_NONE,
+ 1, G_TYPE_INT);
+}
- max_page = ev_document_get_n_pages (EV_JOB (job)->document) - 1;
+EvJob *
+ev_job_find_new (EvDocument *document,
+ gint start_page,
+ gint n_pages,
+ const gchar *text,
+ gboolean case_sensitive)
+{
+ EvJobFind *job;
+
+ ev_debug_message (DEBUG_JOBS, NULL);
+
+ job = g_object_new (EV_TYPE_JOB_FIND, NULL);
- if (job->n_ranges == 0)
- return max_page;
+ EV_JOB (job)->document = g_object_ref (document);
+ job->start_page = start_page;
+ job->current_page = start_page;
+ job->n_pages = n_pages;
+ job->pages = g_new0 (GList *, n_pages);
+ job->text = g_strdup (text);
+ job->case_sensitive = case_sensitive;
+ job->has_results = FALSE;
- for (i = 0; i < job->n_ranges; i++) {
- if (job->ranges[i].end > last_page)
- last_page = job->ranges[i].end;
- }
+ return EV_JOB (job);
+}
- return MIN (max_page, last_page);
+gint
+ev_job_find_get_n_results (EvJobFind *job,
+ gint page)
+{
+ return g_list_length (job->pages[page]);
}
-static gboolean
-ev_print_job_print_page_in_set (EvJobPrint *job,
- gint page)
+gdouble
+ev_job_find_get_progress (EvJobFind *job)
{
- switch (job->page_set) {
- case EV_PRINT_PAGE_SET_EVEN:
- return page % 2 == 0;
- case EV_PRINT_PAGE_SET_ODD:
- return page % 2 != 0;
- case EV_PRINT_PAGE_SET_ALL:
- return TRUE;
+ gint pages_done;
+
+ if (ev_job_is_finished (EV_JOB (job)))
+ return 1.0;
+
+ if (job->current_page > job->start_page) {
+ pages_done = job->current_page - job->start_page + 1;
+ } else if (job->current_page == job->start_page) {
+ pages_done = job->n_pages;
+ } else {
+ pages_done = job->n_pages - job->start_page + job->current_page;
}
- return FALSE;
+ return pages_done / (gdouble) job->n_pages;
}
-static gint *
-ev_job_print_get_page_list (EvJobPrint *job,
- gint *n_pages)
+gboolean
+ev_job_find_has_results (EvJobFind *job)
{
- gint i, j, page, max_page;
- gint pages = 0;
- gint *page_list;
-
- max_page = ev_document_get_n_pages (EV_JOB (job)->document) - 1;
-
- for (i = 0; i < job->n_ranges; i++) {
- gint rsize;
- gint start, end;
+ return job->has_results;
+}
- if (job->ranges[i].start > max_page)
- continue;
-
- start = job->ranges[i].start + 1;
- end = job->ranges[i].end <= max_page ? job->ranges[i].end + 1 : max_page + 1;
- rsize = end - start + 1;
-
- switch (job->page_set) {
- case EV_PRINT_PAGE_SET_EVEN:
- pages += start % 2 == 0 ? (rsize / 2) + (rsize % 2) : (rsize / 2);
- break;
- case EV_PRINT_PAGE_SET_ODD:
- pages += start % 2 != 0 ? (rsize / 2) + (rsize % 2) : (rsize / 2);
- break;
- default:
- pages += rsize;
- break;
- }
- }
+GList **
+ev_job_find_get_results (EvJobFind *job)
+{
+ return job->pages;
+}
- *n_pages = pages;
+/* EvJobLayers */
+static void
+ev_job_layers_init (EvJobLayers *job)
+{
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
+}
- if (pages == 0)
- return NULL;
+static void
+ev_job_layers_dispose (GObject *object)
+{
+ EvJobLayers *job;
- page_list = g_new (gint, pages);
+ ev_debug_message (DEBUG_JOBS, NULL);
+
+ job = EV_JOB_LAYERS (object);
- page = 0;
- for (i = 0; i < job->n_ranges; i++) {
- for (j = job->ranges[i].start; j <= job->ranges[i].end; j++) {
- if (j > max_page)
- break;
-
- if (ev_print_job_print_page_in_set (job, j + 1))
- page_list[page++] = j;
- }
+ if (job->model) {
+ g_object_unref (job->model);
+ job->model = NULL;
}
- return page_list;
+ (* G_OBJECT_CLASS (ev_job_layers_parent_class)->dispose) (object);
}
-void
-ev_job_print_run (EvJobPrint *job)
-{
- EvDocument *document = EV_JOB (job)->document;
- EvFileExporterContext fc;
- EvRenderContext *rc;
- gint fd;
- gint *page_list;
- gint n_pages;
- gint last_page;
- gint first_page;
- gint i, j;
- gchar *filename;
-
- g_return_if_fail (EV_IS_JOB_PRINT (job));
-
- if (job->temp_file)
- g_free (job->temp_file);
- job->temp_file = NULL;
-
- if (job->error)
- g_error_free (job->error);
- job->error = NULL;
+static gboolean
+ev_job_layers_run (EvJob *job)
+{
+ EvJobLayers *job_layers = EV_JOB_LAYERS (job);
- filename = g_strdup_printf ("evince_print.%s.XXXXXX", job->format);
- fd = g_file_open_tmp (filename, &job->temp_file, &job->error);
- g_free (filename);
- if (fd <= -1) {
- EV_JOB (job)->finished = TRUE;
- return;
- }
+ 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_layers->model = ev_document_layers_get_layers (EV_DOCUMENT_LAYERS (job->document));
+ ev_document_doc_mutex_unlock ();
+
+ ev_job_succeeded (job);
+
+ return FALSE;
+}
- page_list = ev_job_print_get_page_list (job, &n_pages);
- if (n_pages == 0) {
- close (fd);
- EV_JOB (job)->finished = TRUE;
- return;
- }
+static void
+ev_job_layers_class_init (EvJobLayersClass *class)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
- first_page = ev_print_job_get_first_page (job);
- last_page = ev_print_job_get_last_page (job);
+ oclass->dispose = ev_job_layers_dispose;
+ job_class->run = ev_job_layers_run;
+}
- fc.format = g_ascii_strcasecmp (job->format, "pdf") == 0 ?
- EV_FILE_FORMAT_PDF : EV_FILE_FORMAT_PS;
- fc.filename = job->temp_file;
- fc.first_page = MIN (first_page, last_page);
- fc.last_page = MAX (first_page, last_page);
- fc.paper_width = job->width;
- fc.paper_height = job->height;
- fc.duplex = FALSE;
- fc.pages_per_sheet = MAX (1, job->pages_per_sheet);
+EvJob *
+ev_job_layers_new (EvDocument *document)
+{
+ EvJob *job;
- rc = ev_render_context_new (0, 0, 1.0);
+ ev_debug_message (DEBUG_JOBS, NULL);
- ev_document_doc_mutex_lock ();
- ev_file_exporter_begin (EV_FILE_EXPORTER (document), &fc);
+ job = g_object_new (EV_TYPE_JOB_LAYERS, NULL);
+ job->document = g_object_ref (document);
+
+ return job;
+}
- for (i = 0; i < job->copies; i++) {
- gint page, step;
- gint n_copies;
-
- step = job->reverse ? -1 * job->pages_per_sheet : job->pages_per_sheet;
- page = job->reverse ? (n_pages / job->pages_per_sheet) * job->pages_per_sheet : 0;
- n_copies = job->collate ? job->copies : 1;
+/* EvJobExport */
+static void
+ev_job_export_init (EvJobExport *job)
+{
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
+ job->page = -1;
+}
- while ((job->reverse && (page >= 0)) || (!job->reverse && (page < n_pages))) {
- gint k;
+static void
+ev_job_export_dispose (GObject *object)
+{
+ EvJobExport *job;
- ev_file_exporter_begin_page (EV_FILE_EXPORTER (document));
-
- for (j = 0; j < job->pages_per_sheet; j++) {
- gint p = page + j;
-
- if (p < 0 || p >= n_pages)
- break;
+ ev_debug_message (DEBUG_JOBS, NULL);
+
+ job = EV_JOB_EXPORT (object);
- ev_render_context_set_page (rc, page_list[p]);
+ if (job->rc) {
+ g_object_unref (job->rc);
+ job->rc = NULL;
+ }
- for (k = 0; k < n_copies; k++) {
- ev_file_exporter_do_page (EV_FILE_EXPORTER (document), rc);
- }
- }
+ (* G_OBJECT_CLASS (ev_job_export_parent_class)->dispose) (object);
+}
- ev_file_exporter_end_page (EV_FILE_EXPORTER (document));
+static gboolean
+ev_job_export_run (EvJob *job)
+{
+ EvJobExport *job_export = EV_JOB_EXPORT (job);
+ EvPage *ev_page;
- page += step;
- }
+ g_assert (job_export->page != -1);
- if (job->collate)
- break;
+ 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 ();
+
+ ev_page = ev_document_get_page (job->document, job_export->page);
+ if (job_export->rc) {
+ job->failed = FALSE;
+ job->finished = FALSE;
+ g_clear_error (&job->error);
+
+ ev_render_context_set_page (job_export->rc, ev_page);
+ } else {
+ job_export->rc = ev_render_context_new (ev_page, 0, 1.0);
}
-
- ev_file_exporter_end (EV_FILE_EXPORTER (document));
+ g_object_unref (ev_page);
+
+ ev_file_exporter_do_page (EV_FILE_EXPORTER (job->document), job_export->rc);
+
ev_document_doc_mutex_unlock ();
- g_free (page_list);
- close (fd);
- g_object_unref (rc);
+ ev_job_succeeded (job);
+
+ return FALSE;
+}
+
+static void
+ev_job_export_class_init (EvJobExportClass *class)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
+
+ oclass->dispose = ev_job_export_dispose;
+ job_class->run = ev_job_export_run;
+}
+
+EvJob *
+ev_job_export_new (EvDocument *document)
+{
+ EvJob *job;
+
+ ev_debug_message (DEBUG_JOBS, NULL);
+
+ job = g_object_new (EV_TYPE_JOB_EXPORT, NULL);
+ job->document = g_object_ref (document);
- EV_JOB (job)->finished = TRUE;
+ return job;
+}
+
+void
+ev_job_export_set_page (EvJobExport *job,
+ gint page)
+{
+ job->page = page;
}