2 #include "ev-job-queue.h"
3 #include "ev-document-thumbnails.h"
4 #include "ev-document-links.h"
5 #include "ev-document-fonts.h"
6 #include "ev-selection.h"
7 #include "ev-async-renderer.h"
9 static void ev_job_init (EvJob *job);
10 static void ev_job_class_init (EvJobClass *class);
11 static void ev_job_links_init (EvJobLinks *job);
12 static void ev_job_links_class_init (EvJobLinksClass *class);
13 static void ev_job_render_init (EvJobRender *job);
14 static void ev_job_render_class_init (EvJobRenderClass *class);
15 static void ev_job_thumbnail_init (EvJobThumbnail *job);
16 static void ev_job_thumbnail_class_init (EvJobThumbnailClass *class);
17 static void ev_job_load_init (EvJobLoad *job);
18 static void ev_job_load_class_init (EvJobLoadClass *class);
26 static guint job_signals[LAST_SIGNAL] = { 0 };
28 G_DEFINE_TYPE (EvJob, ev_job, G_TYPE_OBJECT)
29 G_DEFINE_TYPE (EvJobLinks, ev_job_links, EV_TYPE_JOB)
30 G_DEFINE_TYPE (EvJobRender, ev_job_render, EV_TYPE_JOB)
31 G_DEFINE_TYPE (EvJobThumbnail, ev_job_thumbnail, EV_TYPE_JOB)
32 G_DEFINE_TYPE (EvJobLoad, ev_job_load, EV_TYPE_JOB)
33 G_DEFINE_TYPE (EvJobFonts, ev_job_fonts, EV_TYPE_JOB)
35 static void ev_job_init (EvJob *job) { /* Do Nothing */ }
38 ev_job_dispose (GObject *object)
42 job = EV_JOB (object);
45 g_object_unref (job->document);
49 (* G_OBJECT_CLASS (ev_job_parent_class)->dispose) (object);
53 ev_job_class_init (EvJobClass *class)
57 oclass = G_OBJECT_CLASS (class);
59 oclass->dispose = ev_job_dispose;
61 job_signals [FINISHED] =
62 g_signal_new ("finished",
65 G_STRUCT_OFFSET (EvJobClass, finished),
67 g_cclosure_marshal_VOID__VOID,
72 static void ev_job_links_init (EvJobLinks *job) { /* Do Nothing */ }
75 ev_job_links_dispose (GObject *object)
79 job = EV_JOB_LINKS (object);
82 g_object_unref (job->model);
86 (* G_OBJECT_CLASS (ev_job_links_parent_class)->dispose) (object);
90 ev_job_links_class_init (EvJobLinksClass *class)
94 oclass = G_OBJECT_CLASS (class);
96 oclass->dispose = ev_job_links_dispose;
100 static void ev_job_render_init (EvJobRender *job) { /* Do Nothing */ }
103 ev_job_render_dispose (GObject *object)
107 job = EV_JOB_RENDER (object);
110 g_object_unref (job->pixbuf);
115 g_object_unref (job->rc);
119 if (job->selection) {
120 g_object_unref (job->selection);
121 job->selection = NULL;
124 if (job->selection_region) {
125 gdk_region_destroy (job->selection_region);
126 job->selection_region = NULL;
129 (* G_OBJECT_CLASS (ev_job_render_parent_class)->dispose) (object);
133 ev_job_render_class_init (EvJobRenderClass *class)
135 GObjectClass *oclass;
137 oclass = G_OBJECT_CLASS (class);
139 oclass->dispose = ev_job_render_dispose;
142 static void ev_job_thumbnail_init (EvJobThumbnail *job) { /* Do Nothing */ }
145 ev_job_thumbnail_dispose (GObject *object)
149 job = EV_JOB_THUMBNAIL (object);
151 if (job->thumbnail) {
152 g_object_unref (job->thumbnail);
153 job->thumbnail = NULL;
156 (* G_OBJECT_CLASS (ev_job_thumbnail_parent_class)->dispose) (object);
160 ev_job_thumbnail_class_init (EvJobThumbnailClass *class)
162 GObjectClass *oclass;
164 oclass = G_OBJECT_CLASS (class);
166 oclass->dispose = ev_job_thumbnail_dispose;
169 static void ev_job_load_init (EvJobLoad *job) { /* Do Nothing */ }
172 ev_job_load_dispose (GObject *object)
176 job = EV_JOB_LOAD (object);
184 g_error_free (job->error);
188 (* G_OBJECT_CLASS (ev_job_load_parent_class)->dispose) (object);
192 ev_job_load_class_init (EvJobLoadClass *class)
194 GObjectClass *oclass;
196 oclass = G_OBJECT_CLASS (class);
198 oclass->dispose = ev_job_load_dispose;
201 /* Public functions */
203 ev_job_finished (EvJob *job)
205 g_return_if_fail (EV_IS_JOB (job));
207 g_signal_emit (job, job_signals[FINISHED], 0);
211 ev_job_links_new (EvDocument *document)
215 job = g_object_new (EV_TYPE_JOB_LINKS, NULL);
216 job->document = g_object_ref (document);
222 ev_job_links_run (EvJobLinks *job)
224 g_return_if_fail (EV_IS_JOB_LINKS (job));
226 ev_document_doc_mutex_lock ();
227 job->model = ev_document_links_get_links_model (EV_DOCUMENT_LINKS (EV_JOB (job)->document));
228 EV_JOB (job)->finished = TRUE;
229 ev_document_doc_mutex_unlock ();
234 ev_job_render_new (EvDocument *document,
238 EvRectangle *selection_points,
241 gboolean include_links,
242 gboolean include_text,
243 gboolean include_selection)
247 g_return_val_if_fail (EV_IS_RENDER_CONTEXT (rc), NULL);
248 if (include_selection)
249 g_return_val_if_fail (selection_points != NULL, NULL);
251 job = g_object_new (EV_TYPE_JOB_RENDER, NULL);
253 EV_JOB (job)->document = g_object_ref (document);
254 job->rc = g_object_ref (rc);
255 job->target_width = width;
256 job->target_height = height;
259 job->include_links = include_links;
260 job->include_text = include_text;
261 job->include_selection = include_selection;
263 if (include_selection)
264 job->selection_points = *selection_points;
266 if (EV_IS_ASYNC_RENDERER (document)) {
267 EV_JOB (job)->async = TRUE;
274 render_finished_cb (EvDocument *document, GdkPixbuf *pixbuf, EvJobRender *job)
276 g_signal_handlers_disconnect_by_func (EV_JOB (job)->document,
277 render_finished_cb, job);
279 EV_JOB (job)->finished = TRUE;
280 job->pixbuf = g_object_ref (pixbuf);
281 ev_job_finished (EV_JOB (job));
285 ev_job_render_run (EvJobRender *job)
287 g_return_if_fail (EV_IS_JOB_RENDER (job));
289 ev_document_doc_mutex_lock ();
291 if (EV_JOB (job)->async) {
292 EvAsyncRenderer *renderer = EV_ASYNC_RENDERER (EV_JOB (job)->document);
293 ev_async_renderer_render_pixbuf (renderer, job->rc->page, job->rc->scale);
294 g_signal_connect (EV_JOB (job)->document, "render_finished",
295 G_CALLBACK (render_finished_cb), job);
297 job->pixbuf = ev_document_render_pixbuf (EV_JOB (job)->document, job->rc);
298 if (job->include_links)
299 job->link_mapping = ev_document_get_links (EV_JOB (job)->document, job->rc->page);
300 if (job->include_text && EV_IS_SELECTION (EV_JOB (job)->document))
301 job->text_mapping = ev_selection_get_selection_map (EV_SELECTION (EV_JOB (job)->document), job->rc);
302 if (job->include_selection && EV_IS_SELECTION (EV_JOB (job)->document)) {
303 ev_selection_render_selection (EV_SELECTION (EV_JOB (job)->document),
306 &(job->selection_points),
308 job->text, job->base);
309 job->selection_region =
310 ev_selection_get_selection_region (EV_SELECTION (EV_JOB (job)->document),
312 &(job->selection_points));
315 EV_JOB (job)->finished = TRUE;
318 ev_document_doc_mutex_unlock ();
322 ev_job_thumbnail_new (EvDocument *document,
325 gint requested_width)
329 job = g_object_new (EV_TYPE_JOB_THUMBNAIL, NULL);
331 EV_JOB (job)->document = g_object_ref (document);
333 job->rotation = rotation;
334 job->requested_width = requested_width;
340 ev_job_thumbnail_run (EvJobThumbnail *job)
342 g_return_if_fail (EV_IS_JOB_THUMBNAIL (job));
344 ev_document_doc_mutex_lock ();
347 ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (EV_JOB (job)->document),
350 job->requested_width,
352 EV_JOB (job)->finished = TRUE;
354 ev_document_doc_mutex_unlock ();
358 ev_job_load_new (EvDocument *document,
363 job = g_object_new (EV_TYPE_JOB_LOAD, NULL);
365 EV_JOB (job)->document = g_object_ref (document);
366 job->uri = g_strdup (uri);
372 ev_job_load_run (EvJobLoad *job)
374 g_return_if_fail (EV_IS_JOB_LOAD (job));
376 ev_document_doc_mutex_lock ();
379 g_error_free (job->error);
383 ev_document_load (EV_JOB(job)->document, job->uri, &job->error);
385 EV_JOB (job)->finished = TRUE;
387 ev_document_doc_mutex_unlock ();
390 static void ev_job_fonts_init (EvJobFonts *job) { /* Do Nothing */ }
392 static void ev_job_fonts_class_init (EvJobFontsClass *class) { /* Do Nothing */ }
395 ev_job_fonts_new (EvDocument *document)
399 job = g_object_new (EV_TYPE_JOB_FONTS, NULL);
401 EV_JOB (job)->document = g_object_ref (document);
407 ev_job_fonts_run (EvJobFonts *job)
409 EvDocumentFonts *fonts;
411 g_return_if_fail (EV_IS_JOB_FONTS (job));
413 ev_document_doc_mutex_lock ();
415 fonts = EV_DOCUMENT_FONTS (EV_JOB (job)->document);
416 job->scan_completed = !ev_document_fonts_scan (fonts, 20);
418 EV_JOB (job)->finished = TRUE;
420 ev_document_doc_mutex_unlock ();