]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprinter.c
More of the same
[~andy/gtk] / gtk / gtkprinter.c
index 65f7e223bd4d2c16490070194b5dc816a3bb362a..3da9434a2a4515385250a9fd70605501842d2c80 100644 (file)
@@ -477,7 +477,7 @@ gtk_printer_set_state_message (GtkPrinter  *printer,
  * gtk_printer_get_location:
  * @printer: a #GtkPrinter
  * 
- * Returns a  description of the location of the printer.
+ * Returns a description of the location of the printer.
  * 
  * Return value: the location of @printer
  *
@@ -511,7 +511,7 @@ gtk_printer_set_location (GtkPrinter  *printer,
   return TRUE;
 }
 
-/**
+**
  * gtk_printer_get_icon_name:
  * @printer: a #GtkPrinter
  * 
@@ -582,9 +582,21 @@ gtk_printer_set_job_count (GtkPrinter *printer,
   return TRUE;
 }
 
+/**
+ * gtk_printer_has_details:
+ * @printer: a #GtkPrinter
+ * 
+ * Returns whether the printer details are available.
+ * 
+ * Return value: %TRUE if @printer details are available
+ *
+ * Since: 2.12
+ */
 gboolean
-_gtk_printer_has_details (GtkPrinter *printer)
+gtk_printer_has_details (GtkPrinter *printer)
 {
+  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
+
   return printer->priv->has_details;
 }
 
@@ -644,6 +656,17 @@ gtk_printer_is_virtual (GtkPrinter *printer)
   return printer->priv->is_virtual;
 }
 
+/**
+ * gtk_printer_accepts_pdf:
+ * @printer: a #GtkPrinter
+ *
+ * Returns whether the printer accepts input in
+ * PDF format.  
+ *
+ * Return value: %TRUE if @printer accepts PDF
+ *
+ * Since: 2.10
+ */
 gboolean 
 gtk_printer_accepts_pdf (GtkPrinter *printer)
 { 
@@ -652,6 +675,17 @@ gtk_printer_accepts_pdf (GtkPrinter *printer)
   return printer->priv->accepts_pdf;
 }
 
+/**
+ * gtk_printer_accepts_ps:
+ * @printer: a #GtkPrinter
+ *
+ * Returns whether the printer accepts input in
+ * PostScript format.  
+ *
+ * Return value: %TRUE if @printer accepts PostScript
+ *
+ * Since: 2.10
+ */
 gboolean 
 gtk_printer_accepts_ps (GtkPrinter *printer)
 { 
@@ -705,10 +739,23 @@ gtk_printer_set_is_default (GtkPrinter *printer,
   printer->priv->is_default = TRUE;
 }
 
+/**
+ * gtk_printer_request_details:
+ * @printer: a #GtkPrinter
+ * 
+ * Requests the printer details. When the details are available,
+ * the #GtkPrinter::details-acquired signal will be emitted on @printer.
+ * 
+ * Since: 2.12
+ */
 void
-_gtk_printer_request_details (GtkPrinter *printer)
+gtk_printer_request_details (GtkPrinter *printer)
 {
-  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
+  GtkPrintBackendClass *backend_class;
+
+  g_return_if_fail (GTK_IS_PRINTER (printer));
+
+  backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
   backend_class->printer_request_details (printer);
 }
 
@@ -754,19 +801,34 @@ _gtk_printer_create_cairo_surface (GtkPrinter       *printer,
                                   GtkPrintSettings *settings,
                                   gdouble           width, 
                                   gdouble           height,
-                                  gint              cache_fd)
+                                  GIOChannel       *cache_io)
 {
   GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
 
   return backend_class->printer_create_cairo_surface (printer, settings,
-                                                     width, height, cache_fd);
+                                                     width, height, cache_io);
 }
 
+/**
+ * gtk_printer_list_papers:
+ * @printer:
+ * 
+ * Lists all the paper sizes @printer supports.
+ * This will return and empty list unless the printer's details are 
+ * available, see gtk_printer_has_details() and gtk_printer_request_details().
+ * 
+ * Return value: a newly allocated list of newly allocated #GtkPageSetup s.
+ *
+ * Since: 2.12
+ */
 GList  *
-_gtk_printer_list_papers (GtkPrinter *printer)
+gtk_printer_list_papers (GtkPrinter *printer)
 {
-  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
+  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_list_papers (printer);
 }
 
@@ -782,16 +844,49 @@ _gtk_printer_get_hard_margins (GtkPrinter *printer,
   backend_class->printer_get_hard_margins (printer, top, bottom, left, right);
 }
 
+/**
+ * gtk_printer_get_capabilities:
+ * @printer: a #GtkPrinter
+ * 
+ * Returns the printer's capabilities.
+ *
+ * This is useful when you're using #GtkPrintUnixDialog's manual-capabilities 
+ * setting and need to know which settings the printer can handle and which 
+ * you must handle yourself.
+ *
+ * This will return 0 unless the printer's details are available, see
+ * gtk_printer_has_details() and gtk_printer_request_details().
+ *  *
+ * Return value: the printer's capabilities
+ *
+ * Since: 2.12
+ */
 GtkPrintCapabilities
-_gtk_printer_get_capabilities (GtkPrinter *printer)
+gtk_printer_get_capabilities (GtkPrinter *printer)
 {
-  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
+  GtkPrintBackendClass *backend_class;
 
+  g_return_val_if_fail (GTK_IS_PRINTER (printer), 0);
+
+  backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
   return backend_class->printer_get_capabilities (printer);
 }
 
