print: stop waiting for printers after five seconds
A print server that never answered blocked the print dialog forever.
This commit is contained in:
parent
ace34b5212
commit
d83328cd72
1 changed files with 44 additions and 1 deletions
|
|
@ -1068,8 +1068,19 @@ typedef struct
|
|||
gpointer data;
|
||||
GDestroyNotify destroy;
|
||||
GMainLoop *loop;
|
||||
guint timeout_id;
|
||||
} PrinterList;
|
||||
|
||||
/* A printing system that takes connections and then never answers (a hung
|
||||
* cupsd, a print server gone away behind a firewall) never says its list
|
||||
* is complete, and a caller waiting for the list (Firefox and Pale Moon do
|
||||
* before every print dialog) waited forever. Waiting ends after this many
|
||||
* seconds without news from any backend; the printers known by then are
|
||||
* the list. */
|
||||
#define ENUMERATE_WAIT_SECONDS 5
|
||||
|
||||
static void list_progress (PrinterList *printer_list);
|
||||
|
||||
static void list_done_cb (GtkPrintBackend *backend,
|
||||
PrinterList *printer_list);
|
||||
|
||||
|
|
@ -1090,6 +1101,9 @@ stop_enumeration (PrinterList *printer_list)
|
|||
static void
|
||||
free_printer_list (PrinterList *printer_list)
|
||||
{
|
||||
if (printer_list->timeout_id)
|
||||
g_source_remove (printer_list->timeout_id);
|
||||
|
||||
if (printer_list->destroy)
|
||||
printer_list->destroy (printer_list->data);
|
||||
|
||||
|
|
@ -1113,9 +1127,34 @@ list_added_cb (GtkPrintBackend *backend,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
list_progress (printer_list);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
list_wait_timeout (gpointer data)
|
||||
{
|
||||
PrinterList *printer_list = data;
|
||||
|
||||
printer_list->timeout_id = 0;
|
||||
stop_enumeration (printer_list);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* news from a backend: waiting goes on */
|
||||
static void
|
||||
list_progress (PrinterList *printer_list)
|
||||
{
|
||||
if (printer_list->timeout_id)
|
||||
{
|
||||
g_source_remove (printer_list->timeout_id);
|
||||
printer_list->timeout_id =
|
||||
gdk_threads_add_timeout_seconds (ENUMERATE_WAIT_SECONDS,
|
||||
list_wait_timeout, printer_list);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
backend_status_changed (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
|
|
@ -1157,7 +1196,8 @@ list_done_cb (GtkPrintBackend *backend,
|
|||
g_signal_handlers_disconnect_by_func (backend, list_done_cb, printer_list);
|
||||
g_signal_handlers_disconnect_by_func (backend, backend_status_changed, printer_list);
|
||||
|
||||
list_printers_remove_backend(printer_list, backend);
|
||||
if (!list_printers_remove_backend (printer_list, backend))
|
||||
list_progress (printer_list);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -1253,6 +1293,9 @@ gtk_enumerate_printers (GtkPrinterFunc func,
|
|||
if (wait && printer_list->backends)
|
||||
{
|
||||
printer_list->loop = g_main_loop_new (NULL, FALSE);
|
||||
printer_list->timeout_id =
|
||||
gdk_threads_add_timeout_seconds (ENUMERATE_WAIT_SECONDS,
|
||||
list_wait_timeout, printer_list);
|
||||
|
||||
GDK_THREADS_LEAVE ();
|
||||
g_main_loop_run (printer_list->loop);
|
||||
|
|
|
|||
Loading…
Reference in a new issue