Hi, Since retrieval of printer attributes when gnome_cups_printer_get is called is now asynchronous, this poses a problem - callers don't know when the attributes (description, URI, etc) are valid. The attached patch adds an API method to know when the attributes have been set for the first time. What we do inside eggcups when a new printer is detected is call gnome_cups_printer_get, attach to its attributes-changed callback, and at that point we know the attributes are valid (in particular the URI). The new method gnome_cups_printer_get_attributes_initialized is used for sanity checks. This patch also changes the API for gnome_cups_request_new_for_printer. It used to take a printer name, but we've changed it to take a real GnomeCupsPrinter object, since that's the only way we can discover the URI for the printer. I'm pretty sure this is the right change because it simplifies all of the callers. I'm not sure if there are even any external callers of gnome_cups_request_new_for_printer, so the API change shouldn't be a problem. We also moved gnome_cups_get_printer_uri back into utils.c, where it makes more sense now I think.
? libgnomecups-0.1.6.tar.gz cvs server: Diffing . cvs server: Diffing libgnomecups Index: libgnomecups/gnome-cups-printer.c =================================================================== RCS file: /cvs/gnome/libgnomecups/libgnomecups/gnome-cups-printer.c,v retrieving revision 1.22 diff -u -r1.22 gnome-cups-printer.c --- libgnomecups/gnome-cups-printer.c 11 Aug 2004 16:41:35 -0000 1.22 +++ libgnomecups/gnome-cups-printer.c 11 Aug 2004 17:21:39 -0000 @@ -42,6 +42,7 @@ struct _GnomeCupsPrinterDetails { char *printer_name; + guint attributes_set : 1; guint is_default : 1; guint is_gone : 1; guint is_local : 1; @@ -259,6 +260,8 @@ ippDelete (response); g_clear_error (error); + printer->details->attributes_set = 1; + if (changed) { g_free (printer->details->full_state); printer->details->full_state = NULL; @@ -290,7 +293,7 @@ } request = gnome_cups_request_new_for_printer (IPP_GET_PRINTER_ATTRIBUTES, - printer->details->printer_name); + printer); gnome_cups_request_add_requested_attributes (request, IPP_TAG_OPERATION, @@ -674,10 +677,15 @@ GError *error = NULL; ipp_t *request; ipp_t *response; + char *printer_uri; - request = gnome_cups_request_new_for_printer (IPP_GET_PRINTER_ATTRIBUTES, - printer); + request = gnome_cups_request_new (IPP_GET_PRINTER_ATTRIBUTES); + + printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", printer); + ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI, + "printer-uri", NULL, printer_uri); response = gnome_cups_request_execute (request, NULL, "/", &error); + g_free (printer_uri); ippDelete (response); @@ -748,6 +756,12 @@ } gboolean +gnome_cups_printer_get_attributes_initialized (GnomeCupsPrinter *printer) +{ + return printer->details->attributes_set; +} + +gboolean gnome_cups_printer_get_is_local (GnomeCupsPrinter *printer) { return (printer->details->device_uri != NULL) && @@ -843,6 +857,12 @@ return ppd; } +const char * +gnome_cups_printer_get_uri (GnomeCupsPrinter *printer) +{ + return printer->details->printer_uri; +} + const char * gnome_cups_printer_get_description (GnomeCupsPrinter *printer) { @@ -869,7 +889,7 @@ } request = gnome_cups_request_new_for_printer (CUPS_ADD_PRINTER, - printer->details->printer_name); + printer); ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", NULL, description); response = gnome_cups_request_execute (request, NULL, "/admin/", error); @@ -901,7 +921,7 @@ } request = gnome_cups_request_new_for_printer (CUPS_ADD_PRINTER, - printer->details->printer_name); + printer); ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", NULL, location); response = gnome_cups_request_execute (request, NULL, "/admin/", error); @@ -919,7 +939,7 @@ g_return_if_fail (GNOME_CUPS_IS_PRINTER (printer)); request = gnome_cups_request_new_for_printer (IPP_PAUSE_PRINTER, - printer->details->printer_name); + printer); response = gnome_cups_request_execute (request, NULL, "/admin/", error); ippDelete (response); update_attributes (printer); @@ -935,7 +955,7 @@ g_return_if_fail (GNOME_CUPS_IS_PRINTER (printer)); request = gnome_cups_request_new_for_printer (IPP_RESUME_PRINTER, - printer->details->printer_name); + printer); response = gnome_cups_request_execute (request, NULL, "/admin/", error); ippDelete (response); update_attributes (printer); @@ -951,7 +971,7 @@ g_return_if_fail (GNOME_CUPS_IS_PRINTER (printer)); request = gnome_cups_request_new_for_printer (CUPS_DELETE_PRINTER, - printer->details->printer_name); + printer); response = gnome_cups_request_execute (request, NULL, "/admin/", error); ippDelete (response); } @@ -1571,26 +1591,4 @@ } return host; -} - -char * -gnome_cups_get_printer_uri (const char *printer_name) -{ - char *uri; - GnomeCupsPrinter *printer; - - if (printer_name) { - printer = gnome_cups_printer_get_existing (printer_name); - if (printer && printer->details->printer_uri) - uri = g_strdup (printer->details->printer_uri); - else - uri = g_strdup_printf ("ipp://localhost/printers/%s", - printer_name); - if (printer) - g_object_unref (printer); - } else { - uri = g_strdup_printf ("ipp://localhost/printers/"); - } - - return uri; } Index: libgnomecups/gnome-cups-printer.h =================================================================== RCS file: /cvs/gnome/libgnomecups/libgnomecups/gnome-cups-printer.h,v retrieving revision 1.9 diff -u -r1.9 gnome-cups-printer.h --- libgnomecups/gnome-cups-printer.h 11 Aug 2004 16:41:35 -0000 1.9 +++ libgnomecups/gnome-cups-printer.h 11 Aug 2004 17:21:39 -0000 @@ -103,8 +103,11 @@ const char * gnome_cups_printer_get_name (GnomeCupsPrinter *printer); gboolean gnome_cups_printer_is_gone (GnomeCupsPrinter *printer); +gboolean gnome_cups_printer_get_attributes_initialized (GnomeCupsPrinter *printer); /* Status and attributes */ + +const char * gnome_cups_printer_get_uri (GnomeCupsPrinter *printer); ipp_pstate_t gnome_cups_printer_get_state (GnomeCupsPrinter *printer); const char * gnome_cups_printer_get_state_name (GnomeCupsPrinter *printer); Index: libgnomecups/gnome-cups-queue.c =================================================================== RCS file: /cvs/gnome/libgnomecups/libgnomecups/gnome-cups-queue.c,v retrieving revision 1.13 diff -u -r1.13 gnome-cups-queue.c --- libgnomecups/gnome-cups-queue.c 21 Jun 2004 15:37:43 -0000 1.13 +++ libgnomecups/gnome-cups-queue.c 11 Aug 2004 17:21:39 -0000 @@ -298,14 +298,19 @@ { ipp_t *request; const char *printer_name; + GnomeCupsPrinter *printer; if (queue->details->get_jobs_request_id > 0) return; printer_name = queue->details->queue_name; + printer = gnome_cups_printer_get_existing (printer_name); + g_return_if_fail (printer != NULL); request = gnome_cups_request_new_for_printer (IPP_GET_JOBS, - printer_name); + printer); + g_object_unref (printer); + queue->details->get_jobs_request_id = gnome_cups_request_execute_async (request, server, "/", get_jobs_cb, @@ -559,24 +564,16 @@ } static gboolean -check_exists (const char *queue) +check_exists (const char *name) { - GError *error = NULL; - ipp_t *request; - ipp_t *response; - - request = gnome_cups_request_new_for_printer (IPP_GET_PRINTER_ATTRIBUTES, - queue); - response = gnome_cups_request_execute (request, NULL, "/", &error); + gboolean exists; + GnomeCupsPrinter *printer; - ippDelete (response); + printer = gnome_cups_printer_get (name); + exists = printer != NULL; + g_object_unref (printer); - if (error) { - g_error_free (error); - return FALSE; - } else { - return TRUE; - } + return exists; } GnomeCupsQueue * Index: libgnomecups/gnome-cups-request.c =================================================================== RCS file: /cvs/gnome/libgnomecups/libgnomecups/gnome-cups-request.c,v retrieving revision 1.13 diff -u -r1.13 gnome-cups-request.c --- libgnomecups/gnome-cups-request.c 21 Jun 2004 15:37:43 -0000 1.13 +++ libgnomecups/gnome-cups-request.c 11 Aug 2004 17:21:39 -0000 @@ -10,6 +10,7 @@ #include "gnome-cups-util.h" #include "gnome-cups-i18n.h" +#include "gnome-cups-printer.h" /* Arbitrary. */ #define MAX_REQUEST_THREADS 10 @@ -397,14 +398,19 @@ ipp_t * gnome_cups_request_new_for_printer (int operation_id, - const char *printer_name) + GnomeCupsPrinter *printer) { ipp_t *request; char *printer_uri; + g_return_val_if_fail (!gnome_cups_printer_get_attributes_initialized (printer), NULL); + + printer_uri = g_strdup (gnome_cups_printer_get_uri (printer)); + if (!printer_uri) + printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", + gnome_cups_printer_get_name (printer)); request = gnome_cups_request_new (operation_id); - printer_uri = gnome_cups_get_printer_uri (printer_name); ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer_uri); g_free (printer_uri); Index: libgnomecups/gnome-cups-request.h =================================================================== RCS file: /cvs/gnome/libgnomecups/libgnomecups/gnome-cups-request.h,v retrieving revision 1.7 diff -u -r1.7 gnome-cups-request.h --- libgnomecups/gnome-cups-request.h 23 Jun 2004 17:07:02 -0000 1.7 +++ libgnomecups/gnome-cups-request.h 11 Aug 2004 17:21:39 -0000 @@ -4,6 +4,7 @@ #include <cups/ipp.h> #include <glib.h> #include "gnome-cups-init.h" +#include "gnome-cups-printer.h" typedef void (*GnomeCupsAsyncRequestCallback) (guint id, const char *path, @@ -13,7 +14,7 @@ ipp_t *gnome_cups_request_new (int operation_id); ipp_t *gnome_cups_request_new_for_printer (int operation_id, - const char *printer_name); + GnomeCupsPrinter *printer); ipp_t *gnome_cups_request_new_for_job (int operation_id, int job_id); void gnome_cups_request_add_requested_attributes (ipp_t *request, Index: libgnomecups/gnome-cups-util.c =================================================================== RCS file: /cvs/gnome/libgnomecups/libgnomecups/gnome-cups-util.c,v retrieving revision 1.3 diff -u -r1.3 gnome-cups-util.c --- libgnomecups/gnome-cups-util.c 17 Jun 2004 17:21:03 -0000 1.3 +++ libgnomecups/gnome-cups-util.c 11 Aug 2004 17:21:39 -0000 @@ -33,4 +33,20 @@ return quark; } +char * +gnome_cups_get_printer_uri (const char *printer_name) +{ + char *uri; + GnomeCupsPrinter *printer; + if (printer_name) { + printer = gnome_cups_printer_get_existing (printer_name); + uri = gnome_cups_printer_get_uri (printer); + g_object_unref (printer); + return g_strdup (uri); + } else { + uri = g_strdup_printf ("ipp://localhost/printers/"); + } + + return uri; +} cvs server: Diffing po
Attachment:
signature.asc
Description: This is a digitally signed message part