diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2007-03-28 15:53:08 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2007-03-28 15:53:08 +0000 |
commit | 0cd610894556406cc879bcb63161741b810728f6 (patch) | |
tree | f6e23abaaf1f098dcb8b0faf83f26b076a8ac74d /modules | |
parent | 8a78c744e10a9b4eb1702fba76fdbf3112a063fa (diff) | |
download | gdk-pixbuf-0cd610894556406cc879bcb63161741b810728f6.tar.gz |
Support raw printers
svn path=/trunk/; revision=17568
Diffstat (limited to 'modules')
-rw-r--r-- | modules/printbackends/cups/gtkcupsutils.c | 130 | ||||
-rw-r--r-- | modules/printbackends/cups/gtkcupsutils.h | 11 | ||||
-rw-r--r-- | modules/printbackends/cups/gtkprintbackendcups.c | 24 |
3 files changed, 141 insertions, 24 deletions
diff --git a/modules/printbackends/cups/gtkcupsutils.c b/modules/printbackends/cups/gtkcupsutils.c index eb5442c2a..e11c86529 100644 --- a/modules/printbackends/cups/gtkcupsutils.c +++ b/modules/printbackends/cups/gtkcupsutils.c @@ -51,6 +51,11 @@ struct _GtkCupsResult { gchar *error_msg; ipp_t *ipp_response; + GtkCupsErrorType error_type; + + /* some error types like HTTP_ERROR have a status and a code */ + int error_status; + int error_code; guint is_error : 1; guint is_ipp_response : 1; @@ -77,15 +82,20 @@ static GtkCupsRequestStateFunc get_states[] = { }; static void -gtk_cups_result_set_error (GtkCupsResult *result, - const char *error_msg, +gtk_cups_result_set_error (GtkCupsResult *result, + GtkCupsErrorType error_type, + int error_status, + int error_code, + const char *error_msg, ...) { va_list args; result->is_ipp_response = FALSE; - result->is_error = TRUE; + result->error_type = error_type; + result->error_status = error_status; + result->error_code = error_code; va_start (args, error_msg); result->error_msg = g_strdup_vprintf (error_msg, args); @@ -214,7 +224,13 @@ gtk_cups_request_read_write (GtkCupsRequest *request) if (request->attempts > _GTK_CUPS_MAX_ATTEMPTS && request->state != GTK_CUPS_REQUEST_DONE) { - gtk_cups_result_set_error (request->result, "Too many failed attempts"); + /* TODO: should add a status or error code for too many failed attempts */ + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_GENERAL, + 0, + 0, + "Too many failed attempts"); + request->state = GTK_CUPS_REQUEST_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; } @@ -629,7 +645,12 @@ _post_send (GtkCupsRequest *request) request->state = GTK_CUPS_POST_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; - gtk_cups_result_set_error (request->result, "Failed Post"); + /* TODO: should add a status or error code for failed post */ + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_GENERAL, + 0, + 0, + "Failed Post"); } request->attempts++; @@ -656,12 +677,16 @@ _post_write_request (GtkCupsRequest *request) if (ipp_status == IPP_ERROR) { + int cups_error = cupsLastError (); request->state = GTK_CUPS_POST_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_IPP, + ipp_status, + cups_error, "%s", - ippErrorString (cupsLastError ())); + ippErrorString (cups_error)); return; } @@ -717,7 +742,10 @@ _post_write_data (GtkCupsRequest *request) request->state = GTK_CUPS_POST_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; - gtk_cups_result_set_error (request->result, + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_IO, + io_status, + error->code, "Error reading from cache file: %s", error->message); @@ -747,7 +775,10 @@ _post_write_data (GtkCupsRequest *request) request->state = GTK_CUPS_POST_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; - gtk_cups_result_set_error (request->result, + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_HTTP, + http_status, + http_errno, "Error writing to socket in Post %s", g_strerror (http_errno)); return; @@ -782,7 +813,12 @@ _post_check (GtkCupsRequest *request) request->state = GTK_CUPS_POST_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; - gtk_cups_result_set_error (request->result, "Can't prompt for authorization"); + /* TODO: create a not implemented error code */ + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_GENERAL, + 0, + 0, + "Can't prompt for authorization"); return; } else if (http_status == HTTP_ERROR) @@ -802,7 +838,12 @@ _post_check (GtkCupsRequest *request) request->state = GTK_CUPS_POST_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; - gtk_cups_result_set_error (request->result, "Unknown HTTP error"); + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_HTTP, + http_status, + error, + "Unknown HTTP error"); + return; } } @@ -834,7 +875,10 @@ _post_check (GtkCupsRequest *request) else { request->state = GTK_CUPS_POST_DONE; - gtk_cups_result_set_error (request->result, + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_HTTP, + http_status, + http_errno, "HTTP Error in POST %s", g_strerror (http_errno)); request->poll_state = GTK_CUPS_HTTP_IDLE; @@ -885,8 +929,13 @@ _post_read_response (GtkCupsRequest *request) if (ipp_status == IPP_ERROR) { - gtk_cups_result_set_error (request->result, "%s", - ippErrorString (cupsLastError ())); + int ipp_error = cupsLastError (); + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_IPP, + ipp_status, + ipp_error, + "%s", + ippErrorString (ipp_error)); ippDelete (request->result->ipp_response); request->result->ipp_response = NULL; @@ -911,8 +960,12 @@ _get_send (GtkCupsRequest *request) if (request->data_io == NULL) { - gtk_cups_result_set_error (request->result, + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_IO, + G_IO_STATUS_ERROR, + G_IO_CHANNEL_ERROR_FAILED, "Get requires an open io channel"); + request->state = GTK_CUPS_GET_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; @@ -930,8 +983,13 @@ _get_send (GtkCupsRequest *request) { request->state = GTK_CUPS_GET_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; - - gtk_cups_result_set_error (request->result, "Failed Get"); + + /* TODO: should add a status or error code for failed GET */ + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_GENERAL, + 0, + 0, + "Failed Get"); } request->attempts++; @@ -968,8 +1026,13 @@ _get_check (GtkCupsRequest *request) g_warning ("NOT IMPLEMENTED: We need to prompt for authorization in a non blocking manner"); request->state = GTK_CUPS_GET_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; - - gtk_cups_result_set_error (request->result, "Can't prompt for authorization"); + + /* TODO: should add a status or error code for not implemented */ + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_GENERAL, + 0, + 0, + "Can't prompt for authorization"); return; } /* TODO: detect ssl in configure.ac */ @@ -988,7 +1051,7 @@ _get_check (GtkCupsRequest *request) request->attempts++; goto again; } -#endif +#endif else if (http_status != HTTP_OK) { int http_errno; @@ -1000,7 +1063,10 @@ _get_check (GtkCupsRequest *request) else { request->state = GTK_CUPS_GET_DONE; - gtk_cups_result_set_error (request->result, + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_HTTP, + http_status, + http_errno, "HTTP Error in GET %s", g_strerror (http_errno)); request->poll_state = GTK_CUPS_HTTP_IDLE; @@ -1078,7 +1144,11 @@ _get_read_data (GtkCupsRequest *request) request->state = GTK_CUPS_POST_DONE; request->poll_state = GTK_CUPS_HTTP_IDLE; - gtk_cups_result_set_error (request->result, error->message); + gtk_cups_result_set_error (request->result, + GTK_CUPS_ERROR_IO, + io_status, + error->code, + error->message); g_error_free (error); } } @@ -1101,6 +1171,24 @@ gtk_cups_result_get_response (GtkCupsResult *result) return result->ipp_response; } +GtkCupsErrorType +gtk_cups_result_get_error_type (GtkCupsResult *result) +{ + return result->error_type; +} + +int +gtk_cups_result_get_error_status (GtkCupsResult *result) +{ + return result->error_status; +} + +int +gtk_cups_result_get_error_code (GtkCupsResult *result) +{ + return result->error_code; +} + const char * gtk_cups_result_get_error_string (GtkCupsResult *result) { diff --git a/modules/printbackends/cups/gtkcupsutils.h b/modules/printbackends/cups/gtkcupsutils.h index d759459ae..6ea80e78d 100644 --- a/modules/printbackends/cups/gtkcupsutils.h +++ b/modules/printbackends/cups/gtkcupsutils.h @@ -33,6 +33,14 @@ typedef struct _GtkCupsResult GtkCupsResult; typedef enum { + GTK_CUPS_ERROR_HTTP, + GTK_CUPS_ERROR_IPP, + GTK_CUPS_ERROR_IO, + GTK_CUPS_ERROR_GENERAL +} GtkCupsErrorType; + +typedef enum +{ GTK_CUPS_POST, GTK_CUPS_GET } GtkCupsRequestType; @@ -126,6 +134,9 @@ void gtk_cups_request_encode_option (GtkCupsRequest *request, const gchar *value); gboolean gtk_cups_result_is_error (GtkCupsResult *result); ipp_t * gtk_cups_result_get_response (GtkCupsResult *result); +GtkCupsErrorType gtk_cups_result_get_error_type (GtkCupsResult *result); +int gtk_cups_result_get_error_status (GtkCupsResult *result); +int gtk_cups_result_get_error_code (GtkCupsResult *result); const char * gtk_cups_result_get_error_string (GtkCupsResult *result); G_END_DECLS diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c index dfc749f21..2d6de7763 100644 --- a/modules/printbackends/cups/gtkprintbackendcups.c +++ b/modules/printbackends/cups/gtkprintbackendcups.c @@ -579,10 +579,17 @@ cups_dispatch_watch_dispatch (GSource *source, g_print ("CUPS Backend: %s <source %p>\n", G_STRFUNC, source)); if (gtk_cups_result_is_error (result)) - g_warning ("Error result: %s", gtk_cups_result_get_error_string (result)); + { + GTK_NOTE (PRINTING, + g_print("Error result: %s (type %i, status %i, code %i)\n", + gtk_cups_result_get_error_string (result), + gtk_cups_result_get_error_type (result), + gtk_cups_result_get_error_status (result), + gtk_cups_result_get_error_code (result))); + } ep_callback (GTK_PRINT_BACKEND (dispatch->backend), result, user_data); - + return FALSE; } @@ -1236,7 +1243,18 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend, if (gtk_cups_result_is_error (result)) { - g_signal_emit_by_name (printer, "details-acquired", FALSE); + gboolean success = FALSE; + + /* if we get a 404 then it is just a raw printer without a ppd + and not an error */ + if ((gtk_cups_result_get_error_type (result) == GTK_CUPS_ERROR_HTTP) && + (gtk_cups_result_get_error_status (result) == HTTP_NOT_FOUND)) + { + gtk_printer_set_has_details (printer, TRUE); + success = TRUE; + } + + g_signal_emit_by_name (printer, "details-acquired", success); return; } |