]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-print-operation.c
shell: Actually use the launch context
[evince.git] / shell / ev-print-operation.c
index 4e78c3f050ee7a02cc6ef29f3746b1f5c5a074dc..08c655d4bce6f1100fa9223154c7615723bcc475 100644 (file)
@@ -28,7 +28,6 @@
 #include <glib/gstdio.h>
 #include <unistd.h>
 
 #include <glib/gstdio.h>
 #include <unistd.h>
 
-#include "ev-page-cache.h"
 #include "ev-file-exporter.h"
 #include "ev-jobs.h"
 #include "ev-job-scheduler.h"
 #include "ev-file-exporter.h"
 #include "ev-jobs.h"
 #include "ev-job-scheduler.h"
@@ -1253,13 +1252,8 @@ ev_print_operation_export_print_dialog_response_cb (GtkDialog              *dial
 
        get_first_and_last_page (export, &first_page, &last_page);
 
 
        get_first_and_last_page (export, &first_page, &last_page);
 
-       if (file_format) {
-               export->fc.format = g_ascii_strcasecmp (file_format, "pdf") == 0 ?
-                       EV_FILE_FORMAT_PDF : EV_FILE_FORMAT_PS;
-       } else {
-               export->fc.format = gtk_printer_accepts_pdf (printer) ?
-                       EV_FILE_FORMAT_PDF : EV_FILE_FORMAT_PS;
-       }
+       export->fc.format = file_format && g_ascii_strcasecmp (file_format, "pdf") == 0 ?
+               EV_FILE_FORMAT_PDF : EV_FILE_FORMAT_PS;
        export->fc.filename = export->temp_file;
        export->fc.first_page = MIN (first_page, last_page);
        export->fc.last_page = MAX (first_page, last_page);
        export->fc.filename = export->temp_file;
        export->fc.first_page = MIN (first_page, last_page);
        export->fc.last_page = MAX (first_page, last_page);
@@ -1428,7 +1422,7 @@ ev_print_operation_export_constructor (GType                  type,
                                                                                       construct_params);
        export = EV_PRINT_OPERATION_EXPORT (object);
        op = EV_PRINT_OPERATION (object);
                                                                                       construct_params);
        export = EV_PRINT_OPERATION_EXPORT (object);
        op = EV_PRINT_OPERATION (object);
-       export->n_pages = ev_page_cache_get_n_pages (ev_page_cache_get (op->document));
+       export->n_pages = ev_document_get_n_pages (op->document);
 
        return object;
 }
 
        return object;
 }
@@ -1472,6 +1466,8 @@ struct _EvPrintOperationPrint {
        EvPrintOperation parent;
 
        GtkPrintOperation *op;
        EvPrintOperation parent;
 
        GtkPrintOperation *op;
+       gint               n_pages_to_print;
+       gint               total;
        EvJob             *job_print;
        gchar             *job_name;
 };
        EvJob             *job_print;
        gchar             *job_name;
 };
