1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * gnome-print-config-dialog.h: A dialog to configure specific |
---|
4 | * printer settings. |
---|
5 | * |
---|
6 | * NOTE: This interface is considered private and should not be used by |
---|
7 | * applications directly! |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU Library General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 of |
---|
12 | * the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU Library General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU Library General Public |
---|
20 | * License along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
22 | * |
---|
23 | * Authors: |
---|
24 | * Andreas J. Guelzow <aguelzow@taliesin.ca> |
---|
25 | * |
---|
26 | * Copyright (C) 2003 Andreas J. Guelzow |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | #define GNOME_PRINT_UNSTABLE_API |
---|
31 | |
---|
32 | #include <config.h> |
---|
33 | |
---|
34 | #include <time.h> |
---|
35 | #include <atk/atk.h> |
---|
36 | #include <gdk/gdkkeysyms.h> |
---|
37 | #include <gtk/gtk.h> |
---|
38 | |
---|
39 | #include <libgnomeprint/gnome-print-config.h> |
---|
40 | |
---|
41 | #include "gnome-print-i18n.h" |
---|
42 | #include "gnome-printer-selector.h" |
---|
43 | #include "gnome-print-paper-selector.h" |
---|
44 | #include "gnome-print-copies.h" |
---|
45 | #include "gnome-print-dialog.h" |
---|
46 | #include "gnome-print-config-dialog.h" |
---|
47 | #include "gnome-print-config-dialog-private.h" |
---|
48 | #include "gpaui/gpa-option-menu.h" |
---|
49 | |
---|
50 | #define PAD 6 |
---|
51 | |
---|
52 | enum { |
---|
53 | PROP_0, |
---|
54 | PROP_PRINT_CONFIG |
---|
55 | }; |
---|
56 | |
---|
57 | static void gnome_print_config_dialog_class_init (GnomePrintConfigDialogClass *class); |
---|
58 | static void gnome_print_config_dialog_init (GnomePrintConfigDialog *dialog); |
---|
59 | |
---|
60 | static GtkDialogClass *parent_class; |
---|
61 | |
---|
62 | GType |
---|
63 | gnome_print_config_dialog_get_type (void) |
---|
64 | { static GType type = 0; |
---|
65 | if (!type) { |
---|
66 | static const GTypeInfo info = { |
---|
67 | sizeof (GnomePrintConfigDialogClass), |
---|
68 | NULL, NULL, |
---|
69 | (GClassInitFunc) gnome_print_config_dialog_class_init, |
---|
70 | NULL, NULL, |
---|
71 | sizeof (GnomePrintConfigDialog), |
---|
72 | 0, |
---|
73 | (GInstanceInitFunc) gnome_print_config_dialog_init, |
---|
74 | NULL, |
---|
75 | }; |
---|
76 | type = g_type_register_static (GTK_TYPE_DIALOG, "GnomePrintConfigDialog", &info, 0); |
---|
77 | } |
---|
78 | return type; |
---|
79 | } |
---|
80 | |
---|
81 | static void |
---|
82 | gnome_print_config_dialog_destroy (GtkObject *object) |
---|
83 | { |
---|
84 | GnomePrintConfigDialog *gpd; |
---|
85 | |
---|
86 | gpd = GNOME_PRINT_CONFIG_DIALOG (object); |
---|
87 | |
---|
88 | if (gpd->config) { |
---|
89 | gpd->config = gnome_print_config_unref (gpd->config); |
---|
90 | } |
---|
91 | |
---|
92 | if (GTK_OBJECT_CLASS (parent_class)->destroy) |
---|
93 | (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); |
---|
94 | } |
---|
95 | |
---|
96 | static void |
---|
97 | gnome_print_config_dialog_set_property (GObject *object, |
---|
98 | guint prop_id, |
---|
99 | GValue const *value, |
---|
100 | GParamSpec *pspec) |
---|
101 | { |
---|
102 | gpointer new_config; |
---|
103 | GnomePrintConfigDialog *gpd = GNOME_PRINT_CONFIG_DIALOG (object); |
---|
104 | |
---|
105 | switch (prop_id) { |
---|
106 | case PROP_PRINT_CONFIG: |
---|
107 | new_config = g_value_get_pointer (value); |
---|
108 | if (new_config) { |
---|
109 | if (gpd->config) |
---|
110 | gnome_print_config_unref (gpd->config); |
---|
111 | gpd->config = g_value_get_pointer (value); |
---|
112 | gnome_print_config_ref (gpd->config); |
---|
113 | } |
---|
114 | break; |
---|
115 | default: |
---|
116 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | static void |
---|
121 | gnome_print_config_dialog_class_init (GnomePrintConfigDialogClass *class) |
---|
122 | { |
---|
123 | GtkObjectClass *object_class; |
---|
124 | |
---|
125 | object_class = (GtkObjectClass *) class; |
---|
126 | |
---|
127 | parent_class = gtk_type_class (GTK_TYPE_DIALOG); |
---|
128 | |
---|
129 | object_class->destroy = gnome_print_config_dialog_destroy; |
---|
130 | |
---|
131 | G_OBJECT_CLASS (class)->set_property = gnome_print_config_dialog_set_property; |
---|
132 | g_object_class_install_property (G_OBJECT_CLASS (class), |
---|
133 | PROP_PRINT_CONFIG, |
---|
134 | g_param_spec_pointer ("print_config", |
---|
135 | "Print Config", |
---|
136 | "Printing Configuration to be used", |
---|
137 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE)); |
---|
138 | } |
---|
139 | |
---|
140 | static void |
---|
141 | gnome_print_config_dialog_init (GnomePrintConfigDialog *gpd) |
---|
142 | { |
---|
143 | /* Empty */ |
---|
144 | } |
---|
145 | |
---|
146 | static void |
---|
147 | gp_config_dialog_read_from_config (GnomePrintConfigDialog *gpd) |
---|
148 | { |
---|
149 | gboolean tumble = FALSE; |
---|
150 | gboolean duplex = FALSE; |
---|
151 | |
---|
152 | if (gpd->config == NULL) |
---|
153 | return; |
---|
154 | |
---|
155 | gnome_print_config_get_boolean (gpd->config, |
---|
156 | GNOME_PRINT_KEY_DUPLEX, &duplex); |
---|
157 | gnome_print_config_get_boolean (gpd->config, |
---|
158 | GNOME_PRINT_KEY_TUMBLE, &tumble); |
---|
159 | |
---|
160 | gtk_toggle_button_set_active ((GtkToggleButton *) gpd->duplex, duplex); |
---|
161 | gtk_toggle_button_set_active ((GtkToggleButton *) gpd->tumble, tumble); |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | static void |
---|
166 | duplex_toggled (GtkWidget *widget, GnomePrintConfigDialog *gpd) |
---|
167 | { |
---|
168 | gboolean duplex = ((GtkToggleButton *) gpd->duplex)->active; |
---|
169 | GdkPixbuf *pb = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), |
---|
170 | (duplex ? "stock_print-duplex" : "stock_print-non-duplex"), |
---|
171 | 48, 0, NULL); |
---|
172 | if (NULL != pb) { |
---|
173 | gtk_image_set_from_pixbuf (GTK_IMAGE (gpd->duplex_image), pb); |
---|
174 | g_object_unref (G_OBJECT (pb)); |
---|
175 | } |
---|
176 | |
---|
177 | gtk_widget_set_sensitive (gpd->tumble, duplex); |
---|
178 | gtk_widget_set_sensitive (gpd->tumble_image, duplex); |
---|
179 | |
---|
180 | if (widget != NULL && gpd->config) |
---|
181 | gnome_print_config_set_boolean (gpd->config, |
---|
182 | GNOME_PRINT_KEY_DUPLEX, |
---|
183 | duplex); |
---|
184 | } |
---|
185 | |
---|
186 | static void |
---|
187 | tumble_toggled (GtkWidget *widget, GnomePrintConfigDialog *gpd) |
---|
188 | { |
---|
189 | gboolean tumble = ((GtkToggleButton *) gpd->tumble)->active; |
---|
190 | GdkPixbuf *pb = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), |
---|
191 | (tumble ? "stock_print-duplex-tumble" : "stock_print-duplex-no-tumble"), |
---|
192 | 48, 0, NULL); |
---|
193 | if (NULL != pb) { |
---|
194 | gtk_image_set_from_pixbuf (GTK_IMAGE (gpd->tumble_image), pb); |
---|
195 | g_object_unref (G_OBJECT (pb)); |
---|
196 | } |
---|
197 | |
---|
198 | if (widget != NULL && gpd->config) |
---|
199 | gnome_print_config_set_boolean (gpd->config, |
---|
200 | GNOME_PRINT_KEY_TUMBLE, |
---|
201 | tumble); |
---|
202 | } |
---|
203 | |
---|
204 | /** |
---|
205 | * gnome_print_config_dialog_new: |
---|
206 | * |
---|
207 | * Create a new gnome-print-config-dialog window. |
---|
208 | * |
---|
209 | * |
---|
210 | * Return value: A newly created and initialised widget. |
---|
211 | **/ |
---|
212 | GtkWidget * |
---|
213 | gnome_print_config_dialog_new (GnomePrintConfig *gpc) |
---|
214 | { |
---|
215 | GnomePrintConfigDialog *gpd; |
---|
216 | |
---|
217 | gpd = GNOME_PRINT_CONFIG_DIALOG (g_object_new (GNOME_TYPE_PRINT_CONFIG_DIALOG, NULL)); |
---|
218 | |
---|
219 | if (gpd) { |
---|
220 | if (gpc == NULL) |
---|
221 | gpc = gnome_print_config_default (); |
---|
222 | else |
---|
223 | gnome_print_config_ref (gpc); |
---|
224 | gpd->config = gpc; |
---|
225 | gnome_print_config_dialog_construct (gpd); |
---|
226 | } |
---|
227 | |
---|
228 | return GTK_WIDGET (gpd); |
---|
229 | } |
---|
230 | |
---|
231 | /** |
---|
232 | * gnome_print_config_dialog_construct: |
---|
233 | * @gpd: A created GnomePrintConfigDialog. |
---|
234 | * |
---|
235 | * Used for language bindings to post-initialise an object instantiation. |
---|
236 | * |
---|
237 | */ |
---|
238 | void |
---|
239 | gnome_print_config_dialog_construct (GnomePrintConfigDialog *gpd) |
---|
240 | { |
---|
241 | g_return_if_fail (gpd != NULL); |
---|
242 | g_return_if_fail (GNOME_IS_PRINT_CONFIG_DIALOG (gpd)); |
---|
243 | |
---|
244 | gtk_window_set_title (GTK_WINDOW (gpd), |
---|
245 | (const guchar *) _("Default Settings")); |
---|
246 | |
---|
247 | if (gpd->config) { |
---|
248 | GtkWidget *table; |
---|
249 | AtkObject *atko; |
---|
250 | guchar *title; |
---|
251 | |
---|
252 | title = gnome_print_config_get (gpd->config, "Printer"); |
---|
253 | if (title) { |
---|
254 | gtk_window_set_title (GTK_WINDOW (gpd), |
---|
255 | (const gchar *) title); |
---|
256 | g_free (title); |
---|
257 | } |
---|
258 | table = gtk_table_new(2, 2, FALSE); |
---|
259 | gtk_table_set_row_spacings (GTK_TABLE (table), PAD); |
---|
260 | gtk_table_set_col_spacings (GTK_TABLE (table), PAD); |
---|
261 | gtk_container_set_border_width (GTK_CONTAINER (table), PAD); |
---|
262 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (gpd)->vbox), |
---|
263 | table, TRUE, TRUE, 0); |
---|
264 | |
---|
265 | gpd->duplex_image = gtk_image_new (); |
---|
266 | gtk_widget_show (gpd->duplex_image); |
---|
267 | gtk_table_attach_defaults ((GtkTable *)table, |
---|
268 | gpd->duplex_image, 0, 1, 0, 1); |
---|
269 | atko = gtk_widget_get_accessible (gpd->duplex_image); |
---|
270 | atk_image_set_image_description (ATK_IMAGE (atko), |
---|
271 | _("Image showing pages " |
---|
272 | "being printed in " |
---|
273 | "duplex.")); |
---|
274 | |
---|
275 | gpd->duplex = gtk_check_button_new_with_mnemonic (_("_Duplex")); |
---|
276 | gtk_widget_show(gpd->duplex); |
---|
277 | gtk_table_attach_defaults((GtkTable *)table, gpd->duplex, 1, 2, 0, 1); |
---|
278 | |
---|
279 | atko = gtk_widget_get_accessible (gpd->duplex); |
---|
280 | atk_object_set_description (atko, |
---|
281 | _("Pages are printed in duplex.")); |
---|
282 | |
---|
283 | gpd->tumble_image = gtk_image_new (); |
---|
284 | gtk_widget_show (gpd->tumble_image); |
---|
285 | gtk_table_attach_defaults ((GtkTable *)table, |
---|
286 | gpd->tumble_image, 0, 1, 1, 2); |
---|
287 | atko = gtk_widget_get_accessible (gpd->tumble_image); |
---|
288 | atk_image_set_image_description (ATK_IMAGE (atko), |
---|
289 | _("Image showing the second " |
---|
290 | "page of a duplex printed " |
---|
291 | "sequence to be printed " |
---|
292 | "upside down.")); |
---|
293 | |
---|
294 | gpd->tumble = gtk_check_button_new_with_mnemonic (_("_Tumble")); |
---|
295 | gtk_widget_show(gpd->tumble); |
---|
296 | gtk_table_attach_defaults((GtkTable *)table, gpd->tumble, 1, 2, 1, 2); |
---|
297 | |
---|
298 | atko = gtk_widget_get_accessible (gpd->tumble); |
---|
299 | atk_object_set_description (atko, |
---|
300 | _("If copies of the document are " |
---|
301 | "printed in duplex, the second " |
---|
302 | "page is flipped upside down,")); |
---|
303 | g_signal_connect (G_OBJECT (gpd->duplex), "toggled", |
---|
304 | (GCallback) duplex_toggled, gpd); |
---|
305 | g_signal_connect (G_OBJECT (gpd->tumble), "toggled", |
---|
306 | (GCallback) tumble_toggled, gpd); |
---|
307 | |
---|
308 | gp_config_dialog_read_from_config (gpd); |
---|
309 | |
---|
310 | tumble_toggled (NULL, gpd); |
---|
311 | duplex_toggled (NULL, gpd); |
---|
312 | |
---|
313 | /* Print Time */ |
---|
314 | { |
---|
315 | GtkWidget *l, *menu; |
---|
316 | AtkRelationSet *relation_set; |
---|
317 | AtkRelation *relation; |
---|
318 | AtkObject *relation_targets[1]; |
---|
319 | |
---|
320 | l = gtk_label_new_with_mnemonic (_("_Printing Time:")); |
---|
321 | gtk_widget_show(l); |
---|
322 | gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); |
---|
323 | gtk_table_attach_defaults (GTK_TABLE (table), l, |
---|
324 | 0, 1, 2, 3); |
---|
325 | |
---|
326 | menu = gpa_option_menu_new (gpd->config, |
---|
327 | GNOME_PRINT_KEY_HOLD); |
---|
328 | gtk_widget_show(menu); |
---|
329 | gtk_table_attach_defaults (GTK_TABLE (table), menu, |
---|
330 | 1, 2, 2, 3); |
---|
331 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, menu); |
---|
332 | |
---|
333 | atko = gtk_widget_get_accessible (menu); |
---|
334 | relation_set = atk_object_ref_relation_set (atko); |
---|
335 | relation_targets[0] = gtk_widget_get_accessible (l); |
---|
336 | relation = atk_relation_new (relation_targets, 1, |
---|
337 | ATK_RELATION_LABELLED_BY); |
---|
338 | atk_relation_set_add (relation_set, relation); |
---|
339 | g_object_unref (G_OBJECT (relation)); |
---|
340 | g_object_unref (G_OBJECT (relation_set)); |
---|
341 | } |
---|
342 | |
---|
343 | gtk_widget_show(table); |
---|
344 | } else { |
---|
345 | GtkWidget *label; |
---|
346 | label = gtk_label_new (_("Error while loading printer configuration")); |
---|
347 | gtk_widget_show (label); |
---|
348 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (gpd)->vbox), label, TRUE, TRUE, 0); |
---|
349 | } |
---|
350 | |
---|
351 | |
---|
352 | gtk_dialog_add_buttons (GTK_DIALOG (gpd), |
---|
353 | GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
---|
354 | NULL); |
---|
355 | |
---|
356 | |
---|
357 | gtk_dialog_set_default_response (GTK_DIALOG (gpd), GTK_RESPONSE_CLOSE); |
---|
358 | } |
---|
359 | |
---|
360 | |
---|
361 | |
---|