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
122 PRINTER_LIST_COL_ICON,
123 PRINTER_LIST_COL_NAME,
124 PRINTER_LIST_COL_STATE,
125 PRINTER_LIST_COL_JOBS,
126 PRINTER_LIST_COL_LOCATION,
127 PRINTER_LIST_COL_PRINTER_OBJ,
131 struct GtkPrintUnixDialogPrivate
135 GtkWidget *printer_treeview;
137 GtkPrintCapabilities manual_capabilities;
138 GtkPrintCapabilities printer_capabilities;
140 GtkTreeModel *printer_list;
141 GtkTreeModelFilter *printer_list_filter;
143 GtkPageSetup *page_setup;
144 gboolean page_setup_set;
146 GtkWidget *all_pages_radio;
147 GtkWidget *current_page_radio;
148 GtkWidget *page_range_radio;
149 GtkWidget *page_range_entry;
151 GtkWidget *copies_spin;
152 GtkWidget *collate_check;
153 GtkWidget *reverse_check;
154 GtkWidget *collate_image;
155 GtkWidget *page_layout_preview;
156 GtkWidget *scale_spin;
157 GtkWidget *page_set_combo;
158 GtkWidget *print_now_radio;
159 GtkWidget *print_at_radio;
160 GtkWidget *print_at_entry;
161 GtkWidget *print_hold_radio;
162 GtkWidget *preview_button;
163 gboolean updating_print_at;
164 GtkPrinterOptionWidget *pages_per_sheet;
165 GtkPrinterOptionWidget *duplex;
166 GtkPrinterOptionWidget *paper_type;
167 GtkPrinterOptionWidget *paper_source;
168 GtkPrinterOptionWidget *output_tray;
169 GtkPrinterOptionWidget *job_prio;
170 GtkPrinterOptionWidget *billing_info;
171 GtkPrinterOptionWidget *cover_before;
172 GtkPrinterOptionWidget *cover_after;
173 GtkPrinterOptionWidget *number_up_layout;
175 GtkWidget *conflicts_widget;
178 GtkWidget *finishing_table;
179 GtkWidget *finishing_page;
180 GtkWidget *image_quality_table;
181 GtkWidget *image_quality_page;
182 GtkWidget *color_table;
183 GtkWidget *color_page;
185 GtkWidget *advanced_vbox;
186 GtkWidget *advanced_page;
188 GtkWidget *extension_point;
190 /* These are set initially on selected printer (either default printer,
191 * printer taken from set settings, or user-selected), but when any setting
192 * is changed by the user it is cleared.
194 GtkPrintSettings *initial_settings;
196 GtkPrinterOption *number_up_layout_n_option;
197 GtkPrinterOption *number_up_layout_2_option;
199 /* This is the initial printer set by set_settings. We look for it in the
200 * added printers. We clear this whenever the user manually changes
201 * to another printer, when the user changes a setting or when we find
204 char *waiting_for_printer;
205 gboolean internal_printer_change;
207 GList *print_backends;
209 GtkPrinter *current_printer;
210 GtkPrinter *request_details_printer;
211 guint request_details_tag;
212 GtkPrinterOptionSet *options;
213 gulong options_changed_handler;
214 gulong mark_conflicts_id;
216 gchar *format_for_printer;
221 G_DEFINE_TYPE_WITH_CODE (GtkPrintUnixDialog, gtk_print_unix_dialog, GTK_TYPE_DIALOG,
222 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
223 gtk_print_unix_dialog_buildable_init))
225 static GtkBuildableIface *parent_buildable_iface;
228 is_default_printer (GtkPrintUnixDialog *dialog,
231 GtkPrintUnixDialogPrivate *priv = dialog->priv;
233 if (priv->format_for_printer)
234 return strcmp (priv->format_for_printer,
235 gtk_printer_get_name (printer)) == 0;
237 return gtk_printer_is_default (printer);
241 gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
243 GObjectClass *object_class;
244 GtkWidgetClass *widget_class;
246 object_class = (GObjectClass *) class;
247 widget_class = (GtkWidgetClass *) class;
249 object_class->finalize = gtk_print_unix_dialog_finalize;
250 object_class->set_property = gtk_print_unix_dialog_set_property;
251 object_class->get_property = gtk_print_unix_dialog_get_property;
253 widget_class->style_set = gtk_print_unix_dialog_style_set;
255 g_object_class_install_property (object_class,
257 g_param_spec_object ("page-setup",
259 P_("The GtkPageSetup to use"),
261 GTK_PARAM_READWRITE));
263 g_object_class_install_property (object_class,
265 g_param_spec_int ("current-page",
267 P_("The current page in the document"),
271 GTK_PARAM_READWRITE));
273 g_object_class_install_property (object_class,
275 g_param_spec_object ("print-settings",
276 P_("Print Settings"),
277 P_("The GtkPrintSettings used for initializing the dialog"),
278 GTK_TYPE_PRINT_SETTINGS,
279 GTK_PARAM_READWRITE));
281 g_object_class_install_property (object_class,
282 PROP_SELECTED_PRINTER,
283 g_param_spec_object ("selected-printer",
284 P_("Selected Printer"),
285 P_("The GtkPrinter which is selected"),
287 GTK_PARAM_READABLE));
290 g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));
293 /* Returns a toplevel GtkWindow, or NULL if none */
295 get_toplevel (GtkWidget *widget)
297 GtkWidget *toplevel = NULL;
299 toplevel = gtk_widget_get_toplevel (widget);
300 if (!GTK_WIDGET_TOPLEVEL (toplevel))
303 return GTK_WINDOW (toplevel);
307 add_custom_button_to_dialog (GtkDialog *dialog,
308 const gchar *mnemonic_label,
309 const gchar *stock_id,
312 GtkWidget *button = NULL;
314 button = gtk_button_new_with_mnemonic (mnemonic_label);
315 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
316 gtk_button_set_image (GTK_BUTTON (button),
317 gtk_image_new_from_stock (stock_id,
318 GTK_ICON_SIZE_BUTTON));
319 gtk_widget_show (button);
321 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
324 /* This function handles error messages before printing.
327 error_dialogs (GtkPrintUnixDialog *print_dialog,
328 gint print_dialog_response_id,
331 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
332 GtkPrinterOption *option = NULL;
333 GtkPrinter *printer = NULL;
334 GtkWindow *toplevel = NULL;
335 GtkWidget *dialog = NULL;
337 gchar *basename = NULL;
338 gchar *dirname = NULL;
341 if (print_dialog != NULL && print_dialog_response_id == GTK_RESPONSE_OK)
343 printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
345 /* Shows overwrite confirmation dialog in the case of printing to file which
347 if (printer != NULL && gtk_printer_is_virtual (printer))
349 option = gtk_printer_option_set_lookup (priv->options,
350 "gtk-main-page-custom-input");
352 if (option != NULL &&
353 option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE)
355 file = g_file_new_for_uri (option->value);
358 g_file_query_exists (file, NULL))
360 toplevel = get_toplevel (GTK_WIDGET (print_dialog));
362 basename = g_file_get_basename (file);
363 dirname = g_file_get_parse_name (g_file_get_parent (file));
365 dialog = gtk_message_dialog_new (toplevel,
367 GTK_DIALOG_DESTROY_WITH_PARENT,
368 GTK_MESSAGE_QUESTION,
370 _("A file named \"%s\" already exists. Do you want to replace it?"),
373 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
374 _("The file already exists in \"%s\". Replacing it will "
375 "overwrite its contents."),
378 gtk_dialog_add_button (GTK_DIALOG (dialog),
379 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
380 add_custom_button_to_dialog (GTK_DIALOG (dialog),
383 GTK_RESPONSE_ACCEPT);
384 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
388 gtk_dialog_set_default_response (GTK_DIALOG (dialog),
389 GTK_RESPONSE_ACCEPT);
392 gtk_window_group_add_window (toplevel->group,
393 GTK_WINDOW (dialog));
395 response = gtk_dialog_run (GTK_DIALOG (dialog));
397 gtk_widget_destroy (dialog);
402 if (response != GTK_RESPONSE_ACCEPT)
404 g_signal_stop_emission_by_name (print_dialog, "response");
405 g_object_unref (file);
410 g_object_unref (file);
418 gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
420 GtkPrintUnixDialogPrivate *priv = dialog->priv;
422 priv = dialog->priv = GTK_PRINT_UNIX_DIALOG_GET_PRIVATE (dialog);
423 priv->print_backends = NULL;
424 priv->current_page = -1;
425 priv->number_up_layout_n_option = NULL;
426 priv->number_up_layout_2_option = NULL;
428 priv->page_setup = gtk_page_setup_new ();
429 priv->page_setup_set = FALSE;
431 g_signal_connect (dialog,
433 (GCallback) gtk_print_unix_dialog_destroy,
436 g_signal_connect (dialog,
438 (GCallback) error_dialogs,
441 priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
442 gtk_widget_show (priv->preview_button);
444 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
445 priv->preview_button,
447 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
448 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
449 GTK_STOCK_PRINT, GTK_RESPONSE_OK,
451 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
457 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
458 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
460 populate_dialog (dialog);
464 gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
466 /* Make sure we don't destroy custom widgets owned by the backends */
467 clear_per_printer_ui (dialog);
471 disconnect_printer_details_request (GtkPrintUnixDialog *dialog)
473 GtkPrintUnixDialogPrivate *priv = dialog->priv;
475 if (priv->request_details_tag)
477 g_signal_handler_disconnect (priv->request_details_printer,
478 priv->request_details_tag);
479 priv->request_details_tag = 0;
480 g_object_unref (priv->request_details_printer);
481 priv->request_details_printer = NULL;
486 gtk_print_unix_dialog_finalize (GObject *object)
488 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
489 GtkPrintUnixDialogPrivate *priv = dialog->priv;
490 GtkPrintBackend *backend;
493 unschedule_idle_mark_conflicts (dialog);
494 disconnect_printer_details_request (dialog);
496 if (priv->current_printer)
498 g_object_unref (priv->current_printer);
499 priv->current_printer = NULL;
502 if (priv->printer_list)
504 g_object_unref (priv->printer_list);
505 priv->printer_list = NULL;
508 if (priv->printer_list_filter)
510 g_object_unref (priv->printer_list_filter);
511 priv->printer_list_filter = NULL;
517 g_object_unref (priv->options);
518 priv->options = NULL;
521 if (priv->number_up_layout_2_option)
523 priv->number_up_layout_2_option->choices[0] = NULL;
524 priv->number_up_layout_2_option->choices[1] = NULL;
525 g_free (priv->number_up_layout_2_option->choices_display[0]);
526 g_free (priv->number_up_layout_2_option->choices_display[1]);
527 priv->number_up_layout_2_option->choices_display[0] = NULL;
528 priv->number_up_layout_2_option->choices_display[1] = NULL;
529 g_object_unref (priv->number_up_layout_2_option);
530 priv->number_up_layout_2_option = NULL;
533 if (priv->number_up_layout_n_option)
535 g_object_unref (priv->number_up_layout_n_option);
536 priv->number_up_layout_n_option = NULL;
539 if (priv->page_setup)
541 g_object_unref (priv->page_setup);
542 priv->page_setup = NULL;
545 if (priv->initial_settings)
547 g_object_unref (priv->initial_settings);
548 priv->initial_settings = NULL;
551 g_free (priv->waiting_for_printer);
552 priv->waiting_for_printer = NULL;
554 g_free (priv->format_for_printer);
555 priv->format_for_printer = NULL;
557 for (node = priv->print_backends; node != NULL; node = node->next)
559 backend = GTK_PRINT_BACKEND (node->data);
561 g_signal_handlers_disconnect_by_func (backend, printer_added_cb, dialog);
562 g_signal_handlers_disconnect_by_func (backend, printer_removed_cb, dialog);
563 g_signal_handlers_disconnect_by_func (backend, printer_status_cb, dialog);
565 gtk_print_backend_destroy (backend);
566 g_object_unref (backend);
569 g_list_free (priv->print_backends);
570 priv->print_backends = NULL;
572 G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->finalize (object);
576 printer_removed_cb (GtkPrintBackend *backend,
578 GtkPrintUnixDialog *dialog)
580 GtkPrintUnixDialogPrivate *priv = dialog->priv;
583 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
584 gtk_list_store_remove (GTK_LIST_STORE (priv->printer_list), iter);
588 gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface)
590 parent_buildable_iface = g_type_interface_peek_parent (iface);
592 iface->get_internal_child = gtk_print_unix_dialog_buildable_get_internal_child;
596 gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
598 const gchar *childname)
600 if (strcmp (childname, "notebook") == 0)
601 return G_OBJECT (GTK_PRINT_UNIX_DIALOG (buildable)->priv->notebook);
603 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
606 /* This function controls "sensitive" property of GtkCellRenderer based on pause
607 * state of printers. */
608 void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
609 GtkCellRenderer *cell,
610 GtkTreeModel *tree_model,
616 gtk_tree_model_get (tree_model, iter, PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
618 if (printer != NULL && !gtk_printer_is_accepting_jobs (printer))
629 printer_status_cb (GtkPrintBackend *backend,
631 GtkPrintUnixDialog *dialog)
633 GtkPrintUnixDialogPrivate *priv = dialog->priv;
635 GtkTreeSelection *selection;
637 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
639 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), iter,
640 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
641 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
642 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
643 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
646 /* When the pause state change then we need to update sensitive property
647 * of GTK_RESPONSE_OK button inside of selected_printer_changed function. */
648 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
649 selected_printer_changed (selection, dialog);
651 if (gtk_print_backend_printer_list_is_done (backend) &&
652 gtk_printer_is_default (printer) &&
653 (gtk_tree_selection_count_selected_rows (selection) == 0))
654 set_active_printer (dialog, gtk_printer_get_name (printer));
658 printer_added_cb (GtkPrintBackend *backend,
660 GtkPrintUnixDialog *dialog)
662 GtkPrintUnixDialogPrivate *priv = dialog->priv;
663 GtkTreeIter iter, filter_iter;
664 GtkTreeSelection *selection;
667 gtk_list_store_append (GTK_LIST_STORE (priv->printer_list), &iter);
669 g_object_set_data_full (G_OBJECT (printer),
670 "gtk-print-tree-iter",
671 gtk_tree_iter_copy (&iter),
672 (GDestroyNotify) gtk_tree_iter_free);
674 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), &iter,
675 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
676 PRINTER_LIST_COL_NAME, gtk_printer_get_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),
680 PRINTER_LIST_COL_PRINTER_OBJ, printer,
683 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
684 &filter_iter, &iter);
685 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->printer_list_filter), &filter_iter);
687 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
689 if (priv->waiting_for_printer != NULL &&
690 strcmp (gtk_printer_get_name (printer),
691 priv->waiting_for_printer) == 0)
693 priv->internal_printer_change = TRUE;
694 gtk_tree_selection_select_iter (selection, &filter_iter);
695 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
696 path, NULL, TRUE, 0.5, 0.0);
697 priv->internal_printer_change = FALSE;
698 g_free (priv->waiting_for_printer);
699 priv->waiting_for_printer = NULL;
701 else if (is_default_printer (dialog, printer) &&
702 gtk_tree_selection_count_selected_rows (selection) == 0)
704 priv->internal_printer_change = TRUE;
705 gtk_tree_selection_select_iter (selection, &filter_iter);
706 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
707 path, NULL, TRUE, 0.5, 0.0);
708 priv->internal_printer_change = FALSE;
711 gtk_tree_path_free (path);
715 printer_list_initialize (GtkPrintUnixDialog *dialog,
716 GtkPrintBackend *print_backend)
721 g_return_if_fail (print_backend != NULL);
723 g_signal_connect_object (print_backend,
725 (GCallback) printer_added_cb,
726 G_OBJECT (dialog), 0);
728 g_signal_connect_object (print_backend,
730 (GCallback) printer_removed_cb,
731 G_OBJECT (dialog), 0);
733 g_signal_connect_object (print_backend,
734 "printer-status-changed",
735 (GCallback) printer_status_cb,
736 G_OBJECT (dialog), 0);
738 list = gtk_print_backend_get_printer_list (print_backend);
743 printer_added_cb (print_backend, node->data, dialog);
751 load_print_backends (GtkPrintUnixDialog *dialog)
753 GtkPrintUnixDialogPrivate *priv = dialog->priv;
756 if (g_module_supported ())
757 priv->print_backends = gtk_print_backend_load_modules ();
759 for (node = priv->print_backends; node != NULL; node = node->next)
760 printer_list_initialize (dialog, GTK_PRINT_BACKEND (node->data));
764 gtk_print_unix_dialog_set_property (GObject *object,
770 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
774 case PROP_PAGE_SETUP:
775 gtk_print_unix_dialog_set_page_setup (dialog, g_value_get_object (value));
777 case PROP_CURRENT_PAGE:
778 gtk_print_unix_dialog_set_current_page (dialog, g_value_get_int (value));
780 case PROP_PRINT_SETTINGS:
781 gtk_print_unix_dialog_set_settings (dialog, g_value_get_object (value));
784 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
790 gtk_print_unix_dialog_get_property (GObject *object,
795 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
796 GtkPrintUnixDialogPrivate *priv = dialog->priv;
800 case PROP_PAGE_SETUP:
801 g_value_set_object (value, priv->page_setup);
803 case PROP_CURRENT_PAGE:
804 g_value_set_int (value, priv->current_page);
806 case PROP_PRINT_SETTINGS:
807 g_value_take_object (value, gtk_print_unix_dialog_get_settings (dialog));
809 case PROP_SELECTED_PRINTER:
810 g_value_set_object (value, priv->current_printer);
813 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
819 is_printer_active (GtkTreeModel *model,
821 GtkPrintUnixDialog *dialog)
825 GtkPrintUnixDialogPrivate *priv = dialog->priv;
827 gtk_tree_model_get (model,
829 PRINTER_LIST_COL_PRINTER_OBJ,
836 result = gtk_printer_is_active (printer);
839 priv->manual_capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF |
840 GTK_PRINT_CAPABILITY_GENERATE_PS))
842 /* Check that the printer can handle at least one of the data
843 * formats that the application supports.
845 result = ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF) &&
846 gtk_printer_accepts_pdf (printer)) ||
847 ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS) &&
848 gtk_printer_accepts_ps (printer));
851 g_object_unref (printer);
857 default_printer_list_sort_func (GtkTreeModel *model,
864 GtkPrinter *a_printer;
865 GtkPrinter *b_printer;
868 gtk_tree_model_get (model, a,
869 PRINTER_LIST_COL_NAME, &a_name,
870 PRINTER_LIST_COL_PRINTER_OBJ, &a_printer,
872 gtk_tree_model_get (model, b,
873 PRINTER_LIST_COL_NAME, &b_name,
874 PRINTER_LIST_COL_PRINTER_OBJ, &b_printer,
877 if (a_printer == NULL && b_printer == NULL)
879 else if (a_printer == NULL)
881 else if (b_printer == NULL)
883 else if (gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
885 else if (gtk_printer_is_virtual (a_printer) && !gtk_printer_is_virtual (b_printer))
887 else if (!gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
889 else if (a_name == NULL && b_name == NULL)
891 else if (a_name == NULL && b_name != NULL)
893 else if (a_name != NULL && b_name == NULL)
896 result = g_ascii_strcasecmp (a_name, b_name);
900 g_object_unref (a_printer);
901 g_object_unref (b_printer);
908 create_printer_list_model (GtkPrintUnixDialog *dialog)
910 GtkPrintUnixDialogPrivate *priv = dialog->priv;
912 GtkTreeSortable *sort;
914 model = gtk_list_store_new (PRINTER_LIST_N_COLS,
922 priv->printer_list = (GtkTreeModel *)model;
923 priv->printer_list_filter = (GtkTreeModelFilter *) gtk_tree_model_filter_new ((GtkTreeModel *)model,
926 gtk_tree_model_filter_set_visible_func (priv->printer_list_filter,
927 (GtkTreeModelFilterVisibleFunc) is_printer_active,
931 sort = GTK_TREE_SORTABLE (model);
932 gtk_tree_sortable_set_default_sort_func (sort,
933 default_printer_list_sort_func,
937 gtk_tree_sortable_set_sort_column_id (sort,
938 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
945 wrap_in_frame (const gchar *label,
948 GtkWidget *frame, *alignment, *label_widget;
951 label_widget = gtk_label_new (NULL);
952 gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
953 gtk_widget_show (label_widget);
955 bold_text = g_markup_printf_escaped ("<b>%s</b>", label);
956 gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
959 frame = gtk_vbox_new (FALSE, 6);
960 gtk_box_pack_start (GTK_BOX (frame), label_widget, FALSE, FALSE, 0);
962 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
963 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
965 gtk_box_pack_start (GTK_BOX (frame), alignment, FALSE, FALSE, 0);
967 gtk_container_add (GTK_CONTAINER (alignment), child);
969 gtk_widget_show (frame);
970 gtk_widget_show (alignment);
976 setup_option (GtkPrintUnixDialog *dialog,
977 const gchar *option_name,
978 GtkPrinterOptionWidget *widget)
980 GtkPrintUnixDialogPrivate *priv = dialog->priv;
981 GtkPrinterOption *option;
983 option = gtk_printer_option_set_lookup (priv->options, option_name);
984 gtk_printer_option_widget_set_source (widget, option);
986 return option != NULL;
990 add_option_to_extension_point (GtkPrinterOption *option,
993 GtkWidget *extension_point = data;
996 widget = gtk_printer_option_widget_new (option);
997 gtk_widget_show (widget);
999 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1001 GtkWidget *label, *hbox;
1003 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1004 gtk_widget_show (label);
1005 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1006 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1008 hbox = gtk_hbox_new (FALSE, 12);
1009 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1010 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1011 gtk_widget_show (hbox);
1013 gtk_box_pack_start (GTK_BOX (extension_point), hbox, FALSE, FALSE, 0);
1016 gtk_box_pack_start (GTK_BOX (extension_point), widget, FALSE, FALSE, 0);
1020 add_option_to_table (GtkPrinterOption *option,
1024 GtkWidget *label, *widget;
1027 table = GTK_TABLE (user_data);
1029 if (g_str_has_prefix (option->name, "gtk-"))
1032 widget = gtk_printer_option_widget_new (option);
1033 gtk_widget_show (widget);
1036 gtk_table_resize (table, table->nrows + 1, 2);
1038 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1040 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1041 gtk_widget_show (label);
1043 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1044 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1046 gtk_table_attach (table, label,
1047 0, 1, row - 1 , row, GTK_FILL, 0, 0, 0);
1049 gtk_table_attach (table, widget,
1050 1, 2, row - 1, row, GTK_FILL, 0, 0, 0);
1053 gtk_table_attach (table, widget,
1054 0, 2, row - 1, row, GTK_FILL, 0, 0, 0);
1059 setup_page_table (GtkPrinterOptionSet *options,
1064 gtk_printer_option_set_foreach_in_group (options, group,
1065 add_option_to_table,
1067 if (GTK_TABLE (table)->nrows == 1)
1068 gtk_widget_hide (page);
1070 gtk_widget_show (page);
1074 update_print_at_option (GtkPrintUnixDialog *dialog)
1076 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1077 GtkPrinterOption *option;
1079 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1084 if (priv->updating_print_at)
1087 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_at_radio)))
1088 gtk_printer_option_set (option, "at");
1089 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio)))
1090 gtk_printer_option_set (option, "on-hold");
1092 gtk_printer_option_set (option, "now");
1094 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1097 const char *text = gtk_entry_get_text (GTK_ENTRY (priv->print_at_entry));
1098 gtk_printer_option_set (option,text);
1104 setup_print_at (GtkPrintUnixDialog *dialog)
1106 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1107 GtkPrinterOption *option;
1109 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1113 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1115 gtk_widget_set_sensitive (priv->print_at_radio, FALSE);
1116 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1117 gtk_widget_set_sensitive (priv->print_hold_radio, FALSE);
1118 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), "");
1122 priv->updating_print_at = TRUE;
1124 if (gtk_printer_option_has_choice (option, "at"))
1126 gtk_widget_set_sensitive (priv->print_at_radio, TRUE);
1127 gtk_widget_set_sensitive (priv->print_at_entry, TRUE);
1131 gtk_widget_set_sensitive (priv->print_at_radio, FALSE);
1132 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1135 gtk_widget_set_sensitive (priv->print_hold_radio,
1136 gtk_printer_option_has_choice (option, "on-hold"));
1138 update_print_at_option (dialog);
1140 if (strcmp (option->value, "at") == 0)
1141 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_at_radio),
1143 else if (strcmp (option->value, "on-hold") == 0)
1144 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio),
1147 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1150 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1152 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry),
1156 priv->updating_print_at = FALSE;
1162 update_dialog_from_settings (GtkPrintUnixDialog *dialog)
1164 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1167 GtkWidget *table, *frame;
1168 gboolean has_advanced, has_job;
1170 if (priv->current_printer == NULL)
1172 clear_per_printer_ui (dialog);
1173 gtk_widget_hide (priv->job_page);
1174 gtk_widget_hide (priv->advanced_page);
1175 gtk_widget_hide (priv->image_quality_page);
1176 gtk_widget_hide (priv->finishing_page);
1177 gtk_widget_hide (priv->color_page);
1178 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1183 setup_option (dialog, "gtk-n-up", priv->pages_per_sheet);
1184 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
1185 setup_option (dialog, "gtk-duplex", priv->duplex);
1186 setup_option (dialog, "gtk-paper-type", priv->paper_type);
1187 setup_option (dialog, "gtk-paper-source", priv->paper_source);
1188 setup_option (dialog, "gtk-output-tray", priv->output_tray);
1191 has_job |= setup_option (dialog, "gtk-job-prio", priv->job_prio);
1192 has_job |= setup_option (dialog, "gtk-billing-info", priv->billing_info);
1193 has_job |= setup_option (dialog, "gtk-cover-before", priv->cover_before);
1194 has_job |= setup_option (dialog, "gtk-cover-after", priv->cover_after);
1195 has_job |= setup_print_at (dialog);
1198 gtk_widget_show (priv->job_page);
1200 gtk_widget_hide (priv->job_page);
1203 setup_page_table (priv->options,
1205 priv->image_quality_table,
1206 priv->image_quality_page);
1208 setup_page_table (priv->options,
1210 priv->finishing_table,
1211 priv->finishing_page);
1213 setup_page_table (priv->options,
1218 gtk_printer_option_set_foreach_in_group (priv->options,
1219 "GtkPrintDialogExtension",
1220 add_option_to_extension_point,
1221 priv->extension_point);
1223 /* Put the rest of the groups in the advanced page */
1224 groups = gtk_printer_option_set_get_groups (priv->options);
1226 has_advanced = FALSE;
1227 for (l = groups; l != NULL; l = l->next)
1234 if (strcmp (group, "ImageQualityPage") == 0 ||
1235 strcmp (group, "ColorPage") == 0 ||
1236 strcmp (group, "FinishingPage") == 0 ||
1237 strcmp (group, "GtkPrintDialogExtension") == 0)
1240 table = gtk_table_new (1, 2, FALSE);
1241 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1242 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1244 gtk_printer_option_set_foreach_in_group (priv->options,
1246 add_option_to_table,
1248 if (GTK_TABLE (table)->nrows == 1)
1249 gtk_widget_destroy (table);
1252 has_advanced = TRUE;
1253 frame = wrap_in_frame (group, table);
1254 gtk_widget_show (table);
1255 gtk_widget_show (frame);
1257 gtk_box_pack_start (GTK_BOX (priv->advanced_vbox),
1258 frame, FALSE, FALSE, 0);
1263 gtk_widget_show (priv->advanced_page);
1265 gtk_widget_hide (priv->advanced_page);
1268 g_list_foreach (groups, (GFunc) g_free, NULL);
1269 g_list_free (groups);
1273 update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
1275 GtkPrintCapabilities caps;
1276 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1277 gboolean can_collate;
1278 const gchar *copies;
1280 copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin));
1281 can_collate = (*copies != '\0' && atoi (copies) > 1);
1283 caps = priv->manual_capabilities | priv->printer_capabilities;
1285 gtk_widget_set_sensitive (priv->page_set_combo,
1286 caps & GTK_PRINT_CAPABILITY_PAGE_SET);
1287 gtk_widget_set_sensitive (priv->copies_spin,
1288 caps & GTK_PRINT_CAPABILITY_COPIES);
1289 gtk_widget_set_sensitive (priv->collate_check,
1291 (caps & GTK_PRINT_CAPABILITY_COLLATE));
1292 gtk_widget_set_sensitive (priv->reverse_check,
1293 caps & GTK_PRINT_CAPABILITY_REVERSE);
1294 gtk_widget_set_sensitive (priv->scale_spin,
1295 caps & GTK_PRINT_CAPABILITY_SCALE);
1296 gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet),
1297 caps & GTK_PRINT_CAPABILITY_NUMBER_UP);
1299 if (caps & GTK_PRINT_CAPABILITY_PREVIEW)
1300 gtk_widget_show (priv->preview_button);
1302 gtk_widget_hide (priv->preview_button);
1304 update_collate_icon (NULL, dialog);
1306 gtk_tree_model_filter_refilter (priv->printer_list_filter);
1310 mark_conflicts (GtkPrintUnixDialog *dialog)
1312 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1313 GtkPrinter *printer;
1314 gboolean have_conflict;
1316 have_conflict = FALSE;
1318 printer = priv->current_printer;
1323 g_signal_handler_block (priv->options,
1324 priv->options_changed_handler);
1326 gtk_printer_option_set_clear_conflicts (priv->options);
1328 have_conflict = _gtk_printer_mark_conflicts (printer,
1331 g_signal_handler_unblock (priv->options,
1332 priv->options_changed_handler);
1336 gtk_widget_show (priv->conflicts_widget);
1338 gtk_widget_hide (priv->conflicts_widget);
1342 mark_conflicts_callback (gpointer data)
1344 GtkPrintUnixDialog *dialog = data;
1345 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1347 priv->mark_conflicts_id = 0;
1349 mark_conflicts (dialog);
1355 unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1357 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1359 if (priv->mark_conflicts_id != 0)
1361 g_source_remove (priv->mark_conflicts_id);
1362 priv->mark_conflicts_id = 0;
1367 schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1369 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1371 if (priv->mark_conflicts_id != 0)
1374 priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
1379 options_changed_cb (GtkPrintUnixDialog *dialog)
1381 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1383 schedule_idle_mark_conflicts (dialog);
1385 if (priv->initial_settings)
1387 g_object_unref (priv->initial_settings);
1388 priv->initial_settings = NULL;
1391 g_free (priv->waiting_for_printer);
1392 priv->waiting_for_printer = NULL;
1396 remove_custom_widget (GtkWidget *widget,
1397 GtkContainer *container)
1399 gtk_container_remove (container, widget);
1403 extension_point_clear_children (GtkContainer *container)
1405 gtk_container_foreach (container,
1406 (GtkCallback)remove_custom_widget,
1411 clear_per_printer_ui (GtkPrintUnixDialog *dialog)
1413 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1415 gtk_container_foreach (GTK_CONTAINER (priv->finishing_table),
1416 (GtkCallback)gtk_widget_destroy,
1418 gtk_table_resize (GTK_TABLE (priv->finishing_table), 1, 2);
1419 gtk_container_foreach (GTK_CONTAINER (priv->image_quality_table),
1420 (GtkCallback)gtk_widget_destroy,
1422 gtk_table_resize (GTK_TABLE (priv->image_quality_table), 1, 2);
1423 gtk_container_foreach (GTK_CONTAINER (priv->color_table),
1424 (GtkCallback)gtk_widget_destroy,
1426 gtk_table_resize (GTK_TABLE (priv->color_table), 1, 2);
1427 gtk_container_foreach (GTK_CONTAINER (priv->advanced_vbox),
1428 (GtkCallback)gtk_widget_destroy,
1430 extension_point_clear_children (GTK_CONTAINER (priv->extension_point));
1434 printer_details_acquired (GtkPrinter *printer,
1436 GtkPrintUnixDialog *dialog)
1438 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1440 disconnect_printer_details_request (dialog);
1444 GtkTreeSelection *selection;
1445 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
1447 selected_printer_changed (selection, dialog);
1452 selected_printer_changed (GtkTreeSelection *selection,
1453 GtkPrintUnixDialog *dialog)
1455 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1456 GtkPrinter *printer;
1457 GtkTreeIter iter, filter_iter;
1459 /* Whenever the user selects a printer we stop looking for
1460 the printer specified in the initial settings */
1461 if (priv->waiting_for_printer &&
1462 !priv->internal_printer_change)
1464 g_free (priv->waiting_for_printer);
1465 priv->waiting_for_printer = NULL;
1468 disconnect_printer_details_request (dialog);
1471 if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
1473 gtk_tree_model_filter_convert_iter_to_child_iter (priv->printer_list_filter,
1477 gtk_tree_model_get (priv->printer_list, &iter,
1478 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1482 /* sets GTK_RESPONSE_OK button sensitive/insensitive depending on whether the printer
1483 * accepts/rejects jobs */
1484 if (printer != NULL)
1486 if (!gtk_printer_is_accepting_jobs (printer))
1488 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1492 if (priv->current_printer == printer && gtk_printer_has_details (printer))
1493 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1497 if (printer != NULL && !gtk_printer_has_details (printer))
1499 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1500 priv->request_details_tag =
1501 g_signal_connect (printer, "details-acquired",
1502 G_CALLBACK (printer_details_acquired), dialog);
1503 /* take the reference */
1504 priv->request_details_printer = printer;
1505 gtk_printer_request_details (printer);
1509 if (printer == priv->current_printer)
1512 g_object_unref (printer);
1518 g_object_unref (priv->options);
1519 priv->options = NULL;
1521 clear_per_printer_ui (dialog);
1524 if (priv->current_printer)
1526 g_object_unref (priv->current_printer);
1529 priv->printer_capabilities = 0;
1531 if (gtk_printer_is_accepting_jobs (printer))
1532 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1533 priv->current_printer = printer;
1535 if (printer != NULL)
1537 if (!priv->page_setup_set)
1539 /* if no explicit page setup has been set, use the printer default */
1540 GtkPageSetup *page_setup;
1542 page_setup = gtk_printer_get_default_page_size (printer);
1545 page_setup = gtk_page_setup_new ();
1547 g_object_unref (priv->page_setup);
1548 priv->page_setup = page_setup;
1551 priv->printer_capabilities = gtk_printer_get_capabilities (printer);
1552 priv->options = _gtk_printer_get_options (printer,
1553 priv->initial_settings,
1555 priv->manual_capabilities);
1557 priv->options_changed_handler =
1558 g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
1561 update_dialog_from_settings (dialog);
1562 update_dialog_from_capabilities (dialog);
1566 update_collate_icon (GtkToggleButton *toggle_button,
1567 GtkPrintUnixDialog *dialog)
1569 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1571 gtk_widget_queue_draw (priv->collate_image);
1575 paint_page (GtkWidget *widget,
1583 gint x, y, width, height;
1584 gint text_y, linewidth;
1586 x = x_offset * scale;
1587 y = y_offset * scale;
1589 height = 26 * scale;
1594 gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
1595 cairo_rectangle (cr, x, y, width, height);
1598 gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_NORMAL]);
1599 cairo_set_line_width (cr, linewidth);
1600 cairo_rectangle (cr, x + linewidth/2.0, y + linewidth/2.0, width - linewidth, height - linewidth);
1603 cairo_select_font_face (cr, "Sans",
1604 CAIRO_FONT_SLANT_NORMAL,
1605 CAIRO_FONT_WEIGHT_NORMAL);
1606 cairo_set_font_size (cr, (gint)(9 * scale));
1607 cairo_move_to (cr, x + (gint)(text_x * scale), y + (gint)(text_y * scale));
1608 cairo_show_text (cr, text);
1613 draw_collate_cb (GtkWidget *widget,
1614 GdkEventExpose *event,
1615 GtkPrintUnixDialog *dialog)
1617 GtkSettings *settings;
1621 gboolean collate, reverse, rtl;
1625 collate = dialog_get_collate (dialog);
1626 reverse = dialog_get_reverse (dialog);
1627 copies = dialog_get_n_copies (dialog);
1629 rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL);
1631 settings = gtk_widget_get_settings (widget);
1632 gtk_icon_size_lookup_for_settings (settings,
1633 GTK_ICON_SIZE_DIALOG,
1636 scale = size / 48.0;
1637 text_x = rtl ? 4 : 11;
1639 cr = gdk_cairo_create (widget->window);
1641 cairo_translate (cr, widget->allocation.x, widget->allocation.y);
1645 paint_page (widget, cr, scale, rtl ? 40: 15, 5, reverse ? "1" : "2", text_x);
1646 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
1650 paint_page (widget, cr, scale, rtl ? 40: 15, 5, collate == reverse ? "1" : "2", text_x);
1651 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
1653 paint_page (widget, cr, scale, rtl ? 5 : 50, 5, reverse ? "1" : "2", text_x);
1654 paint_page (widget, cr, scale, rtl ? 15 : 40, 15, collate == reverse ? "2" : "1", text_x);
1663 gtk_print_unix_dialog_style_set (GtkWidget *widget,
1664 GtkStyle *previous_style)
1666 GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_set (widget, previous_style);
1668 if (gtk_widget_has_screen (widget))
1670 GtkPrintUnixDialog *dialog = (GtkPrintUnixDialog *)widget;
1671 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1672 GtkSettings *settings;
1676 settings = gtk_widget_get_settings (widget);
1677 gtk_icon_size_lookup_for_settings (settings,
1678 GTK_ICON_SIZE_DIALOG,
1681 scale = size / 48.0;
1683 gtk_widget_set_size_request (priv->collate_image,
1690 update_range_sensitivity (GtkWidget *button,
1695 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
1697 gtk_widget_set_sensitive (range, active);
1700 gtk_widget_grab_focus (range);
1704 emit_ok_response (GtkTreeView *tree_view,
1706 GtkTreeViewColumn *column,
1707 gpointer *user_data)
1709 GtkPrintUnixDialog *print_dialog;
1711 print_dialog = (GtkPrintUnixDialog *) user_data;
1713 gtk_dialog_response (GTK_DIALOG (print_dialog), GTK_RESPONSE_OK);
1717 create_main_page (GtkPrintUnixDialog *dialog)
1719 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1720 GtkWidget *main_vbox, *label, *vbox, *hbox;
1721 GtkWidget *scrolled, *treeview, *frame, *table;
1722 GtkWidget *entry, *spinbutton;
1723 GtkWidget *radio, *check, *image;
1724 GtkCellRenderer *renderer;
1725 GtkTreeViewColumn *column;
1726 GtkTreeSelection *selection;
1727 GtkWidget *custom_input;
1728 const gchar *range_tooltip;
1730 main_vbox = gtk_vbox_new (FALSE, 18);
1731 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
1732 gtk_widget_show (main_vbox);
1734 vbox = gtk_vbox_new (FALSE, 6);
1735 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
1736 gtk_widget_show (vbox);
1738 scrolled = gtk_scrolled_window_new (NULL, NULL);
1739 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
1740 GTK_POLICY_AUTOMATIC,
1741 GTK_POLICY_AUTOMATIC);
1742 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
1744 gtk_widget_show (scrolled);
1745 gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
1747 treeview = gtk_tree_view_new_with_model ((GtkTreeModel *) priv->printer_list_filter);
1748 priv->printer_treeview = treeview;
1749 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
1750 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), PRINTER_LIST_COL_NAME);
1751 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), TRUE);
1752 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
1753 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
1754 g_signal_connect (selection, "changed", G_CALLBACK (selected_printer_changed), dialog);
1756 renderer = gtk_cell_renderer_pixbuf_new ();
1757 column = gtk_tree_view_column_new_with_attributes ("",
1760 PRINTER_LIST_COL_ICON,
1762 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1763 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1765 renderer = gtk_cell_renderer_text_new ();
1766 column = gtk_tree_view_column_new_with_attributes (_("Printer"),
1769 PRINTER_LIST_COL_NAME,
1771 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1772 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1774 renderer = gtk_cell_renderer_text_new ();
1775 /* Translators: this is the header for the location column in the print dialog */
1776 column = gtk_tree_view_column_new_with_attributes (_("Location"),
1779 PRINTER_LIST_COL_LOCATION,
1781 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1782 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1784 renderer = gtk_cell_renderer_text_new ();
1785 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1786 /* Translators: this is the header for the printer status column in the print dialog */
1787 column = gtk_tree_view_column_new_with_attributes (_("Status"),
1790 PRINTER_LIST_COL_STATE,
1792 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
1793 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1795 g_signal_connect (GTK_TREE_VIEW (treeview), "row-activated", G_CALLBACK (emit_ok_response), dialog);
1797 gtk_widget_show (treeview);
1798 gtk_container_add (GTK_CONTAINER (scrolled), treeview);
1800 custom_input = gtk_hbox_new (FALSE, 18);
1801 gtk_widget_show (custom_input);
1802 gtk_box_pack_start (GTK_BOX (vbox), custom_input, FALSE, FALSE, 0);
1803 priv->extension_point = custom_input;
1805 hbox = gtk_hbox_new (FALSE, 18);
1806 gtk_widget_show (hbox);
1807 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
1809 table = gtk_table_new (3, 2, FALSE);
1810 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1811 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1812 frame = wrap_in_frame (_("Range"), table);
1813 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
1814 gtk_widget_show (table);
1816 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_All Pages"));
1817 priv->all_pages_radio = radio;
1818 gtk_widget_show (radio);
1819 gtk_table_attach (GTK_TABLE (table), radio,
1820 0, 2, 0, 1, GTK_FILL, 0,
1822 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
1823 _("C_urrent Page"));
1824 if (priv->current_page == -1)
1825 gtk_widget_set_sensitive (radio, FALSE);
1826 priv->current_page_radio = radio;
1827 gtk_widget_show (radio);
1828 gtk_table_attach (GTK_TABLE (table), radio,
1829 0, 2, 1, 2, GTK_FILL, 0,
1832 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)), _("Pag_es:"));
1833 range_tooltip = _("Specify one or more page ranges,\n e.g. 1-3,7,11");
1834 gtk_widget_set_tooltip_text (radio, range_tooltip);
1836 priv->page_range_radio = radio;
1837 gtk_widget_show (radio);
1838 gtk_table_attach (GTK_TABLE (table), radio,
1839 0, 1, 2, 3, GTK_FILL, 0,
1841 entry = gtk_entry_new ();
1842 gtk_widget_set_tooltip_text (entry, range_tooltip);
1843 priv->page_range_entry = entry;
1844 gtk_widget_show (entry);
1845 gtk_table_attach (GTK_TABLE (table), entry,
1846 1, 2, 2, 3, GTK_FILL, 0,
1848 g_signal_connect (radio, "toggled", G_CALLBACK (update_range_sensitivity), entry);
1849 update_range_sensitivity (radio, entry);
1851 table = gtk_table_new (3, 2, FALSE);
1852 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1853 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1854 frame = wrap_in_frame (_("Copies"), table);
1855 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
1856 gtk_widget_show (table);
1858 /* FIXME chpe: too much space between Copies and spinbutton, put those 2 in a hbox and make it span 2 columns */
1859 label = gtk_label_new_with_mnemonic (_("Copie_s:"));
1860 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1861 gtk_widget_show (label);
1862 gtk_table_attach (GTK_TABLE (table), label,
1863 0, 1, 0, 1, GTK_FILL, 0,
1865 spinbutton = gtk_spin_button_new_with_range (1.0, 100.0, 1.0);
1866 priv->copies_spin = spinbutton;
1867 gtk_widget_show (spinbutton);
1868 gtk_table_attach (GTK_TABLE (table), spinbutton,
1869 1, 2, 0, 1, GTK_FILL, 0,
1871 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
1872 g_signal_connect_swapped (spinbutton, "value-changed",
1873 G_CALLBACK (update_dialog_from_capabilities), dialog);
1874 g_signal_connect_swapped (spinbutton, "changed",
1875 G_CALLBACK (update_dialog_from_capabilities), dialog);
1877 check = gtk_check_button_new_with_mnemonic (_("C_ollate"));
1878 priv->collate_check = check;
1879 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
1880 gtk_widget_show (check);
1881 gtk_table_attach (GTK_TABLE (table), check,
1882 0, 1, 1, 2, GTK_FILL, 0,
1885 check = gtk_check_button_new_with_mnemonic (_("_Reverse"));
1886 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
1887 priv->reverse_check = check;
1888 gtk_widget_show (check);
1889 gtk_table_attach (GTK_TABLE (table), check,
1890 0, 1, 2, 3, GTK_FILL, 0,
1893 image = gtk_drawing_area_new ();
1894 GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
1896 priv->collate_image = image;
1897 gtk_widget_show (image);
1898 gtk_widget_set_size_request (image, 70, 90);
1899 gtk_table_attach (GTK_TABLE (table), image,
1900 1, 2, 1, 3, GTK_FILL, 0,
1902 g_signal_connect (image, "expose-event",
1903 G_CALLBACK (draw_collate_cb), dialog);
1905 label = gtk_label_new (_("General"));
1906 gtk_widget_show (label);
1908 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), main_vbox, label);
1912 is_range_separator (gchar c)
1914 return (c == ',' || c == ';' || c == ':');
1917 static GtkPageRange *
1918 dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
1921 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1923 const gchar *text, *p;
1925 GtkPageRange *ranges;
1928 text = gtk_entry_get_text (GTK_ENTRY (priv->page_range_entry));
1940 if (is_range_separator (*p))
1945 ranges = g_new0 (GtkPageRange, n_ranges);
1951 while (isspace (*p)) p++;
1955 /* a half-open range like -2 */
1960 start = (int)strtol (p, &next, 10);
1968 while (isspace (*p)) p++;
1973 end = (int)strtol (p, &next, 10);
1974 if (next == p) /* a half-open range like 2- */
1976 else if (end < start)
1980 ranges[i].start = start - 1;
1981 ranges[i].end = end - 1;
1984 /* Skip until end or separator */
1985 while (*p && !is_range_separator (*p))
1988 /* if not at end, skip separator */
1999 dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
2000 GtkPageRange *ranges,
2003 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2005 GString *s = g_string_new (NULL);
2007 for (i = 0; i < n_ranges; i++)
2009 g_string_append_printf (s, "%d", ranges[i].start + 1);
2010 if (ranges[i].end > ranges[i].start)
2011 g_string_append_printf (s, "-%d", ranges[i].end + 1);
2012 else if (ranges[i].end == -1)
2013 g_string_append (s, "-");
2015 if (i != n_ranges - 1)
2016 g_string_append (s, ",");
2019 gtk_entry_set_text (GTK_ENTRY (priv->page_range_entry), s->str);
2021 g_string_free (s, TRUE);
2025 static GtkPrintPages
2026 dialog_get_print_pages (GtkPrintUnixDialog *dialog)
2028 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2030 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio)))
2031 return GTK_PRINT_PAGES_ALL;
2032 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->current_page_radio)))
2033 return GTK_PRINT_PAGES_CURRENT;
2035 return GTK_PRINT_PAGES_RANGES;
2039 dialog_set_print_pages (GtkPrintUnixDialog *dialog,
2040 GtkPrintPages pages)
2042 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2044 if (pages == GTK_PRINT_PAGES_RANGES)
2045 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
2046 else if (pages == GTK_PRINT_PAGES_CURRENT)
2047 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->current_page_radio), TRUE);
2049 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio), TRUE);
2053 dialog_get_scale (GtkPrintUnixDialog *dialog)
2055 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->scale_spin))
2056 return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
2062 dialog_set_scale (GtkPrintUnixDialog *dialog,
2065 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin), val);
2069 dialog_get_page_set (GtkPrintUnixDialog *dialog)
2071 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->page_set_combo))
2072 return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
2074 return GTK_PAGE_SET_ALL;
2078 dialog_set_page_set (GtkPrintUnixDialog *dialog,
2081 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->page_set_combo),
2086 dialog_get_n_copies (GtkPrintUnixDialog *dialog)
2088 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->copies_spin))
2089 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
2094 dialog_set_n_copies (GtkPrintUnixDialog *dialog,
2097 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->copies_spin),
2102 dialog_get_collate (GtkPrintUnixDialog *dialog)
2104 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->collate_check))
2105 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
2110 dialog_set_collate (GtkPrintUnixDialog *dialog,
2113 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check),
2118 dialog_get_reverse (GtkPrintUnixDialog *dialog)
2120 if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->reverse_check))
2121 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
2126 dialog_set_reverse (GtkPrintUnixDialog *dialog,
2129 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check),
2134 dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
2136 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2140 val = gtk_printer_option_widget_get_value (priv->pages_per_sheet);
2154 static GtkNumberUpLayout
2155 dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
2157 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2158 GtkPrintCapabilities caps;
2159 GtkNumberUpLayout layout;
2161 GEnumClass *enum_class;
2162 GEnumValue *enum_value;
2164 val = gtk_printer_option_widget_get_value (priv->number_up_layout);
2166 caps = priv->manual_capabilities | priv->printer_capabilities;
2168 if ((caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) == 0)
2169 return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2171 if (gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR)
2172 layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2174 layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
2179 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
2180 enum_value = g_enum_get_value_by_nick (enum_class, val);
2182 layout = enum_value->value;
2183 g_type_class_unref (enum_class);
2189 draw_page_cb (GtkWidget *widget,
2190 GdkEventExpose *event,
2191 GtkPrintUnixDialog *dialog)
2193 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2196 gint w, h, tmp, shadow_offset;
2197 gint pages_x, pages_y, i, x, y, layout_w, layout_h;
2198 gdouble page_width, page_height;
2199 GtkPageOrientation orientation;
2201 PangoLayout *layout;
2202 PangoFontDescription *font;
2205 GtkNumberUpLayout number_up_layout;
2206 gint start_x, end_x, start_y, end_y;
2208 gboolean horizontal;
2210 orientation = gtk_page_setup_get_orientation (priv->page_setup);
2212 (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
2213 (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
2215 number_up_layout = dialog_get_number_up_layout (dialog);
2217 cr = gdk_cairo_create (widget->window);
2219 cairo_translate (cr, widget->allocation.x, widget->allocation.y);
2223 w = (EXAMPLE_PAGE_AREA_SIZE - 3) / ratio;
2226 switch (dialog_get_pages_per_sheet (dialog))
2230 pages_x = 1; pages_y = 1;
2233 landscape = !landscape;
2234 pages_x = 1; pages_y = 2;
2237 pages_x = 2; pages_y = 2;
2240 landscape = !landscape;
2241 pages_x = 2; pages_y = 3;
2244 pages_x = 3; pages_y = 3;
2247 pages_x = 4; pages_y = 4;
2264 color = &widget->style->text[GTK_STATE_NORMAL];
2265 cairo_set_source_rgba (cr, color->red / 65535., color->green / 65535., color->blue / 65535, 0.5);
2266 cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
2269 gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
2270 cairo_rectangle (cr, 1, 1, w, h);
2272 cairo_set_line_width (cr, 1.0);
2273 cairo_rectangle (cr, 0.5, 0.5, w+1, h+1);
2275 gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_NORMAL]);
2280 page_width = (double)w / pages_x;
2281 page_height = (double)h / pages_y;
2283 layout = pango_cairo_create_layout (cr);
2285 font = pango_font_description_new ();
2286 pango_font_description_set_family (font, "sans");
2287 pango_font_description_set_absolute_size (font, page_height * 0.4 * PANGO_SCALE);
2288 pango_layout_set_font_description (layout, font);
2289 pango_font_description_free (font);
2291 pango_layout_set_width (layout, page_width * PANGO_SCALE);
2292 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2294 switch (number_up_layout)
2297 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
2299 end_x = pages_x - 1;
2301 end_y = pages_y - 1;
2306 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
2308 end_x = pages_x - 1;
2309 start_y = pages_y - 1;
2315 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
2316 start_x = pages_x - 1;
2319 end_y = pages_y - 1;
2324 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
2325 start_x = pages_x - 1;
2327 start_y = pages_y - 1;
2333 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
2335 end_x = pages_x - 1;
2337 end_y = pages_y - 1;
2342 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
2343 start_x = pages_x - 1;
2346 end_y = pages_y - 1;
2351 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
2353 end_x = pages_x - 1;
2354 start_y = pages_y - 1;
2360 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
2361 start_x = pages_x - 1;
2363 start_y = pages_y - 1;
2372 for (y = start_y; y != end_y + dy; y += dy)
2374 for (x = start_x; x != end_x + dx; x += dx)
2376 text = g_strdup_printf ("%d", i++);
2377 pango_layout_set_text (layout, text, -1);
2379 pango_layout_get_size (layout, &layout_w, &layout_h);
2381 cairo_translate (cr,
2383 y * page_height + (page_height - layout_h / 1024.0) / 2);
2385 pango_cairo_show_layout (cr, layout);
2390 for (x = start_x; x != end_x + dx; x += dx)
2392 for (y = start_y; y != end_y + dy; y += dy)
2394 text = g_strdup_printf ("%d", i++);
2395 pango_layout_set_text (layout, text, -1);
2397 pango_layout_get_size (layout, &layout_w, &layout_h);
2399 cairo_translate (cr,
2401 y * page_height + (page_height - layout_h / 1024.0) / 2);
2403 pango_cairo_show_layout (cr, layout);
2408 g_object_unref (layout);
2415 redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
2417 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2419 if (priv->page_layout_preview)
2420 gtk_widget_queue_draw (priv->page_layout_preview);
2424 update_number_up_layout (GtkPrintUnixDialog *dialog)
2426 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2427 GtkPrintCapabilities caps;
2428 GtkPrinterOptionSet *set;
2429 GtkNumberUpLayout layout;
2430 GtkPrinterOption *option;
2431 GtkPrinterOption *old_option;
2433 set = priv->options;
2435 caps = priv->manual_capabilities | priv->printer_capabilities;
2437 if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
2439 if (priv->number_up_layout_n_option == NULL)
2441 priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
2442 g_object_ref (priv->number_up_layout_n_option);
2444 priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
2446 GTK_PRINTER_OPTION_TYPE_PICKONE);
2447 gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
2449 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
2450 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
2451 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
2452 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
2455 layout = dialog_get_number_up_layout (dialog);
2457 old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
2458 if (old_option != NULL)
2459 gtk_printer_option_set_remove (set, old_option);
2461 if (dialog_get_pages_per_sheet (dialog) != 1)
2463 GEnumClass *enum_class;
2464 GEnumValue *enum_value;
2465 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
2467 if (dialog_get_pages_per_sheet (dialog) == 2)
2469 option = priv->number_up_layout_2_option;
2471 if (layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM ||
2472 layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP ||
2473 layout == GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT ||
2474 layout == GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT)
2475 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
2477 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM);
2481 option = priv->number_up_layout_n_option;
2483 enum_value = g_enum_get_value (enum_class, layout);
2486 g_assert (enum_value != NULL);
2487 gtk_printer_option_set (option, enum_value->value_nick);
2488 g_type_class_unref (enum_class);
2490 gtk_printer_option_set_add (set, option);
2494 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
2496 if (priv->number_up_layout != NULL)
2497 gtk_widget_set_sensitive (GTK_WIDGET (priv->number_up_layout),
2498 (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) &&
2499 (dialog_get_pages_per_sheet (dialog) > 1));
2503 create_page_setup_page (GtkPrintUnixDialog *dialog)
2505 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2506 GtkWidget *main_vbox, *label, *hbox, *hbox2;
2507 GtkWidget *frame, *table, *widget;
2508 GtkWidget *combo, *spinbutton, *draw;
2510 main_vbox = gtk_vbox_new (FALSE, 18);
2511 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2512 gtk_widget_show (main_vbox);
2514 hbox = gtk_hbox_new (FALSE, 18);
2515 gtk_widget_show (hbox);
2516 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
2518 table = gtk_table_new (5, 2, FALSE);
2519 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2520 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2521 frame = wrap_in_frame (_("Layout"), table);
2522 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2523 gtk_widget_show (table);
2525 label = gtk_label_new_with_mnemonic (_("T_wo-sided:"));
2526 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2527 gtk_widget_show (label);
2528 gtk_table_attach (GTK_TABLE (table), label,
2529 0, 1, 0, 1, GTK_FILL, 0,
2532 widget = gtk_printer_option_widget_new (NULL);
2533 priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
2534 gtk_widget_show (widget);
2535 gtk_table_attach (GTK_TABLE (table), widget,
2536 1, 2, 0, 1, GTK_FILL, 0,
2538 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2540 label = gtk_label_new_with_mnemonic (_("Pages per _side:"));
2541 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2542 gtk_widget_show (label);
2543 gtk_table_attach (GTK_TABLE (table), label,
2544 0, 1, 1, 2, GTK_FILL, 0,
2547 widget = gtk_printer_option_widget_new (NULL);
2548 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
2549 g_signal_connect_swapped (widget, "changed", G_CALLBACK (update_number_up_layout), dialog);
2550 priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
2551 gtk_widget_show (widget);
2552 gtk_table_attach (GTK_TABLE (table), widget,
2553 1, 2, 1, 2, GTK_FILL, 0,
2555 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2558 label = gtk_label_new_with_mnemonic (_("Page or_dering:"));
2559 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2560 gtk_widget_show (label);
2561 gtk_table_attach (GTK_TABLE (table), label,
2562 0, 1, 2, 3, GTK_FILL, 0,
2565 widget = gtk_printer_option_widget_new (NULL);
2566 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
2567 priv->number_up_layout = GTK_PRINTER_OPTION_WIDGET (widget);
2568 gtk_widget_show (widget);
2569 gtk_table_attach (GTK_TABLE (table), widget,
2570 1, 2, 2, 3, GTK_FILL, 0,
2572 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2574 label = gtk_label_new_with_mnemonic (_("_Only print:"));
2575 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2576 gtk_widget_show (label);
2577 gtk_table_attach (GTK_TABLE (table), label,
2578 0, 1, 3, 4, GTK_FILL, 0,
2581 combo = gtk_combo_box_new_text ();
2582 priv->page_set_combo = combo;
2583 gtk_widget_show (combo);
2584 gtk_table_attach (GTK_TABLE (table), combo,
2585 1, 2, 3, 4, GTK_FILL, 0,
2587 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
2589 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("All sheets"));
2590 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Even sheets"));
2591 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Odd sheets"));
2592 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
2594 label = gtk_label_new_with_mnemonic (_("Sc_ale:"));
2595 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2596 gtk_widget_show (label);
2597 gtk_table_attach (GTK_TABLE (table), label,
2598 0, 1, 4, 5, GTK_FILL, 0,
2601 hbox2 = gtk_hbox_new (FALSE, 6);
2602 gtk_widget_show (hbox2);
2603 gtk_table_attach (GTK_TABLE (table), hbox2,
2604 1, 2, 4, 5, GTK_FILL, 0,
2607 spinbutton = gtk_spin_button_new_with_range (1.0, 1000.0, 1.0);
2608 priv->scale_spin = spinbutton;
2609 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), 1);
2610 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton), 100.0);
2611 gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
2612 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
2613 gtk_widget_show (spinbutton);
2614 label = gtk_label_new ("%"); /* FIXMEchpe does there exist any language where % needs to be translated? */
2615 gtk_widget_show (label);
2616 gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2618 table = gtk_table_new (4, 2, FALSE);
2619 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2620 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2621 frame = wrap_in_frame (_("Paper"), table);
2622 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
2623 gtk_widget_show (table);
2625 label = gtk_label_new_with_mnemonic (_("Paper _type:"));
2626 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2627 gtk_widget_show (label);
2628 gtk_table_attach (GTK_TABLE (table), label,
2629 0, 1, 0, 1, GTK_FILL, 0,
2632 widget = gtk_printer_option_widget_new (NULL);
2633 priv->paper_type = GTK_PRINTER_OPTION_WIDGET (widget);
2634 gtk_widget_show (widget);
2635 gtk_table_attach (GTK_TABLE (table), widget,
2636 1, 2, 0, 1, GTK_FILL, 0,
2638 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2640 label = gtk_label_new_with_mnemonic (_("Paper _source:"));
2641 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2642 gtk_widget_show (label);
2643 gtk_table_attach (GTK_TABLE (table), label,
2644 0, 1, 1, 2, GTK_FILL, 0,
2647 widget = gtk_printer_option_widget_new (NULL);
2648 priv->paper_source = GTK_PRINTER_OPTION_WIDGET (widget);
2649 gtk_widget_show (widget);
2650 gtk_table_attach (GTK_TABLE (table), widget,
2651 1, 2, 1, 2, GTK_FILL, 0,
2653 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2655 label = gtk_label_new_with_mnemonic (_("Output t_ray:"));
2656 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2657 gtk_widget_show (label);
2658 gtk_table_attach (GTK_TABLE (table), label,
2659 0, 1, 2, 3, GTK_FILL, 0,
2662 widget = gtk_printer_option_widget_new (NULL);
2663 priv->output_tray = GTK_PRINTER_OPTION_WIDGET (widget);
2664 gtk_widget_show (widget);
2665 gtk_table_attach (GTK_TABLE (table), widget,
2666 1, 2, 2, 3, GTK_FILL, 0,
2668 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2670 /* Add the page layout preview */
2671 hbox2 = gtk_hbox_new (FALSE, 0);
2672 gtk_widget_show (hbox2);
2673 gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 0);
2675 draw = gtk_drawing_area_new ();
2676 GTK_WIDGET_SET_FLAGS (draw, GTK_NO_WINDOW);
2677 priv->page_layout_preview = draw;
2678 gtk_widget_set_size_request (draw, 200, 200);
2679 g_signal_connect (draw, "expose-event", G_CALLBACK (draw_page_cb), dialog);
2680 gtk_widget_show (draw);
2682 gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 0);
2684 label = gtk_label_new (_("Page Setup"));
2685 gtk_widget_show (label);
2687 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2692 create_job_page (GtkPrintUnixDialog *dialog)
2694 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2695 GtkWidget *main_table, *label;
2696 GtkWidget *frame, *table, *radio;
2697 GtkWidget *entry, *widget;
2698 const gchar *at_tooltip;
2699 const gchar *on_hold_tooltip;
2701 main_table = gtk_table_new (2, 2, FALSE);
2702 gtk_container_set_border_width (GTK_CONTAINER (main_table), 12);
2703 gtk_table_set_row_spacings (GTK_TABLE (main_table), 18);
2704 gtk_table_set_col_spacings (GTK_TABLE (main_table), 18);
2706 table = gtk_table_new (2, 2, FALSE);
2707 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2708 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2709 frame = wrap_in_frame (_("Job Details"), table);
2710 gtk_table_attach (GTK_TABLE (main_table), frame,
2711 0, 1, 0, 1, GTK_FILL, 0,
2713 gtk_widget_show (table);
2715 label = gtk_label_new_with_mnemonic (_("Pri_ority:"));
2716 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2717 gtk_widget_show (label);
2718 gtk_table_attach (GTK_TABLE (table), label,
2719 0, 1, 0, 1, GTK_FILL, 0,
2722 widget = gtk_printer_option_widget_new (NULL);
2723 priv->job_prio = GTK_PRINTER_OPTION_WIDGET (widget);
2724 gtk_widget_show (widget);
2725 gtk_table_attach (GTK_TABLE (table), widget,
2726 1, 2, 0, 1, GTK_FILL, 0,
2728 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2730 label = gtk_label_new_with_mnemonic (_("_Billing info:"));
2731 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2732 gtk_widget_show (label);
2733 gtk_table_attach (GTK_TABLE (table), label,
2734 0, 1, 1, 2, GTK_FILL, 0,
2737 widget = gtk_printer_option_widget_new (NULL);
2738 priv->billing_info = GTK_PRINTER_OPTION_WIDGET (widget);
2739 gtk_widget_show (widget);
2740 gtk_table_attach (GTK_TABLE (table), widget,
2741 1, 2, 1, 2, GTK_FILL, 0,
2743 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2745 table = gtk_table_new (2, 2, FALSE);
2746 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2747 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2748 frame = wrap_in_frame (_("Print Document"), table);
2749 gtk_table_attach (GTK_TABLE (main_table), frame,
2750 0, 1, 1, 2, GTK_FILL, 0,
2752 gtk_widget_show (table);
2754 /* Translators: this is one of the choices for the print at option
2755 * in the print dialog
2757 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Now"));
2758 priv->print_now_radio = radio;
2759 gtk_widget_show (radio);
2760 gtk_table_attach (GTK_TABLE (table), radio,
2761 0, 2, 0, 1, GTK_FILL, 0,
2763 /* Translators: this is one of the choices for the print at option
2764 * in the print dialog. It also serves as the label for an entry that
2765 * allows the user to enter a time.
2767 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2770 /* Translators: Ability to parse the am/pm format depends on actual locale.
2771 * You can remove the am/pm values below for your locale if they are not supported.
2773 at_tooltip = _("Specify the time of print,\n e.g. 15:30, 2:35 pm, 14:15:20, 11:46:30 am, 4 pm");
2774 gtk_widget_set_tooltip_text (radio, at_tooltip);
2775 priv->print_at_radio = radio;
2776 gtk_widget_show (radio);
2777 gtk_table_attach (GTK_TABLE (table), radio,
2778 0, 1, 1, 2, GTK_FILL, 0,
2781 entry = gtk_entry_new ();
2782 gtk_widget_set_tooltip_text (entry, at_tooltip);
2783 priv->print_at_entry = entry;
2784 gtk_widget_show (entry);
2785 gtk_table_attach (GTK_TABLE (table), entry,
2786 1, 2, 1, 2, GTK_FILL, 0,
2789 /* Translators: this is one of the choices for the print at option
2790 * in the print dialog. It means that the print job will not be
2791 * printed until it explicitly gets 'released'.
2793 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2795 on_hold_tooltip = _("Hold the job until it is explicitly released");
2796 gtk_widget_set_tooltip_text (radio, on_hold_tooltip);
2797 priv->print_hold_radio = radio;
2798 gtk_widget_show (radio);
2799 gtk_table_attach (GTK_TABLE (table), radio,
2800 0, 2, 2, 3, GTK_FILL, 0,
2803 g_signal_connect_swapped (priv->print_now_radio, "toggled",
2804 G_CALLBACK (update_print_at_option), dialog);
2805 g_signal_connect_swapped (priv->print_at_radio, "toggled",
2806 G_CALLBACK (update_print_at_option), dialog);
2807 g_signal_connect_swapped (priv->print_at_entry, "changed",
2808 G_CALLBACK (update_print_at_option), dialog);
2809 g_signal_connect_swapped (priv->print_hold_radio, "toggled",
2810 G_CALLBACK (update_print_at_option), dialog);
2812 table = gtk_table_new (2, 2, FALSE);
2813 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2814 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2815 frame = wrap_in_frame (_("Add Cover Page"), table);
2816 gtk_table_attach (GTK_TABLE (main_table), frame,
2817 1, 2, 0, 1, GTK_FILL, 0,
2819 gtk_widget_show (table);
2821 /* Translators, this is the label used for the option in the print
2822 * dialog that controls the front cover page.
2824 label = gtk_label_new_with_mnemonic (_("Be_fore:"));
2825 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2826 gtk_widget_show (label);
2827 gtk_table_attach (GTK_TABLE (table), label,
2828 0, 1, 0, 1, GTK_FILL, 0,
2831 widget = gtk_printer_option_widget_new (NULL);
2832 priv->cover_before = GTK_PRINTER_OPTION_WIDGET (widget);
2833 gtk_widget_show (widget);
2834 gtk_table_attach (GTK_TABLE (table), widget,
2835 1, 2, 0, 1, GTK_FILL, 0,
2837 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2839 /* Translators, this is the label used for the option in the print
2840 * dialog that controls the back cover page.
2842 label = gtk_label_new_with_mnemonic (_("_After:"));
2843 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2844 gtk_widget_show (label);
2845 gtk_table_attach (GTK_TABLE (table), label,
2846 0, 1, 1, 2, GTK_FILL, 0,
2849 widget = gtk_printer_option_widget_new (NULL);
2850 priv->cover_after = GTK_PRINTER_OPTION_WIDGET (widget);
2851 gtk_widget_show (widget);
2852 gtk_table_attach (GTK_TABLE (table), widget,
2853 1, 2, 1, 2, GTK_FILL, 0,
2855 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
2857 /* Translators: this is the tab label for the notebook tab containing
2858 * job-specific options in the print dialog
2860 label = gtk_label_new (_("Job"));
2861 gtk_widget_show (label);
2863 priv->job_page = main_table;
2864 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2869 create_optional_page (GtkPrintUnixDialog *dialog,
2871 GtkWidget **table_out,
2872 GtkWidget **page_out)
2874 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2875 GtkWidget *table, *label, *scrolled;
2877 scrolled = gtk_scrolled_window_new (NULL, NULL);
2878 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2880 GTK_POLICY_AUTOMATIC);
2882 table = gtk_table_new (1, 2, FALSE);
2883 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2884 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2885 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
2886 gtk_widget_show (table);
2888 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
2890 gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN(scrolled)->child),
2893 label = gtk_label_new (text);
2894 gtk_widget_show (label);
2896 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2900 *page_out = scrolled;
2904 create_advanced_page (GtkPrintUnixDialog *dialog)
2906 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2907 GtkWidget *main_vbox, *label, *scrolled;
2909 scrolled = gtk_scrolled_window_new (NULL, NULL);
2910 priv->advanced_page = scrolled;
2911 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2913 GTK_POLICY_AUTOMATIC);
2915 main_vbox = gtk_vbox_new (FALSE, 18);
2916 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2917 gtk_widget_show (main_vbox);
2919 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
2921 gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN(scrolled)->child),
2924 priv->advanced_vbox = main_vbox;
2926 label = gtk_label_new (_("Advanced"));
2927 gtk_widget_show (label);
2929 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2935 populate_dialog (GtkPrintUnixDialog *print_dialog)
2937 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
2938 GtkDialog *dialog = GTK_DIALOG (print_dialog);
2939 GtkWidget *vbox, *conflict_hbox, *image, *label;
2941 gtk_dialog_set_has_separator (dialog, FALSE);
2942 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
2943 gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
2944 gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
2945 gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
2947 vbox = gtk_vbox_new (FALSE, 6);
2948 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
2949 gtk_box_pack_start (GTK_BOX (dialog->vbox), vbox, TRUE, TRUE, 0);
2950 gtk_widget_show (vbox);
2952 priv->notebook = gtk_notebook_new ();
2953 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
2954 gtk_widget_show (priv->notebook);
2956 create_printer_list_model (print_dialog);
2958 create_main_page (print_dialog);
2959 create_page_setup_page (print_dialog);
2960 create_job_page (print_dialog);
2961 create_optional_page (print_dialog, _("Image Quality"),
2962 &priv->image_quality_table,
2963 &priv->image_quality_page);
2964 create_optional_page (print_dialog, _("Color"),
2967 create_optional_page (print_dialog, _("Finishing"),
2968 &priv->finishing_table,
2969 &priv->finishing_page);
2970 create_advanced_page (print_dialog);
2972 priv->conflicts_widget = conflict_hbox = gtk_hbox_new (FALSE, 12);
2973 gtk_box_pack_end (GTK_BOX (vbox), conflict_hbox, FALSE, FALSE, 0);
2974 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
2975 gtk_widget_show (image);
2976 gtk_box_pack_start (GTK_BOX (conflict_hbox), image, FALSE, TRUE, 0);
2977 label = gtk_label_new (_("Some of the settings in the dialog conflict"));
2978 gtk_widget_show (label);
2979 gtk_box_pack_start (GTK_BOX (conflict_hbox), label, FALSE, TRUE, 0);
2981 load_print_backends (print_dialog);
2985 * gtk_print_unix_dialog_new:
2986 * @title: Title of the dialog, or %NULL
2987 * @parent: Transient parent of the dialog, or %NULL
2989 * Creates a new #GtkPrintUnixDialog.
2991 * Return value: a new #GtkPrintUnixDialog
2996 gtk_print_unix_dialog_new (const gchar *title,
3000 const gchar *_title = _("Print");
3005 result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
3006 "transient-for", parent,
3008 "has-separator", FALSE,
3015 * gtk_print_unix_dialog_get_selected_printer:
3016 * @dialog: a #GtkPrintUnixDialog
3018 * Gets the currently selected printer.
3020 * Returns: the currently selected printer
3025 gtk_print_unix_dialog_get_selected_printer (GtkPrintUnixDialog *dialog)
3027 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3029 return dialog->priv->current_printer;
3033 * gtk_print_unix_dialog_set_page_setup:
3034 * @dialog: a #GtkPrintUnixDialog
3035 * @page_setup: a #GtkPageSetup
3037 * Sets the page setup of the #GtkPrintUnixDialog.
3042 gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
3043 GtkPageSetup *page_setup)
3045 GtkPrintUnixDialogPrivate *priv;
3047 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3048 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
3050 priv = dialog->priv;
3052 if (priv->page_setup != page_setup)
3054 g_object_unref (priv->page_setup);
3055 priv->page_setup = g_object_ref (page_setup);
3057 priv->page_setup_set = TRUE;
3059 g_object_notify (G_OBJECT (dialog), "page-setup");
3064 * gtk_print_unix_dialog_get_page_setup:
3065 * @dialog: a #GtkPrintUnixDialog
3067 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3069 * Returns: the page setup of @dialog.
3074 gtk_print_unix_dialog_get_page_setup (GtkPrintUnixDialog *dialog)
3076 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3078 return dialog->priv->page_setup;
3082 * gtk_print_unix_dialog_set_current_page:
3083 * @dialog: a #GtkPrintUnixDialog
3084 * @current_page: the current page number.
3086 * Sets the current page number. If @current_page is not -1, this enables
3087 * the current page choice for the range of pages to print.
3092 gtk_print_unix_dialog_set_current_page (GtkPrintUnixDialog *dialog,
3095 GtkPrintUnixDialogPrivate *priv;
3097 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3099 priv = dialog->priv;
3101 if (priv->current_page != current_page)
3103 priv->current_page = current_page;
3105 if (priv->current_page_radio)
3106 gtk_widget_set_sensitive (priv->current_page_radio, current_page != -1);
3108 g_object_notify (G_OBJECT (dialog), "current-page");
3113 * gtk_print_unix_dialog_get_current_page:
3114 * @dialog: a #GtkPrintUnixDialog
3116 * Gets the current page of the #GtkPrintDialog.
3118 * Returns: the current page of @dialog
3123 gtk_print_unix_dialog_get_current_page (GtkPrintUnixDialog *dialog)
3125 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), -1);
3127 return dialog->priv->current_page;
3131 set_active_printer (GtkPrintUnixDialog *dialog,
3132 const gchar *printer_name)
3134 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3135 GtkTreeModel *model;
3136 GtkTreeIter iter, filter_iter;
3137 GtkTreeSelection *selection;
3138 GtkPrinter *printer;
3140 model = GTK_TREE_MODEL (priv->printer_list);
3142 if (gtk_tree_model_get_iter_first (model, &iter))
3146 gtk_tree_model_get (GTK_TREE_MODEL (priv->printer_list), &iter,
3147 PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
3148 if (printer == NULL)
3151 if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
3153 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
3154 &filter_iter, &iter);
3156 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
3157 priv->internal_printer_change = TRUE;
3158 gtk_tree_selection_select_iter (selection, &filter_iter);
3159 priv->internal_printer_change = FALSE;
3160 g_free (priv->waiting_for_printer);
3161 priv->waiting_for_printer = NULL;
3163 g_object_unref (printer);
3167 g_object_unref (printer);
3169 } while (gtk_tree_model_iter_next (model, &iter));
3176 * gtk_print_unix_dialog_set_settings:
3177 * @dialog: a #GtkPrintUnixDialog
3178 * @settings: a #GtkPrintSettings, or %NULL
3180 * Sets the #GtkPrintSettings for the #GtkPrintUnixDialog. Typically,
3181 * this is used to restore saved print settings from a previous print
3182 * operation before the print dialog is shown.
3187 gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
3188 GtkPrintSettings *settings)
3190 GtkPrintUnixDialogPrivate *priv;
3191 const gchar *printer;
3192 GtkPageRange *ranges;
3195 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3196 g_return_if_fail (settings == NULL || GTK_IS_PRINT_SETTINGS (settings));
3198 priv = dialog->priv;
3200 if (settings != NULL)
3202 dialog_set_collate (dialog, gtk_print_settings_get_collate (settings));
3203 dialog_set_reverse (dialog, gtk_print_settings_get_reverse (settings));
3204 dialog_set_n_copies (dialog, gtk_print_settings_get_n_copies (settings));
3205 dialog_set_scale (dialog, gtk_print_settings_get_scale (settings));
3206 dialog_set_page_set (dialog, gtk_print_settings_get_page_set (settings));
3207 dialog_set_print_pages (dialog, gtk_print_settings_get_print_pages (settings));
3208 ranges = gtk_print_settings_get_page_ranges (settings, &num_ranges);
3211 dialog_set_page_ranges (dialog, ranges, num_ranges);
3215 priv->format_for_printer =
3216 g_strdup (gtk_print_settings_get (settings, "format-for-printer"));
3219 if (priv->initial_settings)
3220 g_object_unref (priv->initial_settings);
3222 priv->initial_settings = settings;
3224 g_free (priv->waiting_for_printer);
3225 priv->waiting_for_printer = NULL;
3229 g_object_ref (settings);
3231 printer = gtk_print_settings_get_printer (settings);
3233 if (printer && !set_active_printer (dialog, printer))
3234 priv->waiting_for_printer = g_strdup (printer);
3237 g_object_notify (G_OBJECT (dialog), "print-settings");
3241 * gtk_print_unix_dialog_get_settings:
3242 * @dialog: a #GtkPrintUnixDialog
3244 * Gets a new #GtkPrintSettings object that represents the
3245 * current values in the print dialog. Note that this creates a
3246 * <emphasis>new object</emphasis>, and you need to unref it
3247 * if don't want to keep it.
3249 * Returns: a new #GtkPrintSettings object with the values from @dialog
3254 gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
3256 GtkPrintUnixDialogPrivate *priv;
3257 GtkPrintSettings *settings;
3258 GtkPrintPages print_pages;
3259 GtkPageRange *ranges;
3262 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3264 priv = dialog->priv;
3265 settings = gtk_print_settings_new ();
3267 if (priv->current_printer)
3268 gtk_print_settings_set_printer (settings,
3269 gtk_printer_get_name (priv->current_printer));
3271 gtk_print_settings_set_printer (settings, "default");
3273 gtk_print_settings_set (settings, "format-for-printer",
3274 priv->format_for_printer);
3277 gtk_print_settings_set_collate (settings,
3278 dialog_get_collate (dialog));
3280 gtk_print_settings_set_reverse (settings,
3281 dialog_get_reverse (dialog));
3283 gtk_print_settings_set_n_copies (settings,
3284 dialog_get_n_copies (dialog));
3286 gtk_print_settings_set_scale (settings,
3287 dialog_get_scale (dialog));
3289 gtk_print_settings_set_page_set (settings,
3290 dialog_get_page_set (dialog));
3292 print_pages = dialog_get_print_pages (dialog);
3293 gtk_print_settings_set_print_pages (settings, print_pages);
3295 ranges = dialog_get_page_ranges (dialog, &n_ranges);
3298 gtk_print_settings_set_page_ranges (settings, ranges, n_ranges);
3302 /* TODO: print when. How to handle? */
3304 if (priv->current_printer)
3305 _gtk_printer_get_settings_from_options (priv->current_printer,
3313 * gtk_print_unix_dialog_add_custom_tab:
3314 * @dialog: a #GtkPrintUnixDialog
3315 * @child: the widget to put in the custom tab
3316 * @tab_label: the widget to use as tab label
3318 * Adds a custom tab to the print dialog.
3323 gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
3325 GtkWidget *tab_label)
3327 gtk_notebook_insert_page (GTK_NOTEBOOK (dialog->priv->notebook),
3328 child, tab_label, 2);
3329 gtk_widget_show (child);
3330 gtk_widget_show (tab_label);
3334 * gtk_print_unix_dialog_set_manual_capabilities:
3335 * @dialog: a #GtkPrintUnixDialog
3336 * @capabilities: the printing capabilities of your application
3338 * This lets you specify the printing capabilities your application
3339 * supports. For instance, if you can handle scaling the output then
3340 * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then
3341 * the dialog will only let you select the scale if the printing
3342 * system automatically handles scaling.
3347 gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog,
3348 GtkPrintCapabilities capabilities)
3350 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3352 priv->manual_capabilities = capabilities;
3353 update_dialog_from_capabilities (dialog);
3355 if (priv->current_printer)
3357 GtkTreeSelection *selection;
3359 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
3361 g_object_unref (priv->current_printer);
3362 priv->current_printer = NULL;
3363 priv->internal_printer_change = TRUE;
3364 selected_printer_changed (selection, dialog);
3365 priv->internal_printer_change = FALSE;
3369 #define __GTK_PRINT_UNIX_DIALOG_C__
3370 #include "gtkaliasdef.c"