#include "gtkcupsutils.h"
+#ifdef HAVE_COLORD
+#include <colord.h>
+#endif
typedef struct _GtkPrintBackendCupsClass GtkPrintBackendCupsClass;
http_t *http;
GtkCupsRequest *request;
+ GtkCupsPollState poll_state;
GPollFD *data_poll;
GtkPrintBackendCups *backend;
GtkPrintCupsResponseCallbackFunc callback;
GHashTable *auth;
gchar *username;
gboolean authentication_lock;
+#ifdef HAVE_COLORD
+ CdClient *colord_client;
+#endif
};
static GObjectClass *backend_parent_class;
GDK_THREADS_LEAVE ();
}
+typedef struct {
+ GtkCupsRequest *request;
+ GtkPrinterCups *printer;
+} CupsOptionsData;
+
static void
add_cups_options (const gchar *key,
const gchar *value,
gpointer user_data)
{
- GtkCupsRequest *request = user_data;
+ CupsOptionsData *data = (CupsOptionsData *) user_data;
+ GtkCupsRequest *request = data->request;
+ GtkPrinterCups *printer = data->printer;
+ gboolean custom_value = FALSE;
+ gchar *new_value = NULL;
+ gint i;
+
+ if (!key || !value)
+ return;
if (!g_str_has_prefix (key, "cups-"))
return;
if (strcmp (value, "gtk-ignore-value") == 0)
return;
-
+
key = key + strlen ("cups-");
- gtk_cups_request_encode_option (request, key, value);
+ if (printer && printer->ppd_file)
+ {
+ ppd_coption_t *coption;
+ gboolean found = FALSE;
+ gboolean custom_values_enabled = FALSE;
+
+ coption = ppdFindCustomOption (printer->ppd_file, key);
+ if (coption && coption->option)
+ {
+ for (i = 0; i < coption->option->num_choices; i++)
+ {
+ /* Are custom values enabled ? */
+ if (g_str_equal (coption->option->choices[i].choice, "Custom"))
+ custom_values_enabled = TRUE;
+
+ /* Is the value among available choices ? */
+ if (g_str_equal (coption->option->choices[i].choice, value))
+ found = TRUE;
+ }
+
+ if (custom_values_enabled && !found)
+ custom_value = TRUE;
+ }
+ }
+
+ /* Add "Custom." prefix to custom values. */
+ if (custom_value)
+ {
+ new_value = g_strdup_printf ("Custom.%s", value);
+ gtk_cups_request_encode_option (request, key, new_value);
+ g_free (new_value);
+ }
+ else
+ gtk_cups_request_encode_option (request, key, value);
}
static void
{
GtkPrinterCups *cups_printer;
CupsPrintStreamData *ps;
+ CupsOptionsData *options_data;
GtkCupsRequest *request;
GtkPrintSettings *settings;
const gchar *title;
IPP_TAG_NAME, "job-name",
NULL, title);
- gtk_print_settings_foreach (settings, add_cups_options, request);
-
+ options_data = g_new0 (CupsOptionsData, 1);
+ options_data->request = request;
+ options_data->printer = cups_printer;
+ gtk_print_settings_foreach (settings, add_cups_options, options_data);
+ g_free (options_data);
+
ps = g_new0 (CupsPrintStreamData, 1);
ps->callback = callback;
ps->user_data = user_data;
backend_cups->username = NULL;
+#ifdef HAVE_COLORD
+ backend_cups->colord_client = cd_client_new ();
+#endif
+
cups_get_local_default_printer (backend_cups);
}
g_free (backend_cups->username);
+#ifdef HAVE_COLORD
+ g_object_unref (backend_cups->colord_client);
+#endif
+
backend_parent_class->finalize (object);
}
gint i;
if (dispatch->backend->authentication_lock)
- return FALSE;
+ return G_SOURCE_REMOVE;
httpGetHostname (dispatch->request->http, hostname, sizeof (hostname));
if (is_address_local (hostname))
g_free (auth_info_visible);
g_free (key);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static void
poll_state = gtk_cups_request_get_poll_state (dispatch->request);
+ /* Remove the old source if the poll state changed. */
+ if (poll_state != dispatch->poll_state && dispatch->data_poll != NULL)
+ {
+ g_source_remove_poll (source, dispatch->data_poll);
+ g_free (dispatch->data_poll);
+ dispatch->data_poll = NULL;
+ }
+
if (dispatch->request->http != NULL)
{
if (dispatch->data_poll == NULL)
{
dispatch->data_poll = g_new0 (GPollFD, 1);
+ dispatch->poll_state = poll_state;
if (poll_state == GTK_CUPS_HTTP_READ)
dispatch->data_poll->events = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI;
dispatch->request->auth_info = NULL;
}
- return FALSE;
+ return G_SOURCE_REMOVE;
}
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
static gboolean
poll_state = gtk_cups_request_get_poll_state (dispatch->request);
- cups_dispatch_add_poll (source);
-
if (poll_state != GTK_CUPS_HTTP_IDLE && !dispatch->request->need_password)
if (!(dispatch->data_poll->revents & dispatch->data_poll->events))
return FALSE;
- result = gtk_cups_request_read_write (dispatch->request);
+ result = gtk_cups_request_read_write (dispatch->request, FALSE);
if (result && dispatch->data_poll != NULL)
{
g_source_remove_poll (source, dispatch->data_poll);
g_print ("CUPS Backend: %s <source %p>\n", G_STRFUNC, source));
*timeout_ = -1;
-
- result = gtk_cups_request_read_write (dispatch->request);
+
+ result = gtk_cups_request_read_write (dispatch->request, TRUE);
cups_dispatch_add_poll (source);
dispatch->backend = NULL;
}
- g_free (dispatch->data_poll);
+ if (dispatch->data_poll)
+ {
+ g_source_remove_poll (source, dispatch->data_poll);
+ g_free (dispatch->data_poll);
+ dispatch->data_poll = NULL;
+ }
}
static GSourceFuncs _cups_dispatch_watch_funcs = {
dispatch->request = request;
dispatch->backend = g_object_ref (print_backend);
+ dispatch->poll_state = GTK_CUPS_HTTP_IDLE;
dispatch->data_poll = NULL;
dispatch->callback = NULL;
dispatch->callback_data = NULL;
else
cups_request_job_info (data);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static void
char *cups_server; /* CUPS server */
list_has_changed = TRUE;
- cups_printer = gtk_printer_cups_new (printer_name, backend);
+#ifdef HAVE_COLORD
+ cups_printer = gtk_printer_cups_new (printer_name,
+ backend,
+ cups_backend->colord_client);
+#else
+ cups_printer = gtk_printer_cups_new (printer_name, backend, NULL);
+#endif
cups_printer->device_uri = g_strdup_printf ("/printers/%s", printer_name);
as inactive if it is in the list, emitting a printer_removed signal */
if (removed_printer_checklist != NULL)
{
- g_list_foreach (removed_printer_checklist, (GFunc) mark_printer_inactive, backend);
- g_list_free (removed_printer_checklist);
+ g_list_free_full (removed_printer_checklist, (GDestroyNotify) mark_printer_inactive);
list_has_changed = TRUE;
}
GtkCupsResult *result,
GetPPDData *data)
{
- ipp_t *response;
GtkPrinter *printer;
GDK_THREADS_ENTER ();
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)));
option->choices_display[i] = get_choice_text (ppd_file, available[i]);
}
}
- gtk_printer_option_set (option, ppd_option->defchoice);
+
+ if (option->type != GTK_PRINTER_OPTION_TYPE_PICKONE)
+ {
+ if (g_str_has_prefix (ppd_option->defchoice, "Custom."))
+ gtk_printer_option_set (option, ppd_option->defchoice + 7);
+ else
+ gtk_printer_option_set (option, ppd_option->defchoice);
+ }
+ else
+ {
+ gtk_printer_option_set (option, ppd_option->defchoice);
+ }
}
#ifdef PRINT_IGNORED_OPTIONS
else
}
+#ifdef HAVE_COLORD
+
+typedef struct {
+ GtkPrintSettings *settings;
+ GtkPrinter *printer;
+} GtkPrintBackendCupsColordHelper;
+
+static void
+colord_printer_option_set_changed_cb (GtkPrinterOptionSet *set,
+ GtkPrintBackendCupsColordHelper *helper)
+{
+ gtk_printer_cups_update_settings (GTK_PRINTER_CUPS (helper->printer),
+ helper->settings,
+ set);
+}
+#endif
+
static GtkPrinterOptionSet *
cups_printer_get_options (GtkPrinter *printer,
GtkPrintSettings *settings,
GtkPrintBackendCups *backend;
GtkTextDirection text_direction;
GtkPrinterCups *cups_printer = NULL;
-
+#ifdef HAVE_COLORD
+ GtkPrintBackendCupsColordHelper *helper;
+#endif
set = gtk_printer_option_set_new ();
cupsFreeOptions (num_opts, opts);
+#ifdef HAVE_COLORD
+ /* TRANSLATORS: this this the ICC color profile to use for this job */
+ option = gtk_printer_option_new ("colord-profile",
+ _("Printer Profile"),
+ GTK_PRINTER_OPTION_TYPE_INFO);
+
+ /* assign it to the color page */
+ option->group = g_strdup ("ColorPage");
+
+ /* TRANSLATORS: this is when color profile information is unavailable */
+ gtk_printer_option_set (option, _("Unavailable"));
+ gtk_printer_option_set_add (set, option);
+
+ /* watch to see if the user changed the options */
+ helper = g_new (GtkPrintBackendCupsColordHelper, 1);
+ helper->printer = printer;
+ helper->settings = settings;
+ g_signal_connect_data (set, "changed",
+ G_CALLBACK (colord_printer_option_set_changed_cb),
+ helper,
+ (GClosureNotify) g_free,
+ 0);
+
+ /* initial coldplug */
+ gtk_printer_cups_update_settings (GTK_PRINTER_CUPS (printer),
+ settings, set);
+ g_object_bind_property (printer, "profile-title",
+ option, "value",
+ G_BINDING_DEFAULT);
+
+#endif
+
return set;
}
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),
return NULL;
option = ppdFindOption (ppd_file, "PageSize");
+ if (option == NULL)
+ return NULL;
+
size = ppdPageSize (ppd_file, option->defchoice);
+ if (size == NULL)
+ return NULL;
return create_page_setup (ppd_file, size);
}