gtk+ r20120 - in trunk: . docs/reference docs/reference/gtk gtk modules/printbackends/cups modules/printbackends/file



Author: matthiasc
Date: Wed May 21 02:17:30 2008
New Revision: 20120
URL: http://svn.gnome.org/viewvc/gtk+?rev=20120&view=rev

Log:
        RH bug 204621 - "GtkPrint" asks for "Letter" size paper when "A4" size
        was chosen

        Patch by Marek Kasik.

        * gtk/gtk.symbols:
        * gtk/gtkprinter.[hc]: Add gtk_printer_get_default_page_size.

        * gtk/gtkprintbackend.[hc]: Add fallback implementation.

        * modules/printbackends/file/gtkprintbackendfile.c:
        * modules/printbackends/cups/gtkprintbackendcups.c: Implement
        get_default_page_size.

        * gtk/gtkpagesetupunixdialog.c: When selecting a different printer,
        select its default paper size.

        * gtk/gtkprintunixdialog.c: If no explicit page setup has been set,
        use the printer default.

        * gtk/gtkprintoperation-unix.c: Don't create an empty page setup
        if we don't have a default page setup.


Modified:
   trunk/ChangeLog
   trunk/docs/reference/ChangeLog
   trunk/docs/reference/gtk/gtk-sections.txt
   trunk/gtk/gtk.symbols
   trunk/gtk/gtkpagesetupunixdialog.c
   trunk/gtk/gtkprintbackend.c
   trunk/gtk/gtkprintbackend.h
   trunk/gtk/gtkprinter.c
   trunk/gtk/gtkprinter.h
   trunk/gtk/gtkprintoperation-unix.c
   trunk/gtk/gtkprintunixdialog.c
   trunk/modules/printbackends/cups/gtkprintbackendcups.c
   trunk/modules/printbackends/file/gtkprintbackendfile.c

Modified: trunk/docs/reference/gtk/gtk-sections.txt
==============================================================================
--- trunk/docs/reference/gtk/gtk-sections.txt	(original)
+++ trunk/docs/reference/gtk/gtk-sections.txt	Wed May 21 02:17:30 2008
@@ -6435,6 +6435,7 @@
 gtk_printer_has_details
 gtk_printer_request_details
 gtk_printer_get_capabilities
+gtk_printer_get_default_page_size
 GtkPrinterFunc
 gtk_enumerate_printers
 

Modified: trunk/gtk/gtk.symbols
==============================================================================
--- trunk/gtk/gtk.symbols	(original)
+++ trunk/gtk/gtk.symbols	Wed May 21 02:17:30 2008
@@ -2704,6 +2704,7 @@
 gtk_printer_get_backend
 gtk_printer_get_name
 gtk_printer_get_description
+gtk_printer_get_default_page_size
 gtk_printer_get_state_message
 gtk_printer_get_location
 gtk_printer_get_icon_name

Modified: trunk/gtk/gtkpagesetupunixdialog.c
==============================================================================
--- trunk/gtk/gtkpagesetupunixdialog.c	(original)
+++ trunk/gtk/gtkpagesetupunixdialog.c	Wed May 21 02:17:30 2008
@@ -681,8 +681,6 @@
   GtkTreeIter iter;
   gint i;
 
-  current_page_setup = get_current_page_setup (dialog);
-  
   gtk_list_store_clear (priv->page_setup_list);
 
   if (printer == NULL)
@@ -720,6 +718,15 @@
 
   fill_custom_paper_sizes (dialog);
   
+  current_page_setup = NULL;
+
+  /* When selecting a different printer, select its default paper size */
+  if (printer != NULL)
+    current_page_setup = gtk_printer_get_default_page_size (printer);
+
+  if (current_page_setup == NULL)
+    current_page_setup = get_current_page_setup (dialog);
+
   if (!set_paper_size (dialog, current_page_setup, FALSE, FALSE))
     set_paper_size (dialog, current_page_setup, TRUE, TRUE);
   

Modified: trunk/gtk/gtkprintbackend.c
==============================================================================
--- trunk/gtk/gtkprintbackend.c	(original)
+++ trunk/gtk/gtkprintbackend.c	Wed May 21 02:17:30 2008
@@ -283,16 +283,17 @@
 
 G_DEFINE_TYPE (GtkPrintBackend, gtk_print_backend, G_TYPE_OBJECT)
 
