Re: Gtk Printing and gtk_dialog_run



I made an attempt to implement async functions today, patch attached.
They have only been very lightly tested. The patch adds two new functions:

void gtk_print_operation_run_async  (GtkPrintOperation  *op,
                                                     GtkWindow        *parent);
void gtk_print_run_page_setup_dialog_async  (GtkWindow        *parent,
                                                                 
GtkPageSetup    *page_setup,
                                                                 
GtkPrintSettings *settings,
                                                                 
GFunc                done_cb,
                                                                 
gpointer              data);

Both functions work on Unix by showing a modal dialog, connecting a
handler for the response signal, and then returning. Note that the async version
of gtk_print_operation_run() looses both the result that is returned, and the
error parameter. I think the return value can be substituted by storing the
print settings in the begin-print (or end-print) handler.

On windows, both functions work in the same way as their non-async variants.

Matthias
? gtk/.foo.c.swp
? gtk/LOG
? gtk/async.patch
? gtk/attachment.cgi?id=62519
? gtk/foo
? gtk/foo.c
? gtk/foo.out
? gtk/foo2
? gtk/foo2.out
? gtk/gen-paper-names
? gtk/gtk.def
? gtk/gtkprintoperation.c.1
? gtk/gtkrichtext.c
? gtk/gtkrichtext.h
? gtk/out
Index: tests/print-editor.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/Attic/print-editor.c,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 print-editor.c
--- tests/print-editor.c	7 Apr 2006 13:22:38 -0000	1.1.2.3
+++ tests/print-editor.c	21 Apr 2006 03:28:23 -0000
@@ -363,20 +363,41 @@ draw_page (GtkPrintOperation *operation,
 }
 
 static void
-do_page_setup (GtkAction *action)
+end_print (GtkPrintOperation *operation,
+	   GtkPrintContext *context,
+	   PrintData *print_data)
 {
-  GtkPageSetup *new_page_setup;
+  if (settings != NULL)
+    g_object_unref (settings);
+  settings = g_object_ref (gtk_print_operation_get_print_settings (operation));
 
-  if (settings == NULL)
-    settings = gtk_print_settings_new ();
-  
-  new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window),
-						    page_setup, settings);
+  g_free (print_data->text);
+  g_free (print_data);
+}
+
+static void
+page_setup_done (gpointer data,
+                 gpointer user_data)
+{
+  GtkPageSetup *ps = data;
 
   if (page_setup)
     g_object_unref (page_setup);
   
-  page_setup = new_page_setup;
+  page_setup = ps;
+}
+
+static void
+do_page_setup (GtkAction *action)
+{
+  if (settings == NULL)
+    settings = gtk_print_settings_new ();
+  
+  gtk_print_run_page_setup_dialog_async (GTK_WINDOW (main_window),
+				         page_setup, 
+                                         settings,
+                                         page_setup_done, 
+                                         NULL);
 }
 
 static void
@@ -394,16 +415,14 @@ status_changed_cb (GtkPrintOperation *op
 static void
 do_print (GtkAction *action)
 {
-  GtkWidget *error_dialog;
   GtkPrintOperation *print;
-  PrintData print_data;
-  GtkPrintOperationResult res;
-  GError *error;
+  PrintData *print_data;
 
-  print_data.text = get_text ();
+  print_data = g_new0  (PrintData, 1);
 
-  print = gtk_print_operation_new ();
+  print_data->text = get_text ();
 
+  print = gtk_print_operation_new ();
   
   if (settings != NULL)
     gtk_print_operation_set_print_settings (print, settings);
@@ -411,41 +430,19 @@ do_print (GtkAction *action)
   if (page_setup != NULL)
     gtk_print_operation_set_default_page_setup (print, page_setup);
   
-  g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), &print_data);
-  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), &print_data);
+  g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), print_data);
+  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), print_data);
+  g_signal_connect (print, "end_print", G_CALLBACK (end_print), print_data);
 
-  error = NULL;
-  res = gtk_print_operation_run (print, GTK_WINDOW (main_window), &error);
+  gtk_print_operation_run_async (print, GTK_WINDOW (main_window));
 
