[gtk+/gtk-3-4] Extract Function cups_create_printer



commit 8fa106dca66467c3b4a4508b7693554ef5ffd5fb
Author: John Ralls <jralls ceridwen us>
Date:   Sun Feb 19 13:29:11 2012 -0800

    Extract Function cups_create_printer

 modules/printbackends/cups/gtkprintbackendcups.c |  581 ++++++++++++----------
 1 files changed, 317 insertions(+), 264 deletions(-)
---
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
index 32ad4a6..9fc8dda 100644
--- a/modules/printbackends/cups/gtkprintbackendcups.c
+++ b/modules/printbackends/cups/gtkprintbackendcups.c
@@ -1,5 +1,5 @@
 /* GTK - The GIMP Toolkit
- * gtkprintbackendcups.h: Default implementation of GtkPrintBackend 
+ * gtkprintbackendcups.h: Default implementation of GtkPrintBackend
  * for the Common Unix Print System (CUPS)
  * Copyright (C) 2006, 2007 Red Hat, Inc.
  *
@@ -69,7 +69,7 @@ typedef struct _GtkPrintBackendCupsClass GtkPrintBackendCupsClass;
 #define GTK_IS_PRINT_BACKEND_CUPS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PRINT_BACKEND_CUPS))
 #define GTK_PRINT_BACKEND_CUPS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PRINT_BACKEND_CUPS, GtkPrintBackendCupsClass))
 
-#define _CUPS_MAX_ATTEMPTS 10 
+#define _CUPS_MAX_ATTEMPTS 10
 #define _CUPS_MAX_CHUNK_SIZE 8192
 
 /* define this to see warnings about ignored ppd options */
@@ -81,10 +81,10 @@ typedef struct _GtkPrintBackendCupsClass GtkPrintBackendCupsClass;
 static GType print_backend_cups_type = 0;
 
 typedef void (* GtkPrintCupsResponseCallbackFunc) (GtkPrintBackend *print_backend,
-                                                   GtkCupsResult   *result, 
+                                                   GtkCupsResult   *result,
                                                    gpointer         user_data);
 
-typedef enum 
+typedef enum
 {
   DISPATCH_SETUP,
   DISPATCH_REQUEST,
@@ -94,7 +94,7 @@ typedef enum
   DISPATCH_ERROR
 } GtkPrintCupsDispatchState;
 
-typedef struct 
+typedef struct
 {
   GSource source;
 
@@ -118,7 +118,7 @@ struct _GtkPrintBackendCups
   GtkPrintBackend parent_instance;
 
   char *default_printer;
-  
+
   guint list_printers_poll;
   guint list_printers_pending : 1;
   gint  list_printers_attempts;
@@ -195,7 +195,7 @@ static cairo_surface_t *    cups_printer_create_cairo_surface      (GtkPrinter
 								    gdouble                            height,
 								    GIOChannel                        *cache_io);
 
-static void                 gtk_print_backend_cups_set_password    (GtkPrintBackend                   *backend, 
+static void                 gtk_print_backend_cups_set_password    (GtkPrintBackend                   *backend,
                                                                     gchar                            **auth_info_required,
                                                                     gchar                            **auth_info);
 
@@ -225,23 +225,23 @@ gtk_print_backend_cups_register_type (GTypeModule *module)
                                                          &print_backend_cups_info, 0);
 }
 
-G_MODULE_EXPORT void 
+G_MODULE_EXPORT void
 pb_module_init (GTypeModule *module)
 {
   GTK_NOTE (PRINTING,
-            g_print ("CUPS Backend: Initializing the CUPS print backend module\n")); 
+            g_print ("CUPS Backend: Initializing the CUPS print backend module\n"));
 
   gtk_print_backend_cups_register_type (module);
   gtk_printer_cups_register_type (module);
 }
 
-G_MODULE_EXPORT void 
+G_MODULE_EXPORT void
 pb_module_exit (void)
 {
 
 }
-  
-G_MODULE_EXPORT GtkPrintBackend * 
+
+G_MODULE_EXPORT GtkPrintBackend *
 pb_module_create (void)
 {
   return gtk_print_backend_cups_new ();
@@ -300,7 +300,7 @@ gtk_print_backend_cups_class_init (GtkPrintBackendCupsClass *class)
   gobject_class->finalize = gtk_print_backend_cups_finalize;
   gobject_class->dispose = gtk_print_backend_cups_dispose;
 
-  backend_class->request_printer_list = cups_get_printer_list; 
+  backend_class->request_printer_list = cups_get_printer_list;
   backend_class->print_stream = gtk_print_backend_cups_print_stream;
   backend_class->printer_request_details = cups_printer_request_details;
   backend_class->printer_create_cairo_surface = cups_printer_create_cairo_surface;
@@ -329,19 +329,19 @@ _cairo_write_to_cups (void                *closure,
   GTK_NOTE (PRINTING,
             g_print ("CUPS Backend: Writing %i byte chunk to temp file\n", length));
 
-  while (length > 0) 
+  while (length > 0)
     {
       g_io_channel_write_chars (io, (gchar *)data, length, &written, &error);
 
       if (error != NULL)
 	{
 	  GTK_NOTE (PRINTING,
-                    g_print ("CUPS Backend: Error writing to temp file, %s\n", 
+                    g_print ("CUPS Backend: Error writing to temp file, %s\n",
                              error->message));
 
           g_error_free (error);
 	  return CAIRO_STATUS_WRITE_ERROR;
-	}    
+	}
 
       GTK_NOTE (PRINTING,
                 g_print ("CUPS Backend: Wrote %"G_GSIZE_FORMAT" bytes to temp file\n", written));
@@ -356,7 +356,7 @@ _cairo_write_to_cups (void                *closure,
 static cairo_surface_t *
 cups_printer_create_cairo_surface (GtkPrinter       *printer,
 				   GtkPrintSettings *settings,
-				   gdouble           width, 
+				   gdouble           width,
 				   gdouble           height,
 				   GIOChannel       *cache_io)
 {
@@ -472,7 +472,7 @@ cups_print_cb (GtkPrintBackendCups *print_backend,
   GDK_THREADS_ENTER ();
 
   GTK_NOTE (PRINTING,
-            g_print ("CUPS Backend: %s\n", G_STRFUNC)); 
+            g_print ("CUPS Backend: %s\n", G_STRFUNC));
 
   if (gtk_cups_result_is_error (result))
     error = g_error_new_literal (gtk_print_error_quark (),
@@ -498,15 +498,15 @@ cups_print_cb (GtkPrintBackendCups *print_backend,
 	  gtk_print_job_set_status (ps->job, GTK_PRINT_STATUS_PENDING);
 	  cups_begin_polling_info (print_backend, ps->job, job_id);
 	}
-    } 
+    }
   else
     gtk_print_job_set_status (ps->job, GTK_PRINT_STATUS_FINISHED_ABORTED);
 
-  
+
   if (error)
     g_error_free (error);
 
-  GDK_THREADS_LEAVE ();  
+  GDK_THREADS_LEAVE ();
 }
 
 typedef struct {
@@ -590,7 +590,7 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend         *print_backend,
   char  printer_absolute_uri[HTTP_MAX_URI];
 
   GTK_NOTE (PRINTING,
-            g_print ("CUPS Backend: %s\n", G_STRFUNC));   
+            g_print ("CUPS Backend: %s\n", G_STRFUNC));
 
   cups_printer = GTK_PRINTER_CUPS (gtk_print_job_get_printer (job));
   settings = gtk_print_job_get_settings (job);
@@ -621,14 +621,14 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend         *print_backend,
               gtk_printer_get_name (gtk_print_job_get_printer (job)));
 #endif
 
-  gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, 
+  gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION,
                                    IPP_TAG_URI, "printer-uri",
                                    NULL, printer_absolute_uri);
 
   title = gtk_print_job_get_title (job);
   if (title)
-    gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, 
-                                     IPP_TAG_NAME, "job-name", 
+    gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION,
+                                     IPP_TAG_NAME, "job-name",
                                      NULL, title);
 
   options_data = g_new0 (CupsOptionsData, 1);
