]> Pileus Git - ~andy/gtk/commitdiff
Add a boolean show-progress property, and show a progress dialog if it is
authorMatthias Clasen <mclasen@redhat.com>
Tue, 23 May 2006 16:30:45 +0000 (16:30 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 23 May 2006 16:30:45 +0000 (16:30 +0000)
2006-05-23  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtk.symbols:
* gtk/gtkprintoperation.h:
* gtk/gtkprintoperation.c: Add a boolean show-progress
property, and show a progress dialog if it is set to TRUE.

* gtk/gtkprintoperation.c (pdf_end_run):
* gtk/gtkprintoperation-win32.c (win32_end_run):
* gtk/gtkprintoperation-unix.c (unix_end_run):
* gtk/gtkprintoperation-private.h: Add a cancelled
parameter to end_run, and call it even if the print
operation was cancelled.

ChangeLog
ChangeLog.pre-2-10
gtk/gtk.symbols
gtk/gtkprintoperation-private.h
gtk/gtkprintoperation-unix.c
gtk/gtkprintoperation-win32.c
gtk/gtkprintoperation.c
gtk/gtkprintoperation.h

index 9a78450bb5dc6e7a90f54472d6e70ca04fb62789..c1b49706da5f5d15b4a1324f635e8bd3ea84223c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2006-05-23  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkprintoperation.h: 
+       * gtk/gtkprintoperation.c: Add a boolean show-progress  
+       property, and show a progress dialog if it is set to TRUE.
+       
+       * gtk/gtkprintoperation.c (pdf_end_run): 
+       * gtk/gtkprintoperation-win32.c (win32_end_run): 
+       * gtk/gtkprintoperation-unix.c (unix_end_run): 
+       * gtk/gtkprintoperation-private.h: Add a cancelled
+       parameter to end_run, and call it even if the print
+       operation was cancelled.
+
 2006-05-23  Alexander Larsson  <alexl@redhat.com>
 
        * gtk/gtkprinteroptionwidget.c (filesave_changed_cb):
index 9a78450bb5dc6e7a90f54472d6e70ca04fb62789..c1b49706da5f5d15b4a1324f635e8bd3ea84223c 100644 (file)
@@ -1,3 +1,17 @@
+2006-05-23  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkprintoperation.h: 
+       * gtk/gtkprintoperation.c: Add a boolean show-progress  
+       property, and show a progress dialog if it is set to TRUE.
+       
+       * gtk/gtkprintoperation.c (pdf_end_run): 
+       * gtk/gtkprintoperation-win32.c (win32_end_run): 
+       * gtk/gtkprintoperation-unix.c (unix_end_run): 
+       * gtk/gtkprintoperation-private.h: Add a cancelled
+       parameter to end_run, and call it even if the print
+       operation was cancelled.
+
 2006-05-23  Alexander Larsson  <alexl@redhat.com>
 
        * gtk/gtkprinteroptionwidget.c (filesave_changed_cb):
index 81e6df6b26f4c060aedfc06a9730cecc9f4fda1e..675103857cb2ecd97df22e57e3a4e4461f037769 100644 (file)
@@ -2696,6 +2696,7 @@ gtk_print_operation_set_unit
 gtk_print_operation_set_show_dialog
 gtk_print_operation_set_pdf_target
 gtk_print_operation_set_track_print_status
+gtk_print_operation_set_show_progress
 gtk_print_operation_run
 gtk_print_operation_run_async
 gtk_print_operation_get_status
index d1c6a7f81280d343e235944d210a1d1f2e11e35f..99237d5806cacf4fc61b18689b3759dc932c0027 100644 (file)
@@ -39,9 +39,11 @@ struct _GtkPrintOperationPrivate
   guint use_full_page      : 1;
   guint show_dialog        : 1;
   guint track_print_status : 1;
+  guint show_progress      : 1;
   guint cancelled          : 1;
 
   guint print_pages_idle_id;
+  guint show_progress_timeout_id;
 
   /* Data for the print job: */
   cairo_surface_t *surface;
@@ -68,7 +70,8 @@ struct _GtkPrintOperationPrivate
   void (*end_page)   (GtkPrintOperation *operation,
                      GtkPrintContext   *print_context);
   void (*end_run)    (GtkPrintOperation *operation,
-                     gboolean           wait);
+                     gboolean           wait,
+                     gboolean           cancelled);
 };
 
 GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *operation,
@@ -77,6 +80,7 @@ GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPri
                                                                          GError           **error);
 
 typedef void (* GtkPrintOperationPrintFunc) (GtkPrintOperation *op,
+                                            GtkWindow         *parent,
                                             gboolean           wait);
 
 void _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation          *op,
