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,
106 static void gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface);
107 static GObject *gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
109 const gchar *childname);
116 PROP_SELECTED_PRINTER
120 PRINTER_LIST_COL_ICON,
121 PRINTER_LIST_COL_NAME,
122 PRINTER_LIST_COL_STATE,
123 PRINTER_LIST_COL_JOBS,
124 PRINTER_LIST_COL_LOCATION,
125 PRINTER_LIST_COL_PRINTER_OBJ,
129 struct GtkPrintUnixDialogPrivate
133 GtkWidget *printer_treeview;
135 GtkPrintCapabilities manual_capabilities;
136 GtkPrintCapabilities printer_capabilities;
138 GtkTreeModel *printer_list;
139 GtkTreeModelFilter *printer_list_filter;
141 GtkPageSetup *page_setup;
142 gboolean page_setup_set;
144 GtkWidget *all_pages_radio;
145 GtkWidget *current_page_radio;
146 GtkWidget *page_range_radio;
147 GtkWidget *page_range_entry;
149 GtkWidget *copies_spin;
150 GtkWidget *collate_check;
151 GtkWidget *reverse_check;
152 GtkWidget *collate_image;
153 GtkWidget *page_layout_preview;
154 GtkWidget *scale_spin;
155 GtkWidget *page_set_combo;
156 GtkWidget *print_now_radio;
157 GtkWidget *print_at_radio;
158 GtkWidget *print_at_entry;
159 GtkWidget *print_hold_radio;
160 GtkWidget *preview_button;
161 gboolean updating_print_at;
162 GtkPrinterOptionWidget *pages_per_sheet;
163 GtkPrinterOptionWidget *duplex;
164 GtkPrinterOptionWidget *paper_type;
165 GtkPrinterOptionWidget *paper_source;
166 GtkPrinterOptionWidget *output_tray;
167 GtkPrinterOptionWidget *job_prio;
168 GtkPrinterOptionWidget *billing_info;
169 GtkPrinterOptionWidget *cover_before;
170 GtkPrinterOptionWidget *cover_after;
171 GtkPrinterOptionWidget *number_up_layout;
173 GtkWidget *conflicts_widget;
176 GtkWidget *finishing_table;
177 GtkWidget *finishing_page;
178 GtkWidget *image_quality_table;
179 GtkWidget *image_quality_page;
180 GtkWidget *color_table;
181 GtkWidget *color_page;
183 GtkWidget *advanced_vbox;
184 GtkWidget *advanced_page;
186 GtkWidget *extension_point;
188 /* These are set initially on selected printer (either default printer,
189 * printer taken from set settings, or user-selected), but when any setting
190 * is changed by the user it is cleared.
192 GtkPrintSettings *initial_settings;
194 GtkPrinterOption *number_up_layout_n_option;
195 GtkPrinterOption *number_up_layout_2_option;
197 /* This is the initial printer set by set_settings. We look for it in the
198 * added printers. We clear this whenever the user manually changes
199 * to another printer, when the user changes a setting or when we find
202 char *waiting_for_printer;
203 gboolean internal_printer_change;
205 GList *print_backends;
207 GtkPrinter *current_printer;
208 GtkPrinter *request_details_printer;
209 guint request_details_tag;
210 GtkPrinterOptionSet *options;
211 gulong options_changed_handler;
212 gulong mark_conflicts_id;
214 gchar *format_for_printer;
219 G_DEFINE_TYPE_WITH_CODE (GtkPrintUnixDialog, gtk_print_unix_dialog, GTK_TYPE_DIALOG,
220 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
221 gtk_print_unix_dialog_buildable_init))
223 static GtkBuildableIface *parent_buildable_iface;
226 is_default_printer (GtkPrintUnixDialog *dialog,
229 GtkPrintUnixDialogPrivate *priv = dialog->priv;
231 if (priv->format_for_printer)
232 return strcmp (priv->format_for_printer,
233 gtk_printer_get_name (printer)) == 0;
235 return gtk_printer_is_default (printer);
239 gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
241 GObjectClass *object_class;
242 GtkWidgetClass *widget_class;
244 object_class = (GObjectClass *) class;
245 widget_class = (GtkWidgetClass *) class;
247 object_class->finalize = gtk_print_unix_dialog_finalize;
248 object_class->set_property = gtk_print_unix_dialog_set_property;
249 object_class->get_property = gtk_print_unix_dialog_get_property;
251 widget_class->style_set = gtk_print_unix_dialog_style_set;
253 g_object_class_install_property (object_class,
255 g_param_spec_object ("page-setup",
257 P_("The GtkPageSetup to use"),
259 GTK_PARAM_READWRITE));
261 g_object_class_install_property (object_class,
263 g_param_spec_int ("current-page",
265 P_("The current page in the document"),
269 GTK_PARAM_READWRITE));
271 g_object_class_install_property (object_class,
273 g_param_spec_object ("print-settings",
274 P_("Print Settings"),
275 P_("The GtkPrintSettings used for initializing the dialog"),
276 GTK_TYPE_PRINT_SETTINGS,
277 GTK_PARAM_READWRITE));
279 g_object_class_install_property (object_class,
280 PROP_SELECTED_PRINTER,
281 g_param_spec_object ("selected-printer",
282 P_("Selected Printer"),
283 P_("The GtkPrinter which is selected"),
285 GTK_PARAM_READABLE));
288 g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));
291 /* Returns a toplevel GtkWindow, or NULL if none */
293 get_toplevel (GtkWidget *widget)
295 GtkWidget *toplevel = NULL;
297 toplevel = gtk_widget_get_toplevel (widget);
298 if (!GTK_WIDGET_TOPLEVEL (toplevel))
301 return GTK_WINDOW (toplevel);
305 add_custom_button_to_dialog (GtkDialog *dialog,
306 const gchar *mnemonic_label,
307 const gchar *stock_id,
310 GtkWidget *button = NULL;
312 button = gtk_button_new_with_mnemonic (mnemonic_label);
313 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
314 gtk_button_set_image (GTK_BUTTON (button),
315 gtk_image_new_from_stock (stock_id,
316 GTK_ICON_SIZE_BUTTON));
317 gtk_widget_show (button);
319 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
322 /* This function handles error messages before printing.
325 error_dialogs (GtkPrintUnixDialog *print_dialog,
326 gint print_dialog_response_id,
329 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
330 GtkPrinterOption *option = NULL;
331 GtkPrinter *printer = NULL;
332 GtkWindow *toplevel = NULL;
333 GtkWidget *dialog = NULL;
334 gchar *filename = NULL;
335 gchar *basename = NULL;
336 gchar *dirname = NULL;
339 if (print_dialog != NULL && print_dialog_response_id == GTK_RESPONSE_OK)
341 printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
343 /* Shows overwrite confirmation dialog in the case of printing to file which
345 if (printer != NULL && gtk_printer_is_virtual (printer))
347 option = gtk_printer_option_set_lookup (priv->options,
348 "gtk-main-page-custom-input");
350 if (option != NULL &&
351 option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE)
353 filename = g_filename_from_uri (option->value, NULL, NULL);
355 if (filename != NULL &&
356 g_file_test (filename, G_FILE_TEST_EXISTS))
358 toplevel = get_toplevel (GTK_WIDGET (print_dialog));
360 basename = g_path_get_basename (filename);
361 dirname = g_path_get_dirname (filename);
363 dialog = gtk_message_dialog_new (toplevel,
365 GTK_DIALOG_DESTROY_WITH_PARENT,
366 GTK_MESSAGE_QUESTION,
368 _("A file named \"%s\" already exists. Do you want to replace it?"),
371 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
372 _("The file already exists in \"%s\". Replacing it will "
373 "overwrite its contents."),
376 gtk_dialog_add_button (GTK_DIALOG (dialog),
377 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
378 add_custom_button_to_dialog (GTK_DIALOG (dialog),
381 GTK_RESPONSE_ACCEPT);
382 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
386 gtk_dialog_set_default_response (GTK_DIALOG (dialog),
387 GTK_RESPONSE_ACCEPT);
390 gtk_window_group_add_window (toplevel->group,
391 GTK_WINDOW (dialog));
393 response = gtk_dialog_run (GTK_DIALOG (dialog));
395 gtk_widget_destroy (dialog);
397 if (response != GTK_RESPONSE_ACCEPT)
399 g_signal_stop_emission_by_name (print_dialog, "response");
415 gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
417 GtkPrintUnixDialogPrivate *priv = dialog->priv;
419 priv = dialog->priv = GTK_PRINT_UNIX_DIALOG_GET_PRIVATE (dialog);
420 priv->print_backends = NULL;
421 priv->current_page = -1;
422 priv->number_up_layout_n_option = NULL;
423 priv->number_up_layout_2_option = NULL;
425 priv->page_setup = gtk_page_setup_new ();
426 priv->page_setup_set = FALSE;
428 g_signal_connect (dialog,
430 (GCallback) gtk_print_unix_dialog_destroy,
433 g_signal_connect (dialog,
435 (GCallback) error_dialogs,
438 priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
439 gtk_widget_show (priv->preview_button);
441 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
442 priv->preview_button,
444 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
445 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
446 GTK_STOCK_PRINT, GTK_RESPONSE_OK,
448 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
454 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
455 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
457 populate_dialog (dialog);
461 gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
463 /* Make sure we don't destroy custom widgets owned by the backends */
464 clear_per_printer_ui (dialog);
468 disconnect_printer_details_request (GtkPrintUnixDialog *dialog)
470 GtkPrintUnixDialogPrivate *priv = dialog->priv;
472 if (priv->request_details_tag)
474 g_signal_handler_disconnect (priv->request_details_printer,
475 priv->request_details_tag);
476 priv->request_details_tag = 0;
477 g_object_unref (priv->request_details_printer);
478 priv->request_details_printer = NULL;
483 gtk_print_unix_dialog_finalize (GObject *object)
485 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
486 GtkPrintUnixDialogPrivate *priv = dialog->priv;
487 GtkPrintBackend *backend;
490 unschedule_idle_mark_conflicts (dialog);
491 disconnect_printer_details_request (dialog);
493 if (priv->current_printer)
495 g_object_unref (priv->current_printer);
496 priv->current_printer = NULL;
499 if (priv->printer_list)
501 g_object_unref (priv->printer_list);
502 priv->printer_list = NULL;
505 if (priv->printer_list_filter)
507 g_object_unref (priv->printer_list_filter);
508 priv->printer_list_filter = NULL;
514 g_object_unref (priv->options);
515 priv->options = NULL;
518 if (priv->number_up_layout_2_option)
520 priv->number_up_layout_2_option->choices[0] = NULL;
521 priv->number_up_layout_2_option->choices[1] = NULL;
522 g_free (priv->number_up_layout_2_option->choices_display[0]);
523 g_free (priv->number_up_layout_2_option->choices_display[1]);
524 priv->number_up_layout_2_option->choices_display[0] = NULL;
525 priv->number_up_layout_2_option->choices_display[1] = NULL;
526 g_object_unref (priv->number_up_layout_2_option);
527 priv->number_up_layout_2_option = NULL;
530 if (priv->number_up_layout_n_option)
532 g_object_unref (priv->number_up_layout_n_option);
533 priv->number_up_layout_n_option = NULL;
536 if (priv->page_setup)
538 g_object_unref (priv->page_setup);
539 priv->page_setup = NULL;
542 if (priv->initial_settings)
544 g_object_unref (priv->initial_settings);
545 priv->initial_settings = NULL;
548 g_free (priv->waiting_for_printer);
549 priv->waiting_for_printer = NULL;
551 g_free (priv->format_for_printer);
552 priv->format_for_printer = NULL;
554 for (node = priv->print_backends; node != NULL; node = node->next)
556 backend = GTK_PRINT_BACKEND (node->data);
558 g_signal_handlers_disconnect_by_func (backend, printer_added_cb, dialog);
559 g_signal_handlers_disconnect_by_func (backend, printer_removed_cb, dialog);
560 g_signal_handlers_disconnect_by_func (backend, printer_status_cb, dialog);
562 gtk_print_backend_destroy (backend);
563 g_object_unref (backend);
566 g_list_free (priv->print_backends);
567 priv->print_backends = NULL;
569 G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->finalize (object);
573 printer_removed_cb (GtkPrintBackend *backend,
575 GtkPrintUnixDialog *dialog)
577 GtkPrintUnixDialogPrivate *priv = dialog->priv;
580 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
581 gtk_list_store_remove (GTK_LIST_STORE (priv->printer_list), iter);
585 gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface)
587 parent_buildable_iface = g_type_interface_peek_parent (iface);
589 iface->get_internal_child = gtk_print_unix_dialog_buildable_get_internal_child;
593 gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
595 const gchar *childname)
597 if (strcmp (childname, "notebook") == 0)
598 return G_OBJECT (GTK_PRINT_UNIX_DIALOG (buildable)->priv->notebook);
600 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
603 /* This function controls "sensitive" property of GtkCellRenderer based on pause
604 * state of printers. */
605 void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
606 GtkCellRenderer *cell,
607 GtkTreeModel *tree_model,
613 gtk_tree_model_get (tree_model, iter, PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
615 if (printer != NULL && !gtk_printer_is_accepting_jobs (printer))
626 printer_status_cb (GtkPrintBackend *backend,
628 GtkPrintUnixDialog *dialog)
630 GtkPrintUnixDialogPrivate *priv = dialog->priv;
632 GtkTreeSelection *selection;
634 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
636 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), iter,
637 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
638 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
639 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
640 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
643 /* When the pause state change then we need to update sensitive property
644 * of GTK_RESPONSE_OK button inside of selected_printer_changed function. */
645 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
646 selected_printer_changed (selection, dialog);
650 printer_added_cb (GtkPrintBackend *backend,
652 GtkPrintUnixDialog *dialog)
654 GtkPrintUnixDialogPrivate *priv = dialog->priv;
655 GtkTreeIter iter, filter_iter;
656 GtkTreeSelection *selection;
659 gtk_list_store_append (GTK_LIST_STORE (priv->printer_list), &iter);
661 g_object_set_data_full (G_OBJECT (printer),
662 "gtk-print-tree-iter",
663 gtk_tree_iter_copy (&iter),
664 (GDestroyNotify) gtk_tree_iter_free);
666 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), &iter,
667 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
668 PRINTER_LIST_COL_NAME, gtk_printer_get_name (printer),
669 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
670 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
671 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
672 PRINTER_LIST_COL_PRINTER_OBJ, printer,
675 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
676 &filter_iter, &iter);
677 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->printer_list_filter), &filter_iter);
679 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
681 if (priv->waiting_for_printer != NULL &&
682 strcmp (gtk_printer_get_name (printer),
683 priv->waiting_for_printer) == 0)
685 priv->internal_printer_change = TRUE;
686 gtk_tree_selection_select_iter (selection, &filter_iter);
687 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
688 path, NULL, TRUE, 0.5, 0.0);
689 priv->internal_printer_change = FALSE;
690 g_free (priv->waiting_for_printer);
691 priv->waiting_for_printer = NULL;
693 else if (is_default_printer (dialog, printer) &&
694 gtk_tree_selection_count_selected_rows (selection) == 0)
696 priv->internal_printer_change = TRUE;
697 gtk_tree_selection_select_iter (selection, &filter_iter);
698 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
699 path, NULL, TRUE, 0.5, 0.0);
700 priv->internal_printer_change = FALSE;
703 gtk_tree_path_free (path);
707 printer_list_initialize (GtkPrintUnixDialog *dialog,
708 GtkPrintBackend *print_backend)
713 g_return_if_fail (print_backend != NULL);
715 g_signal_connect_object (print_backend,
717 (GCallback) printer_added_cb,
718 G_OBJECT (dialog), 0);
720 g_signal_connect_object (print_backend,
722 (GCallback) printer_removed_cb,
723 G_OBJECT (dialog), 0);
725 g_signal_connect_object (print_backend,
726 "printer-status-changed",
727 (GCallback) printer_status_cb,
728 G_OBJECT (dialog), 0);
730 list = gtk_print_backend_get_printer_list (print_backend);
735 printer_added_cb (print_backend, node->data, dialog);
743 load_print_backends (GtkPrintUnixDialog *dialog)
745 GtkPrintUnixDialogPrivate *priv = dialog->priv;
748 if (g_module_supported ())
749 priv->print_backends = gtk_print_backend_load_modules ();
751 for (node = priv->print_backends; node != NULL; node = node->next)
752 printer_list_initialize (dialog, GTK_PRINT_BACKEND (node->data));
756 gtk_print_unix_dialog_set_property (GObject *object,
762 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
766 case PROP_PAGE_SETUP:
767 gtk_print_unix_dialog_set_page_setup (dialog, g_value_get_object (value));
769 case PROP_CURRENT_PAGE:
770 gtk_print_unix_dialog_set_current_page (dialog, g_value_get_int (value));
772 case PROP_PRINT_SETTINGS:
773 gtk_print_unix_dialog_set_settings (dialog, g_value_get_object (value));
776 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
782 gtk_print_unix_dialog_get_property (GObject *object,
787 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
788 GtkPrintUnixDialogPrivate *priv = dialog->priv;
792 case PROP_PAGE_SETUP:
793 g_value_set_object (value, priv->page_setup);
795 case PROP_CURRENT_PAGE:
796 g_value_set_int (value, priv->current_page);
798 case PROP_PRINT_SETTINGS:
799 g_value_take_object (value, gtk_print_unix_dialog_get_settings (dialog));
801 case PROP_SELECTED_PRINTER:
802 g_value_set_object (value, priv->current_printer);
805 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
811 is_printer_active (GtkTreeModel *model,
813 GtkPrintUnixDialog *dialog)
817 GtkPrintUnixDialogPrivate *priv = dialog->priv;
819 gtk_tree_model_get (model,
821 PRINTER_LIST_COL_PRINTER_OBJ,
828 result = gtk_printer_is_active (printer);
831 priv->manual_capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF |
832 GTK_PRINT_CAPABILITY_GENERATE_PS))
834 /* Check that the printer can handle at least one of the data
835 * formats that the application supports.
837 result = ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF) &&
838 gtk_printer_accepts_pdf (printer)) ||
839 ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS) &&
840 gtk_printer_accepts_ps (printer));
843 g_object_unref (printer);
849 default_printer_list_sort_func (GtkTreeModel *model,
856 GtkPrinter *a_printer;
857 GtkPrinter *b_printer;
860 gtk_tree_model_get (model, a,
861 PRINTER_LIST_COL_NAME, &a_name,
862 PRINTER_LIST_COL_PRINTER_OBJ, &a_printer,
864 gtk_tree_model_get (model, b,
865 PRINTER_LIST_COL_NAME, &b_name,
866 PRINTER_LIST_COL_PRINTER_OBJ, &b_printer,
869 if (a_printer == NULL && b_printer == NULL)
871 else if (a_printer == NULL)
873 else if (b_printer == NULL)
875 else if (gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
877 else if (gtk_printer_is_virtual (a_printer) && !gtk_printer_is_virtual (b_printer))
879 else if (!gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
881 else if (a_name == NULL && b_name == NULL)
883 else if (a_name == NULL && b_name != NULL)
885 else if (a_name != NULL && b_name == NULL)
888 result = g_ascii_strcasecmp (a_name, b_name);
892 g_object_unref (a_printer);
893 g_object_unref (b_printer);
900 create_printer_list_model (GtkPrintUnixDialog *dialog)
902 GtkPrintUnixDialogPrivate *priv = dialog->priv;
904 GtkTreeSortable *sort;
906 model = gtk_list_store_new (PRINTER_LIST_N_COLS,
914 priv->printer_list = (GtkTreeModel *)model;
915 priv->printer_list_filter = (GtkTreeModelFilter *) gtk_tree_model_filter_new ((GtkTreeModel *)model,
918 gtk_tree_model_filter_set_visible_func (priv->printer_list_filter,
919 (GtkTreeModelFilterVisibleFunc) is_printer_active,
923 sort = GTK_TREE_SORTABLE (model);
924 gtk_tree_sortable_set_default_sort_func (sort,
925 default_printer_list_sort_func,
929 gtk_tree_sortable_set_sort_column_id (sort,
930 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
937 wrap_in_frame (const gchar *label,
940 GtkWidget *frame, *alignment, *label_widget;
943 label_widget = gtk_label_new (NULL);
944 gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
945 gtk_widget_show (label_widget);
947 bold_text = g_markup_printf_escaped ("<b>%s</b>", label);
948 gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
951 frame = gtk_vbox_new (FALSE, 6);
952 gtk_box_pack_start (GTK_BOX (frame), label_widget, FALSE, FALSE, 0);
954 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
955 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
957 gtk_box_pack_start (GTK_BOX (frame), alignment, FALSE, FALSE, 0);
959 gtk_container_add (GTK_CONTAINER (alignment), child);
961 gtk_widget_show (frame);
962 gtk_widget_show (alignment);
968 setup_option (GtkPrintUnixDialog *dialog,
969 const gchar *option_name,
970 GtkPrinterOptionWidget *widget)
972 GtkPrintUnixDialogPrivate *priv = dialog->priv;
973 GtkPrinterOption *option;
975 option = gtk_printer_option_set_lookup (priv->options, option_name);
976 gtk_printer_option_widget_set_source (widget, option);
978 return option != NULL;
982 add_option_to_extension_point (GtkPrinterOption *option,
985 GtkWidget *extension_point = data;
988 widget = gtk_printer_option_widget_new (option);
989 gtk_widget_show (widget);
991 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
993 GtkWidget *label, *hbox;
995 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
996 gtk_widget_show (label);
997 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
998 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1000 hbox = gtk_hbox_new (FALSE, 12);
1001 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1002 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1003 gtk_widget_show (hbox);
1005 gtk_box_pack_start (GTK_BOX (extension_point), hbox, FALSE, FALSE, 0);
1008 gtk_box_pack_start (GTK_BOX (extension_point), widget, FALSE, FALSE, 0);
1012 add_option_to_table (GtkPrinterOption *option,
1016 GtkWidget *label, *widget;
1019 table = GTK_TABLE (user_data);
1021 if (g_str_has_prefix (option->name, "gtk-"))
1024 widget = gtk_printer_option_widget_new (option);
1025 gtk_widget_show (widget);
1028 gtk_table_resize (table, table->nrows + 1, 2);
1030 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1032 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1033 gtk_widget_show (label);
1035 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1036 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1038 gtk_table_attach (table, label,
1039 0, 1, row - 1 , row, GTK_FILL, 0, 0, 0);
1041 gtk_table_attach (table, widget,
1042 1, 2, row - 1, row, GTK_FILL, 0, 0, 0);
1045 gtk_table_attach (table, widget,
1046 0, 2, row - 1, row, GTK_FILL, 0, 0, 0);
1051 setup_page_table (GtkPrinterOptionSet *options,
1056 gtk_printer_option_set_foreach_in_group (options, group,
1057 add_option_to_table,
1059 if (GTK_TABLE (table)->nrows == 1)
1060 gtk_widget_hide (page);
1062 gtk_widget_show (page);
1066 update_print_at_option (GtkPrintUnixDialog *dialog)
1068 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1069 GtkPrinterOption *option;
1071 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1076 if (priv->updating_print_at)
1079 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_at_radio)))
1080 gtk_printer_option_set (option, "at");
1081 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio)))
1082 gtk_printer_option_set (option, "on-hold");
1084 gtk_printer_option_set (option, "now");
1086 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1089 const char *text = gtk_entry_get_text (GTK_ENTRY (priv->print_at_entry));
1090 gtk_printer_option_set (option,text);
1096 setup_print_at (GtkPrintUnixDialog *dialog)
1098 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1099 GtkPrinterOption *option;
1101 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1105 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1107 gtk_widget_set_sensitive (priv->print_at_radio, FALSE);
1108 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1109 gtk_widget_set_sensitive (priv->print_hold_radio, FALSE);
1110 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), "");
1114 priv->updating_print_at = TRUE;
1116 if (gtk_printer_option_has_choice (option, "at"))
1118 gtk_widget_set_sensitive (priv->print_at_radio, TRUE);
1119 gtk_widget_set_sensitive (priv->print_at_entry, TRUE);
1123 gtk_widget_set_sensitive (priv->print_at_radio, FALSE);
1124 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1127 gtk_widget_set_sensitive (priv->print_hold_radio,
1128 gtk_printer_option_has_choice (option, "on-hold"));
1130 update_print_at_option (dialog);
1132 if (strcmp (option->value, "at") == 0)
1133 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_at_radio),
1135 else if (strcmp (option->value, "on-hold") == 0)
1136 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio),
1139 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1142 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1144 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry),
1148 priv->updating_print_at = FALSE;
1154 update_dialog_from_settings (GtkPrintUnixDialog *dialog)
1156 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1159 GtkWidget *table, *frame;
1160 gboolean has_advanced, has_job;
1162 if (priv->current_printer == NULL)
1164 clear_per_printer_ui (dialog);
1165 gtk_widget_hide (priv->job_page);
1166 gtk_widget_hide (priv->advanced_page);
1167 gtk_widget_hide (priv->image_quality_page);
1168 gtk_widget_hide (priv->finishing_page);
1169 gtk_widget_hide (priv->color_page);
1170 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1175 setup_option (dialog, "gtk-n-up", priv->pages_per_sheet);
1176 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
1177 setup_option (dialog, "gtk-duplex", priv->duplex);
1178 setup_option (dialog, "gtk-paper-type", priv->paper_type);
1179 setup_option (dialog, "gtk-paper-source", priv->paper_source);
1180 setup_option (dialog, "gtk-output-tray", priv->output_tray);
1183 has_job |= setup_option (dialog, "gtk-job-prio", priv->job_prio);
1184 has_job |= setup_option (dialog, "gtk-billing-info", priv->billing_info);
1185 has_job |= setup_option (dialog, "gtk-cover-before", priv->cover_before);
1186 has_job |= setup_option (dialog, "gtk-cover-after", priv->cover_after);
1187 has_job |= setup_print_at (dialog);
1190 gtk_widget_show (priv->job_page);
1192 gtk_widget_hide (priv->job_page);
1195 setup_page_table (priv->options,
1197 priv->image_quality_table,
1198 priv->image_quality_page);
1200 setup_page_table (priv->options,
1202 priv->finishing_table,
1203 priv->finishing_page);
1205 setup_page_table (priv->options,
1210 gtk_printer_option_set_foreach_in_group (priv->options,
1211 "GtkPrintDialogExtension",
1212 add_option_to_extension_point,
1213 priv->extension_point);
1215 /* Put the rest of the groups in the advanced page */
1216 groups = gtk_printer_option_set_get_groups (priv->options);
1218 has_advanced = FALSE;
1219 for (l = groups; l != NULL; l = l->next)
1226 if (strcmp (group, "ImageQualityPage") == 0 ||
1227 strcmp (group, "ColorPage") == 0 ||
1228 strcmp (group, "FinishingPage") == 0 ||
1229 strcmp (group, "GtkPrintDialogExtension") == 0)
1232 table = gtk_table_new (1, 2, FALSE);
1233 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1234 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1236 gtk_printer_option_set_foreach_in_group (priv->options,
1238 add_option_to_table,
1240 if (GTK_TABLE (table)->nrows == 1)
1241 gtk_widget_destroy (table);
1244 has_advanced = TRUE;
1245 frame = wrap_in_frame (group, table);
1246 gtk_widget_show (table);
1247 gtk_widget_show (frame);
1249 gtk_box_pack_start (GTK_BOX (priv->advanced_vbox),
1250 frame, FALSE, FALSE, 0);
1255 gtk_widget_show (priv->advanced_page);
1257 gtk_widget_hide (priv->advanced_page);
1260 g_list_foreach (groups, (GFunc) g_free, NULL);
1261 g_list_free (groups);
1265 update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
1267 GtkPrintCapabilities caps;
1268 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1269 gboolean can_collate;
1270 const gchar *copies;
1272 copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin));
1273 can_collate = (*copies != '\0' && atoi (copies) > 1);
1275 caps = priv->manual_capabilities | priv->printer_capabilities;
1277 gtk_widget_set_sensitive (priv->page_set_combo,
1278 caps & GTK_PRINT_CAPABILITY_PAGE_SET);
1279 gtk_widget_set_sensitive (priv->copies_spin,
1280 caps & GTK_PRINT_CAPABILITY_COPIES);
1281 gtk_widget_set_sensitive (priv->collate_check,
1283 (caps & GTK_PRINT_CAPABILITY_COLLATE));
1284 gtk_widget_set_sensitive (priv->reverse_check,
1285 caps & GTK_PRINT_CAPABILITY_REVERSE);
1286 gtk_widget_set_sensitive (priv->scale_spin,
1287 caps & GTK_PRINT_CAPABILITY_SCALE);
1288 gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet),
1289 caps & GTK_PRINT_CAPABILITY_NUMBER_UP);
1291 if (caps & GTK_PRINT_CAPABILITY_PREVIEW)
1292 gtk_widget_show (priv->preview_button);
1294 gtk_widget_hide (priv->preview_button);
1296 update_collate_icon (NULL, dialog);
1298 gtk_tree_model_filter_refilter (priv->printer_list_filter);
1302 mark_conflicts (GtkPrintUnixDialog *dialog)
1304 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1305 GtkPrinter *printer;
1306 gboolean have_conflict;
1308 have_conflict = FALSE;
1310 printer = priv->current_printer;
1315 g_signal_handler_block (priv->options,
1316 priv->options_changed_handler);
1318 gtk_printer_option_set_clear_conflicts (priv->options);
1320 have_conflict = _gtk_printer_mark_conflicts (printer,
1323 g_signal_handler_unblock (priv->options,
1324 priv->options_changed_handler);
1328 gtk_widget_show (priv->conflicts_widget);
1330 gtk_widget_hide (priv->conflicts_widget);
1334 mark_conflicts_callback (gpointer data)
1336 GtkPrintUnixDialog *dialog = data;
1337 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1339 priv->mark_conflicts_id = 0;
1341 mark_conflicts (dialog);
1347 unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1349 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1351 if (priv->mark_conflicts_id != 0)
1353 g_source_remove (priv->mark_conflicts_id);
1354 priv->mark_conflicts_id = 0;
1359 schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1361 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1363 if (priv->mark_conflicts_id != 0)
1366 priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
1371 options_changed_cb (GtkPrintUnixDialog *dialog)
1373 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1375 schedule_idle_mark_conflicts (dialog);
1377 if (priv->initial_settings)
1379 g_object_unref (priv->initial_settings);
1380 priv->initial_settings = NULL;
1383 g_free (priv->waiting_for_printer);
1384 priv->waiting_for_printer = NULL;
1388 remove_custom_widget (GtkWidget *widget,
1389 GtkContainer *container)
1391 gtk_container_remove (container, widget);
1395 extension_point_clear_children (GtkContainer *container)
1397 gtk_container_foreach (container,
1398 (GtkCallback)remove_custom_widget,
1403 clear_per_printer_ui (GtkPrintUnixDialog *dialog)
1405 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1407 gtk_container_foreach (GTK_CONTAINER (priv->finishing_table),
1408 (GtkCallback)gtk_widget_destroy,
1410 gtk_table_resize (GTK_TABLE (priv->finishing_table), 1, 2);
1411 gtk_container_foreach (GTK_CONTAINER (priv->image_quality_table),
1412 (GtkCallback)gtk_widget_destroy,
1414 gtk_table_resize (GTK_TABLE (priv->image_quality_table), 1, 2);
1415 gtk_container_foreach (GTK_CONTAINER (priv->color_table),
1416 (GtkCallback)gtk_widget_destroy,
1418 gtk_table_resize (GTK_TABLE (priv->color_table), 1, 2);
1419 gtk_container_foreach (GTK_CONTAINER (priv->advanced_vbox),
1420 (GtkCallback)gtk_widget_destroy,
1422 extension_point_clear_children (GTK_CONTAINER (priv->extension_point));
1426 printer_details_acquired (GtkPrinter *printer,
1428 GtkPrintUnixDialog *dialog)
1430 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1432 disconnect_printer_details_request (dialog);
1436 GtkTreeSelection *selection;
1437 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
1439 selected_printer_changed (selection, dialog);
1444 selected_printer_changed (GtkTreeSelection *selection,
1445 GtkPrintUnixDialog *dialog)
1447 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1448 GtkPrinter *printer;
1449 GtkTreeIter iter, filter_iter;
1451 /* Whenever the user selects a printer we stop looking for
1452 the printer specified in the initial settings */
1453 if (priv->waiting_for_printer &&
1454 !priv->internal_printer_change)
1456 g_free (priv->waiting_for_printer);
1457 priv->waiting_for_printer = NULL;
1460 disconnect_printer_details_request (dialog);
1463 if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
1465 gtk_tree_model_filter_convert_iter_to_child_iter (priv->printer_list_filter,
1469 gtk_tree_model_get (priv->printer_list, &iter,
1470 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1474 /* sets GTK_RESPONSE_OK button sensitive/insensitive depending on whether the printer
1475 * accepts/rejects jobs */
1476 if (printer != NULL)
1478 if (!gtk_printer_is_accepting_jobs (printer))
1480 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1484 if (priv->current_printer == printer && gtk_printer_has_details (printer))
1485 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1489 if (printer != NULL && !gtk_printer_has_details (printer))
1491 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1492 priv->request_details_tag =
1493 g_signal_connect (printer, "details-acquired",
1494 G_CALLBACK (printer_details_acquired), dialog);
1495 /* take the reference */
1496 priv->request_details_printer = printer;
1497 gtk_printer_request_details (printer);
1501 if (printer == priv->current_printer)
1504 g_object_unref (printer);
1510 g_object_unref (priv->options);
1511 priv->options = NULL;
1513 clear_per_printer_ui (dialog);
1516 if (priv->current_printer)
1518 g_object_unref (priv->current_printer);
1521 priv->printer_capabilities = 0;
1523 if (gtk_printer_is_accepting_jobs (printer))
1524 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1525 priv->current_printer = printer;
1527 if (printer != NULL)
1529 if (!priv->page_setup_set)
1531 /* if no explicit page setup has been set, use the printer default */
1532 GtkPageSetup *page_setup;
1534 page_setup = gtk_printer_get_default_page_size (printer);
1537 page_setup = gtk_page_setup_new ();
1539 g_object_unref (priv->page_setup);
1540 priv->page_setup = page_setup;
1543 priv->printer_capabilities = gtk_printer_get_capabilities (printer);
1544 priv->options = _gtk_printer_get_options (printer,
1545 priv->initial_settings,
1547 priv->manual_capabilities);
1549 priv->options_changed_handler =
1550 g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
1553 update_dialog_from_settings (dialog);
1554 update_dialog_from_capabilities (dialog);
1558 update_collate_icon (GtkToggleButton *toggle_button,
1559 GtkPrintUnixDialog *dialog)
1561 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1563 gtk_widget_queue_draw (priv->collate_image);
1567 paint_page (GtkWidget *widget,
1575 gint x, y, width, height;
1576 gint text_y, linewidth;
1578 x = x_offset * scale;
1579 y = y_offset * scale;
1581 height = 26 * scale;
1586 gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
1587 cairo_rectangle (cr, x, y, width, height);
1590 gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_NORMAL]);
1591 cairo_set_line_width (cr, linewidth);
1592 cairo_rectangle (cr, x + linewidth/2.0, y + linewidth/2.0, width - linewidth, height - linewidth);
1595 cairo_select_font_face (cr, "Sans",
1596 CAIRO_FONT_SLANT_NORMAL,
1597 CAIRO_FONT_WEIGHT_NORMAL);
1598 cairo_set_font_size (cr, (gint)(9 * scale));
1599 cairo_move_to (cr, x + (gint)(text_x * scale), y + (gint)(text_y * scale));
1600 cairo_show_text (cr, text);
1605 draw_collate_cb (GtkWidget *widget,
1606 GdkEventExpose *event,
1607 GtkPrintUnixDialog *dialog)
1609 GtkSettings *settings;
1613 gboolean collate, reverse, rtl;
1617 collate = dialog_get_collate (dialog);
1618 reverse = dialog_get_reverse (dialog);
1619 copies = dialog_get_n_copies (dialog);
1621 rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL);
1623 settings = gtk_widget_get_settings (widget);
1624 gtk_icon_size_lookup_for_settings (settings,
1625 GTK_ICON_SIZE_DIALOG,
1628 scale = size / 48.0;
1629 text_x = rtl ? 4 : 11;
1631 cr = gdk_cairo_create (widget->window);
1633 cairo_translate (cr, widget->allocation.x, widget->allocation.y);
1637 paint_page (widget, cr, scale, rtl ? 40: 15, 5, reverse ? "1" : "2", text_x);
1638 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
1642 paint_page (widget, cr, scale, rtl ? 40: 15, 5, collate == reverse ? "1" : "2", text_x);
1643 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
1645 paint_page (widget, cr, scale, rtl ? 5 : 50, 5, reverse ? "1" : "2", text_x);
1646 paint_page (widget, cr, scale, rtl ? 15 : 40, 15, collate == reverse ? "2" : "1", text_x);
1655 gtk_print_unix_dialog_style_set (GtkWidget *widget,
1656 GtkStyle *previous_style)
1658 GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_set (widget, previous_style);
1660 if (gtk_widget_has_screen (widget))
1662 GtkPrintUnixDialog *dialog = (GtkPrintUnixDialog *)widget;
1663 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1664 GtkSettings *settings;
1668 settings = gtk_widget_get_settings (widget);
1669 gtk_icon_size_lookup_for_settings (settings,
1670 GTK_ICON_SIZE_DIALOG,
1673 scale = size / 48.0;
1675 gtk_widget_set_size_request (priv->collate_image,
1682 update_range_sensitivity (GtkWidget *button,
1687 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
1689 gtk_widget_set_sensitive (range, active);
1693 create_main_page (GtkPrintUnixDialog *dialog)
1695 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1696 GtkWidget *main_vbox, *label, *vbox, *hbox;
1697 GtkWidget *scrolled, *treeview, *frame, *table;
1698 GtkWidget *entry, *spinbutton;
1699 GtkWidget *radio, *check, *image;
1700 GtkCellRenderer *renderer;
1701 GtkTreeViewColumn *column;
1702 GtkTreeSelection *selection;
1703 GtkWidget *custom_input;
1705 main_vbox = gtk_vbox_new (FALSE, 18);
1706 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
1707 gtk_widget_show (main_vbox);
1709 vbox = gtk_vbox_new (FALSE, 6);
1710 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
1711 gtk_widget_show (vbox);
1713 scrolled = gtk_scrolled_window_new (NULL, NULL);
1714 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
1715 GTK_POLICY_AUTOMATIC,
1716 GTK_POLICY_AUTOMATIC);
1717 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
1719 gtk_widget_show (scrolled);
1720 gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
1722 treeview = gtk_tree_view_new_with_model ((GtkTreeModel *) priv->printer_list_filter);
1723 priv->printer_treeview = treeview;
1724 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
1725 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), PRINTER_LIST_COL_NAME);
1726 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), TRUE);
1727 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
1728 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
1729 g_signal_connect (selection, "changed", G_CALLBACK (selected_printer_changed), dialog);
1731 renderer = gtk_cell_renderer_pixbuf_new ();
1732 column = gtk_tree_view_column_new_with_attributes ("",
1735 PRINTER_LIST_COL_ICON,
1737 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1738 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1740 renderer = gtk_cell_renderer_text_new ();
1741 column = gtk_tree_view_column_new_with_attributes (_("Printer"),
1744 PRINTER_LIST_COL_NAME,
1746 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1747 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1749 renderer = gtk_cell_renderer_text_new ();
1750 column = gtk_tree_view_column_new_with_attributes (_("Location"),
1753 PRINTER_LIST_COL_LOCATION,
1755 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1756 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1758 renderer = gtk_cell_renderer_text_new ();
1759 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1760 column = gtk_tree_view_column_new_with_attributes (_("Status"),
1763 PRINTER_LIST_COL_STATE,
1765 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1766 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1768 gtk_widget_show (treeview);
1769 gtk_container_add (GTK_CONTAINER (scrolled), treeview);
1771 custom_input = gtk_hbox_new (FALSE, 18);
1772 gtk_widget_show (custom_input);
1773 gtk_box_pack_start (GTK_BOX (vbox), custom_input, FALSE, FALSE, 0);
1774 priv->extension_point = custom_input;
1776 hbox = gtk_hbox_new (FALSE, 18);
1777 gtk_widget_show (hbox);
1778 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
1780 table = gtk_table_new (3, 2, FALSE);
1781 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1782 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1783 frame = wrap_in_frame (_("Range"), table);
1784 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
1785 gtk_widget_show (table);
1787 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_All Pages"));
1788 priv->all_pages_radio = radio;
1789 gtk_widget_show (radio);
1790 gtk_table_attach (GTK_TABLE (table), radio,
1791 0, 2, 0, 1, GTK_FILL, 0,
1793 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
1794 _("C_urrent Page"));
1795 if (priv->current_page == -1)
1796 gtk_widget_set_sensitive (radio, FALSE);
1797 priv->current_page_radio = radio;
1798 gtk_widget_show (radio);
1799 gtk_table_attach (GTK_TABLE (table), radio,
1800 0, 2, 1, 2, GTK_FILL, 0,
1803 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)), _("Pag_es:"));
1804 gtk_widget_set_tooltip_text (radio, _("Specify one or more page ranges,\n e.g. 1-3,7,11"));
1806 priv->page_range_radio = radio;
1807 gtk_widget_show (radio);
1808 gtk_table_attach (GTK_TABLE (table), radio,
1809 0, 1, 2, 3, GTK_FILL, 0,
1811 entry = gtk_entry_new ();
1812 priv->page_range_entry = entry;
1813 gtk_widget_show (entry);
1814 gtk_table_attach (GTK_TABLE (table), entry,
1815 1, 2, 2, 3, GTK_FILL, 0,
1817 g_signal_connect (radio, "toggled", G_CALLBACK (update_range_sensitivity), entry);
1818 update_range_sensitivity (radio, entry);
1820 table = gtk_table_new (3, 2, FALSE);
1821 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1822 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1823 frame = wrap_in_frame (_("Copies"), table);
1824 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
1825 gtk_widget_show (table);
1827 /* FIXME chpe: too much space between Copies and spinbutton, put those 2 in a hbox and make it span 2 columns */
1828 label = gtk_label_new_with_mnemonic (_("Copie_s:"));
1829 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1830 gtk_widget_show (label);
1831 gtk_table_attach (GTK_TABLE (table), label,
1832 0, 1, 0, 1, GTK_FILL, 0,
1834 spinbutton = gtk_spin_button_new_with_range (1.0, 100.0, 1.0);
1835 priv->copies_spin = spinbutton;
1836 gtk_widget_show (spinbutton);
1837 gtk_table_attach (GTK_TABLE (table), spinbutton,
1838 1, 2, 0, 1, GTK_FILL, 0,
1840 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
1841 g_signal_connect_swapped (spinbutton, "value-changed",
1842 G_CALLBACK (update_dialog_from_capabilities), dialog);
1843 g_signal_connect_swapped (spinbutton, "changed",
1844 G_CALLBACK (update_dialog_from_capabilities), dialog);
1846 check = gtk_check_button_new_with_mnemonic (_("C_ollate"));
1847 priv->collate_check = check;
1848 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
1849 gtk_widget_show (check);
1850 gtk_table_attach (GTK_TABLE (table), check,
1851 0, 1, 1, 2, GTK_FILL, 0,
1854 check = gtk_check_button_new_with_mnemonic (_("_Reverse"));
1855 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
1856 priv->reverse_check = check;
1857 gtk_widget_show (check);
1858 gtk_table_attach (GTK_TABLE (table), check,
1859 0, 1, 2, 3, GTK_FILL, 0,
1862 image = gtk_drawing_area_new ();
1863 GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
1865 priv->collate_image = image;
1866 gtk_widget_show (image);
1867 gtk_widget_set_size_request (image, 70, 90);
1868 gtk_table_attach (GTK_TABLE (table), image,
1869 1, 2, 1, 3, GTK_FILL, 0,
1871 g_signal_connect (image, "expose-event",
1872 G_CALLBACK (draw_collate_cb), dialog);
1874 label = gtk_label_new (_("General"));
1875 gtk_widget_show (label);
1877 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), main_vbox, label);
1881 is_range_separator (gchar c)
1883 return (c == ',' || c == ';' || c == ':');
1886 static GtkPageRange *
1887 dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
1890 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1892 const gchar *text, *p;
1894 GtkPageRange *ranges;
1897 text = gtk_entry_get_text (GTK_ENTRY (priv->page_range_entry));
1909 if (is_range_separator (*p))
1914 ranges = g_new0 (GtkPageRange, n_ranges);
1920 while (isspace (*p)) p++;
1924 /* a half-open range like -2 */
1929 start = (int)strtol (p, &next, 10);
1937 while (isspace (*p)) p++;
1942 end = (int)strtol (p, &next, 10);
1943 if (next == p) /* a half-open range like 2- */
1945 else if (end < start)
1949 ranges[i].start = start - 1;
1950 ranges[i].end = end - 1;
1953 /* Skip until end or separator */
1954 while (*p && !is_range_separator (*p))
1957 /* if not at end, skip separator */
1968 dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
1969 GtkPageRange *ranges,
1972 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1974 GString *s = g_string_new (NULL);
1976 for (i = 0; i < n_ranges; i++)
1978 g_string_append_printf (s, "%d", ranges[i].start + 1);
1979 if (ranges[i].end > ranges[i].start)
1980 g_string_append_printf (s, "-%d", ranges[i].end + 1);
1981 else if (ranges[i].end == -1)
1982 g_string_append (s, "-");
1984 if (i != n_ranges - 1)
1985 g_string_append (s, ",");
1988 gtk_entry_set_text (GTK_ENTRY (priv->page_range_entry), s->str);
1990 g_string_free (s, TRUE);
1994 static GtkPrintPages
1995 dialog_get_print_pages (GtkPrintUnixDialog *dialog)
1997 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1999 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio)))
2000 return GTK_PRINT_PAGES_ALL;
2001 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->current_page_radio)))
2002 return GTK_PRINT_PAGES_CURRENT;
2004 return GTK_PRINT_PAGES_RANGES;
2008 dialog_set_print_pages (GtkPrintUnixDialog *dialog,
2009 GtkPrintPages pages)
2011 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2013 if (pages == GTK_PRINT_PAGES_RANGES)
2014 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
2015 else if (pages == GTK_PRINT_PAGES_CURRENT)
2016 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->current_page_radio), TRUE);
2018 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio), TRUE);
2022 dialog_get_scale (GtkPrintUnixDialog *dialog)
2024 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->scale_spin))
2025 return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
2031 dialog_set_scale (GtkPrintUnixDialog *dialog,
2034 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin), val);
2038 dialog_get_page_set (GtkPrintUnixDialog *dialog)
2040 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->page_set_combo))
2041 return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
2043 return GTK_PAGE_SET_ALL;
2047 dialog_set_page_set (GtkPrintUnixDialog *dialog,
2050 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->page_set_combo),
2055 dialog_get_n_copies (GtkPrintUnixDialog *dialog)
2057 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->copies_spin))
2058 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
2063 dialog_set_n_copies (GtkPrintUnixDialog *dialog,
2066 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->copies_spin),
2071 dialog_get_collate (GtkPrintUnixDialog *dialog)
2073 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->collate_check))
2074 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
2079 dialog_set_collate (GtkPrintUnixDialog *dialog,
2082 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check),
2087 dialog_get_reverse (GtkPrintUnixDialog *dialog)
2089 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->reverse_check))
2090 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
2095 dialog_set_reverse (GtkPrintUnixDialog *dialog,
2098 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check),
2103 dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
2105 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2109 val = gtk_printer_option_widget_get_value (priv->pages_per_sheet);
2123 static GtkNumberUpLayout
2124 dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
2126 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2127 GtkPrintCapabilities caps;
2128 GtkNumberUpLayout layout;
2129 GtkTextDirection text_direction;
2132 val = gtk_printer_option_widget_get_value (priv->number_up_layout);
2133 text_direction = gtk_widget_get_default_direction ();
2135 caps = priv->manual_capabilities | priv->printer_capabilities;
2137 if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
2139 if (text_direction == GTK_TEXT_DIR_LTR)
2140 layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2142 layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
2145 layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2150 if (strcmp (val, "lrtb") == 0)
2151 return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2153 if (strcmp (val, "lrbt") == 0)
2154 return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP;
2156 if (strcmp (val, "rltb") == 0)
2157 return GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
2159 if (strcmp (val, "rlbt") == 0)
2160 return GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP;
2162 if (strcmp (val, "tblr") == 0)
2163 return GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT;
2165 if (strcmp (val, "tbrl") == 0)
2166 return GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT;
2168 if (strcmp (val, "btlr") == 0)
2169 return GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT;
2171 if (strcmp (val, "btrl") == 0)
2172 return GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT;
2178 draw_page_cb (GtkWidget *widget,
2179 GdkEventExpose *event,
2180 GtkPrintUnixDialog *dialog)
2182 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2185 gint w, h, tmp, shadow_offset;
2186 gint pages_x, pages_y, i, x, y, layout_w, layout_h;
2187 gdouble page_width, page_height;
2188 GtkPageOrientation orientation;
2190 PangoLayout *layout;
2191 PangoFontDescription *font;
2194 GtkNumberUpLayout number_up_layout;
2195 gint start_x, end_x, start_y, end_y;
2197 gboolean horizontal;
2199 orientation = gtk_page_setup_get_orientation (priv->page_setup);
2201 (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
2202 (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
2204 number_up_layout = dialog_get_number_up_layout (dialog);
2206 cr = gdk_cairo_create (widget->window);
2208 cairo_translate (cr, widget->allocation.x, widget->allocation.y);
2212 w = (EXAMPLE_PAGE_AREA_SIZE - 3) / ratio;
2215 switch (dialog_get_pages_per_sheet (dialog))
2219 pages_x = 1; pages_y = 1;
2222 landscape = !landscape;
2223 pages_x = 1; pages_y = 2;
2226 pages_x = 2; pages_y = 2;
2229 landscape = !landscape;
2230 pages_x = 2; pages_y = 3;
2233 pages_x = 3; pages_y = 3;
2236 pages_x = 4; pages_y = 4;
2253 color = &widget->style->text[GTK_STATE_NORMAL];
2254 cairo_set_source_rgba (cr, color->red / 65535., color->green / 65535., color->blue / 65535, 0.5);
2255 cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
2258 gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
2259 cairo_rectangle (cr, 1, 1, w, h);
2261 cairo_set_line_width (cr, 1.0);
2262 cairo_rectangle (cr, 0.5, 0.5, w+1, h+1);
2264 gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_NORMAL]);
2269 page_width = (double)w / pages_x;
2270 page_height = (double)h / pages_y;
2272 layout = pango_cairo_create_layout (cr);
2274 font = pango_font_description_new ();
2275 pango_font_description_set_family (font, "sans");
2276 pango_font_description_set_absolute_size (font, page_height * 0.4 * PANGO_SCALE);
2277 pango_layout_set_font_description (layout, font);
2278 pango_font_description_free (font);
2280 pango_layout_set_width (layout, page_width * PANGO_SCALE);
2281 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2283 switch (number_up_layout)
2286 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
2288 end_x = pages_x - 1;
2290 end_y = pages_y - 1;
2295 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
2297 end_x = pages_x - 1;
2298 start_y = pages_y - 1;
2304 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
2305 start_x = pages_x - 1;
2308 end_y = pages_y - 1;
2313 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
2314 start_x = pages_x - 1;
2316 start_y = pages_y - 1;
2322 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
2324 end_x = pages_x - 1;
2326 end_y = pages_y - 1;
2331 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
2332 start_x = pages_x - 1;
2335 end_y = pages_y - 1;
2340 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
2342 end_x = pages_x - 1;
2343 start_y = pages_y - 1;
2349 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
2350 start_x = pages_x - 1;
2352 start_y = pages_y - 1;
2361 for (y = start_y; y != end_y + dy; y += dy)
2363 for (x = start_x; x != end_x + dx; x += dx)
2365 text = g_strdup_printf ("%d", i++);
2366 pango_layout_set_text (layout, text, -1);
2368 pango_layout_get_size (layout, &layout_w, &layout_h);
2370 cairo_translate (cr,
2372 y * page_height + (page_height - layout_h / 1024.0) / 2);
2374 pango_cairo_show_layout (cr, layout);
2379 for (x = start_x; x != end_x + dx; x += dx)
2381 for (y = start_y; y != end_y + dy; y += dy)
2383 text = g_strdup_printf ("%d", i++);
2384 pango_layout_set_text (layout, text, -1);
2386 pango_layout_get_size (layout, &layout_w, &layout_h);
2388 cairo_translate (cr,
2390 y * page_height + (page_height - layout_h / 1024.0) / 2);
2392 pango_cairo_show_layout (cr, layout);
2397 g_object_unref (layout);
2404 redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
2406 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2408 if (priv->page_layout_preview)
2409 gtk_widget_queue_draw (priv->page_layout_preview);
2413 update_number_up_layout (GtkPrintUnixDialog *dialog)
2415 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2416 GtkPrintCapabilities caps;
2417 GtkPrinterOptionSet *set;
2418 GtkNumberUpLayout layout;
2419 GtkPrinterOption *option;
2420 GtkPrinterOption *old_option;
2422 set = priv->options;
2424 caps = priv->manual_capabilities | priv->printer_capabilities;
2426 if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
2428 if (priv->number_up_layout_n_option == NULL)
2430 priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
2431 g_object_ref (priv->number_up_layout_n_option);
2433 priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
2435 GTK_PRINTER_OPTION_TYPE_PICKONE);
2436 gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
2438 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
2439 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
2440 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
2441 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
2444 layout = dialog_get_number_up_layout (dialog);
2446 old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
2447 if (old_option != NULL)
2448 gtk_printer_option_set_remove (set, old_option);
2450 if (dialog_get_pages_per_sheet (dialog) != 1)
2452 if (dialog_get_pages_per_sheet (dialog) == 2)
2454 option = priv->number_up_layout_2_option;
2456 if (layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM ||
2457 layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP ||
2458 layout == GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT ||
2459 layout == GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT)
2460 gtk_printer_option_set (option, "lrtb");
2462 gtk_printer_option_set (option, "rltb");
2466 option = priv->number_up_layout_n_option;
2470 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
2471 gtk_printer_option_set (option, "lrtb");
2473 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
2474 gtk_printer_option_set (option, "lrbt");
2476 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
2477 gtk_printer_option_set (option, "rltb");
2479 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
2480 gtk_printer_option_set (option, "rlbt");
2482 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
2483 gtk_printer_option_set (option, "tblr");
2485 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
2486 gtk_printer_option_set (option, "tbrl");
2488 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
2489 gtk_printer_option_set (option, "btlr");
2491 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
2492 gtk_printer_option_set (option, "btrl");
2497 gtk_printer_option_set_add (set, option);
2501 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
2503 if (priv->number_up_layout != NULL)
2504 gtk_widget_set_sensitive (GTK_WIDGET (priv->number_up_layout),
2505 (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) &&
2506 (dialog_get_pages_per_sheet (dialog) > 1));
2510 create_page_setup_page (GtkPrintUnixDialog *dialog)
2512 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2513 GtkWidget *main_vbox, *label, *hbox, *hbox2;
2514 GtkWidget *frame, *table, *widget;
2515 GtkWidget *combo, *spinbutton, *draw;
2517 main_vbox = gtk_vbox_new (FALSE, 18);
2518 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2519 gtk_widget_show (main_vbox);
2521 hbox = gtk_hbox_new (FALSE, 18);
2522 gtk_widget_show (hbox);
2523 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
2525 table = gtk_table_new (5, 2, FALSE);
2526 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2527 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2528 frame = wrap_in_frame (_("Layout"), table);
2529 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2530 gtk_widget_show (table);
2532 label = gtk_label_new_with_mnemonic (_("T_wo-sided:"));
2533 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2534 gtk_widget_show (label);
2535 gtk_table_attach (GTK_TABLE (table), label,
2536 0, 1, 0, 1, GTK_FILL, 0,
2539 widget = gtk_printer_option_widget_new (NULL);
2540 priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
2541 gtk_widget_show (widget);
2542 gtk_table_attach (GTK_TABLE (table), widget,
2543 1, 2, 0, 1, GTK_FILL, 0,
2545 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2547 label = gtk_label_new_with_mnemonic (_("Pages per _side:"));
2548 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2549 gtk_widget_show (label);
2550 gtk_table_attach (GTK_TABLE (table), label,
2551 0, 1, 1, 2, GTK_FILL, 0,
2554 widget = gtk_printer_option_widget_new (NULL);
2555 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
2556 g_signal_connect_swapped (widget, "changed", G_CALLBACK (update_number_up_layout), dialog);
2557 priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
2558 gtk_widget_show (widget);
2559 gtk_table_attach (GTK_TABLE (table), widget,
2560 1, 2, 1, 2, GTK_FILL, 0,
2562 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2565 label = gtk_label_new_with_mnemonic (_("Page or_dering:"));
2566 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2567 gtk_widget_show (label);
2568 gtk_table_attach (GTK_TABLE (table), label,
2569 0, 1, 2, 3, GTK_FILL, 0,
2572 widget = gtk_printer_option_widget_new (NULL);
2573 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
2574 priv->number_up_layout = GTK_PRINTER_OPTION_WIDGET (widget);
2575 gtk_widget_show (widget);
2576 gtk_table_attach (GTK_TABLE (table), widget,
2577 1, 2, 2, 3, GTK_FILL, 0,
2579 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2581 label = gtk_label_new_with_mnemonic (_("_Only print:"));
2582 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2583 gtk_widget_show (label);
2584 gtk_table_attach (GTK_TABLE (table), label,
2585 0, 1, 3, 4, GTK_FILL, 0,
2588 combo = gtk_combo_box_new_text ();
2589 priv->page_set_combo = combo;
2590 gtk_widget_show (combo);
2591 gtk_table_attach (GTK_TABLE (table), combo,
2592 1, 2, 3, 4, GTK_FILL, 0,
2594 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
2596 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("All sheets"));
2597 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Even sheets"));
2598 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Odd sheets"));
2599 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
2601 label = gtk_label_new_with_mnemonic (_("Sc_ale:"));
2602 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2603 gtk_widget_show (label);
2604 gtk_table_attach (GTK_TABLE (table), label,
2605 0, 1, 4, 5, GTK_FILL, 0,
2608 hbox2 = gtk_hbox_new (FALSE, 6);
2609 gtk_widget_show (hbox2);
2610 gtk_table_attach (GTK_TABLE (table), hbox2,
2611 1, 2, 4, 5, GTK_FILL, 0,
2614 spinbutton = gtk_spin_button_new_with_range (1.0, 1000.0, 1.0);
2615 priv->scale_spin = spinbutton;
2616 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), 1);
2617 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton), 100.0);
2618 gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
2619 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
2620 gtk_widget_show (spinbutton);
2621 label = gtk_label_new ("%"); /* FIXMEchpe does there exist any language where % needs to be translated? */
2622 gtk_widget_show (label);
2623 gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2625 table = gtk_table_new (4, 2, FALSE);
2626 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2627 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2628 frame = wrap_in_frame (_("Paper"), table);
2629 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
2630 gtk_widget_show (table);
2632 label = gtk_label_new_with_mnemonic (_("Paper _type:"));
2633 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2634 gtk_widget_show (label);
2635 gtk_table_attach (GTK_TABLE (table), label,
2636 0, 1, 0, 1, GTK_FILL, 0,
2639 widget = gtk_printer_option_widget_new (NULL);
2640 priv->paper_type = GTK_PRINTER_OPTION_WIDGET (widget);
2641 gtk_widget_show (widget);
2642 gtk_table_attach (GTK_TABLE (table), widget,
2643 1, 2, 0, 1, GTK_FILL, 0,
2645 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2647 label = gtk_label_new_with_mnemonic (_("Paper _source:"));
2648 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2649 gtk_widget_show (label);
2650 gtk_table_attach (GTK_TABLE (table), label,
2651 0, 1, 1, 2, GTK_FILL, 0,
2654 widget = gtk_printer_option_widget_new (NULL);
2655 priv->paper_source = GTK_PRINTER_OPTION_WIDGET (widget);
2656 gtk_widget_show (widget);
2657 gtk_table_attach (GTK_TABLE (table), widget,
2658 1, 2, 1, 2, GTK_FILL, 0,
2660 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2662 label = gtk_label_new_with_mnemonic (_("Output t_ray:"));
2663 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2664 gtk_widget_show (label);
2665 gtk_table_attach (GTK_TABLE (table), label,
2666 0, 1, 2, 3, GTK_FILL, 0,
2669 widget = gtk_printer_option_widget_new (NULL);
2670 priv->output_tray = GTK_PRINTER_OPTION_WIDGET (widget);
2671 gtk_widget_show (widget);
2672 gtk_table_attach (GTK_TABLE (table), widget,
2673 1, 2, 2, 3, GTK_FILL, 0,
2675 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2677 /* Add the page layout preview */
2678 hbox2 = gtk_hbox_new (FALSE, 0);
2679 gtk_widget_show (hbox2);
2680 gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 0);
2682 draw = gtk_drawing_area_new ();
2683 GTK_WIDGET_SET_FLAGS (draw, GTK_NO_WINDOW);
2684 priv->page_layout_preview = draw;
2685 gtk_widget_set_size_request (draw, 200, 200);
2686 g_signal_connect (draw, "expose-event", G_CALLBACK (draw_page_cb), dialog);
2687 gtk_widget_show (draw);
2689 gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 0);
2691 label = gtk_label_new (_("Page Setup"));
2692 gtk_widget_show (label);
2694 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2699 create_job_page (GtkPrintUnixDialog *dialog)
2701 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2702 GtkWidget *main_table, *label;
2703 GtkWidget *frame, *table, *radio;
2704 GtkWidget *entry, *widget;
2706 main_table = gtk_table_new (2, 2, FALSE);
2707 gtk_container_set_border_width (GTK_CONTAINER (main_table), 12);
2708 gtk_table_set_row_spacings (GTK_TABLE (main_table), 18);
2709 gtk_table_set_col_spacings (GTK_TABLE (main_table), 18);
2711 table = gtk_table_new (2, 2, FALSE);
2712 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2713 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2714 frame = wrap_in_frame (_("Job Details"), table);
2715 gtk_table_attach (GTK_TABLE (main_table), frame,
2716 0, 1, 0, 1, GTK_FILL, 0,
2718 gtk_widget_show (table);
2720 label = gtk_label_new_with_mnemonic (_("Pri_ority:"));
2721 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2722 gtk_widget_show (label);
2723 gtk_table_attach (GTK_TABLE (table), label,
2724 0, 1, 0, 1, GTK_FILL, 0,
2727 widget = gtk_printer_option_widget_new (NULL);
2728 priv->job_prio = GTK_PRINTER_OPTION_WIDGET (widget);
2729 gtk_widget_show (widget);
2730 gtk_table_attach (GTK_TABLE (table), widget,
2731 1, 2, 0, 1, GTK_FILL, 0,
2733 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2735 label = gtk_label_new_with_mnemonic (_("_Billing info:"));
2736 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2737 gtk_widget_show (label);
2738 gtk_table_attach (GTK_TABLE (table), label,
2739 0, 1, 1, 2, GTK_FILL, 0,
2742 widget = gtk_printer_option_widget_new (NULL);
2743 priv->billing_info = GTK_PRINTER_OPTION_WIDGET (widget);
2744 gtk_widget_show (widget);
2745 gtk_table_attach (GTK_TABLE (table), widget,
2746 1, 2, 1, 2, GTK_FILL, 0,
2748 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2750 table = gtk_table_new (2, 2, FALSE);
2751 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2752 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2753 frame = wrap_in_frame (_("Print Document"), table);
2754 gtk_table_attach (GTK_TABLE (main_table), frame,
2755 0, 1, 1, 2, GTK_FILL, 0,
2757 gtk_widget_show (table);
2759 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Now"));
2760 priv->print_now_radio = radio;
2761 gtk_widget_show (radio);
2762 gtk_table_attach (GTK_TABLE (table), radio,
2763 0, 2, 0, 1, GTK_FILL, 0,
2765 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2767 priv->print_at_radio = radio;
2768 gtk_widget_show (radio);
2769 gtk_table_attach (GTK_TABLE (table), radio,
2770 0, 1, 1, 2, GTK_FILL, 0,
2773 entry = gtk_entry_new ();
2774 priv->print_at_entry = entry;
2775 gtk_widget_show (entry);
2776 gtk_table_attach (GTK_TABLE (table), entry,
2777 1, 2, 1, 2, GTK_FILL, 0,
2780 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2782 priv->print_hold_radio = radio;
2783 gtk_widget_show (radio);
2784 gtk_table_attach (GTK_TABLE (table), radio,
2785 0, 2, 2, 3, GTK_FILL, 0,
2788 g_signal_connect_swapped (priv->print_now_radio, "toggled",
2789 G_CALLBACK (update_print_at_option), dialog);
2790 g_signal_connect_swapped (priv->print_at_radio, "toggled",
2791 G_CALLBACK (update_print_at_option), dialog);
2792 g_signal_connect_swapped (priv->print_at_entry, "changed",
2793 G_CALLBACK (update_print_at_option), dialog);
2794 g_signal_connect_swapped (priv->print_hold_radio, "toggled",
2795 G_CALLBACK (update_print_at_option), dialog);
2797 table = gtk_table_new (2, 2, FALSE);
2798 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2799 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2800 frame = wrap_in_frame (_("Add Cover Page"), table);
2801 gtk_table_attach (GTK_TABLE (main_table), frame,
2802 1, 2, 0, 1, GTK_FILL, 0,
2804 gtk_widget_show (table);
2806 label = gtk_label_new_with_mnemonic (_("Be_fore:"));
2807 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2808 gtk_widget_show (label);
2809 gtk_table_attach (GTK_TABLE (table), label,
2810 0, 1, 0, 1, GTK_FILL, 0,
2813 widget = gtk_printer_option_widget_new (NULL);
2814 priv->cover_before = GTK_PRINTER_OPTION_WIDGET (widget);
2815 gtk_widget_show (widget);
2816 gtk_table_attach (GTK_TABLE (table), widget,
2817 1, 2, 0, 1, GTK_FILL, 0,
2819 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2821 label = gtk_label_new_with_mnemonic (_("_After:"));
2822 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2823 gtk_widget_show (label);
2824 gtk_table_attach (GTK_TABLE (table), label,
2825 0, 1, 1, 2, GTK_FILL, 0,
2828 widget = gtk_printer_option_widget_new (NULL);
2829 priv->cover_after = GTK_PRINTER_OPTION_WIDGET (widget);
2830 gtk_widget_show (widget);
2831 gtk_table_attach (GTK_TABLE (table), widget,
2832 1, 2, 1, 2, GTK_FILL, 0,
2834 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2836 label = gtk_label_new (_("Job"));
2837 gtk_widget_show (label);
2839 priv->job_page = main_table;
2840 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2845 create_optional_page (GtkPrintUnixDialog *dialog,
2847 GtkWidget **table_out,
2848 GtkWidget **page_out)
2850 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2851 GtkWidget *table, *label, *scrolled;
2853 scrolled = gtk_scrolled_window_new (NULL, NULL);
2854 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2856 GTK_POLICY_AUTOMATIC);
2858 table = gtk_table_new (1, 2, FALSE);
2859 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2860 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2861 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
2862 gtk_widget_show (table);
2864 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
2866 gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN(scrolled)->child),
2869 label = gtk_label_new (text);
2870 gtk_widget_show (label);
2872 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2876 *page_out = scrolled;
2880 create_advanced_page (GtkPrintUnixDialog *dialog)
2882 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2883 GtkWidget *main_vbox, *label, *scrolled;
2885 scrolled = gtk_scrolled_window_new (NULL, NULL);
2886 priv->advanced_page = scrolled;
2887 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2889 GTK_POLICY_AUTOMATIC);
2891 main_vbox = gtk_vbox_new (FALSE, 18);
2892 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2893 gtk_widget_show (main_vbox);
2895 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
2897 gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN(scrolled)->child),
2900 priv->advanced_vbox = main_vbox;
2902 label = gtk_label_new (_("Advanced"));
2903 gtk_widget_show (label);
2905 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2911 populate_dialog (GtkPrintUnixDialog *print_dialog)
2913 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
2914 GtkDialog *dialog = GTK_DIALOG (print_dialog);
2915 GtkWidget *vbox, *conflict_hbox, *image, *label;
2917 gtk_dialog_set_has_separator (dialog, FALSE);
2918 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
2919 gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
2920 gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
2921 gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
2923 vbox = gtk_vbox_new (FALSE, 6);
2924 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
2925 gtk_box_pack_start (GTK_BOX (dialog->vbox), vbox, TRUE, TRUE, 0);
2926 gtk_widget_show (vbox);
2928 priv->notebook = gtk_notebook_new ();
2929 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
2930 gtk_widget_show (priv->notebook);
2932 create_printer_list_model (print_dialog);
2934 create_main_page (print_dialog);
2935 create_page_setup_page (print_dialog);
2936 create_job_page (print_dialog);
2937 create_optional_page (print_dialog, _("Image Quality"),
2938 &priv->image_quality_table,
2939 &priv->image_quality_page);
2940 create_optional_page (print_dialog, _("Color"),
2943 create_optional_page (print_dialog, _("Finishing"),
2944 &priv->finishing_table,
2945 &priv->finishing_page);
2946 create_advanced_page (print_dialog);
2948 priv->conflicts_widget = conflict_hbox = gtk_hbox_new (FALSE, 12);
2949 gtk_box_pack_end (GTK_BOX (vbox), conflict_hbox, FALSE, FALSE, 0);
2950 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
2951 gtk_widget_show (image);
2952 gtk_box_pack_start (GTK_BOX (conflict_hbox), image, FALSE, TRUE, 0);
2953 label = gtk_label_new (_("Some of the settings in the dialog conflict"));
2954 gtk_widget_show (label);
2955 gtk_box_pack_start (GTK_BOX (conflict_hbox), label, FALSE, TRUE, 0);
2957 load_print_backends (print_dialog);
2961 * gtk_print_unix_dialog_new:
2962 * @title: Title of the dialog, or %NULL
2963 * @parent: Transient parent of the dialog, or %NULL
2965 * Creates a new #GtkPrintUnixDialog.
2967 * Return value: a new #GtkPrintUnixDialog
2972 gtk_print_unix_dialog_new (const gchar *title,
2976 const gchar *_title = _("Print");
2981 result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
2982 "transient-for", parent,
2984 "has-separator", FALSE,
2991 * gtk_print_unix_dialog_get_selected_printer:
2992 * @dialog: a #GtkPrintUnixDialog
2994 * Gets the currently selected printer.
2996 * Returns: the currently selected printer
3001 gtk_print_unix_dialog_get_selected_printer (GtkPrintUnixDialog *dialog)
3003 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3005 return dialog->priv->current_printer;
3009 * gtk_print_unix_dialog_set_page_setup:
3010 * @dialog: a #GtkPrintUnixDialog
3011 * @page_setup: a #GtkPageSetup
3013 * Sets the page setup of the #GtkPrintUnixDialog.
3018 gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
3019 GtkPageSetup *page_setup)
3021 GtkPrintUnixDialogPrivate *priv;
3023 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3024 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
3026 priv = dialog->priv;
3028 if (priv->page_setup != page_setup)
3030 g_object_unref (priv->page_setup);
3031 priv->page_setup = g_object_ref (page_setup);
3033 priv->page_setup_set = TRUE;
3035 g_object_notify (G_OBJECT (dialog), "page-setup");
3040 * gtk_print_unix_dialog_get_page_setup:
3041 * @dialog: a #GtkPrintUnixDialog
3043 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3045 * Returns: the page setup of @dialog.
3050 gtk_print_unix_dialog_get_page_setup (GtkPrintUnixDialog *dialog)
3052 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3054 return dialog->priv->page_setup;
3058 * gtk_print_unix_dialog_set_current_page:
3059 * @dialog: a #GtkPrintUnixDialog
3060 * @current_page: the current page number.
3062 * Sets the current page number. If @current_page is not -1, this enables
3063 * the current page choice for the range of pages to print.
3068 gtk_print_unix_dialog_set_current_page (GtkPrintUnixDialog *dialog,
3071 GtkPrintUnixDialogPrivate *priv;
3073 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3075 priv = dialog->priv;
3077 if (priv->current_page != current_page)
3079 priv->current_page = current_page;
3081 if (priv->current_page_radio)
3082 gtk_widget_set_sensitive (priv->current_page_radio, current_page != -1);
3084 g_object_notify (G_OBJECT (dialog), "current-page");
3089 * gtk_print_unix_dialog_get_current_page:
3090 * @dialog: a #GtkPrintUnixDialog
3092 * Gets the current page of the #GtkPrintDialog.
3094 * Returns: the current page of @dialog
3099 gtk_print_unix_dialog_get_current_page (GtkPrintUnixDialog *dialog)
3101 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), -1);
3103 return dialog->priv->current_page;
3107 set_active_printer (GtkPrintUnixDialog *dialog,
3108 const gchar *printer_name)
3110 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3111 GtkTreeModel *model;
3112 GtkTreeIter iter, filter_iter;
3113 GtkTreeSelection *selection;
3114 GtkPrinter *printer;
3116 model = GTK_TREE_MODEL (priv->printer_list);
3118 if (gtk_tree_model_get_iter_first (model, &iter))
3122 gtk_tree_model_get (GTK_TREE_MODEL (priv->printer_list), &iter,
3123 PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
3124 if (printer == NULL)
3127 if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
3129 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
3130 &filter_iter, &iter);
3132 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
3133 priv->internal_printer_change = TRUE;
3134 gtk_tree_selection_select_iter (selection, &filter_iter);
3135 priv->internal_printer_change = FALSE;
3136 g_free (priv->waiting_for_printer);
3137 priv->waiting_for_printer = NULL;
3139 g_object_unref (printer);
3143 g_object_unref (printer);
3145 } while (gtk_tree_model_iter_next (model, &iter));
3152 * gtk_print_unix_dialog_set_settings:
3153 * @dialog: a #GtkPrintUnixDialog
3154 * @settings: a #GtkPrintSettings, or %NULL
3156 * Sets the #GtkPrintSettings for the #GtkPrintUnixDialog. Typically,
3157 * this is used to restore saved print settings from a previous print
3158 * operation before the print dialog is shown.
3163 gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
3164 GtkPrintSettings *settings)
3166 GtkPrintUnixDialogPrivate *priv;
3167 const gchar *printer;
3168 GtkPageRange *ranges;
3171 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3172 g_return_if_fail (settings == NULL || GTK_IS_PRINT_SETTINGS (settings));
3174 priv = dialog->priv;
3176 if (settings != NULL)
3178 dialog_set_collate (dialog, gtk_print_settings_get_collate (settings));
3179 dialog_set_reverse (dialog, gtk_print_settings_get_reverse (settings));
3180 dialog_set_n_copies (dialog, gtk_print_settings_get_n_copies (settings));
3181 dialog_set_scale (dialog, gtk_print_settings_get_scale (settings));
3182 dialog_set_page_set (dialog, gtk_print_settings_get_page_set (settings));
3183 dialog_set_print_pages (dialog, gtk_print_settings_get_print_pages (settings));
3184 ranges = gtk_print_settings_get_page_ranges (settings, &num_ranges);
3187 dialog_set_page_ranges (dialog, ranges, num_ranges);
3191 priv->format_for_printer =
3192 g_strdup (gtk_print_settings_get (settings, "format-for-printer"));
3195 if (priv->initial_settings)
3196 g_object_unref (priv->initial_settings);
3198 priv->initial_settings = settings;
3200 g_free (priv->waiting_for_printer);
3201 priv->waiting_for_printer = NULL;
3205 g_object_ref (settings);
3207 printer = gtk_print_settings_get_printer (settings);
3209 if (printer && !set_active_printer (dialog, printer))
3210 priv->waiting_for_printer = g_strdup (printer);
3213 g_object_notify (G_OBJECT (dialog), "print-settings");
3217 * gtk_print_unix_dialog_get_settings:
3218 * @dialog: a #GtkPrintUnixDialog
3220 * Gets a new #GtkPrintSettings object that represents the
3221 * current values in the print dialog. Note that this creates a
3222 * <emphasis>new object</emphasis>, and you need to unref it
3223 * if don't want to keep it.
3225 * Returns: a new #GtkPrintSettings object with the values from @dialog
3230 gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
3232 GtkPrintUnixDialogPrivate *priv;
3233 GtkPrintSettings *settings;
3234 GtkPrintPages print_pages;
3235 GtkPageRange *ranges;
3238 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3240 priv = dialog->priv;
3241 settings = gtk_print_settings_new ();
3243 if (priv->current_printer)
3244 gtk_print_settings_set_printer (settings,
3245 gtk_printer_get_name (priv->current_printer));
3247 gtk_print_settings_set_printer (settings, "default");
3249 gtk_print_settings_set (settings, "format-for-printer",
3250 priv->format_for_printer);
3253 gtk_print_settings_set_collate (settings,
3254 dialog_get_collate (dialog));
3256 gtk_print_settings_set_reverse (settings,
3257 dialog_get_reverse (dialog));
3259 gtk_print_settings_set_n_copies (settings,
3260 dialog_get_n_copies (dialog));
3262 gtk_print_settings_set_scale (settings,
3263 dialog_get_scale (dialog));
3265 gtk_print_settings_set_page_set (settings,
3266 dialog_get_page_set (dialog));
3268 print_pages = dialog_get_print_pages (dialog);
3269 gtk_print_settings_set_print_pages (settings, print_pages);
3271 ranges = dialog_get_page_ranges (dialog, &n_ranges);
3274 gtk_print_settings_set_page_ranges (settings, ranges, n_ranges);
3278 /* TODO: print when. How to handle? */
3280 if (priv->current_printer)
3281 _gtk_printer_get_settings_from_options (priv->current_printer,
3289 * gtk_print_unix_dialog_add_custom_tab:
3290 * @dialog: a #GtkPrintUnixDialog
3291 * @child: the widget to put in the custom tab
3292 * @tab_label: the widget to use as tab label
3294 * Adds a custom tab to the print dialog.
3299 gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
3301 GtkWidget *tab_label)
3303 gtk_notebook_insert_page (GTK_NOTEBOOK (dialog->priv->notebook),
3304 child, tab_label, 2);
3305 gtk_widget_show (child);
3306 gtk_widget_show (tab_label);
3310 * gtk_print_unix_dialog_set_manual_capabilities:
3311 * @dialog: a #GtkPrintUnixDialog
3312 * @capabilities: the printing capabilities of your application
3314 * This lets you specify the printing capabilities your application
3315 * supports. For instance, if you can handle scaling the output then
3316 * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then
3317 * the dialog will only let you select the scale if the printing
3318 * system automatically handles scaling.
3323 gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog,
3324 GtkPrintCapabilities capabilities)
3326 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3328 priv->manual_capabilities = capabilities;
3329 update_dialog_from_capabilities (dialog);
3331 if (priv->current_printer)
3333 GtkTreeSelection *selection;
3335 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
3337 g_object_unref (priv->current_printer);
3338 priv->current_printer = NULL;
3339 priv->internal_printer_change = TRUE;
3340 selected_printer_changed (selection, dialog);
3341 priv->internal_printer_change = FALSE;
3345 #define __GTK_PRINT_UNIX_DIALOG_C__
3346 #include "gtkaliasdef.c"