]> www.fi.muni.cz Git - evince.git/blobdiff - libview/ev-print-operation.c
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / libview / ev-print-operation.c
index d14c9e7b5c8c9514f6054ff9470bcae7fef81bd9..8c96dae4a225b85dd0b29d8438d901f3ee314704 100644 (file)
@@ -855,33 +855,34 @@ export_print_done (EvPrintOperationExport *export)
                g_key_file_free (key_file);
 
                if (!error) {
-                       gint    argc;
-                       gchar **argv;
                        gchar  *cmd;
                        gchar  *quoted_filename;
                        gchar  *quoted_settings_filename;
+                        GAppInfo *app;
+                        GdkAppLaunchContext *ctx;
 
                        quoted_filename = g_shell_quote (export->temp_file);
                        quoted_settings_filename = g_shell_quote (print_settings_file);
                        cmd = g_strdup_printf ("evince-previewer --unlink-tempfile --print-settings %s %s",
                                               quoted_settings_filename, quoted_filename);
 
-                       g_shell_parse_argv (cmd, &argc, &argv, &error);
-
                        g_free (quoted_filename);
                        g_free (quoted_settings_filename);
-                       g_free (cmd);
 
-                       if (!error) {
-                               gdk_spawn_on_screen (gtk_window_get_screen (export->parent_window),
-                                                    NULL, argv, NULL,
-                                                    G_SPAWN_SEARCH_PATH,
-                                                    NULL, NULL, NULL,
-                                                    &error);
-                       }
+                       app = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
 
-                       g_strfreev (argv);
-               }
+                       if (app != NULL) {
+                               ctx = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (export->parent_window)));
+                               gdk_app_launch_context_set_screen (ctx, gtk_window_get_screen (export->parent_window));
+
+                               g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
+
+                               g_object_unref (app);
+                               g_object_unref (ctx);
+                        }
+
+                       g_free (cmd);
+                }
 
                if (error) {
                        if (print_settings_file)
@@ -1622,7 +1623,10 @@ ev_print_operation_print_cancel (EvPrintOperation *op)
 {
        EvPrintOperationPrint *print = EV_PRINT_OPERATION_PRINT (op);
 
-       gtk_print_operation_cancel (print->op);
+        if (print->job_print)
+                ev_job_cancel (print->job_print);
+        else
+                gtk_print_operation_cancel (print->op);
 }
 
 static void
@@ -1701,11 +1705,30 @@ print_job_finished (EvJobPrint            *job,
        ev_job_print_set_cairo (job, NULL);
 }
 
+static gboolean
+draw_page_finish_idle (EvPrintOperationPrint *print)
+{
+        if (ev_job_scheduler_get_running_thread_job () == print->job_print)
+                return TRUE;
+
+        gtk_print_operation_draw_page_finish (print->op);
+
+        return FALSE;
+}
+
 static void
 print_job_cancelled (EvJobPrint            *job,
-                    EvPrintOperationPrint *print)
+                     EvPrintOperationPrint *print)
 {
-       gtk_print_operation_cancel (print->op);
+        /* Finish the current page, so that draw-page
+         * is emitted again and it will cancel the
+         * print operation. If the job is still
+         * running, wait until it finishes.
+         */
+        if (ev_job_scheduler_get_running_thread_job () == print->job_print)
+                g_idle_add ((GSourceFunc)draw_page_finish_idle, print);
+        else
+                gtk_print_operation_draw_page_finish (print->op);
 }
 
 static void
@@ -1770,10 +1793,14 @@ ev_print_operation_print_draw_page (EvPrintOperationPrint *print,
                g_signal_connect (G_OBJECT (print->job_print), "finished",
                                  G_CALLBACK (print_job_finished),
                                  (gpointer)print);
-               g_signal_connect (G_OBJECT (print->job_print), "cancelled",
-                                 G_CALLBACK (print_job_cancelled),
-                                 (gpointer)print);
-       }
+                g_signal_connect (G_OBJECT (print->job_print), "cancelled",
+                                  G_CALLBACK (print_job_cancelled),
+                                  (gpointer)print);
+       } else if (g_cancellable_is_cancelled (print->job_print->cancellable)) {
+                gtk_print_operation_cancel (print->op);
+                ev_job_print_set_cairo (EV_JOB_PRINT (print->job_print), NULL);
+                return;
+        }
 
        ev_job_print_set_page (EV_JOB_PRINT (print->job_print), page);
 
@@ -1861,10 +1888,10 @@ ev_print_operation_print_create_custom_widget (EvPrintOperationPrint *print,
        gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
        gtk_widget_show (label);
 
-       print->scale_combo = gtk_combo_box_new_text ();
-       gtk_combo_box_append_text (GTK_COMBO_BOX (print->scale_combo), _("None"));
-       gtk_combo_box_append_text (GTK_COMBO_BOX (print->scale_combo), _("Shrink to Printable Area"));
-       gtk_combo_box_append_text (GTK_COMBO_BOX (print->scale_combo), _("Fit to Printable Area"));
+       print->scale_combo = gtk_combo_box_text_new ();
+       gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (print->scale_combo), _("None"));
+       gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (print->scale_combo), _("Shrink to Printable Area"));
+       gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (print->scale_combo), _("Fit to Printable Area"));
        gtk_combo_box_set_active (GTK_COMBO_BOX (print->scale_combo), page_scale);
        gtk_widget_set_tooltip_text (print->scale_combo,
                _("Scale document pages to fit the selected printer page. Select from one of the following:\n"