]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprintunixdialog.c
Bug 344522 – support non-local destination files (GtkPrint):
[~andy/gtk] / gtk / gtkprintunixdialog.c
index 59cf75321beb75fbf0a1709889345eda85729724..8751bfe975e145dd4b33271d0c4db7f4e1bedd3a 100644 (file)
@@ -1,6 +1,7 @@
 /* GtkPrintUnixDialog
  * Copyright (C) 2006 John (J5) Palmieri  <johnp@redhat.com>
  * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
+ * Copyright © 2006, 2007 Christian Persch
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,6 +22,7 @@
 #include "config.h"
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <stdio.h>
 #include <math.h>
 
 #include "gtkframe.h"
 #include "gtkalignment.h"
 #include "gtklabel.h"
+#include "gtkeventbox.h"
+#include "gtkbuildable.h"
 
 #include "gtkprintbackend.h"
+#include "gtkprinter-private.h"
 #include "gtkprintunixdialog.h"
 #include "gtkprinteroptionwidget.h"
 #include "gtkalias.h"
 
+#include "gtkmessagedialog.h"
+#include "gtkbutton.h"
+
 #define EXAMPLE_PAGE_AREA_SIZE 140
 
 #define GTK_PRINT_UNIX_DIALOG_GET_PRIVATE(o)  \
    (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PRINT_UNIX_DIALOG, GtkPrintUnixDialogPrivate))
 
-static void gtk_print_unix_dialog_destroy      (GtkPrintUnixDialog *dialog);
-static void gtk_print_unix_dialog_finalize     (GObject            *object);
-static void gtk_print_unix_dialog_set_property (GObject            *object,
-                                               guint               prop_id,
-                                               const GValue       *value,
-                                               GParamSpec         *pspec);
-static void gtk_print_unix_dialog_get_property (GObject            *object,
-                                               guint               prop_id,
-                                               GValue             *value,
-                                               GParamSpec         *pspec);
-static void gtk_print_unix_dialog_style_set    (GtkWidget          *widget,
-                                               GtkStyle           *previous_style);
-static void populate_dialog                    (GtkPrintUnixDialog *dialog);
-static void unschedule_idle_mark_conflicts     (GtkPrintUnixDialog *dialog);
-static void selected_printer_changed           (GtkTreeSelection   *selection,
-                                               GtkPrintUnixDialog *dialog);
-static void clear_per_printer_ui               (GtkPrintUnixDialog *dialog);
-static void printer_added_cb                   (GtkPrintBackend    *backend,
-                                               GtkPrinter         *printer,
-                                               GtkPrintUnixDialog *dialog);
-static void printer_removed_cb                 (GtkPrintBackend    *backend,
-                                               GtkPrinter         *printer,
-                                               GtkPrintUnixDialog *dialog);
-static void printer_status_cb                  (GtkPrintBackend    *backend,
-                                               GtkPrinter         *printer,
-                                               GtkPrintUnixDialog *dialog);
+static void     gtk_print_unix_dialog_destroy      (GtkPrintUnixDialog *dialog);
+static void     gtk_print_unix_dialog_finalize     (GObject            *object);
+static void     gtk_print_unix_dialog_set_property (GObject            *object,
+                                                   guint               prop_id,
+                                                   const GValue       *value,
+                                                   GParamSpec         *pspec);
+static void     gtk_print_unix_dialog_get_property (GObject            *object,
+                                                   guint               prop_id,
+                                                   GValue             *value,
+                                                   GParamSpec         *pspec);
+static void     gtk_print_unix_dialog_style_set    (GtkWidget          *widget,
+                                                   GtkStyle           *previous_style);
+static void     populate_dialog                    (GtkPrintUnixDialog *dialog);
+static void     unschedule_idle_mark_conflicts     (GtkPrintUnixDialog *dialog);
+static void     selected_printer_changed           (GtkTreeSelection   *selection,
+                                                   GtkPrintUnixDialog *dialog);
+static void     clear_per_printer_ui               (GtkPrintUnixDialog *dialog);
+static void     printer_added_cb                   (GtkPrintBackend    *backend,
+                                                   GtkPrinter         *printer,
+                                                   GtkPrintUnixDialog *dialog);
+static void     printer_removed_cb                 (GtkPrintBackend    *backend,
+                                                   GtkPrinter         *printer,
+                                                   GtkPrintUnixDialog *dialog);
+static void     printer_status_cb                  (GtkPrintBackend    *backend,
+                                                   GtkPrinter         *printer,
+                                                   GtkPrintUnixDialog *dialog);
+static void     update_collate_icon                (GtkToggleButton    *toggle_button,
+                                                   GtkPrintUnixDialog *dialog);
+static gboolean dialog_get_collate                 (GtkPrintUnixDialog *dialog);
+static gboolean dialog_get_reverse                 (GtkPrintUnixDialog *dialog);
+static gint     dialog_get_n_copies                (GtkPrintUnixDialog *dialog);
+
+static void     set_cell_sensitivity_func          (GtkTreeViewColumn *tree_column,
+                                                   GtkCellRenderer   *cell,
+                                                   GtkTreeModel      *model,
+                                                   GtkTreeIter       *iter,
+                                                   gpointer           data);
+static gboolean set_active_printer                 (GtkPrintUnixDialog *dialog,
+                                                   const gchar        *printer_name);
+
+/* GtkBuildable */
+static void gtk_print_unix_dialog_buildable_init                    (GtkBuildableIface *iface);
+static GObject *gtk_print_unix_dialog_buildable_get_internal_child  (GtkBuildable *buildable,
+                                                                     GtkBuilder   *builder,
+                                                                     const gchar  *childname);
 
 enum {
   PROP_0,
@@ -101,18 +128,20 @@ enum {
   PRINTER_LIST_N_COLS
 };
 
-#define _EXTENTION_POINT_MAIN_PAGE_CUSTOM_INPUT "gtk-main-page-custom-input"
-
 struct GtkPrintUnixDialogPrivate
 {
   GtkWidget *notebook;
 
   GtkWidget *printer_treeview;
+
+  GtkPrintCapabilities manual_capabilities;
+  GtkPrintCapabilities printer_capabilities;
   
   GtkTreeModel *printer_list;
   GtkTreeModelFilter *printer_list_filter;
 
   GtkPageSetup *page_setup;
+  gboolean page_setup_set;
 
   GtkWidget *all_pages_radio;
   GtkWidget *current_page_radio;
@@ -130,6 +159,7 @@ struct GtkPrintUnixDialogPrivate
   GtkWidget *print_at_radio;
   GtkWidget *print_at_entry;
   GtkWidget *print_hold_radio;
+  GtkWidget *preview_button;
   gboolean updating_print_at;
   GtkPrinterOptionWidget *pages_per_sheet;
   GtkPrinterOptionWidget *duplex;
@@ -140,6 +170,7 @@ struct GtkPrintUnixDialogPrivate
   GtkPrinterOptionWidget *billing_info;
   GtkPrinterOptionWidget *cover_before;
   GtkPrinterOptionWidget *cover_after;
+  GtkPrinterOptionWidget *number_up_layout;
 
   GtkWidget *conflicts_widget;
 
@@ -154,38 +185,48 @@ struct GtkPrintUnixDialogPrivate
   GtkWidget *advanced_vbox;
   GtkWidget *advanced_page;
 
-  GHashTable *extension_points;  
+  GtkWidget *extension_point;
 
-  /* These are set initially on selected printer (either default printer, printer
-   * taken from set settings, or user-selected), but when any setting is changed
-   * by the user it is cleared */
+  /* These are set initially on selected printer (either default printer, 
+   * printer taken from set settings, or user-selected), but when any setting 
+   * is changed by the user it is cleared.
+   */
   GtkPrintSettings *initial_settings;
+
+  GtkPrinterOption *number_up_layout_n_option;
+  GtkPrinterOption *number_up_layout_2_option;
   
   /* This is the initial printer set by set_settings. We look for it in the
    * added printers. We clear this whenever the user manually changes
    * to another printer, when the user changes a setting or when we find
-   * this printer */
+   * this printer.
+   */
   char *waiting_for_printer;
   gboolean internal_printer_change;
   
   GList *print_backends;
   
   GtkPrinter *current_printer;
+  GtkPrinter *request_details_printer;
   guint request_details_tag;
   GtkPrinterOptionSet *options;
   gulong options_changed_handler;
   gulong mark_conflicts_id;
 
-  char *format_for_printer;
+  gchar *format_for_printer;
   
   gint current_page;
 };
 
-G_DEFINE_TYPE (GtkPrintUnixDialog, gtk_print_unix_dialog, GTK_TYPE_DIALOG);
+G_DEFINE_TYPE_WITH_CODE (GtkPrintUnixDialog, gtk_print_unix_dialog, GTK_TYPE_DIALOG,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                                gtk_print_unix_dialog_buildable_init))
+
+static GtkBuildableIface *parent_buildable_iface;
 
 static gboolean
 is_default_printer (GtkPrintUnixDialog *dialog,
-                   GtkPrinter *printer)
+                   GtkPrinter         *printer)
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
 
