]> www.fi.muni.cz Git - evince.git/blob - libview/ev-jobs.h
libview: add a method to get the job currently running in the worker thread
[evince.git] / libview / ev-jobs.h
1 /* this file is part of evince, a gnome document viewer
2  *
3  *  Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
4  *  Copyright (C) 2005 Red Hat, Inc
5  *
6  * Evince is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Evince is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20
21 #if !defined (__EV_EVINCE_VIEW_H_INSIDE__) && !defined (EVINCE_COMPILATION)
22 #error "Only <evince-view.h> can be included directly."
23 #endif
24
25 #ifndef __EV_JOBS_H__
26 #define __EV_JOBS_H__
27
28 #include <gio/gio.h>
29 #include <gtk/gtk.h>
30 #include <cairo.h>
31
32 #include <evince-document.h>
33
34 G_BEGIN_DECLS
35
36 typedef struct _EvJob EvJob;
37 typedef struct _EvJobClass EvJobClass;
38
39 typedef struct _EvJobRender EvJobRender;
40 typedef struct _EvJobRenderClass EvJobRenderClass;
41
42 typedef struct _EvJobPageData EvJobPageData;
43 typedef struct _EvJobPageDataClass EvJobPageDataClass;
44
45 typedef struct _EvJobThumbnail EvJobThumbnail;
46 typedef struct _EvJobThumbnailClass EvJobThumbnailClass;
47
48 typedef struct _EvJobLinks EvJobLinks;
49 typedef struct _EvJobLinksClass EvJobLinksClass;
50
51 typedef struct _EvJobAttachments EvJobAttachments;
52 typedef struct _EvJobAttachmentsClass EvJobAttachmentsClass;
53
54 typedef struct _EvJobAnnots EvJobAnnots;
55 typedef struct _EvJobAnnotsClass EvJobAnnotsClass;
56
57 typedef struct _EvJobFonts EvJobFonts;
58 typedef struct _EvJobFontsClass EvJobFontsClass;
59
60 typedef struct _EvJobLoad EvJobLoad;
61 typedef struct _EvJobLoadClass EvJobLoadClass;
62
63 typedef struct _EvJobSave EvJobSave;
64 typedef struct _EvJobSaveClass EvJobSaveClass;
65
66 typedef struct _EvJobFind EvJobFind;
67 typedef struct _EvJobFindClass EvJobFindClass;
68
69 typedef struct _EvJobLayers EvJobLayers;
70 typedef struct _EvJobLayersClass EvJobLayersClass;
71
72 typedef struct _EvJobExport EvJobExport;
73 typedef struct _EvJobExportClass EvJobExportClass;
74
75 typedef struct _EvJobPrint EvJobPrint;
76 typedef struct _EvJobPrintClass EvJobPrintClass;
77
78 #define EV_TYPE_JOB                          (ev_job_get_type())
79 #define EV_JOB(object)                       (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB, EvJob))
80 #define EV_JOB_CLASS(klass)                  (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB, EvJobClass))
81 #define EV_IS_JOB(object)                    (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB))
82 #define EV_JOB_GET_CLASS(object)             (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_JOB, EvJobClass))
83
84 #define EV_TYPE_JOB_LINKS                    (ev_job_links_get_type())
85 #define EV_JOB_LINKS(object)                 (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_LINKS, EvJobLinks))
86 #define EV_JOB_LINKS_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_LINKS, EvJobLinksClass))
87 #define EV_IS_JOB_LINKS(object)              (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_LINKS))
88
89 #define EV_TYPE_JOB_ATTACHMENTS              (ev_job_attachments_get_type())
90 #define EV_JOB_ATTACHMENTS(object)           (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_ATTACHMENTS, EvJobAttachments))
91 #define EV_JOB_ATTACHMENTS_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_ATTACHMENTS, EvJobAttachmentsClass))
92 #define EV_IS_JOB_ATTACHMENTS(object)        (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_ATTACHMENTS))
93
94 #define EV_TYPE_JOB_ANNOTS                   (ev_job_annots_get_type())
95 #define EV_JOB_ANNOTS(object)                (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_ANNOTS, EvJobAnnots))
96 #define EV_JOB_ANNOTS_CLASS(klass)           (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_ANNOTS, EvJobAnnotsClass))
97 #define EV_IS_JOB_ANNOTS(object)             (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_ANNOTS))
98
99 #define EV_TYPE_JOB_RENDER                   (ev_job_render_get_type())
100 #define EV_JOB_RENDER(object)                (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_RENDER, EvJobRender))
101 #define EV_JOB_RENDER_CLASS(klass)           (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_RENDER, EvJobRenderClass))
102 #define EV_IS_JOB_RENDER(object)             (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_RENDER))
103
104 #define EV_TYPE_JOB_PAGE_DATA                (ev_job_page_data_get_type())
105 #define EV_JOB_PAGE_DATA(object)             (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_PAGE_DATA, EvJobPageData))
106 #define EV_JOB_PAGE_DATA_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_PAGE_DATA, EvJobPageDataClass))
107 #define EV_IS_JOB_PAGE_DATA(object)          (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_PAGE_DATA))
108
109 #define EV_TYPE_JOB_THUMBNAIL                (ev_job_thumbnail_get_type())
110 #define EV_JOB_THUMBNAIL(object)             (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_THUMBNAIL, EvJobThumbnail))
111 #define EV_JOB_THUMBNAIL_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_THUMBNAIL, EvJobThumbnailClass))
112 #define EV_IS_JOB_THUMBNAIL(object)          (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_THUMBNAIL))
113
114 #define EV_TYPE_JOB_FONTS                    (ev_job_fonts_get_type())
115 #define EV_JOB_FONTS(object)                 (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_FONTS, EvJobFonts))
116 #define EV_JOB_FONTS_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_FONTS, EvJobFontsClass))
117 #define EV_IS_JOB_FONTS(object)              (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_FONTS))
118
119 #define EV_TYPE_JOB_LOAD                     (ev_job_load_get_type())
120 #define EV_JOB_LOAD(object)                  (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_LOAD, EvJobLoad))
121 #define EV_JOB_LOAD_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_LOAD, EvJobLoadClass))
122 #define EV_IS_JOB_LOAD(object)               (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_LOAD))
123
124 #define EV_TYPE_JOB_SAVE                     (ev_job_save_get_type())
125 #define EV_JOB_SAVE(object)                  (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_SAVE, EvJobSave))
126 #define EV_JOB_SAVE_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_SAVE, EvJobSaveClass))
127 #define EV_IS_JOB_SAVE(object)               (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_SAVE))
128
129 #define EV_TYPE_JOB_FIND                     (ev_job_find_get_type())
130 #define EV_JOB_FIND(object)                  (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_FIND, EvJobFind))
131 #define EV_JOB_FIND_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_FIND, EvJobFindClass))
132 #define EV_IS_JOB_FIND(object)               (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_FIND))
133
134 #define EV_TYPE_JOB_LAYERS                   (ev_job_layers_get_type())
135 #define EV_JOB_LAYERS(object)                (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_LAYERS, EvJobLayers))
136 #define EV_JOB_LAYERS_CLASS(klass)           (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_LAYERS, EvJobLayersClass))
137 #define EV_IS_JOB_LAYERS(object)             (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_LAYERS))
138
139 #define EV_TYPE_JOB_EXPORT                    (ev_job_export_get_type())
140 #define EV_JOB_EXPORT(object)                 (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_EXPORT, EvJobExport))
141 #define EV_JOB_EXPORT_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_EXPORT, EvJobExportClass))
142 #define EV_IS_JOB_EXPORT(object)              (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_EXPORT))
143
144 #define EV_TYPE_JOB_PRINT                    (ev_job_print_get_type())
145 #define EV_JOB_PRINT(object)                 (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_PRINT, EvJobPrint))
146 #define EV_JOB_PRINT_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_PRINT, EvJobPrintClass))
147 #define EV_IS_JOB_PRINT(object)              (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_PRINT))
148
149 typedef enum {
150         EV_JOB_RUN_THREAD,
151         EV_JOB_RUN_MAIN_LOOP
152 } EvJobRunMode;
153
154 struct _EvJob
155 {
156         GObject parent;
157         
158         EvDocument *document;
159
160         EvJobRunMode run_mode;
161
162         guint cancelled : 1;
163         guint finished : 1;
164         guint failed : 1;
165         
166         GError *error;
167         GCancellable *cancellable;
168
169         guint idle_finished_id;
170         guint idle_cancelled_id;
171 };
172
173 struct _EvJobClass
174 {
175         GObjectClass parent_class;
176
177         gboolean (*run)         (EvJob *job);
178         
179         /* Signals */
180         void     (* cancelled)  (EvJob *job);
181         void     (* finished)   (EvJob *job);
182 };
183
184 struct _EvJobLinks
185 {
186         EvJob parent;
187
188         GtkTreeModel *model;
189 };
190
191 struct _EvJobLinksClass
192 {
193         EvJobClass parent_class;
194 };
195
196 struct _EvJobAttachments
197 {
198         EvJob parent;
199
200         GList *attachments;
201 };
202
203 struct _EvJobAttachmentsClass
204 {
205         EvJobClass parent_class;
206 };
207
208 struct _EvJobAnnots
209 {
210         EvJob parent;
211
212         GList *annots;
213 };
214
215 struct _EvJobAnnotsClass
216 {
217         EvJobClass parent_class;
218 };
219
220 struct _EvJobRender
221 {
222         EvJob parent;
223
224         gint page;
225         gint rotation;
226         gdouble scale;
227
228         gboolean page_ready;
229         gint target_width;
230         gint target_height;
231         cairo_surface_t *surface;
232
233         gboolean include_selection;
234         cairo_surface_t *selection;
235         cairo_region_t *selection_region;
236         EvRectangle selection_points;
237         EvSelectionStyle selection_style;
238         GdkColor base;
239         GdkColor text;
240 };
241
242 struct _EvJobRenderClass
243 {
244         EvJobClass parent_class;
245 };
246
247 typedef enum {
248         EV_PAGE_DATA_INCLUDE_NONE         = 0,
249         EV_PAGE_DATA_INCLUDE_LINKS        = 1 << 0,
250         EV_PAGE_DATA_INCLUDE_TEXT         = 1 << 1,
251         EV_PAGE_DATA_INCLUDE_TEXT_MAPPING = 1 << 2,
252         EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT  = 1 << 3,
253         EV_PAGE_DATA_INCLUDE_IMAGES       = 1 << 4,
254         EV_PAGE_DATA_INCLUDE_FORMS        = 1 << 5,
255         EV_PAGE_DATA_INCLUDE_ANNOTS       = 1 << 6,
256         EV_PAGE_DATA_INCLUDE_ALL          = (1 << 7) - 1
257 } EvJobPageDataFlags;
258
259 struct _EvJobPageData
260 {
261         EvJob parent;
262
263         gint page;
264         EvJobPageDataFlags flags;
265
266         EvMappingList  *link_mapping;
267         EvMappingList  *image_mapping;
268         EvMappingList  *form_field_mapping;
269         EvMappingList  *annot_mapping;
270         cairo_region_t *text_mapping;
271         gchar *text;
272         EvRectangle *text_layout;
273         guint text_layout_length;
274 };
275
276 struct _EvJobPageDataClass
277 {
278         EvJobClass parent_class;
279 };
280
281 struct _EvJobThumbnail
282 {
283         EvJob parent;
284
285         gint page;
286         gint rotation;
287         gdouble scale;
288         
289         GdkPixbuf *thumbnail;
290 };
291
292 struct _EvJobThumbnailClass
293 {
294         EvJobClass parent_class;
295 };
296
297 struct _EvJobFonts
298 {
299         EvJob parent;
300         gboolean scan_completed;
301 };
302
303 struct _EvJobFontsClass
304 {
305         EvJobClass parent_class;
306
307         /* Signals */
308         void (* updated)  (EvJobFonts *job,
309                            gdouble     progress);
310 };
311
312 struct _EvJobLoad
313 {
314         EvJob parent;
315
316         gchar *uri;
317         gchar *password;
318 };
319
320 struct _EvJobLoadClass
321 {
322         EvJobClass parent_class;
323 };
324
325 struct _EvJobSave
326 {
327         EvJob parent;
328
329         gchar *uri;
330         gchar *document_uri;
331 };
332
333 struct _EvJobSaveClass
334 {
335         EvJobClass parent_class;
336 };
337
338 struct _EvJobFind
339 {
340         EvJob parent;
341
342         gint start_page;
343         gint current_page;
344         gint n_pages;
345         GList **pages;
346         gchar *text;
347         gboolean case_sensitive;
348         gboolean has_results;
349 };
350
351 struct _EvJobFindClass
352 {
353         EvJobClass parent_class;
354
355         /* Signals */
356         void (* updated)  (EvJobFind *job,
357                            gint       page);
358 };
359
360 struct _EvJobLayers
361 {
362         EvJob parent;
363
364         GtkTreeModel *model;
365 };
366
367 struct _EvJobLayersClass
368 {
369         EvJobClass parent_class;
370 };
371
372 struct _EvJobExport
373 {
374         EvJob parent;
375
376         gint page;
377         EvRenderContext *rc;
378 };
379
380 struct _EvJobExportClass
381 {
382         EvJobClass parent_class;
383 };
384
385 struct _EvJobPrint
386 {
387         EvJob parent;
388
389         gint page;
390         cairo_t *cr;
391 };
392
393 struct _EvJobPrintClass
394 {
395         EvJobClass parent_class;
396 };
397
398 /* Base job class */
399 GType           ev_job_get_type           (void) G_GNUC_CONST;
400 gboolean        ev_job_run                (EvJob          *job);
401 void            ev_job_cancel             (EvJob          *job);
402 void            ev_job_failed             (EvJob          *job,
403                                            GQuark          domain,
404                                            gint            code,
405                                            const gchar    *format,
406                                            ...);
407 void            ev_job_failed_from_error  (EvJob          *job,
408                                            GError         *error);
409 void            ev_job_succeeded          (EvJob          *job);
410 gboolean        ev_job_is_finished        (EvJob          *job);
411 gboolean        ev_job_is_failed          (EvJob          *job);
412 EvJobRunMode    ev_job_get_run_mode       (EvJob          *job);
413 void            ev_job_set_run_mode       (EvJob          *job,
414                                            EvJobRunMode    run_mode);
415
416 /* EvJobLinks */
417 GType           ev_job_links_get_type     (void) G_GNUC_CONST;
418 EvJob          *ev_job_links_new          (EvDocument     *document);
419
420 /* EvJobAttachments */
421 GType           ev_job_attachments_get_type (void) G_GNUC_CONST;
422 EvJob          *ev_job_attachments_new      (EvDocument     *document);
423
424 /* EvJobAnnots */
425 GType           ev_job_annots_get_type      (void) G_GNUC_CONST;
426 EvJob          *ev_job_annots_new           (EvDocument     *document);
427
428 /* EvJobRender */
429 GType           ev_job_render_get_type    (void) G_GNUC_CONST;
430 EvJob          *ev_job_render_new         (EvDocument      *document,
431                                            gint             page,
432                                            gint             rotation,
433                                            gdouble          scale,
434                                            gint             width,
435                                            gint             height);
436 void     ev_job_render_set_selection_info (EvJobRender     *job,
437                                            EvRectangle     *selection_points,
438                                            EvSelectionStyle selection_style,
439                                            GdkColor        *text,
440                                            GdkColor        *base);
441 /* EvJobPageData */
442 GType           ev_job_page_data_get_type (void) G_GNUC_CONST;
443 EvJob          *ev_job_page_data_new      (EvDocument      *document,
444                                            gint             page,
445                                            EvJobPageDataFlags flags);
446
447 /* EvJobThumbnail */
448 GType           ev_job_thumbnail_get_type (void) G_GNUC_CONST;
449 EvJob          *ev_job_thumbnail_new      (EvDocument      *document,
450                                            gint             page,
451                                            gint             rotation,
452                                            gdouble          scale);
453 /* EvJobFonts */
454 GType           ev_job_fonts_get_type     (void) G_GNUC_CONST;
455 EvJob          *ev_job_fonts_new          (EvDocument      *document);
456
457 /* EvJobLoad */
458 GType           ev_job_load_get_type      (void) G_GNUC_CONST;
459 EvJob          *ev_job_load_new           (const gchar     *uri);
460 void            ev_job_load_set_uri       (EvJobLoad       *load,
461                                            const gchar     *uri);
462 void            ev_job_load_set_password  (EvJobLoad       *job,
463                                            const gchar     *password);
464
465 /* EvJobSave */
466 GType           ev_job_save_get_type      (void) G_GNUC_CONST;
467 EvJob          *ev_job_save_new           (EvDocument      *document,
468                                            const gchar     *uri,
469                                            const gchar     *document_uri);
470 /* EvJobFind */
471 GType           ev_job_find_get_type      (void) G_GNUC_CONST;
472 EvJob          *ev_job_find_new           (EvDocument      *document,
473                                            gint             start_page,
474                                            gint             n_pages,
475                                            const gchar     *text,
476                                            gboolean         case_sensitive);
477 gint            ev_job_find_get_n_results (EvJobFind       *job,
478                                            gint             pages);
479 gdouble         ev_job_find_get_progress  (EvJobFind       *job);
480 gboolean        ev_job_find_has_results   (EvJobFind       *job);
481 GList         **ev_job_find_get_results   (EvJobFind       *job);
482
483 /* EvJobLayers */
484 GType           ev_job_layers_get_type    (void) G_GNUC_CONST;
485 EvJob          *ev_job_layers_new         (EvDocument     *document);
486
487 /* EvJobExport */
488 GType           ev_job_export_get_type    (void) G_GNUC_CONST;
489 EvJob          *ev_job_export_new         (EvDocument     *document);
490 void            ev_job_export_set_page    (EvJobExport    *job,
491                                            gint            page);
492 /* EvJobPrint */
493 GType           ev_job_print_get_type    (void) G_GNUC_CONST;
494 EvJob          *ev_job_print_new         (EvDocument     *document);
495 void            ev_job_print_set_page    (EvJobPrint     *job,
496                                           gint            page);
497 void            ev_job_print_set_cairo   (EvJobPrint     *job,
498                                           cairo_t        *cr);
499
500 G_END_DECLS
501
502 #endif /* __EV_JOBS_H__ */