2 * Copyright (C) 2006 John (J5) Palmieri <johnp@redhat.com>
3 * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
28 #include "gtkprivate.h"
30 #include "gtkspinbutton.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkcellrenderertext.h"
35 #include "gtktreeselection.h"
36 #include "gtknotebook.h"
37 #include "gtkscrolledwindow.h"
38 #include "gtkcombobox.h"
39 #include "gtktogglebutton.h"
40 #include "gtkradiobutton.h"
41 #include "gtkdrawingarea.h"
45 #include "gtkalignment.h"
48 #include "gtkprintbackend.h"
49 #include "gtkprintunixdialog.h"
50 #include "gtkprinteroptionwidget.h"
53 #define EXAMPLE_PAGE_AREA_SIZE 140
55 #define GTK_PRINT_UNIX_DIALOG_GET_PRIVATE(o) \
56 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PRINT_UNIX_DIALOG, GtkPrintUnixDialogPrivate))
58 static void gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog);
59 static void gtk_print_unix_dialog_finalize (GObject *object);
60 static void gtk_print_unix_dialog_set_property (GObject *object,
64 static void gtk_print_unix_dialog_get_property (GObject *object,
68 static void populate_dialog (GtkPrintUnixDialog *dialog);
69 static void unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog);
70 static void selected_printer_changed (GtkTreeSelection *selection,
71 GtkPrintUnixDialog *dialog);
72 static void clear_per_printer_ui (GtkPrintUnixDialog *dialog);
83 PRINTER_LIST_COL_ICON,
84 PRINTER_LIST_COL_NAME,
85 PRINTER_LIST_COL_STATE,
86 PRINTER_LIST_COL_JOBS,
87 PRINTER_LIST_COL_LOCATION,
88 PRINTER_LIST_COL_PRINTER_OBJ,
92 #define _EXTENTION_POINT_MAIN_PAGE_CUSTOM_INPUT "gtk-main-page-custom-input"
94 struct GtkPrintUnixDialogPrivate
98 GtkWidget *printer_treeview;
100 GtkTreeModel *printer_list;
101 GtkTreeModelFilter *printer_list_filter;
103 GtkPageSetup *page_setup;
105 GtkWidget *all_pages_radio;
106 GtkWidget *current_page_radio;
107 GtkWidget *page_range_radio;
108 GtkWidget *page_range_entry;
110 GtkWidget *copies_spin;
111 GtkWidget *collate_check;
112 GtkWidget *reverse_check;
113 GtkWidget *collate_image;
114 GtkWidget *page_layout_preview;
115 GtkWidget *scale_spin;
116 GtkWidget *page_set_combo;
117 GtkWidget *print_now_radio;
118 GtkWidget *print_at_radio;
119 GtkWidget *print_at_entry;
120 GtkWidget *print_hold_radio;
121 gboolean updating_print_at;
122 GtkPrinterOptionWidget *pages_per_sheet;
123 GtkPrinterOptionWidget *duplex;
124 GtkPrinterOptionWidget *paper_type;
125 GtkPrinterOptionWidget *paper_source;
126 GtkPrinterOptionWidget *output_tray;
127 GtkPrinterOptionWidget *job_prio;
128 GtkPrinterOptionWidget *billing_info;
129 GtkPrinterOptionWidget *cover_before;
130 GtkPrinterOptionWidget *cover_after;
132 GtkWidget *conflicts_widget;
135 GtkWidget *finishing_table;
136 GtkWidget *finishing_page;
137 GtkWidget *image_quality_table;
138 GtkWidget *image_quality_page;
139 GtkWidget *color_table;
140 GtkWidget *color_page;
142 GtkWidget *advanced_vbox;
143 GtkWidget *advanced_page;
145 GHashTable *extention_points;
147 /* These are set initially on selected printer (either default printer, printer
148 * taken from set settings, or user-selected), but when any setting is changed
149 * by the user it is cleared */
150 GtkPrintSettings *initial_settings;
152 /* This is the initial printer set by set_settings. We look for it in the
153 * added printers. We clear this whenever the user manually changes
154 * to another printer, when the user changes a setting or when we find
156 char *waiting_for_printer;
157 gboolean internal_printer_change;
159 GList *print_backends;
161 GtkPrinter *current_printer;
162 guint request_details_tag;
163 GtkPrinterOptionSet *options;
164 gulong options_changed_handler;
165 gulong mark_conflicts_id;
167 char *format_for_printer;
172 G_DEFINE_TYPE (GtkPrintUnixDialog, gtk_print_unix_dialog, GTK_TYPE_DIALOG);
175 static const char *collate_xpm[] = {
183 " ..++++++++++++++++.. ..++++++++++++++++..",
184 " ..++++++++++++++++.. ..++++++++++++++++..",
185 " ..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@..",
186 " ..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@..",
187 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
188 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
189 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
190 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
191 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
192 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
193 "..+++++++++##++++++$@@@@@@@@@.. ..+++++++++##++++++$@@@@@@@@@..",
194 "..+++++++++##+++++#+@@@@@@@@@.. ..+++++++++##+++++#+@@@@@@@@@..",
195 "..@@@@@@@@@@@@@@@@++@@@@@@@@@.. ..@@@@@@@@@@@@@@@@++@@@@@@@@@..",
196 "..@@@@@@@@@@@@@@@@++@@@..@@@@.. ..@@@@@@@@@@@@@@@@++@@@..@@@@..",
197 "..@@@@@@@@@@@@@@@@++@@.@@.@@@.. ..@@@@@@@@@@@@@@@@++@@.@@.@@@..",
198 "..@@@@@@@@@@@@@@@@++@@@@@.@@@.. ..@@@@@@@@@@@@@@@@++@@@@@.@@@..",
199 "..@@@@@@@@@@@@@@@@++@@@@.@@@@.. ..@@@@@@@@@@@@@@@@++@@@@.@@@@..",
200 "..@@@@@@@@@@@@@@@@++@@@.@@@@@.. ..@@@@@@@@@@@@@@@@++@@@.@@@@@..",
201 "..@@@@@@@@@@@@@@@@++@@.@@@@@@.. ..@@@@@@@@@@@@@@@@++@@.@@@@@@..",
202 "..@@@@@@@@@@@@@@@@++@@....@@@.. ..@@@@@@@@@@@@@@@@++@@....@@@..",
203 "..@@@@@@@@@@@@@@@@++@@@@@@@@@.. ..@@@@@@@@@@@@@@@@++@@@@@@@@@..",
204 "..@@@@@@@@@@@@@@@@++@@@@@@@@@.. ..@@@@@@@@@@@@@@@@++@@@@@@@@@..",
205 "..@@@@@@@@@@@@@@@@++@@@@@@@@@.. ..@@@@@@@@@@@@@@@@++@@@@@@@@@..",
206 "..@@@@@@@@@@@.@@@@............. ..@@@@@@@@@@@.@@@@.............",
207 "..@@@@@@@@@@..@@@@............. ..@@@@@@@@@@..@@@@.............",
208 "..@@@@@@@@@@@.@@@@.. ..@@@@@@@@@@@.@@@@.. ",
209 "..@@@@@@@@@@@.@@@@.. ..@@@@@@@@@@@.@@@@.. ",
210 "..@@@@@@@@@@@.@@@@.. ..@@@@@@@@@@@.@@@@.. ",
211 "..@@@@@@@@@@@.@@@@.. ..@@@@@@@@@@@.@@@@.. ",
212 "..@@@@@@@@@@...@@@.. ..@@@@@@@@@@...@@@.. ",
213 "..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@.. ",
214 "..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@.. ",
215 "..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@.. ",
216 ".................... .................... ",
217 ".................... .................... "};
220 static const char *nocollate_xpm[] = {
228 " .................... ....................",
229 " .................... ....................",
230 " ..++++++++++++++++.. ..++++++++++++++++..",
231 " ..++++++++++++++++.. ..++++++++++++++++..",
232 " @@++++++++++++++++.. @@++++++++++++++++..",
233 " @@++++++++++++++++.. @@++++++++++++++++..",
234 " @@++++++++++++++++.. @@++++++++++++++++..",
235 " @@++++++++++++++++.. @@++++++++++++++++..",
236 " @@++++++++++++++++.. @@++++++++++++++++..",
237 " @@++++++++++++++++.. @@++++++++++++++++..",
238 "..@@@@@@@@@##@@@@@@$+++++++++.. ..@@@@@@@@@##@@@@@@$+++++++++..",
239 "..@@@@@@@@@##@@@@@#@+++++++++.. ..@@@@@@@@@##@@@@@#@+++++++++..",
240 "..++++++++++++++++@@+++++++++.. ..++++++++++++++++@@+++++++++..",
241 "..++++++++++++++++@@++++.++++.. ..++++++++++++++++@@+++..++++..",
242 "..++++++++++++++++@@+++..++++.. ..++++++++++++++++@@++.++.+++..",
243 "..++++++++++++++++@@++++.++++.. ..++++++++++++++++@@+++++.+++..",
244 "..++++++++++++++++@@++++.++++.. ..++++++++++++++++@@++++.++++..",
245 "..++++++++++++++++@@++++.++++.. ..++++++++++++++++@@+++.+++++..",
246 "..++++++++++++++++@@++++.++++.. ..++++++++++++++++@@++.++++++..",
247 "..++++++++++++++++@@+++...+++.. ..++++++++++++++++@@++....+++..",
248 "..++++++++++++++++@@+++++++++.. ..++++++++++++++++@@+++++++++..",
249 "..++++++++++++++++@@+++++++++.. ..++++++++++++++++@@+++++++++..",
250 "..++++++++++++++++@@+++++++++.. ..++++++++++++++++@@+++++++++..",
251 "..+++++++++++.++++............. ..++++++++++..++++.............",
252 "..++++++++++..++++............. ..+++++++++.++.+++.............",
253 "..+++++++++++.++++.. ..++++++++++++.+++.. ",
254 "..+++++++++++.++++.. ..+++++++++++.++++.. ",
255 "..+++++++++++.++++.. ..++++++++++.+++++.. ",
256 "..+++++++++++.++++.. ..+++++++++.++++++.. ",
257 "..++++++++++...+++.. ..+++++++++....+++.. ",
258 "..++++++++++++++++.. ..++++++++++++++++.. ",
259 "..++++++++++++++++.. ..++++++++++++++++.. ",
260 "..++++++++++++++++.. ..++++++++++++++++.. ",
261 ".................... .................... ",
262 ".................... .................... "};
265 static const char *collate_reverse_xpm[] = {
273 " ..++++++++++++++++.. ..++++++++++++++++..",
274 " ..++++++++++++++++.. ..++++++++++++++++..",
275 " ..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@..",
276 " ..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@..",
277 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
278 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
279 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
280 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
281 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
282 " ++@@@@@@@@@@@@@@@@.. ++@@@@@@@@@@@@@@@@..",
283 "..+++++++++##++++++$@@@@@@@@@.. ..+++++++++##++++++$@@@@@@@@@..",
284 "..+++++++++##+++++#+@@@@@@@@@.. ..+++++++++##+++++#+@@@@@@@@@..",
285 "..@@@@@@@@@@@@@@@@++@@@@@@@@@.. ..@@@@@@@@@@@@@@@@++@@@@@@@@@..",
286 "..@@@@@@@@@@@@@@@@++@@@@.@@@@.. ..@@@@@@@@@@@@@@@@++@@@@.@@@@..",
287 "..@@@@@@@@@@@@@@@@++@@@..@@@@.. ..@@@@@@@@@@@@@@@@++@@@..@@@@..",
288 "..@@@@@@@@@@@@@@@@++@@@@.@@@@.. ..@@@@@@@@@@@@@@@@++@@@@.@@@@..",
289 "..@@@@@@@@@@@@@@@@++@@@@.@@@@.. ..@@@@@@@@@@@@@@@@++@@@@.@@@@..",
290 "..@@@@@@@@@@@@@@@@++@@@@.@@@@.. ..@@@@@@@@@@@@@@@@++@@@@.@@@@..",
291 "..@@@@@@@@@@@@@@@@++@@@@.@@@@.. ..@@@@@@@@@@@@@@@@++@@@@.@@@@..",
292 "..@@@@@@@@@@@@@@@@++@@@...@@@.. ..@@@@@@@@@@@@@@@@++@@@...@@@..",
293 "..@@@@@@@@@@@@@@@@++@@@@@@@@@.. ..@@@@@@@@@@@@@@@@++@@@@@@@@@..",
294 "..@@@@@@@@@@@@@@@@++@@@@@@@@@.. ..@@@@@@@@@@@@@@@@++@@@@@@@@@..",
295 "..@@@@@@@@@@@@@@@@++@@@@@@@@@.. ..@@@@@@@@@@@@@@@@++@@@@@@@@@..",
296 "..@@@@@@@@@@..@@@@............. ..@@@@@@@@@@..@@@@.............",
297 "..@@@@@@@@@.@@.@@@............. ..@@@@@@@@@.@@.@@@.............",
298 "..@@@@@@@@@@@@.@@@.. ..@@@@@@@@@@@@.@@@.. ",
299 "..@@@@@@@@@@@.@@@@.. ..@@@@@@@@@@@.@@@@.. ",
300 "..@@@@@@@@@@.@@@@@.. ..@@@@@@@@@@.@@@@@.. ",
301 "..@@@@@@@@@.@@@@@@.. ..@@@@@@@@@.@@@@@@.. ",
302 "..@@@@@@@@@....@@@.. ..@@@@@@@@@....@@@.. ",
303 "..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@.. ",
304 "..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@.. ",
305 "..@@@@@@@@@@@@@@@@.. ..@@@@@@@@@@@@@@@@.. ",
306 ".................... .................... ",
307 ".................... .................... "};
310 static const char *nocollate_reverse_xpm[] = {
318 " .................... ....................",
319 " .................... ....................",
320 " ..++++++++++++++++.. ..++++++++++++++++..",
321 " ..++++++++++++++++.. ..++++++++++++++++..",
322 " @@++++++++++++++++.. @@++++++++++++++++..",
323 " @@++++++++++++++++.. @@++++++++++++++++..",
324 " @@++++++++++++++++.. @@++++++++++++++++..",
325 " @@++++++++++++++++.. @@++++++++++++++++..",
326 " @@++++++++++++++++.. @@++++++++++++++++..",
327 " @@++++++++++++++++.. @@++++++++++++++++..",
328 "..@@@@@@@@@##@@@@@@$+++++++++.. ..@@@@@@@@@##@@@@@@$+++++++++..",
329 "..@@@@@@@@@##@@@@@#@+++++++++.. ..@@@@@@@@@##@@@@@#@+++++++++..",
330 "..++++++++++++++++@@+++++++++.. ..++++++++++++++++@@+++++++++..",
331 "..++++++++++++++++@@+++..++++.. ..++++++++++++++++@@++++.++++..",
332 "..++++++++++++++++@@++.++.+++.. ..++++++++++++++++@@+++..++++..",
333 "..++++++++++++++++@@+++++.+++.. ..++++++++++++++++@@++++.++++..",
334 "..++++++++++++++++@@++++.++++.. ..++++++++++++++++@@++++.++++..",
335 "..++++++++++++++++@@+++.+++++.. ..++++++++++++++++@@++++.++++..",
336 "..++++++++++++++++@@++.++++++.. ..++++++++++++++++@@++++.++++..",
337 "..++++++++++++++++@@++....+++.. ..++++++++++++++++@@+++...+++..",
338 "..++++++++++++++++@@+++++++++.. ..++++++++++++++++@@+++++++++..",
339 "..++++++++++++++++@@+++++++++.. ..++++++++++++++++@@+++++++++..",
340 "..++++++++++++++++@@+++++++++.. ..++++++++++++++++@@+++++++++..",
341 "..++++++++++..++++............. ..+++++++++++.++++.............",
342 "..+++++++++.++.+++............. ..++++++++++..++++.............",
343 "..++++++++++++.+++.. ..+++++++++++.++++.. ",
344 "..+++++++++++.++++.. ..+++++++++++.++++.. ",
345 "..++++++++++.+++++.. ..+++++++++++.++++.. ",
346 "..+++++++++.++++++.. ..+++++++++++.++++.. ",
347 "..+++++++++....+++.. ..++++++++++...+++.. ",
348 "..++++++++++++++++.. ..++++++++++++++++.. ",
349 "..++++++++++++++++.. ..++++++++++++++++.. ",
350 "..++++++++++++++++.. ..++++++++++++++++.. ",
351 ".................... .................... ",
352 ".................... .................... "};
356 is_default_printer (GtkPrintUnixDialog *dialog,
359 if (dialog->priv->format_for_printer)
360 return strcmp (dialog->priv->format_for_printer,
361 gtk_printer_get_name (printer)) == 0;
363 return gtk_printer_is_default (printer);
367 gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
369 GObjectClass *object_class;
370 GtkWidgetClass *widget_class;
372 object_class = (GObjectClass *) class;
373 widget_class = (GtkWidgetClass *) class;
375 object_class->finalize = gtk_print_unix_dialog_finalize;
376 object_class->set_property = gtk_print_unix_dialog_set_property;
377 object_class->get_property = gtk_print_unix_dialog_get_property;
379 g_object_class_install_property (object_class,
381 g_param_spec_object ("page-setup",
383 P_("The GtkPageSetup to use"),
385 GTK_PARAM_READWRITE));
387 g_object_class_install_property (object_class,
389 g_param_spec_int ("current-page",
391 P_("The current page in the document"),
395 GTK_PARAM_READWRITE));
397 g_object_class_install_property (object_class,
399 g_param_spec_object ("print-settings",
400 P_("Print Settings"),
401 P_("The GtkPrintSettings used for initializing the dialog"),
402 GTK_TYPE_PRINT_SETTINGS,
403 GTK_PARAM_READWRITE));
405 g_object_class_install_property (object_class,
406 PROP_SELECTED_PRINTER,
407 g_param_spec_object ("selected-printer",
408 P_("Selected Printer"),
409 P_("The GtkPrinter which which is selected"),
411 GTK_PARAM_READABLE));
413 g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));
417 gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
419 dialog->priv = GTK_PRINT_UNIX_DIALOG_GET_PRIVATE (dialog);
420 dialog->priv->print_backends = NULL;
421 dialog->priv->current_page = -1;
423 dialog->priv->extention_points = g_hash_table_new (g_str_hash,
426 dialog->priv->page_setup = gtk_page_setup_new ();
428 populate_dialog (dialog);
430 g_signal_connect (dialog,
432 (GCallback) gtk_print_unix_dialog_destroy,
435 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
436 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
437 GTK_STOCK_PRINT, GTK_RESPONSE_OK,
440 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
441 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
445 gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
447 /* Make sure we don't destroy custom widgets owned by the backends */
448 clear_per_printer_ui (dialog);
452 gtk_print_unix_dialog_finalize (GObject *object)
454 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
456 g_return_if_fail (object != NULL);
458 unschedule_idle_mark_conflicts (dialog);
460 if (dialog->priv->request_details_tag)
462 g_source_remove (dialog->priv->request_details_tag);
463 dialog->priv->request_details_tag = 0;
466 if (dialog->priv->current_printer)
468 g_object_unref (dialog->priv->current_printer);
469 dialog->priv->current_printer = NULL;
472 if (dialog->priv->printer_list)
474 g_object_unref (dialog->priv->printer_list);
475 dialog->priv->printer_list = NULL;
478 if (dialog->priv->printer_list_filter)
480 g_object_unref (dialog->priv->printer_list_filter);
481 dialog->priv->printer_list_filter = NULL;
485 if (dialog->priv->options)
487 g_object_unref (dialog->priv->options);
488 dialog->priv->options = NULL;
491 if (dialog->priv->extention_points)
493 g_hash_table_unref (dialog->priv->extention_points);
494 dialog->priv->extention_points = NULL;
497 if (dialog->priv->page_setup)
499 g_object_unref (dialog->priv->page_setup);
500 dialog->priv->page_setup = NULL;
503 if (dialog->priv->initial_settings)
505 g_object_unref (dialog->priv->initial_settings);
506 dialog->priv->initial_settings = NULL;
509 g_free (dialog->priv->waiting_for_printer);
510 dialog->priv->waiting_for_printer = NULL;
512 g_free (dialog->priv->format_for_printer);
513 dialog->priv->format_for_printer = NULL;
515 if (G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->finalize)
516 G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->finalize (object);
520 printer_removed_cb (GtkPrintBackend *backend,
522 GtkPrintUnixDialog *dialog)
525 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
526 gtk_list_store_remove (GTK_LIST_STORE (dialog->priv->printer_list), iter);
530 printer_status_cb (GtkPrintBackend *backend,
532 GtkPrintUnixDialog *dialog)
535 iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
537 gtk_list_store_set (GTK_LIST_STORE (dialog->priv->printer_list), iter,
538 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
539 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
540 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
541 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
547 printer_added_cb (GtkPrintBackend *backend,
549 GtkPrintUnixDialog *dialog)
551 GtkTreeIter iter, filter_iter;
552 GtkTreeSelection *selection;
554 gtk_list_store_append (GTK_LIST_STORE (dialog->priv->printer_list), &iter);
556 g_object_set_data_full (G_OBJECT (printer),
557 "gtk-print-tree-iter",
558 gtk_tree_iter_copy (&iter),
559 (GDestroyNotify) gtk_tree_iter_free);
561 gtk_list_store_set (GTK_LIST_STORE (dialog->priv->printer_list), &iter,
562 PRINTER_LIST_COL_ICON, gtk_printer_get_icon_name (printer),
563 PRINTER_LIST_COL_NAME, gtk_printer_get_name (printer),
564 PRINTER_LIST_COL_STATE, gtk_printer_get_state_message (printer),
565 PRINTER_LIST_COL_JOBS, gtk_printer_get_job_count (printer),
566 PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
567 PRINTER_LIST_COL_PRINTER_OBJ, printer,
570 gtk_tree_model_filter_convert_child_iter_to_iter (dialog->priv->printer_list_filter,
571 &filter_iter, &iter);
573 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->printer_treeview));
575 if (dialog->priv->waiting_for_printer != NULL &&
576 strcmp (gtk_printer_get_name (printer),
577 dialog->priv->waiting_for_printer) == 0)
579 dialog->priv->internal_printer_change = TRUE;
580 gtk_tree_selection_select_iter (selection, &filter_iter);
581 dialog->priv->internal_printer_change = FALSE;
582 g_free (dialog->priv->waiting_for_printer);
583 dialog->priv->waiting_for_printer = NULL;
585 else if (is_default_printer (dialog, printer) &&
586 gtk_tree_selection_count_selected_rows (selection) == 0)
588 dialog->priv->internal_printer_change = TRUE;
589 gtk_tree_selection_select_iter (selection, &filter_iter);
590 dialog->priv->internal_printer_change = FALSE;
595 printer_list_initialize (GtkPrintUnixDialog *dialog,
596 GtkPrintBackend *print_backend)
601 g_return_if_fail (print_backend != NULL);
603 g_signal_connect_object (print_backend,
605 (GCallback) printer_added_cb,
606 G_OBJECT (dialog), 0);
608 g_signal_connect_object (print_backend,
610 (GCallback) printer_removed_cb,
611 G_OBJECT (dialog), 0);
613 g_signal_connect_object (print_backend,
614 "printer-status-changed",
615 (GCallback) printer_status_cb,
616 G_OBJECT (dialog), 0);
618 list = gtk_print_backend_get_printer_list (print_backend);
623 printer_added_cb (print_backend, node->data, dialog);
631 load_print_backends (GtkPrintUnixDialog *dialog)
635 if (g_module_supported ())
636 dialog->priv->print_backends = gtk_print_backend_load_modules ();
638 for (node = dialog->priv->print_backends; node != NULL; node = node->next)
639 printer_list_initialize (dialog, GTK_PRINT_BACKEND (node->data));
643 gtk_print_unix_dialog_set_property (GObject *object,
649 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
653 case PROP_PAGE_SETUP:
654 gtk_print_unix_dialog_set_page_setup (dialog, g_value_get_object (value));
656 case PROP_CURRENT_PAGE:
657 gtk_print_unix_dialog_set_current_page (dialog, g_value_get_int (value));
659 case PROP_PRINT_SETTINGS:
660 gtk_print_unix_dialog_set_settings (dialog, g_value_get_object (value));
663 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
669 gtk_print_unix_dialog_get_property (GObject *object,
674 GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (object);
678 case PROP_PAGE_SETUP:
679 g_value_set_object (value, dialog->priv->page_setup);
681 case PROP_CURRENT_PAGE:
682 g_value_set_int (value, dialog->priv->current_page);
684 case PROP_PRINT_SETTINGS:
685 g_value_set_object (value, gtk_print_unix_dialog_get_settings (dialog));
687 case PROP_SELECTED_PRINTER:
688 g_value_set_object (value, dialog->priv->current_printer);
691 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
697 is_printer_active (GtkTreeModel *model,
699 GtkPrintUnixDialog *dialog)
704 gtk_tree_model_get (model,
706 PRINTER_LIST_COL_PRINTER_OBJ,
713 result = gtk_printer_is_active (printer);
715 g_object_unref (printer);
721 default_printer_list_sort_func (GtkTreeModel *model,
728 GtkPrinter *a_printer;
729 GtkPrinter *b_printer;
732 gtk_tree_model_get (model, a,
733 PRINTER_LIST_COL_NAME, &a_name,
734 PRINTER_LIST_COL_PRINTER_OBJ, &a_printer,
736 gtk_tree_model_get (model, b,
737 PRINTER_LIST_COL_NAME, &b_name,
738 PRINTER_LIST_COL_PRINTER_OBJ, &b_printer,
741 if (a_printer == NULL && b_printer == NULL)
743 else if (a_printer == NULL)
745 else if (b_printer == NULL)
747 else if (gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
749 else if (gtk_printer_is_virtual (a_printer) && !gtk_printer_is_virtual (b_printer))
751 else if (!gtk_printer_is_virtual (a_printer) && gtk_printer_is_virtual (b_printer))
753 else if (a_name == NULL && b_name == NULL)
755 else if (a_name == NULL && b_name != NULL)
757 else if (a_name != NULL && b_name == NULL)
760 result = g_ascii_strcasecmp (a_name, b_name);
764 g_object_unref (a_printer);
765 g_object_unref (b_printer);
772 create_printer_list_model (GtkPrintUnixDialog *dialog)
775 GtkTreeSortable *sort;
777 model = gtk_list_store_new (PRINTER_LIST_N_COLS,
785 dialog->priv->printer_list = (GtkTreeModel *)model;
786 dialog->priv->printer_list_filter = (GtkTreeModelFilter *) gtk_tree_model_filter_new ((GtkTreeModel *)model,
789 gtk_tree_model_filter_set_visible_func (dialog->priv->printer_list_filter,
790 (GtkTreeModelFilterVisibleFunc) is_printer_active,
794 sort = GTK_TREE_SORTABLE (model);
795 gtk_tree_sortable_set_default_sort_func (sort,
796 default_printer_list_sort_func,
800 gtk_tree_sortable_set_sort_column_id (sort,
801 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
808 wrap_in_frame (const gchar *label,
811 GtkWidget *frame, *alignment, *label_widget;
814 label_widget = gtk_label_new ("");
815 gtk_widget_show (label_widget);
817 bold_text = g_markup_printf_escaped ("<b>%s</b>", label);
818 gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
821 frame = gtk_frame_new ("");
822 gtk_frame_set_label_widget (GTK_FRAME (frame), label_widget);
823 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
825 alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
826 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
828 gtk_container_add (GTK_CONTAINER (frame), alignment);
830 gtk_container_add (GTK_CONTAINER (alignment), child);
832 gtk_widget_show (frame);
833 gtk_widget_show (alignment);
839 setup_option (GtkPrintUnixDialog *dialog,
840 const gchar *option_name,
841 GtkPrinterOptionWidget *widget)
843 GtkPrinterOption *option;
845 option = gtk_printer_option_set_lookup (dialog->priv->options, option_name);
846 gtk_printer_option_widget_set_source (widget, option);
848 return option != NULL;
852 add_option_to_extention_point (GtkPrinterOption *option,
855 GHashTable *extention_points = (GHashTable *) user_data;
858 GtkBox *extention_hbox;
860 extention_hbox = (GtkBox *) g_hash_table_lookup (extention_points, option->name);
865 widget = gtk_printer_option_widget_new (option);
866 gtk_widget_show (widget);
868 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
872 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
873 gtk_widget_show (label);
874 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
876 gtk_box_pack_start (extention_hbox, label, FALSE, FALSE, 6);
877 gtk_box_pack_start (extention_hbox, widget, FALSE, FALSE, 6);
881 gtk_box_pack_start (extention_hbox, widget, FALSE, FALSE, 6);
884 g_warning ("Extention point %s requested but not found.", option->name);
888 add_option_to_table (GtkPrinterOption *option,
892 GtkWidget *label, *widget;
895 table = GTK_TABLE (user_data);
897 if (g_str_has_prefix (option->name, "gtk-"))
900 widget = gtk_printer_option_widget_new (option);
901 gtk_widget_show (widget);
904 gtk_table_resize (table, table->nrows + 1, table->ncols + 1);
906 if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
908 label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
909 gtk_widget_show (label);
911 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
913 gtk_table_attach (table, label,
914 0, 1, row - 1 , row, GTK_FILL, 0, 0, 0);
916 gtk_table_attach (table, widget,
917 1, 2, row - 1, row, GTK_FILL, 0, 0, 0);
920 gtk_table_attach (table, widget,
921 0, 2, row - 1, row, GTK_FILL, 0, 0, 0);
926 setup_page_table (GtkPrinterOptionSet *options,
931 gtk_printer_option_set_foreach_in_group (options, group,
934 if (GTK_TABLE (table)->nrows == 1)
935 gtk_widget_hide (page);
937 gtk_widget_show (page);
941 update_print_at_option (GtkPrintUnixDialog *dialog)
943 GtkPrinterOption *option;
945 option = gtk_printer_option_set_lookup (dialog->priv->options, "gtk-print-time");
950 if (dialog->priv->updating_print_at)
953 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->print_at_radio)))
954 gtk_printer_option_set (option, "at");
955 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->print_hold_radio)))
956 gtk_printer_option_set (option, "on-hold");
958 gtk_printer_option_set (option, "now");
960 option = gtk_printer_option_set_lookup (dialog->priv->options, "gtk-print-time-text");
963 const char *text = gtk_entry_get_text (GTK_ENTRY (dialog->priv->print_at_entry));
964 gtk_printer_option_set (option,text);
970 setup_print_at (GtkPrintUnixDialog *dialog)
972 GtkPrinterOption *option;
974 option = gtk_printer_option_set_lookup (dialog->priv->options, "gtk-print-time");
978 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->print_now_radio),
980 gtk_widget_set_sensitive (dialog->priv->print_at_radio, FALSE);
981 gtk_widget_set_sensitive (dialog->priv->print_at_entry, FALSE);
982 gtk_widget_set_sensitive (dialog->priv->print_hold_radio, FALSE);
983 gtk_entry_set_text (GTK_ENTRY (dialog->priv->print_at_entry), "");
987 dialog->priv->updating_print_at = TRUE;
989 if (gtk_printer_option_has_choice (option, "at"))
991 gtk_widget_set_sensitive (dialog->priv->print_at_radio, TRUE);
992 gtk_widget_set_sensitive (dialog->priv->print_at_entry, TRUE);
996 gtk_widget_set_sensitive (dialog->priv->print_at_radio, FALSE);
997 gtk_widget_set_sensitive (dialog->priv->print_at_entry, FALSE);
1000 gtk_widget_set_sensitive (dialog->priv->print_hold_radio,
1001 gtk_printer_option_has_choice (option, "on-hold"));
1003 update_print_at_option (dialog);
1005 if (strcmp (option->value, "at") == 0)
1006 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->print_at_radio),
1008 else if (strcmp (option->value, "on-hold") == 0)
1009 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->print_hold_radio),
1012 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->print_now_radio),
1015 option = gtk_printer_option_set_lookup (dialog->priv->options, "gtk-print-time-text");
1017 gtk_entry_set_text (GTK_ENTRY (dialog->priv->print_at_entry),
1021 dialog->priv->updating_print_at = FALSE;
1027 update_dialog_from_settings (GtkPrintUnixDialog *dialog)
1031 GtkWidget *table, *frame;
1032 gboolean has_advanced, has_job;
1034 if (dialog->priv->current_printer == NULL)
1036 clear_per_printer_ui (dialog);
1037 gtk_widget_hide (dialog->priv->job_page);
1038 gtk_widget_hide (dialog->priv->advanced_page);
1039 gtk_widget_hide (dialog->priv->image_quality_page);
1040 gtk_widget_hide (dialog->priv->finishing_page);
1041 gtk_widget_hide (dialog->priv->color_page);
1042 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1047 setup_option (dialog, "gtk-n-up", dialog->priv->pages_per_sheet);
1048 setup_option (dialog, "gtk-duplex", dialog->priv->duplex);
1049 setup_option (dialog, "gtk-paper-type", dialog->priv->paper_type);
1050 setup_option (dialog, "gtk-paper-source", dialog->priv->paper_source);
1051 setup_option (dialog, "gtk-output-tray", dialog->priv->output_tray);
1054 has_job |= setup_option (dialog, "gtk-job-prio", dialog->priv->job_prio);
1055 has_job |= setup_option (dialog, "gtk-billing-info", dialog->priv->billing_info);
1056 has_job |= setup_option (dialog, "gtk-cover-before", dialog->priv->cover_before);
1057 has_job |= setup_option (dialog, "gtk-cover-after", dialog->priv->cover_after);
1058 has_job |= setup_print_at (dialog);
1061 gtk_widget_show (dialog->priv->job_page);
1063 gtk_widget_hide (dialog->priv->job_page);
1066 setup_page_table (dialog->priv->options,
1068 dialog->priv->image_quality_table,
1069 dialog->priv->image_quality_page);
1071 setup_page_table (dialog->priv->options,
1073 dialog->priv->finishing_table,
1074 dialog->priv->finishing_page);
1076 setup_page_table (dialog->priv->options,
1078 dialog->priv->color_table,
1079 dialog->priv->color_page);
1081 /* Put the rest of the groups in the advanced page */
1082 groups = gtk_printer_option_set_get_groups (dialog->priv->options);
1084 has_advanced = FALSE;
1085 for (l = groups; l != NULL; l = l->next)
1092 if (strcmp (group, "ImageQualityPage") == 0 ||
1093 strcmp (group, "ColorPage") == 0 ||
1094 strcmp (group, "FinishingPage") == 0)
1097 if (strcmp (group, "GtkPrintDialogExtention") == 0)
1099 gtk_printer_option_set_foreach_in_group (dialog->priv->options,
1101 add_option_to_extention_point,
1102 dialog->priv->extention_points);
1106 table = gtk_table_new (1, 2, FALSE);
1107 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1108 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1110 gtk_printer_option_set_foreach_in_group (dialog->priv->options,
1112 add_option_to_table,
1114 if (GTK_TABLE (table)->nrows == 1)
1115 gtk_widget_destroy (table);
1118 has_advanced = TRUE;
1119 frame = wrap_in_frame (group, table);
1120 gtk_widget_show (table);
1121 gtk_widget_show (frame);
1123 gtk_box_pack_start (GTK_BOX (dialog->priv->advanced_vbox),
1124 frame, FALSE, FALSE, 0);
1129 gtk_widget_show (dialog->priv->advanced_page);
1131 gtk_widget_hide (dialog->priv->advanced_page);
1134 g_list_foreach (groups, (GFunc) g_free, NULL);
1135 g_list_free (groups);
1139 mark_conflicts (GtkPrintUnixDialog *dialog)
1141 GtkPrinter *printer;
1142 gboolean have_conflict;
1144 have_conflict = FALSE;
1146 printer = dialog->priv->current_printer;
1151 g_signal_handler_block (dialog->priv->options,
1152 dialog->priv->options_changed_handler);
1154 gtk_printer_option_set_clear_conflicts (dialog->priv->options);
1156 have_conflict = _gtk_printer_mark_conflicts (printer,
1157 dialog->priv->options);
1159 g_signal_handler_unblock (dialog->priv->options,
1160 dialog->priv->options_changed_handler);
1164 gtk_widget_show (dialog->priv->conflicts_widget);
1166 gtk_widget_hide (dialog->priv->conflicts_widget);
1170 mark_conflicts_callback (gpointer data)
1172 GtkPrintUnixDialog *dialog = data;
1174 dialog->priv->mark_conflicts_id = 0;
1176 mark_conflicts (dialog);
1182 unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1184 if (dialog->priv->mark_conflicts_id != 0)
1186 g_source_remove (dialog->priv->mark_conflicts_id);
1187 dialog->priv->mark_conflicts_id = 0;
1192 schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
1194 if (dialog->priv->mark_conflicts_id != 0)
1197 dialog->priv->mark_conflicts_id = g_idle_add (mark_conflicts_callback,
1202 options_changed_cb (GtkPrintUnixDialog *dialog)
1204 schedule_idle_mark_conflicts (dialog);
1206 if (dialog->priv->initial_settings)
1208 g_object_unref (dialog->priv->initial_settings);
1209 dialog->priv->initial_settings = NULL;
1212 g_free (dialog->priv->waiting_for_printer);
1213 dialog->priv->waiting_for_printer = NULL;
1217 remove_custom_widget (GtkWidget *widget,
1218 GtkContainer *container)
1220 gtk_container_remove (container, widget);
1224 extention_point_clear_children (const gchar *key,
1225 GtkContainer *container,
1228 gtk_container_foreach (container,
1229 (GtkCallback)remove_custom_widget,
1234 clear_per_printer_ui (GtkPrintUnixDialog *dialog)
1236 gtk_container_foreach (GTK_CONTAINER (dialog->priv->finishing_table),
1237 (GtkCallback)gtk_widget_destroy,
1239 gtk_table_resize (GTK_TABLE (dialog->priv->finishing_table), 1, 2);
1240 gtk_container_foreach (GTK_CONTAINER (dialog->priv->image_quality_table),
1241 (GtkCallback)gtk_widget_destroy,
1243 gtk_table_resize (GTK_TABLE (dialog->priv->image_quality_table), 1, 2);
1244 gtk_container_foreach (GTK_CONTAINER (dialog->priv->color_table),
1245 (GtkCallback)gtk_widget_destroy,
1247 gtk_table_resize (GTK_TABLE (dialog->priv->color_table), 1, 2);
1248 gtk_container_foreach (GTK_CONTAINER (dialog->priv->advanced_vbox),
1249 (GtkCallback)gtk_widget_destroy,
1251 g_hash_table_foreach (dialog->priv->extention_points,
1252 (GHFunc) extention_point_clear_children,
1257 printer_details_acquired (GtkPrinter *printer,
1259 GtkPrintUnixDialog *dialog)
1261 dialog->priv->request_details_tag = 0;
1265 GtkTreeSelection *selection;
1266 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->printer_treeview));
1268 selected_printer_changed (selection, dialog);
1273 selected_printer_changed (GtkTreeSelection *selection,
1274 GtkPrintUnixDialog *dialog)
1276 GtkPrinter *printer;
1277 GtkTreeIter iter, filter_iter;
1279 /* Whenever the user selects a printer we stop looking for
1280 the printer specified in the initial settings */
1281 if (dialog->priv->waiting_for_printer &&
1282 !dialog->priv->internal_printer_change)
1284 g_free (dialog->priv->waiting_for_printer);
1285 dialog->priv->waiting_for_printer = NULL;
1288 if (dialog->priv->request_details_tag)
1290 g_source_remove (dialog->priv->request_details_tag);
1291 dialog->priv->request_details_tag = 0;
1295 if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
1297 gtk_tree_model_filter_convert_iter_to_child_iter (dialog->priv->printer_list_filter,
1301 gtk_tree_model_get (dialog->priv->printer_list, &iter,
1302 PRINTER_LIST_COL_PRINTER_OBJ, &printer,
1306 if (printer != NULL && !_gtk_printer_has_details (printer))
1308 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1309 dialog->priv->request_details_tag =
1310 g_signal_connect (printer, "details-acquired",
1311 G_CALLBACK (printer_details_acquired), dialog);
1312 _gtk_printer_request_details (printer);
1316 if (printer == dialog->priv->current_printer)
1319 g_object_unref (printer);
1323 if (dialog->priv->options)
1325 g_object_unref (dialog->priv->options);
1326 dialog->priv->options = NULL;
1328 clear_per_printer_ui (dialog);
1331 if (dialog->priv->current_printer)
1333 g_object_unref (dialog->priv->current_printer);
1336 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1337 dialog->priv->current_printer = printer;
1339 if (printer != NULL)
1341 dialog->priv->options = _gtk_printer_get_options (printer, dialog->priv->initial_settings,
1342 dialog->priv->page_setup);
1344 dialog->priv->options_changed_handler =
1345 g_signal_connect_swapped (dialog->priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
1348 update_dialog_from_settings (dialog);
1352 update_collate_icon (GtkToggleButton *toggle_button,
1353 GtkPrintUnixDialog *dialog)
1356 gboolean collate, reverse;
1359 collate = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
1360 reverse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
1365 xpm = collate_reverse_xpm;
1372 xpm = nocollate_reverse_xpm;
1374 xpm = nocollate_xpm;
1377 pixbuf = gdk_pixbuf_new_from_xpm_data (xpm);
1378 gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->priv->collate_image), pixbuf);
1379 g_object_unref (pixbuf);
1383 create_main_page (GtkPrintUnixDialog *dialog)
1385 GtkPrintUnixDialogPrivate *priv;
1386 GtkWidget *main_vbox, *label, *hbox;
1387 GtkWidget *scrolled, *treeview, *frame, *table;
1388 GtkWidget *entry, *spinbutton;
1389 GtkWidget *radio, *check, *image;
1390 GtkCellRenderer *renderer;
1391 GtkTreeViewColumn *column;
1392 GtkTreeSelection *selection;
1393 GtkWidget *custom_input;
1395 priv = dialog->priv;
1397 main_vbox = gtk_vbox_new (FALSE, 6);
1398 gtk_widget_show (main_vbox);
1400 scrolled = gtk_scrolled_window_new (NULL, NULL);
1401 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
1402 GTK_POLICY_AUTOMATIC,
1403 GTK_POLICY_AUTOMATIC);
1404 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
1406 gtk_widget_show (scrolled);
1407 gtk_box_pack_start (GTK_BOX (main_vbox), scrolled, TRUE, TRUE, 0);
1409 treeview = gtk_tree_view_new_with_model ((GtkTreeModel *) priv->printer_list_filter);
1410 priv->printer_treeview = treeview;
1411 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
1412 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), PRINTER_LIST_COL_NAME);
1413 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), TRUE);
1414 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
1415 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
1416 g_signal_connect (selection, "changed", G_CALLBACK (selected_printer_changed), dialog);
1418 renderer = gtk_cell_renderer_pixbuf_new ();
1419 column = gtk_tree_view_column_new_with_attributes ("",
1422 PRINTER_LIST_COL_ICON,
1424 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1427 renderer = gtk_cell_renderer_text_new ();
1428 column = gtk_tree_view_column_new_with_attributes (_("Printer"),
1431 PRINTER_LIST_COL_NAME,
1433 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1435 renderer = gtk_cell_renderer_text_new ();
1436 column = gtk_tree_view_column_new_with_attributes (_("Location"),
1439 PRINTER_LIST_COL_LOCATION,
1441 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1443 renderer = gtk_cell_renderer_text_new ();
1444 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1445 column = gtk_tree_view_column_new_with_attributes (_("Status"),
1448 PRINTER_LIST_COL_STATE,
1450 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
1452 gtk_widget_show (treeview);
1453 gtk_container_add (GTK_CONTAINER (scrolled), treeview);
1455 custom_input = gtk_hbox_new (FALSE, 8);
1456 gtk_widget_show (custom_input);
1457 gtk_box_pack_start (GTK_BOX (main_vbox), custom_input, FALSE, FALSE, 0);
1458 g_hash_table_insert (dialog->priv->extention_points,
1459 _EXTENTION_POINT_MAIN_PAGE_CUSTOM_INPUT,
1462 hbox = gtk_hbox_new (FALSE, 8);
1463 gtk_widget_show (hbox);
1464 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
1466 table = gtk_table_new (3, 2, FALSE);
1467 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1468 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1469 frame = wrap_in_frame (_("Print Pages"), table);
1470 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
1471 gtk_widget_show (table);
1473 radio = gtk_radio_button_new_with_label (NULL, _("All"));
1474 priv->all_pages_radio = radio;
1475 gtk_widget_show (radio);
1476 gtk_table_attach (GTK_TABLE (table), radio,
1477 0, 1, 0, 1, GTK_FILL, 0,
1479 radio = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
1481 if (dialog->priv->current_page == -1)
1482 gtk_widget_set_sensitive (radio, FALSE);
1483 priv->current_page_radio = radio;
1484 gtk_widget_show (radio);
1485 gtk_table_attach (GTK_TABLE (table), radio,
1486 0, 1, 1, 2, GTK_FILL, 0,
1488 radio = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
1490 priv->page_range_radio = radio;
1491 gtk_widget_show (radio);
1492 gtk_table_attach (GTK_TABLE (table), radio,
1493 0, 1, 2, 3, GTK_FILL, 0,
1495 entry = gtk_entry_new ();
1496 priv->page_range_entry = entry;
1497 gtk_widget_show (entry);
1498 gtk_table_attach (GTK_TABLE (table), entry,
1499 1, 2, 2, 3, GTK_FILL, 0,
1502 table = gtk_table_new (3, 2, FALSE);
1503 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1504 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1505 frame = wrap_in_frame (_("Copies"), table);
1506 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
1507 gtk_widget_show (table);
1509 label = gtk_label_new (_("Copies:"));
1510 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1511 gtk_widget_show (label);
1512 gtk_table_attach (GTK_TABLE (table), label,
1513 0, 1, 0, 1, GTK_FILL, 0,
1515 spinbutton = gtk_spin_button_new_with_range (1.0, 100.0, 1.0);
1516 priv->copies_spin = spinbutton;
1517 gtk_widget_show (spinbutton);
1518 gtk_table_attach (GTK_TABLE (table), spinbutton,
1519 1, 2, 0, 1, GTK_FILL, 0,
1522 check = gtk_check_button_new_with_mnemonic (_("_Collate"));
1523 priv->collate_check = check;
1524 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
1525 gtk_widget_show (check);
1526 gtk_table_attach (GTK_TABLE (table), check,
1527 0, 1, 1, 2, GTK_FILL, 0,
1529 check = gtk_check_button_new_with_mnemonic (_("_Reverse"));
1530 g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
1531 priv->reverse_check = check;
1532 gtk_widget_show (check);
1533 gtk_table_attach (GTK_TABLE (table), check,
1534 0, 1, 2, 3, GTK_FILL, 0,
1537 image = gtk_image_new ();
1538 dialog->priv->collate_image = image;
1539 gtk_widget_show (image);
1540 gtk_table_attach (GTK_TABLE (table), image,
1541 1, 2, 1, 3, GTK_FILL, 0,
1544 update_collate_icon (NULL, dialog);
1546 label = gtk_label_new (_("General"));
1547 gtk_widget_show (label);
1549 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
1555 is_range_separator (gchar c)
1557 return (c == ',' || c == ';' || c == ':');
1560 static GtkPageRange *
1561 dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
1565 const char *text, *p;
1567 GtkPageRange *ranges;
1570 text = gtk_entry_get_text (GTK_ENTRY (dialog->priv->page_range_entry));
1582 if (is_range_separator (*p))
1587 ranges = g_new0 (GtkPageRange, n_ranges);
1593 start = (int)strtol (p, &next, 10);
1605 end = (int)strtol (p, NULL, 10);
1611 ranges[i].start = start - 1;
1612 ranges[i].end = end - 1;
1615 /* Skip until end or separator */
1616 while (*p && !is_range_separator (*p))
1619 /* if not at end, skip separator */
1630 dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
1631 GtkPageRange *ranges,
1635 GString *s = g_string_new ("");
1637 for (i = 0; i < n_ranges; i++)
1639 g_string_append_printf (s, "%d", ranges[i].start + 1);
1640 if (ranges[i].end > ranges[i].start)
1641 g_string_append_printf (s, "-%d", ranges[i].end + 1);
1643 if (i != n_ranges - 1)
1644 g_string_append (s, ",");
1647 gtk_entry_set_text (GTK_ENTRY (dialog->priv->page_range_entry),
1650 g_string_free (s, TRUE);
1654 static GtkPrintPages
1655 dialog_get_print_pages (GtkPrintUnixDialog *dialog)
1657 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1659 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio)))
1660 return GTK_PRINT_PAGES_ALL;
1661 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->current_page_radio)))
1662 return GTK_PRINT_PAGES_CURRENT;
1664 return GTK_PRINT_PAGES_RANGES;
1668 dialog_set_print_pages (GtkPrintUnixDialog *dialog, GtkPrintPages pages)
1670 GtkPrintUnixDialogPrivate *priv = dialog->priv;
1672 if (pages == GTK_PRINT_PAGES_RANGES)
1673 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
1674 else if (pages == GTK_PRINT_PAGES_CURRENT)
1675 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->current_page_radio), TRUE);
1677 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_pages_radio), TRUE);
1681 dialog_get_scale (GtkPrintUnixDialog *dialog)
1683 return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
1687 dialog_set_scale (GtkPrintUnixDialog *dialog,
1690 return gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin),
1695 dialog_get_page_set (GtkPrintUnixDialog *dialog)
1697 return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
1701 dialog_set_page_set (GtkPrintUnixDialog *dialog,
1704 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->page_set_combo),
1709 dialog_get_n_copies (GtkPrintUnixDialog *dialog)
1711 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
1715 dialog_set_n_copies (GtkPrintUnixDialog *dialog,
1718 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->copies_spin),
1723 dialog_get_collate (GtkPrintUnixDialog *dialog)
1725 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
1729 dialog_set_collate (GtkPrintUnixDialog *dialog,
1732 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check),
1737 dialog_get_reverse (GtkPrintUnixDialog *dialog)
1739 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
1743 dialog_set_reverse (GtkPrintUnixDialog *dialog,
1746 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check),
1751 dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
1756 val = gtk_printer_option_widget_get_value (dialog->priv->pages_per_sheet);
1772 draw_page_cb (GtkWidget *widget,
1773 GdkEventExpose *event,
1774 GtkPrintUnixDialog *dialog)
1778 int w, h, tmp, shadow_offset;
1779 int pages_x, pages_y, i, x, y, layout_w, layout_h;
1780 double page_width, page_height;
1781 GtkPageOrientation orientation;
1783 PangoLayout *layout;
1784 PangoFontDescription *font;
1787 orientation = gtk_page_setup_get_orientation (dialog->priv->page_setup);
1789 (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
1790 (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
1792 cr = gdk_cairo_create (widget->window);
1796 w = (EXAMPLE_PAGE_AREA_SIZE - 3) / ratio;
1799 switch (dialog_get_pages_per_sheet (dialog))
1803 pages_x = 1; pages_y = 1;
1806 landscape = !landscape;
1807 pages_x = 1; pages_y = 2;
1810 pages_x = 2; pages_y = 2;
1813 landscape = !landscape;
1814 pages_x = 2; pages_y = 3;
1817 pages_x = 3; pages_y = 3;
1820 pages_x = 4; pages_y = 4;
1837 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
1838 cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
1841 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
1842 cairo_rectangle (cr, 1, 1, w, h);
1844 cairo_set_line_width (cr, 1.0);
1845 cairo_rectangle (cr, 0.5, 0.5, w+1, h+1);
1847 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
1852 page_width = (double)w / pages_x;
1853 page_height = (double)h / pages_y;
1855 layout = pango_cairo_create_layout (cr);
1857 font = pango_font_description_new ();
1858 pango_font_description_set_family (font, "sans");
1859 pango_font_description_set_absolute_size (font, page_height * 0.4 * PANGO_SCALE);
1860 pango_layout_set_font_description (layout, font);
1861 pango_font_description_free (font);
1863 pango_layout_set_width (layout, page_width * PANGO_SCALE);
1864 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
1866 for (y = 0; y < pages_y; y++)
1868 for (x = 0; x < pages_x; x++)
1870 text = g_strdup_printf ("%d", i++);
1871 pango_layout_set_text (layout, text, -1);
1873 pango_layout_get_size (layout, &layout_w, &layout_h);
1875 cairo_translate (cr,
1877 y * page_height + (page_height - layout_h / 1024.0) / 2
1880 pango_cairo_show_layout (cr, layout);
1889 redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
1891 if (dialog->priv->page_layout_preview)
1892 gtk_widget_queue_draw (dialog->priv->page_layout_preview);
1896 create_page_setup_page (GtkPrintUnixDialog *dialog)
1898 GtkPrintUnixDialogPrivate *priv;
1899 GtkWidget *main_vbox, *label, *hbox, *hbox2;
1900 GtkWidget *frame, *table, *widget;
1901 GtkWidget *combo, *spinbutton, *draw;
1903 priv = dialog->priv;
1905 main_vbox = gtk_vbox_new (FALSE, 8);
1906 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6);
1907 gtk_widget_show (main_vbox);
1909 hbox = gtk_hbox_new (FALSE, 8);
1910 gtk_widget_show (hbox);
1911 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, TRUE, TRUE, 0);
1913 table = gtk_table_new (5, 2, FALSE);
1914 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1915 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1916 frame = wrap_in_frame (_("Layout"), table);
1917 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
1918 gtk_widget_show (table);
1920 label = gtk_label_new (_("Pages per sheet:"));
1921 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1922 gtk_widget_show (label);
1923 gtk_table_attach (GTK_TABLE (table), label,
1924 0, 1, 0, 1, GTK_FILL, 0,
1927 widget = gtk_printer_option_widget_new (NULL);
1928 g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
1929 priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
1930 gtk_widget_show (widget);
1931 gtk_table_attach (GTK_TABLE (table), widget,
1932 1, 2, 0, 1, GTK_FILL, 0,
1935 label = gtk_label_new (_("Two-sided:"));
1936 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1937 gtk_widget_show (label);
1938 gtk_table_attach (GTK_TABLE (table), label,
1939 0, 1, 1, 2, GTK_FILL, 0,
1942 widget = gtk_printer_option_widget_new (NULL);
1943 priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
1944 gtk_widget_show (widget);
1945 gtk_table_attach (GTK_TABLE (table), widget,
1946 1, 2, 1, 2, GTK_FILL, 0,
1949 label = gtk_label_new (_("Only Print:"));
1950 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1951 gtk_widget_show (label);
1952 gtk_table_attach (GTK_TABLE (table), label,
1953 0, 1, 2, 3, GTK_FILL, 0,
1956 combo = gtk_combo_box_new_text ();
1957 priv->page_set_combo = combo;
1958 gtk_widget_show (combo);
1959 gtk_table_attach (GTK_TABLE (table), combo,
1960 1, 2, 2, 3, GTK_FILL, 0,
1963 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("All pages"));
1964 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Even pages"));
1965 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Odd pages"));
1966 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
1968 label = gtk_label_new (_("Scale:"));
1969 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1970 gtk_widget_show (label);
1971 gtk_table_attach (GTK_TABLE (table), label,
1972 0, 1, 3, 4, GTK_FILL, 0,
1975 hbox2 = gtk_hbox_new (FALSE, 0);
1976 gtk_widget_show (hbox2);
1977 gtk_table_attach (GTK_TABLE (table), hbox2,
1978 1, 2, 3, 4, GTK_FILL, 0,
1981 spinbutton = gtk_spin_button_new_with_range (1.0, 1000.0, 1.0);
1982 priv->scale_spin = spinbutton;
1983 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), 1);
1984 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton), 100.0);
1985 gtk_widget_show (spinbutton);
1986 gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
1987 label = gtk_label_new ("%");
1988 gtk_widget_show (label);
1989 gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
1992 table = gtk_table_new (4, 2, FALSE);
1993 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1994 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1995 frame = wrap_in_frame (_("Paper"), table);
1996 gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
1997 gtk_widget_show (table);
1999 label = gtk_label_new (_("Paper Type:"));
2000 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2001 gtk_widget_show (label);
2002 gtk_table_attach (GTK_TABLE (table), label,
2003 0, 1, 0, 1, GTK_FILL, 0,
2006 widget = gtk_printer_option_widget_new (NULL);
2007 priv->paper_type = GTK_PRINTER_OPTION_WIDGET (widget);
2008 gtk_widget_show (widget);
2009 gtk_table_attach (GTK_TABLE (table), widget,
2010 1, 2, 0, 1, GTK_FILL, 0,
2013 label = gtk_label_new (_("Paper Source:"));
2014 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2015 gtk_widget_show (label);
2016 gtk_table_attach (GTK_TABLE (table), label,
2017 0, 1, 1, 2, GTK_FILL, 0,
2020 widget = gtk_printer_option_widget_new (NULL);
2021 priv->paper_source = GTK_PRINTER_OPTION_WIDGET (widget);
2022 gtk_widget_show (widget);
2023 gtk_table_attach (GTK_TABLE (table), widget,
2024 1, 2, 1, 2, GTK_FILL, 0,
2027 label = gtk_label_new (_("Output Tray:"));
2028 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2029 gtk_widget_show (label);
2030 gtk_table_attach (GTK_TABLE (table), label,
2031 0, 1, 2, 3, GTK_FILL, 0,
2034 widget = gtk_printer_option_widget_new (NULL);
2035 priv->output_tray = GTK_PRINTER_OPTION_WIDGET (widget);
2036 gtk_widget_show (widget);
2037 gtk_table_attach (GTK_TABLE (table), widget,
2038 1, 2, 2, 3, GTK_FILL, 0,
2041 hbox2 = gtk_hbox_new (FALSE, 0);
2042 gtk_widget_show (hbox2);
2043 gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 6);
2045 draw = gtk_drawing_area_new ();
2046 dialog->priv->page_layout_preview = draw;
2047 gtk_widget_set_size_request (draw, 200, 200);
2048 g_signal_connect (draw, "expose_event", G_CALLBACK (draw_page_cb), dialog);
2049 gtk_widget_show (draw);
2051 gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 6);
2053 label = gtk_label_new (_("Page Setup"));
2054 gtk_widget_show (label);
2056 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2062 create_job_page (GtkPrintUnixDialog *dialog)
2064 GtkPrintUnixDialogPrivate *priv;
2065 GtkWidget *main_table, *label;
2066 GtkWidget *frame, *table, *radio;
2067 GtkWidget *entry, *widget;
2069 priv = dialog->priv;
2071 main_table = gtk_table_new (2, 2, FALSE);
2072 gtk_container_set_border_width (GTK_CONTAINER (main_table), 6);
2074 table = gtk_table_new (2, 2, FALSE);
2075 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2076 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2077 frame = wrap_in_frame (_("Job Details"), table);
2078 gtk_table_attach (GTK_TABLE (main_table), frame,
2081 gtk_widget_show (table);
2083 label = gtk_label_new (_("Priority:"));
2084 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2085 gtk_widget_show (label);
2086 gtk_table_attach (GTK_TABLE (table), label,
2087 0, 1, 0, 1, GTK_FILL, 0,
2090 widget = gtk_printer_option_widget_new (NULL);
2091 priv->job_prio = GTK_PRINTER_OPTION_WIDGET (widget);
2092 gtk_widget_show (widget);
2093 gtk_table_attach (GTK_TABLE (table), widget,
2094 1, 2, 0, 1, GTK_FILL, 0,
2097 label = gtk_label_new (_("Billing info:"));
2098 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2099 gtk_widget_show (label);
2100 gtk_table_attach (GTK_TABLE (table), label,
2101 0, 1, 1, 2, GTK_FILL, 0,
2104 widget = gtk_printer_option_widget_new (NULL);
2105 priv->billing_info = GTK_PRINTER_OPTION_WIDGET (widget);
2106 gtk_widget_show (widget);
2107 gtk_table_attach (GTK_TABLE (table), widget,
2108 1, 2, 1, 2, GTK_FILL, 0,
2112 table = gtk_table_new (2, 2, FALSE);
2113 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2114 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2115 frame = wrap_in_frame (_("Print Document"), table);
2116 gtk_table_attach (GTK_TABLE (main_table), frame,
2119 gtk_widget_show (table);
2121 radio = gtk_radio_button_new_with_label (NULL, _("Now"));
2122 priv->print_now_radio = radio;
2123 gtk_widget_show (radio);
2124 gtk_table_attach (GTK_TABLE (table), radio,
2125 0, 1, 0, 1, GTK_FILL, 0,
2127 radio = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2129 priv->print_at_radio = radio;
2130 gtk_widget_show (radio);
2131 gtk_table_attach (GTK_TABLE (table), radio,
2132 0, 1, 1, 2, GTK_FILL, 0,
2134 radio = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
2136 priv->print_hold_radio = radio;
2137 gtk_widget_show (radio);
2138 gtk_table_attach (GTK_TABLE (table), radio,
2139 0, 1, 2, 3, GTK_FILL, 0,
2141 entry = gtk_entry_new ();
2142 priv->print_at_entry = entry;
2143 gtk_widget_show (entry);
2144 gtk_table_attach (GTK_TABLE (table), entry,
2145 1, 2, 1, 2, GTK_FILL, 0,
2148 g_signal_connect_swapped (priv->print_now_radio, "toggled",
2149 G_CALLBACK (update_print_at_option), dialog);
2150 g_signal_connect_swapped (priv->print_at_radio, "toggled",
2151 G_CALLBACK (update_print_at_option), dialog);
2152 g_signal_connect_swapped (priv->print_at_entry, "changed",
2153 G_CALLBACK (update_print_at_option), dialog);
2154 g_signal_connect_swapped (priv->print_hold_radio, "toggled",
2155 G_CALLBACK (update_print_at_option), dialog);
2157 table = gtk_table_new (2, 2, FALSE);
2158 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2159 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2160 frame = wrap_in_frame (_("Add Cover Page"), table);
2161 gtk_table_attach (GTK_TABLE (main_table), frame,
2164 gtk_widget_show (table);
2166 label = gtk_label_new (_("Before:"));
2167 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2168 gtk_widget_show (label);
2169 gtk_table_attach (GTK_TABLE (table), label,
2170 0, 1, 0, 1, GTK_FILL, 0,
2173 widget = gtk_printer_option_widget_new (NULL);
2174 priv->cover_before = GTK_PRINTER_OPTION_WIDGET (widget);
2175 gtk_widget_show (widget);
2176 gtk_table_attach (GTK_TABLE (table), widget,
2177 1, 2, 0, 1, GTK_FILL, 0,
2180 label = gtk_label_new (_("After:"));
2181 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2182 gtk_widget_show (label);
2183 gtk_table_attach (GTK_TABLE (table), label,
2184 0, 1, 1, 2, GTK_FILL, 0,
2187 widget = gtk_printer_option_widget_new (NULL);
2188 priv->cover_after = GTK_PRINTER_OPTION_WIDGET (widget);
2189 gtk_widget_show (widget);
2190 gtk_table_attach (GTK_TABLE (table), widget,
2191 1, 2, 1, 2, GTK_FILL, 0,
2194 label = gtk_label_new (_("Job"));
2195 gtk_widget_show (label);
2197 priv->job_page = main_table;
2198 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2203 create_optional_page (GtkPrintUnixDialog *dialog,
2205 GtkWidget **table_out,
2206 GtkWidget **page_out)
2208 GtkPrintUnixDialogPrivate *priv;
2209 GtkWidget *table, *label, *scrolled;
2211 priv = dialog->priv;
2213 scrolled = gtk_scrolled_window_new (NULL, NULL);
2214 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2216 GTK_POLICY_AUTOMATIC);
2218 table = gtk_table_new (1, 2, FALSE);
2219 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
2220 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
2221 gtk_container_set_border_width (GTK_CONTAINER (table), 6);
2222 gtk_widget_show (table);
2224 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
2226 gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN(scrolled)->child),
2229 label = gtk_label_new (text);
2230 gtk_widget_show (label);
2232 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2236 *page_out = scrolled;
2240 create_advanced_page (GtkPrintUnixDialog *dialog)
2242 GtkPrintUnixDialogPrivate *priv;
2243 GtkWidget *main_vbox, *label, *scrolled;
2245 priv = dialog->priv;
2247 scrolled = gtk_scrolled_window_new (NULL, NULL);
2248 priv->advanced_page = scrolled;
2249 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
2251 GTK_POLICY_AUTOMATIC);
2253 main_vbox = gtk_vbox_new (FALSE, 8);
2254 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6);
2255 gtk_widget_show (main_vbox);
2257 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
2259 gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN(scrolled)->child),
2262 dialog->priv->advanced_vbox = main_vbox;
2264 label = gtk_label_new (_("Advanced"));
2265 gtk_widget_show (label);
2267 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
2273 populate_dialog (GtkPrintUnixDialog *dialog)
2275 GtkPrintUnixDialogPrivate *priv;
2276 GtkWidget *hbox, *conflict_hbox, *image, *label;
2278 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
2280 priv = dialog->priv;
2282 create_printer_list_model (dialog);
2284 priv->notebook = gtk_notebook_new ();
2286 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
2290 create_main_page (dialog);
2291 create_page_setup_page (dialog);
2292 create_job_page (dialog);
2293 create_optional_page (dialog, _("Image Quality"),
2294 &dialog->priv->image_quality_table,
2295 &dialog->priv->image_quality_page);
2296 create_optional_page (dialog, _("Color"),
2297 &dialog->priv->color_table,
2298 &dialog->priv->color_page);
2299 create_optional_page (dialog, _("Finishing"),
2300 &dialog->priv->finishing_table,
2301 &dialog->priv->finishing_page);
2302 create_advanced_page (dialog);
2304 hbox = gtk_hbox_new (FALSE, 0);
2305 gtk_widget_show (hbox);
2306 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
2309 conflict_hbox = gtk_hbox_new (FALSE, 0);
2310 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
2311 gtk_widget_show (image);
2312 gtk_box_pack_start (GTK_BOX (conflict_hbox), image, FALSE, TRUE, 0);
2313 label = gtk_label_new (_("Some of the settings in the dialog conflict"));
2314 gtk_widget_show (label);
2315 gtk_box_pack_start (GTK_BOX (conflict_hbox), label, FALSE, TRUE, 0);
2316 dialog->priv->conflicts_widget = conflict_hbox;
2318 gtk_box_pack_start (GTK_BOX (hbox), conflict_hbox,
2321 /* Reparent the action area into the hbox. This is so we can have the
2322 * conflict warning on the same row, but not make the buttons the same
2323 * width as the warning (which the buttonbox does).
2325 g_object_ref (GTK_DIALOG (dialog)->action_area);
2326 gtk_container_remove (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
2327 GTK_DIALOG (dialog)->action_area);
2328 gtk_box_pack_end (GTK_BOX (hbox), GTK_DIALOG (dialog)->action_area,
2330 g_object_unref (GTK_DIALOG (dialog)->action_area);
2332 gtk_widget_show (dialog->priv->notebook);
2334 load_print_backends (dialog);
2338 * gtk_print_unix_dialog_new:
2339 * @title: Title of the dialog, or %NULL
2340 * @parent: Transient parent of the dialog, or %NULL
2342 * Creates a new #GtkPrintUnixDialog.
2344 * Return value: a new #GtkPrintUnixDialog
2349 gtk_print_unix_dialog_new (const gchar *title,
2353 const gchar *_title = _("Print");
2358 result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
2360 "has-separator", FALSE,
2364 gtk_window_set_transient_for (GTK_WINDOW (result), parent);
2370 gtk_print_unix_dialog_get_selected_printer (GtkPrintUnixDialog *dialog)
2372 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
2374 return dialog->priv->current_printer;
2378 gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
2379 GtkPageSetup *page_setup)
2381 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
2382 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
2384 if (dialog->priv->page_setup != page_setup)
2386 g_object_unref (dialog->priv->page_setup);
2387 dialog->priv->page_setup = g_object_ref (page_setup);
2389 g_object_notify (G_OBJECT (dialog), "page-setup");
2394 gtk_print_unix_dialog_get_page_setup (GtkPrintUnixDialog *dialog)
2396 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
2398 return dialog->priv->page_setup;
2402 gtk_print_unix_dialog_set_current_page (GtkPrintUnixDialog *dialog,
2405 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
2407 if (dialog->priv->current_page != current_page)
2409 dialog->priv->current_page = current_page;
2411 if (dialog->priv->current_page_radio)
2412 gtk_widget_set_sensitive (dialog->priv->current_page_radio, current_page != -1);
2414 g_object_notify (G_OBJECT (dialog), "current-page");
2419 gtk_print_unix_dialog_get_current_page (GtkPrintUnixDialog *dialog)
2421 g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), -1);
2423 return dialog->priv->current_page;
2427 set_active_printer (GtkPrintUnixDialog *dialog,
2428 const gchar *printer_name)
2430 GtkTreeModel *model;
2431 GtkTreeIter iter, filter_iter;
2432 GtkTreeSelection *selection;
2433 GtkPrinter *printer;
2435 model = GTK_TREE_MODEL (dialog->priv->printer_list);
2437 if (gtk_tree_model_get_iter_first (model, &iter))
2441 gtk_tree_model_get (GTK_TREE_MODEL (dialog->priv->printer_list), &iter,
2442 PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
2443 if (printer == NULL)
2446 if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
2448 gtk_tree_model_filter_convert_child_iter_to_iter (dialog->priv->printer_list_filter,
2449 &filter_iter, &iter);
2451 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->printer_treeview));
2452 dialog->priv->internal_printer_change = TRUE;
2453 gtk_tree_selection_select_iter (selection, &filter_iter);
2454 dialog->priv->internal_printer_change = FALSE;
2455 g_free (dialog->priv->waiting_for_printer);
2456 dialog->priv->waiting_for_printer = NULL;
2458 g_object_unref (printer);
2462 g_object_unref (printer);
2464 } while (gtk_tree_model_iter_next (model, &iter));
2471 gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
2472 GtkPrintSettings *settings)
2474 const char *printer;
2475 GtkPageRange *ranges;
2478 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
2479 g_return_if_fail (settings == NULL || GTK_IS_PRINT_SETTINGS (settings));
2481 if (settings != NULL)
2483 dialog_set_collate (dialog, gtk_print_settings_get_collate (settings));
2484 dialog_set_reverse (dialog, gtk_print_settings_get_reverse (settings));
2485 dialog_set_n_copies (dialog, gtk_print_settings_get_num_copies (settings));
2486 dialog_set_scale (dialog, gtk_print_settings_get_scale (settings));
2487 dialog_set_page_set (dialog, gtk_print_settings_get_page_set (settings));
2488 dialog_set_print_pages (dialog, gtk_print_settings_get_print_pages (settings));
2489 ranges = gtk_print_settings_get_page_ranges (settings, &num_ranges);
2491 dialog_set_page_ranges (dialog, ranges, num_ranges);
2493 dialog->priv->format_for_printer =
2494 g_strdup (gtk_print_settings_get (settings, "format-for-printer"));
2497 if (dialog->priv->initial_settings)
2498 g_object_unref (dialog->priv->initial_settings);
2500 dialog->priv->initial_settings = settings;
2502 g_free (dialog->priv->waiting_for_printer);
2503 dialog->priv->waiting_for_printer = NULL;
2507 g_object_ref (settings);
2509 printer = gtk_print_settings_get_printer (settings);
2511 if (printer && !set_active_printer (dialog, printer))
2512 dialog->priv->waiting_for_printer = g_strdup (printer);
2515 g_object_notify (G_OBJECT (dialog), "print-settings");
2519 gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
2521 GtkPrintSettings *settings;
2522 GtkPrintPages print_pages;
2523 GtkPageRange *ranges;
2526 g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
2528 settings = gtk_print_settings_new ();
2530 if (dialog->priv->current_printer)
2531 gtk_print_settings_set_printer (settings,
2532 gtk_printer_get_name (dialog->priv->current_printer));
2534 gtk_print_settings_set_printer (settings, "default");
2536 gtk_print_settings_set (settings, "format-for-printer",
2537 dialog->priv->format_for_printer);
2540 gtk_print_settings_set_collate (settings,
2541 dialog_get_collate (dialog));
2543 gtk_print_settings_set_reverse (settings,
2544 dialog_get_reverse (dialog));
2546 gtk_print_settings_set_num_copies (settings,
2547 dialog_get_n_copies (dialog));
2549 gtk_print_settings_set_scale (settings,
2550 dialog_get_scale (dialog));
2552 gtk_print_settings_set_page_set (settings,
2553 dialog_get_page_set (dialog));
2555 print_pages = dialog_get_print_pages (dialog);
2556 gtk_print_settings_set_print_pages (settings, print_pages);
2558 ranges = dialog_get_page_ranges (dialog, &n_ranges);
2561 gtk_print_settings_set_page_ranges (settings, ranges, n_ranges);
2565 /* TODO: print when. How to handle? */
2567 if (dialog->priv->current_printer)
2568 _gtk_printer_get_settings_from_options (dialog->priv->current_printer,
2569 dialog->priv->options,
2576 #define __GTK_PRINT_UNIX_DIALOG_C__
2577 #include "gtkaliasdef.c"