index 8176fd404b2dfcda5b51da7f34b46e350b4533d6..cc48bdcb60f8e4a91d9878250244de6475a193b8 100644 (file)
@@ -135,10 +135,14 @@ unix_finish_send  (GtkPrintJob *job,
 
 static void
 unix_end_run (GtkPrintOperation *op,
-             gboolean wait)
+             gboolean           wait,
+             gboolean           cancelled)
 {
   GtkPrintOperationUnix *op_unix = op->priv->platform_data;
 
+  if (cancelled)
+    return;
+
   if (wait)
     op_unix->loop = g_main_loop_new (NULL, FALSE);
   
@@ -293,7 +297,7 @@ finish_print (PrintResponseData *rdata,
   if (rdata->print_cb)
     {
       if (rdata->do_print)
-        rdata->print_cb (op, FALSE); 
+        rdata->print_cb (op, rdata->parent, FALSE); 
       else
        _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL); 
     }
index 2ee127da5e753dbd008fdf5a7e3cdd7a71c8d826..97e1aaa605785f09023393b1d3df2965adeb66bc 100644 (file)
@@ -471,7 +471,8 @@ win32_poll_status_timeout (GtkPrintOperation *op)
 
 static void
 win32_end_run (GtkPrintOperation *op,
-              gboolean wait)
+              gboolean           wait,
+              gboolean           cancelled)
 {
   GtkPrintOperationWin32 *op_win32 = op->priv->platform_data;
   LPDEVNAMES devnames;
@@ -1616,7 +1617,7 @@ _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation
 
   _gtk_print_operation_platform_backend_run_dialog (op, parent, &do_print, NULL);
   if (do_print)
-    print_cb (op, FALSE);
+    print_cb (op, parent, FALSE);
   else
     _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
 }
index 8c5fdc6f6e21c0d92c0cd1da9fe44584ea431eab..413d43b114cae553dceb7b068510f2f34aca7d4b 100644 (file)
  */
 
 #include "config.h"
-#include "string.h"
+#include <string.h>
 #include "gtkprintoperation-private.h"
 #include "gtkmarshalers.h"
 #include <cairo-pdf.h>
 #include "gtkintl.h"
 #include "gtkprivate.h"
+#include "gtkmessagedialog.h"
 #include "gtkalias.h"
 
+#define SHOW_PROGRESS_TIME 1200
+
 #define GTK_PRINT_OPERATION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_PRINT_OPERATION, GtkPrintOperationPrivate))
 
 enum {
@@ -52,6 +55,7 @@ enum {
   PROP_TRACK_PRINT_STATUS,
   PROP_UNIT,
   PROP_SHOW_DIALOG,
+  PROP_SHOW_PROGRESS,
   PROP_PDF_TARGET,
   PROP_STATUS,
   PROP_STATUS_STRING
@@ -105,6 +109,9 @@ gtk_print_operation_finalize (GObject *object)
   if (priv->print_pages_idle_id > 0)
     g_source_remove (priv->print_pages_idle_id);
 
+  if (priv->show_progress_timeout_id > 0)
+    g_source_remove (priv->show_progress_timeout_id);
+
   G_OBJECT_CLASS (gtk_print_operation_parent_class)->finalize (object);
 }
 
@@ -124,6 +131,7 @@ gtk_print_operation_init (GtkPrintOperation *operation)
   priv->current_page = -1;
   priv->use_full_page = FALSE;
   priv->show_dialog = TRUE;
+  priv->show_progress = FALSE;
   priv->pdf_target = NULL;
   priv->track_print_status = FALSE;
 
@@ -170,6 +178,9 @@ gtk_print_operation_set_property (GObject      *object,
     case PROP_SHOW_DIALOG:
       gtk_print_operation_set_show_dialog (op, g_value_get_boolean (value));
       break;
+    case PROP_SHOW_PROGRESS:
+      gtk_print_operation_set_show_progress (op, g_value_get_boolean (value));
+      break;
     case PROP_PDF_TARGET:
       gtk_print_operation_set_pdf_target (op, g_value_get_string (value));
       break;
@@ -217,6 +228,9 @@ gtk_print_operation_get_property (GObject    *object,
     case PROP_SHOW_DIALOG:
       g_value_set_boolean (value, priv->show_dialog);
       break;
+    case PROP_SHOW_PROGRESS:
+      g_value_set_boolean (value, priv->show_progress);
+      break;
     case PROP_PDF_TARGET:
       g_value_set_string (value, priv->pdf_target);
       break;
@@ -651,6 +665,24 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class)
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));
   
