[gnumeric] Ask for confirmation if many pages are to be previewed!
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Ask for confirmation if many pages are to be previewed!
- Date: Wed, 19 Oct 2011 17:52:56 +0000 (UTC)
commit ccd8bd180965422fe65a623bf6b62bcfb78babca
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Wed Oct 19 11:52:18 2011 -0600
Ask for confirmation if many pages are to be previewed!
2011-10-19 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/print.c (PrintingInstance): new field
(gnm_paginate_cb): check for too many previewed pages
(gnm_ready_preview_cb): new
(gnm_begin_print_cb): adjust progress text for preview vs. print
(gnm_draw_page_cb): ditto
(gnm_print_sheet): set new field of PrintingInstance and connect
gnm_ready_preview_cb
ChangeLog | 10 +++++++
src/print.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 78 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ada0191..a28a15f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2011-10-19 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * src/print.c (PrintingInstance): new field
+ (gnm_paginate_cb): check for too many previewed pages
+ (gnm_ready_preview_cb): new
+ (gnm_begin_print_cb): adjust progress text for preview vs. print
+ (gnm_draw_page_cb): ditto
+ (gnm_print_sheet): set new field of PrintingInstance and connect
+ gnm_ready_preview_cb
+
+2011-10-19 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* src/print.c (gnm_draw_page_cb): disconnect handler after cancelling
2011-10-18 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/src/print.c b/src/print.c
index 0fa1b5c..dcb56c0 100644
--- a/src/print.c
+++ b/src/print.c
@@ -78,6 +78,7 @@ typedef struct {
HFRenderInfo *hfi;
GtkWidget *progress;
gboolean cancel;
+ gboolean preview;
} PrintingInstance;
typedef struct {
@@ -1163,21 +1164,51 @@ gnm_paginate_cb (GtkPrintOperation *operation,
spi = g_list_nth_data (pi->gnmSheets, paginate);
if (spi == NULL) { /*We are done paginating */
- GList *l;
- gint n_pages = 0;
-
- for (l = pi->gnmSheets; l != NULL; l = l->next) {
- SheetPrintInfo *spi = l->data;
- n_pages += spi->pages;
- }
+ /* GTK sends additional pagination requests! */
+ /* We only need to do this once though! */
+ if (g_list_nth_data (pi->gnmSheets, paginate - 1) != NULL) {
+ GList *l;
+ gint n_pages = 0;
+
+ for (l = pi->gnmSheets; l != NULL; l = l->next) {
+ SheetPrintInfo *spi = l->data;
+ n_pages += spi->pages;
+ }
- gtk_print_operation_set_n_pages (operation, n_pages == 0 ? 1 : n_pages);
- gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);
- pi->hfi->pages = n_pages;
+ if (pi->preview) {
+ int i, count = 0;
+
+ for (i = 0; i < n_pages; i++) {
+ if (gtk_print_operation_preview_is_selected
+ (GTK_PRINT_OPERATION_PREVIEW (operation),
+ i))
+ count++;
+ if (count > 1000)
+ break;
+ }
+ /* Note that gtk_print_operation_preview_is_selected always */
+ /* returns FALSE if "all pages" where selected! This is a gtk bug! */
+ if ((count > 1000 || (count == 0 && n_pages > 1000)) && !go_gtk_query_yes_no
+ (pi->progress != NULL ?
+ GTK_WINDOW (pi->progress) : wbcg_toplevel (WBC_GTK (pi->wbc)),
+ FALSE, "%s",
+ (count > 1000) ?
+ _("You have chosen more than 1000 pages to preview. "
+ "This may take a long time. "
+ "Do you really want to proceed?") :
+ _("You may have chosen more than 1000 pages to preview. "
+ "This would take a long time. "
+ "Do you really want to proceed?")))
+ n_pages = 0;
+ }
- if (n_pages == 0) /* gtk+ cannot handle 0 pages */
- gtk_print_operation_cancel (operation);
+ gtk_print_operation_set_n_pages (operation, n_pages == 0 ? 1 : n_pages);
+ gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);
+ pi->hfi->pages = n_pages;
+ if (n_pages == 0) /* gtk+ cannot handle 0 pages */
+ gtk_print_operation_cancel (operation);
+ }
return TRUE;
}
@@ -1206,6 +1237,19 @@ cb_progress_delete (G_GNUC_UNUSED GtkWidget *widget,
return TRUE;
}
+static gboolean
+gnm_ready_preview_cb (G_GNUC_UNUSED GtkPrintOperation *operation,
+ G_GNUC_UNUSED GtkPrintOperationPreview *preview,
+ G_GNUC_UNUSED GtkPrintContext *context,
+ G_GNUC_UNUSED GtkWindow *parent,
+ gpointer user_data)
+{
+ PrintingInstance * pi = (PrintingInstance *) user_data;
+ pi->preview = TRUE;
+
+ return FALSE;
+}
+
static void
gnm_begin_print_cb (GtkPrintOperation *operation,
G_GNUC_UNUSED GtkPrintContext *context,
@@ -1250,6 +1294,8 @@ gnm_begin_print_cb (GtkPrintOperation *operation,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CANCEL,
+ pi->preview ?
+ _("Preparing to preview"):
_("Preparing to print"));
g_signal_connect (G_OBJECT (pi->progress), "response",
G_CALLBACK (cb_progress_response), pi);
@@ -1336,10 +1382,15 @@ gnm_draw_page_cb (GtkPrintOperation *operation,
char *text;
if (pi->hfi->pages == -1)
- text = g_strdup_printf (_("Printing page %.3d"), page_nr);
+ text = g_strdup_printf
+ (pi->preview ? _("Creating preview of page %3d")
+ : _("Printing page %3d"), page_nr);
else
- text = g_strdup_printf (_("Printing page %.3d of %.3d pages"),
- page_nr, pi->hfi->pages);
+ text = g_strdup_printf
+ (pi->preview ?
+ _("Creating preview of page %3d of %3d pages")
+ : _("Printing page %3d of %3d pages"),
+ page_nr, pi->hfi->pages);
g_object_set (G_OBJECT (pi->progress), "text", text, NULL);
g_free (text);
}
@@ -1679,6 +1730,7 @@ gnm_print_sheet (WorkbookControl *wbc, Sheet *sheet,
pi->wb = sheet->workbook;
pi->wbc = wbc ? WORKBOOK_CONTROL (wbc) : NULL;
pi->sheet = sheet;
+ pi->preview = preview;
settings = gnm_conf_get_print_settings ();
if (default_range == PRINT_SAVED_INFO) {
@@ -1725,6 +1777,7 @@ gnm_print_sheet (WorkbookControl *wbc, Sheet *sheet,
g_object_unref (page_setup);
}
+ g_signal_connect (print, "preview", G_CALLBACK (gnm_ready_preview_cb), pi);
g_signal_connect (print, "begin-print", G_CALLBACK (gnm_begin_print_cb), pi);
g_signal_connect (print, "paginate", G_CALLBACK (gnm_paginate_cb), pi);
g_signal_connect (print, "draw-page", G_CALLBACK (gnm_draw_page_cb), pi);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]