1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * example_12.c: sample gnome-print code to show gnome-print-widget usage |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or |
---|
6 | * modify it under the terms of the GNU Library General Public License |
---|
7 | * as 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 Library General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Library General Public |
---|
16 | * License along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
18 | * |
---|
19 | * Authors: |
---|
20 | * Chema Celorio <chema@ximian.com> |
---|
21 | * |
---|
22 | * Copyright (C) 2002 Ximian Inc. and authors |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | /* |
---|
27 | * See README |
---|
28 | */ |
---|
29 | |
---|
30 | #define GNOME_PRINT_UNSTABLE_API |
---|
31 | |
---|
32 | #include <libgnomeprint/gnome-print.h> |
---|
33 | #include <libgnomeprint/gnome-print-job.h> |
---|
34 | #include <libgnomeprint/gnome-print-config.h> |
---|
35 | #include <gtk/gtkwidget.h> |
---|
36 | #include <gtk/gtkdialog.h> |
---|
37 | #include <gtk/gtkbox.h> |
---|
38 | #include <gtk/gtkmain.h> |
---|
39 | #include <libgnomeprintui/gnome-print-dialog.h> |
---|
40 | #include <libgnomeprintui/gnome-print-widget.h> |
---|
41 | #include <libgnomeprintui/gnome-print-i18n.h> |
---|
42 | |
---|
43 | GnomePrintConfigOption frames [] = { |
---|
44 | {"AsDisplayed", N_("As _displayed"), 0}, |
---|
45 | {"SelectedFrame", N_("_Selected Frame"), 1}, |
---|
46 | {"Separately", N_("Print each frame _separately"), 2}, |
---|
47 | {NULL} |
---|
48 | }; |
---|
49 | |
---|
50 | GnomePrintConfigOption colors [] = { |
---|
51 | {"Color", N_("_Color"), 0}, |
---|
52 | {"Grayscale", N_("_Black and white"), 1}, |
---|
53 | {NULL} |
---|
54 | }; |
---|
55 | |
---|
56 | static void |
---|
57 | add_custom_options (GnomePrintConfig *config) |
---|
58 | { |
---|
59 | gnome_print_config_insert_boolean ( |
---|
60 | config, "Settings.Application.PageTitle", TRUE); |
---|
61 | gnome_print_config_insert_boolean ( |
---|
62 | config, "Settings.Application.PageURL", TRUE); |
---|
63 | gnome_print_config_insert_boolean ( |
---|
64 | config, "Settings.Application.PageNumbers", TRUE); |
---|
65 | gnome_print_config_insert_boolean ( |
---|
66 | config, "Settings.Application.Date", TRUE); |
---|
67 | |
---|
68 | gnome_print_config_insert_options ( |
---|
69 | config, "Settings.Application.Color", |
---|
70 | colors, "Color"); |
---|
71 | gnome_print_config_insert_options ( |
---|
72 | config, "Settings.Application.FrameType", |
---|
73 | frames, "AsDisplayed"); |
---|
74 | } |
---|
75 | |
---|
76 | static GtkDialog * |
---|
77 | add_custom_widgets (GnomePrintConfig *config) |
---|
78 | { |
---|
79 | GtkWidget *w1, *w2, *w3, *w4, *w5, *w6; |
---|
80 | GtkWidget *dialog; |
---|
81 | GtkBox *box; |
---|
82 | |
---|
83 | dialog = gtk_dialog_new (); |
---|
84 | box = GTK_BOX (GTK_DIALOG (dialog)->vbox); |
---|
85 | |
---|
86 | w1 = gnome_print_checkbutton_new ( |
---|
87 | config, "Settings.Application.PageTitle", _("Add page title")); |
---|
88 | w2 = gnome_print_checkbutton_new ( |
---|
89 | config, "Settings.Application.PageURL", _("Add page URL")); |
---|
90 | w3 = gnome_print_checkbutton_new ( |
---|
91 | config, "Settings.Application.PageNumbers", _("Show page numbers")); |
---|
92 | w4 = gnome_print_checkbutton_new ( |
---|
93 | config, "Settings.Application.Date", _("Show date")); |
---|
94 | |
---|
95 | w5 = gnome_print_radiobutton_new ( |
---|
96 | config, "Settings.Application.Color", colors); |
---|
97 | w6 = gnome_print_radiobutton_new ( |
---|
98 | config, "Settings.Application.FrameType", frames); |
---|
99 | |
---|
100 | gtk_box_pack_start (box, w1, TRUE, TRUE, 0); |
---|
101 | gtk_box_pack_start (box, w2, TRUE, TRUE, 0); |
---|
102 | gtk_box_pack_start (box, w3, TRUE, TRUE, 0); |
---|
103 | gtk_box_pack_start (box, w4, TRUE, TRUE, 0); |
---|
104 | gtk_box_pack_start (box, w5, TRUE, TRUE, 0); |
---|
105 | gtk_box_pack_start (box, w6, TRUE, TRUE, 0); |
---|
106 | |
---|
107 | gtk_widget_show_all (dialog); |
---|
108 | |
---|
109 | return GTK_DIALOG (dialog); |
---|
110 | } |
---|
111 | |
---|
112 | static void |
---|
113 | dump_custom_options (GnomePrintConfig *config) |
---|
114 | { |
---|
115 | gboolean state = FALSE; |
---|
116 | gint index; |
---|
117 | gchar *id; |
---|
118 | |
---|
119 | state = TRUE; |
---|
120 | gnome_print_config_get_boolean (config, "Settings.Application.PageTitle", &state); |
---|
121 | g_print ("Page title: %s\n", state ? "yes" : "no"); |
---|
122 | |
---|
123 | state = TRUE; |
---|
124 | gnome_print_config_get_boolean (config, "Settings.Application.PageURL", &state); |
---|
125 | g_print ("Page url: %s\n", state ? "yes" : "no"); |
---|
126 | |
---|
127 | state = TRUE; |
---|
128 | gnome_print_config_get_boolean (config, "Settings.Application.PageNumbers", &state); |
---|
129 | g_print ("Page num.: %s\n", state ? "yes" : "no"); |
---|
130 | |
---|
131 | state = TRUE; |
---|
132 | gnome_print_config_get_boolean (config, "Settings.Application.Date", &state); |
---|
133 | g_print ("Print date: %s\n", state ? "yes" : "no"); |
---|
134 | |
---|
135 | index = 0; |
---|
136 | gnome_print_config_get_option (config, "Settings.Application.Color", colors, &index); |
---|
137 | g_print ("Color by index: %d\n", index); |
---|
138 | |
---|
139 | id = gnome_print_config_get (config, "Settings.Application.Color"); |
---|
140 | g_print ("Color by id: %s\n", id); |
---|
141 | |
---|
142 | index = 0; |
---|
143 | gnome_print_config_get_option (config, "Settings.Application.FrameType", frames, &index); |
---|
144 | g_print ("Frame type by index: %d\n", index); |
---|
145 | |
---|
146 | id = gnome_print_config_get (config, "Settings.Application.FrameType"); |
---|
147 | g_print ("Frame type by id : %s\n", id); |
---|
148 | } |
---|
149 | |
---|
150 | static void |
---|
151 | my_print (void) |
---|
152 | { |
---|
153 | GnomePrintJob *job; |
---|
154 | GnomePrintConfig *config; |
---|
155 | GtkDialog *d; |
---|
156 | |
---|
157 | job = gnome_print_job_new (NULL); |
---|
158 | config = gnome_print_job_get_config (job); |
---|
159 | |
---|
160 | add_custom_options (config); |
---|
161 | d = add_custom_widgets (config); |
---|
162 | gtk_window_move (GTK_WINDOW (d), 10, 10); |
---|
163 | d = add_custom_widgets (config); |
---|
164 | |
---|
165 | gtk_dialog_run (d); |
---|
166 | |
---|
167 | gnome_print_config_dump (config); |
---|
168 | dump_custom_options (config); |
---|
169 | |
---|
170 | g_object_unref (config); |
---|
171 | g_object_unref (job); |
---|
172 | } |
---|
173 | |
---|
174 | int |
---|
175 | main (int argc, char * argv[]) |
---|
176 | { |
---|
177 | gtk_init (&argc, &argv); |
---|
178 | |
---|
179 | my_print (); |
---|
180 | |
---|
181 | g_print ("Done...\n"); |
---|
182 | |
---|
183 | return 0; |
---|
184 | } |
---|