@@ -241,13 +282,138 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
                                   PROP_SELECTED_PRINTER,
                                   g_param_spec_object ("selected-printer",
                                                        P_("Selected Printer"),
-                                                       P_("The GtkPrinter which which is selected"),
+                                                       P_("The GtkPrinter which is selected"),
                                                        GTK_TYPE_PRINTER,
                                                        GTK_PARAM_READABLE));
   
+  
   g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));  
 }
 
+/* Returns a toplevel GtkWindow, or NULL if none */
+static GtkWindow *
+get_toplevel (GtkWidget *widget)
+{
+  GtkWidget *toplevel = NULL;
+
+  toplevel = gtk_widget_get_toplevel (widget);
+  if (!GTK_WIDGET_TOPLEVEL (toplevel))
+    return NULL;
+  else
+    return GTK_WINDOW (toplevel);
+}
+
+static void
+add_custom_button_to_dialog (GtkDialog   *dialog,
+                             const gchar *mnemonic_label,
+                             const gchar *stock_id,
+                             gint         response_id)
+{
+  GtkWidget *button = NULL;
+
+  button = gtk_button_new_with_mnemonic (mnemonic_label);
+  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+  gtk_button_set_image (GTK_BUTTON (button),
+                        gtk_image_new_from_stock (stock_id,
+                                                  GTK_ICON_SIZE_BUTTON));
+  gtk_widget_show (button);
+
+  gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
+}
+
+/* This function handles error messages before printing.
+ */
+static gboolean
+error_dialogs (GtkPrintUnixDialog *print_dialog,
+               gint                print_dialog_response_id,
+               gpointer            data)
+{
+  GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
+  GtkPrinterOption          *option = NULL;
+  GtkPrinter                *printer = NULL;
+  GtkWindow                 *toplevel = NULL;
+  GtkWidget                 *dialog = NULL;
+  GFile                     *file = NULL;
+  gchar                     *basename = NULL;
+  gchar                     *dirname = NULL;
+  int                        response;
+
+  if (print_dialog != NULL && print_dialog_response_id == GTK_RESPONSE_OK)
+    {
+      printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
+
+      /* Shows overwrite confirmation dialog in the case of printing to file which
+       * already exists. */
+      if (printer != NULL && gtk_printer_is_virtual (printer))
+        {
+          option = gtk_printer_option_set_lookup (priv->options,
+                                                  "gtk-main-page-custom-input");
+
+          if (option != NULL &&
+              option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE)
+            {
+              file = g_file_new_for_uri (option->value);
+
+              if (file != NULL &&
+                  g_file_query_exists (file, NULL))
+                {
+                  toplevel = get_toplevel (GTK_WIDGET (print_dialog));
+
+                  basename = g_file_get_basename (file);
+                  dirname = g_file_get_parse_name (g_file_get_parent (file));
+
+                  dialog = gtk_message_dialog_new (toplevel,
+                                                   GTK_DIALOG_MODAL |
+                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                   GTK_MESSAGE_QUESTION,
+                                                   GTK_BUTTONS_NONE,
+                                                   _("A file named \"%s\" already exists.  Do you want to replace it?"),
+                                                   basename);
+
+                  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                            _("The file already exists in \"%s\".  Replacing it will "
+                                                            "overwrite its contents."),
+                                                            dirname);
+
+                  gtk_dialog_add_button (GTK_DIALOG (dialog),
+                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+                  add_custom_button_to_dialog (GTK_DIALOG (dialog),
+                                               _("_Replace"),
+                                               GTK_STOCK_PRINT,
+                                               GTK_RESPONSE_ACCEPT);
+                  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
+                                                           GTK_RESPONSE_ACCEPT,
+                                                           GTK_RESPONSE_CANCEL,
+                                                           -1);
+                  gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+                                                   GTK_RESPONSE_ACCEPT);
+
+                  if (toplevel->group)
+                    gtk_window_group_add_window (toplevel->group,
+                                                 GTK_WINDOW (dialog));
+
+                  response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+                  gtk_widget_destroy (dialog);
+
+                  g_free (dirname);
+                  g_free (basename);
+
+                  if (response != GTK_RESPONSE_ACCEPT)
+                    {
+                      g_signal_stop_emission_by_name (print_dialog, "response");
+                      g_object_unref (file);
+                      return TRUE;
+                    }
+                }
+
+              g_object_unref (file);
+            }
+        }
+    }
+  return FALSE;
+}
+
 static void
 gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
 {
@@ -256,26 +422,42 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
   priv = dialog->priv = GTK_PRINT_UNIX_DIALOG_GET_PRIVATE (dialog); 
   priv->print_backends = NULL;
   priv->current_page = -1;
-
-  priv->extension_points = g_hash_table_new (g_str_hash,
-                                             g_str_equal);
+  priv->number_up_layout_n_option = NULL;
+  priv->number_up_layout_2_option = NULL;
 
   priv->page_setup = gtk_page_setup_new ();
-
-  populate_dialog (dialog);
+  priv->page_setup_set = FALSE;
 
   g_signal_connect (dialog, 
                     "destroy", 
                    (GCallback) gtk_print_unix_dialog_destroy, 
                    NULL);
 
-  gtk_dialog_add_buttons (GTK_DIALOG (dialog), 
+  g_signal_connect (dialog,
+                    "response",
+                    (GCallback) error_dialogs,
+                    NULL);
+
+  priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
+  gtk_widget_show (priv->preview_button);
+   
+  gtk_dialog_add_action_widget (GTK_DIALOG (dialog), 
+                                priv->preview_button, 
+                                GTK_RESPONSE_APPLY);
+  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                          GTK_STOCK_PRINT, GTK_RESPONSE_OK,
                           NULL);
+  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
+                                          GTK_RESPONSE_APPLY,
+                                          GTK_RESPONSE_OK,
+                                          GTK_RESPONSE_CANCEL,
+                                          -1);
 
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
   gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
+
+  populate_dialog (dialog);  
 }
 
 static void
@@ -285,6 +467,21 @@ gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
   clear_per_printer_ui (dialog);  
 }
 