-  if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
-    {
-      error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
-					     GTK_DIALOG_DESTROY_WITH_PARENT,
-					     GTK_MESSAGE_ERROR,
-					     GTK_BUTTONS_CLOSE,
-					     "Error printing file:\n%s",
-					     error->message);
-      g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
-      gtk_widget_show (error_dialog);
-      g_error_free (error);
-    }
-  else if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
-    {
-      if (settings != NULL)
-	g_object_unref (settings);
-      settings = g_object_ref (gtk_print_operation_get_print_settings (print));
-    }
+  g_object_ref (print);
+  active_prints = g_list_append (active_prints, print);
+  update_statusbar ();
 
-  if (!gtk_print_operation_is_finished (print))
-    {
-      g_object_ref (print);
-      active_prints = g_list_append (active_prints, print);
-      update_statusbar ();
-      
-      /* This ref is unref:ed when we get the final state change */
-      g_signal_connect (print, "status_changed",
-			G_CALLBACK (status_changed_cb), NULL);
-    }
+  /* This ref is unref:ed when we get the final state change */
+  g_signal_connect (print, "status_changed",
+	            G_CALLBACK (status_changed_cb), NULL);
   
   g_object_unref (print);
 }
Index: gtk/gtkpagesetupunixdialog.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Attic/gtkpagesetupunixdialog.c,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 gtkpagesetupunixdialog.c
--- gtk/gtkpagesetupunixdialog.c	5 Apr 2006 11:00:29 -0000	1.1.2.10
+++ gtk/gtkpagesetupunixdialog.c	21 Apr 2006 03:28:24 -0000
@@ -1208,8 +1208,6 @@ gtk_page_setup_unix_dialog_get_page_setu
   GtkPageSetup *page_setup;
   
   page_setup = get_current_page_setup (dialog);
-  if (page_setup == NULL)
-    page_setup = gtk_page_setup_new ();
 
   gtk_page_setup_set_orientation (page_setup, get_orientation (dialog));
 
Index: gtk/gtkprintoperation-private.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Attic/gtkprintoperation-private.h,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 gtkprintoperation-private.h
--- gtk/gtkprintoperation-private.h	10 Apr 2006 11:33:28 -0000	1.1.2.5
+++ gtk/gtkprintoperation-private.h	21 Apr 2006 03:28:24 -0000
@@ -69,6 +69,9 @@ GtkPrintOperationResult _gtk_print_opera
 									  GtkWindow *parent,
 									  gboolean *do_print,
 									  GError **error);
+void _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
+							     GtkWindow         *parent,
+							     GFunc              print_cb);
 
 void _gtk_print_operation_set_status (GtkPrintOperation *op,
 				      GtkPrintStatus status,
Index: gtk/gtkprintoperation-unix.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Attic/gtkprintoperation-unix.c,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 gtkprintoperation-unix.c
--- gtk/gtkprintoperation-unix.c	10 Apr 2006 11:33:28 -0000	1.1.2.9
+++ gtk/gtkprintoperation-unix.c	21 Apr 2006 03:28:24 -0000
@@ -29,7 +29,6 @@
 #include "gtkprintoperation-private.h"
 #include "gtkmarshal.h"
 #include "gtkmessagedialog.h"
-
 #include "gtkprintunixdialog.h"
 #include "gtkpagesetupunixdialog.h"
 #include "gtkprintbackend.h"
@@ -40,20 +39,20 @@
 typedef struct {
   GtkPrintJob *job;         /* the job we are sending to the printer */
   gulong job_status_changed_tag;
-  GtkWindow *parent;        /* parent window just in case we need to throw error dialogs */
+  GtkWindow *parent;        /* just in case we need to throw error dialogs */
 } GtkPrintOperationUnix;
 
 static void
 unix_start_page (GtkPrintOperation *op,
-		 GtkPrintContext *print_context,
-		 GtkPageSetup *page_setup)
+		 GtkPrintContext   *print_context,
+		 GtkPageSetup      *page_setup)
 {
 
 }
 
 static void
 unix_end_page (GtkPrintOperation *op,
-	       GtkPrintContext *print_context)
+	       GtkPrintContext   *print_context)
 {
   cairo_t *cr;
 
@@ -76,8 +75,8 @@ op_unix_free (GtkPrintOperationUnix *op_
 
 static void
 unix_finish_send  (GtkPrintJob *job,
-                   void *user_data, 
-                   GError *error)
+                   void        *user_data, 
+                   GError      *error)
 {
   GtkPrintOperationUnix *op_unix;
   GtkWindow *parent;
@@ -114,52 +113,74 @@ unix_end_run (GtkPrintOperation *op)
 }
 
 static void
-job_status_changed_cb (GtkPrintJob *job, GtkPrintOperation *op)
+job_status_changed_cb (GtkPrintJob       *job, 
+                       GtkPrintOperation *op)
 {
   _gtk_print_operation_set_status (op, gtk_print_job_get_status (job), NULL);
 }
 
-GtkPrintOperationResult
-_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
-						  GtkWindow *parent,
-						  gboolean *do_print,
-						  GError **error)
+static GtkWidget *
+get_print_dialog (GtkPrintOperation *op,
+                  GtkWindow         *parent)
 {
   GtkWidget *pd;
-  GtkPrintOperationResult result;
   GtkPageSetup *page_setup;
-  
-  result = GTK_PRINT_OPERATION_RESULT_CANCEL;
+
+  pd = gtk_print_unix_dialog_new (NULL, parent);
+
+  if (op->priv->print_settings)
+    gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd),
+					op->priv->print_settings);
 
   if (op->priv->default_page_setup)
     page_setup = gtk_page_setup_copy (op->priv->default_page_setup);
   else
     page_setup = gtk_page_setup_new ();
 