+
+  /**
+   * GtkPrintOperation:show-progress:
+   *
+   * Determines whether to show a progress dialog during the 
+   * print operation.
+   *
+   * Since: 2.10
+   */
+  g_object_class_install_property (gobject_class,
+                                  PROP_SHOW_PROGRESS,
+                                  g_param_spec_boolean ("show-progress",
+                                                        P_("Show Dialog"),
+                                                        P_("TRUE if a progress dialog is shown while printing."),
+                                                        FALSE,
+                                                        GTK_PARAM_READWRITE));
+  
+  
   /**
    * GtkPrintOperation:pdf-target:
    *
@@ -1050,7 +1082,6 @@ gtk_print_operation_set_track_print_status (GtkPrintOperation  *op,
     }
 }
 
-
 void
 _gtk_print_operation_set_status (GtkPrintOperation *op,
                                 GtkPrintStatus     status,
@@ -1200,6 +1231,37 @@ gtk_print_operation_set_show_dialog (GtkPrintOperation *op,
     }
 }
 
+
+/**
+ * gtk_print_operation_set_show_progress:
+ * @op: a #GtkPrintOperation
+ * @show_progress: %TRUE to show a progress dialog
+ * 
+ * If @show_progress is %TRUE, the print operation will show a 
+ * progress dialog during the print operation.
+ * 
+ * Since: 2.10
+ */
+void
+gtk_print_operation_set_show_progress (GtkPrintOperation  *op,
+                                      gboolean            show_progress)
+{
+  GtkPrintOperationPrivate *priv;
+
+  g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
+
+  priv = op->priv;
+
+  show_progress = show_progress != FALSE;
+
+  if (priv->show_progress != show_progress)
+    {
+      priv->show_progress = show_progress;
+
+      g_object_notify (G_OBJECT (op), "show-progress");
+    }
+}
+
 /**
  * gtk_print_operation_set_pdf_target:
  * @op: a #GtkPrintOperation
@@ -1305,7 +1367,8 @@ pdf_end_page (GtkPrintOperation *op,
 
 static void
 pdf_end_run (GtkPrintOperation *op,
-            gboolean           wait)
+            gboolean           wait,
+            gboolean           cancelled)
 {
   GtkPrintOperationPrivate *priv = op->priv;
 
@@ -1360,9 +1423,10 @@ run_pdf (GtkPrintOperation  *op,
 typedef struct
 {
   GtkPrintOperation *op;
+  gboolean wait;
   gint uncollated_copies;
   gint collated_copies;
-  gint uncollated, collated;
+  gint uncollated, collated, total;
 
   gint range, num_ranges;
   GtkPageRange *ranges;
@@ -1372,6 +1436,8 @@ typedef struct
 
   GtkPageSetup *initial_page_setup;
   GtkPrintContext *print_context;  
+
+  GtkWidget *progress;
 } PrintPagesData;
 
 static void
@@ -1425,17 +1491,61 @@ static void
 print_pages_idle_done (gpointer user_data)
 {
   PrintPagesData *data;
+  GtkPrintOperationPrivate *priv;
+
+  GDK_THREADS_ENTER ();
 
   data = (PrintPagesData*)user_data;
-  data->op->priv->print_pages_idle_id = 0;
+  priv = data->op->priv;
+
+  priv->print_pages_idle_id = 0;
+
+  if (priv->show_progress_timeout_id > 0)
+    {
+      g_source_remove (priv->show_progress_timeout_id);
+      priv->show_progress_timeout_id = 0;
+    }
+
+  if (data->progress)
+    gtk_widget_destroy (data->progress);
 
   g_object_unref (data->print_context);
   g_object_unref (data->initial_page_setup);
 
   g_object_unref (data->op);
   g_free (data);
+
+  GDK_THREADS_LEAVE ();
 }
 
+static void
+update_progress (PrintPagesData *data)
+{
+  GtkPrintOperationPrivate *priv; 
+  gchar *text = NULL;
+  
+  priv = data->op->priv;
+  if (data->progress)
+    {
+      if (priv->status == GTK_PRINT_STATUS_PREPARING)
+       {
+         if (priv->nr_of_pages > 0)
+           text = g_strdup_printf (_("Preparing %d"), priv->nr_of_pages);
+         else
+           text = g_strdup (_("Preparing"));
+       }
+      else if (priv->status == GTK_PRINT_STATUS_GENERATING_DATA)
+       text = g_strdup_printf (_("Printing %d"), data->total);
+      
+      if (text)
+       {
+         g_object_set (data->progress, "text", text, NULL);
+         g_free (text);
+       }
+    }
+ }
+
 static gboolean
 print_pages_idle (gpointer user_data)
 {
@@ -1510,17 +1620,13 @@ print_pages_idle (gpointer user_data)
       goto out;
     }
 
+  data->total++;
   data->collated++;
   if (data->collated == data->collated_copies)
     {
       data->collated = 0;
       if (!increment_page_sequence (data))
        {
-         g_signal_emit (data->op, signals[END_PRINT], 0, data->print_context);
-         
-         cairo_surface_finish (data->op->priv->surface);
-         priv->end_run (data->op, TRUE);
-         
          done = TRUE;
 
          goto out;
@@ -1561,22 +1667,54 @@ print_pages_idle (gpointer user_data)
 
   if (priv->cancelled)
     {
-      g_signal_emit (data->op, signals[END_PRINT], 0, data->print_context);
-      
-      cairo_surface_finish (data->op->priv->surface);
-      
       _gtk_print_operation_set_status (data->op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
       
       done = TRUE;
     }
 
+  if (done)
+    {
+      g_signal_emit (data->op, signals[END_PRINT], 0, data->print_context);
+      
+      cairo_surface_finish (data->op->priv->surface);
+      priv->end_run (data->op, data->wait, priv->cancelled);
+    }
+
+  update_progress (data);
+
   GDK_THREADS_LEAVE ();
 
   return !done;
 }
   
+static void
+handle_progress_response (GtkWidget *dialog, 
+                         gint       response,
+                         gpointer   data)
+{
+  GtkPrintOperation *op = (GtkPrintOperation *)data;
+
+  gtk_widget_hide (dialog);
+  gtk_print_operation_cancel (op);
+}
+
+static gboolean
+show_progress_timeout (PrintPagesData *data)
+{
+  GDK_THREADS_ENTER ();
+
+  gtk_window_present (data->progress);
+
+  data->op->priv->show_progress_timeout_id = 0;
+
+  GDK_THREADS_LEAVE ();
+
+  return FALSE;
+}
+
 static void
 print_pages (GtkPrintOperation *op,
+            GtkWindow         *parent,
             gboolean           wait)
 {
   GtkPrintOperationPrivate *priv = op->priv;
@@ -1584,9 +1722,27 @@ print_pages (GtkPrintOperation *op,
   GtkPrintContext *print_context;
   int uncollated_copies, collated_copies;
   PrintPagesData *data;
+  GtkWidget *progress = NULL;
  
   _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_PREPARING, NULL);  
 
+  data = g_new0 (PrintPagesData, 1);
+
+  if (priv->show_progress)
+    {
+      progress = gtk_message_dialog_new (parent, 0, 
+                                        GTK_MESSAGE_OTHER,
+                                        GTK_BUTTONS_CANCEL,
+                                        _("Preparing"));
+      g_signal_connect (progress, "response", 
+                       G_CALLBACK (handle_progress_response), op);
+
+      priv->show_progress_timeout_id = 
+       g_timeout_add (SHOW_PROGRESS_TIME, 
+                      (GSourceFunc)show_progress_timeout,
+                      data);
+    }
+
   print_context = _gtk_print_context_new (op);
 
   initial_page_setup = create_page_setup (op);
@@ -1605,12 +1761,13 @@ print_pages (GtkPrintOperation *op,
       collated_copies = priv->manual_num_copies;
     }
 
-  data = g_new0 (PrintPagesData, 1);
   data->op = g_object_ref (op);
+  data->wait = wait;
   data->uncollated_copies = uncollated_copies;
   data->collated_copies = collated_copies;
   data->initial_page_setup = initial_page_setup;
   data->print_context = print_context;
+  data->progress = progress;
 
   if (wait)
     {
@@ -1679,7 +1836,7 @@ gtk_print_operation_run (GtkPrintOperation  *op,
                                                               &do_print,
                                                               error);
   if (do_print)
-    print_pages (op, TRUE);
+    print_pages (op, parent, TRUE);
   else 
     _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
 
@@ -1720,7 +1877,7 @@ gtk_print_operation_run_async (GtkPrintOperation *op,
     {
       run_pdf (op, parent, &do_print, NULL);
       if (do_print)
-       print_pages (op, FALSE);
+       print_pages (op, parent, FALSE);
       else 
        _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
     }
index 58baf745612c15c6e9b3807893d85c137bd17952..f3003e4dc231c1e601789c002d6bada0c5bb3959 100644 (file)
@@ -136,6 +136,8 @@ void                    gtk_print_operation_set_pdf_target         (GtkPrintOper
                                                                    const gchar        *filename);
 void                    gtk_print_operation_set_track_print_status (GtkPrintOperation  *op,
                                                                    gboolean            track_status);
+void                    gtk_print_operation_set_show_progress      (GtkPrintOperation  *op,
+                                                                   gboolean            show_progress);
 GtkPrintOperationResult gtk_print_operation_run                    (GtkPrintOperation  *op,
                                                                    GtkWindow          *parent,
                                                                    GError            **error);