43 #include <glib/gstdio.h>
44 #include <glib/gi18n-lib.h>
94 G_DEFINE_ABSTRACT_TYPE (
EvJob, ev_job, G_TYPE_OBJECT)
115 job->cancellable = g_cancellable_new ();
126 g_object_unref (job->document);
127 job->document = NULL;
130 if (job->cancellable) {
131 g_object_unref (job->cancellable);
132 job->cancellable = NULL;
136 g_error_free (job->error);
140 (* G_OBJECT_CLASS (ev_job_parent_class)->dispose) (
object);
146 GObjectClass *oclass;
148 oclass = G_OBJECT_CLASS (
class);
153 g_signal_new (
"cancelled",
158 g_cclosure_marshal_VOID__VOID,
161 g_signal_new (
"finished",
166 g_cclosure_marshal_VOID__VOID,
175 job->idle_finished_id = 0;
177 if (job->cancelled) {
192 if (g_cancellable_is_cancelled (job->cancellable)) {
197 job->finished =
TRUE;
200 job->idle_finished_id =
201 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
204 (GDestroyNotify)g_object_unref);
216 return class->
run (job);
229 job->cancelled =
TRUE;
230 g_cancellable_cancel (job->cancellable);
232 if (job->finished && job->idle_finished_id == 0)
248 if (job->failed || job->finished)
255 va_start (args, format);
256 message = g_strdup_vprintf (format, args);
259 job->error = g_error_new_literal (domain, code, message);
276 if (job->failed || job->finished)
282 job->error = g_error_copy (error);
302 return job->finished;
314 return job->run_mode;
321 job->run_mode = run_mode;
341 g_object_unref (job->
model);
345 (* G_OBJECT_CLASS (ev_job_links_parent_class)->dispose) (
object);
358 gtk_tree_model_get (tree_model, iter,
370 gtk_tree_store_set (GTK_TREE_STORE (tree_model), iter,
375 g_object_unref (link);
402 GObjectClass *oclass = G_OBJECT_CLASS (
class);
417 job->document = g_object_ref (document);
455 g_list_foreach (job->
attachments, (GFunc)g_object_unref, NULL);
460 (* G_OBJECT_CLASS (ev_job_attachments_parent_class)->dispose) (
object);
484 GObjectClass *oclass = G_OBJECT_CLASS (
class);
499 job->document = g_object_ref (document);
522 g_list_free (job->
annots);
526 G_OBJECT_CLASS (ev_job_annots_parent_class)->dispose (
object);
546 g_object_unref (page);
549 job_annots->
annots = g_list_prepend (job_annots->
annots, mapping_list);
553 job_annots->
annots = g_list_reverse (job_annots->
annots);
563 GObjectClass *oclass = G_OBJECT_CLASS (
class);
578 job->document = g_object_ref (document);
600 cairo_surface_destroy (job->
surface);
614 (* G_OBJECT_CLASS (ev_job_render_parent_class)->dispose) (
object);
637 g_object_unref (ev_page);
641 if (job_render->
surface == NULL) {
649 _(
"Failed to render page %d"),
658 if (g_cancellable_is_cancelled (job->cancellable)) {
673 &(job_render->
text), &(job_render->
base));
694 GObjectClass *oclass = G_OBJECT_CLASS (
class);
715 EV_JOB (job)->document = g_object_ref (document);
800 g_object_unref (ev_page);
827 EV_JOB (job)->document = g_object_ref (document);
860 (* G_OBJECT_CLASS (ev_job_thumbnail_parent_class)->dispose) (
object);
868 GdkPixbuf *pixbuf = NULL;
880 g_object_unref (page);
893 g_object_unref (pixbuf);
901 _(
"Failed to create thumbnail for page %d"),
913 GObjectClass *oclass = G_OBJECT_CLASS (
class);
932 EV_JOB (job)->document = g_object_ref (document);
1012 #ifdef EV_ENABLE_DEBUG
1039 g_signal_new (
"updated",
1044 g_cclosure_marshal_VOID__DOUBLE,
1058 EV_JOB (job)->document = g_object_ref (document);
1087 (* G_OBJECT_CLASS (ev_job_load_parent_class)->dispose) (
object);
1094 GError *error = NULL;
1104 if (job->document) {
1105 const gchar *uncompressed_uri;
1112 job->failed =
FALSE;
1113 job->finished =
FALSE;
1114 g_clear_error (&job->error);
1116 uncompressed_uri = g_object_get_data (G_OBJECT (job->document),
1117 "uri-uncompressed");
1119 uncompressed_uri ? uncompressed_uri : job_load->
uri,
1130 g_error_free (error);
1141 GObjectClass *oclass = G_OBJECT_CLASS (
class);
1156 job->
uri = g_strdup (uri);
1168 job->
uri = g_strdup (uri);
1178 job->
password = password ? g_strdup (password) : NULL;
1205 g_object_unref (job->
stream);
1212 G_OBJECT_CLASS (ev_job_load_stream_parent_class)->dispose (
object);
1219 GError *error = NULL;
1229 if (job->document) {
1236 job->failed =
FALSE;
1237 job->finished =
FALSE;
1238 g_clear_error (&job->error);
1242 job_load_stream->
flags,
1248 job_load_stream->
flags,
1257 g_error_free (error);
1268 GObjectClass *oclass = G_OBJECT_CLASS (
class);
1290 GInputStream *stream)
1293 g_return_if_fail (G_IS_INPUT_STREAM (stream));
1295 g_object_ref (stream);
1297 g_object_unref (job->
stream);
1312 const char *password)
1321 job->
password = g_strdup (password);
1322 g_free (old_password);
1349 g_object_unref (job->
gfile);
1356 G_OBJECT_CLASS (ev_job_load_gfile_parent_class)->dispose (
object);
1363 GError *error = NULL;
1372 if (job->document) {
1379 job->failed =
FALSE;
1380 job->finished =
FALSE;
1381 g_clear_error (&job->error);
1384 job_load_gfile->
gfile,
1385 job_load_gfile->
flags,
1390 job_load_gfile->
flags,
1399 g_error_free (error);
1410 GObjectClass *oclass = G_OBJECT_CLASS (
class);
1435 g_return_if_fail (G_IS_FILE (gfile));
1437 g_object_ref (gfile);
1439 g_object_unref (job->
gfile);
1454 const char *password)
1463 job->
password = g_strdup (password);
1464 g_free (old_password);
1491 (* G_OBJECT_CLASS (ev_job_save_parent_class)->dispose) (
object);
1499 gchar *tmp_filename = NULL;
1501 GError *error = NULL;
1506 fd =
ev_mkstemp (
"saveacopy.XXXXXX", &tmp_filename, &error);
1509 g_error_free (error);
1518 local_uri = g_filename_to_uri (tmp_filename, NULL, &error);
1519 if (local_uri != NULL) {
1528 g_error_free (error);
1536 if (g_object_get_data (G_OBJECT (job->document),
"uri-uncompressed")) {
1542 if (ext && g_ascii_strcasecmp (ext,
".gz") == 0)
1546 if (ext && g_ascii_strcasecmp (ext,
".bz2") == 0)
1551 g_unlink (tmp_filename);
1553 if (!uri_comp || error) {
1556 local_uri = uri_comp;
1560 g_free (tmp_filename);
1565 g_error_free (error);
1584 g_error_free (error);
1595 GObjectClass *oclass = G_OBJECT_CLASS (
class);
1605 const gchar *document_uri)
1609 ev_debug_message (DEBUG_JOBS,
"uri: %s, document_uri: %s", uri, document_uri);
1613 EV_JOB (job)->document = g_object_ref (document);
1614 job->
uri = g_strdup (uri);
1642 for (i = 0; i < job->
n_pages; i++) {
1644 g_list_free (job->
pages[i]);
1647 g_free (job->
pages);
1651 (* G_OBJECT_CLASS (ev_job_find_parent_class)->dispose) (
object);
1668 #ifdef EV_ENABLE_DEBUG
1677 g_object_unref (ev_page);
1701 GObjectClass *gobject_class = G_OBJECT_CLASS (
class);
1707 g_signal_new (
"updated",
1712 g_cclosure_marshal_VOID__INT,
1722 gboolean case_sensitive)
1730 EV_JOB (job)->document = g_object_ref (document);
1734 job->
pages = g_new0 (GList *, n_pages);
1735 job->
text = g_strdup (text);
1779 return g_list_length (job->
pages[page]);
1798 return pages_done / (gdouble) job->
n_pages;
1836 g_object_unref (job->
model);
1840 (* G_OBJECT_CLASS (ev_job_layers_parent_class)->dispose) (
object);
1863 GObjectClass *oclass = G_OBJECT_CLASS (
class);
1878 job->document = g_object_ref (document);
1901 g_object_unref (job->
rc);
1905 (* G_OBJECT_CLASS (ev_job_export_parent_class)->dispose) (
object);
1914 g_assert (job_export->
page != -1);
1922 if (job_export->
rc) {
1923 job->failed =
FALSE;
1924 job->finished =
FALSE;
1925 g_clear_error (&job->error);
1931 g_object_unref (ev_page);
1945 GObjectClass *oclass = G_OBJECT_CLASS (
class);
1960 job->document = g_object_ref (document);
1990 cairo_destroy (job->
cr);
1994 (* G_OBJECT_CLASS (ev_job_print_parent_class)->dispose) (
object);
2002 cairo_status_t cr_status;
2004 g_assert (job_print->
page != -1);
2005 g_assert (job_print->
cr != NULL);
2010 job->failed =
FALSE;
2011 job->finished =
FALSE;
2012 g_clear_error (&job->error);
2018 ev_page, job_print->
cr);
2019 g_object_unref (ev_page);
2023 if (g_cancellable_is_cancelled (job->cancellable))
2026 cr_status = cairo_status (job_print->
cr);
2027 if (cr_status == CAIRO_STATUS_SUCCESS) {
2032 GTK_PRINT_ERROR_GENERAL,
2033 _(
"Failed to print page %d: %s"),
2035 cairo_status_to_string (cr_status));
2044 GObjectClass *oclass = G_OBJECT_CLASS (
class);
2059 job->document = g_object_ref (document);
2079 cairo_destroy (job->
cr);
2080 job->
cr = cr ? cairo_reference (cr) : NULL;