[gtk+] Get default cover sheets from each printer separately



commit 94bc87c637c2acd9f9f3e69211b7d4a5aeb64030
Author: Marek Kasik <mkasik redhat com>
Date:   Wed Aug 5 10:34:27 2009 +0200

    Get default cover sheets from each printer separately
    
    Fixes bug #590309.
    Add default_cover_before string and default_cover_after string
    to GtkPrinterCups and fill it when getting list of printers.

 modules/printbackends/cups/gtkprintbackendcups.c |   35 +++++++++------------
 modules/printbackends/cups/gtkprintercups.c      |    4 ++
 modules/printbackends/cups/gtkprintercups.h      |    3 ++
 3 files changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
index 6491e34..f29d637 100644
--- a/modules/printbackends/cups/gtkprintbackendcups.c
+++ b/modules/printbackends/cups/gtkprintbackendcups.c
@@ -115,8 +115,6 @@ struct _GtkPrintBackendCups
   GtkCupsConnectionTest *cups_connection_test;
 
   char **covers;
-  char  *default_cover_before;
-  char  *default_cover_after;
   int    number_of_covers;
 
   GList      *requests;
@@ -598,8 +596,6 @@ gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups)
   backend_cups->authentication_lock = FALSE;
 
   backend_cups->covers = NULL;
-  backend_cups->default_cover_before = NULL;
-  backend_cups->default_cover_after = NULL;
   backend_cups->number_of_covers = 0;
 
   backend_cups->default_printer_poll = 0;
@@ -626,9 +622,6 @@ gtk_print_backend_cups_finalize (GObject *object)
   g_strfreev (backend_cups->covers);
   backend_cups->number_of_covers = 0;
 
-  g_free (backend_cups->default_cover_before);
-  g_free (backend_cups->default_cover_after);
-
   gtk_cups_connection_test_free (backend_cups->cups_connection_test);
   backend_cups->cups_connection_test = NULL;
 
@@ -1431,6 +1424,8 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
       gboolean is_accepting_jobs = TRUE;
       gboolean default_printer = FALSE;
       gboolean got_printer_type = FALSE;
+      gchar   *default_cover_before = NULL;
+      gchar   *default_cover_after = NULL;
       
       /* Skip leading attributes until we hit a printer...
        */
@@ -1523,22 +1518,17 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
               {
                 cups_backend->number_of_covers = attr->num_values;
                 cups_backend->covers = g_new (char *, cups_backend->number_of_covers + 1);
-
                 for (i = 0; i < cups_backend->number_of_covers; i++)
                   cups_backend->covers[i] = g_strdup (attr->values[i].string.text);
-
                 cups_backend->covers[cups_backend->number_of_covers] = NULL;
               }
           }
         else if (strcmp (attr->name, "job-sheets-default") == 0)
           {
-            if ( (cups_backend->default_cover_before == NULL) && (cups_backend->default_cover_after == NULL))
+            if (attr->num_values == 2)
               {
-                if (attr->num_values == 2)
-                  {
-                    cups_backend->default_cover_before = g_strdup (attr->values[0].string.text);
-                    cups_backend->default_cover_after = g_strdup (attr->values[1].string.text);
-                  }
+                default_cover_before = attr->values[0].string.text;
+                default_cover_after = attr->values[1].string.text;
               }
           }
         else if (strcmp (attr->name, "printer-type") == 0)
@@ -1656,6 +1646,9 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
 
 	  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;
 	  
@@ -3136,6 +3129,7 @@ cups_printer_get_options (GtkPrinter           *printer,
   cups_option_t *opts = NULL;
   GtkPrintBackendCups *backend;
   GtkTextDirection text_direction;
+  GtkPrinterCups *cups_printer = NULL;
 
 
   set = gtk_printer_option_set_new ();
@@ -3200,8 +3194,9 @@ cups_printer_get_options (GtkPrinter           *printer,
   g_object_unref (option);
 
   backend = GTK_PRINT_BACKEND_CUPS (gtk_printer_get_backend (printer));
+  cups_printer = GTK_PRINTER_CUPS (printer);
 
-  if (backend != NULL)
+  if (backend != NULL && printer != NULL)
     {
       char *cover_default[] = {"none", "classified", "confidential", "secret", "standard", "topsecret", "unclassified" };
       /* Translators, these strings are names for various 'standard' cover 
@@ -3246,8 +3241,8 @@ cups_printer_get_options (GtkPrinter           *printer,
       gtk_printer_option_choices_from_array (option, num_of_covers,
 					 cover, cover_display_translated);
 
-      if (backend->default_cover_before != NULL)
-        gtk_printer_option_set (option, backend->default_cover_before);
+      if (cups_printer->default_cover_before != NULL)
+        gtk_printer_option_set (option, cups_printer->default_cover_before);
       else
         gtk_printer_option_set (option, "none");
       set_option_from_settings (option, settings);
@@ -3260,8 +3255,8 @@ cups_printer_get_options (GtkPrinter           *printer,
       option = gtk_printer_option_new ("gtk-cover-after", _("After"), GTK_PRINTER_OPTION_TYPE_PICKONE);
       gtk_printer_option_choices_from_array (option, num_of_covers,
 					 cover, cover_display_translated);
-      if (backend->default_cover_after != NULL)
-        gtk_printer_option_set (option, backend->default_cover_after);
+      if (cups_printer->default_cover_after != NULL)
+        gtk_printer_option_set (option, cups_printer->default_cover_after);
       else
         gtk_printer_option_set (option, "none");
       set_option_from_settings (option, settings);
diff --git a/modules/printbackends/cups/gtkprintercups.c b/modules/printbackends/cups/gtkprintercups.c
index e543619..cd27b17 100644
--- a/modules/printbackends/cups/gtkprintercups.c
+++ b/modules/printbackends/cups/gtkprintercups.c
@@ -75,6 +75,8 @@ gtk_printer_cups_init (GtkPrinterCups *printer)
   printer->port = 0;
   printer->ppd_name = NULL;
   printer->ppd_file = NULL;
+  printer->default_cover_before = NULL;
+  printer->default_cover_after = NULL;
 }
 
 static void
@@ -90,6 +92,8 @@ gtk_printer_cups_finalize (GObject *object)
   g_free (printer->printer_uri);
   g_free (printer->hostname);
   g_free (printer->ppd_name);
+  g_free (printer->default_cover_before);
+  g_free (printer->default_cover_after);
 
   if (printer->ppd_file)
     ppdClose (printer->ppd_file);
diff --git a/modules/printbackends/cups/gtkprintercups.h b/modules/printbackends/cups/gtkprintercups.h
index 6f1c00d..cd2b318 100644
--- a/modules/printbackends/cups/gtkprintercups.h
+++ b/modules/printbackends/cups/gtkprintercups.h
@@ -52,6 +52,9 @@ struct _GtkPrinterCups
   gboolean reading_ppd;
   gchar      *ppd_name;
   ppd_file_t *ppd_file;
+
+  gchar  *default_cover_before;
+  gchar  *default_cover_after;
 };
 
 struct _GtkPrinterCupsClass



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