]> www.fi.muni.cz Git - evince.git/commitdiff
Add preview button to print dialog. Fixes bug #445419.
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 17 Jun 2007 16:20:49 +0000 (16:20 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Sun, 17 Jun 2007 16:20:49 +0000 (16:20 +0000)
2007-06-17  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-window.c: (ev_window_print_send),
(ev_window_print_dialog_response_cb), (ev_window_print_range):
Add preview button to print dialog. Fixes bug #445419.

svn path=/trunk/; revision=2507

ChangeLog
shell/ev-window.c

index 445480597db76413de54430316508fb183ae5e01..cf696752bc5720ca219fcaec7fbe48bcab91fbe0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-06-17  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-window.c: (ev_window_print_send),
+       (ev_window_print_dialog_response_cb), (ev_window_print_range):
+
+       Add preview button to print dialog. Fixes bug #445419.
+       
 2007-06-17  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/dvi/Makefile.am:
 2007-06-17  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/dvi/Makefile.am:
index 7f3a520311d4324724476999cf0ddf93e8a26338..95f5777d4e09c19336db7a164354f0c1c799980b 100644 (file)
@@ -192,6 +192,7 @@ struct _EvWindowPrivate {
 
 #ifdef WITH_GTK_PRINT
        EvJob            *print_job;
 
 #ifdef WITH_GTK_PRINT
        EvJob            *print_job;
+       gboolean          print_preview;
        GtkPrintJob      *gtk_print_job;
        GtkPrinter       *printer;
        GtkPrintSettings *print_settings;
        GtkPrintJob      *gtk_print_job;
        GtkPrinter       *printer;
        GtkPrintSettings *print_settings;
@@ -2204,13 +2205,8 @@ static void
 ev_window_print_send (EvWindow    *window,
                      const gchar *filename)
 {
 ev_window_print_send (EvWindow    *window,
                      const gchar *filename)
 {
-       GtkPrintJob *job;
        GtkPrintSettings *settings;
        GtkPrintSettings *settings;
-       GError      *error = NULL;
        
        
-       if (window->priv->gtk_print_job)
-               g_object_unref (window->priv->gtk_print_job);
-
        /* Some printers take into account some print settings,
         * and others don't. However we have exported the document
         * to a ps or pdf file according to such print settings. So,
        /* Some printers take into account some print settings,
         * and others don't. However we have exported the document
         * to a ps or pdf file according to such print settings. So,
@@ -2225,25 +2221,54 @@ ev_window_print_send (EvWindow    *window,
        gtk_print_settings_set_scale (settings, 1.0);
        gtk_print_settings_set_collate (settings, FALSE);
        gtk_print_settings_set_reverse (settings, FALSE);
        gtk_print_settings_set_scale (settings, 1.0);
        gtk_print_settings_set_collate (settings, FALSE);
        gtk_print_settings_set_reverse (settings, FALSE);
-       
-       job = gtk_print_job_new ("evince-print",
-                                window->priv->printer,
-                                settings,
-                                window->priv->print_page_setup);
 
 
-       g_object_unref (settings);
-       
-       window->priv->gtk_print_job = job;
+       if (window->priv->print_preview) {
+               gchar *uri;
+               gchar *print_settings_file = NULL;
 
 
-       if (gtk_print_job_set_source_file (job, filename, &error)) {
-               gtk_print_job_send (job,
-                                   (GtkPrintJobCompleteFunc)ev_window_print_finished,
-                                   window, NULL);
+               ev_application_set_print_settings (EV_APP,
+                                                  window->priv->print_settings);
+               
+#if GTK_CHECK_VERSION (2, 11, 0)
+               print_settings_file = ev_tmp_filename ("print-settings");
+               gtk_print_settings_to_file (settings, print_settings_file, NULL);
+#endif
+               uri = g_filename_to_uri (filename, NULL, NULL);
+               ev_application_open_uri_at_dest (EV_APP,
+                                                uri, 
+                                                gtk_window_get_screen (GTK_WINDOW (window)),
+                                                NULL,
+                                                EV_WINDOW_MODE_PREVIEW,
+                                                TRUE,
+                                                print_settings_file,
+                                                GDK_CURRENT_TIME);
+               g_free (print_settings_file);
+               g_free (uri);
        } else {
        } else {
-               ev_window_clear_print_job (window);
-               g_warning (error->message);
-               g_error_free (error);
+               GtkPrintJob *job;
+               GError      *error = NULL;
+       
+               job = gtk_print_job_new ("evince-print",
+                                        window->priv->printer,
+                                        settings,
+                                        window->priv->print_page_setup);
+
+               if (window->priv->gtk_print_job)
+                       g_object_unref (window->priv->gtk_print_job);
+               window->priv->gtk_print_job = job;
+
+               if (gtk_print_job_set_source_file (job, filename, &error)) {
+                       gtk_print_job_send (job,
+                                           (GtkPrintJobCompleteFunc)ev_window_print_finished,
+                                           window, NULL);
+               } else {
+                       ev_window_clear_print_job (window);
+                       g_warning (error->message);
+                       g_error_free (error);
+               }
        }
        }
+
+       g_object_unref (settings);
 }
 
 static void
 }
 
 static void
@@ -2279,13 +2304,15 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
        GtkPrintPages  print_pages;
        const gchar   *file_format;
        
        GtkPrintPages  print_pages;
        const gchar   *file_format;
        
-       if (response != GTK_RESPONSE_OK) {
+       if (response == GTK_RESPONSE_CANCEL) {
                gtk_widget_destroy (GTK_WIDGET (dialog));
                window->priv->print_dialog = NULL;
 
                return FALSE;
        }
 
                gtk_widget_destroy (GTK_WIDGET (dialog));
                window->priv->print_dialog = NULL;
 
                return FALSE;
        }
 
+       window->priv->print_preview = (response == GTK_RESPONSE_APPLY);
+
        if (window->priv->printer)
                g_object_unref (window->priv->printer);
        if (window->priv->print_settings)
        if (window->priv->printer)
                g_object_unref (window->priv->printer);
        if (window->priv->print_settings)
@@ -2430,7 +2457,8 @@ ev_window_print_range (EvWindow *ev_window, int first_page, int last_page)
                GTK_PRINT_CAPABILITY_COLLATE |
                GTK_PRINT_CAPABILITY_REVERSE |
                GTK_PRINT_CAPABILITY_SCALE |
                GTK_PRINT_CAPABILITY_COLLATE |
                GTK_PRINT_CAPABILITY_REVERSE |
                GTK_PRINT_CAPABILITY_SCALE |
-               GTK_PRINT_CAPABILITY_GENERATE_PS;
+               GTK_PRINT_CAPABILITY_GENERATE_PS |
+               GTK_PRINT_CAPABILITY_PREVIEW;
        
        if (EV_IS_FILE_EXPORTER (ev_window->priv->document) &&
            ev_file_exporter_format_supported (EV_FILE_EXPORTER (ev_window->priv->document),
        
        if (EV_IS_FILE_EXPORTER (ev_window->priv->document) &&
            ev_file_exporter_format_supported (EV_FILE_EXPORTER (ev_window->priv->document),