]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Added possibility to set other printer settings (closes #177).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 3 Nov 2011 15:50:20 +0000 (16:50 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 3 Nov 2011 15:50:20 +0000 (16:50 +0100)
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
src/rptprint.c
src/rptprint.h
tests/rptreport.c

index 1ecd6c2c72535682a227ad33d6fc95bf78aaa9a5..35f15c658a56e4daa934ad4d2f79606c2964568f 100644 (file)
@@ -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])
 
index e833555ffabdc772dfea35c735e4f6db4343fe98..63f69b75704cf79c5cc0778bb21136798fdf587c 100644 (file)
@@ -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
index 19972c4bffc0931b11273797beddedc1b589c642..434f4c7f3008e54f59663aeeeb42c61c0465ab5a 100644 (file)
@@ -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);
index bc0dfded65636617b065c5c869bfc5951fa863fb..e0245f0d5314f7a824e68555d4b4d7fd349d7e3f 100644 (file)
@@ -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