-  pd = gtk_print_unix_dialog_new (NULL, parent);
+  gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd), 
+                                        page_setup);
 
-  if (op->priv->print_settings)
-    gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd),
-					op->priv->print_settings);
+  g_object_unref (page_setup);
 
-  gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd), page_setup);
-  
-  *do_print = FALSE; 
-  if (gtk_dialog_run (GTK_DIALOG (pd)) == GTK_RESPONSE_OK)
+  return pd;
+}
+
+typedef struct {
+  GtkPrintOperation      *op;
+  gboolean                do_print;
+  GError                **error;
+  GtkPrintOperationResult result;
+  GFunc                   print_cb;
+  GDestroyNotify          destroy;
+} PrintResponseData;
+
+static void
+handle_print_response (GtkDialog *dialog,
+		       gint       response,
+		       gpointer   data)
+{
+  GtkPrintUnixDialog *pd = GTK_PRINT_UNIX_DIALOG (dialog);
+  PrintResponseData *rdata = data;
+  GtkPrintOperation *op = rdata->op;
+
+  if (response == GTK_RESPONSE_OK)
     {
       GtkPrintOperationUnix *op_unix;
       GtkPrinter *printer;
       GtkPrintSettings *settings;
+      GtkPageSetup *page_setup;
 
-      result = GTK_PRINT_OPERATION_RESULT_APPLY;
+      rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY;
       
       printer = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (pd));
       if (printer == NULL)
 	goto out;
       
-      *do_print = TRUE;
+      rdata->do_print = TRUE;
 
       settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (pd));
+      page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (pd));
+
       gtk_print_operation_set_print_settings (op, settings);
 
       op_unix = g_new0 (GtkPrintOperationUnix, 1);
@@ -169,21 +190,22 @@ _gtk_print_operation_platform_backend_ru
 					page_setup);
       g_object_unref (settings);
 
-      op->priv->surface = gtk_print_job_get_surface (op_unix->job, error);
+      rdata->op->priv->surface = gtk_print_job_get_surface (op_unix->job, 
+                                                            rdata->error);
       if (op->priv->surface == NULL)
         {
-	  *do_print = FALSE;
+	  rdata->do_print = FALSE;
 	  op_unix_free (op_unix);
-	  result = GTK_PRINT_OPERATION_RESULT_ERROR;
+	  rdata->result = GTK_PRINT_OPERATION_RESULT_ERROR;
 	  goto out;
 	}
 
       _gtk_print_operation_set_status (op, gtk_print_job_get_status (op_unix->job), NULL);
       op_unix->job_status_changed_tag =
