]> www.fi.muni.cz Git - evince.git/commitdiff
Fixes bug #437681 - blocks while enumerating printers.
authorChristian Persch <chpe@gnome.org>
Sun, 29 Jul 2007 13:08:25 +0000 (13:08 +0000)
committerNickolay V. Shmyrev <nshmyrev@src.gnome.org>
Sun, 29 Jul 2007 13:08:25 +0000 (13:08 +0000)
2007-07-29  Christian Persch  <chpe@gnome.org>

* shell/ev-window.c: (ev_window_enumerate_printer_cb),
(ev_window_preview_print_finished), (ev_window_do_preview_print),
(ev_window_cmd_preview_print):

Fixes bug #437681 - blocks while enumerating printers.

svn path=/trunk/; revision=2588

ChangeLog
shell/ev-window.c

index 14f674600faa0c6b001f1dd9570fd879ee4df9fe..100b1744b397f96d3ac120faf07ea9a69b952a37 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-07-29  Christian Persch  <chpe@gnome.org>
+
+       * shell/ev-window.c: (ev_window_enumerate_printer_cb),
+       (ev_window_preview_print_finished), (ev_window_do_preview_print),
+       (ev_window_cmd_preview_print):
+       
+       Fixes bug #437681 - blocks while enumerating printers.
+
 2007-07-29  Christian Persch  <chpe@gnome.org>
 
        * shell/ev-window.c: (ev_window_screen_changed):
index 6a03b75d1fe37608bcd9feb941bc65dbd35bd41c..f5a7bf4eed95c0549794a8824eb5de2d8d3f7287 100644 (file)
@@ -3326,25 +3326,30 @@ ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
 }
 
 #ifdef WITH_GTK_PRINT
+static void ev_window_do_preview_print (EvWindow *window);
+
 static gboolean
-lookup_printer_from_name (GtkPrinter *printer,
-                         EvWindow   *window)
+ev_window_enumerate_printer_cb (GtkPrinter *printer,
+                               EvWindow   *window)
 {
+       EvWindowPrivate *priv = window->priv;
        const gchar *printer_name;
 
-       printer_name = gtk_print_settings_get_printer (window->priv->print_settings);
-       
+       printer_name = gtk_print_settings_get_printer (priv->print_settings);
        if ((printer_name
-            && g_ascii_strcasecmp (printer_name, gtk_printer_get_name (printer)) == 0) ||
+            && strcmp (printer_name, gtk_printer_get_name (printer)) == 0) ||
            (!printer_name && gtk_printer_is_default (printer))) {
-               if (window->priv->printer)
-                       g_object_unref (window->priv->printer);
-               window->priv->printer = g_object_ref (printer);
+               if (priv->printer)
+                       g_object_unref (priv->printer);
+               priv->printer = g_object_ref (printer);
 
-               return TRUE;
+               /* Now that we have the printer, we'll start the print */
+               ev_window_do_preview_print (window);
+
+               return TRUE; /* we're done */
        }
 
-       return FALSE;
+       return FALSE; /* continue the enumeration */
 }
 
 static void
@@ -3370,62 +3375,34 @@ ev_window_preview_print_finished (GtkPrintJob *print_job,
        g_object_unref (print_job);
        gtk_widget_destroy (GTK_WIDGET (window));
 }
-#endif /* WITH_GTK_PRINT */
 
 static void
-ev_window_cmd_preview_print (GtkAction *action, EvWindow *window)
+ev_window_do_preview_print (EvWindow *window)
 {
-#ifdef WITH_GTK_PRINT
-       GtkPrintSettings *print_settings = NULL;
+       EvWindowPrivate  *priv = window->priv;
        GtkPageSetup     *page_setup;
        GtkPrintJob      *job;
        gchar            *filename;
        GError           *error = NULL;
-#if GTK_CHECK_VERSION (2, 11, 0)
-       const gchar      *print_settings_file = window->priv->print_settings_file;
 
-       if (print_settings_file) {
-               if (g_file_test (print_settings_file, G_FILE_TEST_IS_REGULAR)) {
-                       GError *error = NULL;
+       g_assert (priv->print_settings != NULL);
+       g_assert (priv->printer != NULL);
 
-                       print_settings = gtk_print_settings_new_from_file (print_settings_file,
-                                                                          &error);
-                       
-                       if (error) {
-                               g_warning (error->message);
-                               g_error_free (error);
-                               print_settings = NULL;
-                       }
-               }
-       }
-#endif /* GTK 2.11.0 */
-       
-       if (!print_settings)
-               print_settings = gtk_print_settings_new ();
-
-       if (window->priv->print_settings)
-               g_object_unref (window->priv->print_settings);
-       window->priv->print_settings = print_settings;
-
-       gtk_enumerate_printers ((GtkPrinterFunc) lookup_printer_from_name,
-                               window, NULL, TRUE);
-       g_assert (GTK_IS_PRINTER (window->priv->printer));      
-       
        page_setup = gtk_page_setup_new ();
 
        job = gtk_print_job_new ("evince-print",
-                                window->priv->printer,
-                                window->priv->print_settings,
+                                priv->printer,
+                                priv->print_settings,
                                 page_setup);
 
-       g_object_unref (window->priv->print_settings);
-       window->priv->print_settings = NULL;
-       g_object_unref (window->priv->printer);
-       window->priv->printer = NULL;
+       g_object_unref (priv->print_settings);
+       priv->print_settings = NULL;
+       g_object_unref (priv->printer);
+       priv->printer = NULL;
        g_object_unref (page_setup);
 
-       filename = g_filename_from_uri (window->priv->local_uri ?
-                                       window->priv->local_uri : window->priv->uri,
+       filename = g_filename_from_uri (priv->local_uri ?
+                                       priv->local_uri : priv->uri,
                                        NULL, NULL);
 
        if (gtk_print_job_set_source_file (job, filename, &error)) {
@@ -3440,6 +3417,44 @@ ev_window_cmd_preview_print (GtkAction *action, EvWindow *window)
        g_free (filename);
 
        gtk_widget_hide (GTK_WIDGET (window));
+}
+
+#endif /* WITH_GTK_PRINT */
+
+static void
+ev_window_cmd_preview_print (GtkAction *action, EvWindow *window)
+{
+#ifdef WITH_GTK_PRINT
+       EvWindowPrivate *priv = window->priv;
+       GtkPrintSettings *print_settings = NULL;
+#if GTK_CHECK_VERSION (2, 11, 0)
+       const gchar      *print_settings_file = priv->print_settings_file;
+
+       if (print_settings_file) {
+               if (g_file_test (print_settings_file, G_FILE_TEST_IS_REGULAR)) {
+                       GError *error = NULL;
+
+                       print_settings = gtk_print_settings_new_from_file (print_settings_file,
+                                                                          &error);
+                       
+                       if (error) {
+                               g_warning (error->message);
+                               g_error_free (error);
+                               print_settings = NULL;
+                       }
+               }
+       }
+#endif /* GTK 2.11.0 */
+       
+       if (!print_settings)
+               print_settings = gtk_print_settings_new ();
+
+       if (priv->print_settings)
+               g_object_unref (priv->print_settings);
+       priv->print_settings = print_settings;
+
+       gtk_enumerate_printers ((GtkPrinterFunc) ev_window_enumerate_printer_cb,
+                               window, NULL, FALSE);
 #endif /* WITH_GTK_PRINT */
 }