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, see <http://www.gnu.org/licenses/>.
28 #include "gtkprintunixdialog.h"
30 #include "gtkcustompaperunixdialog.h"
31 #include "gtkprintbackend.h"
32 #include "gtkprinter-private.h"
33 #include "gtkprinteroptionwidget.h"
34 #include "gtkprintutils.h"
36 #include "gtkspinbutton.h"
37 #include "gtkcellrendererpixbuf.h"
38 #include "gtkcellrenderertext.h"
40 #include "gtkiconfactory.h"
42 #include "gtktreeselection.h"
43 #include "gtknotebook.h"
44 #include "gtkscrolledwindow.h"
45 #include "gtkcombobox.h"
46 #include "gtktogglebutton.h"
47 #include "gtkradiobutton.h"
48 #include "gtkdrawingarea.h"
53 #include "gtkeventbox.h"
54 #include "gtkbuildable.h"
55 #include "gtkmessagedialog.h"
56 #include "gtkbutton.h"
58 #include "gtkprivate.h"
59 #include "gtktypebuiltins.h"
63 * SECTION:gtkprintunixdialog
64 * @Short_description: A print dialog
65 * @Title: GtkPrintUnixDialog
66 * @See_also: #GtkPageSetupUnixDialog, #GtkPrinter, #GtkPrintJob
68 * GtkPrintUnixDialog implements a print dialog for platforms
69 * which don't provide a native print dialog, like Unix. It can
70 * be used very much like any other GTK+ dialog, at the cost of
71 * the portability offered by the
72 * <link linkend="gtk-High-level-Printing-API">high-level printing API</link>
74 * In order to print something with #GtkPrintUnixDialog, you need
75 * to use gtk_print_unix_dialog_get_selected_printer() to obtain
76 * a #GtkPrinter object and use it to construct a #GtkPrintJob using
77 * gtk_print_job_new().
79 * #GtkPrintUnixDialog uses the following response values:
81 * <varlistentry><term>%GTK_RESPONSE_OK</term>
82 * <listitem><para>for the "Print" button</para></listitem>
84 * <varlistentry><term>%GTK_RESPONSE_APPLY</term>
85 * <listitem><para>for the "Preview" button</para></listitem>
87 * <varlistentry><term>%GTK_RESPONSE_CANCEL</term>
88 * <listitem><para>for the "Cancel" button</para></listitem>
92 * <!-- FIXME example here -->
94 * Printing support was added in GTK+ 2.10.
96 * <refsect2 id="GtkPrintUnixDialog-BUILDER-UI">
97 * <title>GtkPrintUnixDialog as GtkBuildable</title>
99 * The GtkPrintUnixDialog implementation of the GtkBuildable interface exposes its
100 * @notebook internal children with the name "notebook".
103 * <title>A <structname>GtkPrintUnixDialog</structname> UI definition fragment.</title>
104 * <programlisting><![CDATA[
105 * <object class="GtkPrintUnixDialog" id="dialog1">
106 * <child internal-child="notebook">
107 * <object class="GtkNotebook" id="notebook">
109 * <object class="GtkLabel" id="tabcontent">
110 * <property name="label">Content on notebook tab</property>
114 * <object class="GtkLabel" id="tablabel">
115 * <property name="label">Tab label</property>
118 * <property name="tab_expand">False</property>
119 * <property name="tab_fill">False</property>
125 * ]]></programlisting>
132 #define EXAMPLE_PAGE_AREA_SIZE 110
133 #define RULER_DISTANCE 7.5
134 #define RULER_RADIUS 2
137 static void gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog);
138 static void gtk_print_unix_dialog_finalize (GObject *object);
139 static void gtk_print_unix_dialog_set_property (GObject *object,
143 static void gtk_print_unix_dialog_get_property (GObject *object,
147 static void gtk_print_unix_dialog_style_updated (GtkWidget *widget);
148 static void populate_dialog (GtkPrintUnixDialog *dialog);
149 static void unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog);
150 static void selected_printer_changed (GtkTreeSelection *selection,
151 GtkPrintUnixDialog *dialog);
152 static void clear_per_printer_ui (GtkPrintUnixDialog *dialog);
153 static void printer_added_cb (GtkPrintBackend *backend,
155 GtkPrintUnixDialog *dialog);
156 static void printer_removed_cb (GtkPrintBackend *backend,
158 GtkPrintUnixDialog *dialog);
159 static void printer_status_cb (GtkPrintBackend *backend,
161 GtkPrintUnixDialog *dialog);
162 static void update_collate_icon (GtkToggleButton *toggle_button,
163 GtkPrintUnixDialog *dialog);
164 static gboolean dialog_get_collate (GtkPrintUnixDialog *dialog);
165 static gboolean dialog_get_reverse (GtkPrintUnixDialog *dialog);
166 static gint dialog_get_n_copies (GtkPrintUnixDialog *dialog);
168 static void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
169 GtkCellRenderer *cell,
173 static gboolean set_active_printer (GtkPrintUnixDialog *dialog,
174 const gchar *printer_name);
175 static void redraw_page_layout_preview (GtkPrintUnixDialog *dialog);
178 static void gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface);
179 static GObject *gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
181 const gchar *childname);
183 static const gchar const common_paper_sizes[][16] = {
199 PAGE_SETUP_LIST_COL_PAGE_SETUP,
200 PAGE_SETUP_LIST_COL_IS_SEPARATOR,
201 PAGE_SETUP_LIST_N_COLS
209 PROP_SELECTED_PRINTER,
210 PROP_MANUAL_CAPABILITIES,
211 PROP_SUPPORT_SELECTION,
213 PROP_EMBED_PAGE_SETUP
217 PRINTER_LIST_COL_ICON,
218 PRINTER_LIST_COL_NAME,
219 PRINTER_LIST_COL_STATE,
220 PRINTER_LIST_COL_JOBS,
221 PRINTER_LIST_COL_LOCATION,
222 PRINTER_LIST_COL_PRINTER_OBJ,
226 struct GtkPrintUnixDialogPrivate
230 GtkWidget *printer_treeview;
232 GtkPrintCapabilities manual_capabilities;
233 GtkPrintCapabilities printer_capabilities;
235 GtkTreeModel *printer_list;
236 GtkTreeModelFilter *printer_list_filter;
238 GtkPageSetup *page_setup;
239 gboolean page_setup_set;
240 gboolean embed_page_setup;
241 GtkListStore *page_setup_list;
242 GtkListStore *custom_paper_list;
244 gboolean support_selection;
245 gboolean has_selection;
247 GtkWidget *all_pages_radio;
248 GtkWidget *current_page_radio;
249 GtkWidget *selection_radio;
250 GtkWidget *range_table;
251 GtkWidget *page_range_radio;
252 GtkWidget *page_range_entry;
254 GtkWidget *copies_spin;
255 GtkWidget *collate_check;
256 GtkWidget *reverse_check;
257 GtkWidget *collate_image;
258 GtkWidget *page_layout_preview;
259 GtkWidget *scale_spin;
260 GtkWidget *page_set_combo;
261 GtkWidget *print_now_radio;
262 GtkWidget *print_at_radio;
263 GtkWidget *print_at_entry;
264 GtkWidget *print_hold_radio;
265 GtkWidget *preview_button;
266 GtkWidget *paper_size_combo;
267 GtkWidget *paper_size_combo_label;
268 GtkWidget *orientation_combo;
269 GtkWidget *orientation_combo_label;
270 gboolean internal_page_setup_change;
271 gboolean updating_print_at;
272 GtkPrinterOptionWidget *pages_per_sheet;
273 GtkPrinterOptionWidget *duplex;
274 GtkPrinterOptionWidget *paper_type;
275 GtkPrinterOptionWidget *paper_source;
276 GtkPrinterOptionWidget *output_tray;
277 GtkPrinterOptionWidget *job_prio;
278 GtkPrinterOptionWidget *billing_info;
279 GtkPrinterOptionWidget *cover_before;
280 GtkPrinterOptionWidget *cover_after;
281 GtkPrinterOptionWidget *number_up_layout;
283 GtkWidget *conflicts_widget;
286 GtkWidget *finishing_table;
287 GtkWidget *finishing_page;
288 GtkWidget *image_quality_table;
289 GtkWidget *image_quality_page;
290 GtkWidget *color_table;
291 GtkWidget *color_page;
293 GtkWidget *advanced_vbox;
294 GtkWidget *advanced_page;
296 GtkWidget *extension_point;
298 /* These are set initially on selected printer (either default printer,
299 * printer taken from set settings, or user-selected), but when any
300 * setting is changed by the user it is cleared.
302 GtkPrintSettings *initial_settings;
304 GtkPrinterOption *number_up_layout_n_option;
305 GtkPrinterOption *number_up_layout_2_option;
307 /* This is the initial printer set by set_settings. We look for it in
308 * the added printers. We clear this whenever the user manually changes
309 * to another printer, when the user changes a setting or when we find
312 char *waiting_for_printer;
313 gboolean internal_printer_change;
315 GList *print_backends;
317 GtkPrinter *current_printer;
318 GtkPrinter *request_details_printer;
319 gulong request_details_tag;
320 GtkPrinterOptionSet *options;
321 gulong options_changed_handler;
322 gulong mark_conflicts_id;
324 gchar *format_for_printer;
329 G_DEFINE_TYPE_WITH_CODE (GtkPrintUnixDialog, gtk_print_unix_dialog, GTK_TYPE_DIALOG,
330 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
331 gtk_print_unix_dialog_buildable_init))
333 static GtkBuildableIface *parent_buildable_iface;
336 is_default_printer (GtkPrintUnixDialog *dialog,
339 GtkPrintUnixDialogPrivate *priv = dialog->priv;
341 if (priv->format_for_printer)
342 return strcmp (priv->format_for_printer,
343 gtk_printer_get_name (printer)) == 0;
345 return gtk_printer_is_default (printer);
349 gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
351 GObjectClass *object_class;
352 GtkWidgetClass *widget_class;
354 object_class = (GObjectClass *) class;
355 widget_class = (GtkWidgetClass *) class;
357 object_class->finalize = gtk_print_unix_dialog_finalize;
358 object_class->set_property = gtk_print_unix_dialog_set_property;
359 object_class->get_property = gtk_print_unix_dialog_get_property;
361 widget_class->style_updated = gtk_print_unix_dialog_style_updated;
363 g_object_class_install_property (object_class,
365 g_param_spec_object ("page-setup",
367 P_("The GtkPageSetup to use"),
369 GTK_PARAM_READWRITE));
371 g_object_class_install_property (object_class,
373 g_param_spec_int ("current-page",
375 P_("The current page in the document"),
379 GTK_PARAM_READWRITE));
381 g_object_class_install_property (object_class,
383 g_param_spec_object ("print-settings",
384 P_("Print Settings"),
385 P_("The GtkPrintSettings used for initializing the dialog"),
386 GTK_TYPE_PRINT_SETTINGS,
387 GTK_PARAM_READWRITE));
389 g_object_class_install_property (object_class,
390 PROP_SELECTED_PRINTER,
391 g_param_spec_object ("selected-printer",
392 P_("Selected Printer"),
393 P_("The GtkPrinter which is selected"),
395 GTK_PARAM_READABLE));
397 g_object_class_install_property (object_class,
398 PROP_MANUAL_CAPABILITIES,
399 g_param_spec_flags ("manual-capabilities",
400 P_("Manual Capabilities"),
401 P_("Capabilities the application can handle"),
402 GTK_TYPE_PRINT_CAPABILITIES,
404 GTK_PARAM_READWRITE));
406 g_object_class_install_property (object_class,
407 PROP_SUPPORT_SELECTION,
408 g_param_spec_boolean ("support-selection",
409 P_("Support Selection"),
410 P_("Whether the dialog supports selection"),
412 GTK_PARAM_READWRITE));
414 g_object_class_install_property (object_class,
416 g_param_spec_boolean ("has-selection",
418 P_("Whether the application has a selection"),
420 GTK_PARAM_READWRITE));
422 g_object_class_install_property (object_class,
423 PROP_EMBED_PAGE_SETUP,
424 g_param_spec_boolean ("embed-page-setup",
425 P_("Embed Page Setup"),
426 P_("TRUE if page setup combos are embedded in GtkPrintUnixDialog"),
428 GTK_PARAM_READWRITE));
430 g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));
433 /* Returns a toplevel GtkWindow, or NULL if none */
435 get_toplevel (GtkWidget *widget)
437 GtkWidget *toplevel = NULL;
439 toplevel = gtk_widget_get_toplevel (widget);
440 if (!gtk_widget_is_toplevel (toplevel))
443 return GTK_WINDOW (toplevel);
447 set_busy_cursor (GtkPrintUnixDialog *dialog,
455 toplevel = get_toplevel (GTK_WIDGET (dialog));
456 widget = GTK_WIDGET (toplevel);
458 if (!toplevel || !gtk_widget_get_realized (widget))
461 display = gtk_widget_get_display (widget);
464 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
468 gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
469 gdk_display_flush (display);
472 g_object_unref (cursor);
476 add_custom_button_to_dialog (GtkDialog *dialog,
477 const gchar *mnemonic_label,
478 const gchar *stock_id,
481 GtkWidget *button = NULL;
483 button = gtk_button_new_with_mnemonic (mnemonic_label);
484 gtk_widget_set_can_default (button, TRUE);
485 gtk_button_set_image (GTK_BUTTON (button),
486 gtk_image_new_from_stock (stock_id,
487 GTK_ICON_SIZE_BUTTON));
488 gtk_widget_show (button);
490 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
493 /* This function handles error messages before printing.
496 error_dialogs (GtkPrintUnixDialog *print_dialog,
497 gint print_dialog_response_id,
500 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
501 GtkPrinterOption *option = NULL;
502 GtkPrinter *printer = NULL;
503 GtkWindow *toplevel = NULL;
504 GtkWidget *dialog = NULL;
506 gchar *basename = NULL;
507 gchar *dirname = NULL;
510 if (print_dialog != NULL && print_dialog_response_id == GTK_RESPONSE_OK)
512 printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
516 if (priv->request_details_tag || !gtk_printer_is_accepting_jobs (printer))
518 g_signal_stop_emission_by_name (print_dialog, "response");
522 /* Shows overwrite confirmation dialog in the case of printing
523 * to file which already exists.
525 if (gtk_printer_is_virtual (printer))
527 option = gtk_printer_option_set_lookup (priv->options,
528 "gtk-main-page-custom-input");
530 if (option != NULL &&
531 option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE)
533 file = g_file_new_for_uri (option->value);
536 g_file_query_exists (file, NULL))
538 toplevel = get_toplevel (GTK_WIDGET (print_dialog));
540 basename = g_file_get_basename (file);
541 dirname = g_file_get_parse_name (g_file_get_parent (file));
543 dialog = gtk_message_dialog_new (toplevel,
545 GTK_DIALOG_DESTROY_WITH_PARENT,
546 GTK_MESSAGE_QUESTION,
548 _("A file named \"%s\" already exists. Do you want to replace it?"),
551 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
552 _("The file already exists in \"%s\". Replacing it will "
553 "overwrite its contents."),
556 gtk_dialog_add_button (GTK_DIALOG (dialog),
557 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
558 add_custom_button_to_dialog (GTK_DIALOG (dialog),
561 GTK_RESPONSE_ACCEPT);
562 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
566 gtk_dialog_set_default_response (GTK_DIALOG (dialog),
567 GTK_RESPONSE_ACCEPT);
569 if (gtk_window_has_group (toplevel))
570 gtk_window_group_add_window (gtk_window_get_group (toplevel),
571 GTK_WINDOW (dialog));
573 response = gtk_dialog_run (GTK_DIALOG (dialog));
575 gtk_widget_destroy (dialog);
580 if (response != GTK_RESPONSE_ACCEPT)
582 g_signal_stop_emission_by_name (print_dialog, "response");
583 g_object_unref (file);
588 g_object_unref (file);
597 gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
599 GtkPrintUnixDialogPrivate *priv;
601 dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
602 GTK_TYPE_PRINT_UNIX_DIALOG,
603 GtkPrintUnixDialogPrivate);
606 priv->print_backends = NULL;
607 priv->current_page = -1;
608 priv->number_up_layout_n_option = NULL;
609 priv->number_up_layout_2_option = NULL;
611 priv->page_setup = gtk_page_setup_new ();
612 priv->page_setup_set = FALSE;
613 priv->embed_page_setup = FALSE;
614 priv->internal_page_setup_change = FALSE;
616 priv->support_selection = FALSE;
617 priv->has_selection = FALSE;
619 g_signal_connect (dialog, "destroy",
620 (GCallback) gtk_print_unix_dialog_destroy, NULL);
622 g_signal_connect (dialog, "response",
623 (GCallback) error_dialogs, NULL);
625 g_signal_connect (dialog, "notify::page-setup",
626 (GCallback) redraw_page_layout_preview, NULL);
628 priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
629 gtk_widget_show (priv->preview_button);
631 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
632 priv->preview_button,
634 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
635 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
636 GTK_STOCK_PRINT, GTK_RESPONSE_OK,
638 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
644 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
645 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
647 priv->page_setup_list = gtk_list_store_new (PAGE_SETUP_LIST_N_COLS,
651 priv->custom_paper_list = gtk_list_store_new (1, G_TYPE_OBJECT);
652 _gtk_print_load_custom_papers (priv->custom_paper_list);
654 populate_dialog (dialog);
658 gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
660 /* Make sure we don't destroy custom widgets owned by the backends */
661 clear_per_printer_ui (dialog);
665 disconnect_printer_details_request (GtkPrintUnixDialog *dialog,
666 gboolean details_failed)
668 GtkPrintUnixDialogPrivate *priv = dialog->priv;
670 if (priv->request_details_tag)
672 g_signal_handler_disconnect (priv->request_details_printer,
673 priv->request_details_tag);
674 priv->request_details_tag = 0;
675 set_busy_cursor (dialog, FALSE);
677 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
678 g_object_get_data (G_OBJECT (priv->request_details_printer),
679 "gtk-print-tree-iter"),
680 PRINTER_LIST_COL_STATE,
681 _("Getting printer information failed"),
684 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
685 g_object_get_data (G_OBJECT (priv->request_details_printer),
686 "gtk-print-tree-iter"),
687 PRINTER_LIST_COL_STATE,
688 gtk_printer_get_state_message (priv->request_details_printer),
690 g_object_unref (priv->request_details_printer);
691 priv->request_details_printer = NULL;
696 gtk_print_unix_dialog_finalize (GObject *object)
698 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
699 GtkPrintUnixDialogPrivate *priv = dialog->priv;
700 GtkPrintBackend *backend;
703 unschedule_idle_mark_conflicts (dialog);
704 disconnect_printer_details_request (dialog, FALSE);
706 g_clear_object (&priv->current_printer);
707 g_clear_object (&priv->printer_list);
708 g_clear_object (&priv->custom_paper_list);
709 g_clear_object (&priv->printer_list_filter);
710 g_clear_object (&priv->options);
712 if (priv->number_up_layout_2_option)
714 priv->number_up_layout_2_option->choices[0] = NULL;
715 priv->number_up_layout_2_option->choices[1] = NULL;
716 g_free (priv->number_up_layout_2_option->choices_display[0]);
717 g_free (priv->number_up_layout_2_option->choices_display[1]);
718 priv->number_up_layout_2_option->choices_display[0] = NULL;
719 priv->number_up_layout_2_option->choices_display[1] = NULL;
720 g_object_unref (priv->number_up_layout_2_option);
721 priv->number_up_layout_2_option = NULL;
724 g_clear_object (&priv->number_up_layout_n_option);
725 g_clear_object (&priv->page_setup);
726 g_clear_object (&priv->initial_settings);
727 g_clear_pointer (&priv->waiting_for_printer, (GDestroyNotify)g_free);
728 g_clear_pointer (&priv->format_for_printer, (GDestroyNotify)g_free);
730 for (node = priv->print_backends; node != NULL; node = node->next)
732 backend = GTK_PRINT_BACKEND (node->data);
734 g_signal_handlers_disconnect_by_func (backend, printer_added_cb, dialog);
735 g_signal_handlers_disconnect_by_func (backend, printer_removed_cb, dialog);
736 g_signal_handlers_disconnect_by_func (backend, printer_status_cb, dialog);
738 gtk_print_backend_destroy (backend);
739 g_object_unref (backend);
742 g_list_free (priv->print_backends);
743 priv->print_backends = NULL;
745 g_clear_object (&priv->page_setup_list);
747 G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->finalize (object);
751 printer_removed_cb (GtkPrintBackend *backend,
753 GtkPrintUnixDialog *dialog)
755 GtkPrintUnixDialogPrivate *priv = dialog->priv;
758 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
759 gtk_list_store_remove (GTK_LIST_STORE (priv->printer_list), iter);
763 gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface)
765 parent_buildable_iface = g_type_interface_peek_parent (iface);
767 iface->get_internal_child = gtk_print_unix_dialog_buildable_get_internal_child;
771 gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
773 const gchar *childname)
775 if (strcmp (childname, "notebook") == 0)
776 return G_OBJECT (GTK_PRINT_UNIX_DIALOG (buildable)->priv->notebook);
778 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
781 /* This function controls "sensitive" property of GtkCellRenderer
782 * based on pause state of printers.
784 void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
785 GtkCellRenderer *cell,
786 GtkTreeModel *tree_model,
792 gtk_tree_model_get (tree_model, iter,
793 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
796 if (printer != NULL && !gtk_printer_is_accepting_jobs (printer))
797 g_object_set (cell, "sensitive", FALSE, NULL);
799 g_object_set (cell, "sensitive", TRUE, NULL);
801 g_object_unref (printer);
805 printer_status_cb (GtkPrintBackend *backend,
807 GtkPrintUnixDialog *dialog)
809 GtkPrintUnixDialogPrivate *priv = dialog->priv;
811 GtkTreeSelection *selection;
813 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
815 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), iter,
816 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
817 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
818 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
819 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
822 /* When the pause state change then we need to update sensitive property
823 * of GTK_RESPONSE_OK button inside of selected_printer_changed function.
825 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
826 selected_printer_changed (selection, dialog);
828 if (gtk_print_backend_printer_list_is_done (backend) &&
829 gtk_printer_is_default (printer) &&
830 (gtk_tree_selection_count_selected_rows (selection) == 0))
831 set_active_printer (dialog, gtk_printer_get_name (printer));
835 printer_added_cb (GtkPrintBackend *backend,
837 GtkPrintUnixDialog *dialog)
839 GtkPrintUnixDialogPrivate *priv = dialog->priv;
840 GtkTreeIter iter, filter_iter;
841 GtkTreeSelection *selection;
844 gtk_list_store_append (GTK_LIST_STORE (priv->printer_list), &iter);
846 g_object_set_data_full (G_OBJECT (printer),
847 "gtk-print-tree-iter",
848 gtk_tree_iter_copy (&iter),
849 (GDestroyNotify) gtk_tree_iter_free);
851 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), &iter,
852 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
853 PRINTER_LIST_COL_NAME, gtk_printer_get_name (printer),
854 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
855 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
856 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
857 PRINTER_LIST_COL_PRINTER_OBJ, printer,
860 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
861 &filter_iter, &iter);
862 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->printer_list_filter), &filter_iter);
864 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
866 if (priv->waiting_for_printer != NULL &&
867 strcmp (gtk_printer_get_name (printer), priv->waiting_for_printer) == 0)
869 priv->internal_printer_change = TRUE;
870 gtk_tree_selection_select_iter (selection, &filter_iter);
871 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
872 path, NULL, TRUE, 0.5, 0.0);
873 priv->internal_printer_change = FALSE;
874 g_free (priv->waiting_for_printer);
875 priv->waiting_for_printer = NULL;
877 else if (is_default_printer (dialog, printer) &&
878 gtk_tree_selection_count_selected_rows (selection) == 0)
880 priv->internal_printer_change = TRUE;
881 gtk_tree_selection_select_iter (selection, &filter_iter);
882 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
883 path, NULL, TRUE, 0.5, 0.0);
884 priv->internal_printer_change = FALSE;
887 gtk_tree_path_free (path);
891 printer_list_initialize (GtkPrintUnixDialog *dialog,
892 GtkPrintBackend *print_backend)
897 g_return_if_fail (print_backend != NULL);
899 g_signal_connect_object (print_backend, "printer-added",
900 (GCallback) printer_added_cb, G_OBJECT (dialog), 0);
902 g_signal_connect_object (print_backend, "printer-removed",
903 (GCallback) printer_removed_cb, G_OBJECT (dialog), 0);
905 g_signal_connect_object (print_backend, "printer-status-changed",
906 (GCallback) printer_status_cb, G_OBJECT (dialog), 0);
908 list = gtk_print_backend_get_printer_list (print_backend);
913 printer_added_cb (print_backend, node->data, dialog);
921 load_print_backends (GtkPrintUnixDialog *dialog)
923 GtkPrintUnixDialogPrivate *priv = dialog->priv;
926 if (g_module_supported ())
927 priv->print_backends = gtk_print_backend_load_modules ();
929 for (node = priv->print_backends; node != NULL; node = node->next)
931 GtkPrintBackend *backend = node->data;
932 printer_list_initialize (dialog, backend);
937 gtk_print_unix_dialog_set_property (GObject *object,
943 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
947 case PROP_PAGE_SETUP:
948 gtk_print_unix_dialog_set_page_setup (dialog, g_value_get_object (value));
950 case PROP_CURRENT_PAGE:
951 gtk_print_unix_dialog_set_current_page (dialog, g_value_get_int (value));
953 case PROP_PRINT_SETTINGS:
954 gtk_print_unix_dialog_set_settings (dialog, g_value_get_object (value));
956 case PROP_MANUAL_CAPABILITIES:
957 gtk_print_unix_dialog_set_manual_capabilities (dialog, g_value_get_flags (value));
959 case PROP_SUPPORT_SELECTION:
960 gtk_print_unix_dialog_set_support_selection (dialog, g_value_get_boolean (value));
962 case PROP_HAS_SELECTION:
963 gtk_print_unix_dialog_set_has_selection (dialog, g_value_get_boolean (value));
965 case PROP_EMBED_PAGE_SETUP:
966 gtk_print_unix_dialog_set_embed_page_setup (dialog, g_value_get_boolean (value));
969 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
975 gtk_print_unix_dialog_get_property (GObject *object,
980 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
981 GtkPrintUnixDialogPrivate *priv = dialog->priv;
985 case PROP_PAGE_SETUP:
986 g_value_set_object (value, priv->page_setup);
988 case PROP_CURRENT_PAGE:
989 g_value_set_int (value, priv->current_page);
991 case PROP_PRINT_SETTINGS:
992 g_value_take_object (value, gtk_print_unix_dialog_get_settings (dialog));
994 case PROP_SELECTED_PRINTER:
995 g_value_set_object (value, priv->current_printer);
997 case PROP_MANUAL_CAPABILITIES:
998 g_value_set_flags (value, priv->manual_capabilities);
1000 case PROP_SUPPORT_SELECTION:
1001 g_value_set_boolean (value, priv->support_selection);
1003 case PROP_HAS_SELECTION:
1004 g_value_set_boolean (value, priv->has_selection);
1006 case PROP_EMBED_PAGE_SETUP:
1007 g_value_set_boolean (value, priv->embed_page_setup);
1010 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1016 is_printer_active (GtkTreeModel *model,
1018 GtkPrintUnixDialog *dialog)
1021 GtkPrinter *printer;
1022 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1024 gtk_tree_model_get (model, iter,
1025 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1028 if (printer == NULL)
1031 result = gtk_printer_is_active (printer);
1034 priv->manual_capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF |
1035 GTK_PRINT_CAPABILITY_GENERATE_PS))
1037 /* Check that the printer can handle at least one of the data
1038 * formats that the application supports.
1040 result = ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF) &&
1041 gtk_printer_accepts_pdf (printer)) ||
1042 ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS) &&
1043 gtk_printer_accepts_ps (printer));
1046 g_object_unref (printer);
1052 default_printer_list_sort_func (GtkTreeModel *model,
1059 GtkPrinter *a_printer;
1060 GtkPrinter *b_printer;
1063 gtk_tree_model_get (model, a,
1064 PRINTER_LIST_COL_NAME, &a_name,
1065 PRINTER_LIST_COL_PRINTER_OBJ, &a_printer,
1067 gtk_tree_model_get (model, b,
1068 PRINTER_LIST_COL_NAME, &b_name,
1069 PRINTER_LIST_COL_PRINTER_OBJ, &b_printer,
1072 if (a_printer == NULL && b_printer == NULL)
1074 else if (a_printer == NULL)
1076 else if (b_printer == NULL)
1078 else if (gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
1080 else if (gtk_printer_is_virtual (a_printer) && !gtk_printer_is_virtual (b_printer))
1082 else if (!gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
1084 else if (a_name == NULL && b_name == NULL)
1086 else if (a_name == NULL && b_name != NULL)
1088 else if (a_name != NULL && b_name == NULL)
1091 result = g_ascii_strcasecmp (a_name, b_name);
1096 g_object_unref (a_printer);
1098 g_object_unref (b_printer);
1104 create_printer_list_model (GtkPrintUnixDialog *dialog)
1106 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1107 GtkListStore *model;
1108 GtkTreeSortable *sort;
1110 model = gtk_list_store_new (PRINTER_LIST_N_COLS,
1118 priv->printer_list = (GtkTreeModel *)model;
1119 priv->printer_list_filter = (GtkTreeModelFilter *) gtk_tree_model_filter_new ((GtkTreeModel *)model,
1122 gtk_tree_model_filter_set_visible_func (priv->printer_list_filter,
1123 (GtkTreeModelFilterVisibleFunc) is_printer_active,
1127 sort = GTK_TREE_SORTABLE (model);
1128 gtk_tree_sortable_set_default_sort_func (sort,
1129 default_printer_list_sort_func,
1133 gtk_tree_sortable_set_sort_column_id (sort,
1134 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
1135 GTK_SORT_ASCENDING);
1141 wrap_in_frame (const gchar *label,
1144 GtkWidget *frame, *label_widget;
1147 label_widget = gtk_label_new (NULL);
1148 gtk_widget_set_halign (label_widget, GTK_ALIGN_START);
1149 gtk_widget_set_valign (label_widget, GTK_ALIGN_CENTER);
1150 gtk_widget_show (label_widget);
1152 bold_text = g_markup_printf_escaped ("<b>%s</b>", label);
1153 gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
1156 frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
1157 gtk_box_pack_start (GTK_BOX (frame), label_widget, FALSE, FALSE, 0);
1159 gtk_widget_set_margin_left (child, 12);
1160 gtk_widget_set_halign (child, GTK_ALIGN_FILL);
1161 gtk_widget_set_valign (child, GTK_ALIGN_FILL);
1163 gtk_box_pack_start (GTK_BOX (frame), child, FALSE, FALSE, 0);
1165 gtk_widget_show (frame);
1171 setup_option (GtkPrintUnixDialog *dialog,
1172 const gchar *option_name,
1173 GtkPrinterOptionWidget *widget)
1175 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1176 GtkPrinterOption *option;
1178 option = gtk_printer_option_set_lookup (priv->options, option_name);
1179 gtk_printer_option_widget_set_source (widget, option);
1181 return option != NULL;
1185 add_option_to_extension_point (GtkPrinterOption *option,
1188 GtkWidget *extension_point = data;
1191 widget = gtk_printer_option_widget_new (option);
1192 gtk_widget_show (widget);
1194 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1196 GtkWidget *label, *hbox;
1198 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1199 gtk_widget_show (label);
1200 gtk_widget_set_halign (label, GTK_ALIGN_START);
1201 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1202 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1204 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
1205 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1206 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1207 gtk_widget_show (hbox);
1209 gtk_box_pack_start (GTK_BOX (extension_point), hbox, TRUE, TRUE, 0);
1212 gtk_box_pack_start (GTK_BOX (extension_point), widget, TRUE, TRUE, 0);
1216 grid_rows (GtkGrid *table)
1219 GList *children, *c;
1221 children = gtk_container_get_children (GTK_CONTAINER (table));
1223 for (c = children; c; c = c->next)
1225 gtk_container_child_get (GTK_CONTAINER (table), c->data,
1242 g_list_free (children);
1248 add_option_to_table (GtkPrinterOption *option,
1252 GtkWidget *label, *widget;
1255 table = GTK_GRID (user_data);
1257 if (g_str_has_prefix (option->name, "gtk-"))
1260 row = grid_rows (table);
1262 widget = gtk_printer_option_widget_new (option);
1263 gtk_widget_show (widget);
1265 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1267 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1268 gtk_widget_show (label);
1270 gtk_widget_set_halign (label, GTK_ALIGN_START);
1271 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1272 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1274 gtk_grid_attach (table, label, 0, row - 1, 1, 1);
1275 gtk_grid_attach (table, widget, 1, row - 1, 1, 1);
1278 gtk_grid_attach (table, widget, 0, row - 1, 2, 1);
1282 setup_page_table (GtkPrinterOptionSet *options,
1289 gtk_printer_option_set_foreach_in_group (options, group,
1290 add_option_to_table,
1293 nrows = grid_rows (GTK_GRID (table));
1295 gtk_widget_hide (page);
1297 gtk_widget_show (page);
1301 update_print_at_option (GtkPrintUnixDialog *dialog)
1303 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1304 GtkPrinterOption *option;
1306 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1311 if (priv->updating_print_at)
1314 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_at_radio)))
1315 gtk_printer_option_set (option, "at");
1316 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio)))
1317 gtk_printer_option_set (option, "on-hold");
1319 gtk_printer_option_set (option, "now");
1321 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1326 text = gtk_entry_get_text (GTK_ENTRY (priv->print_at_entry));
1327 gtk_printer_option_set (option, text);
1333 setup_print_at (GtkPrintUnixDialog *dialog)
1335 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1336 GtkPrinterOption *option;
1338 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1342 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1344 gtk_widget_set_sensitive (priv->print_at_radio, FALSE);
1345 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1346 gtk_widget_set_sensitive (priv->print_hold_radio, FALSE);
1347 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), "");
1351 priv->updating_print_at = TRUE;
1353 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1354 gtk_widget_set_sensitive (priv->print_at_radio,
1355 gtk_printer_option_has_choice (option, "at"));
1357 gtk_widget_set_sensitive (priv->print_hold_radio,
1358 gtk_printer_option_has_choice (option, "on-hold"));
1360 update_print_at_option (dialog);
1362 if (strcmp (option->value, "at") == 0)
1363 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_at_radio),
1365 else if (strcmp (option->value, "on-hold") == 0)
1366 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio),
1369 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1372 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1374 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), option->value);
1376 priv->updating_print_at = FALSE;
1382 update_dialog_from_settings (GtkPrintUnixDialog *dialog)
1384 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1387 GtkWidget *table, *frame;
1388 gboolean has_advanced, has_job;
1392 if (priv->current_printer == NULL)
1394 clear_per_printer_ui (dialog);
1395 gtk_widget_hide (priv->job_page);
1396 gtk_widget_hide (priv->advanced_page);
1397 gtk_widget_hide (priv->image_quality_page);
1398 gtk_widget_hide (priv->finishing_page);
1399 gtk_widget_hide (priv->color_page);
1400 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1405 setup_option (dialog, "gtk-n-up", priv->pages_per_sheet);
1406 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
1407 setup_option (dialog, "gtk-duplex", priv->duplex);
1408 setup_option (dialog, "gtk-paper-type", priv->paper_type);
1409 setup_option (dialog, "gtk-paper-source", priv->paper_source);
1410 setup_option (dialog, "gtk-output-tray", priv->output_tray);
1413 has_job |= setup_option (dialog, "gtk-job-prio", priv->job_prio);
1414 has_job |= setup_option (dialog, "gtk-billing-info", priv->billing_info);
1415 has_job |= setup_option (dialog, "gtk-cover-before", priv->cover_before);
1416 has_job |= setup_option (dialog, "gtk-cover-after", priv->cover_after);
1417 has_job |= setup_print_at (dialog);
1420 gtk_widget_show (priv->job_page);
1422 gtk_widget_hide (priv->job_page);
1424 setup_page_table (priv->options,
1426 priv->image_quality_table,
1427 priv->image_quality_page);
1429 setup_page_table (priv->options,
1431 priv->finishing_table,
1432 priv->finishing_page);
1434 setup_page_table (priv->options,
1439 gtk_printer_option_set_foreach_in_group (priv->options,
1440 "GtkPrintDialogExtension",
1441 add_option_to_extension_point,
1442 priv->extension_point);
1444 /* A bit of a hack, keep the last option flush right.
1445 * This keeps the file format radios from moving as the
1448 children = gtk_container_get_children (GTK_CONTAINER (priv->extension_point));
1449 l = g_list_last (children);
1450 if (l && l != children)
1451 gtk_widget_set_halign (GTK_WIDGET (l->data), GTK_ALIGN_END);
1452 g_list_free (children);
1454 /* Put the rest of the groups in the advanced page */
1455 groups = gtk_printer_option_set_get_groups (priv->options);
1457 has_advanced = FALSE;
1458 for (l = groups; l != NULL; l = l->next)
1465 if (strcmp (group, "ImageQualityPage") == 0 ||
1466 strcmp (group, "ColorPage") == 0 ||
1467 strcmp (group, "FinishingPage") == 0 ||
1468 strcmp (group, "GtkPrintDialogExtension") == 0)
1471 table = gtk_grid_new ();
1472 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
1473 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
1475 gtk_printer_option_set_foreach_in_group (priv->options,
1477 add_option_to_table,
1480 nrows = grid_rows (GTK_GRID (table));
1482 gtk_widget_destroy (table);
1485 has_advanced = TRUE;
1486 frame = wrap_in_frame (group, table);
1487 gtk_widget_show (table);
1488 gtk_widget_show (frame);
1490 gtk_box_pack_start (GTK_BOX (priv->advanced_vbox),
1491 frame, FALSE, FALSE, 0);
1496 gtk_widget_show (priv->advanced_page);
1498 gtk_widget_hide (priv->advanced_page);
1500 g_list_free_full (groups, g_free);
1504 update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
1506 GtkPrintCapabilities caps;
1507 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1508 gboolean can_collate;
1509 const gchar *copies;
1511 copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin));
1512 can_collate = (*copies != '\0' && atoi (copies) > 1);
1514 caps = priv->manual_capabilities | priv->printer_capabilities;
1516 gtk_widget_set_sensitive (priv->page_set_combo,
1517 caps & GTK_PRINT_CAPABILITY_PAGE_SET);
1518 gtk_widget_set_sensitive (priv->copies_spin,
1519 caps & GTK_PRINT_CAPABILITY_COPIES);
1520 gtk_widget_set_sensitive (priv->collate_check,
1522 (caps & GTK_PRINT_CAPABILITY_COLLATE));
1523 gtk_widget_set_sensitive (priv->reverse_check,
1524 caps & GTK_PRINT_CAPABILITY_REVERSE);
1525 gtk_widget_set_sensitive (priv->scale_spin,
1526 caps & GTK_PRINT_CAPABILITY_SCALE);
1527 gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet),
1528 caps & GTK_PRINT_CAPABILITY_NUMBER_UP);
1530 if (caps & GTK_PRINT_CAPABILITY_PREVIEW)
1531 gtk_widget_show (priv->preview_button);
1533 gtk_widget_hide (priv->preview_button);
1535 update_collate_icon (NULL, dialog);
1537 gtk_tree_model_filter_refilter (priv->printer_list_filter);
1541 page_setup_is_equal (GtkPageSetup *a,
1545 gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
1546 gtk_page_setup_get_paper_size (b)) &&
1547 gtk_page_setup_get_top_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_top_margin (b, GTK_UNIT_MM) &&
1548 gtk_page_setup_get_bottom_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_bottom_margin (b, GTK_UNIT_MM) &&
1549 gtk_page_setup_get_left_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_left_margin (b, GTK_UNIT_MM) &&
1550 gtk_page_setup_get_right_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_right_margin (b, GTK_UNIT_MM);
1554 page_setup_is_same_size (GtkPageSetup *a,
1557 return gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
1558 gtk_page_setup_get_paper_size (b));
1562 set_paper_size (GtkPrintUnixDialog *dialog,
1563 GtkPageSetup *page_setup,
1567 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1568 GtkTreeModel *model;
1570 GtkPageSetup *list_page_setup;
1572 if (!priv->internal_page_setup_change)
1575 if (page_setup == NULL)
1578 model = GTK_TREE_MODEL (priv->page_setup_list);
1580 if (gtk_tree_model_get_iter_first (model, &iter))
1584 gtk_tree_model_get (GTK_TREE_MODEL (priv->page_setup_list), &iter,
1585 PAGE_SETUP_LIST_COL_PAGE_SETUP, &list_page_setup,
1587 if (list_page_setup == NULL)
1590 if ((size_only && page_setup_is_same_size (page_setup, list_page_setup)) ||
1591 (!size_only && page_setup_is_equal (page_setup, list_page_setup)))
1593 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->paper_size_combo),
1595 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->orientation_combo),
1596 gtk_page_setup_get_orientation (page_setup));
1597 g_object_unref (list_page_setup);
1601 g_object_unref (list_page_setup);
1603 } while (gtk_tree_model_iter_next (model, &iter));
1608 gtk_list_store_append (priv->page_setup_list, &iter);
1609 gtk_list_store_set (priv->page_setup_list, &iter,
1610 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1612 gtk_list_store_append (priv->page_setup_list, &iter);
1613 gtk_list_store_set (priv->page_setup_list, &iter,
1614 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1616 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->paper_size_combo),
1618 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->orientation_combo),
1619 gtk_page_setup_get_orientation (page_setup));
1627 fill_custom_paper_sizes (GtkPrintUnixDialog *dialog)
1629 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1630 GtkTreeIter iter, paper_iter;
1631 GtkTreeModel *model;
1633 model = GTK_TREE_MODEL (priv->custom_paper_list);
1634 if (gtk_tree_model_get_iter_first (model, &iter))
1636 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1637 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1638 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1642 GtkPageSetup *page_setup;
1643 gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
1645 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1646 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1647 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1650 g_object_unref (page_setup);
1651 } while (gtk_tree_model_iter_next (model, &iter));
1654 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1655 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1656 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1658 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1659 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1660 PAGE_SETUP_LIST_COL_PAGE_SETUP, NULL,
1665 fill_paper_sizes (GtkPrintUnixDialog *dialog,
1666 GtkPrinter *printer)
1668 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1670 GtkPageSetup *page_setup;
1671 GtkPaperSize *paper_size;
1675 gtk_list_store_clear (priv->page_setup_list);
1677 if (printer == NULL || (list = gtk_printer_list_papers (printer)) == NULL)
1679 for (i = 0; i < G_N_ELEMENTS (common_paper_sizes); i++)
1681 page_setup = gtk_page_setup_new ();
1682 paper_size = gtk_paper_size_new (common_paper_sizes[i]);
1683 gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size);
1684 gtk_paper_size_free (paper_size);
1686 gtk_list_store_append (priv->page_setup_list, &iter);
1687 gtk_list_store_set (priv->page_setup_list, &iter,
1688 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1690 g_object_unref (page_setup);
1695 for (l = list; l != NULL; l = l->next)
1697 page_setup = l->data;
1698 gtk_list_store_append (priv->page_setup_list, &iter);
1699 gtk_list_store_set (priv->page_setup_list, &iter,
1700 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1702 g_object_unref (page_setup);
1707 fill_custom_paper_sizes (dialog);
1711 update_paper_sizes (GtkPrintUnixDialog *dialog)
1713 GtkPageSetup *current_page_setup = NULL;
1714 GtkPrinter *printer;
1716 printer = gtk_print_unix_dialog_get_selected_printer (dialog);
1718 fill_paper_sizes (dialog, printer);
1720 current_page_setup = gtk_page_setup_copy (gtk_print_unix_dialog_get_page_setup (dialog));
1722 if (current_page_setup)
1724 if (!set_paper_size (dialog, current_page_setup, FALSE, FALSE))
1725 set_paper_size (dialog, current_page_setup, TRUE, TRUE);
1727 g_object_unref (current_page_setup);
1732 mark_conflicts (GtkPrintUnixDialog *dialog)
1734 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1735 GtkPrinter *printer;
1736 gboolean have_conflict;
1738 have_conflict = FALSE;
1740 printer = priv->current_printer;
1745 g_signal_handler_block (priv->options,
1746 priv->options_changed_handler);
1748 gtk_printer_option_set_clear_conflicts (priv->options);
1750 have_conflict = _gtk_printer_mark_conflicts (printer,
1753 g_signal_handler_unblock (priv->options,
1754 priv->options_changed_handler);
1758 gtk_widget_show (priv->conflicts_widget);
1760 gtk_widget_hide (priv->conflicts_widget);
1764 mark_conflicts_callback (gpointer data)
1766 GtkPrintUnixDialog *dialog = data;
1767 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1769 priv->mark_conflicts_id = 0;
1771 mark_conflicts (dialog);
1777 unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1779 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1781 if (priv->mark_conflicts_id != 0)
1783 g_source_remove (priv->mark_conflicts_id);
1784 priv->mark_conflicts_id = 0;
1789 schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1791 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1793 if (priv->mark_conflicts_id != 0)
1796 priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
1801 options_changed_cb (GtkPrintUnixDialog *dialog)
1803 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1805 schedule_idle_mark_conflicts (dialog);
1807 g_free (priv->waiting_for_printer);
1808 priv->waiting_for_printer = NULL;
1812 remove_custom_widget (GtkWidget *widget,
1813 GtkContainer *container)
1815 gtk_container_remove (container, widget);
1819 extension_point_clear_children (GtkContainer *container)
1821 gtk_container_foreach (container,
1822 (GtkCallback)remove_custom_widget,
1827 clear_per_printer_ui (GtkPrintUnixDialog *dialog)
1829 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1831 gtk_container_foreach (GTK_CONTAINER (priv->finishing_table),
1832 (GtkCallback)gtk_widget_destroy, NULL);
1833 gtk_container_foreach (GTK_CONTAINER (priv->image_quality_table),
1834 (GtkCallback)gtk_widget_destroy, NULL);
1835 gtk_container_foreach (GTK_CONTAINER (priv->color_table),
1836 (GtkCallback)gtk_widget_destroy, NULL);
1837 gtk_container_foreach (GTK_CONTAINER (priv->advanced_vbox),
1838 (GtkCallback)gtk_widget_destroy, NULL);
1839 extension_point_clear_children (GTK_CONTAINER (priv->extension_point));
1843 printer_details_acquired (GtkPrinter *printer,
1845 GtkPrintUnixDialog *dialog)
1847 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1849 disconnect_printer_details_request (dialog, !success);
1853 GtkTreeSelection *selection;
1854 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
1856 selected_printer_changed (selection, dialog);
1861 selected_printer_changed (GtkTreeSelection *selection,
1862 GtkPrintUnixDialog *dialog)
1864 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1865 GtkPrinter *printer;
1866 GtkTreeIter iter, filter_iter;
1868 /* Whenever the user selects a printer we stop looking for
1869 * the printer specified in the initial settings
1871 if (priv->waiting_for_printer &&
1872 !priv->internal_printer_change)
1874 g_free (priv->waiting_for_printer);
1875 priv->waiting_for_printer = NULL;
1878 disconnect_printer_details_request (dialog, FALSE);
1881 if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
1883 gtk_tree_model_filter_convert_iter_to_child_iter (priv->printer_list_filter,
1887 gtk_tree_model_get (priv->printer_list, &iter,
1888 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1892 /* sets GTK_RESPONSE_OK button sensitivity depending on whether the printer
1893 * accepts/rejects jobs
1895 if (printer != NULL)
1897 if (!gtk_printer_is_accepting_jobs (printer))
1898 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1899 else if (priv->current_printer == printer && gtk_printer_has_details (printer))
1901 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1904 if (printer != NULL && !gtk_printer_has_details (printer))
1906 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1907 priv->request_details_tag =
1908 g_signal_connect (printer, "details-acquired",
1909 G_CALLBACK (printer_details_acquired), dialog);
1910 /* take the reference */
1911 priv->request_details_printer = printer;
1912 gtk_printer_request_details (printer);
1913 set_busy_cursor (dialog, TRUE);
1914 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
1915 g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter"),
1916 PRINTER_LIST_COL_STATE, _("Getting printer information…"),
1921 if (printer == priv->current_printer)
1924 g_object_unref (printer);
1930 g_clear_object (&priv->options);
1931 clear_per_printer_ui (dialog);
1934 g_clear_object (&priv->current_printer);
1935 priv->printer_capabilities = 0;
1937 if (printer != NULL && gtk_printer_is_accepting_jobs (printer))
1938 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1939 priv->current_printer = printer;
1941 if (printer != NULL)
1943 if (!priv->page_setup_set)
1945 /* if no explicit page setup has been set, use the printer default */
1946 GtkPageSetup *page_setup;
1948 page_setup = gtk_printer_get_default_page_size (printer);
1951 page_setup = gtk_page_setup_new ();
1953 if (page_setup && priv->page_setup)
1954 gtk_page_setup_set_orientation (page_setup, gtk_page_setup_get_orientation (priv->page_setup));
1956 g_object_unref (priv->page_setup);
1957 priv->page_setup = page_setup;
1960 priv->printer_capabilities = gtk_printer_get_capabilities (printer);
1961 priv->options = _gtk_printer_get_options (printer,
1962 priv->initial_settings,
1964 priv->manual_capabilities);
1966 priv->options_changed_handler =
1967 g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
1968 schedule_idle_mark_conflicts (dialog);
1971 update_dialog_from_settings (dialog);
1972 update_dialog_from_capabilities (dialog);
1974 priv->internal_page_setup_change = TRUE;
1975 update_paper_sizes (dialog);
1976 priv->internal_page_setup_change = FALSE;
1978 g_object_notify ( G_OBJECT(dialog), "selected-printer");
1982 update_collate_icon (GtkToggleButton *toggle_button,
1983 GtkPrintUnixDialog *dialog)
1985 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1987 gtk_widget_queue_draw (priv->collate_image);
1991 paint_page (GtkWidget *widget,
1999 GtkStyleContext *context;
2000 gint x, y, width, height;
2001 gint text_y, linewidth;
2004 x = x_offset * scale;
2005 y = y_offset * scale;
2007 height = 26 * scale;
2012 context = gtk_widget_get_style_context (widget);
2014 gtk_style_context_save (context);
2015 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
2017 gtk_style_context_get_background_color (context, 0, &color);
2018 gdk_cairo_set_source_rgba (cr, &color);
2019 cairo_rectangle (cr, x, y, width, height);
2022 gtk_style_context_get_color (context, 0, &color);
2023 gdk_cairo_set_source_rgba (cr, &color);
2024 cairo_set_line_width (cr, linewidth);
2025 cairo_rectangle (cr, x + linewidth/2.0, y + linewidth/2.0, width - linewidth, height - linewidth);
2028 cairo_select_font_face (cr, "Sans",
2029 CAIRO_FONT_SLANT_NORMAL,
2030 CAIRO_FONT_WEIGHT_NORMAL);
2031 cairo_set_font_size (cr, (gint)(9 * scale));
2032 cairo_move_to (cr, x + (gint)(text_x * scale), y + (gint)(text_y * scale));
2033 cairo_show_text (cr, text);
2035 gtk_style_context_restore (context);
2039 draw_collate_cb (GtkWidget *widget,
2041 GtkPrintUnixDialog *dialog)
2043 GtkSettings *settings;
2046 gboolean collate, reverse, rtl;
2050 collate = dialog_get_collate (dialog);
2051 reverse = dialog_get_reverse (dialog);
2052 copies = dialog_get_n_copies (dialog);
2054 rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL);
2056 settings = gtk_widget_get_settings (widget);
2057 gtk_icon_size_lookup_for_settings (settings,
2058 GTK_ICON_SIZE_DIALOG,
2061 scale = size / 48.0;
2062 text_x = rtl ? 4 : 11;
2066 paint_page (widget, cr, scale, rtl ? 40: 15, 5, reverse ? "1" : "2", text_x);
2067 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
2071 paint_page (widget, cr, scale, rtl ? 40: 15, 5, collate == reverse ? "1" : "2", text_x);
2072 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
2074 paint_page (widget, cr, scale, rtl ? 5 : 50, 5, reverse ? "1" : "2", text_x);
2075 paint_page (widget, cr, scale, rtl ? 15 : 40, 15, collate == reverse ? "2" : "1", text_x);
2082 gtk_print_unix_dialog_style_updated (GtkWidget *widget)
2084 GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_updated (widget);
2086 if (gtk_widget_has_screen (widget))
2088 GtkPrintUnixDialog *dialog = (GtkPrintUnixDialog *)widget;
2089 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2090 GtkSettings *settings;
2094 settings = gtk_widget_get_settings (widget);
2095 gtk_icon_size_lookup_for_settings (settings,
2096 GTK_ICON_SIZE_DIALOG,
2099 scale = size / 48.0;
2101 gtk_widget_set_size_request (priv->collate_image,
2108 update_entry_sensitivity (GtkWidget *button,
2113 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
2115 gtk_widget_set_sensitive (range, active);
2118 gtk_widget_grab_focus (range);
2122 emit_ok_response (GtkTreeView *tree_view,
2124 GtkTreeViewColumn *column,
2125 gpointer *user_data)
2127 GtkPrintUnixDialog *print_dialog;
2129 print_dialog = (GtkPrintUnixDialog *) user_data;
2131 gtk_dialog_response (GTK_DIALOG (print_dialog), GTK_RESPONSE_OK);
2135 create_main_page (GtkPrintUnixDialog *dialog)
2137 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2138 GtkWidget *main_vbox, *label, *vbox, *hbox;
2139 GtkWidget *scrolled, *treeview, *frame, *table;
2140 GtkWidget *entry, *spinbutton;
2141 GtkWidget *radio, *check, *image;
2142 GtkCellRenderer *renderer;
2143 GtkTreeViewColumn *column;
2144 GtkTreeSelection *selection;
2145 GtkWidget *custom_input;
2146 const gchar *range_tooltip;
2148 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
2149 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2150 gtk_widget_show (main_vbox);
2152 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
2153 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
2154 gtk_widget_show (vbox);
2156 scrolled = gtk_scrolled_window_new (NULL, NULL);
2157 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2158 GTK_POLICY_AUTOMATIC,
2159 GTK_POLICY_AUTOMATIC);
2160 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
2162 gtk_widget_show (scrolled);
2163 gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
2165 treeview = gtk_tree_view_new_with_model ((GtkTreeModel *) priv->printer_list_filter);
2166 priv->printer_treeview = treeview;
2167 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
2168 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), PRINTER_LIST_COL_NAME);
2169 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), TRUE);
2170 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
2171 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
2172 g_signal_connect (selection, "changed", G_CALLBACK (selected_printer_changed), dialog);
2174 renderer = gtk_cell_renderer_pixbuf_new ();
2175 column = gtk_tree_view_column_new_with_attributes ("",
2178 PRINTER_LIST_COL_ICON,
2180 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2181 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2183 renderer = gtk_cell_renderer_text_new ();
2184 column = gtk_tree_view_column_new_with_attributes (_("Printer"),
2187 PRINTER_LIST_COL_NAME,
2189 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2190 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2192 renderer = gtk_cell_renderer_text_new ();
2193 /* Translators: this is the header for the location column in the print dialog */
2194 column = gtk_tree_view_column_new_with_attributes (_("Location"),
2197 PRINTER_LIST_COL_LOCATION,
2199 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2200 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2202 renderer = gtk_cell_renderer_text_new ();
2203 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
2204 /* Translators: this is the header for the printer status column in the print dialog */
2205 column = gtk_tree_view_column_new_with_attributes (_("Status"),
2208 PRINTER_LIST_COL_STATE,
2210 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2211 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2213 g_signal_connect (GTK_TREE_VIEW (treeview), "row-activated", G_CALLBACK (emit_ok_response), dialog);
2215 gtk_widget_show (treeview);
2216 gtk_container_add (GTK_CONTAINER (scrolled), treeview);
2218 custom_input = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
2219 gtk_widget_show (custom_input);
2220 gtk_box_pack_start (GTK_BOX (vbox), custom_input, FALSE, FALSE, 0);
2221 priv->extension_point = custom_input;
2223 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
2224 gtk_widget_show (hbox);
2225 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
2227 table = gtk_grid_new ();
2228 priv->range_table = table;
2229 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
2230 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
2231 frame = wrap_in_frame (_("Range"), table);
2232 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2233 gtk_widget_show (table);
2235 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_All Pages"));
2236 priv->all_pages_radio = radio;
2237 gtk_widget_show (radio);
2238 gtk_grid_attach (GTK_GRID (table), radio, 0, 0, 2, 1);
2239 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2240 _("C_urrent Page"));
2241 if (priv->current_page == -1)
2242 gtk_widget_set_sensitive (radio, FALSE);
2243 priv->current_page_radio = radio;
2244 gtk_widget_show (radio);
2245 gtk_grid_attach (GTK_GRID (table), radio, 0, 1, 2, 1);
2247 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2250 gtk_widget_set_sensitive (radio, priv->has_selection);
2251 priv->selection_radio = radio;
2252 gtk_grid_attach (GTK_GRID (table), radio, 0, 2, 2, 1);
2254 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)), _("Pag_es:"));
2255 range_tooltip = _("Specify one or more page ranges,\n e.g. 1-3,7,11");
2256 gtk_widget_set_tooltip_text (radio, range_tooltip);
2258 priv->page_range_radio = radio;
2259 gtk_widget_show (radio);
2260 gtk_grid_attach (GTK_GRID (table), radio, 0, 3, 1, 1);
2261 entry = gtk_entry_new ();
2262 gtk_widget_set_tooltip_text (entry, range_tooltip);
2263 gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
2264 atk_object_set_name (gtk_widget_get_accessible (entry), _("Pages"));
2265 atk_object_set_description (gtk_widget_get_accessible (entry), range_tooltip);
2266 priv->page_range_entry = entry;
2267 gtk_widget_show (entry);
2268 gtk_grid_attach (GTK_GRID (table), entry, 1, 3, 1, 1);
2269 g_signal_connect (radio, "toggled", G_CALLBACK (update_entry_sensitivity), entry);
2270 update_entry_sensitivity (radio, entry);
2272 table = gtk_grid_new ();
2273 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
2274 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
2275 frame = wrap_in_frame (_("Copies"), table);
2276 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2277 gtk_widget_show (table);
2279 /* FIXME chpe: too much space between Copies and spinbutton, put those 2 in a hbox and make it span 2 columns */
2280 label = gtk_label_new_with_mnemonic (_("Copie_s:"));
2281 gtk_widget_set_halign (label, GTK_ALIGN_START);
2282 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
2283 gtk_widget_show (label);
2284 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
2285 spinbutton = gtk_spin_button_new_with_range (1.0, 100.0, 1.0);
2286 gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
2287 priv->copies_spin = spinbutton;
2288 gtk_widget_show (spinbutton);
2289 gtk_grid_attach (GTK_GRID (table), spinbutton, 1, 0, 1, 1);
2290 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
2291 g_signal_connect_swapped (spinbutton, "value-changed",
2292 G_CALLBACK (update_dialog_from_capabilities), dialog);
2293 g_signal_connect_swapped (spinbutton, "changed",
2294 G_CALLBACK (update_dialog_from_capabilities), dialog);
2296 check = gtk_check_button_new_with_mnemonic (_("C_ollate"));
2297 priv->collate_check = check;
2298 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
2299 gtk_widget_show (check);
2300 gtk_grid_attach (GTK_GRID (table), check, 0, 1, 1, 1);
2302 check = gtk_check_button_new_with_mnemonic (_("_Reverse"));
2303 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
2304 priv->reverse_check = check;
2305 gtk_widget_show (check);
2306 gtk_grid_attach (GTK_GRID (table), check, 0, 2, 1, 1);
2308 image = gtk_drawing_area_new ();
2309 gtk_widget_set_has_window (image, FALSE);
2311 priv->collate_image = image;
2312 gtk_widget_show (image);
2313 gtk_widget_set_size_request (image, 70, 90);
2314 gtk_grid_attach (GTK_GRID (table), image, 1, 1, 1, 2);
2315 g_signal_connect (image, "draw",
2316 G_CALLBACK (draw_collate_cb), dialog);
2318 label = gtk_label_new (_("General"));
2319 gtk_widget_show (label);
2321 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), main_vbox, label);
2325 is_range_separator (gchar c)
2327 return (c == ',' || c == ';' || c == ':');
2330 static GtkPageRange *
2331 dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
2334 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2336 const gchar *text, *p;
2338 GtkPageRange *ranges;
2341 text = gtk_entry_get_text (GTK_ENTRY (priv->page_range_entry));
2353 if (is_range_separator (*p))
2358 ranges = g_new0 (GtkPageRange, n_ranges);
2364 while (isspace (*p)) p++;
2368 /* a half-open range like -2 */
2373 start = (int)strtol (p, &next, 10);
2381 while (isspace (*p)) p++;
2386 end = (int)strtol (p, &next, 10);
2387 if (next == p) /* a half-open range like 2- */
2389 else if (end < start)
2393 ranges[i].start = start - 1;
2394 ranges[i].end = end - 1;
2397 /* Skip until end or separator */
2398 while (*p && !is_range_separator (*p))
2401 /* if not at end, skip separator */
2412 dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
2413 GtkPageRange *ranges,
2416 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2418 GString *s = g_string_new (NULL);
2420 for (i = 0; i < n_ranges; i++)
2422 g_string_append_printf (s, "%d", ranges[i].start + 1);
2423 if (ranges[i].end > ranges[i].start)
2424 g_string_append_printf (s, "-%d", ranges[i].end + 1);
2425 else if (ranges[i].end == -1)
2426 g_string_append (s, "-");
2428 if (i != n_ranges - 1)
2429 g_string_append (s, ",");
2432 gtk_entry_set_text (GTK_ENTRY (priv->page_range_entry), s->str);
2434 g_string_free (s, TRUE);
2437 static GtkPrintPages
2438 dialog_get_print_pages (GtkPrintUnixDialog *dialog)
2440 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2442 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio)))
2443 return GTK_PRINT_PAGES_ALL;
2444 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->current_page_radio)))
2445 return GTK_PRINT_PAGES_CURRENT;
2446 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->selection_radio)))
2447 return GTK_PRINT_PAGES_SELECTION;
2449 return GTK_PRINT_PAGES_RANGES;
2453 dialog_set_print_pages (GtkPrintUnixDialog *dialog,
2454 GtkPrintPages pages)
2456 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2458 if (pages == GTK_PRINT_PAGES_RANGES)
2459 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
2460 else if (pages == GTK_PRINT_PAGES_CURRENT)
2461 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->current_page_radio), TRUE);
2462 else if (pages == GTK_PRINT_PAGES_SELECTION)
2463 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->selection_radio), TRUE);
2465 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio), TRUE);
2469 dialog_get_scale (GtkPrintUnixDialog *dialog)
2471 if (gtk_widget_is_sensitive (dialog->priv->scale_spin))
2472 return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
2478 dialog_set_scale (GtkPrintUnixDialog *dialog,
2481 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin), val);
2485 dialog_get_page_set (GtkPrintUnixDialog *dialog)
2487 if (gtk_widget_is_sensitive (dialog->priv->page_set_combo))
2488 return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
2490 return GTK_PAGE_SET_ALL;
2494 dialog_set_page_set (GtkPrintUnixDialog *dialog,
2497 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->page_set_combo),
2502 dialog_get_n_copies (GtkPrintUnixDialog *dialog)
2504 if (gtk_widget_is_sensitive (dialog->priv->copies_spin))
2505 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
2510 dialog_set_n_copies (GtkPrintUnixDialog *dialog,
2513 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->copies_spin),
2518 dialog_get_collate (GtkPrintUnixDialog *dialog)
2520 if (gtk_widget_is_sensitive (dialog->priv->collate_check))
2521 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
2526 dialog_set_collate (GtkPrintUnixDialog *dialog,
2529 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check),
2534 dialog_get_reverse (GtkPrintUnixDialog *dialog)
2536 if (gtk_widget_is_sensitive (dialog->priv->reverse_check))
2537 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
2542 dialog_set_reverse (GtkPrintUnixDialog *dialog,
2545 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check),
2550 dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
2552 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2556 val = gtk_printer_option_widget_get_value (priv->pages_per_sheet);
2570 static GtkNumberUpLayout
2571 dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
2573 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2574 GtkPrintCapabilities caps;
2575 GtkNumberUpLayout layout;
2577 GEnumClass *enum_class;
2578 GEnumValue *enum_value;
2580 val = gtk_printer_option_widget_get_value (priv->number_up_layout);
2582 caps = priv->manual_capabilities | priv->printer_capabilities;
2584 if ((caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) == 0)
2585 return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2587 if (gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR)
2588 layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2590 layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
2595 if (val[0] == '\0' && priv->options)
2597 GtkPrinterOption *option = gtk_printer_option_set_lookup (priv->options, "gtk-n-up-layout");
2599 val = option->value;
2602 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
2603 enum_value = g_enum_get_value_by_nick (enum_class, val);
2605 layout = enum_value->value;
2606 g_type_class_unref (enum_class);
2612 draw_page_cb (GtkWidget *widget,
2614 GtkPrintUnixDialog *dialog)
2616 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2617 GtkStyleContext *context;
2619 gint w, h, tmp, shadow_offset;
2620 gint pages_x, pages_y, i, x, y, layout_w, layout_h;
2621 gdouble page_width, page_height;
2622 GtkPageOrientation orientation;
2624 PangoLayout *layout;
2625 PangoFontDescription *font;
2628 GtkNumberUpLayout number_up_layout;
2629 gint start_x, end_x, start_y, end_y;
2632 gboolean horizontal;
2633 GtkPageSetup *page_setup;
2634 gdouble paper_width, paper_height;
2635 gdouble pos_x, pos_y;
2636 gint pages_per_sheet;
2637 gboolean ltr = TRUE;
2639 orientation = gtk_page_setup_get_orientation (priv->page_setup);
2641 (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
2642 (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
2644 number_up_layout = dialog_get_number_up_layout (dialog);
2645 width = gtk_widget_get_allocated_width (widget);
2646 height = gtk_widget_get_allocated_height (widget);
2650 page_setup = gtk_print_unix_dialog_get_page_setup (dialog);
2652 if (page_setup != NULL)
2656 paper_width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
2657 paper_height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
2661 paper_width = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
2662 paper_height = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
2665 if (paper_width < paper_height)
2667 h = EXAMPLE_PAGE_AREA_SIZE - 3;
2668 w = (paper_height != 0) ? h * paper_width / paper_height : 0;
2672 w = EXAMPLE_PAGE_AREA_SIZE - 3;
2673 h = (paper_width != 0) ? w * paper_height / paper_width : 0;
2676 if (paper_width == 0)
2679 if (paper_height == 0)
2685 w = (EXAMPLE_PAGE_AREA_SIZE - 3) / ratio;
2686 h = EXAMPLE_PAGE_AREA_SIZE - 3;
2689 pages_per_sheet = dialog_get_pages_per_sheet (dialog);
2690 switch (pages_per_sheet)
2694 pages_x = 1; pages_y = 1;
2697 landscape = !landscape;
2698 pages_x = 1; pages_y = 2;
2701 pages_x = 2; pages_y = 2;
2704 landscape = !landscape;
2705 pages_x = 2; pages_y = 3;
2708 pages_x = 3; pages_y = 3;
2711 pages_x = 4; pages_y = 4;
2726 context = gtk_widget_get_style_context (widget);
2728 gtk_style_context_save (context);
2729 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
2731 pos_x = (width - w) / 2;
2732 pos_y = (height - h) / 2 - 10;
2733 cairo_translate (cr, pos_x, pos_y);
2737 gtk_style_context_get_color (context, 0, &color);
2738 cairo_set_source_rgba (cr, color.red, color.green, color.blue, 0.5);
2739 cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
2742 gtk_style_context_get_background_color (context, 0, &color);
2743 gdk_cairo_set_source_rgba (cr, &color);
2744 cairo_rectangle (cr, 1, 1, w, h);
2746 cairo_set_line_width (cr, 1.0);
2747 cairo_rectangle (cr, 0.5, 0.5, w + 1, h + 1);
2749 gtk_style_context_get_color (context, 0, &color);
2750 gdk_cairo_set_source_rgba (cr, &color);
2755 page_width = (gdouble)w / pages_x;
2756 page_height = (gdouble)h / pages_y;
2758 layout = pango_cairo_create_layout (cr);
2760 font = pango_font_description_new ();
2761 pango_font_description_set_family (font, "sans");
2763 if (page_height > 0)
2764 pango_font_description_set_absolute_size (font, page_height * 0.4 * PANGO_SCALE);
2766 pango_font_description_set_absolute_size (font, 1);
2768 pango_layout_set_font_description (layout, font);
2769 pango_font_description_free (font);
2771 pango_layout_set_width (layout, page_width * PANGO_SCALE);
2772 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2774 switch (number_up_layout)
2777 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
2779 end_x = pages_x - 1;
2781 end_y = pages_y - 1;
2786 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
2788 end_x = pages_x - 1;
2789 start_y = pages_y - 1;
2795 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
2796 start_x = pages_x - 1;
2799 end_y = pages_y - 1;
2804 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
2805 start_x = pages_x - 1;
2807 start_y = pages_y - 1;
2813 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
2815 end_x = pages_x - 1;
2817 end_y = pages_y - 1;
2822 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
2823 start_x = pages_x - 1;
2826 end_y = pages_y - 1;
2831 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
2833 end_x = pages_x - 1;
2834 start_y = pages_y - 1;
2840 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
2841 start_x = pages_x - 1;
2843 start_y = pages_y - 1;
2852 for (y = start_y; y != end_y + dy; y += dy)
2854 for (x = start_x; x != end_x + dx; x += dx)
2856 text = g_strdup_printf ("%d", i++);
2857 pango_layout_set_text (layout, text, -1);
2859 pango_layout_get_size (layout, &layout_w, &layout_h);
2861 cairo_translate (cr,
2863 y * page_height + (page_height - layout_h / 1024.0) / 2);
2865 pango_cairo_show_layout (cr, layout);
2870 for (x = start_x; x != end_x + dx; x += dx)
2872 for (y = start_y; y != end_y + dy; y += dy)
2874 text = g_strdup_printf ("%d", i++);
2875 pango_layout_set_text (layout, text, -1);
2877 pango_layout_get_size (layout, &layout_w, &layout_h);
2879 cairo_translate (cr,
2881 y * page_height + (page_height - layout_h / 1024.0) / 2);
2883 pango_cairo_show_layout (cr, layout);
2888 g_object_unref (layout);
2890 if (page_setup != NULL)
2895 if (pages_per_sheet == 2 || pages_per_sheet == 6)
2897 paper_width = gtk_page_setup_get_paper_height (page_setup, _gtk_print_get_default_user_units ());
2898 paper_height = gtk_page_setup_get_paper_width (page_setup, _gtk_print_get_default_user_units ());
2902 paper_width = gtk_page_setup_get_paper_width (page_setup, _gtk_print_get_default_user_units ());
2903 paper_height = gtk_page_setup_get_paper_height (page_setup, _gtk_print_get_default_user_units ());
2909 layout = pango_cairo_create_layout (cr);
2911 font = pango_font_description_new ();
2912 pango_font_description_set_family (font, "sans");
2914 PangoContext *pango_c = NULL;
2915 PangoFontDescription *pango_f = NULL;
2916 gint font_size = 12 * PANGO_SCALE;
2918 pango_c = gtk_widget_get_pango_context (widget);
2919 if (pango_c != NULL)
2921 pango_f = pango_context_get_font_description (pango_c);
2922 if (pango_f != NULL)
2923 font_size = pango_font_description_get_size (pango_f);
2926 pango_font_description_set_size (font, font_size);
2927 pango_layout_set_font_description (layout, font);
2928 pango_font_description_free (font);
2930 pango_layout_set_width (layout, -1);
2931 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2933 if (_gtk_print_get_default_user_units () == GTK_UNIT_MM)
2934 text = g_strdup_printf ("%.1f mm", paper_height);
2936 text = g_strdup_printf ("%.2f inch", paper_height);
2938 pango_layout_set_text (layout, text, -1);
2940 pango_layout_get_size (layout, &layout_w, &layout_h);
2942 ltr = gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR;
2945 cairo_translate (cr, pos_x - layout_w / PANGO_SCALE - 2 * RULER_DISTANCE,
2946 (height - layout_h / PANGO_SCALE) / 2);
2948 cairo_translate (cr, pos_x + w + shadow_offset + 2 * RULER_DISTANCE,
2949 (height - layout_h / PANGO_SCALE) / 2);
2951 pango_cairo_show_layout (cr, layout);
2956 if (_gtk_print_get_default_user_units () == GTK_UNIT_MM)
2957 text = g_strdup_printf ("%.1f mm", paper_width);
2959 text = g_strdup_printf ("%.2f inch", paper_width);
2961 pango_layout_set_text (layout, text, -1);
2963 pango_layout_get_size (layout, &layout_w, &layout_h);
2965 cairo_translate (cr, (width - layout_w / PANGO_SCALE) / 2,
2966 pos_y + h + shadow_offset + 2 * RULER_DISTANCE);
2968 pango_cairo_show_layout (cr, layout);
2970 g_object_unref (layout);
2974 cairo_set_line_width (cr, 1);
2978 cairo_move_to (cr, pos_x - RULER_DISTANCE, pos_y);
2979 cairo_line_to (cr, pos_x - RULER_DISTANCE, pos_y + h);
2982 cairo_move_to (cr, pos_x - RULER_DISTANCE - RULER_RADIUS, pos_y - 0.5);
2983 cairo_line_to (cr, pos_x - RULER_DISTANCE + RULER_RADIUS, pos_y - 0.5);
2986 cairo_move_to (cr, pos_x - RULER_DISTANCE - RULER_RADIUS, pos_y + h + 0.5);
2987 cairo_line_to (cr, pos_x - RULER_DISTANCE + RULER_RADIUS, pos_y + h + 0.5);
2992 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE, pos_y);
2993 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE, pos_y + h);
2996 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE - RULER_RADIUS, pos_y - 0.5);
2997 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE + RULER_RADIUS, pos_y - 0.5);
3000 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE - RULER_RADIUS, pos_y + h + 0.5);
3001 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE + RULER_RADIUS, pos_y + h + 0.5);
3005 cairo_move_to (cr, pos_x, pos_y + h + shadow_offset + RULER_DISTANCE);
3006 cairo_line_to (cr, pos_x + w, pos_y + h + shadow_offset + RULER_DISTANCE);
3009 cairo_move_to (cr, pos_x - 0.5, pos_y + h + shadow_offset + RULER_DISTANCE - RULER_RADIUS);
3010 cairo_line_to (cr, pos_x - 0.5, pos_y + h + shadow_offset + RULER_DISTANCE + RULER_RADIUS);
3013 cairo_move_to (cr, pos_x + w + 0.5, pos_y + h + shadow_offset + RULER_DISTANCE - RULER_RADIUS);
3014 cairo_line_to (cr, pos_x + w + 0.5, pos_y + h + shadow_offset + RULER_DISTANCE + RULER_RADIUS);
3018 gtk_style_context_restore (context);
3024 redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
3026 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3028 if (priv->page_layout_preview)
3029 gtk_widget_queue_draw (priv->page_layout_preview);
3033 update_number_up_layout (GtkPrintUnixDialog *dialog)
3035 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3036 GtkPrintCapabilities caps;
3037 GtkPrinterOptionSet *set;
3038 GtkNumberUpLayout layout;
3039 GtkPrinterOption *option;
3040 GtkPrinterOption *old_option;
3041 GtkPageOrientation page_orientation;
3043 set = priv->options;
3045 caps = priv->manual_capabilities | priv->printer_capabilities;
3047 if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
3049 if (priv->number_up_layout_n_option == NULL)
3051 priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
3052 if (priv->number_up_layout_n_option == NULL)
3054 char *n_up_layout[] = { "lrtb", "lrbt", "rltb", "rlbt", "tblr", "tbrl", "btlr", "btrl" };
3055 /* Translators: These strings name the possible arrangements of
3056 * multiple pages on a sheet when printing (same as in gtkprintbackendcups.c)
3058 char *n_up_layout_display[] = { N_("Left to right, top to bottom"), N_("Left to right, bottom to top"),
3059 N_("Right to left, top to bottom"), N_("Right to left, bottom to top"),
3060 N_("Top to bottom, left to right"), N_("Top to bottom, right to left"),
3061 N_("Bottom to top, left to right"), N_("Bottom to top, right to left") };
3064 priv->number_up_layout_n_option = gtk_printer_option_new ("gtk-n-up-layout",
3066 GTK_PRINTER_OPTION_TYPE_PICKONE);
3067 gtk_printer_option_allocate_choices (priv->number_up_layout_n_option, 8);
3069 for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
3071 priv->number_up_layout_n_option->choices[i] = g_strdup (n_up_layout[i]);
3072 priv->number_up_layout_n_option->choices_display[i] = g_strdup (_(n_up_layout_display[i]));
3075 g_object_ref (priv->number_up_layout_n_option);
3077 priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
3079 GTK_PRINTER_OPTION_TYPE_PICKONE);
3080 gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
3083 page_orientation = gtk_page_setup_get_orientation (priv->page_setup);
3084 if (page_orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
3085 page_orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
3087 if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
3088 priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[2]))
3090 g_free (priv->number_up_layout_2_option->choices_display[0]);
3091 g_free (priv->number_up_layout_2_option->choices_display[1]);
3092 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
3093 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
3094 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
3095 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
3100 if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
3101 priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[1]))
3103 g_free (priv->number_up_layout_2_option->choices_display[0]);
3104 g_free (priv->number_up_layout_2_option->choices_display[1]);
3105 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
3106 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[1];
3107 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Top to bottom"));
3108 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Bottom to top"));
3112 layout = dialog_get_number_up_layout (dialog);
3114 old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
3115 if (old_option != NULL)
3116 gtk_printer_option_set_remove (set, old_option);
3118 if (dialog_get_pages_per_sheet (dialog) != 1)
3120 GEnumClass *enum_class;
3121 GEnumValue *enum_value;
3122 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
3124 if (dialog_get_pages_per_sheet (dialog) == 2)
3126 option = priv->number_up_layout_2_option;
3130 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
3131 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
3132 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
3135 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
3136 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
3137 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP);
3140 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
3141 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
3142 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM);
3145 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
3146 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
3147 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP);
3151 g_assert_not_reached();
3157 option = priv->number_up_layout_n_option;
3159 enum_value = g_enum_get_value (enum_class, layout);
3162 g_assert (enum_value != NULL);
3163 gtk_printer_option_set (option, enum_value->value_nick);
3164 g_type_class_unref (enum_class);
3166 gtk_printer_option_set_add (set, option);
3170 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
3172 if (priv->number_up_layout != NULL)
3173 gtk_widget_set_sensitive (GTK_WIDGET (priv->number_up_layout),
3174 (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) &&
3175 (dialog_get_pages_per_sheet (dialog) > 1));
3179 custom_paper_dialog_response_cb (GtkDialog *custom_paper_dialog,
3183 GtkPrintUnixDialog *print_dialog = GTK_PRINT_UNIX_DIALOG (user_data);
3184 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
3185 GtkTreeModel *model;
3188 _gtk_print_load_custom_papers (priv->custom_paper_list);
3190 priv->internal_page_setup_change = TRUE;
3191 update_paper_sizes (print_dialog);
3192 priv->internal_page_setup_change = FALSE;
3194 if (priv->page_setup_set)
3196 model = GTK_TREE_MODEL (priv->custom_paper_list);
3197 if (gtk_tree_model_get_iter_first (model, &iter))
3201 GtkPageSetup *page_setup;
3202 gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
3205 g_strcmp0 (gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size (page_setup)),
3206 gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size (priv->page_setup))) == 0)
3207 gtk_print_unix_dialog_set_page_setup (print_dialog, page_setup);
3209 g_object_unref (page_setup);
3210 } while (gtk_tree_model_iter_next (model, &iter));
3214 gtk_widget_destroy (GTK_WIDGET (custom_paper_dialog));
3218 orientation_changed (GtkComboBox *combo_box,
3219 GtkPrintUnixDialog *dialog)
3221 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3222 GtkPageOrientation orientation;
3223 GtkPageSetup *page_setup;
3225 if (priv->internal_page_setup_change)
3228 orientation = (GtkPageOrientation) gtk_combo_box_get_active (GTK_COMBO_BOX (priv->orientation_combo));
3230 if (priv->page_setup)
3232 page_setup = gtk_page_setup_copy (priv->page_setup);
3234 gtk_page_setup_set_orientation (page_setup, orientation);
3236 gtk_print_unix_dialog_set_page_setup (dialog, page_setup);
3239 redraw_page_layout_preview (dialog);
3243 paper_size_changed (GtkComboBox *combo_box,
3244 GtkPrintUnixDialog *dialog)
3246 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3248 GtkPageSetup *page_setup, *last_page_setup;
3249 GtkPageOrientation orientation;
3251 if (priv->internal_page_setup_change)
3254 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3256 gtk_tree_model_get (gtk_combo_box_get_model (combo_box),
3257 &iter, PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup,
3260 if (page_setup == NULL)
3262 GtkWidget *custom_paper_dialog;
3264 /* Change from "manage" menu item to last value */
3265 if (priv->page_setup)
3266 last_page_setup = g_object_ref (priv->page_setup);
3268 last_page_setup = gtk_page_setup_new (); /* "good" default */
3270 if (!set_paper_size (dialog, last_page_setup, FALSE, FALSE))
3271 set_paper_size (dialog, last_page_setup, TRUE, TRUE);
3272 g_object_unref (last_page_setup);
3274 /* And show the custom paper dialog */
3275 custom_paper_dialog = _gtk_custom_paper_unix_dialog_new (GTK_WINDOW (dialog), _("Manage Custom Sizes"));
3276 g_signal_connect (custom_paper_dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), dialog);
3277 gtk_window_present (GTK_WINDOW (custom_paper_dialog));
3282 if (priv->page_setup)
3283 orientation = gtk_page_setup_get_orientation (priv->page_setup);
3285 orientation = GTK_PAGE_ORIENTATION_PORTRAIT;
3287 gtk_page_setup_set_orientation (page_setup, orientation);
3288 gtk_print_unix_dialog_set_page_setup (dialog, page_setup);
3290 g_object_unref (page_setup);
3293 redraw_page_layout_preview (dialog);
3297 paper_size_row_is_separator (GtkTreeModel *model,
3303 gtk_tree_model_get (model, iter,
3304 PAGE_SETUP_LIST_COL_IS_SEPARATOR, &separator,
3310 page_name_func (GtkCellLayout *cell_layout,
3311 GtkCellRenderer *cell,
3312 GtkTreeModel *tree_model,
3316 GtkPageSetup *page_setup;
3317 GtkPaperSize *paper_size;
3319 gtk_tree_model_get (tree_model, iter,
3320 PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup,
3324 paper_size = gtk_page_setup_get_paper_size (page_setup);
3325 g_object_set (cell, "text", gtk_paper_size_get_display_name (paper_size), NULL);
3326 g_object_unref (page_setup);
3329 g_object_set (cell, "text", _("Manage Custom Sizes…"), NULL);
3333 create_page_setup_page (GtkPrintUnixDialog *dialog)
3335 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3336 GtkWidget *main_vbox, *label, *hbox, *hbox2;
3337 GtkWidget *frame, *table, *widget;
3338 GtkWidget *combo, *spinbutton, *draw;
3339 GtkCellRenderer *cell;
3341 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
3342 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
3343 gtk_widget_show (main_vbox);
3345 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
3346 gtk_widget_show (hbox);
3347 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
3349 table = gtk_grid_new ();
3350 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3351 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3352 frame = wrap_in_frame (_("Layout"), table);
3353 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
3354 gtk_widget_show (table);
3356 label = gtk_label_new_with_mnemonic (_("T_wo-sided:"));
3357 gtk_widget_set_halign (label, GTK_ALIGN_START);
3358 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3359 gtk_widget_show (label);
3360 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3362 widget = gtk_printer_option_widget_new (NULL);
3363 priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
3364 gtk_widget_show (widget);
3365 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3366 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3368 label = gtk_label_new_with_mnemonic (_("Pages per _side:"));
3369 gtk_widget_set_halign (label, GTK_ALIGN_START);
3370 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3371 gtk_widget_show (label);
3372 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3374 widget = gtk_printer_option_widget_new (NULL);
3375 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
3376 g_signal_connect_swapped (widget, "changed", G_CALLBACK (update_number_up_layout), dialog);
3377 priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
3378 gtk_widget_show (widget);
3379 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3380 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3382 label = gtk_label_new_with_mnemonic (_("Page or_dering:"));
3383 gtk_widget_set_halign (label, GTK_ALIGN_START);
3384 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3385 gtk_widget_show (label);
3386 gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
3388 widget = gtk_printer_option_widget_new (NULL);
3389 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
3390 priv->number_up_layout = GTK_PRINTER_OPTION_WIDGET (widget);
3391 gtk_widget_show (widget);
3392 gtk_grid_attach (GTK_GRID (table), widget, 1, 2, 1, 1);
3393 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3395 label = gtk_label_new_with_mnemonic (_("_Only print:"));
3396 gtk_widget_set_halign (label, GTK_ALIGN_START);
3397 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3398 gtk_widget_show (label);
3399 gtk_grid_attach (GTK_GRID (table), label, 0, 3, 1, 1);
3401 combo = gtk_combo_box_text_new ();
3402 priv->page_set_combo = combo;
3403 gtk_widget_show (combo);
3404 gtk_grid_attach (GTK_GRID (table), combo, 1, 3, 1, 1);
3405 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3407 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("All sheets"));
3408 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Even sheets"));
3409 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Odd sheets"));
3410 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
3412 label = gtk_label_new_with_mnemonic (_("Sc_ale:"));
3413 gtk_widget_set_halign (label, GTK_ALIGN_START);
3414 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3415 gtk_widget_show (label);
3416 gtk_grid_attach (GTK_GRID (table), label, 0, 4, 1, 1);
3418 hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
3419 gtk_widget_show (hbox2);
3420 gtk_grid_attach (GTK_GRID (table), hbox2, 1, 4, 1, 1);
3422 spinbutton = gtk_spin_button_new_with_range (1.0, 1000.0, 1.0);
3423 priv->scale_spin = spinbutton;
3424 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), 1);
3425 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton), 100.0);
3426 gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
3427 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
3428 gtk_widget_show (spinbutton);
3429 label = gtk_label_new ("%"); /* FIXMEchpe does there exist any language where % needs to be translated? */
3430 gtk_widget_show (label);
3431 gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
3433 table = gtk_grid_new ();
3434 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3435 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3436 frame = wrap_in_frame (_("Paper"), table);
3437 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
3438 gtk_widget_show (table);
3440 label = gtk_label_new_with_mnemonic (_("Paper _type:"));
3441 gtk_widget_set_halign (label, GTK_ALIGN_START);
3442 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3443 gtk_widget_show (label);
3444 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3446 widget = gtk_printer_option_widget_new (NULL);
3447 priv->paper_type = GTK_PRINTER_OPTION_WIDGET (widget);
3448 gtk_widget_show (widget);
3449 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3450 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3452 label = gtk_label_new_with_mnemonic (_("Paper _source:"));
3453 gtk_widget_set_halign (label, GTK_ALIGN_START);
3454 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3455 gtk_widget_show (label);
3456 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3458 widget = gtk_printer_option_widget_new (NULL);
3459 priv->paper_source = GTK_PRINTER_OPTION_WIDGET (widget);
3460 gtk_widget_show (widget);
3461 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3462 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3464 label = gtk_label_new_with_mnemonic (_("Output t_ray:"));
3465 gtk_widget_set_halign (label, GTK_ALIGN_START);
3466 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3467 gtk_widget_show (label);
3468 gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
3470 widget = gtk_printer_option_widget_new (NULL);
3471 priv->output_tray = GTK_PRINTER_OPTION_WIDGET (widget);
3472 gtk_widget_show (widget);
3473 gtk_grid_attach (GTK_GRID (table), widget, 1, 2, 1, 1);
3474 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3477 label = gtk_label_new_with_mnemonic (_("_Paper size:"));
3478 priv->paper_size_combo_label = GTK_WIDGET (label);
3479 gtk_widget_set_halign (label, GTK_ALIGN_START);
3480 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3481 gtk_widget_show (label);
3482 gtk_grid_attach (GTK_GRID (table), label, 0, 3, 1, 1);
3484 combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->page_setup_list));
3485 priv->paper_size_combo = GTK_WIDGET (combo);
3486 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
3487 paper_size_row_is_separator, NULL, NULL);
3488 cell = gtk_cell_renderer_text_new ();
3489 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
3490 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), cell,
3491 page_name_func, NULL, NULL);
3492 gtk_grid_attach (GTK_GRID (table), combo, 1, 3, 1, 1);
3493 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3494 gtk_widget_set_sensitive (combo, FALSE);
3495 gtk_widget_show (combo);
3497 label = gtk_label_new_with_mnemonic (_("Or_ientation:"));
3498 priv->orientation_combo_label = GTK_WIDGET (label);
3499 gtk_widget_set_halign (label, GTK_ALIGN_START);
3500 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3501 gtk_widget_show (label);
3502 gtk_grid_attach (GTK_GRID (table), label, 0, 4, 1, 1);
3504 combo = gtk_combo_box_text_new ();
3505 priv->orientation_combo = GTK_WIDGET (combo);
3506 gtk_grid_attach (GTK_GRID (table), combo, 1, 4, 1, 1);
3507 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3509 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Portrait"));
3510 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Landscape"));
3511 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Reverse portrait"));
3512 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Reverse landscape"));
3513 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
3514 gtk_widget_set_sensitive (combo, FALSE);
3515 gtk_widget_show (combo);
3517 /* Add the page layout preview */
3518 hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
3519 gtk_widget_show (hbox2);
3520 gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 0);
3522 draw = gtk_drawing_area_new ();
3523 gtk_widget_set_has_window (draw, FALSE);
3524 priv->page_layout_preview = draw;
3525 gtk_widget_set_size_request (draw, 280, 160);
3526 g_signal_connect (draw, "draw", G_CALLBACK (draw_page_cb), dialog);
3527 gtk_widget_show (draw);
3529 gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 0);
3531 label = gtk_label_new (_("Page Setup"));
3532 gtk_widget_show (label);
3534 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3539 create_job_page (GtkPrintUnixDialog *dialog)
3541 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3542 GtkWidget *main_table, *label;
3543 GtkWidget *frame, *table, *radio;
3544 GtkWidget *entry, *widget;
3545 const gchar *at_tooltip;
3546 const gchar *on_hold_tooltip;
3548 main_table = gtk_grid_new ();
3549 gtk_container_set_border_width (GTK_CONTAINER (main_table), 12);
3550 gtk_grid_set_row_spacing (GTK_GRID (main_table), 18);
3551 gtk_grid_set_column_spacing (GTK_GRID (main_table), 18);
3553 table = gtk_grid_new ();
3554 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3555 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3556 frame = wrap_in_frame (_("Job Details"), table);
3557 gtk_grid_attach (GTK_GRID (main_table), frame, 0, 0, 1, 1);
3558 gtk_widget_show (table);
3560 label = gtk_label_new_with_mnemonic (_("Pri_ority:"));
3561 gtk_widget_set_halign (label, GTK_ALIGN_START);
3562 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3563 gtk_widget_show (label);
3564 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3566 widget = gtk_printer_option_widget_new (NULL);
3567 priv->job_prio = GTK_PRINTER_OPTION_WIDGET (widget);
3568 gtk_widget_show (widget);
3569 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3570 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3572 label = gtk_label_new_with_mnemonic (_("_Billing info:"));
3573 gtk_widget_set_halign (label, GTK_ALIGN_START);
3574 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3575 gtk_widget_show (label);
3576 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3578 widget = gtk_printer_option_widget_new (NULL);
3579 priv->billing_info = GTK_PRINTER_OPTION_WIDGET (widget);
3580 gtk_widget_show (widget);
3581 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3582 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3584 table = gtk_grid_new ();
3585 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3586 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3587 frame = wrap_in_frame (_("Print Document"), table);
3588 gtk_grid_attach (GTK_GRID (main_table), frame, 0, 1, 1, 1);
3589 gtk_widget_show (table);
3591 /* Translators: this is one of the choices for the print at option
3592 * in the print dialog
3594 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Now"));
3595 priv->print_now_radio = radio;
3596 gtk_widget_show (radio);
3597 gtk_grid_attach (GTK_GRID (table), radio, 0, 0, 2, 1);
3598 /* Translators: this is one of the choices for the print at option
3599 * in the print dialog. It also serves as the label for an entry that
3600 * allows the user to enter a time.
3602 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
3605 /* Translators: Ability to parse the am/pm format depends on actual locale.
3606 * You can remove the am/pm values below for your locale if they are not
3609 at_tooltip = _("Specify the time of print,\n e.g. 15:30, 2:35 pm, 14:15:20, 11:46:30 am, 4 pm");
3610 gtk_widget_set_tooltip_text (radio, at_tooltip);
3611 priv->print_at_radio = radio;
3612 gtk_widget_show (radio);
3613 gtk_grid_attach (GTK_GRID (table), radio, 0, 1, 1, 1);
3615 entry = gtk_entry_new ();
3616 gtk_widget_set_tooltip_text (entry, at_tooltip);
3617 atk_object_set_name (gtk_widget_get_accessible (entry), _("Time of print"));
3618 atk_object_set_description (gtk_widget_get_accessible (entry), at_tooltip);
3619 priv->print_at_entry = entry;
3620 gtk_widget_show (entry);
3621 gtk_grid_attach (GTK_GRID (table), entry, 1, 1, 1, 1);
3623 g_signal_connect (radio, "toggled", G_CALLBACK (update_entry_sensitivity), entry);
3624 update_entry_sensitivity (radio, entry);
3626 /* Translators: this is one of the choices for the print at option
3627 * in the print dialog. It means that the print job will not be
3628 * printed until it explicitly gets 'released'.
3630 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
3632 on_hold_tooltip = _("Hold the job until it is explicitly released");
3633 gtk_widget_set_tooltip_text (radio, on_hold_tooltip);
3634 priv->print_hold_radio = radio;
3635 gtk_widget_show (radio);
3636 gtk_grid_attach (GTK_GRID (table), radio, 0, 2, 2, 1);
3638 g_signal_connect_swapped (priv->print_now_radio, "toggled",
3639 G_CALLBACK (update_print_at_option), dialog);
3640 g_signal_connect_swapped (priv->print_at_radio, "toggled",
3641 G_CALLBACK (update_print_at_option), dialog);
3642 g_signal_connect_swapped (priv->print_at_entry, "changed",
3643 G_CALLBACK (update_print_at_option), dialog);
3644 g_signal_connect_swapped (priv->print_hold_radio, "toggled",
3645 G_CALLBACK (update_print_at_option), dialog);
3647 table = gtk_grid_new ();
3648 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3649 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3650 frame = wrap_in_frame (_("Add Cover Page"), table);
3651 gtk_grid_attach (GTK_GRID (main_table), frame, 1, 0, 1, 1);
3652 gtk_widget_show (table);
3654 /* Translators, this is the label used for the option in the print
3655 * dialog that controls the front cover page.
3657 label = gtk_label_new_with_mnemonic (_("Be_fore:"));
3658 gtk_widget_set_halign (label, GTK_ALIGN_START);
3659 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3660 gtk_widget_show (label);
3661 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3663 widget = gtk_printer_option_widget_new (NULL);
3664 priv->cover_before = GTK_PRINTER_OPTION_WIDGET (widget);
3665 gtk_widget_show (widget);
3666 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3667 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3669 /* Translators, this is the label used for the option in the print
3670 * dialog that controls the back cover page.
3672 label = gtk_label_new_with_mnemonic (_("_After:"));
3673 gtk_widget_set_halign (label, GTK_ALIGN_START);
3674 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3675 gtk_widget_show (label);
3676 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3678 widget = gtk_printer_option_widget_new (NULL);
3679 priv->cover_after = GTK_PRINTER_OPTION_WIDGET (widget);
3680 gtk_widget_show (widget);
3681 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3682 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3684 /* Translators: this is the tab label for the notebook tab containing
3685 * job-specific options in the print dialog
3687 label = gtk_label_new (_("Job"));
3688 gtk_widget_show (label);
3690 priv->job_page = main_table;
3691 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3696 create_optional_page (GtkPrintUnixDialog *dialog,
3698 GtkWidget **table_out,
3699 GtkWidget **page_out)
3701 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3702 GtkWidget *table, *label, *scrolled;
3704 scrolled = gtk_scrolled_window_new (NULL, NULL);
3705 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
3707 GTK_POLICY_AUTOMATIC);
3709 table = gtk_grid_new ();
3710 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3711 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3712 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
3713 gtk_widget_show (table);
3715 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
3717 gtk_viewport_set_shadow_type (GTK_VIEWPORT (gtk_bin_get_child (GTK_BIN (scrolled))),
3720 label = gtk_label_new (text);
3721 gtk_widget_show (label);
3723 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3727 *page_out = scrolled;
3731 create_advanced_page (GtkPrintUnixDialog *dialog)
3733 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3734 GtkWidget *main_vbox, *label, *scrolled;
3736 scrolled = gtk_scrolled_window_new (NULL, NULL);
3737 priv->advanced_page = scrolled;
3738 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
3740 GTK_POLICY_AUTOMATIC);
3742 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
3743 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
3744 gtk_widget_show (main_vbox);
3746 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
3748 gtk_viewport_set_shadow_type (GTK_VIEWPORT (gtk_bin_get_child (GTK_BIN (scrolled))),
3751 priv->advanced_vbox = main_vbox;
3753 label = gtk_label_new (_("Advanced"));
3754 gtk_widget_show (label);
3756 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3761 populate_dialog (GtkPrintUnixDialog *print_dialog)
3763 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
3764 GtkDialog *dialog = GTK_DIALOG (print_dialog);
3765 GtkWidget *vbox, *conflict_hbox, *image, *label;
3766 GtkWidget *action_area, *content_area;
3768 content_area = gtk_dialog_get_content_area (dialog);
3769 action_area = gtk_dialog_get_action_area (dialog);
3771 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
3772 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
3773 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
3774 gtk_box_set_spacing (GTK_BOX (action_area), 6);
3776 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
3777 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
3778 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
3779 gtk_widget_show (vbox);
3781 priv->notebook = gtk_notebook_new ();
3782 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
3783 gtk_widget_show (priv->notebook);
3785 create_printer_list_model (print_dialog);
3787 create_main_page (print_dialog);
3788 create_page_setup_page (print_dialog);
3789 create_job_page (print_dialog);
3790 /* Translators: this will appear as tab label in print dialog. */
3791 create_optional_page (print_dialog, _("Image Quality"),
3792 &priv->image_quality_table,
3793 &priv->image_quality_page);
3794 /* Translators: this will appear as tab label in print dialog. */
3795 create_optional_page (print_dialog, _("Color"),
3798 /* Translators: this will appear as tab label in print dialog. */
3799 /* It's a typographical term, as in "Binding and finishing" */
3800 create_optional_page (print_dialog, _("Finishing"),
3801 &priv->finishing_table,
3802 &priv->finishing_page);
3803 create_advanced_page (print_dialog);
3805 priv->conflicts_widget = conflict_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
3806 gtk_box_pack_end (GTK_BOX (vbox), conflict_hbox, FALSE, FALSE, 0);
3807 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
3808 gtk_widget_show (image);
3809 gtk_box_pack_start (GTK_BOX (conflict_hbox), image, FALSE, TRUE, 0);
3810 label = gtk_label_new (_("Some of the settings in the dialog conflict"));
3811 gtk_widget_show (label);
3812 gtk_box_pack_start (GTK_BOX (conflict_hbox), label, FALSE, TRUE, 0);
3814 load_print_backends (print_dialog);
3818 * gtk_print_unix_dialog_new:
3819 * @title: (allow-none): Title of the dialog, or %NULL
3820 * @parent: (allow-none): Transient parent of the dialog, or %NULL
3822 * Creates a new #GtkPrintUnixDialog.
3824 * Return value: a new #GtkPrintUnixDialog
3829 gtk_print_unix_dialog_new (const gchar *title,
3834 result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
3835 "transient-for", parent,
3836 "title", title ? title : _("Print"),
3843 * gtk_print_unix_dialog_get_selected_printer:
3844 * @dialog: a #GtkPrintUnixDialog
3846 * Gets the currently selected printer.
3848 * Returns: (transfer none): the currently selected printer
3853 gtk_print_unix_dialog_get_selected_printer (GtkPrintUnixDialog *dialog)
3855 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3857 return dialog->priv->current_printer;
3861 * gtk_print_unix_dialog_set_page_setup:
3862 * @dialog: a #GtkPrintUnixDialog
3863 * @page_setup: a #GtkPageSetup
3865 * Sets the page setup of the #GtkPrintUnixDialog.
3870 gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
3871 GtkPageSetup *page_setup)
3873 GtkPrintUnixDialogPrivate *priv;
3875 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3876 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
3878 priv = dialog->priv;
3880 if (priv->page_setup != page_setup)
3882 g_object_unref (priv->page_setup);
3883 priv->page_setup = g_object_ref (page_setup);
3885 priv->page_setup_set = TRUE;
3887 g_object_notify (G_OBJECT (dialog), "page-setup");
3892 * gtk_print_unix_dialog_get_page_setup:
3893 * @dialog: a #GtkPrintUnixDialog
3895 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3897 * Returns: (transfer none): the page setup of @dialog.
3902 gtk_print_unix_dialog_get_page_setup (GtkPrintUnixDialog *dialog)
3904 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3906 return dialog->priv->page_setup;
3910 * gtk_print_unix_dialog_get_page_setup_set:
3911 * @dialog: a #GtkPrintUnixDialog
3913 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3915 * Returns: whether a page setup was set by user.
3920 gtk_print_unix_dialog_get_page_setup_set (GtkPrintUnixDialog *dialog)
3922 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
3924 return dialog->priv->page_setup_set;
3928 * gtk_print_unix_dialog_set_current_page:
3929 * @dialog: a #GtkPrintUnixDialog
3930 * @current_page: the current page number.
3932 * Sets the current page number. If @current_page is not -1, this enables
3933 * the current page choice for the range of pages to print.
3938 gtk_print_unix_dialog_set_current_page (GtkPrintUnixDialog *dialog,
3941 GtkPrintUnixDialogPrivate *priv;
3943 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3945 priv = dialog->priv;
3947 if (priv->current_page != current_page)
3949 priv->current_page = current_page;
3951 if (priv->current_page_radio)
3952 gtk_widget_set_sensitive (priv->current_page_radio, current_page != -1);
3954 g_object_notify (G_OBJECT (dialog), "current-page");
3959 * gtk_print_unix_dialog_get_current_page:
3960 * @dialog: a #GtkPrintUnixDialog
3962 * Gets the current page of the #GtkPrintUnixDialog.
3964 * Returns: the current page of @dialog
3969 gtk_print_unix_dialog_get_current_page (GtkPrintUnixDialog *dialog)
3971 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), -1);
3973 return dialog->priv->current_page;
3977 set_active_printer (GtkPrintUnixDialog *dialog,
3978 const gchar *printer_name)
3980 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3981 GtkTreeModel *model;
3982 GtkTreeIter iter, filter_iter;
3983 GtkTreeSelection *selection;
3984 GtkPrinter *printer;
3986 model = GTK_TREE_MODEL (priv->printer_list);
3988 if (gtk_tree_model_get_iter_first (model, &iter))
3992 gtk_tree_model_get (GTK_TREE_MODEL (priv->printer_list), &iter,
3993 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
3995 if (printer == NULL)
3998 if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
4000 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
4001 &filter_iter, &iter);
4003 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
4004 priv->internal_printer_change = TRUE;
4005 gtk_tree_selection_select_iter (selection, &filter_iter);
4006 priv->internal_printer_change = FALSE;
4007 g_free (priv->waiting_for_printer);
4008 priv->waiting_for_printer = NULL;
4010 g_object_unref (printer);
4014 g_object_unref (printer);
4016 } while (gtk_tree_model_iter_next (model, &iter));
4023 * gtk_print_unix_dialog_set_settings:
4024 * @dialog: a #GtkPrintUnixDialog
4025 * @settings: (allow-none): a #GtkPrintSettings, or %NULL
4027 * Sets the #GtkPrintSettings for the #GtkPrintUnixDialog. Typically,
4028 * this is used to restore saved print settings from a previous print
4029 * operation before the print dialog is shown.
4034 gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
4035 GtkPrintSettings *settings)
4037 GtkPrintUnixDialogPrivate *priv;
4038 const gchar *printer;
4039 GtkPageRange *ranges;
4042 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4043 g_return_if_fail (settings == NULL || GTK_IS_PRINT_SETTINGS (settings));
4045 priv = dialog->priv;
4047 if (settings != NULL)
4049 dialog_set_collate (dialog, gtk_print_settings_get_collate (settings));
4050 dialog_set_reverse (dialog, gtk_print_settings_get_reverse (settings));
4051 dialog_set_n_copies (dialog, gtk_print_settings_get_n_copies (settings));
4052 dialog_set_scale (dialog, gtk_print_settings_get_scale (settings));
4053 dialog_set_page_set (dialog, gtk_print_settings_get_page_set (settings));
4054 dialog_set_print_pages (dialog, gtk_print_settings_get_print_pages (settings));
4055 ranges = gtk_print_settings_get_page_ranges (settings, &num_ranges);
4058 dialog_set_page_ranges (dialog, ranges, num_ranges);
4062 priv->format_for_printer =
4063 g_strdup (gtk_print_settings_get (settings, "format-for-printer"));
4066 if (priv->initial_settings)
4067 g_object_unref (priv->initial_settings);
4069 priv->initial_settings = settings;
4071 g_free (priv->waiting_for_printer);
4072 priv->waiting_for_printer = NULL;
4076 g_object_ref (settings);
4078 printer = gtk_print_settings_get_printer (settings);
4080 if (printer && !set_active_printer (dialog, printer))
4081 priv->waiting_for_printer = g_strdup (printer);
4084 g_object_notify (G_OBJECT (dialog), "print-settings");
4088 * gtk_print_unix_dialog_get_settings:
4089 * @dialog: a #GtkPrintUnixDialog
4091 * Gets a new #GtkPrintSettings object that represents the
4092 * current values in the print dialog. Note that this creates a
4093 * <emphasis>new object</emphasis>, and you need to unref it
4094 * if don't want to keep it.
4096 * Returns: a new #GtkPrintSettings object with the values from @dialog
4101 gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
4103 GtkPrintUnixDialogPrivate *priv;
4104 GtkPrintSettings *settings;
4105 GtkPrintPages print_pages;
4106 GtkPageRange *ranges;
4109 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
4111 priv = dialog->priv;
4112 settings = gtk_print_settings_new ();
4114 if (priv->current_printer)
4115 gtk_print_settings_set_printer (settings,
4116 gtk_printer_get_name (priv->current_printer));
4118 gtk_print_settings_set_printer (settings, "default");
4120 gtk_print_settings_set (settings, "format-for-printer",
4121 priv->format_for_printer);
4123 gtk_print_settings_set_collate (settings,
4124 dialog_get_collate (dialog));
4126 gtk_print_settings_set_reverse (settings,
4127 dialog_get_reverse (dialog));
4129 gtk_print_settings_set_n_copies (settings,
4130 dialog_get_n_copies (dialog));
4132 gtk_print_settings_set_scale (settings,
4133 dialog_get_scale (dialog));
4135 gtk_print_settings_set_page_set (settings,
4136 dialog_get_page_set (dialog));
4138 print_pages = dialog_get_print_pages (dialog);
4139 gtk_print_settings_set_print_pages (settings, print_pages);
4141 ranges = dialog_get_page_ranges (dialog, &n_ranges);
4144 gtk_print_settings_set_page_ranges (settings, ranges, n_ranges);
4148 /* TODO: print when. How to handle? */
4150 if (priv->current_printer)
4151 _gtk_printer_get_settings_from_options (priv->current_printer,
4159 * gtk_print_unix_dialog_add_custom_tab:
4160 * @dialog: a #GtkPrintUnixDialog
4161 * @child: the widget to put in the custom tab
4162 * @tab_label: the widget to use as tab label
4164 * Adds a custom tab to the print dialog.
4169 gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
4171 GtkWidget *tab_label)
4173 gtk_notebook_insert_page (GTK_NOTEBOOK (dialog->priv->notebook),
4174 child, tab_label, 2);
4175 gtk_widget_show (child);
4176 gtk_widget_show (tab_label);
4180 * gtk_print_unix_dialog_set_manual_capabilities:
4181 * @dialog: a #GtkPrintUnixDialog
4182 * @capabilities: the printing capabilities of your application
4184 * This lets you specify the printing capabilities your application
4185 * supports. For instance, if you can handle scaling the output then
4186 * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then
4187 * the dialog will only let you select the scale if the printing
4188 * system automatically handles scaling.
4193 gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog,
4194 GtkPrintCapabilities capabilities)
4196 GtkPrintUnixDialogPrivate *priv = dialog->priv;
4198 if (priv->manual_capabilities != capabilities)
4200 priv->manual_capabilities = capabilities;
4201 update_dialog_from_capabilities (dialog);
4203 if (priv->current_printer)
4205 GtkTreeSelection *selection;
4207 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
4208 g_clear_object (&priv->current_printer);
4209 priv->internal_printer_change = TRUE;
4210 selected_printer_changed (selection, dialog);
4211 priv->internal_printer_change = FALSE;
4214 g_object_notify (G_OBJECT (dialog), "manual-capabilities");
4219 * gtk_print_unix_dialog_get_manual_capabilities:
4220 * @dialog: a #GtkPrintUnixDialog
4222 * Gets the value of #GtkPrintUnixDialog:manual-capabilities property.
4224 * Returns: the printing capabilities
4228 GtkPrintCapabilities
4229 gtk_print_unix_dialog_get_manual_capabilities (GtkPrintUnixDialog *dialog)
4231 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4233 return dialog->priv->manual_capabilities;
4237 * gtk_print_unix_dialog_set_support_selection:
4238 * @dialog: a #GtkPrintUnixDialog
4239 * @support_selection: %TRUE to allow print selection
4241 * Sets whether the print dialog allows user to print a selection.
4246 gtk_print_unix_dialog_set_support_selection (GtkPrintUnixDialog *dialog,
4247 gboolean support_selection)
4249 GtkPrintUnixDialogPrivate *priv;
4251 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4253 priv = dialog->priv;
4255 support_selection = support_selection != FALSE;
4256 if (priv->support_selection != support_selection)
4258 priv->support_selection = support_selection;
4260 if (priv->selection_radio)
4262 if (support_selection)
4264 gtk_widget_set_sensitive (priv->selection_radio, priv->has_selection);
4265 gtk_widget_show (priv->selection_radio);
4269 gtk_widget_set_sensitive (priv->selection_radio, FALSE);
4270 gtk_widget_hide (priv->selection_radio);
4274 g_object_notify (G_OBJECT (dialog), "support-selection");
4279 * gtk_print_unix_dialog_get_support_selection:
4280 * @dialog: a #GtkPrintUnixDialog
4282 * Gets the value of #GtkPrintUnixDialog:support-selection property.
4284 * Returns: whether the application supports print of selection
4289 gtk_print_unix_dialog_get_support_selection (GtkPrintUnixDialog *dialog)
4291 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4293 return dialog->priv->support_selection;
4297 * gtk_print_unix_dialog_set_has_selection:
4298 * @dialog: a #GtkPrintUnixDialog
4299 * @has_selection: %TRUE indicates that a selection exists
4301 * Sets whether a selection exists.
4306 gtk_print_unix_dialog_set_has_selection (GtkPrintUnixDialog *dialog,
4307 gboolean has_selection)
4309 GtkPrintUnixDialogPrivate *priv;
4311 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4313 priv = dialog->priv;
4315 has_selection = has_selection != FALSE;
4316 if (priv->has_selection != has_selection)
4318 priv->has_selection = has_selection;
4320 if (priv->selection_radio)
4322 if (priv->support_selection)
4323 gtk_widget_set_sensitive (priv->selection_radio, has_selection);
4325 gtk_widget_set_sensitive (priv->selection_radio, FALSE);
4328 g_object_notify (G_OBJECT (dialog), "has-selection");
4333 * gtk_print_unix_dialog_get_has_selection:
4334 * @dialog: a #GtkPrintUnixDialog
4336 * Gets the value of #GtkPrintUnixDialog:has-selection property.
4338 * Returns: whether there is a selection
4343 gtk_print_unix_dialog_get_has_selection (GtkPrintUnixDialog *dialog)
4345 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4347 return dialog->priv->has_selection;
4351 * gtk_print_unix_dialog_set_embed_page_setup
4352 * @dialog: a #GtkPrintUnixDialog
4353 * @embed: embed page setup selection
4355 * Embed page size combo box and orientation combo box into page setup page.
4360 gtk_print_unix_dialog_set_embed_page_setup (GtkPrintUnixDialog *dialog,
4363 GtkPrintUnixDialogPrivate *priv;
4365 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4367 priv = dialog->priv;
4369 embed = embed != FALSE;
4370 if (priv->embed_page_setup != embed)
4372 priv->embed_page_setup = embed;
4374 gtk_widget_set_sensitive (priv->paper_size_combo, priv->embed_page_setup);
4375 gtk_widget_set_sensitive (priv->orientation_combo, priv->embed_page_setup);
4377 if (priv->embed_page_setup)
4379 if (priv->paper_size_combo != NULL)
4380 g_signal_connect (priv->paper_size_combo, "changed", G_CALLBACK (paper_size_changed), dialog);
4382 if (priv->orientation_combo)
4383 g_signal_connect (priv->orientation_combo, "changed", G_CALLBACK (orientation_changed), dialog);
4387 if (priv->paper_size_combo != NULL)
4388 g_signal_handlers_disconnect_by_func (priv->paper_size_combo, G_CALLBACK (paper_size_changed), dialog);
4390 if (priv->orientation_combo)
4391 g_signal_handlers_disconnect_by_func (priv->orientation_combo, G_CALLBACK (orientation_changed), dialog);
4394 priv->internal_page_setup_change = TRUE;
4395 update_paper_sizes (dialog);
4396 priv->internal_page_setup_change = FALSE;
4401 * gtk_print_unix_dialog_get_embed_page_setup:
4402 * @dialog: a #GtkPrintUnixDialog
4404 * Gets the value of #GtkPrintUnixDialog:embed-page-setup property.
4406 * Returns: whether there is a selection
4411 gtk_print_unix_dialog_get_embed_page_setup (GtkPrintUnixDialog *dialog)
4413 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4415 return dialog->priv->embed_page_setup;