-	g_signal_connect (op_unix->job, "status_changed",
+	g_signal_connect (op_unix->job, "status-changed",
 			  G_CALLBACK (job_status_changed_cb), op);
       
-      op_unix->parent = parent;
+      op_unix->parent = gtk_window_get_transient_for (GTK_WINDOW (pd));
 
       op->priv->dpi_x = 72;
       op->priv->dpi_y = 72;
@@ -201,41 +223,177 @@ _gtk_print_operation_platform_backend_ru
       op->priv->manual_page_set = op_unix->job->page_set;
       op->priv->manual_scale = op_unix->job->scale;
       op->priv->manual_orientation = op_unix->job->rotate_to_orientation;
-    } 
+    }
 
   op->priv->start_page = unix_start_page;
   op->priv->end_page = unix_end_page;
   op->priv->end_run = unix_end_run;
 
  out:
-  g_object_unref (page_setup); 
+  gtk_widget_destroy (GTK_WIDGET (pd));
+
+  if (rdata->print_cb)
+    {
+      if (rdata->do_print)
+        rdata->print_cb (op, NULL); 
+      else
+       _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL); 
+    }
+
+  if (rdata->destroy)
+    rdata->destroy (rdata);
+}
+
+static void
+print_response_data_free (gpointer data)
+{
+  PrintResponseData *rdata = data;
+
+  g_object_unref (rdata->op);
+  g_free (rdata);
+}
+
+void
+_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
+                                                        GtkWindow         *parent,
+							GFunc              print_cb)
+{
+  GtkWidget *pd;
+  PrintResponseData *rdata;
   
-  gtk_widget_destroy (pd);
+  rdata = g_new (PrintResponseData, 1);
+  rdata->op = g_object_ref (op);
+  rdata->do_print = FALSE;
+  rdata->result = GTK_PRINT_OPERATION_RESULT_CANCEL;
+  rdata->error = NULL;
+  rdata->print_cb = print_cb;
+  rdata->destroy = print_response_data_free;
+  
+  pd = get_print_dialog (op, parent);
+  gtk_window_set_modal (GTK_WINDOW (pd), TRUE);
+
+  g_signal_connect (pd, "response", 
+		    G_CALLBACK (handle_print_response), rdata);
 
-  return result;
+  gtk_window_present (GTK_WINDOW (pd));
 }
 
-GtkPageSetup *
-gtk_print_run_page_setup_dialog (GtkWindow        *parent,
-				 GtkPageSetup     *page_setup,
-				 GtkPrintSettings *settings)
+GtkPrintOperationResult
+_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
+						  GtkWindow         *parent,
+						  gboolean          *do_print,
+						  GError           **error)
 {
-  GtkWidget *dialog;
-  GtkPageSetup *new_page_setup;
+  GtkWidget *pd;
+  PrintResponseData rdata;
+  gint response;  
   
+  rdata.op = op;
+  rdata.do_print = FALSE;
+  rdata.result = GTK_PRINT_OPERATION_RESULT_CANCEL;
+  rdata.error = error;
+  rdata.print_cb = NULL;
+  rdata.destroy = NULL;
+
+  pd = get_print_dialog (op, parent);
+
+  response = gtk_dialog_run (GTK_DIALOG (pd));
+  handle_print_response (GTK_DIALOG (pd), response, &rdata);
+
+  *do_print = rdata.do_print;
+
+  return rdata.result;
+}
+
+typedef struct {
+  GtkPageSetup  *page_setup;
+  GFunc          done_cb;
+  gpointer       data;
+  GDestroyNotify destroy;
+} PageSetupResponseData;
+
+static void
+handle_page_setup_response (GtkDialog *dialog,
+			    gint       response,
+			    gpointer   data)
+{
+  GtkPageSetupUnixDialog *psd;
+  PageSetupResponseData *rdata = data;
+
+  psd = GTK_PAGE_SETUP_UNIX_DIALOG (dialog);
+  rdata->page_setup = gtk_page_setup_unix_dialog_get_page_setup (psd);
+
+  gtk_widget_destroy (dialog);
+
+  if (rdata->done_cb)
+    rdata->done_cb (rdata->page_setup, rdata->data);
+
+  if (rdata->destroy)
+    rdata->destroy (rdata);
+}
+
+static GtkWidget *
+get_page_setup_dialog (GtkWindow        *parent,
+		       GtkPageSetup     *page_setup,
+		       GtkPrintSettings *settings)
+{
+  GtkWidget *dialog;
+
   dialog = gtk_page_setup_unix_dialog_new (NULL, parent);
   if (page_setup)
     gtk_page_setup_unix_dialog_set_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog),
 					       page_setup);
   gtk_page_setup_unix_dialog_set_print_settings (GTK_PAGE_SETUP_UNIX_DIALOG (dialog),
 						 settings);
