diff options
author | Marek Kasik <mkasik@redhat.com> | 2009-09-23 14:35:26 +0200 |
---|---|---|
committer | Marek Kasik <mkasik@redhat.com> | 2009-09-23 14:35:26 +0200 |
commit | 5f4915f62403ddb2502fa7b431a97943c9b56b88 (patch) | |
tree | 802a9174e86e5e339019997f6875ece301098cc0 /modules/printbackends | |
parent | 915957fca35ead312f7327ce59a73eb301024faf (diff) | |
download | gtk+-5f4915f62403ddb2502fa7b431a97943c9b56b88.tar.gz |
Don't hang print dialog when remote CUPS printer is not available
This patch tests availability of remote host before getting ppd file
for selected printer (#586207). It also adds a state message for
failure of getting details.
Diffstat (limited to 'modules/printbackends')
-rw-r--r-- | modules/printbackends/cups/gtkprintbackendcups.c | 47 | ||||
-rw-r--r-- | modules/printbackends/cups/gtkprintercups.c | 8 | ||||
-rw-r--r-- | modules/printbackends/cups/gtkprintercups.h | 5 |
3 files changed, 56 insertions, 4 deletions
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c index 92d4b9ba65..f13090ce24 100644 --- a/modules/printbackends/cups/gtkprintbackendcups.c +++ b/modules/printbackends/cups/gtkprintbackendcups.c @@ -154,7 +154,7 @@ static GList * cups_printer_list_papers (GtkPrinter static GtkPageSetup * cups_printer_get_default_page_size (GtkPrinter *printer); static void cups_printer_request_details (GtkPrinter *printer); static gboolean cups_request_default_printer (GtkPrintBackendCups *print_backend); -static void cups_request_ppd (GtkPrinter *printer); +static gboolean cups_request_ppd (GtkPrinter *printer); static void cups_printer_get_hard_margins (GtkPrinter *printer, double *top, double *bottom, @@ -1686,6 +1686,8 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend, else g_object_ref (printer); + GTK_PRINTER_CUPS (printer)->remote = remote_printer; + gtk_printer_set_is_paused (printer, is_paused); gtk_printer_set_is_accepting_jobs (printer, is_accepting_jobs); @@ -1985,7 +1987,7 @@ done: GDK_THREADS_LEAVE (); } -static void +static gboolean cups_request_ppd (GtkPrinter *printer) { GError *error; @@ -2005,6 +2007,26 @@ cups_request_ppd (GtkPrinter *printer) GTK_NOTE (PRINTING, g_print ("CUPS Backend: %s\n", G_STRFUNC)); + if (cups_printer->remote) + { + GtkCupsConnectionState state; + + state = gtk_cups_connection_test_get_state (cups_printer->remote_cups_connection_test); + + if (state == GTK_CUPS_CONNECTION_IN_PROGRESS) + return TRUE; + + gtk_cups_connection_test_free (cups_printer->remote_cups_connection_test); + cups_printer->remote_cups_connection_test = NULL; + cups_printer->get_remote_ppd_poll = 0; + + if (state == GTK_CUPS_CONNECTION_NOT_AVAILABLE) + { + g_signal_emit_by_name (printer, "details-acquired", FALSE); + return FALSE; + } + } + http = httpConnectEncrypt (cups_printer->hostname, cups_printer->port, cupsEncryption ()); @@ -2034,7 +2056,7 @@ cups_request_ppd (GtkPrinter *printer) g_free (data); g_signal_emit_by_name (printer, "details-acquired", FALSE); - return; + return FALSE; } data->http = http; @@ -2072,6 +2094,8 @@ cups_request_ppd (GtkPrinter *printer) g_free (resource); g_free (ppd_filename); + + return FALSE; } /* Ordering matters for default preference */ @@ -2369,7 +2393,22 @@ cups_printer_request_details (GtkPrinter *printer) cups_printer = GTK_PRINTER_CUPS (printer); if (!cups_printer->reading_ppd && gtk_printer_cups_get_ppd (cups_printer) == NULL) - cups_request_ppd (printer); + { + if (cups_printer->remote) + { + if (cups_printer->get_remote_ppd_poll == 0) + { + cups_printer->remote_cups_connection_test = gtk_cups_connection_test_new (cups_printer->hostname); + + if (cups_request_ppd (printer)) + cups_printer->get_remote_ppd_poll = gdk_threads_add_timeout (200, + (GSourceFunc) cups_request_ppd, + printer); + } + } + else + cups_request_ppd (printer); + } } static char * diff --git a/modules/printbackends/cups/gtkprintercups.c b/modules/printbackends/cups/gtkprintercups.c index cd27b175ef..22a9b01f74 100644 --- a/modules/printbackends/cups/gtkprintercups.c +++ b/modules/printbackends/cups/gtkprintercups.c @@ -77,6 +77,9 @@ gtk_printer_cups_init (GtkPrinterCups *printer) printer->ppd_file = NULL; printer->default_cover_before = NULL; printer->default_cover_after = NULL; + printer->remote = FALSE; + printer->get_remote_ppd_poll = 0; + printer->remote_cups_connection_test = NULL; } static void @@ -98,6 +101,11 @@ gtk_printer_cups_finalize (GObject *object) if (printer->ppd_file) ppdClose (printer->ppd_file); + if (printer->get_remote_ppd_poll > 0) + g_source_remove (printer->get_remote_ppd_poll); + + gtk_cups_connection_test_free (printer->remote_cups_connection_test); + G_OBJECT_CLASS (gtk_printer_cups_parent_class)->finalize (object); } diff --git a/modules/printbackends/cups/gtkprintercups.h b/modules/printbackends/cups/gtkprintercups.h index cd2b318e64..b00d086c38 100644 --- a/modules/printbackends/cups/gtkprintercups.h +++ b/modules/printbackends/cups/gtkprintercups.h @@ -23,6 +23,7 @@ #include <glib-object.h> #include <cups/cups.h> #include <cups/ppd.h> +#include "gtkcupsutils.h" #include <gtk/gtkunixprint.h> @@ -55,6 +56,10 @@ struct _GtkPrinterCups gchar *default_cover_before; gchar *default_cover_after; + + gboolean remote; + guint get_remote_ppd_poll; + GtkCupsConnectionTest *remote_cups_connection_test; }; struct _GtkPrinterCupsClass |