From f628d64bc327e037fa58c8c11f7919b62b182cb6 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 17 Jan 2007 04:14:38 +0000 Subject: [PATCH] 2007-01-16 Jim Evins * src/Makefile.am: * src/print-dialog.c: * src/print-dialog.h: * src/print-op.c: * src/print-op.h: * src/template-designer.c: (print_test_cb): * src/ui-commands.c: (gl_ui_cmd_file_print): * src/print.c: Renamed PrintDialog to PrintOp. Added constructor for batch printing. * src/glabels-batch.c: (main): Converted to use new PrintOp object for printing. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@606 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 15 + glabels2/src/Makefile.am | 14 +- glabels2/src/glabels-batch.c | 51 +-- glabels2/src/print-dialog.c | 456 ------------------------- glabels2/src/print-dialog.h | 67 ---- glabels2/src/print-op.c | 562 +++++++++++++++++++++++++++++++ glabels2/src/print-op.h | 79 +++++ glabels2/src/print.c | 36 -- glabels2/src/template-designer.c | 10 +- glabels2/src/ui-commands.c | 8 +- 10 files changed, 695 insertions(+), 603 deletions(-) delete mode 100644 glabels2/src/print-dialog.c delete mode 100644 glabels2/src/print-dialog.h create mode 100644 glabels2/src/print-op.c create mode 100644 glabels2/src/print-op.h diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index eba73529..2b94897e 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,18 @@ +2007-01-16 Jim Evins + + * src/Makefile.am: + * src/print-dialog.c: + * src/print-dialog.h: + * src/print-op.c: + * src/print-op.h: + * src/template-designer.c: (print_test_cb): + * src/ui-commands.c: (gl_ui_cmd_file_print): + * src/print.c: + Renamed PrintDialog to PrintOp. Added constructor for batch + printing. + * src/glabels-batch.c: (main): + Converted to use new PrintOp object for printing. + 2007-01-15 Jim Evins * data/glade/Makefile.am: diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index 7f0b1953..f4ffa687 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -113,8 +113,8 @@ glabels_SOURCES = \ object-editor-shadow-page.c \ print.c \ print.h \ - print-dialog.c \ - print-dialog.h \ + print-op.c \ + print-op.h \ template-designer.c \ template-designer.h \ bc.c \ @@ -191,6 +191,8 @@ glabels_batch_SOURCES = \ glabels-batch.c \ print.c \ print.h \ + print-op.c \ + print-op.h \ bc.c \ bc.h \ bc-gnubarcode.c \ @@ -247,6 +249,14 @@ glabels_batch_SOURCES = \ color.h \ debug.c \ debug.h \ + wdgt-print-copies.c \ + wdgt-print-copies.h \ + wdgt-print-merge.c \ + wdgt-print-merge.h \ + wdgt-mini-preview.c \ + wdgt-mini-preview.h \ + hig.c \ + hig.h \ $(BUILT_SOURCES) marshal.h: marshal.list $(GLIB_GENMARSHAL) diff --git a/glabels2/src/glabels-batch.c b/glabels2/src/glabels-batch.c index 39426bde..64588deb 100644 --- a/glabels2/src/glabels-batch.c +++ b/glabels2/src/glabels-batch.c @@ -26,11 +26,11 @@ #include #include -#include #include "merge-init.h" #include "xml-label.h" #include "print.h" +#include "print-op.h" #include #include #include "util.h" @@ -41,7 +41,7 @@ /*============================================*/ static gboolean help_flag = FALSE; static gboolean version_flag = FALSE; -static gchar *output = "output.ps"; +static gchar *output = "output.pdf"; static gint n_copies = 1; static gint n_sheets = 1; static gint first = 1; @@ -56,7 +56,7 @@ static struct poptOption options[] = { {"version", 'v', POPT_ARG_NONE, &version_flag, 0, N_("print the version of glabels-batch being used"), NULL}, {"output", 'o', POPT_ARG_STRING, &output, 0, - N_("set output filename (default=\"output.ps\")"), N_("filename")}, + N_("set output filename (default=\"output.pdf\")"), N_("filename")}, {"sheets", 's', POPT_ARG_INT, &n_sheets, 0, N_("number of sheets (default=1)"), N_("sheets")}, {"copies", 'c', POPT_ARG_INT, &n_copies, 0, @@ -88,13 +88,11 @@ main (int argc, char **argv) gint rc; GSList *p, *file_list = NULL; gint n_files; - GnomePrintJob *job = NULL; gchar *abs_fn; - GnomePrintConfig *config = NULL; glLabel *label = NULL; glMerge *merge = NULL; glXMLLabelStatus status; - glPrintFlags flags; + glPrintOp *print_op; bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR); textdomain (GETTEXT_PACKAGE); @@ -133,10 +131,6 @@ main (int argc, char **argv) } poptFreeContext (pctx); - flags.outline = outline_flag; - flags.reverse = reverse_flag; - flags.crop_marks = crop_marks_flag; - /* initialize components */ gl_debug_init (); gl_merge_init (); @@ -162,23 +156,21 @@ main (int argc, char **argv) (char *)p->data ); } } - if ( job == NULL ) { - job = gnome_print_job_new (NULL); - abs_fn = gl_util_make_absolute ( output ); - config = gnome_print_job_get_config (job); - gnome_print_config_set (config, - (guchar*)"Printer", - (guchar*)"GENERIC"); - gnome_print_config_set (config, - (guchar*)"Settings.Transport.Backend", - (guchar*)"file"); - gnome_print_config_set (config, - (guchar*)GNOME_PRINT_KEY_OUTPUT_FILENAME, - (guchar*)abs_fn); - g_free( abs_fn ); - } + abs_fn = gl_util_make_absolute ( output ); + print_op = gl_print_op_new_batch (label, + abs_fn, + n_sheets, + n_copies, + first, + outline_flag, + reverse_flag, + crop_marks_flag); + + gtk_print_operation_run (GTK_PRINT_OPERATION (print_op), + GTK_PRINT_OPERATION_ACTION_EXPORT, + NULL, + NULL); - gl_print_batch (job, label, n_sheets, n_copies, first, &flags); g_object_unref (label); } else { @@ -186,13 +178,6 @@ main (int argc, char **argv) (char *)p->data ); } } - if ( job != NULL ) { - - gnome_print_job_close (job); - gnome_print_job_print (job); - - g_object_unref (job); - } g_slist_free (file_list); diff --git a/glabels2/src/print-dialog.c b/glabels2/src/print-dialog.c deleted file mode 100644 index 5051da21..00000000 --- a/glabels2/src/print-dialog.c +++ /dev/null @@ -1,456 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ - -/* - * (GLABELS) Label and Business Card Creation program for GNOME - * - * print-dialog.c: Print dialog module - * - * Copyright (C) 2001-2007 Jim Evins . - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include - -#include "print-dialog.h" - -#include -#include -#include -#include -#include -#include - -#include "print.h" -#include "label.h" - -#include "wdgt-print-copies.h" -#include "wdgt-print-merge.h" - -#include "debug.h" - -/*===========================================*/ -/* Private data types */ -/*===========================================*/ - -struct _glPrintDialogPrivate { - - glLabel *label; - - GladeXML *gui; - - GtkWidget *simple_frame; - GtkWidget *copies_vbox; - GtkWidget *copies; - - GtkWidget *merge_frame; - GtkWidget *prmerge_vbox; - GtkWidget *prmerge; - - GtkWidget *outline_check; - GtkWidget *reverse_check; - GtkWidget *crop_marks_check; - - gboolean force_outline_flag; - - gboolean outline_flag; - gboolean reverse_flag; - gboolean crop_marks_flag; - gboolean merge_flag; - gboolean collate_flag; - - gint first; - gint last; - gint n_sheets; - gint n_copies; - - glPrintState state; -}; - - -/*===========================================*/ -/* Private globals */ -/*===========================================*/ - -static GtkPrintOperationClass* parent_class = NULL; - -/*===========================================*/ -/* Local function prototypes */ -/*===========================================*/ - -static void gl_print_dialog_class_init (glPrintDialogClass *klass); -static void gl_print_dialog_init (glPrintDialog *dialog); -static void gl_print_dialog_finalize (GObject *object); - -static void gl_print_dialog_construct (glPrintDialog *dialog, - glLabel *label); - - -static GObject *create_custom_widget_cb (GtkPrintOperation *operation, - gpointer user_data); - -static void custom_widget_apply_cb (GtkPrintOperation *operation, - GtkWidget *widget, - gpointer user_data); - -static void begin_print_cb (GtkPrintOperation *operation, - GtkPrintContext *context, - gpointer user_data); - -static void draw_page_cb (GtkPrintOperation *operation, - GtkPrintContext *context, - int page_nr, - gpointer user_data); - - - - -/*****************************************************************************/ -/* Boilerplate object stuff. */ -/*****************************************************************************/ -GType -gl_print_dialog_get_type (void) -{ - static GType type = 0; - - if (!type) - { - static const GTypeInfo info = - { - sizeof (glPrintDialogClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) gl_print_dialog_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (glPrintDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) gl_print_dialog_init, - NULL - }; - - type = g_type_register_static (GTK_TYPE_PRINT_OPERATION, - "glPrintDialog", &info, 0); - } - - return type; -} - -static void -gl_print_dialog_class_init (glPrintDialogClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkPrintOperationClass *print_class = GTK_PRINT_OPERATION_CLASS (klass); - - gl_debug (DEBUG_PRINT, ""); - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = gl_print_dialog_finalize; -} - -static void -gl_print_dialog_init (glPrintDialog *dialog) -{ - GtkWidget *pp_button; - - gl_debug (DEBUG_PRINT, ""); - - gtk_print_operation_set_use_full_page (GTK_PRINT_OPERATION (dialog), - TRUE); - - gtk_print_operation_set_unit (GTK_PRINT_OPERATION (dialog), - GTK_UNIT_POINTS); - - dialog->priv = g_new0 (glPrintDialogPrivate, 1); - -} - -static void -gl_print_dialog_finalize (GObject *object) -{ - glPrintDialog* dialog; - - gl_debug (DEBUG_PRINT, ""); - - g_return_if_fail (object != NULL); - - dialog = GL_PRINT_DIALOG (object); - - g_return_if_fail (GL_IS_PRINT_DIALOG (dialog)); - g_return_if_fail (dialog->priv != NULL); - - if (dialog->priv->label) { - g_object_unref (G_OBJECT(dialog->priv->label)); - } - g_free (dialog->priv); - - G_OBJECT_CLASS (parent_class)->finalize (object); - - g_free (dialog->priv); -} - -/*****************************************************************************/ -/* NEW print dialog. */ -/*****************************************************************************/ -glPrintDialog * -gl_print_dialog_new (glLabel *label) -{ - glPrintDialog *dialog; - - gl_debug (DEBUG_PRINT, ""); - - dialog = GL_PRINT_DIALOG (g_object_new (GL_TYPE_PRINT_DIALOG, NULL)); - - gl_print_dialog_construct (GL_PRINT_DIALOG(dialog), label); - - return dialog; -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Construct dialog. */ -/*--------------------------------------------------------------------------*/ -static void -gl_print_dialog_construct (glPrintDialog *dialog, - glLabel *label) -{ - dialog->priv->label = label; - dialog->priv->force_outline_flag = FALSE; - - gtk_print_operation_set_custom_tab_label ( GTK_PRINT_OPERATION (dialog), - _("Labels")); - - g_signal_connect (G_OBJECT (dialog), "create-custom-widget", - G_CALLBACK (create_custom_widget_cb), label); - - g_signal_connect (G_OBJECT (dialog), "custom-widget-apply", - G_CALLBACK (custom_widget_apply_cb), label); - - g_signal_connect (G_OBJECT (dialog), "begin-print", - G_CALLBACK (begin_print_cb), label); - - g_signal_connect (G_OBJECT (dialog), "draw-page", - G_CALLBACK (draw_page_cb), label); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. "Create custom widget" callback */ -/*--------------------------------------------------------------------------*/ -static GObject * -create_custom_widget_cb (GtkPrintOperation *operation, - gpointer user_data) -{ - glPrintDialog *dialog = GL_PRINT_DIALOG (operation); - glLabel *label = GL_LABEL (user_data); - - GtkWidget *vbox; - - glMerge *merge = NULL; - - dialog->priv->gui = glade_xml_new (GLABELS_GLADE_DIR "print-custom-widget.glade", - "print_custom_widget_vbox", - NULL); - - if (!dialog->priv->gui) { - g_warning ("Could not open print-dialog.glade, reinstall glabels!"); - return; - } - - vbox = glade_xml_get_widget (dialog->priv->gui, "print_custom_widget_vbox"); - - /* ----- Simple print control ----- */ - dialog->priv->simple_frame = glade_xml_get_widget (dialog->priv->gui, - "simple_frame"); - dialog->priv->copies_vbox = glade_xml_get_widget (dialog->priv->gui, - "copies_vbox"); - dialog->priv->copies = gl_wdgt_print_copies_new (label); - gtk_box_pack_start (GTK_BOX(dialog->priv->copies_vbox), - dialog->priv->copies, FALSE, FALSE, 0); - - /* ----- Merge print control ----- */ - dialog->priv->merge_frame = glade_xml_get_widget (dialog->priv->gui, - "merge_frame"); - dialog->priv->prmerge_vbox = glade_xml_get_widget (dialog->priv->gui, - "prmerge_vbox"); - dialog->priv->prmerge = gl_wdgt_print_merge_new (label); - gtk_box_pack_start (GTK_BOX(dialog->priv->prmerge_vbox), - dialog->priv->prmerge, FALSE, FALSE, 0); - - /* ----- Options ----------------- */ - dialog->priv->outline_check = glade_xml_get_widget (dialog->priv->gui, - "outline_check"); - dialog->priv->reverse_check = glade_xml_get_widget (dialog->priv->gui, - "reverse_check"); - dialog->priv->crop_marks_check = glade_xml_get_widget (dialog->priv->gui, - "crop_marks_check"); - - /* ---- Activate either simple or merge print control widgets. ---- */ - merge = gl_label_get_merge (dialog->priv->label); - if (merge == NULL) { - - gtk_widget_show_all (dialog->priv->simple_frame); - gtk_widget_hide_all (dialog->priv->merge_frame); - - } else { - - gint n_records = gl_merge_get_record_count( merge ); - gl_wdgt_print_merge_set_copies (GL_WDGT_PRINT_MERGE(dialog->priv->prmerge), - 1, 1, n_records, FALSE); - g_object_unref (G_OBJECT(merge)); - - gtk_widget_hide_all (dialog->priv->simple_frame); - gtk_widget_show_all (dialog->priv->merge_frame); - } - - /* --- Do we need to force the outline flag --- */ - if (dialog->priv->force_outline_flag) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dialog->priv->outline_check), - TRUE); - - gtk_widget_set_sensitive (dialog->priv->outline_check, FALSE); - gtk_widget_set_sensitive (dialog->priv->reverse_check, FALSE); - gtk_widget_set_sensitive (dialog->priv->crop_marks_check, FALSE); - } - - return G_OBJECT (vbox); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. "Custom widget apply" callback */ -/*--------------------------------------------------------------------------*/ -static void -custom_widget_apply_cb (GtkPrintOperation *operation, - GtkWidget *widget, - gpointer user_data) -{ - glPrintDialog *dialog = GL_PRINT_DIALOG (operation); - glMerge *merge = NULL; - - - dialog->priv->outline_flag = - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON - (dialog->priv->outline_check)); - dialog->priv->reverse_flag = - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON - (dialog->priv->reverse_check)); - dialog->priv->crop_marks_flag = - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON - (dialog->priv->crop_marks_check)); - - merge = gl_label_get_merge (dialog->priv->label); - - if (merge == NULL) - { - - dialog->priv->merge_flag = FALSE; - gl_wdgt_print_copies_get_range (GL_WDGT_PRINT_COPIES (dialog->priv->copies), - &dialog->priv->n_sheets, - &dialog->priv->first, - &dialog->priv->last); - } - else - { - - dialog->priv->merge_flag = TRUE; - gl_wdgt_print_merge_get_copies (GL_WDGT_PRINT_MERGE (dialog->priv->prmerge), - &dialog->priv->n_copies, - &dialog->priv->first, - &dialog->priv->collate_flag, - &dialog->priv->n_sheets); - g_object_unref (G_OBJECT(merge)); - } - -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. "Begin print" callback */ -/*--------------------------------------------------------------------------*/ -static void -begin_print_cb (GtkPrintOperation *operation, - GtkPrintContext *context, - gpointer user_data) -{ - glPrintDialog *dialog = GL_PRINT_DIALOG (operation); - - gtk_print_operation_set_n_pages (operation, dialog->priv->n_sheets); - -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. "Draw page" callback. */ -/*--------------------------------------------------------------------------*/ -static void -draw_page_cb (GtkPrintOperation *operation, - GtkPrintContext *context, - int page_nr, - gpointer user_data) -{ - glPrintDialog *dialog = GL_PRINT_DIALOG (operation); - cairo_t *cr; - - cr = gtk_print_context_get_cairo_context (context); - - if (!dialog->priv->merge_flag) - { - gl_print_simple_sheet (dialog->priv->label, - cr, - page_nr, - dialog->priv->n_sheets, - dialog->priv->first, - dialog->priv->last, - dialog->priv->outline_flag, - dialog->priv->reverse_flag, - dialog->priv->crop_marks_flag); - } - else - { - if (dialog->priv->collate_flag) - { - gl_print_collated_merge_sheet (dialog->priv->label, - cr, - page_nr, - dialog->priv->n_copies, - dialog->priv->first, - dialog->priv->outline_flag, - dialog->priv->reverse_flag, - dialog->priv->crop_marks_flag, - &dialog->priv->state); - } - else - { - gl_print_uncollated_merge_sheet (dialog->priv->label, - cr, - page_nr, - dialog->priv->n_copies, - dialog->priv->first, - dialog->priv->outline_flag, - dialog->priv->reverse_flag, - dialog->priv->crop_marks_flag, - &dialog->priv->state); - } - } -} - - -/*****************************************************************************/ -/* Set outline flag/checkbox. */ -/*****************************************************************************/ -void -gl_print_dialog_force_outline_flag (glPrintDialog *dialog) -{ - dialog->priv->force_outline_flag = TRUE; -} - - diff --git a/glabels2/src/print-dialog.h b/glabels2/src/print-dialog.h deleted file mode 100644 index d41bc452..00000000 --- a/glabels2/src/print-dialog.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ - -/* - * (GLABELS) Label and Business Card Creation program for GNOME - * - * print-dialog.h: Print dialog module header file - * - * Copyright (C) 2001-2007 Jim Evins . - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef __PRINT_DIALOG_H__ -#define __PRINT_DIALOG_H__ - -#include -#include "label.h" - -G_BEGIN_DECLS - -#define GL_TYPE_PRINT_DIALOG (gl_print_dialog_get_type ()) -#define GL_PRINT_DIALOG(obj) (GTK_CHECK_CAST ((obj), GL_TYPE_PRINT_DIALOG, glPrintDialog)) -#define GL_PRINT_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_PRINT_DIALOG, glPrintDialogClass)) -#define GL_IS_PRINT_DIALOG(obj) (GTK_CHECK_TYPE ((obj), GL_TYPE_PRINT_DIALOG)) -#define GL_IS_PRINT_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_PRINT_DIALOG)) -#define GL_PRINT_DIALOG_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GL_TYPE_PRINT_DIALOG, glPrintDialogClass)) - - -typedef struct _glPrintDialog glPrintDialog; -typedef struct _glPrintDialogClass glPrintDialogClass; - -typedef struct _glPrintDialogPrivate glPrintDialogPrivate; - -struct _glPrintDialog -{ - GtkPrintOperation parent_instance; - - glPrintDialogPrivate *priv; - -}; - -struct _glPrintDialogClass -{ - GtkPrintOperationClass parent_class; -}; - - -GType gl_print_dialog_get_type (void) G_GNUC_CONST; - -glPrintDialog *gl_print_dialog_new (glLabel *label); - -void gl_print_dialog_force_outline_flag (glPrintDialog *dialog); - -G_END_DECLS - -#endif diff --git a/glabels2/src/print-op.c b/glabels2/src/print-op.c new file mode 100644 index 00000000..fbbade5e --- /dev/null +++ b/glabels2/src/print-op.c @@ -0,0 +1,562 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ + +/* + * (GLABELS) Label and Business Card Creation program for GNOME + * + * print-op.c: Print operation module + * + * Copyright (C) 2001-2007 Jim Evins . + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include + +#include "print-op.h" + +#include +#include +#include +#include +#include +#include + +#include "print.h" +#include "label.h" + +#include "wdgt-print-copies.h" +#include "wdgt-print-merge.h" + +#include "debug.h" + +/*===========================================*/ +/* Private data types */ +/*===========================================*/ + +struct _glPrintOpPrivate { + + glLabel *label; + + GladeXML *gui; + + GtkWidget *simple_frame; + GtkWidget *copies_vbox; + GtkWidget *copies; + + GtkWidget *merge_frame; + GtkWidget *prmerge_vbox; + GtkWidget *prmerge; + + GtkWidget *outline_check; + GtkWidget *reverse_check; + GtkWidget *crop_marks_check; + + gboolean force_outline_flag; + + gchar *filename; + + gboolean outline_flag; + gboolean reverse_flag; + gboolean crop_marks_flag; + gboolean merge_flag; + gboolean collate_flag; + + gint first; + gint last; + gint n_sheets; + gint n_copies; + + glPrintState state; +}; + + +/*===========================================*/ +/* Private globals */ +/*===========================================*/ + +static GtkPrintOperationClass* parent_class = NULL; + +/*===========================================*/ +/* Local function prototypes */ +/*===========================================*/ + +static void gl_print_op_class_init (glPrintOpClass *klass); +static void gl_print_op_init (glPrintOp *op); +static void gl_print_op_finalize (GObject *object); + +static void gl_print_op_construct (glPrintOp *op, + glLabel *label); + +static void gl_print_op_construct_batch (glPrintOp *op, + glLabel *label, + gchar *filename, + gint n_sheets, + gint n_copies, + gint first, + gboolean outline_flag, + gboolean reverse_flag, + gboolean crop_marks_flag); + + +static GObject *create_custom_widget_cb (GtkPrintOperation *operation, + gpointer user_data); + +static void custom_widget_apply_cb (GtkPrintOperation *operation, + GtkWidget *widget, + gpointer user_data); + +static void begin_print_cb (GtkPrintOperation *operation, + GtkPrintContext *context, + gpointer user_data); + +static void draw_page_cb (GtkPrintOperation *operation, + GtkPrintContext *context, + int page_nr, + gpointer user_data); + + + + +/*****************************************************************************/ +/* Boilerplate object stuff. */ +/*****************************************************************************/ +GType +gl_print_op_get_type (void) +{ + static GType type = 0; + + if (!type) + { + static const GTypeInfo info = + { + sizeof (glPrintOpClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gl_print_op_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (glPrintOp), + 0, /* n_preallocs */ + (GInstanceInitFunc) gl_print_op_init, + NULL + }; + + type = g_type_register_static (GTK_TYPE_PRINT_OPERATION, + "glPrintOp", &info, 0); + } + + return type; +} + +static void +gl_print_op_class_init (glPrintOpClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkPrintOperationClass *print_class = GTK_PRINT_OPERATION_CLASS (klass); + + gl_debug (DEBUG_PRINT, ""); + + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = gl_print_op_finalize; +} + +static void +gl_print_op_init (glPrintOp *op) +{ + GtkWidget *pp_button; + + gl_debug (DEBUG_PRINT, ""); + + gtk_print_operation_set_use_full_page (GTK_PRINT_OPERATION (op), TRUE); + + gtk_print_operation_set_unit (GTK_PRINT_OPERATION (op), GTK_UNIT_POINTS); + + op->priv = g_new0 (glPrintOpPrivate, 1); + +} + +static void +gl_print_op_finalize (GObject *object) +{ + glPrintOp* op; + + gl_debug (DEBUG_PRINT, ""); + + g_return_if_fail (object != NULL); + + op = GL_PRINT_OP (object); + + g_return_if_fail (GL_IS_PRINT_OP (op)); + g_return_if_fail (op->priv != NULL); + + if (op->priv->label) { + g_object_unref (G_OBJECT(op->priv->label)); + } + g_free (op->priv->filename); + g_free (op->priv); + + G_OBJECT_CLASS (parent_class)->finalize (object); + + g_free (op->priv); +} + +/*****************************************************************************/ +/* NEW print op. */ +/*****************************************************************************/ +glPrintOp * +gl_print_op_new (glLabel *label) +{ + glPrintOp *op; + + gl_debug (DEBUG_PRINT, ""); + + op = GL_PRINT_OP (g_object_new (GL_TYPE_PRINT_OP, NULL)); + + gl_print_op_construct (GL_PRINT_OP(op), label); + + return op; +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Construct op. */ +/*--------------------------------------------------------------------------*/ +static void +gl_print_op_construct (glPrintOp *op, + glLabel *label) +{ + op->priv->label = label; + op->priv->force_outline_flag = FALSE; + + gtk_print_operation_set_custom_tab_label ( GTK_PRINT_OPERATION (op), + _("Labels")); + + g_signal_connect (G_OBJECT (op), "create-custom-widget", + G_CALLBACK (create_custom_widget_cb), label); + + g_signal_connect (G_OBJECT (op), "custom-widget-apply", + G_CALLBACK (custom_widget_apply_cb), label); + + g_signal_connect (G_OBJECT (op), "begin-print", + G_CALLBACK (begin_print_cb), label); + + g_signal_connect (G_OBJECT (op), "draw-page", + G_CALLBACK (draw_page_cb), label); +} + +/*****************************************************************************/ +/* NEW batch print operation. */ +/*****************************************************************************/ +glPrintOp * +gl_print_op_new_batch (glLabel *label, + gchar *filename, + gint n_sheets, + gint n_copies, + gint first, + gboolean outline_flag, + gboolean reverse_flag, + gboolean crop_marks_flag) +{ + glPrintOp *op; + + gl_debug (DEBUG_PRINT, ""); + + op = GL_PRINT_OP (g_object_new (GL_TYPE_PRINT_OP, NULL)); + + gl_print_op_construct_batch (GL_PRINT_OP(op), + label, + filename, + n_sheets, + n_copies, + first, + outline_flag, + reverse_flag, + crop_marks_flag); + + return op; +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Construct op. */ +/*--------------------------------------------------------------------------*/ +static void +gl_print_op_construct_batch (glPrintOp *op, + glLabel *label, + gchar *filename, + gint n_sheets, + gint n_copies, + gint first, + gboolean outline_flag, + gboolean reverse_flag, + gboolean crop_marks_flag) + +{ + glMerge *merge = NULL; + glTemplate *template = NULL; + const glTemplateLabelType *label_type = NULL; + + op->priv->label = label; + op->priv->force_outline_flag = FALSE; + op->priv->filename = g_strdup (filename); + op->priv->n_sheets = n_sheets; + op->priv->n_copies = n_copies; + op->priv->first = first; + op->priv->outline_flag = outline_flag; + op->priv->reverse_flag = reverse_flag; + op->priv->crop_marks_flag = crop_marks_flag; + + merge = gl_label_get_merge (label); + + template = gl_label_get_template (label); + label_type = gl_template_get_first_label_type (template); + if (merge == NULL) + { + op->priv->merge_flag = FALSE; + + op->priv->last = gl_template_get_n_labels (label_type); + + } + else + { + op->priv->merge_flag = TRUE; + + op->priv->n_sheets = + ceil ((double)(first-1 + n_copies * gl_merge_get_record_count(merge)) + / gl_template_get_n_labels (label_type));; + + g_object_unref (G_OBJECT(merge)); + + } + gl_template_free (template); + + gtk_print_operation_set_export_filename (GTK_PRINT_OPERATION (op), + filename); + + g_signal_connect (G_OBJECT (op), "begin-print", + G_CALLBACK (begin_print_cb), label); + + g_signal_connect (G_OBJECT (op), "draw-page", + G_CALLBACK (draw_page_cb), label); +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. "Create custom widget" callback */ +/*--------------------------------------------------------------------------*/ +static GObject * +create_custom_widget_cb (GtkPrintOperation *operation, + gpointer user_data) +{ + glPrintOp *op = GL_PRINT_OP (operation); + glLabel *label = GL_LABEL (user_data); + + GtkWidget *vbox; + + glMerge *merge = NULL; + + op->priv->gui = glade_xml_new (GLABELS_GLADE_DIR "print-custom-widget.glade", + "print_custom_widget_vbox", + NULL); + + if (!op->priv->gui) { + g_warning ("Could not open print-op.glade, reinstall glabels!"); + return; + } + + vbox = glade_xml_get_widget (op->priv->gui, "print_custom_widget_vbox"); + + /* ----- Simple print control ----- */ + op->priv->simple_frame = glade_xml_get_widget (op->priv->gui, + "simple_frame"); + op->priv->copies_vbox = glade_xml_get_widget (op->priv->gui, + "copies_vbox"); + op->priv->copies = gl_wdgt_print_copies_new (label); + gtk_box_pack_start (GTK_BOX(op->priv->copies_vbox), + op->priv->copies, FALSE, FALSE, 0); + + /* ----- Merge print control ----- */ + op->priv->merge_frame = glade_xml_get_widget (op->priv->gui, + "merge_frame"); + op->priv->prmerge_vbox = glade_xml_get_widget (op->priv->gui, + "prmerge_vbox"); + op->priv->prmerge = gl_wdgt_print_merge_new (label); + gtk_box_pack_start (GTK_BOX(op->priv->prmerge_vbox), + op->priv->prmerge, FALSE, FALSE, 0); + + /* ----- Options ----------------- */ + op->priv->outline_check = glade_xml_get_widget (op->priv->gui, + "outline_check"); + op->priv->reverse_check = glade_xml_get_widget (op->priv->gui, + "reverse_check"); + op->priv->crop_marks_check = glade_xml_get_widget (op->priv->gui, + "crop_marks_check"); + + /* ---- Activate either simple or merge print control widgets. ---- */ + merge = gl_label_get_merge (op->priv->label); + if (merge == NULL) { + + gtk_widget_show_all (op->priv->simple_frame); + gtk_widget_hide_all (op->priv->merge_frame); + + } else { + + gint n_records = gl_merge_get_record_count( merge ); + gl_wdgt_print_merge_set_copies (GL_WDGT_PRINT_MERGE(op->priv->prmerge), + 1, 1, n_records, FALSE); + g_object_unref (G_OBJECT(merge)); + + gtk_widget_hide_all (op->priv->simple_frame); + gtk_widget_show_all (op->priv->merge_frame); + } + + /* --- Do we need to force the outline flag --- */ + if (op->priv->force_outline_flag) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(op->priv->outline_check), + TRUE); + + gtk_widget_set_sensitive (op->priv->outline_check, FALSE); + gtk_widget_set_sensitive (op->priv->reverse_check, FALSE); + gtk_widget_set_sensitive (op->priv->crop_marks_check, FALSE); + } + + return G_OBJECT (vbox); +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. "Custom widget apply" callback */ +/*--------------------------------------------------------------------------*/ +static void +custom_widget_apply_cb (GtkPrintOperation *operation, + GtkWidget *widget, + gpointer user_data) +{ + glPrintOp *op = GL_PRINT_OP (operation); + glMerge *merge = NULL; + + + op->priv->outline_flag = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (op->priv->outline_check)); + op->priv->reverse_flag = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (op->priv->reverse_check)); + op->priv->crop_marks_flag = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (op->priv->crop_marks_check)); + + merge = gl_label_get_merge (op->priv->label); + + if (merge == NULL) + { + + op->priv->merge_flag = FALSE; + gl_wdgt_print_copies_get_range (GL_WDGT_PRINT_COPIES (op->priv->copies), + &op->priv->n_sheets, + &op->priv->first, + &op->priv->last); + } + else + { + + op->priv->merge_flag = TRUE; + gl_wdgt_print_merge_get_copies (GL_WDGT_PRINT_MERGE (op->priv->prmerge), + &op->priv->n_copies, + &op->priv->first, + &op->priv->collate_flag, + &op->priv->n_sheets); + g_object_unref (G_OBJECT(merge)); + } + +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. "Begin print" callback */ +/*--------------------------------------------------------------------------*/ +static void +begin_print_cb (GtkPrintOperation *operation, + GtkPrintContext *context, + gpointer user_data) +{ + glPrintOp *op = GL_PRINT_OP (operation); + + gtk_print_operation_set_n_pages (operation, op->priv->n_sheets); + +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. "Draw page" callback. */ +/*--------------------------------------------------------------------------*/ +static void +draw_page_cb (GtkPrintOperation *operation, + GtkPrintContext *context, + int page_nr, + gpointer user_data) +{ + glPrintOp *op = GL_PRINT_OP (operation); + cairo_t *cr; + + cr = gtk_print_context_get_cairo_context (context); + + if (!op->priv->merge_flag) + { + gl_print_simple_sheet (op->priv->label, + cr, + page_nr, + op->priv->n_sheets, + op->priv->first, + op->priv->last, + op->priv->outline_flag, + op->priv->reverse_flag, + op->priv->crop_marks_flag); + } + else + { + if (op->priv->collate_flag) + { + gl_print_collated_merge_sheet (op->priv->label, + cr, + page_nr, + op->priv->n_copies, + op->priv->first, + op->priv->outline_flag, + op->priv->reverse_flag, + op->priv->crop_marks_flag, + &op->priv->state); + } + else + { + gl_print_uncollated_merge_sheet (op->priv->label, + cr, + page_nr, + op->priv->n_copies, + op->priv->first, + op->priv->outline_flag, + op->priv->reverse_flag, + op->priv->crop_marks_flag, + &op->priv->state); + } + } +} + + +/*****************************************************************************/ +/* Set outline flag/checkbox. */ +/*****************************************************************************/ +void +gl_print_op_force_outline_flag (glPrintOp *op) +{ + op->priv->force_outline_flag = TRUE; +} + + diff --git a/glabels2/src/print-op.h b/glabels2/src/print-op.h new file mode 100644 index 00000000..cd82158b --- /dev/null +++ b/glabels2/src/print-op.h @@ -0,0 +1,79 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ + +/* + * (GLABELS) Label and Business Card Creation program for GNOME + * + * print-op.h: Print operation module header file + * + * Copyright (C) 2001-2007 Jim Evins . + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PRINT_OP_H__ +#define __PRINT_OP_H__ + +#include +#include "label.h" + +G_BEGIN_DECLS + +#define GL_TYPE_PRINT_OP (gl_print_op_get_type ()) +#define GL_PRINT_OP(obj) (GTK_CHECK_CAST ((obj), GL_TYPE_PRINT_OP, glPrintOp)) +#define GL_PRINT_OP_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_PRINT_OP, glPrintOpClass)) +#define GL_IS_PRINT_OP(obj) (GTK_CHECK_TYPE ((obj), GL_TYPE_PRINT_OP)) +#define GL_IS_PRINT_OP_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_PRINT_OP)) +#define GL_PRINT_OP_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GL_TYPE_PRINT_OP, glPrintOpClass)) + + +typedef struct _glPrintOp glPrintOp; +typedef struct _glPrintOpClass glPrintOpClass; + +typedef struct _glPrintOpPrivate glPrintOpPrivate; + +struct _glPrintOp +{ + GtkPrintOperation parent_instance; + + glPrintOpPrivate *priv; + +}; + +struct _glPrintOpClass +{ + GtkPrintOperationClass parent_class; +}; + + +GType gl_print_op_get_type (void) G_GNUC_CONST; + +glPrintOp *gl_print_op_new (glLabel *label); + +void gl_print_op_force_outline_flag (glPrintOp *print_op); + +/* + * Batch print operation + */ +glPrintOp *gl_print_op_new_batch (glLabel *label, + gchar *filename, + gint n_sheets, + gint n_copies, + gint first, + gboolean outline_flag, + gboolean reverse_flag, + gboolean crop_marks_flag); + +G_END_DECLS + +#endif diff --git a/glabels2/src/print.c b/glabels2/src/print.c index 29dbb642..d3cbd39c 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -382,42 +382,6 @@ gl_print_uncollated_merge_sheet (glLabel *label, gl_debug (DEBUG_PRINT, "END"); } -#ifdef TODO -/*****************************************************************************/ -/* Batch print. Call appropriate function above. */ -/*****************************************************************************/ -void -gl_print_batch (GnomePrintJob *job, - glLabel *label, - gint n_sheets, - gint n_copies, - gint first, - glPrintFlags *flags) -{ - glMerge *merge; - glTemplate *template; - const glTemplateLabelType *label_type; - gint n_per_page; - - gl_debug (DEBUG_PRINT, "START"); - - merge = gl_label_get_merge (label); - template = gl_label_get_template (label); - label_type = gl_template_get_first_label_type (template); - - if ( merge == NULL ) { - n_per_page = gl_template_get_n_labels(label_type); - - gl_print_simple (job, label, n_sheets, first, n_per_page, flags); - } else { - gl_print_merge_collated (job, label, n_copies, first, flags); - } - gl_template_free (template); - - gl_debug (DEBUG_PRINT, "END"); -} -#endif - /*---------------------------------------------------------------------------*/ /* PRIVATE. new print info structure */ /*---------------------------------------------------------------------------*/ diff --git a/glabels2/src/template-designer.c b/glabels2/src/template-designer.c index 43a05fbc..ed03109b 100644 --- a/glabels2/src/template-designer.c +++ b/glabels2/src/template-designer.c @@ -39,7 +39,7 @@ #include #include #include "wdgt-mini-preview.h" -#include "print-dialog.h" +#include "print-op.h" #include "debug.h" @@ -1489,16 +1489,16 @@ print_test_cb (glTemplateDesigner *dlg) { GObject *label; glTemplate *template; - GtkWidget *print_dialog; + glPrintOp *print_op; label = gl_label_new (); template = build_template (dlg); gl_label_set_template (GL_LABEL(label), template); - print_dialog = gl_print_dialog_new (GL_LABEL(label)); - gl_print_dialog_force_outline_flag (GL_PRINT_DIALOG(print_dialog)); - gtk_print_operation_run (GTK_PRINT_OPERATION (print_dialog), + print_op = gl_print_op_new (GL_LABEL(label)); + gl_print_op_force_outline_flag (print_op); + gtk_print_operation_run (GTK_PRINT_OPERATION (print_op), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (dlg), NULL); diff --git a/glabels2/src/ui-commands.c b/glabels2/src/ui-commands.c index a7de525b..72283735 100644 --- a/glabels2/src/ui-commands.c +++ b/glabels2/src/ui-commands.c @@ -35,7 +35,7 @@ #include "view.h" #include "file.h" #include "template-designer.h" -#include "print-dialog.h" +#include "print-op.h" #include "prefs.h" #include "prefs-dialog.h" #include "recent.h" @@ -191,16 +191,16 @@ void gl_ui_cmd_file_print (GtkAction *action, glWindow *window) { - glPrintDialog *dialog; + glPrintOp *op; gl_debug (DEBUG_COMMANDS, "START"); g_return_if_fail (action && GTK_IS_ACTION(action)); g_return_if_fail (window && GL_IS_WINDOW(window)); - dialog = gl_print_dialog_new (GL_VIEW(window->view)->label); + op = gl_print_op_new (GL_VIEW(window->view)->label); - gtk_print_operation_run (GTK_PRINT_OPERATION (dialog), + gtk_print_operation_run (GTK_PRINT_OPERATION (op), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (window), NULL); -- 2.39.5