@@ -1587,10 +1583,8 @@ ev_print_operation_print_begin_print (EvPrintOperationPrint *print,
        EvPrintOperation *op = EV_PRINT_OPERATION (print);
        gint              n_pages;
 
        EvPrintOperation *op = EV_PRINT_OPERATION (print);
        gint              n_pages;
 
-       n_pages = ev_page_cache_get_n_pages (ev_page_cache_get (op->document));
+       n_pages = ev_document_get_n_pages (op->document);
        gtk_print_operation_set_n_pages (print->op, n_pages);
        gtk_print_operation_set_n_pages (print->op, n_pages);
-
-       /* FIXME: gtk_print should provide the progress */
        ev_print_operation_update_status (op, -1, n_pages, 0);
 
        g_signal_emit (op, signals[BEGIN_PRINT], 0);
        ev_print_operation_update_status (op, -1, n_pages, 0);
 
        g_signal_emit (op, signals[BEGIN_PRINT], 0);
@@ -1602,17 +1596,36 @@ ev_print_operation_print_done (EvPrintOperationPrint  *print,
 {
        EvPrintOperation *op = EV_PRINT_OPERATION (print);
 
 {
        EvPrintOperation *op = EV_PRINT_OPERATION (print);
 
-       /* FIXME: gtk_print should provide the progress */
-       ev_print_operation_update_status (op, 0, 1, 1.0);
+       ev_print_operation_update_status (op, 0, print->n_pages_to_print, 1.0);
 
        g_signal_emit (op, signals[DONE], 0, result);
 }
 
 
        g_signal_emit (op, signals[DONE], 0, result);
 }
 
+static void
+ev_print_operation_print_status_changed (EvPrintOperationPrint *print)
+{
+#ifdef HAVE_GTK_PRINT_OPERATION_GET_N_PAGES_TO_PRINT
+       GtkPrintStatus status;
+
+       status = gtk_print_operation_get_status (print->op);
+       if (status == GTK_PRINT_STATUS_GENERATING_DATA)
+               print->n_pages_to_print = gtk_print_operation_get_n_pages_to_print (print->op);
+#endif
+}
+
 static void
 print_job_finished (EvJobPrint            *job,
                    EvPrintOperationPrint *print)
 {
 static void
 print_job_finished (EvJobPrint            *job,
                    EvPrintOperationPrint *print)
 {
+       EvPrintOperation *op = EV_PRINT_OPERATION (print);
+
        gtk_print_operation_draw_page_finish (print->op);
        gtk_print_operation_draw_page_finish (print->op);
+#ifdef HAVE_GTK_PRINT_OPERATION_GET_N_PAGES_TO_PRINT
+       print->total++;
+       ev_print_operation_update_status (op, print->total,
+                                         print->n_pages_to_print,
+                                         print->total / (gdouble)print->n_pages_to_print);
+#endif
        ev_job_print_set_cairo (job, NULL);
 }
 
        ev_job_print_set_cairo (job, NULL);
 }
 
@@ -1623,6 +1636,23 @@ print_job_cancelled (EvJobPrint            *job,
        gtk_print_operation_cancel (print->op);
 }
 
        gtk_print_operation_cancel (print->op);
 }
 
+static void
+ev_print_operation_print_request_page_setup (EvPrintOperationPrint *print,
+                                            GtkPrintContext       *context,
+                                            gint                   page_nr,
+                                            GtkPageSetup          *setup)
+{
+       EvPrintOperation *op = EV_PRINT_OPERATION (print);
+       gdouble           width, height;
+
+       ev_document_get_page_size (op->document, page_nr,
+                                  &width, &height);
+       if (width > height)
+               gtk_page_setup_set_orientation (setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
+       else
+               gtk_page_setup_set_orientation (setup, GTK_PAGE_ORIENTATION_PORTRAIT);
+}
+
 static void
 ev_print_operation_print_draw_page (EvPrintOperationPrint *print,
                                    GtkPrintContext       *context,
 static void
 ev_print_operation_print_draw_page (EvPrintOperationPrint *print,
                                    GtkPrintContext       *context,
@@ -1631,7 +1661,7 @@ ev_print_operation_print_draw_page (EvPrintOperationPrint *print,
        EvPrintOperation *op = EV_PRINT_OPERATION (print);
        cairo_t          *cr;
        gdouble           cr_width, cr_height;
        EvPrintOperation *op = EV_PRINT_OPERATION (print);
        cairo_t          *cr;
        gdouble           cr_width, cr_height;
-       gint              width, height;
+       gdouble           width, height, scale;
 
        gtk_print_operation_set_defer_drawing (print->op);
 
 
        gtk_print_operation_set_defer_drawing (print->op);
 
@@ -1650,10 +1680,13 @@ ev_print_operation_print_draw_page (EvPrintOperationPrint *print,
        cr = gtk_print_context_get_cairo_context (context);
        cr_width = gtk_print_context_get_width (context);
        cr_height = gtk_print_context_get_height (context);
        cr = gtk_print_context_get_cairo_context (context);
        cr_width = gtk_print_context_get_width (context);
        cr_height = gtk_print_context_get_height (context);
-       ev_page_cache_get_size (ev_page_cache_get (op->document),
-                               page, 0, 1.0,
-                               &width, &height);
-       cairo_scale (cr, cr_width / (gdouble)width, cr_height / (gdouble)height);
+       ev_document_get_page_size (op->document, page,
+                                  &width, &height);
+       if (cr_width / width < cr_height / height)
+               scale = cr_width / width;
+       else
+               scale = cr_height / height;
+       cairo_scale (cr, scale, scale);
 
        ev_job_print_set_cairo (EV_JOB_PRINT (print->job_print), cr);
        ev_job_scheduler_push_job (print->job_print, EV_JOB_PRIORITY_NONE);
 
        ev_job_print_set_cairo (EV_JOB_PRINT (print->job_print), cr);
        ev_job_scheduler_push_job (print->job_print, EV_JOB_PRIORITY_NONE);
@@ -1703,6 +1736,12 @@ ev_print_operation_print_init (EvPrintOperationPrint *print)
        g_signal_connect_swapped (print->op, "draw_page",
                                  G_CALLBACK (ev_print_operation_print_draw_page),
                                  print);
        g_signal_connect_swapped (print->op, "draw_page",
                                  G_CALLBACK (ev_print_operation_print_draw_page),
                                  print);
+       g_signal_connect_swapped (print->op, "status_changed",
+                                 G_CALLBACK (ev_print_operation_print_status_changed),
+                                 print);
+       g_signal_connect_swapped (print->op, "request_page_setup",
+                                 G_CALLBACK (ev_print_operation_print_request_page_setup),
+                                 print);
        gtk_print_operation_set_allow_async (print->op, TRUE);
 }
 
        gtk_print_operation_set_allow_async (print->op, TRUE);
 }