-static void                 fallback_printer_request_details  (GtkPrinter          *printer);
-static gboolean             fallback_printer_mark_conflicts   (GtkPrinter          *printer,
-							       GtkPrinterOptionSet *options);
-static void                 fallback_printer_get_hard_margins (GtkPrinter          *printer,
-							       gdouble             *top,
-							       gdouble             *bottom,
-							       gdouble             *left,
-							       gdouble             *right);
-static GList *              fallback_printer_list_papers      (GtkPrinter          *printer);
-static GtkPrintCapabilities fallback_printer_get_capabilities (GtkPrinter          *printer);
+static void                 fallback_printer_request_details       (GtkPrinter          *printer);
+static gboolean             fallback_printer_mark_conflicts        (GtkPrinter          *printer,
+								    GtkPrinterOptionSet *options);
+static void                 fallback_printer_get_hard_margins      (GtkPrinter          *printer,
+								    gdouble             *top,
+								    gdouble             *bottom,
+								    gdouble             *left,
+								    gdouble             *right);
+static GList *              fallback_printer_list_papers           (GtkPrinter          *printer);
+static GtkPageSetup *       fallback_printer_get_default_page_size (GtkPrinter          *printer);
+static GtkPrintCapabilities fallback_printer_get_capabilities      (GtkPrinter          *printer);
   
 static void
 gtk_print_backend_class_init (GtkPrintBackendClass *class)
@@ -308,6 +309,7 @@
   class->printer_mark_conflicts = fallback_printer_mark_conflicts;
   class->printer_get_hard_margins = fallback_printer_get_hard_margins;
   class->printer_list_papers = fallback_printer_list_papers;
+  class->printer_get_default_page_size = fallback_printer_get_default_page_size;
   class->printer_get_capabilities = fallback_printer_get_capabilities;
   
   g_type_class_add_private (class, sizeof (GtkPrintBackendPrivate));
@@ -419,6 +421,12 @@
   return NULL;
 }
 
+static GtkPageSetup *
+fallback_printer_get_default_page_size (GtkPrinter *printer)
+{
+  return NULL;
+}
+
 static GtkPrintCapabilities
 fallback_printer_get_capabilities (GtkPrinter *printer)
 {

Modified: trunk/gtk/gtkprintbackend.h
==============================================================================
--- trunk/gtk/gtkprintbackend.h	(original)
+++ trunk/gtk/gtkprintbackend.h	Wed May 21 02:17:30 2008
@@ -99,6 +99,7 @@
 							      GtkPrintSettings    *settings,
 							      GtkPageSetup        *page_setup);
   GList  *              (*printer_list_papers)               (GtkPrinter          *printer);
+  GtkPageSetup *        (*printer_get_default_page_size)     (GtkPrinter          *printer);
   void                  (*printer_get_hard_margins)          (GtkPrinter          *printer,
 							      double              *top,
 							      double              *bottom,
@@ -123,7 +124,6 @@
   void (*_gtk_reserved4) (void);
   void (*_gtk_reserved5) (void);
   void (*_gtk_reserved6) (void);
-  void (*_gtk_reserved7) (void);
 };
 
 GType   gtk_print_backend_get_type       (void) G_GNUC_CONST;

Modified: trunk/gtk/gtkprinter.c
==============================================================================
--- trunk/gtk/gtkprinter.c	(original)
+++ trunk/gtk/gtkprinter.c	Wed May 21 02:17:30 2008
@@ -832,6 +832,27 @@
   return backend_class->printer_list_papers (printer);
 }
 
+/**
+ * gtk_printer_get_default_page_size:
+ * @printer: a #GtkPrinter
+ * 
+ * Returns default page size of @printer.
+ * 
+ * Return value: a newly allocated #GtkPageSetup with default page size of the printer.
+ *
+ * Since: 2.13
+ */
+GtkPageSetup  *
+gtk_printer_get_default_page_size (GtkPrinter *printer)
+{
+  GtkPrintBackendClass *backend_class;
+
+  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);
+
+  backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
+  return backend_class->printer_get_default_page_size (printer);
+}
+
 void
 _gtk_printer_get_hard_margins (GtkPrinter *printer,
 			       gdouble    *top,

Modified: trunk/gtk/gtkprinter.h
==============================================================================
--- trunk/gtk/gtkprinter.h	(original)
+++ trunk/gtk/gtkprinter.h	Wed May 21 02:17:30 2008
@@ -83,28 +83,29 @@
   void (*_gtk_reserved7) (void);
 };
 
