GtkCupsRequest *request;
GPollFD *data_poll;
GtkPrintBackendCups *backend;
+ GtkPrintCupsResponseCallbackFunc callback;
+ gpointer callback_data;
} GtkPrintCupsDispatchWatch;
guint list_printers_poll;
guint list_printers_pending : 1;
+ gint list_printers_attempts;
guint got_default_printer : 1;
guint default_printer_poll;
GtkCupsConnectionTest *cups_connection_test;
+ gint reading_ppds;
char **covers;
int number_of_covers;
static GtkPageSetup * cups_printer_get_default_page_size (GtkPrinter *printer);
static void cups_printer_request_details (GtkPrinter *printer);
static gboolean cups_request_default_printer (GtkPrintBackendCups *print_backend);
-static void cups_request_ppd (GtkPrinter *printer);
-static void cups_printer_get_hard_margins (GtkPrinter *printer,
- double *top,
- double *bottom,
- double *left,
- double *right);
+static gboolean cups_request_ppd (GtkPrinter *printer);
+static gboolean cups_printer_get_hard_margins (GtkPrinter *printer,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right);
static GtkPrintCapabilities cups_printer_get_capabilities (GtkPrinter *printer);
static void set_option_from_settings (GtkPrinterOption *option,
GtkPrintSettings *setting);
gdouble height,
GIOChannel *cache_io);
-static void gtk_print_backend_cups_set_password (GtkPrintBackend *backend,
- const gchar *hostname,
- const gchar *username,
- const gchar *password);
+static void gtk_print_backend_cups_set_password (GtkPrintBackend *backend,
+ gchar **auth_info_required,
+ gchar **auth_info);
-void overwrite_and_free (gpointer data);
-static gboolean is_address_local (const gchar *address);
+void overwrite_and_free (gpointer data);
+static gboolean is_address_local (const gchar *address);
+static gboolean request_auth_info (gpointer data);
static void
gtk_print_backend_cups_register_type (GTypeModule *module)
{
- static const GTypeInfo print_backend_cups_info =
+ const GTypeInfo print_backend_cups_info =
{
sizeof (GtkPrintBackendCupsClass),
NULL, /* base_init */
}
GTK_NOTE (PRINTING,
- g_print ("CUPS Backend: Wrote %i bytes to temp file\n", written));
+ g_print ("CUPS Backend: Wrote %"G_GSIZE_FORMAT" bytes to temp file\n", written));
data += written;
length -= written;
gdouble height,
GIOChannel *cache_io)
{
- cairo_surface_t *surface;
+ cairo_surface_t *surface;
ppd_file_t *ppd_file = NULL;
ppd_attr_t *ppd_attr = NULL;
ppd_attr_t *ppd_attr_res = NULL;
ppd_attr_t *ppd_attr_screen_freq = NULL;
ppd_attr_t *ppd_attr_res_screen_freq = NULL;
gchar *res_string = NULL;
- int level = 2;
-
- /* TODO: check if it is a ps or pdf printer */
-
- surface = cairo_ps_surface_create_for_stream (_cairo_write_to_cups, cache_io, width, height);
+ gint level = 2;
+
+ if (gtk_printer_accepts_pdf (printer))
+ surface = cairo_pdf_surface_create_for_stream (_cairo_write_to_cups, cache_io, width, height);
+ else
+ surface = cairo_ps_surface_create_for_stream (_cairo_write_to_cups, cache_io, width, height);
ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
}
}
- res_string = g_strdup_printf ("%ddpi",
+ res_string = g_strdup_printf ("%ddpi",
gtk_print_settings_get_resolution (settings));
ppd_attr_res_screen_freq = ppdFindAttr (ppd_file, "ResScreenFreq", res_string);
g_free (res_string);
if (ppd_attr_res_screen_freq == NULL)
{
- res_string = g_strdup_printf ("%dx%ddpi",
+ res_string = g_strdup_printf ("%dx%ddpi",
gtk_print_settings_get_resolution_x (settings),
gtk_print_settings_get_resolution_y (settings));
ppd_attr_res_screen_freq = ppdFindAttr (ppd_file, "ResScreenFreq", res_string);
gtk_print_settings_set_printer_lpi (settings, atof (ppd_attr_screen_freq->value));
}
- if (level == 2)
- cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
+ if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_PS)
+ {
+ if (level == 2)
+ cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
- if (level == 3)
- cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_3);
+ if (level == 3)
+ cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_3);
+ }
cairo_surface_set_fallback_resolution (surface,
2.0 * gtk_print_settings_get_printer_lpi (settings),
ps->dnotify = dnotify;
ps->job = g_object_ref (job);
+ request->need_auth_info = cups_printer->auth_info_required != NULL;
+ request->auth_info_required = g_strdupv (cups_printer->auth_info_required);
+
cups_request_execute (GTK_PRINT_BACKEND_CUPS (print_backend),
request,
(GtkPrintCupsResponseCallbackFunc) cups_print_cb,
backend_cups->list_printers_poll = FALSE;
backend_cups->got_default_printer = FALSE;
backend_cups->list_printers_pending = FALSE;
+ backend_cups->list_printers_attempts = 0;
+ backend_cups->reading_ppds = 0;
backend_cups->requests = NULL;
backend_cups->auth = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, overwrite_and_free);
if (backend_cups->list_printers_poll > 0)
g_source_remove (backend_cups->list_printers_poll);
backend_cups->list_printers_poll = 0;
+ backend_cups->list_printers_attempts = 0;
if (backend_cups->default_printer_poll > 0)
g_source_remove (backend_cups->default_printer_poll);
return FALSE;
}
+#ifndef HAVE_CUPS_API_1_2
+/* Included from CUPS library because of backward compatibility */
+const char *
+httpGetHostname(http_t *http,
+ char *s,
+ int slen)
+{
+ struct hostent *host;
+
+ if (!s || slen <= 1)
+ return (NULL);
+
+ if (http)
+ {
+ if (http->hostname[0] == '/')
+ g_strlcpy (s, "localhost", slen);
+ else
+ g_strlcpy (s, http->hostname, slen);
+ }
+ else
+ {
+ if (gethostname (s, slen) < 0)
+ g_strlcpy (s, "localhost", slen);
+
+ if (!strchr (s, '.'))
+ {
+ if ((host = gethostbyname (s)) != NULL && host->h_name)
+ g_strlcpy (s, host->h_name, slen);
+ }
+ }
+ return (s);
+}
+#endif
+
static void
-gtk_print_backend_cups_set_password (GtkPrintBackend *backend,
- const gchar *hostname,
- const gchar *username,
- const gchar *password)
+gtk_print_backend_cups_set_password (GtkPrintBackend *backend,
+ gchar **auth_info_required,
+ gchar **auth_info)
{
GtkPrintBackendCups *cups_backend = GTK_PRINT_BACKEND_CUPS (backend);
GList *l;
char dispatch_hostname[HTTP_MAX_URI];
- gchar *key;
+ gchar *username = NULL;
+ gchar *hostname = NULL;
+ gchar *password = NULL;
+ gint length;
+ gint i;
- key = g_strconcat (username, "@", hostname, NULL);
- g_hash_table_insert (cups_backend->auth, key, g_strdup (password));
+ length = g_strv_length (auth_info_required);
+
+ if (auth_info != NULL)
+ for (i = 0; i < length; i++)
+ {
+ if (g_strcmp0 (auth_info_required[i], "username") == 0)
+ username = g_strdup (auth_info[i]);
+ else if (g_strcmp0 (auth_info_required[i], "hostname") == 0)
+ hostname = g_strdup (auth_info[i]);
+ else if (g_strcmp0 (auth_info_required[i], "password") == 0)
+ password = g_strdup (auth_info[i]);
+ }
+
+ if (hostname != NULL && username != NULL && password != NULL)
+ {
+ gchar *key = g_strconcat (username, "@", hostname, NULL);
+ g_hash_table_insert (cups_backend->auth, key, g_strdup (password));
+ GTK_NOTE (PRINTING,
+ g_print ("CUPS backend: storing password for %s\n", key));
+ }
g_free (cups_backend->username);
cups_backend->username = g_strdup (username);
- GTK_NOTE (PRINTING,
- g_print ("CUPS backend: storing password for %s\n", key));
for (l = cups_backend->requests; l; l = l->next)
{
if (is_address_local (dispatch_hostname))
strcpy (dispatch_hostname, "localhost");
- if (strcmp (hostname, dispatch_hostname) == 0)
+ if (dispatch->request->need_auth_info)
+ {
+ if (auth_info != NULL)
+ {
+ dispatch->request->auth_info = g_new0 (gchar *, length + 1);
+ for (i = 0; i < length; i++)
+ dispatch->request->auth_info[i] = g_strdup (auth_info[i]);
+ }
+ dispatch->backend->authentication_lock = FALSE;
+ dispatch->request->need_auth_info = FALSE;
+ }
+ else if (dispatch->request->password_state == GTK_CUPS_PASSWORD_REQUESTED || auth_info == NULL)
{
overwrite_and_free (dispatch->request->password);
dispatch->request->password = g_strdup (password);
gchar *prompt = NULL;
gchar *key = NULL;
char hostname[HTTP_MAX_URI];
+ gchar **auth_info_required;
+ gchar **auth_info_default;
+ gchar **auth_info_display;
+ gboolean *auth_info_visible;
+ gint length = 3;
+ gint i;
if (dispatch->backend->authentication_lock)
return FALSE;
else
username = cupsUser ();
+ auth_info_required = g_new0 (gchar*, length + 1);
+ auth_info_required[0] = g_strdup ("hostname");
+ auth_info_required[1] = g_strdup ("username");
+ auth_info_required[2] = g_strdup ("password");
+
+ auth_info_default = g_new0 (gchar*, length + 1);
+ auth_info_default[0] = g_strdup (hostname);
+ auth_info_default[1] = g_strdup (username);
+
+ auth_info_display = g_new0 (gchar*, length + 1);
+ auth_info_display[1] = g_strdup (_("Username:"));
+ auth_info_display[2] = g_strdup (_("Password:"));
+
+ auth_info_visible = g_new0 (gboolean, length + 1);
+ auth_info_visible[1] = TRUE;
+
key = g_strconcat (username, "@", hostname, NULL);
password = g_hash_table_lookup (dispatch->backend->auth, key);
switch (dispatch->request->ipp_request->request.op.operation_id)
{
- case 0:
- prompt = g_strdup_printf ( _("Authentication is required to get a file from %s"), hostname);
- break;
case IPP_PRINT_JOB:
if (job_title != NULL && printer_name != NULL)
prompt = g_strdup_printf ( _("Authentication is required to print document '%s' on printer %s"), job_title, printer_name);
prompt = g_strdup_printf ( _("Authentication is required to get printers from %s"), hostname);
break;
default:
- prompt = g_strdup_printf ( _("Authentication is required on %s"), hostname);
+ /* work around gcc warning about 0 not being a value for this enum */
+ if (dispatch->request->ipp_request->request.op.operation_id == 0)
+ prompt = g_strdup_printf ( _("Authentication is required to get a file from %s"), hostname);
+ else
+ prompt = g_strdup_printf ( _("Authentication is required on %s"), hostname);
break;
}
g_free (printer_name);
g_signal_emit_by_name (dispatch->backend, "request-password",
- hostname, username, prompt);
+ auth_info_required, auth_info_default, auth_info_display, auth_info_visible, prompt);
g_free (prompt);
}
+ for (i = 0; i < length; i++)
+ {
+ g_free (auth_info_required[i]);
+ g_free (auth_info_default[i]);
+ g_free (auth_info_display[i]);
+ }
+
+ g_free (auth_info_required);
+ g_free (auth_info_default);
+ g_free (auth_info_display);
+ g_free (auth_info_visible);
g_free (key);
return FALSE;
}
}
+static gboolean
+check_auth_info (gpointer user_data)
+{
+ GtkPrintCupsDispatchWatch *dispatch;
+ dispatch = (GtkPrintCupsDispatchWatch *) user_data;
+
+ if (!dispatch->request->need_auth_info)
+ {
+ if (dispatch->request->auth_info == NULL)
+ {
+ dispatch->callback (GTK_PRINT_BACKEND (dispatch->backend),
+ gtk_cups_request_get_result (dispatch->request),
+ dispatch->callback_data);
+ g_source_destroy ((GSource *) dispatch);
+ }
+ else
+ {
+ gint length;
+ gint i;
+
+ length = g_strv_length (dispatch->request->auth_info_required);
+
+ gtk_cups_request_ipp_add_strings (dispatch->request,
+ IPP_TAG_JOB,
+ IPP_TAG_TEXT,
+ "auth-info",
+ length,
+ NULL,
+ (const char * const *) dispatch->request->auth_info);
+
+ g_source_attach ((GSource *) dispatch, NULL);
+ g_source_unref ((GSource *) dispatch);
+
+ for (i = 0; i < length; i++)
+ overwrite_and_free (dispatch->request->auth_info[i]);
+ g_free (dispatch->request->auth_info);
+ dispatch->request->auth_info = NULL;
+ }
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+request_auth_info (gpointer user_data)
+{
+ GtkPrintCupsDispatchWatch *dispatch;
+ const char *job_title;
+ const char *printer_uri;
+ gchar *prompt = NULL;
+ char *printer_name = NULL;
+ gint length;
+ gint i;
+ gboolean *auth_info_visible = NULL;
+ gchar **auth_info_default = NULL;
+ gchar **auth_info_display = NULL;
+
+ dispatch = (GtkPrintCupsDispatchWatch *) user_data;
+
+ if (dispatch->backend->authentication_lock)
+ return FALSE;
+
+ job_title = gtk_cups_request_ipp_get_string (dispatch->request, IPP_TAG_NAME, "job-name");
+ printer_uri = gtk_cups_request_ipp_get_string (dispatch->request, IPP_TAG_URI, "printer-uri");
+ length = g_strv_length (dispatch->request->auth_info_required);
+
+ auth_info_visible = g_new0 (gboolean, length);
+ auth_info_default = g_new0 (gchar *, length + 1);
+ auth_info_display = g_new0 (gchar *, length + 1);
+
+ for (i = 0; i < length; i++)
+ {
+ if (g_strcmp0 (dispatch->request->auth_info_required[i], "domain") == 0)
+ {
+ auth_info_display[i] = g_strdup (_("Domain:"));
+ auth_info_default[i] = g_strdup ("WORKGROUP");
+ auth_info_visible[i] = TRUE;
+ }
+ else if (g_strcmp0 (dispatch->request->auth_info_required[i], "username") == 0)
+ {
+ auth_info_display[i] = g_strdup (_("Username:"));
+ if (dispatch->backend->username != NULL)
+ auth_info_default[i] = g_strdup (dispatch->backend->username);
+ else
+ auth_info_default[i] = g_strdup (cupsUser ());
+ auth_info_visible[i] = TRUE;
+ }
+ else if (g_strcmp0 (dispatch->request->auth_info_required[i], "password") == 0)
+ {
+ auth_info_display[i] = g_strdup (_("Password:"));
+ auth_info_visible[i] = FALSE;
+ }
+ }
+
+ if (printer_uri != NULL && strrchr (printer_uri, '/') != NULL)
+ printer_name = g_strdup (strrchr (printer_uri, '/') + 1);
+
+ dispatch->backend->authentication_lock = TRUE;
+
+ if (job_title != NULL)
+ {
+ if (printer_name != NULL)
+ prompt = g_strdup_printf ( _("Authentication is required to print document '%s' on printer %s"), job_title, printer_name);
+ else
+ prompt = g_strdup_printf ( _("Authentication is required to print document '%s'"), job_title);
+ }
+ else
+ {
+ if (printer_name != NULL)
+ prompt = g_strdup_printf ( _("Authentication is required to print this document on printer %s"), printer_name);
+ else
+ prompt = g_strdup ( _("Authentication is required to print this document"));
+ }
+
+ g_signal_emit_by_name (dispatch->backend, "request-password",
+ dispatch->request->auth_info_required,
+ auth_info_default,
+ auth_info_display,
+ auth_info_visible,
+ prompt);
+
+ for (i = 0; i < length; i++)
+ {
+ g_free (auth_info_default[i]);
+ g_free (auth_info_display[i]);
+ }
+
+ g_free (auth_info_default);
+ g_free (auth_info_display);
+ g_free (printer_name);
+ g_free (prompt);
+
+ g_idle_add (check_auth_info, user_data);
+
+ return FALSE;
+}
+
static gboolean
cups_dispatch_watch_check (GSource *source)
{
dispatch = (GtkPrintCupsDispatchWatch *) g_source_new (&_cups_dispatch_watch_funcs,
sizeof (GtkPrintCupsDispatchWatch));
+ g_source_set_name (&dispatch->source, "GTK+ CUPS backend");
GTK_NOTE (PRINTING,
g_print ("CUPS Backend: %s <source %p> - Executing cups request on server '%s' and resource '%s'\n", G_STRFUNC, dispatch, request->server, request->resource));
dispatch->request = request;
dispatch->backend = g_object_ref (print_backend);
dispatch->data_poll = NULL;
+ dispatch->callback = NULL;
+ dispatch->callback_data = NULL;
print_backend->requests = g_list_prepend (print_backend->requests, dispatch);
g_source_set_callback ((GSource *) dispatch, (GSourceFunc) callback, user_data, notify);
- g_source_attach ((GSource *) dispatch, NULL);
- g_source_unref ((GSource *) dispatch);
+ if (request->need_auth_info)
+ {
+ dispatch->callback = callback;
+ dispatch->callback_data = user_data;
+ request_auth_info (dispatch);
+ }
+ else
+ {
+ g_source_attach ((GSource *) dispatch, NULL);
+ g_source_unref ((GSource *) dispatch);
+ }
}
#if 0
response = gtk_cups_result_get_response (result);
/* TODO: determine printer type and use correct icon */
- gtk_printer_set_icon_name (printer, "gtk-print");
+ gtk_printer_set_icon_name (printer, "printer");
state_msg = "";
loc = "";
if (cups_backend->list_printers_poll > 0)
g_source_remove (cups_backend->list_printers_poll);
cups_backend->list_printers_poll = 0;
+ cups_backend->list_printers_attempts = 0;
}
goto done;
"media-low",
"media-empty",
"offline",
- "connecting-to-device",
"other"
};
static const char * reasons_descs[] =
N_("The door is open on printer '%s'."),
N_("Printer '%s' is low on paper."),
N_("Printer '%s' is out of paper."),
- N_("Printer '%s' is currently off-line."),
- N_("Printer '%s' may not be connected."),
+ N_("Printer '%s' is currently offline."),
N_("There is a problem on printer '%s'.")
};
gboolean is_paused = FALSE;
gchar *default_cover_before = NULL;
gchar *default_cover_after = NULL;
gboolean remote_printer = FALSE;
+ gchar **auth_info_required = NULL;
/* Skip leading attributes until we hit a printer...
*/
else
remote_printer = FALSE;
}
+ else if (strcmp (attr->name, "auth-info-required") == 0)
+ {
+ if (strcmp (attr->values[0].string.text, "none") != 0)
+ {
+ auth_info_required = g_new0 (gchar *, attr->num_values + 1);
+ for (i = 0; i < attr->num_values; i++)
+ auth_info_required[i] = g_strdup (attr->values[i].string.text);
+ }
+ }
else
{
GTK_NOTE (PRINTING,
cups_printer->hostname = g_strdup (hostname);
cups_printer->port = port;
+ cups_printer->auth_info_required = g_strdupv (auth_info_required);
+ g_strfreev (auth_info_required);
+
printer = GTK_PRINTER (cups_printer);
if (cups_backend->default_printer != NULL &&
else
g_object_ref (printer);
+ GTK_PRINTER_CUPS (printer)->remote = remote_printer;
+
gtk_printer_set_is_paused (printer, is_paused);
gtk_printer_set_is_accepting_jobs (printer, is_accepting_jobs);
/* Set printer icon according to importance
(none, report, warning, error - report is omitted). */
if (printer_state_reason_level == 3)
- gtk_printer_set_icon_name (printer, "gtk-print-error");
+ gtk_printer_set_icon_name (printer, "printer-error");
else if (printer_state_reason_level == 2)
- gtk_printer_set_icon_name (printer, "gtk-print-warning");
+ gtk_printer_set_icon_name (printer, "printer-warning");
else if (gtk_printer_is_paused (printer))
- gtk_printer_set_icon_name (printer, "gtk-print-paused");
+ gtk_printer_set_icon_name (printer, "printer-paused");
else
- gtk_printer_set_icon_name (printer, "gtk-print");
+ gtk_printer_set_icon_name (printer, "printer");
if (status_changed)
g_signal_emit_by_name (GTK_PRINT_BACKEND (backend),
"printer-is-accepting-jobs",
"job-sheets-supported",
"job-sheets-default",
- "printer-type"
+ "printer-type",
+ "auth-info-required"
};
- if (cups_backend->list_printers_pending)
+ if (cups_backend->reading_ppds > 0 || cups_backend->list_printers_pending)
return TRUE;
state = gtk_cups_connection_test_get_state (cups_backend->cups_connection_test);
update_backend_status (cups_backend, state);
+ if (cups_backend->list_printers_attempts == 60)
+ {
+ cups_backend->list_printers_attempts = -1;
+ if (cups_backend->list_printers_poll > 0)
+ g_source_remove (cups_backend->list_printers_poll);
+ cups_backend->list_printers_poll = gdk_threads_add_timeout (200,
+ (GSourceFunc) cups_request_printer_list,
+ cups_backend);
+ }
+ else if (cups_backend->list_printers_attempts != -1)
+ cups_backend->list_printers_attempts++;
+
if (state == GTK_CUPS_CONNECTION_IN_PROGRESS || state == GTK_CUPS_CONNECTION_NOT_AVAILABLE)
return TRUE;
+ else
+ if (cups_backend->list_printers_attempts > 0)
+ cups_backend->list_printers_attempts = 60;
cups_backend->list_printers_pending = TRUE;
if (cups_backend->list_printers_poll == 0)
{
if (cups_request_printer_list (cups_backend))
- cups_backend->list_printers_poll = gdk_threads_add_timeout_seconds (3,
- (GSourceFunc) cups_request_printer_list,
- backend);
+ cups_backend->list_printers_poll = gdk_threads_add_timeout (50,
+ (GSourceFunc) cups_request_printer_list,
+ backend);
}
}
GtkCupsResult *result,
GetPPDData *data)
{
- ipp_t *response;
GtkPrinter *printer;
GDK_THREADS_ENTER ();
printer = GTK_PRINTER (data->printer);
GTK_PRINTER_CUPS (printer)->reading_ppd = FALSE;
+ print_backend->reading_ppds--;
if (gtk_cups_result_is_error (result))
{
goto done;
}
- response = gtk_cups_result_get_response (result);
-
/* let ppdOpenFd take over the ownership of the open file */
g_io_channel_seek_position (data->ppd_io, 0, G_SEEK_SET, NULL);
data->printer->ppd_file = ppdOpenFd (dup (g_io_channel_unix_get_fd (data->ppd_io)));
GDK_THREADS_LEAVE ();
}
-static void
+static gboolean
cups_request_ppd (GtkPrinter *printer)
{
GError *error;
GTK_NOTE (PRINTING,
g_print ("CUPS Backend: %s\n", G_STRFUNC));
+ if (cups_printer->remote)
+ {
+ GtkCupsConnectionState state;
+
+ state = gtk_cups_connection_test_get_state (cups_printer->remote_cups_connection_test);
+
+ if (state == GTK_CUPS_CONNECTION_IN_PROGRESS)
+ {
+ if (cups_printer->get_remote_ppd_attempts == 60)
+ {
+ cups_printer->get_remote_ppd_attempts = -1;
+ if (cups_printer->get_remote_ppd_poll > 0)
+ g_source_remove (cups_printer->get_remote_ppd_poll);
+ cups_printer->get_remote_ppd_poll = gdk_threads_add_timeout (200,
+ (GSourceFunc) cups_request_ppd,
+ printer);
+ }
+ else if (cups_printer->get_remote_ppd_attempts != -1)
+ cups_printer->get_remote_ppd_attempts++;
+
+ return TRUE;
+ }
+
+ gtk_cups_connection_test_free (cups_printer->remote_cups_connection_test);
+ cups_printer->remote_cups_connection_test = NULL;
+ cups_printer->get_remote_ppd_poll = 0;
+ cups_printer->get_remote_ppd_attempts = 0;
+
+ if (state == GTK_CUPS_CONNECTION_NOT_AVAILABLE)
+ {
+ g_signal_emit_by_name (printer, "details-acquired", FALSE);
+ return FALSE;
+ }
+ }
+
http = httpConnectEncrypt (cups_printer->hostname,
cups_printer->port,
cupsEncryption ());
#ifdef G_ENABLE_DEBUG
/* If we are debugging printing don't delete the tmp files */
- if (!(gtk_debug_flags & GTK_DEBUG_PRINTING))
+ if (!(gtk_get_debug_flags () & GTK_DEBUG_PRINTING))
unlink (ppd_filename);
#else
unlink (ppd_filename);
g_free (data);
g_signal_emit_by_name (printer, "details-acquired", FALSE);
- return;
+ return FALSE;
}
data->http = http;
cups_printer->reading_ppd = TRUE;
+ GTK_PRINT_BACKEND_CUPS (print_backend)->reading_ppds++;
cups_request_execute (GTK_PRINT_BACKEND_CUPS (print_backend),
request,
g_free (resource);
g_free (ppd_filename);
+
+ return FALSE;
}
/* Ordering matters for default preference */
if (cups_backend->default_printer_poll == 0)
{
if (cups_request_default_printer (cups_backend))
- cups_backend->default_printer_poll = gdk_threads_add_timeout (500,
- (GSourceFunc) cups_request_default_printer,
- backend);
+ cups_backend->default_printer_poll = gdk_threads_add_timeout (200,
+ (GSourceFunc) cups_request_default_printer,
+ backend);
}
}
cups_printer = GTK_PRINTER_CUPS (printer);
if (!cups_printer->reading_ppd &&
gtk_printer_cups_get_ppd (cups_printer) == NULL)
- cups_request_ppd (printer);
+ {
+ if (cups_printer->remote)
+ {
+ if (cups_printer->get_remote_ppd_poll == 0)
+ {
+ cups_printer->remote_cups_connection_test = gtk_cups_connection_test_new (cups_printer->hostname);
+
+ if (cups_request_ppd (printer))
+ cups_printer->get_remote_ppd_poll = gdk_threads_add_timeout (50,
+ (GSourceFunc) cups_request_ppd,
+ printer);
+ }
+ }
+ else
+ cups_request_ppd (printer);
+ }
}
static char *
static const struct {
const char *ppd_keyword;
const char *name;
-} option_names[] = {
+} ppd_option_names[] = {
{"Duplex", "gtk-duplex" },
{"MediaType", "gtk-paper-type"},
{"InputSlot", "gtk-paper-source"},
{"OutputBin", "gtk-output-tray"},
};
+static const struct {
+ const char *lpoption;
+ const char *name;
+} lpoption_names[] = {
+ {"number-up", "gtk-n-up" },
+ {"number-up-layout", "gtk-n-up-layout"},
+ {"job-billing", "gtk-billing-info"},
+ {"job-priority", "gtk-job-prio"},
+};
+
/* keep sorted when changing */
static const char *color_option_whitelist[] = {
"BRColorEnhancement",
}
static gchar *
-get_option_name (const gchar *keyword)
+get_ppd_option_name (const gchar *keyword)
{
int i;
- for (i = 0; i < G_N_ELEMENTS (option_names); i++)
- if (strcmp (option_names[i].ppd_keyword, keyword) == 0)
- return g_strdup (option_names[i].name);
+ for (i = 0; i < G_N_ELEMENTS (ppd_option_names); i++)
+ if (strcmp (ppd_option_names[i].ppd_keyword, keyword) == 0)
+ return g_strdup (ppd_option_names[i].name);
return g_strdup_printf ("cups-%s", keyword);
}
+static gchar *
+get_lpoption_name (const gchar *lpoption)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (ppd_option_names); i++)
+ if (strcmp (ppd_option_names[i].ppd_keyword, lpoption) == 0)
+ return g_strdup (ppd_option_names[i].name);
+
+ for (i = 0; i < G_N_ELEMENTS (lpoption_names); i++)
+ if (strcmp (lpoption_names[i].lpoption, lpoption) == 0)
+ return g_strdup (lpoption_names[i].name);
+
+ return g_strdup_printf ("cups-%s", lpoption);
+}
+
static int
strptr_cmp (const void *a,
const void *b)
if (STRING_IN_TABLE (ppd_option->keyword, cups_option_blacklist))
return;
- name = get_option_name (ppd_option->keyword);
+ name = get_ppd_option_name (ppd_option->keyword);
option = NULL;
if (ppd_option->ui == PPD_UI_PICKONE)
if (STRING_IN_TABLE (opts[i].name, cups_option_blacklist))
continue;
- name = get_option_name (opts[i].name);
- option = gtk_printer_option_set_lookup (set, name);
- if (option)
- gtk_printer_option_set (option, opts[i].value);
+ name = get_lpoption_name (opts[i].name);
+ if (strcmp (name, "cups-job-sheets") == 0)
+ {
+ gchar **values;
+ gint num_values;
+
+ values = g_strsplit (opts[i].value, ",", 2);
+ num_values = g_strv_length (values);
+
+ option = gtk_printer_option_set_lookup (set, "gtk-cover-before");
+ if (option && num_values > 0)
+ gtk_printer_option_set (option, g_strstrip (values[0]));
+
+ option = gtk_printer_option_set_lookup (set, "gtk-cover-after");
+ if (option && num_values > 1)
+ gtk_printer_option_set (option, g_strstrip (values[1]));
+
+ g_strfreev (values);
+ }
+ else if (strcmp (name, "cups-job-hold-until") == 0)
+ {
+ GtkPrinterOption *option2 = NULL;
+
+ option = gtk_printer_option_set_lookup (set, "gtk-print-time-text");
+ if (option && opts[i].value)
+ {
+ option2 = gtk_printer_option_set_lookup (set, "gtk-print-time");
+ if (option2)
+ {
+ if (strcmp (opts[i].value, "indefinite") == 0)
+ gtk_printer_option_set (option2, "on-hold");
+ else
+ {
+ gtk_printer_option_set (option2, "at");
+ gtk_printer_option_set (option, opts[i].value);
+ }
+ }
+ }
+ }
+ else if (strcmp (name, "cups-sides") == 0)
+ {
+ option = gtk_printer_option_set_lookup (set, "gtk-duplex");
+ if (option && opts[i].value)
+ {
+ if (strcmp (opts[i].value, "two-sided-short-edge") == 0)
+ gtk_printer_option_set (option, "DuplexTumble");
+ else if (strcmp (opts[i].value, "two-sided-long-edge") == 0)
+ gtk_printer_option_set (option, "DuplexNoTumble");
+ }
+ }
+ else
+ {
+ option = gtk_printer_option_set_lookup (set, name);
+ if (option)
+ gtk_printer_option_set (option, opts[i].value);
+ }
g_free (name);
}
ppd_option_t *ppd_option)
{
GtkPrinterOption *option;
- char *name = get_option_name (ppd_option->keyword);
+ char *name = get_ppd_option_name (ppd_option->keyword);
option = gtk_printer_option_set_lookup (set, name);
if (ppd_option->conflicted)
{
- name = get_option_name (ppd_option->keyword);
+ name = get_ppd_option_name (ppd_option->keyword);
option = gtk_printer_option_set_lookup (set, name);
if (option)
gtk_printer_option_set (option, cups_value);
else
{
- int res = gtk_print_settings_get_resolution (settings);
- int res_x = gtk_print_settings_get_resolution_x (settings);
- int res_y = gtk_print_settings_get_resolution_y (settings);
+ if (gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION, -1) != -1 ||
+ gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION_X, -1) != -1 ||
+ gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y, -1) != -1 ||
+ option->value == NULL || option->value[0] == '\0')
+ {
+ int res = gtk_print_settings_get_resolution (settings);
+ int res_x = gtk_print_settings_get_resolution_x (settings);
+ int res_y = gtk_print_settings_get_resolution_y (settings);
- if (res_x != res_y)
- {
- value = g_strdup_printf ("%dx%ddpi", res_x, res_y);
- gtk_printer_option_set (option, value);
- g_free (value);
+ if (res_x != res_y)
+ {
+ value = g_strdup_printf ("%dx%ddpi", res_x, res_y);
+ gtk_printer_option_set (option, value);
+ g_free (value);
+ }
+ else if (res != 0)
+ {
+ value = g_strdup_printf ("%ddpi", res);
+ gtk_printer_option_set (option, value);
+ g_free (value);
+ }
}
- else if (res != 0)
- {
- value = g_strdup_printf ("%ddpi", res);
- gtk_printer_option_set (option, value);
- g_free (value);
- }
- }
+ }
}
else if (strcmp (option->name, "gtk-paper-type") == 0)
map_settings_to_option (option, media_type_map, G_N_ELEMENTS (media_type_map),
GtkPrintSettings *settings,
GtkPageSetup *page_setup)
{
+ GtkPrintPages pages;
+ GtkPageRange *ranges;
+ gint n_ranges;
GtkPageSet page_set;
GtkPaperSize *paper_size;
const char *ppd_paper_name;
double scale;
- print_job->print_pages = gtk_print_settings_get_print_pages (settings);
- print_job->page_ranges = NULL;
- print_job->num_page_ranges = 0;
-
- if (print_job->print_pages == GTK_PRINT_PAGES_RANGES)
- print_job->page_ranges =
- gtk_print_settings_get_page_ranges (settings,
- &print_job->num_page_ranges);
-
+ pages = gtk_print_settings_get_print_pages (settings);
+ gtk_print_job_set_pages (print_job, pages);
+
+ if (pages == GTK_PRINT_PAGES_RANGES)
+ ranges = gtk_print_settings_get_page_ranges (settings, &n_ranges);
+ else
+ {
+ ranges = NULL;
+ n_ranges = 0;
+ }
+
+ gtk_print_job_set_page_ranges (print_job, ranges, n_ranges);
if (gtk_print_settings_get_collate (settings))
gtk_print_settings_set (settings, "cups-Collate", "True");
- print_job->collate = FALSE;
+ gtk_print_job_set_collate (print_job, FALSE);
if (gtk_print_settings_get_reverse (settings))
gtk_print_settings_set (settings, "cups-OutputOrder", "Reverse");
- print_job->reverse = FALSE;
+ gtk_print_job_set_reverse (print_job, FALSE);
if (gtk_print_settings_get_n_copies (settings) > 1)
gtk_print_settings_set_int (settings, "cups-copies",
- gtk_print_settings_get_n_copies (settings));
- print_job->num_copies = 1;
+ gtk_print_settings_get_n_copies (settings));
+ gtk_print_job_set_num_copies (print_job, 1);
scale = gtk_print_settings_get_scale (settings);
- print_job->scale = 1.0;
if (scale != 100.0)
- print_job->scale = scale/100.0;
+ gtk_print_job_set_scale (print_job, scale / 100.0);
page_set = gtk_print_settings_get_page_set (settings);
if (page_set == GTK_PAGE_SET_EVEN)
gtk_print_settings_set (settings, "cups-page-set", "even");
else if (page_set == GTK_PAGE_SET_ODD)
gtk_print_settings_set (settings, "cups-page-set", "odd");
- print_job->page_set = GTK_PAGE_SET_ALL;
+ gtk_print_job_set_page_set (print_job, GTK_PAGE_SET_ALL);
paper_size = gtk_page_setup_get_paper_size (page_setup);
ppd_paper_name = gtk_paper_size_get_ppd_name (paper_size);
break;
case GTK_PAGE_ORIENTATION_LANDSCAPE:
if (layout < 4)
- layout = layout + 5 - 2 * (layout % 2);
+ layout = layout + 2 + 4 * (1 - layout / 2);
else
- layout = layout - 6 + 4 * (1 - (layout - 4) / 2);
+ layout = layout - 3 - 2 * (layout % 2);
break;
case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
layout = (layout + 3 - 2 * (layout % 2)) % 4 + 4 * (layout / 4);
break;
case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
if (layout < 4)
- layout = layout + 2 + 4 * (1 - layout / 2);
+ layout = layout + 5 - 2 * (layout % 2);
else
- layout = layout - 3 - 2 * (layout % 2);
+ layout = layout - 6 + 4 * (1 - (layout - 4) / 2);
break;
}
g_type_class_unref (enum_class);
}
- print_job->rotate_to_orientation = TRUE;
+ gtk_print_job_set_rotate (print_job, TRUE);
}
static GtkPageSetup *
return create_page_setup (ppd_file, size);
}
-static void
+static gboolean
cups_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,
gdouble *bottom,
ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
if (ppd_file == NULL)
- return;
+ return FALSE;
*left = ppd_file->custom_margins[0];
*bottom = ppd_file->custom_margins[1];
*right = ppd_file->custom_margins[2];
*top = ppd_file->custom_margins[3];
+
+ return TRUE;
}
static GtkPrintCapabilities