From ab9728d41fddeeedda3a470ec256311a8be7d037 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 3 Nov 2011 16:50:20 +0100 Subject: [PATCH] Added possibility to set other printer settings (closes #177). Also the printer can be set. Some options work only when RPT_OUTPUT_GTK_DEFAULT_PRINTER (for example the printer). Setted version 0.2.2. --- configure.ac | 2 +- src/rptprint.c | 53 +++++++++++++++++++++++++++++++++++++---------- src/rptprint.h | 1 + tests/rptreport.c | 38 +++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 1ecd6c2..35f15c6 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libreptool], [0.2.1], [azagli@libero.it]) +AC_INIT([libreptool], [0.2.2], [azagli@libero.it]) AC_CONFIG_SRCDIR([src/rptprint.c]) AC_CONFIG_HEADER([config.h]) diff --git a/src/rptprint.c b/src/rptprint.c index e833555..63f69b7 100644 --- a/src/rptprint.c +++ b/src/rptprint.c @@ -113,7 +113,7 @@ struct _RptPrintPrivate eRptOutputType output_type; gchar *output_filename; - guint copies; + GtkPrintSettings *gtk_print_settings; gdouble width; gdouble height; @@ -192,6 +192,7 @@ rpt_print_init (RptPrint *rpt_print) priv->surface = NULL; priv->cr = NULL; priv->gtk_print_context = NULL; + priv->gtk_print_settings = NULL; } /** @@ -297,11 +298,33 @@ rpt_print_set_output_filename (RptPrint *rpt_print, const gchar *output_filename } } +/** + * rpt_print_set_gtkprintsettings: + * @rpt_print: an #RptPrint object. + * @settings: a #GtkPrintSettings object. + * + */ +void +rpt_print_set_gtkprintsettings (RptPrint *rpt_print, GtkPrintSettings *settings) +{ + g_return_if_fail (IS_RPT_PRINT (rpt_print)); + g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings)); + + RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print); + + if (GTK_IS_PRINT_SETTINGS (priv->gtk_print_settings)) + { + g_object_unref (priv->gtk_print_settings); + } + priv->gtk_print_settings = gtk_print_settings_copy (settings); +} + /** * rpt_print_set_copies: * @rpt_print: an #RptPrint object. * @copies: number of copies. * + * Deprecated:0.2.2: use rpt_print_set_gtkprintsettings() instead. */ void rpt_print_set_copies (RptPrint *rpt_print, guint copies) @@ -310,7 +333,11 @@ rpt_print_set_copies (RptPrint *rpt_print, guint copies) RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print); - priv->copies = copies; + if (!GTK_IS_PRINT_SETTINGS (priv->gtk_print_settings)) + { + priv->gtk_print_settings = gtk_print_settings_new (); + } + gtk_print_settings_set_n_copies (priv->gtk_print_settings, copies); } /** @@ -423,6 +450,11 @@ rpt_print_print (RptPrint *rpt_print, GtkWindow *transient) g_signal_connect (G_OBJECT (operation), "draw-page", G_CALLBACK (rpt_print_gtk_draw_page), (gpointer)rpt_print); + if (GTK_IS_PRINT_SETTINGS (priv->gtk_print_settings)) + { + gtk_print_operation_set_print_settings (operation, priv->gtk_print_settings); + } + error = NULL; locale_num = setlocale (LC_NUMERIC, "C"); res = gtk_print_operation_run (operation, @@ -647,7 +679,14 @@ rpt_print_get_property (GObject *object, guint property_id, GValue *value, GPara break; case PROP_COPIES: - g_value_set_uint (value, priv->copies); + if (priv->gtk_print_settings != NULL) + { + g_value_set_uint (value, gtk_print_settings_get_n_copies (priv->gtk_print_settings)); + } + else + { + g_value_set_uint (value, 1); + } break; case PROP_PATH_RELATIVES_TO: @@ -1556,14 +1595,6 @@ rpt_print_gtk_begin_print (GtkPrintOperation *operation, gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS); gtk_print_operation_set_n_pages (operation, priv->pages->nodeNr); - - GtkPrintSettings *settings = gtk_print_operation_get_print_settings (operation); - if (settings == NULL) - { - settings = gtk_print_settings_new (); - } - gtk_print_settings_set_n_copies (settings, priv->copies); - gtk_print_operation_set_print_settings (operation, settings); } static void diff --git a/src/rptprint.h b/src/rptprint.h index 19972c4..434f4c7 100644 --- a/src/rptprint.h +++ b/src/rptprint.h @@ -60,6 +60,7 @@ RptPrint *rpt_print_new_from_file (const gchar *filename); void rpt_print_set_output_type (RptPrint *rpt_print, eRptOutputType output_type); void rpt_print_set_output_filename (RptPrint *rpt_print, const gchar *output_filename); +void rpt_print_set_gtkprintsettings (RptPrint *rpt_print, GtkPrintSettings *settings); void rpt_print_set_copies (RptPrint *rpt_print, guint copies); void rpt_print_print (RptPrint *rpt_print, GtkWindow *transient); diff --git a/tests/rptreport.c b/tests/rptreport.c index bc0dfde..e0245f0 100644 --- a/tests/rptreport.c +++ b/tests/rptreport.c @@ -25,6 +25,8 @@ static gchar *xml_rptr_file_name = NULL; static gchar *path_relatives_to = NULL; static gchar *output_type = NULL; static gchar *output_file_name = NULL; +static gchar *printer_name = NULL; +static gint copies = 1; static GOptionEntry entries[] = { @@ -34,6 +36,8 @@ static GOptionEntry entries[] = { "path-relatives-to", 't', 0, G_OPTION_ARG_FILENAME, &path_relatives_to, "Path relatives to", "FILE-NAME" }, { "output-type", 'o', 0, G_OPTION_ARG_STRING, &output_type, "Output type (png | pdf | ps | svg | gtk | gtk-default)", "OUTPUT-TYPE" }, { "output-file-name", 'f', 0, G_OPTION_ARG_FILENAME, &output_file_name, "Output file name", "FILE-NAME" }, + { "printer-name", 0, 0, G_OPTION_ARG_STRING, &printer_name, "Printer name", "PRINTER-NAME" }, + { "copies", 0, 0, G_OPTION_ARG_INT, &copies, "Number of copies", "N_COPIES" }, { NULL } }; @@ -73,6 +77,8 @@ main (int argc, char **argv) RptReport *rptr; RptPrint *rptp; + GtkPrintSettings *settings; + g_type_init (); context = g_option_context_new ("- test rptprint"); @@ -97,6 +103,15 @@ main (int argc, char **argv) if (rptr != NULL) { + rpt_report_set_output_type (rptr, rpt_common_stroutputtype_to_enum (output_type)); + if (g_strcmp0 (output_type, "png") == 0 + || g_strcmp0 (output_type, "pdf") == 0 + || g_strcmp0 (output_type, "ps") == 0 + || g_strcmp0 (output_type, "svg") == 0) + { + rpt_report_set_output_filename (rptr, output_file_name == NULL ? g_strdup_printf ("test.%s", output_type) : output_file_name); + } + xmlDoc *report = rpt_report_get_xml (rptr); if (xml_rpt_file_name != NULL) { @@ -125,6 +140,29 @@ main (int argc, char **argv) { rpt_print_set_output_filename (rptp, output_file_name == NULL ? g_strdup_printf ("test.%s", output_type) : output_file_name); } + + if (printer_name != NULL) + { + if (!GTK_IS_PRINT_SETTINGS (settings)) + { + settings = gtk_print_settings_new (); + } + gtk_print_settings_set_printer (settings, printer_name); + } + if (copies > 1) + { + if (!GTK_IS_PRINT_SETTINGS (settings)) + { + settings = gtk_print_settings_new (); + } + gtk_print_settings_set_n_copies (settings, copies); + } + + if (GTK_IS_PRINT_SETTINGS (settings)) + { + rpt_print_set_gtkprintsettings (rptp, settings); + } + rpt_print_print (rptp, NULL); } else -- 2.49.0