-GType                    gtk_printer_get_type          (void) G_GNUC_CONST;
-GtkPrinter              *gtk_printer_new               (const gchar     *name,
-							GtkPrintBackend *backend,
-							gboolean         virtual_);
-GtkPrintBackend         *gtk_printer_get_backend       (GtkPrinter      *printer);
-G_CONST_RETURN gchar    *gtk_printer_get_name          (GtkPrinter      *printer);
-G_CONST_RETURN gchar    *gtk_printer_get_state_message (GtkPrinter      *printer);
-G_CONST_RETURN gchar    *gtk_printer_get_description   (GtkPrinter      *printer);
-G_CONST_RETURN gchar    *gtk_printer_get_location      (GtkPrinter      *printer);
-G_CONST_RETURN gchar    *gtk_printer_get_icon_name     (GtkPrinter      *printer);
-gint                     gtk_printer_get_job_count     (GtkPrinter      *printer);
-gboolean                 gtk_printer_is_active         (GtkPrinter      *printer);
-gboolean                 gtk_printer_is_virtual        (GtkPrinter      *printer);
-gboolean                 gtk_printer_is_default        (GtkPrinter      *printer);
-gboolean                 gtk_printer_accepts_pdf       (GtkPrinter      *printer);
-gboolean                 gtk_printer_accepts_ps        (GtkPrinter      *printer);
-GList                   *gtk_printer_list_papers       (GtkPrinter      *printer);
-gint                     gtk_printer_compare           (GtkPrinter *a,
-							GtkPrinter *b);
-gboolean                 gtk_printer_has_details       (GtkPrinter       *printer);
-void                     gtk_printer_request_details   (GtkPrinter       *printer);
-GtkPrintCapabilities     gtk_printer_get_capabilities  (GtkPrinter       *printer);
+GType                    gtk_printer_get_type              (void) G_GNUC_CONST;
+GtkPrinter              *gtk_printer_new                   (const gchar     *name,
+							    GtkPrintBackend *backend,
+							    gboolean         virtual_);
+GtkPrintBackend         *gtk_printer_get_backend           (GtkPrinter      *printer);
+G_CONST_RETURN gchar    *gtk_printer_get_name              (GtkPrinter      *printer);
+G_CONST_RETURN gchar    *gtk_printer_get_state_message     (GtkPrinter      *printer);
+G_CONST_RETURN gchar    *gtk_printer_get_description       (GtkPrinter      *printer);
+G_CONST_RETURN gchar    *gtk_printer_get_location          (GtkPrinter      *printer);
+G_CONST_RETURN gchar    *gtk_printer_get_icon_name         (GtkPrinter      *printer);
+gint                     gtk_printer_get_job_count         (GtkPrinter      *printer);
+gboolean                 gtk_printer_is_active             (GtkPrinter      *printer);
+gboolean                 gtk_printer_is_virtual            (GtkPrinter      *printer);
+gboolean                 gtk_printer_is_default            (GtkPrinter      *printer);
+gboolean                 gtk_printer_accepts_pdf           (GtkPrinter      *printer);
+gboolean                 gtk_printer_accepts_ps            (GtkPrinter      *printer);
+GList                   *gtk_printer_list_papers           (GtkPrinter      *printer);
+GtkPageSetup            *gtk_printer_get_default_page_size (GtkPrinter      *printer);
+gint                     gtk_printer_compare               (GtkPrinter *a,
+						    	    GtkPrinter *b);
+gboolean                 gtk_printer_has_details           (GtkPrinter       *printer);
+void                     gtk_printer_request_details       (GtkPrinter       *printer);
+GtkPrintCapabilities     gtk_printer_get_capabilities      (GtkPrinter       *printer);
 
 typedef gboolean (*GtkPrinterFunc) (GtkPrinter *printer,
 				    gpointer    data);

Modified: trunk/gtk/gtkprintoperation-unix.c
==============================================================================
--- trunk/gtk/gtkprintoperation-unix.c	(original)
+++ trunk/gtk/gtkprintoperation-unix.c	Wed May 21 02:17:30 2008
@@ -349,7 +349,6 @@
 {
   GtkPrintOperationPrivate *priv = op->priv;
   GtkWidget *pd, *label;
-  GtkPageSetup *page_setup;
   const gchar *custom_tab_label;
 
   pd = gtk_print_unix_dialog_new (NULL, parent);
@@ -366,13 +365,8 @@
     gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd),
 					priv->print_settings);
   if (priv->default_page_setup)