+static void
+disconnect_printer_details_request (GtkPrintUnixDialog *dialog)
+{
+  GtkPrintUnixDialogPrivate *priv = dialog->priv;
+
+  if (priv->request_details_tag)
+    {
+      g_signal_handler_disconnect (priv->request_details_printer,
+                                   priv->request_details_tag);
+      priv->request_details_tag = 0;
+      g_object_unref (priv->request_details_printer);
+      priv->request_details_printer = NULL;
+    }
+}
+
 static void
 gtk_print_unix_dialog_finalize (GObject *object)
 {
@@ -294,13 +491,8 @@ gtk_print_unix_dialog_finalize (GObject *object)
   GList *node;
 
   unschedule_idle_mark_conflicts (dialog);
+  disconnect_printer_details_request (dialog);
 
-  if (priv->request_details_tag)
-    {
-      g_source_remove (priv->request_details_tag);
-      priv->request_details_tag = 0;
-    }
-  
   if (priv->current_printer)
     {
       g_object_unref (priv->current_printer);
@@ -326,13 +518,25 @@ gtk_print_unix_dialog_finalize (GObject *object)
       priv->options = NULL;
     }
  
-  if (priv->extension_points)
+  if (priv->number_up_layout_2_option)
     {
-      g_hash_table_unref (priv->extension_points);
-      priv->extension_points = NULL;
+      priv->number_up_layout_2_option->choices[0] = NULL;
+      priv->number_up_layout_2_option->choices[1] = NULL;
+      g_free (priv->number_up_layout_2_option->choices_display[0]);
+      g_free (priv->number_up_layout_2_option->choices_display[1]);
+      priv->number_up_layout_2_option->choices_display[0] = NULL;
+      priv->number_up_layout_2_option->choices_display[1] = NULL;
+      g_object_unref (priv->number_up_layout_2_option);
+      priv->number_up_layout_2_option = NULL;
     }
-  if (priv->page_setup)
+
+  if (priv->number_up_layout_n_option)
+    {
+      g_object_unref (priv->number_up_layout_n_option);
+      priv->number_up_layout_n_option = NULL;
+    }
+
+ if (priv->page_setup)
     {
       g_object_unref (priv->page_setup);
       priv->page_setup = NULL;
@@ -380,6 +584,47 @@ printer_removed_cb (GtkPrintBackend    *backend,
   gtk_list_store_remove (GTK_LIST_STORE (priv->printer_list), iter);
 }
 
+static void
+gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+
+  iface->get_internal_child = gtk_print_unix_dialog_buildable_get_internal_child;
+}
+
+static GObject *
+gtk_print_unix_dialog_buildable_get_internal_child (GtkBuildable *buildable,
+                                                    GtkBuilder   *builder,
+                                                    const gchar  *childname)
+{
+  if (strcmp (childname, "notebook") == 0)
+    return G_OBJECT (GTK_PRINT_UNIX_DIALOG (buildable)->priv->notebook);
+
+  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
+}
+
+/* This function controls "sensitive" property of GtkCellRenderer based on pause
+ * state of printers. */
+void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
+                                GtkCellRenderer   *cell,
+                                GtkTreeModel      *tree_model,
+                                GtkTreeIter       *iter,
+                                gpointer           data)
+{
+  GtkPrinter *printer;
+  
+  gtk_tree_model_get (tree_model, iter, PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1);
+
+  if (printer != NULL && !gtk_printer_is_accepting_jobs (printer))
+    g_object_set (cell,
+                  "sensitive", FALSE,
+                  NULL);
+  else
+    g_object_set (cell,
+                  "sensitive", TRUE,
+                  NULL);
+}
+
 static void
 printer_status_cb (GtkPrintBackend    *backend, 
                   GtkPrinter         *printer, 
@@ -387,6 +632,7 @@ printer_status_cb (GtkPrintBackend    *backend,
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
   GtkTreeIter *iter;
+  GtkTreeSelection *selection;
 
   iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
 
@@ -397,6 +643,15 @@ printer_status_cb (GtkPrintBackend    *backend,
                       PRINTER_LIST_COL_LOCATION, gtk_printer_get_location (printer),
                       -1);
 
+  /* When the pause state change then we need to update sensitive property
+   * of GTK_RESPONSE_OK button inside of selected_printer_changed function. */
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
+  selected_printer_changed (selection, dialog);
+
+  if (gtk_print_backend_printer_list_is_done (backend) &&
+      gtk_printer_is_default (printer) &&
+      (gtk_tree_selection_count_selected_rows (selection) == 0))
+    set_active_printer (dialog, gtk_printer_get_name (printer));
 }
 
 static void
@@ -407,6 +662,7 @@ printer_added_cb (GtkPrintBackend    *backend,
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
   GtkTreeIter iter, filter_iter;
   GtkTreeSelection *selection;
+  GtkTreePath *path;
 
   gtk_list_store_append (GTK_LIST_STORE (priv->printer_list), &iter);
   
@@ -426,7 +682,8 @@ printer_added_cb (GtkPrintBackend    *backend,
 
   gtk_tree_model_filter_convert_child_iter_to_iter (priv->printer_list_filter,
                                                    &filter_iter, &iter);
-  
+  path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->printer_list_filter), &filter_iter);
+
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
   
   if (priv->waiting_for_printer != NULL &&
@@ -435,6 +692,8 @@ printer_added_cb (GtkPrintBackend    *backend,
     {
       priv->internal_printer_change = TRUE;
       gtk_tree_selection_select_iter (selection, &filter_iter);
+      gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
+                                    path, NULL, TRUE, 0.5, 0.0);
       priv->internal_printer_change = FALSE;
       g_free (priv->waiting_for_printer);
       priv->waiting_for_printer = NULL;
@@ -444,8 +703,12 @@ printer_added_cb (GtkPrintBackend    *backend,
     {
       priv->internal_printer_change = TRUE;
       gtk_tree_selection_select_iter (selection, &filter_iter);
+      gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->printer_treeview),
+                                    path, NULL, TRUE, 0.5, 0.0);
       priv->internal_printer_change = FALSE;
     }
+
+  gtk_tree_path_free (path);
 }
 
 static void
@@ -541,7 +804,7 @@ gtk_print_unix_dialog_get_property (GObject    *object,
       g_value_set_int (value, priv->current_page);
       break;
     case PROP_PRINT_SETTINGS:
-      g_value_set_object (value, gtk_print_unix_dialog_get_settings (dialog));
+      g_value_take_object (value, gtk_print_unix_dialog_get_settings (dialog));
       break;
     case PROP_SELECTED_PRINTER:
       g_value_set_object (value, priv->current_printer);
@@ -559,6 +822,7 @@ is_printer_active (GtkTreeModel       *model,
 {
   gboolean result;
   GtkPrinter *printer;
+  GtkPrintUnixDialogPrivate *priv = dialog->priv;
 
   gtk_tree_model_get (model,
                      iter,
@@ -570,9 +834,22 @@ is_printer_active (GtkTreeModel       *model,
     return FALSE;
 
   result = gtk_printer_is_active (printer);
-
+  
+  if (result && 
+      priv->manual_capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF |
+                                  GTK_PRINT_CAPABILITY_GENERATE_PS))
+    {
+       /* Check that the printer can handle at least one of the data 
+       * formats that the application supports.
+        */
+       result = ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF) &&
+                gtk_printer_accepts_pdf (printer)) ||
+               ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS) &&
+                gtk_printer_accepts_ps (printer));
+    }
+  
   g_object_unref (printer);
-
+  
   return result;
 }
 
@@ -669,9 +946,9 @@ wrap_in_frame (const gchar *label,
                GtkWidget   *child)
 {
   GtkWidget *frame, *alignment, *label_widget;
-  char *bold_text;
+  gchar *bold_text;
 
-  label_widget = gtk_label_new ("");
+  label_widget = gtk_label_new (NULL);
   gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
   gtk_widget_show (label_widget);
   
@@ -711,40 +988,32 @@ setup_option (GtkPrintUnixDialog     *dialog,
 
 static void
 add_option_to_extension_point (GtkPrinterOption *option,
-                              gpointer          user_data)
+                              gpointer          data)
 {
-  GHashTable *extension_points = (GHashTable *) user_data;
-  GtkWidget *widget, *extension_hbox;
-
-  extension_hbox = g_hash_table_lookup (extension_points, option->name);
-
-  if (extension_hbox)
-    {
+  GtkWidget *extension_point = data;
+  GtkWidget *widget;
 
-      widget = gtk_printer_option_widget_new (option);
-      gtk_widget_show (widget);
+  widget = gtk_printer_option_widget_new (option);
+  gtk_widget_show (widget);
    
-      if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
-        {
-          GtkWidget *label, *hbox;
-
-          label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
-          gtk_widget_show (label);
-          gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-          gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
-
-          hbox = gtk_hbox_new (FALSE, 12);
-          gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-          gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
-          gtk_widget_show (hbox);
-
-          gtk_box_pack_start (GTK_BOX (extension_hbox), hbox, FALSE, FALSE, 0);
-        }
-      else
-        gtk_box_pack_start (GTK_BOX (extension_hbox), widget, FALSE, FALSE, 0);
+  if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
+    {
+      GtkWidget *label, *hbox;
+      
+      label = gtk_printer_option_widget_get_external_label (GTK_PRINTER_OPTION_WIDGET (widget));
+      gtk_widget_show (label);
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
+      
+      hbox = gtk_hbox_new (FALSE, 12);
+      gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+      gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
+      gtk_widget_show (hbox);
+      
+      gtk_box_pack_start (GTK_BOX (extension_point), hbox, FALSE, FALSE, 0);
     }
   else
-    g_warning ("Extension point %s requested but not found.", option->name);
+    gtk_box_pack_start (GTK_BOX (extension_point), widget, FALSE, FALSE, 0);
 }
 
 static void
@@ -753,7 +1022,7 @@ add_option_to_table (GtkPrinterOption *option,
 {
   GtkTable *table;
   GtkWidget *label, *widget;
-  int row;
+  gint row;
 
   table = GTK_TABLE (user_data);
   
@@ -764,7 +1033,7 @@ add_option_to_table (GtkPrinterOption *option,
   gtk_widget_show (widget);
 
   row = table->nrows;
-  gtk_table_resize (table, table->nrows + 1, table->ncols + 1);
+  gtk_table_resize (table, table->nrows + 1, 2);
   
   if (gtk_printer_option_widget_has_external_label (GTK_PRINTER_OPTION_WIDGET (widget)))
     {
@@ -894,7 +1163,7 @@ update_dialog_from_settings (GtkPrintUnixDialog *dialog)
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
   GList *groups, *l;
-  char *group;
+  gchar *group;
   GtkWidget *table, *frame;
   gboolean has_advanced, has_job;
  
@@ -912,6 +1181,7 @@ update_dialog_from_settings (GtkPrintUnixDialog *dialog)
     }
  
   setup_option (dialog, "gtk-n-up", priv->pages_per_sheet);
+  setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
   setup_option (dialog, "gtk-duplex", priv->duplex);
   setup_option (dialog, "gtk-paper-type", priv->paper_type);
   setup_option (dialog, "gtk-paper-source", priv->paper_source);
@@ -945,6 +1215,11 @@ update_dialog_from_settings (GtkPrintUnixDialog *dialog)
                    priv->color_table,
                    priv->color_page);
 
+  gtk_printer_option_set_foreach_in_group (priv->options,
+                                          "GtkPrintDialogExtension",
+                                          add_option_to_extension_point,
+                                          priv->extension_point);
+
   /* Put the rest of the groups in the advanced page */
   groups = gtk_printer_option_set_get_groups (priv->options);
 
@@ -958,18 +1233,10 @@ update_dialog_from_settings (GtkPrintUnixDialog *dialog)
       
       if (strcmp (group, "ImageQualityPage") == 0 ||
          strcmp (group, "ColorPage") == 0 ||
-         strcmp (group, "FinishingPage") == 0)
+         strcmp (group, "FinishingPage") == 0 ||
+         strcmp (group, "GtkPrintDialogExtension") == 0)
        continue;
 
-      if (strcmp (group, "GtkPrintDialogExtention") == 0)
-        {
-          gtk_printer_option_set_foreach_in_group (priv->options,
-                                                  group,
-                                                  add_option_to_extension_point,
-                                                  priv->extension_points);
-          continue;
-        }
-
       table = gtk_table_new (1, 2, FALSE);
       gtk_table_set_row_spacings (GTK_TABLE (table), 6);
       gtk_table_set_col_spacings (GTK_TABLE (table), 12);
@@ -1002,6 +1269,43 @@ update_dialog_from_settings (GtkPrintUnixDialog *dialog)
   g_list_free (groups);
 }
 
+static void
+update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
+{
+  GtkPrintCapabilities caps;
+  GtkPrintUnixDialogPrivate *priv = dialog->priv;
+  gboolean can_collate;
+  const gchar *copies;
+
+  copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin));
+  can_collate = (*copies != '\0' && atoi (copies) > 1);
+
+  caps = priv->manual_capabilities | priv->printer_capabilities;
+
+  gtk_widget_set_sensitive (priv->page_set_combo,
+                           caps & GTK_PRINT_CAPABILITY_PAGE_SET);
+  gtk_widget_set_sensitive (priv->copies_spin,
+                           caps & GTK_PRINT_CAPABILITY_COPIES);
+  gtk_widget_set_sensitive (priv->collate_check,
+                           can_collate && 
+                           (caps & GTK_PRINT_CAPABILITY_COLLATE));
+  gtk_widget_set_sensitive (priv->reverse_check,
+                           caps & GTK_PRINT_CAPABILITY_REVERSE);
+  gtk_widget_set_sensitive (priv->scale_spin,
+                           caps & GTK_PRINT_CAPABILITY_SCALE);
+  gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet),
+                           caps & GTK_PRINT_CAPABILITY_NUMBER_UP);
+
+  if (caps & GTK_PRINT_CAPABILITY_PREVIEW)
+    gtk_widget_show (priv->preview_button);
+  else
+    gtk_widget_hide (priv->preview_button);
+
+  update_collate_icon (NULL, dialog);
+
+  gtk_tree_model_filter_refilter (priv->printer_list_filter);
+}
+
 static void
 mark_conflicts (GtkPrintUnixDialog *dialog)
 {
@@ -1067,8 +1371,8 @@ schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
   if (priv->mark_conflicts_id != 0)
     return;
 
-  priv->mark_conflicts_id = g_idle_add (mark_conflicts_callback,
-                                               dialog);
+  priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
+                                       dialog);
 }
 
 static void
