From d36ca9a2c19bb21b243024e325336d9d876497e2 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sun, 29 Jul 2007 13:08:25 +0000 Subject: [PATCH] Fixes bug #437681 - blocks while enumerating printers. 2007-07-29 Christian Persch * 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 | 8 ++++ shell/ev-window.c | 115 ++++++++++++++++++++++++++-------------------- 2 files changed, 73 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14f67460..100b1744 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-07-29 Christian Persch + + * 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 * shell/ev-window.c: (ev_window_screen_changed): diff --git a/shell/ev-window.c b/shell/ev-window.c index 6a03b75d..f5a7bf4e 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -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 */ } -- 2.43.5