+/**
+ * gtk_printer_compare:
+ * @a: a #GtkPrinter
+ * @b: another #GtkPrinter
+ *
+ * Compares two printers.
+ * 
+ * Return value: 0 if the printer match, a negative value if @a < @b, 
+ *   or a positive value if @a > @b
+ *
+ * Since: 2.10
+ */
 gint
-gtk_printer_compare (GtkPrinter *a, GtkPrinter *b)
+gtk_printer_compare (GtkPrinter *a, 
+                     GtkPrinter *b)
 {
   const char *name_a, *name_b;
   
@@ -834,27 +929,35 @@ stop_enumeration (PrinterList *printer_list)
       backend = GTK_PRINT_BACKEND (list->data);
       list_done_cb (backend, printer_list);
     }
+}
 
+static void 
+free_printer_list (PrinterList *printer_list)
+{
   if (printer_list->destroy)
     printer_list->destroy (printer_list->data);
 
   if (printer_list->loop)
     {    
       g_main_loop_quit (printer_list->loop);
-
       g_main_loop_unref (printer_list->loop);
     }
 
   g_free (printer_list);
 }
 
-static void
+static gboolean
 list_added_cb (GtkPrintBackend *backend, 
               GtkPrinter      *printer, 
               PrinterList     *printer_list)
 {
   if (printer_list->func (printer, printer_list->data))
-    stop_enumeration (printer_list);
+    {
+      stop_enumeration (printer_list);
+      return TRUE;
+    }
+
+  return FALSE;
 }
 
 static void
@@ -870,20 +973,25 @@ list_done_cb (GtkPrintBackend *backend,
   g_object_unref (backend);
 
   if (printer_list->backends == NULL)
-    stop_enumeration (printer_list);
+    free_printer_list (printer_list);
 }
 
-static void
+static gboolean
 list_printers_init (PrinterList     *printer_list,
                    GtkPrintBackend *backend)
 {
-  GList *list;
-  GList *node;
+  GList *list, *node;
 
   list = gtk_print_backend_get_printer_list (backend);
 
   for (node = list; node != NULL; node = node->next)
-    list_added_cb (backend, node->data, printer_list);
+    {
+      if (list_added_cb (backend, node->data, printer_list))
+        {
+          g_list_free (list);
+          return TRUE;
+        }
+    }
 
   g_list_free (list);
 
@@ -903,6 +1011,7 @@ list_printers_init (PrinterList     *printer_list,
                        printer_list);
     }
 
+  return FALSE;
 }
 
 /**
@@ -913,8 +1022,8 @@ list_printers_init (PrinterList     *printer_list,
  * @wait: if %TRUE, wait in a recursive mainloop until
  *    all printers are enumerated; otherwise return early
  *
- * Calls a function for all #GtkPrinter<!-- -->s. If @func
- * returns %TRUE, the enumeration is stopped.
+ * Calls a function for all #GtkPrinter<!-- -->s. 
+ * If @func returns %TRUE, the enumeration is stopped.
  *
  * Since: 2.10
  */
@@ -925,7 +1034,7 @@ gtk_enumerate_printers (GtkPrinterFunc func,
                        gboolean       wait)
 {
   PrinterList *printer_list;
-  GList *printers, *node, *next;
+  GList *node, *next;
   GtkPrintBackend *backend;
 
   printer_list = g_new0 (PrinterList, 1);
@@ -936,12 +1045,19 @@ gtk_enumerate_printers (GtkPrinterFunc func,
 
   if (g_module_supported ())
     printer_list->backends = gtk_print_backend_load_modules ();
+  
+  if (printer_list->backends == NULL)
+    {
+      free_printer_list (printer_list);
+      return;
+    }
 
   for (node = printer_list->backends; node != NULL; node = next)
     {
       next = node->next;
       backend = GTK_PRINT_BACKEND (node->data);
-      list_printers_init (printer_list, backend);
+      if (list_printers_init (printer_list, backend))
+        return;
     }
 
   if (wait && printer_list->backends)
@@ -954,6 +1070,31 @@ gtk_enumerate_printers (GtkPrinterFunc func,
     }
 }
 
+GType
+gtk_print_capabilities_get_type (void)
+{
+  static GType etype = 0;
+
+  if (G_UNLIKELY (etype == 0))
+    {
+      static const GFlagsValue values[] = {
+        { GTK_PRINT_CAPABILITY_PAGE_SET, "GTK_PRINT_CAPABILITY_PAGE_SET", "page-set" },
+        { GTK_PRINT_CAPABILITY_COPIES, "GTK_PRINT_CAPABILITY_COPIES", "copies" },
+        { GTK_PRINT_CAPABILITY_COLLATE, "GTK_PRINT_CAPABILITY_COLLATE", "collate" },
+        { GTK_PRINT_CAPABILITY_REVERSE, "GTK_PRINT_CAPABILITY_REVERSE", "reverse" },
+        { GTK_PRINT_CAPABILITY_SCALE, "GTK_PRINT_CAPABILITY_SCALE", "scale" },
+        { GTK_PRINT_CAPABILITY_GENERATE_PDF, "GTK_PRINT_CAPABILITY_GENERATE_PDF", "generate-pdf" },
+        { GTK_PRINT_CAPABILITY_GENERATE_PS, "GTK_PRINT_CAPABILITY_GENERATE_PS", "generate-ps" },
+        { GTK_PRINT_CAPABILITY_PREVIEW, "GTK_PRINT_CAPABILITY_PREVIEW", "preview" },
+        { 0, NULL, NULL }
+      };
+
+      etype = g_flags_register_static (I_("GtkPrintCapabilities"), values);
+    }
+
+  return etype;
+}
+
 
 #define __GTK_PRINTER_C__
 #include "gtkaliasdef.c"