2 * Copyright (C) 2006 John (J5) Palmieri <johnp@redhat.com>
3 * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
4 * Copyright © 2006, 2007 Christian Persch
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
30 #include "gtkprintunixdialog.h"
32 #include "gtkcustompaperunixdialog.h"
33 #include "gtkprintbackend.h"
34 #include "gtkprinter-private.h"
35 #include "gtkprinteroptionwidget.h"
36 #include "gtkprintutils.h"
38 #include "gtkspinbutton.h"
39 #include "gtkcellrendererpixbuf.h"
40 #include "gtkcellrenderertext.h"
42 #include "gtkiconfactory.h"
44 #include "gtktreeselection.h"
45 #include "gtknotebook.h"
46 #include "gtkscrolledwindow.h"
47 #include "gtkcombobox.h"
48 #include "gtktogglebutton.h"
49 #include "gtkradiobutton.h"
50 #include "gtkdrawingarea.h"
55 #include "gtkeventbox.h"
56 #include "gtkbuildable.h"
57 #include "gtkmessagedialog.h"
58 #include "gtkbutton.h"
60 #include "gtkprivate.h"
61 #include "gtktypebuiltins.h"
65 * SECTION:gtkprintunixdialog
66 * @Short_description: A print dialog
67 * @Title: GtkPrintUnixDialog
68 * @See_also: #GtkPageSetupUnixDialog, #GtkPrinter, #GtkPrintJob
70 * GtkPrintUnixDialog implements a print dialog for platforms
71 * which don't provide a native print dialog, like Unix. It can
72 * be used very much like any other GTK+ dialog, at the cost of
73 * the portability offered by the
74 * <link linkend="gtk-High-level-Printing-API">high-level printing API</link>
76 * In order to print something with #GtkPrintUnixDialog, you need
77 * to use gtk_print_unix_dialog_get_selected_printer() to obtain
78 * a #GtkPrinter object and use it to construct a #GtkPrintJob using
79 * gtk_print_job_new().
81 * #GtkPrintUnixDialog uses the following response values:
83 * <varlistentry><term>%GTK_RESPONSE_OK</term>
84 * <listitem><para>for the "Print" button</para></listitem>
86 * <varlistentry><term>%GTK_RESPONSE_APPLY</term>
87 * <listitem><para>for the "Preview" button</para></listitem>
89 * <varlistentry><term>%GTK_RESPONSE_CANCEL</term>
90 * <listitem><para>for the "Cancel" button</para></listitem>
94 * <!-- FIXME example here -->
96 * Printing support was added in GTK+ 2.10.
98 * <refsect2 id="GtkPrintUnixDialog-BUILDER-UI">
99 * <title>GtkPrintUnixDialog as GtkBuildable</title>
101 * The GtkPrintUnixDialog implementation of the GtkBuildable interface exposes its
102 * @notebook internal children with the name "notebook".
105 * <title>A <structname>GtkPrintUnixDialog</structname> UI definition fragment.</title>
106 * <programlisting><![CDATA[
107 * <object class="GtkPrintUnixDialog" id="dialog1">
108 * <child internal-child="notebook">
109 * <object class="GtkNotebook" id="notebook">
111 * <object class="GtkLabel" id="tabcontent">
112 * <property name="label">Content on notebook tab</property>
116 * <object class="GtkLabel" id="tablabel">
117 * <property name="label">Tab label</property>
120 * <property name="tab_expand">False</property>
121 * <property name="tab_fill">False</property>
127 * ]]></programlisting>
134 #define EXAMPLE_PAGE_AREA_SIZE 110
135 #define RULER_DISTANCE 7.5
136 #define RULER_RADIUS 2
139 static void gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog);
140 static void gtk_print_unix_dialog_finalize (GObject *object);
141 static void gtk_print_unix_dialog_set_property (GObject *object,
145 static void gtk_print_unix_dialog_get_property (GObject *object,
149 static void gtk_print_unix_dialog_style_updated (GtkWidget *widget);
150 static void populate_dialog (GtkPrintUnixDialog *dialog);
151 static void unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog);
152 static void selected_printer_changed (GtkTreeSelection *selection,
153 GtkPrintUnixDialog *dialog);
154 static void clear_per_printer_ui (GtkPrintUnixDialog *dialog);
155 static void printer_added_cb (GtkPrintBackend *backend,
157 GtkPrintUnixDialog *dialog);
158 static void printer_removed_cb (GtkPrintBackend *backend,
160 GtkPrintUnixDialog *dialog);
161 static void printer_status_cb (GtkPrintBackend *backend,
163 GtkPrintUnixDialog *dialog);
164 static void update_collate_icon (GtkToggleButton *toggle_button,
165 GtkPrintUnixDialog *dialog);
166 static gboolean dialog_get_collate (GtkPrintUnixDialog *dialog);
167 static gboolean dialog_get_reverse (GtkPrintUnixDialog *dialog);
168 static gint dialog_get_n_copies (GtkPrintUnixDialog *dialog);
170 static void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
171 GtkCellRenderer *cell,
175 static gboolean set_active_printer (GtkPrintUnixDialog *dialog,
176 const gchar *printer_name);
177 static void redraw_page_layout_preview (GtkPrintUnixDialog *dialog);
180 static void gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface);
181 static GObject *gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
183 const gchar *childname);
185 static const gchar const common_paper_sizes[][16] = {
201 PAGE_SETUP_LIST_COL_PAGE_SETUP,
202 PAGE_SETUP_LIST_COL_IS_SEPARATOR,
203 PAGE_SETUP_LIST_N_COLS
211 PROP_SELECTED_PRINTER,
212 PROP_MANUAL_CAPABILITIES,
213 PROP_SUPPORT_SELECTION,
215 PROP_EMBED_PAGE_SETUP
219 PRINTER_LIST_COL_ICON,
220 PRINTER_LIST_COL_NAME,
221 PRINTER_LIST_COL_STATE,
222 PRINTER_LIST_COL_JOBS,
223 PRINTER_LIST_COL_LOCATION,
224 PRINTER_LIST_COL_PRINTER_OBJ,
228 struct GtkPrintUnixDialogPrivate
232 GtkWidget *printer_treeview;
234 GtkPrintCapabilities manual_capabilities;
235 GtkPrintCapabilities printer_capabilities;
237 GtkTreeModel *printer_list;
238 GtkTreeModelFilter *printer_list_filter;
240 GtkPageSetup *page_setup;
241 gboolean page_setup_set;
242 gboolean embed_page_setup;
243 GtkListStore *page_setup_list;
244 GtkListStore *custom_paper_list;
246 gboolean support_selection;
247 gboolean has_selection;
249 GtkWidget *all_pages_radio;
250 GtkWidget *current_page_radio;
251 GtkWidget *selection_radio;
252 GtkWidget *range_table;
253 GtkWidget *page_range_radio;
254 GtkWidget *page_range_entry;
256 GtkWidget *copies_spin;
257 GtkWidget *collate_check;
258 GtkWidget *reverse_check;
259 GtkWidget *collate_image;
260 GtkWidget *page_layout_preview;
261 GtkWidget *scale_spin;
262 GtkWidget *page_set_combo;
263 GtkWidget *print_now_radio;
264 GtkWidget *print_at_radio;
265 GtkWidget *print_at_entry;
266 GtkWidget *print_hold_radio;
267 GtkWidget *preview_button;
268 GtkWidget *paper_size_combo;
269 GtkWidget *paper_size_combo_label;
270 GtkWidget *orientation_combo;
271 GtkWidget *orientation_combo_label;
272 gboolean internal_page_setup_change;
273 gboolean updating_print_at;
274 GtkPrinterOptionWidget *pages_per_sheet;
275 GtkPrinterOptionWidget *duplex;
276 GtkPrinterOptionWidget *paper_type;
277 GtkPrinterOptionWidget *paper_source;
278 GtkPrinterOptionWidget *output_tray;
279 GtkPrinterOptionWidget *job_prio;
280 GtkPrinterOptionWidget *billing_info;
281 GtkPrinterOptionWidget *cover_before;
282 GtkPrinterOptionWidget *cover_after;
283 GtkPrinterOptionWidget *number_up_layout;
285 GtkWidget *conflicts_widget;
288 GtkWidget *finishing_table;
289 GtkWidget *finishing_page;
290 GtkWidget *image_quality_table;
291 GtkWidget *image_quality_page;
292 GtkWidget *color_table;
293 GtkWidget *color_page;
295 GtkWidget *advanced_vbox;
296 GtkWidget *advanced_page;
298 GtkWidget *extension_point;
300 /* These are set initially on selected printer (either default printer,
301 * printer taken from set settings, or user-selected), but when any
302 * setting is changed by the user it is cleared.
304 GtkPrintSettings *initial_settings;
306 GtkPrinterOption *number_up_layout_n_option;
307 GtkPrinterOption *number_up_layout_2_option;
309 /* This is the initial printer set by set_settings. We look for it in
310 * the added printers. We clear this whenever the user manually changes
311 * to another printer, when the user changes a setting or when we find
314 char *waiting_for_printer;
315 gboolean internal_printer_change;
317 GList *print_backends;
319 GtkPrinter *current_printer;
320 GtkPrinter *request_details_printer;
321 gulong request_details_tag;
322 GtkPrinterOptionSet *options;
323 gulong options_changed_handler;
324 gulong mark_conflicts_id;
326 gchar *format_for_printer;
331 G_DEFINE_TYPE_WITH_CODE (GtkPrintUnixDialog, gtk_print_unix_dialog, GTK_TYPE_DIALOG,
332 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
333 gtk_print_unix_dialog_buildable_init))
335 static GtkBuildableIface *parent_buildable_iface;
338 is_default_printer (GtkPrintUnixDialog *dialog,
341 GtkPrintUnixDialogPrivate *priv = dialog->priv;
343 if (priv->format_for_printer)
344 return strcmp (priv->format_for_printer,
345 gtk_printer_get_name (printer)) == 0;
347 return gtk_printer_is_default (printer);
351 gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
353 GObjectClass *object_class;
354 GtkWidgetClass *widget_class;
356 object_class = (GObjectClass *) class;
357 widget_class = (GtkWidgetClass *) class;
359 object_class->finalize = gtk_print_unix_dialog_finalize;
360 object_class->set_property = gtk_print_unix_dialog_set_property;
361 object_class->get_property = gtk_print_unix_dialog_get_property;
363 widget_class->style_updated = gtk_print_unix_dialog_style_updated;
365 g_object_class_install_property (object_class,
367 g_param_spec_object ("page-setup",
369 P_("The GtkPageSetup to use"),
371 GTK_PARAM_READWRITE));
373 g_object_class_install_property (object_class,
375 g_param_spec_int ("current-page",
377 P_("The current page in the document"),
381 GTK_PARAM_READWRITE));
383 g_object_class_install_property (object_class,
385 g_param_spec_object ("print-settings",
386 P_("Print Settings"),
387 P_("The GtkPrintSettings used for initializing the dialog"),
388 GTK_TYPE_PRINT_SETTINGS,
389 GTK_PARAM_READWRITE));
391 g_object_class_install_property (object_class,
392 PROP_SELECTED_PRINTER,
393 g_param_spec_object ("selected-printer",
394 P_("Selected Printer"),
395 P_("The GtkPrinter which is selected"),
397 GTK_PARAM_READABLE));
399 g_object_class_install_property (object_class,
400 PROP_MANUAL_CAPABILITIES,
401 g_param_spec_flags ("manual-capabilities",
402 P_("Manual Capabilities"),
403 P_("Capabilities the application can handle"),
404 GTK_TYPE_PRINT_CAPABILITIES,
406 GTK_PARAM_READWRITE));
408 g_object_class_install_property (object_class,
409 PROP_SUPPORT_SELECTION,
410 g_param_spec_boolean ("support-selection",
411 P_("Support Selection"),
412 P_("Whether the dialog supports selection"),
414 GTK_PARAM_READWRITE));
416 g_object_class_install_property (object_class,
418 g_param_spec_boolean ("has-selection",
420 P_("Whether the application has a selection"),
422 GTK_PARAM_READWRITE));
424 g_object_class_install_property (object_class,
425 PROP_EMBED_PAGE_SETUP,
426 g_param_spec_boolean ("embed-page-setup",
427 P_("Embed Page Setup"),
428 P_("TRUE if page setup combos are embedded in GtkPrintUnixDialog"),
430 GTK_PARAM_READWRITE));
432 g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));
435 /* Returns a toplevel GtkWindow, or NULL if none */
437 get_toplevel (GtkWidget *widget)
439 GtkWidget *toplevel = NULL;
441 toplevel = gtk_widget_get_toplevel (widget);
442 if (!gtk_widget_is_toplevel (toplevel))
445 return GTK_WINDOW (toplevel);
449 set_busy_cursor (GtkPrintUnixDialog *dialog,
457 toplevel = get_toplevel (GTK_WIDGET (dialog));
458 widget = GTK_WIDGET (toplevel);
460 if (!toplevel || !gtk_widget_get_realized (widget))
463 display = gtk_widget_get_display (widget);
466 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
470 gdk_window_set_cursor (gtk_widget_get_window (widget),
472 gdk_display_flush (display);
475 g_object_unref (cursor);
479 add_custom_button_to_dialog (GtkDialog *dialog,
480 const gchar *mnemonic_label,
481 const gchar *stock_id,
484 GtkWidget *button = NULL;
486 button = gtk_button_new_with_mnemonic (mnemonic_label);
487 gtk_widget_set_can_default (button, TRUE);
488 gtk_button_set_image (GTK_BUTTON (button),
489 gtk_image_new_from_stock (stock_id,
490 GTK_ICON_SIZE_BUTTON));
491 gtk_widget_show (button);
493 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
496 /* This function handles error messages before printing.
499 error_dialogs (GtkPrintUnixDialog *print_dialog,
500 gint print_dialog_response_id,
503 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
504 GtkPrinterOption *option = NULL;
505 GtkPrinter *printer = NULL;
506 GtkWindow *toplevel = NULL;
507 GtkWidget *dialog = NULL;
509 gchar *basename = NULL;
510 gchar *dirname = NULL;
513 if (print_dialog != NULL && print_dialog_response_id == GTK_RESPONSE_OK)
515 printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
519 if (priv->request_details_tag || !gtk_printer_is_accepting_jobs (printer))
521 g_signal_stop_emission_by_name (print_dialog, "response");
525 /* Shows overwrite confirmation dialog in the case of printing to file which
527 if (gtk_printer_is_virtual (printer))
529 option = gtk_printer_option_set_lookup (priv->options,
530 "gtk-main-page-custom-input");
532 if (option != NULL &&
533 option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE)
535 file = g_file_new_for_uri (option->value);
538 g_file_query_exists (file, NULL))
540 toplevel = get_toplevel (GTK_WIDGET (print_dialog));
542 basename = g_file_get_basename (file);
543 dirname = g_file_get_parse_name (g_file_get_parent (file));
545 dialog = gtk_message_dialog_new (toplevel,
547 GTK_DIALOG_DESTROY_WITH_PARENT,
548 GTK_MESSAGE_QUESTION,
550 _("A file named \"%s\" already exists. Do you want to replace it?"),
553 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
554 _("The file already exists in \"%s\". Replacing it will "
555 "overwrite its contents."),
558 gtk_dialog_add_button (GTK_DIALOG (dialog),
559 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
560 add_custom_button_to_dialog (GTK_DIALOG (dialog),
563 GTK_RESPONSE_ACCEPT);
564 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
568 gtk_dialog_set_default_response (GTK_DIALOG (dialog),
569 GTK_RESPONSE_ACCEPT);
571 if (gtk_window_has_group (toplevel))
572 gtk_window_group_add_window (gtk_window_get_group (toplevel),
573 GTK_WINDOW (dialog));
575 response = gtk_dialog_run (GTK_DIALOG (dialog));
577 gtk_widget_destroy (dialog);
582 if (response != GTK_RESPONSE_ACCEPT)
584 g_signal_stop_emission_by_name (print_dialog, "response");
585 g_object_unref (file);
590 g_object_unref (file);
599 gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
601 GtkPrintUnixDialogPrivate *priv;
603 dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
604 GTK_TYPE_PRINT_UNIX_DIALOG,
605 GtkPrintUnixDialogPrivate);
608 priv->print_backends = NULL;
609 priv->current_page = -1;
610 priv->number_up_layout_n_option = NULL;
611 priv->number_up_layout_2_option = NULL;
613 priv->page_setup = gtk_page_setup_new ();
614 priv->page_setup_set = FALSE;
615 priv->embed_page_setup = FALSE;
616 priv->internal_page_setup_change = FALSE;
618 priv->support_selection = FALSE;
619 priv->has_selection = FALSE;
621 g_signal_connect (dialog,
623 (GCallback) gtk_print_unix_dialog_destroy,
626 g_signal_connect (dialog,
628 (GCallback) error_dialogs,
631 g_signal_connect (dialog,
632 "notify::page-setup",
633 (GCallback) redraw_page_layout_preview,
636 priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
637 gtk_widget_show (priv->preview_button);
639 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
640 priv->preview_button,
642 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
643 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
644 GTK_STOCK_PRINT, GTK_RESPONSE_OK,
646 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
652 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
653 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
655 priv->page_setup_list = gtk_list_store_new (PAGE_SETUP_LIST_N_COLS,
659 priv->custom_paper_list = gtk_list_store_new (1, G_TYPE_OBJECT);
660 _gtk_print_load_custom_papers (priv->custom_paper_list);
662 populate_dialog (dialog);
666 gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
668 /* Make sure we don't destroy custom widgets owned by the backends */
669 clear_per_printer_ui (dialog);
673 disconnect_printer_details_request (GtkPrintUnixDialog *dialog, gboolean details_failed)
675 GtkPrintUnixDialogPrivate *priv = dialog->priv;
677 if (priv->request_details_tag)
679 g_signal_handler_disconnect (priv->request_details_printer,
680 priv->request_details_tag);
681 priv->request_details_tag = 0;
682 set_busy_cursor (dialog, FALSE);
684 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
685 g_object_get_data (G_OBJECT (priv->request_details_printer),
686 "gtk-print-tree-iter"),
687 PRINTER_LIST_COL_STATE,
688 _("Getting printer information failed"),
691 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
692 g_object_get_data (G_OBJECT (priv->request_details_printer),
693 "gtk-print-tree-iter"),
694 PRINTER_LIST_COL_STATE,
695 gtk_printer_get_state_message (priv->request_details_printer),
697 g_object_unref (priv->request_details_printer);
698 priv->request_details_printer = NULL;
703 gtk_print_unix_dialog_finalize (GObject *object)
705 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
706 GtkPrintUnixDialogPrivate *priv = dialog->priv;
707 GtkPrintBackend *backend;
710 unschedule_idle_mark_conflicts (dialog);
711 disconnect_printer_details_request (dialog, FALSE);
713 if (priv->current_printer)
715 g_object_unref (priv->current_printer);
716 priv->current_printer = NULL;
719 if (priv->printer_list)
721 g_object_unref (priv->printer_list);
722 priv->printer_list = NULL;
725 if (priv->custom_paper_list)
727 g_object_unref (priv->custom_paper_list);
728 priv->custom_paper_list = NULL;
731 if (priv->printer_list_filter)
733 g_object_unref (priv->printer_list_filter);
734 priv->printer_list_filter = NULL;
739 g_object_unref (priv->options);
740 priv->options = NULL;
743 if (priv->number_up_layout_2_option)
745 priv->number_up_layout_2_option->choices[0] = NULL;
746 priv->number_up_layout_2_option->choices[1] = NULL;
747 g_free (priv->number_up_layout_2_option->choices_display[0]);
748 g_free (priv->number_up_layout_2_option->choices_display[1]);
749 priv->number_up_layout_2_option->choices_display[0] = NULL;
750 priv->number_up_layout_2_option->choices_display[1] = NULL;
751 g_object_unref (priv->number_up_layout_2_option);
752 priv->number_up_layout_2_option = NULL;
755 if (priv->number_up_layout_n_option)
757 g_object_unref (priv->number_up_layout_n_option);
758 priv->number_up_layout_n_option = NULL;
761 if (priv->page_setup)
763 g_object_unref (priv->page_setup);
764 priv->page_setup = NULL;
767 if (priv->initial_settings)
769 g_object_unref (priv->initial_settings);
770 priv->initial_settings = NULL;
773 g_free (priv->waiting_for_printer);
774 priv->waiting_for_printer = NULL;
776 g_free (priv->format_for_printer);
777 priv->format_for_printer = NULL;
779 for (node = priv->print_backends; node != NULL; node = node->next)
781 backend = GTK_PRINT_BACKEND (node->data);
783 g_signal_handlers_disconnect_by_func (backend, printer_added_cb, dialog);
784 g_signal_handlers_disconnect_by_func (backend, printer_removed_cb, dialog);
785 g_signal_handlers_disconnect_by_func (backend, printer_status_cb, dialog);
787 gtk_print_backend_destroy (backend);
788 g_object_unref (backend);
791 g_list_free (priv->print_backends);
792 priv->print_backends = NULL;
794 if (priv->page_setup_list)
796 g_object_unref (priv->page_setup_list);
797 priv->page_setup_list = NULL;
800 G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->finalize (object);
804 printer_removed_cb (GtkPrintBackend *backend,
806 GtkPrintUnixDialog *dialog)
808 GtkPrintUnixDialogPrivate *priv = dialog->priv;
811 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
812 gtk_list_store_remove (GTK_LIST_STORE (priv->printer_list), iter);
816 gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface)
818 parent_buildable_iface = g_type_interface_peek_parent (iface);
820 iface->get_internal_child = gtk_print_unix_dialog_buildable_get_internal_child;
824 gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
826 const gchar *childname)
828 if (strcmp (childname, "notebook") == 0)
829 return G_OBJECT (GTK_PRINT_UNIX_DIALOG (buildable)->priv->notebook);
831 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
834 /* This function controls "sensitive" property of GtkCellRenderer based on pause
835 * state of printers. */
836 void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
837 GtkCellRenderer *cell,
838 GtkTreeModel *tree_model,
844 gtk_tree_model_get (tree_model, iter, PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
846 if (printer != NULL && !gtk_printer_is_accepting_jobs (printer))
847 g_object_set (cell, "sensitive", FALSE, NULL);
849 g_object_set (cell, "sensitive", TRUE, NULL);
851 g_object_unref (printer);
855 printer_status_cb (GtkPrintBackend *backend,
857 GtkPrintUnixDialog *dialog)
859 GtkPrintUnixDialogPrivate *priv = dialog->priv;
861 GtkTreeSelection *selection;
863 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
865 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), iter,
866 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
867 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
868 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
869 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
872 /* When the pause state change then we need to update sensitive property
873 * of GTK_RESPONSE_OK button inside of selected_printer_changed function. */
874 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
875 selected_printer_changed (selection, dialog);
877 if (gtk_print_backend_printer_list_is_done (backend) &&
878 gtk_printer_is_default (printer) &&
879 (gtk_tree_selection_count_selected_rows (selection) == 0))
880 set_active_printer (dialog, gtk_printer_get_name (printer));
884 printer_added_cb (GtkPrintBackend *backend,
886 GtkPrintUnixDialog *dialog)
888 GtkPrintUnixDialogPrivate *priv = dialog->priv;
889 GtkTreeIter iter, filter_iter;
890 GtkTreeSelection *selection;
893 gtk_list_store_append (GTK_LIST_STORE (priv->printer_list), &iter);
895 g_object_set_data_full (G_OBJECT (printer),
896 "gtk-print-tree-iter",
897 gtk_tree_iter_copy (&iter),
898 (GDestroyNotify) gtk_tree_iter_free);
900 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list), &iter,
901 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
902 PRINTER_LIST_COL_NAME, gtk_printer_get_name (printer),
903 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
904 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
905 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
906 PRINTER_LIST_COL_PRINTER_OBJ, printer,
909 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
910 &filter_iter, &iter);
911 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->printer_list_filter), &filter_iter);
913 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
915 if (priv->waiting_for_printer != NULL &&
916 strcmp (gtk_printer_get_name (printer),
917 priv->waiting_for_printer) == 0)
919 priv->internal_printer_change = TRUE;
920 gtk_tree_selection_select_iter (selection, &filter_iter);
921 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
922 path, NULL, TRUE, 0.5, 0.0);
923 priv->internal_printer_change = FALSE;
924 g_free (priv->waiting_for_printer);
925 priv->waiting_for_printer = NULL;
927 else if (is_default_printer (dialog, printer) &&
928 gtk_tree_selection_count_selected_rows (selection) == 0)
930 priv->internal_printer_change = TRUE;
931 gtk_tree_selection_select_iter (selection, &filter_iter);
932 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
933 path, NULL, TRUE, 0.5, 0.0);
934 priv->internal_printer_change = FALSE;
937 gtk_tree_path_free (path);
941 printer_list_initialize (GtkPrintUnixDialog *dialog,
942 GtkPrintBackend *print_backend)
947 g_return_if_fail (print_backend != NULL);
949 g_signal_connect_object (print_backend,
951 (GCallback) printer_added_cb,
952 G_OBJECT (dialog), 0);
954 g_signal_connect_object (print_backend,
956 (GCallback) printer_removed_cb,
957 G_OBJECT (dialog), 0);
959 g_signal_connect_object (print_backend,
960 "printer-status-changed",
961 (GCallback) printer_status_cb,
962 G_OBJECT (dialog), 0);
964 list = gtk_print_backend_get_printer_list (print_backend);
969 printer_added_cb (print_backend, node->data, dialog);
977 load_print_backends (GtkPrintUnixDialog *dialog)
979 GtkPrintUnixDialogPrivate *priv = dialog->priv;
982 if (g_module_supported ())
983 priv->print_backends = gtk_print_backend_load_modules ();
985 for (node = priv->print_backends; node != NULL; node = node->next)
987 GtkPrintBackend *backend = node->data;
988 printer_list_initialize (dialog, backend);
993 gtk_print_unix_dialog_set_property (GObject *object,
999 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
1003 case PROP_PAGE_SETUP:
1004 gtk_print_unix_dialog_set_page_setup (dialog, g_value_get_object (value));
1006 case PROP_CURRENT_PAGE:
1007 gtk_print_unix_dialog_set_current_page (dialog, g_value_get_int (value));
1009 case PROP_PRINT_SETTINGS:
1010 gtk_print_unix_dialog_set_settings (dialog, g_value_get_object (value));
1012 case PROP_MANUAL_CAPABILITIES:
1013 gtk_print_unix_dialog_set_manual_capabilities (dialog, g_value_get_flags (value));
1015 case PROP_SUPPORT_SELECTION:
1016 gtk_print_unix_dialog_set_support_selection (dialog, g_value_get_boolean (value));
1018 case PROP_HAS_SELECTION:
1019 gtk_print_unix_dialog_set_has_selection (dialog, g_value_get_boolean (value));
1021 case PROP_EMBED_PAGE_SETUP:
1022 gtk_print_unix_dialog_set_embed_page_setup (dialog, g_value_get_boolean (value));
1025 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1031 gtk_print_unix_dialog_get_property (GObject *object,
1036 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
1037 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1041 case PROP_PAGE_SETUP:
1042 g_value_set_object (value, priv->page_setup);
1044 case PROP_CURRENT_PAGE:
1045 g_value_set_int (value, priv->current_page);
1047 case PROP_PRINT_SETTINGS:
1048 g_value_take_object (value, gtk_print_unix_dialog_get_settings (dialog));
1050 case PROP_SELECTED_PRINTER:
1051 g_value_set_object (value, priv->current_printer);
1053 case PROP_MANUAL_CAPABILITIES:
1054 g_value_set_flags (value, priv->manual_capabilities);
1056 case PROP_SUPPORT_SELECTION:
1057 g_value_set_boolean (value, priv->support_selection);
1059 case PROP_HAS_SELECTION:
1060 g_value_set_boolean (value, priv->has_selection);
1062 case PROP_EMBED_PAGE_SETUP:
1063 g_value_set_boolean (value, priv->embed_page_setup);
1066 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1072 is_printer_active (GtkTreeModel *model,
1074 GtkPrintUnixDialog *dialog)
1077 GtkPrinter *printer;
1078 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1080 gtk_tree_model_get (model, iter,
1081 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1084 if (printer == NULL)
1087 result = gtk_printer_is_active (printer);
1090 priv->manual_capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF |
1091 GTK_PRINT_CAPABILITY_GENERATE_PS))
1093 /* Check that the printer can handle at least one of the data
1094 * formats that the application supports.
1096 result = ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF) &&
1097 gtk_printer_accepts_pdf (printer)) ||
1098 ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS) &&
1099 gtk_printer_accepts_ps (printer));
1102 g_object_unref (printer);
1108 default_printer_list_sort_func (GtkTreeModel *model,
1115 GtkPrinter *a_printer;
1116 GtkPrinter *b_printer;
1119 gtk_tree_model_get (model, a,
1120 PRINTER_LIST_COL_NAME, &a_name,
1121 PRINTER_LIST_COL_PRINTER_OBJ, &a_printer,
1123 gtk_tree_model_get (model, b,
1124 PRINTER_LIST_COL_NAME, &b_name,
1125 PRINTER_LIST_COL_PRINTER_OBJ, &b_printer,
1128 if (a_printer == NULL && b_printer == NULL)
1130 else if (a_printer == NULL)
1132 else if (b_printer == NULL)
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 (!gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
1140 else if (a_name == NULL && b_name == NULL)
1142 else if (a_name == NULL && b_name != NULL)
1144 else if (a_name != NULL && b_name == NULL)
1147 result = g_ascii_strcasecmp (a_name, b_name);
1152 g_object_unref (a_printer);
1154 g_object_unref (b_printer);
1160 create_printer_list_model (GtkPrintUnixDialog *dialog)
1162 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1163 GtkListStore *model;
1164 GtkTreeSortable *sort;
1166 model = gtk_list_store_new (PRINTER_LIST_N_COLS,
1174 priv->printer_list = (GtkTreeModel *)model;
1175 priv->printer_list_filter = (GtkTreeModelFilter *) gtk_tree_model_filter_new ((GtkTreeModel *)model,
1178 gtk_tree_model_filter_set_visible_func (priv->printer_list_filter,
1179 (GtkTreeModelFilterVisibleFunc) is_printer_active,
1183 sort = GTK_TREE_SORTABLE (model);
1184 gtk_tree_sortable_set_default_sort_func (sort,
1185 default_printer_list_sort_func,
1189 gtk_tree_sortable_set_sort_column_id (sort,
1190 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
1191 GTK_SORT_ASCENDING);
1197 wrap_in_frame (const gchar *label,
1200 GtkWidget *frame, *label_widget;
1203 label_widget = gtk_label_new (NULL);
1204 gtk_widget_set_halign (label_widget, GTK_ALIGN_START);
1205 gtk_widget_set_valign (label_widget, GTK_ALIGN_CENTER);
1206 gtk_widget_show (label_widget);
1208 bold_text = g_markup_printf_escaped ("<b>%s</b>", label);
1209 gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
1212 frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
1213 gtk_box_pack_start (GTK_BOX (frame), label_widget, FALSE, FALSE, 0);
1215 gtk_widget_set_margin_left (child, 12);
1216 gtk_widget_set_halign (child, GTK_ALIGN_FILL);
1217 gtk_widget_set_valign (child, GTK_ALIGN_FILL);
1219 gtk_box_pack_start (GTK_BOX (frame), child, FALSE, FALSE, 0);
1221 gtk_widget_show (frame);
1227 setup_option (GtkPrintUnixDialog *dialog,
1228 const gchar *option_name,
1229 GtkPrinterOptionWidget *widget)
1231 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1232 GtkPrinterOption *option;
1234 option = gtk_printer_option_set_lookup (priv->options, option_name);
1235 gtk_printer_option_widget_set_source (widget, option);
1237 return option != NULL;
1241 add_option_to_extension_point (GtkPrinterOption *option,
1244 GtkWidget *extension_point = data;
1247 widget = gtk_printer_option_widget_new (option);
1248 gtk_widget_show (widget);
1250 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1252 GtkWidget *label, *hbox;
1254 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1255 gtk_widget_show (label);
1256 gtk_widget_set_halign (label, GTK_ALIGN_START);
1257 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1258 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1260 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
1261 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1262 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1263 gtk_widget_show (hbox);
1265 gtk_box_pack_start (GTK_BOX (extension_point), hbox, FALSE, FALSE, 0);
1268 gtk_box_pack_start (GTK_BOX (extension_point), widget, FALSE, FALSE, 0);
1272 grid_rows (GtkGrid *table)
1275 GList *children, *c;
1277 children = gtk_container_get_children (GTK_CONTAINER (table));
1279 for (c = children; c; c = c->next)
1281 gtk_container_child_get (GTK_CONTAINER (table), c->data,
1298 g_list_free (children);
1304 add_option_to_table (GtkPrinterOption *option,
1308 GtkWidget *label, *widget;
1311 table = GTK_GRID (user_data);
1313 if (g_str_has_prefix (option->name, "gtk-"))
1316 row = grid_rows (table);
1318 widget = gtk_printer_option_widget_new (option);
1319 gtk_widget_show (widget);
1321 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
1323 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
1324 gtk_widget_show (label);
1326 gtk_widget_set_halign (label, GTK_ALIGN_START);
1327 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1328 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1330 gtk_grid_attach (table, label, 0, row - 1, 1, 1);
1331 gtk_grid_attach (table, widget, 1, row - 1, 1, 1);
1334 gtk_grid_attach (table, widget, 0, row - 1, 2, 1);
1338 setup_page_table (GtkPrinterOptionSet *options,
1345 gtk_printer_option_set_foreach_in_group (options, group,
1346 add_option_to_table,
1349 nrows = grid_rows (GTK_GRID (table));
1351 gtk_widget_hide (page);
1353 gtk_widget_show (page);
1357 update_print_at_option (GtkPrintUnixDialog *dialog)
1359 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1360 GtkPrinterOption *option;
1362 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1367 if (priv->updating_print_at)
1370 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_at_radio)))
1371 gtk_printer_option_set (option, "at");
1372 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio)))
1373 gtk_printer_option_set (option, "on-hold");
1375 gtk_printer_option_set (option, "now");
1377 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1380 const char *text = gtk_entry_get_text (GTK_ENTRY (priv->print_at_entry));
1381 gtk_printer_option_set (option, text);
1387 setup_print_at (GtkPrintUnixDialog *dialog)
1389 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1390 GtkPrinterOption *option;
1392 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time");
1396 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1398 gtk_widget_set_sensitive (priv->print_at_radio, FALSE);
1399 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1400 gtk_widget_set_sensitive (priv->print_hold_radio, FALSE);
1401 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), "");
1405 priv->updating_print_at = TRUE;
1407 gtk_widget_set_sensitive (priv->print_at_entry, FALSE);
1408 gtk_widget_set_sensitive (priv->print_at_radio,
1409 gtk_printer_option_has_choice (option, "at"));
1411 gtk_widget_set_sensitive (priv->print_hold_radio,
1412 gtk_printer_option_has_choice (option, "on-hold"));
1414 update_print_at_option (dialog);
1416 if (strcmp (option->value, "at") == 0)
1417 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_at_radio),
1419 else if (strcmp (option->value, "on-hold") == 0)
1420 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_hold_radio),
1423 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->print_now_radio),
1426 option = gtk_printer_option_set_lookup (priv->options, "gtk-print-time-text");
1428 gtk_entry_set_text (GTK_ENTRY (priv->print_at_entry), option->value);
1430 priv->updating_print_at = FALSE;
1436 update_dialog_from_settings (GtkPrintUnixDialog *dialog)
1438 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1441 GtkWidget *table, *frame;
1442 gboolean has_advanced, has_job;
1445 if (priv->current_printer == NULL)
1447 clear_per_printer_ui (dialog);
1448 gtk_widget_hide (priv->job_page);
1449 gtk_widget_hide (priv->advanced_page);
1450 gtk_widget_hide (priv->image_quality_page);
1451 gtk_widget_hide (priv->finishing_page);
1452 gtk_widget_hide (priv->color_page);
1453 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1458 setup_option (dialog, "gtk-n-up", priv->pages_per_sheet);
1459 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
1460 setup_option (dialog, "gtk-duplex", priv->duplex);
1461 setup_option (dialog, "gtk-paper-type", priv->paper_type);
1462 setup_option (dialog, "gtk-paper-source", priv->paper_source);
1463 setup_option (dialog, "gtk-output-tray", priv->output_tray);
1466 has_job |= setup_option (dialog, "gtk-job-prio", priv->job_prio);
1467 has_job |= setup_option (dialog, "gtk-billing-info", priv->billing_info);
1468 has_job |= setup_option (dialog, "gtk-cover-before", priv->cover_before);
1469 has_job |= setup_option (dialog, "gtk-cover-after", priv->cover_after);
1470 has_job |= setup_print_at (dialog);
1473 gtk_widget_show (priv->job_page);
1475 gtk_widget_hide (priv->job_page);
1477 setup_page_table (priv->options,
1479 priv->image_quality_table,
1480 priv->image_quality_page);
1482 setup_page_table (priv->options,
1484 priv->finishing_table,
1485 priv->finishing_page);
1487 setup_page_table (priv->options,
1492 gtk_printer_option_set_foreach_in_group (priv->options,
1493 "GtkPrintDialogExtension",
1494 add_option_to_extension_point,
1495 priv->extension_point);
1497 /* Put the rest of the groups in the advanced page */
1498 groups = gtk_printer_option_set_get_groups (priv->options);
1500 has_advanced = FALSE;
1501 for (l = groups; l != NULL; l = l->next)
1508 if (strcmp (group, "ImageQualityPage") == 0 ||
1509 strcmp (group, "ColorPage") == 0 ||
1510 strcmp (group, "FinishingPage") == 0 ||
1511 strcmp (group, "GtkPrintDialogExtension") == 0)
1514 table = gtk_grid_new ();
1515 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
1516 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
1518 gtk_printer_option_set_foreach_in_group (priv->options,
1520 add_option_to_table,
1523 nrows = grid_rows (GTK_GRID (table));
1525 gtk_widget_destroy (table);
1528 has_advanced = TRUE;
1529 frame = wrap_in_frame (group, table);
1530 gtk_widget_show (table);
1531 gtk_widget_show (frame);
1533 gtk_box_pack_start (GTK_BOX (priv->advanced_vbox),
1534 frame, FALSE, FALSE, 0);
1539 gtk_widget_show (priv->advanced_page);
1541 gtk_widget_hide (priv->advanced_page);
1543 g_list_free_full (groups, g_free);
1547 update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
1549 GtkPrintCapabilities caps;
1550 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1551 gboolean can_collate;
1552 const gchar *copies;
1554 copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin));
1555 can_collate = (*copies != '\0' && atoi (copies) > 1);
1557 caps = priv->manual_capabilities | priv->printer_capabilities;
1559 gtk_widget_set_sensitive (priv->page_set_combo,
1560 caps & GTK_PRINT_CAPABILITY_PAGE_SET);
1561 gtk_widget_set_sensitive (priv->copies_spin,
1562 caps & GTK_PRINT_CAPABILITY_COPIES);
1563 gtk_widget_set_sensitive (priv->collate_check,
1565 (caps & GTK_PRINT_CAPABILITY_COLLATE));
1566 gtk_widget_set_sensitive (priv->reverse_check,
1567 caps & GTK_PRINT_CAPABILITY_REVERSE);
1568 gtk_widget_set_sensitive (priv->scale_spin,
1569 caps & GTK_PRINT_CAPABILITY_SCALE);
1570 gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet),
1571 caps & GTK_PRINT_CAPABILITY_NUMBER_UP);
1573 if (caps & GTK_PRINT_CAPABILITY_PREVIEW)
1574 gtk_widget_show (priv->preview_button);
1576 gtk_widget_hide (priv->preview_button);
1578 update_collate_icon (NULL, dialog);
1580 gtk_tree_model_filter_refilter (priv->printer_list_filter);
1584 page_setup_is_equal (GtkPageSetup *a,
1588 gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
1589 gtk_page_setup_get_paper_size (b)) &&
1590 gtk_page_setup_get_top_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_top_margin (b, GTK_UNIT_MM) &&
1591 gtk_page_setup_get_bottom_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_bottom_margin (b, GTK_UNIT_MM) &&
1592 gtk_page_setup_get_left_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_left_margin (b, GTK_UNIT_MM) &&
1593 gtk_page_setup_get_right_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_right_margin (b, GTK_UNIT_MM);
1597 page_setup_is_same_size (GtkPageSetup *a,
1600 return gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
1601 gtk_page_setup_get_paper_size (b));
1605 set_paper_size (GtkPrintUnixDialog *dialog,
1606 GtkPageSetup *page_setup,
1610 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1611 GtkTreeModel *model;
1613 GtkPageSetup *list_page_setup;
1615 if (!priv->internal_page_setup_change)
1618 if (page_setup == NULL)
1621 model = GTK_TREE_MODEL (priv->page_setup_list);
1623 if (gtk_tree_model_get_iter_first (model, &iter))
1627 gtk_tree_model_get (GTK_TREE_MODEL (priv->page_setup_list), &iter,
1628 PAGE_SETUP_LIST_COL_PAGE_SETUP, &list_page_setup, -1);
1629 if (list_page_setup == NULL)
1632 if ((size_only && page_setup_is_same_size (page_setup, list_page_setup)) ||
1633 (!size_only && page_setup_is_equal (page_setup, list_page_setup)))
1635 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->paper_size_combo),
1637 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->orientation_combo),
1638 gtk_page_setup_get_orientation (page_setup));
1639 g_object_unref (list_page_setup);
1643 g_object_unref (list_page_setup);
1645 } while (gtk_tree_model_iter_next (model, &iter));
1650 gtk_list_store_append (priv->page_setup_list, &iter);
1651 gtk_list_store_set (priv->page_setup_list, &iter,
1652 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1654 gtk_list_store_append (priv->page_setup_list, &iter);
1655 gtk_list_store_set (priv->page_setup_list, &iter,
1656 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1658 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->paper_size_combo),
1660 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->orientation_combo),
1661 gtk_page_setup_get_orientation (page_setup));
1669 fill_custom_paper_sizes (GtkPrintUnixDialog *dialog)
1671 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1672 GtkTreeIter iter, paper_iter;
1673 GtkTreeModel *model;
1675 model = GTK_TREE_MODEL (priv->custom_paper_list);
1676 if (gtk_tree_model_get_iter_first (model, &iter))
1678 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1679 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1680 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1684 GtkPageSetup *page_setup;
1685 gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
1687 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1688 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1689 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1692 g_object_unref (page_setup);
1693 } while (gtk_tree_model_iter_next (model, &iter));
1696 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1697 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1698 PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
1700 gtk_list_store_append (priv->page_setup_list, &paper_iter);
1701 gtk_list_store_set (priv->page_setup_list, &paper_iter,
1702 PAGE_SETUP_LIST_COL_PAGE_SETUP, NULL,
1707 fill_paper_sizes (GtkPrintUnixDialog *dialog,
1708 GtkPrinter *printer)
1710 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1712 GtkPageSetup *page_setup;
1713 GtkPaperSize *paper_size;
1717 gtk_list_store_clear (priv->page_setup_list);
1719 if (printer == NULL || (list = gtk_printer_list_papers (printer)) == NULL)
1721 for (i = 0; i < G_N_ELEMENTS (common_paper_sizes); i++)
1723 page_setup = gtk_page_setup_new ();
1724 paper_size = gtk_paper_size_new (common_paper_sizes[i]);
1725 gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size);
1726 gtk_paper_size_free (paper_size);
1728 gtk_list_store_append (priv->page_setup_list, &iter);
1729 gtk_list_store_set (priv->page_setup_list, &iter,
1730 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1732 g_object_unref (page_setup);
1737 for (l = list; l != NULL; l = l->next)
1739 page_setup = l->data;
1740 gtk_list_store_append (priv->page_setup_list, &iter);
1741 gtk_list_store_set (priv->page_setup_list, &iter,
1742 PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
1744 g_object_unref (page_setup);
1749 fill_custom_paper_sizes (dialog);
1753 update_paper_sizes (GtkPrintUnixDialog *dialog)
1755 GtkPageSetup *current_page_setup = NULL;
1756 GtkPrinter *printer;
1758 printer = gtk_print_unix_dialog_get_selected_printer (dialog);
1760 fill_paper_sizes (dialog, printer);
1762 current_page_setup = gtk_page_setup_copy (gtk_print_unix_dialog_get_page_setup (dialog));
1764 if (current_page_setup)
1766 if (!set_paper_size (dialog, current_page_setup, FALSE, FALSE))
1767 set_paper_size (dialog, current_page_setup, TRUE, TRUE);
1769 g_object_unref (current_page_setup);
1774 mark_conflicts (GtkPrintUnixDialog *dialog)
1776 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1777 GtkPrinter *printer;
1778 gboolean have_conflict;
1780 have_conflict = FALSE;
1782 printer = priv->current_printer;
1787 g_signal_handler_block (priv->options,
1788 priv->options_changed_handler);
1790 gtk_printer_option_set_clear_conflicts (priv->options);
1792 have_conflict = _gtk_printer_mark_conflicts (printer,
1795 g_signal_handler_unblock (priv->options,
1796 priv->options_changed_handler);
1800 gtk_widget_show (priv->conflicts_widget);
1802 gtk_widget_hide (priv->conflicts_widget);
1806 mark_conflicts_callback (gpointer data)
1808 GtkPrintUnixDialog *dialog = data;
1809 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1811 priv->mark_conflicts_id = 0;
1813 mark_conflicts (dialog);
1819 unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1821 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1823 if (priv->mark_conflicts_id != 0)
1825 g_source_remove (priv->mark_conflicts_id);
1826 priv->mark_conflicts_id = 0;
1831 schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1833 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1835 if (priv->mark_conflicts_id != 0)
1838 priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
1843 options_changed_cb (GtkPrintUnixDialog *dialog)
1845 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1847 schedule_idle_mark_conflicts (dialog);
1849 g_free (priv->waiting_for_printer);
1850 priv->waiting_for_printer = NULL;
1854 remove_custom_widget (GtkWidget *widget,
1855 GtkContainer *container)
1857 gtk_container_remove (container, widget);
1861 extension_point_clear_children (GtkContainer *container)
1863 gtk_container_foreach (container,
1864 (GtkCallback)remove_custom_widget,
1869 clear_per_printer_ui (GtkPrintUnixDialog *dialog)
1871 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1873 gtk_container_foreach (GTK_CONTAINER (priv->finishing_table),
1874 (GtkCallback)gtk_widget_destroy, NULL);
1875 gtk_container_foreach (GTK_CONTAINER (priv->image_quality_table),
1876 (GtkCallback)gtk_widget_destroy, NULL);
1877 gtk_container_foreach (GTK_CONTAINER (priv->color_table),
1878 (GtkCallback)gtk_widget_destroy, NULL);
1879 gtk_container_foreach (GTK_CONTAINER (priv->advanced_vbox),
1880 (GtkCallback)gtk_widget_destroy, NULL);
1881 extension_point_clear_children (GTK_CONTAINER (priv->extension_point));
1885 printer_details_acquired (GtkPrinter *printer,
1887 GtkPrintUnixDialog *dialog)
1889 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1891 disconnect_printer_details_request (dialog, !success);
1895 GtkTreeSelection *selection;
1896 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
1898 selected_printer_changed (selection, dialog);
1903 selected_printer_changed (GtkTreeSelection *selection,
1904 GtkPrintUnixDialog *dialog)
1906 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1907 GtkPrinter *printer;
1908 GtkTreeIter iter, filter_iter;
1910 /* Whenever the user selects a printer we stop looking for
1911 the printer specified in the initial settings */
1912 if (priv->waiting_for_printer &&
1913 !priv->internal_printer_change)
1915 g_free (priv->waiting_for_printer);
1916 priv->waiting_for_printer = NULL;
1919 disconnect_printer_details_request (dialog, FALSE);
1922 if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
1924 gtk_tree_model_filter_convert_iter_to_child_iter (priv->printer_list_filter,
1928 gtk_tree_model_get (priv->printer_list, &iter,
1929 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1933 /* sets GTK_RESPONSE_OK button sensitivity depending on whether the printer
1934 * accepts/rejects jobs
1936 if (printer != NULL)
1938 if (!gtk_printer_is_accepting_jobs (printer))
1940 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1944 if (priv->current_printer == printer && gtk_printer_has_details (printer))
1945 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1949 if (printer != NULL && !gtk_printer_has_details (printer))
1951 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1952 priv->request_details_tag =
1953 g_signal_connect (printer, "details-acquired",
1954 G_CALLBACK (printer_details_acquired), dialog);
1955 /* take the reference */
1956 priv->request_details_printer = printer;
1957 gtk_printer_request_details (printer);
1958 set_busy_cursor (dialog, TRUE);
1959 gtk_list_store_set (GTK_LIST_STORE (priv->printer_list),
1960 g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter"),
1961 PRINTER_LIST_COL_STATE, _("Getting printer information..."),
1966 if (printer == priv->current_printer)
1969 g_object_unref (printer);
1975 g_object_unref (priv->options);
1976 priv->options = NULL;
1978 clear_per_printer_ui (dialog);
1981 if (priv->current_printer)
1983 g_object_unref (priv->current_printer);
1986 priv->printer_capabilities = 0;
1988 if (printer != NULL && gtk_printer_is_accepting_jobs (printer))
1989 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1990 priv->current_printer = printer;
1992 if (printer != NULL)
1994 if (!priv->page_setup_set)
1996 /* if no explicit page setup has been set, use the printer default */
1997 GtkPageSetup *page_setup;
1999 page_setup = gtk_printer_get_default_page_size (printer);
2002 page_setup = gtk_page_setup_new ();
2004 if (page_setup && priv->page_setup)
2005 gtk_page_setup_set_orientation (page_setup, gtk_page_setup_get_orientation (priv->page_setup));
2007 g_object_unref (priv->page_setup);
2008 priv->page_setup = page_setup;
2011 priv->printer_capabilities = gtk_printer_get_capabilities (printer);
2012 priv->options = _gtk_printer_get_options (printer,
2013 priv->initial_settings,
2015 priv->manual_capabilities);
2017 priv->options_changed_handler =
2018 g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
2019 schedule_idle_mark_conflicts (dialog);
2022 update_dialog_from_settings (dialog);
2023 update_dialog_from_capabilities (dialog);
2025 priv->internal_page_setup_change = TRUE;
2026 update_paper_sizes (dialog);
2027 priv->internal_page_setup_change = FALSE;
2029 g_object_notify ( G_OBJECT(dialog), "selected-printer");
2033 update_collate_icon (GtkToggleButton *toggle_button,
2034 GtkPrintUnixDialog *dialog)
2036 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2038 gtk_widget_queue_draw (priv->collate_image);
2042 paint_page (GtkWidget *widget,
2050 GtkStyleContext *context;
2051 gint x, y, width, height;
2052 gint text_y, linewidth;
2055 x = x_offset * scale;
2056 y = y_offset * scale;
2058 height = 26 * scale;
2063 context = gtk_widget_get_style_context (widget);
2065 gtk_style_context_save (context);
2066 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
2068 gtk_style_context_get_background_color (context, 0, &color);
2069 gdk_cairo_set_source_rgba (cr, &color);
2070 cairo_rectangle (cr, x, y, width, height);
2073 gtk_style_context_get_color (context, 0, &color);
2074 gdk_cairo_set_source_rgba (cr, &color);
2075 cairo_set_line_width (cr, linewidth);
2076 cairo_rectangle (cr, x + linewidth/2.0, y + linewidth/2.0, width - linewidth, height - linewidth);
2079 cairo_select_font_face (cr, "Sans",
2080 CAIRO_FONT_SLANT_NORMAL,
2081 CAIRO_FONT_WEIGHT_NORMAL);
2082 cairo_set_font_size (cr, (gint)(9 * scale));
2083 cairo_move_to (cr, x + (gint)(text_x * scale), y + (gint)(text_y * scale));
2084 cairo_show_text (cr, text);
2086 gtk_style_context_restore (context);
2090 draw_collate_cb (GtkWidget *widget,
2092 GtkPrintUnixDialog *dialog)
2094 GtkSettings *settings;
2097 gboolean collate, reverse, rtl;
2101 collate = dialog_get_collate (dialog);
2102 reverse = dialog_get_reverse (dialog);
2103 copies = dialog_get_n_copies (dialog);
2105 rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL);
2107 settings = gtk_widget_get_settings (widget);
2108 gtk_icon_size_lookup_for_settings (settings,
2109 GTK_ICON_SIZE_DIALOG,
2112 scale = size / 48.0;
2113 text_x = rtl ? 4 : 11;
2117 paint_page (widget, cr, scale, rtl ? 40: 15, 5, reverse ? "1" : "2", text_x);
2118 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
2122 paint_page (widget, cr, scale, rtl ? 40: 15, 5, collate == reverse ? "1" : "2", text_x);
2123 paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
2125 paint_page (widget, cr, scale, rtl ? 5 : 50, 5, reverse ? "1" : "2", text_x);
2126 paint_page (widget, cr, scale, rtl ? 15 : 40, 15, collate == reverse ? "2" : "1", text_x);
2133 gtk_print_unix_dialog_style_updated (GtkWidget *widget)
2135 GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_updated (widget);
2137 if (gtk_widget_has_screen (widget))
2139 GtkPrintUnixDialog *dialog = (GtkPrintUnixDialog *)widget;
2140 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2141 GtkSettings *settings;
2145 settings = gtk_widget_get_settings (widget);
2146 gtk_icon_size_lookup_for_settings (settings,
2147 GTK_ICON_SIZE_DIALOG,
2150 scale = size / 48.0;
2152 gtk_widget_set_size_request (priv->collate_image,
2159 update_entry_sensitivity (GtkWidget *button,
2164 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
2166 gtk_widget_set_sensitive (range, active);
2169 gtk_widget_grab_focus (range);
2173 emit_ok_response (GtkTreeView *tree_view,
2175 GtkTreeViewColumn *column,
2176 gpointer *user_data)
2178 GtkPrintUnixDialog *print_dialog;
2180 print_dialog = (GtkPrintUnixDialog *) user_data;
2182 gtk_dialog_response (GTK_DIALOG (print_dialog), GTK_RESPONSE_OK);
2186 create_main_page (GtkPrintUnixDialog *dialog)
2188 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2189 GtkWidget *main_vbox, *label, *vbox, *hbox;
2190 GtkWidget *scrolled, *treeview, *frame, *table;
2191 GtkWidget *entry, *spinbutton;
2192 GtkWidget *radio, *check, *image;
2193 GtkCellRenderer *renderer;
2194 GtkTreeViewColumn *column;
2195 GtkTreeSelection *selection;
2196 GtkWidget *custom_input;
2197 const gchar *range_tooltip;
2199 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
2200 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2201 gtk_widget_show (main_vbox);
2203 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
2204 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
2205 gtk_widget_show (vbox);
2207 scrolled = gtk_scrolled_window_new (NULL, NULL);
2208 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2209 GTK_POLICY_AUTOMATIC,
2210 GTK_POLICY_AUTOMATIC);
2211 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
2213 gtk_widget_show (scrolled);
2214 gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
2216 treeview = gtk_tree_view_new_with_model ((GtkTreeModel *) priv->printer_list_filter);
2217 priv->printer_treeview = treeview;
2218 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
2219 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), PRINTER_LIST_COL_NAME);
2220 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), TRUE);
2221 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
2222 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
2223 g_signal_connect (selection, "changed", G_CALLBACK (selected_printer_changed), dialog);
2225 renderer = gtk_cell_renderer_pixbuf_new ();
2226 column = gtk_tree_view_column_new_with_attributes ("",
2229 PRINTER_LIST_COL_ICON,
2231 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2232 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2234 renderer = gtk_cell_renderer_text_new ();
2235 column = gtk_tree_view_column_new_with_attributes (_("Printer"),
2238 PRINTER_LIST_COL_NAME,
2240 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2241 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2243 renderer = gtk_cell_renderer_text_new ();
2244 /* Translators: this is the header for the location column in the print dialog */
2245 column = gtk_tree_view_column_new_with_attributes (_("Location"),
2248 PRINTER_LIST_COL_LOCATION,
2250 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2251 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2253 renderer = gtk_cell_renderer_text_new ();
2254 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
2255 /* Translators: this is the header for the printer status column in the print dialog */
2256 column = gtk_tree_view_column_new_with_attributes (_("Status"),
2259 PRINTER_LIST_COL_STATE,
2261 gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
2262 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
2264 g_signal_connect (GTK_TREE_VIEW (treeview), "row-activated", G_CALLBACK (emit_ok_response), dialog);
2266 gtk_widget_show (treeview);
2267 gtk_container_add (GTK_CONTAINER (scrolled), treeview);
2269 custom_input = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
2270 gtk_widget_show (custom_input);
2271 gtk_box_pack_start (GTK_BOX (vbox), custom_input, FALSE, FALSE, 0);
2272 priv->extension_point = custom_input;
2274 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
2275 gtk_widget_show (hbox);
2276 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
2278 table = gtk_grid_new ();
2279 priv->range_table = table;
2280 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
2281 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
2282 frame = wrap_in_frame (_("Range"), table);
2283 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2284 gtk_widget_show (table);
2286 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_All Pages"));
2287 priv->all_pages_radio = radio;
2288 gtk_widget_show (radio);
2289 gtk_grid_attach (GTK_GRID (table), radio, 0, 0, 2, 1);
2290 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2291 _("C_urrent Page"));
2292 if (priv->current_page == -1)
2293 gtk_widget_set_sensitive (radio, FALSE);
2294 priv->current_page_radio = radio;
2295 gtk_widget_show (radio);
2296 gtk_grid_attach (GTK_GRID (table), radio, 0, 1, 2, 1);
2298 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2301 gtk_widget_set_sensitive (radio, priv->has_selection);
2302 priv->selection_radio = radio;
2303 gtk_grid_attach (GTK_GRID (table), radio, 0, 2, 2, 1);
2305 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)), _("Pag_es:"));
2306 range_tooltip = _("Specify one or more page ranges,\n e.g. 1-3,7,11");
2307 gtk_widget_set_tooltip_text (radio, range_tooltip);
2309 priv->page_range_radio = radio;
2310 gtk_widget_show (radio);
2311 gtk_grid_attach (GTK_GRID (table), radio, 0, 3, 1, 1);
2312 entry = gtk_entry_new ();
2313 gtk_widget_set_tooltip_text (entry, range_tooltip);
2314 gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
2315 atk_object_set_name (gtk_widget_get_accessible (entry), _("Pages"));
2316 atk_object_set_description (gtk_widget_get_accessible (entry), range_tooltip);
2317 priv->page_range_entry = entry;
2318 gtk_widget_show (entry);
2319 gtk_grid_attach (GTK_GRID (table), entry, 1, 3, 1, 1);
2320 g_signal_connect (radio, "toggled", G_CALLBACK (update_entry_sensitivity), entry);
2321 update_entry_sensitivity (radio, entry);
2323 table = gtk_grid_new ();
2324 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
2325 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
2326 frame = wrap_in_frame (_("Copies"), table);
2327 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
2328 gtk_widget_show (table);
2330 /* FIXME chpe: too much space between Copies and spinbutton, put those 2 in a hbox and make it span 2 columns */
2331 label = gtk_label_new_with_mnemonic (_("Copie_s:"));
2332 gtk_widget_set_halign (label, GTK_ALIGN_START);
2333 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
2334 gtk_widget_show (label);
2335 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
2336 spinbutton = gtk_spin_button_new_with_range (1.0, 100.0, 1.0);
2337 gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
2338 priv->copies_spin = spinbutton;
2339 gtk_widget_show (spinbutton);
2340 gtk_grid_attach (GTK_GRID (table), spinbutton, 1, 0, 1, 1);
2341 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
2342 g_signal_connect_swapped (spinbutton, "value-changed",
2343 G_CALLBACK (update_dialog_from_capabilities), dialog);
2344 g_signal_connect_swapped (spinbutton, "changed",
2345 G_CALLBACK (update_dialog_from_capabilities), dialog);
2347 check = gtk_check_button_new_with_mnemonic (_("C_ollate"));
2348 priv->collate_check = check;
2349 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
2350 gtk_widget_show (check);
2351 gtk_grid_attach (GTK_GRID (table), check, 0, 1, 1, 1);
2353 check = gtk_check_button_new_with_mnemonic (_("_Reverse"));
2354 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
2355 priv->reverse_check = check;
2356 gtk_widget_show (check);
2357 gtk_grid_attach (GTK_GRID (table), check, 0, 2, 1, 1);
2359 image = gtk_drawing_area_new ();
2360 gtk_widget_set_has_window (image, FALSE);
2362 priv->collate_image = image;
2363 gtk_widget_show (image);
2364 gtk_widget_set_size_request (image, 70, 90);
2365 gtk_grid_attach (GTK_GRID (table), image, 1, 1, 1, 2);
2366 g_signal_connect (image, "draw",
2367 G_CALLBACK (draw_collate_cb), dialog);
2369 label = gtk_label_new (_("General"));
2370 gtk_widget_show (label);
2372 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), main_vbox, label);
2376 is_range_separator (gchar c)
2378 return (c == ',' || c == ';' || c == ':');
2381 static GtkPageRange *
2382 dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
2385 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2387 const gchar *text, *p;
2389 GtkPageRange *ranges;
2392 text = gtk_entry_get_text (GTK_ENTRY (priv->page_range_entry));
2404 if (is_range_separator (*p))
2409 ranges = g_new0 (GtkPageRange, n_ranges);
2415 while (isspace (*p)) p++;
2419 /* a half-open range like -2 */
2424 start = (int)strtol (p, &next, 10);
2432 while (isspace (*p)) p++;
2437 end = (int)strtol (p, &next, 10);
2438 if (next == p) /* a half-open range like 2- */
2440 else if (end < start)
2444 ranges[i].start = start - 1;
2445 ranges[i].end = end - 1;
2448 /* Skip until end or separator */
2449 while (*p && !is_range_separator (*p))
2452 /* if not at end, skip separator */
2463 dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
2464 GtkPageRange *ranges,
2467 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2469 GString *s = g_string_new (NULL);
2471 for (i = 0; i < n_ranges; i++)
2473 g_string_append_printf (s, "%d", ranges[i].start + 1);
2474 if (ranges[i].end > ranges[i].start)
2475 g_string_append_printf (s, "-%d", ranges[i].end + 1);
2476 else if (ranges[i].end == -1)
2477 g_string_append (s, "-");
2479 if (i != n_ranges - 1)
2480 g_string_append (s, ",");
2483 gtk_entry_set_text (GTK_ENTRY (priv->page_range_entry), s->str);
2485 g_string_free (s, TRUE);
2488 static GtkPrintPages
2489 dialog_get_print_pages (GtkPrintUnixDialog *dialog)
2491 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2493 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio)))
2494 return GTK_PRINT_PAGES_ALL;
2495 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->current_page_radio)))
2496 return GTK_PRINT_PAGES_CURRENT;
2497 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->selection_radio)))
2498 return GTK_PRINT_PAGES_SELECTION;
2500 return GTK_PRINT_PAGES_RANGES;
2504 dialog_set_print_pages (GtkPrintUnixDialog *dialog,
2505 GtkPrintPages pages)
2507 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2509 if (pages == GTK_PRINT_PAGES_RANGES)
2510 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
2511 else if (pages == GTK_PRINT_PAGES_CURRENT)
2512 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->current_page_radio), TRUE);
2513 else if (pages == GTK_PRINT_PAGES_SELECTION)
2514 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->selection_radio), TRUE);
2516 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio), TRUE);
2520 dialog_get_scale (GtkPrintUnixDialog *dialog)
2522 if (gtk_widget_is_sensitive (dialog->priv->scale_spin))
2523 return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
2529 dialog_set_scale (GtkPrintUnixDialog *dialog,
2532 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin), val);
2536 dialog_get_page_set (GtkPrintUnixDialog *dialog)
2538 if (gtk_widget_is_sensitive (dialog->priv->page_set_combo))
2539 return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
2541 return GTK_PAGE_SET_ALL;
2545 dialog_set_page_set (GtkPrintUnixDialog *dialog,
2548 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->page_set_combo),
2553 dialog_get_n_copies (GtkPrintUnixDialog *dialog)
2555 if (gtk_widget_is_sensitive (dialog->priv->copies_spin))
2556 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
2561 dialog_set_n_copies (GtkPrintUnixDialog *dialog,
2564 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->copies_spin),
2569 dialog_get_collate (GtkPrintUnixDialog *dialog)
2571 if (gtk_widget_is_sensitive (dialog->priv->collate_check))
2572 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
2577 dialog_set_collate (GtkPrintUnixDialog *dialog,
2580 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check),
2585 dialog_get_reverse (GtkPrintUnixDialog *dialog)
2587 if (gtk_widget_is_sensitive (dialog->priv->reverse_check))
2588 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
2593 dialog_set_reverse (GtkPrintUnixDialog *dialog,
2596 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check),
2601 dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
2603 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2607 val = gtk_printer_option_widget_get_value (priv->pages_per_sheet);
2621 static GtkNumberUpLayout
2622 dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
2624 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2625 GtkPrintCapabilities caps;
2626 GtkNumberUpLayout layout;
2628 GEnumClass *enum_class;
2629 GEnumValue *enum_value;
2631 val = gtk_printer_option_widget_get_value (priv->number_up_layout);
2633 caps = priv->manual_capabilities | priv->printer_capabilities;
2635 if ((caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) == 0)
2636 return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2638 if (gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR)
2639 layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
2641 layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
2646 if (val[0] == '\0' && priv->options)
2648 GtkPrinterOption *option = gtk_printer_option_set_lookup (priv->options, "gtk-n-up-layout");
2650 val = option->value;
2653 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
2654 enum_value = g_enum_get_value_by_nick (enum_class, val);
2656 layout = enum_value->value;
2657 g_type_class_unref (enum_class);
2663 draw_page_cb (GtkWidget *widget,
2665 GtkPrintUnixDialog *dialog)
2667 GtkPrintUnixDialogPrivate *priv = dialog->priv;
2668 GtkStyleContext *context;
2670 gint w, h, tmp, shadow_offset;
2671 gint pages_x, pages_y, i, x, y, layout_w, layout_h;
2672 gdouble page_width, page_height;
2673 GtkPageOrientation orientation;
2675 PangoLayout *layout;
2676 PangoFontDescription *font;
2679 GtkNumberUpLayout number_up_layout;
2680 gint start_x, end_x, start_y, end_y;
2683 gboolean horizontal;
2684 GtkPageSetup *page_setup;
2685 gdouble paper_width, paper_height;
2686 gdouble pos_x, pos_y;
2687 gint pages_per_sheet;
2688 gboolean ltr = TRUE;
2690 orientation = gtk_page_setup_get_orientation (priv->page_setup);
2692 (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
2693 (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
2695 number_up_layout = dialog_get_number_up_layout (dialog);
2696 width = gtk_widget_get_allocated_width (widget);
2697 height = gtk_widget_get_allocated_height (widget);
2701 page_setup = gtk_print_unix_dialog_get_page_setup (dialog);
2703 if (page_setup != NULL)
2707 paper_width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
2708 paper_height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
2712 paper_width = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
2713 paper_height = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
2716 if (paper_width < paper_height)
2718 h = EXAMPLE_PAGE_AREA_SIZE - 3;
2719 w = (paper_height != 0) ? h * paper_width / paper_height : 0;
2723 w = EXAMPLE_PAGE_AREA_SIZE - 3;
2724 h = (paper_width != 0) ? w * paper_height / paper_width : 0;
2727 if (paper_width == 0)
2730 if (paper_height == 0)
2736 w = (EXAMPLE_PAGE_AREA_SIZE - 3) / ratio;
2737 h = EXAMPLE_PAGE_AREA_SIZE - 3;
2740 pages_per_sheet = dialog_get_pages_per_sheet (dialog);
2741 switch (pages_per_sheet)
2745 pages_x = 1; pages_y = 1;
2748 landscape = !landscape;
2749 pages_x = 1; pages_y = 2;
2752 pages_x = 2; pages_y = 2;
2755 landscape = !landscape;
2756 pages_x = 2; pages_y = 3;
2759 pages_x = 3; pages_y = 3;
2762 pages_x = 4; pages_y = 4;
2777 context = gtk_widget_get_style_context (widget);
2779 gtk_style_context_save (context);
2780 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
2782 pos_x = (width - w) / 2;
2783 pos_y = (height - h) / 2 - 10;
2784 cairo_translate (cr, pos_x, pos_y);
2788 gtk_style_context_get_color (context, 0, &color);
2789 cairo_set_source_rgba (cr, color.red, color.green, color.blue, 0.5);
2790 cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
2793 gtk_style_context_get_background_color (context, 0, &color);
2794 gdk_cairo_set_source_rgba (cr, &color);
2795 cairo_rectangle (cr, 1, 1, w, h);
2797 cairo_set_line_width (cr, 1.0);
2798 cairo_rectangle (cr, 0.5, 0.5, w + 1, h + 1);
2800 gtk_style_context_get_color (context, 0, &color);
2801 gdk_cairo_set_source_rgba (cr, &color);
2806 page_width = (double)w / pages_x;
2807 page_height = (double)h / pages_y;
2809 layout = pango_cairo_create_layout (cr);
2811 font = pango_font_description_new ();
2812 pango_font_description_set_family (font, "sans");
2814 if (page_height > 0)
2815 pango_font_description_set_absolute_size (font, page_height * 0.4 * PANGO_SCALE);
2817 pango_font_description_set_absolute_size (font, 1);
2819 pango_layout_set_font_description (layout, font);
2820 pango_font_description_free (font);
2822 pango_layout_set_width (layout, page_width * PANGO_SCALE);
2823 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2825 switch (number_up_layout)
2828 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
2830 end_x = pages_x - 1;
2832 end_y = pages_y - 1;
2837 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
2839 end_x = pages_x - 1;
2840 start_y = pages_y - 1;
2846 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
2847 start_x = pages_x - 1;
2850 end_y = pages_y - 1;
2855 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
2856 start_x = pages_x - 1;
2858 start_y = pages_y - 1;
2864 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
2866 end_x = pages_x - 1;
2868 end_y = pages_y - 1;
2873 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
2874 start_x = pages_x - 1;
2877 end_y = pages_y - 1;
2882 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
2884 end_x = pages_x - 1;
2885 start_y = pages_y - 1;
2891 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
2892 start_x = pages_x - 1;
2894 start_y = pages_y - 1;
2903 for (y = start_y; y != end_y + dy; y += dy)
2905 for (x = start_x; x != end_x + dx; x += dx)
2907 text = g_strdup_printf ("%d", i++);
2908 pango_layout_set_text (layout, text, -1);
2910 pango_layout_get_size (layout, &layout_w, &layout_h);
2912 cairo_translate (cr,
2914 y * page_height + (page_height - layout_h / 1024.0) / 2);
2916 pango_cairo_show_layout (cr, layout);
2921 for (x = start_x; x != end_x + dx; x += dx)
2923 for (y = start_y; y != end_y + dy; y += dy)
2925 text = g_strdup_printf ("%d", i++);
2926 pango_layout_set_text (layout, text, -1);
2928 pango_layout_get_size (layout, &layout_w, &layout_h);
2930 cairo_translate (cr,
2932 y * page_height + (page_height - layout_h / 1024.0) / 2);
2934 pango_cairo_show_layout (cr, layout);
2939 g_object_unref (layout);
2941 if (page_setup != NULL)
2946 if (pages_per_sheet == 2 || pages_per_sheet == 6)
2948 paper_width = gtk_page_setup_get_paper_height (page_setup, _gtk_print_get_default_user_units ());
2949 paper_height = gtk_page_setup_get_paper_width (page_setup, _gtk_print_get_default_user_units ());
2953 paper_width = gtk_page_setup_get_paper_width (page_setup, _gtk_print_get_default_user_units ());
2954 paper_height = gtk_page_setup_get_paper_height (page_setup, _gtk_print_get_default_user_units ());
2960 layout = pango_cairo_create_layout (cr);
2962 font = pango_font_description_new ();
2963 pango_font_description_set_family (font, "sans");
2965 PangoContext *pango_c = NULL;
2966 PangoFontDescription *pango_f = NULL;
2967 gint font_size = 12 * PANGO_SCALE;
2969 pango_c = gtk_widget_get_pango_context (widget);
2970 if (pango_c != NULL)
2972 pango_f = pango_context_get_font_description (pango_c);
2973 if (pango_f != NULL)
2974 font_size = pango_font_description_get_size (pango_f);
2977 pango_font_description_set_size (font, font_size);
2978 pango_layout_set_font_description (layout, font);
2979 pango_font_description_free (font);
2981 pango_layout_set_width (layout, -1);
2982 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
2984 if (_gtk_print_get_default_user_units () == GTK_UNIT_MM)
2985 text = g_strdup_printf ("%.1f mm", paper_height);
2987 text = g_strdup_printf ("%.2f inch", paper_height);
2989 pango_layout_set_text (layout, text, -1);
2991 pango_layout_get_size (layout, &layout_w, &layout_h);
2993 ltr = gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR;
2996 cairo_translate (cr, pos_x - layout_w / PANGO_SCALE - 2 * RULER_DISTANCE,
2997 (height - layout_h / PANGO_SCALE) / 2);
2999 cairo_translate (cr, pos_x + w + shadow_offset + 2 * RULER_DISTANCE,
3000 (height - layout_h / PANGO_SCALE) / 2);
3002 pango_cairo_show_layout (cr, layout);
3007 if (_gtk_print_get_default_user_units () == GTK_UNIT_MM)
3008 text = g_strdup_printf ("%.1f mm", paper_width);
3010 text = g_strdup_printf ("%.2f inch", paper_width);
3012 pango_layout_set_text (layout, text, -1);
3014 pango_layout_get_size (layout, &layout_w, &layout_h);
3016 cairo_translate (cr, (width - layout_w / PANGO_SCALE) / 2,
3017 pos_y + h + shadow_offset + 2 * RULER_DISTANCE);
3019 pango_cairo_show_layout (cr, layout);
3021 g_object_unref (layout);
3025 cairo_set_line_width (cr, 1);
3029 cairo_move_to (cr, pos_x - RULER_DISTANCE, pos_y);
3030 cairo_line_to (cr, pos_x - RULER_DISTANCE, pos_y + h);
3033 cairo_move_to (cr, pos_x - RULER_DISTANCE - RULER_RADIUS, pos_y - 0.5);
3034 cairo_line_to (cr, pos_x - RULER_DISTANCE + RULER_RADIUS, pos_y - 0.5);
3037 cairo_move_to (cr, pos_x - RULER_DISTANCE - RULER_RADIUS, pos_y + h + 0.5);
3038 cairo_line_to (cr, pos_x - RULER_DISTANCE + RULER_RADIUS, pos_y + h + 0.5);
3043 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE, pos_y);
3044 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE, pos_y + h);
3047 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE - RULER_RADIUS, pos_y - 0.5);
3048 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE + RULER_RADIUS, pos_y - 0.5);
3051 cairo_move_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE - RULER_RADIUS, pos_y + h + 0.5);
3052 cairo_line_to (cr, pos_x + w + shadow_offset + RULER_DISTANCE + RULER_RADIUS, pos_y + h + 0.5);
3056 cairo_move_to (cr, pos_x, pos_y + h + shadow_offset + RULER_DISTANCE);
3057 cairo_line_to (cr, pos_x + w, pos_y + h + shadow_offset + RULER_DISTANCE);
3060 cairo_move_to (cr, pos_x - 0.5, pos_y + h + shadow_offset + RULER_DISTANCE - RULER_RADIUS);
3061 cairo_line_to (cr, pos_x - 0.5, pos_y + h + shadow_offset + RULER_DISTANCE + RULER_RADIUS);
3064 cairo_move_to (cr, pos_x + w + 0.5, pos_y + h + shadow_offset + RULER_DISTANCE - RULER_RADIUS);
3065 cairo_line_to (cr, pos_x + w + 0.5, pos_y + h + shadow_offset + RULER_DISTANCE + RULER_RADIUS);
3069 gtk_style_context_restore (context);
3075 redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
3077 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3079 if (priv->page_layout_preview)
3080 gtk_widget_queue_draw (priv->page_layout_preview);
3084 update_number_up_layout (GtkPrintUnixDialog *dialog)
3086 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3087 GtkPrintCapabilities caps;
3088 GtkPrinterOptionSet *set;
3089 GtkNumberUpLayout layout;
3090 GtkPrinterOption *option;
3091 GtkPrinterOption *old_option;
3092 GtkPageOrientation page_orientation;
3094 set = priv->options;
3096 caps = priv->manual_capabilities | priv->printer_capabilities;
3098 if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
3100 if (priv->number_up_layout_n_option == NULL)
3102 priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
3103 if (priv->number_up_layout_n_option == NULL)
3105 char *n_up_layout[] = { "lrtb", "lrbt", "rltb", "rlbt", "tblr", "tbrl", "btlr", "btrl" };
3106 /* Translators: These strings name the possible arrangements of
3107 * multiple pages on a sheet when printing (same as in gtkprintbackendcups.c)
3109 char *n_up_layout_display[] = { N_("Left to right, top to bottom"), N_("Left to right, bottom to top"),
3110 N_("Right to left, top to bottom"), N_("Right to left, bottom to top"),
3111 N_("Top to bottom, left to right"), N_("Top to bottom, right to left"),
3112 N_("Bottom to top, left to right"), N_("Bottom to top, right to left") };
3115 priv->number_up_layout_n_option = gtk_printer_option_new ("gtk-n-up-layout",
3117 GTK_PRINTER_OPTION_TYPE_PICKONE);
3118 gtk_printer_option_allocate_choices (priv->number_up_layout_n_option, 8);
3120 for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
3122 priv->number_up_layout_n_option->choices[i] = g_strdup (n_up_layout[i]);
3123 priv->number_up_layout_n_option->choices_display[i] = g_strdup (_(n_up_layout_display[i]));
3126 g_object_ref (priv->number_up_layout_n_option);
3128 priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
3130 GTK_PRINTER_OPTION_TYPE_PICKONE);
3131 gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
3134 page_orientation = gtk_page_setup_get_orientation (priv->page_setup);
3135 if (page_orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
3136 page_orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
3138 if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
3139 priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[2]))
3141 g_free (priv->number_up_layout_2_option->choices_display[0]);
3142 g_free (priv->number_up_layout_2_option->choices_display[1]);
3143 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
3144 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
3145 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
3146 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
3151 if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
3152 priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[1]))
3154 g_free (priv->number_up_layout_2_option->choices_display[0]);
3155 g_free (priv->number_up_layout_2_option->choices_display[1]);
3156 priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
3157 priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[1];
3158 priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Top to bottom"));
3159 priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Bottom to top"));
3163 layout = dialog_get_number_up_layout (dialog);
3165 old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
3166 if (old_option != NULL)
3167 gtk_printer_option_set_remove (set, old_option);
3169 if (dialog_get_pages_per_sheet (dialog) != 1)
3171 GEnumClass *enum_class;
3172 GEnumValue *enum_value;
3173 enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
3175 if (dialog_get_pages_per_sheet (dialog) == 2)
3177 option = priv->number_up_layout_2_option;
3181 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
3182 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
3183 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
3186 case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
3187 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
3188 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP);
3191 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
3192 case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
3193 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM);
3196 case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
3197 case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
3198 enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP);
3202 g_assert_not_reached();
3208 option = priv->number_up_layout_n_option;
3210 enum_value = g_enum_get_value (enum_class, layout);
3213 g_assert (enum_value != NULL);
3214 gtk_printer_option_set (option, enum_value->value_nick);
3215 g_type_class_unref (enum_class);
3217 gtk_printer_option_set_add (set, option);
3221 setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
3223 if (priv->number_up_layout != NULL)
3224 gtk_widget_set_sensitive (GTK_WIDGET (priv->number_up_layout),
3225 (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) &&
3226 (dialog_get_pages_per_sheet (dialog) > 1));
3230 custom_paper_dialog_response_cb (GtkDialog *custom_paper_dialog,
3234 GtkPrintUnixDialog *print_dialog = GTK_PRINT_UNIX_DIALOG (user_data);
3235 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
3236 GtkTreeModel *model;
3239 _gtk_print_load_custom_papers (priv->custom_paper_list);
3241 priv->internal_page_setup_change = TRUE;
3242 update_paper_sizes (print_dialog);
3243 priv->internal_page_setup_change = FALSE;
3245 if (priv->page_setup_set)
3247 model = GTK_TREE_MODEL (priv->custom_paper_list);
3248 if (gtk_tree_model_get_iter_first (model, &iter))
3252 GtkPageSetup *page_setup;
3253 gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
3256 g_strcmp0 (gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size (page_setup)),
3257 gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size (priv->page_setup))) == 0)
3258 gtk_print_unix_dialog_set_page_setup (print_dialog, page_setup);
3260 g_object_unref (page_setup);
3261 } while (gtk_tree_model_iter_next (model, &iter));
3265 gtk_widget_destroy (GTK_WIDGET (custom_paper_dialog));
3269 orientation_changed (GtkComboBox *combo_box,
3270 GtkPrintUnixDialog *dialog)
3272 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3273 GtkPageOrientation orientation;
3274 GtkPageSetup *page_setup;
3276 if (priv->internal_page_setup_change)
3279 orientation = (GtkPageOrientation) gtk_combo_box_get_active (GTK_COMBO_BOX (priv->orientation_combo));
3281 if (priv->page_setup)
3283 page_setup = gtk_page_setup_copy (priv->page_setup);
3285 gtk_page_setup_set_orientation (page_setup, orientation);
3287 gtk_print_unix_dialog_set_page_setup (dialog, page_setup);
3290 redraw_page_layout_preview (dialog);
3294 paper_size_changed (GtkComboBox *combo_box,
3295 GtkPrintUnixDialog *dialog)
3297 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3299 GtkPageSetup *page_setup, *last_page_setup;
3300 GtkPageOrientation orientation;
3302 if (priv->internal_page_setup_change)
3305 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3307 gtk_tree_model_get (gtk_combo_box_get_model (combo_box),
3308 &iter, PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup, -1);
3310 if (page_setup == NULL)
3312 GtkWidget *custom_paper_dialog;
3314 /* Change from "manage" menu item to last value */
3315 if (priv->page_setup)
3316 last_page_setup = g_object_ref (priv->page_setup);
3318 last_page_setup = gtk_page_setup_new (); /* "good" default */
3320 if (!set_paper_size (dialog, last_page_setup, FALSE, FALSE))
3321 set_paper_size (dialog, last_page_setup, TRUE, TRUE);
3322 g_object_unref (last_page_setup);
3324 /* And show the custom paper dialog */
3325 custom_paper_dialog = _gtk_custom_paper_unix_dialog_new (GTK_WINDOW (dialog), _("Manage Custom Sizes"));
3326 g_signal_connect (custom_paper_dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), dialog);
3327 gtk_window_present (GTK_WINDOW (custom_paper_dialog));
3332 if (priv->page_setup)
3333 orientation = gtk_page_setup_get_orientation (priv->page_setup);
3335 orientation = GTK_PAGE_ORIENTATION_PORTRAIT;
3337 gtk_page_setup_set_orientation (page_setup, orientation);
3338 gtk_print_unix_dialog_set_page_setup (dialog, page_setup);
3340 g_object_unref (page_setup);
3343 redraw_page_layout_preview (dialog);
3347 paper_size_row_is_separator (GtkTreeModel *model,
3353 gtk_tree_model_get (model, iter, PAGE_SETUP_LIST_COL_IS_SEPARATOR, &separator, -1);
3358 page_name_func (GtkCellLayout *cell_layout,
3359 GtkCellRenderer *cell,
3360 GtkTreeModel *tree_model,
3364 GtkPageSetup *page_setup;
3365 GtkPaperSize *paper_size;
3367 gtk_tree_model_get (tree_model, iter,
3368 PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup, -1);
3371 paper_size = gtk_page_setup_get_paper_size (page_setup);
3372 g_object_set (cell, "text", gtk_paper_size_get_display_name (paper_size), NULL);
3373 g_object_unref (page_setup);
3376 g_object_set (cell, "text", _("Manage Custom Sizes..."), NULL);
3380 create_page_setup_page (GtkPrintUnixDialog *dialog)
3382 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3383 GtkWidget *main_vbox, *label, *hbox, *hbox2;
3384 GtkWidget *frame, *table, *widget;
3385 GtkWidget *combo, *spinbutton, *draw;
3386 GtkCellRenderer *cell;
3388 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
3389 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
3390 gtk_widget_show (main_vbox);
3392 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
3393 gtk_widget_show (hbox);
3394 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
3396 table = gtk_grid_new ();
3397 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3398 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3399 frame = wrap_in_frame (_("Layout"), table);
3400 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
3401 gtk_widget_show (table);
3403 label = gtk_label_new_with_mnemonic (_("T_wo-sided:"));
3404 gtk_widget_set_halign (label, GTK_ALIGN_START);
3405 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3406 gtk_widget_show (label);
3407 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3409 widget = gtk_printer_option_widget_new (NULL);
3410 priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
3411 gtk_widget_show (widget);
3412 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3413 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3415 label = gtk_label_new_with_mnemonic (_("Pages per _side:"));
3416 gtk_widget_set_halign (label, GTK_ALIGN_START);
3417 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3418 gtk_widget_show (label);
3419 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3421 widget = gtk_printer_option_widget_new (NULL);
3422 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
3423 g_signal_connect_swapped (widget, "changed", G_CALLBACK (update_number_up_layout), dialog);
3424 priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
3425 gtk_widget_show (widget);
3426 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3427 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3429 label = gtk_label_new_with_mnemonic (_("Page or_dering:"));
3430 gtk_widget_set_halign (label, GTK_ALIGN_START);
3431 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3432 gtk_widget_show (label);
3433 gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
3435 widget = gtk_printer_option_widget_new (NULL);
3436 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
3437 priv->number_up_layout = GTK_PRINTER_OPTION_WIDGET (widget);
3438 gtk_widget_show (widget);
3439 gtk_grid_attach (GTK_GRID (table), widget, 1, 2, 1, 1);
3440 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3442 label = gtk_label_new_with_mnemonic (_("_Only print:"));
3443 gtk_widget_set_halign (label, GTK_ALIGN_START);
3444 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3445 gtk_widget_show (label);
3446 gtk_grid_attach (GTK_GRID (table), label, 0, 3, 1, 1);
3448 combo = gtk_combo_box_text_new ();
3449 priv->page_set_combo = combo;
3450 gtk_widget_show (combo);
3451 gtk_grid_attach (GTK_GRID (table), combo, 1, 3, 1, 1);
3452 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3454 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("All sheets"));
3455 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Even sheets"));
3456 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Odd sheets"));
3457 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
3459 label = gtk_label_new_with_mnemonic (_("Sc_ale:"));
3460 gtk_widget_set_halign (label, GTK_ALIGN_START);
3461 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3462 gtk_widget_show (label);
3463 gtk_grid_attach (GTK_GRID (table), label, 0, 4, 1, 1);
3465 hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
3466 gtk_widget_show (hbox2);
3467 gtk_grid_attach (GTK_GRID (table), hbox2, 1, 4, 1, 1);
3469 spinbutton = gtk_spin_button_new_with_range (1.0, 1000.0, 1.0);
3470 priv->scale_spin = spinbutton;
3471 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), 1);
3472 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton), 100.0);
3473 gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
3474 gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
3475 gtk_widget_show (spinbutton);
3476 label = gtk_label_new ("%"); /* FIXMEchpe does there exist any language where % needs to be translated? */
3477 gtk_widget_show (label);
3478 gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
3480 table = gtk_grid_new ();
3481 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3482 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3483 frame = wrap_in_frame (_("Paper"), table);
3484 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
3485 gtk_widget_show (table);
3487 label = gtk_label_new_with_mnemonic (_("Paper _type:"));
3488 gtk_widget_set_halign (label, GTK_ALIGN_START);
3489 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3490 gtk_widget_show (label);
3491 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3493 widget = gtk_printer_option_widget_new (NULL);
3494 priv->paper_type = GTK_PRINTER_OPTION_WIDGET (widget);
3495 gtk_widget_show (widget);
3496 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3497 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3499 label = gtk_label_new_with_mnemonic (_("Paper _source:"));
3500 gtk_widget_set_halign (label, GTK_ALIGN_START);
3501 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3502 gtk_widget_show (label);
3503 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3505 widget = gtk_printer_option_widget_new (NULL);
3506 priv->paper_source = GTK_PRINTER_OPTION_WIDGET (widget);
3507 gtk_widget_show (widget);
3508 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3509 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3511 label = gtk_label_new_with_mnemonic (_("Output t_ray:"));
3512 gtk_widget_set_halign (label, GTK_ALIGN_START);
3513 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3514 gtk_widget_show (label);
3515 gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
3517 widget = gtk_printer_option_widget_new (NULL);
3518 priv->output_tray = GTK_PRINTER_OPTION_WIDGET (widget);
3519 gtk_widget_show (widget);
3520 gtk_grid_attach (GTK_GRID (table), widget, 1, 2, 1, 1);
3521 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3524 label = gtk_label_new_with_mnemonic (_("_Paper size:"));
3525 priv->paper_size_combo_label = GTK_WIDGET (label);
3526 gtk_widget_set_halign (label, GTK_ALIGN_START);
3527 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3528 gtk_widget_show (label);
3529 gtk_grid_attach (GTK_GRID (table), label, 0, 3, 1, 1);
3531 combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->page_setup_list));
3532 priv->paper_size_combo = GTK_WIDGET (combo);
3533 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
3534 paper_size_row_is_separator, NULL, NULL);
3535 cell = gtk_cell_renderer_text_new ();
3536 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
3537 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), cell,
3538 page_name_func, NULL, NULL);
3539 gtk_grid_attach (GTK_GRID (table), combo, 1, 3, 1, 1);
3540 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3541 gtk_widget_set_sensitive (combo, FALSE);
3542 gtk_widget_show (combo);
3544 label = gtk_label_new_with_mnemonic (_("Or_ientation:"));
3545 priv->orientation_combo_label = GTK_WIDGET (label);
3546 gtk_widget_set_halign (label, GTK_ALIGN_START);
3547 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3548 gtk_widget_show (label);
3549 gtk_grid_attach (GTK_GRID (table), label, 0, 4, 1, 1);
3551 combo = gtk_combo_box_text_new ();
3552 priv->orientation_combo = GTK_WIDGET (combo);
3553 gtk_grid_attach (GTK_GRID (table), combo, 1, 4, 1, 1);
3554 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
3556 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Portrait"));
3557 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Landscape"));
3558 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Reverse portrait"));
3559 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Reverse landscape"));
3560 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
3561 gtk_widget_set_sensitive (combo, FALSE);
3562 gtk_widget_show (combo);
3565 /* Add the page layout preview */
3566 hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
3567 gtk_widget_show (hbox2);
3568 gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 0);
3570 draw = gtk_drawing_area_new ();
3571 gtk_widget_set_has_window (draw, FALSE);
3572 priv->page_layout_preview = draw;
3573 gtk_widget_set_size_request (draw, 280, 160);
3574 g_signal_connect (draw, "draw", G_CALLBACK (draw_page_cb), dialog);
3575 gtk_widget_show (draw);
3577 gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 0);
3579 label = gtk_label_new (_("Page Setup"));
3580 gtk_widget_show (label);
3582 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3587 create_job_page (GtkPrintUnixDialog *dialog)
3589 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3590 GtkWidget *main_table, *label;
3591 GtkWidget *frame, *table, *radio;
3592 GtkWidget *entry, *widget;
3593 const gchar *at_tooltip;
3594 const gchar *on_hold_tooltip;
3596 main_table = gtk_grid_new ();
3597 gtk_container_set_border_width (GTK_CONTAINER (main_table), 12);
3598 gtk_grid_set_row_spacing (GTK_GRID (main_table), 18);
3599 gtk_grid_set_column_spacing (GTK_GRID (main_table), 18);
3601 table = gtk_grid_new ();
3602 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3603 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3604 frame = wrap_in_frame (_("Job Details"), table);
3605 gtk_grid_attach (GTK_GRID (main_table), frame, 0, 0, 1, 1);
3606 gtk_widget_show (table);
3608 label = gtk_label_new_with_mnemonic (_("Pri_ority:"));
3609 gtk_widget_set_halign (label, GTK_ALIGN_START);
3610 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3611 gtk_widget_show (label);
3612 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3614 widget = gtk_printer_option_widget_new (NULL);
3615 priv->job_prio = GTK_PRINTER_OPTION_WIDGET (widget);
3616 gtk_widget_show (widget);
3617 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3618 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3620 label = gtk_label_new_with_mnemonic (_("_Billing info:"));
3621 gtk_widget_set_halign (label, GTK_ALIGN_START);
3622 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3623 gtk_widget_show (label);
3624 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3626 widget = gtk_printer_option_widget_new (NULL);
3627 priv->billing_info = GTK_PRINTER_OPTION_WIDGET (widget);
3628 gtk_widget_show (widget);
3629 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3630 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3632 table = gtk_grid_new ();
3633 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3634 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3635 frame = wrap_in_frame (_("Print Document"), table);
3636 gtk_grid_attach (GTK_GRID (main_table), frame, 0, 1, 1, 1);
3637 gtk_widget_show (table);
3639 /* Translators: this is one of the choices for the print at option
3640 * in the print dialog
3642 radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Now"));
3643 priv->print_now_radio = radio;
3644 gtk_widget_show (radio);
3645 gtk_grid_attach (GTK_GRID (table), radio, 0, 0, 2, 1);
3646 /* Translators: this is one of the choices for the print at option
3647 * in the print dialog. It also serves as the label for an entry that
3648 * allows the user to enter a time.
3650 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
3653 /* Translators: Ability to parse the am/pm format depends on actual locale.
3654 * You can remove the am/pm values below for your locale if they are not
3657 at_tooltip = _("Specify the time of print,\n e.g. 15:30, 2:35 pm, 14:15:20, 11:46:30 am, 4 pm");
3658 gtk_widget_set_tooltip_text (radio, at_tooltip);
3659 priv->print_at_radio = radio;
3660 gtk_widget_show (radio);
3661 gtk_grid_attach (GTK_GRID (table), radio, 0, 1, 1, 1);
3663 entry = gtk_entry_new ();
3664 gtk_widget_set_tooltip_text (entry, at_tooltip);
3665 atk_object_set_name (gtk_widget_get_accessible (entry), _("Time of print"));
3666 atk_object_set_description (gtk_widget_get_accessible (entry), at_tooltip);
3667 priv->print_at_entry = entry;
3668 gtk_widget_show (entry);
3669 gtk_grid_attach (GTK_GRID (table), entry, 1, 1, 1, 1);
3671 g_signal_connect (radio, "toggled", G_CALLBACK (update_entry_sensitivity), entry);
3672 update_entry_sensitivity (radio, entry);
3674 /* Translators: this is one of the choices for the print at option
3675 * in the print dialog. It means that the print job will not be
3676 * printed until it explicitly gets 'released'.
3678 radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
3680 on_hold_tooltip = _("Hold the job until it is explicitly released");
3681 gtk_widget_set_tooltip_text (radio, on_hold_tooltip);
3682 priv->print_hold_radio = radio;
3683 gtk_widget_show (radio);
3684 gtk_grid_attach (GTK_GRID (table), radio, 0, 2, 2, 1);
3686 g_signal_connect_swapped (priv->print_now_radio, "toggled",
3687 G_CALLBACK (update_print_at_option), dialog);
3688 g_signal_connect_swapped (priv->print_at_radio, "toggled",
3689 G_CALLBACK (update_print_at_option), dialog);
3690 g_signal_connect_swapped (priv->print_at_entry, "changed",
3691 G_CALLBACK (update_print_at_option), dialog);
3692 g_signal_connect_swapped (priv->print_hold_radio, "toggled",
3693 G_CALLBACK (update_print_at_option), dialog);
3695 table = gtk_grid_new ();
3696 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3697 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3698 frame = wrap_in_frame (_("Add Cover Page"), table);
3699 gtk_grid_attach (GTK_GRID (main_table), frame, 1, 0, 1, 1);
3700 gtk_widget_show (table);
3702 /* Translators, this is the label used for the option in the print
3703 * dialog that controls the front cover page.
3705 label = gtk_label_new_with_mnemonic (_("Be_fore:"));
3706 gtk_widget_set_halign (label, GTK_ALIGN_START);
3707 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3708 gtk_widget_show (label);
3709 gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
3711 widget = gtk_printer_option_widget_new (NULL);
3712 priv->cover_before = GTK_PRINTER_OPTION_WIDGET (widget);
3713 gtk_widget_show (widget);
3714 gtk_grid_attach (GTK_GRID (table), widget, 1, 0, 1, 1);
3715 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3717 /* Translators, this is the label used for the option in the print
3718 * dialog that controls the back cover page.
3720 label = gtk_label_new_with_mnemonic (_("_After:"));
3721 gtk_widget_set_halign (label, GTK_ALIGN_START);
3722 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
3723 gtk_widget_show (label);
3724 gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
3726 widget = gtk_printer_option_widget_new (NULL);
3727 priv->cover_after = GTK_PRINTER_OPTION_WIDGET (widget);
3728 gtk_widget_show (widget);
3729 gtk_grid_attach (GTK_GRID (table), widget, 1, 1, 1, 1);
3730 gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
3732 /* Translators: this is the tab label for the notebook tab containing
3733 * job-specific options in the print dialog
3735 label = gtk_label_new (_("Job"));
3736 gtk_widget_show (label);
3738 priv->job_page = main_table;
3739 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3744 create_optional_page (GtkPrintUnixDialog *dialog,
3746 GtkWidget **table_out,
3747 GtkWidget **page_out)
3749 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3750 GtkWidget *table, *label, *scrolled;
3752 scrolled = gtk_scrolled_window_new (NULL, NULL);
3753 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
3755 GTK_POLICY_AUTOMATIC);
3757 table = gtk_grid_new ();
3758 gtk_grid_set_row_spacing (GTK_GRID (table), 6);
3759 gtk_grid_set_column_spacing (GTK_GRID (table), 12);
3760 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
3761 gtk_widget_show (table);
3763 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
3765 gtk_viewport_set_shadow_type (GTK_VIEWPORT (gtk_bin_get_child (GTK_BIN (scrolled))),
3768 label = gtk_label_new (text);
3769 gtk_widget_show (label);
3771 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3775 *page_out = scrolled;
3779 create_advanced_page (GtkPrintUnixDialog *dialog)
3781 GtkPrintUnixDialogPrivate *priv = dialog->priv;
3782 GtkWidget *main_vbox, *label, *scrolled;
3784 scrolled = gtk_scrolled_window_new (NULL, NULL);
3785 priv->advanced_page = scrolled;
3786 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
3788 GTK_POLICY_AUTOMATIC);
3790 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
3791 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
3792 gtk_widget_show (main_vbox);
3794 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
3796 gtk_viewport_set_shadow_type (GTK_VIEWPORT (gtk_bin_get_child (GTK_BIN (scrolled))),
3799 priv->advanced_vbox = main_vbox;
3801 label = gtk_label_new (_("Advanced"));
3802 gtk_widget_show (label);
3804 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
3809 populate_dialog (GtkPrintUnixDialog *print_dialog)
3811 GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
3812 GtkDialog *dialog = GTK_DIALOG (print_dialog);
3813 GtkWidget *vbox, *conflict_hbox, *image, *label;
3814 GtkWidget *action_area, *content_area;
3816 content_area = gtk_dialog_get_content_area (dialog);
3817 action_area = gtk_dialog_get_action_area (dialog);
3819 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
3820 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
3821 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
3822 gtk_box_set_spacing (GTK_BOX (action_area), 6);
3824 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
3825 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
3826 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
3827 gtk_widget_show (vbox);
3829 priv->notebook = gtk_notebook_new ();
3830 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
3831 gtk_widget_show (priv->notebook);
3833 create_printer_list_model (print_dialog);
3835 create_main_page (print_dialog);
3836 create_page_setup_page (print_dialog);
3837 create_job_page (print_dialog);
3838 /* Translators: this will appear as tab label in print dialog. */
3839 create_optional_page (print_dialog, _("Image Quality"),
3840 &priv->image_quality_table,
3841 &priv->image_quality_page);
3842 /* Translators: this will appear as tab label in print dialog. */
3843 create_optional_page (print_dialog, _("Color"),
3846 /* Translators: this will appear as tab label in print dialog. */
3847 /* It's a typographical term, as in "Binding and finishing" */
3848 create_optional_page (print_dialog, _("Finishing"),
3849 &priv->finishing_table,
3850 &priv->finishing_page);
3851 create_advanced_page (print_dialog);
3853 priv->conflicts_widget = conflict_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
3854 gtk_box_pack_end (GTK_BOX (vbox), conflict_hbox, FALSE, FALSE, 0);
3855 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
3856 gtk_widget_show (image);
3857 gtk_box_pack_start (GTK_BOX (conflict_hbox), image, FALSE, TRUE, 0);
3858 label = gtk_label_new (_("Some of the settings in the dialog conflict"));
3859 gtk_widget_show (label);
3860 gtk_box_pack_start (GTK_BOX (conflict_hbox), label, FALSE, TRUE, 0);
3862 load_print_backends (print_dialog);
3866 * gtk_print_unix_dialog_new:
3867 * @title: (allow-none): Title of the dialog, or %NULL
3868 * @parent: (allow-none): Transient parent of the dialog, or %NULL
3870 * Creates a new #GtkPrintUnixDialog.
3872 * Return value: a new #GtkPrintUnixDialog
3877 gtk_print_unix_dialog_new (const gchar *title,
3881 const gchar *_title = _("Print");
3886 result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
3887 "transient-for", parent,
3895 * gtk_print_unix_dialog_get_selected_printer:
3896 * @dialog: a #GtkPrintUnixDialog
3898 * Gets the currently selected printer.
3900 * Returns: (transfer none): the currently selected printer
3905 gtk_print_unix_dialog_get_selected_printer (GtkPrintUnixDialog *dialog)
3907 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3909 return dialog->priv->current_printer;
3913 * gtk_print_unix_dialog_set_page_setup:
3914 * @dialog: a #GtkPrintUnixDialog
3915 * @page_setup: a #GtkPageSetup
3917 * Sets the page setup of the #GtkPrintUnixDialog.
3922 gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
3923 GtkPageSetup *page_setup)
3925 GtkPrintUnixDialogPrivate *priv;
3927 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3928 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
3930 priv = dialog->priv;
3932 if (priv->page_setup != page_setup)
3934 g_object_unref (priv->page_setup);
3935 priv->page_setup = g_object_ref (page_setup);
3937 priv->page_setup_set = TRUE;
3939 g_object_notify (G_OBJECT (dialog), "page-setup");
3944 * gtk_print_unix_dialog_get_page_setup:
3945 * @dialog: a #GtkPrintUnixDialog
3947 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3949 * Returns: (transfer none): the page setup of @dialog.
3954 gtk_print_unix_dialog_get_page_setup (GtkPrintUnixDialog *dialog)
3956 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
3958 return dialog->priv->page_setup;
3962 * gtk_print_unix_dialog_get_page_setup_set:
3963 * @dialog: a #GtkPrintUnixDialog
3965 * Gets the page setup that is used by the #GtkPrintUnixDialog.
3967 * Returns: whether a page setup was set by user.
3972 gtk_print_unix_dialog_get_page_setup_set (GtkPrintUnixDialog *dialog)
3974 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
3976 return dialog->priv->page_setup_set;
3980 * gtk_print_unix_dialog_set_current_page:
3981 * @dialog: a #GtkPrintUnixDialog
3982 * @current_page: the current page number.
3984 * Sets the current page number. If @current_page is not -1, this enables
3985 * the current page choice for the range of pages to print.
3990 gtk_print_unix_dialog_set_current_page (GtkPrintUnixDialog *dialog,
3993 GtkPrintUnixDialogPrivate *priv;
3995 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
3997 priv = dialog->priv;
3999 if (priv->current_page != current_page)
4001 priv->current_page = current_page;
4003 if (priv->current_page_radio)
4004 gtk_widget_set_sensitive (priv->current_page_radio, current_page != -1);
4006 g_object_notify (G_OBJECT (dialog), "current-page");
4011 * gtk_print_unix_dialog_get_current_page:
4012 * @dialog: a #GtkPrintUnixDialog
4014 * Gets the current page of the #GtkPrintDialog.
4016 * Returns: the current page of @dialog
4021 gtk_print_unix_dialog_get_current_page (GtkPrintUnixDialog *dialog)
4023 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), -1);
4025 return dialog->priv->current_page;
4029 set_active_printer (GtkPrintUnixDialog *dialog,
4030 const gchar *printer_name)
4032 GtkPrintUnixDialogPrivate *priv = dialog->priv;
4033 GtkTreeModel *model;
4034 GtkTreeIter iter, filter_iter;
4035 GtkTreeSelection *selection;
4036 GtkPrinter *printer;
4038 model = GTK_TREE_MODEL (priv->printer_list);
4040 if (gtk_tree_model_get_iter_first (model, &iter))
4044 gtk_tree_model_get (GTK_TREE_MODEL (priv->printer_list), &iter,
4045 PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
4046 if (printer == NULL)
4049 if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
4051 gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
4052 &filter_iter, &iter);
4054 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
4055 priv->internal_printer_change = TRUE;
4056 gtk_tree_selection_select_iter (selection, &filter_iter);
4057 priv->internal_printer_change = FALSE;
4058 g_free (priv->waiting_for_printer);
4059 priv->waiting_for_printer = NULL;
4061 g_object_unref (printer);
4065 g_object_unref (printer);
4067 } while (gtk_tree_model_iter_next (model, &iter));
4074 * gtk_print_unix_dialog_set_settings:
4075 * @dialog: a #GtkPrintUnixDialog
4076 * @settings: (allow-none): a #GtkPrintSettings, or %NULL
4078 * Sets the #GtkPrintSettings for the #GtkPrintUnixDialog. Typically,
4079 * this is used to restore saved print settings from a previous print
4080 * operation before the print dialog is shown.
4085 gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
4086 GtkPrintSettings *settings)
4088 GtkPrintUnixDialogPrivate *priv;
4089 const gchar *printer;
4090 GtkPageRange *ranges;
4093 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4094 g_return_if_fail (settings == NULL || GTK_IS_PRINT_SETTINGS (settings));
4096 priv = dialog->priv;
4098 if (settings != NULL)
4100 dialog_set_collate (dialog, gtk_print_settings_get_collate (settings));
4101 dialog_set_reverse (dialog, gtk_print_settings_get_reverse (settings));
4102 dialog_set_n_copies (dialog, gtk_print_settings_get_n_copies (settings));
4103 dialog_set_scale (dialog, gtk_print_settings_get_scale (settings));
4104 dialog_set_page_set (dialog, gtk_print_settings_get_page_set (settings));
4105 dialog_set_print_pages (dialog, gtk_print_settings_get_print_pages (settings));
4106 ranges = gtk_print_settings_get_page_ranges (settings, &num_ranges);
4109 dialog_set_page_ranges (dialog, ranges, num_ranges);
4113 priv->format_for_printer =
4114 g_strdup (gtk_print_settings_get (settings, "format-for-printer"));
4117 if (priv->initial_settings)
4118 g_object_unref (priv->initial_settings);
4120 priv->initial_settings = settings;
4122 g_free (priv->waiting_for_printer);
4123 priv->waiting_for_printer = NULL;
4127 g_object_ref (settings);
4129 printer = gtk_print_settings_get_printer (settings);
4131 if (printer && !set_active_printer (dialog, printer))
4132 priv->waiting_for_printer = g_strdup (printer);
4135 g_object_notify (G_OBJECT (dialog), "print-settings");
4139 * gtk_print_unix_dialog_get_settings:
4140 * @dialog: a #GtkPrintUnixDialog
4142 * Gets a new #GtkPrintSettings object that represents the
4143 * current values in the print dialog. Note that this creates a
4144 * <emphasis>new object</emphasis>, and you need to unref it
4145 * if don't want to keep it.
4147 * Returns: a new #GtkPrintSettings object with the values from @dialog
4152 gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
4154 GtkPrintUnixDialogPrivate *priv;
4155 GtkPrintSettings *settings;
4156 GtkPrintPages print_pages;
4157 GtkPageRange *ranges;
4160 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
4162 priv = dialog->priv;
4163 settings = gtk_print_settings_new ();
4165 if (priv->current_printer)
4166 gtk_print_settings_set_printer (settings,
4167 gtk_printer_get_name (priv->current_printer));
4169 gtk_print_settings_set_printer (settings, "default");
4171 gtk_print_settings_set (settings, "format-for-printer",
4172 priv->format_for_printer);
4174 gtk_print_settings_set_collate (settings,
4175 dialog_get_collate (dialog));
4177 gtk_print_settings_set_reverse (settings,
4178 dialog_get_reverse (dialog));
4180 gtk_print_settings_set_n_copies (settings,
4181 dialog_get_n_copies (dialog));
4183 gtk_print_settings_set_scale (settings,
4184 dialog_get_scale (dialog));
4186 gtk_print_settings_set_page_set (settings,
4187 dialog_get_page_set (dialog));
4189 print_pages = dialog_get_print_pages (dialog);
4190 gtk_print_settings_set_print_pages (settings, print_pages);
4192 ranges = dialog_get_page_ranges (dialog, &n_ranges);
4195 gtk_print_settings_set_page_ranges (settings, ranges, n_ranges);
4199 /* TODO: print when. How to handle? */
4201 if (priv->current_printer)
4202 _gtk_printer_get_settings_from_options (priv->current_printer,
4210 * gtk_print_unix_dialog_add_custom_tab:
4211 * @dialog: a #GtkPrintUnixDialog
4212 * @child: the widget to put in the custom tab
4213 * @tab_label: the widget to use as tab label
4215 * Adds a custom tab to the print dialog.
4220 gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
4222 GtkWidget *tab_label)
4224 gtk_notebook_insert_page (GTK_NOTEBOOK (dialog->priv->notebook),
4225 child, tab_label, 2);
4226 gtk_widget_show (child);
4227 gtk_widget_show (tab_label);
4231 * gtk_print_unix_dialog_set_manual_capabilities:
4232 * @dialog: a #GtkPrintUnixDialog
4233 * @capabilities: the printing capabilities of your application
4235 * This lets you specify the printing capabilities your application
4236 * supports. For instance, if you can handle scaling the output then
4237 * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then
4238 * the dialog will only let you select the scale if the printing
4239 * system automatically handles scaling.
4244 gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog,
4245 GtkPrintCapabilities capabilities)
4247 GtkPrintUnixDialogPrivate *priv = dialog->priv;
4249 if (priv->manual_capabilities != capabilities)
4251 priv->manual_capabilities = capabilities;
4252 update_dialog_from_capabilities (dialog);
4254 if (priv->current_printer)
4256 GtkTreeSelection *selection;
4258 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
4260 g_object_unref (priv->current_printer);
4261 priv->current_printer = NULL;
4262 priv->internal_printer_change = TRUE;
4263 selected_printer_changed (selection, dialog);
4264 priv->internal_printer_change = FALSE;
4267 g_object_notify (G_OBJECT (dialog), "manual-capabilities");
4272 * gtk_print_unix_dialog_get_manual_capabilities:
4273 * @dialog: a #GtkPrintUnixDialog
4275 * Gets the value of #GtkPrintUnixDialog:manual-capabilities property.
4277 * Returns: the printing capabilities
4281 GtkPrintCapabilities
4282 gtk_print_unix_dialog_get_manual_capabilities (GtkPrintUnixDialog *dialog)
4284 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4286 return dialog->priv->manual_capabilities;
4290 * gtk_print_unix_dialog_set_support_selection:
4291 * @dialog: a #GtkPrintUnixDialog
4292 * @support_selection: %TRUE to allow print selection
4294 * Sets whether the print dialog allows user to print a selection.
4299 gtk_print_unix_dialog_set_support_selection (GtkPrintUnixDialog *dialog,
4300 gboolean support_selection)
4302 GtkPrintUnixDialogPrivate *priv;
4304 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4306 priv = dialog->priv;
4308 support_selection = support_selection != FALSE;
4309 if (priv->support_selection != support_selection)
4311 priv->support_selection = support_selection;
4313 if (priv->selection_radio)
4315 if (support_selection)
4317 gtk_widget_set_sensitive (priv->selection_radio, priv->has_selection);
4318 gtk_widget_show (priv->selection_radio);
4322 gtk_widget_set_sensitive (priv->selection_radio, FALSE);
4323 gtk_widget_hide (priv->selection_radio);
4327 g_object_notify (G_OBJECT (dialog), "support-selection");
4332 * gtk_print_unix_dialog_get_support_selection:
4333 * @dialog: a #GtkPrintUnixDialog
4335 * Gets the value of #GtkPrintUnixDialog:support-selection property.
4337 * Returns: whether the application supports print of selection
4342 gtk_print_unix_dialog_get_support_selection (GtkPrintUnixDialog *dialog)
4344 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4346 return dialog->priv->support_selection;
4350 * gtk_print_unix_dialog_set_has_selection:
4351 * @dialog: a #GtkPrintUnixDialog
4352 * @has_selection: %TRUE indicates that a selection exists
4354 * Sets whether a selection exists.
4359 gtk_print_unix_dialog_set_has_selection (GtkPrintUnixDialog *dialog,
4360 gboolean has_selection)
4362 GtkPrintUnixDialogPrivate *priv;
4364 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4366 priv = dialog->priv;
4368 has_selection = has_selection != FALSE;
4369 if (priv->has_selection != has_selection)
4371 priv->has_selection = has_selection;
4373 if (priv->selection_radio)
4375 if (priv->support_selection)
4376 gtk_widget_set_sensitive (priv->selection_radio, has_selection);
4378 gtk_widget_set_sensitive (priv->selection_radio, FALSE);
4381 g_object_notify (G_OBJECT (dialog), "has-selection");
4386 * gtk_print_unix_dialog_get_has_selection:
4387 * @dialog: a #GtkPrintUnixDialog
4389 * Gets the value of #GtkPrintUnixDialog:has-selection property.
4391 * Returns: whether there is a selection
4396 gtk_print_unix_dialog_get_has_selection (GtkPrintUnixDialog *dialog)
4398 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4400 return dialog->priv->has_selection;
4404 * gtk_print_unix_dialog_set_embed_page_setup
4405 * @dialog: a #GtkPrintUnixDialog
4406 * @embed: embed page setup selection
4408 * Embed page size combo box and orientation combo box into page setup page.
4413 gtk_print_unix_dialog_set_embed_page_setup (GtkPrintUnixDialog *dialog,
4416 GtkPrintUnixDialogPrivate *priv;
4418 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
4420 priv = dialog->priv;
4422 embed = embed != FALSE;
4423 if (priv->embed_page_setup != embed)
4425 priv->embed_page_setup = embed;
4427 gtk_widget_set_sensitive (priv->paper_size_combo, priv->embed_page_setup);
4428 gtk_widget_set_sensitive (priv->orientation_combo, priv->embed_page_setup);
4430 if (priv->embed_page_setup)
4432 if (priv->paper_size_combo != NULL)
4433 g_signal_connect (priv->paper_size_combo, "changed", G_CALLBACK (paper_size_changed), dialog);
4435 if (priv->orientation_combo)
4436 g_signal_connect (priv->orientation_combo, "changed", G_CALLBACK (orientation_changed), dialog);
4440 if (priv->paper_size_combo != NULL)
4441 g_signal_handlers_disconnect_by_func (priv->paper_size_combo, G_CALLBACK (paper_size_changed), dialog);
4443 if (priv->orientation_combo)
4444 g_signal_handlers_disconnect_by_func (priv->orientation_combo, G_CALLBACK (orientation_changed), dialog);
4447 priv->internal_page_setup_change = TRUE;
4448 update_paper_sizes (dialog);
4449 priv->internal_page_setup_change = FALSE;
4454 * gtk_print_unix_dialog_get_embed_page_setup:
4455 * @dialog: a #GtkPrintUnixDialog
4457 * Gets the value of #GtkPrintUnixDialog:embed-page-setup property.
4459 * Returns: whether there is a selection
4464 gtk_print_unix_dialog_get_embed_page_setup (GtkPrintUnixDialog *dialog)
4466 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), FALSE);
4468 return dialog->priv->embed_page_setup;