@@ -1096,9 +1400,7 @@ remove_custom_widget (GtkWidget    *widget,
 }
 
 static void
-extension_point_clear_children (const gchar  *key,
-                                GtkContainer *container,
-                                gpointer      data)
+extension_point_clear_children (GtkContainer *container)
 {
   gtk_container_foreach (container,
                          (GtkCallback)remove_custom_widget,
@@ -1125,9 +1427,7 @@ clear_per_printer_ui (GtkPrintUnixDialog *dialog)
   gtk_container_foreach (GTK_CONTAINER (priv->advanced_vbox),
                         (GtkCallback)gtk_widget_destroy,
                         NULL);
-  g_hash_table_foreach (priv->extension_points, 
-                        (GHFunc) extension_point_clear_children, 
-                        NULL);
+  extension_point_clear_children (GTK_CONTAINER (priv->extension_point));
 }
 
 static void
@@ -1137,7 +1437,7 @@ printer_details_acquired (GtkPrinter         *printer,
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
 
-  priv->request_details_tag = 0;
+  disconnect_printer_details_request (dialog);
   
   if (success)
     {
@@ -1164,13 +1464,9 @@ selected_printer_changed (GtkTreeSelection   *selection,
       g_free (priv->waiting_for_printer);
       priv->waiting_for_printer = NULL;
     }
-  
-  if (priv->request_details_tag)
-    {
-      g_source_remove (priv->request_details_tag);
-      priv->request_details_tag = 0;
-    }
-  
+
+  disconnect_printer_details_request (dialog);
+
   printer = NULL;
   if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter))
     {
@@ -1182,15 +1478,31 @@ selected_printer_changed (GtkTreeSelection   *selection,
                          PRINTER_LIST_COL_PRINTER_OBJ, &printer,
                          -1);
     }
+
+  /* sets GTK_RESPONSE_OK button sensitive/insensitive depending on whether the printer 
+   * accepts/rejects jobs */
+  if (printer != NULL)
+    {
+      if (!gtk_printer_is_accepting_jobs (printer))
+        {
+          gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
+        }
+      else
+        {
+          if (priv->current_printer == printer && gtk_printer_has_details (printer))
+            gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
+        }
+    }
   
-  if (printer != NULL && !_gtk_printer_has_details (printer))
+  if (printer != NULL && !gtk_printer_has_details (printer))
     {
       gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
       priv->request_details_tag =
        g_signal_connect (printer, "details-acquired",
                          G_CALLBACK (printer_details_acquired), dialog);
-      _gtk_printer_request_details (printer);
-      g_object_unref (printer);
+      /* take the reference */
+      priv->request_details_printer = printer;
+      gtk_printer_request_details (printer);
       return;
     }
   
@@ -1214,20 +1526,42 @@ selected_printer_changed (GtkTreeSelection   *selection,
       g_object_unref (priv->current_printer);
     }
 
-  gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
+  priv->printer_capabilities = 0;
+  
+  if (gtk_printer_is_accepting_jobs (printer))
+    gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
   priv->current_printer = printer;
 
   if (printer != NULL)
     {
-      priv->options = _gtk_printer_get_options (printer, priv->initial_settings,
-                                                       priv->page_setup);
+      if (!priv->page_setup_set)
+       {
+         /* if no explicit page setup has been set, use the printer default */   
+         GtkPageSetup *page_setup;
+
+         page_setup = gtk_printer_get_default_page_size (printer);
+
+         if (!page_setup)
+           page_setup = gtk_page_setup_new ();
+
+         g_object_unref (priv->page_setup);
+         priv->page_setup = page_setup;
+       }
+
+      priv->printer_capabilities = gtk_printer_get_capabilities (printer);
+      priv->options = _gtk_printer_get_options (printer, 
+                                               priv->initial_settings,
+                                               priv->page_setup,
+                                               priv->manual_capabilities);
   
       priv->options_changed_handler = 
         g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
     }
 
   update_dialog_from_settings (dialog);
+  update_dialog_from_capabilities (dialog);
 }
+
 static void
 update_collate_icon (GtkToggleButton    *toggle_button,
                     GtkPrintUnixDialog *dialog)
@@ -1243,16 +1577,20 @@ paint_page (GtkWidget *widget,
            gfloat     scale,
            gint       x_offset, 
            gint       y_offset,
-           gchar     *text)
+           gchar     *text,
+           gint       text_x)
 {
   gint x, y, width, height;
-  gint linewidth = 2;
+  gint text_y, linewidth;
 
   x = x_offset * scale;
   y = y_offset * scale;
   width = 20 * scale;
   height = 26 * scale;
 
+  linewidth = 2;
+  text_y = 21;
+
   gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
   cairo_rectangle (cr, x, y, width, height);
   cairo_fill (cr);
@@ -1266,7 +1604,7 @@ paint_page (GtkWidget *widget,
                          CAIRO_FONT_SLANT_NORMAL,
                          CAIRO_FONT_WEIGHT_NORMAL);
   cairo_set_font_size (cr, (gint)(9 * scale));
-  cairo_move_to (cr, x + (gint)(11 * scale), y + (gint)(21 * scale));
+  cairo_move_to (cr, x + (gint)(text_x * scale), y + (gint)(text_y * scale));
   cairo_show_text (cr, text);
 }
 
