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),
470 gdk_display_flush (display);
473 g_object_unref (cursor);
477 add_custom_button_to_dialog (GtkDialog *dialog,
478 const gchar *mnemonic_label,
479 const gchar *stock_id,
482 GtkWidget *button = NULL;
484 button = gtk_button_new_with_mnemonic (mnemonic_label);
485 gtk_widget_set_can_default (button, TRUE);
486 gtk_button_set_image (GTK_BUTTON (button),
487 gtk_image_new_from_stock (stock_id,
488 GTK_ICON_SIZE_BUTTON));
489 gtk_widget_show (button);
491 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
494 /* This function handles error messages before printing.
497 error_dialogs (GtkPrintUnixDialog *print_dialog,
498 gint print_dialog_response_id,
501 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
502 GtkPrinterOption *option = NULL;
503 GtkPrinter *printer = NULL;
504 GtkWindow *toplevel = NULL;
505 GtkWidget *dialog = NULL;
507 gchar *basename = NULL;
508 gchar *dirname = NULL;
511 if (print_dialog != NULL && print_dialog_response_id == GTK_RESPONSE_OK)
513 printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
517 if (priv->request_details_tag || !gtk_printer_is_accepting_jobs (printer))
519 g_signal_stop_emission_by_name (print_dialog, "response");
523 /* Shows overwrite confirmation dialog in the case of printing to file which
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,
621 (GCallback) gtk_print_unix_dialog_destroy,
624 g_signal_connect (dialog,
626 (GCallback) error_dialogs,
629 g_signal_connect (dialog,
630 "notify::page-setup",
631 (GCallback) redraw_page_layout_preview,
634 priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
635 gtk_widget_show (priv->preview_button);
637 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
638 priv->preview_button,
640 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
641 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
642 GTK_STOCK_PRINT, GTK_RESPONSE_OK,
644 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
650 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
651 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
653 priv->page_setup_list = gtk_list_store_new (PAGE_SETUP_LIST_N_COLS,
657 priv->custom_paper_list = gtk_list_store_new (1, G_TYPE_OBJECT);
658 _gtk_print_load_custom_papers (priv->custom_paper_list);
660 populate_dialog (dialog);
664 gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
666 /* Make sure we don't destroy custom widgets owned by the backends */
667 clear_per_printer_ui (dialog);
671 disconnect_printer_details_request (GtkPrintUnixDialog *dialog, gboolean details_failed)
673 GtkPrintUnixDialogPrivate *priv = dialog->priv;
675 if (priv->request_details_tag)
677 g_signal_handler_disconnect (priv->request_details_printer,
678 priv->request_details_tag);
679 priv->request_details_tag = 0;
680 set_busy_cursor (dialog, FALSE);
682 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
683 g_object_get_data (G_OBJECT (priv->request_details_printer),
684 "gtk-print-tree-iter"),
685 PRINTER_LIST_COL_STATE,
686 _("Getting printer information failed"),
689 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
690 g_object_get_data (G_OBJECT (priv->request_details_printer),
691 "gtk-print-tree-iter"),
692 PRINTER_LIST_COL_STATE,
693 gtk_printer_get_state_message (priv->request_details_printer),
695 g_object_unref (priv->request_details_printer);
696 priv->request_details_printer = NULL;
701 gtk_print_unix_dialog_finalize (GObject *object)
703 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
704 GtkPrintUnixDialogPrivate *priv = dialog->priv;
705 GtkPrintBackend *backend;
708 unschedule_idle_mark_conflicts (dialog);
709 disconnect_printer_details_request (dialog, FALSE);
711 if (priv->current_printer)
713 g_object_unref (priv->current_printer);
714 priv->current_printer = NULL;
717 if (priv->printer_list)
719 g_object_unref (priv->printer_list);
720 priv->printer_list = NULL;
723 if (priv->custom_paper_list)
725 g_object_unref (priv->custom_paper_list);
726 priv->custom_paper_list = NULL;
729 if (priv->printer_list_filter)
731 g_object_unref (priv->printer_list_filter);
732 priv->printer_list_filter = NULL;
737 g_object_unref (priv->options);
738 priv->options = NULL;
741 if (priv->number_up_layout_2_option)
743 priv->number_up_layout_2_option->choices[0] = NULL;
744 priv->number_up_layout_2_option->choices[1] = NULL;
745 g_free (priv->number_up_layout_2_option->choices_display[0]);
746 g_free (priv->number_up_layout_2_option->choices_display[1]);
747 priv->number_up_layout_2_option->choices_display[0] = NULL;
748 priv->number_up_layout_2_option->choices_display[1] = NULL;
749 g_object_unref (priv->number_up_layout_2_option);
750 priv->number_up_layout_2_option = NULL;
753 if (priv->number_up_layout_n_option)
755 g_object_unref (priv->number_up_layout_n_option);
756 priv->number_up_layout_n_option = NULL;
759 if (priv->page_setup)
761 g_object_unref (priv->page_setup);
762 priv->page_setup = NULL;
765 if (priv->initial_settings)
767 g_object_unref (priv->initial_settings);
768 priv->initial_settings = NULL;
771 g_free (priv->waiting_for_printer);
772 priv->waiting_for_printer = NULL;
774 g_free (priv->format_for_printer);
775 priv->format_for_printer = NULL;
777 for (node = priv->print_backends; node != NULL; node = node->next)
779 backend = GTK_PRINT_BACKEND (node->data);
781 g_signal_handlers_disconnect_by_func (backend, printer_added_cb, dialog);
782 g_signal_handlers_disconnect_by_func (backend, printer_removed_cb, dialog);
783 g_signal_handlers_disconnect_by_func (backend, printer_status_cb, dialog);
785 gtk_print_backend_destroy (backend);
786 g_object_unref (backend);
789 g_list_free (priv->print_backends);
790 priv->print_backends = NULL;
792 if (priv->page_setup_list)
794 g_object_unref (priv->page_setup_list);
795 priv->page_setup_list = NULL;
798 G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->finalize (object);
802 printer_removed_cb (GtkPrintBackend *backend,
804 GtkPrintUnixDialog *dialog)
806 GtkPrintUnixDialogPrivate *priv = dialog->priv;
809 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
810 gtk_list_store_remove (GTK_LIST_STORE (priv->printer_list), iter);
814 gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface)
816 parent_buildable_iface = g_type_interface_peek_parent (iface);
818 iface->get_internal_child = gtk_print_unix_dialog_buildable_get_internal_child;
822 gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
824 const gchar *childname)
826 if (strcmp (childname, "notebook") == 0)
827 return G_OBJECT (GTK_PRINT_UNIX_DIALOG (buildable)->priv->notebook);
829 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
832 /* This function controls "sensitive" property of GtkCellRenderer based on pause
833 * state of printers. */
834 void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
835 GtkCellRenderer *cell,
836 GtkTreeModel *tree_model,
842 gtk_tree_model_get (tree_model, iter, PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
844 if (printer != NULL && !gtk_printer_is_accepting_jobs (printer))
845 g_object_set (cell, "sensitive", FALSE, NULL);
847 g_object_set (cell, "sensitive", TRUE, NULL);
849 g_object_unref (printer);
853 printer_status_cb (GtkPrintBackend *backend,
855 GtkPrintUnixDialog *dialog)
857 GtkPrintUnixDialogPrivate *priv = dialog->priv;
859 GtkTreeSelection *selection;
861 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
863 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), iter,
864 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
865 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
866 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
867 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
870 /* When the pause state change then we need to update sensitive property
871 * of GTK_RESPONSE_OK button inside of selected_printer_changed function. */
872 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
873 selected_printer_changed (selection, dialog);
875 if (gtk_print_backend_printer_list_is_done (backend) &&
876 gtk_printer_is_default (printer) &&
877 (gtk_tree_selection_count_selected_rows (selection) == 0))
878 set_active_printer (dialog, gtk_printer_get_name (printer));
882 printer_added_cb (GtkPrintBackend *backend,
884 GtkPrintUnixDialog *dialog)
886 GtkPrintUnixDialogPrivate *priv = dialog->priv;
887 GtkTreeIter iter, filter_iter;
888 GtkTreeSelection *selection;
891 gtk_list_store_append (GTK_LIST_STORE (priv->printer_list), &iter);
893 g_object_set_data_full (G_OBJECT (printer),
894 "gtk-print-tree-iter",
895 gtk_tree_iter_copy (&iter),
896 (GDestroyNotify) gtk_tree_iter_free);
898 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), &iter,
899 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
900 PRINTER_LIST_COL_NAME, gtk_printer_get_name (printer),
901 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
902 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
903 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
904 PRINTER_LIST_COL_PRINTER_OBJ, printer,
907 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
908 &filter_iter, &iter);
909 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->printer_list_filter), &filter_iter);
911 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
913 if (priv->waiting_for_printer != NULL &&
914 strcmp (gtk_printer_get_name (printer),
915 priv->waiting_for_printer) == 0)
917 priv->internal_printer_change = TRUE;
918 gtk_tree_selection_select_iter (selection, &filter_iter);
919 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
920 path, NULL, TRUE, 0.5, 0.0);
921 priv->internal_printer_change = FALSE;
922 g_free (priv->waiting_for_printer);
923 priv->waiting_for_printer = NULL;
925 else if (is_default_printer (dialog, printer) &&
926 gtk_tree_selection_count_selected_rows (selection) == 0)
928 priv->internal_printer_change = TRUE;
929 gtk_tree_selection_select_iter (selection, &filter_iter);
930 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
931 path, NULL, TRUE, 0.5, 0.0);
932 priv->internal_printer_change = FALSE;
935 gtk_tree_path_free (path);
939 printer_list_initialize (GtkPrintUnixDialog *dialog,
940 GtkPrintBackend *print_backend)
945 g_return_if_fail (print_backend != NULL);
947 g_signal_connect_object (print_backend,
949 (GCallback) printer_added_cb,
950 G_OBJECT (dialog), 0);
952 g_signal_connect_object (print_backend,
954 (GCallback) printer_removed_cb,
955 G_OBJECT (dialog), 0);
957 g_signal_connect_object (print_backend,
958 "printer-status-changed",
959 (GCallback) printer_status_cb,
960 G_OBJECT (dialog), 0);
962 list = gtk_print_backend_get_printer_list (print_backend);
967 printer_added_cb (print_backend, node->data, dialog);
975 load_print_backends (GtkPrintUnixDialog *dialog)
977 GtkPrintUnixDialogPrivate *priv = dialog->priv;
980 if (g_module_supported ())
981 priv->print_backends = gtk_print_backend_load_modules ();
983 for (node = priv->print_backends; node != NULL; node = node->next)
985 GtkPrintBackend *backend = node->data;
986 printer_list_initialize (dialog, backend);
991 gtk_print_unix_dialog_set_property (GObject *object,
997 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
1001 case PROP_PAGE_SETUP:
1002 gtk_print_unix_dialog_set_page_setup (dialog, g_value_get_object (value));
1004 case PROP_CURRENT_PAGE:
1005 gtk_print_unix_dialog_set_current_page (dialog, g_value_get_int (value));
1007 case PROP_PRINT_SETTINGS:
1008 gtk_print_unix_dialog_set_settings (dialog, g_value_get_object (value));
1010 case PROP_MANUAL_CAPABILITIES:
1011 gtk_print_unix_dialog_set_manual_capabilities (dialog, g_value_get_flags (value));
1013 case PROP_SUPPORT_SELECTION:
1014 gtk_print_unix_dialog_set_support_selection (dialog, g_value_get_boolean (value));
1016 case PROP_HAS_SELECTION:
1017 gtk_print_unix_dialog_set_has_selection (dialog, g_value_get_boolean (value));
1019 case PROP_EMBED_PAGE_SETUP:
1020 gtk_print_unix_dialog_set_embed_page_setup (dialog, g_value_get_boolean (value));
1023 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1029 gtk_print_unix_dialog_get_property (GObject *object,
1034 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
1035 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1039 case PROP_PAGE_SETUP:
1040 g_value_set_object (value, priv->page_setup);
1042 case PROP_CURRENT_PAGE:
1043 g_value_set_int (value, priv->current_page);
1045 case PROP_PRINT_SETTINGS:
1046 g_value_take_object (value, gtk_print_unix_dialog_get_settings (dialog));
1048 case PROP_SELECTED_PRINTER:
1049 g_value_set_object (value, priv->current_printer);
1051 case PROP_MANUAL_CAPABILITIES:
1052 g_value_set_flags (value, priv->manual_capabilities);
1054 case PROP_SUPPORT_SELECTION:
1055 g_value_set_boolean (value, priv->support_selection);
1057 case PROP_HAS_SELECTION:
1058 g_value_set_boolean (value, priv->has_selection);
1060 case PROP_EMBED_PAGE_SETUP:
1061 g_value_set_boolean (value, priv->embed_page_setup);
1064 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1070 is_printer_active (GtkTreeModel *model,
1072 GtkPrintUnixDialog *dialog)
1075 GtkPrinter *printer;
1076 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1078 gtk_tree_model_get (model, iter,
1079 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1082 if (printer == NULL)
1085 result = gtk_printer_is_active (printer);
1088 priv->manual_capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF |
1089 GTK_PRINT_CAPABILITY_GENERATE_PS))
1091 /* Check that the printer can handle at least one of the data
1092 * formats that the application supports.
1094 result = ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF) &&
1095 gtk_printer_accepts_pdf (printer)) ||
1096 ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS) &&
1097 gtk_printer_accepts_ps (printer));
1100 g_object_unref (printer);
1106 default_printer_list_sort_func (GtkTreeModel *model,
1113 GtkPrinter *a_printer;
1114 GtkPrinter *b_printer;
1117 gtk_tree_model_get (model, a,
1118 PRINTER_LIST_COL_NAME, &a_name,
1119 PRINTER_LIST_COL_PRINTER_OBJ, &a_printer,
1121 gtk_tree_model_get (model, b,
1122 PRINTER_LIST_COL_NAME, &b_name,
1123 PRINTER_LIST_COL_PRINTER_OBJ, &b_printer,
1126 if (a_printer == NULL && b_printer == NULL)
1128 else if (a_printer == NULL)
1130 else if (b_printer == NULL)
1132 else if (gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
1134 else if (gtk_printer_is_virtual (a_printer) && !gtk_printer_is_virtual (b_printer))
1136 else if (!gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
1138 else if (a_name == NULL && b_name == NULL)
1140 else if (a_name == NULL && b_name != NULL)
1142 else if (a_name != NULL && b_name == NULL)
1145 result = g_ascii_strcasecmp (a_name, b_name);
1150 g_object_unref (a_printer);
1152 g_object_unref (b_printer);
1158 create_printer_list_model (GtkPrintUnixDialog *dialog)
1160 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1161 GtkListStore *model;
1162 GtkTreeSortable *sort;
1164 model = gtk_list_store_new (PRINTER_LIST_N_COLS,
1172 priv->printer_list = (GtkTreeModel *)model;
1173 priv->printer_list_filter = (GtkTreeModelFilter *) gtk_tree_model_filter_new ((GtkTreeModel *)model,
1176 gtk_tree_model_filter_set_visible_func (priv->printer_list_filter,
1177 (GtkTreeModelFilterVisibleFunc) is_printer_active,
1181 sort = GTK_TREE_SORTABLE (model);
1182 gtk_tree_sortable_set_default_sort_func (sort,
1183 default_printer_list_sort_func,
1187 gtk_tree_sortable_set_sort_column_id (sort,
1188 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
1189 GTK_SORT_ASCENDING);
1195 wrap_in_frame (const gchar *label,
1198 GtkWidget *frame, *label_widget;
1201 label_widget = gtk_label_new (NULL);
1202 gtk_widget_set_halign (label_widget, GTK_ALIGN_START);
1203 gtk_widget_set_valign (label_widget, GTK_ALIGN_CENTER);
1204 gtk_widget_show (label_widget);
1206 bold_text = g_markup_printf_escaped ("<b>%s</b>", label);
1207 gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
1210 frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
1211 gtk_box_pack_start (GTK_BOX (frame), label_widget, FALSE, FALSE, 0);
1213 gtk_widget_set_margin_left (child, 12);
1214 gtk_widget_set_halign (child, GTK_ALIGN_FILL);
1215 gtk_widget_set_valign (child, GTK_ALIGN_FILL);
1217 gtk_box_pack_start (GTK_BOX (frame), child, FALSE, FALSE, 0);
1219 gtk_widget_show (frame);
1225 setup_option (GtkPrintUnixDialog *dialog,
1226 const gchar *option_name,
1227 GtkPrinterOptionWidget *widget)
1229 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1230 GtkPrinterOption *option;
1232 option = gtk_printer_option_set_lookup (priv->options, option_name);
1233 gtk_printer_option_widget_set_source (widget, option);
1235 return option != NULL;
1239 add_option_to_extension_point (GtkPrinterOption *option,
1242 GtkWidget *extension_point = data;
1245 widget = gtk_printer_option_widget_new (option);
1246 gtk_widget_show (widget);
1248 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1250 GtkWidget *label, *hbox;
1252 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1253 gtk_widget_show (label);
1254 gtk_widget_set_halign (label, GTK_ALIGN_START);
1255 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1256 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1258 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
1259 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1260 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1261 gtk_widget_show (hbox);
1263 gtk_box_pack_start (GTK_BOX (extension_point), hbox, FALSE, FALSE, 0);
1266 gtk_box_pack_start (GTK_BOX (extension_point), widget, FALSE, FALSE, 0);
1270 grid_rows (GtkGrid *table)
1273 GList *children, *c;
1275 children = gtk_container_get_children (GTK_CONTAINER (table));
1277 for (c = children; c; c = c->next)
1279 gtk_container_child_get (GTK_CONTAINER (table), c->data,
1296 g_list_free (children);
1302 add_option_to_table (GtkPrinterOption *option,
1306 GtkWidget *label, *widget;
1309 table = GTK_GRID (user_data);
1311 if (g_str_has_prefix (option->name, "gtk-"))
1314 row = grid_rows (table);
1316 widget = gtk_printer_option_widget_new (option);
1317 gtk_widget_show (widget);
1319 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1321 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1322 gtk_widget_show (label);
1324 gtk_widget_set_halign (label, GTK_ALIGN_START);
1325 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1326 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1328 gtk_grid_attach (table, label, 0, row - 1, 1, 1);
1329 gtk_grid_attach (table, widget, 1, row - 1, 1, 1);
1332 gtk_grid_attach (table, widget, 0, row - 1, 2, 1);
1336 setup_page_table (GtkPrinterOptionSet *options,
1343 gtk_printer_option_set_foreach_in_group (options, group,
1344 add_option_to_table,
1347 nrows = grid_rows (GTK_GRID (table));
1349 gtk_widget_hide (page);
1351 gtk_widget_show (page);
1355 update_print_at_option (GtkPrintUnixDialog *dialog)
1357 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1358 GtkPrinterOption *option;
1360 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1365 if (priv->updating_print_at)
1368 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_at_radio)))
1369 gtk_printer_option_set (option, "at");
1370 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio)))
1371 gtk_printer_option_set (option, "on-hold");
1373 gtk_printer_option_set (option, "now");
1375 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1378 const char *text = gtk_entry_get_text (GTK_ENTRY (priv->print_at_entry));
1379 gtk_printer_option_set (option, text);
1385 setup_print_at (GtkPrintUnixDialog *dialog)
1387 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1388 GtkPrinterOption *option;
1390 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1394 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1396 gtk_widget_set_sensitive (priv->print_at_radio, FALSE);
1397 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1398 gtk_widget_set_sensitive (priv->print_hold_radio, FALSE);
1399 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), "");
1403 priv->updating_print_at = TRUE;
1405 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1406 gtk_widget_set_sensitive (priv->print_at_radio,
1407 gtk_printer_option_has_choice (option, "at"));
1409 gtk_widget_set_sensitive (priv->print_hold_radio,
1410 gtk_printer_option_has_choice (option, "on-hold"));
1412 update_print_at_option (dialog);
1414 if (strcmp (option->value, "at") == 0)
1415 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_at_radio),
1417 else if (strcmp (option->value, "on-hold") == 0)
1418 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio),
1421 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1424 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1426 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), option->value);
1428 priv->updating_print_at = FALSE;
1434 update_dialog_from_settings (GtkPrintUnixDialog *dialog)
1436 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1439 GtkWidget *table, *frame;
1440 gboolean has_advanced, has_job;
1443 if (priv->current_printer == NULL)
1445 clear_per_printer_ui (dialog);
1446 gtk_widget_hide (priv->job_page);
1447 gtk_widget_hide (priv->advanced_page);
1448 gtk_widget_hide (priv->image_quality_page);
1449 gtk_widget_hide (priv->finishing_page);
1450 gtk_widget_hide (priv->color_page);
1451 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1456 setup_option (dialog, "gtk-n-up", priv->pages_per_sheet);
1457 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
1458 setup_option (dialog, "gtk-duplex", priv->duplex);
1459 setup_option (dialog, "gtk-paper-type", priv->paper_type);
1460 setup_option (dialog, "gtk-paper-source", priv->paper_source);
1461 setup_option (dialog, "gtk-output-tray", priv->output_tray);
1464 has_job |= setup_option (dialog, "gtk-job-prio", priv->job_prio);
1465 has_job |= setup_option (dialog, "gtk-billing-info", priv->billing_info);
1466 has_job |= setup_option (dialog, "gtk-cover-before", priv->cover_before);
1467 has_job |= setup_option (dialog, "gtk-cover-after", priv->cover_after);
1468 has_job |= setup_print_at (dialog);
1471 gtk_widget_show (priv->job_page);
1473 gtk_widget_hide (priv->job_page);
1475 setup_page_table (priv->options,
1477 priv->image_quality_table,
1478 priv->image_quality_page);
1480 setup_page_table (priv->options,
1482 priv->finishing_table,
1483 priv->finishing_page);
1485 setup_page_table (priv->options,
1490 gtk_printer_option_set_foreach_in_group (priv->options,
1491 "GtkPrintDialogExtension",
1492 add_option_to_extension_point,
1493 priv->extension_point);
1495 /* Put the rest of the groups in the advanced page */
1496 groups = gtk_printer_option_set_get_groups (priv->options);
1498 has_advanced = FALSE;
1499 for (l = groups; l != NULL; l = l->next)
1506 if (strcmp (group, "ImageQualityPage") == 0 ||
1507 strcmp (group, "ColorPage") == 0 ||
1508 strcmp (group, "FinishingPage") == 0 ||
1509 strcmp (group, "GtkPrintDialogExtension") == 0)
1512 table = gtk_grid_new ();
1513 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
1514 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
1516 gtk_printer_option_set_foreach_in_group (priv->options,
1518 add_option_to_table,
1521 nrows = grid_rows (GTK_GRID (table));
1523 gtk_widget_destroy (table);
1526 has_advanced = TRUE;
1527 frame = wrap_in_frame (group, table);
1528 gtk_widget_show (table);
1529 gtk_widget_show (frame);
1531 gtk_box_pack_start (GTK_BOX (priv->advanced_vbox),
1532 frame, FALSE, FALSE, 0);
1537 gtk_widget_show (priv->advanced_page);
1539 gtk_widget_hide (priv->advanced_page);
1541 g_list_free_full (groups, g_free);
1545 update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
1547 GtkPrintCapabilities caps;
1548 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1549 gboolean can_collate;
1550 const gchar *copies;
1552 copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin));
1553 can_collate = (*copies != '\0' && atoi (copies) > 1);
1555 caps = priv->manual_capabilities | priv->printer_capabilities;
1557 gtk_widget_set_sensitive (priv->page_set_combo,
1558 caps & GTK_PRINT_CAPABILITY_PAGE_SET);
1559 gtk_widget_set_sensitive (priv->copies_spin,
1560 caps & GTK_PRINT_CAPABILITY_COPIES);
1561 gtk_widget_set_sensitive (priv->collate_check,
1563 (caps & GTK_PRINT_CAPABILITY_COLLATE));
1564 gtk_widget_set_sensitive (priv->reverse_check,
1565 caps & GTK_PRINT_CAPABILITY_REVERSE);
1566 gtk_widget_set_sensitive (priv->scale_spin,
1567 caps & GTK_PRINT_CAPABILITY_SCALE);
1568 gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet),
1569 caps & GTK_PRINT_CAPABILITY_NUMBER_UP);
1571 if (caps & GTK_PRINT_CAPABILITY_PREVIEW)
1572 gtk_widget_show (priv->preview_button);
1574 gtk_widget_hide (priv->preview_button);
1576 update_collate_icon (NULL, dialog);
1578 gtk_tree_model_filter_refilter (priv->printer_list_filter);
1582 page_setup_is_equal (GtkPageSetup *a,
1586 gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
1587 gtk_page_setup_get_paper_size (b)) &&
1588 gtk_page_setup_get_top_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_top_margin (b, GTK_UNIT_MM) &&
1589 gtk_page_setup_get_bottom_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_bottom_margin (b, GTK_UNIT_MM) &&
1590 gtk_page_setup_get_left_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_left_margin (b, GTK_UNIT_MM) &&
1591 gtk_page_setup_get_right_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_right_margin (b, GTK_UNIT_MM);
1595 page_setup_is_same_size (GtkPageSetup *a,
1598 return gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
1599 gtk_page_setup_get_paper_size (b));
1603 set_paper_size (GtkPrintUnixDialog *dialog,
1604 GtkPageSetup *page_setup,
1608 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1609 GtkTreeModel *model;
1611 GtkPageSetup *list_page_setup;
1613 if (!priv->internal_page_setup_change)
1616 if (page_setup == NULL)
1619 model = GTK_TREE_MODEL (priv->page_setup_list);
1621 if (gtk_tree_model_get_iter_first (model, &iter))
1625 gtk_tree_model_get (GTK_TREE_MODEL (priv->page_setup_list), &iter,
1626 PAGE_SETUP_LIST_COL_PAGE_SETUP, &list_page_setup, -1);
1627 if (list_page_setup == NULL)
1630 if ((size_only && page_setup_is_same_size (page_setup, list_page_setup)) ||
1631 (!size_only && page_setup_is_equal (page_setup, list_page_setup)))
1633 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->paper_size_combo),
1635 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->orientation_combo),
1636 gtk_page_setup_get_orientation (page_setup));
1637 g_object_unref (list_page_setup);
1641 g_object_unref (list_page_setup);
1643 } while (gtk_tree_model_iter_next (model, &iter));
1648 gtk_list_store_append (priv->page_setup_list, &iter);
1649 gtk_list_store_set (priv->page_setup_list, &iter,
1650 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1652 gtk_list_store_append (priv->page_setup_list, &iter);
1653 gtk_list_store_set (priv->page_setup_list, &iter,
1654 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1656 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->paper_size_combo),
1658 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->orientation_combo),
1659 gtk_page_setup_get_orientation (page_setup));
1667 fill_custom_paper_sizes (GtkPrintUnixDialog *dialog)
1669 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1670 GtkTreeIter iter, paper_iter;
1671 GtkTreeModel *model;
1673 model = GTK_TREE_MODEL (priv->custom_paper_list);
1674 if (gtk_tree_model_get_iter_first (model, &iter))
1676 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1677 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1678 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1682 GtkPageSetup *page_setup;
1683 gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
1685 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1686 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1687 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1690 g_object_unref (page_setup);
1691 } while (gtk_tree_model_iter_next (model, &iter));
1694 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1695 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1696 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1698 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1699 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1700 PAGE_SETUP_LIST_COL_PAGE_SETUP, NULL,
1705 fill_paper_sizes (GtkPrintUnixDialog *dialog,
1706 GtkPrinter *printer)
1708 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1710 GtkPageSetup *page_setup;
1711 GtkPaperSize *paper_size;
1715 gtk_list_store_clear (priv->page_setup_list);
1717 if (printer == NULL || (list = gtk_printer_list_papers (printer)) == NULL)
1719 for (i = 0; i < G_N_ELEMENTS (common_paper_sizes); i++)
1721 page_setup = gtk_page_setup_new ();
1722 paper_size = gtk_paper_size_new (common_paper_sizes[i]);
1723 gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size);
1724 gtk_paper_size_free (paper_size);
1726 gtk_list_store_append (priv->page_setup_list, &iter);
1727 gtk_list_store_set (priv->page_setup_list, &iter,
1728 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1730 g_object_unref (page_setup);
1735 for (l = list; l != NULL; l = l->next)
1737 page_setup = l->data;
1738 gtk_list_store_append (priv->page_setup_list, &iter);
1739 gtk_list_store_set (priv->page_setup_list, &iter,
1740 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1742 g_object_unref (page_setup);
1747 fill_custom_paper_sizes (dialog);
1751 update_paper_sizes (GtkPrintUnixDialog *dialog)
1753 GtkPageSetup *current_page_setup = NULL;
1754 GtkPrinter *printer;
1756 printer = gtk_print_unix_dialog_get_selected_printer (dialog);
1758 fill_paper_sizes (dialog, printer);
1760 current_page_setup = gtk_page_setup_copy (gtk_print_unix_dialog_get_page_setup (dialog));
1762 if (current_page_setup)
1764 if (!set_paper_size (dialog, current_page_setup, FALSE, FALSE))
1765 set_paper_size (dialog, current_page_setup, TRUE, TRUE);
1767 g_object_unref (current_page_setup);
1772 mark_conflicts (GtkPrintUnixDialog *dialog)
1774 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1775 GtkPrinter *printer;
1776 gboolean have_conflict;
1778 have_conflict = FALSE;
1780 printer = priv->current_printer;
1785 g_signal_handler_block (priv->options,
1786 priv->options_changed_handler);
1788 gtk_printer_option_set_clear_conflicts (priv->options);
1790 have_conflict = _gtk_printer_mark_conflicts (printer,
1793 g_signal_handler_unblock (priv->options,
1794 priv->options_changed_handler);
1798 gtk_widget_show (priv->conflicts_widget);
1800 gtk_widget_hide (priv->conflicts_widget);
1804 mark_conflicts_callback (gpointer data)
1806 GtkPrintUnixDialog *dialog = data;
1807 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1809 priv->mark_conflicts_id = 0;
1811 mark_conflicts (dialog);
1817 unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1819 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1821 if (priv->mark_conflicts_id != 0)
1823 g_source_remove (priv->mark_conflicts_id);
1824 priv->mark_conflicts_id = 0;
1829 schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1831 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1833 if (priv->mark_conflicts_id != 0)
1836 priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
1841 options_changed_cb (GtkPrintUnixDialog *dialog)
1843 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1845 schedule_idle_mark_conflicts (dialog);
1847 g_free (priv->waiting_for_printer);
1848 priv->waiting_for_printer = NULL;
1852 remove_custom_widget (GtkWidget *widget,
1853 GtkContainer *container)
1855 gtk_container_remove (container, widget);
1859 extension_point_clear_children (GtkContainer *container)
1861 gtk_container_foreach (container,
1862 (GtkCallback)remove_custom_widget,
1867 clear_per_printer_ui (GtkPrintUnixDialog *dialog)
1869 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1871 gtk_container_foreach (GTK_CONTAINER (priv->finishing_table),
1872 (GtkCallback)gtk_widget_destroy, NULL);
1873 gtk_container_foreach (GTK_CONTAINER (priv->image_quality_table),
1874 (GtkCallback)gtk_widget_destroy, NULL);
1875 gtk_container_foreach (GTK_CONTAINER (priv->color_table),
1876 (GtkCallback)gtk_widget_destroy, NULL);
1877 gtk_container_foreach (GTK_CONTAINER (priv->advanced_vbox),
1878 (GtkCallback)gtk_widget_destroy, NULL);
1879 extension_point_clear_children (GTK_CONTAINER (priv->extension_point));
1883 printer_details_acquired (GtkPrinter *printer,
1885 GtkPrintUnixDialog *dialog)
1887 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1889 disconnect_printer_details_request (dialog, !success);
1893 GtkTreeSelection *selection;
1894 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
1896 selected_printer_changed (selection, dialog);
1901 selected_printer_changed (GtkTreeSelection *selection,
1902 GtkPrintUnixDialog *dialog)
1904 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1905 GtkPrinter *printer;
1906 GtkTreeIter iter, filter_iter;
1908 /* Whenever the user selects a printer we stop looking for
1909 the printer specified in the initial settings */
1910 if (priv->waiting_for_printer &&
1911 !priv->internal_printer_change)
1913 g_free (priv->waiting_for_printer);
1914 priv->waiting_for_printer = NULL;
1917 disconnect_printer_details_request (dialog, FALSE);
1920 if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
1922 gtk_tree_model_filter_convert_iter_to_child_iter (priv->printer_list_filter,
1926 gtk_tree_model_get (priv->printer_list, &iter,
1927 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1931 /* sets GTK_RESPONSE_OK button sensitivity depending on whether the printer
1932 * accepts/rejects jobs
1934 if (printer != NULL)
1936 if (!gtk_printer_is_accepting_jobs (printer))
1938 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1942 if (priv->current_printer == printer && gtk_printer_has_details (printer))
1943 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1947 if (printer != NULL && !gtk_printer_has_details (printer))
1949 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1950 priv->request_details_tag =
1951 g_signal_connect (printer, "details-acquired",
1952 G_CALLBACK (printer_details_acquired), dialog);
1953 /* take the reference */
1954 priv->request_details_printer = printer;
1955 gtk_printer_request_details (printer);
1956 set_busy_cursor (dialog, TRUE);
1957 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
1958 g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter"),
1959 PRINTER_LIST_COL_STATE, _("Getting printer information..."),
1964 if (printer == priv->current_printer)
1967 g_object_unref (printer);
1973 g_object_unref (priv->options);
1974 priv->options = NULL;
1976 clear_per_printer_ui (dialog);
1979 if (priv->current_printer)
1981 g_object_unref (priv->current_printer);
1984 priv->printer_capabilities = 0;
1986 if (printer != NULL && gtk_printer_is_accepting_jobs (printer))
1987 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1988 priv->current_printer = printer;
1990 if (printer != NULL)
1992 if (!priv->page_setup_set)
1994 /* if no explicit page setup has been set, use the printer default */
1995 GtkPageSetup *page_setup;
1997 page_setup = gtk_printer_get_default_page_size (printer);
2000 page_setup = gtk_page_setup_new ();
2002 if (page_setup && priv->page_setup)
2003 gtk_page_setup_set_orientation (page_setup, gtk_page_setup_get_orientation (priv->page_setup));
2005 g_object_unref (priv->page_setup);
2006 priv->page_setup = page_setup;
2009 priv->printer_capabilities = gtk_printer_get_capabilities (printer);
2010 priv->options = _gtk_printer_get_options (printer,
2011 priv->initial_settings,
2013 priv->manual_capabilities);
2015 priv->options_changed_handler =
2016 g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
2017 schedule_idle_mark_conflicts (dialog);
2020 update_dialog_from_settings (dialog);
2021 update_dialog_from_capabilities (dialog);
2023 priv->internal_page_setup_change = TRUE;
2024 update_paper_sizes (dialog);
2025 priv->internal_page_setup_change = FALSE;
2027 g_object_notify ( G_OBJECT(dialog), "selected-printer");
2031 update_collate_icon (GtkToggleButton *toggle_button,
2032 GtkPrintUnixDialog *dialog)
2034 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2036 gtk_widget_queue_draw (priv->collate_image);
2040 paint_page (GtkWidget *widget,
2048 GtkStyleContext *context;
2049 gint x, y, width, height;
2050 gint text_y, linewidth;
2053 x = x_offset * scale;
2054 y = y_offset * scale;
2056 height = 26 * scale;
2061 context = gtk_widget_get_style_context (widget);
2063 gtk_style_context_save (context);
2064 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
2066 gtk_style_context_get_background_color (context, 0, &color);
2067 gdk_cairo_set_source_rgba (cr, &color);
2068 cairo_rectangle (cr, x, y, width, height);
2071 gtk_style_context_get_color (context, 0, &color);
2072 gdk_cairo_set_source_rgba (cr, &color);
2073 cairo_set_line_width (cr, linewidth);
2074 cairo_rectangle (cr, x + linewidth/2.0, y + linewidth/2.0, width - linewidth, height - linewidth);
2077 cairo_select_font_face (cr, "Sans",
2078 CAIRO_FONT_SLANT_NORMAL,
2079 CAIRO_FONT_WEIGHT_NORMAL);
2080 cairo_set_font_size (cr, (gint)(9 * scale));
2081 cairo_move_to (cr, x + (gint)(text_x * scale), y + (gint)(text_y * scale));
2082 cairo_show_text (cr, text);
2084 gtk_style_context_restore (context);
2088 draw_collate_cb (GtkWidget *widget,
2090 GtkPrintUnixDialog *dialog)
2092 GtkSettings *settings;
2095 gboolean collate, reverse, rtl;
2099 collate = dialog_get_collate (dialog);
2100 reverse = dialog_get_reverse (dialog);
2101 copies = dialog_get_n_copies (dialog);
2103 rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL);
2105 settings = gtk_widget_get_settings (widget);
2106 gtk_icon_size_lookup_for_settings (settings,
2107 GTK_ICON_SIZE_DIALOG,
2110 scale = size / 48.0;
2111 text_x = rtl ? 4 : 11;
2115 paint_page (widget, cr, scale, rtl ? 40: 15, 5, reverse ? "1" : "2", text_x);
2116 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
2120 paint_page (widget, cr, scale, rtl ? 40: 15, 5, collate == reverse ? "1" : "2", text_x);
2121 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
2123 paint_page (widget, cr, scale, rtl ? 5 : 50, 5, reverse ? "1" : "2", text_x);
2124 paint_page (widget, cr, scale, rtl ? 15 : 40, 15, collate == reverse ? "2" : "1", text_x);
2131 gtk_print_unix_dialog_style_updated (GtkWidget *widget)
2133 GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_updated (widget);
2135 if (gtk_widget_has_screen (widget))
2137 GtkPrintUnixDialog *dialog = (GtkPrintUnixDialog *)widget;
2138 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2139 GtkSettings *settings;
2143 settings = gtk_widget_get_settings (widget);
2144 gtk_icon_size_lookup_for_settings (settings,
2145 GTK_ICON_SIZE_DIALOG,
2148 scale = size / 48.0;
2150 gtk_widget_set_size_request (priv->collate_image,
2157 update_entry_sensitivity (GtkWidget *button,
2162 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
2164 gtk_widget_set_sensitive (range, active);
2167 gtk_widget_grab_focus (range);
2171 emit_ok_response (GtkTreeView *tree_view,
2173 GtkTreeViewColumn *column,
2174 gpointer *user_data)
2176 GtkPrintUnixDialog *print_dialog;
2178 print_dialog = (GtkPrintUnixDialog *) user_data;
2180 gtk_dialog_response (GTK_DIALOG (print_dialog), GTK_RESPONSE_OK);
2184 create_main_page (GtkPrintUnixDialog *dialog)
2186 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2187 GtkWidget *main_vbox, *label, *vbox, *hbox;
2188 GtkWidget *scrolled, *treeview, *frame, *table;
2189 GtkWidget *entry, *spinbutton;
2190 GtkWidget *radio, *check, *image;
2191 GtkCellRenderer *renderer;
2192 GtkTreeViewColumn *column;
2193 GtkTreeSelection *selection;
2194 GtkWidget *custom_input;
2195 const gchar *range_tooltip;
2197 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
2198 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2199 gtk_widget_show (main_vbox);
2201 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
2202 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
2203 gtk_widget_show (vbox);
2205 scrolled = gtk_scrolled_window_new (NULL, NULL);
2206 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2207 GTK_POLICY_AUTOMATIC,
2208 GTK_POLICY_AUTOMATIC);
2209 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
2211 gtk_widget_show (scrolled);
2212 gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
2214 treeview = gtk_tree_view_new_with_model ((GtkTreeModel *) priv->printer_list_filter);
2215 priv->printer_treeview = treeview;
2216 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
2217 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), PRINTER_LIST_COL_NAME);
2218 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), TRUE);
2219 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
2220 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
2221 g_signal_connect (selection, "changed", G_CALLBACK (selected_printer_changed), dialog);
2223 renderer = gtk_cell_renderer_pixbuf_new ();
2224 column = gtk_tree_view_column_new_with_attributes ("",
2227 PRINTER_LIST_COL_ICON,
2229 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2230 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2232 renderer = gtk_cell_renderer_text_new ();
2233 column = gtk_tree_view_column_new_with_attributes (_("Printer"),
2236 PRINTER_LIST_COL_NAME,
2238 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2239 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2241 renderer = gtk_cell_renderer_text_new ();
2242 /* Translators: this is the header for the location column in the print dialog */
2243 column = gtk_tree_view_column_new_with_attributes (_("Location"),
2246 PRINTER_LIST_COL_LOCATION,
2248 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2249 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2251 renderer = gtk_cell_renderer_text_new ();
2252 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
2253 /* Translators: this is the header for the printer status column in the print dialog */
2254 column = gtk_tree_view_column_new_with_attributes (_("Status"),
2257 PRINTER_LIST_COL_STATE,
2259 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2260 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2262 g_signal_connect (GTK_TREE_VIEW (treeview), "row-activated", G_CALLBACK (emit_ok_response), dialog);
2264 gtk_widget_show (treeview);
2265 gtk_container_add (GTK_CONTAINER (scrolled), treeview);
2267 custom_input = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
2268 gtk_widget_show (custom_input);
2269 gtk_box_pack_start (GTK_BOX (vbox), custom_input, FALSE, FALSE, 0);
2270 priv->extension_point = custom_input;
2272 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
2273 gtk_widget_show (hbox);
2274 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
2276 table = gtk_grid_new ();
2277 priv->range_table = table;
2278 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
2279 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
2280 frame = wrap_in_frame (_("Range"), table);
2281 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2282 gtk_widget_show (table);
2284 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_All Pages"));
2285 priv->all_pages_radio = radio;
2286 gtk_widget_show (radio);
2287 gtk_grid_attach (GTK_GRID (table), radio, 0, 0, 2, 1);
2288 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2289 _("C_urrent Page"));
2290 if (priv->current_page == -1)
2291 gtk_widget_set_sensitive (radio, FALSE);
2292 priv->current_page_radio = radio;
2293 gtk_widget_show (radio);
2294 gtk_grid_attach (GTK_GRID (table), radio, 0, 1, 2, 1);
2296 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2299 gtk_widget_set_sensitive (radio, priv->has_selection);
2300 priv->selection_radio = radio;
2301 gtk_grid_attach (GTK_GRID (table), radio, 0, 2, 2, 1);
2303 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)), _("Pag_es:"));
2304 range_tooltip = _("Specify one or more page ranges,\n e.g. 1-3,7,11");
2305 gtk_widget_set_tooltip_text (radio, range_tooltip);
2307 priv->page_range_radio = radio;
2308 gtk_widget_show (radio);
2309 gtk_grid_attach (GTK_GRID (table), radio, 0, 3, 1, 1);
2310 entry = gtk_entry_new ();
2311 gtk_widget_set_tooltip_text (entry, range_tooltip);
2312 gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
2313 atk_object_set_name (gtk_widget_get_accessible (entry), _("Pages"));
2314 atk_object_set_description (gtk_widget_get_accessible (entry), range_tooltip);
2315 priv->page_range_entry = entry;
2316 gtk_widget_show (entry);
2317 gtk_grid_attach (GTK_GRID (table), entry, 1, 3, 1, 1);
2318 g_signal_connect (radio, "toggled", G_CALLBACK (update_entry_sensitivity), entry);
2319 update_entry_sensitivity (radio, entry);
2321 table = gtk_grid_new ();
2322 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
2323 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
2324 frame = wrap_in_frame (_("Copies"), table);
2325 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2326 gtk_widget_show (table);
2328 /* FIXME chpe: too much space between Copies and spinbutton, put those 2 in a hbox and make it span 2 columns */
2329 label = gtk_label_new_with_mnemonic (_("Copie_s:"));
2330 gtk_widget_set_halign (label, GTK_ALIGN_START);
2331 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
2332 gtk_widget_show (label);
2333 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
2334 spinbutton = gtk_spin_button_new_with_range (1.0, 100.0, 1.0);
2335 gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
2336 priv->copies_spin = spinbutton;
2337 gtk_widget_show (spinbutton);
2338 gtk_grid_attach (GTK_GRID (table), spinbutton, 1, 0, 1, 1);
2339 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
2340 g_signal_connect_swapped (spinbutton, "value-changed",
2341 G_CALLBACK (update_dialog_from_capabilities), dialog);
2342 g_signal_connect_swapped (spinbutton, "changed",
2343 G_CALLBACK (update_dialog_from_capabilities), dialog);
2345 check = gtk_check_button_new_with_mnemonic (_("C_ollate"));
2346 priv->collate_check = check;
2347 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
2348 gtk_widget_show (check);
2349 gtk_grid_attach (GTK_GRID (table), check, 0, 1, 1, 1);
2351 check = gtk_check_button_new_with_mnemonic (_("_Reverse"));
2352 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
2353 priv->reverse_check = check;
2354 gtk_widget_show (check);
2355 gtk_grid_attach (GTK_GRID (table), check, 0, 2, 1, 1);
2357 image = gtk_drawing_area_new ();
2358 gtk_widget_set_has_window (image, FALSE);
2360 priv->collate_image = image;
2361 gtk_widget_show (image);
2362 gtk_widget_set_size_request (image, 70, 90);
2363 gtk_grid_attach (GTK_GRID (table), image, 1, 1, 1, 2);
2364 g_signal_connect (image, "draw",
2365 G_CALLBACK (draw_collate_cb), dialog);
2367 label = gtk_label_new (_("General"));
2368 gtk_widget_show (label);
2370 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), main_vbox, label);
2374 is_range_separator (gchar c)
2376 return (c == ',' || c == ';' || c == ':');
2379 static GtkPageRange *
2380 dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
2383 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2385 const gchar *text, *p;
2387 GtkPageRange *ranges;
2390 text = gtk_entry_get_text (GTK_ENTRY (priv->page_range_entry));
2402 if (is_range_separator (*p))
2407 ranges = g_new0 (GtkPageRange, n_ranges);
2413 while (isspace (*p)) p++;
2417 /* a half-open range like -2 */
2422 start = (int)strtol (p, &next, 10);
2430 while (isspace (*p)) p++;
2435 end = (int)strtol (p, &next, 10);
2436 if (next == p) /* a half-open range like 2- */
2438 else if (end < start)
2442 ranges[i].start = start - 1;
2443 ranges[i].end = end - 1;
2446 /* Skip until end or separator */
2447 while (*p && !is_range_separator (*p))
2450 /* if not at end, skip separator */
2461 dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
2462 GtkPageRange *ranges,
2465 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2467 GString *s = g_string_new (NULL);
2469 for (i = 0; i < n_ranges; i++)
2471 g_string_append_printf (s, "%d", ranges[i].start + 1);
2472 if (ranges[i].end > ranges[i].start)
2473 g_string_append_printf (s, "-%d", ranges[i].end + 1);
2474 else if (ranges[i].end == -1)
2475 g_string_append (s, "-");
2477 if (i != n_ranges - 1)
2478 g_string_append (s, ",");
2481 gtk_entry_set_text (GTK_ENTRY (priv->page_range_entry), s->str);
2483 g_string_free (s, TRUE);
2486 static GtkPrintPages
2487 dialog_get_print_pages (GtkPrintUnixDialog *dialog)
2489 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2491 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio)))
2492 return GTK_PRINT_PAGES_ALL;
2493 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->current_page_radio)))
2494 return GTK_PRINT_PAGES_CURRENT;
2495 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->selection_radio)))
2496 return GTK_PRINT_PAGES_SELECTION;
2498 return GTK_PRINT_PAGES_RANGES;
2502 dialog_set_print_pages (GtkPrintUnixDialog *dialog,
2503 GtkPrintPages pages)
2505 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2507 if (pages == GTK_PRINT_PAGES_RANGES)
2508 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
2509 else if (pages == GTK_PRINT_PAGES_CURRENT)
2510 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->current_page_radio), TRUE);
2511 else if (pages == GTK_PRINT_PAGES_SELECTION)
2512 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->selection_radio), TRUE);
2514 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio), TRUE);
2518 dialog_get_scale (GtkPrintUnixDialog *dialog)
2520 if (gtk_widget_is_sensitive (dialog->priv->scale_spin))
2521 return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
2527 dialog_set_scale (GtkPrintUnixDialog *dialog,
2530 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin), val);
2534 dialog_get_page_set (GtkPrintUnixDialog *dialog)
2536 if (gtk_widget_is_sensitive (dialog->priv->page_set_combo))
2537 return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
2539 return GTK_PAGE_SET_ALL;
2543 dialog_set_page_set (GtkPrintUnixDialog *dialog,
2546 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->page_set_combo),
2551 dialog_get_n_copies (GtkPrintUnixDialog *dialog)
2553 if (gtk_widget_is_sensitive (dialog->priv->copies_spin))
2554 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
2559 dialog_set_n_copies (GtkPrintUnixDialog *dialog,
2562 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->copies_spin),
2567 dialog_get_collate (GtkPrintUnixDialog *dialog)
2569 if (gtk_widget_is_sensitive (dialog->priv->collate_check))
2570 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
2575 dialog_set_collate (GtkPrintUnixDialog *dialog,
2578 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check),
2583 dialog_get_reverse (GtkPrintUnixDialog *dialog)
2585 if (gtk_widget_is_sensitive (dialog->priv->reverse_check))
2586 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
2591 dialog_set_reverse (GtkPrintUnixDialog *dialog,
2594 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check),
2599 dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
2601 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2605 val = gtk_printer_option_widget_get_value (priv->pages_per_sheet);
2619 static GtkNumberUpLayout
2620 dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
2622 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2623 GtkPrintCapabilities caps;
2624 GtkNumberUpLayout layout;
2626 GEnumClass *enum_class;
2627 GEnumValue *enum_value;
2629 val = gtk_printer_option_widget_get_value (priv->number_up_layout);
2631 caps = priv->manual_capabilities | priv->printer_capabilities;
2633 if ((caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) == 0)
2634 return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2636 if (gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR)
2637 layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2639 layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
2644 if (val[0] == '\0' && priv->options)
2646 GtkPrinterOption *option = gtk_printer_option_set_lookup (priv->options, "gtk-n-up-layout");
2648 val = option->value;
2651 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
2652 enum_value = g_enum_get_value_by_nick (enum_class, val);
2654 layout = enum_value->value;
2655 g_type_class_unref (enum_class);
2661 draw_page_cb (GtkWidget *widget,
2663 GtkPrintUnixDialog *dialog)
2665 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2666 GtkStyleContext *context;
2668 gint w, h, tmp, shadow_offset;
2669 gint pages_x, pages_y, i, x, y, layout_w, layout_h;
2670 gdouble page_width, page_height;
2671 GtkPageOrientation orientation;
2673 PangoLayout *layout;
2674 PangoFontDescription *font;
2677 GtkNumberUpLayout number_up_layout;
2678 gint start_x, end_x, start_y, end_y;
2681 gboolean horizontal;
2682 GtkPageSetup *page_setup;
2683 gdouble paper_width, paper_height;
2684 gdouble pos_x, pos_y;
2685 gint pages_per_sheet;
2686 gboolean ltr = TRUE;
2688 orientation = gtk_page_setup_get_orientation (priv->page_setup);
2690 (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
2691 (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
2693 number_up_layout = dialog_get_number_up_layout (dialog);
2694 width = gtk_widget_get_allocated_width (widget);
2695 height = gtk_widget_get_allocated_height (widget);
2699 page_setup = gtk_print_unix_dialog_get_page_setup (dialog);
2701 if (page_setup != NULL)
2705 paper_width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
2706 paper_height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
2710 paper_width = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
2711 paper_height = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
2714 if (paper_width < paper_height)
2716 h = EXAMPLE_PAGE_AREA_SIZE - 3;
2717 w = (paper_height != 0) ? h * paper_width / paper_height : 0;
2721 w = EXAMPLE_PAGE_AREA_SIZE - 3;
2722 h = (paper_width != 0) ? w * paper_height / paper_width : 0;
2725 if (paper_width == 0)
2728 if (paper_height == 0)
2734 w = (EXAMPLE_PAGE_AREA_SIZE - 3) / ratio;
2735 h = EXAMPLE_PAGE_AREA_SIZE - 3;
2738 pages_per_sheet = dialog_get_pages_per_sheet (dialog);
2739 switch (pages_per_sheet)
2743 pages_x = 1; pages_y = 1;
2746 landscape = !landscape;
2747 pages_x = 1; pages_y = 2;
2750 pages_x = 2; pages_y = 2;
2753 landscape = !landscape;
2754 pages_x = 2; pages_y = 3;
2757 pages_x = 3; pages_y = 3;
2760 pages_x = 4; pages_y = 4;
2775 context = gtk_widget_get_style_context (widget);
2777 gtk_style_context_save (context);
2778 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
2780 pos_x = (width - w) / 2;
2781 pos_y = (height - h) / 2 - 10;
2782 cairo_translate (cr, pos_x, pos_y);
2786 gtk_style_context_get_color (context, 0, &color);
2787 cairo_set_source_rgba (cr, color.red, color.green, color.blue, 0.5);
2788 cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
2791 gtk_style_context_get_background_color (context, 0, &color);
2792 gdk_cairo_set_source_rgba (cr, &color);
2793 cairo_rectangle (cr, 1, 1, w, h);
2795 cairo_set_line_width (cr, 1.0);
2796 cairo_rectangle (cr, 0.5, 0.5, w + 1, h + 1);
2798 gtk_style_context_get_color (context, 0, &color);
2799 gdk_cairo_set_source_rgba (cr, &color);
2804 page_width = (double)w / pages_x;
2805 page_height = (double)h / pages_y;
2807 layout = pango_cairo_create_layout (cr);
2809 font = pango_font_description_new ();
2810 pango_font_description_set_family (font, "sans");
2812 if (page_height > 0)
2813 pango_font_description_set_absolute_size (font, page_height * 0.4 * PANGO_SCALE);
2815 pango_font_description_set_absolute_size (font, 1);
2817 pango_layout_set_font_description (layout, font);
2818 pango_font_description_free (font);
2820 pango_layout_set_width (layout, page_width * PANGO_SCALE);
2821 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2823 switch (number_up_layout)
2826 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
2828 end_x = pages_x - 1;
2830 end_y = pages_y - 1;
2835 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
2837 end_x = pages_x - 1;
2838 start_y = pages_y - 1;
2844 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
2845 start_x = pages_x - 1;
2848 end_y = pages_y - 1;
2853 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
2854 start_x = pages_x - 1;
2856 start_y = pages_y - 1;
2862 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
2864 end_x = pages_x - 1;
2866 end_y = pages_y - 1;
2871 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
2872 start_x = pages_x - 1;
2875 end_y = pages_y - 1;
2880 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
2882 end_x = pages_x - 1;
2883 start_y = pages_y - 1;
2889 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
2890 start_x = pages_x - 1;
2892 start_y = pages_y - 1;
2901 for (y = start_y; y != end_y + dy; y += dy)
2903 for (x = start_x; x != end_x + dx; x += dx)
2905 text = g_strdup_printf ("%d", i++);
2906 pango_layout_set_text (layout, text, -1);
2908 pango_layout_get_size (layout, &layout_w, &layout_h);
2910 cairo_translate (cr,
2912 y * page_height + (page_height - layout_h / 1024.0) / 2);
2914 pango_cairo_show_layout (cr, layout);
2919 for (x = start_x; x != end_x + dx; x += dx)
2921 for (y = start_y; y != end_y + dy; y += dy)
2923 text = g_strdup_printf ("%d", i++);
2924 pango_layout_set_text (layout, text, -1);
2926 pango_layout_get_size (layout, &layout_w, &layout_h);
2928 cairo_translate (cr,
2930 y * page_height + (page_height - layout_h / 1024.0) / 2);
2932 pango_cairo_show_layout (cr, layout);
2937 g_object_unref (layout);
2939 if (page_setup != NULL)
2944 if (pages_per_sheet == 2 || pages_per_sheet == 6)
2946 paper_width = gtk_page_setup_get_paper_height (page_setup, _gtk_print_get_default_user_units ());
2947 paper_height = gtk_page_setup_get_paper_width (page_setup, _gtk_print_get_default_user_units ());
2951 paper_width = gtk_page_setup_get_paper_width (page_setup, _gtk_print_get_default_user_units ());
2952 paper_height = gtk_page_setup_get_paper_height (page_setup, _gtk_print_get_default_user_units ());
2958 layout = pango_cairo_create_layout (cr);
2960 font = pango_font_description_new ();
2961 pango_font_description_set_family (font, "sans");
2963 PangoContext *pango_c = NULL;
2964 PangoFontDescription *pango_f = NULL;
2965 gint font_size = 12 * PANGO_SCALE;
2967 pango_c = gtk_widget_get_pango_context (widget);
2968 if (pango_c != NULL)
2970 pango_f = pango_context_get_font_description (pango_c);
2971 if (pango_f != NULL)
2972 font_size = pango_font_description_get_size (pango_f);
2975 pango_font_description_set_size (font, font_size);
2976 pango_layout_set_font_description (layout, font);
2977 pango_font_description_free (font);
2979 pango_layout_set_width (layout, -1);
2980 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2982 if (_gtk_print_get_default_user_units () == GTK_UNIT_MM)
2983 text = g_strdup_printf ("%.1f mm", paper_height);
2985 text = g_strdup_printf ("%.2f inch", paper_height);
2987 pango_layout_set_text (layout, text, -1);
2989 pango_layout_get_size (layout, &layout_w, &layout_h);
2991 ltr = gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR;
2994 cairo_translate (cr, pos_x - layout_w / PANGO_SCALE - 2 * RULER_DISTANCE,
2995 (height - layout_h / PANGO_SCALE) / 2);
2997 cairo_translate (cr, pos_x + w + shadow_offset + 2 * RULER_DISTANCE,
2998 (height - layout_h / PANGO_SCALE) / 2);
3000 pango_cairo_show_layout (cr, layout);
3005 if (_gtk_print_get_default_user_units () == GTK_UNIT_MM)
3006 text = g_strdup_printf ("%.1f mm", paper_width);
3008 text = g_strdup_printf ("%.2f inch", paper_width);
3010 pango_layout_set_text (layout, text, -1);
3012 pango_layout_get_size (layout, &layout_w, &layout_h);
3014 cairo_translate (cr, (width - layout_w / PANGO_SCALE) / 2,
3015 pos_y + h + shadow_offset + 2 * RULER_DISTANCE);
3017 pango_cairo_show_layout (cr, layout);
3019 g_object_unref (layout);
3023 cairo_set_line_width (cr, 1);
3027 cairo_move_to (cr, pos_x - RULER_DISTANCE, pos_y);
3028 cairo_line_to (cr, pos_x - RULER_DISTANCE, pos_y + h);
3031 cairo_move_to (cr, pos_x - RULER_DISTANCE - RULER_RADIUS, pos_y - 0.5);
3032 cairo_line_to (cr, pos_x - RULER_DISTANCE + RULER_RADIUS, pos_y - 0.5);
3035 cairo_move_to (cr, pos_x - RULER_DISTANCE - RULER_RADIUS, pos_y + h + 0.5);
3036 cairo_line_to (cr, pos_x - RULER_DISTANCE + RULER_RADIUS, pos_y + h + 0.5);
3041 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE, pos_y);
3042 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE, pos_y + h);
3045 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE - RULER_RADIUS, pos_y - 0.5);
3046 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE + RULER_RADIUS, pos_y - 0.5);
3049 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE - RULER_RADIUS, pos_y + h + 0.5);
3050 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE + RULER_RADIUS, pos_y + h + 0.5);
3054 cairo_move_to (cr, pos_x, pos_y + h + shadow_offset + RULER_DISTANCE);
3055 cairo_line_to (cr, pos_x + w, pos_y + h + shadow_offset + RULER_DISTANCE);
3058 cairo_move_to (cr, pos_x - 0.5, pos_y + h + shadow_offset + RULER_DISTANCE - RULER_RADIUS);
3059 cairo_line_to (cr, pos_x - 0.5, pos_y + h + shadow_offset + RULER_DISTANCE + RULER_RADIUS);
3062 cairo_move_to (cr, pos_x + w + 0.5, pos_y + h + shadow_offset + RULER_DISTANCE - RULER_RADIUS);
3063 cairo_line_to (cr, pos_x + w + 0.5, pos_y + h + shadow_offset + RULER_DISTANCE + RULER_RADIUS);
3067 gtk_style_context_restore (context);
3073 redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
3075 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3077 if (priv->page_layout_preview)
3078 gtk_widget_queue_draw (priv->page_layout_preview);
3082 update_number_up_layout (GtkPrintUnixDialog *dialog)
3084 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3085 GtkPrintCapabilities caps;
3086 GtkPrinterOptionSet *set;
3087 GtkNumberUpLayout layout;
3088 GtkPrinterOption *option;
3089 GtkPrinterOption *old_option;
3090 GtkPageOrientation page_orientation;
3092 set = priv->options;
3094 caps = priv->manual_capabilities | priv->printer_capabilities;
3096 if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
3098 if (priv->number_up_layout_n_option == NULL)
3100 priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
3101 if (priv->number_up_layout_n_option == NULL)
3103 char *n_up_layout[] = { "lrtb", "lrbt", "rltb", "rlbt", "tblr", "tbrl", "btlr", "btrl" };
3104 /* Translators: These strings name the possible arrangements of
3105 * multiple pages on a sheet when printing (same as in gtkprintbackendcups.c)
3107 char *n_up_layout_display[] = { N_("Left to right, top to bottom"), N_("Left to right, bottom to top"),
3108 N_("Right to left, top to bottom"), N_("Right to left, bottom to top"),
3109 N_("Top to bottom, left to right"), N_("Top to bottom, right to left"),
3110 N_("Bottom to top, left to right"), N_("Bottom to top, right to left") };
3113 priv->number_up_layout_n_option = gtk_printer_option_new ("gtk-n-up-layout",
3115 GTK_PRINTER_OPTION_TYPE_PICKONE);
3116 gtk_printer_option_allocate_choices (priv->number_up_layout_n_option, 8);
3118 for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
3120 priv->number_up_layout_n_option->choices[i] = g_strdup (n_up_layout[i]);
3121 priv->number_up_layout_n_option->choices_display[i] = g_strdup (_(n_up_layout_display[i]));
3124 g_object_ref (priv->number_up_layout_n_option);
3126 priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
3128 GTK_PRINTER_OPTION_TYPE_PICKONE);
3129 gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
3132 page_orientation = gtk_page_setup_get_orientation (priv->page_setup);
3133 if (page_orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
3134 page_orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
3136 if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
3137 priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[2]))
3139 g_free (priv->number_up_layout_2_option->choices_display[0]);
3140 g_free (priv->number_up_layout_2_option->choices_display[1]);
3141 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
3142 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
3143 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
3144 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
3149 if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
3150 priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[1]))
3152 g_free (priv->number_up_layout_2_option->choices_display[0]);
3153 g_free (priv->number_up_layout_2_option->choices_display[1]);
3154 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
3155 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[1];
3156 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Top to bottom"));
3157 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Bottom to top"));
3161 layout = dialog_get_number_up_layout (dialog);
3163 old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
3164 if (old_option != NULL)
3165 gtk_printer_option_set_remove (set, old_option);
3167 if (dialog_get_pages_per_sheet (dialog) != 1)
3169 GEnumClass *enum_class;
3170 GEnumValue *enum_value;
3171 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
3173 if (dialog_get_pages_per_sheet (dialog) == 2)
3175 option = priv->number_up_layout_2_option;
3179 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
3180 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
3181 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
3184 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
3185 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
3186 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP);
3189 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
3190 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
3191 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM);
3194 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
3195 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
3196 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP);
3200 g_assert_not_reached();
3206 option = priv->number_up_layout_n_option;
3208 enum_value = g_enum_get_value (enum_class, layout);
3211 g_assert (enum_value != NULL);
3212 gtk_printer_option_set (option, enum_value->value_nick);
3213 g_type_class_unref (enum_class);
3215 gtk_printer_option_set_add (set, option);
3219 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
3221 if (priv->number_up_layout != NULL)
3222 gtk_widget_set_sensitive (GTK_WIDGET (priv->number_up_layout),
3223 (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) &&
3224 (dialog_get_pages_per_sheet (dialog) > 1));
3228 custom_paper_dialog_response_cb (GtkDialog *custom_paper_dialog,
3232 GtkPrintUnixDialog *print_dialog = GTK_PRINT_UNIX_DIALOG (user_data);
3233 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
3234 GtkTreeModel *model;
3237 _gtk_print_load_custom_papers (priv->custom_paper_list);
3239 priv->internal_page_setup_change = TRUE;
3240 update_paper_sizes (print_dialog);
3241 priv->internal_page_setup_change = FALSE;
3243 if (priv->page_setup_set)
3245 model = GTK_TREE_MODEL (priv->custom_paper_list);
3246 if (gtk_tree_model_get_iter_first (model, &iter))
3250 GtkPageSetup *page_setup;
3251 gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
3254 g_strcmp0 (gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size (page_setup)),
3255 gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size (priv->page_setup))) == 0)
3256 gtk_print_unix_dialog_set_page_setup (print_dialog, page_setup);
3258 g_object_unref (page_setup);
3259 } while (gtk_tree_model_iter_next (model, &iter));
3263 gtk_widget_destroy (GTK_WIDGET (custom_paper_dialog));
3267 orientation_changed (GtkComboBox *combo_box,
3268 GtkPrintUnixDialog *dialog)
3270 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3271 GtkPageOrientation orientation;
3272 GtkPageSetup *page_setup;
3274 if (priv->internal_page_setup_change)
3277 orientation = (GtkPageOrientation) gtk_combo_box_get_active (GTK_COMBO_BOX (priv->orientation_combo));
3279 if (priv->page_setup)
3281 page_setup = gtk_page_setup_copy (priv->page_setup);
3283 gtk_page_setup_set_orientation (page_setup, orientation);
3285 gtk_print_unix_dialog_set_page_setup (dialog, page_setup);
3288 redraw_page_layout_preview (dialog);
3292 paper_size_changed (GtkComboBox *combo_box,
3293 GtkPrintUnixDialog *dialog)
3295 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3297 GtkPageSetup *page_setup, *last_page_setup;
3298 GtkPageOrientation orientation;
3300 if (priv->internal_page_setup_change)
3303 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3305 gtk_tree_model_get (gtk_combo_box_get_model (combo_box),
3306 &iter, PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup, -1);
3308 if (page_setup == NULL)
3310 GtkWidget *custom_paper_dialog;
3312 /* Change from "manage" menu item to last value */
3313 if (priv->page_setup)
3314 last_page_setup = g_object_ref (priv->page_setup);
3316 last_page_setup = gtk_page_setup_new (); /* "good" default */
3318 if (!set_paper_size (dialog, last_page_setup, FALSE, FALSE))
3319 set_paper_size (dialog, last_page_setup, TRUE, TRUE);
3320 g_object_unref (last_page_setup);
3322 /* And show the custom paper dialog */
3323 custom_paper_dialog = _gtk_custom_paper_unix_dialog_new (GTK_WINDOW (dialog), _("Manage Custom Sizes"));
3324 g_signal_connect (custom_paper_dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), dialog);
3325 gtk_window_present (GTK_WINDOW (custom_paper_dialog));
3330 if (priv->page_setup)
3331 orientation = gtk_page_setup_get_orientation (priv->page_setup);
3333 orientation = GTK_PAGE_ORIENTATION_PORTRAIT;
3335 gtk_page_setup_set_orientation (page_setup, orientation);
3336 gtk_print_unix_dialog_set_page_setup (dialog, page_setup);
3338 g_object_unref (page_setup);
3341 redraw_page_layout_preview (dialog);
3345 paper_size_row_is_separator (GtkTreeModel *model,
3351 gtk_tree_model_get (model, iter, PAGE_SETUP_LIST_COL_IS_SEPARATOR, &separator, -1);
3356 page_name_func (GtkCellLayout *cell_layout,
3357 GtkCellRenderer *cell,
3358 GtkTreeModel *tree_model,
3362 GtkPageSetup *page_setup;
3363 GtkPaperSize *paper_size;
3365 gtk_tree_model_get (tree_model, iter,
3366 PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup, -1);
3369 paper_size = gtk_page_setup_get_paper_size (page_setup);
3370 g_object_set (cell, "text", gtk_paper_size_get_display_name (paper_size), NULL);
3371 g_object_unref (page_setup);
3374 g_object_set (cell, "text", _("Manage Custom Sizes..."), NULL);
3378 create_page_setup_page (GtkPrintUnixDialog *dialog)
3380 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3381 GtkWidget *main_vbox, *label, *hbox, *hbox2;
3382 GtkWidget *frame, *table, *widget;
3383 GtkWidget *combo, *spinbutton, *draw;
3384 GtkCellRenderer *cell;
3386 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
3387 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
3388 gtk_widget_show (main_vbox);
3390 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
3391 gtk_widget_show (hbox);
3392 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
3394 table = gtk_grid_new ();
3395 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3396 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3397 frame = wrap_in_frame (_("Layout"), table);
3398 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
3399 gtk_widget_show (table);
3401 label = gtk_label_new_with_mnemonic (_("T_wo-sided:"));
3402 gtk_widget_set_halign (label, GTK_ALIGN_START);
3403 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3404 gtk_widget_show (label);
3405 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3407 widget = gtk_printer_option_widget_new (NULL);
3408 priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
3409 gtk_widget_show (widget);
3410 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3411 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3413 label = gtk_label_new_with_mnemonic (_("Pages per _side:"));
3414 gtk_widget_set_halign (label, GTK_ALIGN_START);
3415 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3416 gtk_widget_show (label);
3417 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3419 widget = gtk_printer_option_widget_new (NULL);
3420 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
3421 g_signal_connect_swapped (widget, "changed", G_CALLBACK (update_number_up_layout), dialog);
3422 priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
3423 gtk_widget_show (widget);
3424 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3425 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3427 label = gtk_label_new_with_mnemonic (_("Page or_dering:"));
3428 gtk_widget_set_halign (label, GTK_ALIGN_START);
3429 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3430 gtk_widget_show (label);
3431 gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
3433 widget = gtk_printer_option_widget_new (NULL);
3434 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
3435 priv->number_up_layout = GTK_PRINTER_OPTION_WIDGET (widget);
3436 gtk_widget_show (widget);
3437 gtk_grid_attach (GTK_GRID (table), widget, 1, 2, 1, 1);
3438 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3440 label = gtk_label_new_with_mnemonic (_("_Only print:"));
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, 3, 1, 1);
3446 combo = gtk_combo_box_text_new ();
3447 priv->page_set_combo = combo;
3448 gtk_widget_show (combo);
3449 gtk_grid_attach (GTK_GRID (table), combo, 1, 3, 1, 1);
3450 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3452 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("All sheets"));
3453 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Even sheets"));
3454 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Odd sheets"));
3455 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
3457 label = gtk_label_new_with_mnemonic (_("Sc_ale:"));
3458 gtk_widget_set_halign (label, GTK_ALIGN_START);
3459 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3460 gtk_widget_show (label);
3461 gtk_grid_attach (GTK_GRID (table), label, 0, 4, 1, 1);
3463 hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
3464 gtk_widget_show (hbox2);
3465 gtk_grid_attach (GTK_GRID (table), hbox2, 1, 4, 1, 1);
3467 spinbutton = gtk_spin_button_new_with_range (1.0, 1000.0, 1.0);
3468 priv->scale_spin = spinbutton;
3469 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), 1);
3470 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton), 100.0);
3471 gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
3472 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
3473 gtk_widget_show (spinbutton);
3474 label = gtk_label_new ("%"); /* FIXMEchpe does there exist any language where % needs to be translated? */
3475 gtk_widget_show (label);
3476 gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
3478 table = gtk_grid_new ();
3479 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3480 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3481 frame = wrap_in_frame (_("Paper"), table);
3482 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
3483 gtk_widget_show (table);
3485 label = gtk_label_new_with_mnemonic (_("Paper _type:"));
3486 gtk_widget_set_halign (label, GTK_ALIGN_START);
3487 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3488 gtk_widget_show (label);
3489 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3491 widget = gtk_printer_option_widget_new (NULL);
3492 priv->paper_type = GTK_PRINTER_OPTION_WIDGET (widget);
3493 gtk_widget_show (widget);
3494 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3495 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3497 label = gtk_label_new_with_mnemonic (_("Paper _source:"));
3498 gtk_widget_set_halign (label, GTK_ALIGN_START);
3499 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3500 gtk_widget_show (label);
3501 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3503 widget = gtk_printer_option_widget_new (NULL);
3504 priv->paper_source = GTK_PRINTER_OPTION_WIDGET (widget);
3505 gtk_widget_show (widget);
3506 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3507 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3509 label = gtk_label_new_with_mnemonic (_("Output t_ray:"));
3510 gtk_widget_set_halign (label, GTK_ALIGN_START);
3511 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3512 gtk_widget_show (label);
3513 gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
3515 widget = gtk_printer_option_widget_new (NULL);
3516 priv->output_tray = GTK_PRINTER_OPTION_WIDGET (widget);
3517 gtk_widget_show (widget);
3518 gtk_grid_attach (GTK_GRID (table), widget, 1, 2, 1, 1);
3519 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3522 label = gtk_label_new_with_mnemonic (_("_Paper size:"));
3523 priv->paper_size_combo_label = GTK_WIDGET (label);
3524 gtk_widget_set_halign (label, GTK_ALIGN_START);
3525 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3526 gtk_widget_show (label);
3527 gtk_grid_attach (GTK_GRID (table), label, 0, 3, 1, 1);
3529 combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->page_setup_list));
3530 priv->paper_size_combo = GTK_WIDGET (combo);
3531 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
3532 paper_size_row_is_separator, NULL, NULL);
3533 cell = gtk_cell_renderer_text_new ();
3534 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
3535 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), cell,
3536 page_name_func, NULL, NULL);
3537 gtk_grid_attach (GTK_GRID (table), combo, 1, 3, 1, 1);
3538 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3539 gtk_widget_set_sensitive (combo, FALSE);
3540 gtk_widget_show (combo);
3542 label = gtk_label_new_with_mnemonic (_("Or_ientation:"));
3543 priv->orientation_combo_label = GTK_WIDGET (label);
3544 gtk_widget_set_halign (label, GTK_ALIGN_START);
3545 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3546 gtk_widget_show (label);
3547 gtk_grid_attach (GTK_GRID (table), label, 0, 4, 1, 1);
3549 combo = gtk_combo_box_text_new ();
3550 priv->orientation_combo = GTK_WIDGET (combo);
3551 gtk_grid_attach (GTK_GRID (table), combo, 1, 4, 1, 1);
3552 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3554 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Portrait"));
3555 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Landscape"));
3556 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Reverse portrait"));
3557 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Reverse landscape"));
3558 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
3559 gtk_widget_set_sensitive (combo, FALSE);
3560 gtk_widget_show (combo);
3563 /* Add the page layout preview */
3564 hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
3565 gtk_widget_show (hbox2);
3566 gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 0);
3568 draw = gtk_drawing_area_new ();
3569 gtk_widget_set_has_window (draw, FALSE);
3570 priv->page_layout_preview = draw;
3571 gtk_widget_set_size_request (draw, 280, 160);
3572 g_signal_connect (draw, "draw", G_CALLBACK (draw_page_cb), dialog);
3573 gtk_widget_show (draw);
3575 gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 0);
3577 label = gtk_label_new (_("Page Setup"));
3578 gtk_widget_show (label);
3580 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3585 create_job_page (GtkPrintUnixDialog *dialog)
3587 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3588 GtkWidget *main_table, *label;
3589 GtkWidget *frame, *table, *radio;
3590 GtkWidget *entry, *widget;
3591 const gchar *at_tooltip;
3592 const gchar *on_hold_tooltip;
3594 main_table = gtk_grid_new ();
3595 gtk_container_set_border_width (GTK_CONTAINER (main_table), 12);
3596 gtk_grid_set_row_spacing (GTK_GRID (main_table), 18);
3597 gtk_grid_set_column_spacing (GTK_GRID (main_table), 18);
3599 table = gtk_grid_new ();
3600 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3601 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3602 frame = wrap_in_frame (_("Job Details"), table);
3603 gtk_grid_attach (GTK_GRID (main_table), frame, 0, 0, 1, 1);
3604 gtk_widget_show (table);
3606 label = gtk_label_new_with_mnemonic (_("Pri_ority:"));
3607 gtk_widget_set_halign (label, GTK_ALIGN_START);
3608 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3609 gtk_widget_show (label);
3610 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3612 widget = gtk_printer_option_widget_new (NULL);
3613 priv->job_prio = GTK_PRINTER_OPTION_WIDGET (widget);
3614 gtk_widget_show (widget);
3615 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3616 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3618 label = gtk_label_new_with_mnemonic (_("_Billing info:"));
3619 gtk_widget_set_halign (label, GTK_ALIGN_START);
3620 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3621 gtk_widget_show (label);
3622 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3624 widget = gtk_printer_option_widget_new (NULL);
3625 priv->billing_info = GTK_PRINTER_OPTION_WIDGET (widget);
3626 gtk_widget_show (widget);
3627 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3628 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3630 table = gtk_grid_new ();
3631 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3632 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3633 frame = wrap_in_frame (_("Print Document"), table);
3634 gtk_grid_attach (GTK_GRID (main_table), frame, 0, 1, 1, 1);
3635 gtk_widget_show (table);
3637 /* Translators: this is one of the choices for the print at option
3638 * in the print dialog
3640 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Now"));
3641 priv->print_now_radio = radio;
3642 gtk_widget_show (radio);
3643 gtk_grid_attach (GTK_GRID (table), radio, 0, 0, 2, 1);
3644 /* Translators: this is one of the choices for the print at option
3645 * in the print dialog. It also serves as the label for an entry that
3646 * allows the user to enter a time.
3648 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
3651 /* Translators: Ability to parse the am/pm format depends on actual locale.
3652 * You can remove the am/pm values below for your locale if they are not
3655 at_tooltip = _("Specify the time of print,\n e.g. 15:30, 2:35 pm, 14:15:20, 11:46:30 am, 4 pm");
3656 gtk_widget_set_tooltip_text (radio, at_tooltip);
3657 priv->print_at_radio = radio;
3658 gtk_widget_show (radio);
3659 gtk_grid_attach (GTK_GRID (table), radio, 0, 1, 1, 1);
3661 entry = gtk_entry_new ();
3662 gtk_widget_set_tooltip_text (entry, at_tooltip);
3663 atk_object_set_name (gtk_widget_get_accessible (entry), _("Time of print"));
3664 atk_object_set_description (gtk_widget_get_accessible (entry), at_tooltip);
3665 priv->print_at_entry = entry;
3666 gtk_widget_show (entry);
3667 gtk_grid_attach (GTK_GRID (table), entry, 1, 1, 1, 1);
3669 g_signal_connect (radio, "toggled", G_CALLBACK (update_entry_sensitivity), entry);
3670 update_entry_sensitivity (radio, entry);
3672 /* Translators: this is one of the choices for the print at option
3673 * in the print dialog. It means that the print job will not be
3674 * printed until it explicitly gets 'released'.
3676 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
3678 on_hold_tooltip = _("Hold the job until it is explicitly released");
3679 gtk_widget_set_tooltip_text (radio, on_hold_tooltip);
3680 priv->print_hold_radio = radio;
3681 gtk_widget_show (radio);
3682 gtk_grid_attach (GTK_GRID (table), radio, 0, 2, 2, 1);
3684 g_signal_connect_swapped (priv->print_now_radio, "toggled",
3685 G_CALLBACK (update_print_at_option), dialog);
3686 g_signal_connect_swapped (priv->print_at_radio, "toggled",
3687 G_CALLBACK (update_print_at_option), dialog);
3688 g_signal_connect_swapped (priv->print_at_entry, "changed",
3689 G_CALLBACK (update_print_at_option), dialog);
3690 g_signal_connect_swapped (priv->print_hold_radio, "toggled",
3691 G_CALLBACK (update_print_at_option), dialog);
3693 table = gtk_grid_new ();
3694 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3695 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3696 frame = wrap_in_frame (_("Add Cover Page"), table);
3697 gtk_grid_attach (GTK_GRID (main_table), frame, 1, 0, 1, 1);
3698 gtk_widget_show (table);
3700 /* Translators, this is the label used for the option in the print
3701 * dialog that controls the front cover page.
3703 label = gtk_label_new_with_mnemonic (_("Be_fore:"));
3704 gtk_widget_set_halign (label, GTK_ALIGN_START);
3705 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3706 gtk_widget_show (label);
3707 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3709 widget = gtk_printer_option_widget_new (NULL);
3710 priv->cover_before = GTK_PRINTER_OPTION_WIDGET (widget);
3711 gtk_widget_show (widget);
3712 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3713 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3715 /* Translators, this is the label used for the option in the print
3716 * dialog that controls the back cover page.
3718 label = gtk_label_new_with_mnemonic (_("_After:"));
3719 gtk_widget_set_halign (label, GTK_ALIGN_START);
3720 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3721 gtk_widget_show (label);
3722 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3724 widget = gtk_printer_option_widget_new (NULL);
3725 priv->cover_after = GTK_PRINTER_OPTION_WIDGET (widget);
3726 gtk_widget_show (widget);
3727 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3728 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3730 /* Translators: this is the tab label for the notebook tab containing
3731 * job-specific options in the print dialog
3733 label = gtk_label_new (_("Job"));
3734 gtk_widget_show (label);
3736 priv->job_page = main_table;
3737 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3742 create_optional_page (GtkPrintUnixDialog *dialog,
3744 GtkWidget **table_out,
3745 GtkWidget **page_out)
3747 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3748 GtkWidget *table, *label, *scrolled;
3750 scrolled = gtk_scrolled_window_new (NULL, NULL);
3751 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
3753 GTK_POLICY_AUTOMATIC);
3755 table = gtk_grid_new ();
3756 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3757 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3758 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
3759 gtk_widget_show (table);
3761 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
3763 gtk_viewport_set_shadow_type (GTK_VIEWPORT (gtk_bin_get_child (GTK_BIN (scrolled))),
3766 label = gtk_label_new (text);
3767 gtk_widget_show (label);
3769 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3773 *page_out = scrolled;
3777 create_advanced_page (GtkPrintUnixDialog *dialog)
3779 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3780 GtkWidget *main_vbox, *label, *scrolled;
3782 scrolled = gtk_scrolled_window_new (NULL, NULL);
3783 priv->advanced_page = scrolled;
3784 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
3786 GTK_POLICY_AUTOMATIC);
3788 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
3789 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
3790 gtk_widget_show (main_vbox);
3792 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
3794 gtk_viewport_set_shadow_type (GTK_VIEWPORT (gtk_bin_get_child (GTK_BIN (scrolled))),
3797 priv->advanced_vbox = main_vbox;
3799 label = gtk_label_new (_("Advanced"));
3800 gtk_widget_show (label);
3802 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3807 populate_dialog (GtkPrintUnixDialog *print_dialog)
3809 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
3810 GtkDialog *dialog = GTK_DIALOG (print_dialog);
3811 GtkWidget *vbox, *conflict_hbox, *image, *label;
3812 GtkWidget *action_area, *content_area;
3814 content_area = gtk_dialog_get_content_area (dialog);
3815 action_area = gtk_dialog_get_action_area (dialog);
3817 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
3818 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
3819 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
3820 gtk_box_set_spacing (GTK_BOX (action_area), 6);
3822 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
3823 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
3824 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
3825 gtk_widget_show (vbox);
3827 priv->notebook = gtk_notebook_new ();
3828 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
3829 gtk_widget_show (priv->notebook);
3831 create_printer_list_model (print_dialog);
3833 create_main_page (print_dialog);
3834 create_page_setup_page (print_dialog);
3835 create_job_page (print_dialog);
3836 /* Translators: this will appear as tab label in print dialog. */
3837 create_optional_page (print_dialog, _("Image Quality"),
3838 &priv->image_quality_table,
3839 &priv->image_quality_page);
3840 /* Translators: this will appear as tab label in print dialog. */
3841 create_optional_page (print_dialog, _("Color"),
3844 /* Translators: this will appear as tab label in print dialog. */
3845 /* It's a typographical term, as in "Binding and finishing" */
3846 create_optional_page (print_dialog, _("Finishing"),
3847 &priv->finishing_table,
3848 &priv->finishing_page);
3849 create_advanced_page (print_dialog);
3851 priv->conflicts_widget = conflict_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
3852 gtk_box_pack_end (GTK_BOX (vbox), conflict_hbox, FALSE, FALSE, 0);
3853 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
3854 gtk_widget_show (image);
3855 gtk_box_pack_start (GTK_BOX (conflict_hbox), image, FALSE, TRUE, 0);
3856 label = gtk_label_new (_("Some of the settings in the dialog conflict"));
3857 gtk_widget_show (label);
3858 gtk_box_pack_start (GTK_BOX (conflict_hbox), label, FALSE, TRUE, 0);
3860 load_print_backends (print_dialog);
3864 * gtk_print_unix_dialog_new:
3865 * @title: (allow-none): Title of the dialog, or %NULL
3866 * @parent: (allow-none): Transient parent of the dialog, or %NULL
3868 * Creates a new #GtkPrintUnixDialog.
3870 * Return value: a new #GtkPrintUnixDialog
3875 gtk_print_unix_dialog_new (const gchar *title,
3879 const gchar *_title = _("Print");
3884 result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
3885 "transient-for", parent,
3893 * gtk_print_unix_dialog_get_selected_printer:
3894 * @dialog: a #GtkPrintUnixDialog
3896 * Gets the currently selected printer.
3898 * Returns: (transfer none): the currently selected printer
3903 gtk_print_unix_dialog_get_selected_printer (GtkPrintUnixDialog *dialog)
3905 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3907 return dialog->priv->current_printer;
3911 * gtk_print_unix_dialog_set_page_setup:
3912 * @dialog: a #GtkPrintUnixDialog
3913 * @page_setup: a #GtkPageSetup
3915 * Sets the page setup of the #GtkPrintUnixDialog.
3920 gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
3921 GtkPageSetup *page_setup)
3923 GtkPrintUnixDialogPrivate *priv;
3925 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3926 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
3928 priv = dialog->priv;
3930 if (priv->page_setup != page_setup)
3932 g_object_unref (priv->page_setup);
3933 priv->page_setup = g_object_ref (page_setup);
3935 priv->page_setup_set = TRUE;
3937 g_object_notify (G_OBJECT (dialog), "page-setup");
3942 * gtk_print_unix_dialog_get_page_setup:
3943 * @dialog: a #GtkPrintUnixDialog
3945 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3947 * Returns: (transfer none): the page setup of @dialog.
3952 gtk_print_unix_dialog_get_page_setup (GtkPrintUnixDialog *dialog)
3954 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3956 return dialog->priv->page_setup;
3960 * gtk_print_unix_dialog_get_page_setup_set:
3961 * @dialog: a #GtkPrintUnixDialog
3963 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3965 * Returns: whether a page setup was set by user.
3970 gtk_print_unix_dialog_get_page_setup_set (GtkPrintUnixDialog *dialog)
3972 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
3974 return dialog->priv->page_setup_set;
3978 * gtk_print_unix_dialog_set_current_page:
3979 * @dialog: a #GtkPrintUnixDialog
3980 * @current_page: the current page number.
3982 * Sets the current page number. If @current_page is not -1, this enables
3983 * the current page choice for the range of pages to print.
3988 gtk_print_unix_dialog_set_current_page (GtkPrintUnixDialog *dialog,
3991 GtkPrintUnixDialogPrivate *priv;
3993 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3995 priv = dialog->priv;
3997 if (priv->current_page != current_page)
3999 priv->current_page = current_page;
4001 if (priv->current_page_radio)
4002 gtk_widget_set_sensitive (priv->current_page_radio, current_page != -1);
4004 g_object_notify (G_OBJECT (dialog), "current-page");
4009 * gtk_print_unix_dialog_get_current_page:
4010 * @dialog: a #GtkPrintUnixDialog
4012 * Gets the current page of the #GtkPrintDialog.
4014 * Returns: the current page of @dialog
4019 gtk_print_unix_dialog_get_current_page (GtkPrintUnixDialog *dialog)
4021 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), -1);
4023 return dialog->priv->current_page;
4027 set_active_printer (GtkPrintUnixDialog *dialog,
4028 const gchar *printer_name)
4030 GtkPrintUnixDialogPrivate *priv = dialog->priv;
4031 GtkTreeModel *model;
4032 GtkTreeIter iter, filter_iter;
4033 GtkTreeSelection *selection;
4034 GtkPrinter *printer;
4036 model = GTK_TREE_MODEL (priv->printer_list);
4038 if (gtk_tree_model_get_iter_first (model, &iter))
4042 gtk_tree_model_get (GTK_TREE_MODEL (priv->printer_list), &iter,
4043 PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
4044 if (printer == NULL)
4047 if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
4049 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
4050 &filter_iter, &iter);
4052 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
4053 priv->internal_printer_change = TRUE;
4054 gtk_tree_selection_select_iter (selection, &filter_iter);
4055 priv->internal_printer_change = FALSE;
4056 g_free (priv->waiting_for_printer);
4057 priv->waiting_for_printer = NULL;
4059 g_object_unref (printer);
4063 g_object_unref (printer);
4065 } while (gtk_tree_model_iter_next (model, &iter));
4072 * gtk_print_unix_dialog_set_settings:
4073 * @dialog: a #GtkPrintUnixDialog
4074 * @settings: (allow-none): a #GtkPrintSettings, or %NULL
4076 * Sets the #GtkPrintSettings for the #GtkPrintUnixDialog. Typically,
4077 * this is used to restore saved print settings from a previous print
4078 * operation before the print dialog is shown.
4083 gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
4084 GtkPrintSettings *settings)
4086 GtkPrintUnixDialogPrivate *priv;
4087 const gchar *printer;
4088 GtkPageRange *ranges;
4091 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4092 g_return_if_fail (settings == NULL || GTK_IS_PRINT_SETTINGS (settings));
4094 priv = dialog->priv;
4096 if (settings != NULL)
4098 dialog_set_collate (dialog, gtk_print_settings_get_collate (settings));
4099 dialog_set_reverse (dialog, gtk_print_settings_get_reverse (settings));
4100 dialog_set_n_copies (dialog, gtk_print_settings_get_n_copies (settings));
4101 dialog_set_scale (dialog, gtk_print_settings_get_scale (settings));
4102 dialog_set_page_set (dialog, gtk_print_settings_get_page_set (settings));
4103 dialog_set_print_pages (dialog, gtk_print_settings_get_print_pages (settings));
4104 ranges = gtk_print_settings_get_page_ranges (settings, &num_ranges);
4107 dialog_set_page_ranges (dialog, ranges, num_ranges);
4111 priv->format_for_printer =
4112 g_strdup (gtk_print_settings_get (settings, "format-for-printer"));
4115 if (priv->initial_settings)
4116 g_object_unref (priv->initial_settings);
4118 priv->initial_settings = settings;
4120 g_free (priv->waiting_for_printer);
4121 priv->waiting_for_printer = NULL;
4125 g_object_ref (settings);
4127 printer = gtk_print_settings_get_printer (settings);
4129 if (printer && !set_active_printer (dialog, printer))
4130 priv->waiting_for_printer = g_strdup (printer);
4133 g_object_notify (G_OBJECT (dialog), "print-settings");
4137 * gtk_print_unix_dialog_get_settings:
4138 * @dialog: a #GtkPrintUnixDialog
4140 * Gets a new #GtkPrintSettings object that represents the
4141 * current values in the print dialog. Note that this creates a
4142 * <emphasis>new object</emphasis>, and you need to unref it
4143 * if don't want to keep it.
4145 * Returns: a new #GtkPrintSettings object with the values from @dialog
4150 gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
4152 GtkPrintUnixDialogPrivate *priv;
4153 GtkPrintSettings *settings;
4154 GtkPrintPages print_pages;
4155 GtkPageRange *ranges;
4158 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
4160 priv = dialog->priv;
4161 settings = gtk_print_settings_new ();
4163 if (priv->current_printer)
4164 gtk_print_settings_set_printer (settings,
4165 gtk_printer_get_name (priv->current_printer));
4167 gtk_print_settings_set_printer (settings, "default");
4169 gtk_print_settings_set (settings, "format-for-printer",
4170 priv->format_for_printer);
4172 gtk_print_settings_set_collate (settings,
4173 dialog_get_collate (dialog));
4175 gtk_print_settings_set_reverse (settings,
4176 dialog_get_reverse (dialog));
4178 gtk_print_settings_set_n_copies (settings,
4179 dialog_get_n_copies (dialog));
4181 gtk_print_settings_set_scale (settings,
4182 dialog_get_scale (dialog));
4184 gtk_print_settings_set_page_set (settings,
4185 dialog_get_page_set (dialog));
4187 print_pages = dialog_get_print_pages (dialog);
4188 gtk_print_settings_set_print_pages (settings, print_pages);
4190 ranges = dialog_get_page_ranges (dialog, &n_ranges);
4193 gtk_print_settings_set_page_ranges (settings, ranges, n_ranges);
4197 /* TODO: print when. How to handle? */
4199 if (priv->current_printer)
4200 _gtk_printer_get_settings_from_options (priv->current_printer,
4208 * gtk_print_unix_dialog_add_custom_tab:
4209 * @dialog: a #GtkPrintUnixDialog
4210 * @child: the widget to put in the custom tab
4211 * @tab_label: the widget to use as tab label
4213 * Adds a custom tab to the print dialog.
4218 gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
4220 GtkWidget *tab_label)
4222 gtk_notebook_insert_page (GTK_NOTEBOOK (dialog->priv->notebook),
4223 child, tab_label, 2);
4224 gtk_widget_show (child);
4225 gtk_widget_show (tab_label);
4229 * gtk_print_unix_dialog_set_manual_capabilities:
4230 * @dialog: a #GtkPrintUnixDialog
4231 * @capabilities: the printing capabilities of your application
4233 * This lets you specify the printing capabilities your application
4234 * supports. For instance, if you can handle scaling the output then
4235 * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then
4236 * the dialog will only let you select the scale if the printing
4237 * system automatically handles scaling.
4242 gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog,
4243 GtkPrintCapabilities capabilities)
4245 GtkPrintUnixDialogPrivate *priv = dialog->priv;
4247 if (priv->manual_capabilities != capabilities)
4249 priv->manual_capabilities = capabilities;
4250 update_dialog_from_capabilities (dialog);
4252 if (priv->current_printer)
4254 GtkTreeSelection *selection;
4256 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
4258 g_object_unref (priv->current_printer);
4259 priv->current_printer = NULL;
4260 priv->internal_printer_change = TRUE;
4261 selected_printer_changed (selection, dialog);
4262 priv->internal_printer_change = FALSE;
4265 g_object_notify (G_OBJECT (dialog), "manual-capabilities");
4270 * gtk_print_unix_dialog_get_manual_capabilities:
4271 * @dialog: a #GtkPrintUnixDialog
4273 * Gets the value of #GtkPrintUnixDialog:manual-capabilities property.
4275 * Returns: the printing capabilities
4279 GtkPrintCapabilities
4280 gtk_print_unix_dialog_get_manual_capabilities (GtkPrintUnixDialog *dialog)
4282 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4284 return dialog->priv->manual_capabilities;
4288 * gtk_print_unix_dialog_set_support_selection:
4289 * @dialog: a #GtkPrintUnixDialog
4290 * @support_selection: %TRUE to allow print selection
4292 * Sets whether the print dialog allows user to print a selection.
4297 gtk_print_unix_dialog_set_support_selection (GtkPrintUnixDialog *dialog,
4298 gboolean support_selection)
4300 GtkPrintUnixDialogPrivate *priv;
4302 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4304 priv = dialog->priv;
4306 support_selection = support_selection != FALSE;
4307 if (priv->support_selection != support_selection)
4309 priv->support_selection = support_selection;
4311 if (priv->selection_radio)
4313 if (support_selection)
4315 gtk_widget_set_sensitive (priv->selection_radio, priv->has_selection);
4316 gtk_widget_show (priv->selection_radio);
4320 gtk_widget_set_sensitive (priv->selection_radio, FALSE);
4321 gtk_widget_hide (priv->selection_radio);
4325 g_object_notify (G_OBJECT (dialog), "support-selection");
4330 * gtk_print_unix_dialog_get_support_selection:
4331 * @dialog: a #GtkPrintUnixDialog
4333 * Gets the value of #GtkPrintUnixDialog:support-selection property.
4335 * Returns: whether the application supports print of selection
4340 gtk_print_unix_dialog_get_support_selection (GtkPrintUnixDialog *dialog)
4342 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4344 return dialog->priv->support_selection;
4348 * gtk_print_unix_dialog_set_has_selection:
4349 * @dialog: a #GtkPrintUnixDialog
4350 * @has_selection: %TRUE indicates that a selection exists
4352 * Sets whether a selection exists.
4357 gtk_print_unix_dialog_set_has_selection (GtkPrintUnixDialog *dialog,
4358 gboolean has_selection)
4360 GtkPrintUnixDialogPrivate *priv;
4362 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4364 priv = dialog->priv;
4366 has_selection = has_selection != FALSE;
4367 if (priv->has_selection != has_selection)
4369 priv->has_selection = has_selection;
4371 if (priv->selection_radio)
4373 if (priv->support_selection)
4374 gtk_widget_set_sensitive (priv->selection_radio, has_selection);
4376 gtk_widget_set_sensitive (priv->selection_radio, FALSE);
4379 g_object_notify (G_OBJECT (dialog), "has-selection");
4384 * gtk_print_unix_dialog_get_has_selection:
4385 * @dialog: a #GtkPrintUnixDialog
4387 * Gets the value of #GtkPrintUnixDialog:has-selection property.
4389 * Returns: whether there is a selection
4394 gtk_print_unix_dialog_get_has_selection (GtkPrintUnixDialog *dialog)
4396 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4398 return dialog->priv->has_selection;
4402 * gtk_print_unix_dialog_set_embed_page_setup
4403 * @dialog: a #GtkPrintUnixDialog
4404 * @embed: embed page setup selection
4406 * Embed page size combo box and orientation combo box into page setup page.
4411 gtk_print_unix_dialog_set_embed_page_setup (GtkPrintUnixDialog *dialog,
4414 GtkPrintUnixDialogPrivate *priv;
4416 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4418 priv = dialog->priv;
4420 embed = embed != FALSE;
4421 if (priv->embed_page_setup != embed)
4423 priv->embed_page_setup = embed;
4425 gtk_widget_set_sensitive (priv->paper_size_combo, priv->embed_page_setup);
4426 gtk_widget_set_sensitive (priv->orientation_combo, priv->embed_page_setup);
4428 if (priv->embed_page_setup)
4430 if (priv->paper_size_combo != NULL)
4431 g_signal_connect (priv->paper_size_combo, "changed", G_CALLBACK (paper_size_changed), dialog);
4433 if (priv->orientation_combo)
4434 g_signal_connect (priv->orientation_combo, "changed", G_CALLBACK (orientation_changed), dialog);
4438 if (priv->paper_size_combo != NULL)
4439 g_signal_handlers_disconnect_by_func (priv->paper_size_combo, G_CALLBACK (paper_size_changed), dialog);
4441 if (priv->orientation_combo)
4442 g_signal_handlers_disconnect_by_func (priv->orientation_combo, G_CALLBACK (orientation_changed), dialog);
4445 priv->internal_page_setup_change = TRUE;
4446 update_paper_sizes (dialog);
4447 priv->internal_page_setup_change = FALSE;
4452 * gtk_print_unix_dialog_get_embed_page_setup:
4453 * @dialog: a #GtkPrintUnixDialog
4455 * Gets the value of #GtkPrintUnixDialog:embed-page-setup property.
4457 * Returns: whether there is a selection
4462 gtk_print_unix_dialog_get_embed_page_setup (GtkPrintUnixDialog *dialog)
4464 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4466 return dialog->priv->embed_page_setup;