[gtk+] Add CUPS events as soon as possible when printing



commit 3b336186ee4d55799f4290c672d6bccd787c70fa
Author: Marek Kasik <mkasik redhat com>
Date:   Sat Aug 29 21:32:01 2009 -0400

    Add CUPS events as soon as possible when printing
    
    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 |   46 +++++++++++++++-------
 1 files changed, 31 insertions(+), 15 deletions(-)
---
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
index f84c920..e930980 100644
--- a/modules/printbackends/cups/gtkprintbackendcups.c
+++ b/modules/printbackends/cups/gtkprintbackendcups.c
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]