Index: modules/printbackends/cups/gtkprintbackendcups.c
===================================================================
--- modules/printbackends/cups/gtkprintbackendcups.c	(revision 20842)
+++ modules/printbackends/cups/gtkprintbackendcups.c	(working copy)
@@ -104,6 +104,7 @@
   char *default_printer;
   
   guint list_printers_poll;
+  guint default_printer_poll;
   guint list_printers_pending : 1;
   guint got_default_printer   : 1;
 
@@ -120,6 +121,7 @@
 static void                 gtk_print_backend_cups_finalize        (GObject                           *object);
 static void                 gtk_print_backend_cups_dispose         (GObject                           *object);
 static void                 cups_get_printer_list                  (GtkPrintBackend                   *print_backend);
+static void                 cups_get_default_printer               (GtkPrintBackendCups               *print_backend);
 static void                 cups_request_execute                   (GtkPrintBackendCups               *print_backend,
 								    GtkCupsRequest                    *request,
 								    GtkPrintCupsResponseCallbackFunc   callback,
@@ -141,7 +143,7 @@
 static GList *              cups_printer_list_papers               (GtkPrinter                        *printer);
 static GtkPageSetup *       cups_printer_get_default_page_size     (GtkPrinter                        *printer);
 static void                 cups_printer_request_details           (GtkPrinter                        *printer);
-static void                 cups_request_default_printer           (GtkPrintBackendCups               *print_backend);
+static gboolean             cups_request_default_printer           (GtkPrintBackendCups               *print_backend);
 static void                 cups_request_ppd                       (GtkPrinter                        *printer);
 static void                 cups_printer_get_hard_margins          (GtkPrinter                        *printer,
 								    double                            *top,
@@ -501,6 +503,7 @@
 gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups)
 {
   backend_cups->list_printers_poll = FALSE;  
+  backend_cups->default_printer_poll = 0;
   backend_cups->got_default_printer = FALSE;  
   backend_cups->list_printers_pending = FALSE;
 
@@ -509,7 +512,7 @@
   backend_cups->default_cover_after = NULL;
   backend_cups->number_of_covers = 0;
 
-  cups_request_default_printer (backend_cups);
+  cups_get_default_printer (backend_cups);
 }
 
 static void
@@ -547,6 +550,10 @@
   if (backend_cups->list_printers_poll > 0)
     g_source_remove (backend_cups->list_printers_poll);
   backend_cups->list_printers_poll = 0;
+
+  if (backend_cups->default_printer_poll > 0)
+    g_source_remove (backend_cups->default_printer_poll);
+  backend_cups->default_printer_poll = 0;
   
   backend_parent_class->dispose (object);
 }
@@ -1806,7 +1813,31 @@
   return num_options;
 }
 
+/* This function requests default printer from a CUPS server in regular intervals.
+ * In the case of unreachable CUPS server the request is repeated later.
+ * The default printer is not requested in the case of previous success.
+*/
 static void
+cups_get_default_printer (GtkPrintBackendCups *backend)
+{
+  GtkPrintBackendCups *cups_backend;
+
+  cups_backend = backend;
+
+  if (cups_backend->default_printer_poll == 0)
+    {
+      if (cups_request_default_printer (cups_backend))
+        {
+          cups_backend->default_printer_poll = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT - 1,
+                                                                             10000,
+                                                                             (GSourceFunc) cups_request_default_printer,
+                                                                             backend,
+                                                                             NULL);
+        }
+    }
+}
+
+static void
 cups_request_default_printer_cb (GtkPrintBackendCups *print_backend,
 				 GtkCupsResult       *result,
 				 gpointer             user_data)
@@ -1814,6 +1845,8 @@
   ipp_t *response;
   ipp_attribute_t *attr;
 
+  GDK_THREADS_ENTER ();
+
   response = gtk_cups_result_get_response (result);
   
   if ((attr = ippFindAttribute (response, "printer-name", IPP_TAG_NAME)) != NULL)
@@ -1826,9 +1859,11 @@
    */
   if (print_backend->list_printers_poll != 0)
     cups_request_printer_list (print_backend);
+
+  GDK_THREADS_LEAVE ();
 }
 
-static void
+static gboolean
 cups_request_default_printer (GtkPrintBackendCups *print_backend)
 {
   GtkCupsRequest *request;
@@ -1839,14 +1874,14 @@
     {
       print_backend->default_printer = g_strdup (str);
       print_backend->got_default_printer = TRUE;
-      return;
+      return FALSE;
     }
   else if ((str = g_getenv ("PRINTER")) != NULL &&
 	   strcmp (str, "lp") != 0)
     {
       print_backend->default_printer = g_strdup (str);
       print_backend->got_default_printer = TRUE;
-      return;
+      return FALSE;
     }
   
   /* Figure out user setting for default printer */  
@@ -1855,7 +1890,7 @@
     {
        print_backend->default_printer = name;
        print_backend->got_default_printer = TRUE;
-       return;
+       return FALSE;
     }
 
   request = gtk_cups_request_new (NULL,
@@ -1864,12 +1899,24 @@
 				  NULL,
 				  NULL,
 				  NULL);
+
+  /* A test whether it is possible to connect to a CUPS server.
+   * If the connection fails then we return TRUE to repeat calling
+   * of this function later.
+   */
+  if (request->http == NULL)
+    {
+      gtk_cups_request_free (request);
+      return TRUE;
+    }
   
   cups_request_execute (print_backend,
                         request,
                         (GtkPrintCupsResponseCallbackFunc) cups_request_default_printer_cb,
 		        g_object_ref (print_backend),
 		        g_object_unref);
+
+  return FALSE;
 }
 
 static void
