1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #include "config.h"
19 
20 #include <libgimp/gimp.h>
21 #include <libgimp/gimpui.h>
22 
23 #include "print.h"
24 #include "print-page-setup.h"
25 #include "print-utils.h"
26 
27 #define PRINT_PAGE_SETUP_NAME  "print-page-setup"
28 
29 
30 #ifndef EMBED_PAGE_SETUP
31 void
print_page_setup_dialog(GtkPrintOperation * operation)32 print_page_setup_dialog (GtkPrintOperation *operation)
33 {
34   GtkPrintSettings *settings;
35   GtkPageSetup     *setup;
36 
37   g_return_if_fail (GTK_IS_PRINT_OPERATION (operation));
38 
39   setup = gtk_print_operation_get_default_page_setup (operation);
40 
41   settings = gtk_print_settings_new ();
42   setup = gtk_print_run_page_setup_dialog (NULL, setup, settings);
43   g_object_unref (settings);
44 
45   gtk_print_operation_set_default_page_setup (operation, setup);
46 }
47 #endif
48 
49 void
print_page_setup_load(GtkPrintOperation * operation,gint32 image_ID)50 print_page_setup_load (GtkPrintOperation *operation,
51                        gint32             image_ID)
52 {
53   GKeyFile *key_file;
54 
55   g_return_if_fail (GTK_IS_PRINT_OPERATION (operation));
56 
57   key_file = print_utils_key_file_load_from_parasite (image_ID,
58                                                       PRINT_PAGE_SETUP_NAME);
59 
60   if (! key_file)
61     key_file = print_utils_key_file_load_from_rcfile (PRINT_PAGE_SETUP_NAME);
62 
63   if (key_file)
64     {
65       GtkPageSetup *setup;
66 
67       setup = gtk_page_setup_new_from_key_file (key_file,
68                                                 PRINT_PAGE_SETUP_NAME, NULL);
69 
70       if (setup)
71         {
72           gtk_print_operation_set_default_page_setup (operation, setup);
73           g_object_unref (setup);
74         }
75 
76       g_key_file_free (key_file);
77     }
78 }
79 
80 void
print_page_setup_save(GtkPrintOperation * operation,gint32 image_ID)81 print_page_setup_save (GtkPrintOperation *operation,
82                        gint32             image_ID)
83 {
84   GtkPageSetup *setup;
85   GKeyFile     *key_file;
86 
87   g_return_if_fail (GTK_IS_PRINT_OPERATION (operation));
88 
89   key_file = g_key_file_new ();
90 
91   setup = gtk_print_operation_get_default_page_setup (operation);
92 
93   gtk_page_setup_to_key_file (setup, key_file, PRINT_PAGE_SETUP_NAME);
94 
95   print_utils_key_file_save_as_parasite (key_file,
96                                          image_ID, PRINT_PAGE_SETUP_NAME);
97   print_utils_key_file_save_as_rcfile (key_file,
98                                        PRINT_PAGE_SETUP_NAME);
99 
100   g_key_file_free (key_file);
101 }
102