#include <gtk/gtk.h>
#include <gtk/gtkunixprint.h>

GList *printers;

static gboolean
enumerate_printer_cb (GtkPrinter *printer,
                      gpointer    data)
{
        printers = g_list_prepend (printers, g_object_ref (printer));
        return FALSE;
}

static gpointer
enumerate_printers_thread (gpointer data)
{
        GMainLoop *loop;
        GMainContext *context;

        context = g_main_context_new ();
        g_main_context_push_thread_default (context);
        loop = g_main_loop_new (context, TRUE);

        gtk_enumerate_printers (enumerate_printer_cb,
                                loop,
                                (GDestroyNotify)g_main_loop_quit,
                                FALSE);
        g_main_loop_run (loop);

        g_main_loop_unref (loop);
        g_main_context_unref (context);

        return NULL;
}

gint main (gint argc, gchar **argv)
{
        GList *l;

        g_thread_join(g_thread_new("Enumerate Printers",
                                   enumerate_printers_thread, NULL));

        for (l = printers; l; l = g_list_next (l)) {
                GtkPrinter *printer = (GtkPrinter *)l->data;

                g_print ("Found Printer: %s\n", gtk_printer_get_name (printer));
                g_object_unref (printer);
        }

        g_list_free (printers);

        return 0;
}
