[gtk+] Don't hang print dialog when remote CUPS printer is not available
- From: Marek Kašík <mkasik src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+] Don't hang print dialog when remote CUPS printer is not available
- Date: Wed, 23 Sep 2009 12:42:32 +0000 (UTC)
commit 5f4915f62403ddb2502fa7b431a97943c9b56b88
Author: Marek Kasik <mkasik redhat com>
Date: Wed Sep 23 14:35:26 2009 +0200
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.
gtk/gtkprintunixdialog.c | 28 ++++++++-----
modules/printbackends/cups/gtkprintbackendcups.c | 47 ++++++++++++++++++++--
modules/printbackends/cups/gtkprintercups.c | 8 ++++
modules/printbackends/cups/gtkprintercups.h | 5 ++
4 files changed, 74 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index d08cdfb..5f9d8d2 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -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,12 +606,20 @@ disconnect_printer_details_request (GtkPrintUnixDialog *dialog)
priv->request_details_tag);
priv->request_details_tag = 0;
set_busy_cursor (dialog, FALSE);
- 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,
- gtk_printer_get_state_message (priv->request_details_printer),
- -1);
+ 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"),
+ PRINTER_LIST_COL_STATE,
+ gtk_printer_get_state_message (priv->request_details_printer),
+ -1);
g_object_unref (priv->request_details_printer);
priv->request_details_printer = NULL;
}
@@ -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))
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
index 92d4b9b..f13090c 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 cd27b17..22a9b01 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 cd2b318..b00d086 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]