@@ -1276,15 +1614,19 @@ draw_collate_cb (GtkWidget          *widget,
                 GdkEventExpose     *event,
                 GtkPrintUnixDialog *dialog)
 {
-  GtkPrintUnixDialogPrivate *priv = dialog->priv;
   GtkSettings *settings;
   cairo_t *cr;
   gint size;
   gfloat scale;
-  gboolean collate, reverse;
+  gboolean collate, reverse, rtl;
+  gint copies;
+  gint text_x;
 
-  collate = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->collate_check));
-  reverse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->reverse_check));
+  collate = dialog_get_collate (dialog);
+  reverse = dialog_get_reverse (dialog);
+  copies = dialog_get_n_copies (dialog);
+
+  rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL);
 
   settings = gtk_widget_get_settings (widget);
   gtk_icon_size_lookup_for_settings (settings,
@@ -1292,15 +1634,26 @@ draw_collate_cb (GtkWidget          *widget,
                                     &size,
                                     NULL);
   scale = size / 48.0;
+  text_x = rtl ? 4 : 11;
 
   cr = gdk_cairo_create (widget->window);
 
-  paint_page (widget, cr, scale, 15, 5, collate == reverse ? "1" : "2");
-  paint_page (widget, cr, scale, 5, 15, reverse ? "2" : "1");
+  cairo_translate (cr, widget->allocation.x, widget->allocation.y);
+
+  if (copies == 1)
+    {
+      paint_page (widget, cr, scale, rtl ? 40: 15, 5, reverse ? "1" : "2", text_x);
+      paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
+    }
+  else
+    {
+      paint_page (widget, cr, scale, rtl ? 40: 15, 5, collate == reverse ? "1" : "2", text_x);
+      paint_page (widget, cr, scale, rtl ? 50: 5, 15, reverse ? "2" : "1", text_x);
+
+      paint_page (widget, cr, scale, rtl ? 5 : 50, 5, reverse ? "1" : "2", text_x);
+      paint_page (widget, cr, scale, rtl ? 15 : 40, 15, collate == reverse ? "2" : "1", text_x);
+    }
 
-  paint_page (widget, cr, scale, 50, 5, reverse ? "1" : "2");
-  paint_page (widget, cr, scale, 40, 15, collate == reverse ? "2" : "1");
-  
   cairo_destroy (cr);
 
   return TRUE;
@@ -1310,8 +1663,7 @@ static void
 gtk_print_unix_dialog_style_set (GtkWidget *widget,
                                 GtkStyle  *previous_style)
 {
-  if (GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_set)
-    GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_set (widget, previous_style);
+  GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_set (widget, previous_style);
 
   if (gtk_widget_has_screen (widget))
     {
@@ -1334,6 +1686,17 @@ gtk_print_unix_dialog_style_set (GtkWidget *widget,
     }
 }
 
+static void
+update_range_sensitivity (GtkWidget *button,
+                         GtkWidget *range)
+{
+  gboolean active;
+
+  active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+  gtk_widget_set_sensitive (range, active);
+}
+
 static void
 create_main_page (GtkPrintUnixDialog *dialog)
 {
@@ -1379,6 +1742,7 @@ create_main_page (GtkPrintUnixDialog *dialog)
                                                     "icon-name",
                                                     PRINTER_LIST_COL_ICON,
                                                     NULL);
+  gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
   gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
 
   renderer = gtk_cell_renderer_text_new ();
@@ -1387,23 +1751,28 @@ create_main_page (GtkPrintUnixDialog *dialog)
                                                     "text",
                                                     PRINTER_LIST_COL_NAME,
                                                     NULL);
+  gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
   gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
   
   renderer = gtk_cell_renderer_text_new ();
+  /* Translators: this is the header for the location column in the print dialog */
   column = gtk_tree_view_column_new_with_attributes (_("Location"),
                                                     renderer,
                                                     "text",
                                                     PRINTER_LIST_COL_LOCATION,
                                                     NULL);
+  gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
   gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
 
   renderer = gtk_cell_renderer_text_new ();
   g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  /* Translators: this is the header for the printer status column in the print dialog */
   column = gtk_tree_view_column_new_with_attributes (_("Status"),
                                                     renderer,
                                                     "text",
                                                     PRINTER_LIST_COL_STATE,
                                                     NULL);
+  gtk_tree_view_column_set_cell_data_func (column, renderer, set_cell_sensitivity_func, NULL, NULL);
   gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
   
   gtk_widget_show (treeview);
@@ -1412,9 +1781,7 @@ create_main_page (GtkPrintUnixDialog *dialog)
   custom_input = gtk_hbox_new (FALSE, 18);
   gtk_widget_show (custom_input);
   gtk_box_pack_start (GTK_BOX (vbox), custom_input, FALSE, FALSE, 0);
-  g_hash_table_insert (priv->extension_points, 
-                       _EXTENTION_POINT_MAIN_PAGE_CUSTOM_INPUT,
-                       custom_input);
+  priv->extension_point = custom_input;
 
   hbox = gtk_hbox_new (FALSE, 18);
   gtk_widget_show (hbox);
@@ -1423,18 +1790,18 @@ create_main_page (GtkPrintUnixDialog *dialog)
   table = gtk_table_new (3, 2, FALSE);
   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
   gtk_table_set_col_spacings (GTK_TABLE (table), 12);
-  frame = wrap_in_frame (_("Print Pages"), table);
+  frame = wrap_in_frame (_("Range"), table);
   gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
   gtk_widget_show (table);
 
-  radio = gtk_radio_button_new_with_mnemonic (NULL, _("_All"));
+  radio = gtk_radio_button_new_with_mnemonic (NULL, _("_All Pages"));
   priv->all_pages_radio = radio;
   gtk_widget_show (radio);
   gtk_table_attach (GTK_TABLE (table), radio,
                    0, 2, 0, 1,  GTK_FILL, 0,
                    0, 0);
   radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
-                                             _("C_urrent"));
+                                             _("C_urrent Page"));
   if (priv->current_page == -1)
     gtk_widget_set_sensitive (radio, FALSE);    
   priv->current_page_radio = radio;
@@ -1442,8 +1809,10 @@ create_main_page (GtkPrintUnixDialog *dialog)
   gtk_table_attach (GTK_TABLE (table), radio,
                    0, 2, 1, 2,  GTK_FILL, 0,
                    0, 0);
-  radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
-                                             _("Ra_nge: "));
+  radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)), _("Pag_es:"));
+  gtk_widget_set_tooltip_text (radio, _("Specify one or more page ranges,\n e.g. 1-3,7,11"));
   priv->page_range_radio = radio;
   gtk_widget_show (radio);
   gtk_table_attach (GTK_TABLE (table), radio,
@@ -1455,6 +1824,8 @@ create_main_page (GtkPrintUnixDialog *dialog)
   gtk_table_attach (GTK_TABLE (table), entry,
                    1, 2, 2, 3,  GTK_FILL, 0,
                    0, 0);
+  g_signal_connect (radio, "toggled", G_CALLBACK (update_range_sensitivity), entry);
+  update_range_sensitivity (radio, entry);
 
   table = gtk_table_new (3, 2, FALSE);
   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
@@ -1463,7 +1834,7 @@ create_main_page (GtkPrintUnixDialog *dialog)
   gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
   gtk_widget_show (table);
 
-  /* FIXMEchpe: too much space between Copies and spinbutton, put those 2 in a hbox and make it span 2 columns */
+  /* FIXME chpe: too much space between Copies and spinbutton, put those 2 in a hbox and make it span 2 columns */
   label = gtk_label_new_with_mnemonic (_("Copie_s:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
@@ -1477,7 +1848,11 @@ create_main_page (GtkPrintUnixDialog *dialog)
                    1, 2, 0, 1,  GTK_FILL, 0,
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
-
+  g_signal_connect_swapped (spinbutton, "value-changed", 
+                           G_CALLBACK (update_dialog_from_capabilities), dialog);
+  g_signal_connect_swapped (spinbutton, "changed", 
+                           G_CALLBACK (update_dialog_from_capabilities), dialog);
+  
   check = gtk_check_button_new_with_mnemonic (_("C_ollate"));
   priv->collate_check = check;
   g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
@@ -1485,6 +1860,7 @@ create_main_page (GtkPrintUnixDialog *dialog)
   gtk_table_attach (GTK_TABLE (table), check,
                    0, 1, 1, 2,  GTK_FILL, 0,
                    0, 0);
+
   check = gtk_check_button_new_with_mnemonic (_("_Reverse"));
   g_signal_connect (check, "toggled", G_CALLBACK (update_collate_icon), dialog);
   priv->reverse_check = check;
@@ -1494,19 +1870,21 @@ create_main_page (GtkPrintUnixDialog *dialog)
                    0, 0);
 
   image = gtk_drawing_area_new ();
+  GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
+
   priv->collate_image = image;
   gtk_widget_show (image);
   gtk_widget_set_size_request (image, 70, 90);
   gtk_table_attach (GTK_TABLE (table), image,
                    1, 2, 1, 3, GTK_FILL, 0,
                    0, 0);
-  g_signal_connect (image, "expose_event", G_CALLBACK (draw_collate_cb), dialog);
+  g_signal_connect (image, "expose-event",
+                    G_CALLBACK (draw_collate_cb), dialog);
 
   label = gtk_label_new (_("General"));
   gtk_widget_show (label);
   
-  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
-                           main_vbox, label);
+  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), main_vbox, label);
 }
 
 static gboolean
@@ -1520,11 +1898,11 @@ dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
                        gint               *n_ranges_out)
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
-  int i, n_ranges;
-  const char *text, *p;
-  char *next;
+  gint i, n_ranges;
+  const gchar *text, *p;
+  gchar *next;
   GtkPageRange *ranges;
-  int start, end;
+  gint start, end;
   
   text = gtk_entry_get_text (GTK_ENTRY (priv->page_range_entry));
 
@@ -1549,22 +1927,33 @@ dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
   p = text;
   while (*p)
     {
-      start = (int)strtol (p, &next, 10);
-      if (start < 1)
-       start = 1;
+      while (isspace (*p)) p++;
+
+      if (*p == '-')
+        {
+          /* a half-open range like -2 */
+          start = 1;
+        }
+      else
+        {
+          start = (int)strtol (p, &next, 10);
+          if (start < 1)
+           start = 1;
+          p = next;
+        }
+      
       end = start;
 
-      if (next != p)
-       {
-         p = next;
+      while (isspace (*p)) p++;
 
-         if (*p == '-')
-           {
-             p++;
-             end = (int)strtol (p, NULL, 10);
-             if (end < start)
-               end = start;
-           }
+      if (*p == '-')
+       {
+         p++;
+         end = (int)strtol (p, &next, 10);
+          if (next == p) /* a half-open range like 2- */
+            end = 0;
+         else if (end < start)
+           end = start;
        }
 
       ranges[i].start = start - 1;
@@ -1591,21 +1980,22 @@ dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
                        gint                n_ranges)
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
-  int i;
-  GString *s = g_string_new ("");
+  gint i;
+  GString *s = g_string_new (NULL);
 
   for (i = 0; i < n_ranges; i++)
     {
       g_string_append_printf (s, "%d", ranges[i].start + 1);
       if (ranges[i].end > ranges[i].start)
        g_string_append_printf (s, "-%d", ranges[i].end + 1);
+      else if (ranges[i].end == -1)
+        g_string_append (s, "-");
       
       if (i != n_ranges - 1)
        g_string_append (s, ",");
     }
 
-  gtk_entry_set_text (GTK_ENTRY (priv->page_range_entry),
-                     s->str);
+  gtk_entry_set_text (GTK_ENTRY (priv->page_range_entry), s->str);
   
   g_string_free (s, TRUE);
 }