-  gtk_dialog_run (GTK_DIALOG (dialog));
+  
+  return dialog;
+}
+
+GtkPageSetup *
+gtk_print_run_page_setup_dialog (GtkWindow        *parent,
+				 GtkPageSetup     *page_setup,
+				 GtkPrintSettings *settings)
+{
+  GtkWidget *dialog;
+  gint response;
+  PageSetupResponseData rdata;  
+  
+  rdata.page_setup = NULL;
+  rdata.done_cb = NULL;
+  rdata.data = NULL;
+  rdata.destroy = NULL;
+
+  dialog = get_page_setup_dialog (parent, page_setup, settings);
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+  handle_page_setup_response (dialog, response, &rdata);
 
-  new_page_setup = gtk_page_setup_unix_dialog_get_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog));
+  return rdata.page_setup;
+}
 
-  gtk_widget_destroy (dialog);
+void
+gtk_print_run_page_setup_dialog_async (GtkWindow        *parent,
+				       GtkPageSetup     *page_setup,
+				       GtkPrintSettings *settings,
+				       GFunc             done_cb,
+				       gpointer          data)
+{
+  GtkWidget *dialog;
+  GtkPageSetup *new_page_setup;
+  PageSetupResponseData *rdata;
+  
+  dialog = get_page_setup_dialog (parent, page_setup, settings);
+  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+  
+  rdata = g_new (PageSetupResponseData, 1);
+  rdata->page_setup = NULL;
+  rdata->done_cb = done_cb;
+  rdata->data = data;
+  rdata->destroy = g_free;
+
+  g_signal_connect (dialog, "response",
+		    G_CALLBACK (handle_page_setup_response), rdata);
 
-  return new_page_setup;
+  gtk_window_present (GTK_WINDOW (dialog));
 }
 
 
Index: gtk/gtkprintoperation-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Attic/gtkprintoperation-win32.c,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 gtkprintoperation-win32.c
--- gtk/gtkprintoperation-win32.c	11 Apr 2006 16:06:06 -0000	1.1.2.9
+++ gtk/gtkprintoperation-win32.c	21 Apr 2006 03:28:24 -0000
@@ -1465,6 +1465,20 @@ _gtk_print_operation_platform_backend_ru
   return result;
 }
 
+void 
+_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
+                                                        GtkWindow         *parent,
+							GFunc              print_cb)
+{
+  gboolean do_print;
+
+  _gtk_print_operation_platform_backend_run_dialog (op, parent, &do_print, NULL);
+  if (do_print)
+    print_cb (op);
+  else
+    _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
+}
+
 GtkPageSetup *
 gtk_print_run_page_setup_dialog (GtkWindow        *parent,
 				 GtkPageSetup     *page_setup,
@@ -1595,4 +1609,17 @@ gtk_print_run_page_setup_dialog (GtkWind
     }
   
   return page_setup;
+}
+
+void
+gtk_print_run_page_setup_dialog_async (GtkWindow        *parent,
+				       GtkPageSetup     *page_setup,
+				       GtkPrintSettings *settings,
+				       GFunc             done_cb,
+				       gpointer          data)
+{
+  GtkPageSetup *page_setup;
+
+  page_setup = gtk_print_run_page_setup_dialog (parent, page_setup, settings);
+  done_cb (page_setup, data);
 }
Index: gtk/gtkprintoperation.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Attic/gtkprintoperation.c,v
retrieving revision 1.1.2.13
diff -u -p -r1.1.2.13 gtkprintoperation.c
--- gtk/gtkprintoperation.c	20 Apr 2006 19:44:18 -0000	1.1.2.13
+++ gtk/gtkprintoperation.c	21 Apr 2006 03:28:24 -0000
@@ -950,84 +950,19 @@ run_pdf (GtkPrintOperation  *op,
   return GTK_PRINT_OPERATION_RESULT_APPLY; 
 }
 
