Support raw printers

svn path=/trunk/; revision=17568
This commit is contained in:
Matthias Clasen 2007-03-28 15:53:08 +00:00
parent 8a78c744e1
commit 0cd6108945
4 changed files with 148 additions and 24 deletions

View File

@ -1,3 +1,10 @@
2007-03-28 Matthias Clasen <mclasen@redhat.com>
* modules/printbackends/cups/gtkcupsutils.[hc]:
* modules/printbackends/cups/gtkprintbackendcups.c: Apply
a patch by John Palmieri to make the cups print backend support
raw printers.
2007-03-28 Kristian Rietveld <kris@imendio.com>
* gtk/gtkwidget.c (gtk_widget_set_tooltip_window): don't unref

View File

@ -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;
@ -78,14 +83,19 @@ static GtkCupsRequestStateFunc get_states[] = {
static void
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;
}
@ -718,6 +743,9 @@ _post_write_data (GtkCupsRequest *request)
request->poll_state = GTK_CUPS_HTTP_IDLE;
gtk_cups_result_set_error (request->result,
GTK_CUPS_ERROR_IO,
io_status,
error->code,
"Error reading from cache file: %s",
error->message);
@ -748,6 +776,9 @@ _post_write_data (GtkCupsRequest *request)
request->poll_state = GTK_CUPS_HTTP_IDLE;
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;
}
}
@ -835,6 +876,9 @@ _post_check (GtkCupsRequest *request)
{
request->state = GTK_CUPS_POST_DONE;
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;
@ -912,7 +961,11 @@ _get_send (GtkCupsRequest *request)
if (request->data_io == NULL)
{
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;
@ -931,7 +984,12 @@ _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++;
@ -969,7 +1027,12 @@ _get_check (GtkCupsRequest *request)
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 */
@ -1001,6 +1064,9 @@ _get_check (GtkCupsRequest *request)
{
request->state = GTK_CUPS_GET_DONE;
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)
{

View File

@ -31,6 +31,14 @@ G_BEGIN_DECLS
typedef struct _GtkCupsRequest GtkCupsRequest;
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,
@ -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

View File

@ -579,7 +579,14 @@ 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);
@ -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;
}