@@ -1625,7 +2015,8 @@ dialog_get_print_pages (GtkPrintUnixDialog *dialog)
 }
 
 static void
-dialog_set_print_pages (GtkPrintUnixDialog *dialog, GtkPrintPages pages)
+dialog_set_print_pages (GtkPrintUnixDialog *dialog, 
+                       GtkPrintPages       pages)
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
 
@@ -1640,21 +2031,26 @@ dialog_set_print_pages (GtkPrintUnixDialog *dialog, GtkPrintPages pages)
 static gdouble
 dialog_get_scale (GtkPrintUnixDialog *dialog)
 {
-  return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
+  if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->scale_spin))
+    return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin));
+  else
+    return 100.0;
 }
 
 static void
 dialog_set_scale (GtkPrintUnixDialog *dialog, 
                   gdouble             val)
 {
-  return gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin),
-                                   val);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin), val);
 }
 
 static GtkPageSet
 dialog_get_page_set (GtkPrintUnixDialog *dialog)
 {
-  return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
+  if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->page_set_combo))
+    return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo));
+  else
+    return GTK_PAGE_SET_ALL;
 }
 
 static void
@@ -1668,7 +2064,9 @@ dialog_set_page_set (GtkPrintUnixDialog *dialog,
 static gint
 dialog_get_n_copies (GtkPrintUnixDialog *dialog)
 {
-  return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
+  if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->copies_spin))
+    return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin));
+  return 1;
 }
 
 static void
@@ -1682,7 +2080,9 @@ dialog_set_n_copies (GtkPrintUnixDialog *dialog,
 static gboolean
 dialog_get_collate (GtkPrintUnixDialog *dialog)
 {
-  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
+  if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->collate_check))
+    return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check));
+  return FALSE;
 }
 
 static void
@@ -1696,7 +2096,9 @@ dialog_set_collate (GtkPrintUnixDialog *dialog,
 static gboolean
 dialog_get_reverse (GtkPrintUnixDialog *dialog)
 {
-  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
+  if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->reverse_check))
+    return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check));
+  return FALSE;
 }
 
 static void
@@ -1711,8 +2113,8 @@ static gint
 dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
-  const char *val;
-  int num;
+  const gchar *val;
+  gint num;
 
   val = gtk_printer_option_widget_get_value (priv->pages_per_sheet);
 
@@ -1728,6 +2130,39 @@ dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
   return num;
 }
 