-static GtkPrintOperationResult
-run_print_dialog (GtkPrintOperation  *op,
-		  GtkWindow          *parent,
-		  gboolean           *do_print,
-		  GError            **error)
-{
-  if (op->priv->pdf_target != NULL)
-    return run_pdf (op, parent, do_print, error);
-
-  /* This does:
-   * Open print dialog 
-   * set print settings on dialog
-   * run dialog, if show_dialog set
-   * extract print settings from dialog
-   * create cairo surface and data for print job
-   * return correct result val
-   */
-  return _gtk_print_operation_platform_backend_run_dialog (op, 
-							   parent,
-							   do_print,
-							   error);
-}
-
-/**
- * gtk_print_operation_run:
- * @op: a #GtkPrintOperation
- * @parent: Transient parent of the dialog, or %NULL
- * @error: Return location for errors, or %NULL
- * 
- * Runs the print operation, by first letting the user modify
- * print settings in the print dialog, and then print the
- * document.
- *
- * Note that this function does not return until the rendering
- * of all pages is complete. You can connect to the ::status-changed
- * signal on @op to obtain some information about the progress
- * of the print operation.
- * 
- * <informalexample><programlisting>
- *  FIXME: need an example here
- * </programlisting></informalexample>
- *
- * Return value: the result of the print operation. A return value
- *   of %GTK_PRINT_OPERATION_RESULT_APPLY indicates that the printing
- *   was completed successfully. In this case, it is a good idea
- *   to obtain the used print settings with 
- *   gtk_print_operation_get_print_settings() and store them for
- *   reuse with the next print operation.
- *
- * Since: 2.10
- **/
-GtkPrintOperationResult
-gtk_print_operation_run (GtkPrintOperation  *op,
-			 GtkWindow          *parent,
-			 GError            **error)
+static void
+print_pages (GtkPrintOperation *op)
 {
   int page, range;
   GtkPageSetup *initial_page_setup, *page_setup;
   GtkPrintContext *print_context;
   cairo_t *cr;
-  gboolean do_print;
   int uncollated_copies, collated_copies;
   int i, j;
   GtkPageRange *ranges;
   GtkPageRange one_range;
   int num_ranges;
-  GtkPrintOperationResult result;
-  
-  g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), 
-                        GTK_PRINT_OPERATION_RESULT_ERROR);
 
-  result = run_print_dialog (op, parent, &do_print, error);
-  if (!do_print)
-    {
-      _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
-      return result;
-    }
-  
   if (op->priv->manual_collation)
     {
       uncollated_copies = op->priv->manual_num_copies;
@@ -1047,7 +982,7 @@ gtk_print_operation_run (GtkPrintOperati
   _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_PREPARING, NULL);
   g_signal_emit (op, signals[BEGIN_PRINT], 0, print_context);
   
-  g_return_val_if_fail (op->priv->nr_of_pages > 0, GTK_PRINT_OPERATION_RESULT_ERROR);
+  g_return_if_fail (op->priv->nr_of_pages > 0);
 
   if (op->priv->print_pages == GTK_PRINT_PAGES_RANGES)
     {
@@ -1144,8 +1079,82 @@ gtk_print_operation_run (GtkPrintOperati
 
   cairo_surface_finish (op->priv->surface);
   op->priv->end_run (op);
+}
+
+/**
+ * gtk_print_operation_run:
+ * @op: a #GtkPrintOperation
+ * @parent: Transient parent of the dialog, or %NULL
+ * @error: Return location for errors, or %NULL
+ * 
+ * Runs the print operation, by first letting the user modify
+ * print settings in the print dialog, and then print the
+ * document.
+ *
+ * Note that this function does not return until the rendering
+ * of all pages is complete. You can connect to the ::status-changed
+ * signal on @op to obtain some information about the progress
+ * of the print operation.
+ * 
+ * <informalexample><programlisting>
+ *  FIXME: need an example here
+ * </programlisting></informalexample>
+ *
+ * Return value: the result of the print operation. A return value
+ *   of %GTK_PRINT_OPERATION_RESULT_APPLY indicates that the printing
+ *   was completed successfully. In this case, it is a good idea
+ *   to obtain the used print settings with 
+ *   gtk_print_operation_get_print_settings() and store them for
+ *   reuse with the next print operation.
+ *
+ * Since: 2.10
+ **/
+GtkPrintOperationResult
+gtk_print_operation_run (GtkPrintOperation  *op,
+			 GtkWindow          *parent,
+			 GError            **error)
+{
+  GtkPrintOperationResult result;
+  gboolean do_print;
+  
+  g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), 
+                        GTK_PRINT_OPERATION_RESULT_ERROR);
+
+  if (op->priv->pdf_target != NULL)
+    result = run_pdf (op, parent, &do_print, error);
+  else
+    result = _gtk_print_operation_platform_backend_run_dialog (op, 
+							       parent,
+							       &do_print,
+							       error);
+  if (do_print)
+    print_pages (op);
+  else 
+    _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
+
+  return result;
+}
+
+void
+gtk_print_operation_run_async (GtkPrintOperation *op,
+			       GtkWindow         *parent)
+{
+  gboolean do_print;
+
+  g_return_if_fail (GTK_IS_PRINT_OPERATION (op)); 
 
-  return GTK_PRINT_OPERATION_RESULT_APPLY;
+  if (op->priv->pdf_target != NULL)
+    {
+      run_pdf (op, parent, &do_print, NULL);
+      if (do_print)
+	print_pages (op);
+      else 
+	_gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
+    }
+  else
+    _gtk_print_operation_platform_backend_run_dialog_async (op, 
+							    parent,
+							    print_pages);
 }
 
 
