2 * Copyright (C) 2006 John (J5) Palmieri <johnp@redhat.com>
3 * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
4 * Copyright © 2006, 2007 Christian Persch
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
30 #include "gtkprivate.h"
32 #include "gtkspinbutton.h"
33 #include "gtkcellrendererpixbuf.h"
34 #include "gtkcellrenderertext.h"
36 #include "gtkiconfactory.h"
38 #include "gtktreeselection.h"
39 #include "gtknotebook.h"
40 #include "gtkscrolledwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtktogglebutton.h"
43 #include "gtkradiobutton.h"
44 #include "gtkdrawingarea.h"
48 #include "gtkalignment.h"
50 #include "gtkeventbox.h"
51 #include "gtkbuildable.h"
53 #include "gtkprintbackend.h"
54 #include "gtkprinter-private.h"
55 #include "gtkprintunixdialog.h"
56 #include "gtkprinteroptionwidget.h"
59 #include "gtkmessagedialog.h"
60 #include "gtkbutton.h"
62 #define EXAMPLE_PAGE_AREA_SIZE 140
64 #define GTK_PRINT_UNIX_DIALOG_GET_PRIVATE(o) \
65 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PRINT_UNIX_DIALOG, GtkPrintUnixDialogPrivate))
67 static void gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog);
68 static void gtk_print_unix_dialog_finalize (GObject *object);
69 static void gtk_print_unix_dialog_set_property (GObject *object,
73 static void gtk_print_unix_dialog_get_property (GObject *object,
77 static void gtk_print_unix_dialog_style_set (GtkWidget *widget,
78 GtkStyle *previous_style);
79 static void populate_dialog (GtkPrintUnixDialog *dialog);
80 static void unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog);
81 static void selected_printer_changed (GtkTreeSelection *selection,
82 GtkPrintUnixDialog *dialog);
83 static void clear_per_printer_ui (GtkPrintUnixDialog *dialog);
84 static void printer_added_cb (GtkPrintBackend *backend,
86 GtkPrintUnixDialog *dialog);
87 static void printer_removed_cb (GtkPrintBackend *backend,
89 GtkPrintUnixDialog *dialog);
90 static void printer_status_cb (GtkPrintBackend *backend,
92 GtkPrintUnixDialog *dialog);
93 static void update_collate_icon (GtkToggleButton *toggle_button,
94 GtkPrintUnixDialog *dialog);
95 static gboolean dialog_get_collate (GtkPrintUnixDialog *dialog);
96 static gboolean dialog_get_reverse (GtkPrintUnixDialog *dialog);
97 static gint dialog_get_n_copies (GtkPrintUnixDialog *dialog);
99 static void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
100 GtkCellRenderer *cell,
104 static gboolean set_active_printer (GtkPrintUnixDialog *dialog,
105 const gchar *printer_name);
108 static void gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface);
109 static GObject *gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
111 const gchar *childname);
118 PROP_SELECTED_PRINTER,
119 PROP_MANUAL_CAPABILITIES,
120 PROP_SUPPORT_SELECTION,
125 PRINTER_LIST_COL_ICON,
126 PRINTER_LIST_COL_NAME,
127 PRINTER_LIST_COL_STATE,
128 PRINTER_LIST_COL_JOBS,
129 PRINTER_LIST_COL_LOCATION,
130 PRINTER_LIST_COL_PRINTER_OBJ,
134 struct GtkPrintUnixDialogPrivate
138 GtkWidget *printer_treeview;
140 GtkPrintCapabilities manual_capabilities;
141 GtkPrintCapabilities printer_capabilities;
143 GtkTreeModel *printer_list;
144 GtkTreeModelFilter *printer_list_filter;
146 GtkPageSetup *page_setup;
147 gboolean page_setup_set;
149 gboolean support_selection;
150 gboolean has_selection;
152 GtkWidget *all_pages_radio;
153 GtkWidget *current_page_radio;
154 GtkWidget *selection_radio;
155 GtkWidget *range_table;
156 GtkWidget *page_range_radio;
157 GtkWidget *page_range_entry;
159 GtkWidget *copies_spin;
160 GtkWidget *collate_check;
161 GtkWidget *reverse_check;
162 GtkWidget *collate_image;
163 GtkWidget *page_layout_preview;
164 GtkWidget *scale_spin;
165 GtkWidget *page_set_combo;
166 GtkWidget *print_now_radio;
167 GtkWidget *print_at_radio;
168 GtkWidget *print_at_entry;
169 GtkWidget *print_hold_radio;
170 GtkWidget *preview_button;
171 gboolean updating_print_at;
172 GtkPrinterOptionWidget *pages_per_sheet;
173 GtkPrinterOptionWidget *duplex;
174 GtkPrinterOptionWidget *paper_type;
175 GtkPrinterOptionWidget *paper_source;
176 GtkPrinterOptionWidget *output_tray;
177 GtkPrinterOptionWidget *job_prio;
178 GtkPrinterOptionWidget *billing_info;
179 GtkPrinterOptionWidget *cover_before;
180 GtkPrinterOptionWidget *cover_after;
181 GtkPrinterOptionWidget *number_up_layout;
183 GtkWidget *conflicts_widget;
186 GtkWidget *finishing_table;
187 GtkWidget *finishing_page;
188 GtkWidget *image_quality_table;
189 GtkWidget *image_quality_page;
190 GtkWidget *color_table;
191 GtkWidget *color_page;
193 GtkWidget *advanced_vbox;
194 GtkWidget *advanced_page;
196 GtkWidget *extension_point;
198 /* These are set initially on selected printer (either default printer,
199 * printer taken from set settings, or user-selected), but when any setting
200 * is changed by the user it is cleared.
202 GtkPrintSettings *initial_settings;
204 GtkPrinterOption *number_up_layout_n_option;
205 GtkPrinterOption *number_up_layout_2_option;
207 /* This is the initial printer set by set_settings. We look for it in the
208 * added printers. We clear this whenever the user manually changes
209 * to another printer, when the user changes a setting or when we find
212 char *waiting_for_printer;
213 gboolean internal_printer_change;
215 GList *print_backends;
217 GtkPrinter *current_printer;
218 GtkPrinter *request_details_printer;
219 guint request_details_tag;
220 GtkPrinterOptionSet *options;
221 gulong options_changed_handler;
222 gulong mark_conflicts_id;
224 gchar *format_for_printer;
229 G_DEFINE_TYPE_WITH_CODE (GtkPrintUnixDialog, gtk_print_unix_dialog, GTK_TYPE_DIALOG,
230 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
231 gtk_print_unix_dialog_buildable_init))
233 static GtkBuildableIface *parent_buildable_iface;
236 is_default_printer (GtkPrintUnixDialog *dialog,
239 GtkPrintUnixDialogPrivate *priv = dialog->priv;
241 if (priv->format_for_printer)
242 return strcmp (priv->format_for_printer,
243 gtk_printer_get_name (printer)) == 0;
245 return gtk_printer_is_default (printer);
249 gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
251 GObjectClass *object_class;
252 GtkWidgetClass *widget_class;
254 object_class = (GObjectClass *) class;
255 widget_class = (GtkWidgetClass *) class;
257 object_class->finalize = gtk_print_unix_dialog_finalize;
258 object_class->set_property = gtk_print_unix_dialog_set_property;
259 object_class->get_property = gtk_print_unix_dialog_get_property;
261 widget_class->style_set = gtk_print_unix_dialog_style_set;
263 g_object_class_install_property (object_class,
265 g_param_spec_object ("page-setup",
267 P_("The GtkPageSetup to use"),
269 GTK_PARAM_READWRITE));
271 g_object_class_install_property (object_class,
273 g_param_spec_int ("current-page",
275 P_("The current page in the document"),
279 GTK_PARAM_READWRITE));
281 g_object_class_install_property (object_class,
283 g_param_spec_object ("print-settings",
284 P_("Print Settings"),
285 P_("The GtkPrintSettings used for initializing the dialog"),
286 GTK_TYPE_PRINT_SETTINGS,
287 GTK_PARAM_READWRITE));
289 g_object_class_install_property (object_class,
290 PROP_SELECTED_PRINTER,
291 g_param_spec_object ("selected-printer",
292 P_("Selected Printer"),
293 P_("The GtkPrinter which is selected"),
295 GTK_PARAM_READABLE));
297 g_object_class_install_property (object_class,
298 PROP_MANUAL_CAPABILITIES,
299 g_param_spec_flags ("manual-capabilities",
300 P_("Manual Capabilites"),
301 P_("Capabilities the application can handle"),
302 GTK_TYPE_PRINT_CAPABILITIES,
304 GTK_PARAM_READWRITE));
306 g_object_class_install_property (object_class,
307 PROP_SUPPORT_SELECTION,
308 g_param_spec_boolean ("support-selection",
309 P_("Support Selection"),
310 P_("Whether the dialog supports selection"),
312 GTK_PARAM_READWRITE));
314 g_object_class_install_property (object_class,
316 g_param_spec_boolean ("has-selection",
318 P_("Whether the application has a selection"),
320 GTK_PARAM_READWRITE));
323 g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));
326 /* Returns a toplevel GtkWindow, or NULL if none */
328 get_toplevel (GtkWidget *widget)
330 GtkWidget *toplevel = NULL;
332 toplevel = gtk_widget_get_toplevel (widget);
333 if (!GTK_WIDGET_TOPLEVEL (toplevel))
336 return GTK_WINDOW (toplevel);
340 add_custom_button_to_dialog (GtkDialog *dialog,
341 const gchar *mnemonic_label,
342 const gchar *stock_id,
345 GtkWidget *button = NULL;
347 button = gtk_button_new_with_mnemonic (mnemonic_label);
348 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
349 gtk_button_set_image (GTK_BUTTON (button),
350 gtk_image_new_from_stock (stock_id,
351 GTK_ICON_SIZE_BUTTON));
352 gtk_widget_show (button);
354 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
357 /* This function handles error messages before printing.
360 error_dialogs (GtkPrintUnixDialog *print_dialog,
361 gint print_dialog_response_id,
364 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
365 GtkPrinterOption *option = NULL;
366 GtkPrinter *printer = NULL;
367 GtkWindow *toplevel = NULL;
368 GtkWidget *dialog = NULL;
370 gchar *basename = NULL;
371 gchar *dirname = NULL;
374 if (print_dialog != NULL && print_dialog_response_id == GTK_RESPONSE_OK)
376 printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
378 /* Shows overwrite confirmation dialog in the case of printing to file which
380 if (printer != NULL && gtk_printer_is_virtual (printer))
382 option = gtk_printer_option_set_lookup (priv->options,
383 "gtk-main-page-custom-input");
385 if (option != NULL &&
386 option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE)
388 file = g_file_new_for_uri (option->value);
391 g_file_query_exists (file, NULL))
393 toplevel = get_toplevel (GTK_WIDGET (print_dialog));
395 basename = g_file_get_basename (file);
396 dirname = g_file_get_parse_name (g_file_get_parent (file));
398 dialog = gtk_message_dialog_new (toplevel,
400 GTK_DIALOG_DESTROY_WITH_PARENT,
401 GTK_MESSAGE_QUESTION,
403 _("A file named \"%s\" already exists. Do you want to replace it?"),
406 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
407 _("The file already exists in \"%s\". Replacing it will "
408 "overwrite its contents."),
411 gtk_dialog_add_button (GTK_DIALOG (dialog),
412 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
413 add_custom_button_to_dialog (GTK_DIALOG (dialog),
416 GTK_RESPONSE_ACCEPT);
417 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
421 gtk_dialog_set_default_response (GTK_DIALOG (dialog),
422 GTK_RESPONSE_ACCEPT);
425 gtk_window_group_add_window (toplevel->group,
426 GTK_WINDOW (dialog));
428 response = gtk_dialog_run (GTK_DIALOG (dialog));
430 gtk_widget_destroy (dialog);
435 if (response != GTK_RESPONSE_ACCEPT)
437 g_signal_stop_emission_by_name (print_dialog, "response");
438 g_object_unref (file);
443 g_object_unref (file);
451 gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
453 GtkPrintUnixDialogPrivate *priv = dialog->priv;
455 priv = dialog->priv = GTK_PRINT_UNIX_DIALOG_GET_PRIVATE (dialog);
456 priv->print_backends = NULL;
457 priv->current_page = -1;
458 priv->number_up_layout_n_option = NULL;
459 priv->number_up_layout_2_option = NULL;
461 priv->page_setup = gtk_page_setup_new ();
462 priv->page_setup_set = FALSE;
464 priv->support_selection = FALSE;
465 priv->has_selection = FALSE;
467 g_signal_connect (dialog,
469 (GCallback) gtk_print_unix_dialog_destroy,
472 g_signal_connect (dialog,
474 (GCallback) error_dialogs,
477 priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
478 gtk_widget_show (priv->preview_button);
480 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
481 priv->preview_button,
483 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
484 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
485 GTK_STOCK_PRINT, GTK_RESPONSE_OK,
487 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
493 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
494 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
496 populate_dialog (dialog);
500 gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
502 /* Make sure we don't destroy custom widgets owned by the backends */
503 clear_per_printer_ui (dialog);
507 disconnect_printer_details_request (GtkPrintUnixDialog *dialog)
509 GtkPrintUnixDialogPrivate *priv = dialog->priv;
511 if (priv->request_details_tag)
513 g_signal_handler_disconnect (priv->request_details_printer,
514 priv->request_details_tag);
515 priv->request_details_tag = 0;
516 g_object_unref (priv->request_details_printer);
517 priv->request_details_printer = NULL;
522 gtk_print_unix_dialog_finalize (GObject *object)
524 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
525 GtkPrintUnixDialogPrivate *priv = dialog->priv;
526 GtkPrintBackend *backend;
529 unschedule_idle_mark_conflicts (dialog);
530 disconnect_printer_details_request (dialog);
532 if (priv->current_printer)
534 g_object_unref (priv->current_printer);
535 priv->current_printer = NULL;
538 if (priv->printer_list)
540 g_object_unref (priv->printer_list);
541 priv->printer_list = NULL;
544 if (priv->printer_list_filter)
546 g_object_unref (priv->printer_list_filter);
547 priv->printer_list_filter = NULL;
553 g_object_unref (priv->options);
554 priv->options = NULL;
557 if (priv->number_up_layout_2_option)
559 priv->number_up_layout_2_option->choices[0] = NULL;
560 priv->number_up_layout_2_option->choices[1] = NULL;
561 g_free (priv->number_up_layout_2_option->choices_display[0]);
562 g_free (priv->number_up_layout_2_option->choices_display[1]);
563 priv->number_up_layout_2_option->choices_display[0] = NULL;
564 priv->number_up_layout_2_option->choices_display[1] = NULL;
565 g_object_unref (priv->number_up_layout_2_option);
566 priv->number_up_layout_2_option = NULL;
569 if (priv->number_up_layout_n_option)
571 g_object_unref (priv->number_up_layout_n_option);
572 priv->number_up_layout_n_option = NULL;
575 if (priv->page_setup)
577 g_object_unref (priv->page_setup);
578 priv->page_setup = NULL;
581 if (priv->initial_settings)
583 g_object_unref (priv->initial_settings);
584 priv->initial_settings = NULL;
587 g_free (priv->waiting_for_printer);
588 priv->waiting_for_printer = NULL;
590 g_free (priv->format_for_printer);
591 priv->format_for_printer = NULL;
593 for (node = priv->print_backends; node != NULL; node = node->next)
595 backend = GTK_PRINT_BACKEND (node->data);
597 g_signal_handlers_disconnect_by_func (backend, printer_added_cb, dialog);
598 g_signal_handlers_disconnect_by_func (backend, printer_removed_cb, dialog);
599 g_signal_handlers_disconnect_by_func (backend, printer_status_cb, dialog);
601 gtk_print_backend_destroy (backend);
602 g_object_unref (backend);
605 g_list_free (priv->print_backends);
606 priv->print_backends = NULL;
608 G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->finalize (object);
612 printer_removed_cb (GtkPrintBackend *backend,
614 GtkPrintUnixDialog *dialog)
616 GtkPrintUnixDialogPrivate *priv = dialog->priv;
619 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
620 gtk_list_store_remove (GTK_LIST_STORE (priv->printer_list), iter);
624 gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface)
626 parent_buildable_iface = g_type_interface_peek_parent (iface);
628 iface->get_internal_child = gtk_print_unix_dialog_buildable_get_internal_child;
632 gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
634 const gchar *childname)
636 if (strcmp (childname, "notebook") == 0)
637 return G_OBJECT (GTK_PRINT_UNIX_DIALOG (buildable)->priv->notebook);
639 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
642 /* This function controls "sensitive" property of GtkCellRenderer based on pause
643 * state of printers. */
644 void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
645 GtkCellRenderer *cell,
646 GtkTreeModel *tree_model,
652 gtk_tree_model_get (tree_model, iter, PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
654 if (printer != NULL && !gtk_printer_is_accepting_jobs (printer))
665 printer_status_cb (GtkPrintBackend *backend,
667 GtkPrintUnixDialog *dialog)
669 GtkPrintUnixDialogPrivate *priv = dialog->priv;
671 GtkTreeSelection *selection;
673 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
675 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), iter,
676 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
677 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
678 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
679 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
682 /* When the pause state change then we need to update sensitive property
683 * of GTK_RESPONSE_OK button inside of selected_printer_changed function. */
684 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
685 selected_printer_changed (selection, dialog);
687 if (gtk_print_backend_printer_list_is_done (backend) &&
688 gtk_printer_is_default (printer) &&
689 (gtk_tree_selection_count_selected_rows (selection) == 0))
690 set_active_printer (dialog, gtk_printer_get_name (printer));
694 printer_added_cb (GtkPrintBackend *backend,
696 GtkPrintUnixDialog *dialog)
698 GtkPrintUnixDialogPrivate *priv = dialog->priv;
699 GtkTreeIter iter, filter_iter;
700 GtkTreeSelection *selection;
703 gtk_list_store_append (GTK_LIST_STORE (priv->printer_list), &iter);
705 g_object_set_data_full (G_OBJECT (printer),
706 "gtk-print-tree-iter",
707 gtk_tree_iter_copy (&iter),
708 (GDestroyNotify) gtk_tree_iter_free);
710 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), &iter,
711 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
712 PRINTER_LIST_COL_NAME, gtk_printer_get_name (printer),
713 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
714 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
715 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
716 PRINTER_LIST_COL_PRINTER_OBJ, printer,
719 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
720 &filter_iter, &iter);
721 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->printer_list_filter), &filter_iter);
723 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
725 if (priv->waiting_for_printer != NULL &&
726 strcmp (gtk_printer_get_name (printer),
727 priv->waiting_for_printer) == 0)
729 priv->internal_printer_change = TRUE;
730 gtk_tree_selection_select_iter (selection, &filter_iter);
731 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
732 path, NULL, TRUE, 0.5, 0.0);
733 priv->internal_printer_change = FALSE;
734 g_free (priv->waiting_for_printer);
735 priv->waiting_for_printer = NULL;
737 else if (is_default_printer (dialog, printer) &&
738 gtk_tree_selection_count_selected_rows (selection) == 0)
740 priv->internal_printer_change = TRUE;
741 gtk_tree_selection_select_iter (selection, &filter_iter);
742 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
743 path, NULL, TRUE, 0.5, 0.0);
744 priv->internal_printer_change = FALSE;
747 gtk_tree_path_free (path);
751 printer_list_initialize (GtkPrintUnixDialog *dialog,
752 GtkPrintBackend *print_backend)
757 g_return_if_fail (print_backend != NULL);
759 g_signal_connect_object (print_backend,
761 (GCallback) printer_added_cb,
762 G_OBJECT (dialog), 0);
764 g_signal_connect_object (print_backend,
766 (GCallback) printer_removed_cb,
767 G_OBJECT (dialog), 0);
769 g_signal_connect_object (print_backend,
770 "printer-status-changed",
771 (GCallback) printer_status_cb,
772 G_OBJECT (dialog), 0);
774 list = gtk_print_backend_get_printer_list (print_backend);
779 printer_added_cb (print_backend, node->data, dialog);
787 load_print_backends (GtkPrintUnixDialog *dialog)
789 GtkPrintUnixDialogPrivate *priv = dialog->priv;
792 if (g_module_supported ())
793 priv->print_backends = gtk_print_backend_load_modules ();
795 for (node = priv->print_backends; node != NULL; node = node->next)
797 GtkPrintBackend *backend = node->data;
798 printer_list_initialize (dialog, backend);
803 gtk_print_unix_dialog_set_property (GObject *object,
809 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
813 case PROP_PAGE_SETUP:
814 gtk_print_unix_dialog_set_page_setup (dialog, g_value_get_object (value));
816 case PROP_CURRENT_PAGE:
817 gtk_print_unix_dialog_set_current_page (dialog, g_value_get_int (value));
819 case PROP_PRINT_SETTINGS:
820 gtk_print_unix_dialog_set_settings (dialog, g_value_get_object (value));
822 case PROP_MANUAL_CAPABILITIES:
823 gtk_print_unix_dialog_set_manual_capabilities (dialog, g_value_get_flags (value));
825 case PROP_SUPPORT_SELECTION:
826 gtk_print_unix_dialog_set_support_selection (dialog, g_value_get_boolean (value));
828 case PROP_HAS_SELECTION:
829 gtk_print_unix_dialog_set_has_selection (dialog, g_value_get_boolean (value));
832 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
838 gtk_print_unix_dialog_get_property (GObject *object,
843 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
844 GtkPrintUnixDialogPrivate *priv = dialog->priv;
848 case PROP_PAGE_SETUP:
849 g_value_set_object (value, priv->page_setup);
851 case PROP_CURRENT_PAGE:
852 g_value_set_int (value, priv->current_page);
854 case PROP_PRINT_SETTINGS:
855 g_value_take_object (value, gtk_print_unix_dialog_get_settings (dialog));
857 case PROP_SELECTED_PRINTER:
858 g_value_set_object (value, priv->current_printer);
860 case PROP_MANUAL_CAPABILITIES:
861 g_value_set_flags (value, priv->manual_capabilities);
863 case PROP_SUPPORT_SELECTION:
864 g_value_set_boolean (value, priv->support_selection);
866 case PROP_HAS_SELECTION:
867 g_value_set_boolean (value, priv->has_selection);
870 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
876 is_printer_active (GtkTreeModel *model,
878 GtkPrintUnixDialog *dialog)
882 GtkPrintUnixDialogPrivate *priv = dialog->priv;
884 gtk_tree_model_get (model,
886 PRINTER_LIST_COL_PRINTER_OBJ,
893 result = gtk_printer_is_active (printer);
896 priv->manual_capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF |
897 GTK_PRINT_CAPABILITY_GENERATE_PS))
899 /* Check that the printer can handle at least one of the data
900 * formats that the application supports.
902 result = ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF) &&
903 gtk_printer_accepts_pdf (printer)) ||
904 ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS) &&
905 gtk_printer_accepts_ps (printer));
908 g_object_unref (printer);
914 default_printer_list_sort_func (GtkTreeModel *model,
921 GtkPrinter *a_printer;
922 GtkPrinter *b_printer;
925 gtk_tree_model_get (model, a,
926 PRINTER_LIST_COL_NAME, &a_name,
927 PRINTER_LIST_COL_PRINTER_OBJ, &a_printer,
929 gtk_tree_model_get (model, b,
930 PRINTER_LIST_COL_NAME, &b_name,
931 PRINTER_LIST_COL_PRINTER_OBJ, &b_printer,
934 if (a_printer == NULL && b_printer == NULL)
936 else if (a_printer == NULL)
938 else if (b_printer == NULL)
940 else if (gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
942 else if (gtk_printer_is_virtual (a_printer) && !gtk_printer_is_virtual (b_printer))
944 else if (!gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
946 else if (a_name == NULL && b_name == NULL)
948 else if (a_name == NULL && b_name != NULL)
950 else if (a_name != NULL && b_name == NULL)
953 result = g_ascii_strcasecmp (a_name, b_name);
957 g_object_unref (a_printer);
958 g_object_unref (b_printer);
965 create_printer_list_model (GtkPrintUnixDialog *dialog)
967 GtkPrintUnixDialogPrivate *priv = dialog->priv;
969 GtkTreeSortable *sort;
971 model = gtk_list_store_new (PRINTER_LIST_N_COLS,
979 priv->printer_list = (GtkTreeModel *)model;
980 priv->printer_list_filter = (GtkTreeModelFilter *) gtk_tree_model_filter_new ((GtkTreeModel *)model,
983 gtk_tree_model_filter_set_visible_func (priv->printer_list_filter,
984 (GtkTreeModelFilterVisibleFunc) is_printer_active,
988 sort = GTK_TREE_SORTABLE (model);
989 gtk_tree_sortable_set_default_sort_func (sort,
990 default_printer_list_sort_func,
994 gtk_tree_sortable_set_sort_column_id (sort,
995 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
1002 wrap_in_frame (const gchar *label,
1005 GtkWidget *frame, *alignment, *label_widget;
1008 label_widget = gtk_label_new (NULL);
1009 gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
1010 gtk_widget_show (label_widget);
1012 bold_text = g_markup_printf_escaped ("<b>%s</b>", label);
1013 gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
1016 frame = gtk_vbox_new (FALSE, 6);
1017 gtk_box_pack_start (GTK_BOX (frame), label_widget, FALSE, FALSE, 0);
1019 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1020 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
1022 gtk_box_pack_start (GTK_BOX (frame), alignment, FALSE, FALSE, 0);
1024 gtk_container_add (GTK_CONTAINER (alignment), child);
1026 gtk_widget_show (frame);
1027 gtk_widget_show (alignment);
1033 setup_option (GtkPrintUnixDialog *dialog,
1034 const gchar *option_name,
1035 GtkPrinterOptionWidget *widget)
1037 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1038 GtkPrinterOption *option;
1040 option = gtk_printer_option_set_lookup (priv->options, option_name);
1041 gtk_printer_option_widget_set_source (widget, option);
1043 return option != NULL;
1047 add_option_to_extension_point (GtkPrinterOption *option,
1050 GtkWidget *extension_point = data;
1053 widget = gtk_printer_option_widget_new (option);
1054 gtk_widget_show (widget);
1056 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1058 GtkWidget *label, *hbox;
1060 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1061 gtk_widget_show (label);
1062 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1063 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1065 hbox = gtk_hbox_new (FALSE, 12);
1066 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1067 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1068 gtk_widget_show (hbox);
1070 gtk_box_pack_start (GTK_BOX (extension_point), hbox, FALSE, FALSE, 0);
1073 gtk_box_pack_start (GTK_BOX (extension_point), widget, FALSE, FALSE, 0);
1077 add_option_to_table (GtkPrinterOption *option,
1081 GtkWidget *label, *widget;
1084 table = GTK_TABLE (user_data);
1086 if (g_str_has_prefix (option->name, "gtk-"))
1089 widget = gtk_printer_option_widget_new (option);
1090 gtk_widget_show (widget);
1093 gtk_table_resize (table, table->nrows + 1, 2);
1095 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1097 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1098 gtk_widget_show (label);
1100 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1101 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1103 gtk_table_attach (table, label,
1104 0, 1, row - 1 , row, GTK_FILL, 0, 0, 0);
1106 gtk_table_attach (table, widget,
1107 1, 2, row - 1, row, GTK_FILL, 0, 0, 0);
1110 gtk_table_attach (table, widget,
1111 0, 2, row - 1, row, GTK_FILL, 0, 0, 0);
1116 setup_page_table (GtkPrinterOptionSet *options,
1121 gtk_printer_option_set_foreach_in_group (options, group,
1122 add_option_to_table,
1124 if (GTK_TABLE (table)->nrows == 1)
1125 gtk_widget_hide (page);
1127 gtk_widget_show (page);
1131 update_print_at_option (GtkPrintUnixDialog *dialog)
1133 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1134 GtkPrinterOption *option;
1136 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1141 if (priv->updating_print_at)
1144 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_at_radio)))
1145 gtk_printer_option_set (option, "at");
1146 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio)))
1147 gtk_printer_option_set (option, "on-hold");
1149 gtk_printer_option_set (option, "now");
1151 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1154 const char *text = gtk_entry_get_text (GTK_ENTRY (priv->print_at_entry));
1155 gtk_printer_option_set (option, text);
1161 setup_print_at (GtkPrintUnixDialog *dialog)
1163 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1164 GtkPrinterOption *option;
1166 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1170 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1172 gtk_widget_set_sensitive (priv->print_at_radio, FALSE);
1173 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1174 gtk_widget_set_sensitive (priv->print_hold_radio, FALSE);
1175 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), "");
1179 priv->updating_print_at = TRUE;
1181 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1182 gtk_widget_set_sensitive (priv->print_at_radio,
1183 gtk_printer_option_has_choice (option, "at"));
1185 gtk_widget_set_sensitive (priv->print_hold_radio,
1186 gtk_printer_option_has_choice (option, "on-hold"));
1188 update_print_at_option (dialog);
1190 if (strcmp (option->value, "at") == 0)
1191 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_at_radio),
1193 else if (strcmp (option->value, "on-hold") == 0)
1194 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio),
1197 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1200 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1202 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), option->value);
1205 priv->updating_print_at = FALSE;
1211 update_dialog_from_settings (GtkPrintUnixDialog *dialog)
1213 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1216 GtkWidget *table, *frame;
1217 gboolean has_advanced, has_job;
1219 if (priv->current_printer == NULL)
1221 clear_per_printer_ui (dialog);
1222 gtk_widget_hide (priv->job_page);
1223 gtk_widget_hide (priv->advanced_page);
1224 gtk_widget_hide (priv->image_quality_page);
1225 gtk_widget_hide (priv->finishing_page);
1226 gtk_widget_hide (priv->color_page);
1227 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1232 setup_option (dialog, "gtk-n-up", priv->pages_per_sheet);
1233 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
1234 setup_option (dialog, "gtk-duplex", priv->duplex);
1235 setup_option (dialog, "gtk-paper-type", priv->paper_type);
1236 setup_option (dialog, "gtk-paper-source", priv->paper_source);
1237 setup_option (dialog, "gtk-output-tray", priv->output_tray);
1240 has_job |= setup_option (dialog, "gtk-job-prio", priv->job_prio);
1241 has_job |= setup_option (dialog, "gtk-billing-info", priv->billing_info);
1242 has_job |= setup_option (dialog, "gtk-cover-before", priv->cover_before);
1243 has_job |= setup_option (dialog, "gtk-cover-after", priv->cover_after);
1244 has_job |= setup_print_at (dialog);
1247 gtk_widget_show (priv->job_page);
1249 gtk_widget_hide (priv->job_page);
1252 setup_page_table (priv->options,
1254 priv->image_quality_table,
1255 priv->image_quality_page);
1257 setup_page_table (priv->options,
1259 priv->finishing_table,
1260 priv->finishing_page);
1262 setup_page_table (priv->options,
1267 gtk_printer_option_set_foreach_in_group (priv->options,
1268 "GtkPrintDialogExtension",
1269 add_option_to_extension_point,
1270 priv->extension_point);
1272 /* Put the rest of the groups in the advanced page */
1273 groups = gtk_printer_option_set_get_groups (priv->options);
1275 has_advanced = FALSE;
1276 for (l = groups; l != NULL; l = l->next)
1283 if (strcmp (group, "ImageQualityPage") == 0 ||
1284 strcmp (group, "ColorPage") == 0 ||
1285 strcmp (group, "FinishingPage") == 0 ||
1286 strcmp (group, "GtkPrintDialogExtension") == 0)
1289 table = gtk_table_new (1, 2, FALSE);
1290 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1291 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1293 gtk_printer_option_set_foreach_in_group (priv->options,
1295 add_option_to_table,
1297 if (GTK_TABLE (table)->nrows == 1)
1298 gtk_widget_destroy (table);
1301 has_advanced = TRUE;
1302 frame = wrap_in_frame (group, table);
1303 gtk_widget_show (table);
1304 gtk_widget_show (frame);
1306 gtk_box_pack_start (GTK_BOX (priv->advanced_vbox),
1307 frame, FALSE, FALSE, 0);
1312 gtk_widget_show (priv->advanced_page);
1314 gtk_widget_hide (priv->advanced_page);
1317 g_list_foreach (groups, (GFunc) g_free, NULL);
1318 g_list_free (groups);
1322 update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
1324 GtkPrintCapabilities caps;
1325 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1326 gboolean can_collate;
1327 const gchar *copies;
1329 copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin));
1330 can_collate = (*copies != '\0' && atoi (copies) > 1);
1332 caps = priv->manual_capabilities | priv->printer_capabilities;
1334 gtk_widget_set_sensitive (priv->page_set_combo,
1335 caps & GTK_PRINT_CAPABILITY_PAGE_SET);
1336 gtk_widget_set_sensitive (priv->copies_spin,
1337 caps & GTK_PRINT_CAPABILITY_COPIES);
1338 gtk_widget_set_sensitive (priv->collate_check,
1340 (caps & GTK_PRINT_CAPABILITY_COLLATE));
1341 gtk_widget_set_sensitive (priv->reverse_check,
1342 caps & GTK_PRINT_CAPABILITY_REVERSE);
1343 gtk_widget_set_sensitive (priv->scale_spin,
1344 caps & GTK_PRINT_CAPABILITY_SCALE);
1345 gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet),
1346 caps & GTK_PRINT_CAPABILITY_NUMBER_UP);
1348 if (caps & GTK_PRINT_CAPABILITY_PREVIEW)
1349 gtk_widget_show (priv->preview_button);
1351 gtk_widget_hide (priv->preview_button);
1353 update_collate_icon (NULL, dialog);
1355 gtk_tree_model_filter_refilter (priv->printer_list_filter);
1359 mark_conflicts (GtkPrintUnixDialog *dialog)
1361 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1362 GtkPrinter *printer;
1363 gboolean have_conflict;
1365 have_conflict = FALSE;
1367 printer = priv->current_printer;
1372 g_signal_handler_block (priv->options,
1373 priv->options_changed_handler);
1375 gtk_printer_option_set_clear_conflicts (priv->options);
1377 have_conflict = _gtk_printer_mark_conflicts (printer,
1380 g_signal_handler_unblock (priv->options,
1381 priv->options_changed_handler);
1385 gtk_widget_show (priv->conflicts_widget);
1387 gtk_widget_hide (priv->conflicts_widget);
1391 mark_conflicts_callback (gpointer data)
1393 GtkPrintUnixDialog *dialog = data;
1394 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1396 priv->mark_conflicts_id = 0;
1398 mark_conflicts (dialog);
1404 unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1406 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1408 if (priv->mark_conflicts_id != 0)
1410 g_source_remove (priv->mark_conflicts_id);
1411 priv->mark_conflicts_id = 0;
1416 schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1418 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1420 if (priv->mark_conflicts_id != 0)
1423 priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
1428 options_changed_cb (GtkPrintUnixDialog *dialog)
1430 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1432 schedule_idle_mark_conflicts (dialog);
1434 if (priv->initial_settings)
1436 g_object_unref (priv->initial_settings);
1437 priv->initial_settings = NULL;
1440 g_free (priv->waiting_for_printer);
1441 priv->waiting_for_printer = NULL;
1445 remove_custom_widget (GtkWidget *widget,
1446 GtkContainer *container)
1448 gtk_container_remove (container, widget);
1452 extension_point_clear_children (GtkContainer *container)
1454 gtk_container_foreach (container,
1455 (GtkCallback)remove_custom_widget,
1460 clear_per_printer_ui (GtkPrintUnixDialog *dialog)
1462 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1464 gtk_container_foreach (GTK_CONTAINER (priv->finishing_table),
1465 (GtkCallback)gtk_widget_destroy,
1467 gtk_table_resize (GTK_TABLE (priv->finishing_table), 1, 2);
1468 gtk_container_foreach (GTK_CONTAINER (priv->image_quality_table),
1469 (GtkCallback)gtk_widget_destroy,
1471 gtk_table_resize (GTK_TABLE (priv->image_quality_table), 1, 2);
1472 gtk_container_foreach (GTK_CONTAINER (priv->color_table),
1473 (GtkCallback)gtk_widget_destroy,
1475 gtk_table_resize (GTK_TABLE (priv->color_table), 1, 2);
1476 gtk_container_foreach (GTK_CONTAINER (priv->advanced_vbox),
1477 (GtkCallback)gtk_widget_destroy,
1479 extension_point_clear_children (GTK_CONTAINER (priv->extension_point));
1483 printer_details_acquired (GtkPrinter *printer,
1485 GtkPrintUnixDialog *dialog)
1487 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1489 disconnect_printer_details_request (dialog);
1493 GtkTreeSelection *selection;
1494 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
1496 selected_printer_changed (selection, dialog);
1501 selected_printer_changed (GtkTreeSelection *selection,
1502 GtkPrintUnixDialog *dialog)
1504 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1505 GtkPrinter *printer;
1506 GtkTreeIter iter, filter_iter;
1508 /* Whenever the user selects a printer we stop looking for
1509 the printer specified in the initial settings */
1510 if (priv->waiting_for_printer &&
1511 !priv->internal_printer_change)
1513 g_free (priv->waiting_for_printer);
1514 priv->waiting_for_printer = NULL;
1517 disconnect_printer_details_request (dialog);
1520 if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
1522 gtk_tree_model_filter_convert_iter_to_child_iter (priv->printer_list_filter,
1526 gtk_tree_model_get (priv->printer_list, &iter,
1527 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1531 /* sets GTK_RESPONSE_OK button sensitive/insensitive depending on whether the printer
1532 * accepts/rejects jobs */
1533 if (printer != NULL)
1535 if (!gtk_printer_is_accepting_jobs (printer))
1537 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1541 if (priv->current_printer == printer && gtk_printer_has_details (printer))
1542 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1546 if (printer != NULL && !gtk_printer_has_details (printer))
1548 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1549 priv->request_details_tag =
1550 g_signal_connect (printer, "details-acquired",
1551 G_CALLBACK (printer_details_acquired), dialog);
1552 /* take the reference */
1553 priv->request_details_printer = printer;
1554 gtk_printer_request_details (printer);
1558 if (printer == priv->current_printer)
1561 g_object_unref (printer);
1567 g_object_unref (priv->options);
1568 priv->options = NULL;
1570 clear_per_printer_ui (dialog);
1573 if (priv->current_printer)
1575 g_object_unref (priv->current_printer);
1578 priv->printer_capabilities = 0;
1580 if (gtk_printer_is_accepting_jobs (printer))
1581 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1582 priv->current_printer = printer;
1584 if (printer != NULL)
1586 if (!priv->page_setup_set)
1588 /* if no explicit page setup has been set, use the printer default */
1589 GtkPageSetup *page_setup;
1591 page_setup = gtk_printer_get_default_page_size (printer);
1594 page_setup = gtk_page_setup_new ();
1596 g_object_unref (priv->page_setup);
1597 priv->page_setup = page_setup;
1600 priv->printer_capabilities = gtk_printer_get_capabilities (printer);
1601 priv->options = _gtk_printer_get_options (printer,
1602 priv->initial_settings,
1604 priv->manual_capabilities);
1606 priv->options_changed_handler =
1607 g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
1610 update_dialog_from_settings (dialog);
1611 update_dialog_from_capabilities (dialog);
1613 g_object_notify ( G_OBJECT(dialog), "selected-printer");
1617 update_collate_icon (GtkToggleButton *toggle_button,
1618 GtkPrintUnixDialog *dialog)
1620 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1622 gtk_widget_queue_draw (priv->collate_image);
1626 paint_page (GtkWidget *widget,
1634 gint x, y, width, height;
1635 gint text_y, linewidth;
1637 x = x_offset * scale;
1638 y = y_offset * scale;
1640 height = 26 * scale;
1645 gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
1646 cairo_rectangle (cr, x, y, width, height);
1649 gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_NORMAL]);
1650 cairo_set_line_width (cr, linewidth);
1651 cairo_rectangle (cr, x + linewidth/2.0, y + linewidth/2.0, width - linewidth, height - linewidth);
1654 cairo_select_font_face (cr, "Sans",
1655 CAIRO_FONT_SLANT_NORMAL,
1656 CAIRO_FONT_WEIGHT_NORMAL);
1657 cairo_set_font_size (cr, (gint)(9 * scale));
1658 cairo_move_to (cr, x + (gint)(text_x * scale), y + (gint)(text_y * scale));
1659 cairo_show_text (cr, text);
1664 draw_collate_cb (GtkWidget *widget,
1665 GdkEventExpose *event,
1666 GtkPrintUnixDialog *dialog)
1668 GtkSettings *settings;
1672 gboolean collate, reverse, rtl;
1676 collate = dialog_get_collate (dialog);
1677 reverse = dialog_get_reverse (dialog);
1678 copies = dialog_get_n_copies (dialog);
1680 rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL);
1682 settings = gtk_widget_get_settings (widget);
1683 gtk_icon_size_lookup_for_settings (settings,
1684 GTK_ICON_SIZE_DIALOG,
1687 scale = size / 48.0;
1688 text_x = rtl ? 4 : 11;
1690 cr = gdk_cairo_create (widget->window);
1692 cairo_translate (cr, widget->allocation.x, widget->allocation.y);
1696 paint_page (widget, cr, scale, rtl ? 40: 15, 5, reverse ? "1" : "2", text_x);
1697 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
1701 paint_page (widget, cr, scale, rtl ? 40: 15, 5, collate == reverse ? "1" : "2", text_x);
1702 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
1704 paint_page (widget, cr, scale, rtl ? 5 : 50, 5, reverse ? "1" : "2", text_x);
1705 paint_page (widget, cr, scale, rtl ? 15 : 40, 15, collate == reverse ? "2" : "1", text_x);
1714 gtk_print_unix_dialog_style_set (GtkWidget *widget,
1715 GtkStyle *previous_style)
1717 GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_set (widget, previous_style);
1719 if (gtk_widget_has_screen (widget))
1721 GtkPrintUnixDialog *dialog = (GtkPrintUnixDialog *)widget;
1722 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1723 GtkSettings *settings;
1727 settings = gtk_widget_get_settings (widget);
1728 gtk_icon_size_lookup_for_settings (settings,
1729 GTK_ICON_SIZE_DIALOG,
1732 scale = size / 48.0;
1734 gtk_widget_set_size_request (priv->collate_image,
1741 update_entry_sensitivity (GtkWidget *button,
1746 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
1748 gtk_widget_set_sensitive (range, active);
1751 gtk_widget_grab_focus (range);
1755 emit_ok_response (GtkTreeView *tree_view,
1757 GtkTreeViewColumn *column,
1758 gpointer *user_data)
1760 GtkPrintUnixDialog *print_dialog;
1762 print_dialog = (GtkPrintUnixDialog *) user_data;
1764 gtk_dialog_response (GTK_DIALOG (print_dialog), GTK_RESPONSE_OK);
1768 create_main_page (GtkPrintUnixDialog *dialog)
1770 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1771 GtkWidget *main_vbox, *label, *vbox, *hbox;
1772 GtkWidget *scrolled, *treeview, *frame, *table;
1773 GtkWidget *entry, *spinbutton;
1774 GtkWidget *radio, *check, *image;
1775 GtkCellRenderer *renderer;
1776 GtkTreeViewColumn *column;
1777 GtkTreeSelection *selection;
1778 GtkWidget *custom_input;
1779 const gchar *range_tooltip;
1781 main_vbox = gtk_vbox_new (FALSE, 18);
1782 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
1783 gtk_widget_show (main_vbox);
1785 vbox = gtk_vbox_new (FALSE, 6);
1786 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
1787 gtk_widget_show (vbox);
1789 scrolled = gtk_scrolled_window_new (NULL, NULL);
1790 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
1791 GTK_POLICY_AUTOMATIC,
1792 GTK_POLICY_AUTOMATIC);
1793 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
1795 gtk_widget_show (scrolled);
1796 gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
1798 treeview = gtk_tree_view_new_with_model ((GtkTreeModel *) priv->printer_list_filter);
1799 priv->printer_treeview = treeview;
1800 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
1801 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), PRINTER_LIST_COL_NAME);
1802 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), TRUE);
1803 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
1804 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
1805 g_signal_connect (selection, "changed", G_CALLBACK (selected_printer_changed), dialog);
1807 renderer = gtk_cell_renderer_pixbuf_new ();
1808 column = gtk_tree_view_column_new_with_attributes ("",
1811 PRINTER_LIST_COL_ICON,
1813 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1814 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1816 renderer = gtk_cell_renderer_text_new ();
1817 column = gtk_tree_view_column_new_with_attributes (_("Printer"),
1820 PRINTER_LIST_COL_NAME,
1822 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1823 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1825 renderer = gtk_cell_renderer_text_new ();
1826 /* Translators: this is the header for the location column in the print dialog */
1827 column = gtk_tree_view_column_new_with_attributes (_("Location"),
1830 PRINTER_LIST_COL_LOCATION,
1832 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1833 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1835 renderer = gtk_cell_renderer_text_new ();
1836 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1837 /* Translators: this is the header for the printer status column in the print dialog */
1838 column = gtk_tree_view_column_new_with_attributes (_("Status"),
1841 PRINTER_LIST_COL_STATE,
1843 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1844 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1846 g_signal_connect (GTK_TREE_VIEW (treeview), "row-activated", G_CALLBACK (emit_ok_response), dialog);
1848 gtk_widget_show (treeview);
1849 gtk_container_add (GTK_CONTAINER (scrolled), treeview);
1851 custom_input = gtk_hbox_new (FALSE, 18);
1852 gtk_widget_show (custom_input);
1853 gtk_box_pack_start (GTK_BOX (vbox), custom_input, FALSE, FALSE, 0);
1854 priv->extension_point = custom_input;
1856 hbox = gtk_hbox_new (FALSE, 18);
1857 gtk_widget_show (hbox);
1858 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
1860 table = gtk_table_new (4, 2, FALSE);
1861 priv->range_table = table;
1862 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1863 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1864 frame = wrap_in_frame (_("Range"), table);
1865 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
1866 gtk_widget_show (table);
1868 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_All Pages"));
1869 priv->all_pages_radio = radio;
1870 gtk_widget_show (radio);
1871 gtk_table_attach (GTK_TABLE (table), radio,
1872 0, 2, 0, 1, GTK_FILL, 0,
1874 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
1875 _("C_urrent Page"));
1876 if (priv->current_page == -1)
1877 gtk_widget_set_sensitive (radio, FALSE);
1878 priv->current_page_radio = radio;
1879 gtk_widget_show (radio);
1880 gtk_table_attach (GTK_TABLE (table), radio,
1881 0, 2, 1, 2, GTK_FILL, 0,
1885 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
1888 gtk_widget_set_sensitive (radio, priv->has_selection);
1889 priv->selection_radio = radio;
1890 gtk_table_attach (GTK_TABLE (table), radio,
1891 0, 2, 2, 3, GTK_FILL, 0,
1893 gtk_table_set_row_spacing (GTK_TABLE (table), 2, 0);
1895 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)), _("Pag_es:"));
1896 range_tooltip = _("Specify one or more page ranges,\n e.g. 1-3,7,11");
1897 gtk_widget_set_tooltip_text (radio, range_tooltip);
1899 priv->page_range_radio = radio;
1900 gtk_widget_show (radio);
1901 gtk_table_attach (GTK_TABLE (table), radio,
1902 0, 1, 3, 4, GTK_FILL, 0,
1904 entry = gtk_entry_new ();
1905 gtk_widget_set_tooltip_text (entry, range_tooltip);
1906 atk_object_set_name (gtk_widget_get_accessible (entry), _("Pages"));
1907 atk_object_set_description (gtk_widget_get_accessible (entry), range_tooltip);
1908 priv->page_range_entry = entry;
1909 gtk_widget_show (entry);
1910 gtk_table_attach (GTK_TABLE (table), entry,
1911 1, 2, 3, 4, GTK_FILL, 0,
1913 g_signal_connect (radio, "toggled", G_CALLBACK (update_entry_sensitivity), entry);
1914 update_entry_sensitivity (radio, entry);
1916 table = gtk_table_new (3, 2, FALSE);
1917 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1918 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1919 frame = wrap_in_frame (_("Copies"), table);
1920 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
1921 gtk_widget_show (table);
1923 /* FIXME chpe: too much space between Copies and spinbutton, put those 2 in a hbox and make it span 2 columns */
1924 label = gtk_label_new_with_mnemonic (_("Copie_s:"));
1925 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1926 gtk_widget_show (label);
1927 gtk_table_attach (GTK_TABLE (table), label,
1928 0, 1, 0, 1, GTK_FILL, 0,
1930 spinbutton = gtk_spin_button_new_with_range (1.0, 100.0, 1.0);
1931 priv->copies_spin = spinbutton;
1932 gtk_widget_show (spinbutton);
1933 gtk_table_attach (GTK_TABLE (table), spinbutton,
1934 1, 2, 0, 1, GTK_FILL, 0,
1936 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
1937 g_signal_connect_swapped (spinbutton, "value-changed",
1938 G_CALLBACK (update_dialog_from_capabilities), dialog);
1939 g_signal_connect_swapped (spinbutton, "changed",
1940 G_CALLBACK (update_dialog_from_capabilities), dialog);
1942 check = gtk_check_button_new_with_mnemonic (_("C_ollate"));
1943 priv->collate_check = check;
1944 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
1945 gtk_widget_show (check);
1946 gtk_table_attach (GTK_TABLE (table), check,
1947 0, 1, 1, 2, GTK_FILL, 0,
1950 check = gtk_check_button_new_with_mnemonic (_("_Reverse"));
1951 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
1952 priv->reverse_check = check;
1953 gtk_widget_show (check);
1954 gtk_table_attach (GTK_TABLE (table), check,
1955 0, 1, 2, 3, GTK_FILL, 0,
1958 image = gtk_drawing_area_new ();
1959 GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
1961 priv->collate_image = image;
1962 gtk_widget_show (image);
1963 gtk_widget_set_size_request (image, 70, 90);
1964 gtk_table_attach (GTK_TABLE (table), image,
1965 1, 2, 1, 3, GTK_FILL, 0,
1967 g_signal_connect (image, "expose-event",
1968 G_CALLBACK (draw_collate_cb), dialog);
1970 label = gtk_label_new (_("General"));
1971 gtk_widget_show (label);
1973 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), main_vbox, label);
1977 is_range_separator (gchar c)
1979 return (c == ',' || c == ';' || c == ':');
1982 static GtkPageRange *
1983 dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
1986 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1988 const gchar *text, *p;
1990 GtkPageRange *ranges;
1993 text = gtk_entry_get_text (GTK_ENTRY (priv->page_range_entry));
2005 if (is_range_separator (*p))
2010 ranges = g_new0 (GtkPageRange, n_ranges);
2016 while (isspace (*p)) p++;
2020 /* a half-open range like -2 */
2025 start = (int)strtol (p, &next, 10);
2033 while (isspace (*p)) p++;
2038 end = (int)strtol (p, &next, 10);
2039 if (next == p) /* a half-open range like 2- */
2041 else if (end < start)
2045 ranges[i].start = start - 1;
2046 ranges[i].end = end - 1;
2049 /* Skip until end or separator */
2050 while (*p && !is_range_separator (*p))
2053 /* if not at end, skip separator */
2064 dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
2065 GtkPageRange *ranges,
2068 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2070 GString *s = g_string_new (NULL);
2072 for (i = 0; i < n_ranges; i++)
2074 g_string_append_printf (s, "%d", ranges[i].start + 1);
2075 if (ranges[i].end > ranges[i].start)
2076 g_string_append_printf (s, "-%d", ranges[i].end + 1);
2077 else if (ranges[i].end == -1)
2078 g_string_append (s, "-");
2080 if (i != n_ranges - 1)
2081 g_string_append (s, ",");
2084 gtk_entry_set_text (GTK_ENTRY (priv->page_range_entry), s->str);
2086 g_string_free (s, TRUE);
2090 static GtkPrintPages
2091 dialog_get_print_pages (GtkPrintUnixDialog *dialog)
2093 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2095 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio)))
2096 return GTK_PRINT_PAGES_ALL;
2097 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->current_page_radio)))
2098 return GTK_PRINT_PAGES_CURRENT;
2099 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->selection_radio)))
2100 return GTK_PRINT_PAGES_SELECTION;
2102 return GTK_PRINT_PAGES_RANGES;
2106 dialog_set_print_pages (GtkPrintUnixDialog *dialog,
2107 GtkPrintPages pages)
2109 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2111 if (pages == GTK_PRINT_PAGES_RANGES)
2112 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
2113 else if (pages == GTK_PRINT_PAGES_CURRENT)
2114 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->current_page_radio), TRUE);
2115 else if (pages == GTK_PRINT_PAGES_SELECTION)
2116 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->selection_radio), TRUE);
2118 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio), TRUE);
2122 dialog_get_scale (GtkPrintUnixDialog *dialog)
2124 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->scale_spin))
2125 return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
2131 dialog_set_scale (GtkPrintUnixDialog *dialog,
2134 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin), val);
2138 dialog_get_page_set (GtkPrintUnixDialog *dialog)
2140 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->page_set_combo))
2141 return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
2143 return GTK_PAGE_SET_ALL;
2147 dialog_set_page_set (GtkPrintUnixDialog *dialog,
2150 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->page_set_combo),
2155 dialog_get_n_copies (GtkPrintUnixDialog *dialog)
2157 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->copies_spin))
2158 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
2163 dialog_set_n_copies (GtkPrintUnixDialog *dialog,
2166 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->copies_spin),
2171 dialog_get_collate (GtkPrintUnixDialog *dialog)
2173 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->collate_check))
2174 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
2179 dialog_set_collate (GtkPrintUnixDialog *dialog,
2182 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check),
2187 dialog_get_reverse (GtkPrintUnixDialog *dialog)
2189 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->reverse_check))
2190 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
2195 dialog_set_reverse (GtkPrintUnixDialog *dialog,
2198 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check),
2203 dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
2205 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2209 val = gtk_printer_option_widget_get_value (priv->pages_per_sheet);
2223 static GtkNumberUpLayout
2224 dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
2226 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2227 GtkPrintCapabilities caps;
2228 GtkNumberUpLayout layout;
2230 GEnumClass *enum_class;
2231 GEnumValue *enum_value;
2233 val = gtk_printer_option_widget_get_value (priv->number_up_layout);
2235 caps = priv->manual_capabilities | priv->printer_capabilities;
2237 if ((caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) == 0)
2238 return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2240 if (gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR)
2241 layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2243 layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
2248 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
2249 enum_value = g_enum_get_value_by_nick (enum_class, val);
2251 layout = enum_value->value;
2252 g_type_class_unref (enum_class);
2258 draw_page_cb (GtkWidget *widget,
2259 GdkEventExpose *event,
2260 GtkPrintUnixDialog *dialog)
2262 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2265 gint w, h, tmp, shadow_offset;
2266 gint pages_x, pages_y, i, x, y, layout_w, layout_h;
2267 gdouble page_width, page_height;
2268 GtkPageOrientation orientation;
2270 PangoLayout *layout;
2271 PangoFontDescription *font;
2274 GtkNumberUpLayout number_up_layout;
2275 gint start_x, end_x, start_y, end_y;
2277 gboolean horizontal;
2279 orientation = gtk_page_setup_get_orientation (priv->page_setup);
2281 (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
2282 (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
2284 number_up_layout = dialog_get_number_up_layout (dialog);
2286 cr = gdk_cairo_create (widget->window);
2288 cairo_translate (cr, widget->allocation.x, widget->allocation.y);
2292 w = (EXAMPLE_PAGE_AREA_SIZE - 3) / ratio;
2295 switch (dialog_get_pages_per_sheet (dialog))
2299 pages_x = 1; pages_y = 1;
2302 landscape = !landscape;
2303 pages_x = 1; pages_y = 2;
2306 pages_x = 2; pages_y = 2;
2309 landscape = !landscape;
2310 pages_x = 2; pages_y = 3;
2313 pages_x = 3; pages_y = 3;
2316 pages_x = 4; pages_y = 4;
2333 color = &widget->style->text[GTK_STATE_NORMAL];
2334 cairo_set_source_rgba (cr, color->red / 65535., color->green / 65535., color->blue / 65535, 0.5);
2335 cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
2338 gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
2339 cairo_rectangle (cr, 1, 1, w, h);
2341 cairo_set_line_width (cr, 1.0);
2342 cairo_rectangle (cr, 0.5, 0.5, w+1, h+1);
2344 gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_NORMAL]);
2349 page_width = (double)w / pages_x;
2350 page_height = (double)h / pages_y;
2352 layout = pango_cairo_create_layout (cr);
2354 font = pango_font_description_new ();
2355 pango_font_description_set_family (font, "sans");
2356 pango_font_description_set_absolute_size (font, page_height * 0.4 * PANGO_SCALE);
2357 pango_layout_set_font_description (layout, font);
2358 pango_font_description_free (font);
2360 pango_layout_set_width (layout, page_width * PANGO_SCALE);
2361 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2363 switch (number_up_layout)
2366 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
2368 end_x = pages_x - 1;
2370 end_y = pages_y - 1;
2375 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
2377 end_x = pages_x - 1;
2378 start_y = pages_y - 1;
2384 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
2385 start_x = pages_x - 1;
2388 end_y = pages_y - 1;
2393 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
2394 start_x = pages_x - 1;
2396 start_y = pages_y - 1;
2402 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
2404 end_x = pages_x - 1;
2406 end_y = pages_y - 1;
2411 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
2412 start_x = pages_x - 1;
2415 end_y = pages_y - 1;
2420 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
2422 end_x = pages_x - 1;
2423 start_y = pages_y - 1;
2429 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
2430 start_x = pages_x - 1;
2432 start_y = pages_y - 1;
2441 for (y = start_y; y != end_y + dy; y += dy)
2443 for (x = start_x; x != end_x + dx; x += dx)
2445 text = g_strdup_printf ("%d", i++);
2446 pango_layout_set_text (layout, text, -1);
2448 pango_layout_get_size (layout, &layout_w, &layout_h);
2450 cairo_translate (cr,
2452 y * page_height + (page_height - layout_h / 1024.0) / 2);
2454 pango_cairo_show_layout (cr, layout);
2459 for (x = start_x; x != end_x + dx; x += dx)
2461 for (y = start_y; y != end_y + dy; y += dy)
2463 text = g_strdup_printf ("%d", i++);
2464 pango_layout_set_text (layout, text, -1);
2466 pango_layout_get_size (layout, &layout_w, &layout_h);
2468 cairo_translate (cr,
2470 y * page_height + (page_height - layout_h / 1024.0) / 2);
2472 pango_cairo_show_layout (cr, layout);
2477 g_object_unref (layout);
2484 redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
2486 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2488 if (priv->page_layout_preview)
2489 gtk_widget_queue_draw (priv->page_layout_preview);
2493 update_number_up_layout (GtkPrintUnixDialog *dialog)
2495 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2496 GtkPrintCapabilities caps;
2497 GtkPrinterOptionSet *set;
2498 GtkNumberUpLayout layout;
2499 GtkPrinterOption *option;
2500 GtkPrinterOption *old_option;
2501 GtkPageOrientation page_orientation;
2503 set = priv->options;
2505 caps = priv->manual_capabilities | priv->printer_capabilities;
2507 if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
2509 if (priv->number_up_layout_n_option == NULL)
2511 priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
2512 if (priv->number_up_layout_n_option == NULL)
2514 char *n_up_layout[] = { "lrtb", "lrbt", "rltb", "rlbt", "tblr", "tbrl", "btlr", "btrl" };
2515 /* Translators: These strings name the possible arrangements of
2516 * multiple pages on a sheet when printing (same as in gtkprintbackendcups.c)
2518 char *n_up_layout_display[] = { N_("Left to right, top to bottom"), N_("Left to right, bottom to top"),
2519 N_("Right to left, top to bottom"), N_("Right to left, bottom to top"),
2520 N_("Top to bottom, left to right"), N_("Top to bottom, right to left"),
2521 N_("Bottom to top, left to right"), N_("Bottom to top, right to left") };
2524 priv->number_up_layout_n_option = gtk_printer_option_new ("gtk-n-up-layout",
2526 GTK_PRINTER_OPTION_TYPE_PICKONE);
2527 gtk_printer_option_allocate_choices (priv->number_up_layout_n_option, 8);
2529 for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
2531 priv->number_up_layout_n_option->choices[i] = g_strdup (n_up_layout[i]);
2532 priv->number_up_layout_n_option->choices_display[i] = g_strdup (_(n_up_layout_display[i]));
2535 g_object_ref (priv->number_up_layout_n_option);
2537 priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
2539 GTK_PRINTER_OPTION_TYPE_PICKONE);
2540 gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
2543 page_orientation = gtk_page_setup_get_orientation (priv->page_setup);
2544 if (page_orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
2545 page_orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
2547 if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
2548 priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[2]))
2550 g_free (priv->number_up_layout_2_option->choices_display[0]);
2551 g_free (priv->number_up_layout_2_option->choices_display[1]);
2552 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
2553 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
2554 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
2555 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
2560 if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
2561 priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[1]))
2563 g_free (priv->number_up_layout_2_option->choices_display[0]);
2564 g_free (priv->number_up_layout_2_option->choices_display[1]);
2565 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
2566 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[1];
2567 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Top to bottom"));
2568 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Bottom to top"));
2572 layout = dialog_get_number_up_layout (dialog);
2574 old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
2575 if (old_option != NULL)
2576 gtk_printer_option_set_remove (set, old_option);
2578 if (dialog_get_pages_per_sheet (dialog) != 1)
2580 GEnumClass *enum_class;
2581 GEnumValue *enum_value;
2582 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
2584 if (dialog_get_pages_per_sheet (dialog) == 2)
2586 option = priv->number_up_layout_2_option;
2588 if (layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM ||
2589 layout == GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT)
2590 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
2592 if (layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP ||
2593 layout == GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT)
2594 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP);
2596 if (layout == GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM ||
2597 layout == GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT)
2598 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM);
2600 if (layout == GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP ||
2601 layout == GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT)
2602 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP);
2606 option = priv->number_up_layout_n_option;
2608 enum_value = g_enum_get_value (enum_class, layout);
2611 g_assert (enum_value != NULL);
2612 gtk_printer_option_set (option, enum_value->value_nick);
2613 g_type_class_unref (enum_class);
2615 gtk_printer_option_set_add (set, option);
2619 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
2621 if (priv->number_up_layout != NULL)
2622 gtk_widget_set_sensitive (GTK_WIDGET (priv->number_up_layout),
2623 (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) &&
2624 (dialog_get_pages_per_sheet (dialog) > 1));
2628 create_page_setup_page (GtkPrintUnixDialog *dialog)
2630 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2631 GtkWidget *main_vbox, *label, *hbox, *hbox2;
2632 GtkWidget *frame, *table, *widget;
2633 GtkWidget *combo, *spinbutton, *draw;
2635 main_vbox = gtk_vbox_new (FALSE, 18);
2636 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2637 gtk_widget_show (main_vbox);
2639 hbox = gtk_hbox_new (FALSE, 18);
2640 gtk_widget_show (hbox);
2641 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
2643 table = gtk_table_new (5, 2, FALSE);
2644 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2645 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2646 frame = wrap_in_frame (_("Layout"), table);
2647 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2648 gtk_widget_show (table);
2650 label = gtk_label_new_with_mnemonic (_("T_wo-sided:"));
2651 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2652 gtk_widget_show (label);
2653 gtk_table_attach (GTK_TABLE (table), label,
2654 0, 1, 0, 1, GTK_FILL, 0,
2657 widget = gtk_printer_option_widget_new (NULL);
2658 priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
2659 gtk_widget_show (widget);
2660 gtk_table_attach (GTK_TABLE (table), widget,
2661 1, 2, 0, 1, GTK_FILL, 0,
2663 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2665 label = gtk_label_new_with_mnemonic (_("Pages per _side:"));
2666 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2667 gtk_widget_show (label);
2668 gtk_table_attach (GTK_TABLE (table), label,
2669 0, 1, 1, 2, GTK_FILL, 0,
2672 widget = gtk_printer_option_widget_new (NULL);
2673 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
2674 g_signal_connect_swapped (widget, "changed", G_CALLBACK (update_number_up_layout), dialog);
2675 priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
2676 gtk_widget_show (widget);
2677 gtk_table_attach (GTK_TABLE (table), widget,
2678 1, 2, 1, 2, GTK_FILL, 0,
2680 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2683 label = gtk_label_new_with_mnemonic (_("Page or_dering:"));
2684 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2685 gtk_widget_show (label);
2686 gtk_table_attach (GTK_TABLE (table), label,
2687 0, 1, 2, 3, GTK_FILL, 0,
2690 widget = gtk_printer_option_widget_new (NULL);
2691 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
2692 priv->number_up_layout = GTK_PRINTER_OPTION_WIDGET (widget);
2693 gtk_widget_show (widget);
2694 gtk_table_attach (GTK_TABLE (table), widget,
2695 1, 2, 2, 3, GTK_FILL, 0,
2697 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2699 label = gtk_label_new_with_mnemonic (_("_Only print:"));
2700 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2701 gtk_widget_show (label);
2702 gtk_table_attach (GTK_TABLE (table), label,
2703 0, 1, 3, 4, GTK_FILL, 0,
2706 combo = gtk_combo_box_new_text ();
2707 priv->page_set_combo = combo;
2708 gtk_widget_show (combo);
2709 gtk_table_attach (GTK_TABLE (table), combo,
2710 1, 2, 3, 4, GTK_FILL, 0,
2712 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
2714 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("All sheets"));
2715 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Even sheets"));
2716 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Odd sheets"));
2717 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
2719 label = gtk_label_new_with_mnemonic (_("Sc_ale:"));
2720 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2721 gtk_widget_show (label);
2722 gtk_table_attach (GTK_TABLE (table), label,
2723 0, 1, 4, 5, GTK_FILL, 0,
2726 hbox2 = gtk_hbox_new (FALSE, 6);
2727 gtk_widget_show (hbox2);
2728 gtk_table_attach (GTK_TABLE (table), hbox2,
2729 1, 2, 4, 5, GTK_FILL, 0,
2732 spinbutton = gtk_spin_button_new_with_range (1.0, 1000.0, 1.0);
2733 priv->scale_spin = spinbutton;
2734 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), 1);
2735 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton), 100.0);
2736 gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
2737 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
2738 gtk_widget_show (spinbutton);
2739 label = gtk_label_new ("%"); /* FIXMEchpe does there exist any language where % needs to be translated? */
2740 gtk_widget_show (label);
2741 gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2743 table = gtk_table_new (4, 2, FALSE);
2744 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2745 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2746 frame = wrap_in_frame (_("Paper"), table);
2747 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
2748 gtk_widget_show (table);
2750 label = gtk_label_new_with_mnemonic (_("Paper _type:"));
2751 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2752 gtk_widget_show (label);
2753 gtk_table_attach (GTK_TABLE (table), label,
2754 0, 1, 0, 1, GTK_FILL, 0,
2757 widget = gtk_printer_option_widget_new (NULL);
2758 priv->paper_type = GTK_PRINTER_OPTION_WIDGET (widget);
2759 gtk_widget_show (widget);
2760 gtk_table_attach (GTK_TABLE (table), widget,
2761 1, 2, 0, 1, GTK_FILL, 0,
2763 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2765 label = gtk_label_new_with_mnemonic (_("Paper _source:"));
2766 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2767 gtk_widget_show (label);
2768 gtk_table_attach (GTK_TABLE (table), label,
2769 0, 1, 1, 2, GTK_FILL, 0,
2772 widget = gtk_printer_option_widget_new (NULL);
2773 priv->paper_source = GTK_PRINTER_OPTION_WIDGET (widget);
2774 gtk_widget_show (widget);
2775 gtk_table_attach (GTK_TABLE (table), widget,
2776 1, 2, 1, 2, GTK_FILL, 0,
2778 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2780 label = gtk_label_new_with_mnemonic (_("Output t_ray:"));
2781 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2782 gtk_widget_show (label);
2783 gtk_table_attach (GTK_TABLE (table), label,
2784 0, 1, 2, 3, GTK_FILL, 0,
2787 widget = gtk_printer_option_widget_new (NULL);
2788 priv->output_tray = GTK_PRINTER_OPTION_WIDGET (widget);
2789 gtk_widget_show (widget);
2790 gtk_table_attach (GTK_TABLE (table), widget,
2791 1, 2, 2, 3, GTK_FILL, 0,
2793 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2795 /* Add the page layout preview */
2796 hbox2 = gtk_hbox_new (FALSE, 0);
2797 gtk_widget_show (hbox2);
2798 gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 0);
2800 draw = gtk_drawing_area_new ();
2801 GTK_WIDGET_SET_FLAGS (draw, GTK_NO_WINDOW);
2802 priv->page_layout_preview = draw;
2803 gtk_widget_set_size_request (draw, 200, 200);
2804 g_signal_connect (draw, "expose-event", G_CALLBACK (draw_page_cb), dialog);
2805 gtk_widget_show (draw);
2807 gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 0);
2809 label = gtk_label_new (_("Page Setup"));
2810 gtk_widget_show (label);
2812 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2817 create_job_page (GtkPrintUnixDialog *dialog)
2819 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2820 GtkWidget *main_table, *label;
2821 GtkWidget *frame, *table, *radio;
2822 GtkWidget *entry, *widget;
2823 const gchar *at_tooltip;
2824 const gchar *on_hold_tooltip;
2826 main_table = gtk_table_new (2, 2, FALSE);
2827 gtk_container_set_border_width (GTK_CONTAINER (main_table), 12);
2828 gtk_table_set_row_spacings (GTK_TABLE (main_table), 18);
2829 gtk_table_set_col_spacings (GTK_TABLE (main_table), 18);
2831 table = gtk_table_new (2, 2, FALSE);
2832 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2833 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2834 frame = wrap_in_frame (_("Job Details"), table);
2835 gtk_table_attach (GTK_TABLE (main_table), frame,
2836 0, 1, 0, 1, GTK_FILL, 0,
2838 gtk_widget_show (table);
2840 label = gtk_label_new_with_mnemonic (_("Pri_ority:"));
2841 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2842 gtk_widget_show (label);
2843 gtk_table_attach (GTK_TABLE (table), label,
2844 0, 1, 0, 1, GTK_FILL, 0,
2847 widget = gtk_printer_option_widget_new (NULL);
2848 priv->job_prio = GTK_PRINTER_OPTION_WIDGET (widget);
2849 gtk_widget_show (widget);
2850 gtk_table_attach (GTK_TABLE (table), widget,
2851 1, 2, 0, 1, GTK_FILL, 0,
2853 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2855 label = gtk_label_new_with_mnemonic (_("_Billing info:"));
2856 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2857 gtk_widget_show (label);
2858 gtk_table_attach (GTK_TABLE (table), label,
2859 0, 1, 1, 2, GTK_FILL, 0,
2862 widget = gtk_printer_option_widget_new (NULL);
2863 priv->billing_info = GTK_PRINTER_OPTION_WIDGET (widget);
2864 gtk_widget_show (widget);
2865 gtk_table_attach (GTK_TABLE (table), widget,
2866 1, 2, 1, 2, GTK_FILL, 0,
2868 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2870 table = gtk_table_new (2, 2, FALSE);
2871 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2872 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2873 frame = wrap_in_frame (_("Print Document"), table);
2874 gtk_table_attach (GTK_TABLE (main_table), frame,
2875 0, 1, 1, 2, GTK_FILL, 0,
2877 gtk_widget_show (table);
2879 /* Translators: this is one of the choices for the print at option
2880 * in the print dialog
2882 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Now"));
2883 priv->print_now_radio = radio;
2884 gtk_widget_show (radio);
2885 gtk_table_attach (GTK_TABLE (table), radio,
2886 0, 2, 0, 1, GTK_FILL, 0,
2888 /* Translators: this is one of the choices for the print at option
2889 * in the print dialog. It also serves as the label for an entry that
2890 * allows the user to enter a time.
2892 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2895 /* Translators: Ability to parse the am/pm format depends on actual locale.
2896 * You can remove the am/pm values below for your locale if they are not
2899 at_tooltip = _("Specify the time of print,\n e.g. 15:30, 2:35 pm, 14:15:20, 11:46:30 am, 4 pm");
2900 gtk_widget_set_tooltip_text (radio, at_tooltip);
2901 priv->print_at_radio = radio;
2902 gtk_widget_show (radio);
2903 gtk_table_attach (GTK_TABLE (table), radio,
2904 0, 1, 1, 2, GTK_FILL, 0,
2907 entry = gtk_entry_new ();
2908 gtk_widget_set_tooltip_text (entry, at_tooltip);
2909 atk_object_set_name (gtk_widget_get_accessible (entry), _("Time of print"));
2910 atk_object_set_description (gtk_widget_get_accessible (entry), at_tooltip);
2911 priv->print_at_entry = entry;
2912 gtk_widget_show (entry);
2913 gtk_table_attach (GTK_TABLE (table), entry,
2914 1, 2, 1, 2, GTK_FILL, 0,
2917 g_signal_connect (radio, "toggled", G_CALLBACK (update_entry_sensitivity), entry);
2918 update_entry_sensitivity (radio, entry);
2920 /* Translators: this is one of the choices for the print at option
2921 * in the print dialog. It means that the print job will not be
2922 * printed until it explicitly gets 'released'.
2924 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2926 on_hold_tooltip = _("Hold the job until it is explicitly released");
2927 gtk_widget_set_tooltip_text (radio, on_hold_tooltip);
2928 priv->print_hold_radio = radio;
2929 gtk_widget_show (radio);
2930 gtk_table_attach (GTK_TABLE (table), radio,
2931 0, 2, 2, 3, GTK_FILL, 0,
2934 g_signal_connect_swapped (priv->print_now_radio, "toggled",
2935 G_CALLBACK (update_print_at_option), dialog);
2936 g_signal_connect_swapped (priv->print_at_radio, "toggled",
2937 G_CALLBACK (update_print_at_option), dialog);
2938 g_signal_connect_swapped (priv->print_at_entry, "changed",
2939 G_CALLBACK (update_print_at_option), dialog);
2940 g_signal_connect_swapped (priv->print_hold_radio, "toggled",
2941 G_CALLBACK (update_print_at_option), dialog);
2943 table = gtk_table_new (2, 2, FALSE);
2944 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2945 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2946 frame = wrap_in_frame (_("Add Cover Page"), table);
2947 gtk_table_attach (GTK_TABLE (main_table), frame,
2948 1, 2, 0, 1, GTK_FILL, 0,
2950 gtk_widget_show (table);
2952 /* Translators, this is the label used for the option in the print
2953 * dialog that controls the front cover page.
2955 label = gtk_label_new_with_mnemonic (_("Be_fore:"));
2956 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2957 gtk_widget_show (label);
2958 gtk_table_attach (GTK_TABLE (table), label,
2959 0, 1, 0, 1, GTK_FILL, 0,
2962 widget = gtk_printer_option_widget_new (NULL);
2963 priv->cover_before = GTK_PRINTER_OPTION_WIDGET (widget);
2964 gtk_widget_show (widget);
2965 gtk_table_attach (GTK_TABLE (table), widget,
2966 1, 2, 0, 1, GTK_FILL, 0,
2968 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2970 /* Translators, this is the label used for the option in the print
2971 * dialog that controls the back cover page.
2973 label = gtk_label_new_with_mnemonic (_("_After:"));
2974 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2975 gtk_widget_show (label);
2976 gtk_table_attach (GTK_TABLE (table), label,
2977 0, 1, 1, 2, GTK_FILL, 0,
2980 widget = gtk_printer_option_widget_new (NULL);
2981 priv->cover_after = GTK_PRINTER_OPTION_WIDGET (widget);
2982 gtk_widget_show (widget);
2983 gtk_table_attach (GTK_TABLE (table), widget,
2984 1, 2, 1, 2, GTK_FILL, 0,
2986 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2988 /* Translators: this is the tab label for the notebook tab containing
2989 * job-specific options in the print dialog
2991 label = gtk_label_new (_("Job"));
2992 gtk_widget_show (label);
2994 priv->job_page = main_table;
2995 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3000 create_optional_page (GtkPrintUnixDialog *dialog,
3002 GtkWidget **table_out,
3003 GtkWidget **page_out)
3005 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3006 GtkWidget *table, *label, *scrolled;
3008 scrolled = gtk_scrolled_window_new (NULL, NULL);
3009 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
3011 GTK_POLICY_AUTOMATIC);
3013 table = gtk_table_new (1, 2, FALSE);
3014 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
3015 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
3016 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
3017 gtk_widget_show (table);
3019 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
3021 gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN(scrolled)->child),
3024 label = gtk_label_new (text);
3025 gtk_widget_show (label);
3027 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3031 *page_out = scrolled;
3035 create_advanced_page (GtkPrintUnixDialog *dialog)
3037 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3038 GtkWidget *main_vbox, *label, *scrolled;
3040 scrolled = gtk_scrolled_window_new (NULL, NULL);
3041 priv->advanced_page = scrolled;
3042 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
3044 GTK_POLICY_AUTOMATIC);
3046 main_vbox = gtk_vbox_new (FALSE, 18);
3047 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
3048 gtk_widget_show (main_vbox);
3050 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
3052 gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN(scrolled)->child),
3055 priv->advanced_vbox = main_vbox;
3057 label = gtk_label_new (_("Advanced"));
3058 gtk_widget_show (label);
3060 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3066 populate_dialog (GtkPrintUnixDialog *print_dialog)
3068 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
3069 GtkDialog *dialog = GTK_DIALOG (print_dialog);
3070 GtkWidget *vbox, *conflict_hbox, *image, *label;
3072 gtk_dialog_set_has_separator (dialog, FALSE);
3073 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
3074 gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
3075 gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
3076 gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
3078 vbox = gtk_vbox_new (FALSE, 6);
3079 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
3080 gtk_box_pack_start (GTK_BOX (dialog->vbox), vbox, TRUE, TRUE, 0);
3081 gtk_widget_show (vbox);
3083 priv->notebook = gtk_notebook_new ();
3084 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
3085 gtk_widget_show (priv->notebook);
3087 create_printer_list_model (print_dialog);
3089 create_main_page (print_dialog);
3090 create_page_setup_page (print_dialog);
3091 create_job_page (print_dialog);
3092 create_optional_page (print_dialog, _("Image Quality"),
3093 &priv->image_quality_table,
3094 &priv->image_quality_page);
3095 create_optional_page (print_dialog, _("Color"),
3098 create_optional_page (print_dialog, _("Finishing"),
3099 &priv->finishing_table,
3100 &priv->finishing_page);
3101 create_advanced_page (print_dialog);
3103 priv->conflicts_widget = conflict_hbox = gtk_hbox_new (FALSE, 12);
3104 gtk_box_pack_end (GTK_BOX (vbox), conflict_hbox, FALSE, FALSE, 0);
3105 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
3106 gtk_widget_show (image);
3107 gtk_box_pack_start (GTK_BOX (conflict_hbox), image, FALSE, TRUE, 0);
3108 label = gtk_label_new (_("Some of the settings in the dialog conflict"));
3109 gtk_widget_show (label);
3110 gtk_box_pack_start (GTK_BOX (conflict_hbox), label, FALSE, TRUE, 0);
3112 load_print_backends (print_dialog);
3116 * gtk_print_unix_dialog_new:
3117 * @title: Title of the dialog, or %NULL
3118 * @parent: Transient parent of the dialog, or %NULL
3120 * Creates a new #GtkPrintUnixDialog.
3122 * Return value: a new #GtkPrintUnixDialog
3127 gtk_print_unix_dialog_new (const gchar *title,
3131 const gchar *_title = _("Print");
3136 result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
3137 "transient-for", parent,
3139 "has-separator", FALSE,
3146 * gtk_print_unix_dialog_get_selected_printer:
3147 * @dialog: a #GtkPrintUnixDialog
3149 * Gets the currently selected printer.
3151 * Returns: the currently selected printer
3156 gtk_print_unix_dialog_get_selected_printer (GtkPrintUnixDialog *dialog)
3158 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3160 return dialog->priv->current_printer;
3164 * gtk_print_unix_dialog_set_page_setup:
3165 * @dialog: a #GtkPrintUnixDialog
3166 * @page_setup: a #GtkPageSetup
3168 * Sets the page setup of the #GtkPrintUnixDialog.
3173 gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
3174 GtkPageSetup *page_setup)
3176 GtkPrintUnixDialogPrivate *priv;
3178 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3179 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
3181 priv = dialog->priv;
3183 if (priv->page_setup != page_setup)
3185 g_object_unref (priv->page_setup);
3186 priv->page_setup = g_object_ref (page_setup);
3188 priv->page_setup_set = TRUE;
3190 g_object_notify (G_OBJECT (dialog), "page-setup");
3195 * gtk_print_unix_dialog_get_page_setup:
3196 * @dialog: a #GtkPrintUnixDialog
3198 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3200 * Returns: the page setup of @dialog.
3205 gtk_print_unix_dialog_get_page_setup (GtkPrintUnixDialog *dialog)
3207 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3209 return dialog->priv->page_setup;
3213 * gtk_print_unix_dialog_set_current_page:
3214 * @dialog: a #GtkPrintUnixDialog
3215 * @current_page: the current page number.
3217 * Sets the current page number. If @current_page is not -1, this enables
3218 * the current page choice for the range of pages to print.
3223 gtk_print_unix_dialog_set_current_page (GtkPrintUnixDialog *dialog,
3226 GtkPrintUnixDialogPrivate *priv;
3228 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3230 priv = dialog->priv;
3232 if (priv->current_page != current_page)
3234 priv->current_page = current_page;
3236 if (priv->current_page_radio)
3237 gtk_widget_set_sensitive (priv->current_page_radio, current_page != -1);
3239 g_object_notify (G_OBJECT (dialog), "current-page");
3244 * gtk_print_unix_dialog_get_current_page:
3245 * @dialog: a #GtkPrintUnixDialog
3247 * Gets the current page of the #GtkPrintDialog.
3249 * Returns: the current page of @dialog
3254 gtk_print_unix_dialog_get_current_page (GtkPrintUnixDialog *dialog)
3256 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), -1);
3258 return dialog->priv->current_page;
3262 set_active_printer (GtkPrintUnixDialog *dialog,
3263 const gchar *printer_name)
3265 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3266 GtkTreeModel *model;
3267 GtkTreeIter iter, filter_iter;
3268 GtkTreeSelection *selection;
3269 GtkPrinter *printer;
3271 model = GTK_TREE_MODEL (priv->printer_list);
3273 if (gtk_tree_model_get_iter_first (model, &iter))
3277 gtk_tree_model_get (GTK_TREE_MODEL (priv->printer_list), &iter,
3278 PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
3279 if (printer == NULL)
3282 if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
3284 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
3285 &filter_iter, &iter);
3287 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
3288 priv->internal_printer_change = TRUE;
3289 gtk_tree_selection_select_iter (selection, &filter_iter);
3290 priv->internal_printer_change = FALSE;
3291 g_free (priv->waiting_for_printer);
3292 priv->waiting_for_printer = NULL;
3294 g_object_unref (printer);
3298 g_object_unref (printer);
3300 } while (gtk_tree_model_iter_next (model, &iter));
3307 * gtk_print_unix_dialog_set_settings:
3308 * @dialog: a #GtkPrintUnixDialog
3309 * @settings: a #GtkPrintSettings, or %NULL
3311 * Sets the #GtkPrintSettings for the #GtkPrintUnixDialog. Typically,
3312 * this is used to restore saved print settings from a previous print
3313 * operation before the print dialog is shown.
3318 gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
3319 GtkPrintSettings *settings)
3321 GtkPrintUnixDialogPrivate *priv;
3322 const gchar *printer;
3323 GtkPageRange *ranges;
3326 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3327 g_return_if_fail (settings == NULL || GTK_IS_PRINT_SETTINGS (settings));
3329 priv = dialog->priv;
3331 if (settings != NULL)
3333 dialog_set_collate (dialog, gtk_print_settings_get_collate (settings));
3334 dialog_set_reverse (dialog, gtk_print_settings_get_reverse (settings));
3335 dialog_set_n_copies (dialog, gtk_print_settings_get_n_copies (settings));
3336 dialog_set_scale (dialog, gtk_print_settings_get_scale (settings));
3337 dialog_set_page_set (dialog, gtk_print_settings_get_page_set (settings));
3338 dialog_set_print_pages (dialog, gtk_print_settings_get_print_pages (settings));
3339 ranges = gtk_print_settings_get_page_ranges (settings, &num_ranges);
3342 dialog_set_page_ranges (dialog, ranges, num_ranges);
3346 priv->format_for_printer =
3347 g_strdup (gtk_print_settings_get (settings, "format-for-printer"));
3350 if (priv->initial_settings)
3351 g_object_unref (priv->initial_settings);
3353 priv->initial_settings = settings;
3355 g_free (priv->waiting_for_printer);
3356 priv->waiting_for_printer = NULL;
3360 g_object_ref (settings);
3362 printer = gtk_print_settings_get_printer (settings);
3364 if (printer && !set_active_printer (dialog, printer))
3365 priv->waiting_for_printer = g_strdup (printer);
3368 g_object_notify (G_OBJECT (dialog), "print-settings");
3372 * gtk_print_unix_dialog_get_settings:
3373 * @dialog: a #GtkPrintUnixDialog
3375 * Gets a new #GtkPrintSettings object that represents the
3376 * current values in the print dialog. Note that this creates a
3377 * <emphasis>new object</emphasis>, and you need to unref it
3378 * if don't want to keep it.
3380 * Returns: a new #GtkPrintSettings object with the values from @dialog
3385 gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
3387 GtkPrintUnixDialogPrivate *priv;
3388 GtkPrintSettings *settings;
3389 GtkPrintPages print_pages;
3390 GtkPageRange *ranges;
3393 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3395 priv = dialog->priv;
3396 settings = gtk_print_settings_new ();
3398 if (priv->current_printer)
3399 gtk_print_settings_set_printer (settings,
3400 gtk_printer_get_name (priv->current_printer));
3402 gtk_print_settings_set_printer (settings, "default");
3404 gtk_print_settings_set (settings, "format-for-printer",
3405 priv->format_for_printer);
3408 gtk_print_settings_set_collate (settings,
3409 dialog_get_collate (dialog));
3411 gtk_print_settings_set_reverse (settings,
3412 dialog_get_reverse (dialog));
3414 gtk_print_settings_set_n_copies (settings,
3415 dialog_get_n_copies (dialog));
3417 gtk_print_settings_set_scale (settings,
3418 dialog_get_scale (dialog));
3420 gtk_print_settings_set_page_set (settings,
3421 dialog_get_page_set (dialog));
3423 print_pages = dialog_get_print_pages (dialog);
3424 gtk_print_settings_set_print_pages (settings, print_pages);
3426 ranges = dialog_get_page_ranges (dialog, &n_ranges);
3429 gtk_print_settings_set_page_ranges (settings, ranges, n_ranges);
3433 /* TODO: print when. How to handle? */
3435 if (priv->current_printer)
3436 _gtk_printer_get_settings_from_options (priv->current_printer,
3444 * gtk_print_unix_dialog_add_custom_tab:
3445 * @dialog: a #GtkPrintUnixDialog
3446 * @child: the widget to put in the custom tab
3447 * @tab_label: the widget to use as tab label
3449 * Adds a custom tab to the print dialog.
3454 gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
3456 GtkWidget *tab_label)
3458 gtk_notebook_insert_page (GTK_NOTEBOOK (dialog->priv->notebook),
3459 child, tab_label, 2);
3460 gtk_widget_show (child);
3461 gtk_widget_show (tab_label);
3465 * gtk_print_unix_dialog_set_manual_capabilities:
3466 * @dialog: a #GtkPrintUnixDialog
3467 * @capabilities: the printing capabilities of your application
3469 * This lets you specify the printing capabilities your application
3470 * supports. For instance, if you can handle scaling the output then
3471 * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then
3472 * the dialog will only let you select the scale if the printing
3473 * system automatically handles scaling.
3478 gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog,
3479 GtkPrintCapabilities capabilities)
3481 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3483 if (priv->manual_capabilities != capabilities)
3485 priv->manual_capabilities = capabilities;
3486 update_dialog_from_capabilities (dialog);
3488 if (priv->current_printer)
3490 GtkTreeSelection *selection;
3492 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
3494 g_object_unref (priv->current_printer);
3495 priv->current_printer = NULL;
3496 priv->internal_printer_change = TRUE;
3497 selected_printer_changed (selection, dialog);
3498 priv->internal_printer_change = FALSE;
3501 g_object_notify (G_OBJECT (dialog), "manual-capabilities");
3506 * gtk_print_unix_dialog_get_manual_capabilities:
3507 * @dialog: a #GtkPrintUnixDialog
3509 * Gets the value of #GtkPrintUnixDialog::manual-capabilities property.
3511 * Returns: the printing capabilities
3515 GtkPrintCapabilities
3516 gtk_print_unix_dialog_get_manual_capabilities (GtkPrintUnixDialog *dialog)
3518 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
3520 return dialog->priv->manual_capabilities;
3524 * gtk_print_unix_dialog_set_support_selection:
3525 * @dialog: a #GtkPrintUnixDialog
3526 * @support_selection: %TRUE to allow print selection
3528 * Sets whether the print dialog allows user to print a selection.
3533 gtk_print_unix_dialog_set_support_selection (GtkPrintUnixDialog *dialog,
3534 gboolean support_selection)
3536 GtkPrintUnixDialogPrivate *priv;
3538 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3540 priv = dialog->priv;
3542 support_selection = support_selection != FALSE;
3543 if (priv->support_selection != support_selection)
3545 priv->support_selection = support_selection;
3547 if (priv->selection_radio)
3549 if (support_selection)
3551 gtk_widget_set_sensitive (priv->selection_radio, priv->has_selection);
3552 gtk_table_set_row_spacing (GTK_TABLE (priv->range_table),
3554 gtk_table_get_default_row_spacing (GTK_TABLE (priv->range_table)));
3555 gtk_widget_show (priv->selection_radio);
3559 gtk_widget_set_sensitive (priv->selection_radio, FALSE);
3560 gtk_table_set_row_spacing (GTK_TABLE (priv->range_table), 2, 0);
3561 gtk_widget_hide (priv->selection_radio);
3565 g_object_notify (G_OBJECT (dialog), "support-selection");
3570 * gtk_print_unix_dialog_get_support_selection:
3571 * @dialog: a #GtkPrintUnixDialog
3573 * Gets the value of #GtkPrintUnixDialog::support-selection property.
3575 * Returns: whether the application supports print of selection
3580 gtk_print_unix_dialog_get_support_selection (GtkPrintUnixDialog *dialog)
3582 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
3584 return dialog->priv->support_selection;
3588 * gtk_print_unix_dialog_set_has_selection:
3589 * @dialog: a #GtkPrintUnixDialog
3590 * @has_selection: %TRUE indicates that a selection exists
3592 * Sets whether a selection exists.
3597 gtk_print_unix_dialog_set_has_selection (GtkPrintUnixDialog *dialog,
3598 gboolean has_selection)
3600 GtkPrintUnixDialogPrivate *priv;
3602 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3604 priv = dialog->priv;
3606 has_selection = has_selection != FALSE;
3607 if (priv->has_selection != has_selection)
3609 priv->has_selection = has_selection;
3611 if (priv->selection_radio)
3613 if (priv->support_selection)
3614 gtk_widget_set_sensitive (priv->selection_radio, has_selection);
3616 gtk_widget_set_sensitive (priv->selection_radio, FALSE);
3619 g_object_notify (G_OBJECT (dialog), "has-selection");
3624 * gtk_print_unix_dialog_get_has_selection:
3625 * @dialog: a #GtkPrintUnixDialog
3627 * Gets the value of #GtkPrintUnixDialog::has-selection property.
3629 * Returns: whether there is a selection
3634 gtk_print_unix_dialog_get_has_selection (GtkPrintUnixDialog *dialog)
3636 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
3638 return dialog->priv->has_selection;
3641 #define __GTK_PRINT_UNIX_DIALOG_C__
3642 #include "gtkaliasdef.c"