Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(révision 17706)
+++ tests/Makefile.am	(copie de travail)
@@ -56,6 +56,7 @@ noinst_PROGRAMS =			\
 	testnotebookdnd			\
 	testnouiprint			\
 	testprint			\
+	testprinterenum			\
 	testrgb				\
 	testrecentchooser 		\
 	testrecentchoosermenu		\
@@ -116,6 +117,7 @@ testmultiscreen_DEPENDENCIES = $(TEST_DE
 testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
 testnouiprint_DEPENDENCIES = $(TEST_DEPS)
 testprint_DEPENDENCIES = $(TEST_DEPS)
+testprinterenum_DEPENDENCIES = $(TEST_DEPS)
 testrecentchooser_DEPENDENCIES = $(TEST_DEPS)
 testrecentchoosermenu_DEPENDENCIES = $(TEST_DEPS)
 testrgb_DEPENDENCIES = $(TEST_DEPS)
@@ -170,6 +172,7 @@ testmultiscreen_LDADD = $(LDADDS)
 testnotebookdnd_LDADD = $(LDADDS)
 testnouiprint_LDADD = $(LDADDS)
 testprint_LDADD = $(LDADDS)
+testprinterenum_LDADD = $(LDADDS)
 testrecentchooser_LDADD = $(LDADDS)
 testrecentchoosermenu_LDADD = $(LDADDS)
 testrgb_LDADD = $(LDADDS)
@@ -244,6 +247,9 @@ testprint_SOURCES =    	\
 	testprintfileoperation.h \
 	testprintfileoperation.c
 
+testprinterenum_SOURCES =    	\
+	testprinterenum.c
+
 testsocket_SOURCES =    	\
 	testsocket.c		\
 	testsocket_common.c
Index: tests/testprinterenum.c
===================================================================
--- tests/testprinterenum.c	(révision 0)
+++ tests/testprinterenum.c	(révision 0)
@@ -0,0 +1,195 @@
+/*
+ *  Copyright © 2007 Christian Persch
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+
+#include <gtk/gtk.h>
+#include <gtk/gtkprinter.h>
+
+static guint n_requests = 0;
+static gboolean list_papers = FALSE;
+
+static gboolean
+tick_cb (GtkLabel *label)
+{
+  static guint ticks = 0;
+
+  ticks++;
+  if (label != NULL)
+    {
+      char str[32];
+
+      g_snprintf (str, sizeof (str), "Ticks: %u", ticks);
+      gtk_label_set_text (label, str);
+    }
+
+  return TRUE;
+}
+
+static void
+maybe_quit (GMainLoop *loop)
+{
+  if (n_requests == 0 && g_main_loop_is_running (loop)) {
+    g_main_loop_quit (loop);
+  }
+}
+
+static void
+print_papers (GtkPrinter *printer)
+{
+  GList *list, *l;
+
+  g_print ("Printer \"%s\" has the following paper sizes:\n", gtk_printer_get_name (printer));
+
+  list = gtk_printer_list_papers (printer);
+  for (l = list; l != NULL; l = l->next)
+    {
+      GtkPageSetup *setup = l->data;
+      GtkPaperSize *size;
+
+      size = gtk_page_setup_get_paper_size (setup);
+
+      g_print ("  Paper size \"%s\" [\"%s\", %.2fmmx%.2fmm]\n",
+               gtk_paper_size_get_display_name (size),
+	       gtk_paper_size_get_name (size),
+	       gtk_paper_size_get_width (size, GTK_UNIT_MM),
+	       gtk_paper_size_get_height (size, GTK_UNIT_MM));
+    }
+
+  g_print ("\n");
+
+  g_list_foreach (list, (GFunc) g_object_unref, NULL);
+  g_list_free (list);
+}
+
+static void
+details_acquired_cb (GtkPrinter *printer,
+		     gboolean success,
+		     GMainLoop *loop)
+{
+  const gchar *name;
+
+  name = gtk_printer_get_name (printer);
+  if (success) {
+    g_print ("Printer \"%s\" details acquired\n", name);
+    print_papers (printer);
+  } else {
+    g_print ("Printer \"%s\" failed to acquire details\n", name);
+  }
+
+  g_object_unref (printer);
+
+  --n_requests;
+  maybe_quit (loop);
+}
+
+static gboolean
+printer_added_cb (GtkPrinter *printer,
+	       	  GMainLoop *loop)
+{
+  g_print ("Printer \"%s\" found (has-details: %s)\n\n",
+	   gtk_printer_get_name (printer),
+	   gtk_printer_has_details (printer) ? "true" : "false");
+
+  /* No need to acquire details */
+  if (!list_papers)
+    return FALSE; /* continue enumeration */
+
+  if (gtk_printer_has_details (printer)) {
+    print_papers (printer);
+  } else {
+    g_object_ref (printer);
+    g_signal_connect (printer, "details-acquired",
+		      G_CALLBACK (details_acquired_cb), loop);
+    
+    n_requests++;
+    gtk_printer_request_details (printer);			   
+  }
+
+  return FALSE; /* continue enumeration */
+}
+
+int
+main (int argc, char **argv)
+{
+  GMainLoop *loop = NULL;
+  GOptionContext *context;
+  GError *error = NULL;
+  gboolean retval;
+  gboolean with_ui = FALSE;
+  gboolean tick = FALSE;
+  gdouble tick_frequency = 4.0;
+  const GOptionEntry options[] =
+    {
+      { "paper-sizes", 's', 0, G_OPTION_ARG_NONE, &list_papers, "List paper sizes", NULL },
+      { "ui", 'u', 0, G_OPTION_ARG_NONE, &with_ui, "Show user interface", NULL },
+      { "tick", 't', 0, G_OPTION_ARG_NONE, &tick, "Regular events", NULL },
+      { "frequency", 'f', 0, G_OPTION_ARG_DOUBLE, &tick_frequency, "Event frequency (default: 4 Hz)", "FREQ" },
+      { NULL }
+    };
+
+  context = g_option_context_new ("- Enumerate printers");
+  g_option_context_add_main_entries (context, options, NULL);
+  g_option_context_add_group (context, gtk_get_option_group (TRUE));
+
+  retval = g_option_context_parse (context, &argc, &argv, &error);
+  g_option_context_free (context);
+  if (!retval)
+    {
+      g_print ("Error parsing arguments: %s\n", error->message);
+      g_error_free (error);
+      exit (1);
+    }
+
+  if (with_ui)
+    {
+      GtkWidget *window, *label;
+
+      window = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Message");
+      gtk_window_set_modal (GTK_WINDOW (window), FALSE);
+      gtk_window_present (GTK_WINDOW (window));
+
+      if (tick)
+        {
+          label = gtk_label_new (NULL);
+          gtk_box_pack_end (GTK_BOX (GTK_DIALOG (window)->vbox), label, FALSE, FALSE, 0);
+          gtk_widget_show (label);
+
+          g_timeout_add (1000.0 / tick_frequency, (GSourceFunc) tick_cb, label);
+        }
+    }
+  else if (tick)
+    {
+      g_timeout_add (1000.0 / tick_frequency, (GSourceFunc) tick_cb, NULL);
+    }
+
+  loop = g_main_loop_new (NULL, TRUE);
+
+  gtk_enumerate_printers ((GtkPrinterFunc) printer_added_cb,
+			  loop, (GDestroyNotify) maybe_quit, FALSE);
+
+  g_main_loop_run (loop);
+
+  g_assert (n_requests == 0);
+
+  g_main_loop_unref (loop);
+
+  return 0;
+}