Index: gtk/gtkprintoperation.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Attic/gtkprintoperation.h,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 gtkprintoperation.h
--- gtk/gtkprintoperation.h	20 Apr 2006 14:05:42 -0000	1.1.2.9
+++ gtk/gtkprintoperation.h	21 Apr 2006 03:28:24 -0000
@@ -131,6 +131,8 @@ void                    gtk_print_operat
 GtkPrintOperationResult gtk_print_operation_run                    (GtkPrintOperation  *op,
 								    GtkWindow          *parent,
 								    GError            **error);
+void                    gtk_print_operation_run_async              (GtkPrintOperation  *op,
+                                                                    GtkWindow          *parent);
 GtkPrintStatus          gtk_print_operation_get_status             (GtkPrintOperation  *op);
 G_CONST_RETURN gchar *  gtk_print_operation_get_status_string      (GtkPrintOperation  *op);
 gboolean                gtk_print_operation_is_finished            (GtkPrintOperation  *op);
@@ -138,6 +140,11 @@ gboolean                gtk_print_operat
 GtkPageSetup           *gtk_print_run_page_setup_dialog            (GtkWindow          *parent,
 								    GtkPageSetup       *page_setup,
 								    GtkPrintSettings   *settings);
+void                   gtk_print_run_page_setup_dialog_async       (GtkWindow          *parent,
+								    GtkPageSetup       *page_setup,
+								    GtkPrintSettings   *settings,
+                                                                    GFunc               done_cb,
+                                                                    gpointer            data);
 
 G_END_DECLS
 
Index: gtk/gtkprintsettings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Attic/gtkprintsettings.c,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 gtkprintsettings.c
--- gtk/gtkprintsettings.c	25 Mar 2006 22:02:50 -0000	1.1.2.2
+++ gtk/gtkprintsettings.c	21 Apr 2006 03:28:24 -0000
@@ -742,7 +742,7 @@ gtk_print_settings_get_print_pages (GtkP
 
 void
 gtk_print_settings_set_print_pages (GtkPrintSettings *settings,
-				    GtkPrintPages       print_pages)
+				    GtkPrintPages     print_pages)
 {
   const char *str;
 
Index: gtk/paper_names.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Attic/paper_names.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 paper_names.c
--- gtk/paper_names.c	24 Mar 2006 16:33:20 -0000	1.1.2.1
+++ gtk/paper_names.c	21 Apr 2006 03:28:25 -0000
@@ -5,6 +5,14 @@
  *
  * The PPD names come from the PPD specification.
  */
+typedef struct
+{
+  const char *name;
+  const char *size;
+  const char *display_name;
+  const char *ppd_name;
+} PaperInfo;
+
 
 static const PaperInfo standard_names[] = {
   /* sorted by name, remember to sort when changing */


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