]> Pileus Git - ~andy/gtk/commitdiff
Add CUPS events as soon as possible when printing
authorMarek Kasik <mkasik@redhat.com>
Sun, 30 Aug 2009 01:32:01 +0000 (21:32 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 30 Aug 2009 01:32:01 +0000 (21:32 -0400)
CUPS events are added in prepare part of the main loop. These
events are initialized before their addition (#434318, #586466).

modules/printbackends/cups/gtkprintbackendcups.c

index f84c920c17d2a0ba99de5aa0d8cb263fccd34892..e930980cff9ed42b19973107fd7cc42f08f7e173 100644 (file)
@@ -803,15 +803,11 @@ request_password (gpointer data)
   return FALSE;
 }
 
-static gboolean
-cups_dispatch_watch_check (GSource *source)
+static void
+cups_dispatch_add_poll (GSource *source)
 {
   GtkPrintCupsDispatchWatch *dispatch;
   GtkCupsPollState poll_state;
-  gboolean result;
-
-  GTK_NOTE (PRINTING,
-            g_print ("CUPS Backend: %s <source %p>\n", G_STRFUNC, source)); 
 
   dispatch = (GtkPrintCupsDispatchWatch *) source;
 
@@ -820,26 +816,41 @@ cups_dispatch_watch_check (GSource *source)
   if (dispatch->request->http != NULL)
     {
       if (dispatch->data_poll == NULL)
-       {
+        {
          dispatch->data_poll = g_new0 (GPollFD, 1);
-         g_source_add_poll (source, dispatch->data_poll);
-       }
-      else
-       {
+
          if (poll_state == GTK_CUPS_HTTP_READ)
            dispatch->data_poll->events = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI;
          else if (poll_state == GTK_CUPS_HTTP_WRITE)
            dispatch->data_poll->events = G_IO_OUT | G_IO_ERR;
          else
            dispatch->data_poll->events = 0;
-       }
 
 #ifdef HAVE_CUPS_API_1_2
-      dispatch->data_poll->fd = httpGetFd (dispatch->request->http);
+          dispatch->data_poll->fd = httpGetFd (dispatch->request->http);
 #else
-      dispatch->data_poll->fd = dispatch->request->http->fd;
+          dispatch->data_poll->fd = dispatch->request->http->fd;
 #endif
+          g_source_add_poll (source, dispatch->data_poll);
+        }
     }
+}
+
+static gboolean
+cups_dispatch_watch_check (GSource *source)
+{
+  GtkPrintCupsDispatchWatch *dispatch;
+  GtkCupsPollState poll_state;
+  gboolean result;
+
+  GTK_NOTE (PRINTING,
+            g_print ("CUPS Backend: %s <source %p>\n", G_STRFUNC, source)); 
+
+  dispatch = (GtkPrintCupsDispatchWatch *) source;
+
+  poll_state = gtk_cups_request_get_poll_state (dispatch->request);
+
+  cups_dispatch_add_poll (source);
     
   if (poll_state != GTK_CUPS_HTTP_IDLE && !dispatch->request->need_password)
     if (!(dispatch->data_poll->revents & dispatch->data_poll->events)) 
@@ -868,6 +879,7 @@ cups_dispatch_watch_prepare (GSource *source,
                             gint    *timeout_)
 {
   GtkPrintCupsDispatchWatch *dispatch;
+  gboolean result;
 
   dispatch = (GtkPrintCupsDispatchWatch *) source;
 
@@ -876,7 +888,11 @@ cups_dispatch_watch_prepare (GSource *source,
 
   *timeout_ = -1;
   
-  return gtk_cups_request_read_write (dispatch->request);
+  result = gtk_cups_request_read_write (dispatch->request);
+
+  cups_dispatch_add_poll (source);
+
+  return result;
 }
 
 static gboolean