+static GtkNumberUpLayout
+dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
+{
+  GtkPrintUnixDialogPrivate *priv = dialog->priv;
+  GtkPrintCapabilities       caps;
+  GtkNumberUpLayout          layout;
+  const gchar               *val;
+  GEnumClass                *enum_class;
+  GEnumValue                *enum_value;
+
+  val = gtk_printer_option_widget_get_value (priv->number_up_layout);
+
+  caps = priv->manual_capabilities | priv->printer_capabilities;
+
+  if ((caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) == 0)
+    return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
+
+  if (gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR)
+    layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
+  else
+    layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
+
+  if (val == NULL)
+    return layout;
+
+  enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
+  enum_value = g_enum_get_value_by_nick (enum_class, val);
+  if (enum_value)
+    layout = enum_value->value;
+  g_type_class_unref (enum_class);
+
+  return layout;
+}
 
 static gboolean
 draw_page_cb (GtkWidget                 *widget,
@@ -1736,23 +2171,32 @@ draw_page_cb (GtkWidget          *widget,
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
   cairo_t *cr;
-  double ratio;
-  int w, h, tmp, shadow_offset;
-  int pages_x, pages_y, i, x, y, layout_w, layout_h;
-  double page_width, page_height;
+  gdouble ratio;
+  gint w, h, tmp, shadow_offset;
+  gint pages_x, pages_y, i, x, y, layout_w, layout_h;
+  gdouble page_width, page_height;
   GtkPageOrientation orientation;
   gboolean landscape;
   PangoLayout *layout;
   PangoFontDescription *font;
-  char *text;
+  gchar *text;
+  GdkColor *color;
+  GtkNumberUpLayout number_up_layout;
+  gint start_x, end_x, start_y, end_y;
+  gint dx, dy;
+  gboolean horizontal;
   
   orientation = gtk_page_setup_get_orientation (priv->page_setup);
   landscape =
     (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
     (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
-  
+
+  number_up_layout = dialog_get_number_up_layout (dialog);
+
   cr = gdk_cairo_create (widget->window);
   
+  cairo_translate (cr, widget->allocation.x, widget->allocation.y);
+
   ratio = G_SQRT2;
 
   w = (EXAMPLE_PAGE_AREA_SIZE - 3) / ratio;
@@ -1796,17 +2240,18 @@ draw_page_cb (GtkWidget          *widget,
   
   shadow_offset = 3;
   
-  cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
+  color = &widget->style->text[GTK_STATE_NORMAL];
+  cairo_set_source_rgba (cr, color->red / 65535., color->green / 65535., color->blue / 65535, 0.5);
   cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
   cairo_fill (cr);
   
-  cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+  gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
   cairo_rectangle (cr, 1, 1, w, h);
   cairo_fill (cr);
   cairo_set_line_width (cr, 1.0);
   cairo_rectangle (cr, 0.5, 0.5, w+1, h+1);
   
-  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+  gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_NORMAL]);
   cairo_stroke (cr);
 
   i = 1;
@@ -1825,25 +2270,121 @@ draw_page_cb (GtkWidget                 *widget,
   pango_layout_set_width (layout, page_width * PANGO_SCALE);
   pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
   
-  for (y = 0; y < pages_y; y++)
+  switch (number_up_layout)
     {
-      for (x = 0; x < pages_x; x++)
-       {
-         text = g_strdup_printf ("%d", i++);
-         pango_layout_set_text (layout, text, -1);
-         g_free (text);
-         pango_layout_get_size (layout, &layout_w, &layout_h);
-         cairo_save (cr);
-         cairo_translate (cr,
-                          x * page_width,
-                          y * page_height + (page_height - layout_h / 1024.0) / 2
-                          );
-         
-         pango_cairo_show_layout (cr, layout);
-         cairo_restore (cr);
-       }
+      default:
+      case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
+        start_x = 0;
+        end_x = pages_x - 1;
+        start_y = 0;
+        end_y = pages_y - 1;
+        dx = 1;
+        dy = 1;
+        horizontal = TRUE;
+        break;
+      case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
+        start_x = 0;
+        end_x = pages_x - 1;
+        start_y = pages_y - 1;
+        end_y = 0;
+        dx = 1;
+        dy = - 1;
+        horizontal = TRUE;
+        break;
+      case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
+        start_x = pages_x - 1;
+        end_x = 0;
+        start_y = 0;
+        end_y = pages_y - 1;
+        dx = - 1;
+        dy = 1;
+        horizontal = TRUE;
+        break;
+      case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
+        start_x = pages_x - 1;
+        end_x = 0;
+        start_y = pages_y - 1;
+        end_y = 0;
+        dx = - 1;
+        dy = - 1;
+        horizontal = TRUE;
+        break;
+      case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
+        start_x = 0;
+        end_x = pages_x - 1;
+        start_y = 0;
+        end_y = pages_y - 1;
+        dx = 1;
+        dy = 1;
+        horizontal = FALSE;
+        break;
+      case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
+        start_x = pages_x - 1;
+        end_x = 0;
+        start_y = 0;
+        end_y = pages_y - 1;
+        dx = - 1;
+        dy = 1;
+        horizontal = FALSE;
+        break;
+      case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
+        start_x = 0;
+        end_x = pages_x - 1;
+        start_y = pages_y - 1;
+        end_y = 0;
+        dx = 1;
+        dy = - 1;
+        horizontal = FALSE;
+        break;
+      case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
+        start_x = pages_x - 1;
+        end_x = 0;
+        start_y = pages_y - 1;
+        end_y = 0;
+        dx = - 1;
+        dy = - 1;
+        horizontal = FALSE;
+        break;
     }
-    
+
+  if (horizontal)
+    for (y = start_y; y != end_y + dy; y += dy)
+      {
+        for (x = start_x; x != end_x + dx; x += dx)
+          {
+            text = g_strdup_printf ("%d", i++);
+            pango_layout_set_text (layout, text, -1);
+            g_free (text);
+            pango_layout_get_size (layout, &layout_w, &layout_h);
+            cairo_save (cr);
+            cairo_translate (cr,
+                             x * page_width,
+                             y * page_height + (page_height - layout_h / 1024.0) / 2);
+
+            pango_cairo_show_layout (cr, layout);
+            cairo_restore (cr);
+          }
+      }
+  else
+    for (x = start_x; x != end_x + dx; x += dx)
+      {
+        for (y = start_y; y != end_y + dy; y += dy)
+          {
+            text = g_strdup_printf ("%d", i++);
+            pango_layout_set_text (layout, text, -1);
+            g_free (text);
+            pango_layout_get_size (layout, &layout_w, &layout_h);
+            cairo_save (cr);
+            cairo_translate (cr,
+                             x * page_width,
+                             y * page_height + (page_height - layout_h / 1024.0) / 2);
+
+            pango_cairo_show_layout (cr, layout);
+            cairo_restore (cr);
+          }
+      }
+  
+  g_object_unref (layout);
   cairo_destroy (cr);
 
   return TRUE;
@@ -1858,6 +2399,85 @@ redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
     gtk_widget_queue_draw (priv->page_layout_preview);
 }
 
+static void
+update_number_up_layout (GtkPrintUnixDialog *dialog)
+{
+  GtkPrintUnixDialogPrivate *priv = dialog->priv;
+  GtkPrintCapabilities       caps;
+  GtkPrinterOptionSet       *set;
+  GtkNumberUpLayout          layout;
+  GtkPrinterOption          *option;
+  GtkPrinterOption          *old_option;
+
+  set = priv->options;
+
+  caps = priv->manual_capabilities | priv->printer_capabilities;
+
+  if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
+    {
+      if (priv->number_up_layout_n_option == NULL)
+        {
+          priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
+          g_object_ref (priv->number_up_layout_n_option);
+
+          priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
+                                                                    _("Page Ordering"),
+                                                                    GTK_PRINTER_OPTION_TYPE_PICKONE);
+          gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
+
+          priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
+          priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
+          priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
+          priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
+        }
+
+      layout = dialog_get_number_up_layout (dialog);
+
+      old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
+      if (old_option != NULL)
+        gtk_printer_option_set_remove (set, old_option);
+
+      if (dialog_get_pages_per_sheet (dialog) != 1)
+        {
+          GEnumClass *enum_class;
+          GEnumValue *enum_value;
+          enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
+
+          if (dialog_get_pages_per_sheet (dialog) == 2)
+            {
+              option = priv->number_up_layout_2_option;
+
+              if (layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM ||
+                  layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP ||
+                  layout == GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT ||
+                  layout == GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT)
+                enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
+              else
+                enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM);
+            }
+          else
+            {
+              option = priv->number_up_layout_n_option;
+
+              enum_value = g_enum_get_value (enum_class, layout);
+            }
+
+          g_assert (enum_value != NULL);
+          gtk_printer_option_set (option, enum_value->value_nick);
+          g_type_class_unref (enum_class);
+
+          gtk_printer_option_set_add (set, option);
+        }
+    }
+
+  setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
+
+  if (priv->number_up_layout != NULL)
+    gtk_widget_set_sensitive (GTK_WIDGET (priv->number_up_layout),
+                              (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) &&
+                              (dialog_get_pages_per_sheet (dialog) > 1));
+}
+
 static void
 create_page_setup_page (GtkPrintUnixDialog *dialog)
 {
@@ -1881,7 +2501,7 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
   gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
   gtk_widget_show (table);
 
-  label = gtk_label_new_with_mnemonic (_("Pages per _sheet:"));
+  label = gtk_label_new_with_mnemonic (_("T_wo-sided:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
   gtk_table_attach (GTK_TABLE (table), label,
@@ -1889,15 +2509,14 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
                    0, 0);
 
   widget = gtk_printer_option_widget_new (NULL);
-  g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
-  priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
+  priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
   gtk_widget_show (widget);
   gtk_table_attach (GTK_TABLE (table), widget,
                    1, 2, 0, 1,  GTK_FILL, 0,
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
 
-  label = gtk_label_new_with_mnemonic (_("T_wo-sided:"));
+  label = gtk_label_new_with_mnemonic (_("Pages per _side:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
   gtk_table_attach (GTK_TABLE (table), label,
@@ -1905,25 +2524,44 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
                    0, 0);
 
   widget = gtk_printer_option_widget_new (NULL);
-  priv->duplex = GTK_PRINTER_OPTION_WIDGET (widget);
+  g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
+  g_signal_connect_swapped (widget, "changed", G_CALLBACK (update_number_up_layout), dialog);
+  priv->pages_per_sheet = GTK_PRINTER_OPTION_WIDGET (widget);
   gtk_widget_show (widget);
   gtk_table_attach (GTK_TABLE (table), widget,
                    1, 2, 1, 2,  GTK_FILL, 0,
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
 
-  label = gtk_label_new_with_mnemonic (_("_Only Print:"));
+
+  label = gtk_label_new_with_mnemonic (_("Page or_dering:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
   gtk_table_attach (GTK_TABLE (table), label,
                    0, 1, 2, 3,  GTK_FILL, 0,
                    0, 0);
 
+  widget = gtk_printer_option_widget_new (NULL);
+  g_signal_connect_swapped (widget, "changed", G_CALLBACK (redraw_page_layout_preview), dialog);
+  priv->number_up_layout = GTK_PRINTER_OPTION_WIDGET (widget);
+  gtk_widget_show (widget);
+  gtk_table_attach (GTK_TABLE (table), widget,
+                   1, 2, 2, 3,  GTK_FILL, 0,
+                   0, 0);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
+
+  label = gtk_label_new_with_mnemonic (_("_Only print:"));
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label,
+                   0, 1, 3, 4,  GTK_FILL, 0,
+                   0, 0);
+
   combo = gtk_combo_box_new_text ();
   priv->page_set_combo = combo;
   gtk_widget_show (combo);
   gtk_table_attach (GTK_TABLE (table), combo,
-                   1, 2, 2, 3,  GTK_FILL, 0,
+                   1, 2, 3, 4,  GTK_FILL, 0,
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
   /* In enum order */
@@ -1936,13 +2574,13 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
   gtk_table_attach (GTK_TABLE (table), label,
-                   0, 1, 3, 4,  GTK_FILL, 0,
+                   0, 1, 4, 5,  GTK_FILL, 0,
                    0, 0);
 
   hbox2 = gtk_hbox_new (FALSE, 6);
   gtk_widget_show (hbox2);
   gtk_table_attach (GTK_TABLE (table), hbox2,
-                   1, 2, 3, 4,  GTK_FILL, 0,
+                   1, 2, 4, 5,  GTK_FILL, 0,
                    0, 0);
   
   spinbutton = gtk_spin_button_new_with_range (1.0, 1000.0, 1.0);
@@ -1963,7 +2601,7 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
   gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 6);
   gtk_widget_show (table);
 
-  label = gtk_label_new_with_mnemonic (_("Paper _Type:"));
+  label = gtk_label_new_with_mnemonic (_("Paper _type:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
   gtk_table_attach (GTK_TABLE (table), label,
@@ -1978,7 +2616,7 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
 
-  label = gtk_label_new_with_mnemonic (_("Paper _Source:"));
+  label = gtk_label_new_with_mnemonic (_("Paper _source:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
   gtk_table_attach (GTK_TABLE (table), label,
@@ -1993,7 +2631,7 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
 
-  label = gtk_label_new_with_mnemonic (_("Output T_ray:"));
+  label = gtk_label_new_with_mnemonic (_("Output t_ray:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
   gtk_table_attach (GTK_TABLE (table), label,
@@ -2014,9 +2652,10 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
   gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 0);
 
   draw = gtk_drawing_area_new ();
+  GTK_WIDGET_SET_FLAGS (draw, GTK_NO_WINDOW);
   priv->page_layout_preview = draw;
   gtk_widget_set_size_request (draw, 200, 200);
-  g_signal_connect (draw, "expose_event", G_CALLBACK (draw_page_cb), dialog);
+  g_signal_connect (draw, "expose-event", G_CALLBACK (draw_page_cb), dialog);
   gtk_widget_show (draw);
 
   gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 0);
@@ -2089,12 +2728,19 @@ create_job_page (GtkPrintUnixDialog *dialog)
                    0, 0);
   gtk_widget_show (table);
 
+  /* Translators: this is one of the choices for the print at option 
+   * in the print dialog
+   */
   radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Now"));
   priv->print_now_radio = radio;
   gtk_widget_show (radio);
   gtk_table_attach (GTK_TABLE (table), radio,
                    0, 2, 0, 1,  GTK_FILL, 0,
                    0, 0);
+  /* Translators: this is one of the choices for the print at option 
+   * in the print dialog. It also serves as the label for an entry that
+   * allows the user to enter a time.
+   */
   radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
                                              _("A_t:"));
   priv->print_at_radio = radio;
@@ -2110,8 +2756,12 @@ create_job_page (GtkPrintUnixDialog *dialog)
                    1, 2, 1, 2,  GTK_FILL, 0,
                    0, 0);
 
+  /* Translators: this is one of the choices for the print at option 
+   * in the print dialog. It means that the print job will not be
+   * printed until it explicitly gets 'released'.
+   */
   radio = gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)),
-                                             _("On _Hold"));
+                                             _("On _hold"));
   priv->print_hold_radio = radio;
   gtk_widget_show (radio);
   gtk_table_attach (GTK_TABLE (table), radio,
@@ -2136,6 +2786,9 @@ create_job_page (GtkPrintUnixDialog *dialog)
                    0, 0);
   gtk_widget_show (table);
 
+  /* Translators, this is the label used for the option in the print 
+   * dialog that controls the front cover page.
+   */
   label = gtk_label_new_with_mnemonic (_("Be_fore:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
@@ -2151,6 +2804,9 @@ create_job_page (GtkPrintUnixDialog *dialog)
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
 
+  /* Translators, this is the label used for the option in the print 
+   * dialog that controls the back cover page.
+   */
   label = gtk_label_new_with_mnemonic (_("_After:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
@@ -2166,6 +2822,9 @@ create_job_page (GtkPrintUnixDialog *dialog)
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
 
+  /* Translators: this is the tab label for the notebook tab containing
+   * job-specific options in the print dialog
+   */
   label = gtk_label_new (_("Job"));
   gtk_widget_show (label);
 
@@ -2245,7 +2904,7 @@ populate_dialog (GtkPrintUnixDialog *print_dialog)
 {
   GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
   GtkDialog *dialog = GTK_DIALOG (print_dialog);
-  GtkWidget *hbox, *conflict_hbox, *image, *label;
+  GtkWidget *vbox, *conflict_hbox, *image, *label;
 
   gtk_dialog_set_has_separator (dialog, FALSE);
   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
@@ -2253,9 +2912,14 @@ populate_dialog (GtkPrintUnixDialog *print_dialog)
   gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
   gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
 
+  vbox = gtk_vbox_new (FALSE, 6);
+  gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
+  gtk_box_pack_start (GTK_BOX (dialog->vbox), vbox, TRUE, TRUE, 0);
+  gtk_widget_show (vbox);
+
   priv->notebook = gtk_notebook_new ();
-  gtk_container_set_border_width (GTK_CONTAINER (priv->notebook), 5);
-  gtk_box_pack_start (GTK_BOX (dialog->vbox), priv->notebook, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
+  gtk_widget_show (priv->notebook);
 
   create_printer_list_model (print_dialog);
 
@@ -2273,35 +2937,15 @@ populate_dialog (GtkPrintUnixDialog *print_dialog)
                        &priv->finishing_page);
   create_advanced_page (print_dialog);
 
-  hbox = gtk_hbox_new (FALSE, 0);
-  gtk_widget_show (hbox);
-  gtk_box_pack_end (GTK_BOX (dialog->vbox), hbox, FALSE, TRUE, 0);
-  
-  conflict_hbox = gtk_hbox_new (FALSE, 0);
+  priv->conflicts_widget = conflict_hbox = gtk_hbox_new (FALSE, 12);
+  gtk_box_pack_end (GTK_BOX (vbox), conflict_hbox, FALSE, FALSE, 0);
   image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
   gtk_widget_show (image);
   gtk_box_pack_start (GTK_BOX (conflict_hbox), image, FALSE, TRUE, 0);
   label = gtk_label_new (_("Some of the settings in the dialog conflict"));
   gtk_widget_show (label);
   gtk_box_pack_start (GTK_BOX (conflict_hbox), label, FALSE, TRUE, 0);
-  priv->conflicts_widget = conflict_hbox;
-
-  gtk_box_pack_start (GTK_BOX (hbox), conflict_hbox,
-                     FALSE, FALSE, 0);
-
-  /* Reparent the action area into the hbox. This is so we can have the
-   * conflict warning on the same row, but not make the buttons the same
-   * width as the warning (which the buttonbox does).
-   */
-  g_object_ref (dialog->action_area);
-  gtk_container_remove (GTK_CONTAINER (dialog->vbox),
-                       dialog->action_area);
-  gtk_box_pack_end (GTK_BOX (hbox), dialog->action_area,
-                   FALSE, FALSE, 0);
-  g_object_unref (dialog->action_area);
   
-  gtk_widget_show (priv->notebook);
-
   load_print_backends (print_dialog);
 }
 
@@ -2325,15 +2969,13 @@ gtk_print_unix_dialog_new (const gchar *title,
 
   if (title)
     _title = title;
-  
+
   result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
+                        "transient-for", parent,
                          "title", _title,
                         "has-separator", FALSE,
                          NULL);
-
-  if (parent)
-    gtk_window_set_transient_for (GTK_WINDOW (result), parent);
-
+  
   return result;
 }
 
@@ -2380,6 +3022,8 @@ gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
       g_object_unref (priv->page_setup);
       priv->page_setup = g_object_ref (page_setup);
 
+      priv->page_setup_set = TRUE;
+
       g_object_notify (G_OBJECT (dialog), "page-setup");
     }
 }
@@ -2512,9 +3156,9 @@ gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
                                    GtkPrintSettings   *settings)
 {
   GtkPrintUnixDialogPrivate *priv;
-  const char *printer;
+  const gchar *printer;
   GtkPageRange *ranges;
-  int num_ranges;
+  gint num_ranges;
   
   g_return_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog));
   g_return_if_fail (settings == NULL || GTK_IS_PRINT_SETTINGS (settings));
@@ -2525,13 +3169,16 @@ gtk_print_unix_dialog_set_settings (GtkPrintUnixDialog *dialog,
     {
       dialog_set_collate (dialog, gtk_print_settings_get_collate (settings));
       dialog_set_reverse (dialog, gtk_print_settings_get_reverse (settings));
-      dialog_set_n_copies (dialog, gtk_print_settings_get_num_copies (settings));
+      dialog_set_n_copies (dialog, gtk_print_settings_get_n_copies (settings));
       dialog_set_scale (dialog, gtk_print_settings_get_scale (settings));
       dialog_set_page_set (dialog, gtk_print_settings_get_page_set (settings));
       dialog_set_print_pages (dialog, gtk_print_settings_get_print_pages (settings));
       ranges = gtk_print_settings_get_page_ranges (settings, &num_ranges);
       if (ranges)
-       dialog_set_page_ranges (dialog, ranges, num_ranges);
+        {
+         dialog_set_page_ranges (dialog, ranges, num_ranges);
+          g_free (ranges);
+        }
 
       priv->format_for_printer =
        g_strdup (gtk_print_settings_get (settings, "format-for-printer"));
@@ -2578,7 +3225,7 @@ gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
   GtkPrintSettings *settings;
   GtkPrintPages print_pages;
   GtkPageRange *ranges;
-  int n_ranges;
+  gint n_ranges;
 
   g_return_val_if_fail (GTK_IS_PRINT_UNIX_DIALOG (dialog), NULL);
 
@@ -2601,8 +3248,8 @@ gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
   gtk_print_settings_set_reverse (settings,
                                  dialog_get_reverse (dialog));
   
-  gtk_print_settings_set_num_copies (settings,
-                                    dialog_get_n_copies (dialog));
+  gtk_print_settings_set_n_copies (settings,
+                                  dialog_get_n_copies (dialog));
 
   gtk_print_settings_set_scale (settings,
                                dialog_get_scale (dialog));
@@ -2630,6 +3277,63 @@ gtk_print_unix_dialog_get_settings (GtkPrintUnixDialog *dialog)
   return settings;
 }
 
+/**
+ * gtk_print_unix_dialog_add_custom_tab:
+ * @dialog: a #GtkPrintUnixDialog
+ * @child: the widget to put in the custom tab
+ * @tab_label: the widget to use as tab label
+ *
+ * Adds a custom tab to the print dialog.
+ *
+ * Since: 2.10
+ */
+void
+gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
+                                     GtkWidget          *child,
+                                     GtkWidget          *tab_label)
+{
+  gtk_notebook_insert_page (GTK_NOTEBOOK (dialog->priv->notebook),
+                           child, tab_label, 2);
+  gtk_widget_show (child);
+  gtk_widget_show (tab_label);
+}
+
+/**
+ * gtk_print_unix_dialog_set_manual_capabilities:
+ * @dialog: a #GtkPrintUnixDialog
+ * @capabilities: the printing capabilities of your application
+ *
+ * This lets you specify the printing capabilities your application
+ * supports. For instance, if you can handle scaling the output then
+ * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then
+ * the dialog will only let you select the scale if the printing
+ * system automatically handles scaling.
+ *
+ * Since: 2.10
+ */
+void
+gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog   *dialog,
+                                              GtkPrintCapabilities  capabilities)
+{
+  GtkPrintUnixDialogPrivate *priv = dialog->priv;
+
+  priv->manual_capabilities = capabilities;
+  update_dialog_from_capabilities (dialog);
+
+  if (priv->current_printer)
+    {
+      GtkTreeSelection *selection;
+
+      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview));
+
+      g_object_unref (priv->current_printer);
+      priv->current_printer = NULL;
+      priv->internal_printer_change = TRUE;
+      selected_printer_changed (selection, dialog);
+      priv->internal_printer_change = FALSE;
+   }
+}
 
 #define __GTK_PRINT_UNIX_DIALOG_C__
 #include "gtkaliasdef.c"
+