forked from AuroraMiddleware/gtk
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.
This commit is contained in:
parent
915957fca3
commit
5f4915f624
@ -596,7 +596,7 @@ gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_printer_details_request (GtkPrintUnixDialog *dialog)
|
||||
disconnect_printer_details_request (GtkPrintUnixDialog *dialog, gboolean details_failed)
|
||||
{
|
||||
GtkPrintUnixDialogPrivate *priv = dialog->priv;
|
||||
|
||||
@ -606,6 +606,14 @@ disconnect_printer_details_request (GtkPrintUnixDialog *dialog)
|
||||
priv->request_details_tag);
|
||||
priv->request_details_tag = 0;
|
||||
set_busy_cursor (dialog, FALSE);
|
||||
if (details_failed)
|
||||
gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
|
||||
g_object_get_data (G_OBJECT (priv->request_details_printer),
|
||||
"gtk-print-tree-iter"),
|
||||
PRINTER_LIST_COL_STATE,
|
||||
_("Getting printer information failed"),
|
||||
-1);
|
||||
else
|
||||
gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
|
||||
g_object_get_data (G_OBJECT (priv->request_details_printer),
|
||||
"gtk-print-tree-iter"),
|
||||
@ -626,7 +634,7 @@ gtk_print_unix_dialog_finalize (GObject *object)
|
||||
GList *node;
|
||||
|
||||
unschedule_idle_mark_conflicts (dialog);
|
||||
disconnect_printer_details_request (dialog);
|
||||
disconnect_printer_details_request (dialog, FALSE);
|
||||
|
||||
if (priv->current_printer)
|
||||
{
|
||||
@ -1781,7 +1789,7 @@ printer_details_acquired (GtkPrinter *printer,
|
||||
{
|
||||
GtkPrintUnixDialogPrivate *priv = dialog->priv;
|
||||
|
||||
disconnect_printer_details_request (dialog);
|
||||
disconnect_printer_details_request (dialog, !success);
|
||||
|
||||
if (success)
|
||||
{
|
||||
@ -1809,7 +1817,7 @@ selected_printer_changed (GtkTreeSelection *selection,
|
||||
priv->waiting_for_printer = NULL;
|
||||
}
|
||||
|
||||
disconnect_printer_details_request (dialog);
|
||||
disconnect_printer_details_request (dialog, FALSE);
|
||||
|
||||
printer = NULL;
|
||||
if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
|
||||
|
@ -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,8 +2393,23 @@ 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)
|
||||
{
|
||||
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 *
|
||||
ppd_text_to_utf8 (ppd_file_t *ppd_file,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user