GnuCash  5.6-150-g038405b370+
print-session.c
1 /********************************************************************\
2  * print-session.c -- simple printing manager for gnucash *
3  * Copyright (C) 2000 Bill Gribble <grib@billgribble.com> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA gnu@gnu.org *
21 \********************************************************************/
22 
23 #include <config.h>
24 
25 #include <gtk/gtk.h>
26 
27 #include "print-session.h"
28 
29 #undef G_LOG_DOMAIN
30 #define G_LOG_DOMAIN "gnc.printing"
31 
32 static GtkPrintSettings *print_settings = NULL;
33 static GtkPageSetup *page_setup = NULL;
34 G_LOCK_DEFINE_STATIC(print_settings);
35 G_LOCK_DEFINE_STATIC(page_setup);
36 
37 
38 void
40 {
41  g_return_if_fail(op);
42 
43  G_LOCK(print_settings);
44  if (print_settings)
45  g_object_unref(print_settings);
46  print_settings = g_object_ref(gtk_print_operation_get_print_settings(op));
47  G_UNLOCK(print_settings);
48 }
49 
50 void
51 gnc_print_operation_init(GtkPrintOperation *op, const gchar* jobname)
52 {
53  g_return_if_fail(op);
54 
55  /* Restore print settings */
56  G_LOCK(print_settings);
57  if (print_settings)
58  gtk_print_operation_set_print_settings(op, print_settings);
59  G_UNLOCK(print_settings);
60 
61  /* Restore page setup */
62  G_LOCK(page_setup);
63  if (page_setup)
64  gtk_print_operation_set_default_page_setup(op, page_setup);
65  G_UNLOCK(page_setup);
66 
67  gtk_print_operation_set_job_name ( op, jobname);
68 }
69 
70 void
71 gnc_ui_page_setup(GtkWindow *parent)
72 {
73  GtkPrintSettings *settings = NULL;
74  GtkPageSetup *old_page_setup, *new_page_setup;
75 
76  /* Get a reference to the current print settings */
77  G_LOCK(print_settings);
78  settings = print_settings;
79  if (settings)
80  g_object_ref(settings);
81  G_UNLOCK(print_settings);
82 
83  /* Get a reference to the current page setup */
84  G_LOCK(page_setup);
85  old_page_setup = page_setup;
86  if (old_page_setup)
87  g_object_ref(old_page_setup);
88  G_UNLOCK(page_setup);
89 
90  /* Run dialog */
91  new_page_setup = gtk_print_run_page_setup_dialog(parent, old_page_setup,
92  settings);
93 
94  /* Save new page setup */
95  G_LOCK(page_setup);
96  if (page_setup)
97  g_object_unref(page_setup);
98  page_setup = new_page_setup;
99  G_UNLOCK(page_setup);
100 
101  /* Release references */
102  if (settings)
103  g_object_unref(settings);
104  if (old_page_setup)
105  g_object_unref(old_page_setup);
106 }
107 
108 GtkPrintSettings *gnc_print_get_settings()
109 {
110  return print_settings;
111 }
void gnc_print_operation_save_print_settings(GtkPrintOperation *op)
Retrieve the print settings from the GtkPrintOperation op and save them in a static variable...
Definition: print-session.c:39
void gnc_ui_page_setup(GtkWindow *parent)
Run a page setup dialog and save the resulting GtkPageSetup in a static variable. ...
Definition: print-session.c:71
void gnc_print_operation_init(GtkPrintOperation *op, const gchar *jobname)
If print settings have been saved by gnc_print_operation_save_print_settings(), then set them on the ...
Definition: print-session.c:51
GtkPrintSettings * gnc_print_get_settings()
Returns the pointer to our static GtkPrintSettings object.