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 (* G_OBJECT_CLASS (ev_job_render_parent_class)->dispose) (object);
123 ev_job_render_class_init (EvJobRenderClass *class)
125 GObjectClass *oclass;
127 oclass = G_OBJECT_CLASS (class);
129 oclass->dispose = ev_job_render_dispose;
132 static void ev_job_thumbnail_init (EvJobThumbnail *job) { /* Do Nothing */ }
135 ev_job_thumbnail_dispose (GObject *object)
139 job = EV_JOB_THUMBNAIL (object);
141 if (job->thumbnail) {
142 g_object_unref (job->thumbnail);
143 job->thumbnail = NULL;
146 (* G_OBJECT_CLASS (ev_job_thumbnail_parent_class)->dispose) (object);
150 ev_job_thumbnail_class_init (EvJobThumbnailClass *class)
152 GObjectClass *oclass;
154 oclass = G_OBJECT_CLASS (class);
156 oclass->dispose = ev_job_thumbnail_dispose;
159 static void ev_job_load_init (EvJobLoad *job) { /* Do Nothing */ }
162 ev_job_load_dispose (GObject *object)
166 job = EV_JOB_LOAD (object);
174 g_error_free (job->error);
178 (* G_OBJECT_CLASS (ev_job_load_parent_class)->dispose) (object);
182 ev_job_load_class_init (EvJobLoadClass *class)
184 GObjectClass *oclass;
186 oclass = G_OBJECT_CLASS (class);
188 oclass->dispose = ev_job_load_dispose;
191 /* Public functions */
193 ev_job_finished (EvJob *job)
195 g_return_if_fail (EV_IS_JOB (job));
197 g_signal_emit (job, job_signals[FINISHED], 0);
201 ev_job_links_new (EvDocument *document)
205 job = g_object_new (EV_TYPE_JOB_LINKS, NULL);
206 job->document = g_object_ref (document);
212 ev_job_links_run (EvJobLinks *job)
214 g_return_if_fail (EV_IS_JOB_LINKS (job));
216 ev_document_doc_mutex_lock ();
217 job->model = ev_document_links_get_links_model (EV_DOCUMENT_LINKS (EV_JOB (job)->document));
218 EV_JOB (job)->finished = TRUE;
219 ev_document_doc_mutex_unlock ();
224 ev_job_render_new (EvDocument *document,
228 EvRectangle *selection_points,
229 gboolean include_links,
230 gboolean include_selection)
234 g_return_val_if_fail (EV_IS_RENDER_CONTEXT (rc), NULL);
235 if (include_selection)
236 g_return_val_if_fail (selection_points != NULL, NULL);
238 job = g_object_new (EV_TYPE_JOB_RENDER, NULL);
240 EV_JOB (job)->document = g_object_ref (document);
241 job->rc = g_object_ref (rc);
242 job->target_width = width;
243 job->target_height = height;
244 job->include_links = include_links;
245 job->include_selection = include_selection;
247 if (include_selection)
248 job->selection_points = *selection_points;
250 if (EV_IS_ASYNC_RENDERER (document)) {
251 EV_JOB (job)->async = TRUE;
258 render_finished_cb (EvDocument *document, GdkPixbuf *pixbuf, EvJobRender *job)
260 g_signal_handlers_disconnect_by_func (EV_JOB (job)->document,
261 render_finished_cb, job);
263 EV_JOB (job)->finished = TRUE;
264 job->pixbuf = g_object_ref (pixbuf);
265 ev_job_finished (EV_JOB (job));
269 ev_job_render_run (EvJobRender *job)
271 g_return_if_fail (EV_IS_JOB_RENDER (job));
273 ev_document_doc_mutex_lock ();
275 if (EV_JOB (job)->async) {
276 EvAsyncRenderer *renderer = EV_ASYNC_RENDERER (EV_JOB (job)->document);
277 ev_async_renderer_render_pixbuf (renderer, job->rc->page, job->rc->scale);
278 g_signal_connect (EV_JOB (job)->document, "render_finished",
279 G_CALLBACK (render_finished_cb), job);
281 job->pixbuf = ev_document_render_pixbuf (EV_JOB (job)->document, job->rc);
282 if (job->include_links)
283 job->link_mapping = ev_document_get_links (EV_JOB (job)->document, job->rc->page);
284 if (job->include_selection && EV_IS_SELECTION (EV_JOB (job)->document))
285 ev_selection_render_selection (EV_SELECTION (EV_JOB (job)->document),
288 &(job->selection_points),
291 EV_JOB (job)->finished = TRUE;
294 ev_document_doc_mutex_unlock ();
298 ev_job_thumbnail_new (EvDocument *document,
300 gint requested_width)
304 job = g_object_new (EV_TYPE_JOB_THUMBNAIL, NULL);
306 EV_JOB (job)->document = g_object_ref (document);
308 job->requested_width = requested_width;
314 ev_job_thumbnail_run (EvJobThumbnail *job)
316 g_return_if_fail (EV_IS_JOB_THUMBNAIL (job));
318 ev_document_doc_mutex_lock ();
321 ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (EV_JOB (job)->document),
323 job->requested_width,
325 EV_JOB (job)->finished = TRUE;
327 ev_document_doc_mutex_unlock ();
331 ev_job_load_new (EvDocument *document,
336 job = g_object_new (EV_TYPE_JOB_LOAD, NULL);
338 EV_JOB (job)->document = g_object_ref (document);
339 job->uri = g_strdup (uri);
345 ev_job_load_run (EvJobLoad *job)
347 g_return_if_fail (EV_IS_JOB_LOAD (job));
349 ev_document_doc_mutex_lock ();
352 g_error_free (job->error);
356 ev_document_load (EV_JOB(job)->document, job->uri, &job->error);
358 EV_JOB (job)->finished = TRUE;
360 ev_document_doc_mutex_unlock ();
363 static void ev_job_fonts_init (EvJobFonts *job) { /* Do Nothing */ }
365 static void ev_job_fonts_class_init (EvJobFontsClass *class) { /* Do Nothing */ }
368 ev_job_fonts_new (EvDocument *document)
372 job = g_object_new (EV_TYPE_JOB_FONTS, NULL);
374 EV_JOB (job)->document = g_object_ref (document);
380 ev_job_fonts_run (EvJobFonts *job)
382 EvDocumentFonts *fonts;
384 g_return_if_fail (EV_IS_JOB_FONTS (job));
386 ev_document_doc_mutex_lock ();
388 fonts = EV_DOCUMENT_FONTS (EV_JOB (job)->document);
389 job->scan_completed = !ev_document_fonts_scan (fonts, 20);
391 EV_JOB (job)->finished = TRUE;
393 ev_document_doc_mutex_unlock ();