@@ -667,8 +667,8 @@ void overwrite_and_free (gpointer data)
 static void
 gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups)
 {
-  backend_cups->list_printers_poll = FALSE;  
-  backend_cups->got_default_printer = FALSE;  
+  backend_cups->list_printers_poll = FALSE;
+  backend_cups->got_default_printer = FALSE;
   backend_cups->list_printers_pending = FALSE;
   backend_cups->list_printers_attempts = 0;
   backend_cups->reading_ppds = 0;
@@ -696,7 +696,7 @@ static void
 gtk_print_backend_cups_finalize (GObject *object)
 {
   GtkPrintBackendCups *backend_cups;
-  
+
   GTK_NOTE (PRINTING,
             g_print ("CUPS Backend: finalizing CUPS backend module\n"));
 
@@ -736,7 +736,7 @@ gtk_print_backend_cups_dispose (GObject *object)
     g_source_remove (backend_cups->list_printers_poll);
   backend_cups->list_printers_poll = 0;
   backend_cups->list_printers_attempts = 0;
-  
+
   if (backend_cups->default_printer_poll > 0)
     g_source_remove (backend_cups->default_printer_poll);
   backend_cups->default_printer_poll = 0;
@@ -936,7 +936,7 @@ request_password (gpointer data)
 
       g_free (printer_name);
 
-      g_signal_emit_by_name (dispatch->backend, "request-password", 
+      g_signal_emit_by_name (dispatch->backend, "request-password",
                              auth_info_required, auth_info_default, auth_info_display, auth_info_visible, prompt);
 
       g_free (prompt);
@@ -1143,16 +1143,16 @@ cups_dispatch_watch_check (GSource *source)
   gboolean result;
 
   GTK_NOTE (PRINTING,
-            g_print ("CUPS Backend: %s <source %p>\n", G_STRFUNC, source)); 
+            g_print ("CUPS Backend: %s <source %p>\n", G_STRFUNC, source));
 
   dispatch = (GtkPrintCupsDispatchWatch *) source;
 
   poll_state = gtk_cups_request_get_poll_state (dispatch->request);
 
   if (poll_state != GTK_CUPS_HTTP_IDLE && !dispatch->request->need_password)
-    if (!(dispatch->data_poll->revents & dispatch->data_poll->events)) 
+    if (!(dispatch->data_poll->revents & dispatch->data_poll->events))
        return FALSE;
-  
+
   result = gtk_cups_request_read_write (dispatch->request, FALSE);
   if (result && dispatch->data_poll != NULL)
     {
@@ -1167,7 +1167,7 @@ cups_dispatch_watch_check (GSource *source)
       g_idle_add (request_password, dispatch);
       result = FALSE;
     }
-  
+
   return result;
 }
 
@@ -1198,13 +1198,13 @@ cups_dispatch_watch_dispatch (GSource     *source,
 			      gpointer     user_data)
 {
   GtkPrintCupsDispatchWatch *dispatch;
-  GtkPrintCupsResponseCallbackFunc ep_callback;  
+  GtkPrintCupsResponseCallbackFunc ep_callback;
   GtkCupsResult *result;
-  
+
   g_assert (callback != NULL);
 
   ep_callback = (GtkPrintCupsResponseCallbackFunc) callback;
-  
+
   dispatch = (GtkPrintCupsDispatchWatch *) source;
 
   result = gtk_cups_request_get_result (dispatch->request);
@@ -1214,8 +1214,8 @@ cups_dispatch_watch_dispatch (GSource     *source,
 
   if (gtk_cups_result_is_error (result))
     {
-      GTK_NOTE (PRINTING, 
-                g_print("Error result: %s (type %i, status %i, code %i)\n", 
+      GTK_NOTE (PRINTING,
+                g_print("Error result: %s (type %i, status %i, code %i)\n",
                         gtk_cups_result_get_error_string (result),
                         gtk_cups_result_get_error_type (result),
                         gtk_cups_result_get_error_status (result),
@@ -1223,7 +1223,7 @@ cups_dispatch_watch_dispatch (GSource     *source,
      }
 
   ep_callback (GTK_PRINT_BACKEND (dispatch->backend), result, user_data);
-    
+
   return FALSE;
 }
 
@@ -1244,7 +1244,7 @@ cups_dispatch_watch_finalize (GSource *source)
       const gchar *username;
       gchar        hostname[HTTP_MAX_URI];
       gchar       *key;
-    
+
       httpGetHostname (dispatch->request->http, hostname, sizeof (hostname));
       if (is_address_local (hostname))
         strcpy (hostname, "localhost");
@@ -1259,7 +1259,7 @@ cups_dispatch_watch_finalize (GSource *source)
                 g_print ("CUPS backend: removing stored password for %s\n", key));
       g_hash_table_remove (dispatch->backend->auth, key);
       g_free (key);
-      
+
       if (dispatch->backend)
         dispatch->backend->authentication_lock = FALSE;
     }
@@ -1280,7 +1280,7 @@ cups_dispatch_watch_finalize (GSource *source)
 
       dispatch->backend->requests = g_list_remove (dispatch->backend->requests, dispatch);
 
-      
+
       g_object_unref (dispatch->backend);
       dispatch->backend = NULL;
     }
@@ -1310,7 +1310,7 @@ cups_request_execute (GtkPrintBackendCups              *print_backend,
 {
   GtkPrintCupsDispatchWatch *dispatch;
 
-  dispatch = (GtkPrintCupsDispatchWatch *) g_source_new (&_cups_dispatch_watch_funcs, 
+  dispatch = (GtkPrintCupsDispatchWatch *) g_source_new (&_cups_dispatch_watch_funcs,
                                                          sizeof (GtkPrintCupsDispatchWatch));
   g_source_set_name (&dispatch->source, "GTK+ CUPS backend");
 
@@ -1356,7 +1356,7 @@ cups_request_printer_info_cb (GtkPrintBackendCups *backend,
   gchar *desc;
   gchar *state_msg;
   int job_count;
-  gboolean status_changed;  
+  gboolean status_changed;
 
   g_assert (GTK_IS_PRINT_BACKEND_CUPS (backend));
 
@@ -1375,7 +1375,7 @@ cups_request_printer_info_cb (GtkPrintBackendCups *backend,
     }
 
   cups_printer = GTK_PRINTER_CUPS (printer);
-  
+
   if (gtk_cups_result_is_error (result))
     {
       if (gtk_printer_is_new (printer))
@@ -1392,12 +1392,12 @@ cups_request_printer_info_cb (GtkPrintBackendCups *backend,
 
   /* TODO: determine printer type and use correct icon */
   gtk_printer_set_icon_name (printer, "printer");
- 
+
   state_msg = "";
   loc = "";
   desc = "";
   job_count = 0;
-  for (attr = response->attrs; attr != NULL; attr = attr->next) 
+  for (attr = response->attrs; attr != NULL; attr = attr->next)
     {
       if (!attr->name)
         continue;
@@ -1410,14 +1410,14 @@ cups_request_printer_info_cb (GtkPrintBackendCups *backend,
     }
 
   status_changed = gtk_printer_set_job_count (printer, job_count);
-  
+
   status_changed |= gtk_printer_set_location (printer, loc);
   status_changed |= gtk_printer_set_description (printer, desc);
   status_changed |= gtk_printer_set_state_message (printer, state_msg);
 
   if (status_changed)
     g_signal_emit_by_name (GTK_PRINT_BACKEND (backend),
-			   "printer-status-changed", printer); 
+			   "printer-status-changed", printer);
 }
 
 static void
@@ -1458,7 +1458,7 @@ cups_request_printer_info (GtkPrintBackendCups *print_backend,
   gtk_cups_request_ipp_add_strings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
 				    "requested-attributes", G_N_ELEMENTS (pattrs),
 				    NULL, pattrs);
- 
+
   cups_request_execute (print_backend,
                         request,
                         (GtkPrintCupsResponseCallbackFunc) cups_request_printer_info_cb,
@@ -1487,7 +1487,7 @@ cups_job_poll_data_free (CupsJobPollData *data)
 {
   if (data->job)
     g_object_weak_unref (G_OBJECT (data->job), job_object_died, data);
-    
+
   g_free (data);
 }
 
@@ -1520,11 +1520,11 @@ cups_request_job_info_cb (GtkPrintBackendCups *print_backend,
   attr = ippFindAttribute (response, "job-state", IPP_TAG_INTEGER);
   state = ippGetInteger (attr, 0);
 #else
-  for (attr = response->attrs; attr != NULL; attr = attr->next) 
+  for (attr = response->attrs; attr != NULL; attr = attr->next)
     {
       if (!attr->name)
         continue;
-      
+
       _CUPS_MAP_ATTR_INT (attr, state, "job-state");
     }
 #endif
@@ -1567,11 +1567,11 @@ cups_request_job_info_cb (GtkPrintBackendCups *print_backend,
 	timeout = 500;
       else
 	timeout = 1000;
-      
+
       g_timeout_add (timeout, cups_job_info_poll_timeout, data);
     }
   else
-    cups_job_poll_data_free (data);    
+    cups_job_poll_data_free (data);
 
 done:
   GDK_THREADS_LEAVE ();
@@ -1607,12 +1607,12 @@ static gboolean
 cups_job_info_poll_timeout (gpointer user_data)
 {
   CupsJobPollData *data = user_data;
-  
+
   if (data->job == NULL)
     cups_job_poll_data_free (data);
   else
     cups_request_job_info (data);
-  
+
   return G_SOURCE_REMOVE;
 }
 
@@ -1636,7 +1636,7 @@ cups_begin_polling_info (GtkPrintBackendCups *print_backend,
 }
 
 static void
-mark_printer_inactive (GtkPrinter      *printer, 
+mark_printer_inactive (GtkPrinter      *printer,
                        GtkPrintBackend *backend)
 {
   gtk_printer_set_is_active (printer, FALSE);
@@ -1644,7 +1644,7 @@ mark_printer_inactive (GtkPrinter      *printer,
 }
 
 static gint
-find_printer (GtkPrinter  *printer, 
+find_printer (GtkPrinter  *printer,
 	      const gchar *find_name)
 {
   const gchar *printer_name;
@@ -1849,6 +1849,109 @@ cups_printer_handle_attribute (GtkPrintBackendCups *cups_backend,
     }
 }
 
+static GtkPrinter*
+cups_create_printer (GtkPrintBackendCups *cups_backend,
+		     PrinterSetupInfo *info)
+{
+  GtkPrinterCups *cups_printer;
+  GtkPrinter *printer;
+  GtkPrintBackend *backend = GTK_PRINT_BACKEND (cups_backend);
+  char uri[HTTP_MAX_URI];	/* Printer URI */
+  char method[HTTP_MAX_URI];	/* Method/scheme name */
+  char username[HTTP_MAX_URI];	/* Username:password */
+  char hostname[HTTP_MAX_URI];	/* Hostname */
+  char resource[HTTP_MAX_URI];	/* Resource name */
+  int  port;			/* Port number */
+  char *cups_server;            /* CUPS server */
+
+#ifdef HAVE_COLORD
+  cups_printer = gtk_printer_cups_new (info->printer_name,
+				       backend,
+				       cups_backend->colord_client);
+#else
+  cups_printer = gtk_printer_cups_new (info->printer_name, backend, NULL);
+#endif
+
+  cups_printer->device_uri = g_strdup_printf ("/printers/%s",
+					      info->printer_name);
+
+  /* Check to see if we are looking at a class */
+  if (info->member_uris)
+    {
+      cups_printer->printer_uri = g_strdup (info->member_uris);
+      /* TODO if member_uris is a class we need to recursivly find a printer */
+      GTK_NOTE (PRINTING,
+		g_print ("CUPS Backend: Found class with printer %s\n",
+			 info->member_uris));
+    }
+  else
+    {
+      cups_printer->printer_uri = g_strdup (info->printer_uri);
+      GTK_NOTE (PRINTING,
+		g_print ("CUPS Backend: Found printer %s\n",
+			 info->printer_uri));
+    }
+
+#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 2) || CUPS_VERSION_MAJOR > 1
+  httpSeparateURI (HTTP_URI_CODING_ALL, cups_printer->printer_uri,
+		   method, sizeof (method),
+		   username, sizeof (username),
+		   hostname, sizeof (hostname),
+		   &port,
+		   resource, sizeof (resource));
+
+#else
+  httpSeparate (cups_printer->printer_uri,
+		method,
+		username,
+		hostname,
+		&port,
+		resource);
+#endif
+
+  if (strncmp (resource, "/printers/", 10) == 0)
+    {
+      cups_printer->ppd_name = g_strdup (resource + 10);
+      GTK_NOTE (PRINTING,
+		g_print ("CUPS Backend: Setting ppd name '%s' for printer/class '%s'\n", cups_printer->ppd_name, printer_name));
+    }
+
+  gethostname (uri, sizeof (uri));
+  cups_server = g_strdup (cupsServer());
+
+  if (strcasecmp (uri, hostname) == 0)
+    strcpy (hostname, "localhost");
+
+  /* if the cups server is local and listening at a unix domain socket
+   * then use the socket connection
+   */
+  if ((strstr (hostname, "localhost") != NULL) &&
+      (cups_server[0] == '/'))
+    strcpy (hostname, cups_server);
+
+  g_free (cups_server);
+
+  cups_printer->default_cover_before = g_strdup (info->default_cover_before);
+  cups_printer->default_cover_after = g_strdup (info->default_cover_after);
+
+  cups_printer->hostname = g_strdup (hostname);
+  cups_printer->port = port;
+
+  cups_printer->auth_info_required = g_strdupv (info->auth_info_required);
+  g_strfreev (info->auth_info_required);
+
+  printer = GTK_PRINTER (cups_printer);
+
+  if (cups_backend->default_printer != NULL &&
+      strcmp (cups_backend->default_printer, gtk_printer_get_name (printer)) == 0)
+    gtk_printer_set_is_default (printer, TRUE);
+
+
+  gtk_print_backend_add_printer (backend, printer);
+  return printer;
+}
+
+
 static void
 cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
                               GtkCupsResult       *result,
@@ -1872,8 +1975,8 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
 
   if (gtk_cups_result_is_error (result))
     {
-      GTK_NOTE (PRINTING, 
-                g_warning ("CUPS Backend: Error getting printer list: %s %d %d", 
+      GTK_NOTE (PRINTING,
+                g_warning ("CUPS Backend: Error getting printer list: %s %d %d",
                            gtk_cups_result_get_error_string (result),
                            gtk_cups_result_get_error_type (result),
                            gtk_cups_result_get_error_code (result)));
@@ -1890,12 +1993,12 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
 
       goto done;
     }
-  
+
   /* Gather the names of the printers in the current queue
-   * so we may check to see if they were removed 
+   * so we may check to see if they were removed
    */
   removed_printer_checklist = gtk_print_backend_get_printer_list (backend);
-								  
+
   response = gtk_cups_result_get_response (result);
 
   for (attr = response->attrs; attr != NULL; attr = attr->next)
@@ -1903,13 +2006,12 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
       GtkPrinter *printer;
       gboolean status_changed = FALSE;
       GList *node;
-      gint i,j;
+      gint i;
       gchar *reason_msg_desc = NULL;
       gchar *tmp_msg = NULL;
       gchar *tmp_msg2 = NULL;
       gboolean found = FALSE;
       PrinterSetupInfo *info = g_slice_new0 (PrinterSetupInfo);
-      info->default_number_up = 1;
 
       /* Skip leading attributes until we hit a printer...
        */
@@ -1962,102 +2064,14 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
 				 (GCompareFunc) find_printer);
       removed_printer_checklist = g_list_delete_link (removed_printer_checklist,
 						      node);
- 
+
       printer = gtk_print_backend_find_printer (backend, info->printer_name);
       if (!printer)
-        {
-	  GtkPrinterCups *cups_printer;
-	  char uri[HTTP_MAX_URI];	/* Printer URI */
-	  char method[HTTP_MAX_URI];	/* Method/scheme name */
-	  char username[HTTP_MAX_URI];	/* Username:password */
-	  char hostname[HTTP_MAX_URI];	/* Hostname */
-	  char resource[HTTP_MAX_URI];	/* Resource name */
-	  int  port;			/* Port number */
-	  char *cups_server;            /* CUPS server */
-	  
-          list_has_changed = TRUE;
-#ifdef HAVE_COLORD
-          cups_printer = gtk_printer_cups_new (printer_name,
-                                               backend,
-                                               cups_backend->colord_client);
-#else
-          cups_printer = gtk_printer_cups_new (printer_name, backend, NULL);
-#endif
-
-	  cups_printer->device_uri = g_strdup_printf ("/printers/%s", printer_name);
-
-          /* Check to see if we are looking at a class */
-	  if (member_uris)
-	    {
-	      cups_printer->printer_uri = g_strdup (member_uris);
-	      /* TODO if member_uris is a class we need to recursivly find a printer */
-	      GTK_NOTE (PRINTING,
-                        g_print ("CUPS Backend: Found class with printer %s\n", member_uris));
-	    }
-	  else
-	    {
-	      cups_printer->printer_uri = g_strdup (printer_uri);
-              GTK_NOTE (PRINTING,
-                        g_print ("CUPS Backend: Found printer %s\n", printer_uri));
-            }
-
-#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 2) || CUPS_VERSION_MAJOR > 1
-	  httpSeparateURI (HTTP_URI_CODING_ALL, cups_printer->printer_uri, 
-			   method, sizeof (method), 
-			   username, sizeof (username),
-			   hostname, sizeof (hostname),
-			   &port, 
-			   resource, sizeof (resource));
-
-#else
-	  httpSeparate (cups_printer->printer_uri, 
-			method, 
-			username, 
-			hostname,
-			&port, 
-			resource);
-#endif
-
-          if (strncmp (resource, "/printers/", 10) == 0)
-	    {
-	      cups_printer->ppd_name = g_strdup (resource + 10);
-              GTK_NOTE (PRINTING,
-                        g_print ("CUPS Backend: Setting ppd name '%s' for printer/class '%s'\n", cups_printer->ppd_name, printer_name));
-            }
-
-	  gethostname (uri, sizeof (uri));
-	  cups_server = g_strdup (cupsServer());
-
-	  if (strcasecmp (uri, hostname) == 0)
-	    strcpy (hostname, "localhost");
-
-          /* if the cups server is local and listening at a unix domain socket 
-           * then use the socket connection
-           */
-	  if ((strstr (hostname, "localhost") != NULL) &&
-	      (cups_server[0] == '/'))
-	    strcpy (hostname, cups_server);
-
-	  g_free (cups_server);
-
-          cups_printer->default_cover_before = g_strdup (default_cover_before);
-          cups_printer->default_cover_after = g_strdup (default_cover_after);
-
-	  cups_printer->hostname = g_strdup (hostname);
-	  cups_printer->port = port;
-	  
-          cups_printer->auth_info_required = g_strdupv (auth_info_required);
-          g_strfreev (auth_info_required);
-
-	  printer = GTK_PRINTER (cups_printer);
-	  
-	  if (cups_backend->default_printer != NULL &&
-	      strcmp (cups_backend->default_printer, gtk_printer_get_name (printer)) == 0)
-	    gtk_printer_set_is_default (printer, TRUE);
+	{
+	  printer = cups_create_printer (cups_backend, info);
+	  list_has_changed = TRUE;
+	}
 
-	  
-	  gtk_print_backend_add_printer (backend, printer);
-        }
       else
 	g_object_ref (printer);
 
@@ -2181,11 +2195,11 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
       g_list_free_full (removed_printer_checklist, (GDestroyNotify) mark_printer_inactive);
       list_has_changed = TRUE;
     }
-  
+
 done:
   if (list_has_changed)
     g_signal_emit_by_name (backend, "printer-list-changed");
-  
+
   gtk_print_backend_set_list_done (backend);
 
   if (!cups_backend->got_default_printer && remote_default_printer != NULL)
@@ -2360,8 +2374,8 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend,
         {
           gtk_printer_set_has_details (printer, TRUE);
           success = TRUE;
-        } 
-        
+        }
+
       g_signal_emit_by_name (printer, "details-acquired", success);
       goto done;
     }
@@ -2371,7 +2385,7 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend,
   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);
 
@@ -2434,17 +2448,17 @@ cups_request_ppd (GtkPrinter *printer)
         }
     }
 
-  http = httpConnectEncrypt (cups_printer->hostname, 
+  http = httpConnectEncrypt (cups_printer->hostname,
 			     cups_printer->port,
 			     cupsEncryption ());
-  
+
   data = g_new0 (GetPPDData, 1);
 
-  fd = g_file_open_tmp ("gtkprint_ppd_XXXXXX", 
-                        &ppd_filename, 
+  fd = g_file_open_tmp ("gtkprint_ppd_XXXXXX",
+                        &ppd_filename,
                         &error);
 
-#ifdef G_ENABLE_DEBUG 
+#ifdef G_ENABLE_DEBUG
   /* If we are debugging printing don't delete the tmp files */
   if (!(gtk_get_debug_flags () & GTK_DEBUG_PRINTING))
     unlink (ppd_filename);
@@ -2454,8 +2468,8 @@ cups_request_ppd (GtkPrinter *printer)
 
   if (error != NULL)
     {
-      GTK_NOTE (PRINTING, 
-                g_warning ("CUPS Backend: Failed to create temp file, %s\n", 
+      GTK_NOTE (PRINTING,
+                g_warning ("CUPS Backend: Failed to create temp file, %s\n",
                            error->message));
       g_error_free (error);
       httpClose (http);
@@ -2465,7 +2479,7 @@ cups_request_ppd (GtkPrinter *printer)
       g_signal_emit_by_name (printer, "details-acquired", FALSE);
       return FALSE;
     }
-    
+
   data->http = http;
   fchmod (fd, S_IRUSR | S_IWUSR);
   data->ppd_io = g_io_channel_unix_new (fd);
@@ -2474,7 +2488,7 @@ cups_request_ppd (GtkPrinter *printer)
 
   data->printer = g_object_ref (printer);
 
-  resource = g_strdup_printf ("/printers/%s.ppd", 
+  resource = g_strdup_printf ("/printers/%s.ppd",
                               gtk_printer_cups_get_ppd_name (GTK_PRINTER_CUPS (printer)));
 
   print_backend = gtk_printer_get_backend (printer);
@@ -2509,7 +2523,7 @@ cups_request_ppd (GtkPrinter *printer)
 /* Ordering matters for default preference */
 static const char *lpoptions_locations[] = {
   "/etc/cups/lpoptions",
-  ".lpoptions", 
+  ".lpoptions",
   ".cups/lpoptions"
 };
 
@@ -2519,7 +2533,7 @@ cups_parse_user_default_printer (const char  *filename,
 {
   FILE *fp;
   char line[1024], *lineptr, *defname = NULL;
-  
+
   if ((fp = g_fopen (filename, "r")) == NULL)
     return;
 
@@ -2562,11 +2576,11 @@ cups_get_user_default_printer (char **printer_name)
           cups_parse_user_default_printer (lpoptions_locations[i],
                                            printer_name);
         }
-      else 
+      else
         {
           char *filename;
 
-          filename = g_build_filename (g_get_home_dir (), 
+          filename = g_build_filename (g_get_home_dir (),
                                        lpoptions_locations[i], NULL);
           cups_parse_user_default_printer (filename, printer_name);
           g_free (filename);
@@ -2638,7 +2652,7 @@ cups_get_user_options (const char     *printer_name,
   for (i = 0; i < G_N_ELEMENTS (lpoptions_locations); i++)
     {
       if (g_path_is_absolute (lpoptions_locations[i]))
-        { 
+        {
            num_options = cups_parse_user_options (lpoptions_locations[i],
                                                   printer_name,
                                                   num_options,
@@ -2648,7 +2662,7 @@ cups_get_user_options (const char     *printer_name,
         {
           char *filename;
 
-          filename = g_build_filename (g_get_home_dir (), 
+          filename = g_build_filename (g_get_home_dir (),
                                        lpoptions_locations[i], NULL);
           num_options = cups_parse_user_options (filename, printer_name,
                                                  num_options, options);
@@ -2702,8 +2716,8 @@ cups_get_local_default_printer (GtkPrintBackendCups *backend)
       backend->got_default_printer = TRUE;
       return;
     }
-  
-  /* Figure out user setting for default printer */  
+
+  /* Figure out user setting for default printer */
   cups_get_user_default_printer (&name);
   if (name != NULL)
     {
@@ -2739,7 +2753,7 @@ cups_request_default_printer_cb (GtkPrintBackendCups *print_backend,
     }
 
   response = gtk_cups_result_get_response (result);
-  
+
   if ((attr = ippFindAttribute (response, "printer-name", IPP_TAG_NAME)) != NULL)
       print_backend->default_printer = g_strdup (ippGetString (attr, 0, NULL));
 
@@ -2755,8 +2769,8 @@ cups_request_default_printer_cb (GtkPrintBackendCups *print_backend,
         }
     }
 
-  /* Make sure to kick off get_printers if we are polling it, 
-   * as we could have blocked this reading the default printer 
+  /* Make sure to kick off get_printers if we are polling it,
+   * as we could have blocked this reading the default printer
    */
   if (print_backend->list_printers_poll != 0)
     cups_request_printer_list (print_backend);
@@ -2783,7 +2797,7 @@ cups_request_default_printer (GtkPrintBackendCups *print_backend)
                                                 NULL,
                                                 NULL,
                                                 print_backend->username);
-  
+
   cups_request_execute (print_backend,
                         request,
                         (GtkPrintCupsResponseCallbackFunc) cups_request_default_printer_cb,
@@ -2799,7 +2813,7 @@ cups_printer_request_details (GtkPrinter *printer)
   GtkPrinterCups *cups_printer;
 
   cups_printer = GTK_PRINTER_CUPS (printer);
-  if (!cups_printer->reading_ppd && 
+  if (!cups_printer->reading_ppd &&
       gtk_printer_cups_get_ppd (cups_printer) == NULL)
     {
       if (cups_printer->remote)
@@ -2820,12 +2834,12 @@ cups_printer_request_details (GtkPrinter *printer)
 }
 
 static char *
-ppd_text_to_utf8 (ppd_file_t *ppd_file, 
+ppd_text_to_utf8 (ppd_file_t *ppd_file,
 		  const char *text)
 {
   const char *encoding = NULL;
   char *res;
-  
+
   if (g_ascii_strcasecmp (ppd_file->lang_encoding, "UTF-8") == 0)
     {
       return g_strdup (text);
@@ -2854,7 +2868,7 @@ ppd_text_to_utf8 (ppd_file_t *ppd_file,
     {
       encoding = "WINDOWS-1252";
     }
-  else 
+  else
     {
       /* Fallback, try iso-8859-1... */
       encoding = "ISO-8859-1";
@@ -2868,7 +2882,7 @@ ppd_text_to_utf8 (ppd_file_t *ppd_file,
                 g_warning ("CUPS Backend: Unable to convert PPD text\n"));
       res = g_strdup ("???");
     }
-  
+
   return res;
 }
 
@@ -2980,7 +2994,7 @@ static const char *color_group_whitelist[] = {
   "FPColorWise5",
   "HPColorOptionsPanel",
 };
-  
+
 /* keep sorted when changing */
 static const char *image_quality_option_whitelist[] = {
   "BRDocument",
@@ -3050,19 +3064,19 @@ static const char *finishing_group_whitelist[] = {
 /* keep sorted when changing */
 static const char *cups_option_blacklist[] = {
   "Collate",
-  "Copies", 
+  "Copies",
   "OutputOrder",
   "PageRegion",
   "PageSize",
 };
 
 static char *
-get_option_text (ppd_file_t   *ppd_file, 
+get_option_text (ppd_file_t   *ppd_file,
 		 ppd_option_t *option)
 {
   int i;
   char *utf8;
-  
+
   for (i = 0; i < G_N_ELEMENTS (cups_option_translations); i++)
     {
       if (strcmp (cups_option_translations[i].keyword, option->keyword) == 0)
@@ -3073,18 +3087,18 @@ get_option_text (ppd_file_t   *ppd_file,
 
   /* Some ppd files have spaces in the text before the colon */
   g_strchomp (utf8);
-  
+
   return utf8;
 }
 
 static char *
-get_choice_text (ppd_file_t   *ppd_file, 
+get_choice_text (ppd_file_t   *ppd_file,
 		 ppd_choice_t *choice)
 {
   int i;
   ppd_option_t *option = choice->option;
   const char *keyword = option->keyword;
-  
+
   for (i = 0; i < G_N_ELEMENTS (cups_choice_translations); i++)
     {
       if (strcmp (cups_choice_translations[i].keyword, keyword) == 0 &&
@@ -3095,18 +3109,18 @@ get_choice_text (ppd_file_t   *ppd_file,
 }
 
 static gboolean
-group_has_option (ppd_group_t  *group, 
+group_has_option (ppd_group_t  *group,
 		  ppd_option_t *option)
 {
   int i;
 
   if (group == NULL)
     return FALSE;
-  
+
   if (group->num_options > 0 &&
       option >= group->options && option < group->options + group->num_options)
     return TRUE;
-  
+
   for (i = 0; i < group->num_subgroups; i++)
     {
       if (group_has_option (&group->subgroups[i],option))
@@ -3136,7 +3150,7 @@ value_is_off (const char *value)
 static char *
 ppd_group_name (ppd_group_t *group)
 {
-#if CUPS_VERSION_MAJOR > 1 || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR > 1) || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR == 1 && CUPS_VERSION_PATCH >= 18) 
+#if CUPS_VERSION_MAJOR > 1 || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR > 1) || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR == 1 && CUPS_VERSION_PATCH >= 18)
   return group->name;
 #else
   return group->text;
@@ -3168,7 +3182,7 @@ available_choices (ppd_file_t     *ppd,
   installed_options = NULL;
   for (i = 0; i < ppd->num_groups; i++)
     {
-      char *name; 
+      char *name;
 
       name = ppd_group_name (&ppd->groups[i]);
       if (strcmp (name, "InstallableOptions") == 0)
@@ -3290,7 +3304,7 @@ available_choices (ppd_file_t     *ppd,
       if (!found_auto)
 	add_auto = 1;
     }
-  
+
   if (available)
     {
       *available = g_new (ppd_choice_t *, option->num_choices - num_conflicts + add_auto);
@@ -3302,12 +3316,12 @@ available_choices (ppd_file_t     *ppd,
 	    (*available)[i++] = &option->choices[j];
 	}
 
-      if (add_auto) 
+      if (add_auto)
 	(*available)[i++] = NULL;
     }
 
   g_free (conflicts);
-  
+
   return option->num_choices - num_conflicts + add_auto;
 }
 
@@ -3324,14 +3338,14 @@ create_pickone_option (ppd_file_t   *ppd_file,
   ppd_coption_t *coption;
 
   g_assert (ppd_option->ui == PPD_UI_PICKONE);
-  
+
   option = NULL;
 
   n_choices = available_choices (ppd_file, ppd_option, &available, g_str_has_prefix (gtk_name, "gtk-"));
   if (n_choices > 0)
     {
-      
-      /* right now only support one parameter per custom option 
+
+      /* right now only support one parameter per custom option
        * if more than one print warning and only offer the default choices
        */
 
@@ -3370,17 +3384,17 @@ create_pickone_option (ppd_file_t   *ppd_file,
 				         GTK_PRINTER_OPTION_TYPE_PICKONE_STRING);
 		  break;
 #ifdef PRINT_IGNORED_OPTIONS
-                case PPD_CUSTOM_POINTS: 
+                case PPD_CUSTOM_POINTS:
 		  g_warning ("CUPS Backend: PPD Custom Points Option not supported");
 		  break;
                 case PPD_CUSTOM_CURVE:
                   g_warning ("CUPS Backend: PPD Custom Curve Option not supported");
 		  break;
-                case PPD_CUSTOM_INVCURVE: 	
+                case PPD_CUSTOM_INVCURVE:
 		  g_warning ("CUPS Backend: PPD Custom Inverse Curve Option not supported");
 		  break;
 #endif
-                default: 
+                default:
                   break;
 		}
 	    }
@@ -3394,7 +3408,7 @@ create_pickone_option (ppd_file_t   *ppd_file,
         option = gtk_printer_option_new (gtk_name, label,
 				         GTK_PRINTER_OPTION_TYPE_PICKONE);
       g_free (label);
-      
+
       gtk_printer_option_allocate_choices (option, n_choices);
       for (i = 0; i < n_choices; i++)
 	{
@@ -3443,7 +3457,7 @@ create_boolean_option (ppd_file_t   *ppd_file,
   int n_choices;
 
   g_assert (ppd_option->ui == PPD_UI_BOOLEAN);
-  
+
   option = NULL;
 
   n_choices = available_choices (ppd_file, ppd_option, &available, g_str_has_prefix (gtk_name, "gtk-"));
@@ -3453,13 +3467,13 @@ create_boolean_option (ppd_file_t   *ppd_file,
       option = gtk_printer_option_new (gtk_name, label,
 				       GTK_PRINTER_OPTION_TYPE_BOOLEAN);
       g_free (label);
-      
+
       gtk_printer_option_allocate_choices (option, 2);
       option->choices[0] = g_strdup ("True");
       option->choices_display[0] = g_strdup ("True");
       option->choices[1] = g_strdup ("False");
       option->choices_display[1] = g_strdup ("False");
-      
+
       gtk_printer_option_set (option, ppd_option->defchoice);
     }
 #ifdef PRINT_IGNORED_OPTIONS
@@ -3500,7 +3514,7 @@ get_lpoption_name (const gchar *lpoption)
 }
 
 static int
-strptr_cmp (const void *a, 
+strptr_cmp (const void *a,
 	    const void *b)
 {
   char **aa = (char **)a;
@@ -3510,8 +3524,8 @@ strptr_cmp (const void *a,
 
 
 static gboolean
-string_in_table (gchar       *str, 
-		 const gchar *table[], 
+string_in_table (gchar       *str,
+		 const gchar *table[],
 		 gint         table_len)
 {
   return bsearch (&str, table, table_len, sizeof (char *), (void *)strptr_cmp) != NULL;
@@ -3547,8 +3561,8 @@ handle_option (GtkPrinterOptionSet *set,
 #ifdef PRINT_IGNORED_OPTIONS
   else
     g_warning ("CUPS Backend: Ignoring pickmany setting %s\n", ppd_option->text);
-#endif  
-  
+#endif
+
   if (option)
     {
       char *name;
@@ -3591,10 +3605,10 @@ handle_option (GtkPrinterOptionSet *set,
 	}
 
       set_option_from_settings (option, settings);
-      
+
       gtk_printer_option_set_add (set, option);
     }
-  
+
   g_free (name);
 }
 
@@ -3607,12 +3621,12 @@ handle_group (GtkPrinterOptionSet *set,
 {
   gint i;
   gchar *name;
-  
+
   /* Ignore installable options */
   name = ppd_group_name (toplevel_group);
   if (strcmp (name, "InstallableOptions") == 0)
     return;
-  
+
   for (i = 0; i < group->num_options; i++)
     handle_option (set, ppd_file, &group->options[i], toplevel_group, settings);
 
@@ -3651,7 +3665,7 @@ cups_printer_get_options (GtkPrinter           *printer,
   char *print_at[] = { "now", "at", "on-hold" };
   char *n_up[] = {"1", "2", "4", "6", "9", "16" };
   char *prio[] = {"100", "80", "50", "30" };
-  /* Translators: These strings name the possible values of the 
+  /* Translators: These strings name the possible values of the
    * job priority option in the print dialog
    */
   char *prio_display[] = {N_("Urgent"), N_("High"), N_("Medium"), N_("Low") };
@@ -3659,9 +3673,9 @@ cups_printer_get_options (GtkPrinter           *printer,
   /* Translators: These strings name the possible arrangements of
    * multiple pages on a sheet when printing
    */
-  char *n_up_layout_display[] = { N_("Left to right, top to bottom"), N_("Left to right, bottom to top"), 
-                                  N_("Right to left, top to bottom"), N_("Right to left, bottom to top"), 
-                                  N_("Top to bottom, left to right"), N_("Top to bottom, right to left"), 
+  char *n_up_layout_display[] = { N_("Left to right, top to bottom"), N_("Left to right, bottom to top"),
+                                  N_("Right to left, top to bottom"), N_("Right to left, bottom to top"),
+                                  N_("Top to bottom, left to right"), N_("Top to bottom, right to left"),
                                   N_("Bottom to top, left to right"), N_("Bottom to top, right to left") };
   char *name;
   int num_opts;
@@ -3713,9 +3727,9 @@ cups_printer_get_options (GtkPrinter           *printer,
 
   for (i = 0; i < G_N_ELEMENTS(prio_display); i++)
     prio_display[i] = _(prio_display[i]);
-  
-  /* Translators, this string is used to label the job priority option 
-   * in the print dialog 
+
+  /* Translators, this string is used to label the job priority option
+   * in the print dialog
    */
   option = gtk_printer_option_new ("gtk-job-prio", _("Job Priority"), GTK_PRINTER_OPTION_TYPE_PICKONE);
   gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (prio),
@@ -3726,7 +3740,7 @@ cups_printer_get_options (GtkPrinter           *printer,
   g_object_unref (option);
 
   /* Translators, this string is used to label the billing info entry
-   * in the print dialog 
+   * in the print dialog
    */
   option = gtk_printer_option_new ("gtk-billing-info", _("Billing Info"), GTK_PRINTER_OPTION_TYPE_STRING);
   gtk_printer_option_set (option, "");
@@ -3740,7 +3754,7 @@ cups_printer_get_options (GtkPrinter           *printer,
   if (backend != NULL && printer != NULL)
     {
       char *cover_default[] = {"none", "classified", "confidential", "secret", "standard", "topsecret", "unclassified" };
-      /* Translators, these strings are names for various 'standard' cover 
+      /* Translators, these strings are names for various 'standard' cover
        * pages that the printing system may support.
        */
       char *cover_display_default[] = {N_("None"), N_("Classified"), N_("Confidential"), N_("Secret"), N_("Standard"), N_("Top Secret"), N_("Unclassified"),};
@@ -3751,6 +3765,45 @@ cups_printer_get_options (GtkPrinter           *printer,
       gpointer value;
       gint j;
 
+<<<<<<< HEAD
+=======
+       /* Translators, this string is used to label the pages-per-sheet option
+        * in the print dialog
+        */
+      option = gtk_printer_option_new ("gtk-n-up", _("Pages per Sheet"), GTK_PRINTER_OPTION_TYPE_PICKONE);
+      gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up),
+					     n_up, n_up);
+      default_number_up = g_strdup_printf ("%d", cups_printer->default_number_up);
+      gtk_printer_option_set (option, default_number_up);
+      g_free (default_number_up);
+      set_option_from_settings (option, settings);
+      gtk_printer_option_set_add (set, option);
+      g_object_unref (option);
+
+      if (cups_printer_get_capabilities (printer) & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
+        {
+          for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
+            n_up_layout_display[i] = _(n_up_layout_display[i]);
+
+           /* Translators, this string is used to label the option in the print
+            * dialog that controls in what order multiple pages are arranged
+            */
+          option = gtk_printer_option_new ("gtk-n-up-layout", _("Page Ordering"), GTK_PRINTER_OPTION_TYPE_PICKONE);
+          gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up_layout),
+                                                 n_up_layout, n_up_layout_display);
+
+          text_direction = gtk_widget_get_default_direction ();
+          if (text_direction == GTK_TEXT_DIR_LTR)
+            gtk_printer_option_set (option, "lrtb");
+          else
+            gtk_printer_option_set (option, "rltb");
+
+          set_option_from_settings (option, settings);
+          gtk_printer_option_set_add (set, option);
+          g_object_unref (option);
+        }
+
+>>>>>>> 58ca845... Extract Function cups_create_printer
       num_of_covers = backend->number_of_covers;
       cover = g_new (char *, num_of_covers + 1);
       cover[num_of_covers] = NULL;
@@ -3774,8 +3827,8 @@ cups_printer_get_options (GtkPrinter           *printer,
 
       for (i = 0; i < num_of_covers; i++)
         cover_display_translated[i] = _(cover_display[i]);
-  
-      /* Translators, this is the label used for the option in the print 
+
+      /* Translators, this is the label used for the option in the print
        * dialog that controls the front cover page.
        */
       option = gtk_printer_option_new ("gtk-cover-before", _("Before"), GTK_PRINTER_OPTION_TYPE_PICKONE);
@@ -3790,7 +3843,7 @@ cups_printer_get_options (GtkPrinter           *printer,
       gtk_printer_option_set_add (set, option);
       g_object_unref (option);
 
-      /* Translators, this is the label used for the option in the print 
+      /* Translators, this is the label used for the option in the print
        * dialog that controls the back cover page.
        */
       option = gtk_printer_option_new ("gtk-cover-after", _("After"), GTK_PRINTER_OPTION_TYPE_PICKONE);
@@ -3820,7 +3873,7 @@ cups_printer_get_options (GtkPrinter           *printer,
   set_option_from_settings (option, settings);
   gtk_printer_option_set_add (set, option);
   g_object_unref (option);
-  
+
   /* Translators: this is the name of the option that allows the user
    * to specify a time when a print job will be printed.
    */
@@ -3829,7 +3882,7 @@ cups_printer_get_options (GtkPrinter           *printer,
   set_option_from_settings (option, settings);
   gtk_printer_option_set_add (set, option);
   g_object_unref (option);
-  
+
   /* Printer (ppd) specific settings */
   ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
   if (ppd_file)
@@ -3844,7 +3897,7 @@ cups_printer_get_options (GtkPrinter           *printer,
 
       option = ppdFindOption (ppd_file, "PageSize");
       ppd_name = gtk_paper_size_get_ppd_name (paper_size);
-      
+
       if (ppd_name)
 	strncpy (option->defchoice, ppd_name, PPD_MAX_NAME);
       else
@@ -3881,7 +3934,7 @@ cups_printer_get_options (GtkPrinter           *printer,
         {
           gchar **values;
           gint    num_values;
-          
+
           values = g_strsplit (opts[i].value, ",", 2);
           num_values = g_strv_length (values);
 
@@ -3985,7 +4038,7 @@ mark_option_from_set (GtkPrinterOptionSet *set,
 
   if (option)
     ppdMarkOption (ppd_file, ppd_option->keyword, option->value);
-  
+
   g_free (name);
 }
 
@@ -4023,7 +4076,7 @@ set_conflicts_from_option (GtkPrinterOptionSet *set,
       else
 	g_warning ("CUPS Backend: Ignoring conflict for option %s", ppd_option->keyword);
 #endif
-      
+
       g_free (name);
     }
 }
@@ -4049,7 +4102,7 @@ cups_printer_mark_conflicts (GtkPrinter          *printer,
   ppd_file_t *ppd_file;
   int num_conflicts;
   int i;
- 
+
   ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
 
   if (ppd_file == NULL)
@@ -4067,7 +4120,7 @@ cups_printer_mark_conflicts (GtkPrinter          *printer,
       for (i = 0; i < ppd_file->num_groups; i++)
 	set_conflicts_from_group (options, ppd_file, &ppd_file->groups[i]);
     }
- 
+
   return num_conflicts > 0;
 }
 
@@ -4100,8 +4153,8 @@ map_settings_to_option (GtkPrinterOption  *option,
   name = g_strdup_printf ("cups-%s", cups_name);
   cups_value = gtk_print_settings_get (settings, name);
   g_free (name);
-  
-  if (cups_value != NULL) 
+
+  if (cups_value != NULL)
     {
       gtk_printer_option_set (option, cups_value);
       return;
@@ -4229,7 +4282,7 @@ set_option_from_settings (GtkPrinterOption *option,
 {
   const char *cups_value;
   char *value;
-  
+
   if (settings == NULL)
     return;
 
@@ -4294,43 +4347,43 @@ set_option_from_settings (GtkPrinterOption *option,
       cups_value = gtk_print_settings_get (settings, "cups-job-billing");
       if (cups_value)
 	gtk_printer_option_set (option, cups_value);
-    } 
+    }
   else if (strcmp (option->name, "gtk-job-prio") == 0)
     {
       cups_value = gtk_print_settings_get (settings, "cups-job-priority");
       if (cups_value)
 	gtk_printer_option_set (option, cups_value);
-    } 
+    }
   else if (strcmp (option->name, "gtk-cover-before") == 0)
     {
       cups_value = gtk_print_settings_get (settings, "cover-before");
       if (cups_value)
 	gtk_printer_option_set (option, cups_value);
-    } 
+    }
   else if (strcmp (option->name, "gtk-cover-after") == 0)
     {
       cups_value = gtk_print_settings_get (settings, "cover-after");
       if (cups_value)
 	gtk_printer_option_set (option, cups_value);
-    } 
+    }
   else if (strcmp (option->name, "gtk-print-time") == 0)
     {
       cups_value = gtk_print_settings_get (settings, "print-at");
       if (cups_value)
 	gtk_printer_option_set (option, cups_value);
-    } 
+    }
   else if (strcmp (option->name, "gtk-print-time-text") == 0)
     {
       cups_value = gtk_print_settings_get (settings, "print-at-time");
       if (cups_value)
 	gtk_printer_option_set (option, cups_value);
-    } 
+    }
   else if (g_str_has_prefix (option->name, "cups-"))
     {
       cups_value = gtk_print_settings_get (settings, option->name);
       if (cups_value)
 	gtk_printer_option_set (option, cups_value);
-    } 
+    }
 }
 
 static void
@@ -4490,11 +4543,11 @@ cups_printer_get_settings_from_options (GtkPrinter          *printer,
   data.options = options;
   data.settings = settings;
   data.ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
- 
+
   if (data.ppd_file != NULL)
     {
       GtkPrinterOption *cover_before, *cover_after;
-      
+
       gtk_printer_option_set_foreach (options, foreach_option_get_settings, &data);
 
       cover_before = gtk_printer_option_set_lookup (options, "gtk-cover-before");
@@ -4512,7 +4565,7 @@ cups_printer_get_settings_from_options (GtkPrinter          *printer,
       if (strcmp (print_at, "at") == 0)
         {
           gchar *utc_time = NULL;
-          
+
           utc_time = localtime_to_utctime (print_at_time);
 
           if (utc_time != NULL)
@@ -4652,7 +4705,7 @@ create_page_setup (ppd_file_t *ppd_file,
 
   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,
@@ -4660,12 +4713,12 @@ create_page_setup (ppd_file_t *ppd_file,
 					    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;
@@ -4685,10 +4738,10 @@ cups_printer_list_papers (GtkPrinter *printer)
     return NULL;
 
   l = NULL;
-  
+
   for (i = 0; i < ppd_file->num_sizes; i++)
     {
-      size = &ppd_file->sizes[i];      
+      size = &ppd_file->sizes[i];
 
       page_setup = create_page_setup (ppd_file, size);
 
@@ -4714,7 +4767,7 @@ cups_printer_get_default_page_size (GtkPrinter *printer)
   if (option == NULL)
     return NULL;
 
-  size = ppdPageSize (ppd_file, option->defchoice); 
+  size = ppdPageSize (ppd_file, option->defchoice);
   if (size == NULL)
     return NULL;
 



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