-    page_setup = gtk_page_setup_copy (priv->default_page_setup);
-  else
-    page_setup = gtk_page_setup_new ();
-
-  gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd), 
-                                        page_setup);
-  g_object_unref (page_setup);
+    gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd), 
+                                          priv->default_page_setup);
 
   g_signal_emit_by_name (op, "create-custom-widget",
 			 &priv->custom_widget);
@@ -432,6 +426,10 @@
     {
       gtk_print_operation_set_print_settings (op, settings);
       priv->print_context = _gtk_print_context_new (op);
+
+      if ( (page_setup != NULL) && (gtk_print_operation_get_default_page_setup (op) == NULL))
+        gtk_print_operation_set_default_page_setup (op, page_setup);
+
       _gtk_print_context_set_page_setup (priv->print_context, page_setup);
 
       if (!rdata->do_preview)

Modified: trunk/gtk/gtkprintunixdialog.c
==============================================================================
--- trunk/gtk/gtkprintunixdialog.c	(original)
+++ trunk/gtk/gtkprintunixdialog.c	Wed May 21 02:17:30 2008
@@ -133,6 +133,7 @@
   GtkTreeModelFilter *printer_list_filter;
 
   GtkPageSetup *page_setup;
+  gboolean page_setup_set;
 
   GtkWidget *all_pages_radio;
   GtkWidget *current_page_radio;
@@ -407,6 +408,7 @@
   priv->current_page = -1;
 
   priv->page_setup = gtk_page_setup_new ();
+  priv->page_setup_set = FALSE;
 
   g_signal_connect (dialog, 
                     "destroy", 
@@ -1440,6 +1442,20 @@
 
   if (printer != NULL)
     {
+      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,
@@ -2650,6 +2666,8 @@
       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");
     }
 }

Modified: trunk/modules/printbackends/cups/gtkprintbackendcups.c
==============================================================================
--- trunk/modules/printbackends/cups/gtkprintbackendcups.c	(original)
+++ trunk/modules/printbackends/cups/gtkprintbackendcups.c	Wed May 21 02:17:30 2008
@@ -136,6 +136,7 @@
 								    GtkPrintSettings                  *settings,
 								    GtkPageSetup                      *page_setup);
 static GList *              cups_printer_list_papers               (GtkPrinter                        *printer);
+static GtkPageSetup *       cups_printer_get_default_page_size     (GtkPrinter                        *printer);
 static void                 cups_printer_request_details           (GtkPrinter                        *printer);
 static void                 cups_request_default_printer           (GtkPrintBackendCups               *print_backend);
 static void                 cups_request_ppd                       (GtkPrinter                        *printer);
@@ -255,6 +256,7 @@
   backend_class->printer_get_settings_from_options = cups_printer_get_settings_from_options;
   backend_class->printer_prepare_for_print = cups_printer_prepare_for_print;
   backend_class->printer_list_papers = cups_printer_list_papers;
+  backend_class->printer_get_default_page_size = cups_printer_get_default_page_size;
   backend_class->printer_get_hard_margins = cups_printer_get_hard_margins;
   backend_class->printer_get_capabilities = cups_printer_get_capabilities;
 }
@@ -1437,6 +1439,8 @@
   /* let ppdOpenFd take over the ownership of the open file */
   g_io_channel_seek_position (data->ppd_io, 0, G_SEEK_SET, NULL);
   data->printer->ppd_file = ppdOpenFd (dup (g_io_channel_unix_get_fd (data->ppd_io)));
+
+  ppdMarkDefaults (data->printer->ppd_file);
   
   gtk_printer_set_has_details (printer, TRUE);
   g_signal_emit_by_name (printer, "details-acquired", TRUE);
@@ -3121,16 +3125,52 @@
   print_job->rotate_to_orientation = TRUE;
 }
 
