summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtk.symbols1
-rw-r--r--gtk/gtkprintoperation-private.h6
-rw-r--r--gtk/gtkprintoperation-unix.c8
-rw-r--r--gtk/gtkprintoperation-win32.c5
-rw-r--r--gtk/gtkprintoperation.c191
-rw-r--r--gtk/gtkprintoperation.h2
6 files changed, 191 insertions, 22 deletions
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 81e6df6b26..675103857c 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -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
diff --git a/gtk/gtkprintoperation-private.h b/gtk/gtkprintoperation-private.h
index d1c6a7f812..99237d5806 100644
--- a/gtk/gtkprintoperation-private.h
+++ b/gtk/gtkprintoperation-private.h
@@ -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,
diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c
index 8176fd404b..cc48bdcb60 100644
--- a/gtk/gtkprintoperation-unix.c
+++ b/gtk/gtkprintoperation-unix.c
@@ -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);
}
diff --git a/gtk/gtkprintoperation-win32.c b/gtk/gtkprintoperation-win32.c
index 2ee127da5e..97e1aaa605 100644
--- a/gtk/gtkprintoperation-win32.c
+++ b/gtk/gtkprintoperation-win32.c
@@ -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);
}
diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c
index 8c5fdc6f6e..413d43b114 100644
--- a/gtk/gtkprintoperation.c
+++ b/gtk/gtkprintoperation.c
@@ -19,14 +19,17 @@
*/
#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);
}
diff --git a/gtk/gtkprintoperation.h b/gtk/gtkprintoperation.h
index 58baf74561..f3003e4dc2 100644
--- a/gtk/gtkprintoperation.h
+++ b/gtk/gtkprintoperation.h
@@ -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);