+static GtkPageSetup *
+create_page_setup (ppd_file_t *ppd_file,
+		   ppd_size_t *size)
+ {
+   char *display_name;
+   GtkPageSetup *page_setup;
+   GtkPaperSize *paper_size;
+   ppd_option_t *option;
+   ppd_choice_t *choice;
+
+  display_name = NULL;
+  option = ppdFindOption (ppd_file, "PageSize");
+  if (option)
+    {
+      choice = ppdFindChoice (option, size->name);
+      if (choice)
+	display_name = ppd_text_to_utf8 (ppd_file, choice->text);
+    }
+
+  if (display_name == NULL)
+    display_name = g_strdup (size->name);
+  
+  page_setup = gtk_page_setup_new ();
+  paper_size = gtk_paper_size_new_from_ppd (size->name,
+					    display_name,
+					    size->width,
+					    size->length);
+  gtk_page_setup_set_paper_size (page_setup, paper_size);
+  gtk_paper_size_free (paper_size);
+  
+  gtk_page_setup_set_top_margin (page_setup, size->length - size->top, GTK_UNIT_POINTS);
+  gtk_page_setup_set_bottom_margin (page_setup, size->bottom, GTK_UNIT_POINTS);
+  gtk_page_setup_set_left_margin (page_setup, size->left, GTK_UNIT_POINTS);
+  gtk_page_setup_set_right_margin (page_setup, size->width - size->right, GTK_UNIT_POINTS);
+  
+  g_free (display_name);
+
+  return page_setup;
+}
+
 static GList *
 cups_printer_list_papers (GtkPrinter *printer)
 {
   ppd_file_t *ppd_file;
   ppd_size_t *size;
-  char *display_name;
   GtkPageSetup *page_setup;
-  GtkPaperSize *paper_size;
-  ppd_option_t *option;
-  ppd_choice_t *choice;
   GList *l;
   int i;
 
@@ -3142,33 +3182,9 @@
   
   for (i = 0; i < ppd_file->num_sizes; i++)
     {
-      size = &ppd_file->sizes[i];
+      size = &ppd_file->sizes[i];      
 
-      display_name = NULL;
-      option = ppdFindOption (ppd_file, "PageSize");
-      if (option)
-	{
-	  choice = ppdFindChoice (option, size->name);
-	  if (choice)
-	    display_name = ppd_text_to_utf8 (ppd_file, choice->text);
-	}
-      if (display_name == NULL)
-	display_name = g_strdup (size->name);
-
-      page_setup = gtk_page_setup_new ();
-      paper_size = gtk_paper_size_new_from_ppd (size->name,
-						display_name,
-						size->width,
-						size->length);
-      gtk_page_setup_set_paper_size (page_setup, paper_size);
-      gtk_paper_size_free (paper_size);
-
-      gtk_page_setup_set_top_margin (page_setup, size->length - size->top, GTK_UNIT_POINTS);
-      gtk_page_setup_set_bottom_margin (page_setup, size->bottom, GTK_UNIT_POINTS);
-      gtk_page_setup_set_left_margin (page_setup, size->left, GTK_UNIT_POINTS);
-      gtk_page_setup_set_right_margin (page_setup, size->width - size->right, GTK_UNIT_POINTS);
-	
-      g_free (display_name);
+      page_setup = create_page_setup (ppd_file, size);
 
       l = g_list_prepend (l, page_setup);
     }
@@ -3176,6 +3192,24 @@
   return g_list_reverse (l);
 }
 
+static GtkPageSetup *
+cups_printer_get_default_page_size (GtkPrinter *printer)
+{
+  ppd_file_t *ppd_file;
+  ppd_size_t *size;
+  ppd_option_t *option;
+
+
+  ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
+  if (ppd_file == NULL)
+    return NULL;
+
+  option = ppdFindOption (ppd_file, "PageSize");
+  size = ppdPageSize (ppd_file, option->defchoice); 
+
+  return create_page_setup (ppd_file, size);
+}
+
 static void
 cups_printer_get_hard_margins (GtkPrinter *printer,
 			       gdouble    *top,

Modified: trunk/modules/printbackends/file/gtkprintbackendfile.c
==============================================================================
--- trunk/modules/printbackends/file/gtkprintbackendfile.c	(original)
+++ trunk/modules/printbackends/file/gtkprintbackendfile.c	Wed May 21 02:17:30 2008
@@ -104,6 +104,7 @@
 								    GIOChannel              *cache_io);
 
 static GList *              file_printer_list_papers               (GtkPrinter              *printer);
+static GtkPageSetup *       file_printer_get_default_page_size     (GtkPrinter              *printer);
 
 static void
 gtk_print_backend_file_register_type (GTypeModule *module)
@@ -182,6 +183,7 @@
   backend_class->printer_get_settings_from_options = file_printer_get_settings_from_options;
   backend_class->printer_prepare_for_print = file_printer_prepare_for_print;
   backend_class->printer_list_papers = file_printer_list_papers;
+  backend_class->printer_get_default_page_size = file_printer_get_default_page_size;
 }
 
 /* return N_FORMATS if no explicit format in the settings */
@@ -697,3 +699,11 @@
 
   return g_list_reverse (result);
 }
+
+static GtkPageSetup *
+file_printer_get_default_page_size (GtkPrinter *printer)
+{
+  GtkPageSetup *result = NULL;
+
+  return result;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]